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