e0d54d48279ee7e78d22a2b43e22f8ae272cb279
[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         RTE_ETH_FOREACH_DEV(pid) {
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         }
4677
4678 }
4679
4680 cmdline_parse_token_string_t cmd_createbonded_device_create =
4681                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4682                                 create, "create");
4683 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
4684                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4685                                 bonded, "bonded");
4686 cmdline_parse_token_string_t cmd_createbonded_device_device =
4687                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4688                                 device, "device");
4689 cmdline_parse_token_num_t cmd_createbonded_device_mode =
4690                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4691                                 mode, UINT8);
4692 cmdline_parse_token_num_t cmd_createbonded_device_socket =
4693                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4694                                 socket, UINT8);
4695
4696 cmdline_parse_inst_t cmd_create_bonded_device = {
4697                 .f = cmd_create_bonded_device_parsed,
4698                 .help_str = "create bonded device <mode> <socket>: "
4699                         "Create a new bonded device with specific bonding mode and socket",
4700                 .data = NULL,
4701                 .tokens = {
4702                                 (void *)&cmd_createbonded_device_create,
4703                                 (void *)&cmd_createbonded_device_bonded,
4704                                 (void *)&cmd_createbonded_device_device,
4705                                 (void *)&cmd_createbonded_device_mode,
4706                                 (void *)&cmd_createbonded_device_socket,
4707                                 NULL
4708                 }
4709 };
4710
4711 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
4712 struct cmd_set_bond_mac_addr_result {
4713         cmdline_fixed_string_t set;
4714         cmdline_fixed_string_t bonding;
4715         cmdline_fixed_string_t mac_addr;
4716         uint8_t port_num;
4717         struct ether_addr address;
4718 };
4719
4720 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
4721                 __attribute__((unused))  struct cmdline *cl,
4722                 __attribute__((unused)) void *data)
4723 {
4724         struct cmd_set_bond_mac_addr_result *res = parsed_result;
4725         int ret;
4726
4727         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
4728                 return;
4729
4730         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
4731
4732         /* check the return value and print it if is < 0 */
4733         if (ret < 0)
4734                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4735 }
4736
4737 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
4738                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
4739 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
4740                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
4741                                 "bonding");
4742 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
4743                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
4744                                 "mac_addr");
4745 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
4746                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
4747 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
4748                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
4749
4750 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
4751                 .f = cmd_set_bond_mac_addr_parsed,
4752                 .data = (void *) 0,
4753                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
4754                 .tokens = {
4755                                 (void *)&cmd_set_bond_mac_addr_set,
4756                                 (void *)&cmd_set_bond_mac_addr_bonding,
4757                                 (void *)&cmd_set_bond_mac_addr_mac,
4758                                 (void *)&cmd_set_bond_mac_addr_portnum,
4759                                 (void *)&cmd_set_bond_mac_addr_addr,
4760                                 NULL
4761                 }
4762 };
4763
4764
4765 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
4766 struct cmd_set_bond_mon_period_result {
4767         cmdline_fixed_string_t set;
4768         cmdline_fixed_string_t bonding;
4769         cmdline_fixed_string_t mon_period;
4770         uint8_t port_num;
4771         uint32_t period_ms;
4772 };
4773
4774 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
4775                 __attribute__((unused))  struct cmdline *cl,
4776                 __attribute__((unused)) void *data)
4777 {
4778         struct cmd_set_bond_mon_period_result *res = parsed_result;
4779         int ret;
4780
4781         if (res->port_num >= nb_ports) {
4782                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
4783                 return;
4784         }
4785
4786         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
4787
4788         /* check the return value and print it if is < 0 */
4789         if (ret < 0)
4790                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4791 }
4792
4793 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
4794                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4795                                 set, "set");
4796 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
4797                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4798                                 bonding, "bonding");
4799 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
4800                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4801                                 mon_period,     "mon_period");
4802 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
4803                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4804                                 port_num, UINT8);
4805 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
4806                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4807                                 period_ms, UINT32);
4808
4809 cmdline_parse_inst_t cmd_set_bond_mon_period = {
4810                 .f = cmd_set_bond_mon_period_parsed,
4811                 .data = (void *) 0,
4812                 .help_str = "set bonding mon_period <port_id> <period_ms>",
4813                 .tokens = {
4814                                 (void *)&cmd_set_bond_mon_period_set,
4815                                 (void *)&cmd_set_bond_mon_period_bonding,
4816                                 (void *)&cmd_set_bond_mon_period_mon_period,
4817                                 (void *)&cmd_set_bond_mon_period_portnum,
4818                                 (void *)&cmd_set_bond_mon_period_period_ms,
4819                                 NULL
4820                 }
4821 };
4822
4823 #endif /* RTE_LIBRTE_PMD_BOND */
4824
4825 /* *** SET FORWARDING MODE *** */
4826 struct cmd_set_fwd_mode_result {
4827         cmdline_fixed_string_t set;
4828         cmdline_fixed_string_t fwd;
4829         cmdline_fixed_string_t mode;
4830 };
4831
4832 static void cmd_set_fwd_mode_parsed(void *parsed_result,
4833                                     __attribute__((unused)) struct cmdline *cl,
4834                                     __attribute__((unused)) void *data)
4835 {
4836         struct cmd_set_fwd_mode_result *res = parsed_result;
4837
4838         retry_enabled = 0;
4839         set_pkt_forwarding_mode(res->mode);
4840 }
4841
4842 cmdline_parse_token_string_t cmd_setfwd_set =
4843         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
4844 cmdline_parse_token_string_t cmd_setfwd_fwd =
4845         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
4846 cmdline_parse_token_string_t cmd_setfwd_mode =
4847         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
4848                 "" /* defined at init */);
4849
4850 cmdline_parse_inst_t cmd_set_fwd_mode = {
4851         .f = cmd_set_fwd_mode_parsed,
4852         .data = NULL,
4853         .help_str = NULL, /* defined at init */
4854         .tokens = {
4855                 (void *)&cmd_setfwd_set,
4856                 (void *)&cmd_setfwd_fwd,
4857                 (void *)&cmd_setfwd_mode,
4858                 NULL,
4859         },
4860 };
4861
4862 static void cmd_set_fwd_mode_init(void)
4863 {
4864         char *modes, *c;
4865         static char token[128];
4866         static char help[256];
4867         cmdline_parse_token_string_t *token_struct;
4868
4869         modes = list_pkt_forwarding_modes();
4870         snprintf(help, sizeof(help), "set fwd %s: "
4871                 "Set packet forwarding mode", modes);
4872         cmd_set_fwd_mode.help_str = help;
4873
4874         /* string token separator is # */
4875         for (c = token; *modes != '\0'; modes++)
4876                 if (*modes == '|')
4877                         *c++ = '#';
4878                 else
4879                         *c++ = *modes;
4880         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
4881         token_struct->string_data.str = token;
4882 }
4883
4884 /* *** SET RETRY FORWARDING MODE *** */
4885 struct cmd_set_fwd_retry_mode_result {
4886         cmdline_fixed_string_t set;
4887         cmdline_fixed_string_t fwd;
4888         cmdline_fixed_string_t mode;
4889         cmdline_fixed_string_t retry;
4890 };
4891
4892 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
4893                             __attribute__((unused)) struct cmdline *cl,
4894                             __attribute__((unused)) void *data)
4895 {
4896         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
4897
4898         retry_enabled = 1;
4899         set_pkt_forwarding_mode(res->mode);
4900 }
4901
4902 cmdline_parse_token_string_t cmd_setfwd_retry_set =
4903         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4904                         set, "set");
4905 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
4906         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4907                         fwd, "fwd");
4908 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
4909         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4910                         mode,
4911                 "" /* defined at init */);
4912 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
4913         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4914                         retry, "retry");
4915
4916 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
4917         .f = cmd_set_fwd_retry_mode_parsed,
4918         .data = NULL,
4919         .help_str = NULL, /* defined at init */
4920         .tokens = {
4921                 (void *)&cmd_setfwd_retry_set,
4922                 (void *)&cmd_setfwd_retry_fwd,
4923                 (void *)&cmd_setfwd_retry_mode,
4924                 (void *)&cmd_setfwd_retry_retry,
4925                 NULL,
4926         },
4927 };
4928
4929 static void cmd_set_fwd_retry_mode_init(void)
4930 {
4931         char *modes, *c;
4932         static char token[128];
4933         static char help[256];
4934         cmdline_parse_token_string_t *token_struct;
4935
4936         modes = list_pkt_forwarding_retry_modes();
4937         snprintf(help, sizeof(help), "set fwd %s retry: "
4938                 "Set packet forwarding mode with retry", modes);
4939         cmd_set_fwd_retry_mode.help_str = help;
4940
4941         /* string token separator is # */
4942         for (c = token; *modes != '\0'; modes++)
4943                 if (*modes == '|')
4944                         *c++ = '#';
4945                 else
4946                         *c++ = *modes;
4947         token_struct = (cmdline_parse_token_string_t *)
4948                 cmd_set_fwd_retry_mode.tokens[2];
4949         token_struct->string_data.str = token;
4950 }
4951
4952 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
4953 struct cmd_set_burst_tx_retry_result {
4954         cmdline_fixed_string_t set;
4955         cmdline_fixed_string_t burst;
4956         cmdline_fixed_string_t tx;
4957         cmdline_fixed_string_t delay;
4958         uint32_t time;
4959         cmdline_fixed_string_t retry;
4960         uint32_t retry_num;
4961 };
4962
4963 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
4964                                         __attribute__((unused)) struct cmdline *cl,
4965                                         __attribute__((unused)) void *data)
4966 {
4967         struct cmd_set_burst_tx_retry_result *res = parsed_result;
4968
4969         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
4970                 && !strcmp(res->tx, "tx")) {
4971                 if (!strcmp(res->delay, "delay"))
4972                         burst_tx_delay_time = res->time;
4973                 if (!strcmp(res->retry, "retry"))
4974                         burst_tx_retry_num = res->retry_num;
4975         }
4976
4977 }
4978
4979 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
4980         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
4981 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
4982         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
4983                                  "burst");
4984 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
4985         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
4986 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
4987         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
4988 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
4989         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
4990 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
4991         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
4992 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
4993         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
4994
4995 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
4996         .f = cmd_set_burst_tx_retry_parsed,
4997         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
4998         .tokens = {
4999                 (void *)&cmd_set_burst_tx_retry_set,
5000                 (void *)&cmd_set_burst_tx_retry_burst,
5001                 (void *)&cmd_set_burst_tx_retry_tx,
5002                 (void *)&cmd_set_burst_tx_retry_delay,
5003                 (void *)&cmd_set_burst_tx_retry_time,
5004                 (void *)&cmd_set_burst_tx_retry_retry,
5005                 (void *)&cmd_set_burst_tx_retry_retry_num,
5006                 NULL,
5007         },
5008 };
5009
5010 /* *** SET PROMISC MODE *** */
5011 struct cmd_set_promisc_mode_result {
5012         cmdline_fixed_string_t set;
5013         cmdline_fixed_string_t promisc;
5014         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5015         uint8_t port_num;                /* valid if "allports" argument == 0 */
5016         cmdline_fixed_string_t mode;
5017 };
5018
5019 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5020                                         __attribute__((unused)) struct cmdline *cl,
5021                                         void *allports)
5022 {
5023         struct cmd_set_promisc_mode_result *res = parsed_result;
5024         int enable;
5025         portid_t i;
5026
5027         if (!strcmp(res->mode, "on"))
5028                 enable = 1;
5029         else
5030                 enable = 0;
5031
5032         /* all ports */
5033         if (allports) {
5034                 RTE_ETH_FOREACH_DEV(i) {
5035                         if (enable)
5036                                 rte_eth_promiscuous_enable(i);
5037                         else
5038                                 rte_eth_promiscuous_disable(i);
5039                 }
5040         }
5041         else {
5042                 if (enable)
5043                         rte_eth_promiscuous_enable(res->port_num);
5044                 else
5045                         rte_eth_promiscuous_disable(res->port_num);
5046         }
5047 }
5048
5049 cmdline_parse_token_string_t cmd_setpromisc_set =
5050         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5051 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5052         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5053                                  "promisc");
5054 cmdline_parse_token_string_t cmd_setpromisc_portall =
5055         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5056                                  "all");
5057 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5058         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5059                               UINT8);
5060 cmdline_parse_token_string_t cmd_setpromisc_mode =
5061         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5062                                  "on#off");
5063
5064 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5065         .f = cmd_set_promisc_mode_parsed,
5066         .data = (void *)1,
5067         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5068         .tokens = {
5069                 (void *)&cmd_setpromisc_set,
5070                 (void *)&cmd_setpromisc_promisc,
5071                 (void *)&cmd_setpromisc_portall,
5072                 (void *)&cmd_setpromisc_mode,
5073                 NULL,
5074         },
5075 };
5076
5077 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5078         .f = cmd_set_promisc_mode_parsed,
5079         .data = (void *)0,
5080         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5081         .tokens = {
5082                 (void *)&cmd_setpromisc_set,
5083                 (void *)&cmd_setpromisc_promisc,
5084                 (void *)&cmd_setpromisc_portnum,
5085                 (void *)&cmd_setpromisc_mode,
5086                 NULL,
5087         },
5088 };
5089
5090 /* *** SET ALLMULTI MODE *** */
5091 struct cmd_set_allmulti_mode_result {
5092         cmdline_fixed_string_t set;
5093         cmdline_fixed_string_t allmulti;
5094         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5095         uint8_t port_num;                /* valid if "allports" argument == 0 */
5096         cmdline_fixed_string_t mode;
5097 };
5098
5099 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5100                                         __attribute__((unused)) struct cmdline *cl,
5101                                         void *allports)
5102 {
5103         struct cmd_set_allmulti_mode_result *res = parsed_result;
5104         int enable;
5105         portid_t i;
5106
5107         if (!strcmp(res->mode, "on"))
5108                 enable = 1;
5109         else
5110                 enable = 0;
5111
5112         /* all ports */
5113         if (allports) {
5114                 RTE_ETH_FOREACH_DEV(i) {
5115                         if (enable)
5116                                 rte_eth_allmulticast_enable(i);
5117                         else
5118                                 rte_eth_allmulticast_disable(i);
5119                 }
5120         }
5121         else {
5122                 if (enable)
5123                         rte_eth_allmulticast_enable(res->port_num);
5124                 else
5125                         rte_eth_allmulticast_disable(res->port_num);
5126         }
5127 }
5128
5129 cmdline_parse_token_string_t cmd_setallmulti_set =
5130         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5131 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5132         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5133                                  "allmulti");
5134 cmdline_parse_token_string_t cmd_setallmulti_portall =
5135         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5136                                  "all");
5137 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5138         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5139                               UINT8);
5140 cmdline_parse_token_string_t cmd_setallmulti_mode =
5141         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5142                                  "on#off");
5143
5144 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5145         .f = cmd_set_allmulti_mode_parsed,
5146         .data = (void *)1,
5147         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5148         .tokens = {
5149                 (void *)&cmd_setallmulti_set,
5150                 (void *)&cmd_setallmulti_allmulti,
5151                 (void *)&cmd_setallmulti_portall,
5152                 (void *)&cmd_setallmulti_mode,
5153                 NULL,
5154         },
5155 };
5156
5157 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5158         .f = cmd_set_allmulti_mode_parsed,
5159         .data = (void *)0,
5160         .help_str = "set allmulti <port_id> on|off: "
5161                 "Set allmulti mode on port_id",
5162         .tokens = {
5163                 (void *)&cmd_setallmulti_set,
5164                 (void *)&cmd_setallmulti_allmulti,
5165                 (void *)&cmd_setallmulti_portnum,
5166                 (void *)&cmd_setallmulti_mode,
5167                 NULL,
5168         },
5169 };
5170
5171 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5172 struct cmd_link_flow_ctrl_set_result {
5173         cmdline_fixed_string_t set;
5174         cmdline_fixed_string_t flow_ctrl;
5175         cmdline_fixed_string_t rx;
5176         cmdline_fixed_string_t rx_lfc_mode;
5177         cmdline_fixed_string_t tx;
5178         cmdline_fixed_string_t tx_lfc_mode;
5179         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5180         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5181         cmdline_fixed_string_t autoneg_str;
5182         cmdline_fixed_string_t autoneg;
5183         cmdline_fixed_string_t hw_str;
5184         uint32_t high_water;
5185         cmdline_fixed_string_t lw_str;
5186         uint32_t low_water;
5187         cmdline_fixed_string_t pt_str;
5188         uint16_t pause_time;
5189         cmdline_fixed_string_t xon_str;
5190         uint16_t send_xon;
5191         uint8_t  port_id;
5192 };
5193
5194 cmdline_parse_token_string_t cmd_lfc_set_set =
5195         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5196                                 set, "set");
5197 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5198         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5199                                 flow_ctrl, "flow_ctrl");
5200 cmdline_parse_token_string_t cmd_lfc_set_rx =
5201         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5202                                 rx, "rx");
5203 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5204         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5205                                 rx_lfc_mode, "on#off");
5206 cmdline_parse_token_string_t cmd_lfc_set_tx =
5207         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5208                                 tx, "tx");
5209 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5210         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5211                                 tx_lfc_mode, "on#off");
5212 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5213         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5214                                 hw_str, "high_water");
5215 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5216         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5217                                 high_water, UINT32);
5218 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5219         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5220                                 lw_str, "low_water");
5221 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5222         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5223                                 low_water, UINT32);
5224 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5225         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5226                                 pt_str, "pause_time");
5227 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5228         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5229                                 pause_time, UINT16);
5230 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5231         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5232                                 xon_str, "send_xon");
5233 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5234         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5235                                 send_xon, UINT16);
5236 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5237         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5238                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5239 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5240         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5241                                 mac_ctrl_frame_fwd_mode, "on#off");
5242 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5243         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5244                                 autoneg_str, "autoneg");
5245 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5246         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5247                                 autoneg, "on#off");
5248 cmdline_parse_token_num_t cmd_lfc_set_portid =
5249         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5250                                 port_id, UINT8);
5251
5252 /* forward declaration */
5253 static void
5254 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5255                               void *data);
5256
5257 cmdline_parse_inst_t cmd_link_flow_control_set = {
5258         .f = cmd_link_flow_ctrl_set_parsed,
5259         .data = NULL,
5260         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5261                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5262                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5263         .tokens = {
5264                 (void *)&cmd_lfc_set_set,
5265                 (void *)&cmd_lfc_set_flow_ctrl,
5266                 (void *)&cmd_lfc_set_rx,
5267                 (void *)&cmd_lfc_set_rx_mode,
5268                 (void *)&cmd_lfc_set_tx,
5269                 (void *)&cmd_lfc_set_tx_mode,
5270                 (void *)&cmd_lfc_set_high_water,
5271                 (void *)&cmd_lfc_set_low_water,
5272                 (void *)&cmd_lfc_set_pause_time,
5273                 (void *)&cmd_lfc_set_send_xon,
5274                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5275                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5276                 (void *)&cmd_lfc_set_autoneg_str,
5277                 (void *)&cmd_lfc_set_autoneg,
5278                 (void *)&cmd_lfc_set_portid,
5279                 NULL,
5280         },
5281 };
5282
5283 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5284         .f = cmd_link_flow_ctrl_set_parsed,
5285         .data = (void *)&cmd_link_flow_control_set_rx,
5286         .help_str = "set flow_ctrl rx on|off <port_id>: "
5287                 "Change rx flow control parameter",
5288         .tokens = {
5289                 (void *)&cmd_lfc_set_set,
5290                 (void *)&cmd_lfc_set_flow_ctrl,
5291                 (void *)&cmd_lfc_set_rx,
5292                 (void *)&cmd_lfc_set_rx_mode,
5293                 (void *)&cmd_lfc_set_portid,
5294                 NULL,
5295         },
5296 };
5297
5298 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5299         .f = cmd_link_flow_ctrl_set_parsed,
5300         .data = (void *)&cmd_link_flow_control_set_tx,
5301         .help_str = "set flow_ctrl tx on|off <port_id>: "
5302                 "Change tx flow control parameter",
5303         .tokens = {
5304                 (void *)&cmd_lfc_set_set,
5305                 (void *)&cmd_lfc_set_flow_ctrl,
5306                 (void *)&cmd_lfc_set_tx,
5307                 (void *)&cmd_lfc_set_tx_mode,
5308                 (void *)&cmd_lfc_set_portid,
5309                 NULL,
5310         },
5311 };
5312
5313 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5314         .f = cmd_link_flow_ctrl_set_parsed,
5315         .data = (void *)&cmd_link_flow_control_set_hw,
5316         .help_str = "set flow_ctrl high_water <value> <port_id>: "
5317                 "Change high water flow control parameter",
5318         .tokens = {
5319                 (void *)&cmd_lfc_set_set,
5320                 (void *)&cmd_lfc_set_flow_ctrl,
5321                 (void *)&cmd_lfc_set_high_water_str,
5322                 (void *)&cmd_lfc_set_high_water,
5323                 (void *)&cmd_lfc_set_portid,
5324                 NULL,
5325         },
5326 };
5327
5328 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5329         .f = cmd_link_flow_ctrl_set_parsed,
5330         .data = (void *)&cmd_link_flow_control_set_lw,
5331         .help_str = "set flow_ctrl low_water <value> <port_id>: "
5332                 "Change low water flow control parameter",
5333         .tokens = {
5334                 (void *)&cmd_lfc_set_set,
5335                 (void *)&cmd_lfc_set_flow_ctrl,
5336                 (void *)&cmd_lfc_set_low_water_str,
5337                 (void *)&cmd_lfc_set_low_water,
5338                 (void *)&cmd_lfc_set_portid,
5339                 NULL,
5340         },
5341 };
5342
5343 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5344         .f = cmd_link_flow_ctrl_set_parsed,
5345         .data = (void *)&cmd_link_flow_control_set_pt,
5346         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
5347                 "Change pause time flow control parameter",
5348         .tokens = {
5349                 (void *)&cmd_lfc_set_set,
5350                 (void *)&cmd_lfc_set_flow_ctrl,
5351                 (void *)&cmd_lfc_set_pause_time_str,
5352                 (void *)&cmd_lfc_set_pause_time,
5353                 (void *)&cmd_lfc_set_portid,
5354                 NULL,
5355         },
5356 };
5357
5358 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5359         .f = cmd_link_flow_ctrl_set_parsed,
5360         .data = (void *)&cmd_link_flow_control_set_xon,
5361         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
5362                 "Change send_xon flow control parameter",
5363         .tokens = {
5364                 (void *)&cmd_lfc_set_set,
5365                 (void *)&cmd_lfc_set_flow_ctrl,
5366                 (void *)&cmd_lfc_set_send_xon_str,
5367                 (void *)&cmd_lfc_set_send_xon,
5368                 (void *)&cmd_lfc_set_portid,
5369                 NULL,
5370         },
5371 };
5372
5373 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5374         .f = cmd_link_flow_ctrl_set_parsed,
5375         .data = (void *)&cmd_link_flow_control_set_macfwd,
5376         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
5377                 "Change mac ctrl fwd flow control parameter",
5378         .tokens = {
5379                 (void *)&cmd_lfc_set_set,
5380                 (void *)&cmd_lfc_set_flow_ctrl,
5381                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5382                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5383                 (void *)&cmd_lfc_set_portid,
5384                 NULL,
5385         },
5386 };
5387
5388 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5389         .f = cmd_link_flow_ctrl_set_parsed,
5390         .data = (void *)&cmd_link_flow_control_set_autoneg,
5391         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
5392                 "Change autoneg flow control parameter",
5393         .tokens = {
5394                 (void *)&cmd_lfc_set_set,
5395                 (void *)&cmd_lfc_set_flow_ctrl,
5396                 (void *)&cmd_lfc_set_autoneg_str,
5397                 (void *)&cmd_lfc_set_autoneg,
5398                 (void *)&cmd_lfc_set_portid,
5399                 NULL,
5400         },
5401 };
5402
5403 static void
5404 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
5405                               __attribute__((unused)) struct cmdline *cl,
5406                               void *data)
5407 {
5408         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
5409         cmdline_parse_inst_t *cmd = data;
5410         struct rte_eth_fc_conf fc_conf;
5411         int rx_fc_en = 0;
5412         int tx_fc_en = 0;
5413         int ret;
5414
5415         /*
5416          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5417          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5418          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5419          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5420          */
5421         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5422                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
5423         };
5424
5425         /* Partial command line, retrieve current configuration */
5426         if (cmd) {
5427                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5428                 if (ret != 0) {
5429                         printf("cannot get current flow ctrl parameters, return"
5430                                "code = %d\n", ret);
5431                         return;
5432                 }
5433
5434                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
5435                     (fc_conf.mode == RTE_FC_FULL))
5436                         rx_fc_en = 1;
5437                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
5438                     (fc_conf.mode == RTE_FC_FULL))
5439                         tx_fc_en = 1;
5440         }
5441
5442         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
5443                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
5444
5445         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
5446                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
5447
5448         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
5449
5450         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
5451                 fc_conf.high_water = res->high_water;
5452
5453         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
5454                 fc_conf.low_water = res->low_water;
5455
5456         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
5457                 fc_conf.pause_time = res->pause_time;
5458
5459         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
5460                 fc_conf.send_xon = res->send_xon;
5461
5462         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
5463                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
5464                         fc_conf.mac_ctrl_frame_fwd = 1;
5465                 else
5466                         fc_conf.mac_ctrl_frame_fwd = 0;
5467         }
5468
5469         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
5470                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
5471
5472         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
5473         if (ret != 0)
5474                 printf("bad flow contrl parameter, return code = %d \n", ret);
5475 }
5476
5477 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
5478 struct cmd_priority_flow_ctrl_set_result {
5479         cmdline_fixed_string_t set;
5480         cmdline_fixed_string_t pfc_ctrl;
5481         cmdline_fixed_string_t rx;
5482         cmdline_fixed_string_t rx_pfc_mode;
5483         cmdline_fixed_string_t tx;
5484         cmdline_fixed_string_t tx_pfc_mode;
5485         uint32_t high_water;
5486         uint32_t low_water;
5487         uint16_t pause_time;
5488         uint8_t  priority;
5489         uint8_t  port_id;
5490 };
5491
5492 static void
5493 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
5494                        __attribute__((unused)) struct cmdline *cl,
5495                        __attribute__((unused)) void *data)
5496 {
5497         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
5498         struct rte_eth_pfc_conf pfc_conf;
5499         int rx_fc_enable, tx_fc_enable;
5500         int ret;
5501
5502         /*
5503          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5504          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5505          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5506          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5507          */
5508         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
5509                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
5510         };
5511
5512         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
5513         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
5514         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
5515         pfc_conf.fc.high_water = res->high_water;
5516         pfc_conf.fc.low_water  = res->low_water;
5517         pfc_conf.fc.pause_time = res->pause_time;
5518         pfc_conf.priority      = res->priority;
5519
5520         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
5521         if (ret != 0)
5522                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
5523 }
5524
5525 cmdline_parse_token_string_t cmd_pfc_set_set =
5526         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5527                                 set, "set");
5528 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
5529         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5530                                 pfc_ctrl, "pfc_ctrl");
5531 cmdline_parse_token_string_t cmd_pfc_set_rx =
5532         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5533                                 rx, "rx");
5534 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
5535         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5536                                 rx_pfc_mode, "on#off");
5537 cmdline_parse_token_string_t cmd_pfc_set_tx =
5538         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5539                                 tx, "tx");
5540 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
5541         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5542                                 tx_pfc_mode, "on#off");
5543 cmdline_parse_token_num_t cmd_pfc_set_high_water =
5544         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5545                                 high_water, UINT32);
5546 cmdline_parse_token_num_t cmd_pfc_set_low_water =
5547         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5548                                 low_water, UINT32);
5549 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
5550         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5551                                 pause_time, UINT16);
5552 cmdline_parse_token_num_t cmd_pfc_set_priority =
5553         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5554                                 priority, UINT8);
5555 cmdline_parse_token_num_t cmd_pfc_set_portid =
5556         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5557                                 port_id, UINT8);
5558
5559 cmdline_parse_inst_t cmd_priority_flow_control_set = {
5560         .f = cmd_priority_flow_ctrl_set_parsed,
5561         .data = NULL,
5562         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
5563                 "<pause_time> <priority> <port_id>: "
5564                 "Configure the Ethernet priority flow control",
5565         .tokens = {
5566                 (void *)&cmd_pfc_set_set,
5567                 (void *)&cmd_pfc_set_flow_ctrl,
5568                 (void *)&cmd_pfc_set_rx,
5569                 (void *)&cmd_pfc_set_rx_mode,
5570                 (void *)&cmd_pfc_set_tx,
5571                 (void *)&cmd_pfc_set_tx_mode,
5572                 (void *)&cmd_pfc_set_high_water,
5573                 (void *)&cmd_pfc_set_low_water,
5574                 (void *)&cmd_pfc_set_pause_time,
5575                 (void *)&cmd_pfc_set_priority,
5576                 (void *)&cmd_pfc_set_portid,
5577                 NULL,
5578         },
5579 };
5580
5581 /* *** RESET CONFIGURATION *** */
5582 struct cmd_reset_result {
5583         cmdline_fixed_string_t reset;
5584         cmdline_fixed_string_t def;
5585 };
5586
5587 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
5588                              struct cmdline *cl,
5589                              __attribute__((unused)) void *data)
5590 {
5591         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
5592         set_def_fwd_config();
5593 }
5594
5595 cmdline_parse_token_string_t cmd_reset_set =
5596         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
5597 cmdline_parse_token_string_t cmd_reset_def =
5598         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
5599                                  "default");
5600
5601 cmdline_parse_inst_t cmd_reset = {
5602         .f = cmd_reset_parsed,
5603         .data = NULL,
5604         .help_str = "set default: Reset default forwarding configuration",
5605         .tokens = {
5606                 (void *)&cmd_reset_set,
5607                 (void *)&cmd_reset_def,
5608                 NULL,
5609         },
5610 };
5611
5612 /* *** START FORWARDING *** */
5613 struct cmd_start_result {
5614         cmdline_fixed_string_t start;
5615 };
5616
5617 cmdline_parse_token_string_t cmd_start_start =
5618         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
5619
5620 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
5621                              __attribute__((unused)) struct cmdline *cl,
5622                              __attribute__((unused)) void *data)
5623 {
5624         start_packet_forwarding(0);
5625 }
5626
5627 cmdline_parse_inst_t cmd_start = {
5628         .f = cmd_start_parsed,
5629         .data = NULL,
5630         .help_str = "start: Start packet forwarding",
5631         .tokens = {
5632                 (void *)&cmd_start_start,
5633                 NULL,
5634         },
5635 };
5636
5637 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
5638 struct cmd_start_tx_first_result {
5639         cmdline_fixed_string_t start;
5640         cmdline_fixed_string_t tx_first;
5641 };
5642
5643 static void
5644 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
5645                           __attribute__((unused)) struct cmdline *cl,
5646                           __attribute__((unused)) void *data)
5647 {
5648         start_packet_forwarding(1);
5649 }
5650
5651 cmdline_parse_token_string_t cmd_start_tx_first_start =
5652         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
5653                                  "start");
5654 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
5655         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
5656                                  tx_first, "tx_first");
5657
5658 cmdline_parse_inst_t cmd_start_tx_first = {
5659         .f = cmd_start_tx_first_parsed,
5660         .data = NULL,
5661         .help_str = "start tx_first: Start packet forwarding, "
5662                 "after sending 1 burst of packets",
5663         .tokens = {
5664                 (void *)&cmd_start_tx_first_start,
5665                 (void *)&cmd_start_tx_first_tx_first,
5666                 NULL,
5667         },
5668 };
5669
5670 /* *** START FORWARDING WITH N TX BURST FIRST *** */
5671 struct cmd_start_tx_first_n_result {
5672         cmdline_fixed_string_t start;
5673         cmdline_fixed_string_t tx_first;
5674         uint32_t tx_num;
5675 };
5676
5677 static void
5678 cmd_start_tx_first_n_parsed(void *parsed_result,
5679                           __attribute__((unused)) struct cmdline *cl,
5680                           __attribute__((unused)) void *data)
5681 {
5682         struct cmd_start_tx_first_n_result *res = parsed_result;
5683
5684         start_packet_forwarding(res->tx_num);
5685 }
5686
5687 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
5688         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
5689                         start, "start");
5690 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
5691         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
5692                         tx_first, "tx_first");
5693 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
5694         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
5695                         tx_num, UINT32);
5696
5697 cmdline_parse_inst_t cmd_start_tx_first_n = {
5698         .f = cmd_start_tx_first_n_parsed,
5699         .data = NULL,
5700         .help_str = "start tx_first <num>: "
5701                 "packet forwarding, after sending <num> bursts of packets",
5702         .tokens = {
5703                 (void *)&cmd_start_tx_first_n_start,
5704                 (void *)&cmd_start_tx_first_n_tx_first,
5705                 (void *)&cmd_start_tx_first_n_tx_num,
5706                 NULL,
5707         },
5708 };
5709
5710 /* *** SET LINK UP *** */
5711 struct cmd_set_link_up_result {
5712         cmdline_fixed_string_t set;
5713         cmdline_fixed_string_t link_up;
5714         cmdline_fixed_string_t port;
5715         uint8_t port_id;
5716 };
5717
5718 cmdline_parse_token_string_t cmd_set_link_up_set =
5719         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
5720 cmdline_parse_token_string_t cmd_set_link_up_link_up =
5721         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
5722                                 "link-up");
5723 cmdline_parse_token_string_t cmd_set_link_up_port =
5724         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
5725 cmdline_parse_token_num_t cmd_set_link_up_port_id =
5726         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
5727
5728 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
5729                              __attribute__((unused)) struct cmdline *cl,
5730                              __attribute__((unused)) void *data)
5731 {
5732         struct cmd_set_link_up_result *res = parsed_result;
5733         dev_set_link_up(res->port_id);
5734 }
5735
5736 cmdline_parse_inst_t cmd_set_link_up = {
5737         .f = cmd_set_link_up_parsed,
5738         .data = NULL,
5739         .help_str = "set link-up port <port id>",
5740         .tokens = {
5741                 (void *)&cmd_set_link_up_set,
5742                 (void *)&cmd_set_link_up_link_up,
5743                 (void *)&cmd_set_link_up_port,
5744                 (void *)&cmd_set_link_up_port_id,
5745                 NULL,
5746         },
5747 };
5748
5749 /* *** SET LINK DOWN *** */
5750 struct cmd_set_link_down_result {
5751         cmdline_fixed_string_t set;
5752         cmdline_fixed_string_t link_down;
5753         cmdline_fixed_string_t port;
5754         uint8_t port_id;
5755 };
5756
5757 cmdline_parse_token_string_t cmd_set_link_down_set =
5758         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
5759 cmdline_parse_token_string_t cmd_set_link_down_link_down =
5760         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
5761                                 "link-down");
5762 cmdline_parse_token_string_t cmd_set_link_down_port =
5763         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
5764 cmdline_parse_token_num_t cmd_set_link_down_port_id =
5765         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
5766
5767 static void cmd_set_link_down_parsed(
5768                                 __attribute__((unused)) void *parsed_result,
5769                                 __attribute__((unused)) struct cmdline *cl,
5770                                 __attribute__((unused)) void *data)
5771 {
5772         struct cmd_set_link_down_result *res = parsed_result;
5773         dev_set_link_down(res->port_id);
5774 }
5775
5776 cmdline_parse_inst_t cmd_set_link_down = {
5777         .f = cmd_set_link_down_parsed,
5778         .data = NULL,
5779         .help_str = "set link-down port <port id>",
5780         .tokens = {
5781                 (void *)&cmd_set_link_down_set,
5782                 (void *)&cmd_set_link_down_link_down,
5783                 (void *)&cmd_set_link_down_port,
5784                 (void *)&cmd_set_link_down_port_id,
5785                 NULL,
5786         },
5787 };
5788
5789 /* *** SHOW CFG *** */
5790 struct cmd_showcfg_result {
5791         cmdline_fixed_string_t show;
5792         cmdline_fixed_string_t cfg;
5793         cmdline_fixed_string_t what;
5794 };
5795
5796 static void cmd_showcfg_parsed(void *parsed_result,
5797                                __attribute__((unused)) struct cmdline *cl,
5798                                __attribute__((unused)) void *data)
5799 {
5800         struct cmd_showcfg_result *res = parsed_result;
5801         if (!strcmp(res->what, "rxtx"))
5802                 rxtx_config_display();
5803         else if (!strcmp(res->what, "cores"))
5804                 fwd_lcores_config_display();
5805         else if (!strcmp(res->what, "fwd"))
5806                 pkt_fwd_config_display(&cur_fwd_config);
5807         else if (!strcmp(res->what, "txpkts"))
5808                 show_tx_pkt_segments();
5809 }
5810
5811 cmdline_parse_token_string_t cmd_showcfg_show =
5812         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
5813 cmdline_parse_token_string_t cmd_showcfg_port =
5814         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
5815 cmdline_parse_token_string_t cmd_showcfg_what =
5816         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
5817                                  "rxtx#cores#fwd#txpkts");
5818
5819 cmdline_parse_inst_t cmd_showcfg = {
5820         .f = cmd_showcfg_parsed,
5821         .data = NULL,
5822         .help_str = "show config rxtx|cores|fwd|txpkts",
5823         .tokens = {
5824                 (void *)&cmd_showcfg_show,
5825                 (void *)&cmd_showcfg_port,
5826                 (void *)&cmd_showcfg_what,
5827                 NULL,
5828         },
5829 };
5830
5831 /* *** SHOW ALL PORT INFO *** */
5832 struct cmd_showportall_result {
5833         cmdline_fixed_string_t show;
5834         cmdline_fixed_string_t port;
5835         cmdline_fixed_string_t what;
5836         cmdline_fixed_string_t all;
5837 };
5838
5839 static void cmd_showportall_parsed(void *parsed_result,
5840                                 __attribute__((unused)) struct cmdline *cl,
5841                                 __attribute__((unused)) void *data)
5842 {
5843         portid_t i;
5844
5845         struct cmd_showportall_result *res = parsed_result;
5846         if (!strcmp(res->show, "clear")) {
5847                 if (!strcmp(res->what, "stats"))
5848                         RTE_ETH_FOREACH_DEV(i)
5849                                 nic_stats_clear(i);
5850                 else if (!strcmp(res->what, "xstats"))
5851                         RTE_ETH_FOREACH_DEV(i)
5852                                 nic_xstats_clear(i);
5853         } else if (!strcmp(res->what, "info"))
5854                 RTE_ETH_FOREACH_DEV(i)
5855                         port_infos_display(i);
5856         else if (!strcmp(res->what, "stats"))
5857                 RTE_ETH_FOREACH_DEV(i)
5858                         nic_stats_display(i);
5859         else if (!strcmp(res->what, "xstats"))
5860                 RTE_ETH_FOREACH_DEV(i)
5861                         nic_xstats_display(i);
5862         else if (!strcmp(res->what, "fdir"))
5863                 RTE_ETH_FOREACH_DEV(i)
5864                         fdir_get_infos(i);
5865         else if (!strcmp(res->what, "stat_qmap"))
5866                 RTE_ETH_FOREACH_DEV(i)
5867                         nic_stats_mapping_display(i);
5868         else if (!strcmp(res->what, "dcb_tc"))
5869                 RTE_ETH_FOREACH_DEV(i)
5870                         port_dcb_info_display(i);
5871         else if (!strcmp(res->what, "cap"))
5872                 RTE_ETH_FOREACH_DEV(i)
5873                         port_offload_cap_display(i);
5874 }
5875
5876 cmdline_parse_token_string_t cmd_showportall_show =
5877         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
5878                                  "show#clear");
5879 cmdline_parse_token_string_t cmd_showportall_port =
5880         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
5881 cmdline_parse_token_string_t cmd_showportall_what =
5882         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
5883                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
5884 cmdline_parse_token_string_t cmd_showportall_all =
5885         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
5886 cmdline_parse_inst_t cmd_showportall = {
5887         .f = cmd_showportall_parsed,
5888         .data = NULL,
5889         .help_str = "show|clear port "
5890                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
5891         .tokens = {
5892                 (void *)&cmd_showportall_show,
5893                 (void *)&cmd_showportall_port,
5894                 (void *)&cmd_showportall_what,
5895                 (void *)&cmd_showportall_all,
5896                 NULL,
5897         },
5898 };
5899
5900 /* *** SHOW PORT INFO *** */
5901 struct cmd_showport_result {
5902         cmdline_fixed_string_t show;
5903         cmdline_fixed_string_t port;
5904         cmdline_fixed_string_t what;
5905         uint8_t portnum;
5906 };
5907
5908 static void cmd_showport_parsed(void *parsed_result,
5909                                 __attribute__((unused)) struct cmdline *cl,
5910                                 __attribute__((unused)) void *data)
5911 {
5912         struct cmd_showport_result *res = parsed_result;
5913         if (!strcmp(res->show, "clear")) {
5914                 if (!strcmp(res->what, "stats"))
5915                         nic_stats_clear(res->portnum);
5916                 else if (!strcmp(res->what, "xstats"))
5917                         nic_xstats_clear(res->portnum);
5918         } else if (!strcmp(res->what, "info"))
5919                 port_infos_display(res->portnum);
5920         else if (!strcmp(res->what, "stats"))
5921                 nic_stats_display(res->portnum);
5922         else if (!strcmp(res->what, "xstats"))
5923                 nic_xstats_display(res->portnum);
5924         else if (!strcmp(res->what, "fdir"))
5925                  fdir_get_infos(res->portnum);
5926         else if (!strcmp(res->what, "stat_qmap"))
5927                 nic_stats_mapping_display(res->portnum);
5928         else if (!strcmp(res->what, "dcb_tc"))
5929                 port_dcb_info_display(res->portnum);
5930         else if (!strcmp(res->what, "cap"))
5931                 port_offload_cap_display(res->portnum);
5932 }
5933
5934 cmdline_parse_token_string_t cmd_showport_show =
5935         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
5936                                  "show#clear");
5937 cmdline_parse_token_string_t cmd_showport_port =
5938         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
5939 cmdline_parse_token_string_t cmd_showport_what =
5940         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
5941                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
5942 cmdline_parse_token_num_t cmd_showport_portnum =
5943         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
5944
5945 cmdline_parse_inst_t cmd_showport = {
5946         .f = cmd_showport_parsed,
5947         .data = NULL,
5948         .help_str = "show|clear port "
5949                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
5950                 "<port_id>",
5951         .tokens = {
5952                 (void *)&cmd_showport_show,
5953                 (void *)&cmd_showport_port,
5954                 (void *)&cmd_showport_what,
5955                 (void *)&cmd_showport_portnum,
5956                 NULL,
5957         },
5958 };
5959
5960 /* *** SHOW QUEUE INFO *** */
5961 struct cmd_showqueue_result {
5962         cmdline_fixed_string_t show;
5963         cmdline_fixed_string_t type;
5964         cmdline_fixed_string_t what;
5965         uint8_t portnum;
5966         uint16_t queuenum;
5967 };
5968
5969 static void
5970 cmd_showqueue_parsed(void *parsed_result,
5971         __attribute__((unused)) struct cmdline *cl,
5972         __attribute__((unused)) void *data)
5973 {
5974         struct cmd_showqueue_result *res = parsed_result;
5975
5976         if (!strcmp(res->type, "rxq"))
5977                 rx_queue_infos_display(res->portnum, res->queuenum);
5978         else if (!strcmp(res->type, "txq"))
5979                 tx_queue_infos_display(res->portnum, res->queuenum);
5980 }
5981
5982 cmdline_parse_token_string_t cmd_showqueue_show =
5983         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
5984 cmdline_parse_token_string_t cmd_showqueue_type =
5985         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
5986 cmdline_parse_token_string_t cmd_showqueue_what =
5987         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
5988 cmdline_parse_token_num_t cmd_showqueue_portnum =
5989         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
5990 cmdline_parse_token_num_t cmd_showqueue_queuenum =
5991         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
5992
5993 cmdline_parse_inst_t cmd_showqueue = {
5994         .f = cmd_showqueue_parsed,
5995         .data = NULL,
5996         .help_str = "show rxq|txq info <port_id> <queue_id>",
5997         .tokens = {
5998                 (void *)&cmd_showqueue_show,
5999                 (void *)&cmd_showqueue_type,
6000                 (void *)&cmd_showqueue_what,
6001                 (void *)&cmd_showqueue_portnum,
6002                 (void *)&cmd_showqueue_queuenum,
6003                 NULL,
6004         },
6005 };
6006
6007 /* *** READ PORT REGISTER *** */
6008 struct cmd_read_reg_result {
6009         cmdline_fixed_string_t read;
6010         cmdline_fixed_string_t reg;
6011         uint8_t port_id;
6012         uint32_t reg_off;
6013 };
6014
6015 static void
6016 cmd_read_reg_parsed(void *parsed_result,
6017                     __attribute__((unused)) struct cmdline *cl,
6018                     __attribute__((unused)) void *data)
6019 {
6020         struct cmd_read_reg_result *res = parsed_result;
6021         port_reg_display(res->port_id, res->reg_off);
6022 }
6023
6024 cmdline_parse_token_string_t cmd_read_reg_read =
6025         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6026 cmdline_parse_token_string_t cmd_read_reg_reg =
6027         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6028 cmdline_parse_token_num_t cmd_read_reg_port_id =
6029         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
6030 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6031         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6032
6033 cmdline_parse_inst_t cmd_read_reg = {
6034         .f = cmd_read_reg_parsed,
6035         .data = NULL,
6036         .help_str = "read reg <port_id> <reg_off>",
6037         .tokens = {
6038                 (void *)&cmd_read_reg_read,
6039                 (void *)&cmd_read_reg_reg,
6040                 (void *)&cmd_read_reg_port_id,
6041                 (void *)&cmd_read_reg_reg_off,
6042                 NULL,
6043         },
6044 };
6045
6046 /* *** READ PORT REGISTER BIT FIELD *** */
6047 struct cmd_read_reg_bit_field_result {
6048         cmdline_fixed_string_t read;
6049         cmdline_fixed_string_t regfield;
6050         uint8_t port_id;
6051         uint32_t reg_off;
6052         uint8_t bit1_pos;
6053         uint8_t bit2_pos;
6054 };
6055
6056 static void
6057 cmd_read_reg_bit_field_parsed(void *parsed_result,
6058                               __attribute__((unused)) struct cmdline *cl,
6059                               __attribute__((unused)) void *data)
6060 {
6061         struct cmd_read_reg_bit_field_result *res = parsed_result;
6062         port_reg_bit_field_display(res->port_id, res->reg_off,
6063                                    res->bit1_pos, res->bit2_pos);
6064 }
6065
6066 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6067         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6068                                  "read");
6069 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6070         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6071                                  regfield, "regfield");
6072 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6073         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6074                               UINT8);
6075 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6076         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6077                               UINT32);
6078 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6079         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6080                               UINT8);
6081 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6082         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6083                               UINT8);
6084
6085 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6086         .f = cmd_read_reg_bit_field_parsed,
6087         .data = NULL,
6088         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6089         "Read register bit field between bit_x and bit_y included",
6090         .tokens = {
6091                 (void *)&cmd_read_reg_bit_field_read,
6092                 (void *)&cmd_read_reg_bit_field_regfield,
6093                 (void *)&cmd_read_reg_bit_field_port_id,
6094                 (void *)&cmd_read_reg_bit_field_reg_off,
6095                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6096                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6097                 NULL,
6098         },
6099 };
6100
6101 /* *** READ PORT REGISTER BIT *** */
6102 struct cmd_read_reg_bit_result {
6103         cmdline_fixed_string_t read;
6104         cmdline_fixed_string_t regbit;
6105         uint8_t port_id;
6106         uint32_t reg_off;
6107         uint8_t bit_pos;
6108 };
6109
6110 static void
6111 cmd_read_reg_bit_parsed(void *parsed_result,
6112                         __attribute__((unused)) struct cmdline *cl,
6113                         __attribute__((unused)) void *data)
6114 {
6115         struct cmd_read_reg_bit_result *res = parsed_result;
6116         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6117 }
6118
6119 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6120         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6121 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6122         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6123                                  regbit, "regbit");
6124 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6125         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
6126 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6127         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6128 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6129         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6130
6131 cmdline_parse_inst_t cmd_read_reg_bit = {
6132         .f = cmd_read_reg_bit_parsed,
6133         .data = NULL,
6134         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6135         .tokens = {
6136                 (void *)&cmd_read_reg_bit_read,
6137                 (void *)&cmd_read_reg_bit_regbit,
6138                 (void *)&cmd_read_reg_bit_port_id,
6139                 (void *)&cmd_read_reg_bit_reg_off,
6140                 (void *)&cmd_read_reg_bit_bit_pos,
6141                 NULL,
6142         },
6143 };
6144
6145 /* *** WRITE PORT REGISTER *** */
6146 struct cmd_write_reg_result {
6147         cmdline_fixed_string_t write;
6148         cmdline_fixed_string_t reg;
6149         uint8_t port_id;
6150         uint32_t reg_off;
6151         uint32_t value;
6152 };
6153
6154 static void
6155 cmd_write_reg_parsed(void *parsed_result,
6156                      __attribute__((unused)) struct cmdline *cl,
6157                      __attribute__((unused)) void *data)
6158 {
6159         struct cmd_write_reg_result *res = parsed_result;
6160         port_reg_set(res->port_id, res->reg_off, res->value);
6161 }
6162
6163 cmdline_parse_token_string_t cmd_write_reg_write =
6164         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6165 cmdline_parse_token_string_t cmd_write_reg_reg =
6166         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6167 cmdline_parse_token_num_t cmd_write_reg_port_id =
6168         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
6169 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6170         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6171 cmdline_parse_token_num_t cmd_write_reg_value =
6172         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6173
6174 cmdline_parse_inst_t cmd_write_reg = {
6175         .f = cmd_write_reg_parsed,
6176         .data = NULL,
6177         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6178         .tokens = {
6179                 (void *)&cmd_write_reg_write,
6180                 (void *)&cmd_write_reg_reg,
6181                 (void *)&cmd_write_reg_port_id,
6182                 (void *)&cmd_write_reg_reg_off,
6183                 (void *)&cmd_write_reg_value,
6184                 NULL,
6185         },
6186 };
6187
6188 /* *** WRITE PORT REGISTER BIT FIELD *** */
6189 struct cmd_write_reg_bit_field_result {
6190         cmdline_fixed_string_t write;
6191         cmdline_fixed_string_t regfield;
6192         uint8_t port_id;
6193         uint32_t reg_off;
6194         uint8_t bit1_pos;
6195         uint8_t bit2_pos;
6196         uint32_t value;
6197 };
6198
6199 static void
6200 cmd_write_reg_bit_field_parsed(void *parsed_result,
6201                                __attribute__((unused)) struct cmdline *cl,
6202                                __attribute__((unused)) void *data)
6203 {
6204         struct cmd_write_reg_bit_field_result *res = parsed_result;
6205         port_reg_bit_field_set(res->port_id, res->reg_off,
6206                           res->bit1_pos, res->bit2_pos, res->value);
6207 }
6208
6209 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6210         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6211                                  "write");
6212 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6213         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6214                                  regfield, "regfield");
6215 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6216         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6217                               UINT8);
6218 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6219         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6220                               UINT32);
6221 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6222         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6223                               UINT8);
6224 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6225         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6226                               UINT8);
6227 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6228         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6229                               UINT32);
6230
6231 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6232         .f = cmd_write_reg_bit_field_parsed,
6233         .data = NULL,
6234         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6235                 "<reg_value>: "
6236                 "Set register bit field between bit_x and bit_y included",
6237         .tokens = {
6238                 (void *)&cmd_write_reg_bit_field_write,
6239                 (void *)&cmd_write_reg_bit_field_regfield,
6240                 (void *)&cmd_write_reg_bit_field_port_id,
6241                 (void *)&cmd_write_reg_bit_field_reg_off,
6242                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6243                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6244                 (void *)&cmd_write_reg_bit_field_value,
6245                 NULL,
6246         },
6247 };
6248
6249 /* *** WRITE PORT REGISTER BIT *** */
6250 struct cmd_write_reg_bit_result {
6251         cmdline_fixed_string_t write;
6252         cmdline_fixed_string_t regbit;
6253         uint8_t port_id;
6254         uint32_t reg_off;
6255         uint8_t bit_pos;
6256         uint8_t value;
6257 };
6258
6259 static void
6260 cmd_write_reg_bit_parsed(void *parsed_result,
6261                          __attribute__((unused)) struct cmdline *cl,
6262                          __attribute__((unused)) void *data)
6263 {
6264         struct cmd_write_reg_bit_result *res = parsed_result;
6265         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6266 }
6267
6268 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6269         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6270                                  "write");
6271 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6272         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6273                                  regbit, "regbit");
6274 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6275         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
6276 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6277         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6278 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6279         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6280 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6281         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6282
6283 cmdline_parse_inst_t cmd_write_reg_bit = {
6284         .f = cmd_write_reg_bit_parsed,
6285         .data = NULL,
6286         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6287                 "0 <= bit_x <= 31",
6288         .tokens = {
6289                 (void *)&cmd_write_reg_bit_write,
6290                 (void *)&cmd_write_reg_bit_regbit,
6291                 (void *)&cmd_write_reg_bit_port_id,
6292                 (void *)&cmd_write_reg_bit_reg_off,
6293                 (void *)&cmd_write_reg_bit_bit_pos,
6294                 (void *)&cmd_write_reg_bit_value,
6295                 NULL,
6296         },
6297 };
6298
6299 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6300 struct cmd_read_rxd_txd_result {
6301         cmdline_fixed_string_t read;
6302         cmdline_fixed_string_t rxd_txd;
6303         uint8_t port_id;
6304         uint16_t queue_id;
6305         uint16_t desc_id;
6306 };
6307
6308 static void
6309 cmd_read_rxd_txd_parsed(void *parsed_result,
6310                         __attribute__((unused)) struct cmdline *cl,
6311                         __attribute__((unused)) void *data)
6312 {
6313         struct cmd_read_rxd_txd_result *res = parsed_result;
6314
6315         if (!strcmp(res->rxd_txd, "rxd"))
6316                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6317         else if (!strcmp(res->rxd_txd, "txd"))
6318                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6319 }
6320
6321 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6322         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6323 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6324         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6325                                  "rxd#txd");
6326 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6327         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
6328 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6329         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6330 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6331         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6332
6333 cmdline_parse_inst_t cmd_read_rxd_txd = {
6334         .f = cmd_read_rxd_txd_parsed,
6335         .data = NULL,
6336         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6337         .tokens = {
6338                 (void *)&cmd_read_rxd_txd_read,
6339                 (void *)&cmd_read_rxd_txd_rxd_txd,
6340                 (void *)&cmd_read_rxd_txd_port_id,
6341                 (void *)&cmd_read_rxd_txd_queue_id,
6342                 (void *)&cmd_read_rxd_txd_desc_id,
6343                 NULL,
6344         },
6345 };
6346
6347 /* *** QUIT *** */
6348 struct cmd_quit_result {
6349         cmdline_fixed_string_t quit;
6350 };
6351
6352 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6353                             struct cmdline *cl,
6354                             __attribute__((unused)) void *data)
6355 {
6356         pmd_test_exit();
6357         cmdline_quit(cl);
6358 }
6359
6360 cmdline_parse_token_string_t cmd_quit_quit =
6361         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6362
6363 cmdline_parse_inst_t cmd_quit = {
6364         .f = cmd_quit_parsed,
6365         .data = NULL,
6366         .help_str = "quit: Exit application",
6367         .tokens = {
6368                 (void *)&cmd_quit_quit,
6369                 NULL,
6370         },
6371 };
6372
6373 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
6374 struct cmd_mac_addr_result {
6375         cmdline_fixed_string_t mac_addr_cmd;
6376         cmdline_fixed_string_t what;
6377         uint8_t port_num;
6378         struct ether_addr address;
6379 };
6380
6381 static void cmd_mac_addr_parsed(void *parsed_result,
6382                 __attribute__((unused)) struct cmdline *cl,
6383                 __attribute__((unused)) void *data)
6384 {
6385         struct cmd_mac_addr_result *res = parsed_result;
6386         int ret;
6387
6388         if (strcmp(res->what, "add") == 0)
6389                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
6390         else if (strcmp(res->what, "set") == 0)
6391                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
6392                                                        &res->address);
6393         else
6394                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
6395
6396         /* check the return value and print it if is < 0 */
6397         if(ret < 0)
6398                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
6399
6400 }
6401
6402 cmdline_parse_token_string_t cmd_mac_addr_cmd =
6403         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
6404                                 "mac_addr");
6405 cmdline_parse_token_string_t cmd_mac_addr_what =
6406         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
6407                                 "add#remove#set");
6408 cmdline_parse_token_num_t cmd_mac_addr_portnum =
6409                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
6410 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
6411                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
6412
6413 cmdline_parse_inst_t cmd_mac_addr = {
6414         .f = cmd_mac_addr_parsed,
6415         .data = (void *)0,
6416         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
6417                         "Add/Remove/Set MAC address on port_id",
6418         .tokens = {
6419                 (void *)&cmd_mac_addr_cmd,
6420                 (void *)&cmd_mac_addr_what,
6421                 (void *)&cmd_mac_addr_portnum,
6422                 (void *)&cmd_mac_addr_addr,
6423                 NULL,
6424         },
6425 };
6426
6427
6428 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
6429 struct cmd_set_qmap_result {
6430         cmdline_fixed_string_t set;
6431         cmdline_fixed_string_t qmap;
6432         cmdline_fixed_string_t what;
6433         uint8_t port_id;
6434         uint16_t queue_id;
6435         uint8_t map_value;
6436 };
6437
6438 static void
6439 cmd_set_qmap_parsed(void *parsed_result,
6440                        __attribute__((unused)) struct cmdline *cl,
6441                        __attribute__((unused)) void *data)
6442 {
6443         struct cmd_set_qmap_result *res = parsed_result;
6444         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
6445
6446         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
6447 }
6448
6449 cmdline_parse_token_string_t cmd_setqmap_set =
6450         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6451                                  set, "set");
6452 cmdline_parse_token_string_t cmd_setqmap_qmap =
6453         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6454                                  qmap, "stat_qmap");
6455 cmdline_parse_token_string_t cmd_setqmap_what =
6456         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6457                                  what, "tx#rx");
6458 cmdline_parse_token_num_t cmd_setqmap_portid =
6459         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6460                               port_id, UINT8);
6461 cmdline_parse_token_num_t cmd_setqmap_queueid =
6462         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6463                               queue_id, UINT16);
6464 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
6465         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6466                               map_value, UINT8);
6467
6468 cmdline_parse_inst_t cmd_set_qmap = {
6469         .f = cmd_set_qmap_parsed,
6470         .data = NULL,
6471         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
6472                 "Set statistics mapping value on tx|rx queue_id of port_id",
6473         .tokens = {
6474                 (void *)&cmd_setqmap_set,
6475                 (void *)&cmd_setqmap_qmap,
6476                 (void *)&cmd_setqmap_what,
6477                 (void *)&cmd_setqmap_portid,
6478                 (void *)&cmd_setqmap_queueid,
6479                 (void *)&cmd_setqmap_mapvalue,
6480                 NULL,
6481         },
6482 };
6483
6484 /* *** CONFIGURE UNICAST HASH TABLE *** */
6485 struct cmd_set_uc_hash_table {
6486         cmdline_fixed_string_t set;
6487         cmdline_fixed_string_t port;
6488         uint8_t port_id;
6489         cmdline_fixed_string_t what;
6490         struct ether_addr address;
6491         cmdline_fixed_string_t mode;
6492 };
6493
6494 static void
6495 cmd_set_uc_hash_parsed(void *parsed_result,
6496                        __attribute__((unused)) struct cmdline *cl,
6497                        __attribute__((unused)) void *data)
6498 {
6499         int ret=0;
6500         struct cmd_set_uc_hash_table *res = parsed_result;
6501
6502         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6503
6504         if (strcmp(res->what, "uta") == 0)
6505                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
6506                                                 &res->address,(uint8_t)is_on);
6507         if (ret < 0)
6508                 printf("bad unicast hash table parameter, return code = %d \n", ret);
6509
6510 }
6511
6512 cmdline_parse_token_string_t cmd_set_uc_hash_set =
6513         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6514                                  set, "set");
6515 cmdline_parse_token_string_t cmd_set_uc_hash_port =
6516         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6517                                  port, "port");
6518 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
6519         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
6520                               port_id, UINT8);
6521 cmdline_parse_token_string_t cmd_set_uc_hash_what =
6522         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6523                                  what, "uta");
6524 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
6525         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
6526                                 address);
6527 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
6528         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6529                                  mode, "on#off");
6530
6531 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
6532         .f = cmd_set_uc_hash_parsed,
6533         .data = NULL,
6534         .help_str = "set port <port_id> uta <mac_addr> on|off)",
6535         .tokens = {
6536                 (void *)&cmd_set_uc_hash_set,
6537                 (void *)&cmd_set_uc_hash_port,
6538                 (void *)&cmd_set_uc_hash_portid,
6539                 (void *)&cmd_set_uc_hash_what,
6540                 (void *)&cmd_set_uc_hash_mac,
6541                 (void *)&cmd_set_uc_hash_mode,
6542                 NULL,
6543         },
6544 };
6545
6546 struct cmd_set_uc_all_hash_table {
6547         cmdline_fixed_string_t set;
6548         cmdline_fixed_string_t port;
6549         uint8_t port_id;
6550         cmdline_fixed_string_t what;
6551         cmdline_fixed_string_t value;
6552         cmdline_fixed_string_t mode;
6553 };
6554
6555 static void
6556 cmd_set_uc_all_hash_parsed(void *parsed_result,
6557                        __attribute__((unused)) struct cmdline *cl,
6558                        __attribute__((unused)) void *data)
6559 {
6560         int ret=0;
6561         struct cmd_set_uc_all_hash_table *res = parsed_result;
6562
6563         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6564
6565         if ((strcmp(res->what, "uta") == 0) &&
6566                 (strcmp(res->value, "all") == 0))
6567                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
6568         if (ret < 0)
6569                 printf("bad unicast hash table parameter,"
6570                         "return code = %d \n", ret);
6571 }
6572
6573 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
6574         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6575                                  set, "set");
6576 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
6577         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6578                                  port, "port");
6579 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
6580         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
6581                               port_id, UINT8);
6582 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
6583         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6584                                  what, "uta");
6585 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
6586         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6587                                 value,"all");
6588 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
6589         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6590                                  mode, "on#off");
6591
6592 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
6593         .f = cmd_set_uc_all_hash_parsed,
6594         .data = NULL,
6595         .help_str = "set port <port_id> uta all on|off",
6596         .tokens = {
6597                 (void *)&cmd_set_uc_all_hash_set,
6598                 (void *)&cmd_set_uc_all_hash_port,
6599                 (void *)&cmd_set_uc_all_hash_portid,
6600                 (void *)&cmd_set_uc_all_hash_what,
6601                 (void *)&cmd_set_uc_all_hash_value,
6602                 (void *)&cmd_set_uc_all_hash_mode,
6603                 NULL,
6604         },
6605 };
6606
6607 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
6608 struct cmd_set_vf_macvlan_filter {
6609         cmdline_fixed_string_t set;
6610         cmdline_fixed_string_t port;
6611         uint8_t port_id;
6612         cmdline_fixed_string_t vf;
6613         uint8_t vf_id;
6614         struct ether_addr address;
6615         cmdline_fixed_string_t filter_type;
6616         cmdline_fixed_string_t mode;
6617 };
6618
6619 static void
6620 cmd_set_vf_macvlan_parsed(void *parsed_result,
6621                        __attribute__((unused)) struct cmdline *cl,
6622                        __attribute__((unused)) void *data)
6623 {
6624         int is_on, ret = 0;
6625         struct cmd_set_vf_macvlan_filter *res = parsed_result;
6626         struct rte_eth_mac_filter filter;
6627
6628         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
6629
6630         (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
6631
6632         /* set VF MAC filter */
6633         filter.is_vf = 1;
6634
6635         /* set VF ID */
6636         filter.dst_id = res->vf_id;
6637
6638         if (!strcmp(res->filter_type, "exact-mac"))
6639                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
6640         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
6641                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
6642         else if (!strcmp(res->filter_type, "hashmac"))
6643                 filter.filter_type = RTE_MAC_HASH_MATCH;
6644         else if (!strcmp(res->filter_type, "hashmac-vlan"))
6645                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
6646
6647         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6648
6649         if (is_on)
6650                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6651                                         RTE_ETH_FILTER_MACVLAN,
6652                                         RTE_ETH_FILTER_ADD,
6653                                          &filter);
6654         else
6655                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6656                                         RTE_ETH_FILTER_MACVLAN,
6657                                         RTE_ETH_FILTER_DELETE,
6658                                         &filter);
6659
6660         if (ret < 0)
6661                 printf("bad set MAC hash parameter, return code = %d\n", ret);
6662
6663 }
6664
6665 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
6666         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6667                                  set, "set");
6668 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
6669         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6670                                  port, "port");
6671 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
6672         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6673                               port_id, UINT8);
6674 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
6675         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6676                                  vf, "vf");
6677 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
6678         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6679                                 vf_id, UINT8);
6680 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
6681         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6682                                 address);
6683 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
6684         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6685                                 filter_type, "exact-mac#exact-mac-vlan"
6686                                 "#hashmac#hashmac-vlan");
6687 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
6688         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6689                                  mode, "on#off");
6690
6691 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
6692         .f = cmd_set_vf_macvlan_parsed,
6693         .data = NULL,
6694         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
6695                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
6696                 "Exact match rule: exact match of MAC or MAC and VLAN; "
6697                 "hash match rule: hash match of MAC and exact match of VLAN",
6698         .tokens = {
6699                 (void *)&cmd_set_vf_macvlan_set,
6700                 (void *)&cmd_set_vf_macvlan_port,
6701                 (void *)&cmd_set_vf_macvlan_portid,
6702                 (void *)&cmd_set_vf_macvlan_vf,
6703                 (void *)&cmd_set_vf_macvlan_vf_id,
6704                 (void *)&cmd_set_vf_macvlan_mac,
6705                 (void *)&cmd_set_vf_macvlan_filter_type,
6706                 (void *)&cmd_set_vf_macvlan_mode,
6707                 NULL,
6708         },
6709 };
6710
6711 #ifdef RTE_LIBRTE_IXGBE_PMD
6712 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
6713 struct cmd_set_vf_traffic {
6714         cmdline_fixed_string_t set;
6715         cmdline_fixed_string_t port;
6716         uint8_t port_id;
6717         cmdline_fixed_string_t vf;
6718         uint8_t vf_id;
6719         cmdline_fixed_string_t what;
6720         cmdline_fixed_string_t mode;
6721 };
6722
6723 static void
6724 cmd_set_vf_traffic_parsed(void *parsed_result,
6725                        __attribute__((unused)) struct cmdline *cl,
6726                        __attribute__((unused)) void *data)
6727 {
6728         struct cmd_set_vf_traffic *res = parsed_result;
6729         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
6730         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6731
6732         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
6733 }
6734
6735 cmdline_parse_token_string_t cmd_setvf_traffic_set =
6736         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6737                                  set, "set");
6738 cmdline_parse_token_string_t cmd_setvf_traffic_port =
6739         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6740                                  port, "port");
6741 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
6742         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6743                               port_id, UINT8);
6744 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
6745         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6746                                  vf, "vf");
6747 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
6748         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6749                               vf_id, UINT8);
6750 cmdline_parse_token_string_t cmd_setvf_traffic_what =
6751         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6752                                  what, "tx#rx");
6753 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
6754         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6755                                  mode, "on#off");
6756
6757 cmdline_parse_inst_t cmd_set_vf_traffic = {
6758         .f = cmd_set_vf_traffic_parsed,
6759         .data = NULL,
6760         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
6761         .tokens = {
6762                 (void *)&cmd_setvf_traffic_set,
6763                 (void *)&cmd_setvf_traffic_port,
6764                 (void *)&cmd_setvf_traffic_portid,
6765                 (void *)&cmd_setvf_traffic_vf,
6766                 (void *)&cmd_setvf_traffic_vfid,
6767                 (void *)&cmd_setvf_traffic_what,
6768                 (void *)&cmd_setvf_traffic_mode,
6769                 NULL,
6770         },
6771 };
6772
6773 /* *** CONFIGURE VF RECEIVE MODE *** */
6774 struct cmd_set_vf_rxmode {
6775         cmdline_fixed_string_t set;
6776         cmdline_fixed_string_t port;
6777         uint8_t port_id;
6778         cmdline_fixed_string_t vf;
6779         uint8_t vf_id;
6780         cmdline_fixed_string_t what;
6781         cmdline_fixed_string_t mode;
6782         cmdline_fixed_string_t on;
6783 };
6784
6785 static void
6786 cmd_set_vf_rxmode_parsed(void *parsed_result,
6787                        __attribute__((unused)) struct cmdline *cl,
6788                        __attribute__((unused)) void *data)
6789 {
6790         int ret;
6791         uint16_t rx_mode = 0;
6792         struct cmd_set_vf_rxmode *res = parsed_result;
6793
6794         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
6795         if (!strcmp(res->what,"rxmode")) {
6796                 if (!strcmp(res->mode, "AUPE"))
6797                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
6798                 else if (!strcmp(res->mode, "ROPE"))
6799                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
6800                 else if (!strcmp(res->mode, "BAM"))
6801                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
6802                 else if (!strncmp(res->mode, "MPE",3))
6803                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
6804         }
6805
6806         ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id, rx_mode, (uint8_t)is_on);
6807         if (ret < 0)
6808                 printf("bad VF receive mode parameter, return code = %d \n",
6809                 ret);
6810 }
6811
6812 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
6813         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6814                                  set, "set");
6815 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
6816         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6817                                  port, "port");
6818 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
6819         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6820                               port_id, UINT8);
6821 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
6822         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6823                                  vf, "vf");
6824 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
6825         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6826                               vf_id, UINT8);
6827 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
6828         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6829                                  what, "rxmode");
6830 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
6831         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6832                                  mode, "AUPE#ROPE#BAM#MPE");
6833 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
6834         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6835                                  on, "on#off");
6836
6837 cmdline_parse_inst_t cmd_set_vf_rxmode = {
6838         .f = cmd_set_vf_rxmode_parsed,
6839         .data = NULL,
6840         .help_str = "set port <port_id> vf <vf_id> rxmode "
6841                 "AUPE|ROPE|BAM|MPE on|off",
6842         .tokens = {
6843                 (void *)&cmd_set_vf_rxmode_set,
6844                 (void *)&cmd_set_vf_rxmode_port,
6845                 (void *)&cmd_set_vf_rxmode_portid,
6846                 (void *)&cmd_set_vf_rxmode_vf,
6847                 (void *)&cmd_set_vf_rxmode_vfid,
6848                 (void *)&cmd_set_vf_rxmode_what,
6849                 (void *)&cmd_set_vf_rxmode_mode,
6850                 (void *)&cmd_set_vf_rxmode_on,
6851                 NULL,
6852         },
6853 };
6854 #endif
6855
6856 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
6857 struct cmd_vf_mac_addr_result {
6858         cmdline_fixed_string_t mac_addr_cmd;
6859         cmdline_fixed_string_t what;
6860         cmdline_fixed_string_t port;
6861         uint8_t port_num;
6862         cmdline_fixed_string_t vf;
6863         uint8_t vf_num;
6864         struct ether_addr address;
6865 };
6866
6867 static void cmd_vf_mac_addr_parsed(void *parsed_result,
6868                 __attribute__((unused)) struct cmdline *cl,
6869                 __attribute__((unused)) void *data)
6870 {
6871         struct cmd_vf_mac_addr_result *res = parsed_result;
6872         int ret = 0;
6873
6874         if (strcmp(res->what, "add") == 0)
6875                 ret = rte_eth_dev_mac_addr_add(res->port_num,
6876                                         &res->address, res->vf_num);
6877         if(ret < 0)
6878                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
6879
6880 }
6881
6882 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
6883         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6884                                 mac_addr_cmd,"mac_addr");
6885 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
6886         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6887                                 what,"add");
6888 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
6889         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6890                                 port,"port");
6891 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
6892         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6893                                 port_num, UINT8);
6894 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
6895         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6896                                 vf,"vf");
6897 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
6898         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6899                                 vf_num, UINT8);
6900 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
6901         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
6902                                 address);
6903
6904 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
6905         .f = cmd_vf_mac_addr_parsed,
6906         .data = (void *)0,
6907         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
6908                 "Add MAC address filtering for a VF on port_id",
6909         .tokens = {
6910                 (void *)&cmd_vf_mac_addr_cmd,
6911                 (void *)&cmd_vf_mac_addr_what,
6912                 (void *)&cmd_vf_mac_addr_port,
6913                 (void *)&cmd_vf_mac_addr_portnum,
6914                 (void *)&cmd_vf_mac_addr_vf,
6915                 (void *)&cmd_vf_mac_addr_vfnum,
6916                 (void *)&cmd_vf_mac_addr_addr,
6917                 NULL,
6918         },
6919 };
6920
6921 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
6922 struct cmd_vf_rx_vlan_filter {
6923         cmdline_fixed_string_t rx_vlan;
6924         cmdline_fixed_string_t what;
6925         uint16_t vlan_id;
6926         cmdline_fixed_string_t port;
6927         uint8_t port_id;
6928         cmdline_fixed_string_t vf;
6929         uint64_t vf_mask;
6930 };
6931
6932 static void
6933 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
6934                           __attribute__((unused)) struct cmdline *cl,
6935                           __attribute__((unused)) void *data)
6936 {
6937         struct cmd_vf_rx_vlan_filter *res = parsed_result;
6938         int ret = -ENOTSUP;
6939
6940         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
6941
6942 #ifdef RTE_LIBRTE_IXGBE_PMD
6943         if (ret == -ENOTSUP)
6944                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
6945                                 res->vlan_id, res->vf_mask, is_add);
6946 #endif
6947 #ifdef RTE_LIBRTE_I40E_PMD
6948         if (ret == -ENOTSUP)
6949                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
6950                                 res->vlan_id, res->vf_mask, is_add);
6951 #endif
6952
6953         switch (ret) {
6954         case 0:
6955                 break;
6956         case -EINVAL:
6957                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
6958                                 res->vlan_id, res->vf_mask);
6959                 break;
6960         case -ENODEV:
6961                 printf("invalid port_id %d\n", res->port_id);
6962                 break;
6963         case -ENOTSUP:
6964                 printf("function not implemented or supported\n");
6965                 break;
6966         default:
6967                 printf("programming error: (%s)\n", strerror(-ret));
6968         }
6969 }
6970
6971 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
6972         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6973                                  rx_vlan, "rx_vlan");
6974 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
6975         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6976                                  what, "add#rm");
6977 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
6978         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6979                               vlan_id, UINT16);
6980 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
6981         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6982                                  port, "port");
6983 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
6984         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6985                               port_id, UINT8);
6986 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
6987         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6988                                  vf, "vf");
6989 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
6990         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6991                               vf_mask, UINT64);
6992
6993 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
6994         .f = cmd_vf_rx_vlan_filter_parsed,
6995         .data = NULL,
6996         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
6997                 "(vf_mask = hexadecimal VF mask)",
6998         .tokens = {
6999                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7000                 (void *)&cmd_vf_rx_vlan_filter_what,
7001                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7002                 (void *)&cmd_vf_rx_vlan_filter_port,
7003                 (void *)&cmd_vf_rx_vlan_filter_portid,
7004                 (void *)&cmd_vf_rx_vlan_filter_vf,
7005                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7006                 NULL,
7007         },
7008 };
7009
7010 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7011 struct cmd_queue_rate_limit_result {
7012         cmdline_fixed_string_t set;
7013         cmdline_fixed_string_t port;
7014         uint8_t port_num;
7015         cmdline_fixed_string_t queue;
7016         uint8_t queue_num;
7017         cmdline_fixed_string_t rate;
7018         uint16_t rate_num;
7019 };
7020
7021 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7022                 __attribute__((unused)) struct cmdline *cl,
7023                 __attribute__((unused)) void *data)
7024 {
7025         struct cmd_queue_rate_limit_result *res = parsed_result;
7026         int ret = 0;
7027
7028         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7029                 && (strcmp(res->queue, "queue") == 0)
7030                 && (strcmp(res->rate, "rate") == 0))
7031                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7032                                         res->rate_num);
7033         if (ret < 0)
7034                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7035
7036 }
7037
7038 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7039         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7040                                 set, "set");
7041 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7042         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7043                                 port, "port");
7044 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7045         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7046                                 port_num, UINT8);
7047 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7048         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7049                                 queue, "queue");
7050 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7051         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7052                                 queue_num, UINT8);
7053 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7054         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7055                                 rate, "rate");
7056 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7057         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7058                                 rate_num, UINT16);
7059
7060 cmdline_parse_inst_t cmd_queue_rate_limit = {
7061         .f = cmd_queue_rate_limit_parsed,
7062         .data = (void *)0,
7063         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7064                 "Set rate limit for a queue on port_id",
7065         .tokens = {
7066                 (void *)&cmd_queue_rate_limit_set,
7067                 (void *)&cmd_queue_rate_limit_port,
7068                 (void *)&cmd_queue_rate_limit_portnum,
7069                 (void *)&cmd_queue_rate_limit_queue,
7070                 (void *)&cmd_queue_rate_limit_queuenum,
7071                 (void *)&cmd_queue_rate_limit_rate,
7072                 (void *)&cmd_queue_rate_limit_ratenum,
7073                 NULL,
7074         },
7075 };
7076
7077 #ifdef RTE_LIBRTE_IXGBE_PMD
7078 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7079 struct cmd_vf_rate_limit_result {
7080         cmdline_fixed_string_t set;
7081         cmdline_fixed_string_t port;
7082         uint8_t port_num;
7083         cmdline_fixed_string_t vf;
7084         uint8_t vf_num;
7085         cmdline_fixed_string_t rate;
7086         uint16_t rate_num;
7087         cmdline_fixed_string_t q_msk;
7088         uint64_t q_msk_val;
7089 };
7090
7091 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7092                 __attribute__((unused)) struct cmdline *cl,
7093                 __attribute__((unused)) void *data)
7094 {
7095         struct cmd_vf_rate_limit_result *res = parsed_result;
7096         int ret = 0;
7097
7098         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7099                 && (strcmp(res->vf, "vf") == 0)
7100                 && (strcmp(res->rate, "rate") == 0)
7101                 && (strcmp(res->q_msk, "queue_mask") == 0))
7102                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7103                                         res->rate_num, res->q_msk_val);
7104         if (ret < 0)
7105                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7106
7107 }
7108
7109 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7110         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7111                                 set, "set");
7112 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7113         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7114                                 port, "port");
7115 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7116         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7117                                 port_num, UINT8);
7118 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7119         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7120                                 vf, "vf");
7121 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7122         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7123                                 vf_num, UINT8);
7124 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7125         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7126                                 rate, "rate");
7127 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7128         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7129                                 rate_num, UINT16);
7130 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7131         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7132                                 q_msk, "queue_mask");
7133 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7134         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7135                                 q_msk_val, UINT64);
7136
7137 cmdline_parse_inst_t cmd_vf_rate_limit = {
7138         .f = cmd_vf_rate_limit_parsed,
7139         .data = (void *)0,
7140         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7141                 "queue_mask <queue_mask_value>: "
7142                 "Set rate limit for queues of VF on port_id",
7143         .tokens = {
7144                 (void *)&cmd_vf_rate_limit_set,
7145                 (void *)&cmd_vf_rate_limit_port,
7146                 (void *)&cmd_vf_rate_limit_portnum,
7147                 (void *)&cmd_vf_rate_limit_vf,
7148                 (void *)&cmd_vf_rate_limit_vfnum,
7149                 (void *)&cmd_vf_rate_limit_rate,
7150                 (void *)&cmd_vf_rate_limit_ratenum,
7151                 (void *)&cmd_vf_rate_limit_q_msk,
7152                 (void *)&cmd_vf_rate_limit_q_msk_val,
7153                 NULL,
7154         },
7155 };
7156 #endif
7157
7158 /* *** ADD TUNNEL FILTER OF A PORT *** */
7159 struct cmd_tunnel_filter_result {
7160         cmdline_fixed_string_t cmd;
7161         cmdline_fixed_string_t what;
7162         uint8_t port_id;
7163         struct ether_addr outer_mac;
7164         struct ether_addr inner_mac;
7165         cmdline_ipaddr_t ip_value;
7166         uint16_t inner_vlan;
7167         cmdline_fixed_string_t tunnel_type;
7168         cmdline_fixed_string_t filter_type;
7169         uint32_t tenant_id;
7170         uint16_t queue_num;
7171 };
7172
7173 static void
7174 cmd_tunnel_filter_parsed(void *parsed_result,
7175                           __attribute__((unused)) struct cmdline *cl,
7176                           __attribute__((unused)) void *data)
7177 {
7178         struct cmd_tunnel_filter_result *res = parsed_result;
7179         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7180         int ret = 0;
7181
7182         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7183
7184         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7185         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7186         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7187
7188         if (res->ip_value.family == AF_INET) {
7189                 tunnel_filter_conf.ip_addr.ipv4_addr =
7190                         res->ip_value.addr.ipv4.s_addr;
7191                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7192         } else {
7193                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7194                         &(res->ip_value.addr.ipv6),
7195                         sizeof(struct in6_addr));
7196                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7197         }
7198
7199         if (!strcmp(res->filter_type, "imac-ivlan"))
7200                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7201         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7202                 tunnel_filter_conf.filter_type =
7203                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7204         else if (!strcmp(res->filter_type, "imac-tenid"))
7205                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7206         else if (!strcmp(res->filter_type, "imac"))
7207                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7208         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7209                 tunnel_filter_conf.filter_type =
7210                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7211         else if (!strcmp(res->filter_type, "oip"))
7212                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7213         else if (!strcmp(res->filter_type, "iip"))
7214                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7215         else {
7216                 printf("The filter type is not supported");
7217                 return;
7218         }
7219
7220         if (!strcmp(res->tunnel_type, "vxlan"))
7221                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7222         else if (!strcmp(res->tunnel_type, "nvgre"))
7223                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7224         else if (!strcmp(res->tunnel_type, "ipingre"))
7225                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7226         else {
7227                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7228                 return;
7229         }
7230
7231         tunnel_filter_conf.tenant_id = res->tenant_id;
7232         tunnel_filter_conf.queue_id = res->queue_num;
7233         if (!strcmp(res->what, "add"))
7234                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7235                                         RTE_ETH_FILTER_TUNNEL,
7236                                         RTE_ETH_FILTER_ADD,
7237                                         &tunnel_filter_conf);
7238         else
7239                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7240                                         RTE_ETH_FILTER_TUNNEL,
7241                                         RTE_ETH_FILTER_DELETE,
7242                                         &tunnel_filter_conf);
7243         if (ret < 0)
7244                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
7245                                 strerror(-ret));
7246
7247 }
7248 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7249         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7250         cmd, "tunnel_filter");
7251 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7252         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7253         what, "add#rm");
7254 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7255         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7256         port_id, UINT8);
7257 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7258         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7259         outer_mac);
7260 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7261         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7262         inner_mac);
7263 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7264         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7265         inner_vlan, UINT16);
7266 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7267         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7268         ip_value);
7269 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7270         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7271         tunnel_type, "vxlan#nvgre#ipingre");
7272
7273 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7274         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7275         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7276                 "imac#omac-imac-tenid");
7277 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7278         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7279         tenant_id, UINT32);
7280 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7281         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7282         queue_num, UINT16);
7283
7284 cmdline_parse_inst_t cmd_tunnel_filter = {
7285         .f = cmd_tunnel_filter_parsed,
7286         .data = (void *)0,
7287         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7288                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7289                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7290                 "<queue_id>: Add/Rm tunnel filter of a port",
7291         .tokens = {
7292                 (void *)&cmd_tunnel_filter_cmd,
7293                 (void *)&cmd_tunnel_filter_what,
7294                 (void *)&cmd_tunnel_filter_port_id,
7295                 (void *)&cmd_tunnel_filter_outer_mac,
7296                 (void *)&cmd_tunnel_filter_inner_mac,
7297                 (void *)&cmd_tunnel_filter_ip_value,
7298                 (void *)&cmd_tunnel_filter_innner_vlan,
7299                 (void *)&cmd_tunnel_filter_tunnel_type,
7300                 (void *)&cmd_tunnel_filter_filter_type,
7301                 (void *)&cmd_tunnel_filter_tenant_id,
7302                 (void *)&cmd_tunnel_filter_queue_num,
7303                 NULL,
7304         },
7305 };
7306
7307 /* *** CONFIGURE TUNNEL UDP PORT *** */
7308 struct cmd_tunnel_udp_config {
7309         cmdline_fixed_string_t cmd;
7310         cmdline_fixed_string_t what;
7311         uint16_t udp_port;
7312         uint8_t port_id;
7313 };
7314
7315 static void
7316 cmd_tunnel_udp_config_parsed(void *parsed_result,
7317                           __attribute__((unused)) struct cmdline *cl,
7318                           __attribute__((unused)) void *data)
7319 {
7320         struct cmd_tunnel_udp_config *res = parsed_result;
7321         struct rte_eth_udp_tunnel tunnel_udp;
7322         int ret;
7323
7324         tunnel_udp.udp_port = res->udp_port;
7325
7326         if (!strcmp(res->cmd, "rx_vxlan_port"))
7327                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7328
7329         if (!strcmp(res->what, "add"))
7330                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7331                                                       &tunnel_udp);
7332         else
7333                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7334                                                          &tunnel_udp);
7335
7336         if (ret < 0)
7337                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
7338 }
7339
7340 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7341         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7342                                 cmd, "rx_vxlan_port");
7343 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7344         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7345                                 what, "add#rm");
7346 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7347         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7348                                 udp_port, UINT16);
7349 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7350         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7351                                 port_id, UINT8);
7352
7353 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7354         .f = cmd_tunnel_udp_config_parsed,
7355         .data = (void *)0,
7356         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
7357                 "Add/Remove a tunneling UDP port filter",
7358         .tokens = {
7359                 (void *)&cmd_tunnel_udp_config_cmd,
7360                 (void *)&cmd_tunnel_udp_config_what,
7361                 (void *)&cmd_tunnel_udp_config_udp_port,
7362                 (void *)&cmd_tunnel_udp_config_port_id,
7363                 NULL,
7364         },
7365 };
7366
7367 /* *** GLOBAL CONFIG *** */
7368 struct cmd_global_config_result {
7369         cmdline_fixed_string_t cmd;
7370         uint8_t port_id;
7371         cmdline_fixed_string_t cfg_type;
7372         uint8_t len;
7373 };
7374
7375 static void
7376 cmd_global_config_parsed(void *parsed_result,
7377                          __attribute__((unused)) struct cmdline *cl,
7378                          __attribute__((unused)) void *data)
7379 {
7380         struct cmd_global_config_result *res = parsed_result;
7381         struct rte_eth_global_cfg conf;
7382         int ret;
7383
7384         memset(&conf, 0, sizeof(conf));
7385         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
7386         conf.cfg.gre_key_len = res->len;
7387         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
7388                                       RTE_ETH_FILTER_SET, &conf);
7389         if (ret != 0)
7390                 printf("Global config error\n");
7391 }
7392
7393 cmdline_parse_token_string_t cmd_global_config_cmd =
7394         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
7395                 "global_config");
7396 cmdline_parse_token_num_t cmd_global_config_port_id =
7397         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
7398 cmdline_parse_token_string_t cmd_global_config_type =
7399         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
7400                 cfg_type, "gre-key-len");
7401 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
7402         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
7403                 len, UINT8);
7404
7405 cmdline_parse_inst_t cmd_global_config = {
7406         .f = cmd_global_config_parsed,
7407         .data = (void *)NULL,
7408         .help_str = "global_config <port_id> gre-key-len <key_len>",
7409         .tokens = {
7410                 (void *)&cmd_global_config_cmd,
7411                 (void *)&cmd_global_config_port_id,
7412                 (void *)&cmd_global_config_type,
7413                 (void *)&cmd_global_config_gre_key_len,
7414                 NULL,
7415         },
7416 };
7417
7418 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
7419 struct cmd_set_mirror_mask_result {
7420         cmdline_fixed_string_t set;
7421         cmdline_fixed_string_t port;
7422         uint8_t port_id;
7423         cmdline_fixed_string_t mirror;
7424         uint8_t rule_id;
7425         cmdline_fixed_string_t what;
7426         cmdline_fixed_string_t value;
7427         cmdline_fixed_string_t dstpool;
7428         uint8_t dstpool_id;
7429         cmdline_fixed_string_t on;
7430 };
7431
7432 cmdline_parse_token_string_t cmd_mirror_mask_set =
7433         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7434                                 set, "set");
7435 cmdline_parse_token_string_t cmd_mirror_mask_port =
7436         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7437                                 port, "port");
7438 cmdline_parse_token_num_t cmd_mirror_mask_portid =
7439         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7440                                 port_id, UINT8);
7441 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
7442         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7443                                 mirror, "mirror-rule");
7444 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
7445         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7446                                 rule_id, UINT8);
7447 cmdline_parse_token_string_t cmd_mirror_mask_what =
7448         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7449                                 what, "pool-mirror-up#pool-mirror-down"
7450                                       "#vlan-mirror");
7451 cmdline_parse_token_string_t cmd_mirror_mask_value =
7452         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7453                                 value, NULL);
7454 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
7455         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7456                                 dstpool, "dst-pool");
7457 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
7458         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7459                                 dstpool_id, UINT8);
7460 cmdline_parse_token_string_t cmd_mirror_mask_on =
7461         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7462                                 on, "on#off");
7463
7464 static void
7465 cmd_set_mirror_mask_parsed(void *parsed_result,
7466                        __attribute__((unused)) struct cmdline *cl,
7467                        __attribute__((unused)) void *data)
7468 {
7469         int ret,nb_item,i;
7470         struct cmd_set_mirror_mask_result *res = parsed_result;
7471         struct rte_eth_mirror_conf mr_conf;
7472
7473         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7474
7475         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
7476
7477         mr_conf.dst_pool = res->dstpool_id;
7478
7479         if (!strcmp(res->what, "pool-mirror-up")) {
7480                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7481                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
7482         } else if (!strcmp(res->what, "pool-mirror-down")) {
7483                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7484                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
7485         } else if (!strcmp(res->what, "vlan-mirror")) {
7486                 mr_conf.rule_type = ETH_MIRROR_VLAN;
7487                 nb_item = parse_item_list(res->value, "vlan",
7488                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
7489                 if (nb_item <= 0)
7490                         return;
7491
7492                 for (i = 0; i < nb_item; i++) {
7493                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
7494                                 printf("Invalid vlan_id: must be < 4096\n");
7495                                 return;
7496                         }
7497
7498                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
7499                         mr_conf.vlan.vlan_mask |= 1ULL << i;
7500                 }
7501         }
7502
7503         if (!strcmp(res->on, "on"))
7504                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7505                                                 res->rule_id, 1);
7506         else
7507                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7508                                                 res->rule_id, 0);
7509         if (ret < 0)
7510                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7511 }
7512
7513 cmdline_parse_inst_t cmd_set_mirror_mask = {
7514                 .f = cmd_set_mirror_mask_parsed,
7515                 .data = NULL,
7516                 .help_str = "set port <port_id> mirror-rule <rule_id> "
7517                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
7518                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
7519                 .tokens = {
7520                         (void *)&cmd_mirror_mask_set,
7521                         (void *)&cmd_mirror_mask_port,
7522                         (void *)&cmd_mirror_mask_portid,
7523                         (void *)&cmd_mirror_mask_mirror,
7524                         (void *)&cmd_mirror_mask_ruleid,
7525                         (void *)&cmd_mirror_mask_what,
7526                         (void *)&cmd_mirror_mask_value,
7527                         (void *)&cmd_mirror_mask_dstpool,
7528                         (void *)&cmd_mirror_mask_poolid,
7529                         (void *)&cmd_mirror_mask_on,
7530                         NULL,
7531                 },
7532 };
7533
7534 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
7535 struct cmd_set_mirror_link_result {
7536         cmdline_fixed_string_t set;
7537         cmdline_fixed_string_t port;
7538         uint8_t port_id;
7539         cmdline_fixed_string_t mirror;
7540         uint8_t rule_id;
7541         cmdline_fixed_string_t what;
7542         cmdline_fixed_string_t dstpool;
7543         uint8_t dstpool_id;
7544         cmdline_fixed_string_t on;
7545 };
7546
7547 cmdline_parse_token_string_t cmd_mirror_link_set =
7548         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7549                                  set, "set");
7550 cmdline_parse_token_string_t cmd_mirror_link_port =
7551         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7552                                 port, "port");
7553 cmdline_parse_token_num_t cmd_mirror_link_portid =
7554         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7555                                 port_id, UINT8);
7556 cmdline_parse_token_string_t cmd_mirror_link_mirror =
7557         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7558                                 mirror, "mirror-rule");
7559 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7560         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7561                             rule_id, UINT8);
7562 cmdline_parse_token_string_t cmd_mirror_link_what =
7563         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7564                                 what, "uplink-mirror#downlink-mirror");
7565 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7566         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7567                                 dstpool, "dst-pool");
7568 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7569         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7570                                 dstpool_id, UINT8);
7571 cmdline_parse_token_string_t cmd_mirror_link_on =
7572         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7573                                 on, "on#off");
7574
7575 static void
7576 cmd_set_mirror_link_parsed(void *parsed_result,
7577                        __attribute__((unused)) struct cmdline *cl,
7578                        __attribute__((unused)) void *data)
7579 {
7580         int ret;
7581         struct cmd_set_mirror_link_result *res = parsed_result;
7582         struct rte_eth_mirror_conf mr_conf;
7583
7584         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7585         if (!strcmp(res->what, "uplink-mirror"))
7586                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
7587         else
7588                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
7589
7590         mr_conf.dst_pool = res->dstpool_id;
7591
7592         if (!strcmp(res->on, "on"))
7593                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7594                                                 res->rule_id, 1);
7595         else
7596                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7597                                                 res->rule_id, 0);
7598
7599         /* check the return value and print it if is < 0 */
7600         if (ret < 0)
7601                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7602
7603 }
7604
7605 cmdline_parse_inst_t cmd_set_mirror_link = {
7606                 .f = cmd_set_mirror_link_parsed,
7607                 .data = NULL,
7608                 .help_str = "set port <port_id> mirror-rule <rule_id> "
7609                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
7610                 .tokens = {
7611                         (void *)&cmd_mirror_link_set,
7612                         (void *)&cmd_mirror_link_port,
7613                         (void *)&cmd_mirror_link_portid,
7614                         (void *)&cmd_mirror_link_mirror,
7615                         (void *)&cmd_mirror_link_ruleid,
7616                         (void *)&cmd_mirror_link_what,
7617                         (void *)&cmd_mirror_link_dstpool,
7618                         (void *)&cmd_mirror_link_poolid,
7619                         (void *)&cmd_mirror_link_on,
7620                         NULL,
7621                 },
7622 };
7623
7624 /* *** RESET VM MIRROR RULE *** */
7625 struct cmd_rm_mirror_rule_result {
7626         cmdline_fixed_string_t reset;
7627         cmdline_fixed_string_t port;
7628         uint8_t port_id;
7629         cmdline_fixed_string_t mirror;
7630         uint8_t rule_id;
7631 };
7632
7633 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
7634         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7635                                  reset, "reset");
7636 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
7637         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7638                                 port, "port");
7639 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
7640         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7641                                 port_id, UINT8);
7642 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
7643         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7644                                 mirror, "mirror-rule");
7645 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
7646         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7647                                 rule_id, UINT8);
7648
7649 static void
7650 cmd_reset_mirror_rule_parsed(void *parsed_result,
7651                        __attribute__((unused)) struct cmdline *cl,
7652                        __attribute__((unused)) void *data)
7653 {
7654         int ret;
7655         struct cmd_set_mirror_link_result *res = parsed_result;
7656         /* check rule_id */
7657         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
7658         if(ret < 0)
7659                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
7660 }
7661
7662 cmdline_parse_inst_t cmd_reset_mirror_rule = {
7663                 .f = cmd_reset_mirror_rule_parsed,
7664                 .data = NULL,
7665                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
7666                 .tokens = {
7667                         (void *)&cmd_rm_mirror_rule_reset,
7668                         (void *)&cmd_rm_mirror_rule_port,
7669                         (void *)&cmd_rm_mirror_rule_portid,
7670                         (void *)&cmd_rm_mirror_rule_mirror,
7671                         (void *)&cmd_rm_mirror_rule_ruleid,
7672                         NULL,
7673                 },
7674 };
7675
7676 /* ******************************************************************************** */
7677
7678 struct cmd_dump_result {
7679         cmdline_fixed_string_t dump;
7680 };
7681
7682 static void
7683 dump_struct_sizes(void)
7684 {
7685 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
7686         DUMP_SIZE(struct rte_mbuf);
7687         DUMP_SIZE(struct rte_mempool);
7688         DUMP_SIZE(struct rte_ring);
7689 #undef DUMP_SIZE
7690 }
7691
7692 static void cmd_dump_parsed(void *parsed_result,
7693                             __attribute__((unused)) struct cmdline *cl,
7694                             __attribute__((unused)) void *data)
7695 {
7696         struct cmd_dump_result *res = parsed_result;
7697
7698         if (!strcmp(res->dump, "dump_physmem"))
7699                 rte_dump_physmem_layout(stdout);
7700         else if (!strcmp(res->dump, "dump_memzone"))
7701                 rte_memzone_dump(stdout);
7702         else if (!strcmp(res->dump, "dump_struct_sizes"))
7703                 dump_struct_sizes();
7704         else if (!strcmp(res->dump, "dump_ring"))
7705                 rte_ring_list_dump(stdout);
7706         else if (!strcmp(res->dump, "dump_mempool"))
7707                 rte_mempool_list_dump(stdout);
7708         else if (!strcmp(res->dump, "dump_devargs"))
7709                 rte_eal_devargs_dump(stdout);
7710         else if (!strcmp(res->dump, "dump_log_types"))
7711                 rte_log_dump(stdout);
7712 }
7713
7714 cmdline_parse_token_string_t cmd_dump_dump =
7715         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
7716                 "dump_physmem#"
7717                 "dump_memzone#"
7718                 "dump_struct_sizes#"
7719                 "dump_ring#"
7720                 "dump_mempool#"
7721                 "dump_devargs#"
7722                 "dump_log_types");
7723
7724 cmdline_parse_inst_t cmd_dump = {
7725         .f = cmd_dump_parsed,  /* function to call */
7726         .data = NULL,      /* 2nd arg of func */
7727         .help_str = "Dump status",
7728         .tokens = {        /* token list, NULL terminated */
7729                 (void *)&cmd_dump_dump,
7730                 NULL,
7731         },
7732 };
7733
7734 /* ******************************************************************************** */
7735
7736 struct cmd_dump_one_result {
7737         cmdline_fixed_string_t dump;
7738         cmdline_fixed_string_t name;
7739 };
7740
7741 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
7742                                 __attribute__((unused)) void *data)
7743 {
7744         struct cmd_dump_one_result *res = parsed_result;
7745
7746         if (!strcmp(res->dump, "dump_ring")) {
7747                 struct rte_ring *r;
7748                 r = rte_ring_lookup(res->name);
7749                 if (r == NULL) {
7750                         cmdline_printf(cl, "Cannot find ring\n");
7751                         return;
7752                 }
7753                 rte_ring_dump(stdout, r);
7754         } else if (!strcmp(res->dump, "dump_mempool")) {
7755                 struct rte_mempool *mp;
7756                 mp = rte_mempool_lookup(res->name);
7757                 if (mp == NULL) {
7758                         cmdline_printf(cl, "Cannot find mempool\n");
7759                         return;
7760                 }
7761                 rte_mempool_dump(stdout, mp);
7762         }
7763 }
7764
7765 cmdline_parse_token_string_t cmd_dump_one_dump =
7766         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
7767                                  "dump_ring#dump_mempool");
7768
7769 cmdline_parse_token_string_t cmd_dump_one_name =
7770         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
7771
7772 cmdline_parse_inst_t cmd_dump_one = {
7773         .f = cmd_dump_one_parsed,  /* function to call */
7774         .data = NULL,      /* 2nd arg of func */
7775         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
7776         .tokens = {        /* token list, NULL terminated */
7777                 (void *)&cmd_dump_one_dump,
7778                 (void *)&cmd_dump_one_name,
7779                 NULL,
7780         },
7781 };
7782
7783 /* *** Add/Del syn filter *** */
7784 struct cmd_syn_filter_result {
7785         cmdline_fixed_string_t filter;
7786         uint8_t port_id;
7787         cmdline_fixed_string_t ops;
7788         cmdline_fixed_string_t priority;
7789         cmdline_fixed_string_t high;
7790         cmdline_fixed_string_t queue;
7791         uint16_t queue_id;
7792 };
7793
7794 static void
7795 cmd_syn_filter_parsed(void *parsed_result,
7796                         __attribute__((unused)) struct cmdline *cl,
7797                         __attribute__((unused)) void *data)
7798 {
7799         struct cmd_syn_filter_result *res = parsed_result;
7800         struct rte_eth_syn_filter syn_filter;
7801         int ret = 0;
7802
7803         ret = rte_eth_dev_filter_supported(res->port_id,
7804                                         RTE_ETH_FILTER_SYN);
7805         if (ret < 0) {
7806                 printf("syn filter is not supported on port %u.\n",
7807                                 res->port_id);
7808                 return;
7809         }
7810
7811         memset(&syn_filter, 0, sizeof(syn_filter));
7812
7813         if (!strcmp(res->ops, "add")) {
7814                 if (!strcmp(res->high, "high"))
7815                         syn_filter.hig_pri = 1;
7816                 else
7817                         syn_filter.hig_pri = 0;
7818
7819                 syn_filter.queue = res->queue_id;
7820                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7821                                                 RTE_ETH_FILTER_SYN,
7822                                                 RTE_ETH_FILTER_ADD,
7823                                                 &syn_filter);
7824         } else
7825                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7826                                                 RTE_ETH_FILTER_SYN,
7827                                                 RTE_ETH_FILTER_DELETE,
7828                                                 &syn_filter);
7829
7830         if (ret < 0)
7831                 printf("syn filter programming error: (%s)\n",
7832                                 strerror(-ret));
7833 }
7834
7835 cmdline_parse_token_string_t cmd_syn_filter_filter =
7836         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7837         filter, "syn_filter");
7838 cmdline_parse_token_num_t cmd_syn_filter_port_id =
7839         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7840         port_id, UINT8);
7841 cmdline_parse_token_string_t cmd_syn_filter_ops =
7842         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7843         ops, "add#del");
7844 cmdline_parse_token_string_t cmd_syn_filter_priority =
7845         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7846                                 priority, "priority");
7847 cmdline_parse_token_string_t cmd_syn_filter_high =
7848         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7849                                 high, "high#low");
7850 cmdline_parse_token_string_t cmd_syn_filter_queue =
7851         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7852                                 queue, "queue");
7853 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
7854         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7855                                 queue_id, UINT16);
7856
7857 cmdline_parse_inst_t cmd_syn_filter = {
7858         .f = cmd_syn_filter_parsed,
7859         .data = NULL,
7860         .help_str = "syn_filter <port_id> add|del priority high|low queue "
7861                 "<queue_id>: Add/Delete syn filter",
7862         .tokens = {
7863                 (void *)&cmd_syn_filter_filter,
7864                 (void *)&cmd_syn_filter_port_id,
7865                 (void *)&cmd_syn_filter_ops,
7866                 (void *)&cmd_syn_filter_priority,
7867                 (void *)&cmd_syn_filter_high,
7868                 (void *)&cmd_syn_filter_queue,
7869                 (void *)&cmd_syn_filter_queue_id,
7870                 NULL,
7871         },
7872 };
7873
7874 /* *** ADD/REMOVE A 2tuple FILTER *** */
7875 struct cmd_2tuple_filter_result {
7876         cmdline_fixed_string_t filter;
7877         uint8_t  port_id;
7878         cmdline_fixed_string_t ops;
7879         cmdline_fixed_string_t dst_port;
7880         uint16_t dst_port_value;
7881         cmdline_fixed_string_t protocol;
7882         uint8_t protocol_value;
7883         cmdline_fixed_string_t mask;
7884         uint8_t  mask_value;
7885         cmdline_fixed_string_t tcp_flags;
7886         uint8_t tcp_flags_value;
7887         cmdline_fixed_string_t priority;
7888         uint8_t  priority_value;
7889         cmdline_fixed_string_t queue;
7890         uint16_t  queue_id;
7891 };
7892
7893 static void
7894 cmd_2tuple_filter_parsed(void *parsed_result,
7895                         __attribute__((unused)) struct cmdline *cl,
7896                         __attribute__((unused)) void *data)
7897 {
7898         struct rte_eth_ntuple_filter filter;
7899         struct cmd_2tuple_filter_result *res = parsed_result;
7900         int ret = 0;
7901
7902         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7903         if (ret < 0) {
7904                 printf("ntuple filter is not supported on port %u.\n",
7905                         res->port_id);
7906                 return;
7907         }
7908
7909         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7910
7911         filter.flags = RTE_2TUPLE_FLAGS;
7912         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7913         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7914         filter.proto = res->protocol_value;
7915         filter.priority = res->priority_value;
7916         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7917                 printf("nonzero tcp_flags is only meaningful"
7918                         " when protocol is TCP.\n");
7919                 return;
7920         }
7921         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7922                 printf("invalid TCP flags.\n");
7923                 return;
7924         }
7925
7926         if (res->tcp_flags_value != 0) {
7927                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7928                 filter.tcp_flags = res->tcp_flags_value;
7929         }
7930
7931         /* need convert to big endian. */
7932         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7933         filter.queue = res->queue_id;
7934
7935         if (!strcmp(res->ops, "add"))
7936                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7937                                 RTE_ETH_FILTER_NTUPLE,
7938                                 RTE_ETH_FILTER_ADD,
7939                                 &filter);
7940         else
7941                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7942                                 RTE_ETH_FILTER_NTUPLE,
7943                                 RTE_ETH_FILTER_DELETE,
7944                                 &filter);
7945         if (ret < 0)
7946                 printf("2tuple filter programming error: (%s)\n",
7947                         strerror(-ret));
7948
7949 }
7950
7951 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
7952         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7953                                  filter, "2tuple_filter");
7954 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
7955         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7956                                 port_id, UINT8);
7957 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
7958         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7959                                  ops, "add#del");
7960 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
7961         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7962                                 dst_port, "dst_port");
7963 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
7964         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7965                                 dst_port_value, UINT16);
7966 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
7967         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7968                                 protocol, "protocol");
7969 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
7970         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7971                                 protocol_value, UINT8);
7972 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
7973         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7974                                 mask, "mask");
7975 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
7976         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7977                                 mask_value, INT8);
7978 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
7979         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7980                                 tcp_flags, "tcp_flags");
7981 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
7982         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7983                                 tcp_flags_value, UINT8);
7984 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
7985         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7986                                 priority, "priority");
7987 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
7988         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7989                                 priority_value, UINT8);
7990 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
7991         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7992                                 queue, "queue");
7993 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
7994         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7995                                 queue_id, UINT16);
7996
7997 cmdline_parse_inst_t cmd_2tuple_filter = {
7998         .f = cmd_2tuple_filter_parsed,
7999         .data = NULL,
8000         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
8001                 "<value> mask <value> tcp_flags <value> priority <value> queue "
8002                 "<queue_id>: Add a 2tuple filter",
8003         .tokens = {
8004                 (void *)&cmd_2tuple_filter_filter,
8005                 (void *)&cmd_2tuple_filter_port_id,
8006                 (void *)&cmd_2tuple_filter_ops,
8007                 (void *)&cmd_2tuple_filter_dst_port,
8008                 (void *)&cmd_2tuple_filter_dst_port_value,
8009                 (void *)&cmd_2tuple_filter_protocol,
8010                 (void *)&cmd_2tuple_filter_protocol_value,
8011                 (void *)&cmd_2tuple_filter_mask,
8012                 (void *)&cmd_2tuple_filter_mask_value,
8013                 (void *)&cmd_2tuple_filter_tcp_flags,
8014                 (void *)&cmd_2tuple_filter_tcp_flags_value,
8015                 (void *)&cmd_2tuple_filter_priority,
8016                 (void *)&cmd_2tuple_filter_priority_value,
8017                 (void *)&cmd_2tuple_filter_queue,
8018                 (void *)&cmd_2tuple_filter_queue_id,
8019                 NULL,
8020         },
8021 };
8022
8023 /* *** ADD/REMOVE A 5tuple FILTER *** */
8024 struct cmd_5tuple_filter_result {
8025         cmdline_fixed_string_t filter;
8026         uint8_t  port_id;
8027         cmdline_fixed_string_t ops;
8028         cmdline_fixed_string_t dst_ip;
8029         cmdline_ipaddr_t dst_ip_value;
8030         cmdline_fixed_string_t src_ip;
8031         cmdline_ipaddr_t src_ip_value;
8032         cmdline_fixed_string_t dst_port;
8033         uint16_t dst_port_value;
8034         cmdline_fixed_string_t src_port;
8035         uint16_t src_port_value;
8036         cmdline_fixed_string_t protocol;
8037         uint8_t protocol_value;
8038         cmdline_fixed_string_t mask;
8039         uint8_t  mask_value;
8040         cmdline_fixed_string_t tcp_flags;
8041         uint8_t tcp_flags_value;
8042         cmdline_fixed_string_t priority;
8043         uint8_t  priority_value;
8044         cmdline_fixed_string_t queue;
8045         uint16_t  queue_id;
8046 };
8047
8048 static void
8049 cmd_5tuple_filter_parsed(void *parsed_result,
8050                         __attribute__((unused)) struct cmdline *cl,
8051                         __attribute__((unused)) void *data)
8052 {
8053         struct rte_eth_ntuple_filter filter;
8054         struct cmd_5tuple_filter_result *res = parsed_result;
8055         int ret = 0;
8056
8057         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8058         if (ret < 0) {
8059                 printf("ntuple filter is not supported on port %u.\n",
8060                         res->port_id);
8061                 return;
8062         }
8063
8064         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8065
8066         filter.flags = RTE_5TUPLE_FLAGS;
8067         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
8068         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
8069         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
8070         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8071         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8072         filter.proto = res->protocol_value;
8073         filter.priority = res->priority_value;
8074         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8075                 printf("nonzero tcp_flags is only meaningful"
8076                         " when protocol is TCP.\n");
8077                 return;
8078         }
8079         if (res->tcp_flags_value > TCP_FLAG_ALL) {
8080                 printf("invalid TCP flags.\n");
8081                 return;
8082         }
8083
8084         if (res->tcp_flags_value != 0) {
8085                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8086                 filter.tcp_flags = res->tcp_flags_value;
8087         }
8088
8089         if (res->dst_ip_value.family == AF_INET)
8090                 /* no need to convert, already big endian. */
8091                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
8092         else {
8093                 if (filter.dst_ip_mask == 0) {
8094                         printf("can not support ipv6 involved compare.\n");
8095                         return;
8096                 }
8097                 filter.dst_ip = 0;
8098         }
8099
8100         if (res->src_ip_value.family == AF_INET)
8101                 /* no need to convert, already big endian. */
8102                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
8103         else {
8104                 if (filter.src_ip_mask == 0) {
8105                         printf("can not support ipv6 involved compare.\n");
8106                         return;
8107                 }
8108                 filter.src_ip = 0;
8109         }
8110         /* need convert to big endian. */
8111         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8112         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
8113         filter.queue = res->queue_id;
8114
8115         if (!strcmp(res->ops, "add"))
8116                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8117                                 RTE_ETH_FILTER_NTUPLE,
8118                                 RTE_ETH_FILTER_ADD,
8119                                 &filter);
8120         else
8121                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8122                                 RTE_ETH_FILTER_NTUPLE,
8123                                 RTE_ETH_FILTER_DELETE,
8124                                 &filter);
8125         if (ret < 0)
8126                 printf("5tuple filter programming error: (%s)\n",
8127                         strerror(-ret));
8128 }
8129
8130 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
8131         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8132                                  filter, "5tuple_filter");
8133 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
8134         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8135                                 port_id, UINT8);
8136 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
8137         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8138                                  ops, "add#del");
8139 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
8140         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8141                                 dst_ip, "dst_ip");
8142 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
8143         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8144                                 dst_ip_value);
8145 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
8146         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8147                                 src_ip, "src_ip");
8148 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
8149         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8150                                 src_ip_value);
8151 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
8152         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8153                                 dst_port, "dst_port");
8154 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
8155         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8156                                 dst_port_value, UINT16);
8157 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
8158         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8159                                 src_port, "src_port");
8160 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
8161         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8162                                 src_port_value, UINT16);
8163 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
8164         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8165                                 protocol, "protocol");
8166 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
8167         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8168                                 protocol_value, UINT8);
8169 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
8170         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8171                                 mask, "mask");
8172 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
8173         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8174                                 mask_value, INT8);
8175 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
8176         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8177                                 tcp_flags, "tcp_flags");
8178 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
8179         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8180                                 tcp_flags_value, UINT8);
8181 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
8182         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8183                                 priority, "priority");
8184 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
8185         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8186                                 priority_value, UINT8);
8187 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
8188         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8189                                 queue, "queue");
8190 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
8191         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8192                                 queue_id, UINT16);
8193
8194 cmdline_parse_inst_t cmd_5tuple_filter = {
8195         .f = cmd_5tuple_filter_parsed,
8196         .data = NULL,
8197         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
8198                 "src_ip <value> dst_port <value> src_port <value> "
8199                 "protocol <value>  mask <value> tcp_flags <value> "
8200                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
8201         .tokens = {
8202                 (void *)&cmd_5tuple_filter_filter,
8203                 (void *)&cmd_5tuple_filter_port_id,
8204                 (void *)&cmd_5tuple_filter_ops,
8205                 (void *)&cmd_5tuple_filter_dst_ip,
8206                 (void *)&cmd_5tuple_filter_dst_ip_value,
8207                 (void *)&cmd_5tuple_filter_src_ip,
8208                 (void *)&cmd_5tuple_filter_src_ip_value,
8209                 (void *)&cmd_5tuple_filter_dst_port,
8210                 (void *)&cmd_5tuple_filter_dst_port_value,
8211                 (void *)&cmd_5tuple_filter_src_port,
8212                 (void *)&cmd_5tuple_filter_src_port_value,
8213                 (void *)&cmd_5tuple_filter_protocol,
8214                 (void *)&cmd_5tuple_filter_protocol_value,
8215                 (void *)&cmd_5tuple_filter_mask,
8216                 (void *)&cmd_5tuple_filter_mask_value,
8217                 (void *)&cmd_5tuple_filter_tcp_flags,
8218                 (void *)&cmd_5tuple_filter_tcp_flags_value,
8219                 (void *)&cmd_5tuple_filter_priority,
8220                 (void *)&cmd_5tuple_filter_priority_value,
8221                 (void *)&cmd_5tuple_filter_queue,
8222                 (void *)&cmd_5tuple_filter_queue_id,
8223                 NULL,
8224         },
8225 };
8226
8227 /* *** ADD/REMOVE A flex FILTER *** */
8228 struct cmd_flex_filter_result {
8229         cmdline_fixed_string_t filter;
8230         cmdline_fixed_string_t ops;
8231         uint8_t port_id;
8232         cmdline_fixed_string_t len;
8233         uint8_t len_value;
8234         cmdline_fixed_string_t bytes;
8235         cmdline_fixed_string_t bytes_value;
8236         cmdline_fixed_string_t mask;
8237         cmdline_fixed_string_t mask_value;
8238         cmdline_fixed_string_t priority;
8239         uint8_t priority_value;
8240         cmdline_fixed_string_t queue;
8241         uint16_t queue_id;
8242 };
8243
8244 static int xdigit2val(unsigned char c)
8245 {
8246         int val;
8247         if (isdigit(c))
8248                 val = c - '0';
8249         else if (isupper(c))
8250                 val = c - 'A' + 10;
8251         else
8252                 val = c - 'a' + 10;
8253         return val;
8254 }
8255
8256 static void
8257 cmd_flex_filter_parsed(void *parsed_result,
8258                           __attribute__((unused)) struct cmdline *cl,
8259                           __attribute__((unused)) void *data)
8260 {
8261         int ret = 0;
8262         struct rte_eth_flex_filter filter;
8263         struct cmd_flex_filter_result *res = parsed_result;
8264         char *bytes_ptr, *mask_ptr;
8265         uint16_t len, i, j = 0;
8266         char c;
8267         int val;
8268         uint8_t byte = 0;
8269
8270         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
8271                 printf("the len exceed the max length 128\n");
8272                 return;
8273         }
8274         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
8275         filter.len = res->len_value;
8276         filter.priority = res->priority_value;
8277         filter.queue = res->queue_id;
8278         bytes_ptr = res->bytes_value;
8279         mask_ptr = res->mask_value;
8280
8281          /* translate bytes string to array. */
8282         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
8283                 (bytes_ptr[1] == 'X')))
8284                 bytes_ptr += 2;
8285         len = strnlen(bytes_ptr, res->len_value * 2);
8286         if (len == 0 || (len % 8 != 0)) {
8287                 printf("please check len and bytes input\n");
8288                 return;
8289         }
8290         for (i = 0; i < len; i++) {
8291                 c = bytes_ptr[i];
8292                 if (isxdigit(c) == 0) {
8293                         /* invalid characters. */
8294                         printf("invalid input\n");
8295                         return;
8296                 }
8297                 val = xdigit2val(c);
8298                 if (i % 2) {
8299                         byte |= val;
8300                         filter.bytes[j] = byte;
8301                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
8302                         j++;
8303                         byte = 0;
8304                 } else
8305                         byte |= val << 4;
8306         }
8307         printf("\n");
8308          /* translate mask string to uint8_t array. */
8309         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
8310                 (mask_ptr[1] == 'X')))
8311                 mask_ptr += 2;
8312         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
8313         if (len == 0) {
8314                 printf("invalid input\n");
8315                 return;
8316         }
8317         j = 0;
8318         byte = 0;
8319         for (i = 0; i < len; i++) {
8320                 c = mask_ptr[i];
8321                 if (isxdigit(c) == 0) {
8322                         /* invalid characters. */
8323                         printf("invalid input\n");
8324                         return;
8325                 }
8326                 val = xdigit2val(c);
8327                 if (i % 2) {
8328                         byte |= val;
8329                         filter.mask[j] = byte;
8330                         printf("mask[%d]:%02x ", j, filter.mask[j]);
8331                         j++;
8332                         byte = 0;
8333                 } else
8334                         byte |= val << 4;
8335         }
8336         printf("\n");
8337
8338         if (!strcmp(res->ops, "add"))
8339                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8340                                 RTE_ETH_FILTER_FLEXIBLE,
8341                                 RTE_ETH_FILTER_ADD,
8342                                 &filter);
8343         else
8344                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8345                                 RTE_ETH_FILTER_FLEXIBLE,
8346                                 RTE_ETH_FILTER_DELETE,
8347                                 &filter);
8348
8349         if (ret < 0)
8350                 printf("flex filter setting error: (%s)\n", strerror(-ret));
8351 }
8352
8353 cmdline_parse_token_string_t cmd_flex_filter_filter =
8354         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8355                                 filter, "flex_filter");
8356 cmdline_parse_token_num_t cmd_flex_filter_port_id =
8357         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8358                                 port_id, UINT8);
8359 cmdline_parse_token_string_t cmd_flex_filter_ops =
8360         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8361                                 ops, "add#del");
8362 cmdline_parse_token_string_t cmd_flex_filter_len =
8363         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8364                                 len, "len");
8365 cmdline_parse_token_num_t cmd_flex_filter_len_value =
8366         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8367                                 len_value, UINT8);
8368 cmdline_parse_token_string_t cmd_flex_filter_bytes =
8369         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8370                                 bytes, "bytes");
8371 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
8372         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8373                                 bytes_value, NULL);
8374 cmdline_parse_token_string_t cmd_flex_filter_mask =
8375         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8376                                 mask, "mask");
8377 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
8378         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8379                                 mask_value, NULL);
8380 cmdline_parse_token_string_t cmd_flex_filter_priority =
8381         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8382                                 priority, "priority");
8383 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
8384         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8385                                 priority_value, UINT8);
8386 cmdline_parse_token_string_t cmd_flex_filter_queue =
8387         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8388                                 queue, "queue");
8389 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
8390         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8391                                 queue_id, UINT16);
8392 cmdline_parse_inst_t cmd_flex_filter = {
8393         .f = cmd_flex_filter_parsed,
8394         .data = NULL,
8395         .help_str = "flex_filter <port_id> add|del len <value> bytes "
8396                 "<value> mask <value> priority <value> queue <queue_id>: "
8397                 "Add/Del a flex filter",
8398         .tokens = {
8399                 (void *)&cmd_flex_filter_filter,
8400                 (void *)&cmd_flex_filter_port_id,
8401                 (void *)&cmd_flex_filter_ops,
8402                 (void *)&cmd_flex_filter_len,
8403                 (void *)&cmd_flex_filter_len_value,
8404                 (void *)&cmd_flex_filter_bytes,
8405                 (void *)&cmd_flex_filter_bytes_value,
8406                 (void *)&cmd_flex_filter_mask,
8407                 (void *)&cmd_flex_filter_mask_value,
8408                 (void *)&cmd_flex_filter_priority,
8409                 (void *)&cmd_flex_filter_priority_value,
8410                 (void *)&cmd_flex_filter_queue,
8411                 (void *)&cmd_flex_filter_queue_id,
8412                 NULL,
8413         },
8414 };
8415
8416 /* *** Filters Control *** */
8417
8418 /* *** deal with ethertype filter *** */
8419 struct cmd_ethertype_filter_result {
8420         cmdline_fixed_string_t filter;
8421         uint8_t port_id;
8422         cmdline_fixed_string_t ops;
8423         cmdline_fixed_string_t mac;
8424         struct ether_addr mac_addr;
8425         cmdline_fixed_string_t ethertype;
8426         uint16_t ethertype_value;
8427         cmdline_fixed_string_t drop;
8428         cmdline_fixed_string_t queue;
8429         uint16_t  queue_id;
8430 };
8431
8432 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
8433         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8434                                  filter, "ethertype_filter");
8435 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
8436         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8437                               port_id, UINT8);
8438 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
8439         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8440                                  ops, "add#del");
8441 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
8442         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8443                                  mac, "mac_addr#mac_ignr");
8444 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
8445         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
8446                                      mac_addr);
8447 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
8448         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8449                                  ethertype, "ethertype");
8450 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
8451         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8452                               ethertype_value, UINT16);
8453 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
8454         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8455                                  drop, "drop#fwd");
8456 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
8457         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8458                                  queue, "queue");
8459 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
8460         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8461                               queue_id, UINT16);
8462
8463 static void
8464 cmd_ethertype_filter_parsed(void *parsed_result,
8465                           __attribute__((unused)) struct cmdline *cl,
8466                           __attribute__((unused)) void *data)
8467 {
8468         struct cmd_ethertype_filter_result *res = parsed_result;
8469         struct rte_eth_ethertype_filter filter;
8470         int ret = 0;
8471
8472         ret = rte_eth_dev_filter_supported(res->port_id,
8473                         RTE_ETH_FILTER_ETHERTYPE);
8474         if (ret < 0) {
8475                 printf("ethertype filter is not supported on port %u.\n",
8476                         res->port_id);
8477                 return;
8478         }
8479
8480         memset(&filter, 0, sizeof(filter));
8481         if (!strcmp(res->mac, "mac_addr")) {
8482                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
8483                 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr,
8484                         sizeof(struct ether_addr));
8485         }
8486         if (!strcmp(res->drop, "drop"))
8487                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
8488         filter.ether_type = res->ethertype_value;
8489         filter.queue = res->queue_id;
8490
8491         if (!strcmp(res->ops, "add"))
8492                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8493                                 RTE_ETH_FILTER_ETHERTYPE,
8494                                 RTE_ETH_FILTER_ADD,
8495                                 &filter);
8496         else
8497                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8498                                 RTE_ETH_FILTER_ETHERTYPE,
8499                                 RTE_ETH_FILTER_DELETE,
8500                                 &filter);
8501         if (ret < 0)
8502                 printf("ethertype filter programming error: (%s)\n",
8503                         strerror(-ret));
8504 }
8505
8506 cmdline_parse_inst_t cmd_ethertype_filter = {
8507         .f = cmd_ethertype_filter_parsed,
8508         .data = NULL,
8509         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
8510                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
8511                 "Add or delete an ethertype filter entry",
8512         .tokens = {
8513                 (void *)&cmd_ethertype_filter_filter,
8514                 (void *)&cmd_ethertype_filter_port_id,
8515                 (void *)&cmd_ethertype_filter_ops,
8516                 (void *)&cmd_ethertype_filter_mac,
8517                 (void *)&cmd_ethertype_filter_mac_addr,
8518                 (void *)&cmd_ethertype_filter_ethertype,
8519                 (void *)&cmd_ethertype_filter_ethertype_value,
8520                 (void *)&cmd_ethertype_filter_drop,
8521                 (void *)&cmd_ethertype_filter_queue,
8522                 (void *)&cmd_ethertype_filter_queue_id,
8523                 NULL,
8524         },
8525 };
8526
8527 /* *** deal with flow director filter *** */
8528 struct cmd_flow_director_result {
8529         cmdline_fixed_string_t flow_director_filter;
8530         uint8_t port_id;
8531         cmdline_fixed_string_t mode;
8532         cmdline_fixed_string_t mode_value;
8533         cmdline_fixed_string_t ops;
8534         cmdline_fixed_string_t flow;
8535         cmdline_fixed_string_t flow_type;
8536         cmdline_fixed_string_t ether;
8537         uint16_t ether_type;
8538         cmdline_fixed_string_t src;
8539         cmdline_ipaddr_t ip_src;
8540         uint16_t port_src;
8541         cmdline_fixed_string_t dst;
8542         cmdline_ipaddr_t ip_dst;
8543         uint16_t port_dst;
8544         cmdline_fixed_string_t verify_tag;
8545         uint32_t verify_tag_value;
8546         cmdline_ipaddr_t tos;
8547         uint8_t tos_value;
8548         cmdline_ipaddr_t proto;
8549         uint8_t proto_value;
8550         cmdline_ipaddr_t ttl;
8551         uint8_t ttl_value;
8552         cmdline_fixed_string_t vlan;
8553         uint16_t vlan_value;
8554         cmdline_fixed_string_t flexbytes;
8555         cmdline_fixed_string_t flexbytes_value;
8556         cmdline_fixed_string_t pf_vf;
8557         cmdline_fixed_string_t drop;
8558         cmdline_fixed_string_t queue;
8559         uint16_t  queue_id;
8560         cmdline_fixed_string_t fd_id;
8561         uint32_t  fd_id_value;
8562         cmdline_fixed_string_t mac;
8563         struct ether_addr mac_addr;
8564         cmdline_fixed_string_t tunnel;
8565         cmdline_fixed_string_t tunnel_type;
8566         cmdline_fixed_string_t tunnel_id;
8567         uint32_t tunnel_id_value;
8568 };
8569
8570 static inline int
8571 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
8572 {
8573         char s[256];
8574         const char *p, *p0 = q_arg;
8575         char *end;
8576         unsigned long int_fld;
8577         char *str_fld[max_num];
8578         int i;
8579         unsigned size;
8580         int ret = -1;
8581
8582         p = strchr(p0, '(');
8583         if (p == NULL)
8584                 return -1;
8585         ++p;
8586         p0 = strchr(p, ')');
8587         if (p0 == NULL)
8588                 return -1;
8589
8590         size = p0 - p;
8591         if (size >= sizeof(s))
8592                 return -1;
8593
8594         snprintf(s, sizeof(s), "%.*s", size, p);
8595         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8596         if (ret < 0 || ret > max_num)
8597                 return -1;
8598         for (i = 0; i < ret; i++) {
8599                 errno = 0;
8600                 int_fld = strtoul(str_fld[i], &end, 0);
8601                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
8602                         return -1;
8603                 flexbytes[i] = (uint8_t)int_fld;
8604         }
8605         return ret;
8606 }
8607
8608 static uint16_t
8609 str2flowtype(char *string)
8610 {
8611         uint8_t i = 0;
8612         static const struct {
8613                 char str[32];
8614                 uint16_t type;
8615         } flowtype_str[] = {
8616                 {"raw", RTE_ETH_FLOW_RAW},
8617                 {"ipv4", RTE_ETH_FLOW_IPV4},
8618                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
8619                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
8620                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
8621                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
8622                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
8623                 {"ipv6", RTE_ETH_FLOW_IPV6},
8624                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
8625                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
8626                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
8627                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
8628                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
8629                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
8630         };
8631
8632         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
8633                 if (!strcmp(flowtype_str[i].str, string))
8634                         return flowtype_str[i].type;
8635         }
8636         return RTE_ETH_FLOW_UNKNOWN;
8637 }
8638
8639 static enum rte_eth_fdir_tunnel_type
8640 str2fdir_tunneltype(char *string)
8641 {
8642         uint8_t i = 0;
8643
8644         static const struct {
8645                 char str[32];
8646                 enum rte_eth_fdir_tunnel_type type;
8647         } tunneltype_str[] = {
8648                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
8649                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
8650         };
8651
8652         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
8653                 if (!strcmp(tunneltype_str[i].str, string))
8654                         return tunneltype_str[i].type;
8655         }
8656         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
8657 }
8658
8659 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
8660 do { \
8661         if ((ip_addr).family == AF_INET) \
8662                 (ip) = (ip_addr).addr.ipv4.s_addr; \
8663         else { \
8664                 printf("invalid parameter.\n"); \
8665                 return; \
8666         } \
8667 } while (0)
8668
8669 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
8670 do { \
8671         if ((ip_addr).family == AF_INET6) \
8672                 (void)rte_memcpy(&(ip), \
8673                                  &((ip_addr).addr.ipv6), \
8674                                  sizeof(struct in6_addr)); \
8675         else { \
8676                 printf("invalid parameter.\n"); \
8677                 return; \
8678         } \
8679 } while (0)
8680
8681 static void
8682 cmd_flow_director_filter_parsed(void *parsed_result,
8683                           __attribute__((unused)) struct cmdline *cl,
8684                           __attribute__((unused)) void *data)
8685 {
8686         struct cmd_flow_director_result *res = parsed_result;
8687         struct rte_eth_fdir_filter entry;
8688         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
8689         char *end;
8690         unsigned long vf_id;
8691         int ret = 0;
8692
8693         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8694         if (ret < 0) {
8695                 printf("flow director is not supported on port %u.\n",
8696                         res->port_id);
8697                 return;
8698         }
8699         memset(flexbytes, 0, sizeof(flexbytes));
8700         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
8701
8702         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
8703                 if (strcmp(res->mode_value, "MAC-VLAN")) {
8704                         printf("Please set mode to MAC-VLAN.\n");
8705                         return;
8706                 }
8707         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8708                 if (strcmp(res->mode_value, "Tunnel")) {
8709                         printf("Please set mode to Tunnel.\n");
8710                         return;
8711                 }
8712         } else {
8713                 if (strcmp(res->mode_value, "IP")) {
8714                         printf("Please set mode to IP.\n");
8715                         return;
8716                 }
8717                 entry.input.flow_type = str2flowtype(res->flow_type);
8718         }
8719
8720         ret = parse_flexbytes(res->flexbytes_value,
8721                                         flexbytes,
8722                                         RTE_ETH_FDIR_MAX_FLEXLEN);
8723         if (ret < 0) {
8724                 printf("error: Cannot parse flexbytes input.\n");
8725                 return;
8726         }
8727
8728         switch (entry.input.flow_type) {
8729         case RTE_ETH_FLOW_FRAG_IPV4:
8730         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
8731                 entry.input.flow.ip4_flow.proto = res->proto_value;
8732         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
8733         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
8734                 IPV4_ADDR_TO_UINT(res->ip_dst,
8735                         entry.input.flow.ip4_flow.dst_ip);
8736                 IPV4_ADDR_TO_UINT(res->ip_src,
8737                         entry.input.flow.ip4_flow.src_ip);
8738                 entry.input.flow.ip4_flow.tos = res->tos_value;
8739                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
8740                 /* need convert to big endian. */
8741                 entry.input.flow.udp4_flow.dst_port =
8742                                 rte_cpu_to_be_16(res->port_dst);
8743                 entry.input.flow.udp4_flow.src_port =
8744                                 rte_cpu_to_be_16(res->port_src);
8745                 break;
8746         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
8747                 IPV4_ADDR_TO_UINT(res->ip_dst,
8748                         entry.input.flow.sctp4_flow.ip.dst_ip);
8749                 IPV4_ADDR_TO_UINT(res->ip_src,
8750                         entry.input.flow.sctp4_flow.ip.src_ip);
8751                 entry.input.flow.ip4_flow.tos = res->tos_value;
8752                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
8753                 /* need convert to big endian. */
8754                 entry.input.flow.sctp4_flow.dst_port =
8755                                 rte_cpu_to_be_16(res->port_dst);
8756                 entry.input.flow.sctp4_flow.src_port =
8757                                 rte_cpu_to_be_16(res->port_src);
8758                 entry.input.flow.sctp4_flow.verify_tag =
8759                                 rte_cpu_to_be_32(res->verify_tag_value);
8760                 break;
8761         case RTE_ETH_FLOW_FRAG_IPV6:
8762         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
8763                 entry.input.flow.ipv6_flow.proto = res->proto_value;
8764         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
8765         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
8766                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8767                         entry.input.flow.ipv6_flow.dst_ip);
8768                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8769                         entry.input.flow.ipv6_flow.src_ip);
8770                 entry.input.flow.ipv6_flow.tc = res->tos_value;
8771                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
8772                 /* need convert to big endian. */
8773                 entry.input.flow.udp6_flow.dst_port =
8774                                 rte_cpu_to_be_16(res->port_dst);
8775                 entry.input.flow.udp6_flow.src_port =
8776                                 rte_cpu_to_be_16(res->port_src);
8777                 break;
8778         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
8779                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8780                         entry.input.flow.sctp6_flow.ip.dst_ip);
8781                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8782                         entry.input.flow.sctp6_flow.ip.src_ip);
8783                 entry.input.flow.ipv6_flow.tc = res->tos_value;
8784                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
8785                 /* need convert to big endian. */
8786                 entry.input.flow.sctp6_flow.dst_port =
8787                                 rte_cpu_to_be_16(res->port_dst);
8788                 entry.input.flow.sctp6_flow.src_port =
8789                                 rte_cpu_to_be_16(res->port_src);
8790                 entry.input.flow.sctp6_flow.verify_tag =
8791                                 rte_cpu_to_be_32(res->verify_tag_value);
8792                 break;
8793         case RTE_ETH_FLOW_L2_PAYLOAD:
8794                 entry.input.flow.l2_flow.ether_type =
8795                         rte_cpu_to_be_16(res->ether_type);
8796                 break;
8797         default:
8798                 break;
8799         }
8800
8801         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
8802                 (void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
8803                                  &res->mac_addr,
8804                                  sizeof(struct ether_addr));
8805
8806         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8807                 (void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
8808                                  &res->mac_addr,
8809                                  sizeof(struct ether_addr));
8810                 entry.input.flow.tunnel_flow.tunnel_type =
8811                         str2fdir_tunneltype(res->tunnel_type);
8812                 entry.input.flow.tunnel_flow.tunnel_id =
8813                         rte_cpu_to_be_32(res->tunnel_id_value);
8814         }
8815
8816         (void)rte_memcpy(entry.input.flow_ext.flexbytes,
8817                    flexbytes,
8818                    RTE_ETH_FDIR_MAX_FLEXLEN);
8819
8820         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
8821
8822         entry.action.flex_off = 0;  /*use 0 by default */
8823         if (!strcmp(res->drop, "drop"))
8824                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
8825         else
8826                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
8827
8828         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
8829             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8830                 if (!strcmp(res->pf_vf, "pf"))
8831                         entry.input.flow_ext.is_vf = 0;
8832                 else if (!strncmp(res->pf_vf, "vf", 2)) {
8833                         struct rte_eth_dev_info dev_info;
8834
8835                         memset(&dev_info, 0, sizeof(dev_info));
8836                         rte_eth_dev_info_get(res->port_id, &dev_info);
8837                         errno = 0;
8838                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
8839                         if (errno != 0 || *end != '\0' ||
8840                             vf_id >= dev_info.max_vfs) {
8841                                 printf("invalid parameter %s.\n", res->pf_vf);
8842                                 return;
8843                         }
8844                         entry.input.flow_ext.is_vf = 1;
8845                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
8846                 } else {
8847                         printf("invalid parameter %s.\n", res->pf_vf);
8848                         return;
8849                 }
8850         }
8851
8852         /* set to report FD ID by default */
8853         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
8854         entry.action.rx_queue = res->queue_id;
8855         entry.soft_id = res->fd_id_value;
8856         if (!strcmp(res->ops, "add"))
8857                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8858                                              RTE_ETH_FILTER_ADD, &entry);
8859         else if (!strcmp(res->ops, "del"))
8860                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8861                                              RTE_ETH_FILTER_DELETE, &entry);
8862         else
8863                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8864                                              RTE_ETH_FILTER_UPDATE, &entry);
8865         if (ret < 0)
8866                 printf("flow director programming error: (%s)\n",
8867                         strerror(-ret));
8868 }
8869
8870 cmdline_parse_token_string_t cmd_flow_director_filter =
8871         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8872                                  flow_director_filter, "flow_director_filter");
8873 cmdline_parse_token_num_t cmd_flow_director_port_id =
8874         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8875                               port_id, UINT8);
8876 cmdline_parse_token_string_t cmd_flow_director_ops =
8877         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8878                                  ops, "add#del#update");
8879 cmdline_parse_token_string_t cmd_flow_director_flow =
8880         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8881                                  flow, "flow");
8882 cmdline_parse_token_string_t cmd_flow_director_flow_type =
8883         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8884                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
8885                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
8886 cmdline_parse_token_string_t cmd_flow_director_ether =
8887         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8888                                  ether, "ether");
8889 cmdline_parse_token_num_t cmd_flow_director_ether_type =
8890         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8891                               ether_type, UINT16);
8892 cmdline_parse_token_string_t cmd_flow_director_src =
8893         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8894                                  src, "src");
8895 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
8896         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8897                                  ip_src);
8898 cmdline_parse_token_num_t cmd_flow_director_port_src =
8899         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8900                               port_src, UINT16);
8901 cmdline_parse_token_string_t cmd_flow_director_dst =
8902         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8903                                  dst, "dst");
8904 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
8905         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8906                                  ip_dst);
8907 cmdline_parse_token_num_t cmd_flow_director_port_dst =
8908         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8909                               port_dst, UINT16);
8910 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
8911         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8912                                   verify_tag, "verify_tag");
8913 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
8914         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8915                               verify_tag_value, UINT32);
8916 cmdline_parse_token_string_t cmd_flow_director_tos =
8917         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8918                                  tos, "tos");
8919 cmdline_parse_token_num_t cmd_flow_director_tos_value =
8920         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8921                               tos_value, UINT8);
8922 cmdline_parse_token_string_t cmd_flow_director_proto =
8923         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8924                                  proto, "proto");
8925 cmdline_parse_token_num_t cmd_flow_director_proto_value =
8926         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8927                               proto_value, UINT8);
8928 cmdline_parse_token_string_t cmd_flow_director_ttl =
8929         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8930                                  ttl, "ttl");
8931 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
8932         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8933                               ttl_value, UINT8);
8934 cmdline_parse_token_string_t cmd_flow_director_vlan =
8935         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8936                                  vlan, "vlan");
8937 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
8938         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8939                               vlan_value, UINT16);
8940 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
8941         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8942                                  flexbytes, "flexbytes");
8943 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
8944         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8945                               flexbytes_value, NULL);
8946 cmdline_parse_token_string_t cmd_flow_director_drop =
8947         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8948                                  drop, "drop#fwd");
8949 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
8950         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8951                               pf_vf, NULL);
8952 cmdline_parse_token_string_t cmd_flow_director_queue =
8953         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8954                                  queue, "queue");
8955 cmdline_parse_token_num_t cmd_flow_director_queue_id =
8956         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8957                               queue_id, UINT16);
8958 cmdline_parse_token_string_t cmd_flow_director_fd_id =
8959         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8960                                  fd_id, "fd_id");
8961 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
8962         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8963                               fd_id_value, UINT32);
8964
8965 cmdline_parse_token_string_t cmd_flow_director_mode =
8966         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8967                                  mode, "mode");
8968 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
8969         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8970                                  mode_value, "IP");
8971 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
8972         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8973                                  mode_value, "MAC-VLAN");
8974 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
8975         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8976                                  mode_value, "Tunnel");
8977 cmdline_parse_token_string_t cmd_flow_director_mac =
8978         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8979                                  mac, "mac");
8980 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
8981         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
8982                                     mac_addr);
8983 cmdline_parse_token_string_t cmd_flow_director_tunnel =
8984         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8985                                  tunnel, "tunnel");
8986 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
8987         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8988                                  tunnel_type, "NVGRE#VxLAN");
8989 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
8990         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8991                                  tunnel_id, "tunnel-id");
8992 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
8993         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8994                               tunnel_id_value, UINT32);
8995
8996 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
8997         .f = cmd_flow_director_filter_parsed,
8998         .data = NULL,
8999         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
9000                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
9001                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
9002                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
9003                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
9004                 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
9005                 "fd_id <fd_id_value>: "
9006                 "Add or delete an ip flow director entry on NIC",
9007         .tokens = {
9008                 (void *)&cmd_flow_director_filter,
9009                 (void *)&cmd_flow_director_port_id,
9010                 (void *)&cmd_flow_director_mode,
9011                 (void *)&cmd_flow_director_mode_ip,
9012                 (void *)&cmd_flow_director_ops,
9013                 (void *)&cmd_flow_director_flow,
9014                 (void *)&cmd_flow_director_flow_type,
9015                 (void *)&cmd_flow_director_src,
9016                 (void *)&cmd_flow_director_ip_src,
9017                 (void *)&cmd_flow_director_dst,
9018                 (void *)&cmd_flow_director_ip_dst,
9019                 (void *)&cmd_flow_director_tos,
9020                 (void *)&cmd_flow_director_tos_value,
9021                 (void *)&cmd_flow_director_proto,
9022                 (void *)&cmd_flow_director_proto_value,
9023                 (void *)&cmd_flow_director_ttl,
9024                 (void *)&cmd_flow_director_ttl_value,
9025                 (void *)&cmd_flow_director_vlan,
9026                 (void *)&cmd_flow_director_vlan_value,
9027                 (void *)&cmd_flow_director_flexbytes,
9028                 (void *)&cmd_flow_director_flexbytes_value,
9029                 (void *)&cmd_flow_director_drop,
9030                 (void *)&cmd_flow_director_pf_vf,
9031                 (void *)&cmd_flow_director_queue,
9032                 (void *)&cmd_flow_director_queue_id,
9033                 (void *)&cmd_flow_director_fd_id,
9034                 (void *)&cmd_flow_director_fd_id_value,
9035                 NULL,
9036         },
9037 };
9038
9039 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
9040         .f = cmd_flow_director_filter_parsed,
9041         .data = NULL,
9042         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
9043                 "director entry on NIC",
9044         .tokens = {
9045                 (void *)&cmd_flow_director_filter,
9046                 (void *)&cmd_flow_director_port_id,
9047                 (void *)&cmd_flow_director_mode,
9048                 (void *)&cmd_flow_director_mode_ip,
9049                 (void *)&cmd_flow_director_ops,
9050                 (void *)&cmd_flow_director_flow,
9051                 (void *)&cmd_flow_director_flow_type,
9052                 (void *)&cmd_flow_director_src,
9053                 (void *)&cmd_flow_director_ip_src,
9054                 (void *)&cmd_flow_director_port_src,
9055                 (void *)&cmd_flow_director_dst,
9056                 (void *)&cmd_flow_director_ip_dst,
9057                 (void *)&cmd_flow_director_port_dst,
9058                 (void *)&cmd_flow_director_tos,
9059                 (void *)&cmd_flow_director_tos_value,
9060                 (void *)&cmd_flow_director_ttl,
9061                 (void *)&cmd_flow_director_ttl_value,
9062                 (void *)&cmd_flow_director_vlan,
9063                 (void *)&cmd_flow_director_vlan_value,
9064                 (void *)&cmd_flow_director_flexbytes,
9065                 (void *)&cmd_flow_director_flexbytes_value,
9066                 (void *)&cmd_flow_director_drop,
9067                 (void *)&cmd_flow_director_pf_vf,
9068                 (void *)&cmd_flow_director_queue,
9069                 (void *)&cmd_flow_director_queue_id,
9070                 (void *)&cmd_flow_director_fd_id,
9071                 (void *)&cmd_flow_director_fd_id_value,
9072                 NULL,
9073         },
9074 };
9075
9076 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
9077         .f = cmd_flow_director_filter_parsed,
9078         .data = NULL,
9079         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
9080                 "director entry on NIC",
9081         .tokens = {
9082                 (void *)&cmd_flow_director_filter,
9083                 (void *)&cmd_flow_director_port_id,
9084                 (void *)&cmd_flow_director_mode,
9085                 (void *)&cmd_flow_director_mode_ip,
9086                 (void *)&cmd_flow_director_ops,
9087                 (void *)&cmd_flow_director_flow,
9088                 (void *)&cmd_flow_director_flow_type,
9089                 (void *)&cmd_flow_director_src,
9090                 (void *)&cmd_flow_director_ip_src,
9091                 (void *)&cmd_flow_director_port_dst,
9092                 (void *)&cmd_flow_director_dst,
9093                 (void *)&cmd_flow_director_ip_dst,
9094                 (void *)&cmd_flow_director_port_dst,
9095                 (void *)&cmd_flow_director_verify_tag,
9096                 (void *)&cmd_flow_director_verify_tag_value,
9097                 (void *)&cmd_flow_director_tos,
9098                 (void *)&cmd_flow_director_tos_value,
9099                 (void *)&cmd_flow_director_ttl,
9100                 (void *)&cmd_flow_director_ttl_value,
9101                 (void *)&cmd_flow_director_vlan,
9102                 (void *)&cmd_flow_director_vlan_value,
9103                 (void *)&cmd_flow_director_flexbytes,
9104                 (void *)&cmd_flow_director_flexbytes_value,
9105                 (void *)&cmd_flow_director_drop,
9106                 (void *)&cmd_flow_director_pf_vf,
9107                 (void *)&cmd_flow_director_queue,
9108                 (void *)&cmd_flow_director_queue_id,
9109                 (void *)&cmd_flow_director_fd_id,
9110                 (void *)&cmd_flow_director_fd_id_value,
9111                 NULL,
9112         },
9113 };
9114
9115 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
9116         .f = cmd_flow_director_filter_parsed,
9117         .data = NULL,
9118         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
9119                 "director entry on NIC",
9120         .tokens = {
9121                 (void *)&cmd_flow_director_filter,
9122                 (void *)&cmd_flow_director_port_id,
9123                 (void *)&cmd_flow_director_mode,
9124                 (void *)&cmd_flow_director_mode_ip,
9125                 (void *)&cmd_flow_director_ops,
9126                 (void *)&cmd_flow_director_flow,
9127                 (void *)&cmd_flow_director_flow_type,
9128                 (void *)&cmd_flow_director_ether,
9129                 (void *)&cmd_flow_director_ether_type,
9130                 (void *)&cmd_flow_director_flexbytes,
9131                 (void *)&cmd_flow_director_flexbytes_value,
9132                 (void *)&cmd_flow_director_drop,
9133                 (void *)&cmd_flow_director_pf_vf,
9134                 (void *)&cmd_flow_director_queue,
9135                 (void *)&cmd_flow_director_queue_id,
9136                 (void *)&cmd_flow_director_fd_id,
9137                 (void *)&cmd_flow_director_fd_id_value,
9138                 NULL,
9139         },
9140 };
9141
9142 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
9143         .f = cmd_flow_director_filter_parsed,
9144         .data = NULL,
9145         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
9146                 "director entry on NIC",
9147         .tokens = {
9148                 (void *)&cmd_flow_director_filter,
9149                 (void *)&cmd_flow_director_port_id,
9150                 (void *)&cmd_flow_director_mode,
9151                 (void *)&cmd_flow_director_mode_mac_vlan,
9152                 (void *)&cmd_flow_director_ops,
9153                 (void *)&cmd_flow_director_mac,
9154                 (void *)&cmd_flow_director_mac_addr,
9155                 (void *)&cmd_flow_director_vlan,
9156                 (void *)&cmd_flow_director_vlan_value,
9157                 (void *)&cmd_flow_director_flexbytes,
9158                 (void *)&cmd_flow_director_flexbytes_value,
9159                 (void *)&cmd_flow_director_drop,
9160                 (void *)&cmd_flow_director_queue,
9161                 (void *)&cmd_flow_director_queue_id,
9162                 (void *)&cmd_flow_director_fd_id,
9163                 (void *)&cmd_flow_director_fd_id_value,
9164                 NULL,
9165         },
9166 };
9167
9168 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
9169         .f = cmd_flow_director_filter_parsed,
9170         .data = NULL,
9171         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
9172                 "director entry on NIC",
9173         .tokens = {
9174                 (void *)&cmd_flow_director_filter,
9175                 (void *)&cmd_flow_director_port_id,
9176                 (void *)&cmd_flow_director_mode,
9177                 (void *)&cmd_flow_director_mode_tunnel,
9178                 (void *)&cmd_flow_director_ops,
9179                 (void *)&cmd_flow_director_mac,
9180                 (void *)&cmd_flow_director_mac_addr,
9181                 (void *)&cmd_flow_director_vlan,
9182                 (void *)&cmd_flow_director_vlan_value,
9183                 (void *)&cmd_flow_director_tunnel,
9184                 (void *)&cmd_flow_director_tunnel_type,
9185                 (void *)&cmd_flow_director_tunnel_id,
9186                 (void *)&cmd_flow_director_tunnel_id_value,
9187                 (void *)&cmd_flow_director_flexbytes,
9188                 (void *)&cmd_flow_director_flexbytes_value,
9189                 (void *)&cmd_flow_director_drop,
9190                 (void *)&cmd_flow_director_queue,
9191                 (void *)&cmd_flow_director_queue_id,
9192                 (void *)&cmd_flow_director_fd_id,
9193                 (void *)&cmd_flow_director_fd_id_value,
9194                 NULL,
9195         },
9196 };
9197
9198 struct cmd_flush_flow_director_result {
9199         cmdline_fixed_string_t flush_flow_director;
9200         uint8_t port_id;
9201 };
9202
9203 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
9204         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
9205                                  flush_flow_director, "flush_flow_director");
9206 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
9207         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
9208                               port_id, UINT8);
9209
9210 static void
9211 cmd_flush_flow_director_parsed(void *parsed_result,
9212                           __attribute__((unused)) struct cmdline *cl,
9213                           __attribute__((unused)) void *data)
9214 {
9215         struct cmd_flow_director_result *res = parsed_result;
9216         int ret = 0;
9217
9218         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9219         if (ret < 0) {
9220                 printf("flow director is not supported on port %u.\n",
9221                         res->port_id);
9222                 return;
9223         }
9224
9225         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9226                         RTE_ETH_FILTER_FLUSH, NULL);
9227         if (ret < 0)
9228                 printf("flow director table flushing error: (%s)\n",
9229                         strerror(-ret));
9230 }
9231
9232 cmdline_parse_inst_t cmd_flush_flow_director = {
9233         .f = cmd_flush_flow_director_parsed,
9234         .data = NULL,
9235         .help_str = "flush_flow_director <port_id>: "
9236                 "Flush all flow director entries of a device on NIC",
9237         .tokens = {
9238                 (void *)&cmd_flush_flow_director_flush,
9239                 (void *)&cmd_flush_flow_director_port_id,
9240                 NULL,
9241         },
9242 };
9243
9244 /* *** deal with flow director mask *** */
9245 struct cmd_flow_director_mask_result {
9246         cmdline_fixed_string_t flow_director_mask;
9247         uint8_t port_id;
9248         cmdline_fixed_string_t mode;
9249         cmdline_fixed_string_t mode_value;
9250         cmdline_fixed_string_t vlan;
9251         uint16_t vlan_mask;
9252         cmdline_fixed_string_t src_mask;
9253         cmdline_ipaddr_t ipv4_src;
9254         cmdline_ipaddr_t ipv6_src;
9255         uint16_t port_src;
9256         cmdline_fixed_string_t dst_mask;
9257         cmdline_ipaddr_t ipv4_dst;
9258         cmdline_ipaddr_t ipv6_dst;
9259         uint16_t port_dst;
9260         cmdline_fixed_string_t mac;
9261         uint8_t mac_addr_byte_mask;
9262         cmdline_fixed_string_t tunnel_id;
9263         uint32_t tunnel_id_mask;
9264         cmdline_fixed_string_t tunnel_type;
9265         uint8_t tunnel_type_mask;
9266 };
9267
9268 static void
9269 cmd_flow_director_mask_parsed(void *parsed_result,
9270                           __attribute__((unused)) struct cmdline *cl,
9271                           __attribute__((unused)) void *data)
9272 {
9273         struct cmd_flow_director_mask_result *res = parsed_result;
9274         struct rte_eth_fdir_masks *mask;
9275         struct rte_port *port;
9276
9277         if (res->port_id > nb_ports) {
9278                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9279                 return;
9280         }
9281
9282         port = &ports[res->port_id];
9283         /** Check if the port is not started **/
9284         if (port->port_status != RTE_PORT_STOPPED) {
9285                 printf("Please stop port %d first\n", res->port_id);
9286                 return;
9287         }
9288
9289         mask = &port->dev_conf.fdir_conf.mask;
9290
9291         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9292                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9293                         printf("Please set mode to MAC-VLAN.\n");
9294                         return;
9295                 }
9296
9297                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9298         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9299                 if (strcmp(res->mode_value, "Tunnel")) {
9300                         printf("Please set mode to Tunnel.\n");
9301                         return;
9302                 }
9303
9304                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9305                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9306                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
9307                 mask->tunnel_type_mask = res->tunnel_type_mask;
9308         } else {
9309                 if (strcmp(res->mode_value, "IP")) {
9310                         printf("Please set mode to IP.\n");
9311                         return;
9312                 }
9313
9314                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9315                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
9316                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
9317                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
9318                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
9319                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
9320                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
9321         }
9322
9323         cmd_reconfig_device_queue(res->port_id, 1, 1);
9324 }
9325
9326 cmdline_parse_token_string_t cmd_flow_director_mask =
9327         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9328                                  flow_director_mask, "flow_director_mask");
9329 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
9330         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9331                               port_id, UINT8);
9332 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
9333         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9334                                  vlan, "vlan");
9335 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
9336         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9337                               vlan_mask, UINT16);
9338 cmdline_parse_token_string_t cmd_flow_director_mask_src =
9339         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9340                                  src_mask, "src_mask");
9341 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
9342         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9343                                  ipv4_src);
9344 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
9345         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9346                                  ipv6_src);
9347 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
9348         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9349                               port_src, UINT16);
9350 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
9351         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9352                                  dst_mask, "dst_mask");
9353 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
9354         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9355                                  ipv4_dst);
9356 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
9357         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9358                                  ipv6_dst);
9359 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
9360         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9361                               port_dst, UINT16);
9362
9363 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
9364         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9365                                  mode, "mode");
9366 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
9367         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9368                                  mode_value, "IP");
9369 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
9370         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9371                                  mode_value, "MAC-VLAN");
9372 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
9373         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9374                                  mode_value, "Tunnel");
9375 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
9376         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9377                                  mac, "mac");
9378 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
9379         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9380                               mac_addr_byte_mask, UINT8);
9381 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
9382         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9383                                  tunnel_type, "tunnel-type");
9384 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
9385         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9386                               tunnel_type_mask, UINT8);
9387 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
9388         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9389                                  tunnel_id, "tunnel-id");
9390 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
9391         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9392                               tunnel_id_mask, UINT32);
9393
9394 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
9395         .f = cmd_flow_director_mask_parsed,
9396         .data = NULL,
9397         .help_str = "flow_director_mask ... : "
9398                 "Set IP mode flow director's mask on NIC",
9399         .tokens = {
9400                 (void *)&cmd_flow_director_mask,
9401                 (void *)&cmd_flow_director_mask_port_id,
9402                 (void *)&cmd_flow_director_mask_mode,
9403                 (void *)&cmd_flow_director_mask_mode_ip,
9404                 (void *)&cmd_flow_director_mask_vlan,
9405                 (void *)&cmd_flow_director_mask_vlan_value,
9406                 (void *)&cmd_flow_director_mask_src,
9407                 (void *)&cmd_flow_director_mask_ipv4_src,
9408                 (void *)&cmd_flow_director_mask_ipv6_src,
9409                 (void *)&cmd_flow_director_mask_port_src,
9410                 (void *)&cmd_flow_director_mask_dst,
9411                 (void *)&cmd_flow_director_mask_ipv4_dst,
9412                 (void *)&cmd_flow_director_mask_ipv6_dst,
9413                 (void *)&cmd_flow_director_mask_port_dst,
9414                 NULL,
9415         },
9416 };
9417
9418 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
9419         .f = cmd_flow_director_mask_parsed,
9420         .data = NULL,
9421         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
9422                 "flow director's mask on NIC",
9423         .tokens = {
9424                 (void *)&cmd_flow_director_mask,
9425                 (void *)&cmd_flow_director_mask_port_id,
9426                 (void *)&cmd_flow_director_mask_mode,
9427                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
9428                 (void *)&cmd_flow_director_mask_vlan,
9429                 (void *)&cmd_flow_director_mask_vlan_value,
9430                 NULL,
9431         },
9432 };
9433
9434 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
9435         .f = cmd_flow_director_mask_parsed,
9436         .data = NULL,
9437         .help_str = "flow_director_mask ... : Set tunnel mode "
9438                 "flow director's mask on NIC",
9439         .tokens = {
9440                 (void *)&cmd_flow_director_mask,
9441                 (void *)&cmd_flow_director_mask_port_id,
9442                 (void *)&cmd_flow_director_mask_mode,
9443                 (void *)&cmd_flow_director_mask_mode_tunnel,
9444                 (void *)&cmd_flow_director_mask_vlan,
9445                 (void *)&cmd_flow_director_mask_vlan_value,
9446                 (void *)&cmd_flow_director_mask_mac,
9447                 (void *)&cmd_flow_director_mask_mac_value,
9448                 (void *)&cmd_flow_director_mask_tunnel_type,
9449                 (void *)&cmd_flow_director_mask_tunnel_type_value,
9450                 (void *)&cmd_flow_director_mask_tunnel_id,
9451                 (void *)&cmd_flow_director_mask_tunnel_id_value,
9452                 NULL,
9453         },
9454 };
9455
9456 /* *** deal with flow director mask on flexible payload *** */
9457 struct cmd_flow_director_flex_mask_result {
9458         cmdline_fixed_string_t flow_director_flexmask;
9459         uint8_t port_id;
9460         cmdline_fixed_string_t flow;
9461         cmdline_fixed_string_t flow_type;
9462         cmdline_fixed_string_t mask;
9463 };
9464
9465 static void
9466 cmd_flow_director_flex_mask_parsed(void *parsed_result,
9467                           __attribute__((unused)) struct cmdline *cl,
9468                           __attribute__((unused)) void *data)
9469 {
9470         struct cmd_flow_director_flex_mask_result *res = parsed_result;
9471         struct rte_eth_fdir_info fdir_info;
9472         struct rte_eth_fdir_flex_mask flex_mask;
9473         struct rte_port *port;
9474         uint32_t flow_type_mask;
9475         uint16_t i;
9476         int ret;
9477
9478         if (res->port_id > nb_ports) {
9479                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9480                 return;
9481         }
9482
9483         port = &ports[res->port_id];
9484         /** Check if the port is not started **/
9485         if (port->port_status != RTE_PORT_STOPPED) {
9486                 printf("Please stop port %d first\n", res->port_id);
9487                 return;
9488         }
9489
9490         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
9491         ret = parse_flexbytes(res->mask,
9492                         flex_mask.mask,
9493                         RTE_ETH_FDIR_MAX_FLEXLEN);
9494         if (ret < 0) {
9495                 printf("error: Cannot parse mask input.\n");
9496                 return;
9497         }
9498
9499         memset(&fdir_info, 0, sizeof(fdir_info));
9500         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9501                                 RTE_ETH_FILTER_INFO, &fdir_info);
9502         if (ret < 0) {
9503                 printf("Cannot get FDir filter info\n");
9504                 return;
9505         }
9506
9507         if (!strcmp(res->flow_type, "none")) {
9508                 /* means don't specify the flow type */
9509                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
9510                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
9511                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
9512                                0, sizeof(struct rte_eth_fdir_flex_mask));
9513                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
9514                 (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
9515                                  &flex_mask,
9516                                  sizeof(struct rte_eth_fdir_flex_mask));
9517                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9518                 return;
9519         }
9520         flow_type_mask = fdir_info.flow_types_mask[0];
9521         if (!strcmp(res->flow_type, "all")) {
9522                 if (!flow_type_mask) {
9523                         printf("No flow type supported\n");
9524                         return;
9525                 }
9526                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
9527                         if (flow_type_mask & (1 << i)) {
9528                                 flex_mask.flow_type = i;
9529                                 fdir_set_flex_mask(res->port_id, &flex_mask);
9530                         }
9531                 }
9532                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9533                 return;
9534         }
9535         flex_mask.flow_type = str2flowtype(res->flow_type);
9536         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
9537                 printf("Flow type %s not supported on port %d\n",
9538                                 res->flow_type, res->port_id);
9539                 return;
9540         }
9541         fdir_set_flex_mask(res->port_id, &flex_mask);
9542         cmd_reconfig_device_queue(res->port_id, 1, 1);
9543 }
9544
9545 cmdline_parse_token_string_t cmd_flow_director_flexmask =
9546         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9547                                  flow_director_flexmask,
9548                                  "flow_director_flex_mask");
9549 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
9550         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9551                               port_id, UINT8);
9552 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
9553         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9554                                  flow, "flow");
9555 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
9556         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9557                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9558                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
9559 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
9560         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9561                                  mask, NULL);
9562
9563 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
9564         .f = cmd_flow_director_flex_mask_parsed,
9565         .data = NULL,
9566         .help_str = "flow_director_flex_mask ... : "
9567                 "Set flow director's flex mask on NIC",
9568         .tokens = {
9569                 (void *)&cmd_flow_director_flexmask,
9570                 (void *)&cmd_flow_director_flexmask_port_id,
9571                 (void *)&cmd_flow_director_flexmask_flow,
9572                 (void *)&cmd_flow_director_flexmask_flow_type,
9573                 (void *)&cmd_flow_director_flexmask_mask,
9574                 NULL,
9575         },
9576 };
9577
9578 /* *** deal with flow director flexible payload configuration *** */
9579 struct cmd_flow_director_flexpayload_result {
9580         cmdline_fixed_string_t flow_director_flexpayload;
9581         uint8_t port_id;
9582         cmdline_fixed_string_t payload_layer;
9583         cmdline_fixed_string_t payload_cfg;
9584 };
9585
9586 static inline int
9587 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
9588 {
9589         char s[256];
9590         const char *p, *p0 = q_arg;
9591         char *end;
9592         unsigned long int_fld;
9593         char *str_fld[max_num];
9594         int i;
9595         unsigned size;
9596         int ret = -1;
9597
9598         p = strchr(p0, '(');
9599         if (p == NULL)
9600                 return -1;
9601         ++p;
9602         p0 = strchr(p, ')');
9603         if (p0 == NULL)
9604                 return -1;
9605
9606         size = p0 - p;
9607         if (size >= sizeof(s))
9608                 return -1;
9609
9610         snprintf(s, sizeof(s), "%.*s", size, p);
9611         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9612         if (ret < 0 || ret > max_num)
9613                 return -1;
9614         for (i = 0; i < ret; i++) {
9615                 errno = 0;
9616                 int_fld = strtoul(str_fld[i], &end, 0);
9617                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
9618                         return -1;
9619                 offsets[i] = (uint16_t)int_fld;
9620         }
9621         return ret;
9622 }
9623
9624 static void
9625 cmd_flow_director_flxpld_parsed(void *parsed_result,
9626                           __attribute__((unused)) struct cmdline *cl,
9627                           __attribute__((unused)) void *data)
9628 {
9629         struct cmd_flow_director_flexpayload_result *res = parsed_result;
9630         struct rte_eth_flex_payload_cfg flex_cfg;
9631         struct rte_port *port;
9632         int ret = 0;
9633
9634         if (res->port_id > nb_ports) {
9635                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9636                 return;
9637         }
9638
9639         port = &ports[res->port_id];
9640         /** Check if the port is not started **/
9641         if (port->port_status != RTE_PORT_STOPPED) {
9642                 printf("Please stop port %d first\n", res->port_id);
9643                 return;
9644         }
9645
9646         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
9647
9648         if (!strcmp(res->payload_layer, "raw"))
9649                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
9650         else if (!strcmp(res->payload_layer, "l2"))
9651                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
9652         else if (!strcmp(res->payload_layer, "l3"))
9653                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
9654         else if (!strcmp(res->payload_layer, "l4"))
9655                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
9656
9657         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
9658                             RTE_ETH_FDIR_MAX_FLEXLEN);
9659         if (ret < 0) {
9660                 printf("error: Cannot parse flex payload input.\n");
9661                 return;
9662         }
9663
9664         fdir_set_flex_payload(res->port_id, &flex_cfg);
9665         cmd_reconfig_device_queue(res->port_id, 1, 1);
9666 }
9667
9668 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
9669         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9670                                  flow_director_flexpayload,
9671                                  "flow_director_flex_payload");
9672 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
9673         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9674                               port_id, UINT8);
9675 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
9676         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9677                                  payload_layer, "raw#l2#l3#l4");
9678 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
9679         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9680                                  payload_cfg, NULL);
9681
9682 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
9683         .f = cmd_flow_director_flxpld_parsed,
9684         .data = NULL,
9685         .help_str = "flow_director_flexpayload ... : "
9686                 "Set flow director's flex payload on NIC",
9687         .tokens = {
9688                 (void *)&cmd_flow_director_flexpayload,
9689                 (void *)&cmd_flow_director_flexpayload_port_id,
9690                 (void *)&cmd_flow_director_flexpayload_payload_layer,
9691                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
9692                 NULL,
9693         },
9694 };
9695
9696 /* Generic flow interface command. */
9697 extern cmdline_parse_inst_t cmd_flow;
9698
9699 /* *** Classification Filters Control *** */
9700 /* *** Get symmetric hash enable per port *** */
9701 struct cmd_get_sym_hash_ena_per_port_result {
9702         cmdline_fixed_string_t get_sym_hash_ena_per_port;
9703         uint8_t port_id;
9704 };
9705
9706 static void
9707 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
9708                                  __rte_unused struct cmdline *cl,
9709                                  __rte_unused void *data)
9710 {
9711         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
9712         struct rte_eth_hash_filter_info info;
9713         int ret;
9714
9715         if (rte_eth_dev_filter_supported(res->port_id,
9716                                 RTE_ETH_FILTER_HASH) < 0) {
9717                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9718                                                         res->port_id);
9719                 return;
9720         }
9721
9722         memset(&info, 0, sizeof(info));
9723         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9724         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9725                                                 RTE_ETH_FILTER_GET, &info);
9726
9727         if (ret < 0) {
9728                 printf("Cannot get symmetric hash enable per port "
9729                                         "on port %u\n", res->port_id);
9730                 return;
9731         }
9732
9733         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
9734                                 "enabled" : "disabled", res->port_id);
9735 }
9736
9737 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
9738         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9739                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
9740 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
9741         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9742                 port_id, UINT8);
9743
9744 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
9745         .f = cmd_get_sym_hash_per_port_parsed,
9746         .data = NULL,
9747         .help_str = "get_sym_hash_ena_per_port <port_id>",
9748         .tokens = {
9749                 (void *)&cmd_get_sym_hash_ena_per_port_all,
9750                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
9751                 NULL,
9752         },
9753 };
9754
9755 /* *** Set symmetric hash enable per port *** */
9756 struct cmd_set_sym_hash_ena_per_port_result {
9757         cmdline_fixed_string_t set_sym_hash_ena_per_port;
9758         cmdline_fixed_string_t enable;
9759         uint8_t port_id;
9760 };
9761
9762 static void
9763 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
9764                                  __rte_unused struct cmdline *cl,
9765                                  __rte_unused void *data)
9766 {
9767         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
9768         struct rte_eth_hash_filter_info info;
9769         int ret;
9770
9771         if (rte_eth_dev_filter_supported(res->port_id,
9772                                 RTE_ETH_FILTER_HASH) < 0) {
9773                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9774                                                         res->port_id);
9775                 return;
9776         }
9777
9778         memset(&info, 0, sizeof(info));
9779         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9780         if (!strcmp(res->enable, "enable"))
9781                 info.info.enable = 1;
9782         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9783                                         RTE_ETH_FILTER_SET, &info);
9784         if (ret < 0) {
9785                 printf("Cannot set symmetric hash enable per port on "
9786                                         "port %u\n", res->port_id);
9787                 return;
9788         }
9789         printf("Symmetric hash has been set to %s on port %u\n",
9790                                         res->enable, res->port_id);
9791 }
9792
9793 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
9794         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9795                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
9796 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
9797         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9798                 port_id, UINT8);
9799 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
9800         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9801                 enable, "enable#disable");
9802
9803 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
9804         .f = cmd_set_sym_hash_per_port_parsed,
9805         .data = NULL,
9806         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
9807         .tokens = {
9808                 (void *)&cmd_set_sym_hash_ena_per_port_all,
9809                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
9810                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
9811                 NULL,
9812         },
9813 };
9814
9815 /* Get global config of hash function */
9816 struct cmd_get_hash_global_config_result {
9817         cmdline_fixed_string_t get_hash_global_config;
9818         uint8_t port_id;
9819 };
9820
9821 static char *
9822 flowtype_to_str(uint16_t ftype)
9823 {
9824         uint16_t i;
9825         static struct {
9826                 char str[16];
9827                 uint16_t ftype;
9828         } ftype_table[] = {
9829                 {"ipv4", RTE_ETH_FLOW_IPV4},
9830                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9831                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9832                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9833                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9834                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9835                 {"ipv6", RTE_ETH_FLOW_IPV6},
9836                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9837                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9838                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9839                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9840                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9841                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9842                 {"port", RTE_ETH_FLOW_PORT},
9843                 {"vxlan", RTE_ETH_FLOW_VXLAN},
9844                 {"geneve", RTE_ETH_FLOW_GENEVE},
9845                 {"nvgre", RTE_ETH_FLOW_NVGRE},
9846         };
9847
9848         for (i = 0; i < RTE_DIM(ftype_table); i++) {
9849                 if (ftype_table[i].ftype == ftype)
9850                         return ftype_table[i].str;
9851         }
9852
9853         return NULL;
9854 }
9855
9856 static void
9857 cmd_get_hash_global_config_parsed(void *parsed_result,
9858                                   __rte_unused struct cmdline *cl,
9859                                   __rte_unused void *data)
9860 {
9861         struct cmd_get_hash_global_config_result *res = parsed_result;
9862         struct rte_eth_hash_filter_info info;
9863         uint32_t idx, offset;
9864         uint16_t i;
9865         char *str;
9866         int ret;
9867
9868         if (rte_eth_dev_filter_supported(res->port_id,
9869                         RTE_ETH_FILTER_HASH) < 0) {
9870                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9871                                                         res->port_id);
9872                 return;
9873         }
9874
9875         memset(&info, 0, sizeof(info));
9876         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9877         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9878                                         RTE_ETH_FILTER_GET, &info);
9879         if (ret < 0) {
9880                 printf("Cannot get hash global configurations by port %d\n",
9881                                                         res->port_id);
9882                 return;
9883         }
9884
9885         switch (info.info.global_conf.hash_func) {
9886         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
9887                 printf("Hash function is Toeplitz\n");
9888                 break;
9889         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
9890                 printf("Hash function is Simple XOR\n");
9891                 break;
9892         default:
9893                 printf("Unknown hash function\n");
9894                 break;
9895         }
9896
9897         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
9898                 idx = i / UINT32_BIT;
9899                 offset = i % UINT32_BIT;
9900                 if (!(info.info.global_conf.valid_bit_mask[idx] &
9901                                                 (1UL << offset)))
9902                         continue;
9903                 str = flowtype_to_str(i);
9904                 if (!str)
9905                         continue;
9906                 printf("Symmetric hash is %s globally for flow type %s "
9907                                                         "by port %d\n",
9908                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
9909                         (1UL << offset)) ? "enabled" : "disabled"), str,
9910                                                         res->port_id);
9911         }
9912 }
9913
9914 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
9915         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
9916                 get_hash_global_config, "get_hash_global_config");
9917 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
9918         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
9919                 port_id, UINT8);
9920
9921 cmdline_parse_inst_t cmd_get_hash_global_config = {
9922         .f = cmd_get_hash_global_config_parsed,
9923         .data = NULL,
9924         .help_str = "get_hash_global_config <port_id>",
9925         .tokens = {
9926                 (void *)&cmd_get_hash_global_config_all,
9927                 (void *)&cmd_get_hash_global_config_port_id,
9928                 NULL,
9929         },
9930 };
9931
9932 /* Set global config of hash function */
9933 struct cmd_set_hash_global_config_result {
9934         cmdline_fixed_string_t set_hash_global_config;
9935         uint8_t port_id;
9936         cmdline_fixed_string_t hash_func;
9937         cmdline_fixed_string_t flow_type;
9938         cmdline_fixed_string_t enable;
9939 };
9940
9941 static void
9942 cmd_set_hash_global_config_parsed(void *parsed_result,
9943                                   __rte_unused struct cmdline *cl,
9944                                   __rte_unused void *data)
9945 {
9946         struct cmd_set_hash_global_config_result *res = parsed_result;
9947         struct rte_eth_hash_filter_info info;
9948         uint32_t ftype, idx, offset;
9949         int ret;
9950
9951         if (rte_eth_dev_filter_supported(res->port_id,
9952                                 RTE_ETH_FILTER_HASH) < 0) {
9953                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9954                                                         res->port_id);
9955                 return;
9956         }
9957         memset(&info, 0, sizeof(info));
9958         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9959         if (!strcmp(res->hash_func, "toeplitz"))
9960                 info.info.global_conf.hash_func =
9961                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
9962         else if (!strcmp(res->hash_func, "simple_xor"))
9963                 info.info.global_conf.hash_func =
9964                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
9965         else if (!strcmp(res->hash_func, "default"))
9966                 info.info.global_conf.hash_func =
9967                         RTE_ETH_HASH_FUNCTION_DEFAULT;
9968
9969         ftype = str2flowtype(res->flow_type);
9970         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
9971         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
9972         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
9973         if (!strcmp(res->enable, "enable"))
9974                 info.info.global_conf.sym_hash_enable_mask[idx] |=
9975                                                 (1UL << offset);
9976         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9977                                         RTE_ETH_FILTER_SET, &info);
9978         if (ret < 0)
9979                 printf("Cannot set global hash configurations by port %d\n",
9980                                                         res->port_id);
9981         else
9982                 printf("Global hash configurations have been set "
9983                         "succcessfully by port %d\n", res->port_id);
9984 }
9985
9986 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
9987         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9988                 set_hash_global_config, "set_hash_global_config");
9989 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
9990         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
9991                 port_id, UINT8);
9992 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
9993         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9994                 hash_func, "toeplitz#simple_xor#default");
9995 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
9996         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9997                 flow_type,
9998                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
9999                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10000 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
10001         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10002                 enable, "enable#disable");
10003
10004 cmdline_parse_inst_t cmd_set_hash_global_config = {
10005         .f = cmd_set_hash_global_config_parsed,
10006         .data = NULL,
10007         .help_str = "set_hash_global_config <port_id> "
10008                 "toeplitz|simple_xor|default "
10009                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10010                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
10011                 "l2_payload enable|disable",
10012         .tokens = {
10013                 (void *)&cmd_set_hash_global_config_all,
10014                 (void *)&cmd_set_hash_global_config_port_id,
10015                 (void *)&cmd_set_hash_global_config_hash_func,
10016                 (void *)&cmd_set_hash_global_config_flow_type,
10017                 (void *)&cmd_set_hash_global_config_enable,
10018                 NULL,
10019         },
10020 };
10021
10022 /* Set hash input set */
10023 struct cmd_set_hash_input_set_result {
10024         cmdline_fixed_string_t set_hash_input_set;
10025         uint8_t port_id;
10026         cmdline_fixed_string_t flow_type;
10027         cmdline_fixed_string_t inset_field;
10028         cmdline_fixed_string_t select;
10029 };
10030
10031 static enum rte_eth_input_set_field
10032 str2inset(char *string)
10033 {
10034         uint16_t i;
10035
10036         static const struct {
10037                 char str[32];
10038                 enum rte_eth_input_set_field inset;
10039         } inset_table[] = {
10040                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
10041                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
10042                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
10043                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
10044                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
10045                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
10046                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
10047                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
10048                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
10049                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
10050                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
10051                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
10052                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
10053                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
10054                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
10055                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
10056                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
10057                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
10058                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
10059                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
10060                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
10061                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
10062                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
10063                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
10064                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
10065                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
10066                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
10067                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
10068                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
10069                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
10070                 {"none", RTE_ETH_INPUT_SET_NONE},
10071         };
10072
10073         for (i = 0; i < RTE_DIM(inset_table); i++) {
10074                 if (!strcmp(string, inset_table[i].str))
10075                         return inset_table[i].inset;
10076         }
10077
10078         return RTE_ETH_INPUT_SET_UNKNOWN;
10079 }
10080
10081 static void
10082 cmd_set_hash_input_set_parsed(void *parsed_result,
10083                               __rte_unused struct cmdline *cl,
10084                               __rte_unused void *data)
10085 {
10086         struct cmd_set_hash_input_set_result *res = parsed_result;
10087         struct rte_eth_hash_filter_info info;
10088
10089         memset(&info, 0, sizeof(info));
10090         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
10091         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10092         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10093         info.info.input_set_conf.inset_size = 1;
10094         if (!strcmp(res->select, "select"))
10095                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10096         else if (!strcmp(res->select, "add"))
10097                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10098         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10099                                 RTE_ETH_FILTER_SET, &info);
10100 }
10101
10102 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
10103         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10104                 set_hash_input_set, "set_hash_input_set");
10105 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
10106         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
10107                 port_id, UINT8);
10108 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
10109         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10110                 flow_type,
10111                 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10112                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10113 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
10114         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10115                 inset_field,
10116                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10117                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
10118                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
10119                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
10120                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
10121                 "fld-8th#none");
10122 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
10123         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10124                 select, "select#add");
10125
10126 cmdline_parse_inst_t cmd_set_hash_input_set = {
10127         .f = cmd_set_hash_input_set_parsed,
10128         .data = NULL,
10129         .help_str = "set_hash_input_set <port_id> "
10130         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10131         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10132         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
10133         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
10134         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
10135         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
10136         "fld-7th|fld-8th|none select|add",
10137         .tokens = {
10138                 (void *)&cmd_set_hash_input_set_cmd,
10139                 (void *)&cmd_set_hash_input_set_port_id,
10140                 (void *)&cmd_set_hash_input_set_flow_type,
10141                 (void *)&cmd_set_hash_input_set_field,
10142                 (void *)&cmd_set_hash_input_set_select,
10143                 NULL,
10144         },
10145 };
10146
10147 /* Set flow director input set */
10148 struct cmd_set_fdir_input_set_result {
10149         cmdline_fixed_string_t set_fdir_input_set;
10150         uint8_t port_id;
10151         cmdline_fixed_string_t flow_type;
10152         cmdline_fixed_string_t inset_field;
10153         cmdline_fixed_string_t select;
10154 };
10155
10156 static void
10157 cmd_set_fdir_input_set_parsed(void *parsed_result,
10158         __rte_unused struct cmdline *cl,
10159         __rte_unused void *data)
10160 {
10161         struct cmd_set_fdir_input_set_result *res = parsed_result;
10162         struct rte_eth_fdir_filter_info info;
10163
10164         memset(&info, 0, sizeof(info));
10165         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
10166         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10167         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10168         info.info.input_set_conf.inset_size = 1;
10169         if (!strcmp(res->select, "select"))
10170                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10171         else if (!strcmp(res->select, "add"))
10172                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10173         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10174                 RTE_ETH_FILTER_SET, &info);
10175 }
10176
10177 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
10178         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10179         set_fdir_input_set, "set_fdir_input_set");
10180 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
10181         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
10182         port_id, UINT8);
10183 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
10184         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10185         flow_type,
10186         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10187         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10188 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
10189         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10190         inset_field,
10191         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10192         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
10193         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
10194         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
10195         "sctp-veri-tag#none");
10196 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
10197         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10198         select, "select#add");
10199
10200 cmdline_parse_inst_t cmd_set_fdir_input_set = {
10201         .f = cmd_set_fdir_input_set_parsed,
10202         .data = NULL,
10203         .help_str = "set_fdir_input_set <port_id> "
10204         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10205         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10206         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
10207         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
10208         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
10209         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
10210         "sctp-veri-tag|none select|add",
10211         .tokens = {
10212                 (void *)&cmd_set_fdir_input_set_cmd,
10213                 (void *)&cmd_set_fdir_input_set_port_id,
10214                 (void *)&cmd_set_fdir_input_set_flow_type,
10215                 (void *)&cmd_set_fdir_input_set_field,
10216                 (void *)&cmd_set_fdir_input_set_select,
10217                 NULL,
10218         },
10219 };
10220
10221 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10222 struct cmd_mcast_addr_result {
10223         cmdline_fixed_string_t mcast_addr_cmd;
10224         cmdline_fixed_string_t what;
10225         uint8_t port_num;
10226         struct ether_addr mc_addr;
10227 };
10228
10229 static void cmd_mcast_addr_parsed(void *parsed_result,
10230                 __attribute__((unused)) struct cmdline *cl,
10231                 __attribute__((unused)) void *data)
10232 {
10233         struct cmd_mcast_addr_result *res = parsed_result;
10234
10235         if (!is_multicast_ether_addr(&res->mc_addr)) {
10236                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10237                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10238                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10239                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10240                 return;
10241         }
10242         if (strcmp(res->what, "add") == 0)
10243                 mcast_addr_add(res->port_num, &res->mc_addr);
10244         else
10245                 mcast_addr_remove(res->port_num, &res->mc_addr);
10246 }
10247
10248 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10249         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10250                                  mcast_addr_cmd, "mcast_addr");
10251 cmdline_parse_token_string_t cmd_mcast_addr_what =
10252         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10253                                  "add#remove");
10254 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10255         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
10256 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10257         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10258
10259 cmdline_parse_inst_t cmd_mcast_addr = {
10260         .f = cmd_mcast_addr_parsed,
10261         .data = (void *)0,
10262         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10263                 "Add/Remove multicast MAC address on port_id",
10264         .tokens = {
10265                 (void *)&cmd_mcast_addr_cmd,
10266                 (void *)&cmd_mcast_addr_what,
10267                 (void *)&cmd_mcast_addr_portnum,
10268                 (void *)&cmd_mcast_addr_addr,
10269                 NULL,
10270         },
10271 };
10272
10273 /* l2 tunnel config
10274  * only support E-tag now.
10275  */
10276
10277 /* Ether type config */
10278 struct cmd_config_l2_tunnel_eth_type_result {
10279         cmdline_fixed_string_t port;
10280         cmdline_fixed_string_t config;
10281         cmdline_fixed_string_t all;
10282         uint8_t id;
10283         cmdline_fixed_string_t l2_tunnel;
10284         cmdline_fixed_string_t l2_tunnel_type;
10285         cmdline_fixed_string_t eth_type;
10286         uint16_t eth_type_val;
10287 };
10288
10289 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10290         TOKEN_STRING_INITIALIZER
10291                 (struct cmd_config_l2_tunnel_eth_type_result,
10292                  port, "port");
10293 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10294         TOKEN_STRING_INITIALIZER
10295                 (struct cmd_config_l2_tunnel_eth_type_result,
10296                  config, "config");
10297 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10298         TOKEN_STRING_INITIALIZER
10299                 (struct cmd_config_l2_tunnel_eth_type_result,
10300                  all, "all");
10301 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10302         TOKEN_NUM_INITIALIZER
10303                 (struct cmd_config_l2_tunnel_eth_type_result,
10304                  id, UINT8);
10305 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10306         TOKEN_STRING_INITIALIZER
10307                 (struct cmd_config_l2_tunnel_eth_type_result,
10308                  l2_tunnel, "l2-tunnel");
10309 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10310         TOKEN_STRING_INITIALIZER
10311                 (struct cmd_config_l2_tunnel_eth_type_result,
10312                  l2_tunnel_type, "E-tag");
10313 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10314         TOKEN_STRING_INITIALIZER
10315                 (struct cmd_config_l2_tunnel_eth_type_result,
10316                  eth_type, "ether-type");
10317 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10318         TOKEN_NUM_INITIALIZER
10319                 (struct cmd_config_l2_tunnel_eth_type_result,
10320                  eth_type_val, UINT16);
10321
10322 static enum rte_eth_tunnel_type
10323 str2fdir_l2_tunnel_type(char *string)
10324 {
10325         uint32_t i = 0;
10326
10327         static const struct {
10328                 char str[32];
10329                 enum rte_eth_tunnel_type type;
10330         } l2_tunnel_type_str[] = {
10331                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10332         };
10333
10334         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10335                 if (!strcmp(l2_tunnel_type_str[i].str, string))
10336                         return l2_tunnel_type_str[i].type;
10337         }
10338         return RTE_TUNNEL_TYPE_NONE;
10339 }
10340
10341 /* ether type config for all ports */
10342 static void
10343 cmd_config_l2_tunnel_eth_type_all_parsed
10344         (void *parsed_result,
10345          __attribute__((unused)) struct cmdline *cl,
10346          __attribute__((unused)) void *data)
10347 {
10348         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10349         struct rte_eth_l2_tunnel_conf entry;
10350         portid_t pid;
10351
10352         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10353         entry.ether_type = res->eth_type_val;
10354
10355         RTE_ETH_FOREACH_DEV(pid) {
10356                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10357         }
10358 }
10359
10360 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10361         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
10362         .data = NULL,
10363         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
10364         .tokens = {
10365                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10366                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10367                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
10368                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10369                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10370                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10371                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10372                 NULL,
10373         },
10374 };
10375
10376 /* ether type config for a specific port */
10377 static void
10378 cmd_config_l2_tunnel_eth_type_specific_parsed(
10379         void *parsed_result,
10380         __attribute__((unused)) struct cmdline *cl,
10381         __attribute__((unused)) void *data)
10382 {
10383         struct cmd_config_l2_tunnel_eth_type_result *res =
10384                  parsed_result;
10385         struct rte_eth_l2_tunnel_conf entry;
10386
10387         if (port_id_is_invalid(res->id, ENABLED_WARN))
10388                 return;
10389
10390         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10391         entry.ether_type = res->eth_type_val;
10392
10393         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10394 }
10395
10396 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10397         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
10398         .data = NULL,
10399         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
10400         .tokens = {
10401                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10402                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10403                 (void *)&cmd_config_l2_tunnel_eth_type_id,
10404                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10405                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10406                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10407                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10408                 NULL,
10409         },
10410 };
10411
10412 /* Enable/disable l2 tunnel */
10413 struct cmd_config_l2_tunnel_en_dis_result {
10414         cmdline_fixed_string_t port;
10415         cmdline_fixed_string_t config;
10416         cmdline_fixed_string_t all;
10417         uint8_t id;
10418         cmdline_fixed_string_t l2_tunnel;
10419         cmdline_fixed_string_t l2_tunnel_type;
10420         cmdline_fixed_string_t en_dis;
10421 };
10422
10423 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
10424         TOKEN_STRING_INITIALIZER
10425                 (struct cmd_config_l2_tunnel_en_dis_result,
10426                  port, "port");
10427 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
10428         TOKEN_STRING_INITIALIZER
10429                 (struct cmd_config_l2_tunnel_en_dis_result,
10430                  config, "config");
10431 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
10432         TOKEN_STRING_INITIALIZER
10433                 (struct cmd_config_l2_tunnel_en_dis_result,
10434                  all, "all");
10435 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
10436         TOKEN_NUM_INITIALIZER
10437                 (struct cmd_config_l2_tunnel_en_dis_result,
10438                  id, UINT8);
10439 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
10440         TOKEN_STRING_INITIALIZER
10441                 (struct cmd_config_l2_tunnel_en_dis_result,
10442                  l2_tunnel, "l2-tunnel");
10443 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
10444         TOKEN_STRING_INITIALIZER
10445                 (struct cmd_config_l2_tunnel_en_dis_result,
10446                  l2_tunnel_type, "E-tag");
10447 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
10448         TOKEN_STRING_INITIALIZER
10449                 (struct cmd_config_l2_tunnel_en_dis_result,
10450                  en_dis, "enable#disable");
10451
10452 /* enable/disable l2 tunnel for all ports */
10453 static void
10454 cmd_config_l2_tunnel_en_dis_all_parsed(
10455         void *parsed_result,
10456         __attribute__((unused)) struct cmdline *cl,
10457         __attribute__((unused)) void *data)
10458 {
10459         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
10460         struct rte_eth_l2_tunnel_conf entry;
10461         portid_t pid;
10462         uint8_t en;
10463
10464         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10465
10466         if (!strcmp("enable", res->en_dis))
10467                 en = 1;
10468         else
10469                 en = 0;
10470
10471         RTE_ETH_FOREACH_DEV(pid) {
10472                 rte_eth_dev_l2_tunnel_offload_set(pid,
10473                                                   &entry,
10474                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10475                                                   en);
10476         }
10477 }
10478
10479 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
10480         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
10481         .data = NULL,
10482         .help_str = "port config all l2-tunnel E-tag enable|disable",
10483         .tokens = {
10484                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10485                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10486                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
10487                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10488                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10489                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10490                 NULL,
10491         },
10492 };
10493
10494 /* enable/disable l2 tunnel for a port */
10495 static void
10496 cmd_config_l2_tunnel_en_dis_specific_parsed(
10497         void *parsed_result,
10498         __attribute__((unused)) struct cmdline *cl,
10499         __attribute__((unused)) void *data)
10500 {
10501         struct cmd_config_l2_tunnel_en_dis_result *res =
10502                 parsed_result;
10503         struct rte_eth_l2_tunnel_conf entry;
10504
10505         if (port_id_is_invalid(res->id, ENABLED_WARN))
10506                 return;
10507
10508         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10509
10510         if (!strcmp("enable", res->en_dis))
10511                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10512                                                   &entry,
10513                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10514                                                   1);
10515         else
10516                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10517                                                   &entry,
10518                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10519                                                   0);
10520 }
10521
10522 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
10523         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
10524         .data = NULL,
10525         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
10526         .tokens = {
10527                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10528                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10529                 (void *)&cmd_config_l2_tunnel_en_dis_id,
10530                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10531                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10532                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10533                 NULL,
10534         },
10535 };
10536
10537 /* E-tag configuration */
10538
10539 /* Common result structure for all E-tag configuration */
10540 struct cmd_config_e_tag_result {
10541         cmdline_fixed_string_t e_tag;
10542         cmdline_fixed_string_t set;
10543         cmdline_fixed_string_t insertion;
10544         cmdline_fixed_string_t stripping;
10545         cmdline_fixed_string_t forwarding;
10546         cmdline_fixed_string_t filter;
10547         cmdline_fixed_string_t add;
10548         cmdline_fixed_string_t del;
10549         cmdline_fixed_string_t on;
10550         cmdline_fixed_string_t off;
10551         cmdline_fixed_string_t on_off;
10552         cmdline_fixed_string_t port_tag_id;
10553         uint32_t port_tag_id_val;
10554         cmdline_fixed_string_t e_tag_id;
10555         uint16_t e_tag_id_val;
10556         cmdline_fixed_string_t dst_pool;
10557         uint8_t dst_pool_val;
10558         cmdline_fixed_string_t port;
10559         uint8_t port_id;
10560         cmdline_fixed_string_t vf;
10561         uint8_t vf_id;
10562 };
10563
10564 /* Common CLI fields for all E-tag configuration */
10565 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
10566         TOKEN_STRING_INITIALIZER
10567                 (struct cmd_config_e_tag_result,
10568                  e_tag, "E-tag");
10569 cmdline_parse_token_string_t cmd_config_e_tag_set =
10570         TOKEN_STRING_INITIALIZER
10571                 (struct cmd_config_e_tag_result,
10572                  set, "set");
10573 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
10574         TOKEN_STRING_INITIALIZER
10575                 (struct cmd_config_e_tag_result,
10576                  insertion, "insertion");
10577 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
10578         TOKEN_STRING_INITIALIZER
10579                 (struct cmd_config_e_tag_result,
10580                  stripping, "stripping");
10581 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
10582         TOKEN_STRING_INITIALIZER
10583                 (struct cmd_config_e_tag_result,
10584                  forwarding, "forwarding");
10585 cmdline_parse_token_string_t cmd_config_e_tag_filter =
10586         TOKEN_STRING_INITIALIZER
10587                 (struct cmd_config_e_tag_result,
10588                  filter, "filter");
10589 cmdline_parse_token_string_t cmd_config_e_tag_add =
10590         TOKEN_STRING_INITIALIZER
10591                 (struct cmd_config_e_tag_result,
10592                  add, "add");
10593 cmdline_parse_token_string_t cmd_config_e_tag_del =
10594         TOKEN_STRING_INITIALIZER
10595                 (struct cmd_config_e_tag_result,
10596                  del, "del");
10597 cmdline_parse_token_string_t cmd_config_e_tag_on =
10598         TOKEN_STRING_INITIALIZER
10599                 (struct cmd_config_e_tag_result,
10600                  on, "on");
10601 cmdline_parse_token_string_t cmd_config_e_tag_off =
10602         TOKEN_STRING_INITIALIZER
10603                 (struct cmd_config_e_tag_result,
10604                  off, "off");
10605 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
10606         TOKEN_STRING_INITIALIZER
10607                 (struct cmd_config_e_tag_result,
10608                  on_off, "on#off");
10609 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
10610         TOKEN_STRING_INITIALIZER
10611                 (struct cmd_config_e_tag_result,
10612                  port_tag_id, "port-tag-id");
10613 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
10614         TOKEN_NUM_INITIALIZER
10615                 (struct cmd_config_e_tag_result,
10616                  port_tag_id_val, UINT32);
10617 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
10618         TOKEN_STRING_INITIALIZER
10619                 (struct cmd_config_e_tag_result,
10620                  e_tag_id, "e-tag-id");
10621 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
10622         TOKEN_NUM_INITIALIZER
10623                 (struct cmd_config_e_tag_result,
10624                  e_tag_id_val, UINT16);
10625 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
10626         TOKEN_STRING_INITIALIZER
10627                 (struct cmd_config_e_tag_result,
10628                  dst_pool, "dst-pool");
10629 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
10630         TOKEN_NUM_INITIALIZER
10631                 (struct cmd_config_e_tag_result,
10632                  dst_pool_val, UINT8);
10633 cmdline_parse_token_string_t cmd_config_e_tag_port =
10634         TOKEN_STRING_INITIALIZER
10635                 (struct cmd_config_e_tag_result,
10636                  port, "port");
10637 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
10638         TOKEN_NUM_INITIALIZER
10639                 (struct cmd_config_e_tag_result,
10640                  port_id, UINT8);
10641 cmdline_parse_token_string_t cmd_config_e_tag_vf =
10642         TOKEN_STRING_INITIALIZER
10643                 (struct cmd_config_e_tag_result,
10644                  vf, "vf");
10645 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
10646         TOKEN_NUM_INITIALIZER
10647                 (struct cmd_config_e_tag_result,
10648                  vf_id, UINT8);
10649
10650 /* E-tag insertion configuration */
10651 static void
10652 cmd_config_e_tag_insertion_en_parsed(
10653         void *parsed_result,
10654         __attribute__((unused)) struct cmdline *cl,
10655         __attribute__((unused)) void *data)
10656 {
10657         struct cmd_config_e_tag_result *res =
10658                 parsed_result;
10659         struct rte_eth_l2_tunnel_conf entry;
10660
10661         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10662                 return;
10663
10664         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10665         entry.tunnel_id = res->port_tag_id_val;
10666         entry.vf_id = res->vf_id;
10667         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10668                                           &entry,
10669                                           ETH_L2_TUNNEL_INSERTION_MASK,
10670                                           1);
10671 }
10672
10673 static void
10674 cmd_config_e_tag_insertion_dis_parsed(
10675         void *parsed_result,
10676         __attribute__((unused)) struct cmdline *cl,
10677         __attribute__((unused)) void *data)
10678 {
10679         struct cmd_config_e_tag_result *res =
10680                 parsed_result;
10681         struct rte_eth_l2_tunnel_conf entry;
10682
10683         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10684                 return;
10685
10686         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10687         entry.vf_id = res->vf_id;
10688
10689         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10690                                           &entry,
10691                                           ETH_L2_TUNNEL_INSERTION_MASK,
10692                                           0);
10693 }
10694
10695 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
10696         .f = cmd_config_e_tag_insertion_en_parsed,
10697         .data = NULL,
10698         .help_str = "E-tag ... : E-tag insertion enable",
10699         .tokens = {
10700                 (void *)&cmd_config_e_tag_e_tag,
10701                 (void *)&cmd_config_e_tag_set,
10702                 (void *)&cmd_config_e_tag_insertion,
10703                 (void *)&cmd_config_e_tag_on,
10704                 (void *)&cmd_config_e_tag_port_tag_id,
10705                 (void *)&cmd_config_e_tag_port_tag_id_val,
10706                 (void *)&cmd_config_e_tag_port,
10707                 (void *)&cmd_config_e_tag_port_id,
10708                 (void *)&cmd_config_e_tag_vf,
10709                 (void *)&cmd_config_e_tag_vf_id,
10710                 NULL,
10711         },
10712 };
10713
10714 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
10715         .f = cmd_config_e_tag_insertion_dis_parsed,
10716         .data = NULL,
10717         .help_str = "E-tag ... : E-tag insertion disable",
10718         .tokens = {
10719                 (void *)&cmd_config_e_tag_e_tag,
10720                 (void *)&cmd_config_e_tag_set,
10721                 (void *)&cmd_config_e_tag_insertion,
10722                 (void *)&cmd_config_e_tag_off,
10723                 (void *)&cmd_config_e_tag_port,
10724                 (void *)&cmd_config_e_tag_port_id,
10725                 (void *)&cmd_config_e_tag_vf,
10726                 (void *)&cmd_config_e_tag_vf_id,
10727                 NULL,
10728         },
10729 };
10730
10731 /* E-tag stripping configuration */
10732 static void
10733 cmd_config_e_tag_stripping_parsed(
10734         void *parsed_result,
10735         __attribute__((unused)) struct cmdline *cl,
10736         __attribute__((unused)) void *data)
10737 {
10738         struct cmd_config_e_tag_result *res =
10739                 parsed_result;
10740         struct rte_eth_l2_tunnel_conf entry;
10741
10742         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10743                 return;
10744
10745         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10746
10747         if (!strcmp(res->on_off, "on"))
10748                 rte_eth_dev_l2_tunnel_offload_set
10749                         (res->port_id,
10750                          &entry,
10751                          ETH_L2_TUNNEL_STRIPPING_MASK,
10752                          1);
10753         else
10754                 rte_eth_dev_l2_tunnel_offload_set
10755                         (res->port_id,
10756                          &entry,
10757                          ETH_L2_TUNNEL_STRIPPING_MASK,
10758                          0);
10759 }
10760
10761 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
10762         .f = cmd_config_e_tag_stripping_parsed,
10763         .data = NULL,
10764         .help_str = "E-tag ... : E-tag stripping enable/disable",
10765         .tokens = {
10766                 (void *)&cmd_config_e_tag_e_tag,
10767                 (void *)&cmd_config_e_tag_set,
10768                 (void *)&cmd_config_e_tag_stripping,
10769                 (void *)&cmd_config_e_tag_on_off,
10770                 (void *)&cmd_config_e_tag_port,
10771                 (void *)&cmd_config_e_tag_port_id,
10772                 NULL,
10773         },
10774 };
10775
10776 /* E-tag forwarding configuration */
10777 static void
10778 cmd_config_e_tag_forwarding_parsed(
10779         void *parsed_result,
10780         __attribute__((unused)) struct cmdline *cl,
10781         __attribute__((unused)) void *data)
10782 {
10783         struct cmd_config_e_tag_result *res = parsed_result;
10784         struct rte_eth_l2_tunnel_conf entry;
10785
10786         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10787                 return;
10788
10789         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10790
10791         if (!strcmp(res->on_off, "on"))
10792                 rte_eth_dev_l2_tunnel_offload_set
10793                         (res->port_id,
10794                          &entry,
10795                          ETH_L2_TUNNEL_FORWARDING_MASK,
10796                          1);
10797         else
10798                 rte_eth_dev_l2_tunnel_offload_set
10799                         (res->port_id,
10800                          &entry,
10801                          ETH_L2_TUNNEL_FORWARDING_MASK,
10802                          0);
10803 }
10804
10805 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
10806         .f = cmd_config_e_tag_forwarding_parsed,
10807         .data = NULL,
10808         .help_str = "E-tag ... : E-tag forwarding enable/disable",
10809         .tokens = {
10810                 (void *)&cmd_config_e_tag_e_tag,
10811                 (void *)&cmd_config_e_tag_set,
10812                 (void *)&cmd_config_e_tag_forwarding,
10813                 (void *)&cmd_config_e_tag_on_off,
10814                 (void *)&cmd_config_e_tag_port,
10815                 (void *)&cmd_config_e_tag_port_id,
10816                 NULL,
10817         },
10818 };
10819
10820 /* E-tag filter configuration */
10821 static void
10822 cmd_config_e_tag_filter_add_parsed(
10823         void *parsed_result,
10824         __attribute__((unused)) struct cmdline *cl,
10825         __attribute__((unused)) void *data)
10826 {
10827         struct cmd_config_e_tag_result *res = parsed_result;
10828         struct rte_eth_l2_tunnel_conf entry;
10829         int ret = 0;
10830
10831         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10832                 return;
10833
10834         if (res->e_tag_id_val > 0x3fff) {
10835                 printf("e-tag-id must be equal or less than 0x3fff.\n");
10836                 return;
10837         }
10838
10839         ret = rte_eth_dev_filter_supported(res->port_id,
10840                                            RTE_ETH_FILTER_L2_TUNNEL);
10841         if (ret < 0) {
10842                 printf("E-tag filter is not supported on port %u.\n",
10843                        res->port_id);
10844                 return;
10845         }
10846
10847         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10848         entry.tunnel_id = res->e_tag_id_val;
10849         entry.pool = res->dst_pool_val;
10850
10851         ret = rte_eth_dev_filter_ctrl(res->port_id,
10852                                       RTE_ETH_FILTER_L2_TUNNEL,
10853                                       RTE_ETH_FILTER_ADD,
10854                                       &entry);
10855         if (ret < 0)
10856                 printf("E-tag filter programming error: (%s)\n",
10857                        strerror(-ret));
10858 }
10859
10860 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
10861         .f = cmd_config_e_tag_filter_add_parsed,
10862         .data = NULL,
10863         .help_str = "E-tag ... : E-tag filter add",
10864         .tokens = {
10865                 (void *)&cmd_config_e_tag_e_tag,
10866                 (void *)&cmd_config_e_tag_set,
10867                 (void *)&cmd_config_e_tag_filter,
10868                 (void *)&cmd_config_e_tag_add,
10869                 (void *)&cmd_config_e_tag_e_tag_id,
10870                 (void *)&cmd_config_e_tag_e_tag_id_val,
10871                 (void *)&cmd_config_e_tag_dst_pool,
10872                 (void *)&cmd_config_e_tag_dst_pool_val,
10873                 (void *)&cmd_config_e_tag_port,
10874                 (void *)&cmd_config_e_tag_port_id,
10875                 NULL,
10876         },
10877 };
10878
10879 static void
10880 cmd_config_e_tag_filter_del_parsed(
10881         void *parsed_result,
10882         __attribute__((unused)) struct cmdline *cl,
10883         __attribute__((unused)) void *data)
10884 {
10885         struct cmd_config_e_tag_result *res = parsed_result;
10886         struct rte_eth_l2_tunnel_conf entry;
10887         int ret = 0;
10888
10889         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10890                 return;
10891
10892         if (res->e_tag_id_val > 0x3fff) {
10893                 printf("e-tag-id must be less than 0x3fff.\n");
10894                 return;
10895         }
10896
10897         ret = rte_eth_dev_filter_supported(res->port_id,
10898                                            RTE_ETH_FILTER_L2_TUNNEL);
10899         if (ret < 0) {
10900                 printf("E-tag filter is not supported on port %u.\n",
10901                        res->port_id);
10902                 return;
10903         }
10904
10905         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10906         entry.tunnel_id = res->e_tag_id_val;
10907
10908         ret = rte_eth_dev_filter_ctrl(res->port_id,
10909                                       RTE_ETH_FILTER_L2_TUNNEL,
10910                                       RTE_ETH_FILTER_DELETE,
10911                                       &entry);
10912         if (ret < 0)
10913                 printf("E-tag filter programming error: (%s)\n",
10914                        strerror(-ret));
10915 }
10916
10917 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
10918         .f = cmd_config_e_tag_filter_del_parsed,
10919         .data = NULL,
10920         .help_str = "E-tag ... : E-tag filter delete",
10921         .tokens = {
10922                 (void *)&cmd_config_e_tag_e_tag,
10923                 (void *)&cmd_config_e_tag_set,
10924                 (void *)&cmd_config_e_tag_filter,
10925                 (void *)&cmd_config_e_tag_del,
10926                 (void *)&cmd_config_e_tag_e_tag_id,
10927                 (void *)&cmd_config_e_tag_e_tag_id_val,
10928                 (void *)&cmd_config_e_tag_port,
10929                 (void *)&cmd_config_e_tag_port_id,
10930                 NULL,
10931         },
10932 };
10933
10934 /* vf vlan anti spoof configuration */
10935
10936 /* Common result structure for vf vlan anti spoof */
10937 struct cmd_vf_vlan_anti_spoof_result {
10938         cmdline_fixed_string_t set;
10939         cmdline_fixed_string_t vf;
10940         cmdline_fixed_string_t vlan;
10941         cmdline_fixed_string_t antispoof;
10942         uint8_t port_id;
10943         uint32_t vf_id;
10944         cmdline_fixed_string_t on_off;
10945 };
10946
10947 /* Common CLI fields for vf vlan anti spoof enable disable */
10948 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10949         TOKEN_STRING_INITIALIZER
10950                 (struct cmd_vf_vlan_anti_spoof_result,
10951                  set, "set");
10952 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10953         TOKEN_STRING_INITIALIZER
10954                 (struct cmd_vf_vlan_anti_spoof_result,
10955                  vf, "vf");
10956 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10957         TOKEN_STRING_INITIALIZER
10958                 (struct cmd_vf_vlan_anti_spoof_result,
10959                  vlan, "vlan");
10960 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10961         TOKEN_STRING_INITIALIZER
10962                 (struct cmd_vf_vlan_anti_spoof_result,
10963                  antispoof, "antispoof");
10964 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10965         TOKEN_NUM_INITIALIZER
10966                 (struct cmd_vf_vlan_anti_spoof_result,
10967                  port_id, UINT8);
10968 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10969         TOKEN_NUM_INITIALIZER
10970                 (struct cmd_vf_vlan_anti_spoof_result,
10971                  vf_id, UINT32);
10972 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10973         TOKEN_STRING_INITIALIZER
10974                 (struct cmd_vf_vlan_anti_spoof_result,
10975                  on_off, "on#off");
10976
10977 static void
10978 cmd_set_vf_vlan_anti_spoof_parsed(
10979         void *parsed_result,
10980         __attribute__((unused)) struct cmdline *cl,
10981         __attribute__((unused)) void *data)
10982 {
10983         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10984         int ret = -ENOTSUP;
10985
10986         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10987
10988         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10989                 return;
10990
10991 #ifdef RTE_LIBRTE_IXGBE_PMD
10992         if (ret == -ENOTSUP)
10993                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
10994                                 res->vf_id, is_on);
10995 #endif
10996 #ifdef RTE_LIBRTE_I40E_PMD
10997         if (ret == -ENOTSUP)
10998                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
10999                                 res->vf_id, is_on);
11000 #endif
11001
11002         switch (ret) {
11003         case 0:
11004                 break;
11005         case -EINVAL:
11006                 printf("invalid vf_id %d\n", res->vf_id);
11007                 break;
11008         case -ENODEV:
11009                 printf("invalid port_id %d\n", res->port_id);
11010                 break;
11011         case -ENOTSUP:
11012                 printf("function not implemented\n");
11013                 break;
11014         default:
11015                 printf("programming error: (%s)\n", strerror(-ret));
11016         }
11017 }
11018
11019 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11020         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11021         .data = NULL,
11022         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11023         .tokens = {
11024                 (void *)&cmd_vf_vlan_anti_spoof_set,
11025                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11026                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11027                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11028                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11029                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11030                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11031                 NULL,
11032         },
11033 };
11034
11035 /* vf mac anti spoof configuration */
11036
11037 /* Common result structure for vf mac anti spoof */
11038 struct cmd_vf_mac_anti_spoof_result {
11039         cmdline_fixed_string_t set;
11040         cmdline_fixed_string_t vf;
11041         cmdline_fixed_string_t mac;
11042         cmdline_fixed_string_t antispoof;
11043         uint8_t port_id;
11044         uint32_t vf_id;
11045         cmdline_fixed_string_t on_off;
11046 };
11047
11048 /* Common CLI fields for vf mac anti spoof enable disable */
11049 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11050         TOKEN_STRING_INITIALIZER
11051                 (struct cmd_vf_mac_anti_spoof_result,
11052                  set, "set");
11053 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11054         TOKEN_STRING_INITIALIZER
11055                 (struct cmd_vf_mac_anti_spoof_result,
11056                  vf, "vf");
11057 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11058         TOKEN_STRING_INITIALIZER
11059                 (struct cmd_vf_mac_anti_spoof_result,
11060                  mac, "mac");
11061 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11062         TOKEN_STRING_INITIALIZER
11063                 (struct cmd_vf_mac_anti_spoof_result,
11064                  antispoof, "antispoof");
11065 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11066         TOKEN_NUM_INITIALIZER
11067                 (struct cmd_vf_mac_anti_spoof_result,
11068                  port_id, UINT8);
11069 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11070         TOKEN_NUM_INITIALIZER
11071                 (struct cmd_vf_mac_anti_spoof_result,
11072                  vf_id, UINT32);
11073 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11074         TOKEN_STRING_INITIALIZER
11075                 (struct cmd_vf_mac_anti_spoof_result,
11076                  on_off, "on#off");
11077
11078 static void
11079 cmd_set_vf_mac_anti_spoof_parsed(
11080         void *parsed_result,
11081         __attribute__((unused)) struct cmdline *cl,
11082         __attribute__((unused)) void *data)
11083 {
11084         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11085         int ret = -ENOTSUP;
11086
11087         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11088
11089         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11090                 return;
11091
11092 #ifdef RTE_LIBRTE_IXGBE_PMD
11093         if (ret == -ENOTSUP)
11094                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11095                         res->vf_id, is_on);
11096 #endif
11097 #ifdef RTE_LIBRTE_I40E_PMD
11098         if (ret == -ENOTSUP)
11099                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11100                         res->vf_id, is_on);
11101 #endif
11102
11103         switch (ret) {
11104         case 0:
11105                 break;
11106         case -EINVAL:
11107                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11108                 break;
11109         case -ENODEV:
11110                 printf("invalid port_id %d\n", res->port_id);
11111                 break;
11112         case -ENOTSUP:
11113                 printf("function not implemented\n");
11114                 break;
11115         default:
11116                 printf("programming error: (%s)\n", strerror(-ret));
11117         }
11118 }
11119
11120 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11121         .f = cmd_set_vf_mac_anti_spoof_parsed,
11122         .data = NULL,
11123         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11124         .tokens = {
11125                 (void *)&cmd_vf_mac_anti_spoof_set,
11126                 (void *)&cmd_vf_mac_anti_spoof_vf,
11127                 (void *)&cmd_vf_mac_anti_spoof_mac,
11128                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11129                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11130                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11131                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11132                 NULL,
11133         },
11134 };
11135
11136 /* vf vlan strip queue configuration */
11137
11138 /* Common result structure for vf mac anti spoof */
11139 struct cmd_vf_vlan_stripq_result {
11140         cmdline_fixed_string_t set;
11141         cmdline_fixed_string_t vf;
11142         cmdline_fixed_string_t vlan;
11143         cmdline_fixed_string_t stripq;
11144         uint8_t port_id;
11145         uint16_t vf_id;
11146         cmdline_fixed_string_t on_off;
11147 };
11148
11149 /* Common CLI fields for vf vlan strip enable disable */
11150 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11151         TOKEN_STRING_INITIALIZER
11152                 (struct cmd_vf_vlan_stripq_result,
11153                  set, "set");
11154 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11155         TOKEN_STRING_INITIALIZER
11156                 (struct cmd_vf_vlan_stripq_result,
11157                  vf, "vf");
11158 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11159         TOKEN_STRING_INITIALIZER
11160                 (struct cmd_vf_vlan_stripq_result,
11161                  vlan, "vlan");
11162 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11163         TOKEN_STRING_INITIALIZER
11164                 (struct cmd_vf_vlan_stripq_result,
11165                  stripq, "stripq");
11166 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11167         TOKEN_NUM_INITIALIZER
11168                 (struct cmd_vf_vlan_stripq_result,
11169                  port_id, UINT8);
11170 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11171         TOKEN_NUM_INITIALIZER
11172                 (struct cmd_vf_vlan_stripq_result,
11173                  vf_id, UINT16);
11174 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11175         TOKEN_STRING_INITIALIZER
11176                 (struct cmd_vf_vlan_stripq_result,
11177                  on_off, "on#off");
11178
11179 static void
11180 cmd_set_vf_vlan_stripq_parsed(
11181         void *parsed_result,
11182         __attribute__((unused)) struct cmdline *cl,
11183         __attribute__((unused)) void *data)
11184 {
11185         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11186         int ret = -ENOTSUP;
11187
11188         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11189
11190         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11191                 return;
11192
11193 #ifdef RTE_LIBRTE_IXGBE_PMD
11194         if (ret == -ENOTSUP)
11195                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11196                         res->vf_id, is_on);
11197 #endif
11198 #ifdef RTE_LIBRTE_I40E_PMD
11199         if (ret == -ENOTSUP)
11200                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11201                         res->vf_id, is_on);
11202 #endif
11203
11204         switch (ret) {
11205         case 0:
11206                 break;
11207         case -EINVAL:
11208                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11209                 break;
11210         case -ENODEV:
11211                 printf("invalid port_id %d\n", res->port_id);
11212                 break;
11213         case -ENOTSUP:
11214                 printf("function not implemented\n");
11215                 break;
11216         default:
11217                 printf("programming error: (%s)\n", strerror(-ret));
11218         }
11219 }
11220
11221 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11222         .f = cmd_set_vf_vlan_stripq_parsed,
11223         .data = NULL,
11224         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11225         .tokens = {
11226                 (void *)&cmd_vf_vlan_stripq_set,
11227                 (void *)&cmd_vf_vlan_stripq_vf,
11228                 (void *)&cmd_vf_vlan_stripq_vlan,
11229                 (void *)&cmd_vf_vlan_stripq_stripq,
11230                 (void *)&cmd_vf_vlan_stripq_port_id,
11231                 (void *)&cmd_vf_vlan_stripq_vf_id,
11232                 (void *)&cmd_vf_vlan_stripq_on_off,
11233                 NULL,
11234         },
11235 };
11236
11237 /* vf vlan insert configuration */
11238
11239 /* Common result structure for vf vlan insert */
11240 struct cmd_vf_vlan_insert_result {
11241         cmdline_fixed_string_t set;
11242         cmdline_fixed_string_t vf;
11243         cmdline_fixed_string_t vlan;
11244         cmdline_fixed_string_t insert;
11245         uint8_t port_id;
11246         uint16_t vf_id;
11247         uint16_t vlan_id;
11248 };
11249
11250 /* Common CLI fields for vf vlan insert enable disable */
11251 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11252         TOKEN_STRING_INITIALIZER
11253                 (struct cmd_vf_vlan_insert_result,
11254                  set, "set");
11255 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11256         TOKEN_STRING_INITIALIZER
11257                 (struct cmd_vf_vlan_insert_result,
11258                  vf, "vf");
11259 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11260         TOKEN_STRING_INITIALIZER
11261                 (struct cmd_vf_vlan_insert_result,
11262                  vlan, "vlan");
11263 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11264         TOKEN_STRING_INITIALIZER
11265                 (struct cmd_vf_vlan_insert_result,
11266                  insert, "insert");
11267 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11268         TOKEN_NUM_INITIALIZER
11269                 (struct cmd_vf_vlan_insert_result,
11270                  port_id, UINT8);
11271 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11272         TOKEN_NUM_INITIALIZER
11273                 (struct cmd_vf_vlan_insert_result,
11274                  vf_id, UINT16);
11275 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11276         TOKEN_NUM_INITIALIZER
11277                 (struct cmd_vf_vlan_insert_result,
11278                  vlan_id, UINT16);
11279
11280 static void
11281 cmd_set_vf_vlan_insert_parsed(
11282         void *parsed_result,
11283         __attribute__((unused)) struct cmdline *cl,
11284         __attribute__((unused)) void *data)
11285 {
11286         struct cmd_vf_vlan_insert_result *res = parsed_result;
11287         int ret = -ENOTSUP;
11288
11289         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11290                 return;
11291
11292 #ifdef RTE_LIBRTE_IXGBE_PMD
11293         if (ret == -ENOTSUP)
11294                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11295                         res->vlan_id);
11296 #endif
11297 #ifdef RTE_LIBRTE_I40E_PMD
11298         if (ret == -ENOTSUP)
11299                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11300                         res->vlan_id);
11301 #endif
11302
11303         switch (ret) {
11304         case 0:
11305                 break;
11306         case -EINVAL:
11307                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11308                 break;
11309         case -ENODEV:
11310                 printf("invalid port_id %d\n", res->port_id);
11311                 break;
11312         case -ENOTSUP:
11313                 printf("function not implemented\n");
11314                 break;
11315         default:
11316                 printf("programming error: (%s)\n", strerror(-ret));
11317         }
11318 }
11319
11320 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11321         .f = cmd_set_vf_vlan_insert_parsed,
11322         .data = NULL,
11323         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11324         .tokens = {
11325                 (void *)&cmd_vf_vlan_insert_set,
11326                 (void *)&cmd_vf_vlan_insert_vf,
11327                 (void *)&cmd_vf_vlan_insert_vlan,
11328                 (void *)&cmd_vf_vlan_insert_insert,
11329                 (void *)&cmd_vf_vlan_insert_port_id,
11330                 (void *)&cmd_vf_vlan_insert_vf_id,
11331                 (void *)&cmd_vf_vlan_insert_vlan_id,
11332                 NULL,
11333         },
11334 };
11335
11336 /* tx loopback configuration */
11337
11338 /* Common result structure for tx loopback */
11339 struct cmd_tx_loopback_result {
11340         cmdline_fixed_string_t set;
11341         cmdline_fixed_string_t tx;
11342         cmdline_fixed_string_t loopback;
11343         uint8_t port_id;
11344         cmdline_fixed_string_t on_off;
11345 };
11346
11347 /* Common CLI fields for tx loopback enable disable */
11348 cmdline_parse_token_string_t cmd_tx_loopback_set =
11349         TOKEN_STRING_INITIALIZER
11350                 (struct cmd_tx_loopback_result,
11351                  set, "set");
11352 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11353         TOKEN_STRING_INITIALIZER
11354                 (struct cmd_tx_loopback_result,
11355                  tx, "tx");
11356 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11357         TOKEN_STRING_INITIALIZER
11358                 (struct cmd_tx_loopback_result,
11359                  loopback, "loopback");
11360 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11361         TOKEN_NUM_INITIALIZER
11362                 (struct cmd_tx_loopback_result,
11363                  port_id, UINT8);
11364 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11365         TOKEN_STRING_INITIALIZER
11366                 (struct cmd_tx_loopback_result,
11367                  on_off, "on#off");
11368
11369 static void
11370 cmd_set_tx_loopback_parsed(
11371         void *parsed_result,
11372         __attribute__((unused)) struct cmdline *cl,
11373         __attribute__((unused)) void *data)
11374 {
11375         struct cmd_tx_loopback_result *res = parsed_result;
11376         int ret = -ENOTSUP;
11377
11378         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11379
11380         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11381                 return;
11382
11383 #ifdef RTE_LIBRTE_IXGBE_PMD
11384         if (ret == -ENOTSUP)
11385                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11386 #endif
11387 #ifdef RTE_LIBRTE_I40E_PMD
11388         if (ret == -ENOTSUP)
11389                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11390 #endif
11391
11392         switch (ret) {
11393         case 0:
11394                 break;
11395         case -EINVAL:
11396                 printf("invalid is_on %d\n", is_on);
11397                 break;
11398         case -ENODEV:
11399                 printf("invalid port_id %d\n", res->port_id);
11400                 break;
11401         case -ENOTSUP:
11402                 printf("function not implemented\n");
11403                 break;
11404         default:
11405                 printf("programming error: (%s)\n", strerror(-ret));
11406         }
11407 }
11408
11409 cmdline_parse_inst_t cmd_set_tx_loopback = {
11410         .f = cmd_set_tx_loopback_parsed,
11411         .data = NULL,
11412         .help_str = "set tx loopback <port_id> on|off",
11413         .tokens = {
11414                 (void *)&cmd_tx_loopback_set,
11415                 (void *)&cmd_tx_loopback_tx,
11416                 (void *)&cmd_tx_loopback_loopback,
11417                 (void *)&cmd_tx_loopback_port_id,
11418                 (void *)&cmd_tx_loopback_on_off,
11419                 NULL,
11420         },
11421 };
11422
11423 #ifdef RTE_LIBRTE_IXGBE_PMD
11424 /* all queues drop enable configuration */
11425
11426 /* Common result structure for all queues drop enable */
11427 struct cmd_all_queues_drop_en_result {
11428         cmdline_fixed_string_t set;
11429         cmdline_fixed_string_t all;
11430         cmdline_fixed_string_t queues;
11431         cmdline_fixed_string_t drop;
11432         uint8_t port_id;
11433         cmdline_fixed_string_t on_off;
11434 };
11435
11436 /* Common CLI fields for tx loopback enable disable */
11437 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11438         TOKEN_STRING_INITIALIZER
11439                 (struct cmd_all_queues_drop_en_result,
11440                  set, "set");
11441 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11442         TOKEN_STRING_INITIALIZER
11443                 (struct cmd_all_queues_drop_en_result,
11444                  all, "all");
11445 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11446         TOKEN_STRING_INITIALIZER
11447                 (struct cmd_all_queues_drop_en_result,
11448                  queues, "queues");
11449 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11450         TOKEN_STRING_INITIALIZER
11451                 (struct cmd_all_queues_drop_en_result,
11452                  drop, "drop");
11453 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11454         TOKEN_NUM_INITIALIZER
11455                 (struct cmd_all_queues_drop_en_result,
11456                  port_id, UINT8);
11457 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11458         TOKEN_STRING_INITIALIZER
11459                 (struct cmd_all_queues_drop_en_result,
11460                  on_off, "on#off");
11461
11462 static void
11463 cmd_set_all_queues_drop_en_parsed(
11464         void *parsed_result,
11465         __attribute__((unused)) struct cmdline *cl,
11466         __attribute__((unused)) void *data)
11467 {
11468         struct cmd_all_queues_drop_en_result *res = parsed_result;
11469         int ret = 0;
11470         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11471
11472         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11473                 return;
11474
11475         ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11476         switch (ret) {
11477         case 0:
11478                 break;
11479         case -EINVAL:
11480                 printf("invalid is_on %d\n", is_on);
11481                 break;
11482         case -ENODEV:
11483                 printf("invalid port_id %d\n", res->port_id);
11484                 break;
11485         case -ENOTSUP:
11486                 printf("function not implemented\n");
11487                 break;
11488         default:
11489                 printf("programming error: (%s)\n", strerror(-ret));
11490         }
11491 }
11492
11493 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11494         .f = cmd_set_all_queues_drop_en_parsed,
11495         .data = NULL,
11496         .help_str = "set all queues drop <port_id> on|off",
11497         .tokens = {
11498                 (void *)&cmd_all_queues_drop_en_set,
11499                 (void *)&cmd_all_queues_drop_en_all,
11500                 (void *)&cmd_all_queues_drop_en_queues,
11501                 (void *)&cmd_all_queues_drop_en_drop,
11502                 (void *)&cmd_all_queues_drop_en_port_id,
11503                 (void *)&cmd_all_queues_drop_en_on_off,
11504                 NULL,
11505         },
11506 };
11507
11508 /* vf split drop enable configuration */
11509
11510 /* Common result structure for vf split drop enable */
11511 struct cmd_vf_split_drop_en_result {
11512         cmdline_fixed_string_t set;
11513         cmdline_fixed_string_t vf;
11514         cmdline_fixed_string_t split;
11515         cmdline_fixed_string_t drop;
11516         uint8_t port_id;
11517         uint16_t vf_id;
11518         cmdline_fixed_string_t on_off;
11519 };
11520
11521 /* Common CLI fields for vf split drop enable disable */
11522 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11523         TOKEN_STRING_INITIALIZER
11524                 (struct cmd_vf_split_drop_en_result,
11525                  set, "set");
11526 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11527         TOKEN_STRING_INITIALIZER
11528                 (struct cmd_vf_split_drop_en_result,
11529                  vf, "vf");
11530 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11531         TOKEN_STRING_INITIALIZER
11532                 (struct cmd_vf_split_drop_en_result,
11533                  split, "split");
11534 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11535         TOKEN_STRING_INITIALIZER
11536                 (struct cmd_vf_split_drop_en_result,
11537                  drop, "drop");
11538 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11539         TOKEN_NUM_INITIALIZER
11540                 (struct cmd_vf_split_drop_en_result,
11541                  port_id, UINT8);
11542 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11543         TOKEN_NUM_INITIALIZER
11544                 (struct cmd_vf_split_drop_en_result,
11545                  vf_id, UINT16);
11546 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11547         TOKEN_STRING_INITIALIZER
11548                 (struct cmd_vf_split_drop_en_result,
11549                  on_off, "on#off");
11550
11551 static void
11552 cmd_set_vf_split_drop_en_parsed(
11553         void *parsed_result,
11554         __attribute__((unused)) struct cmdline *cl,
11555         __attribute__((unused)) void *data)
11556 {
11557         struct cmd_vf_split_drop_en_result *res = parsed_result;
11558         int ret;
11559         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11560
11561         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11562                 return;
11563
11564         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11565                         is_on);
11566         switch (ret) {
11567         case 0:
11568                 break;
11569         case -EINVAL:
11570                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11571                 break;
11572         case -ENODEV:
11573                 printf("invalid port_id %d\n", res->port_id);
11574                 break;
11575         default:
11576                 printf("programming error: (%s)\n", strerror(-ret));
11577         }
11578 }
11579
11580 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11581         .f = cmd_set_vf_split_drop_en_parsed,
11582         .data = NULL,
11583         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11584         .tokens = {
11585                 (void *)&cmd_vf_split_drop_en_set,
11586                 (void *)&cmd_vf_split_drop_en_vf,
11587                 (void *)&cmd_vf_split_drop_en_split,
11588                 (void *)&cmd_vf_split_drop_en_drop,
11589                 (void *)&cmd_vf_split_drop_en_port_id,
11590                 (void *)&cmd_vf_split_drop_en_vf_id,
11591                 (void *)&cmd_vf_split_drop_en_on_off,
11592                 NULL,
11593         },
11594 };
11595 #endif
11596
11597 /* vf mac address configuration */
11598
11599 /* Common result structure for vf mac address */
11600 struct cmd_set_vf_mac_addr_result {
11601         cmdline_fixed_string_t set;
11602         cmdline_fixed_string_t vf;
11603         cmdline_fixed_string_t mac;
11604         cmdline_fixed_string_t addr;
11605         uint8_t port_id;
11606         uint16_t vf_id;
11607         struct ether_addr mac_addr;
11608
11609 };
11610
11611 /* Common CLI fields for vf split drop enable disable */
11612 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11613         TOKEN_STRING_INITIALIZER
11614                 (struct cmd_set_vf_mac_addr_result,
11615                  set, "set");
11616 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11617         TOKEN_STRING_INITIALIZER
11618                 (struct cmd_set_vf_mac_addr_result,
11619                  vf, "vf");
11620 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11621         TOKEN_STRING_INITIALIZER
11622                 (struct cmd_set_vf_mac_addr_result,
11623                  mac, "mac");
11624 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11625         TOKEN_STRING_INITIALIZER
11626                 (struct cmd_set_vf_mac_addr_result,
11627                  addr, "addr");
11628 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11629         TOKEN_NUM_INITIALIZER
11630                 (struct cmd_set_vf_mac_addr_result,
11631                  port_id, UINT8);
11632 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11633         TOKEN_NUM_INITIALIZER
11634                 (struct cmd_set_vf_mac_addr_result,
11635                  vf_id, UINT16);
11636 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11637         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11638                  mac_addr);
11639
11640 static void
11641 cmd_set_vf_mac_addr_parsed(
11642         void *parsed_result,
11643         __attribute__((unused)) struct cmdline *cl,
11644         __attribute__((unused)) void *data)
11645 {
11646         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11647         int ret = -ENOTSUP;
11648
11649         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11650                 return;
11651
11652 #ifdef RTE_LIBRTE_IXGBE_PMD
11653         if (ret == -ENOTSUP)
11654                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11655                                 &res->mac_addr);
11656 #endif
11657 #ifdef RTE_LIBRTE_I40E_PMD
11658         if (ret == -ENOTSUP)
11659                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11660                                 &res->mac_addr);
11661 #endif
11662
11663         switch (ret) {
11664         case 0:
11665                 break;
11666         case -EINVAL:
11667                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11668                 break;
11669         case -ENODEV:
11670                 printf("invalid port_id %d\n", res->port_id);
11671                 break;
11672         case -ENOTSUP:
11673                 printf("function not implemented\n");
11674                 break;
11675         default:
11676                 printf("programming error: (%s)\n", strerror(-ret));
11677         }
11678 }
11679
11680 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11681         .f = cmd_set_vf_mac_addr_parsed,
11682         .data = NULL,
11683         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11684         .tokens = {
11685                 (void *)&cmd_set_vf_mac_addr_set,
11686                 (void *)&cmd_set_vf_mac_addr_vf,
11687                 (void *)&cmd_set_vf_mac_addr_mac,
11688                 (void *)&cmd_set_vf_mac_addr_addr,
11689                 (void *)&cmd_set_vf_mac_addr_port_id,
11690                 (void *)&cmd_set_vf_mac_addr_vf_id,
11691                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11692                 NULL,
11693         },
11694 };
11695
11696 #ifdef RTE_LIBRTE_IXGBE_PMD
11697 /* MACsec configuration */
11698
11699 /* Common result structure for MACsec offload enable */
11700 struct cmd_macsec_offload_on_result {
11701         cmdline_fixed_string_t set;
11702         cmdline_fixed_string_t macsec;
11703         cmdline_fixed_string_t offload;
11704         uint8_t port_id;
11705         cmdline_fixed_string_t on;
11706         cmdline_fixed_string_t encrypt;
11707         cmdline_fixed_string_t en_on_off;
11708         cmdline_fixed_string_t replay_protect;
11709         cmdline_fixed_string_t rp_on_off;
11710 };
11711
11712 /* Common CLI fields for MACsec offload disable */
11713 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11714         TOKEN_STRING_INITIALIZER
11715                 (struct cmd_macsec_offload_on_result,
11716                  set, "set");
11717 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11718         TOKEN_STRING_INITIALIZER
11719                 (struct cmd_macsec_offload_on_result,
11720                  macsec, "macsec");
11721 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11722         TOKEN_STRING_INITIALIZER
11723                 (struct cmd_macsec_offload_on_result,
11724                  offload, "offload");
11725 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11726         TOKEN_NUM_INITIALIZER
11727                 (struct cmd_macsec_offload_on_result,
11728                  port_id, UINT8);
11729 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11730         TOKEN_STRING_INITIALIZER
11731                 (struct cmd_macsec_offload_on_result,
11732                  on, "on");
11733 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11734         TOKEN_STRING_INITIALIZER
11735                 (struct cmd_macsec_offload_on_result,
11736                  encrypt, "encrypt");
11737 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11738         TOKEN_STRING_INITIALIZER
11739                 (struct cmd_macsec_offload_on_result,
11740                  en_on_off, "on#off");
11741 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11742         TOKEN_STRING_INITIALIZER
11743                 (struct cmd_macsec_offload_on_result,
11744                  replay_protect, "replay-protect");
11745 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11746         TOKEN_STRING_INITIALIZER
11747                 (struct cmd_macsec_offload_on_result,
11748                  rp_on_off, "on#off");
11749
11750 static void
11751 cmd_set_macsec_offload_on_parsed(
11752         void *parsed_result,
11753         __attribute__((unused)) struct cmdline *cl,
11754         __attribute__((unused)) void *data)
11755 {
11756         struct cmd_macsec_offload_on_result *res = parsed_result;
11757         int ret;
11758         portid_t port_id = res->port_id;
11759         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11760         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11761
11762         if (port_id_is_invalid(port_id, ENABLED_WARN))
11763                 return;
11764
11765         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
11766         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11767
11768         switch (ret) {
11769         case 0:
11770                 break;
11771         case -ENODEV:
11772                 printf("invalid port_id %d\n", port_id);
11773                 break;
11774         default:
11775                 printf("programming error: (%s)\n", strerror(-ret));
11776         }
11777 }
11778
11779 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11780         .f = cmd_set_macsec_offload_on_parsed,
11781         .data = NULL,
11782         .help_str = "set macsec offload <port_id> on "
11783                 "encrypt on|off replay-protect on|off",
11784         .tokens = {
11785                 (void *)&cmd_macsec_offload_on_set,
11786                 (void *)&cmd_macsec_offload_on_macsec,
11787                 (void *)&cmd_macsec_offload_on_offload,
11788                 (void *)&cmd_macsec_offload_on_port_id,
11789                 (void *)&cmd_macsec_offload_on_on,
11790                 (void *)&cmd_macsec_offload_on_encrypt,
11791                 (void *)&cmd_macsec_offload_on_en_on_off,
11792                 (void *)&cmd_macsec_offload_on_replay_protect,
11793                 (void *)&cmd_macsec_offload_on_rp_on_off,
11794                 NULL,
11795         },
11796 };
11797
11798 /* Common result structure for MACsec offload disable */
11799 struct cmd_macsec_offload_off_result {
11800         cmdline_fixed_string_t set;
11801         cmdline_fixed_string_t macsec;
11802         cmdline_fixed_string_t offload;
11803         uint8_t port_id;
11804         cmdline_fixed_string_t off;
11805 };
11806
11807 /* Common CLI fields for MACsec offload disable */
11808 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11809         TOKEN_STRING_INITIALIZER
11810                 (struct cmd_macsec_offload_off_result,
11811                  set, "set");
11812 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11813         TOKEN_STRING_INITIALIZER
11814                 (struct cmd_macsec_offload_off_result,
11815                  macsec, "macsec");
11816 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11817         TOKEN_STRING_INITIALIZER
11818                 (struct cmd_macsec_offload_off_result,
11819                  offload, "offload");
11820 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11821         TOKEN_NUM_INITIALIZER
11822                 (struct cmd_macsec_offload_off_result,
11823                  port_id, UINT8);
11824 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11825         TOKEN_STRING_INITIALIZER
11826                 (struct cmd_macsec_offload_off_result,
11827                  off, "off");
11828
11829 static void
11830 cmd_set_macsec_offload_off_parsed(
11831         void *parsed_result,
11832         __attribute__((unused)) struct cmdline *cl,
11833         __attribute__((unused)) void *data)
11834 {
11835         struct cmd_macsec_offload_off_result *res = parsed_result;
11836         int ret;
11837         portid_t port_id = res->port_id;
11838
11839         if (port_id_is_invalid(port_id, ENABLED_WARN))
11840                 return;
11841
11842         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
11843         ret = rte_pmd_ixgbe_macsec_disable(port_id);
11844
11845         switch (ret) {
11846         case 0:
11847                 break;
11848         case -ENODEV:
11849                 printf("invalid port_id %d\n", port_id);
11850                 break;
11851         default:
11852                 printf("programming error: (%s)\n", strerror(-ret));
11853         }
11854 }
11855
11856 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11857         .f = cmd_set_macsec_offload_off_parsed,
11858         .data = NULL,
11859         .help_str = "set macsec offload <port_id> off",
11860         .tokens = {
11861                 (void *)&cmd_macsec_offload_off_set,
11862                 (void *)&cmd_macsec_offload_off_macsec,
11863                 (void *)&cmd_macsec_offload_off_offload,
11864                 (void *)&cmd_macsec_offload_off_port_id,
11865                 (void *)&cmd_macsec_offload_off_off,
11866                 NULL,
11867         },
11868 };
11869
11870 /* Common result structure for MACsec secure connection configure */
11871 struct cmd_macsec_sc_result {
11872         cmdline_fixed_string_t set;
11873         cmdline_fixed_string_t macsec;
11874         cmdline_fixed_string_t sc;
11875         cmdline_fixed_string_t tx_rx;
11876         uint8_t port_id;
11877         struct ether_addr mac;
11878         uint16_t pi;
11879 };
11880
11881 /* Common CLI fields for MACsec secure connection configure */
11882 cmdline_parse_token_string_t cmd_macsec_sc_set =
11883         TOKEN_STRING_INITIALIZER
11884                 (struct cmd_macsec_sc_result,
11885                  set, "set");
11886 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11887         TOKEN_STRING_INITIALIZER
11888                 (struct cmd_macsec_sc_result,
11889                  macsec, "macsec");
11890 cmdline_parse_token_string_t cmd_macsec_sc_sc =
11891         TOKEN_STRING_INITIALIZER
11892                 (struct cmd_macsec_sc_result,
11893                  sc, "sc");
11894 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11895         TOKEN_STRING_INITIALIZER
11896                 (struct cmd_macsec_sc_result,
11897                  tx_rx, "tx#rx");
11898 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11899         TOKEN_NUM_INITIALIZER
11900                 (struct cmd_macsec_sc_result,
11901                  port_id, UINT8);
11902 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11903         TOKEN_ETHERADDR_INITIALIZER
11904                 (struct cmd_macsec_sc_result,
11905                  mac);
11906 cmdline_parse_token_num_t cmd_macsec_sc_pi =
11907         TOKEN_NUM_INITIALIZER
11908                 (struct cmd_macsec_sc_result,
11909                  pi, UINT16);
11910
11911 static void
11912 cmd_set_macsec_sc_parsed(
11913         void *parsed_result,
11914         __attribute__((unused)) struct cmdline *cl,
11915         __attribute__((unused)) void *data)
11916 {
11917         struct cmd_macsec_sc_result *res = parsed_result;
11918         int ret;
11919         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11920
11921         ret = is_tx ?
11922                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
11923                                 res->mac.addr_bytes) :
11924                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
11925                                 res->mac.addr_bytes, res->pi);
11926         switch (ret) {
11927         case 0:
11928                 break;
11929         case -ENODEV:
11930                 printf("invalid port_id %d\n", res->port_id);
11931                 break;
11932         default:
11933                 printf("programming error: (%s)\n", strerror(-ret));
11934         }
11935 }
11936
11937 cmdline_parse_inst_t cmd_set_macsec_sc = {
11938         .f = cmd_set_macsec_sc_parsed,
11939         .data = NULL,
11940         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
11941         .tokens = {
11942                 (void *)&cmd_macsec_sc_set,
11943                 (void *)&cmd_macsec_sc_macsec,
11944                 (void *)&cmd_macsec_sc_sc,
11945                 (void *)&cmd_macsec_sc_tx_rx,
11946                 (void *)&cmd_macsec_sc_port_id,
11947                 (void *)&cmd_macsec_sc_mac,
11948                 (void *)&cmd_macsec_sc_pi,
11949                 NULL,
11950         },
11951 };
11952
11953 /* Common result structure for MACsec secure connection configure */
11954 struct cmd_macsec_sa_result {
11955         cmdline_fixed_string_t set;
11956         cmdline_fixed_string_t macsec;
11957         cmdline_fixed_string_t sa;
11958         cmdline_fixed_string_t tx_rx;
11959         uint8_t port_id;
11960         uint8_t idx;
11961         uint8_t an;
11962         uint32_t pn;
11963         cmdline_fixed_string_t key;
11964 };
11965
11966 /* Common CLI fields for MACsec secure connection configure */
11967 cmdline_parse_token_string_t cmd_macsec_sa_set =
11968         TOKEN_STRING_INITIALIZER
11969                 (struct cmd_macsec_sa_result,
11970                  set, "set");
11971 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
11972         TOKEN_STRING_INITIALIZER
11973                 (struct cmd_macsec_sa_result,
11974                  macsec, "macsec");
11975 cmdline_parse_token_string_t cmd_macsec_sa_sa =
11976         TOKEN_STRING_INITIALIZER
11977                 (struct cmd_macsec_sa_result,
11978                  sa, "sa");
11979 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
11980         TOKEN_STRING_INITIALIZER
11981                 (struct cmd_macsec_sa_result,
11982                  tx_rx, "tx#rx");
11983 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
11984         TOKEN_NUM_INITIALIZER
11985                 (struct cmd_macsec_sa_result,
11986                  port_id, UINT8);
11987 cmdline_parse_token_num_t cmd_macsec_sa_idx =
11988         TOKEN_NUM_INITIALIZER
11989                 (struct cmd_macsec_sa_result,
11990                  idx, UINT8);
11991 cmdline_parse_token_num_t cmd_macsec_sa_an =
11992         TOKEN_NUM_INITIALIZER
11993                 (struct cmd_macsec_sa_result,
11994                  an, UINT8);
11995 cmdline_parse_token_num_t cmd_macsec_sa_pn =
11996         TOKEN_NUM_INITIALIZER
11997                 (struct cmd_macsec_sa_result,
11998                  pn, UINT32);
11999 cmdline_parse_token_string_t cmd_macsec_sa_key =
12000         TOKEN_STRING_INITIALIZER
12001                 (struct cmd_macsec_sa_result,
12002                  key, NULL);
12003
12004 static void
12005 cmd_set_macsec_sa_parsed(
12006         void *parsed_result,
12007         __attribute__((unused)) struct cmdline *cl,
12008         __attribute__((unused)) void *data)
12009 {
12010         struct cmd_macsec_sa_result *res = parsed_result;
12011         int ret;
12012         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12013         uint8_t key[16] = { 0 };
12014         uint8_t xdgt0;
12015         uint8_t xdgt1;
12016         int key_len;
12017         int i;
12018
12019         key_len = strlen(res->key) / 2;
12020         if (key_len > 16)
12021                 key_len = 16;
12022
12023         for (i = 0; i < key_len; i++) {
12024                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12025                 if (xdgt0 == 0xFF)
12026                         return;
12027                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12028                 if (xdgt1 == 0xFF)
12029                         return;
12030                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12031         }
12032
12033         ret = is_tx ?
12034                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12035                         res->idx, res->an, res->pn, key) :
12036                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12037                         res->idx, res->an, res->pn, key);
12038         switch (ret) {
12039         case 0:
12040                 break;
12041         case -EINVAL:
12042                 printf("invalid idx %d or an %d\n", res->idx, res->an);
12043                 break;
12044         case -ENODEV:
12045                 printf("invalid port_id %d\n", res->port_id);
12046                 break;
12047         default:
12048                 printf("programming error: (%s)\n", strerror(-ret));
12049         }
12050 }
12051
12052 cmdline_parse_inst_t cmd_set_macsec_sa = {
12053         .f = cmd_set_macsec_sa_parsed,
12054         .data = NULL,
12055         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12056         .tokens = {
12057                 (void *)&cmd_macsec_sa_set,
12058                 (void *)&cmd_macsec_sa_macsec,
12059                 (void *)&cmd_macsec_sa_sa,
12060                 (void *)&cmd_macsec_sa_tx_rx,
12061                 (void *)&cmd_macsec_sa_port_id,
12062                 (void *)&cmd_macsec_sa_idx,
12063                 (void *)&cmd_macsec_sa_an,
12064                 (void *)&cmd_macsec_sa_pn,
12065                 (void *)&cmd_macsec_sa_key,
12066                 NULL,
12067         },
12068 };
12069 #endif
12070
12071 /* VF unicast promiscuous mode configuration */
12072
12073 /* Common result structure for VF unicast promiscuous mode */
12074 struct cmd_vf_promisc_result {
12075         cmdline_fixed_string_t set;
12076         cmdline_fixed_string_t vf;
12077         cmdline_fixed_string_t promisc;
12078         uint8_t port_id;
12079         uint32_t vf_id;
12080         cmdline_fixed_string_t on_off;
12081 };
12082
12083 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12084 cmdline_parse_token_string_t cmd_vf_promisc_set =
12085         TOKEN_STRING_INITIALIZER
12086                 (struct cmd_vf_promisc_result,
12087                  set, "set");
12088 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12089         TOKEN_STRING_INITIALIZER
12090                 (struct cmd_vf_promisc_result,
12091                  vf, "vf");
12092 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12093         TOKEN_STRING_INITIALIZER
12094                 (struct cmd_vf_promisc_result,
12095                  promisc, "promisc");
12096 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12097         TOKEN_NUM_INITIALIZER
12098                 (struct cmd_vf_promisc_result,
12099                  port_id, UINT8);
12100 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12101         TOKEN_NUM_INITIALIZER
12102                 (struct cmd_vf_promisc_result,
12103                  vf_id, UINT32);
12104 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12105         TOKEN_STRING_INITIALIZER
12106                 (struct cmd_vf_promisc_result,
12107                  on_off, "on#off");
12108
12109 static void
12110 cmd_set_vf_promisc_parsed(
12111         void *parsed_result,
12112         __attribute__((unused)) struct cmdline *cl,
12113         __attribute__((unused)) void *data)
12114 {
12115         struct cmd_vf_promisc_result *res = parsed_result;
12116         int ret = -ENOTSUP;
12117
12118         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12119
12120         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12121                 return;
12122
12123 #ifdef RTE_LIBRTE_I40E_PMD
12124         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12125                                                   res->vf_id, is_on);
12126 #endif
12127
12128         switch (ret) {
12129         case 0:
12130                 break;
12131         case -EINVAL:
12132                 printf("invalid vf_id %d\n", res->vf_id);
12133                 break;
12134         case -ENODEV:
12135                 printf("invalid port_id %d\n", res->port_id);
12136                 break;
12137         case -ENOTSUP:
12138                 printf("function not implemented\n");
12139                 break;
12140         default:
12141                 printf("programming error: (%s)\n", strerror(-ret));
12142         }
12143 }
12144
12145 cmdline_parse_inst_t cmd_set_vf_promisc = {
12146         .f = cmd_set_vf_promisc_parsed,
12147         .data = NULL,
12148         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12149                 "Set unicast promiscuous mode for a VF from the PF",
12150         .tokens = {
12151                 (void *)&cmd_vf_promisc_set,
12152                 (void *)&cmd_vf_promisc_vf,
12153                 (void *)&cmd_vf_promisc_promisc,
12154                 (void *)&cmd_vf_promisc_port_id,
12155                 (void *)&cmd_vf_promisc_vf_id,
12156                 (void *)&cmd_vf_promisc_on_off,
12157                 NULL,
12158         },
12159 };
12160
12161 /* VF multicast promiscuous mode configuration */
12162
12163 /* Common result structure for VF multicast promiscuous mode */
12164 struct cmd_vf_allmulti_result {
12165         cmdline_fixed_string_t set;
12166         cmdline_fixed_string_t vf;
12167         cmdline_fixed_string_t allmulti;
12168         uint8_t port_id;
12169         uint32_t vf_id;
12170         cmdline_fixed_string_t on_off;
12171 };
12172
12173 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12174 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12175         TOKEN_STRING_INITIALIZER
12176                 (struct cmd_vf_allmulti_result,
12177                  set, "set");
12178 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12179         TOKEN_STRING_INITIALIZER
12180                 (struct cmd_vf_allmulti_result,
12181                  vf, "vf");
12182 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12183         TOKEN_STRING_INITIALIZER
12184                 (struct cmd_vf_allmulti_result,
12185                  allmulti, "allmulti");
12186 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12187         TOKEN_NUM_INITIALIZER
12188                 (struct cmd_vf_allmulti_result,
12189                  port_id, UINT8);
12190 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12191         TOKEN_NUM_INITIALIZER
12192                 (struct cmd_vf_allmulti_result,
12193                  vf_id, UINT32);
12194 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12195         TOKEN_STRING_INITIALIZER
12196                 (struct cmd_vf_allmulti_result,
12197                  on_off, "on#off");
12198
12199 static void
12200 cmd_set_vf_allmulti_parsed(
12201         void *parsed_result,
12202         __attribute__((unused)) struct cmdline *cl,
12203         __attribute__((unused)) void *data)
12204 {
12205         struct cmd_vf_allmulti_result *res = parsed_result;
12206         int ret = -ENOTSUP;
12207
12208         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12209
12210         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12211                 return;
12212
12213 #ifdef RTE_LIBRTE_I40E_PMD
12214         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12215                                                     res->vf_id, is_on);
12216 #endif
12217
12218         switch (ret) {
12219         case 0:
12220                 break;
12221         case -EINVAL:
12222                 printf("invalid vf_id %d\n", res->vf_id);
12223                 break;
12224         case -ENODEV:
12225                 printf("invalid port_id %d\n", res->port_id);
12226                 break;
12227         case -ENOTSUP:
12228                 printf("function not implemented\n");
12229                 break;
12230         default:
12231                 printf("programming error: (%s)\n", strerror(-ret));
12232         }
12233 }
12234
12235 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12236         .f = cmd_set_vf_allmulti_parsed,
12237         .data = NULL,
12238         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12239                 "Set multicast promiscuous mode for a VF from the PF",
12240         .tokens = {
12241                 (void *)&cmd_vf_allmulti_set,
12242                 (void *)&cmd_vf_allmulti_vf,
12243                 (void *)&cmd_vf_allmulti_allmulti,
12244                 (void *)&cmd_vf_allmulti_port_id,
12245                 (void *)&cmd_vf_allmulti_vf_id,
12246                 (void *)&cmd_vf_allmulti_on_off,
12247                 NULL,
12248         },
12249 };
12250
12251 /* vf broadcast mode configuration */
12252
12253 /* Common result structure for vf broadcast */
12254 struct cmd_set_vf_broadcast_result {
12255         cmdline_fixed_string_t set;
12256         cmdline_fixed_string_t vf;
12257         cmdline_fixed_string_t broadcast;
12258         uint8_t port_id;
12259         uint16_t vf_id;
12260         cmdline_fixed_string_t on_off;
12261 };
12262
12263 /* Common CLI fields for vf broadcast enable disable */
12264 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12265         TOKEN_STRING_INITIALIZER
12266                 (struct cmd_set_vf_broadcast_result,
12267                  set, "set");
12268 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12269         TOKEN_STRING_INITIALIZER
12270                 (struct cmd_set_vf_broadcast_result,
12271                  vf, "vf");
12272 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12273         TOKEN_STRING_INITIALIZER
12274                 (struct cmd_set_vf_broadcast_result,
12275                  broadcast, "broadcast");
12276 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12277         TOKEN_NUM_INITIALIZER
12278                 (struct cmd_set_vf_broadcast_result,
12279                  port_id, UINT8);
12280 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12281         TOKEN_NUM_INITIALIZER
12282                 (struct cmd_set_vf_broadcast_result,
12283                  vf_id, UINT16);
12284 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12285         TOKEN_STRING_INITIALIZER
12286                 (struct cmd_set_vf_broadcast_result,
12287                  on_off, "on#off");
12288
12289 static void
12290 cmd_set_vf_broadcast_parsed(
12291         void *parsed_result,
12292         __attribute__((unused)) struct cmdline *cl,
12293         __attribute__((unused)) void *data)
12294 {
12295         struct cmd_set_vf_broadcast_result *res = parsed_result;
12296         int ret = -ENOTSUP;
12297
12298         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12299
12300         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12301                 return;
12302
12303 #ifdef RTE_LIBRTE_I40E_PMD
12304         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12305                                             res->vf_id, is_on);
12306 #endif
12307
12308         switch (ret) {
12309         case 0:
12310                 break;
12311         case -EINVAL:
12312                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12313                 break;
12314         case -ENODEV:
12315                 printf("invalid port_id %d\n", res->port_id);
12316                 break;
12317         case -ENOTSUP:
12318                 printf("function not implemented\n");
12319                 break;
12320         default:
12321                 printf("programming error: (%s)\n", strerror(-ret));
12322         }
12323 }
12324
12325 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12326         .f = cmd_set_vf_broadcast_parsed,
12327         .data = NULL,
12328         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12329         .tokens = {
12330                 (void *)&cmd_set_vf_broadcast_set,
12331                 (void *)&cmd_set_vf_broadcast_vf,
12332                 (void *)&cmd_set_vf_broadcast_broadcast,
12333                 (void *)&cmd_set_vf_broadcast_port_id,
12334                 (void *)&cmd_set_vf_broadcast_vf_id,
12335                 (void *)&cmd_set_vf_broadcast_on_off,
12336                 NULL,
12337         },
12338 };
12339
12340 /* vf vlan tag configuration */
12341
12342 /* Common result structure for vf vlan tag */
12343 struct cmd_set_vf_vlan_tag_result {
12344         cmdline_fixed_string_t set;
12345         cmdline_fixed_string_t vf;
12346         cmdline_fixed_string_t vlan;
12347         cmdline_fixed_string_t tag;
12348         uint8_t port_id;
12349         uint16_t vf_id;
12350         cmdline_fixed_string_t on_off;
12351 };
12352
12353 /* Common CLI fields for vf vlan tag enable disable */
12354 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12355         TOKEN_STRING_INITIALIZER
12356                 (struct cmd_set_vf_vlan_tag_result,
12357                  set, "set");
12358 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12359         TOKEN_STRING_INITIALIZER
12360                 (struct cmd_set_vf_vlan_tag_result,
12361                  vf, "vf");
12362 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12363         TOKEN_STRING_INITIALIZER
12364                 (struct cmd_set_vf_vlan_tag_result,
12365                  vlan, "vlan");
12366 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12367         TOKEN_STRING_INITIALIZER
12368                 (struct cmd_set_vf_vlan_tag_result,
12369                  tag, "tag");
12370 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12371         TOKEN_NUM_INITIALIZER
12372                 (struct cmd_set_vf_vlan_tag_result,
12373                  port_id, UINT8);
12374 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12375         TOKEN_NUM_INITIALIZER
12376                 (struct cmd_set_vf_vlan_tag_result,
12377                  vf_id, UINT16);
12378 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12379         TOKEN_STRING_INITIALIZER
12380                 (struct cmd_set_vf_vlan_tag_result,
12381                  on_off, "on#off");
12382
12383 static void
12384 cmd_set_vf_vlan_tag_parsed(
12385         void *parsed_result,
12386         __attribute__((unused)) struct cmdline *cl,
12387         __attribute__((unused)) void *data)
12388 {
12389         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12390         int ret = -ENOTSUP;
12391
12392         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12393
12394         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12395                 return;
12396
12397 #ifdef RTE_LIBRTE_I40E_PMD
12398         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12399                                            res->vf_id, is_on);
12400 #endif
12401
12402         switch (ret) {
12403         case 0:
12404                 break;
12405         case -EINVAL:
12406                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12407                 break;
12408         case -ENODEV:
12409                 printf("invalid port_id %d\n", res->port_id);
12410                 break;
12411         case -ENOTSUP:
12412                 printf("function not implemented\n");
12413                 break;
12414         default:
12415                 printf("programming error: (%s)\n", strerror(-ret));
12416         }
12417 }
12418
12419 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12420         .f = cmd_set_vf_vlan_tag_parsed,
12421         .data = NULL,
12422         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12423         .tokens = {
12424                 (void *)&cmd_set_vf_vlan_tag_set,
12425                 (void *)&cmd_set_vf_vlan_tag_vf,
12426                 (void *)&cmd_set_vf_vlan_tag_vlan,
12427                 (void *)&cmd_set_vf_vlan_tag_tag,
12428                 (void *)&cmd_set_vf_vlan_tag_port_id,
12429                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12430                 (void *)&cmd_set_vf_vlan_tag_on_off,
12431                 NULL,
12432         },
12433 };
12434
12435 /* Common definition of VF and TC TX bandwidth configuration */
12436 struct cmd_vf_tc_bw_result {
12437         cmdline_fixed_string_t set;
12438         cmdline_fixed_string_t vf;
12439         cmdline_fixed_string_t tc;
12440         cmdline_fixed_string_t tx;
12441         cmdline_fixed_string_t min_bw;
12442         cmdline_fixed_string_t max_bw;
12443         cmdline_fixed_string_t strict_link_prio;
12444         uint8_t port_id;
12445         uint16_t vf_id;
12446         uint8_t tc_no;
12447         uint32_t bw;
12448         cmdline_fixed_string_t bw_list;
12449         uint8_t tc_map;
12450 };
12451
12452 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12453         TOKEN_STRING_INITIALIZER
12454                 (struct cmd_vf_tc_bw_result,
12455                  set, "set");
12456 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12457         TOKEN_STRING_INITIALIZER
12458                 (struct cmd_vf_tc_bw_result,
12459                  vf, "vf");
12460 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12461         TOKEN_STRING_INITIALIZER
12462                 (struct cmd_vf_tc_bw_result,
12463                  tc, "tc");
12464 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12465         TOKEN_STRING_INITIALIZER
12466                 (struct cmd_vf_tc_bw_result,
12467                  tx, "tx");
12468 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12469         TOKEN_STRING_INITIALIZER
12470                 (struct cmd_vf_tc_bw_result,
12471                  strict_link_prio, "strict-link-priority");
12472 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12473         TOKEN_STRING_INITIALIZER
12474                 (struct cmd_vf_tc_bw_result,
12475                  min_bw, "min-bandwidth");
12476 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12477         TOKEN_STRING_INITIALIZER
12478                 (struct cmd_vf_tc_bw_result,
12479                  max_bw, "max-bandwidth");
12480 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12481         TOKEN_NUM_INITIALIZER
12482                 (struct cmd_vf_tc_bw_result,
12483                  port_id, UINT8);
12484 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12485         TOKEN_NUM_INITIALIZER
12486                 (struct cmd_vf_tc_bw_result,
12487                  vf_id, UINT16);
12488 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12489         TOKEN_NUM_INITIALIZER
12490                 (struct cmd_vf_tc_bw_result,
12491                  tc_no, UINT8);
12492 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12493         TOKEN_NUM_INITIALIZER
12494                 (struct cmd_vf_tc_bw_result,
12495                  bw, UINT32);
12496 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12497         TOKEN_STRING_INITIALIZER
12498                 (struct cmd_vf_tc_bw_result,
12499                  bw_list, NULL);
12500 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12501         TOKEN_NUM_INITIALIZER
12502                 (struct cmd_vf_tc_bw_result,
12503                  tc_map, UINT8);
12504
12505 /* VF max bandwidth setting */
12506 static void
12507 cmd_vf_max_bw_parsed(
12508         void *parsed_result,
12509         __attribute__((unused)) struct cmdline *cl,
12510         __attribute__((unused)) void *data)
12511 {
12512         struct cmd_vf_tc_bw_result *res = parsed_result;
12513         int ret = -ENOTSUP;
12514
12515         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12516                 return;
12517
12518 #ifdef RTE_LIBRTE_I40E_PMD
12519         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12520                                          res->vf_id, res->bw);
12521 #endif
12522
12523         switch (ret) {
12524         case 0:
12525                 break;
12526         case -EINVAL:
12527                 printf("invalid vf_id %d or bandwidth %d\n",
12528                        res->vf_id, res->bw);
12529                 break;
12530         case -ENODEV:
12531                 printf("invalid port_id %d\n", res->port_id);
12532                 break;
12533         case -ENOTSUP:
12534                 printf("function not implemented\n");
12535                 break;
12536         default:
12537                 printf("programming error: (%s)\n", strerror(-ret));
12538         }
12539 }
12540
12541 cmdline_parse_inst_t cmd_vf_max_bw = {
12542         .f = cmd_vf_max_bw_parsed,
12543         .data = NULL,
12544         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12545         .tokens = {
12546                 (void *)&cmd_vf_tc_bw_set,
12547                 (void *)&cmd_vf_tc_bw_vf,
12548                 (void *)&cmd_vf_tc_bw_tx,
12549                 (void *)&cmd_vf_tc_bw_max_bw,
12550                 (void *)&cmd_vf_tc_bw_port_id,
12551                 (void *)&cmd_vf_tc_bw_vf_id,
12552                 (void *)&cmd_vf_tc_bw_bw,
12553                 NULL,
12554         },
12555 };
12556
12557 static int
12558 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12559                            uint8_t *tc_num,
12560                            char *str)
12561 {
12562         uint32_t size;
12563         const char *p, *p0 = str;
12564         char s[256];
12565         char *end;
12566         char *str_fld[16];
12567         uint16_t i;
12568         int ret;
12569
12570         p = strchr(p0, '(');
12571         if (p == NULL) {
12572                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12573                 return -1;
12574         }
12575         p++;
12576         p0 = strchr(p, ')');
12577         if (p0 == NULL) {
12578                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12579                 return -1;
12580         }
12581         size = p0 - p;
12582         if (size >= sizeof(s)) {
12583                 printf("The string size exceeds the internal buffer size\n");
12584                 return -1;
12585         }
12586         snprintf(s, sizeof(s), "%.*s", size, p);
12587         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12588         if (ret <= 0) {
12589                 printf("Failed to get the bandwidth list. ");
12590                 return -1;
12591         }
12592         *tc_num = ret;
12593         for (i = 0; i < ret; i++)
12594                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12595
12596         return 0;
12597 }
12598
12599 /* TC min bandwidth setting */
12600 static void
12601 cmd_vf_tc_min_bw_parsed(
12602         void *parsed_result,
12603         __attribute__((unused)) struct cmdline *cl,
12604         __attribute__((unused)) void *data)
12605 {
12606         struct cmd_vf_tc_bw_result *res = parsed_result;
12607         uint8_t tc_num;
12608         uint8_t bw[16];
12609         int ret = -ENOTSUP;
12610
12611         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12612                 return;
12613
12614         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12615         if (ret)
12616                 return;
12617
12618 #ifdef RTE_LIBRTE_I40E_PMD
12619         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12620                                               tc_num, bw);
12621 #endif
12622
12623         switch (ret) {
12624         case 0:
12625                 break;
12626         case -EINVAL:
12627                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
12628                 break;
12629         case -ENODEV:
12630                 printf("invalid port_id %d\n", res->port_id);
12631                 break;
12632         case -ENOTSUP:
12633                 printf("function not implemented\n");
12634                 break;
12635         default:
12636                 printf("programming error: (%s)\n", strerror(-ret));
12637         }
12638 }
12639
12640 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12641         .f = cmd_vf_tc_min_bw_parsed,
12642         .data = NULL,
12643         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12644                     " <bw1, bw2, ...>",
12645         .tokens = {
12646                 (void *)&cmd_vf_tc_bw_set,
12647                 (void *)&cmd_vf_tc_bw_vf,
12648                 (void *)&cmd_vf_tc_bw_tc,
12649                 (void *)&cmd_vf_tc_bw_tx,
12650                 (void *)&cmd_vf_tc_bw_min_bw,
12651                 (void *)&cmd_vf_tc_bw_port_id,
12652                 (void *)&cmd_vf_tc_bw_vf_id,
12653                 (void *)&cmd_vf_tc_bw_bw_list,
12654                 NULL,
12655         },
12656 };
12657
12658 static void
12659 cmd_tc_min_bw_parsed(
12660         void *parsed_result,
12661         __attribute__((unused)) struct cmdline *cl,
12662         __attribute__((unused)) void *data)
12663 {
12664         struct cmd_vf_tc_bw_result *res = parsed_result;
12665         struct rte_port *port;
12666         uint8_t tc_num;
12667         uint8_t bw[16];
12668         int ret = -ENOTSUP;
12669
12670         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12671                 return;
12672
12673         port = &ports[res->port_id];
12674         /** Check if the port is not started **/
12675         if (port->port_status != RTE_PORT_STOPPED) {
12676                 printf("Please stop port %d first\n", res->port_id);
12677                 return;
12678         }
12679
12680         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12681         if (ret)
12682                 return;
12683
12684 #ifdef RTE_LIBRTE_IXGBE_PMD
12685         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12686 #endif
12687
12688         switch (ret) {
12689         case 0:
12690                 break;
12691         case -EINVAL:
12692                 printf("invalid bandwidth\n");
12693                 break;
12694         case -ENODEV:
12695                 printf("invalid port_id %d\n", res->port_id);
12696                 break;
12697         case -ENOTSUP:
12698                 printf("function not implemented\n");
12699                 break;
12700         default:
12701                 printf("programming error: (%s)\n", strerror(-ret));
12702         }
12703 }
12704
12705 cmdline_parse_inst_t cmd_tc_min_bw = {
12706         .f = cmd_tc_min_bw_parsed,
12707         .data = NULL,
12708         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12709         .tokens = {
12710                 (void *)&cmd_vf_tc_bw_set,
12711                 (void *)&cmd_vf_tc_bw_tc,
12712                 (void *)&cmd_vf_tc_bw_tx,
12713                 (void *)&cmd_vf_tc_bw_min_bw,
12714                 (void *)&cmd_vf_tc_bw_port_id,
12715                 (void *)&cmd_vf_tc_bw_bw_list,
12716                 NULL,
12717         },
12718 };
12719
12720 /* TC max bandwidth setting */
12721 static void
12722 cmd_vf_tc_max_bw_parsed(
12723         void *parsed_result,
12724         __attribute__((unused)) struct cmdline *cl,
12725         __attribute__((unused)) void *data)
12726 {
12727         struct cmd_vf_tc_bw_result *res = parsed_result;
12728         int ret = -ENOTSUP;
12729
12730         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12731                 return;
12732
12733 #ifdef RTE_LIBRTE_I40E_PMD
12734         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12735                                             res->tc_no, res->bw);
12736 #endif
12737
12738         switch (ret) {
12739         case 0:
12740                 break;
12741         case -EINVAL:
12742                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
12743                        res->vf_id, res->tc_no, res->bw);
12744                 break;
12745         case -ENODEV:
12746                 printf("invalid port_id %d\n", res->port_id);
12747                 break;
12748         case -ENOTSUP:
12749                 printf("function not implemented\n");
12750                 break;
12751         default:
12752                 printf("programming error: (%s)\n", strerror(-ret));
12753         }
12754 }
12755
12756 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12757         .f = cmd_vf_tc_max_bw_parsed,
12758         .data = NULL,
12759         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12760                     " <bandwidth>",
12761         .tokens = {
12762                 (void *)&cmd_vf_tc_bw_set,
12763                 (void *)&cmd_vf_tc_bw_vf,
12764                 (void *)&cmd_vf_tc_bw_tc,
12765                 (void *)&cmd_vf_tc_bw_tx,
12766                 (void *)&cmd_vf_tc_bw_max_bw,
12767                 (void *)&cmd_vf_tc_bw_port_id,
12768                 (void *)&cmd_vf_tc_bw_vf_id,
12769                 (void *)&cmd_vf_tc_bw_tc_no,
12770                 (void *)&cmd_vf_tc_bw_bw,
12771                 NULL,
12772         },
12773 };
12774
12775 /* Strict link priority scheduling mode setting */
12776 static void
12777 cmd_strict_link_prio_parsed(
12778         void *parsed_result,
12779         __attribute__((unused)) struct cmdline *cl,
12780         __attribute__((unused)) void *data)
12781 {
12782         struct cmd_vf_tc_bw_result *res = parsed_result;
12783         int ret = -ENOTSUP;
12784
12785         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12786                 return;
12787
12788 #ifdef RTE_LIBRTE_I40E_PMD
12789         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
12790 #endif
12791
12792         switch (ret) {
12793         case 0:
12794                 break;
12795         case -EINVAL:
12796                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
12797                 break;
12798         case -ENODEV:
12799                 printf("invalid port_id %d\n", res->port_id);
12800                 break;
12801         case -ENOTSUP:
12802                 printf("function not implemented\n");
12803                 break;
12804         default:
12805                 printf("programming error: (%s)\n", strerror(-ret));
12806         }
12807 }
12808
12809 cmdline_parse_inst_t cmd_strict_link_prio = {
12810         .f = cmd_strict_link_prio_parsed,
12811         .data = NULL,
12812         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
12813         .tokens = {
12814                 (void *)&cmd_vf_tc_bw_set,
12815                 (void *)&cmd_vf_tc_bw_tx,
12816                 (void *)&cmd_vf_tc_bw_strict_link_prio,
12817                 (void *)&cmd_vf_tc_bw_port_id,
12818                 (void *)&cmd_vf_tc_bw_tc_map,
12819                 NULL,
12820         },
12821 };
12822
12823 /* Load dynamic device personalization*/
12824 struct cmd_ddp_add_result {
12825         cmdline_fixed_string_t ddp;
12826         cmdline_fixed_string_t add;
12827         uint8_t port_id;
12828         char filepath[];
12829 };
12830
12831 cmdline_parse_token_string_t cmd_ddp_add_ddp =
12832         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
12833 cmdline_parse_token_string_t cmd_ddp_add_add =
12834         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
12835 cmdline_parse_token_num_t cmd_ddp_add_port_id =
12836         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8);
12837 cmdline_parse_token_string_t cmd_ddp_add_filepath =
12838         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
12839
12840 static void
12841 cmd_ddp_add_parsed(
12842         void *parsed_result,
12843         __attribute__((unused)) struct cmdline *cl,
12844         __attribute__((unused)) void *data)
12845 {
12846         struct cmd_ddp_add_result *res = parsed_result;
12847         uint8_t *buff;
12848         uint32_t size;
12849         int ret = -ENOTSUP;
12850
12851         if (res->port_id > nb_ports) {
12852                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
12853                 return;
12854         }
12855
12856         if (!all_ports_stopped()) {
12857                 printf("Please stop all ports first\n");
12858                 return;
12859         }
12860
12861         buff = open_ddp_package_file(res->filepath, &size);
12862         if (!buff)
12863                 return;
12864
12865 #ifdef RTE_LIBRTE_I40E_PMD
12866         if (ret == -ENOTSUP)
12867                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
12868                                                buff, size,
12869                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
12870 #endif
12871
12872         if (ret < 0)
12873                 printf("Failed to load profile.\n");
12874         else if (ret > 0)
12875                 printf("Profile has already existed.\n");
12876
12877         close_ddp_package_file(buff);
12878 }
12879
12880 cmdline_parse_inst_t cmd_ddp_add = {
12881         .f = cmd_ddp_add_parsed,
12882         .data = NULL,
12883         .help_str = "ddp add <port_id> <profile_path>",
12884         .tokens = {
12885                 (void *)&cmd_ddp_add_ddp,
12886                 (void *)&cmd_ddp_add_add,
12887                 (void *)&cmd_ddp_add_port_id,
12888                 (void *)&cmd_ddp_add_filepath,
12889                 NULL,
12890         },
12891 };
12892
12893 /* Get dynamic device personalization profile info list*/
12894 #define PROFILE_INFO_SIZE 48
12895 #define MAX_PROFILE_NUM 16
12896
12897 struct cmd_ddp_get_list_result {
12898         cmdline_fixed_string_t ddp;
12899         cmdline_fixed_string_t get;
12900         cmdline_fixed_string_t list;
12901         uint8_t port_id;
12902 };
12903
12904 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
12905         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
12906 cmdline_parse_token_string_t cmd_ddp_get_list_get =
12907         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
12908 cmdline_parse_token_string_t cmd_ddp_get_list_list =
12909         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
12910 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
12911         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8);
12912
12913 static void
12914 cmd_ddp_get_list_parsed(
12915         void *parsed_result,
12916         __attribute__((unused)) struct cmdline *cl,
12917         __attribute__((unused)) void *data)
12918 {
12919         struct cmd_ddp_get_list_result *res = parsed_result;
12920 #ifdef RTE_LIBRTE_I40E_PMD
12921         struct rte_pmd_i40e_profile_list *p_list;
12922         struct rte_pmd_i40e_profile_info *p_info;
12923         uint32_t p_num;
12924         uint32_t size;
12925         uint32_t i;
12926 #endif
12927         int ret = -ENOTSUP;
12928
12929         if (res->port_id > nb_ports) {
12930                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
12931                 return;
12932         }
12933
12934 #ifdef RTE_LIBRTE_I40E_PMD
12935         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
12936         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
12937         if (!p_list)
12938                 printf("%s: Failed to malloc buffer\n", __func__);
12939
12940         if (ret == -ENOTSUP)
12941                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
12942                                                 (uint8_t *)p_list, size);
12943
12944         if (!ret) {
12945                 p_num = p_list->p_count;
12946                 printf("Profile number is: %d\n\n", p_num);
12947
12948                 for (i = 0; i < p_num; i++) {
12949                         p_info = &p_list->p_info[i];
12950                         printf("Profile %d:\n", i);
12951                         printf("Track id:     0x%x\n", p_info->track_id);
12952                         printf("Version:      %d.%d.%d.%d\n",
12953                                p_info->version.major,
12954                                p_info->version.minor,
12955                                p_info->version.update,
12956                                p_info->version.draft);
12957                         printf("Profile name: %s\n\n", p_info->name);
12958                 }
12959         }
12960
12961         free(p_list);
12962 #endif
12963
12964         if (ret < 0)
12965                 printf("Failed to get ddp list\n");
12966 }
12967
12968 cmdline_parse_inst_t cmd_ddp_get_list = {
12969         .f = cmd_ddp_get_list_parsed,
12970         .data = NULL,
12971         .help_str = "ddp get list <port_id>",
12972         .tokens = {
12973                 (void *)&cmd_ddp_get_list_ddp,
12974                 (void *)&cmd_ddp_get_list_get,
12975                 (void *)&cmd_ddp_get_list_list,
12976                 (void *)&cmd_ddp_get_list_port_id,
12977                 NULL,
12978         },
12979 };
12980
12981 /* show vf stats */
12982
12983 /* Common result structure for show vf stats */
12984 struct cmd_show_vf_stats_result {
12985         cmdline_fixed_string_t show;
12986         cmdline_fixed_string_t vf;
12987         cmdline_fixed_string_t stats;
12988         uint8_t port_id;
12989         uint16_t vf_id;
12990 };
12991
12992 /* Common CLI fields show vf stats*/
12993 cmdline_parse_token_string_t cmd_show_vf_stats_show =
12994         TOKEN_STRING_INITIALIZER
12995                 (struct cmd_show_vf_stats_result,
12996                  show, "show");
12997 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
12998         TOKEN_STRING_INITIALIZER
12999                 (struct cmd_show_vf_stats_result,
13000                  vf, "vf");
13001 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
13002         TOKEN_STRING_INITIALIZER
13003                 (struct cmd_show_vf_stats_result,
13004                  stats, "stats");
13005 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
13006         TOKEN_NUM_INITIALIZER
13007                 (struct cmd_show_vf_stats_result,
13008                  port_id, UINT8);
13009 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
13010         TOKEN_NUM_INITIALIZER
13011                 (struct cmd_show_vf_stats_result,
13012                  vf_id, UINT16);
13013
13014 static void
13015 cmd_show_vf_stats_parsed(
13016         void *parsed_result,
13017         __attribute__((unused)) struct cmdline *cl,
13018         __attribute__((unused)) void *data)
13019 {
13020         struct cmd_show_vf_stats_result *res = parsed_result;
13021         struct rte_eth_stats stats;
13022         int ret = -ENOTSUP;
13023         static const char *nic_stats_border = "########################";
13024
13025         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13026                 return;
13027
13028         memset(&stats, 0, sizeof(stats));
13029
13030 #ifdef RTE_LIBRTE_I40E_PMD
13031         ret = rte_pmd_i40e_get_vf_stats(res->port_id,
13032                                         res->vf_id,
13033                                         &stats);
13034 #endif
13035
13036         switch (ret) {
13037         case 0:
13038                 break;
13039         case -EINVAL:
13040                 printf("invalid vf_id %d\n", res->vf_id);
13041                 break;
13042         case -ENODEV:
13043                 printf("invalid port_id %d\n", res->port_id);
13044                 break;
13045         case -ENOTSUP:
13046                 printf("function not implemented\n");
13047                 break;
13048         default:
13049                 printf("programming error: (%s)\n", strerror(-ret));
13050         }
13051
13052         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
13053                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
13054
13055         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
13056                "%-"PRIu64"\n",
13057                stats.ipackets, stats.imissed, stats.ibytes);
13058         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
13059         printf("  RX-nombuf:  %-10"PRIu64"\n",
13060                stats.rx_nombuf);
13061         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
13062                "%-"PRIu64"\n",
13063                stats.opackets, stats.oerrors, stats.obytes);
13064
13065         printf("  %s############################%s\n",
13066                                nic_stats_border, nic_stats_border);
13067 }
13068
13069 cmdline_parse_inst_t cmd_show_vf_stats = {
13070         .f = cmd_show_vf_stats_parsed,
13071         .data = NULL,
13072         .help_str = "show vf stats <port_id> <vf_id>",
13073         .tokens = {
13074                 (void *)&cmd_show_vf_stats_show,
13075                 (void *)&cmd_show_vf_stats_vf,
13076                 (void *)&cmd_show_vf_stats_stats,
13077                 (void *)&cmd_show_vf_stats_port_id,
13078                 (void *)&cmd_show_vf_stats_vf_id,
13079                 NULL,
13080         },
13081 };
13082
13083 /* clear vf stats */
13084
13085 /* Common result structure for clear vf stats */
13086 struct cmd_clear_vf_stats_result {
13087         cmdline_fixed_string_t clear;
13088         cmdline_fixed_string_t vf;
13089         cmdline_fixed_string_t stats;
13090         uint8_t port_id;
13091         uint16_t vf_id;
13092 };
13093
13094 /* Common CLI fields clear vf stats*/
13095 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
13096         TOKEN_STRING_INITIALIZER
13097                 (struct cmd_clear_vf_stats_result,
13098                  clear, "clear");
13099 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
13100         TOKEN_STRING_INITIALIZER
13101                 (struct cmd_clear_vf_stats_result,
13102                  vf, "vf");
13103 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
13104         TOKEN_STRING_INITIALIZER
13105                 (struct cmd_clear_vf_stats_result,
13106                  stats, "stats");
13107 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
13108         TOKEN_NUM_INITIALIZER
13109                 (struct cmd_clear_vf_stats_result,
13110                  port_id, UINT8);
13111 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
13112         TOKEN_NUM_INITIALIZER
13113                 (struct cmd_clear_vf_stats_result,
13114                  vf_id, UINT16);
13115
13116 static void
13117 cmd_clear_vf_stats_parsed(
13118         void *parsed_result,
13119         __attribute__((unused)) struct cmdline *cl,
13120         __attribute__((unused)) void *data)
13121 {
13122         struct cmd_clear_vf_stats_result *res = parsed_result;
13123         int ret = -ENOTSUP;
13124
13125         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13126                 return;
13127
13128 #ifdef RTE_LIBRTE_I40E_PMD
13129         ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
13130                                           res->vf_id);
13131 #endif
13132
13133         switch (ret) {
13134         case 0:
13135                 break;
13136         case -EINVAL:
13137                 printf("invalid vf_id %d\n", res->vf_id);
13138                 break;
13139         case -ENODEV:
13140                 printf("invalid port_id %d\n", res->port_id);
13141                 break;
13142         case -ENOTSUP:
13143                 printf("function not implemented\n");
13144                 break;
13145         default:
13146                 printf("programming error: (%s)\n", strerror(-ret));
13147         }
13148 }
13149
13150 cmdline_parse_inst_t cmd_clear_vf_stats = {
13151         .f = cmd_clear_vf_stats_parsed,
13152         .data = NULL,
13153         .help_str = "clear vf stats <port_id> <vf_id>",
13154         .tokens = {
13155                 (void *)&cmd_clear_vf_stats_clear,
13156                 (void *)&cmd_clear_vf_stats_vf,
13157                 (void *)&cmd_clear_vf_stats_stats,
13158                 (void *)&cmd_clear_vf_stats_port_id,
13159                 (void *)&cmd_clear_vf_stats_vf_id,
13160                 NULL,
13161         },
13162 };
13163
13164 /* ******************************************************************************** */
13165
13166 /* list of instructions */
13167 cmdline_parse_ctx_t main_ctx[] = {
13168         (cmdline_parse_inst_t *)&cmd_help_brief,
13169         (cmdline_parse_inst_t *)&cmd_help_long,
13170         (cmdline_parse_inst_t *)&cmd_quit,
13171         (cmdline_parse_inst_t *)&cmd_showport,
13172         (cmdline_parse_inst_t *)&cmd_showqueue,
13173         (cmdline_parse_inst_t *)&cmd_showportall,
13174         (cmdline_parse_inst_t *)&cmd_showcfg,
13175         (cmdline_parse_inst_t *)&cmd_start,
13176         (cmdline_parse_inst_t *)&cmd_start_tx_first,
13177         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
13178         (cmdline_parse_inst_t *)&cmd_set_link_up,
13179         (cmdline_parse_inst_t *)&cmd_set_link_down,
13180         (cmdline_parse_inst_t *)&cmd_reset,
13181         (cmdline_parse_inst_t *)&cmd_set_numbers,
13182         (cmdline_parse_inst_t *)&cmd_set_txpkts,
13183         (cmdline_parse_inst_t *)&cmd_set_txsplit,
13184         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
13185         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
13186         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
13187         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
13188         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
13189         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
13190         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
13191         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
13192         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
13193         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
13194         (cmdline_parse_inst_t *)&cmd_set_link_check,
13195 #ifdef RTE_NIC_BYPASS
13196         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
13197         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
13198         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
13199         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
13200 #endif
13201 #ifdef RTE_LIBRTE_PMD_BOND
13202         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
13203         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
13204         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
13205         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
13206         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
13207         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
13208         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
13209         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
13210         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
13211 #endif
13212         (cmdline_parse_inst_t *)&cmd_vlan_offload,
13213         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
13214         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
13215         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
13216         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
13217         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
13218         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
13219         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
13220         (cmdline_parse_inst_t *)&cmd_csum_set,
13221         (cmdline_parse_inst_t *)&cmd_csum_show,
13222         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
13223         (cmdline_parse_inst_t *)&cmd_tso_set,
13224         (cmdline_parse_inst_t *)&cmd_tso_show,
13225         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
13226         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
13227         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
13228         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
13229         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
13230         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
13231         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
13232         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
13233         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
13234         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
13235         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
13236         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
13237         (cmdline_parse_inst_t *)&cmd_config_dcb,
13238         (cmdline_parse_inst_t *)&cmd_read_reg,
13239         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
13240         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
13241         (cmdline_parse_inst_t *)&cmd_write_reg,
13242         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
13243         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
13244         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
13245         (cmdline_parse_inst_t *)&cmd_stop,
13246         (cmdline_parse_inst_t *)&cmd_mac_addr,
13247         (cmdline_parse_inst_t *)&cmd_set_qmap,
13248         (cmdline_parse_inst_t *)&cmd_operate_port,
13249         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
13250         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
13251         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
13252         (cmdline_parse_inst_t *)&cmd_config_speed_all,
13253         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
13254         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
13255         (cmdline_parse_inst_t *)&cmd_config_mtu,
13256         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
13257         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
13258         (cmdline_parse_inst_t *)&cmd_config_rss,
13259         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
13260         (cmdline_parse_inst_t *)&cmd_config_txqflags,
13261         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
13262         (cmdline_parse_inst_t *)&cmd_showport_reta,
13263         (cmdline_parse_inst_t *)&cmd_config_burst,
13264         (cmdline_parse_inst_t *)&cmd_config_thresh,
13265         (cmdline_parse_inst_t *)&cmd_config_threshold,
13266         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
13267         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
13268         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
13269         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
13270         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
13271         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
13272         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
13273         (cmdline_parse_inst_t *)&cmd_global_config,
13274         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
13275         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
13276         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
13277         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
13278         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
13279         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
13280         (cmdline_parse_inst_t *)&cmd_dump,
13281         (cmdline_parse_inst_t *)&cmd_dump_one,
13282         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
13283         (cmdline_parse_inst_t *)&cmd_syn_filter,
13284         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
13285         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
13286         (cmdline_parse_inst_t *)&cmd_flex_filter,
13287         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
13288         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
13289         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
13290         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
13291         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
13292         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
13293         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
13294         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
13295         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
13296         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
13297         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
13298         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
13299         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
13300         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
13301         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
13302         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
13303         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
13304         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
13305         (cmdline_parse_inst_t *)&cmd_flow,
13306         (cmdline_parse_inst_t *)&cmd_mcast_addr,
13307         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
13308         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
13309         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
13310         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
13311         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
13312         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
13313         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
13314         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
13315         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
13316         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
13317         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
13318         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
13319         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
13320         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
13321         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
13322 #ifdef RTE_LIBRTE_IXGBE_PMD
13323         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
13324         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
13325         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
13326         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
13327         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
13328         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
13329         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
13330         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
13331         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
13332 #endif
13333         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
13334         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
13335         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
13336         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
13337         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
13338         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
13339         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
13340         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
13341         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
13342         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
13343         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
13344         (cmdline_parse_inst_t *)&cmd_ddp_add,
13345         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
13346         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
13347         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
13348         NULL,
13349 };
13350
13351 /* prompt function, called from main on MASTER lcore */
13352 void
13353 prompt(void)
13354 {
13355         /* initialize non-constant commands */
13356         cmd_set_fwd_mode_init();
13357         cmd_set_fwd_retry_mode_init();
13358
13359         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
13360         if (testpmd_cl == NULL)
13361                 return;
13362         cmdline_interact(testpmd_cl);
13363         cmdline_stdin_exit(testpmd_cl);
13364 }
13365
13366 void
13367 prompt_exit(void)
13368 {
13369         if (testpmd_cl != NULL)
13370                 cmdline_quit(testpmd_cl);
13371 }
13372
13373 static void
13374 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
13375 {
13376         if (id == (portid_t)RTE_PORT_ALL) {
13377                 portid_t pid;
13378
13379                 RTE_ETH_FOREACH_DEV(pid) {
13380                         /* check if need_reconfig has been set to 1 */
13381                         if (ports[pid].need_reconfig == 0)
13382                                 ports[pid].need_reconfig = dev;
13383                         /* check if need_reconfig_queues has been set to 1 */
13384                         if (ports[pid].need_reconfig_queues == 0)
13385                                 ports[pid].need_reconfig_queues = queue;
13386                 }
13387         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
13388                 /* check if need_reconfig has been set to 1 */
13389                 if (ports[id].need_reconfig == 0)
13390                         ports[id].need_reconfig = dev;
13391                 /* check if need_reconfig_queues has been set to 1 */
13392                 if (ports[id].need_reconfig_queues == 0)
13393                         ports[id].need_reconfig_queues = queue;
13394         }
13395 }