xref: /dpdk/app/test-pmd/cmdline.c (revision 236bc417e2dad4034e4b9b7ea4fc10e71a07c1f8)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5 
6 #include <ctype.h>
7 #include <stdarg.h>
8 #include <errno.h>
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <unistd.h>
14 #include <inttypes.h>
15 #include <sys/queue.h>
16 
17 #include <rte_common.h>
18 #include <rte_byteorder.h>
19 #include <rte_log.h>
20 #include <rte_debug.h>
21 #include <rte_cycles.h>
22 #include <rte_memory.h>
23 #include <rte_memzone.h>
24 #include <rte_malloc.h>
25 #include <rte_launch.h>
26 #include <rte_eal.h>
27 #include <rte_per_lcore.h>
28 #include <rte_lcore.h>
29 #include <rte_branch_prediction.h>
30 #include <rte_ring.h>
31 #include <rte_mempool.h>
32 #include <rte_interrupts.h>
33 #include <rte_ether.h>
34 #include <rte_ethdev.h>
35 #include <rte_string_fns.h>
36 #include <rte_devargs.h>
37 #include <rte_flow.h>
38 #ifdef RTE_LIB_GRO
39 #include <rte_gro.h>
40 #endif
41 #include <rte_mbuf_dyn.h>
42 
43 #include <cmdline_rdline.h>
44 #include <cmdline_parse.h>
45 #include <cmdline_parse_num.h>
46 #include <cmdline_parse_string.h>
47 #include <cmdline_parse_ipaddr.h>
48 #include <cmdline_parse_etheraddr.h>
49 #include <cmdline_socket.h>
50 #include <cmdline.h>
51 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
52 #include <rte_pmd_dpaa.h>
53 #endif
54 #ifdef RTE_NET_IXGBE
55 #include <rte_pmd_ixgbe.h>
56 #endif
57 #ifdef RTE_NET_I40E
58 #include <rte_pmd_i40e.h>
59 #endif
60 #ifdef RTE_NET_BNXT
61 #include <rte_pmd_bnxt.h>
62 #endif
63 #include "testpmd.h"
64 #include "cmdline_mtr.h"
65 #include "cmdline_tm.h"
66 #include "bpf_cmd.h"
67 
68 static struct cmdline *testpmd_cl;
69 static cmdline_parse_ctx_t *main_ctx;
70 static TAILQ_HEAD(, testpmd_driver_commands) driver_commands_head =
71 	TAILQ_HEAD_INITIALIZER(driver_commands_head);
72 
73 /* *** Help command with introduction. *** */
74 struct cmd_help_brief_result {
75 	cmdline_fixed_string_t help;
76 };
77 
78 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
79                                   struct cmdline *cl,
80                                   __rte_unused void *data)
81 {
82 	cmdline_printf(
83 		cl,
84 		"\n"
85 		"Help is available for the following sections:\n\n"
86 		"    help control                    : Start and stop forwarding.\n"
87 		"    help display                    : Displaying port, stats and config "
88 		"information.\n"
89 		"    help config                     : Configuration information.\n"
90 		"    help ports                      : Configuring ports.\n"
91 		"    help filters                    : Filters configuration help.\n"
92 		"    help traffic_management         : Traffic Management commands.\n"
93 		"    help devices                    : Device related commands.\n"
94 		"    help drivers                    : Driver specific commands.\n"
95 		"    help all                        : All of the above sections.\n\n"
96 	);
97 
98 }
99 
100 static cmdline_parse_token_string_t cmd_help_brief_help =
101 	TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
102 
103 static cmdline_parse_inst_t cmd_help_brief = {
104 	.f = cmd_help_brief_parsed,
105 	.data = NULL,
106 	.help_str = "help: Show help",
107 	.tokens = {
108 		(void *)&cmd_help_brief_help,
109 		NULL,
110 	},
111 };
112 
113 /* *** Help command with help sections. *** */
114 struct cmd_help_long_result {
115 	cmdline_fixed_string_t help;
116 	cmdline_fixed_string_t section;
117 };
118 
119 static void cmd_help_long_parsed(void *parsed_result,
120                                  struct cmdline *cl,
121                                  __rte_unused void *data)
122 {
123 	int show_all = 0;
124 	struct cmd_help_long_result *res = parsed_result;
125 
126 	if (!strcmp(res->section, "all"))
127 		show_all = 1;
128 
129 	if (show_all || !strcmp(res->section, "control")) {
130 
131 		cmdline_printf(
132 			cl,
133 			"\n"
134 			"Control forwarding:\n"
135 			"-------------------\n\n"
136 
137 			"start\n"
138 			"    Start packet forwarding with current configuration.\n\n"
139 
140 			"start tx_first\n"
141 			"    Start packet forwarding with current config"
142 			" after sending one burst of packets.\n\n"
143 
144 			"stop\n"
145 			"    Stop packet forwarding, and display accumulated"
146 			" statistics.\n\n"
147 
148 			"quit\n"
149 			"    Quit to prompt.\n\n"
150 		);
151 	}
152 
153 	if (show_all || !strcmp(res->section, "display")) {
154 
155 		cmdline_printf(
156 			cl,
157 			"\n"
158 			"Display:\n"
159 			"--------\n\n"
160 
161 			"show port (info|stats|summary|xstats|fdir|dcb_tc) (port_id|all)\n"
162 			"    Display information for port_id, or all.\n\n"
163 
164 			"show port info (port_id) representor\n"
165 			"    Show supported representors for a specific port\n\n"
166 
167 			"show port port_id (module_eeprom|eeprom)\n"
168 			"    Display the module EEPROM or EEPROM information for port_id.\n\n"
169 
170 			"show port X rss reta (size) (mask0,mask1,...)\n"
171 			"    Display the rss redirection table entry indicated"
172 			" by masks on port X. size is used to indicate the"
173 			" hardware supported reta size\n\n"
174 
175 			"show port (port_id) rss-hash [key]\n"
176 			"    Display the RSS hash functions and RSS hash key of port\n\n"
177 
178 			"clear port (info|stats|xstats|fdir) (port_id|all)\n"
179 			"    Clear information for port_id, or all.\n\n"
180 
181 			"show (rxq|txq) info (port_id) (queue_id)\n"
182 			"    Display information for configured RX/TX queue.\n\n"
183 
184 			"show config (rxtx|cores|fwd|rxoffs|rxpkts|rxhdrs|txpkts)\n"
185 			"    Display the given configuration.\n\n"
186 
187 			"read rxd (port_id) (queue_id) (rxd_id)\n"
188 			"    Display an RX descriptor of a port RX queue.\n\n"
189 
190 			"read txd (port_id) (queue_id) (txd_id)\n"
191 			"    Display a TX descriptor of a port TX queue.\n\n"
192 
193 			"show vf stats (port_id) (vf_id)\n"
194 			"    Display a VF's statistics.\n\n"
195 
196 			"clear vf stats (port_id) (vf_id)\n"
197 			"    Reset a VF's statistics.\n\n"
198 
199 			"show port meter stats (port_id) (meter_id) (clear)\n"
200 			"    Get meter stats on a port\n\n"
201 
202 			"show fwd stats all\n"
203 			"    Display statistics for all fwd engines.\n\n"
204 
205 			"clear fwd stats all\n"
206 			"    Clear statistics for all fwd engines.\n\n"
207 
208 			"show port (port_id) rx_offload capabilities\n"
209 			"    List all per queue and per port Rx offloading"
210 			" capabilities of a port\n\n"
211 
212 			"show port (port_id) rx_offload configuration\n"
213 			"    List port level and all queue level"
214 			" Rx offloading configuration\n\n"
215 
216 			"show port (port_id) tx_offload capabilities\n"
217 			"    List all per queue and per port"
218 			" Tx offloading capabilities of a port\n\n"
219 
220 			"show port (port_id) tx_offload configuration\n"
221 			"    List port level and all queue level"
222 			" Tx offloading configuration\n\n"
223 
224 			"show port (port_id) tx_metadata\n"
225 			"    Show Tx metadata value set"
226 			" for a specific port\n\n"
227 
228 			"show port (port_id) ptypes\n"
229 			"    Show port supported ptypes"
230 			" for a specific port\n\n"
231 
232 			"show device info (<identifier>|all)"
233 			"       Show general information about devices probed.\n\n"
234 
235 			"show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
236 			"       Show status of rx|tx descriptor.\n\n"
237 
238 			"show port (port_id) rxq (queue_id) desc used count\n"
239 			"    Show current number of filled receive"
240 			" packet descriptors.\n\n"
241 
242 			"show port (port_id) macs|mcast_macs"
243 			"       Display list of mac addresses added to port.\n\n"
244 
245 			"show port (port_id) flow transfer proxy\n"
246 			"	Display proxy port to manage transfer flows\n\n"
247 
248 			"show port (port_id) fec capabilities"
249 			"	Show fec capabilities of a port.\n\n"
250 
251 			"show port (port_id) fec_mode"
252 			"	Show fec mode of a port.\n\n"
253 
254 			"show port (port_id) flow_ctrl"
255 			"	Show flow control info of a port.\n\n"
256 		);
257 	}
258 
259 	if (show_all || !strcmp(res->section, "config")) {
260 		cmdline_printf(
261 			cl,
262 			"\n"
263 			"Configuration:\n"
264 			"--------------\n"
265 			"Configuration changes only become active when"
266 			" forwarding is started/restarted.\n\n"
267 
268 			"set default\n"
269 			"    Reset forwarding to the default configuration.\n\n"
270 
271 			"set verbose (level)\n"
272 			"    Set the debug verbosity level X.\n\n"
273 
274 			"set log global|(type) (level)\n"
275 			"    Set the log level.\n\n"
276 
277 			"set nbport (num)\n"
278 			"    Set number of ports.\n\n"
279 
280 			"set nbcore (num)\n"
281 			"    Set number of cores.\n\n"
282 
283 			"set coremask (mask)\n"
284 			"    Set the forwarding cores hexadecimal mask.\n\n"
285 
286 			"set portmask (mask)\n"
287 			"    Set the forwarding ports hexadecimal mask.\n\n"
288 
289 			"set burst (num)\n"
290 			"    Set number of packets per burst.\n\n"
291 
292 			"set burst tx delay (microseconds) retry (num)\n"
293 			"    Set the transmit delay time and number of retries,"
294 			" effective when retry is enabled.\n\n"
295 
296 			"set rxoffs (x[,y]*)\n"
297 			"    Set the offset of each packet segment on"
298 			" receiving if split feature is engaged."
299 			" Affects only the queues configured with split"
300 			" offloads.\n\n"
301 
302 			"set rxpkts (x[,y]*)\n"
303 			"    Set the length of each segment to scatter"
304 			" packets on receiving if split feature is engaged."
305 			" Affects only the queues configured with split"
306 			" offloads.\n\n"
307 
308 			"set rxhdrs (eth[,ipv4])*\n"
309 			"    Set the protocol hdr of each segment to scatter"
310 			" packets on receiving if split feature is engaged."
311 			" Affects only the queues configured with split"
312 			" offloads.\n"
313 			"    Supported values: eth|ipv4|ipv6|ipv4-tcp|ipv6-tcp|"
314 			"ipv4-udp|ipv6-udp|ipv4-sctp|ipv6-sctp|"
315 			"grenat|inner-eth|inner-ipv4|inner-ipv6|inner-ipv4-tcp|"
316 			"inner-ipv6-tcp|inner-ipv4-udp|inner-ipv6-udp|"
317 			"inner-ipv4-sctp|inner-ipv6-sctp\n\n"
318 
319 			"set txpkts (x[,y]*)\n"
320 			"    Set the length of each segment of TXONLY"
321 			" and optionally CSUM packets.\n\n"
322 
323 			"set txsplit (off|on|rand)\n"
324 			"    Set the split policy for the TX packets."
325 			" Right now only applicable for CSUM and TXONLY"
326 			" modes\n\n"
327 
328 			"set txtimes (x, y)\n"
329 			"    Set the scheduling on timestamps"
330 			" timings for the TXONLY mode\n\n"
331 
332 			"set corelist (x[,y]*)\n"
333 			"    Set the list of forwarding cores.\n\n"
334 
335 			"set portlist (x[,y]*)\n"
336 			"    Set the list of forwarding ports.\n\n"
337 
338 			"set port setup on (iterator|event)\n"
339 			"    Select how attached port is retrieved for setup.\n\n"
340 
341 			"set tx loopback (port_id) (on|off)\n"
342 			"    Enable or disable tx loopback.\n\n"
343 
344 			"set all queues drop (port_id) (on|off)\n"
345 			"    Set drop enable bit for all queues.\n\n"
346 
347 			"set vf mac antispoof (port_id) (vf_id) (on|off).\n"
348 			"    Set MAC antispoof for a VF from the PF.\n\n"
349 
350 			"vlan set stripq (on|off) (port_id,queue_id)\n"
351 			"    Set the VLAN strip for a queue on a port.\n\n"
352 
353 			"set vf vlan stripq (port_id) (vf_id) (on|off)\n"
354 			"    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
355 
356 			"set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
357 			"    Set VLAN insert for a VF from the PF.\n\n"
358 
359 			"set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
360 			"    Set VLAN antispoof for a VF from the PF.\n\n"
361 
362 			"vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
363 			"    Set the VLAN strip or filter or qinq strip or extend\n\n"
364 
365 			"vlan set (inner|outer) tpid (value) (port_id)\n"
366 			"    Set the VLAN TPID for Packet Filtering on"
367 			" a port\n\n"
368 
369 			"rx_vlan add (vlan_id|all) (port_id)\n"
370 			"    Add a vlan_id, or all identifiers, to the set"
371 			" of VLAN identifiers filtered by port_id.\n\n"
372 
373 			"rx_vlan rm (vlan_id|all) (port_id)\n"
374 			"    Remove a vlan_id, or all identifiers, from the set"
375 			" of VLAN identifiers filtered by port_id.\n\n"
376 
377 			"rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
378 			"    Add a vlan_id, to the set of VLAN identifiers"
379 			"filtered for VF(s) from port_id.\n\n"
380 
381 			"rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
382 			"    Remove a vlan_id, to the set of VLAN identifiers"
383 			"filtered for VF(s) from port_id.\n\n"
384 
385 			"rx_vxlan_port add (udp_port) (port_id)\n"
386 			"    Add an UDP port for VXLAN packet filter on a port\n\n"
387 
388 			"rx_vxlan_port rm (udp_port) (port_id)\n"
389 			"    Remove an UDP port for VXLAN packet filter on a port\n\n"
390 
391 			"tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
392 			"    Set hardware insertion of VLAN IDs (single or double VLAN "
393 			"depends on the number of VLAN IDs) in packets sent on a port.\n\n"
394 
395 			"tx_vlan set pvid port_id vlan_id (on|off)\n"
396 			"    Set port based TX VLAN insertion.\n\n"
397 
398 			"tx_vlan reset (port_id)\n"
399 			"    Disable hardware insertion of a VLAN header in"
400 			" packets sent on a port.\n\n"
401 
402 			"csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
403 			"    Select hardware or software calculation of the"
404 			" checksum when transmitting a packet using the"
405 			" csum forward engine.\n"
406 			"    ip|udp|tcp|sctp always concern the inner layer.\n"
407 			"    outer-ip concerns the outer IP layer in"
408 			"    outer-udp concerns the outer UDP layer in"
409 			" case the packet is recognized as a tunnel packet by"
410 			" the forward engine (vxlan, gre and ipip are supported)\n"
411 			"    Please check the NIC datasheet for HW limits.\n\n"
412 
413 			"csum parse-tunnel (on|off) (tx_port_id)\n"
414 			"    If disabled, treat tunnel packets as non-tunneled"
415 			" packets (treat inner headers as payload). The port\n"
416 			"    argument is the port used for TX in csum forward"
417 			" engine.\n\n"
418 
419 			"csum show (port_id)\n"
420 			"    Display tx checksum offload configuration\n\n"
421 
422 			"tso set (segsize) (portid)\n"
423 			"    Enable TCP Segmentation Offload in csum forward"
424 			" engine.\n"
425 			"    Please check the NIC datasheet for HW limits.\n\n"
426 
427 			"tso show (portid)"
428 			"    Display the status of TCP Segmentation Offload.\n\n"
429 
430 #ifdef RTE_LIB_GRO
431 			"set port (port_id) gro on|off\n"
432 			"    Enable or disable Generic Receive Offload in"
433 			" csum forwarding engine.\n\n"
434 
435 			"show port (port_id) gro\n"
436 			"    Display GRO configuration.\n\n"
437 
438 			"set gro flush (cycles)\n"
439 			"    Set the cycle to flush GROed packets from"
440 			" reassembly tables.\n\n"
441 #endif
442 
443 #ifdef RTE_LIB_GSO
444 			"set port (port_id) gso (on|off)"
445 			"    Enable or disable Generic Segmentation Offload in"
446 			" csum forwarding engine.\n\n"
447 
448 			"set gso segsz (length)\n"
449 			"    Set max packet length for output GSO segments,"
450 			" including packet header and payload.\n\n"
451 
452 			"show port (port_id) gso\n"
453 			"    Show GSO configuration.\n\n"
454 #endif
455 
456 			"set fwd (%s)\n"
457 			"    Set packet forwarding mode.\n\n"
458 
459 			"mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
460 			"    Add a MAC address on port_id.\n\n"
461 
462 			"mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
463 			"    Remove a MAC address from port_id.\n\n"
464 
465 			"mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
466 			"    Set the default MAC address for port_id.\n\n"
467 
468 			"mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
469 			"    Add a MAC address for a VF on the port.\n\n"
470 
471 			"set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
472 			"    Set the MAC address for a VF from the PF.\n\n"
473 
474 			"set eth-peer (port_id) (peer_addr)\n"
475 			"    set the peer address for certain port.\n\n"
476 
477 			"set port (port_id) uta (mac_address|all) (on|off)\n"
478 			"    Add/Remove a or all unicast hash filter(s)"
479 			"from port X.\n\n"
480 
481 			"set promisc (port_id|all) (on|off)\n"
482 			"    Set the promiscuous mode on port_id, or all.\n\n"
483 
484 			"set allmulti (port_id|all) (on|off)\n"
485 			"    Set the allmulti mode on port_id, or all.\n\n"
486 
487 			"set flow_ctrl rx (on|off) tx (on|off) (high_water)"
488 			" (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
489 			" (on|off) autoneg (on|off) (port_id)\n"
490 			"set flow_ctrl rx (on|off) (portid)\n"
491 			"set flow_ctrl tx (on|off) (portid)\n"
492 			"set flow_ctrl high_water (high_water) (portid)\n"
493 			"set flow_ctrl low_water (low_water) (portid)\n"
494 			"set flow_ctrl pause_time (pause_time) (portid)\n"
495 			"set flow_ctrl send_xon (send_xon) (portid)\n"
496 			"set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
497 			"set flow_ctrl autoneg (on|off) (port_id)\n"
498 			"    Set the link flow control parameter on a port.\n\n"
499 
500 			"set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
501 			" (low_water) (pause_time) (priority) (port_id)\n"
502 			"    Set the priority flow control parameter on a"
503 			" port.\n\n"
504 
505 			"set pfc_queue_ctrl (port_id) rx (on|off) (tx_qid)"
506 			" (tx_tc) tx (on|off) (rx_qid) (rx_tc) (pause_time)\n"
507 			"    Set the queue priority flow control parameter on a"
508 			" given Rx and Tx queues of a port.\n\n"
509 
510 			"set port (port_id) rxq (queue_id) avail_thresh (0..99)>\n "
511 			"    set available descriptors threshold for Rx queue\n\n"
512 
513 			"set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
514 			"    Set statistics mapping (qmapping 0..15) for RX/TX"
515 			" queue on port.\n"
516 			"    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
517 			" on port 0 to mapping 5.\n\n"
518 
519 			"set xstats-hide-zero on|off\n"
520 			"    Set the option to hide the zero values"
521 			" for xstats display.\n"
522 
523 			"set record-core-cycles on|off\n"
524 			"    Set the option to enable measurement of CPU cycles.\n"
525 
526 			"set record-burst-stats on|off\n"
527 			"    Set the option to enable display of RX and TX bursts.\n"
528 
529 			"set port (port_id) vf (vf_id) rx|tx on|off\n"
530 			"    Enable/Disable a VF receive/transmit from a port\n\n"
531 
532 			"set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
533 			"|MPE) (on|off)\n"
534 			"    AUPE:accepts untagged VLAN;"
535 			"ROPE:accept unicast hash\n\n"
536 			"    BAM:accepts broadcast packets;"
537 			"MPE:accepts all multicast packets\n\n"
538 			"    Enable/Disable a VF receive mode of a port\n\n"
539 
540 			"set port (port_id) queue (queue_id) rate (rate_num)\n"
541 			"    Set rate limit for a queue of a port\n\n"
542 
543 			"set port (port_id) vf (vf_id) rate (rate_num) "
544 			"queue_mask (queue_mask_value)\n"
545 			"    Set rate limit for queues in VF of a port\n\n"
546 
547 			"set flush_rx (on|off)\n"
548 			"   Flush (default) or don't flush RX streams before"
549 			" forwarding. Mainly used with PCAP drivers.\n\n"
550 
551 			"set link-up port (port_id)\n"
552 			"	Set link up for a port.\n\n"
553 
554 			"set link-down port (port_id)\n"
555 			"	Set link down for a port.\n\n"
556 
557 			"set port (port_id) ptype_mask (ptype_mask)\n"
558 			"    set packet types classification for a specific port\n\n"
559 
560 			"show port meter cap (port_id)\n"
561 			"    Show port meter capability information\n\n"
562 
563 			"add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (packet_mode)\n"
564 			"    meter profile add - srtcm rfc 2697\n\n"
565 
566 			"add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs) (packet_mode)\n"
567 			"    meter profile add - trtcm rfc 2698\n\n"
568 
569 			"add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs) (packet_mode)\n"
570 			"    meter profile add - trtcm rfc 4115\n\n"
571 
572 			"del port meter profile (port_id) (profile_id)\n"
573 			"    meter profile delete\n\n"
574 
575 			"create port meter (port_id) (mtr_id) (profile_id) (policy_id) (meter_enable)\n"
576 			"(stats_mask) (shared) (use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
577 			"(dscp_tbl_entry63)]\n"
578 			"    meter create\n\n"
579 
580 			"enable port meter (port_id) (mtr_id)\n"
581 			"    meter enable\n\n"
582 
583 			"disable port meter (port_id) (mtr_id)\n"
584 			"    meter disable\n\n"
585 
586 			"del port meter (port_id) (mtr_id)\n"
587 			"    meter delete\n\n"
588 
589 			"add port meter policy (port_id) (policy_id) g_actions (actions)\n"
590 			"y_actions (actions) r_actions (actions)\n"
591 			"    meter policy add\n\n"
592 
593 			"del port meter policy (port_id) (policy_id)\n"
594 			"    meter policy delete\n\n"
595 
596 			"set port meter profile (port_id) (mtr_id) (profile_id)\n"
597 			"    meter update meter profile\n\n"
598 
599 			"set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
600 			"(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
601 			"    update meter dscp table entries\n\n"
602 
603 			"set port meter policer action (port_id) (mtr_id) (action_mask)\n"
604 			"(action0) [(action1) (action2)]\n"
605 			"    meter update policer action\n\n"
606 
607 			"set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
608 			"    meter update stats\n\n"
609 
610 			"set port (port_id) fec_mode auto|off|rs|baser\n"
611 			"    set fec mode for a specific port\n\n"
612 
613 			, list_pkt_forwarding_modes()
614 		);
615 	}
616 
617 	if (show_all || !strcmp(res->section, "ports")) {
618 
619 		cmdline_printf(
620 			cl,
621 			"\n"
622 			"Port Operations:\n"
623 			"----------------\n\n"
624 
625 			"port start (port_id|all)\n"
626 			"    Start all ports or port_id.\n\n"
627 
628 			"port stop (port_id|all)\n"
629 			"    Stop all ports or port_id.\n\n"
630 
631 			"port close (port_id|all)\n"
632 			"    Close all ports or port_id.\n\n"
633 
634 			"port reset (port_id|all)\n"
635 			"    Reset all ports or port_id.\n\n"
636 
637 			"port attach (ident)\n"
638 			"    Attach physical or virtual dev by pci address or virtual device name\n\n"
639 
640 			"port detach (port_id)\n"
641 			"    Detach physical or virtual dev by port_id\n\n"
642 
643 			"port config (port_id|all)"
644 			" speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
645 			" duplex (half|full|auto)\n"
646 			"    Set speed and duplex for all ports or port_id\n\n"
647 
648 			"port config (port_id|all) loopback (mode)\n"
649 			"    Set loopback mode for all ports or port_id\n\n"
650 
651 			"port config all (rxq|txq|rxd|txd) (value)\n"
652 			"    Set number for rxq/txq/rxd/txd.\n\n"
653 
654 			"port config all max-pkt-len (value)\n"
655 			"    Set the max packet length.\n\n"
656 
657 			"port config all max-lro-pkt-size (value)\n"
658 			"    Set the max LRO aggregated packet size.\n\n"
659 
660 			"port config all drop-en (on|off)\n"
661 			"    Enable or disable packet drop on all RX queues of all ports when no "
662 			"receive buffers available.\n\n"
663 
664 			"port config all rss (all|default|level-default|level-outer|level-inner|"
665 			"ip|tcp|udp|sctp|tunnel|vlan|none|"
666 			"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
667 			"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
668 			"l2-payload|port|vxlan|geneve|nvgre|gtpu|eth|s-vlan|c-vlan|"
669 			"esp|ah|l2tpv3|pfcp|pppoe|ecpri|mpls|ipv4-chksum|l4-chksum|"
670 			"l2tpv2|l3-pre96|l3-pre64|l3-pre56|l3-pre48|l3-pre40|l3-pre32|"
671 			"l2-dst-only|l2-src-only|l4-dst-only|l4-src-only|l3-dst-only|l3-src-only|<rsstype_id>)\n"
672 			"    Set the RSS mode.\n\n"
673 
674 			"port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
675 			"    Set the RSS redirection table.\n\n"
676 
677 			"port config (port_id) dcb vt (on|off) (traffic_class)"
678 			" pfc (on|off)\n"
679 			"    Set the DCB mode.\n\n"
680 
681 			"port config all burst (value)\n"
682 			"    Set the number of packets per burst.\n\n"
683 
684 			"port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
685 			" (value)\n"
686 			"    Set the ring prefetch/host/writeback threshold"
687 			" for tx/rx queue.\n\n"
688 
689 			"port config all (txfreet|txrst|rxfreet) (value)\n"
690 			"    Set free threshold for rx/tx, or set"
691 			" tx rs bit threshold.\n\n"
692 			"port config mtu X value\n"
693 			"    Set the MTU of port X to a given value\n\n"
694 
695 			"port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
696 			"    Set a rx/tx queue's ring size configuration, the new"
697 			" value will take effect after command that (re-)start the port"
698 			" or command that setup the specific queue\n\n"
699 
700 			"port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
701 			"    Start/stop a rx/tx queue of port X. Only take effect"
702 			" when port X is started\n\n"
703 
704 			"port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
705 			"    Switch on/off a deferred start of port X rx/tx queue. Only"
706 			" take effect when port X is stopped.\n\n"
707 
708 			"port (port_id) (rxq|txq) (queue_id) setup\n"
709 			"    Setup a rx/tx queue of port X.\n\n"
710 
711 			"port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
712 			"    Add/remove UDP tunnel port for tunneling offload\n\n"
713 
714 			"port config <port_id> rx_offload vlan_strip|"
715 			"ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
716 			"outer_ipv4_cksum|macsec_strip|"
717 			"vlan_filter|vlan_extend|scatter|"
718 			"buffer_split|timestamp|security|keep_crc on|off\n"
719 			"     Enable or disable a per port Rx offloading"
720 			" on all Rx queues of a port\n\n"
721 
722 			"port (port_id) rxq (queue_id) rx_offload vlan_strip|"
723 			"ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
724 			"outer_ipv4_cksum|macsec_strip|"
725 			"vlan_filter|vlan_extend|scatter|"
726 			"buffer_split|timestamp|security|keep_crc on|off\n"
727 			"    Enable or disable a per queue Rx offloading"
728 			" only on a specific Rx queue\n\n"
729 
730 			"port config (port_id) tx_offload vlan_insert|"
731 			"ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
732 			"udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
733 			"gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
734 			"macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
735 			"security on|off\n"
736 			"    Enable or disable a per port Tx offloading"
737 			" on all Tx queues of a port\n\n"
738 
739 			"port (port_id) txq (queue_id) tx_offload vlan_insert|"
740 			"ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
741 			"udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
742 			"gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
743 			"|mt_lockfree|multi_segs|mbuf_fast_free|security"
744 			" on|off\n"
745 			"    Enable or disable a per queue Tx offloading"
746 			" only on a specific Tx queue\n\n"
747 
748 			"bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
749 			"    Load an eBPF program as a callback"
750 			" for particular RX/TX queue\n\n"
751 
752 			"bpf-unload rx|tx (port) (queue)\n"
753 			"    Unload previously loaded eBPF program"
754 			" for particular RX/TX queue\n\n"
755 
756 			"port config (port_id) tx_metadata (value)\n"
757 			"    Set Tx metadata value per port. Testpmd will add this value"
758 			" to any Tx packet sent from this port\n\n"
759 
760 			"port config (port_id) dynf (name) set|clear\n"
761 			"    Register a dynf and Set/clear this flag on Tx. "
762 			"Testpmd will set this value to any Tx packet "
763 			"sent from this port\n\n"
764 
765 			"port cleanup (port_id) txq (queue_id) (free_cnt)\n"
766 			"    Cleanup txq mbufs for a specific Tx queue\n\n"
767 		);
768 	}
769 
770 	if (show_all || !strcmp(res->section, "filters")) {
771 
772 		cmdline_printf(
773 			cl,
774 			"\n"
775 			"filters:\n"
776 			"--------\n\n"
777 
778 			"flow validate {port_id}"
779 			" [group {group_id}] [priority {level}]"
780 			" [ingress] [egress]"
781 			" pattern {item} [/ {item} [...]] / end"
782 			" actions {action} [/ {action} [...]] / end\n"
783 			"    Check whether a flow rule can be created.\n\n"
784 
785 			"flow create {port_id}"
786 			" [group {group_id}] [priority {level}]"
787 			" [ingress] [egress]"
788 			" pattern {item} [/ {item} [...]] / end"
789 			" actions {action} [/ {action} [...]] / end\n"
790 			"    Create a flow rule.\n\n"
791 
792 			"flow destroy {port_id} rule {rule_id} [...]\n"
793 			"    Destroy specific flow rules.\n\n"
794 
795 			"flow flush {port_id}\n"
796 			"    Destroy all flow rules.\n\n"
797 
798 			"flow query {port_id} {rule_id} {action}\n"
799 			"    Query an existing flow rule.\n\n"
800 
801 			"flow list {port_id} [group {group_id}] [...]\n"
802 			"    List existing flow rules sorted by priority,"
803 			" filtered by group identifiers.\n\n"
804 
805 			"flow isolate {port_id} {boolean}\n"
806 			"    Restrict ingress traffic to the defined"
807 			" flow rules\n\n"
808 
809 			"flow aged {port_id} [destroy]\n"
810 			"    List and destroy aged flows"
811 			" flow rules\n\n"
812 
813 			"flow indirect_action {port_id} create"
814 			" [action_id {indirect_action_id}]"
815 			" [ingress] [egress]"
816 			" action {action} / end\n"
817 			"    Create indirect action.\n\n"
818 
819 			"flow indirect_action {port_id} update"
820 			" {indirect_action_id} action {action} / end\n"
821 			"    Update indirect action.\n\n"
822 
823 			"flow indirect_action {port_id} destroy"
824 			" action_id {indirect_action_id} [...]\n"
825 			"    Destroy specific indirect actions.\n\n"
826 
827 			"flow indirect_action {port_id} query"
828 			" {indirect_action_id}\n"
829 			"    Query an existing indirect action.\n\n"
830 
831 			"set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
832 			" (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
833 			" (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
834 			"       Configure the VXLAN encapsulation for flows.\n\n"
835 
836 			"set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
837 			" udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
838 			" ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
839 			" eth-dst (eth-dst)\n"
840 			"       Configure the VXLAN encapsulation for flows.\n\n"
841 
842 			"set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
843 			" (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
844 			" ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
845 			" eth-dst (eth-dst)\n"
846 			"       Configure the VXLAN encapsulation for flows.\n\n"
847 
848 			"set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
849 			" (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
850 			" (eth-dst)\n"
851 			"       Configure the NVGRE encapsulation for flows.\n\n"
852 
853 			"set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
854 			" ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
855 			" eth-src (eth-src) eth-dst (eth-dst)\n"
856 			"       Configure the NVGRE encapsulation for flows.\n\n"
857 
858 			"set raw_encap {flow items}\n"
859 			"	Configure the encapsulation with raw data.\n\n"
860 
861 			"set raw_decap {flow items}\n"
862 			"	Configure the decapsulation with raw data.\n\n"
863 
864 		);
865 	}
866 
867 	if (show_all || !strcmp(res->section, "traffic_management")) {
868 		cmdline_printf(
869 			cl,
870 			"\n"
871 			"Traffic Management:\n"
872 			"--------------\n"
873 			"show port tm cap (port_id)\n"
874 			"       Display the port TM capability.\n\n"
875 
876 			"show port tm level cap (port_id) (level_id)\n"
877 			"       Display the port TM hierarchical level capability.\n\n"
878 
879 			"show port tm node cap (port_id) (node_id)\n"
880 			"       Display the port TM node capability.\n\n"
881 
882 			"show port tm node type (port_id) (node_id)\n"
883 			"       Display the port TM node type.\n\n"
884 
885 			"show port tm node stats (port_id) (node_id) (clear)\n"
886 			"       Display the port TM node stats.\n\n"
887 
888 			"add port tm node shaper profile (port_id) (shaper_profile_id)"
889 			" (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
890 			" (packet_length_adjust) (packet_mode)\n"
891 			"       Add port tm node private shaper profile.\n\n"
892 
893 			"del port tm node shaper profile (port_id) (shaper_profile_id)\n"
894 			"       Delete port tm node private shaper profile.\n\n"
895 
896 			"add port tm node shared shaper (port_id) (shared_shaper_id)"
897 			" (shaper_profile_id)\n"
898 			"       Add/update port tm node shared shaper.\n\n"
899 
900 			"del port tm node shared shaper (port_id) (shared_shaper_id)\n"
901 			"       Delete port tm node shared shaper.\n\n"
902 
903 			"set port tm node shaper profile (port_id) (node_id)"
904 			" (shaper_profile_id)\n"
905 			"       Set port tm node shaper profile.\n\n"
906 
907 			"add port tm node wred profile (port_id) (wred_profile_id)"
908 			" (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
909 			" (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
910 			" (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
911 			"       Add port tm node wred profile.\n\n"
912 
913 			"del port tm node wred profile (port_id) (wred_profile_id)\n"
914 			"       Delete port tm node wred profile.\n\n"
915 
916 			"add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
917 			" (priority) (weight) (level_id) (shaper_profile_id)"
918 			" (n_sp_priorities) (stats_mask) (n_shared_shapers)"
919 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
920 			"       Add port tm nonleaf node.\n\n"
921 
922 			"add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
923 			" (priority) (weight) (level_id) (shaper_profile_id)"
924 			" (n_sp_priorities) (stats_mask) (n_shared_shapers)"
925 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
926 			"       Add port tm nonleaf node with pkt mode enabled.\n\n"
927 
928 			"add port tm leaf node (port_id) (node_id) (parent_node_id)"
929 			" (priority) (weight) (level_id) (shaper_profile_id)"
930 			" (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
931 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
932 			"       Add port tm leaf node.\n\n"
933 
934 			"del port tm node (port_id) (node_id)\n"
935 			"       Delete port tm node.\n\n"
936 
937 			"set port tm node parent (port_id) (node_id) (parent_node_id)"
938 			" (priority) (weight)\n"
939 			"       Set port tm node parent.\n\n"
940 
941 			"suspend port tm node (port_id) (node_id)"
942 			"       Suspend tm node.\n\n"
943 
944 			"resume port tm node (port_id) (node_id)"
945 			"       Resume tm node.\n\n"
946 
947 			"port tm hierarchy commit (port_id) (clean_on_fail)\n"
948 			"       Commit tm hierarchy.\n\n"
949 
950 			"set port tm mark ip_ecn (port) (green) (yellow)"
951 			" (red)\n"
952 			"    Enables/Disables the traffic management marking"
953 			" for IP ECN (Explicit Congestion Notification)"
954 			" packets on a given port\n\n"
955 
956 			"set port tm mark ip_dscp (port) (green) (yellow)"
957 			" (red)\n"
958 			"    Enables/Disables the traffic management marking"
959 			" on the port for IP dscp packets\n\n"
960 
961 			"set port tm mark vlan_dei (port) (green) (yellow)"
962 			" (red)\n"
963 			"    Enables/Disables the traffic management marking"
964 			" on the port for VLAN packets with DEI enabled\n\n"
965 		);
966 	}
967 
968 	if (show_all || !strcmp(res->section, "devices")) {
969 		cmdline_printf(
970 			cl,
971 			"\n"
972 			"Device Operations:\n"
973 			"--------------\n"
974 			"device detach (identifier)\n"
975 			"       Detach device by identifier.\n\n"
976 		);
977 	}
978 
979 	if (show_all || !strcmp(res->section, "drivers")) {
980 		struct testpmd_driver_commands *c;
981 		unsigned int i;
982 
983 		cmdline_printf(
984 			cl,
985 			"\n"
986 			"Driver specific:\n"
987 			"----------------\n"
988 		);
989 		TAILQ_FOREACH(c, &driver_commands_head, next) {
990 			for (i = 0; c->commands[i].ctx != NULL; i++)
991 				cmdline_printf(cl, "%s\n", c->commands[i].help);
992 		}
993 	}
994 }
995 
996 static cmdline_parse_token_string_t cmd_help_long_help =
997 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
998 
999 static cmdline_parse_token_string_t cmd_help_long_section =
1000 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1001 		"all#control#display#config#ports#"
1002 		"filters#traffic_management#devices#drivers");
1003 
1004 static cmdline_parse_inst_t cmd_help_long = {
1005 	.f = cmd_help_long_parsed,
1006 	.data = NULL,
1007 	.help_str = "help all|control|display|config|ports|"
1008 		"filters|traffic_management|devices|drivers: "
1009 		"Show help",
1010 	.tokens = {
1011 		(void *)&cmd_help_long_help,
1012 		(void *)&cmd_help_long_section,
1013 		NULL,
1014 	},
1015 };
1016 
1017 
1018 /* *** start/stop/close all ports *** */
1019 struct cmd_operate_port_result {
1020 	cmdline_fixed_string_t keyword;
1021 	cmdline_fixed_string_t name;
1022 	cmdline_fixed_string_t value;
1023 };
1024 
1025 static void cmd_operate_port_parsed(void *parsed_result,
1026 				__rte_unused struct cmdline *cl,
1027 				__rte_unused void *data)
1028 {
1029 	struct cmd_operate_port_result *res = parsed_result;
1030 
1031 	if (!strcmp(res->name, "start"))
1032 		start_port(RTE_PORT_ALL);
1033 	else if (!strcmp(res->name, "stop"))
1034 		stop_port(RTE_PORT_ALL);
1035 	else if (!strcmp(res->name, "close"))
1036 		close_port(RTE_PORT_ALL);
1037 	else if (!strcmp(res->name, "reset"))
1038 		reset_port(RTE_PORT_ALL);
1039 	else
1040 		fprintf(stderr, "Unknown parameter\n");
1041 }
1042 
1043 static cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1044 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1045 								"port");
1046 static cmdline_parse_token_string_t cmd_operate_port_all_port =
1047 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1048 						"start#stop#close#reset");
1049 static cmdline_parse_token_string_t cmd_operate_port_all_all =
1050 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1051 
1052 static cmdline_parse_inst_t cmd_operate_port = {
1053 	.f = cmd_operate_port_parsed,
1054 	.data = NULL,
1055 	.help_str = "port start|stop|close|reset all: Start/Stop/Close/Reset all ports",
1056 	.tokens = {
1057 		(void *)&cmd_operate_port_all_cmd,
1058 		(void *)&cmd_operate_port_all_port,
1059 		(void *)&cmd_operate_port_all_all,
1060 		NULL,
1061 	},
1062 };
1063 
1064 /* *** start/stop/close specific port *** */
1065 struct cmd_operate_specific_port_result {
1066 	cmdline_fixed_string_t keyword;
1067 	cmdline_fixed_string_t name;
1068 	uint8_t value;
1069 };
1070 
1071 static void cmd_operate_specific_port_parsed(void *parsed_result,
1072 			__rte_unused struct cmdline *cl,
1073 				__rte_unused void *data)
1074 {
1075 	struct cmd_operate_specific_port_result *res = parsed_result;
1076 
1077 	if (!strcmp(res->name, "start"))
1078 		start_port(res->value);
1079 	else if (!strcmp(res->name, "stop"))
1080 		stop_port(res->value);
1081 	else if (!strcmp(res->name, "close"))
1082 		close_port(res->value);
1083 	else if (!strcmp(res->name, "reset"))
1084 		reset_port(res->value);
1085 	else
1086 		fprintf(stderr, "Unknown parameter\n");
1087 }
1088 
1089 static cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1090 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1091 							keyword, "port");
1092 static cmdline_parse_token_string_t cmd_operate_specific_port_port =
1093 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1094 						name, "start#stop#close#reset");
1095 static cmdline_parse_token_num_t cmd_operate_specific_port_id =
1096 	TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1097 							value, RTE_UINT8);
1098 
1099 static cmdline_parse_inst_t cmd_operate_specific_port = {
1100 	.f = cmd_operate_specific_port_parsed,
1101 	.data = NULL,
1102 	.help_str = "port start|stop|close|reset <port_id>: Start/Stop/Close/Reset port_id",
1103 	.tokens = {
1104 		(void *)&cmd_operate_specific_port_cmd,
1105 		(void *)&cmd_operate_specific_port_port,
1106 		(void *)&cmd_operate_specific_port_id,
1107 		NULL,
1108 	},
1109 };
1110 
1111 /* *** enable port setup (after attach) via iterator or event *** */
1112 struct cmd_set_port_setup_on_result {
1113 	cmdline_fixed_string_t set;
1114 	cmdline_fixed_string_t port;
1115 	cmdline_fixed_string_t setup;
1116 	cmdline_fixed_string_t on;
1117 	cmdline_fixed_string_t mode;
1118 };
1119 
1120 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1121 				__rte_unused struct cmdline *cl,
1122 				__rte_unused void *data)
1123 {
1124 	struct cmd_set_port_setup_on_result *res = parsed_result;
1125 
1126 	if (strcmp(res->mode, "event") == 0)
1127 		setup_on_probe_event = true;
1128 	else if (strcmp(res->mode, "iterator") == 0)
1129 		setup_on_probe_event = false;
1130 	else
1131 		fprintf(stderr, "Unknown mode\n");
1132 }
1133 
1134 static cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1135 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1136 			set, "set");
1137 static cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1138 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1139 			port, "port");
1140 static cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1141 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1142 			setup, "setup");
1143 static cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1144 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1145 			on, "on");
1146 static cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1147 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1148 			mode, "iterator#event");
1149 
1150 static cmdline_parse_inst_t cmd_set_port_setup_on = {
1151 	.f = cmd_set_port_setup_on_parsed,
1152 	.data = NULL,
1153 	.help_str = "set port setup on iterator|event",
1154 	.tokens = {
1155 		(void *)&cmd_set_port_setup_on_set,
1156 		(void *)&cmd_set_port_setup_on_port,
1157 		(void *)&cmd_set_port_setup_on_setup,
1158 		(void *)&cmd_set_port_setup_on_on,
1159 		(void *)&cmd_set_port_setup_on_mode,
1160 		NULL,
1161 	},
1162 };
1163 
1164 /* *** attach a specified port *** */
1165 struct cmd_operate_attach_port_result {
1166 	cmdline_fixed_string_t port;
1167 	cmdline_fixed_string_t keyword;
1168 	cmdline_multi_string_t identifier;
1169 };
1170 
1171 static void cmd_operate_attach_port_parsed(void *parsed_result,
1172 				__rte_unused struct cmdline *cl,
1173 				__rte_unused void *data)
1174 {
1175 	struct cmd_operate_attach_port_result *res = parsed_result;
1176 
1177 	if (!strcmp(res->keyword, "attach"))
1178 		attach_port(res->identifier);
1179 	else
1180 		fprintf(stderr, "Unknown parameter\n");
1181 }
1182 
1183 static cmdline_parse_token_string_t cmd_operate_attach_port_port =
1184 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1185 			port, "port");
1186 static cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1187 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1188 			keyword, "attach");
1189 static cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1190 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1191 			identifier, TOKEN_STRING_MULTI);
1192 
1193 static cmdline_parse_inst_t cmd_operate_attach_port = {
1194 	.f = cmd_operate_attach_port_parsed,
1195 	.data = NULL,
1196 	.help_str = "port attach <identifier>: "
1197 		"(identifier: pci address or virtual dev name)",
1198 	.tokens = {
1199 		(void *)&cmd_operate_attach_port_port,
1200 		(void *)&cmd_operate_attach_port_keyword,
1201 		(void *)&cmd_operate_attach_port_identifier,
1202 		NULL,
1203 	},
1204 };
1205 
1206 /* *** detach a specified port *** */
1207 struct cmd_operate_detach_port_result {
1208 	cmdline_fixed_string_t port;
1209 	cmdline_fixed_string_t keyword;
1210 	portid_t port_id;
1211 };
1212 
1213 static void cmd_operate_detach_port_parsed(void *parsed_result,
1214 				__rte_unused struct cmdline *cl,
1215 				__rte_unused void *data)
1216 {
1217 	struct cmd_operate_detach_port_result *res = parsed_result;
1218 
1219 	if (!strcmp(res->keyword, "detach")) {
1220 		RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1221 		detach_port_device(res->port_id);
1222 	} else {
1223 		fprintf(stderr, "Unknown parameter\n");
1224 	}
1225 }
1226 
1227 static cmdline_parse_token_string_t cmd_operate_detach_port_port =
1228 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1229 			port, "port");
1230 static cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1231 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1232 			keyword, "detach");
1233 static cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1234 	TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1235 			port_id, RTE_UINT16);
1236 
1237 static cmdline_parse_inst_t cmd_operate_detach_port = {
1238 	.f = cmd_operate_detach_port_parsed,
1239 	.data = NULL,
1240 	.help_str = "port detach <port_id>",
1241 	.tokens = {
1242 		(void *)&cmd_operate_detach_port_port,
1243 		(void *)&cmd_operate_detach_port_keyword,
1244 		(void *)&cmd_operate_detach_port_port_id,
1245 		NULL,
1246 	},
1247 };
1248 
1249 /* *** detach device by identifier *** */
1250 struct cmd_operate_detach_device_result {
1251 	cmdline_fixed_string_t device;
1252 	cmdline_fixed_string_t keyword;
1253 	cmdline_fixed_string_t identifier;
1254 };
1255 
1256 static void cmd_operate_detach_device_parsed(void *parsed_result,
1257 				__rte_unused struct cmdline *cl,
1258 				__rte_unused void *data)
1259 {
1260 	struct cmd_operate_detach_device_result *res = parsed_result;
1261 
1262 	if (!strcmp(res->keyword, "detach"))
1263 		detach_devargs(res->identifier);
1264 	else
1265 		fprintf(stderr, "Unknown parameter\n");
1266 }
1267 
1268 static cmdline_parse_token_string_t cmd_operate_detach_device_device =
1269 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1270 			device, "device");
1271 static cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1272 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1273 			keyword, "detach");
1274 static cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1275 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1276 			identifier, NULL);
1277 
1278 static cmdline_parse_inst_t cmd_operate_detach_device = {
1279 	.f = cmd_operate_detach_device_parsed,
1280 	.data = NULL,
1281 	.help_str = "device detach <identifier>:"
1282 		"(identifier: pci address or virtual dev name)",
1283 	.tokens = {
1284 		(void *)&cmd_operate_detach_device_device,
1285 		(void *)&cmd_operate_detach_device_keyword,
1286 		(void *)&cmd_operate_detach_device_identifier,
1287 		NULL,
1288 	},
1289 };
1290 /* *** configure speed for all ports *** */
1291 struct cmd_config_speed_all {
1292 	cmdline_fixed_string_t port;
1293 	cmdline_fixed_string_t keyword;
1294 	cmdline_fixed_string_t all;
1295 	cmdline_fixed_string_t item1;
1296 	cmdline_fixed_string_t item2;
1297 	cmdline_fixed_string_t value1;
1298 	cmdline_fixed_string_t value2;
1299 };
1300 
1301 static int
1302 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1303 {
1304 
1305 	int duplex;
1306 
1307 	if (!strcmp(duplexstr, "half")) {
1308 		duplex = RTE_ETH_LINK_HALF_DUPLEX;
1309 	} else if (!strcmp(duplexstr, "full")) {
1310 		duplex = RTE_ETH_LINK_FULL_DUPLEX;
1311 	} else if (!strcmp(duplexstr, "auto")) {
1312 		duplex = RTE_ETH_LINK_FULL_DUPLEX;
1313 	} else {
1314 		fprintf(stderr, "Unknown duplex parameter\n");
1315 		return -1;
1316 	}
1317 
1318 	if (!strcmp(speedstr, "10")) {
1319 		*speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1320 				RTE_ETH_LINK_SPEED_10M_HD : RTE_ETH_LINK_SPEED_10M;
1321 	} else if (!strcmp(speedstr, "100")) {
1322 		*speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1323 				RTE_ETH_LINK_SPEED_100M_HD : RTE_ETH_LINK_SPEED_100M;
1324 	} else {
1325 		if (duplex != RTE_ETH_LINK_FULL_DUPLEX) {
1326 			fprintf(stderr, "Invalid speed/duplex parameters\n");
1327 			return -1;
1328 		}
1329 		if (!strcmp(speedstr, "1000")) {
1330 			*speed = RTE_ETH_LINK_SPEED_1G;
1331 		} else if (!strcmp(speedstr, "10000")) {
1332 			*speed = RTE_ETH_LINK_SPEED_10G;
1333 		} else if (!strcmp(speedstr, "25000")) {
1334 			*speed = RTE_ETH_LINK_SPEED_25G;
1335 		} else if (!strcmp(speedstr, "40000")) {
1336 			*speed = RTE_ETH_LINK_SPEED_40G;
1337 		} else if (!strcmp(speedstr, "50000")) {
1338 			*speed = RTE_ETH_LINK_SPEED_50G;
1339 		} else if (!strcmp(speedstr, "100000")) {
1340 			*speed = RTE_ETH_LINK_SPEED_100G;
1341 		} else if (!strcmp(speedstr, "200000")) {
1342 			*speed = RTE_ETH_LINK_SPEED_200G;
1343 		} else if (!strcmp(speedstr, "auto")) {
1344 			*speed = RTE_ETH_LINK_SPEED_AUTONEG;
1345 		} else {
1346 			fprintf(stderr, "Unknown speed parameter\n");
1347 			return -1;
1348 		}
1349 	}
1350 
1351 	if (*speed != RTE_ETH_LINK_SPEED_AUTONEG)
1352 		*speed |= RTE_ETH_LINK_SPEED_FIXED;
1353 
1354 	return 0;
1355 }
1356 
1357 static void
1358 cmd_config_speed_all_parsed(void *parsed_result,
1359 			__rte_unused struct cmdline *cl,
1360 			__rte_unused void *data)
1361 {
1362 	struct cmd_config_speed_all *res = parsed_result;
1363 	uint32_t link_speed;
1364 	portid_t pid;
1365 
1366 	if (!all_ports_stopped()) {
1367 		fprintf(stderr, "Please stop all ports first\n");
1368 		return;
1369 	}
1370 
1371 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1372 			&link_speed) < 0)
1373 		return;
1374 
1375 	RTE_ETH_FOREACH_DEV(pid) {
1376 		ports[pid].dev_conf.link_speeds = link_speed;
1377 	}
1378 
1379 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1380 }
1381 
1382 static cmdline_parse_token_string_t cmd_config_speed_all_port =
1383 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1384 static cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1385 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1386 							"config");
1387 static cmdline_parse_token_string_t cmd_config_speed_all_all =
1388 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1389 static cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1390 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1391 static cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1392 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1393 				"10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1394 static cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1395 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1396 static cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1397 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1398 						"half#full#auto");
1399 
1400 static cmdline_parse_inst_t cmd_config_speed_all = {
1401 	.f = cmd_config_speed_all_parsed,
1402 	.data = NULL,
1403 	.help_str = "port config all speed "
1404 		"10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1405 							"half|full|auto",
1406 	.tokens = {
1407 		(void *)&cmd_config_speed_all_port,
1408 		(void *)&cmd_config_speed_all_keyword,
1409 		(void *)&cmd_config_speed_all_all,
1410 		(void *)&cmd_config_speed_all_item1,
1411 		(void *)&cmd_config_speed_all_value1,
1412 		(void *)&cmd_config_speed_all_item2,
1413 		(void *)&cmd_config_speed_all_value2,
1414 		NULL,
1415 	},
1416 };
1417 
1418 /* *** configure speed for specific port *** */
1419 struct cmd_config_speed_specific {
1420 	cmdline_fixed_string_t port;
1421 	cmdline_fixed_string_t keyword;
1422 	portid_t id;
1423 	cmdline_fixed_string_t item1;
1424 	cmdline_fixed_string_t item2;
1425 	cmdline_fixed_string_t value1;
1426 	cmdline_fixed_string_t value2;
1427 };
1428 
1429 static void
1430 cmd_config_speed_specific_parsed(void *parsed_result,
1431 				__rte_unused struct cmdline *cl,
1432 				__rte_unused void *data)
1433 {
1434 	struct cmd_config_speed_specific *res = parsed_result;
1435 	uint32_t link_speed;
1436 
1437 	if (port_id_is_invalid(res->id, ENABLED_WARN))
1438 		return;
1439 
1440 	if (!port_is_stopped(res->id)) {
1441 		fprintf(stderr, "Please stop port %d first\n", res->id);
1442 		return;
1443 	}
1444 
1445 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1446 			&link_speed) < 0)
1447 		return;
1448 
1449 	ports[res->id].dev_conf.link_speeds = link_speed;
1450 
1451 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1452 }
1453 
1454 
1455 static cmdline_parse_token_string_t cmd_config_speed_specific_port =
1456 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1457 								"port");
1458 static cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1459 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1460 								"config");
1461 static cmdline_parse_token_num_t cmd_config_speed_specific_id =
1462 	TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1463 static cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1464 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1465 								"speed");
1466 static cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1467 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1468 				"10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1469 static cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1470 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1471 								"duplex");
1472 static cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1473 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1474 							"half#full#auto");
1475 
1476 static cmdline_parse_inst_t cmd_config_speed_specific = {
1477 	.f = cmd_config_speed_specific_parsed,
1478 	.data = NULL,
1479 	.help_str = "port config <port_id> speed "
1480 		"10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1481 							"half|full|auto",
1482 	.tokens = {
1483 		(void *)&cmd_config_speed_specific_port,
1484 		(void *)&cmd_config_speed_specific_keyword,
1485 		(void *)&cmd_config_speed_specific_id,
1486 		(void *)&cmd_config_speed_specific_item1,
1487 		(void *)&cmd_config_speed_specific_value1,
1488 		(void *)&cmd_config_speed_specific_item2,
1489 		(void *)&cmd_config_speed_specific_value2,
1490 		NULL,
1491 	},
1492 };
1493 
1494 /* *** configure loopback for all ports *** */
1495 struct cmd_config_loopback_all {
1496 	cmdline_fixed_string_t port;
1497 	cmdline_fixed_string_t keyword;
1498 	cmdline_fixed_string_t all;
1499 	cmdline_fixed_string_t item;
1500 	uint32_t mode;
1501 };
1502 
1503 static void
1504 cmd_config_loopback_all_parsed(void *parsed_result,
1505 			__rte_unused struct cmdline *cl,
1506 			__rte_unused void *data)
1507 {
1508 	struct cmd_config_loopback_all *res = parsed_result;
1509 	portid_t pid;
1510 
1511 	if (!all_ports_stopped()) {
1512 		fprintf(stderr, "Please stop all ports first\n");
1513 		return;
1514 	}
1515 
1516 	RTE_ETH_FOREACH_DEV(pid) {
1517 		ports[pid].dev_conf.lpbk_mode = res->mode;
1518 	}
1519 
1520 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1521 }
1522 
1523 static cmdline_parse_token_string_t cmd_config_loopback_all_port =
1524 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1525 static cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1526 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1527 							"config");
1528 static cmdline_parse_token_string_t cmd_config_loopback_all_all =
1529 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1530 static cmdline_parse_token_string_t cmd_config_loopback_all_item =
1531 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1532 							"loopback");
1533 static cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1534 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1535 
1536 static cmdline_parse_inst_t cmd_config_loopback_all = {
1537 	.f = cmd_config_loopback_all_parsed,
1538 	.data = NULL,
1539 	.help_str = "port config all loopback <mode>",
1540 	.tokens = {
1541 		(void *)&cmd_config_loopback_all_port,
1542 		(void *)&cmd_config_loopback_all_keyword,
1543 		(void *)&cmd_config_loopback_all_all,
1544 		(void *)&cmd_config_loopback_all_item,
1545 		(void *)&cmd_config_loopback_all_mode,
1546 		NULL,
1547 	},
1548 };
1549 
1550 /* *** configure loopback for specific port *** */
1551 struct cmd_config_loopback_specific {
1552 	cmdline_fixed_string_t port;
1553 	cmdline_fixed_string_t keyword;
1554 	uint16_t port_id;
1555 	cmdline_fixed_string_t item;
1556 	uint32_t mode;
1557 };
1558 
1559 static void
1560 cmd_config_loopback_specific_parsed(void *parsed_result,
1561 				__rte_unused struct cmdline *cl,
1562 				__rte_unused void *data)
1563 {
1564 	struct cmd_config_loopback_specific *res = parsed_result;
1565 
1566 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1567 		return;
1568 
1569 	if (!port_is_stopped(res->port_id)) {
1570 		fprintf(stderr, "Please stop port %u first\n", res->port_id);
1571 		return;
1572 	}
1573 
1574 	ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1575 
1576 	cmd_reconfig_device_queue(res->port_id, 1, 1);
1577 }
1578 
1579 
1580 static cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1581 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1582 								"port");
1583 static cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1584 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1585 								"config");
1586 static cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1587 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1588 								RTE_UINT16);
1589 static cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1590 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1591 								"loopback");
1592 static cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1593 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1594 			      RTE_UINT32);
1595 
1596 static cmdline_parse_inst_t cmd_config_loopback_specific = {
1597 	.f = cmd_config_loopback_specific_parsed,
1598 	.data = NULL,
1599 	.help_str = "port config <port_id> loopback <mode>",
1600 	.tokens = {
1601 		(void *)&cmd_config_loopback_specific_port,
1602 		(void *)&cmd_config_loopback_specific_keyword,
1603 		(void *)&cmd_config_loopback_specific_id,
1604 		(void *)&cmd_config_loopback_specific_item,
1605 		(void *)&cmd_config_loopback_specific_mode,
1606 		NULL,
1607 	},
1608 };
1609 
1610 /* *** configure txq/rxq, txd/rxd *** */
1611 struct cmd_config_rx_tx {
1612 	cmdline_fixed_string_t port;
1613 	cmdline_fixed_string_t keyword;
1614 	cmdline_fixed_string_t all;
1615 	cmdline_fixed_string_t name;
1616 	uint16_t value;
1617 };
1618 
1619 static void
1620 cmd_config_rx_tx_parsed(void *parsed_result,
1621 			__rte_unused struct cmdline *cl,
1622 			__rte_unused void *data)
1623 {
1624 	struct cmd_config_rx_tx *res = parsed_result;
1625 
1626 	if (!all_ports_stopped()) {
1627 		fprintf(stderr, "Please stop all ports first\n");
1628 		return;
1629 	}
1630 	if (!strcmp(res->name, "rxq")) {
1631 		if (!res->value && !nb_txq) {
1632 			fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1633 			return;
1634 		}
1635 		if (check_nb_rxq(res->value) != 0)
1636 			return;
1637 		nb_rxq = res->value;
1638 	}
1639 	else if (!strcmp(res->name, "txq")) {
1640 		if (!res->value && !nb_rxq) {
1641 			fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1642 			return;
1643 		}
1644 		if (check_nb_txq(res->value) != 0)
1645 			return;
1646 		nb_txq = res->value;
1647 	}
1648 	else if (!strcmp(res->name, "rxd")) {
1649 		if (check_nb_rxd(res->value) != 0)
1650 			return;
1651 		nb_rxd = res->value;
1652 	} else if (!strcmp(res->name, "txd")) {
1653 		if (check_nb_txd(res->value) != 0)
1654 			return;
1655 
1656 		nb_txd = res->value;
1657 	} else {
1658 		fprintf(stderr, "Unknown parameter\n");
1659 		return;
1660 	}
1661 
1662 	fwd_config_setup();
1663 
1664 	init_port_config();
1665 
1666 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1667 }
1668 
1669 static cmdline_parse_token_string_t cmd_config_rx_tx_port =
1670 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1671 static cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1672 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1673 static cmdline_parse_token_string_t cmd_config_rx_tx_all =
1674 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1675 static cmdline_parse_token_string_t cmd_config_rx_tx_name =
1676 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1677 						"rxq#txq#rxd#txd");
1678 static cmdline_parse_token_num_t cmd_config_rx_tx_value =
1679 	TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1680 
1681 static cmdline_parse_inst_t cmd_config_rx_tx = {
1682 	.f = cmd_config_rx_tx_parsed,
1683 	.data = NULL,
1684 	.help_str = "port config all rxq|txq|rxd|txd <value>",
1685 	.tokens = {
1686 		(void *)&cmd_config_rx_tx_port,
1687 		(void *)&cmd_config_rx_tx_keyword,
1688 		(void *)&cmd_config_rx_tx_all,
1689 		(void *)&cmd_config_rx_tx_name,
1690 		(void *)&cmd_config_rx_tx_value,
1691 		NULL,
1692 	},
1693 };
1694 
1695 /* *** config max packet length *** */
1696 struct cmd_config_max_pkt_len_result {
1697 	cmdline_fixed_string_t port;
1698 	cmdline_fixed_string_t keyword;
1699 	cmdline_fixed_string_t all;
1700 	cmdline_fixed_string_t name;
1701 	uint32_t value;
1702 };
1703 
1704 static void
1705 cmd_config_max_pkt_len_parsed(void *parsed_result,
1706 				__rte_unused struct cmdline *cl,
1707 				__rte_unused void *data)
1708 {
1709 	struct cmd_config_max_pkt_len_result *res = parsed_result;
1710 	portid_t port_id;
1711 	int ret;
1712 
1713 	if (strcmp(res->name, "max-pkt-len") != 0) {
1714 		printf("Unknown parameter\n");
1715 		return;
1716 	}
1717 
1718 	if (!all_ports_stopped()) {
1719 		fprintf(stderr, "Please stop all ports first\n");
1720 		return;
1721 	}
1722 
1723 	RTE_ETH_FOREACH_DEV(port_id) {
1724 		struct rte_port *port = &ports[port_id];
1725 
1726 		if (res->value < RTE_ETHER_MIN_LEN) {
1727 			fprintf(stderr,
1728 				"max-pkt-len can not be less than %d\n",
1729 				RTE_ETHER_MIN_LEN);
1730 			return;
1731 		}
1732 
1733 		ret = eth_dev_info_get_print_err(port_id, &port->dev_info);
1734 		if (ret != 0) {
1735 			fprintf(stderr,
1736 				"rte_eth_dev_info_get() failed for port %u\n",
1737 				port_id);
1738 			return;
1739 		}
1740 
1741 		update_mtu_from_frame_size(port_id, res->value);
1742 	}
1743 
1744 	init_port_config();
1745 
1746 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1747 }
1748 
1749 static cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1750 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1751 								"port");
1752 static cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1753 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1754 								"config");
1755 static cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1756 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1757 								"all");
1758 static cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1759 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1760 								"max-pkt-len");
1761 static cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1762 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1763 								RTE_UINT32);
1764 
1765 static cmdline_parse_inst_t cmd_config_max_pkt_len = {
1766 	.f = cmd_config_max_pkt_len_parsed,
1767 	.data = NULL,
1768 	.help_str = "port config all max-pkt-len <value>",
1769 	.tokens = {
1770 		(void *)&cmd_config_max_pkt_len_port,
1771 		(void *)&cmd_config_max_pkt_len_keyword,
1772 		(void *)&cmd_config_max_pkt_len_all,
1773 		(void *)&cmd_config_max_pkt_len_name,
1774 		(void *)&cmd_config_max_pkt_len_value,
1775 		NULL,
1776 	},
1777 };
1778 
1779 /* *** config max LRO aggregated packet size *** */
1780 struct cmd_config_max_lro_pkt_size_result {
1781 	cmdline_fixed_string_t port;
1782 	cmdline_fixed_string_t keyword;
1783 	cmdline_fixed_string_t all;
1784 	cmdline_fixed_string_t name;
1785 	uint32_t value;
1786 };
1787 
1788 static void
1789 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1790 				__rte_unused struct cmdline *cl,
1791 				__rte_unused void *data)
1792 {
1793 	struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1794 	portid_t pid;
1795 
1796 	if (!all_ports_stopped()) {
1797 		fprintf(stderr, "Please stop all ports first\n");
1798 		return;
1799 	}
1800 
1801 	RTE_ETH_FOREACH_DEV(pid) {
1802 		struct rte_port *port = &ports[pid];
1803 
1804 		if (!strcmp(res->name, "max-lro-pkt-size")) {
1805 			if (res->value ==
1806 					port->dev_conf.rxmode.max_lro_pkt_size)
1807 				return;
1808 
1809 			port->dev_conf.rxmode.max_lro_pkt_size = res->value;
1810 		} else {
1811 			fprintf(stderr, "Unknown parameter\n");
1812 			return;
1813 		}
1814 	}
1815 
1816 	init_port_config();
1817 
1818 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1819 }
1820 
1821 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
1822 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1823 				 port, "port");
1824 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
1825 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1826 				 keyword, "config");
1827 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
1828 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1829 				 all, "all");
1830 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
1831 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1832 				 name, "max-lro-pkt-size");
1833 static cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
1834 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1835 			      value, RTE_UINT32);
1836 
1837 static cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
1838 	.f = cmd_config_max_lro_pkt_size_parsed,
1839 	.data = NULL,
1840 	.help_str = "port config all max-lro-pkt-size <value>",
1841 	.tokens = {
1842 		(void *)&cmd_config_max_lro_pkt_size_port,
1843 		(void *)&cmd_config_max_lro_pkt_size_keyword,
1844 		(void *)&cmd_config_max_lro_pkt_size_all,
1845 		(void *)&cmd_config_max_lro_pkt_size_name,
1846 		(void *)&cmd_config_max_lro_pkt_size_value,
1847 		NULL,
1848 	},
1849 };
1850 
1851 /* *** configure port MTU *** */
1852 struct cmd_config_mtu_result {
1853 	cmdline_fixed_string_t port;
1854 	cmdline_fixed_string_t keyword;
1855 	cmdline_fixed_string_t mtu;
1856 	portid_t port_id;
1857 	uint16_t value;
1858 };
1859 
1860 static void
1861 cmd_config_mtu_parsed(void *parsed_result,
1862 		      __rte_unused struct cmdline *cl,
1863 		      __rte_unused void *data)
1864 {
1865 	struct cmd_config_mtu_result *res = parsed_result;
1866 
1867 	port_mtu_set(res->port_id, res->value);
1868 }
1869 
1870 static cmdline_parse_token_string_t cmd_config_mtu_port =
1871 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1872 				 "port");
1873 static cmdline_parse_token_string_t cmd_config_mtu_keyword =
1874 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1875 				 "config");
1876 static cmdline_parse_token_string_t cmd_config_mtu_mtu =
1877 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1878 				 "mtu");
1879 static cmdline_parse_token_num_t cmd_config_mtu_port_id =
1880 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
1881 				 RTE_UINT16);
1882 static cmdline_parse_token_num_t cmd_config_mtu_value =
1883 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
1884 				 RTE_UINT16);
1885 
1886 static cmdline_parse_inst_t cmd_config_mtu = {
1887 	.f = cmd_config_mtu_parsed,
1888 	.data = NULL,
1889 	.help_str = "port config mtu <port_id> <value>",
1890 	.tokens = {
1891 		(void *)&cmd_config_mtu_port,
1892 		(void *)&cmd_config_mtu_keyword,
1893 		(void *)&cmd_config_mtu_mtu,
1894 		(void *)&cmd_config_mtu_port_id,
1895 		(void *)&cmd_config_mtu_value,
1896 		NULL,
1897 	},
1898 };
1899 
1900 /* *** configure rx mode *** */
1901 struct cmd_config_rx_mode_flag {
1902 	cmdline_fixed_string_t port;
1903 	cmdline_fixed_string_t keyword;
1904 	cmdline_fixed_string_t all;
1905 	cmdline_fixed_string_t name;
1906 	cmdline_fixed_string_t value;
1907 };
1908 
1909 static void
1910 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1911 				__rte_unused struct cmdline *cl,
1912 				__rte_unused void *data)
1913 {
1914 	struct cmd_config_rx_mode_flag *res = parsed_result;
1915 
1916 	if (!all_ports_stopped()) {
1917 		fprintf(stderr, "Please stop all ports first\n");
1918 		return;
1919 	}
1920 
1921 	if (!strcmp(res->name, "drop-en")) {
1922 		if (!strcmp(res->value, "on"))
1923 			rx_drop_en = 1;
1924 		else if (!strcmp(res->value, "off"))
1925 			rx_drop_en = 0;
1926 		else {
1927 			fprintf(stderr, "Unknown parameter\n");
1928 			return;
1929 		}
1930 	} else {
1931 		fprintf(stderr, "Unknown parameter\n");
1932 		return;
1933 	}
1934 
1935 	init_port_config();
1936 
1937 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1938 }
1939 
1940 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1941 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1942 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1943 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1944 								"config");
1945 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1946 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1947 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1948 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1949 					"drop-en");
1950 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1951 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1952 							"on#off");
1953 
1954 static cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1955 	.f = cmd_config_rx_mode_flag_parsed,
1956 	.data = NULL,
1957 	.help_str = "port config all drop-en on|off",
1958 	.tokens = {
1959 		(void *)&cmd_config_rx_mode_flag_port,
1960 		(void *)&cmd_config_rx_mode_flag_keyword,
1961 		(void *)&cmd_config_rx_mode_flag_all,
1962 		(void *)&cmd_config_rx_mode_flag_name,
1963 		(void *)&cmd_config_rx_mode_flag_value,
1964 		NULL,
1965 	},
1966 };
1967 
1968 /* *** configure rss *** */
1969 struct cmd_config_rss {
1970 	cmdline_fixed_string_t port;
1971 	cmdline_fixed_string_t keyword;
1972 	cmdline_fixed_string_t all;
1973 	cmdline_fixed_string_t name;
1974 	cmdline_fixed_string_t value;
1975 };
1976 
1977 static void
1978 cmd_config_rss_parsed(void *parsed_result,
1979 			__rte_unused struct cmdline *cl,
1980 			__rte_unused void *data)
1981 {
1982 	struct cmd_config_rss *res = parsed_result;
1983 	struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1984 	struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
1985 	int use_default = 0;
1986 	int all_updated = 1;
1987 	int diag;
1988 	uint16_t i;
1989 	int ret;
1990 
1991 	if (!strcmp(res->value, "level-default")) {
1992 		rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
1993 		rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_PMD_DEFAULT);
1994 	} else if (!strcmp(res->value, "level-outer")) {
1995 		rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
1996 		rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_OUTERMOST);
1997 	} else if (!strcmp(res->value, "level-inner")) {
1998 		rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
1999 		rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_INNERMOST);
2000 	} else if (!strcmp(res->value, "default")) {
2001 		use_default = 1;
2002 	} else if (isdigit(res->value[0])) {
2003 		int value = atoi(res->value);
2004 		if (value > 0 && value < 64)
2005 			rss_conf.rss_hf = 1ULL << (uint8_t)value;
2006 		else {
2007 			fprintf(stderr, "flowtype_id should be greater than 0 and less than 64.\n");
2008 			return;
2009 		}
2010 	} else if (!strcmp(res->value, "none")) {
2011 		rss_conf.rss_hf = 0;
2012 	} else {
2013 		rss_conf.rss_hf = str_to_rsstypes(res->value);
2014 		if (rss_conf.rss_hf == 0) {
2015 			fprintf(stderr, "Unknown parameter\n");
2016 			return;
2017 		}
2018 	}
2019 	rss_conf.rss_key = NULL;
2020 	/* Update global configuration for RSS types. */
2021 	RTE_ETH_FOREACH_DEV(i) {
2022 		struct rte_eth_rss_conf local_rss_conf;
2023 
2024 		ret = eth_dev_info_get_print_err(i, &dev_info);
2025 		if (ret != 0)
2026 			return;
2027 
2028 		if (use_default)
2029 			rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2030 
2031 		local_rss_conf = rss_conf;
2032 		local_rss_conf.rss_hf = rss_conf.rss_hf &
2033 			dev_info.flow_type_rss_offloads;
2034 		if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2035 			printf("Port %u modified RSS hash function based on hardware support,"
2036 				"requested:%#"PRIx64" configured:%#"PRIx64"\n",
2037 				i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2038 		}
2039 		diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2040 		if (diag < 0) {
2041 			all_updated = 0;
2042 			fprintf(stderr,
2043 				"Configuration of RSS hash at ethernet port %d failed with error (%d): %s.\n",
2044 				i, -diag, strerror(-diag));
2045 		}
2046 	}
2047 	if (all_updated && !use_default) {
2048 		rss_hf = rss_conf.rss_hf;
2049 		printf("rss_hf %#"PRIx64"\n", rss_hf);
2050 	}
2051 }
2052 
2053 static cmdline_parse_token_string_t cmd_config_rss_port =
2054 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2055 static cmdline_parse_token_string_t cmd_config_rss_keyword =
2056 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2057 static cmdline_parse_token_string_t cmd_config_rss_all =
2058 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2059 static cmdline_parse_token_string_t cmd_config_rss_name =
2060 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2061 static cmdline_parse_token_string_t cmd_config_rss_value =
2062 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2063 
2064 static cmdline_parse_inst_t cmd_config_rss = {
2065 	.f = cmd_config_rss_parsed,
2066 	.data = NULL,
2067 	.help_str = "port config all rss "
2068 		"all|default|level-default|level-outer|level-inner|"
2069 		"ip|tcp|udp|sctp|tunnel|vlan|none|"
2070 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2071 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2072 		"l2-payload|port|vxlan|geneve|nvgre|gtpu|eth|s-vlan|c-vlan|"
2073 		"esp|ah|l2tpv3|pfcp|pppoe|ecpri|mpls|ipv4-chksum|l4-chksum|"
2074 		"l2tpv2|l3-pre96|l3-pre64|l3-pre56|l3-pre48|l3-pre40|l3-pre32|"
2075 		"l2-dst-only|l2-src-only|l4-dst-only|l4-src-only|l3-dst-only|l3-src-only|<rsstype_id>",
2076 	.tokens = {
2077 		(void *)&cmd_config_rss_port,
2078 		(void *)&cmd_config_rss_keyword,
2079 		(void *)&cmd_config_rss_all,
2080 		(void *)&cmd_config_rss_name,
2081 		(void *)&cmd_config_rss_value,
2082 		NULL,
2083 	},
2084 };
2085 
2086 /* *** configure rss hash key *** */
2087 struct cmd_config_rss_hash_key {
2088 	cmdline_fixed_string_t port;
2089 	cmdline_fixed_string_t config;
2090 	portid_t port_id;
2091 	cmdline_fixed_string_t rss_hash_key;
2092 	cmdline_fixed_string_t rss_type;
2093 	cmdline_fixed_string_t key;
2094 };
2095 
2096 static uint8_t
2097 hexa_digit_to_value(char hexa_digit)
2098 {
2099 	if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2100 		return (uint8_t) (hexa_digit - '0');
2101 	if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2102 		return (uint8_t) ((hexa_digit - 'a') + 10);
2103 	if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2104 		return (uint8_t) ((hexa_digit - 'A') + 10);
2105 	/* Invalid hexa digit */
2106 	return 0xFF;
2107 }
2108 
2109 static uint8_t
2110 parse_and_check_key_hexa_digit(char *key, int idx)
2111 {
2112 	uint8_t hexa_v;
2113 
2114 	hexa_v = hexa_digit_to_value(key[idx]);
2115 	if (hexa_v == 0xFF)
2116 		fprintf(stderr,
2117 			"invalid key: character %c at position %d is not a valid hexa digit\n",
2118 			key[idx], idx);
2119 	return hexa_v;
2120 }
2121 
2122 static void
2123 cmd_config_rss_hash_key_parsed(void *parsed_result,
2124 			       __rte_unused struct cmdline *cl,
2125 			       __rte_unused void *data)
2126 {
2127 	struct cmd_config_rss_hash_key *res = parsed_result;
2128 	uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2129 	uint8_t xdgt0;
2130 	uint8_t xdgt1;
2131 	int i;
2132 	struct rte_eth_dev_info dev_info;
2133 	uint8_t hash_key_size;
2134 	uint32_t key_len;
2135 	int ret;
2136 
2137 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2138 	if (ret != 0)
2139 		return;
2140 
2141 	if (dev_info.hash_key_size > 0 &&
2142 			dev_info.hash_key_size <= sizeof(hash_key))
2143 		hash_key_size = dev_info.hash_key_size;
2144 	else {
2145 		fprintf(stderr,
2146 			"dev_info did not provide a valid hash key size\n");
2147 		return;
2148 	}
2149 	/* Check the length of the RSS hash key */
2150 	key_len = strlen(res->key);
2151 	if (key_len != (hash_key_size * 2)) {
2152 		fprintf(stderr,
2153 			"key length: %d invalid - key must be a string of %d hexa-decimal numbers\n",
2154 			(int)key_len, hash_key_size * 2);
2155 		return;
2156 	}
2157 	/* Translate RSS hash key into binary representation */
2158 	for (i = 0; i < hash_key_size; i++) {
2159 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2160 		if (xdgt0 == 0xFF)
2161 			return;
2162 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2163 		if (xdgt1 == 0xFF)
2164 			return;
2165 		hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2166 	}
2167 	port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2168 			hash_key_size);
2169 }
2170 
2171 static cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2172 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2173 static cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2174 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2175 				 "config");
2176 static cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2177 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2178 				 RTE_UINT16);
2179 static cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2180 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2181 				 rss_hash_key, "rss-hash-key");
2182 static cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2183 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2184 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2185 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2186 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2187 				 "ipv6-tcp-ex#ipv6-udp-ex#"
2188 				 "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2189 				 "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2190 				 "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls#l2tpv2");
2191 static cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2192 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2193 
2194 static cmdline_parse_inst_t cmd_config_rss_hash_key = {
2195 	.f = cmd_config_rss_hash_key_parsed,
2196 	.data = NULL,
2197 	.help_str = "port config <port_id> rss-hash-key "
2198 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2199 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2200 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2201 		"l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2202 		"l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2203 		"l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls|l2tpv2 "
2204 		"<string of hex digits (variable length, NIC dependent)>",
2205 	.tokens = {
2206 		(void *)&cmd_config_rss_hash_key_port,
2207 		(void *)&cmd_config_rss_hash_key_config,
2208 		(void *)&cmd_config_rss_hash_key_port_id,
2209 		(void *)&cmd_config_rss_hash_key_rss_hash_key,
2210 		(void *)&cmd_config_rss_hash_key_rss_type,
2211 		(void *)&cmd_config_rss_hash_key_value,
2212 		NULL,
2213 	},
2214 };
2215 
2216 /* *** cleanup txq mbufs *** */
2217 struct cmd_cleanup_txq_mbufs_result {
2218 	cmdline_fixed_string_t port;
2219 	cmdline_fixed_string_t keyword;
2220 	cmdline_fixed_string_t name;
2221 	uint16_t port_id;
2222 	uint16_t queue_id;
2223 	uint32_t free_cnt;
2224 };
2225 
2226 static void
2227 cmd_cleanup_txq_mbufs_parsed(void *parsed_result,
2228 			     __rte_unused struct cmdline *cl,
2229 			     __rte_unused void *data)
2230 {
2231 	struct cmd_cleanup_txq_mbufs_result *res = parsed_result;
2232 	uint16_t port_id = res->port_id;
2233 	uint16_t queue_id = res->queue_id;
2234 	uint32_t free_cnt = res->free_cnt;
2235 	struct rte_eth_txq_info qinfo;
2236 	int ret;
2237 
2238 	if (test_done == 0) {
2239 		fprintf(stderr, "Please stop forwarding first\n");
2240 		return;
2241 	}
2242 
2243 	if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) {
2244 		fprintf(stderr, "Failed to get port %u Tx queue %u info\n",
2245 			port_id, queue_id);
2246 		return;
2247 	}
2248 
2249 	if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
2250 		fprintf(stderr, "Tx queue %u not started\n", queue_id);
2251 		return;
2252 	}
2253 
2254 	ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt);
2255 	if (ret < 0) {
2256 		fprintf(stderr,
2257 			"Failed to cleanup mbuf for port %u Tx queue %u error desc: %s(%d)\n",
2258 			port_id, queue_id, strerror(-ret), ret);
2259 		return;
2260 	}
2261 
2262 	printf("Cleanup port %u Tx queue %u mbuf nums: %u\n",
2263 	       port_id, queue_id, ret);
2264 }
2265 
2266 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port =
2267 	TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port,
2268 				 "port");
2269 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup =
2270 	TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword,
2271 				 "cleanup");
2272 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id =
2273 	TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id,
2274 			      RTE_UINT16);
2275 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq =
2276 	TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name,
2277 				 "txq");
2278 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id =
2279 	TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id,
2280 			      RTE_UINT16);
2281 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt =
2282 	TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt,
2283 			      RTE_UINT32);
2284 
2285 static cmdline_parse_inst_t cmd_cleanup_txq_mbufs = {
2286 	.f = cmd_cleanup_txq_mbufs_parsed,
2287 	.data = NULL,
2288 	.help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>",
2289 	.tokens = {
2290 		(void *)&cmd_cleanup_txq_mbufs_port,
2291 		(void *)&cmd_cleanup_txq_mbufs_cleanup,
2292 		(void *)&cmd_cleanup_txq_mbufs_port_id,
2293 		(void *)&cmd_cleanup_txq_mbufs_txq,
2294 		(void *)&cmd_cleanup_txq_mbufs_queue_id,
2295 		(void *)&cmd_cleanup_txq_mbufs_free_cnt,
2296 		NULL,
2297 	},
2298 };
2299 
2300 /* *** configure port rxq/txq ring size *** */
2301 struct cmd_config_rxtx_ring_size {
2302 	cmdline_fixed_string_t port;
2303 	cmdline_fixed_string_t config;
2304 	portid_t portid;
2305 	cmdline_fixed_string_t rxtxq;
2306 	uint16_t qid;
2307 	cmdline_fixed_string_t rsize;
2308 	uint16_t size;
2309 };
2310 
2311 static void
2312 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2313 				 __rte_unused struct cmdline *cl,
2314 				 __rte_unused void *data)
2315 {
2316 	struct cmd_config_rxtx_ring_size *res = parsed_result;
2317 	struct rte_port *port;
2318 	uint8_t isrx;
2319 
2320 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2321 		return;
2322 
2323 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2324 		fprintf(stderr, "Invalid port id\n");
2325 		return;
2326 	}
2327 
2328 	port = &ports[res->portid];
2329 
2330 	if (!strcmp(res->rxtxq, "rxq"))
2331 		isrx = 1;
2332 	else if (!strcmp(res->rxtxq, "txq"))
2333 		isrx = 0;
2334 	else {
2335 		fprintf(stderr, "Unknown parameter\n");
2336 		return;
2337 	}
2338 
2339 	if (isrx && rx_queue_id_is_invalid(res->qid))
2340 		return;
2341 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2342 		return;
2343 
2344 	if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2345 		fprintf(stderr,
2346 			"Invalid rx ring_size, must > rx_free_thresh: %d\n",
2347 			rx_free_thresh);
2348 		return;
2349 	}
2350 
2351 	if (isrx)
2352 		port->nb_rx_desc[res->qid] = res->size;
2353 	else
2354 		port->nb_tx_desc[res->qid] = res->size;
2355 
2356 	cmd_reconfig_device_queue(res->portid, 0, 1);
2357 }
2358 
2359 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2360 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2361 				 port, "port");
2362 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2363 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2364 				 config, "config");
2365 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2366 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2367 				 portid, RTE_UINT16);
2368 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2369 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2370 				 rxtxq, "rxq#txq");
2371 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2372 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2373 			      qid, RTE_UINT16);
2374 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2375 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2376 				 rsize, "ring_size");
2377 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2378 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2379 			      size, RTE_UINT16);
2380 
2381 static cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2382 	.f = cmd_config_rxtx_ring_size_parsed,
2383 	.data = NULL,
2384 	.help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2385 	.tokens = {
2386 		(void *)&cmd_config_rxtx_ring_size_port,
2387 		(void *)&cmd_config_rxtx_ring_size_config,
2388 		(void *)&cmd_config_rxtx_ring_size_portid,
2389 		(void *)&cmd_config_rxtx_ring_size_rxtxq,
2390 		(void *)&cmd_config_rxtx_ring_size_qid,
2391 		(void *)&cmd_config_rxtx_ring_size_rsize,
2392 		(void *)&cmd_config_rxtx_ring_size_size,
2393 		NULL,
2394 	},
2395 };
2396 
2397 /* *** configure port rxq/txq start/stop *** */
2398 struct cmd_config_rxtx_queue {
2399 	cmdline_fixed_string_t port;
2400 	portid_t portid;
2401 	cmdline_fixed_string_t rxtxq;
2402 	uint16_t qid;
2403 	cmdline_fixed_string_t opname;
2404 };
2405 
2406 static void
2407 cmd_config_rxtx_queue_parsed(void *parsed_result,
2408 			__rte_unused struct cmdline *cl,
2409 			__rte_unused void *data)
2410 {
2411 	struct cmd_config_rxtx_queue *res = parsed_result;
2412 	struct rte_port *port;
2413 	uint8_t isrx;
2414 	uint8_t isstart;
2415 	uint8_t *state;
2416 	int ret = 0;
2417 
2418 	if (test_done == 0) {
2419 		fprintf(stderr, "Please stop forwarding first\n");
2420 		return;
2421 	}
2422 
2423 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2424 		return;
2425 
2426 	if (port_is_started(res->portid) != 1) {
2427 		fprintf(stderr, "Please start port %u first\n", res->portid);
2428 		return;
2429 	}
2430 
2431 	if (!strcmp(res->rxtxq, "rxq"))
2432 		isrx = 1;
2433 	else if (!strcmp(res->rxtxq, "txq"))
2434 		isrx = 0;
2435 	else {
2436 		fprintf(stderr, "Unknown parameter\n");
2437 		return;
2438 	}
2439 
2440 	if (isrx && rx_queue_id_is_invalid(res->qid))
2441 		return;
2442 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2443 		return;
2444 
2445 	if (!strcmp(res->opname, "start"))
2446 		isstart = 1;
2447 	else if (!strcmp(res->opname, "stop"))
2448 		isstart = 0;
2449 	else {
2450 		fprintf(stderr, "Unknown parameter\n");
2451 		return;
2452 	}
2453 
2454 	if (isstart && isrx)
2455 		ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2456 	else if (!isstart && isrx)
2457 		ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2458 	else if (isstart && !isrx)
2459 		ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2460 	else
2461 		ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2462 
2463 	if (ret == -ENOTSUP) {
2464 		fprintf(stderr, "Function not supported in PMD\n");
2465 		return;
2466 	}
2467 
2468 	port = &ports[res->portid];
2469 	state = isrx ? &port->rxq[res->qid].state : &port->txq[res->qid].state;
2470 	*state = isstart ? RTE_ETH_QUEUE_STATE_STARTED :
2471 			   RTE_ETH_QUEUE_STATE_STOPPED;
2472 }
2473 
2474 static cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2475 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2476 static cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2477 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2478 static cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2479 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2480 static cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2481 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2482 static cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2483 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2484 						"start#stop");
2485 
2486 static cmdline_parse_inst_t cmd_config_rxtx_queue = {
2487 	.f = cmd_config_rxtx_queue_parsed,
2488 	.data = NULL,
2489 	.help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2490 	.tokens = {
2491 		(void *)&cmd_config_rxtx_queue_port,
2492 		(void *)&cmd_config_rxtx_queue_portid,
2493 		(void *)&cmd_config_rxtx_queue_rxtxq,
2494 		(void *)&cmd_config_rxtx_queue_qid,
2495 		(void *)&cmd_config_rxtx_queue_opname,
2496 		NULL,
2497 	},
2498 };
2499 
2500 /* *** configure port rxq/txq deferred start on/off *** */
2501 struct cmd_config_deferred_start_rxtx_queue {
2502 	cmdline_fixed_string_t port;
2503 	portid_t port_id;
2504 	cmdline_fixed_string_t rxtxq;
2505 	uint16_t qid;
2506 	cmdline_fixed_string_t opname;
2507 	cmdline_fixed_string_t state;
2508 };
2509 
2510 static void
2511 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2512 			__rte_unused struct cmdline *cl,
2513 			__rte_unused void *data)
2514 {
2515 	struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2516 	struct rte_port *port;
2517 	uint8_t isrx;
2518 	uint8_t ison;
2519 	uint8_t needreconfig = 0;
2520 
2521 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2522 		return;
2523 
2524 	if (port_is_started(res->port_id) != 0) {
2525 		fprintf(stderr, "Please stop port %u first\n", res->port_id);
2526 		return;
2527 	}
2528 
2529 	port = &ports[res->port_id];
2530 
2531 	isrx = !strcmp(res->rxtxq, "rxq");
2532 
2533 	if (isrx && rx_queue_id_is_invalid(res->qid))
2534 		return;
2535 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2536 		return;
2537 
2538 	ison = !strcmp(res->state, "on");
2539 
2540 	if (isrx && port->rxq[res->qid].conf.rx_deferred_start != ison) {
2541 		port->rxq[res->qid].conf.rx_deferred_start = ison;
2542 		needreconfig = 1;
2543 	} else if (!isrx && port->txq[res->qid].conf.tx_deferred_start != ison) {
2544 		port->txq[res->qid].conf.tx_deferred_start = ison;
2545 		needreconfig = 1;
2546 	}
2547 
2548 	if (needreconfig)
2549 		cmd_reconfig_device_queue(res->port_id, 0, 1);
2550 }
2551 
2552 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2553 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2554 						port, "port");
2555 static cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2556 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2557 						port_id, RTE_UINT16);
2558 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2559 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2560 						rxtxq, "rxq#txq");
2561 static cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2562 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2563 						qid, RTE_UINT16);
2564 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2565 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2566 						opname, "deferred_start");
2567 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2568 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2569 						state, "on#off");
2570 
2571 static cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2572 	.f = cmd_config_deferred_start_rxtx_queue_parsed,
2573 	.data = NULL,
2574 	.help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2575 	.tokens = {
2576 		(void *)&cmd_config_deferred_start_rxtx_queue_port,
2577 		(void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2578 		(void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2579 		(void *)&cmd_config_deferred_start_rxtx_queue_qid,
2580 		(void *)&cmd_config_deferred_start_rxtx_queue_opname,
2581 		(void *)&cmd_config_deferred_start_rxtx_queue_state,
2582 		NULL,
2583 	},
2584 };
2585 
2586 /* *** configure port rxq/txq setup *** */
2587 struct cmd_setup_rxtx_queue {
2588 	cmdline_fixed_string_t port;
2589 	portid_t portid;
2590 	cmdline_fixed_string_t rxtxq;
2591 	uint16_t qid;
2592 	cmdline_fixed_string_t setup;
2593 };
2594 
2595 /* Common CLI fields for queue setup */
2596 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2597 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2598 static cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2599 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2600 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2601 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2602 static cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2603 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2604 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2605 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2606 
2607 static void
2608 cmd_setup_rxtx_queue_parsed(
2609 	void *parsed_result,
2610 	__rte_unused struct cmdline *cl,
2611 	__rte_unused void *data)
2612 {
2613 	struct cmd_setup_rxtx_queue *res = parsed_result;
2614 	struct rte_port *port;
2615 	struct rte_mempool *mp;
2616 	unsigned int socket_id;
2617 	uint8_t isrx = 0;
2618 	int ret;
2619 
2620 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2621 		return;
2622 
2623 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2624 		fprintf(stderr, "Invalid port id\n");
2625 		return;
2626 	}
2627 
2628 	if (!strcmp(res->rxtxq, "rxq"))
2629 		isrx = 1;
2630 	else if (!strcmp(res->rxtxq, "txq"))
2631 		isrx = 0;
2632 	else {
2633 		fprintf(stderr, "Unknown parameter\n");
2634 		return;
2635 	}
2636 
2637 	if (isrx && rx_queue_id_is_invalid(res->qid)) {
2638 		fprintf(stderr, "Invalid rx queue\n");
2639 		return;
2640 	} else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2641 		fprintf(stderr, "Invalid tx queue\n");
2642 		return;
2643 	}
2644 
2645 	port = &ports[res->portid];
2646 	if (isrx) {
2647 		socket_id = rxring_numa[res->portid];
2648 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2649 			socket_id = port->socket_id;
2650 
2651 		mp = mbuf_pool_find(socket_id, 0);
2652 		if (mp == NULL) {
2653 			fprintf(stderr,
2654 				"Failed to setup RX queue: No mempool allocation on the socket %d\n",
2655 				rxring_numa[res->portid]);
2656 			return;
2657 		}
2658 		ret = rx_queue_setup(res->portid,
2659 				     res->qid,
2660 				     port->nb_rx_desc[res->qid],
2661 				     socket_id,
2662 				     &port->rxq[res->qid].conf,
2663 				     mp);
2664 		if (ret)
2665 			fprintf(stderr, "Failed to setup RX queue\n");
2666 	} else {
2667 		socket_id = txring_numa[res->portid];
2668 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2669 			socket_id = port->socket_id;
2670 
2671 		if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
2672 			fprintf(stderr,
2673 				"Failed to setup TX queue: not enough descriptors\n");
2674 			return;
2675 		}
2676 		ret = rte_eth_tx_queue_setup(res->portid,
2677 					     res->qid,
2678 					     port->nb_tx_desc[res->qid],
2679 					     socket_id,
2680 					     &port->txq[res->qid].conf);
2681 		if (ret)
2682 			fprintf(stderr, "Failed to setup TX queue\n");
2683 	}
2684 }
2685 
2686 static cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2687 	.f = cmd_setup_rxtx_queue_parsed,
2688 	.data = NULL,
2689 	.help_str = "port <port_id> rxq|txq <queue_idx> setup",
2690 	.tokens = {
2691 		(void *)&cmd_setup_rxtx_queue_port,
2692 		(void *)&cmd_setup_rxtx_queue_portid,
2693 		(void *)&cmd_setup_rxtx_queue_rxtxq,
2694 		(void *)&cmd_setup_rxtx_queue_qid,
2695 		(void *)&cmd_setup_rxtx_queue_setup,
2696 		NULL,
2697 	},
2698 };
2699 
2700 
2701 /* *** Configure RSS RETA *** */
2702 struct cmd_config_rss_reta {
2703 	cmdline_fixed_string_t port;
2704 	cmdline_fixed_string_t keyword;
2705 	portid_t port_id;
2706 	cmdline_fixed_string_t name;
2707 	cmdline_fixed_string_t list_name;
2708 	cmdline_fixed_string_t list_of_items;
2709 };
2710 
2711 static int
2712 parse_reta_config(const char *str,
2713 		  struct rte_eth_rss_reta_entry64 *reta_conf,
2714 		  uint16_t nb_entries)
2715 {
2716 	int i;
2717 	unsigned size;
2718 	uint16_t hash_index, idx, shift;
2719 	uint16_t nb_queue;
2720 	char s[256];
2721 	const char *p, *p0 = str;
2722 	char *end;
2723 	enum fieldnames {
2724 		FLD_HASH_INDEX = 0,
2725 		FLD_QUEUE,
2726 		_NUM_FLD
2727 	};
2728 	unsigned long int_fld[_NUM_FLD];
2729 	char *str_fld[_NUM_FLD];
2730 
2731 	while ((p = strchr(p0,'(')) != NULL) {
2732 		++p;
2733 		if((p0 = strchr(p,')')) == NULL)
2734 			return -1;
2735 
2736 		size = p0 - p;
2737 		if(size >= sizeof(s))
2738 			return -1;
2739 
2740 		snprintf(s, sizeof(s), "%.*s", size, p);
2741 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2742 			return -1;
2743 		for (i = 0; i < _NUM_FLD; i++) {
2744 			errno = 0;
2745 			int_fld[i] = strtoul(str_fld[i], &end, 0);
2746 			if (errno != 0 || end == str_fld[i] ||
2747 					int_fld[i] > 65535)
2748 				return -1;
2749 		}
2750 
2751 		hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2752 		nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2753 
2754 		if (hash_index >= nb_entries) {
2755 			fprintf(stderr, "Invalid RETA hash index=%d\n",
2756 				hash_index);
2757 			return -1;
2758 		}
2759 
2760 		idx = hash_index / RTE_ETH_RETA_GROUP_SIZE;
2761 		shift = hash_index % RTE_ETH_RETA_GROUP_SIZE;
2762 		reta_conf[idx].mask |= (1ULL << shift);
2763 		reta_conf[idx].reta[shift] = nb_queue;
2764 	}
2765 
2766 	return 0;
2767 }
2768 
2769 static void
2770 cmd_set_rss_reta_parsed(void *parsed_result,
2771 			__rte_unused struct cmdline *cl,
2772 			__rte_unused void *data)
2773 {
2774 	int ret;
2775 	struct rte_eth_dev_info dev_info;
2776 	struct rte_eth_rss_reta_entry64 reta_conf[8];
2777 	struct cmd_config_rss_reta *res = parsed_result;
2778 
2779 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2780 	if (ret != 0)
2781 		return;
2782 
2783 	if (dev_info.reta_size == 0) {
2784 		fprintf(stderr,
2785 			"Redirection table size is 0 which is invalid for RSS\n");
2786 		return;
2787 	} else
2788 		printf("The reta size of port %d is %u\n",
2789 			res->port_id, dev_info.reta_size);
2790 	if (dev_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
2791 		fprintf(stderr,
2792 			"Currently do not support more than %u entries of redirection table\n",
2793 			RTE_ETH_RSS_RETA_SIZE_512);
2794 		return;
2795 	}
2796 
2797 	memset(reta_conf, 0, sizeof(reta_conf));
2798 	if (!strcmp(res->list_name, "reta")) {
2799 		if (parse_reta_config(res->list_of_items, reta_conf,
2800 						dev_info.reta_size)) {
2801 			fprintf(stderr,
2802 				"Invalid RSS Redirection Table config entered\n");
2803 			return;
2804 		}
2805 		ret = rte_eth_dev_rss_reta_update(res->port_id,
2806 				reta_conf, dev_info.reta_size);
2807 		if (ret != 0)
2808 			fprintf(stderr,
2809 				"Bad redirection table parameter, return code = %d\n",
2810 				ret);
2811 	}
2812 }
2813 
2814 static cmdline_parse_token_string_t cmd_config_rss_reta_port =
2815 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2816 static cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2817 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2818 static cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2819 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
2820 static cmdline_parse_token_string_t cmd_config_rss_reta_name =
2821 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2822 static cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2823 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2824 static cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2825         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2826                                  NULL);
2827 static cmdline_parse_inst_t cmd_config_rss_reta = {
2828 	.f = cmd_set_rss_reta_parsed,
2829 	.data = NULL,
2830 	.help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2831 	.tokens = {
2832 		(void *)&cmd_config_rss_reta_port,
2833 		(void *)&cmd_config_rss_reta_keyword,
2834 		(void *)&cmd_config_rss_reta_port_id,
2835 		(void *)&cmd_config_rss_reta_name,
2836 		(void *)&cmd_config_rss_reta_list_name,
2837 		(void *)&cmd_config_rss_reta_list_of_items,
2838 		NULL,
2839 	},
2840 };
2841 
2842 /* *** SHOW PORT RETA INFO *** */
2843 struct cmd_showport_reta {
2844 	cmdline_fixed_string_t show;
2845 	cmdline_fixed_string_t port;
2846 	portid_t port_id;
2847 	cmdline_fixed_string_t rss;
2848 	cmdline_fixed_string_t reta;
2849 	uint16_t size;
2850 	cmdline_fixed_string_t list_of_items;
2851 };
2852 
2853 static int
2854 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2855 			   uint16_t nb_entries,
2856 			   char *str)
2857 {
2858 	uint32_t size;
2859 	const char *p, *p0 = str;
2860 	char s[256];
2861 	char *end;
2862 	char *str_fld[8];
2863 	uint16_t i;
2864 	uint16_t num = (nb_entries + RTE_ETH_RETA_GROUP_SIZE - 1) /
2865 			RTE_ETH_RETA_GROUP_SIZE;
2866 	int ret;
2867 
2868 	p = strchr(p0, '(');
2869 	if (p == NULL)
2870 		return -1;
2871 	p++;
2872 	p0 = strchr(p, ')');
2873 	if (p0 == NULL)
2874 		return -1;
2875 	size = p0 - p;
2876 	if (size >= sizeof(s)) {
2877 		fprintf(stderr,
2878 			"The string size exceeds the internal buffer size\n");
2879 		return -1;
2880 	}
2881 	snprintf(s, sizeof(s), "%.*s", size, p);
2882 	ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2883 	if (ret <= 0 || ret != num) {
2884 		fprintf(stderr,
2885 			"The bits of masks do not match the number of reta entries: %u\n",
2886 			num);
2887 		return -1;
2888 	}
2889 	for (i = 0; i < ret; i++)
2890 		conf[i].mask = (uint64_t)strtoull(str_fld[i], &end, 0);
2891 
2892 	return 0;
2893 }
2894 
2895 static void
2896 cmd_showport_reta_parsed(void *parsed_result,
2897 			 __rte_unused struct cmdline *cl,
2898 			 __rte_unused void *data)
2899 {
2900 	struct cmd_showport_reta *res = parsed_result;
2901 	struct rte_eth_rss_reta_entry64 reta_conf[8];
2902 	struct rte_eth_dev_info dev_info;
2903 	uint16_t max_reta_size;
2904 	int ret;
2905 
2906 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2907 	if (ret != 0)
2908 		return;
2909 
2910 	max_reta_size = RTE_MIN(dev_info.reta_size, RTE_ETH_RSS_RETA_SIZE_512);
2911 	if (res->size == 0 || res->size > max_reta_size) {
2912 		fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n",
2913 			res->size, max_reta_size);
2914 		return;
2915 	}
2916 
2917 	memset(reta_conf, 0, sizeof(reta_conf));
2918 	if (showport_parse_reta_config(reta_conf, res->size,
2919 				res->list_of_items) < 0) {
2920 		fprintf(stderr, "Invalid string: %s for reta masks\n",
2921 			res->list_of_items);
2922 		return;
2923 	}
2924 	port_rss_reta_info(res->port_id, reta_conf, res->size);
2925 }
2926 
2927 static cmdline_parse_token_string_t cmd_showport_reta_show =
2928 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2929 static cmdline_parse_token_string_t cmd_showport_reta_port =
2930 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2931 static cmdline_parse_token_num_t cmd_showport_reta_port_id =
2932 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
2933 static cmdline_parse_token_string_t cmd_showport_reta_rss =
2934 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2935 static cmdline_parse_token_string_t cmd_showport_reta_reta =
2936 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2937 static cmdline_parse_token_num_t cmd_showport_reta_size =
2938 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
2939 static cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2940 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2941 					list_of_items, NULL);
2942 
2943 static cmdline_parse_inst_t cmd_showport_reta = {
2944 	.f = cmd_showport_reta_parsed,
2945 	.data = NULL,
2946 	.help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2947 	.tokens = {
2948 		(void *)&cmd_showport_reta_show,
2949 		(void *)&cmd_showport_reta_port,
2950 		(void *)&cmd_showport_reta_port_id,
2951 		(void *)&cmd_showport_reta_rss,
2952 		(void *)&cmd_showport_reta_reta,
2953 		(void *)&cmd_showport_reta_size,
2954 		(void *)&cmd_showport_reta_list_of_items,
2955 		NULL,
2956 	},
2957 };
2958 
2959 /* *** Show RSS hash configuration *** */
2960 struct cmd_showport_rss_hash {
2961 	cmdline_fixed_string_t show;
2962 	cmdline_fixed_string_t port;
2963 	portid_t port_id;
2964 	cmdline_fixed_string_t rss_hash;
2965 	cmdline_fixed_string_t rss_type;
2966 	cmdline_fixed_string_t key; /* optional argument */
2967 };
2968 
2969 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2970 				__rte_unused struct cmdline *cl,
2971 				void *show_rss_key)
2972 {
2973 	struct cmd_showport_rss_hash *res = parsed_result;
2974 
2975 	port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
2976 }
2977 
2978 static cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2979 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2980 static cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2981 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2982 static cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2983 	TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
2984 				 RTE_UINT16);
2985 static cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2986 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2987 				 "rss-hash");
2988 static cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2989 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2990 
2991 static cmdline_parse_inst_t cmd_showport_rss_hash = {
2992 	.f = cmd_showport_rss_hash_parsed,
2993 	.data = NULL,
2994 	.help_str = "show port <port_id> rss-hash",
2995 	.tokens = {
2996 		(void *)&cmd_showport_rss_hash_show,
2997 		(void *)&cmd_showport_rss_hash_port,
2998 		(void *)&cmd_showport_rss_hash_port_id,
2999 		(void *)&cmd_showport_rss_hash_rss_hash,
3000 		NULL,
3001 	},
3002 };
3003 
3004 static cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3005 	.f = cmd_showport_rss_hash_parsed,
3006 	.data = (void *)1,
3007 	.help_str = "show port <port_id> rss-hash key",
3008 	.tokens = {
3009 		(void *)&cmd_showport_rss_hash_show,
3010 		(void *)&cmd_showport_rss_hash_port,
3011 		(void *)&cmd_showport_rss_hash_port_id,
3012 		(void *)&cmd_showport_rss_hash_rss_hash,
3013 		(void *)&cmd_showport_rss_hash_rss_key,
3014 		NULL,
3015 	},
3016 };
3017 
3018 /* *** Configure DCB *** */
3019 struct cmd_config_dcb {
3020 	cmdline_fixed_string_t port;
3021 	cmdline_fixed_string_t config;
3022 	portid_t port_id;
3023 	cmdline_fixed_string_t dcb;
3024 	cmdline_fixed_string_t vt;
3025 	cmdline_fixed_string_t vt_en;
3026 	uint8_t num_tcs;
3027 	cmdline_fixed_string_t pfc;
3028 	cmdline_fixed_string_t pfc_en;
3029 };
3030 
3031 static void
3032 cmd_config_dcb_parsed(void *parsed_result,
3033                         __rte_unused struct cmdline *cl,
3034                         __rte_unused void *data)
3035 {
3036 	struct cmd_config_dcb *res = parsed_result;
3037 	struct rte_eth_dcb_info dcb_info;
3038 	portid_t port_id = res->port_id;
3039 	struct rte_port *port;
3040 	uint8_t pfc_en;
3041 	int ret;
3042 
3043 	port = &ports[port_id];
3044 	/** Check if the port is not started **/
3045 	if (port->port_status != RTE_PORT_STOPPED) {
3046 		fprintf(stderr, "Please stop port %d first\n", port_id);
3047 		return;
3048 	}
3049 
3050 	if ((res->num_tcs != RTE_ETH_4_TCS) && (res->num_tcs != RTE_ETH_8_TCS)) {
3051 		fprintf(stderr,
3052 			"The invalid number of traffic class, only 4 or 8 allowed.\n");
3053 		return;
3054 	}
3055 
3056 	if (nb_fwd_lcores < res->num_tcs) {
3057 		fprintf(stderr,
3058 			"nb_cores shouldn't be less than number of TCs.\n");
3059 		return;
3060 	}
3061 
3062 	/* Check whether the port supports the report of DCB info. */
3063 	ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3064 	if (ret == -ENOTSUP) {
3065 		fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n");
3066 		return;
3067 	}
3068 
3069 	if (!strncmp(res->pfc_en, "on", 2))
3070 		pfc_en = 1;
3071 	else
3072 		pfc_en = 0;
3073 
3074 	/* DCB in VT mode */
3075 	if (!strncmp(res->vt_en, "on", 2))
3076 		ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3077 				(enum rte_eth_nb_tcs)res->num_tcs,
3078 				pfc_en);
3079 	else
3080 		ret = init_port_dcb_config(port_id, DCB_ENABLED,
3081 				(enum rte_eth_nb_tcs)res->num_tcs,
3082 				pfc_en);
3083 	if (ret != 0) {
3084 		fprintf(stderr, "Cannot initialize network ports.\n");
3085 		return;
3086 	}
3087 
3088 	fwd_config_setup();
3089 
3090 	cmd_reconfig_device_queue(port_id, 1, 1);
3091 }
3092 
3093 static cmdline_parse_token_string_t cmd_config_dcb_port =
3094         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3095 static cmdline_parse_token_string_t cmd_config_dcb_config =
3096         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3097 static cmdline_parse_token_num_t cmd_config_dcb_port_id =
3098 	TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3099 static cmdline_parse_token_string_t cmd_config_dcb_dcb =
3100         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3101 static cmdline_parse_token_string_t cmd_config_dcb_vt =
3102         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3103 static cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3104         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3105 static cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3106 	TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3107 static cmdline_parse_token_string_t cmd_config_dcb_pfc =
3108         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3109 static cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3110         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3111 
3112 static cmdline_parse_inst_t cmd_config_dcb = {
3113 	.f = cmd_config_dcb_parsed,
3114 	.data = NULL,
3115 	.help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3116 	.tokens = {
3117 		(void *)&cmd_config_dcb_port,
3118 		(void *)&cmd_config_dcb_config,
3119 		(void *)&cmd_config_dcb_port_id,
3120 		(void *)&cmd_config_dcb_dcb,
3121 		(void *)&cmd_config_dcb_vt,
3122 		(void *)&cmd_config_dcb_vt_en,
3123 		(void *)&cmd_config_dcb_num_tcs,
3124 		(void *)&cmd_config_dcb_pfc,
3125 		(void *)&cmd_config_dcb_pfc_en,
3126                 NULL,
3127         },
3128 };
3129 
3130 /* *** configure number of packets per burst *** */
3131 struct cmd_config_burst {
3132 	cmdline_fixed_string_t port;
3133 	cmdline_fixed_string_t keyword;
3134 	cmdline_fixed_string_t all;
3135 	cmdline_fixed_string_t name;
3136 	uint16_t value;
3137 };
3138 
3139 static void
3140 cmd_config_burst_parsed(void *parsed_result,
3141 			__rte_unused struct cmdline *cl,
3142 			__rte_unused void *data)
3143 {
3144 	struct cmd_config_burst *res = parsed_result;
3145 	struct rte_eth_dev_info dev_info;
3146 	uint16_t rec_nb_pkts;
3147 	int ret;
3148 
3149 	if (!all_ports_stopped()) {
3150 		fprintf(stderr, "Please stop all ports first\n");
3151 		return;
3152 	}
3153 
3154 	if (!strcmp(res->name, "burst")) {
3155 		if (res->value == 0) {
3156 			/* If user gives a value of zero, query the PMD for
3157 			 * its recommended Rx burst size. Testpmd uses a single
3158 			 * size for all ports, so assume all ports are the same
3159 			 * NIC model and use the values from Port 0.
3160 			 */
3161 			ret = eth_dev_info_get_print_err(0, &dev_info);
3162 			if (ret != 0)
3163 				return;
3164 
3165 			rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3166 
3167 			if (rec_nb_pkts == 0) {
3168 				printf("PMD does not recommend a burst size.\n"
3169 					"User provided value must be between"
3170 					" 1 and %d\n", MAX_PKT_BURST);
3171 				return;
3172 			} else if (rec_nb_pkts > MAX_PKT_BURST) {
3173 				printf("PMD recommended burst size of %d"
3174 					" exceeds maximum value of %d\n",
3175 					rec_nb_pkts, MAX_PKT_BURST);
3176 				return;
3177 			}
3178 			printf("Using PMD-provided burst value of %d\n",
3179 				rec_nb_pkts);
3180 			nb_pkt_per_burst = rec_nb_pkts;
3181 		} else if (res->value > MAX_PKT_BURST) {
3182 			fprintf(stderr, "burst must be >= 1 && <= %d\n",
3183 				MAX_PKT_BURST);
3184 			return;
3185 		} else
3186 			nb_pkt_per_burst = res->value;
3187 	} else {
3188 		fprintf(stderr, "Unknown parameter\n");
3189 		return;
3190 	}
3191 
3192 	init_port_config();
3193 
3194 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3195 }
3196 
3197 static cmdline_parse_token_string_t cmd_config_burst_port =
3198 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3199 static cmdline_parse_token_string_t cmd_config_burst_keyword =
3200 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3201 static cmdline_parse_token_string_t cmd_config_burst_all =
3202 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3203 static cmdline_parse_token_string_t cmd_config_burst_name =
3204 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3205 static cmdline_parse_token_num_t cmd_config_burst_value =
3206 	TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3207 
3208 static cmdline_parse_inst_t cmd_config_burst = {
3209 	.f = cmd_config_burst_parsed,
3210 	.data = NULL,
3211 	.help_str = "port config all burst <value>",
3212 	.tokens = {
3213 		(void *)&cmd_config_burst_port,
3214 		(void *)&cmd_config_burst_keyword,
3215 		(void *)&cmd_config_burst_all,
3216 		(void *)&cmd_config_burst_name,
3217 		(void *)&cmd_config_burst_value,
3218 		NULL,
3219 	},
3220 };
3221 
3222 /* *** configure rx/tx queues *** */
3223 struct cmd_config_thresh {
3224 	cmdline_fixed_string_t port;
3225 	cmdline_fixed_string_t keyword;
3226 	cmdline_fixed_string_t all;
3227 	cmdline_fixed_string_t name;
3228 	uint8_t value;
3229 };
3230 
3231 static void
3232 cmd_config_thresh_parsed(void *parsed_result,
3233 			__rte_unused struct cmdline *cl,
3234 			__rte_unused void *data)
3235 {
3236 	struct cmd_config_thresh *res = parsed_result;
3237 
3238 	if (!all_ports_stopped()) {
3239 		fprintf(stderr, "Please stop all ports first\n");
3240 		return;
3241 	}
3242 
3243 	if (!strcmp(res->name, "txpt"))
3244 		tx_pthresh = res->value;
3245 	else if(!strcmp(res->name, "txht"))
3246 		tx_hthresh = res->value;
3247 	else if(!strcmp(res->name, "txwt"))
3248 		tx_wthresh = res->value;
3249 	else if(!strcmp(res->name, "rxpt"))
3250 		rx_pthresh = res->value;
3251 	else if(!strcmp(res->name, "rxht"))
3252 		rx_hthresh = res->value;
3253 	else if(!strcmp(res->name, "rxwt"))
3254 		rx_wthresh = res->value;
3255 	else {
3256 		fprintf(stderr, "Unknown parameter\n");
3257 		return;
3258 	}
3259 
3260 	init_port_config();
3261 
3262 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3263 }
3264 
3265 static cmdline_parse_token_string_t cmd_config_thresh_port =
3266 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3267 static cmdline_parse_token_string_t cmd_config_thresh_keyword =
3268 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3269 static cmdline_parse_token_string_t cmd_config_thresh_all =
3270 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3271 static cmdline_parse_token_string_t cmd_config_thresh_name =
3272 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3273 				"txpt#txht#txwt#rxpt#rxht#rxwt");
3274 static cmdline_parse_token_num_t cmd_config_thresh_value =
3275 	TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3276 
3277 static cmdline_parse_inst_t cmd_config_thresh = {
3278 	.f = cmd_config_thresh_parsed,
3279 	.data = NULL,
3280 	.help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3281 	.tokens = {
3282 		(void *)&cmd_config_thresh_port,
3283 		(void *)&cmd_config_thresh_keyword,
3284 		(void *)&cmd_config_thresh_all,
3285 		(void *)&cmd_config_thresh_name,
3286 		(void *)&cmd_config_thresh_value,
3287 		NULL,
3288 	},
3289 };
3290 
3291 /* *** configure free/rs threshold *** */
3292 struct cmd_config_threshold {
3293 	cmdline_fixed_string_t port;
3294 	cmdline_fixed_string_t keyword;
3295 	cmdline_fixed_string_t all;
3296 	cmdline_fixed_string_t name;
3297 	uint16_t value;
3298 };
3299 
3300 static void
3301 cmd_config_threshold_parsed(void *parsed_result,
3302 			__rte_unused struct cmdline *cl,
3303 			__rte_unused void *data)
3304 {
3305 	struct cmd_config_threshold *res = parsed_result;
3306 
3307 	if (!all_ports_stopped()) {
3308 		fprintf(stderr, "Please stop all ports first\n");
3309 		return;
3310 	}
3311 
3312 	if (!strcmp(res->name, "txfreet"))
3313 		tx_free_thresh = res->value;
3314 	else if (!strcmp(res->name, "txrst"))
3315 		tx_rs_thresh = res->value;
3316 	else if (!strcmp(res->name, "rxfreet"))
3317 		rx_free_thresh = res->value;
3318 	else {
3319 		fprintf(stderr, "Unknown parameter\n");
3320 		return;
3321 	}
3322 
3323 	init_port_config();
3324 
3325 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3326 }
3327 
3328 static cmdline_parse_token_string_t cmd_config_threshold_port =
3329 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3330 static cmdline_parse_token_string_t cmd_config_threshold_keyword =
3331 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3332 								"config");
3333 static cmdline_parse_token_string_t cmd_config_threshold_all =
3334 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3335 static cmdline_parse_token_string_t cmd_config_threshold_name =
3336 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3337 						"txfreet#txrst#rxfreet");
3338 static cmdline_parse_token_num_t cmd_config_threshold_value =
3339 	TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3340 
3341 static cmdline_parse_inst_t cmd_config_threshold = {
3342 	.f = cmd_config_threshold_parsed,
3343 	.data = NULL,
3344 	.help_str = "port config all txfreet|txrst|rxfreet <value>",
3345 	.tokens = {
3346 		(void *)&cmd_config_threshold_port,
3347 		(void *)&cmd_config_threshold_keyword,
3348 		(void *)&cmd_config_threshold_all,
3349 		(void *)&cmd_config_threshold_name,
3350 		(void *)&cmd_config_threshold_value,
3351 		NULL,
3352 	},
3353 };
3354 
3355 /* *** stop *** */
3356 struct cmd_stop_result {
3357 	cmdline_fixed_string_t stop;
3358 };
3359 
3360 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3361 			    __rte_unused struct cmdline *cl,
3362 			    __rte_unused void *data)
3363 {
3364 	stop_packet_forwarding();
3365 }
3366 
3367 static cmdline_parse_token_string_t cmd_stop_stop =
3368 	TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3369 
3370 static cmdline_parse_inst_t cmd_stop = {
3371 	.f = cmd_stop_parsed,
3372 	.data = NULL,
3373 	.help_str = "stop: Stop packet forwarding",
3374 	.tokens = {
3375 		(void *)&cmd_stop_stop,
3376 		NULL,
3377 	},
3378 };
3379 
3380 static unsigned int
3381 get_ptype(char *value)
3382 {
3383 	uint32_t protocol;
3384 
3385 	if (!strcmp(value, "eth"))
3386 		protocol = RTE_PTYPE_L2_ETHER;
3387 	else if (!strcmp(value, "ipv4"))
3388 		protocol = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
3389 	else if (!strcmp(value, "ipv6"))
3390 		protocol = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
3391 	else if (!strcmp(value, "ipv4-tcp"))
3392 		protocol = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_TCP;
3393 	else if (!strcmp(value, "ipv4-udp"))
3394 		protocol = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP;
3395 	else if (!strcmp(value, "ipv4-sctp"))
3396 		protocol = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_SCTP;
3397 	else if (!strcmp(value, "ipv6-tcp"))
3398 		protocol = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_TCP;
3399 	else if (!strcmp(value, "ipv6-udp"))
3400 		protocol = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_UDP;
3401 	else if (!strcmp(value, "ipv6-sctp"))
3402 		protocol = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_SCTP;
3403 	else if (!strcmp(value, "grenat"))
3404 		protocol = RTE_PTYPE_TUNNEL_GRENAT;
3405 	else if (!strcmp(value, "inner-eth"))
3406 		protocol = RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER;
3407 	else if (!strcmp(value, "inner-ipv4"))
3408 		protocol = RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3409 				RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
3410 	else if (!strcmp(value, "inner-ipv6"))
3411 		protocol = RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3412 				RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
3413 	else if (!strcmp(value, "inner-ipv4-tcp"))
3414 		protocol = RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3415 				RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_TCP;
3416 	else if (!strcmp(value, "inner-ipv4-udp"))
3417 		protocol = RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3418 				RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_UDP;
3419 	else if (!strcmp(value, "inner-ipv4-sctp"))
3420 		protocol = RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3421 				RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_SCTP;
3422 	else if (!strcmp(value, "inner-ipv6-tcp"))
3423 		protocol = RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3424 				RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_TCP;
3425 	else if (!strcmp(value, "inner-ipv6-udp"))
3426 		protocol = RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3427 				RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_UDP;
3428 	else if (!strcmp(value, "inner-ipv6-sctp"))
3429 		protocol = RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3430 				RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_SCTP;
3431 	else {
3432 		fprintf(stderr, "Unsupported protocol: %s\n", value);
3433 		protocol = RTE_PTYPE_UNKNOWN;
3434 	}
3435 
3436 	return protocol;
3437 }
3438 
3439 /* *** SET RXHDRSLIST *** */
3440 
3441 unsigned int
3442 parse_hdrs_list(const char *str, const char *item_name, unsigned int max_items,
3443 				unsigned int *parsed_items)
3444 {
3445 	unsigned int nb_item;
3446 	char *cur;
3447 	char *tmp;
3448 	unsigned int cur_item, prev_items = 0;
3449 
3450 	nb_item = 0;
3451 	char *str2 = strdup(str);
3452 	cur = strtok_r(str2, ",", &tmp);
3453 	while (cur != NULL) {
3454 		cur_item = get_ptype(cur);
3455 		cur_item &= ~prev_items;
3456 		parsed_items[nb_item] = cur_item;
3457 		cur = strtok_r(NULL, ",", &tmp);
3458 		nb_item++;
3459 		prev_items |= cur_item;
3460 	}
3461 	if (nb_item > max_items)
3462 		fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3463 			item_name, nb_item + 1, max_items);
3464 	free(str2);
3465 	return nb_item;
3466 }
3467 
3468 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3469 
3470 unsigned int
3471 parse_item_list(const char *str, const char *item_name, unsigned int max_items,
3472 		unsigned int *parsed_items, int check_unique_values)
3473 {
3474 	unsigned int nb_item;
3475 	unsigned int value;
3476 	unsigned int i;
3477 	unsigned int j;
3478 	int value_ok;
3479 	char c;
3480 
3481 	/*
3482 	 * First parse all items in the list and store their value.
3483 	 */
3484 	value = 0;
3485 	nb_item = 0;
3486 	value_ok = 0;
3487 	for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3488 		c = str[i];
3489 		if ((c >= '0') && (c <= '9')) {
3490 			value = (unsigned int) (value * 10 + (c - '0'));
3491 			value_ok = 1;
3492 			continue;
3493 		}
3494 		if (c != ',') {
3495 			fprintf(stderr, "character %c is not a decimal digit\n", c);
3496 			return 0;
3497 		}
3498 		if (! value_ok) {
3499 			fprintf(stderr, "No valid value before comma\n");
3500 			return 0;
3501 		}
3502 		if (nb_item < max_items) {
3503 			parsed_items[nb_item] = value;
3504 			value_ok = 0;
3505 			value = 0;
3506 		}
3507 		nb_item++;
3508 	}
3509 	if (nb_item >= max_items) {
3510 		fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3511 			item_name, nb_item + 1, max_items);
3512 		return 0;
3513 	}
3514 	parsed_items[nb_item++] = value;
3515 	if (! check_unique_values)
3516 		return nb_item;
3517 
3518 	/*
3519 	 * Then, check that all values in the list are different.
3520 	 * No optimization here...
3521 	 */
3522 	for (i = 0; i < nb_item; i++) {
3523 		for (j = i + 1; j < nb_item; j++) {
3524 			if (parsed_items[j] == parsed_items[i]) {
3525 				fprintf(stderr,
3526 					"duplicated %s %u at index %u and %u\n",
3527 					item_name, parsed_items[i], i, j);
3528 				return 0;
3529 			}
3530 		}
3531 	}
3532 	return nb_item;
3533 }
3534 
3535 struct cmd_set_list_result {
3536 	cmdline_fixed_string_t cmd_keyword;
3537 	cmdline_fixed_string_t list_name;
3538 	cmdline_fixed_string_t list_of_items;
3539 };
3540 
3541 static void cmd_set_list_parsed(void *parsed_result,
3542 				__rte_unused struct cmdline *cl,
3543 				__rte_unused void *data)
3544 {
3545 	struct cmd_set_list_result *res;
3546 	union {
3547 		unsigned int lcorelist[RTE_MAX_LCORE];
3548 		unsigned int portlist[RTE_MAX_ETHPORTS];
3549 	} parsed_items;
3550 	unsigned int nb_item;
3551 
3552 	if (test_done == 0) {
3553 		fprintf(stderr, "Please stop forwarding first\n");
3554 		return;
3555 	}
3556 
3557 	res = parsed_result;
3558 	if (!strcmp(res->list_name, "corelist")) {
3559 		nb_item = parse_item_list(res->list_of_items, "core",
3560 					  RTE_MAX_LCORE,
3561 					  parsed_items.lcorelist, 1);
3562 		if (nb_item > 0) {
3563 			set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3564 			fwd_config_setup();
3565 		}
3566 		return;
3567 	}
3568 	if (!strcmp(res->list_name, "portlist")) {
3569 		nb_item = parse_item_list(res->list_of_items, "port",
3570 					  RTE_MAX_ETHPORTS,
3571 					  parsed_items.portlist, 1);
3572 		if (nb_item > 0) {
3573 			set_fwd_ports_list(parsed_items.portlist, nb_item);
3574 			fwd_config_setup();
3575 		}
3576 	}
3577 }
3578 
3579 static cmdline_parse_token_string_t cmd_set_list_keyword =
3580 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3581 				 "set");
3582 static cmdline_parse_token_string_t cmd_set_list_name =
3583 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3584 				 "corelist#portlist");
3585 static cmdline_parse_token_string_t cmd_set_list_of_items =
3586 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3587 				 NULL);
3588 
3589 static cmdline_parse_inst_t cmd_set_fwd_list = {
3590 	.f = cmd_set_list_parsed,
3591 	.data = NULL,
3592 	.help_str = "set corelist|portlist <list0[,list1]*>",
3593 	.tokens = {
3594 		(void *)&cmd_set_list_keyword,
3595 		(void *)&cmd_set_list_name,
3596 		(void *)&cmd_set_list_of_items,
3597 		NULL,
3598 	},
3599 };
3600 
3601 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3602 
3603 struct cmd_setmask_result {
3604 	cmdline_fixed_string_t set;
3605 	cmdline_fixed_string_t mask;
3606 	uint64_t hexavalue;
3607 };
3608 
3609 static void cmd_set_mask_parsed(void *parsed_result,
3610 				__rte_unused struct cmdline *cl,
3611 				__rte_unused void *data)
3612 {
3613 	struct cmd_setmask_result *res = parsed_result;
3614 
3615 	if (test_done == 0) {
3616 		fprintf(stderr, "Please stop forwarding first\n");
3617 		return;
3618 	}
3619 	if (!strcmp(res->mask, "coremask")) {
3620 		set_fwd_lcores_mask(res->hexavalue);
3621 		fwd_config_setup();
3622 	} else if (!strcmp(res->mask, "portmask")) {
3623 		set_fwd_ports_mask(res->hexavalue);
3624 		fwd_config_setup();
3625 	}
3626 }
3627 
3628 static cmdline_parse_token_string_t cmd_setmask_set =
3629 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3630 static cmdline_parse_token_string_t cmd_setmask_mask =
3631 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3632 				 "coremask#portmask");
3633 static cmdline_parse_token_num_t cmd_setmask_value =
3634 	TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3635 
3636 static cmdline_parse_inst_t cmd_set_fwd_mask = {
3637 	.f = cmd_set_mask_parsed,
3638 	.data = NULL,
3639 	.help_str = "set coremask|portmask <hexadecimal value>",
3640 	.tokens = {
3641 		(void *)&cmd_setmask_set,
3642 		(void *)&cmd_setmask_mask,
3643 		(void *)&cmd_setmask_value,
3644 		NULL,
3645 	},
3646 };
3647 
3648 /*
3649  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3650  */
3651 struct cmd_set_result {
3652 	cmdline_fixed_string_t set;
3653 	cmdline_fixed_string_t what;
3654 	uint16_t value;
3655 };
3656 
3657 static void cmd_set_parsed(void *parsed_result,
3658 			   __rte_unused struct cmdline *cl,
3659 			   __rte_unused void *data)
3660 {
3661 	struct cmd_set_result *res = parsed_result;
3662 	if (!strcmp(res->what, "nbport")) {
3663 		set_fwd_ports_number(res->value);
3664 		fwd_config_setup();
3665 	} else if (!strcmp(res->what, "nbcore")) {
3666 		set_fwd_lcores_number(res->value);
3667 		fwd_config_setup();
3668 	} else if (!strcmp(res->what, "burst"))
3669 		set_nb_pkt_per_burst(res->value);
3670 	else if (!strcmp(res->what, "verbose"))
3671 		set_verbose_level(res->value);
3672 }
3673 
3674 static cmdline_parse_token_string_t cmd_set_set =
3675 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3676 static cmdline_parse_token_string_t cmd_set_what =
3677 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3678 				 "nbport#nbcore#burst#verbose");
3679 static cmdline_parse_token_num_t cmd_set_value =
3680 	TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3681 
3682 static cmdline_parse_inst_t cmd_set_numbers = {
3683 	.f = cmd_set_parsed,
3684 	.data = NULL,
3685 	.help_str = "set nbport|nbcore|burst|verbose <value>",
3686 	.tokens = {
3687 		(void *)&cmd_set_set,
3688 		(void *)&cmd_set_what,
3689 		(void *)&cmd_set_value,
3690 		NULL,
3691 	},
3692 };
3693 
3694 /* *** SET LOG LEVEL CONFIGURATION *** */
3695 
3696 struct cmd_set_log_result {
3697 	cmdline_fixed_string_t set;
3698 	cmdline_fixed_string_t log;
3699 	cmdline_fixed_string_t type;
3700 	uint32_t level;
3701 };
3702 
3703 static void
3704 cmd_set_log_parsed(void *parsed_result,
3705 		   __rte_unused struct cmdline *cl,
3706 		   __rte_unused void *data)
3707 {
3708 	struct cmd_set_log_result *res;
3709 	int ret;
3710 
3711 	res = parsed_result;
3712 	if (!strcmp(res->type, "global"))
3713 		rte_log_set_global_level(res->level);
3714 	else {
3715 		ret = rte_log_set_level_regexp(res->type, res->level);
3716 		if (ret < 0)
3717 			fprintf(stderr, "Unable to set log level\n");
3718 	}
3719 }
3720 
3721 static cmdline_parse_token_string_t cmd_set_log_set =
3722 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3723 static cmdline_parse_token_string_t cmd_set_log_log =
3724 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3725 static cmdline_parse_token_string_t cmd_set_log_type =
3726 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3727 static cmdline_parse_token_num_t cmd_set_log_level =
3728 	TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3729 
3730 static cmdline_parse_inst_t cmd_set_log = {
3731 	.f = cmd_set_log_parsed,
3732 	.data = NULL,
3733 	.help_str = "set log global|<type> <level>",
3734 	.tokens = {
3735 		(void *)&cmd_set_log_set,
3736 		(void *)&cmd_set_log_log,
3737 		(void *)&cmd_set_log_type,
3738 		(void *)&cmd_set_log_level,
3739 		NULL,
3740 	},
3741 };
3742 
3743 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3744 
3745 struct cmd_set_rxoffs_result {
3746 	cmdline_fixed_string_t cmd_keyword;
3747 	cmdline_fixed_string_t rxoffs;
3748 	cmdline_fixed_string_t seg_offsets;
3749 };
3750 
3751 static void
3752 cmd_set_rxoffs_parsed(void *parsed_result,
3753 		      __rte_unused struct cmdline *cl,
3754 		      __rte_unused void *data)
3755 {
3756 	struct cmd_set_rxoffs_result *res;
3757 	unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3758 	unsigned int nb_segs;
3759 
3760 	res = parsed_result;
3761 	nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3762 				  MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3763 	if (nb_segs > 0)
3764 		set_rx_pkt_offsets(seg_offsets, nb_segs);
3765 	cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3766 }
3767 
3768 static cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3769 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3770 				 cmd_keyword, "set");
3771 static cmdline_parse_token_string_t cmd_set_rxoffs_name =
3772 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3773 				 rxoffs, "rxoffs");
3774 static cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3775 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3776 				 seg_offsets, NULL);
3777 
3778 static cmdline_parse_inst_t cmd_set_rxoffs = {
3779 	.f = cmd_set_rxoffs_parsed,
3780 	.data = NULL,
3781 	.help_str = "set rxoffs <len0[,len1]*>",
3782 	.tokens = {
3783 		(void *)&cmd_set_rxoffs_keyword,
3784 		(void *)&cmd_set_rxoffs_name,
3785 		(void *)&cmd_set_rxoffs_offsets,
3786 		NULL,
3787 	},
3788 };
3789 
3790 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3791 
3792 struct cmd_set_rxpkts_result {
3793 	cmdline_fixed_string_t cmd_keyword;
3794 	cmdline_fixed_string_t rxpkts;
3795 	cmdline_fixed_string_t seg_lengths;
3796 };
3797 
3798 static void
3799 cmd_set_rxpkts_parsed(void *parsed_result,
3800 		      __rte_unused struct cmdline *cl,
3801 		      __rte_unused void *data)
3802 {
3803 	struct cmd_set_rxpkts_result *res;
3804 	unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3805 	unsigned int nb_segs;
3806 
3807 	res = parsed_result;
3808 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3809 				  MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3810 	if (nb_segs > 0)
3811 		set_rx_pkt_segments(seg_lengths, nb_segs);
3812 	cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3813 }
3814 
3815 static cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3816 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3817 				 cmd_keyword, "set");
3818 static cmdline_parse_token_string_t cmd_set_rxpkts_name =
3819 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3820 				 rxpkts, "rxpkts");
3821 static cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3822 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3823 				 seg_lengths, NULL);
3824 
3825 static cmdline_parse_inst_t cmd_set_rxpkts = {
3826 	.f = cmd_set_rxpkts_parsed,
3827 	.data = NULL,
3828 	.help_str = "set rxpkts <len0[,len1]*>",
3829 	.tokens = {
3830 		(void *)&cmd_set_rxpkts_keyword,
3831 		(void *)&cmd_set_rxpkts_name,
3832 		(void *)&cmd_set_rxpkts_lengths,
3833 		NULL,
3834 	},
3835 };
3836 
3837 /* *** SET SEGMENT HEADERS OF RX PACKETS SPLIT *** */
3838 struct cmd_set_rxhdrs_result {
3839 	cmdline_fixed_string_t set;
3840 	cmdline_fixed_string_t rxhdrs;
3841 	cmdline_fixed_string_t values;
3842 };
3843 
3844 static void
3845 cmd_set_rxhdrs_parsed(void *parsed_result,
3846 		      __rte_unused struct cmdline *cl,
3847 		      __rte_unused void *data)
3848 {
3849 	struct cmd_set_rxhdrs_result *res;
3850 	unsigned int seg_hdrs[MAX_SEGS_BUFFER_SPLIT];
3851 	unsigned int nb_segs;
3852 
3853 	res = parsed_result;
3854 	nb_segs = parse_hdrs_list(res->values, "segment hdrs",
3855 				  MAX_SEGS_BUFFER_SPLIT, seg_hdrs);
3856 	if (nb_segs > 0)
3857 		set_rx_pkt_hdrs(seg_hdrs, nb_segs);
3858 	cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3859 }
3860 
3861 static cmdline_parse_token_string_t cmd_set_rxhdrs_set =
3862 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxhdrs_result,
3863 				set, "set");
3864 static cmdline_parse_token_string_t cmd_set_rxhdrs_rxhdrs =
3865 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxhdrs_result,
3866 				rxhdrs, "rxhdrs");
3867 static cmdline_parse_token_string_t cmd_set_rxhdrs_values =
3868 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxhdrs_result,
3869 				values, NULL);
3870 
3871 static cmdline_parse_inst_t cmd_set_rxhdrs = {
3872 	.f = cmd_set_rxhdrs_parsed,
3873 	.data = NULL,
3874 	.help_str = "set rxhdrs <eth[,ipv4]*>",
3875 	.tokens = {
3876 		(void *)&cmd_set_rxhdrs_set,
3877 		(void *)&cmd_set_rxhdrs_rxhdrs,
3878 		(void *)&cmd_set_rxhdrs_values,
3879 		NULL,
3880 	},
3881 };
3882 
3883 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3884 
3885 struct cmd_set_txpkts_result {
3886 	cmdline_fixed_string_t cmd_keyword;
3887 	cmdline_fixed_string_t txpkts;
3888 	cmdline_fixed_string_t seg_lengths;
3889 };
3890 
3891 static void
3892 cmd_set_txpkts_parsed(void *parsed_result,
3893 		      __rte_unused struct cmdline *cl,
3894 		      __rte_unused void *data)
3895 {
3896 	struct cmd_set_txpkts_result *res;
3897 	unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3898 	unsigned int nb_segs;
3899 
3900 	res = parsed_result;
3901 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3902 				  RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3903 	if (nb_segs > 0)
3904 		set_tx_pkt_segments(seg_lengths, nb_segs);
3905 }
3906 
3907 static cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3908 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3909 				 cmd_keyword, "set");
3910 static cmdline_parse_token_string_t cmd_set_txpkts_name =
3911 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3912 				 txpkts, "txpkts");
3913 static cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3914 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3915 				 seg_lengths, NULL);
3916 
3917 static cmdline_parse_inst_t cmd_set_txpkts = {
3918 	.f = cmd_set_txpkts_parsed,
3919 	.data = NULL,
3920 	.help_str = "set txpkts <len0[,len1]*>",
3921 	.tokens = {
3922 		(void *)&cmd_set_txpkts_keyword,
3923 		(void *)&cmd_set_txpkts_name,
3924 		(void *)&cmd_set_txpkts_lengths,
3925 		NULL,
3926 	},
3927 };
3928 
3929 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3930 
3931 struct cmd_set_txsplit_result {
3932 	cmdline_fixed_string_t cmd_keyword;
3933 	cmdline_fixed_string_t txsplit;
3934 	cmdline_fixed_string_t mode;
3935 };
3936 
3937 static void
3938 cmd_set_txsplit_parsed(void *parsed_result,
3939 		      __rte_unused struct cmdline *cl,
3940 		      __rte_unused void *data)
3941 {
3942 	struct cmd_set_txsplit_result *res;
3943 
3944 	res = parsed_result;
3945 	set_tx_pkt_split(res->mode);
3946 }
3947 
3948 static cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3949 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3950 				 cmd_keyword, "set");
3951 static cmdline_parse_token_string_t cmd_set_txsplit_name =
3952 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3953 				 txsplit, "txsplit");
3954 static cmdline_parse_token_string_t cmd_set_txsplit_mode =
3955 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3956 				 mode, NULL);
3957 
3958 static cmdline_parse_inst_t cmd_set_txsplit = {
3959 	.f = cmd_set_txsplit_parsed,
3960 	.data = NULL,
3961 	.help_str = "set txsplit on|off|rand",
3962 	.tokens = {
3963 		(void *)&cmd_set_txsplit_keyword,
3964 		(void *)&cmd_set_txsplit_name,
3965 		(void *)&cmd_set_txsplit_mode,
3966 		NULL,
3967 	},
3968 };
3969 
3970 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3971 
3972 struct cmd_set_txtimes_result {
3973 	cmdline_fixed_string_t cmd_keyword;
3974 	cmdline_fixed_string_t txtimes;
3975 	cmdline_fixed_string_t tx_times;
3976 };
3977 
3978 static void
3979 cmd_set_txtimes_parsed(void *parsed_result,
3980 		       __rte_unused struct cmdline *cl,
3981 		       __rte_unused void *data)
3982 {
3983 	struct cmd_set_txtimes_result *res;
3984 	unsigned int tx_times[2] = {0, 0};
3985 	unsigned int n_times;
3986 
3987 	res = parsed_result;
3988 	n_times = parse_item_list(res->tx_times, "tx times",
3989 				  2, tx_times, 0);
3990 	if (n_times == 2)
3991 		set_tx_pkt_times(tx_times);
3992 }
3993 
3994 static cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3995 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3996 				 cmd_keyword, "set");
3997 static cmdline_parse_token_string_t cmd_set_txtimes_name =
3998 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3999 				 txtimes, "txtimes");
4000 static cmdline_parse_token_string_t cmd_set_txtimes_value =
4001 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4002 				 tx_times, NULL);
4003 
4004 static cmdline_parse_inst_t cmd_set_txtimes = {
4005 	.f = cmd_set_txtimes_parsed,
4006 	.data = NULL,
4007 	.help_str = "set txtimes <inter_burst>,<intra_burst>",
4008 	.tokens = {
4009 		(void *)&cmd_set_txtimes_keyword,
4010 		(void *)&cmd_set_txtimes_name,
4011 		(void *)&cmd_set_txtimes_value,
4012 		NULL,
4013 	},
4014 };
4015 
4016 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4017 struct cmd_rx_vlan_filter_all_result {
4018 	cmdline_fixed_string_t rx_vlan;
4019 	cmdline_fixed_string_t what;
4020 	cmdline_fixed_string_t all;
4021 	portid_t port_id;
4022 };
4023 
4024 static void
4025 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4026 			      __rte_unused struct cmdline *cl,
4027 			      __rte_unused void *data)
4028 {
4029 	struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4030 
4031 	if (!strcmp(res->what, "add"))
4032 		rx_vlan_all_filter_set(res->port_id, 1);
4033 	else
4034 		rx_vlan_all_filter_set(res->port_id, 0);
4035 }
4036 
4037 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4038 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4039 				 rx_vlan, "rx_vlan");
4040 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4041 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4042 				 what, "add#rm");
4043 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4044 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4045 				 all, "all");
4046 static cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4047 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4048 			      port_id, RTE_UINT16);
4049 
4050 static cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4051 	.f = cmd_rx_vlan_filter_all_parsed,
4052 	.data = NULL,
4053 	.help_str = "rx_vlan add|rm all <port_id>: "
4054 		"Add/Remove all identifiers to/from the set of VLAN "
4055 		"identifiers filtered by a port",
4056 	.tokens = {
4057 		(void *)&cmd_rx_vlan_filter_all_rx_vlan,
4058 		(void *)&cmd_rx_vlan_filter_all_what,
4059 		(void *)&cmd_rx_vlan_filter_all_all,
4060 		(void *)&cmd_rx_vlan_filter_all_portid,
4061 		NULL,
4062 	},
4063 };
4064 
4065 /* *** VLAN OFFLOAD SET ON A PORT *** */
4066 struct cmd_vlan_offload_result {
4067 	cmdline_fixed_string_t vlan;
4068 	cmdline_fixed_string_t set;
4069 	cmdline_fixed_string_t vlan_type;
4070 	cmdline_fixed_string_t what;
4071 	cmdline_fixed_string_t on;
4072 	cmdline_fixed_string_t port_id;
4073 };
4074 
4075 static void
4076 cmd_vlan_offload_parsed(void *parsed_result,
4077 			  __rte_unused struct cmdline *cl,
4078 			  __rte_unused void *data)
4079 {
4080 	int on;
4081 	struct cmd_vlan_offload_result *res = parsed_result;
4082 	char *str;
4083 	int i, len = 0;
4084 	portid_t port_id = 0;
4085 	unsigned int tmp;
4086 
4087 	str = res->port_id;
4088 	len = strnlen(str, STR_TOKEN_SIZE);
4089 	i = 0;
4090 	/* Get port_id first */
4091 	while(i < len){
4092 		if(str[i] == ',')
4093 			break;
4094 
4095 		i++;
4096 	}
4097 	str[i]='\0';
4098 	tmp = strtoul(str, NULL, 0);
4099 	/* If port_id greater that what portid_t can represent, return */
4100 	if(tmp >= RTE_MAX_ETHPORTS)
4101 		return;
4102 	port_id = (portid_t)tmp;
4103 
4104 	if (!strcmp(res->on, "on"))
4105 		on = 1;
4106 	else
4107 		on = 0;
4108 
4109 	if (!strcmp(res->what, "strip"))
4110 		rx_vlan_strip_set(port_id,  on);
4111 	else if(!strcmp(res->what, "stripq")){
4112 		uint16_t queue_id = 0;
4113 
4114 		/* No queue_id, return */
4115 		if(i + 1 >= len) {
4116 			fprintf(stderr, "must specify (port,queue_id)\n");
4117 			return;
4118 		}
4119 		tmp = strtoul(str + i + 1, NULL, 0);
4120 		/* If queue_id greater that what 16-bits can represent, return */
4121 		if(tmp > 0xffff)
4122 			return;
4123 
4124 		queue_id = (uint16_t)tmp;
4125 		rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4126 	}
4127 	else if (!strcmp(res->what, "filter"))
4128 		rx_vlan_filter_set(port_id, on);
4129 	else if (!strcmp(res->what, "qinq_strip"))
4130 		rx_vlan_qinq_strip_set(port_id, on);
4131 	else
4132 		vlan_extend_set(port_id, on);
4133 
4134 	return;
4135 }
4136 
4137 static cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4138 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4139 				 vlan, "vlan");
4140 static cmdline_parse_token_string_t cmd_vlan_offload_set =
4141 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4142 				 set, "set");
4143 static cmdline_parse_token_string_t cmd_vlan_offload_what =
4144 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4145 				what, "strip#filter#qinq_strip#extend#stripq");
4146 static cmdline_parse_token_string_t cmd_vlan_offload_on =
4147 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4148 			      on, "on#off");
4149 static cmdline_parse_token_string_t cmd_vlan_offload_portid =
4150 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4151 			      port_id, NULL);
4152 
4153 static cmdline_parse_inst_t cmd_vlan_offload = {
4154 	.f = cmd_vlan_offload_parsed,
4155 	.data = NULL,
4156 	.help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4157 		"<port_id[,queue_id]>: "
4158 		"Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4159 	.tokens = {
4160 		(void *)&cmd_vlan_offload_vlan,
4161 		(void *)&cmd_vlan_offload_set,
4162 		(void *)&cmd_vlan_offload_what,
4163 		(void *)&cmd_vlan_offload_on,
4164 		(void *)&cmd_vlan_offload_portid,
4165 		NULL,
4166 	},
4167 };
4168 
4169 /* *** VLAN TPID SET ON A PORT *** */
4170 struct cmd_vlan_tpid_result {
4171 	cmdline_fixed_string_t vlan;
4172 	cmdline_fixed_string_t set;
4173 	cmdline_fixed_string_t vlan_type;
4174 	cmdline_fixed_string_t what;
4175 	uint16_t tp_id;
4176 	portid_t port_id;
4177 };
4178 
4179 static void
4180 cmd_vlan_tpid_parsed(void *parsed_result,
4181 			  __rte_unused struct cmdline *cl,
4182 			  __rte_unused void *data)
4183 {
4184 	struct cmd_vlan_tpid_result *res = parsed_result;
4185 	enum rte_vlan_type vlan_type;
4186 
4187 	if (!strcmp(res->vlan_type, "inner"))
4188 		vlan_type = RTE_ETH_VLAN_TYPE_INNER;
4189 	else if (!strcmp(res->vlan_type, "outer"))
4190 		vlan_type = RTE_ETH_VLAN_TYPE_OUTER;
4191 	else {
4192 		fprintf(stderr, "Unknown vlan type\n");
4193 		return;
4194 	}
4195 	vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4196 }
4197 
4198 static cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4199 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4200 				 vlan, "vlan");
4201 static cmdline_parse_token_string_t cmd_vlan_tpid_set =
4202 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4203 				 set, "set");
4204 static cmdline_parse_token_string_t cmd_vlan_type =
4205 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4206 				 vlan_type, "inner#outer");
4207 static cmdline_parse_token_string_t cmd_vlan_tpid_what =
4208 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4209 				 what, "tpid");
4210 static cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4211 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4212 			      tp_id, RTE_UINT16);
4213 static cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4214 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4215 			      port_id, RTE_UINT16);
4216 
4217 static cmdline_parse_inst_t cmd_vlan_tpid = {
4218 	.f = cmd_vlan_tpid_parsed,
4219 	.data = NULL,
4220 	.help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4221 		"Set the VLAN Ether type",
4222 	.tokens = {
4223 		(void *)&cmd_vlan_tpid_vlan,
4224 		(void *)&cmd_vlan_tpid_set,
4225 		(void *)&cmd_vlan_type,
4226 		(void *)&cmd_vlan_tpid_what,
4227 		(void *)&cmd_vlan_tpid_tpid,
4228 		(void *)&cmd_vlan_tpid_portid,
4229 		NULL,
4230 	},
4231 };
4232 
4233 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4234 struct cmd_rx_vlan_filter_result {
4235 	cmdline_fixed_string_t rx_vlan;
4236 	cmdline_fixed_string_t what;
4237 	uint16_t vlan_id;
4238 	portid_t port_id;
4239 };
4240 
4241 static void
4242 cmd_rx_vlan_filter_parsed(void *parsed_result,
4243 			  __rte_unused struct cmdline *cl,
4244 			  __rte_unused void *data)
4245 {
4246 	struct cmd_rx_vlan_filter_result *res = parsed_result;
4247 
4248 	if (!strcmp(res->what, "add"))
4249 		rx_vft_set(res->port_id, res->vlan_id, 1);
4250 	else
4251 		rx_vft_set(res->port_id, res->vlan_id, 0);
4252 }
4253 
4254 static cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4255 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4256 				 rx_vlan, "rx_vlan");
4257 static cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4258 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4259 				 what, "add#rm");
4260 static cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4261 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4262 			      vlan_id, RTE_UINT16);
4263 static cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4264 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4265 			      port_id, RTE_UINT16);
4266 
4267 static cmdline_parse_inst_t cmd_rx_vlan_filter = {
4268 	.f = cmd_rx_vlan_filter_parsed,
4269 	.data = NULL,
4270 	.help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4271 		"Add/Remove a VLAN identifier to/from the set of VLAN "
4272 		"identifiers filtered by a port",
4273 	.tokens = {
4274 		(void *)&cmd_rx_vlan_filter_rx_vlan,
4275 		(void *)&cmd_rx_vlan_filter_what,
4276 		(void *)&cmd_rx_vlan_filter_vlanid,
4277 		(void *)&cmd_rx_vlan_filter_portid,
4278 		NULL,
4279 	},
4280 };
4281 
4282 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4283 struct cmd_tx_vlan_set_result {
4284 	cmdline_fixed_string_t tx_vlan;
4285 	cmdline_fixed_string_t set;
4286 	portid_t port_id;
4287 	uint16_t vlan_id;
4288 };
4289 
4290 static void
4291 cmd_tx_vlan_set_parsed(void *parsed_result,
4292 		       __rte_unused struct cmdline *cl,
4293 		       __rte_unused void *data)
4294 {
4295 	struct cmd_tx_vlan_set_result *res = parsed_result;
4296 
4297 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4298 		return;
4299 
4300 	if (!port_is_stopped(res->port_id)) {
4301 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4302 		return;
4303 	}
4304 
4305 	tx_vlan_set(res->port_id, res->vlan_id);
4306 
4307 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4308 }
4309 
4310 static cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4311 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4312 				 tx_vlan, "tx_vlan");
4313 static cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4314 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4315 				 set, "set");
4316 static cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4317 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4318 			      port_id, RTE_UINT16);
4319 static cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4320 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4321 			      vlan_id, RTE_UINT16);
4322 
4323 static cmdline_parse_inst_t cmd_tx_vlan_set = {
4324 	.f = cmd_tx_vlan_set_parsed,
4325 	.data = NULL,
4326 	.help_str = "tx_vlan set <port_id> <vlan_id>: "
4327 		"Enable hardware insertion of a single VLAN header "
4328 		"with a given TAG Identifier in packets sent on a port",
4329 	.tokens = {
4330 		(void *)&cmd_tx_vlan_set_tx_vlan,
4331 		(void *)&cmd_tx_vlan_set_set,
4332 		(void *)&cmd_tx_vlan_set_portid,
4333 		(void *)&cmd_tx_vlan_set_vlanid,
4334 		NULL,
4335 	},
4336 };
4337 
4338 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4339 struct cmd_tx_vlan_set_qinq_result {
4340 	cmdline_fixed_string_t tx_vlan;
4341 	cmdline_fixed_string_t set;
4342 	portid_t port_id;
4343 	uint16_t vlan_id;
4344 	uint16_t vlan_id_outer;
4345 };
4346 
4347 static void
4348 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4349 			    __rte_unused struct cmdline *cl,
4350 			    __rte_unused void *data)
4351 {
4352 	struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4353 
4354 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4355 		return;
4356 
4357 	if (!port_is_stopped(res->port_id)) {
4358 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4359 		return;
4360 	}
4361 
4362 	tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4363 
4364 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4365 }
4366 
4367 static cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4368 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4369 		tx_vlan, "tx_vlan");
4370 static cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4371 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4372 		set, "set");
4373 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4374 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4375 		port_id, RTE_UINT16);
4376 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4377 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4378 		vlan_id, RTE_UINT16);
4379 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4380 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4381 		vlan_id_outer, RTE_UINT16);
4382 
4383 static cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4384 	.f = cmd_tx_vlan_set_qinq_parsed,
4385 	.data = NULL,
4386 	.help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4387 		"Enable hardware insertion of double VLAN header "
4388 		"with given TAG Identifiers in packets sent on a port",
4389 	.tokens = {
4390 		(void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4391 		(void *)&cmd_tx_vlan_set_qinq_set,
4392 		(void *)&cmd_tx_vlan_set_qinq_portid,
4393 		(void *)&cmd_tx_vlan_set_qinq_vlanid,
4394 		(void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4395 		NULL,
4396 	},
4397 };
4398 
4399 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4400 struct cmd_tx_vlan_set_pvid_result {
4401 	cmdline_fixed_string_t tx_vlan;
4402 	cmdline_fixed_string_t set;
4403 	cmdline_fixed_string_t pvid;
4404 	portid_t port_id;
4405 	uint16_t vlan_id;
4406 	cmdline_fixed_string_t mode;
4407 };
4408 
4409 static void
4410 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4411 			    __rte_unused struct cmdline *cl,
4412 			    __rte_unused void *data)
4413 {
4414 	struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4415 
4416 	if (strcmp(res->mode, "on") == 0)
4417 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4418 	else
4419 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4420 }
4421 
4422 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4423 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4424 				 tx_vlan, "tx_vlan");
4425 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4426 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4427 				 set, "set");
4428 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4429 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4430 				 pvid, "pvid");
4431 static cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4432 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4433 			     port_id, RTE_UINT16);
4434 static cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4435 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4436 			      vlan_id, RTE_UINT16);
4437 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4438 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4439 				 mode, "on#off");
4440 
4441 static cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4442 	.f = cmd_tx_vlan_set_pvid_parsed,
4443 	.data = NULL,
4444 	.help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4445 	.tokens = {
4446 		(void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4447 		(void *)&cmd_tx_vlan_set_pvid_set,
4448 		(void *)&cmd_tx_vlan_set_pvid_pvid,
4449 		(void *)&cmd_tx_vlan_set_pvid_port_id,
4450 		(void *)&cmd_tx_vlan_set_pvid_vlan_id,
4451 		(void *)&cmd_tx_vlan_set_pvid_mode,
4452 		NULL,
4453 	},
4454 };
4455 
4456 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4457 struct cmd_tx_vlan_reset_result {
4458 	cmdline_fixed_string_t tx_vlan;
4459 	cmdline_fixed_string_t reset;
4460 	portid_t port_id;
4461 };
4462 
4463 static void
4464 cmd_tx_vlan_reset_parsed(void *parsed_result,
4465 			 __rte_unused struct cmdline *cl,
4466 			 __rte_unused void *data)
4467 {
4468 	struct cmd_tx_vlan_reset_result *res = parsed_result;
4469 
4470 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4471 		return;
4472 
4473 	if (!port_is_stopped(res->port_id)) {
4474 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4475 		return;
4476 	}
4477 
4478 	tx_vlan_reset(res->port_id);
4479 
4480 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4481 }
4482 
4483 static cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4484 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4485 				 tx_vlan, "tx_vlan");
4486 static cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4487 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4488 				 reset, "reset");
4489 static cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4490 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4491 			      port_id, RTE_UINT16);
4492 
4493 static cmdline_parse_inst_t cmd_tx_vlan_reset = {
4494 	.f = cmd_tx_vlan_reset_parsed,
4495 	.data = NULL,
4496 	.help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4497 		"VLAN header in packets sent on a port",
4498 	.tokens = {
4499 		(void *)&cmd_tx_vlan_reset_tx_vlan,
4500 		(void *)&cmd_tx_vlan_reset_reset,
4501 		(void *)&cmd_tx_vlan_reset_portid,
4502 		NULL,
4503 	},
4504 };
4505 
4506 
4507 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4508 struct cmd_csum_result {
4509 	cmdline_fixed_string_t csum;
4510 	cmdline_fixed_string_t mode;
4511 	cmdline_fixed_string_t proto;
4512 	cmdline_fixed_string_t hwsw;
4513 	portid_t port_id;
4514 };
4515 
4516 static void
4517 csum_show(int port_id)
4518 {
4519 	struct rte_eth_dev_info dev_info;
4520 	uint64_t tx_offloads;
4521 	int ret;
4522 
4523 	tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4524 	printf("Parse tunnel is %s\n",
4525 		(ports[port_id].parse_tunnel) ? "on" : "off");
4526 	printf("IP checksum offload is %s\n",
4527 		(tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4528 	printf("UDP checksum offload is %s\n",
4529 		(tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4530 	printf("TCP checksum offload is %s\n",
4531 		(tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4532 	printf("SCTP checksum offload is %s\n",
4533 		(tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4534 	printf("Outer-Ip checksum offload is %s\n",
4535 		(tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4536 	printf("Outer-Udp checksum offload is %s\n",
4537 		(tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4538 
4539 	/* display warnings if configuration is not supported by the NIC */
4540 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
4541 	if (ret != 0)
4542 		return;
4543 
4544 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) &&
4545 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4546 		fprintf(stderr,
4547 			"Warning: hardware IP checksum enabled but not supported by port %d\n",
4548 			port_id);
4549 	}
4550 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) &&
4551 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) == 0) {
4552 		fprintf(stderr,
4553 			"Warning: hardware UDP checksum enabled but not supported by port %d\n",
4554 			port_id);
4555 	}
4556 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) &&
4557 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) == 0) {
4558 		fprintf(stderr,
4559 			"Warning: hardware TCP checksum enabled but not supported by port %d\n",
4560 			port_id);
4561 	}
4562 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) &&
4563 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4564 		fprintf(stderr,
4565 			"Warning: hardware SCTP checksum enabled but not supported by port %d\n",
4566 			port_id);
4567 	}
4568 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4569 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4570 		fprintf(stderr,
4571 			"Warning: hardware outer IP checksum enabled but not supported by port %d\n",
4572 			port_id);
4573 	}
4574 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4575 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
4576 			== 0) {
4577 		fprintf(stderr,
4578 			"Warning: hardware outer UDP checksum enabled but not supported by port %d\n",
4579 			port_id);
4580 	}
4581 }
4582 
4583 static void
4584 cmd_config_queue_tx_offloads(struct rte_port *port)
4585 {
4586 	int k;
4587 
4588 	/* Apply queue tx offloads configuration */
4589 	for (k = 0; k < port->dev_info.max_tx_queues; k++)
4590 		port->txq[k].conf.offloads =
4591 			port->dev_conf.txmode.offloads;
4592 }
4593 
4594 static void
4595 cmd_csum_parsed(void *parsed_result,
4596 		       __rte_unused struct cmdline *cl,
4597 		       __rte_unused void *data)
4598 {
4599 	struct cmd_csum_result *res = parsed_result;
4600 	int hw = 0;
4601 	uint64_t csum_offloads = 0;
4602 	struct rte_eth_dev_info dev_info;
4603 	int ret;
4604 
4605 	if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4606 		fprintf(stderr, "invalid port %d\n", res->port_id);
4607 		return;
4608 	}
4609 	if (!port_is_stopped(res->port_id)) {
4610 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4611 		return;
4612 	}
4613 
4614 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4615 	if (ret != 0)
4616 		return;
4617 
4618 	if (!strcmp(res->mode, "set")) {
4619 
4620 		if (!strcmp(res->hwsw, "hw"))
4621 			hw = 1;
4622 
4623 		if (!strcmp(res->proto, "ip")) {
4624 			if (hw == 0 || (dev_info.tx_offload_capa &
4625 						RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)) {
4626 				csum_offloads |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
4627 			} else {
4628 				fprintf(stderr,
4629 					"IP checksum offload is not supported by port %u\n",
4630 					res->port_id);
4631 			}
4632 		} else if (!strcmp(res->proto, "udp")) {
4633 			if (hw == 0 || (dev_info.tx_offload_capa &
4634 						RTE_ETH_TX_OFFLOAD_UDP_CKSUM)) {
4635 				csum_offloads |= RTE_ETH_TX_OFFLOAD_UDP_CKSUM;
4636 			} else {
4637 				fprintf(stderr,
4638 					"UDP checksum offload is not supported by port %u\n",
4639 					res->port_id);
4640 			}
4641 		} else if (!strcmp(res->proto, "tcp")) {
4642 			if (hw == 0 || (dev_info.tx_offload_capa &
4643 						RTE_ETH_TX_OFFLOAD_TCP_CKSUM)) {
4644 				csum_offloads |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
4645 			} else {
4646 				fprintf(stderr,
4647 					"TCP checksum offload is not supported by port %u\n",
4648 					res->port_id);
4649 			}
4650 		} else if (!strcmp(res->proto, "sctp")) {
4651 			if (hw == 0 || (dev_info.tx_offload_capa &
4652 						RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)) {
4653 				csum_offloads |= RTE_ETH_TX_OFFLOAD_SCTP_CKSUM;
4654 			} else {
4655 				fprintf(stderr,
4656 					"SCTP checksum offload is not supported by port %u\n",
4657 					res->port_id);
4658 			}
4659 		} else if (!strcmp(res->proto, "outer-ip")) {
4660 			if (hw == 0 || (dev_info.tx_offload_capa &
4661 					RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4662 				csum_offloads |=
4663 						RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4664 			} else {
4665 				fprintf(stderr,
4666 					"Outer IP checksum offload is not supported by port %u\n",
4667 					res->port_id);
4668 			}
4669 		} else if (!strcmp(res->proto, "outer-udp")) {
4670 			if (hw == 0 || (dev_info.tx_offload_capa &
4671 					RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4672 				csum_offloads |=
4673 						RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
4674 			} else {
4675 				fprintf(stderr,
4676 					"Outer UDP checksum offload is not supported by port %u\n",
4677 					res->port_id);
4678 			}
4679 		}
4680 
4681 		if (hw) {
4682 			ports[res->port_id].dev_conf.txmode.offloads |=
4683 							csum_offloads;
4684 		} else {
4685 			ports[res->port_id].dev_conf.txmode.offloads &=
4686 							(~csum_offloads);
4687 		}
4688 		cmd_config_queue_tx_offloads(&ports[res->port_id]);
4689 	}
4690 	csum_show(res->port_id);
4691 
4692 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4693 }
4694 
4695 static cmdline_parse_token_string_t cmd_csum_csum =
4696 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4697 				csum, "csum");
4698 static cmdline_parse_token_string_t cmd_csum_mode =
4699 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4700 				mode, "set");
4701 static cmdline_parse_token_string_t cmd_csum_proto =
4702 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4703 				proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4704 static cmdline_parse_token_string_t cmd_csum_hwsw =
4705 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4706 				hwsw, "hw#sw");
4707 static cmdline_parse_token_num_t cmd_csum_portid =
4708 	TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4709 				port_id, RTE_UINT16);
4710 
4711 static cmdline_parse_inst_t cmd_csum_set = {
4712 	.f = cmd_csum_parsed,
4713 	.data = NULL,
4714 	.help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4715 		"Enable/Disable hardware calculation of L3/L4 checksum when "
4716 		"using csum forward engine",
4717 	.tokens = {
4718 		(void *)&cmd_csum_csum,
4719 		(void *)&cmd_csum_mode,
4720 		(void *)&cmd_csum_proto,
4721 		(void *)&cmd_csum_hwsw,
4722 		(void *)&cmd_csum_portid,
4723 		NULL,
4724 	},
4725 };
4726 
4727 static cmdline_parse_token_string_t cmd_csum_mode_show =
4728 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4729 				mode, "show");
4730 
4731 static cmdline_parse_inst_t cmd_csum_show = {
4732 	.f = cmd_csum_parsed,
4733 	.data = NULL,
4734 	.help_str = "csum show <port_id>: Show checksum offload configuration",
4735 	.tokens = {
4736 		(void *)&cmd_csum_csum,
4737 		(void *)&cmd_csum_mode_show,
4738 		(void *)&cmd_csum_portid,
4739 		NULL,
4740 	},
4741 };
4742 
4743 /* Enable/disable tunnel parsing */
4744 struct cmd_csum_tunnel_result {
4745 	cmdline_fixed_string_t csum;
4746 	cmdline_fixed_string_t parse;
4747 	cmdline_fixed_string_t onoff;
4748 	portid_t port_id;
4749 };
4750 
4751 static void
4752 cmd_csum_tunnel_parsed(void *parsed_result,
4753 		       __rte_unused struct cmdline *cl,
4754 		       __rte_unused void *data)
4755 {
4756 	struct cmd_csum_tunnel_result *res = parsed_result;
4757 
4758 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4759 		return;
4760 
4761 	if (!strcmp(res->onoff, "on"))
4762 		ports[res->port_id].parse_tunnel = 1;
4763 	else
4764 		ports[res->port_id].parse_tunnel = 0;
4765 
4766 	csum_show(res->port_id);
4767 }
4768 
4769 static cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4770 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4771 				csum, "csum");
4772 static cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4773 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4774 				parse, "parse-tunnel");
4775 static cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4776 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4777 				onoff, "on#off");
4778 static cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4779 	TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4780 				port_id, RTE_UINT16);
4781 
4782 static cmdline_parse_inst_t cmd_csum_tunnel = {
4783 	.f = cmd_csum_tunnel_parsed,
4784 	.data = NULL,
4785 	.help_str = "csum parse-tunnel on|off <port_id>: "
4786 		"Enable/Disable parsing of tunnels for csum engine",
4787 	.tokens = {
4788 		(void *)&cmd_csum_tunnel_csum,
4789 		(void *)&cmd_csum_tunnel_parse,
4790 		(void *)&cmd_csum_tunnel_onoff,
4791 		(void *)&cmd_csum_tunnel_portid,
4792 		NULL,
4793 	},
4794 };
4795 
4796 struct cmd_csum_mac_swap_result {
4797 	cmdline_fixed_string_t csum;
4798 	cmdline_fixed_string_t parse;
4799 	cmdline_fixed_string_t onoff;
4800 	portid_t port_id;
4801 };
4802 
4803 static void
4804 cmd_csum_mac_swap_parsed(void *parsed_result,
4805 		       __rte_unused struct cmdline *cl,
4806 		       __rte_unused void *data)
4807 {
4808 	struct cmd_csum_mac_swap_result *res = parsed_result;
4809 
4810 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4811 		return;
4812 	if (strcmp(res->onoff, "on") == 0)
4813 		ports[res->port_id].fwd_mac_swap = 1;
4814 	else
4815 		ports[res->port_id].fwd_mac_swap = 0;
4816 }
4817 
4818 static cmdline_parse_token_string_t cmd_csum_mac_swap_csum =
4819 	TOKEN_STRING_INITIALIZER(struct cmd_csum_mac_swap_result,
4820 				 csum, "csum");
4821 static cmdline_parse_token_string_t cmd_csum_mac_swap_parse =
4822 	TOKEN_STRING_INITIALIZER(struct cmd_csum_mac_swap_result,
4823 				 parse, "mac-swap");
4824 static cmdline_parse_token_string_t cmd_csum_mac_swap_onoff =
4825 	TOKEN_STRING_INITIALIZER(struct cmd_csum_mac_swap_result,
4826 				 onoff, "on#off");
4827 static cmdline_parse_token_num_t cmd_csum_mac_swap_portid =
4828 	TOKEN_NUM_INITIALIZER(struct cmd_csum_mac_swap_result,
4829 			      port_id, RTE_UINT16);
4830 
4831 static cmdline_parse_inst_t cmd_csum_mac_swap = {
4832 	.f = cmd_csum_mac_swap_parsed,
4833 	.data = NULL,
4834 	.help_str = "csum mac-swap on|off <port_id>: "
4835 		    "Enable/Disable forward mac address swap",
4836 	.tokens = {
4837 		(void *)&cmd_csum_mac_swap_csum,
4838 		(void *)&cmd_csum_mac_swap_parse,
4839 		(void *)&cmd_csum_mac_swap_onoff,
4840 		(void *)&cmd_csum_mac_swap_portid,
4841 		NULL,
4842 	},
4843 };
4844 
4845 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4846 struct cmd_tso_set_result {
4847 	cmdline_fixed_string_t tso;
4848 	cmdline_fixed_string_t mode;
4849 	uint16_t tso_segsz;
4850 	portid_t port_id;
4851 };
4852 
4853 static void
4854 cmd_tso_set_parsed(void *parsed_result,
4855 		       __rte_unused struct cmdline *cl,
4856 		       __rte_unused void *data)
4857 {
4858 	struct cmd_tso_set_result *res = parsed_result;
4859 	struct rte_eth_dev_info dev_info;
4860 	int ret;
4861 
4862 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4863 		return;
4864 	if (!port_is_stopped(res->port_id)) {
4865 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4866 		return;
4867 	}
4868 
4869 	if (!strcmp(res->mode, "set"))
4870 		ports[res->port_id].tso_segsz = res->tso_segsz;
4871 
4872 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4873 	if (ret != 0)
4874 		return;
4875 
4876 	if ((ports[res->port_id].tso_segsz != 0) &&
4877 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4878 		fprintf(stderr, "Error: TSO is not supported by port %d\n",
4879 			res->port_id);
4880 		return;
4881 	}
4882 
4883 	if (ports[res->port_id].tso_segsz == 0) {
4884 		ports[res->port_id].dev_conf.txmode.offloads &=
4885 						~RTE_ETH_TX_OFFLOAD_TCP_TSO;
4886 		printf("TSO for non-tunneled packets is disabled\n");
4887 	} else {
4888 		ports[res->port_id].dev_conf.txmode.offloads |=
4889 						RTE_ETH_TX_OFFLOAD_TCP_TSO;
4890 		printf("TSO segment size for non-tunneled packets is %d\n",
4891 			ports[res->port_id].tso_segsz);
4892 	}
4893 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
4894 
4895 	/* display warnings if configuration is not supported by the NIC */
4896 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4897 	if (ret != 0)
4898 		return;
4899 
4900 	if ((ports[res->port_id].tso_segsz != 0) &&
4901 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4902 		fprintf(stderr,
4903 			"Warning: TSO enabled but not supported by port %d\n",
4904 			res->port_id);
4905 	}
4906 
4907 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4908 }
4909 
4910 static cmdline_parse_token_string_t cmd_tso_set_tso =
4911 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4912 				tso, "tso");
4913 static cmdline_parse_token_string_t cmd_tso_set_mode =
4914 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4915 				mode, "set");
4916 static cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4917 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4918 				tso_segsz, RTE_UINT16);
4919 static cmdline_parse_token_num_t cmd_tso_set_portid =
4920 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4921 				port_id, RTE_UINT16);
4922 
4923 static cmdline_parse_inst_t cmd_tso_set = {
4924 	.f = cmd_tso_set_parsed,
4925 	.data = NULL,
4926 	.help_str = "tso set <tso_segsz> <port_id>: "
4927 		"Set TSO segment size of non-tunneled packets for csum engine "
4928 		"(0 to disable)",
4929 	.tokens = {
4930 		(void *)&cmd_tso_set_tso,
4931 		(void *)&cmd_tso_set_mode,
4932 		(void *)&cmd_tso_set_tso_segsz,
4933 		(void *)&cmd_tso_set_portid,
4934 		NULL,
4935 	},
4936 };
4937 
4938 static cmdline_parse_token_string_t cmd_tso_show_mode =
4939 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4940 				mode, "show");
4941 
4942 
4943 static cmdline_parse_inst_t cmd_tso_show = {
4944 	.f = cmd_tso_set_parsed,
4945 	.data = NULL,
4946 	.help_str = "tso show <port_id>: "
4947 		"Show TSO segment size of non-tunneled packets for csum engine",
4948 	.tokens = {
4949 		(void *)&cmd_tso_set_tso,
4950 		(void *)&cmd_tso_show_mode,
4951 		(void *)&cmd_tso_set_portid,
4952 		NULL,
4953 	},
4954 };
4955 
4956 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4957 struct cmd_tunnel_tso_set_result {
4958 	cmdline_fixed_string_t tso;
4959 	cmdline_fixed_string_t mode;
4960 	uint16_t tso_segsz;
4961 	portid_t port_id;
4962 };
4963 
4964 static struct rte_eth_dev_info
4965 check_tunnel_tso_nic_support(portid_t port_id)
4966 {
4967 	struct rte_eth_dev_info dev_info;
4968 
4969 	if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4970 		return dev_info;
4971 
4972 	if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO))
4973 		fprintf(stderr,
4974 			"Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n",
4975 			port_id);
4976 	if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO))
4977 		fprintf(stderr,
4978 			"Warning: GRE TUNNEL TSO not supported therefore not enabled for port %d\n",
4979 			port_id);
4980 	if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO))
4981 		fprintf(stderr,
4982 			"Warning: IPIP TUNNEL TSO not supported therefore not enabled for port %d\n",
4983 			port_id);
4984 	if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO))
4985 		fprintf(stderr,
4986 			"Warning: GENEVE TUNNEL TSO not supported therefore not enabled for port %d\n",
4987 			port_id);
4988 	if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IP_TNL_TSO))
4989 		fprintf(stderr,
4990 			"Warning: IP TUNNEL TSO not supported therefore not enabled for port %d\n",
4991 			port_id);
4992 	if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO))
4993 		fprintf(stderr,
4994 			"Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n",
4995 			port_id);
4996 	return dev_info;
4997 }
4998 
4999 static void
5000 cmd_tunnel_tso_set_parsed(void *parsed_result,
5001 			  __rte_unused struct cmdline *cl,
5002 			  __rte_unused void *data)
5003 {
5004 	struct cmd_tunnel_tso_set_result *res = parsed_result;
5005 	struct rte_eth_dev_info dev_info;
5006 
5007 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5008 		return;
5009 	if (!port_is_stopped(res->port_id)) {
5010 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
5011 		return;
5012 	}
5013 
5014 	if (!strcmp(res->mode, "set"))
5015 		ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5016 
5017 	dev_info = check_tunnel_tso_nic_support(res->port_id);
5018 	if (ports[res->port_id].tunnel_tso_segsz == 0) {
5019 		ports[res->port_id].dev_conf.txmode.offloads &=
5020 			~(RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5021 			  RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5022 			  RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5023 			  RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5024 			  RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5025 			  RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5026 		printf("TSO for tunneled packets is disabled\n");
5027 	} else {
5028 		uint64_t tso_offloads = (RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5029 					 RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5030 					 RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5031 					 RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5032 					 RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5033 					 RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5034 
5035 		ports[res->port_id].dev_conf.txmode.offloads |=
5036 			(tso_offloads & dev_info.tx_offload_capa);
5037 		printf("TSO segment size for tunneled packets is %d\n",
5038 			ports[res->port_id].tunnel_tso_segsz);
5039 
5040 		/* Below conditions are needed to make it work:
5041 		 * (1) tunnel TSO is supported by the NIC;
5042 		 * (2) "csum parse_tunnel" must be set so that tunneled pkts
5043 		 * are recognized;
5044 		 * (3) for tunneled pkts with outer L3 of IPv4,
5045 		 * "csum set outer-ip" must be set to hw, because after tso,
5046 		 * total_len of outer IP header is changed, and the checksum
5047 		 * of outer IP header calculated by sw should be wrong; that
5048 		 * is not necessary for IPv6 tunneled pkts because there's no
5049 		 * checksum in IP header anymore.
5050 		 */
5051 
5052 		if (!ports[res->port_id].parse_tunnel)
5053 			fprintf(stderr,
5054 				"Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n");
5055 		if (!(ports[res->port_id].dev_conf.txmode.offloads &
5056 		      RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5057 			fprintf(stderr,
5058 				"Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n");
5059 	}
5060 
5061 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
5062 	cmd_reconfig_device_queue(res->port_id, 1, 1);
5063 }
5064 
5065 static cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5066 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5067 				tso, "tunnel_tso");
5068 static cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5069 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5070 				mode, "set");
5071 static cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5072 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5073 				tso_segsz, RTE_UINT16);
5074 static cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5075 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5076 				port_id, RTE_UINT16);
5077 
5078 static cmdline_parse_inst_t cmd_tunnel_tso_set = {
5079 	.f = cmd_tunnel_tso_set_parsed,
5080 	.data = NULL,
5081 	.help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5082 		"Set TSO segment size of tunneled packets for csum engine "
5083 		"(0 to disable)",
5084 	.tokens = {
5085 		(void *)&cmd_tunnel_tso_set_tso,
5086 		(void *)&cmd_tunnel_tso_set_mode,
5087 		(void *)&cmd_tunnel_tso_set_tso_segsz,
5088 		(void *)&cmd_tunnel_tso_set_portid,
5089 		NULL,
5090 	},
5091 };
5092 
5093 static cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5094 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5095 				mode, "show");
5096 
5097 
5098 static cmdline_parse_inst_t cmd_tunnel_tso_show = {
5099 	.f = cmd_tunnel_tso_set_parsed,
5100 	.data = NULL,
5101 	.help_str = "tunnel_tso show <port_id> "
5102 		"Show TSO segment size of tunneled packets for csum engine",
5103 	.tokens = {
5104 		(void *)&cmd_tunnel_tso_set_tso,
5105 		(void *)&cmd_tunnel_tso_show_mode,
5106 		(void *)&cmd_tunnel_tso_set_portid,
5107 		NULL,
5108 	},
5109 };
5110 
5111 #ifdef RTE_LIB_GRO
5112 /* *** SET GRO FOR A PORT *** */
5113 struct cmd_gro_enable_result {
5114 	cmdline_fixed_string_t cmd_set;
5115 	cmdline_fixed_string_t cmd_port;
5116 	cmdline_fixed_string_t cmd_keyword;
5117 	cmdline_fixed_string_t cmd_onoff;
5118 	portid_t cmd_pid;
5119 };
5120 
5121 static void
5122 cmd_gro_enable_parsed(void *parsed_result,
5123 		__rte_unused struct cmdline *cl,
5124 		__rte_unused void *data)
5125 {
5126 	struct cmd_gro_enable_result *res;
5127 
5128 	res = parsed_result;
5129 	if (!strcmp(res->cmd_keyword, "gro"))
5130 		setup_gro(res->cmd_onoff, res->cmd_pid);
5131 }
5132 
5133 static cmdline_parse_token_string_t cmd_gro_enable_set =
5134 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5135 			cmd_set, "set");
5136 static cmdline_parse_token_string_t cmd_gro_enable_port =
5137 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5138 			cmd_keyword, "port");
5139 static cmdline_parse_token_num_t cmd_gro_enable_pid =
5140 	TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5141 			cmd_pid, RTE_UINT16);
5142 static cmdline_parse_token_string_t cmd_gro_enable_keyword =
5143 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5144 			cmd_keyword, "gro");
5145 static cmdline_parse_token_string_t cmd_gro_enable_onoff =
5146 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5147 			cmd_onoff, "on#off");
5148 
5149 static cmdline_parse_inst_t cmd_gro_enable = {
5150 	.f = cmd_gro_enable_parsed,
5151 	.data = NULL,
5152 	.help_str = "set port <port_id> gro on|off",
5153 	.tokens = {
5154 		(void *)&cmd_gro_enable_set,
5155 		(void *)&cmd_gro_enable_port,
5156 		(void *)&cmd_gro_enable_pid,
5157 		(void *)&cmd_gro_enable_keyword,
5158 		(void *)&cmd_gro_enable_onoff,
5159 		NULL,
5160 	},
5161 };
5162 
5163 /* *** DISPLAY GRO CONFIGURATION *** */
5164 struct cmd_gro_show_result {
5165 	cmdline_fixed_string_t cmd_show;
5166 	cmdline_fixed_string_t cmd_port;
5167 	cmdline_fixed_string_t cmd_keyword;
5168 	portid_t cmd_pid;
5169 };
5170 
5171 static void
5172 cmd_gro_show_parsed(void *parsed_result,
5173 		__rte_unused struct cmdline *cl,
5174 		__rte_unused void *data)
5175 {
5176 	struct cmd_gro_show_result *res;
5177 
5178 	res = parsed_result;
5179 	if (!strcmp(res->cmd_keyword, "gro"))
5180 		show_gro(res->cmd_pid);
5181 }
5182 
5183 static cmdline_parse_token_string_t cmd_gro_show_show =
5184 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5185 			cmd_show, "show");
5186 static cmdline_parse_token_string_t cmd_gro_show_port =
5187 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5188 			cmd_port, "port");
5189 static cmdline_parse_token_num_t cmd_gro_show_pid =
5190 	TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5191 			cmd_pid, RTE_UINT16);
5192 static cmdline_parse_token_string_t cmd_gro_show_keyword =
5193 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5194 			cmd_keyword, "gro");
5195 
5196 static cmdline_parse_inst_t cmd_gro_show = {
5197 	.f = cmd_gro_show_parsed,
5198 	.data = NULL,
5199 	.help_str = "show port <port_id> gro",
5200 	.tokens = {
5201 		(void *)&cmd_gro_show_show,
5202 		(void *)&cmd_gro_show_port,
5203 		(void *)&cmd_gro_show_pid,
5204 		(void *)&cmd_gro_show_keyword,
5205 		NULL,
5206 	},
5207 };
5208 
5209 /* *** SET FLUSH CYCLES FOR GRO *** */
5210 struct cmd_gro_flush_result {
5211 	cmdline_fixed_string_t cmd_set;
5212 	cmdline_fixed_string_t cmd_keyword;
5213 	cmdline_fixed_string_t cmd_flush;
5214 	uint8_t cmd_cycles;
5215 };
5216 
5217 static void
5218 cmd_gro_flush_parsed(void *parsed_result,
5219 		__rte_unused struct cmdline *cl,
5220 		__rte_unused void *data)
5221 {
5222 	struct cmd_gro_flush_result *res;
5223 
5224 	res = parsed_result;
5225 	if ((!strcmp(res->cmd_keyword, "gro")) &&
5226 			(!strcmp(res->cmd_flush, "flush")))
5227 		setup_gro_flush_cycles(res->cmd_cycles);
5228 }
5229 
5230 static cmdline_parse_token_string_t cmd_gro_flush_set =
5231 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5232 			cmd_set, "set");
5233 static cmdline_parse_token_string_t cmd_gro_flush_keyword =
5234 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5235 			cmd_keyword, "gro");
5236 static cmdline_parse_token_string_t cmd_gro_flush_flush =
5237 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5238 			cmd_flush, "flush");
5239 static cmdline_parse_token_num_t cmd_gro_flush_cycles =
5240 	TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5241 			cmd_cycles, RTE_UINT8);
5242 
5243 static cmdline_parse_inst_t cmd_gro_flush = {
5244 	.f = cmd_gro_flush_parsed,
5245 	.data = NULL,
5246 	.help_str = "set gro flush <cycles>",
5247 	.tokens = {
5248 		(void *)&cmd_gro_flush_set,
5249 		(void *)&cmd_gro_flush_keyword,
5250 		(void *)&cmd_gro_flush_flush,
5251 		(void *)&cmd_gro_flush_cycles,
5252 		NULL,
5253 	},
5254 };
5255 #endif /* RTE_LIB_GRO */
5256 
5257 #ifdef RTE_LIB_GSO
5258 /* *** ENABLE/DISABLE GSO *** */
5259 struct cmd_gso_enable_result {
5260 	cmdline_fixed_string_t cmd_set;
5261 	cmdline_fixed_string_t cmd_port;
5262 	cmdline_fixed_string_t cmd_keyword;
5263 	cmdline_fixed_string_t cmd_mode;
5264 	portid_t cmd_pid;
5265 };
5266 
5267 static void
5268 cmd_gso_enable_parsed(void *parsed_result,
5269 		__rte_unused struct cmdline *cl,
5270 		__rte_unused void *data)
5271 {
5272 	struct cmd_gso_enable_result *res;
5273 
5274 	res = parsed_result;
5275 	if (!strcmp(res->cmd_keyword, "gso"))
5276 		setup_gso(res->cmd_mode, res->cmd_pid);
5277 }
5278 
5279 static cmdline_parse_token_string_t cmd_gso_enable_set =
5280 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5281 			cmd_set, "set");
5282 static cmdline_parse_token_string_t cmd_gso_enable_port =
5283 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5284 			cmd_port, "port");
5285 static cmdline_parse_token_string_t cmd_gso_enable_keyword =
5286 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5287 			cmd_keyword, "gso");
5288 static cmdline_parse_token_string_t cmd_gso_enable_mode =
5289 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5290 			cmd_mode, "on#off");
5291 static cmdline_parse_token_num_t cmd_gso_enable_pid =
5292 	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5293 			cmd_pid, RTE_UINT16);
5294 
5295 static cmdline_parse_inst_t cmd_gso_enable = {
5296 	.f = cmd_gso_enable_parsed,
5297 	.data = NULL,
5298 	.help_str = "set port <port_id> gso on|off",
5299 	.tokens = {
5300 		(void *)&cmd_gso_enable_set,
5301 		(void *)&cmd_gso_enable_port,
5302 		(void *)&cmd_gso_enable_pid,
5303 		(void *)&cmd_gso_enable_keyword,
5304 		(void *)&cmd_gso_enable_mode,
5305 		NULL,
5306 	},
5307 };
5308 
5309 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5310 struct cmd_gso_size_result {
5311 	cmdline_fixed_string_t cmd_set;
5312 	cmdline_fixed_string_t cmd_keyword;
5313 	cmdline_fixed_string_t cmd_segsz;
5314 	uint16_t cmd_size;
5315 };
5316 
5317 static void
5318 cmd_gso_size_parsed(void *parsed_result,
5319 		       __rte_unused struct cmdline *cl,
5320 		       __rte_unused void *data)
5321 {
5322 	struct cmd_gso_size_result *res = parsed_result;
5323 
5324 	if (test_done == 0) {
5325 		fprintf(stderr,
5326 			"Before setting GSO segsz, please first stop forwarding\n");
5327 		return;
5328 	}
5329 
5330 	if (!strcmp(res->cmd_keyword, "gso") &&
5331 			!strcmp(res->cmd_segsz, "segsz")) {
5332 		if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5333 			fprintf(stderr,
5334 				"gso_size should be larger than %zu. Please input a legal value\n",
5335 				RTE_GSO_SEG_SIZE_MIN);
5336 		else
5337 			gso_max_segment_size = res->cmd_size;
5338 	}
5339 }
5340 
5341 static cmdline_parse_token_string_t cmd_gso_size_set =
5342 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5343 				cmd_set, "set");
5344 static cmdline_parse_token_string_t cmd_gso_size_keyword =
5345 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5346 				cmd_keyword, "gso");
5347 static cmdline_parse_token_string_t cmd_gso_size_segsz =
5348 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5349 				cmd_segsz, "segsz");
5350 static cmdline_parse_token_num_t cmd_gso_size_size =
5351 	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5352 				cmd_size, RTE_UINT16);
5353 
5354 static cmdline_parse_inst_t cmd_gso_size = {
5355 	.f = cmd_gso_size_parsed,
5356 	.data = NULL,
5357 	.help_str = "set gso segsz <length>",
5358 	.tokens = {
5359 		(void *)&cmd_gso_size_set,
5360 		(void *)&cmd_gso_size_keyword,
5361 		(void *)&cmd_gso_size_segsz,
5362 		(void *)&cmd_gso_size_size,
5363 		NULL,
5364 	},
5365 };
5366 
5367 /* *** SHOW GSO CONFIGURATION *** */
5368 struct cmd_gso_show_result {
5369 	cmdline_fixed_string_t cmd_show;
5370 	cmdline_fixed_string_t cmd_port;
5371 	cmdline_fixed_string_t cmd_keyword;
5372 	portid_t cmd_pid;
5373 };
5374 
5375 static void
5376 cmd_gso_show_parsed(void *parsed_result,
5377 		       __rte_unused struct cmdline *cl,
5378 		       __rte_unused void *data)
5379 {
5380 	struct cmd_gso_show_result *res = parsed_result;
5381 
5382 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5383 		fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
5384 		return;
5385 	}
5386 	if (!strcmp(res->cmd_keyword, "gso")) {
5387 		if (gso_ports[res->cmd_pid].enable) {
5388 			printf("Max GSO'd packet size: %uB\n"
5389 					"Supported GSO types: TCP/IPv4, "
5390 					"UDP/IPv4, VxLAN with inner "
5391 					"TCP/IPv4 packet, GRE with inner "
5392 					"TCP/IPv4 packet\n",
5393 					gso_max_segment_size);
5394 		} else
5395 			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5396 	}
5397 }
5398 
5399 static cmdline_parse_token_string_t cmd_gso_show_show =
5400 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5401 		cmd_show, "show");
5402 static cmdline_parse_token_string_t cmd_gso_show_port =
5403 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5404 		cmd_port, "port");
5405 static cmdline_parse_token_string_t cmd_gso_show_keyword =
5406 	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5407 				cmd_keyword, "gso");
5408 static cmdline_parse_token_num_t cmd_gso_show_pid =
5409 	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5410 				cmd_pid, RTE_UINT16);
5411 
5412 static cmdline_parse_inst_t cmd_gso_show = {
5413 	.f = cmd_gso_show_parsed,
5414 	.data = NULL,
5415 	.help_str = "show port <port_id> gso",
5416 	.tokens = {
5417 		(void *)&cmd_gso_show_show,
5418 		(void *)&cmd_gso_show_port,
5419 		(void *)&cmd_gso_show_pid,
5420 		(void *)&cmd_gso_show_keyword,
5421 		NULL,
5422 	},
5423 };
5424 #endif /* RTE_LIB_GSO */
5425 
5426 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5427 struct cmd_set_flush_rx {
5428 	cmdline_fixed_string_t set;
5429 	cmdline_fixed_string_t flush_rx;
5430 	cmdline_fixed_string_t mode;
5431 };
5432 
5433 static void
5434 cmd_set_flush_rx_parsed(void *parsed_result,
5435 		__rte_unused struct cmdline *cl,
5436 		__rte_unused void *data)
5437 {
5438 	struct cmd_set_flush_rx *res = parsed_result;
5439 
5440 	if (num_procs > 1 && (strcmp(res->mode, "on") == 0)) {
5441 		printf("multi-process doesn't support to flush Rx queues.\n");
5442 		return;
5443 	}
5444 
5445 	no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5446 }
5447 
5448 static cmdline_parse_token_string_t cmd_setflushrx_set =
5449 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5450 			set, "set");
5451 static cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5452 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5453 			flush_rx, "flush_rx");
5454 static cmdline_parse_token_string_t cmd_setflushrx_mode =
5455 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5456 			mode, "on#off");
5457 
5458 
5459 static cmdline_parse_inst_t cmd_set_flush_rx = {
5460 	.f = cmd_set_flush_rx_parsed,
5461 	.help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5462 	.data = NULL,
5463 	.tokens = {
5464 		(void *)&cmd_setflushrx_set,
5465 		(void *)&cmd_setflushrx_flush_rx,
5466 		(void *)&cmd_setflushrx_mode,
5467 		NULL,
5468 	},
5469 };
5470 
5471 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5472 struct cmd_set_link_check {
5473 	cmdline_fixed_string_t set;
5474 	cmdline_fixed_string_t link_check;
5475 	cmdline_fixed_string_t mode;
5476 };
5477 
5478 static void
5479 cmd_set_link_check_parsed(void *parsed_result,
5480 		__rte_unused struct cmdline *cl,
5481 		__rte_unused void *data)
5482 {
5483 	struct cmd_set_link_check *res = parsed_result;
5484 	no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5485 }
5486 
5487 static cmdline_parse_token_string_t cmd_setlinkcheck_set =
5488 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5489 			set, "set");
5490 static cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5491 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5492 			link_check, "link_check");
5493 static cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5494 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5495 			mode, "on#off");
5496 
5497 
5498 static cmdline_parse_inst_t cmd_set_link_check = {
5499 	.f = cmd_set_link_check_parsed,
5500 	.help_str = "set link_check on|off: Enable/Disable link status check "
5501 	            "when starting/stopping a port",
5502 	.data = NULL,
5503 	.tokens = {
5504 		(void *)&cmd_setlinkcheck_set,
5505 		(void *)&cmd_setlinkcheck_link_check,
5506 		(void *)&cmd_setlinkcheck_mode,
5507 		NULL,
5508 	},
5509 };
5510 
5511 /* *** SET FORWARDING MODE *** */
5512 struct cmd_set_fwd_mode_result {
5513 	cmdline_fixed_string_t set;
5514 	cmdline_fixed_string_t fwd;
5515 	cmdline_fixed_string_t mode;
5516 };
5517 
5518 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5519 				    __rte_unused struct cmdline *cl,
5520 				    __rte_unused void *data)
5521 {
5522 	struct cmd_set_fwd_mode_result *res = parsed_result;
5523 
5524 	retry_enabled = 0;
5525 	set_pkt_forwarding_mode(res->mode);
5526 }
5527 
5528 static cmdline_parse_token_string_t cmd_setfwd_set =
5529 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5530 static cmdline_parse_token_string_t cmd_setfwd_fwd =
5531 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5532 static cmdline_parse_token_string_t cmd_setfwd_mode =
5533 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5534 		"" /* defined at init */);
5535 
5536 static cmdline_parse_inst_t cmd_set_fwd_mode = {
5537 	.f = cmd_set_fwd_mode_parsed,
5538 	.data = NULL,
5539 	.help_str = NULL, /* defined at init */
5540 	.tokens = {
5541 		(void *)&cmd_setfwd_set,
5542 		(void *)&cmd_setfwd_fwd,
5543 		(void *)&cmd_setfwd_mode,
5544 		NULL,
5545 	},
5546 };
5547 
5548 static void cmd_set_fwd_mode_init(void)
5549 {
5550 	char *modes, *c;
5551 	static char token[128];
5552 	static char help[256];
5553 	cmdline_parse_token_string_t *token_struct;
5554 
5555 	modes = list_pkt_forwarding_modes();
5556 	snprintf(help, sizeof(help), "set fwd %s: "
5557 		"Set packet forwarding mode", modes);
5558 	cmd_set_fwd_mode.help_str = help;
5559 
5560 	/* string token separator is # */
5561 	for (c = token; *modes != '\0'; modes++)
5562 		if (*modes == '|')
5563 			*c++ = '#';
5564 		else
5565 			*c++ = *modes;
5566 	token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5567 	token_struct->string_data.str = token;
5568 }
5569 
5570 /* *** SET RETRY FORWARDING MODE *** */
5571 struct cmd_set_fwd_retry_mode_result {
5572 	cmdline_fixed_string_t set;
5573 	cmdline_fixed_string_t fwd;
5574 	cmdline_fixed_string_t mode;
5575 	cmdline_fixed_string_t retry;
5576 };
5577 
5578 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5579 			    __rte_unused struct cmdline *cl,
5580 			    __rte_unused void *data)
5581 {
5582 	struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5583 
5584 	retry_enabled = 1;
5585 	set_pkt_forwarding_mode(res->mode);
5586 }
5587 
5588 static cmdline_parse_token_string_t cmd_setfwd_retry_set =
5589 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5590 			set, "set");
5591 static cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5592 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5593 			fwd, "fwd");
5594 static cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5595 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5596 			mode,
5597 		"" /* defined at init */);
5598 static cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5599 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5600 			retry, "retry");
5601 
5602 static cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5603 	.f = cmd_set_fwd_retry_mode_parsed,
5604 	.data = NULL,
5605 	.help_str = NULL, /* defined at init */
5606 	.tokens = {
5607 		(void *)&cmd_setfwd_retry_set,
5608 		(void *)&cmd_setfwd_retry_fwd,
5609 		(void *)&cmd_setfwd_retry_mode,
5610 		(void *)&cmd_setfwd_retry_retry,
5611 		NULL,
5612 	},
5613 };
5614 
5615 static void cmd_set_fwd_retry_mode_init(void)
5616 {
5617 	char *modes, *c;
5618 	static char token[128];
5619 	static char help[256];
5620 	cmdline_parse_token_string_t *token_struct;
5621 
5622 	modes = list_pkt_forwarding_retry_modes();
5623 	snprintf(help, sizeof(help), "set fwd %s retry: "
5624 		"Set packet forwarding mode with retry", modes);
5625 	cmd_set_fwd_retry_mode.help_str = help;
5626 
5627 	/* string token separator is # */
5628 	for (c = token; *modes != '\0'; modes++)
5629 		if (*modes == '|')
5630 			*c++ = '#';
5631 		else
5632 			*c++ = *modes;
5633 	token_struct = (cmdline_parse_token_string_t *)
5634 		cmd_set_fwd_retry_mode.tokens[2];
5635 	token_struct->string_data.str = token;
5636 }
5637 
5638 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5639 struct cmd_set_burst_tx_retry_result {
5640 	cmdline_fixed_string_t set;
5641 	cmdline_fixed_string_t burst;
5642 	cmdline_fixed_string_t tx;
5643 	cmdline_fixed_string_t delay;
5644 	uint32_t time;
5645 	cmdline_fixed_string_t retry;
5646 	uint32_t retry_num;
5647 };
5648 
5649 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5650 					__rte_unused struct cmdline *cl,
5651 					__rte_unused void *data)
5652 {
5653 	struct cmd_set_burst_tx_retry_result *res = parsed_result;
5654 
5655 	if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5656 		&& !strcmp(res->tx, "tx")) {
5657 		if (!strcmp(res->delay, "delay"))
5658 			burst_tx_delay_time = res->time;
5659 		if (!strcmp(res->retry, "retry"))
5660 			burst_tx_retry_num = res->retry_num;
5661 	}
5662 
5663 }
5664 
5665 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5666 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5667 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5668 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5669 				 "burst");
5670 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5671 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5672 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5673 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5674 static cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5675 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
5676 				 RTE_UINT32);
5677 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5678 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5679 static cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5680 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
5681 				 RTE_UINT32);
5682 
5683 static cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5684 	.f = cmd_set_burst_tx_retry_parsed,
5685 	.help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5686 	.tokens = {
5687 		(void *)&cmd_set_burst_tx_retry_set,
5688 		(void *)&cmd_set_burst_tx_retry_burst,
5689 		(void *)&cmd_set_burst_tx_retry_tx,
5690 		(void *)&cmd_set_burst_tx_retry_delay,
5691 		(void *)&cmd_set_burst_tx_retry_time,
5692 		(void *)&cmd_set_burst_tx_retry_retry,
5693 		(void *)&cmd_set_burst_tx_retry_retry_num,
5694 		NULL,
5695 	},
5696 };
5697 
5698 /* *** SET PROMISC MODE *** */
5699 struct cmd_set_promisc_mode_result {
5700 	cmdline_fixed_string_t set;
5701 	cmdline_fixed_string_t promisc;
5702 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5703 	uint16_t port_num;               /* valid if "allports" argument == 0 */
5704 	cmdline_fixed_string_t mode;
5705 };
5706 
5707 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5708 					__rte_unused struct cmdline *cl,
5709 					void *allports)
5710 {
5711 	struct cmd_set_promisc_mode_result *res = parsed_result;
5712 	int enable;
5713 	portid_t i;
5714 
5715 	if (!strcmp(res->mode, "on"))
5716 		enable = 1;
5717 	else
5718 		enable = 0;
5719 
5720 	/* all ports */
5721 	if (allports) {
5722 		RTE_ETH_FOREACH_DEV(i)
5723 			eth_set_promisc_mode(i, enable);
5724 	} else {
5725 		eth_set_promisc_mode(res->port_num, enable);
5726 	}
5727 }
5728 
5729 static cmdline_parse_token_string_t cmd_setpromisc_set =
5730 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5731 static cmdline_parse_token_string_t cmd_setpromisc_promisc =
5732 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5733 				 "promisc");
5734 static cmdline_parse_token_string_t cmd_setpromisc_portall =
5735 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5736 				 "all");
5737 static cmdline_parse_token_num_t cmd_setpromisc_portnum =
5738 	TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5739 			      RTE_UINT16);
5740 static cmdline_parse_token_string_t cmd_setpromisc_mode =
5741 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5742 				 "on#off");
5743 
5744 static cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5745 	.f = cmd_set_promisc_mode_parsed,
5746 	.data = (void *)1,
5747 	.help_str = "set promisc all on|off: Set promisc mode for all ports",
5748 	.tokens = {
5749 		(void *)&cmd_setpromisc_set,
5750 		(void *)&cmd_setpromisc_promisc,
5751 		(void *)&cmd_setpromisc_portall,
5752 		(void *)&cmd_setpromisc_mode,
5753 		NULL,
5754 	},
5755 };
5756 
5757 static cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5758 	.f = cmd_set_promisc_mode_parsed,
5759 	.data = (void *)0,
5760 	.help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5761 	.tokens = {
5762 		(void *)&cmd_setpromisc_set,
5763 		(void *)&cmd_setpromisc_promisc,
5764 		(void *)&cmd_setpromisc_portnum,
5765 		(void *)&cmd_setpromisc_mode,
5766 		NULL,
5767 	},
5768 };
5769 
5770 /* *** SET ALLMULTI MODE *** */
5771 struct cmd_set_allmulti_mode_result {
5772 	cmdline_fixed_string_t set;
5773 	cmdline_fixed_string_t allmulti;
5774 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5775 	uint16_t port_num;               /* valid if "allports" argument == 0 */
5776 	cmdline_fixed_string_t mode;
5777 };
5778 
5779 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5780 					__rte_unused struct cmdline *cl,
5781 					void *allports)
5782 {
5783 	struct cmd_set_allmulti_mode_result *res = parsed_result;
5784 	int enable;
5785 	portid_t i;
5786 
5787 	if (!strcmp(res->mode, "on"))
5788 		enable = 1;
5789 	else
5790 		enable = 0;
5791 
5792 	/* all ports */
5793 	if (allports) {
5794 		RTE_ETH_FOREACH_DEV(i) {
5795 			eth_set_allmulticast_mode(i, enable);
5796 		}
5797 	}
5798 	else {
5799 		eth_set_allmulticast_mode(res->port_num, enable);
5800 	}
5801 }
5802 
5803 static cmdline_parse_token_string_t cmd_setallmulti_set =
5804 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5805 static cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5806 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5807 				 "allmulti");
5808 static cmdline_parse_token_string_t cmd_setallmulti_portall =
5809 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5810 				 "all");
5811 static cmdline_parse_token_num_t cmd_setallmulti_portnum =
5812 	TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5813 			      RTE_UINT16);
5814 static cmdline_parse_token_string_t cmd_setallmulti_mode =
5815 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5816 				 "on#off");
5817 
5818 static cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5819 	.f = cmd_set_allmulti_mode_parsed,
5820 	.data = (void *)1,
5821 	.help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5822 	.tokens = {
5823 		(void *)&cmd_setallmulti_set,
5824 		(void *)&cmd_setallmulti_allmulti,
5825 		(void *)&cmd_setallmulti_portall,
5826 		(void *)&cmd_setallmulti_mode,
5827 		NULL,
5828 	},
5829 };
5830 
5831 static cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5832 	.f = cmd_set_allmulti_mode_parsed,
5833 	.data = (void *)0,
5834 	.help_str = "set allmulti <port_id> on|off: "
5835 		"Set allmulti mode on port_id",
5836 	.tokens = {
5837 		(void *)&cmd_setallmulti_set,
5838 		(void *)&cmd_setallmulti_allmulti,
5839 		(void *)&cmd_setallmulti_portnum,
5840 		(void *)&cmd_setallmulti_mode,
5841 		NULL,
5842 	},
5843 };
5844 
5845 /* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */
5846 struct cmd_link_flow_ctrl_show {
5847 	cmdline_fixed_string_t show;
5848 	cmdline_fixed_string_t port;
5849 	portid_t port_id;
5850 	cmdline_fixed_string_t flow_ctrl;
5851 };
5852 
5853 static cmdline_parse_token_string_t cmd_lfc_show_show =
5854 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
5855 				show, "show");
5856 static cmdline_parse_token_string_t cmd_lfc_show_port =
5857 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
5858 				port, "port");
5859 static cmdline_parse_token_num_t cmd_lfc_show_portid =
5860 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show,
5861 				port_id, RTE_UINT16);
5862 static cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl =
5863 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
5864 				flow_ctrl, "flow_ctrl");
5865 
5866 static void
5867 cmd_link_flow_ctrl_show_parsed(void *parsed_result,
5868 			      __rte_unused struct cmdline *cl,
5869 			      __rte_unused void *data)
5870 {
5871 	struct cmd_link_flow_ctrl_show *res = parsed_result;
5872 	static const char *info_border = "*********************";
5873 	struct rte_eth_fc_conf fc_conf;
5874 	bool rx_fc_en = false;
5875 	bool tx_fc_en = false;
5876 	int ret;
5877 
5878 	ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5879 	if (ret != 0) {
5880 		fprintf(stderr,
5881 			"Failed to get current flow ctrl information: err = %d\n",
5882 			ret);
5883 		return;
5884 	}
5885 
5886 	if (fc_conf.mode == RTE_ETH_FC_RX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
5887 		rx_fc_en = true;
5888 	if (fc_conf.mode == RTE_ETH_FC_TX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
5889 		tx_fc_en = true;
5890 
5891 	printf("\n%s Flow control infos for port %-2d %s\n",
5892 		info_border, res->port_id, info_border);
5893 	printf("FC mode:\n");
5894 	printf("   Rx pause: %s\n", rx_fc_en ? "on" : "off");
5895 	printf("   Tx pause: %s\n", tx_fc_en ? "on" : "off");
5896 	printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off");
5897 	printf("Pause time: 0x%x\n", fc_conf.pause_time);
5898 	printf("High waterline: 0x%x\n", fc_conf.high_water);
5899 	printf("Low waterline: 0x%x\n", fc_conf.low_water);
5900 	printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off");
5901 	printf("Forward MAC control frames: %s\n",
5902 		fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
5903 	printf("\n%s**************   End  ***********%s\n",
5904 		info_border, info_border);
5905 }
5906 
5907 static cmdline_parse_inst_t cmd_link_flow_control_show = {
5908 	.f = cmd_link_flow_ctrl_show_parsed,
5909 	.data = NULL,
5910 	.help_str = "show port <port_id> flow_ctrl",
5911 	.tokens = {
5912 		(void *)&cmd_lfc_show_show,
5913 		(void *)&cmd_lfc_show_port,
5914 		(void *)&cmd_lfc_show_portid,
5915 		(void *)&cmd_lfc_show_flow_ctrl,
5916 		NULL,
5917 	},
5918 };
5919 
5920 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5921 struct cmd_link_flow_ctrl_set_result {
5922 	cmdline_fixed_string_t set;
5923 	cmdline_fixed_string_t flow_ctrl;
5924 	cmdline_fixed_string_t rx;
5925 	cmdline_fixed_string_t rx_lfc_mode;
5926 	cmdline_fixed_string_t tx;
5927 	cmdline_fixed_string_t tx_lfc_mode;
5928 	cmdline_fixed_string_t mac_ctrl_frame_fwd;
5929 	cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5930 	cmdline_fixed_string_t autoneg_str;
5931 	cmdline_fixed_string_t autoneg;
5932 	cmdline_fixed_string_t hw_str;
5933 	uint32_t high_water;
5934 	cmdline_fixed_string_t lw_str;
5935 	uint32_t low_water;
5936 	cmdline_fixed_string_t pt_str;
5937 	uint16_t pause_time;
5938 	cmdline_fixed_string_t xon_str;
5939 	uint16_t send_xon;
5940 	portid_t port_id;
5941 };
5942 
5943 static cmdline_parse_token_string_t cmd_lfc_set_set =
5944 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5945 				set, "set");
5946 static cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5947 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5948 				flow_ctrl, "flow_ctrl");
5949 static cmdline_parse_token_string_t cmd_lfc_set_rx =
5950 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5951 				rx, "rx");
5952 static cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5953 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5954 				rx_lfc_mode, "on#off");
5955 static cmdline_parse_token_string_t cmd_lfc_set_tx =
5956 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5957 				tx, "tx");
5958 static cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5959 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5960 				tx_lfc_mode, "on#off");
5961 static cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5962 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5963 				hw_str, "high_water");
5964 static cmdline_parse_token_num_t cmd_lfc_set_high_water =
5965 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5966 				high_water, RTE_UINT32);
5967 static cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5968 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5969 				lw_str, "low_water");
5970 static cmdline_parse_token_num_t cmd_lfc_set_low_water =
5971 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5972 				low_water, RTE_UINT32);
5973 static cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5974 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5975 				pt_str, "pause_time");
5976 static cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5977 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5978 				pause_time, RTE_UINT16);
5979 static cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5980 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5981 				xon_str, "send_xon");
5982 static cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5983 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5984 				send_xon, RTE_UINT16);
5985 static cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5986 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5987 				mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5988 static cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5989 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5990 				mac_ctrl_frame_fwd_mode, "on#off");
5991 static cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5992 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5993 				autoneg_str, "autoneg");
5994 static cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5995 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5996 				autoneg, "on#off");
5997 static cmdline_parse_token_num_t cmd_lfc_set_portid =
5998 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5999 				port_id, RTE_UINT16);
6000 
6001 /* forward declaration */
6002 static void
6003 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6004 			      void *data);
6005 
6006 static cmdline_parse_inst_t cmd_link_flow_control_set = {
6007 	.f = cmd_link_flow_ctrl_set_parsed,
6008 	.data = NULL,
6009 	.help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6010 		"<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6011 		"autoneg on|off <port_id>: Configure the Ethernet flow control",
6012 	.tokens = {
6013 		(void *)&cmd_lfc_set_set,
6014 		(void *)&cmd_lfc_set_flow_ctrl,
6015 		(void *)&cmd_lfc_set_rx,
6016 		(void *)&cmd_lfc_set_rx_mode,
6017 		(void *)&cmd_lfc_set_tx,
6018 		(void *)&cmd_lfc_set_tx_mode,
6019 		(void *)&cmd_lfc_set_high_water,
6020 		(void *)&cmd_lfc_set_low_water,
6021 		(void *)&cmd_lfc_set_pause_time,
6022 		(void *)&cmd_lfc_set_send_xon,
6023 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6024 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6025 		(void *)&cmd_lfc_set_autoneg_str,
6026 		(void *)&cmd_lfc_set_autoneg,
6027 		(void *)&cmd_lfc_set_portid,
6028 		NULL,
6029 	},
6030 };
6031 
6032 static cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6033 	.f = cmd_link_flow_ctrl_set_parsed,
6034 	.data = (void *)&cmd_link_flow_control_set_rx,
6035 	.help_str = "set flow_ctrl rx on|off <port_id>: "
6036 		"Change rx flow control parameter",
6037 	.tokens = {
6038 		(void *)&cmd_lfc_set_set,
6039 		(void *)&cmd_lfc_set_flow_ctrl,
6040 		(void *)&cmd_lfc_set_rx,
6041 		(void *)&cmd_lfc_set_rx_mode,
6042 		(void *)&cmd_lfc_set_portid,
6043 		NULL,
6044 	},
6045 };
6046 
6047 static cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6048 	.f = cmd_link_flow_ctrl_set_parsed,
6049 	.data = (void *)&cmd_link_flow_control_set_tx,
6050 	.help_str = "set flow_ctrl tx on|off <port_id>: "
6051 		"Change tx flow control parameter",
6052 	.tokens = {
6053 		(void *)&cmd_lfc_set_set,
6054 		(void *)&cmd_lfc_set_flow_ctrl,
6055 		(void *)&cmd_lfc_set_tx,
6056 		(void *)&cmd_lfc_set_tx_mode,
6057 		(void *)&cmd_lfc_set_portid,
6058 		NULL,
6059 	},
6060 };
6061 
6062 static cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6063 	.f = cmd_link_flow_ctrl_set_parsed,
6064 	.data = (void *)&cmd_link_flow_control_set_hw,
6065 	.help_str = "set flow_ctrl high_water <value> <port_id>: "
6066 		"Change high water flow control parameter",
6067 	.tokens = {
6068 		(void *)&cmd_lfc_set_set,
6069 		(void *)&cmd_lfc_set_flow_ctrl,
6070 		(void *)&cmd_lfc_set_high_water_str,
6071 		(void *)&cmd_lfc_set_high_water,
6072 		(void *)&cmd_lfc_set_portid,
6073 		NULL,
6074 	},
6075 };
6076 
6077 static cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6078 	.f = cmd_link_flow_ctrl_set_parsed,
6079 	.data = (void *)&cmd_link_flow_control_set_lw,
6080 	.help_str = "set flow_ctrl low_water <value> <port_id>: "
6081 		"Change low water flow control parameter",
6082 	.tokens = {
6083 		(void *)&cmd_lfc_set_set,
6084 		(void *)&cmd_lfc_set_flow_ctrl,
6085 		(void *)&cmd_lfc_set_low_water_str,
6086 		(void *)&cmd_lfc_set_low_water,
6087 		(void *)&cmd_lfc_set_portid,
6088 		NULL,
6089 	},
6090 };
6091 
6092 static cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6093 	.f = cmd_link_flow_ctrl_set_parsed,
6094 	.data = (void *)&cmd_link_flow_control_set_pt,
6095 	.help_str = "set flow_ctrl pause_time <value> <port_id>: "
6096 		"Change pause time flow control parameter",
6097 	.tokens = {
6098 		(void *)&cmd_lfc_set_set,
6099 		(void *)&cmd_lfc_set_flow_ctrl,
6100 		(void *)&cmd_lfc_set_pause_time_str,
6101 		(void *)&cmd_lfc_set_pause_time,
6102 		(void *)&cmd_lfc_set_portid,
6103 		NULL,
6104 	},
6105 };
6106 
6107 static cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6108 	.f = cmd_link_flow_ctrl_set_parsed,
6109 	.data = (void *)&cmd_link_flow_control_set_xon,
6110 	.help_str = "set flow_ctrl send_xon <value> <port_id>: "
6111 		"Change send_xon flow control parameter",
6112 	.tokens = {
6113 		(void *)&cmd_lfc_set_set,
6114 		(void *)&cmd_lfc_set_flow_ctrl,
6115 		(void *)&cmd_lfc_set_send_xon_str,
6116 		(void *)&cmd_lfc_set_send_xon,
6117 		(void *)&cmd_lfc_set_portid,
6118 		NULL,
6119 	},
6120 };
6121 
6122 static cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6123 	.f = cmd_link_flow_ctrl_set_parsed,
6124 	.data = (void *)&cmd_link_flow_control_set_macfwd,
6125 	.help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6126 		"Change mac ctrl fwd flow control parameter",
6127 	.tokens = {
6128 		(void *)&cmd_lfc_set_set,
6129 		(void *)&cmd_lfc_set_flow_ctrl,
6130 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6131 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6132 		(void *)&cmd_lfc_set_portid,
6133 		NULL,
6134 	},
6135 };
6136 
6137 static cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6138 	.f = cmd_link_flow_ctrl_set_parsed,
6139 	.data = (void *)&cmd_link_flow_control_set_autoneg,
6140 	.help_str = "set flow_ctrl autoneg on|off <port_id>: "
6141 		"Change autoneg flow control parameter",
6142 	.tokens = {
6143 		(void *)&cmd_lfc_set_set,
6144 		(void *)&cmd_lfc_set_flow_ctrl,
6145 		(void *)&cmd_lfc_set_autoneg_str,
6146 		(void *)&cmd_lfc_set_autoneg,
6147 		(void *)&cmd_lfc_set_portid,
6148 		NULL,
6149 	},
6150 };
6151 
6152 static void
6153 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6154 			      __rte_unused struct cmdline *cl,
6155 			      void *data)
6156 {
6157 	struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6158 	cmdline_parse_inst_t *cmd = data;
6159 	struct rte_eth_fc_conf fc_conf;
6160 	int rx_fc_en = 0;
6161 	int tx_fc_en = 0;
6162 	int ret;
6163 
6164 	/*
6165 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6166 	 * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6167 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6168 	 * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6169 	 */
6170 	static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6171 			{RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
6172 	};
6173 
6174 	/* Partial command line, retrieve current configuration */
6175 	if (cmd) {
6176 		ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6177 		if (ret != 0) {
6178 			fprintf(stderr,
6179 				"cannot get current flow ctrl parameters, return code = %d\n",
6180 				ret);
6181 			return;
6182 		}
6183 
6184 		if ((fc_conf.mode == RTE_ETH_FC_RX_PAUSE) ||
6185 		    (fc_conf.mode == RTE_ETH_FC_FULL))
6186 			rx_fc_en = 1;
6187 		if ((fc_conf.mode == RTE_ETH_FC_TX_PAUSE) ||
6188 		    (fc_conf.mode == RTE_ETH_FC_FULL))
6189 			tx_fc_en = 1;
6190 	}
6191 
6192 	if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6193 		rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6194 
6195 	if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6196 		tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6197 
6198 	fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6199 
6200 	if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6201 		fc_conf.high_water = res->high_water;
6202 
6203 	if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6204 		fc_conf.low_water = res->low_water;
6205 
6206 	if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6207 		fc_conf.pause_time = res->pause_time;
6208 
6209 	if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6210 		fc_conf.send_xon = res->send_xon;
6211 
6212 	if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6213 		if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6214 			fc_conf.mac_ctrl_frame_fwd = 1;
6215 		else
6216 			fc_conf.mac_ctrl_frame_fwd = 0;
6217 	}
6218 
6219 	if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6220 		fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6221 
6222 	ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6223 	if (ret != 0)
6224 		fprintf(stderr,
6225 			"bad flow control parameter, return code = %d\n",
6226 			ret);
6227 }
6228 
6229 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6230 struct cmd_priority_flow_ctrl_set_result {
6231 	cmdline_fixed_string_t set;
6232 	cmdline_fixed_string_t pfc_ctrl;
6233 	cmdline_fixed_string_t rx;
6234 	cmdline_fixed_string_t rx_pfc_mode;
6235 	cmdline_fixed_string_t tx;
6236 	cmdline_fixed_string_t tx_pfc_mode;
6237 	uint32_t high_water;
6238 	uint32_t low_water;
6239 	uint16_t pause_time;
6240 	uint8_t  priority;
6241 	portid_t port_id;
6242 };
6243 
6244 static void
6245 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6246 		       __rte_unused struct cmdline *cl,
6247 		       __rte_unused void *data)
6248 {
6249 	struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6250 	struct rte_eth_pfc_conf pfc_conf;
6251 	int rx_fc_enable, tx_fc_enable;
6252 	int ret;
6253 
6254 	/*
6255 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6256 	 * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6257 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6258 	 * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6259 	 */
6260 	static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6261 		{RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
6262 	};
6263 
6264 	memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
6265 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6266 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6267 	pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6268 	pfc_conf.fc.high_water = res->high_water;
6269 	pfc_conf.fc.low_water  = res->low_water;
6270 	pfc_conf.fc.pause_time = res->pause_time;
6271 	pfc_conf.priority      = res->priority;
6272 
6273 	ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6274 	if (ret != 0)
6275 		fprintf(stderr,
6276 			"bad priority flow control parameter, return code = %d\n",
6277 			ret);
6278 }
6279 
6280 static cmdline_parse_token_string_t cmd_pfc_set_set =
6281 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6282 				set, "set");
6283 static cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6284 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6285 				pfc_ctrl, "pfc_ctrl");
6286 static cmdline_parse_token_string_t cmd_pfc_set_rx =
6287 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6288 				rx, "rx");
6289 static cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6290 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6291 				rx_pfc_mode, "on#off");
6292 static cmdline_parse_token_string_t cmd_pfc_set_tx =
6293 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6294 				tx, "tx");
6295 static cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6296 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6297 				tx_pfc_mode, "on#off");
6298 static cmdline_parse_token_num_t cmd_pfc_set_high_water =
6299 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6300 				high_water, RTE_UINT32);
6301 static cmdline_parse_token_num_t cmd_pfc_set_low_water =
6302 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6303 				low_water, RTE_UINT32);
6304 static cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6305 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6306 				pause_time, RTE_UINT16);
6307 static cmdline_parse_token_num_t cmd_pfc_set_priority =
6308 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6309 				priority, RTE_UINT8);
6310 static cmdline_parse_token_num_t cmd_pfc_set_portid =
6311 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6312 				port_id, RTE_UINT16);
6313 
6314 static cmdline_parse_inst_t cmd_priority_flow_control_set = {
6315 	.f = cmd_priority_flow_ctrl_set_parsed,
6316 	.data = NULL,
6317 	.help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6318 		"<pause_time> <priority> <port_id>: "
6319 		"Configure the Ethernet priority flow control",
6320 	.tokens = {
6321 		(void *)&cmd_pfc_set_set,
6322 		(void *)&cmd_pfc_set_flow_ctrl,
6323 		(void *)&cmd_pfc_set_rx,
6324 		(void *)&cmd_pfc_set_rx_mode,
6325 		(void *)&cmd_pfc_set_tx,
6326 		(void *)&cmd_pfc_set_tx_mode,
6327 		(void *)&cmd_pfc_set_high_water,
6328 		(void *)&cmd_pfc_set_low_water,
6329 		(void *)&cmd_pfc_set_pause_time,
6330 		(void *)&cmd_pfc_set_priority,
6331 		(void *)&cmd_pfc_set_portid,
6332 		NULL,
6333 	},
6334 };
6335 
6336 struct cmd_queue_priority_flow_ctrl_set_result {
6337 	cmdline_fixed_string_t set;
6338 	cmdline_fixed_string_t pfc_queue_ctrl;
6339 	portid_t port_id;
6340 	cmdline_fixed_string_t rx;
6341 	cmdline_fixed_string_t rx_pfc_mode;
6342 	uint16_t tx_qid;
6343 	uint8_t  tx_tc;
6344 	cmdline_fixed_string_t tx;
6345 	cmdline_fixed_string_t tx_pfc_mode;
6346 	uint16_t rx_qid;
6347 	uint8_t  rx_tc;
6348 	uint16_t pause_time;
6349 };
6350 
6351 static void
6352 cmd_queue_priority_flow_ctrl_set_parsed(void *parsed_result,
6353 					__rte_unused struct cmdline *cl,
6354 					__rte_unused void *data)
6355 {
6356 	struct cmd_queue_priority_flow_ctrl_set_result *res = parsed_result;
6357 	struct rte_eth_pfc_queue_conf pfc_queue_conf;
6358 	int rx_fc_enable, tx_fc_enable;
6359 	int ret;
6360 
6361 	/*
6362 	 * Rx on/off, flow control is enabled/disabled on RX side. This can
6363 	 * indicate the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx
6364 	 * side. Tx on/off, flow control is enabled/disabled on TX side. This
6365 	 * can indicate the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at
6366 	 * the Tx side.
6367 	 */
6368 	static enum rte_eth_fc_mode rx_tx_onoff_2_mode[2][2] = {
6369 		{RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE},
6370 		{RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
6371 	};
6372 
6373 	memset(&pfc_queue_conf, 0, sizeof(struct rte_eth_pfc_queue_conf));
6374 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on", 2)) ? 1 : 0;
6375 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on", 2)) ? 1 : 0;
6376 	pfc_queue_conf.mode = rx_tx_onoff_2_mode[rx_fc_enable][tx_fc_enable];
6377 	pfc_queue_conf.rx_pause.tc  = res->tx_tc;
6378 	pfc_queue_conf.rx_pause.tx_qid = res->tx_qid;
6379 	pfc_queue_conf.tx_pause.tc  = res->rx_tc;
6380 	pfc_queue_conf.tx_pause.rx_qid  = res->rx_qid;
6381 	pfc_queue_conf.tx_pause.pause_time = res->pause_time;
6382 
6383 	ret = rte_eth_dev_priority_flow_ctrl_queue_configure(res->port_id,
6384 							     &pfc_queue_conf);
6385 	if (ret != 0) {
6386 		fprintf(stderr,
6387 			"bad queue priority flow control parameter, rc = %d\n",
6388 			ret);
6389 	}
6390 }
6391 
6392 static cmdline_parse_token_string_t cmd_q_pfc_set_set =
6393 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
6394 				set, "set");
6395 static cmdline_parse_token_string_t cmd_q_pfc_set_flow_ctrl =
6396 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
6397 				pfc_queue_ctrl, "pfc_queue_ctrl");
6398 static cmdline_parse_token_num_t cmd_q_pfc_set_portid =
6399 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
6400 				port_id, RTE_UINT16);
6401 static cmdline_parse_token_string_t cmd_q_pfc_set_rx =
6402 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
6403 				rx, "rx");
6404 static cmdline_parse_token_string_t cmd_q_pfc_set_rx_mode =
6405 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
6406 				rx_pfc_mode, "on#off");
6407 static cmdline_parse_token_num_t cmd_q_pfc_set_tx_qid =
6408 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
6409 				tx_qid, RTE_UINT16);
6410 static cmdline_parse_token_num_t cmd_q_pfc_set_tx_tc =
6411 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
6412 				tx_tc, RTE_UINT8);
6413 static cmdline_parse_token_string_t cmd_q_pfc_set_tx =
6414 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
6415 				tx, "tx");
6416 static cmdline_parse_token_string_t cmd_q_pfc_set_tx_mode =
6417 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
6418 				tx_pfc_mode, "on#off");
6419 static cmdline_parse_token_num_t cmd_q_pfc_set_rx_qid =
6420 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
6421 				rx_qid, RTE_UINT16);
6422 static cmdline_parse_token_num_t cmd_q_pfc_set_rx_tc =
6423 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
6424 				rx_tc, RTE_UINT8);
6425 static cmdline_parse_token_num_t cmd_q_pfc_set_pause_time =
6426 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
6427 				pause_time, RTE_UINT16);
6428 
6429 static cmdline_parse_inst_t cmd_queue_priority_flow_control_set = {
6430 	.f = cmd_queue_priority_flow_ctrl_set_parsed,
6431 	.data = NULL,
6432 	.help_str = "set pfc_queue_ctrl <port_id> rx <on|off> <tx_qid> <tx_tc> "
6433 		"tx <on|off> <rx_qid> <rx_tc> <pause_time>: "
6434 		"Configure the Ethernet queue priority flow control",
6435 	.tokens = {
6436 		(void *)&cmd_q_pfc_set_set,
6437 		(void *)&cmd_q_pfc_set_flow_ctrl,
6438 		(void *)&cmd_q_pfc_set_portid,
6439 		(void *)&cmd_q_pfc_set_rx,
6440 		(void *)&cmd_q_pfc_set_rx_mode,
6441 		(void *)&cmd_q_pfc_set_tx_qid,
6442 		(void *)&cmd_q_pfc_set_tx_tc,
6443 		(void *)&cmd_q_pfc_set_tx,
6444 		(void *)&cmd_q_pfc_set_tx_mode,
6445 		(void *)&cmd_q_pfc_set_rx_qid,
6446 		(void *)&cmd_q_pfc_set_rx_tc,
6447 		(void *)&cmd_q_pfc_set_pause_time,
6448 		NULL,
6449 	},
6450 };
6451 
6452 /* *** RESET CONFIGURATION *** */
6453 struct cmd_reset_result {
6454 	cmdline_fixed_string_t reset;
6455 	cmdline_fixed_string_t def;
6456 };
6457 
6458 static void cmd_reset_parsed(__rte_unused void *parsed_result,
6459 			     struct cmdline *cl,
6460 			     __rte_unused void *data)
6461 {
6462 	cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6463 	set_def_fwd_config();
6464 }
6465 
6466 static cmdline_parse_token_string_t cmd_reset_set =
6467 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6468 static cmdline_parse_token_string_t cmd_reset_def =
6469 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6470 				 "default");
6471 
6472 static cmdline_parse_inst_t cmd_reset = {
6473 	.f = cmd_reset_parsed,
6474 	.data = NULL,
6475 	.help_str = "set default: Reset default forwarding configuration",
6476 	.tokens = {
6477 		(void *)&cmd_reset_set,
6478 		(void *)&cmd_reset_def,
6479 		NULL,
6480 	},
6481 };
6482 
6483 /* *** START FORWARDING *** */
6484 struct cmd_start_result {
6485 	cmdline_fixed_string_t start;
6486 };
6487 
6488 static cmdline_parse_token_string_t cmd_start_start =
6489 	TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6490 
6491 static void cmd_start_parsed(__rte_unused void *parsed_result,
6492 			     __rte_unused struct cmdline *cl,
6493 			     __rte_unused void *data)
6494 {
6495 	start_packet_forwarding(0);
6496 }
6497 
6498 static cmdline_parse_inst_t cmd_start = {
6499 	.f = cmd_start_parsed,
6500 	.data = NULL,
6501 	.help_str = "start: Start packet forwarding",
6502 	.tokens = {
6503 		(void *)&cmd_start_start,
6504 		NULL,
6505 	},
6506 };
6507 
6508 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6509 struct cmd_start_tx_first_result {
6510 	cmdline_fixed_string_t start;
6511 	cmdline_fixed_string_t tx_first;
6512 };
6513 
6514 static void
6515 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
6516 			  __rte_unused struct cmdline *cl,
6517 			  __rte_unused void *data)
6518 {
6519 	start_packet_forwarding(1);
6520 }
6521 
6522 static cmdline_parse_token_string_t cmd_start_tx_first_start =
6523 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6524 				 "start");
6525 static cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6526 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6527 				 tx_first, "tx_first");
6528 
6529 static cmdline_parse_inst_t cmd_start_tx_first = {
6530 	.f = cmd_start_tx_first_parsed,
6531 	.data = NULL,
6532 	.help_str = "start tx_first: Start packet forwarding, "
6533 		"after sending 1 burst of packets",
6534 	.tokens = {
6535 		(void *)&cmd_start_tx_first_start,
6536 		(void *)&cmd_start_tx_first_tx_first,
6537 		NULL,
6538 	},
6539 };
6540 
6541 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6542 struct cmd_start_tx_first_n_result {
6543 	cmdline_fixed_string_t start;
6544 	cmdline_fixed_string_t tx_first;
6545 	uint32_t tx_num;
6546 };
6547 
6548 static void
6549 cmd_start_tx_first_n_parsed(void *parsed_result,
6550 			  __rte_unused struct cmdline *cl,
6551 			  __rte_unused void *data)
6552 {
6553 	struct cmd_start_tx_first_n_result *res = parsed_result;
6554 
6555 	start_packet_forwarding(res->tx_num);
6556 }
6557 
6558 static cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6559 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6560 			start, "start");
6561 static cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6562 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6563 			tx_first, "tx_first");
6564 static cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6565 	TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6566 			tx_num, RTE_UINT32);
6567 
6568 static cmdline_parse_inst_t cmd_start_tx_first_n = {
6569 	.f = cmd_start_tx_first_n_parsed,
6570 	.data = NULL,
6571 	.help_str = "start tx_first <num>: "
6572 		"packet forwarding, after sending <num> bursts of packets",
6573 	.tokens = {
6574 		(void *)&cmd_start_tx_first_n_start,
6575 		(void *)&cmd_start_tx_first_n_tx_first,
6576 		(void *)&cmd_start_tx_first_n_tx_num,
6577 		NULL,
6578 	},
6579 };
6580 
6581 /* *** SET LINK UP *** */
6582 struct cmd_set_link_up_result {
6583 	cmdline_fixed_string_t set;
6584 	cmdline_fixed_string_t link_up;
6585 	cmdline_fixed_string_t port;
6586 	portid_t port_id;
6587 };
6588 
6589 static cmdline_parse_token_string_t cmd_set_link_up_set =
6590 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6591 static cmdline_parse_token_string_t cmd_set_link_up_link_up =
6592 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6593 				"link-up");
6594 static cmdline_parse_token_string_t cmd_set_link_up_port =
6595 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6596 static cmdline_parse_token_num_t cmd_set_link_up_port_id =
6597 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
6598 				RTE_UINT16);
6599 
6600 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
6601 			     __rte_unused struct cmdline *cl,
6602 			     __rte_unused void *data)
6603 {
6604 	struct cmd_set_link_up_result *res = parsed_result;
6605 	dev_set_link_up(res->port_id);
6606 }
6607 
6608 static cmdline_parse_inst_t cmd_set_link_up = {
6609 	.f = cmd_set_link_up_parsed,
6610 	.data = NULL,
6611 	.help_str = "set link-up port <port id>",
6612 	.tokens = {
6613 		(void *)&cmd_set_link_up_set,
6614 		(void *)&cmd_set_link_up_link_up,
6615 		(void *)&cmd_set_link_up_port,
6616 		(void *)&cmd_set_link_up_port_id,
6617 		NULL,
6618 	},
6619 };
6620 
6621 /* *** SET LINK DOWN *** */
6622 struct cmd_set_link_down_result {
6623 	cmdline_fixed_string_t set;
6624 	cmdline_fixed_string_t link_down;
6625 	cmdline_fixed_string_t port;
6626 	portid_t port_id;
6627 };
6628 
6629 static cmdline_parse_token_string_t cmd_set_link_down_set =
6630 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6631 static cmdline_parse_token_string_t cmd_set_link_down_link_down =
6632 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6633 				"link-down");
6634 static cmdline_parse_token_string_t cmd_set_link_down_port =
6635 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6636 static cmdline_parse_token_num_t cmd_set_link_down_port_id =
6637 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
6638 				RTE_UINT16);
6639 
6640 static void cmd_set_link_down_parsed(
6641 				__rte_unused void *parsed_result,
6642 				__rte_unused struct cmdline *cl,
6643 				__rte_unused void *data)
6644 {
6645 	struct cmd_set_link_down_result *res = parsed_result;
6646 	dev_set_link_down(res->port_id);
6647 }
6648 
6649 static cmdline_parse_inst_t cmd_set_link_down = {
6650 	.f = cmd_set_link_down_parsed,
6651 	.data = NULL,
6652 	.help_str = "set link-down port <port id>",
6653 	.tokens = {
6654 		(void *)&cmd_set_link_down_set,
6655 		(void *)&cmd_set_link_down_link_down,
6656 		(void *)&cmd_set_link_down_port,
6657 		(void *)&cmd_set_link_down_port_id,
6658 		NULL,
6659 	},
6660 };
6661 
6662 /* *** SHOW CFG *** */
6663 struct cmd_showcfg_result {
6664 	cmdline_fixed_string_t show;
6665 	cmdline_fixed_string_t cfg;
6666 	cmdline_fixed_string_t what;
6667 };
6668 
6669 static void cmd_showcfg_parsed(void *parsed_result,
6670 			       __rte_unused struct cmdline *cl,
6671 			       __rte_unused void *data)
6672 {
6673 	struct cmd_showcfg_result *res = parsed_result;
6674 	if (!strcmp(res->what, "rxtx"))
6675 		rxtx_config_display();
6676 	else if (!strcmp(res->what, "cores"))
6677 		fwd_lcores_config_display();
6678 	else if (!strcmp(res->what, "fwd"))
6679 		pkt_fwd_config_display(&cur_fwd_config);
6680 	else if (!strcmp(res->what, "rxoffs"))
6681 		show_rx_pkt_offsets();
6682 	else if (!strcmp(res->what, "rxpkts"))
6683 		show_rx_pkt_segments();
6684 	else if (!strcmp(res->what, "rxhdrs"))
6685 		show_rx_pkt_hdrs();
6686 	else if (!strcmp(res->what, "txpkts"))
6687 		show_tx_pkt_segments();
6688 	else if (!strcmp(res->what, "txtimes"))
6689 		show_tx_pkt_times();
6690 }
6691 
6692 static cmdline_parse_token_string_t cmd_showcfg_show =
6693 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6694 static cmdline_parse_token_string_t cmd_showcfg_port =
6695 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6696 static cmdline_parse_token_string_t cmd_showcfg_what =
6697 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6698 				 "rxtx#cores#fwd#rxoffs#rxpkts#rxhdrs#txpkts#txtimes");
6699 
6700 static cmdline_parse_inst_t cmd_showcfg = {
6701 	.f = cmd_showcfg_parsed,
6702 	.data = NULL,
6703 	.help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|rxhdrs|txpkts|txtimes",
6704 	.tokens = {
6705 		(void *)&cmd_showcfg_show,
6706 		(void *)&cmd_showcfg_port,
6707 		(void *)&cmd_showcfg_what,
6708 		NULL,
6709 	},
6710 };
6711 
6712 /* *** SHOW ALL PORT INFO *** */
6713 struct cmd_showportall_result {
6714 	cmdline_fixed_string_t show;
6715 	cmdline_fixed_string_t port;
6716 	cmdline_fixed_string_t what;
6717 	cmdline_fixed_string_t all;
6718 };
6719 
6720 static void cmd_showportall_parsed(void *parsed_result,
6721 				__rte_unused struct cmdline *cl,
6722 				__rte_unused void *data)
6723 {
6724 	portid_t i;
6725 
6726 	struct cmd_showportall_result *res = parsed_result;
6727 	if (!strcmp(res->show, "clear")) {
6728 		if (!strcmp(res->what, "stats"))
6729 			RTE_ETH_FOREACH_DEV(i)
6730 				nic_stats_clear(i);
6731 		else if (!strcmp(res->what, "xstats"))
6732 			RTE_ETH_FOREACH_DEV(i)
6733 				nic_xstats_clear(i);
6734 	} else if (!strcmp(res->what, "info"))
6735 		RTE_ETH_FOREACH_DEV(i)
6736 			port_infos_display(i);
6737 	else if (!strcmp(res->what, "summary")) {
6738 		port_summary_header_display();
6739 		RTE_ETH_FOREACH_DEV(i)
6740 			port_summary_display(i);
6741 	}
6742 	else if (!strcmp(res->what, "stats"))
6743 		RTE_ETH_FOREACH_DEV(i)
6744 			nic_stats_display(i);
6745 	else if (!strcmp(res->what, "xstats"))
6746 		RTE_ETH_FOREACH_DEV(i)
6747 			nic_xstats_display(i);
6748 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
6749 	else if (!strcmp(res->what, "fdir"))
6750 		RTE_ETH_FOREACH_DEV(i)
6751 			fdir_get_infos(i);
6752 #endif
6753 	else if (!strcmp(res->what, "dcb_tc"))
6754 		RTE_ETH_FOREACH_DEV(i)
6755 			port_dcb_info_display(i);
6756 }
6757 
6758 static cmdline_parse_token_string_t cmd_showportall_show =
6759 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6760 				 "show#clear");
6761 static cmdline_parse_token_string_t cmd_showportall_port =
6762 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6763 static cmdline_parse_token_string_t cmd_showportall_what =
6764 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6765 				 "info#summary#stats#xstats#fdir#dcb_tc");
6766 static cmdline_parse_token_string_t cmd_showportall_all =
6767 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6768 static cmdline_parse_inst_t cmd_showportall = {
6769 	.f = cmd_showportall_parsed,
6770 	.data = NULL,
6771 	.help_str = "show|clear port "
6772 		"info|summary|stats|xstats|fdir|dcb_tc all",
6773 	.tokens = {
6774 		(void *)&cmd_showportall_show,
6775 		(void *)&cmd_showportall_port,
6776 		(void *)&cmd_showportall_what,
6777 		(void *)&cmd_showportall_all,
6778 		NULL,
6779 	},
6780 };
6781 
6782 /* *** SHOW PORT INFO *** */
6783 struct cmd_showport_result {
6784 	cmdline_fixed_string_t show;
6785 	cmdline_fixed_string_t port;
6786 	cmdline_fixed_string_t what;
6787 	uint16_t portnum;
6788 };
6789 
6790 static void cmd_showport_parsed(void *parsed_result,
6791 				__rte_unused struct cmdline *cl,
6792 				__rte_unused void *data)
6793 {
6794 	struct cmd_showport_result *res = parsed_result;
6795 	if (!strcmp(res->show, "clear")) {
6796 		if (!strcmp(res->what, "stats"))
6797 			nic_stats_clear(res->portnum);
6798 		else if (!strcmp(res->what, "xstats"))
6799 			nic_xstats_clear(res->portnum);
6800 	} else if (!strcmp(res->what, "info"))
6801 		port_infos_display(res->portnum);
6802 	else if (!strcmp(res->what, "summary")) {
6803 		port_summary_header_display();
6804 		port_summary_display(res->portnum);
6805 	}
6806 	else if (!strcmp(res->what, "stats"))
6807 		nic_stats_display(res->portnum);
6808 	else if (!strcmp(res->what, "xstats"))
6809 		nic_xstats_display(res->portnum);
6810 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
6811 	else if (!strcmp(res->what, "fdir"))
6812 		 fdir_get_infos(res->portnum);
6813 #endif
6814 	else if (!strcmp(res->what, "dcb_tc"))
6815 		port_dcb_info_display(res->portnum);
6816 }
6817 
6818 static cmdline_parse_token_string_t cmd_showport_show =
6819 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6820 				 "show#clear");
6821 static cmdline_parse_token_string_t cmd_showport_port =
6822 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6823 static cmdline_parse_token_string_t cmd_showport_what =
6824 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6825 				 "info#summary#stats#xstats#fdir#dcb_tc");
6826 static cmdline_parse_token_num_t cmd_showport_portnum =
6827 	TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
6828 
6829 static cmdline_parse_inst_t cmd_showport = {
6830 	.f = cmd_showport_parsed,
6831 	.data = NULL,
6832 	.help_str = "show|clear port "
6833 		"info|summary|stats|xstats|fdir|dcb_tc "
6834 		"<port_id>",
6835 	.tokens = {
6836 		(void *)&cmd_showport_show,
6837 		(void *)&cmd_showport_port,
6838 		(void *)&cmd_showport_what,
6839 		(void *)&cmd_showport_portnum,
6840 		NULL,
6841 	},
6842 };
6843 
6844 /* *** show port representors information *** */
6845 struct cmd_representor_info_result {
6846 	cmdline_fixed_string_t cmd_show;
6847 	cmdline_fixed_string_t cmd_port;
6848 	cmdline_fixed_string_t cmd_info;
6849 	cmdline_fixed_string_t cmd_keyword;
6850 	portid_t cmd_pid;
6851 };
6852 
6853 static void
6854 cmd_representor_info_parsed(void *parsed_result,
6855 		__rte_unused struct cmdline *cl,
6856 		__rte_unused void *data)
6857 {
6858 	struct cmd_representor_info_result *res = parsed_result;
6859 	struct rte_eth_representor_info *info;
6860 	struct rte_eth_representor_range *range;
6861 	uint32_t range_diff;
6862 	uint32_t i;
6863 	int ret;
6864 	int num;
6865 
6866 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
6867 		fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
6868 		return;
6869 	}
6870 
6871 	ret = rte_eth_representor_info_get(res->cmd_pid, NULL);
6872 	if (ret < 0) {
6873 		fprintf(stderr,
6874 			"Failed to get the number of representor info ranges for port %hu: %s\n",
6875 			res->cmd_pid, rte_strerror(-ret));
6876 		return;
6877 	}
6878 	num = ret;
6879 
6880 	info = calloc(1, sizeof(*info) + num * sizeof(info->ranges[0]));
6881 	if (info == NULL) {
6882 		fprintf(stderr,
6883 			"Failed to allocate memory for representor info for port %hu\n",
6884 			res->cmd_pid);
6885 		return;
6886 	}
6887 	info->nb_ranges_alloc = num;
6888 
6889 	ret = rte_eth_representor_info_get(res->cmd_pid, info);
6890 	if (ret < 0) {
6891 		fprintf(stderr,
6892 			"Failed to get the representor info for port %hu: %s\n",
6893 			res->cmd_pid, rte_strerror(-ret));
6894 		free(info);
6895 		return;
6896 	}
6897 
6898 	printf("Port controller: %hu\n", info->controller);
6899 	printf("Port PF: %hu\n", info->pf);
6900 
6901 	printf("Ranges: %u\n", info->nb_ranges);
6902 	for (i = 0; i < info->nb_ranges; i++) {
6903 		range = &info->ranges[i];
6904 		range_diff = range->id_end - range->id_base;
6905 
6906 		printf("%u. ", i + 1);
6907 		printf("'%s' ", range->name);
6908 		if (range_diff > 0)
6909 			printf("[%u-%u]: ", range->id_base, range->id_end);
6910 		else
6911 			printf("[%u]: ", range->id_base);
6912 
6913 		printf("Controller %d, PF %d", range->controller, range->pf);
6914 
6915 		switch (range->type) {
6916 		case RTE_ETH_REPRESENTOR_NONE:
6917 			printf(", NONE\n");
6918 			break;
6919 		case RTE_ETH_REPRESENTOR_VF:
6920 			if (range_diff > 0)
6921 				printf(", VF %d..%d\n", range->vf,
6922 				       range->vf + range_diff);
6923 			else
6924 				printf(", VF %d\n", range->vf);
6925 			break;
6926 		case RTE_ETH_REPRESENTOR_SF:
6927 			printf(", SF %d\n", range->sf);
6928 			break;
6929 		case RTE_ETH_REPRESENTOR_PF:
6930 			if (range_diff > 0)
6931 				printf("..%d\n", range->pf + range_diff);
6932 			else
6933 				printf("\n");
6934 			break;
6935 		default:
6936 			printf(", UNKNOWN TYPE %d\n", range->type);
6937 			break;
6938 		}
6939 	}
6940 
6941 	free(info);
6942 }
6943 
6944 static cmdline_parse_token_string_t cmd_representor_info_show =
6945 	TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
6946 			cmd_show, "show");
6947 static cmdline_parse_token_string_t cmd_representor_info_port =
6948 	TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
6949 			cmd_port, "port");
6950 static cmdline_parse_token_string_t cmd_representor_info_info =
6951 	TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
6952 			cmd_info, "info");
6953 static cmdline_parse_token_num_t cmd_representor_info_pid =
6954 	TOKEN_NUM_INITIALIZER(struct cmd_representor_info_result,
6955 			cmd_pid, RTE_UINT16);
6956 static cmdline_parse_token_string_t cmd_representor_info_keyword =
6957 	TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
6958 			cmd_keyword, "representor");
6959 
6960 static cmdline_parse_inst_t cmd_representor_info = {
6961 	.f = cmd_representor_info_parsed,
6962 	.data = NULL,
6963 	.help_str = "show port info <port_id> representor",
6964 	.tokens = {
6965 		(void *)&cmd_representor_info_show,
6966 		(void *)&cmd_representor_info_port,
6967 		(void *)&cmd_representor_info_info,
6968 		(void *)&cmd_representor_info_pid,
6969 		(void *)&cmd_representor_info_keyword,
6970 		NULL,
6971 	},
6972 };
6973 
6974 
6975 /* *** SHOW DEVICE INFO *** */
6976 struct cmd_showdevice_result {
6977 	cmdline_fixed_string_t show;
6978 	cmdline_fixed_string_t device;
6979 	cmdline_fixed_string_t what;
6980 	cmdline_fixed_string_t identifier;
6981 };
6982 
6983 static void cmd_showdevice_parsed(void *parsed_result,
6984 				__rte_unused struct cmdline *cl,
6985 				__rte_unused void *data)
6986 {
6987 	struct cmd_showdevice_result *res = parsed_result;
6988 	if (!strcmp(res->what, "info")) {
6989 		if (!strcmp(res->identifier, "all"))
6990 			device_infos_display(NULL);
6991 		else
6992 			device_infos_display(res->identifier);
6993 	}
6994 }
6995 
6996 static cmdline_parse_token_string_t cmd_showdevice_show =
6997 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
6998 				 "show");
6999 static cmdline_parse_token_string_t cmd_showdevice_device =
7000 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7001 static cmdline_parse_token_string_t cmd_showdevice_what =
7002 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7003 				 "info");
7004 static cmdline_parse_token_string_t cmd_showdevice_identifier =
7005 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7006 			identifier, NULL);
7007 
7008 static cmdline_parse_inst_t cmd_showdevice = {
7009 	.f = cmd_showdevice_parsed,
7010 	.data = NULL,
7011 	.help_str = "show device info <identifier>|all",
7012 	.tokens = {
7013 		(void *)&cmd_showdevice_show,
7014 		(void *)&cmd_showdevice_device,
7015 		(void *)&cmd_showdevice_what,
7016 		(void *)&cmd_showdevice_identifier,
7017 		NULL,
7018 	},
7019 };
7020 
7021 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7022 struct cmd_showeeprom_result {
7023 	cmdline_fixed_string_t show;
7024 	cmdline_fixed_string_t port;
7025 	uint16_t portnum;
7026 	cmdline_fixed_string_t type;
7027 };
7028 
7029 static void cmd_showeeprom_parsed(void *parsed_result,
7030 		__rte_unused struct cmdline *cl,
7031 		__rte_unused void *data)
7032 {
7033 	struct cmd_showeeprom_result *res = parsed_result;
7034 
7035 	if (!strcmp(res->type, "eeprom"))
7036 		port_eeprom_display(res->portnum);
7037 	else if (!strcmp(res->type, "module_eeprom"))
7038 		port_module_eeprom_display(res->portnum);
7039 	else
7040 		fprintf(stderr, "Unknown argument\n");
7041 }
7042 
7043 static cmdline_parse_token_string_t cmd_showeeprom_show =
7044 	TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7045 static cmdline_parse_token_string_t cmd_showeeprom_port =
7046 	TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7047 static cmdline_parse_token_num_t cmd_showeeprom_portnum =
7048 	TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
7049 			RTE_UINT16);
7050 static cmdline_parse_token_string_t cmd_showeeprom_type =
7051 	TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7052 
7053 static cmdline_parse_inst_t cmd_showeeprom = {
7054 	.f = cmd_showeeprom_parsed,
7055 	.data = NULL,
7056 	.help_str = "show port <port_id> module_eeprom|eeprom",
7057 	.tokens = {
7058 		(void *)&cmd_showeeprom_show,
7059 		(void *)&cmd_showeeprom_port,
7060 		(void *)&cmd_showeeprom_portnum,
7061 		(void *)&cmd_showeeprom_type,
7062 		NULL,
7063 	},
7064 };
7065 
7066 /* *** SHOW QUEUE INFO *** */
7067 struct cmd_showqueue_result {
7068 	cmdline_fixed_string_t show;
7069 	cmdline_fixed_string_t type;
7070 	cmdline_fixed_string_t what;
7071 	uint16_t portnum;
7072 	uint16_t queuenum;
7073 };
7074 
7075 static void
7076 cmd_showqueue_parsed(void *parsed_result,
7077 	__rte_unused struct cmdline *cl,
7078 	__rte_unused void *data)
7079 {
7080 	struct cmd_showqueue_result *res = parsed_result;
7081 
7082 	if (!strcmp(res->type, "rxq"))
7083 		rx_queue_infos_display(res->portnum, res->queuenum);
7084 	else if (!strcmp(res->type, "txq"))
7085 		tx_queue_infos_display(res->portnum, res->queuenum);
7086 }
7087 
7088 static cmdline_parse_token_string_t cmd_showqueue_show =
7089 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7090 static cmdline_parse_token_string_t cmd_showqueue_type =
7091 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7092 static cmdline_parse_token_string_t cmd_showqueue_what =
7093 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7094 static cmdline_parse_token_num_t cmd_showqueue_portnum =
7095 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
7096 		RTE_UINT16);
7097 static cmdline_parse_token_num_t cmd_showqueue_queuenum =
7098 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
7099 		RTE_UINT16);
7100 
7101 static cmdline_parse_inst_t cmd_showqueue = {
7102 	.f = cmd_showqueue_parsed,
7103 	.data = NULL,
7104 	.help_str = "show rxq|txq info <port_id> <queue_id>",
7105 	.tokens = {
7106 		(void *)&cmd_showqueue_show,
7107 		(void *)&cmd_showqueue_type,
7108 		(void *)&cmd_showqueue_what,
7109 		(void *)&cmd_showqueue_portnum,
7110 		(void *)&cmd_showqueue_queuenum,
7111 		NULL,
7112 	},
7113 };
7114 
7115 /* show/clear fwd engine statistics */
7116 struct fwd_result {
7117 	cmdline_fixed_string_t action;
7118 	cmdline_fixed_string_t fwd;
7119 	cmdline_fixed_string_t stats;
7120 	cmdline_fixed_string_t all;
7121 };
7122 
7123 static cmdline_parse_token_string_t cmd_fwd_action =
7124 	TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7125 static cmdline_parse_token_string_t cmd_fwd_fwd =
7126 	TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7127 static cmdline_parse_token_string_t cmd_fwd_stats =
7128 	TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7129 static cmdline_parse_token_string_t cmd_fwd_all =
7130 	TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7131 
7132 static void
7133 cmd_showfwdall_parsed(void *parsed_result,
7134 		      __rte_unused struct cmdline *cl,
7135 		      __rte_unused void *data)
7136 {
7137 	struct fwd_result *res = parsed_result;
7138 
7139 	if (!strcmp(res->action, "show"))
7140 		fwd_stats_display();
7141 	else
7142 		fwd_stats_reset();
7143 }
7144 
7145 static cmdline_parse_inst_t cmd_showfwdall = {
7146 	.f = cmd_showfwdall_parsed,
7147 	.data = NULL,
7148 	.help_str = "show|clear fwd stats all",
7149 	.tokens = {
7150 		(void *)&cmd_fwd_action,
7151 		(void *)&cmd_fwd_fwd,
7152 		(void *)&cmd_fwd_stats,
7153 		(void *)&cmd_fwd_all,
7154 		NULL,
7155 	},
7156 };
7157 
7158 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7159 struct cmd_read_rxd_txd_result {
7160 	cmdline_fixed_string_t read;
7161 	cmdline_fixed_string_t rxd_txd;
7162 	portid_t port_id;
7163 	uint16_t queue_id;
7164 	uint16_t desc_id;
7165 };
7166 
7167 static void
7168 cmd_read_rxd_txd_parsed(void *parsed_result,
7169 			__rte_unused struct cmdline *cl,
7170 			__rte_unused void *data)
7171 {
7172 	struct cmd_read_rxd_txd_result *res = parsed_result;
7173 
7174 	if (!strcmp(res->rxd_txd, "rxd"))
7175 		rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7176 	else if (!strcmp(res->rxd_txd, "txd"))
7177 		tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7178 }
7179 
7180 static cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7181 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7182 static cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7183 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7184 				 "rxd#txd");
7185 static cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7186 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
7187 				 RTE_UINT16);
7188 static cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7189 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
7190 				 RTE_UINT16);
7191 static cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7192 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
7193 				 RTE_UINT16);
7194 
7195 static cmdline_parse_inst_t cmd_read_rxd_txd = {
7196 	.f = cmd_read_rxd_txd_parsed,
7197 	.data = NULL,
7198 	.help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7199 	.tokens = {
7200 		(void *)&cmd_read_rxd_txd_read,
7201 		(void *)&cmd_read_rxd_txd_rxd_txd,
7202 		(void *)&cmd_read_rxd_txd_port_id,
7203 		(void *)&cmd_read_rxd_txd_queue_id,
7204 		(void *)&cmd_read_rxd_txd_desc_id,
7205 		NULL,
7206 	},
7207 };
7208 
7209 /* *** QUIT *** */
7210 struct cmd_quit_result {
7211 	cmdline_fixed_string_t quit;
7212 };
7213 
7214 static void cmd_quit_parsed(__rte_unused void *parsed_result,
7215 			    struct cmdline *cl,
7216 			    __rte_unused void *data)
7217 {
7218 	cmdline_quit(cl);
7219 	cl_quit = 1;
7220 }
7221 
7222 static cmdline_parse_token_string_t cmd_quit_quit =
7223 	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7224 
7225 static cmdline_parse_inst_t cmd_quit = {
7226 	.f = cmd_quit_parsed,
7227 	.data = NULL,
7228 	.help_str = "quit: Exit application",
7229 	.tokens = {
7230 		(void *)&cmd_quit_quit,
7231 		NULL,
7232 	},
7233 };
7234 
7235 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7236 struct cmd_mac_addr_result {
7237 	cmdline_fixed_string_t mac_addr_cmd;
7238 	cmdline_fixed_string_t what;
7239 	uint16_t port_num;
7240 	struct rte_ether_addr address;
7241 };
7242 
7243 static void cmd_mac_addr_parsed(void *parsed_result,
7244 		__rte_unused struct cmdline *cl,
7245 		__rte_unused void *data)
7246 {
7247 	struct cmd_mac_addr_result *res = parsed_result;
7248 	int ret;
7249 
7250 	if (strcmp(res->what, "add") == 0)
7251 		ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7252 	else if (strcmp(res->what, "set") == 0)
7253 		ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7254 						       &res->address);
7255 	else
7256 		ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7257 
7258 	/* check the return value and print it if is < 0 */
7259 	if(ret < 0)
7260 		fprintf(stderr, "mac_addr_cmd error: (%s)\n", strerror(-ret));
7261 
7262 }
7263 
7264 static cmdline_parse_token_string_t cmd_mac_addr_cmd =
7265 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7266 				"mac_addr");
7267 static cmdline_parse_token_string_t cmd_mac_addr_what =
7268 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7269 				"add#remove#set");
7270 static cmdline_parse_token_num_t cmd_mac_addr_portnum =
7271 		TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7272 					RTE_UINT16);
7273 static cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7274 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7275 
7276 static cmdline_parse_inst_t cmd_mac_addr = {
7277 	.f = cmd_mac_addr_parsed,
7278 	.data = (void *)0,
7279 	.help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7280 			"Add/Remove/Set MAC address on port_id",
7281 	.tokens = {
7282 		(void *)&cmd_mac_addr_cmd,
7283 		(void *)&cmd_mac_addr_what,
7284 		(void *)&cmd_mac_addr_portnum,
7285 		(void *)&cmd_mac_addr_addr,
7286 		NULL,
7287 	},
7288 };
7289 
7290 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7291 struct cmd_eth_peer_result {
7292 	cmdline_fixed_string_t set;
7293 	cmdline_fixed_string_t eth_peer;
7294 	portid_t port_id;
7295 	cmdline_fixed_string_t peer_addr;
7296 };
7297 
7298 static void cmd_set_eth_peer_parsed(void *parsed_result,
7299 			__rte_unused struct cmdline *cl,
7300 			__rte_unused void *data)
7301 {
7302 		struct cmd_eth_peer_result *res = parsed_result;
7303 
7304 		if (test_done == 0) {
7305 			fprintf(stderr, "Please stop forwarding first\n");
7306 			return;
7307 		}
7308 		if (!strcmp(res->eth_peer, "eth-peer")) {
7309 			set_fwd_eth_peer(res->port_id, res->peer_addr);
7310 			fwd_config_setup();
7311 		}
7312 }
7313 static cmdline_parse_token_string_t cmd_eth_peer_set =
7314 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7315 static cmdline_parse_token_string_t cmd_eth_peer =
7316 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7317 static cmdline_parse_token_num_t cmd_eth_peer_port_id =
7318 	TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
7319 		RTE_UINT16);
7320 static cmdline_parse_token_string_t cmd_eth_peer_addr =
7321 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7322 
7323 static cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7324 	.f = cmd_set_eth_peer_parsed,
7325 	.data = NULL,
7326 	.help_str = "set eth-peer <port_id> <peer_mac>",
7327 	.tokens = {
7328 		(void *)&cmd_eth_peer_set,
7329 		(void *)&cmd_eth_peer,
7330 		(void *)&cmd_eth_peer_port_id,
7331 		(void *)&cmd_eth_peer_addr,
7332 		NULL,
7333 	},
7334 };
7335 
7336 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7337 struct cmd_set_qmap_result {
7338 	cmdline_fixed_string_t set;
7339 	cmdline_fixed_string_t qmap;
7340 	cmdline_fixed_string_t what;
7341 	portid_t port_id;
7342 	uint16_t queue_id;
7343 	uint8_t map_value;
7344 };
7345 
7346 static void
7347 cmd_set_qmap_parsed(void *parsed_result,
7348 		       __rte_unused struct cmdline *cl,
7349 		       __rte_unused void *data)
7350 {
7351 	struct cmd_set_qmap_result *res = parsed_result;
7352 	int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7353 
7354 	set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7355 }
7356 
7357 static cmdline_parse_token_string_t cmd_setqmap_set =
7358 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7359 				 set, "set");
7360 static cmdline_parse_token_string_t cmd_setqmap_qmap =
7361 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7362 				 qmap, "stat_qmap");
7363 static cmdline_parse_token_string_t cmd_setqmap_what =
7364 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7365 				 what, "tx#rx");
7366 static cmdline_parse_token_num_t cmd_setqmap_portid =
7367 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7368 			      port_id, RTE_UINT16);
7369 static cmdline_parse_token_num_t cmd_setqmap_queueid =
7370 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7371 			      queue_id, RTE_UINT16);
7372 static cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7373 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7374 			      map_value, RTE_UINT8);
7375 
7376 static cmdline_parse_inst_t cmd_set_qmap = {
7377 	.f = cmd_set_qmap_parsed,
7378 	.data = NULL,
7379 	.help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7380 		"Set statistics mapping value on tx|rx queue_id of port_id",
7381 	.tokens = {
7382 		(void *)&cmd_setqmap_set,
7383 		(void *)&cmd_setqmap_qmap,
7384 		(void *)&cmd_setqmap_what,
7385 		(void *)&cmd_setqmap_portid,
7386 		(void *)&cmd_setqmap_queueid,
7387 		(void *)&cmd_setqmap_mapvalue,
7388 		NULL,
7389 	},
7390 };
7391 
7392 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7393 struct cmd_set_xstats_hide_zero_result {
7394 	cmdline_fixed_string_t keyword;
7395 	cmdline_fixed_string_t name;
7396 	cmdline_fixed_string_t on_off;
7397 };
7398 
7399 static void
7400 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7401 			__rte_unused struct cmdline *cl,
7402 			__rte_unused void *data)
7403 {
7404 	struct cmd_set_xstats_hide_zero_result *res;
7405 	uint16_t on_off = 0;
7406 
7407 	res = parsed_result;
7408 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7409 	set_xstats_hide_zero(on_off);
7410 }
7411 
7412 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7413 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7414 				 keyword, "set");
7415 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7416 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7417 				 name, "xstats-hide-zero");
7418 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7419 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7420 				 on_off, "on#off");
7421 
7422 static cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7423 	.f = cmd_set_xstats_hide_zero_parsed,
7424 	.data = NULL,
7425 	.help_str = "set xstats-hide-zero on|off",
7426 	.tokens = {
7427 		(void *)&cmd_set_xstats_hide_zero_keyword,
7428 		(void *)&cmd_set_xstats_hide_zero_name,
7429 		(void *)&cmd_set_xstats_hide_zero_on_off,
7430 		NULL,
7431 	},
7432 };
7433 
7434 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
7435 struct cmd_set_record_core_cycles_result {
7436 	cmdline_fixed_string_t keyword;
7437 	cmdline_fixed_string_t name;
7438 	cmdline_fixed_string_t on_off;
7439 };
7440 
7441 static void
7442 cmd_set_record_core_cycles_parsed(void *parsed_result,
7443 			__rte_unused struct cmdline *cl,
7444 			__rte_unused void *data)
7445 {
7446 	struct cmd_set_record_core_cycles_result *res;
7447 	uint16_t on_off = 0;
7448 
7449 	res = parsed_result;
7450 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7451 	set_record_core_cycles(on_off);
7452 }
7453 
7454 static cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
7455 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
7456 				 keyword, "set");
7457 static cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
7458 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
7459 				 name, "record-core-cycles");
7460 static cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
7461 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
7462 				 on_off, "on#off");
7463 
7464 static cmdline_parse_inst_t cmd_set_record_core_cycles = {
7465 	.f = cmd_set_record_core_cycles_parsed,
7466 	.data = NULL,
7467 	.help_str = "set record-core-cycles on|off",
7468 	.tokens = {
7469 		(void *)&cmd_set_record_core_cycles_keyword,
7470 		(void *)&cmd_set_record_core_cycles_name,
7471 		(void *)&cmd_set_record_core_cycles_on_off,
7472 		NULL,
7473 	},
7474 };
7475 
7476 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
7477 struct cmd_set_record_burst_stats_result {
7478 	cmdline_fixed_string_t keyword;
7479 	cmdline_fixed_string_t name;
7480 	cmdline_fixed_string_t on_off;
7481 };
7482 
7483 static void
7484 cmd_set_record_burst_stats_parsed(void *parsed_result,
7485 			__rte_unused struct cmdline *cl,
7486 			__rte_unused void *data)
7487 {
7488 	struct cmd_set_record_burst_stats_result *res;
7489 	uint16_t on_off = 0;
7490 
7491 	res = parsed_result;
7492 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7493 	set_record_burst_stats(on_off);
7494 }
7495 
7496 static cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
7497 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
7498 				 keyword, "set");
7499 static cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
7500 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
7501 				 name, "record-burst-stats");
7502 static cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
7503 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
7504 				 on_off, "on#off");
7505 
7506 static cmdline_parse_inst_t cmd_set_record_burst_stats = {
7507 	.f = cmd_set_record_burst_stats_parsed,
7508 	.data = NULL,
7509 	.help_str = "set record-burst-stats on|off",
7510 	.tokens = {
7511 		(void *)&cmd_set_record_burst_stats_keyword,
7512 		(void *)&cmd_set_record_burst_stats_name,
7513 		(void *)&cmd_set_record_burst_stats_on_off,
7514 		NULL,
7515 	},
7516 };
7517 
7518 /* *** CONFIGURE UNICAST HASH TABLE *** */
7519 struct cmd_set_uc_hash_table {
7520 	cmdline_fixed_string_t set;
7521 	cmdline_fixed_string_t port;
7522 	portid_t port_id;
7523 	cmdline_fixed_string_t what;
7524 	struct rte_ether_addr address;
7525 	cmdline_fixed_string_t mode;
7526 };
7527 
7528 static void
7529 cmd_set_uc_hash_parsed(void *parsed_result,
7530 		       __rte_unused struct cmdline *cl,
7531 		       __rte_unused void *data)
7532 {
7533 	int ret=0;
7534 	struct cmd_set_uc_hash_table *res = parsed_result;
7535 
7536 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7537 
7538 	if (strcmp(res->what, "uta") == 0)
7539 		ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7540 						&res->address,(uint8_t)is_on);
7541 	if (ret < 0)
7542 		fprintf(stderr,
7543 			"bad unicast hash table parameter, return code = %d\n",
7544 			ret);
7545 
7546 }
7547 
7548 static cmdline_parse_token_string_t cmd_set_uc_hash_set =
7549 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7550 				 set, "set");
7551 static cmdline_parse_token_string_t cmd_set_uc_hash_port =
7552 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7553 				 port, "port");
7554 static cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7555 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7556 			      port_id, RTE_UINT16);
7557 static cmdline_parse_token_string_t cmd_set_uc_hash_what =
7558 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7559 				 what, "uta");
7560 static cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7561 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7562 				address);
7563 static cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7564 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7565 				 mode, "on#off");
7566 
7567 static cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7568 	.f = cmd_set_uc_hash_parsed,
7569 	.data = NULL,
7570 	.help_str = "set port <port_id> uta <mac_addr> on|off)",
7571 	.tokens = {
7572 		(void *)&cmd_set_uc_hash_set,
7573 		(void *)&cmd_set_uc_hash_port,
7574 		(void *)&cmd_set_uc_hash_portid,
7575 		(void *)&cmd_set_uc_hash_what,
7576 		(void *)&cmd_set_uc_hash_mac,
7577 		(void *)&cmd_set_uc_hash_mode,
7578 		NULL,
7579 	},
7580 };
7581 
7582 struct cmd_set_uc_all_hash_table {
7583 	cmdline_fixed_string_t set;
7584 	cmdline_fixed_string_t port;
7585 	portid_t port_id;
7586 	cmdline_fixed_string_t what;
7587 	cmdline_fixed_string_t value;
7588 	cmdline_fixed_string_t mode;
7589 };
7590 
7591 static void
7592 cmd_set_uc_all_hash_parsed(void *parsed_result,
7593 		       __rte_unused struct cmdline *cl,
7594 		       __rte_unused void *data)
7595 {
7596 	int ret=0;
7597 	struct cmd_set_uc_all_hash_table *res = parsed_result;
7598 
7599 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7600 
7601 	if ((strcmp(res->what, "uta") == 0) &&
7602 		(strcmp(res->value, "all") == 0))
7603 		ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7604 	if (ret < 0)
7605 		fprintf(stderr,
7606 			"bad unicast hash table parameter, return code = %d\n",
7607 			ret);
7608 }
7609 
7610 static cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7611 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7612 				 set, "set");
7613 static cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7614 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7615 				 port, "port");
7616 static cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7617 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7618 			      port_id, RTE_UINT16);
7619 static cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7620 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7621 				 what, "uta");
7622 static cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7623 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7624 				value,"all");
7625 static cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7626 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7627 				 mode, "on#off");
7628 
7629 static cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7630 	.f = cmd_set_uc_all_hash_parsed,
7631 	.data = NULL,
7632 	.help_str = "set port <port_id> uta all on|off",
7633 	.tokens = {
7634 		(void *)&cmd_set_uc_all_hash_set,
7635 		(void *)&cmd_set_uc_all_hash_port,
7636 		(void *)&cmd_set_uc_all_hash_portid,
7637 		(void *)&cmd_set_uc_all_hash_what,
7638 		(void *)&cmd_set_uc_all_hash_value,
7639 		(void *)&cmd_set_uc_all_hash_mode,
7640 		NULL,
7641 	},
7642 };
7643 
7644 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7645 struct cmd_set_vf_traffic {
7646 	cmdline_fixed_string_t set;
7647 	cmdline_fixed_string_t port;
7648 	portid_t port_id;
7649 	cmdline_fixed_string_t vf;
7650 	uint8_t vf_id;
7651 	cmdline_fixed_string_t what;
7652 	cmdline_fixed_string_t mode;
7653 };
7654 
7655 static void
7656 cmd_set_vf_traffic_parsed(void *parsed_result,
7657 		       __rte_unused struct cmdline *cl,
7658 		       __rte_unused void *data)
7659 {
7660 	struct cmd_set_vf_traffic *res = parsed_result;
7661 	int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7662 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7663 
7664 	set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7665 }
7666 
7667 static cmdline_parse_token_string_t cmd_setvf_traffic_set =
7668 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7669 				 set, "set");
7670 static cmdline_parse_token_string_t cmd_setvf_traffic_port =
7671 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7672 				 port, "port");
7673 static cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7674 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7675 			      port_id, RTE_UINT16);
7676 static cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7677 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7678 				 vf, "vf");
7679 static cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7680 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7681 			      vf_id, RTE_UINT8);
7682 static cmdline_parse_token_string_t cmd_setvf_traffic_what =
7683 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7684 				 what, "tx#rx");
7685 static cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7686 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7687 				 mode, "on#off");
7688 
7689 static cmdline_parse_inst_t cmd_set_vf_traffic = {
7690 	.f = cmd_set_vf_traffic_parsed,
7691 	.data = NULL,
7692 	.help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7693 	.tokens = {
7694 		(void *)&cmd_setvf_traffic_set,
7695 		(void *)&cmd_setvf_traffic_port,
7696 		(void *)&cmd_setvf_traffic_portid,
7697 		(void *)&cmd_setvf_traffic_vf,
7698 		(void *)&cmd_setvf_traffic_vfid,
7699 		(void *)&cmd_setvf_traffic_what,
7700 		(void *)&cmd_setvf_traffic_mode,
7701 		NULL,
7702 	},
7703 };
7704 
7705 /* *** CONFIGURE VF RECEIVE MODE *** */
7706 struct cmd_set_vf_rxmode {
7707 	cmdline_fixed_string_t set;
7708 	cmdline_fixed_string_t port;
7709 	portid_t port_id;
7710 	cmdline_fixed_string_t vf;
7711 	uint8_t vf_id;
7712 	cmdline_fixed_string_t what;
7713 	cmdline_fixed_string_t mode;
7714 	cmdline_fixed_string_t on;
7715 };
7716 
7717 static void
7718 cmd_set_vf_rxmode_parsed(void *parsed_result,
7719 		       __rte_unused struct cmdline *cl,
7720 		       __rte_unused void *data)
7721 {
7722 	int ret = -ENOTSUP;
7723 	uint16_t vf_rxmode = 0;
7724 	struct cmd_set_vf_rxmode *res = parsed_result;
7725 
7726 	int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7727 	if (!strcmp(res->what,"rxmode")) {
7728 		if (!strcmp(res->mode, "AUPE"))
7729 			vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_UNTAG;
7730 		else if (!strcmp(res->mode, "ROPE"))
7731 			vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_HASH_UC;
7732 		else if (!strcmp(res->mode, "BAM"))
7733 			vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_BROADCAST;
7734 		else if (!strncmp(res->mode, "MPE",3))
7735 			vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_MULTICAST;
7736 	}
7737 
7738 	RTE_SET_USED(is_on);
7739 	RTE_SET_USED(vf_rxmode);
7740 
7741 #ifdef RTE_NET_IXGBE
7742 	if (ret == -ENOTSUP)
7743 		ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7744 						  vf_rxmode, (uint8_t)is_on);
7745 #endif
7746 #ifdef RTE_NET_BNXT
7747 	if (ret == -ENOTSUP)
7748 		ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7749 						 vf_rxmode, (uint8_t)is_on);
7750 #endif
7751 	if (ret < 0)
7752 		fprintf(stderr,
7753 			"bad VF receive mode parameter, return code = %d\n",
7754 			ret);
7755 }
7756 
7757 static cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7758 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7759 				 set, "set");
7760 static cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7761 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7762 				 port, "port");
7763 static cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7764 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7765 			      port_id, RTE_UINT16);
7766 static cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7767 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7768 				 vf, "vf");
7769 static cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7770 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7771 			      vf_id, RTE_UINT8);
7772 static cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7773 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7774 				 what, "rxmode");
7775 static cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7776 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7777 				 mode, "AUPE#ROPE#BAM#MPE");
7778 static cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7779 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7780 				 on, "on#off");
7781 
7782 static cmdline_parse_inst_t cmd_set_vf_rxmode = {
7783 	.f = cmd_set_vf_rxmode_parsed,
7784 	.data = NULL,
7785 	.help_str = "set port <port_id> vf <vf_id> rxmode "
7786 		"AUPE|ROPE|BAM|MPE on|off",
7787 	.tokens = {
7788 		(void *)&cmd_set_vf_rxmode_set,
7789 		(void *)&cmd_set_vf_rxmode_port,
7790 		(void *)&cmd_set_vf_rxmode_portid,
7791 		(void *)&cmd_set_vf_rxmode_vf,
7792 		(void *)&cmd_set_vf_rxmode_vfid,
7793 		(void *)&cmd_set_vf_rxmode_what,
7794 		(void *)&cmd_set_vf_rxmode_mode,
7795 		(void *)&cmd_set_vf_rxmode_on,
7796 		NULL,
7797 	},
7798 };
7799 
7800 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7801 struct cmd_vf_mac_addr_result {
7802 	cmdline_fixed_string_t mac_addr_cmd;
7803 	cmdline_fixed_string_t what;
7804 	cmdline_fixed_string_t port;
7805 	uint16_t port_num;
7806 	cmdline_fixed_string_t vf;
7807 	uint8_t vf_num;
7808 	struct rte_ether_addr address;
7809 };
7810 
7811 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7812 		__rte_unused struct cmdline *cl,
7813 		__rte_unused void *data)
7814 {
7815 	struct cmd_vf_mac_addr_result *res = parsed_result;
7816 	int ret = -ENOTSUP;
7817 
7818 	if (strcmp(res->what, "add") != 0)
7819 		return;
7820 
7821 #ifdef RTE_NET_I40E
7822 	if (ret == -ENOTSUP)
7823 		ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7824 						   &res->address);
7825 #endif
7826 #ifdef RTE_NET_BNXT
7827 	if (ret == -ENOTSUP)
7828 		ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7829 						res->vf_num);
7830 #endif
7831 
7832 	if(ret < 0)
7833 		fprintf(stderr, "vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7834 
7835 }
7836 
7837 static cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7838 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7839 				mac_addr_cmd,"mac_addr");
7840 static cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7841 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7842 				what,"add");
7843 static cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7844 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7845 				port,"port");
7846 static cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7847 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7848 				port_num, RTE_UINT16);
7849 static cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7850 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7851 				vf,"vf");
7852 static cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7853 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7854 				vf_num, RTE_UINT8);
7855 static cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7856 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7857 				address);
7858 
7859 static cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7860 	.f = cmd_vf_mac_addr_parsed,
7861 	.data = (void *)0,
7862 	.help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7863 		"Add MAC address filtering for a VF on port_id",
7864 	.tokens = {
7865 		(void *)&cmd_vf_mac_addr_cmd,
7866 		(void *)&cmd_vf_mac_addr_what,
7867 		(void *)&cmd_vf_mac_addr_port,
7868 		(void *)&cmd_vf_mac_addr_portnum,
7869 		(void *)&cmd_vf_mac_addr_vf,
7870 		(void *)&cmd_vf_mac_addr_vfnum,
7871 		(void *)&cmd_vf_mac_addr_addr,
7872 		NULL,
7873 	},
7874 };
7875 
7876 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7877 struct cmd_vf_rx_vlan_filter {
7878 	cmdline_fixed_string_t rx_vlan;
7879 	cmdline_fixed_string_t what;
7880 	uint16_t vlan_id;
7881 	cmdline_fixed_string_t port;
7882 	portid_t port_id;
7883 	cmdline_fixed_string_t vf;
7884 	uint64_t vf_mask;
7885 };
7886 
7887 static void
7888 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7889 			  __rte_unused struct cmdline *cl,
7890 			  __rte_unused void *data)
7891 {
7892 	struct cmd_vf_rx_vlan_filter *res = parsed_result;
7893 	int ret = -ENOTSUP;
7894 
7895 	__rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7896 
7897 #ifdef RTE_NET_IXGBE
7898 	if (ret == -ENOTSUP)
7899 		ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7900 				res->vlan_id, res->vf_mask, is_add);
7901 #endif
7902 #ifdef RTE_NET_I40E
7903 	if (ret == -ENOTSUP)
7904 		ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7905 				res->vlan_id, res->vf_mask, is_add);
7906 #endif
7907 #ifdef RTE_NET_BNXT
7908 	if (ret == -ENOTSUP)
7909 		ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7910 				res->vlan_id, res->vf_mask, is_add);
7911 #endif
7912 
7913 	switch (ret) {
7914 	case 0:
7915 		break;
7916 	case -EINVAL:
7917 		fprintf(stderr, "invalid vlan_id %d or vf_mask %"PRIu64"\n",
7918 			res->vlan_id, res->vf_mask);
7919 		break;
7920 	case -ENODEV:
7921 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
7922 		break;
7923 	case -ENOTSUP:
7924 		fprintf(stderr, "function not implemented or supported\n");
7925 		break;
7926 	default:
7927 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
7928 	}
7929 }
7930 
7931 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7932 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7933 				 rx_vlan, "rx_vlan");
7934 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7935 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7936 				 what, "add#rm");
7937 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7938 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7939 			      vlan_id, RTE_UINT16);
7940 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7941 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7942 				 port, "port");
7943 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7944 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7945 			      port_id, RTE_UINT16);
7946 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7947 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7948 				 vf, "vf");
7949 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7950 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7951 			      vf_mask, RTE_UINT64);
7952 
7953 static cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7954 	.f = cmd_vf_rx_vlan_filter_parsed,
7955 	.data = NULL,
7956 	.help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7957 		"(vf_mask = hexadecimal VF mask)",
7958 	.tokens = {
7959 		(void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7960 		(void *)&cmd_vf_rx_vlan_filter_what,
7961 		(void *)&cmd_vf_rx_vlan_filter_vlanid,
7962 		(void *)&cmd_vf_rx_vlan_filter_port,
7963 		(void *)&cmd_vf_rx_vlan_filter_portid,
7964 		(void *)&cmd_vf_rx_vlan_filter_vf,
7965 		(void *)&cmd_vf_rx_vlan_filter_vf_mask,
7966 		NULL,
7967 	},
7968 };
7969 
7970 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7971 struct cmd_queue_rate_limit_result {
7972 	cmdline_fixed_string_t set;
7973 	cmdline_fixed_string_t port;
7974 	uint16_t port_num;
7975 	cmdline_fixed_string_t queue;
7976 	uint8_t queue_num;
7977 	cmdline_fixed_string_t rate;
7978 	uint32_t rate_num;
7979 };
7980 
7981 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7982 		__rte_unused struct cmdline *cl,
7983 		__rte_unused void *data)
7984 {
7985 	struct cmd_queue_rate_limit_result *res = parsed_result;
7986 	int ret = 0;
7987 
7988 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7989 		&& (strcmp(res->queue, "queue") == 0)
7990 		&& (strcmp(res->rate, "rate") == 0))
7991 		ret = set_queue_rate_limit(res->port_num, res->queue_num,
7992 					res->rate_num);
7993 	if (ret < 0)
7994 		fprintf(stderr, "queue_rate_limit_cmd error: (%s)\n",
7995 			strerror(-ret));
7996 
7997 }
7998 
7999 static cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8000 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8001 				set, "set");
8002 static cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8003 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8004 				port, "port");
8005 static cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8006 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8007 				port_num, RTE_UINT16);
8008 static cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8009 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8010 				queue, "queue");
8011 static cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8012 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8013 				queue_num, RTE_UINT8);
8014 static cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8015 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8016 				rate, "rate");
8017 static cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8018 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8019 				rate_num, RTE_UINT32);
8020 
8021 static cmdline_parse_inst_t cmd_queue_rate_limit = {
8022 	.f = cmd_queue_rate_limit_parsed,
8023 	.data = (void *)0,
8024 	.help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8025 		"Set rate limit for a queue on port_id",
8026 	.tokens = {
8027 		(void *)&cmd_queue_rate_limit_set,
8028 		(void *)&cmd_queue_rate_limit_port,
8029 		(void *)&cmd_queue_rate_limit_portnum,
8030 		(void *)&cmd_queue_rate_limit_queue,
8031 		(void *)&cmd_queue_rate_limit_queuenum,
8032 		(void *)&cmd_queue_rate_limit_rate,
8033 		(void *)&cmd_queue_rate_limit_ratenum,
8034 		NULL,
8035 	},
8036 };
8037 
8038 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8039 struct cmd_vf_rate_limit_result {
8040 	cmdline_fixed_string_t set;
8041 	cmdline_fixed_string_t port;
8042 	uint16_t port_num;
8043 	cmdline_fixed_string_t vf;
8044 	uint8_t vf_num;
8045 	cmdline_fixed_string_t rate;
8046 	uint32_t rate_num;
8047 	cmdline_fixed_string_t q_msk;
8048 	uint64_t q_msk_val;
8049 };
8050 
8051 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8052 		__rte_unused struct cmdline *cl,
8053 		__rte_unused void *data)
8054 {
8055 	struct cmd_vf_rate_limit_result *res = parsed_result;
8056 	int ret = 0;
8057 
8058 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8059 		&& (strcmp(res->vf, "vf") == 0)
8060 		&& (strcmp(res->rate, "rate") == 0)
8061 		&& (strcmp(res->q_msk, "queue_mask") == 0))
8062 		ret = set_vf_rate_limit(res->port_num, res->vf_num,
8063 					res->rate_num, res->q_msk_val);
8064 	if (ret < 0)
8065 		fprintf(stderr, "vf_rate_limit_cmd error: (%s)\n",
8066 			strerror(-ret));
8067 
8068 }
8069 
8070 static cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8071 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8072 				set, "set");
8073 static cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8074 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8075 				port, "port");
8076 static cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8077 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8078 				port_num, RTE_UINT16);
8079 static cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8080 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8081 				vf, "vf");
8082 static cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8083 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8084 				vf_num, RTE_UINT8);
8085 static cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8086 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8087 				rate, "rate");
8088 static cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8089 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8090 				rate_num, RTE_UINT32);
8091 static cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8092 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8093 				q_msk, "queue_mask");
8094 static cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8095 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8096 				q_msk_val, RTE_UINT64);
8097 
8098 static cmdline_parse_inst_t cmd_vf_rate_limit = {
8099 	.f = cmd_vf_rate_limit_parsed,
8100 	.data = (void *)0,
8101 	.help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8102 		"queue_mask <queue_mask_value>: "
8103 		"Set rate limit for queues of VF on port_id",
8104 	.tokens = {
8105 		(void *)&cmd_vf_rate_limit_set,
8106 		(void *)&cmd_vf_rate_limit_port,
8107 		(void *)&cmd_vf_rate_limit_portnum,
8108 		(void *)&cmd_vf_rate_limit_vf,
8109 		(void *)&cmd_vf_rate_limit_vfnum,
8110 		(void *)&cmd_vf_rate_limit_rate,
8111 		(void *)&cmd_vf_rate_limit_ratenum,
8112 		(void *)&cmd_vf_rate_limit_q_msk,
8113 		(void *)&cmd_vf_rate_limit_q_msk_val,
8114 		NULL,
8115 	},
8116 };
8117 
8118 /* *** CONFIGURE TUNNEL UDP PORT *** */
8119 struct cmd_tunnel_udp_config {
8120 	cmdline_fixed_string_t rx_vxlan_port;
8121 	cmdline_fixed_string_t what;
8122 	uint16_t udp_port;
8123 	portid_t port_id;
8124 };
8125 
8126 static void
8127 cmd_tunnel_udp_config_parsed(void *parsed_result,
8128 			  __rte_unused struct cmdline *cl,
8129 			  __rte_unused void *data)
8130 {
8131 	struct cmd_tunnel_udp_config *res = parsed_result;
8132 	struct rte_eth_udp_tunnel tunnel_udp;
8133 	int ret;
8134 
8135 	tunnel_udp.udp_port = res->udp_port;
8136 	tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
8137 
8138 	if (!strcmp(res->what, "add"))
8139 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8140 						      &tunnel_udp);
8141 	else
8142 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8143 							 &tunnel_udp);
8144 
8145 	if (ret < 0)
8146 		fprintf(stderr, "udp tunneling add error: (%s)\n",
8147 			strerror(-ret));
8148 }
8149 
8150 static cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
8151 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8152 				rx_vxlan_port, "rx_vxlan_port");
8153 static cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8154 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8155 				what, "add#rm");
8156 static cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8157 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8158 				udp_port, RTE_UINT16);
8159 static cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8160 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8161 				port_id, RTE_UINT16);
8162 
8163 static cmdline_parse_inst_t cmd_tunnel_udp_config = {
8164 	.f = cmd_tunnel_udp_config_parsed,
8165 	.data = (void *)0,
8166 	.help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8167 		"Add/Remove a tunneling UDP port filter",
8168 	.tokens = {
8169 		(void *)&cmd_tunnel_udp_config_rx_vxlan_port,
8170 		(void *)&cmd_tunnel_udp_config_what,
8171 		(void *)&cmd_tunnel_udp_config_udp_port,
8172 		(void *)&cmd_tunnel_udp_config_port_id,
8173 		NULL,
8174 	},
8175 };
8176 
8177 struct cmd_config_tunnel_udp_port {
8178 	cmdline_fixed_string_t port;
8179 	cmdline_fixed_string_t config;
8180 	portid_t port_id;
8181 	cmdline_fixed_string_t udp_tunnel_port;
8182 	cmdline_fixed_string_t action;
8183 	cmdline_fixed_string_t tunnel_type;
8184 	uint16_t udp_port;
8185 };
8186 
8187 static void
8188 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8189 			       __rte_unused struct cmdline *cl,
8190 			       __rte_unused void *data)
8191 {
8192 	struct cmd_config_tunnel_udp_port *res = parsed_result;
8193 	struct rte_eth_udp_tunnel tunnel_udp;
8194 	int ret = 0;
8195 
8196 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8197 		return;
8198 
8199 	tunnel_udp.udp_port = res->udp_port;
8200 
8201 	if (!strcmp(res->tunnel_type, "vxlan")) {
8202 		tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
8203 	} else if (!strcmp(res->tunnel_type, "geneve")) {
8204 		tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_GENEVE;
8205 	} else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
8206 		tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN_GPE;
8207 	} else if (!strcmp(res->tunnel_type, "ecpri")) {
8208 		tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_ECPRI;
8209 	} else {
8210 		fprintf(stderr, "Invalid tunnel type\n");
8211 		return;
8212 	}
8213 
8214 	if (!strcmp(res->action, "add"))
8215 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8216 						      &tunnel_udp);
8217 	else
8218 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8219 							 &tunnel_udp);
8220 
8221 	if (ret < 0)
8222 		fprintf(stderr, "udp tunneling port add error: (%s)\n",
8223 			strerror(-ret));
8224 }
8225 
8226 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8227 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8228 				 "port");
8229 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8230 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8231 				 "config");
8232 static cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8233 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8234 			      RTE_UINT16);
8235 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8236 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8237 				 udp_tunnel_port,
8238 				 "udp_tunnel_port");
8239 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8240 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8241 				 "add#rm");
8242 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8243 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8244 				 "vxlan#geneve#vxlan-gpe#ecpri");
8245 static cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8246 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8247 			      RTE_UINT16);
8248 
8249 static cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8250 	.f = cmd_cfg_tunnel_udp_port_parsed,
8251 	.data = NULL,
8252 	.help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
8253 		"geneve|vxlan-gpe|ecpri <udp_port>",
8254 	.tokens = {
8255 		(void *)&cmd_config_tunnel_udp_port_port,
8256 		(void *)&cmd_config_tunnel_udp_port_config,
8257 		(void *)&cmd_config_tunnel_udp_port_port_id,
8258 		(void *)&cmd_config_tunnel_udp_port_tunnel_port,
8259 		(void *)&cmd_config_tunnel_udp_port_action,
8260 		(void *)&cmd_config_tunnel_udp_port_tunnel_type,
8261 		(void *)&cmd_config_tunnel_udp_port_value,
8262 		NULL,
8263 	},
8264 };
8265 
8266 /* ******************************************************************************** */
8267 
8268 struct cmd_dump_result {
8269 	cmdline_fixed_string_t dump;
8270 };
8271 
8272 static void
8273 dump_struct_sizes(void)
8274 {
8275 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8276 	DUMP_SIZE(struct rte_mbuf);
8277 	DUMP_SIZE(struct rte_mempool);
8278 	DUMP_SIZE(struct rte_ring);
8279 #undef DUMP_SIZE
8280 }
8281 
8282 
8283 /* Dump the socket memory statistics on console */
8284 static void
8285 dump_socket_mem(FILE *f)
8286 {
8287 	struct rte_malloc_socket_stats socket_stats;
8288 	unsigned int i;
8289 	size_t total = 0;
8290 	size_t alloc = 0;
8291 	size_t free = 0;
8292 	unsigned int n_alloc = 0;
8293 	unsigned int n_free = 0;
8294 	static size_t last_allocs;
8295 	static size_t last_total;
8296 
8297 
8298 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
8299 		if (rte_malloc_get_socket_stats(i, &socket_stats) ||
8300 		    !socket_stats.heap_totalsz_bytes)
8301 			continue;
8302 		total += socket_stats.heap_totalsz_bytes;
8303 		alloc += socket_stats.heap_allocsz_bytes;
8304 		free += socket_stats.heap_freesz_bytes;
8305 		n_alloc += socket_stats.alloc_count;
8306 		n_free += socket_stats.free_count;
8307 		fprintf(f,
8308 			"Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
8309 			i,
8310 			(double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
8311 			(double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
8312 			(double)socket_stats.heap_allocsz_bytes * 100 /
8313 			(double)socket_stats.heap_totalsz_bytes,
8314 			(double)socket_stats.heap_freesz_bytes / (1024 * 1024),
8315 			socket_stats.alloc_count,
8316 			socket_stats.free_count);
8317 	}
8318 	fprintf(f,
8319 		"Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
8320 		(double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
8321 		total ? ((double)alloc * 100 / (double)total) : 0,
8322 		(double)free / (1024 * 1024),
8323 		n_alloc, n_free);
8324 	if (last_allocs)
8325 		fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
8326 			((double)total - (double)last_total) / (1024 * 1024),
8327 			(double)(alloc - (double)last_allocs) / 1024 / 1024);
8328 	last_allocs = alloc;
8329 	last_total = total;
8330 }
8331 
8332 static void cmd_dump_parsed(void *parsed_result,
8333 			    __rte_unused struct cmdline *cl,
8334 			    __rte_unused void *data)
8335 {
8336 	struct cmd_dump_result *res = parsed_result;
8337 
8338 	if (!strcmp(res->dump, "dump_physmem"))
8339 		rte_dump_physmem_layout(stdout);
8340 	else if (!strcmp(res->dump, "dump_socket_mem"))
8341 		dump_socket_mem(stdout);
8342 	else if (!strcmp(res->dump, "dump_memzone"))
8343 		rte_memzone_dump(stdout);
8344 	else if (!strcmp(res->dump, "dump_struct_sizes"))
8345 		dump_struct_sizes();
8346 	else if (!strcmp(res->dump, "dump_ring"))
8347 		rte_ring_list_dump(stdout);
8348 	else if (!strcmp(res->dump, "dump_mempool"))
8349 		rte_mempool_list_dump(stdout);
8350 	else if (!strcmp(res->dump, "dump_devargs"))
8351 		rte_devargs_dump(stdout);
8352 	else if (!strcmp(res->dump, "dump_log_types"))
8353 		rte_log_dump(stdout);
8354 }
8355 
8356 static cmdline_parse_token_string_t cmd_dump_dump =
8357 	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8358 		"dump_physmem#"
8359 		"dump_memzone#"
8360 		"dump_socket_mem#"
8361 		"dump_struct_sizes#"
8362 		"dump_ring#"
8363 		"dump_mempool#"
8364 		"dump_devargs#"
8365 		"dump_log_types");
8366 
8367 static cmdline_parse_inst_t cmd_dump = {
8368 	.f = cmd_dump_parsed,  /* function to call */
8369 	.data = NULL,      /* 2nd arg of func */
8370 	.help_str = "Dump status",
8371 	.tokens = {        /* token list, NULL terminated */
8372 		(void *)&cmd_dump_dump,
8373 		NULL,
8374 	},
8375 };
8376 
8377 /* ******************************************************************************** */
8378 
8379 struct cmd_dump_one_result {
8380 	cmdline_fixed_string_t dump;
8381 	cmdline_fixed_string_t name;
8382 };
8383 
8384 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8385 				__rte_unused void *data)
8386 {
8387 	struct cmd_dump_one_result *res = parsed_result;
8388 
8389 	if (!strcmp(res->dump, "dump_ring")) {
8390 		struct rte_ring *r;
8391 		r = rte_ring_lookup(res->name);
8392 		if (r == NULL) {
8393 			cmdline_printf(cl, "Cannot find ring\n");
8394 			return;
8395 		}
8396 		rte_ring_dump(stdout, r);
8397 	} else if (!strcmp(res->dump, "dump_mempool")) {
8398 		struct rte_mempool *mp;
8399 		mp = rte_mempool_lookup(res->name);
8400 		if (mp == NULL) {
8401 			cmdline_printf(cl, "Cannot find mempool\n");
8402 			return;
8403 		}
8404 		rte_mempool_dump(stdout, mp);
8405 	}
8406 }
8407 
8408 static cmdline_parse_token_string_t cmd_dump_one_dump =
8409 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8410 				 "dump_ring#dump_mempool");
8411 
8412 static cmdline_parse_token_string_t cmd_dump_one_name =
8413 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8414 
8415 static cmdline_parse_inst_t cmd_dump_one = {
8416 	.f = cmd_dump_one_parsed,  /* function to call */
8417 	.data = NULL,      /* 2nd arg of func */
8418 	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8419 	.tokens = {        /* token list, NULL terminated */
8420 		(void *)&cmd_dump_one_dump,
8421 		(void *)&cmd_dump_one_name,
8422 		NULL,
8423 	},
8424 };
8425 
8426 /* *** Filters Control *** */
8427 
8428 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
8429 do { \
8430 	if ((ip_addr).family == AF_INET) \
8431 		(ip) = (ip_addr).addr.ipv4.s_addr; \
8432 	else { \
8433 		fprintf(stderr, "invalid parameter.\n"); \
8434 		return; \
8435 	} \
8436 } while (0)
8437 
8438 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
8439 do { \
8440 	if ((ip_addr).family == AF_INET6) \
8441 		rte_memcpy(&(ip), \
8442 				 &((ip_addr).addr.ipv6), \
8443 				 sizeof(struct in6_addr)); \
8444 	else { \
8445 		fprintf(stderr, "invalid parameter.\n"); \
8446 		return; \
8447 	} \
8448 } while (0)
8449 
8450 /* Generic flow interface command. */
8451 extern cmdline_parse_inst_t cmd_flow;
8452 
8453 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
8454 struct cmd_mcast_addr_result {
8455 	cmdline_fixed_string_t mcast_addr_cmd;
8456 	cmdline_fixed_string_t what;
8457 	uint16_t port_num;
8458 	struct rte_ether_addr mc_addr;
8459 };
8460 
8461 static void cmd_mcast_addr_parsed(void *parsed_result,
8462 		__rte_unused struct cmdline *cl,
8463 		__rte_unused void *data)
8464 {
8465 	struct cmd_mcast_addr_result *res = parsed_result;
8466 
8467 	if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
8468 		fprintf(stderr,
8469 			"Invalid multicast addr " RTE_ETHER_ADDR_PRT_FMT "\n",
8470 			RTE_ETHER_ADDR_BYTES(&res->mc_addr));
8471 		return;
8472 	}
8473 	if (strcmp(res->what, "add") == 0)
8474 		mcast_addr_add(res->port_num, &res->mc_addr);
8475 	else
8476 		mcast_addr_remove(res->port_num, &res->mc_addr);
8477 }
8478 
8479 static cmdline_parse_token_string_t cmd_mcast_addr_cmd =
8480 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
8481 				 mcast_addr_cmd, "mcast_addr");
8482 static cmdline_parse_token_string_t cmd_mcast_addr_what =
8483 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
8484 				 "add#remove");
8485 static cmdline_parse_token_num_t cmd_mcast_addr_portnum =
8486 	TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
8487 				 RTE_UINT16);
8488 static cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
8489 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8490 
8491 static cmdline_parse_inst_t cmd_mcast_addr = {
8492 	.f = cmd_mcast_addr_parsed,
8493 	.data = (void *)0,
8494 	.help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
8495 		"Add/Remove multicast MAC address on port_id",
8496 	.tokens = {
8497 		(void *)&cmd_mcast_addr_cmd,
8498 		(void *)&cmd_mcast_addr_what,
8499 		(void *)&cmd_mcast_addr_portnum,
8500 		(void *)&cmd_mcast_addr_addr,
8501 		NULL,
8502 	},
8503 };
8504 
8505 /* vf vlan anti spoof configuration */
8506 
8507 /* Common result structure for vf vlan anti spoof */
8508 struct cmd_vf_vlan_anti_spoof_result {
8509 	cmdline_fixed_string_t set;
8510 	cmdline_fixed_string_t vf;
8511 	cmdline_fixed_string_t vlan;
8512 	cmdline_fixed_string_t antispoof;
8513 	portid_t port_id;
8514 	uint32_t vf_id;
8515 	cmdline_fixed_string_t on_off;
8516 };
8517 
8518 /* Common CLI fields for vf vlan anti spoof enable disable */
8519 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
8520 	TOKEN_STRING_INITIALIZER
8521 		(struct cmd_vf_vlan_anti_spoof_result,
8522 		 set, "set");
8523 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
8524 	TOKEN_STRING_INITIALIZER
8525 		(struct cmd_vf_vlan_anti_spoof_result,
8526 		 vf, "vf");
8527 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
8528 	TOKEN_STRING_INITIALIZER
8529 		(struct cmd_vf_vlan_anti_spoof_result,
8530 		 vlan, "vlan");
8531 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
8532 	TOKEN_STRING_INITIALIZER
8533 		(struct cmd_vf_vlan_anti_spoof_result,
8534 		 antispoof, "antispoof");
8535 static cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
8536 	TOKEN_NUM_INITIALIZER
8537 		(struct cmd_vf_vlan_anti_spoof_result,
8538 		 port_id, RTE_UINT16);
8539 static cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
8540 	TOKEN_NUM_INITIALIZER
8541 		(struct cmd_vf_vlan_anti_spoof_result,
8542 		 vf_id, RTE_UINT32);
8543 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
8544 	TOKEN_STRING_INITIALIZER
8545 		(struct cmd_vf_vlan_anti_spoof_result,
8546 		 on_off, "on#off");
8547 
8548 static void
8549 cmd_set_vf_vlan_anti_spoof_parsed(
8550 	void *parsed_result,
8551 	__rte_unused struct cmdline *cl,
8552 	__rte_unused void *data)
8553 {
8554 	struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
8555 	int ret = -ENOTSUP;
8556 
8557 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
8558 
8559 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8560 		return;
8561 
8562 #ifdef RTE_NET_IXGBE
8563 	if (ret == -ENOTSUP)
8564 		ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
8565 				res->vf_id, is_on);
8566 #endif
8567 #ifdef RTE_NET_I40E
8568 	if (ret == -ENOTSUP)
8569 		ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
8570 				res->vf_id, is_on);
8571 #endif
8572 #ifdef RTE_NET_BNXT
8573 	if (ret == -ENOTSUP)
8574 		ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
8575 				res->vf_id, is_on);
8576 #endif
8577 
8578 	switch (ret) {
8579 	case 0:
8580 		break;
8581 	case -EINVAL:
8582 		fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
8583 		break;
8584 	case -ENODEV:
8585 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
8586 		break;
8587 	case -ENOTSUP:
8588 		fprintf(stderr, "function not implemented\n");
8589 		break;
8590 	default:
8591 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
8592 	}
8593 }
8594 
8595 static cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
8596 	.f = cmd_set_vf_vlan_anti_spoof_parsed,
8597 	.data = NULL,
8598 	.help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
8599 	.tokens = {
8600 		(void *)&cmd_vf_vlan_anti_spoof_set,
8601 		(void *)&cmd_vf_vlan_anti_spoof_vf,
8602 		(void *)&cmd_vf_vlan_anti_spoof_vlan,
8603 		(void *)&cmd_vf_vlan_anti_spoof_antispoof,
8604 		(void *)&cmd_vf_vlan_anti_spoof_port_id,
8605 		(void *)&cmd_vf_vlan_anti_spoof_vf_id,
8606 		(void *)&cmd_vf_vlan_anti_spoof_on_off,
8607 		NULL,
8608 	},
8609 };
8610 
8611 /* vf mac anti spoof configuration */
8612 
8613 /* Common result structure for vf mac anti spoof */
8614 struct cmd_vf_mac_anti_spoof_result {
8615 	cmdline_fixed_string_t set;
8616 	cmdline_fixed_string_t vf;
8617 	cmdline_fixed_string_t mac;
8618 	cmdline_fixed_string_t antispoof;
8619 	portid_t port_id;
8620 	uint32_t vf_id;
8621 	cmdline_fixed_string_t on_off;
8622 };
8623 
8624 /* Common CLI fields for vf mac anti spoof enable disable */
8625 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
8626 	TOKEN_STRING_INITIALIZER
8627 		(struct cmd_vf_mac_anti_spoof_result,
8628 		 set, "set");
8629 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
8630 	TOKEN_STRING_INITIALIZER
8631 		(struct cmd_vf_mac_anti_spoof_result,
8632 		 vf, "vf");
8633 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
8634 	TOKEN_STRING_INITIALIZER
8635 		(struct cmd_vf_mac_anti_spoof_result,
8636 		 mac, "mac");
8637 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
8638 	TOKEN_STRING_INITIALIZER
8639 		(struct cmd_vf_mac_anti_spoof_result,
8640 		 antispoof, "antispoof");
8641 static cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
8642 	TOKEN_NUM_INITIALIZER
8643 		(struct cmd_vf_mac_anti_spoof_result,
8644 		 port_id, RTE_UINT16);
8645 static cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
8646 	TOKEN_NUM_INITIALIZER
8647 		(struct cmd_vf_mac_anti_spoof_result,
8648 		 vf_id, RTE_UINT32);
8649 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
8650 	TOKEN_STRING_INITIALIZER
8651 		(struct cmd_vf_mac_anti_spoof_result,
8652 		 on_off, "on#off");
8653 
8654 static void
8655 cmd_set_vf_mac_anti_spoof_parsed(
8656 	void *parsed_result,
8657 	__rte_unused struct cmdline *cl,
8658 	__rte_unused void *data)
8659 {
8660 	struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
8661 	int ret = -ENOTSUP;
8662 
8663 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
8664 
8665 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8666 		return;
8667 
8668 #ifdef RTE_NET_IXGBE
8669 	if (ret == -ENOTSUP)
8670 		ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
8671 			res->vf_id, is_on);
8672 #endif
8673 #ifdef RTE_NET_I40E
8674 	if (ret == -ENOTSUP)
8675 		ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
8676 			res->vf_id, is_on);
8677 #endif
8678 #ifdef RTE_NET_BNXT
8679 	if (ret == -ENOTSUP)
8680 		ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
8681 			res->vf_id, is_on);
8682 #endif
8683 
8684 	switch (ret) {
8685 	case 0:
8686 		break;
8687 	case -EINVAL:
8688 		fprintf(stderr, "invalid vf_id %d or is_on %d\n",
8689 			res->vf_id, is_on);
8690 		break;
8691 	case -ENODEV:
8692 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
8693 		break;
8694 	case -ENOTSUP:
8695 		fprintf(stderr, "function not implemented\n");
8696 		break;
8697 	default:
8698 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
8699 	}
8700 }
8701 
8702 static cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
8703 	.f = cmd_set_vf_mac_anti_spoof_parsed,
8704 	.data = NULL,
8705 	.help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
8706 	.tokens = {
8707 		(void *)&cmd_vf_mac_anti_spoof_set,
8708 		(void *)&cmd_vf_mac_anti_spoof_vf,
8709 		(void *)&cmd_vf_mac_anti_spoof_mac,
8710 		(void *)&cmd_vf_mac_anti_spoof_antispoof,
8711 		(void *)&cmd_vf_mac_anti_spoof_port_id,
8712 		(void *)&cmd_vf_mac_anti_spoof_vf_id,
8713 		(void *)&cmd_vf_mac_anti_spoof_on_off,
8714 		NULL,
8715 	},
8716 };
8717 
8718 /* vf vlan strip queue configuration */
8719 
8720 /* Common result structure for vf mac anti spoof */
8721 struct cmd_vf_vlan_stripq_result {
8722 	cmdline_fixed_string_t set;
8723 	cmdline_fixed_string_t vf;
8724 	cmdline_fixed_string_t vlan;
8725 	cmdline_fixed_string_t stripq;
8726 	portid_t port_id;
8727 	uint16_t vf_id;
8728 	cmdline_fixed_string_t on_off;
8729 };
8730 
8731 /* Common CLI fields for vf vlan strip enable disable */
8732 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
8733 	TOKEN_STRING_INITIALIZER
8734 		(struct cmd_vf_vlan_stripq_result,
8735 		 set, "set");
8736 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
8737 	TOKEN_STRING_INITIALIZER
8738 		(struct cmd_vf_vlan_stripq_result,
8739 		 vf, "vf");
8740 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
8741 	TOKEN_STRING_INITIALIZER
8742 		(struct cmd_vf_vlan_stripq_result,
8743 		 vlan, "vlan");
8744 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
8745 	TOKEN_STRING_INITIALIZER
8746 		(struct cmd_vf_vlan_stripq_result,
8747 		 stripq, "stripq");
8748 static cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
8749 	TOKEN_NUM_INITIALIZER
8750 		(struct cmd_vf_vlan_stripq_result,
8751 		 port_id, RTE_UINT16);
8752 static cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
8753 	TOKEN_NUM_INITIALIZER
8754 		(struct cmd_vf_vlan_stripq_result,
8755 		 vf_id, RTE_UINT16);
8756 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
8757 	TOKEN_STRING_INITIALIZER
8758 		(struct cmd_vf_vlan_stripq_result,
8759 		 on_off, "on#off");
8760 
8761 static void
8762 cmd_set_vf_vlan_stripq_parsed(
8763 	void *parsed_result,
8764 	__rte_unused struct cmdline *cl,
8765 	__rte_unused void *data)
8766 {
8767 	struct cmd_vf_vlan_stripq_result *res = parsed_result;
8768 	int ret = -ENOTSUP;
8769 
8770 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
8771 
8772 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8773 		return;
8774 
8775 #ifdef RTE_NET_IXGBE
8776 	if (ret == -ENOTSUP)
8777 		ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
8778 			res->vf_id, is_on);
8779 #endif
8780 #ifdef RTE_NET_I40E
8781 	if (ret == -ENOTSUP)
8782 		ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
8783 			res->vf_id, is_on);
8784 #endif
8785 #ifdef RTE_NET_BNXT
8786 	if (ret == -ENOTSUP)
8787 		ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
8788 			res->vf_id, is_on);
8789 #endif
8790 
8791 	switch (ret) {
8792 	case 0:
8793 		break;
8794 	case -EINVAL:
8795 		fprintf(stderr, "invalid vf_id %d or is_on %d\n",
8796 			res->vf_id, is_on);
8797 		break;
8798 	case -ENODEV:
8799 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
8800 		break;
8801 	case -ENOTSUP:
8802 		fprintf(stderr, "function not implemented\n");
8803 		break;
8804 	default:
8805 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
8806 	}
8807 }
8808 
8809 static cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
8810 	.f = cmd_set_vf_vlan_stripq_parsed,
8811 	.data = NULL,
8812 	.help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
8813 	.tokens = {
8814 		(void *)&cmd_vf_vlan_stripq_set,
8815 		(void *)&cmd_vf_vlan_stripq_vf,
8816 		(void *)&cmd_vf_vlan_stripq_vlan,
8817 		(void *)&cmd_vf_vlan_stripq_stripq,
8818 		(void *)&cmd_vf_vlan_stripq_port_id,
8819 		(void *)&cmd_vf_vlan_stripq_vf_id,
8820 		(void *)&cmd_vf_vlan_stripq_on_off,
8821 		NULL,
8822 	},
8823 };
8824 
8825 /* vf vlan insert configuration */
8826 
8827 /* Common result structure for vf vlan insert */
8828 struct cmd_vf_vlan_insert_result {
8829 	cmdline_fixed_string_t set;
8830 	cmdline_fixed_string_t vf;
8831 	cmdline_fixed_string_t vlan;
8832 	cmdline_fixed_string_t insert;
8833 	portid_t port_id;
8834 	uint16_t vf_id;
8835 	uint16_t vlan_id;
8836 };
8837 
8838 /* Common CLI fields for vf vlan insert enable disable */
8839 static cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
8840 	TOKEN_STRING_INITIALIZER
8841 		(struct cmd_vf_vlan_insert_result,
8842 		 set, "set");
8843 static cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
8844 	TOKEN_STRING_INITIALIZER
8845 		(struct cmd_vf_vlan_insert_result,
8846 		 vf, "vf");
8847 static cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
8848 	TOKEN_STRING_INITIALIZER
8849 		(struct cmd_vf_vlan_insert_result,
8850 		 vlan, "vlan");
8851 static cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
8852 	TOKEN_STRING_INITIALIZER
8853 		(struct cmd_vf_vlan_insert_result,
8854 		 insert, "insert");
8855 static cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
8856 	TOKEN_NUM_INITIALIZER
8857 		(struct cmd_vf_vlan_insert_result,
8858 		 port_id, RTE_UINT16);
8859 static cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
8860 	TOKEN_NUM_INITIALIZER
8861 		(struct cmd_vf_vlan_insert_result,
8862 		 vf_id, RTE_UINT16);
8863 static cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
8864 	TOKEN_NUM_INITIALIZER
8865 		(struct cmd_vf_vlan_insert_result,
8866 		 vlan_id, RTE_UINT16);
8867 
8868 static void
8869 cmd_set_vf_vlan_insert_parsed(
8870 	void *parsed_result,
8871 	__rte_unused struct cmdline *cl,
8872 	__rte_unused void *data)
8873 {
8874 	struct cmd_vf_vlan_insert_result *res = parsed_result;
8875 	int ret = -ENOTSUP;
8876 
8877 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8878 		return;
8879 
8880 #ifdef RTE_NET_IXGBE
8881 	if (ret == -ENOTSUP)
8882 		ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
8883 			res->vlan_id);
8884 #endif
8885 #ifdef RTE_NET_I40E
8886 	if (ret == -ENOTSUP)
8887 		ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
8888 			res->vlan_id);
8889 #endif
8890 #ifdef RTE_NET_BNXT
8891 	if (ret == -ENOTSUP)
8892 		ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
8893 			res->vlan_id);
8894 #endif
8895 
8896 	switch (ret) {
8897 	case 0:
8898 		break;
8899 	case -EINVAL:
8900 		fprintf(stderr, "invalid vf_id %d or vlan_id %d\n",
8901 			res->vf_id, res->vlan_id);
8902 		break;
8903 	case -ENODEV:
8904 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
8905 		break;
8906 	case -ENOTSUP:
8907 		fprintf(stderr, "function not implemented\n");
8908 		break;
8909 	default:
8910 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
8911 	}
8912 }
8913 
8914 static cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
8915 	.f = cmd_set_vf_vlan_insert_parsed,
8916 	.data = NULL,
8917 	.help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
8918 	.tokens = {
8919 		(void *)&cmd_vf_vlan_insert_set,
8920 		(void *)&cmd_vf_vlan_insert_vf,
8921 		(void *)&cmd_vf_vlan_insert_vlan,
8922 		(void *)&cmd_vf_vlan_insert_insert,
8923 		(void *)&cmd_vf_vlan_insert_port_id,
8924 		(void *)&cmd_vf_vlan_insert_vf_id,
8925 		(void *)&cmd_vf_vlan_insert_vlan_id,
8926 		NULL,
8927 	},
8928 };
8929 
8930 /* tx loopback configuration */
8931 
8932 /* Common result structure for tx loopback */
8933 struct cmd_tx_loopback_result {
8934 	cmdline_fixed_string_t set;
8935 	cmdline_fixed_string_t tx;
8936 	cmdline_fixed_string_t loopback;
8937 	portid_t port_id;
8938 	cmdline_fixed_string_t on_off;
8939 };
8940 
8941 /* Common CLI fields for tx loopback enable disable */
8942 static cmdline_parse_token_string_t cmd_tx_loopback_set =
8943 	TOKEN_STRING_INITIALIZER
8944 		(struct cmd_tx_loopback_result,
8945 		 set, "set");
8946 static cmdline_parse_token_string_t cmd_tx_loopback_tx =
8947 	TOKEN_STRING_INITIALIZER
8948 		(struct cmd_tx_loopback_result,
8949 		 tx, "tx");
8950 static cmdline_parse_token_string_t cmd_tx_loopback_loopback =
8951 	TOKEN_STRING_INITIALIZER
8952 		(struct cmd_tx_loopback_result,
8953 		 loopback, "loopback");
8954 static cmdline_parse_token_num_t cmd_tx_loopback_port_id =
8955 	TOKEN_NUM_INITIALIZER
8956 		(struct cmd_tx_loopback_result,
8957 		 port_id, RTE_UINT16);
8958 static cmdline_parse_token_string_t cmd_tx_loopback_on_off =
8959 	TOKEN_STRING_INITIALIZER
8960 		(struct cmd_tx_loopback_result,
8961 		 on_off, "on#off");
8962 
8963 static void
8964 cmd_set_tx_loopback_parsed(
8965 	void *parsed_result,
8966 	__rte_unused struct cmdline *cl,
8967 	__rte_unused void *data)
8968 {
8969 	struct cmd_tx_loopback_result *res = parsed_result;
8970 	int ret = -ENOTSUP;
8971 
8972 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
8973 
8974 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8975 		return;
8976 
8977 #ifdef RTE_NET_IXGBE
8978 	if (ret == -ENOTSUP)
8979 		ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
8980 #endif
8981 #ifdef RTE_NET_I40E
8982 	if (ret == -ENOTSUP)
8983 		ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
8984 #endif
8985 #ifdef RTE_NET_BNXT
8986 	if (ret == -ENOTSUP)
8987 		ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
8988 #endif
8989 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
8990 	if (ret == -ENOTSUP)
8991 		ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
8992 #endif
8993 
8994 	switch (ret) {
8995 	case 0:
8996 		break;
8997 	case -EINVAL:
8998 		fprintf(stderr, "invalid is_on %d\n", is_on);
8999 		break;
9000 	case -ENODEV:
9001 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
9002 		break;
9003 	case -ENOTSUP:
9004 		fprintf(stderr, "function not implemented\n");
9005 		break;
9006 	default:
9007 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
9008 	}
9009 }
9010 
9011 static cmdline_parse_inst_t cmd_set_tx_loopback = {
9012 	.f = cmd_set_tx_loopback_parsed,
9013 	.data = NULL,
9014 	.help_str = "set tx loopback <port_id> on|off",
9015 	.tokens = {
9016 		(void *)&cmd_tx_loopback_set,
9017 		(void *)&cmd_tx_loopback_tx,
9018 		(void *)&cmd_tx_loopback_loopback,
9019 		(void *)&cmd_tx_loopback_port_id,
9020 		(void *)&cmd_tx_loopback_on_off,
9021 		NULL,
9022 	},
9023 };
9024 
9025 /* all queues drop enable configuration */
9026 
9027 /* Common result structure for all queues drop enable */
9028 struct cmd_all_queues_drop_en_result {
9029 	cmdline_fixed_string_t set;
9030 	cmdline_fixed_string_t all;
9031 	cmdline_fixed_string_t queues;
9032 	cmdline_fixed_string_t drop;
9033 	portid_t port_id;
9034 	cmdline_fixed_string_t on_off;
9035 };
9036 
9037 /* Common CLI fields for tx loopback enable disable */
9038 static cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
9039 	TOKEN_STRING_INITIALIZER
9040 		(struct cmd_all_queues_drop_en_result,
9041 		 set, "set");
9042 static cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
9043 	TOKEN_STRING_INITIALIZER
9044 		(struct cmd_all_queues_drop_en_result,
9045 		 all, "all");
9046 static cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
9047 	TOKEN_STRING_INITIALIZER
9048 		(struct cmd_all_queues_drop_en_result,
9049 		 queues, "queues");
9050 static cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
9051 	TOKEN_STRING_INITIALIZER
9052 		(struct cmd_all_queues_drop_en_result,
9053 		 drop, "drop");
9054 static cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
9055 	TOKEN_NUM_INITIALIZER
9056 		(struct cmd_all_queues_drop_en_result,
9057 		 port_id, RTE_UINT16);
9058 static cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
9059 	TOKEN_STRING_INITIALIZER
9060 		(struct cmd_all_queues_drop_en_result,
9061 		 on_off, "on#off");
9062 
9063 static void
9064 cmd_set_all_queues_drop_en_parsed(
9065 	void *parsed_result,
9066 	__rte_unused struct cmdline *cl,
9067 	__rte_unused void *data)
9068 {
9069 	struct cmd_all_queues_drop_en_result *res = parsed_result;
9070 	int ret = -ENOTSUP;
9071 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
9072 
9073 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9074 		return;
9075 
9076 #ifdef RTE_NET_IXGBE
9077 	if (ret == -ENOTSUP)
9078 		ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
9079 #endif
9080 #ifdef RTE_NET_BNXT
9081 	if (ret == -ENOTSUP)
9082 		ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
9083 #endif
9084 	switch (ret) {
9085 	case 0:
9086 		break;
9087 	case -EINVAL:
9088 		fprintf(stderr, "invalid is_on %d\n", is_on);
9089 		break;
9090 	case -ENODEV:
9091 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
9092 		break;
9093 	case -ENOTSUP:
9094 		fprintf(stderr, "function not implemented\n");
9095 		break;
9096 	default:
9097 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
9098 	}
9099 }
9100 
9101 static cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
9102 	.f = cmd_set_all_queues_drop_en_parsed,
9103 	.data = NULL,
9104 	.help_str = "set all queues drop <port_id> on|off",
9105 	.tokens = {
9106 		(void *)&cmd_all_queues_drop_en_set,
9107 		(void *)&cmd_all_queues_drop_en_all,
9108 		(void *)&cmd_all_queues_drop_en_queues,
9109 		(void *)&cmd_all_queues_drop_en_drop,
9110 		(void *)&cmd_all_queues_drop_en_port_id,
9111 		(void *)&cmd_all_queues_drop_en_on_off,
9112 		NULL,
9113 	},
9114 };
9115 
9116 /* vf mac address configuration */
9117 
9118 /* Common result structure for vf mac address */
9119 struct cmd_set_vf_mac_addr_result {
9120 	cmdline_fixed_string_t set;
9121 	cmdline_fixed_string_t vf;
9122 	cmdline_fixed_string_t mac;
9123 	cmdline_fixed_string_t addr;
9124 	portid_t port_id;
9125 	uint16_t vf_id;
9126 	struct rte_ether_addr mac_addr;
9127 
9128 };
9129 
9130 /* Common CLI fields for vf split drop enable disable */
9131 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
9132 	TOKEN_STRING_INITIALIZER
9133 		(struct cmd_set_vf_mac_addr_result,
9134 		 set, "set");
9135 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
9136 	TOKEN_STRING_INITIALIZER
9137 		(struct cmd_set_vf_mac_addr_result,
9138 		 vf, "vf");
9139 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
9140 	TOKEN_STRING_INITIALIZER
9141 		(struct cmd_set_vf_mac_addr_result,
9142 		 mac, "mac");
9143 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
9144 	TOKEN_STRING_INITIALIZER
9145 		(struct cmd_set_vf_mac_addr_result,
9146 		 addr, "addr");
9147 static cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
9148 	TOKEN_NUM_INITIALIZER
9149 		(struct cmd_set_vf_mac_addr_result,
9150 		 port_id, RTE_UINT16);
9151 static cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
9152 	TOKEN_NUM_INITIALIZER
9153 		(struct cmd_set_vf_mac_addr_result,
9154 		 vf_id, RTE_UINT16);
9155 static cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
9156 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
9157 		 mac_addr);
9158 
9159 static void
9160 cmd_set_vf_mac_addr_parsed(
9161 	void *parsed_result,
9162 	__rte_unused struct cmdline *cl,
9163 	__rte_unused void *data)
9164 {
9165 	struct cmd_set_vf_mac_addr_result *res = parsed_result;
9166 	int ret = -ENOTSUP;
9167 
9168 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9169 		return;
9170 
9171 #ifdef RTE_NET_IXGBE
9172 	if (ret == -ENOTSUP)
9173 		ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
9174 				&res->mac_addr);
9175 #endif
9176 #ifdef RTE_NET_I40E
9177 	if (ret == -ENOTSUP)
9178 		ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
9179 				&res->mac_addr);
9180 #endif
9181 #ifdef RTE_NET_BNXT
9182 	if (ret == -ENOTSUP)
9183 		ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
9184 				&res->mac_addr);
9185 #endif
9186 
9187 	switch (ret) {
9188 	case 0:
9189 		break;
9190 	case -EINVAL:
9191 		fprintf(stderr, "invalid vf_id %d or mac_addr\n", res->vf_id);
9192 		break;
9193 	case -ENODEV:
9194 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
9195 		break;
9196 	case -ENOTSUP:
9197 		fprintf(stderr, "function not implemented\n");
9198 		break;
9199 	default:
9200 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
9201 	}
9202 }
9203 
9204 static cmdline_parse_inst_t cmd_set_vf_mac_addr = {
9205 	.f = cmd_set_vf_mac_addr_parsed,
9206 	.data = NULL,
9207 	.help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
9208 	.tokens = {
9209 		(void *)&cmd_set_vf_mac_addr_set,
9210 		(void *)&cmd_set_vf_mac_addr_vf,
9211 		(void *)&cmd_set_vf_mac_addr_mac,
9212 		(void *)&cmd_set_vf_mac_addr_addr,
9213 		(void *)&cmd_set_vf_mac_addr_port_id,
9214 		(void *)&cmd_set_vf_mac_addr_vf_id,
9215 		(void *)&cmd_set_vf_mac_addr_mac_addr,
9216 		NULL,
9217 	},
9218 };
9219 
9220 /** Set VXLAN encapsulation details */
9221 struct cmd_set_vxlan_result {
9222 	cmdline_fixed_string_t set;
9223 	cmdline_fixed_string_t vxlan;
9224 	cmdline_fixed_string_t pos_token;
9225 	cmdline_fixed_string_t ip_version;
9226 	uint32_t vlan_present:1;
9227 	uint32_t vni;
9228 	uint16_t udp_src;
9229 	uint16_t udp_dst;
9230 	cmdline_ipaddr_t ip_src;
9231 	cmdline_ipaddr_t ip_dst;
9232 	uint16_t tci;
9233 	uint8_t tos;
9234 	uint8_t ttl;
9235 	struct rte_ether_addr eth_src;
9236 	struct rte_ether_addr eth_dst;
9237 };
9238 
9239 static cmdline_parse_token_string_t cmd_set_vxlan_set =
9240 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
9241 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
9242 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
9243 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
9244 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
9245 				 "vxlan-tos-ttl");
9246 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
9247 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
9248 				 "vxlan-with-vlan");
9249 static cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
9250 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
9251 				 "ip-version");
9252 static cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
9253 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
9254 				 "ipv4#ipv6");
9255 static cmdline_parse_token_string_t cmd_set_vxlan_vni =
9256 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
9257 				 "vni");
9258 static cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
9259 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
9260 static cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
9261 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
9262 				 "udp-src");
9263 static cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
9264 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
9265 static cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
9266 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
9267 				 "udp-dst");
9268 static cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
9269 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
9270 static cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
9271 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
9272 				 "ip-tos");
9273 static cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
9274 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
9275 static cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
9276 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
9277 				 "ip-ttl");
9278 static cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
9279 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
9280 static cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
9281 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
9282 				 "ip-src");
9283 static cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
9284 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
9285 static cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
9286 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
9287 				 "ip-dst");
9288 static cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
9289 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
9290 static cmdline_parse_token_string_t cmd_set_vxlan_vlan =
9291 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
9292 				 "vlan-tci");
9293 static cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
9294 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
9295 static cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
9296 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
9297 				 "eth-src");
9298 static cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
9299 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
9300 static cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
9301 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
9302 				 "eth-dst");
9303 static cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
9304 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
9305 
9306 static void cmd_set_vxlan_parsed(void *parsed_result,
9307 	__rte_unused struct cmdline *cl,
9308 	__rte_unused void *data)
9309 {
9310 	struct cmd_set_vxlan_result *res = parsed_result;
9311 	union {
9312 		uint32_t vxlan_id;
9313 		uint8_t vni[4];
9314 	} id = {
9315 		.vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
9316 	};
9317 
9318 	vxlan_encap_conf.select_tos_ttl = 0;
9319 	if (strcmp(res->vxlan, "vxlan") == 0)
9320 		vxlan_encap_conf.select_vlan = 0;
9321 	else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
9322 		vxlan_encap_conf.select_vlan = 1;
9323 	else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
9324 		vxlan_encap_conf.select_vlan = 0;
9325 		vxlan_encap_conf.select_tos_ttl = 1;
9326 	}
9327 	if (strcmp(res->ip_version, "ipv4") == 0)
9328 		vxlan_encap_conf.select_ipv4 = 1;
9329 	else if (strcmp(res->ip_version, "ipv6") == 0)
9330 		vxlan_encap_conf.select_ipv4 = 0;
9331 	else
9332 		return;
9333 	rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
9334 	vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
9335 	vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
9336 	vxlan_encap_conf.ip_tos = res->tos;
9337 	vxlan_encap_conf.ip_ttl = res->ttl;
9338 	if (vxlan_encap_conf.select_ipv4) {
9339 		IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
9340 		IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
9341 	} else {
9342 		IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
9343 		IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
9344 	}
9345 	if (vxlan_encap_conf.select_vlan)
9346 		vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
9347 	rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
9348 		   RTE_ETHER_ADDR_LEN);
9349 	rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
9350 		   RTE_ETHER_ADDR_LEN);
9351 }
9352 
9353 static cmdline_parse_inst_t cmd_set_vxlan = {
9354 	.f = cmd_set_vxlan_parsed,
9355 	.data = NULL,
9356 	.help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
9357 		" <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
9358 		" eth-src <eth-src> eth-dst <eth-dst>",
9359 	.tokens = {
9360 		(void *)&cmd_set_vxlan_set,
9361 		(void *)&cmd_set_vxlan_vxlan,
9362 		(void *)&cmd_set_vxlan_ip_version,
9363 		(void *)&cmd_set_vxlan_ip_version_value,
9364 		(void *)&cmd_set_vxlan_vni,
9365 		(void *)&cmd_set_vxlan_vni_value,
9366 		(void *)&cmd_set_vxlan_udp_src,
9367 		(void *)&cmd_set_vxlan_udp_src_value,
9368 		(void *)&cmd_set_vxlan_udp_dst,
9369 		(void *)&cmd_set_vxlan_udp_dst_value,
9370 		(void *)&cmd_set_vxlan_ip_src,
9371 		(void *)&cmd_set_vxlan_ip_src_value,
9372 		(void *)&cmd_set_vxlan_ip_dst,
9373 		(void *)&cmd_set_vxlan_ip_dst_value,
9374 		(void *)&cmd_set_vxlan_eth_src,
9375 		(void *)&cmd_set_vxlan_eth_src_value,
9376 		(void *)&cmd_set_vxlan_eth_dst,
9377 		(void *)&cmd_set_vxlan_eth_dst_value,
9378 		NULL,
9379 	},
9380 };
9381 
9382 static cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
9383 	.f = cmd_set_vxlan_parsed,
9384 	.data = NULL,
9385 	.help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
9386 		" <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
9387 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
9388 		" eth-dst <eth-dst>",
9389 	.tokens = {
9390 		(void *)&cmd_set_vxlan_set,
9391 		(void *)&cmd_set_vxlan_vxlan_tos_ttl,
9392 		(void *)&cmd_set_vxlan_ip_version,
9393 		(void *)&cmd_set_vxlan_ip_version_value,
9394 		(void *)&cmd_set_vxlan_vni,
9395 		(void *)&cmd_set_vxlan_vni_value,
9396 		(void *)&cmd_set_vxlan_udp_src,
9397 		(void *)&cmd_set_vxlan_udp_src_value,
9398 		(void *)&cmd_set_vxlan_udp_dst,
9399 		(void *)&cmd_set_vxlan_udp_dst_value,
9400 		(void *)&cmd_set_vxlan_ip_tos,
9401 		(void *)&cmd_set_vxlan_ip_tos_value,
9402 		(void *)&cmd_set_vxlan_ip_ttl,
9403 		(void *)&cmd_set_vxlan_ip_ttl_value,
9404 		(void *)&cmd_set_vxlan_ip_src,
9405 		(void *)&cmd_set_vxlan_ip_src_value,
9406 		(void *)&cmd_set_vxlan_ip_dst,
9407 		(void *)&cmd_set_vxlan_ip_dst_value,
9408 		(void *)&cmd_set_vxlan_eth_src,
9409 		(void *)&cmd_set_vxlan_eth_src_value,
9410 		(void *)&cmd_set_vxlan_eth_dst,
9411 		(void *)&cmd_set_vxlan_eth_dst_value,
9412 		NULL,
9413 	},
9414 };
9415 
9416 static cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
9417 	.f = cmd_set_vxlan_parsed,
9418 	.data = NULL,
9419 	.help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
9420 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
9421 		" <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
9422 		" <eth-dst>",
9423 	.tokens = {
9424 		(void *)&cmd_set_vxlan_set,
9425 		(void *)&cmd_set_vxlan_vxlan_with_vlan,
9426 		(void *)&cmd_set_vxlan_ip_version,
9427 		(void *)&cmd_set_vxlan_ip_version_value,
9428 		(void *)&cmd_set_vxlan_vni,
9429 		(void *)&cmd_set_vxlan_vni_value,
9430 		(void *)&cmd_set_vxlan_udp_src,
9431 		(void *)&cmd_set_vxlan_udp_src_value,
9432 		(void *)&cmd_set_vxlan_udp_dst,
9433 		(void *)&cmd_set_vxlan_udp_dst_value,
9434 		(void *)&cmd_set_vxlan_ip_src,
9435 		(void *)&cmd_set_vxlan_ip_src_value,
9436 		(void *)&cmd_set_vxlan_ip_dst,
9437 		(void *)&cmd_set_vxlan_ip_dst_value,
9438 		(void *)&cmd_set_vxlan_vlan,
9439 		(void *)&cmd_set_vxlan_vlan_value,
9440 		(void *)&cmd_set_vxlan_eth_src,
9441 		(void *)&cmd_set_vxlan_eth_src_value,
9442 		(void *)&cmd_set_vxlan_eth_dst,
9443 		(void *)&cmd_set_vxlan_eth_dst_value,
9444 		NULL,
9445 	},
9446 };
9447 
9448 /** Set NVGRE encapsulation details */
9449 struct cmd_set_nvgre_result {
9450 	cmdline_fixed_string_t set;
9451 	cmdline_fixed_string_t nvgre;
9452 	cmdline_fixed_string_t pos_token;
9453 	cmdline_fixed_string_t ip_version;
9454 	uint32_t tni;
9455 	cmdline_ipaddr_t ip_src;
9456 	cmdline_ipaddr_t ip_dst;
9457 	uint16_t tci;
9458 	struct rte_ether_addr eth_src;
9459 	struct rte_ether_addr eth_dst;
9460 };
9461 
9462 static cmdline_parse_token_string_t cmd_set_nvgre_set =
9463 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
9464 static cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
9465 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
9466 static cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
9467 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
9468 				 "nvgre-with-vlan");
9469 static cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
9470 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
9471 				 "ip-version");
9472 static cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
9473 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
9474 				 "ipv4#ipv6");
9475 static cmdline_parse_token_string_t cmd_set_nvgre_tni =
9476 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
9477 				 "tni");
9478 static cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
9479 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
9480 static cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
9481 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
9482 				 "ip-src");
9483 static cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
9484 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
9485 static cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
9486 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
9487 				 "ip-dst");
9488 static cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
9489 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
9490 static cmdline_parse_token_string_t cmd_set_nvgre_vlan =
9491 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
9492 				 "vlan-tci");
9493 static cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
9494 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
9495 static cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
9496 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
9497 				 "eth-src");
9498 static cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
9499 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
9500 static cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
9501 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
9502 				 "eth-dst");
9503 static cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
9504 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
9505 
9506 static void cmd_set_nvgre_parsed(void *parsed_result,
9507 	__rte_unused struct cmdline *cl,
9508 	__rte_unused void *data)
9509 {
9510 	struct cmd_set_nvgre_result *res = parsed_result;
9511 	union {
9512 		uint32_t nvgre_tni;
9513 		uint8_t tni[4];
9514 	} id = {
9515 		.nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
9516 	};
9517 
9518 	if (strcmp(res->nvgre, "nvgre") == 0)
9519 		nvgre_encap_conf.select_vlan = 0;
9520 	else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
9521 		nvgre_encap_conf.select_vlan = 1;
9522 	if (strcmp(res->ip_version, "ipv4") == 0)
9523 		nvgre_encap_conf.select_ipv4 = 1;
9524 	else if (strcmp(res->ip_version, "ipv6") == 0)
9525 		nvgre_encap_conf.select_ipv4 = 0;
9526 	else
9527 		return;
9528 	rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
9529 	if (nvgre_encap_conf.select_ipv4) {
9530 		IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
9531 		IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
9532 	} else {
9533 		IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
9534 		IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
9535 	}
9536 	if (nvgre_encap_conf.select_vlan)
9537 		nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
9538 	rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
9539 		   RTE_ETHER_ADDR_LEN);
9540 	rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
9541 		   RTE_ETHER_ADDR_LEN);
9542 }
9543 
9544 static cmdline_parse_inst_t cmd_set_nvgre = {
9545 	.f = cmd_set_nvgre_parsed,
9546 	.data = NULL,
9547 	.help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
9548 		" <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
9549 		" eth-dst <eth-dst>",
9550 	.tokens = {
9551 		(void *)&cmd_set_nvgre_set,
9552 		(void *)&cmd_set_nvgre_nvgre,
9553 		(void *)&cmd_set_nvgre_ip_version,
9554 		(void *)&cmd_set_nvgre_ip_version_value,
9555 		(void *)&cmd_set_nvgre_tni,
9556 		(void *)&cmd_set_nvgre_tni_value,
9557 		(void *)&cmd_set_nvgre_ip_src,
9558 		(void *)&cmd_set_nvgre_ip_src_value,
9559 		(void *)&cmd_set_nvgre_ip_dst,
9560 		(void *)&cmd_set_nvgre_ip_dst_value,
9561 		(void *)&cmd_set_nvgre_eth_src,
9562 		(void *)&cmd_set_nvgre_eth_src_value,
9563 		(void *)&cmd_set_nvgre_eth_dst,
9564 		(void *)&cmd_set_nvgre_eth_dst_value,
9565 		NULL,
9566 	},
9567 };
9568 
9569 static cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
9570 	.f = cmd_set_nvgre_parsed,
9571 	.data = NULL,
9572 	.help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
9573 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
9574 		" eth-src <eth-src> eth-dst <eth-dst>",
9575 	.tokens = {
9576 		(void *)&cmd_set_nvgre_set,
9577 		(void *)&cmd_set_nvgre_nvgre_with_vlan,
9578 		(void *)&cmd_set_nvgre_ip_version,
9579 		(void *)&cmd_set_nvgre_ip_version_value,
9580 		(void *)&cmd_set_nvgre_tni,
9581 		(void *)&cmd_set_nvgre_tni_value,
9582 		(void *)&cmd_set_nvgre_ip_src,
9583 		(void *)&cmd_set_nvgre_ip_src_value,
9584 		(void *)&cmd_set_nvgre_ip_dst,
9585 		(void *)&cmd_set_nvgre_ip_dst_value,
9586 		(void *)&cmd_set_nvgre_vlan,
9587 		(void *)&cmd_set_nvgre_vlan_value,
9588 		(void *)&cmd_set_nvgre_eth_src,
9589 		(void *)&cmd_set_nvgre_eth_src_value,
9590 		(void *)&cmd_set_nvgre_eth_dst,
9591 		(void *)&cmd_set_nvgre_eth_dst_value,
9592 		NULL,
9593 	},
9594 };
9595 
9596 /** Set L2 encapsulation details */
9597 struct cmd_set_l2_encap_result {
9598 	cmdline_fixed_string_t set;
9599 	cmdline_fixed_string_t l2_encap;
9600 	cmdline_fixed_string_t pos_token;
9601 	cmdline_fixed_string_t ip_version;
9602 	uint32_t vlan_present:1;
9603 	uint16_t tci;
9604 	struct rte_ether_addr eth_src;
9605 	struct rte_ether_addr eth_dst;
9606 };
9607 
9608 static cmdline_parse_token_string_t cmd_set_l2_encap_set =
9609 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
9610 static cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
9611 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
9612 static cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
9613 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
9614 				 "l2_encap-with-vlan");
9615 static cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
9616 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
9617 				 "ip-version");
9618 static cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
9619 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
9620 				 "ipv4#ipv6");
9621 static cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
9622 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
9623 				 "vlan-tci");
9624 static cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
9625 	TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
9626 static cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
9627 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
9628 				 "eth-src");
9629 static cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
9630 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
9631 static cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
9632 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
9633 				 "eth-dst");
9634 static cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
9635 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
9636 
9637 static void cmd_set_l2_encap_parsed(void *parsed_result,
9638 	__rte_unused struct cmdline *cl,
9639 	__rte_unused void *data)
9640 {
9641 	struct cmd_set_l2_encap_result *res = parsed_result;
9642 
9643 	if (strcmp(res->l2_encap, "l2_encap") == 0)
9644 		l2_encap_conf.select_vlan = 0;
9645 	else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
9646 		l2_encap_conf.select_vlan = 1;
9647 	if (strcmp(res->ip_version, "ipv4") == 0)
9648 		l2_encap_conf.select_ipv4 = 1;
9649 	else if (strcmp(res->ip_version, "ipv6") == 0)
9650 		l2_encap_conf.select_ipv4 = 0;
9651 	else
9652 		return;
9653 	if (l2_encap_conf.select_vlan)
9654 		l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
9655 	rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
9656 		   RTE_ETHER_ADDR_LEN);
9657 	rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
9658 		   RTE_ETHER_ADDR_LEN);
9659 }
9660 
9661 static cmdline_parse_inst_t cmd_set_l2_encap = {
9662 	.f = cmd_set_l2_encap_parsed,
9663 	.data = NULL,
9664 	.help_str = "set l2_encap ip-version ipv4|ipv6"
9665 		" eth-src <eth-src> eth-dst <eth-dst>",
9666 	.tokens = {
9667 		(void *)&cmd_set_l2_encap_set,
9668 		(void *)&cmd_set_l2_encap_l2_encap,
9669 		(void *)&cmd_set_l2_encap_ip_version,
9670 		(void *)&cmd_set_l2_encap_ip_version_value,
9671 		(void *)&cmd_set_l2_encap_eth_src,
9672 		(void *)&cmd_set_l2_encap_eth_src_value,
9673 		(void *)&cmd_set_l2_encap_eth_dst,
9674 		(void *)&cmd_set_l2_encap_eth_dst_value,
9675 		NULL,
9676 	},
9677 };
9678 
9679 static cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
9680 	.f = cmd_set_l2_encap_parsed,
9681 	.data = NULL,
9682 	.help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
9683 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
9684 	.tokens = {
9685 		(void *)&cmd_set_l2_encap_set,
9686 		(void *)&cmd_set_l2_encap_l2_encap_with_vlan,
9687 		(void *)&cmd_set_l2_encap_ip_version,
9688 		(void *)&cmd_set_l2_encap_ip_version_value,
9689 		(void *)&cmd_set_l2_encap_vlan,
9690 		(void *)&cmd_set_l2_encap_vlan_value,
9691 		(void *)&cmd_set_l2_encap_eth_src,
9692 		(void *)&cmd_set_l2_encap_eth_src_value,
9693 		(void *)&cmd_set_l2_encap_eth_dst,
9694 		(void *)&cmd_set_l2_encap_eth_dst_value,
9695 		NULL,
9696 	},
9697 };
9698 
9699 /** Set L2 decapsulation details */
9700 struct cmd_set_l2_decap_result {
9701 	cmdline_fixed_string_t set;
9702 	cmdline_fixed_string_t l2_decap;
9703 	cmdline_fixed_string_t pos_token;
9704 	uint32_t vlan_present:1;
9705 };
9706 
9707 static cmdline_parse_token_string_t cmd_set_l2_decap_set =
9708 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
9709 static cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
9710 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
9711 				 "l2_decap");
9712 static cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
9713 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
9714 				 "l2_decap-with-vlan");
9715 
9716 static void cmd_set_l2_decap_parsed(void *parsed_result,
9717 	__rte_unused struct cmdline *cl,
9718 	__rte_unused void *data)
9719 {
9720 	struct cmd_set_l2_decap_result *res = parsed_result;
9721 
9722 	if (strcmp(res->l2_decap, "l2_decap") == 0)
9723 		l2_decap_conf.select_vlan = 0;
9724 	else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
9725 		l2_decap_conf.select_vlan = 1;
9726 }
9727 
9728 static cmdline_parse_inst_t cmd_set_l2_decap = {
9729 	.f = cmd_set_l2_decap_parsed,
9730 	.data = NULL,
9731 	.help_str = "set l2_decap",
9732 	.tokens = {
9733 		(void *)&cmd_set_l2_decap_set,
9734 		(void *)&cmd_set_l2_decap_l2_decap,
9735 		NULL,
9736 	},
9737 };
9738 
9739 static cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
9740 	.f = cmd_set_l2_decap_parsed,
9741 	.data = NULL,
9742 	.help_str = "set l2_decap-with-vlan",
9743 	.tokens = {
9744 		(void *)&cmd_set_l2_decap_set,
9745 		(void *)&cmd_set_l2_decap_l2_decap_with_vlan,
9746 		NULL,
9747 	},
9748 };
9749 
9750 /** Set MPLSoGRE encapsulation details */
9751 struct cmd_set_mplsogre_encap_result {
9752 	cmdline_fixed_string_t set;
9753 	cmdline_fixed_string_t mplsogre;
9754 	cmdline_fixed_string_t pos_token;
9755 	cmdline_fixed_string_t ip_version;
9756 	uint32_t vlan_present:1;
9757 	uint32_t label;
9758 	cmdline_ipaddr_t ip_src;
9759 	cmdline_ipaddr_t ip_dst;
9760 	uint16_t tci;
9761 	struct rte_ether_addr eth_src;
9762 	struct rte_ether_addr eth_dst;
9763 };
9764 
9765 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
9766 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
9767 				 "set");
9768 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
9769 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
9770 				 "mplsogre_encap");
9771 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
9772 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
9773 				 mplsogre, "mplsogre_encap-with-vlan");
9774 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
9775 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
9776 				 pos_token, "ip-version");
9777 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
9778 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
9779 				 ip_version, "ipv4#ipv6");
9780 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
9781 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
9782 				 pos_token, "label");
9783 static cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
9784 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
9785 			      RTE_UINT32);
9786 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
9787 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
9788 				 pos_token, "ip-src");
9789 static cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
9790 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
9791 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
9792 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
9793 				 pos_token, "ip-dst");
9794 static cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
9795 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
9796 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
9797 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
9798 				 pos_token, "vlan-tci");
9799 static cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
9800 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
9801 			      RTE_UINT16);
9802 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
9803 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
9804 				 pos_token, "eth-src");
9805 static cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
9806 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
9807 				    eth_src);
9808 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
9809 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
9810 				 pos_token, "eth-dst");
9811 static cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
9812 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
9813 				    eth_dst);
9814 
9815 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
9816 	__rte_unused struct cmdline *cl,
9817 	__rte_unused void *data)
9818 {
9819 	struct cmd_set_mplsogre_encap_result *res = parsed_result;
9820 	union {
9821 		uint32_t mplsogre_label;
9822 		uint8_t label[4];
9823 	} id = {
9824 		.mplsogre_label = rte_cpu_to_be_32(res->label<<12),
9825 	};
9826 
9827 	if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
9828 		mplsogre_encap_conf.select_vlan = 0;
9829 	else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
9830 		mplsogre_encap_conf.select_vlan = 1;
9831 	if (strcmp(res->ip_version, "ipv4") == 0)
9832 		mplsogre_encap_conf.select_ipv4 = 1;
9833 	else if (strcmp(res->ip_version, "ipv6") == 0)
9834 		mplsogre_encap_conf.select_ipv4 = 0;
9835 	else
9836 		return;
9837 	rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
9838 	if (mplsogre_encap_conf.select_ipv4) {
9839 		IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
9840 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
9841 	} else {
9842 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
9843 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
9844 	}
9845 	if (mplsogre_encap_conf.select_vlan)
9846 		mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
9847 	rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
9848 		   RTE_ETHER_ADDR_LEN);
9849 	rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
9850 		   RTE_ETHER_ADDR_LEN);
9851 }
9852 
9853 static cmdline_parse_inst_t cmd_set_mplsogre_encap = {
9854 	.f = cmd_set_mplsogre_encap_parsed,
9855 	.data = NULL,
9856 	.help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
9857 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
9858 		" eth-dst <eth-dst>",
9859 	.tokens = {
9860 		(void *)&cmd_set_mplsogre_encap_set,
9861 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap,
9862 		(void *)&cmd_set_mplsogre_encap_ip_version,
9863 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
9864 		(void *)&cmd_set_mplsogre_encap_label,
9865 		(void *)&cmd_set_mplsogre_encap_label_value,
9866 		(void *)&cmd_set_mplsogre_encap_ip_src,
9867 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
9868 		(void *)&cmd_set_mplsogre_encap_ip_dst,
9869 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
9870 		(void *)&cmd_set_mplsogre_encap_eth_src,
9871 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
9872 		(void *)&cmd_set_mplsogre_encap_eth_dst,
9873 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
9874 		NULL,
9875 	},
9876 };
9877 
9878 static cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
9879 	.f = cmd_set_mplsogre_encap_parsed,
9880 	.data = NULL,
9881 	.help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
9882 		" label <label> ip-src <ip-src> ip-dst <ip-dst>"
9883 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
9884 	.tokens = {
9885 		(void *)&cmd_set_mplsogre_encap_set,
9886 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
9887 		(void *)&cmd_set_mplsogre_encap_ip_version,
9888 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
9889 		(void *)&cmd_set_mplsogre_encap_label,
9890 		(void *)&cmd_set_mplsogre_encap_label_value,
9891 		(void *)&cmd_set_mplsogre_encap_ip_src,
9892 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
9893 		(void *)&cmd_set_mplsogre_encap_ip_dst,
9894 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
9895 		(void *)&cmd_set_mplsogre_encap_vlan,
9896 		(void *)&cmd_set_mplsogre_encap_vlan_value,
9897 		(void *)&cmd_set_mplsogre_encap_eth_src,
9898 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
9899 		(void *)&cmd_set_mplsogre_encap_eth_dst,
9900 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
9901 		NULL,
9902 	},
9903 };
9904 
9905 /** Set MPLSoGRE decapsulation details */
9906 struct cmd_set_mplsogre_decap_result {
9907 	cmdline_fixed_string_t set;
9908 	cmdline_fixed_string_t mplsogre;
9909 	cmdline_fixed_string_t pos_token;
9910 	cmdline_fixed_string_t ip_version;
9911 	uint32_t vlan_present:1;
9912 };
9913 
9914 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
9915 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
9916 				 "set");
9917 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
9918 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
9919 				 "mplsogre_decap");
9920 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
9921 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
9922 				 mplsogre, "mplsogre_decap-with-vlan");
9923 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
9924 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
9925 				 pos_token, "ip-version");
9926 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
9927 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
9928 				 ip_version, "ipv4#ipv6");
9929 
9930 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
9931 	__rte_unused struct cmdline *cl,
9932 	__rte_unused void *data)
9933 {
9934 	struct cmd_set_mplsogre_decap_result *res = parsed_result;
9935 
9936 	if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
9937 		mplsogre_decap_conf.select_vlan = 0;
9938 	else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
9939 		mplsogre_decap_conf.select_vlan = 1;
9940 	if (strcmp(res->ip_version, "ipv4") == 0)
9941 		mplsogre_decap_conf.select_ipv4 = 1;
9942 	else if (strcmp(res->ip_version, "ipv6") == 0)
9943 		mplsogre_decap_conf.select_ipv4 = 0;
9944 }
9945 
9946 static cmdline_parse_inst_t cmd_set_mplsogre_decap = {
9947 	.f = cmd_set_mplsogre_decap_parsed,
9948 	.data = NULL,
9949 	.help_str = "set mplsogre_decap ip-version ipv4|ipv6",
9950 	.tokens = {
9951 		(void *)&cmd_set_mplsogre_decap_set,
9952 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap,
9953 		(void *)&cmd_set_mplsogre_decap_ip_version,
9954 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
9955 		NULL,
9956 	},
9957 };
9958 
9959 static cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
9960 	.f = cmd_set_mplsogre_decap_parsed,
9961 	.data = NULL,
9962 	.help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
9963 	.tokens = {
9964 		(void *)&cmd_set_mplsogre_decap_set,
9965 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
9966 		(void *)&cmd_set_mplsogre_decap_ip_version,
9967 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
9968 		NULL,
9969 	},
9970 };
9971 
9972 /** Set MPLSoUDP encapsulation details */
9973 struct cmd_set_mplsoudp_encap_result {
9974 	cmdline_fixed_string_t set;
9975 	cmdline_fixed_string_t mplsoudp;
9976 	cmdline_fixed_string_t pos_token;
9977 	cmdline_fixed_string_t ip_version;
9978 	uint32_t vlan_present:1;
9979 	uint32_t label;
9980 	uint16_t udp_src;
9981 	uint16_t udp_dst;
9982 	cmdline_ipaddr_t ip_src;
9983 	cmdline_ipaddr_t ip_dst;
9984 	uint16_t tci;
9985 	struct rte_ether_addr eth_src;
9986 	struct rte_ether_addr eth_dst;
9987 };
9988 
9989 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
9990 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
9991 				 "set");
9992 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
9993 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
9994 				 "mplsoudp_encap");
9995 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
9996 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
9997 				 mplsoudp, "mplsoudp_encap-with-vlan");
9998 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
9999 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
10000 				 pos_token, "ip-version");
10001 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
10002 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
10003 				 ip_version, "ipv4#ipv6");
10004 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
10005 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
10006 				 pos_token, "label");
10007 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
10008 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
10009 			      RTE_UINT32);
10010 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
10011 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
10012 				 pos_token, "udp-src");
10013 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
10014 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
10015 			      RTE_UINT16);
10016 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
10017 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
10018 				 pos_token, "udp-dst");
10019 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
10020 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
10021 			      RTE_UINT16);
10022 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
10023 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
10024 				 pos_token, "ip-src");
10025 static cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
10026 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
10027 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
10028 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
10029 				 pos_token, "ip-dst");
10030 static cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
10031 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
10032 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
10033 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
10034 				 pos_token, "vlan-tci");
10035 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
10036 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
10037 			      RTE_UINT16);
10038 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
10039 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
10040 				 pos_token, "eth-src");
10041 static cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
10042 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
10043 				    eth_src);
10044 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
10045 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
10046 				 pos_token, "eth-dst");
10047 static cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
10048 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
10049 				    eth_dst);
10050 
10051 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
10052 	__rte_unused struct cmdline *cl,
10053 	__rte_unused void *data)
10054 {
10055 	struct cmd_set_mplsoudp_encap_result *res = parsed_result;
10056 	union {
10057 		uint32_t mplsoudp_label;
10058 		uint8_t label[4];
10059 	} id = {
10060 		.mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
10061 	};
10062 
10063 	if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
10064 		mplsoudp_encap_conf.select_vlan = 0;
10065 	else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
10066 		mplsoudp_encap_conf.select_vlan = 1;
10067 	if (strcmp(res->ip_version, "ipv4") == 0)
10068 		mplsoudp_encap_conf.select_ipv4 = 1;
10069 	else if (strcmp(res->ip_version, "ipv6") == 0)
10070 		mplsoudp_encap_conf.select_ipv4 = 0;
10071 	else
10072 		return;
10073 	rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
10074 	mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
10075 	mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
10076 	if (mplsoudp_encap_conf.select_ipv4) {
10077 		IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
10078 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
10079 	} else {
10080 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
10081 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
10082 	}
10083 	if (mplsoudp_encap_conf.select_vlan)
10084 		mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
10085 	rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
10086 		   RTE_ETHER_ADDR_LEN);
10087 	rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
10088 		   RTE_ETHER_ADDR_LEN);
10089 }
10090 
10091 static cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
10092 	.f = cmd_set_mplsoudp_encap_parsed,
10093 	.data = NULL,
10094 	.help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
10095 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
10096 		" ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
10097 	.tokens = {
10098 		(void *)&cmd_set_mplsoudp_encap_set,
10099 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
10100 		(void *)&cmd_set_mplsoudp_encap_ip_version,
10101 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
10102 		(void *)&cmd_set_mplsoudp_encap_label,
10103 		(void *)&cmd_set_mplsoudp_encap_label_value,
10104 		(void *)&cmd_set_mplsoudp_encap_udp_src,
10105 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
10106 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
10107 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
10108 		(void *)&cmd_set_mplsoudp_encap_ip_src,
10109 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
10110 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
10111 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
10112 		(void *)&cmd_set_mplsoudp_encap_eth_src,
10113 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
10114 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
10115 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
10116 		NULL,
10117 	},
10118 };
10119 
10120 static cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
10121 	.f = cmd_set_mplsoudp_encap_parsed,
10122 	.data = NULL,
10123 	.help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
10124 		" label <label> udp-src <udp-src> udp-dst <udp-dst>"
10125 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
10126 		" eth-src <eth-src> eth-dst <eth-dst>",
10127 	.tokens = {
10128 		(void *)&cmd_set_mplsoudp_encap_set,
10129 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
10130 		(void *)&cmd_set_mplsoudp_encap_ip_version,
10131 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
10132 		(void *)&cmd_set_mplsoudp_encap_label,
10133 		(void *)&cmd_set_mplsoudp_encap_label_value,
10134 		(void *)&cmd_set_mplsoudp_encap_udp_src,
10135 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
10136 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
10137 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
10138 		(void *)&cmd_set_mplsoudp_encap_ip_src,
10139 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
10140 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
10141 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
10142 		(void *)&cmd_set_mplsoudp_encap_vlan,
10143 		(void *)&cmd_set_mplsoudp_encap_vlan_value,
10144 		(void *)&cmd_set_mplsoudp_encap_eth_src,
10145 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
10146 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
10147 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
10148 		NULL,
10149 	},
10150 };
10151 
10152 /** Set MPLSoUDP decapsulation details */
10153 struct cmd_set_mplsoudp_decap_result {
10154 	cmdline_fixed_string_t set;
10155 	cmdline_fixed_string_t mplsoudp;
10156 	cmdline_fixed_string_t pos_token;
10157 	cmdline_fixed_string_t ip_version;
10158 	uint32_t vlan_present:1;
10159 };
10160 
10161 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
10162 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
10163 				 "set");
10164 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
10165 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
10166 				 "mplsoudp_decap");
10167 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
10168 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
10169 				 mplsoudp, "mplsoudp_decap-with-vlan");
10170 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
10171 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
10172 				 pos_token, "ip-version");
10173 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
10174 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
10175 				 ip_version, "ipv4#ipv6");
10176 
10177 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
10178 	__rte_unused struct cmdline *cl,
10179 	__rte_unused void *data)
10180 {
10181 	struct cmd_set_mplsoudp_decap_result *res = parsed_result;
10182 
10183 	if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
10184 		mplsoudp_decap_conf.select_vlan = 0;
10185 	else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
10186 		mplsoudp_decap_conf.select_vlan = 1;
10187 	if (strcmp(res->ip_version, "ipv4") == 0)
10188 		mplsoudp_decap_conf.select_ipv4 = 1;
10189 	else if (strcmp(res->ip_version, "ipv6") == 0)
10190 		mplsoudp_decap_conf.select_ipv4 = 0;
10191 }
10192 
10193 static cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
10194 	.f = cmd_set_mplsoudp_decap_parsed,
10195 	.data = NULL,
10196 	.help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
10197 	.tokens = {
10198 		(void *)&cmd_set_mplsoudp_decap_set,
10199 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
10200 		(void *)&cmd_set_mplsoudp_decap_ip_version,
10201 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
10202 		NULL,
10203 	},
10204 };
10205 
10206 static cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
10207 	.f = cmd_set_mplsoudp_decap_parsed,
10208 	.data = NULL,
10209 	.help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
10210 	.tokens = {
10211 		(void *)&cmd_set_mplsoudp_decap_set,
10212 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
10213 		(void *)&cmd_set_mplsoudp_decap_ip_version,
10214 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
10215 		NULL,
10216 	},
10217 };
10218 
10219 /** Set connection tracking object common details */
10220 struct cmd_set_conntrack_common_result {
10221 	cmdline_fixed_string_t set;
10222 	cmdline_fixed_string_t conntrack;
10223 	cmdline_fixed_string_t common;
10224 	cmdline_fixed_string_t peer;
10225 	cmdline_fixed_string_t is_orig;
10226 	cmdline_fixed_string_t enable;
10227 	cmdline_fixed_string_t live;
10228 	cmdline_fixed_string_t sack;
10229 	cmdline_fixed_string_t cack;
10230 	cmdline_fixed_string_t last_dir;
10231 	cmdline_fixed_string_t liberal;
10232 	cmdline_fixed_string_t state;
10233 	cmdline_fixed_string_t max_ack_win;
10234 	cmdline_fixed_string_t retrans;
10235 	cmdline_fixed_string_t last_win;
10236 	cmdline_fixed_string_t last_seq;
10237 	cmdline_fixed_string_t last_ack;
10238 	cmdline_fixed_string_t last_end;
10239 	cmdline_fixed_string_t last_index;
10240 	uint8_t stat;
10241 	uint8_t factor;
10242 	uint16_t peer_port;
10243 	uint32_t is_original;
10244 	uint32_t en;
10245 	uint32_t is_live;
10246 	uint32_t s_ack;
10247 	uint32_t c_ack;
10248 	uint32_t ld;
10249 	uint32_t lb;
10250 	uint8_t re_num;
10251 	uint8_t li;
10252 	uint16_t lw;
10253 	uint32_t ls;
10254 	uint32_t la;
10255 	uint32_t le;
10256 };
10257 
10258 static cmdline_parse_token_string_t cmd_set_conntrack_set =
10259 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10260 				 set, "set");
10261 static cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
10262 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10263 				 conntrack, "conntrack");
10264 static cmdline_parse_token_string_t cmd_set_conntrack_common_com =
10265 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10266 				 common, "com");
10267 static cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
10268 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10269 				 peer, "peer");
10270 static cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
10271 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10272 			      peer_port, RTE_UINT16);
10273 static cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
10274 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10275 				 is_orig, "is_orig");
10276 static cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
10277 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10278 			      is_original, RTE_UINT32);
10279 static cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
10280 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10281 				 enable, "enable");
10282 static cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
10283 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10284 			      en, RTE_UINT32);
10285 static cmdline_parse_token_string_t cmd_set_conntrack_common_live =
10286 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10287 				 live, "live");
10288 static cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
10289 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10290 			      is_live, RTE_UINT32);
10291 static cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
10292 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10293 				 sack, "sack");
10294 static cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
10295 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10296 			      s_ack, RTE_UINT32);
10297 static cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
10298 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10299 				 cack, "cack");
10300 static cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
10301 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10302 			      c_ack, RTE_UINT32);
10303 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
10304 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10305 				 last_dir, "last_dir");
10306 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
10307 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10308 			      ld, RTE_UINT32);
10309 static cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
10310 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10311 				 liberal, "liberal");
10312 static cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
10313 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10314 			      lb, RTE_UINT32);
10315 static cmdline_parse_token_string_t cmd_set_conntrack_common_state =
10316 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10317 				 state, "state");
10318 static cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
10319 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10320 			      stat, RTE_UINT8);
10321 static cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
10322 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10323 				 max_ack_win, "max_ack_win");
10324 static cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
10325 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10326 			      factor, RTE_UINT8);
10327 static cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
10328 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10329 				 retrans, "r_lim");
10330 static cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
10331 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10332 			      re_num, RTE_UINT8);
10333 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
10334 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10335 				 last_win, "last_win");
10336 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
10337 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10338 			      lw, RTE_UINT16);
10339 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
10340 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10341 				 last_seq, "last_seq");
10342 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
10343 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10344 			      ls, RTE_UINT32);
10345 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
10346 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10347 				 last_ack, "last_ack");
10348 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
10349 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10350 			      la, RTE_UINT32);
10351 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
10352 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10353 				 last_end, "last_end");
10354 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
10355 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10356 			      le, RTE_UINT32);
10357 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
10358 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
10359 				 last_index, "last_index");
10360 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
10361 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
10362 			      li, RTE_UINT8);
10363 
10364 static void cmd_set_conntrack_common_parsed(void *parsed_result,
10365 	__rte_unused struct cmdline *cl,
10366 	__rte_unused void *data)
10367 {
10368 	struct cmd_set_conntrack_common_result *res = parsed_result;
10369 
10370 	/* No need to swap to big endian. */
10371 	conntrack_context.peer_port = res->peer_port;
10372 	conntrack_context.is_original_dir = res->is_original;
10373 	conntrack_context.enable = res->en;
10374 	conntrack_context.live_connection = res->is_live;
10375 	conntrack_context.selective_ack = res->s_ack;
10376 	conntrack_context.challenge_ack_passed = res->c_ack;
10377 	conntrack_context.last_direction = res->ld;
10378 	conntrack_context.liberal_mode = res->lb;
10379 	conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
10380 	conntrack_context.max_ack_window = res->factor;
10381 	conntrack_context.retransmission_limit = res->re_num;
10382 	conntrack_context.last_window = res->lw;
10383 	conntrack_context.last_index =
10384 		(enum rte_flow_conntrack_tcp_last_index)res->li;
10385 	conntrack_context.last_seq = res->ls;
10386 	conntrack_context.last_ack = res->la;
10387 	conntrack_context.last_end = res->le;
10388 }
10389 
10390 static cmdline_parse_inst_t cmd_set_conntrack_common = {
10391 	.f = cmd_set_conntrack_common_parsed,
10392 	.data = NULL,
10393 	.help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
10394 		" live <ack_seen> sack <en> cack <passed> last_dir <dir>"
10395 		" liberal <en> state <s> max_ack_win <factor> r_lim <num>"
10396 		" last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
10397 		" last_index <flag>",
10398 	.tokens = {
10399 		(void *)&cmd_set_conntrack_set,
10400 		(void *)&cmd_set_conntrack_conntrack,
10401 		(void *)&cmd_set_conntrack_common_com,
10402 		(void *)&cmd_set_conntrack_common_peer,
10403 		(void *)&cmd_set_conntrack_common_peer_value,
10404 		(void *)&cmd_set_conntrack_common_is_orig,
10405 		(void *)&cmd_set_conntrack_common_is_orig_value,
10406 		(void *)&cmd_set_conntrack_common_enable,
10407 		(void *)&cmd_set_conntrack_common_enable_value,
10408 		(void *)&cmd_set_conntrack_common_live,
10409 		(void *)&cmd_set_conntrack_common_live_value,
10410 		(void *)&cmd_set_conntrack_common_sack,
10411 		(void *)&cmd_set_conntrack_common_sack_value,
10412 		(void *)&cmd_set_conntrack_common_cack,
10413 		(void *)&cmd_set_conntrack_common_cack_value,
10414 		(void *)&cmd_set_conntrack_common_last_dir,
10415 		(void *)&cmd_set_conntrack_common_last_dir_value,
10416 		(void *)&cmd_set_conntrack_common_liberal,
10417 		(void *)&cmd_set_conntrack_common_liberal_value,
10418 		(void *)&cmd_set_conntrack_common_state,
10419 		(void *)&cmd_set_conntrack_common_state_value,
10420 		(void *)&cmd_set_conntrack_common_max_ackwin,
10421 		(void *)&cmd_set_conntrack_common_max_ackwin_value,
10422 		(void *)&cmd_set_conntrack_common_retrans,
10423 		(void *)&cmd_set_conntrack_common_retrans_value,
10424 		(void *)&cmd_set_conntrack_common_last_win,
10425 		(void *)&cmd_set_conntrack_common_last_win_value,
10426 		(void *)&cmd_set_conntrack_common_last_seq,
10427 		(void *)&cmd_set_conntrack_common_last_seq_value,
10428 		(void *)&cmd_set_conntrack_common_last_ack,
10429 		(void *)&cmd_set_conntrack_common_last_ack_value,
10430 		(void *)&cmd_set_conntrack_common_last_end,
10431 		(void *)&cmd_set_conntrack_common_last_end_value,
10432 		(void *)&cmd_set_conntrack_common_last_index,
10433 		(void *)&cmd_set_conntrack_common_last_index_value,
10434 		NULL,
10435 	},
10436 };
10437 
10438 /** Set connection tracking object both directions' details */
10439 struct cmd_set_conntrack_dir_result {
10440 	cmdline_fixed_string_t set;
10441 	cmdline_fixed_string_t conntrack;
10442 	cmdline_fixed_string_t dir;
10443 	cmdline_fixed_string_t scale;
10444 	cmdline_fixed_string_t fin;
10445 	cmdline_fixed_string_t ack_seen;
10446 	cmdline_fixed_string_t unack;
10447 	cmdline_fixed_string_t sent_end;
10448 	cmdline_fixed_string_t reply_end;
10449 	cmdline_fixed_string_t max_win;
10450 	cmdline_fixed_string_t max_ack;
10451 	uint32_t factor;
10452 	uint32_t f;
10453 	uint32_t as;
10454 	uint32_t un;
10455 	uint32_t se;
10456 	uint32_t re;
10457 	uint32_t mw;
10458 	uint32_t ma;
10459 };
10460 
10461 static cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
10462 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
10463 				 dir, "orig#rply");
10464 static cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
10465 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
10466 				 scale, "scale");
10467 static cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
10468 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
10469 			      factor, RTE_UINT32);
10470 static cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
10471 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
10472 				 fin, "fin");
10473 static cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
10474 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
10475 			      f, RTE_UINT32);
10476 static cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
10477 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
10478 				 ack_seen, "acked");
10479 static cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
10480 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
10481 			      as, RTE_UINT32);
10482 static cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
10483 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
10484 				 unack, "unack_data");
10485 static cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
10486 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
10487 			      un, RTE_UINT32);
10488 static cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
10489 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
10490 				 sent_end, "sent_end");
10491 static cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
10492 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
10493 			      se, RTE_UINT32);
10494 static cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
10495 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
10496 				 reply_end, "reply_end");
10497 static cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
10498 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
10499 			      re, RTE_UINT32);
10500 static cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
10501 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
10502 				 max_win, "max_win");
10503 static cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
10504 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
10505 			      mw, RTE_UINT32);
10506 static cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
10507 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
10508 				 max_ack, "max_ack");
10509 static cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
10510 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
10511 			      ma, RTE_UINT32);
10512 
10513 static void cmd_set_conntrack_dir_parsed(void *parsed_result,
10514 	__rte_unused struct cmdline *cl,
10515 	__rte_unused void *data)
10516 {
10517 	struct cmd_set_conntrack_dir_result *res = parsed_result;
10518 	struct rte_flow_tcp_dir_param *dir = NULL;
10519 
10520 	if (strcmp(res->dir, "orig") == 0)
10521 		dir = &conntrack_context.original_dir;
10522 	else if (strcmp(res->dir, "rply") == 0)
10523 		dir = &conntrack_context.reply_dir;
10524 	else
10525 		return;
10526 	dir->scale = res->factor;
10527 	dir->close_initiated = res->f;
10528 	dir->last_ack_seen = res->as;
10529 	dir->data_unacked = res->un;
10530 	dir->sent_end = res->se;
10531 	dir->reply_end = res->re;
10532 	dir->max_ack = res->ma;
10533 	dir->max_win = res->mw;
10534 }
10535 
10536 static cmdline_parse_inst_t cmd_set_conntrack_dir = {
10537 	.f = cmd_set_conntrack_dir_parsed,
10538 	.data = NULL,
10539 	.help_str = "set conntrack orig|rply scale <factor> fin <sent>"
10540 		    " acked <seen> unack_data <unack> sent_end <sent>"
10541 		    " reply_end <reply> max_win <win> max_ack <ack>",
10542 	.tokens = {
10543 		(void *)&cmd_set_conntrack_set,
10544 		(void *)&cmd_set_conntrack_conntrack,
10545 		(void *)&cmd_set_conntrack_dir_dir,
10546 		(void *)&cmd_set_conntrack_dir_scale,
10547 		(void *)&cmd_set_conntrack_dir_scale_value,
10548 		(void *)&cmd_set_conntrack_dir_fin,
10549 		(void *)&cmd_set_conntrack_dir_fin_value,
10550 		(void *)&cmd_set_conntrack_dir_ack,
10551 		(void *)&cmd_set_conntrack_dir_ack_value,
10552 		(void *)&cmd_set_conntrack_dir_unack_data,
10553 		(void *)&cmd_set_conntrack_dir_unack_data_value,
10554 		(void *)&cmd_set_conntrack_dir_sent_end,
10555 		(void *)&cmd_set_conntrack_dir_sent_end_value,
10556 		(void *)&cmd_set_conntrack_dir_reply_end,
10557 		(void *)&cmd_set_conntrack_dir_reply_end_value,
10558 		(void *)&cmd_set_conntrack_dir_max_win,
10559 		(void *)&cmd_set_conntrack_dir_max_win_value,
10560 		(void *)&cmd_set_conntrack_dir_max_ack,
10561 		(void *)&cmd_set_conntrack_dir_max_ack_value,
10562 		NULL,
10563 	},
10564 };
10565 
10566 /* show vf stats */
10567 
10568 /* Common result structure for show vf stats */
10569 struct cmd_show_vf_stats_result {
10570 	cmdline_fixed_string_t show;
10571 	cmdline_fixed_string_t vf;
10572 	cmdline_fixed_string_t stats;
10573 	portid_t port_id;
10574 	uint16_t vf_id;
10575 };
10576 
10577 /* Common CLI fields show vf stats*/
10578 static cmdline_parse_token_string_t cmd_show_vf_stats_show =
10579 	TOKEN_STRING_INITIALIZER
10580 		(struct cmd_show_vf_stats_result,
10581 		 show, "show");
10582 static cmdline_parse_token_string_t cmd_show_vf_stats_vf =
10583 	TOKEN_STRING_INITIALIZER
10584 		(struct cmd_show_vf_stats_result,
10585 		 vf, "vf");
10586 static cmdline_parse_token_string_t cmd_show_vf_stats_stats =
10587 	TOKEN_STRING_INITIALIZER
10588 		(struct cmd_show_vf_stats_result,
10589 		 stats, "stats");
10590 static cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
10591 	TOKEN_NUM_INITIALIZER
10592 		(struct cmd_show_vf_stats_result,
10593 		 port_id, RTE_UINT16);
10594 static cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
10595 	TOKEN_NUM_INITIALIZER
10596 		(struct cmd_show_vf_stats_result,
10597 		 vf_id, RTE_UINT16);
10598 
10599 static void
10600 cmd_show_vf_stats_parsed(
10601 	void *parsed_result,
10602 	__rte_unused struct cmdline *cl,
10603 	__rte_unused void *data)
10604 {
10605 	struct cmd_show_vf_stats_result *res = parsed_result;
10606 	struct rte_eth_stats stats;
10607 	int ret = -ENOTSUP;
10608 	static const char *nic_stats_border = "########################";
10609 
10610 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10611 		return;
10612 
10613 	memset(&stats, 0, sizeof(stats));
10614 
10615 #ifdef RTE_NET_I40E
10616 	if (ret == -ENOTSUP)
10617 		ret = rte_pmd_i40e_get_vf_stats(res->port_id,
10618 						res->vf_id,
10619 						&stats);
10620 #endif
10621 #ifdef RTE_NET_BNXT
10622 	if (ret == -ENOTSUP)
10623 		ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
10624 						res->vf_id,
10625 						&stats);
10626 #endif
10627 
10628 	switch (ret) {
10629 	case 0:
10630 		break;
10631 	case -EINVAL:
10632 		fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
10633 		break;
10634 	case -ENODEV:
10635 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
10636 		break;
10637 	case -ENOTSUP:
10638 		fprintf(stderr, "function not implemented\n");
10639 		break;
10640 	default:
10641 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
10642 	}
10643 
10644 	printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
10645 		nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
10646 
10647 	printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
10648 	       "%-"PRIu64"\n",
10649 	       stats.ipackets, stats.imissed, stats.ibytes);
10650 	printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
10651 	printf("  RX-nombuf:  %-10"PRIu64"\n",
10652 	       stats.rx_nombuf);
10653 	printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
10654 	       "%-"PRIu64"\n",
10655 	       stats.opackets, stats.oerrors, stats.obytes);
10656 
10657 	printf("  %s############################%s\n",
10658 			       nic_stats_border, nic_stats_border);
10659 }
10660 
10661 static cmdline_parse_inst_t cmd_show_vf_stats = {
10662 	.f = cmd_show_vf_stats_parsed,
10663 	.data = NULL,
10664 	.help_str = "show vf stats <port_id> <vf_id>",
10665 	.tokens = {
10666 		(void *)&cmd_show_vf_stats_show,
10667 		(void *)&cmd_show_vf_stats_vf,
10668 		(void *)&cmd_show_vf_stats_stats,
10669 		(void *)&cmd_show_vf_stats_port_id,
10670 		(void *)&cmd_show_vf_stats_vf_id,
10671 		NULL,
10672 	},
10673 };
10674 
10675 /* clear vf stats */
10676 
10677 /* Common result structure for clear vf stats */
10678 struct cmd_clear_vf_stats_result {
10679 	cmdline_fixed_string_t clear;
10680 	cmdline_fixed_string_t vf;
10681 	cmdline_fixed_string_t stats;
10682 	portid_t port_id;
10683 	uint16_t vf_id;
10684 };
10685 
10686 /* Common CLI fields clear vf stats*/
10687 static cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
10688 	TOKEN_STRING_INITIALIZER
10689 		(struct cmd_clear_vf_stats_result,
10690 		 clear, "clear");
10691 static cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
10692 	TOKEN_STRING_INITIALIZER
10693 		(struct cmd_clear_vf_stats_result,
10694 		 vf, "vf");
10695 static cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
10696 	TOKEN_STRING_INITIALIZER
10697 		(struct cmd_clear_vf_stats_result,
10698 		 stats, "stats");
10699 static cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
10700 	TOKEN_NUM_INITIALIZER
10701 		(struct cmd_clear_vf_stats_result,
10702 		 port_id, RTE_UINT16);
10703 static cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
10704 	TOKEN_NUM_INITIALIZER
10705 		(struct cmd_clear_vf_stats_result,
10706 		 vf_id, RTE_UINT16);
10707 
10708 static void
10709 cmd_clear_vf_stats_parsed(
10710 	void *parsed_result,
10711 	__rte_unused struct cmdline *cl,
10712 	__rte_unused void *data)
10713 {
10714 	struct cmd_clear_vf_stats_result *res = parsed_result;
10715 	int ret = -ENOTSUP;
10716 
10717 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10718 		return;
10719 
10720 #ifdef RTE_NET_I40E
10721 	if (ret == -ENOTSUP)
10722 		ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
10723 						  res->vf_id);
10724 #endif
10725 #ifdef RTE_NET_BNXT
10726 	if (ret == -ENOTSUP)
10727 		ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
10728 						  res->vf_id);
10729 #endif
10730 
10731 	switch (ret) {
10732 	case 0:
10733 		break;
10734 	case -EINVAL:
10735 		fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
10736 		break;
10737 	case -ENODEV:
10738 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
10739 		break;
10740 	case -ENOTSUP:
10741 		fprintf(stderr, "function not implemented\n");
10742 		break;
10743 	default:
10744 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
10745 	}
10746 }
10747 
10748 static cmdline_parse_inst_t cmd_clear_vf_stats = {
10749 	.f = cmd_clear_vf_stats_parsed,
10750 	.data = NULL,
10751 	.help_str = "clear vf stats <port_id> <vf_id>",
10752 	.tokens = {
10753 		(void *)&cmd_clear_vf_stats_clear,
10754 		(void *)&cmd_clear_vf_stats_vf,
10755 		(void *)&cmd_clear_vf_stats_stats,
10756 		(void *)&cmd_clear_vf_stats_port_id,
10757 		(void *)&cmd_clear_vf_stats_vf_id,
10758 		NULL,
10759 	},
10760 };
10761 
10762 /* Common result structure for file commands */
10763 struct cmd_cmdfile_result {
10764 	cmdline_fixed_string_t load;
10765 	cmdline_fixed_string_t filename;
10766 };
10767 
10768 /* Common CLI fields for file commands */
10769 static cmdline_parse_token_string_t cmd_load_cmdfile =
10770 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
10771 static cmdline_parse_token_string_t cmd_load_cmdfile_filename =
10772 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
10773 
10774 static void
10775 cmd_load_from_file_parsed(
10776 	void *parsed_result,
10777 	__rte_unused struct cmdline *cl,
10778 	__rte_unused void *data)
10779 {
10780 	struct cmd_cmdfile_result *res = parsed_result;
10781 
10782 	cmdline_read_from_file(res->filename);
10783 }
10784 
10785 static cmdline_parse_inst_t cmd_load_from_file = {
10786 	.f = cmd_load_from_file_parsed,
10787 	.data = NULL,
10788 	.help_str = "load <filename>",
10789 	.tokens = {
10790 		(void *)&cmd_load_cmdfile,
10791 		(void *)&cmd_load_cmdfile_filename,
10792 		NULL,
10793 	},
10794 };
10795 
10796 /* Get Rx offloads capabilities */
10797 struct cmd_rx_offload_get_capa_result {
10798 	cmdline_fixed_string_t show;
10799 	cmdline_fixed_string_t port;
10800 	portid_t port_id;
10801 	cmdline_fixed_string_t rx_offload;
10802 	cmdline_fixed_string_t capabilities;
10803 };
10804 
10805 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
10806 	TOKEN_STRING_INITIALIZER
10807 		(struct cmd_rx_offload_get_capa_result,
10808 		 show, "show");
10809 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
10810 	TOKEN_STRING_INITIALIZER
10811 		(struct cmd_rx_offload_get_capa_result,
10812 		 port, "port");
10813 static cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
10814 	TOKEN_NUM_INITIALIZER
10815 		(struct cmd_rx_offload_get_capa_result,
10816 		 port_id, RTE_UINT16);
10817 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
10818 	TOKEN_STRING_INITIALIZER
10819 		(struct cmd_rx_offload_get_capa_result,
10820 		 rx_offload, "rx_offload");
10821 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
10822 	TOKEN_STRING_INITIALIZER
10823 		(struct cmd_rx_offload_get_capa_result,
10824 		 capabilities, "capabilities");
10825 
10826 static void
10827 print_rx_offloads(uint64_t offloads)
10828 {
10829 	uint64_t single_offload;
10830 	int begin;
10831 	int end;
10832 	int bit;
10833 
10834 	if (offloads == 0)
10835 		return;
10836 
10837 	begin = __builtin_ctzll(offloads);
10838 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
10839 
10840 	single_offload = 1ULL << begin;
10841 	for (bit = begin; bit < end; bit++) {
10842 		if (offloads & single_offload)
10843 			printf(" %s",
10844 			       rte_eth_dev_rx_offload_name(single_offload));
10845 		single_offload <<= 1;
10846 	}
10847 }
10848 
10849 static void
10850 cmd_rx_offload_get_capa_parsed(
10851 	void *parsed_result,
10852 	__rte_unused struct cmdline *cl,
10853 	__rte_unused void *data)
10854 {
10855 	struct cmd_rx_offload_get_capa_result *res = parsed_result;
10856 	struct rte_eth_dev_info dev_info;
10857 	portid_t port_id = res->port_id;
10858 	uint64_t queue_offloads;
10859 	uint64_t port_offloads;
10860 	int ret;
10861 
10862 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
10863 	if (ret != 0)
10864 		return;
10865 
10866 	queue_offloads = dev_info.rx_queue_offload_capa;
10867 	port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
10868 
10869 	printf("Rx Offloading Capabilities of port %d :\n", port_id);
10870 	printf("  Per Queue :");
10871 	print_rx_offloads(queue_offloads);
10872 
10873 	printf("\n");
10874 	printf("  Per Port  :");
10875 	print_rx_offloads(port_offloads);
10876 	printf("\n\n");
10877 }
10878 
10879 static cmdline_parse_inst_t cmd_rx_offload_get_capa = {
10880 	.f = cmd_rx_offload_get_capa_parsed,
10881 	.data = NULL,
10882 	.help_str = "show port <port_id> rx_offload capabilities",
10883 	.tokens = {
10884 		(void *)&cmd_rx_offload_get_capa_show,
10885 		(void *)&cmd_rx_offload_get_capa_port,
10886 		(void *)&cmd_rx_offload_get_capa_port_id,
10887 		(void *)&cmd_rx_offload_get_capa_rx_offload,
10888 		(void *)&cmd_rx_offload_get_capa_capabilities,
10889 		NULL,
10890 	}
10891 };
10892 
10893 /* Get Rx offloads configuration */
10894 struct cmd_rx_offload_get_configuration_result {
10895 	cmdline_fixed_string_t show;
10896 	cmdline_fixed_string_t port;
10897 	portid_t port_id;
10898 	cmdline_fixed_string_t rx_offload;
10899 	cmdline_fixed_string_t configuration;
10900 };
10901 
10902 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
10903 	TOKEN_STRING_INITIALIZER
10904 		(struct cmd_rx_offload_get_configuration_result,
10905 		 show, "show");
10906 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
10907 	TOKEN_STRING_INITIALIZER
10908 		(struct cmd_rx_offload_get_configuration_result,
10909 		 port, "port");
10910 static cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
10911 	TOKEN_NUM_INITIALIZER
10912 		(struct cmd_rx_offload_get_configuration_result,
10913 		 port_id, RTE_UINT16);
10914 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
10915 	TOKEN_STRING_INITIALIZER
10916 		(struct cmd_rx_offload_get_configuration_result,
10917 		 rx_offload, "rx_offload");
10918 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
10919 	TOKEN_STRING_INITIALIZER
10920 		(struct cmd_rx_offload_get_configuration_result,
10921 		 configuration, "configuration");
10922 
10923 static void
10924 cmd_rx_offload_get_configuration_parsed(
10925 	void *parsed_result,
10926 	__rte_unused struct cmdline *cl,
10927 	__rte_unused void *data)
10928 {
10929 	struct cmd_rx_offload_get_configuration_result *res = parsed_result;
10930 	struct rte_eth_dev_info dev_info;
10931 	portid_t port_id = res->port_id;
10932 	struct rte_port *port = &ports[port_id];
10933 	struct rte_eth_conf dev_conf;
10934 	uint64_t port_offloads;
10935 	uint64_t queue_offloads;
10936 	uint16_t nb_rx_queues;
10937 	int q;
10938 	int ret;
10939 
10940 	printf("Rx Offloading Configuration of port %d :\n", port_id);
10941 
10942 	ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
10943 	if (ret != 0)
10944 		return;
10945 
10946 	port_offloads = dev_conf.rxmode.offloads;
10947 	printf("  Port :");
10948 	print_rx_offloads(port_offloads);
10949 	printf("\n");
10950 
10951 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
10952 	if (ret != 0)
10953 		return;
10954 
10955 	nb_rx_queues = dev_info.nb_rx_queues;
10956 	for (q = 0; q < nb_rx_queues; q++) {
10957 		queue_offloads = port->rxq[q].conf.offloads;
10958 		printf("  Queue[%2d] :", q);
10959 		print_rx_offloads(queue_offloads);
10960 		printf("\n");
10961 	}
10962 	printf("\n");
10963 }
10964 
10965 static cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
10966 	.f = cmd_rx_offload_get_configuration_parsed,
10967 	.data = NULL,
10968 	.help_str = "show port <port_id> rx_offload configuration",
10969 	.tokens = {
10970 		(void *)&cmd_rx_offload_get_configuration_show,
10971 		(void *)&cmd_rx_offload_get_configuration_port,
10972 		(void *)&cmd_rx_offload_get_configuration_port_id,
10973 		(void *)&cmd_rx_offload_get_configuration_rx_offload,
10974 		(void *)&cmd_rx_offload_get_configuration_configuration,
10975 		NULL,
10976 	}
10977 };
10978 
10979 /* Enable/Disable a per port offloading */
10980 struct cmd_config_per_port_rx_offload_result {
10981 	cmdline_fixed_string_t port;
10982 	cmdline_fixed_string_t config;
10983 	portid_t port_id;
10984 	cmdline_fixed_string_t rx_offload;
10985 	cmdline_fixed_string_t offload;
10986 	cmdline_fixed_string_t on_off;
10987 };
10988 
10989 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
10990 	TOKEN_STRING_INITIALIZER
10991 		(struct cmd_config_per_port_rx_offload_result,
10992 		 port, "port");
10993 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
10994 	TOKEN_STRING_INITIALIZER
10995 		(struct cmd_config_per_port_rx_offload_result,
10996 		 config, "config");
10997 static cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
10998 	TOKEN_NUM_INITIALIZER
10999 		(struct cmd_config_per_port_rx_offload_result,
11000 		 port_id, RTE_UINT16);
11001 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
11002 	TOKEN_STRING_INITIALIZER
11003 		(struct cmd_config_per_port_rx_offload_result,
11004 		 rx_offload, "rx_offload");
11005 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
11006 	TOKEN_STRING_INITIALIZER
11007 		(struct cmd_config_per_port_rx_offload_result,
11008 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
11009 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
11010 			   "vlan_filter#vlan_extend#"
11011 			   "scatter#buffer_split#timestamp#security#"
11012 			   "keep_crc#rss_hash");
11013 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
11014 	TOKEN_STRING_INITIALIZER
11015 		(struct cmd_config_per_port_rx_offload_result,
11016 		 on_off, "on#off");
11017 
11018 static uint64_t
11019 search_rx_offload(const char *name)
11020 {
11021 	uint64_t single_offload;
11022 	const char *single_name;
11023 	int found = 0;
11024 	unsigned int bit;
11025 
11026 	single_offload = 1;
11027 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
11028 		single_name = rte_eth_dev_rx_offload_name(single_offload);
11029 		if (!strcasecmp(single_name, name)) {
11030 			found = 1;
11031 			break;
11032 		}
11033 		single_offload <<= 1;
11034 	}
11035 
11036 	if (found)
11037 		return single_offload;
11038 
11039 	return 0;
11040 }
11041 
11042 static void
11043 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
11044 				__rte_unused struct cmdline *cl,
11045 				__rte_unused void *data)
11046 {
11047 	struct cmd_config_per_port_rx_offload_result *res = parsed_result;
11048 	portid_t port_id = res->port_id;
11049 	struct rte_eth_dev_info dev_info;
11050 	struct rte_port *port = &ports[port_id];
11051 	uint64_t single_offload;
11052 	uint16_t nb_rx_queues;
11053 	int q;
11054 	int ret;
11055 
11056 	if (port->port_status != RTE_PORT_STOPPED) {
11057 		fprintf(stderr,
11058 			"Error: Can't config offload when Port %d is not stopped\n",
11059 			port_id);
11060 		return;
11061 	}
11062 
11063 	single_offload = search_rx_offload(res->offload);
11064 	if (single_offload == 0) {
11065 		fprintf(stderr, "Unknown offload name: %s\n", res->offload);
11066 		return;
11067 	}
11068 
11069 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
11070 	if (ret != 0)
11071 		return;
11072 
11073 	nb_rx_queues = dev_info.nb_rx_queues;
11074 	if (!strcmp(res->on_off, "on")) {
11075 		port->dev_conf.rxmode.offloads |= single_offload;
11076 		for (q = 0; q < nb_rx_queues; q++)
11077 			port->rxq[q].conf.offloads |= single_offload;
11078 	} else {
11079 		port->dev_conf.rxmode.offloads &= ~single_offload;
11080 		for (q = 0; q < nb_rx_queues; q++)
11081 			port->rxq[q].conf.offloads &= ~single_offload;
11082 	}
11083 
11084 	cmd_reconfig_device_queue(port_id, 1, 1);
11085 }
11086 
11087 static cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
11088 	.f = cmd_config_per_port_rx_offload_parsed,
11089 	.data = NULL,
11090 	.help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
11091 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
11092 		    "macsec_strip|vlan_filter|vlan_extend|"
11093 		    "scatter|buffer_split|timestamp|security|"
11094 		    "keep_crc|rss_hash on|off",
11095 	.tokens = {
11096 		(void *)&cmd_config_per_port_rx_offload_result_port,
11097 		(void *)&cmd_config_per_port_rx_offload_result_config,
11098 		(void *)&cmd_config_per_port_rx_offload_result_port_id,
11099 		(void *)&cmd_config_per_port_rx_offload_result_rx_offload,
11100 		(void *)&cmd_config_per_port_rx_offload_result_offload,
11101 		(void *)&cmd_config_per_port_rx_offload_result_on_off,
11102 		NULL,
11103 	}
11104 };
11105 
11106 /* Enable/Disable a per queue offloading */
11107 struct cmd_config_per_queue_rx_offload_result {
11108 	cmdline_fixed_string_t port;
11109 	portid_t port_id;
11110 	cmdline_fixed_string_t rxq;
11111 	uint16_t queue_id;
11112 	cmdline_fixed_string_t rx_offload;
11113 	cmdline_fixed_string_t offload;
11114 	cmdline_fixed_string_t on_off;
11115 };
11116 
11117 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
11118 	TOKEN_STRING_INITIALIZER
11119 		(struct cmd_config_per_queue_rx_offload_result,
11120 		 port, "port");
11121 static cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
11122 	TOKEN_NUM_INITIALIZER
11123 		(struct cmd_config_per_queue_rx_offload_result,
11124 		 port_id, RTE_UINT16);
11125 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
11126 	TOKEN_STRING_INITIALIZER
11127 		(struct cmd_config_per_queue_rx_offload_result,
11128 		 rxq, "rxq");
11129 static cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
11130 	TOKEN_NUM_INITIALIZER
11131 		(struct cmd_config_per_queue_rx_offload_result,
11132 		 queue_id, RTE_UINT16);
11133 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
11134 	TOKEN_STRING_INITIALIZER
11135 		(struct cmd_config_per_queue_rx_offload_result,
11136 		 rx_offload, "rx_offload");
11137 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
11138 	TOKEN_STRING_INITIALIZER
11139 		(struct cmd_config_per_queue_rx_offload_result,
11140 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
11141 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
11142 			   "vlan_filter#vlan_extend#"
11143 			   "scatter#buffer_split#timestamp#security#keep_crc");
11144 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
11145 	TOKEN_STRING_INITIALIZER
11146 		(struct cmd_config_per_queue_rx_offload_result,
11147 		 on_off, "on#off");
11148 
11149 static void
11150 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
11151 				__rte_unused struct cmdline *cl,
11152 				__rte_unused void *data)
11153 {
11154 	struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
11155 	struct rte_eth_dev_info dev_info;
11156 	portid_t port_id = res->port_id;
11157 	uint16_t queue_id = res->queue_id;
11158 	struct rte_port *port = &ports[port_id];
11159 	uint64_t single_offload;
11160 	int ret;
11161 
11162 	if (port->port_status != RTE_PORT_STOPPED) {
11163 		fprintf(stderr,
11164 			"Error: Can't config offload when Port %d is not stopped\n",
11165 			port_id);
11166 		return;
11167 	}
11168 
11169 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
11170 	if (ret != 0)
11171 		return;
11172 
11173 	if (queue_id >= dev_info.nb_rx_queues) {
11174 		fprintf(stderr,
11175 			"Error: input queue_id should be 0 ... %d\n",
11176 			dev_info.nb_rx_queues - 1);
11177 		return;
11178 	}
11179 
11180 	single_offload = search_rx_offload(res->offload);
11181 	if (single_offload == 0) {
11182 		fprintf(stderr, "Unknown offload name: %s\n", res->offload);
11183 		return;
11184 	}
11185 
11186 	if (!strcmp(res->on_off, "on"))
11187 		port->rxq[queue_id].conf.offloads |= single_offload;
11188 	else
11189 		port->rxq[queue_id].conf.offloads &= ~single_offload;
11190 
11191 	cmd_reconfig_device_queue(port_id, 1, 1);
11192 }
11193 
11194 static cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
11195 	.f = cmd_config_per_queue_rx_offload_parsed,
11196 	.data = NULL,
11197 	.help_str = "port <port_id> rxq <queue_id> rx_offload "
11198 		    "vlan_strip|ipv4_cksum|"
11199 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
11200 		    "macsec_strip|vlan_filter|vlan_extend|"
11201 		    "scatter|buffer_split|timestamp|security|"
11202 		    "keep_crc on|off",
11203 	.tokens = {
11204 		(void *)&cmd_config_per_queue_rx_offload_result_port,
11205 		(void *)&cmd_config_per_queue_rx_offload_result_port_id,
11206 		(void *)&cmd_config_per_queue_rx_offload_result_rxq,
11207 		(void *)&cmd_config_per_queue_rx_offload_result_queue_id,
11208 		(void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
11209 		(void *)&cmd_config_per_queue_rx_offload_result_offload,
11210 		(void *)&cmd_config_per_queue_rx_offload_result_on_off,
11211 		NULL,
11212 	}
11213 };
11214 
11215 /* Get Tx offloads capabilities */
11216 struct cmd_tx_offload_get_capa_result {
11217 	cmdline_fixed_string_t show;
11218 	cmdline_fixed_string_t port;
11219 	portid_t port_id;
11220 	cmdline_fixed_string_t tx_offload;
11221 	cmdline_fixed_string_t capabilities;
11222 };
11223 
11224 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
11225 	TOKEN_STRING_INITIALIZER
11226 		(struct cmd_tx_offload_get_capa_result,
11227 		 show, "show");
11228 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
11229 	TOKEN_STRING_INITIALIZER
11230 		(struct cmd_tx_offload_get_capa_result,
11231 		 port, "port");
11232 static cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
11233 	TOKEN_NUM_INITIALIZER
11234 		(struct cmd_tx_offload_get_capa_result,
11235 		 port_id, RTE_UINT16);
11236 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
11237 	TOKEN_STRING_INITIALIZER
11238 		(struct cmd_tx_offload_get_capa_result,
11239 		 tx_offload, "tx_offload");
11240 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
11241 	TOKEN_STRING_INITIALIZER
11242 		(struct cmd_tx_offload_get_capa_result,
11243 		 capabilities, "capabilities");
11244 
11245 static void
11246 print_tx_offloads(uint64_t offloads)
11247 {
11248 	uint64_t single_offload;
11249 	int begin;
11250 	int end;
11251 	int bit;
11252 
11253 	if (offloads == 0)
11254 		return;
11255 
11256 	begin = __builtin_ctzll(offloads);
11257 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
11258 
11259 	single_offload = 1ULL << begin;
11260 	for (bit = begin; bit < end; bit++) {
11261 		if (offloads & single_offload)
11262 			printf(" %s",
11263 			       rte_eth_dev_tx_offload_name(single_offload));
11264 		single_offload <<= 1;
11265 	}
11266 }
11267 
11268 static void
11269 cmd_tx_offload_get_capa_parsed(
11270 	void *parsed_result,
11271 	__rte_unused struct cmdline *cl,
11272 	__rte_unused void *data)
11273 {
11274 	struct cmd_tx_offload_get_capa_result *res = parsed_result;
11275 	struct rte_eth_dev_info dev_info;
11276 	portid_t port_id = res->port_id;
11277 	uint64_t queue_offloads;
11278 	uint64_t port_offloads;
11279 	int ret;
11280 
11281 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
11282 	if (ret != 0)
11283 		return;
11284 
11285 	queue_offloads = dev_info.tx_queue_offload_capa;
11286 	port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
11287 
11288 	printf("Tx Offloading Capabilities of port %d :\n", port_id);
11289 	printf("  Per Queue :");
11290 	print_tx_offloads(queue_offloads);
11291 
11292 	printf("\n");
11293 	printf("  Per Port  :");
11294 	print_tx_offloads(port_offloads);
11295 	printf("\n\n");
11296 }
11297 
11298 static cmdline_parse_inst_t cmd_tx_offload_get_capa = {
11299 	.f = cmd_tx_offload_get_capa_parsed,
11300 	.data = NULL,
11301 	.help_str = "show port <port_id> tx_offload capabilities",
11302 	.tokens = {
11303 		(void *)&cmd_tx_offload_get_capa_show,
11304 		(void *)&cmd_tx_offload_get_capa_port,
11305 		(void *)&cmd_tx_offload_get_capa_port_id,
11306 		(void *)&cmd_tx_offload_get_capa_tx_offload,
11307 		(void *)&cmd_tx_offload_get_capa_capabilities,
11308 		NULL,
11309 	}
11310 };
11311 
11312 /* Get Tx offloads configuration */
11313 struct cmd_tx_offload_get_configuration_result {
11314 	cmdline_fixed_string_t show;
11315 	cmdline_fixed_string_t port;
11316 	portid_t port_id;
11317 	cmdline_fixed_string_t tx_offload;
11318 	cmdline_fixed_string_t configuration;
11319 };
11320 
11321 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
11322 	TOKEN_STRING_INITIALIZER
11323 		(struct cmd_tx_offload_get_configuration_result,
11324 		 show, "show");
11325 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
11326 	TOKEN_STRING_INITIALIZER
11327 		(struct cmd_tx_offload_get_configuration_result,
11328 		 port, "port");
11329 static cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
11330 	TOKEN_NUM_INITIALIZER
11331 		(struct cmd_tx_offload_get_configuration_result,
11332 		 port_id, RTE_UINT16);
11333 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
11334 	TOKEN_STRING_INITIALIZER
11335 		(struct cmd_tx_offload_get_configuration_result,
11336 		 tx_offload, "tx_offload");
11337 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
11338 	TOKEN_STRING_INITIALIZER
11339 		(struct cmd_tx_offload_get_configuration_result,
11340 		 configuration, "configuration");
11341 
11342 static void
11343 cmd_tx_offload_get_configuration_parsed(
11344 	void *parsed_result,
11345 	__rte_unused struct cmdline *cl,
11346 	__rte_unused void *data)
11347 {
11348 	struct cmd_tx_offload_get_configuration_result *res = parsed_result;
11349 	struct rte_eth_dev_info dev_info;
11350 	portid_t port_id = res->port_id;
11351 	struct rte_port *port = &ports[port_id];
11352 	struct rte_eth_conf dev_conf;
11353 	uint64_t port_offloads;
11354 	uint64_t queue_offloads;
11355 	uint16_t nb_tx_queues;
11356 	int q;
11357 	int ret;
11358 
11359 	printf("Tx Offloading Configuration of port %d :\n", port_id);
11360 
11361 	ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
11362 	if (ret != 0)
11363 		return;
11364 
11365 	port_offloads = dev_conf.txmode.offloads;
11366 	printf("  Port :");
11367 	print_tx_offloads(port_offloads);
11368 	printf("\n");
11369 
11370 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
11371 	if (ret != 0)
11372 		return;
11373 
11374 	nb_tx_queues = dev_info.nb_tx_queues;
11375 	for (q = 0; q < nb_tx_queues; q++) {
11376 		queue_offloads = port->txq[q].conf.offloads;
11377 		printf("  Queue[%2d] :", q);
11378 		print_tx_offloads(queue_offloads);
11379 		printf("\n");
11380 	}
11381 	printf("\n");
11382 }
11383 
11384 static cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
11385 	.f = cmd_tx_offload_get_configuration_parsed,
11386 	.data = NULL,
11387 	.help_str = "show port <port_id> tx_offload configuration",
11388 	.tokens = {
11389 		(void *)&cmd_tx_offload_get_configuration_show,
11390 		(void *)&cmd_tx_offload_get_configuration_port,
11391 		(void *)&cmd_tx_offload_get_configuration_port_id,
11392 		(void *)&cmd_tx_offload_get_configuration_tx_offload,
11393 		(void *)&cmd_tx_offload_get_configuration_configuration,
11394 		NULL,
11395 	}
11396 };
11397 
11398 /* Enable/Disable a per port offloading */
11399 struct cmd_config_per_port_tx_offload_result {
11400 	cmdline_fixed_string_t port;
11401 	cmdline_fixed_string_t config;
11402 	portid_t port_id;
11403 	cmdline_fixed_string_t tx_offload;
11404 	cmdline_fixed_string_t offload;
11405 	cmdline_fixed_string_t on_off;
11406 };
11407 
11408 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
11409 	TOKEN_STRING_INITIALIZER
11410 		(struct cmd_config_per_port_tx_offload_result,
11411 		 port, "port");
11412 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
11413 	TOKEN_STRING_INITIALIZER
11414 		(struct cmd_config_per_port_tx_offload_result,
11415 		 config, "config");
11416 static cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
11417 	TOKEN_NUM_INITIALIZER
11418 		(struct cmd_config_per_port_tx_offload_result,
11419 		 port_id, RTE_UINT16);
11420 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
11421 	TOKEN_STRING_INITIALIZER
11422 		(struct cmd_config_per_port_tx_offload_result,
11423 		 tx_offload, "tx_offload");
11424 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
11425 	TOKEN_STRING_INITIALIZER
11426 		(struct cmd_config_per_port_tx_offload_result,
11427 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
11428 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
11429 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
11430 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
11431 			  "mt_lockfree#multi_segs#mbuf_fast_free#security#"
11432 			  "send_on_timestamp");
11433 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
11434 	TOKEN_STRING_INITIALIZER
11435 		(struct cmd_config_per_port_tx_offload_result,
11436 		 on_off, "on#off");
11437 
11438 static uint64_t
11439 search_tx_offload(const char *name)
11440 {
11441 	uint64_t single_offload;
11442 	const char *single_name;
11443 	int found = 0;
11444 	unsigned int bit;
11445 
11446 	single_offload = 1;
11447 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
11448 		single_name = rte_eth_dev_tx_offload_name(single_offload);
11449 		if (single_name == NULL)
11450 			break;
11451 		if (!strcasecmp(single_name, name)) {
11452 			found = 1;
11453 			break;
11454 		} else if (!strcasecmp(single_name, "UNKNOWN"))
11455 			break;
11456 		single_offload <<= 1;
11457 	}
11458 
11459 	if (found)
11460 		return single_offload;
11461 
11462 	return 0;
11463 }
11464 
11465 static void
11466 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
11467 				__rte_unused struct cmdline *cl,
11468 				__rte_unused void *data)
11469 {
11470 	struct cmd_config_per_port_tx_offload_result *res = parsed_result;
11471 	portid_t port_id = res->port_id;
11472 	struct rte_eth_dev_info dev_info;
11473 	struct rte_port *port = &ports[port_id];
11474 	uint64_t single_offload;
11475 	uint16_t nb_tx_queues;
11476 	int q;
11477 	int ret;
11478 
11479 	if (port->port_status != RTE_PORT_STOPPED) {
11480 		fprintf(stderr,
11481 			"Error: Can't config offload when Port %d is not stopped\n",
11482 			port_id);
11483 		return;
11484 	}
11485 
11486 	single_offload = search_tx_offload(res->offload);
11487 	if (single_offload == 0) {
11488 		fprintf(stderr, "Unknown offload name: %s\n", res->offload);
11489 		return;
11490 	}
11491 
11492 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
11493 	if (ret != 0)
11494 		return;
11495 
11496 	nb_tx_queues = dev_info.nb_tx_queues;
11497 	if (!strcmp(res->on_off, "on")) {
11498 		port->dev_conf.txmode.offloads |= single_offload;
11499 		for (q = 0; q < nb_tx_queues; q++)
11500 			port->txq[q].conf.offloads |= single_offload;
11501 	} else {
11502 		port->dev_conf.txmode.offloads &= ~single_offload;
11503 		for (q = 0; q < nb_tx_queues; q++)
11504 			port->txq[q].conf.offloads &= ~single_offload;
11505 	}
11506 
11507 	cmd_reconfig_device_queue(port_id, 1, 1);
11508 }
11509 
11510 static cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
11511 	.f = cmd_config_per_port_tx_offload_parsed,
11512 	.data = NULL,
11513 	.help_str = "port config <port_id> tx_offload "
11514 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
11515 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
11516 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
11517 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
11518 		    "mt_lockfree|multi_segs|mbuf_fast_free|security|"
11519 		    "send_on_timestamp on|off",
11520 	.tokens = {
11521 		(void *)&cmd_config_per_port_tx_offload_result_port,
11522 		(void *)&cmd_config_per_port_tx_offload_result_config,
11523 		(void *)&cmd_config_per_port_tx_offload_result_port_id,
11524 		(void *)&cmd_config_per_port_tx_offload_result_tx_offload,
11525 		(void *)&cmd_config_per_port_tx_offload_result_offload,
11526 		(void *)&cmd_config_per_port_tx_offload_result_on_off,
11527 		NULL,
11528 	}
11529 };
11530 
11531 /* Enable/Disable a per queue offloading */
11532 struct cmd_config_per_queue_tx_offload_result {
11533 	cmdline_fixed_string_t port;
11534 	portid_t port_id;
11535 	cmdline_fixed_string_t txq;
11536 	uint16_t queue_id;
11537 	cmdline_fixed_string_t tx_offload;
11538 	cmdline_fixed_string_t offload;
11539 	cmdline_fixed_string_t on_off;
11540 };
11541 
11542 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
11543 	TOKEN_STRING_INITIALIZER
11544 		(struct cmd_config_per_queue_tx_offload_result,
11545 		 port, "port");
11546 static cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
11547 	TOKEN_NUM_INITIALIZER
11548 		(struct cmd_config_per_queue_tx_offload_result,
11549 		 port_id, RTE_UINT16);
11550 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
11551 	TOKEN_STRING_INITIALIZER
11552 		(struct cmd_config_per_queue_tx_offload_result,
11553 		 txq, "txq");
11554 static cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
11555 	TOKEN_NUM_INITIALIZER
11556 		(struct cmd_config_per_queue_tx_offload_result,
11557 		 queue_id, RTE_UINT16);
11558 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
11559 	TOKEN_STRING_INITIALIZER
11560 		(struct cmd_config_per_queue_tx_offload_result,
11561 		 tx_offload, "tx_offload");
11562 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
11563 	TOKEN_STRING_INITIALIZER
11564 		(struct cmd_config_per_queue_tx_offload_result,
11565 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
11566 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
11567 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
11568 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
11569 			  "mt_lockfree#multi_segs#mbuf_fast_free#security");
11570 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
11571 	TOKEN_STRING_INITIALIZER
11572 		(struct cmd_config_per_queue_tx_offload_result,
11573 		 on_off, "on#off");
11574 
11575 static void
11576 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
11577 				__rte_unused struct cmdline *cl,
11578 				__rte_unused void *data)
11579 {
11580 	struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
11581 	struct rte_eth_dev_info dev_info;
11582 	portid_t port_id = res->port_id;
11583 	uint16_t queue_id = res->queue_id;
11584 	struct rte_port *port = &ports[port_id];
11585 	uint64_t single_offload;
11586 	int ret;
11587 
11588 	if (port->port_status != RTE_PORT_STOPPED) {
11589 		fprintf(stderr,
11590 			"Error: Can't config offload when Port %d is not stopped\n",
11591 			port_id);
11592 		return;
11593 	}
11594 
11595 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
11596 	if (ret != 0)
11597 		return;
11598 
11599 	if (queue_id >= dev_info.nb_tx_queues) {
11600 		fprintf(stderr,
11601 			"Error: input queue_id should be 0 ... %d\n",
11602 			dev_info.nb_tx_queues - 1);
11603 		return;
11604 	}
11605 
11606 	single_offload = search_tx_offload(res->offload);
11607 	if (single_offload == 0) {
11608 		fprintf(stderr, "Unknown offload name: %s\n", res->offload);
11609 		return;
11610 	}
11611 
11612 	if (!strcmp(res->on_off, "on"))
11613 		port->txq[queue_id].conf.offloads |= single_offload;
11614 	else
11615 		port->txq[queue_id].conf.offloads &= ~single_offload;
11616 
11617 	cmd_reconfig_device_queue(port_id, 1, 1);
11618 }
11619 
11620 static cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
11621 	.f = cmd_config_per_queue_tx_offload_parsed,
11622 	.data = NULL,
11623 	.help_str = "port <port_id> txq <queue_id> tx_offload "
11624 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
11625 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
11626 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
11627 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
11628 		    "mt_lockfree|multi_segs|mbuf_fast_free|security "
11629 		    "on|off",
11630 	.tokens = {
11631 		(void *)&cmd_config_per_queue_tx_offload_result_port,
11632 		(void *)&cmd_config_per_queue_tx_offload_result_port_id,
11633 		(void *)&cmd_config_per_queue_tx_offload_result_txq,
11634 		(void *)&cmd_config_per_queue_tx_offload_result_queue_id,
11635 		(void *)&cmd_config_per_queue_tx_offload_result_txoffload,
11636 		(void *)&cmd_config_per_queue_tx_offload_result_offload,
11637 		(void *)&cmd_config_per_queue_tx_offload_result_on_off,
11638 		NULL,
11639 	}
11640 };
11641 
11642 /* *** configure tx_metadata for specific port *** */
11643 struct cmd_config_tx_metadata_specific_result {
11644 	cmdline_fixed_string_t port;
11645 	cmdline_fixed_string_t keyword;
11646 	uint16_t port_id;
11647 	cmdline_fixed_string_t item;
11648 	uint32_t value;
11649 };
11650 
11651 static void
11652 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
11653 				__rte_unused struct cmdline *cl,
11654 				__rte_unused void *data)
11655 {
11656 	struct cmd_config_tx_metadata_specific_result *res = parsed_result;
11657 
11658 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11659 		return;
11660 	ports[res->port_id].tx_metadata = res->value;
11661 	/* Add/remove callback to insert valid metadata in every Tx packet. */
11662 	if (ports[res->port_id].tx_metadata)
11663 		add_tx_md_callback(res->port_id);
11664 	else
11665 		remove_tx_md_callback(res->port_id);
11666 	rte_flow_dynf_metadata_register();
11667 }
11668 
11669 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
11670 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
11671 			port, "port");
11672 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
11673 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
11674 			keyword, "config");
11675 static cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
11676 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
11677 			port_id, RTE_UINT16);
11678 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
11679 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
11680 			item, "tx_metadata");
11681 static cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
11682 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
11683 			value, RTE_UINT32);
11684 
11685 static cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
11686 	.f = cmd_config_tx_metadata_specific_parsed,
11687 	.data = NULL,
11688 	.help_str = "port config <port_id> tx_metadata <value>",
11689 	.tokens = {
11690 		(void *)&cmd_config_tx_metadata_specific_port,
11691 		(void *)&cmd_config_tx_metadata_specific_keyword,
11692 		(void *)&cmd_config_tx_metadata_specific_id,
11693 		(void *)&cmd_config_tx_metadata_specific_item,
11694 		(void *)&cmd_config_tx_metadata_specific_value,
11695 		NULL,
11696 	},
11697 };
11698 
11699 /* *** set dynf *** */
11700 struct cmd_config_tx_dynf_specific_result {
11701 	cmdline_fixed_string_t port;
11702 	cmdline_fixed_string_t keyword;
11703 	uint16_t port_id;
11704 	cmdline_fixed_string_t item;
11705 	cmdline_fixed_string_t name;
11706 	cmdline_fixed_string_t value;
11707 };
11708 
11709 static void
11710 cmd_config_dynf_specific_parsed(void *parsed_result,
11711 				__rte_unused struct cmdline *cl,
11712 				__rte_unused void *data)
11713 {
11714 	struct cmd_config_tx_dynf_specific_result *res = parsed_result;
11715 	struct rte_mbuf_dynflag desc_flag;
11716 	int flag;
11717 	uint64_t old_port_flags;
11718 
11719 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11720 		return;
11721 	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
11722 	if (flag <= 0) {
11723 		if (strlcpy(desc_flag.name, res->name,
11724 			    RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
11725 			fprintf(stderr, "Flag name too long\n");
11726 			return;
11727 		}
11728 		desc_flag.flags = 0;
11729 		flag = rte_mbuf_dynflag_register(&desc_flag);
11730 		if (flag < 0) {
11731 			fprintf(stderr, "Can't register flag\n");
11732 			return;
11733 		}
11734 		strcpy(dynf_names[flag], desc_flag.name);
11735 	}
11736 	old_port_flags = ports[res->port_id].mbuf_dynf;
11737 	if (!strcmp(res->value, "set")) {
11738 		ports[res->port_id].mbuf_dynf |= 1UL << flag;
11739 		if (old_port_flags == 0)
11740 			add_tx_dynf_callback(res->port_id);
11741 	} else {
11742 		ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
11743 		if (ports[res->port_id].mbuf_dynf == 0)
11744 			remove_tx_dynf_callback(res->port_id);
11745 	}
11746 }
11747 
11748 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
11749 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
11750 			keyword, "port");
11751 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
11752 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
11753 			keyword, "config");
11754 static cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
11755 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
11756 			port_id, RTE_UINT16);
11757 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
11758 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
11759 			item, "dynf");
11760 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
11761 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
11762 			name, NULL);
11763 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
11764 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
11765 			value, "set#clear");
11766 
11767 static cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
11768 	.f = cmd_config_dynf_specific_parsed,
11769 	.data = NULL,
11770 	.help_str = "port config <port id> dynf <name> set|clear",
11771 	.tokens = {
11772 		(void *)&cmd_config_tx_dynf_specific_port,
11773 		(void *)&cmd_config_tx_dynf_specific_keyword,
11774 		(void *)&cmd_config_tx_dynf_specific_port_id,
11775 		(void *)&cmd_config_tx_dynf_specific_item,
11776 		(void *)&cmd_config_tx_dynf_specific_name,
11777 		(void *)&cmd_config_tx_dynf_specific_value,
11778 		NULL,
11779 	},
11780 };
11781 
11782 /* *** display tx_metadata per port configuration *** */
11783 struct cmd_show_tx_metadata_result {
11784 	cmdline_fixed_string_t cmd_show;
11785 	cmdline_fixed_string_t cmd_port;
11786 	cmdline_fixed_string_t cmd_keyword;
11787 	portid_t cmd_pid;
11788 };
11789 
11790 static void
11791 cmd_show_tx_metadata_parsed(void *parsed_result,
11792 		__rte_unused struct cmdline *cl,
11793 		__rte_unused void *data)
11794 {
11795 	struct cmd_show_tx_metadata_result *res = parsed_result;
11796 
11797 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
11798 		fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
11799 		return;
11800 	}
11801 	if (!strcmp(res->cmd_keyword, "tx_metadata")) {
11802 		printf("Port %u tx_metadata: %u\n", res->cmd_pid,
11803 		       ports[res->cmd_pid].tx_metadata);
11804 	}
11805 }
11806 
11807 static cmdline_parse_token_string_t cmd_show_tx_metadata_show =
11808 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
11809 			cmd_show, "show");
11810 static cmdline_parse_token_string_t cmd_show_tx_metadata_port =
11811 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
11812 			cmd_port, "port");
11813 static cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
11814 	TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
11815 			cmd_pid, RTE_UINT16);
11816 static cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
11817 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
11818 			cmd_keyword, "tx_metadata");
11819 
11820 static cmdline_parse_inst_t cmd_show_tx_metadata = {
11821 	.f = cmd_show_tx_metadata_parsed,
11822 	.data = NULL,
11823 	.help_str = "show port <port_id> tx_metadata",
11824 	.tokens = {
11825 		(void *)&cmd_show_tx_metadata_show,
11826 		(void *)&cmd_show_tx_metadata_port,
11827 		(void *)&cmd_show_tx_metadata_pid,
11828 		(void *)&cmd_show_tx_metadata_keyword,
11829 		NULL,
11830 	},
11831 };
11832 
11833 /* *** show fec capability per port configuration *** */
11834 struct cmd_show_fec_capability_result {
11835 	cmdline_fixed_string_t cmd_show;
11836 	cmdline_fixed_string_t cmd_port;
11837 	cmdline_fixed_string_t cmd_fec;
11838 	cmdline_fixed_string_t cmd_keyword;
11839 	portid_t cmd_pid;
11840 };
11841 
11842 static void
11843 cmd_show_fec_capability_parsed(void *parsed_result,
11844 		__rte_unused struct cmdline *cl,
11845 		__rte_unused void *data)
11846 {
11847 	struct cmd_show_fec_capability_result *res = parsed_result;
11848 	struct rte_eth_fec_capa *speed_fec_capa;
11849 	unsigned int num;
11850 	int ret;
11851 
11852 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
11853 		fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
11854 		return;
11855 	}
11856 
11857 	ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
11858 	if (ret == -ENOTSUP) {
11859 		fprintf(stderr, "Function not implemented\n");
11860 		return;
11861 	} else if (ret < 0) {
11862 		fprintf(stderr, "Get FEC capability failed: %d\n", ret);
11863 		return;
11864 	}
11865 
11866 	num = (unsigned int)ret;
11867 	speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
11868 	if (speed_fec_capa == NULL) {
11869 		fprintf(stderr, "Failed to alloc FEC capability buffer\n");
11870 		return;
11871 	}
11872 
11873 	ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
11874 	if (ret < 0) {
11875 		fprintf(stderr, "Error getting FEC capability: %d\n", ret);
11876 		goto out;
11877 	}
11878 
11879 	show_fec_capability(num, speed_fec_capa);
11880 out:
11881 	free(speed_fec_capa);
11882 }
11883 
11884 static cmdline_parse_token_string_t cmd_show_fec_capability_show =
11885 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
11886 			cmd_show, "show");
11887 static cmdline_parse_token_string_t cmd_show_fec_capability_port =
11888 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
11889 			cmd_port, "port");
11890 static cmdline_parse_token_num_t cmd_show_fec_capability_pid =
11891 	TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
11892 			cmd_pid, RTE_UINT16);
11893 static cmdline_parse_token_string_t cmd_show_fec_capability_fec =
11894 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
11895 			cmd_fec, "fec");
11896 static cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
11897 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
11898 			cmd_keyword, "capabilities");
11899 
11900 static cmdline_parse_inst_t cmd_show_capability = {
11901 	.f = cmd_show_fec_capability_parsed,
11902 	.data = NULL,
11903 	.help_str = "show port <port_id> fec capabilities",
11904 	.tokens = {
11905 		(void *)&cmd_show_fec_capability_show,
11906 		(void *)&cmd_show_fec_capability_port,
11907 		(void *)&cmd_show_fec_capability_pid,
11908 		(void *)&cmd_show_fec_capability_fec,
11909 		(void *)&cmd_show_fec_capability_keyword,
11910 		NULL,
11911 	},
11912 };
11913 
11914 /* *** show fec mode per port configuration *** */
11915 struct cmd_show_fec_metadata_result {
11916 	cmdline_fixed_string_t cmd_show;
11917 	cmdline_fixed_string_t cmd_port;
11918 	cmdline_fixed_string_t cmd_keyword;
11919 	portid_t cmd_pid;
11920 };
11921 
11922 static void
11923 cmd_show_fec_mode_parsed(void *parsed_result,
11924 		__rte_unused struct cmdline *cl,
11925 		__rte_unused void *data)
11926 {
11927 #define FEC_NAME_SIZE 16
11928 	struct cmd_show_fec_metadata_result *res = parsed_result;
11929 	uint32_t mode;
11930 	char buf[FEC_NAME_SIZE];
11931 	int ret;
11932 
11933 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
11934 		fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
11935 		return;
11936 	}
11937 	ret = rte_eth_fec_get(res->cmd_pid, &mode);
11938 	if (ret == -ENOTSUP) {
11939 		fprintf(stderr, "Function not implemented\n");
11940 		return;
11941 	} else if (ret < 0) {
11942 		fprintf(stderr, "Get FEC mode failed\n");
11943 		return;
11944 	}
11945 
11946 	switch (mode) {
11947 	case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
11948 		strlcpy(buf, "off", sizeof(buf));
11949 		break;
11950 	case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
11951 		strlcpy(buf, "auto", sizeof(buf));
11952 		break;
11953 	case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
11954 		strlcpy(buf, "baser", sizeof(buf));
11955 		break;
11956 	case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
11957 		strlcpy(buf, "rs", sizeof(buf));
11958 		break;
11959 	default:
11960 		return;
11961 	}
11962 
11963 	printf("%s\n", buf);
11964 }
11965 
11966 static cmdline_parse_token_string_t cmd_show_fec_mode_show =
11967 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
11968 			cmd_show, "show");
11969 static cmdline_parse_token_string_t cmd_show_fec_mode_port =
11970 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
11971 			cmd_port, "port");
11972 static cmdline_parse_token_num_t cmd_show_fec_mode_pid =
11973 	TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
11974 			cmd_pid, RTE_UINT16);
11975 static cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
11976 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
11977 			cmd_keyword, "fec_mode");
11978 
11979 static cmdline_parse_inst_t cmd_show_fec_mode = {
11980 	.f = cmd_show_fec_mode_parsed,
11981 	.data = NULL,
11982 	.help_str = "show port <port_id> fec_mode",
11983 	.tokens = {
11984 		(void *)&cmd_show_fec_mode_show,
11985 		(void *)&cmd_show_fec_mode_port,
11986 		(void *)&cmd_show_fec_mode_pid,
11987 		(void *)&cmd_show_fec_mode_keyword,
11988 		NULL,
11989 	},
11990 };
11991 
11992 /* *** set fec mode per port configuration *** */
11993 struct cmd_set_port_fec_mode {
11994 	cmdline_fixed_string_t set;
11995 	cmdline_fixed_string_t port;
11996 	portid_t port_id;
11997 	cmdline_fixed_string_t fec_mode;
11998 	cmdline_fixed_string_t fec_value;
11999 };
12000 
12001 /* Common CLI fields for set fec mode */
12002 static cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
12003 	TOKEN_STRING_INITIALIZER
12004 		(struct cmd_set_port_fec_mode,
12005 		 set, "set");
12006 static cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
12007 	TOKEN_STRING_INITIALIZER
12008 		(struct cmd_set_port_fec_mode,
12009 		 port, "port");
12010 static cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
12011 	TOKEN_NUM_INITIALIZER
12012 		(struct cmd_set_port_fec_mode,
12013 		 port_id, RTE_UINT16);
12014 static cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
12015 	TOKEN_STRING_INITIALIZER
12016 		(struct cmd_set_port_fec_mode,
12017 		 fec_mode, "fec_mode");
12018 static cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
12019 	TOKEN_STRING_INITIALIZER
12020 		(struct cmd_set_port_fec_mode,
12021 		 fec_value, NULL);
12022 
12023 static void
12024 cmd_set_port_fec_mode_parsed(
12025 	void *parsed_result,
12026 	__rte_unused struct cmdline *cl,
12027 	__rte_unused void *data)
12028 {
12029 	struct cmd_set_port_fec_mode *res = parsed_result;
12030 	uint16_t port_id = res->port_id;
12031 	uint32_t fec_capa;
12032 	int ret;
12033 
12034 	ret = parse_fec_mode(res->fec_value, &fec_capa);
12035 	if (ret < 0) {
12036 		fprintf(stderr, "Unknown fec mode: %s for port %d\n",
12037 				res->fec_value,	port_id);
12038 		return;
12039 	}
12040 
12041 	ret = rte_eth_fec_set(port_id, fec_capa);
12042 	if (ret == -ENOTSUP) {
12043 		fprintf(stderr, "Function not implemented\n");
12044 		return;
12045 	} else if (ret < 0) {
12046 		fprintf(stderr, "Set FEC mode failed\n");
12047 		return;
12048 	}
12049 }
12050 
12051 static cmdline_parse_inst_t cmd_set_fec_mode = {
12052 	.f = cmd_set_port_fec_mode_parsed,
12053 	.data = NULL,
12054 	.help_str = "set port <port_id> fec_mode auto|off|rs|baser",
12055 	.tokens = {
12056 		(void *)&cmd_set_port_fec_mode_set,
12057 		(void *)&cmd_set_port_fec_mode_port,
12058 		(void *)&cmd_set_port_fec_mode_port_id,
12059 		(void *)&cmd_set_port_fec_mode_str,
12060 		(void *)&cmd_set_port_fec_mode_value,
12061 		NULL,
12062 	},
12063 };
12064 
12065 /* *** set available descriptors threshold for an RxQ of a port *** */
12066 struct cmd_set_rxq_avail_thresh_result {
12067 	cmdline_fixed_string_t set;
12068 	cmdline_fixed_string_t port;
12069 	uint16_t port_num;
12070 	cmdline_fixed_string_t rxq;
12071 	uint16_t rxq_num;
12072 	cmdline_fixed_string_t avail_thresh;
12073 	uint8_t avail_thresh_num;
12074 };
12075 
12076 static void cmd_set_rxq_avail_thresh_parsed(void *parsed_result,
12077 		__rte_unused struct cmdline *cl,
12078 		__rte_unused void *data)
12079 {
12080 	struct cmd_set_rxq_avail_thresh_result *res = parsed_result;
12081 	int ret = 0;
12082 
12083 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
12084 	    && (strcmp(res->rxq, "rxq") == 0)
12085 	    && (strcmp(res->avail_thresh, "avail_thresh") == 0))
12086 		ret = set_rxq_avail_thresh(res->port_num, res->rxq_num,
12087 				  res->avail_thresh_num);
12088 	if (ret < 0)
12089 		printf("rxq_avail_thresh_cmd error: (%s)\n", strerror(-ret));
12090 
12091 }
12092 
12093 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_set =
12094 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
12095 				set, "set");
12096 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_port =
12097 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
12098 				port, "port");
12099 static cmdline_parse_token_num_t cmd_set_rxq_avail_thresh_portnum =
12100 	TOKEN_NUM_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
12101 				port_num, RTE_UINT16);
12102 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_rxq =
12103 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
12104 				rxq, "rxq");
12105 static cmdline_parse_token_num_t cmd_set_rxq_avail_thresh_rxqnum =
12106 	TOKEN_NUM_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
12107 				rxq_num, RTE_UINT16);
12108 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_avail_thresh =
12109 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
12110 				avail_thresh, "avail_thresh");
12111 static cmdline_parse_token_num_t cmd_set_rxq_avail_thresh_avail_threshnum =
12112 	TOKEN_NUM_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
12113 				avail_thresh_num, RTE_UINT8);
12114 
12115 static cmdline_parse_inst_t cmd_set_rxq_avail_thresh = {
12116 	.f = cmd_set_rxq_avail_thresh_parsed,
12117 	.data = (void *)0,
12118 	.help_str =
12119 		"set port <port_id> rxq <queue_id> avail_thresh <0..99>: "
12120 		"Set available descriptors threshold for Rx queue",
12121 	.tokens = {
12122 		(void *)&cmd_set_rxq_avail_thresh_set,
12123 		(void *)&cmd_set_rxq_avail_thresh_port,
12124 		(void *)&cmd_set_rxq_avail_thresh_portnum,
12125 		(void *)&cmd_set_rxq_avail_thresh_rxq,
12126 		(void *)&cmd_set_rxq_avail_thresh_rxqnum,
12127 		(void *)&cmd_set_rxq_avail_thresh_avail_thresh,
12128 		(void *)&cmd_set_rxq_avail_thresh_avail_threshnum,
12129 		NULL,
12130 	},
12131 };
12132 
12133 /* show port supported ptypes */
12134 
12135 /* Common result structure for show port ptypes */
12136 struct cmd_show_port_supported_ptypes_result {
12137 	cmdline_fixed_string_t show;
12138 	cmdline_fixed_string_t port;
12139 	portid_t port_id;
12140 	cmdline_fixed_string_t ptypes;
12141 };
12142 
12143 /* Common CLI fields for show port ptypes */
12144 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
12145 	TOKEN_STRING_INITIALIZER
12146 		(struct cmd_show_port_supported_ptypes_result,
12147 		 show, "show");
12148 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
12149 	TOKEN_STRING_INITIALIZER
12150 		(struct cmd_show_port_supported_ptypes_result,
12151 		 port, "port");
12152 static cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
12153 	TOKEN_NUM_INITIALIZER
12154 		(struct cmd_show_port_supported_ptypes_result,
12155 		 port_id, RTE_UINT16);
12156 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
12157 	TOKEN_STRING_INITIALIZER
12158 		(struct cmd_show_port_supported_ptypes_result,
12159 		 ptypes, "ptypes");
12160 
12161 static void
12162 cmd_show_port_supported_ptypes_parsed(
12163 	void *parsed_result,
12164 	__rte_unused struct cmdline *cl,
12165 	__rte_unused void *data)
12166 {
12167 #define RSVD_PTYPE_MASK       0xf0000000
12168 #define MAX_PTYPES_PER_LAYER  16
12169 #define LTYPE_NAMESIZE        32
12170 #define PTYPE_NAMESIZE        256
12171 	struct cmd_show_port_supported_ptypes_result *res = parsed_result;
12172 	char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
12173 	uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
12174 	uint32_t ptypes[MAX_PTYPES_PER_LAYER];
12175 	uint16_t port_id = res->port_id;
12176 	int ret, i;
12177 
12178 	ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
12179 	if (ret < 0)
12180 		return;
12181 
12182 	while (ptype_mask != RSVD_PTYPE_MASK) {
12183 
12184 		switch (ptype_mask) {
12185 		case RTE_PTYPE_L2_MASK:
12186 			strlcpy(ltype, "L2", sizeof(ltype));
12187 			break;
12188 		case RTE_PTYPE_L3_MASK:
12189 			strlcpy(ltype, "L3", sizeof(ltype));
12190 			break;
12191 		case RTE_PTYPE_L4_MASK:
12192 			strlcpy(ltype, "L4", sizeof(ltype));
12193 			break;
12194 		case RTE_PTYPE_TUNNEL_MASK:
12195 			strlcpy(ltype, "Tunnel", sizeof(ltype));
12196 			break;
12197 		case RTE_PTYPE_INNER_L2_MASK:
12198 			strlcpy(ltype, "Inner L2", sizeof(ltype));
12199 			break;
12200 		case RTE_PTYPE_INNER_L3_MASK:
12201 			strlcpy(ltype, "Inner L3", sizeof(ltype));
12202 			break;
12203 		case RTE_PTYPE_INNER_L4_MASK:
12204 			strlcpy(ltype, "Inner L4", sizeof(ltype));
12205 			break;
12206 		default:
12207 			return;
12208 		}
12209 
12210 		ret = rte_eth_dev_get_supported_ptypes(res->port_id,
12211 						       ptype_mask, ptypes,
12212 						       MAX_PTYPES_PER_LAYER);
12213 
12214 		if (ret > 0)
12215 			printf("Supported %s ptypes:\n", ltype);
12216 		else
12217 			printf("%s ptypes unsupported\n", ltype);
12218 
12219 		for (i = 0; i < ret; ++i) {
12220 			rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
12221 			printf("%s\n", buf);
12222 		}
12223 
12224 		ptype_mask <<= 4;
12225 	}
12226 }
12227 
12228 static cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
12229 	.f = cmd_show_port_supported_ptypes_parsed,
12230 	.data = NULL,
12231 	.help_str = "show port <port_id> ptypes",
12232 	.tokens = {
12233 		(void *)&cmd_show_port_supported_ptypes_show,
12234 		(void *)&cmd_show_port_supported_ptypes_port,
12235 		(void *)&cmd_show_port_supported_ptypes_port_id,
12236 		(void *)&cmd_show_port_supported_ptypes_ptypes,
12237 		NULL,
12238 	},
12239 };
12240 
12241 /* *** display rx/tx descriptor status *** */
12242 struct cmd_show_rx_tx_desc_status_result {
12243 	cmdline_fixed_string_t cmd_show;
12244 	cmdline_fixed_string_t cmd_port;
12245 	cmdline_fixed_string_t cmd_keyword;
12246 	cmdline_fixed_string_t cmd_desc;
12247 	cmdline_fixed_string_t cmd_status;
12248 	portid_t cmd_pid;
12249 	portid_t cmd_qid;
12250 	portid_t cmd_did;
12251 };
12252 
12253 static void
12254 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
12255 		__rte_unused struct cmdline *cl,
12256 		__rte_unused void *data)
12257 {
12258 	struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
12259 	int rc;
12260 
12261 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
12262 		fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
12263 		return;
12264 	}
12265 
12266 	if (!strcmp(res->cmd_keyword, "rxq")) {
12267 		rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
12268 					     res->cmd_did);
12269 		if (rc < 0) {
12270 			fprintf(stderr,
12271 				"Invalid input: queue id = %d, desc id = %d\n",
12272 				res->cmd_qid, res->cmd_did);
12273 			return;
12274 		}
12275 		if (rc == RTE_ETH_RX_DESC_AVAIL)
12276 			printf("Desc status = AVAILABLE\n");
12277 		else if (rc == RTE_ETH_RX_DESC_DONE)
12278 			printf("Desc status = DONE\n");
12279 		else
12280 			printf("Desc status = UNAVAILABLE\n");
12281 	} else if (!strcmp(res->cmd_keyword, "txq")) {
12282 		rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
12283 					     res->cmd_did);
12284 		if (rc < 0) {
12285 			fprintf(stderr,
12286 				"Invalid input: queue id = %d, desc id = %d\n",
12287 				res->cmd_qid, res->cmd_did);
12288 			return;
12289 		}
12290 		if (rc == RTE_ETH_TX_DESC_FULL)
12291 			printf("Desc status = FULL\n");
12292 		else if (rc == RTE_ETH_TX_DESC_DONE)
12293 			printf("Desc status = DONE\n");
12294 		else
12295 			printf("Desc status = UNAVAILABLE\n");
12296 	}
12297 }
12298 
12299 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
12300 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
12301 			cmd_show, "show");
12302 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
12303 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
12304 			cmd_port, "port");
12305 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
12306 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
12307 			cmd_pid, RTE_UINT16);
12308 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
12309 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
12310 			cmd_keyword, "rxq#txq");
12311 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
12312 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
12313 			cmd_qid, RTE_UINT16);
12314 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
12315 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
12316 			cmd_desc, "desc");
12317 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
12318 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
12319 			cmd_did, RTE_UINT16);
12320 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
12321 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
12322 			cmd_status, "status");
12323 static cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
12324 	.f = cmd_show_rx_tx_desc_status_parsed,
12325 	.data = NULL,
12326 	.help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
12327 		"status",
12328 	.tokens = {
12329 		(void *)&cmd_show_rx_tx_desc_status_show,
12330 		(void *)&cmd_show_rx_tx_desc_status_port,
12331 		(void *)&cmd_show_rx_tx_desc_status_pid,
12332 		(void *)&cmd_show_rx_tx_desc_status_keyword,
12333 		(void *)&cmd_show_rx_tx_desc_status_qid,
12334 		(void *)&cmd_show_rx_tx_desc_status_desc,
12335 		(void *)&cmd_show_rx_tx_desc_status_did,
12336 		(void *)&cmd_show_rx_tx_desc_status_status,
12337 		NULL,
12338 	},
12339 };
12340 
12341 /* *** display rx queue desc used count *** */
12342 struct cmd_show_rx_queue_desc_used_count_result {
12343 	cmdline_fixed_string_t cmd_show;
12344 	cmdline_fixed_string_t cmd_port;
12345 	cmdline_fixed_string_t cmd_rxq;
12346 	cmdline_fixed_string_t cmd_desc;
12347 	cmdline_fixed_string_t cmd_used;
12348 	cmdline_fixed_string_t cmd_count;
12349 	portid_t cmd_pid;
12350 	portid_t cmd_qid;
12351 };
12352 
12353 static void
12354 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
12355 		__rte_unused struct cmdline *cl,
12356 		__rte_unused void *data)
12357 {
12358 	struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
12359 	int rc;
12360 
12361 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
12362 		fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
12363 		return;
12364 	}
12365 
12366 	rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
12367 	if (rc < 0) {
12368 		fprintf(stderr, "Invalid queueid = %d\n", res->cmd_qid);
12369 		return;
12370 	}
12371 	printf("Used desc count = %d\n", rc);
12372 }
12373 
12374 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
12375 	TOKEN_STRING_INITIALIZER
12376 		(struct cmd_show_rx_queue_desc_used_count_result,
12377 		 cmd_show, "show");
12378 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
12379 	TOKEN_STRING_INITIALIZER
12380 		(struct cmd_show_rx_queue_desc_used_count_result,
12381 		 cmd_port, "port");
12382 static cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
12383 	TOKEN_NUM_INITIALIZER
12384 		(struct cmd_show_rx_queue_desc_used_count_result,
12385 		 cmd_pid, RTE_UINT16);
12386 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
12387 	TOKEN_STRING_INITIALIZER
12388 		(struct cmd_show_rx_queue_desc_used_count_result,
12389 		 cmd_rxq, "rxq");
12390 static cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
12391 	TOKEN_NUM_INITIALIZER
12392 		(struct cmd_show_rx_queue_desc_used_count_result,
12393 		 cmd_qid, RTE_UINT16);
12394 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
12395 	TOKEN_STRING_INITIALIZER
12396 		(struct cmd_show_rx_queue_desc_used_count_result,
12397 		 cmd_count, "desc");
12398 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
12399 	TOKEN_STRING_INITIALIZER
12400 		(struct cmd_show_rx_queue_desc_used_count_result,
12401 		 cmd_count, "used");
12402 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
12403 	TOKEN_STRING_INITIALIZER
12404 		(struct cmd_show_rx_queue_desc_used_count_result,
12405 		 cmd_count, "count");
12406 static cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
12407 	.f = cmd_show_rx_queue_desc_used_count_parsed,
12408 	.data = NULL,
12409 	.help_str = "show port <port_id> rxq <queue_id> desc used count",
12410 	.tokens = {
12411 		(void *)&cmd_show_rx_queue_desc_used_count_show,
12412 		(void *)&cmd_show_rx_queue_desc_used_count_port,
12413 		(void *)&cmd_show_rx_queue_desc_used_count_pid,
12414 		(void *)&cmd_show_rx_queue_desc_used_count_rxq,
12415 		(void *)&cmd_show_rx_queue_desc_used_count_qid,
12416 		(void *)&cmd_show_rx_queue_desc_used_count_desc,
12417 		(void *)&cmd_show_rx_queue_desc_used_count_used,
12418 		(void *)&cmd_show_rx_queue_desc_used_count_count,
12419 		NULL,
12420 	},
12421 };
12422 
12423 /* Common result structure for set port ptypes */
12424 struct cmd_set_port_ptypes_result {
12425 	cmdline_fixed_string_t set;
12426 	cmdline_fixed_string_t port;
12427 	portid_t port_id;
12428 	cmdline_fixed_string_t ptype_mask;
12429 	uint32_t mask;
12430 };
12431 
12432 /* Common CLI fields for set port ptypes */
12433 static cmdline_parse_token_string_t cmd_set_port_ptypes_set =
12434 	TOKEN_STRING_INITIALIZER
12435 		(struct cmd_set_port_ptypes_result,
12436 		 set, "set");
12437 static cmdline_parse_token_string_t cmd_set_port_ptypes_port =
12438 	TOKEN_STRING_INITIALIZER
12439 		(struct cmd_set_port_ptypes_result,
12440 		 port, "port");
12441 static cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
12442 	TOKEN_NUM_INITIALIZER
12443 		(struct cmd_set_port_ptypes_result,
12444 		 port_id, RTE_UINT16);
12445 static cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
12446 	TOKEN_STRING_INITIALIZER
12447 		(struct cmd_set_port_ptypes_result,
12448 		 ptype_mask, "ptype_mask");
12449 static cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
12450 	TOKEN_NUM_INITIALIZER
12451 		(struct cmd_set_port_ptypes_result,
12452 		 mask, RTE_UINT32);
12453 
12454 static void
12455 cmd_set_port_ptypes_parsed(
12456 	void *parsed_result,
12457 	__rte_unused struct cmdline *cl,
12458 	__rte_unused void *data)
12459 {
12460 	struct cmd_set_port_ptypes_result *res = parsed_result;
12461 #define PTYPE_NAMESIZE        256
12462 	char ptype_name[PTYPE_NAMESIZE];
12463 	uint16_t port_id = res->port_id;
12464 	uint32_t ptype_mask = res->mask;
12465 	int ret, i;
12466 
12467 	ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
12468 					       NULL, 0);
12469 	if (ret <= 0) {
12470 		fprintf(stderr, "Port %d doesn't support any ptypes.\n",
12471 			port_id);
12472 		return;
12473 	}
12474 
12475 	uint32_t ptypes[ret];
12476 
12477 	ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
12478 	if (ret < 0) {
12479 		fprintf(stderr, "Unable to set requested ptypes for Port %d\n",
12480 			port_id);
12481 		return;
12482 	}
12483 
12484 	printf("Successfully set following ptypes for Port %d\n", port_id);
12485 	for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
12486 		rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
12487 		printf("%s\n", ptype_name);
12488 	}
12489 
12490 	clear_ptypes = false;
12491 }
12492 
12493 static cmdline_parse_inst_t cmd_set_port_ptypes = {
12494 	.f = cmd_set_port_ptypes_parsed,
12495 	.data = NULL,
12496 	.help_str = "set port <port_id> ptype_mask <mask>",
12497 	.tokens = {
12498 		(void *)&cmd_set_port_ptypes_set,
12499 		(void *)&cmd_set_port_ptypes_port,
12500 		(void *)&cmd_set_port_ptypes_port_id,
12501 		(void *)&cmd_set_port_ptypes_mask_str,
12502 		(void *)&cmd_set_port_ptypes_mask_u32,
12503 		NULL,
12504 	},
12505 };
12506 
12507 /* *** display mac addresses added to a port *** */
12508 struct cmd_showport_macs_result {
12509 	cmdline_fixed_string_t cmd_show;
12510 	cmdline_fixed_string_t cmd_port;
12511 	cmdline_fixed_string_t cmd_keyword;
12512 	portid_t cmd_pid;
12513 };
12514 
12515 static void
12516 cmd_showport_macs_parsed(void *parsed_result,
12517 		__rte_unused struct cmdline *cl,
12518 		__rte_unused void *data)
12519 {
12520 	struct cmd_showport_macs_result *res = parsed_result;
12521 
12522 	if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
12523 		return;
12524 
12525 	if (!strcmp(res->cmd_keyword, "macs"))
12526 		show_macs(res->cmd_pid);
12527 	else if (!strcmp(res->cmd_keyword, "mcast_macs"))
12528 		show_mcast_macs(res->cmd_pid);
12529 }
12530 
12531 static cmdline_parse_token_string_t cmd_showport_macs_show =
12532 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
12533 			cmd_show, "show");
12534 static cmdline_parse_token_string_t cmd_showport_macs_port =
12535 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
12536 			cmd_port, "port");
12537 static cmdline_parse_token_num_t cmd_showport_macs_pid =
12538 	TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
12539 			cmd_pid, RTE_UINT16);
12540 static cmdline_parse_token_string_t cmd_showport_macs_keyword =
12541 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
12542 			cmd_keyword, "macs#mcast_macs");
12543 
12544 static cmdline_parse_inst_t cmd_showport_macs = {
12545 	.f = cmd_showport_macs_parsed,
12546 	.data = NULL,
12547 	.help_str = "show port <port_id> macs|mcast_macs",
12548 	.tokens = {
12549 		(void *)&cmd_showport_macs_show,
12550 		(void *)&cmd_showport_macs_port,
12551 		(void *)&cmd_showport_macs_pid,
12552 		(void *)&cmd_showport_macs_keyword,
12553 		NULL,
12554 	},
12555 };
12556 
12557 /* *** show flow transfer proxy port ID for the given port *** */
12558 struct cmd_show_port_flow_transfer_proxy_result {
12559 	cmdline_fixed_string_t show;
12560 	cmdline_fixed_string_t port;
12561 	portid_t port_id;
12562 	cmdline_fixed_string_t flow;
12563 	cmdline_fixed_string_t transfer;
12564 	cmdline_fixed_string_t proxy;
12565 };
12566 
12567 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_show =
12568 	TOKEN_STRING_INITIALIZER
12569 		(struct cmd_show_port_flow_transfer_proxy_result,
12570 		 show, "show");
12571 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_port =
12572 	TOKEN_STRING_INITIALIZER
12573 		(struct cmd_show_port_flow_transfer_proxy_result,
12574 		 port, "port");
12575 static cmdline_parse_token_num_t cmd_show_port_flow_transfer_proxy_port_id =
12576 	TOKEN_NUM_INITIALIZER
12577 		(struct cmd_show_port_flow_transfer_proxy_result,
12578 		 port_id, RTE_UINT16);
12579 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_flow =
12580 	TOKEN_STRING_INITIALIZER
12581 		(struct cmd_show_port_flow_transfer_proxy_result,
12582 		 flow, "flow");
12583 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_transfer =
12584 	TOKEN_STRING_INITIALIZER
12585 		(struct cmd_show_port_flow_transfer_proxy_result,
12586 		 transfer, "transfer");
12587 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_proxy =
12588 	TOKEN_STRING_INITIALIZER
12589 		(struct cmd_show_port_flow_transfer_proxy_result,
12590 		 proxy, "proxy");
12591 
12592 static void
12593 cmd_show_port_flow_transfer_proxy_parsed(void *parsed_result,
12594 					 __rte_unused struct cmdline *cl,
12595 					 __rte_unused void *data)
12596 {
12597 	struct cmd_show_port_flow_transfer_proxy_result *res = parsed_result;
12598 	portid_t proxy_port_id;
12599 	int ret;
12600 
12601 	printf("\n");
12602 
12603 	ret = rte_flow_pick_transfer_proxy(res->port_id, &proxy_port_id, NULL);
12604 	if (ret != 0) {
12605 		fprintf(stderr, "Failed to pick transfer proxy: %s\n",
12606 			rte_strerror(-ret));
12607 		return;
12608 	}
12609 
12610 	printf("Transfer proxy port ID: %u\n\n", proxy_port_id);
12611 }
12612 
12613 static cmdline_parse_inst_t cmd_show_port_flow_transfer_proxy = {
12614 	.f = cmd_show_port_flow_transfer_proxy_parsed,
12615 	.data = NULL,
12616 	.help_str = "show port <port_id> flow transfer proxy",
12617 	.tokens = {
12618 		(void *)&cmd_show_port_flow_transfer_proxy_show,
12619 		(void *)&cmd_show_port_flow_transfer_proxy_port,
12620 		(void *)&cmd_show_port_flow_transfer_proxy_port_id,
12621 		(void *)&cmd_show_port_flow_transfer_proxy_flow,
12622 		(void *)&cmd_show_port_flow_transfer_proxy_transfer,
12623 		(void *)&cmd_show_port_flow_transfer_proxy_proxy,
12624 		NULL,
12625 	}
12626 };
12627 
12628 /* ******************************************************************************** */
12629 
12630 /* list of instructions */
12631 static cmdline_parse_ctx_t builtin_ctx[] = {
12632 	(cmdline_parse_inst_t *)&cmd_help_brief,
12633 	(cmdline_parse_inst_t *)&cmd_help_long,
12634 	(cmdline_parse_inst_t *)&cmd_quit,
12635 	(cmdline_parse_inst_t *)&cmd_load_from_file,
12636 	(cmdline_parse_inst_t *)&cmd_showport,
12637 	(cmdline_parse_inst_t *)&cmd_showqueue,
12638 	(cmdline_parse_inst_t *)&cmd_showeeprom,
12639 	(cmdline_parse_inst_t *)&cmd_showportall,
12640 	(cmdline_parse_inst_t *)&cmd_representor_info,
12641 	(cmdline_parse_inst_t *)&cmd_showdevice,
12642 	(cmdline_parse_inst_t *)&cmd_showcfg,
12643 	(cmdline_parse_inst_t *)&cmd_showfwdall,
12644 	(cmdline_parse_inst_t *)&cmd_start,
12645 	(cmdline_parse_inst_t *)&cmd_start_tx_first,
12646 	(cmdline_parse_inst_t *)&cmd_start_tx_first_n,
12647 	(cmdline_parse_inst_t *)&cmd_set_link_up,
12648 	(cmdline_parse_inst_t *)&cmd_set_link_down,
12649 	(cmdline_parse_inst_t *)&cmd_reset,
12650 	(cmdline_parse_inst_t *)&cmd_set_numbers,
12651 	(cmdline_parse_inst_t *)&cmd_set_log,
12652 	(cmdline_parse_inst_t *)&cmd_set_rxoffs,
12653 	(cmdline_parse_inst_t *)&cmd_set_rxpkts,
12654 	(cmdline_parse_inst_t *)&cmd_set_rxhdrs,
12655 	(cmdline_parse_inst_t *)&cmd_set_txpkts,
12656 	(cmdline_parse_inst_t *)&cmd_set_txsplit,
12657 	(cmdline_parse_inst_t *)&cmd_set_txtimes,
12658 	(cmdline_parse_inst_t *)&cmd_set_fwd_list,
12659 	(cmdline_parse_inst_t *)&cmd_set_fwd_mask,
12660 	(cmdline_parse_inst_t *)&cmd_set_fwd_mode,
12661 	(cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
12662 	(cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
12663 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
12664 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
12665 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
12666 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
12667 	(cmdline_parse_inst_t *)&cmd_set_flush_rx,
12668 	(cmdline_parse_inst_t *)&cmd_set_link_check,
12669 	(cmdline_parse_inst_t *)&cmd_vlan_offload,
12670 	(cmdline_parse_inst_t *)&cmd_vlan_tpid,
12671 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
12672 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
12673 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set,
12674 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
12675 	(cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
12676 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
12677 	(cmdline_parse_inst_t *)&cmd_csum_set,
12678 	(cmdline_parse_inst_t *)&cmd_csum_show,
12679 	(cmdline_parse_inst_t *)&cmd_csum_tunnel,
12680 	(cmdline_parse_inst_t *)&cmd_csum_mac_swap,
12681 	(cmdline_parse_inst_t *)&cmd_tso_set,
12682 	(cmdline_parse_inst_t *)&cmd_tso_show,
12683 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
12684 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
12685 #ifdef RTE_LIB_GRO
12686 	(cmdline_parse_inst_t *)&cmd_gro_enable,
12687 	(cmdline_parse_inst_t *)&cmd_gro_flush,
12688 	(cmdline_parse_inst_t *)&cmd_gro_show,
12689 #endif
12690 #ifdef RTE_LIB_GSO
12691 	(cmdline_parse_inst_t *)&cmd_gso_enable,
12692 	(cmdline_parse_inst_t *)&cmd_gso_size,
12693 	(cmdline_parse_inst_t *)&cmd_gso_show,
12694 #endif
12695 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
12696 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
12697 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
12698 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
12699 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
12700 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
12701 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
12702 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
12703 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
12704 	(cmdline_parse_inst_t *)&cmd_link_flow_control_show,
12705 	(cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
12706 	(cmdline_parse_inst_t *)&cmd_queue_priority_flow_control_set,
12707 	(cmdline_parse_inst_t *)&cmd_config_dcb,
12708 	(cmdline_parse_inst_t *)&cmd_read_rxd_txd,
12709 	(cmdline_parse_inst_t *)&cmd_stop,
12710 	(cmdline_parse_inst_t *)&cmd_mac_addr,
12711 	(cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
12712 	(cmdline_parse_inst_t *)&cmd_set_qmap,
12713 	(cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
12714 	(cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
12715 	(cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
12716 	(cmdline_parse_inst_t *)&cmd_operate_port,
12717 	(cmdline_parse_inst_t *)&cmd_operate_specific_port,
12718 	(cmdline_parse_inst_t *)&cmd_operate_attach_port,
12719 	(cmdline_parse_inst_t *)&cmd_operate_detach_port,
12720 	(cmdline_parse_inst_t *)&cmd_operate_detach_device,
12721 	(cmdline_parse_inst_t *)&cmd_set_port_setup_on,
12722 	(cmdline_parse_inst_t *)&cmd_config_speed_all,
12723 	(cmdline_parse_inst_t *)&cmd_config_speed_specific,
12724 	(cmdline_parse_inst_t *)&cmd_config_loopback_all,
12725 	(cmdline_parse_inst_t *)&cmd_config_loopback_specific,
12726 	(cmdline_parse_inst_t *)&cmd_config_rx_tx,
12727 	(cmdline_parse_inst_t *)&cmd_config_mtu,
12728 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
12729 	(cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
12730 	(cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
12731 	(cmdline_parse_inst_t *)&cmd_config_rss,
12732 	(cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
12733 	(cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
12734 	(cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
12735 	(cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
12736 	(cmdline_parse_inst_t *)&cmd_config_rss_reta,
12737 	(cmdline_parse_inst_t *)&cmd_showport_reta,
12738 	(cmdline_parse_inst_t *)&cmd_showport_macs,
12739 	(cmdline_parse_inst_t *)&cmd_show_port_flow_transfer_proxy,
12740 	(cmdline_parse_inst_t *)&cmd_config_burst,
12741 	(cmdline_parse_inst_t *)&cmd_config_thresh,
12742 	(cmdline_parse_inst_t *)&cmd_config_threshold,
12743 	(cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
12744 	(cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
12745 	(cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
12746 	(cmdline_parse_inst_t *)&cmd_queue_rate_limit,
12747 	(cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
12748 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash,
12749 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
12750 	(cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
12751 	(cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs,
12752 	(cmdline_parse_inst_t *)&cmd_dump,
12753 	(cmdline_parse_inst_t *)&cmd_dump_one,
12754 	(cmdline_parse_inst_t *)&cmd_flow,
12755 	(cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
12756 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
12757 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
12758 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm_rfc4115,
12759 	(cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
12760 	(cmdline_parse_inst_t *)&cmd_create_port_meter,
12761 	(cmdline_parse_inst_t *)&cmd_enable_port_meter,
12762 	(cmdline_parse_inst_t *)&cmd_disable_port_meter,
12763 	(cmdline_parse_inst_t *)&cmd_del_port_meter,
12764 	(cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
12765 	(cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
12766 	(cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
12767 	(cmdline_parse_inst_t *)&cmd_set_port_meter_vlan_table,
12768 	(cmdline_parse_inst_t *)&cmd_set_port_meter_in_proto,
12769 	(cmdline_parse_inst_t *)&cmd_get_port_meter_in_proto,
12770 	(cmdline_parse_inst_t *)&cmd_get_port_meter_in_proto_prio,
12771 	(cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
12772 	(cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
12773 	(cmdline_parse_inst_t *)&cmd_mcast_addr,
12774 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
12775 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
12776 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
12777 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
12778 	(cmdline_parse_inst_t *)&cmd_set_tx_loopback,
12779 	(cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
12780 	(cmdline_parse_inst_t *)&cmd_set_vf_traffic,
12781 	(cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
12782 	(cmdline_parse_inst_t *)&cmd_vf_rate_limit,
12783 	(cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
12784 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
12785 	(cmdline_parse_inst_t *)&cmd_set_vxlan,
12786 	(cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
12787 	(cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
12788 	(cmdline_parse_inst_t *)&cmd_set_nvgre,
12789 	(cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
12790 	(cmdline_parse_inst_t *)&cmd_set_l2_encap,
12791 	(cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
12792 	(cmdline_parse_inst_t *)&cmd_set_l2_decap,
12793 	(cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
12794 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
12795 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
12796 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
12797 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
12798 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
12799 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
12800 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
12801 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
12802 	(cmdline_parse_inst_t *)&cmd_set_conntrack_common,
12803 	(cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
12804 	(cmdline_parse_inst_t *)&cmd_show_vf_stats,
12805 	(cmdline_parse_inst_t *)&cmd_clear_vf_stats,
12806 	(cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
12807 	(cmdline_parse_inst_t *)&cmd_set_port_ptypes,
12808 	(cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
12809 	(cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
12810 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
12811 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
12812 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
12813 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
12814 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
12815 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
12816 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
12817 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
12818 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
12819 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
12820 	(cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
12821 	(cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
12822 	(cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
12823 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node,
12824 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
12825 	(cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
12826 	(cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
12827 	(cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
12828 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
12829 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
12830 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
12831 	(cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
12832 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
12833 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
12834 	(cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
12835 	(cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
12836 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
12837 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
12838 	(cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
12839 	(cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
12840 #ifdef RTE_LIB_BPF
12841 	(cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
12842 	(cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
12843 #endif
12844 	(cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
12845 	(cmdline_parse_inst_t *)&cmd_show_tx_metadata,
12846 	(cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
12847 	(cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
12848 	(cmdline_parse_inst_t *)&cmd_set_raw,
12849 	(cmdline_parse_inst_t *)&cmd_show_set_raw,
12850 	(cmdline_parse_inst_t *)&cmd_show_set_raw_all,
12851 	(cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
12852 	(cmdline_parse_inst_t *)&cmd_show_fec_mode,
12853 	(cmdline_parse_inst_t *)&cmd_set_fec_mode,
12854 	(cmdline_parse_inst_t *)&cmd_set_rxq_avail_thresh,
12855 	(cmdline_parse_inst_t *)&cmd_show_capability,
12856 	(cmdline_parse_inst_t *)&cmd_set_flex_is_pattern,
12857 	(cmdline_parse_inst_t *)&cmd_set_flex_spec_pattern,
12858 	NULL,
12859 };
12860 
12861 void
12862 testpmd_add_driver_commands(struct testpmd_driver_commands *c)
12863 {
12864 	TAILQ_INSERT_TAIL(&driver_commands_head, c, next);
12865 }
12866 
12867 int
12868 init_cmdline(void)
12869 {
12870 	struct testpmd_driver_commands *c;
12871 	unsigned int count;
12872 	unsigned int i;
12873 
12874 	/* initialize non-constant commands */
12875 	cmd_set_fwd_mode_init();
12876 	cmd_set_fwd_retry_mode_init();
12877 
12878 	count = 0;
12879 	for (i = 0; builtin_ctx[i] != NULL; i++)
12880 		count++;
12881 	TAILQ_FOREACH(c, &driver_commands_head, next) {
12882 		for (i = 0; c->commands[i].ctx != NULL; i++)
12883 			count++;
12884 	}
12885 
12886 	/* cmdline expects a NULL terminated array */
12887 	main_ctx = calloc(count + 1, sizeof(main_ctx[0]));
12888 	if (main_ctx == NULL)
12889 		return -1;
12890 
12891 	count = 0;
12892 	for (i = 0; builtin_ctx[i] != NULL; i++, count++)
12893 		main_ctx[count] = builtin_ctx[i];
12894 	TAILQ_FOREACH(c, &driver_commands_head, next) {
12895 		for (i = 0; c->commands[i].ctx != NULL; i++, count++)
12896 			main_ctx[count] = c->commands[i].ctx;
12897 	}
12898 
12899 	return 0;
12900 }
12901 
12902 /* read cmdline commands from file */
12903 void
12904 cmdline_read_from_file(const char *filename)
12905 {
12906 	struct cmdline *cl;
12907 
12908 	cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
12909 	if (cl == NULL) {
12910 		fprintf(stderr,
12911 			"Failed to create file based cmdline context: %s\n",
12912 			filename);
12913 		return;
12914 	}
12915 
12916 	cmdline_interact(cl);
12917 	cmdline_quit(cl);
12918 
12919 	cmdline_free(cl);
12920 
12921 	printf("Read CLI commands from %s\n", filename);
12922 }
12923 
12924 /* prompt function, called from main on MAIN lcore */
12925 void
12926 prompt(void)
12927 {
12928 	int ret;
12929 
12930 	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
12931 	if (testpmd_cl == NULL)
12932 		return;
12933 
12934 	ret = atexit(prompt_exit);
12935 	if (ret != 0)
12936 		fprintf(stderr, "Cannot set exit function for cmdline\n");
12937 
12938 	cmdline_interact(testpmd_cl);
12939 	if (ret != 0)
12940 		cmdline_stdin_exit(testpmd_cl);
12941 }
12942 
12943 void
12944 prompt_exit(void)
12945 {
12946 	if (testpmd_cl != NULL) {
12947 		cmdline_quit(testpmd_cl);
12948 		cmdline_stdin_exit(testpmd_cl);
12949 	}
12950 }
12951 
12952 void
12953 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
12954 {
12955 	if (id == (portid_t)RTE_PORT_ALL) {
12956 		portid_t pid;
12957 
12958 		RTE_ETH_FOREACH_DEV(pid) {
12959 			/* check if need_reconfig has been set to 1 */
12960 			if (ports[pid].need_reconfig == 0)
12961 				ports[pid].need_reconfig = dev;
12962 			/* check if need_reconfig_queues has been set to 1 */
12963 			if (ports[pid].need_reconfig_queues == 0)
12964 				ports[pid].need_reconfig_queues = queue;
12965 		}
12966 	} else if (!port_id_is_invalid(id, DISABLED_WARN)) {
12967 		/* check if need_reconfig has been set to 1 */
12968 		if (ports[id].need_reconfig == 0)
12969 			ports[id].need_reconfig = dev;
12970 		/* check if need_reconfig_queues has been set to 1 */
12971 		if (ports[id].need_reconfig_queues == 0)
12972 			ports[id].need_reconfig_queues = queue;
12973 	}
12974 }
12975