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