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