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