app/testpmd: enable TCP/IPv4 GRO
[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 <stdarg.h>
40 #include <string.h>
41 #include <termios.h>
42 #include <unistd.h>
43 #include <inttypes.h>
44 #ifndef __linux__
45 #ifndef __FreeBSD__
46 #include <net/socket.h>
47 #else
48 #include <sys/socket.h>
49 #endif
50 #endif
51 #include <netinet/in.h>
52
53 #include <sys/queue.h>
54
55 #include <rte_common.h>
56 #include <rte_byteorder.h>
57 #include <rte_log.h>
58 #include <rte_debug.h>
59 #include <rte_cycles.h>
60 #include <rte_memory.h>
61 #include <rte_memzone.h>
62 #include <rte_malloc.h>
63 #include <rte_launch.h>
64 #include <rte_eal.h>
65 #include <rte_per_lcore.h>
66 #include <rte_lcore.h>
67 #include <rte_atomic.h>
68 #include <rte_branch_prediction.h>
69 #include <rte_ring.h>
70 #include <rte_mempool.h>
71 #include <rte_interrupts.h>
72 #include <rte_pci.h>
73 #include <rte_ether.h>
74 #include <rte_ethdev.h>
75 #include <rte_string_fns.h>
76 #include <rte_devargs.h>
77 #include <rte_eth_ctrl.h>
78 #include <rte_flow.h>
79 #include <rte_gro.h>
80
81 #include <cmdline_rdline.h>
82 #include <cmdline_parse.h>
83 #include <cmdline_parse_num.h>
84 #include <cmdline_parse_string.h>
85 #include <cmdline_parse_ipaddr.h>
86 #include <cmdline_parse_etheraddr.h>
87 #include <cmdline_socket.h>
88 #include <cmdline.h>
89 #ifdef RTE_LIBRTE_PMD_BOND
90 #include <rte_eth_bond.h>
91 #include <rte_eth_bond_8023ad.h>
92 #endif
93 #ifdef RTE_LIBRTE_IXGBE_PMD
94 #include <rte_pmd_ixgbe.h>
95 #endif
96 #ifdef RTE_LIBRTE_I40E_PMD
97 #include <rte_pmd_i40e.h>
98 #endif
99 #ifdef RTE_LIBRTE_BNXT_PMD
100 #include <rte_pmd_bnxt.h>
101 #endif
102 #include "testpmd.h"
103
104 static struct cmdline *testpmd_cl;
105
106 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
107
108 /* *** Help command with introduction. *** */
109 struct cmd_help_brief_result {
110         cmdline_fixed_string_t help;
111 };
112
113 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
114                                   struct cmdline *cl,
115                                   __attribute__((unused)) void *data)
116 {
117         cmdline_printf(
118                 cl,
119                 "\n"
120                 "Help is available for the following sections:\n\n"
121                 "    help control    : Start and stop forwarding.\n"
122                 "    help display    : Displaying port, stats and config "
123                 "information.\n"
124                 "    help config     : Configuration information.\n"
125                 "    help ports      : Configuring ports.\n"
126                 "    help registers  : Reading and setting port registers.\n"
127                 "    help filters    : Filters configuration help.\n"
128                 "    help all        : All of the above sections.\n\n"
129         );
130
131 }
132
133 cmdline_parse_token_string_t cmd_help_brief_help =
134         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
135
136 cmdline_parse_inst_t cmd_help_brief = {
137         .f = cmd_help_brief_parsed,
138         .data = NULL,
139         .help_str = "help: Show help",
140         .tokens = {
141                 (void *)&cmd_help_brief_help,
142                 NULL,
143         },
144 };
145
146 /* *** Help command with help sections. *** */
147 struct cmd_help_long_result {
148         cmdline_fixed_string_t help;
149         cmdline_fixed_string_t section;
150 };
151
152 static void cmd_help_long_parsed(void *parsed_result,
153                                  struct cmdline *cl,
154                                  __attribute__((unused)) void *data)
155 {
156         int show_all = 0;
157         struct cmd_help_long_result *res = parsed_result;
158
159         if (!strcmp(res->section, "all"))
160                 show_all = 1;
161
162         if (show_all || !strcmp(res->section, "control")) {
163
164                 cmdline_printf(
165                         cl,
166                         "\n"
167                         "Control forwarding:\n"
168                         "-------------------\n\n"
169
170                         "start\n"
171                         "    Start packet forwarding with current configuration.\n\n"
172
173                         "start tx_first\n"
174                         "    Start packet forwarding with current config"
175                         " after sending one burst of packets.\n\n"
176
177                         "stop\n"
178                         "    Stop packet forwarding, and display accumulated"
179                         " statistics.\n\n"
180
181                         "quit\n"
182                         "    Quit to prompt.\n\n"
183                 );
184         }
185
186         if (show_all || !strcmp(res->section, "display")) {
187
188                 cmdline_printf(
189                         cl,
190                         "\n"
191                         "Display:\n"
192                         "--------\n\n"
193
194                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
195                         "    Display information for port_id, or all.\n\n"
196
197                         "show port X rss reta (size) (mask0,mask1,...)\n"
198                         "    Display the rss redirection table entry indicated"
199                         " by masks on port X. size is used to indicate the"
200                         " hardware supported reta size\n\n"
201
202                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
203                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
204                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
205                         "    Display the RSS hash functions and RSS hash key"
206                         " of port X\n\n"
207
208                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
209                         "    Clear information for port_id, or all.\n\n"
210
211                         "show (rxq|txq) info (port_id) (queue_id)\n"
212                         "    Display information for configured RX/TX queue.\n\n"
213
214                         "show config (rxtx|cores|fwd|txpkts)\n"
215                         "    Display the given configuration.\n\n"
216
217                         "read rxd (port_id) (queue_id) (rxd_id)\n"
218                         "    Display an RX descriptor of a port RX queue.\n\n"
219
220                         "read txd (port_id) (queue_id) (txd_id)\n"
221                         "    Display a TX descriptor of a port TX queue.\n\n"
222
223                         "ddp get list (port_id)\n"
224                         "    Get ddp profile info list\n\n"
225
226                         "ddp get info (profile_path)\n"
227                         "    Get ddp profile information.\n\n"
228
229                         "show vf stats (port_id) (vf_id)\n"
230                         "    Display a VF's statistics.\n\n"
231
232                         "clear vf stats (port_id) (vf_id)\n"
233                         "    Reset a VF's statistics.\n\n"
234                 );
235         }
236
237         if (show_all || !strcmp(res->section, "config")) {
238                 cmdline_printf(
239                         cl,
240                         "\n"
241                         "Configuration:\n"
242                         "--------------\n"
243                         "Configuration changes only become active when"
244                         " forwarding is started/restarted.\n\n"
245
246                         "set default\n"
247                         "    Reset forwarding to the default configuration.\n\n"
248
249                         "set verbose (level)\n"
250                         "    Set the debug verbosity level X.\n\n"
251
252                         "set nbport (num)\n"
253                         "    Set number of ports.\n\n"
254
255                         "set nbcore (num)\n"
256                         "    Set number of cores.\n\n"
257
258                         "set coremask (mask)\n"
259                         "    Set the forwarding cores hexadecimal mask.\n\n"
260
261                         "set portmask (mask)\n"
262                         "    Set the forwarding ports hexadecimal mask.\n\n"
263
264                         "set burst (num)\n"
265                         "    Set number of packets per burst.\n\n"
266
267                         "set burst tx delay (microseconds) retry (num)\n"
268                         "    Set the transmit delay time and number of retries,"
269                         " effective when retry is enabled.\n\n"
270
271                         "set txpkts (x[,y]*)\n"
272                         "    Set the length of each segment of TXONLY"
273                         " and optionally CSUM packets.\n\n"
274
275                         "set txsplit (off|on|rand)\n"
276                         "    Set the split policy for the TX packets."
277                         " Right now only applicable for CSUM and TXONLY"
278                         " modes\n\n"
279
280                         "set corelist (x[,y]*)\n"
281                         "    Set the list of forwarding cores.\n\n"
282
283                         "set portlist (x[,y]*)\n"
284                         "    Set the list of forwarding ports.\n\n"
285
286                         "set tx loopback (port_id) (on|off)\n"
287                         "    Enable or disable tx loopback.\n\n"
288
289                         "set all queues drop (port_id) (on|off)\n"
290                         "    Set drop enable bit for all queues.\n\n"
291
292                         "set vf split drop (port_id) (vf_id) (on|off)\n"
293                         "    Set split drop enable bit for a VF from the PF.\n\n"
294
295                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
296                         "    Set MAC antispoof for a VF from the PF.\n\n"
297
298                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
299                         "    Enable MACsec offload.\n\n"
300
301                         "set macsec offload (port_id) off\n"
302                         "    Disable MACsec offload.\n\n"
303
304                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
305                         "    Configure MACsec secure connection (SC).\n\n"
306
307                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
308                         "    Configure MACsec secure association (SA).\n\n"
309
310                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
311                         "    Set VF broadcast for a VF from the PF.\n\n"
312
313                         "vlan set strip (on|off) (port_id)\n"
314                         "    Set the VLAN strip on a port.\n\n"
315
316                         "vlan set stripq (on|off) (port_id,queue_id)\n"
317                         "    Set the VLAN strip for a queue on a port.\n\n"
318
319                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
320                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
321
322                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
323                         "    Set VLAN insert for a VF from the PF.\n\n"
324
325                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
326                         "    Set VLAN antispoof for a VF from the PF.\n\n"
327
328                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
329                         "    Set VLAN tag for a VF from the PF.\n\n"
330
331                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
332                         "    Set a VF's max bandwidth(Mbps).\n\n"
333
334                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
335                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
336
337                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
338                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
339
340                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
341                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
342
343                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
344                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
345
346                         "vlan set filter (on|off) (port_id)\n"
347                         "    Set the VLAN filter on a port.\n\n"
348
349                         "vlan set qinq (on|off) (port_id)\n"
350                         "    Set the VLAN QinQ (extended queue in queue)"
351                         " on a port.\n\n"
352
353                         "vlan set (inner|outer) tpid (value) (port_id)\n"
354                         "    Set the VLAN TPID for Packet Filtering on"
355                         " a port\n\n"
356
357                         "rx_vlan add (vlan_id|all) (port_id)\n"
358                         "    Add a vlan_id, or all identifiers, to the set"
359                         " of VLAN identifiers filtered by port_id.\n\n"
360
361                         "rx_vlan rm (vlan_id|all) (port_id)\n"
362                         "    Remove a vlan_id, or all identifiers, from the set"
363                         " of VLAN identifiers filtered by port_id.\n\n"
364
365                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
366                         "    Add a vlan_id, to the set of VLAN identifiers"
367                         "filtered for VF(s) from port_id.\n\n"
368
369                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
370                         "    Remove a vlan_id, to the set of VLAN identifiers"
371                         "filtered for VF(s) from port_id.\n\n"
372
373                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
374                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
375                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
376                         "   add a tunnel filter of a port.\n\n"
377
378                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
379                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
380                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
381                         "   remove a tunnel filter of a port.\n\n"
382
383                         "rx_vxlan_port add (udp_port) (port_id)\n"
384                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
385
386                         "rx_vxlan_port rm (udp_port) (port_id)\n"
387                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
388
389                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
390                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
391                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
392
393                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
394                         "    Set port based TX VLAN insertion.\n\n"
395
396                         "tx_vlan reset (port_id)\n"
397                         "    Disable hardware insertion of a VLAN header in"
398                         " packets sent on a port.\n\n"
399
400                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
401                         "    Select hardware or software calculation of the"
402                         " checksum when transmitting a packet using the"
403                         " csum forward engine.\n"
404                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
405                         "    outer-ip concerns the outer IP layer in"
406                         " case the packet is recognized as a tunnel packet by"
407                         " the forward engine (vxlan, gre and ipip are supported)\n"
408                         "    Please check the NIC datasheet for HW limits.\n\n"
409
410                         "csum parse-tunnel (on|off) (tx_port_id)\n"
411                         "    If disabled, treat tunnel packets as non-tunneled"
412                         " packets (treat inner headers as payload). The port\n"
413                         "    argument is the port used for TX in csum forward"
414                         " engine.\n\n"
415
416                         "csum show (port_id)\n"
417                         "    Display tx checksum offload configuration\n\n"
418
419                         "tso set (segsize) (portid)\n"
420                         "    Enable TCP Segmentation Offload in csum forward"
421                         " engine.\n"
422                         "    Please check the NIC datasheet for HW limits.\n\n"
423
424                         "tso show (portid)"
425                         "    Display the status of TCP Segmentation Offload.\n\n"
426
427                         "gro (on|off) (port_id)"
428                         "    Enable or disable Generic Receive Offload in io"
429                         " forward engine.\n\n"
430
431                         "gro set (max_flow_num) (max_item_num_per_flow) (port_id)\n"
432                         "    Set max flow number and max packet number per-flow"
433                         " for GRO.\n\n"
434
435                         "set fwd (%s)\n"
436                         "    Set packet forwarding mode.\n\n"
437
438                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
439                         "    Add a MAC address on port_id.\n\n"
440
441                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
442                         "    Remove a MAC address from port_id.\n\n"
443
444                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
445                         "    Set the default MAC address for port_id.\n\n"
446
447                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
448                         "    Add a MAC address for a VF on the port.\n\n"
449
450                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
451                         "    Set the MAC address for a VF from the PF.\n\n"
452
453                         "set port (port_id) uta (mac_address|all) (on|off)\n"
454                         "    Add/Remove a or all unicast hash filter(s)"
455                         "from port X.\n\n"
456
457                         "set promisc (port_id|all) (on|off)\n"
458                         "    Set the promiscuous mode on port_id, or all.\n\n"
459
460                         "set allmulti (port_id|all) (on|off)\n"
461                         "    Set the allmulti mode on port_id, or all.\n\n"
462
463                         "set vf promisc (port_id) (vf_id) (on|off)\n"
464                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
465
466                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
467                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
468
469                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
470                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
471                         " (on|off) autoneg (on|off) (port_id)\n"
472                         "set flow_ctrl rx (on|off) (portid)\n"
473                         "set flow_ctrl tx (on|off) (portid)\n"
474                         "set flow_ctrl high_water (high_water) (portid)\n"
475                         "set flow_ctrl low_water (low_water) (portid)\n"
476                         "set flow_ctrl pause_time (pause_time) (portid)\n"
477                         "set flow_ctrl send_xon (send_xon) (portid)\n"
478                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
479                         "set flow_ctrl autoneg (on|off) (port_id)\n"
480                         "    Set the link flow control parameter on a port.\n\n"
481
482                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
483                         " (low_water) (pause_time) (priority) (port_id)\n"
484                         "    Set the priority flow control parameter on a"
485                         " port.\n\n"
486
487                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
488                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
489                         " queue on port.\n"
490                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
491                         " on port 0 to mapping 5.\n\n"
492
493                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
494                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
495
496                         "set port (port_id) vf (vf_id) (mac_addr)"
497                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
498                         "   Add/Remove unicast or multicast MAC addr filter"
499                         " for a VF.\n\n"
500
501                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
502                         "|MPE) (on|off)\n"
503                         "    AUPE:accepts untagged VLAN;"
504                         "ROPE:accept unicast hash\n\n"
505                         "    BAM:accepts broadcast packets;"
506                         "MPE:accepts all multicast packets\n\n"
507                         "    Enable/Disable a VF receive mode of a port\n\n"
508
509                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
510                         "    Set rate limit for a queue of a port\n\n"
511
512                         "set port (port_id) vf (vf_id) rate (rate_num) "
513                         "queue_mask (queue_mask_value)\n"
514                         "    Set rate limit for queues in VF of a port\n\n"
515
516                         "set port (port_id) mirror-rule (rule_id)"
517                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
518                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
519                         "   Set pool or vlan type mirror rule on a port.\n"
520                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
521                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
522                         " to pool 0.\n\n"
523
524                         "set port (port_id) mirror-rule (rule_id)"
525                         " (uplink-mirror|downlink-mirror) dst-pool"
526                         " (pool_id) (on|off)\n"
527                         "   Set uplink or downlink type mirror rule on a port.\n"
528                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
529                         " 0 on' enable mirror income traffic to pool 0.\n\n"
530
531                         "reset port (port_id) mirror-rule (rule_id)\n"
532                         "   Reset a mirror rule.\n\n"
533
534                         "set flush_rx (on|off)\n"
535                         "   Flush (default) or don't flush RX streams before"
536                         " forwarding. Mainly used with PCAP drivers.\n\n"
537
538                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
539                         "   Set the bypass mode for the lowest port on bypass enabled"
540                         " NIC.\n\n"
541
542                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
543                         "mode (normal|bypass|isolate) (port_id)\n"
544                         "   Set the event required to initiate specified bypass mode for"
545                         " the lowest port on a bypass enabled NIC where:\n"
546                         "       timeout   = enable bypass after watchdog timeout.\n"
547                         "       os_on     = enable bypass when OS/board is powered on.\n"
548                         "       os_off    = enable bypass when OS/board is powered off.\n"
549                         "       power_on  = enable bypass when power supply is turned on.\n"
550                         "       power_off = enable bypass when power supply is turned off."
551                         "\n\n"
552
553                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
554                         "   Set the bypass watchdog timeout to 'n' seconds"
555                         " where 0 = instant.\n\n"
556
557                         "show bypass config (port_id)\n"
558                         "   Show the bypass configuration for a bypass enabled NIC"
559                         " using the lowest port on the NIC.\n\n"
560
561 #ifdef RTE_LIBRTE_PMD_BOND
562                         "create bonded device (mode) (socket)\n"
563                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
564
565                         "add bonding slave (slave_id) (port_id)\n"
566                         "       Add a slave device to a bonded device.\n\n"
567
568                         "remove bonding slave (slave_id) (port_id)\n"
569                         "       Remove a slave device from a bonded device.\n\n"
570
571                         "set bonding mode (value) (port_id)\n"
572                         "       Set the bonding mode on a bonded device.\n\n"
573
574                         "set bonding primary (slave_id) (port_id)\n"
575                         "       Set the primary slave for a bonded device.\n\n"
576
577                         "show bonding config (port_id)\n"
578                         "       Show the bonding config for port_id.\n\n"
579
580                         "set bonding mac_addr (port_id) (address)\n"
581                         "       Set the MAC address of a bonded device.\n\n"
582
583                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
584                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
585
586                         "set bonding mon_period (port_id) (value)\n"
587                         "       Set the bonding link status monitoring polling period in ms.\n\n"
588
589                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
590                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
591
592 #endif
593                         "set link-up port (port_id)\n"
594                         "       Set link up for a port.\n\n"
595
596                         "set link-down port (port_id)\n"
597                         "       Set link down for a port.\n\n"
598
599                         "E-tag set insertion on port-tag-id (value)"
600                         " port (port_id) vf (vf_id)\n"
601                         "    Enable E-tag insertion for a VF on a port\n\n"
602
603                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
604                         "    Disable E-tag insertion for a VF on a port\n\n"
605
606                         "E-tag set stripping (on|off) port (port_id)\n"
607                         "    Enable/disable E-tag stripping on a port\n\n"
608
609                         "E-tag set forwarding (on|off) port (port_id)\n"
610                         "    Enable/disable E-tag based forwarding"
611                         " on a port\n\n"
612
613                         "E-tag set filter add e-tag-id (value) dst-pool"
614                         " (pool_id) port (port_id)\n"
615                         "    Add an E-tag forwarding filter on a port\n\n"
616
617                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
618                         "    Delete an E-tag forwarding filter on a port\n\n"
619
620                         "ddp add (port_id) (profile_path[,output_path])\n"
621                         "    Load a profile package on a port\n\n"
622
623                         "ddp del (port_id) (profile_path)\n"
624                         "    Delete a profile package from a port\n\n"
625
626                         "ptype mapping get (port_id) (valid_only)\n"
627                         "    Get ptype mapping on a port\n\n"
628
629                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
630                         "    Replace target with the pkt_type in ptype mapping\n\n"
631
632                         "ptype mapping reset (port_id)\n"
633                         "    Reset ptype mapping on a port\n\n"
634
635                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
636                         "    Update a ptype mapping item on a port\n\n"
637
638                         , list_pkt_forwarding_modes()
639                 );
640         }
641
642         if (show_all || !strcmp(res->section, "ports")) {
643
644                 cmdline_printf(
645                         cl,
646                         "\n"
647                         "Port Operations:\n"
648                         "----------------\n\n"
649
650                         "port start (port_id|all)\n"
651                         "    Start all ports or port_id.\n\n"
652
653                         "port stop (port_id|all)\n"
654                         "    Stop all ports or port_id.\n\n"
655
656                         "port close (port_id|all)\n"
657                         "    Close all ports or port_id.\n\n"
658
659                         "port attach (ident)\n"
660                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
661
662                         "port detach (port_id)\n"
663                         "    Detach physical or virtual dev by port_id\n\n"
664
665                         "port config (port_id|all)"
666                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
667                         " duplex (half|full|auto)\n"
668                         "    Set speed and duplex for all ports or port_id\n\n"
669
670                         "port config all (rxq|txq|rxd|txd) (value)\n"
671                         "    Set number for rxq/txq/rxd/txd.\n\n"
672
673                         "port config all max-pkt-len (value)\n"
674                         "    Set the max packet length.\n\n"
675
676                         "port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|"
677                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
678                         " (on|off)\n"
679                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
680                         " for ports.\n\n"
681
682                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none)\n"
683                         "    Set the RSS mode.\n\n"
684
685                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
686                         "    Set the RSS redirection table.\n\n"
687
688                         "port config (port_id) dcb vt (on|off) (traffic_class)"
689                         " pfc (on|off)\n"
690                         "    Set the DCB mode.\n\n"
691
692                         "port config all burst (value)\n"
693                         "    Set the number of packets per burst.\n\n"
694
695                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
696                         " (value)\n"
697                         "    Set the ring prefetch/host/writeback threshold"
698                         " for tx/rx queue.\n\n"
699
700                         "port config all (txfreet|txrst|rxfreet) (value)\n"
701                         "    Set free threshold for rx/tx, or set"
702                         " tx rs bit threshold.\n\n"
703                         "port config mtu X value\n"
704                         "    Set the MTU of port X to a given value\n\n"
705
706                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
707                         "    Start/stop a rx/tx queue of port X. Only take effect"
708                         " when port X is started\n\n"
709
710                         "port config (port_id|all) l2-tunnel E-tag ether-type"
711                         " (value)\n"
712                         "    Set the value of E-tag ether-type.\n\n"
713
714                         "port config (port_id|all) l2-tunnel E-tag"
715                         " (enable|disable)\n"
716                         "    Enable/disable the E-tag support.\n\n"
717                 );
718         }
719
720         if (show_all || !strcmp(res->section, "registers")) {
721
722                 cmdline_printf(
723                         cl,
724                         "\n"
725                         "Registers:\n"
726                         "----------\n\n"
727
728                         "read reg (port_id) (address)\n"
729                         "    Display value of a port register.\n\n"
730
731                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
732                         "    Display a port register bit field.\n\n"
733
734                         "read regbit (port_id) (address) (bit_x)\n"
735                         "    Display a single port register bit.\n\n"
736
737                         "write reg (port_id) (address) (value)\n"
738                         "    Set value of a port register.\n\n"
739
740                         "write regfield (port_id) (address) (bit_x) (bit_y)"
741                         " (value)\n"
742                         "    Set bit field of a port register.\n\n"
743
744                         "write regbit (port_id) (address) (bit_x) (value)\n"
745                         "    Set single bit value of a port register.\n\n"
746                 );
747         }
748         if (show_all || !strcmp(res->section, "filters")) {
749
750                 cmdline_printf(
751                         cl,
752                         "\n"
753                         "filters:\n"
754                         "--------\n\n"
755
756                         "ethertype_filter (port_id) (add|del)"
757                         " (mac_addr|mac_ignr) (mac_address) ethertype"
758                         " (ether_type) (drop|fwd) queue (queue_id)\n"
759                         "    Add/Del an ethertype filter.\n\n"
760
761                         "2tuple_filter (port_id) (add|del)"
762                         " dst_port (dst_port_value) protocol (protocol_value)"
763                         " mask (mask_value) tcp_flags (tcp_flags_value)"
764                         " priority (prio_value) queue (queue_id)\n"
765                         "    Add/Del a 2tuple filter.\n\n"
766
767                         "5tuple_filter (port_id) (add|del)"
768                         " dst_ip (dst_address) src_ip (src_address)"
769                         " dst_port (dst_port_value) src_port (src_port_value)"
770                         " protocol (protocol_value)"
771                         " mask (mask_value) tcp_flags (tcp_flags_value)"
772                         " priority (prio_value) queue (queue_id)\n"
773                         "    Add/Del a 5tuple filter.\n\n"
774
775                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
776                         "    Add/Del syn filter.\n\n"
777
778                         "flex_filter (port_id) (add|del) len (len_value)"
779                         " bytes (bytes_value) mask (mask_value)"
780                         " priority (prio_value) queue (queue_id)\n"
781                         "    Add/Del a flex filter.\n\n"
782
783                         "flow_director_filter (port_id) mode IP (add|del|update)"
784                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
785                         " src (src_ip_address) dst (dst_ip_address)"
786                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
787                         " vlan (vlan_value) flexbytes (flexbytes_value)"
788                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
789                         " fd_id (fd_id_value)\n"
790                         "    Add/Del an IP type flow director filter.\n\n"
791
792                         "flow_director_filter (port_id) mode IP (add|del|update)"
793                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
794                         " src (src_ip_address) (src_port)"
795                         " dst (dst_ip_address) (dst_port)"
796                         " tos (tos_value) ttl (ttl_value)"
797                         " vlan (vlan_value) flexbytes (flexbytes_value)"
798                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
799                         " fd_id (fd_id_value)\n"
800                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
801
802                         "flow_director_filter (port_id) mode IP (add|del|update)"
803                         " flow (ipv4-sctp|ipv6-sctp)"
804                         " src (src_ip_address) (src_port)"
805                         " dst (dst_ip_address) (dst_port)"
806                         " tag (verification_tag) "
807                         " tos (tos_value) ttl (ttl_value)"
808                         " vlan (vlan_value)"
809                         " flexbytes (flexbytes_value) (drop|fwd)"
810                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
811                         "    Add/Del a SCTP type flow director filter.\n\n"
812
813                         "flow_director_filter (port_id) mode IP (add|del|update)"
814                         " flow l2_payload ether (ethertype)"
815                         " flexbytes (flexbytes_value) (drop|fwd)"
816                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
817                         "    Add/Del a l2 payload type flow director filter.\n\n"
818
819                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
820                         " mac (mac_address) vlan (vlan_value)"
821                         " flexbytes (flexbytes_value) (drop|fwd)"
822                         " queue (queue_id) fd_id (fd_id_value)\n"
823                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
824
825                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
826                         " mac (mac_address) vlan (vlan_value)"
827                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
828                         " flexbytes (flexbytes_value) (drop|fwd)"
829                         " queue (queue_id) fd_id (fd_id_value)\n"
830                         "    Add/Del a Tunnel flow director filter.\n\n"
831
832                         "flush_flow_director (port_id)\n"
833                         "    Flush all flow director entries of a device.\n\n"
834
835                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
836                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
837                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
838                         "    Set flow director IP mask.\n\n"
839
840                         "flow_director_mask (port_id) mode MAC-VLAN"
841                         " vlan (vlan_value)\n"
842                         "    Set flow director MAC-VLAN mask.\n\n"
843
844                         "flow_director_mask (port_id) mode Tunnel"
845                         " vlan (vlan_value) mac (mac_value)"
846                         " tunnel-type (tunnel_type_value)"
847                         " tunnel-id (tunnel_id_value)\n"
848                         "    Set flow director Tunnel mask.\n\n"
849
850                         "flow_director_flex_mask (port_id)"
851                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
852                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
853                         " (mask)\n"
854                         "    Configure mask of flex payload.\n\n"
855
856                         "flow_director_flex_payload (port_id)"
857                         " (raw|l2|l3|l4) (config)\n"
858                         "    Configure flex payload selection.\n\n"
859
860                         "get_sym_hash_ena_per_port (port_id)\n"
861                         "    get symmetric hash enable configuration per port.\n\n"
862
863                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
864                         "    set symmetric hash enable configuration per port"
865                         " to enable or disable.\n\n"
866
867                         "get_hash_global_config (port_id)\n"
868                         "    Get the global configurations of hash filters.\n\n"
869
870                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
871                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
872                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
873                         " (enable|disable)\n"
874                         "    Set the global configurations of hash filters.\n\n"
875
876                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
877                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
878                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
879                         "l2_payload) (ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|"
880                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
881                         "ipv6-next-header|udp-src-port|udp-dst-port|"
882                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
883                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
884                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
885                         "fld-8th|none) (select|add)\n"
886                         "    Set the input set for hash.\n\n"
887
888                         "set_fdir_input_set (port_id) "
889                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
890                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
891                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
892                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
893                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
894                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
895                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
896                         " (select|add)\n"
897                         "    Set the input set for FDir.\n\n"
898
899                         "flow validate {port_id}"
900                         " [group {group_id}] [priority {level}]"
901                         " [ingress] [egress]"
902                         " pattern {item} [/ {item} [...]] / end"
903                         " actions {action} [/ {action} [...]] / end\n"
904                         "    Check whether a flow rule can be created.\n\n"
905
906                         "flow create {port_id}"
907                         " [group {group_id}] [priority {level}]"
908                         " [ingress] [egress]"
909                         " pattern {item} [/ {item} [...]] / end"
910                         " actions {action} [/ {action} [...]] / end\n"
911                         "    Create a flow rule.\n\n"
912
913                         "flow destroy {port_id} rule {rule_id} [...]\n"
914                         "    Destroy specific flow rules.\n\n"
915
916                         "flow flush {port_id}\n"
917                         "    Destroy all flow rules.\n\n"
918
919                         "flow query {port_id} {rule_id} {action}\n"
920                         "    Query an existing flow rule.\n\n"
921
922                         "flow list {port_id} [group {group_id}] [...]\n"
923                         "    List existing flow rules sorted by priority,"
924                         " filtered by group identifiers.\n\n"
925
926                         "flow isolate {port_id} {boolean}\n"
927                         "    Restrict ingress traffic to the defined"
928                         " flow rules\n\n"
929                 );
930         }
931 }
932
933 cmdline_parse_token_string_t cmd_help_long_help =
934         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
935
936 cmdline_parse_token_string_t cmd_help_long_section =
937         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
938                         "all#control#display#config#"
939                         "ports#registers#filters");
940
941 cmdline_parse_inst_t cmd_help_long = {
942         .f = cmd_help_long_parsed,
943         .data = NULL,
944         .help_str = "help all|control|display|config|ports|register|filters: "
945                 "Show help",
946         .tokens = {
947                 (void *)&cmd_help_long_help,
948                 (void *)&cmd_help_long_section,
949                 NULL,
950         },
951 };
952
953
954 /* *** start/stop/close all ports *** */
955 struct cmd_operate_port_result {
956         cmdline_fixed_string_t keyword;
957         cmdline_fixed_string_t name;
958         cmdline_fixed_string_t value;
959 };
960
961 static void cmd_operate_port_parsed(void *parsed_result,
962                                 __attribute__((unused)) struct cmdline *cl,
963                                 __attribute__((unused)) void *data)
964 {
965         struct cmd_operate_port_result *res = parsed_result;
966
967         if (!strcmp(res->name, "start"))
968                 start_port(RTE_PORT_ALL);
969         else if (!strcmp(res->name, "stop"))
970                 stop_port(RTE_PORT_ALL);
971         else if (!strcmp(res->name, "close"))
972                 close_port(RTE_PORT_ALL);
973         else
974                 printf("Unknown parameter\n");
975 }
976
977 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
978         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
979                                                                 "port");
980 cmdline_parse_token_string_t cmd_operate_port_all_port =
981         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
982                                                 "start#stop#close");
983 cmdline_parse_token_string_t cmd_operate_port_all_all =
984         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
985
986 cmdline_parse_inst_t cmd_operate_port = {
987         .f = cmd_operate_port_parsed,
988         .data = NULL,
989         .help_str = "port start|stop|close all: Start/Stop/Close all ports",
990         .tokens = {
991                 (void *)&cmd_operate_port_all_cmd,
992                 (void *)&cmd_operate_port_all_port,
993                 (void *)&cmd_operate_port_all_all,
994                 NULL,
995         },
996 };
997
998 /* *** start/stop/close specific port *** */
999 struct cmd_operate_specific_port_result {
1000         cmdline_fixed_string_t keyword;
1001         cmdline_fixed_string_t name;
1002         uint8_t value;
1003 };
1004
1005 static void cmd_operate_specific_port_parsed(void *parsed_result,
1006                         __attribute__((unused)) struct cmdline *cl,
1007                                 __attribute__((unused)) void *data)
1008 {
1009         struct cmd_operate_specific_port_result *res = parsed_result;
1010
1011         if (!strcmp(res->name, "start"))
1012                 start_port(res->value);
1013         else if (!strcmp(res->name, "stop"))
1014                 stop_port(res->value);
1015         else if (!strcmp(res->name, "close"))
1016                 close_port(res->value);
1017         else
1018                 printf("Unknown parameter\n");
1019 }
1020
1021 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1022         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1023                                                         keyword, "port");
1024 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1025         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1026                                                 name, "start#stop#close");
1027 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1028         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1029                                                         value, UINT8);
1030
1031 cmdline_parse_inst_t cmd_operate_specific_port = {
1032         .f = cmd_operate_specific_port_parsed,
1033         .data = NULL,
1034         .help_str = "port start|stop|close <port_id>: Start/Stop/Close port_id",
1035         .tokens = {
1036                 (void *)&cmd_operate_specific_port_cmd,
1037                 (void *)&cmd_operate_specific_port_port,
1038                 (void *)&cmd_operate_specific_port_id,
1039                 NULL,
1040         },
1041 };
1042
1043 /* *** attach a specified port *** */
1044 struct cmd_operate_attach_port_result {
1045         cmdline_fixed_string_t port;
1046         cmdline_fixed_string_t keyword;
1047         cmdline_fixed_string_t identifier;
1048 };
1049
1050 static void cmd_operate_attach_port_parsed(void *parsed_result,
1051                                 __attribute__((unused)) struct cmdline *cl,
1052                                 __attribute__((unused)) void *data)
1053 {
1054         struct cmd_operate_attach_port_result *res = parsed_result;
1055
1056         if (!strcmp(res->keyword, "attach"))
1057                 attach_port(res->identifier);
1058         else
1059                 printf("Unknown parameter\n");
1060 }
1061
1062 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1063         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1064                         port, "port");
1065 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1066         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1067                         keyword, "attach");
1068 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1069         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1070                         identifier, NULL);
1071
1072 cmdline_parse_inst_t cmd_operate_attach_port = {
1073         .f = cmd_operate_attach_port_parsed,
1074         .data = NULL,
1075         .help_str = "port attach <identifier>: "
1076                 "(identifier: pci address or virtual dev name)",
1077         .tokens = {
1078                 (void *)&cmd_operate_attach_port_port,
1079                 (void *)&cmd_operate_attach_port_keyword,
1080                 (void *)&cmd_operate_attach_port_identifier,
1081                 NULL,
1082         },
1083 };
1084
1085 /* *** detach a specified port *** */
1086 struct cmd_operate_detach_port_result {
1087         cmdline_fixed_string_t port;
1088         cmdline_fixed_string_t keyword;
1089         uint8_t port_id;
1090 };
1091
1092 static void cmd_operate_detach_port_parsed(void *parsed_result,
1093                                 __attribute__((unused)) struct cmdline *cl,
1094                                 __attribute__((unused)) void *data)
1095 {
1096         struct cmd_operate_detach_port_result *res = parsed_result;
1097
1098         if (!strcmp(res->keyword, "detach"))
1099                 detach_port(res->port_id);
1100         else
1101                 printf("Unknown parameter\n");
1102 }
1103
1104 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1105         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1106                         port, "port");
1107 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1108         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1109                         keyword, "detach");
1110 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1111         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1112                         port_id, UINT8);
1113
1114 cmdline_parse_inst_t cmd_operate_detach_port = {
1115         .f = cmd_operate_detach_port_parsed,
1116         .data = NULL,
1117         .help_str = "port detach <port_id>",
1118         .tokens = {
1119                 (void *)&cmd_operate_detach_port_port,
1120                 (void *)&cmd_operate_detach_port_keyword,
1121                 (void *)&cmd_operate_detach_port_port_id,
1122                 NULL,
1123         },
1124 };
1125
1126 /* *** configure speed for all ports *** */
1127 struct cmd_config_speed_all {
1128         cmdline_fixed_string_t port;
1129         cmdline_fixed_string_t keyword;
1130         cmdline_fixed_string_t all;
1131         cmdline_fixed_string_t item1;
1132         cmdline_fixed_string_t item2;
1133         cmdline_fixed_string_t value1;
1134         cmdline_fixed_string_t value2;
1135 };
1136
1137 static int
1138 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1139 {
1140
1141         int duplex;
1142
1143         if (!strcmp(duplexstr, "half")) {
1144                 duplex = ETH_LINK_HALF_DUPLEX;
1145         } else if (!strcmp(duplexstr, "full")) {
1146                 duplex = ETH_LINK_FULL_DUPLEX;
1147         } else if (!strcmp(duplexstr, "auto")) {
1148                 duplex = ETH_LINK_FULL_DUPLEX;
1149         } else {
1150                 printf("Unknown duplex parameter\n");
1151                 return -1;
1152         }
1153
1154         if (!strcmp(speedstr, "10")) {
1155                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1156                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1157         } else if (!strcmp(speedstr, "100")) {
1158                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1159                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1160         } else {
1161                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1162                         printf("Invalid speed/duplex parameters\n");
1163                         return -1;
1164                 }
1165                 if (!strcmp(speedstr, "1000")) {
1166                         *speed = ETH_LINK_SPEED_1G;
1167                 } else if (!strcmp(speedstr, "10000")) {
1168                         *speed = ETH_LINK_SPEED_10G;
1169                 } else if (!strcmp(speedstr, "25000")) {
1170                         *speed = ETH_LINK_SPEED_25G;
1171                 } else if (!strcmp(speedstr, "40000")) {
1172                         *speed = ETH_LINK_SPEED_40G;
1173                 } else if (!strcmp(speedstr, "50000")) {
1174                         *speed = ETH_LINK_SPEED_50G;
1175                 } else if (!strcmp(speedstr, "100000")) {
1176                         *speed = ETH_LINK_SPEED_100G;
1177                 } else if (!strcmp(speedstr, "auto")) {
1178                         *speed = ETH_LINK_SPEED_AUTONEG;
1179                 } else {
1180                         printf("Unknown speed parameter\n");
1181                         return -1;
1182                 }
1183         }
1184
1185         return 0;
1186 }
1187
1188 static void
1189 cmd_config_speed_all_parsed(void *parsed_result,
1190                         __attribute__((unused)) struct cmdline *cl,
1191                         __attribute__((unused)) void *data)
1192 {
1193         struct cmd_config_speed_all *res = parsed_result;
1194         uint32_t link_speed;
1195         portid_t pid;
1196
1197         if (!all_ports_stopped()) {
1198                 printf("Please stop all ports first\n");
1199                 return;
1200         }
1201
1202         if (parse_and_check_speed_duplex(res->value1, res->value2,
1203                         &link_speed) < 0)
1204                 return;
1205
1206         RTE_ETH_FOREACH_DEV(pid) {
1207                 ports[pid].dev_conf.link_speeds = link_speed;
1208         }
1209
1210         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1211 }
1212
1213 cmdline_parse_token_string_t cmd_config_speed_all_port =
1214         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1215 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1216         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1217                                                         "config");
1218 cmdline_parse_token_string_t cmd_config_speed_all_all =
1219         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1220 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1221         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1222 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1223         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1224                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1225 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1226         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1227 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1228         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1229                                                 "half#full#auto");
1230
1231 cmdline_parse_inst_t cmd_config_speed_all = {
1232         .f = cmd_config_speed_all_parsed,
1233         .data = NULL,
1234         .help_str = "port config all speed "
1235                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1236                                                         "half|full|auto",
1237         .tokens = {
1238                 (void *)&cmd_config_speed_all_port,
1239                 (void *)&cmd_config_speed_all_keyword,
1240                 (void *)&cmd_config_speed_all_all,
1241                 (void *)&cmd_config_speed_all_item1,
1242                 (void *)&cmd_config_speed_all_value1,
1243                 (void *)&cmd_config_speed_all_item2,
1244                 (void *)&cmd_config_speed_all_value2,
1245                 NULL,
1246         },
1247 };
1248
1249 /* *** configure speed for specific port *** */
1250 struct cmd_config_speed_specific {
1251         cmdline_fixed_string_t port;
1252         cmdline_fixed_string_t keyword;
1253         uint8_t id;
1254         cmdline_fixed_string_t item1;
1255         cmdline_fixed_string_t item2;
1256         cmdline_fixed_string_t value1;
1257         cmdline_fixed_string_t value2;
1258 };
1259
1260 static void
1261 cmd_config_speed_specific_parsed(void *parsed_result,
1262                                 __attribute__((unused)) struct cmdline *cl,
1263                                 __attribute__((unused)) void *data)
1264 {
1265         struct cmd_config_speed_specific *res = parsed_result;
1266         uint32_t link_speed;
1267
1268         if (!all_ports_stopped()) {
1269                 printf("Please stop all ports first\n");
1270                 return;
1271         }
1272
1273         if (port_id_is_invalid(res->id, ENABLED_WARN))
1274                 return;
1275
1276         if (parse_and_check_speed_duplex(res->value1, res->value2,
1277                         &link_speed) < 0)
1278                 return;
1279
1280         ports[res->id].dev_conf.link_speeds = link_speed;
1281
1282         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1283 }
1284
1285
1286 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1287         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1288                                                                 "port");
1289 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1290         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1291                                                                 "config");
1292 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1293         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1294 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1295         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1296                                                                 "speed");
1297 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1298         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1299                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1300 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1301         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1302                                                                 "duplex");
1303 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1304         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1305                                                         "half#full#auto");
1306
1307 cmdline_parse_inst_t cmd_config_speed_specific = {
1308         .f = cmd_config_speed_specific_parsed,
1309         .data = NULL,
1310         .help_str = "port config <port_id> speed "
1311                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1312                                                         "half|full|auto",
1313         .tokens = {
1314                 (void *)&cmd_config_speed_specific_port,
1315                 (void *)&cmd_config_speed_specific_keyword,
1316                 (void *)&cmd_config_speed_specific_id,
1317                 (void *)&cmd_config_speed_specific_item1,
1318                 (void *)&cmd_config_speed_specific_value1,
1319                 (void *)&cmd_config_speed_specific_item2,
1320                 (void *)&cmd_config_speed_specific_value2,
1321                 NULL,
1322         },
1323 };
1324
1325 /* *** configure txq/rxq, txd/rxd *** */
1326 struct cmd_config_rx_tx {
1327         cmdline_fixed_string_t port;
1328         cmdline_fixed_string_t keyword;
1329         cmdline_fixed_string_t all;
1330         cmdline_fixed_string_t name;
1331         uint16_t value;
1332 };
1333
1334 static void
1335 cmd_config_rx_tx_parsed(void *parsed_result,
1336                         __attribute__((unused)) struct cmdline *cl,
1337                         __attribute__((unused)) void *data)
1338 {
1339         struct cmd_config_rx_tx *res = parsed_result;
1340
1341         if (!all_ports_stopped()) {
1342                 printf("Please stop all ports first\n");
1343                 return;
1344         }
1345         if (!strcmp(res->name, "rxq")) {
1346                 if (!res->value && !nb_txq) {
1347                         printf("Warning: Either rx or tx queues should be non zero\n");
1348                         return;
1349                 }
1350                 nb_rxq = res->value;
1351         }
1352         else if (!strcmp(res->name, "txq")) {
1353                 if (!res->value && !nb_rxq) {
1354                         printf("Warning: Either rx or tx queues should be non zero\n");
1355                         return;
1356                 }
1357                 nb_txq = res->value;
1358         }
1359         else if (!strcmp(res->name, "rxd")) {
1360                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1361                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1362                                         res->value, RTE_TEST_RX_DESC_MAX);
1363                         return;
1364                 }
1365                 nb_rxd = res->value;
1366         } else if (!strcmp(res->name, "txd")) {
1367                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1368                         printf("txd %d invalid - must be > 0 && <= %d\n",
1369                                         res->value, RTE_TEST_TX_DESC_MAX);
1370                         return;
1371                 }
1372                 nb_txd = res->value;
1373         } else {
1374                 printf("Unknown parameter\n");
1375                 return;
1376         }
1377
1378         fwd_config_setup();
1379
1380         init_port_config();
1381
1382         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1383 }
1384
1385 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1386         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1387 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1388         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1389 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1390         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1391 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1392         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1393                                                 "rxq#txq#rxd#txd");
1394 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1395         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1396
1397 cmdline_parse_inst_t cmd_config_rx_tx = {
1398         .f = cmd_config_rx_tx_parsed,
1399         .data = NULL,
1400         .help_str = "port config all rxq|txq|rxd|txd <value>",
1401         .tokens = {
1402                 (void *)&cmd_config_rx_tx_port,
1403                 (void *)&cmd_config_rx_tx_keyword,
1404                 (void *)&cmd_config_rx_tx_all,
1405                 (void *)&cmd_config_rx_tx_name,
1406                 (void *)&cmd_config_rx_tx_value,
1407                 NULL,
1408         },
1409 };
1410
1411 /* *** config max packet length *** */
1412 struct cmd_config_max_pkt_len_result {
1413         cmdline_fixed_string_t port;
1414         cmdline_fixed_string_t keyword;
1415         cmdline_fixed_string_t all;
1416         cmdline_fixed_string_t name;
1417         uint32_t value;
1418 };
1419
1420 static void
1421 cmd_config_max_pkt_len_parsed(void *parsed_result,
1422                                 __attribute__((unused)) struct cmdline *cl,
1423                                 __attribute__((unused)) void *data)
1424 {
1425         struct cmd_config_max_pkt_len_result *res = parsed_result;
1426
1427         if (!all_ports_stopped()) {
1428                 printf("Please stop all ports first\n");
1429                 return;
1430         }
1431
1432         if (!strcmp(res->name, "max-pkt-len")) {
1433                 if (res->value < ETHER_MIN_LEN) {
1434                         printf("max-pkt-len can not be less than %d\n",
1435                                                         ETHER_MIN_LEN);
1436                         return;
1437                 }
1438                 if (res->value == rx_mode.max_rx_pkt_len)
1439                         return;
1440
1441                 rx_mode.max_rx_pkt_len = res->value;
1442                 if (res->value > ETHER_MAX_LEN)
1443                         rx_mode.jumbo_frame = 1;
1444                 else
1445                         rx_mode.jumbo_frame = 0;
1446         } else {
1447                 printf("Unknown parameter\n");
1448                 return;
1449         }
1450
1451         init_port_config();
1452
1453         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1454 }
1455
1456 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1457         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1458                                                                 "port");
1459 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1460         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1461                                                                 "config");
1462 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1463         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1464                                                                 "all");
1465 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1467                                                                 "max-pkt-len");
1468 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1469         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1470                                                                 UINT32);
1471
1472 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1473         .f = cmd_config_max_pkt_len_parsed,
1474         .data = NULL,
1475         .help_str = "port config all max-pkt-len <value>",
1476         .tokens = {
1477                 (void *)&cmd_config_max_pkt_len_port,
1478                 (void *)&cmd_config_max_pkt_len_keyword,
1479                 (void *)&cmd_config_max_pkt_len_all,
1480                 (void *)&cmd_config_max_pkt_len_name,
1481                 (void *)&cmd_config_max_pkt_len_value,
1482                 NULL,
1483         },
1484 };
1485
1486 /* *** configure port MTU *** */
1487 struct cmd_config_mtu_result {
1488         cmdline_fixed_string_t port;
1489         cmdline_fixed_string_t keyword;
1490         cmdline_fixed_string_t mtu;
1491         uint8_t port_id;
1492         uint16_t value;
1493 };
1494
1495 static void
1496 cmd_config_mtu_parsed(void *parsed_result,
1497                       __attribute__((unused)) struct cmdline *cl,
1498                       __attribute__((unused)) void *data)
1499 {
1500         struct cmd_config_mtu_result *res = parsed_result;
1501
1502         if (res->value < ETHER_MIN_LEN) {
1503                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1504                 return;
1505         }
1506         port_mtu_set(res->port_id, res->value);
1507 }
1508
1509 cmdline_parse_token_string_t cmd_config_mtu_port =
1510         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1511                                  "port");
1512 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1513         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1514                                  "config");
1515 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1516         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1517                                  "mtu");
1518 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1519         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1520 cmdline_parse_token_num_t cmd_config_mtu_value =
1521         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1522
1523 cmdline_parse_inst_t cmd_config_mtu = {
1524         .f = cmd_config_mtu_parsed,
1525         .data = NULL,
1526         .help_str = "port config mtu <port_id> <value>",
1527         .tokens = {
1528                 (void *)&cmd_config_mtu_port,
1529                 (void *)&cmd_config_mtu_keyword,
1530                 (void *)&cmd_config_mtu_mtu,
1531                 (void *)&cmd_config_mtu_port_id,
1532                 (void *)&cmd_config_mtu_value,
1533                 NULL,
1534         },
1535 };
1536
1537 /* *** configure rx mode *** */
1538 struct cmd_config_rx_mode_flag {
1539         cmdline_fixed_string_t port;
1540         cmdline_fixed_string_t keyword;
1541         cmdline_fixed_string_t all;
1542         cmdline_fixed_string_t name;
1543         cmdline_fixed_string_t value;
1544 };
1545
1546 static void
1547 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1548                                 __attribute__((unused)) struct cmdline *cl,
1549                                 __attribute__((unused)) void *data)
1550 {
1551         struct cmd_config_rx_mode_flag *res = parsed_result;
1552
1553         if (!all_ports_stopped()) {
1554                 printf("Please stop all ports first\n");
1555                 return;
1556         }
1557
1558         if (!strcmp(res->name, "crc-strip")) {
1559                 if (!strcmp(res->value, "on"))
1560                         rx_mode.hw_strip_crc = 1;
1561                 else if (!strcmp(res->value, "off"))
1562                         rx_mode.hw_strip_crc = 0;
1563                 else {
1564                         printf("Unknown parameter\n");
1565                         return;
1566                 }
1567         } else if (!strcmp(res->name, "scatter")) {
1568                 if (!strcmp(res->value, "on"))
1569                         rx_mode.enable_scatter = 1;
1570                 else if (!strcmp(res->value, "off"))
1571                         rx_mode.enable_scatter = 0;
1572                 else {
1573                         printf("Unknown parameter\n");
1574                         return;
1575                 }
1576         } else if (!strcmp(res->name, "rx-cksum")) {
1577                 if (!strcmp(res->value, "on"))
1578                         rx_mode.hw_ip_checksum = 1;
1579                 else if (!strcmp(res->value, "off"))
1580                         rx_mode.hw_ip_checksum = 0;
1581                 else {
1582                         printf("Unknown parameter\n");
1583                         return;
1584                 }
1585         } else if (!strcmp(res->name, "hw-vlan")) {
1586                 if (!strcmp(res->value, "on")) {
1587                         rx_mode.hw_vlan_filter = 1;
1588                         rx_mode.hw_vlan_strip  = 1;
1589                 }
1590                 else if (!strcmp(res->value, "off")) {
1591                         rx_mode.hw_vlan_filter = 0;
1592                         rx_mode.hw_vlan_strip  = 0;
1593                 }
1594                 else {
1595                         printf("Unknown parameter\n");
1596                         return;
1597                 }
1598         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1599                 if (!strcmp(res->value, "on"))
1600                         rx_mode.hw_vlan_filter = 1;
1601                 else if (!strcmp(res->value, "off"))
1602                         rx_mode.hw_vlan_filter = 0;
1603                 else {
1604                         printf("Unknown parameter\n");
1605                         return;
1606                 }
1607         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1608                 if (!strcmp(res->value, "on"))
1609                         rx_mode.hw_vlan_strip  = 1;
1610                 else if (!strcmp(res->value, "off"))
1611                         rx_mode.hw_vlan_strip  = 0;
1612                 else {
1613                         printf("Unknown parameter\n");
1614                         return;
1615                 }
1616         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1617                 if (!strcmp(res->value, "on"))
1618                         rx_mode.hw_vlan_extend = 1;
1619                 else if (!strcmp(res->value, "off"))
1620                         rx_mode.hw_vlan_extend = 0;
1621                 else {
1622                         printf("Unknown parameter\n");
1623                         return;
1624                 }
1625         } else if (!strcmp(res->name, "drop-en")) {
1626                 if (!strcmp(res->value, "on"))
1627                         rx_drop_en = 1;
1628                 else if (!strcmp(res->value, "off"))
1629                         rx_drop_en = 0;
1630                 else {
1631                         printf("Unknown parameter\n");
1632                         return;
1633                 }
1634         } else {
1635                 printf("Unknown parameter\n");
1636                 return;
1637         }
1638
1639         init_port_config();
1640
1641         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1642 }
1643
1644 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1645         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1646 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1647         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1648                                                                 "config");
1649 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1650         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1651 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1652         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1653                                         "crc-strip#scatter#rx-cksum#hw-vlan#"
1654                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1655 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1656         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1657                                                         "on#off");
1658
1659 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1660         .f = cmd_config_rx_mode_flag_parsed,
1661         .data = NULL,
1662         .help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|"
1663                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1664         .tokens = {
1665                 (void *)&cmd_config_rx_mode_flag_port,
1666                 (void *)&cmd_config_rx_mode_flag_keyword,
1667                 (void *)&cmd_config_rx_mode_flag_all,
1668                 (void *)&cmd_config_rx_mode_flag_name,
1669                 (void *)&cmd_config_rx_mode_flag_value,
1670                 NULL,
1671         },
1672 };
1673
1674 /* *** configure rss *** */
1675 struct cmd_config_rss {
1676         cmdline_fixed_string_t port;
1677         cmdline_fixed_string_t keyword;
1678         cmdline_fixed_string_t all;
1679         cmdline_fixed_string_t name;
1680         cmdline_fixed_string_t value;
1681 };
1682
1683 static void
1684 cmd_config_rss_parsed(void *parsed_result,
1685                         __attribute__((unused)) struct cmdline *cl,
1686                         __attribute__((unused)) void *data)
1687 {
1688         struct cmd_config_rss *res = parsed_result;
1689         struct rte_eth_rss_conf rss_conf;
1690         int diag;
1691         uint8_t i;
1692
1693         if (!strcmp(res->value, "all"))
1694                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1695                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1696                                         ETH_RSS_L2_PAYLOAD;
1697         else if (!strcmp(res->value, "ip"))
1698                 rss_conf.rss_hf = ETH_RSS_IP;
1699         else if (!strcmp(res->value, "udp"))
1700                 rss_conf.rss_hf = ETH_RSS_UDP;
1701         else if (!strcmp(res->value, "tcp"))
1702                 rss_conf.rss_hf = ETH_RSS_TCP;
1703         else if (!strcmp(res->value, "sctp"))
1704                 rss_conf.rss_hf = ETH_RSS_SCTP;
1705         else if (!strcmp(res->value, "ether"))
1706                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1707         else if (!strcmp(res->value, "port"))
1708                 rss_conf.rss_hf = ETH_RSS_PORT;
1709         else if (!strcmp(res->value, "vxlan"))
1710                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1711         else if (!strcmp(res->value, "geneve"))
1712                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1713         else if (!strcmp(res->value, "nvgre"))
1714                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1715         else if (!strcmp(res->value, "none"))
1716                 rss_conf.rss_hf = 0;
1717         else {
1718                 printf("Unknown parameter\n");
1719                 return;
1720         }
1721         rss_conf.rss_key = NULL;
1722         for (i = 0; i < rte_eth_dev_count(); i++) {
1723                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1724                 if (diag < 0)
1725                         printf("Configuration of RSS hash at ethernet port %d "
1726                                 "failed with error (%d): %s.\n",
1727                                 i, -diag, strerror(-diag));
1728         }
1729 }
1730
1731 cmdline_parse_token_string_t cmd_config_rss_port =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1733 cmdline_parse_token_string_t cmd_config_rss_keyword =
1734         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1735 cmdline_parse_token_string_t cmd_config_rss_all =
1736         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1737 cmdline_parse_token_string_t cmd_config_rss_name =
1738         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1739 cmdline_parse_token_string_t cmd_config_rss_value =
1740         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value,
1741                 "all#ip#tcp#udp#sctp#ether#port#vxlan#geneve#nvgre#none");
1742
1743 cmdline_parse_inst_t cmd_config_rss = {
1744         .f = cmd_config_rss_parsed,
1745         .data = NULL,
1746         .help_str = "port config all rss "
1747                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none",
1748         .tokens = {
1749                 (void *)&cmd_config_rss_port,
1750                 (void *)&cmd_config_rss_keyword,
1751                 (void *)&cmd_config_rss_all,
1752                 (void *)&cmd_config_rss_name,
1753                 (void *)&cmd_config_rss_value,
1754                 NULL,
1755         },
1756 };
1757
1758 /* *** configure rss hash key *** */
1759 struct cmd_config_rss_hash_key {
1760         cmdline_fixed_string_t port;
1761         cmdline_fixed_string_t config;
1762         uint8_t port_id;
1763         cmdline_fixed_string_t rss_hash_key;
1764         cmdline_fixed_string_t rss_type;
1765         cmdline_fixed_string_t key;
1766 };
1767
1768 static uint8_t
1769 hexa_digit_to_value(char hexa_digit)
1770 {
1771         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1772                 return (uint8_t) (hexa_digit - '0');
1773         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1774                 return (uint8_t) ((hexa_digit - 'a') + 10);
1775         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1776                 return (uint8_t) ((hexa_digit - 'A') + 10);
1777         /* Invalid hexa digit */
1778         return 0xFF;
1779 }
1780
1781 static uint8_t
1782 parse_and_check_key_hexa_digit(char *key, int idx)
1783 {
1784         uint8_t hexa_v;
1785
1786         hexa_v = hexa_digit_to_value(key[idx]);
1787         if (hexa_v == 0xFF)
1788                 printf("invalid key: character %c at position %d is not a "
1789                        "valid hexa digit\n", key[idx], idx);
1790         return hexa_v;
1791 }
1792
1793 static void
1794 cmd_config_rss_hash_key_parsed(void *parsed_result,
1795                                __attribute__((unused)) struct cmdline *cl,
1796                                __attribute__((unused)) void *data)
1797 {
1798         struct cmd_config_rss_hash_key *res = parsed_result;
1799         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1800         uint8_t xdgt0;
1801         uint8_t xdgt1;
1802         int i;
1803         struct rte_eth_dev_info dev_info;
1804         uint8_t hash_key_size;
1805         uint32_t key_len;
1806
1807         memset(&dev_info, 0, sizeof(dev_info));
1808         rte_eth_dev_info_get(res->port_id, &dev_info);
1809         if (dev_info.hash_key_size > 0 &&
1810                         dev_info.hash_key_size <= sizeof(hash_key))
1811                 hash_key_size = dev_info.hash_key_size;
1812         else {
1813                 printf("dev_info did not provide a valid hash key size\n");
1814                 return;
1815         }
1816         /* Check the length of the RSS hash key */
1817         key_len = strlen(res->key);
1818         if (key_len != (hash_key_size * 2)) {
1819                 printf("key length: %d invalid - key must be a string of %d"
1820                            " hexa-decimal numbers\n",
1821                            (int) key_len, hash_key_size * 2);
1822                 return;
1823         }
1824         /* Translate RSS hash key into binary representation */
1825         for (i = 0; i < hash_key_size; i++) {
1826                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1827                 if (xdgt0 == 0xFF)
1828                         return;
1829                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1830                 if (xdgt1 == 0xFF)
1831                         return;
1832                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1833         }
1834         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1835                         hash_key_size);
1836 }
1837
1838 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1839         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1840 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1841         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1842                                  "config");
1843 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1844         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1845 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1846         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1847                                  rss_hash_key, "rss-hash-key");
1848 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1849         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1850                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1851                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1852                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1853                                  "ipv6-tcp-ex#ipv6-udp-ex");
1854 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1855         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1856
1857 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1858         .f = cmd_config_rss_hash_key_parsed,
1859         .data = NULL,
1860         .help_str = "port config <port_id> rss-hash-key "
1861                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1862                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1863                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
1864                 "<string of hex digits (variable length, NIC dependent)>",
1865         .tokens = {
1866                 (void *)&cmd_config_rss_hash_key_port,
1867                 (void *)&cmd_config_rss_hash_key_config,
1868                 (void *)&cmd_config_rss_hash_key_port_id,
1869                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1870                 (void *)&cmd_config_rss_hash_key_rss_type,
1871                 (void *)&cmd_config_rss_hash_key_value,
1872                 NULL,
1873         },
1874 };
1875
1876 /* *** configure port rxq/txq start/stop *** */
1877 struct cmd_config_rxtx_queue {
1878         cmdline_fixed_string_t port;
1879         uint8_t portid;
1880         cmdline_fixed_string_t rxtxq;
1881         uint16_t qid;
1882         cmdline_fixed_string_t opname;
1883 };
1884
1885 static void
1886 cmd_config_rxtx_queue_parsed(void *parsed_result,
1887                         __attribute__((unused)) struct cmdline *cl,
1888                         __attribute__((unused)) void *data)
1889 {
1890         struct cmd_config_rxtx_queue *res = parsed_result;
1891         uint8_t isrx;
1892         uint8_t isstart;
1893         int ret = 0;
1894
1895         if (test_done == 0) {
1896                 printf("Please stop forwarding first\n");
1897                 return;
1898         }
1899
1900         if (port_id_is_invalid(res->portid, ENABLED_WARN))
1901                 return;
1902
1903         if (port_is_started(res->portid) != 1) {
1904                 printf("Please start port %u first\n", res->portid);
1905                 return;
1906         }
1907
1908         if (!strcmp(res->rxtxq, "rxq"))
1909                 isrx = 1;
1910         else if (!strcmp(res->rxtxq, "txq"))
1911                 isrx = 0;
1912         else {
1913                 printf("Unknown parameter\n");
1914                 return;
1915         }
1916
1917         if (isrx && rx_queue_id_is_invalid(res->qid))
1918                 return;
1919         else if (!isrx && tx_queue_id_is_invalid(res->qid))
1920                 return;
1921
1922         if (!strcmp(res->opname, "start"))
1923                 isstart = 1;
1924         else if (!strcmp(res->opname, "stop"))
1925                 isstart = 0;
1926         else {
1927                 printf("Unknown parameter\n");
1928                 return;
1929         }
1930
1931         if (isstart && isrx)
1932                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1933         else if (!isstart && isrx)
1934                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1935         else if (isstart && !isrx)
1936                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1937         else
1938                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1939
1940         if (ret == -ENOTSUP)
1941                 printf("Function not supported in PMD driver\n");
1942 }
1943
1944 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1945         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1946 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1947         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1948 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1949         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1950 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1951         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
1952 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
1953         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
1954                                                 "start#stop");
1955
1956 cmdline_parse_inst_t cmd_config_rxtx_queue = {
1957         .f = cmd_config_rxtx_queue_parsed,
1958         .data = NULL,
1959         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
1960         .tokens = {
1961                 (void *)&cmd_config_speed_all_port,
1962                 (void *)&cmd_config_rxtx_queue_portid,
1963                 (void *)&cmd_config_rxtx_queue_rxtxq,
1964                 (void *)&cmd_config_rxtx_queue_qid,
1965                 (void *)&cmd_config_rxtx_queue_opname,
1966                 NULL,
1967         },
1968 };
1969
1970 /* *** Configure RSS RETA *** */
1971 struct cmd_config_rss_reta {
1972         cmdline_fixed_string_t port;
1973         cmdline_fixed_string_t keyword;
1974         uint8_t port_id;
1975         cmdline_fixed_string_t name;
1976         cmdline_fixed_string_t list_name;
1977         cmdline_fixed_string_t list_of_items;
1978 };
1979
1980 static int
1981 parse_reta_config(const char *str,
1982                   struct rte_eth_rss_reta_entry64 *reta_conf,
1983                   uint16_t nb_entries)
1984 {
1985         int i;
1986         unsigned size;
1987         uint16_t hash_index, idx, shift;
1988         uint16_t nb_queue;
1989         char s[256];
1990         const char *p, *p0 = str;
1991         char *end;
1992         enum fieldnames {
1993                 FLD_HASH_INDEX = 0,
1994                 FLD_QUEUE,
1995                 _NUM_FLD
1996         };
1997         unsigned long int_fld[_NUM_FLD];
1998         char *str_fld[_NUM_FLD];
1999
2000         while ((p = strchr(p0,'(')) != NULL) {
2001                 ++p;
2002                 if((p0 = strchr(p,')')) == NULL)
2003                         return -1;
2004
2005                 size = p0 - p;
2006                 if(size >= sizeof(s))
2007                         return -1;
2008
2009                 snprintf(s, sizeof(s), "%.*s", size, p);
2010                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2011                         return -1;
2012                 for (i = 0; i < _NUM_FLD; i++) {
2013                         errno = 0;
2014                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2015                         if (errno != 0 || end == str_fld[i] ||
2016                                         int_fld[i] > 65535)
2017                                 return -1;
2018                 }
2019
2020                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2021                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2022
2023                 if (hash_index >= nb_entries) {
2024                         printf("Invalid RETA hash index=%d\n", hash_index);
2025                         return -1;
2026                 }
2027
2028                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2029                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2030                 reta_conf[idx].mask |= (1ULL << shift);
2031                 reta_conf[idx].reta[shift] = nb_queue;
2032         }
2033
2034         return 0;
2035 }
2036
2037 static void
2038 cmd_set_rss_reta_parsed(void *parsed_result,
2039                         __attribute__((unused)) struct cmdline *cl,
2040                         __attribute__((unused)) void *data)
2041 {
2042         int ret;
2043         struct rte_eth_dev_info dev_info;
2044         struct rte_eth_rss_reta_entry64 reta_conf[8];
2045         struct cmd_config_rss_reta *res = parsed_result;
2046
2047         memset(&dev_info, 0, sizeof(dev_info));
2048         rte_eth_dev_info_get(res->port_id, &dev_info);
2049         if (dev_info.reta_size == 0) {
2050                 printf("Redirection table size is 0 which is "
2051                                         "invalid for RSS\n");
2052                 return;
2053         } else
2054                 printf("The reta size of port %d is %u\n",
2055                         res->port_id, dev_info.reta_size);
2056         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2057                 printf("Currently do not support more than %u entries of "
2058                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2059                 return;
2060         }
2061
2062         memset(reta_conf, 0, sizeof(reta_conf));
2063         if (!strcmp(res->list_name, "reta")) {
2064                 if (parse_reta_config(res->list_of_items, reta_conf,
2065                                                 dev_info.reta_size)) {
2066                         printf("Invalid RSS Redirection Table "
2067                                         "config entered\n");
2068                         return;
2069                 }
2070                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2071                                 reta_conf, dev_info.reta_size);
2072                 if (ret != 0)
2073                         printf("Bad redirection table parameter, "
2074                                         "return code = %d \n", ret);
2075         }
2076 }
2077
2078 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2079         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2080 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2081         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2082 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2083         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
2084 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2085         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2086 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2087         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2088 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2089         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2090                                  NULL);
2091 cmdline_parse_inst_t cmd_config_rss_reta = {
2092         .f = cmd_set_rss_reta_parsed,
2093         .data = NULL,
2094         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2095         .tokens = {
2096                 (void *)&cmd_config_rss_reta_port,
2097                 (void *)&cmd_config_rss_reta_keyword,
2098                 (void *)&cmd_config_rss_reta_port_id,
2099                 (void *)&cmd_config_rss_reta_name,
2100                 (void *)&cmd_config_rss_reta_list_name,
2101                 (void *)&cmd_config_rss_reta_list_of_items,
2102                 NULL,
2103         },
2104 };
2105
2106 /* *** SHOW PORT RETA INFO *** */
2107 struct cmd_showport_reta {
2108         cmdline_fixed_string_t show;
2109         cmdline_fixed_string_t port;
2110         uint8_t port_id;
2111         cmdline_fixed_string_t rss;
2112         cmdline_fixed_string_t reta;
2113         uint16_t size;
2114         cmdline_fixed_string_t list_of_items;
2115 };
2116
2117 static int
2118 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2119                            uint16_t nb_entries,
2120                            char *str)
2121 {
2122         uint32_t size;
2123         const char *p, *p0 = str;
2124         char s[256];
2125         char *end;
2126         char *str_fld[8];
2127         uint16_t i;
2128         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2129                         RTE_RETA_GROUP_SIZE;
2130         int ret;
2131
2132         p = strchr(p0, '(');
2133         if (p == NULL)
2134                 return -1;
2135         p++;
2136         p0 = strchr(p, ')');
2137         if (p0 == NULL)
2138                 return -1;
2139         size = p0 - p;
2140         if (size >= sizeof(s)) {
2141                 printf("The string size exceeds the internal buffer size\n");
2142                 return -1;
2143         }
2144         snprintf(s, sizeof(s), "%.*s", size, p);
2145         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2146         if (ret <= 0 || ret != num) {
2147                 printf("The bits of masks do not match the number of "
2148                                         "reta entries: %u\n", num);
2149                 return -1;
2150         }
2151         for (i = 0; i < ret; i++)
2152                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2153
2154         return 0;
2155 }
2156
2157 static void
2158 cmd_showport_reta_parsed(void *parsed_result,
2159                          __attribute__((unused)) struct cmdline *cl,
2160                          __attribute__((unused)) void *data)
2161 {
2162         struct cmd_showport_reta *res = parsed_result;
2163         struct rte_eth_rss_reta_entry64 reta_conf[8];
2164         struct rte_eth_dev_info dev_info;
2165
2166         memset(&dev_info, 0, sizeof(dev_info));
2167         rte_eth_dev_info_get(res->port_id, &dev_info);
2168         if (dev_info.reta_size == 0 || res->size != dev_info.reta_size ||
2169                                 res->size > ETH_RSS_RETA_SIZE_512) {
2170                 printf("Invalid redirection table size: %u\n", res->size);
2171                 return;
2172         }
2173
2174         memset(reta_conf, 0, sizeof(reta_conf));
2175         if (showport_parse_reta_config(reta_conf, res->size,
2176                                 res->list_of_items) < 0) {
2177                 printf("Invalid string: %s for reta masks\n",
2178                                         res->list_of_items);
2179                 return;
2180         }
2181         port_rss_reta_info(res->port_id, reta_conf, res->size);
2182 }
2183
2184 cmdline_parse_token_string_t cmd_showport_reta_show =
2185         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2186 cmdline_parse_token_string_t cmd_showport_reta_port =
2187         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2188 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2189         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
2190 cmdline_parse_token_string_t cmd_showport_reta_rss =
2191         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2192 cmdline_parse_token_string_t cmd_showport_reta_reta =
2193         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2194 cmdline_parse_token_num_t cmd_showport_reta_size =
2195         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2196 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2197         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2198                                         list_of_items, NULL);
2199
2200 cmdline_parse_inst_t cmd_showport_reta = {
2201         .f = cmd_showport_reta_parsed,
2202         .data = NULL,
2203         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2204         .tokens = {
2205                 (void *)&cmd_showport_reta_show,
2206                 (void *)&cmd_showport_reta_port,
2207                 (void *)&cmd_showport_reta_port_id,
2208                 (void *)&cmd_showport_reta_rss,
2209                 (void *)&cmd_showport_reta_reta,
2210                 (void *)&cmd_showport_reta_size,
2211                 (void *)&cmd_showport_reta_list_of_items,
2212                 NULL,
2213         },
2214 };
2215
2216 /* *** Show RSS hash configuration *** */
2217 struct cmd_showport_rss_hash {
2218         cmdline_fixed_string_t show;
2219         cmdline_fixed_string_t port;
2220         uint8_t port_id;
2221         cmdline_fixed_string_t rss_hash;
2222         cmdline_fixed_string_t rss_type;
2223         cmdline_fixed_string_t key; /* optional argument */
2224 };
2225
2226 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2227                                 __attribute__((unused)) struct cmdline *cl,
2228                                 void *show_rss_key)
2229 {
2230         struct cmd_showport_rss_hash *res = parsed_result;
2231
2232         port_rss_hash_conf_show(res->port_id, res->rss_type,
2233                                 show_rss_key != NULL);
2234 }
2235
2236 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2237         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2238 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2239         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2240 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2241         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
2242 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2243         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2244                                  "rss-hash");
2245 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2246         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2247                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2248                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2249                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2250                                  "ipv6-tcp-ex#ipv6-udp-ex");
2251 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2252         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2253
2254 cmdline_parse_inst_t cmd_showport_rss_hash = {
2255         .f = cmd_showport_rss_hash_parsed,
2256         .data = NULL,
2257         .help_str = "show port <port_id> rss-hash "
2258                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2259                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2260                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2261         .tokens = {
2262                 (void *)&cmd_showport_rss_hash_show,
2263                 (void *)&cmd_showport_rss_hash_port,
2264                 (void *)&cmd_showport_rss_hash_port_id,
2265                 (void *)&cmd_showport_rss_hash_rss_hash,
2266                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2267                 NULL,
2268         },
2269 };
2270
2271 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2272         .f = cmd_showport_rss_hash_parsed,
2273         .data = (void *)1,
2274         .help_str = "show port <port_id> rss-hash "
2275                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2276                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2277                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2278         .tokens = {
2279                 (void *)&cmd_showport_rss_hash_show,
2280                 (void *)&cmd_showport_rss_hash_port,
2281                 (void *)&cmd_showport_rss_hash_port_id,
2282                 (void *)&cmd_showport_rss_hash_rss_hash,
2283                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2284                 (void *)&cmd_showport_rss_hash_rss_key,
2285                 NULL,
2286         },
2287 };
2288
2289 /* *** Configure DCB *** */
2290 struct cmd_config_dcb {
2291         cmdline_fixed_string_t port;
2292         cmdline_fixed_string_t config;
2293         uint8_t port_id;
2294         cmdline_fixed_string_t dcb;
2295         cmdline_fixed_string_t vt;
2296         cmdline_fixed_string_t vt_en;
2297         uint8_t num_tcs;
2298         cmdline_fixed_string_t pfc;
2299         cmdline_fixed_string_t pfc_en;
2300 };
2301
2302 static void
2303 cmd_config_dcb_parsed(void *parsed_result,
2304                         __attribute__((unused)) struct cmdline *cl,
2305                         __attribute__((unused)) void *data)
2306 {
2307         struct cmd_config_dcb *res = parsed_result;
2308         portid_t port_id = res->port_id;
2309         struct rte_port *port;
2310         uint8_t pfc_en;
2311         int ret;
2312
2313         port = &ports[port_id];
2314         /** Check if the port is not started **/
2315         if (port->port_status != RTE_PORT_STOPPED) {
2316                 printf("Please stop port %d first\n", port_id);
2317                 return;
2318         }
2319
2320         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2321                 printf("The invalid number of traffic class,"
2322                         " only 4 or 8 allowed.\n");
2323                 return;
2324         }
2325
2326         if (nb_fwd_lcores < res->num_tcs) {
2327                 printf("nb_cores shouldn't be less than number of TCs.\n");
2328                 return;
2329         }
2330         if (!strncmp(res->pfc_en, "on", 2))
2331                 pfc_en = 1;
2332         else
2333                 pfc_en = 0;
2334
2335         /* DCB in VT mode */
2336         if (!strncmp(res->vt_en, "on", 2))
2337                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2338                                 (enum rte_eth_nb_tcs)res->num_tcs,
2339                                 pfc_en);
2340         else
2341                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2342                                 (enum rte_eth_nb_tcs)res->num_tcs,
2343                                 pfc_en);
2344
2345
2346         if (ret != 0) {
2347                 printf("Cannot initialize network ports.\n");
2348                 return;
2349         }
2350
2351         cmd_reconfig_device_queue(port_id, 1, 1);
2352 }
2353
2354 cmdline_parse_token_string_t cmd_config_dcb_port =
2355         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2356 cmdline_parse_token_string_t cmd_config_dcb_config =
2357         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2358 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2359         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2360 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2361         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2362 cmdline_parse_token_string_t cmd_config_dcb_vt =
2363         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2364 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2365         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2366 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2367         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2368 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2369         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2370 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2371         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2372
2373 cmdline_parse_inst_t cmd_config_dcb = {
2374         .f = cmd_config_dcb_parsed,
2375         .data = NULL,
2376         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2377         .tokens = {
2378                 (void *)&cmd_config_dcb_port,
2379                 (void *)&cmd_config_dcb_config,
2380                 (void *)&cmd_config_dcb_port_id,
2381                 (void *)&cmd_config_dcb_dcb,
2382                 (void *)&cmd_config_dcb_vt,
2383                 (void *)&cmd_config_dcb_vt_en,
2384                 (void *)&cmd_config_dcb_num_tcs,
2385                 (void *)&cmd_config_dcb_pfc,
2386                 (void *)&cmd_config_dcb_pfc_en,
2387                 NULL,
2388         },
2389 };
2390
2391 /* *** configure number of packets per burst *** */
2392 struct cmd_config_burst {
2393         cmdline_fixed_string_t port;
2394         cmdline_fixed_string_t keyword;
2395         cmdline_fixed_string_t all;
2396         cmdline_fixed_string_t name;
2397         uint16_t value;
2398 };
2399
2400 static void
2401 cmd_config_burst_parsed(void *parsed_result,
2402                         __attribute__((unused)) struct cmdline *cl,
2403                         __attribute__((unused)) void *data)
2404 {
2405         struct cmd_config_burst *res = parsed_result;
2406
2407         if (!all_ports_stopped()) {
2408                 printf("Please stop all ports first\n");
2409                 return;
2410         }
2411
2412         if (!strcmp(res->name, "burst")) {
2413                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2414                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2415                         return;
2416                 }
2417                 nb_pkt_per_burst = res->value;
2418         } else {
2419                 printf("Unknown parameter\n");
2420                 return;
2421         }
2422
2423         init_port_config();
2424
2425         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2426 }
2427
2428 cmdline_parse_token_string_t cmd_config_burst_port =
2429         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2430 cmdline_parse_token_string_t cmd_config_burst_keyword =
2431         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2432 cmdline_parse_token_string_t cmd_config_burst_all =
2433         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2434 cmdline_parse_token_string_t cmd_config_burst_name =
2435         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2436 cmdline_parse_token_num_t cmd_config_burst_value =
2437         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2438
2439 cmdline_parse_inst_t cmd_config_burst = {
2440         .f = cmd_config_burst_parsed,
2441         .data = NULL,
2442         .help_str = "port config all burst <value>",
2443         .tokens = {
2444                 (void *)&cmd_config_burst_port,
2445                 (void *)&cmd_config_burst_keyword,
2446                 (void *)&cmd_config_burst_all,
2447                 (void *)&cmd_config_burst_name,
2448                 (void *)&cmd_config_burst_value,
2449                 NULL,
2450         },
2451 };
2452
2453 /* *** configure rx/tx queues *** */
2454 struct cmd_config_thresh {
2455         cmdline_fixed_string_t port;
2456         cmdline_fixed_string_t keyword;
2457         cmdline_fixed_string_t all;
2458         cmdline_fixed_string_t name;
2459         uint8_t value;
2460 };
2461
2462 static void
2463 cmd_config_thresh_parsed(void *parsed_result,
2464                         __attribute__((unused)) struct cmdline *cl,
2465                         __attribute__((unused)) void *data)
2466 {
2467         struct cmd_config_thresh *res = parsed_result;
2468
2469         if (!all_ports_stopped()) {
2470                 printf("Please stop all ports first\n");
2471                 return;
2472         }
2473
2474         if (!strcmp(res->name, "txpt"))
2475                 tx_pthresh = res->value;
2476         else if(!strcmp(res->name, "txht"))
2477                 tx_hthresh = res->value;
2478         else if(!strcmp(res->name, "txwt"))
2479                 tx_wthresh = res->value;
2480         else if(!strcmp(res->name, "rxpt"))
2481                 rx_pthresh = res->value;
2482         else if(!strcmp(res->name, "rxht"))
2483                 rx_hthresh = res->value;
2484         else if(!strcmp(res->name, "rxwt"))
2485                 rx_wthresh = res->value;
2486         else {
2487                 printf("Unknown parameter\n");
2488                 return;
2489         }
2490
2491         init_port_config();
2492
2493         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2494 }
2495
2496 cmdline_parse_token_string_t cmd_config_thresh_port =
2497         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2498 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2499         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2500 cmdline_parse_token_string_t cmd_config_thresh_all =
2501         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2502 cmdline_parse_token_string_t cmd_config_thresh_name =
2503         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2504                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2505 cmdline_parse_token_num_t cmd_config_thresh_value =
2506         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2507
2508 cmdline_parse_inst_t cmd_config_thresh = {
2509         .f = cmd_config_thresh_parsed,
2510         .data = NULL,
2511         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2512         .tokens = {
2513                 (void *)&cmd_config_thresh_port,
2514                 (void *)&cmd_config_thresh_keyword,
2515                 (void *)&cmd_config_thresh_all,
2516                 (void *)&cmd_config_thresh_name,
2517                 (void *)&cmd_config_thresh_value,
2518                 NULL,
2519         },
2520 };
2521
2522 /* *** configure free/rs threshold *** */
2523 struct cmd_config_threshold {
2524         cmdline_fixed_string_t port;
2525         cmdline_fixed_string_t keyword;
2526         cmdline_fixed_string_t all;
2527         cmdline_fixed_string_t name;
2528         uint16_t value;
2529 };
2530
2531 static void
2532 cmd_config_threshold_parsed(void *parsed_result,
2533                         __attribute__((unused)) struct cmdline *cl,
2534                         __attribute__((unused)) void *data)
2535 {
2536         struct cmd_config_threshold *res = parsed_result;
2537
2538         if (!all_ports_stopped()) {
2539                 printf("Please stop all ports first\n");
2540                 return;
2541         }
2542
2543         if (!strcmp(res->name, "txfreet"))
2544                 tx_free_thresh = res->value;
2545         else if (!strcmp(res->name, "txrst"))
2546                 tx_rs_thresh = res->value;
2547         else if (!strcmp(res->name, "rxfreet"))
2548                 rx_free_thresh = res->value;
2549         else {
2550                 printf("Unknown parameter\n");
2551                 return;
2552         }
2553
2554         init_port_config();
2555
2556         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2557 }
2558
2559 cmdline_parse_token_string_t cmd_config_threshold_port =
2560         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2561 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2562         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2563                                                                 "config");
2564 cmdline_parse_token_string_t cmd_config_threshold_all =
2565         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2566 cmdline_parse_token_string_t cmd_config_threshold_name =
2567         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2568                                                 "txfreet#txrst#rxfreet");
2569 cmdline_parse_token_num_t cmd_config_threshold_value =
2570         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2571
2572 cmdline_parse_inst_t cmd_config_threshold = {
2573         .f = cmd_config_threshold_parsed,
2574         .data = NULL,
2575         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2576         .tokens = {
2577                 (void *)&cmd_config_threshold_port,
2578                 (void *)&cmd_config_threshold_keyword,
2579                 (void *)&cmd_config_threshold_all,
2580                 (void *)&cmd_config_threshold_name,
2581                 (void *)&cmd_config_threshold_value,
2582                 NULL,
2583         },
2584 };
2585
2586 /* *** stop *** */
2587 struct cmd_stop_result {
2588         cmdline_fixed_string_t stop;
2589 };
2590
2591 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2592                             __attribute__((unused)) struct cmdline *cl,
2593                             __attribute__((unused)) void *data)
2594 {
2595         stop_packet_forwarding();
2596 }
2597
2598 cmdline_parse_token_string_t cmd_stop_stop =
2599         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2600
2601 cmdline_parse_inst_t cmd_stop = {
2602         .f = cmd_stop_parsed,
2603         .data = NULL,
2604         .help_str = "stop: Stop packet forwarding",
2605         .tokens = {
2606                 (void *)&cmd_stop_stop,
2607                 NULL,
2608         },
2609 };
2610
2611 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2612
2613 unsigned int
2614 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2615                 unsigned int *parsed_items, int check_unique_values)
2616 {
2617         unsigned int nb_item;
2618         unsigned int value;
2619         unsigned int i;
2620         unsigned int j;
2621         int value_ok;
2622         char c;
2623
2624         /*
2625          * First parse all items in the list and store their value.
2626          */
2627         value = 0;
2628         nb_item = 0;
2629         value_ok = 0;
2630         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2631                 c = str[i];
2632                 if ((c >= '0') && (c <= '9')) {
2633                         value = (unsigned int) (value * 10 + (c - '0'));
2634                         value_ok = 1;
2635                         continue;
2636                 }
2637                 if (c != ',') {
2638                         printf("character %c is not a decimal digit\n", c);
2639                         return 0;
2640                 }
2641                 if (! value_ok) {
2642                         printf("No valid value before comma\n");
2643                         return 0;
2644                 }
2645                 if (nb_item < max_items) {
2646                         parsed_items[nb_item] = value;
2647                         value_ok = 0;
2648                         value = 0;
2649                 }
2650                 nb_item++;
2651         }
2652         if (nb_item >= max_items) {
2653                 printf("Number of %s = %u > %u (maximum items)\n",
2654                        item_name, nb_item + 1, max_items);
2655                 return 0;
2656         }
2657         parsed_items[nb_item++] = value;
2658         if (! check_unique_values)
2659                 return nb_item;
2660
2661         /*
2662          * Then, check that all values in the list are differents.
2663          * No optimization here...
2664          */
2665         for (i = 0; i < nb_item; i++) {
2666                 for (j = i + 1; j < nb_item; j++) {
2667                         if (parsed_items[j] == parsed_items[i]) {
2668                                 printf("duplicated %s %u at index %u and %u\n",
2669                                        item_name, parsed_items[i], i, j);
2670                                 return 0;
2671                         }
2672                 }
2673         }
2674         return nb_item;
2675 }
2676
2677 struct cmd_set_list_result {
2678         cmdline_fixed_string_t cmd_keyword;
2679         cmdline_fixed_string_t list_name;
2680         cmdline_fixed_string_t list_of_items;
2681 };
2682
2683 static void cmd_set_list_parsed(void *parsed_result,
2684                                 __attribute__((unused)) struct cmdline *cl,
2685                                 __attribute__((unused)) void *data)
2686 {
2687         struct cmd_set_list_result *res;
2688         union {
2689                 unsigned int lcorelist[RTE_MAX_LCORE];
2690                 unsigned int portlist[RTE_MAX_ETHPORTS];
2691         } parsed_items;
2692         unsigned int nb_item;
2693
2694         if (test_done == 0) {
2695                 printf("Please stop forwarding first\n");
2696                 return;
2697         }
2698
2699         res = parsed_result;
2700         if (!strcmp(res->list_name, "corelist")) {
2701                 nb_item = parse_item_list(res->list_of_items, "core",
2702                                           RTE_MAX_LCORE,
2703                                           parsed_items.lcorelist, 1);
2704                 if (nb_item > 0) {
2705                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2706                         fwd_config_setup();
2707                 }
2708                 return;
2709         }
2710         if (!strcmp(res->list_name, "portlist")) {
2711                 nb_item = parse_item_list(res->list_of_items, "port",
2712                                           RTE_MAX_ETHPORTS,
2713                                           parsed_items.portlist, 1);
2714                 if (nb_item > 0) {
2715                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2716                         fwd_config_setup();
2717                 }
2718         }
2719 }
2720
2721 cmdline_parse_token_string_t cmd_set_list_keyword =
2722         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2723                                  "set");
2724 cmdline_parse_token_string_t cmd_set_list_name =
2725         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2726                                  "corelist#portlist");
2727 cmdline_parse_token_string_t cmd_set_list_of_items =
2728         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2729                                  NULL);
2730
2731 cmdline_parse_inst_t cmd_set_fwd_list = {
2732         .f = cmd_set_list_parsed,
2733         .data = NULL,
2734         .help_str = "set corelist|portlist <list0[,list1]*>",
2735         .tokens = {
2736                 (void *)&cmd_set_list_keyword,
2737                 (void *)&cmd_set_list_name,
2738                 (void *)&cmd_set_list_of_items,
2739                 NULL,
2740         },
2741 };
2742
2743 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2744
2745 struct cmd_setmask_result {
2746         cmdline_fixed_string_t set;
2747         cmdline_fixed_string_t mask;
2748         uint64_t hexavalue;
2749 };
2750
2751 static void cmd_set_mask_parsed(void *parsed_result,
2752                                 __attribute__((unused)) struct cmdline *cl,
2753                                 __attribute__((unused)) void *data)
2754 {
2755         struct cmd_setmask_result *res = parsed_result;
2756
2757         if (test_done == 0) {
2758                 printf("Please stop forwarding first\n");
2759                 return;
2760         }
2761         if (!strcmp(res->mask, "coremask")) {
2762                 set_fwd_lcores_mask(res->hexavalue);
2763                 fwd_config_setup();
2764         } else if (!strcmp(res->mask, "portmask")) {
2765                 set_fwd_ports_mask(res->hexavalue);
2766                 fwd_config_setup();
2767         }
2768 }
2769
2770 cmdline_parse_token_string_t cmd_setmask_set =
2771         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2772 cmdline_parse_token_string_t cmd_setmask_mask =
2773         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2774                                  "coremask#portmask");
2775 cmdline_parse_token_num_t cmd_setmask_value =
2776         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2777
2778 cmdline_parse_inst_t cmd_set_fwd_mask = {
2779         .f = cmd_set_mask_parsed,
2780         .data = NULL,
2781         .help_str = "set coremask|portmask <hexadecimal value>",
2782         .tokens = {
2783                 (void *)&cmd_setmask_set,
2784                 (void *)&cmd_setmask_mask,
2785                 (void *)&cmd_setmask_value,
2786                 NULL,
2787         },
2788 };
2789
2790 /*
2791  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2792  */
2793 struct cmd_set_result {
2794         cmdline_fixed_string_t set;
2795         cmdline_fixed_string_t what;
2796         uint16_t value;
2797 };
2798
2799 static void cmd_set_parsed(void *parsed_result,
2800                            __attribute__((unused)) struct cmdline *cl,
2801                            __attribute__((unused)) void *data)
2802 {
2803         struct cmd_set_result *res = parsed_result;
2804         if (!strcmp(res->what, "nbport")) {
2805                 set_fwd_ports_number(res->value);
2806                 fwd_config_setup();
2807         } else if (!strcmp(res->what, "nbcore")) {
2808                 set_fwd_lcores_number(res->value);
2809                 fwd_config_setup();
2810         } else if (!strcmp(res->what, "burst"))
2811                 set_nb_pkt_per_burst(res->value);
2812         else if (!strcmp(res->what, "verbose"))
2813                 set_verbose_level(res->value);
2814 }
2815
2816 cmdline_parse_token_string_t cmd_set_set =
2817         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2818 cmdline_parse_token_string_t cmd_set_what =
2819         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2820                                  "nbport#nbcore#burst#verbose");
2821 cmdline_parse_token_num_t cmd_set_value =
2822         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2823
2824 cmdline_parse_inst_t cmd_set_numbers = {
2825         .f = cmd_set_parsed,
2826         .data = NULL,
2827         .help_str = "set nbport|nbcore|burst|verbose <value>",
2828         .tokens = {
2829                 (void *)&cmd_set_set,
2830                 (void *)&cmd_set_what,
2831                 (void *)&cmd_set_value,
2832                 NULL,
2833         },
2834 };
2835
2836 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2837
2838 struct cmd_set_txpkts_result {
2839         cmdline_fixed_string_t cmd_keyword;
2840         cmdline_fixed_string_t txpkts;
2841         cmdline_fixed_string_t seg_lengths;
2842 };
2843
2844 static void
2845 cmd_set_txpkts_parsed(void *parsed_result,
2846                       __attribute__((unused)) struct cmdline *cl,
2847                       __attribute__((unused)) void *data)
2848 {
2849         struct cmd_set_txpkts_result *res;
2850         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2851         unsigned int nb_segs;
2852
2853         res = parsed_result;
2854         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2855                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2856         if (nb_segs > 0)
2857                 set_tx_pkt_segments(seg_lengths, nb_segs);
2858 }
2859
2860 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2861         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2862                                  cmd_keyword, "set");
2863 cmdline_parse_token_string_t cmd_set_txpkts_name =
2864         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2865                                  txpkts, "txpkts");
2866 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2867         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2868                                  seg_lengths, NULL);
2869
2870 cmdline_parse_inst_t cmd_set_txpkts = {
2871         .f = cmd_set_txpkts_parsed,
2872         .data = NULL,
2873         .help_str = "set txpkts <len0[,len1]*>",
2874         .tokens = {
2875                 (void *)&cmd_set_txpkts_keyword,
2876                 (void *)&cmd_set_txpkts_name,
2877                 (void *)&cmd_set_txpkts_lengths,
2878                 NULL,
2879         },
2880 };
2881
2882 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2883
2884 struct cmd_set_txsplit_result {
2885         cmdline_fixed_string_t cmd_keyword;
2886         cmdline_fixed_string_t txsplit;
2887         cmdline_fixed_string_t mode;
2888 };
2889
2890 static void
2891 cmd_set_txsplit_parsed(void *parsed_result,
2892                       __attribute__((unused)) struct cmdline *cl,
2893                       __attribute__((unused)) void *data)
2894 {
2895         struct cmd_set_txsplit_result *res;
2896
2897         res = parsed_result;
2898         set_tx_pkt_split(res->mode);
2899 }
2900
2901 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2902         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2903                                  cmd_keyword, "set");
2904 cmdline_parse_token_string_t cmd_set_txsplit_name =
2905         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2906                                  txsplit, "txsplit");
2907 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2908         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2909                                  mode, NULL);
2910
2911 cmdline_parse_inst_t cmd_set_txsplit = {
2912         .f = cmd_set_txsplit_parsed,
2913         .data = NULL,
2914         .help_str = "set txsplit on|off|rand",
2915         .tokens = {
2916                 (void *)&cmd_set_txsplit_keyword,
2917                 (void *)&cmd_set_txsplit_name,
2918                 (void *)&cmd_set_txsplit_mode,
2919                 NULL,
2920         },
2921 };
2922
2923 /* *** CONFIG TX QUEUE FLAGS *** */
2924
2925 struct cmd_config_txqflags_result {
2926         cmdline_fixed_string_t port;
2927         cmdline_fixed_string_t config;
2928         cmdline_fixed_string_t all;
2929         cmdline_fixed_string_t what;
2930         int32_t hexvalue;
2931 };
2932
2933 static void cmd_config_txqflags_parsed(void *parsed_result,
2934                                 __attribute__((unused)) struct cmdline *cl,
2935                                 __attribute__((unused)) void *data)
2936 {
2937         struct cmd_config_txqflags_result *res = parsed_result;
2938
2939         if (!all_ports_stopped()) {
2940                 printf("Please stop all ports first\n");
2941                 return;
2942         }
2943
2944         if (strcmp(res->what, "txqflags")) {
2945                 printf("Unknown parameter\n");
2946                 return;
2947         }
2948
2949         if (res->hexvalue >= 0) {
2950                 txq_flags = res->hexvalue;
2951         } else {
2952                 printf("txqflags must be >= 0\n");
2953                 return;
2954         }
2955
2956         init_port_config();
2957
2958         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2959 }
2960
2961 cmdline_parse_token_string_t cmd_config_txqflags_port =
2962         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
2963                                  "port");
2964 cmdline_parse_token_string_t cmd_config_txqflags_config =
2965         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
2966                                  "config");
2967 cmdline_parse_token_string_t cmd_config_txqflags_all =
2968         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
2969                                  "all");
2970 cmdline_parse_token_string_t cmd_config_txqflags_what =
2971         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
2972                                  "txqflags");
2973 cmdline_parse_token_num_t cmd_config_txqflags_value =
2974         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
2975                                 hexvalue, INT32);
2976
2977 cmdline_parse_inst_t cmd_config_txqflags = {
2978         .f = cmd_config_txqflags_parsed,
2979         .data = NULL,
2980         .help_str = "port config all txqflags <value>",
2981         .tokens = {
2982                 (void *)&cmd_config_txqflags_port,
2983                 (void *)&cmd_config_txqflags_config,
2984                 (void *)&cmd_config_txqflags_all,
2985                 (void *)&cmd_config_txqflags_what,
2986                 (void *)&cmd_config_txqflags_value,
2987                 NULL,
2988         },
2989 };
2990
2991 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
2992 struct cmd_rx_vlan_filter_all_result {
2993         cmdline_fixed_string_t rx_vlan;
2994         cmdline_fixed_string_t what;
2995         cmdline_fixed_string_t all;
2996         uint8_t port_id;
2997 };
2998
2999 static void
3000 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3001                               __attribute__((unused)) struct cmdline *cl,
3002                               __attribute__((unused)) void *data)
3003 {
3004         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3005
3006         if (!strcmp(res->what, "add"))
3007                 rx_vlan_all_filter_set(res->port_id, 1);
3008         else
3009                 rx_vlan_all_filter_set(res->port_id, 0);
3010 }
3011
3012 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3013         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3014                                  rx_vlan, "rx_vlan");
3015 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3016         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3017                                  what, "add#rm");
3018 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3019         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3020                                  all, "all");
3021 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3022         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3023                               port_id, UINT8);
3024
3025 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3026         .f = cmd_rx_vlan_filter_all_parsed,
3027         .data = NULL,
3028         .help_str = "rx_vlan add|rm all <port_id>: "
3029                 "Add/Remove all identifiers to/from the set of VLAN "
3030                 "identifiers filtered by a port",
3031         .tokens = {
3032                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3033                 (void *)&cmd_rx_vlan_filter_all_what,
3034                 (void *)&cmd_rx_vlan_filter_all_all,
3035                 (void *)&cmd_rx_vlan_filter_all_portid,
3036                 NULL,
3037         },
3038 };
3039
3040 /* *** VLAN OFFLOAD SET ON A PORT *** */
3041 struct cmd_vlan_offload_result {
3042         cmdline_fixed_string_t vlan;
3043         cmdline_fixed_string_t set;
3044         cmdline_fixed_string_t vlan_type;
3045         cmdline_fixed_string_t what;
3046         cmdline_fixed_string_t on;
3047         cmdline_fixed_string_t port_id;
3048 };
3049
3050 static void
3051 cmd_vlan_offload_parsed(void *parsed_result,
3052                           __attribute__((unused)) struct cmdline *cl,
3053                           __attribute__((unused)) void *data)
3054 {
3055         int on;
3056         struct cmd_vlan_offload_result *res = parsed_result;
3057         char *str;
3058         int i, len = 0;
3059         portid_t port_id = 0;
3060         unsigned int tmp;
3061
3062         str = res->port_id;
3063         len = strnlen(str, STR_TOKEN_SIZE);
3064         i = 0;
3065         /* Get port_id first */
3066         while(i < len){
3067                 if(str[i] == ',')
3068                         break;
3069
3070                 i++;
3071         }
3072         str[i]='\0';
3073         tmp = strtoul(str, NULL, 0);
3074         /* If port_id greater that what portid_t can represent, return */
3075         if(tmp >= RTE_MAX_ETHPORTS)
3076                 return;
3077         port_id = (portid_t)tmp;
3078
3079         if (!strcmp(res->on, "on"))
3080                 on = 1;
3081         else
3082                 on = 0;
3083
3084         if (!strcmp(res->what, "strip"))
3085                 rx_vlan_strip_set(port_id,  on);
3086         else if(!strcmp(res->what, "stripq")){
3087                 uint16_t queue_id = 0;
3088
3089                 /* No queue_id, return */
3090                 if(i + 1 >= len) {
3091                         printf("must specify (port,queue_id)\n");
3092                         return;
3093                 }
3094                 tmp = strtoul(str + i + 1, NULL, 0);
3095                 /* If queue_id greater that what 16-bits can represent, return */
3096                 if(tmp > 0xffff)
3097                         return;
3098
3099                 queue_id = (uint16_t)tmp;
3100                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3101         }
3102         else if (!strcmp(res->what, "filter"))
3103                 rx_vlan_filter_set(port_id, on);
3104         else
3105                 vlan_extend_set(port_id, on);
3106
3107         return;
3108 }
3109
3110 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3111         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3112                                  vlan, "vlan");
3113 cmdline_parse_token_string_t cmd_vlan_offload_set =
3114         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3115                                  set, "set");
3116 cmdline_parse_token_string_t cmd_vlan_offload_what =
3117         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3118                                  what, "strip#filter#qinq#stripq");
3119 cmdline_parse_token_string_t cmd_vlan_offload_on =
3120         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3121                               on, "on#off");
3122 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3123         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3124                               port_id, NULL);
3125
3126 cmdline_parse_inst_t cmd_vlan_offload = {
3127         .f = cmd_vlan_offload_parsed,
3128         .data = NULL,
3129         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3130                 "<port_id[,queue_id]>: "
3131                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3132         .tokens = {
3133                 (void *)&cmd_vlan_offload_vlan,
3134                 (void *)&cmd_vlan_offload_set,
3135                 (void *)&cmd_vlan_offload_what,
3136                 (void *)&cmd_vlan_offload_on,
3137                 (void *)&cmd_vlan_offload_portid,
3138                 NULL,
3139         },
3140 };
3141
3142 /* *** VLAN TPID SET ON A PORT *** */
3143 struct cmd_vlan_tpid_result {
3144         cmdline_fixed_string_t vlan;
3145         cmdline_fixed_string_t set;
3146         cmdline_fixed_string_t vlan_type;
3147         cmdline_fixed_string_t what;
3148         uint16_t tp_id;
3149         uint8_t port_id;
3150 };
3151
3152 static void
3153 cmd_vlan_tpid_parsed(void *parsed_result,
3154                           __attribute__((unused)) struct cmdline *cl,
3155                           __attribute__((unused)) void *data)
3156 {
3157         struct cmd_vlan_tpid_result *res = parsed_result;
3158         enum rte_vlan_type vlan_type;
3159
3160         if (!strcmp(res->vlan_type, "inner"))
3161                 vlan_type = ETH_VLAN_TYPE_INNER;
3162         else if (!strcmp(res->vlan_type, "outer"))
3163                 vlan_type = ETH_VLAN_TYPE_OUTER;
3164         else {
3165                 printf("Unknown vlan type\n");
3166                 return;
3167         }
3168         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3169 }
3170
3171 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3172         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3173                                  vlan, "vlan");
3174 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3175         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3176                                  set, "set");
3177 cmdline_parse_token_string_t cmd_vlan_type =
3178         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3179                                  vlan_type, "inner#outer");
3180 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3181         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3182                                  what, "tpid");
3183 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3184         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3185                               tp_id, UINT16);
3186 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3187         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3188                               port_id, UINT8);
3189
3190 cmdline_parse_inst_t cmd_vlan_tpid = {
3191         .f = cmd_vlan_tpid_parsed,
3192         .data = NULL,
3193         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3194                 "Set the VLAN Ether type",
3195         .tokens = {
3196                 (void *)&cmd_vlan_tpid_vlan,
3197                 (void *)&cmd_vlan_tpid_set,
3198                 (void *)&cmd_vlan_type,
3199                 (void *)&cmd_vlan_tpid_what,
3200                 (void *)&cmd_vlan_tpid_tpid,
3201                 (void *)&cmd_vlan_tpid_portid,
3202                 NULL,
3203         },
3204 };
3205
3206 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3207 struct cmd_rx_vlan_filter_result {
3208         cmdline_fixed_string_t rx_vlan;
3209         cmdline_fixed_string_t what;
3210         uint16_t vlan_id;
3211         uint8_t port_id;
3212 };
3213
3214 static void
3215 cmd_rx_vlan_filter_parsed(void *parsed_result,
3216                           __attribute__((unused)) struct cmdline *cl,
3217                           __attribute__((unused)) void *data)
3218 {
3219         struct cmd_rx_vlan_filter_result *res = parsed_result;
3220
3221         if (!strcmp(res->what, "add"))
3222                 rx_vft_set(res->port_id, res->vlan_id, 1);
3223         else
3224                 rx_vft_set(res->port_id, res->vlan_id, 0);
3225 }
3226
3227 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3228         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3229                                  rx_vlan, "rx_vlan");
3230 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3231         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3232                                  what, "add#rm");
3233 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3234         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3235                               vlan_id, UINT16);
3236 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3237         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3238                               port_id, UINT8);
3239
3240 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3241         .f = cmd_rx_vlan_filter_parsed,
3242         .data = NULL,
3243         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3244                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3245                 "identifiers filtered by a port",
3246         .tokens = {
3247                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3248                 (void *)&cmd_rx_vlan_filter_what,
3249                 (void *)&cmd_rx_vlan_filter_vlanid,
3250                 (void *)&cmd_rx_vlan_filter_portid,
3251                 NULL,
3252         },
3253 };
3254
3255 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3256 struct cmd_tx_vlan_set_result {
3257         cmdline_fixed_string_t tx_vlan;
3258         cmdline_fixed_string_t set;
3259         uint8_t port_id;
3260         uint16_t vlan_id;
3261 };
3262
3263 static void
3264 cmd_tx_vlan_set_parsed(void *parsed_result,
3265                        __attribute__((unused)) struct cmdline *cl,
3266                        __attribute__((unused)) void *data)
3267 {
3268         struct cmd_tx_vlan_set_result *res = parsed_result;
3269
3270         tx_vlan_set(res->port_id, res->vlan_id);
3271 }
3272
3273 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3274         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3275                                  tx_vlan, "tx_vlan");
3276 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3277         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3278                                  set, "set");
3279 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3280         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3281                               port_id, UINT8);
3282 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3283         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3284                               vlan_id, UINT16);
3285
3286 cmdline_parse_inst_t cmd_tx_vlan_set = {
3287         .f = cmd_tx_vlan_set_parsed,
3288         .data = NULL,
3289         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3290                 "Enable hardware insertion of a single VLAN header "
3291                 "with a given TAG Identifier in packets sent on a port",
3292         .tokens = {
3293                 (void *)&cmd_tx_vlan_set_tx_vlan,
3294                 (void *)&cmd_tx_vlan_set_set,
3295                 (void *)&cmd_tx_vlan_set_portid,
3296                 (void *)&cmd_tx_vlan_set_vlanid,
3297                 NULL,
3298         },
3299 };
3300
3301 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3302 struct cmd_tx_vlan_set_qinq_result {
3303         cmdline_fixed_string_t tx_vlan;
3304         cmdline_fixed_string_t set;
3305         uint8_t port_id;
3306         uint16_t vlan_id;
3307         uint16_t vlan_id_outer;
3308 };
3309
3310 static void
3311 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3312                             __attribute__((unused)) struct cmdline *cl,
3313                             __attribute__((unused)) void *data)
3314 {
3315         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3316
3317         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3318 }
3319
3320 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3321         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3322                 tx_vlan, "tx_vlan");
3323 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3324         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3325                 set, "set");
3326 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3327         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3328                 port_id, UINT8);
3329 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3330         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3331                 vlan_id, UINT16);
3332 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3333         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3334                 vlan_id_outer, UINT16);
3335
3336 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3337         .f = cmd_tx_vlan_set_qinq_parsed,
3338         .data = NULL,
3339         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3340                 "Enable hardware insertion of double VLAN header "
3341                 "with given TAG Identifiers in packets sent on a port",
3342         .tokens = {
3343                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3344                 (void *)&cmd_tx_vlan_set_qinq_set,
3345                 (void *)&cmd_tx_vlan_set_qinq_portid,
3346                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3347                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3348                 NULL,
3349         },
3350 };
3351
3352 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3353 struct cmd_tx_vlan_set_pvid_result {
3354         cmdline_fixed_string_t tx_vlan;
3355         cmdline_fixed_string_t set;
3356         cmdline_fixed_string_t pvid;
3357         uint8_t port_id;
3358         uint16_t vlan_id;
3359         cmdline_fixed_string_t mode;
3360 };
3361
3362 static void
3363 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3364                             __attribute__((unused)) struct cmdline *cl,
3365                             __attribute__((unused)) void *data)
3366 {
3367         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3368
3369         if (strcmp(res->mode, "on") == 0)
3370                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3371         else
3372                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3373 }
3374
3375 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3376         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3377                                  tx_vlan, "tx_vlan");
3378 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3379         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3380                                  set, "set");
3381 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3382         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3383                                  pvid, "pvid");
3384 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3385         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3386                              port_id, UINT8);
3387 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3388         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3389                               vlan_id, UINT16);
3390 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3391         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3392                                  mode, "on#off");
3393
3394 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3395         .f = cmd_tx_vlan_set_pvid_parsed,
3396         .data = NULL,
3397         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3398         .tokens = {
3399                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3400                 (void *)&cmd_tx_vlan_set_pvid_set,
3401                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3402                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3403                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3404                 (void *)&cmd_tx_vlan_set_pvid_mode,
3405                 NULL,
3406         },
3407 };
3408
3409 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3410 struct cmd_tx_vlan_reset_result {
3411         cmdline_fixed_string_t tx_vlan;
3412         cmdline_fixed_string_t reset;
3413         uint8_t port_id;
3414 };
3415
3416 static void
3417 cmd_tx_vlan_reset_parsed(void *parsed_result,
3418                          __attribute__((unused)) struct cmdline *cl,
3419                          __attribute__((unused)) void *data)
3420 {
3421         struct cmd_tx_vlan_reset_result *res = parsed_result;
3422
3423         tx_vlan_reset(res->port_id);
3424 }
3425
3426 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3427         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3428                                  tx_vlan, "tx_vlan");
3429 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3430         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3431                                  reset, "reset");
3432 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3433         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3434                               port_id, UINT8);
3435
3436 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3437         .f = cmd_tx_vlan_reset_parsed,
3438         .data = NULL,
3439         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3440                 "VLAN header in packets sent on a port",
3441         .tokens = {
3442                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3443                 (void *)&cmd_tx_vlan_reset_reset,
3444                 (void *)&cmd_tx_vlan_reset_portid,
3445                 NULL,
3446         },
3447 };
3448
3449
3450 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3451 struct cmd_csum_result {
3452         cmdline_fixed_string_t csum;
3453         cmdline_fixed_string_t mode;
3454         cmdline_fixed_string_t proto;
3455         cmdline_fixed_string_t hwsw;
3456         uint8_t port_id;
3457 };
3458
3459 static void
3460 csum_show(int port_id)
3461 {
3462         struct rte_eth_dev_info dev_info;
3463         uint16_t ol_flags;
3464
3465         ol_flags = ports[port_id].tx_ol_flags;
3466         printf("Parse tunnel is %s\n",
3467                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3468         printf("IP checksum offload is %s\n",
3469                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3470         printf("UDP checksum offload is %s\n",
3471                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3472         printf("TCP checksum offload is %s\n",
3473                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3474         printf("SCTP checksum offload is %s\n",
3475                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3476         printf("Outer-Ip checksum offload is %s\n",
3477                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3478
3479         /* display warnings if configuration is not supported by the NIC */
3480         rte_eth_dev_info_get(port_id, &dev_info);
3481         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3482                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3483                 printf("Warning: hardware IP checksum enabled but not "
3484                         "supported by port %d\n", port_id);
3485         }
3486         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3487                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3488                 printf("Warning: hardware UDP checksum enabled but not "
3489                         "supported by port %d\n", port_id);
3490         }
3491         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3492                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3493                 printf("Warning: hardware TCP checksum enabled but not "
3494                         "supported by port %d\n", port_id);
3495         }
3496         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3497                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3498                 printf("Warning: hardware SCTP checksum enabled but not "
3499                         "supported by port %d\n", port_id);
3500         }
3501         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3502                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3503                 printf("Warning: hardware outer IP checksum enabled but not "
3504                         "supported by port %d\n", port_id);
3505         }
3506 }
3507
3508 static void
3509 cmd_csum_parsed(void *parsed_result,
3510                        __attribute__((unused)) struct cmdline *cl,
3511                        __attribute__((unused)) void *data)
3512 {
3513         struct cmd_csum_result *res = parsed_result;
3514         int hw = 0;
3515         uint16_t mask = 0;
3516
3517         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3518                 printf("invalid port %d\n", res->port_id);
3519                 return;
3520         }
3521
3522         if (!strcmp(res->mode, "set")) {
3523
3524                 if (!strcmp(res->hwsw, "hw"))
3525                         hw = 1;
3526
3527                 if (!strcmp(res->proto, "ip")) {
3528                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3529                 } else if (!strcmp(res->proto, "udp")) {
3530                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3531                 } else if (!strcmp(res->proto, "tcp")) {
3532                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3533                 } else if (!strcmp(res->proto, "sctp")) {
3534                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3535                 } else if (!strcmp(res->proto, "outer-ip")) {
3536                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3537                 }
3538
3539                 if (hw)
3540                         ports[res->port_id].tx_ol_flags |= mask;
3541                 else
3542                         ports[res->port_id].tx_ol_flags &= (~mask);
3543         }
3544         csum_show(res->port_id);
3545 }
3546
3547 cmdline_parse_token_string_t cmd_csum_csum =
3548         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3549                                 csum, "csum");
3550 cmdline_parse_token_string_t cmd_csum_mode =
3551         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3552                                 mode, "set");
3553 cmdline_parse_token_string_t cmd_csum_proto =
3554         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3555                                 proto, "ip#tcp#udp#sctp#outer-ip");
3556 cmdline_parse_token_string_t cmd_csum_hwsw =
3557         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3558                                 hwsw, "hw#sw");
3559 cmdline_parse_token_num_t cmd_csum_portid =
3560         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3561                                 port_id, UINT8);
3562
3563 cmdline_parse_inst_t cmd_csum_set = {
3564         .f = cmd_csum_parsed,
3565         .data = NULL,
3566         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3567                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3568                 "using csum forward engine",
3569         .tokens = {
3570                 (void *)&cmd_csum_csum,
3571                 (void *)&cmd_csum_mode,
3572                 (void *)&cmd_csum_proto,
3573                 (void *)&cmd_csum_hwsw,
3574                 (void *)&cmd_csum_portid,
3575                 NULL,
3576         },
3577 };
3578
3579 cmdline_parse_token_string_t cmd_csum_mode_show =
3580         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3581                                 mode, "show");
3582
3583 cmdline_parse_inst_t cmd_csum_show = {
3584         .f = cmd_csum_parsed,
3585         .data = NULL,
3586         .help_str = "csum show <port_id>: Show checksum offload configuration",
3587         .tokens = {
3588                 (void *)&cmd_csum_csum,
3589                 (void *)&cmd_csum_mode_show,
3590                 (void *)&cmd_csum_portid,
3591                 NULL,
3592         },
3593 };
3594
3595 /* Enable/disable tunnel parsing */
3596 struct cmd_csum_tunnel_result {
3597         cmdline_fixed_string_t csum;
3598         cmdline_fixed_string_t parse;
3599         cmdline_fixed_string_t onoff;
3600         uint8_t port_id;
3601 };
3602
3603 static void
3604 cmd_csum_tunnel_parsed(void *parsed_result,
3605                        __attribute__((unused)) struct cmdline *cl,
3606                        __attribute__((unused)) void *data)
3607 {
3608         struct cmd_csum_tunnel_result *res = parsed_result;
3609
3610         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3611                 return;
3612
3613         if (!strcmp(res->onoff, "on"))
3614                 ports[res->port_id].tx_ol_flags |=
3615                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3616         else
3617                 ports[res->port_id].tx_ol_flags &=
3618                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3619
3620         csum_show(res->port_id);
3621 }
3622
3623 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3624         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3625                                 csum, "csum");
3626 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3627         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3628                                 parse, "parse_tunnel");
3629 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3630         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3631                                 onoff, "on#off");
3632 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3633         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3634                                 port_id, UINT8);
3635
3636 cmdline_parse_inst_t cmd_csum_tunnel = {
3637         .f = cmd_csum_tunnel_parsed,
3638         .data = NULL,
3639         .help_str = "csum parse_tunnel on|off <port_id>: "
3640                 "Enable/Disable parsing of tunnels for csum engine",
3641         .tokens = {
3642                 (void *)&cmd_csum_tunnel_csum,
3643                 (void *)&cmd_csum_tunnel_parse,
3644                 (void *)&cmd_csum_tunnel_onoff,
3645                 (void *)&cmd_csum_tunnel_portid,
3646                 NULL,
3647         },
3648 };
3649
3650 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3651 struct cmd_tso_set_result {
3652         cmdline_fixed_string_t tso;
3653         cmdline_fixed_string_t mode;
3654         uint16_t tso_segsz;
3655         uint8_t port_id;
3656 };
3657
3658 static void
3659 cmd_tso_set_parsed(void *parsed_result,
3660                        __attribute__((unused)) struct cmdline *cl,
3661                        __attribute__((unused)) void *data)
3662 {
3663         struct cmd_tso_set_result *res = parsed_result;
3664         struct rte_eth_dev_info dev_info;
3665
3666         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3667                 return;
3668
3669         if (!strcmp(res->mode, "set"))
3670                 ports[res->port_id].tso_segsz = res->tso_segsz;
3671
3672         if (ports[res->port_id].tso_segsz == 0)
3673                 printf("TSO for non-tunneled packets is disabled\n");
3674         else
3675                 printf("TSO segment size for non-tunneled packets is %d\n",
3676                         ports[res->port_id].tso_segsz);
3677
3678         /* display warnings if configuration is not supported by the NIC */
3679         rte_eth_dev_info_get(res->port_id, &dev_info);
3680         if ((ports[res->port_id].tso_segsz != 0) &&
3681                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3682                 printf("Warning: TSO enabled but not "
3683                         "supported by port %d\n", res->port_id);
3684         }
3685 }
3686
3687 cmdline_parse_token_string_t cmd_tso_set_tso =
3688         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3689                                 tso, "tso");
3690 cmdline_parse_token_string_t cmd_tso_set_mode =
3691         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3692                                 mode, "set");
3693 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3694         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3695                                 tso_segsz, UINT16);
3696 cmdline_parse_token_num_t cmd_tso_set_portid =
3697         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3698                                 port_id, UINT8);
3699
3700 cmdline_parse_inst_t cmd_tso_set = {
3701         .f = cmd_tso_set_parsed,
3702         .data = NULL,
3703         .help_str = "tso set <tso_segsz> <port_id>: "
3704                 "Set TSO segment size of non-tunneled packets for csum engine "
3705                 "(0 to disable)",
3706         .tokens = {
3707                 (void *)&cmd_tso_set_tso,
3708                 (void *)&cmd_tso_set_mode,
3709                 (void *)&cmd_tso_set_tso_segsz,
3710                 (void *)&cmd_tso_set_portid,
3711                 NULL,
3712         },
3713 };
3714
3715 cmdline_parse_token_string_t cmd_tso_show_mode =
3716         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3717                                 mode, "show");
3718
3719
3720 cmdline_parse_inst_t cmd_tso_show = {
3721         .f = cmd_tso_set_parsed,
3722         .data = NULL,
3723         .help_str = "tso show <port_id>: "
3724                 "Show TSO segment size of non-tunneled packets for csum engine",
3725         .tokens = {
3726                 (void *)&cmd_tso_set_tso,
3727                 (void *)&cmd_tso_show_mode,
3728                 (void *)&cmd_tso_set_portid,
3729                 NULL,
3730         },
3731 };
3732
3733 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3734 struct cmd_tunnel_tso_set_result {
3735         cmdline_fixed_string_t tso;
3736         cmdline_fixed_string_t mode;
3737         uint16_t tso_segsz;
3738         uint8_t port_id;
3739 };
3740
3741 static void
3742 check_tunnel_tso_nic_support(uint8_t port_id)
3743 {
3744         struct rte_eth_dev_info dev_info;
3745
3746         rte_eth_dev_info_get(port_id, &dev_info);
3747         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3748                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3749                        "supported by port %d\n", port_id);
3750         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3751                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3752                         "supported by port %d\n", port_id);
3753         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3754                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3755                        "supported by port %d\n", port_id);
3756         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3757                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3758                        "supported by port %d\n", port_id);
3759 }
3760
3761 static void
3762 cmd_tunnel_tso_set_parsed(void *parsed_result,
3763                           __attribute__((unused)) struct cmdline *cl,
3764                           __attribute__((unused)) void *data)
3765 {
3766         struct cmd_tunnel_tso_set_result *res = parsed_result;
3767
3768         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3769                 return;
3770
3771         if (!strcmp(res->mode, "set"))
3772                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3773
3774         if (ports[res->port_id].tunnel_tso_segsz == 0)
3775                 printf("TSO for tunneled packets is disabled\n");
3776         else {
3777                 printf("TSO segment size for tunneled packets is %d\n",
3778                         ports[res->port_id].tunnel_tso_segsz);
3779
3780                 /* Below conditions are needed to make it work:
3781                  * (1) tunnel TSO is supported by the NIC;
3782                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3783                  * are recognized;
3784                  * (3) for tunneled pkts with outer L3 of IPv4,
3785                  * "csum set outer-ip" must be set to hw, because after tso,
3786                  * total_len of outer IP header is changed, and the checksum
3787                  * of outer IP header calculated by sw should be wrong; that
3788                  * is not necessary for IPv6 tunneled pkts because there's no
3789                  * checksum in IP header anymore.
3790                  */
3791                 check_tunnel_tso_nic_support(res->port_id);
3792
3793                 if (!(ports[res->port_id].tx_ol_flags &
3794                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3795                         printf("Warning: csum parse_tunnel must be set "
3796                                 "so that tunneled packets are recognized\n");
3797                 if (!(ports[res->port_id].tx_ol_flags &
3798                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3799                         printf("Warning: csum set outer-ip must be set to hw "
3800                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3801         }
3802 }
3803
3804 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3805         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3806                                 tso, "tunnel_tso");
3807 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3808         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3809                                 mode, "set");
3810 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3811         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3812                                 tso_segsz, UINT16);
3813 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3814         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3815                                 port_id, UINT8);
3816
3817 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3818         .f = cmd_tunnel_tso_set_parsed,
3819         .data = NULL,
3820         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3821                 "Set TSO segment size of tunneled packets for csum engine "
3822                 "(0 to disable)",
3823         .tokens = {
3824                 (void *)&cmd_tunnel_tso_set_tso,
3825                 (void *)&cmd_tunnel_tso_set_mode,
3826                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3827                 (void *)&cmd_tunnel_tso_set_portid,
3828                 NULL,
3829         },
3830 };
3831
3832 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3833         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3834                                 mode, "show");
3835
3836
3837 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3838         .f = cmd_tunnel_tso_set_parsed,
3839         .data = NULL,
3840         .help_str = "tunnel_tso show <port_id> "
3841                 "Show TSO segment size of tunneled packets for csum engine",
3842         .tokens = {
3843                 (void *)&cmd_tunnel_tso_set_tso,
3844                 (void *)&cmd_tunnel_tso_show_mode,
3845                 (void *)&cmd_tunnel_tso_set_portid,
3846                 NULL,
3847         },
3848 };
3849
3850 /* *** SET GRO FOR A PORT *** */
3851 struct cmd_gro_result {
3852         cmdline_fixed_string_t cmd_keyword;
3853         cmdline_fixed_string_t mode;
3854         uint8_t port_id;
3855 };
3856
3857 static void
3858 cmd_enable_gro_parsed(void *parsed_result,
3859                 __attribute__((unused)) struct cmdline *cl,
3860                 __attribute__((unused)) void *data)
3861 {
3862         struct cmd_gro_result *res;
3863
3864         res = parsed_result;
3865         setup_gro(res->mode, res->port_id);
3866 }
3867
3868 cmdline_parse_token_string_t cmd_gro_keyword =
3869         TOKEN_STRING_INITIALIZER(struct cmd_gro_result,
3870                         cmd_keyword, "gro");
3871 cmdline_parse_token_string_t cmd_gro_mode =
3872         TOKEN_STRING_INITIALIZER(struct cmd_gro_result,
3873                         mode, "on#off");
3874 cmdline_parse_token_num_t cmd_gro_pid =
3875         TOKEN_NUM_INITIALIZER(struct cmd_gro_result,
3876                         port_id, UINT8);
3877
3878 cmdline_parse_inst_t cmd_enable_gro = {
3879         .f = cmd_enable_gro_parsed,
3880         .data = NULL,
3881         .help_str = "gro (on|off) (port_id)",
3882         .tokens = {
3883                 (void *)&cmd_gro_keyword,
3884                 (void *)&cmd_gro_mode,
3885                 (void *)&cmd_gro_pid,
3886                 NULL,
3887         },
3888 };
3889
3890 /* *** SET MAX FLOW NUMBER AND ITEM NUM PER FLOW FOR GRO *** */
3891 struct cmd_gro_set_result {
3892         cmdline_fixed_string_t gro;
3893         cmdline_fixed_string_t mode;
3894         uint16_t flow_num;
3895         uint16_t item_num_per_flow;
3896         uint8_t port_id;
3897 };
3898
3899 static void
3900 cmd_gro_set_parsed(void *parsed_result,
3901                        __attribute__((unused)) struct cmdline *cl,
3902                        __attribute__((unused)) void *data)
3903 {
3904         struct cmd_gro_set_result *res = parsed_result;
3905
3906         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3907                 return;
3908         if (test_done == 0) {
3909                 printf("Before set GRO flow_num and item_num_per_flow,"
3910                                 " please stop forwarding first\n");
3911                 return;
3912         }
3913
3914         if (!strcmp(res->mode, "set")) {
3915                 if (res->flow_num == 0)
3916                         printf("Invalid flow number. Revert to default value:"
3917                                         " %u.\n", GRO_DEFAULT_FLOW_NUM);
3918                 else
3919                         gro_ports[res->port_id].param.max_flow_num =
3920                                 res->flow_num;
3921
3922                 if (res->item_num_per_flow == 0)
3923                         printf("Invalid item number per-flow. Revert"
3924                                         " to default value:%u.\n",
3925                                         GRO_DEFAULT_ITEM_NUM_PER_FLOW);
3926                 else
3927                         gro_ports[res->port_id].param.max_item_per_flow =
3928                                 res->item_num_per_flow;
3929         }
3930 }
3931
3932 cmdline_parse_token_string_t cmd_gro_set_gro =
3933         TOKEN_STRING_INITIALIZER(struct cmd_gro_set_result,
3934                                 gro, "gro");
3935 cmdline_parse_token_string_t cmd_gro_set_mode =
3936         TOKEN_STRING_INITIALIZER(struct cmd_gro_set_result,
3937                                 mode, "set");
3938 cmdline_parse_token_num_t cmd_gro_set_flow_num =
3939         TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result,
3940                                 flow_num, UINT16);
3941 cmdline_parse_token_num_t cmd_gro_set_item_num_per_flow =
3942         TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result,
3943                                 item_num_per_flow, UINT16);
3944 cmdline_parse_token_num_t cmd_gro_set_portid =
3945         TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result,
3946                                 port_id, UINT8);
3947
3948 cmdline_parse_inst_t cmd_gro_set = {
3949         .f = cmd_gro_set_parsed,
3950         .data = NULL,
3951         .help_str = "gro set <max_flow_num> <max_item_num_per_flow> "
3952                 "<port_id>: set max flow number and max packet number per-flow "
3953                 "for GRO",
3954         .tokens = {
3955                 (void *)&cmd_gro_set_gro,
3956                 (void *)&cmd_gro_set_mode,
3957                 (void *)&cmd_gro_set_flow_num,
3958                 (void *)&cmd_gro_set_item_num_per_flow,
3959                 (void *)&cmd_gro_set_portid,
3960                 NULL,
3961         },
3962 };
3963
3964 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
3965 struct cmd_set_flush_rx {
3966         cmdline_fixed_string_t set;
3967         cmdline_fixed_string_t flush_rx;
3968         cmdline_fixed_string_t mode;
3969 };
3970
3971 static void
3972 cmd_set_flush_rx_parsed(void *parsed_result,
3973                 __attribute__((unused)) struct cmdline *cl,
3974                 __attribute__((unused)) void *data)
3975 {
3976         struct cmd_set_flush_rx *res = parsed_result;
3977         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3978 }
3979
3980 cmdline_parse_token_string_t cmd_setflushrx_set =
3981         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3982                         set, "set");
3983 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
3984         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3985                         flush_rx, "flush_rx");
3986 cmdline_parse_token_string_t cmd_setflushrx_mode =
3987         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3988                         mode, "on#off");
3989
3990
3991 cmdline_parse_inst_t cmd_set_flush_rx = {
3992         .f = cmd_set_flush_rx_parsed,
3993         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
3994         .data = NULL,
3995         .tokens = {
3996                 (void *)&cmd_setflushrx_set,
3997                 (void *)&cmd_setflushrx_flush_rx,
3998                 (void *)&cmd_setflushrx_mode,
3999                 NULL,
4000         },
4001 };
4002
4003 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4004 struct cmd_set_link_check {
4005         cmdline_fixed_string_t set;
4006         cmdline_fixed_string_t link_check;
4007         cmdline_fixed_string_t mode;
4008 };
4009
4010 static void
4011 cmd_set_link_check_parsed(void *parsed_result,
4012                 __attribute__((unused)) struct cmdline *cl,
4013                 __attribute__((unused)) void *data)
4014 {
4015         struct cmd_set_link_check *res = parsed_result;
4016         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4017 }
4018
4019 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4020         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4021                         set, "set");
4022 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4023         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4024                         link_check, "link_check");
4025 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4026         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4027                         mode, "on#off");
4028
4029
4030 cmdline_parse_inst_t cmd_set_link_check = {
4031         .f = cmd_set_link_check_parsed,
4032         .help_str = "set link_check on|off: Enable/Disable link status check "
4033                     "when starting/stopping a port",
4034         .data = NULL,
4035         .tokens = {
4036                 (void *)&cmd_setlinkcheck_set,
4037                 (void *)&cmd_setlinkcheck_link_check,
4038                 (void *)&cmd_setlinkcheck_mode,
4039                 NULL,
4040         },
4041 };
4042
4043 /* *** SET NIC BYPASS MODE *** */
4044 struct cmd_set_bypass_mode_result {
4045         cmdline_fixed_string_t set;
4046         cmdline_fixed_string_t bypass;
4047         cmdline_fixed_string_t mode;
4048         cmdline_fixed_string_t value;
4049         uint8_t port_id;
4050 };
4051
4052 static void
4053 cmd_set_bypass_mode_parsed(void *parsed_result,
4054                 __attribute__((unused)) struct cmdline *cl,
4055                 __attribute__((unused)) void *data)
4056 {
4057         struct cmd_set_bypass_mode_result *res = parsed_result;
4058         portid_t port_id = res->port_id;
4059         int32_t rc = -EINVAL;
4060
4061 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4062         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4063
4064         if (!strcmp(res->value, "bypass"))
4065                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4066         else if (!strcmp(res->value, "isolate"))
4067                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4068         else
4069                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4070
4071         /* Set the bypass mode for the relevant port. */
4072         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4073 #endif
4074         if (rc != 0)
4075                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4076 }
4077
4078 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4079         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4080                         set, "set");
4081 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4082         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4083                         bypass, "bypass");
4084 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4085         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4086                         mode, "mode");
4087 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4088         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4089                         value, "normal#bypass#isolate");
4090 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4091         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4092                                 port_id, UINT8);
4093
4094 cmdline_parse_inst_t cmd_set_bypass_mode = {
4095         .f = cmd_set_bypass_mode_parsed,
4096         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4097                     "Set the NIC bypass mode for port_id",
4098         .data = NULL,
4099         .tokens = {
4100                 (void *)&cmd_setbypass_mode_set,
4101                 (void *)&cmd_setbypass_mode_bypass,
4102                 (void *)&cmd_setbypass_mode_mode,
4103                 (void *)&cmd_setbypass_mode_value,
4104                 (void *)&cmd_setbypass_mode_port,
4105                 NULL,
4106         },
4107 };
4108
4109 /* *** SET NIC BYPASS EVENT *** */
4110 struct cmd_set_bypass_event_result {
4111         cmdline_fixed_string_t set;
4112         cmdline_fixed_string_t bypass;
4113         cmdline_fixed_string_t event;
4114         cmdline_fixed_string_t event_value;
4115         cmdline_fixed_string_t mode;
4116         cmdline_fixed_string_t mode_value;
4117         uint8_t port_id;
4118 };
4119
4120 static void
4121 cmd_set_bypass_event_parsed(void *parsed_result,
4122                 __attribute__((unused)) struct cmdline *cl,
4123                 __attribute__((unused)) void *data)
4124 {
4125         int32_t rc = -EINVAL;
4126         struct cmd_set_bypass_event_result *res = parsed_result;
4127         portid_t port_id = res->port_id;
4128
4129 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4130         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4131         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4132
4133         if (!strcmp(res->event_value, "timeout"))
4134                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4135         else if (!strcmp(res->event_value, "os_on"))
4136                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4137         else if (!strcmp(res->event_value, "os_off"))
4138                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4139         else if (!strcmp(res->event_value, "power_on"))
4140                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4141         else if (!strcmp(res->event_value, "power_off"))
4142                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4143         else
4144                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4145
4146         if (!strcmp(res->mode_value, "bypass"))
4147                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4148         else if (!strcmp(res->mode_value, "isolate"))
4149                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4150         else
4151                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4152
4153         /* Set the watchdog timeout. */
4154         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4155
4156                 rc = -EINVAL;
4157                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4158                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4159                                                            bypass_timeout);
4160                 }
4161                 if (rc != 0) {
4162                         printf("Failed to set timeout value %u "
4163                         "for port %d, errto code: %d.\n",
4164                         bypass_timeout, port_id, rc);
4165                 }
4166         }
4167
4168         /* Set the bypass event to transition to bypass mode. */
4169         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4170                                               bypass_mode);
4171 #endif
4172
4173         if (rc != 0)
4174                 printf("\t Failed to set bypass event for port = %d.\n",
4175                        port_id);
4176 }
4177
4178 cmdline_parse_token_string_t cmd_setbypass_event_set =
4179         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4180                         set, "set");
4181 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4182         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4183                         bypass, "bypass");
4184 cmdline_parse_token_string_t cmd_setbypass_event_event =
4185         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4186                         event, "event");
4187 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4188         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4189                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4190 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4191         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4192                         mode, "mode");
4193 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4194         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4195                         mode_value, "normal#bypass#isolate");
4196 cmdline_parse_token_num_t cmd_setbypass_event_port =
4197         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4198                                 port_id, UINT8);
4199
4200 cmdline_parse_inst_t cmd_set_bypass_event = {
4201         .f = cmd_set_bypass_event_parsed,
4202         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4203                 "power_off mode normal|bypass|isolate <port_id>: "
4204                 "Set the NIC bypass event mode for port_id",
4205         .data = NULL,
4206         .tokens = {
4207                 (void *)&cmd_setbypass_event_set,
4208                 (void *)&cmd_setbypass_event_bypass,
4209                 (void *)&cmd_setbypass_event_event,
4210                 (void *)&cmd_setbypass_event_event_value,
4211                 (void *)&cmd_setbypass_event_mode,
4212                 (void *)&cmd_setbypass_event_mode_value,
4213                 (void *)&cmd_setbypass_event_port,
4214                 NULL,
4215         },
4216 };
4217
4218
4219 /* *** SET NIC BYPASS TIMEOUT *** */
4220 struct cmd_set_bypass_timeout_result {
4221         cmdline_fixed_string_t set;
4222         cmdline_fixed_string_t bypass;
4223         cmdline_fixed_string_t timeout;
4224         cmdline_fixed_string_t value;
4225 };
4226
4227 static void
4228 cmd_set_bypass_timeout_parsed(void *parsed_result,
4229                 __attribute__((unused)) struct cmdline *cl,
4230                 __attribute__((unused)) void *data)
4231 {
4232         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4233
4234 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4235         if (!strcmp(res->value, "1.5"))
4236                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4237         else if (!strcmp(res->value, "2"))
4238                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4239         else if (!strcmp(res->value, "3"))
4240                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4241         else if (!strcmp(res->value, "4"))
4242                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4243         else if (!strcmp(res->value, "8"))
4244                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4245         else if (!strcmp(res->value, "16"))
4246                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4247         else if (!strcmp(res->value, "32"))
4248                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4249         else
4250                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4251 #endif
4252 }
4253
4254 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4255         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4256                         set, "set");
4257 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4258         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4259                         bypass, "bypass");
4260 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4261         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4262                         timeout, "timeout");
4263 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4264         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4265                         value, "0#1.5#2#3#4#8#16#32");
4266
4267 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4268         .f = cmd_set_bypass_timeout_parsed,
4269         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4270                 "Set the NIC bypass watchdog timeout in seconds",
4271         .data = NULL,
4272         .tokens = {
4273                 (void *)&cmd_setbypass_timeout_set,
4274                 (void *)&cmd_setbypass_timeout_bypass,
4275                 (void *)&cmd_setbypass_timeout_timeout,
4276                 (void *)&cmd_setbypass_timeout_value,
4277                 NULL,
4278         },
4279 };
4280
4281 /* *** SHOW NIC BYPASS MODE *** */
4282 struct cmd_show_bypass_config_result {
4283         cmdline_fixed_string_t show;
4284         cmdline_fixed_string_t bypass;
4285         cmdline_fixed_string_t config;
4286         uint8_t port_id;
4287 };
4288
4289 static void
4290 cmd_show_bypass_config_parsed(void *parsed_result,
4291                 __attribute__((unused)) struct cmdline *cl,
4292                 __attribute__((unused)) void *data)
4293 {
4294         struct cmd_show_bypass_config_result *res = parsed_result;
4295         portid_t port_id = res->port_id;
4296         int rc = -EINVAL;
4297 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4298         uint32_t event_mode;
4299         uint32_t bypass_mode;
4300         uint32_t timeout = bypass_timeout;
4301         int i;
4302
4303         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4304                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4305         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4306                 {"UNKNOWN", "normal", "bypass", "isolate"};
4307         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4308                 "NONE",
4309                 "OS/board on",
4310                 "power supply on",
4311                 "OS/board off",
4312                 "power supply off",
4313                 "timeout"};
4314         int num_events = (sizeof events) / (sizeof events[0]);
4315
4316         /* Display the bypass mode.*/
4317         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4318                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4319                 return;
4320         }
4321         else {
4322                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4323                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4324
4325                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4326         }
4327
4328         /* Display the bypass timeout.*/
4329         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4330                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4331
4332         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4333
4334         /* Display the bypass events and associated modes. */
4335         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4336
4337                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4338                         printf("\tFailed to get bypass mode for event = %s\n",
4339                                 events[i]);
4340                 } else {
4341                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4342                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4343
4344                         printf("\tbypass event: %-16s = %s\n", events[i],
4345                                 modes[event_mode]);
4346                 }
4347         }
4348 #endif
4349         if (rc != 0)
4350                 printf("\tFailed to get bypass configuration for port = %d\n",
4351                        port_id);
4352 }
4353
4354 cmdline_parse_token_string_t cmd_showbypass_config_show =
4355         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4356                         show, "show");
4357 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4358         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4359                         bypass, "bypass");
4360 cmdline_parse_token_string_t cmd_showbypass_config_config =
4361         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4362                         config, "config");
4363 cmdline_parse_token_num_t cmd_showbypass_config_port =
4364         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4365                                 port_id, UINT8);
4366
4367 cmdline_parse_inst_t cmd_show_bypass_config = {
4368         .f = cmd_show_bypass_config_parsed,
4369         .help_str = "show bypass config <port_id>: "
4370                     "Show the NIC bypass config for port_id",
4371         .data = NULL,
4372         .tokens = {
4373                 (void *)&cmd_showbypass_config_show,
4374                 (void *)&cmd_showbypass_config_bypass,
4375                 (void *)&cmd_showbypass_config_config,
4376                 (void *)&cmd_showbypass_config_port,
4377                 NULL,
4378         },
4379 };
4380
4381 #ifdef RTE_LIBRTE_PMD_BOND
4382 /* *** SET BONDING MODE *** */
4383 struct cmd_set_bonding_mode_result {
4384         cmdline_fixed_string_t set;
4385         cmdline_fixed_string_t bonding;
4386         cmdline_fixed_string_t mode;
4387         uint8_t value;
4388         uint8_t port_id;
4389 };
4390
4391 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4392                 __attribute__((unused))  struct cmdline *cl,
4393                 __attribute__((unused)) void *data)
4394 {
4395         struct cmd_set_bonding_mode_result *res = parsed_result;
4396         portid_t port_id = res->port_id;
4397
4398         /* Set the bonding mode for the relevant port. */
4399         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4400                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4401 }
4402
4403 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4404 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4405                 set, "set");
4406 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4407 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4408                 bonding, "bonding");
4409 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4410 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4411                 mode, "mode");
4412 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4413 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4414                 value, UINT8);
4415 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4416 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4417                 port_id, UINT8);
4418
4419 cmdline_parse_inst_t cmd_set_bonding_mode = {
4420                 .f = cmd_set_bonding_mode_parsed,
4421                 .help_str = "set bonding mode <mode_value> <port_id>: "
4422                         "Set the bonding mode for port_id",
4423                 .data = NULL,
4424                 .tokens = {
4425                                 (void *) &cmd_setbonding_mode_set,
4426                                 (void *) &cmd_setbonding_mode_bonding,
4427                                 (void *) &cmd_setbonding_mode_mode,
4428                                 (void *) &cmd_setbonding_mode_value,
4429                                 (void *) &cmd_setbonding_mode_port,
4430                                 NULL
4431                 }
4432 };
4433
4434 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4435 struct cmd_set_bonding_lacp_dedicated_queues_result {
4436         cmdline_fixed_string_t set;
4437         cmdline_fixed_string_t bonding;
4438         cmdline_fixed_string_t lacp;
4439         cmdline_fixed_string_t dedicated_queues;
4440         uint8_t port_id;
4441         cmdline_fixed_string_t mode;
4442 };
4443
4444 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4445                 __attribute__((unused))  struct cmdline *cl,
4446                 __attribute__((unused)) void *data)
4447 {
4448         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4449         portid_t port_id = res->port_id;
4450         struct rte_port *port;
4451
4452         port = &ports[port_id];
4453
4454         /** Check if the port is not started **/
4455         if (port->port_status != RTE_PORT_STOPPED) {
4456                 printf("Please stop port %d first\n", port_id);
4457                 return;
4458         }
4459
4460         if (!strcmp(res->mode, "enable")) {
4461                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4462                         printf("Dedicate queues for LACP control packets"
4463                                         " enabled\n");
4464                 else
4465                         printf("Enabling dedicate queues for LACP control "
4466                                         "packets on port %d failed\n", port_id);
4467         } else if (!strcmp(res->mode, "disable")) {
4468                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4469                         printf("Dedicated queues for LACP control packets "
4470                                         "disabled\n");
4471                 else
4472                         printf("Disabling dedicated queues for LACP control "
4473                                         "traffic on port %d failed\n", port_id);
4474         }
4475 }
4476
4477 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4478 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4479                 set, "set");
4480 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4481 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4482                 bonding, "bonding");
4483 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4484 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4485                 lacp, "lacp");
4486 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4487 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4488                 dedicated_queues, "dedicated_queues");
4489 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4490 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4491                 port_id, UINT8);
4492 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4493 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4494                 mode, "enable#disable");
4495
4496 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4497                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4498                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4499                         "enable|disable: "
4500                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4501                 .data = NULL,
4502                 .tokens = {
4503                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4504                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4505                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4506                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4507                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4508                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4509                         NULL
4510                 }
4511 };
4512
4513 /* *** SET BALANCE XMIT POLICY *** */
4514 struct cmd_set_bonding_balance_xmit_policy_result {
4515         cmdline_fixed_string_t set;
4516         cmdline_fixed_string_t bonding;
4517         cmdline_fixed_string_t balance_xmit_policy;
4518         uint8_t port_id;
4519         cmdline_fixed_string_t policy;
4520 };
4521
4522 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4523                 __attribute__((unused))  struct cmdline *cl,
4524                 __attribute__((unused)) void *data)
4525 {
4526         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4527         portid_t port_id = res->port_id;
4528         uint8_t policy;
4529
4530         if (!strcmp(res->policy, "l2")) {
4531                 policy = BALANCE_XMIT_POLICY_LAYER2;
4532         } else if (!strcmp(res->policy, "l23")) {
4533                 policy = BALANCE_XMIT_POLICY_LAYER23;
4534         } else if (!strcmp(res->policy, "l34")) {
4535                 policy = BALANCE_XMIT_POLICY_LAYER34;
4536         } else {
4537                 printf("\t Invalid xmit policy selection");
4538                 return;
4539         }
4540
4541         /* Set the bonding mode for the relevant port. */
4542         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4543                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4544                                 port_id);
4545         }
4546 }
4547
4548 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4549 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4550                 set, "set");
4551 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4552 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4553                 bonding, "bonding");
4554 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4555 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4556                 balance_xmit_policy, "balance_xmit_policy");
4557 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4558 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4559                 port_id, UINT8);
4560 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4561 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4562                 policy, "l2#l23#l34");
4563
4564 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4565                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4566                 .help_str = "set bonding balance_xmit_policy <port_id> "
4567                         "l2|l23|l34: "
4568                         "Set the bonding balance_xmit_policy for port_id",
4569                 .data = NULL,
4570                 .tokens = {
4571                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4572                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4573                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4574                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4575                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4576                                 NULL
4577                 }
4578 };
4579
4580 /* *** SHOW NIC BONDING CONFIGURATION *** */
4581 struct cmd_show_bonding_config_result {
4582         cmdline_fixed_string_t show;
4583         cmdline_fixed_string_t bonding;
4584         cmdline_fixed_string_t config;
4585         uint8_t port_id;
4586 };
4587
4588 static void cmd_show_bonding_config_parsed(void *parsed_result,
4589                 __attribute__((unused))  struct cmdline *cl,
4590                 __attribute__((unused)) void *data)
4591 {
4592         struct cmd_show_bonding_config_result *res = parsed_result;
4593         int bonding_mode;
4594         uint8_t slaves[RTE_MAX_ETHPORTS];
4595         int num_slaves, num_active_slaves;
4596         int primary_id;
4597         int i;
4598         portid_t port_id = res->port_id;
4599
4600         /* Display the bonding mode.*/
4601         bonding_mode = rte_eth_bond_mode_get(port_id);
4602         if (bonding_mode < 0) {
4603                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4604                 return;
4605         } else
4606                 printf("\tBonding mode: %d\n", bonding_mode);
4607
4608         if (bonding_mode == BONDING_MODE_BALANCE) {
4609                 int balance_xmit_policy;
4610
4611                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4612                 if (balance_xmit_policy < 0) {
4613                         printf("\tFailed to get balance xmit policy for port = %d\n",
4614                                         port_id);
4615                         return;
4616                 } else {
4617                         printf("\tBalance Xmit Policy: ");
4618
4619                         switch (balance_xmit_policy) {
4620                         case BALANCE_XMIT_POLICY_LAYER2:
4621                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4622                                 break;
4623                         case BALANCE_XMIT_POLICY_LAYER23:
4624                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4625                                 break;
4626                         case BALANCE_XMIT_POLICY_LAYER34:
4627                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4628                                 break;
4629                         }
4630                         printf("\n");
4631                 }
4632         }
4633
4634         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4635
4636         if (num_slaves < 0) {
4637                 printf("\tFailed to get slave list for port = %d\n", port_id);
4638                 return;
4639         }
4640         if (num_slaves > 0) {
4641                 printf("\tSlaves (%d): [", num_slaves);
4642                 for (i = 0; i < num_slaves - 1; i++)
4643                         printf("%d ", slaves[i]);
4644
4645                 printf("%d]\n", slaves[num_slaves - 1]);
4646         } else {
4647                 printf("\tSlaves: []\n");
4648
4649         }
4650
4651         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4652                         RTE_MAX_ETHPORTS);
4653
4654         if (num_active_slaves < 0) {
4655                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4656                 return;
4657         }
4658         if (num_active_slaves > 0) {
4659                 printf("\tActive Slaves (%d): [", num_active_slaves);
4660                 for (i = 0; i < num_active_slaves - 1; i++)
4661                         printf("%d ", slaves[i]);
4662
4663                 printf("%d]\n", slaves[num_active_slaves - 1]);
4664
4665         } else {
4666                 printf("\tActive Slaves: []\n");
4667
4668         }
4669
4670         primary_id = rte_eth_bond_primary_get(port_id);
4671         if (primary_id < 0) {
4672                 printf("\tFailed to get primary slave for port = %d\n", port_id);
4673                 return;
4674         } else
4675                 printf("\tPrimary: [%d]\n", primary_id);
4676
4677 }
4678
4679 cmdline_parse_token_string_t cmd_showbonding_config_show =
4680 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4681                 show, "show");
4682 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4683 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4684                 bonding, "bonding");
4685 cmdline_parse_token_string_t cmd_showbonding_config_config =
4686 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4687                 config, "config");
4688 cmdline_parse_token_num_t cmd_showbonding_config_port =
4689 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4690                 port_id, UINT8);
4691
4692 cmdline_parse_inst_t cmd_show_bonding_config = {
4693                 .f = cmd_show_bonding_config_parsed,
4694                 .help_str = "show bonding config <port_id>: "
4695                         "Show the bonding config for port_id",
4696                 .data = NULL,
4697                 .tokens = {
4698                                 (void *)&cmd_showbonding_config_show,
4699                                 (void *)&cmd_showbonding_config_bonding,
4700                                 (void *)&cmd_showbonding_config_config,
4701                                 (void *)&cmd_showbonding_config_port,
4702                                 NULL
4703                 }
4704 };
4705
4706 /* *** SET BONDING PRIMARY *** */
4707 struct cmd_set_bonding_primary_result {
4708         cmdline_fixed_string_t set;
4709         cmdline_fixed_string_t bonding;
4710         cmdline_fixed_string_t primary;
4711         uint8_t slave_id;
4712         uint8_t port_id;
4713 };
4714
4715 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4716                 __attribute__((unused))  struct cmdline *cl,
4717                 __attribute__((unused)) void *data)
4718 {
4719         struct cmd_set_bonding_primary_result *res = parsed_result;
4720         portid_t master_port_id = res->port_id;
4721         portid_t slave_port_id = res->slave_id;
4722
4723         /* Set the primary slave for a bonded device. */
4724         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4725                 printf("\t Failed to set primary slave for port = %d.\n",
4726                                 master_port_id);
4727                 return;
4728         }
4729         init_port_config();
4730 }
4731
4732 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4733 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4734                 set, "set");
4735 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4736 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4737                 bonding, "bonding");
4738 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4739 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4740                 primary, "primary");
4741 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4742 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4743                 slave_id, UINT8);
4744 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4745 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4746                 port_id, UINT8);
4747
4748 cmdline_parse_inst_t cmd_set_bonding_primary = {
4749                 .f = cmd_set_bonding_primary_parsed,
4750                 .help_str = "set bonding primary <slave_id> <port_id>: "
4751                         "Set the primary slave for port_id",
4752                 .data = NULL,
4753                 .tokens = {
4754                                 (void *)&cmd_setbonding_primary_set,
4755                                 (void *)&cmd_setbonding_primary_bonding,
4756                                 (void *)&cmd_setbonding_primary_primary,
4757                                 (void *)&cmd_setbonding_primary_slave,
4758                                 (void *)&cmd_setbonding_primary_port,
4759                                 NULL
4760                 }
4761 };
4762
4763 /* *** ADD SLAVE *** */
4764 struct cmd_add_bonding_slave_result {
4765         cmdline_fixed_string_t add;
4766         cmdline_fixed_string_t bonding;
4767         cmdline_fixed_string_t slave;
4768         uint8_t slave_id;
4769         uint8_t port_id;
4770 };
4771
4772 static void cmd_add_bonding_slave_parsed(void *parsed_result,
4773                 __attribute__((unused))  struct cmdline *cl,
4774                 __attribute__((unused)) void *data)
4775 {
4776         struct cmd_add_bonding_slave_result *res = parsed_result;
4777         portid_t master_port_id = res->port_id;
4778         portid_t slave_port_id = res->slave_id;
4779
4780         /* add the slave for a bonded device. */
4781         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
4782                 printf("\t Failed to add slave %d to master port = %d.\n",
4783                                 slave_port_id, master_port_id);
4784                 return;
4785         }
4786         init_port_config();
4787         set_port_slave_flag(slave_port_id);
4788 }
4789
4790 cmdline_parse_token_string_t cmd_addbonding_slave_add =
4791 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4792                 add, "add");
4793 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
4794 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4795                 bonding, "bonding");
4796 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
4797 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4798                 slave, "slave");
4799 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
4800 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4801                 slave_id, UINT8);
4802 cmdline_parse_token_num_t cmd_addbonding_slave_port =
4803 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4804                 port_id, UINT8);
4805
4806 cmdline_parse_inst_t cmd_add_bonding_slave = {
4807                 .f = cmd_add_bonding_slave_parsed,
4808                 .help_str = "add bonding slave <slave_id> <port_id>: "
4809                         "Add a slave device to a bonded device",
4810                 .data = NULL,
4811                 .tokens = {
4812                                 (void *)&cmd_addbonding_slave_add,
4813                                 (void *)&cmd_addbonding_slave_bonding,
4814                                 (void *)&cmd_addbonding_slave_slave,
4815                                 (void *)&cmd_addbonding_slave_slaveid,
4816                                 (void *)&cmd_addbonding_slave_port,
4817                                 NULL
4818                 }
4819 };
4820
4821 /* *** REMOVE SLAVE *** */
4822 struct cmd_remove_bonding_slave_result {
4823         cmdline_fixed_string_t remove;
4824         cmdline_fixed_string_t bonding;
4825         cmdline_fixed_string_t slave;
4826         uint8_t slave_id;
4827         uint8_t port_id;
4828 };
4829
4830 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
4831                 __attribute__((unused))  struct cmdline *cl,
4832                 __attribute__((unused)) void *data)
4833 {
4834         struct cmd_remove_bonding_slave_result *res = parsed_result;
4835         portid_t master_port_id = res->port_id;
4836         portid_t slave_port_id = res->slave_id;
4837
4838         /* remove the slave from a bonded device. */
4839         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
4840                 printf("\t Failed to remove slave %d from master port = %d.\n",
4841                                 slave_port_id, master_port_id);
4842                 return;
4843         }
4844         init_port_config();
4845         clear_port_slave_flag(slave_port_id);
4846 }
4847
4848 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
4849                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4850                                 remove, "remove");
4851 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
4852                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4853                                 bonding, "bonding");
4854 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
4855                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4856                                 slave, "slave");
4857 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
4858                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4859                                 slave_id, UINT8);
4860 cmdline_parse_token_num_t cmd_removebonding_slave_port =
4861                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4862                                 port_id, UINT8);
4863
4864 cmdline_parse_inst_t cmd_remove_bonding_slave = {
4865                 .f = cmd_remove_bonding_slave_parsed,
4866                 .help_str = "remove bonding slave <slave_id> <port_id>: "
4867                         "Remove a slave device from a bonded device",
4868                 .data = NULL,
4869                 .tokens = {
4870                                 (void *)&cmd_removebonding_slave_remove,
4871                                 (void *)&cmd_removebonding_slave_bonding,
4872                                 (void *)&cmd_removebonding_slave_slave,
4873                                 (void *)&cmd_removebonding_slave_slaveid,
4874                                 (void *)&cmd_removebonding_slave_port,
4875                                 NULL
4876                 }
4877 };
4878
4879 /* *** CREATE BONDED DEVICE *** */
4880 struct cmd_create_bonded_device_result {
4881         cmdline_fixed_string_t create;
4882         cmdline_fixed_string_t bonded;
4883         cmdline_fixed_string_t device;
4884         uint8_t mode;
4885         uint8_t socket;
4886 };
4887
4888 static int bond_dev_num = 0;
4889
4890 static void cmd_create_bonded_device_parsed(void *parsed_result,
4891                 __attribute__((unused))  struct cmdline *cl,
4892                 __attribute__((unused)) void *data)
4893 {
4894         struct cmd_create_bonded_device_result *res = parsed_result;
4895         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
4896         int port_id;
4897
4898         if (test_done == 0) {
4899                 printf("Please stop forwarding first\n");
4900                 return;
4901         }
4902
4903         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bond_testpmd_%d",
4904                         bond_dev_num++);
4905
4906         /* Create a new bonded device. */
4907         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
4908         if (port_id < 0) {
4909                 printf("\t Failed to create bonded device.\n");
4910                 return;
4911         } else {
4912                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
4913                                 port_id);
4914
4915                 /* Update number of ports */
4916                 nb_ports = rte_eth_dev_count();
4917                 reconfig(port_id, res->socket);
4918                 rte_eth_promiscuous_enable(port_id);
4919         }
4920
4921 }
4922
4923 cmdline_parse_token_string_t cmd_createbonded_device_create =
4924                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4925                                 create, "create");
4926 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
4927                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4928                                 bonded, "bonded");
4929 cmdline_parse_token_string_t cmd_createbonded_device_device =
4930                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4931                                 device, "device");
4932 cmdline_parse_token_num_t cmd_createbonded_device_mode =
4933                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4934                                 mode, UINT8);
4935 cmdline_parse_token_num_t cmd_createbonded_device_socket =
4936                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4937                                 socket, UINT8);
4938
4939 cmdline_parse_inst_t cmd_create_bonded_device = {
4940                 .f = cmd_create_bonded_device_parsed,
4941                 .help_str = "create bonded device <mode> <socket>: "
4942                         "Create a new bonded device with specific bonding mode and socket",
4943                 .data = NULL,
4944                 .tokens = {
4945                                 (void *)&cmd_createbonded_device_create,
4946                                 (void *)&cmd_createbonded_device_bonded,
4947                                 (void *)&cmd_createbonded_device_device,
4948                                 (void *)&cmd_createbonded_device_mode,
4949                                 (void *)&cmd_createbonded_device_socket,
4950                                 NULL
4951                 }
4952 };
4953
4954 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
4955 struct cmd_set_bond_mac_addr_result {
4956         cmdline_fixed_string_t set;
4957         cmdline_fixed_string_t bonding;
4958         cmdline_fixed_string_t mac_addr;
4959         uint8_t port_num;
4960         struct ether_addr address;
4961 };
4962
4963 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
4964                 __attribute__((unused))  struct cmdline *cl,
4965                 __attribute__((unused)) void *data)
4966 {
4967         struct cmd_set_bond_mac_addr_result *res = parsed_result;
4968         int ret;
4969
4970         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
4971                 return;
4972
4973         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
4974
4975         /* check the return value and print it if is < 0 */
4976         if (ret < 0)
4977                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4978 }
4979
4980 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
4981                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
4982 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
4983                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
4984                                 "bonding");
4985 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
4986                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
4987                                 "mac_addr");
4988 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
4989                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
4990 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
4991                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
4992
4993 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
4994                 .f = cmd_set_bond_mac_addr_parsed,
4995                 .data = (void *) 0,
4996                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
4997                 .tokens = {
4998                                 (void *)&cmd_set_bond_mac_addr_set,
4999                                 (void *)&cmd_set_bond_mac_addr_bonding,
5000                                 (void *)&cmd_set_bond_mac_addr_mac,
5001                                 (void *)&cmd_set_bond_mac_addr_portnum,
5002                                 (void *)&cmd_set_bond_mac_addr_addr,
5003                                 NULL
5004                 }
5005 };
5006
5007
5008 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5009 struct cmd_set_bond_mon_period_result {
5010         cmdline_fixed_string_t set;
5011         cmdline_fixed_string_t bonding;
5012         cmdline_fixed_string_t mon_period;
5013         uint8_t port_num;
5014         uint32_t period_ms;
5015 };
5016
5017 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5018                 __attribute__((unused))  struct cmdline *cl,
5019                 __attribute__((unused)) void *data)
5020 {
5021         struct cmd_set_bond_mon_period_result *res = parsed_result;
5022         int ret;
5023
5024         if (res->port_num >= nb_ports) {
5025                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5026                 return;
5027         }
5028
5029         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5030
5031         /* check the return value and print it if is < 0 */
5032         if (ret < 0)
5033                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5034 }
5035
5036 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5037                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5038                                 set, "set");
5039 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5040                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5041                                 bonding, "bonding");
5042 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5043                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5044                                 mon_period,     "mon_period");
5045 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5046                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5047                                 port_num, UINT8);
5048 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5049                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5050                                 period_ms, UINT32);
5051
5052 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5053                 .f = cmd_set_bond_mon_period_parsed,
5054                 .data = (void *) 0,
5055                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5056                 .tokens = {
5057                                 (void *)&cmd_set_bond_mon_period_set,
5058                                 (void *)&cmd_set_bond_mon_period_bonding,
5059                                 (void *)&cmd_set_bond_mon_period_mon_period,
5060                                 (void *)&cmd_set_bond_mon_period_portnum,
5061                                 (void *)&cmd_set_bond_mon_period_period_ms,
5062                                 NULL
5063                 }
5064 };
5065
5066 #endif /* RTE_LIBRTE_PMD_BOND */
5067
5068 /* *** SET FORWARDING MODE *** */
5069 struct cmd_set_fwd_mode_result {
5070         cmdline_fixed_string_t set;
5071         cmdline_fixed_string_t fwd;
5072         cmdline_fixed_string_t mode;
5073 };
5074
5075 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5076                                     __attribute__((unused)) struct cmdline *cl,
5077                                     __attribute__((unused)) void *data)
5078 {
5079         struct cmd_set_fwd_mode_result *res = parsed_result;
5080
5081         retry_enabled = 0;
5082         set_pkt_forwarding_mode(res->mode);
5083 }
5084
5085 cmdline_parse_token_string_t cmd_setfwd_set =
5086         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5087 cmdline_parse_token_string_t cmd_setfwd_fwd =
5088         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5089 cmdline_parse_token_string_t cmd_setfwd_mode =
5090         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5091                 "" /* defined at init */);
5092
5093 cmdline_parse_inst_t cmd_set_fwd_mode = {
5094         .f = cmd_set_fwd_mode_parsed,
5095         .data = NULL,
5096         .help_str = NULL, /* defined at init */
5097         .tokens = {
5098                 (void *)&cmd_setfwd_set,
5099                 (void *)&cmd_setfwd_fwd,
5100                 (void *)&cmd_setfwd_mode,
5101                 NULL,
5102         },
5103 };
5104
5105 static void cmd_set_fwd_mode_init(void)
5106 {
5107         char *modes, *c;
5108         static char token[128];
5109         static char help[256];
5110         cmdline_parse_token_string_t *token_struct;
5111
5112         modes = list_pkt_forwarding_modes();
5113         snprintf(help, sizeof(help), "set fwd %s: "
5114                 "Set packet forwarding mode", modes);
5115         cmd_set_fwd_mode.help_str = help;
5116
5117         /* string token separator is # */
5118         for (c = token; *modes != '\0'; modes++)
5119                 if (*modes == '|')
5120                         *c++ = '#';
5121                 else
5122                         *c++ = *modes;
5123         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5124         token_struct->string_data.str = token;
5125 }
5126
5127 /* *** SET RETRY FORWARDING MODE *** */
5128 struct cmd_set_fwd_retry_mode_result {
5129         cmdline_fixed_string_t set;
5130         cmdline_fixed_string_t fwd;
5131         cmdline_fixed_string_t mode;
5132         cmdline_fixed_string_t retry;
5133 };
5134
5135 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5136                             __attribute__((unused)) struct cmdline *cl,
5137                             __attribute__((unused)) void *data)
5138 {
5139         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5140
5141         retry_enabled = 1;
5142         set_pkt_forwarding_mode(res->mode);
5143 }
5144
5145 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5146         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5147                         set, "set");
5148 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5149         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5150                         fwd, "fwd");
5151 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5152         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5153                         mode,
5154                 "" /* defined at init */);
5155 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5156         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5157                         retry, "retry");
5158
5159 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5160         .f = cmd_set_fwd_retry_mode_parsed,
5161         .data = NULL,
5162         .help_str = NULL, /* defined at init */
5163         .tokens = {
5164                 (void *)&cmd_setfwd_retry_set,
5165                 (void *)&cmd_setfwd_retry_fwd,
5166                 (void *)&cmd_setfwd_retry_mode,
5167                 (void *)&cmd_setfwd_retry_retry,
5168                 NULL,
5169         },
5170 };
5171
5172 static void cmd_set_fwd_retry_mode_init(void)
5173 {
5174         char *modes, *c;
5175         static char token[128];
5176         static char help[256];
5177         cmdline_parse_token_string_t *token_struct;
5178
5179         modes = list_pkt_forwarding_retry_modes();
5180         snprintf(help, sizeof(help), "set fwd %s retry: "
5181                 "Set packet forwarding mode with retry", modes);
5182         cmd_set_fwd_retry_mode.help_str = help;
5183
5184         /* string token separator is # */
5185         for (c = token; *modes != '\0'; modes++)
5186                 if (*modes == '|')
5187                         *c++ = '#';
5188                 else
5189                         *c++ = *modes;
5190         token_struct = (cmdline_parse_token_string_t *)
5191                 cmd_set_fwd_retry_mode.tokens[2];
5192         token_struct->string_data.str = token;
5193 }
5194
5195 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5196 struct cmd_set_burst_tx_retry_result {
5197         cmdline_fixed_string_t set;
5198         cmdline_fixed_string_t burst;
5199         cmdline_fixed_string_t tx;
5200         cmdline_fixed_string_t delay;
5201         uint32_t time;
5202         cmdline_fixed_string_t retry;
5203         uint32_t retry_num;
5204 };
5205
5206 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5207                                         __attribute__((unused)) struct cmdline *cl,
5208                                         __attribute__((unused)) void *data)
5209 {
5210         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5211
5212         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5213                 && !strcmp(res->tx, "tx")) {
5214                 if (!strcmp(res->delay, "delay"))
5215                         burst_tx_delay_time = res->time;
5216                 if (!strcmp(res->retry, "retry"))
5217                         burst_tx_retry_num = res->retry_num;
5218         }
5219
5220 }
5221
5222 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5223         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5224 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5225         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5226                                  "burst");
5227 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5228         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5229 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5230         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5231 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5232         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5233 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5234         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5235 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5236         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5237
5238 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5239         .f = cmd_set_burst_tx_retry_parsed,
5240         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5241         .tokens = {
5242                 (void *)&cmd_set_burst_tx_retry_set,
5243                 (void *)&cmd_set_burst_tx_retry_burst,
5244                 (void *)&cmd_set_burst_tx_retry_tx,
5245                 (void *)&cmd_set_burst_tx_retry_delay,
5246                 (void *)&cmd_set_burst_tx_retry_time,
5247                 (void *)&cmd_set_burst_tx_retry_retry,
5248                 (void *)&cmd_set_burst_tx_retry_retry_num,
5249                 NULL,
5250         },
5251 };
5252
5253 /* *** SET PROMISC MODE *** */
5254 struct cmd_set_promisc_mode_result {
5255         cmdline_fixed_string_t set;
5256         cmdline_fixed_string_t promisc;
5257         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5258         uint8_t port_num;                /* valid if "allports" argument == 0 */
5259         cmdline_fixed_string_t mode;
5260 };
5261
5262 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5263                                         __attribute__((unused)) struct cmdline *cl,
5264                                         void *allports)
5265 {
5266         struct cmd_set_promisc_mode_result *res = parsed_result;
5267         int enable;
5268         portid_t i;
5269
5270         if (!strcmp(res->mode, "on"))
5271                 enable = 1;
5272         else
5273                 enable = 0;
5274
5275         /* all ports */
5276         if (allports) {
5277                 RTE_ETH_FOREACH_DEV(i) {
5278                         if (enable)
5279                                 rte_eth_promiscuous_enable(i);
5280                         else
5281                                 rte_eth_promiscuous_disable(i);
5282                 }
5283         }
5284         else {
5285                 if (enable)
5286                         rte_eth_promiscuous_enable(res->port_num);
5287                 else
5288                         rte_eth_promiscuous_disable(res->port_num);
5289         }
5290 }
5291
5292 cmdline_parse_token_string_t cmd_setpromisc_set =
5293         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5294 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5295         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5296                                  "promisc");
5297 cmdline_parse_token_string_t cmd_setpromisc_portall =
5298         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5299                                  "all");
5300 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5301         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5302                               UINT8);
5303 cmdline_parse_token_string_t cmd_setpromisc_mode =
5304         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5305                                  "on#off");
5306
5307 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5308         .f = cmd_set_promisc_mode_parsed,
5309         .data = (void *)1,
5310         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5311         .tokens = {
5312                 (void *)&cmd_setpromisc_set,
5313                 (void *)&cmd_setpromisc_promisc,
5314                 (void *)&cmd_setpromisc_portall,
5315                 (void *)&cmd_setpromisc_mode,
5316                 NULL,
5317         },
5318 };
5319
5320 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5321         .f = cmd_set_promisc_mode_parsed,
5322         .data = (void *)0,
5323         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5324         .tokens = {
5325                 (void *)&cmd_setpromisc_set,
5326                 (void *)&cmd_setpromisc_promisc,
5327                 (void *)&cmd_setpromisc_portnum,
5328                 (void *)&cmd_setpromisc_mode,
5329                 NULL,
5330         },
5331 };
5332
5333 /* *** SET ALLMULTI MODE *** */
5334 struct cmd_set_allmulti_mode_result {
5335         cmdline_fixed_string_t set;
5336         cmdline_fixed_string_t allmulti;
5337         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5338         uint8_t port_num;                /* valid if "allports" argument == 0 */
5339         cmdline_fixed_string_t mode;
5340 };
5341
5342 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5343                                         __attribute__((unused)) struct cmdline *cl,
5344                                         void *allports)
5345 {
5346         struct cmd_set_allmulti_mode_result *res = parsed_result;
5347         int enable;
5348         portid_t i;
5349
5350         if (!strcmp(res->mode, "on"))
5351                 enable = 1;
5352         else
5353                 enable = 0;
5354
5355         /* all ports */
5356         if (allports) {
5357                 RTE_ETH_FOREACH_DEV(i) {
5358                         if (enable)
5359                                 rte_eth_allmulticast_enable(i);
5360                         else
5361                                 rte_eth_allmulticast_disable(i);
5362                 }
5363         }
5364         else {
5365                 if (enable)
5366                         rte_eth_allmulticast_enable(res->port_num);
5367                 else
5368                         rte_eth_allmulticast_disable(res->port_num);
5369         }
5370 }
5371
5372 cmdline_parse_token_string_t cmd_setallmulti_set =
5373         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5374 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5375         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5376                                  "allmulti");
5377 cmdline_parse_token_string_t cmd_setallmulti_portall =
5378         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5379                                  "all");
5380 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5381         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5382                               UINT8);
5383 cmdline_parse_token_string_t cmd_setallmulti_mode =
5384         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5385                                  "on#off");
5386
5387 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5388         .f = cmd_set_allmulti_mode_parsed,
5389         .data = (void *)1,
5390         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5391         .tokens = {
5392                 (void *)&cmd_setallmulti_set,
5393                 (void *)&cmd_setallmulti_allmulti,
5394                 (void *)&cmd_setallmulti_portall,
5395                 (void *)&cmd_setallmulti_mode,
5396                 NULL,
5397         },
5398 };
5399
5400 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5401         .f = cmd_set_allmulti_mode_parsed,
5402         .data = (void *)0,
5403         .help_str = "set allmulti <port_id> on|off: "
5404                 "Set allmulti mode on port_id",
5405         .tokens = {
5406                 (void *)&cmd_setallmulti_set,
5407                 (void *)&cmd_setallmulti_allmulti,
5408                 (void *)&cmd_setallmulti_portnum,
5409                 (void *)&cmd_setallmulti_mode,
5410                 NULL,
5411         },
5412 };
5413
5414 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5415 struct cmd_link_flow_ctrl_set_result {
5416         cmdline_fixed_string_t set;
5417         cmdline_fixed_string_t flow_ctrl;
5418         cmdline_fixed_string_t rx;
5419         cmdline_fixed_string_t rx_lfc_mode;
5420         cmdline_fixed_string_t tx;
5421         cmdline_fixed_string_t tx_lfc_mode;
5422         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5423         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5424         cmdline_fixed_string_t autoneg_str;
5425         cmdline_fixed_string_t autoneg;
5426         cmdline_fixed_string_t hw_str;
5427         uint32_t high_water;
5428         cmdline_fixed_string_t lw_str;
5429         uint32_t low_water;
5430         cmdline_fixed_string_t pt_str;
5431         uint16_t pause_time;
5432         cmdline_fixed_string_t xon_str;
5433         uint16_t send_xon;
5434         uint8_t  port_id;
5435 };
5436
5437 cmdline_parse_token_string_t cmd_lfc_set_set =
5438         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5439                                 set, "set");
5440 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5441         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5442                                 flow_ctrl, "flow_ctrl");
5443 cmdline_parse_token_string_t cmd_lfc_set_rx =
5444         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5445                                 rx, "rx");
5446 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5447         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5448                                 rx_lfc_mode, "on#off");
5449 cmdline_parse_token_string_t cmd_lfc_set_tx =
5450         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5451                                 tx, "tx");
5452 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5453         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5454                                 tx_lfc_mode, "on#off");
5455 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5456         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5457                                 hw_str, "high_water");
5458 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5459         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5460                                 high_water, UINT32);
5461 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5462         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5463                                 lw_str, "low_water");
5464 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5465         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5466                                 low_water, UINT32);
5467 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5468         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5469                                 pt_str, "pause_time");
5470 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5471         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5472                                 pause_time, UINT16);
5473 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5474         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5475                                 xon_str, "send_xon");
5476 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5477         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5478                                 send_xon, UINT16);
5479 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5480         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5481                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5482 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5483         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5484                                 mac_ctrl_frame_fwd_mode, "on#off");
5485 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5486         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5487                                 autoneg_str, "autoneg");
5488 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5489         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5490                                 autoneg, "on#off");
5491 cmdline_parse_token_num_t cmd_lfc_set_portid =
5492         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5493                                 port_id, UINT8);
5494
5495 /* forward declaration */
5496 static void
5497 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5498                               void *data);
5499
5500 cmdline_parse_inst_t cmd_link_flow_control_set = {
5501         .f = cmd_link_flow_ctrl_set_parsed,
5502         .data = NULL,
5503         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5504                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5505                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5506         .tokens = {
5507                 (void *)&cmd_lfc_set_set,
5508                 (void *)&cmd_lfc_set_flow_ctrl,
5509                 (void *)&cmd_lfc_set_rx,
5510                 (void *)&cmd_lfc_set_rx_mode,
5511                 (void *)&cmd_lfc_set_tx,
5512                 (void *)&cmd_lfc_set_tx_mode,
5513                 (void *)&cmd_lfc_set_high_water,
5514                 (void *)&cmd_lfc_set_low_water,
5515                 (void *)&cmd_lfc_set_pause_time,
5516                 (void *)&cmd_lfc_set_send_xon,
5517                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5518                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5519                 (void *)&cmd_lfc_set_autoneg_str,
5520                 (void *)&cmd_lfc_set_autoneg,
5521                 (void *)&cmd_lfc_set_portid,
5522                 NULL,
5523         },
5524 };
5525
5526 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5527         .f = cmd_link_flow_ctrl_set_parsed,
5528         .data = (void *)&cmd_link_flow_control_set_rx,
5529         .help_str = "set flow_ctrl rx on|off <port_id>: "
5530                 "Change rx flow control parameter",
5531         .tokens = {
5532                 (void *)&cmd_lfc_set_set,
5533                 (void *)&cmd_lfc_set_flow_ctrl,
5534                 (void *)&cmd_lfc_set_rx,
5535                 (void *)&cmd_lfc_set_rx_mode,
5536                 (void *)&cmd_lfc_set_portid,
5537                 NULL,
5538         },
5539 };
5540
5541 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5542         .f = cmd_link_flow_ctrl_set_parsed,
5543         .data = (void *)&cmd_link_flow_control_set_tx,
5544         .help_str = "set flow_ctrl tx on|off <port_id>: "
5545                 "Change tx flow control parameter",
5546         .tokens = {
5547                 (void *)&cmd_lfc_set_set,
5548                 (void *)&cmd_lfc_set_flow_ctrl,
5549                 (void *)&cmd_lfc_set_tx,
5550                 (void *)&cmd_lfc_set_tx_mode,
5551                 (void *)&cmd_lfc_set_portid,
5552                 NULL,
5553         },
5554 };
5555
5556 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5557         .f = cmd_link_flow_ctrl_set_parsed,
5558         .data = (void *)&cmd_link_flow_control_set_hw,
5559         .help_str = "set flow_ctrl high_water <value> <port_id>: "
5560                 "Change high water flow control parameter",
5561         .tokens = {
5562                 (void *)&cmd_lfc_set_set,
5563                 (void *)&cmd_lfc_set_flow_ctrl,
5564                 (void *)&cmd_lfc_set_high_water_str,
5565                 (void *)&cmd_lfc_set_high_water,
5566                 (void *)&cmd_lfc_set_portid,
5567                 NULL,
5568         },
5569 };
5570
5571 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5572         .f = cmd_link_flow_ctrl_set_parsed,
5573         .data = (void *)&cmd_link_flow_control_set_lw,
5574         .help_str = "set flow_ctrl low_water <value> <port_id>: "
5575                 "Change low water flow control parameter",
5576         .tokens = {
5577                 (void *)&cmd_lfc_set_set,
5578                 (void *)&cmd_lfc_set_flow_ctrl,
5579                 (void *)&cmd_lfc_set_low_water_str,
5580                 (void *)&cmd_lfc_set_low_water,
5581                 (void *)&cmd_lfc_set_portid,
5582                 NULL,
5583         },
5584 };
5585
5586 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5587         .f = cmd_link_flow_ctrl_set_parsed,
5588         .data = (void *)&cmd_link_flow_control_set_pt,
5589         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
5590                 "Change pause time flow control parameter",
5591         .tokens = {
5592                 (void *)&cmd_lfc_set_set,
5593                 (void *)&cmd_lfc_set_flow_ctrl,
5594                 (void *)&cmd_lfc_set_pause_time_str,
5595                 (void *)&cmd_lfc_set_pause_time,
5596                 (void *)&cmd_lfc_set_portid,
5597                 NULL,
5598         },
5599 };
5600
5601 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5602         .f = cmd_link_flow_ctrl_set_parsed,
5603         .data = (void *)&cmd_link_flow_control_set_xon,
5604         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
5605                 "Change send_xon flow control parameter",
5606         .tokens = {
5607                 (void *)&cmd_lfc_set_set,
5608                 (void *)&cmd_lfc_set_flow_ctrl,
5609                 (void *)&cmd_lfc_set_send_xon_str,
5610                 (void *)&cmd_lfc_set_send_xon,
5611                 (void *)&cmd_lfc_set_portid,
5612                 NULL,
5613         },
5614 };
5615
5616 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5617         .f = cmd_link_flow_ctrl_set_parsed,
5618         .data = (void *)&cmd_link_flow_control_set_macfwd,
5619         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
5620                 "Change mac ctrl fwd flow control parameter",
5621         .tokens = {
5622                 (void *)&cmd_lfc_set_set,
5623                 (void *)&cmd_lfc_set_flow_ctrl,
5624                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5625                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5626                 (void *)&cmd_lfc_set_portid,
5627                 NULL,
5628         },
5629 };
5630
5631 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5632         .f = cmd_link_flow_ctrl_set_parsed,
5633         .data = (void *)&cmd_link_flow_control_set_autoneg,
5634         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
5635                 "Change autoneg flow control parameter",
5636         .tokens = {
5637                 (void *)&cmd_lfc_set_set,
5638                 (void *)&cmd_lfc_set_flow_ctrl,
5639                 (void *)&cmd_lfc_set_autoneg_str,
5640                 (void *)&cmd_lfc_set_autoneg,
5641                 (void *)&cmd_lfc_set_portid,
5642                 NULL,
5643         },
5644 };
5645
5646 static void
5647 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
5648                               __attribute__((unused)) struct cmdline *cl,
5649                               void *data)
5650 {
5651         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
5652         cmdline_parse_inst_t *cmd = data;
5653         struct rte_eth_fc_conf fc_conf;
5654         int rx_fc_en = 0;
5655         int tx_fc_en = 0;
5656         int ret;
5657
5658         /*
5659          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5660          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5661          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5662          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5663          */
5664         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5665                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
5666         };
5667
5668         /* Partial command line, retrieve current configuration */
5669         if (cmd) {
5670                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5671                 if (ret != 0) {
5672                         printf("cannot get current flow ctrl parameters, return"
5673                                "code = %d\n", ret);
5674                         return;
5675                 }
5676
5677                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
5678                     (fc_conf.mode == RTE_FC_FULL))
5679                         rx_fc_en = 1;
5680                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
5681                     (fc_conf.mode == RTE_FC_FULL))
5682                         tx_fc_en = 1;
5683         }
5684
5685         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
5686                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
5687
5688         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
5689                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
5690
5691         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
5692
5693         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
5694                 fc_conf.high_water = res->high_water;
5695
5696         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
5697                 fc_conf.low_water = res->low_water;
5698
5699         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
5700                 fc_conf.pause_time = res->pause_time;
5701
5702         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
5703                 fc_conf.send_xon = res->send_xon;
5704
5705         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
5706                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
5707                         fc_conf.mac_ctrl_frame_fwd = 1;
5708                 else
5709                         fc_conf.mac_ctrl_frame_fwd = 0;
5710         }
5711
5712         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
5713                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
5714
5715         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
5716         if (ret != 0)
5717                 printf("bad flow contrl parameter, return code = %d \n", ret);
5718 }
5719
5720 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
5721 struct cmd_priority_flow_ctrl_set_result {
5722         cmdline_fixed_string_t set;
5723         cmdline_fixed_string_t pfc_ctrl;
5724         cmdline_fixed_string_t rx;
5725         cmdline_fixed_string_t rx_pfc_mode;
5726         cmdline_fixed_string_t tx;
5727         cmdline_fixed_string_t tx_pfc_mode;
5728         uint32_t high_water;
5729         uint32_t low_water;
5730         uint16_t pause_time;
5731         uint8_t  priority;
5732         uint8_t  port_id;
5733 };
5734
5735 static void
5736 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
5737                        __attribute__((unused)) struct cmdline *cl,
5738                        __attribute__((unused)) void *data)
5739 {
5740         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
5741         struct rte_eth_pfc_conf pfc_conf;
5742         int rx_fc_enable, tx_fc_enable;
5743         int ret;
5744
5745         /*
5746          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5747          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5748          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5749          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5750          */
5751         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
5752                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
5753         };
5754
5755         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
5756         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
5757         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
5758         pfc_conf.fc.high_water = res->high_water;
5759         pfc_conf.fc.low_water  = res->low_water;
5760         pfc_conf.fc.pause_time = res->pause_time;
5761         pfc_conf.priority      = res->priority;
5762
5763         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
5764         if (ret != 0)
5765                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
5766 }
5767
5768 cmdline_parse_token_string_t cmd_pfc_set_set =
5769         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5770                                 set, "set");
5771 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
5772         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5773                                 pfc_ctrl, "pfc_ctrl");
5774 cmdline_parse_token_string_t cmd_pfc_set_rx =
5775         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5776                                 rx, "rx");
5777 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
5778         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5779                                 rx_pfc_mode, "on#off");
5780 cmdline_parse_token_string_t cmd_pfc_set_tx =
5781         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5782                                 tx, "tx");
5783 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
5784         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5785                                 tx_pfc_mode, "on#off");
5786 cmdline_parse_token_num_t cmd_pfc_set_high_water =
5787         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5788                                 high_water, UINT32);
5789 cmdline_parse_token_num_t cmd_pfc_set_low_water =
5790         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5791                                 low_water, UINT32);
5792 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
5793         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5794                                 pause_time, UINT16);
5795 cmdline_parse_token_num_t cmd_pfc_set_priority =
5796         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5797                                 priority, UINT8);
5798 cmdline_parse_token_num_t cmd_pfc_set_portid =
5799         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5800                                 port_id, UINT8);
5801
5802 cmdline_parse_inst_t cmd_priority_flow_control_set = {
5803         .f = cmd_priority_flow_ctrl_set_parsed,
5804         .data = NULL,
5805         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
5806                 "<pause_time> <priority> <port_id>: "
5807                 "Configure the Ethernet priority flow control",
5808         .tokens = {
5809                 (void *)&cmd_pfc_set_set,
5810                 (void *)&cmd_pfc_set_flow_ctrl,
5811                 (void *)&cmd_pfc_set_rx,
5812                 (void *)&cmd_pfc_set_rx_mode,
5813                 (void *)&cmd_pfc_set_tx,
5814                 (void *)&cmd_pfc_set_tx_mode,
5815                 (void *)&cmd_pfc_set_high_water,
5816                 (void *)&cmd_pfc_set_low_water,
5817                 (void *)&cmd_pfc_set_pause_time,
5818                 (void *)&cmd_pfc_set_priority,
5819                 (void *)&cmd_pfc_set_portid,
5820                 NULL,
5821         },
5822 };
5823
5824 /* *** RESET CONFIGURATION *** */
5825 struct cmd_reset_result {
5826         cmdline_fixed_string_t reset;
5827         cmdline_fixed_string_t def;
5828 };
5829
5830 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
5831                              struct cmdline *cl,
5832                              __attribute__((unused)) void *data)
5833 {
5834         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
5835         set_def_fwd_config();
5836 }
5837
5838 cmdline_parse_token_string_t cmd_reset_set =
5839         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
5840 cmdline_parse_token_string_t cmd_reset_def =
5841         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
5842                                  "default");
5843
5844 cmdline_parse_inst_t cmd_reset = {
5845         .f = cmd_reset_parsed,
5846         .data = NULL,
5847         .help_str = "set default: Reset default forwarding configuration",
5848         .tokens = {
5849                 (void *)&cmd_reset_set,
5850                 (void *)&cmd_reset_def,
5851                 NULL,
5852         },
5853 };
5854
5855 /* *** START FORWARDING *** */
5856 struct cmd_start_result {
5857         cmdline_fixed_string_t start;
5858 };
5859
5860 cmdline_parse_token_string_t cmd_start_start =
5861         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
5862
5863 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
5864                              __attribute__((unused)) struct cmdline *cl,
5865                              __attribute__((unused)) void *data)
5866 {
5867         start_packet_forwarding(0);
5868 }
5869
5870 cmdline_parse_inst_t cmd_start = {
5871         .f = cmd_start_parsed,
5872         .data = NULL,
5873         .help_str = "start: Start packet forwarding",
5874         .tokens = {
5875                 (void *)&cmd_start_start,
5876                 NULL,
5877         },
5878 };
5879
5880 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
5881 struct cmd_start_tx_first_result {
5882         cmdline_fixed_string_t start;
5883         cmdline_fixed_string_t tx_first;
5884 };
5885
5886 static void
5887 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
5888                           __attribute__((unused)) struct cmdline *cl,
5889                           __attribute__((unused)) void *data)
5890 {
5891         start_packet_forwarding(1);
5892 }
5893
5894 cmdline_parse_token_string_t cmd_start_tx_first_start =
5895         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
5896                                  "start");
5897 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
5898         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
5899                                  tx_first, "tx_first");
5900
5901 cmdline_parse_inst_t cmd_start_tx_first = {
5902         .f = cmd_start_tx_first_parsed,
5903         .data = NULL,
5904         .help_str = "start tx_first: Start packet forwarding, "
5905                 "after sending 1 burst of packets",
5906         .tokens = {
5907                 (void *)&cmd_start_tx_first_start,
5908                 (void *)&cmd_start_tx_first_tx_first,
5909                 NULL,
5910         },
5911 };
5912
5913 /* *** START FORWARDING WITH N TX BURST FIRST *** */
5914 struct cmd_start_tx_first_n_result {
5915         cmdline_fixed_string_t start;
5916         cmdline_fixed_string_t tx_first;
5917         uint32_t tx_num;
5918 };
5919
5920 static void
5921 cmd_start_tx_first_n_parsed(void *parsed_result,
5922                           __attribute__((unused)) struct cmdline *cl,
5923                           __attribute__((unused)) void *data)
5924 {
5925         struct cmd_start_tx_first_n_result *res = parsed_result;
5926
5927         start_packet_forwarding(res->tx_num);
5928 }
5929
5930 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
5931         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
5932                         start, "start");
5933 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
5934         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
5935                         tx_first, "tx_first");
5936 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
5937         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
5938                         tx_num, UINT32);
5939
5940 cmdline_parse_inst_t cmd_start_tx_first_n = {
5941         .f = cmd_start_tx_first_n_parsed,
5942         .data = NULL,
5943         .help_str = "start tx_first <num>: "
5944                 "packet forwarding, after sending <num> bursts of packets",
5945         .tokens = {
5946                 (void *)&cmd_start_tx_first_n_start,
5947                 (void *)&cmd_start_tx_first_n_tx_first,
5948                 (void *)&cmd_start_tx_first_n_tx_num,
5949                 NULL,
5950         },
5951 };
5952
5953 /* *** SET LINK UP *** */
5954 struct cmd_set_link_up_result {
5955         cmdline_fixed_string_t set;
5956         cmdline_fixed_string_t link_up;
5957         cmdline_fixed_string_t port;
5958         uint8_t port_id;
5959 };
5960
5961 cmdline_parse_token_string_t cmd_set_link_up_set =
5962         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
5963 cmdline_parse_token_string_t cmd_set_link_up_link_up =
5964         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
5965                                 "link-up");
5966 cmdline_parse_token_string_t cmd_set_link_up_port =
5967         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
5968 cmdline_parse_token_num_t cmd_set_link_up_port_id =
5969         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
5970
5971 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
5972                              __attribute__((unused)) struct cmdline *cl,
5973                              __attribute__((unused)) void *data)
5974 {
5975         struct cmd_set_link_up_result *res = parsed_result;
5976         dev_set_link_up(res->port_id);
5977 }
5978
5979 cmdline_parse_inst_t cmd_set_link_up = {
5980         .f = cmd_set_link_up_parsed,
5981         .data = NULL,
5982         .help_str = "set link-up port <port id>",
5983         .tokens = {
5984                 (void *)&cmd_set_link_up_set,
5985                 (void *)&cmd_set_link_up_link_up,
5986                 (void *)&cmd_set_link_up_port,
5987                 (void *)&cmd_set_link_up_port_id,
5988                 NULL,
5989         },
5990 };
5991
5992 /* *** SET LINK DOWN *** */
5993 struct cmd_set_link_down_result {
5994         cmdline_fixed_string_t set;
5995         cmdline_fixed_string_t link_down;
5996         cmdline_fixed_string_t port;
5997         uint8_t port_id;
5998 };
5999
6000 cmdline_parse_token_string_t cmd_set_link_down_set =
6001         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6002 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6003         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6004                                 "link-down");
6005 cmdline_parse_token_string_t cmd_set_link_down_port =
6006         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6007 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6008         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
6009
6010 static void cmd_set_link_down_parsed(
6011                                 __attribute__((unused)) void *parsed_result,
6012                                 __attribute__((unused)) struct cmdline *cl,
6013                                 __attribute__((unused)) void *data)
6014 {
6015         struct cmd_set_link_down_result *res = parsed_result;
6016         dev_set_link_down(res->port_id);
6017 }
6018
6019 cmdline_parse_inst_t cmd_set_link_down = {
6020         .f = cmd_set_link_down_parsed,
6021         .data = NULL,
6022         .help_str = "set link-down port <port id>",
6023         .tokens = {
6024                 (void *)&cmd_set_link_down_set,
6025                 (void *)&cmd_set_link_down_link_down,
6026                 (void *)&cmd_set_link_down_port,
6027                 (void *)&cmd_set_link_down_port_id,
6028                 NULL,
6029         },
6030 };
6031
6032 /* *** SHOW CFG *** */
6033 struct cmd_showcfg_result {
6034         cmdline_fixed_string_t show;
6035         cmdline_fixed_string_t cfg;
6036         cmdline_fixed_string_t what;
6037 };
6038
6039 static void cmd_showcfg_parsed(void *parsed_result,
6040                                __attribute__((unused)) struct cmdline *cl,
6041                                __attribute__((unused)) void *data)
6042 {
6043         struct cmd_showcfg_result *res = parsed_result;
6044         if (!strcmp(res->what, "rxtx"))
6045                 rxtx_config_display();
6046         else if (!strcmp(res->what, "cores"))
6047                 fwd_lcores_config_display();
6048         else if (!strcmp(res->what, "fwd"))
6049                 pkt_fwd_config_display(&cur_fwd_config);
6050         else if (!strcmp(res->what, "txpkts"))
6051                 show_tx_pkt_segments();
6052 }
6053
6054 cmdline_parse_token_string_t cmd_showcfg_show =
6055         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6056 cmdline_parse_token_string_t cmd_showcfg_port =
6057         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6058 cmdline_parse_token_string_t cmd_showcfg_what =
6059         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6060                                  "rxtx#cores#fwd#txpkts");
6061
6062 cmdline_parse_inst_t cmd_showcfg = {
6063         .f = cmd_showcfg_parsed,
6064         .data = NULL,
6065         .help_str = "show config rxtx|cores|fwd|txpkts",
6066         .tokens = {
6067                 (void *)&cmd_showcfg_show,
6068                 (void *)&cmd_showcfg_port,
6069                 (void *)&cmd_showcfg_what,
6070                 NULL,
6071         },
6072 };
6073
6074 /* *** SHOW ALL PORT INFO *** */
6075 struct cmd_showportall_result {
6076         cmdline_fixed_string_t show;
6077         cmdline_fixed_string_t port;
6078         cmdline_fixed_string_t what;
6079         cmdline_fixed_string_t all;
6080 };
6081
6082 static void cmd_showportall_parsed(void *parsed_result,
6083                                 __attribute__((unused)) struct cmdline *cl,
6084                                 __attribute__((unused)) void *data)
6085 {
6086         portid_t i;
6087
6088         struct cmd_showportall_result *res = parsed_result;
6089         if (!strcmp(res->show, "clear")) {
6090                 if (!strcmp(res->what, "stats"))
6091                         RTE_ETH_FOREACH_DEV(i)
6092                                 nic_stats_clear(i);
6093                 else if (!strcmp(res->what, "xstats"))
6094                         RTE_ETH_FOREACH_DEV(i)
6095                                 nic_xstats_clear(i);
6096         } else if (!strcmp(res->what, "info"))
6097                 RTE_ETH_FOREACH_DEV(i)
6098                         port_infos_display(i);
6099         else if (!strcmp(res->what, "stats"))
6100                 RTE_ETH_FOREACH_DEV(i)
6101                         nic_stats_display(i);
6102         else if (!strcmp(res->what, "xstats"))
6103                 RTE_ETH_FOREACH_DEV(i)
6104                         nic_xstats_display(i);
6105         else if (!strcmp(res->what, "fdir"))
6106                 RTE_ETH_FOREACH_DEV(i)
6107                         fdir_get_infos(i);
6108         else if (!strcmp(res->what, "stat_qmap"))
6109                 RTE_ETH_FOREACH_DEV(i)
6110                         nic_stats_mapping_display(i);
6111         else if (!strcmp(res->what, "dcb_tc"))
6112                 RTE_ETH_FOREACH_DEV(i)
6113                         port_dcb_info_display(i);
6114         else if (!strcmp(res->what, "cap"))
6115                 RTE_ETH_FOREACH_DEV(i)
6116                         port_offload_cap_display(i);
6117 }
6118
6119 cmdline_parse_token_string_t cmd_showportall_show =
6120         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6121                                  "show#clear");
6122 cmdline_parse_token_string_t cmd_showportall_port =
6123         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6124 cmdline_parse_token_string_t cmd_showportall_what =
6125         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6126                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6127 cmdline_parse_token_string_t cmd_showportall_all =
6128         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6129 cmdline_parse_inst_t cmd_showportall = {
6130         .f = cmd_showportall_parsed,
6131         .data = NULL,
6132         .help_str = "show|clear port "
6133                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6134         .tokens = {
6135                 (void *)&cmd_showportall_show,
6136                 (void *)&cmd_showportall_port,
6137                 (void *)&cmd_showportall_what,
6138                 (void *)&cmd_showportall_all,
6139                 NULL,
6140         },
6141 };
6142
6143 /* *** SHOW PORT INFO *** */
6144 struct cmd_showport_result {
6145         cmdline_fixed_string_t show;
6146         cmdline_fixed_string_t port;
6147         cmdline_fixed_string_t what;
6148         uint8_t portnum;
6149 };
6150
6151 static void cmd_showport_parsed(void *parsed_result,
6152                                 __attribute__((unused)) struct cmdline *cl,
6153                                 __attribute__((unused)) void *data)
6154 {
6155         struct cmd_showport_result *res = parsed_result;
6156         if (!strcmp(res->show, "clear")) {
6157                 if (!strcmp(res->what, "stats"))
6158                         nic_stats_clear(res->portnum);
6159                 else if (!strcmp(res->what, "xstats"))
6160                         nic_xstats_clear(res->portnum);
6161         } else if (!strcmp(res->what, "info"))
6162                 port_infos_display(res->portnum);
6163         else if (!strcmp(res->what, "stats"))
6164                 nic_stats_display(res->portnum);
6165         else if (!strcmp(res->what, "xstats"))
6166                 nic_xstats_display(res->portnum);
6167         else if (!strcmp(res->what, "fdir"))
6168                  fdir_get_infos(res->portnum);
6169         else if (!strcmp(res->what, "stat_qmap"))
6170                 nic_stats_mapping_display(res->portnum);
6171         else if (!strcmp(res->what, "dcb_tc"))
6172                 port_dcb_info_display(res->portnum);
6173         else if (!strcmp(res->what, "cap"))
6174                 port_offload_cap_display(res->portnum);
6175 }
6176
6177 cmdline_parse_token_string_t cmd_showport_show =
6178         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6179                                  "show#clear");
6180 cmdline_parse_token_string_t cmd_showport_port =
6181         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6182 cmdline_parse_token_string_t cmd_showport_what =
6183         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6184                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6185 cmdline_parse_token_num_t cmd_showport_portnum =
6186         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
6187
6188 cmdline_parse_inst_t cmd_showport = {
6189         .f = cmd_showport_parsed,
6190         .data = NULL,
6191         .help_str = "show|clear port "
6192                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6193                 "<port_id>",
6194         .tokens = {
6195                 (void *)&cmd_showport_show,
6196                 (void *)&cmd_showport_port,
6197                 (void *)&cmd_showport_what,
6198                 (void *)&cmd_showport_portnum,
6199                 NULL,
6200         },
6201 };
6202
6203 /* *** SHOW QUEUE INFO *** */
6204 struct cmd_showqueue_result {
6205         cmdline_fixed_string_t show;
6206         cmdline_fixed_string_t type;
6207         cmdline_fixed_string_t what;
6208         uint8_t portnum;
6209         uint16_t queuenum;
6210 };
6211
6212 static void
6213 cmd_showqueue_parsed(void *parsed_result,
6214         __attribute__((unused)) struct cmdline *cl,
6215         __attribute__((unused)) void *data)
6216 {
6217         struct cmd_showqueue_result *res = parsed_result;
6218
6219         if (!strcmp(res->type, "rxq"))
6220                 rx_queue_infos_display(res->portnum, res->queuenum);
6221         else if (!strcmp(res->type, "txq"))
6222                 tx_queue_infos_display(res->portnum, res->queuenum);
6223 }
6224
6225 cmdline_parse_token_string_t cmd_showqueue_show =
6226         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6227 cmdline_parse_token_string_t cmd_showqueue_type =
6228         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6229 cmdline_parse_token_string_t cmd_showqueue_what =
6230         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6231 cmdline_parse_token_num_t cmd_showqueue_portnum =
6232         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
6233 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6234         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6235
6236 cmdline_parse_inst_t cmd_showqueue = {
6237         .f = cmd_showqueue_parsed,
6238         .data = NULL,
6239         .help_str = "show rxq|txq info <port_id> <queue_id>",
6240         .tokens = {
6241                 (void *)&cmd_showqueue_show,
6242                 (void *)&cmd_showqueue_type,
6243                 (void *)&cmd_showqueue_what,
6244                 (void *)&cmd_showqueue_portnum,
6245                 (void *)&cmd_showqueue_queuenum,
6246                 NULL,
6247         },
6248 };
6249
6250 /* *** READ PORT REGISTER *** */
6251 struct cmd_read_reg_result {
6252         cmdline_fixed_string_t read;
6253         cmdline_fixed_string_t reg;
6254         uint8_t port_id;
6255         uint32_t reg_off;
6256 };
6257
6258 static void
6259 cmd_read_reg_parsed(void *parsed_result,
6260                     __attribute__((unused)) struct cmdline *cl,
6261                     __attribute__((unused)) void *data)
6262 {
6263         struct cmd_read_reg_result *res = parsed_result;
6264         port_reg_display(res->port_id, res->reg_off);
6265 }
6266
6267 cmdline_parse_token_string_t cmd_read_reg_read =
6268         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6269 cmdline_parse_token_string_t cmd_read_reg_reg =
6270         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6271 cmdline_parse_token_num_t cmd_read_reg_port_id =
6272         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
6273 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6274         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6275
6276 cmdline_parse_inst_t cmd_read_reg = {
6277         .f = cmd_read_reg_parsed,
6278         .data = NULL,
6279         .help_str = "read reg <port_id> <reg_off>",
6280         .tokens = {
6281                 (void *)&cmd_read_reg_read,
6282                 (void *)&cmd_read_reg_reg,
6283                 (void *)&cmd_read_reg_port_id,
6284                 (void *)&cmd_read_reg_reg_off,
6285                 NULL,
6286         },
6287 };
6288
6289 /* *** READ PORT REGISTER BIT FIELD *** */
6290 struct cmd_read_reg_bit_field_result {
6291         cmdline_fixed_string_t read;
6292         cmdline_fixed_string_t regfield;
6293         uint8_t port_id;
6294         uint32_t reg_off;
6295         uint8_t bit1_pos;
6296         uint8_t bit2_pos;
6297 };
6298
6299 static void
6300 cmd_read_reg_bit_field_parsed(void *parsed_result,
6301                               __attribute__((unused)) struct cmdline *cl,
6302                               __attribute__((unused)) void *data)
6303 {
6304         struct cmd_read_reg_bit_field_result *res = parsed_result;
6305         port_reg_bit_field_display(res->port_id, res->reg_off,
6306                                    res->bit1_pos, res->bit2_pos);
6307 }
6308
6309 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6310         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6311                                  "read");
6312 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6313         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6314                                  regfield, "regfield");
6315 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6316         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6317                               UINT8);
6318 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6319         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6320                               UINT32);
6321 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6322         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6323                               UINT8);
6324 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6325         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6326                               UINT8);
6327
6328 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6329         .f = cmd_read_reg_bit_field_parsed,
6330         .data = NULL,
6331         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6332         "Read register bit field between bit_x and bit_y included",
6333         .tokens = {
6334                 (void *)&cmd_read_reg_bit_field_read,
6335                 (void *)&cmd_read_reg_bit_field_regfield,
6336                 (void *)&cmd_read_reg_bit_field_port_id,
6337                 (void *)&cmd_read_reg_bit_field_reg_off,
6338                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6339                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6340                 NULL,
6341         },
6342 };
6343
6344 /* *** READ PORT REGISTER BIT *** */
6345 struct cmd_read_reg_bit_result {
6346         cmdline_fixed_string_t read;
6347         cmdline_fixed_string_t regbit;
6348         uint8_t port_id;
6349         uint32_t reg_off;
6350         uint8_t bit_pos;
6351 };
6352
6353 static void
6354 cmd_read_reg_bit_parsed(void *parsed_result,
6355                         __attribute__((unused)) struct cmdline *cl,
6356                         __attribute__((unused)) void *data)
6357 {
6358         struct cmd_read_reg_bit_result *res = parsed_result;
6359         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6360 }
6361
6362 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6363         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6364 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6365         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6366                                  regbit, "regbit");
6367 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6368         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
6369 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6370         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6371 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6372         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6373
6374 cmdline_parse_inst_t cmd_read_reg_bit = {
6375         .f = cmd_read_reg_bit_parsed,
6376         .data = NULL,
6377         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6378         .tokens = {
6379                 (void *)&cmd_read_reg_bit_read,
6380                 (void *)&cmd_read_reg_bit_regbit,
6381                 (void *)&cmd_read_reg_bit_port_id,
6382                 (void *)&cmd_read_reg_bit_reg_off,
6383                 (void *)&cmd_read_reg_bit_bit_pos,
6384                 NULL,
6385         },
6386 };
6387
6388 /* *** WRITE PORT REGISTER *** */
6389 struct cmd_write_reg_result {
6390         cmdline_fixed_string_t write;
6391         cmdline_fixed_string_t reg;
6392         uint8_t port_id;
6393         uint32_t reg_off;
6394         uint32_t value;
6395 };
6396
6397 static void
6398 cmd_write_reg_parsed(void *parsed_result,
6399                      __attribute__((unused)) struct cmdline *cl,
6400                      __attribute__((unused)) void *data)
6401 {
6402         struct cmd_write_reg_result *res = parsed_result;
6403         port_reg_set(res->port_id, res->reg_off, res->value);
6404 }
6405
6406 cmdline_parse_token_string_t cmd_write_reg_write =
6407         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6408 cmdline_parse_token_string_t cmd_write_reg_reg =
6409         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6410 cmdline_parse_token_num_t cmd_write_reg_port_id =
6411         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
6412 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6413         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6414 cmdline_parse_token_num_t cmd_write_reg_value =
6415         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6416
6417 cmdline_parse_inst_t cmd_write_reg = {
6418         .f = cmd_write_reg_parsed,
6419         .data = NULL,
6420         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6421         .tokens = {
6422                 (void *)&cmd_write_reg_write,
6423                 (void *)&cmd_write_reg_reg,
6424                 (void *)&cmd_write_reg_port_id,
6425                 (void *)&cmd_write_reg_reg_off,
6426                 (void *)&cmd_write_reg_value,
6427                 NULL,
6428         },
6429 };
6430
6431 /* *** WRITE PORT REGISTER BIT FIELD *** */
6432 struct cmd_write_reg_bit_field_result {
6433         cmdline_fixed_string_t write;
6434         cmdline_fixed_string_t regfield;
6435         uint8_t port_id;
6436         uint32_t reg_off;
6437         uint8_t bit1_pos;
6438         uint8_t bit2_pos;
6439         uint32_t value;
6440 };
6441
6442 static void
6443 cmd_write_reg_bit_field_parsed(void *parsed_result,
6444                                __attribute__((unused)) struct cmdline *cl,
6445                                __attribute__((unused)) void *data)
6446 {
6447         struct cmd_write_reg_bit_field_result *res = parsed_result;
6448         port_reg_bit_field_set(res->port_id, res->reg_off,
6449                           res->bit1_pos, res->bit2_pos, res->value);
6450 }
6451
6452 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6453         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6454                                  "write");
6455 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6456         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6457                                  regfield, "regfield");
6458 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6459         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6460                               UINT8);
6461 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6462         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6463                               UINT32);
6464 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6465         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6466                               UINT8);
6467 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6468         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6469                               UINT8);
6470 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6471         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6472                               UINT32);
6473
6474 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6475         .f = cmd_write_reg_bit_field_parsed,
6476         .data = NULL,
6477         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6478                 "<reg_value>: "
6479                 "Set register bit field between bit_x and bit_y included",
6480         .tokens = {
6481                 (void *)&cmd_write_reg_bit_field_write,
6482                 (void *)&cmd_write_reg_bit_field_regfield,
6483                 (void *)&cmd_write_reg_bit_field_port_id,
6484                 (void *)&cmd_write_reg_bit_field_reg_off,
6485                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6486                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6487                 (void *)&cmd_write_reg_bit_field_value,
6488                 NULL,
6489         },
6490 };
6491
6492 /* *** WRITE PORT REGISTER BIT *** */
6493 struct cmd_write_reg_bit_result {
6494         cmdline_fixed_string_t write;
6495         cmdline_fixed_string_t regbit;
6496         uint8_t port_id;
6497         uint32_t reg_off;
6498         uint8_t bit_pos;
6499         uint8_t value;
6500 };
6501
6502 static void
6503 cmd_write_reg_bit_parsed(void *parsed_result,
6504                          __attribute__((unused)) struct cmdline *cl,
6505                          __attribute__((unused)) void *data)
6506 {
6507         struct cmd_write_reg_bit_result *res = parsed_result;
6508         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6509 }
6510
6511 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6512         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6513                                  "write");
6514 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6515         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6516                                  regbit, "regbit");
6517 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6518         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
6519 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6520         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6521 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6522         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6523 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6524         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6525
6526 cmdline_parse_inst_t cmd_write_reg_bit = {
6527         .f = cmd_write_reg_bit_parsed,
6528         .data = NULL,
6529         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6530                 "0 <= bit_x <= 31",
6531         .tokens = {
6532                 (void *)&cmd_write_reg_bit_write,
6533                 (void *)&cmd_write_reg_bit_regbit,
6534                 (void *)&cmd_write_reg_bit_port_id,
6535                 (void *)&cmd_write_reg_bit_reg_off,
6536                 (void *)&cmd_write_reg_bit_bit_pos,
6537                 (void *)&cmd_write_reg_bit_value,
6538                 NULL,
6539         },
6540 };
6541
6542 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6543 struct cmd_read_rxd_txd_result {
6544         cmdline_fixed_string_t read;
6545         cmdline_fixed_string_t rxd_txd;
6546         uint8_t port_id;
6547         uint16_t queue_id;
6548         uint16_t desc_id;
6549 };
6550
6551 static void
6552 cmd_read_rxd_txd_parsed(void *parsed_result,
6553                         __attribute__((unused)) struct cmdline *cl,
6554                         __attribute__((unused)) void *data)
6555 {
6556         struct cmd_read_rxd_txd_result *res = parsed_result;
6557
6558         if (!strcmp(res->rxd_txd, "rxd"))
6559                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6560         else if (!strcmp(res->rxd_txd, "txd"))
6561                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6562 }
6563
6564 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6565         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6566 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6567         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6568                                  "rxd#txd");
6569 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6570         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
6571 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6572         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6573 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6574         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6575
6576 cmdline_parse_inst_t cmd_read_rxd_txd = {
6577         .f = cmd_read_rxd_txd_parsed,
6578         .data = NULL,
6579         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6580         .tokens = {
6581                 (void *)&cmd_read_rxd_txd_read,
6582                 (void *)&cmd_read_rxd_txd_rxd_txd,
6583                 (void *)&cmd_read_rxd_txd_port_id,
6584                 (void *)&cmd_read_rxd_txd_queue_id,
6585                 (void *)&cmd_read_rxd_txd_desc_id,
6586                 NULL,
6587         },
6588 };
6589
6590 /* *** QUIT *** */
6591 struct cmd_quit_result {
6592         cmdline_fixed_string_t quit;
6593 };
6594
6595 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6596                             struct cmdline *cl,
6597                             __attribute__((unused)) void *data)
6598 {
6599         pmd_test_exit();
6600         cmdline_quit(cl);
6601 }
6602
6603 cmdline_parse_token_string_t cmd_quit_quit =
6604         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6605
6606 cmdline_parse_inst_t cmd_quit = {
6607         .f = cmd_quit_parsed,
6608         .data = NULL,
6609         .help_str = "quit: Exit application",
6610         .tokens = {
6611                 (void *)&cmd_quit_quit,
6612                 NULL,
6613         },
6614 };
6615
6616 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
6617 struct cmd_mac_addr_result {
6618         cmdline_fixed_string_t mac_addr_cmd;
6619         cmdline_fixed_string_t what;
6620         uint8_t port_num;
6621         struct ether_addr address;
6622 };
6623
6624 static void cmd_mac_addr_parsed(void *parsed_result,
6625                 __attribute__((unused)) struct cmdline *cl,
6626                 __attribute__((unused)) void *data)
6627 {
6628         struct cmd_mac_addr_result *res = parsed_result;
6629         int ret;
6630
6631         if (strcmp(res->what, "add") == 0)
6632                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
6633         else if (strcmp(res->what, "set") == 0)
6634                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
6635                                                        &res->address);
6636         else
6637                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
6638
6639         /* check the return value and print it if is < 0 */
6640         if(ret < 0)
6641                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
6642
6643 }
6644
6645 cmdline_parse_token_string_t cmd_mac_addr_cmd =
6646         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
6647                                 "mac_addr");
6648 cmdline_parse_token_string_t cmd_mac_addr_what =
6649         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
6650                                 "add#remove#set");
6651 cmdline_parse_token_num_t cmd_mac_addr_portnum =
6652                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
6653 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
6654                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
6655
6656 cmdline_parse_inst_t cmd_mac_addr = {
6657         .f = cmd_mac_addr_parsed,
6658         .data = (void *)0,
6659         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
6660                         "Add/Remove/Set MAC address on port_id",
6661         .tokens = {
6662                 (void *)&cmd_mac_addr_cmd,
6663                 (void *)&cmd_mac_addr_what,
6664                 (void *)&cmd_mac_addr_portnum,
6665                 (void *)&cmd_mac_addr_addr,
6666                 NULL,
6667         },
6668 };
6669
6670
6671 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
6672 struct cmd_set_qmap_result {
6673         cmdline_fixed_string_t set;
6674         cmdline_fixed_string_t qmap;
6675         cmdline_fixed_string_t what;
6676         uint8_t port_id;
6677         uint16_t queue_id;
6678         uint8_t map_value;
6679 };
6680
6681 static void
6682 cmd_set_qmap_parsed(void *parsed_result,
6683                        __attribute__((unused)) struct cmdline *cl,
6684                        __attribute__((unused)) void *data)
6685 {
6686         struct cmd_set_qmap_result *res = parsed_result;
6687         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
6688
6689         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
6690 }
6691
6692 cmdline_parse_token_string_t cmd_setqmap_set =
6693         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6694                                  set, "set");
6695 cmdline_parse_token_string_t cmd_setqmap_qmap =
6696         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6697                                  qmap, "stat_qmap");
6698 cmdline_parse_token_string_t cmd_setqmap_what =
6699         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6700                                  what, "tx#rx");
6701 cmdline_parse_token_num_t cmd_setqmap_portid =
6702         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6703                               port_id, UINT8);
6704 cmdline_parse_token_num_t cmd_setqmap_queueid =
6705         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6706                               queue_id, UINT16);
6707 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
6708         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6709                               map_value, UINT8);
6710
6711 cmdline_parse_inst_t cmd_set_qmap = {
6712         .f = cmd_set_qmap_parsed,
6713         .data = NULL,
6714         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
6715                 "Set statistics mapping value on tx|rx queue_id of port_id",
6716         .tokens = {
6717                 (void *)&cmd_setqmap_set,
6718                 (void *)&cmd_setqmap_qmap,
6719                 (void *)&cmd_setqmap_what,
6720                 (void *)&cmd_setqmap_portid,
6721                 (void *)&cmd_setqmap_queueid,
6722                 (void *)&cmd_setqmap_mapvalue,
6723                 NULL,
6724         },
6725 };
6726
6727 /* *** CONFIGURE UNICAST HASH TABLE *** */
6728 struct cmd_set_uc_hash_table {
6729         cmdline_fixed_string_t set;
6730         cmdline_fixed_string_t port;
6731         uint8_t port_id;
6732         cmdline_fixed_string_t what;
6733         struct ether_addr address;
6734         cmdline_fixed_string_t mode;
6735 };
6736
6737 static void
6738 cmd_set_uc_hash_parsed(void *parsed_result,
6739                        __attribute__((unused)) struct cmdline *cl,
6740                        __attribute__((unused)) void *data)
6741 {
6742         int ret=0;
6743         struct cmd_set_uc_hash_table *res = parsed_result;
6744
6745         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6746
6747         if (strcmp(res->what, "uta") == 0)
6748                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
6749                                                 &res->address,(uint8_t)is_on);
6750         if (ret < 0)
6751                 printf("bad unicast hash table parameter, return code = %d \n", ret);
6752
6753 }
6754
6755 cmdline_parse_token_string_t cmd_set_uc_hash_set =
6756         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6757                                  set, "set");
6758 cmdline_parse_token_string_t cmd_set_uc_hash_port =
6759         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6760                                  port, "port");
6761 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
6762         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
6763                               port_id, UINT8);
6764 cmdline_parse_token_string_t cmd_set_uc_hash_what =
6765         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6766                                  what, "uta");
6767 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
6768         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
6769                                 address);
6770 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
6771         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6772                                  mode, "on#off");
6773
6774 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
6775         .f = cmd_set_uc_hash_parsed,
6776         .data = NULL,
6777         .help_str = "set port <port_id> uta <mac_addr> on|off)",
6778         .tokens = {
6779                 (void *)&cmd_set_uc_hash_set,
6780                 (void *)&cmd_set_uc_hash_port,
6781                 (void *)&cmd_set_uc_hash_portid,
6782                 (void *)&cmd_set_uc_hash_what,
6783                 (void *)&cmd_set_uc_hash_mac,
6784                 (void *)&cmd_set_uc_hash_mode,
6785                 NULL,
6786         },
6787 };
6788
6789 struct cmd_set_uc_all_hash_table {
6790         cmdline_fixed_string_t set;
6791         cmdline_fixed_string_t port;
6792         uint8_t port_id;
6793         cmdline_fixed_string_t what;
6794         cmdline_fixed_string_t value;
6795         cmdline_fixed_string_t mode;
6796 };
6797
6798 static void
6799 cmd_set_uc_all_hash_parsed(void *parsed_result,
6800                        __attribute__((unused)) struct cmdline *cl,
6801                        __attribute__((unused)) void *data)
6802 {
6803         int ret=0;
6804         struct cmd_set_uc_all_hash_table *res = parsed_result;
6805
6806         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6807
6808         if ((strcmp(res->what, "uta") == 0) &&
6809                 (strcmp(res->value, "all") == 0))
6810                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
6811         if (ret < 0)
6812                 printf("bad unicast hash table parameter,"
6813                         "return code = %d \n", ret);
6814 }
6815
6816 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
6817         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6818                                  set, "set");
6819 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
6820         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6821                                  port, "port");
6822 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
6823         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
6824                               port_id, UINT8);
6825 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
6826         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6827                                  what, "uta");
6828 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
6829         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6830                                 value,"all");
6831 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
6832         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6833                                  mode, "on#off");
6834
6835 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
6836         .f = cmd_set_uc_all_hash_parsed,
6837         .data = NULL,
6838         .help_str = "set port <port_id> uta all on|off",
6839         .tokens = {
6840                 (void *)&cmd_set_uc_all_hash_set,
6841                 (void *)&cmd_set_uc_all_hash_port,
6842                 (void *)&cmd_set_uc_all_hash_portid,
6843                 (void *)&cmd_set_uc_all_hash_what,
6844                 (void *)&cmd_set_uc_all_hash_value,
6845                 (void *)&cmd_set_uc_all_hash_mode,
6846                 NULL,
6847         },
6848 };
6849
6850 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
6851 struct cmd_set_vf_macvlan_filter {
6852         cmdline_fixed_string_t set;
6853         cmdline_fixed_string_t port;
6854         uint8_t port_id;
6855         cmdline_fixed_string_t vf;
6856         uint8_t vf_id;
6857         struct ether_addr address;
6858         cmdline_fixed_string_t filter_type;
6859         cmdline_fixed_string_t mode;
6860 };
6861
6862 static void
6863 cmd_set_vf_macvlan_parsed(void *parsed_result,
6864                        __attribute__((unused)) struct cmdline *cl,
6865                        __attribute__((unused)) void *data)
6866 {
6867         int is_on, ret = 0;
6868         struct cmd_set_vf_macvlan_filter *res = parsed_result;
6869         struct rte_eth_mac_filter filter;
6870
6871         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
6872
6873         (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
6874
6875         /* set VF MAC filter */
6876         filter.is_vf = 1;
6877
6878         /* set VF ID */
6879         filter.dst_id = res->vf_id;
6880
6881         if (!strcmp(res->filter_type, "exact-mac"))
6882                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
6883         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
6884                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
6885         else if (!strcmp(res->filter_type, "hashmac"))
6886                 filter.filter_type = RTE_MAC_HASH_MATCH;
6887         else if (!strcmp(res->filter_type, "hashmac-vlan"))
6888                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
6889
6890         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6891
6892         if (is_on)
6893                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6894                                         RTE_ETH_FILTER_MACVLAN,
6895                                         RTE_ETH_FILTER_ADD,
6896                                          &filter);
6897         else
6898                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6899                                         RTE_ETH_FILTER_MACVLAN,
6900                                         RTE_ETH_FILTER_DELETE,
6901                                         &filter);
6902
6903         if (ret < 0)
6904                 printf("bad set MAC hash parameter, return code = %d\n", ret);
6905
6906 }
6907
6908 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
6909         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6910                                  set, "set");
6911 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
6912         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6913                                  port, "port");
6914 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
6915         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6916                               port_id, UINT8);
6917 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
6918         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6919                                  vf, "vf");
6920 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
6921         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6922                                 vf_id, UINT8);
6923 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
6924         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6925                                 address);
6926 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
6927         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6928                                 filter_type, "exact-mac#exact-mac-vlan"
6929                                 "#hashmac#hashmac-vlan");
6930 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
6931         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6932                                  mode, "on#off");
6933
6934 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
6935         .f = cmd_set_vf_macvlan_parsed,
6936         .data = NULL,
6937         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
6938                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
6939                 "Exact match rule: exact match of MAC or MAC and VLAN; "
6940                 "hash match rule: hash match of MAC and exact match of VLAN",
6941         .tokens = {
6942                 (void *)&cmd_set_vf_macvlan_set,
6943                 (void *)&cmd_set_vf_macvlan_port,
6944                 (void *)&cmd_set_vf_macvlan_portid,
6945                 (void *)&cmd_set_vf_macvlan_vf,
6946                 (void *)&cmd_set_vf_macvlan_vf_id,
6947                 (void *)&cmd_set_vf_macvlan_mac,
6948                 (void *)&cmd_set_vf_macvlan_filter_type,
6949                 (void *)&cmd_set_vf_macvlan_mode,
6950                 NULL,
6951         },
6952 };
6953
6954 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
6955 struct cmd_set_vf_traffic {
6956         cmdline_fixed_string_t set;
6957         cmdline_fixed_string_t port;
6958         uint8_t port_id;
6959         cmdline_fixed_string_t vf;
6960         uint8_t vf_id;
6961         cmdline_fixed_string_t what;
6962         cmdline_fixed_string_t mode;
6963 };
6964
6965 static void
6966 cmd_set_vf_traffic_parsed(void *parsed_result,
6967                        __attribute__((unused)) struct cmdline *cl,
6968                        __attribute__((unused)) void *data)
6969 {
6970         struct cmd_set_vf_traffic *res = parsed_result;
6971         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
6972         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6973
6974         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
6975 }
6976
6977 cmdline_parse_token_string_t cmd_setvf_traffic_set =
6978         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6979                                  set, "set");
6980 cmdline_parse_token_string_t cmd_setvf_traffic_port =
6981         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6982                                  port, "port");
6983 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
6984         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6985                               port_id, UINT8);
6986 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
6987         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6988                                  vf, "vf");
6989 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
6990         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6991                               vf_id, UINT8);
6992 cmdline_parse_token_string_t cmd_setvf_traffic_what =
6993         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6994                                  what, "tx#rx");
6995 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
6996         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6997                                  mode, "on#off");
6998
6999 cmdline_parse_inst_t cmd_set_vf_traffic = {
7000         .f = cmd_set_vf_traffic_parsed,
7001         .data = NULL,
7002         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7003         .tokens = {
7004                 (void *)&cmd_setvf_traffic_set,
7005                 (void *)&cmd_setvf_traffic_port,
7006                 (void *)&cmd_setvf_traffic_portid,
7007                 (void *)&cmd_setvf_traffic_vf,
7008                 (void *)&cmd_setvf_traffic_vfid,
7009                 (void *)&cmd_setvf_traffic_what,
7010                 (void *)&cmd_setvf_traffic_mode,
7011                 NULL,
7012         },
7013 };
7014
7015 /* *** CONFIGURE VF RECEIVE MODE *** */
7016 struct cmd_set_vf_rxmode {
7017         cmdline_fixed_string_t set;
7018         cmdline_fixed_string_t port;
7019         uint8_t port_id;
7020         cmdline_fixed_string_t vf;
7021         uint8_t vf_id;
7022         cmdline_fixed_string_t what;
7023         cmdline_fixed_string_t mode;
7024         cmdline_fixed_string_t on;
7025 };
7026
7027 static void
7028 cmd_set_vf_rxmode_parsed(void *parsed_result,
7029                        __attribute__((unused)) struct cmdline *cl,
7030                        __attribute__((unused)) void *data)
7031 {
7032         int ret = -ENOTSUP;
7033         uint16_t rx_mode = 0;
7034         struct cmd_set_vf_rxmode *res = parsed_result;
7035
7036         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7037         if (!strcmp(res->what,"rxmode")) {
7038                 if (!strcmp(res->mode, "AUPE"))
7039                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7040                 else if (!strcmp(res->mode, "ROPE"))
7041                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7042                 else if (!strcmp(res->mode, "BAM"))
7043                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7044                 else if (!strncmp(res->mode, "MPE",3))
7045                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7046         }
7047
7048 #ifdef RTE_LIBRTE_IXGBE_PMD
7049         if (ret == -ENOTSUP)
7050                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7051                                                   rx_mode, (uint8_t)is_on);
7052 #endif
7053 #ifdef RTE_LIBRTE_BNXT_PMD
7054         if (ret == -ENOTSUP)
7055                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7056                                                  rx_mode, (uint8_t)is_on);
7057 #endif
7058         if (ret < 0)
7059                 printf("bad VF receive mode parameter, return code = %d \n",
7060                 ret);
7061 }
7062
7063 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7064         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7065                                  set, "set");
7066 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7067         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7068                                  port, "port");
7069 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7070         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7071                               port_id, UINT8);
7072 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7073         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7074                                  vf, "vf");
7075 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7076         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7077                               vf_id, UINT8);
7078 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7079         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7080                                  what, "rxmode");
7081 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7082         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7083                                  mode, "AUPE#ROPE#BAM#MPE");
7084 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7085         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7086                                  on, "on#off");
7087
7088 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7089         .f = cmd_set_vf_rxmode_parsed,
7090         .data = NULL,
7091         .help_str = "set port <port_id> vf <vf_id> rxmode "
7092                 "AUPE|ROPE|BAM|MPE on|off",
7093         .tokens = {
7094                 (void *)&cmd_set_vf_rxmode_set,
7095                 (void *)&cmd_set_vf_rxmode_port,
7096                 (void *)&cmd_set_vf_rxmode_portid,
7097                 (void *)&cmd_set_vf_rxmode_vf,
7098                 (void *)&cmd_set_vf_rxmode_vfid,
7099                 (void *)&cmd_set_vf_rxmode_what,
7100                 (void *)&cmd_set_vf_rxmode_mode,
7101                 (void *)&cmd_set_vf_rxmode_on,
7102                 NULL,
7103         },
7104 };
7105
7106 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7107 struct cmd_vf_mac_addr_result {
7108         cmdline_fixed_string_t mac_addr_cmd;
7109         cmdline_fixed_string_t what;
7110         cmdline_fixed_string_t port;
7111         uint8_t port_num;
7112         cmdline_fixed_string_t vf;
7113         uint8_t vf_num;
7114         struct ether_addr address;
7115 };
7116
7117 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7118                 __attribute__((unused)) struct cmdline *cl,
7119                 __attribute__((unused)) void *data)
7120 {
7121         struct cmd_vf_mac_addr_result *res = parsed_result;
7122         int ret = 0;
7123
7124         if (strcmp(res->what, "add") == 0)
7125                 ret = rte_eth_dev_mac_addr_add(res->port_num,
7126                                         &res->address, res->vf_num);
7127         if(ret < 0)
7128                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7129
7130 }
7131
7132 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7133         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7134                                 mac_addr_cmd,"mac_addr");
7135 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7136         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7137                                 what,"add");
7138 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7139         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7140                                 port,"port");
7141 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7142         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7143                                 port_num, UINT8);
7144 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7145         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7146                                 vf,"vf");
7147 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7148         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7149                                 vf_num, UINT8);
7150 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7151         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7152                                 address);
7153
7154 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7155         .f = cmd_vf_mac_addr_parsed,
7156         .data = (void *)0,
7157         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7158                 "Add MAC address filtering for a VF on port_id",
7159         .tokens = {
7160                 (void *)&cmd_vf_mac_addr_cmd,
7161                 (void *)&cmd_vf_mac_addr_what,
7162                 (void *)&cmd_vf_mac_addr_port,
7163                 (void *)&cmd_vf_mac_addr_portnum,
7164                 (void *)&cmd_vf_mac_addr_vf,
7165                 (void *)&cmd_vf_mac_addr_vfnum,
7166                 (void *)&cmd_vf_mac_addr_addr,
7167                 NULL,
7168         },
7169 };
7170
7171 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7172 struct cmd_vf_rx_vlan_filter {
7173         cmdline_fixed_string_t rx_vlan;
7174         cmdline_fixed_string_t what;
7175         uint16_t vlan_id;
7176         cmdline_fixed_string_t port;
7177         uint8_t port_id;
7178         cmdline_fixed_string_t vf;
7179         uint64_t vf_mask;
7180 };
7181
7182 static void
7183 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7184                           __attribute__((unused)) struct cmdline *cl,
7185                           __attribute__((unused)) void *data)
7186 {
7187         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7188         int ret = -ENOTSUP;
7189
7190         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7191
7192 #ifdef RTE_LIBRTE_IXGBE_PMD
7193         if (ret == -ENOTSUP)
7194                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7195                                 res->vlan_id, res->vf_mask, is_add);
7196 #endif
7197 #ifdef RTE_LIBRTE_I40E_PMD
7198         if (ret == -ENOTSUP)
7199                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7200                                 res->vlan_id, res->vf_mask, is_add);
7201 #endif
7202 #ifdef RTE_LIBRTE_BNXT_PMD
7203         if (ret == -ENOTSUP)
7204                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7205                                 res->vlan_id, res->vf_mask, is_add);
7206 #endif
7207
7208         switch (ret) {
7209         case 0:
7210                 break;
7211         case -EINVAL:
7212                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7213                                 res->vlan_id, res->vf_mask);
7214                 break;
7215         case -ENODEV:
7216                 printf("invalid port_id %d\n", res->port_id);
7217                 break;
7218         case -ENOTSUP:
7219                 printf("function not implemented or supported\n");
7220                 break;
7221         default:
7222                 printf("programming error: (%s)\n", strerror(-ret));
7223         }
7224 }
7225
7226 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7227         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7228                                  rx_vlan, "rx_vlan");
7229 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7230         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7231                                  what, "add#rm");
7232 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7233         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7234                               vlan_id, UINT16);
7235 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7236         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7237                                  port, "port");
7238 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7239         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7240                               port_id, UINT8);
7241 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7242         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7243                                  vf, "vf");
7244 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7245         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7246                               vf_mask, UINT64);
7247
7248 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7249         .f = cmd_vf_rx_vlan_filter_parsed,
7250         .data = NULL,
7251         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7252                 "(vf_mask = hexadecimal VF mask)",
7253         .tokens = {
7254                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7255                 (void *)&cmd_vf_rx_vlan_filter_what,
7256                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7257                 (void *)&cmd_vf_rx_vlan_filter_port,
7258                 (void *)&cmd_vf_rx_vlan_filter_portid,
7259                 (void *)&cmd_vf_rx_vlan_filter_vf,
7260                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7261                 NULL,
7262         },
7263 };
7264
7265 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7266 struct cmd_queue_rate_limit_result {
7267         cmdline_fixed_string_t set;
7268         cmdline_fixed_string_t port;
7269         uint8_t port_num;
7270         cmdline_fixed_string_t queue;
7271         uint8_t queue_num;
7272         cmdline_fixed_string_t rate;
7273         uint16_t rate_num;
7274 };
7275
7276 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7277                 __attribute__((unused)) struct cmdline *cl,
7278                 __attribute__((unused)) void *data)
7279 {
7280         struct cmd_queue_rate_limit_result *res = parsed_result;
7281         int ret = 0;
7282
7283         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7284                 && (strcmp(res->queue, "queue") == 0)
7285                 && (strcmp(res->rate, "rate") == 0))
7286                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7287                                         res->rate_num);
7288         if (ret < 0)
7289                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7290
7291 }
7292
7293 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7294         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7295                                 set, "set");
7296 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7297         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7298                                 port, "port");
7299 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7300         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7301                                 port_num, UINT8);
7302 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7303         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7304                                 queue, "queue");
7305 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7306         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7307                                 queue_num, UINT8);
7308 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7309         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7310                                 rate, "rate");
7311 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7312         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7313                                 rate_num, UINT16);
7314
7315 cmdline_parse_inst_t cmd_queue_rate_limit = {
7316         .f = cmd_queue_rate_limit_parsed,
7317         .data = (void *)0,
7318         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7319                 "Set rate limit for a queue on port_id",
7320         .tokens = {
7321                 (void *)&cmd_queue_rate_limit_set,
7322                 (void *)&cmd_queue_rate_limit_port,
7323                 (void *)&cmd_queue_rate_limit_portnum,
7324                 (void *)&cmd_queue_rate_limit_queue,
7325                 (void *)&cmd_queue_rate_limit_queuenum,
7326                 (void *)&cmd_queue_rate_limit_rate,
7327                 (void *)&cmd_queue_rate_limit_ratenum,
7328                 NULL,
7329         },
7330 };
7331
7332 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7333 struct cmd_vf_rate_limit_result {
7334         cmdline_fixed_string_t set;
7335         cmdline_fixed_string_t port;
7336         uint8_t port_num;
7337         cmdline_fixed_string_t vf;
7338         uint8_t vf_num;
7339         cmdline_fixed_string_t rate;
7340         uint16_t rate_num;
7341         cmdline_fixed_string_t q_msk;
7342         uint64_t q_msk_val;
7343 };
7344
7345 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7346                 __attribute__((unused)) struct cmdline *cl,
7347                 __attribute__((unused)) void *data)
7348 {
7349         struct cmd_vf_rate_limit_result *res = parsed_result;
7350         int ret = 0;
7351
7352         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7353                 && (strcmp(res->vf, "vf") == 0)
7354                 && (strcmp(res->rate, "rate") == 0)
7355                 && (strcmp(res->q_msk, "queue_mask") == 0))
7356                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7357                                         res->rate_num, res->q_msk_val);
7358         if (ret < 0)
7359                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7360
7361 }
7362
7363 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7364         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7365                                 set, "set");
7366 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7367         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7368                                 port, "port");
7369 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7370         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7371                                 port_num, UINT8);
7372 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7373         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7374                                 vf, "vf");
7375 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7376         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7377                                 vf_num, UINT8);
7378 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7379         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7380                                 rate, "rate");
7381 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7382         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7383                                 rate_num, UINT16);
7384 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7385         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7386                                 q_msk, "queue_mask");
7387 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7388         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7389                                 q_msk_val, UINT64);
7390
7391 cmdline_parse_inst_t cmd_vf_rate_limit = {
7392         .f = cmd_vf_rate_limit_parsed,
7393         .data = (void *)0,
7394         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7395                 "queue_mask <queue_mask_value>: "
7396                 "Set rate limit for queues of VF on port_id",
7397         .tokens = {
7398                 (void *)&cmd_vf_rate_limit_set,
7399                 (void *)&cmd_vf_rate_limit_port,
7400                 (void *)&cmd_vf_rate_limit_portnum,
7401                 (void *)&cmd_vf_rate_limit_vf,
7402                 (void *)&cmd_vf_rate_limit_vfnum,
7403                 (void *)&cmd_vf_rate_limit_rate,
7404                 (void *)&cmd_vf_rate_limit_ratenum,
7405                 (void *)&cmd_vf_rate_limit_q_msk,
7406                 (void *)&cmd_vf_rate_limit_q_msk_val,
7407                 NULL,
7408         },
7409 };
7410
7411 /* *** ADD TUNNEL FILTER OF A PORT *** */
7412 struct cmd_tunnel_filter_result {
7413         cmdline_fixed_string_t cmd;
7414         cmdline_fixed_string_t what;
7415         uint8_t port_id;
7416         struct ether_addr outer_mac;
7417         struct ether_addr inner_mac;
7418         cmdline_ipaddr_t ip_value;
7419         uint16_t inner_vlan;
7420         cmdline_fixed_string_t tunnel_type;
7421         cmdline_fixed_string_t filter_type;
7422         uint32_t tenant_id;
7423         uint16_t queue_num;
7424 };
7425
7426 static void
7427 cmd_tunnel_filter_parsed(void *parsed_result,
7428                           __attribute__((unused)) struct cmdline *cl,
7429                           __attribute__((unused)) void *data)
7430 {
7431         struct cmd_tunnel_filter_result *res = parsed_result;
7432         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7433         int ret = 0;
7434
7435         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7436
7437         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7438         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7439         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7440
7441         if (res->ip_value.family == AF_INET) {
7442                 tunnel_filter_conf.ip_addr.ipv4_addr =
7443                         res->ip_value.addr.ipv4.s_addr;
7444                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7445         } else {
7446                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7447                         &(res->ip_value.addr.ipv6),
7448                         sizeof(struct in6_addr));
7449                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7450         }
7451
7452         if (!strcmp(res->filter_type, "imac-ivlan"))
7453                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7454         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7455                 tunnel_filter_conf.filter_type =
7456                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7457         else if (!strcmp(res->filter_type, "imac-tenid"))
7458                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7459         else if (!strcmp(res->filter_type, "imac"))
7460                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7461         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7462                 tunnel_filter_conf.filter_type =
7463                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7464         else if (!strcmp(res->filter_type, "oip"))
7465                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7466         else if (!strcmp(res->filter_type, "iip"))
7467                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7468         else {
7469                 printf("The filter type is not supported");
7470                 return;
7471         }
7472
7473         if (!strcmp(res->tunnel_type, "vxlan"))
7474                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7475         else if (!strcmp(res->tunnel_type, "nvgre"))
7476                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7477         else if (!strcmp(res->tunnel_type, "ipingre"))
7478                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7479         else {
7480                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7481                 return;
7482         }
7483
7484         tunnel_filter_conf.tenant_id = res->tenant_id;
7485         tunnel_filter_conf.queue_id = res->queue_num;
7486         if (!strcmp(res->what, "add"))
7487                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7488                                         RTE_ETH_FILTER_TUNNEL,
7489                                         RTE_ETH_FILTER_ADD,
7490                                         &tunnel_filter_conf);
7491         else
7492                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7493                                         RTE_ETH_FILTER_TUNNEL,
7494                                         RTE_ETH_FILTER_DELETE,
7495                                         &tunnel_filter_conf);
7496         if (ret < 0)
7497                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7498                                 strerror(-ret));
7499
7500 }
7501 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7502         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7503         cmd, "tunnel_filter");
7504 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7505         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7506         what, "add#rm");
7507 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7508         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7509         port_id, UINT8);
7510 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7511         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7512         outer_mac);
7513 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7514         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7515         inner_mac);
7516 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7517         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7518         inner_vlan, UINT16);
7519 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7520         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7521         ip_value);
7522 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7523         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7524         tunnel_type, "vxlan#nvgre#ipingre");
7525
7526 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7527         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7528         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7529                 "imac#omac-imac-tenid");
7530 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7531         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7532         tenant_id, UINT32);
7533 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7534         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7535         queue_num, UINT16);
7536
7537 cmdline_parse_inst_t cmd_tunnel_filter = {
7538         .f = cmd_tunnel_filter_parsed,
7539         .data = (void *)0,
7540         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7541                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7542                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7543                 "<queue_id>: Add/Rm tunnel filter of a port",
7544         .tokens = {
7545                 (void *)&cmd_tunnel_filter_cmd,
7546                 (void *)&cmd_tunnel_filter_what,
7547                 (void *)&cmd_tunnel_filter_port_id,
7548                 (void *)&cmd_tunnel_filter_outer_mac,
7549                 (void *)&cmd_tunnel_filter_inner_mac,
7550                 (void *)&cmd_tunnel_filter_ip_value,
7551                 (void *)&cmd_tunnel_filter_innner_vlan,
7552                 (void *)&cmd_tunnel_filter_tunnel_type,
7553                 (void *)&cmd_tunnel_filter_filter_type,
7554                 (void *)&cmd_tunnel_filter_tenant_id,
7555                 (void *)&cmd_tunnel_filter_queue_num,
7556                 NULL,
7557         },
7558 };
7559
7560 /* *** CONFIGURE TUNNEL UDP PORT *** */
7561 struct cmd_tunnel_udp_config {
7562         cmdline_fixed_string_t cmd;
7563         cmdline_fixed_string_t what;
7564         uint16_t udp_port;
7565         uint8_t port_id;
7566 };
7567
7568 static void
7569 cmd_tunnel_udp_config_parsed(void *parsed_result,
7570                           __attribute__((unused)) struct cmdline *cl,
7571                           __attribute__((unused)) void *data)
7572 {
7573         struct cmd_tunnel_udp_config *res = parsed_result;
7574         struct rte_eth_udp_tunnel tunnel_udp;
7575         int ret;
7576
7577         tunnel_udp.udp_port = res->udp_port;
7578
7579         if (!strcmp(res->cmd, "rx_vxlan_port"))
7580                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7581
7582         if (!strcmp(res->what, "add"))
7583                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7584                                                       &tunnel_udp);
7585         else
7586                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7587                                                          &tunnel_udp);
7588
7589         if (ret < 0)
7590                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
7591 }
7592
7593 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7594         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7595                                 cmd, "rx_vxlan_port");
7596 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7597         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7598                                 what, "add#rm");
7599 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7600         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7601                                 udp_port, UINT16);
7602 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7603         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7604                                 port_id, UINT8);
7605
7606 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7607         .f = cmd_tunnel_udp_config_parsed,
7608         .data = (void *)0,
7609         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
7610                 "Add/Remove a tunneling UDP port filter",
7611         .tokens = {
7612                 (void *)&cmd_tunnel_udp_config_cmd,
7613                 (void *)&cmd_tunnel_udp_config_what,
7614                 (void *)&cmd_tunnel_udp_config_udp_port,
7615                 (void *)&cmd_tunnel_udp_config_port_id,
7616                 NULL,
7617         },
7618 };
7619
7620 /* *** GLOBAL CONFIG *** */
7621 struct cmd_global_config_result {
7622         cmdline_fixed_string_t cmd;
7623         uint8_t port_id;
7624         cmdline_fixed_string_t cfg_type;
7625         uint8_t len;
7626 };
7627
7628 static void
7629 cmd_global_config_parsed(void *parsed_result,
7630                          __attribute__((unused)) struct cmdline *cl,
7631                          __attribute__((unused)) void *data)
7632 {
7633         struct cmd_global_config_result *res = parsed_result;
7634         struct rte_eth_global_cfg conf;
7635         int ret;
7636
7637         memset(&conf, 0, sizeof(conf));
7638         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
7639         conf.cfg.gre_key_len = res->len;
7640         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
7641                                       RTE_ETH_FILTER_SET, &conf);
7642         if (ret != 0)
7643                 printf("Global config error\n");
7644 }
7645
7646 cmdline_parse_token_string_t cmd_global_config_cmd =
7647         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
7648                 "global_config");
7649 cmdline_parse_token_num_t cmd_global_config_port_id =
7650         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
7651 cmdline_parse_token_string_t cmd_global_config_type =
7652         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
7653                 cfg_type, "gre-key-len");
7654 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
7655         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
7656                 len, UINT8);
7657
7658 cmdline_parse_inst_t cmd_global_config = {
7659         .f = cmd_global_config_parsed,
7660         .data = (void *)NULL,
7661         .help_str = "global_config <port_id> gre-key-len <key_len>",
7662         .tokens = {
7663                 (void *)&cmd_global_config_cmd,
7664                 (void *)&cmd_global_config_port_id,
7665                 (void *)&cmd_global_config_type,
7666                 (void *)&cmd_global_config_gre_key_len,
7667                 NULL,
7668         },
7669 };
7670
7671 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
7672 struct cmd_set_mirror_mask_result {
7673         cmdline_fixed_string_t set;
7674         cmdline_fixed_string_t port;
7675         uint8_t port_id;
7676         cmdline_fixed_string_t mirror;
7677         uint8_t rule_id;
7678         cmdline_fixed_string_t what;
7679         cmdline_fixed_string_t value;
7680         cmdline_fixed_string_t dstpool;
7681         uint8_t dstpool_id;
7682         cmdline_fixed_string_t on;
7683 };
7684
7685 cmdline_parse_token_string_t cmd_mirror_mask_set =
7686         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7687                                 set, "set");
7688 cmdline_parse_token_string_t cmd_mirror_mask_port =
7689         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7690                                 port, "port");
7691 cmdline_parse_token_num_t cmd_mirror_mask_portid =
7692         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7693                                 port_id, UINT8);
7694 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
7695         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7696                                 mirror, "mirror-rule");
7697 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
7698         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7699                                 rule_id, UINT8);
7700 cmdline_parse_token_string_t cmd_mirror_mask_what =
7701         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7702                                 what, "pool-mirror-up#pool-mirror-down"
7703                                       "#vlan-mirror");
7704 cmdline_parse_token_string_t cmd_mirror_mask_value =
7705         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7706                                 value, NULL);
7707 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
7708         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7709                                 dstpool, "dst-pool");
7710 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
7711         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7712                                 dstpool_id, UINT8);
7713 cmdline_parse_token_string_t cmd_mirror_mask_on =
7714         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7715                                 on, "on#off");
7716
7717 static void
7718 cmd_set_mirror_mask_parsed(void *parsed_result,
7719                        __attribute__((unused)) struct cmdline *cl,
7720                        __attribute__((unused)) void *data)
7721 {
7722         int ret,nb_item,i;
7723         struct cmd_set_mirror_mask_result *res = parsed_result;
7724         struct rte_eth_mirror_conf mr_conf;
7725
7726         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7727
7728         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
7729
7730         mr_conf.dst_pool = res->dstpool_id;
7731
7732         if (!strcmp(res->what, "pool-mirror-up")) {
7733                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7734                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
7735         } else if (!strcmp(res->what, "pool-mirror-down")) {
7736                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7737                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
7738         } else if (!strcmp(res->what, "vlan-mirror")) {
7739                 mr_conf.rule_type = ETH_MIRROR_VLAN;
7740                 nb_item = parse_item_list(res->value, "vlan",
7741                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
7742                 if (nb_item <= 0)
7743                         return;
7744
7745                 for (i = 0; i < nb_item; i++) {
7746                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
7747                                 printf("Invalid vlan_id: must be < 4096\n");
7748                                 return;
7749                         }
7750
7751                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
7752                         mr_conf.vlan.vlan_mask |= 1ULL << i;
7753                 }
7754         }
7755
7756         if (!strcmp(res->on, "on"))
7757                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7758                                                 res->rule_id, 1);
7759         else
7760                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7761                                                 res->rule_id, 0);
7762         if (ret < 0)
7763                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7764 }
7765
7766 cmdline_parse_inst_t cmd_set_mirror_mask = {
7767                 .f = cmd_set_mirror_mask_parsed,
7768                 .data = NULL,
7769                 .help_str = "set port <port_id> mirror-rule <rule_id> "
7770                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
7771                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
7772                 .tokens = {
7773                         (void *)&cmd_mirror_mask_set,
7774                         (void *)&cmd_mirror_mask_port,
7775                         (void *)&cmd_mirror_mask_portid,
7776                         (void *)&cmd_mirror_mask_mirror,
7777                         (void *)&cmd_mirror_mask_ruleid,
7778                         (void *)&cmd_mirror_mask_what,
7779                         (void *)&cmd_mirror_mask_value,
7780                         (void *)&cmd_mirror_mask_dstpool,
7781                         (void *)&cmd_mirror_mask_poolid,
7782                         (void *)&cmd_mirror_mask_on,
7783                         NULL,
7784                 },
7785 };
7786
7787 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
7788 struct cmd_set_mirror_link_result {
7789         cmdline_fixed_string_t set;
7790         cmdline_fixed_string_t port;
7791         uint8_t port_id;
7792         cmdline_fixed_string_t mirror;
7793         uint8_t rule_id;
7794         cmdline_fixed_string_t what;
7795         cmdline_fixed_string_t dstpool;
7796         uint8_t dstpool_id;
7797         cmdline_fixed_string_t on;
7798 };
7799
7800 cmdline_parse_token_string_t cmd_mirror_link_set =
7801         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7802                                  set, "set");
7803 cmdline_parse_token_string_t cmd_mirror_link_port =
7804         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7805                                 port, "port");
7806 cmdline_parse_token_num_t cmd_mirror_link_portid =
7807         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7808                                 port_id, UINT8);
7809 cmdline_parse_token_string_t cmd_mirror_link_mirror =
7810         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7811                                 mirror, "mirror-rule");
7812 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7813         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7814                             rule_id, UINT8);
7815 cmdline_parse_token_string_t cmd_mirror_link_what =
7816         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7817                                 what, "uplink-mirror#downlink-mirror");
7818 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7819         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7820                                 dstpool, "dst-pool");
7821 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7822         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7823                                 dstpool_id, UINT8);
7824 cmdline_parse_token_string_t cmd_mirror_link_on =
7825         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7826                                 on, "on#off");
7827
7828 static void
7829 cmd_set_mirror_link_parsed(void *parsed_result,
7830                        __attribute__((unused)) struct cmdline *cl,
7831                        __attribute__((unused)) void *data)
7832 {
7833         int ret;
7834         struct cmd_set_mirror_link_result *res = parsed_result;
7835         struct rte_eth_mirror_conf mr_conf;
7836
7837         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7838         if (!strcmp(res->what, "uplink-mirror"))
7839                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
7840         else
7841                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
7842
7843         mr_conf.dst_pool = res->dstpool_id;
7844
7845         if (!strcmp(res->on, "on"))
7846                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7847                                                 res->rule_id, 1);
7848         else
7849                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7850                                                 res->rule_id, 0);
7851
7852         /* check the return value and print it if is < 0 */
7853         if (ret < 0)
7854                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7855
7856 }
7857
7858 cmdline_parse_inst_t cmd_set_mirror_link = {
7859                 .f = cmd_set_mirror_link_parsed,
7860                 .data = NULL,
7861                 .help_str = "set port <port_id> mirror-rule <rule_id> "
7862                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
7863                 .tokens = {
7864                         (void *)&cmd_mirror_link_set,
7865                         (void *)&cmd_mirror_link_port,
7866                         (void *)&cmd_mirror_link_portid,
7867                         (void *)&cmd_mirror_link_mirror,
7868                         (void *)&cmd_mirror_link_ruleid,
7869                         (void *)&cmd_mirror_link_what,
7870                         (void *)&cmd_mirror_link_dstpool,
7871                         (void *)&cmd_mirror_link_poolid,
7872                         (void *)&cmd_mirror_link_on,
7873                         NULL,
7874                 },
7875 };
7876
7877 /* *** RESET VM MIRROR RULE *** */
7878 struct cmd_rm_mirror_rule_result {
7879         cmdline_fixed_string_t reset;
7880         cmdline_fixed_string_t port;
7881         uint8_t port_id;
7882         cmdline_fixed_string_t mirror;
7883         uint8_t rule_id;
7884 };
7885
7886 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
7887         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7888                                  reset, "reset");
7889 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
7890         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7891                                 port, "port");
7892 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
7893         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7894                                 port_id, UINT8);
7895 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
7896         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7897                                 mirror, "mirror-rule");
7898 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
7899         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7900                                 rule_id, UINT8);
7901
7902 static void
7903 cmd_reset_mirror_rule_parsed(void *parsed_result,
7904                        __attribute__((unused)) struct cmdline *cl,
7905                        __attribute__((unused)) void *data)
7906 {
7907         int ret;
7908         struct cmd_set_mirror_link_result *res = parsed_result;
7909         /* check rule_id */
7910         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
7911         if(ret < 0)
7912                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
7913 }
7914
7915 cmdline_parse_inst_t cmd_reset_mirror_rule = {
7916                 .f = cmd_reset_mirror_rule_parsed,
7917                 .data = NULL,
7918                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
7919                 .tokens = {
7920                         (void *)&cmd_rm_mirror_rule_reset,
7921                         (void *)&cmd_rm_mirror_rule_port,
7922                         (void *)&cmd_rm_mirror_rule_portid,
7923                         (void *)&cmd_rm_mirror_rule_mirror,
7924                         (void *)&cmd_rm_mirror_rule_ruleid,
7925                         NULL,
7926                 },
7927 };
7928
7929 /* ******************************************************************************** */
7930
7931 struct cmd_dump_result {
7932         cmdline_fixed_string_t dump;
7933 };
7934
7935 static void
7936 dump_struct_sizes(void)
7937 {
7938 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
7939         DUMP_SIZE(struct rte_mbuf);
7940         DUMP_SIZE(struct rte_mempool);
7941         DUMP_SIZE(struct rte_ring);
7942 #undef DUMP_SIZE
7943 }
7944
7945 static void cmd_dump_parsed(void *parsed_result,
7946                             __attribute__((unused)) struct cmdline *cl,
7947                             __attribute__((unused)) void *data)
7948 {
7949         struct cmd_dump_result *res = parsed_result;
7950
7951         if (!strcmp(res->dump, "dump_physmem"))
7952                 rte_dump_physmem_layout(stdout);
7953         else if (!strcmp(res->dump, "dump_memzone"))
7954                 rte_memzone_dump(stdout);
7955         else if (!strcmp(res->dump, "dump_struct_sizes"))
7956                 dump_struct_sizes();
7957         else if (!strcmp(res->dump, "dump_ring"))
7958                 rte_ring_list_dump(stdout);
7959         else if (!strcmp(res->dump, "dump_mempool"))
7960                 rte_mempool_list_dump(stdout);
7961         else if (!strcmp(res->dump, "dump_devargs"))
7962                 rte_eal_devargs_dump(stdout);
7963         else if (!strcmp(res->dump, "dump_log_types"))
7964                 rte_log_dump(stdout);
7965 }
7966
7967 cmdline_parse_token_string_t cmd_dump_dump =
7968         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
7969                 "dump_physmem#"
7970                 "dump_memzone#"
7971                 "dump_struct_sizes#"
7972                 "dump_ring#"
7973                 "dump_mempool#"
7974                 "dump_devargs#"
7975                 "dump_log_types");
7976
7977 cmdline_parse_inst_t cmd_dump = {
7978         .f = cmd_dump_parsed,  /* function to call */
7979         .data = NULL,      /* 2nd arg of func */
7980         .help_str = "Dump status",
7981         .tokens = {        /* token list, NULL terminated */
7982                 (void *)&cmd_dump_dump,
7983                 NULL,
7984         },
7985 };
7986
7987 /* ******************************************************************************** */
7988
7989 struct cmd_dump_one_result {
7990         cmdline_fixed_string_t dump;
7991         cmdline_fixed_string_t name;
7992 };
7993
7994 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
7995                                 __attribute__((unused)) void *data)
7996 {
7997         struct cmd_dump_one_result *res = parsed_result;
7998
7999         if (!strcmp(res->dump, "dump_ring")) {
8000                 struct rte_ring *r;
8001                 r = rte_ring_lookup(res->name);
8002                 if (r == NULL) {
8003                         cmdline_printf(cl, "Cannot find ring\n");
8004                         return;
8005                 }
8006                 rte_ring_dump(stdout, r);
8007         } else if (!strcmp(res->dump, "dump_mempool")) {
8008                 struct rte_mempool *mp;
8009                 mp = rte_mempool_lookup(res->name);
8010                 if (mp == NULL) {
8011                         cmdline_printf(cl, "Cannot find mempool\n");
8012                         return;
8013                 }
8014                 rte_mempool_dump(stdout, mp);
8015         }
8016 }
8017
8018 cmdline_parse_token_string_t cmd_dump_one_dump =
8019         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8020                                  "dump_ring#dump_mempool");
8021
8022 cmdline_parse_token_string_t cmd_dump_one_name =
8023         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8024
8025 cmdline_parse_inst_t cmd_dump_one = {
8026         .f = cmd_dump_one_parsed,  /* function to call */
8027         .data = NULL,      /* 2nd arg of func */
8028         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8029         .tokens = {        /* token list, NULL terminated */
8030                 (void *)&cmd_dump_one_dump,
8031                 (void *)&cmd_dump_one_name,
8032                 NULL,
8033         },
8034 };
8035
8036 /* *** Add/Del syn filter *** */
8037 struct cmd_syn_filter_result {
8038         cmdline_fixed_string_t filter;
8039         uint8_t port_id;
8040         cmdline_fixed_string_t ops;
8041         cmdline_fixed_string_t priority;
8042         cmdline_fixed_string_t high;
8043         cmdline_fixed_string_t queue;
8044         uint16_t queue_id;
8045 };
8046
8047 static void
8048 cmd_syn_filter_parsed(void *parsed_result,
8049                         __attribute__((unused)) struct cmdline *cl,
8050                         __attribute__((unused)) void *data)
8051 {
8052         struct cmd_syn_filter_result *res = parsed_result;
8053         struct rte_eth_syn_filter syn_filter;
8054         int ret = 0;
8055
8056         ret = rte_eth_dev_filter_supported(res->port_id,
8057                                         RTE_ETH_FILTER_SYN);
8058         if (ret < 0) {
8059                 printf("syn filter is not supported on port %u.\n",
8060                                 res->port_id);
8061                 return;
8062         }
8063
8064         memset(&syn_filter, 0, sizeof(syn_filter));
8065
8066         if (!strcmp(res->ops, "add")) {
8067                 if (!strcmp(res->high, "high"))
8068                         syn_filter.hig_pri = 1;
8069                 else
8070                         syn_filter.hig_pri = 0;
8071
8072                 syn_filter.queue = res->queue_id;
8073                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8074                                                 RTE_ETH_FILTER_SYN,
8075                                                 RTE_ETH_FILTER_ADD,
8076                                                 &syn_filter);
8077         } else
8078                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8079                                                 RTE_ETH_FILTER_SYN,
8080                                                 RTE_ETH_FILTER_DELETE,
8081                                                 &syn_filter);
8082
8083         if (ret < 0)
8084                 printf("syn filter programming error: (%s)\n",
8085                                 strerror(-ret));
8086 }
8087
8088 cmdline_parse_token_string_t cmd_syn_filter_filter =
8089         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8090         filter, "syn_filter");
8091 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8092         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8093         port_id, UINT8);
8094 cmdline_parse_token_string_t cmd_syn_filter_ops =
8095         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8096         ops, "add#del");
8097 cmdline_parse_token_string_t cmd_syn_filter_priority =
8098         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8099                                 priority, "priority");
8100 cmdline_parse_token_string_t cmd_syn_filter_high =
8101         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8102                                 high, "high#low");
8103 cmdline_parse_token_string_t cmd_syn_filter_queue =
8104         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8105                                 queue, "queue");
8106 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8107         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8108                                 queue_id, UINT16);
8109
8110 cmdline_parse_inst_t cmd_syn_filter = {
8111         .f = cmd_syn_filter_parsed,
8112         .data = NULL,
8113         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8114                 "<queue_id>: Add/Delete syn filter",
8115         .tokens = {
8116                 (void *)&cmd_syn_filter_filter,
8117                 (void *)&cmd_syn_filter_port_id,
8118                 (void *)&cmd_syn_filter_ops,
8119                 (void *)&cmd_syn_filter_priority,
8120                 (void *)&cmd_syn_filter_high,
8121                 (void *)&cmd_syn_filter_queue,
8122                 (void *)&cmd_syn_filter_queue_id,
8123                 NULL,
8124         },
8125 };
8126
8127 /* *** ADD/REMOVE A 2tuple FILTER *** */
8128 struct cmd_2tuple_filter_result {
8129         cmdline_fixed_string_t filter;
8130         uint8_t  port_id;
8131         cmdline_fixed_string_t ops;
8132         cmdline_fixed_string_t dst_port;
8133         uint16_t dst_port_value;
8134         cmdline_fixed_string_t protocol;
8135         uint8_t protocol_value;
8136         cmdline_fixed_string_t mask;
8137         uint8_t  mask_value;
8138         cmdline_fixed_string_t tcp_flags;
8139         uint8_t tcp_flags_value;
8140         cmdline_fixed_string_t priority;
8141         uint8_t  priority_value;
8142         cmdline_fixed_string_t queue;
8143         uint16_t  queue_id;
8144 };
8145
8146 static void
8147 cmd_2tuple_filter_parsed(void *parsed_result,
8148                         __attribute__((unused)) struct cmdline *cl,
8149                         __attribute__((unused)) void *data)
8150 {
8151         struct rte_eth_ntuple_filter filter;
8152         struct cmd_2tuple_filter_result *res = parsed_result;
8153         int ret = 0;
8154
8155         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8156         if (ret < 0) {
8157                 printf("ntuple filter is not supported on port %u.\n",
8158                         res->port_id);
8159                 return;
8160         }
8161
8162         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8163
8164         filter.flags = RTE_2TUPLE_FLAGS;
8165         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8166         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8167         filter.proto = res->protocol_value;
8168         filter.priority = res->priority_value;
8169         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8170                 printf("nonzero tcp_flags is only meaningful"
8171                         " when protocol is TCP.\n");
8172                 return;
8173         }
8174         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8175                 printf("invalid TCP flags.\n");
8176                 return;
8177         }
8178
8179         if (res->tcp_flags_value != 0) {
8180                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8181                 filter.tcp_flags = res->tcp_flags_value;
8182         }
8183
8184         /* need convert to big endian. */
8185         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8186         filter.queue = res->queue_id;
8187
8188         if (!strcmp(res->ops, "add"))
8189                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8190                                 RTE_ETH_FILTER_NTUPLE,
8191                                 RTE_ETH_FILTER_ADD,
8192                                 &filter);
8193         else
8194                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8195                                 RTE_ETH_FILTER_NTUPLE,
8196                                 RTE_ETH_FILTER_DELETE,
8197                                 &filter);
8198         if (ret < 0)
8199                 printf("2tuple filter programming error: (%s)\n",
8200                         strerror(-ret));
8201
8202 }
8203
8204 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
8205         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8206                                  filter, "2tuple_filter");
8207 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
8208         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8209                                 port_id, UINT8);
8210 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
8211         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8212                                  ops, "add#del");
8213 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
8214         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8215                                 dst_port, "dst_port");
8216 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
8217         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8218                                 dst_port_value, UINT16);
8219 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
8220         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8221                                 protocol, "protocol");
8222 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
8223         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8224                                 protocol_value, UINT8);
8225 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
8226         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8227                                 mask, "mask");
8228 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
8229         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8230                                 mask_value, INT8);
8231 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
8232         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8233                                 tcp_flags, "tcp_flags");
8234 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
8235         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8236                                 tcp_flags_value, UINT8);
8237 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
8238         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8239                                 priority, "priority");
8240 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
8241         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8242                                 priority_value, UINT8);
8243 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
8244         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8245                                 queue, "queue");
8246 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
8247         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8248                                 queue_id, UINT16);
8249
8250 cmdline_parse_inst_t cmd_2tuple_filter = {
8251         .f = cmd_2tuple_filter_parsed,
8252         .data = NULL,
8253         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
8254                 "<value> mask <value> tcp_flags <value> priority <value> queue "
8255                 "<queue_id>: Add a 2tuple filter",
8256         .tokens = {
8257                 (void *)&cmd_2tuple_filter_filter,
8258                 (void *)&cmd_2tuple_filter_port_id,
8259                 (void *)&cmd_2tuple_filter_ops,
8260                 (void *)&cmd_2tuple_filter_dst_port,
8261                 (void *)&cmd_2tuple_filter_dst_port_value,
8262                 (void *)&cmd_2tuple_filter_protocol,
8263                 (void *)&cmd_2tuple_filter_protocol_value,
8264                 (void *)&cmd_2tuple_filter_mask,
8265                 (void *)&cmd_2tuple_filter_mask_value,
8266                 (void *)&cmd_2tuple_filter_tcp_flags,
8267                 (void *)&cmd_2tuple_filter_tcp_flags_value,
8268                 (void *)&cmd_2tuple_filter_priority,
8269                 (void *)&cmd_2tuple_filter_priority_value,
8270                 (void *)&cmd_2tuple_filter_queue,
8271                 (void *)&cmd_2tuple_filter_queue_id,
8272                 NULL,
8273         },
8274 };
8275
8276 /* *** ADD/REMOVE A 5tuple FILTER *** */
8277 struct cmd_5tuple_filter_result {
8278         cmdline_fixed_string_t filter;
8279         uint8_t  port_id;
8280         cmdline_fixed_string_t ops;
8281         cmdline_fixed_string_t dst_ip;
8282         cmdline_ipaddr_t dst_ip_value;
8283         cmdline_fixed_string_t src_ip;
8284         cmdline_ipaddr_t src_ip_value;
8285         cmdline_fixed_string_t dst_port;
8286         uint16_t dst_port_value;
8287         cmdline_fixed_string_t src_port;
8288         uint16_t src_port_value;
8289         cmdline_fixed_string_t protocol;
8290         uint8_t protocol_value;
8291         cmdline_fixed_string_t mask;
8292         uint8_t  mask_value;
8293         cmdline_fixed_string_t tcp_flags;
8294         uint8_t tcp_flags_value;
8295         cmdline_fixed_string_t priority;
8296         uint8_t  priority_value;
8297         cmdline_fixed_string_t queue;
8298         uint16_t  queue_id;
8299 };
8300
8301 static void
8302 cmd_5tuple_filter_parsed(void *parsed_result,
8303                         __attribute__((unused)) struct cmdline *cl,
8304                         __attribute__((unused)) void *data)
8305 {
8306         struct rte_eth_ntuple_filter filter;
8307         struct cmd_5tuple_filter_result *res = parsed_result;
8308         int ret = 0;
8309
8310         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8311         if (ret < 0) {
8312                 printf("ntuple filter is not supported on port %u.\n",
8313                         res->port_id);
8314                 return;
8315         }
8316
8317         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8318
8319         filter.flags = RTE_5TUPLE_FLAGS;
8320         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
8321         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
8322         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
8323         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8324         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8325         filter.proto = res->protocol_value;
8326         filter.priority = res->priority_value;
8327         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8328                 printf("nonzero tcp_flags is only meaningful"
8329                         " when protocol is TCP.\n");
8330                 return;
8331         }
8332         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8333                 printf("invalid TCP flags.\n");
8334                 return;
8335         }
8336
8337         if (res->tcp_flags_value != 0) {
8338                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8339                 filter.tcp_flags = res->tcp_flags_value;
8340         }
8341
8342         if (res->dst_ip_value.family == AF_INET)
8343                 /* no need to convert, already big endian. */
8344                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
8345         else {
8346                 if (filter.dst_ip_mask == 0) {
8347                         printf("can not support ipv6 involved compare.\n");
8348                         return;
8349                 }
8350                 filter.dst_ip = 0;
8351         }
8352
8353         if (res->src_ip_value.family == AF_INET)
8354                 /* no need to convert, already big endian. */
8355                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
8356         else {
8357                 if (filter.src_ip_mask == 0) {
8358                         printf("can not support ipv6 involved compare.\n");
8359                         return;
8360                 }
8361                 filter.src_ip = 0;
8362         }
8363         /* need convert to big endian. */
8364         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8365         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
8366         filter.queue = res->queue_id;
8367
8368         if (!strcmp(res->ops, "add"))
8369                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8370                                 RTE_ETH_FILTER_NTUPLE,
8371                                 RTE_ETH_FILTER_ADD,
8372                                 &filter);
8373         else
8374                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8375                                 RTE_ETH_FILTER_NTUPLE,
8376                                 RTE_ETH_FILTER_DELETE,
8377                                 &filter);
8378         if (ret < 0)
8379                 printf("5tuple filter programming error: (%s)\n",
8380                         strerror(-ret));
8381 }
8382
8383 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
8384         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8385                                  filter, "5tuple_filter");
8386 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
8387         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8388                                 port_id, UINT8);
8389 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
8390         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8391                                  ops, "add#del");
8392 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
8393         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8394                                 dst_ip, "dst_ip");
8395 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
8396         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8397                                 dst_ip_value);
8398 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
8399         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8400                                 src_ip, "src_ip");
8401 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
8402         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8403                                 src_ip_value);
8404 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
8405         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8406                                 dst_port, "dst_port");
8407 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
8408         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8409                                 dst_port_value, UINT16);
8410 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
8411         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8412                                 src_port, "src_port");
8413 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
8414         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8415                                 src_port_value, UINT16);
8416 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
8417         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8418                                 protocol, "protocol");
8419 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
8420         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8421                                 protocol_value, UINT8);
8422 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
8423         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8424                                 mask, "mask");
8425 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
8426         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8427                                 mask_value, INT8);
8428 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
8429         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8430                                 tcp_flags, "tcp_flags");
8431 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
8432         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8433                                 tcp_flags_value, UINT8);
8434 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
8435         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8436                                 priority, "priority");
8437 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
8438         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8439                                 priority_value, UINT8);
8440 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
8441         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8442                                 queue, "queue");
8443 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
8444         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8445                                 queue_id, UINT16);
8446
8447 cmdline_parse_inst_t cmd_5tuple_filter = {
8448         .f = cmd_5tuple_filter_parsed,
8449         .data = NULL,
8450         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
8451                 "src_ip <value> dst_port <value> src_port <value> "
8452                 "protocol <value>  mask <value> tcp_flags <value> "
8453                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
8454         .tokens = {
8455                 (void *)&cmd_5tuple_filter_filter,
8456                 (void *)&cmd_5tuple_filter_port_id,
8457                 (void *)&cmd_5tuple_filter_ops,
8458                 (void *)&cmd_5tuple_filter_dst_ip,
8459                 (void *)&cmd_5tuple_filter_dst_ip_value,
8460                 (void *)&cmd_5tuple_filter_src_ip,
8461                 (void *)&cmd_5tuple_filter_src_ip_value,
8462                 (void *)&cmd_5tuple_filter_dst_port,
8463                 (void *)&cmd_5tuple_filter_dst_port_value,
8464                 (void *)&cmd_5tuple_filter_src_port,
8465                 (void *)&cmd_5tuple_filter_src_port_value,
8466                 (void *)&cmd_5tuple_filter_protocol,
8467                 (void *)&cmd_5tuple_filter_protocol_value,
8468                 (void *)&cmd_5tuple_filter_mask,
8469                 (void *)&cmd_5tuple_filter_mask_value,
8470                 (void *)&cmd_5tuple_filter_tcp_flags,
8471                 (void *)&cmd_5tuple_filter_tcp_flags_value,
8472                 (void *)&cmd_5tuple_filter_priority,
8473                 (void *)&cmd_5tuple_filter_priority_value,
8474                 (void *)&cmd_5tuple_filter_queue,
8475                 (void *)&cmd_5tuple_filter_queue_id,
8476                 NULL,
8477         },
8478 };
8479
8480 /* *** ADD/REMOVE A flex FILTER *** */
8481 struct cmd_flex_filter_result {
8482         cmdline_fixed_string_t filter;
8483         cmdline_fixed_string_t ops;
8484         uint8_t port_id;
8485         cmdline_fixed_string_t len;
8486         uint8_t len_value;
8487         cmdline_fixed_string_t bytes;
8488         cmdline_fixed_string_t bytes_value;
8489         cmdline_fixed_string_t mask;
8490         cmdline_fixed_string_t mask_value;
8491         cmdline_fixed_string_t priority;
8492         uint8_t priority_value;
8493         cmdline_fixed_string_t queue;
8494         uint16_t queue_id;
8495 };
8496
8497 static int xdigit2val(unsigned char c)
8498 {
8499         int val;
8500         if (isdigit(c))
8501                 val = c - '0';
8502         else if (isupper(c))
8503                 val = c - 'A' + 10;
8504         else
8505                 val = c - 'a' + 10;
8506         return val;
8507 }
8508
8509 static void
8510 cmd_flex_filter_parsed(void *parsed_result,
8511                           __attribute__((unused)) struct cmdline *cl,
8512                           __attribute__((unused)) void *data)
8513 {
8514         int ret = 0;
8515         struct rte_eth_flex_filter filter;
8516         struct cmd_flex_filter_result *res = parsed_result;
8517         char *bytes_ptr, *mask_ptr;
8518         uint16_t len, i, j = 0;
8519         char c;
8520         int val;
8521         uint8_t byte = 0;
8522
8523         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
8524                 printf("the len exceed the max length 128\n");
8525                 return;
8526         }
8527         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
8528         filter.len = res->len_value;
8529         filter.priority = res->priority_value;
8530         filter.queue = res->queue_id;
8531         bytes_ptr = res->bytes_value;
8532         mask_ptr = res->mask_value;
8533
8534          /* translate bytes string to array. */
8535         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
8536                 (bytes_ptr[1] == 'X')))
8537                 bytes_ptr += 2;
8538         len = strnlen(bytes_ptr, res->len_value * 2);
8539         if (len == 0 || (len % 8 != 0)) {
8540                 printf("please check len and bytes input\n");
8541                 return;
8542         }
8543         for (i = 0; i < len; i++) {
8544                 c = bytes_ptr[i];
8545                 if (isxdigit(c) == 0) {
8546                         /* invalid characters. */
8547                         printf("invalid input\n");
8548                         return;
8549                 }
8550                 val = xdigit2val(c);
8551                 if (i % 2) {
8552                         byte |= val;
8553                         filter.bytes[j] = byte;
8554                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
8555                         j++;
8556                         byte = 0;
8557                 } else
8558                         byte |= val << 4;
8559         }
8560         printf("\n");
8561          /* translate mask string to uint8_t array. */
8562         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
8563                 (mask_ptr[1] == 'X')))
8564                 mask_ptr += 2;
8565         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
8566         if (len == 0) {
8567                 printf("invalid input\n");
8568                 return;
8569         }
8570         j = 0;
8571         byte = 0;
8572         for (i = 0; i < len; i++) {
8573                 c = mask_ptr[i];
8574                 if (isxdigit(c) == 0) {
8575                         /* invalid characters. */
8576                         printf("invalid input\n");
8577                         return;
8578                 }
8579                 val = xdigit2val(c);
8580                 if (i % 2) {
8581                         byte |= val;
8582                         filter.mask[j] = byte;
8583                         printf("mask[%d]:%02x ", j, filter.mask[j]);
8584                         j++;
8585                         byte = 0;
8586                 } else
8587                         byte |= val << 4;
8588         }
8589         printf("\n");
8590
8591         if (!strcmp(res->ops, "add"))
8592                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8593                                 RTE_ETH_FILTER_FLEXIBLE,
8594                                 RTE_ETH_FILTER_ADD,
8595                                 &filter);
8596         else
8597                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8598                                 RTE_ETH_FILTER_FLEXIBLE,
8599                                 RTE_ETH_FILTER_DELETE,
8600                                 &filter);
8601
8602         if (ret < 0)
8603                 printf("flex filter setting error: (%s)\n", strerror(-ret));
8604 }
8605
8606 cmdline_parse_token_string_t cmd_flex_filter_filter =
8607         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8608                                 filter, "flex_filter");
8609 cmdline_parse_token_num_t cmd_flex_filter_port_id =
8610         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8611                                 port_id, UINT8);
8612 cmdline_parse_token_string_t cmd_flex_filter_ops =
8613         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8614                                 ops, "add#del");
8615 cmdline_parse_token_string_t cmd_flex_filter_len =
8616         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8617                                 len, "len");
8618 cmdline_parse_token_num_t cmd_flex_filter_len_value =
8619         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8620                                 len_value, UINT8);
8621 cmdline_parse_token_string_t cmd_flex_filter_bytes =
8622         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8623                                 bytes, "bytes");
8624 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
8625         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8626                                 bytes_value, NULL);
8627 cmdline_parse_token_string_t cmd_flex_filter_mask =
8628         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8629                                 mask, "mask");
8630 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
8631         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8632                                 mask_value, NULL);
8633 cmdline_parse_token_string_t cmd_flex_filter_priority =
8634         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8635                                 priority, "priority");
8636 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
8637         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8638                                 priority_value, UINT8);
8639 cmdline_parse_token_string_t cmd_flex_filter_queue =
8640         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8641                                 queue, "queue");
8642 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
8643         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8644                                 queue_id, UINT16);
8645 cmdline_parse_inst_t cmd_flex_filter = {
8646         .f = cmd_flex_filter_parsed,
8647         .data = NULL,
8648         .help_str = "flex_filter <port_id> add|del len <value> bytes "
8649                 "<value> mask <value> priority <value> queue <queue_id>: "
8650                 "Add/Del a flex filter",
8651         .tokens = {
8652                 (void *)&cmd_flex_filter_filter,
8653                 (void *)&cmd_flex_filter_port_id,
8654                 (void *)&cmd_flex_filter_ops,
8655                 (void *)&cmd_flex_filter_len,
8656                 (void *)&cmd_flex_filter_len_value,
8657                 (void *)&cmd_flex_filter_bytes,
8658                 (void *)&cmd_flex_filter_bytes_value,
8659                 (void *)&cmd_flex_filter_mask,
8660                 (void *)&cmd_flex_filter_mask_value,
8661                 (void *)&cmd_flex_filter_priority,
8662                 (void *)&cmd_flex_filter_priority_value,
8663                 (void *)&cmd_flex_filter_queue,
8664                 (void *)&cmd_flex_filter_queue_id,
8665                 NULL,
8666         },
8667 };
8668
8669 /* *** Filters Control *** */
8670
8671 /* *** deal with ethertype filter *** */
8672 struct cmd_ethertype_filter_result {
8673         cmdline_fixed_string_t filter;
8674         uint8_t port_id;
8675         cmdline_fixed_string_t ops;
8676         cmdline_fixed_string_t mac;
8677         struct ether_addr mac_addr;
8678         cmdline_fixed_string_t ethertype;
8679         uint16_t ethertype_value;
8680         cmdline_fixed_string_t drop;
8681         cmdline_fixed_string_t queue;
8682         uint16_t  queue_id;
8683 };
8684
8685 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
8686         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8687                                  filter, "ethertype_filter");
8688 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
8689         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8690                               port_id, UINT8);
8691 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
8692         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8693                                  ops, "add#del");
8694 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
8695         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8696                                  mac, "mac_addr#mac_ignr");
8697 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
8698         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
8699                                      mac_addr);
8700 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
8701         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8702                                  ethertype, "ethertype");
8703 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
8704         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8705                               ethertype_value, UINT16);
8706 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
8707         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8708                                  drop, "drop#fwd");
8709 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
8710         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8711                                  queue, "queue");
8712 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
8713         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8714                               queue_id, UINT16);
8715
8716 static void
8717 cmd_ethertype_filter_parsed(void *parsed_result,
8718                           __attribute__((unused)) struct cmdline *cl,
8719                           __attribute__((unused)) void *data)
8720 {
8721         struct cmd_ethertype_filter_result *res = parsed_result;
8722         struct rte_eth_ethertype_filter filter;
8723         int ret = 0;
8724
8725         ret = rte_eth_dev_filter_supported(res->port_id,
8726                         RTE_ETH_FILTER_ETHERTYPE);
8727         if (ret < 0) {
8728                 printf("ethertype filter is not supported on port %u.\n",
8729                         res->port_id);
8730                 return;
8731         }
8732
8733         memset(&filter, 0, sizeof(filter));
8734         if (!strcmp(res->mac, "mac_addr")) {
8735                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
8736                 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr,
8737                         sizeof(struct ether_addr));
8738         }
8739         if (!strcmp(res->drop, "drop"))
8740                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
8741         filter.ether_type = res->ethertype_value;
8742         filter.queue = res->queue_id;
8743
8744         if (!strcmp(res->ops, "add"))
8745                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8746                                 RTE_ETH_FILTER_ETHERTYPE,
8747                                 RTE_ETH_FILTER_ADD,
8748                                 &filter);
8749         else
8750                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8751                                 RTE_ETH_FILTER_ETHERTYPE,
8752                                 RTE_ETH_FILTER_DELETE,
8753                                 &filter);
8754         if (ret < 0)
8755                 printf("ethertype filter programming error: (%s)\n",
8756                         strerror(-ret));
8757 }
8758
8759 cmdline_parse_inst_t cmd_ethertype_filter = {
8760         .f = cmd_ethertype_filter_parsed,
8761         .data = NULL,
8762         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
8763                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
8764                 "Add or delete an ethertype filter entry",
8765         .tokens = {
8766                 (void *)&cmd_ethertype_filter_filter,
8767                 (void *)&cmd_ethertype_filter_port_id,
8768                 (void *)&cmd_ethertype_filter_ops,
8769                 (void *)&cmd_ethertype_filter_mac,
8770                 (void *)&cmd_ethertype_filter_mac_addr,
8771                 (void *)&cmd_ethertype_filter_ethertype,
8772                 (void *)&cmd_ethertype_filter_ethertype_value,
8773                 (void *)&cmd_ethertype_filter_drop,
8774                 (void *)&cmd_ethertype_filter_queue,
8775                 (void *)&cmd_ethertype_filter_queue_id,
8776                 NULL,
8777         },
8778 };
8779
8780 /* *** deal with flow director filter *** */
8781 struct cmd_flow_director_result {
8782         cmdline_fixed_string_t flow_director_filter;
8783         uint8_t port_id;
8784         cmdline_fixed_string_t mode;
8785         cmdline_fixed_string_t mode_value;
8786         cmdline_fixed_string_t ops;
8787         cmdline_fixed_string_t flow;
8788         cmdline_fixed_string_t flow_type;
8789         cmdline_fixed_string_t ether;
8790         uint16_t ether_type;
8791         cmdline_fixed_string_t src;
8792         cmdline_ipaddr_t ip_src;
8793         uint16_t port_src;
8794         cmdline_fixed_string_t dst;
8795         cmdline_ipaddr_t ip_dst;
8796         uint16_t port_dst;
8797         cmdline_fixed_string_t verify_tag;
8798         uint32_t verify_tag_value;
8799         cmdline_ipaddr_t tos;
8800         uint8_t tos_value;
8801         cmdline_ipaddr_t proto;
8802         uint8_t proto_value;
8803         cmdline_ipaddr_t ttl;
8804         uint8_t ttl_value;
8805         cmdline_fixed_string_t vlan;
8806         uint16_t vlan_value;
8807         cmdline_fixed_string_t flexbytes;
8808         cmdline_fixed_string_t flexbytes_value;
8809         cmdline_fixed_string_t pf_vf;
8810         cmdline_fixed_string_t drop;
8811         cmdline_fixed_string_t queue;
8812         uint16_t  queue_id;
8813         cmdline_fixed_string_t fd_id;
8814         uint32_t  fd_id_value;
8815         cmdline_fixed_string_t mac;
8816         struct ether_addr mac_addr;
8817         cmdline_fixed_string_t tunnel;
8818         cmdline_fixed_string_t tunnel_type;
8819         cmdline_fixed_string_t tunnel_id;
8820         uint32_t tunnel_id_value;
8821 };
8822
8823 static inline int
8824 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
8825 {
8826         char s[256];
8827         const char *p, *p0 = q_arg;
8828         char *end;
8829         unsigned long int_fld;
8830         char *str_fld[max_num];
8831         int i;
8832         unsigned size;
8833         int ret = -1;
8834
8835         p = strchr(p0, '(');
8836         if (p == NULL)
8837                 return -1;
8838         ++p;
8839         p0 = strchr(p, ')');
8840         if (p0 == NULL)
8841                 return -1;
8842
8843         size = p0 - p;
8844         if (size >= sizeof(s))
8845                 return -1;
8846
8847         snprintf(s, sizeof(s), "%.*s", size, p);
8848         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8849         if (ret < 0 || ret > max_num)
8850                 return -1;
8851         for (i = 0; i < ret; i++) {
8852                 errno = 0;
8853                 int_fld = strtoul(str_fld[i], &end, 0);
8854                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
8855                         return -1;
8856                 flexbytes[i] = (uint8_t)int_fld;
8857         }
8858         return ret;
8859 }
8860
8861 static uint16_t
8862 str2flowtype(char *string)
8863 {
8864         uint8_t i = 0;
8865         static const struct {
8866                 char str[32];
8867                 uint16_t type;
8868         } flowtype_str[] = {
8869                 {"raw", RTE_ETH_FLOW_RAW},
8870                 {"ipv4", RTE_ETH_FLOW_IPV4},
8871                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
8872                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
8873                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
8874                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
8875                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
8876                 {"ipv6", RTE_ETH_FLOW_IPV6},
8877                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
8878                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
8879                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
8880                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
8881                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
8882                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
8883         };
8884
8885         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
8886                 if (!strcmp(flowtype_str[i].str, string))
8887                         return flowtype_str[i].type;
8888         }
8889         return RTE_ETH_FLOW_UNKNOWN;
8890 }
8891
8892 static enum rte_eth_fdir_tunnel_type
8893 str2fdir_tunneltype(char *string)
8894 {
8895         uint8_t i = 0;
8896
8897         static const struct {
8898                 char str[32];
8899                 enum rte_eth_fdir_tunnel_type type;
8900         } tunneltype_str[] = {
8901                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
8902                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
8903         };
8904
8905         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
8906                 if (!strcmp(tunneltype_str[i].str, string))
8907                         return tunneltype_str[i].type;
8908         }
8909         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
8910 }
8911
8912 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
8913 do { \
8914         if ((ip_addr).family == AF_INET) \
8915                 (ip) = (ip_addr).addr.ipv4.s_addr; \
8916         else { \
8917                 printf("invalid parameter.\n"); \
8918                 return; \
8919         } \
8920 } while (0)
8921
8922 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
8923 do { \
8924         if ((ip_addr).family == AF_INET6) \
8925                 (void)rte_memcpy(&(ip), \
8926                                  &((ip_addr).addr.ipv6), \
8927                                  sizeof(struct in6_addr)); \
8928         else { \
8929                 printf("invalid parameter.\n"); \
8930                 return; \
8931         } \
8932 } while (0)
8933
8934 static void
8935 cmd_flow_director_filter_parsed(void *parsed_result,
8936                           __attribute__((unused)) struct cmdline *cl,
8937                           __attribute__((unused)) void *data)
8938 {
8939         struct cmd_flow_director_result *res = parsed_result;
8940         struct rte_eth_fdir_filter entry;
8941         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
8942         char *end;
8943         unsigned long vf_id;
8944         int ret = 0;
8945
8946         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8947         if (ret < 0) {
8948                 printf("flow director is not supported on port %u.\n",
8949                         res->port_id);
8950                 return;
8951         }
8952         memset(flexbytes, 0, sizeof(flexbytes));
8953         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
8954
8955         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
8956                 if (strcmp(res->mode_value, "MAC-VLAN")) {
8957                         printf("Please set mode to MAC-VLAN.\n");
8958                         return;
8959                 }
8960         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8961                 if (strcmp(res->mode_value, "Tunnel")) {
8962                         printf("Please set mode to Tunnel.\n");
8963                         return;
8964                 }
8965         } else {
8966                 if (strcmp(res->mode_value, "IP")) {
8967                         printf("Please set mode to IP.\n");
8968                         return;
8969                 }
8970                 entry.input.flow_type = str2flowtype(res->flow_type);
8971         }
8972
8973         ret = parse_flexbytes(res->flexbytes_value,
8974                                         flexbytes,
8975                                         RTE_ETH_FDIR_MAX_FLEXLEN);
8976         if (ret < 0) {
8977                 printf("error: Cannot parse flexbytes input.\n");
8978                 return;
8979         }
8980
8981         switch (entry.input.flow_type) {
8982         case RTE_ETH_FLOW_FRAG_IPV4:
8983         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
8984                 entry.input.flow.ip4_flow.proto = res->proto_value;
8985                 /* fall-through */
8986         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
8987         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
8988                 IPV4_ADDR_TO_UINT(res->ip_dst,
8989                         entry.input.flow.ip4_flow.dst_ip);
8990                 IPV4_ADDR_TO_UINT(res->ip_src,
8991                         entry.input.flow.ip4_flow.src_ip);
8992                 entry.input.flow.ip4_flow.tos = res->tos_value;
8993                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
8994                 /* need convert to big endian. */
8995                 entry.input.flow.udp4_flow.dst_port =
8996                                 rte_cpu_to_be_16(res->port_dst);
8997                 entry.input.flow.udp4_flow.src_port =
8998                                 rte_cpu_to_be_16(res->port_src);
8999                 break;
9000         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9001                 IPV4_ADDR_TO_UINT(res->ip_dst,
9002                         entry.input.flow.sctp4_flow.ip.dst_ip);
9003                 IPV4_ADDR_TO_UINT(res->ip_src,
9004                         entry.input.flow.sctp4_flow.ip.src_ip);
9005                 entry.input.flow.ip4_flow.tos = res->tos_value;
9006                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9007                 /* need convert to big endian. */
9008                 entry.input.flow.sctp4_flow.dst_port =
9009                                 rte_cpu_to_be_16(res->port_dst);
9010                 entry.input.flow.sctp4_flow.src_port =
9011                                 rte_cpu_to_be_16(res->port_src);
9012                 entry.input.flow.sctp4_flow.verify_tag =
9013                                 rte_cpu_to_be_32(res->verify_tag_value);
9014                 break;
9015         case RTE_ETH_FLOW_FRAG_IPV6:
9016         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9017                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9018                 /* fall-through */
9019         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9020         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9021                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9022                         entry.input.flow.ipv6_flow.dst_ip);
9023                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9024                         entry.input.flow.ipv6_flow.src_ip);
9025                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9026                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9027                 /* need convert to big endian. */
9028                 entry.input.flow.udp6_flow.dst_port =
9029                                 rte_cpu_to_be_16(res->port_dst);
9030                 entry.input.flow.udp6_flow.src_port =
9031                                 rte_cpu_to_be_16(res->port_src);
9032                 break;
9033         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9034                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9035                         entry.input.flow.sctp6_flow.ip.dst_ip);
9036                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9037                         entry.input.flow.sctp6_flow.ip.src_ip);
9038                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9039                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9040                 /* need convert to big endian. */
9041                 entry.input.flow.sctp6_flow.dst_port =
9042                                 rte_cpu_to_be_16(res->port_dst);
9043                 entry.input.flow.sctp6_flow.src_port =
9044                                 rte_cpu_to_be_16(res->port_src);
9045                 entry.input.flow.sctp6_flow.verify_tag =
9046                                 rte_cpu_to_be_32(res->verify_tag_value);
9047                 break;
9048         case RTE_ETH_FLOW_L2_PAYLOAD:
9049                 entry.input.flow.l2_flow.ether_type =
9050                         rte_cpu_to_be_16(res->ether_type);
9051                 break;
9052         default:
9053                 break;
9054         }
9055
9056         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9057                 (void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9058                                  &res->mac_addr,
9059                                  sizeof(struct ether_addr));
9060
9061         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9062                 (void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9063                                  &res->mac_addr,
9064                                  sizeof(struct ether_addr));
9065                 entry.input.flow.tunnel_flow.tunnel_type =
9066                         str2fdir_tunneltype(res->tunnel_type);
9067                 entry.input.flow.tunnel_flow.tunnel_id =
9068                         rte_cpu_to_be_32(res->tunnel_id_value);
9069         }
9070
9071         (void)rte_memcpy(entry.input.flow_ext.flexbytes,
9072                    flexbytes,
9073                    RTE_ETH_FDIR_MAX_FLEXLEN);
9074
9075         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9076
9077         entry.action.flex_off = 0;  /*use 0 by default */
9078         if (!strcmp(res->drop, "drop"))
9079                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
9080         else
9081                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9082
9083         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9084             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9085                 if (!strcmp(res->pf_vf, "pf"))
9086                         entry.input.flow_ext.is_vf = 0;
9087                 else if (!strncmp(res->pf_vf, "vf", 2)) {
9088                         struct rte_eth_dev_info dev_info;
9089
9090                         memset(&dev_info, 0, sizeof(dev_info));
9091                         rte_eth_dev_info_get(res->port_id, &dev_info);
9092                         errno = 0;
9093                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
9094                         if (errno != 0 || *end != '\0' ||
9095                             vf_id >= dev_info.max_vfs) {
9096                                 printf("invalid parameter %s.\n", res->pf_vf);
9097                                 return;
9098                         }
9099                         entry.input.flow_ext.is_vf = 1;
9100                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
9101                 } else {
9102                         printf("invalid parameter %s.\n", res->pf_vf);
9103                         return;
9104                 }
9105         }
9106
9107         /* set to report FD ID by default */
9108         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
9109         entry.action.rx_queue = res->queue_id;
9110         entry.soft_id = res->fd_id_value;
9111         if (!strcmp(res->ops, "add"))
9112                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9113                                              RTE_ETH_FILTER_ADD, &entry);
9114         else if (!strcmp(res->ops, "del"))
9115                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9116                                              RTE_ETH_FILTER_DELETE, &entry);
9117         else
9118                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9119                                              RTE_ETH_FILTER_UPDATE, &entry);
9120         if (ret < 0)
9121                 printf("flow director programming error: (%s)\n",
9122                         strerror(-ret));
9123 }
9124
9125 cmdline_parse_token_string_t cmd_flow_director_filter =
9126         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9127                                  flow_director_filter, "flow_director_filter");
9128 cmdline_parse_token_num_t cmd_flow_director_port_id =
9129         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9130                               port_id, UINT8);
9131 cmdline_parse_token_string_t cmd_flow_director_ops =
9132         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9133                                  ops, "add#del#update");
9134 cmdline_parse_token_string_t cmd_flow_director_flow =
9135         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9136                                  flow, "flow");
9137 cmdline_parse_token_string_t cmd_flow_director_flow_type =
9138         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9139                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9140                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
9141 cmdline_parse_token_string_t cmd_flow_director_ether =
9142         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9143                                  ether, "ether");
9144 cmdline_parse_token_num_t cmd_flow_director_ether_type =
9145         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9146                               ether_type, UINT16);
9147 cmdline_parse_token_string_t cmd_flow_director_src =
9148         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9149                                  src, "src");
9150 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
9151         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9152                                  ip_src);
9153 cmdline_parse_token_num_t cmd_flow_director_port_src =
9154         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9155                               port_src, UINT16);
9156 cmdline_parse_token_string_t cmd_flow_director_dst =
9157         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9158                                  dst, "dst");
9159 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
9160         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9161                                  ip_dst);
9162 cmdline_parse_token_num_t cmd_flow_director_port_dst =
9163         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9164                               port_dst, UINT16);
9165 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
9166         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9167                                   verify_tag, "verify_tag");
9168 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
9169         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9170                               verify_tag_value, UINT32);
9171 cmdline_parse_token_string_t cmd_flow_director_tos =
9172         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9173                                  tos, "tos");
9174 cmdline_parse_token_num_t cmd_flow_director_tos_value =
9175         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9176                               tos_value, UINT8);
9177 cmdline_parse_token_string_t cmd_flow_director_proto =
9178         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9179                                  proto, "proto");
9180 cmdline_parse_token_num_t cmd_flow_director_proto_value =
9181         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9182                               proto_value, UINT8);
9183 cmdline_parse_token_string_t cmd_flow_director_ttl =
9184         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9185                                  ttl, "ttl");
9186 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
9187         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9188                               ttl_value, UINT8);
9189 cmdline_parse_token_string_t cmd_flow_director_vlan =
9190         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9191                                  vlan, "vlan");
9192 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
9193         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9194                               vlan_value, UINT16);
9195 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
9196         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9197                                  flexbytes, "flexbytes");
9198 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
9199         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9200                               flexbytes_value, NULL);
9201 cmdline_parse_token_string_t cmd_flow_director_drop =
9202         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9203                                  drop, "drop#fwd");
9204 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
9205         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9206                               pf_vf, NULL);
9207 cmdline_parse_token_string_t cmd_flow_director_queue =
9208         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9209                                  queue, "queue");
9210 cmdline_parse_token_num_t cmd_flow_director_queue_id =
9211         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9212                               queue_id, UINT16);
9213 cmdline_parse_token_string_t cmd_flow_director_fd_id =
9214         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9215                                  fd_id, "fd_id");
9216 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
9217         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9218                               fd_id_value, UINT32);
9219
9220 cmdline_parse_token_string_t cmd_flow_director_mode =
9221         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9222                                  mode, "mode");
9223 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
9224         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9225                                  mode_value, "IP");
9226 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
9227         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9228                                  mode_value, "MAC-VLAN");
9229 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
9230         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9231                                  mode_value, "Tunnel");
9232 cmdline_parse_token_string_t cmd_flow_director_mac =
9233         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9234                                  mac, "mac");
9235 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
9236         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
9237                                     mac_addr);
9238 cmdline_parse_token_string_t cmd_flow_director_tunnel =
9239         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9240                                  tunnel, "tunnel");
9241 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
9242         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9243                                  tunnel_type, "NVGRE#VxLAN");
9244 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
9245         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9246                                  tunnel_id, "tunnel-id");
9247 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
9248         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9249                               tunnel_id_value, UINT32);
9250
9251 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
9252         .f = cmd_flow_director_filter_parsed,
9253         .data = NULL,
9254         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
9255                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
9256                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
9257                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
9258                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
9259                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
9260                 "fd_id <fd_id_value>: "
9261                 "Add or delete an ip flow director entry on NIC",
9262         .tokens = {
9263                 (void *)&cmd_flow_director_filter,
9264                 (void *)&cmd_flow_director_port_id,
9265                 (void *)&cmd_flow_director_mode,
9266                 (void *)&cmd_flow_director_mode_ip,
9267                 (void *)&cmd_flow_director_ops,
9268                 (void *)&cmd_flow_director_flow,
9269                 (void *)&cmd_flow_director_flow_type,
9270                 (void *)&cmd_flow_director_src,
9271                 (void *)&cmd_flow_director_ip_src,
9272                 (void *)&cmd_flow_director_dst,
9273                 (void *)&cmd_flow_director_ip_dst,
9274                 (void *)&cmd_flow_director_tos,
9275                 (void *)&cmd_flow_director_tos_value,
9276                 (void *)&cmd_flow_director_proto,
9277                 (void *)&cmd_flow_director_proto_value,
9278                 (void *)&cmd_flow_director_ttl,
9279                 (void *)&cmd_flow_director_ttl_value,
9280                 (void *)&cmd_flow_director_vlan,
9281                 (void *)&cmd_flow_director_vlan_value,
9282                 (void *)&cmd_flow_director_flexbytes,
9283                 (void *)&cmd_flow_director_flexbytes_value,
9284                 (void *)&cmd_flow_director_drop,
9285                 (void *)&cmd_flow_director_pf_vf,
9286                 (void *)&cmd_flow_director_queue,
9287                 (void *)&cmd_flow_director_queue_id,
9288                 (void *)&cmd_flow_director_fd_id,
9289                 (void *)&cmd_flow_director_fd_id_value,
9290                 NULL,
9291         },
9292 };
9293
9294 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
9295         .f = cmd_flow_director_filter_parsed,
9296         .data = NULL,
9297         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
9298                 "director entry on NIC",
9299         .tokens = {
9300                 (void *)&cmd_flow_director_filter,
9301                 (void *)&cmd_flow_director_port_id,
9302                 (void *)&cmd_flow_director_mode,
9303                 (void *)&cmd_flow_director_mode_ip,
9304                 (void *)&cmd_flow_director_ops,
9305                 (void *)&cmd_flow_director_flow,
9306                 (void *)&cmd_flow_director_flow_type,
9307                 (void *)&cmd_flow_director_src,
9308                 (void *)&cmd_flow_director_ip_src,
9309                 (void *)&cmd_flow_director_port_src,
9310                 (void *)&cmd_flow_director_dst,
9311                 (void *)&cmd_flow_director_ip_dst,
9312                 (void *)&cmd_flow_director_port_dst,
9313                 (void *)&cmd_flow_director_tos,
9314                 (void *)&cmd_flow_director_tos_value,
9315                 (void *)&cmd_flow_director_ttl,
9316                 (void *)&cmd_flow_director_ttl_value,
9317                 (void *)&cmd_flow_director_vlan,
9318                 (void *)&cmd_flow_director_vlan_value,
9319                 (void *)&cmd_flow_director_flexbytes,
9320                 (void *)&cmd_flow_director_flexbytes_value,
9321                 (void *)&cmd_flow_director_drop,
9322                 (void *)&cmd_flow_director_pf_vf,
9323                 (void *)&cmd_flow_director_queue,
9324                 (void *)&cmd_flow_director_queue_id,
9325                 (void *)&cmd_flow_director_fd_id,
9326                 (void *)&cmd_flow_director_fd_id_value,
9327                 NULL,
9328         },
9329 };
9330
9331 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
9332         .f = cmd_flow_director_filter_parsed,
9333         .data = NULL,
9334         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
9335                 "director entry on NIC",
9336         .tokens = {
9337                 (void *)&cmd_flow_director_filter,
9338                 (void *)&cmd_flow_director_port_id,
9339                 (void *)&cmd_flow_director_mode,
9340                 (void *)&cmd_flow_director_mode_ip,
9341                 (void *)&cmd_flow_director_ops,
9342                 (void *)&cmd_flow_director_flow,
9343                 (void *)&cmd_flow_director_flow_type,
9344                 (void *)&cmd_flow_director_src,
9345                 (void *)&cmd_flow_director_ip_src,
9346                 (void *)&cmd_flow_director_port_dst,
9347                 (void *)&cmd_flow_director_dst,
9348                 (void *)&cmd_flow_director_ip_dst,
9349                 (void *)&cmd_flow_director_port_dst,
9350                 (void *)&cmd_flow_director_verify_tag,
9351                 (void *)&cmd_flow_director_verify_tag_value,
9352                 (void *)&cmd_flow_director_tos,
9353                 (void *)&cmd_flow_director_tos_value,
9354                 (void *)&cmd_flow_director_ttl,
9355                 (void *)&cmd_flow_director_ttl_value,
9356                 (void *)&cmd_flow_director_vlan,
9357                 (void *)&cmd_flow_director_vlan_value,
9358                 (void *)&cmd_flow_director_flexbytes,
9359                 (void *)&cmd_flow_director_flexbytes_value,
9360                 (void *)&cmd_flow_director_drop,
9361                 (void *)&cmd_flow_director_pf_vf,
9362                 (void *)&cmd_flow_director_queue,
9363                 (void *)&cmd_flow_director_queue_id,
9364                 (void *)&cmd_flow_director_fd_id,
9365                 (void *)&cmd_flow_director_fd_id_value,
9366                 NULL,
9367         },
9368 };
9369
9370 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
9371         .f = cmd_flow_director_filter_parsed,
9372         .data = NULL,
9373         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
9374                 "director entry on NIC",
9375         .tokens = {
9376                 (void *)&cmd_flow_director_filter,
9377                 (void *)&cmd_flow_director_port_id,
9378                 (void *)&cmd_flow_director_mode,
9379                 (void *)&cmd_flow_director_mode_ip,
9380                 (void *)&cmd_flow_director_ops,
9381                 (void *)&cmd_flow_director_flow,
9382                 (void *)&cmd_flow_director_flow_type,
9383                 (void *)&cmd_flow_director_ether,
9384                 (void *)&cmd_flow_director_ether_type,
9385                 (void *)&cmd_flow_director_flexbytes,
9386                 (void *)&cmd_flow_director_flexbytes_value,
9387                 (void *)&cmd_flow_director_drop,
9388                 (void *)&cmd_flow_director_pf_vf,
9389                 (void *)&cmd_flow_director_queue,
9390                 (void *)&cmd_flow_director_queue_id,
9391                 (void *)&cmd_flow_director_fd_id,
9392                 (void *)&cmd_flow_director_fd_id_value,
9393                 NULL,
9394         },
9395 };
9396
9397 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
9398         .f = cmd_flow_director_filter_parsed,
9399         .data = NULL,
9400         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
9401                 "director entry on NIC",
9402         .tokens = {
9403                 (void *)&cmd_flow_director_filter,
9404                 (void *)&cmd_flow_director_port_id,
9405                 (void *)&cmd_flow_director_mode,
9406                 (void *)&cmd_flow_director_mode_mac_vlan,
9407                 (void *)&cmd_flow_director_ops,
9408                 (void *)&cmd_flow_director_mac,
9409                 (void *)&cmd_flow_director_mac_addr,
9410                 (void *)&cmd_flow_director_vlan,
9411                 (void *)&cmd_flow_director_vlan_value,
9412                 (void *)&cmd_flow_director_flexbytes,
9413                 (void *)&cmd_flow_director_flexbytes_value,
9414                 (void *)&cmd_flow_director_drop,
9415                 (void *)&cmd_flow_director_queue,
9416                 (void *)&cmd_flow_director_queue_id,
9417                 (void *)&cmd_flow_director_fd_id,
9418                 (void *)&cmd_flow_director_fd_id_value,
9419                 NULL,
9420         },
9421 };
9422
9423 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
9424         .f = cmd_flow_director_filter_parsed,
9425         .data = NULL,
9426         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
9427                 "director entry on NIC",
9428         .tokens = {
9429                 (void *)&cmd_flow_director_filter,
9430                 (void *)&cmd_flow_director_port_id,
9431                 (void *)&cmd_flow_director_mode,
9432                 (void *)&cmd_flow_director_mode_tunnel,
9433                 (void *)&cmd_flow_director_ops,
9434                 (void *)&cmd_flow_director_mac,
9435                 (void *)&cmd_flow_director_mac_addr,
9436                 (void *)&cmd_flow_director_vlan,
9437                 (void *)&cmd_flow_director_vlan_value,
9438                 (void *)&cmd_flow_director_tunnel,
9439                 (void *)&cmd_flow_director_tunnel_type,
9440                 (void *)&cmd_flow_director_tunnel_id,
9441                 (void *)&cmd_flow_director_tunnel_id_value,
9442                 (void *)&cmd_flow_director_flexbytes,
9443                 (void *)&cmd_flow_director_flexbytes_value,
9444                 (void *)&cmd_flow_director_drop,
9445                 (void *)&cmd_flow_director_queue,
9446                 (void *)&cmd_flow_director_queue_id,
9447                 (void *)&cmd_flow_director_fd_id,
9448                 (void *)&cmd_flow_director_fd_id_value,
9449                 NULL,
9450         },
9451 };
9452
9453 struct cmd_flush_flow_director_result {
9454         cmdline_fixed_string_t flush_flow_director;
9455         uint8_t port_id;
9456 };
9457
9458 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
9459         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
9460                                  flush_flow_director, "flush_flow_director");
9461 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
9462         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
9463                               port_id, UINT8);
9464
9465 static void
9466 cmd_flush_flow_director_parsed(void *parsed_result,
9467                           __attribute__((unused)) struct cmdline *cl,
9468                           __attribute__((unused)) void *data)
9469 {
9470         struct cmd_flow_director_result *res = parsed_result;
9471         int ret = 0;
9472
9473         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9474         if (ret < 0) {
9475                 printf("flow director is not supported on port %u.\n",
9476                         res->port_id);
9477                 return;
9478         }
9479
9480         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9481                         RTE_ETH_FILTER_FLUSH, NULL);
9482         if (ret < 0)
9483                 printf("flow director table flushing error: (%s)\n",
9484                         strerror(-ret));
9485 }
9486
9487 cmdline_parse_inst_t cmd_flush_flow_director = {
9488         .f = cmd_flush_flow_director_parsed,
9489         .data = NULL,
9490         .help_str = "flush_flow_director <port_id>: "
9491                 "Flush all flow director entries of a device on NIC",
9492         .tokens = {
9493                 (void *)&cmd_flush_flow_director_flush,
9494                 (void *)&cmd_flush_flow_director_port_id,
9495                 NULL,
9496         },
9497 };
9498
9499 /* *** deal with flow director mask *** */
9500 struct cmd_flow_director_mask_result {
9501         cmdline_fixed_string_t flow_director_mask;
9502         uint8_t port_id;
9503         cmdline_fixed_string_t mode;
9504         cmdline_fixed_string_t mode_value;
9505         cmdline_fixed_string_t vlan;
9506         uint16_t vlan_mask;
9507         cmdline_fixed_string_t src_mask;
9508         cmdline_ipaddr_t ipv4_src;
9509         cmdline_ipaddr_t ipv6_src;
9510         uint16_t port_src;
9511         cmdline_fixed_string_t dst_mask;
9512         cmdline_ipaddr_t ipv4_dst;
9513         cmdline_ipaddr_t ipv6_dst;
9514         uint16_t port_dst;
9515         cmdline_fixed_string_t mac;
9516         uint8_t mac_addr_byte_mask;
9517         cmdline_fixed_string_t tunnel_id;
9518         uint32_t tunnel_id_mask;
9519         cmdline_fixed_string_t tunnel_type;
9520         uint8_t tunnel_type_mask;
9521 };
9522
9523 static void
9524 cmd_flow_director_mask_parsed(void *parsed_result,
9525                           __attribute__((unused)) struct cmdline *cl,
9526                           __attribute__((unused)) void *data)
9527 {
9528         struct cmd_flow_director_mask_result *res = parsed_result;
9529         struct rte_eth_fdir_masks *mask;
9530         struct rte_port *port;
9531
9532         if (res->port_id > nb_ports) {
9533                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9534                 return;
9535         }
9536
9537         port = &ports[res->port_id];
9538         /** Check if the port is not started **/
9539         if (port->port_status != RTE_PORT_STOPPED) {
9540                 printf("Please stop port %d first\n", res->port_id);
9541                 return;
9542         }
9543
9544         mask = &port->dev_conf.fdir_conf.mask;
9545
9546         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9547                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9548                         printf("Please set mode to MAC-VLAN.\n");
9549                         return;
9550                 }
9551
9552                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9553         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9554                 if (strcmp(res->mode_value, "Tunnel")) {
9555                         printf("Please set mode to Tunnel.\n");
9556                         return;
9557                 }
9558
9559                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9560                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9561                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
9562                 mask->tunnel_type_mask = res->tunnel_type_mask;
9563         } else {
9564                 if (strcmp(res->mode_value, "IP")) {
9565                         printf("Please set mode to IP.\n");
9566                         return;
9567                 }
9568
9569                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9570                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
9571                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
9572                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
9573                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
9574                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
9575                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
9576         }
9577
9578         cmd_reconfig_device_queue(res->port_id, 1, 1);
9579 }
9580
9581 cmdline_parse_token_string_t cmd_flow_director_mask =
9582         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9583                                  flow_director_mask, "flow_director_mask");
9584 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
9585         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9586                               port_id, UINT8);
9587 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
9588         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9589                                  vlan, "vlan");
9590 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
9591         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9592                               vlan_mask, UINT16);
9593 cmdline_parse_token_string_t cmd_flow_director_mask_src =
9594         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9595                                  src_mask, "src_mask");
9596 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
9597         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9598                                  ipv4_src);
9599 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
9600         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9601                                  ipv6_src);
9602 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
9603         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9604                               port_src, UINT16);
9605 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
9606         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9607                                  dst_mask, "dst_mask");
9608 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
9609         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9610                                  ipv4_dst);
9611 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
9612         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9613                                  ipv6_dst);
9614 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
9615         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9616                               port_dst, UINT16);
9617
9618 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
9619         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9620                                  mode, "mode");
9621 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
9622         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9623                                  mode_value, "IP");
9624 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
9625         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9626                                  mode_value, "MAC-VLAN");
9627 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
9628         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9629                                  mode_value, "Tunnel");
9630 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
9631         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9632                                  mac, "mac");
9633 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
9634         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9635                               mac_addr_byte_mask, UINT8);
9636 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
9637         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9638                                  tunnel_type, "tunnel-type");
9639 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
9640         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9641                               tunnel_type_mask, UINT8);
9642 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
9643         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9644                                  tunnel_id, "tunnel-id");
9645 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
9646         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9647                               tunnel_id_mask, UINT32);
9648
9649 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
9650         .f = cmd_flow_director_mask_parsed,
9651         .data = NULL,
9652         .help_str = "flow_director_mask ... : "
9653                 "Set IP mode flow director's mask on NIC",
9654         .tokens = {
9655                 (void *)&cmd_flow_director_mask,
9656                 (void *)&cmd_flow_director_mask_port_id,
9657                 (void *)&cmd_flow_director_mask_mode,
9658                 (void *)&cmd_flow_director_mask_mode_ip,
9659                 (void *)&cmd_flow_director_mask_vlan,
9660                 (void *)&cmd_flow_director_mask_vlan_value,
9661                 (void *)&cmd_flow_director_mask_src,
9662                 (void *)&cmd_flow_director_mask_ipv4_src,
9663                 (void *)&cmd_flow_director_mask_ipv6_src,
9664                 (void *)&cmd_flow_director_mask_port_src,
9665                 (void *)&cmd_flow_director_mask_dst,
9666                 (void *)&cmd_flow_director_mask_ipv4_dst,
9667                 (void *)&cmd_flow_director_mask_ipv6_dst,
9668                 (void *)&cmd_flow_director_mask_port_dst,
9669                 NULL,
9670         },
9671 };
9672
9673 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
9674         .f = cmd_flow_director_mask_parsed,
9675         .data = NULL,
9676         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
9677                 "flow director's mask on NIC",
9678         .tokens = {
9679                 (void *)&cmd_flow_director_mask,
9680                 (void *)&cmd_flow_director_mask_port_id,
9681                 (void *)&cmd_flow_director_mask_mode,
9682                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
9683                 (void *)&cmd_flow_director_mask_vlan,
9684                 (void *)&cmd_flow_director_mask_vlan_value,
9685                 NULL,
9686         },
9687 };
9688
9689 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
9690         .f = cmd_flow_director_mask_parsed,
9691         .data = NULL,
9692         .help_str = "flow_director_mask ... : Set tunnel mode "
9693                 "flow director's mask on NIC",
9694         .tokens = {
9695                 (void *)&cmd_flow_director_mask,
9696                 (void *)&cmd_flow_director_mask_port_id,
9697                 (void *)&cmd_flow_director_mask_mode,
9698                 (void *)&cmd_flow_director_mask_mode_tunnel,
9699                 (void *)&cmd_flow_director_mask_vlan,
9700                 (void *)&cmd_flow_director_mask_vlan_value,
9701                 (void *)&cmd_flow_director_mask_mac,
9702                 (void *)&cmd_flow_director_mask_mac_value,
9703                 (void *)&cmd_flow_director_mask_tunnel_type,
9704                 (void *)&cmd_flow_director_mask_tunnel_type_value,
9705                 (void *)&cmd_flow_director_mask_tunnel_id,
9706                 (void *)&cmd_flow_director_mask_tunnel_id_value,
9707                 NULL,
9708         },
9709 };
9710
9711 /* *** deal with flow director mask on flexible payload *** */
9712 struct cmd_flow_director_flex_mask_result {
9713         cmdline_fixed_string_t flow_director_flexmask;
9714         uint8_t port_id;
9715         cmdline_fixed_string_t flow;
9716         cmdline_fixed_string_t flow_type;
9717         cmdline_fixed_string_t mask;
9718 };
9719
9720 static void
9721 cmd_flow_director_flex_mask_parsed(void *parsed_result,
9722                           __attribute__((unused)) struct cmdline *cl,
9723                           __attribute__((unused)) void *data)
9724 {
9725         struct cmd_flow_director_flex_mask_result *res = parsed_result;
9726         struct rte_eth_fdir_info fdir_info;
9727         struct rte_eth_fdir_flex_mask flex_mask;
9728         struct rte_port *port;
9729         uint32_t flow_type_mask;
9730         uint16_t i;
9731         int ret;
9732
9733         if (res->port_id > nb_ports) {
9734                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9735                 return;
9736         }
9737
9738         port = &ports[res->port_id];
9739         /** Check if the port is not started **/
9740         if (port->port_status != RTE_PORT_STOPPED) {
9741                 printf("Please stop port %d first\n", res->port_id);
9742                 return;
9743         }
9744
9745         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
9746         ret = parse_flexbytes(res->mask,
9747                         flex_mask.mask,
9748                         RTE_ETH_FDIR_MAX_FLEXLEN);
9749         if (ret < 0) {
9750                 printf("error: Cannot parse mask input.\n");
9751                 return;
9752         }
9753
9754         memset(&fdir_info, 0, sizeof(fdir_info));
9755         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9756                                 RTE_ETH_FILTER_INFO, &fdir_info);
9757         if (ret < 0) {
9758                 printf("Cannot get FDir filter info\n");
9759                 return;
9760         }
9761
9762         if (!strcmp(res->flow_type, "none")) {
9763                 /* means don't specify the flow type */
9764                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
9765                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
9766                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
9767                                0, sizeof(struct rte_eth_fdir_flex_mask));
9768                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
9769                 (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
9770                                  &flex_mask,
9771                                  sizeof(struct rte_eth_fdir_flex_mask));
9772                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9773                 return;
9774         }
9775         flow_type_mask = fdir_info.flow_types_mask[0];
9776         if (!strcmp(res->flow_type, "all")) {
9777                 if (!flow_type_mask) {
9778                         printf("No flow type supported\n");
9779                         return;
9780                 }
9781                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
9782                         if (flow_type_mask & (1 << i)) {
9783                                 flex_mask.flow_type = i;
9784                                 fdir_set_flex_mask(res->port_id, &flex_mask);
9785                         }
9786                 }
9787                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9788                 return;
9789         }
9790         flex_mask.flow_type = str2flowtype(res->flow_type);
9791         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
9792                 printf("Flow type %s not supported on port %d\n",
9793                                 res->flow_type, res->port_id);
9794                 return;
9795         }
9796         fdir_set_flex_mask(res->port_id, &flex_mask);
9797         cmd_reconfig_device_queue(res->port_id, 1, 1);
9798 }
9799
9800 cmdline_parse_token_string_t cmd_flow_director_flexmask =
9801         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9802                                  flow_director_flexmask,
9803                                  "flow_director_flex_mask");
9804 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
9805         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9806                               port_id, UINT8);
9807 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
9808         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9809                                  flow, "flow");
9810 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
9811         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9812                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9813                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
9814 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
9815         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9816                                  mask, NULL);
9817
9818 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
9819         .f = cmd_flow_director_flex_mask_parsed,
9820         .data = NULL,
9821         .help_str = "flow_director_flex_mask ... : "
9822                 "Set flow director's flex mask on NIC",
9823         .tokens = {
9824                 (void *)&cmd_flow_director_flexmask,
9825                 (void *)&cmd_flow_director_flexmask_port_id,
9826                 (void *)&cmd_flow_director_flexmask_flow,
9827                 (void *)&cmd_flow_director_flexmask_flow_type,
9828                 (void *)&cmd_flow_director_flexmask_mask,
9829                 NULL,
9830         },
9831 };
9832
9833 /* *** deal with flow director flexible payload configuration *** */
9834 struct cmd_flow_director_flexpayload_result {
9835         cmdline_fixed_string_t flow_director_flexpayload;
9836         uint8_t port_id;
9837         cmdline_fixed_string_t payload_layer;
9838         cmdline_fixed_string_t payload_cfg;
9839 };
9840
9841 static inline int
9842 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
9843 {
9844         char s[256];
9845         const char *p, *p0 = q_arg;
9846         char *end;
9847         unsigned long int_fld;
9848         char *str_fld[max_num];
9849         int i;
9850         unsigned size;
9851         int ret = -1;
9852
9853         p = strchr(p0, '(');
9854         if (p == NULL)
9855                 return -1;
9856         ++p;
9857         p0 = strchr(p, ')');
9858         if (p0 == NULL)
9859                 return -1;
9860
9861         size = p0 - p;
9862         if (size >= sizeof(s))
9863                 return -1;
9864
9865         snprintf(s, sizeof(s), "%.*s", size, p);
9866         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9867         if (ret < 0 || ret > max_num)
9868                 return -1;
9869         for (i = 0; i < ret; i++) {
9870                 errno = 0;
9871                 int_fld = strtoul(str_fld[i], &end, 0);
9872                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
9873                         return -1;
9874                 offsets[i] = (uint16_t)int_fld;
9875         }
9876         return ret;
9877 }
9878
9879 static void
9880 cmd_flow_director_flxpld_parsed(void *parsed_result,
9881                           __attribute__((unused)) struct cmdline *cl,
9882                           __attribute__((unused)) void *data)
9883 {
9884         struct cmd_flow_director_flexpayload_result *res = parsed_result;
9885         struct rte_eth_flex_payload_cfg flex_cfg;
9886         struct rte_port *port;
9887         int ret = 0;
9888
9889         if (res->port_id > nb_ports) {
9890                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9891                 return;
9892         }
9893
9894         port = &ports[res->port_id];
9895         /** Check if the port is not started **/
9896         if (port->port_status != RTE_PORT_STOPPED) {
9897                 printf("Please stop port %d first\n", res->port_id);
9898                 return;
9899         }
9900
9901         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
9902
9903         if (!strcmp(res->payload_layer, "raw"))
9904                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
9905         else if (!strcmp(res->payload_layer, "l2"))
9906                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
9907         else if (!strcmp(res->payload_layer, "l3"))
9908                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
9909         else if (!strcmp(res->payload_layer, "l4"))
9910                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
9911
9912         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
9913                             RTE_ETH_FDIR_MAX_FLEXLEN);
9914         if (ret < 0) {
9915                 printf("error: Cannot parse flex payload input.\n");
9916                 return;
9917         }
9918
9919         fdir_set_flex_payload(res->port_id, &flex_cfg);
9920         cmd_reconfig_device_queue(res->port_id, 1, 1);
9921 }
9922
9923 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
9924         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9925                                  flow_director_flexpayload,
9926                                  "flow_director_flex_payload");
9927 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
9928         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9929                               port_id, UINT8);
9930 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
9931         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9932                                  payload_layer, "raw#l2#l3#l4");
9933 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
9934         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9935                                  payload_cfg, NULL);
9936
9937 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
9938         .f = cmd_flow_director_flxpld_parsed,
9939         .data = NULL,
9940         .help_str = "flow_director_flexpayload ... : "
9941                 "Set flow director's flex payload on NIC",
9942         .tokens = {
9943                 (void *)&cmd_flow_director_flexpayload,
9944                 (void *)&cmd_flow_director_flexpayload_port_id,
9945                 (void *)&cmd_flow_director_flexpayload_payload_layer,
9946                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
9947                 NULL,
9948         },
9949 };
9950
9951 /* Generic flow interface command. */
9952 extern cmdline_parse_inst_t cmd_flow;
9953
9954 /* *** Classification Filters Control *** */
9955 /* *** Get symmetric hash enable per port *** */
9956 struct cmd_get_sym_hash_ena_per_port_result {
9957         cmdline_fixed_string_t get_sym_hash_ena_per_port;
9958         uint8_t port_id;
9959 };
9960
9961 static void
9962 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
9963                                  __rte_unused struct cmdline *cl,
9964                                  __rte_unused void *data)
9965 {
9966         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
9967         struct rte_eth_hash_filter_info info;
9968         int ret;
9969
9970         if (rte_eth_dev_filter_supported(res->port_id,
9971                                 RTE_ETH_FILTER_HASH) < 0) {
9972                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9973                                                         res->port_id);
9974                 return;
9975         }
9976
9977         memset(&info, 0, sizeof(info));
9978         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9979         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9980                                                 RTE_ETH_FILTER_GET, &info);
9981
9982         if (ret < 0) {
9983                 printf("Cannot get symmetric hash enable per port "
9984                                         "on port %u\n", res->port_id);
9985                 return;
9986         }
9987
9988         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
9989                                 "enabled" : "disabled", res->port_id);
9990 }
9991
9992 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
9993         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9994                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
9995 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
9996         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9997                 port_id, UINT8);
9998
9999 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10000         .f = cmd_get_sym_hash_per_port_parsed,
10001         .data = NULL,
10002         .help_str = "get_sym_hash_ena_per_port <port_id>",
10003         .tokens = {
10004                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10005                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10006                 NULL,
10007         },
10008 };
10009
10010 /* *** Set symmetric hash enable per port *** */
10011 struct cmd_set_sym_hash_ena_per_port_result {
10012         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10013         cmdline_fixed_string_t enable;
10014         uint8_t port_id;
10015 };
10016
10017 static void
10018 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10019                                  __rte_unused struct cmdline *cl,
10020                                  __rte_unused void *data)
10021 {
10022         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10023         struct rte_eth_hash_filter_info info;
10024         int ret;
10025
10026         if (rte_eth_dev_filter_supported(res->port_id,
10027                                 RTE_ETH_FILTER_HASH) < 0) {
10028                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10029                                                         res->port_id);
10030                 return;
10031         }
10032
10033         memset(&info, 0, sizeof(info));
10034         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10035         if (!strcmp(res->enable, "enable"))
10036                 info.info.enable = 1;
10037         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10038                                         RTE_ETH_FILTER_SET, &info);
10039         if (ret < 0) {
10040                 printf("Cannot set symmetric hash enable per port on "
10041                                         "port %u\n", res->port_id);
10042                 return;
10043         }
10044         printf("Symmetric hash has been set to %s on port %u\n",
10045                                         res->enable, res->port_id);
10046 }
10047
10048 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10049         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10050                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10051 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10052         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10053                 port_id, UINT8);
10054 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10055         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10056                 enable, "enable#disable");
10057
10058 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10059         .f = cmd_set_sym_hash_per_port_parsed,
10060         .data = NULL,
10061         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10062         .tokens = {
10063                 (void *)&cmd_set_sym_hash_ena_per_port_all,
10064                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
10065                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
10066                 NULL,
10067         },
10068 };
10069
10070 /* Get global config of hash function */
10071 struct cmd_get_hash_global_config_result {
10072         cmdline_fixed_string_t get_hash_global_config;
10073         uint8_t port_id;
10074 };
10075
10076 static char *
10077 flowtype_to_str(uint16_t ftype)
10078 {
10079         uint16_t i;
10080         static struct {
10081                 char str[16];
10082                 uint16_t ftype;
10083         } ftype_table[] = {
10084                 {"ipv4", RTE_ETH_FLOW_IPV4},
10085                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10086                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10087                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10088                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10089                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10090                 {"ipv6", RTE_ETH_FLOW_IPV6},
10091                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10092                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10093                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10094                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10095                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10096                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10097                 {"port", RTE_ETH_FLOW_PORT},
10098                 {"vxlan", RTE_ETH_FLOW_VXLAN},
10099                 {"geneve", RTE_ETH_FLOW_GENEVE},
10100                 {"nvgre", RTE_ETH_FLOW_NVGRE},
10101         };
10102
10103         for (i = 0; i < RTE_DIM(ftype_table); i++) {
10104                 if (ftype_table[i].ftype == ftype)
10105                         return ftype_table[i].str;
10106         }
10107
10108         return NULL;
10109 }
10110
10111 static void
10112 cmd_get_hash_global_config_parsed(void *parsed_result,
10113                                   __rte_unused struct cmdline *cl,
10114                                   __rte_unused void *data)
10115 {
10116         struct cmd_get_hash_global_config_result *res = parsed_result;
10117         struct rte_eth_hash_filter_info info;
10118         uint32_t idx, offset;
10119         uint16_t i;
10120         char *str;
10121         int ret;
10122
10123         if (rte_eth_dev_filter_supported(res->port_id,
10124                         RTE_ETH_FILTER_HASH) < 0) {
10125                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10126                                                         res->port_id);
10127                 return;
10128         }
10129
10130         memset(&info, 0, sizeof(info));
10131         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10132         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10133                                         RTE_ETH_FILTER_GET, &info);
10134         if (ret < 0) {
10135                 printf("Cannot get hash global configurations by port %d\n",
10136                                                         res->port_id);
10137                 return;
10138         }
10139
10140         switch (info.info.global_conf.hash_func) {
10141         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
10142                 printf("Hash function is Toeplitz\n");
10143                 break;
10144         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
10145                 printf("Hash function is Simple XOR\n");
10146                 break;
10147         default:
10148                 printf("Unknown hash function\n");
10149                 break;
10150         }
10151
10152         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
10153                 idx = i / UINT32_BIT;
10154                 offset = i % UINT32_BIT;
10155                 if (!(info.info.global_conf.valid_bit_mask[idx] &
10156                                                 (1UL << offset)))
10157                         continue;
10158                 str = flowtype_to_str(i);
10159                 if (!str)
10160                         continue;
10161                 printf("Symmetric hash is %s globally for flow type %s "
10162                                                         "by port %d\n",
10163                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
10164                         (1UL << offset)) ? "enabled" : "disabled"), str,
10165                                                         res->port_id);
10166         }
10167 }
10168
10169 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
10170         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
10171                 get_hash_global_config, "get_hash_global_config");
10172 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
10173         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
10174                 port_id, UINT8);
10175
10176 cmdline_parse_inst_t cmd_get_hash_global_config = {
10177         .f = cmd_get_hash_global_config_parsed,
10178         .data = NULL,
10179         .help_str = "get_hash_global_config <port_id>",
10180         .tokens = {
10181                 (void *)&cmd_get_hash_global_config_all,
10182                 (void *)&cmd_get_hash_global_config_port_id,
10183                 NULL,
10184         },
10185 };
10186
10187 /* Set global config of hash function */
10188 struct cmd_set_hash_global_config_result {
10189         cmdline_fixed_string_t set_hash_global_config;
10190         uint8_t port_id;
10191         cmdline_fixed_string_t hash_func;
10192         cmdline_fixed_string_t flow_type;
10193         cmdline_fixed_string_t enable;
10194 };
10195
10196 static void
10197 cmd_set_hash_global_config_parsed(void *parsed_result,
10198                                   __rte_unused struct cmdline *cl,
10199                                   __rte_unused void *data)
10200 {
10201         struct cmd_set_hash_global_config_result *res = parsed_result;
10202         struct rte_eth_hash_filter_info info;
10203         uint32_t ftype, idx, offset;
10204         int ret;
10205
10206         if (rte_eth_dev_filter_supported(res->port_id,
10207                                 RTE_ETH_FILTER_HASH) < 0) {
10208                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10209                                                         res->port_id);
10210                 return;
10211         }
10212         memset(&info, 0, sizeof(info));
10213         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10214         if (!strcmp(res->hash_func, "toeplitz"))
10215                 info.info.global_conf.hash_func =
10216                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
10217         else if (!strcmp(res->hash_func, "simple_xor"))
10218                 info.info.global_conf.hash_func =
10219                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
10220         else if (!strcmp(res->hash_func, "default"))
10221                 info.info.global_conf.hash_func =
10222                         RTE_ETH_HASH_FUNCTION_DEFAULT;
10223
10224         ftype = str2flowtype(res->flow_type);
10225         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
10226         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
10227         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
10228         if (!strcmp(res->enable, "enable"))
10229                 info.info.global_conf.sym_hash_enable_mask[idx] |=
10230                                                 (1UL << offset);
10231         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10232                                         RTE_ETH_FILTER_SET, &info);
10233         if (ret < 0)
10234                 printf("Cannot set global hash configurations by port %d\n",
10235                                                         res->port_id);
10236         else
10237                 printf("Global hash configurations have been set "
10238                         "succcessfully by port %d\n", res->port_id);
10239 }
10240
10241 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
10242         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10243                 set_hash_global_config, "set_hash_global_config");
10244 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
10245         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
10246                 port_id, UINT8);
10247 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
10248         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10249                 hash_func, "toeplitz#simple_xor#default");
10250 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
10251         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10252                 flow_type,
10253                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
10254                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10255 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
10256         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10257                 enable, "enable#disable");
10258
10259 cmdline_parse_inst_t cmd_set_hash_global_config = {
10260         .f = cmd_set_hash_global_config_parsed,
10261         .data = NULL,
10262         .help_str = "set_hash_global_config <port_id> "
10263                 "toeplitz|simple_xor|default "
10264                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10265                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
10266                 "l2_payload enable|disable",
10267         .tokens = {
10268                 (void *)&cmd_set_hash_global_config_all,
10269                 (void *)&cmd_set_hash_global_config_port_id,
10270                 (void *)&cmd_set_hash_global_config_hash_func,
10271                 (void *)&cmd_set_hash_global_config_flow_type,
10272                 (void *)&cmd_set_hash_global_config_enable,
10273                 NULL,
10274         },
10275 };
10276
10277 /* Set hash input set */
10278 struct cmd_set_hash_input_set_result {
10279         cmdline_fixed_string_t set_hash_input_set;
10280         uint8_t port_id;
10281         cmdline_fixed_string_t flow_type;
10282         cmdline_fixed_string_t inset_field;
10283         cmdline_fixed_string_t select;
10284 };
10285
10286 static enum rte_eth_input_set_field
10287 str2inset(char *string)
10288 {
10289         uint16_t i;
10290
10291         static const struct {
10292                 char str[32];
10293                 enum rte_eth_input_set_field inset;
10294         } inset_table[] = {
10295                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
10296                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
10297                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
10298                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
10299                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
10300                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
10301                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
10302                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
10303                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
10304                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
10305                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
10306                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
10307                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
10308                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
10309                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
10310                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
10311                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
10312                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
10313                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
10314                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
10315                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
10316                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
10317                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
10318                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
10319                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
10320                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
10321                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
10322                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
10323                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
10324                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
10325                 {"none", RTE_ETH_INPUT_SET_NONE},
10326         };
10327
10328         for (i = 0; i < RTE_DIM(inset_table); i++) {
10329                 if (!strcmp(string, inset_table[i].str))
10330                         return inset_table[i].inset;
10331         }
10332
10333         return RTE_ETH_INPUT_SET_UNKNOWN;
10334 }
10335
10336 static void
10337 cmd_set_hash_input_set_parsed(void *parsed_result,
10338                               __rte_unused struct cmdline *cl,
10339                               __rte_unused void *data)
10340 {
10341         struct cmd_set_hash_input_set_result *res = parsed_result;
10342         struct rte_eth_hash_filter_info info;
10343
10344         memset(&info, 0, sizeof(info));
10345         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
10346         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10347         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10348         info.info.input_set_conf.inset_size = 1;
10349         if (!strcmp(res->select, "select"))
10350                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10351         else if (!strcmp(res->select, "add"))
10352                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10353         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10354                                 RTE_ETH_FILTER_SET, &info);
10355 }
10356
10357 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
10358         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10359                 set_hash_input_set, "set_hash_input_set");
10360 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
10361         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
10362                 port_id, UINT8);
10363 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
10364         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10365                 flow_type,
10366                 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10367                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10368 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
10369         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10370                 inset_field,
10371                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10372                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
10373                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
10374                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
10375                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
10376                 "fld-8th#none");
10377 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
10378         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10379                 select, "select#add");
10380
10381 cmdline_parse_inst_t cmd_set_hash_input_set = {
10382         .f = cmd_set_hash_input_set_parsed,
10383         .data = NULL,
10384         .help_str = "set_hash_input_set <port_id> "
10385         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10386         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10387         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
10388         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
10389         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
10390         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
10391         "fld-7th|fld-8th|none select|add",
10392         .tokens = {
10393                 (void *)&cmd_set_hash_input_set_cmd,
10394                 (void *)&cmd_set_hash_input_set_port_id,
10395                 (void *)&cmd_set_hash_input_set_flow_type,
10396                 (void *)&cmd_set_hash_input_set_field,
10397                 (void *)&cmd_set_hash_input_set_select,
10398                 NULL,
10399         },
10400 };
10401
10402 /* Set flow director input set */
10403 struct cmd_set_fdir_input_set_result {
10404         cmdline_fixed_string_t set_fdir_input_set;
10405         uint8_t port_id;
10406         cmdline_fixed_string_t flow_type;
10407         cmdline_fixed_string_t inset_field;
10408         cmdline_fixed_string_t select;
10409 };
10410
10411 static void
10412 cmd_set_fdir_input_set_parsed(void *parsed_result,
10413         __rte_unused struct cmdline *cl,
10414         __rte_unused void *data)
10415 {
10416         struct cmd_set_fdir_input_set_result *res = parsed_result;
10417         struct rte_eth_fdir_filter_info info;
10418
10419         memset(&info, 0, sizeof(info));
10420         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
10421         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10422         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10423         info.info.input_set_conf.inset_size = 1;
10424         if (!strcmp(res->select, "select"))
10425                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10426         else if (!strcmp(res->select, "add"))
10427                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10428         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10429                 RTE_ETH_FILTER_SET, &info);
10430 }
10431
10432 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
10433         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10434         set_fdir_input_set, "set_fdir_input_set");
10435 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
10436         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
10437         port_id, UINT8);
10438 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
10439         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10440         flow_type,
10441         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10442         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10443 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
10444         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10445         inset_field,
10446         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10447         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
10448         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
10449         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
10450         "sctp-veri-tag#none");
10451 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
10452         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10453         select, "select#add");
10454
10455 cmdline_parse_inst_t cmd_set_fdir_input_set = {
10456         .f = cmd_set_fdir_input_set_parsed,
10457         .data = NULL,
10458         .help_str = "set_fdir_input_set <port_id> "
10459         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10460         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10461         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
10462         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
10463         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
10464         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
10465         "sctp-veri-tag|none select|add",
10466         .tokens = {
10467                 (void *)&cmd_set_fdir_input_set_cmd,
10468                 (void *)&cmd_set_fdir_input_set_port_id,
10469                 (void *)&cmd_set_fdir_input_set_flow_type,
10470                 (void *)&cmd_set_fdir_input_set_field,
10471                 (void *)&cmd_set_fdir_input_set_select,
10472                 NULL,
10473         },
10474 };
10475
10476 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10477 struct cmd_mcast_addr_result {
10478         cmdline_fixed_string_t mcast_addr_cmd;
10479         cmdline_fixed_string_t what;
10480         uint8_t port_num;
10481         struct ether_addr mc_addr;
10482 };
10483
10484 static void cmd_mcast_addr_parsed(void *parsed_result,
10485                 __attribute__((unused)) struct cmdline *cl,
10486                 __attribute__((unused)) void *data)
10487 {
10488         struct cmd_mcast_addr_result *res = parsed_result;
10489
10490         if (!is_multicast_ether_addr(&res->mc_addr)) {
10491                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10492                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10493                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10494                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10495                 return;
10496         }
10497         if (strcmp(res->what, "add") == 0)
10498                 mcast_addr_add(res->port_num, &res->mc_addr);
10499         else
10500                 mcast_addr_remove(res->port_num, &res->mc_addr);
10501 }
10502
10503 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10504         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10505                                  mcast_addr_cmd, "mcast_addr");
10506 cmdline_parse_token_string_t cmd_mcast_addr_what =
10507         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10508                                  "add#remove");
10509 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10510         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
10511 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10512         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10513
10514 cmdline_parse_inst_t cmd_mcast_addr = {
10515         .f = cmd_mcast_addr_parsed,
10516         .data = (void *)0,
10517         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10518                 "Add/Remove multicast MAC address on port_id",
10519         .tokens = {
10520                 (void *)&cmd_mcast_addr_cmd,
10521                 (void *)&cmd_mcast_addr_what,
10522                 (void *)&cmd_mcast_addr_portnum,
10523                 (void *)&cmd_mcast_addr_addr,
10524                 NULL,
10525         },
10526 };
10527
10528 /* l2 tunnel config
10529  * only support E-tag now.
10530  */
10531
10532 /* Ether type config */
10533 struct cmd_config_l2_tunnel_eth_type_result {
10534         cmdline_fixed_string_t port;
10535         cmdline_fixed_string_t config;
10536         cmdline_fixed_string_t all;
10537         uint8_t id;
10538         cmdline_fixed_string_t l2_tunnel;
10539         cmdline_fixed_string_t l2_tunnel_type;
10540         cmdline_fixed_string_t eth_type;
10541         uint16_t eth_type_val;
10542 };
10543
10544 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10545         TOKEN_STRING_INITIALIZER
10546                 (struct cmd_config_l2_tunnel_eth_type_result,
10547                  port, "port");
10548 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10549         TOKEN_STRING_INITIALIZER
10550                 (struct cmd_config_l2_tunnel_eth_type_result,
10551                  config, "config");
10552 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10553         TOKEN_STRING_INITIALIZER
10554                 (struct cmd_config_l2_tunnel_eth_type_result,
10555                  all, "all");
10556 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10557         TOKEN_NUM_INITIALIZER
10558                 (struct cmd_config_l2_tunnel_eth_type_result,
10559                  id, UINT8);
10560 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10561         TOKEN_STRING_INITIALIZER
10562                 (struct cmd_config_l2_tunnel_eth_type_result,
10563                  l2_tunnel, "l2-tunnel");
10564 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10565         TOKEN_STRING_INITIALIZER
10566                 (struct cmd_config_l2_tunnel_eth_type_result,
10567                  l2_tunnel_type, "E-tag");
10568 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10569         TOKEN_STRING_INITIALIZER
10570                 (struct cmd_config_l2_tunnel_eth_type_result,
10571                  eth_type, "ether-type");
10572 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10573         TOKEN_NUM_INITIALIZER
10574                 (struct cmd_config_l2_tunnel_eth_type_result,
10575                  eth_type_val, UINT16);
10576
10577 static enum rte_eth_tunnel_type
10578 str2fdir_l2_tunnel_type(char *string)
10579 {
10580         uint32_t i = 0;
10581
10582         static const struct {
10583                 char str[32];
10584                 enum rte_eth_tunnel_type type;
10585         } l2_tunnel_type_str[] = {
10586                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10587         };
10588
10589         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10590                 if (!strcmp(l2_tunnel_type_str[i].str, string))
10591                         return l2_tunnel_type_str[i].type;
10592         }
10593         return RTE_TUNNEL_TYPE_NONE;
10594 }
10595
10596 /* ether type config for all ports */
10597 static void
10598 cmd_config_l2_tunnel_eth_type_all_parsed
10599         (void *parsed_result,
10600          __attribute__((unused)) struct cmdline *cl,
10601          __attribute__((unused)) void *data)
10602 {
10603         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10604         struct rte_eth_l2_tunnel_conf entry;
10605         portid_t pid;
10606
10607         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10608         entry.ether_type = res->eth_type_val;
10609
10610         RTE_ETH_FOREACH_DEV(pid) {
10611                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10612         }
10613 }
10614
10615 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10616         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
10617         .data = NULL,
10618         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
10619         .tokens = {
10620                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10621                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10622                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
10623                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10624                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10625                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10626                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10627                 NULL,
10628         },
10629 };
10630
10631 /* ether type config for a specific port */
10632 static void
10633 cmd_config_l2_tunnel_eth_type_specific_parsed(
10634         void *parsed_result,
10635         __attribute__((unused)) struct cmdline *cl,
10636         __attribute__((unused)) void *data)
10637 {
10638         struct cmd_config_l2_tunnel_eth_type_result *res =
10639                  parsed_result;
10640         struct rte_eth_l2_tunnel_conf entry;
10641
10642         if (port_id_is_invalid(res->id, ENABLED_WARN))
10643                 return;
10644
10645         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10646         entry.ether_type = res->eth_type_val;
10647
10648         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10649 }
10650
10651 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10652         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
10653         .data = NULL,
10654         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
10655         .tokens = {
10656                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10657                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10658                 (void *)&cmd_config_l2_tunnel_eth_type_id,
10659                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10660                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10661                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10662                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10663                 NULL,
10664         },
10665 };
10666
10667 /* Enable/disable l2 tunnel */
10668 struct cmd_config_l2_tunnel_en_dis_result {
10669         cmdline_fixed_string_t port;
10670         cmdline_fixed_string_t config;
10671         cmdline_fixed_string_t all;
10672         uint8_t id;
10673         cmdline_fixed_string_t l2_tunnel;
10674         cmdline_fixed_string_t l2_tunnel_type;
10675         cmdline_fixed_string_t en_dis;
10676 };
10677
10678 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
10679         TOKEN_STRING_INITIALIZER
10680                 (struct cmd_config_l2_tunnel_en_dis_result,
10681                  port, "port");
10682 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
10683         TOKEN_STRING_INITIALIZER
10684                 (struct cmd_config_l2_tunnel_en_dis_result,
10685                  config, "config");
10686 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
10687         TOKEN_STRING_INITIALIZER
10688                 (struct cmd_config_l2_tunnel_en_dis_result,
10689                  all, "all");
10690 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
10691         TOKEN_NUM_INITIALIZER
10692                 (struct cmd_config_l2_tunnel_en_dis_result,
10693                  id, UINT8);
10694 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
10695         TOKEN_STRING_INITIALIZER
10696                 (struct cmd_config_l2_tunnel_en_dis_result,
10697                  l2_tunnel, "l2-tunnel");
10698 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
10699         TOKEN_STRING_INITIALIZER
10700                 (struct cmd_config_l2_tunnel_en_dis_result,
10701                  l2_tunnel_type, "E-tag");
10702 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
10703         TOKEN_STRING_INITIALIZER
10704                 (struct cmd_config_l2_tunnel_en_dis_result,
10705                  en_dis, "enable#disable");
10706
10707 /* enable/disable l2 tunnel for all ports */
10708 static void
10709 cmd_config_l2_tunnel_en_dis_all_parsed(
10710         void *parsed_result,
10711         __attribute__((unused)) struct cmdline *cl,
10712         __attribute__((unused)) void *data)
10713 {
10714         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
10715         struct rte_eth_l2_tunnel_conf entry;
10716         portid_t pid;
10717         uint8_t en;
10718
10719         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10720
10721         if (!strcmp("enable", res->en_dis))
10722                 en = 1;
10723         else
10724                 en = 0;
10725
10726         RTE_ETH_FOREACH_DEV(pid) {
10727                 rte_eth_dev_l2_tunnel_offload_set(pid,
10728                                                   &entry,
10729                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10730                                                   en);
10731         }
10732 }
10733
10734 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
10735         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
10736         .data = NULL,
10737         .help_str = "port config all l2-tunnel E-tag enable|disable",
10738         .tokens = {
10739                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10740                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10741                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
10742                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10743                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10744                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10745                 NULL,
10746         },
10747 };
10748
10749 /* enable/disable l2 tunnel for a port */
10750 static void
10751 cmd_config_l2_tunnel_en_dis_specific_parsed(
10752         void *parsed_result,
10753         __attribute__((unused)) struct cmdline *cl,
10754         __attribute__((unused)) void *data)
10755 {
10756         struct cmd_config_l2_tunnel_en_dis_result *res =
10757                 parsed_result;
10758         struct rte_eth_l2_tunnel_conf entry;
10759
10760         if (port_id_is_invalid(res->id, ENABLED_WARN))
10761                 return;
10762
10763         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10764
10765         if (!strcmp("enable", res->en_dis))
10766                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10767                                                   &entry,
10768                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10769                                                   1);
10770         else
10771                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10772                                                   &entry,
10773                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10774                                                   0);
10775 }
10776
10777 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
10778         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
10779         .data = NULL,
10780         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
10781         .tokens = {
10782                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10783                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10784                 (void *)&cmd_config_l2_tunnel_en_dis_id,
10785                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10786                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10787                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10788                 NULL,
10789         },
10790 };
10791
10792 /* E-tag configuration */
10793
10794 /* Common result structure for all E-tag configuration */
10795 struct cmd_config_e_tag_result {
10796         cmdline_fixed_string_t e_tag;
10797         cmdline_fixed_string_t set;
10798         cmdline_fixed_string_t insertion;
10799         cmdline_fixed_string_t stripping;
10800         cmdline_fixed_string_t forwarding;
10801         cmdline_fixed_string_t filter;
10802         cmdline_fixed_string_t add;
10803         cmdline_fixed_string_t del;
10804         cmdline_fixed_string_t on;
10805         cmdline_fixed_string_t off;
10806         cmdline_fixed_string_t on_off;
10807         cmdline_fixed_string_t port_tag_id;
10808         uint32_t port_tag_id_val;
10809         cmdline_fixed_string_t e_tag_id;
10810         uint16_t e_tag_id_val;
10811         cmdline_fixed_string_t dst_pool;
10812         uint8_t dst_pool_val;
10813         cmdline_fixed_string_t port;
10814         uint8_t port_id;
10815         cmdline_fixed_string_t vf;
10816         uint8_t vf_id;
10817 };
10818
10819 /* Common CLI fields for all E-tag configuration */
10820 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
10821         TOKEN_STRING_INITIALIZER
10822                 (struct cmd_config_e_tag_result,
10823                  e_tag, "E-tag");
10824 cmdline_parse_token_string_t cmd_config_e_tag_set =
10825         TOKEN_STRING_INITIALIZER
10826                 (struct cmd_config_e_tag_result,
10827                  set, "set");
10828 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
10829         TOKEN_STRING_INITIALIZER
10830                 (struct cmd_config_e_tag_result,
10831                  insertion, "insertion");
10832 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
10833         TOKEN_STRING_INITIALIZER
10834                 (struct cmd_config_e_tag_result,
10835                  stripping, "stripping");
10836 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
10837         TOKEN_STRING_INITIALIZER
10838                 (struct cmd_config_e_tag_result,
10839                  forwarding, "forwarding");
10840 cmdline_parse_token_string_t cmd_config_e_tag_filter =
10841         TOKEN_STRING_INITIALIZER
10842                 (struct cmd_config_e_tag_result,
10843                  filter, "filter");
10844 cmdline_parse_token_string_t cmd_config_e_tag_add =
10845         TOKEN_STRING_INITIALIZER
10846                 (struct cmd_config_e_tag_result,
10847                  add, "add");
10848 cmdline_parse_token_string_t cmd_config_e_tag_del =
10849         TOKEN_STRING_INITIALIZER
10850                 (struct cmd_config_e_tag_result,
10851                  del, "del");
10852 cmdline_parse_token_string_t cmd_config_e_tag_on =
10853         TOKEN_STRING_INITIALIZER
10854                 (struct cmd_config_e_tag_result,
10855                  on, "on");
10856 cmdline_parse_token_string_t cmd_config_e_tag_off =
10857         TOKEN_STRING_INITIALIZER
10858                 (struct cmd_config_e_tag_result,
10859                  off, "off");
10860 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
10861         TOKEN_STRING_INITIALIZER
10862                 (struct cmd_config_e_tag_result,
10863                  on_off, "on#off");
10864 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
10865         TOKEN_STRING_INITIALIZER
10866                 (struct cmd_config_e_tag_result,
10867                  port_tag_id, "port-tag-id");
10868 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
10869         TOKEN_NUM_INITIALIZER
10870                 (struct cmd_config_e_tag_result,
10871                  port_tag_id_val, UINT32);
10872 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
10873         TOKEN_STRING_INITIALIZER
10874                 (struct cmd_config_e_tag_result,
10875                  e_tag_id, "e-tag-id");
10876 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
10877         TOKEN_NUM_INITIALIZER
10878                 (struct cmd_config_e_tag_result,
10879                  e_tag_id_val, UINT16);
10880 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
10881         TOKEN_STRING_INITIALIZER
10882                 (struct cmd_config_e_tag_result,
10883                  dst_pool, "dst-pool");
10884 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
10885         TOKEN_NUM_INITIALIZER
10886                 (struct cmd_config_e_tag_result,
10887                  dst_pool_val, UINT8);
10888 cmdline_parse_token_string_t cmd_config_e_tag_port =
10889         TOKEN_STRING_INITIALIZER
10890                 (struct cmd_config_e_tag_result,
10891                  port, "port");
10892 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
10893         TOKEN_NUM_INITIALIZER
10894                 (struct cmd_config_e_tag_result,
10895                  port_id, UINT8);
10896 cmdline_parse_token_string_t cmd_config_e_tag_vf =
10897         TOKEN_STRING_INITIALIZER
10898                 (struct cmd_config_e_tag_result,
10899                  vf, "vf");
10900 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
10901         TOKEN_NUM_INITIALIZER
10902                 (struct cmd_config_e_tag_result,
10903                  vf_id, UINT8);
10904
10905 /* E-tag insertion configuration */
10906 static void
10907 cmd_config_e_tag_insertion_en_parsed(
10908         void *parsed_result,
10909         __attribute__((unused)) struct cmdline *cl,
10910         __attribute__((unused)) void *data)
10911 {
10912         struct cmd_config_e_tag_result *res =
10913                 parsed_result;
10914         struct rte_eth_l2_tunnel_conf entry;
10915
10916         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10917                 return;
10918
10919         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10920         entry.tunnel_id = res->port_tag_id_val;
10921         entry.vf_id = res->vf_id;
10922         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10923                                           &entry,
10924                                           ETH_L2_TUNNEL_INSERTION_MASK,
10925                                           1);
10926 }
10927
10928 static void
10929 cmd_config_e_tag_insertion_dis_parsed(
10930         void *parsed_result,
10931         __attribute__((unused)) struct cmdline *cl,
10932         __attribute__((unused)) void *data)
10933 {
10934         struct cmd_config_e_tag_result *res =
10935                 parsed_result;
10936         struct rte_eth_l2_tunnel_conf entry;
10937
10938         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10939                 return;
10940
10941         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10942         entry.vf_id = res->vf_id;
10943
10944         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10945                                           &entry,
10946                                           ETH_L2_TUNNEL_INSERTION_MASK,
10947                                           0);
10948 }
10949
10950 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
10951         .f = cmd_config_e_tag_insertion_en_parsed,
10952         .data = NULL,
10953         .help_str = "E-tag ... : E-tag insertion enable",
10954         .tokens = {
10955                 (void *)&cmd_config_e_tag_e_tag,
10956                 (void *)&cmd_config_e_tag_set,
10957                 (void *)&cmd_config_e_tag_insertion,
10958                 (void *)&cmd_config_e_tag_on,
10959                 (void *)&cmd_config_e_tag_port_tag_id,
10960                 (void *)&cmd_config_e_tag_port_tag_id_val,
10961                 (void *)&cmd_config_e_tag_port,
10962                 (void *)&cmd_config_e_tag_port_id,
10963                 (void *)&cmd_config_e_tag_vf,
10964                 (void *)&cmd_config_e_tag_vf_id,
10965                 NULL,
10966         },
10967 };
10968
10969 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
10970         .f = cmd_config_e_tag_insertion_dis_parsed,
10971         .data = NULL,
10972         .help_str = "E-tag ... : E-tag insertion disable",
10973         .tokens = {
10974                 (void *)&cmd_config_e_tag_e_tag,
10975                 (void *)&cmd_config_e_tag_set,
10976                 (void *)&cmd_config_e_tag_insertion,
10977                 (void *)&cmd_config_e_tag_off,
10978                 (void *)&cmd_config_e_tag_port,
10979                 (void *)&cmd_config_e_tag_port_id,
10980                 (void *)&cmd_config_e_tag_vf,
10981                 (void *)&cmd_config_e_tag_vf_id,
10982                 NULL,
10983         },
10984 };
10985
10986 /* E-tag stripping configuration */
10987 static void
10988 cmd_config_e_tag_stripping_parsed(
10989         void *parsed_result,
10990         __attribute__((unused)) struct cmdline *cl,
10991         __attribute__((unused)) void *data)
10992 {
10993         struct cmd_config_e_tag_result *res =
10994                 parsed_result;
10995         struct rte_eth_l2_tunnel_conf entry;
10996
10997         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10998                 return;
10999
11000         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11001
11002         if (!strcmp(res->on_off, "on"))
11003                 rte_eth_dev_l2_tunnel_offload_set
11004                         (res->port_id,
11005                          &entry,
11006                          ETH_L2_TUNNEL_STRIPPING_MASK,
11007                          1);
11008         else
11009                 rte_eth_dev_l2_tunnel_offload_set
11010                         (res->port_id,
11011                          &entry,
11012                          ETH_L2_TUNNEL_STRIPPING_MASK,
11013                          0);
11014 }
11015
11016 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11017         .f = cmd_config_e_tag_stripping_parsed,
11018         .data = NULL,
11019         .help_str = "E-tag ... : E-tag stripping enable/disable",
11020         .tokens = {
11021                 (void *)&cmd_config_e_tag_e_tag,
11022                 (void *)&cmd_config_e_tag_set,
11023                 (void *)&cmd_config_e_tag_stripping,
11024                 (void *)&cmd_config_e_tag_on_off,
11025                 (void *)&cmd_config_e_tag_port,
11026                 (void *)&cmd_config_e_tag_port_id,
11027                 NULL,
11028         },
11029 };
11030
11031 /* E-tag forwarding configuration */
11032 static void
11033 cmd_config_e_tag_forwarding_parsed(
11034         void *parsed_result,
11035         __attribute__((unused)) struct cmdline *cl,
11036         __attribute__((unused)) void *data)
11037 {
11038         struct cmd_config_e_tag_result *res = parsed_result;
11039         struct rte_eth_l2_tunnel_conf entry;
11040
11041         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11042                 return;
11043
11044         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11045
11046         if (!strcmp(res->on_off, "on"))
11047                 rte_eth_dev_l2_tunnel_offload_set
11048                         (res->port_id,
11049                          &entry,
11050                          ETH_L2_TUNNEL_FORWARDING_MASK,
11051                          1);
11052         else
11053                 rte_eth_dev_l2_tunnel_offload_set
11054                         (res->port_id,
11055                          &entry,
11056                          ETH_L2_TUNNEL_FORWARDING_MASK,
11057                          0);
11058 }
11059
11060 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11061         .f = cmd_config_e_tag_forwarding_parsed,
11062         .data = NULL,
11063         .help_str = "E-tag ... : E-tag forwarding enable/disable",
11064         .tokens = {
11065                 (void *)&cmd_config_e_tag_e_tag,
11066                 (void *)&cmd_config_e_tag_set,
11067                 (void *)&cmd_config_e_tag_forwarding,
11068                 (void *)&cmd_config_e_tag_on_off,
11069                 (void *)&cmd_config_e_tag_port,
11070                 (void *)&cmd_config_e_tag_port_id,
11071                 NULL,
11072         },
11073 };
11074
11075 /* E-tag filter configuration */
11076 static void
11077 cmd_config_e_tag_filter_add_parsed(
11078         void *parsed_result,
11079         __attribute__((unused)) struct cmdline *cl,
11080         __attribute__((unused)) void *data)
11081 {
11082         struct cmd_config_e_tag_result *res = parsed_result;
11083         struct rte_eth_l2_tunnel_conf entry;
11084         int ret = 0;
11085
11086         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11087                 return;
11088
11089         if (res->e_tag_id_val > 0x3fff) {
11090                 printf("e-tag-id must be equal or less than 0x3fff.\n");
11091                 return;
11092         }
11093
11094         ret = rte_eth_dev_filter_supported(res->port_id,
11095                                            RTE_ETH_FILTER_L2_TUNNEL);
11096         if (ret < 0) {
11097                 printf("E-tag filter is not supported on port %u.\n",
11098                        res->port_id);
11099                 return;
11100         }
11101
11102         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11103         entry.tunnel_id = res->e_tag_id_val;
11104         entry.pool = res->dst_pool_val;
11105
11106         ret = rte_eth_dev_filter_ctrl(res->port_id,
11107                                       RTE_ETH_FILTER_L2_TUNNEL,
11108                                       RTE_ETH_FILTER_ADD,
11109                                       &entry);
11110         if (ret < 0)
11111                 printf("E-tag filter programming error: (%s)\n",
11112                        strerror(-ret));
11113 }
11114
11115 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
11116         .f = cmd_config_e_tag_filter_add_parsed,
11117         .data = NULL,
11118         .help_str = "E-tag ... : E-tag filter add",
11119         .tokens = {
11120                 (void *)&cmd_config_e_tag_e_tag,
11121                 (void *)&cmd_config_e_tag_set,
11122                 (void *)&cmd_config_e_tag_filter,
11123                 (void *)&cmd_config_e_tag_add,
11124                 (void *)&cmd_config_e_tag_e_tag_id,
11125                 (void *)&cmd_config_e_tag_e_tag_id_val,
11126                 (void *)&cmd_config_e_tag_dst_pool,
11127                 (void *)&cmd_config_e_tag_dst_pool_val,
11128                 (void *)&cmd_config_e_tag_port,
11129                 (void *)&cmd_config_e_tag_port_id,
11130                 NULL,
11131         },
11132 };
11133
11134 static void
11135 cmd_config_e_tag_filter_del_parsed(
11136         void *parsed_result,
11137         __attribute__((unused)) struct cmdline *cl,
11138         __attribute__((unused)) void *data)
11139 {
11140         struct cmd_config_e_tag_result *res = parsed_result;
11141         struct rte_eth_l2_tunnel_conf entry;
11142         int ret = 0;
11143
11144         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11145                 return;
11146
11147         if (res->e_tag_id_val > 0x3fff) {
11148                 printf("e-tag-id must be less than 0x3fff.\n");
11149                 return;
11150         }
11151
11152         ret = rte_eth_dev_filter_supported(res->port_id,
11153                                            RTE_ETH_FILTER_L2_TUNNEL);
11154         if (ret < 0) {
11155                 printf("E-tag filter is not supported on port %u.\n",
11156                        res->port_id);
11157                 return;
11158         }
11159
11160         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11161         entry.tunnel_id = res->e_tag_id_val;
11162
11163         ret = rte_eth_dev_filter_ctrl(res->port_id,
11164                                       RTE_ETH_FILTER_L2_TUNNEL,
11165                                       RTE_ETH_FILTER_DELETE,
11166                                       &entry);
11167         if (ret < 0)
11168                 printf("E-tag filter programming error: (%s)\n",
11169                        strerror(-ret));
11170 }
11171
11172 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
11173         .f = cmd_config_e_tag_filter_del_parsed,
11174         .data = NULL,
11175         .help_str = "E-tag ... : E-tag filter delete",
11176         .tokens = {
11177                 (void *)&cmd_config_e_tag_e_tag,
11178                 (void *)&cmd_config_e_tag_set,
11179                 (void *)&cmd_config_e_tag_filter,
11180                 (void *)&cmd_config_e_tag_del,
11181                 (void *)&cmd_config_e_tag_e_tag_id,
11182                 (void *)&cmd_config_e_tag_e_tag_id_val,
11183                 (void *)&cmd_config_e_tag_port,
11184                 (void *)&cmd_config_e_tag_port_id,
11185                 NULL,
11186         },
11187 };
11188
11189 /* vf vlan anti spoof configuration */
11190
11191 /* Common result structure for vf vlan anti spoof */
11192 struct cmd_vf_vlan_anti_spoof_result {
11193         cmdline_fixed_string_t set;
11194         cmdline_fixed_string_t vf;
11195         cmdline_fixed_string_t vlan;
11196         cmdline_fixed_string_t antispoof;
11197         uint8_t port_id;
11198         uint32_t vf_id;
11199         cmdline_fixed_string_t on_off;
11200 };
11201
11202 /* Common CLI fields for vf vlan anti spoof enable disable */
11203 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11204         TOKEN_STRING_INITIALIZER
11205                 (struct cmd_vf_vlan_anti_spoof_result,
11206                  set, "set");
11207 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11208         TOKEN_STRING_INITIALIZER
11209                 (struct cmd_vf_vlan_anti_spoof_result,
11210                  vf, "vf");
11211 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11212         TOKEN_STRING_INITIALIZER
11213                 (struct cmd_vf_vlan_anti_spoof_result,
11214                  vlan, "vlan");
11215 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11216         TOKEN_STRING_INITIALIZER
11217                 (struct cmd_vf_vlan_anti_spoof_result,
11218                  antispoof, "antispoof");
11219 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11220         TOKEN_NUM_INITIALIZER
11221                 (struct cmd_vf_vlan_anti_spoof_result,
11222                  port_id, UINT8);
11223 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11224         TOKEN_NUM_INITIALIZER
11225                 (struct cmd_vf_vlan_anti_spoof_result,
11226                  vf_id, UINT32);
11227 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11228         TOKEN_STRING_INITIALIZER
11229                 (struct cmd_vf_vlan_anti_spoof_result,
11230                  on_off, "on#off");
11231
11232 static void
11233 cmd_set_vf_vlan_anti_spoof_parsed(
11234         void *parsed_result,
11235         __attribute__((unused)) struct cmdline *cl,
11236         __attribute__((unused)) void *data)
11237 {
11238         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11239         int ret = -ENOTSUP;
11240
11241         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11242
11243         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11244                 return;
11245
11246 #ifdef RTE_LIBRTE_IXGBE_PMD
11247         if (ret == -ENOTSUP)
11248                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11249                                 res->vf_id, is_on);
11250 #endif
11251 #ifdef RTE_LIBRTE_I40E_PMD
11252         if (ret == -ENOTSUP)
11253                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11254                                 res->vf_id, is_on);
11255 #endif
11256 #ifdef RTE_LIBRTE_BNXT_PMD
11257         if (ret == -ENOTSUP)
11258                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11259                                 res->vf_id, is_on);
11260 #endif
11261
11262         switch (ret) {
11263         case 0:
11264                 break;
11265         case -EINVAL:
11266                 printf("invalid vf_id %d\n", res->vf_id);
11267                 break;
11268         case -ENODEV:
11269                 printf("invalid port_id %d\n", res->port_id);
11270                 break;
11271         case -ENOTSUP:
11272                 printf("function not implemented\n");
11273                 break;
11274         default:
11275                 printf("programming error: (%s)\n", strerror(-ret));
11276         }
11277 }
11278
11279 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11280         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11281         .data = NULL,
11282         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11283         .tokens = {
11284                 (void *)&cmd_vf_vlan_anti_spoof_set,
11285                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11286                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11287                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11288                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11289                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11290                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11291                 NULL,
11292         },
11293 };
11294
11295 /* vf mac anti spoof configuration */
11296
11297 /* Common result structure for vf mac anti spoof */
11298 struct cmd_vf_mac_anti_spoof_result {
11299         cmdline_fixed_string_t set;
11300         cmdline_fixed_string_t vf;
11301         cmdline_fixed_string_t mac;
11302         cmdline_fixed_string_t antispoof;
11303         uint8_t port_id;
11304         uint32_t vf_id;
11305         cmdline_fixed_string_t on_off;
11306 };
11307
11308 /* Common CLI fields for vf mac anti spoof enable disable */
11309 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11310         TOKEN_STRING_INITIALIZER
11311                 (struct cmd_vf_mac_anti_spoof_result,
11312                  set, "set");
11313 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11314         TOKEN_STRING_INITIALIZER
11315                 (struct cmd_vf_mac_anti_spoof_result,
11316                  vf, "vf");
11317 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11318         TOKEN_STRING_INITIALIZER
11319                 (struct cmd_vf_mac_anti_spoof_result,
11320                  mac, "mac");
11321 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11322         TOKEN_STRING_INITIALIZER
11323                 (struct cmd_vf_mac_anti_spoof_result,
11324                  antispoof, "antispoof");
11325 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11326         TOKEN_NUM_INITIALIZER
11327                 (struct cmd_vf_mac_anti_spoof_result,
11328                  port_id, UINT8);
11329 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11330         TOKEN_NUM_INITIALIZER
11331                 (struct cmd_vf_mac_anti_spoof_result,
11332                  vf_id, UINT32);
11333 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11334         TOKEN_STRING_INITIALIZER
11335                 (struct cmd_vf_mac_anti_spoof_result,
11336                  on_off, "on#off");
11337
11338 static void
11339 cmd_set_vf_mac_anti_spoof_parsed(
11340         void *parsed_result,
11341         __attribute__((unused)) struct cmdline *cl,
11342         __attribute__((unused)) void *data)
11343 {
11344         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11345         int ret = -ENOTSUP;
11346
11347         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11348
11349         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11350                 return;
11351
11352 #ifdef RTE_LIBRTE_IXGBE_PMD
11353         if (ret == -ENOTSUP)
11354                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11355                         res->vf_id, is_on);
11356 #endif
11357 #ifdef RTE_LIBRTE_I40E_PMD
11358         if (ret == -ENOTSUP)
11359                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11360                         res->vf_id, is_on);
11361 #endif
11362 #ifdef RTE_LIBRTE_BNXT_PMD
11363         if (ret == -ENOTSUP)
11364                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11365                         res->vf_id, is_on);
11366 #endif
11367
11368         switch (ret) {
11369         case 0:
11370                 break;
11371         case -EINVAL:
11372                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11373                 break;
11374         case -ENODEV:
11375                 printf("invalid port_id %d\n", res->port_id);
11376                 break;
11377         case -ENOTSUP:
11378                 printf("function not implemented\n");
11379                 break;
11380         default:
11381                 printf("programming error: (%s)\n", strerror(-ret));
11382         }
11383 }
11384
11385 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11386         .f = cmd_set_vf_mac_anti_spoof_parsed,
11387         .data = NULL,
11388         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11389         .tokens = {
11390                 (void *)&cmd_vf_mac_anti_spoof_set,
11391                 (void *)&cmd_vf_mac_anti_spoof_vf,
11392                 (void *)&cmd_vf_mac_anti_spoof_mac,
11393                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11394                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11395                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11396                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11397                 NULL,
11398         },
11399 };
11400
11401 /* vf vlan strip queue configuration */
11402
11403 /* Common result structure for vf mac anti spoof */
11404 struct cmd_vf_vlan_stripq_result {
11405         cmdline_fixed_string_t set;
11406         cmdline_fixed_string_t vf;
11407         cmdline_fixed_string_t vlan;
11408         cmdline_fixed_string_t stripq;
11409         uint8_t port_id;
11410         uint16_t vf_id;
11411         cmdline_fixed_string_t on_off;
11412 };
11413
11414 /* Common CLI fields for vf vlan strip enable disable */
11415 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11416         TOKEN_STRING_INITIALIZER
11417                 (struct cmd_vf_vlan_stripq_result,
11418                  set, "set");
11419 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11420         TOKEN_STRING_INITIALIZER
11421                 (struct cmd_vf_vlan_stripq_result,
11422                  vf, "vf");
11423 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11424         TOKEN_STRING_INITIALIZER
11425                 (struct cmd_vf_vlan_stripq_result,
11426                  vlan, "vlan");
11427 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11428         TOKEN_STRING_INITIALIZER
11429                 (struct cmd_vf_vlan_stripq_result,
11430                  stripq, "stripq");
11431 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11432         TOKEN_NUM_INITIALIZER
11433                 (struct cmd_vf_vlan_stripq_result,
11434                  port_id, UINT8);
11435 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11436         TOKEN_NUM_INITIALIZER
11437                 (struct cmd_vf_vlan_stripq_result,
11438                  vf_id, UINT16);
11439 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11440         TOKEN_STRING_INITIALIZER
11441                 (struct cmd_vf_vlan_stripq_result,
11442                  on_off, "on#off");
11443
11444 static void
11445 cmd_set_vf_vlan_stripq_parsed(
11446         void *parsed_result,
11447         __attribute__((unused)) struct cmdline *cl,
11448         __attribute__((unused)) void *data)
11449 {
11450         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11451         int ret = -ENOTSUP;
11452
11453         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11454
11455         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11456                 return;
11457
11458 #ifdef RTE_LIBRTE_IXGBE_PMD
11459         if (ret == -ENOTSUP)
11460                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11461                         res->vf_id, is_on);
11462 #endif
11463 #ifdef RTE_LIBRTE_I40E_PMD
11464         if (ret == -ENOTSUP)
11465                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11466                         res->vf_id, is_on);
11467 #endif
11468 #ifdef RTE_LIBRTE_BNXT_PMD
11469         if (ret == -ENOTSUP)
11470                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11471                         res->vf_id, is_on);
11472 #endif
11473
11474         switch (ret) {
11475         case 0:
11476                 break;
11477         case -EINVAL:
11478                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11479                 break;
11480         case -ENODEV:
11481                 printf("invalid port_id %d\n", res->port_id);
11482                 break;
11483         case -ENOTSUP:
11484                 printf("function not implemented\n");
11485                 break;
11486         default:
11487                 printf("programming error: (%s)\n", strerror(-ret));
11488         }
11489 }
11490
11491 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11492         .f = cmd_set_vf_vlan_stripq_parsed,
11493         .data = NULL,
11494         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11495         .tokens = {
11496                 (void *)&cmd_vf_vlan_stripq_set,
11497                 (void *)&cmd_vf_vlan_stripq_vf,
11498                 (void *)&cmd_vf_vlan_stripq_vlan,
11499                 (void *)&cmd_vf_vlan_stripq_stripq,
11500                 (void *)&cmd_vf_vlan_stripq_port_id,
11501                 (void *)&cmd_vf_vlan_stripq_vf_id,
11502                 (void *)&cmd_vf_vlan_stripq_on_off,
11503                 NULL,
11504         },
11505 };
11506
11507 /* vf vlan insert configuration */
11508
11509 /* Common result structure for vf vlan insert */
11510 struct cmd_vf_vlan_insert_result {
11511         cmdline_fixed_string_t set;
11512         cmdline_fixed_string_t vf;
11513         cmdline_fixed_string_t vlan;
11514         cmdline_fixed_string_t insert;
11515         uint8_t port_id;
11516         uint16_t vf_id;
11517         uint16_t vlan_id;
11518 };
11519
11520 /* Common CLI fields for vf vlan insert enable disable */
11521 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11522         TOKEN_STRING_INITIALIZER
11523                 (struct cmd_vf_vlan_insert_result,
11524                  set, "set");
11525 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11526         TOKEN_STRING_INITIALIZER
11527                 (struct cmd_vf_vlan_insert_result,
11528                  vf, "vf");
11529 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11530         TOKEN_STRING_INITIALIZER
11531                 (struct cmd_vf_vlan_insert_result,
11532                  vlan, "vlan");
11533 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11534         TOKEN_STRING_INITIALIZER
11535                 (struct cmd_vf_vlan_insert_result,
11536                  insert, "insert");
11537 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11538         TOKEN_NUM_INITIALIZER
11539                 (struct cmd_vf_vlan_insert_result,
11540                  port_id, UINT8);
11541 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11542         TOKEN_NUM_INITIALIZER
11543                 (struct cmd_vf_vlan_insert_result,
11544                  vf_id, UINT16);
11545 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11546         TOKEN_NUM_INITIALIZER
11547                 (struct cmd_vf_vlan_insert_result,
11548                  vlan_id, UINT16);
11549
11550 static void
11551 cmd_set_vf_vlan_insert_parsed(
11552         void *parsed_result,
11553         __attribute__((unused)) struct cmdline *cl,
11554         __attribute__((unused)) void *data)
11555 {
11556         struct cmd_vf_vlan_insert_result *res = parsed_result;
11557         int ret = -ENOTSUP;
11558
11559         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11560                 return;
11561
11562 #ifdef RTE_LIBRTE_IXGBE_PMD
11563         if (ret == -ENOTSUP)
11564                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11565                         res->vlan_id);
11566 #endif
11567 #ifdef RTE_LIBRTE_I40E_PMD
11568         if (ret == -ENOTSUP)
11569                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11570                         res->vlan_id);
11571 #endif
11572 #ifdef RTE_LIBRTE_BNXT_PMD
11573         if (ret == -ENOTSUP)
11574                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11575                         res->vlan_id);
11576 #endif
11577
11578         switch (ret) {
11579         case 0:
11580                 break;
11581         case -EINVAL:
11582                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11583                 break;
11584         case -ENODEV:
11585                 printf("invalid port_id %d\n", res->port_id);
11586                 break;
11587         case -ENOTSUP:
11588                 printf("function not implemented\n");
11589                 break;
11590         default:
11591                 printf("programming error: (%s)\n", strerror(-ret));
11592         }
11593 }
11594
11595 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11596         .f = cmd_set_vf_vlan_insert_parsed,
11597         .data = NULL,
11598         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11599         .tokens = {
11600                 (void *)&cmd_vf_vlan_insert_set,
11601                 (void *)&cmd_vf_vlan_insert_vf,
11602                 (void *)&cmd_vf_vlan_insert_vlan,
11603                 (void *)&cmd_vf_vlan_insert_insert,
11604                 (void *)&cmd_vf_vlan_insert_port_id,
11605                 (void *)&cmd_vf_vlan_insert_vf_id,
11606                 (void *)&cmd_vf_vlan_insert_vlan_id,
11607                 NULL,
11608         },
11609 };
11610
11611 /* tx loopback configuration */
11612
11613 /* Common result structure for tx loopback */
11614 struct cmd_tx_loopback_result {
11615         cmdline_fixed_string_t set;
11616         cmdline_fixed_string_t tx;
11617         cmdline_fixed_string_t loopback;
11618         uint8_t port_id;
11619         cmdline_fixed_string_t on_off;
11620 };
11621
11622 /* Common CLI fields for tx loopback enable disable */
11623 cmdline_parse_token_string_t cmd_tx_loopback_set =
11624         TOKEN_STRING_INITIALIZER
11625                 (struct cmd_tx_loopback_result,
11626                  set, "set");
11627 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11628         TOKEN_STRING_INITIALIZER
11629                 (struct cmd_tx_loopback_result,
11630                  tx, "tx");
11631 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11632         TOKEN_STRING_INITIALIZER
11633                 (struct cmd_tx_loopback_result,
11634                  loopback, "loopback");
11635 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11636         TOKEN_NUM_INITIALIZER
11637                 (struct cmd_tx_loopback_result,
11638                  port_id, UINT8);
11639 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11640         TOKEN_STRING_INITIALIZER
11641                 (struct cmd_tx_loopback_result,
11642                  on_off, "on#off");
11643
11644 static void
11645 cmd_set_tx_loopback_parsed(
11646         void *parsed_result,
11647         __attribute__((unused)) struct cmdline *cl,
11648         __attribute__((unused)) void *data)
11649 {
11650         struct cmd_tx_loopback_result *res = parsed_result;
11651         int ret = -ENOTSUP;
11652
11653         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11654
11655         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11656                 return;
11657
11658 #ifdef RTE_LIBRTE_IXGBE_PMD
11659         if (ret == -ENOTSUP)
11660                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11661 #endif
11662 #ifdef RTE_LIBRTE_I40E_PMD
11663         if (ret == -ENOTSUP)
11664                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11665 #endif
11666 #ifdef RTE_LIBRTE_BNXT_PMD
11667         if (ret == -ENOTSUP)
11668                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11669 #endif
11670
11671         switch (ret) {
11672         case 0:
11673                 break;
11674         case -EINVAL:
11675                 printf("invalid is_on %d\n", is_on);
11676                 break;
11677         case -ENODEV:
11678                 printf("invalid port_id %d\n", res->port_id);
11679                 break;
11680         case -ENOTSUP:
11681                 printf("function not implemented\n");
11682                 break;
11683         default:
11684                 printf("programming error: (%s)\n", strerror(-ret));
11685         }
11686 }
11687
11688 cmdline_parse_inst_t cmd_set_tx_loopback = {
11689         .f = cmd_set_tx_loopback_parsed,
11690         .data = NULL,
11691         .help_str = "set tx loopback <port_id> on|off",
11692         .tokens = {
11693                 (void *)&cmd_tx_loopback_set,
11694                 (void *)&cmd_tx_loopback_tx,
11695                 (void *)&cmd_tx_loopback_loopback,
11696                 (void *)&cmd_tx_loopback_port_id,
11697                 (void *)&cmd_tx_loopback_on_off,
11698                 NULL,
11699         },
11700 };
11701
11702 /* all queues drop enable configuration */
11703
11704 /* Common result structure for all queues drop enable */
11705 struct cmd_all_queues_drop_en_result {
11706         cmdline_fixed_string_t set;
11707         cmdline_fixed_string_t all;
11708         cmdline_fixed_string_t queues;
11709         cmdline_fixed_string_t drop;
11710         uint8_t port_id;
11711         cmdline_fixed_string_t on_off;
11712 };
11713
11714 /* Common CLI fields for tx loopback enable disable */
11715 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11716         TOKEN_STRING_INITIALIZER
11717                 (struct cmd_all_queues_drop_en_result,
11718                  set, "set");
11719 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11720         TOKEN_STRING_INITIALIZER
11721                 (struct cmd_all_queues_drop_en_result,
11722                  all, "all");
11723 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11724         TOKEN_STRING_INITIALIZER
11725                 (struct cmd_all_queues_drop_en_result,
11726                  queues, "queues");
11727 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11728         TOKEN_STRING_INITIALIZER
11729                 (struct cmd_all_queues_drop_en_result,
11730                  drop, "drop");
11731 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11732         TOKEN_NUM_INITIALIZER
11733                 (struct cmd_all_queues_drop_en_result,
11734                  port_id, UINT8);
11735 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11736         TOKEN_STRING_INITIALIZER
11737                 (struct cmd_all_queues_drop_en_result,
11738                  on_off, "on#off");
11739
11740 static void
11741 cmd_set_all_queues_drop_en_parsed(
11742         void *parsed_result,
11743         __attribute__((unused)) struct cmdline *cl,
11744         __attribute__((unused)) void *data)
11745 {
11746         struct cmd_all_queues_drop_en_result *res = parsed_result;
11747         int ret = -ENOTSUP;
11748         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11749
11750         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11751                 return;
11752
11753 #ifdef RTE_LIBRTE_IXGBE_PMD
11754         if (ret == -ENOTSUP)
11755                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11756 #endif
11757 #ifdef RTE_LIBRTE_BNXT_PMD
11758         if (ret == -ENOTSUP)
11759                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11760 #endif
11761         switch (ret) {
11762         case 0:
11763                 break;
11764         case -EINVAL:
11765                 printf("invalid is_on %d\n", is_on);
11766                 break;
11767         case -ENODEV:
11768                 printf("invalid port_id %d\n", res->port_id);
11769                 break;
11770         case -ENOTSUP:
11771                 printf("function not implemented\n");
11772                 break;
11773         default:
11774                 printf("programming error: (%s)\n", strerror(-ret));
11775         }
11776 }
11777
11778 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11779         .f = cmd_set_all_queues_drop_en_parsed,
11780         .data = NULL,
11781         .help_str = "set all queues drop <port_id> on|off",
11782         .tokens = {
11783                 (void *)&cmd_all_queues_drop_en_set,
11784                 (void *)&cmd_all_queues_drop_en_all,
11785                 (void *)&cmd_all_queues_drop_en_queues,
11786                 (void *)&cmd_all_queues_drop_en_drop,
11787                 (void *)&cmd_all_queues_drop_en_port_id,
11788                 (void *)&cmd_all_queues_drop_en_on_off,
11789                 NULL,
11790         },
11791 };
11792
11793 /* vf split drop enable configuration */
11794
11795 /* Common result structure for vf split drop enable */
11796 struct cmd_vf_split_drop_en_result {
11797         cmdline_fixed_string_t set;
11798         cmdline_fixed_string_t vf;
11799         cmdline_fixed_string_t split;
11800         cmdline_fixed_string_t drop;
11801         uint8_t port_id;
11802         uint16_t vf_id;
11803         cmdline_fixed_string_t on_off;
11804 };
11805
11806 /* Common CLI fields for vf split drop enable disable */
11807 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11808         TOKEN_STRING_INITIALIZER
11809                 (struct cmd_vf_split_drop_en_result,
11810                  set, "set");
11811 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11812         TOKEN_STRING_INITIALIZER
11813                 (struct cmd_vf_split_drop_en_result,
11814                  vf, "vf");
11815 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11816         TOKEN_STRING_INITIALIZER
11817                 (struct cmd_vf_split_drop_en_result,
11818                  split, "split");
11819 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11820         TOKEN_STRING_INITIALIZER
11821                 (struct cmd_vf_split_drop_en_result,
11822                  drop, "drop");
11823 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11824         TOKEN_NUM_INITIALIZER
11825                 (struct cmd_vf_split_drop_en_result,
11826                  port_id, UINT8);
11827 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11828         TOKEN_NUM_INITIALIZER
11829                 (struct cmd_vf_split_drop_en_result,
11830                  vf_id, UINT16);
11831 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11832         TOKEN_STRING_INITIALIZER
11833                 (struct cmd_vf_split_drop_en_result,
11834                  on_off, "on#off");
11835
11836 static void
11837 cmd_set_vf_split_drop_en_parsed(
11838         void *parsed_result,
11839         __attribute__((unused)) struct cmdline *cl,
11840         __attribute__((unused)) void *data)
11841 {
11842         struct cmd_vf_split_drop_en_result *res = parsed_result;
11843         int ret = -ENOTSUP;
11844         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11845
11846         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11847                 return;
11848
11849 #ifdef RTE_LIBRTE_IXGBE_PMD
11850         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11851                         is_on);
11852 #endif
11853         switch (ret) {
11854         case 0:
11855                 break;
11856         case -EINVAL:
11857                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11858                 break;
11859         case -ENODEV:
11860                 printf("invalid port_id %d\n", res->port_id);
11861                 break;
11862         case -ENOTSUP:
11863                 printf("not supported on port %d\n", res->port_id);
11864                 break;
11865         default:
11866                 printf("programming error: (%s)\n", strerror(-ret));
11867         }
11868 }
11869
11870 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11871         .f = cmd_set_vf_split_drop_en_parsed,
11872         .data = NULL,
11873         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11874         .tokens = {
11875                 (void *)&cmd_vf_split_drop_en_set,
11876                 (void *)&cmd_vf_split_drop_en_vf,
11877                 (void *)&cmd_vf_split_drop_en_split,
11878                 (void *)&cmd_vf_split_drop_en_drop,
11879                 (void *)&cmd_vf_split_drop_en_port_id,
11880                 (void *)&cmd_vf_split_drop_en_vf_id,
11881                 (void *)&cmd_vf_split_drop_en_on_off,
11882                 NULL,
11883         },
11884 };
11885
11886 /* vf mac address configuration */
11887
11888 /* Common result structure for vf mac address */
11889 struct cmd_set_vf_mac_addr_result {
11890         cmdline_fixed_string_t set;
11891         cmdline_fixed_string_t vf;
11892         cmdline_fixed_string_t mac;
11893         cmdline_fixed_string_t addr;
11894         uint8_t port_id;
11895         uint16_t vf_id;
11896         struct ether_addr mac_addr;
11897
11898 };
11899
11900 /* Common CLI fields for vf split drop enable disable */
11901 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11902         TOKEN_STRING_INITIALIZER
11903                 (struct cmd_set_vf_mac_addr_result,
11904                  set, "set");
11905 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11906         TOKEN_STRING_INITIALIZER
11907                 (struct cmd_set_vf_mac_addr_result,
11908                  vf, "vf");
11909 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11910         TOKEN_STRING_INITIALIZER
11911                 (struct cmd_set_vf_mac_addr_result,
11912                  mac, "mac");
11913 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11914         TOKEN_STRING_INITIALIZER
11915                 (struct cmd_set_vf_mac_addr_result,
11916                  addr, "addr");
11917 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11918         TOKEN_NUM_INITIALIZER
11919                 (struct cmd_set_vf_mac_addr_result,
11920                  port_id, UINT8);
11921 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11922         TOKEN_NUM_INITIALIZER
11923                 (struct cmd_set_vf_mac_addr_result,
11924                  vf_id, UINT16);
11925 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11926         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11927                  mac_addr);
11928
11929 static void
11930 cmd_set_vf_mac_addr_parsed(
11931         void *parsed_result,
11932         __attribute__((unused)) struct cmdline *cl,
11933         __attribute__((unused)) void *data)
11934 {
11935         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11936         int ret = -ENOTSUP;
11937
11938         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11939                 return;
11940
11941 #ifdef RTE_LIBRTE_IXGBE_PMD
11942         if (ret == -ENOTSUP)
11943                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11944                                 &res->mac_addr);
11945 #endif
11946 #ifdef RTE_LIBRTE_I40E_PMD
11947         if (ret == -ENOTSUP)
11948                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11949                                 &res->mac_addr);
11950 #endif
11951 #ifdef RTE_LIBRTE_BNXT_PMD
11952         if (ret == -ENOTSUP)
11953                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11954                                 &res->mac_addr);
11955 #endif
11956
11957         switch (ret) {
11958         case 0:
11959                 break;
11960         case -EINVAL:
11961                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11962                 break;
11963         case -ENODEV:
11964                 printf("invalid port_id %d\n", res->port_id);
11965                 break;
11966         case -ENOTSUP:
11967                 printf("function not implemented\n");
11968                 break;
11969         default:
11970                 printf("programming error: (%s)\n", strerror(-ret));
11971         }
11972 }
11973
11974 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11975         .f = cmd_set_vf_mac_addr_parsed,
11976         .data = NULL,
11977         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11978         .tokens = {
11979                 (void *)&cmd_set_vf_mac_addr_set,
11980                 (void *)&cmd_set_vf_mac_addr_vf,
11981                 (void *)&cmd_set_vf_mac_addr_mac,
11982                 (void *)&cmd_set_vf_mac_addr_addr,
11983                 (void *)&cmd_set_vf_mac_addr_port_id,
11984                 (void *)&cmd_set_vf_mac_addr_vf_id,
11985                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11986                 NULL,
11987         },
11988 };
11989
11990 /* MACsec configuration */
11991
11992 /* Common result structure for MACsec offload enable */
11993 struct cmd_macsec_offload_on_result {
11994         cmdline_fixed_string_t set;
11995         cmdline_fixed_string_t macsec;
11996         cmdline_fixed_string_t offload;
11997         uint8_t port_id;
11998         cmdline_fixed_string_t on;
11999         cmdline_fixed_string_t encrypt;
12000         cmdline_fixed_string_t en_on_off;
12001         cmdline_fixed_string_t replay_protect;
12002         cmdline_fixed_string_t rp_on_off;
12003 };
12004
12005 /* Common CLI fields for MACsec offload disable */
12006 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12007         TOKEN_STRING_INITIALIZER
12008                 (struct cmd_macsec_offload_on_result,
12009                  set, "set");
12010 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12011         TOKEN_STRING_INITIALIZER
12012                 (struct cmd_macsec_offload_on_result,
12013                  macsec, "macsec");
12014 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12015         TOKEN_STRING_INITIALIZER
12016                 (struct cmd_macsec_offload_on_result,
12017                  offload, "offload");
12018 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12019         TOKEN_NUM_INITIALIZER
12020                 (struct cmd_macsec_offload_on_result,
12021                  port_id, UINT8);
12022 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12023         TOKEN_STRING_INITIALIZER
12024                 (struct cmd_macsec_offload_on_result,
12025                  on, "on");
12026 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12027         TOKEN_STRING_INITIALIZER
12028                 (struct cmd_macsec_offload_on_result,
12029                  encrypt, "encrypt");
12030 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12031         TOKEN_STRING_INITIALIZER
12032                 (struct cmd_macsec_offload_on_result,
12033                  en_on_off, "on#off");
12034 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12035         TOKEN_STRING_INITIALIZER
12036                 (struct cmd_macsec_offload_on_result,
12037                  replay_protect, "replay-protect");
12038 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12039         TOKEN_STRING_INITIALIZER
12040                 (struct cmd_macsec_offload_on_result,
12041                  rp_on_off, "on#off");
12042
12043 static void
12044 cmd_set_macsec_offload_on_parsed(
12045         void *parsed_result,
12046         __attribute__((unused)) struct cmdline *cl,
12047         __attribute__((unused)) void *data)
12048 {
12049         struct cmd_macsec_offload_on_result *res = parsed_result;
12050         int ret = -ENOTSUP;
12051         portid_t port_id = res->port_id;
12052         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12053         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12054
12055         if (port_id_is_invalid(port_id, ENABLED_WARN))
12056                 return;
12057
12058         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12059 #ifdef RTE_LIBRTE_IXGBE_PMD
12060         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12061 #endif
12062         RTE_SET_USED(en);
12063         RTE_SET_USED(rp);
12064
12065         switch (ret) {
12066         case 0:
12067                 break;
12068         case -ENODEV:
12069                 printf("invalid port_id %d\n", port_id);
12070                 break;
12071         case -ENOTSUP:
12072                 printf("not supported on port %d\n", port_id);
12073                 break;
12074         default:
12075                 printf("programming error: (%s)\n", strerror(-ret));
12076         }
12077 }
12078
12079 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12080         .f = cmd_set_macsec_offload_on_parsed,
12081         .data = NULL,
12082         .help_str = "set macsec offload <port_id> on "
12083                 "encrypt on|off replay-protect on|off",
12084         .tokens = {
12085                 (void *)&cmd_macsec_offload_on_set,
12086                 (void *)&cmd_macsec_offload_on_macsec,
12087                 (void *)&cmd_macsec_offload_on_offload,
12088                 (void *)&cmd_macsec_offload_on_port_id,
12089                 (void *)&cmd_macsec_offload_on_on,
12090                 (void *)&cmd_macsec_offload_on_encrypt,
12091                 (void *)&cmd_macsec_offload_on_en_on_off,
12092                 (void *)&cmd_macsec_offload_on_replay_protect,
12093                 (void *)&cmd_macsec_offload_on_rp_on_off,
12094                 NULL,
12095         },
12096 };
12097
12098 /* Common result structure for MACsec offload disable */
12099 struct cmd_macsec_offload_off_result {
12100         cmdline_fixed_string_t set;
12101         cmdline_fixed_string_t macsec;
12102         cmdline_fixed_string_t offload;
12103         uint8_t port_id;
12104         cmdline_fixed_string_t off;
12105 };
12106
12107 /* Common CLI fields for MACsec offload disable */
12108 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12109         TOKEN_STRING_INITIALIZER
12110                 (struct cmd_macsec_offload_off_result,
12111                  set, "set");
12112 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12113         TOKEN_STRING_INITIALIZER
12114                 (struct cmd_macsec_offload_off_result,
12115                  macsec, "macsec");
12116 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12117         TOKEN_STRING_INITIALIZER
12118                 (struct cmd_macsec_offload_off_result,
12119                  offload, "offload");
12120 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12121         TOKEN_NUM_INITIALIZER
12122                 (struct cmd_macsec_offload_off_result,
12123                  port_id, UINT8);
12124 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12125         TOKEN_STRING_INITIALIZER
12126                 (struct cmd_macsec_offload_off_result,
12127                  off, "off");
12128
12129 static void
12130 cmd_set_macsec_offload_off_parsed(
12131         void *parsed_result,
12132         __attribute__((unused)) struct cmdline *cl,
12133         __attribute__((unused)) void *data)
12134 {
12135         struct cmd_macsec_offload_off_result *res = parsed_result;
12136         int ret = -ENOTSUP;
12137         portid_t port_id = res->port_id;
12138
12139         if (port_id_is_invalid(port_id, ENABLED_WARN))
12140                 return;
12141
12142         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
12143 #ifdef RTE_LIBRTE_IXGBE_PMD
12144         ret = rte_pmd_ixgbe_macsec_disable(port_id);
12145 #endif
12146
12147         switch (ret) {
12148         case 0:
12149                 break;
12150         case -ENODEV:
12151                 printf("invalid port_id %d\n", port_id);
12152                 break;
12153         case -ENOTSUP:
12154                 printf("not supported on port %d\n", port_id);
12155                 break;
12156         default:
12157                 printf("programming error: (%s)\n", strerror(-ret));
12158         }
12159 }
12160
12161 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12162         .f = cmd_set_macsec_offload_off_parsed,
12163         .data = NULL,
12164         .help_str = "set macsec offload <port_id> off",
12165         .tokens = {
12166                 (void *)&cmd_macsec_offload_off_set,
12167                 (void *)&cmd_macsec_offload_off_macsec,
12168                 (void *)&cmd_macsec_offload_off_offload,
12169                 (void *)&cmd_macsec_offload_off_port_id,
12170                 (void *)&cmd_macsec_offload_off_off,
12171                 NULL,
12172         },
12173 };
12174
12175 /* Common result structure for MACsec secure connection configure */
12176 struct cmd_macsec_sc_result {
12177         cmdline_fixed_string_t set;
12178         cmdline_fixed_string_t macsec;
12179         cmdline_fixed_string_t sc;
12180         cmdline_fixed_string_t tx_rx;
12181         uint8_t port_id;
12182         struct ether_addr mac;
12183         uint16_t pi;
12184 };
12185
12186 /* Common CLI fields for MACsec secure connection configure */
12187 cmdline_parse_token_string_t cmd_macsec_sc_set =
12188         TOKEN_STRING_INITIALIZER
12189                 (struct cmd_macsec_sc_result,
12190                  set, "set");
12191 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12192         TOKEN_STRING_INITIALIZER
12193                 (struct cmd_macsec_sc_result,
12194                  macsec, "macsec");
12195 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12196         TOKEN_STRING_INITIALIZER
12197                 (struct cmd_macsec_sc_result,
12198                  sc, "sc");
12199 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12200         TOKEN_STRING_INITIALIZER
12201                 (struct cmd_macsec_sc_result,
12202                  tx_rx, "tx#rx");
12203 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12204         TOKEN_NUM_INITIALIZER
12205                 (struct cmd_macsec_sc_result,
12206                  port_id, UINT8);
12207 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12208         TOKEN_ETHERADDR_INITIALIZER
12209                 (struct cmd_macsec_sc_result,
12210                  mac);
12211 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12212         TOKEN_NUM_INITIALIZER
12213                 (struct cmd_macsec_sc_result,
12214                  pi, UINT16);
12215
12216 static void
12217 cmd_set_macsec_sc_parsed(
12218         void *parsed_result,
12219         __attribute__((unused)) struct cmdline *cl,
12220         __attribute__((unused)) void *data)
12221 {
12222         struct cmd_macsec_sc_result *res = parsed_result;
12223         int ret = -ENOTSUP;
12224         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12225
12226 #ifdef RTE_LIBRTE_IXGBE_PMD
12227         ret = is_tx ?
12228                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12229                                 res->mac.addr_bytes) :
12230                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12231                                 res->mac.addr_bytes, res->pi);
12232 #endif
12233         RTE_SET_USED(is_tx);
12234
12235         switch (ret) {
12236         case 0:
12237                 break;
12238         case -ENODEV:
12239                 printf("invalid port_id %d\n", res->port_id);
12240                 break;
12241         case -ENOTSUP:
12242                 printf("not supported on port %d\n", res->port_id);
12243                 break;
12244         default:
12245                 printf("programming error: (%s)\n", strerror(-ret));
12246         }
12247 }
12248
12249 cmdline_parse_inst_t cmd_set_macsec_sc = {
12250         .f = cmd_set_macsec_sc_parsed,
12251         .data = NULL,
12252         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12253         .tokens = {
12254                 (void *)&cmd_macsec_sc_set,
12255                 (void *)&cmd_macsec_sc_macsec,
12256                 (void *)&cmd_macsec_sc_sc,
12257                 (void *)&cmd_macsec_sc_tx_rx,
12258                 (void *)&cmd_macsec_sc_port_id,
12259                 (void *)&cmd_macsec_sc_mac,
12260                 (void *)&cmd_macsec_sc_pi,
12261                 NULL,
12262         },
12263 };
12264
12265 /* Common result structure for MACsec secure connection configure */
12266 struct cmd_macsec_sa_result {
12267         cmdline_fixed_string_t set;
12268         cmdline_fixed_string_t macsec;
12269         cmdline_fixed_string_t sa;
12270         cmdline_fixed_string_t tx_rx;
12271         uint8_t port_id;
12272         uint8_t idx;
12273         uint8_t an;
12274         uint32_t pn;
12275         cmdline_fixed_string_t key;
12276 };
12277
12278 /* Common CLI fields for MACsec secure connection configure */
12279 cmdline_parse_token_string_t cmd_macsec_sa_set =
12280         TOKEN_STRING_INITIALIZER
12281                 (struct cmd_macsec_sa_result,
12282                  set, "set");
12283 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12284         TOKEN_STRING_INITIALIZER
12285                 (struct cmd_macsec_sa_result,
12286                  macsec, "macsec");
12287 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12288         TOKEN_STRING_INITIALIZER
12289                 (struct cmd_macsec_sa_result,
12290                  sa, "sa");
12291 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12292         TOKEN_STRING_INITIALIZER
12293                 (struct cmd_macsec_sa_result,
12294                  tx_rx, "tx#rx");
12295 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12296         TOKEN_NUM_INITIALIZER
12297                 (struct cmd_macsec_sa_result,
12298                  port_id, UINT8);
12299 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12300         TOKEN_NUM_INITIALIZER
12301                 (struct cmd_macsec_sa_result,
12302                  idx, UINT8);
12303 cmdline_parse_token_num_t cmd_macsec_sa_an =
12304         TOKEN_NUM_INITIALIZER
12305                 (struct cmd_macsec_sa_result,
12306                  an, UINT8);
12307 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12308         TOKEN_NUM_INITIALIZER
12309                 (struct cmd_macsec_sa_result,
12310                  pn, UINT32);
12311 cmdline_parse_token_string_t cmd_macsec_sa_key =
12312         TOKEN_STRING_INITIALIZER
12313                 (struct cmd_macsec_sa_result,
12314                  key, NULL);
12315
12316 static void
12317 cmd_set_macsec_sa_parsed(
12318         void *parsed_result,
12319         __attribute__((unused)) struct cmdline *cl,
12320         __attribute__((unused)) void *data)
12321 {
12322         struct cmd_macsec_sa_result *res = parsed_result;
12323         int ret = -ENOTSUP;
12324         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12325         uint8_t key[16] = { 0 };
12326         uint8_t xdgt0;
12327         uint8_t xdgt1;
12328         int key_len;
12329         int i;
12330
12331         key_len = strlen(res->key) / 2;
12332         if (key_len > 16)
12333                 key_len = 16;
12334
12335         for (i = 0; i < key_len; i++) {
12336                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12337                 if (xdgt0 == 0xFF)
12338                         return;
12339                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12340                 if (xdgt1 == 0xFF)
12341                         return;
12342                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12343         }
12344
12345 #ifdef RTE_LIBRTE_IXGBE_PMD
12346         ret = is_tx ?
12347                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12348                         res->idx, res->an, res->pn, key) :
12349                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12350                         res->idx, res->an, res->pn, key);
12351 #endif
12352         RTE_SET_USED(is_tx);
12353         RTE_SET_USED(key);
12354
12355         switch (ret) {
12356         case 0:
12357                 break;
12358         case -EINVAL:
12359                 printf("invalid idx %d or an %d\n", res->idx, res->an);
12360                 break;
12361         case -ENODEV:
12362                 printf("invalid port_id %d\n", res->port_id);
12363                 break;
12364         case -ENOTSUP:
12365                 printf("not supported on port %d\n", res->port_id);
12366                 break;
12367         default:
12368                 printf("programming error: (%s)\n", strerror(-ret));
12369         }
12370 }
12371
12372 cmdline_parse_inst_t cmd_set_macsec_sa = {
12373         .f = cmd_set_macsec_sa_parsed,
12374         .data = NULL,
12375         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12376         .tokens = {
12377                 (void *)&cmd_macsec_sa_set,
12378                 (void *)&cmd_macsec_sa_macsec,
12379                 (void *)&cmd_macsec_sa_sa,
12380                 (void *)&cmd_macsec_sa_tx_rx,
12381                 (void *)&cmd_macsec_sa_port_id,
12382                 (void *)&cmd_macsec_sa_idx,
12383                 (void *)&cmd_macsec_sa_an,
12384                 (void *)&cmd_macsec_sa_pn,
12385                 (void *)&cmd_macsec_sa_key,
12386                 NULL,
12387         },
12388 };
12389
12390 /* VF unicast promiscuous mode configuration */
12391
12392 /* Common result structure for VF unicast promiscuous mode */
12393 struct cmd_vf_promisc_result {
12394         cmdline_fixed_string_t set;
12395         cmdline_fixed_string_t vf;
12396         cmdline_fixed_string_t promisc;
12397         uint8_t port_id;
12398         uint32_t vf_id;
12399         cmdline_fixed_string_t on_off;
12400 };
12401
12402 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12403 cmdline_parse_token_string_t cmd_vf_promisc_set =
12404         TOKEN_STRING_INITIALIZER
12405                 (struct cmd_vf_promisc_result,
12406                  set, "set");
12407 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12408         TOKEN_STRING_INITIALIZER
12409                 (struct cmd_vf_promisc_result,
12410                  vf, "vf");
12411 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12412         TOKEN_STRING_INITIALIZER
12413                 (struct cmd_vf_promisc_result,
12414                  promisc, "promisc");
12415 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12416         TOKEN_NUM_INITIALIZER
12417                 (struct cmd_vf_promisc_result,
12418                  port_id, UINT8);
12419 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12420         TOKEN_NUM_INITIALIZER
12421                 (struct cmd_vf_promisc_result,
12422                  vf_id, UINT32);
12423 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12424         TOKEN_STRING_INITIALIZER
12425                 (struct cmd_vf_promisc_result,
12426                  on_off, "on#off");
12427
12428 static void
12429 cmd_set_vf_promisc_parsed(
12430         void *parsed_result,
12431         __attribute__((unused)) struct cmdline *cl,
12432         __attribute__((unused)) void *data)
12433 {
12434         struct cmd_vf_promisc_result *res = parsed_result;
12435         int ret = -ENOTSUP;
12436
12437         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12438
12439         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12440                 return;
12441
12442 #ifdef RTE_LIBRTE_I40E_PMD
12443         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12444                                                   res->vf_id, is_on);
12445 #endif
12446
12447         switch (ret) {
12448         case 0:
12449                 break;
12450         case -EINVAL:
12451                 printf("invalid vf_id %d\n", res->vf_id);
12452                 break;
12453         case -ENODEV:
12454                 printf("invalid port_id %d\n", res->port_id);
12455                 break;
12456         case -ENOTSUP:
12457                 printf("function not implemented\n");
12458                 break;
12459         default:
12460                 printf("programming error: (%s)\n", strerror(-ret));
12461         }
12462 }
12463
12464 cmdline_parse_inst_t cmd_set_vf_promisc = {
12465         .f = cmd_set_vf_promisc_parsed,
12466         .data = NULL,
12467         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12468                 "Set unicast promiscuous mode for a VF from the PF",
12469         .tokens = {
12470                 (void *)&cmd_vf_promisc_set,
12471                 (void *)&cmd_vf_promisc_vf,
12472                 (void *)&cmd_vf_promisc_promisc,
12473                 (void *)&cmd_vf_promisc_port_id,
12474                 (void *)&cmd_vf_promisc_vf_id,
12475                 (void *)&cmd_vf_promisc_on_off,
12476                 NULL,
12477         },
12478 };
12479
12480 /* VF multicast promiscuous mode configuration */
12481
12482 /* Common result structure for VF multicast promiscuous mode */
12483 struct cmd_vf_allmulti_result {
12484         cmdline_fixed_string_t set;
12485         cmdline_fixed_string_t vf;
12486         cmdline_fixed_string_t allmulti;
12487         uint8_t port_id;
12488         uint32_t vf_id;
12489         cmdline_fixed_string_t on_off;
12490 };
12491
12492 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12493 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12494         TOKEN_STRING_INITIALIZER
12495                 (struct cmd_vf_allmulti_result,
12496                  set, "set");
12497 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12498         TOKEN_STRING_INITIALIZER
12499                 (struct cmd_vf_allmulti_result,
12500                  vf, "vf");
12501 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12502         TOKEN_STRING_INITIALIZER
12503                 (struct cmd_vf_allmulti_result,
12504                  allmulti, "allmulti");
12505 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12506         TOKEN_NUM_INITIALIZER
12507                 (struct cmd_vf_allmulti_result,
12508                  port_id, UINT8);
12509 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12510         TOKEN_NUM_INITIALIZER
12511                 (struct cmd_vf_allmulti_result,
12512                  vf_id, UINT32);
12513 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12514         TOKEN_STRING_INITIALIZER
12515                 (struct cmd_vf_allmulti_result,
12516                  on_off, "on#off");
12517
12518 static void
12519 cmd_set_vf_allmulti_parsed(
12520         void *parsed_result,
12521         __attribute__((unused)) struct cmdline *cl,
12522         __attribute__((unused)) void *data)
12523 {
12524         struct cmd_vf_allmulti_result *res = parsed_result;
12525         int ret = -ENOTSUP;
12526
12527         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12528
12529         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12530                 return;
12531
12532 #ifdef RTE_LIBRTE_I40E_PMD
12533         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12534                                                     res->vf_id, is_on);
12535 #endif
12536
12537         switch (ret) {
12538         case 0:
12539                 break;
12540         case -EINVAL:
12541                 printf("invalid vf_id %d\n", res->vf_id);
12542                 break;
12543         case -ENODEV:
12544                 printf("invalid port_id %d\n", res->port_id);
12545                 break;
12546         case -ENOTSUP:
12547                 printf("function not implemented\n");
12548                 break;
12549         default:
12550                 printf("programming error: (%s)\n", strerror(-ret));
12551         }
12552 }
12553
12554 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12555         .f = cmd_set_vf_allmulti_parsed,
12556         .data = NULL,
12557         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12558                 "Set multicast promiscuous mode for a VF from the PF",
12559         .tokens = {
12560                 (void *)&cmd_vf_allmulti_set,
12561                 (void *)&cmd_vf_allmulti_vf,
12562                 (void *)&cmd_vf_allmulti_allmulti,
12563                 (void *)&cmd_vf_allmulti_port_id,
12564                 (void *)&cmd_vf_allmulti_vf_id,
12565                 (void *)&cmd_vf_allmulti_on_off,
12566                 NULL,
12567         },
12568 };
12569
12570 /* vf broadcast mode configuration */
12571
12572 /* Common result structure for vf broadcast */
12573 struct cmd_set_vf_broadcast_result {
12574         cmdline_fixed_string_t set;
12575         cmdline_fixed_string_t vf;
12576         cmdline_fixed_string_t broadcast;
12577         uint8_t port_id;
12578         uint16_t vf_id;
12579         cmdline_fixed_string_t on_off;
12580 };
12581
12582 /* Common CLI fields for vf broadcast enable disable */
12583 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12584         TOKEN_STRING_INITIALIZER
12585                 (struct cmd_set_vf_broadcast_result,
12586                  set, "set");
12587 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12588         TOKEN_STRING_INITIALIZER
12589                 (struct cmd_set_vf_broadcast_result,
12590                  vf, "vf");
12591 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12592         TOKEN_STRING_INITIALIZER
12593                 (struct cmd_set_vf_broadcast_result,
12594                  broadcast, "broadcast");
12595 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12596         TOKEN_NUM_INITIALIZER
12597                 (struct cmd_set_vf_broadcast_result,
12598                  port_id, UINT8);
12599 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12600         TOKEN_NUM_INITIALIZER
12601                 (struct cmd_set_vf_broadcast_result,
12602                  vf_id, UINT16);
12603 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12604         TOKEN_STRING_INITIALIZER
12605                 (struct cmd_set_vf_broadcast_result,
12606                  on_off, "on#off");
12607
12608 static void
12609 cmd_set_vf_broadcast_parsed(
12610         void *parsed_result,
12611         __attribute__((unused)) struct cmdline *cl,
12612         __attribute__((unused)) void *data)
12613 {
12614         struct cmd_set_vf_broadcast_result *res = parsed_result;
12615         int ret = -ENOTSUP;
12616
12617         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12618
12619         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12620                 return;
12621
12622 #ifdef RTE_LIBRTE_I40E_PMD
12623         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12624                                             res->vf_id, is_on);
12625 #endif
12626
12627         switch (ret) {
12628         case 0:
12629                 break;
12630         case -EINVAL:
12631                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12632                 break;
12633         case -ENODEV:
12634                 printf("invalid port_id %d\n", res->port_id);
12635                 break;
12636         case -ENOTSUP:
12637                 printf("function not implemented\n");
12638                 break;
12639         default:
12640                 printf("programming error: (%s)\n", strerror(-ret));
12641         }
12642 }
12643
12644 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12645         .f = cmd_set_vf_broadcast_parsed,
12646         .data = NULL,
12647         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12648         .tokens = {
12649                 (void *)&cmd_set_vf_broadcast_set,
12650                 (void *)&cmd_set_vf_broadcast_vf,
12651                 (void *)&cmd_set_vf_broadcast_broadcast,
12652                 (void *)&cmd_set_vf_broadcast_port_id,
12653                 (void *)&cmd_set_vf_broadcast_vf_id,
12654                 (void *)&cmd_set_vf_broadcast_on_off,
12655                 NULL,
12656         },
12657 };
12658
12659 /* vf vlan tag configuration */
12660
12661 /* Common result structure for vf vlan tag */
12662 struct cmd_set_vf_vlan_tag_result {
12663         cmdline_fixed_string_t set;
12664         cmdline_fixed_string_t vf;
12665         cmdline_fixed_string_t vlan;
12666         cmdline_fixed_string_t tag;
12667         uint8_t port_id;
12668         uint16_t vf_id;
12669         cmdline_fixed_string_t on_off;
12670 };
12671
12672 /* Common CLI fields for vf vlan tag enable disable */
12673 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12674         TOKEN_STRING_INITIALIZER
12675                 (struct cmd_set_vf_vlan_tag_result,
12676                  set, "set");
12677 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12678         TOKEN_STRING_INITIALIZER
12679                 (struct cmd_set_vf_vlan_tag_result,
12680                  vf, "vf");
12681 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12682         TOKEN_STRING_INITIALIZER
12683                 (struct cmd_set_vf_vlan_tag_result,
12684                  vlan, "vlan");
12685 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12686         TOKEN_STRING_INITIALIZER
12687                 (struct cmd_set_vf_vlan_tag_result,
12688                  tag, "tag");
12689 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12690         TOKEN_NUM_INITIALIZER
12691                 (struct cmd_set_vf_vlan_tag_result,
12692                  port_id, UINT8);
12693 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12694         TOKEN_NUM_INITIALIZER
12695                 (struct cmd_set_vf_vlan_tag_result,
12696                  vf_id, UINT16);
12697 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12698         TOKEN_STRING_INITIALIZER
12699                 (struct cmd_set_vf_vlan_tag_result,
12700                  on_off, "on#off");
12701
12702 static void
12703 cmd_set_vf_vlan_tag_parsed(
12704         void *parsed_result,
12705         __attribute__((unused)) struct cmdline *cl,
12706         __attribute__((unused)) void *data)
12707 {
12708         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12709         int ret = -ENOTSUP;
12710
12711         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12712
12713         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12714                 return;
12715
12716 #ifdef RTE_LIBRTE_I40E_PMD
12717         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12718                                            res->vf_id, is_on);
12719 #endif
12720
12721         switch (ret) {
12722         case 0:
12723                 break;
12724         case -EINVAL:
12725                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12726                 break;
12727         case -ENODEV:
12728                 printf("invalid port_id %d\n", res->port_id);
12729                 break;
12730         case -ENOTSUP:
12731                 printf("function not implemented\n");
12732                 break;
12733         default:
12734                 printf("programming error: (%s)\n", strerror(-ret));
12735         }
12736 }
12737
12738 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12739         .f = cmd_set_vf_vlan_tag_parsed,
12740         .data = NULL,
12741         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12742         .tokens = {
12743                 (void *)&cmd_set_vf_vlan_tag_set,
12744                 (void *)&cmd_set_vf_vlan_tag_vf,
12745                 (void *)&cmd_set_vf_vlan_tag_vlan,
12746                 (void *)&cmd_set_vf_vlan_tag_tag,
12747                 (void *)&cmd_set_vf_vlan_tag_port_id,
12748                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12749                 (void *)&cmd_set_vf_vlan_tag_on_off,
12750                 NULL,
12751         },
12752 };
12753
12754 /* Common definition of VF and TC TX bandwidth configuration */
12755 struct cmd_vf_tc_bw_result {
12756         cmdline_fixed_string_t set;
12757         cmdline_fixed_string_t vf;
12758         cmdline_fixed_string_t tc;
12759         cmdline_fixed_string_t tx;
12760         cmdline_fixed_string_t min_bw;
12761         cmdline_fixed_string_t max_bw;
12762         cmdline_fixed_string_t strict_link_prio;
12763         uint8_t port_id;
12764         uint16_t vf_id;
12765         uint8_t tc_no;
12766         uint32_t bw;
12767         cmdline_fixed_string_t bw_list;
12768         uint8_t tc_map;
12769 };
12770
12771 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12772         TOKEN_STRING_INITIALIZER
12773                 (struct cmd_vf_tc_bw_result,
12774                  set, "set");
12775 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12776         TOKEN_STRING_INITIALIZER
12777                 (struct cmd_vf_tc_bw_result,
12778                  vf, "vf");
12779 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12780         TOKEN_STRING_INITIALIZER
12781                 (struct cmd_vf_tc_bw_result,
12782                  tc, "tc");
12783 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12784         TOKEN_STRING_INITIALIZER
12785                 (struct cmd_vf_tc_bw_result,
12786                  tx, "tx");
12787 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12788         TOKEN_STRING_INITIALIZER
12789                 (struct cmd_vf_tc_bw_result,
12790                  strict_link_prio, "strict-link-priority");
12791 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12792         TOKEN_STRING_INITIALIZER
12793                 (struct cmd_vf_tc_bw_result,
12794                  min_bw, "min-bandwidth");
12795 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12796         TOKEN_STRING_INITIALIZER
12797                 (struct cmd_vf_tc_bw_result,
12798                  max_bw, "max-bandwidth");
12799 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12800         TOKEN_NUM_INITIALIZER
12801                 (struct cmd_vf_tc_bw_result,
12802                  port_id, UINT8);
12803 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12804         TOKEN_NUM_INITIALIZER
12805                 (struct cmd_vf_tc_bw_result,
12806                  vf_id, UINT16);
12807 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12808         TOKEN_NUM_INITIALIZER
12809                 (struct cmd_vf_tc_bw_result,
12810                  tc_no, UINT8);
12811 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12812         TOKEN_NUM_INITIALIZER
12813                 (struct cmd_vf_tc_bw_result,
12814                  bw, UINT32);
12815 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12816         TOKEN_STRING_INITIALIZER
12817                 (struct cmd_vf_tc_bw_result,
12818                  bw_list, NULL);
12819 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12820         TOKEN_NUM_INITIALIZER
12821                 (struct cmd_vf_tc_bw_result,
12822                  tc_map, UINT8);
12823
12824 /* VF max bandwidth setting */
12825 static void
12826 cmd_vf_max_bw_parsed(
12827         void *parsed_result,
12828         __attribute__((unused)) struct cmdline *cl,
12829         __attribute__((unused)) void *data)
12830 {
12831         struct cmd_vf_tc_bw_result *res = parsed_result;
12832         int ret = -ENOTSUP;
12833
12834         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12835                 return;
12836
12837 #ifdef RTE_LIBRTE_I40E_PMD
12838         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12839                                          res->vf_id, res->bw);
12840 #endif
12841
12842         switch (ret) {
12843         case 0:
12844                 break;
12845         case -EINVAL:
12846                 printf("invalid vf_id %d or bandwidth %d\n",
12847                        res->vf_id, res->bw);
12848                 break;
12849         case -ENODEV:
12850                 printf("invalid port_id %d\n", res->port_id);
12851                 break;
12852         case -ENOTSUP:
12853                 printf("function not implemented\n");
12854                 break;
12855         default:
12856                 printf("programming error: (%s)\n", strerror(-ret));
12857         }
12858 }
12859
12860 cmdline_parse_inst_t cmd_vf_max_bw = {
12861         .f = cmd_vf_max_bw_parsed,
12862         .data = NULL,
12863         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12864         .tokens = {
12865                 (void *)&cmd_vf_tc_bw_set,
12866                 (void *)&cmd_vf_tc_bw_vf,
12867                 (void *)&cmd_vf_tc_bw_tx,
12868                 (void *)&cmd_vf_tc_bw_max_bw,
12869                 (void *)&cmd_vf_tc_bw_port_id,
12870                 (void *)&cmd_vf_tc_bw_vf_id,
12871                 (void *)&cmd_vf_tc_bw_bw,
12872                 NULL,
12873         },
12874 };
12875
12876 static int
12877 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12878                            uint8_t *tc_num,
12879                            char *str)
12880 {
12881         uint32_t size;
12882         const char *p, *p0 = str;
12883         char s[256];
12884         char *end;
12885         char *str_fld[16];
12886         uint16_t i;
12887         int ret;
12888
12889         p = strchr(p0, '(');
12890         if (p == NULL) {
12891                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12892                 return -1;
12893         }
12894         p++;
12895         p0 = strchr(p, ')');
12896         if (p0 == NULL) {
12897                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12898                 return -1;
12899         }
12900         size = p0 - p;
12901         if (size >= sizeof(s)) {
12902                 printf("The string size exceeds the internal buffer size\n");
12903                 return -1;
12904         }
12905         snprintf(s, sizeof(s), "%.*s", size, p);
12906         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12907         if (ret <= 0) {
12908                 printf("Failed to get the bandwidth list. ");
12909                 return -1;
12910         }
12911         *tc_num = ret;
12912         for (i = 0; i < ret; i++)
12913                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12914
12915         return 0;
12916 }
12917
12918 /* TC min bandwidth setting */
12919 static void
12920 cmd_vf_tc_min_bw_parsed(
12921         void *parsed_result,
12922         __attribute__((unused)) struct cmdline *cl,
12923         __attribute__((unused)) void *data)
12924 {
12925         struct cmd_vf_tc_bw_result *res = parsed_result;
12926         uint8_t tc_num;
12927         uint8_t bw[16];
12928         int ret = -ENOTSUP;
12929
12930         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12931                 return;
12932
12933         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12934         if (ret)
12935                 return;
12936
12937 #ifdef RTE_LIBRTE_I40E_PMD
12938         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12939                                               tc_num, bw);
12940 #endif
12941
12942         switch (ret) {
12943         case 0:
12944                 break;
12945         case -EINVAL:
12946                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
12947                 break;
12948         case -ENODEV:
12949                 printf("invalid port_id %d\n", res->port_id);
12950                 break;
12951         case -ENOTSUP:
12952                 printf("function not implemented\n");
12953                 break;
12954         default:
12955                 printf("programming error: (%s)\n", strerror(-ret));
12956         }
12957 }
12958
12959 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12960         .f = cmd_vf_tc_min_bw_parsed,
12961         .data = NULL,
12962         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12963                     " <bw1, bw2, ...>",
12964         .tokens = {
12965                 (void *)&cmd_vf_tc_bw_set,
12966                 (void *)&cmd_vf_tc_bw_vf,
12967                 (void *)&cmd_vf_tc_bw_tc,
12968                 (void *)&cmd_vf_tc_bw_tx,
12969                 (void *)&cmd_vf_tc_bw_min_bw,
12970                 (void *)&cmd_vf_tc_bw_port_id,
12971                 (void *)&cmd_vf_tc_bw_vf_id,
12972                 (void *)&cmd_vf_tc_bw_bw_list,
12973                 NULL,
12974         },
12975 };
12976
12977 static void
12978 cmd_tc_min_bw_parsed(
12979         void *parsed_result,
12980         __attribute__((unused)) struct cmdline *cl,
12981         __attribute__((unused)) void *data)
12982 {
12983         struct cmd_vf_tc_bw_result *res = parsed_result;
12984         struct rte_port *port;
12985         uint8_t tc_num;
12986         uint8_t bw[16];
12987         int ret = -ENOTSUP;
12988
12989         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12990                 return;
12991
12992         port = &ports[res->port_id];
12993         /** Check if the port is not started **/
12994         if (port->port_status != RTE_PORT_STOPPED) {
12995                 printf("Please stop port %d first\n", res->port_id);
12996                 return;
12997         }
12998
12999         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13000         if (ret)
13001                 return;
13002
13003 #ifdef RTE_LIBRTE_IXGBE_PMD
13004         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13005 #endif
13006
13007         switch (ret) {
13008         case 0:
13009                 break;
13010         case -EINVAL:
13011                 printf("invalid bandwidth\n");
13012                 break;
13013         case -ENODEV:
13014                 printf("invalid port_id %d\n", res->port_id);
13015                 break;
13016         case -ENOTSUP:
13017                 printf("function not implemented\n");
13018                 break;
13019         default:
13020                 printf("programming error: (%s)\n", strerror(-ret));
13021         }
13022 }
13023
13024 cmdline_parse_inst_t cmd_tc_min_bw = {
13025         .f = cmd_tc_min_bw_parsed,
13026         .data = NULL,
13027         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13028         .tokens = {
13029                 (void *)&cmd_vf_tc_bw_set,
13030                 (void *)&cmd_vf_tc_bw_tc,
13031                 (void *)&cmd_vf_tc_bw_tx,
13032                 (void *)&cmd_vf_tc_bw_min_bw,
13033                 (void *)&cmd_vf_tc_bw_port_id,
13034                 (void *)&cmd_vf_tc_bw_bw_list,
13035                 NULL,
13036         },
13037 };
13038
13039 /* TC max bandwidth setting */
13040 static void
13041 cmd_vf_tc_max_bw_parsed(
13042         void *parsed_result,
13043         __attribute__((unused)) struct cmdline *cl,
13044         __attribute__((unused)) void *data)
13045 {
13046         struct cmd_vf_tc_bw_result *res = parsed_result;
13047         int ret = -ENOTSUP;
13048
13049         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13050                 return;
13051
13052 #ifdef RTE_LIBRTE_I40E_PMD
13053         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13054                                             res->tc_no, res->bw);
13055 #endif
13056
13057         switch (ret) {
13058         case 0:
13059                 break;
13060         case -EINVAL:
13061                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13062                        res->vf_id, res->tc_no, res->bw);
13063                 break;
13064         case -ENODEV:
13065                 printf("invalid port_id %d\n", res->port_id);
13066                 break;
13067         case -ENOTSUP:
13068                 printf("function not implemented\n");
13069                 break;
13070         default:
13071                 printf("programming error: (%s)\n", strerror(-ret));
13072         }
13073 }
13074
13075 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13076         .f = cmd_vf_tc_max_bw_parsed,
13077         .data = NULL,
13078         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13079                     " <bandwidth>",
13080         .tokens = {
13081                 (void *)&cmd_vf_tc_bw_set,
13082                 (void *)&cmd_vf_tc_bw_vf,
13083                 (void *)&cmd_vf_tc_bw_tc,
13084                 (void *)&cmd_vf_tc_bw_tx,
13085                 (void *)&cmd_vf_tc_bw_max_bw,
13086                 (void *)&cmd_vf_tc_bw_port_id,
13087                 (void *)&cmd_vf_tc_bw_vf_id,
13088                 (void *)&cmd_vf_tc_bw_tc_no,
13089                 (void *)&cmd_vf_tc_bw_bw,
13090                 NULL,
13091         },
13092 };
13093
13094 /* Strict link priority scheduling mode setting */
13095 static void
13096 cmd_strict_link_prio_parsed(
13097         void *parsed_result,
13098         __attribute__((unused)) struct cmdline *cl,
13099         __attribute__((unused)) void *data)
13100 {
13101         struct cmd_vf_tc_bw_result *res = parsed_result;
13102         int ret = -ENOTSUP;
13103
13104         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13105                 return;
13106
13107 #ifdef RTE_LIBRTE_I40E_PMD
13108         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13109 #endif
13110
13111         switch (ret) {
13112         case 0:
13113                 break;
13114         case -EINVAL:
13115                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13116                 break;
13117         case -ENODEV:
13118                 printf("invalid port_id %d\n", res->port_id);
13119                 break;
13120         case -ENOTSUP:
13121                 printf("function not implemented\n");
13122                 break;
13123         default:
13124                 printf("programming error: (%s)\n", strerror(-ret));
13125         }
13126 }
13127
13128 cmdline_parse_inst_t cmd_strict_link_prio = {
13129         .f = cmd_strict_link_prio_parsed,
13130         .data = NULL,
13131         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13132         .tokens = {
13133                 (void *)&cmd_vf_tc_bw_set,
13134                 (void *)&cmd_vf_tc_bw_tx,
13135                 (void *)&cmd_vf_tc_bw_strict_link_prio,
13136                 (void *)&cmd_vf_tc_bw_port_id,
13137                 (void *)&cmd_vf_tc_bw_tc_map,
13138                 NULL,
13139         },
13140 };
13141
13142 /* Load dynamic device personalization*/
13143 struct cmd_ddp_add_result {
13144         cmdline_fixed_string_t ddp;
13145         cmdline_fixed_string_t add;
13146         uint8_t port_id;
13147         char filepath[];
13148 };
13149
13150 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13151         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13152 cmdline_parse_token_string_t cmd_ddp_add_add =
13153         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13154 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13155         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8);
13156 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13157         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13158
13159 static void
13160 cmd_ddp_add_parsed(
13161         void *parsed_result,
13162         __attribute__((unused)) struct cmdline *cl,
13163         __attribute__((unused)) void *data)
13164 {
13165         struct cmd_ddp_add_result *res = parsed_result;
13166         uint8_t *buff;
13167         uint32_t size;
13168         char *filepath;
13169         char *file_fld[2];
13170         int file_num;
13171         int ret = -ENOTSUP;
13172
13173         if (res->port_id > nb_ports) {
13174                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13175                 return;
13176         }
13177
13178         if (!all_ports_stopped()) {
13179                 printf("Please stop all ports first\n");
13180                 return;
13181         }
13182
13183         filepath = strdup(res->filepath);
13184         if (filepath == NULL) {
13185                 printf("Failed to allocate memory\n");
13186                 return;
13187         }
13188         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13189
13190         buff = open_ddp_package_file(file_fld[0], &size);
13191         if (!buff) {
13192                 free((void *)filepath);
13193                 return;
13194         }
13195
13196 #ifdef RTE_LIBRTE_I40E_PMD
13197         if (ret == -ENOTSUP)
13198                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13199                                                buff, size,
13200                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
13201 #endif
13202
13203         if (ret == -EEXIST)
13204                 printf("Profile has already existed.\n");
13205         else if (ret < 0)
13206                 printf("Failed to load profile.\n");
13207         else if (file_num == 2)
13208                 save_ddp_package_file(file_fld[1], buff, size);
13209
13210         close_ddp_package_file(buff);
13211         free((void *)filepath);
13212 }
13213
13214 cmdline_parse_inst_t cmd_ddp_add = {
13215         .f = cmd_ddp_add_parsed,
13216         .data = NULL,
13217         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
13218         .tokens = {
13219                 (void *)&cmd_ddp_add_ddp,
13220                 (void *)&cmd_ddp_add_add,
13221                 (void *)&cmd_ddp_add_port_id,
13222                 (void *)&cmd_ddp_add_filepath,
13223                 NULL,
13224         },
13225 };
13226
13227 /* Delete dynamic device personalization*/
13228 struct cmd_ddp_del_result {
13229         cmdline_fixed_string_t ddp;
13230         cmdline_fixed_string_t del;
13231         uint8_t port_id;
13232         char filepath[];
13233 };
13234
13235 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13236         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13237 cmdline_parse_token_string_t cmd_ddp_del_del =
13238         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13239 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13240         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT8);
13241 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13242         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13243
13244 static void
13245 cmd_ddp_del_parsed(
13246         void *parsed_result,
13247         __attribute__((unused)) struct cmdline *cl,
13248         __attribute__((unused)) void *data)
13249 {
13250         struct cmd_ddp_del_result *res = parsed_result;
13251         uint8_t *buff;
13252         uint32_t size;
13253         int ret = -ENOTSUP;
13254
13255         if (res->port_id > nb_ports) {
13256                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13257                 return;
13258         }
13259
13260         if (!all_ports_stopped()) {
13261                 printf("Please stop all ports first\n");
13262                 return;
13263         }
13264
13265         buff = open_ddp_package_file(res->filepath, &size);
13266         if (!buff)
13267                 return;
13268
13269 #ifdef RTE_LIBRTE_I40E_PMD
13270         if (ret == -ENOTSUP)
13271                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13272                                                buff, size,
13273                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
13274 #endif
13275
13276         if (ret == -EACCES)
13277                 printf("Profile does not exist.\n");
13278         else if (ret < 0)
13279                 printf("Failed to delete profile.\n");
13280
13281         close_ddp_package_file(buff);
13282 }
13283
13284 cmdline_parse_inst_t cmd_ddp_del = {
13285         .f = cmd_ddp_del_parsed,
13286         .data = NULL,
13287         .help_str = "ddp del <port_id> <profile_path>",
13288         .tokens = {
13289                 (void *)&cmd_ddp_del_ddp,
13290                 (void *)&cmd_ddp_del_del,
13291                 (void *)&cmd_ddp_del_port_id,
13292                 (void *)&cmd_ddp_del_filepath,
13293                 NULL,
13294         },
13295 };
13296
13297 /* Get dynamic device personalization profile info */
13298 struct cmd_ddp_info_result {
13299         cmdline_fixed_string_t ddp;
13300         cmdline_fixed_string_t get;
13301         cmdline_fixed_string_t info;
13302         char filepath[];
13303 };
13304
13305 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13306         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13307 cmdline_parse_token_string_t cmd_ddp_info_get =
13308         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13309 cmdline_parse_token_string_t cmd_ddp_info_info =
13310         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13311 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13312         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13313
13314 static void
13315 cmd_ddp_info_parsed(
13316         void *parsed_result,
13317         __attribute__((unused)) struct cmdline *cl,
13318         __attribute__((unused)) void *data)
13319 {
13320         struct cmd_ddp_info_result *res = parsed_result;
13321         uint8_t *pkg;
13322         uint32_t pkg_size;
13323         int ret = -ENOTSUP;
13324 #ifdef RTE_LIBRTE_I40E_PMD
13325         uint32_t i;
13326         uint8_t *buff;
13327         uint32_t buff_size;
13328         struct rte_pmd_i40e_profile_info info;
13329         uint32_t dev_num;
13330         struct rte_pmd_i40e_ddp_device_id *devs;
13331 #endif
13332
13333         pkg = open_ddp_package_file(res->filepath, &pkg_size);
13334         if (!pkg)
13335                 return;
13336
13337 #ifdef RTE_LIBRTE_I40E_PMD
13338         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13339                                 (uint8_t *)&info, sizeof(info),
13340                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13341         if (!ret) {
13342                 printf("Global Track id:       0x%x\n", info.track_id);
13343                 printf("Global Version:        %d.%d.%d.%d\n",
13344                         info.version.major,
13345                         info.version.minor,
13346                         info.version.update,
13347                         info.version.draft);
13348                 printf("Global Package name:   %s\n\n", info.name);
13349         }
13350
13351         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13352                                 (uint8_t *)&info, sizeof(info),
13353                                 RTE_PMD_I40E_PKG_INFO_HEADER);
13354         if (!ret) {
13355                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
13356                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
13357                         info.version.major,
13358                         info.version.minor,
13359                         info.version.update,
13360                         info.version.draft);
13361                 printf("i40e Profile name:     %s\n\n", info.name);
13362         }
13363
13364         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13365                                 (uint8_t *)&buff_size, sizeof(buff_size),
13366                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13367         if (!ret && buff_size) {
13368                 buff = (uint8_t *)malloc(buff_size);
13369                 if (buff) {
13370                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13371                                                 buff, buff_size,
13372                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13373                         if (!ret)
13374                                 printf("Package Notes:\n%s\n\n", buff);
13375                         free(buff);
13376                 }
13377         }
13378
13379         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13380                                 (uint8_t *)&dev_num, sizeof(dev_num),
13381                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13382         if (!ret && dev_num) {
13383                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(dev_num *
13384                         sizeof(struct rte_pmd_i40e_ddp_device_id));
13385                 if (devs) {
13386                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13387                                                 (uint8_t *)devs, dev_num *
13388                                                 sizeof(struct rte_pmd_i40e_ddp_device_id),
13389                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13390                         if (!ret) {
13391                                 printf("List of supported devices:\n");
13392                                 for (i = 0; i < dev_num; i++) {
13393                                         printf("  %04X:%04X %04X:%04X\n",
13394                                                 devs[i].vendor_dev_id >> 16,
13395                                                 devs[i].vendor_dev_id & 0xFFFF,
13396                                                 devs[i].sub_vendor_dev_id >> 16,
13397                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
13398                                 }
13399                                 printf("\n");
13400                         }
13401                         free(devs);
13402                 }
13403         }
13404         ret = 0;
13405 #endif
13406         if (ret == -ENOTSUP)
13407                 printf("Function not supported in PMD driver\n");
13408         close_ddp_package_file(pkg);
13409 }
13410
13411 cmdline_parse_inst_t cmd_ddp_get_info = {
13412         .f = cmd_ddp_info_parsed,
13413         .data = NULL,
13414         .help_str = "ddp get info <profile_path>",
13415         .tokens = {
13416                 (void *)&cmd_ddp_info_ddp,
13417                 (void *)&cmd_ddp_info_get,
13418                 (void *)&cmd_ddp_info_info,
13419                 (void *)&cmd_ddp_info_filepath,
13420                 NULL,
13421         },
13422 };
13423
13424 /* Get dynamic device personalization profile info list*/
13425 #define PROFILE_INFO_SIZE 48
13426 #define MAX_PROFILE_NUM 16
13427
13428 struct cmd_ddp_get_list_result {
13429         cmdline_fixed_string_t ddp;
13430         cmdline_fixed_string_t get;
13431         cmdline_fixed_string_t list;
13432         uint8_t port_id;
13433 };
13434
13435 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
13436         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
13437 cmdline_parse_token_string_t cmd_ddp_get_list_get =
13438         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
13439 cmdline_parse_token_string_t cmd_ddp_get_list_list =
13440         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
13441 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
13442         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8);
13443
13444 static void
13445 cmd_ddp_get_list_parsed(
13446         void *parsed_result,
13447         __attribute__((unused)) struct cmdline *cl,
13448         __attribute__((unused)) void *data)
13449 {
13450         struct cmd_ddp_get_list_result *res = parsed_result;
13451 #ifdef RTE_LIBRTE_I40E_PMD
13452         struct rte_pmd_i40e_profile_list *p_list;
13453         struct rte_pmd_i40e_profile_info *p_info;
13454         uint32_t p_num;
13455         uint32_t size;
13456         uint32_t i;
13457 #endif
13458         int ret = -ENOTSUP;
13459
13460         if (res->port_id > nb_ports) {
13461                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13462                 return;
13463         }
13464
13465 #ifdef RTE_LIBRTE_I40E_PMD
13466         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
13467         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
13468         if (!p_list)
13469                 printf("%s: Failed to malloc buffer\n", __func__);
13470
13471         if (ret == -ENOTSUP)
13472                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
13473                                                 (uint8_t *)p_list, size);
13474
13475         if (!ret) {
13476                 p_num = p_list->p_count;
13477                 printf("Profile number is: %d\n\n", p_num);
13478
13479                 for (i = 0; i < p_num; i++) {
13480                         p_info = &p_list->p_info[i];
13481                         printf("Profile %d:\n", i);
13482                         printf("Track id:     0x%x\n", p_info->track_id);
13483                         printf("Version:      %d.%d.%d.%d\n",
13484                                p_info->version.major,
13485                                p_info->version.minor,
13486                                p_info->version.update,
13487                                p_info->version.draft);
13488                         printf("Profile name: %s\n\n", p_info->name);
13489                 }
13490         }
13491
13492         free(p_list);
13493 #endif
13494
13495         if (ret < 0)
13496                 printf("Failed to get ddp list\n");
13497 }
13498
13499 cmdline_parse_inst_t cmd_ddp_get_list = {
13500         .f = cmd_ddp_get_list_parsed,
13501         .data = NULL,
13502         .help_str = "ddp get list <port_id>",
13503         .tokens = {
13504                 (void *)&cmd_ddp_get_list_ddp,
13505                 (void *)&cmd_ddp_get_list_get,
13506                 (void *)&cmd_ddp_get_list_list,
13507                 (void *)&cmd_ddp_get_list_port_id,
13508                 NULL,
13509         },
13510 };
13511
13512 /* show vf stats */
13513
13514 /* Common result structure for show vf stats */
13515 struct cmd_show_vf_stats_result {
13516         cmdline_fixed_string_t show;
13517         cmdline_fixed_string_t vf;
13518         cmdline_fixed_string_t stats;
13519         uint8_t port_id;
13520         uint16_t vf_id;
13521 };
13522
13523 /* Common CLI fields show vf stats*/
13524 cmdline_parse_token_string_t cmd_show_vf_stats_show =
13525         TOKEN_STRING_INITIALIZER
13526                 (struct cmd_show_vf_stats_result,
13527                  show, "show");
13528 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
13529         TOKEN_STRING_INITIALIZER
13530                 (struct cmd_show_vf_stats_result,
13531                  vf, "vf");
13532 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
13533         TOKEN_STRING_INITIALIZER
13534                 (struct cmd_show_vf_stats_result,
13535                  stats, "stats");
13536 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
13537         TOKEN_NUM_INITIALIZER
13538                 (struct cmd_show_vf_stats_result,
13539                  port_id, UINT8);
13540 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
13541         TOKEN_NUM_INITIALIZER
13542                 (struct cmd_show_vf_stats_result,
13543                  vf_id, UINT16);
13544
13545 static void
13546 cmd_show_vf_stats_parsed(
13547         void *parsed_result,
13548         __attribute__((unused)) struct cmdline *cl,
13549         __attribute__((unused)) void *data)
13550 {
13551         struct cmd_show_vf_stats_result *res = parsed_result;
13552         struct rte_eth_stats stats;
13553         int ret = -ENOTSUP;
13554         static const char *nic_stats_border = "########################";
13555
13556         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13557                 return;
13558
13559         memset(&stats, 0, sizeof(stats));
13560
13561 #ifdef RTE_LIBRTE_I40E_PMD
13562         if (ret == -ENOTSUP)
13563                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
13564                                                 res->vf_id,
13565                                                 &stats);
13566 #endif
13567 #ifdef RTE_LIBRTE_BNXT_PMD
13568         if (ret == -ENOTSUP)
13569                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
13570                                                 res->vf_id,
13571                                                 &stats);
13572 #endif
13573
13574         switch (ret) {
13575         case 0:
13576                 break;
13577         case -EINVAL:
13578                 printf("invalid vf_id %d\n", res->vf_id);
13579                 break;
13580         case -ENODEV:
13581                 printf("invalid port_id %d\n", res->port_id);
13582                 break;
13583         case -ENOTSUP:
13584                 printf("function not implemented\n");
13585                 break;
13586         default:
13587                 printf("programming error: (%s)\n", strerror(-ret));
13588         }
13589
13590         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
13591                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
13592
13593         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
13594                "%-"PRIu64"\n",
13595                stats.ipackets, stats.imissed, stats.ibytes);
13596         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
13597         printf("  RX-nombuf:  %-10"PRIu64"\n",
13598                stats.rx_nombuf);
13599         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
13600                "%-"PRIu64"\n",
13601                stats.opackets, stats.oerrors, stats.obytes);
13602
13603         printf("  %s############################%s\n",
13604                                nic_stats_border, nic_stats_border);
13605 }
13606
13607 cmdline_parse_inst_t cmd_show_vf_stats = {
13608         .f = cmd_show_vf_stats_parsed,
13609         .data = NULL,
13610         .help_str = "show vf stats <port_id> <vf_id>",
13611         .tokens = {
13612                 (void *)&cmd_show_vf_stats_show,
13613                 (void *)&cmd_show_vf_stats_vf,
13614                 (void *)&cmd_show_vf_stats_stats,
13615                 (void *)&cmd_show_vf_stats_port_id,
13616                 (void *)&cmd_show_vf_stats_vf_id,
13617                 NULL,
13618         },
13619 };
13620
13621 /* clear vf stats */
13622
13623 /* Common result structure for clear vf stats */
13624 struct cmd_clear_vf_stats_result {
13625         cmdline_fixed_string_t clear;
13626         cmdline_fixed_string_t vf;
13627         cmdline_fixed_string_t stats;
13628         uint8_t port_id;
13629         uint16_t vf_id;
13630 };
13631
13632 /* Common CLI fields clear vf stats*/
13633 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
13634         TOKEN_STRING_INITIALIZER
13635                 (struct cmd_clear_vf_stats_result,
13636                  clear, "clear");
13637 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
13638         TOKEN_STRING_INITIALIZER
13639                 (struct cmd_clear_vf_stats_result,
13640                  vf, "vf");
13641 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
13642         TOKEN_STRING_INITIALIZER
13643                 (struct cmd_clear_vf_stats_result,
13644                  stats, "stats");
13645 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
13646         TOKEN_NUM_INITIALIZER
13647                 (struct cmd_clear_vf_stats_result,
13648                  port_id, UINT8);
13649 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
13650         TOKEN_NUM_INITIALIZER
13651                 (struct cmd_clear_vf_stats_result,
13652                  vf_id, UINT16);
13653
13654 static void
13655 cmd_clear_vf_stats_parsed(
13656         void *parsed_result,
13657         __attribute__((unused)) struct cmdline *cl,
13658         __attribute__((unused)) void *data)
13659 {
13660         struct cmd_clear_vf_stats_result *res = parsed_result;
13661         int ret = -ENOTSUP;
13662
13663         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13664                 return;
13665
13666 #ifdef RTE_LIBRTE_I40E_PMD
13667         if (ret == -ENOTSUP)
13668                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
13669                                                   res->vf_id);
13670 #endif
13671 #ifdef RTE_LIBRTE_BNXT_PMD
13672         if (ret == -ENOTSUP)
13673                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
13674                                                   res->vf_id);
13675 #endif
13676
13677         switch (ret) {
13678         case 0:
13679                 break;
13680         case -EINVAL:
13681                 printf("invalid vf_id %d\n", res->vf_id);
13682                 break;
13683         case -ENODEV:
13684                 printf("invalid port_id %d\n", res->port_id);
13685                 break;
13686         case -ENOTSUP:
13687                 printf("function not implemented\n");
13688                 break;
13689         default:
13690                 printf("programming error: (%s)\n", strerror(-ret));
13691         }
13692 }
13693
13694 cmdline_parse_inst_t cmd_clear_vf_stats = {
13695         .f = cmd_clear_vf_stats_parsed,
13696         .data = NULL,
13697         .help_str = "clear vf stats <port_id> <vf_id>",
13698         .tokens = {
13699                 (void *)&cmd_clear_vf_stats_clear,
13700                 (void *)&cmd_clear_vf_stats_vf,
13701                 (void *)&cmd_clear_vf_stats_stats,
13702                 (void *)&cmd_clear_vf_stats_port_id,
13703                 (void *)&cmd_clear_vf_stats_vf_id,
13704                 NULL,
13705         },
13706 };
13707
13708 /* ptype mapping get */
13709
13710 /* Common result structure for ptype mapping get */
13711 struct cmd_ptype_mapping_get_result {
13712         cmdline_fixed_string_t ptype;
13713         cmdline_fixed_string_t mapping;
13714         cmdline_fixed_string_t get;
13715         uint8_t port_id;
13716         uint8_t valid_only;
13717 };
13718
13719 /* Common CLI fields for ptype mapping get */
13720 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
13721         TOKEN_STRING_INITIALIZER
13722                 (struct cmd_ptype_mapping_get_result,
13723                  ptype, "ptype");
13724 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
13725         TOKEN_STRING_INITIALIZER
13726                 (struct cmd_ptype_mapping_get_result,
13727                  mapping, "mapping");
13728 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
13729         TOKEN_STRING_INITIALIZER
13730                 (struct cmd_ptype_mapping_get_result,
13731                  get, "get");
13732 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
13733         TOKEN_NUM_INITIALIZER
13734                 (struct cmd_ptype_mapping_get_result,
13735                  port_id, UINT8);
13736 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
13737         TOKEN_NUM_INITIALIZER
13738                 (struct cmd_ptype_mapping_get_result,
13739                  valid_only, UINT8);
13740
13741 static void
13742 cmd_ptype_mapping_get_parsed(
13743         void *parsed_result,
13744         __attribute__((unused)) struct cmdline *cl,
13745         __attribute__((unused)) void *data)
13746 {
13747         struct cmd_ptype_mapping_get_result *res = parsed_result;
13748         int ret = -ENOTSUP;
13749 #ifdef RTE_LIBRTE_I40E_PMD
13750         int max_ptype_num = 256;
13751         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
13752         uint16_t count;
13753         int i;
13754 #endif
13755
13756         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13757                 return;
13758
13759 #ifdef RTE_LIBRTE_I40E_PMD
13760         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
13761                                         mapping,
13762                                         max_ptype_num,
13763                                         &count,
13764                                         res->valid_only);
13765 #endif
13766
13767         switch (ret) {
13768         case 0:
13769                 break;
13770         case -ENODEV:
13771                 printf("invalid port_id %d\n", res->port_id);
13772                 break;
13773         case -ENOTSUP:
13774                 printf("function not implemented\n");
13775                 break;
13776         default:
13777                 printf("programming error: (%s)\n", strerror(-ret));
13778         }
13779
13780 #ifdef RTE_LIBRTE_I40E_PMD
13781         if (!ret) {
13782                 for (i = 0; i < count; i++)
13783                         printf("%3d\t0x%08x\n",
13784                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
13785         }
13786 #endif
13787 }
13788
13789 cmdline_parse_inst_t cmd_ptype_mapping_get = {
13790         .f = cmd_ptype_mapping_get_parsed,
13791         .data = NULL,
13792         .help_str = "ptype mapping get <port_id> <valid_only>",
13793         .tokens = {
13794                 (void *)&cmd_ptype_mapping_get_ptype,
13795                 (void *)&cmd_ptype_mapping_get_mapping,
13796                 (void *)&cmd_ptype_mapping_get_get,
13797                 (void *)&cmd_ptype_mapping_get_port_id,
13798                 (void *)&cmd_ptype_mapping_get_valid_only,
13799                 NULL,
13800         },
13801 };
13802
13803 /* ptype mapping replace */
13804
13805 /* Common result structure for ptype mapping replace */
13806 struct cmd_ptype_mapping_replace_result {
13807         cmdline_fixed_string_t ptype;
13808         cmdline_fixed_string_t mapping;
13809         cmdline_fixed_string_t replace;
13810         uint8_t port_id;
13811         uint32_t target;
13812         uint8_t mask;
13813         uint32_t pkt_type;
13814 };
13815
13816 /* Common CLI fields for ptype mapping replace */
13817 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
13818         TOKEN_STRING_INITIALIZER
13819                 (struct cmd_ptype_mapping_replace_result,
13820                  ptype, "ptype");
13821 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
13822         TOKEN_STRING_INITIALIZER
13823                 (struct cmd_ptype_mapping_replace_result,
13824                  mapping, "mapping");
13825 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
13826         TOKEN_STRING_INITIALIZER
13827                 (struct cmd_ptype_mapping_replace_result,
13828                  replace, "replace");
13829 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
13830         TOKEN_NUM_INITIALIZER
13831                 (struct cmd_ptype_mapping_replace_result,
13832                  port_id, UINT8);
13833 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
13834         TOKEN_NUM_INITIALIZER
13835                 (struct cmd_ptype_mapping_replace_result,
13836                  target, UINT32);
13837 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
13838         TOKEN_NUM_INITIALIZER
13839                 (struct cmd_ptype_mapping_replace_result,
13840                  mask, UINT8);
13841 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
13842         TOKEN_NUM_INITIALIZER
13843                 (struct cmd_ptype_mapping_replace_result,
13844                  pkt_type, UINT32);
13845
13846 static void
13847 cmd_ptype_mapping_replace_parsed(
13848         void *parsed_result,
13849         __attribute__((unused)) struct cmdline *cl,
13850         __attribute__((unused)) void *data)
13851 {
13852         struct cmd_ptype_mapping_replace_result *res = parsed_result;
13853         int ret = -ENOTSUP;
13854
13855         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13856                 return;
13857
13858 #ifdef RTE_LIBRTE_I40E_PMD
13859         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
13860                                         res->target,
13861                                         res->mask,
13862                                         res->pkt_type);
13863 #endif
13864
13865         switch (ret) {
13866         case 0:
13867                 break;
13868         case -EINVAL:
13869                 printf("invalid ptype 0x%8x or 0x%8x\n",
13870                                 res->target, res->pkt_type);
13871                 break;
13872         case -ENODEV:
13873                 printf("invalid port_id %d\n", res->port_id);
13874                 break;
13875         case -ENOTSUP:
13876                 printf("function not implemented\n");
13877                 break;
13878         default:
13879                 printf("programming error: (%s)\n", strerror(-ret));
13880         }
13881 }
13882
13883 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
13884         .f = cmd_ptype_mapping_replace_parsed,
13885         .data = NULL,
13886         .help_str =
13887                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
13888         .tokens = {
13889                 (void *)&cmd_ptype_mapping_replace_ptype,
13890                 (void *)&cmd_ptype_mapping_replace_mapping,
13891                 (void *)&cmd_ptype_mapping_replace_replace,
13892                 (void *)&cmd_ptype_mapping_replace_port_id,
13893                 (void *)&cmd_ptype_mapping_replace_target,
13894                 (void *)&cmd_ptype_mapping_replace_mask,
13895                 (void *)&cmd_ptype_mapping_replace_pkt_type,
13896                 NULL,
13897         },
13898 };
13899
13900 /* ptype mapping reset */
13901
13902 /* Common result structure for ptype mapping reset */
13903 struct cmd_ptype_mapping_reset_result {
13904         cmdline_fixed_string_t ptype;
13905         cmdline_fixed_string_t mapping;
13906         cmdline_fixed_string_t reset;
13907         uint8_t port_id;
13908 };
13909
13910 /* Common CLI fields for ptype mapping reset*/
13911 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
13912         TOKEN_STRING_INITIALIZER
13913                 (struct cmd_ptype_mapping_reset_result,
13914                  ptype, "ptype");
13915 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
13916         TOKEN_STRING_INITIALIZER
13917                 (struct cmd_ptype_mapping_reset_result,
13918                  mapping, "mapping");
13919 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
13920         TOKEN_STRING_INITIALIZER
13921                 (struct cmd_ptype_mapping_reset_result,
13922                  reset, "reset");
13923 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
13924         TOKEN_NUM_INITIALIZER
13925                 (struct cmd_ptype_mapping_reset_result,
13926                  port_id, UINT8);
13927
13928 static void
13929 cmd_ptype_mapping_reset_parsed(
13930         void *parsed_result,
13931         __attribute__((unused)) struct cmdline *cl,
13932         __attribute__((unused)) void *data)
13933 {
13934         struct cmd_ptype_mapping_reset_result *res = parsed_result;
13935         int ret = -ENOTSUP;
13936
13937         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13938                 return;
13939
13940 #ifdef RTE_LIBRTE_I40E_PMD
13941         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
13942 #endif
13943
13944         switch (ret) {
13945         case 0:
13946                 break;
13947         case -ENODEV:
13948                 printf("invalid port_id %d\n", res->port_id);
13949                 break;
13950         case -ENOTSUP:
13951                 printf("function not implemented\n");
13952                 break;
13953         default:
13954                 printf("programming error: (%s)\n", strerror(-ret));
13955         }
13956 }
13957
13958 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
13959         .f = cmd_ptype_mapping_reset_parsed,
13960         .data = NULL,
13961         .help_str = "ptype mapping reset <port_id>",
13962         .tokens = {
13963                 (void *)&cmd_ptype_mapping_reset_ptype,
13964                 (void *)&cmd_ptype_mapping_reset_mapping,
13965                 (void *)&cmd_ptype_mapping_reset_reset,
13966                 (void *)&cmd_ptype_mapping_reset_port_id,
13967                 NULL,
13968         },
13969 };
13970
13971 /* ptype mapping update */
13972
13973 /* Common result structure for ptype mapping update */
13974 struct cmd_ptype_mapping_update_result {
13975         cmdline_fixed_string_t ptype;
13976         cmdline_fixed_string_t mapping;
13977         cmdline_fixed_string_t reset;
13978         uint8_t port_id;
13979         uint8_t hw_ptype;
13980         uint32_t sw_ptype;
13981 };
13982
13983 /* Common CLI fields for ptype mapping update*/
13984 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
13985         TOKEN_STRING_INITIALIZER
13986                 (struct cmd_ptype_mapping_update_result,
13987                  ptype, "ptype");
13988 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
13989         TOKEN_STRING_INITIALIZER
13990                 (struct cmd_ptype_mapping_update_result,
13991                  mapping, "mapping");
13992 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
13993         TOKEN_STRING_INITIALIZER
13994                 (struct cmd_ptype_mapping_update_result,
13995                  reset, "update");
13996 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
13997         TOKEN_NUM_INITIALIZER
13998                 (struct cmd_ptype_mapping_update_result,
13999                  port_id, UINT8);
14000 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
14001         TOKEN_NUM_INITIALIZER
14002                 (struct cmd_ptype_mapping_update_result,
14003                  hw_ptype, UINT8);
14004 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
14005         TOKEN_NUM_INITIALIZER
14006                 (struct cmd_ptype_mapping_update_result,
14007                  sw_ptype, UINT32);
14008
14009 static void
14010 cmd_ptype_mapping_update_parsed(
14011         void *parsed_result,
14012         __attribute__((unused)) struct cmdline *cl,
14013         __attribute__((unused)) void *data)
14014 {
14015         struct cmd_ptype_mapping_update_result *res = parsed_result;
14016         int ret = -ENOTSUP;
14017 #ifdef RTE_LIBRTE_I40E_PMD
14018         struct rte_pmd_i40e_ptype_mapping mapping;
14019 #endif
14020         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14021                 return;
14022
14023 #ifdef RTE_LIBRTE_I40E_PMD
14024         mapping.hw_ptype = res->hw_ptype;
14025         mapping.sw_ptype = res->sw_ptype;
14026         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
14027                                                 &mapping,
14028                                                 1,
14029                                                 0);
14030 #endif
14031
14032         switch (ret) {
14033         case 0:
14034                 break;
14035         case -EINVAL:
14036                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
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_ptype_mapping_update = {
14050         .f = cmd_ptype_mapping_update_parsed,
14051         .data = NULL,
14052         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
14053         .tokens = {
14054                 (void *)&cmd_ptype_mapping_update_ptype,
14055                 (void *)&cmd_ptype_mapping_update_mapping,
14056                 (void *)&cmd_ptype_mapping_update_update,
14057                 (void *)&cmd_ptype_mapping_update_port_id,
14058                 (void *)&cmd_ptype_mapping_update_hw_ptype,
14059                 (void *)&cmd_ptype_mapping_update_sw_ptype,
14060                 NULL,
14061         },
14062 };
14063
14064 /* Common result structure for file commands */
14065 struct cmd_cmdfile_result {
14066         cmdline_fixed_string_t load;
14067         cmdline_fixed_string_t filename;
14068 };
14069
14070 /* Common CLI fields for file commands */
14071 cmdline_parse_token_string_t cmd_load_cmdfile =
14072         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
14073 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
14074         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
14075
14076 static void
14077 cmd_load_from_file_parsed(
14078         void *parsed_result,
14079         __attribute__((unused)) struct cmdline *cl,
14080         __attribute__((unused)) void *data)
14081 {
14082         struct cmd_cmdfile_result *res = parsed_result;
14083
14084         cmdline_read_from_file(res->filename);
14085 }
14086
14087 cmdline_parse_inst_t cmd_load_from_file = {
14088         .f = cmd_load_from_file_parsed,
14089         .data = NULL,
14090         .help_str = "load <filename>",
14091         .tokens = {
14092                 (void *)&cmd_load_cmdfile,
14093                 (void *)&cmd_load_cmdfile_filename,
14094                 NULL,
14095         },
14096 };
14097
14098 /* ******************************************************************************** */
14099
14100 /* list of instructions */
14101 cmdline_parse_ctx_t main_ctx[] = {
14102         (cmdline_parse_inst_t *)&cmd_help_brief,
14103         (cmdline_parse_inst_t *)&cmd_help_long,
14104         (cmdline_parse_inst_t *)&cmd_quit,
14105         (cmdline_parse_inst_t *)&cmd_load_from_file,
14106         (cmdline_parse_inst_t *)&cmd_showport,
14107         (cmdline_parse_inst_t *)&cmd_showqueue,
14108         (cmdline_parse_inst_t *)&cmd_showportall,
14109         (cmdline_parse_inst_t *)&cmd_showcfg,
14110         (cmdline_parse_inst_t *)&cmd_start,
14111         (cmdline_parse_inst_t *)&cmd_start_tx_first,
14112         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
14113         (cmdline_parse_inst_t *)&cmd_set_link_up,
14114         (cmdline_parse_inst_t *)&cmd_set_link_down,
14115         (cmdline_parse_inst_t *)&cmd_reset,
14116         (cmdline_parse_inst_t *)&cmd_set_numbers,
14117         (cmdline_parse_inst_t *)&cmd_set_txpkts,
14118         (cmdline_parse_inst_t *)&cmd_set_txsplit,
14119         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
14120         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
14121         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
14122         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
14123         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
14124         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
14125         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
14126         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
14127         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
14128         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
14129         (cmdline_parse_inst_t *)&cmd_set_link_check,
14130         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
14131         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
14132         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
14133         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
14134 #ifdef RTE_LIBRTE_PMD_BOND
14135         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
14136         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
14137         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
14138         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
14139         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
14140         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
14141         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
14142         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
14143         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
14144         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
14145 #endif
14146         (cmdline_parse_inst_t *)&cmd_vlan_offload,
14147         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
14148         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
14149         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
14150         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
14151         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
14152         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
14153         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
14154         (cmdline_parse_inst_t *)&cmd_csum_set,
14155         (cmdline_parse_inst_t *)&cmd_csum_show,
14156         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
14157         (cmdline_parse_inst_t *)&cmd_tso_set,
14158         (cmdline_parse_inst_t *)&cmd_tso_show,
14159         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
14160         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
14161         (cmdline_parse_inst_t *)&cmd_enable_gro,
14162         (cmdline_parse_inst_t *)&cmd_gro_set,
14163         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
14164         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
14165         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
14166         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
14167         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
14168         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
14169         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
14170         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
14171         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
14172         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
14173         (cmdline_parse_inst_t *)&cmd_config_dcb,
14174         (cmdline_parse_inst_t *)&cmd_read_reg,
14175         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
14176         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
14177         (cmdline_parse_inst_t *)&cmd_write_reg,
14178         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
14179         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
14180         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
14181         (cmdline_parse_inst_t *)&cmd_stop,
14182         (cmdline_parse_inst_t *)&cmd_mac_addr,
14183         (cmdline_parse_inst_t *)&cmd_set_qmap,
14184         (cmdline_parse_inst_t *)&cmd_operate_port,
14185         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
14186         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
14187         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
14188         (cmdline_parse_inst_t *)&cmd_config_speed_all,
14189         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
14190         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
14191         (cmdline_parse_inst_t *)&cmd_config_mtu,
14192         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
14193         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
14194         (cmdline_parse_inst_t *)&cmd_config_rss,
14195         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
14196         (cmdline_parse_inst_t *)&cmd_config_txqflags,
14197         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
14198         (cmdline_parse_inst_t *)&cmd_showport_reta,
14199         (cmdline_parse_inst_t *)&cmd_config_burst,
14200         (cmdline_parse_inst_t *)&cmd_config_thresh,
14201         (cmdline_parse_inst_t *)&cmd_config_threshold,
14202         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
14203         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
14204         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
14205         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
14206         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
14207         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
14208         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
14209         (cmdline_parse_inst_t *)&cmd_global_config,
14210         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
14211         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
14212         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
14213         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
14214         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
14215         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
14216         (cmdline_parse_inst_t *)&cmd_dump,
14217         (cmdline_parse_inst_t *)&cmd_dump_one,
14218         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
14219         (cmdline_parse_inst_t *)&cmd_syn_filter,
14220         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
14221         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
14222         (cmdline_parse_inst_t *)&cmd_flex_filter,
14223         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
14224         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
14225         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
14226         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
14227         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
14228         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
14229         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
14230         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
14231         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
14232         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
14233         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
14234         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
14235         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
14236         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
14237         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
14238         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
14239         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
14240         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
14241         (cmdline_parse_inst_t *)&cmd_flow,
14242         (cmdline_parse_inst_t *)&cmd_mcast_addr,
14243         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
14244         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
14245         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
14246         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
14247         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
14248         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
14249         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
14250         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
14251         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
14252         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
14253         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
14254         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
14255         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
14256         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
14257         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
14258         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
14259         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
14260         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
14261         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
14262         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
14263         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
14264         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
14265         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
14266         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
14267         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
14268         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
14269         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
14270         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
14271         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
14272         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
14273         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
14274         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
14275         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
14276         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
14277         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
14278         (cmdline_parse_inst_t *)&cmd_ddp_add,
14279         (cmdline_parse_inst_t *)&cmd_ddp_del,
14280         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
14281         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
14282         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
14283         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
14284         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
14285         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
14286         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
14287         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
14288         NULL,
14289 };
14290
14291 /* read cmdline commands from file */
14292 void
14293 cmdline_read_from_file(const char *filename)
14294 {
14295         struct cmdline *cl;
14296
14297         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
14298         if (cl == NULL) {
14299                 printf("Failed to create file based cmdline context: %s\n",
14300                        filename);
14301                 return;
14302         }
14303
14304         cmdline_interact(cl);
14305         cmdline_quit(cl);
14306
14307         cmdline_free(cl);
14308
14309         printf("Read CLI commands from %s\n", filename);
14310 }
14311
14312 /* prompt function, called from main on MASTER lcore */
14313 void
14314 prompt(void)
14315 {
14316         /* initialize non-constant commands */
14317         cmd_set_fwd_mode_init();
14318         cmd_set_fwd_retry_mode_init();
14319
14320         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
14321         if (testpmd_cl == NULL)
14322                 return;
14323         cmdline_interact(testpmd_cl);
14324         cmdline_stdin_exit(testpmd_cl);
14325 }
14326
14327 void
14328 prompt_exit(void)
14329 {
14330         if (testpmd_cl != NULL)
14331                 cmdline_quit(testpmd_cl);
14332 }
14333
14334 static void
14335 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
14336 {
14337         if (id == (portid_t)RTE_PORT_ALL) {
14338                 portid_t pid;
14339
14340                 RTE_ETH_FOREACH_DEV(pid) {
14341                         /* check if need_reconfig has been set to 1 */
14342                         if (ports[pid].need_reconfig == 0)
14343                                 ports[pid].need_reconfig = dev;
14344                         /* check if need_reconfig_queues has been set to 1 */
14345                         if (ports[pid].need_reconfig_queues == 0)
14346                                 ports[pid].need_reconfig_queues = queue;
14347                 }
14348         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
14349                 /* check if need_reconfig has been set to 1 */
14350                 if (ports[id].need_reconfig == 0)
14351                         ports[id].need_reconfig = dev;
14352                 /* check if need_reconfig_queues has been set to 1 */
14353                 if (ports[id].need_reconfig_queues == 0)
14354                         ports[id].need_reconfig_queues = queue;
14355         }
14356 }