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