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