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