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