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