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