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