app/testpmd: enforce offload capabilities check
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51
52 #include <sys/queue.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.h>
79
80 #include <cmdline_rdline.h>
81 #include <cmdline_parse.h>
82 #include <cmdline_parse_num.h>
83 #include <cmdline_parse_string.h>
84 #include <cmdline_parse_ipaddr.h>
85 #include <cmdline_parse_etheraddr.h>
86 #include <cmdline_socket.h>
87 #include <cmdline.h>
88 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_IXGBE_PMD
93 #include <rte_pmd_ixgbe.h>
94 #endif
95 #ifdef RTE_LIBRTE_I40E_PMD
96 #include <rte_pmd_i40e.h>
97 #endif
98 #ifdef RTE_LIBRTE_BNXT_PMD
99 #include <rte_pmd_bnxt.h>
100 #endif
101 #include "testpmd.h"
102 #include "cmdline_mtr.h"
103 #include "cmdline_tm.h"
104
105 static struct cmdline *testpmd_cl;
106
107 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
108
109 /* *** Help command with introduction. *** */
110 struct cmd_help_brief_result {
111         cmdline_fixed_string_t help;
112 };
113
114 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
115                                   struct cmdline *cl,
116                                   __attribute__((unused)) void *data)
117 {
118         cmdline_printf(
119                 cl,
120                 "\n"
121                 "Help is available for the following sections:\n\n"
122                 "    help control    : Start and stop forwarding.\n"
123                 "    help display    : Displaying port, stats and config "
124                 "information.\n"
125                 "    help config     : Configuration information.\n"
126                 "    help ports      : Configuring ports.\n"
127                 "    help registers  : Reading and setting port registers.\n"
128                 "    help filters    : Filters configuration help.\n"
129                 "    help all        : All of the above sections.\n\n"
130         );
131
132 }
133
134 cmdline_parse_token_string_t cmd_help_brief_help =
135         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
136
137 cmdline_parse_inst_t cmd_help_brief = {
138         .f = cmd_help_brief_parsed,
139         .data = NULL,
140         .help_str = "help: Show help",
141         .tokens = {
142                 (void *)&cmd_help_brief_help,
143                 NULL,
144         },
145 };
146
147 /* *** Help command with help sections. *** */
148 struct cmd_help_long_result {
149         cmdline_fixed_string_t help;
150         cmdline_fixed_string_t section;
151 };
152
153 static void cmd_help_long_parsed(void *parsed_result,
154                                  struct cmdline *cl,
155                                  __attribute__((unused)) void *data)
156 {
157         int show_all = 0;
158         struct cmd_help_long_result *res = parsed_result;
159
160         if (!strcmp(res->section, "all"))
161                 show_all = 1;
162
163         if (show_all || !strcmp(res->section, "control")) {
164
165                 cmdline_printf(
166                         cl,
167                         "\n"
168                         "Control forwarding:\n"
169                         "-------------------\n\n"
170
171                         "start\n"
172                         "    Start packet forwarding with current configuration.\n\n"
173
174                         "start tx_first\n"
175                         "    Start packet forwarding with current config"
176                         " after sending one burst of packets.\n\n"
177
178                         "stop\n"
179                         "    Stop packet forwarding, and display accumulated"
180                         " statistics.\n\n"
181
182                         "quit\n"
183                         "    Quit to prompt.\n\n"
184                 );
185         }
186
187         if (show_all || !strcmp(res->section, "display")) {
188
189                 cmdline_printf(
190                         cl,
191                         "\n"
192                         "Display:\n"
193                         "--------\n\n"
194
195                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
196                         "    Display information for port_id, or all.\n\n"
197
198                         "show port X rss reta (size) (mask0,mask1,...)\n"
199                         "    Display the rss redirection table entry indicated"
200                         " by masks on port X. size is used to indicate the"
201                         " hardware supported reta size\n\n"
202
203                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
204                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
205                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
206                         "    Display the RSS hash functions and RSS hash key"
207                         " of port X\n\n"
208
209                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
210                         "    Clear information for port_id, or all.\n\n"
211
212                         "show (rxq|txq) info (port_id) (queue_id)\n"
213                         "    Display information for configured RX/TX queue.\n\n"
214
215                         "show config (rxtx|cores|fwd|txpkts)\n"
216                         "    Display the given configuration.\n\n"
217
218                         "read rxd (port_id) (queue_id) (rxd_id)\n"
219                         "    Display an RX descriptor of a port RX queue.\n\n"
220
221                         "read txd (port_id) (queue_id) (txd_id)\n"
222                         "    Display a TX descriptor of a port TX queue.\n\n"
223
224                         "ddp get list (port_id)\n"
225                         "    Get ddp profile info list\n\n"
226
227                         "ddp get info (profile_path)\n"
228                         "    Get ddp profile information.\n\n"
229
230                         "show vf stats (port_id) (vf_id)\n"
231                         "    Display a VF's statistics.\n\n"
232
233                         "clear vf stats (port_id) (vf_id)\n"
234                         "    Reset a VF's statistics.\n\n"
235
236                         "show port (port_id) pctype mapping\n"
237                         "    Get flow ptype to pctype mapping on a port\n\n"
238
239                         "show port meter stats (port_id) (meter_id) (clear)\n"
240                         "    Get meter stats on a port\n\n"
241                         "show port tm cap (port_id)\n"
242                         "       Display the port TM capability.\n\n"
243
244                         "show port tm level cap (port_id) (level_id)\n"
245                         "       Display the port TM hierarchical level capability.\n\n"
246
247                         "show port tm node cap (port_id) (node_id)\n"
248                         "       Display the port TM node capability.\n\n"
249
250                         "show port tm node type (port_id) (node_id)\n"
251                         "       Display the port TM node type.\n\n"
252
253                         "show port tm node stats (port_id) (node_id) (clear)\n"
254                         "       Display the port TM node stats.\n\n"
255
256                 );
257         }
258
259         if (show_all || !strcmp(res->section, "config")) {
260                 cmdline_printf(
261                         cl,
262                         "\n"
263                         "Configuration:\n"
264                         "--------------\n"
265                         "Configuration changes only become active when"
266                         " forwarding is started/restarted.\n\n"
267
268                         "set default\n"
269                         "    Reset forwarding to the default configuration.\n\n"
270
271                         "set verbose (level)\n"
272                         "    Set the debug verbosity level X.\n\n"
273
274                         "set nbport (num)\n"
275                         "    Set number of ports.\n\n"
276
277                         "set nbcore (num)\n"
278                         "    Set number of cores.\n\n"
279
280                         "set coremask (mask)\n"
281                         "    Set the forwarding cores hexadecimal mask.\n\n"
282
283                         "set portmask (mask)\n"
284                         "    Set the forwarding ports hexadecimal mask.\n\n"
285
286                         "set burst (num)\n"
287                         "    Set number of packets per burst.\n\n"
288
289                         "set burst tx delay (microseconds) retry (num)\n"
290                         "    Set the transmit delay time and number of retries,"
291                         " effective when retry is enabled.\n\n"
292
293                         "set txpkts (x[,y]*)\n"
294                         "    Set the length of each segment of TXONLY"
295                         " and optionally CSUM packets.\n\n"
296
297                         "set txsplit (off|on|rand)\n"
298                         "    Set the split policy for the TX packets."
299                         " Right now only applicable for CSUM and TXONLY"
300                         " modes\n\n"
301
302                         "set corelist (x[,y]*)\n"
303                         "    Set the list of forwarding cores.\n\n"
304
305                         "set portlist (x[,y]*)\n"
306                         "    Set the list of forwarding ports.\n\n"
307
308                         "set tx loopback (port_id) (on|off)\n"
309                         "    Enable or disable tx loopback.\n\n"
310
311                         "set all queues drop (port_id) (on|off)\n"
312                         "    Set drop enable bit for all queues.\n\n"
313
314                         "set vf split drop (port_id) (vf_id) (on|off)\n"
315                         "    Set split drop enable bit for a VF from the PF.\n\n"
316
317                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
318                         "    Set MAC antispoof for a VF from the PF.\n\n"
319
320                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
321                         "    Enable MACsec offload.\n\n"
322
323                         "set macsec offload (port_id) off\n"
324                         "    Disable MACsec offload.\n\n"
325
326                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
327                         "    Configure MACsec secure connection (SC).\n\n"
328
329                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
330                         "    Configure MACsec secure association (SA).\n\n"
331
332                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
333                         "    Set VF broadcast for a VF from the PF.\n\n"
334
335                         "vlan set strip (on|off) (port_id)\n"
336                         "    Set the VLAN strip on a port.\n\n"
337
338                         "vlan set stripq (on|off) (port_id,queue_id)\n"
339                         "    Set the VLAN strip for a queue on a port.\n\n"
340
341                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
342                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
343
344                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
345                         "    Set VLAN insert for a VF from the PF.\n\n"
346
347                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
348                         "    Set VLAN antispoof for a VF from the PF.\n\n"
349
350                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
351                         "    Set VLAN tag for a VF from the PF.\n\n"
352
353                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
354                         "    Set a VF's max bandwidth(Mbps).\n\n"
355
356                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
357                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
358
359                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
360                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
361
362                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
363                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
364
365                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
366                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
367
368                         "vlan set filter (on|off) (port_id)\n"
369                         "    Set the VLAN filter on a port.\n\n"
370
371                         "vlan set qinq (on|off) (port_id)\n"
372                         "    Set the VLAN QinQ (extended queue in queue)"
373                         " on a port.\n\n"
374
375                         "vlan set (inner|outer) tpid (value) (port_id)\n"
376                         "    Set the VLAN TPID for Packet Filtering on"
377                         " a port\n\n"
378
379                         "rx_vlan add (vlan_id|all) (port_id)\n"
380                         "    Add a vlan_id, or all identifiers, to the set"
381                         " of VLAN identifiers filtered by port_id.\n\n"
382
383                         "rx_vlan rm (vlan_id|all) (port_id)\n"
384                         "    Remove a vlan_id, or all identifiers, from the set"
385                         " of VLAN identifiers filtered by port_id.\n\n"
386
387                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
388                         "    Add a vlan_id, to the set of VLAN identifiers"
389                         "filtered for VF(s) from port_id.\n\n"
390
391                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
392                         "    Remove a vlan_id, to the set of VLAN identifiers"
393                         "filtered for VF(s) from port_id.\n\n"
394
395                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
396                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
397                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
398                         "   add a tunnel filter of a port.\n\n"
399
400                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
401                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
402                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
403                         "   remove a tunnel filter of a port.\n\n"
404
405                         "rx_vxlan_port add (udp_port) (port_id)\n"
406                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
407
408                         "rx_vxlan_port rm (udp_port) (port_id)\n"
409                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
410
411                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
412                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
413                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
414
415                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
416                         "    Set port based TX VLAN insertion.\n\n"
417
418                         "tx_vlan reset (port_id)\n"
419                         "    Disable hardware insertion of a VLAN header in"
420                         " packets sent on a port.\n\n"
421
422                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
423                         "    Select hardware or software calculation of the"
424                         " checksum when transmitting a packet using the"
425                         " csum forward engine.\n"
426                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
427                         "    outer-ip concerns the outer IP layer in"
428                         " case the packet is recognized as a tunnel packet by"
429                         " the forward engine (vxlan, gre and ipip are supported)\n"
430                         "    Please check the NIC datasheet for HW limits.\n\n"
431
432                         "csum parse-tunnel (on|off) (tx_port_id)\n"
433                         "    If disabled, treat tunnel packets as non-tunneled"
434                         " packets (treat inner headers as payload). The port\n"
435                         "    argument is the port used for TX in csum forward"
436                         " engine.\n\n"
437
438                         "csum show (port_id)\n"
439                         "    Display tx checksum offload configuration\n\n"
440
441                         "tso set (segsize) (portid)\n"
442                         "    Enable TCP Segmentation Offload in csum forward"
443                         " engine.\n"
444                         "    Please check the NIC datasheet for HW limits.\n\n"
445
446                         "tso show (portid)"
447                         "    Display the status of TCP Segmentation Offload.\n\n"
448
449                         "set port (port_id) gro on|off\n"
450                         "    Enable or disable Generic Receive Offload in"
451                         " csum forwarding engine.\n\n"
452
453                         "show port (port_id) gro\n"
454                         "    Display GRO configuration.\n\n"
455
456                         "set gro flush (cycles)\n"
457                         "    Set the cycle to flush GROed packets from"
458                         " reassembly tables.\n\n"
459
460                         "set port (port_id) gso (on|off)"
461                         "    Enable or disable Generic Segmentation Offload in"
462                         " csum forwarding engine.\n\n"
463
464                         "set gso segsz (length)\n"
465                         "    Set max packet length for output GSO segments,"
466                         " including packet header and payload.\n\n"
467
468                         "show port (port_id) gso\n"
469                         "    Show GSO configuration.\n\n"
470
471                         "set fwd (%s)\n"
472                         "    Set packet forwarding mode.\n\n"
473
474                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
475                         "    Add a MAC address on port_id.\n\n"
476
477                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
478                         "    Remove a MAC address from port_id.\n\n"
479
480                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Set the default MAC address for port_id.\n\n"
482
483                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
484                         "    Add a MAC address for a VF on the port.\n\n"
485
486                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
487                         "    Set the MAC address for a VF from the PF.\n\n"
488
489                         "set port (port_id) uta (mac_address|all) (on|off)\n"
490                         "    Add/Remove a or all unicast hash filter(s)"
491                         "from port X.\n\n"
492
493                         "set promisc (port_id|all) (on|off)\n"
494                         "    Set the promiscuous mode on port_id, or all.\n\n"
495
496                         "set allmulti (port_id|all) (on|off)\n"
497                         "    Set the allmulti mode on port_id, or all.\n\n"
498
499                         "set vf promisc (port_id) (vf_id) (on|off)\n"
500                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
501
502                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
503                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
504
505                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
506                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
507                         " (on|off) autoneg (on|off) (port_id)\n"
508                         "set flow_ctrl rx (on|off) (portid)\n"
509                         "set flow_ctrl tx (on|off) (portid)\n"
510                         "set flow_ctrl high_water (high_water) (portid)\n"
511                         "set flow_ctrl low_water (low_water) (portid)\n"
512                         "set flow_ctrl pause_time (pause_time) (portid)\n"
513                         "set flow_ctrl send_xon (send_xon) (portid)\n"
514                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
515                         "set flow_ctrl autoneg (on|off) (port_id)\n"
516                         "    Set the link flow control parameter on a port.\n\n"
517
518                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
519                         " (low_water) (pause_time) (priority) (port_id)\n"
520                         "    Set the priority flow control parameter on a"
521                         " port.\n\n"
522
523                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
524                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
525                         " queue on port.\n"
526                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
527                         " on port 0 to mapping 5.\n\n"
528
529                         "set xstats-hide-zero on|off\n"
530                         "    Set the option to hide the zero values"
531                         " for xstats display.\n"
532
533                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
534                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
535
536                         "set port (port_id) vf (vf_id) (mac_addr)"
537                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
538                         "   Add/Remove unicast or multicast MAC addr filter"
539                         " for a VF.\n\n"
540
541                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
542                         "|MPE) (on|off)\n"
543                         "    AUPE:accepts untagged VLAN;"
544                         "ROPE:accept unicast hash\n\n"
545                         "    BAM:accepts broadcast packets;"
546                         "MPE:accepts all multicast packets\n\n"
547                         "    Enable/Disable a VF receive mode of a port\n\n"
548
549                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
550                         "    Set rate limit for a queue of a port\n\n"
551
552                         "set port (port_id) vf (vf_id) rate (rate_num) "
553                         "queue_mask (queue_mask_value)\n"
554                         "    Set rate limit for queues in VF of a port\n\n"
555
556                         "set port (port_id) mirror-rule (rule_id)"
557                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
558                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
559                         "   Set pool or vlan type mirror rule on a port.\n"
560                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
561                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
562                         " to pool 0.\n\n"
563
564                         "set port (port_id) mirror-rule (rule_id)"
565                         " (uplink-mirror|downlink-mirror) dst-pool"
566                         " (pool_id) (on|off)\n"
567                         "   Set uplink or downlink type mirror rule on a port.\n"
568                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
569                         " 0 on' enable mirror income traffic to pool 0.\n\n"
570
571                         "reset port (port_id) mirror-rule (rule_id)\n"
572                         "   Reset a mirror rule.\n\n"
573
574                         "set flush_rx (on|off)\n"
575                         "   Flush (default) or don't flush RX streams before"
576                         " forwarding. Mainly used with PCAP drivers.\n\n"
577
578                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
579                         "   Set the bypass mode for the lowest port on bypass enabled"
580                         " NIC.\n\n"
581
582                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
583                         "mode (normal|bypass|isolate) (port_id)\n"
584                         "   Set the event required to initiate specified bypass mode for"
585                         " the lowest port on a bypass enabled NIC where:\n"
586                         "       timeout   = enable bypass after watchdog timeout.\n"
587                         "       os_on     = enable bypass when OS/board is powered on.\n"
588                         "       os_off    = enable bypass when OS/board is powered off.\n"
589                         "       power_on  = enable bypass when power supply is turned on.\n"
590                         "       power_off = enable bypass when power supply is turned off."
591                         "\n\n"
592
593                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
594                         "   Set the bypass watchdog timeout to 'n' seconds"
595                         " where 0 = instant.\n\n"
596
597                         "show bypass config (port_id)\n"
598                         "   Show the bypass configuration for a bypass enabled NIC"
599                         " using the lowest port on the NIC.\n\n"
600
601 #ifdef RTE_LIBRTE_PMD_BOND
602                         "create bonded device (mode) (socket)\n"
603                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
604
605                         "add bonding slave (slave_id) (port_id)\n"
606                         "       Add a slave device to a bonded device.\n\n"
607
608                         "remove bonding slave (slave_id) (port_id)\n"
609                         "       Remove a slave device from a bonded device.\n\n"
610
611                         "set bonding mode (value) (port_id)\n"
612                         "       Set the bonding mode on a bonded device.\n\n"
613
614                         "set bonding primary (slave_id) (port_id)\n"
615                         "       Set the primary slave for a bonded device.\n\n"
616
617                         "show bonding config (port_id)\n"
618                         "       Show the bonding config for port_id.\n\n"
619
620                         "set bonding mac_addr (port_id) (address)\n"
621                         "       Set the MAC address of a bonded device.\n\n"
622
623                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
624                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
625
626                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
627                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
628
629                         "set bonding mon_period (port_id) (value)\n"
630                         "       Set the bonding link status monitoring polling period in ms.\n\n"
631
632                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
633                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
634
635 #endif
636                         "set link-up port (port_id)\n"
637                         "       Set link up for a port.\n\n"
638
639                         "set link-down port (port_id)\n"
640                         "       Set link down for a port.\n\n"
641
642                         "E-tag set insertion on port-tag-id (value)"
643                         " port (port_id) vf (vf_id)\n"
644                         "    Enable E-tag insertion for a VF on a port\n\n"
645
646                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
647                         "    Disable E-tag insertion for a VF on a port\n\n"
648
649                         "E-tag set stripping (on|off) port (port_id)\n"
650                         "    Enable/disable E-tag stripping on a port\n\n"
651
652                         "E-tag set forwarding (on|off) port (port_id)\n"
653                         "    Enable/disable E-tag based forwarding"
654                         " on a port\n\n"
655
656                         "E-tag set filter add e-tag-id (value) dst-pool"
657                         " (pool_id) port (port_id)\n"
658                         "    Add an E-tag forwarding filter on a port\n\n"
659
660                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
661                         "    Delete an E-tag forwarding filter on a port\n\n"
662
663 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
664                         "set port tm hierarchy default (port_id)\n"
665                         "       Set default traffic Management hierarchy on a port\n\n"
666
667 #endif
668                         "ddp add (port_id) (profile_path[,output_path])\n"
669                         "    Load a profile package on a port\n\n"
670
671                         "ddp del (port_id) (profile_path)\n"
672                         "    Delete a profile package from a port\n\n"
673
674                         "ptype mapping get (port_id) (valid_only)\n"
675                         "    Get ptype mapping on a port\n\n"
676
677                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
678                         "    Replace target with the pkt_type in ptype mapping\n\n"
679
680                         "ptype mapping reset (port_id)\n"
681                         "    Reset ptype mapping on a port\n\n"
682
683                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
684                         "    Update a ptype mapping item on a port\n\n"
685
686                         "set port (port_id) queue-region region_id (value) "
687                         "queue_start_index (value) queue_num (value)\n"
688                         "    Set a queue region on a port\n\n"
689
690                         "set port (port_id) queue-region region_id (value) "
691                         "flowtype (value)\n"
692                         "    Set a flowtype region index on a port\n\n"
693
694                         "set port (port_id) queue-region UP (value) region_id (value)\n"
695                         "    Set the mapping of User Priority to "
696                         "queue region on a port\n\n"
697
698                         "set port (port_id) queue-region flush (on|off)\n"
699                         "    flush all queue region related configuration\n\n"
700
701                         "show port meter cap (port_id)\n"
702                         "    Show port meter capability information\n\n"
703
704                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
705                         "    meter profile add - srtcm rfc 2697\n\n"
706
707                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
708                         "    meter profile add - trtcm rfc 2698\n\n"
709
710                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
711                         "    meter profile add - trtcm rfc 4115\n\n"
712
713                         "del port meter profile (port_id) (profile_id)\n"
714                         "    meter profile delete\n\n"
715
716                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
717                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
718                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
719                         "(dscp_tbl_entry63)]\n"
720                         "    meter create\n\n"
721
722                         "enable port meter (port_id) (mtr_id)\n"
723                         "    meter enable\n\n"
724
725                         "disable port meter (port_id) (mtr_id)\n"
726                         "    meter disable\n\n"
727
728                         "del port meter (port_id) (mtr_id)\n"
729                         "    meter delete\n\n"
730
731                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
732                         "    meter update meter profile\n\n"
733
734                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
735                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
736                         "    update meter dscp table entries\n\n"
737
738                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
739                         "(action0) [(action1) (action2)]\n"
740                         "    meter update policer action\n\n"
741
742                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
743                         "    meter update stats\n\n"
744
745                         "show port (port_id) queue-region\n"
746                         "    show all queue region related configuration info\n\n"
747
748                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
749                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
750                         "       Add port tm node private shaper profile.\n\n"
751
752                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
753                         "       Delete port tm node private shaper profile.\n\n"
754
755                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
756                         " (shaper_profile_id)\n"
757                         "       Add/update port tm node shared shaper.\n\n"
758
759                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
760                         "       Delete port tm node shared shaper.\n\n"
761
762                         "set port tm node shaper profile (port_id) (node_id)"
763                         " (shaper_profile_id)\n"
764                         "       Set port tm node shaper profile.\n\n"
765
766                         "add port tm node wred profile (port_id) (wred_profile_id)"
767                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
768                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
769                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
770                         "       Add port tm node wred profile.\n\n"
771
772                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
773                         "       Delete port tm node wred profile.\n\n"
774
775                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
776                         " (priority) (weight) (level_id) (shaper_profile_id)"
777                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
778                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
779                         "       Add port tm nonleaf node.\n\n"
780
781                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
782                         " (priority) (weight) (level_id) (shaper_profile_id)"
783                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
784                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
785                         "       Add port tm leaf node.\n\n"
786
787                         "del port tm node (port_id) (node_id)\n"
788                         "       Delete port tm node.\n\n"
789
790                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
791                         " (priority) (weight)\n"
792                         "       Set port tm node parent.\n\n"
793
794                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
795                         "       Commit tm hierarchy.\n\n"
796
797                         , list_pkt_forwarding_modes()
798                 );
799         }
800
801         if (show_all || !strcmp(res->section, "ports")) {
802
803                 cmdline_printf(
804                         cl,
805                         "\n"
806                         "Port Operations:\n"
807                         "----------------\n\n"
808
809                         "port start (port_id|all)\n"
810                         "    Start all ports or port_id.\n\n"
811
812                         "port stop (port_id|all)\n"
813                         "    Stop all ports or port_id.\n\n"
814
815                         "port close (port_id|all)\n"
816                         "    Close all ports or port_id.\n\n"
817
818                         "port attach (ident)\n"
819                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
820
821                         "port detach (port_id)\n"
822                         "    Detach physical or virtual dev by port_id\n\n"
823
824                         "port config (port_id|all)"
825                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
826                         " duplex (half|full|auto)\n"
827                         "    Set speed and duplex for all ports or port_id\n\n"
828
829                         "port config all (rxq|txq|rxd|txd) (value)\n"
830                         "    Set number for rxq/txq/rxd/txd.\n\n"
831
832                         "port config all max-pkt-len (value)\n"
833                         "    Set the max packet length.\n\n"
834
835                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
836                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
837                         " (on|off)\n"
838                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
839                         " for ports.\n\n"
840
841                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
842                         "geneve|nvgre|none|<flowtype_id>)\n"
843                         "    Set the RSS mode.\n\n"
844
845                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
846                         "    Set the RSS redirection table.\n\n"
847
848                         "port config (port_id) dcb vt (on|off) (traffic_class)"
849                         " pfc (on|off)\n"
850                         "    Set the DCB mode.\n\n"
851
852                         "port config all burst (value)\n"
853                         "    Set the number of packets per burst.\n\n"
854
855                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
856                         " (value)\n"
857                         "    Set the ring prefetch/host/writeback threshold"
858                         " for tx/rx queue.\n\n"
859
860                         "port config all (txfreet|txrst|rxfreet) (value)\n"
861                         "    Set free threshold for rx/tx, or set"
862                         " tx rs bit threshold.\n\n"
863                         "port config mtu X value\n"
864                         "    Set the MTU of port X to a given value\n\n"
865
866                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
867                         "    Start/stop a rx/tx queue of port X. Only take effect"
868                         " when port X is started\n\n"
869
870                         "port config (port_id|all) l2-tunnel E-tag ether-type"
871                         " (value)\n"
872                         "    Set the value of E-tag ether-type.\n\n"
873
874                         "port config (port_id|all) l2-tunnel E-tag"
875                         " (enable|disable)\n"
876                         "    Enable/disable the E-tag support.\n\n"
877
878                         "port config (port_id) pctype mapping reset\n"
879                         "    Reset flow type to pctype mapping on a port\n\n"
880
881                         "port config (port_id) pctype mapping update"
882                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
883                         "    Update a flow type to pctype mapping item on a port\n\n"
884                 );
885         }
886
887         if (show_all || !strcmp(res->section, "registers")) {
888
889                 cmdline_printf(
890                         cl,
891                         "\n"
892                         "Registers:\n"
893                         "----------\n\n"
894
895                         "read reg (port_id) (address)\n"
896                         "    Display value of a port register.\n\n"
897
898                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
899                         "    Display a port register bit field.\n\n"
900
901                         "read regbit (port_id) (address) (bit_x)\n"
902                         "    Display a single port register bit.\n\n"
903
904                         "write reg (port_id) (address) (value)\n"
905                         "    Set value of a port register.\n\n"
906
907                         "write regfield (port_id) (address) (bit_x) (bit_y)"
908                         " (value)\n"
909                         "    Set bit field of a port register.\n\n"
910
911                         "write regbit (port_id) (address) (bit_x) (value)\n"
912                         "    Set single bit value of a port register.\n\n"
913                 );
914         }
915         if (show_all || !strcmp(res->section, "filters")) {
916
917                 cmdline_printf(
918                         cl,
919                         "\n"
920                         "filters:\n"
921                         "--------\n\n"
922
923                         "ethertype_filter (port_id) (add|del)"
924                         " (mac_addr|mac_ignr) (mac_address) ethertype"
925                         " (ether_type) (drop|fwd) queue (queue_id)\n"
926                         "    Add/Del an ethertype filter.\n\n"
927
928                         "2tuple_filter (port_id) (add|del)"
929                         " dst_port (dst_port_value) protocol (protocol_value)"
930                         " mask (mask_value) tcp_flags (tcp_flags_value)"
931                         " priority (prio_value) queue (queue_id)\n"
932                         "    Add/Del a 2tuple filter.\n\n"
933
934                         "5tuple_filter (port_id) (add|del)"
935                         " dst_ip (dst_address) src_ip (src_address)"
936                         " dst_port (dst_port_value) src_port (src_port_value)"
937                         " protocol (protocol_value)"
938                         " mask (mask_value) tcp_flags (tcp_flags_value)"
939                         " priority (prio_value) queue (queue_id)\n"
940                         "    Add/Del a 5tuple filter.\n\n"
941
942                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
943                         "    Add/Del syn filter.\n\n"
944
945                         "flex_filter (port_id) (add|del) len (len_value)"
946                         " bytes (bytes_value) mask (mask_value)"
947                         " priority (prio_value) queue (queue_id)\n"
948                         "    Add/Del a flex filter.\n\n"
949
950                         "flow_director_filter (port_id) mode IP (add|del|update)"
951                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
952                         " src (src_ip_address) dst (dst_ip_address)"
953                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
954                         " vlan (vlan_value) flexbytes (flexbytes_value)"
955                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
956                         " fd_id (fd_id_value)\n"
957                         "    Add/Del an IP type flow director filter.\n\n"
958
959                         "flow_director_filter (port_id) mode IP (add|del|update)"
960                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
961                         " src (src_ip_address) (src_port)"
962                         " dst (dst_ip_address) (dst_port)"
963                         " tos (tos_value) ttl (ttl_value)"
964                         " vlan (vlan_value) flexbytes (flexbytes_value)"
965                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
966                         " fd_id (fd_id_value)\n"
967                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
968
969                         "flow_director_filter (port_id) mode IP (add|del|update)"
970                         " flow (ipv4-sctp|ipv6-sctp)"
971                         " src (src_ip_address) (src_port)"
972                         " dst (dst_ip_address) (dst_port)"
973                         " tag (verification_tag) "
974                         " tos (tos_value) ttl (ttl_value)"
975                         " vlan (vlan_value)"
976                         " flexbytes (flexbytes_value) (drop|fwd)"
977                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
978                         "    Add/Del a SCTP type flow director filter.\n\n"
979
980                         "flow_director_filter (port_id) mode IP (add|del|update)"
981                         " flow l2_payload ether (ethertype)"
982                         " flexbytes (flexbytes_value) (drop|fwd)"
983                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
984                         "    Add/Del a l2 payload type flow director filter.\n\n"
985
986                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
987                         " mac (mac_address) vlan (vlan_value)"
988                         " flexbytes (flexbytes_value) (drop|fwd)"
989                         " queue (queue_id) fd_id (fd_id_value)\n"
990                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
991
992                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
993                         " mac (mac_address) vlan (vlan_value)"
994                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
995                         " flexbytes (flexbytes_value) (drop|fwd)"
996                         " queue (queue_id) fd_id (fd_id_value)\n"
997                         "    Add/Del a Tunnel flow director filter.\n\n"
998
999                         "flush_flow_director (port_id)\n"
1000                         "    Flush all flow director entries of a device.\n\n"
1001
1002                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1003                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1004                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1005                         "    Set flow director IP mask.\n\n"
1006
1007                         "flow_director_mask (port_id) mode MAC-VLAN"
1008                         " vlan (vlan_value)\n"
1009                         "    Set flow director MAC-VLAN mask.\n\n"
1010
1011                         "flow_director_mask (port_id) mode Tunnel"
1012                         " vlan (vlan_value) mac (mac_value)"
1013                         " tunnel-type (tunnel_type_value)"
1014                         " tunnel-id (tunnel_id_value)\n"
1015                         "    Set flow director Tunnel mask.\n\n"
1016
1017                         "flow_director_flex_mask (port_id)"
1018                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1019                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1020                         " (mask)\n"
1021                         "    Configure mask of flex payload.\n\n"
1022
1023                         "flow_director_flex_payload (port_id)"
1024                         " (raw|l2|l3|l4) (config)\n"
1025                         "    Configure flex payload selection.\n\n"
1026
1027                         "get_sym_hash_ena_per_port (port_id)\n"
1028                         "    get symmetric hash enable configuration per port.\n\n"
1029
1030                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1031                         "    set symmetric hash enable configuration per port"
1032                         " to enable or disable.\n\n"
1033
1034                         "get_hash_global_config (port_id)\n"
1035                         "    Get the global configurations of hash filters.\n\n"
1036
1037                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1038                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1039                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1040                         " (enable|disable)\n"
1041                         "    Set the global configurations of hash filters.\n\n"
1042
1043                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1044                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1045                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1046                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1047                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1048                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1049                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1050                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1051                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1052                         "fld-8th|none) (select|add)\n"
1053                         "    Set the input set for hash.\n\n"
1054
1055                         "set_fdir_input_set (port_id) "
1056                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1057                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1058                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1059                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1060                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1061                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1062                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1063                         " (select|add)\n"
1064                         "    Set the input set for FDir.\n\n"
1065
1066                         "flow validate {port_id}"
1067                         " [group {group_id}] [priority {level}]"
1068                         " [ingress] [egress]"
1069                         " pattern {item} [/ {item} [...]] / end"
1070                         " actions {action} [/ {action} [...]] / end\n"
1071                         "    Check whether a flow rule can be created.\n\n"
1072
1073                         "flow create {port_id}"
1074                         " [group {group_id}] [priority {level}]"
1075                         " [ingress] [egress]"
1076                         " pattern {item} [/ {item} [...]] / end"
1077                         " actions {action} [/ {action} [...]] / end\n"
1078                         "    Create a flow rule.\n\n"
1079
1080                         "flow destroy {port_id} rule {rule_id} [...]\n"
1081                         "    Destroy specific flow rules.\n\n"
1082
1083                         "flow flush {port_id}\n"
1084                         "    Destroy all flow rules.\n\n"
1085
1086                         "flow query {port_id} {rule_id} {action}\n"
1087                         "    Query an existing flow rule.\n\n"
1088
1089                         "flow list {port_id} [group {group_id}] [...]\n"
1090                         "    List existing flow rules sorted by priority,"
1091                         " filtered by group identifiers.\n\n"
1092
1093                         "flow isolate {port_id} {boolean}\n"
1094                         "    Restrict ingress traffic to the defined"
1095                         " flow rules\n\n"
1096                 );
1097         }
1098 }
1099
1100 cmdline_parse_token_string_t cmd_help_long_help =
1101         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1102
1103 cmdline_parse_token_string_t cmd_help_long_section =
1104         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1105                         "all#control#display#config#"
1106                         "ports#registers#filters");
1107
1108 cmdline_parse_inst_t cmd_help_long = {
1109         .f = cmd_help_long_parsed,
1110         .data = NULL,
1111         .help_str = "help all|control|display|config|ports|register|filters: "
1112                 "Show help",
1113         .tokens = {
1114                 (void *)&cmd_help_long_help,
1115                 (void *)&cmd_help_long_section,
1116                 NULL,
1117         },
1118 };
1119
1120
1121 /* *** start/stop/close all ports *** */
1122 struct cmd_operate_port_result {
1123         cmdline_fixed_string_t keyword;
1124         cmdline_fixed_string_t name;
1125         cmdline_fixed_string_t value;
1126 };
1127
1128 static void cmd_operate_port_parsed(void *parsed_result,
1129                                 __attribute__((unused)) struct cmdline *cl,
1130                                 __attribute__((unused)) void *data)
1131 {
1132         struct cmd_operate_port_result *res = parsed_result;
1133
1134         if (!strcmp(res->name, "start"))
1135                 start_port(RTE_PORT_ALL);
1136         else if (!strcmp(res->name, "stop"))
1137                 stop_port(RTE_PORT_ALL);
1138         else if (!strcmp(res->name, "close"))
1139                 close_port(RTE_PORT_ALL);
1140         else if (!strcmp(res->name, "reset"))
1141                 reset_port(RTE_PORT_ALL);
1142         else
1143                 printf("Unknown parameter\n");
1144 }
1145
1146 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1147         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1148                                                                 "port");
1149 cmdline_parse_token_string_t cmd_operate_port_all_port =
1150         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1151                                                 "start#stop#close#reset");
1152 cmdline_parse_token_string_t cmd_operate_port_all_all =
1153         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1154
1155 cmdline_parse_inst_t cmd_operate_port = {
1156         .f = cmd_operate_port_parsed,
1157         .data = NULL,
1158         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1159         .tokens = {
1160                 (void *)&cmd_operate_port_all_cmd,
1161                 (void *)&cmd_operate_port_all_port,
1162                 (void *)&cmd_operate_port_all_all,
1163                 NULL,
1164         },
1165 };
1166
1167 /* *** start/stop/close specific port *** */
1168 struct cmd_operate_specific_port_result {
1169         cmdline_fixed_string_t keyword;
1170         cmdline_fixed_string_t name;
1171         uint8_t value;
1172 };
1173
1174 static void cmd_operate_specific_port_parsed(void *parsed_result,
1175                         __attribute__((unused)) struct cmdline *cl,
1176                                 __attribute__((unused)) void *data)
1177 {
1178         struct cmd_operate_specific_port_result *res = parsed_result;
1179
1180         if (!strcmp(res->name, "start"))
1181                 start_port(res->value);
1182         else if (!strcmp(res->name, "stop"))
1183                 stop_port(res->value);
1184         else if (!strcmp(res->name, "close"))
1185                 close_port(res->value);
1186         else if (!strcmp(res->name, "reset"))
1187                 reset_port(res->value);
1188         else
1189                 printf("Unknown parameter\n");
1190 }
1191
1192 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1193         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1194                                                         keyword, "port");
1195 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1196         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1197                                                 name, "start#stop#close#reset");
1198 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1199         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1200                                                         value, UINT8);
1201
1202 cmdline_parse_inst_t cmd_operate_specific_port = {
1203         .f = cmd_operate_specific_port_parsed,
1204         .data = NULL,
1205         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1206         .tokens = {
1207                 (void *)&cmd_operate_specific_port_cmd,
1208                 (void *)&cmd_operate_specific_port_port,
1209                 (void *)&cmd_operate_specific_port_id,
1210                 NULL,
1211         },
1212 };
1213
1214 /* *** attach a specified port *** */
1215 struct cmd_operate_attach_port_result {
1216         cmdline_fixed_string_t port;
1217         cmdline_fixed_string_t keyword;
1218         cmdline_fixed_string_t identifier;
1219 };
1220
1221 static void cmd_operate_attach_port_parsed(void *parsed_result,
1222                                 __attribute__((unused)) struct cmdline *cl,
1223                                 __attribute__((unused)) void *data)
1224 {
1225         struct cmd_operate_attach_port_result *res = parsed_result;
1226
1227         if (!strcmp(res->keyword, "attach"))
1228                 attach_port(res->identifier);
1229         else
1230                 printf("Unknown parameter\n");
1231 }
1232
1233 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1234         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1235                         port, "port");
1236 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1237         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1238                         keyword, "attach");
1239 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1240         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1241                         identifier, NULL);
1242
1243 cmdline_parse_inst_t cmd_operate_attach_port = {
1244         .f = cmd_operate_attach_port_parsed,
1245         .data = NULL,
1246         .help_str = "port attach <identifier>: "
1247                 "(identifier: pci address or virtual dev name)",
1248         .tokens = {
1249                 (void *)&cmd_operate_attach_port_port,
1250                 (void *)&cmd_operate_attach_port_keyword,
1251                 (void *)&cmd_operate_attach_port_identifier,
1252                 NULL,
1253         },
1254 };
1255
1256 /* *** detach a specified port *** */
1257 struct cmd_operate_detach_port_result {
1258         cmdline_fixed_string_t port;
1259         cmdline_fixed_string_t keyword;
1260         portid_t port_id;
1261 };
1262
1263 static void cmd_operate_detach_port_parsed(void *parsed_result,
1264                                 __attribute__((unused)) struct cmdline *cl,
1265                                 __attribute__((unused)) void *data)
1266 {
1267         struct cmd_operate_detach_port_result *res = parsed_result;
1268
1269         if (!strcmp(res->keyword, "detach"))
1270                 detach_port(res->port_id);
1271         else
1272                 printf("Unknown parameter\n");
1273 }
1274
1275 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1276         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1277                         port, "port");
1278 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1279         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1280                         keyword, "detach");
1281 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1282         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1283                         port_id, UINT16);
1284
1285 cmdline_parse_inst_t cmd_operate_detach_port = {
1286         .f = cmd_operate_detach_port_parsed,
1287         .data = NULL,
1288         .help_str = "port detach <port_id>",
1289         .tokens = {
1290                 (void *)&cmd_operate_detach_port_port,
1291                 (void *)&cmd_operate_detach_port_keyword,
1292                 (void *)&cmd_operate_detach_port_port_id,
1293                 NULL,
1294         },
1295 };
1296
1297 /* *** configure speed for all ports *** */
1298 struct cmd_config_speed_all {
1299         cmdline_fixed_string_t port;
1300         cmdline_fixed_string_t keyword;
1301         cmdline_fixed_string_t all;
1302         cmdline_fixed_string_t item1;
1303         cmdline_fixed_string_t item2;
1304         cmdline_fixed_string_t value1;
1305         cmdline_fixed_string_t value2;
1306 };
1307
1308 static int
1309 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1310 {
1311
1312         int duplex;
1313
1314         if (!strcmp(duplexstr, "half")) {
1315                 duplex = ETH_LINK_HALF_DUPLEX;
1316         } else if (!strcmp(duplexstr, "full")) {
1317                 duplex = ETH_LINK_FULL_DUPLEX;
1318         } else if (!strcmp(duplexstr, "auto")) {
1319                 duplex = ETH_LINK_FULL_DUPLEX;
1320         } else {
1321                 printf("Unknown duplex parameter\n");
1322                 return -1;
1323         }
1324
1325         if (!strcmp(speedstr, "10")) {
1326                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1327                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1328         } else if (!strcmp(speedstr, "100")) {
1329                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1330                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1331         } else {
1332                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1333                         printf("Invalid speed/duplex parameters\n");
1334                         return -1;
1335                 }
1336                 if (!strcmp(speedstr, "1000")) {
1337                         *speed = ETH_LINK_SPEED_1G;
1338                 } else if (!strcmp(speedstr, "10000")) {
1339                         *speed = ETH_LINK_SPEED_10G;
1340                 } else if (!strcmp(speedstr, "25000")) {
1341                         *speed = ETH_LINK_SPEED_25G;
1342                 } else if (!strcmp(speedstr, "40000")) {
1343                         *speed = ETH_LINK_SPEED_40G;
1344                 } else if (!strcmp(speedstr, "50000")) {
1345                         *speed = ETH_LINK_SPEED_50G;
1346                 } else if (!strcmp(speedstr, "100000")) {
1347                         *speed = ETH_LINK_SPEED_100G;
1348                 } else if (!strcmp(speedstr, "auto")) {
1349                         *speed = ETH_LINK_SPEED_AUTONEG;
1350                 } else {
1351                         printf("Unknown speed parameter\n");
1352                         return -1;
1353                 }
1354         }
1355
1356         return 0;
1357 }
1358
1359 static void
1360 cmd_config_speed_all_parsed(void *parsed_result,
1361                         __attribute__((unused)) struct cmdline *cl,
1362                         __attribute__((unused)) void *data)
1363 {
1364         struct cmd_config_speed_all *res = parsed_result;
1365         uint32_t link_speed;
1366         portid_t pid;
1367
1368         if (!all_ports_stopped()) {
1369                 printf("Please stop all ports first\n");
1370                 return;
1371         }
1372
1373         if (parse_and_check_speed_duplex(res->value1, res->value2,
1374                         &link_speed) < 0)
1375                 return;
1376
1377         RTE_ETH_FOREACH_DEV(pid) {
1378                 ports[pid].dev_conf.link_speeds = link_speed;
1379         }
1380
1381         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1382 }
1383
1384 cmdline_parse_token_string_t cmd_config_speed_all_port =
1385         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1386 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1387         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1388                                                         "config");
1389 cmdline_parse_token_string_t cmd_config_speed_all_all =
1390         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1391 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1392         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1393 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1394         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1395                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1396 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1397         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1398 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1399         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1400                                                 "half#full#auto");
1401
1402 cmdline_parse_inst_t cmd_config_speed_all = {
1403         .f = cmd_config_speed_all_parsed,
1404         .data = NULL,
1405         .help_str = "port config all speed "
1406                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1407                                                         "half|full|auto",
1408         .tokens = {
1409                 (void *)&cmd_config_speed_all_port,
1410                 (void *)&cmd_config_speed_all_keyword,
1411                 (void *)&cmd_config_speed_all_all,
1412                 (void *)&cmd_config_speed_all_item1,
1413                 (void *)&cmd_config_speed_all_value1,
1414                 (void *)&cmd_config_speed_all_item2,
1415                 (void *)&cmd_config_speed_all_value2,
1416                 NULL,
1417         },
1418 };
1419
1420 /* *** configure speed for specific port *** */
1421 struct cmd_config_speed_specific {
1422         cmdline_fixed_string_t port;
1423         cmdline_fixed_string_t keyword;
1424         uint8_t id;
1425         cmdline_fixed_string_t item1;
1426         cmdline_fixed_string_t item2;
1427         cmdline_fixed_string_t value1;
1428         cmdline_fixed_string_t value2;
1429 };
1430
1431 static void
1432 cmd_config_speed_specific_parsed(void *parsed_result,
1433                                 __attribute__((unused)) struct cmdline *cl,
1434                                 __attribute__((unused)) void *data)
1435 {
1436         struct cmd_config_speed_specific *res = parsed_result;
1437         uint32_t link_speed;
1438
1439         if (!all_ports_stopped()) {
1440                 printf("Please stop all ports first\n");
1441                 return;
1442         }
1443
1444         if (port_id_is_invalid(res->id, ENABLED_WARN))
1445                 return;
1446
1447         if (parse_and_check_speed_duplex(res->value1, res->value2,
1448                         &link_speed) < 0)
1449                 return;
1450
1451         ports[res->id].dev_conf.link_speeds = link_speed;
1452
1453         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1454 }
1455
1456
1457 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1458         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1459                                                                 "port");
1460 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1461         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1462                                                                 "config");
1463 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1464         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1465 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1467                                                                 "speed");
1468 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1470                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1471 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1472         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1473                                                                 "duplex");
1474 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1475         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1476                                                         "half#full#auto");
1477
1478 cmdline_parse_inst_t cmd_config_speed_specific = {
1479         .f = cmd_config_speed_specific_parsed,
1480         .data = NULL,
1481         .help_str = "port config <port_id> speed "
1482                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1483                                                         "half|full|auto",
1484         .tokens = {
1485                 (void *)&cmd_config_speed_specific_port,
1486                 (void *)&cmd_config_speed_specific_keyword,
1487                 (void *)&cmd_config_speed_specific_id,
1488                 (void *)&cmd_config_speed_specific_item1,
1489                 (void *)&cmd_config_speed_specific_value1,
1490                 (void *)&cmd_config_speed_specific_item2,
1491                 (void *)&cmd_config_speed_specific_value2,
1492                 NULL,
1493         },
1494 };
1495
1496 /* *** configure txq/rxq, txd/rxd *** */
1497 struct cmd_config_rx_tx {
1498         cmdline_fixed_string_t port;
1499         cmdline_fixed_string_t keyword;
1500         cmdline_fixed_string_t all;
1501         cmdline_fixed_string_t name;
1502         uint16_t value;
1503 };
1504
1505 static void
1506 cmd_config_rx_tx_parsed(void *parsed_result,
1507                         __attribute__((unused)) struct cmdline *cl,
1508                         __attribute__((unused)) void *data)
1509 {
1510         struct cmd_config_rx_tx *res = parsed_result;
1511
1512         if (!all_ports_stopped()) {
1513                 printf("Please stop all ports first\n");
1514                 return;
1515         }
1516         if (!strcmp(res->name, "rxq")) {
1517                 if (!res->value && !nb_txq) {
1518                         printf("Warning: Either rx or tx queues should be non zero\n");
1519                         return;
1520                 }
1521                 nb_rxq = res->value;
1522         }
1523         else if (!strcmp(res->name, "txq")) {
1524                 if (!res->value && !nb_rxq) {
1525                         printf("Warning: Either rx or tx queues should be non zero\n");
1526                         return;
1527                 }
1528                 nb_txq = res->value;
1529         }
1530         else if (!strcmp(res->name, "rxd")) {
1531                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1532                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1533                                         res->value, RTE_TEST_RX_DESC_MAX);
1534                         return;
1535                 }
1536                 nb_rxd = res->value;
1537         } else if (!strcmp(res->name, "txd")) {
1538                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1539                         printf("txd %d invalid - must be > 0 && <= %d\n",
1540                                         res->value, RTE_TEST_TX_DESC_MAX);
1541                         return;
1542                 }
1543                 nb_txd = res->value;
1544         } else {
1545                 printf("Unknown parameter\n");
1546                 return;
1547         }
1548
1549         fwd_config_setup();
1550
1551         init_port_config();
1552
1553         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1554 }
1555
1556 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1557         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1558 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1559         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1560 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1561         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1562 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1563         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1564                                                 "rxq#txq#rxd#txd");
1565 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1566         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1567
1568 cmdline_parse_inst_t cmd_config_rx_tx = {
1569         .f = cmd_config_rx_tx_parsed,
1570         .data = NULL,
1571         .help_str = "port config all rxq|txq|rxd|txd <value>",
1572         .tokens = {
1573                 (void *)&cmd_config_rx_tx_port,
1574                 (void *)&cmd_config_rx_tx_keyword,
1575                 (void *)&cmd_config_rx_tx_all,
1576                 (void *)&cmd_config_rx_tx_name,
1577                 (void *)&cmd_config_rx_tx_value,
1578                 NULL,
1579         },
1580 };
1581
1582 /* *** config max packet length *** */
1583 struct cmd_config_max_pkt_len_result {
1584         cmdline_fixed_string_t port;
1585         cmdline_fixed_string_t keyword;
1586         cmdline_fixed_string_t all;
1587         cmdline_fixed_string_t name;
1588         uint32_t value;
1589 };
1590
1591 static void
1592 cmd_config_max_pkt_len_parsed(void *parsed_result,
1593                                 __attribute__((unused)) struct cmdline *cl,
1594                                 __attribute__((unused)) void *data)
1595 {
1596         struct cmd_config_max_pkt_len_result *res = parsed_result;
1597         uint64_t rx_offloads = rx_mode.offloads;
1598
1599         if (!all_ports_stopped()) {
1600                 printf("Please stop all ports first\n");
1601                 return;
1602         }
1603
1604         if (!strcmp(res->name, "max-pkt-len")) {
1605                 if (res->value < ETHER_MIN_LEN) {
1606                         printf("max-pkt-len can not be less than %d\n",
1607                                                         ETHER_MIN_LEN);
1608                         return;
1609                 }
1610                 if (res->value == rx_mode.max_rx_pkt_len)
1611                         return;
1612
1613                 rx_mode.max_rx_pkt_len = res->value;
1614                 if (res->value > ETHER_MAX_LEN)
1615                         rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1616                 else
1617                         rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1618         } else {
1619                 printf("Unknown parameter\n");
1620                 return;
1621         }
1622
1623         rx_mode.offloads = rx_offloads;
1624
1625         init_port_config();
1626
1627         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1628 }
1629
1630 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1631         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1632                                                                 "port");
1633 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1634         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1635                                                                 "config");
1636 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1637         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1638                                                                 "all");
1639 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1640         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1641                                                                 "max-pkt-len");
1642 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1643         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1644                                                                 UINT32);
1645
1646 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1647         .f = cmd_config_max_pkt_len_parsed,
1648         .data = NULL,
1649         .help_str = "port config all max-pkt-len <value>",
1650         .tokens = {
1651                 (void *)&cmd_config_max_pkt_len_port,
1652                 (void *)&cmd_config_max_pkt_len_keyword,
1653                 (void *)&cmd_config_max_pkt_len_all,
1654                 (void *)&cmd_config_max_pkt_len_name,
1655                 (void *)&cmd_config_max_pkt_len_value,
1656                 NULL,
1657         },
1658 };
1659
1660 /* *** configure port MTU *** */
1661 struct cmd_config_mtu_result {
1662         cmdline_fixed_string_t port;
1663         cmdline_fixed_string_t keyword;
1664         cmdline_fixed_string_t mtu;
1665         portid_t port_id;
1666         uint16_t value;
1667 };
1668
1669 static void
1670 cmd_config_mtu_parsed(void *parsed_result,
1671                       __attribute__((unused)) struct cmdline *cl,
1672                       __attribute__((unused)) void *data)
1673 {
1674         struct cmd_config_mtu_result *res = parsed_result;
1675
1676         if (res->value < ETHER_MIN_LEN) {
1677                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1678                 return;
1679         }
1680         port_mtu_set(res->port_id, res->value);
1681 }
1682
1683 cmdline_parse_token_string_t cmd_config_mtu_port =
1684         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1685                                  "port");
1686 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1687         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1688                                  "config");
1689 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1690         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1691                                  "mtu");
1692 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1693         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1694 cmdline_parse_token_num_t cmd_config_mtu_value =
1695         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1696
1697 cmdline_parse_inst_t cmd_config_mtu = {
1698         .f = cmd_config_mtu_parsed,
1699         .data = NULL,
1700         .help_str = "port config mtu <port_id> <value>",
1701         .tokens = {
1702                 (void *)&cmd_config_mtu_port,
1703                 (void *)&cmd_config_mtu_keyword,
1704                 (void *)&cmd_config_mtu_mtu,
1705                 (void *)&cmd_config_mtu_port_id,
1706                 (void *)&cmd_config_mtu_value,
1707                 NULL,
1708         },
1709 };
1710
1711 /* *** configure rx mode *** */
1712 struct cmd_config_rx_mode_flag {
1713         cmdline_fixed_string_t port;
1714         cmdline_fixed_string_t keyword;
1715         cmdline_fixed_string_t all;
1716         cmdline_fixed_string_t name;
1717         cmdline_fixed_string_t value;
1718 };
1719
1720 static void
1721 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1722                                 __attribute__((unused)) struct cmdline *cl,
1723                                 __attribute__((unused)) void *data)
1724 {
1725         struct cmd_config_rx_mode_flag *res = parsed_result;
1726         uint64_t rx_offloads = rx_mode.offloads;
1727
1728         if (!all_ports_stopped()) {
1729                 printf("Please stop all ports first\n");
1730                 return;
1731         }
1732
1733         if (!strcmp(res->name, "crc-strip")) {
1734                 if (!strcmp(res->value, "on"))
1735                         rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1736                 else if (!strcmp(res->value, "off"))
1737                         rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1738                 else {
1739                         printf("Unknown parameter\n");
1740                         return;
1741                 }
1742         } else if (!strcmp(res->name, "scatter")) {
1743                 if (!strcmp(res->value, "on")) {
1744                         rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1745                 } else if (!strcmp(res->value, "off")) {
1746                         rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1747                 } else {
1748                         printf("Unknown parameter\n");
1749                         return;
1750                 }
1751         } else if (!strcmp(res->name, "rx-cksum")) {
1752                 if (!strcmp(res->value, "on"))
1753                         rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1754                 else if (!strcmp(res->value, "off"))
1755                         rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1756                 else {
1757                         printf("Unknown parameter\n");
1758                         return;
1759                 }
1760         } else if (!strcmp(res->name, "rx-timestamp")) {
1761                 if (!strcmp(res->value, "on"))
1762                         rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1763                 else if (!strcmp(res->value, "off"))
1764                         rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1765                 else {
1766                         printf("Unknown parameter\n");
1767                         return;
1768                 }
1769         } else if (!strcmp(res->name, "hw-vlan")) {
1770                 if (!strcmp(res->value, "on")) {
1771                         rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1772                                         DEV_RX_OFFLOAD_VLAN_STRIP);
1773                 }
1774                 else if (!strcmp(res->value, "off")) {
1775                         rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1776                                         DEV_RX_OFFLOAD_VLAN_STRIP);
1777                 }
1778                 else {
1779                         printf("Unknown parameter\n");
1780                         return;
1781                 }
1782         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1783                 if (!strcmp(res->value, "on"))
1784                         rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1785                 else if (!strcmp(res->value, "off"))
1786                         rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1787                 else {
1788                         printf("Unknown parameter\n");
1789                         return;
1790                 }
1791         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1792                 if (!strcmp(res->value, "on"))
1793                         rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1794                 else if (!strcmp(res->value, "off"))
1795                         rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1796                 else {
1797                         printf("Unknown parameter\n");
1798                         return;
1799                 }
1800         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1801                 if (!strcmp(res->value, "on"))
1802                         rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1803                 else if (!strcmp(res->value, "off"))
1804                         rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1805                 else {
1806                         printf("Unknown parameter\n");
1807                         return;
1808                 }
1809         } else if (!strcmp(res->name, "drop-en")) {
1810                 if (!strcmp(res->value, "on"))
1811                         rx_drop_en = 1;
1812                 else if (!strcmp(res->value, "off"))
1813                         rx_drop_en = 0;
1814                 else {
1815                         printf("Unknown parameter\n");
1816                         return;
1817                 }
1818         } else {
1819                 printf("Unknown parameter\n");
1820                 return;
1821         }
1822         rx_mode.offloads = rx_offloads;
1823
1824         init_port_config();
1825
1826         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1827 }
1828
1829 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1830         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1831 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1832         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1833                                                                 "config");
1834 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1835         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1836 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1837         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1838                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1839                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1840 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1841         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1842                                                         "on#off");
1843
1844 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1845         .f = cmd_config_rx_mode_flag_parsed,
1846         .data = NULL,
1847         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1848                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1849         .tokens = {
1850                 (void *)&cmd_config_rx_mode_flag_port,
1851                 (void *)&cmd_config_rx_mode_flag_keyword,
1852                 (void *)&cmd_config_rx_mode_flag_all,
1853                 (void *)&cmd_config_rx_mode_flag_name,
1854                 (void *)&cmd_config_rx_mode_flag_value,
1855                 NULL,
1856         },
1857 };
1858
1859 /* *** configure rss *** */
1860 struct cmd_config_rss {
1861         cmdline_fixed_string_t port;
1862         cmdline_fixed_string_t keyword;
1863         cmdline_fixed_string_t all;
1864         cmdline_fixed_string_t name;
1865         cmdline_fixed_string_t value;
1866 };
1867
1868 static void
1869 cmd_config_rss_parsed(void *parsed_result,
1870                         __attribute__((unused)) struct cmdline *cl,
1871                         __attribute__((unused)) void *data)
1872 {
1873         struct cmd_config_rss *res = parsed_result;
1874         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1875         int diag;
1876         uint8_t i;
1877
1878         if (!strcmp(res->value, "all"))
1879                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1880                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1881                                         ETH_RSS_L2_PAYLOAD;
1882         else if (!strcmp(res->value, "ip"))
1883                 rss_conf.rss_hf = ETH_RSS_IP;
1884         else if (!strcmp(res->value, "udp"))
1885                 rss_conf.rss_hf = ETH_RSS_UDP;
1886         else if (!strcmp(res->value, "tcp"))
1887                 rss_conf.rss_hf = ETH_RSS_TCP;
1888         else if (!strcmp(res->value, "sctp"))
1889                 rss_conf.rss_hf = ETH_RSS_SCTP;
1890         else if (!strcmp(res->value, "ether"))
1891                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1892         else if (!strcmp(res->value, "port"))
1893                 rss_conf.rss_hf = ETH_RSS_PORT;
1894         else if (!strcmp(res->value, "vxlan"))
1895                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1896         else if (!strcmp(res->value, "geneve"))
1897                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1898         else if (!strcmp(res->value, "nvgre"))
1899                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1900         else if (!strcmp(res->value, "none"))
1901                 rss_conf.rss_hf = 0;
1902         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1903                                                 atoi(res->value) < 64)
1904                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1905         else {
1906                 printf("Unknown parameter\n");
1907                 return;
1908         }
1909         rss_conf.rss_key = NULL;
1910         for (i = 0; i < rte_eth_dev_count(); i++) {
1911                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1912                 if (diag < 0)
1913                         printf("Configuration of RSS hash at ethernet port %d "
1914                                 "failed with error (%d): %s.\n",
1915                                 i, -diag, strerror(-diag));
1916         }
1917 }
1918
1919 cmdline_parse_token_string_t cmd_config_rss_port =
1920         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1921 cmdline_parse_token_string_t cmd_config_rss_keyword =
1922         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1923 cmdline_parse_token_string_t cmd_config_rss_all =
1924         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1925 cmdline_parse_token_string_t cmd_config_rss_name =
1926         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1927 cmdline_parse_token_string_t cmd_config_rss_value =
1928         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1929
1930 cmdline_parse_inst_t cmd_config_rss = {
1931         .f = cmd_config_rss_parsed,
1932         .data = NULL,
1933         .help_str = "port config all rss "
1934                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1935         .tokens = {
1936                 (void *)&cmd_config_rss_port,
1937                 (void *)&cmd_config_rss_keyword,
1938                 (void *)&cmd_config_rss_all,
1939                 (void *)&cmd_config_rss_name,
1940                 (void *)&cmd_config_rss_value,
1941                 NULL,
1942         },
1943 };
1944
1945 /* *** configure rss hash key *** */
1946 struct cmd_config_rss_hash_key {
1947         cmdline_fixed_string_t port;
1948         cmdline_fixed_string_t config;
1949         portid_t port_id;
1950         cmdline_fixed_string_t rss_hash_key;
1951         cmdline_fixed_string_t rss_type;
1952         cmdline_fixed_string_t key;
1953 };
1954
1955 static uint8_t
1956 hexa_digit_to_value(char hexa_digit)
1957 {
1958         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1959                 return (uint8_t) (hexa_digit - '0');
1960         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1961                 return (uint8_t) ((hexa_digit - 'a') + 10);
1962         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1963                 return (uint8_t) ((hexa_digit - 'A') + 10);
1964         /* Invalid hexa digit */
1965         return 0xFF;
1966 }
1967
1968 static uint8_t
1969 parse_and_check_key_hexa_digit(char *key, int idx)
1970 {
1971         uint8_t hexa_v;
1972
1973         hexa_v = hexa_digit_to_value(key[idx]);
1974         if (hexa_v == 0xFF)
1975                 printf("invalid key: character %c at position %d is not a "
1976                        "valid hexa digit\n", key[idx], idx);
1977         return hexa_v;
1978 }
1979
1980 static void
1981 cmd_config_rss_hash_key_parsed(void *parsed_result,
1982                                __attribute__((unused)) struct cmdline *cl,
1983                                __attribute__((unused)) void *data)
1984 {
1985         struct cmd_config_rss_hash_key *res = parsed_result;
1986         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1987         uint8_t xdgt0;
1988         uint8_t xdgt1;
1989         int i;
1990         struct rte_eth_dev_info dev_info;
1991         uint8_t hash_key_size;
1992         uint32_t key_len;
1993
1994         memset(&dev_info, 0, sizeof(dev_info));
1995         rte_eth_dev_info_get(res->port_id, &dev_info);
1996         if (dev_info.hash_key_size > 0 &&
1997                         dev_info.hash_key_size <= sizeof(hash_key))
1998                 hash_key_size = dev_info.hash_key_size;
1999         else {
2000                 printf("dev_info did not provide a valid hash key size\n");
2001                 return;
2002         }
2003         /* Check the length of the RSS hash key */
2004         key_len = strlen(res->key);
2005         if (key_len != (hash_key_size * 2)) {
2006                 printf("key length: %d invalid - key must be a string of %d"
2007                            " hexa-decimal numbers\n",
2008                            (int) key_len, hash_key_size * 2);
2009                 return;
2010         }
2011         /* Translate RSS hash key into binary representation */
2012         for (i = 0; i < hash_key_size; i++) {
2013                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2014                 if (xdgt0 == 0xFF)
2015                         return;
2016                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2017                 if (xdgt1 == 0xFF)
2018                         return;
2019                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2020         }
2021         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2022                         hash_key_size);
2023 }
2024
2025 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2026         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2027 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2028         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2029                                  "config");
2030 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2031         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2032 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2033         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2034                                  rss_hash_key, "rss-hash-key");
2035 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2036         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2037                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2038                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2039                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2040                                  "ipv6-tcp-ex#ipv6-udp-ex");
2041 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2042         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2043
2044 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2045         .f = cmd_config_rss_hash_key_parsed,
2046         .data = NULL,
2047         .help_str = "port config <port_id> rss-hash-key "
2048                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2049                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2050                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2051                 "<string of hex digits (variable length, NIC dependent)>",
2052         .tokens = {
2053                 (void *)&cmd_config_rss_hash_key_port,
2054                 (void *)&cmd_config_rss_hash_key_config,
2055                 (void *)&cmd_config_rss_hash_key_port_id,
2056                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2057                 (void *)&cmd_config_rss_hash_key_rss_type,
2058                 (void *)&cmd_config_rss_hash_key_value,
2059                 NULL,
2060         },
2061 };
2062
2063 /* *** configure port rxq/txq start/stop *** */
2064 struct cmd_config_rxtx_queue {
2065         cmdline_fixed_string_t port;
2066         portid_t portid;
2067         cmdline_fixed_string_t rxtxq;
2068         uint16_t qid;
2069         cmdline_fixed_string_t opname;
2070 };
2071
2072 static void
2073 cmd_config_rxtx_queue_parsed(void *parsed_result,
2074                         __attribute__((unused)) struct cmdline *cl,
2075                         __attribute__((unused)) void *data)
2076 {
2077         struct cmd_config_rxtx_queue *res = parsed_result;
2078         uint8_t isrx;
2079         uint8_t isstart;
2080         int ret = 0;
2081
2082         if (test_done == 0) {
2083                 printf("Please stop forwarding first\n");
2084                 return;
2085         }
2086
2087         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2088                 return;
2089
2090         if (port_is_started(res->portid) != 1) {
2091                 printf("Please start port %u first\n", res->portid);
2092                 return;
2093         }
2094
2095         if (!strcmp(res->rxtxq, "rxq"))
2096                 isrx = 1;
2097         else if (!strcmp(res->rxtxq, "txq"))
2098                 isrx = 0;
2099         else {
2100                 printf("Unknown parameter\n");
2101                 return;
2102         }
2103
2104         if (isrx && rx_queue_id_is_invalid(res->qid))
2105                 return;
2106         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2107                 return;
2108
2109         if (!strcmp(res->opname, "start"))
2110                 isstart = 1;
2111         else if (!strcmp(res->opname, "stop"))
2112                 isstart = 0;
2113         else {
2114                 printf("Unknown parameter\n");
2115                 return;
2116         }
2117
2118         if (isstart && isrx)
2119                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2120         else if (!isstart && isrx)
2121                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2122         else if (isstart && !isrx)
2123                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2124         else
2125                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2126
2127         if (ret == -ENOTSUP)
2128                 printf("Function not supported in PMD driver\n");
2129 }
2130
2131 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2132         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2133 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2134         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2135 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2136         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2137 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2138         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2139 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2140         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2141                                                 "start#stop");
2142
2143 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2144         .f = cmd_config_rxtx_queue_parsed,
2145         .data = NULL,
2146         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2147         .tokens = {
2148                 (void *)&cmd_config_speed_all_port,
2149                 (void *)&cmd_config_rxtx_queue_portid,
2150                 (void *)&cmd_config_rxtx_queue_rxtxq,
2151                 (void *)&cmd_config_rxtx_queue_qid,
2152                 (void *)&cmd_config_rxtx_queue_opname,
2153                 NULL,
2154         },
2155 };
2156
2157 /* *** Configure RSS RETA *** */
2158 struct cmd_config_rss_reta {
2159         cmdline_fixed_string_t port;
2160         cmdline_fixed_string_t keyword;
2161         portid_t port_id;
2162         cmdline_fixed_string_t name;
2163         cmdline_fixed_string_t list_name;
2164         cmdline_fixed_string_t list_of_items;
2165 };
2166
2167 static int
2168 parse_reta_config(const char *str,
2169                   struct rte_eth_rss_reta_entry64 *reta_conf,
2170                   uint16_t nb_entries)
2171 {
2172         int i;
2173         unsigned size;
2174         uint16_t hash_index, idx, shift;
2175         uint16_t nb_queue;
2176         char s[256];
2177         const char *p, *p0 = str;
2178         char *end;
2179         enum fieldnames {
2180                 FLD_HASH_INDEX = 0,
2181                 FLD_QUEUE,
2182                 _NUM_FLD
2183         };
2184         unsigned long int_fld[_NUM_FLD];
2185         char *str_fld[_NUM_FLD];
2186
2187         while ((p = strchr(p0,'(')) != NULL) {
2188                 ++p;
2189                 if((p0 = strchr(p,')')) == NULL)
2190                         return -1;
2191
2192                 size = p0 - p;
2193                 if(size >= sizeof(s))
2194                         return -1;
2195
2196                 snprintf(s, sizeof(s), "%.*s", size, p);
2197                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2198                         return -1;
2199                 for (i = 0; i < _NUM_FLD; i++) {
2200                         errno = 0;
2201                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2202                         if (errno != 0 || end == str_fld[i] ||
2203                                         int_fld[i] > 65535)
2204                                 return -1;
2205                 }
2206
2207                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2208                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2209
2210                 if (hash_index >= nb_entries) {
2211                         printf("Invalid RETA hash index=%d\n", hash_index);
2212                         return -1;
2213                 }
2214
2215                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2216                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2217                 reta_conf[idx].mask |= (1ULL << shift);
2218                 reta_conf[idx].reta[shift] = nb_queue;
2219         }
2220
2221         return 0;
2222 }
2223
2224 static void
2225 cmd_set_rss_reta_parsed(void *parsed_result,
2226                         __attribute__((unused)) struct cmdline *cl,
2227                         __attribute__((unused)) void *data)
2228 {
2229         int ret;
2230         struct rte_eth_dev_info dev_info;
2231         struct rte_eth_rss_reta_entry64 reta_conf[8];
2232         struct cmd_config_rss_reta *res = parsed_result;
2233
2234         memset(&dev_info, 0, sizeof(dev_info));
2235         rte_eth_dev_info_get(res->port_id, &dev_info);
2236         if (dev_info.reta_size == 0) {
2237                 printf("Redirection table size is 0 which is "
2238                                         "invalid for RSS\n");
2239                 return;
2240         } else
2241                 printf("The reta size of port %d is %u\n",
2242                         res->port_id, dev_info.reta_size);
2243         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2244                 printf("Currently do not support more than %u entries of "
2245                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2246                 return;
2247         }
2248
2249         memset(reta_conf, 0, sizeof(reta_conf));
2250         if (!strcmp(res->list_name, "reta")) {
2251                 if (parse_reta_config(res->list_of_items, reta_conf,
2252                                                 dev_info.reta_size)) {
2253                         printf("Invalid RSS Redirection Table "
2254                                         "config entered\n");
2255                         return;
2256                 }
2257                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2258                                 reta_conf, dev_info.reta_size);
2259                 if (ret != 0)
2260                         printf("Bad redirection table parameter, "
2261                                         "return code = %d \n", ret);
2262         }
2263 }
2264
2265 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2266         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2267 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2268         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2269 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2270         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2271 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2272         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2273 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2274         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2275 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2276         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2277                                  NULL);
2278 cmdline_parse_inst_t cmd_config_rss_reta = {
2279         .f = cmd_set_rss_reta_parsed,
2280         .data = NULL,
2281         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2282         .tokens = {
2283                 (void *)&cmd_config_rss_reta_port,
2284                 (void *)&cmd_config_rss_reta_keyword,
2285                 (void *)&cmd_config_rss_reta_port_id,
2286                 (void *)&cmd_config_rss_reta_name,
2287                 (void *)&cmd_config_rss_reta_list_name,
2288                 (void *)&cmd_config_rss_reta_list_of_items,
2289                 NULL,
2290         },
2291 };
2292
2293 /* *** SHOW PORT RETA INFO *** */
2294 struct cmd_showport_reta {
2295         cmdline_fixed_string_t show;
2296         cmdline_fixed_string_t port;
2297         portid_t port_id;
2298         cmdline_fixed_string_t rss;
2299         cmdline_fixed_string_t reta;
2300         uint16_t size;
2301         cmdline_fixed_string_t list_of_items;
2302 };
2303
2304 static int
2305 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2306                            uint16_t nb_entries,
2307                            char *str)
2308 {
2309         uint32_t size;
2310         const char *p, *p0 = str;
2311         char s[256];
2312         char *end;
2313         char *str_fld[8];
2314         uint16_t i;
2315         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2316                         RTE_RETA_GROUP_SIZE;
2317         int ret;
2318
2319         p = strchr(p0, '(');
2320         if (p == NULL)
2321                 return -1;
2322         p++;
2323         p0 = strchr(p, ')');
2324         if (p0 == NULL)
2325                 return -1;
2326         size = p0 - p;
2327         if (size >= sizeof(s)) {
2328                 printf("The string size exceeds the internal buffer size\n");
2329                 return -1;
2330         }
2331         snprintf(s, sizeof(s), "%.*s", size, p);
2332         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2333         if (ret <= 0 || ret != num) {
2334                 printf("The bits of masks do not match the number of "
2335                                         "reta entries: %u\n", num);
2336                 return -1;
2337         }
2338         for (i = 0; i < ret; i++)
2339                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2340
2341         return 0;
2342 }
2343
2344 static void
2345 cmd_showport_reta_parsed(void *parsed_result,
2346                          __attribute__((unused)) struct cmdline *cl,
2347                          __attribute__((unused)) void *data)
2348 {
2349         struct cmd_showport_reta *res = parsed_result;
2350         struct rte_eth_rss_reta_entry64 reta_conf[8];
2351         struct rte_eth_dev_info dev_info;
2352         uint16_t max_reta_size;
2353
2354         memset(&dev_info, 0, sizeof(dev_info));
2355         rte_eth_dev_info_get(res->port_id, &dev_info);
2356         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2357         if (res->size == 0 || res->size > max_reta_size) {
2358                 printf("Invalid redirection table size: %u (1-%u)\n",
2359                         res->size, max_reta_size);
2360                 return;
2361         }
2362
2363         memset(reta_conf, 0, sizeof(reta_conf));
2364         if (showport_parse_reta_config(reta_conf, res->size,
2365                                 res->list_of_items) < 0) {
2366                 printf("Invalid string: %s for reta masks\n",
2367                                         res->list_of_items);
2368                 return;
2369         }
2370         port_rss_reta_info(res->port_id, reta_conf, res->size);
2371 }
2372
2373 cmdline_parse_token_string_t cmd_showport_reta_show =
2374         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2375 cmdline_parse_token_string_t cmd_showport_reta_port =
2376         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2377 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2378         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2379 cmdline_parse_token_string_t cmd_showport_reta_rss =
2380         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2381 cmdline_parse_token_string_t cmd_showport_reta_reta =
2382         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2383 cmdline_parse_token_num_t cmd_showport_reta_size =
2384         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2385 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2386         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2387                                         list_of_items, NULL);
2388
2389 cmdline_parse_inst_t cmd_showport_reta = {
2390         .f = cmd_showport_reta_parsed,
2391         .data = NULL,
2392         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2393         .tokens = {
2394                 (void *)&cmd_showport_reta_show,
2395                 (void *)&cmd_showport_reta_port,
2396                 (void *)&cmd_showport_reta_port_id,
2397                 (void *)&cmd_showport_reta_rss,
2398                 (void *)&cmd_showport_reta_reta,
2399                 (void *)&cmd_showport_reta_size,
2400                 (void *)&cmd_showport_reta_list_of_items,
2401                 NULL,
2402         },
2403 };
2404
2405 /* *** Show RSS hash configuration *** */
2406 struct cmd_showport_rss_hash {
2407         cmdline_fixed_string_t show;
2408         cmdline_fixed_string_t port;
2409         portid_t port_id;
2410         cmdline_fixed_string_t rss_hash;
2411         cmdline_fixed_string_t rss_type;
2412         cmdline_fixed_string_t key; /* optional argument */
2413 };
2414
2415 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2416                                 __attribute__((unused)) struct cmdline *cl,
2417                                 void *show_rss_key)
2418 {
2419         struct cmd_showport_rss_hash *res = parsed_result;
2420
2421         port_rss_hash_conf_show(res->port_id, res->rss_type,
2422                                 show_rss_key != NULL);
2423 }
2424
2425 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2426         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2427 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2428         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2429 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2430         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2431 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2432         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2433                                  "rss-hash");
2434 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2435         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2436                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2437                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2438                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2439                                  "ipv6-tcp-ex#ipv6-udp-ex");
2440 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2441         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2442
2443 cmdline_parse_inst_t cmd_showport_rss_hash = {
2444         .f = cmd_showport_rss_hash_parsed,
2445         .data = NULL,
2446         .help_str = "show port <port_id> rss-hash "
2447                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2448                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2449                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2450         .tokens = {
2451                 (void *)&cmd_showport_rss_hash_show,
2452                 (void *)&cmd_showport_rss_hash_port,
2453                 (void *)&cmd_showport_rss_hash_port_id,
2454                 (void *)&cmd_showport_rss_hash_rss_hash,
2455                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2456                 NULL,
2457         },
2458 };
2459
2460 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2461         .f = cmd_showport_rss_hash_parsed,
2462         .data = (void *)1,
2463         .help_str = "show port <port_id> rss-hash "
2464                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2465                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2466                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2467         .tokens = {
2468                 (void *)&cmd_showport_rss_hash_show,
2469                 (void *)&cmd_showport_rss_hash_port,
2470                 (void *)&cmd_showport_rss_hash_port_id,
2471                 (void *)&cmd_showport_rss_hash_rss_hash,
2472                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2473                 (void *)&cmd_showport_rss_hash_rss_key,
2474                 NULL,
2475         },
2476 };
2477
2478 /* *** Configure DCB *** */
2479 struct cmd_config_dcb {
2480         cmdline_fixed_string_t port;
2481         cmdline_fixed_string_t config;
2482         portid_t port_id;
2483         cmdline_fixed_string_t dcb;
2484         cmdline_fixed_string_t vt;
2485         cmdline_fixed_string_t vt_en;
2486         uint8_t num_tcs;
2487         cmdline_fixed_string_t pfc;
2488         cmdline_fixed_string_t pfc_en;
2489 };
2490
2491 static void
2492 cmd_config_dcb_parsed(void *parsed_result,
2493                         __attribute__((unused)) struct cmdline *cl,
2494                         __attribute__((unused)) void *data)
2495 {
2496         struct cmd_config_dcb *res = parsed_result;
2497         portid_t port_id = res->port_id;
2498         struct rte_port *port;
2499         uint8_t pfc_en;
2500         int ret;
2501
2502         port = &ports[port_id];
2503         /** Check if the port is not started **/
2504         if (port->port_status != RTE_PORT_STOPPED) {
2505                 printf("Please stop port %d first\n", port_id);
2506                 return;
2507         }
2508
2509         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2510                 printf("The invalid number of traffic class,"
2511                         " only 4 or 8 allowed.\n");
2512                 return;
2513         }
2514
2515         if (nb_fwd_lcores < res->num_tcs) {
2516                 printf("nb_cores shouldn't be less than number of TCs.\n");
2517                 return;
2518         }
2519         if (!strncmp(res->pfc_en, "on", 2))
2520                 pfc_en = 1;
2521         else
2522                 pfc_en = 0;
2523
2524         /* DCB in VT mode */
2525         if (!strncmp(res->vt_en, "on", 2))
2526                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2527                                 (enum rte_eth_nb_tcs)res->num_tcs,
2528                                 pfc_en);
2529         else
2530                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2531                                 (enum rte_eth_nb_tcs)res->num_tcs,
2532                                 pfc_en);
2533
2534
2535         if (ret != 0) {
2536                 printf("Cannot initialize network ports.\n");
2537                 return;
2538         }
2539
2540         cmd_reconfig_device_queue(port_id, 1, 1);
2541 }
2542
2543 cmdline_parse_token_string_t cmd_config_dcb_port =
2544         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2545 cmdline_parse_token_string_t cmd_config_dcb_config =
2546         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2547 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2548         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2549 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2550         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2551 cmdline_parse_token_string_t cmd_config_dcb_vt =
2552         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2553 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2554         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2555 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2556         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2557 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2558         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2559 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2560         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2561
2562 cmdline_parse_inst_t cmd_config_dcb = {
2563         .f = cmd_config_dcb_parsed,
2564         .data = NULL,
2565         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2566         .tokens = {
2567                 (void *)&cmd_config_dcb_port,
2568                 (void *)&cmd_config_dcb_config,
2569                 (void *)&cmd_config_dcb_port_id,
2570                 (void *)&cmd_config_dcb_dcb,
2571                 (void *)&cmd_config_dcb_vt,
2572                 (void *)&cmd_config_dcb_vt_en,
2573                 (void *)&cmd_config_dcb_num_tcs,
2574                 (void *)&cmd_config_dcb_pfc,
2575                 (void *)&cmd_config_dcb_pfc_en,
2576                 NULL,
2577         },
2578 };
2579
2580 /* *** configure number of packets per burst *** */
2581 struct cmd_config_burst {
2582         cmdline_fixed_string_t port;
2583         cmdline_fixed_string_t keyword;
2584         cmdline_fixed_string_t all;
2585         cmdline_fixed_string_t name;
2586         uint16_t value;
2587 };
2588
2589 static void
2590 cmd_config_burst_parsed(void *parsed_result,
2591                         __attribute__((unused)) struct cmdline *cl,
2592                         __attribute__((unused)) void *data)
2593 {
2594         struct cmd_config_burst *res = parsed_result;
2595
2596         if (!all_ports_stopped()) {
2597                 printf("Please stop all ports first\n");
2598                 return;
2599         }
2600
2601         if (!strcmp(res->name, "burst")) {
2602                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2603                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2604                         return;
2605                 }
2606                 nb_pkt_per_burst = res->value;
2607         } else {
2608                 printf("Unknown parameter\n");
2609                 return;
2610         }
2611
2612         init_port_config();
2613
2614         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2615 }
2616
2617 cmdline_parse_token_string_t cmd_config_burst_port =
2618         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2619 cmdline_parse_token_string_t cmd_config_burst_keyword =
2620         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2621 cmdline_parse_token_string_t cmd_config_burst_all =
2622         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2623 cmdline_parse_token_string_t cmd_config_burst_name =
2624         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2625 cmdline_parse_token_num_t cmd_config_burst_value =
2626         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2627
2628 cmdline_parse_inst_t cmd_config_burst = {
2629         .f = cmd_config_burst_parsed,
2630         .data = NULL,
2631         .help_str = "port config all burst <value>",
2632         .tokens = {
2633                 (void *)&cmd_config_burst_port,
2634                 (void *)&cmd_config_burst_keyword,
2635                 (void *)&cmd_config_burst_all,
2636                 (void *)&cmd_config_burst_name,
2637                 (void *)&cmd_config_burst_value,
2638                 NULL,
2639         },
2640 };
2641
2642 /* *** configure rx/tx queues *** */
2643 struct cmd_config_thresh {
2644         cmdline_fixed_string_t port;
2645         cmdline_fixed_string_t keyword;
2646         cmdline_fixed_string_t all;
2647         cmdline_fixed_string_t name;
2648         uint8_t value;
2649 };
2650
2651 static void
2652 cmd_config_thresh_parsed(void *parsed_result,
2653                         __attribute__((unused)) struct cmdline *cl,
2654                         __attribute__((unused)) void *data)
2655 {
2656         struct cmd_config_thresh *res = parsed_result;
2657
2658         if (!all_ports_stopped()) {
2659                 printf("Please stop all ports first\n");
2660                 return;
2661         }
2662
2663         if (!strcmp(res->name, "txpt"))
2664                 tx_pthresh = res->value;
2665         else if(!strcmp(res->name, "txht"))
2666                 tx_hthresh = res->value;
2667         else if(!strcmp(res->name, "txwt"))
2668                 tx_wthresh = res->value;
2669         else if(!strcmp(res->name, "rxpt"))
2670                 rx_pthresh = res->value;
2671         else if(!strcmp(res->name, "rxht"))
2672                 rx_hthresh = res->value;
2673         else if(!strcmp(res->name, "rxwt"))
2674                 rx_wthresh = res->value;
2675         else {
2676                 printf("Unknown parameter\n");
2677                 return;
2678         }
2679
2680         init_port_config();
2681
2682         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2683 }
2684
2685 cmdline_parse_token_string_t cmd_config_thresh_port =
2686         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2687 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2688         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2689 cmdline_parse_token_string_t cmd_config_thresh_all =
2690         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2691 cmdline_parse_token_string_t cmd_config_thresh_name =
2692         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2693                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2694 cmdline_parse_token_num_t cmd_config_thresh_value =
2695         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2696
2697 cmdline_parse_inst_t cmd_config_thresh = {
2698         .f = cmd_config_thresh_parsed,
2699         .data = NULL,
2700         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2701         .tokens = {
2702                 (void *)&cmd_config_thresh_port,
2703                 (void *)&cmd_config_thresh_keyword,
2704                 (void *)&cmd_config_thresh_all,
2705                 (void *)&cmd_config_thresh_name,
2706                 (void *)&cmd_config_thresh_value,
2707                 NULL,
2708         },
2709 };
2710
2711 /* *** configure free/rs threshold *** */
2712 struct cmd_config_threshold {
2713         cmdline_fixed_string_t port;
2714         cmdline_fixed_string_t keyword;
2715         cmdline_fixed_string_t all;
2716         cmdline_fixed_string_t name;
2717         uint16_t value;
2718 };
2719
2720 static void
2721 cmd_config_threshold_parsed(void *parsed_result,
2722                         __attribute__((unused)) struct cmdline *cl,
2723                         __attribute__((unused)) void *data)
2724 {
2725         struct cmd_config_threshold *res = parsed_result;
2726
2727         if (!all_ports_stopped()) {
2728                 printf("Please stop all ports first\n");
2729                 return;
2730         }
2731
2732         if (!strcmp(res->name, "txfreet"))
2733                 tx_free_thresh = res->value;
2734         else if (!strcmp(res->name, "txrst"))
2735                 tx_rs_thresh = res->value;
2736         else if (!strcmp(res->name, "rxfreet"))
2737                 rx_free_thresh = res->value;
2738         else {
2739                 printf("Unknown parameter\n");
2740                 return;
2741         }
2742
2743         init_port_config();
2744
2745         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2746 }
2747
2748 cmdline_parse_token_string_t cmd_config_threshold_port =
2749         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2750 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2751         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2752                                                                 "config");
2753 cmdline_parse_token_string_t cmd_config_threshold_all =
2754         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2755 cmdline_parse_token_string_t cmd_config_threshold_name =
2756         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2757                                                 "txfreet#txrst#rxfreet");
2758 cmdline_parse_token_num_t cmd_config_threshold_value =
2759         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2760
2761 cmdline_parse_inst_t cmd_config_threshold = {
2762         .f = cmd_config_threshold_parsed,
2763         .data = NULL,
2764         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2765         .tokens = {
2766                 (void *)&cmd_config_threshold_port,
2767                 (void *)&cmd_config_threshold_keyword,
2768                 (void *)&cmd_config_threshold_all,
2769                 (void *)&cmd_config_threshold_name,
2770                 (void *)&cmd_config_threshold_value,
2771                 NULL,
2772         },
2773 };
2774
2775 /* *** stop *** */
2776 struct cmd_stop_result {
2777         cmdline_fixed_string_t stop;
2778 };
2779
2780 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2781                             __attribute__((unused)) struct cmdline *cl,
2782                             __attribute__((unused)) void *data)
2783 {
2784         stop_packet_forwarding();
2785 }
2786
2787 cmdline_parse_token_string_t cmd_stop_stop =
2788         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2789
2790 cmdline_parse_inst_t cmd_stop = {
2791         .f = cmd_stop_parsed,
2792         .data = NULL,
2793         .help_str = "stop: Stop packet forwarding",
2794         .tokens = {
2795                 (void *)&cmd_stop_stop,
2796                 NULL,
2797         },
2798 };
2799
2800 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2801
2802 unsigned int
2803 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2804                 unsigned int *parsed_items, int check_unique_values)
2805 {
2806         unsigned int nb_item;
2807         unsigned int value;
2808         unsigned int i;
2809         unsigned int j;
2810         int value_ok;
2811         char c;
2812
2813         /*
2814          * First parse all items in the list and store their value.
2815          */
2816         value = 0;
2817         nb_item = 0;
2818         value_ok = 0;
2819         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2820                 c = str[i];
2821                 if ((c >= '0') && (c <= '9')) {
2822                         value = (unsigned int) (value * 10 + (c - '0'));
2823                         value_ok = 1;
2824                         continue;
2825                 }
2826                 if (c != ',') {
2827                         printf("character %c is not a decimal digit\n", c);
2828                         return 0;
2829                 }
2830                 if (! value_ok) {
2831                         printf("No valid value before comma\n");
2832                         return 0;
2833                 }
2834                 if (nb_item < max_items) {
2835                         parsed_items[nb_item] = value;
2836                         value_ok = 0;
2837                         value = 0;
2838                 }
2839                 nb_item++;
2840         }
2841         if (nb_item >= max_items) {
2842                 printf("Number of %s = %u > %u (maximum items)\n",
2843                        item_name, nb_item + 1, max_items);
2844                 return 0;
2845         }
2846         parsed_items[nb_item++] = value;
2847         if (! check_unique_values)
2848                 return nb_item;
2849
2850         /*
2851          * Then, check that all values in the list are differents.
2852          * No optimization here...
2853          */
2854         for (i = 0; i < nb_item; i++) {
2855                 for (j = i + 1; j < nb_item; j++) {
2856                         if (parsed_items[j] == parsed_items[i]) {
2857                                 printf("duplicated %s %u at index %u and %u\n",
2858                                        item_name, parsed_items[i], i, j);
2859                                 return 0;
2860                         }
2861                 }
2862         }
2863         return nb_item;
2864 }
2865
2866 struct cmd_set_list_result {
2867         cmdline_fixed_string_t cmd_keyword;
2868         cmdline_fixed_string_t list_name;
2869         cmdline_fixed_string_t list_of_items;
2870 };
2871
2872 static void cmd_set_list_parsed(void *parsed_result,
2873                                 __attribute__((unused)) struct cmdline *cl,
2874                                 __attribute__((unused)) void *data)
2875 {
2876         struct cmd_set_list_result *res;
2877         union {
2878                 unsigned int lcorelist[RTE_MAX_LCORE];
2879                 unsigned int portlist[RTE_MAX_ETHPORTS];
2880         } parsed_items;
2881         unsigned int nb_item;
2882
2883         if (test_done == 0) {
2884                 printf("Please stop forwarding first\n");
2885                 return;
2886         }
2887
2888         res = parsed_result;
2889         if (!strcmp(res->list_name, "corelist")) {
2890                 nb_item = parse_item_list(res->list_of_items, "core",
2891                                           RTE_MAX_LCORE,
2892                                           parsed_items.lcorelist, 1);
2893                 if (nb_item > 0) {
2894                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2895                         fwd_config_setup();
2896                 }
2897                 return;
2898         }
2899         if (!strcmp(res->list_name, "portlist")) {
2900                 nb_item = parse_item_list(res->list_of_items, "port",
2901                                           RTE_MAX_ETHPORTS,
2902                                           parsed_items.portlist, 1);
2903                 if (nb_item > 0) {
2904                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2905                         fwd_config_setup();
2906                 }
2907         }
2908 }
2909
2910 cmdline_parse_token_string_t cmd_set_list_keyword =
2911         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2912                                  "set");
2913 cmdline_parse_token_string_t cmd_set_list_name =
2914         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2915                                  "corelist#portlist");
2916 cmdline_parse_token_string_t cmd_set_list_of_items =
2917         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2918                                  NULL);
2919
2920 cmdline_parse_inst_t cmd_set_fwd_list = {
2921         .f = cmd_set_list_parsed,
2922         .data = NULL,
2923         .help_str = "set corelist|portlist <list0[,list1]*>",
2924         .tokens = {
2925                 (void *)&cmd_set_list_keyword,
2926                 (void *)&cmd_set_list_name,
2927                 (void *)&cmd_set_list_of_items,
2928                 NULL,
2929         },
2930 };
2931
2932 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2933
2934 struct cmd_setmask_result {
2935         cmdline_fixed_string_t set;
2936         cmdline_fixed_string_t mask;
2937         uint64_t hexavalue;
2938 };
2939
2940 static void cmd_set_mask_parsed(void *parsed_result,
2941                                 __attribute__((unused)) struct cmdline *cl,
2942                                 __attribute__((unused)) void *data)
2943 {
2944         struct cmd_setmask_result *res = parsed_result;
2945
2946         if (test_done == 0) {
2947                 printf("Please stop forwarding first\n");
2948                 return;
2949         }
2950         if (!strcmp(res->mask, "coremask")) {
2951                 set_fwd_lcores_mask(res->hexavalue);
2952                 fwd_config_setup();
2953         } else if (!strcmp(res->mask, "portmask")) {
2954                 set_fwd_ports_mask(res->hexavalue);
2955                 fwd_config_setup();
2956         }
2957 }
2958
2959 cmdline_parse_token_string_t cmd_setmask_set =
2960         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2961 cmdline_parse_token_string_t cmd_setmask_mask =
2962         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2963                                  "coremask#portmask");
2964 cmdline_parse_token_num_t cmd_setmask_value =
2965         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2966
2967 cmdline_parse_inst_t cmd_set_fwd_mask = {
2968         .f = cmd_set_mask_parsed,
2969         .data = NULL,
2970         .help_str = "set coremask|portmask <hexadecimal value>",
2971         .tokens = {
2972                 (void *)&cmd_setmask_set,
2973                 (void *)&cmd_setmask_mask,
2974                 (void *)&cmd_setmask_value,
2975                 NULL,
2976         },
2977 };
2978
2979 /*
2980  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2981  */
2982 struct cmd_set_result {
2983         cmdline_fixed_string_t set;
2984         cmdline_fixed_string_t what;
2985         uint16_t value;
2986 };
2987
2988 static void cmd_set_parsed(void *parsed_result,
2989                            __attribute__((unused)) struct cmdline *cl,
2990                            __attribute__((unused)) void *data)
2991 {
2992         struct cmd_set_result *res = parsed_result;
2993         if (!strcmp(res->what, "nbport")) {
2994                 set_fwd_ports_number(res->value);
2995                 fwd_config_setup();
2996         } else if (!strcmp(res->what, "nbcore")) {
2997                 set_fwd_lcores_number(res->value);
2998                 fwd_config_setup();
2999         } else if (!strcmp(res->what, "burst"))
3000                 set_nb_pkt_per_burst(res->value);
3001         else if (!strcmp(res->what, "verbose"))
3002                 set_verbose_level(res->value);
3003 }
3004
3005 cmdline_parse_token_string_t cmd_set_set =
3006         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3007 cmdline_parse_token_string_t cmd_set_what =
3008         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3009                                  "nbport#nbcore#burst#verbose");
3010 cmdline_parse_token_num_t cmd_set_value =
3011         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3012
3013 cmdline_parse_inst_t cmd_set_numbers = {
3014         .f = cmd_set_parsed,
3015         .data = NULL,
3016         .help_str = "set nbport|nbcore|burst|verbose <value>",
3017         .tokens = {
3018                 (void *)&cmd_set_set,
3019                 (void *)&cmd_set_what,
3020                 (void *)&cmd_set_value,
3021                 NULL,
3022         },
3023 };
3024
3025 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3026
3027 struct cmd_set_txpkts_result {
3028         cmdline_fixed_string_t cmd_keyword;
3029         cmdline_fixed_string_t txpkts;
3030         cmdline_fixed_string_t seg_lengths;
3031 };
3032
3033 static void
3034 cmd_set_txpkts_parsed(void *parsed_result,
3035                       __attribute__((unused)) struct cmdline *cl,
3036                       __attribute__((unused)) void *data)
3037 {
3038         struct cmd_set_txpkts_result *res;
3039         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3040         unsigned int nb_segs;
3041
3042         res = parsed_result;
3043         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3044                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3045         if (nb_segs > 0)
3046                 set_tx_pkt_segments(seg_lengths, nb_segs);
3047 }
3048
3049 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3050         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3051                                  cmd_keyword, "set");
3052 cmdline_parse_token_string_t cmd_set_txpkts_name =
3053         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3054                                  txpkts, "txpkts");
3055 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3056         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3057                                  seg_lengths, NULL);
3058
3059 cmdline_parse_inst_t cmd_set_txpkts = {
3060         .f = cmd_set_txpkts_parsed,
3061         .data = NULL,
3062         .help_str = "set txpkts <len0[,len1]*>",
3063         .tokens = {
3064                 (void *)&cmd_set_txpkts_keyword,
3065                 (void *)&cmd_set_txpkts_name,
3066                 (void *)&cmd_set_txpkts_lengths,
3067                 NULL,
3068         },
3069 };
3070
3071 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3072
3073 struct cmd_set_txsplit_result {
3074         cmdline_fixed_string_t cmd_keyword;
3075         cmdline_fixed_string_t txsplit;
3076         cmdline_fixed_string_t mode;
3077 };
3078
3079 static void
3080 cmd_set_txsplit_parsed(void *parsed_result,
3081                       __attribute__((unused)) struct cmdline *cl,
3082                       __attribute__((unused)) void *data)
3083 {
3084         struct cmd_set_txsplit_result *res;
3085
3086         res = parsed_result;
3087         set_tx_pkt_split(res->mode);
3088 }
3089
3090 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3091         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3092                                  cmd_keyword, "set");
3093 cmdline_parse_token_string_t cmd_set_txsplit_name =
3094         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3095                                  txsplit, "txsplit");
3096 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3097         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3098                                  mode, NULL);
3099
3100 cmdline_parse_inst_t cmd_set_txsplit = {
3101         .f = cmd_set_txsplit_parsed,
3102         .data = NULL,
3103         .help_str = "set txsplit on|off|rand",
3104         .tokens = {
3105                 (void *)&cmd_set_txsplit_keyword,
3106                 (void *)&cmd_set_txsplit_name,
3107                 (void *)&cmd_set_txsplit_mode,
3108                 NULL,
3109         },
3110 };
3111
3112 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3113 struct cmd_rx_vlan_filter_all_result {
3114         cmdline_fixed_string_t rx_vlan;
3115         cmdline_fixed_string_t what;
3116         cmdline_fixed_string_t all;
3117         portid_t port_id;
3118 };
3119
3120 static void
3121 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3122                               __attribute__((unused)) struct cmdline *cl,
3123                               __attribute__((unused)) void *data)
3124 {
3125         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3126
3127         if (!strcmp(res->what, "add"))
3128                 rx_vlan_all_filter_set(res->port_id, 1);
3129         else
3130                 rx_vlan_all_filter_set(res->port_id, 0);
3131 }
3132
3133 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3134         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3135                                  rx_vlan, "rx_vlan");
3136 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3137         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3138                                  what, "add#rm");
3139 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3140         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3141                                  all, "all");
3142 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3143         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3144                               port_id, UINT16);
3145
3146 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3147         .f = cmd_rx_vlan_filter_all_parsed,
3148         .data = NULL,
3149         .help_str = "rx_vlan add|rm all <port_id>: "
3150                 "Add/Remove all identifiers to/from the set of VLAN "
3151                 "identifiers filtered by a port",
3152         .tokens = {
3153                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3154                 (void *)&cmd_rx_vlan_filter_all_what,
3155                 (void *)&cmd_rx_vlan_filter_all_all,
3156                 (void *)&cmd_rx_vlan_filter_all_portid,
3157                 NULL,
3158         },
3159 };
3160
3161 /* *** VLAN OFFLOAD SET ON A PORT *** */
3162 struct cmd_vlan_offload_result {
3163         cmdline_fixed_string_t vlan;
3164         cmdline_fixed_string_t set;
3165         cmdline_fixed_string_t vlan_type;
3166         cmdline_fixed_string_t what;
3167         cmdline_fixed_string_t on;
3168         cmdline_fixed_string_t port_id;
3169 };
3170
3171 static void
3172 cmd_vlan_offload_parsed(void *parsed_result,
3173                           __attribute__((unused)) struct cmdline *cl,
3174                           __attribute__((unused)) void *data)
3175 {
3176         int on;
3177         struct cmd_vlan_offload_result *res = parsed_result;
3178         char *str;
3179         int i, len = 0;
3180         portid_t port_id = 0;
3181         unsigned int tmp;
3182
3183         str = res->port_id;
3184         len = strnlen(str, STR_TOKEN_SIZE);
3185         i = 0;
3186         /* Get port_id first */
3187         while(i < len){
3188                 if(str[i] == ',')
3189                         break;
3190
3191                 i++;
3192         }
3193         str[i]='\0';
3194         tmp = strtoul(str, NULL, 0);
3195         /* If port_id greater that what portid_t can represent, return */
3196         if(tmp >= RTE_MAX_ETHPORTS)
3197                 return;
3198         port_id = (portid_t)tmp;
3199
3200         if (!strcmp(res->on, "on"))
3201                 on = 1;
3202         else
3203                 on = 0;
3204
3205         if (!strcmp(res->what, "strip"))
3206                 rx_vlan_strip_set(port_id,  on);
3207         else if(!strcmp(res->what, "stripq")){
3208                 uint16_t queue_id = 0;
3209
3210                 /* No queue_id, return */
3211                 if(i + 1 >= len) {
3212                         printf("must specify (port,queue_id)\n");
3213                         return;
3214                 }
3215                 tmp = strtoul(str + i + 1, NULL, 0);
3216                 /* If queue_id greater that what 16-bits can represent, return */
3217                 if(tmp > 0xffff)
3218                         return;
3219
3220                 queue_id = (uint16_t)tmp;
3221                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3222         }
3223         else if (!strcmp(res->what, "filter"))
3224                 rx_vlan_filter_set(port_id, on);
3225         else
3226                 vlan_extend_set(port_id, on);
3227
3228         return;
3229 }
3230
3231 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3232         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3233                                  vlan, "vlan");
3234 cmdline_parse_token_string_t cmd_vlan_offload_set =
3235         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3236                                  set, "set");
3237 cmdline_parse_token_string_t cmd_vlan_offload_what =
3238         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3239                                  what, "strip#filter#qinq#stripq");
3240 cmdline_parse_token_string_t cmd_vlan_offload_on =
3241         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3242                               on, "on#off");
3243 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3244         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3245                               port_id, NULL);
3246
3247 cmdline_parse_inst_t cmd_vlan_offload = {
3248         .f = cmd_vlan_offload_parsed,
3249         .data = NULL,
3250         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3251                 "<port_id[,queue_id]>: "
3252                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3253         .tokens = {
3254                 (void *)&cmd_vlan_offload_vlan,
3255                 (void *)&cmd_vlan_offload_set,
3256                 (void *)&cmd_vlan_offload_what,
3257                 (void *)&cmd_vlan_offload_on,
3258                 (void *)&cmd_vlan_offload_portid,
3259                 NULL,
3260         },
3261 };
3262
3263 /* *** VLAN TPID SET ON A PORT *** */
3264 struct cmd_vlan_tpid_result {
3265         cmdline_fixed_string_t vlan;
3266         cmdline_fixed_string_t set;
3267         cmdline_fixed_string_t vlan_type;
3268         cmdline_fixed_string_t what;
3269         uint16_t tp_id;
3270         portid_t port_id;
3271 };
3272
3273 static void
3274 cmd_vlan_tpid_parsed(void *parsed_result,
3275                           __attribute__((unused)) struct cmdline *cl,
3276                           __attribute__((unused)) void *data)
3277 {
3278         struct cmd_vlan_tpid_result *res = parsed_result;
3279         enum rte_vlan_type vlan_type;
3280
3281         if (!strcmp(res->vlan_type, "inner"))
3282                 vlan_type = ETH_VLAN_TYPE_INNER;
3283         else if (!strcmp(res->vlan_type, "outer"))
3284                 vlan_type = ETH_VLAN_TYPE_OUTER;
3285         else {
3286                 printf("Unknown vlan type\n");
3287                 return;
3288         }
3289         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3290 }
3291
3292 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3293         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3294                                  vlan, "vlan");
3295 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3296         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3297                                  set, "set");
3298 cmdline_parse_token_string_t cmd_vlan_type =
3299         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3300                                  vlan_type, "inner#outer");
3301 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3302         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3303                                  what, "tpid");
3304 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3305         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3306                               tp_id, UINT16);
3307 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3308         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3309                               port_id, UINT16);
3310
3311 cmdline_parse_inst_t cmd_vlan_tpid = {
3312         .f = cmd_vlan_tpid_parsed,
3313         .data = NULL,
3314         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3315                 "Set the VLAN Ether type",
3316         .tokens = {
3317                 (void *)&cmd_vlan_tpid_vlan,
3318                 (void *)&cmd_vlan_tpid_set,
3319                 (void *)&cmd_vlan_type,
3320                 (void *)&cmd_vlan_tpid_what,
3321                 (void *)&cmd_vlan_tpid_tpid,
3322                 (void *)&cmd_vlan_tpid_portid,
3323                 NULL,
3324         },
3325 };
3326
3327 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3328 struct cmd_rx_vlan_filter_result {
3329         cmdline_fixed_string_t rx_vlan;
3330         cmdline_fixed_string_t what;
3331         uint16_t vlan_id;
3332         portid_t port_id;
3333 };
3334
3335 static void
3336 cmd_rx_vlan_filter_parsed(void *parsed_result,
3337                           __attribute__((unused)) struct cmdline *cl,
3338                           __attribute__((unused)) void *data)
3339 {
3340         struct cmd_rx_vlan_filter_result *res = parsed_result;
3341
3342         if (!strcmp(res->what, "add"))
3343                 rx_vft_set(res->port_id, res->vlan_id, 1);
3344         else
3345                 rx_vft_set(res->port_id, res->vlan_id, 0);
3346 }
3347
3348 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3349         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3350                                  rx_vlan, "rx_vlan");
3351 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3352         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3353                                  what, "add#rm");
3354 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3355         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3356                               vlan_id, UINT16);
3357 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3358         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3359                               port_id, UINT16);
3360
3361 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3362         .f = cmd_rx_vlan_filter_parsed,
3363         .data = NULL,
3364         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3365                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3366                 "identifiers filtered by a port",
3367         .tokens = {
3368                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3369                 (void *)&cmd_rx_vlan_filter_what,
3370                 (void *)&cmd_rx_vlan_filter_vlanid,
3371                 (void *)&cmd_rx_vlan_filter_portid,
3372                 NULL,
3373         },
3374 };
3375
3376 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3377 struct cmd_tx_vlan_set_result {
3378         cmdline_fixed_string_t tx_vlan;
3379         cmdline_fixed_string_t set;
3380         portid_t port_id;
3381         uint16_t vlan_id;
3382 };
3383
3384 static void
3385 cmd_tx_vlan_set_parsed(void *parsed_result,
3386                        __attribute__((unused)) struct cmdline *cl,
3387                        __attribute__((unused)) void *data)
3388 {
3389         struct cmd_tx_vlan_set_result *res = parsed_result;
3390
3391         if (!port_is_stopped(res->port_id)) {
3392                 printf("Please stop port %d first\n", res->port_id);
3393                 return;
3394         }
3395
3396         tx_vlan_set(res->port_id, res->vlan_id);
3397
3398         cmd_reconfig_device_queue(res->port_id, 1, 1);
3399 }
3400
3401 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3402         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3403                                  tx_vlan, "tx_vlan");
3404 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3405         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3406                                  set, "set");
3407 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3408         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3409                               port_id, UINT16);
3410 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3411         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3412                               vlan_id, UINT16);
3413
3414 cmdline_parse_inst_t cmd_tx_vlan_set = {
3415         .f = cmd_tx_vlan_set_parsed,
3416         .data = NULL,
3417         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3418                 "Enable hardware insertion of a single VLAN header "
3419                 "with a given TAG Identifier in packets sent on a port",
3420         .tokens = {
3421                 (void *)&cmd_tx_vlan_set_tx_vlan,
3422                 (void *)&cmd_tx_vlan_set_set,
3423                 (void *)&cmd_tx_vlan_set_portid,
3424                 (void *)&cmd_tx_vlan_set_vlanid,
3425                 NULL,
3426         },
3427 };
3428
3429 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3430 struct cmd_tx_vlan_set_qinq_result {
3431         cmdline_fixed_string_t tx_vlan;
3432         cmdline_fixed_string_t set;
3433         portid_t port_id;
3434         uint16_t vlan_id;
3435         uint16_t vlan_id_outer;
3436 };
3437
3438 static void
3439 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3440                             __attribute__((unused)) struct cmdline *cl,
3441                             __attribute__((unused)) void *data)
3442 {
3443         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3444
3445         if (!port_is_stopped(res->port_id)) {
3446                 printf("Please stop port %d first\n", res->port_id);
3447                 return;
3448         }
3449
3450         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3451
3452         cmd_reconfig_device_queue(res->port_id, 1, 1);
3453 }
3454
3455 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3456         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3457                 tx_vlan, "tx_vlan");
3458 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3459         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3460                 set, "set");
3461 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3462         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3463                 port_id, UINT16);
3464 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3465         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3466                 vlan_id, UINT16);
3467 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3468         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3469                 vlan_id_outer, UINT16);
3470
3471 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3472         .f = cmd_tx_vlan_set_qinq_parsed,
3473         .data = NULL,
3474         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3475                 "Enable hardware insertion of double VLAN header "
3476                 "with given TAG Identifiers in packets sent on a port",
3477         .tokens = {
3478                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3479                 (void *)&cmd_tx_vlan_set_qinq_set,
3480                 (void *)&cmd_tx_vlan_set_qinq_portid,
3481                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3482                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3483                 NULL,
3484         },
3485 };
3486
3487 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3488 struct cmd_tx_vlan_set_pvid_result {
3489         cmdline_fixed_string_t tx_vlan;
3490         cmdline_fixed_string_t set;
3491         cmdline_fixed_string_t pvid;
3492         portid_t port_id;
3493         uint16_t vlan_id;
3494         cmdline_fixed_string_t mode;
3495 };
3496
3497 static void
3498 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3499                             __attribute__((unused)) struct cmdline *cl,
3500                             __attribute__((unused)) void *data)
3501 {
3502         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3503
3504         if (strcmp(res->mode, "on") == 0)
3505                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3506         else
3507                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3508 }
3509
3510 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3511         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3512                                  tx_vlan, "tx_vlan");
3513 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3514         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3515                                  set, "set");
3516 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3517         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3518                                  pvid, "pvid");
3519 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3520         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3521                              port_id, UINT16);
3522 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3523         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3524                               vlan_id, UINT16);
3525 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3526         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3527                                  mode, "on#off");
3528
3529 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3530         .f = cmd_tx_vlan_set_pvid_parsed,
3531         .data = NULL,
3532         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3533         .tokens = {
3534                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3535                 (void *)&cmd_tx_vlan_set_pvid_set,
3536                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3537                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3538                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3539                 (void *)&cmd_tx_vlan_set_pvid_mode,
3540                 NULL,
3541         },
3542 };
3543
3544 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3545 struct cmd_tx_vlan_reset_result {
3546         cmdline_fixed_string_t tx_vlan;
3547         cmdline_fixed_string_t reset;
3548         portid_t port_id;
3549 };
3550
3551 static void
3552 cmd_tx_vlan_reset_parsed(void *parsed_result,
3553                          __attribute__((unused)) struct cmdline *cl,
3554                          __attribute__((unused)) void *data)
3555 {
3556         struct cmd_tx_vlan_reset_result *res = parsed_result;
3557
3558         if (!port_is_stopped(res->port_id)) {
3559                 printf("Please stop port %d first\n", res->port_id);
3560                 return;
3561         }
3562
3563         tx_vlan_reset(res->port_id);
3564
3565         cmd_reconfig_device_queue(res->port_id, 1, 1);
3566 }
3567
3568 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3569         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3570                                  tx_vlan, "tx_vlan");
3571 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3572         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3573                                  reset, "reset");
3574 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3575         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3576                               port_id, UINT16);
3577
3578 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3579         .f = cmd_tx_vlan_reset_parsed,
3580         .data = NULL,
3581         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3582                 "VLAN header in packets sent on a port",
3583         .tokens = {
3584                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3585                 (void *)&cmd_tx_vlan_reset_reset,
3586                 (void *)&cmd_tx_vlan_reset_portid,
3587                 NULL,
3588         },
3589 };
3590
3591
3592 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3593 struct cmd_csum_result {
3594         cmdline_fixed_string_t csum;
3595         cmdline_fixed_string_t mode;
3596         cmdline_fixed_string_t proto;
3597         cmdline_fixed_string_t hwsw;
3598         portid_t port_id;
3599 };
3600
3601 static void
3602 csum_show(int port_id)
3603 {
3604         struct rte_eth_dev_info dev_info;
3605         uint64_t tx_offloads;
3606
3607         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
3608         printf("Parse tunnel is %s\n",
3609                 (ports[port_id].parse_tunnel) ? "on" : "off");
3610         printf("IP checksum offload is %s\n",
3611                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
3612         printf("UDP checksum offload is %s\n",
3613                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3614         printf("TCP checksum offload is %s\n",
3615                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3616         printf("SCTP checksum offload is %s\n",
3617                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3618         printf("Outer-Ip checksum offload is %s\n",
3619                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
3620
3621         /* display warnings if configuration is not supported by the NIC */
3622         rte_eth_dev_info_get(port_id, &dev_info);
3623         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
3624                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3625                 printf("Warning: hardware IP checksum enabled but not "
3626                         "supported by port %d\n", port_id);
3627         }
3628         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
3629                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3630                 printf("Warning: hardware UDP checksum enabled but not "
3631                         "supported by port %d\n", port_id);
3632         }
3633         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
3634                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3635                 printf("Warning: hardware TCP checksum enabled but not "
3636                         "supported by port %d\n", port_id);
3637         }
3638         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
3639                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3640                 printf("Warning: hardware SCTP checksum enabled but not "
3641                         "supported by port %d\n", port_id);
3642         }
3643         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
3644                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3645                 printf("Warning: hardware outer IP checksum enabled but not "
3646                         "supported by port %d\n", port_id);
3647         }
3648 }
3649
3650 static void
3651 cmd_csum_parsed(void *parsed_result,
3652                        __attribute__((unused)) struct cmdline *cl,
3653                        __attribute__((unused)) void *data)
3654 {
3655         struct cmd_csum_result *res = parsed_result;
3656         int hw = 0;
3657         uint64_t csum_offloads = 0;
3658         struct rte_eth_dev_info dev_info;
3659
3660         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3661                 printf("invalid port %d\n", res->port_id);
3662                 return;
3663         }
3664         if (!port_is_stopped(res->port_id)) {
3665                 printf("Please stop port %d first\n", res->port_id);
3666                 return;
3667         }
3668
3669         rte_eth_dev_info_get(res->port_id, &dev_info);
3670         if (!strcmp(res->mode, "set")) {
3671
3672                 if (!strcmp(res->hwsw, "hw"))
3673                         hw = 1;
3674
3675                 if (!strcmp(res->proto, "ip")) {
3676                         if (dev_info.tx_offload_capa &
3677                                                 DEV_TX_OFFLOAD_IPV4_CKSUM) {
3678                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
3679                         } else {
3680                                 printf("IP checksum offload is not supported "
3681                                        "by port %u\n", res->port_id);
3682                         }
3683                 } else if (!strcmp(res->proto, "udp")) {
3684                         if (dev_info.tx_offload_capa &
3685                                                 DEV_TX_OFFLOAD_UDP_CKSUM) {
3686                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
3687                         } else {
3688                                 printf("UDP checksum offload is not supported "
3689                                        "by port %u\n", res->port_id);
3690                         }
3691                 } else if (!strcmp(res->proto, "tcp")) {
3692                         if (dev_info.tx_offload_capa &
3693                                                 DEV_TX_OFFLOAD_TCP_CKSUM) {
3694                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
3695                         } else {
3696                                 printf("TCP checksum offload is not supported "
3697                                        "by port %u\n", res->port_id);
3698                         }
3699                 } else if (!strcmp(res->proto, "sctp")) {
3700                         if (dev_info.tx_offload_capa &
3701                                                 DEV_TX_OFFLOAD_SCTP_CKSUM) {
3702                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
3703                         } else {
3704                                 printf("SCTP checksum offload is not supported "
3705                                        "by port %u\n", res->port_id);
3706                         }
3707                 } else if (!strcmp(res->proto, "outer-ip")) {
3708                         if (dev_info.tx_offload_capa &
3709                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
3710                                 csum_offloads |=
3711                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3712                         } else {
3713                                 printf("Outer IP checksum offload is not "
3714                                        "supported by port %u\n", res->port_id);
3715                         }
3716                 }
3717
3718                 if (hw) {
3719                         ports[res->port_id].dev_conf.txmode.offloads |=
3720                                                         csum_offloads;
3721                 } else {
3722                         ports[res->port_id].dev_conf.txmode.offloads &=
3723                                                         (~csum_offloads);
3724                 }
3725         }
3726         csum_show(res->port_id);
3727
3728         cmd_reconfig_device_queue(res->port_id, 1, 1);
3729 }
3730
3731 cmdline_parse_token_string_t cmd_csum_csum =
3732         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3733                                 csum, "csum");
3734 cmdline_parse_token_string_t cmd_csum_mode =
3735         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3736                                 mode, "set");
3737 cmdline_parse_token_string_t cmd_csum_proto =
3738         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3739                                 proto, "ip#tcp#udp#sctp#outer-ip");
3740 cmdline_parse_token_string_t cmd_csum_hwsw =
3741         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3742                                 hwsw, "hw#sw");
3743 cmdline_parse_token_num_t cmd_csum_portid =
3744         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3745                                 port_id, UINT16);
3746
3747 cmdline_parse_inst_t cmd_csum_set = {
3748         .f = cmd_csum_parsed,
3749         .data = NULL,
3750         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3751                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3752                 "using csum forward engine",
3753         .tokens = {
3754                 (void *)&cmd_csum_csum,
3755                 (void *)&cmd_csum_mode,
3756                 (void *)&cmd_csum_proto,
3757                 (void *)&cmd_csum_hwsw,
3758                 (void *)&cmd_csum_portid,
3759                 NULL,
3760         },
3761 };
3762
3763 cmdline_parse_token_string_t cmd_csum_mode_show =
3764         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3765                                 mode, "show");
3766
3767 cmdline_parse_inst_t cmd_csum_show = {
3768         .f = cmd_csum_parsed,
3769         .data = NULL,
3770         .help_str = "csum show <port_id>: Show checksum offload configuration",
3771         .tokens = {
3772                 (void *)&cmd_csum_csum,
3773                 (void *)&cmd_csum_mode_show,
3774                 (void *)&cmd_csum_portid,
3775                 NULL,
3776         },
3777 };
3778
3779 /* Enable/disable tunnel parsing */
3780 struct cmd_csum_tunnel_result {
3781         cmdline_fixed_string_t csum;
3782         cmdline_fixed_string_t parse;
3783         cmdline_fixed_string_t onoff;
3784         portid_t port_id;
3785 };
3786
3787 static void
3788 cmd_csum_tunnel_parsed(void *parsed_result,
3789                        __attribute__((unused)) struct cmdline *cl,
3790                        __attribute__((unused)) void *data)
3791 {
3792         struct cmd_csum_tunnel_result *res = parsed_result;
3793
3794         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3795                 return;
3796
3797         if (!strcmp(res->onoff, "on"))
3798                 ports[res->port_id].parse_tunnel = 1;
3799         else
3800                 ports[res->port_id].parse_tunnel = 0;
3801
3802         csum_show(res->port_id);
3803 }
3804
3805 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3806         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3807                                 csum, "csum");
3808 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3809         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3810                                 parse, "parse_tunnel");
3811 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3812         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3813                                 onoff, "on#off");
3814 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3815         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3816                                 port_id, UINT16);
3817
3818 cmdline_parse_inst_t cmd_csum_tunnel = {
3819         .f = cmd_csum_tunnel_parsed,
3820         .data = NULL,
3821         .help_str = "csum parse_tunnel on|off <port_id>: "
3822                 "Enable/Disable parsing of tunnels for csum engine",
3823         .tokens = {
3824                 (void *)&cmd_csum_tunnel_csum,
3825                 (void *)&cmd_csum_tunnel_parse,
3826                 (void *)&cmd_csum_tunnel_onoff,
3827                 (void *)&cmd_csum_tunnel_portid,
3828                 NULL,
3829         },
3830 };
3831
3832 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3833 struct cmd_tso_set_result {
3834         cmdline_fixed_string_t tso;
3835         cmdline_fixed_string_t mode;
3836         uint16_t tso_segsz;
3837         portid_t port_id;
3838 };
3839
3840 static void
3841 cmd_tso_set_parsed(void *parsed_result,
3842                        __attribute__((unused)) struct cmdline *cl,
3843                        __attribute__((unused)) void *data)
3844 {
3845         struct cmd_tso_set_result *res = parsed_result;
3846         struct rte_eth_dev_info dev_info;
3847
3848         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3849                 return;
3850         if (!port_is_stopped(res->port_id)) {
3851                 printf("Please stop port %d first\n", res->port_id);
3852                 return;
3853         }
3854
3855         if (!strcmp(res->mode, "set"))
3856                 ports[res->port_id].tso_segsz = res->tso_segsz;
3857
3858         rte_eth_dev_info_get(res->port_id, &dev_info);
3859         if ((ports[res->port_id].tso_segsz != 0) &&
3860                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3861                 printf("Error: TSO is not supported by port %d\n",
3862                        res->port_id);
3863                 return;
3864         }
3865
3866         if (ports[res->port_id].tso_segsz == 0) {
3867                 ports[res->port_id].dev_conf.txmode.offloads &=
3868                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
3869                 printf("TSO for non-tunneled packets is disabled\n");
3870         } else {
3871                 ports[res->port_id].dev_conf.txmode.offloads |=
3872                                                 DEV_TX_OFFLOAD_TCP_TSO;
3873                 printf("TSO segment size for non-tunneled packets is %d\n",
3874                         ports[res->port_id].tso_segsz);
3875         }
3876
3877         /* display warnings if configuration is not supported by the NIC */
3878         rte_eth_dev_info_get(res->port_id, &dev_info);
3879         if ((ports[res->port_id].tso_segsz != 0) &&
3880                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3881                 printf("Warning: TSO enabled but not "
3882                         "supported by port %d\n", res->port_id);
3883         }
3884
3885         cmd_reconfig_device_queue(res->port_id, 1, 1);
3886 }
3887
3888 cmdline_parse_token_string_t cmd_tso_set_tso =
3889         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3890                                 tso, "tso");
3891 cmdline_parse_token_string_t cmd_tso_set_mode =
3892         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3893                                 mode, "set");
3894 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3895         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3896                                 tso_segsz, UINT16);
3897 cmdline_parse_token_num_t cmd_tso_set_portid =
3898         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3899                                 port_id, UINT16);
3900
3901 cmdline_parse_inst_t cmd_tso_set = {
3902         .f = cmd_tso_set_parsed,
3903         .data = NULL,
3904         .help_str = "tso set <tso_segsz> <port_id>: "
3905                 "Set TSO segment size of non-tunneled packets for csum engine "
3906                 "(0 to disable)",
3907         .tokens = {
3908                 (void *)&cmd_tso_set_tso,
3909                 (void *)&cmd_tso_set_mode,
3910                 (void *)&cmd_tso_set_tso_segsz,
3911                 (void *)&cmd_tso_set_portid,
3912                 NULL,
3913         },
3914 };
3915
3916 cmdline_parse_token_string_t cmd_tso_show_mode =
3917         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3918                                 mode, "show");
3919
3920
3921 cmdline_parse_inst_t cmd_tso_show = {
3922         .f = cmd_tso_set_parsed,
3923         .data = NULL,
3924         .help_str = "tso show <port_id>: "
3925                 "Show TSO segment size of non-tunneled packets for csum engine",
3926         .tokens = {
3927                 (void *)&cmd_tso_set_tso,
3928                 (void *)&cmd_tso_show_mode,
3929                 (void *)&cmd_tso_set_portid,
3930                 NULL,
3931         },
3932 };
3933
3934 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3935 struct cmd_tunnel_tso_set_result {
3936         cmdline_fixed_string_t tso;
3937         cmdline_fixed_string_t mode;
3938         uint16_t tso_segsz;
3939         portid_t port_id;
3940 };
3941
3942 static struct rte_eth_dev_info
3943 check_tunnel_tso_nic_support(portid_t port_id)
3944 {
3945         struct rte_eth_dev_info dev_info;
3946
3947         rte_eth_dev_info_get(port_id, &dev_info);
3948         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3949                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
3950                        "not enabled for port %d\n", port_id);
3951         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3952                 printf("Warning: GRE TUNNEL TSO not supported therefore "
3953                        "not enabled for port %d\n", port_id);
3954         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3955                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
3956                        "not enabled for port %d\n", port_id);
3957         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3958                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
3959                        "not enabled for port %d\n", port_id);
3960         return dev_info;
3961 }
3962
3963 static void
3964 cmd_tunnel_tso_set_parsed(void *parsed_result,
3965                           __attribute__((unused)) struct cmdline *cl,
3966                           __attribute__((unused)) void *data)
3967 {
3968         struct cmd_tunnel_tso_set_result *res = parsed_result;
3969         struct rte_eth_dev_info dev_info;
3970
3971         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3972                 return;
3973         if (!port_is_stopped(res->port_id)) {
3974                 printf("Please stop port %d first\n", res->port_id);
3975                 return;
3976         }
3977
3978         if (!strcmp(res->mode, "set"))
3979                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3980
3981         dev_info = check_tunnel_tso_nic_support(res->port_id);
3982         if (ports[res->port_id].tunnel_tso_segsz == 0) {
3983                 ports[res->port_id].dev_conf.txmode.offloads &=
3984                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
3985                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
3986                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
3987                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
3988                 printf("TSO for tunneled packets is disabled\n");
3989         } else {
3990                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
3991                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
3992                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
3993                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
3994
3995                 ports[res->port_id].dev_conf.txmode.offloads |=
3996                         (tso_offloads & dev_info.tx_offload_capa);
3997                 printf("TSO segment size for tunneled packets is %d\n",
3998                         ports[res->port_id].tunnel_tso_segsz);
3999
4000                 /* Below conditions are needed to make it work:
4001                  * (1) tunnel TSO is supported by the NIC;
4002                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4003                  * are recognized;
4004                  * (3) for tunneled pkts with outer L3 of IPv4,
4005                  * "csum set outer-ip" must be set to hw, because after tso,
4006                  * total_len of outer IP header is changed, and the checksum
4007                  * of outer IP header calculated by sw should be wrong; that
4008                  * is not necessary for IPv6 tunneled pkts because there's no
4009                  * checksum in IP header anymore.
4010                  */
4011
4012                 if (!ports[res->port_id].parse_tunnel)
4013                         printf("Warning: csum parse_tunnel must be set "
4014                                 "so that tunneled packets are recognized\n");
4015                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4016                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4017                         printf("Warning: csum set outer-ip must be set to hw "
4018                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4019         }
4020
4021         cmd_reconfig_device_queue(res->port_id, 1, 1);
4022 }
4023
4024 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4025         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4026                                 tso, "tunnel_tso");
4027 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4028         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4029                                 mode, "set");
4030 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4031         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4032                                 tso_segsz, UINT16);
4033 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4034         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4035                                 port_id, UINT16);
4036
4037 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4038         .f = cmd_tunnel_tso_set_parsed,
4039         .data = NULL,
4040         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4041                 "Set TSO segment size of tunneled packets for csum engine "
4042                 "(0 to disable)",
4043         .tokens = {
4044                 (void *)&cmd_tunnel_tso_set_tso,
4045                 (void *)&cmd_tunnel_tso_set_mode,
4046                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4047                 (void *)&cmd_tunnel_tso_set_portid,
4048                 NULL,
4049         },
4050 };
4051
4052 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4053         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4054                                 mode, "show");
4055
4056
4057 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4058         .f = cmd_tunnel_tso_set_parsed,
4059         .data = NULL,
4060         .help_str = "tunnel_tso show <port_id> "
4061                 "Show TSO segment size of tunneled packets for csum engine",
4062         .tokens = {
4063                 (void *)&cmd_tunnel_tso_set_tso,
4064                 (void *)&cmd_tunnel_tso_show_mode,
4065                 (void *)&cmd_tunnel_tso_set_portid,
4066                 NULL,
4067         },
4068 };
4069
4070 /* *** SET GRO FOR A PORT *** */
4071 struct cmd_gro_enable_result {
4072         cmdline_fixed_string_t cmd_set;
4073         cmdline_fixed_string_t cmd_port;
4074         cmdline_fixed_string_t cmd_keyword;
4075         cmdline_fixed_string_t cmd_onoff;
4076         portid_t cmd_pid;
4077 };
4078
4079 static void
4080 cmd_gro_enable_parsed(void *parsed_result,
4081                 __attribute__((unused)) struct cmdline *cl,
4082                 __attribute__((unused)) void *data)
4083 {
4084         struct cmd_gro_enable_result *res;
4085
4086         res = parsed_result;
4087         if (!strcmp(res->cmd_keyword, "gro"))
4088                 setup_gro(res->cmd_onoff, res->cmd_pid);
4089 }
4090
4091 cmdline_parse_token_string_t cmd_gro_enable_set =
4092         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4093                         cmd_set, "set");
4094 cmdline_parse_token_string_t cmd_gro_enable_port =
4095         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4096                         cmd_keyword, "port");
4097 cmdline_parse_token_num_t cmd_gro_enable_pid =
4098         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4099                         cmd_pid, UINT16);
4100 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4101         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4102                         cmd_keyword, "gro");
4103 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4104         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4105                         cmd_onoff, "on#off");
4106
4107 cmdline_parse_inst_t cmd_gro_enable = {
4108         .f = cmd_gro_enable_parsed,
4109         .data = NULL,
4110         .help_str = "set port <port_id> gro on|off",
4111         .tokens = {
4112                 (void *)&cmd_gro_enable_set,
4113                 (void *)&cmd_gro_enable_port,
4114                 (void *)&cmd_gro_enable_pid,
4115                 (void *)&cmd_gro_enable_keyword,
4116                 (void *)&cmd_gro_enable_onoff,
4117                 NULL,
4118         },
4119 };
4120
4121 /* *** DISPLAY GRO CONFIGURATION *** */
4122 struct cmd_gro_show_result {
4123         cmdline_fixed_string_t cmd_show;
4124         cmdline_fixed_string_t cmd_port;
4125         cmdline_fixed_string_t cmd_keyword;
4126         portid_t cmd_pid;
4127 };
4128
4129 static void
4130 cmd_gro_show_parsed(void *parsed_result,
4131                 __attribute__((unused)) struct cmdline *cl,
4132                 __attribute__((unused)) void *data)
4133 {
4134         struct cmd_gro_show_result *res;
4135
4136         res = parsed_result;
4137         if (!strcmp(res->cmd_keyword, "gro"))
4138                 show_gro(res->cmd_pid);
4139 }
4140
4141 cmdline_parse_token_string_t cmd_gro_show_show =
4142         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4143                         cmd_show, "show");
4144 cmdline_parse_token_string_t cmd_gro_show_port =
4145         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4146                         cmd_port, "port");
4147 cmdline_parse_token_num_t cmd_gro_show_pid =
4148         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4149                         cmd_pid, UINT16);
4150 cmdline_parse_token_string_t cmd_gro_show_keyword =
4151         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4152                         cmd_keyword, "gro");
4153
4154 cmdline_parse_inst_t cmd_gro_show = {
4155         .f = cmd_gro_show_parsed,
4156         .data = NULL,
4157         .help_str = "show port <port_id> gro",
4158         .tokens = {
4159                 (void *)&cmd_gro_show_show,
4160                 (void *)&cmd_gro_show_port,
4161                 (void *)&cmd_gro_show_pid,
4162                 (void *)&cmd_gro_show_keyword,
4163                 NULL,
4164         },
4165 };
4166
4167 /* *** SET FLUSH CYCLES FOR GRO *** */
4168 struct cmd_gro_flush_result {
4169         cmdline_fixed_string_t cmd_set;
4170         cmdline_fixed_string_t cmd_keyword;
4171         cmdline_fixed_string_t cmd_flush;
4172         uint8_t cmd_cycles;
4173 };
4174
4175 static void
4176 cmd_gro_flush_parsed(void *parsed_result,
4177                 __attribute__((unused)) struct cmdline *cl,
4178                 __attribute__((unused)) void *data)
4179 {
4180         struct cmd_gro_flush_result *res;
4181
4182         res = parsed_result;
4183         if ((!strcmp(res->cmd_keyword, "gro")) &&
4184                         (!strcmp(res->cmd_flush, "flush")))
4185                 setup_gro_flush_cycles(res->cmd_cycles);
4186 }
4187
4188 cmdline_parse_token_string_t cmd_gro_flush_set =
4189         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4190                         cmd_set, "set");
4191 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4192         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4193                         cmd_keyword, "gro");
4194 cmdline_parse_token_string_t cmd_gro_flush_flush =
4195         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4196                         cmd_flush, "flush");
4197 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4198         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4199                         cmd_cycles, UINT8);
4200
4201 cmdline_parse_inst_t cmd_gro_flush = {
4202         .f = cmd_gro_flush_parsed,
4203         .data = NULL,
4204         .help_str = "set gro flush <cycles>",
4205         .tokens = {
4206                 (void *)&cmd_gro_flush_set,
4207                 (void *)&cmd_gro_flush_keyword,
4208                 (void *)&cmd_gro_flush_flush,
4209                 (void *)&cmd_gro_flush_cycles,
4210                 NULL,
4211         },
4212 };
4213
4214 /* *** ENABLE/DISABLE GSO *** */
4215 struct cmd_gso_enable_result {
4216         cmdline_fixed_string_t cmd_set;
4217         cmdline_fixed_string_t cmd_port;
4218         cmdline_fixed_string_t cmd_keyword;
4219         cmdline_fixed_string_t cmd_mode;
4220         portid_t cmd_pid;
4221 };
4222
4223 static void
4224 cmd_gso_enable_parsed(void *parsed_result,
4225                 __attribute__((unused)) struct cmdline *cl,
4226                 __attribute__((unused)) void *data)
4227 {
4228         struct cmd_gso_enable_result *res;
4229
4230         res = parsed_result;
4231         if (!strcmp(res->cmd_keyword, "gso"))
4232                 setup_gso(res->cmd_mode, res->cmd_pid);
4233 }
4234
4235 cmdline_parse_token_string_t cmd_gso_enable_set =
4236         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4237                         cmd_set, "set");
4238 cmdline_parse_token_string_t cmd_gso_enable_port =
4239         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4240                         cmd_port, "port");
4241 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4242         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4243                         cmd_keyword, "gso");
4244 cmdline_parse_token_string_t cmd_gso_enable_mode =
4245         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4246                         cmd_mode, "on#off");
4247 cmdline_parse_token_num_t cmd_gso_enable_pid =
4248         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4249                         cmd_pid, UINT16);
4250
4251 cmdline_parse_inst_t cmd_gso_enable = {
4252         .f = cmd_gso_enable_parsed,
4253         .data = NULL,
4254         .help_str = "set port <port_id> gso on|off",
4255         .tokens = {
4256                 (void *)&cmd_gso_enable_set,
4257                 (void *)&cmd_gso_enable_port,
4258                 (void *)&cmd_gso_enable_pid,
4259                 (void *)&cmd_gso_enable_keyword,
4260                 (void *)&cmd_gso_enable_mode,
4261                 NULL,
4262         },
4263 };
4264
4265 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4266 struct cmd_gso_size_result {
4267         cmdline_fixed_string_t cmd_set;
4268         cmdline_fixed_string_t cmd_keyword;
4269         cmdline_fixed_string_t cmd_segsz;
4270         uint16_t cmd_size;
4271 };
4272
4273 static void
4274 cmd_gso_size_parsed(void *parsed_result,
4275                        __attribute__((unused)) struct cmdline *cl,
4276                        __attribute__((unused)) void *data)
4277 {
4278         struct cmd_gso_size_result *res = parsed_result;
4279
4280         if (test_done == 0) {
4281                 printf("Before setting GSO segsz, please first"
4282                                 " stop fowarding\n");
4283                 return;
4284         }
4285
4286         if (!strcmp(res->cmd_keyword, "gso") &&
4287                         !strcmp(res->cmd_segsz, "segsz")) {
4288                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4289                         printf("gso_size should be larger than %zu."
4290                                         " Please input a legal value\n",
4291                                         RTE_GSO_SEG_SIZE_MIN);
4292                 else
4293                         gso_max_segment_size = res->cmd_size;
4294         }
4295 }
4296
4297 cmdline_parse_token_string_t cmd_gso_size_set =
4298         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4299                                 cmd_set, "set");
4300 cmdline_parse_token_string_t cmd_gso_size_keyword =
4301         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4302                                 cmd_keyword, "gso");
4303 cmdline_parse_token_string_t cmd_gso_size_segsz =
4304         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4305                                 cmd_segsz, "segsz");
4306 cmdline_parse_token_num_t cmd_gso_size_size =
4307         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4308                                 cmd_size, UINT16);
4309
4310 cmdline_parse_inst_t cmd_gso_size = {
4311         .f = cmd_gso_size_parsed,
4312         .data = NULL,
4313         .help_str = "set gso segsz <length>",
4314         .tokens = {
4315                 (void *)&cmd_gso_size_set,
4316                 (void *)&cmd_gso_size_keyword,
4317                 (void *)&cmd_gso_size_segsz,
4318                 (void *)&cmd_gso_size_size,
4319                 NULL,
4320         },
4321 };
4322
4323 /* *** SHOW GSO CONFIGURATION *** */
4324 struct cmd_gso_show_result {
4325         cmdline_fixed_string_t cmd_show;
4326         cmdline_fixed_string_t cmd_port;
4327         cmdline_fixed_string_t cmd_keyword;
4328         portid_t cmd_pid;
4329 };
4330
4331 static void
4332 cmd_gso_show_parsed(void *parsed_result,
4333                        __attribute__((unused)) struct cmdline *cl,
4334                        __attribute__((unused)) void *data)
4335 {
4336         struct cmd_gso_show_result *res = parsed_result;
4337
4338         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4339                 printf("invalid port id %u\n", res->cmd_pid);
4340                 return;
4341         }
4342         if (!strcmp(res->cmd_keyword, "gso")) {
4343                 if (gso_ports[res->cmd_pid].enable) {
4344                         printf("Max GSO'd packet size: %uB\n"
4345                                         "Supported GSO types: TCP/IPv4, "
4346                                         "VxLAN with inner TCP/IPv4 packet, "
4347                                         "GRE with inner TCP/IPv4  packet\n",
4348                                         gso_max_segment_size);
4349                 } else
4350                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4351         }
4352 }
4353
4354 cmdline_parse_token_string_t cmd_gso_show_show =
4355 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4356                 cmd_show, "show");
4357 cmdline_parse_token_string_t cmd_gso_show_port =
4358 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4359                 cmd_port, "port");
4360 cmdline_parse_token_string_t cmd_gso_show_keyword =
4361         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4362                                 cmd_keyword, "gso");
4363 cmdline_parse_token_num_t cmd_gso_show_pid =
4364         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4365                                 cmd_pid, UINT16);
4366
4367 cmdline_parse_inst_t cmd_gso_show = {
4368         .f = cmd_gso_show_parsed,
4369         .data = NULL,
4370         .help_str = "show port <port_id> gso",
4371         .tokens = {
4372                 (void *)&cmd_gso_show_show,
4373                 (void *)&cmd_gso_show_port,
4374                 (void *)&cmd_gso_show_pid,
4375                 (void *)&cmd_gso_show_keyword,
4376                 NULL,
4377         },
4378 };
4379
4380 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4381 struct cmd_set_flush_rx {
4382         cmdline_fixed_string_t set;
4383         cmdline_fixed_string_t flush_rx;
4384         cmdline_fixed_string_t mode;
4385 };
4386
4387 static void
4388 cmd_set_flush_rx_parsed(void *parsed_result,
4389                 __attribute__((unused)) struct cmdline *cl,
4390                 __attribute__((unused)) void *data)
4391 {
4392         struct cmd_set_flush_rx *res = parsed_result;
4393         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4394 }
4395
4396 cmdline_parse_token_string_t cmd_setflushrx_set =
4397         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4398                         set, "set");
4399 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4400         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4401                         flush_rx, "flush_rx");
4402 cmdline_parse_token_string_t cmd_setflushrx_mode =
4403         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4404                         mode, "on#off");
4405
4406
4407 cmdline_parse_inst_t cmd_set_flush_rx = {
4408         .f = cmd_set_flush_rx_parsed,
4409         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4410         .data = NULL,
4411         .tokens = {
4412                 (void *)&cmd_setflushrx_set,
4413                 (void *)&cmd_setflushrx_flush_rx,
4414                 (void *)&cmd_setflushrx_mode,
4415                 NULL,
4416         },
4417 };
4418
4419 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4420 struct cmd_set_link_check {
4421         cmdline_fixed_string_t set;
4422         cmdline_fixed_string_t link_check;
4423         cmdline_fixed_string_t mode;
4424 };
4425
4426 static void
4427 cmd_set_link_check_parsed(void *parsed_result,
4428                 __attribute__((unused)) struct cmdline *cl,
4429                 __attribute__((unused)) void *data)
4430 {
4431         struct cmd_set_link_check *res = parsed_result;
4432         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4433 }
4434
4435 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4436         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4437                         set, "set");
4438 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4439         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4440                         link_check, "link_check");
4441 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4442         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4443                         mode, "on#off");
4444
4445
4446 cmdline_parse_inst_t cmd_set_link_check = {
4447         .f = cmd_set_link_check_parsed,
4448         .help_str = "set link_check on|off: Enable/Disable link status check "
4449                     "when starting/stopping a port",
4450         .data = NULL,
4451         .tokens = {
4452                 (void *)&cmd_setlinkcheck_set,
4453                 (void *)&cmd_setlinkcheck_link_check,
4454                 (void *)&cmd_setlinkcheck_mode,
4455                 NULL,
4456         },
4457 };
4458
4459 /* *** SET NIC BYPASS MODE *** */
4460 struct cmd_set_bypass_mode_result {
4461         cmdline_fixed_string_t set;
4462         cmdline_fixed_string_t bypass;
4463         cmdline_fixed_string_t mode;
4464         cmdline_fixed_string_t value;
4465         portid_t port_id;
4466 };
4467
4468 static void
4469 cmd_set_bypass_mode_parsed(void *parsed_result,
4470                 __attribute__((unused)) struct cmdline *cl,
4471                 __attribute__((unused)) void *data)
4472 {
4473         struct cmd_set_bypass_mode_result *res = parsed_result;
4474         portid_t port_id = res->port_id;
4475         int32_t rc = -EINVAL;
4476
4477 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4478         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4479
4480         if (!strcmp(res->value, "bypass"))
4481                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4482         else if (!strcmp(res->value, "isolate"))
4483                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4484         else
4485                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4486
4487         /* Set the bypass mode for the relevant port. */
4488         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4489 #endif
4490         if (rc != 0)
4491                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4492 }
4493
4494 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4495         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4496                         set, "set");
4497 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4498         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4499                         bypass, "bypass");
4500 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4501         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4502                         mode, "mode");
4503 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4504         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4505                         value, "normal#bypass#isolate");
4506 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4507         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4508                                 port_id, UINT16);
4509
4510 cmdline_parse_inst_t cmd_set_bypass_mode = {
4511         .f = cmd_set_bypass_mode_parsed,
4512         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4513                     "Set the NIC bypass mode for port_id",
4514         .data = NULL,
4515         .tokens = {
4516                 (void *)&cmd_setbypass_mode_set,
4517                 (void *)&cmd_setbypass_mode_bypass,
4518                 (void *)&cmd_setbypass_mode_mode,
4519                 (void *)&cmd_setbypass_mode_value,
4520                 (void *)&cmd_setbypass_mode_port,
4521                 NULL,
4522         },
4523 };
4524
4525 /* *** SET NIC BYPASS EVENT *** */
4526 struct cmd_set_bypass_event_result {
4527         cmdline_fixed_string_t set;
4528         cmdline_fixed_string_t bypass;
4529         cmdline_fixed_string_t event;
4530         cmdline_fixed_string_t event_value;
4531         cmdline_fixed_string_t mode;
4532         cmdline_fixed_string_t mode_value;
4533         portid_t port_id;
4534 };
4535
4536 static void
4537 cmd_set_bypass_event_parsed(void *parsed_result,
4538                 __attribute__((unused)) struct cmdline *cl,
4539                 __attribute__((unused)) void *data)
4540 {
4541         int32_t rc = -EINVAL;
4542         struct cmd_set_bypass_event_result *res = parsed_result;
4543         portid_t port_id = res->port_id;
4544
4545 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4546         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4547         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4548
4549         if (!strcmp(res->event_value, "timeout"))
4550                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4551         else if (!strcmp(res->event_value, "os_on"))
4552                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4553         else if (!strcmp(res->event_value, "os_off"))
4554                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4555         else if (!strcmp(res->event_value, "power_on"))
4556                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4557         else if (!strcmp(res->event_value, "power_off"))
4558                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4559         else
4560                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4561
4562         if (!strcmp(res->mode_value, "bypass"))
4563                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4564         else if (!strcmp(res->mode_value, "isolate"))
4565                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4566         else
4567                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4568
4569         /* Set the watchdog timeout. */
4570         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4571
4572                 rc = -EINVAL;
4573                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4574                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4575                                                            bypass_timeout);
4576                 }
4577                 if (rc != 0) {
4578                         printf("Failed to set timeout value %u "
4579                         "for port %d, errto code: %d.\n",
4580                         bypass_timeout, port_id, rc);
4581                 }
4582         }
4583
4584         /* Set the bypass event to transition to bypass mode. */
4585         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4586                                               bypass_mode);
4587 #endif
4588
4589         if (rc != 0)
4590                 printf("\t Failed to set bypass event for port = %d.\n",
4591                        port_id);
4592 }
4593
4594 cmdline_parse_token_string_t cmd_setbypass_event_set =
4595         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4596                         set, "set");
4597 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4598         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4599                         bypass, "bypass");
4600 cmdline_parse_token_string_t cmd_setbypass_event_event =
4601         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4602                         event, "event");
4603 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4604         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4605                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4606 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4607         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4608                         mode, "mode");
4609 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4610         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4611                         mode_value, "normal#bypass#isolate");
4612 cmdline_parse_token_num_t cmd_setbypass_event_port =
4613         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4614                                 port_id, UINT16);
4615
4616 cmdline_parse_inst_t cmd_set_bypass_event = {
4617         .f = cmd_set_bypass_event_parsed,
4618         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4619                 "power_off mode normal|bypass|isolate <port_id>: "
4620                 "Set the NIC bypass event mode for port_id",
4621         .data = NULL,
4622         .tokens = {
4623                 (void *)&cmd_setbypass_event_set,
4624                 (void *)&cmd_setbypass_event_bypass,
4625                 (void *)&cmd_setbypass_event_event,
4626                 (void *)&cmd_setbypass_event_event_value,
4627                 (void *)&cmd_setbypass_event_mode,
4628                 (void *)&cmd_setbypass_event_mode_value,
4629                 (void *)&cmd_setbypass_event_port,
4630                 NULL,
4631         },
4632 };
4633
4634
4635 /* *** SET NIC BYPASS TIMEOUT *** */
4636 struct cmd_set_bypass_timeout_result {
4637         cmdline_fixed_string_t set;
4638         cmdline_fixed_string_t bypass;
4639         cmdline_fixed_string_t timeout;
4640         cmdline_fixed_string_t value;
4641 };
4642
4643 static void
4644 cmd_set_bypass_timeout_parsed(void *parsed_result,
4645                 __attribute__((unused)) struct cmdline *cl,
4646                 __attribute__((unused)) void *data)
4647 {
4648         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4649
4650 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4651         if (!strcmp(res->value, "1.5"))
4652                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4653         else if (!strcmp(res->value, "2"))
4654                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4655         else if (!strcmp(res->value, "3"))
4656                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4657         else if (!strcmp(res->value, "4"))
4658                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4659         else if (!strcmp(res->value, "8"))
4660                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4661         else if (!strcmp(res->value, "16"))
4662                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4663         else if (!strcmp(res->value, "32"))
4664                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4665         else
4666                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4667 #endif
4668 }
4669
4670 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4671         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4672                         set, "set");
4673 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4674         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4675                         bypass, "bypass");
4676 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4677         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4678                         timeout, "timeout");
4679 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4680         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4681                         value, "0#1.5#2#3#4#8#16#32");
4682
4683 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4684         .f = cmd_set_bypass_timeout_parsed,
4685         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4686                 "Set the NIC bypass watchdog timeout in seconds",
4687         .data = NULL,
4688         .tokens = {
4689                 (void *)&cmd_setbypass_timeout_set,
4690                 (void *)&cmd_setbypass_timeout_bypass,
4691                 (void *)&cmd_setbypass_timeout_timeout,
4692                 (void *)&cmd_setbypass_timeout_value,
4693                 NULL,
4694         },
4695 };
4696
4697 /* *** SHOW NIC BYPASS MODE *** */
4698 struct cmd_show_bypass_config_result {
4699         cmdline_fixed_string_t show;
4700         cmdline_fixed_string_t bypass;
4701         cmdline_fixed_string_t config;
4702         portid_t port_id;
4703 };
4704
4705 static void
4706 cmd_show_bypass_config_parsed(void *parsed_result,
4707                 __attribute__((unused)) struct cmdline *cl,
4708                 __attribute__((unused)) void *data)
4709 {
4710         struct cmd_show_bypass_config_result *res = parsed_result;
4711         portid_t port_id = res->port_id;
4712         int rc = -EINVAL;
4713 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4714         uint32_t event_mode;
4715         uint32_t bypass_mode;
4716         uint32_t timeout = bypass_timeout;
4717         int i;
4718
4719         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4720                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4721         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4722                 {"UNKNOWN", "normal", "bypass", "isolate"};
4723         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4724                 "NONE",
4725                 "OS/board on",
4726                 "power supply on",
4727                 "OS/board off",
4728                 "power supply off",
4729                 "timeout"};
4730         int num_events = (sizeof events) / (sizeof events[0]);
4731
4732         /* Display the bypass mode.*/
4733         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4734                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4735                 return;
4736         }
4737         else {
4738                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4739                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4740
4741                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4742         }
4743
4744         /* Display the bypass timeout.*/
4745         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4746                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4747
4748         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4749
4750         /* Display the bypass events and associated modes. */
4751         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4752
4753                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4754                         printf("\tFailed to get bypass mode for event = %s\n",
4755                                 events[i]);
4756                 } else {
4757                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4758                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4759
4760                         printf("\tbypass event: %-16s = %s\n", events[i],
4761                                 modes[event_mode]);
4762                 }
4763         }
4764 #endif
4765         if (rc != 0)
4766                 printf("\tFailed to get bypass configuration for port = %d\n",
4767                        port_id);
4768 }
4769
4770 cmdline_parse_token_string_t cmd_showbypass_config_show =
4771         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4772                         show, "show");
4773 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4774         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4775                         bypass, "bypass");
4776 cmdline_parse_token_string_t cmd_showbypass_config_config =
4777         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4778                         config, "config");
4779 cmdline_parse_token_num_t cmd_showbypass_config_port =
4780         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4781                                 port_id, UINT16);
4782
4783 cmdline_parse_inst_t cmd_show_bypass_config = {
4784         .f = cmd_show_bypass_config_parsed,
4785         .help_str = "show bypass config <port_id>: "
4786                     "Show the NIC bypass config for port_id",
4787         .data = NULL,
4788         .tokens = {
4789                 (void *)&cmd_showbypass_config_show,
4790                 (void *)&cmd_showbypass_config_bypass,
4791                 (void *)&cmd_showbypass_config_config,
4792                 (void *)&cmd_showbypass_config_port,
4793                 NULL,
4794         },
4795 };
4796
4797 #ifdef RTE_LIBRTE_PMD_BOND
4798 /* *** SET BONDING MODE *** */
4799 struct cmd_set_bonding_mode_result {
4800         cmdline_fixed_string_t set;
4801         cmdline_fixed_string_t bonding;
4802         cmdline_fixed_string_t mode;
4803         uint8_t value;
4804         portid_t port_id;
4805 };
4806
4807 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4808                 __attribute__((unused))  struct cmdline *cl,
4809                 __attribute__((unused)) void *data)
4810 {
4811         struct cmd_set_bonding_mode_result *res = parsed_result;
4812         portid_t port_id = res->port_id;
4813
4814         /* Set the bonding mode for the relevant port. */
4815         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4816                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4817 }
4818
4819 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4820 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4821                 set, "set");
4822 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4823 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4824                 bonding, "bonding");
4825 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4826 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4827                 mode, "mode");
4828 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4829 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4830                 value, UINT8);
4831 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4832 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4833                 port_id, UINT16);
4834
4835 cmdline_parse_inst_t cmd_set_bonding_mode = {
4836                 .f = cmd_set_bonding_mode_parsed,
4837                 .help_str = "set bonding mode <mode_value> <port_id>: "
4838                         "Set the bonding mode for port_id",
4839                 .data = NULL,
4840                 .tokens = {
4841                                 (void *) &cmd_setbonding_mode_set,
4842                                 (void *) &cmd_setbonding_mode_bonding,
4843                                 (void *) &cmd_setbonding_mode_mode,
4844                                 (void *) &cmd_setbonding_mode_value,
4845                                 (void *) &cmd_setbonding_mode_port,
4846                                 NULL
4847                 }
4848 };
4849
4850 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4851 struct cmd_set_bonding_lacp_dedicated_queues_result {
4852         cmdline_fixed_string_t set;
4853         cmdline_fixed_string_t bonding;
4854         cmdline_fixed_string_t lacp;
4855         cmdline_fixed_string_t dedicated_queues;
4856         portid_t port_id;
4857         cmdline_fixed_string_t mode;
4858 };
4859
4860 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4861                 __attribute__((unused))  struct cmdline *cl,
4862                 __attribute__((unused)) void *data)
4863 {
4864         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4865         portid_t port_id = res->port_id;
4866         struct rte_port *port;
4867
4868         port = &ports[port_id];
4869
4870         /** Check if the port is not started **/
4871         if (port->port_status != RTE_PORT_STOPPED) {
4872                 printf("Please stop port %d first\n", port_id);
4873                 return;
4874         }
4875
4876         if (!strcmp(res->mode, "enable")) {
4877                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4878                         printf("Dedicate queues for LACP control packets"
4879                                         " enabled\n");
4880                 else
4881                         printf("Enabling dedicate queues for LACP control "
4882                                         "packets on port %d failed\n", port_id);
4883         } else if (!strcmp(res->mode, "disable")) {
4884                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4885                         printf("Dedicated queues for LACP control packets "
4886                                         "disabled\n");
4887                 else
4888                         printf("Disabling dedicated queues for LACP control "
4889                                         "traffic on port %d failed\n", port_id);
4890         }
4891 }
4892
4893 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4894 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4895                 set, "set");
4896 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4897 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4898                 bonding, "bonding");
4899 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4900 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4901                 lacp, "lacp");
4902 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4903 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4904                 dedicated_queues, "dedicated_queues");
4905 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4906 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4907                 port_id, UINT16);
4908 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4909 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4910                 mode, "enable#disable");
4911
4912 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4913                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4914                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4915                         "enable|disable: "
4916                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4917                 .data = NULL,
4918                 .tokens = {
4919                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4920                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4921                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4922                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4923                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4924                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4925                         NULL
4926                 }
4927 };
4928
4929 /* *** SET BALANCE XMIT POLICY *** */
4930 struct cmd_set_bonding_balance_xmit_policy_result {
4931         cmdline_fixed_string_t set;
4932         cmdline_fixed_string_t bonding;
4933         cmdline_fixed_string_t balance_xmit_policy;
4934         portid_t port_id;
4935         cmdline_fixed_string_t policy;
4936 };
4937
4938 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4939                 __attribute__((unused))  struct cmdline *cl,
4940                 __attribute__((unused)) void *data)
4941 {
4942         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4943         portid_t port_id = res->port_id;
4944         uint8_t policy;
4945
4946         if (!strcmp(res->policy, "l2")) {
4947                 policy = BALANCE_XMIT_POLICY_LAYER2;
4948         } else if (!strcmp(res->policy, "l23")) {
4949                 policy = BALANCE_XMIT_POLICY_LAYER23;
4950         } else if (!strcmp(res->policy, "l34")) {
4951                 policy = BALANCE_XMIT_POLICY_LAYER34;
4952         } else {
4953                 printf("\t Invalid xmit policy selection");
4954                 return;
4955         }
4956
4957         /* Set the bonding mode for the relevant port. */
4958         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4959                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4960                                 port_id);
4961         }
4962 }
4963
4964 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4965 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4966                 set, "set");
4967 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4968 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4969                 bonding, "bonding");
4970 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4971 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4972                 balance_xmit_policy, "balance_xmit_policy");
4973 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4974 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4975                 port_id, UINT16);
4976 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4977 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4978                 policy, "l2#l23#l34");
4979
4980 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4981                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4982                 .help_str = "set bonding balance_xmit_policy <port_id> "
4983                         "l2|l23|l34: "
4984                         "Set the bonding balance_xmit_policy for port_id",
4985                 .data = NULL,
4986                 .tokens = {
4987                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4988                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4989                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4990                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4991                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4992                                 NULL
4993                 }
4994 };
4995
4996 /* *** SHOW NIC BONDING CONFIGURATION *** */
4997 struct cmd_show_bonding_config_result {
4998         cmdline_fixed_string_t show;
4999         cmdline_fixed_string_t bonding;
5000         cmdline_fixed_string_t config;
5001         portid_t port_id;
5002 };
5003
5004 static void cmd_show_bonding_config_parsed(void *parsed_result,
5005                 __attribute__((unused))  struct cmdline *cl,
5006                 __attribute__((unused)) void *data)
5007 {
5008         struct cmd_show_bonding_config_result *res = parsed_result;
5009         int bonding_mode, agg_mode;
5010         portid_t slaves[RTE_MAX_ETHPORTS];
5011         int num_slaves, num_active_slaves;
5012         int primary_id;
5013         int i;
5014         portid_t port_id = res->port_id;
5015
5016         /* Display the bonding mode.*/
5017         bonding_mode = rte_eth_bond_mode_get(port_id);
5018         if (bonding_mode < 0) {
5019                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5020                 return;
5021         } else
5022                 printf("\tBonding mode: %d\n", bonding_mode);
5023
5024         if (bonding_mode == BONDING_MODE_BALANCE) {
5025                 int balance_xmit_policy;
5026
5027                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5028                 if (balance_xmit_policy < 0) {
5029                         printf("\tFailed to get balance xmit policy for port = %d\n",
5030                                         port_id);
5031                         return;
5032                 } else {
5033                         printf("\tBalance Xmit Policy: ");
5034
5035                         switch (balance_xmit_policy) {
5036                         case BALANCE_XMIT_POLICY_LAYER2:
5037                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5038                                 break;
5039                         case BALANCE_XMIT_POLICY_LAYER23:
5040                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5041                                 break;
5042                         case BALANCE_XMIT_POLICY_LAYER34:
5043                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5044                                 break;
5045                         }
5046                         printf("\n");
5047                 }
5048         }
5049
5050         if (bonding_mode == BONDING_MODE_8023AD) {
5051                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5052                 printf("\tIEEE802.3AD Aggregator Mode: ");
5053                 switch (agg_mode) {
5054                 case AGG_BANDWIDTH:
5055                         printf("bandwidth");
5056                         break;
5057                 case AGG_STABLE:
5058                         printf("stable");
5059                         break;
5060                 case AGG_COUNT:
5061                         printf("count");
5062                         break;
5063                 }
5064                 printf("\n");
5065         }
5066
5067         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5068
5069         if (num_slaves < 0) {
5070                 printf("\tFailed to get slave list for port = %d\n", port_id);
5071                 return;
5072         }
5073         if (num_slaves > 0) {
5074                 printf("\tSlaves (%d): [", num_slaves);
5075                 for (i = 0; i < num_slaves - 1; i++)
5076                         printf("%d ", slaves[i]);
5077
5078                 printf("%d]\n", slaves[num_slaves - 1]);
5079         } else {
5080                 printf("\tSlaves: []\n");
5081
5082         }
5083
5084         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5085                         RTE_MAX_ETHPORTS);
5086
5087         if (num_active_slaves < 0) {
5088                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5089                 return;
5090         }
5091         if (num_active_slaves > 0) {
5092                 printf("\tActive Slaves (%d): [", num_active_slaves);
5093                 for (i = 0; i < num_active_slaves - 1; i++)
5094                         printf("%d ", slaves[i]);
5095
5096                 printf("%d]\n", slaves[num_active_slaves - 1]);
5097
5098         } else {
5099                 printf("\tActive Slaves: []\n");
5100
5101         }
5102
5103         primary_id = rte_eth_bond_primary_get(port_id);
5104         if (primary_id < 0) {
5105                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5106                 return;
5107         } else
5108                 printf("\tPrimary: [%d]\n", primary_id);
5109
5110 }
5111
5112 cmdline_parse_token_string_t cmd_showbonding_config_show =
5113 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5114                 show, "show");
5115 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5116 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5117                 bonding, "bonding");
5118 cmdline_parse_token_string_t cmd_showbonding_config_config =
5119 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5120                 config, "config");
5121 cmdline_parse_token_num_t cmd_showbonding_config_port =
5122 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5123                 port_id, UINT16);
5124
5125 cmdline_parse_inst_t cmd_show_bonding_config = {
5126                 .f = cmd_show_bonding_config_parsed,
5127                 .help_str = "show bonding config <port_id>: "
5128                         "Show the bonding config for port_id",
5129                 .data = NULL,
5130                 .tokens = {
5131                                 (void *)&cmd_showbonding_config_show,
5132                                 (void *)&cmd_showbonding_config_bonding,
5133                                 (void *)&cmd_showbonding_config_config,
5134                                 (void *)&cmd_showbonding_config_port,
5135                                 NULL
5136                 }
5137 };
5138
5139 /* *** SET BONDING PRIMARY *** */
5140 struct cmd_set_bonding_primary_result {
5141         cmdline_fixed_string_t set;
5142         cmdline_fixed_string_t bonding;
5143         cmdline_fixed_string_t primary;
5144         portid_t slave_id;
5145         portid_t port_id;
5146 };
5147
5148 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5149                 __attribute__((unused))  struct cmdline *cl,
5150                 __attribute__((unused)) void *data)
5151 {
5152         struct cmd_set_bonding_primary_result *res = parsed_result;
5153         portid_t master_port_id = res->port_id;
5154         portid_t slave_port_id = res->slave_id;
5155
5156         /* Set the primary slave for a bonded device. */
5157         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5158                 printf("\t Failed to set primary slave for port = %d.\n",
5159                                 master_port_id);
5160                 return;
5161         }
5162         init_port_config();
5163 }
5164
5165 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5166 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5167                 set, "set");
5168 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5169 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5170                 bonding, "bonding");
5171 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5172 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5173                 primary, "primary");
5174 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5175 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5176                 slave_id, UINT16);
5177 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5178 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5179                 port_id, UINT16);
5180
5181 cmdline_parse_inst_t cmd_set_bonding_primary = {
5182                 .f = cmd_set_bonding_primary_parsed,
5183                 .help_str = "set bonding primary <slave_id> <port_id>: "
5184                         "Set the primary slave for port_id",
5185                 .data = NULL,
5186                 .tokens = {
5187                                 (void *)&cmd_setbonding_primary_set,
5188                                 (void *)&cmd_setbonding_primary_bonding,
5189                                 (void *)&cmd_setbonding_primary_primary,
5190                                 (void *)&cmd_setbonding_primary_slave,
5191                                 (void *)&cmd_setbonding_primary_port,
5192                                 NULL
5193                 }
5194 };
5195
5196 /* *** ADD SLAVE *** */
5197 struct cmd_add_bonding_slave_result {
5198         cmdline_fixed_string_t add;
5199         cmdline_fixed_string_t bonding;
5200         cmdline_fixed_string_t slave;
5201         portid_t slave_id;
5202         portid_t port_id;
5203 };
5204
5205 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5206                 __attribute__((unused))  struct cmdline *cl,
5207                 __attribute__((unused)) void *data)
5208 {
5209         struct cmd_add_bonding_slave_result *res = parsed_result;
5210         portid_t master_port_id = res->port_id;
5211         portid_t slave_port_id = res->slave_id;
5212
5213         /* add the slave for a bonded device. */
5214         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5215                 printf("\t Failed to add slave %d to master port = %d.\n",
5216                                 slave_port_id, master_port_id);
5217                 return;
5218         }
5219         init_port_config();
5220         set_port_slave_flag(slave_port_id);
5221 }
5222
5223 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5224 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5225                 add, "add");
5226 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5227 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5228                 bonding, "bonding");
5229 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5230 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5231                 slave, "slave");
5232 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5233 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5234                 slave_id, UINT16);
5235 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5236 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5237                 port_id, UINT16);
5238
5239 cmdline_parse_inst_t cmd_add_bonding_slave = {
5240                 .f = cmd_add_bonding_slave_parsed,
5241                 .help_str = "add bonding slave <slave_id> <port_id>: "
5242                         "Add a slave device to a bonded device",
5243                 .data = NULL,
5244                 .tokens = {
5245                                 (void *)&cmd_addbonding_slave_add,
5246                                 (void *)&cmd_addbonding_slave_bonding,
5247                                 (void *)&cmd_addbonding_slave_slave,
5248                                 (void *)&cmd_addbonding_slave_slaveid,
5249                                 (void *)&cmd_addbonding_slave_port,
5250                                 NULL
5251                 }
5252 };
5253
5254 /* *** REMOVE SLAVE *** */
5255 struct cmd_remove_bonding_slave_result {
5256         cmdline_fixed_string_t remove;
5257         cmdline_fixed_string_t bonding;
5258         cmdline_fixed_string_t slave;
5259         portid_t slave_id;
5260         portid_t port_id;
5261 };
5262
5263 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5264                 __attribute__((unused))  struct cmdline *cl,
5265                 __attribute__((unused)) void *data)
5266 {
5267         struct cmd_remove_bonding_slave_result *res = parsed_result;
5268         portid_t master_port_id = res->port_id;
5269         portid_t slave_port_id = res->slave_id;
5270
5271         /* remove the slave from a bonded device. */
5272         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5273                 printf("\t Failed to remove slave %d from master port = %d.\n",
5274                                 slave_port_id, master_port_id);
5275                 return;
5276         }
5277         init_port_config();
5278         clear_port_slave_flag(slave_port_id);
5279 }
5280
5281 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5282                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5283                                 remove, "remove");
5284 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5285                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5286                                 bonding, "bonding");
5287 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5288                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5289                                 slave, "slave");
5290 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5291                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5292                                 slave_id, UINT16);
5293 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5294                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5295                                 port_id, UINT16);
5296
5297 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5298                 .f = cmd_remove_bonding_slave_parsed,
5299                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5300                         "Remove a slave device from a bonded device",
5301                 .data = NULL,
5302                 .tokens = {
5303                                 (void *)&cmd_removebonding_slave_remove,
5304                                 (void *)&cmd_removebonding_slave_bonding,
5305                                 (void *)&cmd_removebonding_slave_slave,
5306                                 (void *)&cmd_removebonding_slave_slaveid,
5307                                 (void *)&cmd_removebonding_slave_port,
5308                                 NULL
5309                 }
5310 };
5311
5312 /* *** CREATE BONDED DEVICE *** */
5313 struct cmd_create_bonded_device_result {
5314         cmdline_fixed_string_t create;
5315         cmdline_fixed_string_t bonded;
5316         cmdline_fixed_string_t device;
5317         uint8_t mode;
5318         uint8_t socket;
5319 };
5320
5321 static int bond_dev_num = 0;
5322
5323 static void cmd_create_bonded_device_parsed(void *parsed_result,
5324                 __attribute__((unused))  struct cmdline *cl,
5325                 __attribute__((unused)) void *data)
5326 {
5327         struct cmd_create_bonded_device_result *res = parsed_result;
5328         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5329         int port_id;
5330
5331         if (test_done == 0) {
5332                 printf("Please stop forwarding first\n");
5333                 return;
5334         }
5335
5336         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5337                         bond_dev_num++);
5338
5339         /* Create a new bonded device. */
5340         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5341         if (port_id < 0) {
5342                 printf("\t Failed to create bonded device.\n");
5343                 return;
5344         } else {
5345                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5346                                 port_id);
5347
5348                 /* Update number of ports */
5349                 nb_ports = rte_eth_dev_count();
5350                 reconfig(port_id, res->socket);
5351                 rte_eth_promiscuous_enable(port_id);
5352         }
5353
5354 }
5355
5356 cmdline_parse_token_string_t cmd_createbonded_device_create =
5357                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5358                                 create, "create");
5359 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5360                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5361                                 bonded, "bonded");
5362 cmdline_parse_token_string_t cmd_createbonded_device_device =
5363                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5364                                 device, "device");
5365 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5366                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5367                                 mode, UINT8);
5368 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5369                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5370                                 socket, UINT8);
5371
5372 cmdline_parse_inst_t cmd_create_bonded_device = {
5373                 .f = cmd_create_bonded_device_parsed,
5374                 .help_str = "create bonded device <mode> <socket>: "
5375                         "Create a new bonded device with specific bonding mode and socket",
5376                 .data = NULL,
5377                 .tokens = {
5378                                 (void *)&cmd_createbonded_device_create,
5379                                 (void *)&cmd_createbonded_device_bonded,
5380                                 (void *)&cmd_createbonded_device_device,
5381                                 (void *)&cmd_createbonded_device_mode,
5382                                 (void *)&cmd_createbonded_device_socket,
5383                                 NULL
5384                 }
5385 };
5386
5387 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5388 struct cmd_set_bond_mac_addr_result {
5389         cmdline_fixed_string_t set;
5390         cmdline_fixed_string_t bonding;
5391         cmdline_fixed_string_t mac_addr;
5392         uint16_t port_num;
5393         struct ether_addr address;
5394 };
5395
5396 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5397                 __attribute__((unused))  struct cmdline *cl,
5398                 __attribute__((unused)) void *data)
5399 {
5400         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5401         int ret;
5402
5403         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5404                 return;
5405
5406         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5407
5408         /* check the return value and print it if is < 0 */
5409         if (ret < 0)
5410                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5411 }
5412
5413 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5414                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5415 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5416                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5417                                 "bonding");
5418 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5419                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5420                                 "mac_addr");
5421 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5422                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5423                                 port_num, UINT16);
5424 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5425                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5426
5427 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5428                 .f = cmd_set_bond_mac_addr_parsed,
5429                 .data = (void *) 0,
5430                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5431                 .tokens = {
5432                                 (void *)&cmd_set_bond_mac_addr_set,
5433                                 (void *)&cmd_set_bond_mac_addr_bonding,
5434                                 (void *)&cmd_set_bond_mac_addr_mac,
5435                                 (void *)&cmd_set_bond_mac_addr_portnum,
5436                                 (void *)&cmd_set_bond_mac_addr_addr,
5437                                 NULL
5438                 }
5439 };
5440
5441
5442 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5443 struct cmd_set_bond_mon_period_result {
5444         cmdline_fixed_string_t set;
5445         cmdline_fixed_string_t bonding;
5446         cmdline_fixed_string_t mon_period;
5447         uint16_t port_num;
5448         uint32_t period_ms;
5449 };
5450
5451 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5452                 __attribute__((unused))  struct cmdline *cl,
5453                 __attribute__((unused)) void *data)
5454 {
5455         struct cmd_set_bond_mon_period_result *res = parsed_result;
5456         int ret;
5457
5458         if (res->port_num >= nb_ports) {
5459                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5460                 return;
5461         }
5462
5463         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5464
5465         /* check the return value and print it if is < 0 */
5466         if (ret < 0)
5467                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5468 }
5469
5470 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5471                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5472                                 set, "set");
5473 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5474                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5475                                 bonding, "bonding");
5476 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5477                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5478                                 mon_period,     "mon_period");
5479 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5480                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5481                                 port_num, UINT16);
5482 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5483                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5484                                 period_ms, UINT32);
5485
5486 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5487                 .f = cmd_set_bond_mon_period_parsed,
5488                 .data = (void *) 0,
5489                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5490                 .tokens = {
5491                                 (void *)&cmd_set_bond_mon_period_set,
5492                                 (void *)&cmd_set_bond_mon_period_bonding,
5493                                 (void *)&cmd_set_bond_mon_period_mon_period,
5494                                 (void *)&cmd_set_bond_mon_period_portnum,
5495                                 (void *)&cmd_set_bond_mon_period_period_ms,
5496                                 NULL
5497                 }
5498 };
5499
5500
5501
5502 struct cmd_set_bonding_agg_mode_policy_result {
5503         cmdline_fixed_string_t set;
5504         cmdline_fixed_string_t bonding;
5505         cmdline_fixed_string_t agg_mode;
5506         uint16_t port_num;
5507         cmdline_fixed_string_t policy;
5508 };
5509
5510
5511 static void
5512 cmd_set_bonding_agg_mode(void *parsed_result,
5513                 __attribute__((unused)) struct cmdline *cl,
5514                 __attribute__((unused)) void *data)
5515 {
5516         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5517         uint8_t policy = AGG_BANDWIDTH;
5518
5519         if (res->port_num >= nb_ports) {
5520                 printf("Port id %d must be less than %d\n",
5521                                 res->port_num, nb_ports);
5522                 return;
5523         }
5524
5525         if (!strcmp(res->policy, "bandwidth"))
5526                 policy = AGG_BANDWIDTH;
5527         else if (!strcmp(res->policy, "stable"))
5528                 policy = AGG_STABLE;
5529         else if (!strcmp(res->policy, "count"))
5530                 policy = AGG_COUNT;
5531
5532         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5533 }
5534
5535
5536 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5537         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5538                                 set, "set");
5539 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5540         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5541                                 bonding, "bonding");
5542
5543 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5544         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5545                                 agg_mode, "agg_mode");
5546
5547 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5548         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5549                                 port_num, UINT16);
5550
5551 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5552         TOKEN_STRING_INITIALIZER(
5553                         struct cmd_set_bonding_balance_xmit_policy_result,
5554                 policy, "stable#bandwidth#count");
5555
5556 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5557         .f = cmd_set_bonding_agg_mode,
5558         .data = (void *) 0,
5559         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5560         .tokens = {
5561                         (void *)&cmd_set_bonding_agg_mode_set,
5562                         (void *)&cmd_set_bonding_agg_mode_bonding,
5563                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5564                         (void *)&cmd_set_bonding_agg_mode_portnum,
5565                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5566                         NULL
5567                 }
5568 };
5569
5570
5571 #endif /* RTE_LIBRTE_PMD_BOND */
5572
5573 /* *** SET FORWARDING MODE *** */
5574 struct cmd_set_fwd_mode_result {
5575         cmdline_fixed_string_t set;
5576         cmdline_fixed_string_t fwd;
5577         cmdline_fixed_string_t mode;
5578 };
5579
5580 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5581                                     __attribute__((unused)) struct cmdline *cl,
5582                                     __attribute__((unused)) void *data)
5583 {
5584         struct cmd_set_fwd_mode_result *res = parsed_result;
5585
5586         retry_enabled = 0;
5587         set_pkt_forwarding_mode(res->mode);
5588 }
5589
5590 cmdline_parse_token_string_t cmd_setfwd_set =
5591         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5592 cmdline_parse_token_string_t cmd_setfwd_fwd =
5593         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5594 cmdline_parse_token_string_t cmd_setfwd_mode =
5595         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5596                 "" /* defined at init */);
5597
5598 cmdline_parse_inst_t cmd_set_fwd_mode = {
5599         .f = cmd_set_fwd_mode_parsed,
5600         .data = NULL,
5601         .help_str = NULL, /* defined at init */
5602         .tokens = {
5603                 (void *)&cmd_setfwd_set,
5604                 (void *)&cmd_setfwd_fwd,
5605                 (void *)&cmd_setfwd_mode,
5606                 NULL,
5607         },
5608 };
5609
5610 static void cmd_set_fwd_mode_init(void)
5611 {
5612         char *modes, *c;
5613         static char token[128];
5614         static char help[256];
5615         cmdline_parse_token_string_t *token_struct;
5616
5617         modes = list_pkt_forwarding_modes();
5618         snprintf(help, sizeof(help), "set fwd %s: "
5619                 "Set packet forwarding mode", modes);
5620         cmd_set_fwd_mode.help_str = help;
5621
5622         /* string token separator is # */
5623         for (c = token; *modes != '\0'; modes++)
5624                 if (*modes == '|')
5625                         *c++ = '#';
5626                 else
5627                         *c++ = *modes;
5628         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5629         token_struct->string_data.str = token;
5630 }
5631
5632 /* *** SET RETRY FORWARDING MODE *** */
5633 struct cmd_set_fwd_retry_mode_result {
5634         cmdline_fixed_string_t set;
5635         cmdline_fixed_string_t fwd;
5636         cmdline_fixed_string_t mode;
5637         cmdline_fixed_string_t retry;
5638 };
5639
5640 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5641                             __attribute__((unused)) struct cmdline *cl,
5642                             __attribute__((unused)) void *data)
5643 {
5644         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5645
5646         retry_enabled = 1;
5647         set_pkt_forwarding_mode(res->mode);
5648 }
5649
5650 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5651         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5652                         set, "set");
5653 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5654         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5655                         fwd, "fwd");
5656 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5657         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5658                         mode,
5659                 "" /* defined at init */);
5660 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5661         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5662                         retry, "retry");
5663
5664 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5665         .f = cmd_set_fwd_retry_mode_parsed,
5666         .data = NULL,
5667         .help_str = NULL, /* defined at init */
5668         .tokens = {
5669                 (void *)&cmd_setfwd_retry_set,
5670                 (void *)&cmd_setfwd_retry_fwd,
5671                 (void *)&cmd_setfwd_retry_mode,
5672                 (void *)&cmd_setfwd_retry_retry,
5673                 NULL,
5674         },
5675 };
5676
5677 static void cmd_set_fwd_retry_mode_init(void)
5678 {
5679         char *modes, *c;
5680         static char token[128];
5681         static char help[256];
5682         cmdline_parse_token_string_t *token_struct;
5683
5684         modes = list_pkt_forwarding_retry_modes();
5685         snprintf(help, sizeof(help), "set fwd %s retry: "
5686                 "Set packet forwarding mode with retry", modes);
5687         cmd_set_fwd_retry_mode.help_str = help;
5688
5689         /* string token separator is # */
5690         for (c = token; *modes != '\0'; modes++)
5691                 if (*modes == '|')
5692                         *c++ = '#';
5693                 else
5694                         *c++ = *modes;
5695         token_struct = (cmdline_parse_token_string_t *)
5696                 cmd_set_fwd_retry_mode.tokens[2];
5697         token_struct->string_data.str = token;
5698 }
5699
5700 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5701 struct cmd_set_burst_tx_retry_result {
5702         cmdline_fixed_string_t set;
5703         cmdline_fixed_string_t burst;
5704         cmdline_fixed_string_t tx;
5705         cmdline_fixed_string_t delay;
5706         uint32_t time;
5707         cmdline_fixed_string_t retry;
5708         uint32_t retry_num;
5709 };
5710
5711 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5712                                         __attribute__((unused)) struct cmdline *cl,
5713                                         __attribute__((unused)) void *data)
5714 {
5715         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5716
5717         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5718                 && !strcmp(res->tx, "tx")) {
5719                 if (!strcmp(res->delay, "delay"))
5720                         burst_tx_delay_time = res->time;
5721                 if (!strcmp(res->retry, "retry"))
5722                         burst_tx_retry_num = res->retry_num;
5723         }
5724
5725 }
5726
5727 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5728         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5729 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5730         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5731                                  "burst");
5732 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5733         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5734 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5735         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5736 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5737         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5738 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5739         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5740 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5741         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5742
5743 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5744         .f = cmd_set_burst_tx_retry_parsed,
5745         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5746         .tokens = {
5747                 (void *)&cmd_set_burst_tx_retry_set,
5748                 (void *)&cmd_set_burst_tx_retry_burst,
5749                 (void *)&cmd_set_burst_tx_retry_tx,
5750                 (void *)&cmd_set_burst_tx_retry_delay,
5751                 (void *)&cmd_set_burst_tx_retry_time,
5752                 (void *)&cmd_set_burst_tx_retry_retry,
5753                 (void *)&cmd_set_burst_tx_retry_retry_num,
5754                 NULL,
5755         },
5756 };
5757
5758 /* *** SET PROMISC MODE *** */
5759 struct cmd_set_promisc_mode_result {
5760         cmdline_fixed_string_t set;
5761         cmdline_fixed_string_t promisc;
5762         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5763         uint16_t port_num;               /* valid if "allports" argument == 0 */
5764         cmdline_fixed_string_t mode;
5765 };
5766
5767 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5768                                         __attribute__((unused)) struct cmdline *cl,
5769                                         void *allports)
5770 {
5771         struct cmd_set_promisc_mode_result *res = parsed_result;
5772         int enable;
5773         portid_t i;
5774
5775         if (!strcmp(res->mode, "on"))
5776                 enable = 1;
5777         else
5778                 enable = 0;
5779
5780         /* all ports */
5781         if (allports) {
5782                 RTE_ETH_FOREACH_DEV(i) {
5783                         if (enable)
5784                                 rte_eth_promiscuous_enable(i);
5785                         else
5786                                 rte_eth_promiscuous_disable(i);
5787                 }
5788         }
5789         else {
5790                 if (enable)
5791                         rte_eth_promiscuous_enable(res->port_num);
5792                 else
5793                         rte_eth_promiscuous_disable(res->port_num);
5794         }
5795 }
5796
5797 cmdline_parse_token_string_t cmd_setpromisc_set =
5798         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5799 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5800         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5801                                  "promisc");
5802 cmdline_parse_token_string_t cmd_setpromisc_portall =
5803         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5804                                  "all");
5805 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5806         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5807                               UINT8);
5808 cmdline_parse_token_string_t cmd_setpromisc_mode =
5809         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5810                                  "on#off");
5811
5812 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5813         .f = cmd_set_promisc_mode_parsed,
5814         .data = (void *)1,
5815         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5816         .tokens = {
5817                 (void *)&cmd_setpromisc_set,
5818                 (void *)&cmd_setpromisc_promisc,
5819                 (void *)&cmd_setpromisc_portall,
5820                 (void *)&cmd_setpromisc_mode,
5821                 NULL,
5822         },
5823 };
5824
5825 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5826         .f = cmd_set_promisc_mode_parsed,
5827         .data = (void *)0,
5828         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5829         .tokens = {
5830                 (void *)&cmd_setpromisc_set,
5831                 (void *)&cmd_setpromisc_promisc,
5832                 (void *)&cmd_setpromisc_portnum,
5833                 (void *)&cmd_setpromisc_mode,
5834                 NULL,
5835         },
5836 };
5837
5838 /* *** SET ALLMULTI MODE *** */
5839 struct cmd_set_allmulti_mode_result {
5840         cmdline_fixed_string_t set;
5841         cmdline_fixed_string_t allmulti;
5842         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5843         uint16_t port_num;               /* valid if "allports" argument == 0 */
5844         cmdline_fixed_string_t mode;
5845 };
5846
5847 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5848                                         __attribute__((unused)) struct cmdline *cl,
5849                                         void *allports)
5850 {
5851         struct cmd_set_allmulti_mode_result *res = parsed_result;
5852         int enable;
5853         portid_t i;
5854
5855         if (!strcmp(res->mode, "on"))
5856                 enable = 1;
5857         else
5858                 enable = 0;
5859
5860         /* all ports */
5861         if (allports) {
5862                 RTE_ETH_FOREACH_DEV(i) {
5863                         if (enable)
5864                                 rte_eth_allmulticast_enable(i);
5865                         else
5866                                 rte_eth_allmulticast_disable(i);
5867                 }
5868         }
5869         else {
5870                 if (enable)
5871                         rte_eth_allmulticast_enable(res->port_num);
5872                 else
5873                         rte_eth_allmulticast_disable(res->port_num);
5874         }
5875 }
5876
5877 cmdline_parse_token_string_t cmd_setallmulti_set =
5878         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5879 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5880         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5881                                  "allmulti");
5882 cmdline_parse_token_string_t cmd_setallmulti_portall =
5883         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5884                                  "all");
5885 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5886         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5887                               UINT16);
5888 cmdline_parse_token_string_t cmd_setallmulti_mode =
5889         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5890                                  "on#off");
5891
5892 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5893         .f = cmd_set_allmulti_mode_parsed,
5894         .data = (void *)1,
5895         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5896         .tokens = {
5897                 (void *)&cmd_setallmulti_set,
5898                 (void *)&cmd_setallmulti_allmulti,
5899                 (void *)&cmd_setallmulti_portall,
5900                 (void *)&cmd_setallmulti_mode,
5901                 NULL,
5902         },
5903 };
5904
5905 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5906         .f = cmd_set_allmulti_mode_parsed,
5907         .data = (void *)0,
5908         .help_str = "set allmulti <port_id> on|off: "
5909                 "Set allmulti mode on port_id",
5910         .tokens = {
5911                 (void *)&cmd_setallmulti_set,
5912                 (void *)&cmd_setallmulti_allmulti,
5913                 (void *)&cmd_setallmulti_portnum,
5914                 (void *)&cmd_setallmulti_mode,
5915                 NULL,
5916         },
5917 };
5918
5919 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5920 struct cmd_link_flow_ctrl_set_result {
5921         cmdline_fixed_string_t set;
5922         cmdline_fixed_string_t flow_ctrl;
5923         cmdline_fixed_string_t rx;
5924         cmdline_fixed_string_t rx_lfc_mode;
5925         cmdline_fixed_string_t tx;
5926         cmdline_fixed_string_t tx_lfc_mode;
5927         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5928         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5929         cmdline_fixed_string_t autoneg_str;
5930         cmdline_fixed_string_t autoneg;
5931         cmdline_fixed_string_t hw_str;
5932         uint32_t high_water;
5933         cmdline_fixed_string_t lw_str;
5934         uint32_t low_water;
5935         cmdline_fixed_string_t pt_str;
5936         uint16_t pause_time;
5937         cmdline_fixed_string_t xon_str;
5938         uint16_t send_xon;
5939         portid_t port_id;
5940 };
5941
5942 cmdline_parse_token_string_t cmd_lfc_set_set =
5943         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5944                                 set, "set");
5945 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5946         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5947                                 flow_ctrl, "flow_ctrl");
5948 cmdline_parse_token_string_t cmd_lfc_set_rx =
5949         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5950                                 rx, "rx");
5951 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5952         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5953                                 rx_lfc_mode, "on#off");
5954 cmdline_parse_token_string_t cmd_lfc_set_tx =
5955         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5956                                 tx, "tx");
5957 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5958         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5959                                 tx_lfc_mode, "on#off");
5960 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5961         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5962                                 hw_str, "high_water");
5963 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5964         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5965                                 high_water, UINT32);
5966 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5967         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5968                                 lw_str, "low_water");
5969 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5970         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5971                                 low_water, UINT32);
5972 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5973         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5974                                 pt_str, "pause_time");
5975 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5976         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5977                                 pause_time, UINT16);
5978 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5979         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5980                                 xon_str, "send_xon");
5981 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5982         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5983                                 send_xon, UINT16);
5984 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5985         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5986                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5987 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5988         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5989                                 mac_ctrl_frame_fwd_mode, "on#off");
5990 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5991         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5992                                 autoneg_str, "autoneg");
5993 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5994         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5995                                 autoneg, "on#off");
5996 cmdline_parse_token_num_t cmd_lfc_set_portid =
5997         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5998                                 port_id, UINT16);
5999
6000 /* forward declaration */
6001 static void
6002 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6003                               void *data);
6004
6005 cmdline_parse_inst_t cmd_link_flow_control_set = {
6006         .f = cmd_link_flow_ctrl_set_parsed,
6007         .data = NULL,
6008         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6009                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6010                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6011         .tokens = {
6012                 (void *)&cmd_lfc_set_set,
6013                 (void *)&cmd_lfc_set_flow_ctrl,
6014                 (void *)&cmd_lfc_set_rx,
6015                 (void *)&cmd_lfc_set_rx_mode,
6016                 (void *)&cmd_lfc_set_tx,
6017                 (void *)&cmd_lfc_set_tx_mode,
6018                 (void *)&cmd_lfc_set_high_water,
6019                 (void *)&cmd_lfc_set_low_water,
6020                 (void *)&cmd_lfc_set_pause_time,
6021                 (void *)&cmd_lfc_set_send_xon,
6022                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6023                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6024                 (void *)&cmd_lfc_set_autoneg_str,
6025                 (void *)&cmd_lfc_set_autoneg,
6026                 (void *)&cmd_lfc_set_portid,
6027                 NULL,
6028         },
6029 };
6030
6031 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6032         .f = cmd_link_flow_ctrl_set_parsed,
6033         .data = (void *)&cmd_link_flow_control_set_rx,
6034         .help_str = "set flow_ctrl rx on|off <port_id>: "
6035                 "Change rx flow control parameter",
6036         .tokens = {
6037                 (void *)&cmd_lfc_set_set,
6038                 (void *)&cmd_lfc_set_flow_ctrl,
6039                 (void *)&cmd_lfc_set_rx,
6040                 (void *)&cmd_lfc_set_rx_mode,
6041                 (void *)&cmd_lfc_set_portid,
6042                 NULL,
6043         },
6044 };
6045
6046 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6047         .f = cmd_link_flow_ctrl_set_parsed,
6048         .data = (void *)&cmd_link_flow_control_set_tx,
6049         .help_str = "set flow_ctrl tx on|off <port_id>: "
6050                 "Change tx flow control parameter",
6051         .tokens = {
6052                 (void *)&cmd_lfc_set_set,
6053                 (void *)&cmd_lfc_set_flow_ctrl,
6054                 (void *)&cmd_lfc_set_tx,
6055                 (void *)&cmd_lfc_set_tx_mode,
6056                 (void *)&cmd_lfc_set_portid,
6057                 NULL,
6058         },
6059 };
6060
6061 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6062         .f = cmd_link_flow_ctrl_set_parsed,
6063         .data = (void *)&cmd_link_flow_control_set_hw,
6064         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6065                 "Change high water flow control parameter",
6066         .tokens = {
6067                 (void *)&cmd_lfc_set_set,
6068                 (void *)&cmd_lfc_set_flow_ctrl,
6069                 (void *)&cmd_lfc_set_high_water_str,
6070                 (void *)&cmd_lfc_set_high_water,
6071                 (void *)&cmd_lfc_set_portid,
6072                 NULL,
6073         },
6074 };
6075
6076 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6077         .f = cmd_link_flow_ctrl_set_parsed,
6078         .data = (void *)&cmd_link_flow_control_set_lw,
6079         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6080                 "Change low water flow control parameter",
6081         .tokens = {
6082                 (void *)&cmd_lfc_set_set,
6083                 (void *)&cmd_lfc_set_flow_ctrl,
6084                 (void *)&cmd_lfc_set_low_water_str,
6085                 (void *)&cmd_lfc_set_low_water,
6086                 (void *)&cmd_lfc_set_portid,
6087                 NULL,
6088         },
6089 };
6090
6091 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6092         .f = cmd_link_flow_ctrl_set_parsed,
6093         .data = (void *)&cmd_link_flow_control_set_pt,
6094         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6095                 "Change pause time flow control parameter",
6096         .tokens = {
6097                 (void *)&cmd_lfc_set_set,
6098                 (void *)&cmd_lfc_set_flow_ctrl,
6099                 (void *)&cmd_lfc_set_pause_time_str,
6100                 (void *)&cmd_lfc_set_pause_time,
6101                 (void *)&cmd_lfc_set_portid,
6102                 NULL,
6103         },
6104 };
6105
6106 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6107         .f = cmd_link_flow_ctrl_set_parsed,
6108         .data = (void *)&cmd_link_flow_control_set_xon,
6109         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6110                 "Change send_xon flow control parameter",
6111         .tokens = {
6112                 (void *)&cmd_lfc_set_set,
6113                 (void *)&cmd_lfc_set_flow_ctrl,
6114                 (void *)&cmd_lfc_set_send_xon_str,
6115                 (void *)&cmd_lfc_set_send_xon,
6116                 (void *)&cmd_lfc_set_portid,
6117                 NULL,
6118         },
6119 };
6120
6121 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6122         .f = cmd_link_flow_ctrl_set_parsed,
6123         .data = (void *)&cmd_link_flow_control_set_macfwd,
6124         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6125                 "Change mac ctrl fwd flow control parameter",
6126         .tokens = {
6127                 (void *)&cmd_lfc_set_set,
6128                 (void *)&cmd_lfc_set_flow_ctrl,
6129                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6130                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6131                 (void *)&cmd_lfc_set_portid,
6132                 NULL,
6133         },
6134 };
6135
6136 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6137         .f = cmd_link_flow_ctrl_set_parsed,
6138         .data = (void *)&cmd_link_flow_control_set_autoneg,
6139         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6140                 "Change autoneg flow control parameter",
6141         .tokens = {
6142                 (void *)&cmd_lfc_set_set,
6143                 (void *)&cmd_lfc_set_flow_ctrl,
6144                 (void *)&cmd_lfc_set_autoneg_str,
6145                 (void *)&cmd_lfc_set_autoneg,
6146                 (void *)&cmd_lfc_set_portid,
6147                 NULL,
6148         },
6149 };
6150
6151 static void
6152 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6153                               __attribute__((unused)) struct cmdline *cl,
6154                               void *data)
6155 {
6156         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6157         cmdline_parse_inst_t *cmd = data;
6158         struct rte_eth_fc_conf fc_conf;
6159         int rx_fc_en = 0;
6160         int tx_fc_en = 0;
6161         int ret;
6162
6163         /*
6164          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6165          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6166          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6167          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6168          */
6169         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6170                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6171         };
6172
6173         /* Partial command line, retrieve current configuration */
6174         if (cmd) {
6175                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6176                 if (ret != 0) {
6177                         printf("cannot get current flow ctrl parameters, return"
6178                                "code = %d\n", ret);
6179                         return;
6180                 }
6181
6182                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6183                     (fc_conf.mode == RTE_FC_FULL))
6184                         rx_fc_en = 1;
6185                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6186                     (fc_conf.mode == RTE_FC_FULL))
6187                         tx_fc_en = 1;
6188         }
6189
6190         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6191                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6192
6193         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6194                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6195
6196         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6197
6198         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6199                 fc_conf.high_water = res->high_water;
6200
6201         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6202                 fc_conf.low_water = res->low_water;
6203
6204         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6205                 fc_conf.pause_time = res->pause_time;
6206
6207         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6208                 fc_conf.send_xon = res->send_xon;
6209
6210         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6211                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6212                         fc_conf.mac_ctrl_frame_fwd = 1;
6213                 else
6214                         fc_conf.mac_ctrl_frame_fwd = 0;
6215         }
6216
6217         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6218                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6219
6220         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6221         if (ret != 0)
6222                 printf("bad flow contrl parameter, return code = %d \n", ret);
6223 }
6224
6225 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6226 struct cmd_priority_flow_ctrl_set_result {
6227         cmdline_fixed_string_t set;
6228         cmdline_fixed_string_t pfc_ctrl;
6229         cmdline_fixed_string_t rx;
6230         cmdline_fixed_string_t rx_pfc_mode;
6231         cmdline_fixed_string_t tx;
6232         cmdline_fixed_string_t tx_pfc_mode;
6233         uint32_t high_water;
6234         uint32_t low_water;
6235         uint16_t pause_time;
6236         uint8_t  priority;
6237         portid_t port_id;
6238 };
6239
6240 static void
6241 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6242                        __attribute__((unused)) struct cmdline *cl,
6243                        __attribute__((unused)) void *data)
6244 {
6245         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6246         struct rte_eth_pfc_conf pfc_conf;
6247         int rx_fc_enable, tx_fc_enable;
6248         int ret;
6249
6250         /*
6251          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6252          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6253          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6254          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6255          */
6256         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6257                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6258         };
6259
6260         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6261         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6262         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6263         pfc_conf.fc.high_water = res->high_water;
6264         pfc_conf.fc.low_water  = res->low_water;
6265         pfc_conf.fc.pause_time = res->pause_time;
6266         pfc_conf.priority      = res->priority;
6267
6268         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6269         if (ret != 0)
6270                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6271 }
6272
6273 cmdline_parse_token_string_t cmd_pfc_set_set =
6274         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6275                                 set, "set");
6276 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6277         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6278                                 pfc_ctrl, "pfc_ctrl");
6279 cmdline_parse_token_string_t cmd_pfc_set_rx =
6280         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6281                                 rx, "rx");
6282 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6283         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6284                                 rx_pfc_mode, "on#off");
6285 cmdline_parse_token_string_t cmd_pfc_set_tx =
6286         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6287                                 tx, "tx");
6288 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6289         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6290                                 tx_pfc_mode, "on#off");
6291 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6292         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6293                                 high_water, UINT32);
6294 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6295         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6296                                 low_water, UINT32);
6297 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6298         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6299                                 pause_time, UINT16);
6300 cmdline_parse_token_num_t cmd_pfc_set_priority =
6301         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6302                                 priority, UINT8);
6303 cmdline_parse_token_num_t cmd_pfc_set_portid =
6304         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6305                                 port_id, UINT16);
6306
6307 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6308         .f = cmd_priority_flow_ctrl_set_parsed,
6309         .data = NULL,
6310         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6311                 "<pause_time> <priority> <port_id>: "
6312                 "Configure the Ethernet priority flow control",
6313         .tokens = {
6314                 (void *)&cmd_pfc_set_set,
6315                 (void *)&cmd_pfc_set_flow_ctrl,
6316                 (void *)&cmd_pfc_set_rx,
6317                 (void *)&cmd_pfc_set_rx_mode,
6318                 (void *)&cmd_pfc_set_tx,
6319                 (void *)&cmd_pfc_set_tx_mode,
6320                 (void *)&cmd_pfc_set_high_water,
6321                 (void *)&cmd_pfc_set_low_water,
6322                 (void *)&cmd_pfc_set_pause_time,
6323                 (void *)&cmd_pfc_set_priority,
6324                 (void *)&cmd_pfc_set_portid,
6325                 NULL,
6326         },
6327 };
6328
6329 /* *** RESET CONFIGURATION *** */
6330 struct cmd_reset_result {
6331         cmdline_fixed_string_t reset;
6332         cmdline_fixed_string_t def;
6333 };
6334
6335 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6336                              struct cmdline *cl,
6337                              __attribute__((unused)) void *data)
6338 {
6339         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6340         set_def_fwd_config();
6341 }
6342
6343 cmdline_parse_token_string_t cmd_reset_set =
6344         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6345 cmdline_parse_token_string_t cmd_reset_def =
6346         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6347                                  "default");
6348
6349 cmdline_parse_inst_t cmd_reset = {
6350         .f = cmd_reset_parsed,
6351         .data = NULL,
6352         .help_str = "set default: Reset default forwarding configuration",
6353         .tokens = {
6354                 (void *)&cmd_reset_set,
6355                 (void *)&cmd_reset_def,
6356                 NULL,
6357         },
6358 };
6359
6360 /* *** START FORWARDING *** */
6361 struct cmd_start_result {
6362         cmdline_fixed_string_t start;
6363 };
6364
6365 cmdline_parse_token_string_t cmd_start_start =
6366         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6367
6368 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6369                              __attribute__((unused)) struct cmdline *cl,
6370                              __attribute__((unused)) void *data)
6371 {
6372         start_packet_forwarding(0);
6373 }
6374
6375 cmdline_parse_inst_t cmd_start = {
6376         .f = cmd_start_parsed,
6377         .data = NULL,
6378         .help_str = "start: Start packet forwarding",
6379         .tokens = {
6380                 (void *)&cmd_start_start,
6381                 NULL,
6382         },
6383 };
6384
6385 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6386 struct cmd_start_tx_first_result {
6387         cmdline_fixed_string_t start;
6388         cmdline_fixed_string_t tx_first;
6389 };
6390
6391 static void
6392 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6393                           __attribute__((unused)) struct cmdline *cl,
6394                           __attribute__((unused)) void *data)
6395 {
6396         start_packet_forwarding(1);
6397 }
6398
6399 cmdline_parse_token_string_t cmd_start_tx_first_start =
6400         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6401                                  "start");
6402 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6403         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6404                                  tx_first, "tx_first");
6405
6406 cmdline_parse_inst_t cmd_start_tx_first = {
6407         .f = cmd_start_tx_first_parsed,
6408         .data = NULL,
6409         .help_str = "start tx_first: Start packet forwarding, "
6410                 "after sending 1 burst of packets",
6411         .tokens = {
6412                 (void *)&cmd_start_tx_first_start,
6413                 (void *)&cmd_start_tx_first_tx_first,
6414                 NULL,
6415         },
6416 };
6417
6418 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6419 struct cmd_start_tx_first_n_result {
6420         cmdline_fixed_string_t start;
6421         cmdline_fixed_string_t tx_first;
6422         uint32_t tx_num;
6423 };
6424
6425 static void
6426 cmd_start_tx_first_n_parsed(void *parsed_result,
6427                           __attribute__((unused)) struct cmdline *cl,
6428                           __attribute__((unused)) void *data)
6429 {
6430         struct cmd_start_tx_first_n_result *res = parsed_result;
6431
6432         start_packet_forwarding(res->tx_num);
6433 }
6434
6435 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6436         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6437                         start, "start");
6438 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6439         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6440                         tx_first, "tx_first");
6441 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6442         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6443                         tx_num, UINT32);
6444
6445 cmdline_parse_inst_t cmd_start_tx_first_n = {
6446         .f = cmd_start_tx_first_n_parsed,
6447         .data = NULL,
6448         .help_str = "start tx_first <num>: "
6449                 "packet forwarding, after sending <num> bursts of packets",
6450         .tokens = {
6451                 (void *)&cmd_start_tx_first_n_start,
6452                 (void *)&cmd_start_tx_first_n_tx_first,
6453                 (void *)&cmd_start_tx_first_n_tx_num,
6454                 NULL,
6455         },
6456 };
6457
6458 /* *** SET LINK UP *** */
6459 struct cmd_set_link_up_result {
6460         cmdline_fixed_string_t set;
6461         cmdline_fixed_string_t link_up;
6462         cmdline_fixed_string_t port;
6463         portid_t port_id;
6464 };
6465
6466 cmdline_parse_token_string_t cmd_set_link_up_set =
6467         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6468 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6469         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6470                                 "link-up");
6471 cmdline_parse_token_string_t cmd_set_link_up_port =
6472         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6473 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6474         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6475
6476 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6477                              __attribute__((unused)) struct cmdline *cl,
6478                              __attribute__((unused)) void *data)
6479 {
6480         struct cmd_set_link_up_result *res = parsed_result;
6481         dev_set_link_up(res->port_id);
6482 }
6483
6484 cmdline_parse_inst_t cmd_set_link_up = {
6485         .f = cmd_set_link_up_parsed,
6486         .data = NULL,
6487         .help_str = "set link-up port <port id>",
6488         .tokens = {
6489                 (void *)&cmd_set_link_up_set,
6490                 (void *)&cmd_set_link_up_link_up,
6491                 (void *)&cmd_set_link_up_port,
6492                 (void *)&cmd_set_link_up_port_id,
6493                 NULL,
6494         },
6495 };
6496
6497 /* *** SET LINK DOWN *** */
6498 struct cmd_set_link_down_result {
6499         cmdline_fixed_string_t set;
6500         cmdline_fixed_string_t link_down;
6501         cmdline_fixed_string_t port;
6502         portid_t port_id;
6503 };
6504
6505 cmdline_parse_token_string_t cmd_set_link_down_set =
6506         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6507 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6508         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6509                                 "link-down");
6510 cmdline_parse_token_string_t cmd_set_link_down_port =
6511         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6512 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6513         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6514
6515 static void cmd_set_link_down_parsed(
6516                                 __attribute__((unused)) void *parsed_result,
6517                                 __attribute__((unused)) struct cmdline *cl,
6518                                 __attribute__((unused)) void *data)
6519 {
6520         struct cmd_set_link_down_result *res = parsed_result;
6521         dev_set_link_down(res->port_id);
6522 }
6523
6524 cmdline_parse_inst_t cmd_set_link_down = {
6525         .f = cmd_set_link_down_parsed,
6526         .data = NULL,
6527         .help_str = "set link-down port <port id>",
6528         .tokens = {
6529                 (void *)&cmd_set_link_down_set,
6530                 (void *)&cmd_set_link_down_link_down,
6531                 (void *)&cmd_set_link_down_port,
6532                 (void *)&cmd_set_link_down_port_id,
6533                 NULL,
6534         },
6535 };
6536
6537 /* *** SHOW CFG *** */
6538 struct cmd_showcfg_result {
6539         cmdline_fixed_string_t show;
6540         cmdline_fixed_string_t cfg;
6541         cmdline_fixed_string_t what;
6542 };
6543
6544 static void cmd_showcfg_parsed(void *parsed_result,
6545                                __attribute__((unused)) struct cmdline *cl,
6546                                __attribute__((unused)) void *data)
6547 {
6548         struct cmd_showcfg_result *res = parsed_result;
6549         if (!strcmp(res->what, "rxtx"))
6550                 rxtx_config_display();
6551         else if (!strcmp(res->what, "cores"))
6552                 fwd_lcores_config_display();
6553         else if (!strcmp(res->what, "fwd"))
6554                 pkt_fwd_config_display(&cur_fwd_config);
6555         else if (!strcmp(res->what, "txpkts"))
6556                 show_tx_pkt_segments();
6557 }
6558
6559 cmdline_parse_token_string_t cmd_showcfg_show =
6560         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6561 cmdline_parse_token_string_t cmd_showcfg_port =
6562         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6563 cmdline_parse_token_string_t cmd_showcfg_what =
6564         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6565                                  "rxtx#cores#fwd#txpkts");
6566
6567 cmdline_parse_inst_t cmd_showcfg = {
6568         .f = cmd_showcfg_parsed,
6569         .data = NULL,
6570         .help_str = "show config rxtx|cores|fwd|txpkts",
6571         .tokens = {
6572                 (void *)&cmd_showcfg_show,
6573                 (void *)&cmd_showcfg_port,
6574                 (void *)&cmd_showcfg_what,
6575                 NULL,
6576         },
6577 };
6578
6579 /* *** SHOW ALL PORT INFO *** */
6580 struct cmd_showportall_result {
6581         cmdline_fixed_string_t show;
6582         cmdline_fixed_string_t port;
6583         cmdline_fixed_string_t what;
6584         cmdline_fixed_string_t all;
6585 };
6586
6587 static void cmd_showportall_parsed(void *parsed_result,
6588                                 __attribute__((unused)) struct cmdline *cl,
6589                                 __attribute__((unused)) void *data)
6590 {
6591         portid_t i;
6592
6593         struct cmd_showportall_result *res = parsed_result;
6594         if (!strcmp(res->show, "clear")) {
6595                 if (!strcmp(res->what, "stats"))
6596                         RTE_ETH_FOREACH_DEV(i)
6597                                 nic_stats_clear(i);
6598                 else if (!strcmp(res->what, "xstats"))
6599                         RTE_ETH_FOREACH_DEV(i)
6600                                 nic_xstats_clear(i);
6601         } else if (!strcmp(res->what, "info"))
6602                 RTE_ETH_FOREACH_DEV(i)
6603                         port_infos_display(i);
6604         else if (!strcmp(res->what, "stats"))
6605                 RTE_ETH_FOREACH_DEV(i)
6606                         nic_stats_display(i);
6607         else if (!strcmp(res->what, "xstats"))
6608                 RTE_ETH_FOREACH_DEV(i)
6609                         nic_xstats_display(i);
6610         else if (!strcmp(res->what, "fdir"))
6611                 RTE_ETH_FOREACH_DEV(i)
6612                         fdir_get_infos(i);
6613         else if (!strcmp(res->what, "stat_qmap"))
6614                 RTE_ETH_FOREACH_DEV(i)
6615                         nic_stats_mapping_display(i);
6616         else if (!strcmp(res->what, "dcb_tc"))
6617                 RTE_ETH_FOREACH_DEV(i)
6618                         port_dcb_info_display(i);
6619         else if (!strcmp(res->what, "cap"))
6620                 RTE_ETH_FOREACH_DEV(i)
6621                         port_offload_cap_display(i);
6622 }
6623
6624 cmdline_parse_token_string_t cmd_showportall_show =
6625         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6626                                  "show#clear");
6627 cmdline_parse_token_string_t cmd_showportall_port =
6628         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6629 cmdline_parse_token_string_t cmd_showportall_what =
6630         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6631                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6632 cmdline_parse_token_string_t cmd_showportall_all =
6633         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6634 cmdline_parse_inst_t cmd_showportall = {
6635         .f = cmd_showportall_parsed,
6636         .data = NULL,
6637         .help_str = "show|clear port "
6638                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6639         .tokens = {
6640                 (void *)&cmd_showportall_show,
6641                 (void *)&cmd_showportall_port,
6642                 (void *)&cmd_showportall_what,
6643                 (void *)&cmd_showportall_all,
6644                 NULL,
6645         },
6646 };
6647
6648 /* *** SHOW PORT INFO *** */
6649 struct cmd_showport_result {
6650         cmdline_fixed_string_t show;
6651         cmdline_fixed_string_t port;
6652         cmdline_fixed_string_t what;
6653         uint16_t portnum;
6654 };
6655
6656 static void cmd_showport_parsed(void *parsed_result,
6657                                 __attribute__((unused)) struct cmdline *cl,
6658                                 __attribute__((unused)) void *data)
6659 {
6660         struct cmd_showport_result *res = parsed_result;
6661         if (!strcmp(res->show, "clear")) {
6662                 if (!strcmp(res->what, "stats"))
6663                         nic_stats_clear(res->portnum);
6664                 else if (!strcmp(res->what, "xstats"))
6665                         nic_xstats_clear(res->portnum);
6666         } else if (!strcmp(res->what, "info"))
6667                 port_infos_display(res->portnum);
6668         else if (!strcmp(res->what, "stats"))
6669                 nic_stats_display(res->portnum);
6670         else if (!strcmp(res->what, "xstats"))
6671                 nic_xstats_display(res->portnum);
6672         else if (!strcmp(res->what, "fdir"))
6673                  fdir_get_infos(res->portnum);
6674         else if (!strcmp(res->what, "stat_qmap"))
6675                 nic_stats_mapping_display(res->portnum);
6676         else if (!strcmp(res->what, "dcb_tc"))
6677                 port_dcb_info_display(res->portnum);
6678         else if (!strcmp(res->what, "cap"))
6679                 port_offload_cap_display(res->portnum);
6680 }
6681
6682 cmdline_parse_token_string_t cmd_showport_show =
6683         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6684                                  "show#clear");
6685 cmdline_parse_token_string_t cmd_showport_port =
6686         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6687 cmdline_parse_token_string_t cmd_showport_what =
6688         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6689                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6690 cmdline_parse_token_num_t cmd_showport_portnum =
6691         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6692
6693 cmdline_parse_inst_t cmd_showport = {
6694         .f = cmd_showport_parsed,
6695         .data = NULL,
6696         .help_str = "show|clear port "
6697                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6698                 "<port_id>",
6699         .tokens = {
6700                 (void *)&cmd_showport_show,
6701                 (void *)&cmd_showport_port,
6702                 (void *)&cmd_showport_what,
6703                 (void *)&cmd_showport_portnum,
6704                 NULL,
6705         },
6706 };
6707
6708 /* *** SHOW QUEUE INFO *** */
6709 struct cmd_showqueue_result {
6710         cmdline_fixed_string_t show;
6711         cmdline_fixed_string_t type;
6712         cmdline_fixed_string_t what;
6713         uint16_t portnum;
6714         uint16_t queuenum;
6715 };
6716
6717 static void
6718 cmd_showqueue_parsed(void *parsed_result,
6719         __attribute__((unused)) struct cmdline *cl,
6720         __attribute__((unused)) void *data)
6721 {
6722         struct cmd_showqueue_result *res = parsed_result;
6723
6724         if (!strcmp(res->type, "rxq"))
6725                 rx_queue_infos_display(res->portnum, res->queuenum);
6726         else if (!strcmp(res->type, "txq"))
6727                 tx_queue_infos_display(res->portnum, res->queuenum);
6728 }
6729
6730 cmdline_parse_token_string_t cmd_showqueue_show =
6731         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6732 cmdline_parse_token_string_t cmd_showqueue_type =
6733         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6734 cmdline_parse_token_string_t cmd_showqueue_what =
6735         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6736 cmdline_parse_token_num_t cmd_showqueue_portnum =
6737         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6738 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6739         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6740
6741 cmdline_parse_inst_t cmd_showqueue = {
6742         .f = cmd_showqueue_parsed,
6743         .data = NULL,
6744         .help_str = "show rxq|txq info <port_id> <queue_id>",
6745         .tokens = {
6746                 (void *)&cmd_showqueue_show,
6747                 (void *)&cmd_showqueue_type,
6748                 (void *)&cmd_showqueue_what,
6749                 (void *)&cmd_showqueue_portnum,
6750                 (void *)&cmd_showqueue_queuenum,
6751                 NULL,
6752         },
6753 };
6754
6755 /* *** READ PORT REGISTER *** */
6756 struct cmd_read_reg_result {
6757         cmdline_fixed_string_t read;
6758         cmdline_fixed_string_t reg;
6759         portid_t port_id;
6760         uint32_t reg_off;
6761 };
6762
6763 static void
6764 cmd_read_reg_parsed(void *parsed_result,
6765                     __attribute__((unused)) struct cmdline *cl,
6766                     __attribute__((unused)) void *data)
6767 {
6768         struct cmd_read_reg_result *res = parsed_result;
6769         port_reg_display(res->port_id, res->reg_off);
6770 }
6771
6772 cmdline_parse_token_string_t cmd_read_reg_read =
6773         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6774 cmdline_parse_token_string_t cmd_read_reg_reg =
6775         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6776 cmdline_parse_token_num_t cmd_read_reg_port_id =
6777         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6778 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6779         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6780
6781 cmdline_parse_inst_t cmd_read_reg = {
6782         .f = cmd_read_reg_parsed,
6783         .data = NULL,
6784         .help_str = "read reg <port_id> <reg_off>",
6785         .tokens = {
6786                 (void *)&cmd_read_reg_read,
6787                 (void *)&cmd_read_reg_reg,
6788                 (void *)&cmd_read_reg_port_id,
6789                 (void *)&cmd_read_reg_reg_off,
6790                 NULL,
6791         },
6792 };
6793
6794 /* *** READ PORT REGISTER BIT FIELD *** */
6795 struct cmd_read_reg_bit_field_result {
6796         cmdline_fixed_string_t read;
6797         cmdline_fixed_string_t regfield;
6798         portid_t port_id;
6799         uint32_t reg_off;
6800         uint8_t bit1_pos;
6801         uint8_t bit2_pos;
6802 };
6803
6804 static void
6805 cmd_read_reg_bit_field_parsed(void *parsed_result,
6806                               __attribute__((unused)) struct cmdline *cl,
6807                               __attribute__((unused)) void *data)
6808 {
6809         struct cmd_read_reg_bit_field_result *res = parsed_result;
6810         port_reg_bit_field_display(res->port_id, res->reg_off,
6811                                    res->bit1_pos, res->bit2_pos);
6812 }
6813
6814 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6815         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6816                                  "read");
6817 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6818         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6819                                  regfield, "regfield");
6820 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6821         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6822                               UINT16);
6823 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6824         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6825                               UINT32);
6826 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6827         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6828                               UINT8);
6829 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6830         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6831                               UINT8);
6832
6833 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6834         .f = cmd_read_reg_bit_field_parsed,
6835         .data = NULL,
6836         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6837         "Read register bit field between bit_x and bit_y included",
6838         .tokens = {
6839                 (void *)&cmd_read_reg_bit_field_read,
6840                 (void *)&cmd_read_reg_bit_field_regfield,
6841                 (void *)&cmd_read_reg_bit_field_port_id,
6842                 (void *)&cmd_read_reg_bit_field_reg_off,
6843                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6844                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6845                 NULL,
6846         },
6847 };
6848
6849 /* *** READ PORT REGISTER BIT *** */
6850 struct cmd_read_reg_bit_result {
6851         cmdline_fixed_string_t read;
6852         cmdline_fixed_string_t regbit;
6853         portid_t port_id;
6854         uint32_t reg_off;
6855         uint8_t bit_pos;
6856 };
6857
6858 static void
6859 cmd_read_reg_bit_parsed(void *parsed_result,
6860                         __attribute__((unused)) struct cmdline *cl,
6861                         __attribute__((unused)) void *data)
6862 {
6863         struct cmd_read_reg_bit_result *res = parsed_result;
6864         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6865 }
6866
6867 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6868         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6869 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6870         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6871                                  regbit, "regbit");
6872 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6873         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6874 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6875         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6876 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6877         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6878
6879 cmdline_parse_inst_t cmd_read_reg_bit = {
6880         .f = cmd_read_reg_bit_parsed,
6881         .data = NULL,
6882         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6883         .tokens = {
6884                 (void *)&cmd_read_reg_bit_read,
6885                 (void *)&cmd_read_reg_bit_regbit,
6886                 (void *)&cmd_read_reg_bit_port_id,
6887                 (void *)&cmd_read_reg_bit_reg_off,
6888                 (void *)&cmd_read_reg_bit_bit_pos,
6889                 NULL,
6890         },
6891 };
6892
6893 /* *** WRITE PORT REGISTER *** */
6894 struct cmd_write_reg_result {
6895         cmdline_fixed_string_t write;
6896         cmdline_fixed_string_t reg;
6897         portid_t port_id;
6898         uint32_t reg_off;
6899         uint32_t value;
6900 };
6901
6902 static void
6903 cmd_write_reg_parsed(void *parsed_result,
6904                      __attribute__((unused)) struct cmdline *cl,
6905                      __attribute__((unused)) void *data)
6906 {
6907         struct cmd_write_reg_result *res = parsed_result;
6908         port_reg_set(res->port_id, res->reg_off, res->value);
6909 }
6910
6911 cmdline_parse_token_string_t cmd_write_reg_write =
6912         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6913 cmdline_parse_token_string_t cmd_write_reg_reg =
6914         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6915 cmdline_parse_token_num_t cmd_write_reg_port_id =
6916         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6917 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6918         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6919 cmdline_parse_token_num_t cmd_write_reg_value =
6920         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6921
6922 cmdline_parse_inst_t cmd_write_reg = {
6923         .f = cmd_write_reg_parsed,
6924         .data = NULL,
6925         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6926         .tokens = {
6927                 (void *)&cmd_write_reg_write,
6928                 (void *)&cmd_write_reg_reg,
6929                 (void *)&cmd_write_reg_port_id,
6930                 (void *)&cmd_write_reg_reg_off,
6931                 (void *)&cmd_write_reg_value,
6932                 NULL,
6933         },
6934 };
6935
6936 /* *** WRITE PORT REGISTER BIT FIELD *** */
6937 struct cmd_write_reg_bit_field_result {
6938         cmdline_fixed_string_t write;
6939         cmdline_fixed_string_t regfield;
6940         portid_t port_id;
6941         uint32_t reg_off;
6942         uint8_t bit1_pos;
6943         uint8_t bit2_pos;
6944         uint32_t value;
6945 };
6946
6947 static void
6948 cmd_write_reg_bit_field_parsed(void *parsed_result,
6949                                __attribute__((unused)) struct cmdline *cl,
6950                                __attribute__((unused)) void *data)
6951 {
6952         struct cmd_write_reg_bit_field_result *res = parsed_result;
6953         port_reg_bit_field_set(res->port_id, res->reg_off,
6954                           res->bit1_pos, res->bit2_pos, res->value);
6955 }
6956
6957 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6958         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6959                                  "write");
6960 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6961         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6962                                  regfield, "regfield");
6963 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6964         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6965                               UINT16);
6966 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6967         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6968                               UINT32);
6969 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6970         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6971                               UINT8);
6972 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6973         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6974                               UINT8);
6975 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6976         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6977                               UINT32);
6978
6979 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6980         .f = cmd_write_reg_bit_field_parsed,
6981         .data = NULL,
6982         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6983                 "<reg_value>: "
6984                 "Set register bit field between bit_x and bit_y included",
6985         .tokens = {
6986                 (void *)&cmd_write_reg_bit_field_write,
6987                 (void *)&cmd_write_reg_bit_field_regfield,
6988                 (void *)&cmd_write_reg_bit_field_port_id,
6989                 (void *)&cmd_write_reg_bit_field_reg_off,
6990                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6991                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6992                 (void *)&cmd_write_reg_bit_field_value,
6993                 NULL,
6994         },
6995 };
6996
6997 /* *** WRITE PORT REGISTER BIT *** */
6998 struct cmd_write_reg_bit_result {
6999         cmdline_fixed_string_t write;
7000         cmdline_fixed_string_t regbit;
7001         portid_t port_id;
7002         uint32_t reg_off;
7003         uint8_t bit_pos;
7004         uint8_t value;
7005 };
7006
7007 static void
7008 cmd_write_reg_bit_parsed(void *parsed_result,
7009                          __attribute__((unused)) struct cmdline *cl,
7010                          __attribute__((unused)) void *data)
7011 {
7012         struct cmd_write_reg_bit_result *res = parsed_result;
7013         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7014 }
7015
7016 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7017         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7018                                  "write");
7019 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7020         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7021                                  regbit, "regbit");
7022 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7023         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7024 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7025         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7026 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7027         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7028 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7029         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7030
7031 cmdline_parse_inst_t cmd_write_reg_bit = {
7032         .f = cmd_write_reg_bit_parsed,
7033         .data = NULL,
7034         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7035                 "0 <= bit_x <= 31",
7036         .tokens = {
7037                 (void *)&cmd_write_reg_bit_write,
7038                 (void *)&cmd_write_reg_bit_regbit,
7039                 (void *)&cmd_write_reg_bit_port_id,
7040                 (void *)&cmd_write_reg_bit_reg_off,
7041                 (void *)&cmd_write_reg_bit_bit_pos,
7042                 (void *)&cmd_write_reg_bit_value,
7043                 NULL,
7044         },
7045 };
7046
7047 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7048 struct cmd_read_rxd_txd_result {
7049         cmdline_fixed_string_t read;
7050         cmdline_fixed_string_t rxd_txd;
7051         portid_t port_id;
7052         uint16_t queue_id;
7053         uint16_t desc_id;
7054 };
7055
7056 static void
7057 cmd_read_rxd_txd_parsed(void *parsed_result,
7058                         __attribute__((unused)) struct cmdline *cl,
7059                         __attribute__((unused)) void *data)
7060 {
7061         struct cmd_read_rxd_txd_result *res = parsed_result;
7062
7063         if (!strcmp(res->rxd_txd, "rxd"))
7064                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7065         else if (!strcmp(res->rxd_txd, "txd"))
7066                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7067 }
7068
7069 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7070         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7071 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7072         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7073                                  "rxd#txd");
7074 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7075         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7076 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7077         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7078 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7079         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7080
7081 cmdline_parse_inst_t cmd_read_rxd_txd = {
7082         .f = cmd_read_rxd_txd_parsed,
7083         .data = NULL,
7084         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7085         .tokens = {
7086                 (void *)&cmd_read_rxd_txd_read,
7087                 (void *)&cmd_read_rxd_txd_rxd_txd,
7088                 (void *)&cmd_read_rxd_txd_port_id,
7089                 (void *)&cmd_read_rxd_txd_queue_id,
7090                 (void *)&cmd_read_rxd_txd_desc_id,
7091                 NULL,
7092         },
7093 };
7094
7095 /* *** QUIT *** */
7096 struct cmd_quit_result {
7097         cmdline_fixed_string_t quit;
7098 };
7099
7100 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7101                             struct cmdline *cl,
7102                             __attribute__((unused)) void *data)
7103 {
7104         pmd_test_exit();
7105         cmdline_quit(cl);
7106 }
7107
7108 cmdline_parse_token_string_t cmd_quit_quit =
7109         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7110
7111 cmdline_parse_inst_t cmd_quit = {
7112         .f = cmd_quit_parsed,
7113         .data = NULL,
7114         .help_str = "quit: Exit application",
7115         .tokens = {
7116                 (void *)&cmd_quit_quit,
7117                 NULL,
7118         },
7119 };
7120
7121 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7122 struct cmd_mac_addr_result {
7123         cmdline_fixed_string_t mac_addr_cmd;
7124         cmdline_fixed_string_t what;
7125         uint16_t port_num;
7126         struct ether_addr address;
7127 };
7128
7129 static void cmd_mac_addr_parsed(void *parsed_result,
7130                 __attribute__((unused)) struct cmdline *cl,
7131                 __attribute__((unused)) void *data)
7132 {
7133         struct cmd_mac_addr_result *res = parsed_result;
7134         int ret;
7135
7136         if (strcmp(res->what, "add") == 0)
7137                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7138         else if (strcmp(res->what, "set") == 0)
7139                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7140                                                        &res->address);
7141         else
7142                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7143
7144         /* check the return value and print it if is < 0 */
7145         if(ret < 0)
7146                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7147
7148 }
7149
7150 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7151         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7152                                 "mac_addr");
7153 cmdline_parse_token_string_t cmd_mac_addr_what =
7154         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7155                                 "add#remove#set");
7156 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7157                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7158                                         UINT16);
7159 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7160                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7161
7162 cmdline_parse_inst_t cmd_mac_addr = {
7163         .f = cmd_mac_addr_parsed,
7164         .data = (void *)0,
7165         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7166                         "Add/Remove/Set MAC address on port_id",
7167         .tokens = {
7168                 (void *)&cmd_mac_addr_cmd,
7169                 (void *)&cmd_mac_addr_what,
7170                 (void *)&cmd_mac_addr_portnum,
7171                 (void *)&cmd_mac_addr_addr,
7172                 NULL,
7173         },
7174 };
7175
7176
7177 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7178 struct cmd_set_qmap_result {
7179         cmdline_fixed_string_t set;
7180         cmdline_fixed_string_t qmap;
7181         cmdline_fixed_string_t what;
7182         portid_t port_id;
7183         uint16_t queue_id;
7184         uint8_t map_value;
7185 };
7186
7187 static void
7188 cmd_set_qmap_parsed(void *parsed_result,
7189                        __attribute__((unused)) struct cmdline *cl,
7190                        __attribute__((unused)) void *data)
7191 {
7192         struct cmd_set_qmap_result *res = parsed_result;
7193         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7194
7195         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7196 }
7197
7198 cmdline_parse_token_string_t cmd_setqmap_set =
7199         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7200                                  set, "set");
7201 cmdline_parse_token_string_t cmd_setqmap_qmap =
7202         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7203                                  qmap, "stat_qmap");
7204 cmdline_parse_token_string_t cmd_setqmap_what =
7205         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7206                                  what, "tx#rx");
7207 cmdline_parse_token_num_t cmd_setqmap_portid =
7208         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7209                               port_id, UINT16);
7210 cmdline_parse_token_num_t cmd_setqmap_queueid =
7211         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7212                               queue_id, UINT16);
7213 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7214         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7215                               map_value, UINT8);
7216
7217 cmdline_parse_inst_t cmd_set_qmap = {
7218         .f = cmd_set_qmap_parsed,
7219         .data = NULL,
7220         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7221                 "Set statistics mapping value on tx|rx queue_id of port_id",
7222         .tokens = {
7223                 (void *)&cmd_setqmap_set,
7224                 (void *)&cmd_setqmap_qmap,
7225                 (void *)&cmd_setqmap_what,
7226                 (void *)&cmd_setqmap_portid,
7227                 (void *)&cmd_setqmap_queueid,
7228                 (void *)&cmd_setqmap_mapvalue,
7229                 NULL,
7230         },
7231 };
7232
7233 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7234 struct cmd_set_xstats_hide_zero_result {
7235         cmdline_fixed_string_t keyword;
7236         cmdline_fixed_string_t name;
7237         cmdline_fixed_string_t on_off;
7238 };
7239
7240 static void
7241 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7242                         __attribute__((unused)) struct cmdline *cl,
7243                         __attribute__((unused)) void *data)
7244 {
7245         struct cmd_set_xstats_hide_zero_result *res;
7246         uint16_t on_off = 0;
7247
7248         res = parsed_result;
7249         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7250         set_xstats_hide_zero(on_off);
7251 }
7252
7253 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7254         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7255                                  keyword, "set");
7256 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7257         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7258                                  name, "xstats-hide-zero");
7259 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7260         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7261                                  on_off, "on#off");
7262
7263 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7264         .f = cmd_set_xstats_hide_zero_parsed,
7265         .data = NULL,
7266         .help_str = "set xstats-hide-zero on|off",
7267         .tokens = {
7268                 (void *)&cmd_set_xstats_hide_zero_keyword,
7269                 (void *)&cmd_set_xstats_hide_zero_name,
7270                 (void *)&cmd_set_xstats_hide_zero_on_off,
7271                 NULL,
7272         },
7273 };
7274
7275 /* *** CONFIGURE UNICAST HASH TABLE *** */
7276 struct cmd_set_uc_hash_table {
7277         cmdline_fixed_string_t set;
7278         cmdline_fixed_string_t port;
7279         portid_t port_id;
7280         cmdline_fixed_string_t what;
7281         struct ether_addr address;
7282         cmdline_fixed_string_t mode;
7283 };
7284
7285 static void
7286 cmd_set_uc_hash_parsed(void *parsed_result,
7287                        __attribute__((unused)) struct cmdline *cl,
7288                        __attribute__((unused)) void *data)
7289 {
7290         int ret=0;
7291         struct cmd_set_uc_hash_table *res = parsed_result;
7292
7293         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7294
7295         if (strcmp(res->what, "uta") == 0)
7296                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7297                                                 &res->address,(uint8_t)is_on);
7298         if (ret < 0)
7299                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7300
7301 }
7302
7303 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7304         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7305                                  set, "set");
7306 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7307         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7308                                  port, "port");
7309 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7310         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7311                               port_id, UINT16);
7312 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7313         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7314                                  what, "uta");
7315 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7316         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7317                                 address);
7318 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7319         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7320                                  mode, "on#off");
7321
7322 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7323         .f = cmd_set_uc_hash_parsed,
7324         .data = NULL,
7325         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7326         .tokens = {
7327                 (void *)&cmd_set_uc_hash_set,
7328                 (void *)&cmd_set_uc_hash_port,
7329                 (void *)&cmd_set_uc_hash_portid,
7330                 (void *)&cmd_set_uc_hash_what,
7331                 (void *)&cmd_set_uc_hash_mac,
7332                 (void *)&cmd_set_uc_hash_mode,
7333                 NULL,
7334         },
7335 };
7336
7337 struct cmd_set_uc_all_hash_table {
7338         cmdline_fixed_string_t set;
7339         cmdline_fixed_string_t port;
7340         portid_t port_id;
7341         cmdline_fixed_string_t what;
7342         cmdline_fixed_string_t value;
7343         cmdline_fixed_string_t mode;
7344 };
7345
7346 static void
7347 cmd_set_uc_all_hash_parsed(void *parsed_result,
7348                        __attribute__((unused)) struct cmdline *cl,
7349                        __attribute__((unused)) void *data)
7350 {
7351         int ret=0;
7352         struct cmd_set_uc_all_hash_table *res = parsed_result;
7353
7354         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7355
7356         if ((strcmp(res->what, "uta") == 0) &&
7357                 (strcmp(res->value, "all") == 0))
7358                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7359         if (ret < 0)
7360                 printf("bad unicast hash table parameter,"
7361                         "return code = %d \n", ret);
7362 }
7363
7364 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7365         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7366                                  set, "set");
7367 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7368         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7369                                  port, "port");
7370 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7371         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7372                               port_id, UINT16);
7373 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7374         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7375                                  what, "uta");
7376 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7377         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7378                                 value,"all");
7379 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7380         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7381                                  mode, "on#off");
7382
7383 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7384         .f = cmd_set_uc_all_hash_parsed,
7385         .data = NULL,
7386         .help_str = "set port <port_id> uta all on|off",
7387         .tokens = {
7388                 (void *)&cmd_set_uc_all_hash_set,
7389                 (void *)&cmd_set_uc_all_hash_port,
7390                 (void *)&cmd_set_uc_all_hash_portid,
7391                 (void *)&cmd_set_uc_all_hash_what,
7392                 (void *)&cmd_set_uc_all_hash_value,
7393                 (void *)&cmd_set_uc_all_hash_mode,
7394                 NULL,
7395         },
7396 };
7397
7398 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7399 struct cmd_set_vf_macvlan_filter {
7400         cmdline_fixed_string_t set;
7401         cmdline_fixed_string_t port;
7402         portid_t port_id;
7403         cmdline_fixed_string_t vf;
7404         uint8_t vf_id;
7405         struct ether_addr address;
7406         cmdline_fixed_string_t filter_type;
7407         cmdline_fixed_string_t mode;
7408 };
7409
7410 static void
7411 cmd_set_vf_macvlan_parsed(void *parsed_result,
7412                        __attribute__((unused)) struct cmdline *cl,
7413                        __attribute__((unused)) void *data)
7414 {
7415         int is_on, ret = 0;
7416         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7417         struct rte_eth_mac_filter filter;
7418
7419         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7420
7421         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7422
7423         /* set VF MAC filter */
7424         filter.is_vf = 1;
7425
7426         /* set VF ID */
7427         filter.dst_id = res->vf_id;
7428
7429         if (!strcmp(res->filter_type, "exact-mac"))
7430                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7431         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7432                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7433         else if (!strcmp(res->filter_type, "hashmac"))
7434                 filter.filter_type = RTE_MAC_HASH_MATCH;
7435         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7436                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7437
7438         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7439
7440         if (is_on)
7441                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7442                                         RTE_ETH_FILTER_MACVLAN,
7443                                         RTE_ETH_FILTER_ADD,
7444                                          &filter);
7445         else
7446                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7447                                         RTE_ETH_FILTER_MACVLAN,
7448                                         RTE_ETH_FILTER_DELETE,
7449                                         &filter);
7450
7451         if (ret < 0)
7452                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7453
7454 }
7455
7456 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7457         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7458                                  set, "set");
7459 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7460         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7461                                  port, "port");
7462 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7463         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7464                               port_id, UINT16);
7465 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7466         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7467                                  vf, "vf");
7468 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7469         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7470                                 vf_id, UINT8);
7471 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7472         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7473                                 address);
7474 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7475         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7476                                 filter_type, "exact-mac#exact-mac-vlan"
7477                                 "#hashmac#hashmac-vlan");
7478 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7479         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7480                                  mode, "on#off");
7481
7482 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7483         .f = cmd_set_vf_macvlan_parsed,
7484         .data = NULL,
7485         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7486                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7487                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7488                 "hash match rule: hash match of MAC and exact match of VLAN",
7489         .tokens = {
7490                 (void *)&cmd_set_vf_macvlan_set,
7491                 (void *)&cmd_set_vf_macvlan_port,
7492                 (void *)&cmd_set_vf_macvlan_portid,
7493                 (void *)&cmd_set_vf_macvlan_vf,
7494                 (void *)&cmd_set_vf_macvlan_vf_id,
7495                 (void *)&cmd_set_vf_macvlan_mac,
7496                 (void *)&cmd_set_vf_macvlan_filter_type,
7497                 (void *)&cmd_set_vf_macvlan_mode,
7498                 NULL,
7499         },
7500 };
7501
7502 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7503 struct cmd_set_vf_traffic {
7504         cmdline_fixed_string_t set;
7505         cmdline_fixed_string_t port;
7506         portid_t port_id;
7507         cmdline_fixed_string_t vf;
7508         uint8_t vf_id;
7509         cmdline_fixed_string_t what;
7510         cmdline_fixed_string_t mode;
7511 };
7512
7513 static void
7514 cmd_set_vf_traffic_parsed(void *parsed_result,
7515                        __attribute__((unused)) struct cmdline *cl,
7516                        __attribute__((unused)) void *data)
7517 {
7518         struct cmd_set_vf_traffic *res = parsed_result;
7519         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7520         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7521
7522         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7523 }
7524
7525 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7526         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7527                                  set, "set");
7528 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7529         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7530                                  port, "port");
7531 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7532         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7533                               port_id, UINT16);
7534 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7535         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7536                                  vf, "vf");
7537 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7538         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7539                               vf_id, UINT8);
7540 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7541         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7542                                  what, "tx#rx");
7543 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7544         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7545                                  mode, "on#off");
7546
7547 cmdline_parse_inst_t cmd_set_vf_traffic = {
7548         .f = cmd_set_vf_traffic_parsed,
7549         .data = NULL,
7550         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7551         .tokens = {
7552                 (void *)&cmd_setvf_traffic_set,
7553                 (void *)&cmd_setvf_traffic_port,
7554                 (void *)&cmd_setvf_traffic_portid,
7555                 (void *)&cmd_setvf_traffic_vf,
7556                 (void *)&cmd_setvf_traffic_vfid,
7557                 (void *)&cmd_setvf_traffic_what,
7558                 (void *)&cmd_setvf_traffic_mode,
7559                 NULL,
7560         },
7561 };
7562
7563 /* *** CONFIGURE VF RECEIVE MODE *** */
7564 struct cmd_set_vf_rxmode {
7565         cmdline_fixed_string_t set;
7566         cmdline_fixed_string_t port;
7567         portid_t port_id;
7568         cmdline_fixed_string_t vf;
7569         uint8_t vf_id;
7570         cmdline_fixed_string_t what;
7571         cmdline_fixed_string_t mode;
7572         cmdline_fixed_string_t on;
7573 };
7574
7575 static void
7576 cmd_set_vf_rxmode_parsed(void *parsed_result,
7577                        __attribute__((unused)) struct cmdline *cl,
7578                        __attribute__((unused)) void *data)
7579 {
7580         int ret = -ENOTSUP;
7581         uint16_t rx_mode = 0;
7582         struct cmd_set_vf_rxmode *res = parsed_result;
7583
7584         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7585         if (!strcmp(res->what,"rxmode")) {
7586                 if (!strcmp(res->mode, "AUPE"))
7587                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7588                 else if (!strcmp(res->mode, "ROPE"))
7589                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7590                 else if (!strcmp(res->mode, "BAM"))
7591                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7592                 else if (!strncmp(res->mode, "MPE",3))
7593                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7594         }
7595
7596         RTE_SET_USED(is_on);
7597
7598 #ifdef RTE_LIBRTE_IXGBE_PMD
7599         if (ret == -ENOTSUP)
7600                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7601                                                   rx_mode, (uint8_t)is_on);
7602 #endif
7603 #ifdef RTE_LIBRTE_BNXT_PMD
7604         if (ret == -ENOTSUP)
7605                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7606                                                  rx_mode, (uint8_t)is_on);
7607 #endif
7608         if (ret < 0)
7609                 printf("bad VF receive mode parameter, return code = %d \n",
7610                 ret);
7611 }
7612
7613 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7614         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7615                                  set, "set");
7616 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7617         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7618                                  port, "port");
7619 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7620         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7621                               port_id, UINT16);
7622 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7623         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7624                                  vf, "vf");
7625 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7626         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7627                               vf_id, UINT8);
7628 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7629         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7630                                  what, "rxmode");
7631 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7632         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7633                                  mode, "AUPE#ROPE#BAM#MPE");
7634 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7635         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7636                                  on, "on#off");
7637
7638 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7639         .f = cmd_set_vf_rxmode_parsed,
7640         .data = NULL,
7641         .help_str = "set port <port_id> vf <vf_id> rxmode "
7642                 "AUPE|ROPE|BAM|MPE on|off",
7643         .tokens = {
7644                 (void *)&cmd_set_vf_rxmode_set,
7645                 (void *)&cmd_set_vf_rxmode_port,
7646                 (void *)&cmd_set_vf_rxmode_portid,
7647                 (void *)&cmd_set_vf_rxmode_vf,
7648                 (void *)&cmd_set_vf_rxmode_vfid,
7649                 (void *)&cmd_set_vf_rxmode_what,
7650                 (void *)&cmd_set_vf_rxmode_mode,
7651                 (void *)&cmd_set_vf_rxmode_on,
7652                 NULL,
7653         },
7654 };
7655
7656 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7657 struct cmd_vf_mac_addr_result {
7658         cmdline_fixed_string_t mac_addr_cmd;
7659         cmdline_fixed_string_t what;
7660         cmdline_fixed_string_t port;
7661         uint16_t port_num;
7662         cmdline_fixed_string_t vf;
7663         uint8_t vf_num;
7664         struct ether_addr address;
7665 };
7666
7667 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7668                 __attribute__((unused)) struct cmdline *cl,
7669                 __attribute__((unused)) void *data)
7670 {
7671         struct cmd_vf_mac_addr_result *res = parsed_result;
7672         int ret = -ENOTSUP;
7673
7674         if (strcmp(res->what, "add") != 0)
7675                 return;
7676
7677 #ifdef RTE_LIBRTE_I40E_PMD
7678         if (ret == -ENOTSUP)
7679                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7680                                                    &res->address);
7681 #endif
7682 #ifdef RTE_LIBRTE_BNXT_PMD
7683         if (ret == -ENOTSUP)
7684                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7685                                                 res->vf_num);
7686 #endif
7687
7688         if(ret < 0)
7689                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7690
7691 }
7692
7693 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7694         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7695                                 mac_addr_cmd,"mac_addr");
7696 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7697         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7698                                 what,"add");
7699 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7700         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7701                                 port,"port");
7702 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7703         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7704                                 port_num, UINT16);
7705 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7706         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7707                                 vf,"vf");
7708 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7709         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7710                                 vf_num, UINT8);
7711 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7712         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7713                                 address);
7714
7715 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7716         .f = cmd_vf_mac_addr_parsed,
7717         .data = (void *)0,
7718         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7719                 "Add MAC address filtering for a VF on port_id",
7720         .tokens = {
7721                 (void *)&cmd_vf_mac_addr_cmd,
7722                 (void *)&cmd_vf_mac_addr_what,
7723                 (void *)&cmd_vf_mac_addr_port,
7724                 (void *)&cmd_vf_mac_addr_portnum,
7725                 (void *)&cmd_vf_mac_addr_vf,
7726                 (void *)&cmd_vf_mac_addr_vfnum,
7727                 (void *)&cmd_vf_mac_addr_addr,
7728                 NULL,
7729         },
7730 };
7731
7732 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7733 struct cmd_vf_rx_vlan_filter {
7734         cmdline_fixed_string_t rx_vlan;
7735         cmdline_fixed_string_t what;
7736         uint16_t vlan_id;
7737         cmdline_fixed_string_t port;
7738         portid_t port_id;
7739         cmdline_fixed_string_t vf;
7740         uint64_t vf_mask;
7741 };
7742
7743 static void
7744 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7745                           __attribute__((unused)) struct cmdline *cl,
7746                           __attribute__((unused)) void *data)
7747 {
7748         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7749         int ret = -ENOTSUP;
7750
7751         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7752
7753 #ifdef RTE_LIBRTE_IXGBE_PMD
7754         if (ret == -ENOTSUP)
7755                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7756                                 res->vlan_id, res->vf_mask, is_add);
7757 #endif
7758 #ifdef RTE_LIBRTE_I40E_PMD
7759         if (ret == -ENOTSUP)
7760                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7761                                 res->vlan_id, res->vf_mask, is_add);
7762 #endif
7763 #ifdef RTE_LIBRTE_BNXT_PMD
7764         if (ret == -ENOTSUP)
7765                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7766                                 res->vlan_id, res->vf_mask, is_add);
7767 #endif
7768
7769         switch (ret) {
7770         case 0:
7771                 break;
7772         case -EINVAL:
7773                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7774                                 res->vlan_id, res->vf_mask);
7775                 break;
7776         case -ENODEV:
7777                 printf("invalid port_id %d\n", res->port_id);
7778                 break;
7779         case -ENOTSUP:
7780                 printf("function not implemented or supported\n");
7781                 break;
7782         default:
7783                 printf("programming error: (%s)\n", strerror(-ret));
7784         }
7785 }
7786
7787 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7788         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7789                                  rx_vlan, "rx_vlan");
7790 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7791         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7792                                  what, "add#rm");
7793 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7794         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7795                               vlan_id, UINT16);
7796 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7797         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7798                                  port, "port");
7799 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7800         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7801                               port_id, UINT16);
7802 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7803         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7804                                  vf, "vf");
7805 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7806         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7807                               vf_mask, UINT64);
7808
7809 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7810         .f = cmd_vf_rx_vlan_filter_parsed,
7811         .data = NULL,
7812         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7813                 "(vf_mask = hexadecimal VF mask)",
7814         .tokens = {
7815                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7816                 (void *)&cmd_vf_rx_vlan_filter_what,
7817                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7818                 (void *)&cmd_vf_rx_vlan_filter_port,
7819                 (void *)&cmd_vf_rx_vlan_filter_portid,
7820                 (void *)&cmd_vf_rx_vlan_filter_vf,
7821                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7822                 NULL,
7823         },
7824 };
7825
7826 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7827 struct cmd_queue_rate_limit_result {
7828         cmdline_fixed_string_t set;
7829         cmdline_fixed_string_t port;
7830         uint16_t port_num;
7831         cmdline_fixed_string_t queue;
7832         uint8_t queue_num;
7833         cmdline_fixed_string_t rate;
7834         uint16_t rate_num;
7835 };
7836
7837 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7838                 __attribute__((unused)) struct cmdline *cl,
7839                 __attribute__((unused)) void *data)
7840 {
7841         struct cmd_queue_rate_limit_result *res = parsed_result;
7842         int ret = 0;
7843
7844         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7845                 && (strcmp(res->queue, "queue") == 0)
7846                 && (strcmp(res->rate, "rate") == 0))
7847                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7848                                         res->rate_num);
7849         if (ret < 0)
7850                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7851
7852 }
7853
7854 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7855         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7856                                 set, "set");
7857 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7858         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7859                                 port, "port");
7860 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7861         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7862                                 port_num, UINT16);
7863 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7864         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7865                                 queue, "queue");
7866 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7867         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7868                                 queue_num, UINT8);
7869 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7870         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7871                                 rate, "rate");
7872 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7873         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7874                                 rate_num, UINT16);
7875
7876 cmdline_parse_inst_t cmd_queue_rate_limit = {
7877         .f = cmd_queue_rate_limit_parsed,
7878         .data = (void *)0,
7879         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7880                 "Set rate limit for a queue on port_id",
7881         .tokens = {
7882                 (void *)&cmd_queue_rate_limit_set,
7883                 (void *)&cmd_queue_rate_limit_port,
7884                 (void *)&cmd_queue_rate_limit_portnum,
7885                 (void *)&cmd_queue_rate_limit_queue,
7886                 (void *)&cmd_queue_rate_limit_queuenum,
7887                 (void *)&cmd_queue_rate_limit_rate,
7888                 (void *)&cmd_queue_rate_limit_ratenum,
7889                 NULL,
7890         },
7891 };
7892
7893 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7894 struct cmd_vf_rate_limit_result {
7895         cmdline_fixed_string_t set;
7896         cmdline_fixed_string_t port;
7897         uint16_t port_num;
7898         cmdline_fixed_string_t vf;
7899         uint8_t vf_num;
7900         cmdline_fixed_string_t rate;
7901         uint16_t rate_num;
7902         cmdline_fixed_string_t q_msk;
7903         uint64_t q_msk_val;
7904 };
7905
7906 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7907                 __attribute__((unused)) struct cmdline *cl,
7908                 __attribute__((unused)) void *data)
7909 {
7910         struct cmd_vf_rate_limit_result *res = parsed_result;
7911         int ret = 0;
7912
7913         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7914                 && (strcmp(res->vf, "vf") == 0)
7915                 && (strcmp(res->rate, "rate") == 0)
7916                 && (strcmp(res->q_msk, "queue_mask") == 0))
7917                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7918                                         res->rate_num, res->q_msk_val);
7919         if (ret < 0)
7920                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7921
7922 }
7923
7924 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7925         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7926                                 set, "set");
7927 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7928         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7929                                 port, "port");
7930 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7931         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7932                                 port_num, UINT16);
7933 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7934         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7935                                 vf, "vf");
7936 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7937         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7938                                 vf_num, UINT8);
7939 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7940         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7941                                 rate, "rate");
7942 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7943         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7944                                 rate_num, UINT16);
7945 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7946         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7947                                 q_msk, "queue_mask");
7948 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7949         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7950                                 q_msk_val, UINT64);
7951
7952 cmdline_parse_inst_t cmd_vf_rate_limit = {
7953         .f = cmd_vf_rate_limit_parsed,
7954         .data = (void *)0,
7955         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7956                 "queue_mask <queue_mask_value>: "
7957                 "Set rate limit for queues of VF on port_id",
7958         .tokens = {
7959                 (void *)&cmd_vf_rate_limit_set,
7960                 (void *)&cmd_vf_rate_limit_port,
7961                 (void *)&cmd_vf_rate_limit_portnum,
7962                 (void *)&cmd_vf_rate_limit_vf,
7963                 (void *)&cmd_vf_rate_limit_vfnum,
7964                 (void *)&cmd_vf_rate_limit_rate,
7965                 (void *)&cmd_vf_rate_limit_ratenum,
7966                 (void *)&cmd_vf_rate_limit_q_msk,
7967                 (void *)&cmd_vf_rate_limit_q_msk_val,
7968                 NULL,
7969         },
7970 };
7971
7972 /* *** ADD TUNNEL FILTER OF A PORT *** */
7973 struct cmd_tunnel_filter_result {
7974         cmdline_fixed_string_t cmd;
7975         cmdline_fixed_string_t what;
7976         portid_t port_id;
7977         struct ether_addr outer_mac;
7978         struct ether_addr inner_mac;
7979         cmdline_ipaddr_t ip_value;
7980         uint16_t inner_vlan;
7981         cmdline_fixed_string_t tunnel_type;
7982         cmdline_fixed_string_t filter_type;
7983         uint32_t tenant_id;
7984         uint16_t queue_num;
7985 };
7986
7987 static void
7988 cmd_tunnel_filter_parsed(void *parsed_result,
7989                           __attribute__((unused)) struct cmdline *cl,
7990                           __attribute__((unused)) void *data)
7991 {
7992         struct cmd_tunnel_filter_result *res = parsed_result;
7993         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7994         int ret = 0;
7995
7996         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7997
7998         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7999         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8000         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8001
8002         if (res->ip_value.family == AF_INET) {
8003                 tunnel_filter_conf.ip_addr.ipv4_addr =
8004                         res->ip_value.addr.ipv4.s_addr;
8005                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8006         } else {
8007                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8008                         &(res->ip_value.addr.ipv6),
8009                         sizeof(struct in6_addr));
8010                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8011         }
8012
8013         if (!strcmp(res->filter_type, "imac-ivlan"))
8014                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8015         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8016                 tunnel_filter_conf.filter_type =
8017                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8018         else if (!strcmp(res->filter_type, "imac-tenid"))
8019                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8020         else if (!strcmp(res->filter_type, "imac"))
8021                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8022         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8023                 tunnel_filter_conf.filter_type =
8024                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8025         else if (!strcmp(res->filter_type, "oip"))
8026                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8027         else if (!strcmp(res->filter_type, "iip"))
8028                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8029         else {
8030                 printf("The filter type is not supported");
8031                 return;
8032         }
8033
8034         if (!strcmp(res->tunnel_type, "vxlan"))
8035                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8036         else if (!strcmp(res->tunnel_type, "nvgre"))
8037                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8038         else if (!strcmp(res->tunnel_type, "ipingre"))
8039                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8040         else {
8041                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8042                 return;
8043         }
8044
8045         tunnel_filter_conf.tenant_id = res->tenant_id;
8046         tunnel_filter_conf.queue_id = res->queue_num;
8047         if (!strcmp(res->what, "add"))
8048                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8049                                         RTE_ETH_FILTER_TUNNEL,
8050                                         RTE_ETH_FILTER_ADD,
8051                                         &tunnel_filter_conf);
8052         else
8053                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8054                                         RTE_ETH_FILTER_TUNNEL,
8055                                         RTE_ETH_FILTER_DELETE,
8056                                         &tunnel_filter_conf);
8057         if (ret < 0)
8058                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8059                                 strerror(-ret));
8060
8061 }
8062 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8063         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8064         cmd, "tunnel_filter");
8065 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8066         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8067         what, "add#rm");
8068 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8069         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8070         port_id, UINT16);
8071 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8072         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8073         outer_mac);
8074 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8075         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8076         inner_mac);
8077 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8078         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8079         inner_vlan, UINT16);
8080 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8081         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8082         ip_value);
8083 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8084         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8085         tunnel_type, "vxlan#nvgre#ipingre");
8086
8087 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8088         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8089         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8090                 "imac#omac-imac-tenid");
8091 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8092         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8093         tenant_id, UINT32);
8094 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8095         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8096         queue_num, UINT16);
8097
8098 cmdline_parse_inst_t cmd_tunnel_filter = {
8099         .f = cmd_tunnel_filter_parsed,
8100         .data = (void *)0,
8101         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8102                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8103                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8104                 "<queue_id>: Add/Rm tunnel filter of a port",
8105         .tokens = {
8106                 (void *)&cmd_tunnel_filter_cmd,
8107                 (void *)&cmd_tunnel_filter_what,
8108                 (void *)&cmd_tunnel_filter_port_id,
8109                 (void *)&cmd_tunnel_filter_outer_mac,
8110                 (void *)&cmd_tunnel_filter_inner_mac,
8111                 (void *)&cmd_tunnel_filter_ip_value,
8112                 (void *)&cmd_tunnel_filter_innner_vlan,
8113                 (void *)&cmd_tunnel_filter_tunnel_type,
8114                 (void *)&cmd_tunnel_filter_filter_type,
8115                 (void *)&cmd_tunnel_filter_tenant_id,
8116                 (void *)&cmd_tunnel_filter_queue_num,
8117                 NULL,
8118         },
8119 };
8120
8121 /* *** CONFIGURE TUNNEL UDP PORT *** */
8122 struct cmd_tunnel_udp_config {
8123         cmdline_fixed_string_t cmd;
8124         cmdline_fixed_string_t what;
8125         uint16_t udp_port;
8126         portid_t port_id;
8127 };
8128
8129 static void
8130 cmd_tunnel_udp_config_parsed(void *parsed_result,
8131                           __attribute__((unused)) struct cmdline *cl,
8132                           __attribute__((unused)) void *data)
8133 {
8134         struct cmd_tunnel_udp_config *res = parsed_result;
8135         struct rte_eth_udp_tunnel tunnel_udp;
8136         int ret;
8137
8138         tunnel_udp.udp_port = res->udp_port;
8139
8140         if (!strcmp(res->cmd, "rx_vxlan_port"))
8141                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8142
8143         if (!strcmp(res->what, "add"))
8144                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8145                                                       &tunnel_udp);
8146         else
8147                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8148                                                          &tunnel_udp);
8149
8150         if (ret < 0)
8151                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8152 }
8153
8154 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8155         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8156                                 cmd, "rx_vxlan_port");
8157 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8158         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8159                                 what, "add#rm");
8160 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8161         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8162                                 udp_port, UINT16);
8163 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8164         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8165                                 port_id, UINT16);
8166
8167 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8168         .f = cmd_tunnel_udp_config_parsed,
8169         .data = (void *)0,
8170         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8171                 "Add/Remove a tunneling UDP port filter",
8172         .tokens = {
8173                 (void *)&cmd_tunnel_udp_config_cmd,
8174                 (void *)&cmd_tunnel_udp_config_what,
8175                 (void *)&cmd_tunnel_udp_config_udp_port,
8176                 (void *)&cmd_tunnel_udp_config_port_id,
8177                 NULL,
8178         },
8179 };
8180
8181 /* *** GLOBAL CONFIG *** */
8182 struct cmd_global_config_result {
8183         cmdline_fixed_string_t cmd;
8184         portid_t port_id;
8185         cmdline_fixed_string_t cfg_type;
8186         uint8_t len;
8187 };
8188
8189 static void
8190 cmd_global_config_parsed(void *parsed_result,
8191                          __attribute__((unused)) struct cmdline *cl,
8192                          __attribute__((unused)) void *data)
8193 {
8194         struct cmd_global_config_result *res = parsed_result;
8195         struct rte_eth_global_cfg conf;
8196         int ret;
8197
8198         memset(&conf, 0, sizeof(conf));
8199         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8200         conf.cfg.gre_key_len = res->len;
8201         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8202                                       RTE_ETH_FILTER_SET, &conf);
8203         if (ret != 0)
8204                 printf("Global config error\n");
8205 }
8206
8207 cmdline_parse_token_string_t cmd_global_config_cmd =
8208         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8209                 "global_config");
8210 cmdline_parse_token_num_t cmd_global_config_port_id =
8211         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8212                                UINT16);
8213 cmdline_parse_token_string_t cmd_global_config_type =
8214         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8215                 cfg_type, "gre-key-len");
8216 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8217         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8218                 len, UINT8);
8219
8220 cmdline_parse_inst_t cmd_global_config = {
8221         .f = cmd_global_config_parsed,
8222         .data = (void *)NULL,
8223         .help_str = "global_config <port_id> gre-key-len <key_len>",
8224         .tokens = {
8225                 (void *)&cmd_global_config_cmd,
8226                 (void *)&cmd_global_config_port_id,
8227                 (void *)&cmd_global_config_type,
8228                 (void *)&cmd_global_config_gre_key_len,
8229                 NULL,
8230         },
8231 };
8232
8233 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8234 struct cmd_set_mirror_mask_result {
8235         cmdline_fixed_string_t set;
8236         cmdline_fixed_string_t port;
8237         portid_t port_id;
8238         cmdline_fixed_string_t mirror;
8239         uint8_t rule_id;
8240         cmdline_fixed_string_t what;
8241         cmdline_fixed_string_t value;
8242         cmdline_fixed_string_t dstpool;
8243         uint8_t dstpool_id;
8244         cmdline_fixed_string_t on;
8245 };
8246
8247 cmdline_parse_token_string_t cmd_mirror_mask_set =
8248         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8249                                 set, "set");
8250 cmdline_parse_token_string_t cmd_mirror_mask_port =
8251         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8252                                 port, "port");
8253 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8254         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8255                                 port_id, UINT16);
8256 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8257         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8258                                 mirror, "mirror-rule");
8259 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8260         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8261                                 rule_id, UINT8);
8262 cmdline_parse_token_string_t cmd_mirror_mask_what =
8263         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8264                                 what, "pool-mirror-up#pool-mirror-down"
8265                                       "#vlan-mirror");
8266 cmdline_parse_token_string_t cmd_mirror_mask_value =
8267         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8268                                 value, NULL);
8269 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8270         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8271                                 dstpool, "dst-pool");
8272 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8273         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8274                                 dstpool_id, UINT8);
8275 cmdline_parse_token_string_t cmd_mirror_mask_on =
8276         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8277                                 on, "on#off");
8278
8279 static void
8280 cmd_set_mirror_mask_parsed(void *parsed_result,
8281                        __attribute__((unused)) struct cmdline *cl,
8282                        __attribute__((unused)) void *data)
8283 {
8284         int ret,nb_item,i;
8285         struct cmd_set_mirror_mask_result *res = parsed_result;
8286         struct rte_eth_mirror_conf mr_conf;
8287
8288         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8289
8290         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8291
8292         mr_conf.dst_pool = res->dstpool_id;
8293
8294         if (!strcmp(res->what, "pool-mirror-up")) {
8295                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8296                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8297         } else if (!strcmp(res->what, "pool-mirror-down")) {
8298                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8299                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8300         } else if (!strcmp(res->what, "vlan-mirror")) {
8301                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8302                 nb_item = parse_item_list(res->value, "vlan",
8303                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8304                 if (nb_item <= 0)
8305                         return;
8306
8307                 for (i = 0; i < nb_item; i++) {
8308                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8309                                 printf("Invalid vlan_id: must be < 4096\n");
8310                                 return;
8311                         }
8312
8313                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8314                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8315                 }
8316         }
8317
8318         if (!strcmp(res->on, "on"))
8319                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8320                                                 res->rule_id, 1);
8321         else
8322                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8323                                                 res->rule_id, 0);
8324         if (ret < 0)
8325                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8326 }
8327
8328 cmdline_parse_inst_t cmd_set_mirror_mask = {
8329                 .f = cmd_set_mirror_mask_parsed,
8330                 .data = NULL,
8331                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8332                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8333                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8334                 .tokens = {
8335                         (void *)&cmd_mirror_mask_set,
8336                         (void *)&cmd_mirror_mask_port,
8337                         (void *)&cmd_mirror_mask_portid,
8338                         (void *)&cmd_mirror_mask_mirror,
8339                         (void *)&cmd_mirror_mask_ruleid,
8340                         (void *)&cmd_mirror_mask_what,
8341                         (void *)&cmd_mirror_mask_value,
8342                         (void *)&cmd_mirror_mask_dstpool,
8343                         (void *)&cmd_mirror_mask_poolid,
8344                         (void *)&cmd_mirror_mask_on,
8345                         NULL,
8346                 },
8347 };
8348
8349 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8350 struct cmd_set_mirror_link_result {
8351         cmdline_fixed_string_t set;
8352         cmdline_fixed_string_t port;
8353         portid_t port_id;
8354         cmdline_fixed_string_t mirror;
8355         uint8_t rule_id;
8356         cmdline_fixed_string_t what;
8357         cmdline_fixed_string_t dstpool;
8358         uint8_t dstpool_id;
8359         cmdline_fixed_string_t on;
8360 };
8361
8362 cmdline_parse_token_string_t cmd_mirror_link_set =
8363         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8364                                  set, "set");
8365 cmdline_parse_token_string_t cmd_mirror_link_port =
8366         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8367                                 port, "port");
8368 cmdline_parse_token_num_t cmd_mirror_link_portid =
8369         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8370                                 port_id, UINT16);
8371 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8372         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8373                                 mirror, "mirror-rule");
8374 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8375         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8376                             rule_id, UINT8);
8377 cmdline_parse_token_string_t cmd_mirror_link_what =
8378         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8379                                 what, "uplink-mirror#downlink-mirror");
8380 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8381         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8382                                 dstpool, "dst-pool");
8383 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8384         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8385                                 dstpool_id, UINT8);
8386 cmdline_parse_token_string_t cmd_mirror_link_on =
8387         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8388                                 on, "on#off");
8389
8390 static void
8391 cmd_set_mirror_link_parsed(void *parsed_result,
8392                        __attribute__((unused)) struct cmdline *cl,
8393                        __attribute__((unused)) void *data)
8394 {
8395         int ret;
8396         struct cmd_set_mirror_link_result *res = parsed_result;
8397         struct rte_eth_mirror_conf mr_conf;
8398
8399         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8400         if (!strcmp(res->what, "uplink-mirror"))
8401                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8402         else
8403                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8404
8405         mr_conf.dst_pool = res->dstpool_id;
8406
8407         if (!strcmp(res->on, "on"))
8408                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8409                                                 res->rule_id, 1);
8410         else
8411                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8412                                                 res->rule_id, 0);
8413
8414         /* check the return value and print it if is < 0 */
8415         if (ret < 0)
8416                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8417
8418 }
8419
8420 cmdline_parse_inst_t cmd_set_mirror_link = {
8421                 .f = cmd_set_mirror_link_parsed,
8422                 .data = NULL,
8423                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8424                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8425                 .tokens = {
8426                         (void *)&cmd_mirror_link_set,
8427                         (void *)&cmd_mirror_link_port,
8428                         (void *)&cmd_mirror_link_portid,
8429                         (void *)&cmd_mirror_link_mirror,
8430                         (void *)&cmd_mirror_link_ruleid,
8431                         (void *)&cmd_mirror_link_what,
8432                         (void *)&cmd_mirror_link_dstpool,
8433                         (void *)&cmd_mirror_link_poolid,
8434                         (void *)&cmd_mirror_link_on,
8435                         NULL,
8436                 },
8437 };
8438
8439 /* *** RESET VM MIRROR RULE *** */
8440 struct cmd_rm_mirror_rule_result {
8441         cmdline_fixed_string_t reset;
8442         cmdline_fixed_string_t port;
8443         portid_t port_id;
8444         cmdline_fixed_string_t mirror;
8445         uint8_t rule_id;
8446 };
8447
8448 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8449         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8450                                  reset, "reset");
8451 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8452         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8453                                 port, "port");
8454 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8455         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8456                                 port_id, UINT16);
8457 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8458         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8459                                 mirror, "mirror-rule");
8460 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8461         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8462                                 rule_id, UINT8);
8463
8464 static void
8465 cmd_reset_mirror_rule_parsed(void *parsed_result,
8466                        __attribute__((unused)) struct cmdline *cl,
8467                        __attribute__((unused)) void *data)
8468 {
8469         int ret;
8470         struct cmd_set_mirror_link_result *res = parsed_result;
8471         /* check rule_id */
8472         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8473         if(ret < 0)
8474                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8475 }
8476
8477 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8478                 .f = cmd_reset_mirror_rule_parsed,
8479                 .data = NULL,
8480                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8481                 .tokens = {
8482                         (void *)&cmd_rm_mirror_rule_reset,
8483                         (void *)&cmd_rm_mirror_rule_port,
8484                         (void *)&cmd_rm_mirror_rule_portid,
8485                         (void *)&cmd_rm_mirror_rule_mirror,
8486                         (void *)&cmd_rm_mirror_rule_ruleid,
8487                         NULL,
8488                 },
8489 };
8490
8491 /* ******************************************************************************** */
8492
8493 struct cmd_dump_result {
8494         cmdline_fixed_string_t dump;
8495 };
8496
8497 static void
8498 dump_struct_sizes(void)
8499 {
8500 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8501         DUMP_SIZE(struct rte_mbuf);
8502         DUMP_SIZE(struct rte_mempool);
8503         DUMP_SIZE(struct rte_ring);
8504 #undef DUMP_SIZE
8505 }
8506
8507 static void cmd_dump_parsed(void *parsed_result,
8508                             __attribute__((unused)) struct cmdline *cl,
8509                             __attribute__((unused)) void *data)
8510 {
8511         struct cmd_dump_result *res = parsed_result;
8512
8513         if (!strcmp(res->dump, "dump_physmem"))
8514                 rte_dump_physmem_layout(stdout);
8515         else if (!strcmp(res->dump, "dump_memzone"))
8516                 rte_memzone_dump(stdout);
8517         else if (!strcmp(res->dump, "dump_struct_sizes"))
8518                 dump_struct_sizes();
8519         else if (!strcmp(res->dump, "dump_ring"))
8520                 rte_ring_list_dump(stdout);
8521         else if (!strcmp(res->dump, "dump_mempool"))
8522                 rte_mempool_list_dump(stdout);
8523         else if (!strcmp(res->dump, "dump_devargs"))
8524                 rte_eal_devargs_dump(stdout);
8525         else if (!strcmp(res->dump, "dump_log_types"))
8526                 rte_log_dump(stdout);
8527 }
8528
8529 cmdline_parse_token_string_t cmd_dump_dump =
8530         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8531                 "dump_physmem#"
8532                 "dump_memzone#"
8533                 "dump_struct_sizes#"
8534                 "dump_ring#"
8535                 "dump_mempool#"
8536                 "dump_devargs#"
8537                 "dump_log_types");
8538
8539 cmdline_parse_inst_t cmd_dump = {
8540         .f = cmd_dump_parsed,  /* function to call */
8541         .data = NULL,      /* 2nd arg of func */
8542         .help_str = "Dump status",
8543         .tokens = {        /* token list, NULL terminated */
8544                 (void *)&cmd_dump_dump,
8545                 NULL,
8546         },
8547 };
8548
8549 /* ******************************************************************************** */
8550
8551 struct cmd_dump_one_result {
8552         cmdline_fixed_string_t dump;
8553         cmdline_fixed_string_t name;
8554 };
8555
8556 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8557                                 __attribute__((unused)) void *data)
8558 {
8559         struct cmd_dump_one_result *res = parsed_result;
8560
8561         if (!strcmp(res->dump, "dump_ring")) {
8562                 struct rte_ring *r;
8563                 r = rte_ring_lookup(res->name);
8564                 if (r == NULL) {
8565                         cmdline_printf(cl, "Cannot find ring\n");
8566                         return;
8567                 }
8568                 rte_ring_dump(stdout, r);
8569         } else if (!strcmp(res->dump, "dump_mempool")) {
8570                 struct rte_mempool *mp;
8571                 mp = rte_mempool_lookup(res->name);
8572                 if (mp == NULL) {
8573                         cmdline_printf(cl, "Cannot find mempool\n");
8574                         return;
8575                 }
8576                 rte_mempool_dump(stdout, mp);
8577         }
8578 }
8579
8580 cmdline_parse_token_string_t cmd_dump_one_dump =
8581         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8582                                  "dump_ring#dump_mempool");
8583
8584 cmdline_parse_token_string_t cmd_dump_one_name =
8585         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8586
8587 cmdline_parse_inst_t cmd_dump_one = {
8588         .f = cmd_dump_one_parsed,  /* function to call */
8589         .data = NULL,      /* 2nd arg of func */
8590         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8591         .tokens = {        /* token list, NULL terminated */
8592                 (void *)&cmd_dump_one_dump,
8593                 (void *)&cmd_dump_one_name,
8594                 NULL,
8595         },
8596 };
8597
8598 /* *** Add/Del syn filter *** */
8599 struct cmd_syn_filter_result {
8600         cmdline_fixed_string_t filter;
8601         portid_t port_id;
8602         cmdline_fixed_string_t ops;
8603         cmdline_fixed_string_t priority;
8604         cmdline_fixed_string_t high;
8605         cmdline_fixed_string_t queue;
8606         uint16_t queue_id;
8607 };
8608
8609 static void
8610 cmd_syn_filter_parsed(void *parsed_result,
8611                         __attribute__((unused)) struct cmdline *cl,
8612                         __attribute__((unused)) void *data)
8613 {
8614         struct cmd_syn_filter_result *res = parsed_result;
8615         struct rte_eth_syn_filter syn_filter;
8616         int ret = 0;
8617
8618         ret = rte_eth_dev_filter_supported(res->port_id,
8619                                         RTE_ETH_FILTER_SYN);
8620         if (ret < 0) {
8621                 printf("syn filter is not supported on port %u.\n",
8622                                 res->port_id);
8623                 return;
8624         }
8625
8626         memset(&syn_filter, 0, sizeof(syn_filter));
8627
8628         if (!strcmp(res->ops, "add")) {
8629                 if (!strcmp(res->high, "high"))
8630                         syn_filter.hig_pri = 1;
8631                 else
8632                         syn_filter.hig_pri = 0;
8633
8634                 syn_filter.queue = res->queue_id;
8635                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8636                                                 RTE_ETH_FILTER_SYN,
8637                                                 RTE_ETH_FILTER_ADD,
8638                                                 &syn_filter);
8639         } else
8640                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8641                                                 RTE_ETH_FILTER_SYN,
8642                                                 RTE_ETH_FILTER_DELETE,
8643                                                 &syn_filter);
8644
8645         if (ret < 0)
8646                 printf("syn filter programming error: (%s)\n",
8647                                 strerror(-ret));
8648 }
8649
8650 cmdline_parse_token_string_t cmd_syn_filter_filter =
8651         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8652         filter, "syn_filter");
8653 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8654         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8655         port_id, UINT16);
8656 cmdline_parse_token_string_t cmd_syn_filter_ops =
8657         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8658         ops, "add#del");
8659 cmdline_parse_token_string_t cmd_syn_filter_priority =
8660         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8661                                 priority, "priority");
8662 cmdline_parse_token_string_t cmd_syn_filter_high =
8663         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8664                                 high, "high#low");
8665 cmdline_parse_token_string_t cmd_syn_filter_queue =
8666         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8667                                 queue, "queue");
8668 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8669         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8670                                 queue_id, UINT16);
8671
8672 cmdline_parse_inst_t cmd_syn_filter = {
8673         .f = cmd_syn_filter_parsed,
8674         .data = NULL,
8675         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8676                 "<queue_id>: Add/Delete syn filter",
8677         .tokens = {
8678                 (void *)&cmd_syn_filter_filter,
8679                 (void *)&cmd_syn_filter_port_id,
8680                 (void *)&cmd_syn_filter_ops,
8681                 (void *)&cmd_syn_filter_priority,
8682                 (void *)&cmd_syn_filter_high,
8683                 (void *)&cmd_syn_filter_queue,
8684                 (void *)&cmd_syn_filter_queue_id,
8685                 NULL,
8686         },
8687 };
8688
8689 /* *** queue region set *** */
8690 struct cmd_queue_region_result {
8691         cmdline_fixed_string_t set;
8692         cmdline_fixed_string_t port;
8693         portid_t port_id;
8694         cmdline_fixed_string_t cmd;
8695         cmdline_fixed_string_t region;
8696         uint8_t  region_id;
8697         cmdline_fixed_string_t queue_start_index;
8698         uint8_t  queue_id;
8699         cmdline_fixed_string_t queue_num;
8700         uint8_t  queue_num_value;
8701 };
8702
8703 static void
8704 cmd_queue_region_parsed(void *parsed_result,
8705                         __attribute__((unused)) struct cmdline *cl,
8706                         __attribute__((unused)) void *data)
8707 {
8708         struct cmd_queue_region_result *res = parsed_result;
8709         int ret = -ENOTSUP;
8710 #ifdef RTE_LIBRTE_I40E_PMD
8711         struct rte_pmd_i40e_queue_region_conf region_conf;
8712         enum rte_pmd_i40e_queue_region_op op_type;
8713 #endif
8714
8715         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8716                 return;
8717
8718 #ifdef RTE_LIBRTE_I40E_PMD
8719         memset(&region_conf, 0, sizeof(region_conf));
8720         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8721         region_conf.region_id = res->region_id;
8722         region_conf.queue_num = res->queue_num_value;
8723         region_conf.queue_start_index = res->queue_id;
8724
8725         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8726                                 op_type, &region_conf);
8727 #endif
8728
8729         switch (ret) {
8730         case 0:
8731                 break;
8732         case -ENOTSUP:
8733                 printf("function not implemented or supported\n");
8734                 break;
8735         default:
8736                 printf("queue region config error: (%s)\n", strerror(-ret));
8737         }
8738 }
8739
8740 cmdline_parse_token_string_t cmd_queue_region_set =
8741 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8742                 set, "set");
8743 cmdline_parse_token_string_t cmd_queue_region_port =
8744         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8745 cmdline_parse_token_num_t cmd_queue_region_port_id =
8746         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8747                                 port_id, UINT16);
8748 cmdline_parse_token_string_t cmd_queue_region_cmd =
8749         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8750                                  cmd, "queue-region");
8751 cmdline_parse_token_string_t cmd_queue_region_id =
8752         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8753                                 region, "region_id");
8754 cmdline_parse_token_num_t cmd_queue_region_index =
8755         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8756                                 region_id, UINT8);
8757 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8758         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8759                                 queue_start_index, "queue_start_index");
8760 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8761         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8762                                 queue_id, UINT8);
8763 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8764         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8765                                 queue_num, "queue_num");
8766 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8767         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8768                                 queue_num_value, UINT8);
8769
8770 cmdline_parse_inst_t cmd_queue_region = {
8771         .f = cmd_queue_region_parsed,
8772         .data = NULL,
8773         .help_str = "set port <port_id> queue-region region_id <value> "
8774                 "queue_start_index <value> queue_num <value>: Set a queue region",
8775         .tokens = {
8776                 (void *)&cmd_queue_region_set,
8777                 (void *)&cmd_queue_region_port,
8778                 (void *)&cmd_queue_region_port_id,
8779                 (void *)&cmd_queue_region_cmd,
8780                 (void *)&cmd_queue_region_id,
8781                 (void *)&cmd_queue_region_index,
8782                 (void *)&cmd_queue_region_queue_start_index,
8783                 (void *)&cmd_queue_region_queue_id,
8784                 (void *)&cmd_queue_region_queue_num,
8785                 (void *)&cmd_queue_region_queue_num_value,
8786                 NULL,
8787         },
8788 };
8789
8790 /* *** queue region and flowtype set *** */
8791 struct cmd_region_flowtype_result {
8792         cmdline_fixed_string_t set;
8793         cmdline_fixed_string_t port;
8794         portid_t port_id;
8795         cmdline_fixed_string_t cmd;
8796         cmdline_fixed_string_t region;
8797         uint8_t  region_id;
8798         cmdline_fixed_string_t flowtype;
8799         uint8_t  flowtype_id;
8800 };
8801
8802 static void
8803 cmd_region_flowtype_parsed(void *parsed_result,
8804                         __attribute__((unused)) struct cmdline *cl,
8805                         __attribute__((unused)) void *data)
8806 {
8807         struct cmd_region_flowtype_result *res = parsed_result;
8808         int ret = -ENOTSUP;
8809 #ifdef RTE_LIBRTE_I40E_PMD
8810         struct rte_pmd_i40e_queue_region_conf region_conf;
8811         enum rte_pmd_i40e_queue_region_op op_type;
8812 #endif
8813
8814         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8815                 return;
8816
8817 #ifdef RTE_LIBRTE_I40E_PMD
8818         memset(&region_conf, 0, sizeof(region_conf));
8819
8820         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8821         region_conf.region_id = res->region_id;
8822         region_conf.hw_flowtype = res->flowtype_id;
8823
8824         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8825                         op_type, &region_conf);
8826 #endif
8827
8828         switch (ret) {
8829         case 0:
8830                 break;
8831         case -ENOTSUP:
8832                 printf("function not implemented or supported\n");
8833                 break;
8834         default:
8835                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8836         }
8837 }
8838
8839 cmdline_parse_token_string_t cmd_region_flowtype_set =
8840 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8841                                 set, "set");
8842 cmdline_parse_token_string_t cmd_region_flowtype_port =
8843         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8844                                 port, "port");
8845 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8846         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8847                                 port_id, UINT16);
8848 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8849         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8850                                 cmd, "queue-region");
8851 cmdline_parse_token_string_t cmd_region_flowtype_index =
8852         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8853                                 region, "region_id");
8854 cmdline_parse_token_num_t cmd_region_flowtype_id =
8855         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8856                                 region_id, UINT8);
8857 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8858         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8859                                 flowtype, "flowtype");
8860 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8861         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8862                                 flowtype_id, UINT8);
8863 cmdline_parse_inst_t cmd_region_flowtype = {
8864         .f = cmd_region_flowtype_parsed,
8865         .data = NULL,
8866         .help_str = "set port <port_id> queue-region region_id <value> "
8867                 "flowtype <value>: Set a flowtype region index",
8868         .tokens = {
8869                 (void *)&cmd_region_flowtype_set,
8870                 (void *)&cmd_region_flowtype_port,
8871                 (void *)&cmd_region_flowtype_port_index,
8872                 (void *)&cmd_region_flowtype_cmd,
8873                 (void *)&cmd_region_flowtype_index,
8874                 (void *)&cmd_region_flowtype_id,
8875                 (void *)&cmd_region_flowtype_flow_index,
8876                 (void *)&cmd_region_flowtype_flow_id,
8877                 NULL,
8878         },
8879 };
8880
8881 /* *** User Priority (UP) to queue region (region_id) set *** */
8882 struct cmd_user_priority_region_result {
8883         cmdline_fixed_string_t set;
8884         cmdline_fixed_string_t port;
8885         portid_t port_id;
8886         cmdline_fixed_string_t cmd;
8887         cmdline_fixed_string_t user_priority;
8888         uint8_t  user_priority_id;
8889         cmdline_fixed_string_t region;
8890         uint8_t  region_id;
8891 };
8892
8893 static void
8894 cmd_user_priority_region_parsed(void *parsed_result,
8895                         __attribute__((unused)) struct cmdline *cl,
8896                         __attribute__((unused)) void *data)
8897 {
8898         struct cmd_user_priority_region_result *res = parsed_result;
8899         int ret = -ENOTSUP;
8900 #ifdef RTE_LIBRTE_I40E_PMD
8901         struct rte_pmd_i40e_queue_region_conf region_conf;
8902         enum rte_pmd_i40e_queue_region_op op_type;
8903 #endif
8904
8905         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8906                 return;
8907
8908 #ifdef RTE_LIBRTE_I40E_PMD
8909         memset(&region_conf, 0, sizeof(region_conf));
8910         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8911         region_conf.user_priority = res->user_priority_id;
8912         region_conf.region_id = res->region_id;
8913
8914         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8915                                 op_type, &region_conf);
8916 #endif
8917
8918         switch (ret) {
8919         case 0:
8920                 break;
8921         case -ENOTSUP:
8922                 printf("function not implemented or supported\n");
8923                 break;
8924         default:
8925                 printf("user_priority region config error: (%s)\n",
8926                                 strerror(-ret));
8927         }
8928 }
8929
8930 cmdline_parse_token_string_t cmd_user_priority_region_set =
8931         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8932                                 set, "set");
8933 cmdline_parse_token_string_t cmd_user_priority_region_port =
8934         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8935                                 port, "port");
8936 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8937         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8938                                 port_id, UINT16);
8939 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8940         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8941                                 cmd, "queue-region");
8942 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8943         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8944                                 user_priority, "UP");
8945 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
8946         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8947                                 user_priority_id, UINT8);
8948 cmdline_parse_token_string_t cmd_user_priority_region_region =
8949         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8950                                 region, "region_id");
8951 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
8952         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8953                                 region_id, UINT8);
8954
8955 cmdline_parse_inst_t cmd_user_priority_region = {
8956         .f = cmd_user_priority_region_parsed,
8957         .data = NULL,
8958         .help_str = "set port <port_id> queue-region UP <value> "
8959                 "region_id <value>: Set the mapping of User Priority (UP) "
8960                 "to queue region (region_id) ",
8961         .tokens = {
8962                 (void *)&cmd_user_priority_region_set,
8963                 (void *)&cmd_user_priority_region_port,
8964                 (void *)&cmd_user_priority_region_port_index,
8965                 (void *)&cmd_user_priority_region_cmd,
8966                 (void *)&cmd_user_priority_region_UP,
8967                 (void *)&cmd_user_priority_region_UP_id,
8968                 (void *)&cmd_user_priority_region_region,
8969                 (void *)&cmd_user_priority_region_region_id,
8970                 NULL,
8971         },
8972 };
8973
8974 /* *** flush all queue region related configuration *** */
8975 struct cmd_flush_queue_region_result {
8976         cmdline_fixed_string_t set;
8977         cmdline_fixed_string_t port;
8978         portid_t port_id;
8979         cmdline_fixed_string_t cmd;
8980         cmdline_fixed_string_t flush;
8981         cmdline_fixed_string_t what;
8982 };
8983
8984 static void
8985 cmd_flush_queue_region_parsed(void *parsed_result,
8986                         __attribute__((unused)) struct cmdline *cl,
8987                         __attribute__((unused)) void *data)
8988 {
8989         struct cmd_flush_queue_region_result *res = parsed_result;
8990         int ret = -ENOTSUP;
8991 #ifdef RTE_LIBRTE_I40E_PMD
8992         struct rte_pmd_i40e_queue_region_conf region_conf;
8993         enum rte_pmd_i40e_queue_region_op op_type;
8994 #endif
8995
8996         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8997                 return;
8998
8999 #ifdef RTE_LIBRTE_I40E_PMD
9000         memset(&region_conf, 0, sizeof(region_conf));
9001
9002         if (strcmp(res->what, "on") == 0)
9003                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9004         else
9005                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9006
9007         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9008                                 op_type, &region_conf);
9009 #endif
9010
9011         switch (ret) {
9012         case 0:
9013                 break;
9014         case -ENOTSUP:
9015                 printf("function not implemented or supported\n");
9016                 break;
9017         default:
9018                 printf("queue region config flush error: (%s)\n",
9019                                 strerror(-ret));
9020         }
9021 }
9022
9023 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9024         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9025                                 set, "set");
9026 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9027         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9028                                 port, "port");
9029 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9030         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9031                                 port_id, UINT16);
9032 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9033         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9034                                 cmd, "queue-region");
9035 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9036         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9037                                 flush, "flush");
9038 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9039         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9040                                 what, "on#off");
9041
9042 cmdline_parse_inst_t cmd_flush_queue_region = {
9043         .f = cmd_flush_queue_region_parsed,
9044         .data = NULL,
9045         .help_str = "set port <port_id> queue-region flush on|off"
9046                 ": flush all queue region related configuration",
9047         .tokens = {
9048                 (void *)&cmd_flush_queue_region_set,
9049                 (void *)&cmd_flush_queue_region_port,
9050                 (void *)&cmd_flush_queue_region_port_index,
9051                 (void *)&cmd_flush_queue_region_cmd,
9052                 (void *)&cmd_flush_queue_region_flush,
9053                 (void *)&cmd_flush_queue_region_what,
9054                 NULL,
9055         },
9056 };
9057
9058 /* *** get all queue region related configuration info *** */
9059 struct cmd_show_queue_region_info {
9060         cmdline_fixed_string_t show;
9061         cmdline_fixed_string_t port;
9062         portid_t port_id;
9063         cmdline_fixed_string_t cmd;
9064 };
9065
9066 static void
9067 cmd_show_queue_region_info_parsed(void *parsed_result,
9068                         __attribute__((unused)) struct cmdline *cl,
9069                         __attribute__((unused)) void *data)
9070 {
9071         struct cmd_show_queue_region_info *res = parsed_result;
9072         int ret = -ENOTSUP;
9073 #ifdef RTE_LIBRTE_I40E_PMD
9074         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9075         enum rte_pmd_i40e_queue_region_op op_type;
9076 #endif
9077
9078         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9079                 return;
9080
9081 #ifdef RTE_LIBRTE_I40E_PMD
9082         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9083
9084         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9085
9086         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9087                                         op_type, &rte_pmd_regions);
9088
9089         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9090 #endif
9091
9092         switch (ret) {
9093         case 0:
9094                 break;
9095         case -ENOTSUP:
9096                 printf("function not implemented or supported\n");
9097                 break;
9098         default:
9099                 printf("queue region config info show error: (%s)\n",
9100                                 strerror(-ret));
9101         }
9102 }
9103
9104 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9105 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9106                                 show, "show");
9107 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9108         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9109                                 port, "port");
9110 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9111         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9112                                 port_id, UINT16);
9113 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9114         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9115                                 cmd, "queue-region");
9116
9117 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9118         .f = cmd_show_queue_region_info_parsed,
9119         .data = NULL,
9120         .help_str = "show port <port_id> queue-region"
9121                 ": show all queue region related configuration info",
9122         .tokens = {
9123                 (void *)&cmd_show_queue_region_info_get,
9124                 (void *)&cmd_show_queue_region_info_port,
9125                 (void *)&cmd_show_queue_region_info_port_index,
9126                 (void *)&cmd_show_queue_region_info_cmd,
9127                 NULL,
9128         },
9129 };
9130
9131 /* *** ADD/REMOVE A 2tuple FILTER *** */
9132 struct cmd_2tuple_filter_result {
9133         cmdline_fixed_string_t filter;
9134         portid_t port_id;
9135         cmdline_fixed_string_t ops;
9136         cmdline_fixed_string_t dst_port;
9137         uint16_t dst_port_value;
9138         cmdline_fixed_string_t protocol;
9139         uint8_t protocol_value;
9140         cmdline_fixed_string_t mask;
9141         uint8_t  mask_value;
9142         cmdline_fixed_string_t tcp_flags;
9143         uint8_t tcp_flags_value;
9144         cmdline_fixed_string_t priority;
9145         uint8_t  priority_value;
9146         cmdline_fixed_string_t queue;
9147         uint16_t  queue_id;
9148 };
9149
9150 static void
9151 cmd_2tuple_filter_parsed(void *parsed_result,
9152                         __attribute__((unused)) struct cmdline *cl,
9153                         __attribute__((unused)) void *data)
9154 {
9155         struct rte_eth_ntuple_filter filter;
9156         struct cmd_2tuple_filter_result *res = parsed_result;
9157         int ret = 0;
9158
9159         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9160         if (ret < 0) {
9161                 printf("ntuple filter is not supported on port %u.\n",
9162                         res->port_id);
9163                 return;
9164         }
9165
9166         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9167
9168         filter.flags = RTE_2TUPLE_FLAGS;
9169         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9170         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9171         filter.proto = res->protocol_value;
9172         filter.priority = res->priority_value;
9173         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9174                 printf("nonzero tcp_flags is only meaningful"
9175                         " when protocol is TCP.\n");
9176                 return;
9177         }
9178         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9179                 printf("invalid TCP flags.\n");
9180                 return;
9181         }
9182
9183         if (res->tcp_flags_value != 0) {
9184                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9185                 filter.tcp_flags = res->tcp_flags_value;
9186         }
9187
9188         /* need convert to big endian. */
9189         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9190         filter.queue = res->queue_id;
9191
9192         if (!strcmp(res->ops, "add"))
9193                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9194                                 RTE_ETH_FILTER_NTUPLE,
9195                                 RTE_ETH_FILTER_ADD,
9196                                 &filter);
9197         else
9198                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9199                                 RTE_ETH_FILTER_NTUPLE,
9200                                 RTE_ETH_FILTER_DELETE,
9201                                 &filter);
9202         if (ret < 0)
9203                 printf("2tuple filter programming error: (%s)\n",
9204                         strerror(-ret));
9205
9206 }
9207
9208 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9209         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9210                                  filter, "2tuple_filter");
9211 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9212         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9213                                 port_id, UINT16);
9214 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9215         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9216                                  ops, "add#del");
9217 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9218         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9219                                 dst_port, "dst_port");
9220 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9221         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9222                                 dst_port_value, UINT16);
9223 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9224         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9225                                 protocol, "protocol");
9226 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9227         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9228                                 protocol_value, UINT8);
9229 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9230         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9231                                 mask, "mask");
9232 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9233         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9234                                 mask_value, INT8);
9235 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9236         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9237                                 tcp_flags, "tcp_flags");
9238 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9239         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9240                                 tcp_flags_value, UINT8);
9241 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9242         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9243                                 priority, "priority");
9244 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9245         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9246                                 priority_value, UINT8);
9247 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9248         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9249                                 queue, "queue");
9250 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9251         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9252                                 queue_id, UINT16);
9253
9254 cmdline_parse_inst_t cmd_2tuple_filter = {
9255         .f = cmd_2tuple_filter_parsed,
9256         .data = NULL,
9257         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9258                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9259                 "<queue_id>: Add a 2tuple filter",
9260         .tokens = {
9261                 (void *)&cmd_2tuple_filter_filter,
9262                 (void *)&cmd_2tuple_filter_port_id,
9263                 (void *)&cmd_2tuple_filter_ops,
9264                 (void *)&cmd_2tuple_filter_dst_port,
9265                 (void *)&cmd_2tuple_filter_dst_port_value,
9266                 (void *)&cmd_2tuple_filter_protocol,
9267                 (void *)&cmd_2tuple_filter_protocol_value,
9268                 (void *)&cmd_2tuple_filter_mask,
9269                 (void *)&cmd_2tuple_filter_mask_value,
9270                 (void *)&cmd_2tuple_filter_tcp_flags,
9271                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9272                 (void *)&cmd_2tuple_filter_priority,
9273                 (void *)&cmd_2tuple_filter_priority_value,
9274                 (void *)&cmd_2tuple_filter_queue,
9275                 (void *)&cmd_2tuple_filter_queue_id,
9276                 NULL,
9277         },
9278 };
9279
9280 /* *** ADD/REMOVE A 5tuple FILTER *** */
9281 struct cmd_5tuple_filter_result {
9282         cmdline_fixed_string_t filter;
9283         portid_t port_id;
9284         cmdline_fixed_string_t ops;
9285         cmdline_fixed_string_t dst_ip;
9286         cmdline_ipaddr_t dst_ip_value;
9287         cmdline_fixed_string_t src_ip;
9288         cmdline_ipaddr_t src_ip_value;
9289         cmdline_fixed_string_t dst_port;
9290         uint16_t dst_port_value;
9291         cmdline_fixed_string_t src_port;
9292         uint16_t src_port_value;
9293         cmdline_fixed_string_t protocol;
9294         uint8_t protocol_value;
9295         cmdline_fixed_string_t mask;
9296         uint8_t  mask_value;
9297         cmdline_fixed_string_t tcp_flags;
9298         uint8_t tcp_flags_value;
9299         cmdline_fixed_string_t priority;
9300         uint8_t  priority_value;
9301         cmdline_fixed_string_t queue;
9302         uint16_t  queue_id;
9303 };
9304
9305 static void
9306 cmd_5tuple_filter_parsed(void *parsed_result,
9307                         __attribute__((unused)) struct cmdline *cl,
9308                         __attribute__((unused)) void *data)
9309 {
9310         struct rte_eth_ntuple_filter filter;
9311         struct cmd_5tuple_filter_result *res = parsed_result;
9312         int ret = 0;
9313
9314         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9315         if (ret < 0) {
9316                 printf("ntuple filter is not supported on port %u.\n",
9317                         res->port_id);
9318                 return;
9319         }
9320
9321         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9322
9323         filter.flags = RTE_5TUPLE_FLAGS;
9324         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9325         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9326         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9327         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9328         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9329         filter.proto = res->protocol_value;
9330         filter.priority = res->priority_value;
9331         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9332                 printf("nonzero tcp_flags is only meaningful"
9333                         " when protocol is TCP.\n");
9334                 return;
9335         }
9336         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9337                 printf("invalid TCP flags.\n");
9338                 return;
9339         }
9340
9341         if (res->tcp_flags_value != 0) {
9342                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9343                 filter.tcp_flags = res->tcp_flags_value;
9344         }
9345
9346         if (res->dst_ip_value.family == AF_INET)
9347                 /* no need to convert, already big endian. */
9348                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9349         else {
9350                 if (filter.dst_ip_mask == 0) {
9351                         printf("can not support ipv6 involved compare.\n");
9352                         return;
9353                 }
9354                 filter.dst_ip = 0;
9355         }
9356
9357         if (res->src_ip_value.family == AF_INET)
9358                 /* no need to convert, already big endian. */
9359                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9360         else {
9361                 if (filter.src_ip_mask == 0) {
9362                         printf("can not support ipv6 involved compare.\n");
9363                         return;
9364                 }
9365                 filter.src_ip = 0;
9366         }
9367         /* need convert to big endian. */
9368         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9369         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9370         filter.queue = res->queue_id;
9371
9372         if (!strcmp(res->ops, "add"))
9373                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9374                                 RTE_ETH_FILTER_NTUPLE,
9375                                 RTE_ETH_FILTER_ADD,
9376                                 &filter);
9377         else
9378                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9379                                 RTE_ETH_FILTER_NTUPLE,
9380                                 RTE_ETH_FILTER_DELETE,
9381                                 &filter);
9382         if (ret < 0)
9383                 printf("5tuple filter programming error: (%s)\n",
9384                         strerror(-ret));
9385 }
9386
9387 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9388         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9389                                  filter, "5tuple_filter");
9390 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9391         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9392                                 port_id, UINT16);
9393 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9394         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9395                                  ops, "add#del");
9396 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9397         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9398                                 dst_ip, "dst_ip");
9399 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9400         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9401                                 dst_ip_value);
9402 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9403         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9404                                 src_ip, "src_ip");
9405 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9406         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9407                                 src_ip_value);
9408 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9409         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9410                                 dst_port, "dst_port");
9411 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9412         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9413                                 dst_port_value, UINT16);
9414 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9415         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9416                                 src_port, "src_port");
9417 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9418         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9419                                 src_port_value, UINT16);
9420 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9421         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9422                                 protocol, "protocol");
9423 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9424         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9425                                 protocol_value, UINT8);
9426 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9427         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9428                                 mask, "mask");
9429 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9430         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9431                                 mask_value, INT8);
9432 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9433         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9434                                 tcp_flags, "tcp_flags");
9435 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9436         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9437                                 tcp_flags_value, UINT8);
9438 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9439         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9440                                 priority, "priority");
9441 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9442         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9443                                 priority_value, UINT8);
9444 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9445         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9446                                 queue, "queue");
9447 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9448         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9449                                 queue_id, UINT16);
9450
9451 cmdline_parse_inst_t cmd_5tuple_filter = {
9452         .f = cmd_5tuple_filter_parsed,
9453         .data = NULL,
9454         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9455                 "src_ip <value> dst_port <value> src_port <value> "
9456                 "protocol <value>  mask <value> tcp_flags <value> "
9457                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9458         .tokens = {
9459                 (void *)&cmd_5tuple_filter_filter,
9460                 (void *)&cmd_5tuple_filter_port_id,
9461                 (void *)&cmd_5tuple_filter_ops,
9462                 (void *)&cmd_5tuple_filter_dst_ip,
9463                 (void *)&cmd_5tuple_filter_dst_ip_value,
9464                 (void *)&cmd_5tuple_filter_src_ip,
9465                 (void *)&cmd_5tuple_filter_src_ip_value,
9466                 (void *)&cmd_5tuple_filter_dst_port,
9467                 (void *)&cmd_5tuple_filter_dst_port_value,
9468                 (void *)&cmd_5tuple_filter_src_port,
9469                 (void *)&cmd_5tuple_filter_src_port_value,
9470                 (void *)&cmd_5tuple_filter_protocol,
9471                 (void *)&cmd_5tuple_filter_protocol_value,
9472                 (void *)&cmd_5tuple_filter_mask,
9473                 (void *)&cmd_5tuple_filter_mask_value,
9474                 (void *)&cmd_5tuple_filter_tcp_flags,
9475                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9476                 (void *)&cmd_5tuple_filter_priority,
9477                 (void *)&cmd_5tuple_filter_priority_value,
9478                 (void *)&cmd_5tuple_filter_queue,
9479                 (void *)&cmd_5tuple_filter_queue_id,
9480                 NULL,
9481         },
9482 };
9483
9484 /* *** ADD/REMOVE A flex FILTER *** */
9485 struct cmd_flex_filter_result {
9486         cmdline_fixed_string_t filter;
9487         cmdline_fixed_string_t ops;
9488         portid_t port_id;
9489         cmdline_fixed_string_t len;
9490         uint8_t len_value;
9491         cmdline_fixed_string_t bytes;
9492         cmdline_fixed_string_t bytes_value;
9493         cmdline_fixed_string_t mask;
9494         cmdline_fixed_string_t mask_value;
9495         cmdline_fixed_string_t priority;
9496         uint8_t priority_value;
9497         cmdline_fixed_string_t queue;
9498         uint16_t queue_id;
9499 };
9500
9501 static int xdigit2val(unsigned char c)
9502 {
9503         int val;
9504         if (isdigit(c))
9505                 val = c - '0';
9506         else if (isupper(c))
9507                 val = c - 'A' + 10;
9508         else
9509                 val = c - 'a' + 10;
9510         return val;
9511 }
9512
9513 static void
9514 cmd_flex_filter_parsed(void *parsed_result,
9515                           __attribute__((unused)) struct cmdline *cl,
9516                           __attribute__((unused)) void *data)
9517 {
9518         int ret = 0;
9519         struct rte_eth_flex_filter filter;
9520         struct cmd_flex_filter_result *res = parsed_result;
9521         char *bytes_ptr, *mask_ptr;
9522         uint16_t len, i, j = 0;
9523         char c;
9524         int val;
9525         uint8_t byte = 0;
9526
9527         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9528                 printf("the len exceed the max length 128\n");
9529                 return;
9530         }
9531         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9532         filter.len = res->len_value;
9533         filter.priority = res->priority_value;
9534         filter.queue = res->queue_id;
9535         bytes_ptr = res->bytes_value;
9536         mask_ptr = res->mask_value;
9537
9538          /* translate bytes string to array. */
9539         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9540                 (bytes_ptr[1] == 'X')))
9541                 bytes_ptr += 2;
9542         len = strnlen(bytes_ptr, res->len_value * 2);
9543         if (len == 0 || (len % 8 != 0)) {
9544                 printf("please check len and bytes input\n");
9545                 return;
9546         }
9547         for (i = 0; i < len; i++) {
9548                 c = bytes_ptr[i];
9549                 if (isxdigit(c) == 0) {
9550                         /* invalid characters. */
9551                         printf("invalid input\n");
9552                         return;
9553                 }
9554                 val = xdigit2val(c);
9555                 if (i % 2) {
9556                         byte |= val;
9557                         filter.bytes[j] = byte;
9558                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9559                         j++;
9560                         byte = 0;
9561                 } else
9562                         byte |= val << 4;
9563         }
9564         printf("\n");
9565          /* translate mask string to uint8_t array. */
9566         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9567                 (mask_ptr[1] == 'X')))
9568                 mask_ptr += 2;
9569         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9570         if (len == 0) {
9571                 printf("invalid input\n");
9572                 return;
9573         }
9574         j = 0;
9575         byte = 0;
9576         for (i = 0; i < len; i++) {
9577                 c = mask_ptr[i];
9578                 if (isxdigit(c) == 0) {
9579                         /* invalid characters. */
9580                         printf("invalid input\n");
9581                         return;
9582                 }
9583                 val = xdigit2val(c);
9584                 if (i % 2) {
9585                         byte |= val;
9586                         filter.mask[j] = byte;
9587                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9588                         j++;
9589                         byte = 0;
9590                 } else
9591                         byte |= val << 4;
9592         }
9593         printf("\n");
9594
9595         if (!strcmp(res->ops, "add"))
9596                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9597                                 RTE_ETH_FILTER_FLEXIBLE,
9598                                 RTE_ETH_FILTER_ADD,
9599                                 &filter);
9600         else
9601                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9602                                 RTE_ETH_FILTER_FLEXIBLE,
9603                                 RTE_ETH_FILTER_DELETE,
9604                                 &filter);
9605
9606         if (ret < 0)
9607                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9608 }
9609
9610 cmdline_parse_token_string_t cmd_flex_filter_filter =
9611         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9612                                 filter, "flex_filter");
9613 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9614         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9615                                 port_id, UINT16);
9616 cmdline_parse_token_string_t cmd_flex_filter_ops =
9617         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9618                                 ops, "add#del");
9619 cmdline_parse_token_string_t cmd_flex_filter_len =
9620         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9621                                 len, "len");
9622 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9623         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9624                                 len_value, UINT8);
9625 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9626         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9627                                 bytes, "bytes");
9628 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9629         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9630                                 bytes_value, NULL);
9631 cmdline_parse_token_string_t cmd_flex_filter_mask =
9632         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9633                                 mask, "mask");
9634 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9635         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9636                                 mask_value, NULL);
9637 cmdline_parse_token_string_t cmd_flex_filter_priority =
9638         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9639                                 priority, "priority");
9640 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9641         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9642                                 priority_value, UINT8);
9643 cmdline_parse_token_string_t cmd_flex_filter_queue =
9644         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9645                                 queue, "queue");
9646 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9647         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9648                                 queue_id, UINT16);
9649 cmdline_parse_inst_t cmd_flex_filter = {
9650         .f = cmd_flex_filter_parsed,
9651         .data = NULL,
9652         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9653                 "<value> mask <value> priority <value> queue <queue_id>: "
9654                 "Add/Del a flex filter",
9655         .tokens = {
9656                 (void *)&cmd_flex_filter_filter,
9657                 (void *)&cmd_flex_filter_port_id,
9658                 (void *)&cmd_flex_filter_ops,
9659                 (void *)&cmd_flex_filter_len,
9660                 (void *)&cmd_flex_filter_len_value,
9661                 (void *)&cmd_flex_filter_bytes,
9662                 (void *)&cmd_flex_filter_bytes_value,
9663                 (void *)&cmd_flex_filter_mask,
9664                 (void *)&cmd_flex_filter_mask_value,
9665                 (void *)&cmd_flex_filter_priority,
9666                 (void *)&cmd_flex_filter_priority_value,
9667                 (void *)&cmd_flex_filter_queue,
9668                 (void *)&cmd_flex_filter_queue_id,
9669                 NULL,
9670         },
9671 };
9672
9673 /* *** Filters Control *** */
9674
9675 /* *** deal with ethertype filter *** */
9676 struct cmd_ethertype_filter_result {
9677         cmdline_fixed_string_t filter;
9678         portid_t port_id;
9679         cmdline_fixed_string_t ops;
9680         cmdline_fixed_string_t mac;
9681         struct ether_addr mac_addr;
9682         cmdline_fixed_string_t ethertype;
9683         uint16_t ethertype_value;
9684         cmdline_fixed_string_t drop;
9685         cmdline_fixed_string_t queue;
9686         uint16_t  queue_id;
9687 };
9688
9689 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9690         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9691                                  filter, "ethertype_filter");
9692 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9693         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9694                               port_id, UINT16);
9695 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9696         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9697                                  ops, "add#del");
9698 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9699         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9700                                  mac, "mac_addr#mac_ignr");
9701 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9702         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9703                                      mac_addr);
9704 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9705         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9706                                  ethertype, "ethertype");
9707 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9708         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9709                               ethertype_value, UINT16);
9710 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9711         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9712                                  drop, "drop#fwd");
9713 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9714         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9715                                  queue, "queue");
9716 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9717         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9718                               queue_id, UINT16);
9719
9720 static void
9721 cmd_ethertype_filter_parsed(void *parsed_result,
9722                           __attribute__((unused)) struct cmdline *cl,
9723                           __attribute__((unused)) void *data)
9724 {
9725         struct cmd_ethertype_filter_result *res = parsed_result;
9726         struct rte_eth_ethertype_filter filter;
9727         int ret = 0;
9728
9729         ret = rte_eth_dev_filter_supported(res->port_id,
9730                         RTE_ETH_FILTER_ETHERTYPE);
9731         if (ret < 0) {
9732                 printf("ethertype filter is not supported on port %u.\n",
9733                         res->port_id);
9734                 return;
9735         }
9736
9737         memset(&filter, 0, sizeof(filter));
9738         if (!strcmp(res->mac, "mac_addr")) {
9739                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9740                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9741                         sizeof(struct ether_addr));
9742         }
9743         if (!strcmp(res->drop, "drop"))
9744                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9745         filter.ether_type = res->ethertype_value;
9746         filter.queue = res->queue_id;
9747
9748         if (!strcmp(res->ops, "add"))
9749                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9750                                 RTE_ETH_FILTER_ETHERTYPE,
9751                                 RTE_ETH_FILTER_ADD,
9752                                 &filter);
9753         else
9754                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9755                                 RTE_ETH_FILTER_ETHERTYPE,
9756                                 RTE_ETH_FILTER_DELETE,
9757                                 &filter);
9758         if (ret < 0)
9759                 printf("ethertype filter programming error: (%s)\n",
9760                         strerror(-ret));
9761 }
9762
9763 cmdline_parse_inst_t cmd_ethertype_filter = {
9764         .f = cmd_ethertype_filter_parsed,
9765         .data = NULL,
9766         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9767                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9768                 "Add or delete an ethertype filter entry",
9769         .tokens = {
9770                 (void *)&cmd_ethertype_filter_filter,
9771                 (void *)&cmd_ethertype_filter_port_id,
9772                 (void *)&cmd_ethertype_filter_ops,
9773                 (void *)&cmd_ethertype_filter_mac,
9774                 (void *)&cmd_ethertype_filter_mac_addr,
9775                 (void *)&cmd_ethertype_filter_ethertype,
9776                 (void *)&cmd_ethertype_filter_ethertype_value,
9777                 (void *)&cmd_ethertype_filter_drop,
9778                 (void *)&cmd_ethertype_filter_queue,
9779                 (void *)&cmd_ethertype_filter_queue_id,
9780                 NULL,
9781         },
9782 };
9783
9784 /* *** deal with flow director filter *** */
9785 struct cmd_flow_director_result {
9786         cmdline_fixed_string_t flow_director_filter;
9787         portid_t port_id;
9788         cmdline_fixed_string_t mode;
9789         cmdline_fixed_string_t mode_value;
9790         cmdline_fixed_string_t ops;
9791         cmdline_fixed_string_t flow;
9792         cmdline_fixed_string_t flow_type;
9793         cmdline_fixed_string_t ether;
9794         uint16_t ether_type;
9795         cmdline_fixed_string_t src;
9796         cmdline_ipaddr_t ip_src;
9797         uint16_t port_src;
9798         cmdline_fixed_string_t dst;
9799         cmdline_ipaddr_t ip_dst;
9800         uint16_t port_dst;
9801         cmdline_fixed_string_t verify_tag;
9802         uint32_t verify_tag_value;
9803         cmdline_ipaddr_t tos;
9804         uint8_t tos_value;
9805         cmdline_ipaddr_t proto;
9806         uint8_t proto_value;
9807         cmdline_ipaddr_t ttl;
9808         uint8_t ttl_value;
9809         cmdline_fixed_string_t vlan;
9810         uint16_t vlan_value;
9811         cmdline_fixed_string_t flexbytes;
9812         cmdline_fixed_string_t flexbytes_value;
9813         cmdline_fixed_string_t pf_vf;
9814         cmdline_fixed_string_t drop;
9815         cmdline_fixed_string_t queue;
9816         uint16_t  queue_id;
9817         cmdline_fixed_string_t fd_id;
9818         uint32_t  fd_id_value;
9819         cmdline_fixed_string_t mac;
9820         struct ether_addr mac_addr;
9821         cmdline_fixed_string_t tunnel;
9822         cmdline_fixed_string_t tunnel_type;
9823         cmdline_fixed_string_t tunnel_id;
9824         uint32_t tunnel_id_value;
9825 };
9826
9827 static inline int
9828 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9829 {
9830         char s[256];
9831         const char *p, *p0 = q_arg;
9832         char *end;
9833         unsigned long int_fld;
9834         char *str_fld[max_num];
9835         int i;
9836         unsigned size;
9837         int ret = -1;
9838
9839         p = strchr(p0, '(');
9840         if (p == NULL)
9841                 return -1;
9842         ++p;
9843         p0 = strchr(p, ')');
9844         if (p0 == NULL)
9845                 return -1;
9846
9847         size = p0 - p;
9848         if (size >= sizeof(s))
9849                 return -1;
9850
9851         snprintf(s, sizeof(s), "%.*s", size, p);
9852         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9853         if (ret < 0 || ret > max_num)
9854                 return -1;
9855         for (i = 0; i < ret; i++) {
9856                 errno = 0;
9857                 int_fld = strtoul(str_fld[i], &end, 0);
9858                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9859                         return -1;
9860                 flexbytes[i] = (uint8_t)int_fld;
9861         }
9862         return ret;
9863 }
9864
9865 static uint16_t
9866 str2flowtype(char *string)
9867 {
9868         uint8_t i = 0;
9869         static const struct {
9870                 char str[32];
9871                 uint16_t type;
9872         } flowtype_str[] = {
9873                 {"raw", RTE_ETH_FLOW_RAW},
9874                 {"ipv4", RTE_ETH_FLOW_IPV4},
9875                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9876                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9877                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9878                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9879                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9880                 {"ipv6", RTE_ETH_FLOW_IPV6},
9881                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9882                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9883                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9884                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9885                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9886                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9887         };
9888
9889         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9890                 if (!strcmp(flowtype_str[i].str, string))
9891                         return flowtype_str[i].type;
9892         }
9893
9894         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9895                 return (uint16_t)atoi(string);
9896
9897         return RTE_ETH_FLOW_UNKNOWN;
9898 }
9899
9900 static enum rte_eth_fdir_tunnel_type
9901 str2fdir_tunneltype(char *string)
9902 {
9903         uint8_t i = 0;
9904
9905         static const struct {
9906                 char str[32];
9907                 enum rte_eth_fdir_tunnel_type type;
9908         } tunneltype_str[] = {
9909                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9910                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9911         };
9912
9913         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9914                 if (!strcmp(tunneltype_str[i].str, string))
9915                         return tunneltype_str[i].type;
9916         }
9917         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9918 }
9919
9920 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9921 do { \
9922         if ((ip_addr).family == AF_INET) \
9923                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9924         else { \
9925                 printf("invalid parameter.\n"); \
9926                 return; \
9927         } \
9928 } while (0)
9929
9930 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9931 do { \
9932         if ((ip_addr).family == AF_INET6) \
9933                 rte_memcpy(&(ip), \
9934                                  &((ip_addr).addr.ipv6), \
9935                                  sizeof(struct in6_addr)); \
9936         else { \
9937                 printf("invalid parameter.\n"); \
9938                 return; \
9939         } \
9940 } while (0)
9941
9942 static void
9943 cmd_flow_director_filter_parsed(void *parsed_result,
9944                           __attribute__((unused)) struct cmdline *cl,
9945                           __attribute__((unused)) void *data)
9946 {
9947         struct cmd_flow_director_result *res = parsed_result;
9948         struct rte_eth_fdir_filter entry;
9949         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9950         char *end;
9951         unsigned long vf_id;
9952         int ret = 0;
9953
9954         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9955         if (ret < 0) {
9956                 printf("flow director is not supported on port %u.\n",
9957                         res->port_id);
9958                 return;
9959         }
9960         memset(flexbytes, 0, sizeof(flexbytes));
9961         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9962
9963         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9964                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9965                         printf("Please set mode to MAC-VLAN.\n");
9966                         return;
9967                 }
9968         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9969                 if (strcmp(res->mode_value, "Tunnel")) {
9970                         printf("Please set mode to Tunnel.\n");
9971                         return;
9972                 }
9973         } else {
9974                 if (strcmp(res->mode_value, "IP")) {
9975                         printf("Please set mode to IP.\n");
9976                         return;
9977                 }
9978                 entry.input.flow_type = str2flowtype(res->flow_type);
9979         }
9980
9981         ret = parse_flexbytes(res->flexbytes_value,
9982                                         flexbytes,
9983                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9984         if (ret < 0) {
9985                 printf("error: Cannot parse flexbytes input.\n");
9986                 return;
9987         }
9988
9989         switch (entry.input.flow_type) {
9990         case RTE_ETH_FLOW_FRAG_IPV4:
9991         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9992                 entry.input.flow.ip4_flow.proto = res->proto_value;
9993                 /* fall-through */
9994         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9995         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9996                 IPV4_ADDR_TO_UINT(res->ip_dst,
9997                         entry.input.flow.ip4_flow.dst_ip);
9998                 IPV4_ADDR_TO_UINT(res->ip_src,
9999                         entry.input.flow.ip4_flow.src_ip);
10000                 entry.input.flow.ip4_flow.tos = res->tos_value;
10001                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10002                 /* need convert to big endian. */
10003                 entry.input.flow.udp4_flow.dst_port =
10004                                 rte_cpu_to_be_16(res->port_dst);
10005                 entry.input.flow.udp4_flow.src_port =
10006                                 rte_cpu_to_be_16(res->port_src);
10007                 break;
10008         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10009                 IPV4_ADDR_TO_UINT(res->ip_dst,
10010                         entry.input.flow.sctp4_flow.ip.dst_ip);
10011                 IPV4_ADDR_TO_UINT(res->ip_src,
10012                         entry.input.flow.sctp4_flow.ip.src_ip);
10013                 entry.input.flow.ip4_flow.tos = res->tos_value;
10014                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10015                 /* need convert to big endian. */
10016                 entry.input.flow.sctp4_flow.dst_port =
10017                                 rte_cpu_to_be_16(res->port_dst);
10018                 entry.input.flow.sctp4_flow.src_port =
10019                                 rte_cpu_to_be_16(res->port_src);
10020                 entry.input.flow.sctp4_flow.verify_tag =
10021                                 rte_cpu_to_be_32(res->verify_tag_value);
10022                 break;
10023         case RTE_ETH_FLOW_FRAG_IPV6:
10024         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10025                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10026                 /* fall-through */
10027         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10028         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10029                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10030                         entry.input.flow.ipv6_flow.dst_ip);
10031                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10032                         entry.input.flow.ipv6_flow.src_ip);
10033                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10034                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10035                 /* need convert to big endian. */
10036                 entry.input.flow.udp6_flow.dst_port =
10037                                 rte_cpu_to_be_16(res->port_dst);
10038                 entry.input.flow.udp6_flow.src_port =
10039                                 rte_cpu_to_be_16(res->port_src);
10040                 break;
10041         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10042                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10043                         entry.input.flow.sctp6_flow.ip.dst_ip);
10044                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10045                         entry.input.flow.sctp6_flow.ip.src_ip);
10046                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10047                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10048                 /* need convert to big endian. */
10049                 entry.input.flow.sctp6_flow.dst_port =
10050                                 rte_cpu_to_be_16(res->port_dst);
10051                 entry.input.flow.sctp6_flow.src_port =
10052                                 rte_cpu_to_be_16(res->port_src);
10053                 entry.input.flow.sctp6_flow.verify_tag =
10054                                 rte_cpu_to_be_32(res->verify_tag_value);
10055                 break;
10056         case RTE_ETH_FLOW_L2_PAYLOAD:
10057                 entry.input.flow.l2_flow.ether_type =
10058                         rte_cpu_to_be_16(res->ether_type);
10059                 break;
10060         default:
10061                 break;
10062         }
10063
10064         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10065                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10066                                  &res->mac_addr,
10067                                  sizeof(struct ether_addr));
10068
10069         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10070                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10071                                  &res->mac_addr,
10072                                  sizeof(struct ether_addr));
10073                 entry.input.flow.tunnel_flow.tunnel_type =
10074                         str2fdir_tunneltype(res->tunnel_type);
10075                 entry.input.flow.tunnel_flow.tunnel_id =
10076                         rte_cpu_to_be_32(res->tunnel_id_value);
10077         }
10078
10079         rte_memcpy(entry.input.flow_ext.flexbytes,
10080                    flexbytes,
10081                    RTE_ETH_FDIR_MAX_FLEXLEN);
10082
10083         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10084
10085         entry.action.flex_off = 0;  /*use 0 by default */
10086         if (!strcmp(res->drop, "drop"))
10087                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10088         else
10089                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10090
10091         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10092             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10093                 if (!strcmp(res->pf_vf, "pf"))
10094                         entry.input.flow_ext.is_vf = 0;
10095                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10096                         struct rte_eth_dev_info dev_info;
10097
10098                         memset(&dev_info, 0, sizeof(dev_info));
10099                         rte_eth_dev_info_get(res->port_id, &dev_info);
10100                         errno = 0;
10101                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10102                         if (errno != 0 || *end != '\0' ||
10103                             vf_id >= dev_info.max_vfs) {
10104                                 printf("invalid parameter %s.\n", res->pf_vf);
10105                                 return;
10106                         }
10107                         entry.input.flow_ext.is_vf = 1;
10108                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10109                 } else {
10110                         printf("invalid parameter %s.\n", res->pf_vf);
10111                         return;
10112                 }
10113         }
10114
10115         /* set to report FD ID by default */
10116         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10117         entry.action.rx_queue = res->queue_id;
10118         entry.soft_id = res->fd_id_value;
10119         if (!strcmp(res->ops, "add"))
10120                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10121                                              RTE_ETH_FILTER_ADD, &entry);
10122         else if (!strcmp(res->ops, "del"))
10123                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10124                                              RTE_ETH_FILTER_DELETE, &entry);
10125         else
10126                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10127                                              RTE_ETH_FILTER_UPDATE, &entry);
10128         if (ret < 0)
10129                 printf("flow director programming error: (%s)\n",
10130                         strerror(-ret));
10131 }
10132
10133 cmdline_parse_token_string_t cmd_flow_director_filter =
10134         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10135                                  flow_director_filter, "flow_director_filter");
10136 cmdline_parse_token_num_t cmd_flow_director_port_id =
10137         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10138                               port_id, UINT16);
10139 cmdline_parse_token_string_t cmd_flow_director_ops =
10140         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10141                                  ops, "add#del#update");
10142 cmdline_parse_token_string_t cmd_flow_director_flow =
10143         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10144                                  flow, "flow");
10145 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10146         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10147                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10148                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
10149 cmdline_parse_token_string_t cmd_flow_director_ether =
10150         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10151                                  ether, "ether");
10152 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10153         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10154                               ether_type, UINT16);
10155 cmdline_parse_token_string_t cmd_flow_director_src =
10156         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10157                                  src, "src");
10158 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10159         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10160                                  ip_src);
10161 cmdline_parse_token_num_t cmd_flow_director_port_src =
10162         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10163                               port_src, UINT16);
10164 cmdline_parse_token_string_t cmd_flow_director_dst =
10165         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10166                                  dst, "dst");
10167 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10168         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10169                                  ip_dst);
10170 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10171         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10172                               port_dst, UINT16);
10173 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10174         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10175                                   verify_tag, "verify_tag");
10176 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10177         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10178                               verify_tag_value, UINT32);
10179 cmdline_parse_token_string_t cmd_flow_director_tos =
10180         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10181                                  tos, "tos");
10182 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10183         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10184                               tos_value, UINT8);
10185 cmdline_parse_token_string_t cmd_flow_director_proto =
10186         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10187                                  proto, "proto");
10188 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10189         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10190                               proto_value, UINT8);
10191 cmdline_parse_token_string_t cmd_flow_director_ttl =
10192         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10193                                  ttl, "ttl");
10194 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10195         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10196                               ttl_value, UINT8);
10197 cmdline_parse_token_string_t cmd_flow_director_vlan =
10198         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10199                                  vlan, "vlan");
10200 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10201         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10202                               vlan_value, UINT16);
10203 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10204         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10205                                  flexbytes, "flexbytes");
10206 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10207         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10208                               flexbytes_value, NULL);
10209 cmdline_parse_token_string_t cmd_flow_director_drop =
10210         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10211                                  drop, "drop#fwd");
10212 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10213         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10214                               pf_vf, NULL);
10215 cmdline_parse_token_string_t cmd_flow_director_queue =
10216         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10217                                  queue, "queue");
10218 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10219         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10220                               queue_id, UINT16);
10221 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10222         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10223                                  fd_id, "fd_id");
10224 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10225         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10226                               fd_id_value, UINT32);
10227
10228 cmdline_parse_token_string_t cmd_flow_director_mode =
10229         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10230                                  mode, "mode");
10231 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10232         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10233                                  mode_value, "IP");
10234 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10235         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10236                                  mode_value, "MAC-VLAN");
10237 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10238         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10239                                  mode_value, "Tunnel");
10240 cmdline_parse_token_string_t cmd_flow_director_mac =
10241         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10242                                  mac, "mac");
10243 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10244         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10245                                     mac_addr);
10246 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10247         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10248                                  tunnel, "tunnel");
10249 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10250         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10251                                  tunnel_type, "NVGRE#VxLAN");
10252 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10253         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10254                                  tunnel_id, "tunnel-id");
10255 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10256         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10257                               tunnel_id_value, UINT32);
10258
10259 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10260         .f = cmd_flow_director_filter_parsed,
10261         .data = NULL,
10262         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10263                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10264                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10265                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10266                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10267                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10268                 "fd_id <fd_id_value>: "
10269                 "Add or delete an ip flow director entry on NIC",
10270         .tokens = {
10271                 (void *)&cmd_flow_director_filter,
10272                 (void *)&cmd_flow_director_port_id,
10273                 (void *)&cmd_flow_director_mode,
10274                 (void *)&cmd_flow_director_mode_ip,
10275                 (void *)&cmd_flow_director_ops,
10276                 (void *)&cmd_flow_director_flow,
10277                 (void *)&cmd_flow_director_flow_type,
10278                 (void *)&cmd_flow_director_src,
10279                 (void *)&cmd_flow_director_ip_src,
10280                 (void *)&cmd_flow_director_dst,
10281                 (void *)&cmd_flow_director_ip_dst,
10282                 (void *)&cmd_flow_director_tos,
10283                 (void *)&cmd_flow_director_tos_value,
10284                 (void *)&cmd_flow_director_proto,
10285                 (void *)&cmd_flow_director_proto_value,
10286                 (void *)&cmd_flow_director_ttl,
10287                 (void *)&cmd_flow_director_ttl_value,
10288                 (void *)&cmd_flow_director_vlan,
10289                 (void *)&cmd_flow_director_vlan_value,
10290                 (void *)&cmd_flow_director_flexbytes,
10291                 (void *)&cmd_flow_director_flexbytes_value,
10292                 (void *)&cmd_flow_director_drop,
10293                 (void *)&cmd_flow_director_pf_vf,
10294                 (void *)&cmd_flow_director_queue,
10295                 (void *)&cmd_flow_director_queue_id,
10296                 (void *)&cmd_flow_director_fd_id,
10297                 (void *)&cmd_flow_director_fd_id_value,
10298                 NULL,
10299         },
10300 };
10301
10302 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10303         .f = cmd_flow_director_filter_parsed,
10304         .data = NULL,
10305         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10306                 "director entry on NIC",
10307         .tokens = {
10308                 (void *)&cmd_flow_director_filter,
10309                 (void *)&cmd_flow_director_port_id,
10310                 (void *)&cmd_flow_director_mode,
10311                 (void *)&cmd_flow_director_mode_ip,
10312                 (void *)&cmd_flow_director_ops,
10313                 (void *)&cmd_flow_director_flow,
10314                 (void *)&cmd_flow_director_flow_type,
10315                 (void *)&cmd_flow_director_src,
10316                 (void *)&cmd_flow_director_ip_src,
10317                 (void *)&cmd_flow_director_port_src,
10318                 (void *)&cmd_flow_director_dst,
10319                 (void *)&cmd_flow_director_ip_dst,
10320                 (void *)&cmd_flow_director_port_dst,
10321                 (void *)&cmd_flow_director_tos,
10322                 (void *)&cmd_flow_director_tos_value,
10323                 (void *)&cmd_flow_director_ttl,
10324                 (void *)&cmd_flow_director_ttl_value,
10325                 (void *)&cmd_flow_director_vlan,
10326                 (void *)&cmd_flow_director_vlan_value,
10327                 (void *)&cmd_flow_director_flexbytes,
10328                 (void *)&cmd_flow_director_flexbytes_value,
10329                 (void *)&cmd_flow_director_drop,
10330                 (void *)&cmd_flow_director_pf_vf,
10331                 (void *)&cmd_flow_director_queue,
10332                 (void *)&cmd_flow_director_queue_id,
10333                 (void *)&cmd_flow_director_fd_id,
10334                 (void *)&cmd_flow_director_fd_id_value,
10335                 NULL,
10336         },
10337 };
10338
10339 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10340         .f = cmd_flow_director_filter_parsed,
10341         .data = NULL,
10342         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10343                 "director entry on NIC",
10344         .tokens = {
10345                 (void *)&cmd_flow_director_filter,
10346                 (void *)&cmd_flow_director_port_id,
10347                 (void *)&cmd_flow_director_mode,
10348                 (void *)&cmd_flow_director_mode_ip,
10349                 (void *)&cmd_flow_director_ops,
10350                 (void *)&cmd_flow_director_flow,
10351                 (void *)&cmd_flow_director_flow_type,
10352                 (void *)&cmd_flow_director_src,
10353                 (void *)&cmd_flow_director_ip_src,
10354                 (void *)&cmd_flow_director_port_dst,
10355                 (void *)&cmd_flow_director_dst,
10356                 (void *)&cmd_flow_director_ip_dst,
10357                 (void *)&cmd_flow_director_port_dst,
10358                 (void *)&cmd_flow_director_verify_tag,
10359                 (void *)&cmd_flow_director_verify_tag_value,
10360                 (void *)&cmd_flow_director_tos,
10361                 (void *)&cmd_flow_director_tos_value,
10362                 (void *)&cmd_flow_director_ttl,
10363                 (void *)&cmd_flow_director_ttl_value,
10364                 (void *)&cmd_flow_director_vlan,
10365                 (void *)&cmd_flow_director_vlan_value,
10366                 (void *)&cmd_flow_director_flexbytes,
10367                 (void *)&cmd_flow_director_flexbytes_value,
10368                 (void *)&cmd_flow_director_drop,
10369                 (void *)&cmd_flow_director_pf_vf,
10370                 (void *)&cmd_flow_director_queue,
10371                 (void *)&cmd_flow_director_queue_id,
10372                 (void *)&cmd_flow_director_fd_id,
10373                 (void *)&cmd_flow_director_fd_id_value,
10374                 NULL,
10375         },
10376 };
10377
10378 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10379         .f = cmd_flow_director_filter_parsed,
10380         .data = NULL,
10381         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10382                 "director entry on NIC",
10383         .tokens = {
10384                 (void *)&cmd_flow_director_filter,
10385                 (void *)&cmd_flow_director_port_id,
10386                 (void *)&cmd_flow_director_mode,
10387                 (void *)&cmd_flow_director_mode_ip,
10388                 (void *)&cmd_flow_director_ops,
10389                 (void *)&cmd_flow_director_flow,
10390                 (void *)&cmd_flow_director_flow_type,
10391                 (void *)&cmd_flow_director_ether,
10392                 (void *)&cmd_flow_director_ether_type,
10393                 (void *)&cmd_flow_director_flexbytes,
10394                 (void *)&cmd_flow_director_flexbytes_value,
10395                 (void *)&cmd_flow_director_drop,
10396                 (void *)&cmd_flow_director_pf_vf,
10397                 (void *)&cmd_flow_director_queue,
10398                 (void *)&cmd_flow_director_queue_id,
10399                 (void *)&cmd_flow_director_fd_id,
10400                 (void *)&cmd_flow_director_fd_id_value,
10401                 NULL,
10402         },
10403 };
10404
10405 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10406         .f = cmd_flow_director_filter_parsed,
10407         .data = NULL,
10408         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10409                 "director entry on NIC",
10410         .tokens = {
10411                 (void *)&cmd_flow_director_filter,
10412                 (void *)&cmd_flow_director_port_id,
10413                 (void *)&cmd_flow_director_mode,
10414                 (void *)&cmd_flow_director_mode_mac_vlan,
10415                 (void *)&cmd_flow_director_ops,
10416                 (void *)&cmd_flow_director_mac,
10417                 (void *)&cmd_flow_director_mac_addr,
10418                 (void *)&cmd_flow_director_vlan,
10419                 (void *)&cmd_flow_director_vlan_value,
10420                 (void *)&cmd_flow_director_flexbytes,
10421                 (void *)&cmd_flow_director_flexbytes_value,
10422                 (void *)&cmd_flow_director_drop,
10423                 (void *)&cmd_flow_director_queue,
10424                 (void *)&cmd_flow_director_queue_id,
10425                 (void *)&cmd_flow_director_fd_id,
10426                 (void *)&cmd_flow_director_fd_id_value,
10427                 NULL,
10428         },
10429 };
10430
10431 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10432         .f = cmd_flow_director_filter_parsed,
10433         .data = NULL,
10434         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10435                 "director entry on NIC",
10436         .tokens = {
10437                 (void *)&cmd_flow_director_filter,
10438                 (void *)&cmd_flow_director_port_id,
10439                 (void *)&cmd_flow_director_mode,
10440                 (void *)&cmd_flow_director_mode_tunnel,
10441                 (void *)&cmd_flow_director_ops,
10442                 (void *)&cmd_flow_director_mac,
10443                 (void *)&cmd_flow_director_mac_addr,
10444                 (void *)&cmd_flow_director_vlan,
10445                 (void *)&cmd_flow_director_vlan_value,
10446                 (void *)&cmd_flow_director_tunnel,
10447                 (void *)&cmd_flow_director_tunnel_type,
10448                 (void *)&cmd_flow_director_tunnel_id,
10449                 (void *)&cmd_flow_director_tunnel_id_value,
10450                 (void *)&cmd_flow_director_flexbytes,
10451                 (void *)&cmd_flow_director_flexbytes_value,
10452                 (void *)&cmd_flow_director_drop,
10453                 (void *)&cmd_flow_director_queue,
10454                 (void *)&cmd_flow_director_queue_id,
10455                 (void *)&cmd_flow_director_fd_id,
10456                 (void *)&cmd_flow_director_fd_id_value,
10457                 NULL,
10458         },
10459 };
10460
10461 struct cmd_flush_flow_director_result {
10462         cmdline_fixed_string_t flush_flow_director;
10463         portid_t port_id;
10464 };
10465
10466 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10467         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10468                                  flush_flow_director, "flush_flow_director");
10469 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10470         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10471                               port_id, UINT16);
10472
10473 static void
10474 cmd_flush_flow_director_parsed(void *parsed_result,
10475                           __attribute__((unused)) struct cmdline *cl,
10476                           __attribute__((unused)) void *data)
10477 {
10478         struct cmd_flow_director_result *res = parsed_result;
10479         int ret = 0;
10480
10481         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10482         if (ret < 0) {
10483                 printf("flow director is not supported on port %u.\n",
10484                         res->port_id);
10485                 return;
10486         }
10487
10488         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10489                         RTE_ETH_FILTER_FLUSH, NULL);
10490         if (ret < 0)
10491                 printf("flow director table flushing error: (%s)\n",
10492                         strerror(-ret));
10493 }
10494
10495 cmdline_parse_inst_t cmd_flush_flow_director = {
10496         .f = cmd_flush_flow_director_parsed,
10497         .data = NULL,
10498         .help_str = "flush_flow_director <port_id>: "
10499                 "Flush all flow director entries of a device on NIC",
10500         .tokens = {
10501                 (void *)&cmd_flush_flow_director_flush,
10502                 (void *)&cmd_flush_flow_director_port_id,
10503                 NULL,
10504         },
10505 };
10506
10507 /* *** deal with flow director mask *** */
10508 struct cmd_flow_director_mask_result {
10509         cmdline_fixed_string_t flow_director_mask;
10510         portid_t port_id;
10511         cmdline_fixed_string_t mode;
10512         cmdline_fixed_string_t mode_value;
10513         cmdline_fixed_string_t vlan;
10514         uint16_t vlan_mask;
10515         cmdline_fixed_string_t src_mask;
10516         cmdline_ipaddr_t ipv4_src;
10517         cmdline_ipaddr_t ipv6_src;
10518         uint16_t port_src;
10519         cmdline_fixed_string_t dst_mask;
10520         cmdline_ipaddr_t ipv4_dst;
10521         cmdline_ipaddr_t ipv6_dst;
10522         uint16_t port_dst;
10523         cmdline_fixed_string_t mac;
10524         uint8_t mac_addr_byte_mask;
10525         cmdline_fixed_string_t tunnel_id;
10526         uint32_t tunnel_id_mask;
10527         cmdline_fixed_string_t tunnel_type;
10528         uint8_t tunnel_type_mask;
10529 };
10530
10531 static void
10532 cmd_flow_director_mask_parsed(void *parsed_result,
10533                           __attribute__((unused)) struct cmdline *cl,
10534                           __attribute__((unused)) void *data)
10535 {
10536         struct cmd_flow_director_mask_result *res = parsed_result;
10537         struct rte_eth_fdir_masks *mask;
10538         struct rte_port *port;
10539
10540         if (res->port_id > nb_ports) {
10541                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10542                 return;
10543         }
10544
10545         port = &ports[res->port_id];
10546         /** Check if the port is not started **/
10547         if (port->port_status != RTE_PORT_STOPPED) {
10548                 printf("Please stop port %d first\n", res->port_id);
10549                 return;
10550         }
10551
10552         mask = &port->dev_conf.fdir_conf.mask;
10553
10554         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10555                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10556                         printf("Please set mode to MAC-VLAN.\n");
10557                         return;
10558                 }
10559
10560                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10561         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10562                 if (strcmp(res->mode_value, "Tunnel")) {
10563                         printf("Please set mode to Tunnel.\n");
10564                         return;
10565                 }
10566
10567                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10568                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10569                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10570                 mask->tunnel_type_mask = res->tunnel_type_mask;
10571         } else {
10572                 if (strcmp(res->mode_value, "IP")) {
10573                         printf("Please set mode to IP.\n");
10574                         return;
10575                 }
10576
10577                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10578                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10579                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10580                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10581                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10582                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10583                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10584         }
10585
10586         cmd_reconfig_device_queue(res->port_id, 1, 1);
10587 }
10588
10589 cmdline_parse_token_string_t cmd_flow_director_mask =
10590         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10591                                  flow_director_mask, "flow_director_mask");
10592 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10593         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10594                               port_id, UINT16);
10595 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10596         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10597                                  vlan, "vlan");
10598 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10599         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10600                               vlan_mask, UINT16);
10601 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10602         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10603                                  src_mask, "src_mask");
10604 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10605         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10606                                  ipv4_src);
10607 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10608         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10609                                  ipv6_src);
10610 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10611         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10612                               port_src, UINT16);
10613 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10614         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10615                                  dst_mask, "dst_mask");
10616 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10617         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10618                                  ipv4_dst);
10619 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10620         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10621                                  ipv6_dst);
10622 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10623         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10624                               port_dst, UINT16);
10625
10626 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10627         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10628                                  mode, "mode");
10629 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10630         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10631                                  mode_value, "IP");
10632 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10633         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10634                                  mode_value, "MAC-VLAN");
10635 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10636         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10637                                  mode_value, "Tunnel");
10638 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10639         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10640                                  mac, "mac");
10641 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10642         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10643                               mac_addr_byte_mask, UINT8);
10644 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10645         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10646                                  tunnel_type, "tunnel-type");
10647 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10648         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10649                               tunnel_type_mask, UINT8);
10650 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10651         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10652                                  tunnel_id, "tunnel-id");
10653 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10654         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10655                               tunnel_id_mask, UINT32);
10656
10657 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10658         .f = cmd_flow_director_mask_parsed,
10659         .data = NULL,
10660         .help_str = "flow_director_mask ... : "
10661                 "Set IP mode flow director's mask on NIC",
10662         .tokens = {
10663                 (void *)&cmd_flow_director_mask,
10664                 (void *)&cmd_flow_director_mask_port_id,
10665                 (void *)&cmd_flow_director_mask_mode,
10666                 (void *)&cmd_flow_director_mask_mode_ip,
10667                 (void *)&cmd_flow_director_mask_vlan,
10668                 (void *)&cmd_flow_director_mask_vlan_value,
10669                 (void *)&cmd_flow_director_mask_src,
10670                 (void *)&cmd_flow_director_mask_ipv4_src,
10671                 (void *)&cmd_flow_director_mask_ipv6_src,
10672                 (void *)&cmd_flow_director_mask_port_src,
10673                 (void *)&cmd_flow_director_mask_dst,
10674                 (void *)&cmd_flow_director_mask_ipv4_dst,
10675                 (void *)&cmd_flow_director_mask_ipv6_dst,
10676                 (void *)&cmd_flow_director_mask_port_dst,
10677                 NULL,
10678         },
10679 };
10680
10681 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10682         .f = cmd_flow_director_mask_parsed,
10683         .data = NULL,
10684         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10685                 "flow director's mask on NIC",
10686         .tokens = {
10687                 (void *)&cmd_flow_director_mask,
10688                 (void *)&cmd_flow_director_mask_port_id,
10689                 (void *)&cmd_flow_director_mask_mode,
10690                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10691                 (void *)&cmd_flow_director_mask_vlan,
10692                 (void *)&cmd_flow_director_mask_vlan_value,
10693                 NULL,
10694         },
10695 };
10696
10697 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10698         .f = cmd_flow_director_mask_parsed,
10699         .data = NULL,
10700         .help_str = "flow_director_mask ... : Set tunnel mode "
10701                 "flow director's mask on NIC",
10702         .tokens = {
10703                 (void *)&cmd_flow_director_mask,
10704                 (void *)&cmd_flow_director_mask_port_id,
10705                 (void *)&cmd_flow_director_mask_mode,
10706                 (void *)&cmd_flow_director_mask_mode_tunnel,
10707                 (void *)&cmd_flow_director_mask_vlan,
10708                 (void *)&cmd_flow_director_mask_vlan_value,
10709                 (void *)&cmd_flow_director_mask_mac,
10710                 (void *)&cmd_flow_director_mask_mac_value,
10711                 (void *)&cmd_flow_director_mask_tunnel_type,
10712                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10713                 (void *)&cmd_flow_director_mask_tunnel_id,
10714                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10715                 NULL,
10716         },
10717 };
10718
10719 /* *** deal with flow director mask on flexible payload *** */
10720 struct cmd_flow_director_flex_mask_result {
10721         cmdline_fixed_string_t flow_director_flexmask;
10722         portid_t port_id;
10723         cmdline_fixed_string_t flow;
10724         cmdline_fixed_string_t flow_type;
10725         cmdline_fixed_string_t mask;
10726 };
10727
10728 static void
10729 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10730                           __attribute__((unused)) struct cmdline *cl,
10731                           __attribute__((unused)) void *data)
10732 {
10733         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10734         struct rte_eth_fdir_info fdir_info;
10735         struct rte_eth_fdir_flex_mask flex_mask;
10736         struct rte_port *port;
10737         uint32_t flow_type_mask;
10738         uint16_t i;
10739         int ret;
10740
10741         if (res->port_id > nb_ports) {
10742                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10743                 return;
10744         }
10745
10746         port = &ports[res->port_id];
10747         /** Check if the port is not started **/
10748         if (port->port_status != RTE_PORT_STOPPED) {
10749                 printf("Please stop port %d first\n", res->port_id);
10750                 return;
10751         }
10752
10753         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10754         ret = parse_flexbytes(res->mask,
10755                         flex_mask.mask,
10756                         RTE_ETH_FDIR_MAX_FLEXLEN);
10757         if (ret < 0) {
10758                 printf("error: Cannot parse mask input.\n");
10759                 return;
10760         }
10761
10762         memset(&fdir_info, 0, sizeof(fdir_info));
10763         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10764                                 RTE_ETH_FILTER_INFO, &fdir_info);
10765         if (ret < 0) {
10766                 printf("Cannot get FDir filter info\n");
10767                 return;
10768         }
10769
10770         if (!strcmp(res->flow_type, "none")) {
10771                 /* means don't specify the flow type */
10772                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10773                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10774                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10775                                0, sizeof(struct rte_eth_fdir_flex_mask));
10776                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10777                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10778                                  &flex_mask,
10779                                  sizeof(struct rte_eth_fdir_flex_mask));
10780                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10781                 return;
10782         }
10783         flow_type_mask = fdir_info.flow_types_mask[0];
10784         if (!strcmp(res->flow_type, "all")) {
10785                 if (!flow_type_mask) {
10786                         printf("No flow type supported\n");
10787                         return;
10788                 }
10789                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10790                         if (flow_type_mask & (1 << i)) {
10791                                 flex_mask.flow_type = i;
10792                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10793                         }
10794                 }
10795                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10796                 return;
10797         }
10798         flex_mask.flow_type = str2flowtype(res->flow_type);
10799         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10800                 printf("Flow type %s not supported on port %d\n",
10801                                 res->flow_type, res->port_id);
10802                 return;
10803         }
10804         fdir_set_flex_mask(res->port_id, &flex_mask);
10805         cmd_reconfig_device_queue(res->port_id, 1, 1);
10806 }
10807
10808 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10809         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10810                                  flow_director_flexmask,
10811                                  "flow_director_flex_mask");
10812 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10813         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10814                               port_id, UINT16);
10815 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10816         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10817                                  flow, "flow");
10818 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10819         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10820                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10821                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10822 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10823         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10824                                  mask, NULL);
10825
10826 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10827         .f = cmd_flow_director_flex_mask_parsed,
10828         .data = NULL,
10829         .help_str = "flow_director_flex_mask ... : "
10830                 "Set flow director's flex mask on NIC",
10831         .tokens = {
10832                 (void *)&cmd_flow_director_flexmask,
10833                 (void *)&cmd_flow_director_flexmask_port_id,
10834                 (void *)&cmd_flow_director_flexmask_flow,
10835                 (void *)&cmd_flow_director_flexmask_flow_type,
10836                 (void *)&cmd_flow_director_flexmask_mask,
10837                 NULL,
10838         },
10839 };
10840
10841 /* *** deal with flow director flexible payload configuration *** */
10842 struct cmd_flow_director_flexpayload_result {
10843         cmdline_fixed_string_t flow_director_flexpayload;
10844         portid_t port_id;
10845         cmdline_fixed_string_t payload_layer;
10846         cmdline_fixed_string_t payload_cfg;
10847 };
10848
10849 static inline int
10850 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10851 {
10852         char s[256];
10853         const char *p, *p0 = q_arg;
10854         char *end;
10855         unsigned long int_fld;
10856         char *str_fld[max_num];
10857         int i;
10858         unsigned size;
10859         int ret = -1;
10860
10861         p = strchr(p0, '(');
10862         if (p == NULL)
10863                 return -1;
10864         ++p;
10865         p0 = strchr(p, ')');
10866         if (p0 == NULL)
10867                 return -1;
10868
10869         size = p0 - p;
10870         if (size >= sizeof(s))
10871                 return -1;
10872
10873         snprintf(s, sizeof(s), "%.*s", size, p);
10874         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10875         if (ret < 0 || ret > max_num)
10876                 return -1;
10877         for (i = 0; i < ret; i++) {
10878                 errno = 0;
10879                 int_fld = strtoul(str_fld[i], &end, 0);
10880                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10881                         return -1;
10882                 offsets[i] = (uint16_t)int_fld;
10883         }
10884         return ret;
10885 }
10886
10887 static void
10888 cmd_flow_director_flxpld_parsed(void *parsed_result,
10889                           __attribute__((unused)) struct cmdline *cl,
10890                           __attribute__((unused)) void *data)
10891 {
10892         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10893         struct rte_eth_flex_payload_cfg flex_cfg;
10894         struct rte_port *port;
10895         int ret = 0;
10896
10897         if (res->port_id > nb_ports) {
10898                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10899                 return;
10900         }
10901
10902         port = &ports[res->port_id];
10903         /** Check if the port is not started **/
10904         if (port->port_status != RTE_PORT_STOPPED) {
10905                 printf("Please stop port %d first\n", res->port_id);
10906                 return;
10907         }
10908
10909         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10910
10911         if (!strcmp(res->payload_layer, "raw"))
10912                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10913         else if (!strcmp(res->payload_layer, "l2"))
10914                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10915         else if (!strcmp(res->payload_layer, "l3"))
10916                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10917         else if (!strcmp(res->payload_layer, "l4"))
10918                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10919
10920         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10921                             RTE_ETH_FDIR_MAX_FLEXLEN);
10922         if (ret < 0) {
10923                 printf("error: Cannot parse flex payload input.\n");
10924                 return;
10925         }
10926
10927         fdir_set_flex_payload(res->port_id, &flex_cfg);
10928         cmd_reconfig_device_queue(res->port_id, 1, 1);
10929 }
10930
10931 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10932         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10933                                  flow_director_flexpayload,
10934                                  "flow_director_flex_payload");
10935 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10936         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10937                               port_id, UINT16);
10938 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10939         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10940                                  payload_layer, "raw#l2#l3#l4");
10941 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10942         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10943                                  payload_cfg, NULL);
10944
10945 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10946         .f = cmd_flow_director_flxpld_parsed,
10947         .data = NULL,
10948         .help_str = "flow_director_flexpayload ... : "
10949                 "Set flow director's flex payload on NIC",
10950         .tokens = {
10951                 (void *)&cmd_flow_director_flexpayload,
10952                 (void *)&cmd_flow_director_flexpayload_port_id,
10953                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10954                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10955                 NULL,
10956         },
10957 };
10958
10959 /* Generic flow interface command. */
10960 extern cmdline_parse_inst_t cmd_flow;
10961
10962 /* *** Classification Filters Control *** */
10963 /* *** Get symmetric hash enable per port *** */
10964 struct cmd_get_sym_hash_ena_per_port_result {
10965         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10966         portid_t port_id;
10967 };
10968
10969 static void
10970 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10971                                  __rte_unused struct cmdline *cl,
10972                                  __rte_unused void *data)
10973 {
10974         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10975         struct rte_eth_hash_filter_info info;
10976         int ret;
10977
10978         if (rte_eth_dev_filter_supported(res->port_id,
10979                                 RTE_ETH_FILTER_HASH) < 0) {
10980                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10981                                                         res->port_id);
10982                 return;
10983         }
10984
10985         memset(&info, 0, sizeof(info));
10986         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10987         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10988                                                 RTE_ETH_FILTER_GET, &info);
10989
10990         if (ret < 0) {
10991                 printf("Cannot get symmetric hash enable per port "
10992                                         "on port %u\n", res->port_id);
10993                 return;
10994         }
10995
10996         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10997                                 "enabled" : "disabled", res->port_id);
10998 }
10999
11000 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11001         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11002                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11003 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11004         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11005                 port_id, UINT16);
11006
11007 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11008         .f = cmd_get_sym_hash_per_port_parsed,
11009         .data = NULL,
11010         .help_str = "get_sym_hash_ena_per_port <port_id>",
11011         .tokens = {
11012                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11013                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11014                 NULL,
11015         },
11016 };
11017
11018 /* *** Set symmetric hash enable per port *** */
11019 struct cmd_set_sym_hash_ena_per_port_result {
11020         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11021         cmdline_fixed_string_t enable;
11022         portid_t port_id;
11023 };
11024
11025 static void
11026 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11027                                  __rte_unused struct cmdline *cl,
11028                                  __rte_unused void *data)
11029 {
11030         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11031         struct rte_eth_hash_filter_info info;
11032         int ret;
11033
11034         if (rte_eth_dev_filter_supported(res->port_id,
11035                                 RTE_ETH_FILTER_HASH) < 0) {
11036                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11037                                                         res->port_id);
11038                 return;
11039         }
11040
11041         memset(&info, 0, sizeof(info));
11042         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11043         if (!strcmp(res->enable, "enable"))
11044                 info.info.enable = 1;
11045         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11046                                         RTE_ETH_FILTER_SET, &info);
11047         if (ret < 0) {
11048                 printf("Cannot set symmetric hash enable per port on "
11049                                         "port %u\n", res->port_id);
11050                 return;
11051         }
11052         printf("Symmetric hash has been set to %s on port %u\n",
11053                                         res->enable, res->port_id);
11054 }
11055
11056 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11057         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11058                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11059 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11060         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11061                 port_id, UINT16);
11062 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11063         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11064                 enable, "enable#disable");
11065
11066 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11067         .f = cmd_set_sym_hash_per_port_parsed,
11068         .data = NULL,
11069         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11070         .tokens = {
11071                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11072                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11073                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11074                 NULL,
11075         },
11076 };
11077
11078 /* Get global config of hash function */
11079 struct cmd_get_hash_global_config_result {
11080         cmdline_fixed_string_t get_hash_global_config;
11081         portid_t port_id;
11082 };
11083
11084 static char *
11085 flowtype_to_str(uint16_t ftype)
11086 {
11087         uint16_t i;
11088         static struct {
11089                 char str[16];
11090                 uint16_t ftype;
11091         } ftype_table[] = {
11092                 {"ipv4", RTE_ETH_FLOW_IPV4},
11093                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11094                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11095                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11096                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11097                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11098                 {"ipv6", RTE_ETH_FLOW_IPV6},
11099                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11100                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11101                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11102                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11103                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11104                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11105                 {"port", RTE_ETH_FLOW_PORT},
11106                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11107                 {"geneve", RTE_ETH_FLOW_GENEVE},
11108                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11109         };
11110
11111         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11112                 if (ftype_table[i].ftype == ftype)
11113                         return ftype_table[i].str;
11114         }
11115
11116         return NULL;
11117 }
11118
11119 static void
11120 cmd_get_hash_global_config_parsed(void *parsed_result,
11121                                   __rte_unused struct cmdline *cl,
11122                                   __rte_unused void *data)
11123 {
11124         struct cmd_get_hash_global_config_result *res = parsed_result;
11125         struct rte_eth_hash_filter_info info;
11126         uint32_t idx, offset;
11127         uint16_t i;
11128         char *str;
11129         int ret;
11130
11131         if (rte_eth_dev_filter_supported(res->port_id,
11132                         RTE_ETH_FILTER_HASH) < 0) {
11133                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11134                                                         res->port_id);
11135                 return;
11136         }
11137
11138         memset(&info, 0, sizeof(info));
11139         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11140         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11141                                         RTE_ETH_FILTER_GET, &info);
11142         if (ret < 0) {
11143                 printf("Cannot get hash global configurations by port %d\n",
11144                                                         res->port_id);
11145                 return;
11146         }
11147
11148         switch (info.info.global_conf.hash_func) {
11149         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11150                 printf("Hash function is Toeplitz\n");
11151                 break;
11152         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11153                 printf("Hash function is Simple XOR\n");
11154                 break;
11155         default:
11156                 printf("Unknown hash function\n");
11157                 break;
11158         }
11159
11160         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11161                 idx = i / UINT32_BIT;
11162                 offset = i % UINT32_BIT;
11163                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11164                                                 (1UL << offset)))
11165                         continue;
11166                 str = flowtype_to_str(i);
11167                 if (!str)
11168                         continue;
11169                 printf("Symmetric hash is %s globally for flow type %s "
11170                                                         "by port %d\n",
11171                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11172                         (1UL << offset)) ? "enabled" : "disabled"), str,
11173                                                         res->port_id);
11174         }
11175 }
11176
11177 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11178         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11179                 get_hash_global_config, "get_hash_global_config");
11180 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11181         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11182                 port_id, UINT16);
11183
11184 cmdline_parse_inst_t cmd_get_hash_global_config = {
11185         .f = cmd_get_hash_global_config_parsed,
11186         .data = NULL,
11187         .help_str = "get_hash_global_config <port_id>",
11188         .tokens = {
11189                 (void *)&cmd_get_hash_global_config_all,
11190                 (void *)&cmd_get_hash_global_config_port_id,
11191                 NULL,
11192         },
11193 };
11194
11195 /* Set global config of hash function */
11196 struct cmd_set_hash_global_config_result {
11197         cmdline_fixed_string_t set_hash_global_config;
11198         portid_t port_id;
11199         cmdline_fixed_string_t hash_func;
11200         cmdline_fixed_string_t flow_type;
11201         cmdline_fixed_string_t enable;
11202 };
11203
11204 static void
11205 cmd_set_hash_global_config_parsed(void *parsed_result,
11206                                   __rte_unused struct cmdline *cl,
11207                                   __rte_unused void *data)
11208 {
11209         struct cmd_set_hash_global_config_result *res = parsed_result;
11210         struct rte_eth_hash_filter_info info;
11211         uint32_t ftype, idx, offset;
11212         int ret;
11213
11214         if (rte_eth_dev_filter_supported(res->port_id,
11215                                 RTE_ETH_FILTER_HASH) < 0) {
11216                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11217                                                         res->port_id);
11218                 return;
11219         }
11220         memset(&info, 0, sizeof(info));
11221         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11222         if (!strcmp(res->hash_func, "toeplitz"))
11223                 info.info.global_conf.hash_func =
11224                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11225         else if (!strcmp(res->hash_func, "simple_xor"))
11226                 info.info.global_conf.hash_func =
11227                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11228         else if (!strcmp(res->hash_func, "default"))
11229                 info.info.global_conf.hash_func =
11230                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11231
11232         ftype = str2flowtype(res->flow_type);
11233         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11234         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11235         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11236         if (!strcmp(res->enable, "enable"))
11237                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11238                                                 (1UL << offset);
11239         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11240                                         RTE_ETH_FILTER_SET, &info);
11241         if (ret < 0)
11242                 printf("Cannot set global hash configurations by port %d\n",
11243                                                         res->port_id);
11244         else
11245                 printf("Global hash configurations have been set "
11246                         "succcessfully by port %d\n", res->port_id);
11247 }
11248
11249 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11250         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11251                 set_hash_global_config, "set_hash_global_config");
11252 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11253         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11254                 port_id, UINT16);
11255 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11256         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11257                 hash_func, "toeplitz#simple_xor#default");
11258 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11259         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11260                 flow_type,
11261                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11262                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11263 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11264         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11265                 enable, "enable#disable");
11266
11267 cmdline_parse_inst_t cmd_set_hash_global_config = {
11268         .f = cmd_set_hash_global_config_parsed,
11269         .data = NULL,
11270         .help_str = "set_hash_global_config <port_id> "
11271                 "toeplitz|simple_xor|default "
11272                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11273                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11274                 "l2_payload enable|disable",
11275         .tokens = {
11276                 (void *)&cmd_set_hash_global_config_all,
11277                 (void *)&cmd_set_hash_global_config_port_id,
11278                 (void *)&cmd_set_hash_global_config_hash_func,
11279                 (void *)&cmd_set_hash_global_config_flow_type,
11280                 (void *)&cmd_set_hash_global_config_enable,
11281                 NULL,
11282         },
11283 };
11284
11285 /* Set hash input set */
11286 struct cmd_set_hash_input_set_result {
11287         cmdline_fixed_string_t set_hash_input_set;
11288         portid_t port_id;
11289         cmdline_fixed_string_t flow_type;
11290         cmdline_fixed_string_t inset_field;
11291         cmdline_fixed_string_t select;
11292 };
11293
11294 static enum rte_eth_input_set_field
11295 str2inset(char *string)
11296 {
11297         uint16_t i;
11298
11299         static const struct {
11300                 char str[32];
11301                 enum rte_eth_input_set_field inset;
11302         } inset_table[] = {
11303                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11304                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11305                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11306                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11307                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11308                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11309                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11310                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11311                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11312                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11313                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11314                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11315                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11316                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11317                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11318                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11319                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11320                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11321                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11322                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11323                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11324                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11325                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11326                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11327                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11328                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11329                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11330                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11331                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11332                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11333                 {"none", RTE_ETH_INPUT_SET_NONE},
11334         };
11335
11336         for (i = 0; i < RTE_DIM(inset_table); i++) {
11337                 if (!strcmp(string, inset_table[i].str))
11338                         return inset_table[i].inset;
11339         }
11340
11341         return RTE_ETH_INPUT_SET_UNKNOWN;
11342 }
11343
11344 static void
11345 cmd_set_hash_input_set_parsed(void *parsed_result,
11346                               __rte_unused struct cmdline *cl,
11347                               __rte_unused void *data)
11348 {
11349         struct cmd_set_hash_input_set_result *res = parsed_result;
11350         struct rte_eth_hash_filter_info info;
11351
11352         memset(&info, 0, sizeof(info));
11353         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11354         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11355         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11356         info.info.input_set_conf.inset_size = 1;
11357         if (!strcmp(res->select, "select"))
11358                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11359         else if (!strcmp(res->select, "add"))
11360                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11361         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11362                                 RTE_ETH_FILTER_SET, &info);
11363 }
11364
11365 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11366         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11367                 set_hash_input_set, "set_hash_input_set");
11368 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11369         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11370                 port_id, UINT16);
11371 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11372         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11373                 flow_type, NULL);
11374 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11375         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11376                 inset_field,
11377                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11378                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11379                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11380                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11381                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11382                 "fld-8th#none");
11383 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11384         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11385                 select, "select#add");
11386
11387 cmdline_parse_inst_t cmd_set_hash_input_set = {
11388         .f = cmd_set_hash_input_set_parsed,
11389         .data = NULL,
11390         .help_str = "set_hash_input_set <port_id> "
11391         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11392         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11393         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11394         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11395         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11396         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11397         "fld-7th|fld-8th|none select|add",
11398         .tokens = {
11399                 (void *)&cmd_set_hash_input_set_cmd,
11400                 (void *)&cmd_set_hash_input_set_port_id,
11401                 (void *)&cmd_set_hash_input_set_flow_type,
11402                 (void *)&cmd_set_hash_input_set_field,
11403                 (void *)&cmd_set_hash_input_set_select,
11404                 NULL,
11405         },
11406 };
11407
11408 /* Set flow director input set */
11409 struct cmd_set_fdir_input_set_result {
11410         cmdline_fixed_string_t set_fdir_input_set;
11411         portid_t port_id;
11412         cmdline_fixed_string_t flow_type;
11413         cmdline_fixed_string_t inset_field;
11414         cmdline_fixed_string_t select;
11415 };
11416
11417 static void
11418 cmd_set_fdir_input_set_parsed(void *parsed_result,
11419         __rte_unused struct cmdline *cl,
11420         __rte_unused void *data)
11421 {
11422         struct cmd_set_fdir_input_set_result *res = parsed_result;
11423         struct rte_eth_fdir_filter_info info;
11424
11425         memset(&info, 0, sizeof(info));
11426         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11427         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11428         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11429         info.info.input_set_conf.inset_size = 1;
11430         if (!strcmp(res->select, "select"))
11431                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11432         else if (!strcmp(res->select, "add"))
11433                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11434         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11435                 RTE_ETH_FILTER_SET, &info);
11436 }
11437
11438 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11439         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11440         set_fdir_input_set, "set_fdir_input_set");
11441 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11442         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11443         port_id, UINT16);
11444 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11445         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11446         flow_type,
11447         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11448         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11449 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11450         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11451         inset_field,
11452         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11453         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11454         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11455         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11456         "sctp-veri-tag#none");
11457 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11458         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11459         select, "select#add");
11460
11461 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11462         .f = cmd_set_fdir_input_set_parsed,
11463         .data = NULL,
11464         .help_str = "set_fdir_input_set <port_id> "
11465         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11466         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11467         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11468         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11469         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11470         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11471         "sctp-veri-tag|none select|add",
11472         .tokens = {
11473                 (void *)&cmd_set_fdir_input_set_cmd,
11474                 (void *)&cmd_set_fdir_input_set_port_id,
11475                 (void *)&cmd_set_fdir_input_set_flow_type,
11476                 (void *)&cmd_set_fdir_input_set_field,
11477                 (void *)&cmd_set_fdir_input_set_select,
11478                 NULL,
11479         },
11480 };
11481
11482 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11483 struct cmd_mcast_addr_result {
11484         cmdline_fixed_string_t mcast_addr_cmd;
11485         cmdline_fixed_string_t what;
11486         uint16_t port_num;
11487         struct ether_addr mc_addr;
11488 };
11489
11490 static void cmd_mcast_addr_parsed(void *parsed_result,
11491                 __attribute__((unused)) struct cmdline *cl,
11492                 __attribute__((unused)) void *data)
11493 {
11494         struct cmd_mcast_addr_result *res = parsed_result;
11495
11496         if (!is_multicast_ether_addr(&res->mc_addr)) {
11497                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11498                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11499                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11500                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11501                 return;
11502         }
11503         if (strcmp(res->what, "add") == 0)
11504                 mcast_addr_add(res->port_num, &res->mc_addr);
11505         else
11506                 mcast_addr_remove(res->port_num, &res->mc_addr);
11507 }
11508
11509 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11510         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11511                                  mcast_addr_cmd, "mcast_addr");
11512 cmdline_parse_token_string_t cmd_mcast_addr_what =
11513         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11514                                  "add#remove");
11515 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11516         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11517 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11518         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11519
11520 cmdline_parse_inst_t cmd_mcast_addr = {
11521         .f = cmd_mcast_addr_parsed,
11522         .data = (void *)0,
11523         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11524                 "Add/Remove multicast MAC address on port_id",
11525         .tokens = {
11526                 (void *)&cmd_mcast_addr_cmd,
11527                 (void *)&cmd_mcast_addr_what,
11528                 (void *)&cmd_mcast_addr_portnum,
11529                 (void *)&cmd_mcast_addr_addr,
11530                 NULL,
11531         },
11532 };
11533
11534 /* l2 tunnel config
11535  * only support E-tag now.
11536  */
11537
11538 /* Ether type config */
11539 struct cmd_config_l2_tunnel_eth_type_result {
11540         cmdline_fixed_string_t port;
11541         cmdline_fixed_string_t config;
11542         cmdline_fixed_string_t all;
11543         uint8_t id;
11544         cmdline_fixed_string_t l2_tunnel;
11545         cmdline_fixed_string_t l2_tunnel_type;
11546         cmdline_fixed_string_t eth_type;
11547         uint16_t eth_type_val;
11548 };
11549
11550 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11551         TOKEN_STRING_INITIALIZER
11552                 (struct cmd_config_l2_tunnel_eth_type_result,
11553                  port, "port");
11554 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11555         TOKEN_STRING_INITIALIZER
11556                 (struct cmd_config_l2_tunnel_eth_type_result,
11557                  config, "config");
11558 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11559         TOKEN_STRING_INITIALIZER
11560                 (struct cmd_config_l2_tunnel_eth_type_result,
11561                  all, "all");
11562 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11563         TOKEN_NUM_INITIALIZER
11564                 (struct cmd_config_l2_tunnel_eth_type_result,
11565                  id, UINT8);
11566 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11567         TOKEN_STRING_INITIALIZER
11568                 (struct cmd_config_l2_tunnel_eth_type_result,
11569                  l2_tunnel, "l2-tunnel");
11570 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11571         TOKEN_STRING_INITIALIZER
11572                 (struct cmd_config_l2_tunnel_eth_type_result,
11573                  l2_tunnel_type, "E-tag");
11574 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11575         TOKEN_STRING_INITIALIZER
11576                 (struct cmd_config_l2_tunnel_eth_type_result,
11577                  eth_type, "ether-type");
11578 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11579         TOKEN_NUM_INITIALIZER
11580                 (struct cmd_config_l2_tunnel_eth_type_result,
11581                  eth_type_val, UINT16);
11582
11583 static enum rte_eth_tunnel_type
11584 str2fdir_l2_tunnel_type(char *string)
11585 {
11586         uint32_t i = 0;
11587
11588         static const struct {
11589                 char str[32];
11590                 enum rte_eth_tunnel_type type;
11591         } l2_tunnel_type_str[] = {
11592                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11593         };
11594
11595         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11596                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11597                         return l2_tunnel_type_str[i].type;
11598         }
11599         return RTE_TUNNEL_TYPE_NONE;
11600 }
11601
11602 /* ether type config for all ports */
11603 static void
11604 cmd_config_l2_tunnel_eth_type_all_parsed
11605         (void *parsed_result,
11606          __attribute__((unused)) struct cmdline *cl,
11607          __attribute__((unused)) void *data)
11608 {
11609         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11610         struct rte_eth_l2_tunnel_conf entry;
11611         portid_t pid;
11612
11613         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11614         entry.ether_type = res->eth_type_val;
11615
11616         RTE_ETH_FOREACH_DEV(pid) {
11617                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11618         }
11619 }
11620
11621 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11622         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11623         .data = NULL,
11624         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11625         .tokens = {
11626                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11627                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11628                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11629                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11630                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11631                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11632                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11633                 NULL,
11634         },
11635 };
11636
11637 /* ether type config for a specific port */
11638 static void
11639 cmd_config_l2_tunnel_eth_type_specific_parsed(
11640         void *parsed_result,
11641         __attribute__((unused)) struct cmdline *cl,
11642         __attribute__((unused)) void *data)
11643 {
11644         struct cmd_config_l2_tunnel_eth_type_result *res =
11645                  parsed_result;
11646         struct rte_eth_l2_tunnel_conf entry;
11647
11648         if (port_id_is_invalid(res->id, ENABLED_WARN))
11649                 return;
11650
11651         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11652         entry.ether_type = res->eth_type_val;
11653
11654         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11655 }
11656
11657 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11658         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11659         .data = NULL,
11660         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11661         .tokens = {
11662                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11663                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11664                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11665                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11666                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11667                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11668                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11669                 NULL,
11670         },
11671 };
11672
11673 /* Enable/disable l2 tunnel */
11674 struct cmd_config_l2_tunnel_en_dis_result {
11675         cmdline_fixed_string_t port;
11676         cmdline_fixed_string_t config;
11677         cmdline_fixed_string_t all;
11678         uint8_t id;
11679         cmdline_fixed_string_t l2_tunnel;
11680         cmdline_fixed_string_t l2_tunnel_type;
11681         cmdline_fixed_string_t en_dis;
11682 };
11683
11684 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11685         TOKEN_STRING_INITIALIZER
11686                 (struct cmd_config_l2_tunnel_en_dis_result,
11687                  port, "port");
11688 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11689         TOKEN_STRING_INITIALIZER
11690                 (struct cmd_config_l2_tunnel_en_dis_result,
11691                  config, "config");
11692 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11693         TOKEN_STRING_INITIALIZER
11694                 (struct cmd_config_l2_tunnel_en_dis_result,
11695                  all, "all");
11696 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11697         TOKEN_NUM_INITIALIZER
11698                 (struct cmd_config_l2_tunnel_en_dis_result,
11699                  id, UINT8);
11700 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11701         TOKEN_STRING_INITIALIZER
11702                 (struct cmd_config_l2_tunnel_en_dis_result,
11703                  l2_tunnel, "l2-tunnel");
11704 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11705         TOKEN_STRING_INITIALIZER
11706                 (struct cmd_config_l2_tunnel_en_dis_result,
11707                  l2_tunnel_type, "E-tag");
11708 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11709         TOKEN_STRING_INITIALIZER
11710                 (struct cmd_config_l2_tunnel_en_dis_result,
11711                  en_dis, "enable#disable");
11712
11713 /* enable/disable l2 tunnel for all ports */
11714 static void
11715 cmd_config_l2_tunnel_en_dis_all_parsed(
11716         void *parsed_result,
11717         __attribute__((unused)) struct cmdline *cl,
11718         __attribute__((unused)) void *data)
11719 {
11720         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11721         struct rte_eth_l2_tunnel_conf entry;
11722         portid_t pid;
11723         uint8_t en;
11724
11725         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11726
11727         if (!strcmp("enable", res->en_dis))
11728                 en = 1;
11729         else
11730                 en = 0;
11731
11732         RTE_ETH_FOREACH_DEV(pid) {
11733                 rte_eth_dev_l2_tunnel_offload_set(pid,
11734                                                   &entry,
11735                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11736                                                   en);
11737         }
11738 }
11739
11740 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11741         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11742         .data = NULL,
11743         .help_str = "port config all l2-tunnel E-tag enable|disable",
11744         .tokens = {
11745                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11746                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11747                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11748                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11749                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11750                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11751                 NULL,
11752         },
11753 };
11754
11755 /* enable/disable l2 tunnel for a port */
11756 static void
11757 cmd_config_l2_tunnel_en_dis_specific_parsed(
11758         void *parsed_result,
11759         __attribute__((unused)) struct cmdline *cl,
11760         __attribute__((unused)) void *data)
11761 {
11762         struct cmd_config_l2_tunnel_en_dis_result *res =
11763                 parsed_result;
11764         struct rte_eth_l2_tunnel_conf entry;
11765
11766         if (port_id_is_invalid(res->id, ENABLED_WARN))
11767                 return;
11768
11769         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11770
11771         if (!strcmp("enable", res->en_dis))
11772                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11773                                                   &entry,
11774                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11775                                                   1);
11776         else
11777                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11778                                                   &entry,
11779                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11780                                                   0);
11781 }
11782
11783 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11784         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11785         .data = NULL,
11786         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11787         .tokens = {
11788                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11789                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11790                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11791                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11792                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11793                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11794                 NULL,
11795         },
11796 };
11797
11798 /* E-tag configuration */
11799
11800 /* Common result structure for all E-tag configuration */
11801 struct cmd_config_e_tag_result {
11802         cmdline_fixed_string_t e_tag;
11803         cmdline_fixed_string_t set;
11804         cmdline_fixed_string_t insertion;
11805         cmdline_fixed_string_t stripping;
11806         cmdline_fixed_string_t forwarding;
11807         cmdline_fixed_string_t filter;
11808         cmdline_fixed_string_t add;
11809         cmdline_fixed_string_t del;
11810         cmdline_fixed_string_t on;
11811         cmdline_fixed_string_t off;
11812         cmdline_fixed_string_t on_off;
11813         cmdline_fixed_string_t port_tag_id;
11814         uint32_t port_tag_id_val;
11815         cmdline_fixed_string_t e_tag_id;
11816         uint16_t e_tag_id_val;
11817         cmdline_fixed_string_t dst_pool;
11818         uint8_t dst_pool_val;
11819         cmdline_fixed_string_t port;
11820         portid_t port_id;
11821         cmdline_fixed_string_t vf;
11822         uint8_t vf_id;
11823 };
11824
11825 /* Common CLI fields for all E-tag configuration */
11826 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11827         TOKEN_STRING_INITIALIZER
11828                 (struct cmd_config_e_tag_result,
11829                  e_tag, "E-tag");
11830 cmdline_parse_token_string_t cmd_config_e_tag_set =
11831         TOKEN_STRING_INITIALIZER
11832                 (struct cmd_config_e_tag_result,
11833                  set, "set");
11834 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11835         TOKEN_STRING_INITIALIZER
11836                 (struct cmd_config_e_tag_result,
11837                  insertion, "insertion");
11838 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11839         TOKEN_STRING_INITIALIZER
11840                 (struct cmd_config_e_tag_result,
11841                  stripping, "stripping");
11842 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11843         TOKEN_STRING_INITIALIZER
11844                 (struct cmd_config_e_tag_result,
11845                  forwarding, "forwarding");
11846 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11847         TOKEN_STRING_INITIALIZER
11848                 (struct cmd_config_e_tag_result,
11849                  filter, "filter");
11850 cmdline_parse_token_string_t cmd_config_e_tag_add =
11851         TOKEN_STRING_INITIALIZER
11852                 (struct cmd_config_e_tag_result,
11853                  add, "add");
11854 cmdline_parse_token_string_t cmd_config_e_tag_del =
11855         TOKEN_STRING_INITIALIZER
11856                 (struct cmd_config_e_tag_result,
11857                  del, "del");
11858 cmdline_parse_token_string_t cmd_config_e_tag_on =
11859         TOKEN_STRING_INITIALIZER
11860                 (struct cmd_config_e_tag_result,
11861                  on, "on");
11862 cmdline_parse_token_string_t cmd_config_e_tag_off =
11863         TOKEN_STRING_INITIALIZER
11864                 (struct cmd_config_e_tag_result,
11865                  off, "off");
11866 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11867         TOKEN_STRING_INITIALIZER
11868                 (struct cmd_config_e_tag_result,
11869                  on_off, "on#off");
11870 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11871         TOKEN_STRING_INITIALIZER
11872                 (struct cmd_config_e_tag_result,
11873                  port_tag_id, "port-tag-id");
11874 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11875         TOKEN_NUM_INITIALIZER
11876                 (struct cmd_config_e_tag_result,
11877                  port_tag_id_val, UINT32);
11878 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11879         TOKEN_STRING_INITIALIZER
11880                 (struct cmd_config_e_tag_result,
11881                  e_tag_id, "e-tag-id");
11882 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11883         TOKEN_NUM_INITIALIZER
11884                 (struct cmd_config_e_tag_result,
11885                  e_tag_id_val, UINT16);
11886 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11887         TOKEN_STRING_INITIALIZER
11888                 (struct cmd_config_e_tag_result,
11889                  dst_pool, "dst-pool");
11890 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11891         TOKEN_NUM_INITIALIZER
11892                 (struct cmd_config_e_tag_result,
11893                  dst_pool_val, UINT8);
11894 cmdline_parse_token_string_t cmd_config_e_tag_port =
11895         TOKEN_STRING_INITIALIZER
11896                 (struct cmd_config_e_tag_result,
11897                  port, "port");
11898 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11899         TOKEN_NUM_INITIALIZER
11900                 (struct cmd_config_e_tag_result,
11901                  port_id, UINT16);
11902 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11903         TOKEN_STRING_INITIALIZER
11904                 (struct cmd_config_e_tag_result,
11905                  vf, "vf");
11906 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11907         TOKEN_NUM_INITIALIZER
11908                 (struct cmd_config_e_tag_result,
11909                  vf_id, UINT8);
11910
11911 /* E-tag insertion configuration */
11912 static void
11913 cmd_config_e_tag_insertion_en_parsed(
11914         void *parsed_result,
11915         __attribute__((unused)) struct cmdline *cl,
11916         __attribute__((unused)) void *data)
11917 {
11918         struct cmd_config_e_tag_result *res =
11919                 parsed_result;
11920         struct rte_eth_l2_tunnel_conf entry;
11921
11922         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11923                 return;
11924
11925         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11926         entry.tunnel_id = res->port_tag_id_val;
11927         entry.vf_id = res->vf_id;
11928         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11929                                           &entry,
11930                                           ETH_L2_TUNNEL_INSERTION_MASK,
11931                                           1);
11932 }
11933
11934 static void
11935 cmd_config_e_tag_insertion_dis_parsed(
11936         void *parsed_result,
11937         __attribute__((unused)) struct cmdline *cl,
11938         __attribute__((unused)) void *data)
11939 {
11940         struct cmd_config_e_tag_result *res =
11941                 parsed_result;
11942         struct rte_eth_l2_tunnel_conf entry;
11943
11944         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11945                 return;
11946
11947         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11948         entry.vf_id = res->vf_id;
11949
11950         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11951                                           &entry,
11952                                           ETH_L2_TUNNEL_INSERTION_MASK,
11953                                           0);
11954 }
11955
11956 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11957         .f = cmd_config_e_tag_insertion_en_parsed,
11958         .data = NULL,
11959         .help_str = "E-tag ... : E-tag insertion enable",
11960         .tokens = {
11961                 (void *)&cmd_config_e_tag_e_tag,
11962                 (void *)&cmd_config_e_tag_set,
11963                 (void *)&cmd_config_e_tag_insertion,
11964                 (void *)&cmd_config_e_tag_on,
11965                 (void *)&cmd_config_e_tag_port_tag_id,
11966                 (void *)&cmd_config_e_tag_port_tag_id_val,
11967                 (void *)&cmd_config_e_tag_port,
11968                 (void *)&cmd_config_e_tag_port_id,
11969                 (void *)&cmd_config_e_tag_vf,
11970                 (void *)&cmd_config_e_tag_vf_id,
11971                 NULL,
11972         },
11973 };
11974
11975 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11976         .f = cmd_config_e_tag_insertion_dis_parsed,
11977         .data = NULL,
11978         .help_str = "E-tag ... : E-tag insertion disable",
11979         .tokens = {
11980                 (void *)&cmd_config_e_tag_e_tag,
11981                 (void *)&cmd_config_e_tag_set,
11982                 (void *)&cmd_config_e_tag_insertion,
11983                 (void *)&cmd_config_e_tag_off,
11984                 (void *)&cmd_config_e_tag_port,
11985                 (void *)&cmd_config_e_tag_port_id,
11986                 (void *)&cmd_config_e_tag_vf,
11987                 (void *)&cmd_config_e_tag_vf_id,
11988                 NULL,
11989         },
11990 };
11991
11992 /* E-tag stripping configuration */
11993 static void
11994 cmd_config_e_tag_stripping_parsed(
11995         void *parsed_result,
11996         __attribute__((unused)) struct cmdline *cl,
11997         __attribute__((unused)) void *data)
11998 {
11999         struct cmd_config_e_tag_result *res =
12000                 parsed_result;
12001         struct rte_eth_l2_tunnel_conf entry;
12002
12003         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12004                 return;
12005
12006         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12007
12008         if (!strcmp(res->on_off, "on"))
12009                 rte_eth_dev_l2_tunnel_offload_set
12010                         (res->port_id,
12011                          &entry,
12012                          ETH_L2_TUNNEL_STRIPPING_MASK,
12013                          1);
12014         else
12015                 rte_eth_dev_l2_tunnel_offload_set
12016                         (res->port_id,
12017                          &entry,
12018                          ETH_L2_TUNNEL_STRIPPING_MASK,
12019                          0);
12020 }
12021
12022 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12023         .f = cmd_config_e_tag_stripping_parsed,
12024         .data = NULL,
12025         .help_str = "E-tag ... : E-tag stripping enable/disable",
12026         .tokens = {
12027                 (void *)&cmd_config_e_tag_e_tag,
12028                 (void *)&cmd_config_e_tag_set,
12029                 (void *)&cmd_config_e_tag_stripping,
12030                 (void *)&cmd_config_e_tag_on_off,
12031                 (void *)&cmd_config_e_tag_port,
12032                 (void *)&cmd_config_e_tag_port_id,
12033                 NULL,
12034         },
12035 };
12036
12037 /* E-tag forwarding configuration */
12038 static void
12039 cmd_config_e_tag_forwarding_parsed(
12040         void *parsed_result,
12041         __attribute__((unused)) struct cmdline *cl,
12042         __attribute__((unused)) void *data)
12043 {
12044         struct cmd_config_e_tag_result *res = parsed_result;
12045         struct rte_eth_l2_tunnel_conf entry;
12046
12047         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12048                 return;
12049
12050         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12051
12052         if (!strcmp(res->on_off, "on"))
12053                 rte_eth_dev_l2_tunnel_offload_set
12054                         (res->port_id,
12055                          &entry,
12056                          ETH_L2_TUNNEL_FORWARDING_MASK,
12057                          1);
12058         else
12059                 rte_eth_dev_l2_tunnel_offload_set
12060                         (res->port_id,
12061                          &entry,
12062                          ETH_L2_TUNNEL_FORWARDING_MASK,
12063                          0);
12064 }
12065
12066 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12067         .f = cmd_config_e_tag_forwarding_parsed,
12068         .data = NULL,
12069         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12070         .tokens = {
12071                 (void *)&cmd_config_e_tag_e_tag,
12072                 (void *)&cmd_config_e_tag_set,
12073                 (void *)&cmd_config_e_tag_forwarding,
12074                 (void *)&cmd_config_e_tag_on_off,
12075                 (void *)&cmd_config_e_tag_port,
12076                 (void *)&cmd_config_e_tag_port_id,
12077                 NULL,
12078         },
12079 };
12080
12081 /* E-tag filter configuration */
12082 static void
12083 cmd_config_e_tag_filter_add_parsed(
12084         void *parsed_result,
12085         __attribute__((unused)) struct cmdline *cl,
12086         __attribute__((unused)) void *data)
12087 {
12088         struct cmd_config_e_tag_result *res = parsed_result;
12089         struct rte_eth_l2_tunnel_conf entry;
12090         int ret = 0;
12091
12092         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12093                 return;
12094
12095         if (res->e_tag_id_val > 0x3fff) {
12096                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12097                 return;
12098         }
12099
12100         ret = rte_eth_dev_filter_supported(res->port_id,
12101                                            RTE_ETH_FILTER_L2_TUNNEL);
12102         if (ret < 0) {
12103                 printf("E-tag filter is not supported on port %u.\n",
12104                        res->port_id);
12105                 return;
12106         }
12107
12108         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12109         entry.tunnel_id = res->e_tag_id_val;
12110         entry.pool = res->dst_pool_val;
12111
12112         ret = rte_eth_dev_filter_ctrl(res->port_id,
12113                                       RTE_ETH_FILTER_L2_TUNNEL,
12114                                       RTE_ETH_FILTER_ADD,
12115                                       &entry);
12116         if (ret < 0)
12117                 printf("E-tag filter programming error: (%s)\n",
12118                        strerror(-ret));
12119 }
12120
12121 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12122         .f = cmd_config_e_tag_filter_add_parsed,
12123         .data = NULL,
12124         .help_str = "E-tag ... : E-tag filter add",
12125         .tokens = {
12126                 (void *)&cmd_config_e_tag_e_tag,
12127                 (void *)&cmd_config_e_tag_set,
12128                 (void *)&cmd_config_e_tag_filter,
12129                 (void *)&cmd_config_e_tag_add,
12130                 (void *)&cmd_config_e_tag_e_tag_id,
12131                 (void *)&cmd_config_e_tag_e_tag_id_val,
12132                 (void *)&cmd_config_e_tag_dst_pool,
12133                 (void *)&cmd_config_e_tag_dst_pool_val,
12134                 (void *)&cmd_config_e_tag_port,
12135                 (void *)&cmd_config_e_tag_port_id,
12136                 NULL,
12137         },
12138 };
12139
12140 static void
12141 cmd_config_e_tag_filter_del_parsed(
12142         void *parsed_result,
12143         __attribute__((unused)) struct cmdline *cl,
12144         __attribute__((unused)) void *data)
12145 {
12146         struct cmd_config_e_tag_result *res = parsed_result;
12147         struct rte_eth_l2_tunnel_conf entry;
12148         int ret = 0;
12149
12150         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12151                 return;
12152
12153         if (res->e_tag_id_val > 0x3fff) {
12154                 printf("e-tag-id must be less than 0x3fff.\n");
12155                 return;
12156         }
12157
12158         ret = rte_eth_dev_filter_supported(res->port_id,
12159                                            RTE_ETH_FILTER_L2_TUNNEL);
12160         if (ret < 0) {
12161                 printf("E-tag filter is not supported on port %u.\n",
12162                        res->port_id);
12163                 return;
12164         }
12165
12166         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12167         entry.tunnel_id = res->e_tag_id_val;
12168
12169         ret = rte_eth_dev_filter_ctrl(res->port_id,
12170                                       RTE_ETH_FILTER_L2_TUNNEL,
12171                                       RTE_ETH_FILTER_DELETE,
12172                                       &entry);
12173         if (ret < 0)
12174                 printf("E-tag filter programming error: (%s)\n",
12175                        strerror(-ret));
12176 }
12177
12178 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12179         .f = cmd_config_e_tag_filter_del_parsed,
12180         .data = NULL,
12181         .help_str = "E-tag ... : E-tag filter delete",
12182         .tokens = {
12183                 (void *)&cmd_config_e_tag_e_tag,
12184                 (void *)&cmd_config_e_tag_set,
12185                 (void *)&cmd_config_e_tag_filter,
12186                 (void *)&cmd_config_e_tag_del,
12187                 (void *)&cmd_config_e_tag_e_tag_id,
12188                 (void *)&cmd_config_e_tag_e_tag_id_val,
12189                 (void *)&cmd_config_e_tag_port,
12190                 (void *)&cmd_config_e_tag_port_id,
12191                 NULL,
12192         },
12193 };
12194
12195 /* vf vlan anti spoof configuration */
12196
12197 /* Common result structure for vf vlan anti spoof */
12198 struct cmd_vf_vlan_anti_spoof_result {
12199         cmdline_fixed_string_t set;
12200         cmdline_fixed_string_t vf;
12201         cmdline_fixed_string_t vlan;
12202         cmdline_fixed_string_t antispoof;
12203         portid_t port_id;
12204         uint32_t vf_id;
12205         cmdline_fixed_string_t on_off;
12206 };
12207
12208 /* Common CLI fields for vf vlan anti spoof enable disable */
12209 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12210         TOKEN_STRING_INITIALIZER
12211                 (struct cmd_vf_vlan_anti_spoof_result,
12212                  set, "set");
12213 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12214         TOKEN_STRING_INITIALIZER
12215                 (struct cmd_vf_vlan_anti_spoof_result,
12216                  vf, "vf");
12217 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12218         TOKEN_STRING_INITIALIZER
12219                 (struct cmd_vf_vlan_anti_spoof_result,
12220                  vlan, "vlan");
12221 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12222         TOKEN_STRING_INITIALIZER
12223                 (struct cmd_vf_vlan_anti_spoof_result,
12224                  antispoof, "antispoof");
12225 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12226         TOKEN_NUM_INITIALIZER
12227                 (struct cmd_vf_vlan_anti_spoof_result,
12228                  port_id, UINT16);
12229 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12230         TOKEN_NUM_INITIALIZER
12231                 (struct cmd_vf_vlan_anti_spoof_result,
12232                  vf_id, UINT32);
12233 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12234         TOKEN_STRING_INITIALIZER
12235                 (struct cmd_vf_vlan_anti_spoof_result,
12236                  on_off, "on#off");
12237
12238 static void
12239 cmd_set_vf_vlan_anti_spoof_parsed(
12240         void *parsed_result,
12241         __attribute__((unused)) struct cmdline *cl,
12242         __attribute__((unused)) void *data)
12243 {
12244         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12245         int ret = -ENOTSUP;
12246
12247         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12248
12249         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12250                 return;
12251
12252 #ifdef RTE_LIBRTE_IXGBE_PMD
12253         if (ret == -ENOTSUP)
12254                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12255                                 res->vf_id, is_on);
12256 #endif
12257 #ifdef RTE_LIBRTE_I40E_PMD
12258         if (ret == -ENOTSUP)
12259                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12260                                 res->vf_id, is_on);
12261 #endif
12262 #ifdef RTE_LIBRTE_BNXT_PMD
12263         if (ret == -ENOTSUP)
12264                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12265                                 res->vf_id, is_on);
12266 #endif
12267
12268         switch (ret) {
12269         case 0:
12270                 break;
12271         case -EINVAL:
12272                 printf("invalid vf_id %d\n", res->vf_id);
12273                 break;
12274         case -ENODEV:
12275                 printf("invalid port_id %d\n", res->port_id);
12276                 break;
12277         case -ENOTSUP:
12278                 printf("function not implemented\n");
12279                 break;
12280         default:
12281                 printf("programming error: (%s)\n", strerror(-ret));
12282         }
12283 }
12284
12285 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12286         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12287         .data = NULL,
12288         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12289         .tokens = {
12290                 (void *)&cmd_vf_vlan_anti_spoof_set,
12291                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12292                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12293                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12294                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12295                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12296                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12297                 NULL,
12298         },
12299 };
12300
12301 /* vf mac anti spoof configuration */
12302
12303 /* Common result structure for vf mac anti spoof */
12304 struct cmd_vf_mac_anti_spoof_result {
12305         cmdline_fixed_string_t set;
12306         cmdline_fixed_string_t vf;
12307         cmdline_fixed_string_t mac;
12308         cmdline_fixed_string_t antispoof;
12309         portid_t port_id;
12310         uint32_t vf_id;
12311         cmdline_fixed_string_t on_off;
12312 };
12313
12314 /* Common CLI fields for vf mac anti spoof enable disable */
12315 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12316         TOKEN_STRING_INITIALIZER
12317                 (struct cmd_vf_mac_anti_spoof_result,
12318                  set, "set");
12319 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12320         TOKEN_STRING_INITIALIZER
12321                 (struct cmd_vf_mac_anti_spoof_result,
12322                  vf, "vf");
12323 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12324         TOKEN_STRING_INITIALIZER
12325                 (struct cmd_vf_mac_anti_spoof_result,
12326                  mac, "mac");
12327 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12328         TOKEN_STRING_INITIALIZER
12329                 (struct cmd_vf_mac_anti_spoof_result,
12330                  antispoof, "antispoof");
12331 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12332         TOKEN_NUM_INITIALIZER
12333                 (struct cmd_vf_mac_anti_spoof_result,
12334                  port_id, UINT16);
12335 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12336         TOKEN_NUM_INITIALIZER
12337                 (struct cmd_vf_mac_anti_spoof_result,
12338                  vf_id, UINT32);
12339 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12340         TOKEN_STRING_INITIALIZER
12341                 (struct cmd_vf_mac_anti_spoof_result,
12342                  on_off, "on#off");
12343
12344 static void
12345 cmd_set_vf_mac_anti_spoof_parsed(
12346         void *parsed_result,
12347         __attribute__((unused)) struct cmdline *cl,
12348         __attribute__((unused)) void *data)
12349 {
12350         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12351         int ret = -ENOTSUP;
12352
12353         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12354
12355         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12356                 return;
12357
12358 #ifdef RTE_LIBRTE_IXGBE_PMD
12359         if (ret == -ENOTSUP)
12360                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12361                         res->vf_id, is_on);
12362 #endif
12363 #ifdef RTE_LIBRTE_I40E_PMD
12364         if (ret == -ENOTSUP)
12365                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12366                         res->vf_id, is_on);
12367 #endif
12368 #ifdef RTE_LIBRTE_BNXT_PMD
12369         if (ret == -ENOTSUP)
12370                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12371                         res->vf_id, is_on);
12372 #endif
12373
12374         switch (ret) {
12375         case 0:
12376                 break;
12377         case -EINVAL:
12378                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12379                 break;
12380         case -ENODEV:
12381                 printf("invalid port_id %d\n", res->port_id);
12382                 break;
12383         case -ENOTSUP:
12384                 printf("function not implemented\n");
12385                 break;
12386         default:
12387                 printf("programming error: (%s)\n", strerror(-ret));
12388         }
12389 }
12390
12391 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12392         .f = cmd_set_vf_mac_anti_spoof_parsed,
12393         .data = NULL,
12394         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12395         .tokens = {
12396                 (void *)&cmd_vf_mac_anti_spoof_set,
12397                 (void *)&cmd_vf_mac_anti_spoof_vf,
12398                 (void *)&cmd_vf_mac_anti_spoof_mac,
12399                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12400                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12401                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12402                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12403                 NULL,
12404         },
12405 };
12406
12407 /* vf vlan strip queue configuration */
12408
12409 /* Common result structure for vf mac anti spoof */
12410 struct cmd_vf_vlan_stripq_result {
12411         cmdline_fixed_string_t set;
12412         cmdline_fixed_string_t vf;
12413         cmdline_fixed_string_t vlan;
12414         cmdline_fixed_string_t stripq;
12415         portid_t port_id;
12416         uint16_t vf_id;
12417         cmdline_fixed_string_t on_off;
12418 };
12419
12420 /* Common CLI fields for vf vlan strip enable disable */
12421 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12422         TOKEN_STRING_INITIALIZER
12423                 (struct cmd_vf_vlan_stripq_result,
12424                  set, "set");
12425 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12426         TOKEN_STRING_INITIALIZER
12427                 (struct cmd_vf_vlan_stripq_result,
12428                  vf, "vf");
12429 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12430         TOKEN_STRING_INITIALIZER
12431                 (struct cmd_vf_vlan_stripq_result,
12432                  vlan, "vlan");
12433 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12434         TOKEN_STRING_INITIALIZER
12435                 (struct cmd_vf_vlan_stripq_result,
12436                  stripq, "stripq");
12437 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12438         TOKEN_NUM_INITIALIZER
12439                 (struct cmd_vf_vlan_stripq_result,
12440                  port_id, UINT16);
12441 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12442         TOKEN_NUM_INITIALIZER
12443                 (struct cmd_vf_vlan_stripq_result,
12444                  vf_id, UINT16);
12445 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12446         TOKEN_STRING_INITIALIZER
12447                 (struct cmd_vf_vlan_stripq_result,
12448                  on_off, "on#off");
12449
12450 static void
12451 cmd_set_vf_vlan_stripq_parsed(
12452         void *parsed_result,
12453         __attribute__((unused)) struct cmdline *cl,
12454         __attribute__((unused)) void *data)
12455 {
12456         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12457         int ret = -ENOTSUP;
12458
12459         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12460
12461         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12462                 return;
12463
12464 #ifdef RTE_LIBRTE_IXGBE_PMD
12465         if (ret == -ENOTSUP)
12466                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12467                         res->vf_id, is_on);
12468 #endif
12469 #ifdef RTE_LIBRTE_I40E_PMD
12470         if (ret == -ENOTSUP)
12471                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12472                         res->vf_id, is_on);
12473 #endif
12474 #ifdef RTE_LIBRTE_BNXT_PMD
12475         if (ret == -ENOTSUP)
12476                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12477                         res->vf_id, is_on);
12478 #endif
12479
12480         switch (ret) {
12481         case 0:
12482                 break;
12483         case -EINVAL:
12484                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12485                 break;
12486         case -ENODEV:
12487                 printf("invalid port_id %d\n", res->port_id);
12488                 break;
12489         case -ENOTSUP:
12490                 printf("function not implemented\n");
12491                 break;
12492         default:
12493                 printf("programming error: (%s)\n", strerror(-ret));
12494         }
12495 }
12496
12497 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12498         .f = cmd_set_vf_vlan_stripq_parsed,
12499         .data = NULL,
12500         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12501         .tokens = {
12502                 (void *)&cmd_vf_vlan_stripq_set,
12503                 (void *)&cmd_vf_vlan_stripq_vf,
12504                 (void *)&cmd_vf_vlan_stripq_vlan,
12505                 (void *)&cmd_vf_vlan_stripq_stripq,
12506                 (void *)&cmd_vf_vlan_stripq_port_id,
12507                 (void *)&cmd_vf_vlan_stripq_vf_id,
12508                 (void *)&cmd_vf_vlan_stripq_on_off,
12509                 NULL,
12510         },
12511 };
12512
12513 /* vf vlan insert configuration */
12514
12515 /* Common result structure for vf vlan insert */
12516 struct cmd_vf_vlan_insert_result {
12517         cmdline_fixed_string_t set;
12518         cmdline_fixed_string_t vf;
12519         cmdline_fixed_string_t vlan;
12520         cmdline_fixed_string_t insert;
12521         portid_t port_id;
12522         uint16_t vf_id;
12523         uint16_t vlan_id;
12524 };
12525
12526 /* Common CLI fields for vf vlan insert enable disable */
12527 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12528         TOKEN_STRING_INITIALIZER
12529                 (struct cmd_vf_vlan_insert_result,
12530                  set, "set");
12531 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12532         TOKEN_STRING_INITIALIZER
12533                 (struct cmd_vf_vlan_insert_result,
12534                  vf, "vf");
12535 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12536         TOKEN_STRING_INITIALIZER
12537                 (struct cmd_vf_vlan_insert_result,
12538                  vlan, "vlan");
12539 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12540         TOKEN_STRING_INITIALIZER
12541                 (struct cmd_vf_vlan_insert_result,
12542                  insert, "insert");
12543 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12544         TOKEN_NUM_INITIALIZER
12545                 (struct cmd_vf_vlan_insert_result,
12546                  port_id, UINT16);
12547 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12548         TOKEN_NUM_INITIALIZER
12549                 (struct cmd_vf_vlan_insert_result,
12550                  vf_id, UINT16);
12551 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12552         TOKEN_NUM_INITIALIZER
12553                 (struct cmd_vf_vlan_insert_result,
12554                  vlan_id, UINT16);
12555
12556 static void
12557 cmd_set_vf_vlan_insert_parsed(
12558         void *parsed_result,
12559         __attribute__((unused)) struct cmdline *cl,
12560         __attribute__((unused)) void *data)
12561 {
12562         struct cmd_vf_vlan_insert_result *res = parsed_result;
12563         int ret = -ENOTSUP;
12564
12565         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12566                 return;
12567
12568 #ifdef RTE_LIBRTE_IXGBE_PMD
12569         if (ret == -ENOTSUP)
12570                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12571                         res->vlan_id);
12572 #endif
12573 #ifdef RTE_LIBRTE_I40E_PMD
12574         if (ret == -ENOTSUP)
12575                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12576                         res->vlan_id);
12577 #endif
12578 #ifdef RTE_LIBRTE_BNXT_PMD
12579         if (ret == -ENOTSUP)
12580                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12581                         res->vlan_id);
12582 #endif
12583
12584         switch (ret) {
12585         case 0:
12586                 break;
12587         case -EINVAL:
12588                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12589                 break;
12590         case -ENODEV:
12591                 printf("invalid port_id %d\n", res->port_id);
12592                 break;
12593         case -ENOTSUP:
12594                 printf("function not implemented\n");
12595                 break;
12596         default:
12597                 printf("programming error: (%s)\n", strerror(-ret));
12598         }
12599 }
12600
12601 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12602         .f = cmd_set_vf_vlan_insert_parsed,
12603         .data = NULL,
12604         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12605         .tokens = {
12606                 (void *)&cmd_vf_vlan_insert_set,
12607                 (void *)&cmd_vf_vlan_insert_vf,
12608                 (void *)&cmd_vf_vlan_insert_vlan,
12609                 (void *)&cmd_vf_vlan_insert_insert,
12610                 (void *)&cmd_vf_vlan_insert_port_id,
12611                 (void *)&cmd_vf_vlan_insert_vf_id,
12612                 (void *)&cmd_vf_vlan_insert_vlan_id,
12613                 NULL,
12614         },
12615 };
12616
12617 /* tx loopback configuration */
12618
12619 /* Common result structure for tx loopback */
12620 struct cmd_tx_loopback_result {
12621         cmdline_fixed_string_t set;
12622         cmdline_fixed_string_t tx;
12623         cmdline_fixed_string_t loopback;
12624         portid_t port_id;
12625         cmdline_fixed_string_t on_off;
12626 };
12627
12628 /* Common CLI fields for tx loopback enable disable */
12629 cmdline_parse_token_string_t cmd_tx_loopback_set =
12630         TOKEN_STRING_INITIALIZER
12631                 (struct cmd_tx_loopback_result,
12632                  set, "set");
12633 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12634         TOKEN_STRING_INITIALIZER
12635                 (struct cmd_tx_loopback_result,
12636                  tx, "tx");
12637 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12638         TOKEN_STRING_INITIALIZER
12639                 (struct cmd_tx_loopback_result,
12640                  loopback, "loopback");
12641 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12642         TOKEN_NUM_INITIALIZER
12643                 (struct cmd_tx_loopback_result,
12644                  port_id, UINT16);
12645 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12646         TOKEN_STRING_INITIALIZER
12647                 (struct cmd_tx_loopback_result,
12648                  on_off, "on#off");
12649
12650 static void
12651 cmd_set_tx_loopback_parsed(
12652         void *parsed_result,
12653         __attribute__((unused)) struct cmdline *cl,
12654         __attribute__((unused)) void *data)
12655 {
12656         struct cmd_tx_loopback_result *res = parsed_result;
12657         int ret = -ENOTSUP;
12658
12659         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12660
12661         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12662                 return;
12663
12664 #ifdef RTE_LIBRTE_IXGBE_PMD
12665         if (ret == -ENOTSUP)
12666                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12667 #endif
12668 #ifdef RTE_LIBRTE_I40E_PMD
12669         if (ret == -ENOTSUP)
12670                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12671 #endif
12672 #ifdef RTE_LIBRTE_BNXT_PMD
12673         if (ret == -ENOTSUP)
12674                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12675 #endif
12676
12677         switch (ret) {
12678         case 0:
12679                 break;
12680         case -EINVAL:
12681                 printf("invalid is_on %d\n", is_on);
12682                 break;
12683         case -ENODEV:
12684                 printf("invalid port_id %d\n", res->port_id);
12685                 break;
12686         case -ENOTSUP:
12687                 printf("function not implemented\n");
12688                 break;
12689         default:
12690                 printf("programming error: (%s)\n", strerror(-ret));
12691         }
12692 }
12693
12694 cmdline_parse_inst_t cmd_set_tx_loopback = {
12695         .f = cmd_set_tx_loopback_parsed,
12696         .data = NULL,
12697         .help_str = "set tx loopback <port_id> on|off",
12698         .tokens = {
12699                 (void *)&cmd_tx_loopback_set,
12700                 (void *)&cmd_tx_loopback_tx,
12701                 (void *)&cmd_tx_loopback_loopback,
12702                 (void *)&cmd_tx_loopback_port_id,
12703                 (void *)&cmd_tx_loopback_on_off,
12704                 NULL,
12705         },
12706 };
12707
12708 /* all queues drop enable configuration */
12709
12710 /* Common result structure for all queues drop enable */
12711 struct cmd_all_queues_drop_en_result {
12712         cmdline_fixed_string_t set;
12713         cmdline_fixed_string_t all;
12714         cmdline_fixed_string_t queues;
12715         cmdline_fixed_string_t drop;
12716         portid_t port_id;
12717         cmdline_fixed_string_t on_off;
12718 };
12719
12720 /* Common CLI fields for tx loopback enable disable */
12721 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12722         TOKEN_STRING_INITIALIZER
12723                 (struct cmd_all_queues_drop_en_result,
12724                  set, "set");
12725 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12726         TOKEN_STRING_INITIALIZER
12727                 (struct cmd_all_queues_drop_en_result,
12728                  all, "all");
12729 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12730         TOKEN_STRING_INITIALIZER
12731                 (struct cmd_all_queues_drop_en_result,
12732                  queues, "queues");
12733 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12734         TOKEN_STRING_INITIALIZER
12735                 (struct cmd_all_queues_drop_en_result,
12736                  drop, "drop");
12737 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12738         TOKEN_NUM_INITIALIZER
12739                 (struct cmd_all_queues_drop_en_result,
12740                  port_id, UINT16);
12741 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12742         TOKEN_STRING_INITIALIZER
12743                 (struct cmd_all_queues_drop_en_result,
12744                  on_off, "on#off");
12745
12746 static void
12747 cmd_set_all_queues_drop_en_parsed(
12748         void *parsed_result,
12749         __attribute__((unused)) struct cmdline *cl,
12750         __attribute__((unused)) void *data)
12751 {
12752         struct cmd_all_queues_drop_en_result *res = parsed_result;
12753         int ret = -ENOTSUP;
12754         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12755
12756         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12757                 return;
12758
12759 #ifdef RTE_LIBRTE_IXGBE_PMD
12760         if (ret == -ENOTSUP)
12761                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12762 #endif
12763 #ifdef RTE_LIBRTE_BNXT_PMD
12764         if (ret == -ENOTSUP)
12765                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12766 #endif
12767         switch (ret) {
12768         case 0:
12769                 break;
12770         case -EINVAL:
12771                 printf("invalid is_on %d\n", is_on);
12772                 break;
12773         case -ENODEV:
12774                 printf("invalid port_id %d\n", res->port_id);
12775                 break;
12776         case -ENOTSUP:
12777                 printf("function not implemented\n");
12778                 break;
12779         default:
12780                 printf("programming error: (%s)\n", strerror(-ret));
12781         }
12782 }
12783
12784 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12785         .f = cmd_set_all_queues_drop_en_parsed,
12786         .data = NULL,
12787         .help_str = "set all queues drop <port_id> on|off",
12788         .tokens = {
12789                 (void *)&cmd_all_queues_drop_en_set,
12790                 (void *)&cmd_all_queues_drop_en_all,
12791                 (void *)&cmd_all_queues_drop_en_queues,
12792                 (void *)&cmd_all_queues_drop_en_drop,
12793                 (void *)&cmd_all_queues_drop_en_port_id,
12794                 (void *)&cmd_all_queues_drop_en_on_off,
12795                 NULL,
12796         },
12797 };
12798
12799 /* vf split drop enable configuration */
12800
12801 /* Common result structure for vf split drop enable */
12802 struct cmd_vf_split_drop_en_result {
12803         cmdline_fixed_string_t set;
12804         cmdline_fixed_string_t vf;
12805         cmdline_fixed_string_t split;
12806         cmdline_fixed_string_t drop;
12807         portid_t port_id;
12808         uint16_t vf_id;
12809         cmdline_fixed_string_t on_off;
12810 };
12811
12812 /* Common CLI fields for vf split drop enable disable */
12813 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12814         TOKEN_STRING_INITIALIZER
12815                 (struct cmd_vf_split_drop_en_result,
12816                  set, "set");
12817 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12818         TOKEN_STRING_INITIALIZER
12819                 (struct cmd_vf_split_drop_en_result,
12820                  vf, "vf");
12821 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12822         TOKEN_STRING_INITIALIZER
12823                 (struct cmd_vf_split_drop_en_result,
12824                  split, "split");
12825 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12826         TOKEN_STRING_INITIALIZER
12827                 (struct cmd_vf_split_drop_en_result,
12828                  drop, "drop");
12829 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12830         TOKEN_NUM_INITIALIZER
12831                 (struct cmd_vf_split_drop_en_result,
12832                  port_id, UINT16);
12833 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12834         TOKEN_NUM_INITIALIZER
12835                 (struct cmd_vf_split_drop_en_result,
12836                  vf_id, UINT16);
12837 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12838         TOKEN_STRING_INITIALIZER
12839                 (struct cmd_vf_split_drop_en_result,
12840                  on_off, "on#off");
12841
12842 static void
12843 cmd_set_vf_split_drop_en_parsed(
12844         void *parsed_result,
12845         __attribute__((unused)) struct cmdline *cl,
12846         __attribute__((unused)) void *data)
12847 {
12848         struct cmd_vf_split_drop_en_result *res = parsed_result;
12849         int ret = -ENOTSUP;
12850         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12851
12852         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12853                 return;
12854
12855 #ifdef RTE_LIBRTE_IXGBE_PMD
12856         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12857                         is_on);
12858 #endif
12859         switch (ret) {
12860         case 0:
12861                 break;
12862         case -EINVAL:
12863                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12864                 break;
12865         case -ENODEV:
12866                 printf("invalid port_id %d\n", res->port_id);
12867                 break;
12868         case -ENOTSUP:
12869                 printf("not supported on port %d\n", res->port_id);
12870                 break;
12871         default:
12872                 printf("programming error: (%s)\n", strerror(-ret));
12873         }
12874 }
12875
12876 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12877         .f = cmd_set_vf_split_drop_en_parsed,
12878         .data = NULL,
12879         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12880         .tokens = {
12881                 (void *)&cmd_vf_split_drop_en_set,
12882                 (void *)&cmd_vf_split_drop_en_vf,
12883                 (void *)&cmd_vf_split_drop_en_split,
12884                 (void *)&cmd_vf_split_drop_en_drop,
12885                 (void *)&cmd_vf_split_drop_en_port_id,
12886                 (void *)&cmd_vf_split_drop_en_vf_id,
12887                 (void *)&cmd_vf_split_drop_en_on_off,
12888                 NULL,
12889         },
12890 };
12891
12892 /* vf mac address configuration */
12893
12894 /* Common result structure for vf mac address */
12895 struct cmd_set_vf_mac_addr_result {
12896         cmdline_fixed_string_t set;
12897         cmdline_fixed_string_t vf;
12898         cmdline_fixed_string_t mac;
12899         cmdline_fixed_string_t addr;
12900         portid_t port_id;
12901         uint16_t vf_id;
12902         struct ether_addr mac_addr;
12903
12904 };
12905
12906 /* Common CLI fields for vf split drop enable disable */
12907 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12908         TOKEN_STRING_INITIALIZER
12909                 (struct cmd_set_vf_mac_addr_result,
12910                  set, "set");
12911 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12912         TOKEN_STRING_INITIALIZER
12913                 (struct cmd_set_vf_mac_addr_result,
12914                  vf, "vf");
12915 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12916         TOKEN_STRING_INITIALIZER
12917                 (struct cmd_set_vf_mac_addr_result,
12918                  mac, "mac");
12919 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12920         TOKEN_STRING_INITIALIZER
12921                 (struct cmd_set_vf_mac_addr_result,
12922                  addr, "addr");
12923 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12924         TOKEN_NUM_INITIALIZER
12925                 (struct cmd_set_vf_mac_addr_result,
12926                  port_id, UINT16);
12927 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12928         TOKEN_NUM_INITIALIZER
12929                 (struct cmd_set_vf_mac_addr_result,
12930                  vf_id, UINT16);
12931 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12932         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12933                  mac_addr);
12934
12935 static void
12936 cmd_set_vf_mac_addr_parsed(
12937         void *parsed_result,
12938         __attribute__((unused)) struct cmdline *cl,
12939         __attribute__((unused)) void *data)
12940 {
12941         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12942         int ret = -ENOTSUP;
12943
12944         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12945                 return;
12946
12947 #ifdef RTE_LIBRTE_IXGBE_PMD
12948         if (ret == -ENOTSUP)
12949                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12950                                 &res->mac_addr);
12951 #endif
12952 #ifdef RTE_LIBRTE_I40E_PMD
12953         if (ret == -ENOTSUP)
12954                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12955                                 &res->mac_addr);
12956 #endif
12957 #ifdef RTE_LIBRTE_BNXT_PMD
12958         if (ret == -ENOTSUP)
12959                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12960                                 &res->mac_addr);
12961 #endif
12962
12963         switch (ret) {
12964         case 0:
12965                 break;
12966         case -EINVAL:
12967                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12968                 break;
12969         case -ENODEV:
12970                 printf("invalid port_id %d\n", res->port_id);
12971                 break;
12972         case -ENOTSUP:
12973                 printf("function not implemented\n");
12974                 break;
12975         default:
12976                 printf("programming error: (%s)\n", strerror(-ret));
12977         }
12978 }
12979
12980 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12981         .f = cmd_set_vf_mac_addr_parsed,
12982         .data = NULL,
12983         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12984         .tokens = {
12985                 (void *)&cmd_set_vf_mac_addr_set,
12986                 (void *)&cmd_set_vf_mac_addr_vf,
12987                 (void *)&cmd_set_vf_mac_addr_mac,
12988                 (void *)&cmd_set_vf_mac_addr_addr,
12989                 (void *)&cmd_set_vf_mac_addr_port_id,
12990                 (void *)&cmd_set_vf_mac_addr_vf_id,
12991                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12992                 NULL,
12993         },
12994 };
12995
12996 /* MACsec configuration */
12997
12998 /* Common result structure for MACsec offload enable */
12999 struct cmd_macsec_offload_on_result {
13000         cmdline_fixed_string_t set;
13001         cmdline_fixed_string_t macsec;
13002         cmdline_fixed_string_t offload;
13003         portid_t port_id;
13004         cmdline_fixed_string_t on;
13005         cmdline_fixed_string_t encrypt;
13006         cmdline_fixed_string_t en_on_off;
13007         cmdline_fixed_string_t replay_protect;
13008         cmdline_fixed_string_t rp_on_off;
13009 };
13010
13011 /* Common CLI fields for MACsec offload disable */
13012 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13013         TOKEN_STRING_INITIALIZER
13014                 (struct cmd_macsec_offload_on_result,
13015                  set, "set");
13016 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13017         TOKEN_STRING_INITIALIZER
13018                 (struct cmd_macsec_offload_on_result,
13019                  macsec, "macsec");
13020 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13021         TOKEN_STRING_INITIALIZER
13022                 (struct cmd_macsec_offload_on_result,
13023                  offload, "offload");
13024 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13025         TOKEN_NUM_INITIALIZER
13026                 (struct cmd_macsec_offload_on_result,
13027                  port_id, UINT16);
13028 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13029         TOKEN_STRING_INITIALIZER
13030                 (struct cmd_macsec_offload_on_result,
13031                  on, "on");
13032 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13033         TOKEN_STRING_INITIALIZER
13034                 (struct cmd_macsec_offload_on_result,
13035                  encrypt, "encrypt");
13036 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13037         TOKEN_STRING_INITIALIZER
13038                 (struct cmd_macsec_offload_on_result,
13039                  en_on_off, "on#off");
13040 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13041         TOKEN_STRING_INITIALIZER
13042                 (struct cmd_macsec_offload_on_result,
13043                  replay_protect, "replay-protect");
13044 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13045         TOKEN_STRING_INITIALIZER
13046                 (struct cmd_macsec_offload_on_result,
13047                  rp_on_off, "on#off");
13048
13049 static void
13050 cmd_set_macsec_offload_on_parsed(
13051         void *parsed_result,
13052         __attribute__((unused)) struct cmdline *cl,
13053         __attribute__((unused)) void *data)
13054 {
13055         struct cmd_macsec_offload_on_result *res = parsed_result;
13056         int ret = -ENOTSUP;
13057         portid_t port_id = res->port_id;
13058         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13059         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13060         struct rte_eth_dev_info dev_info;
13061
13062         if (port_id_is_invalid(port_id, ENABLED_WARN))
13063                 return;
13064         if (!port_is_stopped(port_id)) {
13065                 printf("Please stop port %d first\n", port_id);
13066                 return;
13067         }
13068
13069         rte_eth_dev_info_get(port_id, &dev_info);
13070         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13071 #ifdef RTE_LIBRTE_IXGBE_PMD
13072                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13073 #endif
13074         }
13075         RTE_SET_USED(en);
13076         RTE_SET_USED(rp);
13077
13078         switch (ret) {
13079         case 0:
13080                 ports[port_id].dev_conf.txmode.offloads |=
13081                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13082                 cmd_reconfig_device_queue(port_id, 1, 1);
13083                 break;
13084         case -ENODEV:
13085                 printf("invalid port_id %d\n", port_id);
13086                 break;
13087         case -ENOTSUP:
13088                 printf("not supported on port %d\n", port_id);
13089                 break;
13090         default:
13091                 printf("programming error: (%s)\n", strerror(-ret));
13092         }
13093 }
13094
13095 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13096         .f = cmd_set_macsec_offload_on_parsed,
13097         .data = NULL,
13098         .help_str = "set macsec offload <port_id> on "
13099                 "encrypt on|off replay-protect on|off",
13100         .tokens = {
13101                 (void *)&cmd_macsec_offload_on_set,
13102                 (void *)&cmd_macsec_offload_on_macsec,
13103                 (void *)&cmd_macsec_offload_on_offload,
13104                 (void *)&cmd_macsec_offload_on_port_id,
13105                 (void *)&cmd_macsec_offload_on_on,
13106                 (void *)&cmd_macsec_offload_on_encrypt,
13107                 (void *)&cmd_macsec_offload_on_en_on_off,
13108                 (void *)&cmd_macsec_offload_on_replay_protect,
13109                 (void *)&cmd_macsec_offload_on_rp_on_off,
13110                 NULL,
13111         },
13112 };
13113
13114 /* Common result structure for MACsec offload disable */
13115 struct cmd_macsec_offload_off_result {
13116         cmdline_fixed_string_t set;
13117         cmdline_fixed_string_t macsec;
13118         cmdline_fixed_string_t offload;
13119         portid_t port_id;
13120         cmdline_fixed_string_t off;
13121 };
13122
13123 /* Common CLI fields for MACsec offload disable */
13124 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13125         TOKEN_STRING_INITIALIZER
13126                 (struct cmd_macsec_offload_off_result,
13127                  set, "set");
13128 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13129         TOKEN_STRING_INITIALIZER
13130                 (struct cmd_macsec_offload_off_result,
13131                  macsec, "macsec");
13132 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13133         TOKEN_STRING_INITIALIZER
13134                 (struct cmd_macsec_offload_off_result,
13135                  offload, "offload");
13136 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13137         TOKEN_NUM_INITIALIZER
13138                 (struct cmd_macsec_offload_off_result,
13139                  port_id, UINT16);
13140 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13141         TOKEN_STRING_INITIALIZER
13142                 (struct cmd_macsec_offload_off_result,
13143                  off, "off");
13144
13145 static void
13146 cmd_set_macsec_offload_off_parsed(
13147         void *parsed_result,
13148         __attribute__((unused)) struct cmdline *cl,
13149         __attribute__((unused)) void *data)
13150 {
13151         struct cmd_macsec_offload_off_result *res = parsed_result;
13152         int ret = -ENOTSUP;
13153         struct rte_eth_dev_info dev_info;
13154         portid_t port_id = res->port_id;
13155
13156         if (port_id_is_invalid(port_id, ENABLED_WARN))
13157                 return;
13158         if (!port_is_stopped(port_id)) {
13159                 printf("Please stop port %d first\n", port_id);
13160                 return;
13161         }
13162
13163         rte_eth_dev_info_get(port_id, &dev_info);
13164         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13165 #ifdef RTE_LIBRTE_IXGBE_PMD
13166                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13167 #endif
13168         }
13169         switch (ret) {
13170         case 0:
13171                 ports[port_id].dev_conf.txmode.offloads &=
13172                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13173                 cmd_reconfig_device_queue(port_id, 1, 1);
13174                 break;
13175         case -ENODEV:
13176                 printf("invalid port_id %d\n", port_id);
13177                 break;
13178         case -ENOTSUP:
13179                 printf("not supported on port %d\n", port_id);
13180                 break;
13181         default:
13182                 printf("programming error: (%s)\n", strerror(-ret));
13183         }
13184 }
13185
13186 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13187         .f = cmd_set_macsec_offload_off_parsed,
13188         .data = NULL,
13189         .help_str = "set macsec offload <port_id> off",
13190         .tokens = {
13191                 (void *)&cmd_macsec_offload_off_set,
13192                 (void *)&cmd_macsec_offload_off_macsec,
13193                 (void *)&cmd_macsec_offload_off_offload,
13194                 (void *)&cmd_macsec_offload_off_port_id,
13195                 (void *)&cmd_macsec_offload_off_off,
13196                 NULL,
13197         },
13198 };
13199
13200 /* Common result structure for MACsec secure connection configure */
13201 struct cmd_macsec_sc_result {
13202         cmdline_fixed_string_t set;
13203         cmdline_fixed_string_t macsec;
13204         cmdline_fixed_string_t sc;
13205         cmdline_fixed_string_t tx_rx;
13206         portid_t port_id;
13207         struct ether_addr mac;
13208         uint16_t pi;
13209 };
13210
13211 /* Common CLI fields for MACsec secure connection configure */
13212 cmdline_parse_token_string_t cmd_macsec_sc_set =
13213         TOKEN_STRING_INITIALIZER
13214                 (struct cmd_macsec_sc_result,
13215                  set, "set");
13216 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13217         TOKEN_STRING_INITIALIZER
13218                 (struct cmd_macsec_sc_result,
13219                  macsec, "macsec");
13220 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13221         TOKEN_STRING_INITIALIZER
13222                 (struct cmd_macsec_sc_result,
13223                  sc, "sc");
13224 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13225         TOKEN_STRING_INITIALIZER
13226                 (struct cmd_macsec_sc_result,
13227                  tx_rx, "tx#rx");
13228 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13229         TOKEN_NUM_INITIALIZER
13230                 (struct cmd_macsec_sc_result,
13231                  port_id, UINT16);
13232 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13233         TOKEN_ETHERADDR_INITIALIZER
13234                 (struct cmd_macsec_sc_result,
13235                  mac);
13236 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13237         TOKEN_NUM_INITIALIZER
13238                 (struct cmd_macsec_sc_result,
13239                  pi, UINT16);
13240
13241 static void
13242 cmd_set_macsec_sc_parsed(
13243         void *parsed_result,
13244         __attribute__((unused)) struct cmdline *cl,
13245         __attribute__((unused)) void *data)
13246 {
13247         struct cmd_macsec_sc_result *res = parsed_result;
13248         int ret = -ENOTSUP;
13249         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13250
13251 #ifdef RTE_LIBRTE_IXGBE_PMD
13252         ret = is_tx ?
13253                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13254                                 res->mac.addr_bytes) :
13255                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13256                                 res->mac.addr_bytes, res->pi);
13257 #endif
13258         RTE_SET_USED(is_tx);
13259
13260         switch (ret) {
13261         case 0:
13262                 break;
13263         case -ENODEV:
13264                 printf("invalid port_id %d\n", res->port_id);
13265                 break;
13266         case -ENOTSUP:
13267                 printf("not supported on port %d\n", res->port_id);
13268                 break;
13269         default:
13270                 printf("programming error: (%s)\n", strerror(-ret));
13271         }
13272 }
13273
13274 cmdline_parse_inst_t cmd_set_macsec_sc = {
13275         .f = cmd_set_macsec_sc_parsed,
13276         .data = NULL,
13277         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13278         .tokens = {
13279                 (void *)&cmd_macsec_sc_set,
13280                 (void *)&cmd_macsec_sc_macsec,
13281                 (void *)&cmd_macsec_sc_sc,
13282                 (void *)&cmd_macsec_sc_tx_rx,
13283                 (void *)&cmd_macsec_sc_port_id,
13284                 (void *)&cmd_macsec_sc_mac,
13285                 (void *)&cmd_macsec_sc_pi,
13286                 NULL,
13287         },
13288 };
13289
13290 /* Common result structure for MACsec secure connection configure */
13291 struct cmd_macsec_sa_result {
13292         cmdline_fixed_string_t set;
13293         cmdline_fixed_string_t macsec;
13294         cmdline_fixed_string_t sa;
13295         cmdline_fixed_string_t tx_rx;
13296         portid_t port_id;
13297         uint8_t idx;
13298         uint8_t an;
13299         uint32_t pn;
13300         cmdline_fixed_string_t key;
13301 };
13302
13303 /* Common CLI fields for MACsec secure connection configure */
13304 cmdline_parse_token_string_t cmd_macsec_sa_set =
13305         TOKEN_STRING_INITIALIZER
13306                 (struct cmd_macsec_sa_result,
13307                  set, "set");
13308 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13309         TOKEN_STRING_INITIALIZER
13310                 (struct cmd_macsec_sa_result,
13311                  macsec, "macsec");
13312 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13313         TOKEN_STRING_INITIALIZER
13314                 (struct cmd_macsec_sa_result,
13315                  sa, "sa");
13316 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13317         TOKEN_STRING_INITIALIZER
13318                 (struct cmd_macsec_sa_result,
13319                  tx_rx, "tx#rx");
13320 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13321         TOKEN_NUM_INITIALIZER
13322                 (struct cmd_macsec_sa_result,
13323                  port_id, UINT16);
13324 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13325         TOKEN_NUM_INITIALIZER
13326                 (struct cmd_macsec_sa_result,
13327                  idx, UINT8);
13328 cmdline_parse_token_num_t cmd_macsec_sa_an =
13329         TOKEN_NUM_INITIALIZER
13330                 (struct cmd_macsec_sa_result,
13331                  an, UINT8);
13332 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13333         TOKEN_NUM_INITIALIZER
13334                 (struct cmd_macsec_sa_result,
13335                  pn, UINT32);
13336 cmdline_parse_token_string_t cmd_macsec_sa_key =
13337         TOKEN_STRING_INITIALIZER
13338                 (struct cmd_macsec_sa_result,
13339                  key, NULL);
13340
13341 static void
13342 cmd_set_macsec_sa_parsed(
13343         void *parsed_result,
13344         __attribute__((unused)) struct cmdline *cl,
13345         __attribute__((unused)) void *data)
13346 {
13347         struct cmd_macsec_sa_result *res = parsed_result;
13348         int ret = -ENOTSUP;
13349         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13350         uint8_t key[16] = { 0 };
13351         uint8_t xdgt0;
13352         uint8_t xdgt1;
13353         int key_len;
13354         int i;
13355
13356         key_len = strlen(res->key) / 2;
13357         if (key_len > 16)
13358                 key_len = 16;
13359
13360         for (i = 0; i < key_len; i++) {
13361                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13362                 if (xdgt0 == 0xFF)
13363                         return;
13364                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13365                 if (xdgt1 == 0xFF)
13366                         return;
13367                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13368         }
13369
13370 #ifdef RTE_LIBRTE_IXGBE_PMD
13371         ret = is_tx ?
13372                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13373                         res->idx, res->an, res->pn, key) :
13374                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13375                         res->idx, res->an, res->pn, key);
13376 #endif
13377         RTE_SET_USED(is_tx);
13378         RTE_SET_USED(key);
13379
13380         switch (ret) {
13381         case 0:
13382                 break;
13383         case -EINVAL:
13384                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13385                 break;
13386         case -ENODEV:
13387                 printf("invalid port_id %d\n", res->port_id);
13388                 break;
13389         case -ENOTSUP:
13390                 printf("not supported on port %d\n", res->port_id);
13391                 break;
13392         default:
13393                 printf("programming error: (%s)\n", strerror(-ret));
13394         }
13395 }
13396
13397 cmdline_parse_inst_t cmd_set_macsec_sa = {
13398         .f = cmd_set_macsec_sa_parsed,
13399         .data = NULL,
13400         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13401         .tokens = {
13402                 (void *)&cmd_macsec_sa_set,
13403                 (void *)&cmd_macsec_sa_macsec,
13404                 (void *)&cmd_macsec_sa_sa,
13405                 (void *)&cmd_macsec_sa_tx_rx,
13406                 (void *)&cmd_macsec_sa_port_id,
13407                 (void *)&cmd_macsec_sa_idx,
13408                 (void *)&cmd_macsec_sa_an,
13409                 (void *)&cmd_macsec_sa_pn,
13410                 (void *)&cmd_macsec_sa_key,
13411                 NULL,
13412         },
13413 };
13414
13415 /* VF unicast promiscuous mode configuration */
13416
13417 /* Common result structure for VF unicast promiscuous mode */
13418 struct cmd_vf_promisc_result {
13419         cmdline_fixed_string_t set;
13420         cmdline_fixed_string_t vf;
13421         cmdline_fixed_string_t promisc;
13422         portid_t port_id;
13423         uint32_t vf_id;
13424         cmdline_fixed_string_t on_off;
13425 };
13426
13427 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13428 cmdline_parse_token_string_t cmd_vf_promisc_set =
13429         TOKEN_STRING_INITIALIZER
13430                 (struct cmd_vf_promisc_result,
13431                  set, "set");
13432 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13433         TOKEN_STRING_INITIALIZER
13434                 (struct cmd_vf_promisc_result,
13435                  vf, "vf");
13436 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13437         TOKEN_STRING_INITIALIZER
13438                 (struct cmd_vf_promisc_result,
13439                  promisc, "promisc");
13440 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13441         TOKEN_NUM_INITIALIZER
13442                 (struct cmd_vf_promisc_result,
13443                  port_id, UINT16);
13444 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13445         TOKEN_NUM_INITIALIZER
13446                 (struct cmd_vf_promisc_result,
13447                  vf_id, UINT32);
13448 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13449         TOKEN_STRING_INITIALIZER
13450                 (struct cmd_vf_promisc_result,
13451                  on_off, "on#off");
13452
13453 static void
13454 cmd_set_vf_promisc_parsed(
13455         void *parsed_result,
13456         __attribute__((unused)) struct cmdline *cl,
13457         __attribute__((unused)) void *data)
13458 {
13459         struct cmd_vf_promisc_result *res = parsed_result;
13460         int ret = -ENOTSUP;
13461
13462         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13463
13464         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13465                 return;
13466
13467 #ifdef RTE_LIBRTE_I40E_PMD
13468         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13469                                                   res->vf_id, is_on);
13470 #endif
13471
13472         switch (ret) {
13473         case 0:
13474                 break;
13475         case -EINVAL:
13476                 printf("invalid vf_id %d\n", res->vf_id);
13477                 break;
13478         case -ENODEV:
13479                 printf("invalid port_id %d\n", res->port_id);
13480                 break;
13481         case -ENOTSUP:
13482                 printf("function not implemented\n");
13483                 break;
13484         default:
13485                 printf("programming error: (%s)\n", strerror(-ret));
13486         }
13487 }
13488
13489 cmdline_parse_inst_t cmd_set_vf_promisc = {
13490         .f = cmd_set_vf_promisc_parsed,
13491         .data = NULL,
13492         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13493                 "Set unicast promiscuous mode for a VF from the PF",
13494         .tokens = {
13495                 (void *)&cmd_vf_promisc_set,
13496                 (void *)&cmd_vf_promisc_vf,
13497                 (void *)&cmd_vf_promisc_promisc,
13498                 (void *)&cmd_vf_promisc_port_id,
13499                 (void *)&cmd_vf_promisc_vf_id,
13500                 (void *)&cmd_vf_promisc_on_off,
13501                 NULL,
13502         },
13503 };
13504
13505 /* VF multicast promiscuous mode configuration */
13506
13507 /* Common result structure for VF multicast promiscuous mode */
13508 struct cmd_vf_allmulti_result {
13509         cmdline_fixed_string_t set;
13510         cmdline_fixed_string_t vf;
13511         cmdline_fixed_string_t allmulti;
13512         portid_t port_id;
13513         uint32_t vf_id;
13514         cmdline_fixed_string_t on_off;
13515 };
13516
13517 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13518 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13519         TOKEN_STRING_INITIALIZER
13520                 (struct cmd_vf_allmulti_result,
13521                  set, "set");
13522 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13523         TOKEN_STRING_INITIALIZER
13524                 (struct cmd_vf_allmulti_result,
13525                  vf, "vf");
13526 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13527         TOKEN_STRING_INITIALIZER
13528                 (struct cmd_vf_allmulti_result,
13529                  allmulti, "allmulti");
13530 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13531         TOKEN_NUM_INITIALIZER
13532                 (struct cmd_vf_allmulti_result,
13533                  port_id, UINT16);
13534 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13535         TOKEN_NUM_INITIALIZER
13536                 (struct cmd_vf_allmulti_result,
13537                  vf_id, UINT32);
13538 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13539         TOKEN_STRING_INITIALIZER
13540                 (struct cmd_vf_allmulti_result,
13541                  on_off, "on#off");
13542
13543 static void
13544 cmd_set_vf_allmulti_parsed(
13545         void *parsed_result,
13546         __attribute__((unused)) struct cmdline *cl,
13547         __attribute__((unused)) void *data)
13548 {
13549         struct cmd_vf_allmulti_result *res = parsed_result;
13550         int ret = -ENOTSUP;
13551
13552         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13553
13554         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13555                 return;
13556
13557 #ifdef RTE_LIBRTE_I40E_PMD
13558         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13559                                                     res->vf_id, is_on);
13560 #endif
13561
13562         switch (ret) {
13563         case 0:
13564                 break;
13565         case -EINVAL:
13566                 printf("invalid vf_id %d\n", res->vf_id);
13567                 break;
13568         case -ENODEV:
13569                 printf("invalid port_id %d\n", res->port_id);
13570                 break;
13571         case -ENOTSUP:
13572                 printf("function not implemented\n");
13573                 break;
13574         default:
13575                 printf("programming error: (%s)\n", strerror(-ret));
13576         }
13577 }
13578
13579 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13580         .f = cmd_set_vf_allmulti_parsed,
13581         .data = NULL,
13582         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13583                 "Set multicast promiscuous mode for a VF from the PF",
13584         .tokens = {
13585                 (void *)&cmd_vf_allmulti_set,
13586                 (void *)&cmd_vf_allmulti_vf,
13587                 (void *)&cmd_vf_allmulti_allmulti,
13588                 (void *)&cmd_vf_allmulti_port_id,
13589                 (void *)&cmd_vf_allmulti_vf_id,
13590                 (void *)&cmd_vf_allmulti_on_off,
13591                 NULL,
13592         },
13593 };
13594
13595 /* vf broadcast mode configuration */
13596
13597 /* Common result structure for vf broadcast */
13598 struct cmd_set_vf_broadcast_result {
13599         cmdline_fixed_string_t set;
13600         cmdline_fixed_string_t vf;
13601         cmdline_fixed_string_t broadcast;
13602         portid_t port_id;
13603         uint16_t vf_id;
13604         cmdline_fixed_string_t on_off;
13605 };
13606
13607 /* Common CLI fields for vf broadcast enable disable */
13608 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13609         TOKEN_STRING_INITIALIZER
13610                 (struct cmd_set_vf_broadcast_result,
13611                  set, "set");
13612 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13613         TOKEN_STRING_INITIALIZER
13614                 (struct cmd_set_vf_broadcast_result,
13615                  vf, "vf");
13616 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13617         TOKEN_STRING_INITIALIZER
13618                 (struct cmd_set_vf_broadcast_result,
13619                  broadcast, "broadcast");
13620 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13621         TOKEN_NUM_INITIALIZER
13622                 (struct cmd_set_vf_broadcast_result,
13623                  port_id, UINT16);
13624 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13625         TOKEN_NUM_INITIALIZER
13626                 (struct cmd_set_vf_broadcast_result,
13627                  vf_id, UINT16);
13628 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13629         TOKEN_STRING_INITIALIZER
13630                 (struct cmd_set_vf_broadcast_result,
13631                  on_off, "on#off");
13632
13633 static void
13634 cmd_set_vf_broadcast_parsed(
13635         void *parsed_result,
13636         __attribute__((unused)) struct cmdline *cl,
13637         __attribute__((unused)) void *data)
13638 {
13639         struct cmd_set_vf_broadcast_result *res = parsed_result;
13640         int ret = -ENOTSUP;
13641
13642         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13643
13644         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13645                 return;
13646
13647 #ifdef RTE_LIBRTE_I40E_PMD
13648         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13649                                             res->vf_id, is_on);
13650 #endif
13651
13652         switch (ret) {
13653         case 0:
13654                 break;
13655         case -EINVAL:
13656                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13657                 break;
13658         case -ENODEV:
13659                 printf("invalid port_id %d\n", res->port_id);
13660                 break;
13661         case -ENOTSUP:
13662                 printf("function not implemented\n");
13663                 break;
13664         default:
13665                 printf("programming error: (%s)\n", strerror(-ret));
13666         }
13667 }
13668
13669 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13670         .f = cmd_set_vf_broadcast_parsed,
13671         .data = NULL,
13672         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13673         .tokens = {
13674                 (void *)&cmd_set_vf_broadcast_set,
13675                 (void *)&cmd_set_vf_broadcast_vf,
13676                 (void *)&cmd_set_vf_broadcast_broadcast,
13677                 (void *)&cmd_set_vf_broadcast_port_id,
13678                 (void *)&cmd_set_vf_broadcast_vf_id,
13679                 (void *)&cmd_set_vf_broadcast_on_off,
13680                 NULL,
13681         },
13682 };
13683
13684 /* vf vlan tag configuration */
13685
13686 /* Common result structure for vf vlan tag */
13687 struct cmd_set_vf_vlan_tag_result {
13688         cmdline_fixed_string_t set;
13689         cmdline_fixed_string_t vf;
13690         cmdline_fixed_string_t vlan;
13691         cmdline_fixed_string_t tag;
13692         portid_t port_id;
13693         uint16_t vf_id;
13694         cmdline_fixed_string_t on_off;
13695 };
13696
13697 /* Common CLI fields for vf vlan tag enable disable */
13698 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13699         TOKEN_STRING_INITIALIZER
13700                 (struct cmd_set_vf_vlan_tag_result,
13701                  set, "set");
13702 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13703         TOKEN_STRING_INITIALIZER
13704                 (struct cmd_set_vf_vlan_tag_result,
13705                  vf, "vf");
13706 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13707         TOKEN_STRING_INITIALIZER
13708                 (struct cmd_set_vf_vlan_tag_result,
13709                  vlan, "vlan");
13710 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13711         TOKEN_STRING_INITIALIZER
13712                 (struct cmd_set_vf_vlan_tag_result,
13713                  tag, "tag");
13714 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13715         TOKEN_NUM_INITIALIZER
13716                 (struct cmd_set_vf_vlan_tag_result,
13717                  port_id, UINT16);
13718 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13719         TOKEN_NUM_INITIALIZER
13720                 (struct cmd_set_vf_vlan_tag_result,
13721                  vf_id, UINT16);
13722 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13723         TOKEN_STRING_INITIALIZER
13724                 (struct cmd_set_vf_vlan_tag_result,
13725                  on_off, "on#off");
13726
13727 static void
13728 cmd_set_vf_vlan_tag_parsed(
13729         void *parsed_result,
13730         __attribute__((unused)) struct cmdline *cl,
13731         __attribute__((unused)) void *data)
13732 {
13733         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13734         int ret = -ENOTSUP;
13735
13736         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13737
13738         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13739                 return;
13740
13741 #ifdef RTE_LIBRTE_I40E_PMD
13742         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13743                                            res->vf_id, is_on);
13744 #endif
13745
13746         switch (ret) {
13747         case 0:
13748                 break;
13749         case -EINVAL:
13750                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13751                 break;
13752         case -ENODEV:
13753                 printf("invalid port_id %d\n", res->port_id);
13754                 break;
13755         case -ENOTSUP:
13756                 printf("function not implemented\n");
13757                 break;
13758         default:
13759                 printf("programming error: (%s)\n", strerror(-ret));
13760         }
13761 }
13762
13763 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13764         .f = cmd_set_vf_vlan_tag_parsed,
13765         .data = NULL,
13766         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13767         .tokens = {
13768                 (void *)&cmd_set_vf_vlan_tag_set,
13769                 (void *)&cmd_set_vf_vlan_tag_vf,
13770                 (void *)&cmd_set_vf_vlan_tag_vlan,
13771                 (void *)&cmd_set_vf_vlan_tag_tag,
13772                 (void *)&cmd_set_vf_vlan_tag_port_id,
13773                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13774                 (void *)&cmd_set_vf_vlan_tag_on_off,
13775                 NULL,
13776         },
13777 };
13778
13779 /* Common definition of VF and TC TX bandwidth configuration */
13780 struct cmd_vf_tc_bw_result {
13781         cmdline_fixed_string_t set;
13782         cmdline_fixed_string_t vf;
13783         cmdline_fixed_string_t tc;
13784         cmdline_fixed_string_t tx;
13785         cmdline_fixed_string_t min_bw;
13786         cmdline_fixed_string_t max_bw;
13787         cmdline_fixed_string_t strict_link_prio;
13788         portid_t port_id;
13789         uint16_t vf_id;
13790         uint8_t tc_no;
13791         uint32_t bw;
13792         cmdline_fixed_string_t bw_list;
13793         uint8_t tc_map;
13794 };
13795
13796 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13797         TOKEN_STRING_INITIALIZER
13798                 (struct cmd_vf_tc_bw_result,
13799                  set, "set");
13800 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13801         TOKEN_STRING_INITIALIZER
13802                 (struct cmd_vf_tc_bw_result,
13803                  vf, "vf");
13804 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13805         TOKEN_STRING_INITIALIZER
13806                 (struct cmd_vf_tc_bw_result,
13807                  tc, "tc");
13808 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13809         TOKEN_STRING_INITIALIZER
13810                 (struct cmd_vf_tc_bw_result,
13811                  tx, "tx");
13812 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13813         TOKEN_STRING_INITIALIZER
13814                 (struct cmd_vf_tc_bw_result,
13815                  strict_link_prio, "strict-link-priority");
13816 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13817         TOKEN_STRING_INITIALIZER
13818                 (struct cmd_vf_tc_bw_result,
13819                  min_bw, "min-bandwidth");
13820 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13821         TOKEN_STRING_INITIALIZER
13822                 (struct cmd_vf_tc_bw_result,
13823                  max_bw, "max-bandwidth");
13824 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13825         TOKEN_NUM_INITIALIZER
13826                 (struct cmd_vf_tc_bw_result,
13827                  port_id, UINT16);
13828 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13829         TOKEN_NUM_INITIALIZER
13830                 (struct cmd_vf_tc_bw_result,
13831                  vf_id, UINT16);
13832 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13833         TOKEN_NUM_INITIALIZER
13834                 (struct cmd_vf_tc_bw_result,
13835                  tc_no, UINT8);
13836 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13837         TOKEN_NUM_INITIALIZER
13838                 (struct cmd_vf_tc_bw_result,
13839                  bw, UINT32);
13840 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13841         TOKEN_STRING_INITIALIZER
13842                 (struct cmd_vf_tc_bw_result,
13843                  bw_list, NULL);
13844 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13845         TOKEN_NUM_INITIALIZER
13846                 (struct cmd_vf_tc_bw_result,
13847                  tc_map, UINT8);
13848
13849 /* VF max bandwidth setting */
13850 static void
13851 cmd_vf_max_bw_parsed(
13852         void *parsed_result,
13853         __attribute__((unused)) struct cmdline *cl,
13854         __attribute__((unused)) void *data)
13855 {
13856         struct cmd_vf_tc_bw_result *res = parsed_result;
13857         int ret = -ENOTSUP;
13858
13859         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13860                 return;
13861
13862 #ifdef RTE_LIBRTE_I40E_PMD
13863         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13864                                          res->vf_id, res->bw);
13865 #endif
13866
13867         switch (ret) {
13868         case 0:
13869                 break;
13870         case -EINVAL:
13871                 printf("invalid vf_id %d or bandwidth %d\n",
13872                        res->vf_id, res->bw);
13873                 break;
13874         case -ENODEV:
13875                 printf("invalid port_id %d\n", res->port_id);
13876                 break;
13877         case -ENOTSUP:
13878                 printf("function not implemented\n");
13879                 break;
13880         default:
13881                 printf("programming error: (%s)\n", strerror(-ret));
13882         }
13883 }
13884
13885 cmdline_parse_inst_t cmd_vf_max_bw = {
13886         .f = cmd_vf_max_bw_parsed,
13887         .data = NULL,
13888         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13889         .tokens = {
13890                 (void *)&cmd_vf_tc_bw_set,
13891                 (void *)&cmd_vf_tc_bw_vf,
13892                 (void *)&cmd_vf_tc_bw_tx,
13893                 (void *)&cmd_vf_tc_bw_max_bw,
13894                 (void *)&cmd_vf_tc_bw_port_id,
13895                 (void *)&cmd_vf_tc_bw_vf_id,
13896                 (void *)&cmd_vf_tc_bw_bw,
13897                 NULL,
13898         },
13899 };
13900
13901 static int
13902 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13903                            uint8_t *tc_num,
13904                            char *str)
13905 {
13906         uint32_t size;
13907         const char *p, *p0 = str;
13908         char s[256];
13909         char *end;
13910         char *str_fld[16];
13911         uint16_t i;
13912         int ret;
13913
13914         p = strchr(p0, '(');
13915         if (p == NULL) {
13916                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13917                 return -1;
13918         }
13919         p++;
13920         p0 = strchr(p, ')');
13921         if (p0 == NULL) {
13922                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13923                 return -1;
13924         }
13925         size = p0 - p;
13926         if (size >= sizeof(s)) {
13927                 printf("The string size exceeds the internal buffer size\n");
13928                 return -1;
13929         }
13930         snprintf(s, sizeof(s), "%.*s", size, p);
13931         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13932         if (ret <= 0) {
13933                 printf("Failed to get the bandwidth list. ");
13934                 return -1;
13935         }
13936         *tc_num = ret;
13937         for (i = 0; i < ret; i++)
13938                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13939
13940         return 0;
13941 }
13942
13943 /* TC min bandwidth setting */
13944 static void
13945 cmd_vf_tc_min_bw_parsed(
13946         void *parsed_result,
13947         __attribute__((unused)) struct cmdline *cl,
13948         __attribute__((unused)) void *data)
13949 {
13950         struct cmd_vf_tc_bw_result *res = parsed_result;
13951         uint8_t tc_num;
13952         uint8_t bw[16];
13953         int ret = -ENOTSUP;
13954
13955         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13956                 return;
13957
13958         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13959         if (ret)
13960                 return;
13961
13962 #ifdef RTE_LIBRTE_I40E_PMD
13963         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13964                                               tc_num, bw);
13965 #endif
13966
13967         switch (ret) {
13968         case 0:
13969                 break;
13970         case -EINVAL:
13971                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13972                 break;
13973         case -ENODEV:
13974                 printf("invalid port_id %d\n", res->port_id);
13975                 break;
13976         case -ENOTSUP:
13977                 printf("function not implemented\n");
13978                 break;
13979         default:
13980                 printf("programming error: (%s)\n", strerror(-ret));
13981         }
13982 }
13983
13984 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13985         .f = cmd_vf_tc_min_bw_parsed,
13986         .data = NULL,
13987         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13988                     " <bw1, bw2, ...>",
13989         .tokens = {
13990                 (void *)&cmd_vf_tc_bw_set,
13991                 (void *)&cmd_vf_tc_bw_vf,
13992                 (void *)&cmd_vf_tc_bw_tc,
13993                 (void *)&cmd_vf_tc_bw_tx,
13994                 (void *)&cmd_vf_tc_bw_min_bw,
13995                 (void *)&cmd_vf_tc_bw_port_id,
13996                 (void *)&cmd_vf_tc_bw_vf_id,
13997                 (void *)&cmd_vf_tc_bw_bw_list,
13998                 NULL,
13999         },
14000 };
14001
14002 static void
14003 cmd_tc_min_bw_parsed(
14004         void *parsed_result,
14005         __attribute__((unused)) struct cmdline *cl,
14006         __attribute__((unused)) void *data)
14007 {
14008         struct cmd_vf_tc_bw_result *res = parsed_result;
14009         struct rte_port *port;
14010         uint8_t tc_num;
14011         uint8_t bw[16];
14012         int ret = -ENOTSUP;
14013
14014         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14015                 return;
14016
14017         port = &ports[res->port_id];
14018         /** Check if the port is not started **/
14019         if (port->port_status != RTE_PORT_STOPPED) {
14020                 printf("Please stop port %d first\n", res->port_id);
14021                 return;
14022         }
14023
14024         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14025         if (ret)
14026                 return;
14027
14028 #ifdef RTE_LIBRTE_IXGBE_PMD
14029         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14030 #endif
14031
14032         switch (ret) {
14033         case 0:
14034                 break;
14035         case -EINVAL:
14036                 printf("invalid bandwidth\n");
14037                 break;
14038         case -ENODEV:
14039                 printf("invalid port_id %d\n", res->port_id);
14040                 break;
14041         case -ENOTSUP:
14042                 printf("function not implemented\n");
14043                 break;
14044         default:
14045                 printf("programming error: (%s)\n", strerror(-ret));
14046         }
14047 }
14048
14049 cmdline_parse_inst_t cmd_tc_min_bw = {
14050         .f = cmd_tc_min_bw_parsed,
14051         .data = NULL,
14052         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14053         .tokens = {
14054                 (void *)&cmd_vf_tc_bw_set,
14055                 (void *)&cmd_vf_tc_bw_tc,
14056                 (void *)&cmd_vf_tc_bw_tx,
14057                 (void *)&cmd_vf_tc_bw_min_bw,
14058                 (void *)&cmd_vf_tc_bw_port_id,
14059                 (void *)&cmd_vf_tc_bw_bw_list,
14060                 NULL,
14061         },
14062 };
14063
14064 /* TC max bandwidth setting */
14065 static void
14066 cmd_vf_tc_max_bw_parsed(
14067         void *parsed_result,
14068         __attribute__((unused)) struct cmdline *cl,
14069         __attribute__((unused)) void *data)
14070 {
14071         struct cmd_vf_tc_bw_result *res = parsed_result;
14072         int ret = -ENOTSUP;
14073
14074         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14075                 return;
14076
14077 #ifdef RTE_LIBRTE_I40E_PMD
14078         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14079                                             res->tc_no, res->bw);
14080 #endif
14081
14082         switch (ret) {
14083         case 0:
14084                 break;
14085         case -EINVAL:
14086                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14087                        res->vf_id, res->tc_no, res->bw);
14088                 break;
14089         case -ENODEV:
14090                 printf("invalid port_id %d\n", res->port_id);
14091                 break;
14092         case -ENOTSUP:
14093                 printf("function not implemented\n");
14094                 break;
14095         default:
14096                 printf("programming error: (%s)\n", strerror(-ret));
14097         }
14098 }
14099
14100 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14101         .f = cmd_vf_tc_max_bw_parsed,
14102         .data = NULL,
14103         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14104                     " <bandwidth>",
14105         .tokens = {
14106                 (void *)&cmd_vf_tc_bw_set,
14107                 (void *)&cmd_vf_tc_bw_vf,
14108                 (void *)&cmd_vf_tc_bw_tc,
14109                 (void *)&cmd_vf_tc_bw_tx,
14110                 (void *)&cmd_vf_tc_bw_max_bw,
14111                 (void *)&cmd_vf_tc_bw_port_id,
14112                 (void *)&cmd_vf_tc_bw_vf_id,
14113                 (void *)&cmd_vf_tc_bw_tc_no,
14114                 (void *)&cmd_vf_tc_bw_bw,
14115                 NULL,
14116         },
14117 };
14118
14119
14120 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14121
14122 /* *** Set Port default Traffic Management Hierarchy *** */
14123 struct cmd_set_port_tm_hierarchy_default_result {
14124         cmdline_fixed_string_t set;
14125         cmdline_fixed_string_t port;
14126         cmdline_fixed_string_t tm;
14127         cmdline_fixed_string_t hierarchy;
14128         cmdline_fixed_string_t def;
14129         portid_t port_id;
14130 };
14131
14132 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14133         TOKEN_STRING_INITIALIZER(
14134                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14135 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14136         TOKEN_STRING_INITIALIZER(
14137                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14138 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14139         TOKEN_STRING_INITIALIZER(
14140                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14141 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14142         TOKEN_STRING_INITIALIZER(
14143                 struct cmd_set_port_tm_hierarchy_default_result,
14144                         hierarchy, "hierarchy");
14145 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14146         TOKEN_STRING_INITIALIZER(
14147                 struct cmd_set_port_tm_hierarchy_default_result,
14148                         def, "default");
14149 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14150         TOKEN_NUM_INITIALIZER(
14151                 struct cmd_set_port_tm_hierarchy_default_result,
14152                         port_id, UINT16);
14153
14154 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14155         __attribute__((unused)) struct cmdline *cl,
14156         __attribute__((unused)) void *data)
14157 {
14158         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14159         struct rte_port *p;
14160         portid_t port_id = res->port_id;
14161
14162         if (port_id_is_invalid(port_id, ENABLED_WARN))
14163                 return;
14164
14165         p = &ports[port_id];
14166
14167         /* Port tm flag */
14168         if (p->softport.tm_flag == 0) {
14169                 printf("  tm not enabled on port %u (error)\n", port_id);
14170                 return;
14171         }
14172
14173         /* Forward mode: tm */
14174         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14175                 printf("  tm mode not enabled(error)\n");
14176                 return;
14177         }
14178
14179         /* Set the default tm hierarchy */
14180         p->softport.tm.default_hierarchy_enable = 1;
14181 }
14182
14183 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14184         .f = cmd_set_port_tm_hierarchy_default_parsed,
14185         .data = NULL,
14186         .help_str = "set port tm hierarchy default <port_id>",
14187         .tokens = {
14188                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14189                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14190                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14191                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14192                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14193                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14194                 NULL,
14195         },
14196 };
14197 #endif
14198
14199 /* Strict link priority scheduling mode setting */
14200 static void
14201 cmd_strict_link_prio_parsed(
14202         void *parsed_result,
14203         __attribute__((unused)) struct cmdline *cl,
14204         __attribute__((unused)) void *data)
14205 {
14206         struct cmd_vf_tc_bw_result *res = parsed_result;
14207         int ret = -ENOTSUP;
14208
14209         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14210                 return;
14211
14212 #ifdef RTE_LIBRTE_I40E_PMD
14213         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14214 #endif
14215
14216         switch (ret) {
14217         case 0:
14218                 break;
14219         case -EINVAL:
14220                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14221                 break;
14222         case -ENODEV:
14223                 printf("invalid port_id %d\n", res->port_id);
14224                 break;
14225         case -ENOTSUP:
14226                 printf("function not implemented\n");
14227                 break;
14228         default:
14229                 printf("programming error: (%s)\n", strerror(-ret));
14230         }
14231 }
14232
14233 cmdline_parse_inst_t cmd_strict_link_prio = {
14234         .f = cmd_strict_link_prio_parsed,
14235         .data = NULL,
14236         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14237         .tokens = {
14238                 (void *)&cmd_vf_tc_bw_set,
14239                 (void *)&cmd_vf_tc_bw_tx,
14240                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14241                 (void *)&cmd_vf_tc_bw_port_id,
14242                 (void *)&cmd_vf_tc_bw_tc_map,
14243                 NULL,
14244         },
14245 };
14246
14247 /* Load dynamic device personalization*/
14248 struct cmd_ddp_add_result {
14249         cmdline_fixed_string_t ddp;
14250         cmdline_fixed_string_t add;
14251         portid_t port_id;
14252         char filepath[];
14253 };
14254
14255 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14256         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14257 cmdline_parse_token_string_t cmd_ddp_add_add =
14258         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14259 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14260         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14261 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14262         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14263
14264 static void
14265 cmd_ddp_add_parsed(
14266         void *parsed_result,
14267         __attribute__((unused)) struct cmdline *cl,
14268         __attribute__((unused)) void *data)
14269 {
14270         struct cmd_ddp_add_result *res = parsed_result;
14271         uint8_t *buff;
14272         uint32_t size;
14273         char *filepath;
14274         char *file_fld[2];
14275         int file_num;
14276         int ret = -ENOTSUP;
14277
14278         if (res->port_id > nb_ports) {
14279                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14280                 return;
14281         }
14282
14283         if (!all_ports_stopped()) {
14284                 printf("Please stop all ports first\n");
14285                 return;
14286         }
14287
14288         filepath = strdup(res->filepath);
14289         if (filepath == NULL) {
14290                 printf("Failed to allocate memory\n");
14291                 return;
14292         }
14293         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14294
14295         buff = open_ddp_package_file(file_fld[0], &size);
14296         if (!buff) {
14297                 free((void *)filepath);
14298                 return;
14299         }
14300
14301 #ifdef RTE_LIBRTE_I40E_PMD
14302         if (ret == -ENOTSUP)
14303                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14304                                                buff, size,
14305                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14306 #endif
14307
14308         if (ret == -EEXIST)
14309                 printf("Profile has already existed.\n");
14310         else if (ret < 0)
14311                 printf("Failed to load profile.\n");
14312         else if (file_num == 2)
14313                 save_ddp_package_file(file_fld[1], buff, size);
14314
14315         close_ddp_package_file(buff);
14316         free((void *)filepath);
14317 }
14318
14319 cmdline_parse_inst_t cmd_ddp_add = {
14320         .f = cmd_ddp_add_parsed,
14321         .data = NULL,
14322         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14323         .tokens = {
14324                 (void *)&cmd_ddp_add_ddp,
14325                 (void *)&cmd_ddp_add_add,
14326                 (void *)&cmd_ddp_add_port_id,
14327                 (void *)&cmd_ddp_add_filepath,
14328                 NULL,
14329         },
14330 };
14331
14332 /* Delete dynamic device personalization*/
14333 struct cmd_ddp_del_result {
14334         cmdline_fixed_string_t ddp;
14335         cmdline_fixed_string_t del;
14336         portid_t port_id;
14337         char filepath[];
14338 };
14339
14340 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14341         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14342 cmdline_parse_token_string_t cmd_ddp_del_del =
14343         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14344 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14345         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14346 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14347         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14348
14349 static void
14350 cmd_ddp_del_parsed(
14351         void *parsed_result,
14352         __attribute__((unused)) struct cmdline *cl,
14353         __attribute__((unused)) void *data)
14354 {
14355         struct cmd_ddp_del_result *res = parsed_result;
14356         uint8_t *buff;
14357         uint32_t size;
14358         int ret = -ENOTSUP;
14359
14360         if (res->port_id > nb_ports) {
14361                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14362                 return;
14363         }
14364
14365         if (!all_ports_stopped()) {
14366                 printf("Please stop all ports first\n");
14367                 return;
14368         }
14369
14370         buff = open_ddp_package_file(res->filepath, &size);
14371         if (!buff)
14372                 return;
14373
14374 #ifdef RTE_LIBRTE_I40E_PMD
14375         if (ret == -ENOTSUP)
14376                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14377                                                buff, size,
14378                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14379 #endif
14380
14381         if (ret == -EACCES)
14382                 printf("Profile does not exist.\n");
14383         else if (ret < 0)
14384                 printf("Failed to delete profile.\n");
14385
14386         close_ddp_package_file(buff);
14387 }
14388
14389 cmdline_parse_inst_t cmd_ddp_del = {
14390         .f = cmd_ddp_del_parsed,
14391         .data = NULL,
14392         .help_str = "ddp del <port_id> <profile_path>",
14393         .tokens = {
14394                 (void *)&cmd_ddp_del_ddp,
14395                 (void *)&cmd_ddp_del_del,
14396                 (void *)&cmd_ddp_del_port_id,
14397                 (void *)&cmd_ddp_del_filepath,
14398                 NULL,
14399         },
14400 };
14401
14402 /* Get dynamic device personalization profile info */
14403 struct cmd_ddp_info_result {
14404         cmdline_fixed_string_t ddp;
14405         cmdline_fixed_string_t get;
14406         cmdline_fixed_string_t info;
14407         char filepath[];
14408 };
14409
14410 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14411         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14412 cmdline_parse_token_string_t cmd_ddp_info_get =
14413         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14414 cmdline_parse_token_string_t cmd_ddp_info_info =
14415         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14416 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14417         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14418
14419 static void
14420 cmd_ddp_info_parsed(
14421         void *parsed_result,
14422         __attribute__((unused)) struct cmdline *cl,
14423         __attribute__((unused)) void *data)
14424 {
14425         struct cmd_ddp_info_result *res = parsed_result;
14426         uint8_t *pkg;
14427         uint32_t pkg_size;
14428         int ret = -ENOTSUP;
14429 #ifdef RTE_LIBRTE_I40E_PMD
14430         uint32_t i, j, n;
14431         uint8_t *buff;
14432         uint32_t buff_size = 0;
14433         struct rte_pmd_i40e_profile_info info;
14434         uint32_t dev_num = 0;
14435         struct rte_pmd_i40e_ddp_device_id *devs;
14436         uint32_t proto_num = 0;
14437         struct rte_pmd_i40e_proto_info *proto = NULL;
14438         uint32_t pctype_num = 0;
14439         struct rte_pmd_i40e_ptype_info *pctype;
14440         uint32_t ptype_num = 0;
14441         struct rte_pmd_i40e_ptype_info *ptype;
14442         uint8_t proto_id;
14443
14444 #endif
14445
14446         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14447         if (!pkg)
14448                 return;
14449
14450 #ifdef RTE_LIBRTE_I40E_PMD
14451         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14452                                 (uint8_t *)&info, sizeof(info),
14453                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14454         if (!ret) {
14455                 printf("Global Track id:       0x%x\n", info.track_id);
14456                 printf("Global Version:        %d.%d.%d.%d\n",
14457                         info.version.major,
14458                         info.version.minor,
14459                         info.version.update,
14460                         info.version.draft);
14461                 printf("Global Package name:   %s\n\n", info.name);
14462         }
14463
14464         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14465                                 (uint8_t *)&info, sizeof(info),
14466                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14467         if (!ret) {
14468                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14469                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14470                         info.version.major,
14471                         info.version.minor,
14472                         info.version.update,
14473                         info.version.draft);
14474                 printf("i40e Profile name:     %s\n\n", info.name);
14475         }
14476
14477         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14478                                 (uint8_t *)&buff_size, sizeof(buff_size),
14479                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14480         if (!ret && buff_size) {
14481                 buff = (uint8_t *)malloc(buff_size);
14482                 if (buff) {
14483                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14484                                                 buff, buff_size,
14485                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14486                         if (!ret)
14487                                 printf("Package Notes:\n%s\n\n", buff);
14488                         free(buff);
14489                 }
14490         }
14491
14492         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14493                                 (uint8_t *)&dev_num, sizeof(dev_num),
14494                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14495         if (!ret && dev_num) {
14496                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14497                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14498                 if (devs) {
14499                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14500                                                 (uint8_t *)devs, buff_size,
14501                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14502                         if (!ret) {
14503                                 printf("List of supported devices:\n");
14504                                 for (i = 0; i < dev_num; i++) {
14505                                         printf("  %04X:%04X %04X:%04X\n",
14506                                                 devs[i].vendor_dev_id >> 16,
14507                                                 devs[i].vendor_dev_id & 0xFFFF,
14508                                                 devs[i].sub_vendor_dev_id >> 16,
14509                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14510                                 }
14511                                 printf("\n");
14512                         }
14513                         free(devs);
14514                 }
14515         }
14516
14517         /* get information about protocols and packet types */
14518         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14519                 (uint8_t *)&proto_num, sizeof(proto_num),
14520                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14521         if (ret || !proto_num)
14522                 goto no_print_return;
14523
14524         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14525         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14526         if (!proto)
14527                 goto no_print_return;
14528
14529         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14530                                         buff_size,
14531                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14532         if (!ret) {
14533                 printf("List of used protocols:\n");
14534                 for (i = 0; i < proto_num; i++)
14535                         printf("  %2u: %s\n", proto[i].proto_id,
14536                                proto[i].name);
14537                 printf("\n");
14538         }
14539         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14540                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14541                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14542         if (ret || !pctype_num)
14543                 goto no_print_pctypes;
14544
14545         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14546         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14547         if (!pctype)
14548                 goto no_print_pctypes;
14549
14550         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14551                                         buff_size,
14552                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14553         if (ret) {
14554                 free(pctype);
14555                 goto no_print_pctypes;
14556         }
14557
14558         printf("List of defined packet classification types:\n");
14559         for (i = 0; i < pctype_num; i++) {
14560                 printf("  %2u:", pctype[i].ptype_id);
14561                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14562                         proto_id = pctype[i].protocols[j];
14563                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14564                                 for (n = 0; n < proto_num; n++) {
14565                                         if (proto[n].proto_id == proto_id) {
14566                                                 printf(" %s", proto[n].name);
14567                                                 break;
14568                                         }
14569                                 }
14570                         }
14571                 }
14572                 printf("\n");
14573         }
14574         printf("\n");
14575         free(pctype);
14576
14577 no_print_pctypes:
14578
14579         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14580                                         sizeof(ptype_num),
14581                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14582         if (ret || !ptype_num)
14583                 goto no_print_return;
14584
14585         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14586         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14587         if (!ptype)
14588                 goto no_print_return;
14589
14590         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14591                                         buff_size,
14592                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14593         if (ret) {
14594                 free(ptype);
14595                 goto no_print_return;
14596         }
14597         printf("List of defined packet types:\n");
14598         for (i = 0; i < ptype_num; i++) {
14599                 printf("  %2u:", ptype[i].ptype_id);
14600                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14601                         proto_id = ptype[i].protocols[j];
14602                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14603                                 for (n = 0; n < proto_num; n++) {
14604                                         if (proto[n].proto_id == proto_id) {
14605                                                 printf(" %s", proto[n].name);
14606                                                 break;
14607                                         }
14608                                 }
14609                         }
14610                 }
14611                 printf("\n");
14612         }
14613         free(ptype);
14614         printf("\n");
14615
14616         ret = 0;
14617 no_print_return:
14618         if (proto)
14619                 free(proto);
14620 #endif
14621         if (ret == -ENOTSUP)
14622                 printf("Function not supported in PMD driver\n");
14623         close_ddp_package_file(pkg);
14624 }
14625
14626 cmdline_parse_inst_t cmd_ddp_get_info = {
14627         .f = cmd_ddp_info_parsed,
14628         .data = NULL,
14629         .help_str = "ddp get info <profile_path>",
14630         .tokens = {
14631                 (void *)&cmd_ddp_info_ddp,
14632                 (void *)&cmd_ddp_info_get,
14633                 (void *)&cmd_ddp_info_info,
14634                 (void *)&cmd_ddp_info_filepath,
14635                 NULL,
14636         },
14637 };
14638
14639 /* Get dynamic device personalization profile info list*/
14640 #define PROFILE_INFO_SIZE 48
14641 #define MAX_PROFILE_NUM 16
14642
14643 struct cmd_ddp_get_list_result {
14644         cmdline_fixed_string_t ddp;
14645         cmdline_fixed_string_t get;
14646         cmdline_fixed_string_t list;
14647         portid_t port_id;
14648 };
14649
14650 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14651         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14652 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14653         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14654 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14655         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14656 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14657         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14658
14659 static void
14660 cmd_ddp_get_list_parsed(
14661         void *parsed_result,
14662         __attribute__((unused)) struct cmdline *cl,
14663         __attribute__((unused)) void *data)
14664 {
14665         struct cmd_ddp_get_list_result *res = parsed_result;
14666 #ifdef RTE_LIBRTE_I40E_PMD
14667         struct rte_pmd_i40e_profile_list *p_list;
14668         struct rte_pmd_i40e_profile_info *p_info;
14669         uint32_t p_num;
14670         uint32_t size;
14671         uint32_t i;
14672 #endif
14673         int ret = -ENOTSUP;
14674
14675         if (res->port_id > nb_ports) {
14676                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14677                 return;
14678         }
14679
14680 #ifdef RTE_LIBRTE_I40E_PMD
14681         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14682         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14683         if (!p_list)
14684                 printf("%s: Failed to malloc buffer\n", __func__);
14685
14686         if (ret == -ENOTSUP)
14687                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14688                                                 (uint8_t *)p_list, size);
14689
14690         if (!ret) {
14691                 p_num = p_list->p_count;
14692                 printf("Profile number is: %d\n\n", p_num);
14693
14694                 for (i = 0; i < p_num; i++) {
14695                         p_info = &p_list->p_info[i];
14696                         printf("Profile %d:\n", i);
14697                         printf("Track id:     0x%x\n", p_info->track_id);
14698                         printf("Version:      %d.%d.%d.%d\n",
14699                                p_info->version.major,
14700                                p_info->version.minor,
14701                                p_info->version.update,
14702                                p_info->version.draft);
14703                         printf("Profile name: %s\n\n", p_info->name);
14704                 }
14705         }
14706
14707         free(p_list);
14708 #endif
14709
14710         if (ret < 0)
14711                 printf("Failed to get ddp list\n");
14712 }
14713
14714 cmdline_parse_inst_t cmd_ddp_get_list = {
14715         .f = cmd_ddp_get_list_parsed,
14716         .data = NULL,
14717         .help_str = "ddp get list <port_id>",
14718         .tokens = {
14719                 (void *)&cmd_ddp_get_list_ddp,
14720                 (void *)&cmd_ddp_get_list_get,
14721                 (void *)&cmd_ddp_get_list_list,
14722                 (void *)&cmd_ddp_get_list_port_id,
14723                 NULL,
14724         },
14725 };
14726
14727 /* show vf stats */
14728
14729 /* Common result structure for show vf stats */
14730 struct cmd_show_vf_stats_result {
14731         cmdline_fixed_string_t show;
14732         cmdline_fixed_string_t vf;
14733         cmdline_fixed_string_t stats;
14734         portid_t port_id;
14735         uint16_t vf_id;
14736 };
14737
14738 /* Common CLI fields show vf stats*/
14739 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14740         TOKEN_STRING_INITIALIZER
14741                 (struct cmd_show_vf_stats_result,
14742                  show, "show");
14743 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14744         TOKEN_STRING_INITIALIZER
14745                 (struct cmd_show_vf_stats_result,
14746                  vf, "vf");
14747 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14748         TOKEN_STRING_INITIALIZER
14749                 (struct cmd_show_vf_stats_result,
14750                  stats, "stats");
14751 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14752         TOKEN_NUM_INITIALIZER
14753                 (struct cmd_show_vf_stats_result,
14754                  port_id, UINT16);
14755 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14756         TOKEN_NUM_INITIALIZER
14757                 (struct cmd_show_vf_stats_result,
14758                  vf_id, UINT16);
14759
14760 static void
14761 cmd_show_vf_stats_parsed(
14762         void *parsed_result,
14763         __attribute__((unused)) struct cmdline *cl,
14764         __attribute__((unused)) void *data)
14765 {
14766         struct cmd_show_vf_stats_result *res = parsed_result;
14767         struct rte_eth_stats stats;
14768         int ret = -ENOTSUP;
14769         static const char *nic_stats_border = "########################";
14770
14771         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14772                 return;
14773
14774         memset(&stats, 0, sizeof(stats));
14775
14776 #ifdef RTE_LIBRTE_I40E_PMD
14777         if (ret == -ENOTSUP)
14778                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14779                                                 res->vf_id,
14780                                                 &stats);
14781 #endif
14782 #ifdef RTE_LIBRTE_BNXT_PMD
14783         if (ret == -ENOTSUP)
14784                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14785                                                 res->vf_id,
14786                                                 &stats);
14787 #endif
14788
14789         switch (ret) {
14790         case 0:
14791                 break;
14792         case -EINVAL:
14793                 printf("invalid vf_id %d\n", res->vf_id);
14794                 break;
14795         case -ENODEV:
14796                 printf("invalid port_id %d\n", res->port_id);
14797                 break;
14798         case -ENOTSUP:
14799                 printf("function not implemented\n");
14800                 break;
14801         default:
14802                 printf("programming error: (%s)\n", strerror(-ret));
14803         }
14804
14805         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14806                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14807
14808         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14809                "%-"PRIu64"\n",
14810                stats.ipackets, stats.imissed, stats.ibytes);
14811         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14812         printf("  RX-nombuf:  %-10"PRIu64"\n",
14813                stats.rx_nombuf);
14814         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14815                "%-"PRIu64"\n",
14816                stats.opackets, stats.oerrors, stats.obytes);
14817
14818         printf("  %s############################%s\n",
14819                                nic_stats_border, nic_stats_border);
14820 }
14821
14822 cmdline_parse_inst_t cmd_show_vf_stats = {
14823         .f = cmd_show_vf_stats_parsed,
14824         .data = NULL,
14825         .help_str = "show vf stats <port_id> <vf_id>",
14826         .tokens = {
14827                 (void *)&cmd_show_vf_stats_show,
14828                 (void *)&cmd_show_vf_stats_vf,
14829                 (void *)&cmd_show_vf_stats_stats,
14830                 (void *)&cmd_show_vf_stats_port_id,
14831                 (void *)&cmd_show_vf_stats_vf_id,
14832                 NULL,
14833         },
14834 };
14835
14836 /* clear vf stats */
14837
14838 /* Common result structure for clear vf stats */
14839 struct cmd_clear_vf_stats_result {
14840         cmdline_fixed_string_t clear;
14841         cmdline_fixed_string_t vf;
14842         cmdline_fixed_string_t stats;
14843         portid_t port_id;
14844         uint16_t vf_id;
14845 };
14846
14847 /* Common CLI fields clear vf stats*/
14848 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14849         TOKEN_STRING_INITIALIZER
14850                 (struct cmd_clear_vf_stats_result,
14851                  clear, "clear");
14852 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14853         TOKEN_STRING_INITIALIZER
14854                 (struct cmd_clear_vf_stats_result,
14855                  vf, "vf");
14856 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14857         TOKEN_STRING_INITIALIZER
14858                 (struct cmd_clear_vf_stats_result,
14859                  stats, "stats");
14860 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14861         TOKEN_NUM_INITIALIZER
14862                 (struct cmd_clear_vf_stats_result,
14863                  port_id, UINT16);
14864 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14865         TOKEN_NUM_INITIALIZER
14866                 (struct cmd_clear_vf_stats_result,
14867                  vf_id, UINT16);
14868
14869 static void
14870 cmd_clear_vf_stats_parsed(
14871         void *parsed_result,
14872         __attribute__((unused)) struct cmdline *cl,
14873         __attribute__((unused)) void *data)
14874 {
14875         struct cmd_clear_vf_stats_result *res = parsed_result;
14876         int ret = -ENOTSUP;
14877
14878         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14879                 return;
14880
14881 #ifdef RTE_LIBRTE_I40E_PMD
14882         if (ret == -ENOTSUP)
14883                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14884                                                   res->vf_id);
14885 #endif
14886 #ifdef RTE_LIBRTE_BNXT_PMD
14887         if (ret == -ENOTSUP)
14888                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14889                                                   res->vf_id);
14890 #endif
14891
14892         switch (ret) {
14893         case 0:
14894                 break;
14895         case -EINVAL:
14896                 printf("invalid vf_id %d\n", res->vf_id);
14897                 break;
14898         case -ENODEV:
14899                 printf("invalid port_id %d\n", res->port_id);
14900                 break;
14901         case -ENOTSUP:
14902                 printf("function not implemented\n");
14903                 break;
14904         default:
14905                 printf("programming error: (%s)\n", strerror(-ret));
14906         }
14907 }
14908
14909 cmdline_parse_inst_t cmd_clear_vf_stats = {
14910         .f = cmd_clear_vf_stats_parsed,
14911         .data = NULL,
14912         .help_str = "clear vf stats <port_id> <vf_id>",
14913         .tokens = {
14914                 (void *)&cmd_clear_vf_stats_clear,
14915                 (void *)&cmd_clear_vf_stats_vf,
14916                 (void *)&cmd_clear_vf_stats_stats,
14917                 (void *)&cmd_clear_vf_stats_port_id,
14918                 (void *)&cmd_clear_vf_stats_vf_id,
14919                 NULL,
14920         },
14921 };
14922
14923 /* port config pctype mapping reset */
14924
14925 /* Common result structure for port config pctype mapping reset */
14926 struct cmd_pctype_mapping_reset_result {
14927         cmdline_fixed_string_t port;
14928         cmdline_fixed_string_t config;
14929         portid_t port_id;
14930         cmdline_fixed_string_t pctype;
14931         cmdline_fixed_string_t mapping;
14932         cmdline_fixed_string_t reset;
14933 };
14934
14935 /* Common CLI fields for port config pctype mapping reset*/
14936 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14937         TOKEN_STRING_INITIALIZER
14938                 (struct cmd_pctype_mapping_reset_result,
14939                  port, "port");
14940 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14941         TOKEN_STRING_INITIALIZER
14942                 (struct cmd_pctype_mapping_reset_result,
14943                  config, "config");
14944 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14945         TOKEN_NUM_INITIALIZER
14946                 (struct cmd_pctype_mapping_reset_result,
14947                  port_id, UINT16);
14948 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14949         TOKEN_STRING_INITIALIZER
14950                 (struct cmd_pctype_mapping_reset_result,
14951                  pctype, "pctype");
14952 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14953         TOKEN_STRING_INITIALIZER
14954                 (struct cmd_pctype_mapping_reset_result,
14955                  mapping, "mapping");
14956 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14957         TOKEN_STRING_INITIALIZER
14958                 (struct cmd_pctype_mapping_reset_result,
14959                  reset, "reset");
14960
14961 static void
14962 cmd_pctype_mapping_reset_parsed(
14963         void *parsed_result,
14964         __attribute__((unused)) struct cmdline *cl,
14965         __attribute__((unused)) void *data)
14966 {
14967         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14968         int ret = -ENOTSUP;
14969
14970         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14971                 return;
14972
14973 #ifdef RTE_LIBRTE_I40E_PMD
14974         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14975 #endif
14976
14977         switch (ret) {
14978         case 0:
14979                 break;
14980         case -ENODEV:
14981                 printf("invalid port_id %d\n", res->port_id);
14982                 break;
14983         case -ENOTSUP:
14984                 printf("function not implemented\n");
14985                 break;
14986         default:
14987                 printf("programming error: (%s)\n", strerror(-ret));
14988         }
14989 }
14990
14991 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14992         .f = cmd_pctype_mapping_reset_parsed,
14993         .data = NULL,
14994         .help_str = "port config <port_id> pctype mapping reset",
14995         .tokens = {
14996                 (void *)&cmd_pctype_mapping_reset_port,
14997                 (void *)&cmd_pctype_mapping_reset_config,
14998                 (void *)&cmd_pctype_mapping_reset_port_id,
14999                 (void *)&cmd_pctype_mapping_reset_pctype,
15000                 (void *)&cmd_pctype_mapping_reset_mapping,
15001                 (void *)&cmd_pctype_mapping_reset_reset,
15002                 NULL,
15003         },
15004 };
15005
15006 /* show port pctype mapping */
15007
15008 /* Common result structure for show port pctype mapping */
15009 struct cmd_pctype_mapping_get_result {
15010         cmdline_fixed_string_t show;
15011         cmdline_fixed_string_t port;
15012         portid_t port_id;
15013         cmdline_fixed_string_t pctype;
15014         cmdline_fixed_string_t mapping;
15015 };
15016
15017 /* Common CLI fields for pctype mapping get */
15018 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15019         TOKEN_STRING_INITIALIZER
15020                 (struct cmd_pctype_mapping_get_result,
15021                  show, "show");
15022 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15023         TOKEN_STRING_INITIALIZER
15024                 (struct cmd_pctype_mapping_get_result,
15025                  port, "port");
15026 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15027         TOKEN_NUM_INITIALIZER
15028                 (struct cmd_pctype_mapping_get_result,
15029                  port_id, UINT16);
15030 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15031         TOKEN_STRING_INITIALIZER
15032                 (struct cmd_pctype_mapping_get_result,
15033                  pctype, "pctype");
15034 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15035         TOKEN_STRING_INITIALIZER
15036                 (struct cmd_pctype_mapping_get_result,
15037                  mapping, "mapping");
15038
15039 static void
15040 cmd_pctype_mapping_get_parsed(
15041         void *parsed_result,
15042         __attribute__((unused)) struct cmdline *cl,
15043         __attribute__((unused)) void *data)
15044 {
15045         struct cmd_pctype_mapping_get_result *res = parsed_result;
15046         int ret = -ENOTSUP;
15047 #ifdef RTE_LIBRTE_I40E_PMD
15048         struct rte_pmd_i40e_flow_type_mapping
15049                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15050         int i, j, first_pctype;
15051 #endif
15052
15053         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15054                 return;
15055
15056 #ifdef RTE_LIBRTE_I40E_PMD
15057         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15058 #endif
15059
15060         switch (ret) {
15061         case 0:
15062                 break;
15063         case -ENODEV:
15064                 printf("invalid port_id %d\n", res->port_id);
15065                 return;
15066         case -ENOTSUP:
15067                 printf("function not implemented\n");
15068                 return;
15069         default:
15070                 printf("programming error: (%s)\n", strerror(-ret));
15071                 return;
15072         }
15073
15074 #ifdef RTE_LIBRTE_I40E_PMD
15075         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15076                 if (mapping[i].pctype != 0ULL) {
15077                         first_pctype = 1;
15078
15079                         printf("pctype: ");
15080                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15081                                 if (mapping[i].pctype & (1ULL << j)) {
15082                                         printf(first_pctype ?
15083                                                "%02d" : ",%02d", j);
15084                                         first_pctype = 0;
15085                                 }
15086                         }
15087                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15088                 }
15089         }
15090 #endif
15091 }
15092
15093 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15094         .f = cmd_pctype_mapping_get_parsed,
15095         .data = NULL,
15096         .help_str = "show port <port_id> pctype mapping",
15097         .tokens = {
15098                 (void *)&cmd_pctype_mapping_get_show,
15099                 (void *)&cmd_pctype_mapping_get_port,
15100                 (void *)&cmd_pctype_mapping_get_port_id,
15101                 (void *)&cmd_pctype_mapping_get_pctype,
15102                 (void *)&cmd_pctype_mapping_get_mapping,
15103                 NULL,
15104         },
15105 };
15106
15107 /* port config pctype mapping update */
15108
15109 /* Common result structure for port config pctype mapping update */
15110 struct cmd_pctype_mapping_update_result {
15111         cmdline_fixed_string_t port;
15112         cmdline_fixed_string_t config;
15113         portid_t port_id;
15114         cmdline_fixed_string_t pctype;
15115         cmdline_fixed_string_t mapping;
15116         cmdline_fixed_string_t update;
15117         cmdline_fixed_string_t pctype_list;
15118         uint16_t flow_type;
15119 };
15120
15121 /* Common CLI fields for pctype mapping update*/
15122 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15123         TOKEN_STRING_INITIALIZER
15124                 (struct cmd_pctype_mapping_update_result,
15125                  port, "port");
15126 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15127         TOKEN_STRING_INITIALIZER
15128                 (struct cmd_pctype_mapping_update_result,
15129                  config, "config");
15130 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15131         TOKEN_NUM_INITIALIZER
15132                 (struct cmd_pctype_mapping_update_result,
15133                  port_id, UINT16);
15134 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15135         TOKEN_STRING_INITIALIZER
15136                 (struct cmd_pctype_mapping_update_result,
15137                  pctype, "pctype");
15138 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15139         TOKEN_STRING_INITIALIZER
15140                 (struct cmd_pctype_mapping_update_result,
15141                  mapping, "mapping");
15142 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15143         TOKEN_STRING_INITIALIZER
15144                 (struct cmd_pctype_mapping_update_result,
15145                  update, "update");
15146 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15147         TOKEN_STRING_INITIALIZER
15148                 (struct cmd_pctype_mapping_update_result,
15149                  pctype_list, NULL);
15150 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15151         TOKEN_NUM_INITIALIZER
15152                 (struct cmd_pctype_mapping_update_result,
15153                  flow_type, UINT16);
15154
15155 static void
15156 cmd_pctype_mapping_update_parsed(
15157         void *parsed_result,
15158         __attribute__((unused)) struct cmdline *cl,
15159         __attribute__((unused)) void *data)
15160 {
15161         struct cmd_pctype_mapping_update_result *res = parsed_result;
15162         int ret = -ENOTSUP;
15163 #ifdef RTE_LIBRTE_I40E_PMD
15164         struct rte_pmd_i40e_flow_type_mapping mapping;
15165         unsigned int i;
15166         unsigned int nb_item;
15167         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15168 #endif
15169
15170         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15171                 return;
15172
15173 #ifdef RTE_LIBRTE_I40E_PMD
15174         nb_item = parse_item_list(res->pctype_list, "pctypes",
15175                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15176         mapping.flow_type = res->flow_type;
15177         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15178                 mapping.pctype |= (1ULL << pctype_list[i]);
15179         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15180                                                 &mapping,
15181                                                 1,
15182                                                 0);
15183 #endif
15184
15185         switch (ret) {
15186         case 0:
15187                 break;
15188         case -EINVAL:
15189                 printf("invalid pctype or flow type\n");
15190                 break;
15191         case -ENODEV:
15192                 printf("invalid port_id %d\n", res->port_id);
15193                 break;
15194         case -ENOTSUP:
15195                 printf("function not implemented\n");
15196                 break;
15197         default:
15198                 printf("programming error: (%s)\n", strerror(-ret));
15199         }
15200 }
15201
15202 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15203         .f = cmd_pctype_mapping_update_parsed,
15204         .data = NULL,
15205         .help_str = "port config <port_id> pctype mapping update"
15206         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15207         .tokens = {
15208                 (void *)&cmd_pctype_mapping_update_port,
15209                 (void *)&cmd_pctype_mapping_update_config,
15210                 (void *)&cmd_pctype_mapping_update_port_id,
15211                 (void *)&cmd_pctype_mapping_update_pctype,
15212                 (void *)&cmd_pctype_mapping_update_mapping,
15213                 (void *)&cmd_pctype_mapping_update_update,
15214                 (void *)&cmd_pctype_mapping_update_pc_type,
15215                 (void *)&cmd_pctype_mapping_update_flow_type,
15216                 NULL,
15217         },
15218 };
15219
15220 /* ptype mapping get */
15221
15222 /* Common result structure for ptype mapping get */
15223 struct cmd_ptype_mapping_get_result {
15224         cmdline_fixed_string_t ptype;
15225         cmdline_fixed_string_t mapping;
15226         cmdline_fixed_string_t get;
15227         portid_t port_id;
15228         uint8_t valid_only;
15229 };
15230
15231 /* Common CLI fields for ptype mapping get */
15232 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15233         TOKEN_STRING_INITIALIZER
15234                 (struct cmd_ptype_mapping_get_result,
15235                  ptype, "ptype");
15236 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15237         TOKEN_STRING_INITIALIZER
15238                 (struct cmd_ptype_mapping_get_result,
15239                  mapping, "mapping");
15240 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15241         TOKEN_STRING_INITIALIZER
15242                 (struct cmd_ptype_mapping_get_result,
15243                  get, "get");
15244 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15245         TOKEN_NUM_INITIALIZER
15246                 (struct cmd_ptype_mapping_get_result,
15247                  port_id, UINT16);
15248 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15249         TOKEN_NUM_INITIALIZER
15250                 (struct cmd_ptype_mapping_get_result,
15251                  valid_only, UINT8);
15252
15253 static void
15254 cmd_ptype_mapping_get_parsed(
15255         void *parsed_result,
15256         __attribute__((unused)) struct cmdline *cl,
15257         __attribute__((unused)) void *data)
15258 {
15259         struct cmd_ptype_mapping_get_result *res = parsed_result;
15260         int ret = -ENOTSUP;
15261 #ifdef RTE_LIBRTE_I40E_PMD
15262         int max_ptype_num = 256;
15263         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15264         uint16_t count;
15265         int i;
15266 #endif
15267
15268         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15269                 return;
15270
15271 #ifdef RTE_LIBRTE_I40E_PMD
15272         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15273                                         mapping,
15274                                         max_ptype_num,
15275                                         &count,
15276                                         res->valid_only);
15277 #endif
15278
15279         switch (ret) {
15280         case 0:
15281                 break;
15282         case -ENODEV:
15283                 printf("invalid port_id %d\n", res->port_id);
15284                 break;
15285         case -ENOTSUP:
15286                 printf("function not implemented\n");
15287                 break;
15288         default:
15289                 printf("programming error: (%s)\n", strerror(-ret));
15290         }
15291
15292 #ifdef RTE_LIBRTE_I40E_PMD
15293         if (!ret) {
15294                 for (i = 0; i < count; i++)
15295                         printf("%3d\t0x%08x\n",
15296                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15297         }
15298 #endif
15299 }
15300
15301 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15302         .f = cmd_ptype_mapping_get_parsed,
15303         .data = NULL,
15304         .help_str = "ptype mapping get <port_id> <valid_only>",
15305         .tokens = {
15306                 (void *)&cmd_ptype_mapping_get_ptype,
15307                 (void *)&cmd_ptype_mapping_get_mapping,
15308                 (void *)&cmd_ptype_mapping_get_get,
15309                 (void *)&cmd_ptype_mapping_get_port_id,
15310                 (void *)&cmd_ptype_mapping_get_valid_only,
15311                 NULL,
15312         },
15313 };
15314
15315 /* ptype mapping replace */
15316
15317 /* Common result structure for ptype mapping replace */
15318 struct cmd_ptype_mapping_replace_result {
15319         cmdline_fixed_string_t ptype;
15320         cmdline_fixed_string_t mapping;
15321         cmdline_fixed_string_t replace;
15322         portid_t port_id;
15323         uint32_t target;
15324         uint8_t mask;
15325         uint32_t pkt_type;
15326 };
15327
15328 /* Common CLI fields for ptype mapping replace */
15329 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15330         TOKEN_STRING_INITIALIZER
15331                 (struct cmd_ptype_mapping_replace_result,
15332                  ptype, "ptype");
15333 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15334         TOKEN_STRING_INITIALIZER
15335                 (struct cmd_ptype_mapping_replace_result,
15336                  mapping, "mapping");
15337 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15338         TOKEN_STRING_INITIALIZER
15339                 (struct cmd_ptype_mapping_replace_result,
15340                  replace, "replace");
15341 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15342         TOKEN_NUM_INITIALIZER
15343                 (struct cmd_ptype_mapping_replace_result,
15344                  port_id, UINT16);
15345 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15346         TOKEN_NUM_INITIALIZER
15347                 (struct cmd_ptype_mapping_replace_result,
15348                  target, UINT32);
15349 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15350         TOKEN_NUM_INITIALIZER
15351                 (struct cmd_ptype_mapping_replace_result,
15352                  mask, UINT8);
15353 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15354         TOKEN_NUM_INITIALIZER
15355                 (struct cmd_ptype_mapping_replace_result,
15356                  pkt_type, UINT32);
15357
15358 static void
15359 cmd_ptype_mapping_replace_parsed(
15360         void *parsed_result,
15361         __attribute__((unused)) struct cmdline *cl,
15362         __attribute__((unused)) void *data)
15363 {
15364         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15365         int ret = -ENOTSUP;
15366
15367         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15368                 return;
15369
15370 #ifdef RTE_LIBRTE_I40E_PMD
15371         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15372                                         res->target,
15373                                         res->mask,
15374                                         res->pkt_type);
15375 #endif
15376
15377         switch (ret) {
15378         case 0:
15379                 break;
15380         case -EINVAL:
15381                 printf("invalid ptype 0x%8x or 0x%8x\n",
15382                                 res->target, res->pkt_type);
15383                 break;
15384         case -ENODEV:
15385                 printf("invalid port_id %d\n", res->port_id);
15386                 break;
15387         case -ENOTSUP:
15388                 printf("function not implemented\n");
15389                 break;
15390         default:
15391                 printf("programming error: (%s)\n", strerror(-ret));
15392         }
15393 }
15394
15395 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15396         .f = cmd_ptype_mapping_replace_parsed,
15397         .data = NULL,
15398         .help_str =
15399                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15400         .tokens = {
15401                 (void *)&cmd_ptype_mapping_replace_ptype,
15402                 (void *)&cmd_ptype_mapping_replace_mapping,
15403                 (void *)&cmd_ptype_mapping_replace_replace,
15404                 (void *)&cmd_ptype_mapping_replace_port_id,
15405                 (void *)&cmd_ptype_mapping_replace_target,
15406                 (void *)&cmd_ptype_mapping_replace_mask,
15407                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15408                 NULL,
15409         },
15410 };
15411
15412 /* ptype mapping reset */
15413
15414 /* Common result structure for ptype mapping reset */
15415 struct cmd_ptype_mapping_reset_result {
15416         cmdline_fixed_string_t ptype;
15417         cmdline_fixed_string_t mapping;
15418         cmdline_fixed_string_t reset;
15419         portid_t port_id;
15420 };
15421
15422 /* Common CLI fields for ptype mapping reset*/
15423 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15424         TOKEN_STRING_INITIALIZER
15425                 (struct cmd_ptype_mapping_reset_result,
15426                  ptype, "ptype");
15427 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15428         TOKEN_STRING_INITIALIZER
15429                 (struct cmd_ptype_mapping_reset_result,
15430                  mapping, "mapping");
15431 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15432         TOKEN_STRING_INITIALIZER
15433                 (struct cmd_ptype_mapping_reset_result,
15434                  reset, "reset");
15435 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15436         TOKEN_NUM_INITIALIZER
15437                 (struct cmd_ptype_mapping_reset_result,
15438                  port_id, UINT16);
15439
15440 static void
15441 cmd_ptype_mapping_reset_parsed(
15442         void *parsed_result,
15443         __attribute__((unused)) struct cmdline *cl,
15444         __attribute__((unused)) void *data)
15445 {
15446         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15447         int ret = -ENOTSUP;
15448
15449         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15450                 return;
15451
15452 #ifdef RTE_LIBRTE_I40E_PMD
15453         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15454 #endif
15455
15456         switch (ret) {
15457         case 0:
15458                 break;
15459         case -ENODEV:
15460                 printf("invalid port_id %d\n", res->port_id);
15461                 break;
15462         case -ENOTSUP:
15463                 printf("function not implemented\n");
15464                 break;
15465         default:
15466                 printf("programming error: (%s)\n", strerror(-ret));
15467         }
15468 }
15469
15470 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15471         .f = cmd_ptype_mapping_reset_parsed,
15472         .data = NULL,
15473         .help_str = "ptype mapping reset <port_id>",
15474         .tokens = {
15475                 (void *)&cmd_ptype_mapping_reset_ptype,
15476                 (void *)&cmd_ptype_mapping_reset_mapping,
15477                 (void *)&cmd_ptype_mapping_reset_reset,
15478                 (void *)&cmd_ptype_mapping_reset_port_id,
15479                 NULL,
15480         },
15481 };
15482
15483 /* ptype mapping update */
15484
15485 /* Common result structure for ptype mapping update */
15486 struct cmd_ptype_mapping_update_result {
15487         cmdline_fixed_string_t ptype;
15488         cmdline_fixed_string_t mapping;
15489         cmdline_fixed_string_t reset;
15490         portid_t port_id;
15491         uint8_t hw_ptype;
15492         uint32_t sw_ptype;
15493 };
15494
15495 /* Common CLI fields for ptype mapping update*/
15496 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15497         TOKEN_STRING_INITIALIZER
15498                 (struct cmd_ptype_mapping_update_result,
15499                  ptype, "ptype");
15500 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15501         TOKEN_STRING_INITIALIZER
15502                 (struct cmd_ptype_mapping_update_result,
15503                  mapping, "mapping");
15504 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15505         TOKEN_STRING_INITIALIZER
15506                 (struct cmd_ptype_mapping_update_result,
15507                  reset, "update");
15508 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15509         TOKEN_NUM_INITIALIZER
15510                 (struct cmd_ptype_mapping_update_result,
15511                  port_id, UINT16);
15512 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15513         TOKEN_NUM_INITIALIZER
15514                 (struct cmd_ptype_mapping_update_result,
15515                  hw_ptype, UINT8);
15516 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15517         TOKEN_NUM_INITIALIZER
15518                 (struct cmd_ptype_mapping_update_result,
15519                  sw_ptype, UINT32);
15520
15521 static void
15522 cmd_ptype_mapping_update_parsed(
15523         void *parsed_result,
15524         __attribute__((unused)) struct cmdline *cl,
15525         __attribute__((unused)) void *data)
15526 {
15527         struct cmd_ptype_mapping_update_result *res = parsed_result;
15528         int ret = -ENOTSUP;
15529 #ifdef RTE_LIBRTE_I40E_PMD
15530         struct rte_pmd_i40e_ptype_mapping mapping;
15531 #endif
15532         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15533                 return;
15534
15535 #ifdef RTE_LIBRTE_I40E_PMD
15536         mapping.hw_ptype = res->hw_ptype;
15537         mapping.sw_ptype = res->sw_ptype;
15538         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15539                                                 &mapping,
15540                                                 1,
15541                                                 0);
15542 #endif
15543
15544         switch (ret) {
15545         case 0:
15546                 break;
15547         case -EINVAL:
15548                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15549                 break;
15550         case -ENODEV:
15551                 printf("invalid port_id %d\n", res->port_id);
15552                 break;
15553         case -ENOTSUP:
15554                 printf("function not implemented\n");
15555                 break;
15556         default:
15557                 printf("programming error: (%s)\n", strerror(-ret));
15558         }
15559 }
15560
15561 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15562         .f = cmd_ptype_mapping_update_parsed,
15563         .data = NULL,
15564         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15565         .tokens = {
15566                 (void *)&cmd_ptype_mapping_update_ptype,
15567                 (void *)&cmd_ptype_mapping_update_mapping,
15568                 (void *)&cmd_ptype_mapping_update_update,
15569                 (void *)&cmd_ptype_mapping_update_port_id,
15570                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15571                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15572                 NULL,
15573         },
15574 };
15575
15576 /* Common result structure for file commands */
15577 struct cmd_cmdfile_result {
15578         cmdline_fixed_string_t load;
15579         cmdline_fixed_string_t filename;
15580 };
15581
15582 /* Common CLI fields for file commands */
15583 cmdline_parse_token_string_t cmd_load_cmdfile =
15584         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15585 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15586         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15587
15588 static void
15589 cmd_load_from_file_parsed(
15590         void *parsed_result,
15591         __attribute__((unused)) struct cmdline *cl,
15592         __attribute__((unused)) void *data)
15593 {
15594         struct cmd_cmdfile_result *res = parsed_result;
15595
15596         cmdline_read_from_file(res->filename);
15597 }
15598
15599 cmdline_parse_inst_t cmd_load_from_file = {
15600         .f = cmd_load_from_file_parsed,
15601         .data = NULL,
15602         .help_str = "load <filename>",
15603         .tokens = {
15604                 (void *)&cmd_load_cmdfile,
15605                 (void *)&cmd_load_cmdfile_filename,
15606                 NULL,
15607         },
15608 };
15609
15610 /* ******************************************************************************** */
15611
15612 /* list of instructions */
15613 cmdline_parse_ctx_t main_ctx[] = {
15614         (cmdline_parse_inst_t *)&cmd_help_brief,
15615         (cmdline_parse_inst_t *)&cmd_help_long,
15616         (cmdline_parse_inst_t *)&cmd_quit,
15617         (cmdline_parse_inst_t *)&cmd_load_from_file,
15618         (cmdline_parse_inst_t *)&cmd_showport,
15619         (cmdline_parse_inst_t *)&cmd_showqueue,
15620         (cmdline_parse_inst_t *)&cmd_showportall,
15621         (cmdline_parse_inst_t *)&cmd_showcfg,
15622         (cmdline_parse_inst_t *)&cmd_start,
15623         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15624         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15625         (cmdline_parse_inst_t *)&cmd_set_link_up,
15626         (cmdline_parse_inst_t *)&cmd_set_link_down,
15627         (cmdline_parse_inst_t *)&cmd_reset,
15628         (cmdline_parse_inst_t *)&cmd_set_numbers,
15629         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15630         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15631         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15632         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15633         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15634         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15635         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15636         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15637         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15638         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15639         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15640         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15641         (cmdline_parse_inst_t *)&cmd_set_link_check,
15642         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15643         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15644         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15645         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15646 #ifdef RTE_LIBRTE_PMD_BOND
15647         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15648         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15649         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15650         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15651         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15652         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15653         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15654         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15655         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15656         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15657         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15658 #endif
15659         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15660         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15661         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15662         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15663         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15664         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15665         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15666         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15667         (cmdline_parse_inst_t *)&cmd_csum_set,
15668         (cmdline_parse_inst_t *)&cmd_csum_show,
15669         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15670         (cmdline_parse_inst_t *)&cmd_tso_set,
15671         (cmdline_parse_inst_t *)&cmd_tso_show,
15672         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15673         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15674         (cmdline_parse_inst_t *)&cmd_gro_enable,
15675         (cmdline_parse_inst_t *)&cmd_gro_flush,
15676         (cmdline_parse_inst_t *)&cmd_gro_show,
15677         (cmdline_parse_inst_t *)&cmd_gso_enable,
15678         (cmdline_parse_inst_t *)&cmd_gso_size,
15679         (cmdline_parse_inst_t *)&cmd_gso_show,
15680         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15681         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15682         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15683         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15684         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15685         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15686         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15687         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15688         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15689         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15690         (cmdline_parse_inst_t *)&cmd_config_dcb,
15691         (cmdline_parse_inst_t *)&cmd_read_reg,
15692         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15693         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15694         (cmdline_parse_inst_t *)&cmd_write_reg,
15695         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15696         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15697         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15698         (cmdline_parse_inst_t *)&cmd_stop,
15699         (cmdline_parse_inst_t *)&cmd_mac_addr,
15700         (cmdline_parse_inst_t *)&cmd_set_qmap,
15701         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
15702         (cmdline_parse_inst_t *)&cmd_operate_port,
15703         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15704         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15705         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15706         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15707         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15708         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15709         (cmdline_parse_inst_t *)&cmd_config_mtu,
15710         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15711         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15712         (cmdline_parse_inst_t *)&cmd_config_rss,
15713         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15714         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15715         (cmdline_parse_inst_t *)&cmd_showport_reta,
15716         (cmdline_parse_inst_t *)&cmd_config_burst,
15717         (cmdline_parse_inst_t *)&cmd_config_thresh,
15718         (cmdline_parse_inst_t *)&cmd_config_threshold,
15719         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15720         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15721         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15722         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15723         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15724         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15725         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15726         (cmdline_parse_inst_t *)&cmd_global_config,
15727         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15728         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15729         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15730         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15731         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15732         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15733         (cmdline_parse_inst_t *)&cmd_dump,
15734         (cmdline_parse_inst_t *)&cmd_dump_one,
15735         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15736         (cmdline_parse_inst_t *)&cmd_syn_filter,
15737         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15738         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15739         (cmdline_parse_inst_t *)&cmd_flex_filter,
15740         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15741         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15742         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15743         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15744         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15745         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15746         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15747         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15748         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15749         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15750         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15751         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15752         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15753         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15754         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15755         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15756         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15757         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15758         (cmdline_parse_inst_t *)&cmd_flow,
15759         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
15760         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15761         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15762         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15763         (cmdline_parse_inst_t *)&cmd_create_port_meter,
15764         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
15765         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
15766         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15767         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15768         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
15769         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15770         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15771         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15772         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15773         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15774         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15775         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15776         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15777         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15778         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15779         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15780         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15781         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15782         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15783         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15784         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15785         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15786         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15787         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15788         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15789         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15790         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15791         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15792         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15793         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15794         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15795         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15796         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15797         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15798         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15799         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15800         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15801         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15802         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15803         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15804         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15805         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15806         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15807         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15808 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15809         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15810 #endif
15811         (cmdline_parse_inst_t *)&cmd_ddp_add,
15812         (cmdline_parse_inst_t *)&cmd_ddp_del,
15813         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15814         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15815         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15816         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15817         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15818         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15819         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15820         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15821
15822         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15823         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15824         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15825         (cmdline_parse_inst_t *)&cmd_queue_region,
15826         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15827         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15828         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15829         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15830         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
15831         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
15832         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
15833         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
15834         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
15835         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
15836         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
15837         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
15838         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
15839         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
15840         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
15841         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
15842         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
15843         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
15844         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
15845         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
15846         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
15847         NULL,
15848 };
15849
15850 /* read cmdline commands from file */
15851 void
15852 cmdline_read_from_file(const char *filename)
15853 {
15854         struct cmdline *cl;
15855
15856         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15857         if (cl == NULL) {
15858                 printf("Failed to create file based cmdline context: %s\n",
15859                        filename);
15860                 return;
15861         }
15862
15863         cmdline_interact(cl);
15864         cmdline_quit(cl);
15865
15866         cmdline_free(cl);
15867
15868         printf("Read CLI commands from %s\n", filename);
15869 }
15870
15871 /* prompt function, called from main on MASTER lcore */
15872 void
15873 prompt(void)
15874 {
15875         /* initialize non-constant commands */
15876         cmd_set_fwd_mode_init();
15877         cmd_set_fwd_retry_mode_init();
15878
15879         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15880         if (testpmd_cl == NULL)
15881                 return;
15882         cmdline_interact(testpmd_cl);
15883         cmdline_stdin_exit(testpmd_cl);
15884 }
15885
15886 void
15887 prompt_exit(void)
15888 {
15889         if (testpmd_cl != NULL)
15890                 cmdline_quit(testpmd_cl);
15891 }
15892
15893 static void
15894 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15895 {
15896         if (id == (portid_t)RTE_PORT_ALL) {
15897                 portid_t pid;
15898
15899                 RTE_ETH_FOREACH_DEV(pid) {
15900                         /* check if need_reconfig has been set to 1 */
15901                         if (ports[pid].need_reconfig == 0)
15902                                 ports[pid].need_reconfig = dev;
15903                         /* check if need_reconfig_queues has been set to 1 */
15904                         if (ports[pid].need_reconfig_queues == 0)
15905                                 ports[pid].need_reconfig_queues = queue;
15906                 }
15907         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15908                 /* check if need_reconfig has been set to 1 */
15909                 if (ports[id].need_reconfig == 0)
15910                         ports[id].need_reconfig = dev;
15911                 /* check if need_reconfig_queues has been set to 1 */
15912                 if (ports[id].need_reconfig_queues == 0)
15913                         ports[id].need_reconfig_queues = queue;
15914         }
15915 }