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