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