net/mlx5: use flow to enable promiscuous mode
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51
52 #include <sys/queue.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.h>
79
80 #include <cmdline_rdline.h>
81 #include <cmdline_parse.h>
82 #include <cmdline_parse_num.h>
83 #include <cmdline_parse_string.h>
84 #include <cmdline_parse_ipaddr.h>
85 #include <cmdline_parse_etheraddr.h>
86 #include <cmdline_socket.h>
87 #include <cmdline.h>
88 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_IXGBE_PMD
93 #include <rte_pmd_ixgbe.h>
94 #endif
95 #ifdef RTE_LIBRTE_I40E_PMD
96 #include <rte_pmd_i40e.h>
97 #endif
98 #ifdef RTE_LIBRTE_BNXT_PMD
99 #include <rte_pmd_bnxt.h>
100 #endif
101 #include "testpmd.h"
102
103 static struct cmdline *testpmd_cl;
104
105 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
106
107 /* *** Help command with introduction. *** */
108 struct cmd_help_brief_result {
109         cmdline_fixed_string_t help;
110 };
111
112 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
113                                   struct cmdline *cl,
114                                   __attribute__((unused)) void *data)
115 {
116         cmdline_printf(
117                 cl,
118                 "\n"
119                 "Help is available for the following sections:\n\n"
120                 "    help control    : Start and stop forwarding.\n"
121                 "    help display    : Displaying port, stats and config "
122                 "information.\n"
123                 "    help config     : Configuration information.\n"
124                 "    help ports      : Configuring ports.\n"
125                 "    help registers  : Reading and setting port registers.\n"
126                 "    help filters    : Filters configuration help.\n"
127                 "    help all        : All of the above sections.\n\n"
128         );
129
130 }
131
132 cmdline_parse_token_string_t cmd_help_brief_help =
133         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
134
135 cmdline_parse_inst_t cmd_help_brief = {
136         .f = cmd_help_brief_parsed,
137         .data = NULL,
138         .help_str = "help: Show help",
139         .tokens = {
140                 (void *)&cmd_help_brief_help,
141                 NULL,
142         },
143 };
144
145 /* *** Help command with help sections. *** */
146 struct cmd_help_long_result {
147         cmdline_fixed_string_t help;
148         cmdline_fixed_string_t section;
149 };
150
151 static void cmd_help_long_parsed(void *parsed_result,
152                                  struct cmdline *cl,
153                                  __attribute__((unused)) void *data)
154 {
155         int show_all = 0;
156         struct cmd_help_long_result *res = parsed_result;
157
158         if (!strcmp(res->section, "all"))
159                 show_all = 1;
160
161         if (show_all || !strcmp(res->section, "control")) {
162
163                 cmdline_printf(
164                         cl,
165                         "\n"
166                         "Control forwarding:\n"
167                         "-------------------\n\n"
168
169                         "start\n"
170                         "    Start packet forwarding with current configuration.\n\n"
171
172                         "start tx_first\n"
173                         "    Start packet forwarding with current config"
174                         " after sending one burst of packets.\n\n"
175
176                         "stop\n"
177                         "    Stop packet forwarding, and display accumulated"
178                         " statistics.\n\n"
179
180                         "quit\n"
181                         "    Quit to prompt.\n\n"
182                 );
183         }
184
185         if (show_all || !strcmp(res->section, "display")) {
186
187                 cmdline_printf(
188                         cl,
189                         "\n"
190                         "Display:\n"
191                         "--------\n\n"
192
193                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
194                         "    Display information for port_id, or all.\n\n"
195
196                         "show port X rss reta (size) (mask0,mask1,...)\n"
197                         "    Display the rss redirection table entry indicated"
198                         " by masks on port X. size is used to indicate the"
199                         " hardware supported reta size\n\n"
200
201                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
202                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
203                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
204                         "    Display the RSS hash functions and RSS hash key"
205                         " of port X\n\n"
206
207                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
208                         "    Clear information for port_id, or all.\n\n"
209
210                         "show (rxq|txq) info (port_id) (queue_id)\n"
211                         "    Display information for configured RX/TX queue.\n\n"
212
213                         "show config (rxtx|cores|fwd|txpkts)\n"
214                         "    Display the given configuration.\n\n"
215
216                         "read rxd (port_id) (queue_id) (rxd_id)\n"
217                         "    Display an RX descriptor of a port RX queue.\n\n"
218
219                         "read txd (port_id) (queue_id) (txd_id)\n"
220                         "    Display a TX descriptor of a port TX queue.\n\n"
221
222                         "ddp get list (port_id)\n"
223                         "    Get ddp profile info list\n\n"
224
225                         "ddp get info (profile_path)\n"
226                         "    Get ddp profile information.\n\n"
227
228                         "show vf stats (port_id) (vf_id)\n"
229                         "    Display a VF's statistics.\n\n"
230
231                         "clear vf stats (port_id) (vf_id)\n"
232                         "    Reset a VF's statistics.\n\n"
233
234                         "show port (port_id) pctype mapping\n"
235                         "    Get flow ptype to pctype mapping on a port\n\n"
236
237                 );
238         }
239
240         if (show_all || !strcmp(res->section, "config")) {
241                 cmdline_printf(
242                         cl,
243                         "\n"
244                         "Configuration:\n"
245                         "--------------\n"
246                         "Configuration changes only become active when"
247                         " forwarding is started/restarted.\n\n"
248
249                         "set default\n"
250                         "    Reset forwarding to the default configuration.\n\n"
251
252                         "set verbose (level)\n"
253                         "    Set the debug verbosity level X.\n\n"
254
255                         "set nbport (num)\n"
256                         "    Set number of ports.\n\n"
257
258                         "set nbcore (num)\n"
259                         "    Set number of cores.\n\n"
260
261                         "set coremask (mask)\n"
262                         "    Set the forwarding cores hexadecimal mask.\n\n"
263
264                         "set portmask (mask)\n"
265                         "    Set the forwarding ports hexadecimal mask.\n\n"
266
267                         "set burst (num)\n"
268                         "    Set number of packets per burst.\n\n"
269
270                         "set burst tx delay (microseconds) retry (num)\n"
271                         "    Set the transmit delay time and number of retries,"
272                         " effective when retry is enabled.\n\n"
273
274                         "set txpkts (x[,y]*)\n"
275                         "    Set the length of each segment of TXONLY"
276                         " and optionally CSUM packets.\n\n"
277
278                         "set txsplit (off|on|rand)\n"
279                         "    Set the split policy for the TX packets."
280                         " Right now only applicable for CSUM and TXONLY"
281                         " modes\n\n"
282
283                         "set corelist (x[,y]*)\n"
284                         "    Set the list of forwarding cores.\n\n"
285
286                         "set portlist (x[,y]*)\n"
287                         "    Set the list of forwarding ports.\n\n"
288
289                         "set tx loopback (port_id) (on|off)\n"
290                         "    Enable or disable tx loopback.\n\n"
291
292                         "set all queues drop (port_id) (on|off)\n"
293                         "    Set drop enable bit for all queues.\n\n"
294
295                         "set vf split drop (port_id) (vf_id) (on|off)\n"
296                         "    Set split drop enable bit for a VF from the PF.\n\n"
297
298                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
299                         "    Set MAC antispoof for a VF from the PF.\n\n"
300
301                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
302                         "    Enable MACsec offload.\n\n"
303
304                         "set macsec offload (port_id) off\n"
305                         "    Disable MACsec offload.\n\n"
306
307                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
308                         "    Configure MACsec secure connection (SC).\n\n"
309
310                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
311                         "    Configure MACsec secure association (SA).\n\n"
312
313                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
314                         "    Set VF broadcast for a VF from the PF.\n\n"
315
316                         "vlan set strip (on|off) (port_id)\n"
317                         "    Set the VLAN strip on a port.\n\n"
318
319                         "vlan set stripq (on|off) (port_id,queue_id)\n"
320                         "    Set the VLAN strip for a queue on a port.\n\n"
321
322                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
323                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
324
325                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
326                         "    Set VLAN insert for a VF from the PF.\n\n"
327
328                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
329                         "    Set VLAN antispoof for a VF from the PF.\n\n"
330
331                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
332                         "    Set VLAN tag for a VF from the PF.\n\n"
333
334                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
335                         "    Set a VF's max bandwidth(Mbps).\n\n"
336
337                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
338                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
339
340                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
341                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
342
343                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
344                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
345
346                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
347                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
348
349                         "vlan set filter (on|off) (port_id)\n"
350                         "    Set the VLAN filter on a port.\n\n"
351
352                         "vlan set qinq (on|off) (port_id)\n"
353                         "    Set the VLAN QinQ (extended queue in queue)"
354                         " on a port.\n\n"
355
356                         "vlan set (inner|outer) tpid (value) (port_id)\n"
357                         "    Set the VLAN TPID for Packet Filtering on"
358                         " a port\n\n"
359
360                         "rx_vlan add (vlan_id|all) (port_id)\n"
361                         "    Add a vlan_id, or all identifiers, to the set"
362                         " of VLAN identifiers filtered by port_id.\n\n"
363
364                         "rx_vlan rm (vlan_id|all) (port_id)\n"
365                         "    Remove a vlan_id, or all identifiers, from the set"
366                         " of VLAN identifiers filtered by port_id.\n\n"
367
368                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
369                         "    Add a vlan_id, to the set of VLAN identifiers"
370                         "filtered for VF(s) from port_id.\n\n"
371
372                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
373                         "    Remove a vlan_id, to the set of VLAN identifiers"
374                         "filtered for VF(s) from port_id.\n\n"
375
376                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
377                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
378                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
379                         "   add a tunnel filter of a port.\n\n"
380
381                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
382                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
383                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
384                         "   remove a tunnel filter of a port.\n\n"
385
386                         "rx_vxlan_port add (udp_port) (port_id)\n"
387                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
388
389                         "rx_vxlan_port rm (udp_port) (port_id)\n"
390                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
391
392                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
393                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
394                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
395
396                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
397                         "    Set port based TX VLAN insertion.\n\n"
398
399                         "tx_vlan reset (port_id)\n"
400                         "    Disable hardware insertion of a VLAN header in"
401                         " packets sent on a port.\n\n"
402
403                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
404                         "    Select hardware or software calculation of the"
405                         " checksum when transmitting a packet using the"
406                         " csum forward engine.\n"
407                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
408                         "    outer-ip concerns the outer IP layer in"
409                         " case the packet is recognized as a tunnel packet by"
410                         " the forward engine (vxlan, gre and ipip are supported)\n"
411                         "    Please check the NIC datasheet for HW limits.\n\n"
412
413                         "csum parse-tunnel (on|off) (tx_port_id)\n"
414                         "    If disabled, treat tunnel packets as non-tunneled"
415                         " packets (treat inner headers as payload). The port\n"
416                         "    argument is the port used for TX in csum forward"
417                         " engine.\n\n"
418
419                         "csum show (port_id)\n"
420                         "    Display tx checksum offload configuration\n\n"
421
422                         "tso set (segsize) (portid)\n"
423                         "    Enable TCP Segmentation Offload in csum forward"
424                         " engine.\n"
425                         "    Please check the NIC datasheet for HW limits.\n\n"
426
427                         "tso show (portid)"
428                         "    Display the status of TCP Segmentation Offload.\n\n"
429
430                         "set port (port_id) gro on|off\n"
431                         "    Enable or disable Generic Receive Offload in"
432                         " csum forwarding engine.\n\n"
433
434                         "show port (port_id) gro\n"
435                         "    Display GRO configuration.\n\n"
436
437                         "set gro flush (cycles)\n"
438                         "    Set the cycle to flush GROed packets from"
439                         " reassembly tables.\n\n"
440
441                         "set port (port_id) gso (on|off)"
442                         "    Enable or disable Generic Segmentation Offload in"
443                         " csum forwarding engine.\n\n"
444
445                         "set gso segsz (length)\n"
446                         "    Set max packet length for output GSO segments,"
447                         " including packet header and payload.\n\n"
448
449                         "show port (port_id) gso\n"
450                         "    Show GSO configuration.\n\n"
451
452                         "set fwd (%s)\n"
453                         "    Set packet forwarding mode.\n\n"
454
455                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
456                         "    Add a MAC address on port_id.\n\n"
457
458                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
459                         "    Remove a MAC address from port_id.\n\n"
460
461                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
462                         "    Set the default MAC address for port_id.\n\n"
463
464                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
465                         "    Add a MAC address for a VF on the port.\n\n"
466
467                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
468                         "    Set the MAC address for a VF from the PF.\n\n"
469
470                         "set port (port_id) uta (mac_address|all) (on|off)\n"
471                         "    Add/Remove a or all unicast hash filter(s)"
472                         "from port X.\n\n"
473
474                         "set promisc (port_id|all) (on|off)\n"
475                         "    Set the promiscuous mode on port_id, or all.\n\n"
476
477                         "set allmulti (port_id|all) (on|off)\n"
478                         "    Set the allmulti mode on port_id, or all.\n\n"
479
480                         "set vf promisc (port_id) (vf_id) (on|off)\n"
481                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
482
483                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
484                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
485
486                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
487                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
488                         " (on|off) autoneg (on|off) (port_id)\n"
489                         "set flow_ctrl rx (on|off) (portid)\n"
490                         "set flow_ctrl tx (on|off) (portid)\n"
491                         "set flow_ctrl high_water (high_water) (portid)\n"
492                         "set flow_ctrl low_water (low_water) (portid)\n"
493                         "set flow_ctrl pause_time (pause_time) (portid)\n"
494                         "set flow_ctrl send_xon (send_xon) (portid)\n"
495                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
496                         "set flow_ctrl autoneg (on|off) (port_id)\n"
497                         "    Set the link flow control parameter on a port.\n\n"
498
499                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
500                         " (low_water) (pause_time) (priority) (port_id)\n"
501                         "    Set the priority flow control parameter on a"
502                         " port.\n\n"
503
504                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
505                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
506                         " queue on port.\n"
507                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
508                         " on port 0 to mapping 5.\n\n"
509
510                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
511                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
512
513                         "set port (port_id) vf (vf_id) (mac_addr)"
514                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
515                         "   Add/Remove unicast or multicast MAC addr filter"
516                         " for a VF.\n\n"
517
518                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
519                         "|MPE) (on|off)\n"
520                         "    AUPE:accepts untagged VLAN;"
521                         "ROPE:accept unicast hash\n\n"
522                         "    BAM:accepts broadcast packets;"
523                         "MPE:accepts all multicast packets\n\n"
524                         "    Enable/Disable a VF receive mode of a port\n\n"
525
526                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
527                         "    Set rate limit for a queue of a port\n\n"
528
529                         "set port (port_id) vf (vf_id) rate (rate_num) "
530                         "queue_mask (queue_mask_value)\n"
531                         "    Set rate limit for queues in VF of a port\n\n"
532
533                         "set port (port_id) mirror-rule (rule_id)"
534                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
535                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
536                         "   Set pool or vlan type mirror rule on a port.\n"
537                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
538                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
539                         " to pool 0.\n\n"
540
541                         "set port (port_id) mirror-rule (rule_id)"
542                         " (uplink-mirror|downlink-mirror) dst-pool"
543                         " (pool_id) (on|off)\n"
544                         "   Set uplink or downlink type mirror rule on a port.\n"
545                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
546                         " 0 on' enable mirror income traffic to pool 0.\n\n"
547
548                         "reset port (port_id) mirror-rule (rule_id)\n"
549                         "   Reset a mirror rule.\n\n"
550
551                         "set flush_rx (on|off)\n"
552                         "   Flush (default) or don't flush RX streams before"
553                         " forwarding. Mainly used with PCAP drivers.\n\n"
554
555                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
556                         "   Set the bypass mode for the lowest port on bypass enabled"
557                         " NIC.\n\n"
558
559                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
560                         "mode (normal|bypass|isolate) (port_id)\n"
561                         "   Set the event required to initiate specified bypass mode for"
562                         " the lowest port on a bypass enabled NIC where:\n"
563                         "       timeout   = enable bypass after watchdog timeout.\n"
564                         "       os_on     = enable bypass when OS/board is powered on.\n"
565                         "       os_off    = enable bypass when OS/board is powered off.\n"
566                         "       power_on  = enable bypass when power supply is turned on.\n"
567                         "       power_off = enable bypass when power supply is turned off."
568                         "\n\n"
569
570                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
571                         "   Set the bypass watchdog timeout to 'n' seconds"
572                         " where 0 = instant.\n\n"
573
574                         "show bypass config (port_id)\n"
575                         "   Show the bypass configuration for a bypass enabled NIC"
576                         " using the lowest port on the NIC.\n\n"
577
578 #ifdef RTE_LIBRTE_PMD_BOND
579                         "create bonded device (mode) (socket)\n"
580                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
581
582                         "add bonding slave (slave_id) (port_id)\n"
583                         "       Add a slave device to a bonded device.\n\n"
584
585                         "remove bonding slave (slave_id) (port_id)\n"
586                         "       Remove a slave device from a bonded device.\n\n"
587
588                         "set bonding mode (value) (port_id)\n"
589                         "       Set the bonding mode on a bonded device.\n\n"
590
591                         "set bonding primary (slave_id) (port_id)\n"
592                         "       Set the primary slave for a bonded device.\n\n"
593
594                         "show bonding config (port_id)\n"
595                         "       Show the bonding config for port_id.\n\n"
596
597                         "set bonding mac_addr (port_id) (address)\n"
598                         "       Set the MAC address of a bonded device.\n\n"
599
600                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
601                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
602
603                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
604                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
605
606                         "set bonding mon_period (port_id) (value)\n"
607                         "       Set the bonding link status monitoring polling period in ms.\n\n"
608
609                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
610                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
611
612 #endif
613                         "set link-up port (port_id)\n"
614                         "       Set link up for a port.\n\n"
615
616                         "set link-down port (port_id)\n"
617                         "       Set link down for a port.\n\n"
618
619                         "E-tag set insertion on port-tag-id (value)"
620                         " port (port_id) vf (vf_id)\n"
621                         "    Enable E-tag insertion for a VF on a port\n\n"
622
623                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
624                         "    Disable E-tag insertion for a VF on a port\n\n"
625
626                         "E-tag set stripping (on|off) port (port_id)\n"
627                         "    Enable/disable E-tag stripping on a port\n\n"
628
629                         "E-tag set forwarding (on|off) port (port_id)\n"
630                         "    Enable/disable E-tag based forwarding"
631                         " on a port\n\n"
632
633                         "E-tag set filter add e-tag-id (value) dst-pool"
634                         " (pool_id) port (port_id)\n"
635                         "    Add an E-tag forwarding filter on a port\n\n"
636
637                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
638                         "    Delete an E-tag forwarding filter on a port\n\n"
639
640                         "ddp add (port_id) (profile_path[,output_path])\n"
641                         "    Load a profile package on a port\n\n"
642
643                         "ddp del (port_id) (profile_path)\n"
644                         "    Delete a profile package from a port\n\n"
645
646                         "ptype mapping get (port_id) (valid_only)\n"
647                         "    Get ptype mapping on a port\n\n"
648
649                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
650                         "    Replace target with the pkt_type in ptype mapping\n\n"
651
652                         "ptype mapping reset (port_id)\n"
653                         "    Reset ptype mapping on a port\n\n"
654
655                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
656                         "    Update a ptype mapping item on a port\n\n"
657
658                         , list_pkt_forwarding_modes()
659                 );
660         }
661
662         if (show_all || !strcmp(res->section, "ports")) {
663
664                 cmdline_printf(
665                         cl,
666                         "\n"
667                         "Port Operations:\n"
668                         "----------------\n\n"
669
670                         "port start (port_id|all)\n"
671                         "    Start all ports or port_id.\n\n"
672
673                         "port stop (port_id|all)\n"
674                         "    Stop all ports or port_id.\n\n"
675
676                         "port close (port_id|all)\n"
677                         "    Close all ports or port_id.\n\n"
678
679                         "port attach (ident)\n"
680                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
681
682                         "port detach (port_id)\n"
683                         "    Detach physical or virtual dev by port_id\n\n"
684
685                         "port config (port_id|all)"
686                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
687                         " duplex (half|full|auto)\n"
688                         "    Set speed and duplex for all ports or port_id\n\n"
689
690                         "port config all (rxq|txq|rxd|txd) (value)\n"
691                         "    Set number for rxq/txq/rxd/txd.\n\n"
692
693                         "port config all max-pkt-len (value)\n"
694                         "    Set the max packet length.\n\n"
695
696                         "port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|"
697                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
698                         " (on|off)\n"
699                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
700                         " for ports.\n\n"
701
702                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
703                         "geneve|nvgre|none|<flowtype_id>)\n"
704                         "    Set the RSS mode.\n\n"
705
706                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
707                         "    Set the RSS redirection table.\n\n"
708
709                         "port config (port_id) dcb vt (on|off) (traffic_class)"
710                         " pfc (on|off)\n"
711                         "    Set the DCB mode.\n\n"
712
713                         "port config all burst (value)\n"
714                         "    Set the number of packets per burst.\n\n"
715
716                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
717                         " (value)\n"
718                         "    Set the ring prefetch/host/writeback threshold"
719                         " for tx/rx queue.\n\n"
720
721                         "port config all (txfreet|txrst|rxfreet) (value)\n"
722                         "    Set free threshold for rx/tx, or set"
723                         " tx rs bit threshold.\n\n"
724                         "port config mtu X value\n"
725                         "    Set the MTU of port X to a given value\n\n"
726
727                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
728                         "    Start/stop a rx/tx queue of port X. Only take effect"
729                         " when port X is started\n\n"
730
731                         "port config (port_id|all) l2-tunnel E-tag ether-type"
732                         " (value)\n"
733                         "    Set the value of E-tag ether-type.\n\n"
734
735                         "port config (port_id|all) l2-tunnel E-tag"
736                         " (enable|disable)\n"
737                         "    Enable/disable the E-tag support.\n\n"
738
739                         "port config (port_id) pctype mapping reset\n"
740                         "    Reset flow type to pctype mapping on a port\n\n"
741
742                         "port config (port_id) pctype mapping update"
743                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
744                         "    Update a flow type to pctype mapping item on a port\n\n"
745                 );
746         }
747
748         if (show_all || !strcmp(res->section, "registers")) {
749
750                 cmdline_printf(
751                         cl,
752                         "\n"
753                         "Registers:\n"
754                         "----------\n\n"
755
756                         "read reg (port_id) (address)\n"
757                         "    Display value of a port register.\n\n"
758
759                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
760                         "    Display a port register bit field.\n\n"
761
762                         "read regbit (port_id) (address) (bit_x)\n"
763                         "    Display a single port register bit.\n\n"
764
765                         "write reg (port_id) (address) (value)\n"
766                         "    Set value of a port register.\n\n"
767
768                         "write regfield (port_id) (address) (bit_x) (bit_y)"
769                         " (value)\n"
770                         "    Set bit field of a port register.\n\n"
771
772                         "write regbit (port_id) (address) (bit_x) (value)\n"
773                         "    Set single bit value of a port register.\n\n"
774                 );
775         }
776         if (show_all || !strcmp(res->section, "filters")) {
777
778                 cmdline_printf(
779                         cl,
780                         "\n"
781                         "filters:\n"
782                         "--------\n\n"
783
784                         "ethertype_filter (port_id) (add|del)"
785                         " (mac_addr|mac_ignr) (mac_address) ethertype"
786                         " (ether_type) (drop|fwd) queue (queue_id)\n"
787                         "    Add/Del an ethertype filter.\n\n"
788
789                         "2tuple_filter (port_id) (add|del)"
790                         " dst_port (dst_port_value) protocol (protocol_value)"
791                         " mask (mask_value) tcp_flags (tcp_flags_value)"
792                         " priority (prio_value) queue (queue_id)\n"
793                         "    Add/Del a 2tuple filter.\n\n"
794
795                         "5tuple_filter (port_id) (add|del)"
796                         " dst_ip (dst_address) src_ip (src_address)"
797                         " dst_port (dst_port_value) src_port (src_port_value)"
798                         " protocol (protocol_value)"
799                         " mask (mask_value) tcp_flags (tcp_flags_value)"
800                         " priority (prio_value) queue (queue_id)\n"
801                         "    Add/Del a 5tuple filter.\n\n"
802
803                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
804                         "    Add/Del syn filter.\n\n"
805
806                         "flex_filter (port_id) (add|del) len (len_value)"
807                         " bytes (bytes_value) mask (mask_value)"
808                         " priority (prio_value) queue (queue_id)\n"
809                         "    Add/Del a flex filter.\n\n"
810
811                         "flow_director_filter (port_id) mode IP (add|del|update)"
812                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
813                         " src (src_ip_address) dst (dst_ip_address)"
814                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
815                         " vlan (vlan_value) flexbytes (flexbytes_value)"
816                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
817                         " fd_id (fd_id_value)\n"
818                         "    Add/Del an IP type flow director filter.\n\n"
819
820                         "flow_director_filter (port_id) mode IP (add|del|update)"
821                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
822                         " src (src_ip_address) (src_port)"
823                         " dst (dst_ip_address) (dst_port)"
824                         " tos (tos_value) ttl (ttl_value)"
825                         " vlan (vlan_value) flexbytes (flexbytes_value)"
826                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
827                         " fd_id (fd_id_value)\n"
828                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
829
830                         "flow_director_filter (port_id) mode IP (add|del|update)"
831                         " flow (ipv4-sctp|ipv6-sctp)"
832                         " src (src_ip_address) (src_port)"
833                         " dst (dst_ip_address) (dst_port)"
834                         " tag (verification_tag) "
835                         " tos (tos_value) ttl (ttl_value)"
836                         " vlan (vlan_value)"
837                         " flexbytes (flexbytes_value) (drop|fwd)"
838                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
839                         "    Add/Del a SCTP type flow director filter.\n\n"
840
841                         "flow_director_filter (port_id) mode IP (add|del|update)"
842                         " flow l2_payload ether (ethertype)"
843                         " flexbytes (flexbytes_value) (drop|fwd)"
844                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
845                         "    Add/Del a l2 payload type flow director filter.\n\n"
846
847                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
848                         " mac (mac_address) vlan (vlan_value)"
849                         " flexbytes (flexbytes_value) (drop|fwd)"
850                         " queue (queue_id) fd_id (fd_id_value)\n"
851                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
852
853                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
854                         " mac (mac_address) vlan (vlan_value)"
855                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
856                         " flexbytes (flexbytes_value) (drop|fwd)"
857                         " queue (queue_id) fd_id (fd_id_value)\n"
858                         "    Add/Del a Tunnel flow director filter.\n\n"
859
860                         "flush_flow_director (port_id)\n"
861                         "    Flush all flow director entries of a device.\n\n"
862
863                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
864                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
865                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
866                         "    Set flow director IP mask.\n\n"
867
868                         "flow_director_mask (port_id) mode MAC-VLAN"
869                         " vlan (vlan_value)\n"
870                         "    Set flow director MAC-VLAN mask.\n\n"
871
872                         "flow_director_mask (port_id) mode Tunnel"
873                         " vlan (vlan_value) mac (mac_value)"
874                         " tunnel-type (tunnel_type_value)"
875                         " tunnel-id (tunnel_id_value)\n"
876                         "    Set flow director Tunnel mask.\n\n"
877
878                         "flow_director_flex_mask (port_id)"
879                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
880                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
881                         " (mask)\n"
882                         "    Configure mask of flex payload.\n\n"
883
884                         "flow_director_flex_payload (port_id)"
885                         " (raw|l2|l3|l4) (config)\n"
886                         "    Configure flex payload selection.\n\n"
887
888                         "get_sym_hash_ena_per_port (port_id)\n"
889                         "    get symmetric hash enable configuration per port.\n\n"
890
891                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
892                         "    set symmetric hash enable configuration per port"
893                         " to enable or disable.\n\n"
894
895                         "get_hash_global_config (port_id)\n"
896                         "    Get the global configurations of hash filters.\n\n"
897
898                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
899                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
900                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
901                         " (enable|disable)\n"
902                         "    Set the global configurations of hash filters.\n\n"
903
904                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
905                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
906                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
907                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
908                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
909                         "ipv6-next-header|udp-src-port|udp-dst-port|"
910                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
911                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
912                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
913                         "fld-8th|none) (select|add)\n"
914                         "    Set the input set for hash.\n\n"
915
916                         "set_fdir_input_set (port_id) "
917                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
918                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
919                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
920                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
921                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
922                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
923                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
924                         " (select|add)\n"
925                         "    Set the input set for FDir.\n\n"
926
927                         "flow validate {port_id}"
928                         " [group {group_id}] [priority {level}]"
929                         " [ingress] [egress]"
930                         " pattern {item} [/ {item} [...]] / end"
931                         " actions {action} [/ {action} [...]] / end\n"
932                         "    Check whether a flow rule can be created.\n\n"
933
934                         "flow create {port_id}"
935                         " [group {group_id}] [priority {level}]"
936                         " [ingress] [egress]"
937                         " pattern {item} [/ {item} [...]] / end"
938                         " actions {action} [/ {action} [...]] / end\n"
939                         "    Create a flow rule.\n\n"
940
941                         "flow destroy {port_id} rule {rule_id} [...]\n"
942                         "    Destroy specific flow rules.\n\n"
943
944                         "flow flush {port_id}\n"
945                         "    Destroy all flow rules.\n\n"
946
947                         "flow query {port_id} {rule_id} {action}\n"
948                         "    Query an existing flow rule.\n\n"
949
950                         "flow list {port_id} [group {group_id}] [...]\n"
951                         "    List existing flow rules sorted by priority,"
952                         " filtered by group identifiers.\n\n"
953
954                         "flow isolate {port_id} {boolean}\n"
955                         "    Restrict ingress traffic to the defined"
956                         " flow rules\n\n"
957                 );
958         }
959 }
960
961 cmdline_parse_token_string_t cmd_help_long_help =
962         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
963
964 cmdline_parse_token_string_t cmd_help_long_section =
965         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
966                         "all#control#display#config#"
967                         "ports#registers#filters");
968
969 cmdline_parse_inst_t cmd_help_long = {
970         .f = cmd_help_long_parsed,
971         .data = NULL,
972         .help_str = "help all|control|display|config|ports|register|filters: "
973                 "Show help",
974         .tokens = {
975                 (void *)&cmd_help_long_help,
976                 (void *)&cmd_help_long_section,
977                 NULL,
978         },
979 };
980
981
982 /* *** start/stop/close all ports *** */
983 struct cmd_operate_port_result {
984         cmdline_fixed_string_t keyword;
985         cmdline_fixed_string_t name;
986         cmdline_fixed_string_t value;
987 };
988
989 static void cmd_operate_port_parsed(void *parsed_result,
990                                 __attribute__((unused)) struct cmdline *cl,
991                                 __attribute__((unused)) void *data)
992 {
993         struct cmd_operate_port_result *res = parsed_result;
994
995         if (!strcmp(res->name, "start"))
996                 start_port(RTE_PORT_ALL);
997         else if (!strcmp(res->name, "stop"))
998                 stop_port(RTE_PORT_ALL);
999         else if (!strcmp(res->name, "close"))
1000                 close_port(RTE_PORT_ALL);
1001         else if (!strcmp(res->name, "reset"))
1002                 reset_port(RTE_PORT_ALL);
1003         else
1004                 printf("Unknown parameter\n");
1005 }
1006
1007 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1008         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1009                                                                 "port");
1010 cmdline_parse_token_string_t cmd_operate_port_all_port =
1011         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1012                                                 "start#stop#close#reset");
1013 cmdline_parse_token_string_t cmd_operate_port_all_all =
1014         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1015
1016 cmdline_parse_inst_t cmd_operate_port = {
1017         .f = cmd_operate_port_parsed,
1018         .data = NULL,
1019         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1020         .tokens = {
1021                 (void *)&cmd_operate_port_all_cmd,
1022                 (void *)&cmd_operate_port_all_port,
1023                 (void *)&cmd_operate_port_all_all,
1024                 NULL,
1025         },
1026 };
1027
1028 /* *** start/stop/close specific port *** */
1029 struct cmd_operate_specific_port_result {
1030         cmdline_fixed_string_t keyword;
1031         cmdline_fixed_string_t name;
1032         uint8_t value;
1033 };
1034
1035 static void cmd_operate_specific_port_parsed(void *parsed_result,
1036                         __attribute__((unused)) struct cmdline *cl,
1037                                 __attribute__((unused)) void *data)
1038 {
1039         struct cmd_operate_specific_port_result *res = parsed_result;
1040
1041         if (!strcmp(res->name, "start"))
1042                 start_port(res->value);
1043         else if (!strcmp(res->name, "stop"))
1044                 stop_port(res->value);
1045         else if (!strcmp(res->name, "close"))
1046                 close_port(res->value);
1047         else if (!strcmp(res->name, "reset"))
1048                 reset_port(res->value);
1049         else
1050                 printf("Unknown parameter\n");
1051 }
1052
1053 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1054         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1055                                                         keyword, "port");
1056 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1057         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1058                                                 name, "start#stop#close#reset");
1059 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1060         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1061                                                         value, UINT8);
1062
1063 cmdline_parse_inst_t cmd_operate_specific_port = {
1064         .f = cmd_operate_specific_port_parsed,
1065         .data = NULL,
1066         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1067         .tokens = {
1068                 (void *)&cmd_operate_specific_port_cmd,
1069                 (void *)&cmd_operate_specific_port_port,
1070                 (void *)&cmd_operate_specific_port_id,
1071                 NULL,
1072         },
1073 };
1074
1075 /* *** attach a specified port *** */
1076 struct cmd_operate_attach_port_result {
1077         cmdline_fixed_string_t port;
1078         cmdline_fixed_string_t keyword;
1079         cmdline_fixed_string_t identifier;
1080 };
1081
1082 static void cmd_operate_attach_port_parsed(void *parsed_result,
1083                                 __attribute__((unused)) struct cmdline *cl,
1084                                 __attribute__((unused)) void *data)
1085 {
1086         struct cmd_operate_attach_port_result *res = parsed_result;
1087
1088         if (!strcmp(res->keyword, "attach"))
1089                 attach_port(res->identifier);
1090         else
1091                 printf("Unknown parameter\n");
1092 }
1093
1094 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1095         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1096                         port, "port");
1097 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1098         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1099                         keyword, "attach");
1100 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1101         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1102                         identifier, NULL);
1103
1104 cmdline_parse_inst_t cmd_operate_attach_port = {
1105         .f = cmd_operate_attach_port_parsed,
1106         .data = NULL,
1107         .help_str = "port attach <identifier>: "
1108                 "(identifier: pci address or virtual dev name)",
1109         .tokens = {
1110                 (void *)&cmd_operate_attach_port_port,
1111                 (void *)&cmd_operate_attach_port_keyword,
1112                 (void *)&cmd_operate_attach_port_identifier,
1113                 NULL,
1114         },
1115 };
1116
1117 /* *** detach a specified port *** */
1118 struct cmd_operate_detach_port_result {
1119         cmdline_fixed_string_t port;
1120         cmdline_fixed_string_t keyword;
1121         uint8_t port_id;
1122 };
1123
1124 static void cmd_operate_detach_port_parsed(void *parsed_result,
1125                                 __attribute__((unused)) struct cmdline *cl,
1126                                 __attribute__((unused)) void *data)
1127 {
1128         struct cmd_operate_detach_port_result *res = parsed_result;
1129
1130         if (!strcmp(res->keyword, "detach"))
1131                 detach_port(res->port_id);
1132         else
1133                 printf("Unknown parameter\n");
1134 }
1135
1136 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1137         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1138                         port, "port");
1139 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1140         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1141                         keyword, "detach");
1142 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1143         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1144                         port_id, UINT8);
1145
1146 cmdline_parse_inst_t cmd_operate_detach_port = {
1147         .f = cmd_operate_detach_port_parsed,
1148         .data = NULL,
1149         .help_str = "port detach <port_id>",
1150         .tokens = {
1151                 (void *)&cmd_operate_detach_port_port,
1152                 (void *)&cmd_operate_detach_port_keyword,
1153                 (void *)&cmd_operate_detach_port_port_id,
1154                 NULL,
1155         },
1156 };
1157
1158 /* *** configure speed for all ports *** */
1159 struct cmd_config_speed_all {
1160         cmdline_fixed_string_t port;
1161         cmdline_fixed_string_t keyword;
1162         cmdline_fixed_string_t all;
1163         cmdline_fixed_string_t item1;
1164         cmdline_fixed_string_t item2;
1165         cmdline_fixed_string_t value1;
1166         cmdline_fixed_string_t value2;
1167 };
1168
1169 static int
1170 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1171 {
1172
1173         int duplex;
1174
1175         if (!strcmp(duplexstr, "half")) {
1176                 duplex = ETH_LINK_HALF_DUPLEX;
1177         } else if (!strcmp(duplexstr, "full")) {
1178                 duplex = ETH_LINK_FULL_DUPLEX;
1179         } else if (!strcmp(duplexstr, "auto")) {
1180                 duplex = ETH_LINK_FULL_DUPLEX;
1181         } else {
1182                 printf("Unknown duplex parameter\n");
1183                 return -1;
1184         }
1185
1186         if (!strcmp(speedstr, "10")) {
1187                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1188                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1189         } else if (!strcmp(speedstr, "100")) {
1190                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1191                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1192         } else {
1193                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1194                         printf("Invalid speed/duplex parameters\n");
1195                         return -1;
1196                 }
1197                 if (!strcmp(speedstr, "1000")) {
1198                         *speed = ETH_LINK_SPEED_1G;
1199                 } else if (!strcmp(speedstr, "10000")) {
1200                         *speed = ETH_LINK_SPEED_10G;
1201                 } else if (!strcmp(speedstr, "25000")) {
1202                         *speed = ETH_LINK_SPEED_25G;
1203                 } else if (!strcmp(speedstr, "40000")) {
1204                         *speed = ETH_LINK_SPEED_40G;
1205                 } else if (!strcmp(speedstr, "50000")) {
1206                         *speed = ETH_LINK_SPEED_50G;
1207                 } else if (!strcmp(speedstr, "100000")) {
1208                         *speed = ETH_LINK_SPEED_100G;
1209                 } else if (!strcmp(speedstr, "auto")) {
1210                         *speed = ETH_LINK_SPEED_AUTONEG;
1211                 } else {
1212                         printf("Unknown speed parameter\n");
1213                         return -1;
1214                 }
1215         }
1216
1217         return 0;
1218 }
1219
1220 static void
1221 cmd_config_speed_all_parsed(void *parsed_result,
1222                         __attribute__((unused)) struct cmdline *cl,
1223                         __attribute__((unused)) void *data)
1224 {
1225         struct cmd_config_speed_all *res = parsed_result;
1226         uint32_t link_speed;
1227         portid_t pid;
1228
1229         if (!all_ports_stopped()) {
1230                 printf("Please stop all ports first\n");
1231                 return;
1232         }
1233
1234         if (parse_and_check_speed_duplex(res->value1, res->value2,
1235                         &link_speed) < 0)
1236                 return;
1237
1238         RTE_ETH_FOREACH_DEV(pid) {
1239                 ports[pid].dev_conf.link_speeds = link_speed;
1240         }
1241
1242         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1243 }
1244
1245 cmdline_parse_token_string_t cmd_config_speed_all_port =
1246         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1247 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1248         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1249                                                         "config");
1250 cmdline_parse_token_string_t cmd_config_speed_all_all =
1251         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1252 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1253         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1254 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1255         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1256                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1257 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1258         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1259 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1260         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1261                                                 "half#full#auto");
1262
1263 cmdline_parse_inst_t cmd_config_speed_all = {
1264         .f = cmd_config_speed_all_parsed,
1265         .data = NULL,
1266         .help_str = "port config all speed "
1267                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1268                                                         "half|full|auto",
1269         .tokens = {
1270                 (void *)&cmd_config_speed_all_port,
1271                 (void *)&cmd_config_speed_all_keyword,
1272                 (void *)&cmd_config_speed_all_all,
1273                 (void *)&cmd_config_speed_all_item1,
1274                 (void *)&cmd_config_speed_all_value1,
1275                 (void *)&cmd_config_speed_all_item2,
1276                 (void *)&cmd_config_speed_all_value2,
1277                 NULL,
1278         },
1279 };
1280
1281 /* *** configure speed for specific port *** */
1282 struct cmd_config_speed_specific {
1283         cmdline_fixed_string_t port;
1284         cmdline_fixed_string_t keyword;
1285         uint8_t id;
1286         cmdline_fixed_string_t item1;
1287         cmdline_fixed_string_t item2;
1288         cmdline_fixed_string_t value1;
1289         cmdline_fixed_string_t value2;
1290 };
1291
1292 static void
1293 cmd_config_speed_specific_parsed(void *parsed_result,
1294                                 __attribute__((unused)) struct cmdline *cl,
1295                                 __attribute__((unused)) void *data)
1296 {
1297         struct cmd_config_speed_specific *res = parsed_result;
1298         uint32_t link_speed;
1299
1300         if (!all_ports_stopped()) {
1301                 printf("Please stop all ports first\n");
1302                 return;
1303         }
1304
1305         if (port_id_is_invalid(res->id, ENABLED_WARN))
1306                 return;
1307
1308         if (parse_and_check_speed_duplex(res->value1, res->value2,
1309                         &link_speed) < 0)
1310                 return;
1311
1312         ports[res->id].dev_conf.link_speeds = link_speed;
1313
1314         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1315 }
1316
1317
1318 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1319         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1320                                                                 "port");
1321 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1322         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1323                                                                 "config");
1324 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1325         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1326 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1327         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1328                                                                 "speed");
1329 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1330         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1331                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1332 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1333         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1334                                                                 "duplex");
1335 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1336         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1337                                                         "half#full#auto");
1338
1339 cmdline_parse_inst_t cmd_config_speed_specific = {
1340         .f = cmd_config_speed_specific_parsed,
1341         .data = NULL,
1342         .help_str = "port config <port_id> speed "
1343                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1344                                                         "half|full|auto",
1345         .tokens = {
1346                 (void *)&cmd_config_speed_specific_port,
1347                 (void *)&cmd_config_speed_specific_keyword,
1348                 (void *)&cmd_config_speed_specific_id,
1349                 (void *)&cmd_config_speed_specific_item1,
1350                 (void *)&cmd_config_speed_specific_value1,
1351                 (void *)&cmd_config_speed_specific_item2,
1352                 (void *)&cmd_config_speed_specific_value2,
1353                 NULL,
1354         },
1355 };
1356
1357 /* *** configure txq/rxq, txd/rxd *** */
1358 struct cmd_config_rx_tx {
1359         cmdline_fixed_string_t port;
1360         cmdline_fixed_string_t keyword;
1361         cmdline_fixed_string_t all;
1362         cmdline_fixed_string_t name;
1363         uint16_t value;
1364 };
1365
1366 static void
1367 cmd_config_rx_tx_parsed(void *parsed_result,
1368                         __attribute__((unused)) struct cmdline *cl,
1369                         __attribute__((unused)) void *data)
1370 {
1371         struct cmd_config_rx_tx *res = parsed_result;
1372
1373         if (!all_ports_stopped()) {
1374                 printf("Please stop all ports first\n");
1375                 return;
1376         }
1377         if (!strcmp(res->name, "rxq")) {
1378                 if (!res->value && !nb_txq) {
1379                         printf("Warning: Either rx or tx queues should be non zero\n");
1380                         return;
1381                 }
1382                 nb_rxq = res->value;
1383         }
1384         else if (!strcmp(res->name, "txq")) {
1385                 if (!res->value && !nb_rxq) {
1386                         printf("Warning: Either rx or tx queues should be non zero\n");
1387                         return;
1388                 }
1389                 nb_txq = res->value;
1390         }
1391         else if (!strcmp(res->name, "rxd")) {
1392                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1393                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1394                                         res->value, RTE_TEST_RX_DESC_MAX);
1395                         return;
1396                 }
1397                 nb_rxd = res->value;
1398         } else if (!strcmp(res->name, "txd")) {
1399                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1400                         printf("txd %d invalid - must be > 0 && <= %d\n",
1401                                         res->value, RTE_TEST_TX_DESC_MAX);
1402                         return;
1403                 }
1404                 nb_txd = res->value;
1405         } else {
1406                 printf("Unknown parameter\n");
1407                 return;
1408         }
1409
1410         fwd_config_setup();
1411
1412         init_port_config();
1413
1414         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1415 }
1416
1417 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1418         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1419 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1420         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1421 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1422         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1423 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1424         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1425                                                 "rxq#txq#rxd#txd");
1426 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1427         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1428
1429 cmdline_parse_inst_t cmd_config_rx_tx = {
1430         .f = cmd_config_rx_tx_parsed,
1431         .data = NULL,
1432         .help_str = "port config all rxq|txq|rxd|txd <value>",
1433         .tokens = {
1434                 (void *)&cmd_config_rx_tx_port,
1435                 (void *)&cmd_config_rx_tx_keyword,
1436                 (void *)&cmd_config_rx_tx_all,
1437                 (void *)&cmd_config_rx_tx_name,
1438                 (void *)&cmd_config_rx_tx_value,
1439                 NULL,
1440         },
1441 };
1442
1443 /* *** config max packet length *** */
1444 struct cmd_config_max_pkt_len_result {
1445         cmdline_fixed_string_t port;
1446         cmdline_fixed_string_t keyword;
1447         cmdline_fixed_string_t all;
1448         cmdline_fixed_string_t name;
1449         uint32_t value;
1450 };
1451
1452 static void
1453 cmd_config_max_pkt_len_parsed(void *parsed_result,
1454                                 __attribute__((unused)) struct cmdline *cl,
1455                                 __attribute__((unused)) void *data)
1456 {
1457         struct cmd_config_max_pkt_len_result *res = parsed_result;
1458
1459         if (!all_ports_stopped()) {
1460                 printf("Please stop all ports first\n");
1461                 return;
1462         }
1463
1464         if (!strcmp(res->name, "max-pkt-len")) {
1465                 if (res->value < ETHER_MIN_LEN) {
1466                         printf("max-pkt-len can not be less than %d\n",
1467                                                         ETHER_MIN_LEN);
1468                         return;
1469                 }
1470                 if (res->value == rx_mode.max_rx_pkt_len)
1471                         return;
1472
1473                 rx_mode.max_rx_pkt_len = res->value;
1474                 if (res->value > ETHER_MAX_LEN)
1475                         rx_mode.jumbo_frame = 1;
1476                 else
1477                         rx_mode.jumbo_frame = 0;
1478         } else {
1479                 printf("Unknown parameter\n");
1480                 return;
1481         }
1482
1483         init_port_config();
1484
1485         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1486 }
1487
1488 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1489         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1490                                                                 "port");
1491 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1492         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1493                                                                 "config");
1494 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1495         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1496                                                                 "all");
1497 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1498         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1499                                                                 "max-pkt-len");
1500 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1501         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1502                                                                 UINT32);
1503
1504 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1505         .f = cmd_config_max_pkt_len_parsed,
1506         .data = NULL,
1507         .help_str = "port config all max-pkt-len <value>",
1508         .tokens = {
1509                 (void *)&cmd_config_max_pkt_len_port,
1510                 (void *)&cmd_config_max_pkt_len_keyword,
1511                 (void *)&cmd_config_max_pkt_len_all,
1512                 (void *)&cmd_config_max_pkt_len_name,
1513                 (void *)&cmd_config_max_pkt_len_value,
1514                 NULL,
1515         },
1516 };
1517
1518 /* *** configure port MTU *** */
1519 struct cmd_config_mtu_result {
1520         cmdline_fixed_string_t port;
1521         cmdline_fixed_string_t keyword;
1522         cmdline_fixed_string_t mtu;
1523         uint8_t port_id;
1524         uint16_t value;
1525 };
1526
1527 static void
1528 cmd_config_mtu_parsed(void *parsed_result,
1529                       __attribute__((unused)) struct cmdline *cl,
1530                       __attribute__((unused)) void *data)
1531 {
1532         struct cmd_config_mtu_result *res = parsed_result;
1533
1534         if (res->value < ETHER_MIN_LEN) {
1535                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1536                 return;
1537         }
1538         port_mtu_set(res->port_id, res->value);
1539 }
1540
1541 cmdline_parse_token_string_t cmd_config_mtu_port =
1542         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1543                                  "port");
1544 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1545         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1546                                  "config");
1547 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1548         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1549                                  "mtu");
1550 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1551         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1552 cmdline_parse_token_num_t cmd_config_mtu_value =
1553         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1554
1555 cmdline_parse_inst_t cmd_config_mtu = {
1556         .f = cmd_config_mtu_parsed,
1557         .data = NULL,
1558         .help_str = "port config mtu <port_id> <value>",
1559         .tokens = {
1560                 (void *)&cmd_config_mtu_port,
1561                 (void *)&cmd_config_mtu_keyword,
1562                 (void *)&cmd_config_mtu_mtu,
1563                 (void *)&cmd_config_mtu_port_id,
1564                 (void *)&cmd_config_mtu_value,
1565                 NULL,
1566         },
1567 };
1568
1569 /* *** configure rx mode *** */
1570 struct cmd_config_rx_mode_flag {
1571         cmdline_fixed_string_t port;
1572         cmdline_fixed_string_t keyword;
1573         cmdline_fixed_string_t all;
1574         cmdline_fixed_string_t name;
1575         cmdline_fixed_string_t value;
1576 };
1577
1578 static void
1579 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1580                                 __attribute__((unused)) struct cmdline *cl,
1581                                 __attribute__((unused)) void *data)
1582 {
1583         struct cmd_config_rx_mode_flag *res = parsed_result;
1584
1585         if (!all_ports_stopped()) {
1586                 printf("Please stop all ports first\n");
1587                 return;
1588         }
1589
1590         if (!strcmp(res->name, "crc-strip")) {
1591                 if (!strcmp(res->value, "on"))
1592                         rx_mode.hw_strip_crc = 1;
1593                 else if (!strcmp(res->value, "off"))
1594                         rx_mode.hw_strip_crc = 0;
1595                 else {
1596                         printf("Unknown parameter\n");
1597                         return;
1598                 }
1599         } else if (!strcmp(res->name, "scatter")) {
1600                 if (!strcmp(res->value, "on"))
1601                         rx_mode.enable_scatter = 1;
1602                 else if (!strcmp(res->value, "off"))
1603                         rx_mode.enable_scatter = 0;
1604                 else {
1605                         printf("Unknown parameter\n");
1606                         return;
1607                 }
1608         } else if (!strcmp(res->name, "rx-cksum")) {
1609                 if (!strcmp(res->value, "on"))
1610                         rx_mode.hw_ip_checksum = 1;
1611                 else if (!strcmp(res->value, "off"))
1612                         rx_mode.hw_ip_checksum = 0;
1613                 else {
1614                         printf("Unknown parameter\n");
1615                         return;
1616                 }
1617         } else if (!strcmp(res->name, "hw-vlan")) {
1618                 if (!strcmp(res->value, "on")) {
1619                         rx_mode.hw_vlan_filter = 1;
1620                         rx_mode.hw_vlan_strip  = 1;
1621                 }
1622                 else if (!strcmp(res->value, "off")) {
1623                         rx_mode.hw_vlan_filter = 0;
1624                         rx_mode.hw_vlan_strip  = 0;
1625                 }
1626                 else {
1627                         printf("Unknown parameter\n");
1628                         return;
1629                 }
1630         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1631                 if (!strcmp(res->value, "on"))
1632                         rx_mode.hw_vlan_filter = 1;
1633                 else if (!strcmp(res->value, "off"))
1634                         rx_mode.hw_vlan_filter = 0;
1635                 else {
1636                         printf("Unknown parameter\n");
1637                         return;
1638                 }
1639         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1640                 if (!strcmp(res->value, "on"))
1641                         rx_mode.hw_vlan_strip  = 1;
1642                 else if (!strcmp(res->value, "off"))
1643                         rx_mode.hw_vlan_strip  = 0;
1644                 else {
1645                         printf("Unknown parameter\n");
1646                         return;
1647                 }
1648         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1649                 if (!strcmp(res->value, "on"))
1650                         rx_mode.hw_vlan_extend = 1;
1651                 else if (!strcmp(res->value, "off"))
1652                         rx_mode.hw_vlan_extend = 0;
1653                 else {
1654                         printf("Unknown parameter\n");
1655                         return;
1656                 }
1657         } else if (!strcmp(res->name, "drop-en")) {
1658                 if (!strcmp(res->value, "on"))
1659                         rx_drop_en = 1;
1660                 else if (!strcmp(res->value, "off"))
1661                         rx_drop_en = 0;
1662                 else {
1663                         printf("Unknown parameter\n");
1664                         return;
1665                 }
1666         } else {
1667                 printf("Unknown parameter\n");
1668                 return;
1669         }
1670
1671         init_port_config();
1672
1673         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1674 }
1675
1676 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1677         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1678 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1679         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1680                                                                 "config");
1681 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1682         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1683 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1684         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1685                                         "crc-strip#scatter#rx-cksum#hw-vlan#"
1686                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1687 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1688         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1689                                                         "on#off");
1690
1691 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1692         .f = cmd_config_rx_mode_flag_parsed,
1693         .data = NULL,
1694         .help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|"
1695                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1696         .tokens = {
1697                 (void *)&cmd_config_rx_mode_flag_port,
1698                 (void *)&cmd_config_rx_mode_flag_keyword,
1699                 (void *)&cmd_config_rx_mode_flag_all,
1700                 (void *)&cmd_config_rx_mode_flag_name,
1701                 (void *)&cmd_config_rx_mode_flag_value,
1702                 NULL,
1703         },
1704 };
1705
1706 /* *** configure rss *** */
1707 struct cmd_config_rss {
1708         cmdline_fixed_string_t port;
1709         cmdline_fixed_string_t keyword;
1710         cmdline_fixed_string_t all;
1711         cmdline_fixed_string_t name;
1712         cmdline_fixed_string_t value;
1713 };
1714
1715 static void
1716 cmd_config_rss_parsed(void *parsed_result,
1717                         __attribute__((unused)) struct cmdline *cl,
1718                         __attribute__((unused)) void *data)
1719 {
1720         struct cmd_config_rss *res = parsed_result;
1721         struct rte_eth_rss_conf rss_conf;
1722         int diag;
1723         uint8_t i;
1724
1725         if (!strcmp(res->value, "all"))
1726                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1727                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1728                                         ETH_RSS_L2_PAYLOAD;
1729         else if (!strcmp(res->value, "ip"))
1730                 rss_conf.rss_hf = ETH_RSS_IP;
1731         else if (!strcmp(res->value, "udp"))
1732                 rss_conf.rss_hf = ETH_RSS_UDP;
1733         else if (!strcmp(res->value, "tcp"))
1734                 rss_conf.rss_hf = ETH_RSS_TCP;
1735         else if (!strcmp(res->value, "sctp"))
1736                 rss_conf.rss_hf = ETH_RSS_SCTP;
1737         else if (!strcmp(res->value, "ether"))
1738                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1739         else if (!strcmp(res->value, "port"))
1740                 rss_conf.rss_hf = ETH_RSS_PORT;
1741         else if (!strcmp(res->value, "vxlan"))
1742                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1743         else if (!strcmp(res->value, "geneve"))
1744                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1745         else if (!strcmp(res->value, "nvgre"))
1746                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1747         else if (!strcmp(res->value, "none"))
1748                 rss_conf.rss_hf = 0;
1749         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1750                                                 atoi(res->value) < 64)
1751                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1752         else {
1753                 printf("Unknown parameter\n");
1754                 return;
1755         }
1756         rss_conf.rss_key = NULL;
1757         for (i = 0; i < rte_eth_dev_count(); i++) {
1758                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1759                 if (diag < 0)
1760                         printf("Configuration of RSS hash at ethernet port %d "
1761                                 "failed with error (%d): %s.\n",
1762                                 i, -diag, strerror(-diag));
1763         }
1764 }
1765
1766 cmdline_parse_token_string_t cmd_config_rss_port =
1767         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1768 cmdline_parse_token_string_t cmd_config_rss_keyword =
1769         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1770 cmdline_parse_token_string_t cmd_config_rss_all =
1771         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1772 cmdline_parse_token_string_t cmd_config_rss_name =
1773         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1774 cmdline_parse_token_string_t cmd_config_rss_value =
1775         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1776
1777 cmdline_parse_inst_t cmd_config_rss = {
1778         .f = cmd_config_rss_parsed,
1779         .data = NULL,
1780         .help_str = "port config all rss "
1781                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1782         .tokens = {
1783                 (void *)&cmd_config_rss_port,
1784                 (void *)&cmd_config_rss_keyword,
1785                 (void *)&cmd_config_rss_all,
1786                 (void *)&cmd_config_rss_name,
1787                 (void *)&cmd_config_rss_value,
1788                 NULL,
1789         },
1790 };
1791
1792 /* *** configure rss hash key *** */
1793 struct cmd_config_rss_hash_key {
1794         cmdline_fixed_string_t port;
1795         cmdline_fixed_string_t config;
1796         uint8_t port_id;
1797         cmdline_fixed_string_t rss_hash_key;
1798         cmdline_fixed_string_t rss_type;
1799         cmdline_fixed_string_t key;
1800 };
1801
1802 static uint8_t
1803 hexa_digit_to_value(char hexa_digit)
1804 {
1805         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1806                 return (uint8_t) (hexa_digit - '0');
1807         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1808                 return (uint8_t) ((hexa_digit - 'a') + 10);
1809         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1810                 return (uint8_t) ((hexa_digit - 'A') + 10);
1811         /* Invalid hexa digit */
1812         return 0xFF;
1813 }
1814
1815 static uint8_t
1816 parse_and_check_key_hexa_digit(char *key, int idx)
1817 {
1818         uint8_t hexa_v;
1819
1820         hexa_v = hexa_digit_to_value(key[idx]);
1821         if (hexa_v == 0xFF)
1822                 printf("invalid key: character %c at position %d is not a "
1823                        "valid hexa digit\n", key[idx], idx);
1824         return hexa_v;
1825 }
1826
1827 static void
1828 cmd_config_rss_hash_key_parsed(void *parsed_result,
1829                                __attribute__((unused)) struct cmdline *cl,
1830                                __attribute__((unused)) void *data)
1831 {
1832         struct cmd_config_rss_hash_key *res = parsed_result;
1833         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1834         uint8_t xdgt0;
1835         uint8_t xdgt1;
1836         int i;
1837         struct rte_eth_dev_info dev_info;
1838         uint8_t hash_key_size;
1839         uint32_t key_len;
1840
1841         memset(&dev_info, 0, sizeof(dev_info));
1842         rte_eth_dev_info_get(res->port_id, &dev_info);
1843         if (dev_info.hash_key_size > 0 &&
1844                         dev_info.hash_key_size <= sizeof(hash_key))
1845                 hash_key_size = dev_info.hash_key_size;
1846         else {
1847                 printf("dev_info did not provide a valid hash key size\n");
1848                 return;
1849         }
1850         /* Check the length of the RSS hash key */
1851         key_len = strlen(res->key);
1852         if (key_len != (hash_key_size * 2)) {
1853                 printf("key length: %d invalid - key must be a string of %d"
1854                            " hexa-decimal numbers\n",
1855                            (int) key_len, hash_key_size * 2);
1856                 return;
1857         }
1858         /* Translate RSS hash key into binary representation */
1859         for (i = 0; i < hash_key_size; i++) {
1860                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1861                 if (xdgt0 == 0xFF)
1862                         return;
1863                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1864                 if (xdgt1 == 0xFF)
1865                         return;
1866                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1867         }
1868         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1869                         hash_key_size);
1870 }
1871
1872 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1873         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1874 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1875         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1876                                  "config");
1877 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1878         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1879 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1880         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1881                                  rss_hash_key, "rss-hash-key");
1882 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1883         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1884                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1885                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1886                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1887                                  "ipv6-tcp-ex#ipv6-udp-ex");
1888 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1889         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1890
1891 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1892         .f = cmd_config_rss_hash_key_parsed,
1893         .data = NULL,
1894         .help_str = "port config <port_id> rss-hash-key "
1895                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1896                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1897                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
1898                 "<string of hex digits (variable length, NIC dependent)>",
1899         .tokens = {
1900                 (void *)&cmd_config_rss_hash_key_port,
1901                 (void *)&cmd_config_rss_hash_key_config,
1902                 (void *)&cmd_config_rss_hash_key_port_id,
1903                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1904                 (void *)&cmd_config_rss_hash_key_rss_type,
1905                 (void *)&cmd_config_rss_hash_key_value,
1906                 NULL,
1907         },
1908 };
1909
1910 /* *** configure port rxq/txq start/stop *** */
1911 struct cmd_config_rxtx_queue {
1912         cmdline_fixed_string_t port;
1913         uint8_t portid;
1914         cmdline_fixed_string_t rxtxq;
1915         uint16_t qid;
1916         cmdline_fixed_string_t opname;
1917 };
1918
1919 static void
1920 cmd_config_rxtx_queue_parsed(void *parsed_result,
1921                         __attribute__((unused)) struct cmdline *cl,
1922                         __attribute__((unused)) void *data)
1923 {
1924         struct cmd_config_rxtx_queue *res = parsed_result;
1925         uint8_t isrx;
1926         uint8_t isstart;
1927         int ret = 0;
1928
1929         if (test_done == 0) {
1930                 printf("Please stop forwarding first\n");
1931                 return;
1932         }
1933
1934         if (port_id_is_invalid(res->portid, ENABLED_WARN))
1935                 return;
1936
1937         if (port_is_started(res->portid) != 1) {
1938                 printf("Please start port %u first\n", res->portid);
1939                 return;
1940         }
1941
1942         if (!strcmp(res->rxtxq, "rxq"))
1943                 isrx = 1;
1944         else if (!strcmp(res->rxtxq, "txq"))
1945                 isrx = 0;
1946         else {
1947                 printf("Unknown parameter\n");
1948                 return;
1949         }
1950
1951         if (isrx && rx_queue_id_is_invalid(res->qid))
1952                 return;
1953         else if (!isrx && tx_queue_id_is_invalid(res->qid))
1954                 return;
1955
1956         if (!strcmp(res->opname, "start"))
1957                 isstart = 1;
1958         else if (!strcmp(res->opname, "stop"))
1959                 isstart = 0;
1960         else {
1961                 printf("Unknown parameter\n");
1962                 return;
1963         }
1964
1965         if (isstart && isrx)
1966                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1967         else if (!isstart && isrx)
1968                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1969         else if (isstart && !isrx)
1970                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1971         else
1972                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1973
1974         if (ret == -ENOTSUP)
1975                 printf("Function not supported in PMD driver\n");
1976 }
1977
1978 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1979         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1980 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1981         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1982 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1983         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1984 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1985         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
1986 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
1987         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
1988                                                 "start#stop");
1989
1990 cmdline_parse_inst_t cmd_config_rxtx_queue = {
1991         .f = cmd_config_rxtx_queue_parsed,
1992         .data = NULL,
1993         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
1994         .tokens = {
1995                 (void *)&cmd_config_speed_all_port,
1996                 (void *)&cmd_config_rxtx_queue_portid,
1997                 (void *)&cmd_config_rxtx_queue_rxtxq,
1998                 (void *)&cmd_config_rxtx_queue_qid,
1999                 (void *)&cmd_config_rxtx_queue_opname,
2000                 NULL,
2001         },
2002 };
2003
2004 /* *** Configure RSS RETA *** */
2005 struct cmd_config_rss_reta {
2006         cmdline_fixed_string_t port;
2007         cmdline_fixed_string_t keyword;
2008         uint8_t port_id;
2009         cmdline_fixed_string_t name;
2010         cmdline_fixed_string_t list_name;
2011         cmdline_fixed_string_t list_of_items;
2012 };
2013
2014 static int
2015 parse_reta_config(const char *str,
2016                   struct rte_eth_rss_reta_entry64 *reta_conf,
2017                   uint16_t nb_entries)
2018 {
2019         int i;
2020         unsigned size;
2021         uint16_t hash_index, idx, shift;
2022         uint16_t nb_queue;
2023         char s[256];
2024         const char *p, *p0 = str;
2025         char *end;
2026         enum fieldnames {
2027                 FLD_HASH_INDEX = 0,
2028                 FLD_QUEUE,
2029                 _NUM_FLD
2030         };
2031         unsigned long int_fld[_NUM_FLD];
2032         char *str_fld[_NUM_FLD];
2033
2034         while ((p = strchr(p0,'(')) != NULL) {
2035                 ++p;
2036                 if((p0 = strchr(p,')')) == NULL)
2037                         return -1;
2038
2039                 size = p0 - p;
2040                 if(size >= sizeof(s))
2041                         return -1;
2042
2043                 snprintf(s, sizeof(s), "%.*s", size, p);
2044                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2045                         return -1;
2046                 for (i = 0; i < _NUM_FLD; i++) {
2047                         errno = 0;
2048                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2049                         if (errno != 0 || end == str_fld[i] ||
2050                                         int_fld[i] > 65535)
2051                                 return -1;
2052                 }
2053
2054                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2055                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2056
2057                 if (hash_index >= nb_entries) {
2058                         printf("Invalid RETA hash index=%d\n", hash_index);
2059                         return -1;
2060                 }
2061
2062                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2063                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2064                 reta_conf[idx].mask |= (1ULL << shift);
2065                 reta_conf[idx].reta[shift] = nb_queue;
2066         }
2067
2068         return 0;
2069 }
2070
2071 static void
2072 cmd_set_rss_reta_parsed(void *parsed_result,
2073                         __attribute__((unused)) struct cmdline *cl,
2074                         __attribute__((unused)) void *data)
2075 {
2076         int ret;
2077         struct rte_eth_dev_info dev_info;
2078         struct rte_eth_rss_reta_entry64 reta_conf[8];
2079         struct cmd_config_rss_reta *res = parsed_result;
2080
2081         memset(&dev_info, 0, sizeof(dev_info));
2082         rte_eth_dev_info_get(res->port_id, &dev_info);
2083         if (dev_info.reta_size == 0) {
2084                 printf("Redirection table size is 0 which is "
2085                                         "invalid for RSS\n");
2086                 return;
2087         } else
2088                 printf("The reta size of port %d is %u\n",
2089                         res->port_id, dev_info.reta_size);
2090         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2091                 printf("Currently do not support more than %u entries of "
2092                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2093                 return;
2094         }
2095
2096         memset(reta_conf, 0, sizeof(reta_conf));
2097         if (!strcmp(res->list_name, "reta")) {
2098                 if (parse_reta_config(res->list_of_items, reta_conf,
2099                                                 dev_info.reta_size)) {
2100                         printf("Invalid RSS Redirection Table "
2101                                         "config entered\n");
2102                         return;
2103                 }
2104                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2105                                 reta_conf, dev_info.reta_size);
2106                 if (ret != 0)
2107                         printf("Bad redirection table parameter, "
2108                                         "return code = %d \n", ret);
2109         }
2110 }
2111
2112 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2113         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2114 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2115         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2116 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2117         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
2118 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2119         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2120 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2121         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2122 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2123         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2124                                  NULL);
2125 cmdline_parse_inst_t cmd_config_rss_reta = {
2126         .f = cmd_set_rss_reta_parsed,
2127         .data = NULL,
2128         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2129         .tokens = {
2130                 (void *)&cmd_config_rss_reta_port,
2131                 (void *)&cmd_config_rss_reta_keyword,
2132                 (void *)&cmd_config_rss_reta_port_id,
2133                 (void *)&cmd_config_rss_reta_name,
2134                 (void *)&cmd_config_rss_reta_list_name,
2135                 (void *)&cmd_config_rss_reta_list_of_items,
2136                 NULL,
2137         },
2138 };
2139
2140 /* *** SHOW PORT RETA INFO *** */
2141 struct cmd_showport_reta {
2142         cmdline_fixed_string_t show;
2143         cmdline_fixed_string_t port;
2144         uint8_t port_id;
2145         cmdline_fixed_string_t rss;
2146         cmdline_fixed_string_t reta;
2147         uint16_t size;
2148         cmdline_fixed_string_t list_of_items;
2149 };
2150
2151 static int
2152 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2153                            uint16_t nb_entries,
2154                            char *str)
2155 {
2156         uint32_t size;
2157         const char *p, *p0 = str;
2158         char s[256];
2159         char *end;
2160         char *str_fld[8];
2161         uint16_t i;
2162         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2163                         RTE_RETA_GROUP_SIZE;
2164         int ret;
2165
2166         p = strchr(p0, '(');
2167         if (p == NULL)
2168                 return -1;
2169         p++;
2170         p0 = strchr(p, ')');
2171         if (p0 == NULL)
2172                 return -1;
2173         size = p0 - p;
2174         if (size >= sizeof(s)) {
2175                 printf("The string size exceeds the internal buffer size\n");
2176                 return -1;
2177         }
2178         snprintf(s, sizeof(s), "%.*s", size, p);
2179         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2180         if (ret <= 0 || ret != num) {
2181                 printf("The bits of masks do not match the number of "
2182                                         "reta entries: %u\n", num);
2183                 return -1;
2184         }
2185         for (i = 0; i < ret; i++)
2186                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2187
2188         return 0;
2189 }
2190
2191 static void
2192 cmd_showport_reta_parsed(void *parsed_result,
2193                          __attribute__((unused)) struct cmdline *cl,
2194                          __attribute__((unused)) void *data)
2195 {
2196         struct cmd_showport_reta *res = parsed_result;
2197         struct rte_eth_rss_reta_entry64 reta_conf[8];
2198         struct rte_eth_dev_info dev_info;
2199         uint16_t max_reta_size;
2200
2201         memset(&dev_info, 0, sizeof(dev_info));
2202         rte_eth_dev_info_get(res->port_id, &dev_info);
2203         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2204         if (res->size == 0 || res->size > max_reta_size) {
2205                 printf("Invalid redirection table size: %u (1-%u)\n",
2206                         res->size, max_reta_size);
2207                 return;
2208         }
2209
2210         memset(reta_conf, 0, sizeof(reta_conf));
2211         if (showport_parse_reta_config(reta_conf, res->size,
2212                                 res->list_of_items) < 0) {
2213                 printf("Invalid string: %s for reta masks\n",
2214                                         res->list_of_items);
2215                 return;
2216         }
2217         port_rss_reta_info(res->port_id, reta_conf, res->size);
2218 }
2219
2220 cmdline_parse_token_string_t cmd_showport_reta_show =
2221         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2222 cmdline_parse_token_string_t cmd_showport_reta_port =
2223         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2224 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2225         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
2226 cmdline_parse_token_string_t cmd_showport_reta_rss =
2227         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2228 cmdline_parse_token_string_t cmd_showport_reta_reta =
2229         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2230 cmdline_parse_token_num_t cmd_showport_reta_size =
2231         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2232 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2233         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2234                                         list_of_items, NULL);
2235
2236 cmdline_parse_inst_t cmd_showport_reta = {
2237         .f = cmd_showport_reta_parsed,
2238         .data = NULL,
2239         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2240         .tokens = {
2241                 (void *)&cmd_showport_reta_show,
2242                 (void *)&cmd_showport_reta_port,
2243                 (void *)&cmd_showport_reta_port_id,
2244                 (void *)&cmd_showport_reta_rss,
2245                 (void *)&cmd_showport_reta_reta,
2246                 (void *)&cmd_showport_reta_size,
2247                 (void *)&cmd_showport_reta_list_of_items,
2248                 NULL,
2249         },
2250 };
2251
2252 /* *** Show RSS hash configuration *** */
2253 struct cmd_showport_rss_hash {
2254         cmdline_fixed_string_t show;
2255         cmdline_fixed_string_t port;
2256         uint8_t port_id;
2257         cmdline_fixed_string_t rss_hash;
2258         cmdline_fixed_string_t rss_type;
2259         cmdline_fixed_string_t key; /* optional argument */
2260 };
2261
2262 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2263                                 __attribute__((unused)) struct cmdline *cl,
2264                                 void *show_rss_key)
2265 {
2266         struct cmd_showport_rss_hash *res = parsed_result;
2267
2268         port_rss_hash_conf_show(res->port_id, res->rss_type,
2269                                 show_rss_key != NULL);
2270 }
2271
2272 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2273         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2274 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2275         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2276 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2277         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
2278 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2279         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2280                                  "rss-hash");
2281 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2282         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2283                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2284                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2285                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2286                                  "ipv6-tcp-ex#ipv6-udp-ex");
2287 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2288         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2289
2290 cmdline_parse_inst_t cmd_showport_rss_hash = {
2291         .f = cmd_showport_rss_hash_parsed,
2292         .data = NULL,
2293         .help_str = "show port <port_id> rss-hash "
2294                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2295                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2296                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2297         .tokens = {
2298                 (void *)&cmd_showport_rss_hash_show,
2299                 (void *)&cmd_showport_rss_hash_port,
2300                 (void *)&cmd_showport_rss_hash_port_id,
2301                 (void *)&cmd_showport_rss_hash_rss_hash,
2302                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2303                 NULL,
2304         },
2305 };
2306
2307 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2308         .f = cmd_showport_rss_hash_parsed,
2309         .data = (void *)1,
2310         .help_str = "show port <port_id> rss-hash "
2311                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2312                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2313                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2314         .tokens = {
2315                 (void *)&cmd_showport_rss_hash_show,
2316                 (void *)&cmd_showport_rss_hash_port,
2317                 (void *)&cmd_showport_rss_hash_port_id,
2318                 (void *)&cmd_showport_rss_hash_rss_hash,
2319                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2320                 (void *)&cmd_showport_rss_hash_rss_key,
2321                 NULL,
2322         },
2323 };
2324
2325 /* *** Configure DCB *** */
2326 struct cmd_config_dcb {
2327         cmdline_fixed_string_t port;
2328         cmdline_fixed_string_t config;
2329         uint8_t port_id;
2330         cmdline_fixed_string_t dcb;
2331         cmdline_fixed_string_t vt;
2332         cmdline_fixed_string_t vt_en;
2333         uint8_t num_tcs;
2334         cmdline_fixed_string_t pfc;
2335         cmdline_fixed_string_t pfc_en;
2336 };
2337
2338 static void
2339 cmd_config_dcb_parsed(void *parsed_result,
2340                         __attribute__((unused)) struct cmdline *cl,
2341                         __attribute__((unused)) void *data)
2342 {
2343         struct cmd_config_dcb *res = parsed_result;
2344         portid_t port_id = res->port_id;
2345         struct rte_port *port;
2346         uint8_t pfc_en;
2347         int ret;
2348
2349         port = &ports[port_id];
2350         /** Check if the port is not started **/
2351         if (port->port_status != RTE_PORT_STOPPED) {
2352                 printf("Please stop port %d first\n", port_id);
2353                 return;
2354         }
2355
2356         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2357                 printf("The invalid number of traffic class,"
2358                         " only 4 or 8 allowed.\n");
2359                 return;
2360         }
2361
2362         if (nb_fwd_lcores < res->num_tcs) {
2363                 printf("nb_cores shouldn't be less than number of TCs.\n");
2364                 return;
2365         }
2366         if (!strncmp(res->pfc_en, "on", 2))
2367                 pfc_en = 1;
2368         else
2369                 pfc_en = 0;
2370
2371         /* DCB in VT mode */
2372         if (!strncmp(res->vt_en, "on", 2))
2373                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2374                                 (enum rte_eth_nb_tcs)res->num_tcs,
2375                                 pfc_en);
2376         else
2377                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2378                                 (enum rte_eth_nb_tcs)res->num_tcs,
2379                                 pfc_en);
2380
2381
2382         if (ret != 0) {
2383                 printf("Cannot initialize network ports.\n");
2384                 return;
2385         }
2386
2387         cmd_reconfig_device_queue(port_id, 1, 1);
2388 }
2389
2390 cmdline_parse_token_string_t cmd_config_dcb_port =
2391         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2392 cmdline_parse_token_string_t cmd_config_dcb_config =
2393         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2394 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2395         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2396 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2397         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2398 cmdline_parse_token_string_t cmd_config_dcb_vt =
2399         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2400 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2401         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2402 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2403         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2404 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2405         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2406 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2407         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2408
2409 cmdline_parse_inst_t cmd_config_dcb = {
2410         .f = cmd_config_dcb_parsed,
2411         .data = NULL,
2412         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2413         .tokens = {
2414                 (void *)&cmd_config_dcb_port,
2415                 (void *)&cmd_config_dcb_config,
2416                 (void *)&cmd_config_dcb_port_id,
2417                 (void *)&cmd_config_dcb_dcb,
2418                 (void *)&cmd_config_dcb_vt,
2419                 (void *)&cmd_config_dcb_vt_en,
2420                 (void *)&cmd_config_dcb_num_tcs,
2421                 (void *)&cmd_config_dcb_pfc,
2422                 (void *)&cmd_config_dcb_pfc_en,
2423                 NULL,
2424         },
2425 };
2426
2427 /* *** configure number of packets per burst *** */
2428 struct cmd_config_burst {
2429         cmdline_fixed_string_t port;
2430         cmdline_fixed_string_t keyword;
2431         cmdline_fixed_string_t all;
2432         cmdline_fixed_string_t name;
2433         uint16_t value;
2434 };
2435
2436 static void
2437 cmd_config_burst_parsed(void *parsed_result,
2438                         __attribute__((unused)) struct cmdline *cl,
2439                         __attribute__((unused)) void *data)
2440 {
2441         struct cmd_config_burst *res = parsed_result;
2442
2443         if (!all_ports_stopped()) {
2444                 printf("Please stop all ports first\n");
2445                 return;
2446         }
2447
2448         if (!strcmp(res->name, "burst")) {
2449                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2450                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2451                         return;
2452                 }
2453                 nb_pkt_per_burst = res->value;
2454         } else {
2455                 printf("Unknown parameter\n");
2456                 return;
2457         }
2458
2459         init_port_config();
2460
2461         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2462 }
2463
2464 cmdline_parse_token_string_t cmd_config_burst_port =
2465         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2466 cmdline_parse_token_string_t cmd_config_burst_keyword =
2467         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2468 cmdline_parse_token_string_t cmd_config_burst_all =
2469         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2470 cmdline_parse_token_string_t cmd_config_burst_name =
2471         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2472 cmdline_parse_token_num_t cmd_config_burst_value =
2473         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2474
2475 cmdline_parse_inst_t cmd_config_burst = {
2476         .f = cmd_config_burst_parsed,
2477         .data = NULL,
2478         .help_str = "port config all burst <value>",
2479         .tokens = {
2480                 (void *)&cmd_config_burst_port,
2481                 (void *)&cmd_config_burst_keyword,
2482                 (void *)&cmd_config_burst_all,
2483                 (void *)&cmd_config_burst_name,
2484                 (void *)&cmd_config_burst_value,
2485                 NULL,
2486         },
2487 };
2488
2489 /* *** configure rx/tx queues *** */
2490 struct cmd_config_thresh {
2491         cmdline_fixed_string_t port;
2492         cmdline_fixed_string_t keyword;
2493         cmdline_fixed_string_t all;
2494         cmdline_fixed_string_t name;
2495         uint8_t value;
2496 };
2497
2498 static void
2499 cmd_config_thresh_parsed(void *parsed_result,
2500                         __attribute__((unused)) struct cmdline *cl,
2501                         __attribute__((unused)) void *data)
2502 {
2503         struct cmd_config_thresh *res = parsed_result;
2504
2505         if (!all_ports_stopped()) {
2506                 printf("Please stop all ports first\n");
2507                 return;
2508         }
2509
2510         if (!strcmp(res->name, "txpt"))
2511                 tx_pthresh = res->value;
2512         else if(!strcmp(res->name, "txht"))
2513                 tx_hthresh = res->value;
2514         else if(!strcmp(res->name, "txwt"))
2515                 tx_wthresh = res->value;
2516         else if(!strcmp(res->name, "rxpt"))
2517                 rx_pthresh = res->value;
2518         else if(!strcmp(res->name, "rxht"))
2519                 rx_hthresh = res->value;
2520         else if(!strcmp(res->name, "rxwt"))
2521                 rx_wthresh = res->value;
2522         else {
2523                 printf("Unknown parameter\n");
2524                 return;
2525         }
2526
2527         init_port_config();
2528
2529         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2530 }
2531
2532 cmdline_parse_token_string_t cmd_config_thresh_port =
2533         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2534 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2535         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2536 cmdline_parse_token_string_t cmd_config_thresh_all =
2537         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2538 cmdline_parse_token_string_t cmd_config_thresh_name =
2539         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2540                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2541 cmdline_parse_token_num_t cmd_config_thresh_value =
2542         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2543
2544 cmdline_parse_inst_t cmd_config_thresh = {
2545         .f = cmd_config_thresh_parsed,
2546         .data = NULL,
2547         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2548         .tokens = {
2549                 (void *)&cmd_config_thresh_port,
2550                 (void *)&cmd_config_thresh_keyword,
2551                 (void *)&cmd_config_thresh_all,
2552                 (void *)&cmd_config_thresh_name,
2553                 (void *)&cmd_config_thresh_value,
2554                 NULL,
2555         },
2556 };
2557
2558 /* *** configure free/rs threshold *** */
2559 struct cmd_config_threshold {
2560         cmdline_fixed_string_t port;
2561         cmdline_fixed_string_t keyword;
2562         cmdline_fixed_string_t all;
2563         cmdline_fixed_string_t name;
2564         uint16_t value;
2565 };
2566
2567 static void
2568 cmd_config_threshold_parsed(void *parsed_result,
2569                         __attribute__((unused)) struct cmdline *cl,
2570                         __attribute__((unused)) void *data)
2571 {
2572         struct cmd_config_threshold *res = parsed_result;
2573
2574         if (!all_ports_stopped()) {
2575                 printf("Please stop all ports first\n");
2576                 return;
2577         }
2578
2579         if (!strcmp(res->name, "txfreet"))
2580                 tx_free_thresh = res->value;
2581         else if (!strcmp(res->name, "txrst"))
2582                 tx_rs_thresh = res->value;
2583         else if (!strcmp(res->name, "rxfreet"))
2584                 rx_free_thresh = res->value;
2585         else {
2586                 printf("Unknown parameter\n");
2587                 return;
2588         }
2589
2590         init_port_config();
2591
2592         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2593 }
2594
2595 cmdline_parse_token_string_t cmd_config_threshold_port =
2596         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2597 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2598         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2599                                                                 "config");
2600 cmdline_parse_token_string_t cmd_config_threshold_all =
2601         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2602 cmdline_parse_token_string_t cmd_config_threshold_name =
2603         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2604                                                 "txfreet#txrst#rxfreet");
2605 cmdline_parse_token_num_t cmd_config_threshold_value =
2606         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2607
2608 cmdline_parse_inst_t cmd_config_threshold = {
2609         .f = cmd_config_threshold_parsed,
2610         .data = NULL,
2611         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2612         .tokens = {
2613                 (void *)&cmd_config_threshold_port,
2614                 (void *)&cmd_config_threshold_keyword,
2615                 (void *)&cmd_config_threshold_all,
2616                 (void *)&cmd_config_threshold_name,
2617                 (void *)&cmd_config_threshold_value,
2618                 NULL,
2619         },
2620 };
2621
2622 /* *** stop *** */
2623 struct cmd_stop_result {
2624         cmdline_fixed_string_t stop;
2625 };
2626
2627 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2628                             __attribute__((unused)) struct cmdline *cl,
2629                             __attribute__((unused)) void *data)
2630 {
2631         stop_packet_forwarding();
2632 }
2633
2634 cmdline_parse_token_string_t cmd_stop_stop =
2635         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2636
2637 cmdline_parse_inst_t cmd_stop = {
2638         .f = cmd_stop_parsed,
2639         .data = NULL,
2640         .help_str = "stop: Stop packet forwarding",
2641         .tokens = {
2642                 (void *)&cmd_stop_stop,
2643                 NULL,
2644         },
2645 };
2646
2647 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2648
2649 unsigned int
2650 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2651                 unsigned int *parsed_items, int check_unique_values)
2652 {
2653         unsigned int nb_item;
2654         unsigned int value;
2655         unsigned int i;
2656         unsigned int j;
2657         int value_ok;
2658         char c;
2659
2660         /*
2661          * First parse all items in the list and store their value.
2662          */
2663         value = 0;
2664         nb_item = 0;
2665         value_ok = 0;
2666         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2667                 c = str[i];
2668                 if ((c >= '0') && (c <= '9')) {
2669                         value = (unsigned int) (value * 10 + (c - '0'));
2670                         value_ok = 1;
2671                         continue;
2672                 }
2673                 if (c != ',') {
2674                         printf("character %c is not a decimal digit\n", c);
2675                         return 0;
2676                 }
2677                 if (! value_ok) {
2678                         printf("No valid value before comma\n");
2679                         return 0;
2680                 }
2681                 if (nb_item < max_items) {
2682                         parsed_items[nb_item] = value;
2683                         value_ok = 0;
2684                         value = 0;
2685                 }
2686                 nb_item++;
2687         }
2688         if (nb_item >= max_items) {
2689                 printf("Number of %s = %u > %u (maximum items)\n",
2690                        item_name, nb_item + 1, max_items);
2691                 return 0;
2692         }
2693         parsed_items[nb_item++] = value;
2694         if (! check_unique_values)
2695                 return nb_item;
2696
2697         /*
2698          * Then, check that all values in the list are differents.
2699          * No optimization here...
2700          */
2701         for (i = 0; i < nb_item; i++) {
2702                 for (j = i + 1; j < nb_item; j++) {
2703                         if (parsed_items[j] == parsed_items[i]) {
2704                                 printf("duplicated %s %u at index %u and %u\n",
2705                                        item_name, parsed_items[i], i, j);
2706                                 return 0;
2707                         }
2708                 }
2709         }
2710         return nb_item;
2711 }
2712
2713 struct cmd_set_list_result {
2714         cmdline_fixed_string_t cmd_keyword;
2715         cmdline_fixed_string_t list_name;
2716         cmdline_fixed_string_t list_of_items;
2717 };
2718
2719 static void cmd_set_list_parsed(void *parsed_result,
2720                                 __attribute__((unused)) struct cmdline *cl,
2721                                 __attribute__((unused)) void *data)
2722 {
2723         struct cmd_set_list_result *res;
2724         union {
2725                 unsigned int lcorelist[RTE_MAX_LCORE];
2726                 unsigned int portlist[RTE_MAX_ETHPORTS];
2727         } parsed_items;
2728         unsigned int nb_item;
2729
2730         if (test_done == 0) {
2731                 printf("Please stop forwarding first\n");
2732                 return;
2733         }
2734
2735         res = parsed_result;
2736         if (!strcmp(res->list_name, "corelist")) {
2737                 nb_item = parse_item_list(res->list_of_items, "core",
2738                                           RTE_MAX_LCORE,
2739                                           parsed_items.lcorelist, 1);
2740                 if (nb_item > 0) {
2741                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2742                         fwd_config_setup();
2743                 }
2744                 return;
2745         }
2746         if (!strcmp(res->list_name, "portlist")) {
2747                 nb_item = parse_item_list(res->list_of_items, "port",
2748                                           RTE_MAX_ETHPORTS,
2749                                           parsed_items.portlist, 1);
2750                 if (nb_item > 0) {
2751                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2752                         fwd_config_setup();
2753                 }
2754         }
2755 }
2756
2757 cmdline_parse_token_string_t cmd_set_list_keyword =
2758         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2759                                  "set");
2760 cmdline_parse_token_string_t cmd_set_list_name =
2761         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2762                                  "corelist#portlist");
2763 cmdline_parse_token_string_t cmd_set_list_of_items =
2764         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2765                                  NULL);
2766
2767 cmdline_parse_inst_t cmd_set_fwd_list = {
2768         .f = cmd_set_list_parsed,
2769         .data = NULL,
2770         .help_str = "set corelist|portlist <list0[,list1]*>",
2771         .tokens = {
2772                 (void *)&cmd_set_list_keyword,
2773                 (void *)&cmd_set_list_name,
2774                 (void *)&cmd_set_list_of_items,
2775                 NULL,
2776         },
2777 };
2778
2779 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2780
2781 struct cmd_setmask_result {
2782         cmdline_fixed_string_t set;
2783         cmdline_fixed_string_t mask;
2784         uint64_t hexavalue;
2785 };
2786
2787 static void cmd_set_mask_parsed(void *parsed_result,
2788                                 __attribute__((unused)) struct cmdline *cl,
2789                                 __attribute__((unused)) void *data)
2790 {
2791         struct cmd_setmask_result *res = parsed_result;
2792
2793         if (test_done == 0) {
2794                 printf("Please stop forwarding first\n");
2795                 return;
2796         }
2797         if (!strcmp(res->mask, "coremask")) {
2798                 set_fwd_lcores_mask(res->hexavalue);
2799                 fwd_config_setup();
2800         } else if (!strcmp(res->mask, "portmask")) {
2801                 set_fwd_ports_mask(res->hexavalue);
2802                 fwd_config_setup();
2803         }
2804 }
2805
2806 cmdline_parse_token_string_t cmd_setmask_set =
2807         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2808 cmdline_parse_token_string_t cmd_setmask_mask =
2809         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2810                                  "coremask#portmask");
2811 cmdline_parse_token_num_t cmd_setmask_value =
2812         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2813
2814 cmdline_parse_inst_t cmd_set_fwd_mask = {
2815         .f = cmd_set_mask_parsed,
2816         .data = NULL,
2817         .help_str = "set coremask|portmask <hexadecimal value>",
2818         .tokens = {
2819                 (void *)&cmd_setmask_set,
2820                 (void *)&cmd_setmask_mask,
2821                 (void *)&cmd_setmask_value,
2822                 NULL,
2823         },
2824 };
2825
2826 /*
2827  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2828  */
2829 struct cmd_set_result {
2830         cmdline_fixed_string_t set;
2831         cmdline_fixed_string_t what;
2832         uint16_t value;
2833 };
2834
2835 static void cmd_set_parsed(void *parsed_result,
2836                            __attribute__((unused)) struct cmdline *cl,
2837                            __attribute__((unused)) void *data)
2838 {
2839         struct cmd_set_result *res = parsed_result;
2840         if (!strcmp(res->what, "nbport")) {
2841                 set_fwd_ports_number(res->value);
2842                 fwd_config_setup();
2843         } else if (!strcmp(res->what, "nbcore")) {
2844                 set_fwd_lcores_number(res->value);
2845                 fwd_config_setup();
2846         } else if (!strcmp(res->what, "burst"))
2847                 set_nb_pkt_per_burst(res->value);
2848         else if (!strcmp(res->what, "verbose"))
2849                 set_verbose_level(res->value);
2850 }
2851
2852 cmdline_parse_token_string_t cmd_set_set =
2853         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2854 cmdline_parse_token_string_t cmd_set_what =
2855         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2856                                  "nbport#nbcore#burst#verbose");
2857 cmdline_parse_token_num_t cmd_set_value =
2858         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2859
2860 cmdline_parse_inst_t cmd_set_numbers = {
2861         .f = cmd_set_parsed,
2862         .data = NULL,
2863         .help_str = "set nbport|nbcore|burst|verbose <value>",
2864         .tokens = {
2865                 (void *)&cmd_set_set,
2866                 (void *)&cmd_set_what,
2867                 (void *)&cmd_set_value,
2868                 NULL,
2869         },
2870 };
2871
2872 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2873
2874 struct cmd_set_txpkts_result {
2875         cmdline_fixed_string_t cmd_keyword;
2876         cmdline_fixed_string_t txpkts;
2877         cmdline_fixed_string_t seg_lengths;
2878 };
2879
2880 static void
2881 cmd_set_txpkts_parsed(void *parsed_result,
2882                       __attribute__((unused)) struct cmdline *cl,
2883                       __attribute__((unused)) void *data)
2884 {
2885         struct cmd_set_txpkts_result *res;
2886         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2887         unsigned int nb_segs;
2888
2889         res = parsed_result;
2890         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2891                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2892         if (nb_segs > 0)
2893                 set_tx_pkt_segments(seg_lengths, nb_segs);
2894 }
2895
2896 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2897         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2898                                  cmd_keyword, "set");
2899 cmdline_parse_token_string_t cmd_set_txpkts_name =
2900         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2901                                  txpkts, "txpkts");
2902 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2903         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2904                                  seg_lengths, NULL);
2905
2906 cmdline_parse_inst_t cmd_set_txpkts = {
2907         .f = cmd_set_txpkts_parsed,
2908         .data = NULL,
2909         .help_str = "set txpkts <len0[,len1]*>",
2910         .tokens = {
2911                 (void *)&cmd_set_txpkts_keyword,
2912                 (void *)&cmd_set_txpkts_name,
2913                 (void *)&cmd_set_txpkts_lengths,
2914                 NULL,
2915         },
2916 };
2917
2918 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2919
2920 struct cmd_set_txsplit_result {
2921         cmdline_fixed_string_t cmd_keyword;
2922         cmdline_fixed_string_t txsplit;
2923         cmdline_fixed_string_t mode;
2924 };
2925
2926 static void
2927 cmd_set_txsplit_parsed(void *parsed_result,
2928                       __attribute__((unused)) struct cmdline *cl,
2929                       __attribute__((unused)) void *data)
2930 {
2931         struct cmd_set_txsplit_result *res;
2932
2933         res = parsed_result;
2934         set_tx_pkt_split(res->mode);
2935 }
2936
2937 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2938         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2939                                  cmd_keyword, "set");
2940 cmdline_parse_token_string_t cmd_set_txsplit_name =
2941         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2942                                  txsplit, "txsplit");
2943 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2944         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2945                                  mode, NULL);
2946
2947 cmdline_parse_inst_t cmd_set_txsplit = {
2948         .f = cmd_set_txsplit_parsed,
2949         .data = NULL,
2950         .help_str = "set txsplit on|off|rand",
2951         .tokens = {
2952                 (void *)&cmd_set_txsplit_keyword,
2953                 (void *)&cmd_set_txsplit_name,
2954                 (void *)&cmd_set_txsplit_mode,
2955                 NULL,
2956         },
2957 };
2958
2959 /* *** CONFIG TX QUEUE FLAGS *** */
2960
2961 struct cmd_config_txqflags_result {
2962         cmdline_fixed_string_t port;
2963         cmdline_fixed_string_t config;
2964         cmdline_fixed_string_t all;
2965         cmdline_fixed_string_t what;
2966         int32_t hexvalue;
2967 };
2968
2969 static void cmd_config_txqflags_parsed(void *parsed_result,
2970                                 __attribute__((unused)) struct cmdline *cl,
2971                                 __attribute__((unused)) void *data)
2972 {
2973         struct cmd_config_txqflags_result *res = parsed_result;
2974
2975         if (!all_ports_stopped()) {
2976                 printf("Please stop all ports first\n");
2977                 return;
2978         }
2979
2980         if (strcmp(res->what, "txqflags")) {
2981                 printf("Unknown parameter\n");
2982                 return;
2983         }
2984
2985         if (res->hexvalue >= 0) {
2986                 txq_flags = res->hexvalue;
2987         } else {
2988                 printf("txqflags must be >= 0\n");
2989                 return;
2990         }
2991
2992         init_port_config();
2993
2994         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2995 }
2996
2997 cmdline_parse_token_string_t cmd_config_txqflags_port =
2998         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
2999                                  "port");
3000 cmdline_parse_token_string_t cmd_config_txqflags_config =
3001         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3002                                  "config");
3003 cmdline_parse_token_string_t cmd_config_txqflags_all =
3004         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3005                                  "all");
3006 cmdline_parse_token_string_t cmd_config_txqflags_what =
3007         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3008                                  "txqflags");
3009 cmdline_parse_token_num_t cmd_config_txqflags_value =
3010         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3011                                 hexvalue, INT32);
3012
3013 cmdline_parse_inst_t cmd_config_txqflags = {
3014         .f = cmd_config_txqflags_parsed,
3015         .data = NULL,
3016         .help_str = "port config all txqflags <value>",
3017         .tokens = {
3018                 (void *)&cmd_config_txqflags_port,
3019                 (void *)&cmd_config_txqflags_config,
3020                 (void *)&cmd_config_txqflags_all,
3021                 (void *)&cmd_config_txqflags_what,
3022                 (void *)&cmd_config_txqflags_value,
3023                 NULL,
3024         },
3025 };
3026
3027 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3028 struct cmd_rx_vlan_filter_all_result {
3029         cmdline_fixed_string_t rx_vlan;
3030         cmdline_fixed_string_t what;
3031         cmdline_fixed_string_t all;
3032         uint8_t port_id;
3033 };
3034
3035 static void
3036 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3037                               __attribute__((unused)) struct cmdline *cl,
3038                               __attribute__((unused)) void *data)
3039 {
3040         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3041
3042         if (!strcmp(res->what, "add"))
3043                 rx_vlan_all_filter_set(res->port_id, 1);
3044         else
3045                 rx_vlan_all_filter_set(res->port_id, 0);
3046 }
3047
3048 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3049         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3050                                  rx_vlan, "rx_vlan");
3051 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3052         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3053                                  what, "add#rm");
3054 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3055         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3056                                  all, "all");
3057 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3058         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3059                               port_id, UINT8);
3060
3061 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3062         .f = cmd_rx_vlan_filter_all_parsed,
3063         .data = NULL,
3064         .help_str = "rx_vlan add|rm all <port_id>: "
3065                 "Add/Remove all identifiers to/from the set of VLAN "
3066                 "identifiers filtered by a port",
3067         .tokens = {
3068                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3069                 (void *)&cmd_rx_vlan_filter_all_what,
3070                 (void *)&cmd_rx_vlan_filter_all_all,
3071                 (void *)&cmd_rx_vlan_filter_all_portid,
3072                 NULL,
3073         },
3074 };
3075
3076 /* *** VLAN OFFLOAD SET ON A PORT *** */
3077 struct cmd_vlan_offload_result {
3078         cmdline_fixed_string_t vlan;
3079         cmdline_fixed_string_t set;
3080         cmdline_fixed_string_t vlan_type;
3081         cmdline_fixed_string_t what;
3082         cmdline_fixed_string_t on;
3083         cmdline_fixed_string_t port_id;
3084 };
3085
3086 static void
3087 cmd_vlan_offload_parsed(void *parsed_result,
3088                           __attribute__((unused)) struct cmdline *cl,
3089                           __attribute__((unused)) void *data)
3090 {
3091         int on;
3092         struct cmd_vlan_offload_result *res = parsed_result;
3093         char *str;
3094         int i, len = 0;
3095         portid_t port_id = 0;
3096         unsigned int tmp;
3097
3098         str = res->port_id;
3099         len = strnlen(str, STR_TOKEN_SIZE);
3100         i = 0;
3101         /* Get port_id first */
3102         while(i < len){
3103                 if(str[i] == ',')
3104                         break;
3105
3106                 i++;
3107         }
3108         str[i]='\0';
3109         tmp = strtoul(str, NULL, 0);
3110         /* If port_id greater that what portid_t can represent, return */
3111         if(tmp >= RTE_MAX_ETHPORTS)
3112                 return;
3113         port_id = (portid_t)tmp;
3114
3115         if (!strcmp(res->on, "on"))
3116                 on = 1;
3117         else
3118                 on = 0;
3119
3120         if (!strcmp(res->what, "strip"))
3121                 rx_vlan_strip_set(port_id,  on);
3122         else if(!strcmp(res->what, "stripq")){
3123                 uint16_t queue_id = 0;
3124
3125                 /* No queue_id, return */
3126                 if(i + 1 >= len) {
3127                         printf("must specify (port,queue_id)\n");
3128                         return;
3129                 }
3130                 tmp = strtoul(str + i + 1, NULL, 0);
3131                 /* If queue_id greater that what 16-bits can represent, return */
3132                 if(tmp > 0xffff)
3133                         return;
3134
3135                 queue_id = (uint16_t)tmp;
3136                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3137         }
3138         else if (!strcmp(res->what, "filter"))
3139                 rx_vlan_filter_set(port_id, on);
3140         else
3141                 vlan_extend_set(port_id, on);
3142
3143         return;
3144 }
3145
3146 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3147         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3148                                  vlan, "vlan");
3149 cmdline_parse_token_string_t cmd_vlan_offload_set =
3150         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3151                                  set, "set");
3152 cmdline_parse_token_string_t cmd_vlan_offload_what =
3153         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3154                                  what, "strip#filter#qinq#stripq");
3155 cmdline_parse_token_string_t cmd_vlan_offload_on =
3156         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3157                               on, "on#off");
3158 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3159         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3160                               port_id, NULL);
3161
3162 cmdline_parse_inst_t cmd_vlan_offload = {
3163         .f = cmd_vlan_offload_parsed,
3164         .data = NULL,
3165         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3166                 "<port_id[,queue_id]>: "
3167                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3168         .tokens = {
3169                 (void *)&cmd_vlan_offload_vlan,
3170                 (void *)&cmd_vlan_offload_set,
3171                 (void *)&cmd_vlan_offload_what,
3172                 (void *)&cmd_vlan_offload_on,
3173                 (void *)&cmd_vlan_offload_portid,
3174                 NULL,
3175         },
3176 };
3177
3178 /* *** VLAN TPID SET ON A PORT *** */
3179 struct cmd_vlan_tpid_result {
3180         cmdline_fixed_string_t vlan;
3181         cmdline_fixed_string_t set;
3182         cmdline_fixed_string_t vlan_type;
3183         cmdline_fixed_string_t what;
3184         uint16_t tp_id;
3185         uint8_t port_id;
3186 };
3187
3188 static void
3189 cmd_vlan_tpid_parsed(void *parsed_result,
3190                           __attribute__((unused)) struct cmdline *cl,
3191                           __attribute__((unused)) void *data)
3192 {
3193         struct cmd_vlan_tpid_result *res = parsed_result;
3194         enum rte_vlan_type vlan_type;
3195
3196         if (!strcmp(res->vlan_type, "inner"))
3197                 vlan_type = ETH_VLAN_TYPE_INNER;
3198         else if (!strcmp(res->vlan_type, "outer"))
3199                 vlan_type = ETH_VLAN_TYPE_OUTER;
3200         else {
3201                 printf("Unknown vlan type\n");
3202                 return;
3203         }
3204         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3205 }
3206
3207 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3208         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3209                                  vlan, "vlan");
3210 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3211         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3212                                  set, "set");
3213 cmdline_parse_token_string_t cmd_vlan_type =
3214         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3215                                  vlan_type, "inner#outer");
3216 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3217         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3218                                  what, "tpid");
3219 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3220         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3221                               tp_id, UINT16);
3222 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3223         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3224                               port_id, UINT8);
3225
3226 cmdline_parse_inst_t cmd_vlan_tpid = {
3227         .f = cmd_vlan_tpid_parsed,
3228         .data = NULL,
3229         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3230                 "Set the VLAN Ether type",
3231         .tokens = {
3232                 (void *)&cmd_vlan_tpid_vlan,
3233                 (void *)&cmd_vlan_tpid_set,
3234                 (void *)&cmd_vlan_type,
3235                 (void *)&cmd_vlan_tpid_what,
3236                 (void *)&cmd_vlan_tpid_tpid,
3237                 (void *)&cmd_vlan_tpid_portid,
3238                 NULL,
3239         },
3240 };
3241
3242 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3243 struct cmd_rx_vlan_filter_result {
3244         cmdline_fixed_string_t rx_vlan;
3245         cmdline_fixed_string_t what;
3246         uint16_t vlan_id;
3247         uint8_t port_id;
3248 };
3249
3250 static void
3251 cmd_rx_vlan_filter_parsed(void *parsed_result,
3252                           __attribute__((unused)) struct cmdline *cl,
3253                           __attribute__((unused)) void *data)
3254 {
3255         struct cmd_rx_vlan_filter_result *res = parsed_result;
3256
3257         if (!strcmp(res->what, "add"))
3258                 rx_vft_set(res->port_id, res->vlan_id, 1);
3259         else
3260                 rx_vft_set(res->port_id, res->vlan_id, 0);
3261 }
3262
3263 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3264         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3265                                  rx_vlan, "rx_vlan");
3266 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3267         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3268                                  what, "add#rm");
3269 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3270         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3271                               vlan_id, UINT16);
3272 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3273         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3274                               port_id, UINT8);
3275
3276 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3277         .f = cmd_rx_vlan_filter_parsed,
3278         .data = NULL,
3279         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3280                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3281                 "identifiers filtered by a port",
3282         .tokens = {
3283                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3284                 (void *)&cmd_rx_vlan_filter_what,
3285                 (void *)&cmd_rx_vlan_filter_vlanid,
3286                 (void *)&cmd_rx_vlan_filter_portid,
3287                 NULL,
3288         },
3289 };
3290
3291 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3292 struct cmd_tx_vlan_set_result {
3293         cmdline_fixed_string_t tx_vlan;
3294         cmdline_fixed_string_t set;
3295         uint8_t port_id;
3296         uint16_t vlan_id;
3297 };
3298
3299 static void
3300 cmd_tx_vlan_set_parsed(void *parsed_result,
3301                        __attribute__((unused)) struct cmdline *cl,
3302                        __attribute__((unused)) void *data)
3303 {
3304         struct cmd_tx_vlan_set_result *res = parsed_result;
3305
3306         tx_vlan_set(res->port_id, res->vlan_id);
3307 }
3308
3309 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3310         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3311                                  tx_vlan, "tx_vlan");
3312 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3313         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3314                                  set, "set");
3315 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3316         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3317                               port_id, UINT8);
3318 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3319         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3320                               vlan_id, UINT16);
3321
3322 cmdline_parse_inst_t cmd_tx_vlan_set = {
3323         .f = cmd_tx_vlan_set_parsed,
3324         .data = NULL,
3325         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3326                 "Enable hardware insertion of a single VLAN header "
3327                 "with a given TAG Identifier in packets sent on a port",
3328         .tokens = {
3329                 (void *)&cmd_tx_vlan_set_tx_vlan,
3330                 (void *)&cmd_tx_vlan_set_set,
3331                 (void *)&cmd_tx_vlan_set_portid,
3332                 (void *)&cmd_tx_vlan_set_vlanid,
3333                 NULL,
3334         },
3335 };
3336
3337 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3338 struct cmd_tx_vlan_set_qinq_result {
3339         cmdline_fixed_string_t tx_vlan;
3340         cmdline_fixed_string_t set;
3341         uint8_t port_id;
3342         uint16_t vlan_id;
3343         uint16_t vlan_id_outer;
3344 };
3345
3346 static void
3347 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3348                             __attribute__((unused)) struct cmdline *cl,
3349                             __attribute__((unused)) void *data)
3350 {
3351         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3352
3353         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3354 }
3355
3356 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3357         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3358                 tx_vlan, "tx_vlan");
3359 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3360         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3361                 set, "set");
3362 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3363         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3364                 port_id, UINT8);
3365 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3366         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3367                 vlan_id, UINT16);
3368 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3369         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3370                 vlan_id_outer, UINT16);
3371
3372 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3373         .f = cmd_tx_vlan_set_qinq_parsed,
3374         .data = NULL,
3375         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3376                 "Enable hardware insertion of double VLAN header "
3377                 "with given TAG Identifiers in packets sent on a port",
3378         .tokens = {
3379                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3380                 (void *)&cmd_tx_vlan_set_qinq_set,
3381                 (void *)&cmd_tx_vlan_set_qinq_portid,
3382                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3383                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3384                 NULL,
3385         },
3386 };
3387
3388 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3389 struct cmd_tx_vlan_set_pvid_result {
3390         cmdline_fixed_string_t tx_vlan;
3391         cmdline_fixed_string_t set;
3392         cmdline_fixed_string_t pvid;
3393         uint8_t port_id;
3394         uint16_t vlan_id;
3395         cmdline_fixed_string_t mode;
3396 };
3397
3398 static void
3399 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3400                             __attribute__((unused)) struct cmdline *cl,
3401                             __attribute__((unused)) void *data)
3402 {
3403         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3404
3405         if (strcmp(res->mode, "on") == 0)
3406                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3407         else
3408                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3409 }
3410
3411 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3412         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3413                                  tx_vlan, "tx_vlan");
3414 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3415         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3416                                  set, "set");
3417 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3418         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3419                                  pvid, "pvid");
3420 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3421         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3422                              port_id, UINT8);
3423 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3424         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3425                               vlan_id, UINT16);
3426 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3427         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3428                                  mode, "on#off");
3429
3430 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3431         .f = cmd_tx_vlan_set_pvid_parsed,
3432         .data = NULL,
3433         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3434         .tokens = {
3435                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3436                 (void *)&cmd_tx_vlan_set_pvid_set,
3437                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3438                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3439                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3440                 (void *)&cmd_tx_vlan_set_pvid_mode,
3441                 NULL,
3442         },
3443 };
3444
3445 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3446 struct cmd_tx_vlan_reset_result {
3447         cmdline_fixed_string_t tx_vlan;
3448         cmdline_fixed_string_t reset;
3449         uint8_t port_id;
3450 };
3451
3452 static void
3453 cmd_tx_vlan_reset_parsed(void *parsed_result,
3454                          __attribute__((unused)) struct cmdline *cl,
3455                          __attribute__((unused)) void *data)
3456 {
3457         struct cmd_tx_vlan_reset_result *res = parsed_result;
3458
3459         tx_vlan_reset(res->port_id);
3460 }
3461
3462 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3463         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3464                                  tx_vlan, "tx_vlan");
3465 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3466         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3467                                  reset, "reset");
3468 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3469         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3470                               port_id, UINT8);
3471
3472 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3473         .f = cmd_tx_vlan_reset_parsed,
3474         .data = NULL,
3475         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3476                 "VLAN header in packets sent on a port",
3477         .tokens = {
3478                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3479                 (void *)&cmd_tx_vlan_reset_reset,
3480                 (void *)&cmd_tx_vlan_reset_portid,
3481                 NULL,
3482         },
3483 };
3484
3485
3486 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3487 struct cmd_csum_result {
3488         cmdline_fixed_string_t csum;
3489         cmdline_fixed_string_t mode;
3490         cmdline_fixed_string_t proto;
3491         cmdline_fixed_string_t hwsw;
3492         uint8_t port_id;
3493 };
3494
3495 static void
3496 csum_show(int port_id)
3497 {
3498         struct rte_eth_dev_info dev_info;
3499         uint16_t ol_flags;
3500
3501         ol_flags = ports[port_id].tx_ol_flags;
3502         printf("Parse tunnel is %s\n",
3503                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3504         printf("IP checksum offload is %s\n",
3505                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3506         printf("UDP checksum offload is %s\n",
3507                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3508         printf("TCP checksum offload is %s\n",
3509                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3510         printf("SCTP checksum offload is %s\n",
3511                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3512         printf("Outer-Ip checksum offload is %s\n",
3513                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3514
3515         /* display warnings if configuration is not supported by the NIC */
3516         rte_eth_dev_info_get(port_id, &dev_info);
3517         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3518                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3519                 printf("Warning: hardware IP checksum enabled but not "
3520                         "supported by port %d\n", port_id);
3521         }
3522         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3523                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3524                 printf("Warning: hardware UDP checksum enabled but not "
3525                         "supported by port %d\n", port_id);
3526         }
3527         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3528                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3529                 printf("Warning: hardware TCP checksum enabled but not "
3530                         "supported by port %d\n", port_id);
3531         }
3532         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3533                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3534                 printf("Warning: hardware SCTP checksum enabled but not "
3535                         "supported by port %d\n", port_id);
3536         }
3537         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3538                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3539                 printf("Warning: hardware outer IP checksum enabled but not "
3540                         "supported by port %d\n", port_id);
3541         }
3542 }
3543
3544 static void
3545 cmd_csum_parsed(void *parsed_result,
3546                        __attribute__((unused)) struct cmdline *cl,
3547                        __attribute__((unused)) void *data)
3548 {
3549         struct cmd_csum_result *res = parsed_result;
3550         int hw = 0;
3551         uint16_t mask = 0;
3552
3553         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3554                 printf("invalid port %d\n", res->port_id);
3555                 return;
3556         }
3557
3558         if (!strcmp(res->mode, "set")) {
3559
3560                 if (!strcmp(res->hwsw, "hw"))
3561                         hw = 1;
3562
3563                 if (!strcmp(res->proto, "ip")) {
3564                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3565                 } else if (!strcmp(res->proto, "udp")) {
3566                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3567                 } else if (!strcmp(res->proto, "tcp")) {
3568                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3569                 } else if (!strcmp(res->proto, "sctp")) {
3570                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3571                 } else if (!strcmp(res->proto, "outer-ip")) {
3572                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3573                 }
3574
3575                 if (hw)
3576                         ports[res->port_id].tx_ol_flags |= mask;
3577                 else
3578                         ports[res->port_id].tx_ol_flags &= (~mask);
3579         }
3580         csum_show(res->port_id);
3581 }
3582
3583 cmdline_parse_token_string_t cmd_csum_csum =
3584         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3585                                 csum, "csum");
3586 cmdline_parse_token_string_t cmd_csum_mode =
3587         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3588                                 mode, "set");
3589 cmdline_parse_token_string_t cmd_csum_proto =
3590         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3591                                 proto, "ip#tcp#udp#sctp#outer-ip");
3592 cmdline_parse_token_string_t cmd_csum_hwsw =
3593         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3594                                 hwsw, "hw#sw");
3595 cmdline_parse_token_num_t cmd_csum_portid =
3596         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3597                                 port_id, UINT8);
3598
3599 cmdline_parse_inst_t cmd_csum_set = {
3600         .f = cmd_csum_parsed,
3601         .data = NULL,
3602         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3603                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3604                 "using csum forward engine",
3605         .tokens = {
3606                 (void *)&cmd_csum_csum,
3607                 (void *)&cmd_csum_mode,
3608                 (void *)&cmd_csum_proto,
3609                 (void *)&cmd_csum_hwsw,
3610                 (void *)&cmd_csum_portid,
3611                 NULL,
3612         },
3613 };
3614
3615 cmdline_parse_token_string_t cmd_csum_mode_show =
3616         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3617                                 mode, "show");
3618
3619 cmdline_parse_inst_t cmd_csum_show = {
3620         .f = cmd_csum_parsed,
3621         .data = NULL,
3622         .help_str = "csum show <port_id>: Show checksum offload configuration",
3623         .tokens = {
3624                 (void *)&cmd_csum_csum,
3625                 (void *)&cmd_csum_mode_show,
3626                 (void *)&cmd_csum_portid,
3627                 NULL,
3628         },
3629 };
3630
3631 /* Enable/disable tunnel parsing */
3632 struct cmd_csum_tunnel_result {
3633         cmdline_fixed_string_t csum;
3634         cmdline_fixed_string_t parse;
3635         cmdline_fixed_string_t onoff;
3636         uint8_t port_id;
3637 };
3638
3639 static void
3640 cmd_csum_tunnel_parsed(void *parsed_result,
3641                        __attribute__((unused)) struct cmdline *cl,
3642                        __attribute__((unused)) void *data)
3643 {
3644         struct cmd_csum_tunnel_result *res = parsed_result;
3645
3646         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3647                 return;
3648
3649         if (!strcmp(res->onoff, "on"))
3650                 ports[res->port_id].tx_ol_flags |=
3651                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3652         else
3653                 ports[res->port_id].tx_ol_flags &=
3654                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3655
3656         csum_show(res->port_id);
3657 }
3658
3659 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3660         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3661                                 csum, "csum");
3662 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3663         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3664                                 parse, "parse_tunnel");
3665 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3666         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3667                                 onoff, "on#off");
3668 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3669         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3670                                 port_id, UINT8);
3671
3672 cmdline_parse_inst_t cmd_csum_tunnel = {
3673         .f = cmd_csum_tunnel_parsed,
3674         .data = NULL,
3675         .help_str = "csum parse_tunnel on|off <port_id>: "
3676                 "Enable/Disable parsing of tunnels for csum engine",
3677         .tokens = {
3678                 (void *)&cmd_csum_tunnel_csum,
3679                 (void *)&cmd_csum_tunnel_parse,
3680                 (void *)&cmd_csum_tunnel_onoff,
3681                 (void *)&cmd_csum_tunnel_portid,
3682                 NULL,
3683         },
3684 };
3685
3686 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3687 struct cmd_tso_set_result {
3688         cmdline_fixed_string_t tso;
3689         cmdline_fixed_string_t mode;
3690         uint16_t tso_segsz;
3691         uint8_t port_id;
3692 };
3693
3694 static void
3695 cmd_tso_set_parsed(void *parsed_result,
3696                        __attribute__((unused)) struct cmdline *cl,
3697                        __attribute__((unused)) void *data)
3698 {
3699         struct cmd_tso_set_result *res = parsed_result;
3700         struct rte_eth_dev_info dev_info;
3701
3702         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3703                 return;
3704
3705         if (!strcmp(res->mode, "set"))
3706                 ports[res->port_id].tso_segsz = res->tso_segsz;
3707
3708         if (ports[res->port_id].tso_segsz == 0)
3709                 printf("TSO for non-tunneled packets is disabled\n");
3710         else
3711                 printf("TSO segment size for non-tunneled packets is %d\n",
3712                         ports[res->port_id].tso_segsz);
3713
3714         /* display warnings if configuration is not supported by the NIC */
3715         rte_eth_dev_info_get(res->port_id, &dev_info);
3716         if ((ports[res->port_id].tso_segsz != 0) &&
3717                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3718                 printf("Warning: TSO enabled but not "
3719                         "supported by port %d\n", res->port_id);
3720         }
3721 }
3722
3723 cmdline_parse_token_string_t cmd_tso_set_tso =
3724         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3725                                 tso, "tso");
3726 cmdline_parse_token_string_t cmd_tso_set_mode =
3727         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3728                                 mode, "set");
3729 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3730         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3731                                 tso_segsz, UINT16);
3732 cmdline_parse_token_num_t cmd_tso_set_portid =
3733         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3734                                 port_id, UINT8);
3735
3736 cmdline_parse_inst_t cmd_tso_set = {
3737         .f = cmd_tso_set_parsed,
3738         .data = NULL,
3739         .help_str = "tso set <tso_segsz> <port_id>: "
3740                 "Set TSO segment size of non-tunneled packets for csum engine "
3741                 "(0 to disable)",
3742         .tokens = {
3743                 (void *)&cmd_tso_set_tso,
3744                 (void *)&cmd_tso_set_mode,
3745                 (void *)&cmd_tso_set_tso_segsz,
3746                 (void *)&cmd_tso_set_portid,
3747                 NULL,
3748         },
3749 };
3750
3751 cmdline_parse_token_string_t cmd_tso_show_mode =
3752         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3753                                 mode, "show");
3754
3755
3756 cmdline_parse_inst_t cmd_tso_show = {
3757         .f = cmd_tso_set_parsed,
3758         .data = NULL,
3759         .help_str = "tso show <port_id>: "
3760                 "Show TSO segment size of non-tunneled packets for csum engine",
3761         .tokens = {
3762                 (void *)&cmd_tso_set_tso,
3763                 (void *)&cmd_tso_show_mode,
3764                 (void *)&cmd_tso_set_portid,
3765                 NULL,
3766         },
3767 };
3768
3769 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3770 struct cmd_tunnel_tso_set_result {
3771         cmdline_fixed_string_t tso;
3772         cmdline_fixed_string_t mode;
3773         uint16_t tso_segsz;
3774         uint8_t port_id;
3775 };
3776
3777 static void
3778 check_tunnel_tso_nic_support(uint8_t port_id)
3779 {
3780         struct rte_eth_dev_info dev_info;
3781
3782         rte_eth_dev_info_get(port_id, &dev_info);
3783         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3784                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3785                        "supported by port %d\n", port_id);
3786         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3787                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3788                         "supported by port %d\n", port_id);
3789         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3790                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3791                        "supported by port %d\n", port_id);
3792         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3793                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3794                        "supported by port %d\n", port_id);
3795 }
3796
3797 static void
3798 cmd_tunnel_tso_set_parsed(void *parsed_result,
3799                           __attribute__((unused)) struct cmdline *cl,
3800                           __attribute__((unused)) void *data)
3801 {
3802         struct cmd_tunnel_tso_set_result *res = parsed_result;
3803
3804         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3805                 return;
3806
3807         if (!strcmp(res->mode, "set"))
3808                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3809
3810         if (ports[res->port_id].tunnel_tso_segsz == 0)
3811                 printf("TSO for tunneled packets is disabled\n");
3812         else {
3813                 printf("TSO segment size for tunneled packets is %d\n",
3814                         ports[res->port_id].tunnel_tso_segsz);
3815
3816                 /* Below conditions are needed to make it work:
3817                  * (1) tunnel TSO is supported by the NIC;
3818                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3819                  * are recognized;
3820                  * (3) for tunneled pkts with outer L3 of IPv4,
3821                  * "csum set outer-ip" must be set to hw, because after tso,
3822                  * total_len of outer IP header is changed, and the checksum
3823                  * of outer IP header calculated by sw should be wrong; that
3824                  * is not necessary for IPv6 tunneled pkts because there's no
3825                  * checksum in IP header anymore.
3826                  */
3827                 check_tunnel_tso_nic_support(res->port_id);
3828
3829                 if (!(ports[res->port_id].tx_ol_flags &
3830                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3831                         printf("Warning: csum parse_tunnel must be set "
3832                                 "so that tunneled packets are recognized\n");
3833                 if (!(ports[res->port_id].tx_ol_flags &
3834                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3835                         printf("Warning: csum set outer-ip must be set to hw "
3836                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3837         }
3838 }
3839
3840 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3841         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3842                                 tso, "tunnel_tso");
3843 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3844         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3845                                 mode, "set");
3846 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3847         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3848                                 tso_segsz, UINT16);
3849 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3850         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3851                                 port_id, UINT8);
3852
3853 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3854         .f = cmd_tunnel_tso_set_parsed,
3855         .data = NULL,
3856         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3857                 "Set TSO segment size of tunneled packets for csum engine "
3858                 "(0 to disable)",
3859         .tokens = {
3860                 (void *)&cmd_tunnel_tso_set_tso,
3861                 (void *)&cmd_tunnel_tso_set_mode,
3862                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3863                 (void *)&cmd_tunnel_tso_set_portid,
3864                 NULL,
3865         },
3866 };
3867
3868 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3869         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3870                                 mode, "show");
3871
3872
3873 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3874         .f = cmd_tunnel_tso_set_parsed,
3875         .data = NULL,
3876         .help_str = "tunnel_tso show <port_id> "
3877                 "Show TSO segment size of tunneled packets for csum engine",
3878         .tokens = {
3879                 (void *)&cmd_tunnel_tso_set_tso,
3880                 (void *)&cmd_tunnel_tso_show_mode,
3881                 (void *)&cmd_tunnel_tso_set_portid,
3882                 NULL,
3883         },
3884 };
3885
3886 /* *** SET GRO FOR A PORT *** */
3887 struct cmd_gro_enable_result {
3888         cmdline_fixed_string_t cmd_set;
3889         cmdline_fixed_string_t cmd_port;
3890         cmdline_fixed_string_t cmd_keyword;
3891         cmdline_fixed_string_t cmd_onoff;
3892         portid_t cmd_pid;
3893 };
3894
3895 static void
3896 cmd_gro_enable_parsed(void *parsed_result,
3897                 __attribute__((unused)) struct cmdline *cl,
3898                 __attribute__((unused)) void *data)
3899 {
3900         struct cmd_gro_enable_result *res;
3901
3902         res = parsed_result;
3903         if (!strcmp(res->cmd_keyword, "gro"))
3904                 setup_gro(res->cmd_onoff, res->cmd_pid);
3905 }
3906
3907 cmdline_parse_token_string_t cmd_gro_enable_set =
3908         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3909                         cmd_set, "set");
3910 cmdline_parse_token_string_t cmd_gro_enable_port =
3911         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3912                         cmd_keyword, "port");
3913 cmdline_parse_token_num_t cmd_gro_enable_pid =
3914         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
3915                         cmd_pid, UINT16);
3916 cmdline_parse_token_string_t cmd_gro_enable_keyword =
3917         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3918                         cmd_keyword, "gro");
3919 cmdline_parse_token_string_t cmd_gro_enable_onoff =
3920         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3921                         cmd_onoff, "on#off");
3922
3923 cmdline_parse_inst_t cmd_gro_enable = {
3924         .f = cmd_gro_enable_parsed,
3925         .data = NULL,
3926         .help_str = "set port <port_id> gro on|off",
3927         .tokens = {
3928                 (void *)&cmd_gro_enable_set,
3929                 (void *)&cmd_gro_enable_port,
3930                 (void *)&cmd_gro_enable_pid,
3931                 (void *)&cmd_gro_enable_keyword,
3932                 (void *)&cmd_gro_enable_onoff,
3933                 NULL,
3934         },
3935 };
3936
3937 /* *** DISPLAY GRO CONFIGURATION *** */
3938 struct cmd_gro_show_result {
3939         cmdline_fixed_string_t cmd_show;
3940         cmdline_fixed_string_t cmd_port;
3941         cmdline_fixed_string_t cmd_keyword;
3942         portid_t cmd_pid;
3943 };
3944
3945 static void
3946 cmd_gro_show_parsed(void *parsed_result,
3947                 __attribute__((unused)) struct cmdline *cl,
3948                 __attribute__((unused)) void *data)
3949 {
3950         struct cmd_gro_show_result *res;
3951
3952         res = parsed_result;
3953         if (!strcmp(res->cmd_keyword, "gro"))
3954                 show_gro(res->cmd_pid);
3955 }
3956
3957 cmdline_parse_token_string_t cmd_gro_show_show =
3958         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3959                         cmd_show, "show");
3960 cmdline_parse_token_string_t cmd_gro_show_port =
3961         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3962                         cmd_port, "port");
3963 cmdline_parse_token_num_t cmd_gro_show_pid =
3964         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
3965                         cmd_pid, UINT16);
3966 cmdline_parse_token_string_t cmd_gro_show_keyword =
3967         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3968                         cmd_keyword, "gro");
3969
3970 cmdline_parse_inst_t cmd_gro_show = {
3971         .f = cmd_gro_show_parsed,
3972         .data = NULL,
3973         .help_str = "show port <port_id> gro",
3974         .tokens = {
3975                 (void *)&cmd_gro_show_show,
3976                 (void *)&cmd_gro_show_port,
3977                 (void *)&cmd_gro_show_pid,
3978                 (void *)&cmd_gro_show_keyword,
3979                 NULL,
3980         },
3981 };
3982
3983 /* *** SET FLUSH CYCLES FOR GRO *** */
3984 struct cmd_gro_flush_result {
3985         cmdline_fixed_string_t cmd_set;
3986         cmdline_fixed_string_t cmd_keyword;
3987         cmdline_fixed_string_t cmd_flush;
3988         uint8_t cmd_cycles;
3989 };
3990
3991 static void
3992 cmd_gro_flush_parsed(void *parsed_result,
3993                 __attribute__((unused)) struct cmdline *cl,
3994                 __attribute__((unused)) void *data)
3995 {
3996         struct cmd_gro_flush_result *res;
3997
3998         res = parsed_result;
3999         if ((!strcmp(res->cmd_keyword, "gro")) &&
4000                         (!strcmp(res->cmd_flush, "flush")))
4001                 setup_gro_flush_cycles(res->cmd_cycles);
4002 }
4003
4004 cmdline_parse_token_string_t cmd_gro_flush_set =
4005         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4006                         cmd_set, "set");
4007 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4008         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4009                         cmd_keyword, "gro");
4010 cmdline_parse_token_string_t cmd_gro_flush_flush =
4011         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4012                         cmd_flush, "flush");
4013 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4014         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4015                         cmd_cycles, UINT8);
4016
4017 cmdline_parse_inst_t cmd_gro_flush = {
4018         .f = cmd_gro_flush_parsed,
4019         .data = NULL,
4020         .help_str = "set gro flush <cycles>",
4021         .tokens = {
4022                 (void *)&cmd_gro_flush_set,
4023                 (void *)&cmd_gro_flush_keyword,
4024                 (void *)&cmd_gro_flush_flush,
4025                 (void *)&cmd_gro_flush_cycles,
4026                 NULL,
4027         },
4028 };
4029
4030 /* *** ENABLE/DISABLE GSO *** */
4031 struct cmd_gso_enable_result {
4032         cmdline_fixed_string_t cmd_set;
4033         cmdline_fixed_string_t cmd_port;
4034         cmdline_fixed_string_t cmd_keyword;
4035         cmdline_fixed_string_t cmd_mode;
4036         portid_t cmd_pid;
4037 };
4038
4039 static void
4040 cmd_gso_enable_parsed(void *parsed_result,
4041                 __attribute__((unused)) struct cmdline *cl,
4042                 __attribute__((unused)) void *data)
4043 {
4044         struct cmd_gso_enable_result *res;
4045
4046         res = parsed_result;
4047         if (!strcmp(res->cmd_keyword, "gso"))
4048                 setup_gso(res->cmd_mode, res->cmd_pid);
4049 }
4050
4051 cmdline_parse_token_string_t cmd_gso_enable_set =
4052         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4053                         cmd_set, "set");
4054 cmdline_parse_token_string_t cmd_gso_enable_port =
4055         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4056                         cmd_port, "port");
4057 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4058         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4059                         cmd_keyword, "gso");
4060 cmdline_parse_token_string_t cmd_gso_enable_mode =
4061         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4062                         cmd_mode, "on#off");
4063 cmdline_parse_token_num_t cmd_gso_enable_pid =
4064         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4065                         cmd_pid, UINT16);
4066
4067 cmdline_parse_inst_t cmd_gso_enable = {
4068         .f = cmd_gso_enable_parsed,
4069         .data = NULL,
4070         .help_str = "set port <port_id> gso on|off",
4071         .tokens = {
4072                 (void *)&cmd_gso_enable_set,
4073                 (void *)&cmd_gso_enable_port,
4074                 (void *)&cmd_gso_enable_pid,
4075                 (void *)&cmd_gso_enable_keyword,
4076                 (void *)&cmd_gso_enable_mode,
4077                 NULL,
4078         },
4079 };
4080
4081 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4082 struct cmd_gso_size_result {
4083         cmdline_fixed_string_t cmd_set;
4084         cmdline_fixed_string_t cmd_keyword;
4085         cmdline_fixed_string_t cmd_segsz;
4086         uint16_t cmd_size;
4087 };
4088
4089 static void
4090 cmd_gso_size_parsed(void *parsed_result,
4091                        __attribute__((unused)) struct cmdline *cl,
4092                        __attribute__((unused)) void *data)
4093 {
4094         struct cmd_gso_size_result *res = parsed_result;
4095
4096         if (test_done == 0) {
4097                 printf("Before setting GSO segsz, please first"
4098                                 " stop fowarding\n");
4099                 return;
4100         }
4101
4102         if (!strcmp(res->cmd_keyword, "gso") &&
4103                         !strcmp(res->cmd_segsz, "segsz")) {
4104                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4105                         printf("gso_size should be larger than %zu."
4106                                         " Please input a legal value\n",
4107                                         RTE_GSO_SEG_SIZE_MIN);
4108                 else
4109                         gso_max_segment_size = res->cmd_size;
4110         }
4111 }
4112
4113 cmdline_parse_token_string_t cmd_gso_size_set =
4114         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4115                                 cmd_set, "set");
4116 cmdline_parse_token_string_t cmd_gso_size_keyword =
4117         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4118                                 cmd_keyword, "gso");
4119 cmdline_parse_token_string_t cmd_gso_size_segsz =
4120         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4121                                 cmd_segsz, "segsz");
4122 cmdline_parse_token_num_t cmd_gso_size_size =
4123         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4124                                 cmd_size, UINT16);
4125
4126 cmdline_parse_inst_t cmd_gso_size = {
4127         .f = cmd_gso_size_parsed,
4128         .data = NULL,
4129         .help_str = "set gso segsz <length>",
4130         .tokens = {
4131                 (void *)&cmd_gso_size_set,
4132                 (void *)&cmd_gso_size_keyword,
4133                 (void *)&cmd_gso_size_segsz,
4134                 (void *)&cmd_gso_size_size,
4135                 NULL,
4136         },
4137 };
4138
4139 /* *** SHOW GSO CONFIGURATION *** */
4140 struct cmd_gso_show_result {
4141         cmdline_fixed_string_t cmd_show;
4142         cmdline_fixed_string_t cmd_port;
4143         cmdline_fixed_string_t cmd_keyword;
4144         portid_t cmd_pid;
4145 };
4146
4147 static void
4148 cmd_gso_show_parsed(void *parsed_result,
4149                        __attribute__((unused)) struct cmdline *cl,
4150                        __attribute__((unused)) void *data)
4151 {
4152         struct cmd_gso_show_result *res = parsed_result;
4153
4154         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4155                 printf("invalid port id %u\n", res->cmd_pid);
4156                 return;
4157         }
4158         if (!strcmp(res->cmd_keyword, "gso")) {
4159                 if (gso_ports[res->cmd_pid].enable) {
4160                         printf("Max GSO'd packet size: %uB\n"
4161                                         "Supported GSO types: TCP/IPv4, "
4162                                         "VxLAN with inner TCP/IPv4 packet, "
4163                                         "GRE with inner TCP/IPv4  packet\n",
4164                                         gso_max_segment_size);
4165                 } else
4166                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4167         }
4168 }
4169
4170 cmdline_parse_token_string_t cmd_gso_show_show =
4171 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4172                 cmd_show, "show");
4173 cmdline_parse_token_string_t cmd_gso_show_port =
4174 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4175                 cmd_port, "port");
4176 cmdline_parse_token_string_t cmd_gso_show_keyword =
4177         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4178                                 cmd_keyword, "gso");
4179 cmdline_parse_token_num_t cmd_gso_show_pid =
4180         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4181                                 cmd_pid, UINT16);
4182
4183 cmdline_parse_inst_t cmd_gso_show = {
4184         .f = cmd_gso_show_parsed,
4185         .data = NULL,
4186         .help_str = "show port <port_id> gso",
4187         .tokens = {
4188                 (void *)&cmd_gso_show_show,
4189                 (void *)&cmd_gso_show_port,
4190                 (void *)&cmd_gso_show_pid,
4191                 (void *)&cmd_gso_show_keyword,
4192                 NULL,
4193         },
4194 };
4195
4196 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4197 struct cmd_set_flush_rx {
4198         cmdline_fixed_string_t set;
4199         cmdline_fixed_string_t flush_rx;
4200         cmdline_fixed_string_t mode;
4201 };
4202
4203 static void
4204 cmd_set_flush_rx_parsed(void *parsed_result,
4205                 __attribute__((unused)) struct cmdline *cl,
4206                 __attribute__((unused)) void *data)
4207 {
4208         struct cmd_set_flush_rx *res = parsed_result;
4209         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4210 }
4211
4212 cmdline_parse_token_string_t cmd_setflushrx_set =
4213         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4214                         set, "set");
4215 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4216         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4217                         flush_rx, "flush_rx");
4218 cmdline_parse_token_string_t cmd_setflushrx_mode =
4219         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4220                         mode, "on#off");
4221
4222
4223 cmdline_parse_inst_t cmd_set_flush_rx = {
4224         .f = cmd_set_flush_rx_parsed,
4225         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4226         .data = NULL,
4227         .tokens = {
4228                 (void *)&cmd_setflushrx_set,
4229                 (void *)&cmd_setflushrx_flush_rx,
4230                 (void *)&cmd_setflushrx_mode,
4231                 NULL,
4232         },
4233 };
4234
4235 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4236 struct cmd_set_link_check {
4237         cmdline_fixed_string_t set;
4238         cmdline_fixed_string_t link_check;
4239         cmdline_fixed_string_t mode;
4240 };
4241
4242 static void
4243 cmd_set_link_check_parsed(void *parsed_result,
4244                 __attribute__((unused)) struct cmdline *cl,
4245                 __attribute__((unused)) void *data)
4246 {
4247         struct cmd_set_link_check *res = parsed_result;
4248         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4249 }
4250
4251 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4252         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4253                         set, "set");
4254 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4255         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4256                         link_check, "link_check");
4257 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4258         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4259                         mode, "on#off");
4260
4261
4262 cmdline_parse_inst_t cmd_set_link_check = {
4263         .f = cmd_set_link_check_parsed,
4264         .help_str = "set link_check on|off: Enable/Disable link status check "
4265                     "when starting/stopping a port",
4266         .data = NULL,
4267         .tokens = {
4268                 (void *)&cmd_setlinkcheck_set,
4269                 (void *)&cmd_setlinkcheck_link_check,
4270                 (void *)&cmd_setlinkcheck_mode,
4271                 NULL,
4272         },
4273 };
4274
4275 /* *** SET NIC BYPASS MODE *** */
4276 struct cmd_set_bypass_mode_result {
4277         cmdline_fixed_string_t set;
4278         cmdline_fixed_string_t bypass;
4279         cmdline_fixed_string_t mode;
4280         cmdline_fixed_string_t value;
4281         uint8_t port_id;
4282 };
4283
4284 static void
4285 cmd_set_bypass_mode_parsed(void *parsed_result,
4286                 __attribute__((unused)) struct cmdline *cl,
4287                 __attribute__((unused)) void *data)
4288 {
4289         struct cmd_set_bypass_mode_result *res = parsed_result;
4290         portid_t port_id = res->port_id;
4291         int32_t rc = -EINVAL;
4292
4293 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4294         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4295
4296         if (!strcmp(res->value, "bypass"))
4297                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4298         else if (!strcmp(res->value, "isolate"))
4299                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4300         else
4301                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4302
4303         /* Set the bypass mode for the relevant port. */
4304         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4305 #endif
4306         if (rc != 0)
4307                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4308 }
4309
4310 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4311         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4312                         set, "set");
4313 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4314         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4315                         bypass, "bypass");
4316 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4317         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4318                         mode, "mode");
4319 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4320         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4321                         value, "normal#bypass#isolate");
4322 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4323         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4324                                 port_id, UINT8);
4325
4326 cmdline_parse_inst_t cmd_set_bypass_mode = {
4327         .f = cmd_set_bypass_mode_parsed,
4328         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4329                     "Set the NIC bypass mode for port_id",
4330         .data = NULL,
4331         .tokens = {
4332                 (void *)&cmd_setbypass_mode_set,
4333                 (void *)&cmd_setbypass_mode_bypass,
4334                 (void *)&cmd_setbypass_mode_mode,
4335                 (void *)&cmd_setbypass_mode_value,
4336                 (void *)&cmd_setbypass_mode_port,
4337                 NULL,
4338         },
4339 };
4340
4341 /* *** SET NIC BYPASS EVENT *** */
4342 struct cmd_set_bypass_event_result {
4343         cmdline_fixed_string_t set;
4344         cmdline_fixed_string_t bypass;
4345         cmdline_fixed_string_t event;
4346         cmdline_fixed_string_t event_value;
4347         cmdline_fixed_string_t mode;
4348         cmdline_fixed_string_t mode_value;
4349         uint8_t port_id;
4350 };
4351
4352 static void
4353 cmd_set_bypass_event_parsed(void *parsed_result,
4354                 __attribute__((unused)) struct cmdline *cl,
4355                 __attribute__((unused)) void *data)
4356 {
4357         int32_t rc = -EINVAL;
4358         struct cmd_set_bypass_event_result *res = parsed_result;
4359         portid_t port_id = res->port_id;
4360
4361 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4362         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4363         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4364
4365         if (!strcmp(res->event_value, "timeout"))
4366                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4367         else if (!strcmp(res->event_value, "os_on"))
4368                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4369         else if (!strcmp(res->event_value, "os_off"))
4370                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4371         else if (!strcmp(res->event_value, "power_on"))
4372                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4373         else if (!strcmp(res->event_value, "power_off"))
4374                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4375         else
4376                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4377
4378         if (!strcmp(res->mode_value, "bypass"))
4379                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4380         else if (!strcmp(res->mode_value, "isolate"))
4381                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4382         else
4383                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4384
4385         /* Set the watchdog timeout. */
4386         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4387
4388                 rc = -EINVAL;
4389                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4390                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4391                                                            bypass_timeout);
4392                 }
4393                 if (rc != 0) {
4394                         printf("Failed to set timeout value %u "
4395                         "for port %d, errto code: %d.\n",
4396                         bypass_timeout, port_id, rc);
4397                 }
4398         }
4399
4400         /* Set the bypass event to transition to bypass mode. */
4401         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4402                                               bypass_mode);
4403 #endif
4404
4405         if (rc != 0)
4406                 printf("\t Failed to set bypass event for port = %d.\n",
4407                        port_id);
4408 }
4409
4410 cmdline_parse_token_string_t cmd_setbypass_event_set =
4411         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4412                         set, "set");
4413 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4414         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4415                         bypass, "bypass");
4416 cmdline_parse_token_string_t cmd_setbypass_event_event =
4417         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4418                         event, "event");
4419 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4420         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4421                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4422 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4423         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4424                         mode, "mode");
4425 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4426         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4427                         mode_value, "normal#bypass#isolate");
4428 cmdline_parse_token_num_t cmd_setbypass_event_port =
4429         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4430                                 port_id, UINT8);
4431
4432 cmdline_parse_inst_t cmd_set_bypass_event = {
4433         .f = cmd_set_bypass_event_parsed,
4434         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4435                 "power_off mode normal|bypass|isolate <port_id>: "
4436                 "Set the NIC bypass event mode for port_id",
4437         .data = NULL,
4438         .tokens = {
4439                 (void *)&cmd_setbypass_event_set,
4440                 (void *)&cmd_setbypass_event_bypass,
4441                 (void *)&cmd_setbypass_event_event,
4442                 (void *)&cmd_setbypass_event_event_value,
4443                 (void *)&cmd_setbypass_event_mode,
4444                 (void *)&cmd_setbypass_event_mode_value,
4445                 (void *)&cmd_setbypass_event_port,
4446                 NULL,
4447         },
4448 };
4449
4450
4451 /* *** SET NIC BYPASS TIMEOUT *** */
4452 struct cmd_set_bypass_timeout_result {
4453         cmdline_fixed_string_t set;
4454         cmdline_fixed_string_t bypass;
4455         cmdline_fixed_string_t timeout;
4456         cmdline_fixed_string_t value;
4457 };
4458
4459 static void
4460 cmd_set_bypass_timeout_parsed(void *parsed_result,
4461                 __attribute__((unused)) struct cmdline *cl,
4462                 __attribute__((unused)) void *data)
4463 {
4464         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4465
4466 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4467         if (!strcmp(res->value, "1.5"))
4468                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4469         else if (!strcmp(res->value, "2"))
4470                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4471         else if (!strcmp(res->value, "3"))
4472                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4473         else if (!strcmp(res->value, "4"))
4474                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4475         else if (!strcmp(res->value, "8"))
4476                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4477         else if (!strcmp(res->value, "16"))
4478                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4479         else if (!strcmp(res->value, "32"))
4480                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4481         else
4482                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4483 #endif
4484 }
4485
4486 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4487         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4488                         set, "set");
4489 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4490         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4491                         bypass, "bypass");
4492 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4493         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4494                         timeout, "timeout");
4495 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4496         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4497                         value, "0#1.5#2#3#4#8#16#32");
4498
4499 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4500         .f = cmd_set_bypass_timeout_parsed,
4501         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4502                 "Set the NIC bypass watchdog timeout in seconds",
4503         .data = NULL,
4504         .tokens = {
4505                 (void *)&cmd_setbypass_timeout_set,
4506                 (void *)&cmd_setbypass_timeout_bypass,
4507                 (void *)&cmd_setbypass_timeout_timeout,
4508                 (void *)&cmd_setbypass_timeout_value,
4509                 NULL,
4510         },
4511 };
4512
4513 /* *** SHOW NIC BYPASS MODE *** */
4514 struct cmd_show_bypass_config_result {
4515         cmdline_fixed_string_t show;
4516         cmdline_fixed_string_t bypass;
4517         cmdline_fixed_string_t config;
4518         uint8_t port_id;
4519 };
4520
4521 static void
4522 cmd_show_bypass_config_parsed(void *parsed_result,
4523                 __attribute__((unused)) struct cmdline *cl,
4524                 __attribute__((unused)) void *data)
4525 {
4526         struct cmd_show_bypass_config_result *res = parsed_result;
4527         portid_t port_id = res->port_id;
4528         int rc = -EINVAL;
4529 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4530         uint32_t event_mode;
4531         uint32_t bypass_mode;
4532         uint32_t timeout = bypass_timeout;
4533         int i;
4534
4535         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4536                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4537         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4538                 {"UNKNOWN", "normal", "bypass", "isolate"};
4539         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4540                 "NONE",
4541                 "OS/board on",
4542                 "power supply on",
4543                 "OS/board off",
4544                 "power supply off",
4545                 "timeout"};
4546         int num_events = (sizeof events) / (sizeof events[0]);
4547
4548         /* Display the bypass mode.*/
4549         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4550                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4551                 return;
4552         }
4553         else {
4554                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4555                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4556
4557                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4558         }
4559
4560         /* Display the bypass timeout.*/
4561         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4562                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4563
4564         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4565
4566         /* Display the bypass events and associated modes. */
4567         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4568
4569                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4570                         printf("\tFailed to get bypass mode for event = %s\n",
4571                                 events[i]);
4572                 } else {
4573                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4574                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4575
4576                         printf("\tbypass event: %-16s = %s\n", events[i],
4577                                 modes[event_mode]);
4578                 }
4579         }
4580 #endif
4581         if (rc != 0)
4582                 printf("\tFailed to get bypass configuration for port = %d\n",
4583                        port_id);
4584 }
4585
4586 cmdline_parse_token_string_t cmd_showbypass_config_show =
4587         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4588                         show, "show");
4589 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4590         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4591                         bypass, "bypass");
4592 cmdline_parse_token_string_t cmd_showbypass_config_config =
4593         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4594                         config, "config");
4595 cmdline_parse_token_num_t cmd_showbypass_config_port =
4596         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4597                                 port_id, UINT8);
4598
4599 cmdline_parse_inst_t cmd_show_bypass_config = {
4600         .f = cmd_show_bypass_config_parsed,
4601         .help_str = "show bypass config <port_id>: "
4602                     "Show the NIC bypass config for port_id",
4603         .data = NULL,
4604         .tokens = {
4605                 (void *)&cmd_showbypass_config_show,
4606                 (void *)&cmd_showbypass_config_bypass,
4607                 (void *)&cmd_showbypass_config_config,
4608                 (void *)&cmd_showbypass_config_port,
4609                 NULL,
4610         },
4611 };
4612
4613 #ifdef RTE_LIBRTE_PMD_BOND
4614 /* *** SET BONDING MODE *** */
4615 struct cmd_set_bonding_mode_result {
4616         cmdline_fixed_string_t set;
4617         cmdline_fixed_string_t bonding;
4618         cmdline_fixed_string_t mode;
4619         uint8_t value;
4620         uint8_t port_id;
4621 };
4622
4623 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4624                 __attribute__((unused))  struct cmdline *cl,
4625                 __attribute__((unused)) void *data)
4626 {
4627         struct cmd_set_bonding_mode_result *res = parsed_result;
4628         portid_t port_id = res->port_id;
4629
4630         /* Set the bonding mode for the relevant port. */
4631         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4632                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4633 }
4634
4635 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4636 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4637                 set, "set");
4638 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4639 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4640                 bonding, "bonding");
4641 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4642 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4643                 mode, "mode");
4644 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4645 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4646                 value, UINT8);
4647 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4648 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4649                 port_id, UINT8);
4650
4651 cmdline_parse_inst_t cmd_set_bonding_mode = {
4652                 .f = cmd_set_bonding_mode_parsed,
4653                 .help_str = "set bonding mode <mode_value> <port_id>: "
4654                         "Set the bonding mode for port_id",
4655                 .data = NULL,
4656                 .tokens = {
4657                                 (void *) &cmd_setbonding_mode_set,
4658                                 (void *) &cmd_setbonding_mode_bonding,
4659                                 (void *) &cmd_setbonding_mode_mode,
4660                                 (void *) &cmd_setbonding_mode_value,
4661                                 (void *) &cmd_setbonding_mode_port,
4662                                 NULL
4663                 }
4664 };
4665
4666 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4667 struct cmd_set_bonding_lacp_dedicated_queues_result {
4668         cmdline_fixed_string_t set;
4669         cmdline_fixed_string_t bonding;
4670         cmdline_fixed_string_t lacp;
4671         cmdline_fixed_string_t dedicated_queues;
4672         uint8_t port_id;
4673         cmdline_fixed_string_t mode;
4674 };
4675
4676 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4677                 __attribute__((unused))  struct cmdline *cl,
4678                 __attribute__((unused)) void *data)
4679 {
4680         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4681         portid_t port_id = res->port_id;
4682         struct rte_port *port;
4683
4684         port = &ports[port_id];
4685
4686         /** Check if the port is not started **/
4687         if (port->port_status != RTE_PORT_STOPPED) {
4688                 printf("Please stop port %d first\n", port_id);
4689                 return;
4690         }
4691
4692         if (!strcmp(res->mode, "enable")) {
4693                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4694                         printf("Dedicate queues for LACP control packets"
4695                                         " enabled\n");
4696                 else
4697                         printf("Enabling dedicate queues for LACP control "
4698                                         "packets on port %d failed\n", port_id);
4699         } else if (!strcmp(res->mode, "disable")) {
4700                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4701                         printf("Dedicated queues for LACP control packets "
4702                                         "disabled\n");
4703                 else
4704                         printf("Disabling dedicated queues for LACP control "
4705                                         "traffic on port %d failed\n", port_id);
4706         }
4707 }
4708
4709 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4710 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4711                 set, "set");
4712 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4713 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4714                 bonding, "bonding");
4715 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4716 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4717                 lacp, "lacp");
4718 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4719 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4720                 dedicated_queues, "dedicated_queues");
4721 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4722 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4723                 port_id, UINT8);
4724 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4725 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4726                 mode, "enable#disable");
4727
4728 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4729                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4730                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4731                         "enable|disable: "
4732                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4733                 .data = NULL,
4734                 .tokens = {
4735                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4736                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4737                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4738                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4739                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4740                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4741                         NULL
4742                 }
4743 };
4744
4745 /* *** SET BALANCE XMIT POLICY *** */
4746 struct cmd_set_bonding_balance_xmit_policy_result {
4747         cmdline_fixed_string_t set;
4748         cmdline_fixed_string_t bonding;
4749         cmdline_fixed_string_t balance_xmit_policy;
4750         uint8_t port_id;
4751         cmdline_fixed_string_t policy;
4752 };
4753
4754 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4755                 __attribute__((unused))  struct cmdline *cl,
4756                 __attribute__((unused)) void *data)
4757 {
4758         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4759         portid_t port_id = res->port_id;
4760         uint8_t policy;
4761
4762         if (!strcmp(res->policy, "l2")) {
4763                 policy = BALANCE_XMIT_POLICY_LAYER2;
4764         } else if (!strcmp(res->policy, "l23")) {
4765                 policy = BALANCE_XMIT_POLICY_LAYER23;
4766         } else if (!strcmp(res->policy, "l34")) {
4767                 policy = BALANCE_XMIT_POLICY_LAYER34;
4768         } else {
4769                 printf("\t Invalid xmit policy selection");
4770                 return;
4771         }
4772
4773         /* Set the bonding mode for the relevant port. */
4774         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4775                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4776                                 port_id);
4777         }
4778 }
4779
4780 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4781 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4782                 set, "set");
4783 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4784 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4785                 bonding, "bonding");
4786 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4787 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4788                 balance_xmit_policy, "balance_xmit_policy");
4789 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4790 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4791                 port_id, UINT8);
4792 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4793 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4794                 policy, "l2#l23#l34");
4795
4796 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4797                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4798                 .help_str = "set bonding balance_xmit_policy <port_id> "
4799                         "l2|l23|l34: "
4800                         "Set the bonding balance_xmit_policy for port_id",
4801                 .data = NULL,
4802                 .tokens = {
4803                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4804                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4805                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4806                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4807                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4808                                 NULL
4809                 }
4810 };
4811
4812 /* *** SHOW NIC BONDING CONFIGURATION *** */
4813 struct cmd_show_bonding_config_result {
4814         cmdline_fixed_string_t show;
4815         cmdline_fixed_string_t bonding;
4816         cmdline_fixed_string_t config;
4817         portid_t port_id;
4818 };
4819
4820 static void cmd_show_bonding_config_parsed(void *parsed_result,
4821                 __attribute__((unused))  struct cmdline *cl,
4822                 __attribute__((unused)) void *data)
4823 {
4824         struct cmd_show_bonding_config_result *res = parsed_result;
4825         int bonding_mode, agg_mode;
4826         portid_t slaves[RTE_MAX_ETHPORTS];
4827         int num_slaves, num_active_slaves;
4828         int primary_id;
4829         int i;
4830         portid_t port_id = res->port_id;
4831
4832         /* Display the bonding mode.*/
4833         bonding_mode = rte_eth_bond_mode_get(port_id);
4834         if (bonding_mode < 0) {
4835                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4836                 return;
4837         } else
4838                 printf("\tBonding mode: %d\n", bonding_mode);
4839
4840         if (bonding_mode == BONDING_MODE_BALANCE) {
4841                 int balance_xmit_policy;
4842
4843                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4844                 if (balance_xmit_policy < 0) {
4845                         printf("\tFailed to get balance xmit policy for port = %d\n",
4846                                         port_id);
4847                         return;
4848                 } else {
4849                         printf("\tBalance Xmit Policy: ");
4850
4851                         switch (balance_xmit_policy) {
4852                         case BALANCE_XMIT_POLICY_LAYER2:
4853                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4854                                 break;
4855                         case BALANCE_XMIT_POLICY_LAYER23:
4856                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4857                                 break;
4858                         case BALANCE_XMIT_POLICY_LAYER34:
4859                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4860                                 break;
4861                         }
4862                         printf("\n");
4863                 }
4864         }
4865
4866         if (bonding_mode == BONDING_MODE_8023AD) {
4867                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4868                 printf("\tIEEE802.3AD Aggregator Mode: ");
4869                 switch (agg_mode) {
4870                 case AGG_BANDWIDTH:
4871                         printf("bandwidth");
4872                         break;
4873                 case AGG_STABLE:
4874                         printf("stable");
4875                         break;
4876                 case AGG_COUNT:
4877                         printf("count");
4878                         break;
4879                 }
4880                 printf("\n");
4881         }
4882
4883         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4884
4885         if (num_slaves < 0) {
4886                 printf("\tFailed to get slave list for port = %d\n", port_id);
4887                 return;
4888         }
4889         if (num_slaves > 0) {
4890                 printf("\tSlaves (%d): [", num_slaves);
4891                 for (i = 0; i < num_slaves - 1; i++)
4892                         printf("%d ", slaves[i]);
4893
4894                 printf("%d]\n", slaves[num_slaves - 1]);
4895         } else {
4896                 printf("\tSlaves: []\n");
4897
4898         }
4899
4900         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4901                         RTE_MAX_ETHPORTS);
4902
4903         if (num_active_slaves < 0) {
4904                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4905                 return;
4906         }
4907         if (num_active_slaves > 0) {
4908                 printf("\tActive Slaves (%d): [", num_active_slaves);
4909                 for (i = 0; i < num_active_slaves - 1; i++)
4910                         printf("%d ", slaves[i]);
4911
4912                 printf("%d]\n", slaves[num_active_slaves - 1]);
4913
4914         } else {
4915                 printf("\tActive Slaves: []\n");
4916
4917         }
4918
4919         primary_id = rte_eth_bond_primary_get(port_id);
4920         if (primary_id < 0) {
4921                 printf("\tFailed to get primary slave for port = %d\n", port_id);
4922                 return;
4923         } else
4924                 printf("\tPrimary: [%d]\n", primary_id);
4925
4926 }
4927
4928 cmdline_parse_token_string_t cmd_showbonding_config_show =
4929 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4930                 show, "show");
4931 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4932 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4933                 bonding, "bonding");
4934 cmdline_parse_token_string_t cmd_showbonding_config_config =
4935 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4936                 config, "config");
4937 cmdline_parse_token_num_t cmd_showbonding_config_port =
4938 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4939                 port_id, UINT8);
4940
4941 cmdline_parse_inst_t cmd_show_bonding_config = {
4942                 .f = cmd_show_bonding_config_parsed,
4943                 .help_str = "show bonding config <port_id>: "
4944                         "Show the bonding config for port_id",
4945                 .data = NULL,
4946                 .tokens = {
4947                                 (void *)&cmd_showbonding_config_show,
4948                                 (void *)&cmd_showbonding_config_bonding,
4949                                 (void *)&cmd_showbonding_config_config,
4950                                 (void *)&cmd_showbonding_config_port,
4951                                 NULL
4952                 }
4953 };
4954
4955 /* *** SET BONDING PRIMARY *** */
4956 struct cmd_set_bonding_primary_result {
4957         cmdline_fixed_string_t set;
4958         cmdline_fixed_string_t bonding;
4959         cmdline_fixed_string_t primary;
4960         uint8_t slave_id;
4961         uint8_t port_id;
4962 };
4963
4964 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4965                 __attribute__((unused))  struct cmdline *cl,
4966                 __attribute__((unused)) void *data)
4967 {
4968         struct cmd_set_bonding_primary_result *res = parsed_result;
4969         portid_t master_port_id = res->port_id;
4970         portid_t slave_port_id = res->slave_id;
4971
4972         /* Set the primary slave for a bonded device. */
4973         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4974                 printf("\t Failed to set primary slave for port = %d.\n",
4975                                 master_port_id);
4976                 return;
4977         }
4978         init_port_config();
4979 }
4980
4981 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4982 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4983                 set, "set");
4984 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4985 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4986                 bonding, "bonding");
4987 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4988 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4989                 primary, "primary");
4990 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4991 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4992                 slave_id, UINT8);
4993 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4994 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4995                 port_id, UINT8);
4996
4997 cmdline_parse_inst_t cmd_set_bonding_primary = {
4998                 .f = cmd_set_bonding_primary_parsed,
4999                 .help_str = "set bonding primary <slave_id> <port_id>: "
5000                         "Set the primary slave for port_id",
5001                 .data = NULL,
5002                 .tokens = {
5003                                 (void *)&cmd_setbonding_primary_set,
5004                                 (void *)&cmd_setbonding_primary_bonding,
5005                                 (void *)&cmd_setbonding_primary_primary,
5006                                 (void *)&cmd_setbonding_primary_slave,
5007                                 (void *)&cmd_setbonding_primary_port,
5008                                 NULL
5009                 }
5010 };
5011
5012 /* *** ADD SLAVE *** */
5013 struct cmd_add_bonding_slave_result {
5014         cmdline_fixed_string_t add;
5015         cmdline_fixed_string_t bonding;
5016         cmdline_fixed_string_t slave;
5017         uint8_t slave_id;
5018         uint8_t port_id;
5019 };
5020
5021 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5022                 __attribute__((unused))  struct cmdline *cl,
5023                 __attribute__((unused)) void *data)
5024 {
5025         struct cmd_add_bonding_slave_result *res = parsed_result;
5026         portid_t master_port_id = res->port_id;
5027         portid_t slave_port_id = res->slave_id;
5028
5029         /* add the slave for a bonded device. */
5030         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5031                 printf("\t Failed to add slave %d to master port = %d.\n",
5032                                 slave_port_id, master_port_id);
5033                 return;
5034         }
5035         init_port_config();
5036         set_port_slave_flag(slave_port_id);
5037 }
5038
5039 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5040 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5041                 add, "add");
5042 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5043 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5044                 bonding, "bonding");
5045 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5046 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5047                 slave, "slave");
5048 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5049 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5050                 slave_id, UINT8);
5051 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5052 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5053                 port_id, UINT8);
5054
5055 cmdline_parse_inst_t cmd_add_bonding_slave = {
5056                 .f = cmd_add_bonding_slave_parsed,
5057                 .help_str = "add bonding slave <slave_id> <port_id>: "
5058                         "Add a slave device to a bonded device",
5059                 .data = NULL,
5060                 .tokens = {
5061                                 (void *)&cmd_addbonding_slave_add,
5062                                 (void *)&cmd_addbonding_slave_bonding,
5063                                 (void *)&cmd_addbonding_slave_slave,
5064                                 (void *)&cmd_addbonding_slave_slaveid,
5065                                 (void *)&cmd_addbonding_slave_port,
5066                                 NULL
5067                 }
5068 };
5069
5070 /* *** REMOVE SLAVE *** */
5071 struct cmd_remove_bonding_slave_result {
5072         cmdline_fixed_string_t remove;
5073         cmdline_fixed_string_t bonding;
5074         cmdline_fixed_string_t slave;
5075         uint8_t slave_id;
5076         uint8_t port_id;
5077 };
5078
5079 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5080                 __attribute__((unused))  struct cmdline *cl,
5081                 __attribute__((unused)) void *data)
5082 {
5083         struct cmd_remove_bonding_slave_result *res = parsed_result;
5084         portid_t master_port_id = res->port_id;
5085         portid_t slave_port_id = res->slave_id;
5086
5087         /* remove the slave from a bonded device. */
5088         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5089                 printf("\t Failed to remove slave %d from master port = %d.\n",
5090                                 slave_port_id, master_port_id);
5091                 return;
5092         }
5093         init_port_config();
5094         clear_port_slave_flag(slave_port_id);
5095 }
5096
5097 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5098                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5099                                 remove, "remove");
5100 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5101                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5102                                 bonding, "bonding");
5103 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5104                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5105                                 slave, "slave");
5106 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5107                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5108                                 slave_id, UINT8);
5109 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5110                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5111                                 port_id, UINT8);
5112
5113 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5114                 .f = cmd_remove_bonding_slave_parsed,
5115                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5116                         "Remove a slave device from a bonded device",
5117                 .data = NULL,
5118                 .tokens = {
5119                                 (void *)&cmd_removebonding_slave_remove,
5120                                 (void *)&cmd_removebonding_slave_bonding,
5121                                 (void *)&cmd_removebonding_slave_slave,
5122                                 (void *)&cmd_removebonding_slave_slaveid,
5123                                 (void *)&cmd_removebonding_slave_port,
5124                                 NULL
5125                 }
5126 };
5127
5128 /* *** CREATE BONDED DEVICE *** */
5129 struct cmd_create_bonded_device_result {
5130         cmdline_fixed_string_t create;
5131         cmdline_fixed_string_t bonded;
5132         cmdline_fixed_string_t device;
5133         uint8_t mode;
5134         uint8_t socket;
5135 };
5136
5137 static int bond_dev_num = 0;
5138
5139 static void cmd_create_bonded_device_parsed(void *parsed_result,
5140                 __attribute__((unused))  struct cmdline *cl,
5141                 __attribute__((unused)) void *data)
5142 {
5143         struct cmd_create_bonded_device_result *res = parsed_result;
5144         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5145         int port_id;
5146
5147         if (test_done == 0) {
5148                 printf("Please stop forwarding first\n");
5149                 return;
5150         }
5151
5152         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5153                         bond_dev_num++);
5154
5155         /* Create a new bonded device. */
5156         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5157         if (port_id < 0) {
5158                 printf("\t Failed to create bonded device.\n");
5159                 return;
5160         } else {
5161                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5162                                 port_id);
5163
5164                 /* Update number of ports */
5165                 nb_ports = rte_eth_dev_count();
5166                 reconfig(port_id, res->socket);
5167                 rte_eth_promiscuous_enable(port_id);
5168         }
5169
5170 }
5171
5172 cmdline_parse_token_string_t cmd_createbonded_device_create =
5173                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5174                                 create, "create");
5175 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5176                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5177                                 bonded, "bonded");
5178 cmdline_parse_token_string_t cmd_createbonded_device_device =
5179                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5180                                 device, "device");
5181 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5182                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5183                                 mode, UINT8);
5184 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5185                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5186                                 socket, UINT8);
5187
5188 cmdline_parse_inst_t cmd_create_bonded_device = {
5189                 .f = cmd_create_bonded_device_parsed,
5190                 .help_str = "create bonded device <mode> <socket>: "
5191                         "Create a new bonded device with specific bonding mode and socket",
5192                 .data = NULL,
5193                 .tokens = {
5194                                 (void *)&cmd_createbonded_device_create,
5195                                 (void *)&cmd_createbonded_device_bonded,
5196                                 (void *)&cmd_createbonded_device_device,
5197                                 (void *)&cmd_createbonded_device_mode,
5198                                 (void *)&cmd_createbonded_device_socket,
5199                                 NULL
5200                 }
5201 };
5202
5203 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5204 struct cmd_set_bond_mac_addr_result {
5205         cmdline_fixed_string_t set;
5206         cmdline_fixed_string_t bonding;
5207         cmdline_fixed_string_t mac_addr;
5208         uint8_t port_num;
5209         struct ether_addr address;
5210 };
5211
5212 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5213                 __attribute__((unused))  struct cmdline *cl,
5214                 __attribute__((unused)) void *data)
5215 {
5216         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5217         int ret;
5218
5219         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5220                 return;
5221
5222         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5223
5224         /* check the return value and print it if is < 0 */
5225         if (ret < 0)
5226                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5227 }
5228
5229 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5230                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5231 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5232                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5233                                 "bonding");
5234 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5235                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5236                                 "mac_addr");
5237 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5238                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
5239 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5240                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5241
5242 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5243                 .f = cmd_set_bond_mac_addr_parsed,
5244                 .data = (void *) 0,
5245                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5246                 .tokens = {
5247                                 (void *)&cmd_set_bond_mac_addr_set,
5248                                 (void *)&cmd_set_bond_mac_addr_bonding,
5249                                 (void *)&cmd_set_bond_mac_addr_mac,
5250                                 (void *)&cmd_set_bond_mac_addr_portnum,
5251                                 (void *)&cmd_set_bond_mac_addr_addr,
5252                                 NULL
5253                 }
5254 };
5255
5256
5257 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5258 struct cmd_set_bond_mon_period_result {
5259         cmdline_fixed_string_t set;
5260         cmdline_fixed_string_t bonding;
5261         cmdline_fixed_string_t mon_period;
5262         uint8_t port_num;
5263         uint32_t period_ms;
5264 };
5265
5266 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5267                 __attribute__((unused))  struct cmdline *cl,
5268                 __attribute__((unused)) void *data)
5269 {
5270         struct cmd_set_bond_mon_period_result *res = parsed_result;
5271         int ret;
5272
5273         if (res->port_num >= nb_ports) {
5274                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5275                 return;
5276         }
5277
5278         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5279
5280         /* check the return value and print it if is < 0 */
5281         if (ret < 0)
5282                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5283 }
5284
5285 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5286                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5287                                 set, "set");
5288 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5289                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5290                                 bonding, "bonding");
5291 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5292                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5293                                 mon_period,     "mon_period");
5294 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5295                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5296                                 port_num, UINT8);
5297 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5298                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5299                                 period_ms, UINT32);
5300
5301 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5302                 .f = cmd_set_bond_mon_period_parsed,
5303                 .data = (void *) 0,
5304                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5305                 .tokens = {
5306                                 (void *)&cmd_set_bond_mon_period_set,
5307                                 (void *)&cmd_set_bond_mon_period_bonding,
5308                                 (void *)&cmd_set_bond_mon_period_mon_period,
5309                                 (void *)&cmd_set_bond_mon_period_portnum,
5310                                 (void *)&cmd_set_bond_mon_period_period_ms,
5311                                 NULL
5312                 }
5313 };
5314
5315
5316
5317 struct cmd_set_bonding_agg_mode_policy_result {
5318         cmdline_fixed_string_t set;
5319         cmdline_fixed_string_t bonding;
5320         cmdline_fixed_string_t agg_mode;
5321         uint8_t port_num;
5322         cmdline_fixed_string_t policy;
5323 };
5324
5325
5326 static void
5327 cmd_set_bonding_agg_mode(void *parsed_result,
5328                 __attribute__((unused)) struct cmdline *cl,
5329                 __attribute__((unused)) void *data)
5330 {
5331         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5332         uint8_t policy = AGG_BANDWIDTH;
5333
5334         if (res->port_num >= nb_ports) {
5335                 printf("Port id %d must be less than %d\n",
5336                                 res->port_num, nb_ports);
5337                 return;
5338         }
5339
5340         if (!strcmp(res->policy, "bandwidth"))
5341                 policy = AGG_BANDWIDTH;
5342         else if (!strcmp(res->policy, "stable"))
5343                 policy = AGG_STABLE;
5344         else if (!strcmp(res->policy, "count"))
5345                 policy = AGG_COUNT;
5346
5347         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5348 }
5349
5350
5351 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5352         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5353                                 set, "set");
5354 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5355         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5356                                 bonding, "bonding");
5357
5358 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5359         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5360                                 agg_mode, "agg_mode");
5361
5362 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5363         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5364                                 port_num, UINT8);
5365
5366 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5367         TOKEN_STRING_INITIALIZER(
5368                         struct cmd_set_bonding_balance_xmit_policy_result,
5369                 policy, "stable#bandwidth#count");
5370
5371 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5372         .f = cmd_set_bonding_agg_mode,
5373         .data = (void *) 0,
5374         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5375         .tokens = {
5376                         (void *)&cmd_set_bonding_agg_mode_set,
5377                         (void *)&cmd_set_bonding_agg_mode_bonding,
5378                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5379                         (void *)&cmd_set_bonding_agg_mode_portnum,
5380                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5381                         NULL
5382                 }
5383 };
5384
5385
5386 #endif /* RTE_LIBRTE_PMD_BOND */
5387
5388 /* *** SET FORWARDING MODE *** */
5389 struct cmd_set_fwd_mode_result {
5390         cmdline_fixed_string_t set;
5391         cmdline_fixed_string_t fwd;
5392         cmdline_fixed_string_t mode;
5393 };
5394
5395 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5396                                     __attribute__((unused)) struct cmdline *cl,
5397                                     __attribute__((unused)) void *data)
5398 {
5399         struct cmd_set_fwd_mode_result *res = parsed_result;
5400
5401         retry_enabled = 0;
5402         set_pkt_forwarding_mode(res->mode);
5403 }
5404
5405 cmdline_parse_token_string_t cmd_setfwd_set =
5406         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5407 cmdline_parse_token_string_t cmd_setfwd_fwd =
5408         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5409 cmdline_parse_token_string_t cmd_setfwd_mode =
5410         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5411                 "" /* defined at init */);
5412
5413 cmdline_parse_inst_t cmd_set_fwd_mode = {
5414         .f = cmd_set_fwd_mode_parsed,
5415         .data = NULL,
5416         .help_str = NULL, /* defined at init */
5417         .tokens = {
5418                 (void *)&cmd_setfwd_set,
5419                 (void *)&cmd_setfwd_fwd,
5420                 (void *)&cmd_setfwd_mode,
5421                 NULL,
5422         },
5423 };
5424
5425 static void cmd_set_fwd_mode_init(void)
5426 {
5427         char *modes, *c;
5428         static char token[128];
5429         static char help[256];
5430         cmdline_parse_token_string_t *token_struct;
5431
5432         modes = list_pkt_forwarding_modes();
5433         snprintf(help, sizeof(help), "set fwd %s: "
5434                 "Set packet forwarding mode", modes);
5435         cmd_set_fwd_mode.help_str = help;
5436
5437         /* string token separator is # */
5438         for (c = token; *modes != '\0'; modes++)
5439                 if (*modes == '|')
5440                         *c++ = '#';
5441                 else
5442                         *c++ = *modes;
5443         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5444         token_struct->string_data.str = token;
5445 }
5446
5447 /* *** SET RETRY FORWARDING MODE *** */
5448 struct cmd_set_fwd_retry_mode_result {
5449         cmdline_fixed_string_t set;
5450         cmdline_fixed_string_t fwd;
5451         cmdline_fixed_string_t mode;
5452         cmdline_fixed_string_t retry;
5453 };
5454
5455 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5456                             __attribute__((unused)) struct cmdline *cl,
5457                             __attribute__((unused)) void *data)
5458 {
5459         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5460
5461         retry_enabled = 1;
5462         set_pkt_forwarding_mode(res->mode);
5463 }
5464
5465 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5466         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5467                         set, "set");
5468 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5469         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5470                         fwd, "fwd");
5471 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5472         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5473                         mode,
5474                 "" /* defined at init */);
5475 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5476         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5477                         retry, "retry");
5478
5479 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5480         .f = cmd_set_fwd_retry_mode_parsed,
5481         .data = NULL,
5482         .help_str = NULL, /* defined at init */
5483         .tokens = {
5484                 (void *)&cmd_setfwd_retry_set,
5485                 (void *)&cmd_setfwd_retry_fwd,
5486                 (void *)&cmd_setfwd_retry_mode,
5487                 (void *)&cmd_setfwd_retry_retry,
5488                 NULL,
5489         },
5490 };
5491
5492 static void cmd_set_fwd_retry_mode_init(void)
5493 {
5494         char *modes, *c;
5495         static char token[128];
5496         static char help[256];
5497         cmdline_parse_token_string_t *token_struct;
5498
5499         modes = list_pkt_forwarding_retry_modes();
5500         snprintf(help, sizeof(help), "set fwd %s retry: "
5501                 "Set packet forwarding mode with retry", modes);
5502         cmd_set_fwd_retry_mode.help_str = help;
5503
5504         /* string token separator is # */
5505         for (c = token; *modes != '\0'; modes++)
5506                 if (*modes == '|')
5507                         *c++ = '#';
5508                 else
5509                         *c++ = *modes;
5510         token_struct = (cmdline_parse_token_string_t *)
5511                 cmd_set_fwd_retry_mode.tokens[2];
5512         token_struct->string_data.str = token;
5513 }
5514
5515 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5516 struct cmd_set_burst_tx_retry_result {
5517         cmdline_fixed_string_t set;
5518         cmdline_fixed_string_t burst;
5519         cmdline_fixed_string_t tx;
5520         cmdline_fixed_string_t delay;
5521         uint32_t time;
5522         cmdline_fixed_string_t retry;
5523         uint32_t retry_num;
5524 };
5525
5526 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5527                                         __attribute__((unused)) struct cmdline *cl,
5528                                         __attribute__((unused)) void *data)
5529 {
5530         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5531
5532         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5533                 && !strcmp(res->tx, "tx")) {
5534                 if (!strcmp(res->delay, "delay"))
5535                         burst_tx_delay_time = res->time;
5536                 if (!strcmp(res->retry, "retry"))
5537                         burst_tx_retry_num = res->retry_num;
5538         }
5539
5540 }
5541
5542 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5543         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5544 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5545         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5546                                  "burst");
5547 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5548         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5549 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5550         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5551 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5552         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5553 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5554         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5555 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5556         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5557
5558 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5559         .f = cmd_set_burst_tx_retry_parsed,
5560         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5561         .tokens = {
5562                 (void *)&cmd_set_burst_tx_retry_set,
5563                 (void *)&cmd_set_burst_tx_retry_burst,
5564                 (void *)&cmd_set_burst_tx_retry_tx,
5565                 (void *)&cmd_set_burst_tx_retry_delay,
5566                 (void *)&cmd_set_burst_tx_retry_time,
5567                 (void *)&cmd_set_burst_tx_retry_retry,
5568                 (void *)&cmd_set_burst_tx_retry_retry_num,
5569                 NULL,
5570         },
5571 };
5572
5573 /* *** SET PROMISC MODE *** */
5574 struct cmd_set_promisc_mode_result {
5575         cmdline_fixed_string_t set;
5576         cmdline_fixed_string_t promisc;
5577         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5578         uint8_t port_num;                /* valid if "allports" argument == 0 */
5579         cmdline_fixed_string_t mode;
5580 };
5581
5582 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5583                                         __attribute__((unused)) struct cmdline *cl,
5584                                         void *allports)
5585 {
5586         struct cmd_set_promisc_mode_result *res = parsed_result;
5587         int enable;
5588         portid_t i;
5589
5590         if (!strcmp(res->mode, "on"))
5591                 enable = 1;
5592         else
5593                 enable = 0;
5594
5595         /* all ports */
5596         if (allports) {
5597                 RTE_ETH_FOREACH_DEV(i) {
5598                         if (enable)
5599                                 rte_eth_promiscuous_enable(i);
5600                         else
5601                                 rte_eth_promiscuous_disable(i);
5602                 }
5603         }
5604         else {
5605                 if (enable)
5606                         rte_eth_promiscuous_enable(res->port_num);
5607                 else
5608                         rte_eth_promiscuous_disable(res->port_num);
5609         }
5610 }
5611
5612 cmdline_parse_token_string_t cmd_setpromisc_set =
5613         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5614 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5615         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5616                                  "promisc");
5617 cmdline_parse_token_string_t cmd_setpromisc_portall =
5618         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5619                                  "all");
5620 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5621         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5622                               UINT8);
5623 cmdline_parse_token_string_t cmd_setpromisc_mode =
5624         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5625                                  "on#off");
5626
5627 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5628         .f = cmd_set_promisc_mode_parsed,
5629         .data = (void *)1,
5630         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5631         .tokens = {
5632                 (void *)&cmd_setpromisc_set,
5633                 (void *)&cmd_setpromisc_promisc,
5634                 (void *)&cmd_setpromisc_portall,
5635                 (void *)&cmd_setpromisc_mode,
5636                 NULL,
5637         },
5638 };
5639
5640 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5641         .f = cmd_set_promisc_mode_parsed,
5642         .data = (void *)0,
5643         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5644         .tokens = {
5645                 (void *)&cmd_setpromisc_set,
5646                 (void *)&cmd_setpromisc_promisc,
5647                 (void *)&cmd_setpromisc_portnum,
5648                 (void *)&cmd_setpromisc_mode,
5649                 NULL,
5650         },
5651 };
5652
5653 /* *** SET ALLMULTI MODE *** */
5654 struct cmd_set_allmulti_mode_result {
5655         cmdline_fixed_string_t set;
5656         cmdline_fixed_string_t allmulti;
5657         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5658         uint8_t port_num;                /* valid if "allports" argument == 0 */
5659         cmdline_fixed_string_t mode;
5660 };
5661
5662 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5663                                         __attribute__((unused)) struct cmdline *cl,
5664                                         void *allports)
5665 {
5666         struct cmd_set_allmulti_mode_result *res = parsed_result;
5667         int enable;
5668         portid_t i;
5669
5670         if (!strcmp(res->mode, "on"))
5671                 enable = 1;
5672         else
5673                 enable = 0;
5674
5675         /* all ports */
5676         if (allports) {
5677                 RTE_ETH_FOREACH_DEV(i) {
5678                         if (enable)
5679                                 rte_eth_allmulticast_enable(i);
5680                         else
5681                                 rte_eth_allmulticast_disable(i);
5682                 }
5683         }
5684         else {
5685                 if (enable)
5686                         rte_eth_allmulticast_enable(res->port_num);
5687                 else
5688                         rte_eth_allmulticast_disable(res->port_num);
5689         }
5690 }
5691
5692 cmdline_parse_token_string_t cmd_setallmulti_set =
5693         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5694 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5695         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5696                                  "allmulti");
5697 cmdline_parse_token_string_t cmd_setallmulti_portall =
5698         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5699                                  "all");
5700 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5701         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5702                               UINT8);
5703 cmdline_parse_token_string_t cmd_setallmulti_mode =
5704         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5705                                  "on#off");
5706
5707 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5708         .f = cmd_set_allmulti_mode_parsed,
5709         .data = (void *)1,
5710         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5711         .tokens = {
5712                 (void *)&cmd_setallmulti_set,
5713                 (void *)&cmd_setallmulti_allmulti,
5714                 (void *)&cmd_setallmulti_portall,
5715                 (void *)&cmd_setallmulti_mode,
5716                 NULL,
5717         },
5718 };
5719
5720 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5721         .f = cmd_set_allmulti_mode_parsed,
5722         .data = (void *)0,
5723         .help_str = "set allmulti <port_id> on|off: "
5724                 "Set allmulti mode on port_id",
5725         .tokens = {
5726                 (void *)&cmd_setallmulti_set,
5727                 (void *)&cmd_setallmulti_allmulti,
5728                 (void *)&cmd_setallmulti_portnum,
5729                 (void *)&cmd_setallmulti_mode,
5730                 NULL,
5731         },
5732 };
5733
5734 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5735 struct cmd_link_flow_ctrl_set_result {
5736         cmdline_fixed_string_t set;
5737         cmdline_fixed_string_t flow_ctrl;
5738         cmdline_fixed_string_t rx;
5739         cmdline_fixed_string_t rx_lfc_mode;
5740         cmdline_fixed_string_t tx;
5741         cmdline_fixed_string_t tx_lfc_mode;
5742         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5743         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5744         cmdline_fixed_string_t autoneg_str;
5745         cmdline_fixed_string_t autoneg;
5746         cmdline_fixed_string_t hw_str;
5747         uint32_t high_water;
5748         cmdline_fixed_string_t lw_str;
5749         uint32_t low_water;
5750         cmdline_fixed_string_t pt_str;
5751         uint16_t pause_time;
5752         cmdline_fixed_string_t xon_str;
5753         uint16_t send_xon;
5754         uint8_t  port_id;
5755 };
5756
5757 cmdline_parse_token_string_t cmd_lfc_set_set =
5758         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5759                                 set, "set");
5760 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5761         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5762                                 flow_ctrl, "flow_ctrl");
5763 cmdline_parse_token_string_t cmd_lfc_set_rx =
5764         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5765                                 rx, "rx");
5766 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5767         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5768                                 rx_lfc_mode, "on#off");
5769 cmdline_parse_token_string_t cmd_lfc_set_tx =
5770         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5771                                 tx, "tx");
5772 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5773         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5774                                 tx_lfc_mode, "on#off");
5775 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5776         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5777                                 hw_str, "high_water");
5778 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5779         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5780                                 high_water, UINT32);
5781 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5782         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5783                                 lw_str, "low_water");
5784 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5785         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5786                                 low_water, UINT32);
5787 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5788         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5789                                 pt_str, "pause_time");
5790 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5791         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5792                                 pause_time, UINT16);
5793 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5794         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5795                                 xon_str, "send_xon");
5796 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5797         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5798                                 send_xon, UINT16);
5799 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5800         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5801                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5802 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5803         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5804                                 mac_ctrl_frame_fwd_mode, "on#off");
5805 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5806         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5807                                 autoneg_str, "autoneg");
5808 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5809         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5810                                 autoneg, "on#off");
5811 cmdline_parse_token_num_t cmd_lfc_set_portid =
5812         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5813                                 port_id, UINT8);
5814
5815 /* forward declaration */
5816 static void
5817 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5818                               void *data);
5819
5820 cmdline_parse_inst_t cmd_link_flow_control_set = {
5821         .f = cmd_link_flow_ctrl_set_parsed,
5822         .data = NULL,
5823         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5824                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5825                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5826         .tokens = {
5827                 (void *)&cmd_lfc_set_set,
5828                 (void *)&cmd_lfc_set_flow_ctrl,
5829                 (void *)&cmd_lfc_set_rx,
5830                 (void *)&cmd_lfc_set_rx_mode,
5831                 (void *)&cmd_lfc_set_tx,
5832                 (void *)&cmd_lfc_set_tx_mode,
5833                 (void *)&cmd_lfc_set_high_water,
5834                 (void *)&cmd_lfc_set_low_water,
5835                 (void *)&cmd_lfc_set_pause_time,
5836                 (void *)&cmd_lfc_set_send_xon,
5837                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5838                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5839                 (void *)&cmd_lfc_set_autoneg_str,
5840                 (void *)&cmd_lfc_set_autoneg,
5841                 (void *)&cmd_lfc_set_portid,
5842                 NULL,
5843         },
5844 };
5845
5846 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5847         .f = cmd_link_flow_ctrl_set_parsed,
5848         .data = (void *)&cmd_link_flow_control_set_rx,
5849         .help_str = "set flow_ctrl rx on|off <port_id>: "
5850                 "Change rx flow control parameter",
5851         .tokens = {
5852                 (void *)&cmd_lfc_set_set,
5853                 (void *)&cmd_lfc_set_flow_ctrl,
5854                 (void *)&cmd_lfc_set_rx,
5855                 (void *)&cmd_lfc_set_rx_mode,
5856                 (void *)&cmd_lfc_set_portid,
5857                 NULL,
5858         },
5859 };
5860
5861 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5862         .f = cmd_link_flow_ctrl_set_parsed,
5863         .data = (void *)&cmd_link_flow_control_set_tx,
5864         .help_str = "set flow_ctrl tx on|off <port_id>: "
5865                 "Change tx flow control parameter",
5866         .tokens = {
5867                 (void *)&cmd_lfc_set_set,
5868                 (void *)&cmd_lfc_set_flow_ctrl,
5869                 (void *)&cmd_lfc_set_tx,
5870                 (void *)&cmd_lfc_set_tx_mode,
5871                 (void *)&cmd_lfc_set_portid,
5872                 NULL,
5873         },
5874 };
5875
5876 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5877         .f = cmd_link_flow_ctrl_set_parsed,
5878         .data = (void *)&cmd_link_flow_control_set_hw,
5879         .help_str = "set flow_ctrl high_water <value> <port_id>: "
5880                 "Change high water flow control parameter",
5881         .tokens = {
5882                 (void *)&cmd_lfc_set_set,
5883                 (void *)&cmd_lfc_set_flow_ctrl,
5884                 (void *)&cmd_lfc_set_high_water_str,
5885                 (void *)&cmd_lfc_set_high_water,
5886                 (void *)&cmd_lfc_set_portid,
5887                 NULL,
5888         },
5889 };
5890
5891 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5892         .f = cmd_link_flow_ctrl_set_parsed,
5893         .data = (void *)&cmd_link_flow_control_set_lw,
5894         .help_str = "set flow_ctrl low_water <value> <port_id>: "
5895                 "Change low water flow control parameter",
5896         .tokens = {
5897                 (void *)&cmd_lfc_set_set,
5898                 (void *)&cmd_lfc_set_flow_ctrl,
5899                 (void *)&cmd_lfc_set_low_water_str,
5900                 (void *)&cmd_lfc_set_low_water,
5901                 (void *)&cmd_lfc_set_portid,
5902                 NULL,
5903         },
5904 };
5905
5906 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5907         .f = cmd_link_flow_ctrl_set_parsed,
5908         .data = (void *)&cmd_link_flow_control_set_pt,
5909         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
5910                 "Change pause time flow control parameter",
5911         .tokens = {
5912                 (void *)&cmd_lfc_set_set,
5913                 (void *)&cmd_lfc_set_flow_ctrl,
5914                 (void *)&cmd_lfc_set_pause_time_str,
5915                 (void *)&cmd_lfc_set_pause_time,
5916                 (void *)&cmd_lfc_set_portid,
5917                 NULL,
5918         },
5919 };
5920
5921 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5922         .f = cmd_link_flow_ctrl_set_parsed,
5923         .data = (void *)&cmd_link_flow_control_set_xon,
5924         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
5925                 "Change send_xon flow control parameter",
5926         .tokens = {
5927                 (void *)&cmd_lfc_set_set,
5928                 (void *)&cmd_lfc_set_flow_ctrl,
5929                 (void *)&cmd_lfc_set_send_xon_str,
5930                 (void *)&cmd_lfc_set_send_xon,
5931                 (void *)&cmd_lfc_set_portid,
5932                 NULL,
5933         },
5934 };
5935
5936 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5937         .f = cmd_link_flow_ctrl_set_parsed,
5938         .data = (void *)&cmd_link_flow_control_set_macfwd,
5939         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
5940                 "Change mac ctrl fwd flow control parameter",
5941         .tokens = {
5942                 (void *)&cmd_lfc_set_set,
5943                 (void *)&cmd_lfc_set_flow_ctrl,
5944                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5945                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5946                 (void *)&cmd_lfc_set_portid,
5947                 NULL,
5948         },
5949 };
5950
5951 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5952         .f = cmd_link_flow_ctrl_set_parsed,
5953         .data = (void *)&cmd_link_flow_control_set_autoneg,
5954         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
5955                 "Change autoneg flow control parameter",
5956         .tokens = {
5957                 (void *)&cmd_lfc_set_set,
5958                 (void *)&cmd_lfc_set_flow_ctrl,
5959                 (void *)&cmd_lfc_set_autoneg_str,
5960                 (void *)&cmd_lfc_set_autoneg,
5961                 (void *)&cmd_lfc_set_portid,
5962                 NULL,
5963         },
5964 };
5965
5966 static void
5967 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
5968                               __attribute__((unused)) struct cmdline *cl,
5969                               void *data)
5970 {
5971         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
5972         cmdline_parse_inst_t *cmd = data;
5973         struct rte_eth_fc_conf fc_conf;
5974         int rx_fc_en = 0;
5975         int tx_fc_en = 0;
5976         int ret;
5977
5978         /*
5979          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5980          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5981          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5982          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5983          */
5984         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5985                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
5986         };
5987
5988         /* Partial command line, retrieve current configuration */
5989         if (cmd) {
5990                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5991                 if (ret != 0) {
5992                         printf("cannot get current flow ctrl parameters, return"
5993                                "code = %d\n", ret);
5994                         return;
5995                 }
5996
5997                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
5998                     (fc_conf.mode == RTE_FC_FULL))
5999                         rx_fc_en = 1;
6000                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6001                     (fc_conf.mode == RTE_FC_FULL))
6002                         tx_fc_en = 1;
6003         }
6004
6005         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6006                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6007
6008         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6009                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6010
6011         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6012
6013         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6014                 fc_conf.high_water = res->high_water;
6015
6016         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6017                 fc_conf.low_water = res->low_water;
6018
6019         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6020                 fc_conf.pause_time = res->pause_time;
6021
6022         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6023                 fc_conf.send_xon = res->send_xon;
6024
6025         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6026                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6027                         fc_conf.mac_ctrl_frame_fwd = 1;
6028                 else
6029                         fc_conf.mac_ctrl_frame_fwd = 0;
6030         }
6031
6032         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6033                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6034
6035         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6036         if (ret != 0)
6037                 printf("bad flow contrl parameter, return code = %d \n", ret);
6038 }
6039
6040 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6041 struct cmd_priority_flow_ctrl_set_result {
6042         cmdline_fixed_string_t set;
6043         cmdline_fixed_string_t pfc_ctrl;
6044         cmdline_fixed_string_t rx;
6045         cmdline_fixed_string_t rx_pfc_mode;
6046         cmdline_fixed_string_t tx;
6047         cmdline_fixed_string_t tx_pfc_mode;
6048         uint32_t high_water;
6049         uint32_t low_water;
6050         uint16_t pause_time;
6051         uint8_t  priority;
6052         uint8_t  port_id;
6053 };
6054
6055 static void
6056 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6057                        __attribute__((unused)) struct cmdline *cl,
6058                        __attribute__((unused)) void *data)
6059 {
6060         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6061         struct rte_eth_pfc_conf pfc_conf;
6062         int rx_fc_enable, tx_fc_enable;
6063         int ret;
6064
6065         /*
6066          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6067          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6068          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6069          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6070          */
6071         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6072                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6073         };
6074
6075         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6076         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6077         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6078         pfc_conf.fc.high_water = res->high_water;
6079         pfc_conf.fc.low_water  = res->low_water;
6080         pfc_conf.fc.pause_time = res->pause_time;
6081         pfc_conf.priority      = res->priority;
6082
6083         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6084         if (ret != 0)
6085                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6086 }
6087
6088 cmdline_parse_token_string_t cmd_pfc_set_set =
6089         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6090                                 set, "set");
6091 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6092         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6093                                 pfc_ctrl, "pfc_ctrl");
6094 cmdline_parse_token_string_t cmd_pfc_set_rx =
6095         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6096                                 rx, "rx");
6097 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6098         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6099                                 rx_pfc_mode, "on#off");
6100 cmdline_parse_token_string_t cmd_pfc_set_tx =
6101         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6102                                 tx, "tx");
6103 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6104         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6105                                 tx_pfc_mode, "on#off");
6106 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6107         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6108                                 high_water, UINT32);
6109 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6110         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6111                                 low_water, UINT32);
6112 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6113         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6114                                 pause_time, UINT16);
6115 cmdline_parse_token_num_t cmd_pfc_set_priority =
6116         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6117                                 priority, UINT8);
6118 cmdline_parse_token_num_t cmd_pfc_set_portid =
6119         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6120                                 port_id, UINT8);
6121
6122 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6123         .f = cmd_priority_flow_ctrl_set_parsed,
6124         .data = NULL,
6125         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6126                 "<pause_time> <priority> <port_id>: "
6127                 "Configure the Ethernet priority flow control",
6128         .tokens = {
6129                 (void *)&cmd_pfc_set_set,
6130                 (void *)&cmd_pfc_set_flow_ctrl,
6131                 (void *)&cmd_pfc_set_rx,
6132                 (void *)&cmd_pfc_set_rx_mode,
6133                 (void *)&cmd_pfc_set_tx,
6134                 (void *)&cmd_pfc_set_tx_mode,
6135                 (void *)&cmd_pfc_set_high_water,
6136                 (void *)&cmd_pfc_set_low_water,
6137                 (void *)&cmd_pfc_set_pause_time,
6138                 (void *)&cmd_pfc_set_priority,
6139                 (void *)&cmd_pfc_set_portid,
6140                 NULL,
6141         },
6142 };
6143
6144 /* *** RESET CONFIGURATION *** */
6145 struct cmd_reset_result {
6146         cmdline_fixed_string_t reset;
6147         cmdline_fixed_string_t def;
6148 };
6149
6150 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6151                              struct cmdline *cl,
6152                              __attribute__((unused)) void *data)
6153 {
6154         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6155         set_def_fwd_config();
6156 }
6157
6158 cmdline_parse_token_string_t cmd_reset_set =
6159         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6160 cmdline_parse_token_string_t cmd_reset_def =
6161         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6162                                  "default");
6163
6164 cmdline_parse_inst_t cmd_reset = {
6165         .f = cmd_reset_parsed,
6166         .data = NULL,
6167         .help_str = "set default: Reset default forwarding configuration",
6168         .tokens = {
6169                 (void *)&cmd_reset_set,
6170                 (void *)&cmd_reset_def,
6171                 NULL,
6172         },
6173 };
6174
6175 /* *** START FORWARDING *** */
6176 struct cmd_start_result {
6177         cmdline_fixed_string_t start;
6178 };
6179
6180 cmdline_parse_token_string_t cmd_start_start =
6181         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6182
6183 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6184                              __attribute__((unused)) struct cmdline *cl,
6185                              __attribute__((unused)) void *data)
6186 {
6187         start_packet_forwarding(0);
6188 }
6189
6190 cmdline_parse_inst_t cmd_start = {
6191         .f = cmd_start_parsed,
6192         .data = NULL,
6193         .help_str = "start: Start packet forwarding",
6194         .tokens = {
6195                 (void *)&cmd_start_start,
6196                 NULL,
6197         },
6198 };
6199
6200 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6201 struct cmd_start_tx_first_result {
6202         cmdline_fixed_string_t start;
6203         cmdline_fixed_string_t tx_first;
6204 };
6205
6206 static void
6207 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6208                           __attribute__((unused)) struct cmdline *cl,
6209                           __attribute__((unused)) void *data)
6210 {
6211         start_packet_forwarding(1);
6212 }
6213
6214 cmdline_parse_token_string_t cmd_start_tx_first_start =
6215         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6216                                  "start");
6217 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6218         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6219                                  tx_first, "tx_first");
6220
6221 cmdline_parse_inst_t cmd_start_tx_first = {
6222         .f = cmd_start_tx_first_parsed,
6223         .data = NULL,
6224         .help_str = "start tx_first: Start packet forwarding, "
6225                 "after sending 1 burst of packets",
6226         .tokens = {
6227                 (void *)&cmd_start_tx_first_start,
6228                 (void *)&cmd_start_tx_first_tx_first,
6229                 NULL,
6230         },
6231 };
6232
6233 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6234 struct cmd_start_tx_first_n_result {
6235         cmdline_fixed_string_t start;
6236         cmdline_fixed_string_t tx_first;
6237         uint32_t tx_num;
6238 };
6239
6240 static void
6241 cmd_start_tx_first_n_parsed(void *parsed_result,
6242                           __attribute__((unused)) struct cmdline *cl,
6243                           __attribute__((unused)) void *data)
6244 {
6245         struct cmd_start_tx_first_n_result *res = parsed_result;
6246
6247         start_packet_forwarding(res->tx_num);
6248 }
6249
6250 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6251         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6252                         start, "start");
6253 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6254         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6255                         tx_first, "tx_first");
6256 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6257         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6258                         tx_num, UINT32);
6259
6260 cmdline_parse_inst_t cmd_start_tx_first_n = {
6261         .f = cmd_start_tx_first_n_parsed,
6262         .data = NULL,
6263         .help_str = "start tx_first <num>: "
6264                 "packet forwarding, after sending <num> bursts of packets",
6265         .tokens = {
6266                 (void *)&cmd_start_tx_first_n_start,
6267                 (void *)&cmd_start_tx_first_n_tx_first,
6268                 (void *)&cmd_start_tx_first_n_tx_num,
6269                 NULL,
6270         },
6271 };
6272
6273 /* *** SET LINK UP *** */
6274 struct cmd_set_link_up_result {
6275         cmdline_fixed_string_t set;
6276         cmdline_fixed_string_t link_up;
6277         cmdline_fixed_string_t port;
6278         uint8_t port_id;
6279 };
6280
6281 cmdline_parse_token_string_t cmd_set_link_up_set =
6282         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6283 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6284         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6285                                 "link-up");
6286 cmdline_parse_token_string_t cmd_set_link_up_port =
6287         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6288 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6289         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
6290
6291 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6292                              __attribute__((unused)) struct cmdline *cl,
6293                              __attribute__((unused)) void *data)
6294 {
6295         struct cmd_set_link_up_result *res = parsed_result;
6296         dev_set_link_up(res->port_id);
6297 }
6298
6299 cmdline_parse_inst_t cmd_set_link_up = {
6300         .f = cmd_set_link_up_parsed,
6301         .data = NULL,
6302         .help_str = "set link-up port <port id>",
6303         .tokens = {
6304                 (void *)&cmd_set_link_up_set,
6305                 (void *)&cmd_set_link_up_link_up,
6306                 (void *)&cmd_set_link_up_port,
6307                 (void *)&cmd_set_link_up_port_id,
6308                 NULL,
6309         },
6310 };
6311
6312 /* *** SET LINK DOWN *** */
6313 struct cmd_set_link_down_result {
6314         cmdline_fixed_string_t set;
6315         cmdline_fixed_string_t link_down;
6316         cmdline_fixed_string_t port;
6317         uint8_t port_id;
6318 };
6319
6320 cmdline_parse_token_string_t cmd_set_link_down_set =
6321         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6322 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6323         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6324                                 "link-down");
6325 cmdline_parse_token_string_t cmd_set_link_down_port =
6326         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6327 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6328         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
6329
6330 static void cmd_set_link_down_parsed(
6331                                 __attribute__((unused)) void *parsed_result,
6332                                 __attribute__((unused)) struct cmdline *cl,
6333                                 __attribute__((unused)) void *data)
6334 {
6335         struct cmd_set_link_down_result *res = parsed_result;
6336         dev_set_link_down(res->port_id);
6337 }
6338
6339 cmdline_parse_inst_t cmd_set_link_down = {
6340         .f = cmd_set_link_down_parsed,
6341         .data = NULL,
6342         .help_str = "set link-down port <port id>",
6343         .tokens = {
6344                 (void *)&cmd_set_link_down_set,
6345                 (void *)&cmd_set_link_down_link_down,
6346                 (void *)&cmd_set_link_down_port,
6347                 (void *)&cmd_set_link_down_port_id,
6348                 NULL,
6349         },
6350 };
6351
6352 /* *** SHOW CFG *** */
6353 struct cmd_showcfg_result {
6354         cmdline_fixed_string_t show;
6355         cmdline_fixed_string_t cfg;
6356         cmdline_fixed_string_t what;
6357 };
6358
6359 static void cmd_showcfg_parsed(void *parsed_result,
6360                                __attribute__((unused)) struct cmdline *cl,
6361                                __attribute__((unused)) void *data)
6362 {
6363         struct cmd_showcfg_result *res = parsed_result;
6364         if (!strcmp(res->what, "rxtx"))
6365                 rxtx_config_display();
6366         else if (!strcmp(res->what, "cores"))
6367                 fwd_lcores_config_display();
6368         else if (!strcmp(res->what, "fwd"))
6369                 pkt_fwd_config_display(&cur_fwd_config);
6370         else if (!strcmp(res->what, "txpkts"))
6371                 show_tx_pkt_segments();
6372 }
6373
6374 cmdline_parse_token_string_t cmd_showcfg_show =
6375         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6376 cmdline_parse_token_string_t cmd_showcfg_port =
6377         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6378 cmdline_parse_token_string_t cmd_showcfg_what =
6379         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6380                                  "rxtx#cores#fwd#txpkts");
6381
6382 cmdline_parse_inst_t cmd_showcfg = {
6383         .f = cmd_showcfg_parsed,
6384         .data = NULL,
6385         .help_str = "show config rxtx|cores|fwd|txpkts",
6386         .tokens = {
6387                 (void *)&cmd_showcfg_show,
6388                 (void *)&cmd_showcfg_port,
6389                 (void *)&cmd_showcfg_what,
6390                 NULL,
6391         },
6392 };
6393
6394 /* *** SHOW ALL PORT INFO *** */
6395 struct cmd_showportall_result {
6396         cmdline_fixed_string_t show;
6397         cmdline_fixed_string_t port;
6398         cmdline_fixed_string_t what;
6399         cmdline_fixed_string_t all;
6400 };
6401
6402 static void cmd_showportall_parsed(void *parsed_result,
6403                                 __attribute__((unused)) struct cmdline *cl,
6404                                 __attribute__((unused)) void *data)
6405 {
6406         portid_t i;
6407
6408         struct cmd_showportall_result *res = parsed_result;
6409         if (!strcmp(res->show, "clear")) {
6410                 if (!strcmp(res->what, "stats"))
6411                         RTE_ETH_FOREACH_DEV(i)
6412                                 nic_stats_clear(i);
6413                 else if (!strcmp(res->what, "xstats"))
6414                         RTE_ETH_FOREACH_DEV(i)
6415                                 nic_xstats_clear(i);
6416         } else if (!strcmp(res->what, "info"))
6417                 RTE_ETH_FOREACH_DEV(i)
6418                         port_infos_display(i);
6419         else if (!strcmp(res->what, "stats"))
6420                 RTE_ETH_FOREACH_DEV(i)
6421                         nic_stats_display(i);
6422         else if (!strcmp(res->what, "xstats"))
6423                 RTE_ETH_FOREACH_DEV(i)
6424                         nic_xstats_display(i);
6425         else if (!strcmp(res->what, "fdir"))
6426                 RTE_ETH_FOREACH_DEV(i)
6427                         fdir_get_infos(i);
6428         else if (!strcmp(res->what, "stat_qmap"))
6429                 RTE_ETH_FOREACH_DEV(i)
6430                         nic_stats_mapping_display(i);
6431         else if (!strcmp(res->what, "dcb_tc"))
6432                 RTE_ETH_FOREACH_DEV(i)
6433                         port_dcb_info_display(i);
6434         else if (!strcmp(res->what, "cap"))
6435                 RTE_ETH_FOREACH_DEV(i)
6436                         port_offload_cap_display(i);
6437 }
6438
6439 cmdline_parse_token_string_t cmd_showportall_show =
6440         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6441                                  "show#clear");
6442 cmdline_parse_token_string_t cmd_showportall_port =
6443         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6444 cmdline_parse_token_string_t cmd_showportall_what =
6445         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6446                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6447 cmdline_parse_token_string_t cmd_showportall_all =
6448         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6449 cmdline_parse_inst_t cmd_showportall = {
6450         .f = cmd_showportall_parsed,
6451         .data = NULL,
6452         .help_str = "show|clear port "
6453                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6454         .tokens = {
6455                 (void *)&cmd_showportall_show,
6456                 (void *)&cmd_showportall_port,
6457                 (void *)&cmd_showportall_what,
6458                 (void *)&cmd_showportall_all,
6459                 NULL,
6460         },
6461 };
6462
6463 /* *** SHOW PORT INFO *** */
6464 struct cmd_showport_result {
6465         cmdline_fixed_string_t show;
6466         cmdline_fixed_string_t port;
6467         cmdline_fixed_string_t what;
6468         uint8_t portnum;
6469 };
6470
6471 static void cmd_showport_parsed(void *parsed_result,
6472                                 __attribute__((unused)) struct cmdline *cl,
6473                                 __attribute__((unused)) void *data)
6474 {
6475         struct cmd_showport_result *res = parsed_result;
6476         if (!strcmp(res->show, "clear")) {
6477                 if (!strcmp(res->what, "stats"))
6478                         nic_stats_clear(res->portnum);
6479                 else if (!strcmp(res->what, "xstats"))
6480                         nic_xstats_clear(res->portnum);
6481         } else if (!strcmp(res->what, "info"))
6482                 port_infos_display(res->portnum);
6483         else if (!strcmp(res->what, "stats"))
6484                 nic_stats_display(res->portnum);
6485         else if (!strcmp(res->what, "xstats"))
6486                 nic_xstats_display(res->portnum);
6487         else if (!strcmp(res->what, "fdir"))
6488                  fdir_get_infos(res->portnum);
6489         else if (!strcmp(res->what, "stat_qmap"))
6490                 nic_stats_mapping_display(res->portnum);
6491         else if (!strcmp(res->what, "dcb_tc"))
6492                 port_dcb_info_display(res->portnum);
6493         else if (!strcmp(res->what, "cap"))
6494                 port_offload_cap_display(res->portnum);
6495 }
6496
6497 cmdline_parse_token_string_t cmd_showport_show =
6498         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6499                                  "show#clear");
6500 cmdline_parse_token_string_t cmd_showport_port =
6501         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6502 cmdline_parse_token_string_t cmd_showport_what =
6503         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6504                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6505 cmdline_parse_token_num_t cmd_showport_portnum =
6506         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
6507
6508 cmdline_parse_inst_t cmd_showport = {
6509         .f = cmd_showport_parsed,
6510         .data = NULL,
6511         .help_str = "show|clear port "
6512                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6513                 "<port_id>",
6514         .tokens = {
6515                 (void *)&cmd_showport_show,
6516                 (void *)&cmd_showport_port,
6517                 (void *)&cmd_showport_what,
6518                 (void *)&cmd_showport_portnum,
6519                 NULL,
6520         },
6521 };
6522
6523 /* *** SHOW QUEUE INFO *** */
6524 struct cmd_showqueue_result {
6525         cmdline_fixed_string_t show;
6526         cmdline_fixed_string_t type;
6527         cmdline_fixed_string_t what;
6528         uint8_t portnum;
6529         uint16_t queuenum;
6530 };
6531
6532 static void
6533 cmd_showqueue_parsed(void *parsed_result,
6534         __attribute__((unused)) struct cmdline *cl,
6535         __attribute__((unused)) void *data)
6536 {
6537         struct cmd_showqueue_result *res = parsed_result;
6538
6539         if (!strcmp(res->type, "rxq"))
6540                 rx_queue_infos_display(res->portnum, res->queuenum);
6541         else if (!strcmp(res->type, "txq"))
6542                 tx_queue_infos_display(res->portnum, res->queuenum);
6543 }
6544
6545 cmdline_parse_token_string_t cmd_showqueue_show =
6546         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6547 cmdline_parse_token_string_t cmd_showqueue_type =
6548         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6549 cmdline_parse_token_string_t cmd_showqueue_what =
6550         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6551 cmdline_parse_token_num_t cmd_showqueue_portnum =
6552         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
6553 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6554         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6555
6556 cmdline_parse_inst_t cmd_showqueue = {
6557         .f = cmd_showqueue_parsed,
6558         .data = NULL,
6559         .help_str = "show rxq|txq info <port_id> <queue_id>",
6560         .tokens = {
6561                 (void *)&cmd_showqueue_show,
6562                 (void *)&cmd_showqueue_type,
6563                 (void *)&cmd_showqueue_what,
6564                 (void *)&cmd_showqueue_portnum,
6565                 (void *)&cmd_showqueue_queuenum,
6566                 NULL,
6567         },
6568 };
6569
6570 /* *** READ PORT REGISTER *** */
6571 struct cmd_read_reg_result {
6572         cmdline_fixed_string_t read;
6573         cmdline_fixed_string_t reg;
6574         uint8_t port_id;
6575         uint32_t reg_off;
6576 };
6577
6578 static void
6579 cmd_read_reg_parsed(void *parsed_result,
6580                     __attribute__((unused)) struct cmdline *cl,
6581                     __attribute__((unused)) void *data)
6582 {
6583         struct cmd_read_reg_result *res = parsed_result;
6584         port_reg_display(res->port_id, res->reg_off);
6585 }
6586
6587 cmdline_parse_token_string_t cmd_read_reg_read =
6588         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6589 cmdline_parse_token_string_t cmd_read_reg_reg =
6590         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6591 cmdline_parse_token_num_t cmd_read_reg_port_id =
6592         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
6593 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6594         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6595
6596 cmdline_parse_inst_t cmd_read_reg = {
6597         .f = cmd_read_reg_parsed,
6598         .data = NULL,
6599         .help_str = "read reg <port_id> <reg_off>",
6600         .tokens = {
6601                 (void *)&cmd_read_reg_read,
6602                 (void *)&cmd_read_reg_reg,
6603                 (void *)&cmd_read_reg_port_id,
6604                 (void *)&cmd_read_reg_reg_off,
6605                 NULL,
6606         },
6607 };
6608
6609 /* *** READ PORT REGISTER BIT FIELD *** */
6610 struct cmd_read_reg_bit_field_result {
6611         cmdline_fixed_string_t read;
6612         cmdline_fixed_string_t regfield;
6613         uint8_t port_id;
6614         uint32_t reg_off;
6615         uint8_t bit1_pos;
6616         uint8_t bit2_pos;
6617 };
6618
6619 static void
6620 cmd_read_reg_bit_field_parsed(void *parsed_result,
6621                               __attribute__((unused)) struct cmdline *cl,
6622                               __attribute__((unused)) void *data)
6623 {
6624         struct cmd_read_reg_bit_field_result *res = parsed_result;
6625         port_reg_bit_field_display(res->port_id, res->reg_off,
6626                                    res->bit1_pos, res->bit2_pos);
6627 }
6628
6629 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6630         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6631                                  "read");
6632 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6633         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6634                                  regfield, "regfield");
6635 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6636         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6637                               UINT8);
6638 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6639         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6640                               UINT32);
6641 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6642         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6643                               UINT8);
6644 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6645         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6646                               UINT8);
6647
6648 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6649         .f = cmd_read_reg_bit_field_parsed,
6650         .data = NULL,
6651         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6652         "Read register bit field between bit_x and bit_y included",
6653         .tokens = {
6654                 (void *)&cmd_read_reg_bit_field_read,
6655                 (void *)&cmd_read_reg_bit_field_regfield,
6656                 (void *)&cmd_read_reg_bit_field_port_id,
6657                 (void *)&cmd_read_reg_bit_field_reg_off,
6658                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6659                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6660                 NULL,
6661         },
6662 };
6663
6664 /* *** READ PORT REGISTER BIT *** */
6665 struct cmd_read_reg_bit_result {
6666         cmdline_fixed_string_t read;
6667         cmdline_fixed_string_t regbit;
6668         uint8_t port_id;
6669         uint32_t reg_off;
6670         uint8_t bit_pos;
6671 };
6672
6673 static void
6674 cmd_read_reg_bit_parsed(void *parsed_result,
6675                         __attribute__((unused)) struct cmdline *cl,
6676                         __attribute__((unused)) void *data)
6677 {
6678         struct cmd_read_reg_bit_result *res = parsed_result;
6679         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6680 }
6681
6682 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6683         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6684 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6685         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6686                                  regbit, "regbit");
6687 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6688         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
6689 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6690         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6691 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6692         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6693
6694 cmdline_parse_inst_t cmd_read_reg_bit = {
6695         .f = cmd_read_reg_bit_parsed,
6696         .data = NULL,
6697         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6698         .tokens = {
6699                 (void *)&cmd_read_reg_bit_read,
6700                 (void *)&cmd_read_reg_bit_regbit,
6701                 (void *)&cmd_read_reg_bit_port_id,
6702                 (void *)&cmd_read_reg_bit_reg_off,
6703                 (void *)&cmd_read_reg_bit_bit_pos,
6704                 NULL,
6705         },
6706 };
6707
6708 /* *** WRITE PORT REGISTER *** */
6709 struct cmd_write_reg_result {
6710         cmdline_fixed_string_t write;
6711         cmdline_fixed_string_t reg;
6712         uint8_t port_id;
6713         uint32_t reg_off;
6714         uint32_t value;
6715 };
6716
6717 static void
6718 cmd_write_reg_parsed(void *parsed_result,
6719                      __attribute__((unused)) struct cmdline *cl,
6720                      __attribute__((unused)) void *data)
6721 {
6722         struct cmd_write_reg_result *res = parsed_result;
6723         port_reg_set(res->port_id, res->reg_off, res->value);
6724 }
6725
6726 cmdline_parse_token_string_t cmd_write_reg_write =
6727         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6728 cmdline_parse_token_string_t cmd_write_reg_reg =
6729         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6730 cmdline_parse_token_num_t cmd_write_reg_port_id =
6731         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
6732 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6733         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6734 cmdline_parse_token_num_t cmd_write_reg_value =
6735         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6736
6737 cmdline_parse_inst_t cmd_write_reg = {
6738         .f = cmd_write_reg_parsed,
6739         .data = NULL,
6740         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6741         .tokens = {
6742                 (void *)&cmd_write_reg_write,
6743                 (void *)&cmd_write_reg_reg,
6744                 (void *)&cmd_write_reg_port_id,
6745                 (void *)&cmd_write_reg_reg_off,
6746                 (void *)&cmd_write_reg_value,
6747                 NULL,
6748         },
6749 };
6750
6751 /* *** WRITE PORT REGISTER BIT FIELD *** */
6752 struct cmd_write_reg_bit_field_result {
6753         cmdline_fixed_string_t write;
6754         cmdline_fixed_string_t regfield;
6755         uint8_t port_id;
6756         uint32_t reg_off;
6757         uint8_t bit1_pos;
6758         uint8_t bit2_pos;
6759         uint32_t value;
6760 };
6761
6762 static void
6763 cmd_write_reg_bit_field_parsed(void *parsed_result,
6764                                __attribute__((unused)) struct cmdline *cl,
6765                                __attribute__((unused)) void *data)
6766 {
6767         struct cmd_write_reg_bit_field_result *res = parsed_result;
6768         port_reg_bit_field_set(res->port_id, res->reg_off,
6769                           res->bit1_pos, res->bit2_pos, res->value);
6770 }
6771
6772 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6773         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6774                                  "write");
6775 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6776         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6777                                  regfield, "regfield");
6778 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6779         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6780                               UINT8);
6781 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6782         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6783                               UINT32);
6784 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6785         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6786                               UINT8);
6787 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6788         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6789                               UINT8);
6790 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6791         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6792                               UINT32);
6793
6794 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6795         .f = cmd_write_reg_bit_field_parsed,
6796         .data = NULL,
6797         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6798                 "<reg_value>: "
6799                 "Set register bit field between bit_x and bit_y included",
6800         .tokens = {
6801                 (void *)&cmd_write_reg_bit_field_write,
6802                 (void *)&cmd_write_reg_bit_field_regfield,
6803                 (void *)&cmd_write_reg_bit_field_port_id,
6804                 (void *)&cmd_write_reg_bit_field_reg_off,
6805                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6806                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6807                 (void *)&cmd_write_reg_bit_field_value,
6808                 NULL,
6809         },
6810 };
6811
6812 /* *** WRITE PORT REGISTER BIT *** */
6813 struct cmd_write_reg_bit_result {
6814         cmdline_fixed_string_t write;
6815         cmdline_fixed_string_t regbit;
6816         uint8_t port_id;
6817         uint32_t reg_off;
6818         uint8_t bit_pos;
6819         uint8_t value;
6820 };
6821
6822 static void
6823 cmd_write_reg_bit_parsed(void *parsed_result,
6824                          __attribute__((unused)) struct cmdline *cl,
6825                          __attribute__((unused)) void *data)
6826 {
6827         struct cmd_write_reg_bit_result *res = parsed_result;
6828         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6829 }
6830
6831 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6832         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6833                                  "write");
6834 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6835         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6836                                  regbit, "regbit");
6837 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6838         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
6839 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6840         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6841 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6842         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6843 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6844         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6845
6846 cmdline_parse_inst_t cmd_write_reg_bit = {
6847         .f = cmd_write_reg_bit_parsed,
6848         .data = NULL,
6849         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6850                 "0 <= bit_x <= 31",
6851         .tokens = {
6852                 (void *)&cmd_write_reg_bit_write,
6853                 (void *)&cmd_write_reg_bit_regbit,
6854                 (void *)&cmd_write_reg_bit_port_id,
6855                 (void *)&cmd_write_reg_bit_reg_off,
6856                 (void *)&cmd_write_reg_bit_bit_pos,
6857                 (void *)&cmd_write_reg_bit_value,
6858                 NULL,
6859         },
6860 };
6861
6862 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6863 struct cmd_read_rxd_txd_result {
6864         cmdline_fixed_string_t read;
6865         cmdline_fixed_string_t rxd_txd;
6866         uint8_t port_id;
6867         uint16_t queue_id;
6868         uint16_t desc_id;
6869 };
6870
6871 static void
6872 cmd_read_rxd_txd_parsed(void *parsed_result,
6873                         __attribute__((unused)) struct cmdline *cl,
6874                         __attribute__((unused)) void *data)
6875 {
6876         struct cmd_read_rxd_txd_result *res = parsed_result;
6877
6878         if (!strcmp(res->rxd_txd, "rxd"))
6879                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6880         else if (!strcmp(res->rxd_txd, "txd"))
6881                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6882 }
6883
6884 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6885         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6886 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6887         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6888                                  "rxd#txd");
6889 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6890         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
6891 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6892         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6893 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6894         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6895
6896 cmdline_parse_inst_t cmd_read_rxd_txd = {
6897         .f = cmd_read_rxd_txd_parsed,
6898         .data = NULL,
6899         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6900         .tokens = {
6901                 (void *)&cmd_read_rxd_txd_read,
6902                 (void *)&cmd_read_rxd_txd_rxd_txd,
6903                 (void *)&cmd_read_rxd_txd_port_id,
6904                 (void *)&cmd_read_rxd_txd_queue_id,
6905                 (void *)&cmd_read_rxd_txd_desc_id,
6906                 NULL,
6907         },
6908 };
6909
6910 /* *** QUIT *** */
6911 struct cmd_quit_result {
6912         cmdline_fixed_string_t quit;
6913 };
6914
6915 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6916                             struct cmdline *cl,
6917                             __attribute__((unused)) void *data)
6918 {
6919         pmd_test_exit();
6920         cmdline_quit(cl);
6921 }
6922
6923 cmdline_parse_token_string_t cmd_quit_quit =
6924         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6925
6926 cmdline_parse_inst_t cmd_quit = {
6927         .f = cmd_quit_parsed,
6928         .data = NULL,
6929         .help_str = "quit: Exit application",
6930         .tokens = {
6931                 (void *)&cmd_quit_quit,
6932                 NULL,
6933         },
6934 };
6935
6936 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
6937 struct cmd_mac_addr_result {
6938         cmdline_fixed_string_t mac_addr_cmd;
6939         cmdline_fixed_string_t what;
6940         uint8_t port_num;
6941         struct ether_addr address;
6942 };
6943
6944 static void cmd_mac_addr_parsed(void *parsed_result,
6945                 __attribute__((unused)) struct cmdline *cl,
6946                 __attribute__((unused)) void *data)
6947 {
6948         struct cmd_mac_addr_result *res = parsed_result;
6949         int ret;
6950
6951         if (strcmp(res->what, "add") == 0)
6952                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
6953         else if (strcmp(res->what, "set") == 0)
6954                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
6955                                                        &res->address);
6956         else
6957                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
6958
6959         /* check the return value and print it if is < 0 */
6960         if(ret < 0)
6961                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
6962
6963 }
6964
6965 cmdline_parse_token_string_t cmd_mac_addr_cmd =
6966         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
6967                                 "mac_addr");
6968 cmdline_parse_token_string_t cmd_mac_addr_what =
6969         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
6970                                 "add#remove#set");
6971 cmdline_parse_token_num_t cmd_mac_addr_portnum =
6972                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
6973 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
6974                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
6975
6976 cmdline_parse_inst_t cmd_mac_addr = {
6977         .f = cmd_mac_addr_parsed,
6978         .data = (void *)0,
6979         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
6980                         "Add/Remove/Set MAC address on port_id",
6981         .tokens = {
6982                 (void *)&cmd_mac_addr_cmd,
6983                 (void *)&cmd_mac_addr_what,
6984                 (void *)&cmd_mac_addr_portnum,
6985                 (void *)&cmd_mac_addr_addr,
6986                 NULL,
6987         },
6988 };
6989
6990
6991 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
6992 struct cmd_set_qmap_result {
6993         cmdline_fixed_string_t set;
6994         cmdline_fixed_string_t qmap;
6995         cmdline_fixed_string_t what;
6996         uint8_t port_id;
6997         uint16_t queue_id;
6998         uint8_t map_value;
6999 };
7000
7001 static void
7002 cmd_set_qmap_parsed(void *parsed_result,
7003                        __attribute__((unused)) struct cmdline *cl,
7004                        __attribute__((unused)) void *data)
7005 {
7006         struct cmd_set_qmap_result *res = parsed_result;
7007         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7008
7009         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7010 }
7011
7012 cmdline_parse_token_string_t cmd_setqmap_set =
7013         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7014                                  set, "set");
7015 cmdline_parse_token_string_t cmd_setqmap_qmap =
7016         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7017                                  qmap, "stat_qmap");
7018 cmdline_parse_token_string_t cmd_setqmap_what =
7019         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7020                                  what, "tx#rx");
7021 cmdline_parse_token_num_t cmd_setqmap_portid =
7022         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7023                               port_id, UINT8);
7024 cmdline_parse_token_num_t cmd_setqmap_queueid =
7025         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7026                               queue_id, UINT16);
7027 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7028         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7029                               map_value, UINT8);
7030
7031 cmdline_parse_inst_t cmd_set_qmap = {
7032         .f = cmd_set_qmap_parsed,
7033         .data = NULL,
7034         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7035                 "Set statistics mapping value on tx|rx queue_id of port_id",
7036         .tokens = {
7037                 (void *)&cmd_setqmap_set,
7038                 (void *)&cmd_setqmap_qmap,
7039                 (void *)&cmd_setqmap_what,
7040                 (void *)&cmd_setqmap_portid,
7041                 (void *)&cmd_setqmap_queueid,
7042                 (void *)&cmd_setqmap_mapvalue,
7043                 NULL,
7044         },
7045 };
7046
7047 /* *** CONFIGURE UNICAST HASH TABLE *** */
7048 struct cmd_set_uc_hash_table {
7049         cmdline_fixed_string_t set;
7050         cmdline_fixed_string_t port;
7051         uint8_t port_id;
7052         cmdline_fixed_string_t what;
7053         struct ether_addr address;
7054         cmdline_fixed_string_t mode;
7055 };
7056
7057 static void
7058 cmd_set_uc_hash_parsed(void *parsed_result,
7059                        __attribute__((unused)) struct cmdline *cl,
7060                        __attribute__((unused)) void *data)
7061 {
7062         int ret=0;
7063         struct cmd_set_uc_hash_table *res = parsed_result;
7064
7065         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7066
7067         if (strcmp(res->what, "uta") == 0)
7068                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7069                                                 &res->address,(uint8_t)is_on);
7070         if (ret < 0)
7071                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7072
7073 }
7074
7075 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7076         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7077                                  set, "set");
7078 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7079         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7080                                  port, "port");
7081 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7082         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7083                               port_id, UINT8);
7084 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7085         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7086                                  what, "uta");
7087 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7088         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7089                                 address);
7090 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7091         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7092                                  mode, "on#off");
7093
7094 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7095         .f = cmd_set_uc_hash_parsed,
7096         .data = NULL,
7097         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7098         .tokens = {
7099                 (void *)&cmd_set_uc_hash_set,
7100                 (void *)&cmd_set_uc_hash_port,
7101                 (void *)&cmd_set_uc_hash_portid,
7102                 (void *)&cmd_set_uc_hash_what,
7103                 (void *)&cmd_set_uc_hash_mac,
7104                 (void *)&cmd_set_uc_hash_mode,
7105                 NULL,
7106         },
7107 };
7108
7109 struct cmd_set_uc_all_hash_table {
7110         cmdline_fixed_string_t set;
7111         cmdline_fixed_string_t port;
7112         uint8_t port_id;
7113         cmdline_fixed_string_t what;
7114         cmdline_fixed_string_t value;
7115         cmdline_fixed_string_t mode;
7116 };
7117
7118 static void
7119 cmd_set_uc_all_hash_parsed(void *parsed_result,
7120                        __attribute__((unused)) struct cmdline *cl,
7121                        __attribute__((unused)) void *data)
7122 {
7123         int ret=0;
7124         struct cmd_set_uc_all_hash_table *res = parsed_result;
7125
7126         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7127
7128         if ((strcmp(res->what, "uta") == 0) &&
7129                 (strcmp(res->value, "all") == 0))
7130                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7131         if (ret < 0)
7132                 printf("bad unicast hash table parameter,"
7133                         "return code = %d \n", ret);
7134 }
7135
7136 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7137         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7138                                  set, "set");
7139 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7140         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7141                                  port, "port");
7142 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7143         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7144                               port_id, UINT8);
7145 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7146         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7147                                  what, "uta");
7148 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7149         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7150                                 value,"all");
7151 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7152         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7153                                  mode, "on#off");
7154
7155 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7156         .f = cmd_set_uc_all_hash_parsed,
7157         .data = NULL,
7158         .help_str = "set port <port_id> uta all on|off",
7159         .tokens = {
7160                 (void *)&cmd_set_uc_all_hash_set,
7161                 (void *)&cmd_set_uc_all_hash_port,
7162                 (void *)&cmd_set_uc_all_hash_portid,
7163                 (void *)&cmd_set_uc_all_hash_what,
7164                 (void *)&cmd_set_uc_all_hash_value,
7165                 (void *)&cmd_set_uc_all_hash_mode,
7166                 NULL,
7167         },
7168 };
7169
7170 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7171 struct cmd_set_vf_macvlan_filter {
7172         cmdline_fixed_string_t set;
7173         cmdline_fixed_string_t port;
7174         uint8_t port_id;
7175         cmdline_fixed_string_t vf;
7176         uint8_t vf_id;
7177         struct ether_addr address;
7178         cmdline_fixed_string_t filter_type;
7179         cmdline_fixed_string_t mode;
7180 };
7181
7182 static void
7183 cmd_set_vf_macvlan_parsed(void *parsed_result,
7184                        __attribute__((unused)) struct cmdline *cl,
7185                        __attribute__((unused)) void *data)
7186 {
7187         int is_on, ret = 0;
7188         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7189         struct rte_eth_mac_filter filter;
7190
7191         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7192
7193         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7194
7195         /* set VF MAC filter */
7196         filter.is_vf = 1;
7197
7198         /* set VF ID */
7199         filter.dst_id = res->vf_id;
7200
7201         if (!strcmp(res->filter_type, "exact-mac"))
7202                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7203         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7204                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7205         else if (!strcmp(res->filter_type, "hashmac"))
7206                 filter.filter_type = RTE_MAC_HASH_MATCH;
7207         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7208                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7209
7210         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7211
7212         if (is_on)
7213                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7214                                         RTE_ETH_FILTER_MACVLAN,
7215                                         RTE_ETH_FILTER_ADD,
7216                                          &filter);
7217         else
7218                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7219                                         RTE_ETH_FILTER_MACVLAN,
7220                                         RTE_ETH_FILTER_DELETE,
7221                                         &filter);
7222
7223         if (ret < 0)
7224                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7225
7226 }
7227
7228 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7229         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7230                                  set, "set");
7231 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7232         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7233                                  port, "port");
7234 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7235         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7236                               port_id, UINT8);
7237 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7238         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7239                                  vf, "vf");
7240 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7241         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7242                                 vf_id, UINT8);
7243 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7244         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7245                                 address);
7246 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7247         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7248                                 filter_type, "exact-mac#exact-mac-vlan"
7249                                 "#hashmac#hashmac-vlan");
7250 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7251         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7252                                  mode, "on#off");
7253
7254 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7255         .f = cmd_set_vf_macvlan_parsed,
7256         .data = NULL,
7257         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7258                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7259                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7260                 "hash match rule: hash match of MAC and exact match of VLAN",
7261         .tokens = {
7262                 (void *)&cmd_set_vf_macvlan_set,
7263                 (void *)&cmd_set_vf_macvlan_port,
7264                 (void *)&cmd_set_vf_macvlan_portid,
7265                 (void *)&cmd_set_vf_macvlan_vf,
7266                 (void *)&cmd_set_vf_macvlan_vf_id,
7267                 (void *)&cmd_set_vf_macvlan_mac,
7268                 (void *)&cmd_set_vf_macvlan_filter_type,
7269                 (void *)&cmd_set_vf_macvlan_mode,
7270                 NULL,
7271         },
7272 };
7273
7274 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7275 struct cmd_set_vf_traffic {
7276         cmdline_fixed_string_t set;
7277         cmdline_fixed_string_t port;
7278         uint8_t port_id;
7279         cmdline_fixed_string_t vf;
7280         uint8_t vf_id;
7281         cmdline_fixed_string_t what;
7282         cmdline_fixed_string_t mode;
7283 };
7284
7285 static void
7286 cmd_set_vf_traffic_parsed(void *parsed_result,
7287                        __attribute__((unused)) struct cmdline *cl,
7288                        __attribute__((unused)) void *data)
7289 {
7290         struct cmd_set_vf_traffic *res = parsed_result;
7291         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7292         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7293
7294         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7295 }
7296
7297 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7298         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7299                                  set, "set");
7300 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7301         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7302                                  port, "port");
7303 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7304         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7305                               port_id, UINT8);
7306 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7307         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7308                                  vf, "vf");
7309 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7310         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7311                               vf_id, UINT8);
7312 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7313         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7314                                  what, "tx#rx");
7315 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7316         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7317                                  mode, "on#off");
7318
7319 cmdline_parse_inst_t cmd_set_vf_traffic = {
7320         .f = cmd_set_vf_traffic_parsed,
7321         .data = NULL,
7322         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7323         .tokens = {
7324                 (void *)&cmd_setvf_traffic_set,
7325                 (void *)&cmd_setvf_traffic_port,
7326                 (void *)&cmd_setvf_traffic_portid,
7327                 (void *)&cmd_setvf_traffic_vf,
7328                 (void *)&cmd_setvf_traffic_vfid,
7329                 (void *)&cmd_setvf_traffic_what,
7330                 (void *)&cmd_setvf_traffic_mode,
7331                 NULL,
7332         },
7333 };
7334
7335 /* *** CONFIGURE VF RECEIVE MODE *** */
7336 struct cmd_set_vf_rxmode {
7337         cmdline_fixed_string_t set;
7338         cmdline_fixed_string_t port;
7339         uint8_t port_id;
7340         cmdline_fixed_string_t vf;
7341         uint8_t vf_id;
7342         cmdline_fixed_string_t what;
7343         cmdline_fixed_string_t mode;
7344         cmdline_fixed_string_t on;
7345 };
7346
7347 static void
7348 cmd_set_vf_rxmode_parsed(void *parsed_result,
7349                        __attribute__((unused)) struct cmdline *cl,
7350                        __attribute__((unused)) void *data)
7351 {
7352         int ret = -ENOTSUP;
7353         uint16_t rx_mode = 0;
7354         struct cmd_set_vf_rxmode *res = parsed_result;
7355
7356         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7357         if (!strcmp(res->what,"rxmode")) {
7358                 if (!strcmp(res->mode, "AUPE"))
7359                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7360                 else if (!strcmp(res->mode, "ROPE"))
7361                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7362                 else if (!strcmp(res->mode, "BAM"))
7363                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7364                 else if (!strncmp(res->mode, "MPE",3))
7365                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7366         }
7367
7368 #ifdef RTE_LIBRTE_IXGBE_PMD
7369         if (ret == -ENOTSUP)
7370                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7371                                                   rx_mode, (uint8_t)is_on);
7372 #endif
7373 #ifdef RTE_LIBRTE_BNXT_PMD
7374         if (ret == -ENOTSUP)
7375                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7376                                                  rx_mode, (uint8_t)is_on);
7377 #endif
7378         if (ret < 0)
7379                 printf("bad VF receive mode parameter, return code = %d \n",
7380                 ret);
7381 }
7382
7383 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7384         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7385                                  set, "set");
7386 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7387         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7388                                  port, "port");
7389 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7390         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7391                               port_id, UINT8);
7392 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7393         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7394                                  vf, "vf");
7395 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7396         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7397                               vf_id, UINT8);
7398 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7399         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7400                                  what, "rxmode");
7401 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7402         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7403                                  mode, "AUPE#ROPE#BAM#MPE");
7404 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7405         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7406                                  on, "on#off");
7407
7408 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7409         .f = cmd_set_vf_rxmode_parsed,
7410         .data = NULL,
7411         .help_str = "set port <port_id> vf <vf_id> rxmode "
7412                 "AUPE|ROPE|BAM|MPE on|off",
7413         .tokens = {
7414                 (void *)&cmd_set_vf_rxmode_set,
7415                 (void *)&cmd_set_vf_rxmode_port,
7416                 (void *)&cmd_set_vf_rxmode_portid,
7417                 (void *)&cmd_set_vf_rxmode_vf,
7418                 (void *)&cmd_set_vf_rxmode_vfid,
7419                 (void *)&cmd_set_vf_rxmode_what,
7420                 (void *)&cmd_set_vf_rxmode_mode,
7421                 (void *)&cmd_set_vf_rxmode_on,
7422                 NULL,
7423         },
7424 };
7425
7426 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7427 struct cmd_vf_mac_addr_result {
7428         cmdline_fixed_string_t mac_addr_cmd;
7429         cmdline_fixed_string_t what;
7430         cmdline_fixed_string_t port;
7431         uint8_t port_num;
7432         cmdline_fixed_string_t vf;
7433         uint8_t vf_num;
7434         struct ether_addr address;
7435 };
7436
7437 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7438                 __attribute__((unused)) struct cmdline *cl,
7439                 __attribute__((unused)) void *data)
7440 {
7441         struct cmd_vf_mac_addr_result *res = parsed_result;
7442         int ret = -ENOTSUP;
7443
7444         if (strcmp(res->what, "add") != 0)
7445                 return;
7446
7447 #ifdef RTE_LIBRTE_I40E_PMD
7448         if (ret == -ENOTSUP)
7449                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7450                                                    &res->address);
7451 #endif
7452 #ifdef RTE_LIBRTE_BNXT_PMD
7453         if (ret == -ENOTSUP)
7454                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7455                                                 res->vf_num);
7456 #endif
7457
7458         if(ret < 0)
7459                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7460
7461 }
7462
7463 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7464         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7465                                 mac_addr_cmd,"mac_addr");
7466 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7467         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7468                                 what,"add");
7469 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7470         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7471                                 port,"port");
7472 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7473         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7474                                 port_num, UINT8);
7475 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7476         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7477                                 vf,"vf");
7478 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7479         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7480                                 vf_num, UINT8);
7481 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7482         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7483                                 address);
7484
7485 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7486         .f = cmd_vf_mac_addr_parsed,
7487         .data = (void *)0,
7488         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7489                 "Add MAC address filtering for a VF on port_id",
7490         .tokens = {
7491                 (void *)&cmd_vf_mac_addr_cmd,
7492                 (void *)&cmd_vf_mac_addr_what,
7493                 (void *)&cmd_vf_mac_addr_port,
7494                 (void *)&cmd_vf_mac_addr_portnum,
7495                 (void *)&cmd_vf_mac_addr_vf,
7496                 (void *)&cmd_vf_mac_addr_vfnum,
7497                 (void *)&cmd_vf_mac_addr_addr,
7498                 NULL,
7499         },
7500 };
7501
7502 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7503 struct cmd_vf_rx_vlan_filter {
7504         cmdline_fixed_string_t rx_vlan;
7505         cmdline_fixed_string_t what;
7506         uint16_t vlan_id;
7507         cmdline_fixed_string_t port;
7508         uint8_t port_id;
7509         cmdline_fixed_string_t vf;
7510         uint64_t vf_mask;
7511 };
7512
7513 static void
7514 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7515                           __attribute__((unused)) struct cmdline *cl,
7516                           __attribute__((unused)) void *data)
7517 {
7518         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7519         int ret = -ENOTSUP;
7520
7521         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7522
7523 #ifdef RTE_LIBRTE_IXGBE_PMD
7524         if (ret == -ENOTSUP)
7525                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7526                                 res->vlan_id, res->vf_mask, is_add);
7527 #endif
7528 #ifdef RTE_LIBRTE_I40E_PMD
7529         if (ret == -ENOTSUP)
7530                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7531                                 res->vlan_id, res->vf_mask, is_add);
7532 #endif
7533 #ifdef RTE_LIBRTE_BNXT_PMD
7534         if (ret == -ENOTSUP)
7535                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7536                                 res->vlan_id, res->vf_mask, is_add);
7537 #endif
7538
7539         switch (ret) {
7540         case 0:
7541                 break;
7542         case -EINVAL:
7543                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7544                                 res->vlan_id, res->vf_mask);
7545                 break;
7546         case -ENODEV:
7547                 printf("invalid port_id %d\n", res->port_id);
7548                 break;
7549         case -ENOTSUP:
7550                 printf("function not implemented or supported\n");
7551                 break;
7552         default:
7553                 printf("programming error: (%s)\n", strerror(-ret));
7554         }
7555 }
7556
7557 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7558         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7559                                  rx_vlan, "rx_vlan");
7560 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7561         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7562                                  what, "add#rm");
7563 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7564         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7565                               vlan_id, UINT16);
7566 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7567         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7568                                  port, "port");
7569 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7570         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7571                               port_id, UINT8);
7572 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7573         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7574                                  vf, "vf");
7575 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7576         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7577                               vf_mask, UINT64);
7578
7579 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7580         .f = cmd_vf_rx_vlan_filter_parsed,
7581         .data = NULL,
7582         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7583                 "(vf_mask = hexadecimal VF mask)",
7584         .tokens = {
7585                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7586                 (void *)&cmd_vf_rx_vlan_filter_what,
7587                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7588                 (void *)&cmd_vf_rx_vlan_filter_port,
7589                 (void *)&cmd_vf_rx_vlan_filter_portid,
7590                 (void *)&cmd_vf_rx_vlan_filter_vf,
7591                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7592                 NULL,
7593         },
7594 };
7595
7596 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7597 struct cmd_queue_rate_limit_result {
7598         cmdline_fixed_string_t set;
7599         cmdline_fixed_string_t port;
7600         uint8_t port_num;
7601         cmdline_fixed_string_t queue;
7602         uint8_t queue_num;
7603         cmdline_fixed_string_t rate;
7604         uint16_t rate_num;
7605 };
7606
7607 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7608                 __attribute__((unused)) struct cmdline *cl,
7609                 __attribute__((unused)) void *data)
7610 {
7611         struct cmd_queue_rate_limit_result *res = parsed_result;
7612         int ret = 0;
7613
7614         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7615                 && (strcmp(res->queue, "queue") == 0)
7616                 && (strcmp(res->rate, "rate") == 0))
7617                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7618                                         res->rate_num);
7619         if (ret < 0)
7620                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7621
7622 }
7623
7624 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7625         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7626                                 set, "set");
7627 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7628         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7629                                 port, "port");
7630 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7631         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7632                                 port_num, UINT8);
7633 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7634         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7635                                 queue, "queue");
7636 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7637         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7638                                 queue_num, UINT8);
7639 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7640         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7641                                 rate, "rate");
7642 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7643         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7644                                 rate_num, UINT16);
7645
7646 cmdline_parse_inst_t cmd_queue_rate_limit = {
7647         .f = cmd_queue_rate_limit_parsed,
7648         .data = (void *)0,
7649         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7650                 "Set rate limit for a queue on port_id",
7651         .tokens = {
7652                 (void *)&cmd_queue_rate_limit_set,
7653                 (void *)&cmd_queue_rate_limit_port,
7654                 (void *)&cmd_queue_rate_limit_portnum,
7655                 (void *)&cmd_queue_rate_limit_queue,
7656                 (void *)&cmd_queue_rate_limit_queuenum,
7657                 (void *)&cmd_queue_rate_limit_rate,
7658                 (void *)&cmd_queue_rate_limit_ratenum,
7659                 NULL,
7660         },
7661 };
7662
7663 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7664 struct cmd_vf_rate_limit_result {
7665         cmdline_fixed_string_t set;
7666         cmdline_fixed_string_t port;
7667         uint8_t port_num;
7668         cmdline_fixed_string_t vf;
7669         uint8_t vf_num;
7670         cmdline_fixed_string_t rate;
7671         uint16_t rate_num;
7672         cmdline_fixed_string_t q_msk;
7673         uint64_t q_msk_val;
7674 };
7675
7676 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7677                 __attribute__((unused)) struct cmdline *cl,
7678                 __attribute__((unused)) void *data)
7679 {
7680         struct cmd_vf_rate_limit_result *res = parsed_result;
7681         int ret = 0;
7682
7683         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7684                 && (strcmp(res->vf, "vf") == 0)
7685                 && (strcmp(res->rate, "rate") == 0)
7686                 && (strcmp(res->q_msk, "queue_mask") == 0))
7687                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7688                                         res->rate_num, res->q_msk_val);
7689         if (ret < 0)
7690                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7691
7692 }
7693
7694 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7695         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7696                                 set, "set");
7697 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7698         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7699                                 port, "port");
7700 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7701         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7702                                 port_num, UINT8);
7703 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7704         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7705                                 vf, "vf");
7706 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7707         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7708                                 vf_num, UINT8);
7709 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7710         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7711                                 rate, "rate");
7712 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7713         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7714                                 rate_num, UINT16);
7715 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7716         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7717                                 q_msk, "queue_mask");
7718 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7719         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7720                                 q_msk_val, UINT64);
7721
7722 cmdline_parse_inst_t cmd_vf_rate_limit = {
7723         .f = cmd_vf_rate_limit_parsed,
7724         .data = (void *)0,
7725         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7726                 "queue_mask <queue_mask_value>: "
7727                 "Set rate limit for queues of VF on port_id",
7728         .tokens = {
7729                 (void *)&cmd_vf_rate_limit_set,
7730                 (void *)&cmd_vf_rate_limit_port,
7731                 (void *)&cmd_vf_rate_limit_portnum,
7732                 (void *)&cmd_vf_rate_limit_vf,
7733                 (void *)&cmd_vf_rate_limit_vfnum,
7734                 (void *)&cmd_vf_rate_limit_rate,
7735                 (void *)&cmd_vf_rate_limit_ratenum,
7736                 (void *)&cmd_vf_rate_limit_q_msk,
7737                 (void *)&cmd_vf_rate_limit_q_msk_val,
7738                 NULL,
7739         },
7740 };
7741
7742 /* *** ADD TUNNEL FILTER OF A PORT *** */
7743 struct cmd_tunnel_filter_result {
7744         cmdline_fixed_string_t cmd;
7745         cmdline_fixed_string_t what;
7746         uint8_t port_id;
7747         struct ether_addr outer_mac;
7748         struct ether_addr inner_mac;
7749         cmdline_ipaddr_t ip_value;
7750         uint16_t inner_vlan;
7751         cmdline_fixed_string_t tunnel_type;
7752         cmdline_fixed_string_t filter_type;
7753         uint32_t tenant_id;
7754         uint16_t queue_num;
7755 };
7756
7757 static void
7758 cmd_tunnel_filter_parsed(void *parsed_result,
7759                           __attribute__((unused)) struct cmdline *cl,
7760                           __attribute__((unused)) void *data)
7761 {
7762         struct cmd_tunnel_filter_result *res = parsed_result;
7763         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7764         int ret = 0;
7765
7766         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7767
7768         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7769         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7770         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7771
7772         if (res->ip_value.family == AF_INET) {
7773                 tunnel_filter_conf.ip_addr.ipv4_addr =
7774                         res->ip_value.addr.ipv4.s_addr;
7775                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7776         } else {
7777                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7778                         &(res->ip_value.addr.ipv6),
7779                         sizeof(struct in6_addr));
7780                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7781         }
7782
7783         if (!strcmp(res->filter_type, "imac-ivlan"))
7784                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7785         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7786                 tunnel_filter_conf.filter_type =
7787                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7788         else if (!strcmp(res->filter_type, "imac-tenid"))
7789                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7790         else if (!strcmp(res->filter_type, "imac"))
7791                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7792         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7793                 tunnel_filter_conf.filter_type =
7794                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7795         else if (!strcmp(res->filter_type, "oip"))
7796                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7797         else if (!strcmp(res->filter_type, "iip"))
7798                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7799         else {
7800                 printf("The filter type is not supported");
7801                 return;
7802         }
7803
7804         if (!strcmp(res->tunnel_type, "vxlan"))
7805                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7806         else if (!strcmp(res->tunnel_type, "nvgre"))
7807                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7808         else if (!strcmp(res->tunnel_type, "ipingre"))
7809                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7810         else {
7811                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7812                 return;
7813         }
7814
7815         tunnel_filter_conf.tenant_id = res->tenant_id;
7816         tunnel_filter_conf.queue_id = res->queue_num;
7817         if (!strcmp(res->what, "add"))
7818                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7819                                         RTE_ETH_FILTER_TUNNEL,
7820                                         RTE_ETH_FILTER_ADD,
7821                                         &tunnel_filter_conf);
7822         else
7823                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7824                                         RTE_ETH_FILTER_TUNNEL,
7825                                         RTE_ETH_FILTER_DELETE,
7826                                         &tunnel_filter_conf);
7827         if (ret < 0)
7828                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7829                                 strerror(-ret));
7830
7831 }
7832 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7833         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7834         cmd, "tunnel_filter");
7835 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7836         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7837         what, "add#rm");
7838 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7839         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7840         port_id, UINT8);
7841 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7842         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7843         outer_mac);
7844 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7845         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7846         inner_mac);
7847 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7848         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7849         inner_vlan, UINT16);
7850 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7851         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7852         ip_value);
7853 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7854         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7855         tunnel_type, "vxlan#nvgre#ipingre");
7856
7857 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7858         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7859         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7860                 "imac#omac-imac-tenid");
7861 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7862         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7863         tenant_id, UINT32);
7864 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7865         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7866         queue_num, UINT16);
7867
7868 cmdline_parse_inst_t cmd_tunnel_filter = {
7869         .f = cmd_tunnel_filter_parsed,
7870         .data = (void *)0,
7871         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7872                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7873                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7874                 "<queue_id>: Add/Rm tunnel filter of a port",
7875         .tokens = {
7876                 (void *)&cmd_tunnel_filter_cmd,
7877                 (void *)&cmd_tunnel_filter_what,
7878                 (void *)&cmd_tunnel_filter_port_id,
7879                 (void *)&cmd_tunnel_filter_outer_mac,
7880                 (void *)&cmd_tunnel_filter_inner_mac,
7881                 (void *)&cmd_tunnel_filter_ip_value,
7882                 (void *)&cmd_tunnel_filter_innner_vlan,
7883                 (void *)&cmd_tunnel_filter_tunnel_type,
7884                 (void *)&cmd_tunnel_filter_filter_type,
7885                 (void *)&cmd_tunnel_filter_tenant_id,
7886                 (void *)&cmd_tunnel_filter_queue_num,
7887                 NULL,
7888         },
7889 };
7890
7891 /* *** CONFIGURE TUNNEL UDP PORT *** */
7892 struct cmd_tunnel_udp_config {
7893         cmdline_fixed_string_t cmd;
7894         cmdline_fixed_string_t what;
7895         uint16_t udp_port;
7896         uint8_t port_id;
7897 };
7898
7899 static void
7900 cmd_tunnel_udp_config_parsed(void *parsed_result,
7901                           __attribute__((unused)) struct cmdline *cl,
7902                           __attribute__((unused)) void *data)
7903 {
7904         struct cmd_tunnel_udp_config *res = parsed_result;
7905         struct rte_eth_udp_tunnel tunnel_udp;
7906         int ret;
7907
7908         tunnel_udp.udp_port = res->udp_port;
7909
7910         if (!strcmp(res->cmd, "rx_vxlan_port"))
7911                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7912
7913         if (!strcmp(res->what, "add"))
7914                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7915                                                       &tunnel_udp);
7916         else
7917                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7918                                                          &tunnel_udp);
7919
7920         if (ret < 0)
7921                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
7922 }
7923
7924 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7925         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7926                                 cmd, "rx_vxlan_port");
7927 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7928         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7929                                 what, "add#rm");
7930 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7931         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7932                                 udp_port, UINT16);
7933 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7934         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7935                                 port_id, UINT8);
7936
7937 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7938         .f = cmd_tunnel_udp_config_parsed,
7939         .data = (void *)0,
7940         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
7941                 "Add/Remove a tunneling UDP port filter",
7942         .tokens = {
7943                 (void *)&cmd_tunnel_udp_config_cmd,
7944                 (void *)&cmd_tunnel_udp_config_what,
7945                 (void *)&cmd_tunnel_udp_config_udp_port,
7946                 (void *)&cmd_tunnel_udp_config_port_id,
7947                 NULL,
7948         },
7949 };
7950
7951 /* *** GLOBAL CONFIG *** */
7952 struct cmd_global_config_result {
7953         cmdline_fixed_string_t cmd;
7954         uint8_t port_id;
7955         cmdline_fixed_string_t cfg_type;
7956         uint8_t len;
7957 };
7958
7959 static void
7960 cmd_global_config_parsed(void *parsed_result,
7961                          __attribute__((unused)) struct cmdline *cl,
7962                          __attribute__((unused)) void *data)
7963 {
7964         struct cmd_global_config_result *res = parsed_result;
7965         struct rte_eth_global_cfg conf;
7966         int ret;
7967
7968         memset(&conf, 0, sizeof(conf));
7969         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
7970         conf.cfg.gre_key_len = res->len;
7971         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
7972                                       RTE_ETH_FILTER_SET, &conf);
7973         if (ret != 0)
7974                 printf("Global config error\n");
7975 }
7976
7977 cmdline_parse_token_string_t cmd_global_config_cmd =
7978         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
7979                 "global_config");
7980 cmdline_parse_token_num_t cmd_global_config_port_id =
7981         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
7982 cmdline_parse_token_string_t cmd_global_config_type =
7983         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
7984                 cfg_type, "gre-key-len");
7985 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
7986         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
7987                 len, UINT8);
7988
7989 cmdline_parse_inst_t cmd_global_config = {
7990         .f = cmd_global_config_parsed,
7991         .data = (void *)NULL,
7992         .help_str = "global_config <port_id> gre-key-len <key_len>",
7993         .tokens = {
7994                 (void *)&cmd_global_config_cmd,
7995                 (void *)&cmd_global_config_port_id,
7996                 (void *)&cmd_global_config_type,
7997                 (void *)&cmd_global_config_gre_key_len,
7998                 NULL,
7999         },
8000 };
8001
8002 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8003 struct cmd_set_mirror_mask_result {
8004         cmdline_fixed_string_t set;
8005         cmdline_fixed_string_t port;
8006         uint8_t port_id;
8007         cmdline_fixed_string_t mirror;
8008         uint8_t rule_id;
8009         cmdline_fixed_string_t what;
8010         cmdline_fixed_string_t value;
8011         cmdline_fixed_string_t dstpool;
8012         uint8_t dstpool_id;
8013         cmdline_fixed_string_t on;
8014 };
8015
8016 cmdline_parse_token_string_t cmd_mirror_mask_set =
8017         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8018                                 set, "set");
8019 cmdline_parse_token_string_t cmd_mirror_mask_port =
8020         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8021                                 port, "port");
8022 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8023         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8024                                 port_id, UINT8);
8025 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8026         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8027                                 mirror, "mirror-rule");
8028 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8029         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8030                                 rule_id, UINT8);
8031 cmdline_parse_token_string_t cmd_mirror_mask_what =
8032         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8033                                 what, "pool-mirror-up#pool-mirror-down"
8034                                       "#vlan-mirror");
8035 cmdline_parse_token_string_t cmd_mirror_mask_value =
8036         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8037                                 value, NULL);
8038 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8039         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8040                                 dstpool, "dst-pool");
8041 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8042         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8043                                 dstpool_id, UINT8);
8044 cmdline_parse_token_string_t cmd_mirror_mask_on =
8045         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8046                                 on, "on#off");
8047
8048 static void
8049 cmd_set_mirror_mask_parsed(void *parsed_result,
8050                        __attribute__((unused)) struct cmdline *cl,
8051                        __attribute__((unused)) void *data)
8052 {
8053         int ret,nb_item,i;
8054         struct cmd_set_mirror_mask_result *res = parsed_result;
8055         struct rte_eth_mirror_conf mr_conf;
8056
8057         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8058
8059         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8060
8061         mr_conf.dst_pool = res->dstpool_id;
8062
8063         if (!strcmp(res->what, "pool-mirror-up")) {
8064                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8065                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8066         } else if (!strcmp(res->what, "pool-mirror-down")) {
8067                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8068                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8069         } else if (!strcmp(res->what, "vlan-mirror")) {
8070                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8071                 nb_item = parse_item_list(res->value, "vlan",
8072                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8073                 if (nb_item <= 0)
8074                         return;
8075
8076                 for (i = 0; i < nb_item; i++) {
8077                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8078                                 printf("Invalid vlan_id: must be < 4096\n");
8079                                 return;
8080                         }
8081
8082                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8083                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8084                 }
8085         }
8086
8087         if (!strcmp(res->on, "on"))
8088                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8089                                                 res->rule_id, 1);
8090         else
8091                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8092                                                 res->rule_id, 0);
8093         if (ret < 0)
8094                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8095 }
8096
8097 cmdline_parse_inst_t cmd_set_mirror_mask = {
8098                 .f = cmd_set_mirror_mask_parsed,
8099                 .data = NULL,
8100                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8101                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8102                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8103                 .tokens = {
8104                         (void *)&cmd_mirror_mask_set,
8105                         (void *)&cmd_mirror_mask_port,
8106                         (void *)&cmd_mirror_mask_portid,
8107                         (void *)&cmd_mirror_mask_mirror,
8108                         (void *)&cmd_mirror_mask_ruleid,
8109                         (void *)&cmd_mirror_mask_what,
8110                         (void *)&cmd_mirror_mask_value,
8111                         (void *)&cmd_mirror_mask_dstpool,
8112                         (void *)&cmd_mirror_mask_poolid,
8113                         (void *)&cmd_mirror_mask_on,
8114                         NULL,
8115                 },
8116 };
8117
8118 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8119 struct cmd_set_mirror_link_result {
8120         cmdline_fixed_string_t set;
8121         cmdline_fixed_string_t port;
8122         uint8_t port_id;
8123         cmdline_fixed_string_t mirror;
8124         uint8_t rule_id;
8125         cmdline_fixed_string_t what;
8126         cmdline_fixed_string_t dstpool;
8127         uint8_t dstpool_id;
8128         cmdline_fixed_string_t on;
8129 };
8130
8131 cmdline_parse_token_string_t cmd_mirror_link_set =
8132         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8133                                  set, "set");
8134 cmdline_parse_token_string_t cmd_mirror_link_port =
8135         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8136                                 port, "port");
8137 cmdline_parse_token_num_t cmd_mirror_link_portid =
8138         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8139                                 port_id, UINT8);
8140 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8141         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8142                                 mirror, "mirror-rule");
8143 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8144         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8145                             rule_id, UINT8);
8146 cmdline_parse_token_string_t cmd_mirror_link_what =
8147         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8148                                 what, "uplink-mirror#downlink-mirror");
8149 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8150         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8151                                 dstpool, "dst-pool");
8152 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8153         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8154                                 dstpool_id, UINT8);
8155 cmdline_parse_token_string_t cmd_mirror_link_on =
8156         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8157                                 on, "on#off");
8158
8159 static void
8160 cmd_set_mirror_link_parsed(void *parsed_result,
8161                        __attribute__((unused)) struct cmdline *cl,
8162                        __attribute__((unused)) void *data)
8163 {
8164         int ret;
8165         struct cmd_set_mirror_link_result *res = parsed_result;
8166         struct rte_eth_mirror_conf mr_conf;
8167
8168         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8169         if (!strcmp(res->what, "uplink-mirror"))
8170                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8171         else
8172                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8173
8174         mr_conf.dst_pool = res->dstpool_id;
8175
8176         if (!strcmp(res->on, "on"))
8177                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8178                                                 res->rule_id, 1);
8179         else
8180                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8181                                                 res->rule_id, 0);
8182
8183         /* check the return value and print it if is < 0 */
8184         if (ret < 0)
8185                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8186
8187 }
8188
8189 cmdline_parse_inst_t cmd_set_mirror_link = {
8190                 .f = cmd_set_mirror_link_parsed,
8191                 .data = NULL,
8192                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8193                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8194                 .tokens = {
8195                         (void *)&cmd_mirror_link_set,
8196                         (void *)&cmd_mirror_link_port,
8197                         (void *)&cmd_mirror_link_portid,
8198                         (void *)&cmd_mirror_link_mirror,
8199                         (void *)&cmd_mirror_link_ruleid,
8200                         (void *)&cmd_mirror_link_what,
8201                         (void *)&cmd_mirror_link_dstpool,
8202                         (void *)&cmd_mirror_link_poolid,
8203                         (void *)&cmd_mirror_link_on,
8204                         NULL,
8205                 },
8206 };
8207
8208 /* *** RESET VM MIRROR RULE *** */
8209 struct cmd_rm_mirror_rule_result {
8210         cmdline_fixed_string_t reset;
8211         cmdline_fixed_string_t port;
8212         uint8_t port_id;
8213         cmdline_fixed_string_t mirror;
8214         uint8_t rule_id;
8215 };
8216
8217 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8218         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8219                                  reset, "reset");
8220 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8221         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8222                                 port, "port");
8223 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8224         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8225                                 port_id, UINT8);
8226 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8227         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8228                                 mirror, "mirror-rule");
8229 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8230         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8231                                 rule_id, UINT8);
8232
8233 static void
8234 cmd_reset_mirror_rule_parsed(void *parsed_result,
8235                        __attribute__((unused)) struct cmdline *cl,
8236                        __attribute__((unused)) void *data)
8237 {
8238         int ret;
8239         struct cmd_set_mirror_link_result *res = parsed_result;
8240         /* check rule_id */
8241         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8242         if(ret < 0)
8243                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8244 }
8245
8246 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8247                 .f = cmd_reset_mirror_rule_parsed,
8248                 .data = NULL,
8249                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8250                 .tokens = {
8251                         (void *)&cmd_rm_mirror_rule_reset,
8252                         (void *)&cmd_rm_mirror_rule_port,
8253                         (void *)&cmd_rm_mirror_rule_portid,
8254                         (void *)&cmd_rm_mirror_rule_mirror,
8255                         (void *)&cmd_rm_mirror_rule_ruleid,
8256                         NULL,
8257                 },
8258 };
8259
8260 /* ******************************************************************************** */
8261
8262 struct cmd_dump_result {
8263         cmdline_fixed_string_t dump;
8264 };
8265
8266 static void
8267 dump_struct_sizes(void)
8268 {
8269 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8270         DUMP_SIZE(struct rte_mbuf);
8271         DUMP_SIZE(struct rte_mempool);
8272         DUMP_SIZE(struct rte_ring);
8273 #undef DUMP_SIZE
8274 }
8275
8276 static void cmd_dump_parsed(void *parsed_result,
8277                             __attribute__((unused)) struct cmdline *cl,
8278                             __attribute__((unused)) void *data)
8279 {
8280         struct cmd_dump_result *res = parsed_result;
8281
8282         if (!strcmp(res->dump, "dump_physmem"))
8283                 rte_dump_physmem_layout(stdout);
8284         else if (!strcmp(res->dump, "dump_memzone"))
8285                 rte_memzone_dump(stdout);
8286         else if (!strcmp(res->dump, "dump_struct_sizes"))
8287                 dump_struct_sizes();
8288         else if (!strcmp(res->dump, "dump_ring"))
8289                 rte_ring_list_dump(stdout);
8290         else if (!strcmp(res->dump, "dump_mempool"))
8291                 rte_mempool_list_dump(stdout);
8292         else if (!strcmp(res->dump, "dump_devargs"))
8293                 rte_eal_devargs_dump(stdout);
8294         else if (!strcmp(res->dump, "dump_log_types"))
8295                 rte_log_dump(stdout);
8296 }
8297
8298 cmdline_parse_token_string_t cmd_dump_dump =
8299         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8300                 "dump_physmem#"
8301                 "dump_memzone#"
8302                 "dump_struct_sizes#"
8303                 "dump_ring#"
8304                 "dump_mempool#"
8305                 "dump_devargs#"
8306                 "dump_log_types");
8307
8308 cmdline_parse_inst_t cmd_dump = {
8309         .f = cmd_dump_parsed,  /* function to call */
8310         .data = NULL,      /* 2nd arg of func */
8311         .help_str = "Dump status",
8312         .tokens = {        /* token list, NULL terminated */
8313                 (void *)&cmd_dump_dump,
8314                 NULL,
8315         },
8316 };
8317
8318 /* ******************************************************************************** */
8319
8320 struct cmd_dump_one_result {
8321         cmdline_fixed_string_t dump;
8322         cmdline_fixed_string_t name;
8323 };
8324
8325 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8326                                 __attribute__((unused)) void *data)
8327 {
8328         struct cmd_dump_one_result *res = parsed_result;
8329
8330         if (!strcmp(res->dump, "dump_ring")) {
8331                 struct rte_ring *r;
8332                 r = rte_ring_lookup(res->name);
8333                 if (r == NULL) {
8334                         cmdline_printf(cl, "Cannot find ring\n");
8335                         return;
8336                 }
8337                 rte_ring_dump(stdout, r);
8338         } else if (!strcmp(res->dump, "dump_mempool")) {
8339                 struct rte_mempool *mp;
8340                 mp = rte_mempool_lookup(res->name);
8341                 if (mp == NULL) {
8342                         cmdline_printf(cl, "Cannot find mempool\n");
8343                         return;
8344                 }
8345                 rte_mempool_dump(stdout, mp);
8346         }
8347 }
8348
8349 cmdline_parse_token_string_t cmd_dump_one_dump =
8350         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8351                                  "dump_ring#dump_mempool");
8352
8353 cmdline_parse_token_string_t cmd_dump_one_name =
8354         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8355
8356 cmdline_parse_inst_t cmd_dump_one = {
8357         .f = cmd_dump_one_parsed,  /* function to call */
8358         .data = NULL,      /* 2nd arg of func */
8359         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8360         .tokens = {        /* token list, NULL terminated */
8361                 (void *)&cmd_dump_one_dump,
8362                 (void *)&cmd_dump_one_name,
8363                 NULL,
8364         },
8365 };
8366
8367 /* *** Add/Del syn filter *** */
8368 struct cmd_syn_filter_result {
8369         cmdline_fixed_string_t filter;
8370         uint8_t port_id;
8371         cmdline_fixed_string_t ops;
8372         cmdline_fixed_string_t priority;
8373         cmdline_fixed_string_t high;
8374         cmdline_fixed_string_t queue;
8375         uint16_t queue_id;
8376 };
8377
8378 static void
8379 cmd_syn_filter_parsed(void *parsed_result,
8380                         __attribute__((unused)) struct cmdline *cl,
8381                         __attribute__((unused)) void *data)
8382 {
8383         struct cmd_syn_filter_result *res = parsed_result;
8384         struct rte_eth_syn_filter syn_filter;
8385         int ret = 0;
8386
8387         ret = rte_eth_dev_filter_supported(res->port_id,
8388                                         RTE_ETH_FILTER_SYN);
8389         if (ret < 0) {
8390                 printf("syn filter is not supported on port %u.\n",
8391                                 res->port_id);
8392                 return;
8393         }
8394
8395         memset(&syn_filter, 0, sizeof(syn_filter));
8396
8397         if (!strcmp(res->ops, "add")) {
8398                 if (!strcmp(res->high, "high"))
8399                         syn_filter.hig_pri = 1;
8400                 else
8401                         syn_filter.hig_pri = 0;
8402
8403                 syn_filter.queue = res->queue_id;
8404                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8405                                                 RTE_ETH_FILTER_SYN,
8406                                                 RTE_ETH_FILTER_ADD,
8407                                                 &syn_filter);
8408         } else
8409                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8410                                                 RTE_ETH_FILTER_SYN,
8411                                                 RTE_ETH_FILTER_DELETE,
8412                                                 &syn_filter);
8413
8414         if (ret < 0)
8415                 printf("syn filter programming error: (%s)\n",
8416                                 strerror(-ret));
8417 }
8418
8419 cmdline_parse_token_string_t cmd_syn_filter_filter =
8420         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8421         filter, "syn_filter");
8422 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8423         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8424         port_id, UINT8);
8425 cmdline_parse_token_string_t cmd_syn_filter_ops =
8426         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8427         ops, "add#del");
8428 cmdline_parse_token_string_t cmd_syn_filter_priority =
8429         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8430                                 priority, "priority");
8431 cmdline_parse_token_string_t cmd_syn_filter_high =
8432         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8433                                 high, "high#low");
8434 cmdline_parse_token_string_t cmd_syn_filter_queue =
8435         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8436                                 queue, "queue");
8437 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8438         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8439                                 queue_id, UINT16);
8440
8441 cmdline_parse_inst_t cmd_syn_filter = {
8442         .f = cmd_syn_filter_parsed,
8443         .data = NULL,
8444         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8445                 "<queue_id>: Add/Delete syn filter",
8446         .tokens = {
8447                 (void *)&cmd_syn_filter_filter,
8448                 (void *)&cmd_syn_filter_port_id,
8449                 (void *)&cmd_syn_filter_ops,
8450                 (void *)&cmd_syn_filter_priority,
8451                 (void *)&cmd_syn_filter_high,
8452                 (void *)&cmd_syn_filter_queue,
8453                 (void *)&cmd_syn_filter_queue_id,
8454                 NULL,
8455         },
8456 };
8457
8458 /* *** ADD/REMOVE A 2tuple FILTER *** */
8459 struct cmd_2tuple_filter_result {
8460         cmdline_fixed_string_t filter;
8461         uint8_t  port_id;
8462         cmdline_fixed_string_t ops;
8463         cmdline_fixed_string_t dst_port;
8464         uint16_t dst_port_value;
8465         cmdline_fixed_string_t protocol;
8466         uint8_t protocol_value;
8467         cmdline_fixed_string_t mask;
8468         uint8_t  mask_value;
8469         cmdline_fixed_string_t tcp_flags;
8470         uint8_t tcp_flags_value;
8471         cmdline_fixed_string_t priority;
8472         uint8_t  priority_value;
8473         cmdline_fixed_string_t queue;
8474         uint16_t  queue_id;
8475 };
8476
8477 static void
8478 cmd_2tuple_filter_parsed(void *parsed_result,
8479                         __attribute__((unused)) struct cmdline *cl,
8480                         __attribute__((unused)) void *data)
8481 {
8482         struct rte_eth_ntuple_filter filter;
8483         struct cmd_2tuple_filter_result *res = parsed_result;
8484         int ret = 0;
8485
8486         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8487         if (ret < 0) {
8488                 printf("ntuple filter is not supported on port %u.\n",
8489                         res->port_id);
8490                 return;
8491         }
8492
8493         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8494
8495         filter.flags = RTE_2TUPLE_FLAGS;
8496         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8497         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8498         filter.proto = res->protocol_value;
8499         filter.priority = res->priority_value;
8500         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8501                 printf("nonzero tcp_flags is only meaningful"
8502                         " when protocol is TCP.\n");
8503                 return;
8504         }
8505         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8506                 printf("invalid TCP flags.\n");
8507                 return;
8508         }
8509
8510         if (res->tcp_flags_value != 0) {
8511                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8512                 filter.tcp_flags = res->tcp_flags_value;
8513         }
8514
8515         /* need convert to big endian. */
8516         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8517         filter.queue = res->queue_id;
8518
8519         if (!strcmp(res->ops, "add"))
8520                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8521                                 RTE_ETH_FILTER_NTUPLE,
8522                                 RTE_ETH_FILTER_ADD,
8523                                 &filter);
8524         else
8525                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8526                                 RTE_ETH_FILTER_NTUPLE,
8527                                 RTE_ETH_FILTER_DELETE,
8528                                 &filter);
8529         if (ret < 0)
8530                 printf("2tuple filter programming error: (%s)\n",
8531                         strerror(-ret));
8532
8533 }
8534
8535 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
8536         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8537                                  filter, "2tuple_filter");
8538 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
8539         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8540                                 port_id, UINT8);
8541 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
8542         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8543                                  ops, "add#del");
8544 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
8545         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8546                                 dst_port, "dst_port");
8547 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
8548         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8549                                 dst_port_value, UINT16);
8550 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
8551         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8552                                 protocol, "protocol");
8553 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
8554         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8555                                 protocol_value, UINT8);
8556 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
8557         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8558                                 mask, "mask");
8559 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
8560         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8561                                 mask_value, INT8);
8562 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
8563         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8564                                 tcp_flags, "tcp_flags");
8565 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
8566         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8567                                 tcp_flags_value, UINT8);
8568 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
8569         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8570                                 priority, "priority");
8571 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
8572         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8573                                 priority_value, UINT8);
8574 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
8575         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8576                                 queue, "queue");
8577 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
8578         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8579                                 queue_id, UINT16);
8580
8581 cmdline_parse_inst_t cmd_2tuple_filter = {
8582         .f = cmd_2tuple_filter_parsed,
8583         .data = NULL,
8584         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
8585                 "<value> mask <value> tcp_flags <value> priority <value> queue "
8586                 "<queue_id>: Add a 2tuple filter",
8587         .tokens = {
8588                 (void *)&cmd_2tuple_filter_filter,
8589                 (void *)&cmd_2tuple_filter_port_id,
8590                 (void *)&cmd_2tuple_filter_ops,
8591                 (void *)&cmd_2tuple_filter_dst_port,
8592                 (void *)&cmd_2tuple_filter_dst_port_value,
8593                 (void *)&cmd_2tuple_filter_protocol,
8594                 (void *)&cmd_2tuple_filter_protocol_value,
8595                 (void *)&cmd_2tuple_filter_mask,
8596                 (void *)&cmd_2tuple_filter_mask_value,
8597                 (void *)&cmd_2tuple_filter_tcp_flags,
8598                 (void *)&cmd_2tuple_filter_tcp_flags_value,
8599                 (void *)&cmd_2tuple_filter_priority,
8600                 (void *)&cmd_2tuple_filter_priority_value,
8601                 (void *)&cmd_2tuple_filter_queue,
8602                 (void *)&cmd_2tuple_filter_queue_id,
8603                 NULL,
8604         },
8605 };
8606
8607 /* *** ADD/REMOVE A 5tuple FILTER *** */
8608 struct cmd_5tuple_filter_result {
8609         cmdline_fixed_string_t filter;
8610         uint8_t  port_id;
8611         cmdline_fixed_string_t ops;
8612         cmdline_fixed_string_t dst_ip;
8613         cmdline_ipaddr_t dst_ip_value;
8614         cmdline_fixed_string_t src_ip;
8615         cmdline_ipaddr_t src_ip_value;
8616         cmdline_fixed_string_t dst_port;
8617         uint16_t dst_port_value;
8618         cmdline_fixed_string_t src_port;
8619         uint16_t src_port_value;
8620         cmdline_fixed_string_t protocol;
8621         uint8_t protocol_value;
8622         cmdline_fixed_string_t mask;
8623         uint8_t  mask_value;
8624         cmdline_fixed_string_t tcp_flags;
8625         uint8_t tcp_flags_value;
8626         cmdline_fixed_string_t priority;
8627         uint8_t  priority_value;
8628         cmdline_fixed_string_t queue;
8629         uint16_t  queue_id;
8630 };
8631
8632 static void
8633 cmd_5tuple_filter_parsed(void *parsed_result,
8634                         __attribute__((unused)) struct cmdline *cl,
8635                         __attribute__((unused)) void *data)
8636 {
8637         struct rte_eth_ntuple_filter filter;
8638         struct cmd_5tuple_filter_result *res = parsed_result;
8639         int ret = 0;
8640
8641         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8642         if (ret < 0) {
8643                 printf("ntuple filter is not supported on port %u.\n",
8644                         res->port_id);
8645                 return;
8646         }
8647
8648         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8649
8650         filter.flags = RTE_5TUPLE_FLAGS;
8651         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
8652         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
8653         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
8654         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8655         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8656         filter.proto = res->protocol_value;
8657         filter.priority = res->priority_value;
8658         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8659                 printf("nonzero tcp_flags is only meaningful"
8660                         " when protocol is TCP.\n");
8661                 return;
8662         }
8663         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8664                 printf("invalid TCP flags.\n");
8665                 return;
8666         }
8667
8668         if (res->tcp_flags_value != 0) {
8669                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8670                 filter.tcp_flags = res->tcp_flags_value;
8671         }
8672
8673         if (res->dst_ip_value.family == AF_INET)
8674                 /* no need to convert, already big endian. */
8675                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
8676         else {
8677                 if (filter.dst_ip_mask == 0) {
8678                         printf("can not support ipv6 involved compare.\n");
8679                         return;
8680                 }
8681                 filter.dst_ip = 0;
8682         }
8683
8684         if (res->src_ip_value.family == AF_INET)
8685                 /* no need to convert, already big endian. */
8686                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
8687         else {
8688                 if (filter.src_ip_mask == 0) {
8689                         printf("can not support ipv6 involved compare.\n");
8690                         return;
8691                 }
8692                 filter.src_ip = 0;
8693         }
8694         /* need convert to big endian. */
8695         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8696         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
8697         filter.queue = res->queue_id;
8698
8699         if (!strcmp(res->ops, "add"))
8700                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8701                                 RTE_ETH_FILTER_NTUPLE,
8702                                 RTE_ETH_FILTER_ADD,
8703                                 &filter);
8704         else
8705                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8706                                 RTE_ETH_FILTER_NTUPLE,
8707                                 RTE_ETH_FILTER_DELETE,
8708                                 &filter);
8709         if (ret < 0)
8710                 printf("5tuple filter programming error: (%s)\n",
8711                         strerror(-ret));
8712 }
8713
8714 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
8715         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8716                                  filter, "5tuple_filter");
8717 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
8718         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8719                                 port_id, UINT8);
8720 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
8721         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8722                                  ops, "add#del");
8723 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
8724         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8725                                 dst_ip, "dst_ip");
8726 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
8727         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8728                                 dst_ip_value);
8729 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
8730         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8731                                 src_ip, "src_ip");
8732 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
8733         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8734                                 src_ip_value);
8735 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
8736         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8737                                 dst_port, "dst_port");
8738 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
8739         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8740                                 dst_port_value, UINT16);
8741 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
8742         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8743                                 src_port, "src_port");
8744 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
8745         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8746                                 src_port_value, UINT16);
8747 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
8748         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8749                                 protocol, "protocol");
8750 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
8751         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8752                                 protocol_value, UINT8);
8753 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
8754         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8755                                 mask, "mask");
8756 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
8757         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8758                                 mask_value, INT8);
8759 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
8760         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8761                                 tcp_flags, "tcp_flags");
8762 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
8763         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8764                                 tcp_flags_value, UINT8);
8765 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
8766         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8767                                 priority, "priority");
8768 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
8769         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8770                                 priority_value, UINT8);
8771 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
8772         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8773                                 queue, "queue");
8774 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
8775         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8776                                 queue_id, UINT16);
8777
8778 cmdline_parse_inst_t cmd_5tuple_filter = {
8779         .f = cmd_5tuple_filter_parsed,
8780         .data = NULL,
8781         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
8782                 "src_ip <value> dst_port <value> src_port <value> "
8783                 "protocol <value>  mask <value> tcp_flags <value> "
8784                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
8785         .tokens = {
8786                 (void *)&cmd_5tuple_filter_filter,
8787                 (void *)&cmd_5tuple_filter_port_id,
8788                 (void *)&cmd_5tuple_filter_ops,
8789                 (void *)&cmd_5tuple_filter_dst_ip,
8790                 (void *)&cmd_5tuple_filter_dst_ip_value,
8791                 (void *)&cmd_5tuple_filter_src_ip,
8792                 (void *)&cmd_5tuple_filter_src_ip_value,
8793                 (void *)&cmd_5tuple_filter_dst_port,
8794                 (void *)&cmd_5tuple_filter_dst_port_value,
8795                 (void *)&cmd_5tuple_filter_src_port,
8796                 (void *)&cmd_5tuple_filter_src_port_value,
8797                 (void *)&cmd_5tuple_filter_protocol,
8798                 (void *)&cmd_5tuple_filter_protocol_value,
8799                 (void *)&cmd_5tuple_filter_mask,
8800                 (void *)&cmd_5tuple_filter_mask_value,
8801                 (void *)&cmd_5tuple_filter_tcp_flags,
8802                 (void *)&cmd_5tuple_filter_tcp_flags_value,
8803                 (void *)&cmd_5tuple_filter_priority,
8804                 (void *)&cmd_5tuple_filter_priority_value,
8805                 (void *)&cmd_5tuple_filter_queue,
8806                 (void *)&cmd_5tuple_filter_queue_id,
8807                 NULL,
8808         },
8809 };
8810
8811 /* *** ADD/REMOVE A flex FILTER *** */
8812 struct cmd_flex_filter_result {
8813         cmdline_fixed_string_t filter;
8814         cmdline_fixed_string_t ops;
8815         uint8_t port_id;
8816         cmdline_fixed_string_t len;
8817         uint8_t len_value;
8818         cmdline_fixed_string_t bytes;
8819         cmdline_fixed_string_t bytes_value;
8820         cmdline_fixed_string_t mask;
8821         cmdline_fixed_string_t mask_value;
8822         cmdline_fixed_string_t priority;
8823         uint8_t priority_value;
8824         cmdline_fixed_string_t queue;
8825         uint16_t queue_id;
8826 };
8827
8828 static int xdigit2val(unsigned char c)
8829 {
8830         int val;
8831         if (isdigit(c))
8832                 val = c - '0';
8833         else if (isupper(c))
8834                 val = c - 'A' + 10;
8835         else
8836                 val = c - 'a' + 10;
8837         return val;
8838 }
8839
8840 static void
8841 cmd_flex_filter_parsed(void *parsed_result,
8842                           __attribute__((unused)) struct cmdline *cl,
8843                           __attribute__((unused)) void *data)
8844 {
8845         int ret = 0;
8846         struct rte_eth_flex_filter filter;
8847         struct cmd_flex_filter_result *res = parsed_result;
8848         char *bytes_ptr, *mask_ptr;
8849         uint16_t len, i, j = 0;
8850         char c;
8851         int val;
8852         uint8_t byte = 0;
8853
8854         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
8855                 printf("the len exceed the max length 128\n");
8856                 return;
8857         }
8858         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
8859         filter.len = res->len_value;
8860         filter.priority = res->priority_value;
8861         filter.queue = res->queue_id;
8862         bytes_ptr = res->bytes_value;
8863         mask_ptr = res->mask_value;
8864
8865          /* translate bytes string to array. */
8866         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
8867                 (bytes_ptr[1] == 'X')))
8868                 bytes_ptr += 2;
8869         len = strnlen(bytes_ptr, res->len_value * 2);
8870         if (len == 0 || (len % 8 != 0)) {
8871                 printf("please check len and bytes input\n");
8872                 return;
8873         }
8874         for (i = 0; i < len; i++) {
8875                 c = bytes_ptr[i];
8876                 if (isxdigit(c) == 0) {
8877                         /* invalid characters. */
8878                         printf("invalid input\n");
8879                         return;
8880                 }
8881                 val = xdigit2val(c);
8882                 if (i % 2) {
8883                         byte |= val;
8884                         filter.bytes[j] = byte;
8885                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
8886                         j++;
8887                         byte = 0;
8888                 } else
8889                         byte |= val << 4;
8890         }
8891         printf("\n");
8892          /* translate mask string to uint8_t array. */
8893         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
8894                 (mask_ptr[1] == 'X')))
8895                 mask_ptr += 2;
8896         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
8897         if (len == 0) {
8898                 printf("invalid input\n");
8899                 return;
8900         }
8901         j = 0;
8902         byte = 0;
8903         for (i = 0; i < len; i++) {
8904                 c = mask_ptr[i];
8905                 if (isxdigit(c) == 0) {
8906                         /* invalid characters. */
8907                         printf("invalid input\n");
8908                         return;
8909                 }
8910                 val = xdigit2val(c);
8911                 if (i % 2) {
8912                         byte |= val;
8913                         filter.mask[j] = byte;
8914                         printf("mask[%d]:%02x ", j, filter.mask[j]);
8915                         j++;
8916                         byte = 0;
8917                 } else
8918                         byte |= val << 4;
8919         }
8920         printf("\n");
8921
8922         if (!strcmp(res->ops, "add"))
8923                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8924                                 RTE_ETH_FILTER_FLEXIBLE,
8925                                 RTE_ETH_FILTER_ADD,
8926                                 &filter);
8927         else
8928                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8929                                 RTE_ETH_FILTER_FLEXIBLE,
8930                                 RTE_ETH_FILTER_DELETE,
8931                                 &filter);
8932
8933         if (ret < 0)
8934                 printf("flex filter setting error: (%s)\n", strerror(-ret));
8935 }
8936
8937 cmdline_parse_token_string_t cmd_flex_filter_filter =
8938         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8939                                 filter, "flex_filter");
8940 cmdline_parse_token_num_t cmd_flex_filter_port_id =
8941         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8942                                 port_id, UINT8);
8943 cmdline_parse_token_string_t cmd_flex_filter_ops =
8944         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8945                                 ops, "add#del");
8946 cmdline_parse_token_string_t cmd_flex_filter_len =
8947         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8948                                 len, "len");
8949 cmdline_parse_token_num_t cmd_flex_filter_len_value =
8950         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8951                                 len_value, UINT8);
8952 cmdline_parse_token_string_t cmd_flex_filter_bytes =
8953         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8954                                 bytes, "bytes");
8955 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
8956         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8957                                 bytes_value, NULL);
8958 cmdline_parse_token_string_t cmd_flex_filter_mask =
8959         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8960                                 mask, "mask");
8961 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
8962         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8963                                 mask_value, NULL);
8964 cmdline_parse_token_string_t cmd_flex_filter_priority =
8965         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8966                                 priority, "priority");
8967 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
8968         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8969                                 priority_value, UINT8);
8970 cmdline_parse_token_string_t cmd_flex_filter_queue =
8971         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8972                                 queue, "queue");
8973 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
8974         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8975                                 queue_id, UINT16);
8976 cmdline_parse_inst_t cmd_flex_filter = {
8977         .f = cmd_flex_filter_parsed,
8978         .data = NULL,
8979         .help_str = "flex_filter <port_id> add|del len <value> bytes "
8980                 "<value> mask <value> priority <value> queue <queue_id>: "
8981                 "Add/Del a flex filter",
8982         .tokens = {
8983                 (void *)&cmd_flex_filter_filter,
8984                 (void *)&cmd_flex_filter_port_id,
8985                 (void *)&cmd_flex_filter_ops,
8986                 (void *)&cmd_flex_filter_len,
8987                 (void *)&cmd_flex_filter_len_value,
8988                 (void *)&cmd_flex_filter_bytes,
8989                 (void *)&cmd_flex_filter_bytes_value,
8990                 (void *)&cmd_flex_filter_mask,
8991                 (void *)&cmd_flex_filter_mask_value,
8992                 (void *)&cmd_flex_filter_priority,
8993                 (void *)&cmd_flex_filter_priority_value,
8994                 (void *)&cmd_flex_filter_queue,
8995                 (void *)&cmd_flex_filter_queue_id,
8996                 NULL,
8997         },
8998 };
8999
9000 /* *** Filters Control *** */
9001
9002 /* *** deal with ethertype filter *** */
9003 struct cmd_ethertype_filter_result {
9004         cmdline_fixed_string_t filter;
9005         uint8_t port_id;
9006         cmdline_fixed_string_t ops;
9007         cmdline_fixed_string_t mac;
9008         struct ether_addr mac_addr;
9009         cmdline_fixed_string_t ethertype;
9010         uint16_t ethertype_value;
9011         cmdline_fixed_string_t drop;
9012         cmdline_fixed_string_t queue;
9013         uint16_t  queue_id;
9014 };
9015
9016 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9017         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9018                                  filter, "ethertype_filter");
9019 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9020         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9021                               port_id, UINT8);
9022 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9023         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9024                                  ops, "add#del");
9025 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9026         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9027                                  mac, "mac_addr#mac_ignr");
9028 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9029         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9030                                      mac_addr);
9031 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9032         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9033                                  ethertype, "ethertype");
9034 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9035         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9036                               ethertype_value, UINT16);
9037 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9038         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9039                                  drop, "drop#fwd");
9040 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9041         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9042                                  queue, "queue");
9043 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9044         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9045                               queue_id, UINT16);
9046
9047 static void
9048 cmd_ethertype_filter_parsed(void *parsed_result,
9049                           __attribute__((unused)) struct cmdline *cl,
9050                           __attribute__((unused)) void *data)
9051 {
9052         struct cmd_ethertype_filter_result *res = parsed_result;
9053         struct rte_eth_ethertype_filter filter;
9054         int ret = 0;
9055
9056         ret = rte_eth_dev_filter_supported(res->port_id,
9057                         RTE_ETH_FILTER_ETHERTYPE);
9058         if (ret < 0) {
9059                 printf("ethertype filter is not supported on port %u.\n",
9060                         res->port_id);
9061                 return;
9062         }
9063
9064         memset(&filter, 0, sizeof(filter));
9065         if (!strcmp(res->mac, "mac_addr")) {
9066                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9067                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9068                         sizeof(struct ether_addr));
9069         }
9070         if (!strcmp(res->drop, "drop"))
9071                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9072         filter.ether_type = res->ethertype_value;
9073         filter.queue = res->queue_id;
9074
9075         if (!strcmp(res->ops, "add"))
9076                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9077                                 RTE_ETH_FILTER_ETHERTYPE,
9078                                 RTE_ETH_FILTER_ADD,
9079                                 &filter);
9080         else
9081                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9082                                 RTE_ETH_FILTER_ETHERTYPE,
9083                                 RTE_ETH_FILTER_DELETE,
9084                                 &filter);
9085         if (ret < 0)
9086                 printf("ethertype filter programming error: (%s)\n",
9087                         strerror(-ret));
9088 }
9089
9090 cmdline_parse_inst_t cmd_ethertype_filter = {
9091         .f = cmd_ethertype_filter_parsed,
9092         .data = NULL,
9093         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9094                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9095                 "Add or delete an ethertype filter entry",
9096         .tokens = {
9097                 (void *)&cmd_ethertype_filter_filter,
9098                 (void *)&cmd_ethertype_filter_port_id,
9099                 (void *)&cmd_ethertype_filter_ops,
9100                 (void *)&cmd_ethertype_filter_mac,
9101                 (void *)&cmd_ethertype_filter_mac_addr,
9102                 (void *)&cmd_ethertype_filter_ethertype,
9103                 (void *)&cmd_ethertype_filter_ethertype_value,
9104                 (void *)&cmd_ethertype_filter_drop,
9105                 (void *)&cmd_ethertype_filter_queue,
9106                 (void *)&cmd_ethertype_filter_queue_id,
9107                 NULL,
9108         },
9109 };
9110
9111 /* *** deal with flow director filter *** */
9112 struct cmd_flow_director_result {
9113         cmdline_fixed_string_t flow_director_filter;
9114         uint8_t port_id;
9115         cmdline_fixed_string_t mode;
9116         cmdline_fixed_string_t mode_value;
9117         cmdline_fixed_string_t ops;
9118         cmdline_fixed_string_t flow;
9119         cmdline_fixed_string_t flow_type;
9120         cmdline_fixed_string_t ether;
9121         uint16_t ether_type;
9122         cmdline_fixed_string_t src;
9123         cmdline_ipaddr_t ip_src;
9124         uint16_t port_src;
9125         cmdline_fixed_string_t dst;
9126         cmdline_ipaddr_t ip_dst;
9127         uint16_t port_dst;
9128         cmdline_fixed_string_t verify_tag;
9129         uint32_t verify_tag_value;
9130         cmdline_ipaddr_t tos;
9131         uint8_t tos_value;
9132         cmdline_ipaddr_t proto;
9133         uint8_t proto_value;
9134         cmdline_ipaddr_t ttl;
9135         uint8_t ttl_value;
9136         cmdline_fixed_string_t vlan;
9137         uint16_t vlan_value;
9138         cmdline_fixed_string_t flexbytes;
9139         cmdline_fixed_string_t flexbytes_value;
9140         cmdline_fixed_string_t pf_vf;
9141         cmdline_fixed_string_t drop;
9142         cmdline_fixed_string_t queue;
9143         uint16_t  queue_id;
9144         cmdline_fixed_string_t fd_id;
9145         uint32_t  fd_id_value;
9146         cmdline_fixed_string_t mac;
9147         struct ether_addr mac_addr;
9148         cmdline_fixed_string_t tunnel;
9149         cmdline_fixed_string_t tunnel_type;
9150         cmdline_fixed_string_t tunnel_id;
9151         uint32_t tunnel_id_value;
9152 };
9153
9154 static inline int
9155 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9156 {
9157         char s[256];
9158         const char *p, *p0 = q_arg;
9159         char *end;
9160         unsigned long int_fld;
9161         char *str_fld[max_num];
9162         int i;
9163         unsigned size;
9164         int ret = -1;
9165
9166         p = strchr(p0, '(');
9167         if (p == NULL)
9168                 return -1;
9169         ++p;
9170         p0 = strchr(p, ')');
9171         if (p0 == NULL)
9172                 return -1;
9173
9174         size = p0 - p;
9175         if (size >= sizeof(s))
9176                 return -1;
9177
9178         snprintf(s, sizeof(s), "%.*s", size, p);
9179         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9180         if (ret < 0 || ret > max_num)
9181                 return -1;
9182         for (i = 0; i < ret; i++) {
9183                 errno = 0;
9184                 int_fld = strtoul(str_fld[i], &end, 0);
9185                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9186                         return -1;
9187                 flexbytes[i] = (uint8_t)int_fld;
9188         }
9189         return ret;
9190 }
9191
9192 static uint16_t
9193 str2flowtype(char *string)
9194 {
9195         uint8_t i = 0;
9196         static const struct {
9197                 char str[32];
9198                 uint16_t type;
9199         } flowtype_str[] = {
9200                 {"raw", RTE_ETH_FLOW_RAW},
9201                 {"ipv4", RTE_ETH_FLOW_IPV4},
9202                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9203                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9204                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9205                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9206                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9207                 {"ipv6", RTE_ETH_FLOW_IPV6},
9208                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9209                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9210                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9211                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9212                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9213                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9214         };
9215
9216         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9217                 if (!strcmp(flowtype_str[i].str, string))
9218                         return flowtype_str[i].type;
9219         }
9220
9221         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9222                 return (uint16_t)atoi(string);
9223
9224         return RTE_ETH_FLOW_UNKNOWN;
9225 }
9226
9227 static enum rte_eth_fdir_tunnel_type
9228 str2fdir_tunneltype(char *string)
9229 {
9230         uint8_t i = 0;
9231
9232         static const struct {
9233                 char str[32];
9234                 enum rte_eth_fdir_tunnel_type type;
9235         } tunneltype_str[] = {
9236                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9237                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9238         };
9239
9240         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9241                 if (!strcmp(tunneltype_str[i].str, string))
9242                         return tunneltype_str[i].type;
9243         }
9244         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9245 }
9246
9247 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9248 do { \
9249         if ((ip_addr).family == AF_INET) \
9250                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9251         else { \
9252                 printf("invalid parameter.\n"); \
9253                 return; \
9254         } \
9255 } while (0)
9256
9257 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9258 do { \
9259         if ((ip_addr).family == AF_INET6) \
9260                 rte_memcpy(&(ip), \
9261                                  &((ip_addr).addr.ipv6), \
9262                                  sizeof(struct in6_addr)); \
9263         else { \
9264                 printf("invalid parameter.\n"); \
9265                 return; \
9266         } \
9267 } while (0)
9268
9269 static void
9270 cmd_flow_director_filter_parsed(void *parsed_result,
9271                           __attribute__((unused)) struct cmdline *cl,
9272                           __attribute__((unused)) void *data)
9273 {
9274         struct cmd_flow_director_result *res = parsed_result;
9275         struct rte_eth_fdir_filter entry;
9276         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9277         char *end;
9278         unsigned long vf_id;
9279         int ret = 0;
9280
9281         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9282         if (ret < 0) {
9283                 printf("flow director is not supported on port %u.\n",
9284                         res->port_id);
9285                 return;
9286         }
9287         memset(flexbytes, 0, sizeof(flexbytes));
9288         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9289
9290         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9291                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9292                         printf("Please set mode to MAC-VLAN.\n");
9293                         return;
9294                 }
9295         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9296                 if (strcmp(res->mode_value, "Tunnel")) {
9297                         printf("Please set mode to Tunnel.\n");
9298                         return;
9299                 }
9300         } else {
9301                 if (strcmp(res->mode_value, "IP")) {
9302                         printf("Please set mode to IP.\n");
9303                         return;
9304                 }
9305                 entry.input.flow_type = str2flowtype(res->flow_type);
9306         }
9307
9308         ret = parse_flexbytes(res->flexbytes_value,
9309                                         flexbytes,
9310                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9311         if (ret < 0) {
9312                 printf("error: Cannot parse flexbytes input.\n");
9313                 return;
9314         }
9315
9316         switch (entry.input.flow_type) {
9317         case RTE_ETH_FLOW_FRAG_IPV4:
9318         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9319                 entry.input.flow.ip4_flow.proto = res->proto_value;
9320                 /* fall-through */
9321         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9322         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9323                 IPV4_ADDR_TO_UINT(res->ip_dst,
9324                         entry.input.flow.ip4_flow.dst_ip);
9325                 IPV4_ADDR_TO_UINT(res->ip_src,
9326                         entry.input.flow.ip4_flow.src_ip);
9327                 entry.input.flow.ip4_flow.tos = res->tos_value;
9328                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9329                 /* need convert to big endian. */
9330                 entry.input.flow.udp4_flow.dst_port =
9331                                 rte_cpu_to_be_16(res->port_dst);
9332                 entry.input.flow.udp4_flow.src_port =
9333                                 rte_cpu_to_be_16(res->port_src);
9334                 break;
9335         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9336                 IPV4_ADDR_TO_UINT(res->ip_dst,
9337                         entry.input.flow.sctp4_flow.ip.dst_ip);
9338                 IPV4_ADDR_TO_UINT(res->ip_src,
9339                         entry.input.flow.sctp4_flow.ip.src_ip);
9340                 entry.input.flow.ip4_flow.tos = res->tos_value;
9341                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9342                 /* need convert to big endian. */
9343                 entry.input.flow.sctp4_flow.dst_port =
9344                                 rte_cpu_to_be_16(res->port_dst);
9345                 entry.input.flow.sctp4_flow.src_port =
9346                                 rte_cpu_to_be_16(res->port_src);
9347                 entry.input.flow.sctp4_flow.verify_tag =
9348                                 rte_cpu_to_be_32(res->verify_tag_value);
9349                 break;
9350         case RTE_ETH_FLOW_FRAG_IPV6:
9351         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9352                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9353                 /* fall-through */
9354         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9355         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9356                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9357                         entry.input.flow.ipv6_flow.dst_ip);
9358                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9359                         entry.input.flow.ipv6_flow.src_ip);
9360                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9361                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9362                 /* need convert to big endian. */
9363                 entry.input.flow.udp6_flow.dst_port =
9364                                 rte_cpu_to_be_16(res->port_dst);
9365                 entry.input.flow.udp6_flow.src_port =
9366                                 rte_cpu_to_be_16(res->port_src);
9367                 break;
9368         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9369                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9370                         entry.input.flow.sctp6_flow.ip.dst_ip);
9371                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9372                         entry.input.flow.sctp6_flow.ip.src_ip);
9373                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9374                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9375                 /* need convert to big endian. */
9376                 entry.input.flow.sctp6_flow.dst_port =
9377                                 rte_cpu_to_be_16(res->port_dst);
9378                 entry.input.flow.sctp6_flow.src_port =
9379                                 rte_cpu_to_be_16(res->port_src);
9380                 entry.input.flow.sctp6_flow.verify_tag =
9381                                 rte_cpu_to_be_32(res->verify_tag_value);
9382                 break;
9383         case RTE_ETH_FLOW_L2_PAYLOAD:
9384                 entry.input.flow.l2_flow.ether_type =
9385                         rte_cpu_to_be_16(res->ether_type);
9386                 break;
9387         default:
9388                 break;
9389         }
9390
9391         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9392                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9393                                  &res->mac_addr,
9394                                  sizeof(struct ether_addr));
9395
9396         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9397                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9398                                  &res->mac_addr,
9399                                  sizeof(struct ether_addr));
9400                 entry.input.flow.tunnel_flow.tunnel_type =
9401                         str2fdir_tunneltype(res->tunnel_type);
9402                 entry.input.flow.tunnel_flow.tunnel_id =
9403                         rte_cpu_to_be_32(res->tunnel_id_value);
9404         }
9405
9406         rte_memcpy(entry.input.flow_ext.flexbytes,
9407                    flexbytes,
9408                    RTE_ETH_FDIR_MAX_FLEXLEN);
9409
9410         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9411
9412         entry.action.flex_off = 0;  /*use 0 by default */
9413         if (!strcmp(res->drop, "drop"))
9414                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
9415         else
9416                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9417
9418         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9419             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9420                 if (!strcmp(res->pf_vf, "pf"))
9421                         entry.input.flow_ext.is_vf = 0;
9422                 else if (!strncmp(res->pf_vf, "vf", 2)) {
9423                         struct rte_eth_dev_info dev_info;
9424
9425                         memset(&dev_info, 0, sizeof(dev_info));
9426                         rte_eth_dev_info_get(res->port_id, &dev_info);
9427                         errno = 0;
9428                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
9429                         if (errno != 0 || *end != '\0' ||
9430                             vf_id >= dev_info.max_vfs) {
9431                                 printf("invalid parameter %s.\n", res->pf_vf);
9432                                 return;
9433                         }
9434                         entry.input.flow_ext.is_vf = 1;
9435                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
9436                 } else {
9437                         printf("invalid parameter %s.\n", res->pf_vf);
9438                         return;
9439                 }
9440         }
9441
9442         /* set to report FD ID by default */
9443         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
9444         entry.action.rx_queue = res->queue_id;
9445         entry.soft_id = res->fd_id_value;
9446         if (!strcmp(res->ops, "add"))
9447                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9448                                              RTE_ETH_FILTER_ADD, &entry);
9449         else if (!strcmp(res->ops, "del"))
9450                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9451                                              RTE_ETH_FILTER_DELETE, &entry);
9452         else
9453                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9454                                              RTE_ETH_FILTER_UPDATE, &entry);
9455         if (ret < 0)
9456                 printf("flow director programming error: (%s)\n",
9457                         strerror(-ret));
9458 }
9459
9460 cmdline_parse_token_string_t cmd_flow_director_filter =
9461         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9462                                  flow_director_filter, "flow_director_filter");
9463 cmdline_parse_token_num_t cmd_flow_director_port_id =
9464         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9465                               port_id, UINT8);
9466 cmdline_parse_token_string_t cmd_flow_director_ops =
9467         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9468                                  ops, "add#del#update");
9469 cmdline_parse_token_string_t cmd_flow_director_flow =
9470         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9471                                  flow, "flow");
9472 cmdline_parse_token_string_t cmd_flow_director_flow_type =
9473         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9474                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9475                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
9476 cmdline_parse_token_string_t cmd_flow_director_ether =
9477         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9478                                  ether, "ether");
9479 cmdline_parse_token_num_t cmd_flow_director_ether_type =
9480         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9481                               ether_type, UINT16);
9482 cmdline_parse_token_string_t cmd_flow_director_src =
9483         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9484                                  src, "src");
9485 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
9486         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9487                                  ip_src);
9488 cmdline_parse_token_num_t cmd_flow_director_port_src =
9489         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9490                               port_src, UINT16);
9491 cmdline_parse_token_string_t cmd_flow_director_dst =
9492         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9493                                  dst, "dst");
9494 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
9495         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9496                                  ip_dst);
9497 cmdline_parse_token_num_t cmd_flow_director_port_dst =
9498         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9499                               port_dst, UINT16);
9500 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
9501         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9502                                   verify_tag, "verify_tag");
9503 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
9504         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9505                               verify_tag_value, UINT32);
9506 cmdline_parse_token_string_t cmd_flow_director_tos =
9507         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9508                                  tos, "tos");
9509 cmdline_parse_token_num_t cmd_flow_director_tos_value =
9510         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9511                               tos_value, UINT8);
9512 cmdline_parse_token_string_t cmd_flow_director_proto =
9513         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9514                                  proto, "proto");
9515 cmdline_parse_token_num_t cmd_flow_director_proto_value =
9516         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9517                               proto_value, UINT8);
9518 cmdline_parse_token_string_t cmd_flow_director_ttl =
9519         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9520                                  ttl, "ttl");
9521 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
9522         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9523                               ttl_value, UINT8);
9524 cmdline_parse_token_string_t cmd_flow_director_vlan =
9525         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9526                                  vlan, "vlan");
9527 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
9528         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9529                               vlan_value, UINT16);
9530 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
9531         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9532                                  flexbytes, "flexbytes");
9533 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
9534         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9535                               flexbytes_value, NULL);
9536 cmdline_parse_token_string_t cmd_flow_director_drop =
9537         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9538                                  drop, "drop#fwd");
9539 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
9540         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9541                               pf_vf, NULL);
9542 cmdline_parse_token_string_t cmd_flow_director_queue =
9543         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9544                                  queue, "queue");
9545 cmdline_parse_token_num_t cmd_flow_director_queue_id =
9546         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9547                               queue_id, UINT16);
9548 cmdline_parse_token_string_t cmd_flow_director_fd_id =
9549         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9550                                  fd_id, "fd_id");
9551 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
9552         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9553                               fd_id_value, UINT32);
9554
9555 cmdline_parse_token_string_t cmd_flow_director_mode =
9556         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9557                                  mode, "mode");
9558 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
9559         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9560                                  mode_value, "IP");
9561 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
9562         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9563                                  mode_value, "MAC-VLAN");
9564 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
9565         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9566                                  mode_value, "Tunnel");
9567 cmdline_parse_token_string_t cmd_flow_director_mac =
9568         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9569                                  mac, "mac");
9570 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
9571         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
9572                                     mac_addr);
9573 cmdline_parse_token_string_t cmd_flow_director_tunnel =
9574         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9575                                  tunnel, "tunnel");
9576 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
9577         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9578                                  tunnel_type, "NVGRE#VxLAN");
9579 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
9580         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9581                                  tunnel_id, "tunnel-id");
9582 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
9583         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9584                               tunnel_id_value, UINT32);
9585
9586 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
9587         .f = cmd_flow_director_filter_parsed,
9588         .data = NULL,
9589         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
9590                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
9591                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
9592                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
9593                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
9594                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
9595                 "fd_id <fd_id_value>: "
9596                 "Add or delete an ip flow director entry on NIC",
9597         .tokens = {
9598                 (void *)&cmd_flow_director_filter,
9599                 (void *)&cmd_flow_director_port_id,
9600                 (void *)&cmd_flow_director_mode,
9601                 (void *)&cmd_flow_director_mode_ip,
9602                 (void *)&cmd_flow_director_ops,
9603                 (void *)&cmd_flow_director_flow,
9604                 (void *)&cmd_flow_director_flow_type,
9605                 (void *)&cmd_flow_director_src,
9606                 (void *)&cmd_flow_director_ip_src,
9607                 (void *)&cmd_flow_director_dst,
9608                 (void *)&cmd_flow_director_ip_dst,
9609                 (void *)&cmd_flow_director_tos,
9610                 (void *)&cmd_flow_director_tos_value,
9611                 (void *)&cmd_flow_director_proto,
9612                 (void *)&cmd_flow_director_proto_value,
9613                 (void *)&cmd_flow_director_ttl,
9614                 (void *)&cmd_flow_director_ttl_value,
9615                 (void *)&cmd_flow_director_vlan,
9616                 (void *)&cmd_flow_director_vlan_value,
9617                 (void *)&cmd_flow_director_flexbytes,
9618                 (void *)&cmd_flow_director_flexbytes_value,
9619                 (void *)&cmd_flow_director_drop,
9620                 (void *)&cmd_flow_director_pf_vf,
9621                 (void *)&cmd_flow_director_queue,
9622                 (void *)&cmd_flow_director_queue_id,
9623                 (void *)&cmd_flow_director_fd_id,
9624                 (void *)&cmd_flow_director_fd_id_value,
9625                 NULL,
9626         },
9627 };
9628
9629 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
9630         .f = cmd_flow_director_filter_parsed,
9631         .data = NULL,
9632         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
9633                 "director entry on NIC",
9634         .tokens = {
9635                 (void *)&cmd_flow_director_filter,
9636                 (void *)&cmd_flow_director_port_id,
9637                 (void *)&cmd_flow_director_mode,
9638                 (void *)&cmd_flow_director_mode_ip,
9639                 (void *)&cmd_flow_director_ops,
9640                 (void *)&cmd_flow_director_flow,
9641                 (void *)&cmd_flow_director_flow_type,
9642                 (void *)&cmd_flow_director_src,
9643                 (void *)&cmd_flow_director_ip_src,
9644                 (void *)&cmd_flow_director_port_src,
9645                 (void *)&cmd_flow_director_dst,
9646                 (void *)&cmd_flow_director_ip_dst,
9647                 (void *)&cmd_flow_director_port_dst,
9648                 (void *)&cmd_flow_director_tos,
9649                 (void *)&cmd_flow_director_tos_value,
9650                 (void *)&cmd_flow_director_ttl,
9651                 (void *)&cmd_flow_director_ttl_value,
9652                 (void *)&cmd_flow_director_vlan,
9653                 (void *)&cmd_flow_director_vlan_value,
9654                 (void *)&cmd_flow_director_flexbytes,
9655                 (void *)&cmd_flow_director_flexbytes_value,
9656                 (void *)&cmd_flow_director_drop,
9657                 (void *)&cmd_flow_director_pf_vf,
9658                 (void *)&cmd_flow_director_queue,
9659                 (void *)&cmd_flow_director_queue_id,
9660                 (void *)&cmd_flow_director_fd_id,
9661                 (void *)&cmd_flow_director_fd_id_value,
9662                 NULL,
9663         },
9664 };
9665
9666 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
9667         .f = cmd_flow_director_filter_parsed,
9668         .data = NULL,
9669         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
9670                 "director entry on NIC",
9671         .tokens = {
9672                 (void *)&cmd_flow_director_filter,
9673                 (void *)&cmd_flow_director_port_id,
9674                 (void *)&cmd_flow_director_mode,
9675                 (void *)&cmd_flow_director_mode_ip,
9676                 (void *)&cmd_flow_director_ops,
9677                 (void *)&cmd_flow_director_flow,
9678                 (void *)&cmd_flow_director_flow_type,
9679                 (void *)&cmd_flow_director_src,
9680                 (void *)&cmd_flow_director_ip_src,
9681                 (void *)&cmd_flow_director_port_dst,
9682                 (void *)&cmd_flow_director_dst,
9683                 (void *)&cmd_flow_director_ip_dst,
9684                 (void *)&cmd_flow_director_port_dst,
9685                 (void *)&cmd_flow_director_verify_tag,
9686                 (void *)&cmd_flow_director_verify_tag_value,
9687                 (void *)&cmd_flow_director_tos,
9688                 (void *)&cmd_flow_director_tos_value,
9689                 (void *)&cmd_flow_director_ttl,
9690                 (void *)&cmd_flow_director_ttl_value,
9691                 (void *)&cmd_flow_director_vlan,
9692                 (void *)&cmd_flow_director_vlan_value,
9693                 (void *)&cmd_flow_director_flexbytes,
9694                 (void *)&cmd_flow_director_flexbytes_value,
9695                 (void *)&cmd_flow_director_drop,
9696                 (void *)&cmd_flow_director_pf_vf,
9697                 (void *)&cmd_flow_director_queue,
9698                 (void *)&cmd_flow_director_queue_id,
9699                 (void *)&cmd_flow_director_fd_id,
9700                 (void *)&cmd_flow_director_fd_id_value,
9701                 NULL,
9702         },
9703 };
9704
9705 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
9706         .f = cmd_flow_director_filter_parsed,
9707         .data = NULL,
9708         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
9709                 "director entry on NIC",
9710         .tokens = {
9711                 (void *)&cmd_flow_director_filter,
9712                 (void *)&cmd_flow_director_port_id,
9713                 (void *)&cmd_flow_director_mode,
9714                 (void *)&cmd_flow_director_mode_ip,
9715                 (void *)&cmd_flow_director_ops,
9716                 (void *)&cmd_flow_director_flow,
9717                 (void *)&cmd_flow_director_flow_type,
9718                 (void *)&cmd_flow_director_ether,
9719                 (void *)&cmd_flow_director_ether_type,
9720                 (void *)&cmd_flow_director_flexbytes,
9721                 (void *)&cmd_flow_director_flexbytes_value,
9722                 (void *)&cmd_flow_director_drop,
9723                 (void *)&cmd_flow_director_pf_vf,
9724                 (void *)&cmd_flow_director_queue,
9725                 (void *)&cmd_flow_director_queue_id,
9726                 (void *)&cmd_flow_director_fd_id,
9727                 (void *)&cmd_flow_director_fd_id_value,
9728                 NULL,
9729         },
9730 };
9731
9732 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
9733         .f = cmd_flow_director_filter_parsed,
9734         .data = NULL,
9735         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
9736                 "director entry on NIC",
9737         .tokens = {
9738                 (void *)&cmd_flow_director_filter,
9739                 (void *)&cmd_flow_director_port_id,
9740                 (void *)&cmd_flow_director_mode,
9741                 (void *)&cmd_flow_director_mode_mac_vlan,
9742                 (void *)&cmd_flow_director_ops,
9743                 (void *)&cmd_flow_director_mac,
9744                 (void *)&cmd_flow_director_mac_addr,
9745                 (void *)&cmd_flow_director_vlan,
9746                 (void *)&cmd_flow_director_vlan_value,
9747                 (void *)&cmd_flow_director_flexbytes,
9748                 (void *)&cmd_flow_director_flexbytes_value,
9749                 (void *)&cmd_flow_director_drop,
9750                 (void *)&cmd_flow_director_queue,
9751                 (void *)&cmd_flow_director_queue_id,
9752                 (void *)&cmd_flow_director_fd_id,
9753                 (void *)&cmd_flow_director_fd_id_value,
9754                 NULL,
9755         },
9756 };
9757
9758 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
9759         .f = cmd_flow_director_filter_parsed,
9760         .data = NULL,
9761         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
9762                 "director entry on NIC",
9763         .tokens = {
9764                 (void *)&cmd_flow_director_filter,
9765                 (void *)&cmd_flow_director_port_id,
9766                 (void *)&cmd_flow_director_mode,
9767                 (void *)&cmd_flow_director_mode_tunnel,
9768                 (void *)&cmd_flow_director_ops,
9769                 (void *)&cmd_flow_director_mac,
9770                 (void *)&cmd_flow_director_mac_addr,
9771                 (void *)&cmd_flow_director_vlan,
9772                 (void *)&cmd_flow_director_vlan_value,
9773                 (void *)&cmd_flow_director_tunnel,
9774                 (void *)&cmd_flow_director_tunnel_type,
9775                 (void *)&cmd_flow_director_tunnel_id,
9776                 (void *)&cmd_flow_director_tunnel_id_value,
9777                 (void *)&cmd_flow_director_flexbytes,
9778                 (void *)&cmd_flow_director_flexbytes_value,
9779                 (void *)&cmd_flow_director_drop,
9780                 (void *)&cmd_flow_director_queue,
9781                 (void *)&cmd_flow_director_queue_id,
9782                 (void *)&cmd_flow_director_fd_id,
9783                 (void *)&cmd_flow_director_fd_id_value,
9784                 NULL,
9785         },
9786 };
9787
9788 struct cmd_flush_flow_director_result {
9789         cmdline_fixed_string_t flush_flow_director;
9790         uint8_t port_id;
9791 };
9792
9793 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
9794         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
9795                                  flush_flow_director, "flush_flow_director");
9796 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
9797         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
9798                               port_id, UINT8);
9799
9800 static void
9801 cmd_flush_flow_director_parsed(void *parsed_result,
9802                           __attribute__((unused)) struct cmdline *cl,
9803                           __attribute__((unused)) void *data)
9804 {
9805         struct cmd_flow_director_result *res = parsed_result;
9806         int ret = 0;
9807
9808         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9809         if (ret < 0) {
9810                 printf("flow director is not supported on port %u.\n",
9811                         res->port_id);
9812                 return;
9813         }
9814
9815         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9816                         RTE_ETH_FILTER_FLUSH, NULL);
9817         if (ret < 0)
9818                 printf("flow director table flushing error: (%s)\n",
9819                         strerror(-ret));
9820 }
9821
9822 cmdline_parse_inst_t cmd_flush_flow_director = {
9823         .f = cmd_flush_flow_director_parsed,
9824         .data = NULL,
9825         .help_str = "flush_flow_director <port_id>: "
9826                 "Flush all flow director entries of a device on NIC",
9827         .tokens = {
9828                 (void *)&cmd_flush_flow_director_flush,
9829                 (void *)&cmd_flush_flow_director_port_id,
9830                 NULL,
9831         },
9832 };
9833
9834 /* *** deal with flow director mask *** */
9835 struct cmd_flow_director_mask_result {
9836         cmdline_fixed_string_t flow_director_mask;
9837         uint8_t port_id;
9838         cmdline_fixed_string_t mode;
9839         cmdline_fixed_string_t mode_value;
9840         cmdline_fixed_string_t vlan;
9841         uint16_t vlan_mask;
9842         cmdline_fixed_string_t src_mask;
9843         cmdline_ipaddr_t ipv4_src;
9844         cmdline_ipaddr_t ipv6_src;
9845         uint16_t port_src;
9846         cmdline_fixed_string_t dst_mask;
9847         cmdline_ipaddr_t ipv4_dst;
9848         cmdline_ipaddr_t ipv6_dst;
9849         uint16_t port_dst;
9850         cmdline_fixed_string_t mac;
9851         uint8_t mac_addr_byte_mask;
9852         cmdline_fixed_string_t tunnel_id;
9853         uint32_t tunnel_id_mask;
9854         cmdline_fixed_string_t tunnel_type;
9855         uint8_t tunnel_type_mask;
9856 };
9857
9858 static void
9859 cmd_flow_director_mask_parsed(void *parsed_result,
9860                           __attribute__((unused)) struct cmdline *cl,
9861                           __attribute__((unused)) void *data)
9862 {
9863         struct cmd_flow_director_mask_result *res = parsed_result;
9864         struct rte_eth_fdir_masks *mask;
9865         struct rte_port *port;
9866
9867         if (res->port_id > nb_ports) {
9868                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9869                 return;
9870         }
9871
9872         port = &ports[res->port_id];
9873         /** Check if the port is not started **/
9874         if (port->port_status != RTE_PORT_STOPPED) {
9875                 printf("Please stop port %d first\n", res->port_id);
9876                 return;
9877         }
9878
9879         mask = &port->dev_conf.fdir_conf.mask;
9880
9881         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9882                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9883                         printf("Please set mode to MAC-VLAN.\n");
9884                         return;
9885                 }
9886
9887                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9888         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9889                 if (strcmp(res->mode_value, "Tunnel")) {
9890                         printf("Please set mode to Tunnel.\n");
9891                         return;
9892                 }
9893
9894                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9895                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9896                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
9897                 mask->tunnel_type_mask = res->tunnel_type_mask;
9898         } else {
9899                 if (strcmp(res->mode_value, "IP")) {
9900                         printf("Please set mode to IP.\n");
9901                         return;
9902                 }
9903
9904                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9905                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
9906                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
9907                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
9908                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
9909                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
9910                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
9911         }
9912
9913         cmd_reconfig_device_queue(res->port_id, 1, 1);
9914 }
9915
9916 cmdline_parse_token_string_t cmd_flow_director_mask =
9917         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9918                                  flow_director_mask, "flow_director_mask");
9919 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
9920         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9921                               port_id, UINT8);
9922 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
9923         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9924                                  vlan, "vlan");
9925 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
9926         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9927                               vlan_mask, UINT16);
9928 cmdline_parse_token_string_t cmd_flow_director_mask_src =
9929         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9930                                  src_mask, "src_mask");
9931 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
9932         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9933                                  ipv4_src);
9934 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
9935         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9936                                  ipv6_src);
9937 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
9938         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9939                               port_src, UINT16);
9940 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
9941         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9942                                  dst_mask, "dst_mask");
9943 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
9944         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9945                                  ipv4_dst);
9946 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
9947         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9948                                  ipv6_dst);
9949 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
9950         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9951                               port_dst, UINT16);
9952
9953 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
9954         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9955                                  mode, "mode");
9956 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
9957         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9958                                  mode_value, "IP");
9959 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
9960         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9961                                  mode_value, "MAC-VLAN");
9962 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
9963         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9964                                  mode_value, "Tunnel");
9965 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
9966         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9967                                  mac, "mac");
9968 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
9969         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9970                               mac_addr_byte_mask, UINT8);
9971 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
9972         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9973                                  tunnel_type, "tunnel-type");
9974 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
9975         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9976                               tunnel_type_mask, UINT8);
9977 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
9978         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9979                                  tunnel_id, "tunnel-id");
9980 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
9981         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9982                               tunnel_id_mask, UINT32);
9983
9984 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
9985         .f = cmd_flow_director_mask_parsed,
9986         .data = NULL,
9987         .help_str = "flow_director_mask ... : "
9988                 "Set IP mode flow director's mask on NIC",
9989         .tokens = {
9990                 (void *)&cmd_flow_director_mask,
9991                 (void *)&cmd_flow_director_mask_port_id,
9992                 (void *)&cmd_flow_director_mask_mode,
9993                 (void *)&cmd_flow_director_mask_mode_ip,
9994                 (void *)&cmd_flow_director_mask_vlan,
9995                 (void *)&cmd_flow_director_mask_vlan_value,
9996                 (void *)&cmd_flow_director_mask_src,
9997                 (void *)&cmd_flow_director_mask_ipv4_src,
9998                 (void *)&cmd_flow_director_mask_ipv6_src,
9999                 (void *)&cmd_flow_director_mask_port_src,
10000                 (void *)&cmd_flow_director_mask_dst,
10001                 (void *)&cmd_flow_director_mask_ipv4_dst,
10002                 (void *)&cmd_flow_director_mask_ipv6_dst,
10003                 (void *)&cmd_flow_director_mask_port_dst,
10004                 NULL,
10005         },
10006 };
10007
10008 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10009         .f = cmd_flow_director_mask_parsed,
10010         .data = NULL,
10011         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10012                 "flow director's mask on NIC",
10013         .tokens = {
10014                 (void *)&cmd_flow_director_mask,
10015                 (void *)&cmd_flow_director_mask_port_id,
10016                 (void *)&cmd_flow_director_mask_mode,
10017                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10018                 (void *)&cmd_flow_director_mask_vlan,
10019                 (void *)&cmd_flow_director_mask_vlan_value,
10020                 NULL,
10021         },
10022 };
10023
10024 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10025         .f = cmd_flow_director_mask_parsed,
10026         .data = NULL,
10027         .help_str = "flow_director_mask ... : Set tunnel mode "
10028                 "flow director's mask on NIC",
10029         .tokens = {
10030                 (void *)&cmd_flow_director_mask,
10031                 (void *)&cmd_flow_director_mask_port_id,
10032                 (void *)&cmd_flow_director_mask_mode,
10033                 (void *)&cmd_flow_director_mask_mode_tunnel,
10034                 (void *)&cmd_flow_director_mask_vlan,
10035                 (void *)&cmd_flow_director_mask_vlan_value,
10036                 (void *)&cmd_flow_director_mask_mac,
10037                 (void *)&cmd_flow_director_mask_mac_value,
10038                 (void *)&cmd_flow_director_mask_tunnel_type,
10039                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10040                 (void *)&cmd_flow_director_mask_tunnel_id,
10041                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10042                 NULL,
10043         },
10044 };
10045
10046 /* *** deal with flow director mask on flexible payload *** */
10047 struct cmd_flow_director_flex_mask_result {
10048         cmdline_fixed_string_t flow_director_flexmask;
10049         uint8_t port_id;
10050         cmdline_fixed_string_t flow;
10051         cmdline_fixed_string_t flow_type;
10052         cmdline_fixed_string_t mask;
10053 };
10054
10055 static void
10056 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10057                           __attribute__((unused)) struct cmdline *cl,
10058                           __attribute__((unused)) void *data)
10059 {
10060         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10061         struct rte_eth_fdir_info fdir_info;
10062         struct rte_eth_fdir_flex_mask flex_mask;
10063         struct rte_port *port;
10064         uint32_t flow_type_mask;
10065         uint16_t i;
10066         int ret;
10067
10068         if (res->port_id > nb_ports) {
10069                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10070                 return;
10071         }
10072
10073         port = &ports[res->port_id];
10074         /** Check if the port is not started **/
10075         if (port->port_status != RTE_PORT_STOPPED) {
10076                 printf("Please stop port %d first\n", res->port_id);
10077                 return;
10078         }
10079
10080         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10081         ret = parse_flexbytes(res->mask,
10082                         flex_mask.mask,
10083                         RTE_ETH_FDIR_MAX_FLEXLEN);
10084         if (ret < 0) {
10085                 printf("error: Cannot parse mask input.\n");
10086                 return;
10087         }
10088
10089         memset(&fdir_info, 0, sizeof(fdir_info));
10090         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10091                                 RTE_ETH_FILTER_INFO, &fdir_info);
10092         if (ret < 0) {
10093                 printf("Cannot get FDir filter info\n");
10094                 return;
10095         }
10096
10097         if (!strcmp(res->flow_type, "none")) {
10098                 /* means don't specify the flow type */
10099                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10100                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10101                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10102                                0, sizeof(struct rte_eth_fdir_flex_mask));
10103                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10104                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10105                                  &flex_mask,
10106                                  sizeof(struct rte_eth_fdir_flex_mask));
10107                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10108                 return;
10109         }
10110         flow_type_mask = fdir_info.flow_types_mask[0];
10111         if (!strcmp(res->flow_type, "all")) {
10112                 if (!flow_type_mask) {
10113                         printf("No flow type supported\n");
10114                         return;
10115                 }
10116                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10117                         if (flow_type_mask & (1 << i)) {
10118                                 flex_mask.flow_type = i;
10119                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10120                         }
10121                 }
10122                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10123                 return;
10124         }
10125         flex_mask.flow_type = str2flowtype(res->flow_type);
10126         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10127                 printf("Flow type %s not supported on port %d\n",
10128                                 res->flow_type, res->port_id);
10129                 return;
10130         }
10131         fdir_set_flex_mask(res->port_id, &flex_mask);
10132         cmd_reconfig_device_queue(res->port_id, 1, 1);
10133 }
10134
10135 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10136         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10137                                  flow_director_flexmask,
10138                                  "flow_director_flex_mask");
10139 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10140         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10141                               port_id, UINT8);
10142 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10143         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10144                                  flow, "flow");
10145 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10146         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10147                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10148                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10149 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10150         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10151                                  mask, NULL);
10152
10153 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10154         .f = cmd_flow_director_flex_mask_parsed,
10155         .data = NULL,
10156         .help_str = "flow_director_flex_mask ... : "
10157                 "Set flow director's flex mask on NIC",
10158         .tokens = {
10159                 (void *)&cmd_flow_director_flexmask,
10160                 (void *)&cmd_flow_director_flexmask_port_id,
10161                 (void *)&cmd_flow_director_flexmask_flow,
10162                 (void *)&cmd_flow_director_flexmask_flow_type,
10163                 (void *)&cmd_flow_director_flexmask_mask,
10164                 NULL,
10165         },
10166 };
10167
10168 /* *** deal with flow director flexible payload configuration *** */
10169 struct cmd_flow_director_flexpayload_result {
10170         cmdline_fixed_string_t flow_director_flexpayload;
10171         uint8_t port_id;
10172         cmdline_fixed_string_t payload_layer;
10173         cmdline_fixed_string_t payload_cfg;
10174 };
10175
10176 static inline int
10177 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10178 {
10179         char s[256];
10180         const char *p, *p0 = q_arg;
10181         char *end;
10182         unsigned long int_fld;
10183         char *str_fld[max_num];
10184         int i;
10185         unsigned size;
10186         int ret = -1;
10187
10188         p = strchr(p0, '(');
10189         if (p == NULL)
10190                 return -1;
10191         ++p;
10192         p0 = strchr(p, ')');
10193         if (p0 == NULL)
10194                 return -1;
10195
10196         size = p0 - p;
10197         if (size >= sizeof(s))
10198                 return -1;
10199
10200         snprintf(s, sizeof(s), "%.*s", size, p);
10201         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10202         if (ret < 0 || ret > max_num)
10203                 return -1;
10204         for (i = 0; i < ret; i++) {
10205                 errno = 0;
10206                 int_fld = strtoul(str_fld[i], &end, 0);
10207                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10208                         return -1;
10209                 offsets[i] = (uint16_t)int_fld;
10210         }
10211         return ret;
10212 }
10213
10214 static void
10215 cmd_flow_director_flxpld_parsed(void *parsed_result,
10216                           __attribute__((unused)) struct cmdline *cl,
10217                           __attribute__((unused)) void *data)
10218 {
10219         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10220         struct rte_eth_flex_payload_cfg flex_cfg;
10221         struct rte_port *port;
10222         int ret = 0;
10223
10224         if (res->port_id > nb_ports) {
10225                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10226                 return;
10227         }
10228
10229         port = &ports[res->port_id];
10230         /** Check if the port is not started **/
10231         if (port->port_status != RTE_PORT_STOPPED) {
10232                 printf("Please stop port %d first\n", res->port_id);
10233                 return;
10234         }
10235
10236         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10237
10238         if (!strcmp(res->payload_layer, "raw"))
10239                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10240         else if (!strcmp(res->payload_layer, "l2"))
10241                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10242         else if (!strcmp(res->payload_layer, "l3"))
10243                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10244         else if (!strcmp(res->payload_layer, "l4"))
10245                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10246
10247         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10248                             RTE_ETH_FDIR_MAX_FLEXLEN);
10249         if (ret < 0) {
10250                 printf("error: Cannot parse flex payload input.\n");
10251                 return;
10252         }
10253
10254         fdir_set_flex_payload(res->port_id, &flex_cfg);
10255         cmd_reconfig_device_queue(res->port_id, 1, 1);
10256 }
10257
10258 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10259         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10260                                  flow_director_flexpayload,
10261                                  "flow_director_flex_payload");
10262 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10263         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10264                               port_id, UINT8);
10265 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10266         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10267                                  payload_layer, "raw#l2#l3#l4");
10268 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10269         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10270                                  payload_cfg, NULL);
10271
10272 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10273         .f = cmd_flow_director_flxpld_parsed,
10274         .data = NULL,
10275         .help_str = "flow_director_flexpayload ... : "
10276                 "Set flow director's flex payload on NIC",
10277         .tokens = {
10278                 (void *)&cmd_flow_director_flexpayload,
10279                 (void *)&cmd_flow_director_flexpayload_port_id,
10280                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10281                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10282                 NULL,
10283         },
10284 };
10285
10286 /* Generic flow interface command. */
10287 extern cmdline_parse_inst_t cmd_flow;
10288
10289 /* *** Classification Filters Control *** */
10290 /* *** Get symmetric hash enable per port *** */
10291 struct cmd_get_sym_hash_ena_per_port_result {
10292         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10293         uint8_t port_id;
10294 };
10295
10296 static void
10297 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10298                                  __rte_unused struct cmdline *cl,
10299                                  __rte_unused void *data)
10300 {
10301         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10302         struct rte_eth_hash_filter_info info;
10303         int ret;
10304
10305         if (rte_eth_dev_filter_supported(res->port_id,
10306                                 RTE_ETH_FILTER_HASH) < 0) {
10307                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10308                                                         res->port_id);
10309                 return;
10310         }
10311
10312         memset(&info, 0, sizeof(info));
10313         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10314         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10315                                                 RTE_ETH_FILTER_GET, &info);
10316
10317         if (ret < 0) {
10318                 printf("Cannot get symmetric hash enable per port "
10319                                         "on port %u\n", res->port_id);
10320                 return;
10321         }
10322
10323         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10324                                 "enabled" : "disabled", res->port_id);
10325 }
10326
10327 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10328         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10329                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10330 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10331         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10332                 port_id, UINT8);
10333
10334 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10335         .f = cmd_get_sym_hash_per_port_parsed,
10336         .data = NULL,
10337         .help_str = "get_sym_hash_ena_per_port <port_id>",
10338         .tokens = {
10339                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10340                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10341                 NULL,
10342         },
10343 };
10344
10345 /* *** Set symmetric hash enable per port *** */
10346 struct cmd_set_sym_hash_ena_per_port_result {
10347         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10348         cmdline_fixed_string_t enable;
10349         uint8_t port_id;
10350 };
10351
10352 static void
10353 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10354                                  __rte_unused struct cmdline *cl,
10355                                  __rte_unused void *data)
10356 {
10357         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10358         struct rte_eth_hash_filter_info info;
10359         int ret;
10360
10361         if (rte_eth_dev_filter_supported(res->port_id,
10362                                 RTE_ETH_FILTER_HASH) < 0) {
10363                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10364                                                         res->port_id);
10365                 return;
10366         }
10367
10368         memset(&info, 0, sizeof(info));
10369         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10370         if (!strcmp(res->enable, "enable"))
10371                 info.info.enable = 1;
10372         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10373                                         RTE_ETH_FILTER_SET, &info);
10374         if (ret < 0) {
10375                 printf("Cannot set symmetric hash enable per port on "
10376                                         "port %u\n", res->port_id);
10377                 return;
10378         }
10379         printf("Symmetric hash has been set to %s on port %u\n",
10380                                         res->enable, res->port_id);
10381 }
10382
10383 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10384         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10385                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10386 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10387         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10388                 port_id, UINT8);
10389 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10390         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10391                 enable, "enable#disable");
10392
10393 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10394         .f = cmd_set_sym_hash_per_port_parsed,
10395         .data = NULL,
10396         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10397         .tokens = {
10398                 (void *)&cmd_set_sym_hash_ena_per_port_all,
10399                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
10400                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
10401                 NULL,
10402         },
10403 };
10404
10405 /* Get global config of hash function */
10406 struct cmd_get_hash_global_config_result {
10407         cmdline_fixed_string_t get_hash_global_config;
10408         uint8_t port_id;
10409 };
10410
10411 static char *
10412 flowtype_to_str(uint16_t ftype)
10413 {
10414         uint16_t i;
10415         static struct {
10416                 char str[16];
10417                 uint16_t ftype;
10418         } ftype_table[] = {
10419                 {"ipv4", RTE_ETH_FLOW_IPV4},
10420                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10421                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10422                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10423                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10424                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10425                 {"ipv6", RTE_ETH_FLOW_IPV6},
10426                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10427                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10428                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10429                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10430                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10431                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10432                 {"port", RTE_ETH_FLOW_PORT},
10433                 {"vxlan", RTE_ETH_FLOW_VXLAN},
10434                 {"geneve", RTE_ETH_FLOW_GENEVE},
10435                 {"nvgre", RTE_ETH_FLOW_NVGRE},
10436         };
10437
10438         for (i = 0; i < RTE_DIM(ftype_table); i++) {
10439                 if (ftype_table[i].ftype == ftype)
10440                         return ftype_table[i].str;
10441         }
10442
10443         return NULL;
10444 }
10445
10446 static void
10447 cmd_get_hash_global_config_parsed(void *parsed_result,
10448                                   __rte_unused struct cmdline *cl,
10449                                   __rte_unused void *data)
10450 {
10451         struct cmd_get_hash_global_config_result *res = parsed_result;
10452         struct rte_eth_hash_filter_info info;
10453         uint32_t idx, offset;
10454         uint16_t i;
10455         char *str;
10456         int ret;
10457
10458         if (rte_eth_dev_filter_supported(res->port_id,
10459                         RTE_ETH_FILTER_HASH) < 0) {
10460                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10461                                                         res->port_id);
10462                 return;
10463         }
10464
10465         memset(&info, 0, sizeof(info));
10466         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10467         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10468                                         RTE_ETH_FILTER_GET, &info);
10469         if (ret < 0) {
10470                 printf("Cannot get hash global configurations by port %d\n",
10471                                                         res->port_id);
10472                 return;
10473         }
10474
10475         switch (info.info.global_conf.hash_func) {
10476         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
10477                 printf("Hash function is Toeplitz\n");
10478                 break;
10479         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
10480                 printf("Hash function is Simple XOR\n");
10481                 break;
10482         default:
10483                 printf("Unknown hash function\n");
10484                 break;
10485         }
10486
10487         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
10488                 idx = i / UINT32_BIT;
10489                 offset = i % UINT32_BIT;
10490                 if (!(info.info.global_conf.valid_bit_mask[idx] &
10491                                                 (1UL << offset)))
10492                         continue;
10493                 str = flowtype_to_str(i);
10494                 if (!str)
10495                         continue;
10496                 printf("Symmetric hash is %s globally for flow type %s "
10497                                                         "by port %d\n",
10498                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
10499                         (1UL << offset)) ? "enabled" : "disabled"), str,
10500                                                         res->port_id);
10501         }
10502 }
10503
10504 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
10505         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
10506                 get_hash_global_config, "get_hash_global_config");
10507 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
10508         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
10509                 port_id, UINT8);
10510
10511 cmdline_parse_inst_t cmd_get_hash_global_config = {
10512         .f = cmd_get_hash_global_config_parsed,
10513         .data = NULL,
10514         .help_str = "get_hash_global_config <port_id>",
10515         .tokens = {
10516                 (void *)&cmd_get_hash_global_config_all,
10517                 (void *)&cmd_get_hash_global_config_port_id,
10518                 NULL,
10519         },
10520 };
10521
10522 /* Set global config of hash function */
10523 struct cmd_set_hash_global_config_result {
10524         cmdline_fixed_string_t set_hash_global_config;
10525         uint8_t port_id;
10526         cmdline_fixed_string_t hash_func;
10527         cmdline_fixed_string_t flow_type;
10528         cmdline_fixed_string_t enable;
10529 };
10530
10531 static void
10532 cmd_set_hash_global_config_parsed(void *parsed_result,
10533                                   __rte_unused struct cmdline *cl,
10534                                   __rte_unused void *data)
10535 {
10536         struct cmd_set_hash_global_config_result *res = parsed_result;
10537         struct rte_eth_hash_filter_info info;
10538         uint32_t ftype, idx, offset;
10539         int ret;
10540
10541         if (rte_eth_dev_filter_supported(res->port_id,
10542                                 RTE_ETH_FILTER_HASH) < 0) {
10543                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10544                                                         res->port_id);
10545                 return;
10546         }
10547         memset(&info, 0, sizeof(info));
10548         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10549         if (!strcmp(res->hash_func, "toeplitz"))
10550                 info.info.global_conf.hash_func =
10551                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
10552         else if (!strcmp(res->hash_func, "simple_xor"))
10553                 info.info.global_conf.hash_func =
10554                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
10555         else if (!strcmp(res->hash_func, "default"))
10556                 info.info.global_conf.hash_func =
10557                         RTE_ETH_HASH_FUNCTION_DEFAULT;
10558
10559         ftype = str2flowtype(res->flow_type);
10560         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
10561         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
10562         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
10563         if (!strcmp(res->enable, "enable"))
10564                 info.info.global_conf.sym_hash_enable_mask[idx] |=
10565                                                 (1UL << offset);
10566         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10567                                         RTE_ETH_FILTER_SET, &info);
10568         if (ret < 0)
10569                 printf("Cannot set global hash configurations by port %d\n",
10570                                                         res->port_id);
10571         else
10572                 printf("Global hash configurations have been set "
10573                         "succcessfully by port %d\n", res->port_id);
10574 }
10575
10576 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
10577         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10578                 set_hash_global_config, "set_hash_global_config");
10579 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
10580         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
10581                 port_id, UINT8);
10582 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
10583         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10584                 hash_func, "toeplitz#simple_xor#default");
10585 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
10586         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10587                 flow_type,
10588                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
10589                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10590 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
10591         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10592                 enable, "enable#disable");
10593
10594 cmdline_parse_inst_t cmd_set_hash_global_config = {
10595         .f = cmd_set_hash_global_config_parsed,
10596         .data = NULL,
10597         .help_str = "set_hash_global_config <port_id> "
10598                 "toeplitz|simple_xor|default "
10599                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10600                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
10601                 "l2_payload enable|disable",
10602         .tokens = {
10603                 (void *)&cmd_set_hash_global_config_all,
10604                 (void *)&cmd_set_hash_global_config_port_id,
10605                 (void *)&cmd_set_hash_global_config_hash_func,
10606                 (void *)&cmd_set_hash_global_config_flow_type,
10607                 (void *)&cmd_set_hash_global_config_enable,
10608                 NULL,
10609         },
10610 };
10611
10612 /* Set hash input set */
10613 struct cmd_set_hash_input_set_result {
10614         cmdline_fixed_string_t set_hash_input_set;
10615         uint8_t port_id;
10616         cmdline_fixed_string_t flow_type;
10617         cmdline_fixed_string_t inset_field;
10618         cmdline_fixed_string_t select;
10619 };
10620
10621 static enum rte_eth_input_set_field
10622 str2inset(char *string)
10623 {
10624         uint16_t i;
10625
10626         static const struct {
10627                 char str[32];
10628                 enum rte_eth_input_set_field inset;
10629         } inset_table[] = {
10630                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
10631                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
10632                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
10633                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
10634                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
10635                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
10636                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
10637                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
10638                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
10639                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
10640                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
10641                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
10642                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
10643                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
10644                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
10645                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
10646                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
10647                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
10648                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
10649                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
10650                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
10651                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
10652                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
10653                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
10654                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
10655                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
10656                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
10657                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
10658                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
10659                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
10660                 {"none", RTE_ETH_INPUT_SET_NONE},
10661         };
10662
10663         for (i = 0; i < RTE_DIM(inset_table); i++) {
10664                 if (!strcmp(string, inset_table[i].str))
10665                         return inset_table[i].inset;
10666         }
10667
10668         return RTE_ETH_INPUT_SET_UNKNOWN;
10669 }
10670
10671 static void
10672 cmd_set_hash_input_set_parsed(void *parsed_result,
10673                               __rte_unused struct cmdline *cl,
10674                               __rte_unused void *data)
10675 {
10676         struct cmd_set_hash_input_set_result *res = parsed_result;
10677         struct rte_eth_hash_filter_info info;
10678
10679         memset(&info, 0, sizeof(info));
10680         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
10681         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10682         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10683         info.info.input_set_conf.inset_size = 1;
10684         if (!strcmp(res->select, "select"))
10685                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10686         else if (!strcmp(res->select, "add"))
10687                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10688         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10689                                 RTE_ETH_FILTER_SET, &info);
10690 }
10691
10692 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
10693         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10694                 set_hash_input_set, "set_hash_input_set");
10695 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
10696         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
10697                 port_id, UINT8);
10698 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
10699         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10700                 flow_type, NULL);
10701 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
10702         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10703                 inset_field,
10704                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10705                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
10706                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
10707                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
10708                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
10709                 "fld-8th#none");
10710 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
10711         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10712                 select, "select#add");
10713
10714 cmdline_parse_inst_t cmd_set_hash_input_set = {
10715         .f = cmd_set_hash_input_set_parsed,
10716         .data = NULL,
10717         .help_str = "set_hash_input_set <port_id> "
10718         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10719         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
10720         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
10721         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
10722         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
10723         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
10724         "fld-7th|fld-8th|none select|add",
10725         .tokens = {
10726                 (void *)&cmd_set_hash_input_set_cmd,
10727                 (void *)&cmd_set_hash_input_set_port_id,
10728                 (void *)&cmd_set_hash_input_set_flow_type,
10729                 (void *)&cmd_set_hash_input_set_field,
10730                 (void *)&cmd_set_hash_input_set_select,
10731                 NULL,
10732         },
10733 };
10734
10735 /* Set flow director input set */
10736 struct cmd_set_fdir_input_set_result {
10737         cmdline_fixed_string_t set_fdir_input_set;
10738         uint8_t port_id;
10739         cmdline_fixed_string_t flow_type;
10740         cmdline_fixed_string_t inset_field;
10741         cmdline_fixed_string_t select;
10742 };
10743
10744 static void
10745 cmd_set_fdir_input_set_parsed(void *parsed_result,
10746         __rte_unused struct cmdline *cl,
10747         __rte_unused void *data)
10748 {
10749         struct cmd_set_fdir_input_set_result *res = parsed_result;
10750         struct rte_eth_fdir_filter_info info;
10751
10752         memset(&info, 0, sizeof(info));
10753         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
10754         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10755         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10756         info.info.input_set_conf.inset_size = 1;
10757         if (!strcmp(res->select, "select"))
10758                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10759         else if (!strcmp(res->select, "add"))
10760                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10761         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10762                 RTE_ETH_FILTER_SET, &info);
10763 }
10764
10765 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
10766         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10767         set_fdir_input_set, "set_fdir_input_set");
10768 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
10769         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
10770         port_id, UINT8);
10771 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
10772         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10773         flow_type,
10774         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10775         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10776 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
10777         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10778         inset_field,
10779         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10780         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
10781         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
10782         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
10783         "sctp-veri-tag#none");
10784 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
10785         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10786         select, "select#add");
10787
10788 cmdline_parse_inst_t cmd_set_fdir_input_set = {
10789         .f = cmd_set_fdir_input_set_parsed,
10790         .data = NULL,
10791         .help_str = "set_fdir_input_set <port_id> "
10792         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10793         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10794         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
10795         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
10796         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
10797         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
10798         "sctp-veri-tag|none select|add",
10799         .tokens = {
10800                 (void *)&cmd_set_fdir_input_set_cmd,
10801                 (void *)&cmd_set_fdir_input_set_port_id,
10802                 (void *)&cmd_set_fdir_input_set_flow_type,
10803                 (void *)&cmd_set_fdir_input_set_field,
10804                 (void *)&cmd_set_fdir_input_set_select,
10805                 NULL,
10806         },
10807 };
10808
10809 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10810 struct cmd_mcast_addr_result {
10811         cmdline_fixed_string_t mcast_addr_cmd;
10812         cmdline_fixed_string_t what;
10813         uint8_t port_num;
10814         struct ether_addr mc_addr;
10815 };
10816
10817 static void cmd_mcast_addr_parsed(void *parsed_result,
10818                 __attribute__((unused)) struct cmdline *cl,
10819                 __attribute__((unused)) void *data)
10820 {
10821         struct cmd_mcast_addr_result *res = parsed_result;
10822
10823         if (!is_multicast_ether_addr(&res->mc_addr)) {
10824                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10825                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10826                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10827                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10828                 return;
10829         }
10830         if (strcmp(res->what, "add") == 0)
10831                 mcast_addr_add(res->port_num, &res->mc_addr);
10832         else
10833                 mcast_addr_remove(res->port_num, &res->mc_addr);
10834 }
10835
10836 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10837         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10838                                  mcast_addr_cmd, "mcast_addr");
10839 cmdline_parse_token_string_t cmd_mcast_addr_what =
10840         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10841                                  "add#remove");
10842 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10843         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
10844 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10845         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10846
10847 cmdline_parse_inst_t cmd_mcast_addr = {
10848         .f = cmd_mcast_addr_parsed,
10849         .data = (void *)0,
10850         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10851                 "Add/Remove multicast MAC address on port_id",
10852         .tokens = {
10853                 (void *)&cmd_mcast_addr_cmd,
10854                 (void *)&cmd_mcast_addr_what,
10855                 (void *)&cmd_mcast_addr_portnum,
10856                 (void *)&cmd_mcast_addr_addr,
10857                 NULL,
10858         },
10859 };
10860
10861 /* l2 tunnel config
10862  * only support E-tag now.
10863  */
10864
10865 /* Ether type config */
10866 struct cmd_config_l2_tunnel_eth_type_result {
10867         cmdline_fixed_string_t port;
10868         cmdline_fixed_string_t config;
10869         cmdline_fixed_string_t all;
10870         uint8_t id;
10871         cmdline_fixed_string_t l2_tunnel;
10872         cmdline_fixed_string_t l2_tunnel_type;
10873         cmdline_fixed_string_t eth_type;
10874         uint16_t eth_type_val;
10875 };
10876
10877 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10878         TOKEN_STRING_INITIALIZER
10879                 (struct cmd_config_l2_tunnel_eth_type_result,
10880                  port, "port");
10881 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10882         TOKEN_STRING_INITIALIZER
10883                 (struct cmd_config_l2_tunnel_eth_type_result,
10884                  config, "config");
10885 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10886         TOKEN_STRING_INITIALIZER
10887                 (struct cmd_config_l2_tunnel_eth_type_result,
10888                  all, "all");
10889 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10890         TOKEN_NUM_INITIALIZER
10891                 (struct cmd_config_l2_tunnel_eth_type_result,
10892                  id, UINT8);
10893 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10894         TOKEN_STRING_INITIALIZER
10895                 (struct cmd_config_l2_tunnel_eth_type_result,
10896                  l2_tunnel, "l2-tunnel");
10897 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10898         TOKEN_STRING_INITIALIZER
10899                 (struct cmd_config_l2_tunnel_eth_type_result,
10900                  l2_tunnel_type, "E-tag");
10901 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10902         TOKEN_STRING_INITIALIZER
10903                 (struct cmd_config_l2_tunnel_eth_type_result,
10904                  eth_type, "ether-type");
10905 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10906         TOKEN_NUM_INITIALIZER
10907                 (struct cmd_config_l2_tunnel_eth_type_result,
10908                  eth_type_val, UINT16);
10909
10910 static enum rte_eth_tunnel_type
10911 str2fdir_l2_tunnel_type(char *string)
10912 {
10913         uint32_t i = 0;
10914
10915         static const struct {
10916                 char str[32];
10917                 enum rte_eth_tunnel_type type;
10918         } l2_tunnel_type_str[] = {
10919                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10920         };
10921
10922         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10923                 if (!strcmp(l2_tunnel_type_str[i].str, string))
10924                         return l2_tunnel_type_str[i].type;
10925         }
10926         return RTE_TUNNEL_TYPE_NONE;
10927 }
10928
10929 /* ether type config for all ports */
10930 static void
10931 cmd_config_l2_tunnel_eth_type_all_parsed
10932         (void *parsed_result,
10933          __attribute__((unused)) struct cmdline *cl,
10934          __attribute__((unused)) void *data)
10935 {
10936         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10937         struct rte_eth_l2_tunnel_conf entry;
10938         portid_t pid;
10939
10940         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10941         entry.ether_type = res->eth_type_val;
10942
10943         RTE_ETH_FOREACH_DEV(pid) {
10944                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10945         }
10946 }
10947
10948 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10949         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
10950         .data = NULL,
10951         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
10952         .tokens = {
10953                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10954                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10955                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
10956                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10957                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10958                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10959                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10960                 NULL,
10961         },
10962 };
10963
10964 /* ether type config for a specific port */
10965 static void
10966 cmd_config_l2_tunnel_eth_type_specific_parsed(
10967         void *parsed_result,
10968         __attribute__((unused)) struct cmdline *cl,
10969         __attribute__((unused)) void *data)
10970 {
10971         struct cmd_config_l2_tunnel_eth_type_result *res =
10972                  parsed_result;
10973         struct rte_eth_l2_tunnel_conf entry;
10974
10975         if (port_id_is_invalid(res->id, ENABLED_WARN))
10976                 return;
10977
10978         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10979         entry.ether_type = res->eth_type_val;
10980
10981         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10982 }
10983
10984 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10985         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
10986         .data = NULL,
10987         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
10988         .tokens = {
10989                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10990                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10991                 (void *)&cmd_config_l2_tunnel_eth_type_id,
10992                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10993                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10994                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10995                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10996                 NULL,
10997         },
10998 };
10999
11000 /* Enable/disable l2 tunnel */
11001 struct cmd_config_l2_tunnel_en_dis_result {
11002         cmdline_fixed_string_t port;
11003         cmdline_fixed_string_t config;
11004         cmdline_fixed_string_t all;
11005         uint8_t id;
11006         cmdline_fixed_string_t l2_tunnel;
11007         cmdline_fixed_string_t l2_tunnel_type;
11008         cmdline_fixed_string_t en_dis;
11009 };
11010
11011 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11012         TOKEN_STRING_INITIALIZER
11013                 (struct cmd_config_l2_tunnel_en_dis_result,
11014                  port, "port");
11015 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11016         TOKEN_STRING_INITIALIZER
11017                 (struct cmd_config_l2_tunnel_en_dis_result,
11018                  config, "config");
11019 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11020         TOKEN_STRING_INITIALIZER
11021                 (struct cmd_config_l2_tunnel_en_dis_result,
11022                  all, "all");
11023 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11024         TOKEN_NUM_INITIALIZER
11025                 (struct cmd_config_l2_tunnel_en_dis_result,
11026                  id, UINT8);
11027 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11028         TOKEN_STRING_INITIALIZER
11029                 (struct cmd_config_l2_tunnel_en_dis_result,
11030                  l2_tunnel, "l2-tunnel");
11031 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11032         TOKEN_STRING_INITIALIZER
11033                 (struct cmd_config_l2_tunnel_en_dis_result,
11034                  l2_tunnel_type, "E-tag");
11035 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11036         TOKEN_STRING_INITIALIZER
11037                 (struct cmd_config_l2_tunnel_en_dis_result,
11038                  en_dis, "enable#disable");
11039
11040 /* enable/disable l2 tunnel for all ports */
11041 static void
11042 cmd_config_l2_tunnel_en_dis_all_parsed(
11043         void *parsed_result,
11044         __attribute__((unused)) struct cmdline *cl,
11045         __attribute__((unused)) void *data)
11046 {
11047         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11048         struct rte_eth_l2_tunnel_conf entry;
11049         portid_t pid;
11050         uint8_t en;
11051
11052         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11053
11054         if (!strcmp("enable", res->en_dis))
11055                 en = 1;
11056         else
11057                 en = 0;
11058
11059         RTE_ETH_FOREACH_DEV(pid) {
11060                 rte_eth_dev_l2_tunnel_offload_set(pid,
11061                                                   &entry,
11062                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11063                                                   en);
11064         }
11065 }
11066
11067 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11068         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11069         .data = NULL,
11070         .help_str = "port config all l2-tunnel E-tag enable|disable",
11071         .tokens = {
11072                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11073                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11074                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11075                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11076                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11077                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11078                 NULL,
11079         },
11080 };
11081
11082 /* enable/disable l2 tunnel for a port */
11083 static void
11084 cmd_config_l2_tunnel_en_dis_specific_parsed(
11085         void *parsed_result,
11086         __attribute__((unused)) struct cmdline *cl,
11087         __attribute__((unused)) void *data)
11088 {
11089         struct cmd_config_l2_tunnel_en_dis_result *res =
11090                 parsed_result;
11091         struct rte_eth_l2_tunnel_conf entry;
11092
11093         if (port_id_is_invalid(res->id, ENABLED_WARN))
11094                 return;
11095
11096         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11097
11098         if (!strcmp("enable", res->en_dis))
11099                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11100                                                   &entry,
11101                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11102                                                   1);
11103         else
11104                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11105                                                   &entry,
11106                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11107                                                   0);
11108 }
11109
11110 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11111         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11112         .data = NULL,
11113         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11114         .tokens = {
11115                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11116                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11117                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11118                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11119                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11120                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11121                 NULL,
11122         },
11123 };
11124
11125 /* E-tag configuration */
11126
11127 /* Common result structure for all E-tag configuration */
11128 struct cmd_config_e_tag_result {
11129         cmdline_fixed_string_t e_tag;
11130         cmdline_fixed_string_t set;
11131         cmdline_fixed_string_t insertion;
11132         cmdline_fixed_string_t stripping;
11133         cmdline_fixed_string_t forwarding;
11134         cmdline_fixed_string_t filter;
11135         cmdline_fixed_string_t add;
11136         cmdline_fixed_string_t del;
11137         cmdline_fixed_string_t on;
11138         cmdline_fixed_string_t off;
11139         cmdline_fixed_string_t on_off;
11140         cmdline_fixed_string_t port_tag_id;
11141         uint32_t port_tag_id_val;
11142         cmdline_fixed_string_t e_tag_id;
11143         uint16_t e_tag_id_val;
11144         cmdline_fixed_string_t dst_pool;
11145         uint8_t dst_pool_val;
11146         cmdline_fixed_string_t port;
11147         uint8_t port_id;
11148         cmdline_fixed_string_t vf;
11149         uint8_t vf_id;
11150 };
11151
11152 /* Common CLI fields for all E-tag configuration */
11153 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11154         TOKEN_STRING_INITIALIZER
11155                 (struct cmd_config_e_tag_result,
11156                  e_tag, "E-tag");
11157 cmdline_parse_token_string_t cmd_config_e_tag_set =
11158         TOKEN_STRING_INITIALIZER
11159                 (struct cmd_config_e_tag_result,
11160                  set, "set");
11161 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11162         TOKEN_STRING_INITIALIZER
11163                 (struct cmd_config_e_tag_result,
11164                  insertion, "insertion");
11165 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11166         TOKEN_STRING_INITIALIZER
11167                 (struct cmd_config_e_tag_result,
11168                  stripping, "stripping");
11169 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11170         TOKEN_STRING_INITIALIZER
11171                 (struct cmd_config_e_tag_result,
11172                  forwarding, "forwarding");
11173 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11174         TOKEN_STRING_INITIALIZER
11175                 (struct cmd_config_e_tag_result,
11176                  filter, "filter");
11177 cmdline_parse_token_string_t cmd_config_e_tag_add =
11178         TOKEN_STRING_INITIALIZER
11179                 (struct cmd_config_e_tag_result,
11180                  add, "add");
11181 cmdline_parse_token_string_t cmd_config_e_tag_del =
11182         TOKEN_STRING_INITIALIZER
11183                 (struct cmd_config_e_tag_result,
11184                  del, "del");
11185 cmdline_parse_token_string_t cmd_config_e_tag_on =
11186         TOKEN_STRING_INITIALIZER
11187                 (struct cmd_config_e_tag_result,
11188                  on, "on");
11189 cmdline_parse_token_string_t cmd_config_e_tag_off =
11190         TOKEN_STRING_INITIALIZER
11191                 (struct cmd_config_e_tag_result,
11192                  off, "off");
11193 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11194         TOKEN_STRING_INITIALIZER
11195                 (struct cmd_config_e_tag_result,
11196                  on_off, "on#off");
11197 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11198         TOKEN_STRING_INITIALIZER
11199                 (struct cmd_config_e_tag_result,
11200                  port_tag_id, "port-tag-id");
11201 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11202         TOKEN_NUM_INITIALIZER
11203                 (struct cmd_config_e_tag_result,
11204                  port_tag_id_val, UINT32);
11205 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11206         TOKEN_STRING_INITIALIZER
11207                 (struct cmd_config_e_tag_result,
11208                  e_tag_id, "e-tag-id");
11209 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11210         TOKEN_NUM_INITIALIZER
11211                 (struct cmd_config_e_tag_result,
11212                  e_tag_id_val, UINT16);
11213 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11214         TOKEN_STRING_INITIALIZER
11215                 (struct cmd_config_e_tag_result,
11216                  dst_pool, "dst-pool");
11217 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11218         TOKEN_NUM_INITIALIZER
11219                 (struct cmd_config_e_tag_result,
11220                  dst_pool_val, UINT8);
11221 cmdline_parse_token_string_t cmd_config_e_tag_port =
11222         TOKEN_STRING_INITIALIZER
11223                 (struct cmd_config_e_tag_result,
11224                  port, "port");
11225 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11226         TOKEN_NUM_INITIALIZER
11227                 (struct cmd_config_e_tag_result,
11228                  port_id, UINT8);
11229 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11230         TOKEN_STRING_INITIALIZER
11231                 (struct cmd_config_e_tag_result,
11232                  vf, "vf");
11233 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11234         TOKEN_NUM_INITIALIZER
11235                 (struct cmd_config_e_tag_result,
11236                  vf_id, UINT8);
11237
11238 /* E-tag insertion configuration */
11239 static void
11240 cmd_config_e_tag_insertion_en_parsed(
11241         void *parsed_result,
11242         __attribute__((unused)) struct cmdline *cl,
11243         __attribute__((unused)) void *data)
11244 {
11245         struct cmd_config_e_tag_result *res =
11246                 parsed_result;
11247         struct rte_eth_l2_tunnel_conf entry;
11248
11249         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11250                 return;
11251
11252         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11253         entry.tunnel_id = res->port_tag_id_val;
11254         entry.vf_id = res->vf_id;
11255         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11256                                           &entry,
11257                                           ETH_L2_TUNNEL_INSERTION_MASK,
11258                                           1);
11259 }
11260
11261 static void
11262 cmd_config_e_tag_insertion_dis_parsed(
11263         void *parsed_result,
11264         __attribute__((unused)) struct cmdline *cl,
11265         __attribute__((unused)) void *data)
11266 {
11267         struct cmd_config_e_tag_result *res =
11268                 parsed_result;
11269         struct rte_eth_l2_tunnel_conf entry;
11270
11271         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11272                 return;
11273
11274         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11275         entry.vf_id = res->vf_id;
11276
11277         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11278                                           &entry,
11279                                           ETH_L2_TUNNEL_INSERTION_MASK,
11280                                           0);
11281 }
11282
11283 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11284         .f = cmd_config_e_tag_insertion_en_parsed,
11285         .data = NULL,
11286         .help_str = "E-tag ... : E-tag insertion enable",
11287         .tokens = {
11288                 (void *)&cmd_config_e_tag_e_tag,
11289                 (void *)&cmd_config_e_tag_set,
11290                 (void *)&cmd_config_e_tag_insertion,
11291                 (void *)&cmd_config_e_tag_on,
11292                 (void *)&cmd_config_e_tag_port_tag_id,
11293                 (void *)&cmd_config_e_tag_port_tag_id_val,
11294                 (void *)&cmd_config_e_tag_port,
11295                 (void *)&cmd_config_e_tag_port_id,
11296                 (void *)&cmd_config_e_tag_vf,
11297                 (void *)&cmd_config_e_tag_vf_id,
11298                 NULL,
11299         },
11300 };
11301
11302 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11303         .f = cmd_config_e_tag_insertion_dis_parsed,
11304         .data = NULL,
11305         .help_str = "E-tag ... : E-tag insertion disable",
11306         .tokens = {
11307                 (void *)&cmd_config_e_tag_e_tag,
11308                 (void *)&cmd_config_e_tag_set,
11309                 (void *)&cmd_config_e_tag_insertion,
11310                 (void *)&cmd_config_e_tag_off,
11311                 (void *)&cmd_config_e_tag_port,
11312                 (void *)&cmd_config_e_tag_port_id,
11313                 (void *)&cmd_config_e_tag_vf,
11314                 (void *)&cmd_config_e_tag_vf_id,
11315                 NULL,
11316         },
11317 };
11318
11319 /* E-tag stripping configuration */
11320 static void
11321 cmd_config_e_tag_stripping_parsed(
11322         void *parsed_result,
11323         __attribute__((unused)) struct cmdline *cl,
11324         __attribute__((unused)) void *data)
11325 {
11326         struct cmd_config_e_tag_result *res =
11327                 parsed_result;
11328         struct rte_eth_l2_tunnel_conf entry;
11329
11330         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11331                 return;
11332
11333         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11334
11335         if (!strcmp(res->on_off, "on"))
11336                 rte_eth_dev_l2_tunnel_offload_set
11337                         (res->port_id,
11338                          &entry,
11339                          ETH_L2_TUNNEL_STRIPPING_MASK,
11340                          1);
11341         else
11342                 rte_eth_dev_l2_tunnel_offload_set
11343                         (res->port_id,
11344                          &entry,
11345                          ETH_L2_TUNNEL_STRIPPING_MASK,
11346                          0);
11347 }
11348
11349 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11350         .f = cmd_config_e_tag_stripping_parsed,
11351         .data = NULL,
11352         .help_str = "E-tag ... : E-tag stripping enable/disable",
11353         .tokens = {
11354                 (void *)&cmd_config_e_tag_e_tag,
11355                 (void *)&cmd_config_e_tag_set,
11356                 (void *)&cmd_config_e_tag_stripping,
11357                 (void *)&cmd_config_e_tag_on_off,
11358                 (void *)&cmd_config_e_tag_port,
11359                 (void *)&cmd_config_e_tag_port_id,
11360                 NULL,
11361         },
11362 };
11363
11364 /* E-tag forwarding configuration */
11365 static void
11366 cmd_config_e_tag_forwarding_parsed(
11367         void *parsed_result,
11368         __attribute__((unused)) struct cmdline *cl,
11369         __attribute__((unused)) void *data)
11370 {
11371         struct cmd_config_e_tag_result *res = parsed_result;
11372         struct rte_eth_l2_tunnel_conf entry;
11373
11374         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11375                 return;
11376
11377         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11378
11379         if (!strcmp(res->on_off, "on"))
11380                 rte_eth_dev_l2_tunnel_offload_set
11381                         (res->port_id,
11382                          &entry,
11383                          ETH_L2_TUNNEL_FORWARDING_MASK,
11384                          1);
11385         else
11386                 rte_eth_dev_l2_tunnel_offload_set
11387                         (res->port_id,
11388                          &entry,
11389                          ETH_L2_TUNNEL_FORWARDING_MASK,
11390                          0);
11391 }
11392
11393 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11394         .f = cmd_config_e_tag_forwarding_parsed,
11395         .data = NULL,
11396         .help_str = "E-tag ... : E-tag forwarding enable/disable",
11397         .tokens = {
11398                 (void *)&cmd_config_e_tag_e_tag,
11399                 (void *)&cmd_config_e_tag_set,
11400                 (void *)&cmd_config_e_tag_forwarding,
11401                 (void *)&cmd_config_e_tag_on_off,
11402                 (void *)&cmd_config_e_tag_port,
11403                 (void *)&cmd_config_e_tag_port_id,
11404                 NULL,
11405         },
11406 };
11407
11408 /* E-tag filter configuration */
11409 static void
11410 cmd_config_e_tag_filter_add_parsed(
11411         void *parsed_result,
11412         __attribute__((unused)) struct cmdline *cl,
11413         __attribute__((unused)) void *data)
11414 {
11415         struct cmd_config_e_tag_result *res = parsed_result;
11416         struct rte_eth_l2_tunnel_conf entry;
11417         int ret = 0;
11418
11419         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11420                 return;
11421
11422         if (res->e_tag_id_val > 0x3fff) {
11423                 printf("e-tag-id must be equal or less than 0x3fff.\n");
11424                 return;
11425         }
11426
11427         ret = rte_eth_dev_filter_supported(res->port_id,
11428                                            RTE_ETH_FILTER_L2_TUNNEL);
11429         if (ret < 0) {
11430                 printf("E-tag filter is not supported on port %u.\n",
11431                        res->port_id);
11432                 return;
11433         }
11434
11435         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11436         entry.tunnel_id = res->e_tag_id_val;
11437         entry.pool = res->dst_pool_val;
11438
11439         ret = rte_eth_dev_filter_ctrl(res->port_id,
11440                                       RTE_ETH_FILTER_L2_TUNNEL,
11441                                       RTE_ETH_FILTER_ADD,
11442                                       &entry);
11443         if (ret < 0)
11444                 printf("E-tag filter programming error: (%s)\n",
11445                        strerror(-ret));
11446 }
11447
11448 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
11449         .f = cmd_config_e_tag_filter_add_parsed,
11450         .data = NULL,
11451         .help_str = "E-tag ... : E-tag filter add",
11452         .tokens = {
11453                 (void *)&cmd_config_e_tag_e_tag,
11454                 (void *)&cmd_config_e_tag_set,
11455                 (void *)&cmd_config_e_tag_filter,
11456                 (void *)&cmd_config_e_tag_add,
11457                 (void *)&cmd_config_e_tag_e_tag_id,
11458                 (void *)&cmd_config_e_tag_e_tag_id_val,
11459                 (void *)&cmd_config_e_tag_dst_pool,
11460                 (void *)&cmd_config_e_tag_dst_pool_val,
11461                 (void *)&cmd_config_e_tag_port,
11462                 (void *)&cmd_config_e_tag_port_id,
11463                 NULL,
11464         },
11465 };
11466
11467 static void
11468 cmd_config_e_tag_filter_del_parsed(
11469         void *parsed_result,
11470         __attribute__((unused)) struct cmdline *cl,
11471         __attribute__((unused)) void *data)
11472 {
11473         struct cmd_config_e_tag_result *res = parsed_result;
11474         struct rte_eth_l2_tunnel_conf entry;
11475         int ret = 0;
11476
11477         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11478                 return;
11479
11480         if (res->e_tag_id_val > 0x3fff) {
11481                 printf("e-tag-id must be less than 0x3fff.\n");
11482                 return;
11483         }
11484
11485         ret = rte_eth_dev_filter_supported(res->port_id,
11486                                            RTE_ETH_FILTER_L2_TUNNEL);
11487         if (ret < 0) {
11488                 printf("E-tag filter is not supported on port %u.\n",
11489                        res->port_id);
11490                 return;
11491         }
11492
11493         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11494         entry.tunnel_id = res->e_tag_id_val;
11495
11496         ret = rte_eth_dev_filter_ctrl(res->port_id,
11497                                       RTE_ETH_FILTER_L2_TUNNEL,
11498                                       RTE_ETH_FILTER_DELETE,
11499                                       &entry);
11500         if (ret < 0)
11501                 printf("E-tag filter programming error: (%s)\n",
11502                        strerror(-ret));
11503 }
11504
11505 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
11506         .f = cmd_config_e_tag_filter_del_parsed,
11507         .data = NULL,
11508         .help_str = "E-tag ... : E-tag filter delete",
11509         .tokens = {
11510                 (void *)&cmd_config_e_tag_e_tag,
11511                 (void *)&cmd_config_e_tag_set,
11512                 (void *)&cmd_config_e_tag_filter,
11513                 (void *)&cmd_config_e_tag_del,
11514                 (void *)&cmd_config_e_tag_e_tag_id,
11515                 (void *)&cmd_config_e_tag_e_tag_id_val,
11516                 (void *)&cmd_config_e_tag_port,
11517                 (void *)&cmd_config_e_tag_port_id,
11518                 NULL,
11519         },
11520 };
11521
11522 /* vf vlan anti spoof configuration */
11523
11524 /* Common result structure for vf vlan anti spoof */
11525 struct cmd_vf_vlan_anti_spoof_result {
11526         cmdline_fixed_string_t set;
11527         cmdline_fixed_string_t vf;
11528         cmdline_fixed_string_t vlan;
11529         cmdline_fixed_string_t antispoof;
11530         uint8_t port_id;
11531         uint32_t vf_id;
11532         cmdline_fixed_string_t on_off;
11533 };
11534
11535 /* Common CLI fields for vf vlan anti spoof enable disable */
11536 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11537         TOKEN_STRING_INITIALIZER
11538                 (struct cmd_vf_vlan_anti_spoof_result,
11539                  set, "set");
11540 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11541         TOKEN_STRING_INITIALIZER
11542                 (struct cmd_vf_vlan_anti_spoof_result,
11543                  vf, "vf");
11544 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11545         TOKEN_STRING_INITIALIZER
11546                 (struct cmd_vf_vlan_anti_spoof_result,
11547                  vlan, "vlan");
11548 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11549         TOKEN_STRING_INITIALIZER
11550                 (struct cmd_vf_vlan_anti_spoof_result,
11551                  antispoof, "antispoof");
11552 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11553         TOKEN_NUM_INITIALIZER
11554                 (struct cmd_vf_vlan_anti_spoof_result,
11555                  port_id, UINT8);
11556 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11557         TOKEN_NUM_INITIALIZER
11558                 (struct cmd_vf_vlan_anti_spoof_result,
11559                  vf_id, UINT32);
11560 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11561         TOKEN_STRING_INITIALIZER
11562                 (struct cmd_vf_vlan_anti_spoof_result,
11563                  on_off, "on#off");
11564
11565 static void
11566 cmd_set_vf_vlan_anti_spoof_parsed(
11567         void *parsed_result,
11568         __attribute__((unused)) struct cmdline *cl,
11569         __attribute__((unused)) void *data)
11570 {
11571         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11572         int ret = -ENOTSUP;
11573
11574         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11575
11576         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11577                 return;
11578
11579 #ifdef RTE_LIBRTE_IXGBE_PMD
11580         if (ret == -ENOTSUP)
11581                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11582                                 res->vf_id, is_on);
11583 #endif
11584 #ifdef RTE_LIBRTE_I40E_PMD
11585         if (ret == -ENOTSUP)
11586                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11587                                 res->vf_id, is_on);
11588 #endif
11589 #ifdef RTE_LIBRTE_BNXT_PMD
11590         if (ret == -ENOTSUP)
11591                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11592                                 res->vf_id, is_on);
11593 #endif
11594
11595         switch (ret) {
11596         case 0:
11597                 break;
11598         case -EINVAL:
11599                 printf("invalid vf_id %d\n", res->vf_id);
11600                 break;
11601         case -ENODEV:
11602                 printf("invalid port_id %d\n", res->port_id);
11603                 break;
11604         case -ENOTSUP:
11605                 printf("function not implemented\n");
11606                 break;
11607         default:
11608                 printf("programming error: (%s)\n", strerror(-ret));
11609         }
11610 }
11611
11612 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11613         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11614         .data = NULL,
11615         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11616         .tokens = {
11617                 (void *)&cmd_vf_vlan_anti_spoof_set,
11618                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11619                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11620                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11621                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11622                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11623                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11624                 NULL,
11625         },
11626 };
11627
11628 /* vf mac anti spoof configuration */
11629
11630 /* Common result structure for vf mac anti spoof */
11631 struct cmd_vf_mac_anti_spoof_result {
11632         cmdline_fixed_string_t set;
11633         cmdline_fixed_string_t vf;
11634         cmdline_fixed_string_t mac;
11635         cmdline_fixed_string_t antispoof;
11636         uint8_t port_id;
11637         uint32_t vf_id;
11638         cmdline_fixed_string_t on_off;
11639 };
11640
11641 /* Common CLI fields for vf mac anti spoof enable disable */
11642 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11643         TOKEN_STRING_INITIALIZER
11644                 (struct cmd_vf_mac_anti_spoof_result,
11645                  set, "set");
11646 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11647         TOKEN_STRING_INITIALIZER
11648                 (struct cmd_vf_mac_anti_spoof_result,
11649                  vf, "vf");
11650 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11651         TOKEN_STRING_INITIALIZER
11652                 (struct cmd_vf_mac_anti_spoof_result,
11653                  mac, "mac");
11654 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11655         TOKEN_STRING_INITIALIZER
11656                 (struct cmd_vf_mac_anti_spoof_result,
11657                  antispoof, "antispoof");
11658 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11659         TOKEN_NUM_INITIALIZER
11660                 (struct cmd_vf_mac_anti_spoof_result,
11661                  port_id, UINT8);
11662 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11663         TOKEN_NUM_INITIALIZER
11664                 (struct cmd_vf_mac_anti_spoof_result,
11665                  vf_id, UINT32);
11666 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11667         TOKEN_STRING_INITIALIZER
11668                 (struct cmd_vf_mac_anti_spoof_result,
11669                  on_off, "on#off");
11670
11671 static void
11672 cmd_set_vf_mac_anti_spoof_parsed(
11673         void *parsed_result,
11674         __attribute__((unused)) struct cmdline *cl,
11675         __attribute__((unused)) void *data)
11676 {
11677         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11678         int ret = -ENOTSUP;
11679
11680         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11681
11682         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11683                 return;
11684
11685 #ifdef RTE_LIBRTE_IXGBE_PMD
11686         if (ret == -ENOTSUP)
11687                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11688                         res->vf_id, is_on);
11689 #endif
11690 #ifdef RTE_LIBRTE_I40E_PMD
11691         if (ret == -ENOTSUP)
11692                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11693                         res->vf_id, is_on);
11694 #endif
11695 #ifdef RTE_LIBRTE_BNXT_PMD
11696         if (ret == -ENOTSUP)
11697                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11698                         res->vf_id, is_on);
11699 #endif
11700
11701         switch (ret) {
11702         case 0:
11703                 break;
11704         case -EINVAL:
11705                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11706                 break;
11707         case -ENODEV:
11708                 printf("invalid port_id %d\n", res->port_id);
11709                 break;
11710         case -ENOTSUP:
11711                 printf("function not implemented\n");
11712                 break;
11713         default:
11714                 printf("programming error: (%s)\n", strerror(-ret));
11715         }
11716 }
11717
11718 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11719         .f = cmd_set_vf_mac_anti_spoof_parsed,
11720         .data = NULL,
11721         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11722         .tokens = {
11723                 (void *)&cmd_vf_mac_anti_spoof_set,
11724                 (void *)&cmd_vf_mac_anti_spoof_vf,
11725                 (void *)&cmd_vf_mac_anti_spoof_mac,
11726                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11727                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11728                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11729                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11730                 NULL,
11731         },
11732 };
11733
11734 /* vf vlan strip queue configuration */
11735
11736 /* Common result structure for vf mac anti spoof */
11737 struct cmd_vf_vlan_stripq_result {
11738         cmdline_fixed_string_t set;
11739         cmdline_fixed_string_t vf;
11740         cmdline_fixed_string_t vlan;
11741         cmdline_fixed_string_t stripq;
11742         portid_t port_id;
11743         uint16_t vf_id;
11744         cmdline_fixed_string_t on_off;
11745 };
11746
11747 /* Common CLI fields for vf vlan strip enable disable */
11748 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11749         TOKEN_STRING_INITIALIZER
11750                 (struct cmd_vf_vlan_stripq_result,
11751                  set, "set");
11752 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11753         TOKEN_STRING_INITIALIZER
11754                 (struct cmd_vf_vlan_stripq_result,
11755                  vf, "vf");
11756 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11757         TOKEN_STRING_INITIALIZER
11758                 (struct cmd_vf_vlan_stripq_result,
11759                  vlan, "vlan");
11760 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11761         TOKEN_STRING_INITIALIZER
11762                 (struct cmd_vf_vlan_stripq_result,
11763                  stripq, "stripq");
11764 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11765         TOKEN_NUM_INITIALIZER
11766                 (struct cmd_vf_vlan_stripq_result,
11767                  port_id, UINT8);
11768 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11769         TOKEN_NUM_INITIALIZER
11770                 (struct cmd_vf_vlan_stripq_result,
11771                  vf_id, UINT16);
11772 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11773         TOKEN_STRING_INITIALIZER
11774                 (struct cmd_vf_vlan_stripq_result,
11775                  on_off, "on#off");
11776
11777 static void
11778 cmd_set_vf_vlan_stripq_parsed(
11779         void *parsed_result,
11780         __attribute__((unused)) struct cmdline *cl,
11781         __attribute__((unused)) void *data)
11782 {
11783         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11784         int ret = -ENOTSUP;
11785
11786         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11787
11788         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11789                 return;
11790
11791 #ifdef RTE_LIBRTE_IXGBE_PMD
11792         if (ret == -ENOTSUP)
11793                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11794                         res->vf_id, is_on);
11795 #endif
11796 #ifdef RTE_LIBRTE_I40E_PMD
11797         if (ret == -ENOTSUP)
11798                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11799                         res->vf_id, is_on);
11800 #endif
11801 #ifdef RTE_LIBRTE_BNXT_PMD
11802         if (ret == -ENOTSUP)
11803                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11804                         res->vf_id, is_on);
11805 #endif
11806
11807         switch (ret) {
11808         case 0:
11809                 break;
11810         case -EINVAL:
11811                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11812                 break;
11813         case -ENODEV:
11814                 printf("invalid port_id %d\n", res->port_id);
11815                 break;
11816         case -ENOTSUP:
11817                 printf("function not implemented\n");
11818                 break;
11819         default:
11820                 printf("programming error: (%s)\n", strerror(-ret));
11821         }
11822 }
11823
11824 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11825         .f = cmd_set_vf_vlan_stripq_parsed,
11826         .data = NULL,
11827         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11828         .tokens = {
11829                 (void *)&cmd_vf_vlan_stripq_set,
11830                 (void *)&cmd_vf_vlan_stripq_vf,
11831                 (void *)&cmd_vf_vlan_stripq_vlan,
11832                 (void *)&cmd_vf_vlan_stripq_stripq,
11833                 (void *)&cmd_vf_vlan_stripq_port_id,
11834                 (void *)&cmd_vf_vlan_stripq_vf_id,
11835                 (void *)&cmd_vf_vlan_stripq_on_off,
11836                 NULL,
11837         },
11838 };
11839
11840 /* vf vlan insert configuration */
11841
11842 /* Common result structure for vf vlan insert */
11843 struct cmd_vf_vlan_insert_result {
11844         cmdline_fixed_string_t set;
11845         cmdline_fixed_string_t vf;
11846         cmdline_fixed_string_t vlan;
11847         cmdline_fixed_string_t insert;
11848         uint8_t port_id;
11849         uint16_t vf_id;
11850         uint16_t vlan_id;
11851 };
11852
11853 /* Common CLI fields for vf vlan insert enable disable */
11854 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11855         TOKEN_STRING_INITIALIZER
11856                 (struct cmd_vf_vlan_insert_result,
11857                  set, "set");
11858 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11859         TOKEN_STRING_INITIALIZER
11860                 (struct cmd_vf_vlan_insert_result,
11861                  vf, "vf");
11862 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11863         TOKEN_STRING_INITIALIZER
11864                 (struct cmd_vf_vlan_insert_result,
11865                  vlan, "vlan");
11866 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11867         TOKEN_STRING_INITIALIZER
11868                 (struct cmd_vf_vlan_insert_result,
11869                  insert, "insert");
11870 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11871         TOKEN_NUM_INITIALIZER
11872                 (struct cmd_vf_vlan_insert_result,
11873                  port_id, UINT8);
11874 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11875         TOKEN_NUM_INITIALIZER
11876                 (struct cmd_vf_vlan_insert_result,
11877                  vf_id, UINT16);
11878 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11879         TOKEN_NUM_INITIALIZER
11880                 (struct cmd_vf_vlan_insert_result,
11881                  vlan_id, UINT16);
11882
11883 static void
11884 cmd_set_vf_vlan_insert_parsed(
11885         void *parsed_result,
11886         __attribute__((unused)) struct cmdline *cl,
11887         __attribute__((unused)) void *data)
11888 {
11889         struct cmd_vf_vlan_insert_result *res = parsed_result;
11890         int ret = -ENOTSUP;
11891
11892         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11893                 return;
11894
11895 #ifdef RTE_LIBRTE_IXGBE_PMD
11896         if (ret == -ENOTSUP)
11897                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11898                         res->vlan_id);
11899 #endif
11900 #ifdef RTE_LIBRTE_I40E_PMD
11901         if (ret == -ENOTSUP)
11902                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11903                         res->vlan_id);
11904 #endif
11905 #ifdef RTE_LIBRTE_BNXT_PMD
11906         if (ret == -ENOTSUP)
11907                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11908                         res->vlan_id);
11909 #endif
11910
11911         switch (ret) {
11912         case 0:
11913                 break;
11914         case -EINVAL:
11915                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11916                 break;
11917         case -ENODEV:
11918                 printf("invalid port_id %d\n", res->port_id);
11919                 break;
11920         case -ENOTSUP:
11921                 printf("function not implemented\n");
11922                 break;
11923         default:
11924                 printf("programming error: (%s)\n", strerror(-ret));
11925         }
11926 }
11927
11928 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11929         .f = cmd_set_vf_vlan_insert_parsed,
11930         .data = NULL,
11931         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11932         .tokens = {
11933                 (void *)&cmd_vf_vlan_insert_set,
11934                 (void *)&cmd_vf_vlan_insert_vf,
11935                 (void *)&cmd_vf_vlan_insert_vlan,
11936                 (void *)&cmd_vf_vlan_insert_insert,
11937                 (void *)&cmd_vf_vlan_insert_port_id,
11938                 (void *)&cmd_vf_vlan_insert_vf_id,
11939                 (void *)&cmd_vf_vlan_insert_vlan_id,
11940                 NULL,
11941         },
11942 };
11943
11944 /* tx loopback configuration */
11945
11946 /* Common result structure for tx loopback */
11947 struct cmd_tx_loopback_result {
11948         cmdline_fixed_string_t set;
11949         cmdline_fixed_string_t tx;
11950         cmdline_fixed_string_t loopback;
11951         uint8_t port_id;
11952         cmdline_fixed_string_t on_off;
11953 };
11954
11955 /* Common CLI fields for tx loopback enable disable */
11956 cmdline_parse_token_string_t cmd_tx_loopback_set =
11957         TOKEN_STRING_INITIALIZER
11958                 (struct cmd_tx_loopback_result,
11959                  set, "set");
11960 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11961         TOKEN_STRING_INITIALIZER
11962                 (struct cmd_tx_loopback_result,
11963                  tx, "tx");
11964 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11965         TOKEN_STRING_INITIALIZER
11966                 (struct cmd_tx_loopback_result,
11967                  loopback, "loopback");
11968 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11969         TOKEN_NUM_INITIALIZER
11970                 (struct cmd_tx_loopback_result,
11971                  port_id, UINT8);
11972 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11973         TOKEN_STRING_INITIALIZER
11974                 (struct cmd_tx_loopback_result,
11975                  on_off, "on#off");
11976
11977 static void
11978 cmd_set_tx_loopback_parsed(
11979         void *parsed_result,
11980         __attribute__((unused)) struct cmdline *cl,
11981         __attribute__((unused)) void *data)
11982 {
11983         struct cmd_tx_loopback_result *res = parsed_result;
11984         int ret = -ENOTSUP;
11985
11986         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11987
11988         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11989                 return;
11990
11991 #ifdef RTE_LIBRTE_IXGBE_PMD
11992         if (ret == -ENOTSUP)
11993                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11994 #endif
11995 #ifdef RTE_LIBRTE_I40E_PMD
11996         if (ret == -ENOTSUP)
11997                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11998 #endif
11999 #ifdef RTE_LIBRTE_BNXT_PMD
12000         if (ret == -ENOTSUP)
12001                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12002 #endif
12003
12004         switch (ret) {
12005         case 0:
12006                 break;
12007         case -EINVAL:
12008                 printf("invalid is_on %d\n", is_on);
12009                 break;
12010         case -ENODEV:
12011                 printf("invalid port_id %d\n", res->port_id);
12012                 break;
12013         case -ENOTSUP:
12014                 printf("function not implemented\n");
12015                 break;
12016         default:
12017                 printf("programming error: (%s)\n", strerror(-ret));
12018         }
12019 }
12020
12021 cmdline_parse_inst_t cmd_set_tx_loopback = {
12022         .f = cmd_set_tx_loopback_parsed,
12023         .data = NULL,
12024         .help_str = "set tx loopback <port_id> on|off",
12025         .tokens = {
12026                 (void *)&cmd_tx_loopback_set,
12027                 (void *)&cmd_tx_loopback_tx,
12028                 (void *)&cmd_tx_loopback_loopback,
12029                 (void *)&cmd_tx_loopback_port_id,
12030                 (void *)&cmd_tx_loopback_on_off,
12031                 NULL,
12032         },
12033 };
12034
12035 /* all queues drop enable configuration */
12036
12037 /* Common result structure for all queues drop enable */
12038 struct cmd_all_queues_drop_en_result {
12039         cmdline_fixed_string_t set;
12040         cmdline_fixed_string_t all;
12041         cmdline_fixed_string_t queues;
12042         cmdline_fixed_string_t drop;
12043         uint8_t port_id;
12044         cmdline_fixed_string_t on_off;
12045 };
12046
12047 /* Common CLI fields for tx loopback enable disable */
12048 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12049         TOKEN_STRING_INITIALIZER
12050                 (struct cmd_all_queues_drop_en_result,
12051                  set, "set");
12052 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12053         TOKEN_STRING_INITIALIZER
12054                 (struct cmd_all_queues_drop_en_result,
12055                  all, "all");
12056 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12057         TOKEN_STRING_INITIALIZER
12058                 (struct cmd_all_queues_drop_en_result,
12059                  queues, "queues");
12060 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12061         TOKEN_STRING_INITIALIZER
12062                 (struct cmd_all_queues_drop_en_result,
12063                  drop, "drop");
12064 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12065         TOKEN_NUM_INITIALIZER
12066                 (struct cmd_all_queues_drop_en_result,
12067                  port_id, UINT8);
12068 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12069         TOKEN_STRING_INITIALIZER
12070                 (struct cmd_all_queues_drop_en_result,
12071                  on_off, "on#off");
12072
12073 static void
12074 cmd_set_all_queues_drop_en_parsed(
12075         void *parsed_result,
12076         __attribute__((unused)) struct cmdline *cl,
12077         __attribute__((unused)) void *data)
12078 {
12079         struct cmd_all_queues_drop_en_result *res = parsed_result;
12080         int ret = -ENOTSUP;
12081         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12082
12083         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12084                 return;
12085
12086 #ifdef RTE_LIBRTE_IXGBE_PMD
12087         if (ret == -ENOTSUP)
12088                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12089 #endif
12090 #ifdef RTE_LIBRTE_BNXT_PMD
12091         if (ret == -ENOTSUP)
12092                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12093 #endif
12094         switch (ret) {
12095         case 0:
12096                 break;
12097         case -EINVAL:
12098                 printf("invalid is_on %d\n", is_on);
12099                 break;
12100         case -ENODEV:
12101                 printf("invalid port_id %d\n", res->port_id);
12102                 break;
12103         case -ENOTSUP:
12104                 printf("function not implemented\n");
12105                 break;
12106         default:
12107                 printf("programming error: (%s)\n", strerror(-ret));
12108         }
12109 }
12110
12111 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12112         .f = cmd_set_all_queues_drop_en_parsed,
12113         .data = NULL,
12114         .help_str = "set all queues drop <port_id> on|off",
12115         .tokens = {
12116                 (void *)&cmd_all_queues_drop_en_set,
12117                 (void *)&cmd_all_queues_drop_en_all,
12118                 (void *)&cmd_all_queues_drop_en_queues,
12119                 (void *)&cmd_all_queues_drop_en_drop,
12120                 (void *)&cmd_all_queues_drop_en_port_id,
12121                 (void *)&cmd_all_queues_drop_en_on_off,
12122                 NULL,
12123         },
12124 };
12125
12126 /* vf split drop enable configuration */
12127
12128 /* Common result structure for vf split drop enable */
12129 struct cmd_vf_split_drop_en_result {
12130         cmdline_fixed_string_t set;
12131         cmdline_fixed_string_t vf;
12132         cmdline_fixed_string_t split;
12133         cmdline_fixed_string_t drop;
12134         uint8_t port_id;
12135         uint16_t vf_id;
12136         cmdline_fixed_string_t on_off;
12137 };
12138
12139 /* Common CLI fields for vf split drop enable disable */
12140 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12141         TOKEN_STRING_INITIALIZER
12142                 (struct cmd_vf_split_drop_en_result,
12143                  set, "set");
12144 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12145         TOKEN_STRING_INITIALIZER
12146                 (struct cmd_vf_split_drop_en_result,
12147                  vf, "vf");
12148 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12149         TOKEN_STRING_INITIALIZER
12150                 (struct cmd_vf_split_drop_en_result,
12151                  split, "split");
12152 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12153         TOKEN_STRING_INITIALIZER
12154                 (struct cmd_vf_split_drop_en_result,
12155                  drop, "drop");
12156 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12157         TOKEN_NUM_INITIALIZER
12158                 (struct cmd_vf_split_drop_en_result,
12159                  port_id, UINT8);
12160 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12161         TOKEN_NUM_INITIALIZER
12162                 (struct cmd_vf_split_drop_en_result,
12163                  vf_id, UINT16);
12164 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12165         TOKEN_STRING_INITIALIZER
12166                 (struct cmd_vf_split_drop_en_result,
12167                  on_off, "on#off");
12168
12169 static void
12170 cmd_set_vf_split_drop_en_parsed(
12171         void *parsed_result,
12172         __attribute__((unused)) struct cmdline *cl,
12173         __attribute__((unused)) void *data)
12174 {
12175         struct cmd_vf_split_drop_en_result *res = parsed_result;
12176         int ret = -ENOTSUP;
12177         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12178
12179         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12180                 return;
12181
12182 #ifdef RTE_LIBRTE_IXGBE_PMD
12183         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12184                         is_on);
12185 #endif
12186         switch (ret) {
12187         case 0:
12188                 break;
12189         case -EINVAL:
12190                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12191                 break;
12192         case -ENODEV:
12193                 printf("invalid port_id %d\n", res->port_id);
12194                 break;
12195         case -ENOTSUP:
12196                 printf("not supported on port %d\n", res->port_id);
12197                 break;
12198         default:
12199                 printf("programming error: (%s)\n", strerror(-ret));
12200         }
12201 }
12202
12203 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12204         .f = cmd_set_vf_split_drop_en_parsed,
12205         .data = NULL,
12206         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12207         .tokens = {
12208                 (void *)&cmd_vf_split_drop_en_set,
12209                 (void *)&cmd_vf_split_drop_en_vf,
12210                 (void *)&cmd_vf_split_drop_en_split,
12211                 (void *)&cmd_vf_split_drop_en_drop,
12212                 (void *)&cmd_vf_split_drop_en_port_id,
12213                 (void *)&cmd_vf_split_drop_en_vf_id,
12214                 (void *)&cmd_vf_split_drop_en_on_off,
12215                 NULL,
12216         },
12217 };
12218
12219 /* vf mac address configuration */
12220
12221 /* Common result structure for vf mac address */
12222 struct cmd_set_vf_mac_addr_result {
12223         cmdline_fixed_string_t set;
12224         cmdline_fixed_string_t vf;
12225         cmdline_fixed_string_t mac;
12226         cmdline_fixed_string_t addr;
12227         uint8_t port_id;
12228         uint16_t vf_id;
12229         struct ether_addr mac_addr;
12230
12231 };
12232
12233 /* Common CLI fields for vf split drop enable disable */
12234 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12235         TOKEN_STRING_INITIALIZER
12236                 (struct cmd_set_vf_mac_addr_result,
12237                  set, "set");
12238 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12239         TOKEN_STRING_INITIALIZER
12240                 (struct cmd_set_vf_mac_addr_result,
12241                  vf, "vf");
12242 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12243         TOKEN_STRING_INITIALIZER
12244                 (struct cmd_set_vf_mac_addr_result,
12245                  mac, "mac");
12246 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12247         TOKEN_STRING_INITIALIZER
12248                 (struct cmd_set_vf_mac_addr_result,
12249                  addr, "addr");
12250 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12251         TOKEN_NUM_INITIALIZER
12252                 (struct cmd_set_vf_mac_addr_result,
12253                  port_id, UINT8);
12254 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12255         TOKEN_NUM_INITIALIZER
12256                 (struct cmd_set_vf_mac_addr_result,
12257                  vf_id, UINT16);
12258 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12259         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12260                  mac_addr);
12261
12262 static void
12263 cmd_set_vf_mac_addr_parsed(
12264         void *parsed_result,
12265         __attribute__((unused)) struct cmdline *cl,
12266         __attribute__((unused)) void *data)
12267 {
12268         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12269         int ret = -ENOTSUP;
12270
12271         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12272                 return;
12273
12274 #ifdef RTE_LIBRTE_IXGBE_PMD
12275         if (ret == -ENOTSUP)
12276                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12277                                 &res->mac_addr);
12278 #endif
12279 #ifdef RTE_LIBRTE_I40E_PMD
12280         if (ret == -ENOTSUP)
12281                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12282                                 &res->mac_addr);
12283 #endif
12284 #ifdef RTE_LIBRTE_BNXT_PMD
12285         if (ret == -ENOTSUP)
12286                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12287                                 &res->mac_addr);
12288 #endif
12289
12290         switch (ret) {
12291         case 0:
12292                 break;
12293         case -EINVAL:
12294                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12295                 break;
12296         case -ENODEV:
12297                 printf("invalid port_id %d\n", res->port_id);
12298                 break;
12299         case -ENOTSUP:
12300                 printf("function not implemented\n");
12301                 break;
12302         default:
12303                 printf("programming error: (%s)\n", strerror(-ret));
12304         }
12305 }
12306
12307 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12308         .f = cmd_set_vf_mac_addr_parsed,
12309         .data = NULL,
12310         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12311         .tokens = {
12312                 (void *)&cmd_set_vf_mac_addr_set,
12313                 (void *)&cmd_set_vf_mac_addr_vf,
12314                 (void *)&cmd_set_vf_mac_addr_mac,
12315                 (void *)&cmd_set_vf_mac_addr_addr,
12316                 (void *)&cmd_set_vf_mac_addr_port_id,
12317                 (void *)&cmd_set_vf_mac_addr_vf_id,
12318                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12319                 NULL,
12320         },
12321 };
12322
12323 /* MACsec configuration */
12324
12325 /* Common result structure for MACsec offload enable */
12326 struct cmd_macsec_offload_on_result {
12327         cmdline_fixed_string_t set;
12328         cmdline_fixed_string_t macsec;
12329         cmdline_fixed_string_t offload;
12330         uint8_t port_id;
12331         cmdline_fixed_string_t on;
12332         cmdline_fixed_string_t encrypt;
12333         cmdline_fixed_string_t en_on_off;
12334         cmdline_fixed_string_t replay_protect;
12335         cmdline_fixed_string_t rp_on_off;
12336 };
12337
12338 /* Common CLI fields for MACsec offload disable */
12339 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12340         TOKEN_STRING_INITIALIZER
12341                 (struct cmd_macsec_offload_on_result,
12342                  set, "set");
12343 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12344         TOKEN_STRING_INITIALIZER
12345                 (struct cmd_macsec_offload_on_result,
12346                  macsec, "macsec");
12347 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12348         TOKEN_STRING_INITIALIZER
12349                 (struct cmd_macsec_offload_on_result,
12350                  offload, "offload");
12351 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12352         TOKEN_NUM_INITIALIZER
12353                 (struct cmd_macsec_offload_on_result,
12354                  port_id, UINT8);
12355 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12356         TOKEN_STRING_INITIALIZER
12357                 (struct cmd_macsec_offload_on_result,
12358                  on, "on");
12359 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12360         TOKEN_STRING_INITIALIZER
12361                 (struct cmd_macsec_offload_on_result,
12362                  encrypt, "encrypt");
12363 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12364         TOKEN_STRING_INITIALIZER
12365                 (struct cmd_macsec_offload_on_result,
12366                  en_on_off, "on#off");
12367 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12368         TOKEN_STRING_INITIALIZER
12369                 (struct cmd_macsec_offload_on_result,
12370                  replay_protect, "replay-protect");
12371 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12372         TOKEN_STRING_INITIALIZER
12373                 (struct cmd_macsec_offload_on_result,
12374                  rp_on_off, "on#off");
12375
12376 static void
12377 cmd_set_macsec_offload_on_parsed(
12378         void *parsed_result,
12379         __attribute__((unused)) struct cmdline *cl,
12380         __attribute__((unused)) void *data)
12381 {
12382         struct cmd_macsec_offload_on_result *res = parsed_result;
12383         int ret = -ENOTSUP;
12384         portid_t port_id = res->port_id;
12385         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12386         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12387
12388         if (port_id_is_invalid(port_id, ENABLED_WARN))
12389                 return;
12390
12391         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12392 #ifdef RTE_LIBRTE_IXGBE_PMD
12393         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12394 #endif
12395         RTE_SET_USED(en);
12396         RTE_SET_USED(rp);
12397
12398         switch (ret) {
12399         case 0:
12400                 break;
12401         case -ENODEV:
12402                 printf("invalid port_id %d\n", port_id);
12403                 break;
12404         case -ENOTSUP:
12405                 printf("not supported on port %d\n", port_id);
12406                 break;
12407         default:
12408                 printf("programming error: (%s)\n", strerror(-ret));
12409         }
12410 }
12411
12412 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12413         .f = cmd_set_macsec_offload_on_parsed,
12414         .data = NULL,
12415         .help_str = "set macsec offload <port_id> on "
12416                 "encrypt on|off replay-protect on|off",
12417         .tokens = {
12418                 (void *)&cmd_macsec_offload_on_set,
12419                 (void *)&cmd_macsec_offload_on_macsec,
12420                 (void *)&cmd_macsec_offload_on_offload,
12421                 (void *)&cmd_macsec_offload_on_port_id,
12422                 (void *)&cmd_macsec_offload_on_on,
12423                 (void *)&cmd_macsec_offload_on_encrypt,
12424                 (void *)&cmd_macsec_offload_on_en_on_off,
12425                 (void *)&cmd_macsec_offload_on_replay_protect,
12426                 (void *)&cmd_macsec_offload_on_rp_on_off,
12427                 NULL,
12428         },
12429 };
12430
12431 /* Common result structure for MACsec offload disable */
12432 struct cmd_macsec_offload_off_result {
12433         cmdline_fixed_string_t set;
12434         cmdline_fixed_string_t macsec;
12435         cmdline_fixed_string_t offload;
12436         uint8_t port_id;
12437         cmdline_fixed_string_t off;
12438 };
12439
12440 /* Common CLI fields for MACsec offload disable */
12441 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12442         TOKEN_STRING_INITIALIZER
12443                 (struct cmd_macsec_offload_off_result,
12444                  set, "set");
12445 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12446         TOKEN_STRING_INITIALIZER
12447                 (struct cmd_macsec_offload_off_result,
12448                  macsec, "macsec");
12449 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12450         TOKEN_STRING_INITIALIZER
12451                 (struct cmd_macsec_offload_off_result,
12452                  offload, "offload");
12453 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12454         TOKEN_NUM_INITIALIZER
12455                 (struct cmd_macsec_offload_off_result,
12456                  port_id, UINT8);
12457 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12458         TOKEN_STRING_INITIALIZER
12459                 (struct cmd_macsec_offload_off_result,
12460                  off, "off");
12461
12462 static void
12463 cmd_set_macsec_offload_off_parsed(
12464         void *parsed_result,
12465         __attribute__((unused)) struct cmdline *cl,
12466         __attribute__((unused)) void *data)
12467 {
12468         struct cmd_macsec_offload_off_result *res = parsed_result;
12469         int ret = -ENOTSUP;
12470         portid_t port_id = res->port_id;
12471
12472         if (port_id_is_invalid(port_id, ENABLED_WARN))
12473                 return;
12474
12475         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
12476 #ifdef RTE_LIBRTE_IXGBE_PMD
12477         ret = rte_pmd_ixgbe_macsec_disable(port_id);
12478 #endif
12479
12480         switch (ret) {
12481         case 0:
12482                 break;
12483         case -ENODEV:
12484                 printf("invalid port_id %d\n", port_id);
12485                 break;
12486         case -ENOTSUP:
12487                 printf("not supported on port %d\n", port_id);
12488                 break;
12489         default:
12490                 printf("programming error: (%s)\n", strerror(-ret));
12491         }
12492 }
12493
12494 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12495         .f = cmd_set_macsec_offload_off_parsed,
12496         .data = NULL,
12497         .help_str = "set macsec offload <port_id> off",
12498         .tokens = {
12499                 (void *)&cmd_macsec_offload_off_set,
12500                 (void *)&cmd_macsec_offload_off_macsec,
12501                 (void *)&cmd_macsec_offload_off_offload,
12502                 (void *)&cmd_macsec_offload_off_port_id,
12503                 (void *)&cmd_macsec_offload_off_off,
12504                 NULL,
12505         },
12506 };
12507
12508 /* Common result structure for MACsec secure connection configure */
12509 struct cmd_macsec_sc_result {
12510         cmdline_fixed_string_t set;
12511         cmdline_fixed_string_t macsec;
12512         cmdline_fixed_string_t sc;
12513         cmdline_fixed_string_t tx_rx;
12514         uint8_t port_id;
12515         struct ether_addr mac;
12516         uint16_t pi;
12517 };
12518
12519 /* Common CLI fields for MACsec secure connection configure */
12520 cmdline_parse_token_string_t cmd_macsec_sc_set =
12521         TOKEN_STRING_INITIALIZER
12522                 (struct cmd_macsec_sc_result,
12523                  set, "set");
12524 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12525         TOKEN_STRING_INITIALIZER
12526                 (struct cmd_macsec_sc_result,
12527                  macsec, "macsec");
12528 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12529         TOKEN_STRING_INITIALIZER
12530                 (struct cmd_macsec_sc_result,
12531                  sc, "sc");
12532 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12533         TOKEN_STRING_INITIALIZER
12534                 (struct cmd_macsec_sc_result,
12535                  tx_rx, "tx#rx");
12536 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12537         TOKEN_NUM_INITIALIZER
12538                 (struct cmd_macsec_sc_result,
12539                  port_id, UINT8);
12540 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12541         TOKEN_ETHERADDR_INITIALIZER
12542                 (struct cmd_macsec_sc_result,
12543                  mac);
12544 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12545         TOKEN_NUM_INITIALIZER
12546                 (struct cmd_macsec_sc_result,
12547                  pi, UINT16);
12548
12549 static void
12550 cmd_set_macsec_sc_parsed(
12551         void *parsed_result,
12552         __attribute__((unused)) struct cmdline *cl,
12553         __attribute__((unused)) void *data)
12554 {
12555         struct cmd_macsec_sc_result *res = parsed_result;
12556         int ret = -ENOTSUP;
12557         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12558
12559 #ifdef RTE_LIBRTE_IXGBE_PMD
12560         ret = is_tx ?
12561                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12562                                 res->mac.addr_bytes) :
12563                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12564                                 res->mac.addr_bytes, res->pi);
12565 #endif
12566         RTE_SET_USED(is_tx);
12567
12568         switch (ret) {
12569         case 0:
12570                 break;
12571         case -ENODEV:
12572                 printf("invalid port_id %d\n", res->port_id);
12573                 break;
12574         case -ENOTSUP:
12575                 printf("not supported on port %d\n", res->port_id);
12576                 break;
12577         default:
12578                 printf("programming error: (%s)\n", strerror(-ret));
12579         }
12580 }
12581
12582 cmdline_parse_inst_t cmd_set_macsec_sc = {
12583         .f = cmd_set_macsec_sc_parsed,
12584         .data = NULL,
12585         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12586         .tokens = {
12587                 (void *)&cmd_macsec_sc_set,
12588                 (void *)&cmd_macsec_sc_macsec,
12589                 (void *)&cmd_macsec_sc_sc,
12590                 (void *)&cmd_macsec_sc_tx_rx,
12591                 (void *)&cmd_macsec_sc_port_id,
12592                 (void *)&cmd_macsec_sc_mac,
12593                 (void *)&cmd_macsec_sc_pi,
12594                 NULL,
12595         },
12596 };
12597
12598 /* Common result structure for MACsec secure connection configure */
12599 struct cmd_macsec_sa_result {
12600         cmdline_fixed_string_t set;
12601         cmdline_fixed_string_t macsec;
12602         cmdline_fixed_string_t sa;
12603         cmdline_fixed_string_t tx_rx;
12604         uint8_t port_id;
12605         uint8_t idx;
12606         uint8_t an;
12607         uint32_t pn;
12608         cmdline_fixed_string_t key;
12609 };
12610
12611 /* Common CLI fields for MACsec secure connection configure */
12612 cmdline_parse_token_string_t cmd_macsec_sa_set =
12613         TOKEN_STRING_INITIALIZER
12614                 (struct cmd_macsec_sa_result,
12615                  set, "set");
12616 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12617         TOKEN_STRING_INITIALIZER
12618                 (struct cmd_macsec_sa_result,
12619                  macsec, "macsec");
12620 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12621         TOKEN_STRING_INITIALIZER
12622                 (struct cmd_macsec_sa_result,
12623                  sa, "sa");
12624 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12625         TOKEN_STRING_INITIALIZER
12626                 (struct cmd_macsec_sa_result,
12627                  tx_rx, "tx#rx");
12628 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12629         TOKEN_NUM_INITIALIZER
12630                 (struct cmd_macsec_sa_result,
12631                  port_id, UINT8);
12632 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12633         TOKEN_NUM_INITIALIZER
12634                 (struct cmd_macsec_sa_result,
12635                  idx, UINT8);
12636 cmdline_parse_token_num_t cmd_macsec_sa_an =
12637         TOKEN_NUM_INITIALIZER
12638                 (struct cmd_macsec_sa_result,
12639                  an, UINT8);
12640 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12641         TOKEN_NUM_INITIALIZER
12642                 (struct cmd_macsec_sa_result,
12643                  pn, UINT32);
12644 cmdline_parse_token_string_t cmd_macsec_sa_key =
12645         TOKEN_STRING_INITIALIZER
12646                 (struct cmd_macsec_sa_result,
12647                  key, NULL);
12648
12649 static void
12650 cmd_set_macsec_sa_parsed(
12651         void *parsed_result,
12652         __attribute__((unused)) struct cmdline *cl,
12653         __attribute__((unused)) void *data)
12654 {
12655         struct cmd_macsec_sa_result *res = parsed_result;
12656         int ret = -ENOTSUP;
12657         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12658         uint8_t key[16] = { 0 };
12659         uint8_t xdgt0;
12660         uint8_t xdgt1;
12661         int key_len;
12662         int i;
12663
12664         key_len = strlen(res->key) / 2;
12665         if (key_len > 16)
12666                 key_len = 16;
12667
12668         for (i = 0; i < key_len; i++) {
12669                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12670                 if (xdgt0 == 0xFF)
12671                         return;
12672                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12673                 if (xdgt1 == 0xFF)
12674                         return;
12675                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12676         }
12677
12678 #ifdef RTE_LIBRTE_IXGBE_PMD
12679         ret = is_tx ?
12680                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12681                         res->idx, res->an, res->pn, key) :
12682                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12683                         res->idx, res->an, res->pn, key);
12684 #endif
12685         RTE_SET_USED(is_tx);
12686         RTE_SET_USED(key);
12687
12688         switch (ret) {
12689         case 0:
12690                 break;
12691         case -EINVAL:
12692                 printf("invalid idx %d or an %d\n", res->idx, res->an);
12693                 break;
12694         case -ENODEV:
12695                 printf("invalid port_id %d\n", res->port_id);
12696                 break;
12697         case -ENOTSUP:
12698                 printf("not supported on port %d\n", res->port_id);
12699                 break;
12700         default:
12701                 printf("programming error: (%s)\n", strerror(-ret));
12702         }
12703 }
12704
12705 cmdline_parse_inst_t cmd_set_macsec_sa = {
12706         .f = cmd_set_macsec_sa_parsed,
12707         .data = NULL,
12708         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12709         .tokens = {
12710                 (void *)&cmd_macsec_sa_set,
12711                 (void *)&cmd_macsec_sa_macsec,
12712                 (void *)&cmd_macsec_sa_sa,
12713                 (void *)&cmd_macsec_sa_tx_rx,
12714                 (void *)&cmd_macsec_sa_port_id,
12715                 (void *)&cmd_macsec_sa_idx,
12716                 (void *)&cmd_macsec_sa_an,
12717                 (void *)&cmd_macsec_sa_pn,
12718                 (void *)&cmd_macsec_sa_key,
12719                 NULL,
12720         },
12721 };
12722
12723 /* VF unicast promiscuous mode configuration */
12724
12725 /* Common result structure for VF unicast promiscuous mode */
12726 struct cmd_vf_promisc_result {
12727         cmdline_fixed_string_t set;
12728         cmdline_fixed_string_t vf;
12729         cmdline_fixed_string_t promisc;
12730         uint8_t port_id;
12731         uint32_t vf_id;
12732         cmdline_fixed_string_t on_off;
12733 };
12734
12735 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12736 cmdline_parse_token_string_t cmd_vf_promisc_set =
12737         TOKEN_STRING_INITIALIZER
12738                 (struct cmd_vf_promisc_result,
12739                  set, "set");
12740 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12741         TOKEN_STRING_INITIALIZER
12742                 (struct cmd_vf_promisc_result,
12743                  vf, "vf");
12744 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12745         TOKEN_STRING_INITIALIZER
12746                 (struct cmd_vf_promisc_result,
12747                  promisc, "promisc");
12748 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12749         TOKEN_NUM_INITIALIZER
12750                 (struct cmd_vf_promisc_result,
12751                  port_id, UINT8);
12752 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12753         TOKEN_NUM_INITIALIZER
12754                 (struct cmd_vf_promisc_result,
12755                  vf_id, UINT32);
12756 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12757         TOKEN_STRING_INITIALIZER
12758                 (struct cmd_vf_promisc_result,
12759                  on_off, "on#off");
12760
12761 static void
12762 cmd_set_vf_promisc_parsed(
12763         void *parsed_result,
12764         __attribute__((unused)) struct cmdline *cl,
12765         __attribute__((unused)) void *data)
12766 {
12767         struct cmd_vf_promisc_result *res = parsed_result;
12768         int ret = -ENOTSUP;
12769
12770         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12771
12772         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12773                 return;
12774
12775 #ifdef RTE_LIBRTE_I40E_PMD
12776         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12777                                                   res->vf_id, is_on);
12778 #endif
12779
12780         switch (ret) {
12781         case 0:
12782                 break;
12783         case -EINVAL:
12784                 printf("invalid vf_id %d\n", res->vf_id);
12785                 break;
12786         case -ENODEV:
12787                 printf("invalid port_id %d\n", res->port_id);
12788                 break;
12789         case -ENOTSUP:
12790                 printf("function not implemented\n");
12791                 break;
12792         default:
12793                 printf("programming error: (%s)\n", strerror(-ret));
12794         }
12795 }
12796
12797 cmdline_parse_inst_t cmd_set_vf_promisc = {
12798         .f = cmd_set_vf_promisc_parsed,
12799         .data = NULL,
12800         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12801                 "Set unicast promiscuous mode for a VF from the PF",
12802         .tokens = {
12803                 (void *)&cmd_vf_promisc_set,
12804                 (void *)&cmd_vf_promisc_vf,
12805                 (void *)&cmd_vf_promisc_promisc,
12806                 (void *)&cmd_vf_promisc_port_id,
12807                 (void *)&cmd_vf_promisc_vf_id,
12808                 (void *)&cmd_vf_promisc_on_off,
12809                 NULL,
12810         },
12811 };
12812
12813 /* VF multicast promiscuous mode configuration */
12814
12815 /* Common result structure for VF multicast promiscuous mode */
12816 struct cmd_vf_allmulti_result {
12817         cmdline_fixed_string_t set;
12818         cmdline_fixed_string_t vf;
12819         cmdline_fixed_string_t allmulti;
12820         uint8_t port_id;
12821         uint32_t vf_id;
12822         cmdline_fixed_string_t on_off;
12823 };
12824
12825 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12826 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12827         TOKEN_STRING_INITIALIZER
12828                 (struct cmd_vf_allmulti_result,
12829                  set, "set");
12830 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12831         TOKEN_STRING_INITIALIZER
12832                 (struct cmd_vf_allmulti_result,
12833                  vf, "vf");
12834 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12835         TOKEN_STRING_INITIALIZER
12836                 (struct cmd_vf_allmulti_result,
12837                  allmulti, "allmulti");
12838 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12839         TOKEN_NUM_INITIALIZER
12840                 (struct cmd_vf_allmulti_result,
12841                  port_id, UINT8);
12842 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12843         TOKEN_NUM_INITIALIZER
12844                 (struct cmd_vf_allmulti_result,
12845                  vf_id, UINT32);
12846 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12847         TOKEN_STRING_INITIALIZER
12848                 (struct cmd_vf_allmulti_result,
12849                  on_off, "on#off");
12850
12851 static void
12852 cmd_set_vf_allmulti_parsed(
12853         void *parsed_result,
12854         __attribute__((unused)) struct cmdline *cl,
12855         __attribute__((unused)) void *data)
12856 {
12857         struct cmd_vf_allmulti_result *res = parsed_result;
12858         int ret = -ENOTSUP;
12859
12860         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12861
12862         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12863                 return;
12864
12865 #ifdef RTE_LIBRTE_I40E_PMD
12866         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12867                                                     res->vf_id, is_on);
12868 #endif
12869
12870         switch (ret) {
12871         case 0:
12872                 break;
12873         case -EINVAL:
12874                 printf("invalid vf_id %d\n", res->vf_id);
12875                 break;
12876         case -ENODEV:
12877                 printf("invalid port_id %d\n", res->port_id);
12878                 break;
12879         case -ENOTSUP:
12880                 printf("function not implemented\n");
12881                 break;
12882         default:
12883                 printf("programming error: (%s)\n", strerror(-ret));
12884         }
12885 }
12886
12887 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12888         .f = cmd_set_vf_allmulti_parsed,
12889         .data = NULL,
12890         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12891                 "Set multicast promiscuous mode for a VF from the PF",
12892         .tokens = {
12893                 (void *)&cmd_vf_allmulti_set,
12894                 (void *)&cmd_vf_allmulti_vf,
12895                 (void *)&cmd_vf_allmulti_allmulti,
12896                 (void *)&cmd_vf_allmulti_port_id,
12897                 (void *)&cmd_vf_allmulti_vf_id,
12898                 (void *)&cmd_vf_allmulti_on_off,
12899                 NULL,
12900         },
12901 };
12902
12903 /* vf broadcast mode configuration */
12904
12905 /* Common result structure for vf broadcast */
12906 struct cmd_set_vf_broadcast_result {
12907         cmdline_fixed_string_t set;
12908         cmdline_fixed_string_t vf;
12909         cmdline_fixed_string_t broadcast;
12910         uint8_t port_id;
12911         uint16_t vf_id;
12912         cmdline_fixed_string_t on_off;
12913 };
12914
12915 /* Common CLI fields for vf broadcast enable disable */
12916 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12917         TOKEN_STRING_INITIALIZER
12918                 (struct cmd_set_vf_broadcast_result,
12919                  set, "set");
12920 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12921         TOKEN_STRING_INITIALIZER
12922                 (struct cmd_set_vf_broadcast_result,
12923                  vf, "vf");
12924 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12925         TOKEN_STRING_INITIALIZER
12926                 (struct cmd_set_vf_broadcast_result,
12927                  broadcast, "broadcast");
12928 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12929         TOKEN_NUM_INITIALIZER
12930                 (struct cmd_set_vf_broadcast_result,
12931                  port_id, UINT8);
12932 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12933         TOKEN_NUM_INITIALIZER
12934                 (struct cmd_set_vf_broadcast_result,
12935                  vf_id, UINT16);
12936 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12937         TOKEN_STRING_INITIALIZER
12938                 (struct cmd_set_vf_broadcast_result,
12939                  on_off, "on#off");
12940
12941 static void
12942 cmd_set_vf_broadcast_parsed(
12943         void *parsed_result,
12944         __attribute__((unused)) struct cmdline *cl,
12945         __attribute__((unused)) void *data)
12946 {
12947         struct cmd_set_vf_broadcast_result *res = parsed_result;
12948         int ret = -ENOTSUP;
12949
12950         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12951
12952         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12953                 return;
12954
12955 #ifdef RTE_LIBRTE_I40E_PMD
12956         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12957                                             res->vf_id, is_on);
12958 #endif
12959
12960         switch (ret) {
12961         case 0:
12962                 break;
12963         case -EINVAL:
12964                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12965                 break;
12966         case -ENODEV:
12967                 printf("invalid port_id %d\n", res->port_id);
12968                 break;
12969         case -ENOTSUP:
12970                 printf("function not implemented\n");
12971                 break;
12972         default:
12973                 printf("programming error: (%s)\n", strerror(-ret));
12974         }
12975 }
12976
12977 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12978         .f = cmd_set_vf_broadcast_parsed,
12979         .data = NULL,
12980         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12981         .tokens = {
12982                 (void *)&cmd_set_vf_broadcast_set,
12983                 (void *)&cmd_set_vf_broadcast_vf,
12984                 (void *)&cmd_set_vf_broadcast_broadcast,
12985                 (void *)&cmd_set_vf_broadcast_port_id,
12986                 (void *)&cmd_set_vf_broadcast_vf_id,
12987                 (void *)&cmd_set_vf_broadcast_on_off,
12988                 NULL,
12989         },
12990 };
12991
12992 /* vf vlan tag configuration */
12993
12994 /* Common result structure for vf vlan tag */
12995 struct cmd_set_vf_vlan_tag_result {
12996         cmdline_fixed_string_t set;
12997         cmdline_fixed_string_t vf;
12998         cmdline_fixed_string_t vlan;
12999         cmdline_fixed_string_t tag;
13000         uint8_t port_id;
13001         uint16_t vf_id;
13002         cmdline_fixed_string_t on_off;
13003 };
13004
13005 /* Common CLI fields for vf vlan tag enable disable */
13006 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13007         TOKEN_STRING_INITIALIZER
13008                 (struct cmd_set_vf_vlan_tag_result,
13009                  set, "set");
13010 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13011         TOKEN_STRING_INITIALIZER
13012                 (struct cmd_set_vf_vlan_tag_result,
13013                  vf, "vf");
13014 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13015         TOKEN_STRING_INITIALIZER
13016                 (struct cmd_set_vf_vlan_tag_result,
13017                  vlan, "vlan");
13018 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13019         TOKEN_STRING_INITIALIZER
13020                 (struct cmd_set_vf_vlan_tag_result,
13021                  tag, "tag");
13022 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13023         TOKEN_NUM_INITIALIZER
13024                 (struct cmd_set_vf_vlan_tag_result,
13025                  port_id, UINT8);
13026 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13027         TOKEN_NUM_INITIALIZER
13028                 (struct cmd_set_vf_vlan_tag_result,
13029                  vf_id, UINT16);
13030 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13031         TOKEN_STRING_INITIALIZER
13032                 (struct cmd_set_vf_vlan_tag_result,
13033                  on_off, "on#off");
13034
13035 static void
13036 cmd_set_vf_vlan_tag_parsed(
13037         void *parsed_result,
13038         __attribute__((unused)) struct cmdline *cl,
13039         __attribute__((unused)) void *data)
13040 {
13041         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13042         int ret = -ENOTSUP;
13043
13044         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13045
13046         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13047                 return;
13048
13049 #ifdef RTE_LIBRTE_I40E_PMD
13050         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13051                                            res->vf_id, is_on);
13052 #endif
13053
13054         switch (ret) {
13055         case 0:
13056                 break;
13057         case -EINVAL:
13058                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13059                 break;
13060         case -ENODEV:
13061                 printf("invalid port_id %d\n", res->port_id);
13062                 break;
13063         case -ENOTSUP:
13064                 printf("function not implemented\n");
13065                 break;
13066         default:
13067                 printf("programming error: (%s)\n", strerror(-ret));
13068         }
13069 }
13070
13071 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13072         .f = cmd_set_vf_vlan_tag_parsed,
13073         .data = NULL,
13074         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13075         .tokens = {
13076                 (void *)&cmd_set_vf_vlan_tag_set,
13077                 (void *)&cmd_set_vf_vlan_tag_vf,
13078                 (void *)&cmd_set_vf_vlan_tag_vlan,
13079                 (void *)&cmd_set_vf_vlan_tag_tag,
13080                 (void *)&cmd_set_vf_vlan_tag_port_id,
13081                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13082                 (void *)&cmd_set_vf_vlan_tag_on_off,
13083                 NULL,
13084         },
13085 };
13086
13087 /* Common definition of VF and TC TX bandwidth configuration */
13088 struct cmd_vf_tc_bw_result {
13089         cmdline_fixed_string_t set;
13090         cmdline_fixed_string_t vf;
13091         cmdline_fixed_string_t tc;
13092         cmdline_fixed_string_t tx;
13093         cmdline_fixed_string_t min_bw;
13094         cmdline_fixed_string_t max_bw;
13095         cmdline_fixed_string_t strict_link_prio;
13096         uint8_t port_id;
13097         uint16_t vf_id;
13098         uint8_t tc_no;
13099         uint32_t bw;
13100         cmdline_fixed_string_t bw_list;
13101         uint8_t tc_map;
13102 };
13103
13104 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13105         TOKEN_STRING_INITIALIZER
13106                 (struct cmd_vf_tc_bw_result,
13107                  set, "set");
13108 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13109         TOKEN_STRING_INITIALIZER
13110                 (struct cmd_vf_tc_bw_result,
13111                  vf, "vf");
13112 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13113         TOKEN_STRING_INITIALIZER
13114                 (struct cmd_vf_tc_bw_result,
13115                  tc, "tc");
13116 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13117         TOKEN_STRING_INITIALIZER
13118                 (struct cmd_vf_tc_bw_result,
13119                  tx, "tx");
13120 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13121         TOKEN_STRING_INITIALIZER
13122                 (struct cmd_vf_tc_bw_result,
13123                  strict_link_prio, "strict-link-priority");
13124 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13125         TOKEN_STRING_INITIALIZER
13126                 (struct cmd_vf_tc_bw_result,
13127                  min_bw, "min-bandwidth");
13128 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13129         TOKEN_STRING_INITIALIZER
13130                 (struct cmd_vf_tc_bw_result,
13131                  max_bw, "max-bandwidth");
13132 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13133         TOKEN_NUM_INITIALIZER
13134                 (struct cmd_vf_tc_bw_result,
13135                  port_id, UINT8);
13136 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13137         TOKEN_NUM_INITIALIZER
13138                 (struct cmd_vf_tc_bw_result,
13139                  vf_id, UINT16);
13140 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13141         TOKEN_NUM_INITIALIZER
13142                 (struct cmd_vf_tc_bw_result,
13143                  tc_no, UINT8);
13144 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13145         TOKEN_NUM_INITIALIZER
13146                 (struct cmd_vf_tc_bw_result,
13147                  bw, UINT32);
13148 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13149         TOKEN_STRING_INITIALIZER
13150                 (struct cmd_vf_tc_bw_result,
13151                  bw_list, NULL);
13152 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13153         TOKEN_NUM_INITIALIZER
13154                 (struct cmd_vf_tc_bw_result,
13155                  tc_map, UINT8);
13156
13157 /* VF max bandwidth setting */
13158 static void
13159 cmd_vf_max_bw_parsed(
13160         void *parsed_result,
13161         __attribute__((unused)) struct cmdline *cl,
13162         __attribute__((unused)) void *data)
13163 {
13164         struct cmd_vf_tc_bw_result *res = parsed_result;
13165         int ret = -ENOTSUP;
13166
13167         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13168                 return;
13169
13170 #ifdef RTE_LIBRTE_I40E_PMD
13171         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13172                                          res->vf_id, res->bw);
13173 #endif
13174
13175         switch (ret) {
13176         case 0:
13177                 break;
13178         case -EINVAL:
13179                 printf("invalid vf_id %d or bandwidth %d\n",
13180                        res->vf_id, res->bw);
13181                 break;
13182         case -ENODEV:
13183                 printf("invalid port_id %d\n", res->port_id);
13184                 break;
13185         case -ENOTSUP:
13186                 printf("function not implemented\n");
13187                 break;
13188         default:
13189                 printf("programming error: (%s)\n", strerror(-ret));
13190         }
13191 }
13192
13193 cmdline_parse_inst_t cmd_vf_max_bw = {
13194         .f = cmd_vf_max_bw_parsed,
13195         .data = NULL,
13196         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13197         .tokens = {
13198                 (void *)&cmd_vf_tc_bw_set,
13199                 (void *)&cmd_vf_tc_bw_vf,
13200                 (void *)&cmd_vf_tc_bw_tx,
13201                 (void *)&cmd_vf_tc_bw_max_bw,
13202                 (void *)&cmd_vf_tc_bw_port_id,
13203                 (void *)&cmd_vf_tc_bw_vf_id,
13204                 (void *)&cmd_vf_tc_bw_bw,
13205                 NULL,
13206         },
13207 };
13208
13209 static int
13210 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13211                            uint8_t *tc_num,
13212                            char *str)
13213 {
13214         uint32_t size;
13215         const char *p, *p0 = str;
13216         char s[256];
13217         char *end;
13218         char *str_fld[16];
13219         uint16_t i;
13220         int ret;
13221
13222         p = strchr(p0, '(');
13223         if (p == NULL) {
13224                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13225                 return -1;
13226         }
13227         p++;
13228         p0 = strchr(p, ')');
13229         if (p0 == NULL) {
13230                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13231                 return -1;
13232         }
13233         size = p0 - p;
13234         if (size >= sizeof(s)) {
13235                 printf("The string size exceeds the internal buffer size\n");
13236                 return -1;
13237         }
13238         snprintf(s, sizeof(s), "%.*s", size, p);
13239         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13240         if (ret <= 0) {
13241                 printf("Failed to get the bandwidth list. ");
13242                 return -1;
13243         }
13244         *tc_num = ret;
13245         for (i = 0; i < ret; i++)
13246                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13247
13248         return 0;
13249 }
13250
13251 /* TC min bandwidth setting */
13252 static void
13253 cmd_vf_tc_min_bw_parsed(
13254         void *parsed_result,
13255         __attribute__((unused)) struct cmdline *cl,
13256         __attribute__((unused)) void *data)
13257 {
13258         struct cmd_vf_tc_bw_result *res = parsed_result;
13259         uint8_t tc_num;
13260         uint8_t bw[16];
13261         int ret = -ENOTSUP;
13262
13263         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13264                 return;
13265
13266         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13267         if (ret)
13268                 return;
13269
13270 #ifdef RTE_LIBRTE_I40E_PMD
13271         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13272                                               tc_num, bw);
13273 #endif
13274
13275         switch (ret) {
13276         case 0:
13277                 break;
13278         case -EINVAL:
13279                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13280                 break;
13281         case -ENODEV:
13282                 printf("invalid port_id %d\n", res->port_id);
13283                 break;
13284         case -ENOTSUP:
13285                 printf("function not implemented\n");
13286                 break;
13287         default:
13288                 printf("programming error: (%s)\n", strerror(-ret));
13289         }
13290 }
13291
13292 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13293         .f = cmd_vf_tc_min_bw_parsed,
13294         .data = NULL,
13295         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13296                     " <bw1, bw2, ...>",
13297         .tokens = {
13298                 (void *)&cmd_vf_tc_bw_set,
13299                 (void *)&cmd_vf_tc_bw_vf,
13300                 (void *)&cmd_vf_tc_bw_tc,
13301                 (void *)&cmd_vf_tc_bw_tx,
13302                 (void *)&cmd_vf_tc_bw_min_bw,
13303                 (void *)&cmd_vf_tc_bw_port_id,
13304                 (void *)&cmd_vf_tc_bw_vf_id,
13305                 (void *)&cmd_vf_tc_bw_bw_list,
13306                 NULL,
13307         },
13308 };
13309
13310 static void
13311 cmd_tc_min_bw_parsed(
13312         void *parsed_result,
13313         __attribute__((unused)) struct cmdline *cl,
13314         __attribute__((unused)) void *data)
13315 {
13316         struct cmd_vf_tc_bw_result *res = parsed_result;
13317         struct rte_port *port;
13318         uint8_t tc_num;
13319         uint8_t bw[16];
13320         int ret = -ENOTSUP;
13321
13322         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13323                 return;
13324
13325         port = &ports[res->port_id];
13326         /** Check if the port is not started **/
13327         if (port->port_status != RTE_PORT_STOPPED) {
13328                 printf("Please stop port %d first\n", res->port_id);
13329                 return;
13330         }
13331
13332         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13333         if (ret)
13334                 return;
13335
13336 #ifdef RTE_LIBRTE_IXGBE_PMD
13337         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13338 #endif
13339
13340         switch (ret) {
13341         case 0:
13342                 break;
13343         case -EINVAL:
13344                 printf("invalid bandwidth\n");
13345                 break;
13346         case -ENODEV:
13347                 printf("invalid port_id %d\n", res->port_id);
13348                 break;
13349         case -ENOTSUP:
13350                 printf("function not implemented\n");
13351                 break;
13352         default:
13353                 printf("programming error: (%s)\n", strerror(-ret));
13354         }
13355 }
13356
13357 cmdline_parse_inst_t cmd_tc_min_bw = {
13358         .f = cmd_tc_min_bw_parsed,
13359         .data = NULL,
13360         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13361         .tokens = {
13362                 (void *)&cmd_vf_tc_bw_set,
13363                 (void *)&cmd_vf_tc_bw_tc,
13364                 (void *)&cmd_vf_tc_bw_tx,
13365                 (void *)&cmd_vf_tc_bw_min_bw,
13366                 (void *)&cmd_vf_tc_bw_port_id,
13367                 (void *)&cmd_vf_tc_bw_bw_list,
13368                 NULL,
13369         },
13370 };
13371
13372 /* TC max bandwidth setting */
13373 static void
13374 cmd_vf_tc_max_bw_parsed(
13375         void *parsed_result,
13376         __attribute__((unused)) struct cmdline *cl,
13377         __attribute__((unused)) void *data)
13378 {
13379         struct cmd_vf_tc_bw_result *res = parsed_result;
13380         int ret = -ENOTSUP;
13381
13382         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13383                 return;
13384
13385 #ifdef RTE_LIBRTE_I40E_PMD
13386         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13387                                             res->tc_no, res->bw);
13388 #endif
13389
13390         switch (ret) {
13391         case 0:
13392                 break;
13393         case -EINVAL:
13394                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13395                        res->vf_id, res->tc_no, res->bw);
13396                 break;
13397         case -ENODEV:
13398                 printf("invalid port_id %d\n", res->port_id);
13399                 break;
13400         case -ENOTSUP:
13401                 printf("function not implemented\n");
13402                 break;
13403         default:
13404                 printf("programming error: (%s)\n", strerror(-ret));
13405         }
13406 }
13407
13408 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13409         .f = cmd_vf_tc_max_bw_parsed,
13410         .data = NULL,
13411         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13412                     " <bandwidth>",
13413         .tokens = {
13414                 (void *)&cmd_vf_tc_bw_set,
13415                 (void *)&cmd_vf_tc_bw_vf,
13416                 (void *)&cmd_vf_tc_bw_tc,
13417                 (void *)&cmd_vf_tc_bw_tx,
13418                 (void *)&cmd_vf_tc_bw_max_bw,
13419                 (void *)&cmd_vf_tc_bw_port_id,
13420                 (void *)&cmd_vf_tc_bw_vf_id,
13421                 (void *)&cmd_vf_tc_bw_tc_no,
13422                 (void *)&cmd_vf_tc_bw_bw,
13423                 NULL,
13424         },
13425 };
13426
13427 /* Strict link priority scheduling mode setting */
13428 static void
13429 cmd_strict_link_prio_parsed(
13430         void *parsed_result,
13431         __attribute__((unused)) struct cmdline *cl,
13432         __attribute__((unused)) void *data)
13433 {
13434         struct cmd_vf_tc_bw_result *res = parsed_result;
13435         int ret = -ENOTSUP;
13436
13437         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13438                 return;
13439
13440 #ifdef RTE_LIBRTE_I40E_PMD
13441         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13442 #endif
13443
13444         switch (ret) {
13445         case 0:
13446                 break;
13447         case -EINVAL:
13448                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13449                 break;
13450         case -ENODEV:
13451                 printf("invalid port_id %d\n", res->port_id);
13452                 break;
13453         case -ENOTSUP:
13454                 printf("function not implemented\n");
13455                 break;
13456         default:
13457                 printf("programming error: (%s)\n", strerror(-ret));
13458         }
13459 }
13460
13461 cmdline_parse_inst_t cmd_strict_link_prio = {
13462         .f = cmd_strict_link_prio_parsed,
13463         .data = NULL,
13464         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13465         .tokens = {
13466                 (void *)&cmd_vf_tc_bw_set,
13467                 (void *)&cmd_vf_tc_bw_tx,
13468                 (void *)&cmd_vf_tc_bw_strict_link_prio,
13469                 (void *)&cmd_vf_tc_bw_port_id,
13470                 (void *)&cmd_vf_tc_bw_tc_map,
13471                 NULL,
13472         },
13473 };
13474
13475 /* Load dynamic device personalization*/
13476 struct cmd_ddp_add_result {
13477         cmdline_fixed_string_t ddp;
13478         cmdline_fixed_string_t add;
13479         uint8_t port_id;
13480         char filepath[];
13481 };
13482
13483 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13484         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13485 cmdline_parse_token_string_t cmd_ddp_add_add =
13486         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13487 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13488         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8);
13489 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13490         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13491
13492 static void
13493 cmd_ddp_add_parsed(
13494         void *parsed_result,
13495         __attribute__((unused)) struct cmdline *cl,
13496         __attribute__((unused)) void *data)
13497 {
13498         struct cmd_ddp_add_result *res = parsed_result;
13499         uint8_t *buff;
13500         uint32_t size;
13501         char *filepath;
13502         char *file_fld[2];
13503         int file_num;
13504         int ret = -ENOTSUP;
13505
13506         if (res->port_id > nb_ports) {
13507                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13508                 return;
13509         }
13510
13511         if (!all_ports_stopped()) {
13512                 printf("Please stop all ports first\n");
13513                 return;
13514         }
13515
13516         filepath = strdup(res->filepath);
13517         if (filepath == NULL) {
13518                 printf("Failed to allocate memory\n");
13519                 return;
13520         }
13521         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13522
13523         buff = open_ddp_package_file(file_fld[0], &size);
13524         if (!buff) {
13525                 free((void *)filepath);
13526                 return;
13527         }
13528
13529 #ifdef RTE_LIBRTE_I40E_PMD
13530         if (ret == -ENOTSUP)
13531                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13532                                                buff, size,
13533                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
13534 #endif
13535
13536         if (ret == -EEXIST)
13537                 printf("Profile has already existed.\n");
13538         else if (ret < 0)
13539                 printf("Failed to load profile.\n");
13540         else if (file_num == 2)
13541                 save_ddp_package_file(file_fld[1], buff, size);
13542
13543         close_ddp_package_file(buff);
13544         free((void *)filepath);
13545 }
13546
13547 cmdline_parse_inst_t cmd_ddp_add = {
13548         .f = cmd_ddp_add_parsed,
13549         .data = NULL,
13550         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
13551         .tokens = {
13552                 (void *)&cmd_ddp_add_ddp,
13553                 (void *)&cmd_ddp_add_add,
13554                 (void *)&cmd_ddp_add_port_id,
13555                 (void *)&cmd_ddp_add_filepath,
13556                 NULL,
13557         },
13558 };
13559
13560 /* Delete dynamic device personalization*/
13561 struct cmd_ddp_del_result {
13562         cmdline_fixed_string_t ddp;
13563         cmdline_fixed_string_t del;
13564         uint8_t port_id;
13565         char filepath[];
13566 };
13567
13568 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13569         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13570 cmdline_parse_token_string_t cmd_ddp_del_del =
13571         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13572 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13573         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT8);
13574 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13575         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13576
13577 static void
13578 cmd_ddp_del_parsed(
13579         void *parsed_result,
13580         __attribute__((unused)) struct cmdline *cl,
13581         __attribute__((unused)) void *data)
13582 {
13583         struct cmd_ddp_del_result *res = parsed_result;
13584         uint8_t *buff;
13585         uint32_t size;
13586         int ret = -ENOTSUP;
13587
13588         if (res->port_id > nb_ports) {
13589                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13590                 return;
13591         }
13592
13593         if (!all_ports_stopped()) {
13594                 printf("Please stop all ports first\n");
13595                 return;
13596         }
13597
13598         buff = open_ddp_package_file(res->filepath, &size);
13599         if (!buff)
13600                 return;
13601
13602 #ifdef RTE_LIBRTE_I40E_PMD
13603         if (ret == -ENOTSUP)
13604                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13605                                                buff, size,
13606                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
13607 #endif
13608
13609         if (ret == -EACCES)
13610                 printf("Profile does not exist.\n");
13611         else if (ret < 0)
13612                 printf("Failed to delete profile.\n");
13613
13614         close_ddp_package_file(buff);
13615 }
13616
13617 cmdline_parse_inst_t cmd_ddp_del = {
13618         .f = cmd_ddp_del_parsed,
13619         .data = NULL,
13620         .help_str = "ddp del <port_id> <profile_path>",
13621         .tokens = {
13622                 (void *)&cmd_ddp_del_ddp,
13623                 (void *)&cmd_ddp_del_del,
13624                 (void *)&cmd_ddp_del_port_id,
13625                 (void *)&cmd_ddp_del_filepath,
13626                 NULL,
13627         },
13628 };
13629
13630 /* Get dynamic device personalization profile info */
13631 struct cmd_ddp_info_result {
13632         cmdline_fixed_string_t ddp;
13633         cmdline_fixed_string_t get;
13634         cmdline_fixed_string_t info;
13635         char filepath[];
13636 };
13637
13638 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13639         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13640 cmdline_parse_token_string_t cmd_ddp_info_get =
13641         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13642 cmdline_parse_token_string_t cmd_ddp_info_info =
13643         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13644 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13645         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13646
13647 static void
13648 cmd_ddp_info_parsed(
13649         void *parsed_result,
13650         __attribute__((unused)) struct cmdline *cl,
13651         __attribute__((unused)) void *data)
13652 {
13653         struct cmd_ddp_info_result *res = parsed_result;
13654         uint8_t *pkg;
13655         uint32_t pkg_size;
13656         int ret = -ENOTSUP;
13657 #ifdef RTE_LIBRTE_I40E_PMD
13658         uint32_t i, j, n;
13659         uint8_t *buff;
13660         uint32_t buff_size = 0;
13661         struct rte_pmd_i40e_profile_info info;
13662         uint32_t dev_num = 0;
13663         struct rte_pmd_i40e_ddp_device_id *devs;
13664         uint32_t proto_num = 0;
13665         struct rte_pmd_i40e_proto_info *proto;
13666         uint32_t pctype_num = 0;
13667         struct rte_pmd_i40e_ptype_info *pctype;
13668         uint32_t ptype_num = 0;
13669         struct rte_pmd_i40e_ptype_info *ptype;
13670         uint8_t proto_id;
13671
13672 #endif
13673
13674         pkg = open_ddp_package_file(res->filepath, &pkg_size);
13675         if (!pkg)
13676                 return;
13677
13678 #ifdef RTE_LIBRTE_I40E_PMD
13679         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13680                                 (uint8_t *)&info, sizeof(info),
13681                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13682         if (!ret) {
13683                 printf("Global Track id:       0x%x\n", info.track_id);
13684                 printf("Global Version:        %d.%d.%d.%d\n",
13685                         info.version.major,
13686                         info.version.minor,
13687                         info.version.update,
13688                         info.version.draft);
13689                 printf("Global Package name:   %s\n\n", info.name);
13690         }
13691
13692         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13693                                 (uint8_t *)&info, sizeof(info),
13694                                 RTE_PMD_I40E_PKG_INFO_HEADER);
13695         if (!ret) {
13696                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
13697                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
13698                         info.version.major,
13699                         info.version.minor,
13700                         info.version.update,
13701                         info.version.draft);
13702                 printf("i40e Profile name:     %s\n\n", info.name);
13703         }
13704
13705         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13706                                 (uint8_t *)&buff_size, sizeof(buff_size),
13707                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13708         if (!ret && buff_size) {
13709                 buff = (uint8_t *)malloc(buff_size);
13710                 if (buff) {
13711                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13712                                                 buff, buff_size,
13713                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13714                         if (!ret)
13715                                 printf("Package Notes:\n%s\n\n", buff);
13716                         free(buff);
13717                 }
13718         }
13719
13720         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13721                                 (uint8_t *)&dev_num, sizeof(dev_num),
13722                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13723         if (!ret && dev_num) {
13724                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
13725                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
13726                 if (devs) {
13727                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13728                                                 (uint8_t *)devs, buff_size,
13729                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13730                         if (!ret) {
13731                                 printf("List of supported devices:\n");
13732                                 for (i = 0; i < dev_num; i++) {
13733                                         printf("  %04X:%04X %04X:%04X\n",
13734                                                 devs[i].vendor_dev_id >> 16,
13735                                                 devs[i].vendor_dev_id & 0xFFFF,
13736                                                 devs[i].sub_vendor_dev_id >> 16,
13737                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
13738                                 }
13739                                 printf("\n");
13740                         }
13741                         free(devs);
13742                 }
13743         }
13744
13745         /* get information about protocols and packet types */
13746         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13747                 (uint8_t *)&proto_num, sizeof(proto_num),
13748                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
13749         if (ret || !proto_num)
13750                 goto no_print_return;
13751
13752         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
13753         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
13754         if (!proto)
13755                 goto no_print_return;
13756
13757         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
13758                                         buff_size,
13759                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
13760         if (!ret) {
13761                 printf("List of used protocols:\n");
13762                 for (i = 0; i < proto_num; i++)
13763                         printf("  %2u: %s\n", proto[i].proto_id,
13764                                proto[i].name);
13765                 printf("\n");
13766         }
13767         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13768                 (uint8_t *)&pctype_num, sizeof(pctype_num),
13769                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
13770         if (ret || !pctype_num)
13771                 goto no_print_pctypes;
13772
13773         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13774         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13775         if (!pctype)
13776                 goto no_print_pctypes;
13777
13778         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
13779                                         buff_size,
13780                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
13781         if (ret) {
13782                 free(pctype);
13783                 goto no_print_pctypes;
13784         }
13785
13786         printf("List of defined packet classification types:\n");
13787         for (i = 0; i < pctype_num; i++) {
13788                 printf("  %2u:", pctype[i].ptype_id);
13789                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13790                         proto_id = pctype[i].protocols[j];
13791                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13792                                 for (n = 0; n < proto_num; n++) {
13793                                         if (proto[n].proto_id == proto_id) {
13794                                                 printf(" %s", proto[n].name);
13795                                                 break;
13796                                         }
13797                                 }
13798                         }
13799                 }
13800                 printf("\n");
13801         }
13802         printf("\n");
13803         free(pctype);
13804
13805 no_print_pctypes:
13806
13807         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
13808                                         sizeof(ptype_num),
13809                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
13810         if (ret || !ptype_num)
13811                 goto no_print_return;
13812
13813         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13814         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13815         if (!ptype)
13816                 goto no_print_return;
13817
13818         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
13819                                         buff_size,
13820                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
13821         if (ret) {
13822                 free(ptype);
13823                 goto no_print_return;
13824         }
13825         printf("List of defined packet types:\n");
13826         for (i = 0; i < ptype_num; i++) {
13827                 printf("  %2u:", ptype[i].ptype_id);
13828                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13829                         proto_id = ptype[i].protocols[j];
13830                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13831                                 for (n = 0; n < proto_num; n++) {
13832                                         if (proto[n].proto_id == proto_id) {
13833                                                 printf(" %s", proto[n].name);
13834                                                 break;
13835                                         }
13836                                 }
13837                         }
13838                 }
13839                 printf("\n");
13840         }
13841         free(ptype);
13842         printf("\n");
13843
13844         free(proto);
13845         ret = 0;
13846 no_print_return:
13847 #endif
13848         if (ret == -ENOTSUP)
13849                 printf("Function not supported in PMD driver\n");
13850         close_ddp_package_file(pkg);
13851 }
13852
13853 cmdline_parse_inst_t cmd_ddp_get_info = {
13854         .f = cmd_ddp_info_parsed,
13855         .data = NULL,
13856         .help_str = "ddp get info <profile_path>",
13857         .tokens = {
13858                 (void *)&cmd_ddp_info_ddp,
13859                 (void *)&cmd_ddp_info_get,
13860                 (void *)&cmd_ddp_info_info,
13861                 (void *)&cmd_ddp_info_filepath,
13862                 NULL,
13863         },
13864 };
13865
13866 /* Get dynamic device personalization profile info list*/
13867 #define PROFILE_INFO_SIZE 48
13868 #define MAX_PROFILE_NUM 16
13869
13870 struct cmd_ddp_get_list_result {
13871         cmdline_fixed_string_t ddp;
13872         cmdline_fixed_string_t get;
13873         cmdline_fixed_string_t list;
13874         uint8_t port_id;
13875 };
13876
13877 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
13878         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
13879 cmdline_parse_token_string_t cmd_ddp_get_list_get =
13880         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
13881 cmdline_parse_token_string_t cmd_ddp_get_list_list =
13882         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
13883 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
13884         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8);
13885
13886 static void
13887 cmd_ddp_get_list_parsed(
13888         void *parsed_result,
13889         __attribute__((unused)) struct cmdline *cl,
13890         __attribute__((unused)) void *data)
13891 {
13892         struct cmd_ddp_get_list_result *res = parsed_result;
13893 #ifdef RTE_LIBRTE_I40E_PMD
13894         struct rte_pmd_i40e_profile_list *p_list;
13895         struct rte_pmd_i40e_profile_info *p_info;
13896         uint32_t p_num;
13897         uint32_t size;
13898         uint32_t i;
13899 #endif
13900         int ret = -ENOTSUP;
13901
13902         if (res->port_id > nb_ports) {
13903                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13904                 return;
13905         }
13906
13907 #ifdef RTE_LIBRTE_I40E_PMD
13908         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
13909         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
13910         if (!p_list)
13911                 printf("%s: Failed to malloc buffer\n", __func__);
13912
13913         if (ret == -ENOTSUP)
13914                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
13915                                                 (uint8_t *)p_list, size);
13916
13917         if (!ret) {
13918                 p_num = p_list->p_count;
13919                 printf("Profile number is: %d\n\n", p_num);
13920
13921                 for (i = 0; i < p_num; i++) {
13922                         p_info = &p_list->p_info[i];
13923                         printf("Profile %d:\n", i);
13924                         printf("Track id:     0x%x\n", p_info->track_id);
13925                         printf("Version:      %d.%d.%d.%d\n",
13926                                p_info->version.major,
13927                                p_info->version.minor,
13928                                p_info->version.update,
13929                                p_info->version.draft);
13930                         printf("Profile name: %s\n\n", p_info->name);
13931                 }
13932         }
13933
13934         free(p_list);
13935 #endif
13936
13937         if (ret < 0)
13938                 printf("Failed to get ddp list\n");
13939 }
13940
13941 cmdline_parse_inst_t cmd_ddp_get_list = {
13942         .f = cmd_ddp_get_list_parsed,
13943         .data = NULL,
13944         .help_str = "ddp get list <port_id>",
13945         .tokens = {
13946                 (void *)&cmd_ddp_get_list_ddp,
13947                 (void *)&cmd_ddp_get_list_get,
13948                 (void *)&cmd_ddp_get_list_list,
13949                 (void *)&cmd_ddp_get_list_port_id,
13950                 NULL,
13951         },
13952 };
13953
13954 /* show vf stats */
13955
13956 /* Common result structure for show vf stats */
13957 struct cmd_show_vf_stats_result {
13958         cmdline_fixed_string_t show;
13959         cmdline_fixed_string_t vf;
13960         cmdline_fixed_string_t stats;
13961         uint8_t port_id;
13962         uint16_t vf_id;
13963 };
13964
13965 /* Common CLI fields show vf stats*/
13966 cmdline_parse_token_string_t cmd_show_vf_stats_show =
13967         TOKEN_STRING_INITIALIZER
13968                 (struct cmd_show_vf_stats_result,
13969                  show, "show");
13970 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
13971         TOKEN_STRING_INITIALIZER
13972                 (struct cmd_show_vf_stats_result,
13973                  vf, "vf");
13974 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
13975         TOKEN_STRING_INITIALIZER
13976                 (struct cmd_show_vf_stats_result,
13977                  stats, "stats");
13978 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
13979         TOKEN_NUM_INITIALIZER
13980                 (struct cmd_show_vf_stats_result,
13981                  port_id, UINT8);
13982 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
13983         TOKEN_NUM_INITIALIZER
13984                 (struct cmd_show_vf_stats_result,
13985                  vf_id, UINT16);
13986
13987 static void
13988 cmd_show_vf_stats_parsed(
13989         void *parsed_result,
13990         __attribute__((unused)) struct cmdline *cl,
13991         __attribute__((unused)) void *data)
13992 {
13993         struct cmd_show_vf_stats_result *res = parsed_result;
13994         struct rte_eth_stats stats;
13995         int ret = -ENOTSUP;
13996         static const char *nic_stats_border = "########################";
13997
13998         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13999                 return;
14000
14001         memset(&stats, 0, sizeof(stats));
14002
14003 #ifdef RTE_LIBRTE_I40E_PMD
14004         if (ret == -ENOTSUP)
14005                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14006                                                 res->vf_id,
14007                                                 &stats);
14008 #endif
14009 #ifdef RTE_LIBRTE_BNXT_PMD
14010         if (ret == -ENOTSUP)
14011                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14012                                                 res->vf_id,
14013                                                 &stats);
14014 #endif
14015
14016         switch (ret) {
14017         case 0:
14018                 break;
14019         case -EINVAL:
14020                 printf("invalid vf_id %d\n", res->vf_id);
14021                 break;
14022         case -ENODEV:
14023                 printf("invalid port_id %d\n", res->port_id);
14024                 break;
14025         case -ENOTSUP:
14026                 printf("function not implemented\n");
14027                 break;
14028         default:
14029                 printf("programming error: (%s)\n", strerror(-ret));
14030         }
14031
14032         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14033                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14034
14035         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14036                "%-"PRIu64"\n",
14037                stats.ipackets, stats.imissed, stats.ibytes);
14038         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14039         printf("  RX-nombuf:  %-10"PRIu64"\n",
14040                stats.rx_nombuf);
14041         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14042                "%-"PRIu64"\n",
14043                stats.opackets, stats.oerrors, stats.obytes);
14044
14045         printf("  %s############################%s\n",
14046                                nic_stats_border, nic_stats_border);
14047 }
14048
14049 cmdline_parse_inst_t cmd_show_vf_stats = {
14050         .f = cmd_show_vf_stats_parsed,
14051         .data = NULL,
14052         .help_str = "show vf stats <port_id> <vf_id>",
14053         .tokens = {
14054                 (void *)&cmd_show_vf_stats_show,
14055                 (void *)&cmd_show_vf_stats_vf,
14056                 (void *)&cmd_show_vf_stats_stats,
14057                 (void *)&cmd_show_vf_stats_port_id,
14058                 (void *)&cmd_show_vf_stats_vf_id,
14059                 NULL,
14060         },
14061 };
14062
14063 /* clear vf stats */
14064
14065 /* Common result structure for clear vf stats */
14066 struct cmd_clear_vf_stats_result {
14067         cmdline_fixed_string_t clear;
14068         cmdline_fixed_string_t vf;
14069         cmdline_fixed_string_t stats;
14070         uint8_t port_id;
14071         uint16_t vf_id;
14072 };
14073
14074 /* Common CLI fields clear vf stats*/
14075 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14076         TOKEN_STRING_INITIALIZER
14077                 (struct cmd_clear_vf_stats_result,
14078                  clear, "clear");
14079 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14080         TOKEN_STRING_INITIALIZER
14081                 (struct cmd_clear_vf_stats_result,
14082                  vf, "vf");
14083 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14084         TOKEN_STRING_INITIALIZER
14085                 (struct cmd_clear_vf_stats_result,
14086                  stats, "stats");
14087 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14088         TOKEN_NUM_INITIALIZER
14089                 (struct cmd_clear_vf_stats_result,
14090                  port_id, UINT8);
14091 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14092         TOKEN_NUM_INITIALIZER
14093                 (struct cmd_clear_vf_stats_result,
14094                  vf_id, UINT16);
14095
14096 static void
14097 cmd_clear_vf_stats_parsed(
14098         void *parsed_result,
14099         __attribute__((unused)) struct cmdline *cl,
14100         __attribute__((unused)) void *data)
14101 {
14102         struct cmd_clear_vf_stats_result *res = parsed_result;
14103         int ret = -ENOTSUP;
14104
14105         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14106                 return;
14107
14108 #ifdef RTE_LIBRTE_I40E_PMD
14109         if (ret == -ENOTSUP)
14110                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14111                                                   res->vf_id);
14112 #endif
14113 #ifdef RTE_LIBRTE_BNXT_PMD
14114         if (ret == -ENOTSUP)
14115                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14116                                                   res->vf_id);
14117 #endif
14118
14119         switch (ret) {
14120         case 0:
14121                 break;
14122         case -EINVAL:
14123                 printf("invalid vf_id %d\n", res->vf_id);
14124                 break;
14125         case -ENODEV:
14126                 printf("invalid port_id %d\n", res->port_id);
14127                 break;
14128         case -ENOTSUP:
14129                 printf("function not implemented\n");
14130                 break;
14131         default:
14132                 printf("programming error: (%s)\n", strerror(-ret));
14133         }
14134 }
14135
14136 cmdline_parse_inst_t cmd_clear_vf_stats = {
14137         .f = cmd_clear_vf_stats_parsed,
14138         .data = NULL,
14139         .help_str = "clear vf stats <port_id> <vf_id>",
14140         .tokens = {
14141                 (void *)&cmd_clear_vf_stats_clear,
14142                 (void *)&cmd_clear_vf_stats_vf,
14143                 (void *)&cmd_clear_vf_stats_stats,
14144                 (void *)&cmd_clear_vf_stats_port_id,
14145                 (void *)&cmd_clear_vf_stats_vf_id,
14146                 NULL,
14147         },
14148 };
14149
14150 /* port config pctype mapping reset */
14151
14152 /* Common result structure for port config pctype mapping reset */
14153 struct cmd_pctype_mapping_reset_result {
14154         cmdline_fixed_string_t port;
14155         cmdline_fixed_string_t config;
14156         uint8_t port_id;
14157         cmdline_fixed_string_t pctype;
14158         cmdline_fixed_string_t mapping;
14159         cmdline_fixed_string_t reset;
14160 };
14161
14162 /* Common CLI fields for port config pctype mapping reset*/
14163 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14164         TOKEN_STRING_INITIALIZER
14165                 (struct cmd_pctype_mapping_reset_result,
14166                  port, "port");
14167 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14168         TOKEN_STRING_INITIALIZER
14169                 (struct cmd_pctype_mapping_reset_result,
14170                  config, "config");
14171 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14172         TOKEN_NUM_INITIALIZER
14173                 (struct cmd_pctype_mapping_reset_result,
14174                  port_id, UINT8);
14175 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14176         TOKEN_STRING_INITIALIZER
14177                 (struct cmd_pctype_mapping_reset_result,
14178                  pctype, "pctype");
14179 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14180         TOKEN_STRING_INITIALIZER
14181                 (struct cmd_pctype_mapping_reset_result,
14182                  mapping, "mapping");
14183 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14184         TOKEN_STRING_INITIALIZER
14185                 (struct cmd_pctype_mapping_reset_result,
14186                  reset, "reset");
14187
14188 static void
14189 cmd_pctype_mapping_reset_parsed(
14190         void *parsed_result,
14191         __attribute__((unused)) struct cmdline *cl,
14192         __attribute__((unused)) void *data)
14193 {
14194         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14195         int ret = -ENOTSUP;
14196
14197         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14198                 return;
14199
14200 #ifdef RTE_LIBRTE_I40E_PMD
14201         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14202 #endif
14203
14204         switch (ret) {
14205         case 0:
14206                 break;
14207         case -ENODEV:
14208                 printf("invalid port_id %d\n", res->port_id);
14209                 break;
14210         case -ENOTSUP:
14211                 printf("function not implemented\n");
14212                 break;
14213         default:
14214                 printf("programming error: (%s)\n", strerror(-ret));
14215         }
14216 }
14217
14218 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14219         .f = cmd_pctype_mapping_reset_parsed,
14220         .data = NULL,
14221         .help_str = "port config <port_id> pctype mapping reset",
14222         .tokens = {
14223                 (void *)&cmd_pctype_mapping_reset_port,
14224                 (void *)&cmd_pctype_mapping_reset_config,
14225                 (void *)&cmd_pctype_mapping_reset_port_id,
14226                 (void *)&cmd_pctype_mapping_reset_pctype,
14227                 (void *)&cmd_pctype_mapping_reset_mapping,
14228                 (void *)&cmd_pctype_mapping_reset_reset,
14229                 NULL,
14230         },
14231 };
14232
14233 /* show port pctype mapping */
14234
14235 /* Common result structure for show port pctype mapping */
14236 struct cmd_pctype_mapping_get_result {
14237         cmdline_fixed_string_t show;
14238         cmdline_fixed_string_t port;
14239         uint8_t port_id;
14240         cmdline_fixed_string_t pctype;
14241         cmdline_fixed_string_t mapping;
14242 };
14243
14244 /* Common CLI fields for pctype mapping get */
14245 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14246         TOKEN_STRING_INITIALIZER
14247                 (struct cmd_pctype_mapping_get_result,
14248                  show, "show");
14249 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14250         TOKEN_STRING_INITIALIZER
14251                 (struct cmd_pctype_mapping_get_result,
14252                  port, "port");
14253 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14254         TOKEN_NUM_INITIALIZER
14255                 (struct cmd_pctype_mapping_get_result,
14256                  port_id, UINT8);
14257 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14258         TOKEN_STRING_INITIALIZER
14259                 (struct cmd_pctype_mapping_get_result,
14260                  pctype, "pctype");
14261 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14262         TOKEN_STRING_INITIALIZER
14263                 (struct cmd_pctype_mapping_get_result,
14264                  mapping, "mapping");
14265
14266 static void
14267 cmd_pctype_mapping_get_parsed(
14268         void *parsed_result,
14269         __attribute__((unused)) struct cmdline *cl,
14270         __attribute__((unused)) void *data)
14271 {
14272         struct cmd_pctype_mapping_get_result *res = parsed_result;
14273         int ret = -ENOTSUP;
14274 #ifdef RTE_LIBRTE_I40E_PMD
14275         struct rte_pmd_i40e_flow_type_mapping
14276                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14277         int i, j, first_pctype;
14278 #endif
14279
14280         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14281                 return;
14282
14283 #ifdef RTE_LIBRTE_I40E_PMD
14284         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14285 #endif
14286
14287         switch (ret) {
14288         case 0:
14289                 break;
14290         case -ENODEV:
14291                 printf("invalid port_id %d\n", res->port_id);
14292                 return;
14293         case -ENOTSUP:
14294                 printf("function not implemented\n");
14295                 return;
14296         default:
14297                 printf("programming error: (%s)\n", strerror(-ret));
14298                 return;
14299         }
14300
14301 #ifdef RTE_LIBRTE_I40E_PMD
14302         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14303                 if (mapping[i].pctype != 0ULL) {
14304                         first_pctype = 1;
14305
14306                         printf("pctype: ");
14307                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14308                                 if (mapping[i].pctype & (1ULL << j)) {
14309                                         printf(first_pctype ?
14310                                                "%02d" : ",%02d", j);
14311                                         first_pctype = 0;
14312                                 }
14313                         }
14314                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14315                 }
14316         }
14317 #endif
14318 }
14319
14320 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14321         .f = cmd_pctype_mapping_get_parsed,
14322         .data = NULL,
14323         .help_str = "show port <port_id> pctype mapping",
14324         .tokens = {
14325                 (void *)&cmd_pctype_mapping_get_show,
14326                 (void *)&cmd_pctype_mapping_get_port,
14327                 (void *)&cmd_pctype_mapping_get_port_id,
14328                 (void *)&cmd_pctype_mapping_get_pctype,
14329                 (void *)&cmd_pctype_mapping_get_mapping,
14330                 NULL,
14331         },
14332 };
14333
14334 /* port config pctype mapping update */
14335
14336 /* Common result structure for port config pctype mapping update */
14337 struct cmd_pctype_mapping_update_result {
14338         cmdline_fixed_string_t port;
14339         cmdline_fixed_string_t config;
14340         uint8_t port_id;
14341         cmdline_fixed_string_t pctype;
14342         cmdline_fixed_string_t mapping;
14343         cmdline_fixed_string_t update;
14344         cmdline_fixed_string_t pctype_list;
14345         uint16_t flow_type;
14346 };
14347
14348 /* Common CLI fields for pctype mapping update*/
14349 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14350         TOKEN_STRING_INITIALIZER
14351                 (struct cmd_pctype_mapping_update_result,
14352                  port, "port");
14353 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14354         TOKEN_STRING_INITIALIZER
14355                 (struct cmd_pctype_mapping_update_result,
14356                  config, "config");
14357 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14358         TOKEN_NUM_INITIALIZER
14359                 (struct cmd_pctype_mapping_update_result,
14360                  port_id, UINT8);
14361 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14362         TOKEN_STRING_INITIALIZER
14363                 (struct cmd_pctype_mapping_update_result,
14364                  pctype, "pctype");
14365 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14366         TOKEN_STRING_INITIALIZER
14367                 (struct cmd_pctype_mapping_update_result,
14368                  mapping, "mapping");
14369 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14370         TOKEN_STRING_INITIALIZER
14371                 (struct cmd_pctype_mapping_update_result,
14372                  update, "update");
14373 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14374         TOKEN_STRING_INITIALIZER
14375                 (struct cmd_pctype_mapping_update_result,
14376                  pctype_list, NULL);
14377 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14378         TOKEN_NUM_INITIALIZER
14379                 (struct cmd_pctype_mapping_update_result,
14380                  flow_type, UINT16);
14381
14382 static void
14383 cmd_pctype_mapping_update_parsed(
14384         void *parsed_result,
14385         __attribute__((unused)) struct cmdline *cl,
14386         __attribute__((unused)) void *data)
14387 {
14388         struct cmd_pctype_mapping_update_result *res = parsed_result;
14389         int ret = -ENOTSUP;
14390 #ifdef RTE_LIBRTE_I40E_PMD
14391         struct rte_pmd_i40e_flow_type_mapping mapping;
14392         unsigned int i;
14393         unsigned int nb_item;
14394         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14395 #endif
14396
14397         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14398                 return;
14399
14400 #ifdef RTE_LIBRTE_I40E_PMD
14401         nb_item = parse_item_list(res->pctype_list, "pctypes",
14402                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14403         mapping.flow_type = res->flow_type;
14404         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14405                 mapping.pctype |= (1ULL << pctype_list[i]);
14406         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14407                                                 &mapping,
14408                                                 1,
14409                                                 0);
14410 #endif
14411
14412         switch (ret) {
14413         case 0:
14414                 break;
14415         case -EINVAL:
14416                 printf("invalid pctype or flow type\n");
14417                 break;
14418         case -ENODEV:
14419                 printf("invalid port_id %d\n", res->port_id);
14420                 break;
14421         case -ENOTSUP:
14422                 printf("function not implemented\n");
14423                 break;
14424         default:
14425                 printf("programming error: (%s)\n", strerror(-ret));
14426         }
14427 }
14428
14429 cmdline_parse_inst_t cmd_pctype_mapping_update = {
14430         .f = cmd_pctype_mapping_update_parsed,
14431         .data = NULL,
14432         .help_str = "port config <port_id> pctype mapping update"
14433         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
14434         .tokens = {
14435                 (void *)&cmd_pctype_mapping_update_port,
14436                 (void *)&cmd_pctype_mapping_update_config,
14437                 (void *)&cmd_pctype_mapping_update_port_id,
14438                 (void *)&cmd_pctype_mapping_update_pctype,
14439                 (void *)&cmd_pctype_mapping_update_mapping,
14440                 (void *)&cmd_pctype_mapping_update_update,
14441                 (void *)&cmd_pctype_mapping_update_pc_type,
14442                 (void *)&cmd_pctype_mapping_update_flow_type,
14443                 NULL,
14444         },
14445 };
14446
14447 /* ptype mapping get */
14448
14449 /* Common result structure for ptype mapping get */
14450 struct cmd_ptype_mapping_get_result {
14451         cmdline_fixed_string_t ptype;
14452         cmdline_fixed_string_t mapping;
14453         cmdline_fixed_string_t get;
14454         uint8_t port_id;
14455         uint8_t valid_only;
14456 };
14457
14458 /* Common CLI fields for ptype mapping get */
14459 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
14460         TOKEN_STRING_INITIALIZER
14461                 (struct cmd_ptype_mapping_get_result,
14462                  ptype, "ptype");
14463 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
14464         TOKEN_STRING_INITIALIZER
14465                 (struct cmd_ptype_mapping_get_result,
14466                  mapping, "mapping");
14467 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
14468         TOKEN_STRING_INITIALIZER
14469                 (struct cmd_ptype_mapping_get_result,
14470                  get, "get");
14471 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
14472         TOKEN_NUM_INITIALIZER
14473                 (struct cmd_ptype_mapping_get_result,
14474                  port_id, UINT8);
14475 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
14476         TOKEN_NUM_INITIALIZER
14477                 (struct cmd_ptype_mapping_get_result,
14478                  valid_only, UINT8);
14479
14480 static void
14481 cmd_ptype_mapping_get_parsed(
14482         void *parsed_result,
14483         __attribute__((unused)) struct cmdline *cl,
14484         __attribute__((unused)) void *data)
14485 {
14486         struct cmd_ptype_mapping_get_result *res = parsed_result;
14487         int ret = -ENOTSUP;
14488 #ifdef RTE_LIBRTE_I40E_PMD
14489         int max_ptype_num = 256;
14490         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
14491         uint16_t count;
14492         int i;
14493 #endif
14494
14495         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14496                 return;
14497
14498 #ifdef RTE_LIBRTE_I40E_PMD
14499         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
14500                                         mapping,
14501                                         max_ptype_num,
14502                                         &count,
14503                                         res->valid_only);
14504 #endif
14505
14506         switch (ret) {
14507         case 0:
14508                 break;
14509         case -ENODEV:
14510                 printf("invalid port_id %d\n", res->port_id);
14511                 break;
14512         case -ENOTSUP:
14513                 printf("function not implemented\n");
14514                 break;
14515         default:
14516                 printf("programming error: (%s)\n", strerror(-ret));
14517         }
14518
14519 #ifdef RTE_LIBRTE_I40E_PMD
14520         if (!ret) {
14521                 for (i = 0; i < count; i++)
14522                         printf("%3d\t0x%08x\n",
14523                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
14524         }
14525 #endif
14526 }
14527
14528 cmdline_parse_inst_t cmd_ptype_mapping_get = {
14529         .f = cmd_ptype_mapping_get_parsed,
14530         .data = NULL,
14531         .help_str = "ptype mapping get <port_id> <valid_only>",
14532         .tokens = {
14533                 (void *)&cmd_ptype_mapping_get_ptype,
14534                 (void *)&cmd_ptype_mapping_get_mapping,
14535                 (void *)&cmd_ptype_mapping_get_get,
14536                 (void *)&cmd_ptype_mapping_get_port_id,
14537                 (void *)&cmd_ptype_mapping_get_valid_only,
14538                 NULL,
14539         },
14540 };
14541
14542 /* ptype mapping replace */
14543
14544 /* Common result structure for ptype mapping replace */
14545 struct cmd_ptype_mapping_replace_result {
14546         cmdline_fixed_string_t ptype;
14547         cmdline_fixed_string_t mapping;
14548         cmdline_fixed_string_t replace;
14549         uint8_t port_id;
14550         uint32_t target;
14551         uint8_t mask;
14552         uint32_t pkt_type;
14553 };
14554
14555 /* Common CLI fields for ptype mapping replace */
14556 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
14557         TOKEN_STRING_INITIALIZER
14558                 (struct cmd_ptype_mapping_replace_result,
14559                  ptype, "ptype");
14560 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
14561         TOKEN_STRING_INITIALIZER
14562                 (struct cmd_ptype_mapping_replace_result,
14563                  mapping, "mapping");
14564 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
14565         TOKEN_STRING_INITIALIZER
14566                 (struct cmd_ptype_mapping_replace_result,
14567                  replace, "replace");
14568 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
14569         TOKEN_NUM_INITIALIZER
14570                 (struct cmd_ptype_mapping_replace_result,
14571                  port_id, UINT8);
14572 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
14573         TOKEN_NUM_INITIALIZER
14574                 (struct cmd_ptype_mapping_replace_result,
14575                  target, UINT32);
14576 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
14577         TOKEN_NUM_INITIALIZER
14578                 (struct cmd_ptype_mapping_replace_result,
14579                  mask, UINT8);
14580 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
14581         TOKEN_NUM_INITIALIZER
14582                 (struct cmd_ptype_mapping_replace_result,
14583                  pkt_type, UINT32);
14584
14585 static void
14586 cmd_ptype_mapping_replace_parsed(
14587         void *parsed_result,
14588         __attribute__((unused)) struct cmdline *cl,
14589         __attribute__((unused)) void *data)
14590 {
14591         struct cmd_ptype_mapping_replace_result *res = parsed_result;
14592         int ret = -ENOTSUP;
14593
14594         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14595                 return;
14596
14597 #ifdef RTE_LIBRTE_I40E_PMD
14598         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
14599                                         res->target,
14600                                         res->mask,
14601                                         res->pkt_type);
14602 #endif
14603
14604         switch (ret) {
14605         case 0:
14606                 break;
14607         case -EINVAL:
14608                 printf("invalid ptype 0x%8x or 0x%8x\n",
14609                                 res->target, res->pkt_type);
14610                 break;
14611         case -ENODEV:
14612                 printf("invalid port_id %d\n", res->port_id);
14613                 break;
14614         case -ENOTSUP:
14615                 printf("function not implemented\n");
14616                 break;
14617         default:
14618                 printf("programming error: (%s)\n", strerror(-ret));
14619         }
14620 }
14621
14622 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
14623         .f = cmd_ptype_mapping_replace_parsed,
14624         .data = NULL,
14625         .help_str =
14626                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
14627         .tokens = {
14628                 (void *)&cmd_ptype_mapping_replace_ptype,
14629                 (void *)&cmd_ptype_mapping_replace_mapping,
14630                 (void *)&cmd_ptype_mapping_replace_replace,
14631                 (void *)&cmd_ptype_mapping_replace_port_id,
14632                 (void *)&cmd_ptype_mapping_replace_target,
14633                 (void *)&cmd_ptype_mapping_replace_mask,
14634                 (void *)&cmd_ptype_mapping_replace_pkt_type,
14635                 NULL,
14636         },
14637 };
14638
14639 /* ptype mapping reset */
14640
14641 /* Common result structure for ptype mapping reset */
14642 struct cmd_ptype_mapping_reset_result {
14643         cmdline_fixed_string_t ptype;
14644         cmdline_fixed_string_t mapping;
14645         cmdline_fixed_string_t reset;
14646         uint8_t port_id;
14647 };
14648
14649 /* Common CLI fields for ptype mapping reset*/
14650 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
14651         TOKEN_STRING_INITIALIZER
14652                 (struct cmd_ptype_mapping_reset_result,
14653                  ptype, "ptype");
14654 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
14655         TOKEN_STRING_INITIALIZER
14656                 (struct cmd_ptype_mapping_reset_result,
14657                  mapping, "mapping");
14658 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
14659         TOKEN_STRING_INITIALIZER
14660                 (struct cmd_ptype_mapping_reset_result,
14661                  reset, "reset");
14662 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
14663         TOKEN_NUM_INITIALIZER
14664                 (struct cmd_ptype_mapping_reset_result,
14665                  port_id, UINT8);
14666
14667 static void
14668 cmd_ptype_mapping_reset_parsed(
14669         void *parsed_result,
14670         __attribute__((unused)) struct cmdline *cl,
14671         __attribute__((unused)) void *data)
14672 {
14673         struct cmd_ptype_mapping_reset_result *res = parsed_result;
14674         int ret = -ENOTSUP;
14675
14676         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14677                 return;
14678
14679 #ifdef RTE_LIBRTE_I40E_PMD
14680         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
14681 #endif
14682
14683         switch (ret) {
14684         case 0:
14685                 break;
14686         case -ENODEV:
14687                 printf("invalid port_id %d\n", res->port_id);
14688                 break;
14689         case -ENOTSUP:
14690                 printf("function not implemented\n");
14691                 break;
14692         default:
14693                 printf("programming error: (%s)\n", strerror(-ret));
14694         }
14695 }
14696
14697 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
14698         .f = cmd_ptype_mapping_reset_parsed,
14699         .data = NULL,
14700         .help_str = "ptype mapping reset <port_id>",
14701         .tokens = {
14702                 (void *)&cmd_ptype_mapping_reset_ptype,
14703                 (void *)&cmd_ptype_mapping_reset_mapping,
14704                 (void *)&cmd_ptype_mapping_reset_reset,
14705                 (void *)&cmd_ptype_mapping_reset_port_id,
14706                 NULL,
14707         },
14708 };
14709
14710 /* ptype mapping update */
14711
14712 /* Common result structure for ptype mapping update */
14713 struct cmd_ptype_mapping_update_result {
14714         cmdline_fixed_string_t ptype;
14715         cmdline_fixed_string_t mapping;
14716         cmdline_fixed_string_t reset;
14717         uint8_t port_id;
14718         uint8_t hw_ptype;
14719         uint32_t sw_ptype;
14720 };
14721
14722 /* Common CLI fields for ptype mapping update*/
14723 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
14724         TOKEN_STRING_INITIALIZER
14725                 (struct cmd_ptype_mapping_update_result,
14726                  ptype, "ptype");
14727 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
14728         TOKEN_STRING_INITIALIZER
14729                 (struct cmd_ptype_mapping_update_result,
14730                  mapping, "mapping");
14731 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
14732         TOKEN_STRING_INITIALIZER
14733                 (struct cmd_ptype_mapping_update_result,
14734                  reset, "update");
14735 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
14736         TOKEN_NUM_INITIALIZER
14737                 (struct cmd_ptype_mapping_update_result,
14738                  port_id, UINT8);
14739 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
14740         TOKEN_NUM_INITIALIZER
14741                 (struct cmd_ptype_mapping_update_result,
14742                  hw_ptype, UINT8);
14743 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
14744         TOKEN_NUM_INITIALIZER
14745                 (struct cmd_ptype_mapping_update_result,
14746                  sw_ptype, UINT32);
14747
14748 static void
14749 cmd_ptype_mapping_update_parsed(
14750         void *parsed_result,
14751         __attribute__((unused)) struct cmdline *cl,
14752         __attribute__((unused)) void *data)
14753 {
14754         struct cmd_ptype_mapping_update_result *res = parsed_result;
14755         int ret = -ENOTSUP;
14756 #ifdef RTE_LIBRTE_I40E_PMD
14757         struct rte_pmd_i40e_ptype_mapping mapping;
14758 #endif
14759         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14760                 return;
14761
14762 #ifdef RTE_LIBRTE_I40E_PMD
14763         mapping.hw_ptype = res->hw_ptype;
14764         mapping.sw_ptype = res->sw_ptype;
14765         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
14766                                                 &mapping,
14767                                                 1,
14768                                                 0);
14769 #endif
14770
14771         switch (ret) {
14772         case 0:
14773                 break;
14774         case -EINVAL:
14775                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
14776                 break;
14777         case -ENODEV:
14778                 printf("invalid port_id %d\n", res->port_id);
14779                 break;
14780         case -ENOTSUP:
14781                 printf("function not implemented\n");
14782                 break;
14783         default:
14784                 printf("programming error: (%s)\n", strerror(-ret));
14785         }
14786 }
14787
14788 cmdline_parse_inst_t cmd_ptype_mapping_update = {
14789         .f = cmd_ptype_mapping_update_parsed,
14790         .data = NULL,
14791         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
14792         .tokens = {
14793                 (void *)&cmd_ptype_mapping_update_ptype,
14794                 (void *)&cmd_ptype_mapping_update_mapping,
14795                 (void *)&cmd_ptype_mapping_update_update,
14796                 (void *)&cmd_ptype_mapping_update_port_id,
14797                 (void *)&cmd_ptype_mapping_update_hw_ptype,
14798                 (void *)&cmd_ptype_mapping_update_sw_ptype,
14799                 NULL,
14800         },
14801 };
14802
14803 /* Common result structure for file commands */
14804 struct cmd_cmdfile_result {
14805         cmdline_fixed_string_t load;
14806         cmdline_fixed_string_t filename;
14807 };
14808
14809 /* Common CLI fields for file commands */
14810 cmdline_parse_token_string_t cmd_load_cmdfile =
14811         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
14812 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
14813         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
14814
14815 static void
14816 cmd_load_from_file_parsed(
14817         void *parsed_result,
14818         __attribute__((unused)) struct cmdline *cl,
14819         __attribute__((unused)) void *data)
14820 {
14821         struct cmd_cmdfile_result *res = parsed_result;
14822
14823         cmdline_read_from_file(res->filename);
14824 }
14825
14826 cmdline_parse_inst_t cmd_load_from_file = {
14827         .f = cmd_load_from_file_parsed,
14828         .data = NULL,
14829         .help_str = "load <filename>",
14830         .tokens = {
14831                 (void *)&cmd_load_cmdfile,
14832                 (void *)&cmd_load_cmdfile_filename,
14833                 NULL,
14834         },
14835 };
14836
14837 /* ******************************************************************************** */
14838
14839 /* list of instructions */
14840 cmdline_parse_ctx_t main_ctx[] = {
14841         (cmdline_parse_inst_t *)&cmd_help_brief,
14842         (cmdline_parse_inst_t *)&cmd_help_long,
14843         (cmdline_parse_inst_t *)&cmd_quit,
14844         (cmdline_parse_inst_t *)&cmd_load_from_file,
14845         (cmdline_parse_inst_t *)&cmd_showport,
14846         (cmdline_parse_inst_t *)&cmd_showqueue,
14847         (cmdline_parse_inst_t *)&cmd_showportall,
14848         (cmdline_parse_inst_t *)&cmd_showcfg,
14849         (cmdline_parse_inst_t *)&cmd_start,
14850         (cmdline_parse_inst_t *)&cmd_start_tx_first,
14851         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
14852         (cmdline_parse_inst_t *)&cmd_set_link_up,
14853         (cmdline_parse_inst_t *)&cmd_set_link_down,
14854         (cmdline_parse_inst_t *)&cmd_reset,
14855         (cmdline_parse_inst_t *)&cmd_set_numbers,
14856         (cmdline_parse_inst_t *)&cmd_set_txpkts,
14857         (cmdline_parse_inst_t *)&cmd_set_txsplit,
14858         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
14859         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
14860         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
14861         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
14862         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
14863         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
14864         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
14865         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
14866         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
14867         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
14868         (cmdline_parse_inst_t *)&cmd_set_link_check,
14869         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
14870         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
14871         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
14872         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
14873 #ifdef RTE_LIBRTE_PMD_BOND
14874         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
14875         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
14876         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
14877         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
14878         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
14879         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
14880         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
14881         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
14882         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
14883         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
14884         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
14885 #endif
14886         (cmdline_parse_inst_t *)&cmd_vlan_offload,
14887         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
14888         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
14889         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
14890         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
14891         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
14892         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
14893         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
14894         (cmdline_parse_inst_t *)&cmd_csum_set,
14895         (cmdline_parse_inst_t *)&cmd_csum_show,
14896         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
14897         (cmdline_parse_inst_t *)&cmd_tso_set,
14898         (cmdline_parse_inst_t *)&cmd_tso_show,
14899         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
14900         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
14901         (cmdline_parse_inst_t *)&cmd_gro_enable,
14902         (cmdline_parse_inst_t *)&cmd_gro_flush,
14903         (cmdline_parse_inst_t *)&cmd_gro_show,
14904         (cmdline_parse_inst_t *)&cmd_gso_enable,
14905         (cmdline_parse_inst_t *)&cmd_gso_size,
14906         (cmdline_parse_inst_t *)&cmd_gso_show,
14907         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
14908         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
14909         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
14910         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
14911         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
14912         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
14913         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
14914         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
14915         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
14916         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
14917         (cmdline_parse_inst_t *)&cmd_config_dcb,
14918         (cmdline_parse_inst_t *)&cmd_read_reg,
14919         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
14920         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
14921         (cmdline_parse_inst_t *)&cmd_write_reg,
14922         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
14923         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
14924         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
14925         (cmdline_parse_inst_t *)&cmd_stop,
14926         (cmdline_parse_inst_t *)&cmd_mac_addr,
14927         (cmdline_parse_inst_t *)&cmd_set_qmap,
14928         (cmdline_parse_inst_t *)&cmd_operate_port,
14929         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
14930         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
14931         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
14932         (cmdline_parse_inst_t *)&cmd_config_speed_all,
14933         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
14934         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
14935         (cmdline_parse_inst_t *)&cmd_config_mtu,
14936         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
14937         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
14938         (cmdline_parse_inst_t *)&cmd_config_rss,
14939         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
14940         (cmdline_parse_inst_t *)&cmd_config_txqflags,
14941         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
14942         (cmdline_parse_inst_t *)&cmd_showport_reta,
14943         (cmdline_parse_inst_t *)&cmd_config_burst,
14944         (cmdline_parse_inst_t *)&cmd_config_thresh,
14945         (cmdline_parse_inst_t *)&cmd_config_threshold,
14946         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
14947         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
14948         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
14949         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
14950         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
14951         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
14952         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
14953         (cmdline_parse_inst_t *)&cmd_global_config,
14954         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
14955         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
14956         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
14957         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
14958         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
14959         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
14960         (cmdline_parse_inst_t *)&cmd_dump,
14961         (cmdline_parse_inst_t *)&cmd_dump_one,
14962         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
14963         (cmdline_parse_inst_t *)&cmd_syn_filter,
14964         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
14965         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
14966         (cmdline_parse_inst_t *)&cmd_flex_filter,
14967         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
14968         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
14969         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
14970         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
14971         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
14972         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
14973         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
14974         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
14975         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
14976         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
14977         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
14978         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
14979         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
14980         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
14981         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
14982         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
14983         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
14984         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
14985         (cmdline_parse_inst_t *)&cmd_flow,
14986         (cmdline_parse_inst_t *)&cmd_mcast_addr,
14987         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
14988         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
14989         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
14990         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
14991         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
14992         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
14993         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
14994         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
14995         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
14996         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
14997         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
14998         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
14999         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15000         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15001         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15002         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15003         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15004         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15005         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15006         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15007         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15008         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15009         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15010         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15011         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15012         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15013         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15014         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15015         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15016         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15017         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15018         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15019         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15020         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15021         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15022         (cmdline_parse_inst_t *)&cmd_ddp_add,
15023         (cmdline_parse_inst_t *)&cmd_ddp_del,
15024         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15025         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15026         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15027         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15028         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15029         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15030         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15031         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15032
15033         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15034         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15035         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15036         NULL,
15037 };
15038
15039 /* read cmdline commands from file */
15040 void
15041 cmdline_read_from_file(const char *filename)
15042 {
15043         struct cmdline *cl;
15044
15045         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15046         if (cl == NULL) {
15047                 printf("Failed to create file based cmdline context: %s\n",
15048                        filename);
15049                 return;
15050         }
15051
15052         cmdline_interact(cl);
15053         cmdline_quit(cl);
15054
15055         cmdline_free(cl);
15056
15057         printf("Read CLI commands from %s\n", filename);
15058 }
15059
15060 /* prompt function, called from main on MASTER lcore */
15061 void
15062 prompt(void)
15063 {
15064         /* initialize non-constant commands */
15065         cmd_set_fwd_mode_init();
15066         cmd_set_fwd_retry_mode_init();
15067
15068         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15069         if (testpmd_cl == NULL)
15070                 return;
15071         cmdline_interact(testpmd_cl);
15072         cmdline_stdin_exit(testpmd_cl);
15073 }
15074
15075 void
15076 prompt_exit(void)
15077 {
15078         if (testpmd_cl != NULL)
15079                 cmdline_quit(testpmd_cl);
15080 }
15081
15082 static void
15083 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15084 {
15085         if (id == (portid_t)RTE_PORT_ALL) {
15086                 portid_t pid;
15087
15088                 RTE_ETH_FOREACH_DEV(pid) {
15089                         /* check if need_reconfig has been set to 1 */
15090                         if (ports[pid].need_reconfig == 0)
15091                                 ports[pid].need_reconfig = dev;
15092                         /* check if need_reconfig_queues has been set to 1 */
15093                         if (ports[pid].need_reconfig_queues == 0)
15094                                 ports[pid].need_reconfig_queues = queue;
15095                 }
15096         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15097                 /* check if need_reconfig has been set to 1 */
15098                 if (ports[id].need_reconfig == 0)
15099                         ports[id].need_reconfig = dev;
15100                 /* check if need_reconfig_queues has been set to 1 */
15101                 if (ports[id].need_reconfig_queues == 0)
15102                         ports[id].need_reconfig_queues = queue;
15103         }
15104 }