xref: /dpdk/app/test-pmd/cmdline.c (revision 30a1de105a5f40d77b344a891c4a68f79e815c43)
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 <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <inttypes.h>
13 #include <sys/queue.h>
14 
15 #include <rte_common.h>
16 #include <rte_byteorder.h>
17 #include <rte_log.h>
18 #include <rte_debug.h>
19 #include <rte_cycles.h>
20 #include <rte_memory.h>
21 #include <rte_memzone.h>
22 #include <rte_malloc.h>
23 #include <rte_launch.h>
24 #include <rte_eal.h>
25 #include <rte_per_lcore.h>
26 #include <rte_lcore.h>
27 #include <rte_branch_prediction.h>
28 #include <rte_ring.h>
29 #include <rte_mempool.h>
30 #include <rte_interrupts.h>
31 #include <rte_pci.h>
32 #include <rte_ether.h>
33 #include <rte_ethdev.h>
34 #include <rte_string_fns.h>
35 #include <rte_devargs.h>
36 #include <rte_flow.h>
37 #ifdef RTE_LIB_GRO
38 #include <rte_gro.h>
39 #endif
40 #include <rte_mbuf_dyn.h>
41 
42 #include <cmdline_rdline.h>
43 #include <cmdline_parse.h>
44 #include <cmdline_parse_num.h>
45 #include <cmdline_parse_string.h>
46 #include <cmdline_parse_ipaddr.h>
47 #include <cmdline_parse_etheraddr.h>
48 #include <cmdline_socket.h>
49 #include <cmdline.h>
50 #ifdef RTE_NET_BOND
51 #include <rte_eth_bond.h>
52 #include <rte_eth_bond_8023ad.h>
53 #endif
54 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
55 #include <rte_pmd_dpaa.h>
56 #endif
57 #ifdef RTE_NET_IXGBE
58 #include <rte_pmd_ixgbe.h>
59 #endif
60 #ifdef RTE_NET_I40E
61 #include <rte_pmd_i40e.h>
62 #endif
63 #ifdef RTE_NET_BNXT
64 #include <rte_pmd_bnxt.h>
65 #endif
66 #include "testpmd.h"
67 #include "cmdline_mtr.h"
68 #include "cmdline_tm.h"
69 #include "bpf_cmd.h"
70 
71 static struct cmdline *testpmd_cl;
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 registers                  : Reading and setting port registers.\n"
94 		"    help filters                    : Filters configuration help.\n"
95 		"    help traffic_management         : Traffic Management commands.\n"
96 		"    help devices                    : Device related cmds.\n"
97 		"    help all                        : All of the above sections.\n\n"
98 	);
99 
100 }
101 
102 cmdline_parse_token_string_t cmd_help_brief_help =
103 	TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
104 
105 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 			"ddp get list (port_id)\n"
196 			"    Get ddp profile info list\n\n"
197 
198 			"ddp get info (profile_path)\n"
199 			"    Get ddp profile information.\n\n"
200 
201 			"show vf stats (port_id) (vf_id)\n"
202 			"    Display a VF's statistics.\n\n"
203 
204 			"clear vf stats (port_id) (vf_id)\n"
205 			"    Reset a VF's statistics.\n\n"
206 
207 			"show port (port_id) pctype mapping\n"
208 			"    Get flow ptype to pctype mapping on a port\n\n"
209 
210 			"show port meter stats (port_id) (meter_id) (clear)\n"
211 			"    Get meter stats on a port\n\n"
212 
213 			"show fwd stats all\n"
214 			"    Display statistics for all fwd engines.\n\n"
215 
216 			"clear fwd stats all\n"
217 			"    Clear statistics for all fwd engines.\n\n"
218 
219 			"show port (port_id) rx_offload capabilities\n"
220 			"    List all per queue and per port Rx offloading"
221 			" capabilities of a port\n\n"
222 
223 			"show port (port_id) rx_offload configuration\n"
224 			"    List port level and all queue level"
225 			" Rx offloading configuration\n\n"
226 
227 			"show port (port_id) tx_offload capabilities\n"
228 			"    List all per queue and per port"
229 			" Tx offloading capabilities of a port\n\n"
230 
231 			"show port (port_id) tx_offload configuration\n"
232 			"    List port level and all queue level"
233 			" Tx offloading configuration\n\n"
234 
235 			"show port (port_id) tx_metadata\n"
236 			"    Show Tx metadata value set"
237 			" for a specific port\n\n"
238 
239 			"show port (port_id) ptypes\n"
240 			"    Show port supported ptypes"
241 			" for a specific port\n\n"
242 
243 			"show device info (<identifier>|all)"
244 			"       Show general information about devices probed.\n\n"
245 
246 			"show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
247 			"       Show status of rx|tx descriptor.\n\n"
248 
249 			"show port (port_id) rxq (queue_id) desc used count\n"
250 			"    Show current number of filled receive"
251 			" packet descriptors.\n\n"
252 
253 			"show port (port_id) macs|mcast_macs"
254 			"       Display list of mac addresses added to port.\n\n"
255 
256 			"show port (port_id) flow transfer proxy\n"
257 			"	Display proxy port to manage transfer flows\n\n"
258 
259 			"show port (port_id) fec capabilities"
260 			"	Show fec capabilities of a port.\n\n"
261 
262 			"show port (port_id) fec_mode"
263 			"	Show fec mode of a port.\n\n"
264 
265 			"show port (port_id) flow_ctrl"
266 			"	Show flow control info of a port.\n\n"
267 		);
268 	}
269 
270 	if (show_all || !strcmp(res->section, "config")) {
271 		cmdline_printf(
272 			cl,
273 			"\n"
274 			"Configuration:\n"
275 			"--------------\n"
276 			"Configuration changes only become active when"
277 			" forwarding is started/restarted.\n\n"
278 
279 			"set default\n"
280 			"    Reset forwarding to the default configuration.\n\n"
281 
282 			"set verbose (level)\n"
283 			"    Set the debug verbosity level X.\n\n"
284 
285 			"set log global|(type) (level)\n"
286 			"    Set the log level.\n\n"
287 
288 			"set nbport (num)\n"
289 			"    Set number of ports.\n\n"
290 
291 			"set nbcore (num)\n"
292 			"    Set number of cores.\n\n"
293 
294 			"set coremask (mask)\n"
295 			"    Set the forwarding cores hexadecimal mask.\n\n"
296 
297 			"set portmask (mask)\n"
298 			"    Set the forwarding ports hexadecimal mask.\n\n"
299 
300 			"set burst (num)\n"
301 			"    Set number of packets per burst.\n\n"
302 
303 			"set burst tx delay (microseconds) retry (num)\n"
304 			"    Set the transmit delay time and number of retries,"
305 			" effective when retry is enabled.\n\n"
306 
307 			"set rxoffs (x[,y]*)\n"
308 			"    Set the offset of each packet segment on"
309 			" receiving if split feature is engaged."
310 			" Affects only the queues configured with split"
311 			" offloads.\n\n"
312 
313 			"set rxpkts (x[,y]*)\n"
314 			"    Set the length of each segment to scatter"
315 			" packets on receiving if split feature is engaged."
316 			" Affects only the queues configured with split"
317 			" offloads.\n\n"
318 
319 			"set txpkts (x[,y]*)\n"
320 			"    Set the length of each segment of TXONLY"
321 			" and optionally CSUM packets.\n\n"
322 
323 			"set txsplit (off|on|rand)\n"
324 			"    Set the split policy for the TX packets."
325 			" Right now only applicable for CSUM and TXONLY"
326 			" modes\n\n"
327 
328 			"set txtimes (x, y)\n"
329 			"    Set the scheduling on timestamps"
330 			" timings for the TXONLY mode\n\n"
331 
332 			"set corelist (x[,y]*)\n"
333 			"    Set the list of forwarding cores.\n\n"
334 
335 			"set portlist (x[,y]*)\n"
336 			"    Set the list of forwarding ports.\n\n"
337 
338 			"set port setup on (iterator|event)\n"
339 			"    Select how attached port is retrieved for setup.\n\n"
340 
341 			"set tx loopback (port_id) (on|off)\n"
342 			"    Enable or disable tx loopback.\n\n"
343 
344 			"set all queues drop (port_id) (on|off)\n"
345 			"    Set drop enable bit for all queues.\n\n"
346 
347 			"set vf split drop (port_id) (vf_id) (on|off)\n"
348 			"    Set split drop enable bit for a VF from the PF.\n\n"
349 
350 			"set vf mac antispoof (port_id) (vf_id) (on|off).\n"
351 			"    Set MAC antispoof for a VF from the PF.\n\n"
352 
353 			"set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
354 			"    Enable MACsec offload.\n\n"
355 
356 			"set macsec offload (port_id) off\n"
357 			"    Disable MACsec offload.\n\n"
358 
359 			"set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
360 			"    Configure MACsec secure connection (SC).\n\n"
361 
362 			"set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
363 			"    Configure MACsec secure association (SA).\n\n"
364 
365 			"set vf broadcast (port_id) (vf_id) (on|off)\n"
366 			"    Set VF broadcast for a VF from the PF.\n\n"
367 
368 			"vlan set stripq (on|off) (port_id,queue_id)\n"
369 			"    Set the VLAN strip for a queue on a port.\n\n"
370 
371 			"set vf vlan stripq (port_id) (vf_id) (on|off)\n"
372 			"    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
373 
374 			"set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
375 			"    Set VLAN insert for a VF from the PF.\n\n"
376 
377 			"set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
378 			"    Set VLAN antispoof for a VF from the PF.\n\n"
379 
380 			"set vf vlan tag (port_id) (vf_id) (on|off)\n"
381 			"    Set VLAN tag for a VF from the PF.\n\n"
382 
383 			"set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
384 			"    Set a VF's max bandwidth(Mbps).\n\n"
385 
386 			"set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
387 			"    Set all TCs' min bandwidth(%%) on a VF.\n\n"
388 
389 			"set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
390 			"    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
391 
392 			"set tx strict-link-priority (port_id) (tc_bitmap)\n"
393 			"    Set some TCs' strict link priority mode on a physical port.\n\n"
394 
395 			"set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
396 			"    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
397 
398 			"vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
399 			"    Set the VLAN strip or filter or qinq strip or extend\n\n"
400 
401 			"vlan set (inner|outer) tpid (value) (port_id)\n"
402 			"    Set the VLAN TPID for Packet Filtering on"
403 			" a port\n\n"
404 
405 			"rx_vlan add (vlan_id|all) (port_id)\n"
406 			"    Add a vlan_id, or all identifiers, to the set"
407 			" of VLAN identifiers filtered by port_id.\n\n"
408 
409 			"rx_vlan rm (vlan_id|all) (port_id)\n"
410 			"    Remove a vlan_id, or all identifiers, from the set"
411 			" of VLAN identifiers filtered by port_id.\n\n"
412 
413 			"rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
414 			"    Add a vlan_id, to the set of VLAN identifiers"
415 			"filtered for VF(s) from port_id.\n\n"
416 
417 			"rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
418 			"    Remove a vlan_id, to the set of VLAN identifiers"
419 			"filtered for VF(s) from port_id.\n\n"
420 
421 			"rx_vxlan_port add (udp_port) (port_id)\n"
422 			"    Add an UDP port for VXLAN packet filter on a port\n\n"
423 
424 			"rx_vxlan_port rm (udp_port) (port_id)\n"
425 			"    Remove an UDP port for VXLAN packet filter on a port\n\n"
426 
427 			"tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
428 			"    Set hardware insertion of VLAN IDs (single or double VLAN "
429 			"depends on the number of VLAN IDs) in packets sent on a port.\n\n"
430 
431 			"tx_vlan set pvid port_id vlan_id (on|off)\n"
432 			"    Set port based TX VLAN insertion.\n\n"
433 
434 			"tx_vlan reset (port_id)\n"
435 			"    Disable hardware insertion of a VLAN header in"
436 			" packets sent on a port.\n\n"
437 
438 			"csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
439 			"    Select hardware or software calculation of the"
440 			" checksum when transmitting a packet using the"
441 			" csum forward engine.\n"
442 			"    ip|udp|tcp|sctp always concern the inner layer.\n"
443 			"    outer-ip concerns the outer IP layer in"
444 			"    outer-udp concerns the outer UDP layer in"
445 			" case the packet is recognized as a tunnel packet by"
446 			" the forward engine (vxlan, gre and ipip are supported)\n"
447 			"    Please check the NIC datasheet for HW limits.\n\n"
448 
449 			"csum parse-tunnel (on|off) (tx_port_id)\n"
450 			"    If disabled, treat tunnel packets as non-tunneled"
451 			" packets (treat inner headers as payload). The port\n"
452 			"    argument is the port used for TX in csum forward"
453 			" engine.\n\n"
454 
455 			"csum show (port_id)\n"
456 			"    Display tx checksum offload configuration\n\n"
457 
458 			"tso set (segsize) (portid)\n"
459 			"    Enable TCP Segmentation Offload in csum forward"
460 			" engine.\n"
461 			"    Please check the NIC datasheet for HW limits.\n\n"
462 
463 			"tso show (portid)"
464 			"    Display the status of TCP Segmentation Offload.\n\n"
465 
466 #ifdef RTE_LIB_GRO
467 			"set port (port_id) gro on|off\n"
468 			"    Enable or disable Generic Receive Offload in"
469 			" csum forwarding engine.\n\n"
470 
471 			"show port (port_id) gro\n"
472 			"    Display GRO configuration.\n\n"
473 
474 			"set gro flush (cycles)\n"
475 			"    Set the cycle to flush GROed packets from"
476 			" reassembly tables.\n\n"
477 #endif
478 
479 #ifdef RTE_LIB_GSO
480 			"set port (port_id) gso (on|off)"
481 			"    Enable or disable Generic Segmentation Offload in"
482 			" csum forwarding engine.\n\n"
483 
484 			"set gso segsz (length)\n"
485 			"    Set max packet length for output GSO segments,"
486 			" including packet header and payload.\n\n"
487 
488 			"show port (port_id) gso\n"
489 			"    Show GSO configuration.\n\n"
490 #endif
491 
492 			"set fwd (%s)\n"
493 			"    Set packet forwarding mode.\n\n"
494 
495 			"mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
496 			"    Add a MAC address on port_id.\n\n"
497 
498 			"mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
499 			"    Remove a MAC address from port_id.\n\n"
500 
501 			"mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
502 			"    Set the default MAC address for port_id.\n\n"
503 
504 			"mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
505 			"    Add a MAC address for a VF on the port.\n\n"
506 
507 			"set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
508 			"    Set the MAC address for a VF from the PF.\n\n"
509 
510 			"set eth-peer (port_id) (peer_addr)\n"
511 			"    set the peer address for certain port.\n\n"
512 
513 			"set port (port_id) uta (mac_address|all) (on|off)\n"
514 			"    Add/Remove a or all unicast hash filter(s)"
515 			"from port X.\n\n"
516 
517 			"set promisc (port_id|all) (on|off)\n"
518 			"    Set the promiscuous mode on port_id, or all.\n\n"
519 
520 			"set allmulti (port_id|all) (on|off)\n"
521 			"    Set the allmulti mode on port_id, or all.\n\n"
522 
523 			"set vf promisc (port_id) (vf_id) (on|off)\n"
524 			"    Set unicast promiscuous mode for a VF from the PF.\n\n"
525 
526 			"set vf allmulti (port_id) (vf_id) (on|off)\n"
527 			"    Set multicast promiscuous mode for a VF from the PF.\n\n"
528 
529 			"set flow_ctrl rx (on|off) tx (on|off) (high_water)"
530 			" (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
531 			" (on|off) autoneg (on|off) (port_id)\n"
532 			"set flow_ctrl rx (on|off) (portid)\n"
533 			"set flow_ctrl tx (on|off) (portid)\n"
534 			"set flow_ctrl high_water (high_water) (portid)\n"
535 			"set flow_ctrl low_water (low_water) (portid)\n"
536 			"set flow_ctrl pause_time (pause_time) (portid)\n"
537 			"set flow_ctrl send_xon (send_xon) (portid)\n"
538 			"set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
539 			"set flow_ctrl autoneg (on|off) (port_id)\n"
540 			"    Set the link flow control parameter on a port.\n\n"
541 
542 			"set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
543 			" (low_water) (pause_time) (priority) (port_id)\n"
544 			"    Set the priority flow control parameter on a"
545 			" port.\n\n"
546 
547 			"set pfc_queue_ctrl (port_id) rx (on|off) (tx_qid)"
548 			" (tx_tc) tx (on|off) (rx_qid) (rx_tc) (pause_time)\n"
549 			"    Set the queue priority flow control parameter on a"
550 			" given Rx and Tx queues of a port.\n\n"
551 
552 			"set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
553 			"    Set statistics mapping (qmapping 0..15) for RX/TX"
554 			" queue on port.\n"
555 			"    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
556 			" on port 0 to mapping 5.\n\n"
557 
558 			"set xstats-hide-zero on|off\n"
559 			"    Set the option to hide the zero values"
560 			" for xstats display.\n"
561 
562 			"set record-core-cycles on|off\n"
563 			"    Set the option to enable measurement of CPU cycles.\n"
564 
565 			"set record-burst-stats on|off\n"
566 			"    Set the option to enable display of RX and TX bursts.\n"
567 
568 			"set port (port_id) vf (vf_id) rx|tx on|off\n"
569 			"    Enable/Disable a VF receive/transmit from a port\n\n"
570 
571 			"set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
572 			"|MPE) (on|off)\n"
573 			"    AUPE:accepts untagged VLAN;"
574 			"ROPE:accept unicast hash\n\n"
575 			"    BAM:accepts broadcast packets;"
576 			"MPE:accepts all multicast packets\n\n"
577 			"    Enable/Disable a VF receive mode of a port\n\n"
578 
579 			"set port (port_id) queue (queue_id) rate (rate_num)\n"
580 			"    Set rate limit for a queue of a port\n\n"
581 
582 			"set port (port_id) vf (vf_id) rate (rate_num) "
583 			"queue_mask (queue_mask_value)\n"
584 			"    Set rate limit for queues in VF of a port\n\n"
585 
586 			"set flush_rx (on|off)\n"
587 			"   Flush (default) or don't flush RX streams before"
588 			" forwarding. Mainly used with PCAP drivers.\n\n"
589 
590 			"set bypass mode (normal|bypass|isolate) (port_id)\n"
591 			"   Set the bypass mode for the lowest port on bypass enabled"
592 			" NIC.\n\n"
593 
594 			"set bypass event (timeout|os_on|os_off|power_on|power_off) "
595 			"mode (normal|bypass|isolate) (port_id)\n"
596 			"   Set the event required to initiate specified bypass mode for"
597 			" the lowest port on a bypass enabled NIC where:\n"
598 			"       timeout   = enable bypass after watchdog timeout.\n"
599 			"       os_on     = enable bypass when OS/board is powered on.\n"
600 			"       os_off    = enable bypass when OS/board is powered off.\n"
601 			"       power_on  = enable bypass when power supply is turned on.\n"
602 			"       power_off = enable bypass when power supply is turned off."
603 			"\n\n"
604 
605 			"set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
606 			"   Set the bypass watchdog timeout to 'n' seconds"
607 			" where 0 = instant.\n\n"
608 
609 			"show bypass config (port_id)\n"
610 			"   Show the bypass configuration for a bypass enabled NIC"
611 			" using the lowest port on the NIC.\n\n"
612 
613 #ifdef RTE_NET_BOND
614 			"create bonded device (mode) (socket)\n"
615 			"	Create a new bonded device with specific bonding mode and socket.\n\n"
616 
617 			"add bonding slave (slave_id) (port_id)\n"
618 			"	Add a slave device to a bonded device.\n\n"
619 
620 			"remove bonding slave (slave_id) (port_id)\n"
621 			"	Remove a slave device from a bonded device.\n\n"
622 
623 			"set bonding mode (value) (port_id)\n"
624 			"	Set the bonding mode on a bonded device.\n\n"
625 
626 			"set bonding primary (slave_id) (port_id)\n"
627 			"	Set the primary slave for a bonded device.\n\n"
628 
629 			"show bonding config (port_id)\n"
630 			"	Show the bonding config for port_id.\n\n"
631 
632 			"show bonding lacp info (port_id)\n"
633 			"	Show the bonding lacp information for port_id.\n\n"
634 
635 			"set bonding mac_addr (port_id) (address)\n"
636 			"	Set the MAC address of a bonded device.\n\n"
637 
638 			"set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
639 			"	Set Aggregation mode for IEEE802.3AD (mode 4)"
640 
641 			"set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
642 			"	Set the transmit balance policy for bonded device running in balance mode.\n\n"
643 
644 			"set bonding mon_period (port_id) (value)\n"
645 			"	Set the bonding link status monitoring polling period in ms.\n\n"
646 
647 			"set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
648 			"	Enable/disable dedicated queues for LACP control traffic.\n\n"
649 
650 #endif
651 			"set link-up port (port_id)\n"
652 			"	Set link up for a port.\n\n"
653 
654 			"set link-down port (port_id)\n"
655 			"	Set link down for a port.\n\n"
656 
657 			"ddp add (port_id) (profile_path[,backup_profile_path])\n"
658 			"    Load a profile package on a port\n\n"
659 
660 			"ddp del (port_id) (backup_profile_path)\n"
661 			"    Delete a profile package from a port\n\n"
662 
663 			"ptype mapping get (port_id) (valid_only)\n"
664 			"    Get ptype mapping on a port\n\n"
665 
666 			"ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
667 			"    Replace target with the pkt_type in ptype mapping\n\n"
668 
669 			"ptype mapping reset (port_id)\n"
670 			"    Reset ptype mapping on a port\n\n"
671 
672 			"ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
673 			"    Update a ptype mapping item on a port\n\n"
674 
675 			"set port (port_id) ptype_mask (ptype_mask)\n"
676 			"    set packet types classification for a specific port\n\n"
677 
678 			"set port (port_id) queue-region region_id (value) "
679 			"queue_start_index (value) queue_num (value)\n"
680 			"    Set a queue region on a port\n\n"
681 
682 			"set port (port_id) queue-region region_id (value) "
683 			"flowtype (value)\n"
684 			"    Set a flowtype region index on a port\n\n"
685 
686 			"set port (port_id) queue-region UP (value) region_id (value)\n"
687 			"    Set the mapping of User Priority to "
688 			"queue region on a port\n\n"
689 
690 			"set port (port_id) queue-region flush (on|off)\n"
691 			"    flush all queue region related configuration\n\n"
692 
693 			"show port meter cap (port_id)\n"
694 			"    Show port meter capability information\n\n"
695 
696 			"add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (packet_mode)\n"
697 			"    meter profile add - srtcm rfc 2697\n\n"
698 
699 			"add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs) (packet_mode)\n"
700 			"    meter profile add - trtcm rfc 2698\n\n"
701 
702 			"add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs) (packet_mode)\n"
703 			"    meter profile add - trtcm rfc 4115\n\n"
704 
705 			"del port meter profile (port_id) (profile_id)\n"
706 			"    meter profile delete\n\n"
707 
708 			"create port meter (port_id) (mtr_id) (profile_id) (policy_id) (meter_enable)\n"
709 			"(stats_mask) (shared) (use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
710 			"(dscp_tbl_entry63)]\n"
711 			"    meter create\n\n"
712 
713 			"enable port meter (port_id) (mtr_id)\n"
714 			"    meter enable\n\n"
715 
716 			"disable port meter (port_id) (mtr_id)\n"
717 			"    meter disable\n\n"
718 
719 			"del port meter (port_id) (mtr_id)\n"
720 			"    meter delete\n\n"
721 
722 			"add port meter policy (port_id) (policy_id) g_actions (actions)\n"
723 			"y_actions (actions) r_actions (actions)\n"
724 			"    meter policy add\n\n"
725 
726 			"del port meter policy (port_id) (policy_id)\n"
727 			"    meter policy delete\n\n"
728 
729 			"set port meter profile (port_id) (mtr_id) (profile_id)\n"
730 			"    meter update meter profile\n\n"
731 
732 			"set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
733 			"(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
734 			"    update meter dscp table entries\n\n"
735 
736 			"set port meter policer action (port_id) (mtr_id) (action_mask)\n"
737 			"(action0) [(action1) (action2)]\n"
738 			"    meter update policer action\n\n"
739 
740 			"set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
741 			"    meter update stats\n\n"
742 
743 			"show port (port_id) queue-region\n"
744 			"    show all queue region related configuration info\n\n"
745 
746 			"set port (port_id) fec_mode auto|off|rs|baser\n"
747 			"    set fec mode for a specific port\n\n"
748 
749 			, list_pkt_forwarding_modes()
750 		);
751 	}
752 
753 	if (show_all || !strcmp(res->section, "ports")) {
754 
755 		cmdline_printf(
756 			cl,
757 			"\n"
758 			"Port Operations:\n"
759 			"----------------\n\n"
760 
761 			"port start (port_id|all)\n"
762 			"    Start all ports or port_id.\n\n"
763 
764 			"port stop (port_id|all)\n"
765 			"    Stop all ports or port_id.\n\n"
766 
767 			"port close (port_id|all)\n"
768 			"    Close all ports or port_id.\n\n"
769 
770 			"port reset (port_id|all)\n"
771 			"    Reset all ports or port_id.\n\n"
772 
773 			"port attach (ident)\n"
774 			"    Attach physical or virtual dev by pci address or virtual device name\n\n"
775 
776 			"port detach (port_id)\n"
777 			"    Detach physical or virtual dev by port_id\n\n"
778 
779 			"port config (port_id|all)"
780 			" speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
781 			" duplex (half|full|auto)\n"
782 			"    Set speed and duplex for all ports or port_id\n\n"
783 
784 			"port config (port_id|all) loopback (mode)\n"
785 			"    Set loopback mode for all ports or port_id\n\n"
786 
787 			"port config all (rxq|txq|rxd|txd) (value)\n"
788 			"    Set number for rxq/txq/rxd/txd.\n\n"
789 
790 			"port config all max-pkt-len (value)\n"
791 			"    Set the max packet length.\n\n"
792 
793 			"port config all max-lro-pkt-size (value)\n"
794 			"    Set the max LRO aggregated packet size.\n\n"
795 
796 			"port config all drop-en (on|off)\n"
797 			"    Enable or disable packet drop on all RX queues of all ports when no "
798 			"receive buffers available.\n\n"
799 
800 			"port config all rss (all|default|ip|tcp|udp|sctp|"
801 			"ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|ipv4-chksum|l2tpv2|"
802 			"none|level-default|level-outer|level-inner|<flowtype_id>)\n"
803 			"    Set the RSS mode.\n\n"
804 
805 			"port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
806 			"    Set the RSS redirection table.\n\n"
807 
808 			"port config (port_id) dcb vt (on|off) (traffic_class)"
809 			" pfc (on|off)\n"
810 			"    Set the DCB mode.\n\n"
811 
812 			"port config all burst (value)\n"
813 			"    Set the number of packets per burst.\n\n"
814 
815 			"port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
816 			" (value)\n"
817 			"    Set the ring prefetch/host/writeback threshold"
818 			" for tx/rx queue.\n\n"
819 
820 			"port config all (txfreet|txrst|rxfreet) (value)\n"
821 			"    Set free threshold for rx/tx, or set"
822 			" tx rs bit threshold.\n\n"
823 			"port config mtu X value\n"
824 			"    Set the MTU of port X to a given value\n\n"
825 
826 			"port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
827 			"    Set a rx/tx queue's ring size configuration, the new"
828 			" value will take effect after command that (re-)start the port"
829 			" or command that setup the specific queue\n\n"
830 
831 			"port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
832 			"    Start/stop a rx/tx queue of port X. Only take effect"
833 			" when port X is started\n\n"
834 
835 			"port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
836 			"    Switch on/off a deferred start of port X rx/tx queue. Only"
837 			" take effect when port X is stopped.\n\n"
838 
839 			"port (port_id) (rxq|txq) (queue_id) setup\n"
840 			"    Setup a rx/tx queue of port X.\n\n"
841 
842 			"port config (port_id) pctype mapping reset\n"
843 			"    Reset flow type to pctype mapping on a port\n\n"
844 
845 			"port config (port_id) pctype mapping update"
846 			" (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
847 			"    Update a flow type to pctype mapping item on a port\n\n"
848 
849 			"port config (port_id) pctype (pctype_id) hash_inset|"
850 			"fdir_inset|fdir_flx_inset get|set|clear field\n"
851 			" (field_idx)\n"
852 			"    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
853 
854 			"port config (port_id) pctype (pctype_id) hash_inset|"
855 			"fdir_inset|fdir_flx_inset clear all"
856 			"    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
857 
858 			"port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
859 			"    Add/remove UDP tunnel port for tunneling offload\n\n"
860 
861 			"port config <port_id> rx_offload vlan_strip|"
862 			"ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
863 			"outer_ipv4_cksum|macsec_strip|header_split|"
864 			"vlan_filter|vlan_extend|jumbo_frame|scatter|"
865 			"buffer_split|timestamp|security|keep_crc on|off\n"
866 			"     Enable or disable a per port Rx offloading"
867 			" on all Rx queues of a port\n\n"
868 
869 			"port (port_id) rxq (queue_id) rx_offload vlan_strip|"
870 			"ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
871 			"outer_ipv4_cksum|macsec_strip|header_split|"
872 			"vlan_filter|vlan_extend|jumbo_frame|scatter|"
873 			"buffer_split|timestamp|security|keep_crc on|off\n"
874 			"    Enable or disable a per queue Rx offloading"
875 			" only on a specific Rx queue\n\n"
876 
877 			"port config (port_id) tx_offload vlan_insert|"
878 			"ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
879 			"udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
880 			"gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
881 			"macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
882 			"security on|off\n"
883 			"    Enable or disable a per port Tx offloading"
884 			" on all Tx queues of a port\n\n"
885 
886 			"port (port_id) txq (queue_id) tx_offload vlan_insert|"
887 			"ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
888 			"udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
889 			"gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
890 			"|mt_lockfree|multi_segs|mbuf_fast_free|security"
891 			" on|off\n"
892 			"    Enable or disable a per queue Tx offloading"
893 			" only on a specific Tx queue\n\n"
894 
895 			"bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
896 			"    Load an eBPF program as a callback"
897 			" for particular RX/TX queue\n\n"
898 
899 			"bpf-unload rx|tx (port) (queue)\n"
900 			"    Unload previously loaded eBPF program"
901 			" for particular RX/TX queue\n\n"
902 
903 			"port config (port_id) tx_metadata (value)\n"
904 			"    Set Tx metadata value per port. Testpmd will add this value"
905 			" to any Tx packet sent from this port\n\n"
906 
907 			"port config (port_id) dynf (name) set|clear\n"
908 			"    Register a dynf and Set/clear this flag on Tx. "
909 			"Testpmd will set this value to any Tx packet "
910 			"sent from this port\n\n"
911 
912 			"port cleanup (port_id) txq (queue_id) (free_cnt)\n"
913 			"    Cleanup txq mbufs for a specific Tx queue\n\n"
914 		);
915 	}
916 
917 	if (show_all || !strcmp(res->section, "registers")) {
918 
919 		cmdline_printf(
920 			cl,
921 			"\n"
922 			"Registers:\n"
923 			"----------\n\n"
924 
925 			"read reg (port_id) (address)\n"
926 			"    Display value of a port register.\n\n"
927 
928 			"read regfield (port_id) (address) (bit_x) (bit_y)\n"
929 			"    Display a port register bit field.\n\n"
930 
931 			"read regbit (port_id) (address) (bit_x)\n"
932 			"    Display a single port register bit.\n\n"
933 
934 			"write reg (port_id) (address) (value)\n"
935 			"    Set value of a port register.\n\n"
936 
937 			"write regfield (port_id) (address) (bit_x) (bit_y)"
938 			" (value)\n"
939 			"    Set bit field of a port register.\n\n"
940 
941 			"write regbit (port_id) (address) (bit_x) (value)\n"
942 			"    Set single bit value of a port register.\n\n"
943 		);
944 	}
945 	if (show_all || !strcmp(res->section, "filters")) {
946 
947 		cmdline_printf(
948 			cl,
949 			"\n"
950 			"filters:\n"
951 			"--------\n\n"
952 
953 #ifdef RTE_NET_I40E
954 			"flow_director_filter (port_id) mode raw (add|del|update)"
955 			" flow (flow_id) (drop|fwd) queue (queue_id)"
956 			" fd_id (fd_id_value) packet (packet file name)\n"
957 			"    Add/Del a raw type flow director filter.\n\n"
958 #endif
959 
960 			"flow_director_mask (port_id) mode IP vlan (vlan_value)"
961 			" src_mask (ipv4_src) (ipv6_src) (src_port)"
962 			" dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
963 			"    Set flow director IP mask.\n\n"
964 
965 			"flow_director_mask (port_id) mode MAC-VLAN"
966 			" vlan (vlan_value)\n"
967 			"    Set flow director MAC-VLAN mask.\n\n"
968 
969 			"flow_director_mask (port_id) mode Tunnel"
970 			" vlan (vlan_value) mac (mac_value)"
971 			" tunnel-type (tunnel_type_value)"
972 			" tunnel-id (tunnel_id_value)\n"
973 			"    Set flow director Tunnel mask.\n\n"
974 
975 			"flow_director_flex_payload (port_id)"
976 			" (raw|l2|l3|l4) (config)\n"
977 			"    Configure flex payload selection.\n\n"
978 
979 			"flow validate {port_id}"
980 			" [group {group_id}] [priority {level}]"
981 			" [ingress] [egress]"
982 			" pattern {item} [/ {item} [...]] / end"
983 			" actions {action} [/ {action} [...]] / end\n"
984 			"    Check whether a flow rule can be created.\n\n"
985 
986 			"flow create {port_id}"
987 			" [group {group_id}] [priority {level}]"
988 			" [ingress] [egress]"
989 			" pattern {item} [/ {item} [...]] / end"
990 			" actions {action} [/ {action} [...]] / end\n"
991 			"    Create a flow rule.\n\n"
992 
993 			"flow destroy {port_id} rule {rule_id} [...]\n"
994 			"    Destroy specific flow rules.\n\n"
995 
996 			"flow flush {port_id}\n"
997 			"    Destroy all flow rules.\n\n"
998 
999 			"flow query {port_id} {rule_id} {action}\n"
1000 			"    Query an existing flow rule.\n\n"
1001 
1002 			"flow list {port_id} [group {group_id}] [...]\n"
1003 			"    List existing flow rules sorted by priority,"
1004 			" filtered by group identifiers.\n\n"
1005 
1006 			"flow isolate {port_id} {boolean}\n"
1007 			"    Restrict ingress traffic to the defined"
1008 			" flow rules\n\n"
1009 
1010 			"flow aged {port_id} [destroy]\n"
1011 			"    List and destroy aged flows"
1012 			" flow rules\n\n"
1013 
1014 			"flow indirect_action {port_id} create"
1015 			" [action_id {indirect_action_id}]"
1016 			" [ingress] [egress]"
1017 			" action {action} / end\n"
1018 			"    Create indirect action.\n\n"
1019 
1020 			"flow indirect_action {port_id} update"
1021 			" {indirect_action_id} action {action} / end\n"
1022 			"    Update indirect action.\n\n"
1023 
1024 			"flow indirect_action {port_id} destroy"
1025 			" action_id {indirect_action_id} [...]\n"
1026 			"    Destroy specific indirect actions.\n\n"
1027 
1028 			"flow indirect_action {port_id} query"
1029 			" {indirect_action_id}\n"
1030 			"    Query an existing indirect action.\n\n"
1031 
1032 			"set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1033 			" (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1034 			" (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1035 			"       Configure the VXLAN encapsulation for flows.\n\n"
1036 
1037 			"set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1038 			" udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1039 			" ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1040 			" eth-dst (eth-dst)\n"
1041 			"       Configure the VXLAN encapsulation for flows.\n\n"
1042 
1043 			"set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1044 			" (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1045 			" ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1046 			" eth-dst (eth-dst)\n"
1047 			"       Configure the VXLAN encapsulation for flows.\n\n"
1048 
1049 			"set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1050 			" (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1051 			" (eth-dst)\n"
1052 			"       Configure the NVGRE encapsulation for flows.\n\n"
1053 
1054 			"set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1055 			" ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1056 			" eth-src (eth-src) eth-dst (eth-dst)\n"
1057 			"       Configure the NVGRE encapsulation for flows.\n\n"
1058 
1059 			"set raw_encap {flow items}\n"
1060 			"	Configure the encapsulation with raw data.\n\n"
1061 
1062 			"set raw_decap {flow items}\n"
1063 			"	Configure the decapsulation with raw data.\n\n"
1064 
1065 		);
1066 	}
1067 
1068 	if (show_all || !strcmp(res->section, "traffic_management")) {
1069 		cmdline_printf(
1070 			cl,
1071 			"\n"
1072 			"Traffic Management:\n"
1073 			"--------------\n"
1074 			"show port tm cap (port_id)\n"
1075 			"       Display the port TM capability.\n\n"
1076 
1077 			"show port tm level cap (port_id) (level_id)\n"
1078 			"       Display the port TM hierarchical level capability.\n\n"
1079 
1080 			"show port tm node cap (port_id) (node_id)\n"
1081 			"       Display the port TM node capability.\n\n"
1082 
1083 			"show port tm node type (port_id) (node_id)\n"
1084 			"       Display the port TM node type.\n\n"
1085 
1086 			"show port tm node stats (port_id) (node_id) (clear)\n"
1087 			"       Display the port TM node stats.\n\n"
1088 
1089 			"add port tm node shaper profile (port_id) (shaper_profile_id)"
1090 			" (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1091 			" (packet_length_adjust) (packet_mode)\n"
1092 			"       Add port tm node private shaper profile.\n\n"
1093 
1094 			"del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1095 			"       Delete port tm node private shaper profile.\n\n"
1096 
1097 			"add port tm node shared shaper (port_id) (shared_shaper_id)"
1098 			" (shaper_profile_id)\n"
1099 			"       Add/update port tm node shared shaper.\n\n"
1100 
1101 			"del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1102 			"       Delete port tm node shared shaper.\n\n"
1103 
1104 			"set port tm node shaper profile (port_id) (node_id)"
1105 			" (shaper_profile_id)\n"
1106 			"       Set port tm node shaper profile.\n\n"
1107 
1108 			"add port tm node wred profile (port_id) (wred_profile_id)"
1109 			" (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1110 			" (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1111 			" (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1112 			"       Add port tm node wred profile.\n\n"
1113 
1114 			"del port tm node wred profile (port_id) (wred_profile_id)\n"
1115 			"       Delete port tm node wred profile.\n\n"
1116 
1117 			"add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1118 			" (priority) (weight) (level_id) (shaper_profile_id)"
1119 			" (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1120 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1121 			"       Add port tm nonleaf node.\n\n"
1122 
1123 			"add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1124 			" (priority) (weight) (level_id) (shaper_profile_id)"
1125 			" (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1126 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1127 			"       Add port tm nonleaf node with pkt mode enabled.\n\n"
1128 
1129 			"add port tm leaf node (port_id) (node_id) (parent_node_id)"
1130 			" (priority) (weight) (level_id) (shaper_profile_id)"
1131 			" (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1132 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1133 			"       Add port tm leaf node.\n\n"
1134 
1135 			"del port tm node (port_id) (node_id)\n"
1136 			"       Delete port tm node.\n\n"
1137 
1138 			"set port tm node parent (port_id) (node_id) (parent_node_id)"
1139 			" (priority) (weight)\n"
1140 			"       Set port tm node parent.\n\n"
1141 
1142 			"suspend port tm node (port_id) (node_id)"
1143 			"       Suspend tm node.\n\n"
1144 
1145 			"resume port tm node (port_id) (node_id)"
1146 			"       Resume tm node.\n\n"
1147 
1148 			"port tm hierarchy commit (port_id) (clean_on_fail)\n"
1149 			"       Commit tm hierarchy.\n\n"
1150 
1151 			"set port tm mark ip_ecn (port) (green) (yellow)"
1152 			" (red)\n"
1153 			"    Enables/Disables the traffic management marking"
1154 			" for IP ECN (Explicit Congestion Notification)"
1155 			" packets on a given port\n\n"
1156 
1157 			"set port tm mark ip_dscp (port) (green) (yellow)"
1158 			" (red)\n"
1159 			"    Enables/Disables the traffic management marking"
1160 			" on the port for IP dscp packets\n\n"
1161 
1162 			"set port tm mark vlan_dei (port) (green) (yellow)"
1163 			" (red)\n"
1164 			"    Enables/Disables the traffic management marking"
1165 			" on the port for VLAN packets with DEI enabled\n\n"
1166 		);
1167 	}
1168 
1169 	if (show_all || !strcmp(res->section, "devices")) {
1170 		cmdline_printf(
1171 			cl,
1172 			"\n"
1173 			"Device Operations:\n"
1174 			"--------------\n"
1175 			"device detach (identifier)\n"
1176 			"       Detach device by identifier.\n\n"
1177 		);
1178 	}
1179 
1180 }
1181 
1182 cmdline_parse_token_string_t cmd_help_long_help =
1183 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1184 
1185 cmdline_parse_token_string_t cmd_help_long_section =
1186 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1187 			"all#control#display#config#"
1188 			"ports#registers#filters#traffic_management#devices");
1189 
1190 cmdline_parse_inst_t cmd_help_long = {
1191 	.f = cmd_help_long_parsed,
1192 	.data = NULL,
1193 	.help_str = "help all|control|display|config|ports|register|"
1194 		"filters|traffic_management|devices: "
1195 		"Show help",
1196 	.tokens = {
1197 		(void *)&cmd_help_long_help,
1198 		(void *)&cmd_help_long_section,
1199 		NULL,
1200 	},
1201 };
1202 
1203 
1204 /* *** start/stop/close all ports *** */
1205 struct cmd_operate_port_result {
1206 	cmdline_fixed_string_t keyword;
1207 	cmdline_fixed_string_t name;
1208 	cmdline_fixed_string_t value;
1209 };
1210 
1211 static void cmd_operate_port_parsed(void *parsed_result,
1212 				__rte_unused struct cmdline *cl,
1213 				__rte_unused void *data)
1214 {
1215 	struct cmd_operate_port_result *res = parsed_result;
1216 
1217 	if (!strcmp(res->name, "start"))
1218 		start_port(RTE_PORT_ALL);
1219 	else if (!strcmp(res->name, "stop"))
1220 		stop_port(RTE_PORT_ALL);
1221 	else if (!strcmp(res->name, "close"))
1222 		close_port(RTE_PORT_ALL);
1223 	else if (!strcmp(res->name, "reset"))
1224 		reset_port(RTE_PORT_ALL);
1225 	else
1226 		fprintf(stderr, "Unknown parameter\n");
1227 }
1228 
1229 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1230 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1231 								"port");
1232 cmdline_parse_token_string_t cmd_operate_port_all_port =
1233 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1234 						"start#stop#close#reset");
1235 cmdline_parse_token_string_t cmd_operate_port_all_all =
1236 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1237 
1238 cmdline_parse_inst_t cmd_operate_port = {
1239 	.f = cmd_operate_port_parsed,
1240 	.data = NULL,
1241 	.help_str = "port start|stop|close|reset all: Start/Stop/Close/Reset all ports",
1242 	.tokens = {
1243 		(void *)&cmd_operate_port_all_cmd,
1244 		(void *)&cmd_operate_port_all_port,
1245 		(void *)&cmd_operate_port_all_all,
1246 		NULL,
1247 	},
1248 };
1249 
1250 /* *** start/stop/close specific port *** */
1251 struct cmd_operate_specific_port_result {
1252 	cmdline_fixed_string_t keyword;
1253 	cmdline_fixed_string_t name;
1254 	uint8_t value;
1255 };
1256 
1257 static void cmd_operate_specific_port_parsed(void *parsed_result,
1258 			__rte_unused struct cmdline *cl,
1259 				__rte_unused void *data)
1260 {
1261 	struct cmd_operate_specific_port_result *res = parsed_result;
1262 
1263 	if (!strcmp(res->name, "start"))
1264 		start_port(res->value);
1265 	else if (!strcmp(res->name, "stop"))
1266 		stop_port(res->value);
1267 	else if (!strcmp(res->name, "close"))
1268 		close_port(res->value);
1269 	else if (!strcmp(res->name, "reset"))
1270 		reset_port(res->value);
1271 	else
1272 		fprintf(stderr, "Unknown parameter\n");
1273 }
1274 
1275 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1276 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1277 							keyword, "port");
1278 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1279 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1280 						name, "start#stop#close#reset");
1281 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1282 	TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1283 							value, RTE_UINT8);
1284 
1285 cmdline_parse_inst_t cmd_operate_specific_port = {
1286 	.f = cmd_operate_specific_port_parsed,
1287 	.data = NULL,
1288 	.help_str = "port start|stop|close|reset <port_id>: Start/Stop/Close/Reset port_id",
1289 	.tokens = {
1290 		(void *)&cmd_operate_specific_port_cmd,
1291 		(void *)&cmd_operate_specific_port_port,
1292 		(void *)&cmd_operate_specific_port_id,
1293 		NULL,
1294 	},
1295 };
1296 
1297 /* *** enable port setup (after attach) via iterator or event *** */
1298 struct cmd_set_port_setup_on_result {
1299 	cmdline_fixed_string_t set;
1300 	cmdline_fixed_string_t port;
1301 	cmdline_fixed_string_t setup;
1302 	cmdline_fixed_string_t on;
1303 	cmdline_fixed_string_t mode;
1304 };
1305 
1306 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1307 				__rte_unused struct cmdline *cl,
1308 				__rte_unused void *data)
1309 {
1310 	struct cmd_set_port_setup_on_result *res = parsed_result;
1311 
1312 	if (strcmp(res->mode, "event") == 0)
1313 		setup_on_probe_event = true;
1314 	else if (strcmp(res->mode, "iterator") == 0)
1315 		setup_on_probe_event = false;
1316 	else
1317 		fprintf(stderr, "Unknown mode\n");
1318 }
1319 
1320 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1321 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1322 			set, "set");
1323 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1324 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1325 			port, "port");
1326 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1327 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1328 			setup, "setup");
1329 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1330 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1331 			on, "on");
1332 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1333 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1334 			mode, "iterator#event");
1335 
1336 cmdline_parse_inst_t cmd_set_port_setup_on = {
1337 	.f = cmd_set_port_setup_on_parsed,
1338 	.data = NULL,
1339 	.help_str = "set port setup on iterator|event",
1340 	.tokens = {
1341 		(void *)&cmd_set_port_setup_on_set,
1342 		(void *)&cmd_set_port_setup_on_port,
1343 		(void *)&cmd_set_port_setup_on_setup,
1344 		(void *)&cmd_set_port_setup_on_on,
1345 		(void *)&cmd_set_port_setup_on_mode,
1346 		NULL,
1347 	},
1348 };
1349 
1350 /* *** attach a specified port *** */
1351 struct cmd_operate_attach_port_result {
1352 	cmdline_fixed_string_t port;
1353 	cmdline_fixed_string_t keyword;
1354 	cmdline_multi_string_t identifier;
1355 };
1356 
1357 static void cmd_operate_attach_port_parsed(void *parsed_result,
1358 				__rte_unused struct cmdline *cl,
1359 				__rte_unused void *data)
1360 {
1361 	struct cmd_operate_attach_port_result *res = parsed_result;
1362 
1363 	if (!strcmp(res->keyword, "attach"))
1364 		attach_port(res->identifier);
1365 	else
1366 		fprintf(stderr, "Unknown parameter\n");
1367 }
1368 
1369 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1370 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1371 			port, "port");
1372 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1373 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1374 			keyword, "attach");
1375 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1376 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1377 			identifier, TOKEN_STRING_MULTI);
1378 
1379 cmdline_parse_inst_t cmd_operate_attach_port = {
1380 	.f = cmd_operate_attach_port_parsed,
1381 	.data = NULL,
1382 	.help_str = "port attach <identifier>: "
1383 		"(identifier: pci address or virtual dev name)",
1384 	.tokens = {
1385 		(void *)&cmd_operate_attach_port_port,
1386 		(void *)&cmd_operate_attach_port_keyword,
1387 		(void *)&cmd_operate_attach_port_identifier,
1388 		NULL,
1389 	},
1390 };
1391 
1392 /* *** detach a specified port *** */
1393 struct cmd_operate_detach_port_result {
1394 	cmdline_fixed_string_t port;
1395 	cmdline_fixed_string_t keyword;
1396 	portid_t port_id;
1397 };
1398 
1399 static void cmd_operate_detach_port_parsed(void *parsed_result,
1400 				__rte_unused struct cmdline *cl,
1401 				__rte_unused void *data)
1402 {
1403 	struct cmd_operate_detach_port_result *res = parsed_result;
1404 
1405 	if (!strcmp(res->keyword, "detach")) {
1406 		RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1407 		detach_port_device(res->port_id);
1408 	} else {
1409 		fprintf(stderr, "Unknown parameter\n");
1410 	}
1411 }
1412 
1413 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1414 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1415 			port, "port");
1416 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1417 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1418 			keyword, "detach");
1419 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1420 	TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1421 			port_id, RTE_UINT16);
1422 
1423 cmdline_parse_inst_t cmd_operate_detach_port = {
1424 	.f = cmd_operate_detach_port_parsed,
1425 	.data = NULL,
1426 	.help_str = "port detach <port_id>",
1427 	.tokens = {
1428 		(void *)&cmd_operate_detach_port_port,
1429 		(void *)&cmd_operate_detach_port_keyword,
1430 		(void *)&cmd_operate_detach_port_port_id,
1431 		NULL,
1432 	},
1433 };
1434 
1435 /* *** detach device by identifier *** */
1436 struct cmd_operate_detach_device_result {
1437 	cmdline_fixed_string_t device;
1438 	cmdline_fixed_string_t keyword;
1439 	cmdline_fixed_string_t identifier;
1440 };
1441 
1442 static void cmd_operate_detach_device_parsed(void *parsed_result,
1443 				__rte_unused struct cmdline *cl,
1444 				__rte_unused void *data)
1445 {
1446 	struct cmd_operate_detach_device_result *res = parsed_result;
1447 
1448 	if (!strcmp(res->keyword, "detach"))
1449 		detach_devargs(res->identifier);
1450 	else
1451 		fprintf(stderr, "Unknown parameter\n");
1452 }
1453 
1454 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1455 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1456 			device, "device");
1457 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1458 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1459 			keyword, "detach");
1460 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1461 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1462 			identifier, NULL);
1463 
1464 cmdline_parse_inst_t cmd_operate_detach_device = {
1465 	.f = cmd_operate_detach_device_parsed,
1466 	.data = NULL,
1467 	.help_str = "device detach <identifier>:"
1468 		"(identifier: pci address or virtual dev name)",
1469 	.tokens = {
1470 		(void *)&cmd_operate_detach_device_device,
1471 		(void *)&cmd_operate_detach_device_keyword,
1472 		(void *)&cmd_operate_detach_device_identifier,
1473 		NULL,
1474 	},
1475 };
1476 /* *** configure speed for all ports *** */
1477 struct cmd_config_speed_all {
1478 	cmdline_fixed_string_t port;
1479 	cmdline_fixed_string_t keyword;
1480 	cmdline_fixed_string_t all;
1481 	cmdline_fixed_string_t item1;
1482 	cmdline_fixed_string_t item2;
1483 	cmdline_fixed_string_t value1;
1484 	cmdline_fixed_string_t value2;
1485 };
1486 
1487 static int
1488 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1489 {
1490 
1491 	int duplex;
1492 
1493 	if (!strcmp(duplexstr, "half")) {
1494 		duplex = RTE_ETH_LINK_HALF_DUPLEX;
1495 	} else if (!strcmp(duplexstr, "full")) {
1496 		duplex = RTE_ETH_LINK_FULL_DUPLEX;
1497 	} else if (!strcmp(duplexstr, "auto")) {
1498 		duplex = RTE_ETH_LINK_FULL_DUPLEX;
1499 	} else {
1500 		fprintf(stderr, "Unknown duplex parameter\n");
1501 		return -1;
1502 	}
1503 
1504 	if (!strcmp(speedstr, "10")) {
1505 		*speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1506 				RTE_ETH_LINK_SPEED_10M_HD : RTE_ETH_LINK_SPEED_10M;
1507 	} else if (!strcmp(speedstr, "100")) {
1508 		*speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1509 				RTE_ETH_LINK_SPEED_100M_HD : RTE_ETH_LINK_SPEED_100M;
1510 	} else {
1511 		if (duplex != RTE_ETH_LINK_FULL_DUPLEX) {
1512 			fprintf(stderr, "Invalid speed/duplex parameters\n");
1513 			return -1;
1514 		}
1515 		if (!strcmp(speedstr, "1000")) {
1516 			*speed = RTE_ETH_LINK_SPEED_1G;
1517 		} else if (!strcmp(speedstr, "10000")) {
1518 			*speed = RTE_ETH_LINK_SPEED_10G;
1519 		} else if (!strcmp(speedstr, "25000")) {
1520 			*speed = RTE_ETH_LINK_SPEED_25G;
1521 		} else if (!strcmp(speedstr, "40000")) {
1522 			*speed = RTE_ETH_LINK_SPEED_40G;
1523 		} else if (!strcmp(speedstr, "50000")) {
1524 			*speed = RTE_ETH_LINK_SPEED_50G;
1525 		} else if (!strcmp(speedstr, "100000")) {
1526 			*speed = RTE_ETH_LINK_SPEED_100G;
1527 		} else if (!strcmp(speedstr, "200000")) {
1528 			*speed = RTE_ETH_LINK_SPEED_200G;
1529 		} else if (!strcmp(speedstr, "auto")) {
1530 			*speed = RTE_ETH_LINK_SPEED_AUTONEG;
1531 		} else {
1532 			fprintf(stderr, "Unknown speed parameter\n");
1533 			return -1;
1534 		}
1535 	}
1536 
1537 	if (*speed != RTE_ETH_LINK_SPEED_AUTONEG)
1538 		*speed |= RTE_ETH_LINK_SPEED_FIXED;
1539 
1540 	return 0;
1541 }
1542 
1543 static void
1544 cmd_config_speed_all_parsed(void *parsed_result,
1545 			__rte_unused struct cmdline *cl,
1546 			__rte_unused void *data)
1547 {
1548 	struct cmd_config_speed_all *res = parsed_result;
1549 	uint32_t link_speed;
1550 	portid_t pid;
1551 
1552 	if (!all_ports_stopped()) {
1553 		fprintf(stderr, "Please stop all ports first\n");
1554 		return;
1555 	}
1556 
1557 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1558 			&link_speed) < 0)
1559 		return;
1560 
1561 	RTE_ETH_FOREACH_DEV(pid) {
1562 		ports[pid].dev_conf.link_speeds = link_speed;
1563 	}
1564 
1565 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1566 }
1567 
1568 cmdline_parse_token_string_t cmd_config_speed_all_port =
1569 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1570 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1571 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1572 							"config");
1573 cmdline_parse_token_string_t cmd_config_speed_all_all =
1574 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1575 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1576 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1577 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1578 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1579 				"10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1580 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1581 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1582 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1583 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1584 						"half#full#auto");
1585 
1586 cmdline_parse_inst_t cmd_config_speed_all = {
1587 	.f = cmd_config_speed_all_parsed,
1588 	.data = NULL,
1589 	.help_str = "port config all speed "
1590 		"10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1591 							"half|full|auto",
1592 	.tokens = {
1593 		(void *)&cmd_config_speed_all_port,
1594 		(void *)&cmd_config_speed_all_keyword,
1595 		(void *)&cmd_config_speed_all_all,
1596 		(void *)&cmd_config_speed_all_item1,
1597 		(void *)&cmd_config_speed_all_value1,
1598 		(void *)&cmd_config_speed_all_item2,
1599 		(void *)&cmd_config_speed_all_value2,
1600 		NULL,
1601 	},
1602 };
1603 
1604 /* *** configure speed for specific port *** */
1605 struct cmd_config_speed_specific {
1606 	cmdline_fixed_string_t port;
1607 	cmdline_fixed_string_t keyword;
1608 	portid_t id;
1609 	cmdline_fixed_string_t item1;
1610 	cmdline_fixed_string_t item2;
1611 	cmdline_fixed_string_t value1;
1612 	cmdline_fixed_string_t value2;
1613 };
1614 
1615 static void
1616 cmd_config_speed_specific_parsed(void *parsed_result,
1617 				__rte_unused struct cmdline *cl,
1618 				__rte_unused void *data)
1619 {
1620 	struct cmd_config_speed_specific *res = parsed_result;
1621 	uint32_t link_speed;
1622 
1623 	if (port_id_is_invalid(res->id, ENABLED_WARN))
1624 		return;
1625 
1626 	if (!port_is_stopped(res->id)) {
1627 		fprintf(stderr, "Please stop port %d first\n", res->id);
1628 		return;
1629 	}
1630 
1631 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1632 			&link_speed) < 0)
1633 		return;
1634 
1635 	ports[res->id].dev_conf.link_speeds = link_speed;
1636 
1637 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1638 }
1639 
1640 
1641 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1642 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1643 								"port");
1644 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1645 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1646 								"config");
1647 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1648 	TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1649 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1650 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1651 								"speed");
1652 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1653 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1654 				"10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1655 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1656 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1657 								"duplex");
1658 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1659 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1660 							"half#full#auto");
1661 
1662 cmdline_parse_inst_t cmd_config_speed_specific = {
1663 	.f = cmd_config_speed_specific_parsed,
1664 	.data = NULL,
1665 	.help_str = "port config <port_id> speed "
1666 		"10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1667 							"half|full|auto",
1668 	.tokens = {
1669 		(void *)&cmd_config_speed_specific_port,
1670 		(void *)&cmd_config_speed_specific_keyword,
1671 		(void *)&cmd_config_speed_specific_id,
1672 		(void *)&cmd_config_speed_specific_item1,
1673 		(void *)&cmd_config_speed_specific_value1,
1674 		(void *)&cmd_config_speed_specific_item2,
1675 		(void *)&cmd_config_speed_specific_value2,
1676 		NULL,
1677 	},
1678 };
1679 
1680 /* *** configure loopback for all ports *** */
1681 struct cmd_config_loopback_all {
1682 	cmdline_fixed_string_t port;
1683 	cmdline_fixed_string_t keyword;
1684 	cmdline_fixed_string_t all;
1685 	cmdline_fixed_string_t item;
1686 	uint32_t mode;
1687 };
1688 
1689 static void
1690 cmd_config_loopback_all_parsed(void *parsed_result,
1691 			__rte_unused struct cmdline *cl,
1692 			__rte_unused void *data)
1693 {
1694 	struct cmd_config_loopback_all *res = parsed_result;
1695 	portid_t pid;
1696 
1697 	if (!all_ports_stopped()) {
1698 		fprintf(stderr, "Please stop all ports first\n");
1699 		return;
1700 	}
1701 
1702 	RTE_ETH_FOREACH_DEV(pid) {
1703 		ports[pid].dev_conf.lpbk_mode = res->mode;
1704 	}
1705 
1706 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1707 }
1708 
1709 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1710 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1711 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1712 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1713 							"config");
1714 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1715 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1716 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1717 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1718 							"loopback");
1719 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1720 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1721 
1722 cmdline_parse_inst_t cmd_config_loopback_all = {
1723 	.f = cmd_config_loopback_all_parsed,
1724 	.data = NULL,
1725 	.help_str = "port config all loopback <mode>",
1726 	.tokens = {
1727 		(void *)&cmd_config_loopback_all_port,
1728 		(void *)&cmd_config_loopback_all_keyword,
1729 		(void *)&cmd_config_loopback_all_all,
1730 		(void *)&cmd_config_loopback_all_item,
1731 		(void *)&cmd_config_loopback_all_mode,
1732 		NULL,
1733 	},
1734 };
1735 
1736 /* *** configure loopback for specific port *** */
1737 struct cmd_config_loopback_specific {
1738 	cmdline_fixed_string_t port;
1739 	cmdline_fixed_string_t keyword;
1740 	uint16_t port_id;
1741 	cmdline_fixed_string_t item;
1742 	uint32_t mode;
1743 };
1744 
1745 static void
1746 cmd_config_loopback_specific_parsed(void *parsed_result,
1747 				__rte_unused struct cmdline *cl,
1748 				__rte_unused void *data)
1749 {
1750 	struct cmd_config_loopback_specific *res = parsed_result;
1751 
1752 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1753 		return;
1754 
1755 	if (!port_is_stopped(res->port_id)) {
1756 		fprintf(stderr, "Please stop port %u first\n", res->port_id);
1757 		return;
1758 	}
1759 
1760 	ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1761 
1762 	cmd_reconfig_device_queue(res->port_id, 1, 1);
1763 }
1764 
1765 
1766 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1767 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1768 								"port");
1769 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1770 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1771 								"config");
1772 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1773 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1774 								RTE_UINT16);
1775 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1776 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1777 								"loopback");
1778 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1779 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1780 			      RTE_UINT32);
1781 
1782 cmdline_parse_inst_t cmd_config_loopback_specific = {
1783 	.f = cmd_config_loopback_specific_parsed,
1784 	.data = NULL,
1785 	.help_str = "port config <port_id> loopback <mode>",
1786 	.tokens = {
1787 		(void *)&cmd_config_loopback_specific_port,
1788 		(void *)&cmd_config_loopback_specific_keyword,
1789 		(void *)&cmd_config_loopback_specific_id,
1790 		(void *)&cmd_config_loopback_specific_item,
1791 		(void *)&cmd_config_loopback_specific_mode,
1792 		NULL,
1793 	},
1794 };
1795 
1796 /* *** configure txq/rxq, txd/rxd *** */
1797 struct cmd_config_rx_tx {
1798 	cmdline_fixed_string_t port;
1799 	cmdline_fixed_string_t keyword;
1800 	cmdline_fixed_string_t all;
1801 	cmdline_fixed_string_t name;
1802 	uint16_t value;
1803 };
1804 
1805 static void
1806 cmd_config_rx_tx_parsed(void *parsed_result,
1807 			__rte_unused struct cmdline *cl,
1808 			__rte_unused void *data)
1809 {
1810 	struct cmd_config_rx_tx *res = parsed_result;
1811 
1812 	if (!all_ports_stopped()) {
1813 		fprintf(stderr, "Please stop all ports first\n");
1814 		return;
1815 	}
1816 	if (!strcmp(res->name, "rxq")) {
1817 		if (!res->value && !nb_txq) {
1818 			fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1819 			return;
1820 		}
1821 		if (check_nb_rxq(res->value) != 0)
1822 			return;
1823 		nb_rxq = res->value;
1824 	}
1825 	else if (!strcmp(res->name, "txq")) {
1826 		if (!res->value && !nb_rxq) {
1827 			fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1828 			return;
1829 		}
1830 		if (check_nb_txq(res->value) != 0)
1831 			return;
1832 		nb_txq = res->value;
1833 	}
1834 	else if (!strcmp(res->name, "rxd")) {
1835 		if (check_nb_rxd(res->value) != 0)
1836 			return;
1837 		nb_rxd = res->value;
1838 	} else if (!strcmp(res->name, "txd")) {
1839 		if (check_nb_txd(res->value) != 0)
1840 			return;
1841 
1842 		nb_txd = res->value;
1843 	} else {
1844 		fprintf(stderr, "Unknown parameter\n");
1845 		return;
1846 	}
1847 
1848 	fwd_config_setup();
1849 
1850 	init_port_config();
1851 
1852 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1853 }
1854 
1855 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1856 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1857 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1858 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1859 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1860 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1861 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1862 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1863 						"rxq#txq#rxd#txd");
1864 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1865 	TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1866 
1867 cmdline_parse_inst_t cmd_config_rx_tx = {
1868 	.f = cmd_config_rx_tx_parsed,
1869 	.data = NULL,
1870 	.help_str = "port config all rxq|txq|rxd|txd <value>",
1871 	.tokens = {
1872 		(void *)&cmd_config_rx_tx_port,
1873 		(void *)&cmd_config_rx_tx_keyword,
1874 		(void *)&cmd_config_rx_tx_all,
1875 		(void *)&cmd_config_rx_tx_name,
1876 		(void *)&cmd_config_rx_tx_value,
1877 		NULL,
1878 	},
1879 };
1880 
1881 /* *** config max packet length *** */
1882 struct cmd_config_max_pkt_len_result {
1883 	cmdline_fixed_string_t port;
1884 	cmdline_fixed_string_t keyword;
1885 	cmdline_fixed_string_t all;
1886 	cmdline_fixed_string_t name;
1887 	uint32_t value;
1888 };
1889 
1890 static void
1891 cmd_config_max_pkt_len_parsed(void *parsed_result,
1892 				__rte_unused struct cmdline *cl,
1893 				__rte_unused void *data)
1894 {
1895 	struct cmd_config_max_pkt_len_result *res = parsed_result;
1896 	portid_t port_id;
1897 	int ret;
1898 
1899 	if (strcmp(res->name, "max-pkt-len") != 0) {
1900 		printf("Unknown parameter\n");
1901 		return;
1902 	}
1903 
1904 	if (!all_ports_stopped()) {
1905 		fprintf(stderr, "Please stop all ports first\n");
1906 		return;
1907 	}
1908 
1909 	RTE_ETH_FOREACH_DEV(port_id) {
1910 		struct rte_port *port = &ports[port_id];
1911 
1912 		if (res->value < RTE_ETHER_MIN_LEN) {
1913 			fprintf(stderr,
1914 				"max-pkt-len can not be less than %d\n",
1915 				RTE_ETHER_MIN_LEN);
1916 			return;
1917 		}
1918 
1919 		ret = eth_dev_info_get_print_err(port_id, &port->dev_info);
1920 		if (ret != 0) {
1921 			fprintf(stderr,
1922 				"rte_eth_dev_info_get() failed for port %u\n",
1923 				port_id);
1924 			return;
1925 		}
1926 
1927 		update_mtu_from_frame_size(port_id, res->value);
1928 	}
1929 
1930 	init_port_config();
1931 
1932 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1933 }
1934 
1935 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1936 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1937 								"port");
1938 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1939 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1940 								"config");
1941 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1942 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1943 								"all");
1944 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1945 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1946 								"max-pkt-len");
1947 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1948 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1949 								RTE_UINT32);
1950 
1951 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1952 	.f = cmd_config_max_pkt_len_parsed,
1953 	.data = NULL,
1954 	.help_str = "port config all max-pkt-len <value>",
1955 	.tokens = {
1956 		(void *)&cmd_config_max_pkt_len_port,
1957 		(void *)&cmd_config_max_pkt_len_keyword,
1958 		(void *)&cmd_config_max_pkt_len_all,
1959 		(void *)&cmd_config_max_pkt_len_name,
1960 		(void *)&cmd_config_max_pkt_len_value,
1961 		NULL,
1962 	},
1963 };
1964 
1965 /* *** config max LRO aggregated packet size *** */
1966 struct cmd_config_max_lro_pkt_size_result {
1967 	cmdline_fixed_string_t port;
1968 	cmdline_fixed_string_t keyword;
1969 	cmdline_fixed_string_t all;
1970 	cmdline_fixed_string_t name;
1971 	uint32_t value;
1972 };
1973 
1974 static void
1975 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1976 				__rte_unused struct cmdline *cl,
1977 				__rte_unused void *data)
1978 {
1979 	struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1980 	portid_t pid;
1981 
1982 	if (!all_ports_stopped()) {
1983 		fprintf(stderr, "Please stop all ports first\n");
1984 		return;
1985 	}
1986 
1987 	RTE_ETH_FOREACH_DEV(pid) {
1988 		struct rte_port *port = &ports[pid];
1989 
1990 		if (!strcmp(res->name, "max-lro-pkt-size")) {
1991 			if (res->value ==
1992 					port->dev_conf.rxmode.max_lro_pkt_size)
1993 				return;
1994 
1995 			port->dev_conf.rxmode.max_lro_pkt_size = res->value;
1996 		} else {
1997 			fprintf(stderr, "Unknown parameter\n");
1998 			return;
1999 		}
2000 	}
2001 
2002 	init_port_config();
2003 
2004 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2005 }
2006 
2007 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2008 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2009 				 port, "port");
2010 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2011 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2012 				 keyword, "config");
2013 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2014 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2015 				 all, "all");
2016 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2017 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2018 				 name, "max-lro-pkt-size");
2019 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2020 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2021 			      value, RTE_UINT32);
2022 
2023 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2024 	.f = cmd_config_max_lro_pkt_size_parsed,
2025 	.data = NULL,
2026 	.help_str = "port config all max-lro-pkt-size <value>",
2027 	.tokens = {
2028 		(void *)&cmd_config_max_lro_pkt_size_port,
2029 		(void *)&cmd_config_max_lro_pkt_size_keyword,
2030 		(void *)&cmd_config_max_lro_pkt_size_all,
2031 		(void *)&cmd_config_max_lro_pkt_size_name,
2032 		(void *)&cmd_config_max_lro_pkt_size_value,
2033 		NULL,
2034 	},
2035 };
2036 
2037 /* *** configure port MTU *** */
2038 struct cmd_config_mtu_result {
2039 	cmdline_fixed_string_t port;
2040 	cmdline_fixed_string_t keyword;
2041 	cmdline_fixed_string_t mtu;
2042 	portid_t port_id;
2043 	uint16_t value;
2044 };
2045 
2046 static void
2047 cmd_config_mtu_parsed(void *parsed_result,
2048 		      __rte_unused struct cmdline *cl,
2049 		      __rte_unused void *data)
2050 {
2051 	struct cmd_config_mtu_result *res = parsed_result;
2052 
2053 	if (res->value < RTE_ETHER_MIN_LEN) {
2054 		fprintf(stderr, "mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2055 		return;
2056 	}
2057 	port_mtu_set(res->port_id, res->value);
2058 }
2059 
2060 cmdline_parse_token_string_t cmd_config_mtu_port =
2061 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2062 				 "port");
2063 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2064 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2065 				 "config");
2066 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2067 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2068 				 "mtu");
2069 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2070 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2071 				 RTE_UINT16);
2072 cmdline_parse_token_num_t cmd_config_mtu_value =
2073 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2074 				 RTE_UINT16);
2075 
2076 cmdline_parse_inst_t cmd_config_mtu = {
2077 	.f = cmd_config_mtu_parsed,
2078 	.data = NULL,
2079 	.help_str = "port config mtu <port_id> <value>",
2080 	.tokens = {
2081 		(void *)&cmd_config_mtu_port,
2082 		(void *)&cmd_config_mtu_keyword,
2083 		(void *)&cmd_config_mtu_mtu,
2084 		(void *)&cmd_config_mtu_port_id,
2085 		(void *)&cmd_config_mtu_value,
2086 		NULL,
2087 	},
2088 };
2089 
2090 /* *** configure rx mode *** */
2091 struct cmd_config_rx_mode_flag {
2092 	cmdline_fixed_string_t port;
2093 	cmdline_fixed_string_t keyword;
2094 	cmdline_fixed_string_t all;
2095 	cmdline_fixed_string_t name;
2096 	cmdline_fixed_string_t value;
2097 };
2098 
2099 static void
2100 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2101 				__rte_unused struct cmdline *cl,
2102 				__rte_unused void *data)
2103 {
2104 	struct cmd_config_rx_mode_flag *res = parsed_result;
2105 
2106 	if (!all_ports_stopped()) {
2107 		fprintf(stderr, "Please stop all ports first\n");
2108 		return;
2109 	}
2110 
2111 	if (!strcmp(res->name, "drop-en")) {
2112 		if (!strcmp(res->value, "on"))
2113 			rx_drop_en = 1;
2114 		else if (!strcmp(res->value, "off"))
2115 			rx_drop_en = 0;
2116 		else {
2117 			fprintf(stderr, "Unknown parameter\n");
2118 			return;
2119 		}
2120 	} else {
2121 		fprintf(stderr, "Unknown parameter\n");
2122 		return;
2123 	}
2124 
2125 	init_port_config();
2126 
2127 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2128 }
2129 
2130 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2131 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2132 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2133 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2134 								"config");
2135 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2136 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2137 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2138 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2139 					"drop-en");
2140 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2141 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2142 							"on#off");
2143 
2144 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2145 	.f = cmd_config_rx_mode_flag_parsed,
2146 	.data = NULL,
2147 	.help_str = "port config all drop-en on|off",
2148 	.tokens = {
2149 		(void *)&cmd_config_rx_mode_flag_port,
2150 		(void *)&cmd_config_rx_mode_flag_keyword,
2151 		(void *)&cmd_config_rx_mode_flag_all,
2152 		(void *)&cmd_config_rx_mode_flag_name,
2153 		(void *)&cmd_config_rx_mode_flag_value,
2154 		NULL,
2155 	},
2156 };
2157 
2158 /* *** configure rss *** */
2159 struct cmd_config_rss {
2160 	cmdline_fixed_string_t port;
2161 	cmdline_fixed_string_t keyword;
2162 	cmdline_fixed_string_t all;
2163 	cmdline_fixed_string_t name;
2164 	cmdline_fixed_string_t value;
2165 };
2166 
2167 static void
2168 cmd_config_rss_parsed(void *parsed_result,
2169 			__rte_unused struct cmdline *cl,
2170 			__rte_unused void *data)
2171 {
2172 	struct cmd_config_rss *res = parsed_result;
2173 	struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2174 	struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2175 	int use_default = 0;
2176 	int all_updated = 1;
2177 	int diag;
2178 	uint16_t i;
2179 	int ret;
2180 
2181 	if (!strcmp(res->value, "all"))
2182 		rss_conf.rss_hf = RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP |
2183 			RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP |
2184 			RTE_ETH_RSS_L2_PAYLOAD | RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP |
2185 			RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP | RTE_ETH_RSS_GTPU |
2186 			RTE_ETH_RSS_ECPRI | RTE_ETH_RSS_L2TPV2;
2187 	else if (!strcmp(res->value, "eth"))
2188 		rss_conf.rss_hf = RTE_ETH_RSS_ETH;
2189 	else if (!strcmp(res->value, "vlan"))
2190 		rss_conf.rss_hf = RTE_ETH_RSS_VLAN;
2191 	else if (!strcmp(res->value, "ip"))
2192 		rss_conf.rss_hf = RTE_ETH_RSS_IP;
2193 	else if (!strcmp(res->value, "udp"))
2194 		rss_conf.rss_hf = RTE_ETH_RSS_UDP;
2195 	else if (!strcmp(res->value, "tcp"))
2196 		rss_conf.rss_hf = RTE_ETH_RSS_TCP;
2197 	else if (!strcmp(res->value, "sctp"))
2198 		rss_conf.rss_hf = RTE_ETH_RSS_SCTP;
2199 	else if (!strcmp(res->value, "ether"))
2200 		rss_conf.rss_hf = RTE_ETH_RSS_L2_PAYLOAD;
2201 	else if (!strcmp(res->value, "port"))
2202 		rss_conf.rss_hf = RTE_ETH_RSS_PORT;
2203 	else if (!strcmp(res->value, "vxlan"))
2204 		rss_conf.rss_hf = RTE_ETH_RSS_VXLAN;
2205 	else if (!strcmp(res->value, "geneve"))
2206 		rss_conf.rss_hf = RTE_ETH_RSS_GENEVE;
2207 	else if (!strcmp(res->value, "nvgre"))
2208 		rss_conf.rss_hf = RTE_ETH_RSS_NVGRE;
2209 	else if (!strcmp(res->value, "l3-pre32"))
2210 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2211 	else if (!strcmp(res->value, "l3-pre40"))
2212 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2213 	else if (!strcmp(res->value, "l3-pre48"))
2214 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2215 	else if (!strcmp(res->value, "l3-pre56"))
2216 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2217 	else if (!strcmp(res->value, "l3-pre64"))
2218 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2219 	else if (!strcmp(res->value, "l3-pre96"))
2220 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2221 	else if (!strcmp(res->value, "l3-src-only"))
2222 		rss_conf.rss_hf = RTE_ETH_RSS_L3_SRC_ONLY;
2223 	else if (!strcmp(res->value, "l3-dst-only"))
2224 		rss_conf.rss_hf = RTE_ETH_RSS_L3_DST_ONLY;
2225 	else if (!strcmp(res->value, "l4-src-only"))
2226 		rss_conf.rss_hf = RTE_ETH_RSS_L4_SRC_ONLY;
2227 	else if (!strcmp(res->value, "l4-dst-only"))
2228 		rss_conf.rss_hf = RTE_ETH_RSS_L4_DST_ONLY;
2229 	else if (!strcmp(res->value, "l2-src-only"))
2230 		rss_conf.rss_hf = RTE_ETH_RSS_L2_SRC_ONLY;
2231 	else if (!strcmp(res->value, "l2-dst-only"))
2232 		rss_conf.rss_hf = RTE_ETH_RSS_L2_DST_ONLY;
2233 	else if (!strcmp(res->value, "l2tpv3"))
2234 		rss_conf.rss_hf = RTE_ETH_RSS_L2TPV3;
2235 	else if (!strcmp(res->value, "esp"))
2236 		rss_conf.rss_hf = RTE_ETH_RSS_ESP;
2237 	else if (!strcmp(res->value, "ah"))
2238 		rss_conf.rss_hf = RTE_ETH_RSS_AH;
2239 	else if (!strcmp(res->value, "pfcp"))
2240 		rss_conf.rss_hf = RTE_ETH_RSS_PFCP;
2241 	else if (!strcmp(res->value, "pppoe"))
2242 		rss_conf.rss_hf = RTE_ETH_RSS_PPPOE;
2243 	else if (!strcmp(res->value, "gtpu"))
2244 		rss_conf.rss_hf = RTE_ETH_RSS_GTPU;
2245 	else if (!strcmp(res->value, "ecpri"))
2246 		rss_conf.rss_hf = RTE_ETH_RSS_ECPRI;
2247 	else if (!strcmp(res->value, "mpls"))
2248 		rss_conf.rss_hf = RTE_ETH_RSS_MPLS;
2249 	else if (!strcmp(res->value, "ipv4-chksum"))
2250 		rss_conf.rss_hf = RTE_ETH_RSS_IPV4_CHKSUM;
2251 	else if (!strcmp(res->value, "l2tpv2"))
2252 		rss_conf.rss_hf = RTE_ETH_RSS_L2TPV2;
2253 	else if (!strcmp(res->value, "none"))
2254 		rss_conf.rss_hf = 0;
2255 	else if (!strcmp(res->value, "level-default")) {
2256 		rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2257 		rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_PMD_DEFAULT);
2258 	} else if (!strcmp(res->value, "level-outer")) {
2259 		rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2260 		rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_OUTERMOST);
2261 	} else if (!strcmp(res->value, "level-inner")) {
2262 		rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2263 		rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_INNERMOST);
2264 	} else if (!strcmp(res->value, "default"))
2265 		use_default = 1;
2266 	else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2267 						atoi(res->value) < 64)
2268 		rss_conf.rss_hf = 1ULL << atoi(res->value);
2269 	else {
2270 		fprintf(stderr, "Unknown parameter\n");
2271 		return;
2272 	}
2273 	rss_conf.rss_key = NULL;
2274 	/* Update global configuration for RSS types. */
2275 	RTE_ETH_FOREACH_DEV(i) {
2276 		struct rte_eth_rss_conf local_rss_conf;
2277 
2278 		ret = eth_dev_info_get_print_err(i, &dev_info);
2279 		if (ret != 0)
2280 			return;
2281 
2282 		if (use_default)
2283 			rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2284 
2285 		local_rss_conf = rss_conf;
2286 		local_rss_conf.rss_hf = rss_conf.rss_hf &
2287 			dev_info.flow_type_rss_offloads;
2288 		if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2289 			printf("Port %u modified RSS hash function based on hardware support,"
2290 				"requested:%#"PRIx64" configured:%#"PRIx64"\n",
2291 				i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2292 		}
2293 		diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2294 		if (diag < 0) {
2295 			all_updated = 0;
2296 			fprintf(stderr,
2297 				"Configuration of RSS hash at ethernet port %d failed with error (%d): %s.\n",
2298 				i, -diag, strerror(-diag));
2299 		}
2300 	}
2301 	if (all_updated && !use_default) {
2302 		rss_hf = rss_conf.rss_hf;
2303 		printf("rss_hf %#"PRIx64"\n", rss_hf);
2304 	}
2305 }
2306 
2307 cmdline_parse_token_string_t cmd_config_rss_port =
2308 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2309 cmdline_parse_token_string_t cmd_config_rss_keyword =
2310 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2311 cmdline_parse_token_string_t cmd_config_rss_all =
2312 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2313 cmdline_parse_token_string_t cmd_config_rss_name =
2314 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2315 cmdline_parse_token_string_t cmd_config_rss_value =
2316 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2317 
2318 cmdline_parse_inst_t cmd_config_rss = {
2319 	.f = cmd_config_rss_parsed,
2320 	.data = NULL,
2321 	.help_str = "port config all rss "
2322 		"all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2323 		"nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|ipv4-chksum|l2tpv2|"
2324 		"none|level-default|level-outer|level-inner|<flowtype_id>",
2325 	.tokens = {
2326 		(void *)&cmd_config_rss_port,
2327 		(void *)&cmd_config_rss_keyword,
2328 		(void *)&cmd_config_rss_all,
2329 		(void *)&cmd_config_rss_name,
2330 		(void *)&cmd_config_rss_value,
2331 		NULL,
2332 	},
2333 };
2334 
2335 /* *** configure rss hash key *** */
2336 struct cmd_config_rss_hash_key {
2337 	cmdline_fixed_string_t port;
2338 	cmdline_fixed_string_t config;
2339 	portid_t port_id;
2340 	cmdline_fixed_string_t rss_hash_key;
2341 	cmdline_fixed_string_t rss_type;
2342 	cmdline_fixed_string_t key;
2343 };
2344 
2345 static uint8_t
2346 hexa_digit_to_value(char hexa_digit)
2347 {
2348 	if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2349 		return (uint8_t) (hexa_digit - '0');
2350 	if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2351 		return (uint8_t) ((hexa_digit - 'a') + 10);
2352 	if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2353 		return (uint8_t) ((hexa_digit - 'A') + 10);
2354 	/* Invalid hexa digit */
2355 	return 0xFF;
2356 }
2357 
2358 static uint8_t
2359 parse_and_check_key_hexa_digit(char *key, int idx)
2360 {
2361 	uint8_t hexa_v;
2362 
2363 	hexa_v = hexa_digit_to_value(key[idx]);
2364 	if (hexa_v == 0xFF)
2365 		fprintf(stderr,
2366 			"invalid key: character %c at position %d is not a valid hexa digit\n",
2367 			key[idx], idx);
2368 	return hexa_v;
2369 }
2370 
2371 static void
2372 cmd_config_rss_hash_key_parsed(void *parsed_result,
2373 			       __rte_unused struct cmdline *cl,
2374 			       __rte_unused void *data)
2375 {
2376 	struct cmd_config_rss_hash_key *res = parsed_result;
2377 	uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2378 	uint8_t xdgt0;
2379 	uint8_t xdgt1;
2380 	int i;
2381 	struct rte_eth_dev_info dev_info;
2382 	uint8_t hash_key_size;
2383 	uint32_t key_len;
2384 	int ret;
2385 
2386 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2387 	if (ret != 0)
2388 		return;
2389 
2390 	if (dev_info.hash_key_size > 0 &&
2391 			dev_info.hash_key_size <= sizeof(hash_key))
2392 		hash_key_size = dev_info.hash_key_size;
2393 	else {
2394 		fprintf(stderr,
2395 			"dev_info did not provide a valid hash key size\n");
2396 		return;
2397 	}
2398 	/* Check the length of the RSS hash key */
2399 	key_len = strlen(res->key);
2400 	if (key_len != (hash_key_size * 2)) {
2401 		fprintf(stderr,
2402 			"key length: %d invalid - key must be a string of %d hexa-decimal numbers\n",
2403 			(int)key_len, hash_key_size * 2);
2404 		return;
2405 	}
2406 	/* Translate RSS hash key into binary representation */
2407 	for (i = 0; i < hash_key_size; i++) {
2408 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2409 		if (xdgt0 == 0xFF)
2410 			return;
2411 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2412 		if (xdgt1 == 0xFF)
2413 			return;
2414 		hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2415 	}
2416 	port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2417 			hash_key_size);
2418 }
2419 
2420 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2421 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2422 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2423 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2424 				 "config");
2425 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2426 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2427 				 RTE_UINT16);
2428 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2429 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2430 				 rss_hash_key, "rss-hash-key");
2431 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2432 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2433 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2434 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2435 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2436 				 "ipv6-tcp-ex#ipv6-udp-ex#"
2437 				 "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2438 				 "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2439 				 "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls#l2tpv2");
2440 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2441 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2442 
2443 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2444 	.f = cmd_config_rss_hash_key_parsed,
2445 	.data = NULL,
2446 	.help_str = "port config <port_id> rss-hash-key "
2447 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2448 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2449 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2450 		"l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2451 		"l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2452 		"l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls|l2tpv2 "
2453 		"<string of hex digits (variable length, NIC dependent)>",
2454 	.tokens = {
2455 		(void *)&cmd_config_rss_hash_key_port,
2456 		(void *)&cmd_config_rss_hash_key_config,
2457 		(void *)&cmd_config_rss_hash_key_port_id,
2458 		(void *)&cmd_config_rss_hash_key_rss_hash_key,
2459 		(void *)&cmd_config_rss_hash_key_rss_type,
2460 		(void *)&cmd_config_rss_hash_key_value,
2461 		NULL,
2462 	},
2463 };
2464 
2465 /* *** cleanup txq mbufs *** */
2466 struct cmd_cleanup_txq_mbufs_result {
2467 	cmdline_fixed_string_t port;
2468 	cmdline_fixed_string_t keyword;
2469 	cmdline_fixed_string_t name;
2470 	uint16_t port_id;
2471 	uint16_t queue_id;
2472 	uint32_t free_cnt;
2473 };
2474 
2475 static void
2476 cmd_cleanup_txq_mbufs_parsed(void *parsed_result,
2477 			     __rte_unused struct cmdline *cl,
2478 			     __rte_unused void *data)
2479 {
2480 	struct cmd_cleanup_txq_mbufs_result *res = parsed_result;
2481 	uint16_t port_id = res->port_id;
2482 	uint16_t queue_id = res->queue_id;
2483 	uint32_t free_cnt = res->free_cnt;
2484 	struct rte_eth_txq_info qinfo;
2485 	int ret;
2486 
2487 	if (test_done == 0) {
2488 		fprintf(stderr, "Please stop forwarding first\n");
2489 		return;
2490 	}
2491 
2492 	if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) {
2493 		fprintf(stderr, "Failed to get port %u Tx queue %u info\n",
2494 			port_id, queue_id);
2495 		return;
2496 	}
2497 
2498 	if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
2499 		fprintf(stderr, "Tx queue %u not started\n", queue_id);
2500 		return;
2501 	}
2502 
2503 	ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt);
2504 	if (ret < 0) {
2505 		fprintf(stderr,
2506 			"Failed to cleanup mbuf for port %u Tx queue %u error desc: %s(%d)\n",
2507 			port_id, queue_id, strerror(-ret), ret);
2508 		return;
2509 	}
2510 
2511 	printf("Cleanup port %u Tx queue %u mbuf nums: %u\n",
2512 	       port_id, queue_id, ret);
2513 }
2514 
2515 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port =
2516 	TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port,
2517 				 "port");
2518 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup =
2519 	TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword,
2520 				 "cleanup");
2521 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id =
2522 	TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id,
2523 			      RTE_UINT16);
2524 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq =
2525 	TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name,
2526 				 "txq");
2527 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id =
2528 	TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id,
2529 			      RTE_UINT16);
2530 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt =
2531 	TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt,
2532 			      RTE_UINT32);
2533 
2534 cmdline_parse_inst_t cmd_cleanup_txq_mbufs = {
2535 	.f = cmd_cleanup_txq_mbufs_parsed,
2536 	.data = NULL,
2537 	.help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>",
2538 	.tokens = {
2539 		(void *)&cmd_cleanup_txq_mbufs_port,
2540 		(void *)&cmd_cleanup_txq_mbufs_cleanup,
2541 		(void *)&cmd_cleanup_txq_mbufs_port_id,
2542 		(void *)&cmd_cleanup_txq_mbufs_txq,
2543 		(void *)&cmd_cleanup_txq_mbufs_queue_id,
2544 		(void *)&cmd_cleanup_txq_mbufs_free_cnt,
2545 		NULL,
2546 	},
2547 };
2548 
2549 /* *** configure port rxq/txq ring size *** */
2550 struct cmd_config_rxtx_ring_size {
2551 	cmdline_fixed_string_t port;
2552 	cmdline_fixed_string_t config;
2553 	portid_t portid;
2554 	cmdline_fixed_string_t rxtxq;
2555 	uint16_t qid;
2556 	cmdline_fixed_string_t rsize;
2557 	uint16_t size;
2558 };
2559 
2560 static void
2561 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2562 				 __rte_unused struct cmdline *cl,
2563 				 __rte_unused void *data)
2564 {
2565 	struct cmd_config_rxtx_ring_size *res = parsed_result;
2566 	struct rte_port *port;
2567 	uint8_t isrx;
2568 
2569 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2570 		return;
2571 
2572 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2573 		fprintf(stderr, "Invalid port id\n");
2574 		return;
2575 	}
2576 
2577 	port = &ports[res->portid];
2578 
2579 	if (!strcmp(res->rxtxq, "rxq"))
2580 		isrx = 1;
2581 	else if (!strcmp(res->rxtxq, "txq"))
2582 		isrx = 0;
2583 	else {
2584 		fprintf(stderr, "Unknown parameter\n");
2585 		return;
2586 	}
2587 
2588 	if (isrx && rx_queue_id_is_invalid(res->qid))
2589 		return;
2590 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2591 		return;
2592 
2593 	if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2594 		fprintf(stderr,
2595 			"Invalid rx ring_size, must > rx_free_thresh: %d\n",
2596 			rx_free_thresh);
2597 		return;
2598 	}
2599 
2600 	if (isrx)
2601 		port->nb_rx_desc[res->qid] = res->size;
2602 	else
2603 		port->nb_tx_desc[res->qid] = res->size;
2604 
2605 	cmd_reconfig_device_queue(res->portid, 0, 1);
2606 }
2607 
2608 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2609 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2610 				 port, "port");
2611 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2612 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2613 				 config, "config");
2614 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2615 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2616 				 portid, RTE_UINT16);
2617 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2618 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2619 				 rxtxq, "rxq#txq");
2620 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2621 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2622 			      qid, RTE_UINT16);
2623 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2624 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2625 				 rsize, "ring_size");
2626 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2627 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2628 			      size, RTE_UINT16);
2629 
2630 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2631 	.f = cmd_config_rxtx_ring_size_parsed,
2632 	.data = NULL,
2633 	.help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2634 	.tokens = {
2635 		(void *)&cmd_config_rxtx_ring_size_port,
2636 		(void *)&cmd_config_rxtx_ring_size_config,
2637 		(void *)&cmd_config_rxtx_ring_size_portid,
2638 		(void *)&cmd_config_rxtx_ring_size_rxtxq,
2639 		(void *)&cmd_config_rxtx_ring_size_qid,
2640 		(void *)&cmd_config_rxtx_ring_size_rsize,
2641 		(void *)&cmd_config_rxtx_ring_size_size,
2642 		NULL,
2643 	},
2644 };
2645 
2646 /* *** configure port rxq/txq start/stop *** */
2647 struct cmd_config_rxtx_queue {
2648 	cmdline_fixed_string_t port;
2649 	portid_t portid;
2650 	cmdline_fixed_string_t rxtxq;
2651 	uint16_t qid;
2652 	cmdline_fixed_string_t opname;
2653 };
2654 
2655 static void
2656 cmd_config_rxtx_queue_parsed(void *parsed_result,
2657 			__rte_unused struct cmdline *cl,
2658 			__rte_unused void *data)
2659 {
2660 	struct cmd_config_rxtx_queue *res = parsed_result;
2661 	uint8_t isrx;
2662 	uint8_t isstart;
2663 	int ret = 0;
2664 
2665 	if (test_done == 0) {
2666 		fprintf(stderr, "Please stop forwarding first\n");
2667 		return;
2668 	}
2669 
2670 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2671 		return;
2672 
2673 	if (port_is_started(res->portid) != 1) {
2674 		fprintf(stderr, "Please start port %u first\n", res->portid);
2675 		return;
2676 	}
2677 
2678 	if (!strcmp(res->rxtxq, "rxq"))
2679 		isrx = 1;
2680 	else if (!strcmp(res->rxtxq, "txq"))
2681 		isrx = 0;
2682 	else {
2683 		fprintf(stderr, "Unknown parameter\n");
2684 		return;
2685 	}
2686 
2687 	if (isrx && rx_queue_id_is_invalid(res->qid))
2688 		return;
2689 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2690 		return;
2691 
2692 	if (!strcmp(res->opname, "start"))
2693 		isstart = 1;
2694 	else if (!strcmp(res->opname, "stop"))
2695 		isstart = 0;
2696 	else {
2697 		fprintf(stderr, "Unknown parameter\n");
2698 		return;
2699 	}
2700 
2701 	if (isstart && isrx)
2702 		ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2703 	else if (!isstart && isrx)
2704 		ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2705 	else if (isstart && !isrx)
2706 		ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2707 	else
2708 		ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2709 
2710 	if (ret == -ENOTSUP)
2711 		fprintf(stderr, "Function not supported in PMD\n");
2712 }
2713 
2714 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2715 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2716 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2717 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2718 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2719 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2720 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2721 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2722 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2723 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2724 						"start#stop");
2725 
2726 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2727 	.f = cmd_config_rxtx_queue_parsed,
2728 	.data = NULL,
2729 	.help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2730 	.tokens = {
2731 		(void *)&cmd_config_rxtx_queue_port,
2732 		(void *)&cmd_config_rxtx_queue_portid,
2733 		(void *)&cmd_config_rxtx_queue_rxtxq,
2734 		(void *)&cmd_config_rxtx_queue_qid,
2735 		(void *)&cmd_config_rxtx_queue_opname,
2736 		NULL,
2737 	},
2738 };
2739 
2740 /* *** configure port rxq/txq deferred start on/off *** */
2741 struct cmd_config_deferred_start_rxtx_queue {
2742 	cmdline_fixed_string_t port;
2743 	portid_t port_id;
2744 	cmdline_fixed_string_t rxtxq;
2745 	uint16_t qid;
2746 	cmdline_fixed_string_t opname;
2747 	cmdline_fixed_string_t state;
2748 };
2749 
2750 static void
2751 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2752 			__rte_unused struct cmdline *cl,
2753 			__rte_unused void *data)
2754 {
2755 	struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2756 	struct rte_port *port;
2757 	uint8_t isrx;
2758 	uint8_t ison;
2759 	uint8_t needreconfig = 0;
2760 
2761 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2762 		return;
2763 
2764 	if (port_is_started(res->port_id) != 0) {
2765 		fprintf(stderr, "Please stop port %u first\n", res->port_id);
2766 		return;
2767 	}
2768 
2769 	port = &ports[res->port_id];
2770 
2771 	isrx = !strcmp(res->rxtxq, "rxq");
2772 
2773 	if (isrx && rx_queue_id_is_invalid(res->qid))
2774 		return;
2775 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2776 		return;
2777 
2778 	ison = !strcmp(res->state, "on");
2779 
2780 	if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2781 		port->rx_conf[res->qid].rx_deferred_start = ison;
2782 		needreconfig = 1;
2783 	} else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2784 		port->tx_conf[res->qid].tx_deferred_start = ison;
2785 		needreconfig = 1;
2786 	}
2787 
2788 	if (needreconfig)
2789 		cmd_reconfig_device_queue(res->port_id, 0, 1);
2790 }
2791 
2792 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2793 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2794 						port, "port");
2795 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2796 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2797 						port_id, RTE_UINT16);
2798 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2799 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2800 						rxtxq, "rxq#txq");
2801 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2802 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2803 						qid, RTE_UINT16);
2804 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2805 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2806 						opname, "deferred_start");
2807 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2808 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2809 						state, "on#off");
2810 
2811 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2812 	.f = cmd_config_deferred_start_rxtx_queue_parsed,
2813 	.data = NULL,
2814 	.help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2815 	.tokens = {
2816 		(void *)&cmd_config_deferred_start_rxtx_queue_port,
2817 		(void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2818 		(void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2819 		(void *)&cmd_config_deferred_start_rxtx_queue_qid,
2820 		(void *)&cmd_config_deferred_start_rxtx_queue_opname,
2821 		(void *)&cmd_config_deferred_start_rxtx_queue_state,
2822 		NULL,
2823 	},
2824 };
2825 
2826 /* *** configure port rxq/txq setup *** */
2827 struct cmd_setup_rxtx_queue {
2828 	cmdline_fixed_string_t port;
2829 	portid_t portid;
2830 	cmdline_fixed_string_t rxtxq;
2831 	uint16_t qid;
2832 	cmdline_fixed_string_t setup;
2833 };
2834 
2835 /* Common CLI fields for queue setup */
2836 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2837 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2838 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2839 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2840 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2841 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2842 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2843 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2844 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2845 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2846 
2847 static void
2848 cmd_setup_rxtx_queue_parsed(
2849 	void *parsed_result,
2850 	__rte_unused struct cmdline *cl,
2851 	__rte_unused void *data)
2852 {
2853 	struct cmd_setup_rxtx_queue *res = parsed_result;
2854 	struct rte_port *port;
2855 	struct rte_mempool *mp;
2856 	unsigned int socket_id;
2857 	uint8_t isrx = 0;
2858 	int ret;
2859 
2860 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2861 		return;
2862 
2863 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2864 		fprintf(stderr, "Invalid port id\n");
2865 		return;
2866 	}
2867 
2868 	if (!strcmp(res->rxtxq, "rxq"))
2869 		isrx = 1;
2870 	else if (!strcmp(res->rxtxq, "txq"))
2871 		isrx = 0;
2872 	else {
2873 		fprintf(stderr, "Unknown parameter\n");
2874 		return;
2875 	}
2876 
2877 	if (isrx && rx_queue_id_is_invalid(res->qid)) {
2878 		fprintf(stderr, "Invalid rx queue\n");
2879 		return;
2880 	} else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2881 		fprintf(stderr, "Invalid tx queue\n");
2882 		return;
2883 	}
2884 
2885 	port = &ports[res->portid];
2886 	if (isrx) {
2887 		socket_id = rxring_numa[res->portid];
2888 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2889 			socket_id = port->socket_id;
2890 
2891 		mp = mbuf_pool_find(socket_id, 0);
2892 		if (mp == NULL) {
2893 			fprintf(stderr,
2894 				"Failed to setup RX queue: No mempool allocation on the socket %d\n",
2895 				rxring_numa[res->portid]);
2896 			return;
2897 		}
2898 		ret = rx_queue_setup(res->portid,
2899 				     res->qid,
2900 				     port->nb_rx_desc[res->qid],
2901 				     socket_id,
2902 				     &port->rx_conf[res->qid],
2903 				     mp);
2904 		if (ret)
2905 			fprintf(stderr, "Failed to setup RX queue\n");
2906 	} else {
2907 		socket_id = txring_numa[res->portid];
2908 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2909 			socket_id = port->socket_id;
2910 
2911 		if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
2912 			fprintf(stderr,
2913 				"Failed to setup TX queue: not enough descriptors\n");
2914 			return;
2915 		}
2916 		ret = rte_eth_tx_queue_setup(res->portid,
2917 					     res->qid,
2918 					     port->nb_tx_desc[res->qid],
2919 					     socket_id,
2920 					     &port->tx_conf[res->qid]);
2921 		if (ret)
2922 			fprintf(stderr, "Failed to setup TX queue\n");
2923 	}
2924 }
2925 
2926 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2927 	.f = cmd_setup_rxtx_queue_parsed,
2928 	.data = NULL,
2929 	.help_str = "port <port_id> rxq|txq <queue_idx> setup",
2930 	.tokens = {
2931 		(void *)&cmd_setup_rxtx_queue_port,
2932 		(void *)&cmd_setup_rxtx_queue_portid,
2933 		(void *)&cmd_setup_rxtx_queue_rxtxq,
2934 		(void *)&cmd_setup_rxtx_queue_qid,
2935 		(void *)&cmd_setup_rxtx_queue_setup,
2936 		NULL,
2937 	},
2938 };
2939 
2940 
2941 /* *** Configure RSS RETA *** */
2942 struct cmd_config_rss_reta {
2943 	cmdline_fixed_string_t port;
2944 	cmdline_fixed_string_t keyword;
2945 	portid_t port_id;
2946 	cmdline_fixed_string_t name;
2947 	cmdline_fixed_string_t list_name;
2948 	cmdline_fixed_string_t list_of_items;
2949 };
2950 
2951 static int
2952 parse_reta_config(const char *str,
2953 		  struct rte_eth_rss_reta_entry64 *reta_conf,
2954 		  uint16_t nb_entries)
2955 {
2956 	int i;
2957 	unsigned size;
2958 	uint16_t hash_index, idx, shift;
2959 	uint16_t nb_queue;
2960 	char s[256];
2961 	const char *p, *p0 = str;
2962 	char *end;
2963 	enum fieldnames {
2964 		FLD_HASH_INDEX = 0,
2965 		FLD_QUEUE,
2966 		_NUM_FLD
2967 	};
2968 	unsigned long int_fld[_NUM_FLD];
2969 	char *str_fld[_NUM_FLD];
2970 
2971 	while ((p = strchr(p0,'(')) != NULL) {
2972 		++p;
2973 		if((p0 = strchr(p,')')) == NULL)
2974 			return -1;
2975 
2976 		size = p0 - p;
2977 		if(size >= sizeof(s))
2978 			return -1;
2979 
2980 		snprintf(s, sizeof(s), "%.*s", size, p);
2981 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2982 			return -1;
2983 		for (i = 0; i < _NUM_FLD; i++) {
2984 			errno = 0;
2985 			int_fld[i] = strtoul(str_fld[i], &end, 0);
2986 			if (errno != 0 || end == str_fld[i] ||
2987 					int_fld[i] > 65535)
2988 				return -1;
2989 		}
2990 
2991 		hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2992 		nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2993 
2994 		if (hash_index >= nb_entries) {
2995 			fprintf(stderr, "Invalid RETA hash index=%d\n",
2996 				hash_index);
2997 			return -1;
2998 		}
2999 
3000 		idx = hash_index / RTE_ETH_RETA_GROUP_SIZE;
3001 		shift = hash_index % RTE_ETH_RETA_GROUP_SIZE;
3002 		reta_conf[idx].mask |= (1ULL << shift);
3003 		reta_conf[idx].reta[shift] = nb_queue;
3004 	}
3005 
3006 	return 0;
3007 }
3008 
3009 static void
3010 cmd_set_rss_reta_parsed(void *parsed_result,
3011 			__rte_unused struct cmdline *cl,
3012 			__rte_unused void *data)
3013 {
3014 	int ret;
3015 	struct rte_eth_dev_info dev_info;
3016 	struct rte_eth_rss_reta_entry64 reta_conf[8];
3017 	struct cmd_config_rss_reta *res = parsed_result;
3018 
3019 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3020 	if (ret != 0)
3021 		return;
3022 
3023 	if (dev_info.reta_size == 0) {
3024 		fprintf(stderr,
3025 			"Redirection table size is 0 which is invalid for RSS\n");
3026 		return;
3027 	} else
3028 		printf("The reta size of port %d is %u\n",
3029 			res->port_id, dev_info.reta_size);
3030 	if (dev_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
3031 		fprintf(stderr,
3032 			"Currently do not support more than %u entries of redirection table\n",
3033 			RTE_ETH_RSS_RETA_SIZE_512);
3034 		return;
3035 	}
3036 
3037 	memset(reta_conf, 0, sizeof(reta_conf));
3038 	if (!strcmp(res->list_name, "reta")) {
3039 		if (parse_reta_config(res->list_of_items, reta_conf,
3040 						dev_info.reta_size)) {
3041 			fprintf(stderr,
3042 				"Invalid RSS Redirection Table config entered\n");
3043 			return;
3044 		}
3045 		ret = rte_eth_dev_rss_reta_update(res->port_id,
3046 				reta_conf, dev_info.reta_size);
3047 		if (ret != 0)
3048 			fprintf(stderr,
3049 				"Bad redirection table parameter, return code = %d\n",
3050 				ret);
3051 	}
3052 }
3053 
3054 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3055 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3056 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3057 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3058 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3059 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
3060 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3061 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3062 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3063 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3064 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3065         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3066                                  NULL);
3067 cmdline_parse_inst_t cmd_config_rss_reta = {
3068 	.f = cmd_set_rss_reta_parsed,
3069 	.data = NULL,
3070 	.help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3071 	.tokens = {
3072 		(void *)&cmd_config_rss_reta_port,
3073 		(void *)&cmd_config_rss_reta_keyword,
3074 		(void *)&cmd_config_rss_reta_port_id,
3075 		(void *)&cmd_config_rss_reta_name,
3076 		(void *)&cmd_config_rss_reta_list_name,
3077 		(void *)&cmd_config_rss_reta_list_of_items,
3078 		NULL,
3079 	},
3080 };
3081 
3082 /* *** SHOW PORT RETA INFO *** */
3083 struct cmd_showport_reta {
3084 	cmdline_fixed_string_t show;
3085 	cmdline_fixed_string_t port;
3086 	portid_t port_id;
3087 	cmdline_fixed_string_t rss;
3088 	cmdline_fixed_string_t reta;
3089 	uint16_t size;
3090 	cmdline_fixed_string_t list_of_items;
3091 };
3092 
3093 static int
3094 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3095 			   uint16_t nb_entries,
3096 			   char *str)
3097 {
3098 	uint32_t size;
3099 	const char *p, *p0 = str;
3100 	char s[256];
3101 	char *end;
3102 	char *str_fld[8];
3103 	uint16_t i;
3104 	uint16_t num = (nb_entries + RTE_ETH_RETA_GROUP_SIZE - 1) /
3105 			RTE_ETH_RETA_GROUP_SIZE;
3106 	int ret;
3107 
3108 	p = strchr(p0, '(');
3109 	if (p == NULL)
3110 		return -1;
3111 	p++;
3112 	p0 = strchr(p, ')');
3113 	if (p0 == NULL)
3114 		return -1;
3115 	size = p0 - p;
3116 	if (size >= sizeof(s)) {
3117 		fprintf(stderr,
3118 			"The string size exceeds the internal buffer size\n");
3119 		return -1;
3120 	}
3121 	snprintf(s, sizeof(s), "%.*s", size, p);
3122 	ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3123 	if (ret <= 0 || ret != num) {
3124 		fprintf(stderr,
3125 			"The bits of masks do not match the number of reta entries: %u\n",
3126 			num);
3127 		return -1;
3128 	}
3129 	for (i = 0; i < ret; i++)
3130 		conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3131 
3132 	return 0;
3133 }
3134 
3135 static void
3136 cmd_showport_reta_parsed(void *parsed_result,
3137 			 __rte_unused struct cmdline *cl,
3138 			 __rte_unused void *data)
3139 {
3140 	struct cmd_showport_reta *res = parsed_result;
3141 	struct rte_eth_rss_reta_entry64 reta_conf[8];
3142 	struct rte_eth_dev_info dev_info;
3143 	uint16_t max_reta_size;
3144 	int ret;
3145 
3146 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3147 	if (ret != 0)
3148 		return;
3149 
3150 	max_reta_size = RTE_MIN(dev_info.reta_size, RTE_ETH_RSS_RETA_SIZE_512);
3151 	if (res->size == 0 || res->size > max_reta_size) {
3152 		fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n",
3153 			res->size, max_reta_size);
3154 		return;
3155 	}
3156 
3157 	memset(reta_conf, 0, sizeof(reta_conf));
3158 	if (showport_parse_reta_config(reta_conf, res->size,
3159 				res->list_of_items) < 0) {
3160 		fprintf(stderr, "Invalid string: %s for reta masks\n",
3161 			res->list_of_items);
3162 		return;
3163 	}
3164 	port_rss_reta_info(res->port_id, reta_conf, res->size);
3165 }
3166 
3167 cmdline_parse_token_string_t cmd_showport_reta_show =
3168 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3169 cmdline_parse_token_string_t cmd_showport_reta_port =
3170 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3171 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3172 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3173 cmdline_parse_token_string_t cmd_showport_reta_rss =
3174 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3175 cmdline_parse_token_string_t cmd_showport_reta_reta =
3176 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3177 cmdline_parse_token_num_t cmd_showport_reta_size =
3178 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3179 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3180 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3181 					list_of_items, NULL);
3182 
3183 cmdline_parse_inst_t cmd_showport_reta = {
3184 	.f = cmd_showport_reta_parsed,
3185 	.data = NULL,
3186 	.help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3187 	.tokens = {
3188 		(void *)&cmd_showport_reta_show,
3189 		(void *)&cmd_showport_reta_port,
3190 		(void *)&cmd_showport_reta_port_id,
3191 		(void *)&cmd_showport_reta_rss,
3192 		(void *)&cmd_showport_reta_reta,
3193 		(void *)&cmd_showport_reta_size,
3194 		(void *)&cmd_showport_reta_list_of_items,
3195 		NULL,
3196 	},
3197 };
3198 
3199 /* *** Show RSS hash configuration *** */
3200 struct cmd_showport_rss_hash {
3201 	cmdline_fixed_string_t show;
3202 	cmdline_fixed_string_t port;
3203 	portid_t port_id;
3204 	cmdline_fixed_string_t rss_hash;
3205 	cmdline_fixed_string_t rss_type;
3206 	cmdline_fixed_string_t key; /* optional argument */
3207 };
3208 
3209 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3210 				__rte_unused struct cmdline *cl,
3211 				void *show_rss_key)
3212 {
3213 	struct cmd_showport_rss_hash *res = parsed_result;
3214 
3215 	port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3216 }
3217 
3218 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3219 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3220 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3221 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3222 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3223 	TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3224 				 RTE_UINT16);
3225 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3226 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3227 				 "rss-hash");
3228 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3229 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3230 
3231 cmdline_parse_inst_t cmd_showport_rss_hash = {
3232 	.f = cmd_showport_rss_hash_parsed,
3233 	.data = NULL,
3234 	.help_str = "show port <port_id> rss-hash",
3235 	.tokens = {
3236 		(void *)&cmd_showport_rss_hash_show,
3237 		(void *)&cmd_showport_rss_hash_port,
3238 		(void *)&cmd_showport_rss_hash_port_id,
3239 		(void *)&cmd_showport_rss_hash_rss_hash,
3240 		NULL,
3241 	},
3242 };
3243 
3244 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3245 	.f = cmd_showport_rss_hash_parsed,
3246 	.data = (void *)1,
3247 	.help_str = "show port <port_id> rss-hash key",
3248 	.tokens = {
3249 		(void *)&cmd_showport_rss_hash_show,
3250 		(void *)&cmd_showport_rss_hash_port,
3251 		(void *)&cmd_showport_rss_hash_port_id,
3252 		(void *)&cmd_showport_rss_hash_rss_hash,
3253 		(void *)&cmd_showport_rss_hash_rss_key,
3254 		NULL,
3255 	},
3256 };
3257 
3258 /* *** Configure DCB *** */
3259 struct cmd_config_dcb {
3260 	cmdline_fixed_string_t port;
3261 	cmdline_fixed_string_t config;
3262 	portid_t port_id;
3263 	cmdline_fixed_string_t dcb;
3264 	cmdline_fixed_string_t vt;
3265 	cmdline_fixed_string_t vt_en;
3266 	uint8_t num_tcs;
3267 	cmdline_fixed_string_t pfc;
3268 	cmdline_fixed_string_t pfc_en;
3269 };
3270 
3271 static void
3272 cmd_config_dcb_parsed(void *parsed_result,
3273                         __rte_unused struct cmdline *cl,
3274                         __rte_unused void *data)
3275 {
3276 	struct cmd_config_dcb *res = parsed_result;
3277 	struct rte_eth_dcb_info dcb_info;
3278 	portid_t port_id = res->port_id;
3279 	struct rte_port *port;
3280 	uint8_t pfc_en;
3281 	int ret;
3282 
3283 	port = &ports[port_id];
3284 	/** Check if the port is not started **/
3285 	if (port->port_status != RTE_PORT_STOPPED) {
3286 		fprintf(stderr, "Please stop port %d first\n", port_id);
3287 		return;
3288 	}
3289 
3290 	if ((res->num_tcs != RTE_ETH_4_TCS) && (res->num_tcs != RTE_ETH_8_TCS)) {
3291 		fprintf(stderr,
3292 			"The invalid number of traffic class, only 4 or 8 allowed.\n");
3293 		return;
3294 	}
3295 
3296 	if (nb_fwd_lcores < res->num_tcs) {
3297 		fprintf(stderr,
3298 			"nb_cores shouldn't be less than number of TCs.\n");
3299 		return;
3300 	}
3301 
3302 	/* Check whether the port supports the report of DCB info. */
3303 	ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3304 	if (ret == -ENOTSUP) {
3305 		fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n");
3306 		return;
3307 	}
3308 
3309 	if (!strncmp(res->pfc_en, "on", 2))
3310 		pfc_en = 1;
3311 	else
3312 		pfc_en = 0;
3313 
3314 	/* DCB in VT mode */
3315 	if (!strncmp(res->vt_en, "on", 2))
3316 		ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3317 				(enum rte_eth_nb_tcs)res->num_tcs,
3318 				pfc_en);
3319 	else
3320 		ret = init_port_dcb_config(port_id, DCB_ENABLED,
3321 				(enum rte_eth_nb_tcs)res->num_tcs,
3322 				pfc_en);
3323 	if (ret != 0) {
3324 		fprintf(stderr, "Cannot initialize network ports.\n");
3325 		return;
3326 	}
3327 
3328 	fwd_config_setup();
3329 
3330 	cmd_reconfig_device_queue(port_id, 1, 1);
3331 }
3332 
3333 cmdline_parse_token_string_t cmd_config_dcb_port =
3334         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3335 cmdline_parse_token_string_t cmd_config_dcb_config =
3336         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3337 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3338 	TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3339 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3340         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3341 cmdline_parse_token_string_t cmd_config_dcb_vt =
3342         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3343 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3344         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3345 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3346 	TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3347 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3348         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3349 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3350         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3351 
3352 cmdline_parse_inst_t cmd_config_dcb = {
3353 	.f = cmd_config_dcb_parsed,
3354 	.data = NULL,
3355 	.help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3356 	.tokens = {
3357 		(void *)&cmd_config_dcb_port,
3358 		(void *)&cmd_config_dcb_config,
3359 		(void *)&cmd_config_dcb_port_id,
3360 		(void *)&cmd_config_dcb_dcb,
3361 		(void *)&cmd_config_dcb_vt,
3362 		(void *)&cmd_config_dcb_vt_en,
3363 		(void *)&cmd_config_dcb_num_tcs,
3364 		(void *)&cmd_config_dcb_pfc,
3365 		(void *)&cmd_config_dcb_pfc_en,
3366                 NULL,
3367         },
3368 };
3369 
3370 /* *** configure number of packets per burst *** */
3371 struct cmd_config_burst {
3372 	cmdline_fixed_string_t port;
3373 	cmdline_fixed_string_t keyword;
3374 	cmdline_fixed_string_t all;
3375 	cmdline_fixed_string_t name;
3376 	uint16_t value;
3377 };
3378 
3379 static void
3380 cmd_config_burst_parsed(void *parsed_result,
3381 			__rte_unused struct cmdline *cl,
3382 			__rte_unused void *data)
3383 {
3384 	struct cmd_config_burst *res = parsed_result;
3385 	struct rte_eth_dev_info dev_info;
3386 	uint16_t rec_nb_pkts;
3387 	int ret;
3388 
3389 	if (!all_ports_stopped()) {
3390 		fprintf(stderr, "Please stop all ports first\n");
3391 		return;
3392 	}
3393 
3394 	if (!strcmp(res->name, "burst")) {
3395 		if (res->value == 0) {
3396 			/* If user gives a value of zero, query the PMD for
3397 			 * its recommended Rx burst size. Testpmd uses a single
3398 			 * size for all ports, so assume all ports are the same
3399 			 * NIC model and use the values from Port 0.
3400 			 */
3401 			ret = eth_dev_info_get_print_err(0, &dev_info);
3402 			if (ret != 0)
3403 				return;
3404 
3405 			rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3406 
3407 			if (rec_nb_pkts == 0) {
3408 				printf("PMD does not recommend a burst size.\n"
3409 					"User provided value must be between"
3410 					" 1 and %d\n", MAX_PKT_BURST);
3411 				return;
3412 			} else if (rec_nb_pkts > MAX_PKT_BURST) {
3413 				printf("PMD recommended burst size of %d"
3414 					" exceeds maximum value of %d\n",
3415 					rec_nb_pkts, MAX_PKT_BURST);
3416 				return;
3417 			}
3418 			printf("Using PMD-provided burst value of %d\n",
3419 				rec_nb_pkts);
3420 			nb_pkt_per_burst = rec_nb_pkts;
3421 		} else if (res->value > MAX_PKT_BURST) {
3422 			fprintf(stderr, "burst must be >= 1 && <= %d\n",
3423 				MAX_PKT_BURST);
3424 			return;
3425 		} else
3426 			nb_pkt_per_burst = res->value;
3427 	} else {
3428 		fprintf(stderr, "Unknown parameter\n");
3429 		return;
3430 	}
3431 
3432 	init_port_config();
3433 
3434 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3435 }
3436 
3437 cmdline_parse_token_string_t cmd_config_burst_port =
3438 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3439 cmdline_parse_token_string_t cmd_config_burst_keyword =
3440 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3441 cmdline_parse_token_string_t cmd_config_burst_all =
3442 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3443 cmdline_parse_token_string_t cmd_config_burst_name =
3444 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3445 cmdline_parse_token_num_t cmd_config_burst_value =
3446 	TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3447 
3448 cmdline_parse_inst_t cmd_config_burst = {
3449 	.f = cmd_config_burst_parsed,
3450 	.data = NULL,
3451 	.help_str = "port config all burst <value>",
3452 	.tokens = {
3453 		(void *)&cmd_config_burst_port,
3454 		(void *)&cmd_config_burst_keyword,
3455 		(void *)&cmd_config_burst_all,
3456 		(void *)&cmd_config_burst_name,
3457 		(void *)&cmd_config_burst_value,
3458 		NULL,
3459 	},
3460 };
3461 
3462 /* *** configure rx/tx queues *** */
3463 struct cmd_config_thresh {
3464 	cmdline_fixed_string_t port;
3465 	cmdline_fixed_string_t keyword;
3466 	cmdline_fixed_string_t all;
3467 	cmdline_fixed_string_t name;
3468 	uint8_t value;
3469 };
3470 
3471 static void
3472 cmd_config_thresh_parsed(void *parsed_result,
3473 			__rte_unused struct cmdline *cl,
3474 			__rte_unused void *data)
3475 {
3476 	struct cmd_config_thresh *res = parsed_result;
3477 
3478 	if (!all_ports_stopped()) {
3479 		fprintf(stderr, "Please stop all ports first\n");
3480 		return;
3481 	}
3482 
3483 	if (!strcmp(res->name, "txpt"))
3484 		tx_pthresh = res->value;
3485 	else if(!strcmp(res->name, "txht"))
3486 		tx_hthresh = res->value;
3487 	else if(!strcmp(res->name, "txwt"))
3488 		tx_wthresh = res->value;
3489 	else if(!strcmp(res->name, "rxpt"))
3490 		rx_pthresh = res->value;
3491 	else if(!strcmp(res->name, "rxht"))
3492 		rx_hthresh = res->value;
3493 	else if(!strcmp(res->name, "rxwt"))
3494 		rx_wthresh = res->value;
3495 	else {
3496 		fprintf(stderr, "Unknown parameter\n");
3497 		return;
3498 	}
3499 
3500 	init_port_config();
3501 
3502 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3503 }
3504 
3505 cmdline_parse_token_string_t cmd_config_thresh_port =
3506 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3507 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3508 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3509 cmdline_parse_token_string_t cmd_config_thresh_all =
3510 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3511 cmdline_parse_token_string_t cmd_config_thresh_name =
3512 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3513 				"txpt#txht#txwt#rxpt#rxht#rxwt");
3514 cmdline_parse_token_num_t cmd_config_thresh_value =
3515 	TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3516 
3517 cmdline_parse_inst_t cmd_config_thresh = {
3518 	.f = cmd_config_thresh_parsed,
3519 	.data = NULL,
3520 	.help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3521 	.tokens = {
3522 		(void *)&cmd_config_thresh_port,
3523 		(void *)&cmd_config_thresh_keyword,
3524 		(void *)&cmd_config_thresh_all,
3525 		(void *)&cmd_config_thresh_name,
3526 		(void *)&cmd_config_thresh_value,
3527 		NULL,
3528 	},
3529 };
3530 
3531 /* *** configure free/rs threshold *** */
3532 struct cmd_config_threshold {
3533 	cmdline_fixed_string_t port;
3534 	cmdline_fixed_string_t keyword;
3535 	cmdline_fixed_string_t all;
3536 	cmdline_fixed_string_t name;
3537 	uint16_t value;
3538 };
3539 
3540 static void
3541 cmd_config_threshold_parsed(void *parsed_result,
3542 			__rte_unused struct cmdline *cl,
3543 			__rte_unused void *data)
3544 {
3545 	struct cmd_config_threshold *res = parsed_result;
3546 
3547 	if (!all_ports_stopped()) {
3548 		fprintf(stderr, "Please stop all ports first\n");
3549 		return;
3550 	}
3551 
3552 	if (!strcmp(res->name, "txfreet"))
3553 		tx_free_thresh = res->value;
3554 	else if (!strcmp(res->name, "txrst"))
3555 		tx_rs_thresh = res->value;
3556 	else if (!strcmp(res->name, "rxfreet"))
3557 		rx_free_thresh = res->value;
3558 	else {
3559 		fprintf(stderr, "Unknown parameter\n");
3560 		return;
3561 	}
3562 
3563 	init_port_config();
3564 
3565 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3566 }
3567 
3568 cmdline_parse_token_string_t cmd_config_threshold_port =
3569 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3570 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3571 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3572 								"config");
3573 cmdline_parse_token_string_t cmd_config_threshold_all =
3574 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3575 cmdline_parse_token_string_t cmd_config_threshold_name =
3576 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3577 						"txfreet#txrst#rxfreet");
3578 cmdline_parse_token_num_t cmd_config_threshold_value =
3579 	TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3580 
3581 cmdline_parse_inst_t cmd_config_threshold = {
3582 	.f = cmd_config_threshold_parsed,
3583 	.data = NULL,
3584 	.help_str = "port config all txfreet|txrst|rxfreet <value>",
3585 	.tokens = {
3586 		(void *)&cmd_config_threshold_port,
3587 		(void *)&cmd_config_threshold_keyword,
3588 		(void *)&cmd_config_threshold_all,
3589 		(void *)&cmd_config_threshold_name,
3590 		(void *)&cmd_config_threshold_value,
3591 		NULL,
3592 	},
3593 };
3594 
3595 /* *** stop *** */
3596 struct cmd_stop_result {
3597 	cmdline_fixed_string_t stop;
3598 };
3599 
3600 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3601 			    __rte_unused struct cmdline *cl,
3602 			    __rte_unused void *data)
3603 {
3604 	stop_packet_forwarding();
3605 }
3606 
3607 cmdline_parse_token_string_t cmd_stop_stop =
3608 	TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3609 
3610 cmdline_parse_inst_t cmd_stop = {
3611 	.f = cmd_stop_parsed,
3612 	.data = NULL,
3613 	.help_str = "stop: Stop packet forwarding",
3614 	.tokens = {
3615 		(void *)&cmd_stop_stop,
3616 		NULL,
3617 	},
3618 };
3619 
3620 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3621 
3622 unsigned int
3623 parse_item_list(const char *str, const char *item_name, unsigned int max_items,
3624 		unsigned int *parsed_items, int check_unique_values)
3625 {
3626 	unsigned int nb_item;
3627 	unsigned int value;
3628 	unsigned int i;
3629 	unsigned int j;
3630 	int value_ok;
3631 	char c;
3632 
3633 	/*
3634 	 * First parse all items in the list and store their value.
3635 	 */
3636 	value = 0;
3637 	nb_item = 0;
3638 	value_ok = 0;
3639 	for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3640 		c = str[i];
3641 		if ((c >= '0') && (c <= '9')) {
3642 			value = (unsigned int) (value * 10 + (c - '0'));
3643 			value_ok = 1;
3644 			continue;
3645 		}
3646 		if (c != ',') {
3647 			fprintf(stderr, "character %c is not a decimal digit\n", c);
3648 			return 0;
3649 		}
3650 		if (! value_ok) {
3651 			fprintf(stderr, "No valid value before comma\n");
3652 			return 0;
3653 		}
3654 		if (nb_item < max_items) {
3655 			parsed_items[nb_item] = value;
3656 			value_ok = 0;
3657 			value = 0;
3658 		}
3659 		nb_item++;
3660 	}
3661 	if (nb_item >= max_items) {
3662 		fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3663 			item_name, nb_item + 1, max_items);
3664 		return 0;
3665 	}
3666 	parsed_items[nb_item++] = value;
3667 	if (! check_unique_values)
3668 		return nb_item;
3669 
3670 	/*
3671 	 * Then, check that all values in the list are different.
3672 	 * No optimization here...
3673 	 */
3674 	for (i = 0; i < nb_item; i++) {
3675 		for (j = i + 1; j < nb_item; j++) {
3676 			if (parsed_items[j] == parsed_items[i]) {
3677 				fprintf(stderr,
3678 					"duplicated %s %u at index %u and %u\n",
3679 					item_name, parsed_items[i], i, j);
3680 				return 0;
3681 			}
3682 		}
3683 	}
3684 	return nb_item;
3685 }
3686 
3687 struct cmd_set_list_result {
3688 	cmdline_fixed_string_t cmd_keyword;
3689 	cmdline_fixed_string_t list_name;
3690 	cmdline_fixed_string_t list_of_items;
3691 };
3692 
3693 static void cmd_set_list_parsed(void *parsed_result,
3694 				__rte_unused struct cmdline *cl,
3695 				__rte_unused void *data)
3696 {
3697 	struct cmd_set_list_result *res;
3698 	union {
3699 		unsigned int lcorelist[RTE_MAX_LCORE];
3700 		unsigned int portlist[RTE_MAX_ETHPORTS];
3701 	} parsed_items;
3702 	unsigned int nb_item;
3703 
3704 	if (test_done == 0) {
3705 		fprintf(stderr, "Please stop forwarding first\n");
3706 		return;
3707 	}
3708 
3709 	res = parsed_result;
3710 	if (!strcmp(res->list_name, "corelist")) {
3711 		nb_item = parse_item_list(res->list_of_items, "core",
3712 					  RTE_MAX_LCORE,
3713 					  parsed_items.lcorelist, 1);
3714 		if (nb_item > 0) {
3715 			set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3716 			fwd_config_setup();
3717 		}
3718 		return;
3719 	}
3720 	if (!strcmp(res->list_name, "portlist")) {
3721 		nb_item = parse_item_list(res->list_of_items, "port",
3722 					  RTE_MAX_ETHPORTS,
3723 					  parsed_items.portlist, 1);
3724 		if (nb_item > 0) {
3725 			set_fwd_ports_list(parsed_items.portlist, nb_item);
3726 			fwd_config_setup();
3727 		}
3728 	}
3729 }
3730 
3731 cmdline_parse_token_string_t cmd_set_list_keyword =
3732 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3733 				 "set");
3734 cmdline_parse_token_string_t cmd_set_list_name =
3735 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3736 				 "corelist#portlist");
3737 cmdline_parse_token_string_t cmd_set_list_of_items =
3738 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3739 				 NULL);
3740 
3741 cmdline_parse_inst_t cmd_set_fwd_list = {
3742 	.f = cmd_set_list_parsed,
3743 	.data = NULL,
3744 	.help_str = "set corelist|portlist <list0[,list1]*>",
3745 	.tokens = {
3746 		(void *)&cmd_set_list_keyword,
3747 		(void *)&cmd_set_list_name,
3748 		(void *)&cmd_set_list_of_items,
3749 		NULL,
3750 	},
3751 };
3752 
3753 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3754 
3755 struct cmd_setmask_result {
3756 	cmdline_fixed_string_t set;
3757 	cmdline_fixed_string_t mask;
3758 	uint64_t hexavalue;
3759 };
3760 
3761 static void cmd_set_mask_parsed(void *parsed_result,
3762 				__rte_unused struct cmdline *cl,
3763 				__rte_unused void *data)
3764 {
3765 	struct cmd_setmask_result *res = parsed_result;
3766 
3767 	if (test_done == 0) {
3768 		fprintf(stderr, "Please stop forwarding first\n");
3769 		return;
3770 	}
3771 	if (!strcmp(res->mask, "coremask")) {
3772 		set_fwd_lcores_mask(res->hexavalue);
3773 		fwd_config_setup();
3774 	} else if (!strcmp(res->mask, "portmask")) {
3775 		set_fwd_ports_mask(res->hexavalue);
3776 		fwd_config_setup();
3777 	}
3778 }
3779 
3780 cmdline_parse_token_string_t cmd_setmask_set =
3781 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3782 cmdline_parse_token_string_t cmd_setmask_mask =
3783 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3784 				 "coremask#portmask");
3785 cmdline_parse_token_num_t cmd_setmask_value =
3786 	TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3787 
3788 cmdline_parse_inst_t cmd_set_fwd_mask = {
3789 	.f = cmd_set_mask_parsed,
3790 	.data = NULL,
3791 	.help_str = "set coremask|portmask <hexadecimal value>",
3792 	.tokens = {
3793 		(void *)&cmd_setmask_set,
3794 		(void *)&cmd_setmask_mask,
3795 		(void *)&cmd_setmask_value,
3796 		NULL,
3797 	},
3798 };
3799 
3800 /*
3801  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3802  */
3803 struct cmd_set_result {
3804 	cmdline_fixed_string_t set;
3805 	cmdline_fixed_string_t what;
3806 	uint16_t value;
3807 };
3808 
3809 static void cmd_set_parsed(void *parsed_result,
3810 			   __rte_unused struct cmdline *cl,
3811 			   __rte_unused void *data)
3812 {
3813 	struct cmd_set_result *res = parsed_result;
3814 	if (!strcmp(res->what, "nbport")) {
3815 		set_fwd_ports_number(res->value);
3816 		fwd_config_setup();
3817 	} else if (!strcmp(res->what, "nbcore")) {
3818 		set_fwd_lcores_number(res->value);
3819 		fwd_config_setup();
3820 	} else if (!strcmp(res->what, "burst"))
3821 		set_nb_pkt_per_burst(res->value);
3822 	else if (!strcmp(res->what, "verbose"))
3823 		set_verbose_level(res->value);
3824 }
3825 
3826 cmdline_parse_token_string_t cmd_set_set =
3827 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3828 cmdline_parse_token_string_t cmd_set_what =
3829 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3830 				 "nbport#nbcore#burst#verbose");
3831 cmdline_parse_token_num_t cmd_set_value =
3832 	TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3833 
3834 cmdline_parse_inst_t cmd_set_numbers = {
3835 	.f = cmd_set_parsed,
3836 	.data = NULL,
3837 	.help_str = "set nbport|nbcore|burst|verbose <value>",
3838 	.tokens = {
3839 		(void *)&cmd_set_set,
3840 		(void *)&cmd_set_what,
3841 		(void *)&cmd_set_value,
3842 		NULL,
3843 	},
3844 };
3845 
3846 /* *** SET LOG LEVEL CONFIGURATION *** */
3847 
3848 struct cmd_set_log_result {
3849 	cmdline_fixed_string_t set;
3850 	cmdline_fixed_string_t log;
3851 	cmdline_fixed_string_t type;
3852 	uint32_t level;
3853 };
3854 
3855 static void
3856 cmd_set_log_parsed(void *parsed_result,
3857 		   __rte_unused struct cmdline *cl,
3858 		   __rte_unused void *data)
3859 {
3860 	struct cmd_set_log_result *res;
3861 	int ret;
3862 
3863 	res = parsed_result;
3864 	if (!strcmp(res->type, "global"))
3865 		rte_log_set_global_level(res->level);
3866 	else {
3867 		ret = rte_log_set_level_regexp(res->type, res->level);
3868 		if (ret < 0)
3869 			fprintf(stderr, "Unable to set log level\n");
3870 	}
3871 }
3872 
3873 cmdline_parse_token_string_t cmd_set_log_set =
3874 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3875 cmdline_parse_token_string_t cmd_set_log_log =
3876 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3877 cmdline_parse_token_string_t cmd_set_log_type =
3878 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3879 cmdline_parse_token_num_t cmd_set_log_level =
3880 	TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3881 
3882 cmdline_parse_inst_t cmd_set_log = {
3883 	.f = cmd_set_log_parsed,
3884 	.data = NULL,
3885 	.help_str = "set log global|<type> <level>",
3886 	.tokens = {
3887 		(void *)&cmd_set_log_set,
3888 		(void *)&cmd_set_log_log,
3889 		(void *)&cmd_set_log_type,
3890 		(void *)&cmd_set_log_level,
3891 		NULL,
3892 	},
3893 };
3894 
3895 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3896 
3897 struct cmd_set_rxoffs_result {
3898 	cmdline_fixed_string_t cmd_keyword;
3899 	cmdline_fixed_string_t rxoffs;
3900 	cmdline_fixed_string_t seg_offsets;
3901 };
3902 
3903 static void
3904 cmd_set_rxoffs_parsed(void *parsed_result,
3905 		      __rte_unused struct cmdline *cl,
3906 		      __rte_unused void *data)
3907 {
3908 	struct cmd_set_rxoffs_result *res;
3909 	unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3910 	unsigned int nb_segs;
3911 
3912 	res = parsed_result;
3913 	nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3914 				  MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3915 	if (nb_segs > 0)
3916 		set_rx_pkt_offsets(seg_offsets, nb_segs);
3917 	cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3918 }
3919 
3920 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3921 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3922 				 cmd_keyword, "set");
3923 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3924 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3925 				 rxoffs, "rxoffs");
3926 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3927 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3928 				 seg_offsets, NULL);
3929 
3930 cmdline_parse_inst_t cmd_set_rxoffs = {
3931 	.f = cmd_set_rxoffs_parsed,
3932 	.data = NULL,
3933 	.help_str = "set rxoffs <len0[,len1]*>",
3934 	.tokens = {
3935 		(void *)&cmd_set_rxoffs_keyword,
3936 		(void *)&cmd_set_rxoffs_name,
3937 		(void *)&cmd_set_rxoffs_offsets,
3938 		NULL,
3939 	},
3940 };
3941 
3942 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3943 
3944 struct cmd_set_rxpkts_result {
3945 	cmdline_fixed_string_t cmd_keyword;
3946 	cmdline_fixed_string_t rxpkts;
3947 	cmdline_fixed_string_t seg_lengths;
3948 };
3949 
3950 static void
3951 cmd_set_rxpkts_parsed(void *parsed_result,
3952 		      __rte_unused struct cmdline *cl,
3953 		      __rte_unused void *data)
3954 {
3955 	struct cmd_set_rxpkts_result *res;
3956 	unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3957 	unsigned int nb_segs;
3958 
3959 	res = parsed_result;
3960 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3961 				  MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3962 	if (nb_segs > 0)
3963 		set_rx_pkt_segments(seg_lengths, nb_segs);
3964 	cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3965 }
3966 
3967 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3968 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3969 				 cmd_keyword, "set");
3970 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3971 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3972 				 rxpkts, "rxpkts");
3973 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3974 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3975 				 seg_lengths, NULL);
3976 
3977 cmdline_parse_inst_t cmd_set_rxpkts = {
3978 	.f = cmd_set_rxpkts_parsed,
3979 	.data = NULL,
3980 	.help_str = "set rxpkts <len0[,len1]*>",
3981 	.tokens = {
3982 		(void *)&cmd_set_rxpkts_keyword,
3983 		(void *)&cmd_set_rxpkts_name,
3984 		(void *)&cmd_set_rxpkts_lengths,
3985 		NULL,
3986 	},
3987 };
3988 
3989 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3990 
3991 struct cmd_set_txpkts_result {
3992 	cmdline_fixed_string_t cmd_keyword;
3993 	cmdline_fixed_string_t txpkts;
3994 	cmdline_fixed_string_t seg_lengths;
3995 };
3996 
3997 static void
3998 cmd_set_txpkts_parsed(void *parsed_result,
3999 		      __rte_unused struct cmdline *cl,
4000 		      __rte_unused void *data)
4001 {
4002 	struct cmd_set_txpkts_result *res;
4003 	unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
4004 	unsigned int nb_segs;
4005 
4006 	res = parsed_result;
4007 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
4008 				  RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
4009 	if (nb_segs > 0)
4010 		set_tx_pkt_segments(seg_lengths, nb_segs);
4011 }
4012 
4013 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4014 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4015 				 cmd_keyword, "set");
4016 cmdline_parse_token_string_t cmd_set_txpkts_name =
4017 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4018 				 txpkts, "txpkts");
4019 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4020 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4021 				 seg_lengths, NULL);
4022 
4023 cmdline_parse_inst_t cmd_set_txpkts = {
4024 	.f = cmd_set_txpkts_parsed,
4025 	.data = NULL,
4026 	.help_str = "set txpkts <len0[,len1]*>",
4027 	.tokens = {
4028 		(void *)&cmd_set_txpkts_keyword,
4029 		(void *)&cmd_set_txpkts_name,
4030 		(void *)&cmd_set_txpkts_lengths,
4031 		NULL,
4032 	},
4033 };
4034 
4035 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4036 
4037 struct cmd_set_txsplit_result {
4038 	cmdline_fixed_string_t cmd_keyword;
4039 	cmdline_fixed_string_t txsplit;
4040 	cmdline_fixed_string_t mode;
4041 };
4042 
4043 static void
4044 cmd_set_txsplit_parsed(void *parsed_result,
4045 		      __rte_unused struct cmdline *cl,
4046 		      __rte_unused void *data)
4047 {
4048 	struct cmd_set_txsplit_result *res;
4049 
4050 	res = parsed_result;
4051 	set_tx_pkt_split(res->mode);
4052 }
4053 
4054 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4055 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4056 				 cmd_keyword, "set");
4057 cmdline_parse_token_string_t cmd_set_txsplit_name =
4058 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4059 				 txsplit, "txsplit");
4060 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4061 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4062 				 mode, NULL);
4063 
4064 cmdline_parse_inst_t cmd_set_txsplit = {
4065 	.f = cmd_set_txsplit_parsed,
4066 	.data = NULL,
4067 	.help_str = "set txsplit on|off|rand",
4068 	.tokens = {
4069 		(void *)&cmd_set_txsplit_keyword,
4070 		(void *)&cmd_set_txsplit_name,
4071 		(void *)&cmd_set_txsplit_mode,
4072 		NULL,
4073 	},
4074 };
4075 
4076 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4077 
4078 struct cmd_set_txtimes_result {
4079 	cmdline_fixed_string_t cmd_keyword;
4080 	cmdline_fixed_string_t txtimes;
4081 	cmdline_fixed_string_t tx_times;
4082 };
4083 
4084 static void
4085 cmd_set_txtimes_parsed(void *parsed_result,
4086 		       __rte_unused struct cmdline *cl,
4087 		       __rte_unused void *data)
4088 {
4089 	struct cmd_set_txtimes_result *res;
4090 	unsigned int tx_times[2] = {0, 0};
4091 	unsigned int n_times;
4092 
4093 	res = parsed_result;
4094 	n_times = parse_item_list(res->tx_times, "tx times",
4095 				  2, tx_times, 0);
4096 	if (n_times == 2)
4097 		set_tx_pkt_times(tx_times);
4098 }
4099 
4100 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4101 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4102 				 cmd_keyword, "set");
4103 cmdline_parse_token_string_t cmd_set_txtimes_name =
4104 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4105 				 txtimes, "txtimes");
4106 cmdline_parse_token_string_t cmd_set_txtimes_value =
4107 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4108 				 tx_times, NULL);
4109 
4110 cmdline_parse_inst_t cmd_set_txtimes = {
4111 	.f = cmd_set_txtimes_parsed,
4112 	.data = NULL,
4113 	.help_str = "set txtimes <inter_burst>,<intra_burst>",
4114 	.tokens = {
4115 		(void *)&cmd_set_txtimes_keyword,
4116 		(void *)&cmd_set_txtimes_name,
4117 		(void *)&cmd_set_txtimes_value,
4118 		NULL,
4119 	},
4120 };
4121 
4122 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4123 struct cmd_rx_vlan_filter_all_result {
4124 	cmdline_fixed_string_t rx_vlan;
4125 	cmdline_fixed_string_t what;
4126 	cmdline_fixed_string_t all;
4127 	portid_t port_id;
4128 };
4129 
4130 static void
4131 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4132 			      __rte_unused struct cmdline *cl,
4133 			      __rte_unused void *data)
4134 {
4135 	struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4136 
4137 	if (!strcmp(res->what, "add"))
4138 		rx_vlan_all_filter_set(res->port_id, 1);
4139 	else
4140 		rx_vlan_all_filter_set(res->port_id, 0);
4141 }
4142 
4143 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4144 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4145 				 rx_vlan, "rx_vlan");
4146 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4147 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4148 				 what, "add#rm");
4149 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4150 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4151 				 all, "all");
4152 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4153 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4154 			      port_id, RTE_UINT16);
4155 
4156 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4157 	.f = cmd_rx_vlan_filter_all_parsed,
4158 	.data = NULL,
4159 	.help_str = "rx_vlan add|rm all <port_id>: "
4160 		"Add/Remove all identifiers to/from the set of VLAN "
4161 		"identifiers filtered by a port",
4162 	.tokens = {
4163 		(void *)&cmd_rx_vlan_filter_all_rx_vlan,
4164 		(void *)&cmd_rx_vlan_filter_all_what,
4165 		(void *)&cmd_rx_vlan_filter_all_all,
4166 		(void *)&cmd_rx_vlan_filter_all_portid,
4167 		NULL,
4168 	},
4169 };
4170 
4171 /* *** VLAN OFFLOAD SET ON A PORT *** */
4172 struct cmd_vlan_offload_result {
4173 	cmdline_fixed_string_t vlan;
4174 	cmdline_fixed_string_t set;
4175 	cmdline_fixed_string_t vlan_type;
4176 	cmdline_fixed_string_t what;
4177 	cmdline_fixed_string_t on;
4178 	cmdline_fixed_string_t port_id;
4179 };
4180 
4181 static void
4182 cmd_vlan_offload_parsed(void *parsed_result,
4183 			  __rte_unused struct cmdline *cl,
4184 			  __rte_unused void *data)
4185 {
4186 	int on;
4187 	struct cmd_vlan_offload_result *res = parsed_result;
4188 	char *str;
4189 	int i, len = 0;
4190 	portid_t port_id = 0;
4191 	unsigned int tmp;
4192 
4193 	str = res->port_id;
4194 	len = strnlen(str, STR_TOKEN_SIZE);
4195 	i = 0;
4196 	/* Get port_id first */
4197 	while(i < len){
4198 		if(str[i] == ',')
4199 			break;
4200 
4201 		i++;
4202 	}
4203 	str[i]='\0';
4204 	tmp = strtoul(str, NULL, 0);
4205 	/* If port_id greater that what portid_t can represent, return */
4206 	if(tmp >= RTE_MAX_ETHPORTS)
4207 		return;
4208 	port_id = (portid_t)tmp;
4209 
4210 	if (!strcmp(res->on, "on"))
4211 		on = 1;
4212 	else
4213 		on = 0;
4214 
4215 	if (!strcmp(res->what, "strip"))
4216 		rx_vlan_strip_set(port_id,  on);
4217 	else if(!strcmp(res->what, "stripq")){
4218 		uint16_t queue_id = 0;
4219 
4220 		/* No queue_id, return */
4221 		if(i + 1 >= len) {
4222 			fprintf(stderr, "must specify (port,queue_id)\n");
4223 			return;
4224 		}
4225 		tmp = strtoul(str + i + 1, NULL, 0);
4226 		/* If queue_id greater that what 16-bits can represent, return */
4227 		if(tmp > 0xffff)
4228 			return;
4229 
4230 		queue_id = (uint16_t)tmp;
4231 		rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4232 	}
4233 	else if (!strcmp(res->what, "filter"))
4234 		rx_vlan_filter_set(port_id, on);
4235 	else if (!strcmp(res->what, "qinq_strip"))
4236 		rx_vlan_qinq_strip_set(port_id, on);
4237 	else
4238 		vlan_extend_set(port_id, on);
4239 
4240 	return;
4241 }
4242 
4243 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4244 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4245 				 vlan, "vlan");
4246 cmdline_parse_token_string_t cmd_vlan_offload_set =
4247 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4248 				 set, "set");
4249 cmdline_parse_token_string_t cmd_vlan_offload_what =
4250 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4251 				what, "strip#filter#qinq_strip#extend#stripq");
4252 cmdline_parse_token_string_t cmd_vlan_offload_on =
4253 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4254 			      on, "on#off");
4255 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4256 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4257 			      port_id, NULL);
4258 
4259 cmdline_parse_inst_t cmd_vlan_offload = {
4260 	.f = cmd_vlan_offload_parsed,
4261 	.data = NULL,
4262 	.help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4263 		"<port_id[,queue_id]>: "
4264 		"Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4265 	.tokens = {
4266 		(void *)&cmd_vlan_offload_vlan,
4267 		(void *)&cmd_vlan_offload_set,
4268 		(void *)&cmd_vlan_offload_what,
4269 		(void *)&cmd_vlan_offload_on,
4270 		(void *)&cmd_vlan_offload_portid,
4271 		NULL,
4272 	},
4273 };
4274 
4275 /* *** VLAN TPID SET ON A PORT *** */
4276 struct cmd_vlan_tpid_result {
4277 	cmdline_fixed_string_t vlan;
4278 	cmdline_fixed_string_t set;
4279 	cmdline_fixed_string_t vlan_type;
4280 	cmdline_fixed_string_t what;
4281 	uint16_t tp_id;
4282 	portid_t port_id;
4283 };
4284 
4285 static void
4286 cmd_vlan_tpid_parsed(void *parsed_result,
4287 			  __rte_unused struct cmdline *cl,
4288 			  __rte_unused void *data)
4289 {
4290 	struct cmd_vlan_tpid_result *res = parsed_result;
4291 	enum rte_vlan_type vlan_type;
4292 
4293 	if (!strcmp(res->vlan_type, "inner"))
4294 		vlan_type = RTE_ETH_VLAN_TYPE_INNER;
4295 	else if (!strcmp(res->vlan_type, "outer"))
4296 		vlan_type = RTE_ETH_VLAN_TYPE_OUTER;
4297 	else {
4298 		fprintf(stderr, "Unknown vlan type\n");
4299 		return;
4300 	}
4301 	vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4302 }
4303 
4304 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4305 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4306 				 vlan, "vlan");
4307 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4308 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4309 				 set, "set");
4310 cmdline_parse_token_string_t cmd_vlan_type =
4311 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4312 				 vlan_type, "inner#outer");
4313 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4314 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4315 				 what, "tpid");
4316 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4317 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4318 			      tp_id, RTE_UINT16);
4319 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4320 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4321 			      port_id, RTE_UINT16);
4322 
4323 cmdline_parse_inst_t cmd_vlan_tpid = {
4324 	.f = cmd_vlan_tpid_parsed,
4325 	.data = NULL,
4326 	.help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4327 		"Set the VLAN Ether type",
4328 	.tokens = {
4329 		(void *)&cmd_vlan_tpid_vlan,
4330 		(void *)&cmd_vlan_tpid_set,
4331 		(void *)&cmd_vlan_type,
4332 		(void *)&cmd_vlan_tpid_what,
4333 		(void *)&cmd_vlan_tpid_tpid,
4334 		(void *)&cmd_vlan_tpid_portid,
4335 		NULL,
4336 	},
4337 };
4338 
4339 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4340 struct cmd_rx_vlan_filter_result {
4341 	cmdline_fixed_string_t rx_vlan;
4342 	cmdline_fixed_string_t what;
4343 	uint16_t vlan_id;
4344 	portid_t port_id;
4345 };
4346 
4347 static void
4348 cmd_rx_vlan_filter_parsed(void *parsed_result,
4349 			  __rte_unused struct cmdline *cl,
4350 			  __rte_unused void *data)
4351 {
4352 	struct cmd_rx_vlan_filter_result *res = parsed_result;
4353 
4354 	if (!strcmp(res->what, "add"))
4355 		rx_vft_set(res->port_id, res->vlan_id, 1);
4356 	else
4357 		rx_vft_set(res->port_id, res->vlan_id, 0);
4358 }
4359 
4360 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4361 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4362 				 rx_vlan, "rx_vlan");
4363 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4364 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4365 				 what, "add#rm");
4366 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4367 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4368 			      vlan_id, RTE_UINT16);
4369 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4370 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4371 			      port_id, RTE_UINT16);
4372 
4373 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4374 	.f = cmd_rx_vlan_filter_parsed,
4375 	.data = NULL,
4376 	.help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4377 		"Add/Remove a VLAN identifier to/from the set of VLAN "
4378 		"identifiers filtered by a port",
4379 	.tokens = {
4380 		(void *)&cmd_rx_vlan_filter_rx_vlan,
4381 		(void *)&cmd_rx_vlan_filter_what,
4382 		(void *)&cmd_rx_vlan_filter_vlanid,
4383 		(void *)&cmd_rx_vlan_filter_portid,
4384 		NULL,
4385 	},
4386 };
4387 
4388 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4389 struct cmd_tx_vlan_set_result {
4390 	cmdline_fixed_string_t tx_vlan;
4391 	cmdline_fixed_string_t set;
4392 	portid_t port_id;
4393 	uint16_t vlan_id;
4394 };
4395 
4396 static void
4397 cmd_tx_vlan_set_parsed(void *parsed_result,
4398 		       __rte_unused struct cmdline *cl,
4399 		       __rte_unused void *data)
4400 {
4401 	struct cmd_tx_vlan_set_result *res = parsed_result;
4402 
4403 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4404 		return;
4405 
4406 	if (!port_is_stopped(res->port_id)) {
4407 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4408 		return;
4409 	}
4410 
4411 	tx_vlan_set(res->port_id, res->vlan_id);
4412 
4413 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4414 }
4415 
4416 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4417 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4418 				 tx_vlan, "tx_vlan");
4419 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4420 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4421 				 set, "set");
4422 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4423 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4424 			      port_id, RTE_UINT16);
4425 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4426 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4427 			      vlan_id, RTE_UINT16);
4428 
4429 cmdline_parse_inst_t cmd_tx_vlan_set = {
4430 	.f = cmd_tx_vlan_set_parsed,
4431 	.data = NULL,
4432 	.help_str = "tx_vlan set <port_id> <vlan_id>: "
4433 		"Enable hardware insertion of a single VLAN header "
4434 		"with a given TAG Identifier in packets sent on a port",
4435 	.tokens = {
4436 		(void *)&cmd_tx_vlan_set_tx_vlan,
4437 		(void *)&cmd_tx_vlan_set_set,
4438 		(void *)&cmd_tx_vlan_set_portid,
4439 		(void *)&cmd_tx_vlan_set_vlanid,
4440 		NULL,
4441 	},
4442 };
4443 
4444 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4445 struct cmd_tx_vlan_set_qinq_result {
4446 	cmdline_fixed_string_t tx_vlan;
4447 	cmdline_fixed_string_t set;
4448 	portid_t port_id;
4449 	uint16_t vlan_id;
4450 	uint16_t vlan_id_outer;
4451 };
4452 
4453 static void
4454 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4455 			    __rte_unused struct cmdline *cl,
4456 			    __rte_unused void *data)
4457 {
4458 	struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4459 
4460 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4461 		return;
4462 
4463 	if (!port_is_stopped(res->port_id)) {
4464 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4465 		return;
4466 	}
4467 
4468 	tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4469 
4470 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4471 }
4472 
4473 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4474 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4475 		tx_vlan, "tx_vlan");
4476 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4477 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4478 		set, "set");
4479 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4480 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4481 		port_id, RTE_UINT16);
4482 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4483 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4484 		vlan_id, RTE_UINT16);
4485 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4486 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4487 		vlan_id_outer, RTE_UINT16);
4488 
4489 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4490 	.f = cmd_tx_vlan_set_qinq_parsed,
4491 	.data = NULL,
4492 	.help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4493 		"Enable hardware insertion of double VLAN header "
4494 		"with given TAG Identifiers in packets sent on a port",
4495 	.tokens = {
4496 		(void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4497 		(void *)&cmd_tx_vlan_set_qinq_set,
4498 		(void *)&cmd_tx_vlan_set_qinq_portid,
4499 		(void *)&cmd_tx_vlan_set_qinq_vlanid,
4500 		(void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4501 		NULL,
4502 	},
4503 };
4504 
4505 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4506 struct cmd_tx_vlan_set_pvid_result {
4507 	cmdline_fixed_string_t tx_vlan;
4508 	cmdline_fixed_string_t set;
4509 	cmdline_fixed_string_t pvid;
4510 	portid_t port_id;
4511 	uint16_t vlan_id;
4512 	cmdline_fixed_string_t mode;
4513 };
4514 
4515 static void
4516 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4517 			    __rte_unused struct cmdline *cl,
4518 			    __rte_unused void *data)
4519 {
4520 	struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4521 
4522 	if (strcmp(res->mode, "on") == 0)
4523 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4524 	else
4525 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4526 }
4527 
4528 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4529 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4530 				 tx_vlan, "tx_vlan");
4531 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4532 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4533 				 set, "set");
4534 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4535 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4536 				 pvid, "pvid");
4537 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4538 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4539 			     port_id, RTE_UINT16);
4540 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4541 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4542 			      vlan_id, RTE_UINT16);
4543 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4544 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4545 				 mode, "on#off");
4546 
4547 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4548 	.f = cmd_tx_vlan_set_pvid_parsed,
4549 	.data = NULL,
4550 	.help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4551 	.tokens = {
4552 		(void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4553 		(void *)&cmd_tx_vlan_set_pvid_set,
4554 		(void *)&cmd_tx_vlan_set_pvid_pvid,
4555 		(void *)&cmd_tx_vlan_set_pvid_port_id,
4556 		(void *)&cmd_tx_vlan_set_pvid_vlan_id,
4557 		(void *)&cmd_tx_vlan_set_pvid_mode,
4558 		NULL,
4559 	},
4560 };
4561 
4562 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4563 struct cmd_tx_vlan_reset_result {
4564 	cmdline_fixed_string_t tx_vlan;
4565 	cmdline_fixed_string_t reset;
4566 	portid_t port_id;
4567 };
4568 
4569 static void
4570 cmd_tx_vlan_reset_parsed(void *parsed_result,
4571 			 __rte_unused struct cmdline *cl,
4572 			 __rte_unused void *data)
4573 {
4574 	struct cmd_tx_vlan_reset_result *res = parsed_result;
4575 
4576 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4577 		return;
4578 
4579 	if (!port_is_stopped(res->port_id)) {
4580 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4581 		return;
4582 	}
4583 
4584 	tx_vlan_reset(res->port_id);
4585 
4586 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4587 }
4588 
4589 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4590 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4591 				 tx_vlan, "tx_vlan");
4592 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4593 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4594 				 reset, "reset");
4595 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4596 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4597 			      port_id, RTE_UINT16);
4598 
4599 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4600 	.f = cmd_tx_vlan_reset_parsed,
4601 	.data = NULL,
4602 	.help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4603 		"VLAN header in packets sent on a port",
4604 	.tokens = {
4605 		(void *)&cmd_tx_vlan_reset_tx_vlan,
4606 		(void *)&cmd_tx_vlan_reset_reset,
4607 		(void *)&cmd_tx_vlan_reset_portid,
4608 		NULL,
4609 	},
4610 };
4611 
4612 
4613 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4614 struct cmd_csum_result {
4615 	cmdline_fixed_string_t csum;
4616 	cmdline_fixed_string_t mode;
4617 	cmdline_fixed_string_t proto;
4618 	cmdline_fixed_string_t hwsw;
4619 	portid_t port_id;
4620 };
4621 
4622 static void
4623 csum_show(int port_id)
4624 {
4625 	struct rte_eth_dev_info dev_info;
4626 	uint64_t tx_offloads;
4627 	int ret;
4628 
4629 	tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4630 	printf("Parse tunnel is %s\n",
4631 		(ports[port_id].parse_tunnel) ? "on" : "off");
4632 	printf("IP checksum offload is %s\n",
4633 		(tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4634 	printf("UDP checksum offload is %s\n",
4635 		(tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4636 	printf("TCP checksum offload is %s\n",
4637 		(tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4638 	printf("SCTP checksum offload is %s\n",
4639 		(tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4640 	printf("Outer-Ip checksum offload is %s\n",
4641 		(tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4642 	printf("Outer-Udp checksum offload is %s\n",
4643 		(tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4644 
4645 	/* display warnings if configuration is not supported by the NIC */
4646 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
4647 	if (ret != 0)
4648 		return;
4649 
4650 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) &&
4651 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4652 		fprintf(stderr,
4653 			"Warning: hardware IP checksum enabled but not supported by port %d\n",
4654 			port_id);
4655 	}
4656 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) &&
4657 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) == 0) {
4658 		fprintf(stderr,
4659 			"Warning: hardware UDP checksum enabled but not supported by port %d\n",
4660 			port_id);
4661 	}
4662 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) &&
4663 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) == 0) {
4664 		fprintf(stderr,
4665 			"Warning: hardware TCP checksum enabled but not supported by port %d\n",
4666 			port_id);
4667 	}
4668 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) &&
4669 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4670 		fprintf(stderr,
4671 			"Warning: hardware SCTP checksum enabled but not supported by port %d\n",
4672 			port_id);
4673 	}
4674 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4675 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4676 		fprintf(stderr,
4677 			"Warning: hardware outer IP checksum enabled but not supported by port %d\n",
4678 			port_id);
4679 	}
4680 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4681 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
4682 			== 0) {
4683 		fprintf(stderr,
4684 			"Warning: hardware outer UDP checksum enabled but not supported by port %d\n",
4685 			port_id);
4686 	}
4687 }
4688 
4689 static void
4690 cmd_config_queue_tx_offloads(struct rte_port *port)
4691 {
4692 	int k;
4693 
4694 	/* Apply queue tx offloads configuration */
4695 	for (k = 0; k < port->dev_info.max_tx_queues; k++)
4696 		port->tx_conf[k].offloads =
4697 			port->dev_conf.txmode.offloads;
4698 }
4699 
4700 static void
4701 cmd_csum_parsed(void *parsed_result,
4702 		       __rte_unused struct cmdline *cl,
4703 		       __rte_unused void *data)
4704 {
4705 	struct cmd_csum_result *res = parsed_result;
4706 	int hw = 0;
4707 	uint64_t csum_offloads = 0;
4708 	struct rte_eth_dev_info dev_info;
4709 	int ret;
4710 
4711 	if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4712 		fprintf(stderr, "invalid port %d\n", res->port_id);
4713 		return;
4714 	}
4715 	if (!port_is_stopped(res->port_id)) {
4716 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4717 		return;
4718 	}
4719 
4720 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4721 	if (ret != 0)
4722 		return;
4723 
4724 	if (!strcmp(res->mode, "set")) {
4725 
4726 		if (!strcmp(res->hwsw, "hw"))
4727 			hw = 1;
4728 
4729 		if (!strcmp(res->proto, "ip")) {
4730 			if (hw == 0 || (dev_info.tx_offload_capa &
4731 						RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)) {
4732 				csum_offloads |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
4733 			} else {
4734 				fprintf(stderr,
4735 					"IP checksum offload is not supported by port %u\n",
4736 					res->port_id);
4737 			}
4738 		} else if (!strcmp(res->proto, "udp")) {
4739 			if (hw == 0 || (dev_info.tx_offload_capa &
4740 						RTE_ETH_TX_OFFLOAD_UDP_CKSUM)) {
4741 				csum_offloads |= RTE_ETH_TX_OFFLOAD_UDP_CKSUM;
4742 			} else {
4743 				fprintf(stderr,
4744 					"UDP checksum offload is not supported by port %u\n",
4745 					res->port_id);
4746 			}
4747 		} else if (!strcmp(res->proto, "tcp")) {
4748 			if (hw == 0 || (dev_info.tx_offload_capa &
4749 						RTE_ETH_TX_OFFLOAD_TCP_CKSUM)) {
4750 				csum_offloads |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
4751 			} else {
4752 				fprintf(stderr,
4753 					"TCP checksum offload is not supported by port %u\n",
4754 					res->port_id);
4755 			}
4756 		} else if (!strcmp(res->proto, "sctp")) {
4757 			if (hw == 0 || (dev_info.tx_offload_capa &
4758 						RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)) {
4759 				csum_offloads |= RTE_ETH_TX_OFFLOAD_SCTP_CKSUM;
4760 			} else {
4761 				fprintf(stderr,
4762 					"SCTP checksum offload is not supported by port %u\n",
4763 					res->port_id);
4764 			}
4765 		} else if (!strcmp(res->proto, "outer-ip")) {
4766 			if (hw == 0 || (dev_info.tx_offload_capa &
4767 					RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4768 				csum_offloads |=
4769 						RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4770 			} else {
4771 				fprintf(stderr,
4772 					"Outer IP checksum offload is not supported by port %u\n",
4773 					res->port_id);
4774 			}
4775 		} else if (!strcmp(res->proto, "outer-udp")) {
4776 			if (hw == 0 || (dev_info.tx_offload_capa &
4777 					RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4778 				csum_offloads |=
4779 						RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
4780 			} else {
4781 				fprintf(stderr,
4782 					"Outer UDP checksum offload is not supported by port %u\n",
4783 					res->port_id);
4784 			}
4785 		}
4786 
4787 		if (hw) {
4788 			ports[res->port_id].dev_conf.txmode.offloads |=
4789 							csum_offloads;
4790 		} else {
4791 			ports[res->port_id].dev_conf.txmode.offloads &=
4792 							(~csum_offloads);
4793 		}
4794 		cmd_config_queue_tx_offloads(&ports[res->port_id]);
4795 	}
4796 	csum_show(res->port_id);
4797 
4798 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4799 }
4800 
4801 cmdline_parse_token_string_t cmd_csum_csum =
4802 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4803 				csum, "csum");
4804 cmdline_parse_token_string_t cmd_csum_mode =
4805 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4806 				mode, "set");
4807 cmdline_parse_token_string_t cmd_csum_proto =
4808 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4809 				proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4810 cmdline_parse_token_string_t cmd_csum_hwsw =
4811 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4812 				hwsw, "hw#sw");
4813 cmdline_parse_token_num_t cmd_csum_portid =
4814 	TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4815 				port_id, RTE_UINT16);
4816 
4817 cmdline_parse_inst_t cmd_csum_set = {
4818 	.f = cmd_csum_parsed,
4819 	.data = NULL,
4820 	.help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4821 		"Enable/Disable hardware calculation of L3/L4 checksum when "
4822 		"using csum forward engine",
4823 	.tokens = {
4824 		(void *)&cmd_csum_csum,
4825 		(void *)&cmd_csum_mode,
4826 		(void *)&cmd_csum_proto,
4827 		(void *)&cmd_csum_hwsw,
4828 		(void *)&cmd_csum_portid,
4829 		NULL,
4830 	},
4831 };
4832 
4833 cmdline_parse_token_string_t cmd_csum_mode_show =
4834 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4835 				mode, "show");
4836 
4837 cmdline_parse_inst_t cmd_csum_show = {
4838 	.f = cmd_csum_parsed,
4839 	.data = NULL,
4840 	.help_str = "csum show <port_id>: Show checksum offload configuration",
4841 	.tokens = {
4842 		(void *)&cmd_csum_csum,
4843 		(void *)&cmd_csum_mode_show,
4844 		(void *)&cmd_csum_portid,
4845 		NULL,
4846 	},
4847 };
4848 
4849 /* Enable/disable tunnel parsing */
4850 struct cmd_csum_tunnel_result {
4851 	cmdline_fixed_string_t csum;
4852 	cmdline_fixed_string_t parse;
4853 	cmdline_fixed_string_t onoff;
4854 	portid_t port_id;
4855 };
4856 
4857 static void
4858 cmd_csum_tunnel_parsed(void *parsed_result,
4859 		       __rte_unused struct cmdline *cl,
4860 		       __rte_unused void *data)
4861 {
4862 	struct cmd_csum_tunnel_result *res = parsed_result;
4863 
4864 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4865 		return;
4866 
4867 	if (!strcmp(res->onoff, "on"))
4868 		ports[res->port_id].parse_tunnel = 1;
4869 	else
4870 		ports[res->port_id].parse_tunnel = 0;
4871 
4872 	csum_show(res->port_id);
4873 }
4874 
4875 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4876 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4877 				csum, "csum");
4878 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4879 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4880 				parse, "parse-tunnel");
4881 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4882 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4883 				onoff, "on#off");
4884 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4885 	TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4886 				port_id, RTE_UINT16);
4887 
4888 cmdline_parse_inst_t cmd_csum_tunnel = {
4889 	.f = cmd_csum_tunnel_parsed,
4890 	.data = NULL,
4891 	.help_str = "csum parse-tunnel on|off <port_id>: "
4892 		"Enable/Disable parsing of tunnels for csum engine",
4893 	.tokens = {
4894 		(void *)&cmd_csum_tunnel_csum,
4895 		(void *)&cmd_csum_tunnel_parse,
4896 		(void *)&cmd_csum_tunnel_onoff,
4897 		(void *)&cmd_csum_tunnel_portid,
4898 		NULL,
4899 	},
4900 };
4901 
4902 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4903 struct cmd_tso_set_result {
4904 	cmdline_fixed_string_t tso;
4905 	cmdline_fixed_string_t mode;
4906 	uint16_t tso_segsz;
4907 	portid_t port_id;
4908 };
4909 
4910 static void
4911 cmd_tso_set_parsed(void *parsed_result,
4912 		       __rte_unused struct cmdline *cl,
4913 		       __rte_unused void *data)
4914 {
4915 	struct cmd_tso_set_result *res = parsed_result;
4916 	struct rte_eth_dev_info dev_info;
4917 	int ret;
4918 
4919 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4920 		return;
4921 	if (!port_is_stopped(res->port_id)) {
4922 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4923 		return;
4924 	}
4925 
4926 	if (!strcmp(res->mode, "set"))
4927 		ports[res->port_id].tso_segsz = res->tso_segsz;
4928 
4929 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4930 	if (ret != 0)
4931 		return;
4932 
4933 	if ((ports[res->port_id].tso_segsz != 0) &&
4934 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4935 		fprintf(stderr, "Error: TSO is not supported by port %d\n",
4936 			res->port_id);
4937 		return;
4938 	}
4939 
4940 	if (ports[res->port_id].tso_segsz == 0) {
4941 		ports[res->port_id].dev_conf.txmode.offloads &=
4942 						~RTE_ETH_TX_OFFLOAD_TCP_TSO;
4943 		printf("TSO for non-tunneled packets is disabled\n");
4944 	} else {
4945 		ports[res->port_id].dev_conf.txmode.offloads |=
4946 						RTE_ETH_TX_OFFLOAD_TCP_TSO;
4947 		printf("TSO segment size for non-tunneled packets is %d\n",
4948 			ports[res->port_id].tso_segsz);
4949 	}
4950 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
4951 
4952 	/* display warnings if configuration is not supported by the NIC */
4953 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4954 	if (ret != 0)
4955 		return;
4956 
4957 	if ((ports[res->port_id].tso_segsz != 0) &&
4958 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4959 		fprintf(stderr,
4960 			"Warning: TSO enabled but not supported by port %d\n",
4961 			res->port_id);
4962 	}
4963 
4964 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4965 }
4966 
4967 cmdline_parse_token_string_t cmd_tso_set_tso =
4968 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4969 				tso, "tso");
4970 cmdline_parse_token_string_t cmd_tso_set_mode =
4971 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4972 				mode, "set");
4973 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4974 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4975 				tso_segsz, RTE_UINT16);
4976 cmdline_parse_token_num_t cmd_tso_set_portid =
4977 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4978 				port_id, RTE_UINT16);
4979 
4980 cmdline_parse_inst_t cmd_tso_set = {
4981 	.f = cmd_tso_set_parsed,
4982 	.data = NULL,
4983 	.help_str = "tso set <tso_segsz> <port_id>: "
4984 		"Set TSO segment size of non-tunneled packets for csum engine "
4985 		"(0 to disable)",
4986 	.tokens = {
4987 		(void *)&cmd_tso_set_tso,
4988 		(void *)&cmd_tso_set_mode,
4989 		(void *)&cmd_tso_set_tso_segsz,
4990 		(void *)&cmd_tso_set_portid,
4991 		NULL,
4992 	},
4993 };
4994 
4995 cmdline_parse_token_string_t cmd_tso_show_mode =
4996 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4997 				mode, "show");
4998 
4999 
5000 cmdline_parse_inst_t cmd_tso_show = {
5001 	.f = cmd_tso_set_parsed,
5002 	.data = NULL,
5003 	.help_str = "tso show <port_id>: "
5004 		"Show TSO segment size of non-tunneled packets for csum engine",
5005 	.tokens = {
5006 		(void *)&cmd_tso_set_tso,
5007 		(void *)&cmd_tso_show_mode,
5008 		(void *)&cmd_tso_set_portid,
5009 		NULL,
5010 	},
5011 };
5012 
5013 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5014 struct cmd_tunnel_tso_set_result {
5015 	cmdline_fixed_string_t tso;
5016 	cmdline_fixed_string_t mode;
5017 	uint16_t tso_segsz;
5018 	portid_t port_id;
5019 };
5020 
5021 static struct rte_eth_dev_info
5022 check_tunnel_tso_nic_support(portid_t port_id)
5023 {
5024 	struct rte_eth_dev_info dev_info;
5025 
5026 	if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5027 		return dev_info;
5028 
5029 	if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO))
5030 		fprintf(stderr,
5031 			"Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n",
5032 			port_id);
5033 	if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO))
5034 		fprintf(stderr,
5035 			"Warning: GRE TUNNEL TSO not supported therefore not enabled for port %d\n",
5036 			port_id);
5037 	if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO))
5038 		fprintf(stderr,
5039 			"Warning: IPIP TUNNEL TSO not supported therefore not enabled for port %d\n",
5040 			port_id);
5041 	if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO))
5042 		fprintf(stderr,
5043 			"Warning: GENEVE TUNNEL TSO not supported therefore not enabled for port %d\n",
5044 			port_id);
5045 	if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IP_TNL_TSO))
5046 		fprintf(stderr,
5047 			"Warning: IP TUNNEL TSO not supported therefore not enabled for port %d\n",
5048 			port_id);
5049 	if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO))
5050 		fprintf(stderr,
5051 			"Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n",
5052 			port_id);
5053 	return dev_info;
5054 }
5055 
5056 static void
5057 cmd_tunnel_tso_set_parsed(void *parsed_result,
5058 			  __rte_unused struct cmdline *cl,
5059 			  __rte_unused void *data)
5060 {
5061 	struct cmd_tunnel_tso_set_result *res = parsed_result;
5062 	struct rte_eth_dev_info dev_info;
5063 
5064 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5065 		return;
5066 	if (!port_is_stopped(res->port_id)) {
5067 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
5068 		return;
5069 	}
5070 
5071 	if (!strcmp(res->mode, "set"))
5072 		ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5073 
5074 	dev_info = check_tunnel_tso_nic_support(res->port_id);
5075 	if (ports[res->port_id].tunnel_tso_segsz == 0) {
5076 		ports[res->port_id].dev_conf.txmode.offloads &=
5077 			~(RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5078 			  RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5079 			  RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5080 			  RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5081 			  RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5082 			  RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5083 		printf("TSO for tunneled packets is disabled\n");
5084 	} else {
5085 		uint64_t tso_offloads = (RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5086 					 RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5087 					 RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5088 					 RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5089 					 RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5090 					 RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5091 
5092 		ports[res->port_id].dev_conf.txmode.offloads |=
5093 			(tso_offloads & dev_info.tx_offload_capa);
5094 		printf("TSO segment size for tunneled packets is %d\n",
5095 			ports[res->port_id].tunnel_tso_segsz);
5096 
5097 		/* Below conditions are needed to make it work:
5098 		 * (1) tunnel TSO is supported by the NIC;
5099 		 * (2) "csum parse_tunnel" must be set so that tunneled pkts
5100 		 * are recognized;
5101 		 * (3) for tunneled pkts with outer L3 of IPv4,
5102 		 * "csum set outer-ip" must be set to hw, because after tso,
5103 		 * total_len of outer IP header is changed, and the checksum
5104 		 * of outer IP header calculated by sw should be wrong; that
5105 		 * is not necessary for IPv6 tunneled pkts because there's no
5106 		 * checksum in IP header anymore.
5107 		 */
5108 
5109 		if (!ports[res->port_id].parse_tunnel)
5110 			fprintf(stderr,
5111 				"Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n");
5112 		if (!(ports[res->port_id].dev_conf.txmode.offloads &
5113 		      RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5114 			fprintf(stderr,
5115 				"Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n");
5116 	}
5117 
5118 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
5119 	cmd_reconfig_device_queue(res->port_id, 1, 1);
5120 }
5121 
5122 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5123 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5124 				tso, "tunnel_tso");
5125 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5126 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5127 				mode, "set");
5128 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5129 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5130 				tso_segsz, RTE_UINT16);
5131 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5132 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5133 				port_id, RTE_UINT16);
5134 
5135 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5136 	.f = cmd_tunnel_tso_set_parsed,
5137 	.data = NULL,
5138 	.help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5139 		"Set TSO segment size of tunneled packets for csum engine "
5140 		"(0 to disable)",
5141 	.tokens = {
5142 		(void *)&cmd_tunnel_tso_set_tso,
5143 		(void *)&cmd_tunnel_tso_set_mode,
5144 		(void *)&cmd_tunnel_tso_set_tso_segsz,
5145 		(void *)&cmd_tunnel_tso_set_portid,
5146 		NULL,
5147 	},
5148 };
5149 
5150 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5151 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5152 				mode, "show");
5153 
5154 
5155 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5156 	.f = cmd_tunnel_tso_set_parsed,
5157 	.data = NULL,
5158 	.help_str = "tunnel_tso show <port_id> "
5159 		"Show TSO segment size of tunneled packets for csum engine",
5160 	.tokens = {
5161 		(void *)&cmd_tunnel_tso_set_tso,
5162 		(void *)&cmd_tunnel_tso_show_mode,
5163 		(void *)&cmd_tunnel_tso_set_portid,
5164 		NULL,
5165 	},
5166 };
5167 
5168 #ifdef RTE_LIB_GRO
5169 /* *** SET GRO FOR A PORT *** */
5170 struct cmd_gro_enable_result {
5171 	cmdline_fixed_string_t cmd_set;
5172 	cmdline_fixed_string_t cmd_port;
5173 	cmdline_fixed_string_t cmd_keyword;
5174 	cmdline_fixed_string_t cmd_onoff;
5175 	portid_t cmd_pid;
5176 };
5177 
5178 static void
5179 cmd_gro_enable_parsed(void *parsed_result,
5180 		__rte_unused struct cmdline *cl,
5181 		__rte_unused void *data)
5182 {
5183 	struct cmd_gro_enable_result *res;
5184 
5185 	res = parsed_result;
5186 	if (!strcmp(res->cmd_keyword, "gro"))
5187 		setup_gro(res->cmd_onoff, res->cmd_pid);
5188 }
5189 
5190 cmdline_parse_token_string_t cmd_gro_enable_set =
5191 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5192 			cmd_set, "set");
5193 cmdline_parse_token_string_t cmd_gro_enable_port =
5194 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5195 			cmd_keyword, "port");
5196 cmdline_parse_token_num_t cmd_gro_enable_pid =
5197 	TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5198 			cmd_pid, RTE_UINT16);
5199 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5200 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5201 			cmd_keyword, "gro");
5202 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5203 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5204 			cmd_onoff, "on#off");
5205 
5206 cmdline_parse_inst_t cmd_gro_enable = {
5207 	.f = cmd_gro_enable_parsed,
5208 	.data = NULL,
5209 	.help_str = "set port <port_id> gro on|off",
5210 	.tokens = {
5211 		(void *)&cmd_gro_enable_set,
5212 		(void *)&cmd_gro_enable_port,
5213 		(void *)&cmd_gro_enable_pid,
5214 		(void *)&cmd_gro_enable_keyword,
5215 		(void *)&cmd_gro_enable_onoff,
5216 		NULL,
5217 	},
5218 };
5219 
5220 /* *** DISPLAY GRO CONFIGURATION *** */
5221 struct cmd_gro_show_result {
5222 	cmdline_fixed_string_t cmd_show;
5223 	cmdline_fixed_string_t cmd_port;
5224 	cmdline_fixed_string_t cmd_keyword;
5225 	portid_t cmd_pid;
5226 };
5227 
5228 static void
5229 cmd_gro_show_parsed(void *parsed_result,
5230 		__rte_unused struct cmdline *cl,
5231 		__rte_unused void *data)
5232 {
5233 	struct cmd_gro_show_result *res;
5234 
5235 	res = parsed_result;
5236 	if (!strcmp(res->cmd_keyword, "gro"))
5237 		show_gro(res->cmd_pid);
5238 }
5239 
5240 cmdline_parse_token_string_t cmd_gro_show_show =
5241 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5242 			cmd_show, "show");
5243 cmdline_parse_token_string_t cmd_gro_show_port =
5244 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5245 			cmd_port, "port");
5246 cmdline_parse_token_num_t cmd_gro_show_pid =
5247 	TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5248 			cmd_pid, RTE_UINT16);
5249 cmdline_parse_token_string_t cmd_gro_show_keyword =
5250 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5251 			cmd_keyword, "gro");
5252 
5253 cmdline_parse_inst_t cmd_gro_show = {
5254 	.f = cmd_gro_show_parsed,
5255 	.data = NULL,
5256 	.help_str = "show port <port_id> gro",
5257 	.tokens = {
5258 		(void *)&cmd_gro_show_show,
5259 		(void *)&cmd_gro_show_port,
5260 		(void *)&cmd_gro_show_pid,
5261 		(void *)&cmd_gro_show_keyword,
5262 		NULL,
5263 	},
5264 };
5265 
5266 /* *** SET FLUSH CYCLES FOR GRO *** */
5267 struct cmd_gro_flush_result {
5268 	cmdline_fixed_string_t cmd_set;
5269 	cmdline_fixed_string_t cmd_keyword;
5270 	cmdline_fixed_string_t cmd_flush;
5271 	uint8_t cmd_cycles;
5272 };
5273 
5274 static void
5275 cmd_gro_flush_parsed(void *parsed_result,
5276 		__rte_unused struct cmdline *cl,
5277 		__rte_unused void *data)
5278 {
5279 	struct cmd_gro_flush_result *res;
5280 
5281 	res = parsed_result;
5282 	if ((!strcmp(res->cmd_keyword, "gro")) &&
5283 			(!strcmp(res->cmd_flush, "flush")))
5284 		setup_gro_flush_cycles(res->cmd_cycles);
5285 }
5286 
5287 cmdline_parse_token_string_t cmd_gro_flush_set =
5288 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5289 			cmd_set, "set");
5290 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5291 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5292 			cmd_keyword, "gro");
5293 cmdline_parse_token_string_t cmd_gro_flush_flush =
5294 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5295 			cmd_flush, "flush");
5296 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5297 	TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5298 			cmd_cycles, RTE_UINT8);
5299 
5300 cmdline_parse_inst_t cmd_gro_flush = {
5301 	.f = cmd_gro_flush_parsed,
5302 	.data = NULL,
5303 	.help_str = "set gro flush <cycles>",
5304 	.tokens = {
5305 		(void *)&cmd_gro_flush_set,
5306 		(void *)&cmd_gro_flush_keyword,
5307 		(void *)&cmd_gro_flush_flush,
5308 		(void *)&cmd_gro_flush_cycles,
5309 		NULL,
5310 	},
5311 };
5312 #endif /* RTE_LIB_GRO */
5313 
5314 #ifdef RTE_LIB_GSO
5315 /* *** ENABLE/DISABLE GSO *** */
5316 struct cmd_gso_enable_result {
5317 	cmdline_fixed_string_t cmd_set;
5318 	cmdline_fixed_string_t cmd_port;
5319 	cmdline_fixed_string_t cmd_keyword;
5320 	cmdline_fixed_string_t cmd_mode;
5321 	portid_t cmd_pid;
5322 };
5323 
5324 static void
5325 cmd_gso_enable_parsed(void *parsed_result,
5326 		__rte_unused struct cmdline *cl,
5327 		__rte_unused void *data)
5328 {
5329 	struct cmd_gso_enable_result *res;
5330 
5331 	res = parsed_result;
5332 	if (!strcmp(res->cmd_keyword, "gso"))
5333 		setup_gso(res->cmd_mode, res->cmd_pid);
5334 }
5335 
5336 cmdline_parse_token_string_t cmd_gso_enable_set =
5337 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5338 			cmd_set, "set");
5339 cmdline_parse_token_string_t cmd_gso_enable_port =
5340 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5341 			cmd_port, "port");
5342 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5343 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5344 			cmd_keyword, "gso");
5345 cmdline_parse_token_string_t cmd_gso_enable_mode =
5346 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5347 			cmd_mode, "on#off");
5348 cmdline_parse_token_num_t cmd_gso_enable_pid =
5349 	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5350 			cmd_pid, RTE_UINT16);
5351 
5352 cmdline_parse_inst_t cmd_gso_enable = {
5353 	.f = cmd_gso_enable_parsed,
5354 	.data = NULL,
5355 	.help_str = "set port <port_id> gso on|off",
5356 	.tokens = {
5357 		(void *)&cmd_gso_enable_set,
5358 		(void *)&cmd_gso_enable_port,
5359 		(void *)&cmd_gso_enable_pid,
5360 		(void *)&cmd_gso_enable_keyword,
5361 		(void *)&cmd_gso_enable_mode,
5362 		NULL,
5363 	},
5364 };
5365 
5366 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5367 struct cmd_gso_size_result {
5368 	cmdline_fixed_string_t cmd_set;
5369 	cmdline_fixed_string_t cmd_keyword;
5370 	cmdline_fixed_string_t cmd_segsz;
5371 	uint16_t cmd_size;
5372 };
5373 
5374 static void
5375 cmd_gso_size_parsed(void *parsed_result,
5376 		       __rte_unused struct cmdline *cl,
5377 		       __rte_unused void *data)
5378 {
5379 	struct cmd_gso_size_result *res = parsed_result;
5380 
5381 	if (test_done == 0) {
5382 		fprintf(stderr,
5383 			"Before setting GSO segsz, please first stop forwarding\n");
5384 		return;
5385 	}
5386 
5387 	if (!strcmp(res->cmd_keyword, "gso") &&
5388 			!strcmp(res->cmd_segsz, "segsz")) {
5389 		if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5390 			fprintf(stderr,
5391 				"gso_size should be larger than %zu. Please input a legal value\n",
5392 				RTE_GSO_SEG_SIZE_MIN);
5393 		else
5394 			gso_max_segment_size = res->cmd_size;
5395 	}
5396 }
5397 
5398 cmdline_parse_token_string_t cmd_gso_size_set =
5399 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5400 				cmd_set, "set");
5401 cmdline_parse_token_string_t cmd_gso_size_keyword =
5402 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5403 				cmd_keyword, "gso");
5404 cmdline_parse_token_string_t cmd_gso_size_segsz =
5405 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5406 				cmd_segsz, "segsz");
5407 cmdline_parse_token_num_t cmd_gso_size_size =
5408 	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5409 				cmd_size, RTE_UINT16);
5410 
5411 cmdline_parse_inst_t cmd_gso_size = {
5412 	.f = cmd_gso_size_parsed,
5413 	.data = NULL,
5414 	.help_str = "set gso segsz <length>",
5415 	.tokens = {
5416 		(void *)&cmd_gso_size_set,
5417 		(void *)&cmd_gso_size_keyword,
5418 		(void *)&cmd_gso_size_segsz,
5419 		(void *)&cmd_gso_size_size,
5420 		NULL,
5421 	},
5422 };
5423 
5424 /* *** SHOW GSO CONFIGURATION *** */
5425 struct cmd_gso_show_result {
5426 	cmdline_fixed_string_t cmd_show;
5427 	cmdline_fixed_string_t cmd_port;
5428 	cmdline_fixed_string_t cmd_keyword;
5429 	portid_t cmd_pid;
5430 };
5431 
5432 static void
5433 cmd_gso_show_parsed(void *parsed_result,
5434 		       __rte_unused struct cmdline *cl,
5435 		       __rte_unused void *data)
5436 {
5437 	struct cmd_gso_show_result *res = parsed_result;
5438 
5439 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5440 		fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
5441 		return;
5442 	}
5443 	if (!strcmp(res->cmd_keyword, "gso")) {
5444 		if (gso_ports[res->cmd_pid].enable) {
5445 			printf("Max GSO'd packet size: %uB\n"
5446 					"Supported GSO types: TCP/IPv4, "
5447 					"UDP/IPv4, VxLAN with inner "
5448 					"TCP/IPv4 packet, GRE with inner "
5449 					"TCP/IPv4 packet\n",
5450 					gso_max_segment_size);
5451 		} else
5452 			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5453 	}
5454 }
5455 
5456 cmdline_parse_token_string_t cmd_gso_show_show =
5457 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5458 		cmd_show, "show");
5459 cmdline_parse_token_string_t cmd_gso_show_port =
5460 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5461 		cmd_port, "port");
5462 cmdline_parse_token_string_t cmd_gso_show_keyword =
5463 	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5464 				cmd_keyword, "gso");
5465 cmdline_parse_token_num_t cmd_gso_show_pid =
5466 	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5467 				cmd_pid, RTE_UINT16);
5468 
5469 cmdline_parse_inst_t cmd_gso_show = {
5470 	.f = cmd_gso_show_parsed,
5471 	.data = NULL,
5472 	.help_str = "show port <port_id> gso",
5473 	.tokens = {
5474 		(void *)&cmd_gso_show_show,
5475 		(void *)&cmd_gso_show_port,
5476 		(void *)&cmd_gso_show_pid,
5477 		(void *)&cmd_gso_show_keyword,
5478 		NULL,
5479 	},
5480 };
5481 #endif /* RTE_LIB_GSO */
5482 
5483 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5484 struct cmd_set_flush_rx {
5485 	cmdline_fixed_string_t set;
5486 	cmdline_fixed_string_t flush_rx;
5487 	cmdline_fixed_string_t mode;
5488 };
5489 
5490 static void
5491 cmd_set_flush_rx_parsed(void *parsed_result,
5492 		__rte_unused struct cmdline *cl,
5493 		__rte_unused void *data)
5494 {
5495 	struct cmd_set_flush_rx *res = parsed_result;
5496 
5497 	if (num_procs > 1 && (strcmp(res->mode, "on") == 0)) {
5498 		printf("multi-process doesn't support to flush Rx queues.\n");
5499 		return;
5500 	}
5501 
5502 	no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5503 }
5504 
5505 cmdline_parse_token_string_t cmd_setflushrx_set =
5506 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5507 			set, "set");
5508 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5509 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5510 			flush_rx, "flush_rx");
5511 cmdline_parse_token_string_t cmd_setflushrx_mode =
5512 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5513 			mode, "on#off");
5514 
5515 
5516 cmdline_parse_inst_t cmd_set_flush_rx = {
5517 	.f = cmd_set_flush_rx_parsed,
5518 	.help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5519 	.data = NULL,
5520 	.tokens = {
5521 		(void *)&cmd_setflushrx_set,
5522 		(void *)&cmd_setflushrx_flush_rx,
5523 		(void *)&cmd_setflushrx_mode,
5524 		NULL,
5525 	},
5526 };
5527 
5528 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5529 struct cmd_set_link_check {
5530 	cmdline_fixed_string_t set;
5531 	cmdline_fixed_string_t link_check;
5532 	cmdline_fixed_string_t mode;
5533 };
5534 
5535 static void
5536 cmd_set_link_check_parsed(void *parsed_result,
5537 		__rte_unused struct cmdline *cl,
5538 		__rte_unused void *data)
5539 {
5540 	struct cmd_set_link_check *res = parsed_result;
5541 	no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5542 }
5543 
5544 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5545 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5546 			set, "set");
5547 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5548 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5549 			link_check, "link_check");
5550 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5551 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5552 			mode, "on#off");
5553 
5554 
5555 cmdline_parse_inst_t cmd_set_link_check = {
5556 	.f = cmd_set_link_check_parsed,
5557 	.help_str = "set link_check on|off: Enable/Disable link status check "
5558 	            "when starting/stopping a port",
5559 	.data = NULL,
5560 	.tokens = {
5561 		(void *)&cmd_setlinkcheck_set,
5562 		(void *)&cmd_setlinkcheck_link_check,
5563 		(void *)&cmd_setlinkcheck_mode,
5564 		NULL,
5565 	},
5566 };
5567 
5568 /* *** SET NIC BYPASS MODE *** */
5569 struct cmd_set_bypass_mode_result {
5570 	cmdline_fixed_string_t set;
5571 	cmdline_fixed_string_t bypass;
5572 	cmdline_fixed_string_t mode;
5573 	cmdline_fixed_string_t value;
5574 	portid_t port_id;
5575 };
5576 
5577 static void
5578 cmd_set_bypass_mode_parsed(void *parsed_result,
5579 		__rte_unused struct cmdline *cl,
5580 		__rte_unused void *data)
5581 {
5582 	struct cmd_set_bypass_mode_result *res = parsed_result;
5583 	portid_t port_id = res->port_id;
5584 	int32_t rc = -EINVAL;
5585 
5586 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5587 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5588 
5589 	if (!strcmp(res->value, "bypass"))
5590 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5591 	else if (!strcmp(res->value, "isolate"))
5592 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5593 	else
5594 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5595 
5596 	/* Set the bypass mode for the relevant port. */
5597 	rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5598 #endif
5599 	if (rc != 0)
5600 		fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n",
5601 			port_id);
5602 }
5603 
5604 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5605 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5606 			set, "set");
5607 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5608 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5609 			bypass, "bypass");
5610 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5611 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5612 			mode, "mode");
5613 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5614 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5615 			value, "normal#bypass#isolate");
5616 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5617 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5618 				port_id, RTE_UINT16);
5619 
5620 cmdline_parse_inst_t cmd_set_bypass_mode = {
5621 	.f = cmd_set_bypass_mode_parsed,
5622 	.help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5623 	            "Set the NIC bypass mode for port_id",
5624 	.data = NULL,
5625 	.tokens = {
5626 		(void *)&cmd_setbypass_mode_set,
5627 		(void *)&cmd_setbypass_mode_bypass,
5628 		(void *)&cmd_setbypass_mode_mode,
5629 		(void *)&cmd_setbypass_mode_value,
5630 		(void *)&cmd_setbypass_mode_port,
5631 		NULL,
5632 	},
5633 };
5634 
5635 /* *** SET NIC BYPASS EVENT *** */
5636 struct cmd_set_bypass_event_result {
5637 	cmdline_fixed_string_t set;
5638 	cmdline_fixed_string_t bypass;
5639 	cmdline_fixed_string_t event;
5640 	cmdline_fixed_string_t event_value;
5641 	cmdline_fixed_string_t mode;
5642 	cmdline_fixed_string_t mode_value;
5643 	portid_t port_id;
5644 };
5645 
5646 static void
5647 cmd_set_bypass_event_parsed(void *parsed_result,
5648 		__rte_unused struct cmdline *cl,
5649 		__rte_unused void *data)
5650 {
5651 	int32_t rc = -EINVAL;
5652 	struct cmd_set_bypass_event_result *res = parsed_result;
5653 	portid_t port_id = res->port_id;
5654 
5655 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5656 	uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5657 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5658 
5659 	if (!strcmp(res->event_value, "timeout"))
5660 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5661 	else if (!strcmp(res->event_value, "os_on"))
5662 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5663 	else if (!strcmp(res->event_value, "os_off"))
5664 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5665 	else if (!strcmp(res->event_value, "power_on"))
5666 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5667 	else if (!strcmp(res->event_value, "power_off"))
5668 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5669 	else
5670 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5671 
5672 	if (!strcmp(res->mode_value, "bypass"))
5673 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5674 	else if (!strcmp(res->mode_value, "isolate"))
5675 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5676 	else
5677 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5678 
5679 	/* Set the watchdog timeout. */
5680 	if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5681 
5682 		rc = -EINVAL;
5683 		if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5684 			rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5685 							   bypass_timeout);
5686 		}
5687 		if (rc != 0) {
5688 			fprintf(stderr,
5689 				"Failed to set timeout value %u for port %d, errto code: %d.\n",
5690 				bypass_timeout, port_id, rc);
5691 		}
5692 	}
5693 
5694 	/* Set the bypass event to transition to bypass mode. */
5695 	rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5696 					      bypass_mode);
5697 #endif
5698 
5699 	if (rc != 0)
5700 		fprintf(stderr, "\t Failed to set bypass event for port = %d.\n",
5701 			port_id);
5702 }
5703 
5704 cmdline_parse_token_string_t cmd_setbypass_event_set =
5705 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5706 			set, "set");
5707 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5708 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5709 			bypass, "bypass");
5710 cmdline_parse_token_string_t cmd_setbypass_event_event =
5711 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5712 			event, "event");
5713 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5714 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5715 			event_value, "none#timeout#os_off#os_on#power_on#power_off");
5716 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5717 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5718 			mode, "mode");
5719 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5720 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5721 			mode_value, "normal#bypass#isolate");
5722 cmdline_parse_token_num_t cmd_setbypass_event_port =
5723 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5724 				port_id, RTE_UINT16);
5725 
5726 cmdline_parse_inst_t cmd_set_bypass_event = {
5727 	.f = cmd_set_bypass_event_parsed,
5728 	.help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5729 		"power_off mode normal|bypass|isolate <port_id>: "
5730 		"Set the NIC bypass event mode for port_id",
5731 	.data = NULL,
5732 	.tokens = {
5733 		(void *)&cmd_setbypass_event_set,
5734 		(void *)&cmd_setbypass_event_bypass,
5735 		(void *)&cmd_setbypass_event_event,
5736 		(void *)&cmd_setbypass_event_event_value,
5737 		(void *)&cmd_setbypass_event_mode,
5738 		(void *)&cmd_setbypass_event_mode_value,
5739 		(void *)&cmd_setbypass_event_port,
5740 		NULL,
5741 	},
5742 };
5743 
5744 
5745 /* *** SET NIC BYPASS TIMEOUT *** */
5746 struct cmd_set_bypass_timeout_result {
5747 	cmdline_fixed_string_t set;
5748 	cmdline_fixed_string_t bypass;
5749 	cmdline_fixed_string_t timeout;
5750 	cmdline_fixed_string_t value;
5751 };
5752 
5753 static void
5754 cmd_set_bypass_timeout_parsed(void *parsed_result,
5755 		__rte_unused struct cmdline *cl,
5756 		__rte_unused void *data)
5757 {
5758 	__rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5759 
5760 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5761 	if (!strcmp(res->value, "1.5"))
5762 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5763 	else if (!strcmp(res->value, "2"))
5764 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5765 	else if (!strcmp(res->value, "3"))
5766 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5767 	else if (!strcmp(res->value, "4"))
5768 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5769 	else if (!strcmp(res->value, "8"))
5770 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5771 	else if (!strcmp(res->value, "16"))
5772 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5773 	else if (!strcmp(res->value, "32"))
5774 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5775 	else
5776 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5777 #endif
5778 }
5779 
5780 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5781 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5782 			set, "set");
5783 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5784 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5785 			bypass, "bypass");
5786 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5787 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5788 			timeout, "timeout");
5789 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5790 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5791 			value, "0#1.5#2#3#4#8#16#32");
5792 
5793 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5794 	.f = cmd_set_bypass_timeout_parsed,
5795 	.help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5796 		"Set the NIC bypass watchdog timeout in seconds",
5797 	.data = NULL,
5798 	.tokens = {
5799 		(void *)&cmd_setbypass_timeout_set,
5800 		(void *)&cmd_setbypass_timeout_bypass,
5801 		(void *)&cmd_setbypass_timeout_timeout,
5802 		(void *)&cmd_setbypass_timeout_value,
5803 		NULL,
5804 	},
5805 };
5806 
5807 /* *** SHOW NIC BYPASS MODE *** */
5808 struct cmd_show_bypass_config_result {
5809 	cmdline_fixed_string_t show;
5810 	cmdline_fixed_string_t bypass;
5811 	cmdline_fixed_string_t config;
5812 	portid_t port_id;
5813 };
5814 
5815 static void
5816 cmd_show_bypass_config_parsed(void *parsed_result,
5817 		__rte_unused struct cmdline *cl,
5818 		__rte_unused void *data)
5819 {
5820 	struct cmd_show_bypass_config_result *res = parsed_result;
5821 	portid_t port_id = res->port_id;
5822 	int rc = -EINVAL;
5823 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5824 	uint32_t event_mode;
5825 	uint32_t bypass_mode;
5826 	uint32_t timeout = bypass_timeout;
5827 	unsigned int i;
5828 
5829 	static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5830 		{"off", "1.5", "2", "3", "4", "8", "16", "32"};
5831 	static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5832 		{"UNKNOWN", "normal", "bypass", "isolate"};
5833 	static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5834 		"NONE",
5835 		"OS/board on",
5836 		"power supply on",
5837 		"OS/board off",
5838 		"power supply off",
5839 		"timeout"};
5840 
5841 	/* Display the bypass mode.*/
5842 	if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5843 		fprintf(stderr, "\tFailed to get bypass mode for port = %d\n",
5844 			port_id);
5845 		return;
5846 	}
5847 	else {
5848 		if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5849 			bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5850 
5851 		printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5852 	}
5853 
5854 	/* Display the bypass timeout.*/
5855 	if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5856 		timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5857 
5858 	printf("\tbypass timeout = %s\n", timeouts[timeout]);
5859 
5860 	/* Display the bypass events and associated modes. */
5861 	for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5862 
5863 		if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5864 			fprintf(stderr,
5865 				"\tFailed to get bypass mode for event = %s\n",
5866 				events[i]);
5867 		} else {
5868 			if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5869 				event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5870 
5871 			printf("\tbypass event: %-16s = %s\n", events[i],
5872 				modes[event_mode]);
5873 		}
5874 	}
5875 #endif
5876 	if (rc != 0)
5877 		fprintf(stderr,
5878 			"\tFailed to get bypass configuration for port = %d\n",
5879 		       port_id);
5880 }
5881 
5882 cmdline_parse_token_string_t cmd_showbypass_config_show =
5883 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5884 			show, "show");
5885 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5886 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5887 			bypass, "bypass");
5888 cmdline_parse_token_string_t cmd_showbypass_config_config =
5889 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5890 			config, "config");
5891 cmdline_parse_token_num_t cmd_showbypass_config_port =
5892 	TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5893 				port_id, RTE_UINT16);
5894 
5895 cmdline_parse_inst_t cmd_show_bypass_config = {
5896 	.f = cmd_show_bypass_config_parsed,
5897 	.help_str = "show bypass config <port_id>: "
5898 	            "Show the NIC bypass config for port_id",
5899 	.data = NULL,
5900 	.tokens = {
5901 		(void *)&cmd_showbypass_config_show,
5902 		(void *)&cmd_showbypass_config_bypass,
5903 		(void *)&cmd_showbypass_config_config,
5904 		(void *)&cmd_showbypass_config_port,
5905 		NULL,
5906 	},
5907 };
5908 
5909 #ifdef RTE_NET_BOND
5910 /* *** SET BONDING MODE *** */
5911 struct cmd_set_bonding_mode_result {
5912 	cmdline_fixed_string_t set;
5913 	cmdline_fixed_string_t bonding;
5914 	cmdline_fixed_string_t mode;
5915 	uint8_t value;
5916 	portid_t port_id;
5917 };
5918 
5919 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5920 		__rte_unused  struct cmdline *cl,
5921 		__rte_unused void *data)
5922 {
5923 	struct cmd_set_bonding_mode_result *res = parsed_result;
5924 	portid_t port_id = res->port_id;
5925 	struct rte_port *port = &ports[port_id];
5926 
5927 	/*
5928 	 * Bonding mode changed means resources of device changed, like whether
5929 	 * started rte timer or not. Device should be restarted when resources
5930 	 * of device changed.
5931 	 */
5932 	if (port->port_status != RTE_PORT_STOPPED) {
5933 		fprintf(stderr,
5934 			"\t Error: Can't set bonding mode when port %d is not stopped\n",
5935 			port_id);
5936 		return;
5937 	}
5938 
5939 	/* Set the bonding mode for the relevant port. */
5940 	if (0 != rte_eth_bond_mode_set(port_id, res->value))
5941 		fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
5942 			port_id);
5943 }
5944 
5945 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5946 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5947 		set, "set");
5948 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5949 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5950 		bonding, "bonding");
5951 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5952 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5953 		mode, "mode");
5954 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5955 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5956 		value, RTE_UINT8);
5957 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5958 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5959 		port_id, RTE_UINT16);
5960 
5961 cmdline_parse_inst_t cmd_set_bonding_mode = {
5962 		.f = cmd_set_bonding_mode_parsed,
5963 		.help_str = "set bonding mode <mode_value> <port_id>: "
5964 			"Set the bonding mode for port_id",
5965 		.data = NULL,
5966 		.tokens = {
5967 				(void *) &cmd_setbonding_mode_set,
5968 				(void *) &cmd_setbonding_mode_bonding,
5969 				(void *) &cmd_setbonding_mode_mode,
5970 				(void *) &cmd_setbonding_mode_value,
5971 				(void *) &cmd_setbonding_mode_port,
5972 				NULL
5973 		}
5974 };
5975 
5976 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5977 struct cmd_set_bonding_lacp_dedicated_queues_result {
5978 	cmdline_fixed_string_t set;
5979 	cmdline_fixed_string_t bonding;
5980 	cmdline_fixed_string_t lacp;
5981 	cmdline_fixed_string_t dedicated_queues;
5982 	portid_t port_id;
5983 	cmdline_fixed_string_t mode;
5984 };
5985 
5986 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5987 		__rte_unused  struct cmdline *cl,
5988 		__rte_unused void *data)
5989 {
5990 	struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5991 	portid_t port_id = res->port_id;
5992 	struct rte_port *port;
5993 
5994 	port = &ports[port_id];
5995 
5996 	/** Check if the port is not started **/
5997 	if (port->port_status != RTE_PORT_STOPPED) {
5998 		fprintf(stderr, "Please stop port %d first\n", port_id);
5999 		return;
6000 	}
6001 
6002 	if (!strcmp(res->mode, "enable")) {
6003 		if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
6004 			printf("Dedicate queues for LACP control packets"
6005 					" enabled\n");
6006 		else
6007 			printf("Enabling dedicate queues for LACP control "
6008 					"packets on port %d failed\n", port_id);
6009 	} else if (!strcmp(res->mode, "disable")) {
6010 		if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
6011 			printf("Dedicated queues for LACP control packets "
6012 					"disabled\n");
6013 		else
6014 			printf("Disabling dedicated queues for LACP control "
6015 					"traffic on port %d failed\n", port_id);
6016 	}
6017 }
6018 
6019 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
6020 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6021 		set, "set");
6022 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
6023 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6024 		bonding, "bonding");
6025 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
6026 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6027 		lacp, "lacp");
6028 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
6029 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6030 		dedicated_queues, "dedicated_queues");
6031 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6032 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6033 		port_id, RTE_UINT16);
6034 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6035 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6036 		mode, "enable#disable");
6037 
6038 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6039 		.f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6040 		.help_str = "set bonding lacp dedicated_queues <port_id> "
6041 			"enable|disable: "
6042 			"Enable/disable dedicated queues for LACP control traffic for port_id",
6043 		.data = NULL,
6044 		.tokens = {
6045 			(void *)&cmd_setbonding_lacp_dedicated_queues_set,
6046 			(void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6047 			(void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6048 			(void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6049 			(void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6050 			(void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6051 			NULL
6052 		}
6053 };
6054 
6055 /* *** SET BALANCE XMIT POLICY *** */
6056 struct cmd_set_bonding_balance_xmit_policy_result {
6057 	cmdline_fixed_string_t set;
6058 	cmdline_fixed_string_t bonding;
6059 	cmdline_fixed_string_t balance_xmit_policy;
6060 	portid_t port_id;
6061 	cmdline_fixed_string_t policy;
6062 };
6063 
6064 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6065 		__rte_unused  struct cmdline *cl,
6066 		__rte_unused void *data)
6067 {
6068 	struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6069 	portid_t port_id = res->port_id;
6070 	uint8_t policy;
6071 
6072 	if (!strcmp(res->policy, "l2")) {
6073 		policy = BALANCE_XMIT_POLICY_LAYER2;
6074 	} else if (!strcmp(res->policy, "l23")) {
6075 		policy = BALANCE_XMIT_POLICY_LAYER23;
6076 	} else if (!strcmp(res->policy, "l34")) {
6077 		policy = BALANCE_XMIT_POLICY_LAYER34;
6078 	} else {
6079 		fprintf(stderr, "\t Invalid xmit policy selection");
6080 		return;
6081 	}
6082 
6083 	/* Set the bonding mode for the relevant port. */
6084 	if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6085 		fprintf(stderr,
6086 			"\t Failed to set bonding balance xmit policy for port = %d.\n",
6087 			port_id);
6088 	}
6089 }
6090 
6091 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6092 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6093 		set, "set");
6094 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6095 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6096 		bonding, "bonding");
6097 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6098 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6099 		balance_xmit_policy, "balance_xmit_policy");
6100 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6101 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6102 		port_id, RTE_UINT16);
6103 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6104 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6105 		policy, "l2#l23#l34");
6106 
6107 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6108 		.f = cmd_set_bonding_balance_xmit_policy_parsed,
6109 		.help_str = "set bonding balance_xmit_policy <port_id> "
6110 			"l2|l23|l34: "
6111 			"Set the bonding balance_xmit_policy for port_id",
6112 		.data = NULL,
6113 		.tokens = {
6114 				(void *)&cmd_setbonding_balance_xmit_policy_set,
6115 				(void *)&cmd_setbonding_balance_xmit_policy_bonding,
6116 				(void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6117 				(void *)&cmd_setbonding_balance_xmit_policy_port,
6118 				(void *)&cmd_setbonding_balance_xmit_policy_policy,
6119 				NULL
6120 		}
6121 };
6122 
6123 /* *** SHOW IEEE802.3 BONDING INFORMATION *** */
6124 struct cmd_show_bonding_lacp_info_result {
6125 	cmdline_fixed_string_t show;
6126 	cmdline_fixed_string_t bonding;
6127 	cmdline_fixed_string_t lacp;
6128 	cmdline_fixed_string_t info;
6129 	portid_t port_id;
6130 };
6131 
6132 static void port_param_show(struct port_params *params)
6133 {
6134 	char buf[RTE_ETHER_ADDR_FMT_SIZE];
6135 
6136 	printf("\t\tsystem priority: %u\n", params->system_priority);
6137 	rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &params->system);
6138 	printf("\t\tsystem mac address: %s\n", buf);
6139 	printf("\t\tport key: %u\n", params->key);
6140 	printf("\t\tport priority: %u\n", params->port_priority);
6141 	printf("\t\tport number: %u\n", params->port_number);
6142 }
6143 
6144 static void lacp_slave_info_show(struct rte_eth_bond_8023ad_slave_info *info)
6145 {
6146 	char a_state[256] = { 0 };
6147 	char p_state[256] = { 0 };
6148 	int a_len = 0;
6149 	int p_len = 0;
6150 	uint32_t i;
6151 
6152 	static const char * const state[] = {
6153 		"ACTIVE",
6154 		"TIMEOUT",
6155 		"AGGREGATION",
6156 		"SYNCHRONIZATION",
6157 		"COLLECTING",
6158 		"DISTRIBUTING",
6159 		"DEFAULTED",
6160 		"EXPIRED"
6161 	};
6162 	static const char * const selection[] = {
6163 		"UNSELECTED",
6164 		"STANDBY",
6165 		"SELECTED"
6166 	};
6167 
6168 	for (i = 0; i < RTE_DIM(state); i++) {
6169 		if ((info->actor_state >> i) & 1)
6170 			a_len += snprintf(&a_state[a_len],
6171 						RTE_DIM(a_state) - a_len, "%s ",
6172 						state[i]);
6173 
6174 		if ((info->partner_state >> i) & 1)
6175 			p_len += snprintf(&p_state[p_len],
6176 						RTE_DIM(p_state) - p_len, "%s ",
6177 						state[i]);
6178 	}
6179 	printf("\tAggregator port id: %u\n", info->agg_port_id);
6180 	printf("\tselection: %s\n", selection[info->selected]);
6181 	printf("\tActor detail info:\n");
6182 	port_param_show(&info->actor);
6183 	printf("\t\tport state: %s\n", a_state);
6184 	printf("\tPartner detail info:\n");
6185 	port_param_show(&info->partner);
6186 	printf("\t\tport state: %s\n", p_state);
6187 	printf("\n");
6188 }
6189 
6190 static void lacp_conf_show(struct rte_eth_bond_8023ad_conf *conf)
6191 {
6192 	printf("\tfast period: %u ms\n", conf->fast_periodic_ms);
6193 	printf("\tslow period: %u ms\n", conf->slow_periodic_ms);
6194 	printf("\tshort timeout: %u ms\n", conf->short_timeout_ms);
6195 	printf("\tlong timeout: %u ms\n", conf->long_timeout_ms);
6196 	printf("\taggregate wait timeout: %u ms\n",
6197 			conf->aggregate_wait_timeout_ms);
6198 	printf("\ttx period: %u ms\n", conf->tx_period_ms);
6199 	printf("\trx marker period: %u ms\n", conf->rx_marker_period_ms);
6200 	printf("\tupdate timeout: %u ms\n", conf->update_timeout_ms);
6201 	switch (conf->agg_selection) {
6202 	case AGG_BANDWIDTH:
6203 		printf("\taggregation mode: bandwidth\n");
6204 		break;
6205 	case AGG_STABLE:
6206 		printf("\taggregation mode: stable\n");
6207 		break;
6208 	case AGG_COUNT:
6209 		printf("\taggregation mode: count\n");
6210 		break;
6211 	default:
6212 		printf("\taggregation mode: invalid\n");
6213 		break;
6214 	}
6215 
6216 	printf("\n");
6217 }
6218 
6219 static void cmd_show_bonding_lacp_info_parsed(void *parsed_result,
6220 		__rte_unused  struct cmdline *cl,
6221 		__rte_unused void *data)
6222 {
6223 	struct cmd_show_bonding_lacp_info_result *res = parsed_result;
6224 	struct rte_eth_bond_8023ad_slave_info slave_info;
6225 	struct rte_eth_bond_8023ad_conf port_conf;
6226 	portid_t slaves[RTE_MAX_ETHPORTS];
6227 	portid_t port_id = res->port_id;
6228 	int num_active_slaves;
6229 	int bonding_mode;
6230 	int i;
6231 	int ret;
6232 
6233 	bonding_mode = rte_eth_bond_mode_get(port_id);
6234 	if (bonding_mode != BONDING_MODE_8023AD) {
6235 		fprintf(stderr, "\tBonding mode is not mode 4\n");
6236 		return;
6237 	}
6238 
6239 	num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6240 			RTE_MAX_ETHPORTS);
6241 	if (num_active_slaves < 0) {
6242 		fprintf(stderr, "\tFailed to get active slave list for port = %u\n",
6243 				port_id);
6244 		return;
6245 	}
6246 	if (num_active_slaves == 0)
6247 		fprintf(stderr, "\tIEEE802.3 port %u has no active slave\n",
6248 			port_id);
6249 
6250 	printf("\tIEEE802.3 port: %u\n", port_id);
6251 	ret = rte_eth_bond_8023ad_conf_get(port_id, &port_conf);
6252 	if (ret) {
6253 		fprintf(stderr, "\tGet bonded device %u info failed\n",
6254 			port_id);
6255 		return;
6256 	}
6257 	lacp_conf_show(&port_conf);
6258 
6259 	for (i = 0; i < num_active_slaves; i++) {
6260 		ret = rte_eth_bond_8023ad_slave_info(port_id, slaves[i],
6261 				&slave_info);
6262 		if (ret) {
6263 			fprintf(stderr, "\tGet slave device %u info failed\n",
6264 				slaves[i]);
6265 			return;
6266 		}
6267 		printf("\tSlave Port: %u\n", slaves[i]);
6268 		lacp_slave_info_show(&slave_info);
6269 	}
6270 }
6271 
6272 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_show =
6273 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6274 		show, "show");
6275 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_bonding =
6276 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6277 		bonding, "bonding");
6278 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_lacp =
6279 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6280 		bonding, "lacp");
6281 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_info =
6282 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6283 		info, "info");
6284 cmdline_parse_token_num_t cmd_show_bonding_lacp_info_port_id =
6285 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6286 		port_id, RTE_UINT16);
6287 
6288 cmdline_parse_inst_t cmd_show_bonding_lacp_info = {
6289 		.f = cmd_show_bonding_lacp_info_parsed,
6290 		.help_str = "show bonding lacp info <port_id> : "
6291 			"Show bonding IEEE802.3 information for port_id",
6292 		.data = NULL,
6293 		.tokens = {
6294 			(void *)&cmd_show_bonding_lacp_info_show,
6295 			(void *)&cmd_show_bonding_lacp_info_bonding,
6296 			(void *)&cmd_show_bonding_lacp_info_lacp,
6297 			(void *)&cmd_show_bonding_lacp_info_info,
6298 			(void *)&cmd_show_bonding_lacp_info_port_id,
6299 			NULL
6300 		}
6301 };
6302 
6303 /* *** SHOW NIC BONDING CONFIGURATION *** */
6304 struct cmd_show_bonding_config_result {
6305 	cmdline_fixed_string_t show;
6306 	cmdline_fixed_string_t bonding;
6307 	cmdline_fixed_string_t config;
6308 	portid_t port_id;
6309 };
6310 
6311 static void cmd_show_bonding_config_parsed(void *parsed_result,
6312 		__rte_unused  struct cmdline *cl,
6313 		__rte_unused void *data)
6314 {
6315 	struct cmd_show_bonding_config_result *res = parsed_result;
6316 	int bonding_mode, agg_mode;
6317 	portid_t slaves[RTE_MAX_ETHPORTS];
6318 	int num_slaves, num_active_slaves;
6319 	int primary_id;
6320 	int i;
6321 	portid_t port_id = res->port_id;
6322 
6323 	/* Display the bonding mode.*/
6324 	bonding_mode = rte_eth_bond_mode_get(port_id);
6325 	if (bonding_mode < 0) {
6326 		fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
6327 			port_id);
6328 		return;
6329 	} else
6330 		printf("\tBonding mode: %d\n", bonding_mode);
6331 
6332 	if (bonding_mode == BONDING_MODE_BALANCE ||
6333 		bonding_mode == BONDING_MODE_8023AD) {
6334 		int balance_xmit_policy;
6335 
6336 		balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6337 		if (balance_xmit_policy < 0) {
6338 			fprintf(stderr,
6339 				"\tFailed to get balance xmit policy for port = %d\n",
6340 				port_id);
6341 			return;
6342 		} else {
6343 			printf("\tBalance Xmit Policy: ");
6344 
6345 			switch (balance_xmit_policy) {
6346 			case BALANCE_XMIT_POLICY_LAYER2:
6347 				printf("BALANCE_XMIT_POLICY_LAYER2");
6348 				break;
6349 			case BALANCE_XMIT_POLICY_LAYER23:
6350 				printf("BALANCE_XMIT_POLICY_LAYER23");
6351 				break;
6352 			case BALANCE_XMIT_POLICY_LAYER34:
6353 				printf("BALANCE_XMIT_POLICY_LAYER34");
6354 				break;
6355 			}
6356 			printf("\n");
6357 		}
6358 	}
6359 
6360 	if (bonding_mode == BONDING_MODE_8023AD) {
6361 		agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6362 		printf("\tIEEE802.3AD Aggregator Mode: ");
6363 		switch (agg_mode) {
6364 		case AGG_BANDWIDTH:
6365 			printf("bandwidth");
6366 			break;
6367 		case AGG_STABLE:
6368 			printf("stable");
6369 			break;
6370 		case AGG_COUNT:
6371 			printf("count");
6372 			break;
6373 		}
6374 		printf("\n");
6375 	}
6376 
6377 	num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6378 
6379 	if (num_slaves < 0) {
6380 		fprintf(stderr, "\tFailed to get slave list for port = %d\n",
6381 			port_id);
6382 		return;
6383 	}
6384 	if (num_slaves > 0) {
6385 		printf("\tSlaves (%d): [", num_slaves);
6386 		for (i = 0; i < num_slaves - 1; i++)
6387 			printf("%d ", slaves[i]);
6388 
6389 		printf("%d]\n", slaves[num_slaves - 1]);
6390 	} else {
6391 		printf("\tSlaves: []\n");
6392 
6393 	}
6394 
6395 	num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6396 			RTE_MAX_ETHPORTS);
6397 
6398 	if (num_active_slaves < 0) {
6399 		fprintf(stderr,
6400 			"\tFailed to get active slave list for port = %d\n",
6401 			port_id);
6402 		return;
6403 	}
6404 	if (num_active_slaves > 0) {
6405 		printf("\tActive Slaves (%d): [", num_active_slaves);
6406 		for (i = 0; i < num_active_slaves - 1; i++)
6407 			printf("%d ", slaves[i]);
6408 
6409 		printf("%d]\n", slaves[num_active_slaves - 1]);
6410 
6411 	} else {
6412 		printf("\tActive Slaves: []\n");
6413 
6414 	}
6415 
6416 	primary_id = rte_eth_bond_primary_get(port_id);
6417 	if (primary_id < 0) {
6418 		fprintf(stderr, "\tFailed to get primary slave for port = %d\n",
6419 			port_id);
6420 		return;
6421 	} else
6422 		printf("\tPrimary: [%d]\n", primary_id);
6423 
6424 }
6425 
6426 cmdline_parse_token_string_t cmd_showbonding_config_show =
6427 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6428 		show, "show");
6429 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6430 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6431 		bonding, "bonding");
6432 cmdline_parse_token_string_t cmd_showbonding_config_config =
6433 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6434 		config, "config");
6435 cmdline_parse_token_num_t cmd_showbonding_config_port =
6436 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6437 		port_id, RTE_UINT16);
6438 
6439 cmdline_parse_inst_t cmd_show_bonding_config = {
6440 		.f = cmd_show_bonding_config_parsed,
6441 		.help_str = "show bonding config <port_id>: "
6442 			"Show the bonding config for port_id",
6443 		.data = NULL,
6444 		.tokens = {
6445 				(void *)&cmd_showbonding_config_show,
6446 				(void *)&cmd_showbonding_config_bonding,
6447 				(void *)&cmd_showbonding_config_config,
6448 				(void *)&cmd_showbonding_config_port,
6449 				NULL
6450 		}
6451 };
6452 
6453 /* *** SET BONDING PRIMARY *** */
6454 struct cmd_set_bonding_primary_result {
6455 	cmdline_fixed_string_t set;
6456 	cmdline_fixed_string_t bonding;
6457 	cmdline_fixed_string_t primary;
6458 	portid_t slave_id;
6459 	portid_t port_id;
6460 };
6461 
6462 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6463 		__rte_unused  struct cmdline *cl,
6464 		__rte_unused void *data)
6465 {
6466 	struct cmd_set_bonding_primary_result *res = parsed_result;
6467 	portid_t master_port_id = res->port_id;
6468 	portid_t slave_port_id = res->slave_id;
6469 
6470 	/* Set the primary slave for a bonded device. */
6471 	if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6472 		fprintf(stderr, "\t Failed to set primary slave for port = %d.\n",
6473 			master_port_id);
6474 		return;
6475 	}
6476 	init_port_config();
6477 }
6478 
6479 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6480 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6481 		set, "set");
6482 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6483 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6484 		bonding, "bonding");
6485 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6486 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6487 		primary, "primary");
6488 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6489 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6490 		slave_id, RTE_UINT16);
6491 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6492 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6493 		port_id, RTE_UINT16);
6494 
6495 cmdline_parse_inst_t cmd_set_bonding_primary = {
6496 		.f = cmd_set_bonding_primary_parsed,
6497 		.help_str = "set bonding primary <slave_id> <port_id>: "
6498 			"Set the primary slave for port_id",
6499 		.data = NULL,
6500 		.tokens = {
6501 				(void *)&cmd_setbonding_primary_set,
6502 				(void *)&cmd_setbonding_primary_bonding,
6503 				(void *)&cmd_setbonding_primary_primary,
6504 				(void *)&cmd_setbonding_primary_slave,
6505 				(void *)&cmd_setbonding_primary_port,
6506 				NULL
6507 		}
6508 };
6509 
6510 /* *** ADD SLAVE *** */
6511 struct cmd_add_bonding_slave_result {
6512 	cmdline_fixed_string_t add;
6513 	cmdline_fixed_string_t bonding;
6514 	cmdline_fixed_string_t slave;
6515 	portid_t slave_id;
6516 	portid_t port_id;
6517 };
6518 
6519 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6520 		__rte_unused  struct cmdline *cl,
6521 		__rte_unused void *data)
6522 {
6523 	struct cmd_add_bonding_slave_result *res = parsed_result;
6524 	portid_t master_port_id = res->port_id;
6525 	portid_t slave_port_id = res->slave_id;
6526 
6527 	/* add the slave for a bonded device. */
6528 	if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6529 		fprintf(stderr,
6530 			"\t Failed to add slave %d to master port = %d.\n",
6531 			slave_port_id, master_port_id);
6532 		return;
6533 	}
6534 	init_port_config();
6535 	set_port_slave_flag(slave_port_id);
6536 }
6537 
6538 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6539 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6540 		add, "add");
6541 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6542 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6543 		bonding, "bonding");
6544 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6545 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6546 		slave, "slave");
6547 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6548 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6549 		slave_id, RTE_UINT16);
6550 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6551 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6552 		port_id, RTE_UINT16);
6553 
6554 cmdline_parse_inst_t cmd_add_bonding_slave = {
6555 		.f = cmd_add_bonding_slave_parsed,
6556 		.help_str = "add bonding slave <slave_id> <port_id>: "
6557 			"Add a slave device to a bonded device",
6558 		.data = NULL,
6559 		.tokens = {
6560 				(void *)&cmd_addbonding_slave_add,
6561 				(void *)&cmd_addbonding_slave_bonding,
6562 				(void *)&cmd_addbonding_slave_slave,
6563 				(void *)&cmd_addbonding_slave_slaveid,
6564 				(void *)&cmd_addbonding_slave_port,
6565 				NULL
6566 		}
6567 };
6568 
6569 /* *** REMOVE SLAVE *** */
6570 struct cmd_remove_bonding_slave_result {
6571 	cmdline_fixed_string_t remove;
6572 	cmdline_fixed_string_t bonding;
6573 	cmdline_fixed_string_t slave;
6574 	portid_t slave_id;
6575 	portid_t port_id;
6576 };
6577 
6578 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6579 		__rte_unused  struct cmdline *cl,
6580 		__rte_unused void *data)
6581 {
6582 	struct cmd_remove_bonding_slave_result *res = parsed_result;
6583 	portid_t master_port_id = res->port_id;
6584 	portid_t slave_port_id = res->slave_id;
6585 
6586 	/* remove the slave from a bonded device. */
6587 	if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6588 		fprintf(stderr,
6589 			"\t Failed to remove slave %d from master port = %d.\n",
6590 			slave_port_id, master_port_id);
6591 		return;
6592 	}
6593 	init_port_config();
6594 	clear_port_slave_flag(slave_port_id);
6595 }
6596 
6597 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6598 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6599 				remove, "remove");
6600 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6601 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6602 				bonding, "bonding");
6603 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6604 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6605 				slave, "slave");
6606 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6607 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6608 				slave_id, RTE_UINT16);
6609 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6610 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6611 				port_id, RTE_UINT16);
6612 
6613 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6614 		.f = cmd_remove_bonding_slave_parsed,
6615 		.help_str = "remove bonding slave <slave_id> <port_id>: "
6616 			"Remove a slave device from a bonded device",
6617 		.data = NULL,
6618 		.tokens = {
6619 				(void *)&cmd_removebonding_slave_remove,
6620 				(void *)&cmd_removebonding_slave_bonding,
6621 				(void *)&cmd_removebonding_slave_slave,
6622 				(void *)&cmd_removebonding_slave_slaveid,
6623 				(void *)&cmd_removebonding_slave_port,
6624 				NULL
6625 		}
6626 };
6627 
6628 /* *** CREATE BONDED DEVICE *** */
6629 struct cmd_create_bonded_device_result {
6630 	cmdline_fixed_string_t create;
6631 	cmdline_fixed_string_t bonded;
6632 	cmdline_fixed_string_t device;
6633 	uint8_t mode;
6634 	uint8_t socket;
6635 };
6636 
6637 static int bond_dev_num = 0;
6638 
6639 static void cmd_create_bonded_device_parsed(void *parsed_result,
6640 		__rte_unused  struct cmdline *cl,
6641 		__rte_unused void *data)
6642 {
6643 	struct cmd_create_bonded_device_result *res = parsed_result;
6644 	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6645 	int port_id;
6646 	int ret;
6647 
6648 	if (test_done == 0) {
6649 		fprintf(stderr, "Please stop forwarding first\n");
6650 		return;
6651 	}
6652 
6653 	snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6654 			bond_dev_num++);
6655 
6656 	/* Create a new bonded device. */
6657 	port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6658 	if (port_id < 0) {
6659 		fprintf(stderr, "\t Failed to create bonded device.\n");
6660 		return;
6661 	} else {
6662 		printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6663 				port_id);
6664 
6665 		/* Update number of ports */
6666 		nb_ports = rte_eth_dev_count_avail();
6667 		reconfig(port_id, res->socket);
6668 		ret = rte_eth_promiscuous_enable(port_id);
6669 		if (ret != 0)
6670 			fprintf(stderr,
6671 				"Failed to enable promiscuous mode for port %u: %s - ignore\n",
6672 				port_id, rte_strerror(-ret));
6673 
6674 		ports[port_id].need_setup = 0;
6675 		ports[port_id].port_status = RTE_PORT_STOPPED;
6676 	}
6677 
6678 }
6679 
6680 cmdline_parse_token_string_t cmd_createbonded_device_create =
6681 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6682 				create, "create");
6683 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6684 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6685 				bonded, "bonded");
6686 cmdline_parse_token_string_t cmd_createbonded_device_device =
6687 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6688 				device, "device");
6689 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6690 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6691 				mode, RTE_UINT8);
6692 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6693 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6694 				socket, RTE_UINT8);
6695 
6696 cmdline_parse_inst_t cmd_create_bonded_device = {
6697 		.f = cmd_create_bonded_device_parsed,
6698 		.help_str = "create bonded device <mode> <socket>: "
6699 			"Create a new bonded device with specific bonding mode and socket",
6700 		.data = NULL,
6701 		.tokens = {
6702 				(void *)&cmd_createbonded_device_create,
6703 				(void *)&cmd_createbonded_device_bonded,
6704 				(void *)&cmd_createbonded_device_device,
6705 				(void *)&cmd_createbonded_device_mode,
6706 				(void *)&cmd_createbonded_device_socket,
6707 				NULL
6708 		}
6709 };
6710 
6711 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6712 struct cmd_set_bond_mac_addr_result {
6713 	cmdline_fixed_string_t set;
6714 	cmdline_fixed_string_t bonding;
6715 	cmdline_fixed_string_t mac_addr;
6716 	uint16_t port_num;
6717 	struct rte_ether_addr address;
6718 };
6719 
6720 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6721 		__rte_unused  struct cmdline *cl,
6722 		__rte_unused void *data)
6723 {
6724 	struct cmd_set_bond_mac_addr_result *res = parsed_result;
6725 	int ret;
6726 
6727 	if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6728 		return;
6729 
6730 	ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6731 
6732 	/* check the return value and print it if is < 0 */
6733 	if (ret < 0)
6734 		fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6735 			strerror(-ret));
6736 }
6737 
6738 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6739 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6740 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6741 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6742 				"bonding");
6743 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6744 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6745 				"mac_addr");
6746 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6747 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6748 				port_num, RTE_UINT16);
6749 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6750 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6751 
6752 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6753 		.f = cmd_set_bond_mac_addr_parsed,
6754 		.data = (void *) 0,
6755 		.help_str = "set bonding mac_addr <port_id> <mac_addr>",
6756 		.tokens = {
6757 				(void *)&cmd_set_bond_mac_addr_set,
6758 				(void *)&cmd_set_bond_mac_addr_bonding,
6759 				(void *)&cmd_set_bond_mac_addr_mac,
6760 				(void *)&cmd_set_bond_mac_addr_portnum,
6761 				(void *)&cmd_set_bond_mac_addr_addr,
6762 				NULL
6763 		}
6764 };
6765 
6766 
6767 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6768 struct cmd_set_bond_mon_period_result {
6769 	cmdline_fixed_string_t set;
6770 	cmdline_fixed_string_t bonding;
6771 	cmdline_fixed_string_t mon_period;
6772 	uint16_t port_num;
6773 	uint32_t period_ms;
6774 };
6775 
6776 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6777 		__rte_unused  struct cmdline *cl,
6778 		__rte_unused void *data)
6779 {
6780 	struct cmd_set_bond_mon_period_result *res = parsed_result;
6781 	int ret;
6782 
6783 	ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6784 
6785 	/* check the return value and print it if is < 0 */
6786 	if (ret < 0)
6787 		fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6788 			strerror(-ret));
6789 }
6790 
6791 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6792 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6793 				set, "set");
6794 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6795 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6796 				bonding, "bonding");
6797 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6798 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6799 				mon_period,	"mon_period");
6800 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6801 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6802 				port_num, RTE_UINT16);
6803 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6804 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6805 				period_ms, RTE_UINT32);
6806 
6807 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6808 		.f = cmd_set_bond_mon_period_parsed,
6809 		.data = (void *) 0,
6810 		.help_str = "set bonding mon_period <port_id> <period_ms>",
6811 		.tokens = {
6812 				(void *)&cmd_set_bond_mon_period_set,
6813 				(void *)&cmd_set_bond_mon_period_bonding,
6814 				(void *)&cmd_set_bond_mon_period_mon_period,
6815 				(void *)&cmd_set_bond_mon_period_portnum,
6816 				(void *)&cmd_set_bond_mon_period_period_ms,
6817 				NULL
6818 		}
6819 };
6820 
6821 
6822 
6823 struct cmd_set_bonding_agg_mode_policy_result {
6824 	cmdline_fixed_string_t set;
6825 	cmdline_fixed_string_t bonding;
6826 	cmdline_fixed_string_t agg_mode;
6827 	uint16_t port_num;
6828 	cmdline_fixed_string_t policy;
6829 };
6830 
6831 
6832 static void
6833 cmd_set_bonding_agg_mode(void *parsed_result,
6834 		__rte_unused struct cmdline *cl,
6835 		__rte_unused void *data)
6836 {
6837 	struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6838 	uint8_t policy = AGG_BANDWIDTH;
6839 
6840 	if (!strcmp(res->policy, "bandwidth"))
6841 		policy = AGG_BANDWIDTH;
6842 	else if (!strcmp(res->policy, "stable"))
6843 		policy = AGG_STABLE;
6844 	else if (!strcmp(res->policy, "count"))
6845 		policy = AGG_COUNT;
6846 
6847 	rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6848 }
6849 
6850 
6851 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6852 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6853 				set, "set");
6854 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6855 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6856 				bonding, "bonding");
6857 
6858 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6859 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6860 				agg_mode, "agg_mode");
6861 
6862 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6863 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6864 				port_num, RTE_UINT16);
6865 
6866 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6867 	TOKEN_STRING_INITIALIZER(
6868 			struct cmd_set_bonding_balance_xmit_policy_result,
6869 		policy, "stable#bandwidth#count");
6870 
6871 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6872 	.f = cmd_set_bonding_agg_mode,
6873 	.data = (void *) 0,
6874 	.help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6875 	.tokens = {
6876 			(void *)&cmd_set_bonding_agg_mode_set,
6877 			(void *)&cmd_set_bonding_agg_mode_bonding,
6878 			(void *)&cmd_set_bonding_agg_mode_agg_mode,
6879 			(void *)&cmd_set_bonding_agg_mode_portnum,
6880 			(void *)&cmd_set_bonding_agg_mode_policy_string,
6881 			NULL
6882 		}
6883 };
6884 
6885 
6886 #endif /* RTE_NET_BOND */
6887 
6888 /* *** SET FORWARDING MODE *** */
6889 struct cmd_set_fwd_mode_result {
6890 	cmdline_fixed_string_t set;
6891 	cmdline_fixed_string_t fwd;
6892 	cmdline_fixed_string_t mode;
6893 };
6894 
6895 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6896 				    __rte_unused struct cmdline *cl,
6897 				    __rte_unused void *data)
6898 {
6899 	struct cmd_set_fwd_mode_result *res = parsed_result;
6900 
6901 	retry_enabled = 0;
6902 	set_pkt_forwarding_mode(res->mode);
6903 }
6904 
6905 cmdline_parse_token_string_t cmd_setfwd_set =
6906 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6907 cmdline_parse_token_string_t cmd_setfwd_fwd =
6908 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6909 cmdline_parse_token_string_t cmd_setfwd_mode =
6910 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6911 		"" /* defined at init */);
6912 
6913 cmdline_parse_inst_t cmd_set_fwd_mode = {
6914 	.f = cmd_set_fwd_mode_parsed,
6915 	.data = NULL,
6916 	.help_str = NULL, /* defined at init */
6917 	.tokens = {
6918 		(void *)&cmd_setfwd_set,
6919 		(void *)&cmd_setfwd_fwd,
6920 		(void *)&cmd_setfwd_mode,
6921 		NULL,
6922 	},
6923 };
6924 
6925 static void cmd_set_fwd_mode_init(void)
6926 {
6927 	char *modes, *c;
6928 	static char token[128];
6929 	static char help[256];
6930 	cmdline_parse_token_string_t *token_struct;
6931 
6932 	modes = list_pkt_forwarding_modes();
6933 	snprintf(help, sizeof(help), "set fwd %s: "
6934 		"Set packet forwarding mode", modes);
6935 	cmd_set_fwd_mode.help_str = help;
6936 
6937 	/* string token separator is # */
6938 	for (c = token; *modes != '\0'; modes++)
6939 		if (*modes == '|')
6940 			*c++ = '#';
6941 		else
6942 			*c++ = *modes;
6943 	token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6944 	token_struct->string_data.str = token;
6945 }
6946 
6947 /* *** SET RETRY FORWARDING MODE *** */
6948 struct cmd_set_fwd_retry_mode_result {
6949 	cmdline_fixed_string_t set;
6950 	cmdline_fixed_string_t fwd;
6951 	cmdline_fixed_string_t mode;
6952 	cmdline_fixed_string_t retry;
6953 };
6954 
6955 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6956 			    __rte_unused struct cmdline *cl,
6957 			    __rte_unused void *data)
6958 {
6959 	struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6960 
6961 	retry_enabled = 1;
6962 	set_pkt_forwarding_mode(res->mode);
6963 }
6964 
6965 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6966 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6967 			set, "set");
6968 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6969 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6970 			fwd, "fwd");
6971 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6972 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6973 			mode,
6974 		"" /* defined at init */);
6975 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6976 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6977 			retry, "retry");
6978 
6979 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6980 	.f = cmd_set_fwd_retry_mode_parsed,
6981 	.data = NULL,
6982 	.help_str = NULL, /* defined at init */
6983 	.tokens = {
6984 		(void *)&cmd_setfwd_retry_set,
6985 		(void *)&cmd_setfwd_retry_fwd,
6986 		(void *)&cmd_setfwd_retry_mode,
6987 		(void *)&cmd_setfwd_retry_retry,
6988 		NULL,
6989 	},
6990 };
6991 
6992 static void cmd_set_fwd_retry_mode_init(void)
6993 {
6994 	char *modes, *c;
6995 	static char token[128];
6996 	static char help[256];
6997 	cmdline_parse_token_string_t *token_struct;
6998 
6999 	modes = list_pkt_forwarding_retry_modes();
7000 	snprintf(help, sizeof(help), "set fwd %s retry: "
7001 		"Set packet forwarding mode with retry", modes);
7002 	cmd_set_fwd_retry_mode.help_str = help;
7003 
7004 	/* string token separator is # */
7005 	for (c = token; *modes != '\0'; modes++)
7006 		if (*modes == '|')
7007 			*c++ = '#';
7008 		else
7009 			*c++ = *modes;
7010 	token_struct = (cmdline_parse_token_string_t *)
7011 		cmd_set_fwd_retry_mode.tokens[2];
7012 	token_struct->string_data.str = token;
7013 }
7014 
7015 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
7016 struct cmd_set_burst_tx_retry_result {
7017 	cmdline_fixed_string_t set;
7018 	cmdline_fixed_string_t burst;
7019 	cmdline_fixed_string_t tx;
7020 	cmdline_fixed_string_t delay;
7021 	uint32_t time;
7022 	cmdline_fixed_string_t retry;
7023 	uint32_t retry_num;
7024 };
7025 
7026 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
7027 					__rte_unused struct cmdline *cl,
7028 					__rte_unused void *data)
7029 {
7030 	struct cmd_set_burst_tx_retry_result *res = parsed_result;
7031 
7032 	if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
7033 		&& !strcmp(res->tx, "tx")) {
7034 		if (!strcmp(res->delay, "delay"))
7035 			burst_tx_delay_time = res->time;
7036 		if (!strcmp(res->retry, "retry"))
7037 			burst_tx_retry_num = res->retry_num;
7038 	}
7039 
7040 }
7041 
7042 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
7043 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
7044 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
7045 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
7046 				 "burst");
7047 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
7048 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
7049 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
7050 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
7051 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
7052 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
7053 				 RTE_UINT32);
7054 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
7055 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
7056 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
7057 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
7058 				 RTE_UINT32);
7059 
7060 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
7061 	.f = cmd_set_burst_tx_retry_parsed,
7062 	.help_str = "set burst tx delay <delay_usec> retry <num_retry>",
7063 	.tokens = {
7064 		(void *)&cmd_set_burst_tx_retry_set,
7065 		(void *)&cmd_set_burst_tx_retry_burst,
7066 		(void *)&cmd_set_burst_tx_retry_tx,
7067 		(void *)&cmd_set_burst_tx_retry_delay,
7068 		(void *)&cmd_set_burst_tx_retry_time,
7069 		(void *)&cmd_set_burst_tx_retry_retry,
7070 		(void *)&cmd_set_burst_tx_retry_retry_num,
7071 		NULL,
7072 	},
7073 };
7074 
7075 /* *** SET PROMISC MODE *** */
7076 struct cmd_set_promisc_mode_result {
7077 	cmdline_fixed_string_t set;
7078 	cmdline_fixed_string_t promisc;
7079 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7080 	uint16_t port_num;               /* valid if "allports" argument == 0 */
7081 	cmdline_fixed_string_t mode;
7082 };
7083 
7084 static void cmd_set_promisc_mode_parsed(void *parsed_result,
7085 					__rte_unused struct cmdline *cl,
7086 					void *allports)
7087 {
7088 	struct cmd_set_promisc_mode_result *res = parsed_result;
7089 	int enable;
7090 	portid_t i;
7091 
7092 	if (!strcmp(res->mode, "on"))
7093 		enable = 1;
7094 	else
7095 		enable = 0;
7096 
7097 	/* all ports */
7098 	if (allports) {
7099 		RTE_ETH_FOREACH_DEV(i)
7100 			eth_set_promisc_mode(i, enable);
7101 	} else {
7102 		eth_set_promisc_mode(res->port_num, enable);
7103 	}
7104 }
7105 
7106 cmdline_parse_token_string_t cmd_setpromisc_set =
7107 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
7108 cmdline_parse_token_string_t cmd_setpromisc_promisc =
7109 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
7110 				 "promisc");
7111 cmdline_parse_token_string_t cmd_setpromisc_portall =
7112 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
7113 				 "all");
7114 cmdline_parse_token_num_t cmd_setpromisc_portnum =
7115 	TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
7116 			      RTE_UINT16);
7117 cmdline_parse_token_string_t cmd_setpromisc_mode =
7118 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
7119 				 "on#off");
7120 
7121 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
7122 	.f = cmd_set_promisc_mode_parsed,
7123 	.data = (void *)1,
7124 	.help_str = "set promisc all on|off: Set promisc mode for all ports",
7125 	.tokens = {
7126 		(void *)&cmd_setpromisc_set,
7127 		(void *)&cmd_setpromisc_promisc,
7128 		(void *)&cmd_setpromisc_portall,
7129 		(void *)&cmd_setpromisc_mode,
7130 		NULL,
7131 	},
7132 };
7133 
7134 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
7135 	.f = cmd_set_promisc_mode_parsed,
7136 	.data = (void *)0,
7137 	.help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
7138 	.tokens = {
7139 		(void *)&cmd_setpromisc_set,
7140 		(void *)&cmd_setpromisc_promisc,
7141 		(void *)&cmd_setpromisc_portnum,
7142 		(void *)&cmd_setpromisc_mode,
7143 		NULL,
7144 	},
7145 };
7146 
7147 /* *** SET ALLMULTI MODE *** */
7148 struct cmd_set_allmulti_mode_result {
7149 	cmdline_fixed_string_t set;
7150 	cmdline_fixed_string_t allmulti;
7151 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7152 	uint16_t port_num;               /* valid if "allports" argument == 0 */
7153 	cmdline_fixed_string_t mode;
7154 };
7155 
7156 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
7157 					__rte_unused struct cmdline *cl,
7158 					void *allports)
7159 {
7160 	struct cmd_set_allmulti_mode_result *res = parsed_result;
7161 	int enable;
7162 	portid_t i;
7163 
7164 	if (!strcmp(res->mode, "on"))
7165 		enable = 1;
7166 	else
7167 		enable = 0;
7168 
7169 	/* all ports */
7170 	if (allports) {
7171 		RTE_ETH_FOREACH_DEV(i) {
7172 			eth_set_allmulticast_mode(i, enable);
7173 		}
7174 	}
7175 	else {
7176 		eth_set_allmulticast_mode(res->port_num, enable);
7177 	}
7178 }
7179 
7180 cmdline_parse_token_string_t cmd_setallmulti_set =
7181 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
7182 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
7183 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
7184 				 "allmulti");
7185 cmdline_parse_token_string_t cmd_setallmulti_portall =
7186 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
7187 				 "all");
7188 cmdline_parse_token_num_t cmd_setallmulti_portnum =
7189 	TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
7190 			      RTE_UINT16);
7191 cmdline_parse_token_string_t cmd_setallmulti_mode =
7192 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
7193 				 "on#off");
7194 
7195 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
7196 	.f = cmd_set_allmulti_mode_parsed,
7197 	.data = (void *)1,
7198 	.help_str = "set allmulti all on|off: Set allmulti mode for all ports",
7199 	.tokens = {
7200 		(void *)&cmd_setallmulti_set,
7201 		(void *)&cmd_setallmulti_allmulti,
7202 		(void *)&cmd_setallmulti_portall,
7203 		(void *)&cmd_setallmulti_mode,
7204 		NULL,
7205 	},
7206 };
7207 
7208 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
7209 	.f = cmd_set_allmulti_mode_parsed,
7210 	.data = (void *)0,
7211 	.help_str = "set allmulti <port_id> on|off: "
7212 		"Set allmulti mode on port_id",
7213 	.tokens = {
7214 		(void *)&cmd_setallmulti_set,
7215 		(void *)&cmd_setallmulti_allmulti,
7216 		(void *)&cmd_setallmulti_portnum,
7217 		(void *)&cmd_setallmulti_mode,
7218 		NULL,
7219 	},
7220 };
7221 
7222 /* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */
7223 struct cmd_link_flow_ctrl_show {
7224 	cmdline_fixed_string_t show;
7225 	cmdline_fixed_string_t port;
7226 	portid_t port_id;
7227 	cmdline_fixed_string_t flow_ctrl;
7228 };
7229 
7230 cmdline_parse_token_string_t cmd_lfc_show_show =
7231 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7232 				show, "show");
7233 cmdline_parse_token_string_t cmd_lfc_show_port =
7234 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7235 				port, "port");
7236 cmdline_parse_token_num_t cmd_lfc_show_portid =
7237 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show,
7238 				port_id, RTE_UINT16);
7239 cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl =
7240 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7241 				flow_ctrl, "flow_ctrl");
7242 
7243 static void
7244 cmd_link_flow_ctrl_show_parsed(void *parsed_result,
7245 			      __rte_unused struct cmdline *cl,
7246 			      __rte_unused void *data)
7247 {
7248 	struct cmd_link_flow_ctrl_show *res = parsed_result;
7249 	static const char *info_border = "*********************";
7250 	struct rte_eth_fc_conf fc_conf;
7251 	bool rx_fc_en = false;
7252 	bool tx_fc_en = false;
7253 	int ret;
7254 
7255 	ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7256 	if (ret != 0) {
7257 		fprintf(stderr,
7258 			"Failed to get current flow ctrl information: err = %d\n",
7259 			ret);
7260 		return;
7261 	}
7262 
7263 	if (fc_conf.mode == RTE_ETH_FC_RX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7264 		rx_fc_en = true;
7265 	if (fc_conf.mode == RTE_ETH_FC_TX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7266 		tx_fc_en = true;
7267 
7268 	printf("\n%s Flow control infos for port %-2d %s\n",
7269 		info_border, res->port_id, info_border);
7270 	printf("FC mode:\n");
7271 	printf("   Rx pause: %s\n", rx_fc_en ? "on" : "off");
7272 	printf("   Tx pause: %s\n", tx_fc_en ? "on" : "off");
7273 	printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off");
7274 	printf("Pause time: 0x%x\n", fc_conf.pause_time);
7275 	printf("High waterline: 0x%x\n", fc_conf.high_water);
7276 	printf("Low waterline: 0x%x\n", fc_conf.low_water);
7277 	printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off");
7278 	printf("Forward MAC control frames: %s\n",
7279 		fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
7280 	printf("\n%s**************   End  ***********%s\n",
7281 		info_border, info_border);
7282 }
7283 
7284 cmdline_parse_inst_t cmd_link_flow_control_show = {
7285 	.f = cmd_link_flow_ctrl_show_parsed,
7286 	.data = NULL,
7287 	.help_str = "show port <port_id> flow_ctrl",
7288 	.tokens = {
7289 		(void *)&cmd_lfc_show_show,
7290 		(void *)&cmd_lfc_show_port,
7291 		(void *)&cmd_lfc_show_portid,
7292 		(void *)&cmd_lfc_show_flow_ctrl,
7293 		NULL,
7294 	},
7295 };
7296 
7297 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7298 struct cmd_link_flow_ctrl_set_result {
7299 	cmdline_fixed_string_t set;
7300 	cmdline_fixed_string_t flow_ctrl;
7301 	cmdline_fixed_string_t rx;
7302 	cmdline_fixed_string_t rx_lfc_mode;
7303 	cmdline_fixed_string_t tx;
7304 	cmdline_fixed_string_t tx_lfc_mode;
7305 	cmdline_fixed_string_t mac_ctrl_frame_fwd;
7306 	cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7307 	cmdline_fixed_string_t autoneg_str;
7308 	cmdline_fixed_string_t autoneg;
7309 	cmdline_fixed_string_t hw_str;
7310 	uint32_t high_water;
7311 	cmdline_fixed_string_t lw_str;
7312 	uint32_t low_water;
7313 	cmdline_fixed_string_t pt_str;
7314 	uint16_t pause_time;
7315 	cmdline_fixed_string_t xon_str;
7316 	uint16_t send_xon;
7317 	portid_t port_id;
7318 };
7319 
7320 cmdline_parse_token_string_t cmd_lfc_set_set =
7321 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7322 				set, "set");
7323 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7324 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7325 				flow_ctrl, "flow_ctrl");
7326 cmdline_parse_token_string_t cmd_lfc_set_rx =
7327 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7328 				rx, "rx");
7329 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7330 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7331 				rx_lfc_mode, "on#off");
7332 cmdline_parse_token_string_t cmd_lfc_set_tx =
7333 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7334 				tx, "tx");
7335 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7336 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7337 				tx_lfc_mode, "on#off");
7338 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7339 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7340 				hw_str, "high_water");
7341 cmdline_parse_token_num_t cmd_lfc_set_high_water =
7342 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7343 				high_water, RTE_UINT32);
7344 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7345 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7346 				lw_str, "low_water");
7347 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7348 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7349 				low_water, RTE_UINT32);
7350 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7351 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7352 				pt_str, "pause_time");
7353 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7354 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7355 				pause_time, RTE_UINT16);
7356 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7357 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7358 				xon_str, "send_xon");
7359 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7360 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7361 				send_xon, RTE_UINT16);
7362 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7363 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7364 				mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7365 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7366 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7367 				mac_ctrl_frame_fwd_mode, "on#off");
7368 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7369 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7370 				autoneg_str, "autoneg");
7371 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7372 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7373 				autoneg, "on#off");
7374 cmdline_parse_token_num_t cmd_lfc_set_portid =
7375 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7376 				port_id, RTE_UINT16);
7377 
7378 /* forward declaration */
7379 static void
7380 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7381 			      void *data);
7382 
7383 cmdline_parse_inst_t cmd_link_flow_control_set = {
7384 	.f = cmd_link_flow_ctrl_set_parsed,
7385 	.data = NULL,
7386 	.help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7387 		"<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7388 		"autoneg on|off <port_id>: Configure the Ethernet flow control",
7389 	.tokens = {
7390 		(void *)&cmd_lfc_set_set,
7391 		(void *)&cmd_lfc_set_flow_ctrl,
7392 		(void *)&cmd_lfc_set_rx,
7393 		(void *)&cmd_lfc_set_rx_mode,
7394 		(void *)&cmd_lfc_set_tx,
7395 		(void *)&cmd_lfc_set_tx_mode,
7396 		(void *)&cmd_lfc_set_high_water,
7397 		(void *)&cmd_lfc_set_low_water,
7398 		(void *)&cmd_lfc_set_pause_time,
7399 		(void *)&cmd_lfc_set_send_xon,
7400 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7401 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7402 		(void *)&cmd_lfc_set_autoneg_str,
7403 		(void *)&cmd_lfc_set_autoneg,
7404 		(void *)&cmd_lfc_set_portid,
7405 		NULL,
7406 	},
7407 };
7408 
7409 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7410 	.f = cmd_link_flow_ctrl_set_parsed,
7411 	.data = (void *)&cmd_link_flow_control_set_rx,
7412 	.help_str = "set flow_ctrl rx on|off <port_id>: "
7413 		"Change rx flow control parameter",
7414 	.tokens = {
7415 		(void *)&cmd_lfc_set_set,
7416 		(void *)&cmd_lfc_set_flow_ctrl,
7417 		(void *)&cmd_lfc_set_rx,
7418 		(void *)&cmd_lfc_set_rx_mode,
7419 		(void *)&cmd_lfc_set_portid,
7420 		NULL,
7421 	},
7422 };
7423 
7424 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7425 	.f = cmd_link_flow_ctrl_set_parsed,
7426 	.data = (void *)&cmd_link_flow_control_set_tx,
7427 	.help_str = "set flow_ctrl tx on|off <port_id>: "
7428 		"Change tx flow control parameter",
7429 	.tokens = {
7430 		(void *)&cmd_lfc_set_set,
7431 		(void *)&cmd_lfc_set_flow_ctrl,
7432 		(void *)&cmd_lfc_set_tx,
7433 		(void *)&cmd_lfc_set_tx_mode,
7434 		(void *)&cmd_lfc_set_portid,
7435 		NULL,
7436 	},
7437 };
7438 
7439 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7440 	.f = cmd_link_flow_ctrl_set_parsed,
7441 	.data = (void *)&cmd_link_flow_control_set_hw,
7442 	.help_str = "set flow_ctrl high_water <value> <port_id>: "
7443 		"Change high water flow control parameter",
7444 	.tokens = {
7445 		(void *)&cmd_lfc_set_set,
7446 		(void *)&cmd_lfc_set_flow_ctrl,
7447 		(void *)&cmd_lfc_set_high_water_str,
7448 		(void *)&cmd_lfc_set_high_water,
7449 		(void *)&cmd_lfc_set_portid,
7450 		NULL,
7451 	},
7452 };
7453 
7454 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7455 	.f = cmd_link_flow_ctrl_set_parsed,
7456 	.data = (void *)&cmd_link_flow_control_set_lw,
7457 	.help_str = "set flow_ctrl low_water <value> <port_id>: "
7458 		"Change low water flow control parameter",
7459 	.tokens = {
7460 		(void *)&cmd_lfc_set_set,
7461 		(void *)&cmd_lfc_set_flow_ctrl,
7462 		(void *)&cmd_lfc_set_low_water_str,
7463 		(void *)&cmd_lfc_set_low_water,
7464 		(void *)&cmd_lfc_set_portid,
7465 		NULL,
7466 	},
7467 };
7468 
7469 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7470 	.f = cmd_link_flow_ctrl_set_parsed,
7471 	.data = (void *)&cmd_link_flow_control_set_pt,
7472 	.help_str = "set flow_ctrl pause_time <value> <port_id>: "
7473 		"Change pause time flow control parameter",
7474 	.tokens = {
7475 		(void *)&cmd_lfc_set_set,
7476 		(void *)&cmd_lfc_set_flow_ctrl,
7477 		(void *)&cmd_lfc_set_pause_time_str,
7478 		(void *)&cmd_lfc_set_pause_time,
7479 		(void *)&cmd_lfc_set_portid,
7480 		NULL,
7481 	},
7482 };
7483 
7484 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7485 	.f = cmd_link_flow_ctrl_set_parsed,
7486 	.data = (void *)&cmd_link_flow_control_set_xon,
7487 	.help_str = "set flow_ctrl send_xon <value> <port_id>: "
7488 		"Change send_xon flow control parameter",
7489 	.tokens = {
7490 		(void *)&cmd_lfc_set_set,
7491 		(void *)&cmd_lfc_set_flow_ctrl,
7492 		(void *)&cmd_lfc_set_send_xon_str,
7493 		(void *)&cmd_lfc_set_send_xon,
7494 		(void *)&cmd_lfc_set_portid,
7495 		NULL,
7496 	},
7497 };
7498 
7499 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7500 	.f = cmd_link_flow_ctrl_set_parsed,
7501 	.data = (void *)&cmd_link_flow_control_set_macfwd,
7502 	.help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7503 		"Change mac ctrl fwd flow control parameter",
7504 	.tokens = {
7505 		(void *)&cmd_lfc_set_set,
7506 		(void *)&cmd_lfc_set_flow_ctrl,
7507 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7508 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7509 		(void *)&cmd_lfc_set_portid,
7510 		NULL,
7511 	},
7512 };
7513 
7514 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7515 	.f = cmd_link_flow_ctrl_set_parsed,
7516 	.data = (void *)&cmd_link_flow_control_set_autoneg,
7517 	.help_str = "set flow_ctrl autoneg on|off <port_id>: "
7518 		"Change autoneg flow control parameter",
7519 	.tokens = {
7520 		(void *)&cmd_lfc_set_set,
7521 		(void *)&cmd_lfc_set_flow_ctrl,
7522 		(void *)&cmd_lfc_set_autoneg_str,
7523 		(void *)&cmd_lfc_set_autoneg,
7524 		(void *)&cmd_lfc_set_portid,
7525 		NULL,
7526 	},
7527 };
7528 
7529 static void
7530 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7531 			      __rte_unused struct cmdline *cl,
7532 			      void *data)
7533 {
7534 	struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7535 	cmdline_parse_inst_t *cmd = data;
7536 	struct rte_eth_fc_conf fc_conf;
7537 	int rx_fc_en = 0;
7538 	int tx_fc_en = 0;
7539 	int ret;
7540 
7541 	/*
7542 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7543 	 * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7544 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7545 	 * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7546 	 */
7547 	static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7548 			{RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7549 	};
7550 
7551 	/* Partial command line, retrieve current configuration */
7552 	if (cmd) {
7553 		ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7554 		if (ret != 0) {
7555 			fprintf(stderr,
7556 				"cannot get current flow ctrl parameters, return code = %d\n",
7557 				ret);
7558 			return;
7559 		}
7560 
7561 		if ((fc_conf.mode == RTE_ETH_FC_RX_PAUSE) ||
7562 		    (fc_conf.mode == RTE_ETH_FC_FULL))
7563 			rx_fc_en = 1;
7564 		if ((fc_conf.mode == RTE_ETH_FC_TX_PAUSE) ||
7565 		    (fc_conf.mode == RTE_ETH_FC_FULL))
7566 			tx_fc_en = 1;
7567 	}
7568 
7569 	if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7570 		rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7571 
7572 	if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7573 		tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7574 
7575 	fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7576 
7577 	if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7578 		fc_conf.high_water = res->high_water;
7579 
7580 	if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7581 		fc_conf.low_water = res->low_water;
7582 
7583 	if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7584 		fc_conf.pause_time = res->pause_time;
7585 
7586 	if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7587 		fc_conf.send_xon = res->send_xon;
7588 
7589 	if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7590 		if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7591 			fc_conf.mac_ctrl_frame_fwd = 1;
7592 		else
7593 			fc_conf.mac_ctrl_frame_fwd = 0;
7594 	}
7595 
7596 	if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7597 		fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7598 
7599 	ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7600 	if (ret != 0)
7601 		fprintf(stderr,
7602 			"bad flow control parameter, return code = %d\n",
7603 			ret);
7604 }
7605 
7606 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7607 struct cmd_priority_flow_ctrl_set_result {
7608 	cmdline_fixed_string_t set;
7609 	cmdline_fixed_string_t pfc_ctrl;
7610 	cmdline_fixed_string_t rx;
7611 	cmdline_fixed_string_t rx_pfc_mode;
7612 	cmdline_fixed_string_t tx;
7613 	cmdline_fixed_string_t tx_pfc_mode;
7614 	uint32_t high_water;
7615 	uint32_t low_water;
7616 	uint16_t pause_time;
7617 	uint8_t  priority;
7618 	portid_t port_id;
7619 };
7620 
7621 static void
7622 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7623 		       __rte_unused struct cmdline *cl,
7624 		       __rte_unused void *data)
7625 {
7626 	struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7627 	struct rte_eth_pfc_conf pfc_conf;
7628 	int rx_fc_enable, tx_fc_enable;
7629 	int ret;
7630 
7631 	/*
7632 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7633 	 * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7634 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7635 	 * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7636 	 */
7637 	static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7638 		{RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7639 	};
7640 
7641 	memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7642 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7643 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7644 	pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7645 	pfc_conf.fc.high_water = res->high_water;
7646 	pfc_conf.fc.low_water  = res->low_water;
7647 	pfc_conf.fc.pause_time = res->pause_time;
7648 	pfc_conf.priority      = res->priority;
7649 
7650 	ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7651 	if (ret != 0)
7652 		fprintf(stderr,
7653 			"bad priority flow control parameter, return code = %d\n",
7654 			ret);
7655 }
7656 
7657 cmdline_parse_token_string_t cmd_pfc_set_set =
7658 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7659 				set, "set");
7660 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7661 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7662 				pfc_ctrl, "pfc_ctrl");
7663 cmdline_parse_token_string_t cmd_pfc_set_rx =
7664 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7665 				rx, "rx");
7666 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7667 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7668 				rx_pfc_mode, "on#off");
7669 cmdline_parse_token_string_t cmd_pfc_set_tx =
7670 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7671 				tx, "tx");
7672 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7673 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7674 				tx_pfc_mode, "on#off");
7675 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7676 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7677 				high_water, RTE_UINT32);
7678 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7679 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7680 				low_water, RTE_UINT32);
7681 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7682 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7683 				pause_time, RTE_UINT16);
7684 cmdline_parse_token_num_t cmd_pfc_set_priority =
7685 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7686 				priority, RTE_UINT8);
7687 cmdline_parse_token_num_t cmd_pfc_set_portid =
7688 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7689 				port_id, RTE_UINT16);
7690 
7691 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7692 	.f = cmd_priority_flow_ctrl_set_parsed,
7693 	.data = NULL,
7694 	.help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7695 		"<pause_time> <priority> <port_id>: "
7696 		"Configure the Ethernet priority flow control",
7697 	.tokens = {
7698 		(void *)&cmd_pfc_set_set,
7699 		(void *)&cmd_pfc_set_flow_ctrl,
7700 		(void *)&cmd_pfc_set_rx,
7701 		(void *)&cmd_pfc_set_rx_mode,
7702 		(void *)&cmd_pfc_set_tx,
7703 		(void *)&cmd_pfc_set_tx_mode,
7704 		(void *)&cmd_pfc_set_high_water,
7705 		(void *)&cmd_pfc_set_low_water,
7706 		(void *)&cmd_pfc_set_pause_time,
7707 		(void *)&cmd_pfc_set_priority,
7708 		(void *)&cmd_pfc_set_portid,
7709 		NULL,
7710 	},
7711 };
7712 
7713 struct cmd_queue_priority_flow_ctrl_set_result {
7714 	cmdline_fixed_string_t set;
7715 	cmdline_fixed_string_t pfc_queue_ctrl;
7716 	portid_t port_id;
7717 	cmdline_fixed_string_t rx;
7718 	cmdline_fixed_string_t rx_pfc_mode;
7719 	uint16_t tx_qid;
7720 	uint8_t  tx_tc;
7721 	cmdline_fixed_string_t tx;
7722 	cmdline_fixed_string_t tx_pfc_mode;
7723 	uint16_t rx_qid;
7724 	uint8_t  rx_tc;
7725 	uint16_t pause_time;
7726 };
7727 
7728 static void
7729 cmd_queue_priority_flow_ctrl_set_parsed(void *parsed_result,
7730 					__rte_unused struct cmdline *cl,
7731 					__rte_unused void *data)
7732 {
7733 	struct cmd_queue_priority_flow_ctrl_set_result *res = parsed_result;
7734 	struct rte_eth_pfc_queue_conf pfc_queue_conf;
7735 	int rx_fc_enable, tx_fc_enable;
7736 	int ret;
7737 
7738 	/*
7739 	 * Rx on/off, flow control is enabled/disabled on RX side. This can
7740 	 * indicate the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx
7741 	 * side. Tx on/off, flow control is enabled/disabled on TX side. This
7742 	 * can indicate the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at
7743 	 * the Tx side.
7744 	 */
7745 	static enum rte_eth_fc_mode rx_tx_onoff_2_mode[2][2] = {
7746 		{RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE},
7747 		{RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7748 	};
7749 
7750 	memset(&pfc_queue_conf, 0, sizeof(struct rte_eth_pfc_queue_conf));
7751 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on", 2)) ? 1 : 0;
7752 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on", 2)) ? 1 : 0;
7753 	pfc_queue_conf.mode = rx_tx_onoff_2_mode[rx_fc_enable][tx_fc_enable];
7754 	pfc_queue_conf.rx_pause.tc  = res->tx_tc;
7755 	pfc_queue_conf.rx_pause.tx_qid = res->tx_qid;
7756 	pfc_queue_conf.tx_pause.tc  = res->rx_tc;
7757 	pfc_queue_conf.tx_pause.rx_qid  = res->rx_qid;
7758 	pfc_queue_conf.tx_pause.pause_time = res->pause_time;
7759 
7760 	ret = rte_eth_dev_priority_flow_ctrl_queue_configure(res->port_id,
7761 							     &pfc_queue_conf);
7762 	if (ret != 0) {
7763 		fprintf(stderr,
7764 			"bad queue priority flow control parameter, rc = %d\n",
7765 			ret);
7766 	}
7767 }
7768 
7769 cmdline_parse_token_string_t cmd_q_pfc_set_set =
7770 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7771 				set, "set");
7772 cmdline_parse_token_string_t cmd_q_pfc_set_flow_ctrl =
7773 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7774 				pfc_queue_ctrl, "pfc_queue_ctrl");
7775 cmdline_parse_token_num_t cmd_q_pfc_set_portid =
7776 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7777 				port_id, RTE_UINT16);
7778 cmdline_parse_token_string_t cmd_q_pfc_set_rx =
7779 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7780 				rx, "rx");
7781 cmdline_parse_token_string_t cmd_q_pfc_set_rx_mode =
7782 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7783 				rx_pfc_mode, "on#off");
7784 cmdline_parse_token_num_t cmd_q_pfc_set_tx_qid =
7785 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7786 				tx_qid, RTE_UINT16);
7787 cmdline_parse_token_num_t cmd_q_pfc_set_tx_tc =
7788 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7789 				tx_tc, RTE_UINT8);
7790 cmdline_parse_token_string_t cmd_q_pfc_set_tx =
7791 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7792 				tx, "tx");
7793 cmdline_parse_token_string_t cmd_q_pfc_set_tx_mode =
7794 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7795 				tx_pfc_mode, "on#off");
7796 cmdline_parse_token_num_t cmd_q_pfc_set_rx_qid =
7797 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7798 				rx_qid, RTE_UINT16);
7799 cmdline_parse_token_num_t cmd_q_pfc_set_rx_tc =
7800 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7801 				rx_tc, RTE_UINT8);
7802 cmdline_parse_token_num_t cmd_q_pfc_set_pause_time =
7803 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7804 				pause_time, RTE_UINT16);
7805 
7806 cmdline_parse_inst_t cmd_queue_priority_flow_control_set = {
7807 	.f = cmd_queue_priority_flow_ctrl_set_parsed,
7808 	.data = NULL,
7809 	.help_str = "set pfc_queue_ctrl <port_id> rx <on|off> <tx_qid> <tx_tc> "
7810 		"tx <on|off> <rx_qid> <rx_tc> <pause_time>: "
7811 		"Configure the Ethernet queue priority flow control",
7812 	.tokens = {
7813 		(void *)&cmd_q_pfc_set_set,
7814 		(void *)&cmd_q_pfc_set_flow_ctrl,
7815 		(void *)&cmd_q_pfc_set_portid,
7816 		(void *)&cmd_q_pfc_set_rx,
7817 		(void *)&cmd_q_pfc_set_rx_mode,
7818 		(void *)&cmd_q_pfc_set_tx_qid,
7819 		(void *)&cmd_q_pfc_set_tx_tc,
7820 		(void *)&cmd_q_pfc_set_tx,
7821 		(void *)&cmd_q_pfc_set_tx_mode,
7822 		(void *)&cmd_q_pfc_set_rx_qid,
7823 		(void *)&cmd_q_pfc_set_rx_tc,
7824 		(void *)&cmd_q_pfc_set_pause_time,
7825 		NULL,
7826 	},
7827 };
7828 
7829 /* *** RESET CONFIGURATION *** */
7830 struct cmd_reset_result {
7831 	cmdline_fixed_string_t reset;
7832 	cmdline_fixed_string_t def;
7833 };
7834 
7835 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7836 			     struct cmdline *cl,
7837 			     __rte_unused void *data)
7838 {
7839 	cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7840 	set_def_fwd_config();
7841 }
7842 
7843 cmdline_parse_token_string_t cmd_reset_set =
7844 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7845 cmdline_parse_token_string_t cmd_reset_def =
7846 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7847 				 "default");
7848 
7849 cmdline_parse_inst_t cmd_reset = {
7850 	.f = cmd_reset_parsed,
7851 	.data = NULL,
7852 	.help_str = "set default: Reset default forwarding configuration",
7853 	.tokens = {
7854 		(void *)&cmd_reset_set,
7855 		(void *)&cmd_reset_def,
7856 		NULL,
7857 	},
7858 };
7859 
7860 /* *** START FORWARDING *** */
7861 struct cmd_start_result {
7862 	cmdline_fixed_string_t start;
7863 };
7864 
7865 cmdline_parse_token_string_t cmd_start_start =
7866 	TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7867 
7868 static void cmd_start_parsed(__rte_unused void *parsed_result,
7869 			     __rte_unused struct cmdline *cl,
7870 			     __rte_unused void *data)
7871 {
7872 	start_packet_forwarding(0);
7873 }
7874 
7875 cmdline_parse_inst_t cmd_start = {
7876 	.f = cmd_start_parsed,
7877 	.data = NULL,
7878 	.help_str = "start: Start packet forwarding",
7879 	.tokens = {
7880 		(void *)&cmd_start_start,
7881 		NULL,
7882 	},
7883 };
7884 
7885 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7886 struct cmd_start_tx_first_result {
7887 	cmdline_fixed_string_t start;
7888 	cmdline_fixed_string_t tx_first;
7889 };
7890 
7891 static void
7892 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7893 			  __rte_unused struct cmdline *cl,
7894 			  __rte_unused void *data)
7895 {
7896 	start_packet_forwarding(1);
7897 }
7898 
7899 cmdline_parse_token_string_t cmd_start_tx_first_start =
7900 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7901 				 "start");
7902 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7903 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7904 				 tx_first, "tx_first");
7905 
7906 cmdline_parse_inst_t cmd_start_tx_first = {
7907 	.f = cmd_start_tx_first_parsed,
7908 	.data = NULL,
7909 	.help_str = "start tx_first: Start packet forwarding, "
7910 		"after sending 1 burst of packets",
7911 	.tokens = {
7912 		(void *)&cmd_start_tx_first_start,
7913 		(void *)&cmd_start_tx_first_tx_first,
7914 		NULL,
7915 	},
7916 };
7917 
7918 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7919 struct cmd_start_tx_first_n_result {
7920 	cmdline_fixed_string_t start;
7921 	cmdline_fixed_string_t tx_first;
7922 	uint32_t tx_num;
7923 };
7924 
7925 static void
7926 cmd_start_tx_first_n_parsed(void *parsed_result,
7927 			  __rte_unused struct cmdline *cl,
7928 			  __rte_unused void *data)
7929 {
7930 	struct cmd_start_tx_first_n_result *res = parsed_result;
7931 
7932 	start_packet_forwarding(res->tx_num);
7933 }
7934 
7935 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7936 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7937 			start, "start");
7938 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7939 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7940 			tx_first, "tx_first");
7941 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7942 	TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7943 			tx_num, RTE_UINT32);
7944 
7945 cmdline_parse_inst_t cmd_start_tx_first_n = {
7946 	.f = cmd_start_tx_first_n_parsed,
7947 	.data = NULL,
7948 	.help_str = "start tx_first <num>: "
7949 		"packet forwarding, after sending <num> bursts of packets",
7950 	.tokens = {
7951 		(void *)&cmd_start_tx_first_n_start,
7952 		(void *)&cmd_start_tx_first_n_tx_first,
7953 		(void *)&cmd_start_tx_first_n_tx_num,
7954 		NULL,
7955 	},
7956 };
7957 
7958 /* *** SET LINK UP *** */
7959 struct cmd_set_link_up_result {
7960 	cmdline_fixed_string_t set;
7961 	cmdline_fixed_string_t link_up;
7962 	cmdline_fixed_string_t port;
7963 	portid_t port_id;
7964 };
7965 
7966 cmdline_parse_token_string_t cmd_set_link_up_set =
7967 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7968 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7969 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7970 				"link-up");
7971 cmdline_parse_token_string_t cmd_set_link_up_port =
7972 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7973 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7974 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7975 				RTE_UINT16);
7976 
7977 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7978 			     __rte_unused struct cmdline *cl,
7979 			     __rte_unused void *data)
7980 {
7981 	struct cmd_set_link_up_result *res = parsed_result;
7982 	dev_set_link_up(res->port_id);
7983 }
7984 
7985 cmdline_parse_inst_t cmd_set_link_up = {
7986 	.f = cmd_set_link_up_parsed,
7987 	.data = NULL,
7988 	.help_str = "set link-up port <port id>",
7989 	.tokens = {
7990 		(void *)&cmd_set_link_up_set,
7991 		(void *)&cmd_set_link_up_link_up,
7992 		(void *)&cmd_set_link_up_port,
7993 		(void *)&cmd_set_link_up_port_id,
7994 		NULL,
7995 	},
7996 };
7997 
7998 /* *** SET LINK DOWN *** */
7999 struct cmd_set_link_down_result {
8000 	cmdline_fixed_string_t set;
8001 	cmdline_fixed_string_t link_down;
8002 	cmdline_fixed_string_t port;
8003 	portid_t port_id;
8004 };
8005 
8006 cmdline_parse_token_string_t cmd_set_link_down_set =
8007 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
8008 cmdline_parse_token_string_t cmd_set_link_down_link_down =
8009 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
8010 				"link-down");
8011 cmdline_parse_token_string_t cmd_set_link_down_port =
8012 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
8013 cmdline_parse_token_num_t cmd_set_link_down_port_id =
8014 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
8015 				RTE_UINT16);
8016 
8017 static void cmd_set_link_down_parsed(
8018 				__rte_unused void *parsed_result,
8019 				__rte_unused struct cmdline *cl,
8020 				__rte_unused void *data)
8021 {
8022 	struct cmd_set_link_down_result *res = parsed_result;
8023 	dev_set_link_down(res->port_id);
8024 }
8025 
8026 cmdline_parse_inst_t cmd_set_link_down = {
8027 	.f = cmd_set_link_down_parsed,
8028 	.data = NULL,
8029 	.help_str = "set link-down port <port id>",
8030 	.tokens = {
8031 		(void *)&cmd_set_link_down_set,
8032 		(void *)&cmd_set_link_down_link_down,
8033 		(void *)&cmd_set_link_down_port,
8034 		(void *)&cmd_set_link_down_port_id,
8035 		NULL,
8036 	},
8037 };
8038 
8039 /* *** SHOW CFG *** */
8040 struct cmd_showcfg_result {
8041 	cmdline_fixed_string_t show;
8042 	cmdline_fixed_string_t cfg;
8043 	cmdline_fixed_string_t what;
8044 };
8045 
8046 static void cmd_showcfg_parsed(void *parsed_result,
8047 			       __rte_unused struct cmdline *cl,
8048 			       __rte_unused void *data)
8049 {
8050 	struct cmd_showcfg_result *res = parsed_result;
8051 	if (!strcmp(res->what, "rxtx"))
8052 		rxtx_config_display();
8053 	else if (!strcmp(res->what, "cores"))
8054 		fwd_lcores_config_display();
8055 	else if (!strcmp(res->what, "fwd"))
8056 		pkt_fwd_config_display(&cur_fwd_config);
8057 	else if (!strcmp(res->what, "rxoffs"))
8058 		show_rx_pkt_offsets();
8059 	else if (!strcmp(res->what, "rxpkts"))
8060 		show_rx_pkt_segments();
8061 	else if (!strcmp(res->what, "txpkts"))
8062 		show_tx_pkt_segments();
8063 	else if (!strcmp(res->what, "txtimes"))
8064 		show_tx_pkt_times();
8065 }
8066 
8067 cmdline_parse_token_string_t cmd_showcfg_show =
8068 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
8069 cmdline_parse_token_string_t cmd_showcfg_port =
8070 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
8071 cmdline_parse_token_string_t cmd_showcfg_what =
8072 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
8073 				 "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
8074 
8075 cmdline_parse_inst_t cmd_showcfg = {
8076 	.f = cmd_showcfg_parsed,
8077 	.data = NULL,
8078 	.help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
8079 	.tokens = {
8080 		(void *)&cmd_showcfg_show,
8081 		(void *)&cmd_showcfg_port,
8082 		(void *)&cmd_showcfg_what,
8083 		NULL,
8084 	},
8085 };
8086 
8087 /* *** SHOW ALL PORT INFO *** */
8088 struct cmd_showportall_result {
8089 	cmdline_fixed_string_t show;
8090 	cmdline_fixed_string_t port;
8091 	cmdline_fixed_string_t what;
8092 	cmdline_fixed_string_t all;
8093 };
8094 
8095 static void cmd_showportall_parsed(void *parsed_result,
8096 				__rte_unused struct cmdline *cl,
8097 				__rte_unused void *data)
8098 {
8099 	portid_t i;
8100 
8101 	struct cmd_showportall_result *res = parsed_result;
8102 	if (!strcmp(res->show, "clear")) {
8103 		if (!strcmp(res->what, "stats"))
8104 			RTE_ETH_FOREACH_DEV(i)
8105 				nic_stats_clear(i);
8106 		else if (!strcmp(res->what, "xstats"))
8107 			RTE_ETH_FOREACH_DEV(i)
8108 				nic_xstats_clear(i);
8109 	} else if (!strcmp(res->what, "info"))
8110 		RTE_ETH_FOREACH_DEV(i)
8111 			port_infos_display(i);
8112 	else if (!strcmp(res->what, "summary")) {
8113 		port_summary_header_display();
8114 		RTE_ETH_FOREACH_DEV(i)
8115 			port_summary_display(i);
8116 	}
8117 	else if (!strcmp(res->what, "stats"))
8118 		RTE_ETH_FOREACH_DEV(i)
8119 			nic_stats_display(i);
8120 	else if (!strcmp(res->what, "xstats"))
8121 		RTE_ETH_FOREACH_DEV(i)
8122 			nic_xstats_display(i);
8123 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8124 	else if (!strcmp(res->what, "fdir"))
8125 		RTE_ETH_FOREACH_DEV(i)
8126 			fdir_get_infos(i);
8127 #endif
8128 	else if (!strcmp(res->what, "dcb_tc"))
8129 		RTE_ETH_FOREACH_DEV(i)
8130 			port_dcb_info_display(i);
8131 }
8132 
8133 cmdline_parse_token_string_t cmd_showportall_show =
8134 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
8135 				 "show#clear");
8136 cmdline_parse_token_string_t cmd_showportall_port =
8137 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
8138 cmdline_parse_token_string_t cmd_showportall_what =
8139 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
8140 				 "info#summary#stats#xstats#fdir#dcb_tc");
8141 cmdline_parse_token_string_t cmd_showportall_all =
8142 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
8143 cmdline_parse_inst_t cmd_showportall = {
8144 	.f = cmd_showportall_parsed,
8145 	.data = NULL,
8146 	.help_str = "show|clear port "
8147 		"info|summary|stats|xstats|fdir|dcb_tc all",
8148 	.tokens = {
8149 		(void *)&cmd_showportall_show,
8150 		(void *)&cmd_showportall_port,
8151 		(void *)&cmd_showportall_what,
8152 		(void *)&cmd_showportall_all,
8153 		NULL,
8154 	},
8155 };
8156 
8157 /* *** SHOW PORT INFO *** */
8158 struct cmd_showport_result {
8159 	cmdline_fixed_string_t show;
8160 	cmdline_fixed_string_t port;
8161 	cmdline_fixed_string_t what;
8162 	uint16_t portnum;
8163 };
8164 
8165 static void cmd_showport_parsed(void *parsed_result,
8166 				__rte_unused struct cmdline *cl,
8167 				__rte_unused void *data)
8168 {
8169 	struct cmd_showport_result *res = parsed_result;
8170 	if (!strcmp(res->show, "clear")) {
8171 		if (!strcmp(res->what, "stats"))
8172 			nic_stats_clear(res->portnum);
8173 		else if (!strcmp(res->what, "xstats"))
8174 			nic_xstats_clear(res->portnum);
8175 	} else if (!strcmp(res->what, "info"))
8176 		port_infos_display(res->portnum);
8177 	else if (!strcmp(res->what, "summary")) {
8178 		port_summary_header_display();
8179 		port_summary_display(res->portnum);
8180 	}
8181 	else if (!strcmp(res->what, "stats"))
8182 		nic_stats_display(res->portnum);
8183 	else if (!strcmp(res->what, "xstats"))
8184 		nic_xstats_display(res->portnum);
8185 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8186 	else if (!strcmp(res->what, "fdir"))
8187 		 fdir_get_infos(res->portnum);
8188 #endif
8189 	else if (!strcmp(res->what, "dcb_tc"))
8190 		port_dcb_info_display(res->portnum);
8191 }
8192 
8193 cmdline_parse_token_string_t cmd_showport_show =
8194 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
8195 				 "show#clear");
8196 cmdline_parse_token_string_t cmd_showport_port =
8197 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
8198 cmdline_parse_token_string_t cmd_showport_what =
8199 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
8200 				 "info#summary#stats#xstats#fdir#dcb_tc");
8201 cmdline_parse_token_num_t cmd_showport_portnum =
8202 	TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
8203 
8204 cmdline_parse_inst_t cmd_showport = {
8205 	.f = cmd_showport_parsed,
8206 	.data = NULL,
8207 	.help_str = "show|clear port "
8208 		"info|summary|stats|xstats|fdir|dcb_tc "
8209 		"<port_id>",
8210 	.tokens = {
8211 		(void *)&cmd_showport_show,
8212 		(void *)&cmd_showport_port,
8213 		(void *)&cmd_showport_what,
8214 		(void *)&cmd_showport_portnum,
8215 		NULL,
8216 	},
8217 };
8218 
8219 /* *** show port representors information *** */
8220 struct cmd_representor_info_result {
8221 	cmdline_fixed_string_t cmd_show;
8222 	cmdline_fixed_string_t cmd_port;
8223 	cmdline_fixed_string_t cmd_info;
8224 	cmdline_fixed_string_t cmd_keyword;
8225 	portid_t cmd_pid;
8226 };
8227 
8228 static void
8229 cmd_representor_info_parsed(void *parsed_result,
8230 		__rte_unused struct cmdline *cl,
8231 		__rte_unused void *data)
8232 {
8233 	struct cmd_representor_info_result *res = parsed_result;
8234 	struct rte_eth_representor_info *info;
8235 	struct rte_eth_representor_range *range;
8236 	uint32_t range_diff;
8237 	uint32_t i;
8238 	int ret;
8239 	int num;
8240 
8241 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
8242 		fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
8243 		return;
8244 	}
8245 
8246 	ret = rte_eth_representor_info_get(res->cmd_pid, NULL);
8247 	if (ret < 0) {
8248 		fprintf(stderr,
8249 			"Failed to get the number of representor info ranges for port %hu: %s\n",
8250 			res->cmd_pid, rte_strerror(-ret));
8251 		return;
8252 	}
8253 	num = ret;
8254 
8255 	info = calloc(1, sizeof(*info) + num * sizeof(info->ranges[0]));
8256 	if (info == NULL) {
8257 		fprintf(stderr,
8258 			"Failed to allocate memory for representor info for port %hu\n",
8259 			res->cmd_pid);
8260 		return;
8261 	}
8262 	info->nb_ranges_alloc = num;
8263 
8264 	ret = rte_eth_representor_info_get(res->cmd_pid, info);
8265 	if (ret < 0) {
8266 		fprintf(stderr,
8267 			"Failed to get the representor info for port %hu: %s\n",
8268 			res->cmd_pid, rte_strerror(-ret));
8269 		free(info);
8270 		return;
8271 	}
8272 
8273 	printf("Port controller: %hu\n", info->controller);
8274 	printf("Port PF: %hu\n", info->pf);
8275 
8276 	printf("Ranges: %u\n", info->nb_ranges);
8277 	for (i = 0; i < info->nb_ranges; i++) {
8278 		range = &info->ranges[i];
8279 		range_diff = range->id_end - range->id_base;
8280 
8281 		printf("%u. ", i + 1);
8282 		printf("'%s' ", range->name);
8283 		if (range_diff > 0)
8284 			printf("[%u-%u]: ", range->id_base, range->id_end);
8285 		else
8286 			printf("[%u]: ", range->id_base);
8287 
8288 		printf("Controller %d, PF %d", range->controller, range->pf);
8289 
8290 		switch (range->type) {
8291 		case RTE_ETH_REPRESENTOR_NONE:
8292 			printf(", NONE\n");
8293 			break;
8294 		case RTE_ETH_REPRESENTOR_VF:
8295 			if (range_diff > 0)
8296 				printf(", VF %d..%d\n", range->vf,
8297 				       range->vf + range_diff);
8298 			else
8299 				printf(", VF %d\n", range->vf);
8300 			break;
8301 		case RTE_ETH_REPRESENTOR_SF:
8302 			printf(", SF %d\n", range->sf);
8303 			break;
8304 		case RTE_ETH_REPRESENTOR_PF:
8305 			if (range_diff > 0)
8306 				printf("..%d\n", range->pf + range_diff);
8307 			else
8308 				printf("\n");
8309 			break;
8310 		default:
8311 			printf(", UNKNOWN TYPE %d\n", range->type);
8312 			break;
8313 		}
8314 	}
8315 
8316 	free(info);
8317 }
8318 
8319 cmdline_parse_token_string_t cmd_representor_info_show =
8320 	TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8321 			cmd_show, "show");
8322 cmdline_parse_token_string_t cmd_representor_info_port =
8323 	TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8324 			cmd_port, "port");
8325 cmdline_parse_token_string_t cmd_representor_info_info =
8326 	TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8327 			cmd_info, "info");
8328 cmdline_parse_token_num_t cmd_representor_info_pid =
8329 	TOKEN_NUM_INITIALIZER(struct cmd_representor_info_result,
8330 			cmd_pid, RTE_UINT16);
8331 cmdline_parse_token_string_t cmd_representor_info_keyword =
8332 	TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8333 			cmd_keyword, "representor");
8334 
8335 cmdline_parse_inst_t cmd_representor_info = {
8336 	.f = cmd_representor_info_parsed,
8337 	.data = NULL,
8338 	.help_str = "show port info <port_id> representor",
8339 	.tokens = {
8340 		(void *)&cmd_representor_info_show,
8341 		(void *)&cmd_representor_info_port,
8342 		(void *)&cmd_representor_info_info,
8343 		(void *)&cmd_representor_info_pid,
8344 		(void *)&cmd_representor_info_keyword,
8345 		NULL,
8346 	},
8347 };
8348 
8349 
8350 /* *** SHOW DEVICE INFO *** */
8351 struct cmd_showdevice_result {
8352 	cmdline_fixed_string_t show;
8353 	cmdline_fixed_string_t device;
8354 	cmdline_fixed_string_t what;
8355 	cmdline_fixed_string_t identifier;
8356 };
8357 
8358 static void cmd_showdevice_parsed(void *parsed_result,
8359 				__rte_unused struct cmdline *cl,
8360 				__rte_unused void *data)
8361 {
8362 	struct cmd_showdevice_result *res = parsed_result;
8363 	if (!strcmp(res->what, "info")) {
8364 		if (!strcmp(res->identifier, "all"))
8365 			device_infos_display(NULL);
8366 		else
8367 			device_infos_display(res->identifier);
8368 	}
8369 }
8370 
8371 cmdline_parse_token_string_t cmd_showdevice_show =
8372 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
8373 				 "show");
8374 cmdline_parse_token_string_t cmd_showdevice_device =
8375 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
8376 cmdline_parse_token_string_t cmd_showdevice_what =
8377 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
8378 				 "info");
8379 cmdline_parse_token_string_t cmd_showdevice_identifier =
8380 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
8381 			identifier, NULL);
8382 
8383 cmdline_parse_inst_t cmd_showdevice = {
8384 	.f = cmd_showdevice_parsed,
8385 	.data = NULL,
8386 	.help_str = "show device info <identifier>|all",
8387 	.tokens = {
8388 		(void *)&cmd_showdevice_show,
8389 		(void *)&cmd_showdevice_device,
8390 		(void *)&cmd_showdevice_what,
8391 		(void *)&cmd_showdevice_identifier,
8392 		NULL,
8393 	},
8394 };
8395 
8396 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
8397 struct cmd_showeeprom_result {
8398 	cmdline_fixed_string_t show;
8399 	cmdline_fixed_string_t port;
8400 	uint16_t portnum;
8401 	cmdline_fixed_string_t type;
8402 };
8403 
8404 static void cmd_showeeprom_parsed(void *parsed_result,
8405 		__rte_unused struct cmdline *cl,
8406 		__rte_unused void *data)
8407 {
8408 	struct cmd_showeeprom_result *res = parsed_result;
8409 
8410 	if (!strcmp(res->type, "eeprom"))
8411 		port_eeprom_display(res->portnum);
8412 	else if (!strcmp(res->type, "module_eeprom"))
8413 		port_module_eeprom_display(res->portnum);
8414 	else
8415 		fprintf(stderr, "Unknown argument\n");
8416 }
8417 
8418 cmdline_parse_token_string_t cmd_showeeprom_show =
8419 	TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
8420 cmdline_parse_token_string_t cmd_showeeprom_port =
8421 	TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
8422 cmdline_parse_token_num_t cmd_showeeprom_portnum =
8423 	TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
8424 			RTE_UINT16);
8425 cmdline_parse_token_string_t cmd_showeeprom_type =
8426 	TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
8427 
8428 cmdline_parse_inst_t cmd_showeeprom = {
8429 	.f = cmd_showeeprom_parsed,
8430 	.data = NULL,
8431 	.help_str = "show port <port_id> module_eeprom|eeprom",
8432 	.tokens = {
8433 		(void *)&cmd_showeeprom_show,
8434 		(void *)&cmd_showeeprom_port,
8435 		(void *)&cmd_showeeprom_portnum,
8436 		(void *)&cmd_showeeprom_type,
8437 		NULL,
8438 	},
8439 };
8440 
8441 /* *** SHOW QUEUE INFO *** */
8442 struct cmd_showqueue_result {
8443 	cmdline_fixed_string_t show;
8444 	cmdline_fixed_string_t type;
8445 	cmdline_fixed_string_t what;
8446 	uint16_t portnum;
8447 	uint16_t queuenum;
8448 };
8449 
8450 static void
8451 cmd_showqueue_parsed(void *parsed_result,
8452 	__rte_unused struct cmdline *cl,
8453 	__rte_unused void *data)
8454 {
8455 	struct cmd_showqueue_result *res = parsed_result;
8456 
8457 	if (!strcmp(res->type, "rxq"))
8458 		rx_queue_infos_display(res->portnum, res->queuenum);
8459 	else if (!strcmp(res->type, "txq"))
8460 		tx_queue_infos_display(res->portnum, res->queuenum);
8461 }
8462 
8463 cmdline_parse_token_string_t cmd_showqueue_show =
8464 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
8465 cmdline_parse_token_string_t cmd_showqueue_type =
8466 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
8467 cmdline_parse_token_string_t cmd_showqueue_what =
8468 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
8469 cmdline_parse_token_num_t cmd_showqueue_portnum =
8470 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
8471 		RTE_UINT16);
8472 cmdline_parse_token_num_t cmd_showqueue_queuenum =
8473 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
8474 		RTE_UINT16);
8475 
8476 cmdline_parse_inst_t cmd_showqueue = {
8477 	.f = cmd_showqueue_parsed,
8478 	.data = NULL,
8479 	.help_str = "show rxq|txq info <port_id> <queue_id>",
8480 	.tokens = {
8481 		(void *)&cmd_showqueue_show,
8482 		(void *)&cmd_showqueue_type,
8483 		(void *)&cmd_showqueue_what,
8484 		(void *)&cmd_showqueue_portnum,
8485 		(void *)&cmd_showqueue_queuenum,
8486 		NULL,
8487 	},
8488 };
8489 
8490 /* show/clear fwd engine statistics */
8491 struct fwd_result {
8492 	cmdline_fixed_string_t action;
8493 	cmdline_fixed_string_t fwd;
8494 	cmdline_fixed_string_t stats;
8495 	cmdline_fixed_string_t all;
8496 };
8497 
8498 cmdline_parse_token_string_t cmd_fwd_action =
8499 	TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
8500 cmdline_parse_token_string_t cmd_fwd_fwd =
8501 	TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
8502 cmdline_parse_token_string_t cmd_fwd_stats =
8503 	TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
8504 cmdline_parse_token_string_t cmd_fwd_all =
8505 	TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
8506 
8507 static void
8508 cmd_showfwdall_parsed(void *parsed_result,
8509 		      __rte_unused struct cmdline *cl,
8510 		      __rte_unused void *data)
8511 {
8512 	struct fwd_result *res = parsed_result;
8513 
8514 	if (!strcmp(res->action, "show"))
8515 		fwd_stats_display();
8516 	else
8517 		fwd_stats_reset();
8518 }
8519 
8520 static cmdline_parse_inst_t cmd_showfwdall = {
8521 	.f = cmd_showfwdall_parsed,
8522 	.data = NULL,
8523 	.help_str = "show|clear fwd stats all",
8524 	.tokens = {
8525 		(void *)&cmd_fwd_action,
8526 		(void *)&cmd_fwd_fwd,
8527 		(void *)&cmd_fwd_stats,
8528 		(void *)&cmd_fwd_all,
8529 		NULL,
8530 	},
8531 };
8532 
8533 /* *** READ PORT REGISTER *** */
8534 struct cmd_read_reg_result {
8535 	cmdline_fixed_string_t read;
8536 	cmdline_fixed_string_t reg;
8537 	portid_t port_id;
8538 	uint32_t reg_off;
8539 };
8540 
8541 static void
8542 cmd_read_reg_parsed(void *parsed_result,
8543 		    __rte_unused struct cmdline *cl,
8544 		    __rte_unused void *data)
8545 {
8546 	struct cmd_read_reg_result *res = parsed_result;
8547 	port_reg_display(res->port_id, res->reg_off);
8548 }
8549 
8550 cmdline_parse_token_string_t cmd_read_reg_read =
8551 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8552 cmdline_parse_token_string_t cmd_read_reg_reg =
8553 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8554 cmdline_parse_token_num_t cmd_read_reg_port_id =
8555 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
8556 cmdline_parse_token_num_t cmd_read_reg_reg_off =
8557 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
8558 
8559 cmdline_parse_inst_t cmd_read_reg = {
8560 	.f = cmd_read_reg_parsed,
8561 	.data = NULL,
8562 	.help_str = "read reg <port_id> <reg_off>",
8563 	.tokens = {
8564 		(void *)&cmd_read_reg_read,
8565 		(void *)&cmd_read_reg_reg,
8566 		(void *)&cmd_read_reg_port_id,
8567 		(void *)&cmd_read_reg_reg_off,
8568 		NULL,
8569 	},
8570 };
8571 
8572 /* *** READ PORT REGISTER BIT FIELD *** */
8573 struct cmd_read_reg_bit_field_result {
8574 	cmdline_fixed_string_t read;
8575 	cmdline_fixed_string_t regfield;
8576 	portid_t port_id;
8577 	uint32_t reg_off;
8578 	uint8_t bit1_pos;
8579 	uint8_t bit2_pos;
8580 };
8581 
8582 static void
8583 cmd_read_reg_bit_field_parsed(void *parsed_result,
8584 			      __rte_unused struct cmdline *cl,
8585 			      __rte_unused void *data)
8586 {
8587 	struct cmd_read_reg_bit_field_result *res = parsed_result;
8588 	port_reg_bit_field_display(res->port_id, res->reg_off,
8589 				   res->bit1_pos, res->bit2_pos);
8590 }
8591 
8592 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8593 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8594 				 "read");
8595 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8596 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8597 				 regfield, "regfield");
8598 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8599 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8600 			      RTE_UINT16);
8601 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8602 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8603 			      RTE_UINT32);
8604 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8605 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8606 			      RTE_UINT8);
8607 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8608 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8609 			      RTE_UINT8);
8610 
8611 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8612 	.f = cmd_read_reg_bit_field_parsed,
8613 	.data = NULL,
8614 	.help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8615 	"Read register bit field between bit_x and bit_y included",
8616 	.tokens = {
8617 		(void *)&cmd_read_reg_bit_field_read,
8618 		(void *)&cmd_read_reg_bit_field_regfield,
8619 		(void *)&cmd_read_reg_bit_field_port_id,
8620 		(void *)&cmd_read_reg_bit_field_reg_off,
8621 		(void *)&cmd_read_reg_bit_field_bit1_pos,
8622 		(void *)&cmd_read_reg_bit_field_bit2_pos,
8623 		NULL,
8624 	},
8625 };
8626 
8627 /* *** READ PORT REGISTER BIT *** */
8628 struct cmd_read_reg_bit_result {
8629 	cmdline_fixed_string_t read;
8630 	cmdline_fixed_string_t regbit;
8631 	portid_t port_id;
8632 	uint32_t reg_off;
8633 	uint8_t bit_pos;
8634 };
8635 
8636 static void
8637 cmd_read_reg_bit_parsed(void *parsed_result,
8638 			__rte_unused struct cmdline *cl,
8639 			__rte_unused void *data)
8640 {
8641 	struct cmd_read_reg_bit_result *res = parsed_result;
8642 	port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8643 }
8644 
8645 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8646 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8647 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8648 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8649 				 regbit, "regbit");
8650 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8651 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
8652 				 RTE_UINT16);
8653 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8654 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
8655 				 RTE_UINT32);
8656 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8657 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
8658 				 RTE_UINT8);
8659 
8660 cmdline_parse_inst_t cmd_read_reg_bit = {
8661 	.f = cmd_read_reg_bit_parsed,
8662 	.data = NULL,
8663 	.help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8664 	.tokens = {
8665 		(void *)&cmd_read_reg_bit_read,
8666 		(void *)&cmd_read_reg_bit_regbit,
8667 		(void *)&cmd_read_reg_bit_port_id,
8668 		(void *)&cmd_read_reg_bit_reg_off,
8669 		(void *)&cmd_read_reg_bit_bit_pos,
8670 		NULL,
8671 	},
8672 };
8673 
8674 /* *** WRITE PORT REGISTER *** */
8675 struct cmd_write_reg_result {
8676 	cmdline_fixed_string_t write;
8677 	cmdline_fixed_string_t reg;
8678 	portid_t port_id;
8679 	uint32_t reg_off;
8680 	uint32_t value;
8681 };
8682 
8683 static void
8684 cmd_write_reg_parsed(void *parsed_result,
8685 		     __rte_unused struct cmdline *cl,
8686 		     __rte_unused void *data)
8687 {
8688 	struct cmd_write_reg_result *res = parsed_result;
8689 	port_reg_set(res->port_id, res->reg_off, res->value);
8690 }
8691 
8692 cmdline_parse_token_string_t cmd_write_reg_write =
8693 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8694 cmdline_parse_token_string_t cmd_write_reg_reg =
8695 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8696 cmdline_parse_token_num_t cmd_write_reg_port_id =
8697 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8698 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8699 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8700 cmdline_parse_token_num_t cmd_write_reg_value =
8701 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8702 
8703 cmdline_parse_inst_t cmd_write_reg = {
8704 	.f = cmd_write_reg_parsed,
8705 	.data = NULL,
8706 	.help_str = "write reg <port_id> <reg_off> <reg_value>",
8707 	.tokens = {
8708 		(void *)&cmd_write_reg_write,
8709 		(void *)&cmd_write_reg_reg,
8710 		(void *)&cmd_write_reg_port_id,
8711 		(void *)&cmd_write_reg_reg_off,
8712 		(void *)&cmd_write_reg_value,
8713 		NULL,
8714 	},
8715 };
8716 
8717 /* *** WRITE PORT REGISTER BIT FIELD *** */
8718 struct cmd_write_reg_bit_field_result {
8719 	cmdline_fixed_string_t write;
8720 	cmdline_fixed_string_t regfield;
8721 	portid_t port_id;
8722 	uint32_t reg_off;
8723 	uint8_t bit1_pos;
8724 	uint8_t bit2_pos;
8725 	uint32_t value;
8726 };
8727 
8728 static void
8729 cmd_write_reg_bit_field_parsed(void *parsed_result,
8730 			       __rte_unused struct cmdline *cl,
8731 			       __rte_unused void *data)
8732 {
8733 	struct cmd_write_reg_bit_field_result *res = parsed_result;
8734 	port_reg_bit_field_set(res->port_id, res->reg_off,
8735 			  res->bit1_pos, res->bit2_pos, res->value);
8736 }
8737 
8738 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8739 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8740 				 "write");
8741 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8742 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8743 				 regfield, "regfield");
8744 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8745 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8746 			      RTE_UINT16);
8747 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8748 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8749 			      RTE_UINT32);
8750 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8751 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8752 			      RTE_UINT8);
8753 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8754 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8755 			      RTE_UINT8);
8756 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8757 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8758 			      RTE_UINT32);
8759 
8760 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8761 	.f = cmd_write_reg_bit_field_parsed,
8762 	.data = NULL,
8763 	.help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8764 		"<reg_value>: "
8765 		"Set register bit field between bit_x and bit_y included",
8766 	.tokens = {
8767 		(void *)&cmd_write_reg_bit_field_write,
8768 		(void *)&cmd_write_reg_bit_field_regfield,
8769 		(void *)&cmd_write_reg_bit_field_port_id,
8770 		(void *)&cmd_write_reg_bit_field_reg_off,
8771 		(void *)&cmd_write_reg_bit_field_bit1_pos,
8772 		(void *)&cmd_write_reg_bit_field_bit2_pos,
8773 		(void *)&cmd_write_reg_bit_field_value,
8774 		NULL,
8775 	},
8776 };
8777 
8778 /* *** WRITE PORT REGISTER BIT *** */
8779 struct cmd_write_reg_bit_result {
8780 	cmdline_fixed_string_t write;
8781 	cmdline_fixed_string_t regbit;
8782 	portid_t port_id;
8783 	uint32_t reg_off;
8784 	uint8_t bit_pos;
8785 	uint8_t value;
8786 };
8787 
8788 static void
8789 cmd_write_reg_bit_parsed(void *parsed_result,
8790 			 __rte_unused struct cmdline *cl,
8791 			 __rte_unused void *data)
8792 {
8793 	struct cmd_write_reg_bit_result *res = parsed_result;
8794 	port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8795 }
8796 
8797 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8798 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8799 				 "write");
8800 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8801 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8802 				 regbit, "regbit");
8803 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8804 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8805 				 RTE_UINT16);
8806 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8807 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8808 				 RTE_UINT32);
8809 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8810 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8811 				 RTE_UINT8);
8812 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8813 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8814 				 RTE_UINT8);
8815 
8816 cmdline_parse_inst_t cmd_write_reg_bit = {
8817 	.f = cmd_write_reg_bit_parsed,
8818 	.data = NULL,
8819 	.help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8820 		"0 <= bit_x <= 31",
8821 	.tokens = {
8822 		(void *)&cmd_write_reg_bit_write,
8823 		(void *)&cmd_write_reg_bit_regbit,
8824 		(void *)&cmd_write_reg_bit_port_id,
8825 		(void *)&cmd_write_reg_bit_reg_off,
8826 		(void *)&cmd_write_reg_bit_bit_pos,
8827 		(void *)&cmd_write_reg_bit_value,
8828 		NULL,
8829 	},
8830 };
8831 
8832 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8833 struct cmd_read_rxd_txd_result {
8834 	cmdline_fixed_string_t read;
8835 	cmdline_fixed_string_t rxd_txd;
8836 	portid_t port_id;
8837 	uint16_t queue_id;
8838 	uint16_t desc_id;
8839 };
8840 
8841 static void
8842 cmd_read_rxd_txd_parsed(void *parsed_result,
8843 			__rte_unused struct cmdline *cl,
8844 			__rte_unused void *data)
8845 {
8846 	struct cmd_read_rxd_txd_result *res = parsed_result;
8847 
8848 	if (!strcmp(res->rxd_txd, "rxd"))
8849 		rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8850 	else if (!strcmp(res->rxd_txd, "txd"))
8851 		tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8852 }
8853 
8854 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8855 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8856 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8857 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8858 				 "rxd#txd");
8859 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8860 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8861 				 RTE_UINT16);
8862 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8863 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8864 				 RTE_UINT16);
8865 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8866 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8867 				 RTE_UINT16);
8868 
8869 cmdline_parse_inst_t cmd_read_rxd_txd = {
8870 	.f = cmd_read_rxd_txd_parsed,
8871 	.data = NULL,
8872 	.help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8873 	.tokens = {
8874 		(void *)&cmd_read_rxd_txd_read,
8875 		(void *)&cmd_read_rxd_txd_rxd_txd,
8876 		(void *)&cmd_read_rxd_txd_port_id,
8877 		(void *)&cmd_read_rxd_txd_queue_id,
8878 		(void *)&cmd_read_rxd_txd_desc_id,
8879 		NULL,
8880 	},
8881 };
8882 
8883 /* *** QUIT *** */
8884 struct cmd_quit_result {
8885 	cmdline_fixed_string_t quit;
8886 };
8887 
8888 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8889 			    struct cmdline *cl,
8890 			    __rte_unused void *data)
8891 {
8892 	cmdline_quit(cl);
8893 }
8894 
8895 cmdline_parse_token_string_t cmd_quit_quit =
8896 	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8897 
8898 cmdline_parse_inst_t cmd_quit = {
8899 	.f = cmd_quit_parsed,
8900 	.data = NULL,
8901 	.help_str = "quit: Exit application",
8902 	.tokens = {
8903 		(void *)&cmd_quit_quit,
8904 		NULL,
8905 	},
8906 };
8907 
8908 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8909 struct cmd_mac_addr_result {
8910 	cmdline_fixed_string_t mac_addr_cmd;
8911 	cmdline_fixed_string_t what;
8912 	uint16_t port_num;
8913 	struct rte_ether_addr address;
8914 };
8915 
8916 static void cmd_mac_addr_parsed(void *parsed_result,
8917 		__rte_unused struct cmdline *cl,
8918 		__rte_unused void *data)
8919 {
8920 	struct cmd_mac_addr_result *res = parsed_result;
8921 	int ret;
8922 
8923 	if (strcmp(res->what, "add") == 0)
8924 		ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8925 	else if (strcmp(res->what, "set") == 0)
8926 		ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8927 						       &res->address);
8928 	else
8929 		ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8930 
8931 	/* check the return value and print it if is < 0 */
8932 	if(ret < 0)
8933 		fprintf(stderr, "mac_addr_cmd error: (%s)\n", strerror(-ret));
8934 
8935 }
8936 
8937 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8938 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8939 				"mac_addr");
8940 cmdline_parse_token_string_t cmd_mac_addr_what =
8941 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8942 				"add#remove#set");
8943 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8944 		TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8945 					RTE_UINT16);
8946 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8947 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8948 
8949 cmdline_parse_inst_t cmd_mac_addr = {
8950 	.f = cmd_mac_addr_parsed,
8951 	.data = (void *)0,
8952 	.help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8953 			"Add/Remove/Set MAC address on port_id",
8954 	.tokens = {
8955 		(void *)&cmd_mac_addr_cmd,
8956 		(void *)&cmd_mac_addr_what,
8957 		(void *)&cmd_mac_addr_portnum,
8958 		(void *)&cmd_mac_addr_addr,
8959 		NULL,
8960 	},
8961 };
8962 
8963 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8964 struct cmd_eth_peer_result {
8965 	cmdline_fixed_string_t set;
8966 	cmdline_fixed_string_t eth_peer;
8967 	portid_t port_id;
8968 	cmdline_fixed_string_t peer_addr;
8969 };
8970 
8971 static void cmd_set_eth_peer_parsed(void *parsed_result,
8972 			__rte_unused struct cmdline *cl,
8973 			__rte_unused void *data)
8974 {
8975 		struct cmd_eth_peer_result *res = parsed_result;
8976 
8977 		if (test_done == 0) {
8978 			fprintf(stderr, "Please stop forwarding first\n");
8979 			return;
8980 		}
8981 		if (!strcmp(res->eth_peer, "eth-peer")) {
8982 			set_fwd_eth_peer(res->port_id, res->peer_addr);
8983 			fwd_config_setup();
8984 		}
8985 }
8986 cmdline_parse_token_string_t cmd_eth_peer_set =
8987 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8988 cmdline_parse_token_string_t cmd_eth_peer =
8989 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8990 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8991 	TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8992 		RTE_UINT16);
8993 cmdline_parse_token_string_t cmd_eth_peer_addr =
8994 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8995 
8996 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8997 	.f = cmd_set_eth_peer_parsed,
8998 	.data = NULL,
8999 	.help_str = "set eth-peer <port_id> <peer_mac>",
9000 	.tokens = {
9001 		(void *)&cmd_eth_peer_set,
9002 		(void *)&cmd_eth_peer,
9003 		(void *)&cmd_eth_peer_port_id,
9004 		(void *)&cmd_eth_peer_addr,
9005 		NULL,
9006 	},
9007 };
9008 
9009 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
9010 struct cmd_set_qmap_result {
9011 	cmdline_fixed_string_t set;
9012 	cmdline_fixed_string_t qmap;
9013 	cmdline_fixed_string_t what;
9014 	portid_t port_id;
9015 	uint16_t queue_id;
9016 	uint8_t map_value;
9017 };
9018 
9019 static void
9020 cmd_set_qmap_parsed(void *parsed_result,
9021 		       __rte_unused struct cmdline *cl,
9022 		       __rte_unused void *data)
9023 {
9024 	struct cmd_set_qmap_result *res = parsed_result;
9025 	int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
9026 
9027 	set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
9028 }
9029 
9030 cmdline_parse_token_string_t cmd_setqmap_set =
9031 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9032 				 set, "set");
9033 cmdline_parse_token_string_t cmd_setqmap_qmap =
9034 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9035 				 qmap, "stat_qmap");
9036 cmdline_parse_token_string_t cmd_setqmap_what =
9037 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9038 				 what, "tx#rx");
9039 cmdline_parse_token_num_t cmd_setqmap_portid =
9040 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9041 			      port_id, RTE_UINT16);
9042 cmdline_parse_token_num_t cmd_setqmap_queueid =
9043 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9044 			      queue_id, RTE_UINT16);
9045 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
9046 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9047 			      map_value, RTE_UINT8);
9048 
9049 cmdline_parse_inst_t cmd_set_qmap = {
9050 	.f = cmd_set_qmap_parsed,
9051 	.data = NULL,
9052 	.help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
9053 		"Set statistics mapping value on tx|rx queue_id of port_id",
9054 	.tokens = {
9055 		(void *)&cmd_setqmap_set,
9056 		(void *)&cmd_setqmap_qmap,
9057 		(void *)&cmd_setqmap_what,
9058 		(void *)&cmd_setqmap_portid,
9059 		(void *)&cmd_setqmap_queueid,
9060 		(void *)&cmd_setqmap_mapvalue,
9061 		NULL,
9062 	},
9063 };
9064 
9065 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
9066 struct cmd_set_xstats_hide_zero_result {
9067 	cmdline_fixed_string_t keyword;
9068 	cmdline_fixed_string_t name;
9069 	cmdline_fixed_string_t on_off;
9070 };
9071 
9072 static void
9073 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
9074 			__rte_unused struct cmdline *cl,
9075 			__rte_unused void *data)
9076 {
9077 	struct cmd_set_xstats_hide_zero_result *res;
9078 	uint16_t on_off = 0;
9079 
9080 	res = parsed_result;
9081 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9082 	set_xstats_hide_zero(on_off);
9083 }
9084 
9085 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
9086 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9087 				 keyword, "set");
9088 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
9089 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9090 				 name, "xstats-hide-zero");
9091 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
9092 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9093 				 on_off, "on#off");
9094 
9095 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
9096 	.f = cmd_set_xstats_hide_zero_parsed,
9097 	.data = NULL,
9098 	.help_str = "set xstats-hide-zero on|off",
9099 	.tokens = {
9100 		(void *)&cmd_set_xstats_hide_zero_keyword,
9101 		(void *)&cmd_set_xstats_hide_zero_name,
9102 		(void *)&cmd_set_xstats_hide_zero_on_off,
9103 		NULL,
9104 	},
9105 };
9106 
9107 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
9108 struct cmd_set_record_core_cycles_result {
9109 	cmdline_fixed_string_t keyword;
9110 	cmdline_fixed_string_t name;
9111 	cmdline_fixed_string_t on_off;
9112 };
9113 
9114 static void
9115 cmd_set_record_core_cycles_parsed(void *parsed_result,
9116 			__rte_unused struct cmdline *cl,
9117 			__rte_unused void *data)
9118 {
9119 	struct cmd_set_record_core_cycles_result *res;
9120 	uint16_t on_off = 0;
9121 
9122 	res = parsed_result;
9123 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9124 	set_record_core_cycles(on_off);
9125 }
9126 
9127 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
9128 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9129 				 keyword, "set");
9130 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
9131 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9132 				 name, "record-core-cycles");
9133 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
9134 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9135 				 on_off, "on#off");
9136 
9137 cmdline_parse_inst_t cmd_set_record_core_cycles = {
9138 	.f = cmd_set_record_core_cycles_parsed,
9139 	.data = NULL,
9140 	.help_str = "set record-core-cycles on|off",
9141 	.tokens = {
9142 		(void *)&cmd_set_record_core_cycles_keyword,
9143 		(void *)&cmd_set_record_core_cycles_name,
9144 		(void *)&cmd_set_record_core_cycles_on_off,
9145 		NULL,
9146 	},
9147 };
9148 
9149 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
9150 struct cmd_set_record_burst_stats_result {
9151 	cmdline_fixed_string_t keyword;
9152 	cmdline_fixed_string_t name;
9153 	cmdline_fixed_string_t on_off;
9154 };
9155 
9156 static void
9157 cmd_set_record_burst_stats_parsed(void *parsed_result,
9158 			__rte_unused struct cmdline *cl,
9159 			__rte_unused void *data)
9160 {
9161 	struct cmd_set_record_burst_stats_result *res;
9162 	uint16_t on_off = 0;
9163 
9164 	res = parsed_result;
9165 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9166 	set_record_burst_stats(on_off);
9167 }
9168 
9169 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
9170 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9171 				 keyword, "set");
9172 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
9173 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9174 				 name, "record-burst-stats");
9175 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
9176 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9177 				 on_off, "on#off");
9178 
9179 cmdline_parse_inst_t cmd_set_record_burst_stats = {
9180 	.f = cmd_set_record_burst_stats_parsed,
9181 	.data = NULL,
9182 	.help_str = "set record-burst-stats on|off",
9183 	.tokens = {
9184 		(void *)&cmd_set_record_burst_stats_keyword,
9185 		(void *)&cmd_set_record_burst_stats_name,
9186 		(void *)&cmd_set_record_burst_stats_on_off,
9187 		NULL,
9188 	},
9189 };
9190 
9191 /* *** CONFIGURE UNICAST HASH TABLE *** */
9192 struct cmd_set_uc_hash_table {
9193 	cmdline_fixed_string_t set;
9194 	cmdline_fixed_string_t port;
9195 	portid_t port_id;
9196 	cmdline_fixed_string_t what;
9197 	struct rte_ether_addr address;
9198 	cmdline_fixed_string_t mode;
9199 };
9200 
9201 static void
9202 cmd_set_uc_hash_parsed(void *parsed_result,
9203 		       __rte_unused struct cmdline *cl,
9204 		       __rte_unused void *data)
9205 {
9206 	int ret=0;
9207 	struct cmd_set_uc_hash_table *res = parsed_result;
9208 
9209 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9210 
9211 	if (strcmp(res->what, "uta") == 0)
9212 		ret = rte_eth_dev_uc_hash_table_set(res->port_id,
9213 						&res->address,(uint8_t)is_on);
9214 	if (ret < 0)
9215 		fprintf(stderr,
9216 			"bad unicast hash table parameter, return code = %d\n",
9217 			ret);
9218 
9219 }
9220 
9221 cmdline_parse_token_string_t cmd_set_uc_hash_set =
9222 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9223 				 set, "set");
9224 cmdline_parse_token_string_t cmd_set_uc_hash_port =
9225 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9226 				 port, "port");
9227 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
9228 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
9229 			      port_id, RTE_UINT16);
9230 cmdline_parse_token_string_t cmd_set_uc_hash_what =
9231 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9232 				 what, "uta");
9233 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
9234 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
9235 				address);
9236 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
9237 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9238 				 mode, "on#off");
9239 
9240 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
9241 	.f = cmd_set_uc_hash_parsed,
9242 	.data = NULL,
9243 	.help_str = "set port <port_id> uta <mac_addr> on|off)",
9244 	.tokens = {
9245 		(void *)&cmd_set_uc_hash_set,
9246 		(void *)&cmd_set_uc_hash_port,
9247 		(void *)&cmd_set_uc_hash_portid,
9248 		(void *)&cmd_set_uc_hash_what,
9249 		(void *)&cmd_set_uc_hash_mac,
9250 		(void *)&cmd_set_uc_hash_mode,
9251 		NULL,
9252 	},
9253 };
9254 
9255 struct cmd_set_uc_all_hash_table {
9256 	cmdline_fixed_string_t set;
9257 	cmdline_fixed_string_t port;
9258 	portid_t port_id;
9259 	cmdline_fixed_string_t what;
9260 	cmdline_fixed_string_t value;
9261 	cmdline_fixed_string_t mode;
9262 };
9263 
9264 static void
9265 cmd_set_uc_all_hash_parsed(void *parsed_result,
9266 		       __rte_unused struct cmdline *cl,
9267 		       __rte_unused void *data)
9268 {
9269 	int ret=0;
9270 	struct cmd_set_uc_all_hash_table *res = parsed_result;
9271 
9272 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9273 
9274 	if ((strcmp(res->what, "uta") == 0) &&
9275 		(strcmp(res->value, "all") == 0))
9276 		ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
9277 	if (ret < 0)
9278 		fprintf(stderr,
9279 			"bad unicast hash table parameter, return code = %d\n",
9280 			ret);
9281 }
9282 
9283 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
9284 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9285 				 set, "set");
9286 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
9287 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9288 				 port, "port");
9289 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
9290 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
9291 			      port_id, RTE_UINT16);
9292 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
9293 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9294 				 what, "uta");
9295 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
9296 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9297 				value,"all");
9298 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
9299 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9300 				 mode, "on#off");
9301 
9302 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
9303 	.f = cmd_set_uc_all_hash_parsed,
9304 	.data = NULL,
9305 	.help_str = "set port <port_id> uta all on|off",
9306 	.tokens = {
9307 		(void *)&cmd_set_uc_all_hash_set,
9308 		(void *)&cmd_set_uc_all_hash_port,
9309 		(void *)&cmd_set_uc_all_hash_portid,
9310 		(void *)&cmd_set_uc_all_hash_what,
9311 		(void *)&cmd_set_uc_all_hash_value,
9312 		(void *)&cmd_set_uc_all_hash_mode,
9313 		NULL,
9314 	},
9315 };
9316 
9317 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
9318 struct cmd_set_vf_traffic {
9319 	cmdline_fixed_string_t set;
9320 	cmdline_fixed_string_t port;
9321 	portid_t port_id;
9322 	cmdline_fixed_string_t vf;
9323 	uint8_t vf_id;
9324 	cmdline_fixed_string_t what;
9325 	cmdline_fixed_string_t mode;
9326 };
9327 
9328 static void
9329 cmd_set_vf_traffic_parsed(void *parsed_result,
9330 		       __rte_unused struct cmdline *cl,
9331 		       __rte_unused void *data)
9332 {
9333 	struct cmd_set_vf_traffic *res = parsed_result;
9334 	int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
9335 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9336 
9337 	set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
9338 }
9339 
9340 cmdline_parse_token_string_t cmd_setvf_traffic_set =
9341 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9342 				 set, "set");
9343 cmdline_parse_token_string_t cmd_setvf_traffic_port =
9344 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9345 				 port, "port");
9346 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
9347 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9348 			      port_id, RTE_UINT16);
9349 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
9350 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9351 				 vf, "vf");
9352 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
9353 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9354 			      vf_id, RTE_UINT8);
9355 cmdline_parse_token_string_t cmd_setvf_traffic_what =
9356 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9357 				 what, "tx#rx");
9358 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
9359 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9360 				 mode, "on#off");
9361 
9362 cmdline_parse_inst_t cmd_set_vf_traffic = {
9363 	.f = cmd_set_vf_traffic_parsed,
9364 	.data = NULL,
9365 	.help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
9366 	.tokens = {
9367 		(void *)&cmd_setvf_traffic_set,
9368 		(void *)&cmd_setvf_traffic_port,
9369 		(void *)&cmd_setvf_traffic_portid,
9370 		(void *)&cmd_setvf_traffic_vf,
9371 		(void *)&cmd_setvf_traffic_vfid,
9372 		(void *)&cmd_setvf_traffic_what,
9373 		(void *)&cmd_setvf_traffic_mode,
9374 		NULL,
9375 	},
9376 };
9377 
9378 /* *** CONFIGURE VF RECEIVE MODE *** */
9379 struct cmd_set_vf_rxmode {
9380 	cmdline_fixed_string_t set;
9381 	cmdline_fixed_string_t port;
9382 	portid_t port_id;
9383 	cmdline_fixed_string_t vf;
9384 	uint8_t vf_id;
9385 	cmdline_fixed_string_t what;
9386 	cmdline_fixed_string_t mode;
9387 	cmdline_fixed_string_t on;
9388 };
9389 
9390 static void
9391 cmd_set_vf_rxmode_parsed(void *parsed_result,
9392 		       __rte_unused struct cmdline *cl,
9393 		       __rte_unused void *data)
9394 {
9395 	int ret = -ENOTSUP;
9396 	uint16_t vf_rxmode = 0;
9397 	struct cmd_set_vf_rxmode *res = parsed_result;
9398 
9399 	int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
9400 	if (!strcmp(res->what,"rxmode")) {
9401 		if (!strcmp(res->mode, "AUPE"))
9402 			vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_UNTAG;
9403 		else if (!strcmp(res->mode, "ROPE"))
9404 			vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_HASH_UC;
9405 		else if (!strcmp(res->mode, "BAM"))
9406 			vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_BROADCAST;
9407 		else if (!strncmp(res->mode, "MPE",3))
9408 			vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_MULTICAST;
9409 	}
9410 
9411 	RTE_SET_USED(is_on);
9412 
9413 #ifdef RTE_NET_IXGBE
9414 	if (ret == -ENOTSUP)
9415 		ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
9416 						  vf_rxmode, (uint8_t)is_on);
9417 #endif
9418 #ifdef RTE_NET_BNXT
9419 	if (ret == -ENOTSUP)
9420 		ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
9421 						 vf_rxmode, (uint8_t)is_on);
9422 #endif
9423 	if (ret < 0)
9424 		fprintf(stderr,
9425 			"bad VF receive mode parameter, return code = %d\n",
9426 			ret);
9427 }
9428 
9429 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
9430 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9431 				 set, "set");
9432 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
9433 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9434 				 port, "port");
9435 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
9436 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9437 			      port_id, RTE_UINT16);
9438 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
9439 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9440 				 vf, "vf");
9441 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
9442 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9443 			      vf_id, RTE_UINT8);
9444 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
9445 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9446 				 what, "rxmode");
9447 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
9448 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9449 				 mode, "AUPE#ROPE#BAM#MPE");
9450 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
9451 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9452 				 on, "on#off");
9453 
9454 cmdline_parse_inst_t cmd_set_vf_rxmode = {
9455 	.f = cmd_set_vf_rxmode_parsed,
9456 	.data = NULL,
9457 	.help_str = "set port <port_id> vf <vf_id> rxmode "
9458 		"AUPE|ROPE|BAM|MPE on|off",
9459 	.tokens = {
9460 		(void *)&cmd_set_vf_rxmode_set,
9461 		(void *)&cmd_set_vf_rxmode_port,
9462 		(void *)&cmd_set_vf_rxmode_portid,
9463 		(void *)&cmd_set_vf_rxmode_vf,
9464 		(void *)&cmd_set_vf_rxmode_vfid,
9465 		(void *)&cmd_set_vf_rxmode_what,
9466 		(void *)&cmd_set_vf_rxmode_mode,
9467 		(void *)&cmd_set_vf_rxmode_on,
9468 		NULL,
9469 	},
9470 };
9471 
9472 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
9473 struct cmd_vf_mac_addr_result {
9474 	cmdline_fixed_string_t mac_addr_cmd;
9475 	cmdline_fixed_string_t what;
9476 	cmdline_fixed_string_t port;
9477 	uint16_t port_num;
9478 	cmdline_fixed_string_t vf;
9479 	uint8_t vf_num;
9480 	struct rte_ether_addr address;
9481 };
9482 
9483 static void cmd_vf_mac_addr_parsed(void *parsed_result,
9484 		__rte_unused struct cmdline *cl,
9485 		__rte_unused void *data)
9486 {
9487 	struct cmd_vf_mac_addr_result *res = parsed_result;
9488 	int ret = -ENOTSUP;
9489 
9490 	if (strcmp(res->what, "add") != 0)
9491 		return;
9492 
9493 #ifdef RTE_NET_I40E
9494 	if (ret == -ENOTSUP)
9495 		ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
9496 						   &res->address);
9497 #endif
9498 #ifdef RTE_NET_BNXT
9499 	if (ret == -ENOTSUP)
9500 		ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
9501 						res->vf_num);
9502 #endif
9503 
9504 	if(ret < 0)
9505 		fprintf(stderr, "vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
9506 
9507 }
9508 
9509 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
9510 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9511 				mac_addr_cmd,"mac_addr");
9512 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
9513 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9514 				what,"add");
9515 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
9516 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9517 				port,"port");
9518 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
9519 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9520 				port_num, RTE_UINT16);
9521 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
9522 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9523 				vf,"vf");
9524 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
9525 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9526 				vf_num, RTE_UINT8);
9527 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
9528 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
9529 				address);
9530 
9531 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
9532 	.f = cmd_vf_mac_addr_parsed,
9533 	.data = (void *)0,
9534 	.help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
9535 		"Add MAC address filtering for a VF on port_id",
9536 	.tokens = {
9537 		(void *)&cmd_vf_mac_addr_cmd,
9538 		(void *)&cmd_vf_mac_addr_what,
9539 		(void *)&cmd_vf_mac_addr_port,
9540 		(void *)&cmd_vf_mac_addr_portnum,
9541 		(void *)&cmd_vf_mac_addr_vf,
9542 		(void *)&cmd_vf_mac_addr_vfnum,
9543 		(void *)&cmd_vf_mac_addr_addr,
9544 		NULL,
9545 	},
9546 };
9547 
9548 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
9549 struct cmd_vf_rx_vlan_filter {
9550 	cmdline_fixed_string_t rx_vlan;
9551 	cmdline_fixed_string_t what;
9552 	uint16_t vlan_id;
9553 	cmdline_fixed_string_t port;
9554 	portid_t port_id;
9555 	cmdline_fixed_string_t vf;
9556 	uint64_t vf_mask;
9557 };
9558 
9559 static void
9560 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
9561 			  __rte_unused struct cmdline *cl,
9562 			  __rte_unused void *data)
9563 {
9564 	struct cmd_vf_rx_vlan_filter *res = parsed_result;
9565 	int ret = -ENOTSUP;
9566 
9567 	__rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9568 
9569 #ifdef RTE_NET_IXGBE
9570 	if (ret == -ENOTSUP)
9571 		ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9572 				res->vlan_id, res->vf_mask, is_add);
9573 #endif
9574 #ifdef RTE_NET_I40E
9575 	if (ret == -ENOTSUP)
9576 		ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9577 				res->vlan_id, res->vf_mask, is_add);
9578 #endif
9579 #ifdef RTE_NET_BNXT
9580 	if (ret == -ENOTSUP)
9581 		ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9582 				res->vlan_id, res->vf_mask, is_add);
9583 #endif
9584 
9585 	switch (ret) {
9586 	case 0:
9587 		break;
9588 	case -EINVAL:
9589 		fprintf(stderr, "invalid vlan_id %d or vf_mask %"PRIu64"\n",
9590 			res->vlan_id, res->vf_mask);
9591 		break;
9592 	case -ENODEV:
9593 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
9594 		break;
9595 	case -ENOTSUP:
9596 		fprintf(stderr, "function not implemented or supported\n");
9597 		break;
9598 	default:
9599 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
9600 	}
9601 }
9602 
9603 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9604 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9605 				 rx_vlan, "rx_vlan");
9606 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9607 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9608 				 what, "add#rm");
9609 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9610 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9611 			      vlan_id, RTE_UINT16);
9612 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9613 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9614 				 port, "port");
9615 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9616 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9617 			      port_id, RTE_UINT16);
9618 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9619 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9620 				 vf, "vf");
9621 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9622 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9623 			      vf_mask, RTE_UINT64);
9624 
9625 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9626 	.f = cmd_vf_rx_vlan_filter_parsed,
9627 	.data = NULL,
9628 	.help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9629 		"(vf_mask = hexadecimal VF mask)",
9630 	.tokens = {
9631 		(void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9632 		(void *)&cmd_vf_rx_vlan_filter_what,
9633 		(void *)&cmd_vf_rx_vlan_filter_vlanid,
9634 		(void *)&cmd_vf_rx_vlan_filter_port,
9635 		(void *)&cmd_vf_rx_vlan_filter_portid,
9636 		(void *)&cmd_vf_rx_vlan_filter_vf,
9637 		(void *)&cmd_vf_rx_vlan_filter_vf_mask,
9638 		NULL,
9639 	},
9640 };
9641 
9642 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9643 struct cmd_queue_rate_limit_result {
9644 	cmdline_fixed_string_t set;
9645 	cmdline_fixed_string_t port;
9646 	uint16_t port_num;
9647 	cmdline_fixed_string_t queue;
9648 	uint8_t queue_num;
9649 	cmdline_fixed_string_t rate;
9650 	uint16_t rate_num;
9651 };
9652 
9653 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9654 		__rte_unused struct cmdline *cl,
9655 		__rte_unused void *data)
9656 {
9657 	struct cmd_queue_rate_limit_result *res = parsed_result;
9658 	int ret = 0;
9659 
9660 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9661 		&& (strcmp(res->queue, "queue") == 0)
9662 		&& (strcmp(res->rate, "rate") == 0))
9663 		ret = set_queue_rate_limit(res->port_num, res->queue_num,
9664 					res->rate_num);
9665 	if (ret < 0)
9666 		fprintf(stderr, "queue_rate_limit_cmd error: (%s)\n",
9667 			strerror(-ret));
9668 
9669 }
9670 
9671 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9672 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9673 				set, "set");
9674 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9675 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9676 				port, "port");
9677 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9678 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9679 				port_num, RTE_UINT16);
9680 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9681 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9682 				queue, "queue");
9683 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9684 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9685 				queue_num, RTE_UINT8);
9686 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9687 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9688 				rate, "rate");
9689 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9690 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9691 				rate_num, RTE_UINT16);
9692 
9693 cmdline_parse_inst_t cmd_queue_rate_limit = {
9694 	.f = cmd_queue_rate_limit_parsed,
9695 	.data = (void *)0,
9696 	.help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9697 		"Set rate limit for a queue on port_id",
9698 	.tokens = {
9699 		(void *)&cmd_queue_rate_limit_set,
9700 		(void *)&cmd_queue_rate_limit_port,
9701 		(void *)&cmd_queue_rate_limit_portnum,
9702 		(void *)&cmd_queue_rate_limit_queue,
9703 		(void *)&cmd_queue_rate_limit_queuenum,
9704 		(void *)&cmd_queue_rate_limit_rate,
9705 		(void *)&cmd_queue_rate_limit_ratenum,
9706 		NULL,
9707 	},
9708 };
9709 
9710 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9711 struct cmd_vf_rate_limit_result {
9712 	cmdline_fixed_string_t set;
9713 	cmdline_fixed_string_t port;
9714 	uint16_t port_num;
9715 	cmdline_fixed_string_t vf;
9716 	uint8_t vf_num;
9717 	cmdline_fixed_string_t rate;
9718 	uint16_t rate_num;
9719 	cmdline_fixed_string_t q_msk;
9720 	uint64_t q_msk_val;
9721 };
9722 
9723 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9724 		__rte_unused struct cmdline *cl,
9725 		__rte_unused void *data)
9726 {
9727 	struct cmd_vf_rate_limit_result *res = parsed_result;
9728 	int ret = 0;
9729 
9730 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9731 		&& (strcmp(res->vf, "vf") == 0)
9732 		&& (strcmp(res->rate, "rate") == 0)
9733 		&& (strcmp(res->q_msk, "queue_mask") == 0))
9734 		ret = set_vf_rate_limit(res->port_num, res->vf_num,
9735 					res->rate_num, res->q_msk_val);
9736 	if (ret < 0)
9737 		fprintf(stderr, "vf_rate_limit_cmd error: (%s)\n",
9738 			strerror(-ret));
9739 
9740 }
9741 
9742 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9743 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9744 				set, "set");
9745 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9746 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9747 				port, "port");
9748 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9749 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9750 				port_num, RTE_UINT16);
9751 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9752 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9753 				vf, "vf");
9754 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9755 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9756 				vf_num, RTE_UINT8);
9757 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9758 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9759 				rate, "rate");
9760 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9761 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9762 				rate_num, RTE_UINT16);
9763 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9764 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9765 				q_msk, "queue_mask");
9766 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9767 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9768 				q_msk_val, RTE_UINT64);
9769 
9770 cmdline_parse_inst_t cmd_vf_rate_limit = {
9771 	.f = cmd_vf_rate_limit_parsed,
9772 	.data = (void *)0,
9773 	.help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9774 		"queue_mask <queue_mask_value>: "
9775 		"Set rate limit for queues of VF on port_id",
9776 	.tokens = {
9777 		(void *)&cmd_vf_rate_limit_set,
9778 		(void *)&cmd_vf_rate_limit_port,
9779 		(void *)&cmd_vf_rate_limit_portnum,
9780 		(void *)&cmd_vf_rate_limit_vf,
9781 		(void *)&cmd_vf_rate_limit_vfnum,
9782 		(void *)&cmd_vf_rate_limit_rate,
9783 		(void *)&cmd_vf_rate_limit_ratenum,
9784 		(void *)&cmd_vf_rate_limit_q_msk,
9785 		(void *)&cmd_vf_rate_limit_q_msk_val,
9786 		NULL,
9787 	},
9788 };
9789 
9790 /* *** CONFIGURE TUNNEL UDP PORT *** */
9791 struct cmd_tunnel_udp_config {
9792 	cmdline_fixed_string_t rx_vxlan_port;
9793 	cmdline_fixed_string_t what;
9794 	uint16_t udp_port;
9795 	portid_t port_id;
9796 };
9797 
9798 static void
9799 cmd_tunnel_udp_config_parsed(void *parsed_result,
9800 			  __rte_unused struct cmdline *cl,
9801 			  __rte_unused void *data)
9802 {
9803 	struct cmd_tunnel_udp_config *res = parsed_result;
9804 	struct rte_eth_udp_tunnel tunnel_udp;
9805 	int ret;
9806 
9807 	tunnel_udp.udp_port = res->udp_port;
9808 	tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9809 
9810 	if (!strcmp(res->what, "add"))
9811 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9812 						      &tunnel_udp);
9813 	else
9814 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9815 							 &tunnel_udp);
9816 
9817 	if (ret < 0)
9818 		fprintf(stderr, "udp tunneling add error: (%s)\n",
9819 			strerror(-ret));
9820 }
9821 
9822 cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
9823 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9824 				rx_vxlan_port, "rx_vxlan_port");
9825 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9826 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9827 				what, "add#rm");
9828 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9829 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9830 				udp_port, RTE_UINT16);
9831 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9832 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9833 				port_id, RTE_UINT16);
9834 
9835 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9836 	.f = cmd_tunnel_udp_config_parsed,
9837 	.data = (void *)0,
9838 	.help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9839 		"Add/Remove a tunneling UDP port filter",
9840 	.tokens = {
9841 		(void *)&cmd_tunnel_udp_config_rx_vxlan_port,
9842 		(void *)&cmd_tunnel_udp_config_what,
9843 		(void *)&cmd_tunnel_udp_config_udp_port,
9844 		(void *)&cmd_tunnel_udp_config_port_id,
9845 		NULL,
9846 	},
9847 };
9848 
9849 struct cmd_config_tunnel_udp_port {
9850 	cmdline_fixed_string_t port;
9851 	cmdline_fixed_string_t config;
9852 	portid_t port_id;
9853 	cmdline_fixed_string_t udp_tunnel_port;
9854 	cmdline_fixed_string_t action;
9855 	cmdline_fixed_string_t tunnel_type;
9856 	uint16_t udp_port;
9857 };
9858 
9859 static void
9860 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9861 			       __rte_unused struct cmdline *cl,
9862 			       __rte_unused void *data)
9863 {
9864 	struct cmd_config_tunnel_udp_port *res = parsed_result;
9865 	struct rte_eth_udp_tunnel tunnel_udp;
9866 	int ret = 0;
9867 
9868 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9869 		return;
9870 
9871 	tunnel_udp.udp_port = res->udp_port;
9872 
9873 	if (!strcmp(res->tunnel_type, "vxlan")) {
9874 		tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9875 	} else if (!strcmp(res->tunnel_type, "geneve")) {
9876 		tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_GENEVE;
9877 	} else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9878 		tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN_GPE;
9879 	} else if (!strcmp(res->tunnel_type, "ecpri")) {
9880 		tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_ECPRI;
9881 	} else {
9882 		fprintf(stderr, "Invalid tunnel type\n");
9883 		return;
9884 	}
9885 
9886 	if (!strcmp(res->action, "add"))
9887 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9888 						      &tunnel_udp);
9889 	else
9890 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9891 							 &tunnel_udp);
9892 
9893 	if (ret < 0)
9894 		fprintf(stderr, "udp tunneling port add error: (%s)\n",
9895 			strerror(-ret));
9896 }
9897 
9898 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9899 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9900 				 "port");
9901 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9902 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9903 				 "config");
9904 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9905 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9906 			      RTE_UINT16);
9907 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9908 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9909 				 udp_tunnel_port,
9910 				 "udp_tunnel_port");
9911 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9912 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9913 				 "add#rm");
9914 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9915 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9916 				 "vxlan#geneve#vxlan-gpe#ecpri");
9917 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9918 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9919 			      RTE_UINT16);
9920 
9921 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9922 	.f = cmd_cfg_tunnel_udp_port_parsed,
9923 	.data = NULL,
9924 	.help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9925 		"geneve|vxlan-gpe|ecpri <udp_port>",
9926 	.tokens = {
9927 		(void *)&cmd_config_tunnel_udp_port_port,
9928 		(void *)&cmd_config_tunnel_udp_port_config,
9929 		(void *)&cmd_config_tunnel_udp_port_port_id,
9930 		(void *)&cmd_config_tunnel_udp_port_tunnel_port,
9931 		(void *)&cmd_config_tunnel_udp_port_action,
9932 		(void *)&cmd_config_tunnel_udp_port_tunnel_type,
9933 		(void *)&cmd_config_tunnel_udp_port_value,
9934 		NULL,
9935 	},
9936 };
9937 
9938 /* ******************************************************************************** */
9939 
9940 struct cmd_dump_result {
9941 	cmdline_fixed_string_t dump;
9942 };
9943 
9944 static void
9945 dump_struct_sizes(void)
9946 {
9947 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9948 	DUMP_SIZE(struct rte_mbuf);
9949 	DUMP_SIZE(struct rte_mempool);
9950 	DUMP_SIZE(struct rte_ring);
9951 #undef DUMP_SIZE
9952 }
9953 
9954 
9955 /* Dump the socket memory statistics on console */
9956 static void
9957 dump_socket_mem(FILE *f)
9958 {
9959 	struct rte_malloc_socket_stats socket_stats;
9960 	unsigned int i;
9961 	size_t total = 0;
9962 	size_t alloc = 0;
9963 	size_t free = 0;
9964 	unsigned int n_alloc = 0;
9965 	unsigned int n_free = 0;
9966 	static size_t last_allocs;
9967 	static size_t last_total;
9968 
9969 
9970 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9971 		if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9972 		    !socket_stats.heap_totalsz_bytes)
9973 			continue;
9974 		total += socket_stats.heap_totalsz_bytes;
9975 		alloc += socket_stats.heap_allocsz_bytes;
9976 		free += socket_stats.heap_freesz_bytes;
9977 		n_alloc += socket_stats.alloc_count;
9978 		n_free += socket_stats.free_count;
9979 		fprintf(f,
9980 			"Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9981 			i,
9982 			(double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9983 			(double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9984 			(double)socket_stats.heap_allocsz_bytes * 100 /
9985 			(double)socket_stats.heap_totalsz_bytes,
9986 			(double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9987 			socket_stats.alloc_count,
9988 			socket_stats.free_count);
9989 	}
9990 	fprintf(f,
9991 		"Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9992 		(double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9993 		total ? ((double)alloc * 100 / (double)total) : 0,
9994 		(double)free / (1024 * 1024),
9995 		n_alloc, n_free);
9996 	if (last_allocs)
9997 		fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9998 			((double)total - (double)last_total) / (1024 * 1024),
9999 			(double)(alloc - (double)last_allocs) / 1024 / 1024);
10000 	last_allocs = alloc;
10001 	last_total = total;
10002 }
10003 
10004 static void cmd_dump_parsed(void *parsed_result,
10005 			    __rte_unused struct cmdline *cl,
10006 			    __rte_unused void *data)
10007 {
10008 	struct cmd_dump_result *res = parsed_result;
10009 
10010 	if (!strcmp(res->dump, "dump_physmem"))
10011 		rte_dump_physmem_layout(stdout);
10012 	else if (!strcmp(res->dump, "dump_socket_mem"))
10013 		dump_socket_mem(stdout);
10014 	else if (!strcmp(res->dump, "dump_memzone"))
10015 		rte_memzone_dump(stdout);
10016 	else if (!strcmp(res->dump, "dump_struct_sizes"))
10017 		dump_struct_sizes();
10018 	else if (!strcmp(res->dump, "dump_ring"))
10019 		rte_ring_list_dump(stdout);
10020 	else if (!strcmp(res->dump, "dump_mempool"))
10021 		rte_mempool_list_dump(stdout);
10022 	else if (!strcmp(res->dump, "dump_devargs"))
10023 		rte_devargs_dump(stdout);
10024 	else if (!strcmp(res->dump, "dump_log_types"))
10025 		rte_log_dump(stdout);
10026 }
10027 
10028 cmdline_parse_token_string_t cmd_dump_dump =
10029 	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
10030 		"dump_physmem#"
10031 		"dump_memzone#"
10032 		"dump_socket_mem#"
10033 		"dump_struct_sizes#"
10034 		"dump_ring#"
10035 		"dump_mempool#"
10036 		"dump_devargs#"
10037 		"dump_log_types");
10038 
10039 cmdline_parse_inst_t cmd_dump = {
10040 	.f = cmd_dump_parsed,  /* function to call */
10041 	.data = NULL,      /* 2nd arg of func */
10042 	.help_str = "Dump status",
10043 	.tokens = {        /* token list, NULL terminated */
10044 		(void *)&cmd_dump_dump,
10045 		NULL,
10046 	},
10047 };
10048 
10049 /* ******************************************************************************** */
10050 
10051 struct cmd_dump_one_result {
10052 	cmdline_fixed_string_t dump;
10053 	cmdline_fixed_string_t name;
10054 };
10055 
10056 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
10057 				__rte_unused void *data)
10058 {
10059 	struct cmd_dump_one_result *res = parsed_result;
10060 
10061 	if (!strcmp(res->dump, "dump_ring")) {
10062 		struct rte_ring *r;
10063 		r = rte_ring_lookup(res->name);
10064 		if (r == NULL) {
10065 			cmdline_printf(cl, "Cannot find ring\n");
10066 			return;
10067 		}
10068 		rte_ring_dump(stdout, r);
10069 	} else if (!strcmp(res->dump, "dump_mempool")) {
10070 		struct rte_mempool *mp;
10071 		mp = rte_mempool_lookup(res->name);
10072 		if (mp == NULL) {
10073 			cmdline_printf(cl, "Cannot find mempool\n");
10074 			return;
10075 		}
10076 		rte_mempool_dump(stdout, mp);
10077 	}
10078 }
10079 
10080 cmdline_parse_token_string_t cmd_dump_one_dump =
10081 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
10082 				 "dump_ring#dump_mempool");
10083 
10084 cmdline_parse_token_string_t cmd_dump_one_name =
10085 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
10086 
10087 cmdline_parse_inst_t cmd_dump_one = {
10088 	.f = cmd_dump_one_parsed,  /* function to call */
10089 	.data = NULL,      /* 2nd arg of func */
10090 	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
10091 	.tokens = {        /* token list, NULL terminated */
10092 		(void *)&cmd_dump_one_dump,
10093 		(void *)&cmd_dump_one_name,
10094 		NULL,
10095 	},
10096 };
10097 
10098 /* *** queue region set *** */
10099 struct cmd_queue_region_result {
10100 	cmdline_fixed_string_t set;
10101 	cmdline_fixed_string_t port;
10102 	portid_t port_id;
10103 	cmdline_fixed_string_t cmd;
10104 	cmdline_fixed_string_t region;
10105 	uint8_t  region_id;
10106 	cmdline_fixed_string_t queue_start_index;
10107 	uint8_t  queue_id;
10108 	cmdline_fixed_string_t queue_num;
10109 	uint8_t  queue_num_value;
10110 };
10111 
10112 static void
10113 cmd_queue_region_parsed(void *parsed_result,
10114 			__rte_unused struct cmdline *cl,
10115 			__rte_unused void *data)
10116 {
10117 	struct cmd_queue_region_result *res = parsed_result;
10118 	int ret = -ENOTSUP;
10119 #ifdef RTE_NET_I40E
10120 	struct rte_pmd_i40e_queue_region_conf region_conf;
10121 	enum rte_pmd_i40e_queue_region_op op_type;
10122 #endif
10123 
10124 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10125 		return;
10126 
10127 #ifdef RTE_NET_I40E
10128 	memset(&region_conf, 0, sizeof(region_conf));
10129 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10130 	region_conf.region_id = res->region_id;
10131 	region_conf.queue_num = res->queue_num_value;
10132 	region_conf.queue_start_index = res->queue_id;
10133 
10134 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10135 				op_type, &region_conf);
10136 #endif
10137 
10138 	switch (ret) {
10139 	case 0:
10140 		break;
10141 	case -ENOTSUP:
10142 		fprintf(stderr, "function not implemented or supported\n");
10143 		break;
10144 	default:
10145 		fprintf(stderr, "queue region config error: (%s)\n",
10146 			strerror(-ret));
10147 	}
10148 }
10149 
10150 cmdline_parse_token_string_t cmd_queue_region_set =
10151 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10152 		set, "set");
10153 cmdline_parse_token_string_t cmd_queue_region_port =
10154 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10155 cmdline_parse_token_num_t cmd_queue_region_port_id =
10156 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10157 				port_id, RTE_UINT16);
10158 cmdline_parse_token_string_t cmd_queue_region_cmd =
10159 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10160 				 cmd, "queue-region");
10161 cmdline_parse_token_string_t cmd_queue_region_id =
10162 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10163 				region, "region_id");
10164 cmdline_parse_token_num_t cmd_queue_region_index =
10165 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10166 				region_id, RTE_UINT8);
10167 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10168 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10169 				queue_start_index, "queue_start_index");
10170 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10171 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10172 				queue_id, RTE_UINT8);
10173 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10174 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10175 				queue_num, "queue_num");
10176 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10177 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10178 				queue_num_value, RTE_UINT8);
10179 
10180 cmdline_parse_inst_t cmd_queue_region = {
10181 	.f = cmd_queue_region_parsed,
10182 	.data = NULL,
10183 	.help_str = "set port <port_id> queue-region region_id <value> "
10184 		"queue_start_index <value> queue_num <value>: Set a queue region",
10185 	.tokens = {
10186 		(void *)&cmd_queue_region_set,
10187 		(void *)&cmd_queue_region_port,
10188 		(void *)&cmd_queue_region_port_id,
10189 		(void *)&cmd_queue_region_cmd,
10190 		(void *)&cmd_queue_region_id,
10191 		(void *)&cmd_queue_region_index,
10192 		(void *)&cmd_queue_region_queue_start_index,
10193 		(void *)&cmd_queue_region_queue_id,
10194 		(void *)&cmd_queue_region_queue_num,
10195 		(void *)&cmd_queue_region_queue_num_value,
10196 		NULL,
10197 	},
10198 };
10199 
10200 /* *** queue region and flowtype set *** */
10201 struct cmd_region_flowtype_result {
10202 	cmdline_fixed_string_t set;
10203 	cmdline_fixed_string_t port;
10204 	portid_t port_id;
10205 	cmdline_fixed_string_t cmd;
10206 	cmdline_fixed_string_t region;
10207 	uint8_t  region_id;
10208 	cmdline_fixed_string_t flowtype;
10209 	uint8_t  flowtype_id;
10210 };
10211 
10212 static void
10213 cmd_region_flowtype_parsed(void *parsed_result,
10214 			__rte_unused struct cmdline *cl,
10215 			__rte_unused void *data)
10216 {
10217 	struct cmd_region_flowtype_result *res = parsed_result;
10218 	int ret = -ENOTSUP;
10219 #ifdef RTE_NET_I40E
10220 	struct rte_pmd_i40e_queue_region_conf region_conf;
10221 	enum rte_pmd_i40e_queue_region_op op_type;
10222 #endif
10223 
10224 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10225 		return;
10226 
10227 #ifdef RTE_NET_I40E
10228 	memset(&region_conf, 0, sizeof(region_conf));
10229 
10230 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10231 	region_conf.region_id = res->region_id;
10232 	region_conf.hw_flowtype = res->flowtype_id;
10233 
10234 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10235 			op_type, &region_conf);
10236 #endif
10237 
10238 	switch (ret) {
10239 	case 0:
10240 		break;
10241 	case -ENOTSUP:
10242 		fprintf(stderr, "function not implemented or supported\n");
10243 		break;
10244 	default:
10245 		fprintf(stderr, "region flowtype config error: (%s)\n",
10246 			strerror(-ret));
10247 	}
10248 }
10249 
10250 cmdline_parse_token_string_t cmd_region_flowtype_set =
10251 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10252 				set, "set");
10253 cmdline_parse_token_string_t cmd_region_flowtype_port =
10254 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10255 				port, "port");
10256 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10257 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10258 				port_id, RTE_UINT16);
10259 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10260 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10261 				cmd, "queue-region");
10262 cmdline_parse_token_string_t cmd_region_flowtype_index =
10263 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10264 				region, "region_id");
10265 cmdline_parse_token_num_t cmd_region_flowtype_id =
10266 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10267 				region_id, RTE_UINT8);
10268 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10269 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10270 				flowtype, "flowtype");
10271 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10272 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10273 				flowtype_id, RTE_UINT8);
10274 cmdline_parse_inst_t cmd_region_flowtype = {
10275 	.f = cmd_region_flowtype_parsed,
10276 	.data = NULL,
10277 	.help_str = "set port <port_id> queue-region region_id <value> "
10278 		"flowtype <value>: Set a flowtype region index",
10279 	.tokens = {
10280 		(void *)&cmd_region_flowtype_set,
10281 		(void *)&cmd_region_flowtype_port,
10282 		(void *)&cmd_region_flowtype_port_index,
10283 		(void *)&cmd_region_flowtype_cmd,
10284 		(void *)&cmd_region_flowtype_index,
10285 		(void *)&cmd_region_flowtype_id,
10286 		(void *)&cmd_region_flowtype_flow_index,
10287 		(void *)&cmd_region_flowtype_flow_id,
10288 		NULL,
10289 	},
10290 };
10291 
10292 /* *** User Priority (UP) to queue region (region_id) set *** */
10293 struct cmd_user_priority_region_result {
10294 	cmdline_fixed_string_t set;
10295 	cmdline_fixed_string_t port;
10296 	portid_t port_id;
10297 	cmdline_fixed_string_t cmd;
10298 	cmdline_fixed_string_t user_priority;
10299 	uint8_t  user_priority_id;
10300 	cmdline_fixed_string_t region;
10301 	uint8_t  region_id;
10302 };
10303 
10304 static void
10305 cmd_user_priority_region_parsed(void *parsed_result,
10306 			__rte_unused struct cmdline *cl,
10307 			__rte_unused void *data)
10308 {
10309 	struct cmd_user_priority_region_result *res = parsed_result;
10310 	int ret = -ENOTSUP;
10311 #ifdef RTE_NET_I40E
10312 	struct rte_pmd_i40e_queue_region_conf region_conf;
10313 	enum rte_pmd_i40e_queue_region_op op_type;
10314 #endif
10315 
10316 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10317 		return;
10318 
10319 #ifdef RTE_NET_I40E
10320 	memset(&region_conf, 0, sizeof(region_conf));
10321 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10322 	region_conf.user_priority = res->user_priority_id;
10323 	region_conf.region_id = res->region_id;
10324 
10325 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10326 				op_type, &region_conf);
10327 #endif
10328 
10329 	switch (ret) {
10330 	case 0:
10331 		break;
10332 	case -ENOTSUP:
10333 		fprintf(stderr, "function not implemented or supported\n");
10334 		break;
10335 	default:
10336 		fprintf(stderr, "user_priority region config error: (%s)\n",
10337 			strerror(-ret));
10338 	}
10339 }
10340 
10341 cmdline_parse_token_string_t cmd_user_priority_region_set =
10342 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10343 				set, "set");
10344 cmdline_parse_token_string_t cmd_user_priority_region_port =
10345 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10346 				port, "port");
10347 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10348 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10349 				port_id, RTE_UINT16);
10350 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10351 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10352 				cmd, "queue-region");
10353 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10354 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10355 				user_priority, "UP");
10356 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10357 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10358 				user_priority_id, RTE_UINT8);
10359 cmdline_parse_token_string_t cmd_user_priority_region_region =
10360 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10361 				region, "region_id");
10362 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10363 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10364 				region_id, RTE_UINT8);
10365 
10366 cmdline_parse_inst_t cmd_user_priority_region = {
10367 	.f = cmd_user_priority_region_parsed,
10368 	.data = NULL,
10369 	.help_str = "set port <port_id> queue-region UP <value> "
10370 		"region_id <value>: Set the mapping of User Priority (UP) "
10371 		"to queue region (region_id) ",
10372 	.tokens = {
10373 		(void *)&cmd_user_priority_region_set,
10374 		(void *)&cmd_user_priority_region_port,
10375 		(void *)&cmd_user_priority_region_port_index,
10376 		(void *)&cmd_user_priority_region_cmd,
10377 		(void *)&cmd_user_priority_region_UP,
10378 		(void *)&cmd_user_priority_region_UP_id,
10379 		(void *)&cmd_user_priority_region_region,
10380 		(void *)&cmd_user_priority_region_region_id,
10381 		NULL,
10382 	},
10383 };
10384 
10385 /* *** flush all queue region related configuration *** */
10386 struct cmd_flush_queue_region_result {
10387 	cmdline_fixed_string_t set;
10388 	cmdline_fixed_string_t port;
10389 	portid_t port_id;
10390 	cmdline_fixed_string_t cmd;
10391 	cmdline_fixed_string_t flush;
10392 	cmdline_fixed_string_t what;
10393 };
10394 
10395 static void
10396 cmd_flush_queue_region_parsed(void *parsed_result,
10397 			__rte_unused struct cmdline *cl,
10398 			__rte_unused void *data)
10399 {
10400 	struct cmd_flush_queue_region_result *res = parsed_result;
10401 	int ret = -ENOTSUP;
10402 #ifdef RTE_NET_I40E
10403 	struct rte_pmd_i40e_queue_region_conf region_conf;
10404 	enum rte_pmd_i40e_queue_region_op op_type;
10405 #endif
10406 
10407 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10408 		return;
10409 
10410 #ifdef RTE_NET_I40E
10411 	memset(&region_conf, 0, sizeof(region_conf));
10412 
10413 	if (strcmp(res->what, "on") == 0)
10414 		op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10415 	else
10416 		op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10417 
10418 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10419 				op_type, &region_conf);
10420 #endif
10421 
10422 	switch (ret) {
10423 	case 0:
10424 		break;
10425 	case -ENOTSUP:
10426 		fprintf(stderr, "function not implemented or supported\n");
10427 		break;
10428 	default:
10429 		fprintf(stderr, "queue region config flush error: (%s)\n",
10430 			strerror(-ret));
10431 	}
10432 }
10433 
10434 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10435 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10436 				set, "set");
10437 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10438 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10439 				port, "port");
10440 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10441 	TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10442 				port_id, RTE_UINT16);
10443 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10444 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10445 				cmd, "queue-region");
10446 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10447 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10448 				flush, "flush");
10449 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10450 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10451 				what, "on#off");
10452 
10453 cmdline_parse_inst_t cmd_flush_queue_region = {
10454 	.f = cmd_flush_queue_region_parsed,
10455 	.data = NULL,
10456 	.help_str = "set port <port_id> queue-region flush on|off"
10457 		": flush all queue region related configuration",
10458 	.tokens = {
10459 		(void *)&cmd_flush_queue_region_set,
10460 		(void *)&cmd_flush_queue_region_port,
10461 		(void *)&cmd_flush_queue_region_port_index,
10462 		(void *)&cmd_flush_queue_region_cmd,
10463 		(void *)&cmd_flush_queue_region_flush,
10464 		(void *)&cmd_flush_queue_region_what,
10465 		NULL,
10466 	},
10467 };
10468 
10469 /* *** get all queue region related configuration info *** */
10470 struct cmd_show_queue_region_info {
10471 	cmdline_fixed_string_t show;
10472 	cmdline_fixed_string_t port;
10473 	portid_t port_id;
10474 	cmdline_fixed_string_t cmd;
10475 };
10476 
10477 static void
10478 cmd_show_queue_region_info_parsed(void *parsed_result,
10479 			__rte_unused struct cmdline *cl,
10480 			__rte_unused void *data)
10481 {
10482 	struct cmd_show_queue_region_info *res = parsed_result;
10483 	int ret = -ENOTSUP;
10484 #ifdef RTE_NET_I40E
10485 	struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10486 	enum rte_pmd_i40e_queue_region_op op_type;
10487 #endif
10488 
10489 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10490 		return;
10491 
10492 #ifdef RTE_NET_I40E
10493 	memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10494 
10495 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10496 
10497 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10498 					op_type, &rte_pmd_regions);
10499 
10500 	port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10501 #endif
10502 
10503 	switch (ret) {
10504 	case 0:
10505 		break;
10506 	case -ENOTSUP:
10507 		fprintf(stderr, "function not implemented or supported\n");
10508 		break;
10509 	default:
10510 		fprintf(stderr, "queue region config info show error: (%s)\n",
10511 			strerror(-ret));
10512 	}
10513 }
10514 
10515 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10516 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10517 				show, "show");
10518 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10519 	TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10520 				port, "port");
10521 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10522 	TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10523 				port_id, RTE_UINT16);
10524 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10525 	TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10526 				cmd, "queue-region");
10527 
10528 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10529 	.f = cmd_show_queue_region_info_parsed,
10530 	.data = NULL,
10531 	.help_str = "show port <port_id> queue-region"
10532 		": show all queue region related configuration info",
10533 	.tokens = {
10534 		(void *)&cmd_show_queue_region_info_get,
10535 		(void *)&cmd_show_queue_region_info_port,
10536 		(void *)&cmd_show_queue_region_info_port_index,
10537 		(void *)&cmd_show_queue_region_info_cmd,
10538 		NULL,
10539 	},
10540 };
10541 
10542 /* *** Filters Control *** */
10543 
10544 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10545 do { \
10546 	if ((ip_addr).family == AF_INET) \
10547 		(ip) = (ip_addr).addr.ipv4.s_addr; \
10548 	else { \
10549 		fprintf(stderr, "invalid parameter.\n"); \
10550 		return; \
10551 	} \
10552 } while (0)
10553 
10554 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10555 do { \
10556 	if ((ip_addr).family == AF_INET6) \
10557 		rte_memcpy(&(ip), \
10558 				 &((ip_addr).addr.ipv6), \
10559 				 sizeof(struct in6_addr)); \
10560 	else { \
10561 		fprintf(stderr, "invalid parameter.\n"); \
10562 		return; \
10563 	} \
10564 } while (0)
10565 
10566 #ifdef RTE_NET_I40E
10567 
10568 static uint16_t
10569 str2flowtype(char *string)
10570 {
10571 	uint8_t i = 0;
10572 	static const struct {
10573 		char str[32];
10574 		uint16_t type;
10575 	} flowtype_str[] = {
10576 		{"raw", RTE_ETH_FLOW_RAW},
10577 		{"ipv4", RTE_ETH_FLOW_IPV4},
10578 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10579 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10580 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10581 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10582 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10583 		{"ipv6", RTE_ETH_FLOW_IPV6},
10584 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10585 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10586 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10587 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10588 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10589 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10590 		{"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
10591 		{"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
10592 		{"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
10593 		{"gtpu", RTE_ETH_FLOW_GTPU},
10594 	};
10595 
10596 	for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10597 		if (!strcmp(flowtype_str[i].str, string))
10598 			return flowtype_str[i].type;
10599 	}
10600 
10601 	if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10602 		return (uint16_t)atoi(string);
10603 
10604 	return RTE_ETH_FLOW_UNKNOWN;
10605 }
10606 
10607 /* *** deal with flow director filter *** */
10608 struct cmd_flow_director_result {
10609 	cmdline_fixed_string_t flow_director_filter;
10610 	portid_t port_id;
10611 	cmdline_fixed_string_t mode;
10612 	cmdline_fixed_string_t mode_value;
10613 	cmdline_fixed_string_t ops;
10614 	cmdline_fixed_string_t flow;
10615 	cmdline_fixed_string_t flow_type;
10616 	cmdline_fixed_string_t drop;
10617 	cmdline_fixed_string_t queue;
10618 	uint16_t  queue_id;
10619 	cmdline_fixed_string_t fd_id;
10620 	uint32_t  fd_id_value;
10621 	cmdline_fixed_string_t packet;
10622 	char filepath[];
10623 };
10624 
10625 static void
10626 cmd_flow_director_filter_parsed(void *parsed_result,
10627 			  __rte_unused struct cmdline *cl,
10628 			  __rte_unused void *data)
10629 {
10630 	struct cmd_flow_director_result *res = parsed_result;
10631 	int ret = 0;
10632 	struct rte_pmd_i40e_flow_type_mapping
10633 			mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10634 	struct rte_pmd_i40e_pkt_template_conf conf;
10635 	uint16_t flow_type = str2flowtype(res->flow_type);
10636 	uint16_t i, port = res->port_id;
10637 	uint8_t add;
10638 
10639 	memset(&conf, 0, sizeof(conf));
10640 
10641 	if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10642 		fprintf(stderr, "Invalid flow type specified.\n");
10643 		return;
10644 	}
10645 	ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10646 						 mapping);
10647 	if (ret)
10648 		return;
10649 	if (mapping[flow_type].pctype == 0ULL) {
10650 		fprintf(stderr, "Invalid flow type specified.\n");
10651 		return;
10652 	}
10653 	for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10654 		if (mapping[flow_type].pctype & (1ULL << i)) {
10655 			conf.input.pctype = i;
10656 			break;
10657 		}
10658 	}
10659 
10660 	conf.input.packet = open_file(res->filepath,
10661 				&conf.input.length);
10662 	if (!conf.input.packet)
10663 		return;
10664 	if (!strcmp(res->drop, "drop"))
10665 		conf.action.behavior =
10666 			RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10667 	else
10668 		conf.action.behavior =
10669 			RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10670 	conf.action.report_status =
10671 			RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10672 	conf.action.rx_queue = res->queue_id;
10673 	conf.soft_id = res->fd_id_value;
10674 	add  = strcmp(res->ops, "del") ? 1 : 0;
10675 	ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10676 							&conf,
10677 							add);
10678 	if (ret < 0)
10679 		fprintf(stderr, "flow director config error: (%s)\n",
10680 			strerror(-ret));
10681 	close_file(conf.input.packet);
10682 }
10683 
10684 cmdline_parse_token_string_t cmd_flow_director_filter =
10685 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10686 				 flow_director_filter, "flow_director_filter");
10687 cmdline_parse_token_num_t cmd_flow_director_port_id =
10688 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10689 			      port_id, RTE_UINT16);
10690 cmdline_parse_token_string_t cmd_flow_director_ops =
10691 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10692 				 ops, "add#del#update");
10693 cmdline_parse_token_string_t cmd_flow_director_flow =
10694 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10695 				 flow, "flow");
10696 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10697 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10698 		flow_type, NULL);
10699 cmdline_parse_token_string_t cmd_flow_director_drop =
10700 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10701 				 drop, "drop#fwd");
10702 cmdline_parse_token_string_t cmd_flow_director_queue =
10703 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10704 				 queue, "queue");
10705 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10706 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10707 			      queue_id, RTE_UINT16);
10708 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10709 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10710 				 fd_id, "fd_id");
10711 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10712 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10713 			      fd_id_value, RTE_UINT32);
10714 
10715 cmdline_parse_token_string_t cmd_flow_director_mode =
10716 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10717 				 mode, "mode");
10718 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10719 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10720 				 mode_value, "raw");
10721 cmdline_parse_token_string_t cmd_flow_director_packet =
10722 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10723 				 packet, "packet");
10724 cmdline_parse_token_string_t cmd_flow_director_filepath =
10725 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10726 				 filepath, NULL);
10727 
10728 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10729 	.f = cmd_flow_director_filter_parsed,
10730 	.data = NULL,
10731 	.help_str = "flow_director_filter ... : Add or delete a raw flow "
10732 		"director entry on NIC",
10733 	.tokens = {
10734 		(void *)&cmd_flow_director_filter,
10735 		(void *)&cmd_flow_director_port_id,
10736 		(void *)&cmd_flow_director_mode,
10737 		(void *)&cmd_flow_director_mode_raw,
10738 		(void *)&cmd_flow_director_ops,
10739 		(void *)&cmd_flow_director_flow,
10740 		(void *)&cmd_flow_director_flow_type,
10741 		(void *)&cmd_flow_director_drop,
10742 		(void *)&cmd_flow_director_queue,
10743 		(void *)&cmd_flow_director_queue_id,
10744 		(void *)&cmd_flow_director_fd_id,
10745 		(void *)&cmd_flow_director_fd_id_value,
10746 		(void *)&cmd_flow_director_packet,
10747 		(void *)&cmd_flow_director_filepath,
10748 		NULL,
10749 	},
10750 };
10751 
10752 #endif /* RTE_NET_I40E */
10753 
10754 /* *** deal with flow director mask *** */
10755 struct cmd_flow_director_mask_result {
10756 	cmdline_fixed_string_t flow_director_mask;
10757 	portid_t port_id;
10758 	cmdline_fixed_string_t mode;
10759 	cmdline_fixed_string_t mode_value;
10760 	cmdline_fixed_string_t vlan;
10761 	uint16_t vlan_mask;
10762 	cmdline_fixed_string_t src_mask;
10763 	cmdline_ipaddr_t ipv4_src;
10764 	cmdline_ipaddr_t ipv6_src;
10765 	uint16_t port_src;
10766 	cmdline_fixed_string_t dst_mask;
10767 	cmdline_ipaddr_t ipv4_dst;
10768 	cmdline_ipaddr_t ipv6_dst;
10769 	uint16_t port_dst;
10770 	cmdline_fixed_string_t mac;
10771 	uint8_t mac_addr_byte_mask;
10772 	cmdline_fixed_string_t tunnel_id;
10773 	uint32_t tunnel_id_mask;
10774 	cmdline_fixed_string_t tunnel_type;
10775 	uint8_t tunnel_type_mask;
10776 };
10777 
10778 static void
10779 cmd_flow_director_mask_parsed(void *parsed_result,
10780 			  __rte_unused struct cmdline *cl,
10781 			  __rte_unused void *data)
10782 {
10783 	struct cmd_flow_director_mask_result *res = parsed_result;
10784 	struct rte_eth_fdir_masks *mask;
10785 	struct rte_port *port;
10786 
10787 	port = &ports[res->port_id];
10788 	/** Check if the port is not started **/
10789 	if (port->port_status != RTE_PORT_STOPPED) {
10790 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
10791 		return;
10792 	}
10793 
10794 	mask = &port->dev_conf.fdir_conf.mask;
10795 
10796 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10797 		if (strcmp(res->mode_value, "MAC-VLAN")) {
10798 			fprintf(stderr, "Please set mode to MAC-VLAN.\n");
10799 			return;
10800 		}
10801 
10802 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10803 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10804 		if (strcmp(res->mode_value, "Tunnel")) {
10805 			fprintf(stderr, "Please set mode to Tunnel.\n");
10806 			return;
10807 		}
10808 
10809 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10810 		mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10811 		mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10812 		mask->tunnel_type_mask = res->tunnel_type_mask;
10813 	} else {
10814 		if (strcmp(res->mode_value, "IP")) {
10815 			fprintf(stderr, "Please set mode to IP.\n");
10816 			return;
10817 		}
10818 
10819 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10820 		IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10821 		IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10822 		IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10823 		IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10824 		mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10825 		mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10826 	}
10827 
10828 	cmd_reconfig_device_queue(res->port_id, 1, 1);
10829 }
10830 
10831 cmdline_parse_token_string_t cmd_flow_director_mask =
10832 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10833 				 flow_director_mask, "flow_director_mask");
10834 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10835 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10836 			      port_id, RTE_UINT16);
10837 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10838 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10839 				 vlan, "vlan");
10840 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10841 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10842 			      vlan_mask, RTE_UINT16);
10843 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10844 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10845 				 src_mask, "src_mask");
10846 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10847 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10848 				 ipv4_src);
10849 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10850 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10851 				 ipv6_src);
10852 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10853 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10854 			      port_src, RTE_UINT16);
10855 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10856 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10857 				 dst_mask, "dst_mask");
10858 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10859 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10860 				 ipv4_dst);
10861 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10862 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10863 				 ipv6_dst);
10864 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10865 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10866 			      port_dst, RTE_UINT16);
10867 
10868 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10869 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10870 				 mode, "mode");
10871 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10872 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10873 				 mode_value, "IP");
10874 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10875 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10876 				 mode_value, "MAC-VLAN");
10877 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10878 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10879 				 mode_value, "Tunnel");
10880 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10881 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10882 				 mac, "mac");
10883 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10884 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10885 			      mac_addr_byte_mask, RTE_UINT8);
10886 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10887 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10888 				 tunnel_type, "tunnel-type");
10889 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10890 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10891 			      tunnel_type_mask, RTE_UINT8);
10892 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10893 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10894 				 tunnel_id, "tunnel-id");
10895 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10896 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10897 			      tunnel_id_mask, RTE_UINT32);
10898 
10899 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10900 	.f = cmd_flow_director_mask_parsed,
10901 	.data = NULL,
10902 	.help_str = "flow_director_mask ... : "
10903 		"Set IP mode flow director's mask on NIC",
10904 	.tokens = {
10905 		(void *)&cmd_flow_director_mask,
10906 		(void *)&cmd_flow_director_mask_port_id,
10907 		(void *)&cmd_flow_director_mask_mode,
10908 		(void *)&cmd_flow_director_mask_mode_ip,
10909 		(void *)&cmd_flow_director_mask_vlan,
10910 		(void *)&cmd_flow_director_mask_vlan_value,
10911 		(void *)&cmd_flow_director_mask_src,
10912 		(void *)&cmd_flow_director_mask_ipv4_src,
10913 		(void *)&cmd_flow_director_mask_ipv6_src,
10914 		(void *)&cmd_flow_director_mask_port_src,
10915 		(void *)&cmd_flow_director_mask_dst,
10916 		(void *)&cmd_flow_director_mask_ipv4_dst,
10917 		(void *)&cmd_flow_director_mask_ipv6_dst,
10918 		(void *)&cmd_flow_director_mask_port_dst,
10919 		NULL,
10920 	},
10921 };
10922 
10923 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10924 	.f = cmd_flow_director_mask_parsed,
10925 	.data = NULL,
10926 	.help_str = "flow_director_mask ... : Set MAC VLAN mode "
10927 		"flow director's mask on NIC",
10928 	.tokens = {
10929 		(void *)&cmd_flow_director_mask,
10930 		(void *)&cmd_flow_director_mask_port_id,
10931 		(void *)&cmd_flow_director_mask_mode,
10932 		(void *)&cmd_flow_director_mask_mode_mac_vlan,
10933 		(void *)&cmd_flow_director_mask_vlan,
10934 		(void *)&cmd_flow_director_mask_vlan_value,
10935 		NULL,
10936 	},
10937 };
10938 
10939 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10940 	.f = cmd_flow_director_mask_parsed,
10941 	.data = NULL,
10942 	.help_str = "flow_director_mask ... : Set tunnel mode "
10943 		"flow director's mask on NIC",
10944 	.tokens = {
10945 		(void *)&cmd_flow_director_mask,
10946 		(void *)&cmd_flow_director_mask_port_id,
10947 		(void *)&cmd_flow_director_mask_mode,
10948 		(void *)&cmd_flow_director_mask_mode_tunnel,
10949 		(void *)&cmd_flow_director_mask_vlan,
10950 		(void *)&cmd_flow_director_mask_vlan_value,
10951 		(void *)&cmd_flow_director_mask_mac,
10952 		(void *)&cmd_flow_director_mask_mac_value,
10953 		(void *)&cmd_flow_director_mask_tunnel_type,
10954 		(void *)&cmd_flow_director_mask_tunnel_type_value,
10955 		(void *)&cmd_flow_director_mask_tunnel_id,
10956 		(void *)&cmd_flow_director_mask_tunnel_id_value,
10957 		NULL,
10958 	},
10959 };
10960 
10961 /* *** deal with flow director flexible payload configuration *** */
10962 struct cmd_flow_director_flexpayload_result {
10963 	cmdline_fixed_string_t flow_director_flexpayload;
10964 	portid_t port_id;
10965 	cmdline_fixed_string_t payload_layer;
10966 	cmdline_fixed_string_t payload_cfg;
10967 };
10968 
10969 static inline int
10970 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10971 {
10972 	char s[256];
10973 	const char *p, *p0 = q_arg;
10974 	char *end;
10975 	unsigned long int_fld;
10976 	char *str_fld[max_num];
10977 	int i;
10978 	unsigned size;
10979 	int ret = -1;
10980 
10981 	p = strchr(p0, '(');
10982 	if (p == NULL)
10983 		return -1;
10984 	++p;
10985 	p0 = strchr(p, ')');
10986 	if (p0 == NULL)
10987 		return -1;
10988 
10989 	size = p0 - p;
10990 	if (size >= sizeof(s))
10991 		return -1;
10992 
10993 	snprintf(s, sizeof(s), "%.*s", size, p);
10994 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10995 	if (ret < 0 || ret > max_num)
10996 		return -1;
10997 	for (i = 0; i < ret; i++) {
10998 		errno = 0;
10999 		int_fld = strtoul(str_fld[i], &end, 0);
11000 		if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11001 			return -1;
11002 		offsets[i] = (uint16_t)int_fld;
11003 	}
11004 	return ret;
11005 }
11006 
11007 static void
11008 cmd_flow_director_flxpld_parsed(void *parsed_result,
11009 			  __rte_unused struct cmdline *cl,
11010 			  __rte_unused void *data)
11011 {
11012 	struct cmd_flow_director_flexpayload_result *res = parsed_result;
11013 	struct rte_eth_flex_payload_cfg flex_cfg;
11014 	struct rte_port *port;
11015 	int ret = 0;
11016 
11017 	port = &ports[res->port_id];
11018 	/** Check if the port is not started **/
11019 	if (port->port_status != RTE_PORT_STOPPED) {
11020 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
11021 		return;
11022 	}
11023 
11024 	memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11025 
11026 	if (!strcmp(res->payload_layer, "raw"))
11027 		flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11028 	else if (!strcmp(res->payload_layer, "l2"))
11029 		flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11030 	else if (!strcmp(res->payload_layer, "l3"))
11031 		flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11032 	else if (!strcmp(res->payload_layer, "l4"))
11033 		flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11034 
11035 	ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11036 			    RTE_ETH_FDIR_MAX_FLEXLEN);
11037 	if (ret < 0) {
11038 		fprintf(stderr, "error: Cannot parse flex payload input.\n");
11039 		return;
11040 	}
11041 
11042 	fdir_set_flex_payload(res->port_id, &flex_cfg);
11043 	cmd_reconfig_device_queue(res->port_id, 1, 1);
11044 }
11045 
11046 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11047 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11048 				 flow_director_flexpayload,
11049 				 "flow_director_flex_payload");
11050 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11051 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11052 			      port_id, RTE_UINT16);
11053 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11054 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11055 				 payload_layer, "raw#l2#l3#l4");
11056 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11057 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11058 				 payload_cfg, NULL);
11059 
11060 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11061 	.f = cmd_flow_director_flxpld_parsed,
11062 	.data = NULL,
11063 	.help_str = "flow_director_flexpayload ... : "
11064 		"Set flow director's flex payload on NIC",
11065 	.tokens = {
11066 		(void *)&cmd_flow_director_flexpayload,
11067 		(void *)&cmd_flow_director_flexpayload_port_id,
11068 		(void *)&cmd_flow_director_flexpayload_payload_layer,
11069 		(void *)&cmd_flow_director_flexpayload_payload_cfg,
11070 		NULL,
11071 	},
11072 };
11073 
11074 /* Generic flow interface command. */
11075 extern cmdline_parse_inst_t cmd_flow;
11076 
11077 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11078 struct cmd_mcast_addr_result {
11079 	cmdline_fixed_string_t mcast_addr_cmd;
11080 	cmdline_fixed_string_t what;
11081 	uint16_t port_num;
11082 	struct rte_ether_addr mc_addr;
11083 };
11084 
11085 static void cmd_mcast_addr_parsed(void *parsed_result,
11086 		__rte_unused struct cmdline *cl,
11087 		__rte_unused void *data)
11088 {
11089 	struct cmd_mcast_addr_result *res = parsed_result;
11090 
11091 	if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
11092 		fprintf(stderr,
11093 			"Invalid multicast addr " RTE_ETHER_ADDR_PRT_FMT "\n",
11094 			RTE_ETHER_ADDR_BYTES(&res->mc_addr));
11095 		return;
11096 	}
11097 	if (strcmp(res->what, "add") == 0)
11098 		mcast_addr_add(res->port_num, &res->mc_addr);
11099 	else
11100 		mcast_addr_remove(res->port_num, &res->mc_addr);
11101 }
11102 
11103 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11104 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11105 				 mcast_addr_cmd, "mcast_addr");
11106 cmdline_parse_token_string_t cmd_mcast_addr_what =
11107 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11108 				 "add#remove");
11109 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11110 	TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
11111 				 RTE_UINT16);
11112 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11113 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11114 
11115 cmdline_parse_inst_t cmd_mcast_addr = {
11116 	.f = cmd_mcast_addr_parsed,
11117 	.data = (void *)0,
11118 	.help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11119 		"Add/Remove multicast MAC address on port_id",
11120 	.tokens = {
11121 		(void *)&cmd_mcast_addr_cmd,
11122 		(void *)&cmd_mcast_addr_what,
11123 		(void *)&cmd_mcast_addr_portnum,
11124 		(void *)&cmd_mcast_addr_addr,
11125 		NULL,
11126 	},
11127 };
11128 
11129 /* vf vlan anti spoof configuration */
11130 
11131 /* Common result structure for vf vlan anti spoof */
11132 struct cmd_vf_vlan_anti_spoof_result {
11133 	cmdline_fixed_string_t set;
11134 	cmdline_fixed_string_t vf;
11135 	cmdline_fixed_string_t vlan;
11136 	cmdline_fixed_string_t antispoof;
11137 	portid_t port_id;
11138 	uint32_t vf_id;
11139 	cmdline_fixed_string_t on_off;
11140 };
11141 
11142 /* Common CLI fields for vf vlan anti spoof enable disable */
11143 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11144 	TOKEN_STRING_INITIALIZER
11145 		(struct cmd_vf_vlan_anti_spoof_result,
11146 		 set, "set");
11147 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11148 	TOKEN_STRING_INITIALIZER
11149 		(struct cmd_vf_vlan_anti_spoof_result,
11150 		 vf, "vf");
11151 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11152 	TOKEN_STRING_INITIALIZER
11153 		(struct cmd_vf_vlan_anti_spoof_result,
11154 		 vlan, "vlan");
11155 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11156 	TOKEN_STRING_INITIALIZER
11157 		(struct cmd_vf_vlan_anti_spoof_result,
11158 		 antispoof, "antispoof");
11159 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11160 	TOKEN_NUM_INITIALIZER
11161 		(struct cmd_vf_vlan_anti_spoof_result,
11162 		 port_id, RTE_UINT16);
11163 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11164 	TOKEN_NUM_INITIALIZER
11165 		(struct cmd_vf_vlan_anti_spoof_result,
11166 		 vf_id, RTE_UINT32);
11167 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11168 	TOKEN_STRING_INITIALIZER
11169 		(struct cmd_vf_vlan_anti_spoof_result,
11170 		 on_off, "on#off");
11171 
11172 static void
11173 cmd_set_vf_vlan_anti_spoof_parsed(
11174 	void *parsed_result,
11175 	__rte_unused struct cmdline *cl,
11176 	__rte_unused void *data)
11177 {
11178 	struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11179 	int ret = -ENOTSUP;
11180 
11181 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11182 
11183 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11184 		return;
11185 
11186 #ifdef RTE_NET_IXGBE
11187 	if (ret == -ENOTSUP)
11188 		ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11189 				res->vf_id, is_on);
11190 #endif
11191 #ifdef RTE_NET_I40E
11192 	if (ret == -ENOTSUP)
11193 		ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11194 				res->vf_id, is_on);
11195 #endif
11196 #ifdef RTE_NET_BNXT
11197 	if (ret == -ENOTSUP)
11198 		ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11199 				res->vf_id, is_on);
11200 #endif
11201 
11202 	switch (ret) {
11203 	case 0:
11204 		break;
11205 	case -EINVAL:
11206 		fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
11207 		break;
11208 	case -ENODEV:
11209 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11210 		break;
11211 	case -ENOTSUP:
11212 		fprintf(stderr, "function not implemented\n");
11213 		break;
11214 	default:
11215 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11216 	}
11217 }
11218 
11219 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11220 	.f = cmd_set_vf_vlan_anti_spoof_parsed,
11221 	.data = NULL,
11222 	.help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11223 	.tokens = {
11224 		(void *)&cmd_vf_vlan_anti_spoof_set,
11225 		(void *)&cmd_vf_vlan_anti_spoof_vf,
11226 		(void *)&cmd_vf_vlan_anti_spoof_vlan,
11227 		(void *)&cmd_vf_vlan_anti_spoof_antispoof,
11228 		(void *)&cmd_vf_vlan_anti_spoof_port_id,
11229 		(void *)&cmd_vf_vlan_anti_spoof_vf_id,
11230 		(void *)&cmd_vf_vlan_anti_spoof_on_off,
11231 		NULL,
11232 	},
11233 };
11234 
11235 /* vf mac anti spoof configuration */
11236 
11237 /* Common result structure for vf mac anti spoof */
11238 struct cmd_vf_mac_anti_spoof_result {
11239 	cmdline_fixed_string_t set;
11240 	cmdline_fixed_string_t vf;
11241 	cmdline_fixed_string_t mac;
11242 	cmdline_fixed_string_t antispoof;
11243 	portid_t port_id;
11244 	uint32_t vf_id;
11245 	cmdline_fixed_string_t on_off;
11246 };
11247 
11248 /* Common CLI fields for vf mac anti spoof enable disable */
11249 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11250 	TOKEN_STRING_INITIALIZER
11251 		(struct cmd_vf_mac_anti_spoof_result,
11252 		 set, "set");
11253 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11254 	TOKEN_STRING_INITIALIZER
11255 		(struct cmd_vf_mac_anti_spoof_result,
11256 		 vf, "vf");
11257 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11258 	TOKEN_STRING_INITIALIZER
11259 		(struct cmd_vf_mac_anti_spoof_result,
11260 		 mac, "mac");
11261 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11262 	TOKEN_STRING_INITIALIZER
11263 		(struct cmd_vf_mac_anti_spoof_result,
11264 		 antispoof, "antispoof");
11265 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11266 	TOKEN_NUM_INITIALIZER
11267 		(struct cmd_vf_mac_anti_spoof_result,
11268 		 port_id, RTE_UINT16);
11269 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11270 	TOKEN_NUM_INITIALIZER
11271 		(struct cmd_vf_mac_anti_spoof_result,
11272 		 vf_id, RTE_UINT32);
11273 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11274 	TOKEN_STRING_INITIALIZER
11275 		(struct cmd_vf_mac_anti_spoof_result,
11276 		 on_off, "on#off");
11277 
11278 static void
11279 cmd_set_vf_mac_anti_spoof_parsed(
11280 	void *parsed_result,
11281 	__rte_unused struct cmdline *cl,
11282 	__rte_unused void *data)
11283 {
11284 	struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11285 	int ret = -ENOTSUP;
11286 
11287 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11288 
11289 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11290 		return;
11291 
11292 #ifdef RTE_NET_IXGBE
11293 	if (ret == -ENOTSUP)
11294 		ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11295 			res->vf_id, is_on);
11296 #endif
11297 #ifdef RTE_NET_I40E
11298 	if (ret == -ENOTSUP)
11299 		ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11300 			res->vf_id, is_on);
11301 #endif
11302 #ifdef RTE_NET_BNXT
11303 	if (ret == -ENOTSUP)
11304 		ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11305 			res->vf_id, is_on);
11306 #endif
11307 
11308 	switch (ret) {
11309 	case 0:
11310 		break;
11311 	case -EINVAL:
11312 		fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11313 			res->vf_id, is_on);
11314 		break;
11315 	case -ENODEV:
11316 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11317 		break;
11318 	case -ENOTSUP:
11319 		fprintf(stderr, "function not implemented\n");
11320 		break;
11321 	default:
11322 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11323 	}
11324 }
11325 
11326 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11327 	.f = cmd_set_vf_mac_anti_spoof_parsed,
11328 	.data = NULL,
11329 	.help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11330 	.tokens = {
11331 		(void *)&cmd_vf_mac_anti_spoof_set,
11332 		(void *)&cmd_vf_mac_anti_spoof_vf,
11333 		(void *)&cmd_vf_mac_anti_spoof_mac,
11334 		(void *)&cmd_vf_mac_anti_spoof_antispoof,
11335 		(void *)&cmd_vf_mac_anti_spoof_port_id,
11336 		(void *)&cmd_vf_mac_anti_spoof_vf_id,
11337 		(void *)&cmd_vf_mac_anti_spoof_on_off,
11338 		NULL,
11339 	},
11340 };
11341 
11342 /* vf vlan strip queue configuration */
11343 
11344 /* Common result structure for vf mac anti spoof */
11345 struct cmd_vf_vlan_stripq_result {
11346 	cmdline_fixed_string_t set;
11347 	cmdline_fixed_string_t vf;
11348 	cmdline_fixed_string_t vlan;
11349 	cmdline_fixed_string_t stripq;
11350 	portid_t port_id;
11351 	uint16_t vf_id;
11352 	cmdline_fixed_string_t on_off;
11353 };
11354 
11355 /* Common CLI fields for vf vlan strip enable disable */
11356 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11357 	TOKEN_STRING_INITIALIZER
11358 		(struct cmd_vf_vlan_stripq_result,
11359 		 set, "set");
11360 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11361 	TOKEN_STRING_INITIALIZER
11362 		(struct cmd_vf_vlan_stripq_result,
11363 		 vf, "vf");
11364 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11365 	TOKEN_STRING_INITIALIZER
11366 		(struct cmd_vf_vlan_stripq_result,
11367 		 vlan, "vlan");
11368 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11369 	TOKEN_STRING_INITIALIZER
11370 		(struct cmd_vf_vlan_stripq_result,
11371 		 stripq, "stripq");
11372 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11373 	TOKEN_NUM_INITIALIZER
11374 		(struct cmd_vf_vlan_stripq_result,
11375 		 port_id, RTE_UINT16);
11376 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11377 	TOKEN_NUM_INITIALIZER
11378 		(struct cmd_vf_vlan_stripq_result,
11379 		 vf_id, RTE_UINT16);
11380 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11381 	TOKEN_STRING_INITIALIZER
11382 		(struct cmd_vf_vlan_stripq_result,
11383 		 on_off, "on#off");
11384 
11385 static void
11386 cmd_set_vf_vlan_stripq_parsed(
11387 	void *parsed_result,
11388 	__rte_unused struct cmdline *cl,
11389 	__rte_unused void *data)
11390 {
11391 	struct cmd_vf_vlan_stripq_result *res = parsed_result;
11392 	int ret = -ENOTSUP;
11393 
11394 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11395 
11396 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11397 		return;
11398 
11399 #ifdef RTE_NET_IXGBE
11400 	if (ret == -ENOTSUP)
11401 		ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11402 			res->vf_id, is_on);
11403 #endif
11404 #ifdef RTE_NET_I40E
11405 	if (ret == -ENOTSUP)
11406 		ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11407 			res->vf_id, is_on);
11408 #endif
11409 #ifdef RTE_NET_BNXT
11410 	if (ret == -ENOTSUP)
11411 		ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11412 			res->vf_id, is_on);
11413 #endif
11414 
11415 	switch (ret) {
11416 	case 0:
11417 		break;
11418 	case -EINVAL:
11419 		fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11420 			res->vf_id, is_on);
11421 		break;
11422 	case -ENODEV:
11423 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11424 		break;
11425 	case -ENOTSUP:
11426 		fprintf(stderr, "function not implemented\n");
11427 		break;
11428 	default:
11429 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11430 	}
11431 }
11432 
11433 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11434 	.f = cmd_set_vf_vlan_stripq_parsed,
11435 	.data = NULL,
11436 	.help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11437 	.tokens = {
11438 		(void *)&cmd_vf_vlan_stripq_set,
11439 		(void *)&cmd_vf_vlan_stripq_vf,
11440 		(void *)&cmd_vf_vlan_stripq_vlan,
11441 		(void *)&cmd_vf_vlan_stripq_stripq,
11442 		(void *)&cmd_vf_vlan_stripq_port_id,
11443 		(void *)&cmd_vf_vlan_stripq_vf_id,
11444 		(void *)&cmd_vf_vlan_stripq_on_off,
11445 		NULL,
11446 	},
11447 };
11448 
11449 /* vf vlan insert configuration */
11450 
11451 /* Common result structure for vf vlan insert */
11452 struct cmd_vf_vlan_insert_result {
11453 	cmdline_fixed_string_t set;
11454 	cmdline_fixed_string_t vf;
11455 	cmdline_fixed_string_t vlan;
11456 	cmdline_fixed_string_t insert;
11457 	portid_t port_id;
11458 	uint16_t vf_id;
11459 	uint16_t vlan_id;
11460 };
11461 
11462 /* Common CLI fields for vf vlan insert enable disable */
11463 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11464 	TOKEN_STRING_INITIALIZER
11465 		(struct cmd_vf_vlan_insert_result,
11466 		 set, "set");
11467 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11468 	TOKEN_STRING_INITIALIZER
11469 		(struct cmd_vf_vlan_insert_result,
11470 		 vf, "vf");
11471 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11472 	TOKEN_STRING_INITIALIZER
11473 		(struct cmd_vf_vlan_insert_result,
11474 		 vlan, "vlan");
11475 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11476 	TOKEN_STRING_INITIALIZER
11477 		(struct cmd_vf_vlan_insert_result,
11478 		 insert, "insert");
11479 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11480 	TOKEN_NUM_INITIALIZER
11481 		(struct cmd_vf_vlan_insert_result,
11482 		 port_id, RTE_UINT16);
11483 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11484 	TOKEN_NUM_INITIALIZER
11485 		(struct cmd_vf_vlan_insert_result,
11486 		 vf_id, RTE_UINT16);
11487 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11488 	TOKEN_NUM_INITIALIZER
11489 		(struct cmd_vf_vlan_insert_result,
11490 		 vlan_id, RTE_UINT16);
11491 
11492 static void
11493 cmd_set_vf_vlan_insert_parsed(
11494 	void *parsed_result,
11495 	__rte_unused struct cmdline *cl,
11496 	__rte_unused void *data)
11497 {
11498 	struct cmd_vf_vlan_insert_result *res = parsed_result;
11499 	int ret = -ENOTSUP;
11500 
11501 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11502 		return;
11503 
11504 #ifdef RTE_NET_IXGBE
11505 	if (ret == -ENOTSUP)
11506 		ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11507 			res->vlan_id);
11508 #endif
11509 #ifdef RTE_NET_I40E
11510 	if (ret == -ENOTSUP)
11511 		ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11512 			res->vlan_id);
11513 #endif
11514 #ifdef RTE_NET_BNXT
11515 	if (ret == -ENOTSUP)
11516 		ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11517 			res->vlan_id);
11518 #endif
11519 
11520 	switch (ret) {
11521 	case 0:
11522 		break;
11523 	case -EINVAL:
11524 		fprintf(stderr, "invalid vf_id %d or vlan_id %d\n",
11525 			res->vf_id, res->vlan_id);
11526 		break;
11527 	case -ENODEV:
11528 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11529 		break;
11530 	case -ENOTSUP:
11531 		fprintf(stderr, "function not implemented\n");
11532 		break;
11533 	default:
11534 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11535 	}
11536 }
11537 
11538 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11539 	.f = cmd_set_vf_vlan_insert_parsed,
11540 	.data = NULL,
11541 	.help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11542 	.tokens = {
11543 		(void *)&cmd_vf_vlan_insert_set,
11544 		(void *)&cmd_vf_vlan_insert_vf,
11545 		(void *)&cmd_vf_vlan_insert_vlan,
11546 		(void *)&cmd_vf_vlan_insert_insert,
11547 		(void *)&cmd_vf_vlan_insert_port_id,
11548 		(void *)&cmd_vf_vlan_insert_vf_id,
11549 		(void *)&cmd_vf_vlan_insert_vlan_id,
11550 		NULL,
11551 	},
11552 };
11553 
11554 /* tx loopback configuration */
11555 
11556 /* Common result structure for tx loopback */
11557 struct cmd_tx_loopback_result {
11558 	cmdline_fixed_string_t set;
11559 	cmdline_fixed_string_t tx;
11560 	cmdline_fixed_string_t loopback;
11561 	portid_t port_id;
11562 	cmdline_fixed_string_t on_off;
11563 };
11564 
11565 /* Common CLI fields for tx loopback enable disable */
11566 cmdline_parse_token_string_t cmd_tx_loopback_set =
11567 	TOKEN_STRING_INITIALIZER
11568 		(struct cmd_tx_loopback_result,
11569 		 set, "set");
11570 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11571 	TOKEN_STRING_INITIALIZER
11572 		(struct cmd_tx_loopback_result,
11573 		 tx, "tx");
11574 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11575 	TOKEN_STRING_INITIALIZER
11576 		(struct cmd_tx_loopback_result,
11577 		 loopback, "loopback");
11578 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11579 	TOKEN_NUM_INITIALIZER
11580 		(struct cmd_tx_loopback_result,
11581 		 port_id, RTE_UINT16);
11582 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11583 	TOKEN_STRING_INITIALIZER
11584 		(struct cmd_tx_loopback_result,
11585 		 on_off, "on#off");
11586 
11587 static void
11588 cmd_set_tx_loopback_parsed(
11589 	void *parsed_result,
11590 	__rte_unused struct cmdline *cl,
11591 	__rte_unused void *data)
11592 {
11593 	struct cmd_tx_loopback_result *res = parsed_result;
11594 	int ret = -ENOTSUP;
11595 
11596 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11597 
11598 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11599 		return;
11600 
11601 #ifdef RTE_NET_IXGBE
11602 	if (ret == -ENOTSUP)
11603 		ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11604 #endif
11605 #ifdef RTE_NET_I40E
11606 	if (ret == -ENOTSUP)
11607 		ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11608 #endif
11609 #ifdef RTE_NET_BNXT
11610 	if (ret == -ENOTSUP)
11611 		ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11612 #endif
11613 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11614 	if (ret == -ENOTSUP)
11615 		ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11616 #endif
11617 
11618 	switch (ret) {
11619 	case 0:
11620 		break;
11621 	case -EINVAL:
11622 		fprintf(stderr, "invalid is_on %d\n", is_on);
11623 		break;
11624 	case -ENODEV:
11625 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11626 		break;
11627 	case -ENOTSUP:
11628 		fprintf(stderr, "function not implemented\n");
11629 		break;
11630 	default:
11631 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11632 	}
11633 }
11634 
11635 cmdline_parse_inst_t cmd_set_tx_loopback = {
11636 	.f = cmd_set_tx_loopback_parsed,
11637 	.data = NULL,
11638 	.help_str = "set tx loopback <port_id> on|off",
11639 	.tokens = {
11640 		(void *)&cmd_tx_loopback_set,
11641 		(void *)&cmd_tx_loopback_tx,
11642 		(void *)&cmd_tx_loopback_loopback,
11643 		(void *)&cmd_tx_loopback_port_id,
11644 		(void *)&cmd_tx_loopback_on_off,
11645 		NULL,
11646 	},
11647 };
11648 
11649 /* all queues drop enable configuration */
11650 
11651 /* Common result structure for all queues drop enable */
11652 struct cmd_all_queues_drop_en_result {
11653 	cmdline_fixed_string_t set;
11654 	cmdline_fixed_string_t all;
11655 	cmdline_fixed_string_t queues;
11656 	cmdline_fixed_string_t drop;
11657 	portid_t port_id;
11658 	cmdline_fixed_string_t on_off;
11659 };
11660 
11661 /* Common CLI fields for tx loopback enable disable */
11662 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11663 	TOKEN_STRING_INITIALIZER
11664 		(struct cmd_all_queues_drop_en_result,
11665 		 set, "set");
11666 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11667 	TOKEN_STRING_INITIALIZER
11668 		(struct cmd_all_queues_drop_en_result,
11669 		 all, "all");
11670 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11671 	TOKEN_STRING_INITIALIZER
11672 		(struct cmd_all_queues_drop_en_result,
11673 		 queues, "queues");
11674 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11675 	TOKEN_STRING_INITIALIZER
11676 		(struct cmd_all_queues_drop_en_result,
11677 		 drop, "drop");
11678 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11679 	TOKEN_NUM_INITIALIZER
11680 		(struct cmd_all_queues_drop_en_result,
11681 		 port_id, RTE_UINT16);
11682 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11683 	TOKEN_STRING_INITIALIZER
11684 		(struct cmd_all_queues_drop_en_result,
11685 		 on_off, "on#off");
11686 
11687 static void
11688 cmd_set_all_queues_drop_en_parsed(
11689 	void *parsed_result,
11690 	__rte_unused struct cmdline *cl,
11691 	__rte_unused void *data)
11692 {
11693 	struct cmd_all_queues_drop_en_result *res = parsed_result;
11694 	int ret = -ENOTSUP;
11695 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11696 
11697 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11698 		return;
11699 
11700 #ifdef RTE_NET_IXGBE
11701 	if (ret == -ENOTSUP)
11702 		ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11703 #endif
11704 #ifdef RTE_NET_BNXT
11705 	if (ret == -ENOTSUP)
11706 		ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11707 #endif
11708 	switch (ret) {
11709 	case 0:
11710 		break;
11711 	case -EINVAL:
11712 		fprintf(stderr, "invalid is_on %d\n", is_on);
11713 		break;
11714 	case -ENODEV:
11715 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11716 		break;
11717 	case -ENOTSUP:
11718 		fprintf(stderr, "function not implemented\n");
11719 		break;
11720 	default:
11721 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11722 	}
11723 }
11724 
11725 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11726 	.f = cmd_set_all_queues_drop_en_parsed,
11727 	.data = NULL,
11728 	.help_str = "set all queues drop <port_id> on|off",
11729 	.tokens = {
11730 		(void *)&cmd_all_queues_drop_en_set,
11731 		(void *)&cmd_all_queues_drop_en_all,
11732 		(void *)&cmd_all_queues_drop_en_queues,
11733 		(void *)&cmd_all_queues_drop_en_drop,
11734 		(void *)&cmd_all_queues_drop_en_port_id,
11735 		(void *)&cmd_all_queues_drop_en_on_off,
11736 		NULL,
11737 	},
11738 };
11739 
11740 /* vf split drop enable configuration */
11741 
11742 /* Common result structure for vf split drop enable */
11743 struct cmd_vf_split_drop_en_result {
11744 	cmdline_fixed_string_t set;
11745 	cmdline_fixed_string_t vf;
11746 	cmdline_fixed_string_t split;
11747 	cmdline_fixed_string_t drop;
11748 	portid_t port_id;
11749 	uint16_t vf_id;
11750 	cmdline_fixed_string_t on_off;
11751 };
11752 
11753 /* Common CLI fields for vf split drop enable disable */
11754 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11755 	TOKEN_STRING_INITIALIZER
11756 		(struct cmd_vf_split_drop_en_result,
11757 		 set, "set");
11758 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11759 	TOKEN_STRING_INITIALIZER
11760 		(struct cmd_vf_split_drop_en_result,
11761 		 vf, "vf");
11762 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11763 	TOKEN_STRING_INITIALIZER
11764 		(struct cmd_vf_split_drop_en_result,
11765 		 split, "split");
11766 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11767 	TOKEN_STRING_INITIALIZER
11768 		(struct cmd_vf_split_drop_en_result,
11769 		 drop, "drop");
11770 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11771 	TOKEN_NUM_INITIALIZER
11772 		(struct cmd_vf_split_drop_en_result,
11773 		 port_id, RTE_UINT16);
11774 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11775 	TOKEN_NUM_INITIALIZER
11776 		(struct cmd_vf_split_drop_en_result,
11777 		 vf_id, RTE_UINT16);
11778 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11779 	TOKEN_STRING_INITIALIZER
11780 		(struct cmd_vf_split_drop_en_result,
11781 		 on_off, "on#off");
11782 
11783 static void
11784 cmd_set_vf_split_drop_en_parsed(
11785 	void *parsed_result,
11786 	__rte_unused struct cmdline *cl,
11787 	__rte_unused void *data)
11788 {
11789 	struct cmd_vf_split_drop_en_result *res = parsed_result;
11790 	int ret = -ENOTSUP;
11791 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11792 
11793 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11794 		return;
11795 
11796 #ifdef RTE_NET_IXGBE
11797 	ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11798 			is_on);
11799 #endif
11800 	switch (ret) {
11801 	case 0:
11802 		break;
11803 	case -EINVAL:
11804 		fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11805 			res->vf_id, is_on);
11806 		break;
11807 	case -ENODEV:
11808 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11809 		break;
11810 	case -ENOTSUP:
11811 		fprintf(stderr, "not supported on port %d\n", res->port_id);
11812 		break;
11813 	default:
11814 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11815 	}
11816 }
11817 
11818 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11819 	.f = cmd_set_vf_split_drop_en_parsed,
11820 	.data = NULL,
11821 	.help_str = "set vf split drop <port_id> <vf_id> on|off",
11822 	.tokens = {
11823 		(void *)&cmd_vf_split_drop_en_set,
11824 		(void *)&cmd_vf_split_drop_en_vf,
11825 		(void *)&cmd_vf_split_drop_en_split,
11826 		(void *)&cmd_vf_split_drop_en_drop,
11827 		(void *)&cmd_vf_split_drop_en_port_id,
11828 		(void *)&cmd_vf_split_drop_en_vf_id,
11829 		(void *)&cmd_vf_split_drop_en_on_off,
11830 		NULL,
11831 	},
11832 };
11833 
11834 /* vf mac address configuration */
11835 
11836 /* Common result structure for vf mac address */
11837 struct cmd_set_vf_mac_addr_result {
11838 	cmdline_fixed_string_t set;
11839 	cmdline_fixed_string_t vf;
11840 	cmdline_fixed_string_t mac;
11841 	cmdline_fixed_string_t addr;
11842 	portid_t port_id;
11843 	uint16_t vf_id;
11844 	struct rte_ether_addr mac_addr;
11845 
11846 };
11847 
11848 /* Common CLI fields for vf split drop enable disable */
11849 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11850 	TOKEN_STRING_INITIALIZER
11851 		(struct cmd_set_vf_mac_addr_result,
11852 		 set, "set");
11853 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11854 	TOKEN_STRING_INITIALIZER
11855 		(struct cmd_set_vf_mac_addr_result,
11856 		 vf, "vf");
11857 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11858 	TOKEN_STRING_INITIALIZER
11859 		(struct cmd_set_vf_mac_addr_result,
11860 		 mac, "mac");
11861 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11862 	TOKEN_STRING_INITIALIZER
11863 		(struct cmd_set_vf_mac_addr_result,
11864 		 addr, "addr");
11865 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11866 	TOKEN_NUM_INITIALIZER
11867 		(struct cmd_set_vf_mac_addr_result,
11868 		 port_id, RTE_UINT16);
11869 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11870 	TOKEN_NUM_INITIALIZER
11871 		(struct cmd_set_vf_mac_addr_result,
11872 		 vf_id, RTE_UINT16);
11873 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11874 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11875 		 mac_addr);
11876 
11877 static void
11878 cmd_set_vf_mac_addr_parsed(
11879 	void *parsed_result,
11880 	__rte_unused struct cmdline *cl,
11881 	__rte_unused void *data)
11882 {
11883 	struct cmd_set_vf_mac_addr_result *res = parsed_result;
11884 	int ret = -ENOTSUP;
11885 
11886 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11887 		return;
11888 
11889 #ifdef RTE_NET_IXGBE
11890 	if (ret == -ENOTSUP)
11891 		ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11892 				&res->mac_addr);
11893 #endif
11894 #ifdef RTE_NET_I40E
11895 	if (ret == -ENOTSUP)
11896 		ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11897 				&res->mac_addr);
11898 #endif
11899 #ifdef RTE_NET_BNXT
11900 	if (ret == -ENOTSUP)
11901 		ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11902 				&res->mac_addr);
11903 #endif
11904 
11905 	switch (ret) {
11906 	case 0:
11907 		break;
11908 	case -EINVAL:
11909 		fprintf(stderr, "invalid vf_id %d or mac_addr\n", res->vf_id);
11910 		break;
11911 	case -ENODEV:
11912 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11913 		break;
11914 	case -ENOTSUP:
11915 		fprintf(stderr, "function not implemented\n");
11916 		break;
11917 	default:
11918 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11919 	}
11920 }
11921 
11922 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11923 	.f = cmd_set_vf_mac_addr_parsed,
11924 	.data = NULL,
11925 	.help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11926 	.tokens = {
11927 		(void *)&cmd_set_vf_mac_addr_set,
11928 		(void *)&cmd_set_vf_mac_addr_vf,
11929 		(void *)&cmd_set_vf_mac_addr_mac,
11930 		(void *)&cmd_set_vf_mac_addr_addr,
11931 		(void *)&cmd_set_vf_mac_addr_port_id,
11932 		(void *)&cmd_set_vf_mac_addr_vf_id,
11933 		(void *)&cmd_set_vf_mac_addr_mac_addr,
11934 		NULL,
11935 	},
11936 };
11937 
11938 /* MACsec configuration */
11939 
11940 /* Common result structure for MACsec offload enable */
11941 struct cmd_macsec_offload_on_result {
11942 	cmdline_fixed_string_t set;
11943 	cmdline_fixed_string_t macsec;
11944 	cmdline_fixed_string_t offload;
11945 	portid_t port_id;
11946 	cmdline_fixed_string_t on;
11947 	cmdline_fixed_string_t encrypt;
11948 	cmdline_fixed_string_t en_on_off;
11949 	cmdline_fixed_string_t replay_protect;
11950 	cmdline_fixed_string_t rp_on_off;
11951 };
11952 
11953 /* Common CLI fields for MACsec offload disable */
11954 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11955 	TOKEN_STRING_INITIALIZER
11956 		(struct cmd_macsec_offload_on_result,
11957 		 set, "set");
11958 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11959 	TOKEN_STRING_INITIALIZER
11960 		(struct cmd_macsec_offload_on_result,
11961 		 macsec, "macsec");
11962 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11963 	TOKEN_STRING_INITIALIZER
11964 		(struct cmd_macsec_offload_on_result,
11965 		 offload, "offload");
11966 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11967 	TOKEN_NUM_INITIALIZER
11968 		(struct cmd_macsec_offload_on_result,
11969 		 port_id, RTE_UINT16);
11970 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11971 	TOKEN_STRING_INITIALIZER
11972 		(struct cmd_macsec_offload_on_result,
11973 		 on, "on");
11974 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11975 	TOKEN_STRING_INITIALIZER
11976 		(struct cmd_macsec_offload_on_result,
11977 		 encrypt, "encrypt");
11978 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11979 	TOKEN_STRING_INITIALIZER
11980 		(struct cmd_macsec_offload_on_result,
11981 		 en_on_off, "on#off");
11982 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11983 	TOKEN_STRING_INITIALIZER
11984 		(struct cmd_macsec_offload_on_result,
11985 		 replay_protect, "replay-protect");
11986 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11987 	TOKEN_STRING_INITIALIZER
11988 		(struct cmd_macsec_offload_on_result,
11989 		 rp_on_off, "on#off");
11990 
11991 static void
11992 cmd_set_macsec_offload_on_parsed(
11993 	void *parsed_result,
11994 	__rte_unused struct cmdline *cl,
11995 	__rte_unused void *data)
11996 {
11997 	struct cmd_macsec_offload_on_result *res = parsed_result;
11998 	int ret = -ENOTSUP;
11999 	portid_t port_id = res->port_id;
12000 	int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12001 	int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12002 	struct rte_eth_dev_info dev_info;
12003 
12004 	if (port_id_is_invalid(port_id, ENABLED_WARN))
12005 		return;
12006 	if (!port_is_stopped(port_id)) {
12007 		fprintf(stderr, "Please stop port %d first\n", port_id);
12008 		return;
12009 	}
12010 
12011 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
12012 	if (ret != 0)
12013 		return;
12014 
12015 	if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
12016 #ifdef RTE_NET_IXGBE
12017 		ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12018 #endif
12019 	}
12020 	RTE_SET_USED(en);
12021 	RTE_SET_USED(rp);
12022 
12023 	switch (ret) {
12024 	case 0:
12025 		ports[port_id].dev_conf.txmode.offloads |=
12026 						RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
12027 		cmd_reconfig_device_queue(port_id, 1, 1);
12028 		break;
12029 	case -ENODEV:
12030 		fprintf(stderr, "invalid port_id %d\n", port_id);
12031 		break;
12032 	case -ENOTSUP:
12033 		fprintf(stderr, "not supported on port %d\n", port_id);
12034 		break;
12035 	default:
12036 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12037 	}
12038 }
12039 
12040 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12041 	.f = cmd_set_macsec_offload_on_parsed,
12042 	.data = NULL,
12043 	.help_str = "set macsec offload <port_id> on "
12044 		"encrypt on|off replay-protect on|off",
12045 	.tokens = {
12046 		(void *)&cmd_macsec_offload_on_set,
12047 		(void *)&cmd_macsec_offload_on_macsec,
12048 		(void *)&cmd_macsec_offload_on_offload,
12049 		(void *)&cmd_macsec_offload_on_port_id,
12050 		(void *)&cmd_macsec_offload_on_on,
12051 		(void *)&cmd_macsec_offload_on_encrypt,
12052 		(void *)&cmd_macsec_offload_on_en_on_off,
12053 		(void *)&cmd_macsec_offload_on_replay_protect,
12054 		(void *)&cmd_macsec_offload_on_rp_on_off,
12055 		NULL,
12056 	},
12057 };
12058 
12059 /* Common result structure for MACsec offload disable */
12060 struct cmd_macsec_offload_off_result {
12061 	cmdline_fixed_string_t set;
12062 	cmdline_fixed_string_t macsec;
12063 	cmdline_fixed_string_t offload;
12064 	portid_t port_id;
12065 	cmdline_fixed_string_t off;
12066 };
12067 
12068 /* Common CLI fields for MACsec offload disable */
12069 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12070 	TOKEN_STRING_INITIALIZER
12071 		(struct cmd_macsec_offload_off_result,
12072 		 set, "set");
12073 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12074 	TOKEN_STRING_INITIALIZER
12075 		(struct cmd_macsec_offload_off_result,
12076 		 macsec, "macsec");
12077 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12078 	TOKEN_STRING_INITIALIZER
12079 		(struct cmd_macsec_offload_off_result,
12080 		 offload, "offload");
12081 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12082 	TOKEN_NUM_INITIALIZER
12083 		(struct cmd_macsec_offload_off_result,
12084 		 port_id, RTE_UINT16);
12085 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12086 	TOKEN_STRING_INITIALIZER
12087 		(struct cmd_macsec_offload_off_result,
12088 		 off, "off");
12089 
12090 static void
12091 cmd_set_macsec_offload_off_parsed(
12092 	void *parsed_result,
12093 	__rte_unused struct cmdline *cl,
12094 	__rte_unused void *data)
12095 {
12096 	struct cmd_macsec_offload_off_result *res = parsed_result;
12097 	int ret = -ENOTSUP;
12098 	struct rte_eth_dev_info dev_info;
12099 	portid_t port_id = res->port_id;
12100 
12101 	if (port_id_is_invalid(port_id, ENABLED_WARN))
12102 		return;
12103 	if (!port_is_stopped(port_id)) {
12104 		fprintf(stderr, "Please stop port %d first\n", port_id);
12105 		return;
12106 	}
12107 
12108 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
12109 	if (ret != 0)
12110 		return;
12111 
12112 	if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
12113 #ifdef RTE_NET_IXGBE
12114 		ret = rte_pmd_ixgbe_macsec_disable(port_id);
12115 #endif
12116 	}
12117 	switch (ret) {
12118 	case 0:
12119 		ports[port_id].dev_conf.txmode.offloads &=
12120 						~RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
12121 		cmd_reconfig_device_queue(port_id, 1, 1);
12122 		break;
12123 	case -ENODEV:
12124 		fprintf(stderr, "invalid port_id %d\n", port_id);
12125 		break;
12126 	case -ENOTSUP:
12127 		fprintf(stderr, "not supported on port %d\n", port_id);
12128 		break;
12129 	default:
12130 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12131 	}
12132 }
12133 
12134 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12135 	.f = cmd_set_macsec_offload_off_parsed,
12136 	.data = NULL,
12137 	.help_str = "set macsec offload <port_id> off",
12138 	.tokens = {
12139 		(void *)&cmd_macsec_offload_off_set,
12140 		(void *)&cmd_macsec_offload_off_macsec,
12141 		(void *)&cmd_macsec_offload_off_offload,
12142 		(void *)&cmd_macsec_offload_off_port_id,
12143 		(void *)&cmd_macsec_offload_off_off,
12144 		NULL,
12145 	},
12146 };
12147 
12148 /* Common result structure for MACsec secure connection configure */
12149 struct cmd_macsec_sc_result {
12150 	cmdline_fixed_string_t set;
12151 	cmdline_fixed_string_t macsec;
12152 	cmdline_fixed_string_t sc;
12153 	cmdline_fixed_string_t tx_rx;
12154 	portid_t port_id;
12155 	struct rte_ether_addr mac;
12156 	uint16_t pi;
12157 };
12158 
12159 /* Common CLI fields for MACsec secure connection configure */
12160 cmdline_parse_token_string_t cmd_macsec_sc_set =
12161 	TOKEN_STRING_INITIALIZER
12162 		(struct cmd_macsec_sc_result,
12163 		 set, "set");
12164 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12165 	TOKEN_STRING_INITIALIZER
12166 		(struct cmd_macsec_sc_result,
12167 		 macsec, "macsec");
12168 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12169 	TOKEN_STRING_INITIALIZER
12170 		(struct cmd_macsec_sc_result,
12171 		 sc, "sc");
12172 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12173 	TOKEN_STRING_INITIALIZER
12174 		(struct cmd_macsec_sc_result,
12175 		 tx_rx, "tx#rx");
12176 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12177 	TOKEN_NUM_INITIALIZER
12178 		(struct cmd_macsec_sc_result,
12179 		 port_id, RTE_UINT16);
12180 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12181 	TOKEN_ETHERADDR_INITIALIZER
12182 		(struct cmd_macsec_sc_result,
12183 		 mac);
12184 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12185 	TOKEN_NUM_INITIALIZER
12186 		(struct cmd_macsec_sc_result,
12187 		 pi, RTE_UINT16);
12188 
12189 static void
12190 cmd_set_macsec_sc_parsed(
12191 	void *parsed_result,
12192 	__rte_unused struct cmdline *cl,
12193 	__rte_unused void *data)
12194 {
12195 	struct cmd_macsec_sc_result *res = parsed_result;
12196 	int ret = -ENOTSUP;
12197 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12198 
12199 #ifdef RTE_NET_IXGBE
12200 	ret = is_tx ?
12201 		rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12202 				res->mac.addr_bytes) :
12203 		rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12204 				res->mac.addr_bytes, res->pi);
12205 #endif
12206 	RTE_SET_USED(is_tx);
12207 
12208 	switch (ret) {
12209 	case 0:
12210 		break;
12211 	case -ENODEV:
12212 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12213 		break;
12214 	case -ENOTSUP:
12215 		fprintf(stderr, "not supported on port %d\n", res->port_id);
12216 		break;
12217 	default:
12218 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12219 	}
12220 }
12221 
12222 cmdline_parse_inst_t cmd_set_macsec_sc = {
12223 	.f = cmd_set_macsec_sc_parsed,
12224 	.data = NULL,
12225 	.help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12226 	.tokens = {
12227 		(void *)&cmd_macsec_sc_set,
12228 		(void *)&cmd_macsec_sc_macsec,
12229 		(void *)&cmd_macsec_sc_sc,
12230 		(void *)&cmd_macsec_sc_tx_rx,
12231 		(void *)&cmd_macsec_sc_port_id,
12232 		(void *)&cmd_macsec_sc_mac,
12233 		(void *)&cmd_macsec_sc_pi,
12234 		NULL,
12235 	},
12236 };
12237 
12238 /* Common result structure for MACsec secure connection configure */
12239 struct cmd_macsec_sa_result {
12240 	cmdline_fixed_string_t set;
12241 	cmdline_fixed_string_t macsec;
12242 	cmdline_fixed_string_t sa;
12243 	cmdline_fixed_string_t tx_rx;
12244 	portid_t port_id;
12245 	uint8_t idx;
12246 	uint8_t an;
12247 	uint32_t pn;
12248 	cmdline_fixed_string_t key;
12249 };
12250 
12251 /* Common CLI fields for MACsec secure connection configure */
12252 cmdline_parse_token_string_t cmd_macsec_sa_set =
12253 	TOKEN_STRING_INITIALIZER
12254 		(struct cmd_macsec_sa_result,
12255 		 set, "set");
12256 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12257 	TOKEN_STRING_INITIALIZER
12258 		(struct cmd_macsec_sa_result,
12259 		 macsec, "macsec");
12260 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12261 	TOKEN_STRING_INITIALIZER
12262 		(struct cmd_macsec_sa_result,
12263 		 sa, "sa");
12264 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12265 	TOKEN_STRING_INITIALIZER
12266 		(struct cmd_macsec_sa_result,
12267 		 tx_rx, "tx#rx");
12268 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12269 	TOKEN_NUM_INITIALIZER
12270 		(struct cmd_macsec_sa_result,
12271 		 port_id, RTE_UINT16);
12272 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12273 	TOKEN_NUM_INITIALIZER
12274 		(struct cmd_macsec_sa_result,
12275 		 idx, RTE_UINT8);
12276 cmdline_parse_token_num_t cmd_macsec_sa_an =
12277 	TOKEN_NUM_INITIALIZER
12278 		(struct cmd_macsec_sa_result,
12279 		 an, RTE_UINT8);
12280 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12281 	TOKEN_NUM_INITIALIZER
12282 		(struct cmd_macsec_sa_result,
12283 		 pn, RTE_UINT32);
12284 cmdline_parse_token_string_t cmd_macsec_sa_key =
12285 	TOKEN_STRING_INITIALIZER
12286 		(struct cmd_macsec_sa_result,
12287 		 key, NULL);
12288 
12289 static void
12290 cmd_set_macsec_sa_parsed(
12291 	void *parsed_result,
12292 	__rte_unused struct cmdline *cl,
12293 	__rte_unused void *data)
12294 {
12295 	struct cmd_macsec_sa_result *res = parsed_result;
12296 	int ret = -ENOTSUP;
12297 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12298 	uint8_t key[16] = { 0 };
12299 	uint8_t xdgt0;
12300 	uint8_t xdgt1;
12301 	int key_len;
12302 	int i;
12303 
12304 	key_len = strlen(res->key) / 2;
12305 	if (key_len > 16)
12306 		key_len = 16;
12307 
12308 	for (i = 0; i < key_len; i++) {
12309 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12310 		if (xdgt0 == 0xFF)
12311 			return;
12312 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12313 		if (xdgt1 == 0xFF)
12314 			return;
12315 		key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12316 	}
12317 
12318 #ifdef RTE_NET_IXGBE
12319 	ret = is_tx ?
12320 		rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12321 			res->idx, res->an, res->pn, key) :
12322 		rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12323 			res->idx, res->an, res->pn, key);
12324 #endif
12325 	RTE_SET_USED(is_tx);
12326 	RTE_SET_USED(key);
12327 
12328 	switch (ret) {
12329 	case 0:
12330 		break;
12331 	case -EINVAL:
12332 		fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an);
12333 		break;
12334 	case -ENODEV:
12335 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12336 		break;
12337 	case -ENOTSUP:
12338 		fprintf(stderr, "not supported on port %d\n", res->port_id);
12339 		break;
12340 	default:
12341 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12342 	}
12343 }
12344 
12345 cmdline_parse_inst_t cmd_set_macsec_sa = {
12346 	.f = cmd_set_macsec_sa_parsed,
12347 	.data = NULL,
12348 	.help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12349 	.tokens = {
12350 		(void *)&cmd_macsec_sa_set,
12351 		(void *)&cmd_macsec_sa_macsec,
12352 		(void *)&cmd_macsec_sa_sa,
12353 		(void *)&cmd_macsec_sa_tx_rx,
12354 		(void *)&cmd_macsec_sa_port_id,
12355 		(void *)&cmd_macsec_sa_idx,
12356 		(void *)&cmd_macsec_sa_an,
12357 		(void *)&cmd_macsec_sa_pn,
12358 		(void *)&cmd_macsec_sa_key,
12359 		NULL,
12360 	},
12361 };
12362 
12363 /* VF unicast promiscuous mode configuration */
12364 
12365 /* Common result structure for VF unicast promiscuous mode */
12366 struct cmd_vf_promisc_result {
12367 	cmdline_fixed_string_t set;
12368 	cmdline_fixed_string_t vf;
12369 	cmdline_fixed_string_t promisc;
12370 	portid_t port_id;
12371 	uint32_t vf_id;
12372 	cmdline_fixed_string_t on_off;
12373 };
12374 
12375 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12376 cmdline_parse_token_string_t cmd_vf_promisc_set =
12377 	TOKEN_STRING_INITIALIZER
12378 		(struct cmd_vf_promisc_result,
12379 		 set, "set");
12380 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12381 	TOKEN_STRING_INITIALIZER
12382 		(struct cmd_vf_promisc_result,
12383 		 vf, "vf");
12384 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12385 	TOKEN_STRING_INITIALIZER
12386 		(struct cmd_vf_promisc_result,
12387 		 promisc, "promisc");
12388 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12389 	TOKEN_NUM_INITIALIZER
12390 		(struct cmd_vf_promisc_result,
12391 		 port_id, RTE_UINT16);
12392 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12393 	TOKEN_NUM_INITIALIZER
12394 		(struct cmd_vf_promisc_result,
12395 		 vf_id, RTE_UINT32);
12396 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12397 	TOKEN_STRING_INITIALIZER
12398 		(struct cmd_vf_promisc_result,
12399 		 on_off, "on#off");
12400 
12401 static void
12402 cmd_set_vf_promisc_parsed(
12403 	void *parsed_result,
12404 	__rte_unused struct cmdline *cl,
12405 	__rte_unused void *data)
12406 {
12407 	struct cmd_vf_promisc_result *res = parsed_result;
12408 	int ret = -ENOTSUP;
12409 
12410 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12411 
12412 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12413 		return;
12414 
12415 #ifdef RTE_NET_I40E
12416 	ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12417 						  res->vf_id, is_on);
12418 #endif
12419 
12420 	switch (ret) {
12421 	case 0:
12422 		break;
12423 	case -EINVAL:
12424 		fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12425 		break;
12426 	case -ENODEV:
12427 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12428 		break;
12429 	case -ENOTSUP:
12430 		fprintf(stderr, "function not implemented\n");
12431 		break;
12432 	default:
12433 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12434 	}
12435 }
12436 
12437 cmdline_parse_inst_t cmd_set_vf_promisc = {
12438 	.f = cmd_set_vf_promisc_parsed,
12439 	.data = NULL,
12440 	.help_str = "set vf promisc <port_id> <vf_id> on|off: "
12441 		"Set unicast promiscuous mode for a VF from the PF",
12442 	.tokens = {
12443 		(void *)&cmd_vf_promisc_set,
12444 		(void *)&cmd_vf_promisc_vf,
12445 		(void *)&cmd_vf_promisc_promisc,
12446 		(void *)&cmd_vf_promisc_port_id,
12447 		(void *)&cmd_vf_promisc_vf_id,
12448 		(void *)&cmd_vf_promisc_on_off,
12449 		NULL,
12450 	},
12451 };
12452 
12453 /* VF multicast promiscuous mode configuration */
12454 
12455 /* Common result structure for VF multicast promiscuous mode */
12456 struct cmd_vf_allmulti_result {
12457 	cmdline_fixed_string_t set;
12458 	cmdline_fixed_string_t vf;
12459 	cmdline_fixed_string_t allmulti;
12460 	portid_t port_id;
12461 	uint32_t vf_id;
12462 	cmdline_fixed_string_t on_off;
12463 };
12464 
12465 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12466 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12467 	TOKEN_STRING_INITIALIZER
12468 		(struct cmd_vf_allmulti_result,
12469 		 set, "set");
12470 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12471 	TOKEN_STRING_INITIALIZER
12472 		(struct cmd_vf_allmulti_result,
12473 		 vf, "vf");
12474 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12475 	TOKEN_STRING_INITIALIZER
12476 		(struct cmd_vf_allmulti_result,
12477 		 allmulti, "allmulti");
12478 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12479 	TOKEN_NUM_INITIALIZER
12480 		(struct cmd_vf_allmulti_result,
12481 		 port_id, RTE_UINT16);
12482 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12483 	TOKEN_NUM_INITIALIZER
12484 		(struct cmd_vf_allmulti_result,
12485 		 vf_id, RTE_UINT32);
12486 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12487 	TOKEN_STRING_INITIALIZER
12488 		(struct cmd_vf_allmulti_result,
12489 		 on_off, "on#off");
12490 
12491 static void
12492 cmd_set_vf_allmulti_parsed(
12493 	void *parsed_result,
12494 	__rte_unused struct cmdline *cl,
12495 	__rte_unused void *data)
12496 {
12497 	struct cmd_vf_allmulti_result *res = parsed_result;
12498 	int ret = -ENOTSUP;
12499 
12500 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12501 
12502 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12503 		return;
12504 
12505 #ifdef RTE_NET_I40E
12506 	ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12507 						    res->vf_id, is_on);
12508 #endif
12509 
12510 	switch (ret) {
12511 	case 0:
12512 		break;
12513 	case -EINVAL:
12514 		fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12515 		break;
12516 	case -ENODEV:
12517 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12518 		break;
12519 	case -ENOTSUP:
12520 		fprintf(stderr, "function not implemented\n");
12521 		break;
12522 	default:
12523 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12524 	}
12525 }
12526 
12527 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12528 	.f = cmd_set_vf_allmulti_parsed,
12529 	.data = NULL,
12530 	.help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12531 		"Set multicast promiscuous mode for a VF from the PF",
12532 	.tokens = {
12533 		(void *)&cmd_vf_allmulti_set,
12534 		(void *)&cmd_vf_allmulti_vf,
12535 		(void *)&cmd_vf_allmulti_allmulti,
12536 		(void *)&cmd_vf_allmulti_port_id,
12537 		(void *)&cmd_vf_allmulti_vf_id,
12538 		(void *)&cmd_vf_allmulti_on_off,
12539 		NULL,
12540 	},
12541 };
12542 
12543 /* vf broadcast mode configuration */
12544 
12545 /* Common result structure for vf broadcast */
12546 struct cmd_set_vf_broadcast_result {
12547 	cmdline_fixed_string_t set;
12548 	cmdline_fixed_string_t vf;
12549 	cmdline_fixed_string_t broadcast;
12550 	portid_t port_id;
12551 	uint16_t vf_id;
12552 	cmdline_fixed_string_t on_off;
12553 };
12554 
12555 /* Common CLI fields for vf broadcast enable disable */
12556 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12557 	TOKEN_STRING_INITIALIZER
12558 		(struct cmd_set_vf_broadcast_result,
12559 		 set, "set");
12560 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12561 	TOKEN_STRING_INITIALIZER
12562 		(struct cmd_set_vf_broadcast_result,
12563 		 vf, "vf");
12564 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12565 	TOKEN_STRING_INITIALIZER
12566 		(struct cmd_set_vf_broadcast_result,
12567 		 broadcast, "broadcast");
12568 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12569 	TOKEN_NUM_INITIALIZER
12570 		(struct cmd_set_vf_broadcast_result,
12571 		 port_id, RTE_UINT16);
12572 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12573 	TOKEN_NUM_INITIALIZER
12574 		(struct cmd_set_vf_broadcast_result,
12575 		 vf_id, RTE_UINT16);
12576 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12577 	TOKEN_STRING_INITIALIZER
12578 		(struct cmd_set_vf_broadcast_result,
12579 		 on_off, "on#off");
12580 
12581 static void
12582 cmd_set_vf_broadcast_parsed(
12583 	void *parsed_result,
12584 	__rte_unused struct cmdline *cl,
12585 	__rte_unused void *data)
12586 {
12587 	struct cmd_set_vf_broadcast_result *res = parsed_result;
12588 	int ret = -ENOTSUP;
12589 
12590 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12591 
12592 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12593 		return;
12594 
12595 #ifdef RTE_NET_I40E
12596 	ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12597 					    res->vf_id, is_on);
12598 #endif
12599 
12600 	switch (ret) {
12601 	case 0:
12602 		break;
12603 	case -EINVAL:
12604 		fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12605 			res->vf_id, is_on);
12606 		break;
12607 	case -ENODEV:
12608 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12609 		break;
12610 	case -ENOTSUP:
12611 		fprintf(stderr, "function not implemented\n");
12612 		break;
12613 	default:
12614 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12615 	}
12616 }
12617 
12618 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12619 	.f = cmd_set_vf_broadcast_parsed,
12620 	.data = NULL,
12621 	.help_str = "set vf broadcast <port_id> <vf_id> on|off",
12622 	.tokens = {
12623 		(void *)&cmd_set_vf_broadcast_set,
12624 		(void *)&cmd_set_vf_broadcast_vf,
12625 		(void *)&cmd_set_vf_broadcast_broadcast,
12626 		(void *)&cmd_set_vf_broadcast_port_id,
12627 		(void *)&cmd_set_vf_broadcast_vf_id,
12628 		(void *)&cmd_set_vf_broadcast_on_off,
12629 		NULL,
12630 	},
12631 };
12632 
12633 /* vf vlan tag configuration */
12634 
12635 /* Common result structure for vf vlan tag */
12636 struct cmd_set_vf_vlan_tag_result {
12637 	cmdline_fixed_string_t set;
12638 	cmdline_fixed_string_t vf;
12639 	cmdline_fixed_string_t vlan;
12640 	cmdline_fixed_string_t tag;
12641 	portid_t port_id;
12642 	uint16_t vf_id;
12643 	cmdline_fixed_string_t on_off;
12644 };
12645 
12646 /* Common CLI fields for vf vlan tag enable disable */
12647 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12648 	TOKEN_STRING_INITIALIZER
12649 		(struct cmd_set_vf_vlan_tag_result,
12650 		 set, "set");
12651 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12652 	TOKEN_STRING_INITIALIZER
12653 		(struct cmd_set_vf_vlan_tag_result,
12654 		 vf, "vf");
12655 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12656 	TOKEN_STRING_INITIALIZER
12657 		(struct cmd_set_vf_vlan_tag_result,
12658 		 vlan, "vlan");
12659 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12660 	TOKEN_STRING_INITIALIZER
12661 		(struct cmd_set_vf_vlan_tag_result,
12662 		 tag, "tag");
12663 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12664 	TOKEN_NUM_INITIALIZER
12665 		(struct cmd_set_vf_vlan_tag_result,
12666 		 port_id, RTE_UINT16);
12667 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12668 	TOKEN_NUM_INITIALIZER
12669 		(struct cmd_set_vf_vlan_tag_result,
12670 		 vf_id, RTE_UINT16);
12671 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12672 	TOKEN_STRING_INITIALIZER
12673 		(struct cmd_set_vf_vlan_tag_result,
12674 		 on_off, "on#off");
12675 
12676 static void
12677 cmd_set_vf_vlan_tag_parsed(
12678 	void *parsed_result,
12679 	__rte_unused struct cmdline *cl,
12680 	__rte_unused void *data)
12681 {
12682 	struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12683 	int ret = -ENOTSUP;
12684 
12685 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12686 
12687 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12688 		return;
12689 
12690 #ifdef RTE_NET_I40E
12691 	ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12692 					   res->vf_id, is_on);
12693 #endif
12694 
12695 	switch (ret) {
12696 	case 0:
12697 		break;
12698 	case -EINVAL:
12699 		fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12700 			res->vf_id, is_on);
12701 		break;
12702 	case -ENODEV:
12703 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12704 		break;
12705 	case -ENOTSUP:
12706 		fprintf(stderr, "function not implemented\n");
12707 		break;
12708 	default:
12709 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12710 	}
12711 }
12712 
12713 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12714 	.f = cmd_set_vf_vlan_tag_parsed,
12715 	.data = NULL,
12716 	.help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12717 	.tokens = {
12718 		(void *)&cmd_set_vf_vlan_tag_set,
12719 		(void *)&cmd_set_vf_vlan_tag_vf,
12720 		(void *)&cmd_set_vf_vlan_tag_vlan,
12721 		(void *)&cmd_set_vf_vlan_tag_tag,
12722 		(void *)&cmd_set_vf_vlan_tag_port_id,
12723 		(void *)&cmd_set_vf_vlan_tag_vf_id,
12724 		(void *)&cmd_set_vf_vlan_tag_on_off,
12725 		NULL,
12726 	},
12727 };
12728 
12729 /* Common definition of VF and TC TX bandwidth configuration */
12730 struct cmd_vf_tc_bw_result {
12731 	cmdline_fixed_string_t set;
12732 	cmdline_fixed_string_t vf;
12733 	cmdline_fixed_string_t tc;
12734 	cmdline_fixed_string_t tx;
12735 	cmdline_fixed_string_t min_bw;
12736 	cmdline_fixed_string_t max_bw;
12737 	cmdline_fixed_string_t strict_link_prio;
12738 	portid_t port_id;
12739 	uint16_t vf_id;
12740 	uint8_t tc_no;
12741 	uint32_t bw;
12742 	cmdline_fixed_string_t bw_list;
12743 	uint8_t tc_map;
12744 };
12745 
12746 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12747 	TOKEN_STRING_INITIALIZER
12748 		(struct cmd_vf_tc_bw_result,
12749 		 set, "set");
12750 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12751 	TOKEN_STRING_INITIALIZER
12752 		(struct cmd_vf_tc_bw_result,
12753 		 vf, "vf");
12754 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12755 	TOKEN_STRING_INITIALIZER
12756 		(struct cmd_vf_tc_bw_result,
12757 		 tc, "tc");
12758 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12759 	TOKEN_STRING_INITIALIZER
12760 		(struct cmd_vf_tc_bw_result,
12761 		 tx, "tx");
12762 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12763 	TOKEN_STRING_INITIALIZER
12764 		(struct cmd_vf_tc_bw_result,
12765 		 strict_link_prio, "strict-link-priority");
12766 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12767 	TOKEN_STRING_INITIALIZER
12768 		(struct cmd_vf_tc_bw_result,
12769 		 min_bw, "min-bandwidth");
12770 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12771 	TOKEN_STRING_INITIALIZER
12772 		(struct cmd_vf_tc_bw_result,
12773 		 max_bw, "max-bandwidth");
12774 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12775 	TOKEN_NUM_INITIALIZER
12776 		(struct cmd_vf_tc_bw_result,
12777 		 port_id, RTE_UINT16);
12778 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12779 	TOKEN_NUM_INITIALIZER
12780 		(struct cmd_vf_tc_bw_result,
12781 		 vf_id, RTE_UINT16);
12782 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12783 	TOKEN_NUM_INITIALIZER
12784 		(struct cmd_vf_tc_bw_result,
12785 		 tc_no, RTE_UINT8);
12786 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12787 	TOKEN_NUM_INITIALIZER
12788 		(struct cmd_vf_tc_bw_result,
12789 		 bw, RTE_UINT32);
12790 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12791 	TOKEN_STRING_INITIALIZER
12792 		(struct cmd_vf_tc_bw_result,
12793 		 bw_list, NULL);
12794 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12795 	TOKEN_NUM_INITIALIZER
12796 		(struct cmd_vf_tc_bw_result,
12797 		 tc_map, RTE_UINT8);
12798 
12799 /* VF max bandwidth setting */
12800 static void
12801 cmd_vf_max_bw_parsed(
12802 	void *parsed_result,
12803 	__rte_unused struct cmdline *cl,
12804 	__rte_unused void *data)
12805 {
12806 	struct cmd_vf_tc_bw_result *res = parsed_result;
12807 	int ret = -ENOTSUP;
12808 
12809 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12810 		return;
12811 
12812 #ifdef RTE_NET_I40E
12813 	ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12814 					 res->vf_id, res->bw);
12815 #endif
12816 
12817 	switch (ret) {
12818 	case 0:
12819 		break;
12820 	case -EINVAL:
12821 		fprintf(stderr, "invalid vf_id %d or bandwidth %d\n",
12822 			res->vf_id, res->bw);
12823 		break;
12824 	case -ENODEV:
12825 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12826 		break;
12827 	case -ENOTSUP:
12828 		fprintf(stderr, "function not implemented\n");
12829 		break;
12830 	default:
12831 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12832 	}
12833 }
12834 
12835 cmdline_parse_inst_t cmd_vf_max_bw = {
12836 	.f = cmd_vf_max_bw_parsed,
12837 	.data = NULL,
12838 	.help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12839 	.tokens = {
12840 		(void *)&cmd_vf_tc_bw_set,
12841 		(void *)&cmd_vf_tc_bw_vf,
12842 		(void *)&cmd_vf_tc_bw_tx,
12843 		(void *)&cmd_vf_tc_bw_max_bw,
12844 		(void *)&cmd_vf_tc_bw_port_id,
12845 		(void *)&cmd_vf_tc_bw_vf_id,
12846 		(void *)&cmd_vf_tc_bw_bw,
12847 		NULL,
12848 	},
12849 };
12850 
12851 static int
12852 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12853 			   uint8_t *tc_num,
12854 			   char *str)
12855 {
12856 	uint32_t size;
12857 	const char *p, *p0 = str;
12858 	char s[256];
12859 	char *end;
12860 	char *str_fld[16];
12861 	uint16_t i;
12862 	int ret;
12863 
12864 	p = strchr(p0, '(');
12865 	if (p == NULL) {
12866 		fprintf(stderr,
12867 			"The bandwidth-list should be '(bw1, bw2, ...)'\n");
12868 		return -1;
12869 	}
12870 	p++;
12871 	p0 = strchr(p, ')');
12872 	if (p0 == NULL) {
12873 		fprintf(stderr,
12874 			"The bandwidth-list should be '(bw1, bw2, ...)'\n");
12875 		return -1;
12876 	}
12877 	size = p0 - p;
12878 	if (size >= sizeof(s)) {
12879 		fprintf(stderr,
12880 			"The string size exceeds the internal buffer size\n");
12881 		return -1;
12882 	}
12883 	snprintf(s, sizeof(s), "%.*s", size, p);
12884 	ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12885 	if (ret <= 0) {
12886 		fprintf(stderr, "Failed to get the bandwidth list.\n");
12887 		return -1;
12888 	}
12889 	*tc_num = ret;
12890 	for (i = 0; i < ret; i++)
12891 		bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12892 
12893 	return 0;
12894 }
12895 
12896 /* TC min bandwidth setting */
12897 static void
12898 cmd_vf_tc_min_bw_parsed(
12899 	void *parsed_result,
12900 	__rte_unused struct cmdline *cl,
12901 	__rte_unused void *data)
12902 {
12903 	struct cmd_vf_tc_bw_result *res = parsed_result;
12904 	uint8_t tc_num;
12905 	uint8_t bw[16];
12906 	int ret = -ENOTSUP;
12907 
12908 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12909 		return;
12910 
12911 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12912 	if (ret)
12913 		return;
12914 
12915 #ifdef RTE_NET_I40E
12916 	ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12917 					      tc_num, bw);
12918 #endif
12919 
12920 	switch (ret) {
12921 	case 0:
12922 		break;
12923 	case -EINVAL:
12924 		fprintf(stderr, "invalid vf_id %d or bandwidth\n", res->vf_id);
12925 		break;
12926 	case -ENODEV:
12927 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12928 		break;
12929 	case -ENOTSUP:
12930 		fprintf(stderr, "function not implemented\n");
12931 		break;
12932 	default:
12933 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12934 	}
12935 }
12936 
12937 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12938 	.f = cmd_vf_tc_min_bw_parsed,
12939 	.data = NULL,
12940 	.help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12941 		    " <bw1, bw2, ...>",
12942 	.tokens = {
12943 		(void *)&cmd_vf_tc_bw_set,
12944 		(void *)&cmd_vf_tc_bw_vf,
12945 		(void *)&cmd_vf_tc_bw_tc,
12946 		(void *)&cmd_vf_tc_bw_tx,
12947 		(void *)&cmd_vf_tc_bw_min_bw,
12948 		(void *)&cmd_vf_tc_bw_port_id,
12949 		(void *)&cmd_vf_tc_bw_vf_id,
12950 		(void *)&cmd_vf_tc_bw_bw_list,
12951 		NULL,
12952 	},
12953 };
12954 
12955 static void
12956 cmd_tc_min_bw_parsed(
12957 	void *parsed_result,
12958 	__rte_unused struct cmdline *cl,
12959 	__rte_unused void *data)
12960 {
12961 	struct cmd_vf_tc_bw_result *res = parsed_result;
12962 	struct rte_port *port;
12963 	uint8_t tc_num;
12964 	uint8_t bw[16];
12965 	int ret = -ENOTSUP;
12966 
12967 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12968 		return;
12969 
12970 	port = &ports[res->port_id];
12971 	/** Check if the port is not started **/
12972 	if (port->port_status != RTE_PORT_STOPPED) {
12973 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
12974 		return;
12975 	}
12976 
12977 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12978 	if (ret)
12979 		return;
12980 
12981 #ifdef RTE_NET_IXGBE
12982 	ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12983 #endif
12984 
12985 	switch (ret) {
12986 	case 0:
12987 		break;
12988 	case -EINVAL:
12989 		fprintf(stderr, "invalid bandwidth\n");
12990 		break;
12991 	case -ENODEV:
12992 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12993 		break;
12994 	case -ENOTSUP:
12995 		fprintf(stderr, "function not implemented\n");
12996 		break;
12997 	default:
12998 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12999 	}
13000 }
13001 
13002 cmdline_parse_inst_t cmd_tc_min_bw = {
13003 	.f = cmd_tc_min_bw_parsed,
13004 	.data = NULL,
13005 	.help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13006 	.tokens = {
13007 		(void *)&cmd_vf_tc_bw_set,
13008 		(void *)&cmd_vf_tc_bw_tc,
13009 		(void *)&cmd_vf_tc_bw_tx,
13010 		(void *)&cmd_vf_tc_bw_min_bw,
13011 		(void *)&cmd_vf_tc_bw_port_id,
13012 		(void *)&cmd_vf_tc_bw_bw_list,
13013 		NULL,
13014 	},
13015 };
13016 
13017 /* TC max bandwidth setting */
13018 static void
13019 cmd_vf_tc_max_bw_parsed(
13020 	void *parsed_result,
13021 	__rte_unused struct cmdline *cl,
13022 	__rte_unused void *data)
13023 {
13024 	struct cmd_vf_tc_bw_result *res = parsed_result;
13025 	int ret = -ENOTSUP;
13026 
13027 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13028 		return;
13029 
13030 #ifdef RTE_NET_I40E
13031 	ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13032 					    res->tc_no, res->bw);
13033 #endif
13034 
13035 	switch (ret) {
13036 	case 0:
13037 		break;
13038 	case -EINVAL:
13039 		fprintf(stderr,
13040 			"invalid vf_id %d, tc_no %d or bandwidth %d\n",
13041 			res->vf_id, res->tc_no, res->bw);
13042 		break;
13043 	case -ENODEV:
13044 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
13045 		break;
13046 	case -ENOTSUP:
13047 		fprintf(stderr, "function not implemented\n");
13048 		break;
13049 	default:
13050 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
13051 	}
13052 }
13053 
13054 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13055 	.f = cmd_vf_tc_max_bw_parsed,
13056 	.data = NULL,
13057 	.help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13058 		    " <bandwidth>",
13059 	.tokens = {
13060 		(void *)&cmd_vf_tc_bw_set,
13061 		(void *)&cmd_vf_tc_bw_vf,
13062 		(void *)&cmd_vf_tc_bw_tc,
13063 		(void *)&cmd_vf_tc_bw_tx,
13064 		(void *)&cmd_vf_tc_bw_max_bw,
13065 		(void *)&cmd_vf_tc_bw_port_id,
13066 		(void *)&cmd_vf_tc_bw_vf_id,
13067 		(void *)&cmd_vf_tc_bw_tc_no,
13068 		(void *)&cmd_vf_tc_bw_bw,
13069 		NULL,
13070 	},
13071 };
13072 
13073 /** Set VXLAN encapsulation details */
13074 struct cmd_set_vxlan_result {
13075 	cmdline_fixed_string_t set;
13076 	cmdline_fixed_string_t vxlan;
13077 	cmdline_fixed_string_t pos_token;
13078 	cmdline_fixed_string_t ip_version;
13079 	uint32_t vlan_present:1;
13080 	uint32_t vni;
13081 	uint16_t udp_src;
13082 	uint16_t udp_dst;
13083 	cmdline_ipaddr_t ip_src;
13084 	cmdline_ipaddr_t ip_dst;
13085 	uint16_t tci;
13086 	uint8_t tos;
13087 	uint8_t ttl;
13088 	struct rte_ether_addr eth_src;
13089 	struct rte_ether_addr eth_dst;
13090 };
13091 
13092 cmdline_parse_token_string_t cmd_set_vxlan_set =
13093 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
13094 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
13095 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
13096 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
13097 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13098 				 "vxlan-tos-ttl");
13099 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
13100 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13101 				 "vxlan-with-vlan");
13102 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
13103 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13104 				 "ip-version");
13105 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
13106 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
13107 				 "ipv4#ipv6");
13108 cmdline_parse_token_string_t cmd_set_vxlan_vni =
13109 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13110 				 "vni");
13111 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
13112 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
13113 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
13114 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13115 				 "udp-src");
13116 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
13117 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
13118 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
13119 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13120 				 "udp-dst");
13121 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
13122 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
13123 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
13124 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13125 				 "ip-tos");
13126 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
13127 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
13128 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
13129 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13130 				 "ip-ttl");
13131 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
13132 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
13133 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
13134 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13135 				 "ip-src");
13136 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
13137 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
13138 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
13139 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13140 				 "ip-dst");
13141 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
13142 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
13143 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
13144 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13145 				 "vlan-tci");
13146 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
13147 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
13148 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
13149 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13150 				 "eth-src");
13151 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
13152 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
13153 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
13154 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13155 				 "eth-dst");
13156 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
13157 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
13158 
13159 static void cmd_set_vxlan_parsed(void *parsed_result,
13160 	__rte_unused struct cmdline *cl,
13161 	__rte_unused void *data)
13162 {
13163 	struct cmd_set_vxlan_result *res = parsed_result;
13164 	union {
13165 		uint32_t vxlan_id;
13166 		uint8_t vni[4];
13167 	} id = {
13168 		.vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
13169 	};
13170 
13171 	vxlan_encap_conf.select_tos_ttl = 0;
13172 	if (strcmp(res->vxlan, "vxlan") == 0)
13173 		vxlan_encap_conf.select_vlan = 0;
13174 	else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
13175 		vxlan_encap_conf.select_vlan = 1;
13176 	else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
13177 		vxlan_encap_conf.select_vlan = 0;
13178 		vxlan_encap_conf.select_tos_ttl = 1;
13179 	}
13180 	if (strcmp(res->ip_version, "ipv4") == 0)
13181 		vxlan_encap_conf.select_ipv4 = 1;
13182 	else if (strcmp(res->ip_version, "ipv6") == 0)
13183 		vxlan_encap_conf.select_ipv4 = 0;
13184 	else
13185 		return;
13186 	rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
13187 	vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13188 	vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13189 	vxlan_encap_conf.ip_tos = res->tos;
13190 	vxlan_encap_conf.ip_ttl = res->ttl;
13191 	if (vxlan_encap_conf.select_ipv4) {
13192 		IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
13193 		IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
13194 	} else {
13195 		IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
13196 		IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
13197 	}
13198 	if (vxlan_encap_conf.select_vlan)
13199 		vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13200 	rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
13201 		   RTE_ETHER_ADDR_LEN);
13202 	rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13203 		   RTE_ETHER_ADDR_LEN);
13204 }
13205 
13206 cmdline_parse_inst_t cmd_set_vxlan = {
13207 	.f = cmd_set_vxlan_parsed,
13208 	.data = NULL,
13209 	.help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
13210 		" <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
13211 		" eth-src <eth-src> eth-dst <eth-dst>",
13212 	.tokens = {
13213 		(void *)&cmd_set_vxlan_set,
13214 		(void *)&cmd_set_vxlan_vxlan,
13215 		(void *)&cmd_set_vxlan_ip_version,
13216 		(void *)&cmd_set_vxlan_ip_version_value,
13217 		(void *)&cmd_set_vxlan_vni,
13218 		(void *)&cmd_set_vxlan_vni_value,
13219 		(void *)&cmd_set_vxlan_udp_src,
13220 		(void *)&cmd_set_vxlan_udp_src_value,
13221 		(void *)&cmd_set_vxlan_udp_dst,
13222 		(void *)&cmd_set_vxlan_udp_dst_value,
13223 		(void *)&cmd_set_vxlan_ip_src,
13224 		(void *)&cmd_set_vxlan_ip_src_value,
13225 		(void *)&cmd_set_vxlan_ip_dst,
13226 		(void *)&cmd_set_vxlan_ip_dst_value,
13227 		(void *)&cmd_set_vxlan_eth_src,
13228 		(void *)&cmd_set_vxlan_eth_src_value,
13229 		(void *)&cmd_set_vxlan_eth_dst,
13230 		(void *)&cmd_set_vxlan_eth_dst_value,
13231 		NULL,
13232 	},
13233 };
13234 
13235 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
13236 	.f = cmd_set_vxlan_parsed,
13237 	.data = NULL,
13238 	.help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
13239 		" <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
13240 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13241 		" eth-dst <eth-dst>",
13242 	.tokens = {
13243 		(void *)&cmd_set_vxlan_set,
13244 		(void *)&cmd_set_vxlan_vxlan_tos_ttl,
13245 		(void *)&cmd_set_vxlan_ip_version,
13246 		(void *)&cmd_set_vxlan_ip_version_value,
13247 		(void *)&cmd_set_vxlan_vni,
13248 		(void *)&cmd_set_vxlan_vni_value,
13249 		(void *)&cmd_set_vxlan_udp_src,
13250 		(void *)&cmd_set_vxlan_udp_src_value,
13251 		(void *)&cmd_set_vxlan_udp_dst,
13252 		(void *)&cmd_set_vxlan_udp_dst_value,
13253 		(void *)&cmd_set_vxlan_ip_tos,
13254 		(void *)&cmd_set_vxlan_ip_tos_value,
13255 		(void *)&cmd_set_vxlan_ip_ttl,
13256 		(void *)&cmd_set_vxlan_ip_ttl_value,
13257 		(void *)&cmd_set_vxlan_ip_src,
13258 		(void *)&cmd_set_vxlan_ip_src_value,
13259 		(void *)&cmd_set_vxlan_ip_dst,
13260 		(void *)&cmd_set_vxlan_ip_dst_value,
13261 		(void *)&cmd_set_vxlan_eth_src,
13262 		(void *)&cmd_set_vxlan_eth_src_value,
13263 		(void *)&cmd_set_vxlan_eth_dst,
13264 		(void *)&cmd_set_vxlan_eth_dst_value,
13265 		NULL,
13266 	},
13267 };
13268 
13269 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
13270 	.f = cmd_set_vxlan_parsed,
13271 	.data = NULL,
13272 	.help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
13273 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
13274 		" <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
13275 		" <eth-dst>",
13276 	.tokens = {
13277 		(void *)&cmd_set_vxlan_set,
13278 		(void *)&cmd_set_vxlan_vxlan_with_vlan,
13279 		(void *)&cmd_set_vxlan_ip_version,
13280 		(void *)&cmd_set_vxlan_ip_version_value,
13281 		(void *)&cmd_set_vxlan_vni,
13282 		(void *)&cmd_set_vxlan_vni_value,
13283 		(void *)&cmd_set_vxlan_udp_src,
13284 		(void *)&cmd_set_vxlan_udp_src_value,
13285 		(void *)&cmd_set_vxlan_udp_dst,
13286 		(void *)&cmd_set_vxlan_udp_dst_value,
13287 		(void *)&cmd_set_vxlan_ip_src,
13288 		(void *)&cmd_set_vxlan_ip_src_value,
13289 		(void *)&cmd_set_vxlan_ip_dst,
13290 		(void *)&cmd_set_vxlan_ip_dst_value,
13291 		(void *)&cmd_set_vxlan_vlan,
13292 		(void *)&cmd_set_vxlan_vlan_value,
13293 		(void *)&cmd_set_vxlan_eth_src,
13294 		(void *)&cmd_set_vxlan_eth_src_value,
13295 		(void *)&cmd_set_vxlan_eth_dst,
13296 		(void *)&cmd_set_vxlan_eth_dst_value,
13297 		NULL,
13298 	},
13299 };
13300 
13301 /** Set NVGRE encapsulation details */
13302 struct cmd_set_nvgre_result {
13303 	cmdline_fixed_string_t set;
13304 	cmdline_fixed_string_t nvgre;
13305 	cmdline_fixed_string_t pos_token;
13306 	cmdline_fixed_string_t ip_version;
13307 	uint32_t tni;
13308 	cmdline_ipaddr_t ip_src;
13309 	cmdline_ipaddr_t ip_dst;
13310 	uint16_t tci;
13311 	struct rte_ether_addr eth_src;
13312 	struct rte_ether_addr eth_dst;
13313 };
13314 
13315 cmdline_parse_token_string_t cmd_set_nvgre_set =
13316 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13317 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13318 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13319 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13320 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13321 				 "nvgre-with-vlan");
13322 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13323 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13324 				 "ip-version");
13325 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13326 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13327 				 "ipv4#ipv6");
13328 cmdline_parse_token_string_t cmd_set_nvgre_tni =
13329 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13330 				 "tni");
13331 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13332 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
13333 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13334 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13335 				 "ip-src");
13336 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13337 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13338 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13339 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13340 				 "ip-dst");
13341 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13342 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13343 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13344 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13345 				 "vlan-tci");
13346 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13347 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
13348 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13349 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13350 				 "eth-src");
13351 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13352 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13353 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13354 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13355 				 "eth-dst");
13356 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13357 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13358 
13359 static void cmd_set_nvgre_parsed(void *parsed_result,
13360 	__rte_unused struct cmdline *cl,
13361 	__rte_unused void *data)
13362 {
13363 	struct cmd_set_nvgre_result *res = parsed_result;
13364 	union {
13365 		uint32_t nvgre_tni;
13366 		uint8_t tni[4];
13367 	} id = {
13368 		.nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13369 	};
13370 
13371 	if (strcmp(res->nvgre, "nvgre") == 0)
13372 		nvgre_encap_conf.select_vlan = 0;
13373 	else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13374 		nvgre_encap_conf.select_vlan = 1;
13375 	if (strcmp(res->ip_version, "ipv4") == 0)
13376 		nvgre_encap_conf.select_ipv4 = 1;
13377 	else if (strcmp(res->ip_version, "ipv6") == 0)
13378 		nvgre_encap_conf.select_ipv4 = 0;
13379 	else
13380 		return;
13381 	rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13382 	if (nvgre_encap_conf.select_ipv4) {
13383 		IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13384 		IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13385 	} else {
13386 		IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13387 		IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13388 	}
13389 	if (nvgre_encap_conf.select_vlan)
13390 		nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13391 	rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13392 		   RTE_ETHER_ADDR_LEN);
13393 	rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13394 		   RTE_ETHER_ADDR_LEN);
13395 }
13396 
13397 cmdline_parse_inst_t cmd_set_nvgre = {
13398 	.f = cmd_set_nvgre_parsed,
13399 	.data = NULL,
13400 	.help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13401 		" <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13402 		" eth-dst <eth-dst>",
13403 	.tokens = {
13404 		(void *)&cmd_set_nvgre_set,
13405 		(void *)&cmd_set_nvgre_nvgre,
13406 		(void *)&cmd_set_nvgre_ip_version,
13407 		(void *)&cmd_set_nvgre_ip_version_value,
13408 		(void *)&cmd_set_nvgre_tni,
13409 		(void *)&cmd_set_nvgre_tni_value,
13410 		(void *)&cmd_set_nvgre_ip_src,
13411 		(void *)&cmd_set_nvgre_ip_src_value,
13412 		(void *)&cmd_set_nvgre_ip_dst,
13413 		(void *)&cmd_set_nvgre_ip_dst_value,
13414 		(void *)&cmd_set_nvgre_eth_src,
13415 		(void *)&cmd_set_nvgre_eth_src_value,
13416 		(void *)&cmd_set_nvgre_eth_dst,
13417 		(void *)&cmd_set_nvgre_eth_dst_value,
13418 		NULL,
13419 	},
13420 };
13421 
13422 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13423 	.f = cmd_set_nvgre_parsed,
13424 	.data = NULL,
13425 	.help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13426 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13427 		" eth-src <eth-src> eth-dst <eth-dst>",
13428 	.tokens = {
13429 		(void *)&cmd_set_nvgre_set,
13430 		(void *)&cmd_set_nvgre_nvgre_with_vlan,
13431 		(void *)&cmd_set_nvgre_ip_version,
13432 		(void *)&cmd_set_nvgre_ip_version_value,
13433 		(void *)&cmd_set_nvgre_tni,
13434 		(void *)&cmd_set_nvgre_tni_value,
13435 		(void *)&cmd_set_nvgre_ip_src,
13436 		(void *)&cmd_set_nvgre_ip_src_value,
13437 		(void *)&cmd_set_nvgre_ip_dst,
13438 		(void *)&cmd_set_nvgre_ip_dst_value,
13439 		(void *)&cmd_set_nvgre_vlan,
13440 		(void *)&cmd_set_nvgre_vlan_value,
13441 		(void *)&cmd_set_nvgre_eth_src,
13442 		(void *)&cmd_set_nvgre_eth_src_value,
13443 		(void *)&cmd_set_nvgre_eth_dst,
13444 		(void *)&cmd_set_nvgre_eth_dst_value,
13445 		NULL,
13446 	},
13447 };
13448 
13449 /** Set L2 encapsulation details */
13450 struct cmd_set_l2_encap_result {
13451 	cmdline_fixed_string_t set;
13452 	cmdline_fixed_string_t l2_encap;
13453 	cmdline_fixed_string_t pos_token;
13454 	cmdline_fixed_string_t ip_version;
13455 	uint32_t vlan_present:1;
13456 	uint16_t tci;
13457 	struct rte_ether_addr eth_src;
13458 	struct rte_ether_addr eth_dst;
13459 };
13460 
13461 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13462 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13463 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13464 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13465 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13466 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13467 				 "l2_encap-with-vlan");
13468 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13469 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13470 				 "ip-version");
13471 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13472 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13473 				 "ipv4#ipv6");
13474 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13475 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13476 				 "vlan-tci");
13477 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13478 	TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13479 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13480 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13481 				 "eth-src");
13482 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13483 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13484 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13485 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13486 				 "eth-dst");
13487 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13488 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13489 
13490 static void cmd_set_l2_encap_parsed(void *parsed_result,
13491 	__rte_unused struct cmdline *cl,
13492 	__rte_unused void *data)
13493 {
13494 	struct cmd_set_l2_encap_result *res = parsed_result;
13495 
13496 	if (strcmp(res->l2_encap, "l2_encap") == 0)
13497 		l2_encap_conf.select_vlan = 0;
13498 	else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13499 		l2_encap_conf.select_vlan = 1;
13500 	if (strcmp(res->ip_version, "ipv4") == 0)
13501 		l2_encap_conf.select_ipv4 = 1;
13502 	else if (strcmp(res->ip_version, "ipv6") == 0)
13503 		l2_encap_conf.select_ipv4 = 0;
13504 	else
13505 		return;
13506 	if (l2_encap_conf.select_vlan)
13507 		l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13508 	rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13509 		   RTE_ETHER_ADDR_LEN);
13510 	rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13511 		   RTE_ETHER_ADDR_LEN);
13512 }
13513 
13514 cmdline_parse_inst_t cmd_set_l2_encap = {
13515 	.f = cmd_set_l2_encap_parsed,
13516 	.data = NULL,
13517 	.help_str = "set l2_encap ip-version ipv4|ipv6"
13518 		" eth-src <eth-src> eth-dst <eth-dst>",
13519 	.tokens = {
13520 		(void *)&cmd_set_l2_encap_set,
13521 		(void *)&cmd_set_l2_encap_l2_encap,
13522 		(void *)&cmd_set_l2_encap_ip_version,
13523 		(void *)&cmd_set_l2_encap_ip_version_value,
13524 		(void *)&cmd_set_l2_encap_eth_src,
13525 		(void *)&cmd_set_l2_encap_eth_src_value,
13526 		(void *)&cmd_set_l2_encap_eth_dst,
13527 		(void *)&cmd_set_l2_encap_eth_dst_value,
13528 		NULL,
13529 	},
13530 };
13531 
13532 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13533 	.f = cmd_set_l2_encap_parsed,
13534 	.data = NULL,
13535 	.help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13536 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13537 	.tokens = {
13538 		(void *)&cmd_set_l2_encap_set,
13539 		(void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13540 		(void *)&cmd_set_l2_encap_ip_version,
13541 		(void *)&cmd_set_l2_encap_ip_version_value,
13542 		(void *)&cmd_set_l2_encap_vlan,
13543 		(void *)&cmd_set_l2_encap_vlan_value,
13544 		(void *)&cmd_set_l2_encap_eth_src,
13545 		(void *)&cmd_set_l2_encap_eth_src_value,
13546 		(void *)&cmd_set_l2_encap_eth_dst,
13547 		(void *)&cmd_set_l2_encap_eth_dst_value,
13548 		NULL,
13549 	},
13550 };
13551 
13552 /** Set L2 decapsulation details */
13553 struct cmd_set_l2_decap_result {
13554 	cmdline_fixed_string_t set;
13555 	cmdline_fixed_string_t l2_decap;
13556 	cmdline_fixed_string_t pos_token;
13557 	uint32_t vlan_present:1;
13558 };
13559 
13560 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13561 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13562 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13563 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13564 				 "l2_decap");
13565 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13566 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13567 				 "l2_decap-with-vlan");
13568 
13569 static void cmd_set_l2_decap_parsed(void *parsed_result,
13570 	__rte_unused struct cmdline *cl,
13571 	__rte_unused void *data)
13572 {
13573 	struct cmd_set_l2_decap_result *res = parsed_result;
13574 
13575 	if (strcmp(res->l2_decap, "l2_decap") == 0)
13576 		l2_decap_conf.select_vlan = 0;
13577 	else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13578 		l2_decap_conf.select_vlan = 1;
13579 }
13580 
13581 cmdline_parse_inst_t cmd_set_l2_decap = {
13582 	.f = cmd_set_l2_decap_parsed,
13583 	.data = NULL,
13584 	.help_str = "set l2_decap",
13585 	.tokens = {
13586 		(void *)&cmd_set_l2_decap_set,
13587 		(void *)&cmd_set_l2_decap_l2_decap,
13588 		NULL,
13589 	},
13590 };
13591 
13592 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13593 	.f = cmd_set_l2_decap_parsed,
13594 	.data = NULL,
13595 	.help_str = "set l2_decap-with-vlan",
13596 	.tokens = {
13597 		(void *)&cmd_set_l2_decap_set,
13598 		(void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13599 		NULL,
13600 	},
13601 };
13602 
13603 /** Set MPLSoGRE encapsulation details */
13604 struct cmd_set_mplsogre_encap_result {
13605 	cmdline_fixed_string_t set;
13606 	cmdline_fixed_string_t mplsogre;
13607 	cmdline_fixed_string_t pos_token;
13608 	cmdline_fixed_string_t ip_version;
13609 	uint32_t vlan_present:1;
13610 	uint32_t label;
13611 	cmdline_ipaddr_t ip_src;
13612 	cmdline_ipaddr_t ip_dst;
13613 	uint16_t tci;
13614 	struct rte_ether_addr eth_src;
13615 	struct rte_ether_addr eth_dst;
13616 };
13617 
13618 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13619 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13620 				 "set");
13621 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13622 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13623 				 "mplsogre_encap");
13624 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13625 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13626 				 mplsogre, "mplsogre_encap-with-vlan");
13627 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13628 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13629 				 pos_token, "ip-version");
13630 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13631 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13632 				 ip_version, "ipv4#ipv6");
13633 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13634 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13635 				 pos_token, "label");
13636 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13637 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13638 			      RTE_UINT32);
13639 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13640 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13641 				 pos_token, "ip-src");
13642 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13643 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13644 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13645 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13646 				 pos_token, "ip-dst");
13647 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13648 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13649 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13650 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13651 				 pos_token, "vlan-tci");
13652 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13653 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13654 			      RTE_UINT16);
13655 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13656 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13657 				 pos_token, "eth-src");
13658 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13659 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13660 				    eth_src);
13661 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13662 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13663 				 pos_token, "eth-dst");
13664 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13665 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13666 				    eth_dst);
13667 
13668 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13669 	__rte_unused struct cmdline *cl,
13670 	__rte_unused void *data)
13671 {
13672 	struct cmd_set_mplsogre_encap_result *res = parsed_result;
13673 	union {
13674 		uint32_t mplsogre_label;
13675 		uint8_t label[4];
13676 	} id = {
13677 		.mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13678 	};
13679 
13680 	if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13681 		mplsogre_encap_conf.select_vlan = 0;
13682 	else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13683 		mplsogre_encap_conf.select_vlan = 1;
13684 	if (strcmp(res->ip_version, "ipv4") == 0)
13685 		mplsogre_encap_conf.select_ipv4 = 1;
13686 	else if (strcmp(res->ip_version, "ipv6") == 0)
13687 		mplsogre_encap_conf.select_ipv4 = 0;
13688 	else
13689 		return;
13690 	rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13691 	if (mplsogre_encap_conf.select_ipv4) {
13692 		IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13693 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13694 	} else {
13695 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13696 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13697 	}
13698 	if (mplsogre_encap_conf.select_vlan)
13699 		mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13700 	rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13701 		   RTE_ETHER_ADDR_LEN);
13702 	rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13703 		   RTE_ETHER_ADDR_LEN);
13704 }
13705 
13706 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13707 	.f = cmd_set_mplsogre_encap_parsed,
13708 	.data = NULL,
13709 	.help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13710 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13711 		" eth-dst <eth-dst>",
13712 	.tokens = {
13713 		(void *)&cmd_set_mplsogre_encap_set,
13714 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13715 		(void *)&cmd_set_mplsogre_encap_ip_version,
13716 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
13717 		(void *)&cmd_set_mplsogre_encap_label,
13718 		(void *)&cmd_set_mplsogre_encap_label_value,
13719 		(void *)&cmd_set_mplsogre_encap_ip_src,
13720 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
13721 		(void *)&cmd_set_mplsogre_encap_ip_dst,
13722 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
13723 		(void *)&cmd_set_mplsogre_encap_eth_src,
13724 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
13725 		(void *)&cmd_set_mplsogre_encap_eth_dst,
13726 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
13727 		NULL,
13728 	},
13729 };
13730 
13731 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13732 	.f = cmd_set_mplsogre_encap_parsed,
13733 	.data = NULL,
13734 	.help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13735 		" label <label> ip-src <ip-src> ip-dst <ip-dst>"
13736 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13737 	.tokens = {
13738 		(void *)&cmd_set_mplsogre_encap_set,
13739 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13740 		(void *)&cmd_set_mplsogre_encap_ip_version,
13741 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
13742 		(void *)&cmd_set_mplsogre_encap_label,
13743 		(void *)&cmd_set_mplsogre_encap_label_value,
13744 		(void *)&cmd_set_mplsogre_encap_ip_src,
13745 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
13746 		(void *)&cmd_set_mplsogre_encap_ip_dst,
13747 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
13748 		(void *)&cmd_set_mplsogre_encap_vlan,
13749 		(void *)&cmd_set_mplsogre_encap_vlan_value,
13750 		(void *)&cmd_set_mplsogre_encap_eth_src,
13751 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
13752 		(void *)&cmd_set_mplsogre_encap_eth_dst,
13753 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
13754 		NULL,
13755 	},
13756 };
13757 
13758 /** Set MPLSoGRE decapsulation details */
13759 struct cmd_set_mplsogre_decap_result {
13760 	cmdline_fixed_string_t set;
13761 	cmdline_fixed_string_t mplsogre;
13762 	cmdline_fixed_string_t pos_token;
13763 	cmdline_fixed_string_t ip_version;
13764 	uint32_t vlan_present:1;
13765 };
13766 
13767 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13768 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13769 				 "set");
13770 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13771 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13772 				 "mplsogre_decap");
13773 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13774 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13775 				 mplsogre, "mplsogre_decap-with-vlan");
13776 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13777 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13778 				 pos_token, "ip-version");
13779 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13780 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13781 				 ip_version, "ipv4#ipv6");
13782 
13783 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13784 	__rte_unused struct cmdline *cl,
13785 	__rte_unused void *data)
13786 {
13787 	struct cmd_set_mplsogre_decap_result *res = parsed_result;
13788 
13789 	if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13790 		mplsogre_decap_conf.select_vlan = 0;
13791 	else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13792 		mplsogre_decap_conf.select_vlan = 1;
13793 	if (strcmp(res->ip_version, "ipv4") == 0)
13794 		mplsogre_decap_conf.select_ipv4 = 1;
13795 	else if (strcmp(res->ip_version, "ipv6") == 0)
13796 		mplsogre_decap_conf.select_ipv4 = 0;
13797 }
13798 
13799 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13800 	.f = cmd_set_mplsogre_decap_parsed,
13801 	.data = NULL,
13802 	.help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13803 	.tokens = {
13804 		(void *)&cmd_set_mplsogre_decap_set,
13805 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13806 		(void *)&cmd_set_mplsogre_decap_ip_version,
13807 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
13808 		NULL,
13809 	},
13810 };
13811 
13812 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13813 	.f = cmd_set_mplsogre_decap_parsed,
13814 	.data = NULL,
13815 	.help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13816 	.tokens = {
13817 		(void *)&cmd_set_mplsogre_decap_set,
13818 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13819 		(void *)&cmd_set_mplsogre_decap_ip_version,
13820 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
13821 		NULL,
13822 	},
13823 };
13824 
13825 /** Set MPLSoUDP encapsulation details */
13826 struct cmd_set_mplsoudp_encap_result {
13827 	cmdline_fixed_string_t set;
13828 	cmdline_fixed_string_t mplsoudp;
13829 	cmdline_fixed_string_t pos_token;
13830 	cmdline_fixed_string_t ip_version;
13831 	uint32_t vlan_present:1;
13832 	uint32_t label;
13833 	uint16_t udp_src;
13834 	uint16_t udp_dst;
13835 	cmdline_ipaddr_t ip_src;
13836 	cmdline_ipaddr_t ip_dst;
13837 	uint16_t tci;
13838 	struct rte_ether_addr eth_src;
13839 	struct rte_ether_addr eth_dst;
13840 };
13841 
13842 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13843 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13844 				 "set");
13845 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13846 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13847 				 "mplsoudp_encap");
13848 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13849 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13850 				 mplsoudp, "mplsoudp_encap-with-vlan");
13851 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13852 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13853 				 pos_token, "ip-version");
13854 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13855 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13856 				 ip_version, "ipv4#ipv6");
13857 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13858 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13859 				 pos_token, "label");
13860 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13861 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13862 			      RTE_UINT32);
13863 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13864 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13865 				 pos_token, "udp-src");
13866 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13867 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13868 			      RTE_UINT16);
13869 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13870 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13871 				 pos_token, "udp-dst");
13872 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13873 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13874 			      RTE_UINT16);
13875 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13876 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13877 				 pos_token, "ip-src");
13878 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13879 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13880 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13881 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13882 				 pos_token, "ip-dst");
13883 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13884 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13885 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13886 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13887 				 pos_token, "vlan-tci");
13888 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13889 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13890 			      RTE_UINT16);
13891 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13892 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13893 				 pos_token, "eth-src");
13894 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13895 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13896 				    eth_src);
13897 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13898 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13899 				 pos_token, "eth-dst");
13900 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13901 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13902 				    eth_dst);
13903 
13904 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13905 	__rte_unused struct cmdline *cl,
13906 	__rte_unused void *data)
13907 {
13908 	struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13909 	union {
13910 		uint32_t mplsoudp_label;
13911 		uint8_t label[4];
13912 	} id = {
13913 		.mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13914 	};
13915 
13916 	if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13917 		mplsoudp_encap_conf.select_vlan = 0;
13918 	else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13919 		mplsoudp_encap_conf.select_vlan = 1;
13920 	if (strcmp(res->ip_version, "ipv4") == 0)
13921 		mplsoudp_encap_conf.select_ipv4 = 1;
13922 	else if (strcmp(res->ip_version, "ipv6") == 0)
13923 		mplsoudp_encap_conf.select_ipv4 = 0;
13924 	else
13925 		return;
13926 	rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13927 	mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13928 	mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13929 	if (mplsoudp_encap_conf.select_ipv4) {
13930 		IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13931 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13932 	} else {
13933 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13934 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13935 	}
13936 	if (mplsoudp_encap_conf.select_vlan)
13937 		mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13938 	rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13939 		   RTE_ETHER_ADDR_LEN);
13940 	rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13941 		   RTE_ETHER_ADDR_LEN);
13942 }
13943 
13944 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13945 	.f = cmd_set_mplsoudp_encap_parsed,
13946 	.data = NULL,
13947 	.help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13948 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13949 		" ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13950 	.tokens = {
13951 		(void *)&cmd_set_mplsoudp_encap_set,
13952 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13953 		(void *)&cmd_set_mplsoudp_encap_ip_version,
13954 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
13955 		(void *)&cmd_set_mplsoudp_encap_label,
13956 		(void *)&cmd_set_mplsoudp_encap_label_value,
13957 		(void *)&cmd_set_mplsoudp_encap_udp_src,
13958 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
13959 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
13960 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13961 		(void *)&cmd_set_mplsoudp_encap_ip_src,
13962 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
13963 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
13964 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13965 		(void *)&cmd_set_mplsoudp_encap_eth_src,
13966 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
13967 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
13968 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13969 		NULL,
13970 	},
13971 };
13972 
13973 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13974 	.f = cmd_set_mplsoudp_encap_parsed,
13975 	.data = NULL,
13976 	.help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13977 		" label <label> udp-src <udp-src> udp-dst <udp-dst>"
13978 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13979 		" eth-src <eth-src> eth-dst <eth-dst>",
13980 	.tokens = {
13981 		(void *)&cmd_set_mplsoudp_encap_set,
13982 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13983 		(void *)&cmd_set_mplsoudp_encap_ip_version,
13984 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
13985 		(void *)&cmd_set_mplsoudp_encap_label,
13986 		(void *)&cmd_set_mplsoudp_encap_label_value,
13987 		(void *)&cmd_set_mplsoudp_encap_udp_src,
13988 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
13989 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
13990 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13991 		(void *)&cmd_set_mplsoudp_encap_ip_src,
13992 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
13993 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
13994 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13995 		(void *)&cmd_set_mplsoudp_encap_vlan,
13996 		(void *)&cmd_set_mplsoudp_encap_vlan_value,
13997 		(void *)&cmd_set_mplsoudp_encap_eth_src,
13998 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
13999 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
14000 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
14001 		NULL,
14002 	},
14003 };
14004 
14005 /** Set MPLSoUDP decapsulation details */
14006 struct cmd_set_mplsoudp_decap_result {
14007 	cmdline_fixed_string_t set;
14008 	cmdline_fixed_string_t mplsoudp;
14009 	cmdline_fixed_string_t pos_token;
14010 	cmdline_fixed_string_t ip_version;
14011 	uint32_t vlan_present:1;
14012 };
14013 
14014 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
14015 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
14016 				 "set");
14017 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
14018 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
14019 				 "mplsoudp_decap");
14020 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
14021 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14022 				 mplsoudp, "mplsoudp_decap-with-vlan");
14023 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
14024 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14025 				 pos_token, "ip-version");
14026 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
14027 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14028 				 ip_version, "ipv4#ipv6");
14029 
14030 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
14031 	__rte_unused struct cmdline *cl,
14032 	__rte_unused void *data)
14033 {
14034 	struct cmd_set_mplsoudp_decap_result *res = parsed_result;
14035 
14036 	if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
14037 		mplsoudp_decap_conf.select_vlan = 0;
14038 	else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
14039 		mplsoudp_decap_conf.select_vlan = 1;
14040 	if (strcmp(res->ip_version, "ipv4") == 0)
14041 		mplsoudp_decap_conf.select_ipv4 = 1;
14042 	else if (strcmp(res->ip_version, "ipv6") == 0)
14043 		mplsoudp_decap_conf.select_ipv4 = 0;
14044 }
14045 
14046 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
14047 	.f = cmd_set_mplsoudp_decap_parsed,
14048 	.data = NULL,
14049 	.help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
14050 	.tokens = {
14051 		(void *)&cmd_set_mplsoudp_decap_set,
14052 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
14053 		(void *)&cmd_set_mplsoudp_decap_ip_version,
14054 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
14055 		NULL,
14056 	},
14057 };
14058 
14059 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
14060 	.f = cmd_set_mplsoudp_decap_parsed,
14061 	.data = NULL,
14062 	.help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
14063 	.tokens = {
14064 		(void *)&cmd_set_mplsoudp_decap_set,
14065 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
14066 		(void *)&cmd_set_mplsoudp_decap_ip_version,
14067 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
14068 		NULL,
14069 	},
14070 };
14071 
14072 /** Set connection tracking object common details */
14073 struct cmd_set_conntrack_common_result {
14074 	cmdline_fixed_string_t set;
14075 	cmdline_fixed_string_t conntrack;
14076 	cmdline_fixed_string_t common;
14077 	cmdline_fixed_string_t peer;
14078 	cmdline_fixed_string_t is_orig;
14079 	cmdline_fixed_string_t enable;
14080 	cmdline_fixed_string_t live;
14081 	cmdline_fixed_string_t sack;
14082 	cmdline_fixed_string_t cack;
14083 	cmdline_fixed_string_t last_dir;
14084 	cmdline_fixed_string_t liberal;
14085 	cmdline_fixed_string_t state;
14086 	cmdline_fixed_string_t max_ack_win;
14087 	cmdline_fixed_string_t retrans;
14088 	cmdline_fixed_string_t last_win;
14089 	cmdline_fixed_string_t last_seq;
14090 	cmdline_fixed_string_t last_ack;
14091 	cmdline_fixed_string_t last_end;
14092 	cmdline_fixed_string_t last_index;
14093 	uint8_t stat;
14094 	uint8_t factor;
14095 	uint16_t peer_port;
14096 	uint32_t is_original;
14097 	uint32_t en;
14098 	uint32_t is_live;
14099 	uint32_t s_ack;
14100 	uint32_t c_ack;
14101 	uint32_t ld;
14102 	uint32_t lb;
14103 	uint8_t re_num;
14104 	uint8_t li;
14105 	uint16_t lw;
14106 	uint32_t ls;
14107 	uint32_t la;
14108 	uint32_t le;
14109 };
14110 
14111 cmdline_parse_token_string_t cmd_set_conntrack_set =
14112 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14113 				 set, "set");
14114 cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
14115 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14116 				 conntrack, "conntrack");
14117 cmdline_parse_token_string_t cmd_set_conntrack_common_com =
14118 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14119 				 common, "com");
14120 cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
14121 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14122 				 peer, "peer");
14123 cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
14124 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14125 			      peer_port, RTE_UINT16);
14126 cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
14127 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14128 				 is_orig, "is_orig");
14129 cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
14130 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14131 			      is_original, RTE_UINT32);
14132 cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
14133 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14134 				 enable, "enable");
14135 cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
14136 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14137 			      en, RTE_UINT32);
14138 cmdline_parse_token_string_t cmd_set_conntrack_common_live =
14139 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14140 				 live, "live");
14141 cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
14142 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14143 			      is_live, RTE_UINT32);
14144 cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
14145 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14146 				 sack, "sack");
14147 cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
14148 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14149 			      s_ack, RTE_UINT32);
14150 cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
14151 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14152 				 cack, "cack");
14153 cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
14154 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14155 			      c_ack, RTE_UINT32);
14156 cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
14157 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14158 				 last_dir, "last_dir");
14159 cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
14160 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14161 			      ld, RTE_UINT32);
14162 cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
14163 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14164 				 liberal, "liberal");
14165 cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
14166 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14167 			      lb, RTE_UINT32);
14168 cmdline_parse_token_string_t cmd_set_conntrack_common_state =
14169 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14170 				 state, "state");
14171 cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
14172 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14173 			      stat, RTE_UINT8);
14174 cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
14175 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14176 				 max_ack_win, "max_ack_win");
14177 cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
14178 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14179 			      factor, RTE_UINT8);
14180 cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
14181 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14182 				 retrans, "r_lim");
14183 cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
14184 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14185 			      re_num, RTE_UINT8);
14186 cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
14187 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14188 				 last_win, "last_win");
14189 cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
14190 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14191 			      lw, RTE_UINT16);
14192 cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
14193 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14194 				 last_seq, "last_seq");
14195 cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
14196 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14197 			      ls, RTE_UINT32);
14198 cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
14199 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14200 				 last_ack, "last_ack");
14201 cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
14202 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14203 			      la, RTE_UINT32);
14204 cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
14205 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14206 				 last_end, "last_end");
14207 cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
14208 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14209 			      le, RTE_UINT32);
14210 cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
14211 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14212 				 last_index, "last_index");
14213 cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
14214 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14215 			      li, RTE_UINT8);
14216 
14217 static void cmd_set_conntrack_common_parsed(void *parsed_result,
14218 	__rte_unused struct cmdline *cl,
14219 	__rte_unused void *data)
14220 {
14221 	struct cmd_set_conntrack_common_result *res = parsed_result;
14222 
14223 	/* No need to swap to big endian. */
14224 	conntrack_context.peer_port = res->peer_port;
14225 	conntrack_context.is_original_dir = res->is_original;
14226 	conntrack_context.enable = res->en;
14227 	conntrack_context.live_connection = res->is_live;
14228 	conntrack_context.selective_ack = res->s_ack;
14229 	conntrack_context.challenge_ack_passed = res->c_ack;
14230 	conntrack_context.last_direction = res->ld;
14231 	conntrack_context.liberal_mode = res->lb;
14232 	conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
14233 	conntrack_context.max_ack_window = res->factor;
14234 	conntrack_context.retransmission_limit = res->re_num;
14235 	conntrack_context.last_window = res->lw;
14236 	conntrack_context.last_index =
14237 		(enum rte_flow_conntrack_tcp_last_index)res->li;
14238 	conntrack_context.last_seq = res->ls;
14239 	conntrack_context.last_ack = res->la;
14240 	conntrack_context.last_end = res->le;
14241 }
14242 
14243 cmdline_parse_inst_t cmd_set_conntrack_common = {
14244 	.f = cmd_set_conntrack_common_parsed,
14245 	.data = NULL,
14246 	.help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
14247 		" live <ack_seen> sack <en> cack <passed> last_dir <dir>"
14248 		" liberal <en> state <s> max_ack_win <factor> r_lim <num>"
14249 		" last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
14250 		" last_index <flag>",
14251 	.tokens = {
14252 		(void *)&cmd_set_conntrack_set,
14253 		(void *)&cmd_set_conntrack_conntrack,
14254 		(void *)&cmd_set_conntrack_common_com,
14255 		(void *)&cmd_set_conntrack_common_peer,
14256 		(void *)&cmd_set_conntrack_common_peer_value,
14257 		(void *)&cmd_set_conntrack_common_is_orig,
14258 		(void *)&cmd_set_conntrack_common_is_orig_value,
14259 		(void *)&cmd_set_conntrack_common_enable,
14260 		(void *)&cmd_set_conntrack_common_enable_value,
14261 		(void *)&cmd_set_conntrack_common_live,
14262 		(void *)&cmd_set_conntrack_common_live_value,
14263 		(void *)&cmd_set_conntrack_common_sack,
14264 		(void *)&cmd_set_conntrack_common_sack_value,
14265 		(void *)&cmd_set_conntrack_common_cack,
14266 		(void *)&cmd_set_conntrack_common_cack_value,
14267 		(void *)&cmd_set_conntrack_common_last_dir,
14268 		(void *)&cmd_set_conntrack_common_last_dir_value,
14269 		(void *)&cmd_set_conntrack_common_liberal,
14270 		(void *)&cmd_set_conntrack_common_liberal_value,
14271 		(void *)&cmd_set_conntrack_common_state,
14272 		(void *)&cmd_set_conntrack_common_state_value,
14273 		(void *)&cmd_set_conntrack_common_max_ackwin,
14274 		(void *)&cmd_set_conntrack_common_max_ackwin_value,
14275 		(void *)&cmd_set_conntrack_common_retrans,
14276 		(void *)&cmd_set_conntrack_common_retrans_value,
14277 		(void *)&cmd_set_conntrack_common_last_win,
14278 		(void *)&cmd_set_conntrack_common_last_win_value,
14279 		(void *)&cmd_set_conntrack_common_last_seq,
14280 		(void *)&cmd_set_conntrack_common_last_seq_value,
14281 		(void *)&cmd_set_conntrack_common_last_ack,
14282 		(void *)&cmd_set_conntrack_common_last_ack_value,
14283 		(void *)&cmd_set_conntrack_common_last_end,
14284 		(void *)&cmd_set_conntrack_common_last_end_value,
14285 		(void *)&cmd_set_conntrack_common_last_index,
14286 		(void *)&cmd_set_conntrack_common_last_index_value,
14287 		NULL,
14288 	},
14289 };
14290 
14291 /** Set connection tracking object both directions' details */
14292 struct cmd_set_conntrack_dir_result {
14293 	cmdline_fixed_string_t set;
14294 	cmdline_fixed_string_t conntrack;
14295 	cmdline_fixed_string_t dir;
14296 	cmdline_fixed_string_t scale;
14297 	cmdline_fixed_string_t fin;
14298 	cmdline_fixed_string_t ack_seen;
14299 	cmdline_fixed_string_t unack;
14300 	cmdline_fixed_string_t sent_end;
14301 	cmdline_fixed_string_t reply_end;
14302 	cmdline_fixed_string_t max_win;
14303 	cmdline_fixed_string_t max_ack;
14304 	uint32_t factor;
14305 	uint32_t f;
14306 	uint32_t as;
14307 	uint32_t un;
14308 	uint32_t se;
14309 	uint32_t re;
14310 	uint32_t mw;
14311 	uint32_t ma;
14312 };
14313 
14314 cmdline_parse_token_string_t cmd_set_conntrack_dir_set =
14315 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14316 				 set, "set");
14317 cmdline_parse_token_string_t cmd_set_conntrack_dir_conntrack =
14318 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14319 				 conntrack, "conntrack");
14320 cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
14321 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14322 				 dir, "orig#rply");
14323 cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
14324 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14325 				 scale, "scale");
14326 cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
14327 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14328 			      factor, RTE_UINT32);
14329 cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
14330 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14331 				 fin, "fin");
14332 cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
14333 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14334 			      f, RTE_UINT32);
14335 cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
14336 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14337 				 ack_seen, "acked");
14338 cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
14339 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14340 			      as, RTE_UINT32);
14341 cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
14342 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14343 				 unack, "unack_data");
14344 cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
14345 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14346 			      un, RTE_UINT32);
14347 cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
14348 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14349 				 sent_end, "sent_end");
14350 cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
14351 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14352 			      se, RTE_UINT32);
14353 cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
14354 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14355 				 reply_end, "reply_end");
14356 cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
14357 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14358 			      re, RTE_UINT32);
14359 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
14360 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14361 				 max_win, "max_win");
14362 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
14363 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14364 			      mw, RTE_UINT32);
14365 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
14366 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14367 				 max_ack, "max_ack");
14368 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
14369 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14370 			      ma, RTE_UINT32);
14371 
14372 static void cmd_set_conntrack_dir_parsed(void *parsed_result,
14373 	__rte_unused struct cmdline *cl,
14374 	__rte_unused void *data)
14375 {
14376 	struct cmd_set_conntrack_dir_result *res = parsed_result;
14377 	struct rte_flow_tcp_dir_param *dir = NULL;
14378 
14379 	if (strcmp(res->dir, "orig") == 0)
14380 		dir = &conntrack_context.original_dir;
14381 	else if (strcmp(res->dir, "rply") == 0)
14382 		dir = &conntrack_context.reply_dir;
14383 	else
14384 		return;
14385 	dir->scale = res->factor;
14386 	dir->close_initiated = res->f;
14387 	dir->last_ack_seen = res->as;
14388 	dir->data_unacked = res->un;
14389 	dir->sent_end = res->se;
14390 	dir->reply_end = res->re;
14391 	dir->max_ack = res->ma;
14392 	dir->max_win = res->mw;
14393 }
14394 
14395 cmdline_parse_inst_t cmd_set_conntrack_dir = {
14396 	.f = cmd_set_conntrack_dir_parsed,
14397 	.data = NULL,
14398 	.help_str = "set conntrack orig|rply scale <factor> fin <sent>"
14399 		    " acked <seen> unack_data <unack> sent_end <sent>"
14400 		    " reply_end <reply> max_win <win> max_ack <ack>",
14401 	.tokens = {
14402 		(void *)&cmd_set_conntrack_set,
14403 		(void *)&cmd_set_conntrack_conntrack,
14404 		(void *)&cmd_set_conntrack_dir_dir,
14405 		(void *)&cmd_set_conntrack_dir_scale,
14406 		(void *)&cmd_set_conntrack_dir_scale_value,
14407 		(void *)&cmd_set_conntrack_dir_fin,
14408 		(void *)&cmd_set_conntrack_dir_fin_value,
14409 		(void *)&cmd_set_conntrack_dir_ack,
14410 		(void *)&cmd_set_conntrack_dir_ack_value,
14411 		(void *)&cmd_set_conntrack_dir_unack_data,
14412 		(void *)&cmd_set_conntrack_dir_unack_data_value,
14413 		(void *)&cmd_set_conntrack_dir_sent_end,
14414 		(void *)&cmd_set_conntrack_dir_sent_end_value,
14415 		(void *)&cmd_set_conntrack_dir_reply_end,
14416 		(void *)&cmd_set_conntrack_dir_reply_end_value,
14417 		(void *)&cmd_set_conntrack_dir_max_win,
14418 		(void *)&cmd_set_conntrack_dir_max_win_value,
14419 		(void *)&cmd_set_conntrack_dir_max_ack,
14420 		(void *)&cmd_set_conntrack_dir_max_ack_value,
14421 		NULL,
14422 	},
14423 };
14424 
14425 /* Strict link priority scheduling mode setting */
14426 static void
14427 cmd_strict_link_prio_parsed(
14428 	void *parsed_result,
14429 	__rte_unused struct cmdline *cl,
14430 	__rte_unused void *data)
14431 {
14432 	struct cmd_vf_tc_bw_result *res = parsed_result;
14433 	int ret = -ENOTSUP;
14434 
14435 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14436 		return;
14437 
14438 #ifdef RTE_NET_I40E
14439 	ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14440 #endif
14441 
14442 	switch (ret) {
14443 	case 0:
14444 		break;
14445 	case -EINVAL:
14446 		fprintf(stderr, "invalid tc_bitmap 0x%x\n", res->tc_map);
14447 		break;
14448 	case -ENODEV:
14449 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
14450 		break;
14451 	case -ENOTSUP:
14452 		fprintf(stderr, "function not implemented\n");
14453 		break;
14454 	default:
14455 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
14456 	}
14457 }
14458 
14459 cmdline_parse_inst_t cmd_strict_link_prio = {
14460 	.f = cmd_strict_link_prio_parsed,
14461 	.data = NULL,
14462 	.help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14463 	.tokens = {
14464 		(void *)&cmd_vf_tc_bw_set,
14465 		(void *)&cmd_vf_tc_bw_tx,
14466 		(void *)&cmd_vf_tc_bw_strict_link_prio,
14467 		(void *)&cmd_vf_tc_bw_port_id,
14468 		(void *)&cmd_vf_tc_bw_tc_map,
14469 		NULL,
14470 	},
14471 };
14472 
14473 /* Load dynamic device personalization*/
14474 struct cmd_ddp_add_result {
14475 	cmdline_fixed_string_t ddp;
14476 	cmdline_fixed_string_t add;
14477 	portid_t port_id;
14478 	char filepath[];
14479 };
14480 
14481 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14482 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14483 cmdline_parse_token_string_t cmd_ddp_add_add =
14484 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14485 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14486 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
14487 		RTE_UINT16);
14488 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14489 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14490 
14491 static void
14492 cmd_ddp_add_parsed(
14493 	void *parsed_result,
14494 	__rte_unused struct cmdline *cl,
14495 	__rte_unused void *data)
14496 {
14497 	struct cmd_ddp_add_result *res = parsed_result;
14498 	uint8_t *buff;
14499 	uint32_t size;
14500 	char *filepath;
14501 	char *file_fld[2];
14502 	int file_num;
14503 	int ret = -ENOTSUP;
14504 
14505 	if (!all_ports_stopped()) {
14506 		fprintf(stderr, "Please stop all ports first\n");
14507 		return;
14508 	}
14509 
14510 	filepath = strdup(res->filepath);
14511 	if (filepath == NULL) {
14512 		fprintf(stderr, "Failed to allocate memory\n");
14513 		return;
14514 	}
14515 	file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14516 
14517 	buff = open_file(file_fld[0], &size);
14518 	if (!buff) {
14519 		free((void *)filepath);
14520 		return;
14521 	}
14522 
14523 #ifdef RTE_NET_I40E
14524 	if (ret == -ENOTSUP)
14525 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14526 					       buff, size,
14527 					       RTE_PMD_I40E_PKG_OP_WR_ADD);
14528 #endif
14529 
14530 	if (ret == -EEXIST)
14531 		fprintf(stderr, "Profile has already existed.\n");
14532 	else if (ret < 0)
14533 		fprintf(stderr, "Failed to load profile.\n");
14534 	else if (file_num == 2)
14535 		save_file(file_fld[1], buff, size);
14536 
14537 	close_file(buff);
14538 	free((void *)filepath);
14539 }
14540 
14541 cmdline_parse_inst_t cmd_ddp_add = {
14542 	.f = cmd_ddp_add_parsed,
14543 	.data = NULL,
14544 	.help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14545 	.tokens = {
14546 		(void *)&cmd_ddp_add_ddp,
14547 		(void *)&cmd_ddp_add_add,
14548 		(void *)&cmd_ddp_add_port_id,
14549 		(void *)&cmd_ddp_add_filepath,
14550 		NULL,
14551 	},
14552 };
14553 
14554 /* Delete dynamic device personalization*/
14555 struct cmd_ddp_del_result {
14556 	cmdline_fixed_string_t ddp;
14557 	cmdline_fixed_string_t del;
14558 	portid_t port_id;
14559 	char filepath[];
14560 };
14561 
14562 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14563 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14564 cmdline_parse_token_string_t cmd_ddp_del_del =
14565 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14566 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14567 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
14568 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14569 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14570 
14571 static void
14572 cmd_ddp_del_parsed(
14573 	void *parsed_result,
14574 	__rte_unused struct cmdline *cl,
14575 	__rte_unused void *data)
14576 {
14577 	struct cmd_ddp_del_result *res = parsed_result;
14578 	uint8_t *buff;
14579 	uint32_t size;
14580 	int ret = -ENOTSUP;
14581 
14582 	if (!all_ports_stopped()) {
14583 		fprintf(stderr, "Please stop all ports first\n");
14584 		return;
14585 	}
14586 
14587 	buff = open_file(res->filepath, &size);
14588 	if (!buff)
14589 		return;
14590 
14591 #ifdef RTE_NET_I40E
14592 	if (ret == -ENOTSUP)
14593 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14594 					       buff, size,
14595 					       RTE_PMD_I40E_PKG_OP_WR_DEL);
14596 #endif
14597 
14598 	if (ret == -EACCES)
14599 		fprintf(stderr, "Profile does not exist.\n");
14600 	else if (ret < 0)
14601 		fprintf(stderr, "Failed to delete profile.\n");
14602 
14603 	close_file(buff);
14604 }
14605 
14606 cmdline_parse_inst_t cmd_ddp_del = {
14607 	.f = cmd_ddp_del_parsed,
14608 	.data = NULL,
14609 	.help_str = "ddp del <port_id> <backup_profile_path>",
14610 	.tokens = {
14611 		(void *)&cmd_ddp_del_ddp,
14612 		(void *)&cmd_ddp_del_del,
14613 		(void *)&cmd_ddp_del_port_id,
14614 		(void *)&cmd_ddp_del_filepath,
14615 		NULL,
14616 	},
14617 };
14618 
14619 /* Get dynamic device personalization profile info */
14620 struct cmd_ddp_info_result {
14621 	cmdline_fixed_string_t ddp;
14622 	cmdline_fixed_string_t get;
14623 	cmdline_fixed_string_t info;
14624 	char filepath[];
14625 };
14626 
14627 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14628 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14629 cmdline_parse_token_string_t cmd_ddp_info_get =
14630 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14631 cmdline_parse_token_string_t cmd_ddp_info_info =
14632 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14633 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14634 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14635 
14636 static void
14637 cmd_ddp_info_parsed(
14638 	void *parsed_result,
14639 	__rte_unused struct cmdline *cl,
14640 	__rte_unused void *data)
14641 {
14642 	struct cmd_ddp_info_result *res = parsed_result;
14643 	uint8_t *pkg;
14644 	uint32_t pkg_size;
14645 	int ret = -ENOTSUP;
14646 #ifdef RTE_NET_I40E
14647 	uint32_t i, j, n;
14648 	uint8_t *buff;
14649 	uint32_t buff_size = 0;
14650 	struct rte_pmd_i40e_profile_info info;
14651 	uint32_t dev_num = 0;
14652 	struct rte_pmd_i40e_ddp_device_id *devs;
14653 	uint32_t proto_num = 0;
14654 	struct rte_pmd_i40e_proto_info *proto = NULL;
14655 	uint32_t pctype_num = 0;
14656 	struct rte_pmd_i40e_ptype_info *pctype;
14657 	uint32_t ptype_num = 0;
14658 	struct rte_pmd_i40e_ptype_info *ptype;
14659 	uint8_t proto_id;
14660 
14661 #endif
14662 
14663 	pkg = open_file(res->filepath, &pkg_size);
14664 	if (!pkg)
14665 		return;
14666 
14667 #ifdef RTE_NET_I40E
14668 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14669 				(uint8_t *)&info, sizeof(info),
14670 				RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14671 	if (!ret) {
14672 		printf("Global Track id:       0x%x\n", info.track_id);
14673 		printf("Global Version:        %d.%d.%d.%d\n",
14674 			info.version.major,
14675 			info.version.minor,
14676 			info.version.update,
14677 			info.version.draft);
14678 		printf("Global Package name:   %s\n\n", info.name);
14679 	}
14680 
14681 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14682 				(uint8_t *)&info, sizeof(info),
14683 				RTE_PMD_I40E_PKG_INFO_HEADER);
14684 	if (!ret) {
14685 		printf("i40e Profile Track id: 0x%x\n", info.track_id);
14686 		printf("i40e Profile Version:  %d.%d.%d.%d\n",
14687 			info.version.major,
14688 			info.version.minor,
14689 			info.version.update,
14690 			info.version.draft);
14691 		printf("i40e Profile name:     %s\n\n", info.name);
14692 	}
14693 
14694 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14695 				(uint8_t *)&buff_size, sizeof(buff_size),
14696 				RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14697 	if (!ret && buff_size) {
14698 		buff = (uint8_t *)malloc(buff_size);
14699 		if (buff) {
14700 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14701 						buff, buff_size,
14702 						RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14703 			if (!ret)
14704 				printf("Package Notes:\n%s\n\n", buff);
14705 			free(buff);
14706 		}
14707 	}
14708 
14709 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14710 				(uint8_t *)&dev_num, sizeof(dev_num),
14711 				RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14712 	if (!ret && dev_num) {
14713 		buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14714 		devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14715 		if (devs) {
14716 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14717 						(uint8_t *)devs, buff_size,
14718 						RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14719 			if (!ret) {
14720 				printf("List of supported devices:\n");
14721 				for (i = 0; i < dev_num; i++) {
14722 					printf("  %04X:%04X %04X:%04X\n",
14723 						devs[i].vendor_dev_id >> 16,
14724 						devs[i].vendor_dev_id & 0xFFFF,
14725 						devs[i].sub_vendor_dev_id >> 16,
14726 						devs[i].sub_vendor_dev_id & 0xFFFF);
14727 				}
14728 				printf("\n");
14729 			}
14730 			free(devs);
14731 		}
14732 	}
14733 
14734 	/* get information about protocols and packet types */
14735 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14736 		(uint8_t *)&proto_num, sizeof(proto_num),
14737 		RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14738 	if (ret || !proto_num)
14739 		goto no_print_return;
14740 
14741 	buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14742 	proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14743 	if (!proto)
14744 		goto no_print_return;
14745 
14746 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14747 					buff_size,
14748 					RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14749 	if (!ret) {
14750 		printf("List of used protocols:\n");
14751 		for (i = 0; i < proto_num; i++)
14752 			printf("  %2u: %s\n", proto[i].proto_id,
14753 			       proto[i].name);
14754 		printf("\n");
14755 	}
14756 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14757 		(uint8_t *)&pctype_num, sizeof(pctype_num),
14758 		RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14759 	if (ret || !pctype_num)
14760 		goto no_print_pctypes;
14761 
14762 	buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14763 	pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14764 	if (!pctype)
14765 		goto no_print_pctypes;
14766 
14767 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14768 					buff_size,
14769 					RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14770 	if (ret) {
14771 		free(pctype);
14772 		goto no_print_pctypes;
14773 	}
14774 
14775 	printf("List of defined packet classification types:\n");
14776 	for (i = 0; i < pctype_num; i++) {
14777 		printf("  %2u:", pctype[i].ptype_id);
14778 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14779 			proto_id = pctype[i].protocols[j];
14780 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14781 				for (n = 0; n < proto_num; n++) {
14782 					if (proto[n].proto_id == proto_id) {
14783 						printf(" %s", proto[n].name);
14784 						break;
14785 					}
14786 				}
14787 			}
14788 		}
14789 		printf("\n");
14790 	}
14791 	printf("\n");
14792 	free(pctype);
14793 
14794 no_print_pctypes:
14795 
14796 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14797 					sizeof(ptype_num),
14798 					RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14799 	if (ret || !ptype_num)
14800 		goto no_print_return;
14801 
14802 	buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14803 	ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14804 	if (!ptype)
14805 		goto no_print_return;
14806 
14807 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14808 					buff_size,
14809 					RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14810 	if (ret) {
14811 		free(ptype);
14812 		goto no_print_return;
14813 	}
14814 	printf("List of defined packet types:\n");
14815 	for (i = 0; i < ptype_num; i++) {
14816 		printf("  %2u:", ptype[i].ptype_id);
14817 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14818 			proto_id = ptype[i].protocols[j];
14819 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14820 				for (n = 0; n < proto_num; n++) {
14821 					if (proto[n].proto_id == proto_id) {
14822 						printf(" %s", proto[n].name);
14823 						break;
14824 					}
14825 				}
14826 			}
14827 		}
14828 		printf("\n");
14829 	}
14830 	free(ptype);
14831 	printf("\n");
14832 
14833 	ret = 0;
14834 no_print_return:
14835 	free(proto);
14836 #endif
14837 	if (ret == -ENOTSUP)
14838 		fprintf(stderr, "Function not supported in PMD\n");
14839 	close_file(pkg);
14840 }
14841 
14842 cmdline_parse_inst_t cmd_ddp_get_info = {
14843 	.f = cmd_ddp_info_parsed,
14844 	.data = NULL,
14845 	.help_str = "ddp get info <profile_path>",
14846 	.tokens = {
14847 		(void *)&cmd_ddp_info_ddp,
14848 		(void *)&cmd_ddp_info_get,
14849 		(void *)&cmd_ddp_info_info,
14850 		(void *)&cmd_ddp_info_filepath,
14851 		NULL,
14852 	},
14853 };
14854 
14855 /* Get dynamic device personalization profile info list*/
14856 #define PROFILE_INFO_SIZE 48
14857 #define MAX_PROFILE_NUM 16
14858 
14859 struct cmd_ddp_get_list_result {
14860 	cmdline_fixed_string_t ddp;
14861 	cmdline_fixed_string_t get;
14862 	cmdline_fixed_string_t list;
14863 	portid_t port_id;
14864 };
14865 
14866 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14867 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14868 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14869 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14870 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14871 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14872 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14873 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14874 		RTE_UINT16);
14875 
14876 static void
14877 cmd_ddp_get_list_parsed(
14878 	__rte_unused void *parsed_result,
14879 	__rte_unused struct cmdline *cl,
14880 	__rte_unused void *data)
14881 {
14882 #ifdef RTE_NET_I40E
14883 	struct cmd_ddp_get_list_result *res = parsed_result;
14884 	struct rte_pmd_i40e_profile_list *p_list;
14885 	struct rte_pmd_i40e_profile_info *p_info;
14886 	uint32_t p_num;
14887 	uint32_t size;
14888 	uint32_t i;
14889 #endif
14890 	int ret = -ENOTSUP;
14891 
14892 #ifdef RTE_NET_I40E
14893 	size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14894 	p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14895 	if (!p_list) {
14896 		fprintf(stderr, "%s: Failed to malloc buffer\n", __func__);
14897 		return;
14898 	}
14899 
14900 	if (ret == -ENOTSUP)
14901 		ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14902 						(uint8_t *)p_list, size);
14903 
14904 	if (!ret) {
14905 		p_num = p_list->p_count;
14906 		printf("Profile number is: %d\n\n", p_num);
14907 
14908 		for (i = 0; i < p_num; i++) {
14909 			p_info = &p_list->p_info[i];
14910 			printf("Profile %d:\n", i);
14911 			printf("Track id:     0x%x\n", p_info->track_id);
14912 			printf("Version:      %d.%d.%d.%d\n",
14913 			       p_info->version.major,
14914 			       p_info->version.minor,
14915 			       p_info->version.update,
14916 			       p_info->version.draft);
14917 			printf("Profile name: %s\n\n", p_info->name);
14918 		}
14919 	}
14920 
14921 	free(p_list);
14922 #endif
14923 
14924 	if (ret < 0)
14925 		fprintf(stderr, "Failed to get ddp list\n");
14926 }
14927 
14928 cmdline_parse_inst_t cmd_ddp_get_list = {
14929 	.f = cmd_ddp_get_list_parsed,
14930 	.data = NULL,
14931 	.help_str = "ddp get list <port_id>",
14932 	.tokens = {
14933 		(void *)&cmd_ddp_get_list_ddp,
14934 		(void *)&cmd_ddp_get_list_get,
14935 		(void *)&cmd_ddp_get_list_list,
14936 		(void *)&cmd_ddp_get_list_port_id,
14937 		NULL,
14938 	},
14939 };
14940 
14941 /* Configure input set */
14942 struct cmd_cfg_input_set_result {
14943 	cmdline_fixed_string_t port;
14944 	cmdline_fixed_string_t cfg;
14945 	portid_t port_id;
14946 	cmdline_fixed_string_t pctype;
14947 	uint8_t pctype_id;
14948 	cmdline_fixed_string_t inset_type;
14949 	cmdline_fixed_string_t opt;
14950 	cmdline_fixed_string_t field;
14951 	uint8_t field_idx;
14952 };
14953 
14954 static void
14955 cmd_cfg_input_set_parsed(
14956 	__rte_unused void *parsed_result,
14957 	__rte_unused struct cmdline *cl,
14958 	__rte_unused void *data)
14959 {
14960 #ifdef RTE_NET_I40E
14961 	struct cmd_cfg_input_set_result *res = parsed_result;
14962 	enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14963 	struct rte_pmd_i40e_inset inset;
14964 #endif
14965 	int ret = -ENOTSUP;
14966 
14967 	if (!all_ports_stopped()) {
14968 		fprintf(stderr, "Please stop all ports first\n");
14969 		return;
14970 	}
14971 
14972 #ifdef RTE_NET_I40E
14973 	if (!strcmp(res->inset_type, "hash_inset"))
14974 		inset_type = INSET_HASH;
14975 	else if (!strcmp(res->inset_type, "fdir_inset"))
14976 		inset_type = INSET_FDIR;
14977 	else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14978 		inset_type = INSET_FDIR_FLX;
14979 	ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14980 				     &inset, inset_type);
14981 	if (ret) {
14982 		fprintf(stderr, "Failed to get input set.\n");
14983 		return;
14984 	}
14985 
14986 	if (!strcmp(res->opt, "get")) {
14987 		ret = rte_pmd_i40e_inset_field_get(inset.inset,
14988 						   res->field_idx);
14989 		if (ret)
14990 			printf("Field index %d is enabled.\n", res->field_idx);
14991 		else
14992 			printf("Field index %d is disabled.\n", res->field_idx);
14993 		return;
14994 	} else if (!strcmp(res->opt, "set"))
14995 		ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14996 						   res->field_idx);
14997 	else if (!strcmp(res->opt, "clear"))
14998 		ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14999 						     res->field_idx);
15000 	if (ret) {
15001 		fprintf(stderr, "Failed to configure input set field.\n");
15002 		return;
15003 	}
15004 
15005 	ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15006 				     &inset, inset_type);
15007 	if (ret) {
15008 		fprintf(stderr, "Failed to set input set.\n");
15009 		return;
15010 	}
15011 #endif
15012 
15013 	if (ret == -ENOTSUP)
15014 		fprintf(stderr, "Function not supported\n");
15015 }
15016 
15017 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15018 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15019 				 port, "port");
15020 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15021 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15022 				 cfg, "config");
15023 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15024 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15025 			      port_id, RTE_UINT16);
15026 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15027 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15028 				 pctype, "pctype");
15029 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15030 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15031 			      pctype_id, RTE_UINT8);
15032 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15033 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15034 				 inset_type,
15035 				 "hash_inset#fdir_inset#fdir_flx_inset");
15036 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15037 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15038 				 opt, "get#set#clear");
15039 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15040 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15041 				 field, "field");
15042 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15043 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15044 			      field_idx, RTE_UINT8);
15045 
15046 cmdline_parse_inst_t cmd_cfg_input_set = {
15047 	.f = cmd_cfg_input_set_parsed,
15048 	.data = NULL,
15049 	.help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15050 		    "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15051 	.tokens = {
15052 		(void *)&cmd_cfg_input_set_port,
15053 		(void *)&cmd_cfg_input_set_cfg,
15054 		(void *)&cmd_cfg_input_set_port_id,
15055 		(void *)&cmd_cfg_input_set_pctype,
15056 		(void *)&cmd_cfg_input_set_pctype_id,
15057 		(void *)&cmd_cfg_input_set_inset_type,
15058 		(void *)&cmd_cfg_input_set_opt,
15059 		(void *)&cmd_cfg_input_set_field,
15060 		(void *)&cmd_cfg_input_set_field_idx,
15061 		NULL,
15062 	},
15063 };
15064 
15065 /* Clear input set */
15066 struct cmd_clear_input_set_result {
15067 	cmdline_fixed_string_t port;
15068 	cmdline_fixed_string_t cfg;
15069 	portid_t port_id;
15070 	cmdline_fixed_string_t pctype;
15071 	uint8_t pctype_id;
15072 	cmdline_fixed_string_t inset_type;
15073 	cmdline_fixed_string_t clear;
15074 	cmdline_fixed_string_t all;
15075 };
15076 
15077 static void
15078 cmd_clear_input_set_parsed(
15079 	__rte_unused void *parsed_result,
15080 	__rte_unused struct cmdline *cl,
15081 	__rte_unused void *data)
15082 {
15083 #ifdef RTE_NET_I40E
15084 	struct cmd_clear_input_set_result *res = parsed_result;
15085 	enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15086 	struct rte_pmd_i40e_inset inset;
15087 #endif
15088 	int ret = -ENOTSUP;
15089 
15090 	if (!all_ports_stopped()) {
15091 		fprintf(stderr, "Please stop all ports first\n");
15092 		return;
15093 	}
15094 
15095 #ifdef RTE_NET_I40E
15096 	if (!strcmp(res->inset_type, "hash_inset"))
15097 		inset_type = INSET_HASH;
15098 	else if (!strcmp(res->inset_type, "fdir_inset"))
15099 		inset_type = INSET_FDIR;
15100 	else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15101 		inset_type = INSET_FDIR_FLX;
15102 
15103 	memset(&inset, 0, sizeof(inset));
15104 
15105 	ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15106 				     &inset, inset_type);
15107 	if (ret) {
15108 		fprintf(stderr, "Failed to clear input set.\n");
15109 		return;
15110 	}
15111 
15112 #endif
15113 
15114 	if (ret == -ENOTSUP)
15115 		fprintf(stderr, "Function not supported\n");
15116 }
15117 
15118 cmdline_parse_token_string_t cmd_clear_input_set_port =
15119 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15120 				 port, "port");
15121 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15122 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15123 				 cfg, "config");
15124 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15125 	TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15126 			      port_id, RTE_UINT16);
15127 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15128 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15129 				 pctype, "pctype");
15130 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15131 	TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15132 			      pctype_id, RTE_UINT8);
15133 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15134 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15135 				 inset_type,
15136 				 "hash_inset#fdir_inset#fdir_flx_inset");
15137 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15138 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15139 				 clear, "clear");
15140 cmdline_parse_token_string_t cmd_clear_input_set_all =
15141 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15142 				 all, "all");
15143 
15144 cmdline_parse_inst_t cmd_clear_input_set = {
15145 	.f = cmd_clear_input_set_parsed,
15146 	.data = NULL,
15147 	.help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15148 		    "fdir_inset|fdir_flx_inset clear all",
15149 	.tokens = {
15150 		(void *)&cmd_clear_input_set_port,
15151 		(void *)&cmd_clear_input_set_cfg,
15152 		(void *)&cmd_clear_input_set_port_id,
15153 		(void *)&cmd_clear_input_set_pctype,
15154 		(void *)&cmd_clear_input_set_pctype_id,
15155 		(void *)&cmd_clear_input_set_inset_type,
15156 		(void *)&cmd_clear_input_set_clear,
15157 		(void *)&cmd_clear_input_set_all,
15158 		NULL,
15159 	},
15160 };
15161 
15162 /* show vf stats */
15163 
15164 /* Common result structure for show vf stats */
15165 struct cmd_show_vf_stats_result {
15166 	cmdline_fixed_string_t show;
15167 	cmdline_fixed_string_t vf;
15168 	cmdline_fixed_string_t stats;
15169 	portid_t port_id;
15170 	uint16_t vf_id;
15171 };
15172 
15173 /* Common CLI fields show vf stats*/
15174 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15175 	TOKEN_STRING_INITIALIZER
15176 		(struct cmd_show_vf_stats_result,
15177 		 show, "show");
15178 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15179 	TOKEN_STRING_INITIALIZER
15180 		(struct cmd_show_vf_stats_result,
15181 		 vf, "vf");
15182 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15183 	TOKEN_STRING_INITIALIZER
15184 		(struct cmd_show_vf_stats_result,
15185 		 stats, "stats");
15186 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15187 	TOKEN_NUM_INITIALIZER
15188 		(struct cmd_show_vf_stats_result,
15189 		 port_id, RTE_UINT16);
15190 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15191 	TOKEN_NUM_INITIALIZER
15192 		(struct cmd_show_vf_stats_result,
15193 		 vf_id, RTE_UINT16);
15194 
15195 static void
15196 cmd_show_vf_stats_parsed(
15197 	void *parsed_result,
15198 	__rte_unused struct cmdline *cl,
15199 	__rte_unused void *data)
15200 {
15201 	struct cmd_show_vf_stats_result *res = parsed_result;
15202 	struct rte_eth_stats stats;
15203 	int ret = -ENOTSUP;
15204 	static const char *nic_stats_border = "########################";
15205 
15206 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15207 		return;
15208 
15209 	memset(&stats, 0, sizeof(stats));
15210 
15211 #ifdef RTE_NET_I40E
15212 	if (ret == -ENOTSUP)
15213 		ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15214 						res->vf_id,
15215 						&stats);
15216 #endif
15217 #ifdef RTE_NET_BNXT
15218 	if (ret == -ENOTSUP)
15219 		ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15220 						res->vf_id,
15221 						&stats);
15222 #endif
15223 
15224 	switch (ret) {
15225 	case 0:
15226 		break;
15227 	case -EINVAL:
15228 		fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15229 		break;
15230 	case -ENODEV:
15231 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15232 		break;
15233 	case -ENOTSUP:
15234 		fprintf(stderr, "function not implemented\n");
15235 		break;
15236 	default:
15237 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15238 	}
15239 
15240 	printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15241 		nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15242 
15243 	printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15244 	       "%-"PRIu64"\n",
15245 	       stats.ipackets, stats.imissed, stats.ibytes);
15246 	printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15247 	printf("  RX-nombuf:  %-10"PRIu64"\n",
15248 	       stats.rx_nombuf);
15249 	printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15250 	       "%-"PRIu64"\n",
15251 	       stats.opackets, stats.oerrors, stats.obytes);
15252 
15253 	printf("  %s############################%s\n",
15254 			       nic_stats_border, nic_stats_border);
15255 }
15256 
15257 cmdline_parse_inst_t cmd_show_vf_stats = {
15258 	.f = cmd_show_vf_stats_parsed,
15259 	.data = NULL,
15260 	.help_str = "show vf stats <port_id> <vf_id>",
15261 	.tokens = {
15262 		(void *)&cmd_show_vf_stats_show,
15263 		(void *)&cmd_show_vf_stats_vf,
15264 		(void *)&cmd_show_vf_stats_stats,
15265 		(void *)&cmd_show_vf_stats_port_id,
15266 		(void *)&cmd_show_vf_stats_vf_id,
15267 		NULL,
15268 	},
15269 };
15270 
15271 /* clear vf stats */
15272 
15273 /* Common result structure for clear vf stats */
15274 struct cmd_clear_vf_stats_result {
15275 	cmdline_fixed_string_t clear;
15276 	cmdline_fixed_string_t vf;
15277 	cmdline_fixed_string_t stats;
15278 	portid_t port_id;
15279 	uint16_t vf_id;
15280 };
15281 
15282 /* Common CLI fields clear vf stats*/
15283 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15284 	TOKEN_STRING_INITIALIZER
15285 		(struct cmd_clear_vf_stats_result,
15286 		 clear, "clear");
15287 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15288 	TOKEN_STRING_INITIALIZER
15289 		(struct cmd_clear_vf_stats_result,
15290 		 vf, "vf");
15291 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15292 	TOKEN_STRING_INITIALIZER
15293 		(struct cmd_clear_vf_stats_result,
15294 		 stats, "stats");
15295 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15296 	TOKEN_NUM_INITIALIZER
15297 		(struct cmd_clear_vf_stats_result,
15298 		 port_id, RTE_UINT16);
15299 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15300 	TOKEN_NUM_INITIALIZER
15301 		(struct cmd_clear_vf_stats_result,
15302 		 vf_id, RTE_UINT16);
15303 
15304 static void
15305 cmd_clear_vf_stats_parsed(
15306 	void *parsed_result,
15307 	__rte_unused struct cmdline *cl,
15308 	__rte_unused void *data)
15309 {
15310 	struct cmd_clear_vf_stats_result *res = parsed_result;
15311 	int ret = -ENOTSUP;
15312 
15313 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15314 		return;
15315 
15316 #ifdef RTE_NET_I40E
15317 	if (ret == -ENOTSUP)
15318 		ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15319 						  res->vf_id);
15320 #endif
15321 #ifdef RTE_NET_BNXT
15322 	if (ret == -ENOTSUP)
15323 		ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15324 						  res->vf_id);
15325 #endif
15326 
15327 	switch (ret) {
15328 	case 0:
15329 		break;
15330 	case -EINVAL:
15331 		fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15332 		break;
15333 	case -ENODEV:
15334 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15335 		break;
15336 	case -ENOTSUP:
15337 		fprintf(stderr, "function not implemented\n");
15338 		break;
15339 	default:
15340 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15341 	}
15342 }
15343 
15344 cmdline_parse_inst_t cmd_clear_vf_stats = {
15345 	.f = cmd_clear_vf_stats_parsed,
15346 	.data = NULL,
15347 	.help_str = "clear vf stats <port_id> <vf_id>",
15348 	.tokens = {
15349 		(void *)&cmd_clear_vf_stats_clear,
15350 		(void *)&cmd_clear_vf_stats_vf,
15351 		(void *)&cmd_clear_vf_stats_stats,
15352 		(void *)&cmd_clear_vf_stats_port_id,
15353 		(void *)&cmd_clear_vf_stats_vf_id,
15354 		NULL,
15355 	},
15356 };
15357 
15358 /* port config pctype mapping reset */
15359 
15360 /* Common result structure for port config pctype mapping reset */
15361 struct cmd_pctype_mapping_reset_result {
15362 	cmdline_fixed_string_t port;
15363 	cmdline_fixed_string_t config;
15364 	portid_t port_id;
15365 	cmdline_fixed_string_t pctype;
15366 	cmdline_fixed_string_t mapping;
15367 	cmdline_fixed_string_t reset;
15368 };
15369 
15370 /* Common CLI fields for port config pctype mapping reset*/
15371 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15372 	TOKEN_STRING_INITIALIZER
15373 		(struct cmd_pctype_mapping_reset_result,
15374 		 port, "port");
15375 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15376 	TOKEN_STRING_INITIALIZER
15377 		(struct cmd_pctype_mapping_reset_result,
15378 		 config, "config");
15379 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15380 	TOKEN_NUM_INITIALIZER
15381 		(struct cmd_pctype_mapping_reset_result,
15382 		 port_id, RTE_UINT16);
15383 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15384 	TOKEN_STRING_INITIALIZER
15385 		(struct cmd_pctype_mapping_reset_result,
15386 		 pctype, "pctype");
15387 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15388 	TOKEN_STRING_INITIALIZER
15389 		(struct cmd_pctype_mapping_reset_result,
15390 		 mapping, "mapping");
15391 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15392 	TOKEN_STRING_INITIALIZER
15393 		(struct cmd_pctype_mapping_reset_result,
15394 		 reset, "reset");
15395 
15396 static void
15397 cmd_pctype_mapping_reset_parsed(
15398 	void *parsed_result,
15399 	__rte_unused struct cmdline *cl,
15400 	__rte_unused void *data)
15401 {
15402 	struct cmd_pctype_mapping_reset_result *res = parsed_result;
15403 	int ret = -ENOTSUP;
15404 
15405 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15406 		return;
15407 
15408 #ifdef RTE_NET_I40E
15409 	ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15410 #endif
15411 
15412 	switch (ret) {
15413 	case 0:
15414 		break;
15415 	case -ENODEV:
15416 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15417 		break;
15418 	case -ENOTSUP:
15419 		fprintf(stderr, "function not implemented\n");
15420 		break;
15421 	default:
15422 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15423 	}
15424 }
15425 
15426 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15427 	.f = cmd_pctype_mapping_reset_parsed,
15428 	.data = NULL,
15429 	.help_str = "port config <port_id> pctype mapping reset",
15430 	.tokens = {
15431 		(void *)&cmd_pctype_mapping_reset_port,
15432 		(void *)&cmd_pctype_mapping_reset_config,
15433 		(void *)&cmd_pctype_mapping_reset_port_id,
15434 		(void *)&cmd_pctype_mapping_reset_pctype,
15435 		(void *)&cmd_pctype_mapping_reset_mapping,
15436 		(void *)&cmd_pctype_mapping_reset_reset,
15437 		NULL,
15438 	},
15439 };
15440 
15441 /* show port pctype mapping */
15442 
15443 /* Common result structure for show port pctype mapping */
15444 struct cmd_pctype_mapping_get_result {
15445 	cmdline_fixed_string_t show;
15446 	cmdline_fixed_string_t port;
15447 	portid_t port_id;
15448 	cmdline_fixed_string_t pctype;
15449 	cmdline_fixed_string_t mapping;
15450 };
15451 
15452 /* Common CLI fields for pctype mapping get */
15453 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15454 	TOKEN_STRING_INITIALIZER
15455 		(struct cmd_pctype_mapping_get_result,
15456 		 show, "show");
15457 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15458 	TOKEN_STRING_INITIALIZER
15459 		(struct cmd_pctype_mapping_get_result,
15460 		 port, "port");
15461 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15462 	TOKEN_NUM_INITIALIZER
15463 		(struct cmd_pctype_mapping_get_result,
15464 		 port_id, RTE_UINT16);
15465 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15466 	TOKEN_STRING_INITIALIZER
15467 		(struct cmd_pctype_mapping_get_result,
15468 		 pctype, "pctype");
15469 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15470 	TOKEN_STRING_INITIALIZER
15471 		(struct cmd_pctype_mapping_get_result,
15472 		 mapping, "mapping");
15473 
15474 static void
15475 cmd_pctype_mapping_get_parsed(
15476 	void *parsed_result,
15477 	__rte_unused struct cmdline *cl,
15478 	__rte_unused void *data)
15479 {
15480 	struct cmd_pctype_mapping_get_result *res = parsed_result;
15481 	int ret = -ENOTSUP;
15482 #ifdef RTE_NET_I40E
15483 	struct rte_pmd_i40e_flow_type_mapping
15484 				mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15485 	int i, j, first_pctype;
15486 #endif
15487 
15488 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15489 		return;
15490 
15491 #ifdef RTE_NET_I40E
15492 	ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15493 #endif
15494 
15495 	switch (ret) {
15496 	case 0:
15497 		break;
15498 	case -ENODEV:
15499 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15500 		return;
15501 	case -ENOTSUP:
15502 		fprintf(stderr, "function not implemented\n");
15503 		return;
15504 	default:
15505 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15506 		return;
15507 	}
15508 
15509 #ifdef RTE_NET_I40E
15510 	for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15511 		if (mapping[i].pctype != 0ULL) {
15512 			first_pctype = 1;
15513 
15514 			printf("pctype: ");
15515 			for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15516 				if (mapping[i].pctype & (1ULL << j)) {
15517 					printf(first_pctype ?
15518 					       "%02d" : ",%02d", j);
15519 					first_pctype = 0;
15520 				}
15521 			}
15522 			printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15523 		}
15524 	}
15525 #endif
15526 }
15527 
15528 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15529 	.f = cmd_pctype_mapping_get_parsed,
15530 	.data = NULL,
15531 	.help_str = "show port <port_id> pctype mapping",
15532 	.tokens = {
15533 		(void *)&cmd_pctype_mapping_get_show,
15534 		(void *)&cmd_pctype_mapping_get_port,
15535 		(void *)&cmd_pctype_mapping_get_port_id,
15536 		(void *)&cmd_pctype_mapping_get_pctype,
15537 		(void *)&cmd_pctype_mapping_get_mapping,
15538 		NULL,
15539 	},
15540 };
15541 
15542 /* port config pctype mapping update */
15543 
15544 /* Common result structure for port config pctype mapping update */
15545 struct cmd_pctype_mapping_update_result {
15546 	cmdline_fixed_string_t port;
15547 	cmdline_fixed_string_t config;
15548 	portid_t port_id;
15549 	cmdline_fixed_string_t pctype;
15550 	cmdline_fixed_string_t mapping;
15551 	cmdline_fixed_string_t update;
15552 	cmdline_fixed_string_t pctype_list;
15553 	uint16_t flow_type;
15554 };
15555 
15556 /* Common CLI fields for pctype mapping update*/
15557 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15558 	TOKEN_STRING_INITIALIZER
15559 		(struct cmd_pctype_mapping_update_result,
15560 		 port, "port");
15561 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15562 	TOKEN_STRING_INITIALIZER
15563 		(struct cmd_pctype_mapping_update_result,
15564 		 config, "config");
15565 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15566 	TOKEN_NUM_INITIALIZER
15567 		(struct cmd_pctype_mapping_update_result,
15568 		 port_id, RTE_UINT16);
15569 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15570 	TOKEN_STRING_INITIALIZER
15571 		(struct cmd_pctype_mapping_update_result,
15572 		 pctype, "pctype");
15573 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15574 	TOKEN_STRING_INITIALIZER
15575 		(struct cmd_pctype_mapping_update_result,
15576 		 mapping, "mapping");
15577 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15578 	TOKEN_STRING_INITIALIZER
15579 		(struct cmd_pctype_mapping_update_result,
15580 		 update, "update");
15581 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15582 	TOKEN_STRING_INITIALIZER
15583 		(struct cmd_pctype_mapping_update_result,
15584 		 pctype_list, NULL);
15585 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15586 	TOKEN_NUM_INITIALIZER
15587 		(struct cmd_pctype_mapping_update_result,
15588 		 flow_type, RTE_UINT16);
15589 
15590 static void
15591 cmd_pctype_mapping_update_parsed(
15592 	void *parsed_result,
15593 	__rte_unused struct cmdline *cl,
15594 	__rte_unused void *data)
15595 {
15596 	struct cmd_pctype_mapping_update_result *res = parsed_result;
15597 	int ret = -ENOTSUP;
15598 #ifdef RTE_NET_I40E
15599 	struct rte_pmd_i40e_flow_type_mapping mapping;
15600 	unsigned int i;
15601 	unsigned int nb_item;
15602 	unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15603 #endif
15604 
15605 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15606 		return;
15607 
15608 #ifdef RTE_NET_I40E
15609 	nb_item = parse_item_list(res->pctype_list, "pctypes",
15610 				  RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15611 	mapping.flow_type = res->flow_type;
15612 	for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15613 		mapping.pctype |= (1ULL << pctype_list[i]);
15614 	ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15615 						&mapping,
15616 						1,
15617 						0);
15618 #endif
15619 
15620 	switch (ret) {
15621 	case 0:
15622 		break;
15623 	case -EINVAL:
15624 		fprintf(stderr, "invalid pctype or flow type\n");
15625 		break;
15626 	case -ENODEV:
15627 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15628 		break;
15629 	case -ENOTSUP:
15630 		fprintf(stderr, "function not implemented\n");
15631 		break;
15632 	default:
15633 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15634 	}
15635 }
15636 
15637 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15638 	.f = cmd_pctype_mapping_update_parsed,
15639 	.data = NULL,
15640 	.help_str = "port config <port_id> pctype mapping update"
15641 	" <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15642 	.tokens = {
15643 		(void *)&cmd_pctype_mapping_update_port,
15644 		(void *)&cmd_pctype_mapping_update_config,
15645 		(void *)&cmd_pctype_mapping_update_port_id,
15646 		(void *)&cmd_pctype_mapping_update_pctype,
15647 		(void *)&cmd_pctype_mapping_update_mapping,
15648 		(void *)&cmd_pctype_mapping_update_update,
15649 		(void *)&cmd_pctype_mapping_update_pc_type,
15650 		(void *)&cmd_pctype_mapping_update_flow_type,
15651 		NULL,
15652 	},
15653 };
15654 
15655 /* ptype mapping get */
15656 
15657 /* Common result structure for ptype mapping get */
15658 struct cmd_ptype_mapping_get_result {
15659 	cmdline_fixed_string_t ptype;
15660 	cmdline_fixed_string_t mapping;
15661 	cmdline_fixed_string_t get;
15662 	portid_t port_id;
15663 	uint8_t valid_only;
15664 };
15665 
15666 /* Common CLI fields for ptype mapping get */
15667 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15668 	TOKEN_STRING_INITIALIZER
15669 		(struct cmd_ptype_mapping_get_result,
15670 		 ptype, "ptype");
15671 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15672 	TOKEN_STRING_INITIALIZER
15673 		(struct cmd_ptype_mapping_get_result,
15674 		 mapping, "mapping");
15675 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15676 	TOKEN_STRING_INITIALIZER
15677 		(struct cmd_ptype_mapping_get_result,
15678 		 get, "get");
15679 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15680 	TOKEN_NUM_INITIALIZER
15681 		(struct cmd_ptype_mapping_get_result,
15682 		 port_id, RTE_UINT16);
15683 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15684 	TOKEN_NUM_INITIALIZER
15685 		(struct cmd_ptype_mapping_get_result,
15686 		 valid_only, RTE_UINT8);
15687 
15688 static void
15689 cmd_ptype_mapping_get_parsed(
15690 	void *parsed_result,
15691 	__rte_unused struct cmdline *cl,
15692 	__rte_unused void *data)
15693 {
15694 	struct cmd_ptype_mapping_get_result *res = parsed_result;
15695 	int ret = -ENOTSUP;
15696 #ifdef RTE_NET_I40E
15697 	int max_ptype_num = 256;
15698 	struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15699 	uint16_t count;
15700 	int i;
15701 #endif
15702 
15703 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15704 		return;
15705 
15706 #ifdef RTE_NET_I40E
15707 	ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15708 					mapping,
15709 					max_ptype_num,
15710 					&count,
15711 					res->valid_only);
15712 #endif
15713 
15714 	switch (ret) {
15715 	case 0:
15716 		break;
15717 	case -ENODEV:
15718 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15719 		break;
15720 	case -ENOTSUP:
15721 		fprintf(stderr, "function not implemented\n");
15722 		break;
15723 	default:
15724 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15725 	}
15726 
15727 #ifdef RTE_NET_I40E
15728 	if (!ret) {
15729 		for (i = 0; i < count; i++)
15730 			printf("%3d\t0x%08x\n",
15731 				mapping[i].hw_ptype, mapping[i].sw_ptype);
15732 	}
15733 #endif
15734 }
15735 
15736 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15737 	.f = cmd_ptype_mapping_get_parsed,
15738 	.data = NULL,
15739 	.help_str = "ptype mapping get <port_id> <valid_only>",
15740 	.tokens = {
15741 		(void *)&cmd_ptype_mapping_get_ptype,
15742 		(void *)&cmd_ptype_mapping_get_mapping,
15743 		(void *)&cmd_ptype_mapping_get_get,
15744 		(void *)&cmd_ptype_mapping_get_port_id,
15745 		(void *)&cmd_ptype_mapping_get_valid_only,
15746 		NULL,
15747 	},
15748 };
15749 
15750 /* ptype mapping replace */
15751 
15752 /* Common result structure for ptype mapping replace */
15753 struct cmd_ptype_mapping_replace_result {
15754 	cmdline_fixed_string_t ptype;
15755 	cmdline_fixed_string_t mapping;
15756 	cmdline_fixed_string_t replace;
15757 	portid_t port_id;
15758 	uint32_t target;
15759 	uint8_t mask;
15760 	uint32_t pkt_type;
15761 };
15762 
15763 /* Common CLI fields for ptype mapping replace */
15764 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15765 	TOKEN_STRING_INITIALIZER
15766 		(struct cmd_ptype_mapping_replace_result,
15767 		 ptype, "ptype");
15768 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15769 	TOKEN_STRING_INITIALIZER
15770 		(struct cmd_ptype_mapping_replace_result,
15771 		 mapping, "mapping");
15772 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15773 	TOKEN_STRING_INITIALIZER
15774 		(struct cmd_ptype_mapping_replace_result,
15775 		 replace, "replace");
15776 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15777 	TOKEN_NUM_INITIALIZER
15778 		(struct cmd_ptype_mapping_replace_result,
15779 		 port_id, RTE_UINT16);
15780 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15781 	TOKEN_NUM_INITIALIZER
15782 		(struct cmd_ptype_mapping_replace_result,
15783 		 target, RTE_UINT32);
15784 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15785 	TOKEN_NUM_INITIALIZER
15786 		(struct cmd_ptype_mapping_replace_result,
15787 		 mask, RTE_UINT8);
15788 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15789 	TOKEN_NUM_INITIALIZER
15790 		(struct cmd_ptype_mapping_replace_result,
15791 		 pkt_type, RTE_UINT32);
15792 
15793 static void
15794 cmd_ptype_mapping_replace_parsed(
15795 	void *parsed_result,
15796 	__rte_unused struct cmdline *cl,
15797 	__rte_unused void *data)
15798 {
15799 	struct cmd_ptype_mapping_replace_result *res = parsed_result;
15800 	int ret = -ENOTSUP;
15801 
15802 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15803 		return;
15804 
15805 #ifdef RTE_NET_I40E
15806 	ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15807 					res->target,
15808 					res->mask,
15809 					res->pkt_type);
15810 #endif
15811 
15812 	switch (ret) {
15813 	case 0:
15814 		break;
15815 	case -EINVAL:
15816 		fprintf(stderr, "invalid ptype 0x%8x or 0x%8x\n",
15817 			res->target, res->pkt_type);
15818 		break;
15819 	case -ENODEV:
15820 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15821 		break;
15822 	case -ENOTSUP:
15823 		fprintf(stderr, "function not implemented\n");
15824 		break;
15825 	default:
15826 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15827 	}
15828 }
15829 
15830 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15831 	.f = cmd_ptype_mapping_replace_parsed,
15832 	.data = NULL,
15833 	.help_str =
15834 		"ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15835 	.tokens = {
15836 		(void *)&cmd_ptype_mapping_replace_ptype,
15837 		(void *)&cmd_ptype_mapping_replace_mapping,
15838 		(void *)&cmd_ptype_mapping_replace_replace,
15839 		(void *)&cmd_ptype_mapping_replace_port_id,
15840 		(void *)&cmd_ptype_mapping_replace_target,
15841 		(void *)&cmd_ptype_mapping_replace_mask,
15842 		(void *)&cmd_ptype_mapping_replace_pkt_type,
15843 		NULL,
15844 	},
15845 };
15846 
15847 /* ptype mapping reset */
15848 
15849 /* Common result structure for ptype mapping reset */
15850 struct cmd_ptype_mapping_reset_result {
15851 	cmdline_fixed_string_t ptype;
15852 	cmdline_fixed_string_t mapping;
15853 	cmdline_fixed_string_t reset;
15854 	portid_t port_id;
15855 };
15856 
15857 /* Common CLI fields for ptype mapping reset*/
15858 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15859 	TOKEN_STRING_INITIALIZER
15860 		(struct cmd_ptype_mapping_reset_result,
15861 		 ptype, "ptype");
15862 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15863 	TOKEN_STRING_INITIALIZER
15864 		(struct cmd_ptype_mapping_reset_result,
15865 		 mapping, "mapping");
15866 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15867 	TOKEN_STRING_INITIALIZER
15868 		(struct cmd_ptype_mapping_reset_result,
15869 		 reset, "reset");
15870 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15871 	TOKEN_NUM_INITIALIZER
15872 		(struct cmd_ptype_mapping_reset_result,
15873 		 port_id, RTE_UINT16);
15874 
15875 static void
15876 cmd_ptype_mapping_reset_parsed(
15877 	void *parsed_result,
15878 	__rte_unused struct cmdline *cl,
15879 	__rte_unused void *data)
15880 {
15881 	struct cmd_ptype_mapping_reset_result *res = parsed_result;
15882 	int ret = -ENOTSUP;
15883 
15884 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15885 		return;
15886 
15887 #ifdef RTE_NET_I40E
15888 	ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15889 #endif
15890 
15891 	switch (ret) {
15892 	case 0:
15893 		break;
15894 	case -ENODEV:
15895 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15896 		break;
15897 	case -ENOTSUP:
15898 		fprintf(stderr, "function not implemented\n");
15899 		break;
15900 	default:
15901 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15902 	}
15903 }
15904 
15905 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15906 	.f = cmd_ptype_mapping_reset_parsed,
15907 	.data = NULL,
15908 	.help_str = "ptype mapping reset <port_id>",
15909 	.tokens = {
15910 		(void *)&cmd_ptype_mapping_reset_ptype,
15911 		(void *)&cmd_ptype_mapping_reset_mapping,
15912 		(void *)&cmd_ptype_mapping_reset_reset,
15913 		(void *)&cmd_ptype_mapping_reset_port_id,
15914 		NULL,
15915 	},
15916 };
15917 
15918 /* ptype mapping update */
15919 
15920 /* Common result structure for ptype mapping update */
15921 struct cmd_ptype_mapping_update_result {
15922 	cmdline_fixed_string_t ptype;
15923 	cmdline_fixed_string_t mapping;
15924 	cmdline_fixed_string_t reset;
15925 	portid_t port_id;
15926 	uint8_t hw_ptype;
15927 	uint32_t sw_ptype;
15928 };
15929 
15930 /* Common CLI fields for ptype mapping update*/
15931 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15932 	TOKEN_STRING_INITIALIZER
15933 		(struct cmd_ptype_mapping_update_result,
15934 		 ptype, "ptype");
15935 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15936 	TOKEN_STRING_INITIALIZER
15937 		(struct cmd_ptype_mapping_update_result,
15938 		 mapping, "mapping");
15939 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15940 	TOKEN_STRING_INITIALIZER
15941 		(struct cmd_ptype_mapping_update_result,
15942 		 reset, "update");
15943 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15944 	TOKEN_NUM_INITIALIZER
15945 		(struct cmd_ptype_mapping_update_result,
15946 		 port_id, RTE_UINT16);
15947 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15948 	TOKEN_NUM_INITIALIZER
15949 		(struct cmd_ptype_mapping_update_result,
15950 		 hw_ptype, RTE_UINT8);
15951 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15952 	TOKEN_NUM_INITIALIZER
15953 		(struct cmd_ptype_mapping_update_result,
15954 		 sw_ptype, RTE_UINT32);
15955 
15956 static void
15957 cmd_ptype_mapping_update_parsed(
15958 	void *parsed_result,
15959 	__rte_unused struct cmdline *cl,
15960 	__rte_unused void *data)
15961 {
15962 	struct cmd_ptype_mapping_update_result *res = parsed_result;
15963 	int ret = -ENOTSUP;
15964 #ifdef RTE_NET_I40E
15965 	struct rte_pmd_i40e_ptype_mapping mapping;
15966 #endif
15967 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15968 		return;
15969 
15970 #ifdef RTE_NET_I40E
15971 	mapping.hw_ptype = res->hw_ptype;
15972 	mapping.sw_ptype = res->sw_ptype;
15973 	ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15974 						&mapping,
15975 						1,
15976 						0);
15977 #endif
15978 
15979 	switch (ret) {
15980 	case 0:
15981 		break;
15982 	case -EINVAL:
15983 		fprintf(stderr, "invalid ptype 0x%8x\n", res->sw_ptype);
15984 		break;
15985 	case -ENODEV:
15986 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15987 		break;
15988 	case -ENOTSUP:
15989 		fprintf(stderr, "function not implemented\n");
15990 		break;
15991 	default:
15992 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15993 	}
15994 }
15995 
15996 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15997 	.f = cmd_ptype_mapping_update_parsed,
15998 	.data = NULL,
15999 	.help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16000 	.tokens = {
16001 		(void *)&cmd_ptype_mapping_update_ptype,
16002 		(void *)&cmd_ptype_mapping_update_mapping,
16003 		(void *)&cmd_ptype_mapping_update_update,
16004 		(void *)&cmd_ptype_mapping_update_port_id,
16005 		(void *)&cmd_ptype_mapping_update_hw_ptype,
16006 		(void *)&cmd_ptype_mapping_update_sw_ptype,
16007 		NULL,
16008 	},
16009 };
16010 
16011 /* Common result structure for file commands */
16012 struct cmd_cmdfile_result {
16013 	cmdline_fixed_string_t load;
16014 	cmdline_fixed_string_t filename;
16015 };
16016 
16017 /* Common CLI fields for file commands */
16018 cmdline_parse_token_string_t cmd_load_cmdfile =
16019 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16020 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16021 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16022 
16023 static void
16024 cmd_load_from_file_parsed(
16025 	void *parsed_result,
16026 	__rte_unused struct cmdline *cl,
16027 	__rte_unused void *data)
16028 {
16029 	struct cmd_cmdfile_result *res = parsed_result;
16030 
16031 	cmdline_read_from_file(res->filename);
16032 }
16033 
16034 cmdline_parse_inst_t cmd_load_from_file = {
16035 	.f = cmd_load_from_file_parsed,
16036 	.data = NULL,
16037 	.help_str = "load <filename>",
16038 	.tokens = {
16039 		(void *)&cmd_load_cmdfile,
16040 		(void *)&cmd_load_cmdfile_filename,
16041 		NULL,
16042 	},
16043 };
16044 
16045 /* Get Rx offloads capabilities */
16046 struct cmd_rx_offload_get_capa_result {
16047 	cmdline_fixed_string_t show;
16048 	cmdline_fixed_string_t port;
16049 	portid_t port_id;
16050 	cmdline_fixed_string_t rx_offload;
16051 	cmdline_fixed_string_t capabilities;
16052 };
16053 
16054 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16055 	TOKEN_STRING_INITIALIZER
16056 		(struct cmd_rx_offload_get_capa_result,
16057 		 show, "show");
16058 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16059 	TOKEN_STRING_INITIALIZER
16060 		(struct cmd_rx_offload_get_capa_result,
16061 		 port, "port");
16062 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16063 	TOKEN_NUM_INITIALIZER
16064 		(struct cmd_rx_offload_get_capa_result,
16065 		 port_id, RTE_UINT16);
16066 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16067 	TOKEN_STRING_INITIALIZER
16068 		(struct cmd_rx_offload_get_capa_result,
16069 		 rx_offload, "rx_offload");
16070 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16071 	TOKEN_STRING_INITIALIZER
16072 		(struct cmd_rx_offload_get_capa_result,
16073 		 capabilities, "capabilities");
16074 
16075 static void
16076 print_rx_offloads(uint64_t offloads)
16077 {
16078 	uint64_t single_offload;
16079 	int begin;
16080 	int end;
16081 	int bit;
16082 
16083 	if (offloads == 0)
16084 		return;
16085 
16086 	begin = __builtin_ctzll(offloads);
16087 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16088 
16089 	single_offload = 1ULL << begin;
16090 	for (bit = begin; bit < end; bit++) {
16091 		if (offloads & single_offload)
16092 			printf(" %s",
16093 			       rte_eth_dev_rx_offload_name(single_offload));
16094 		single_offload <<= 1;
16095 	}
16096 }
16097 
16098 static void
16099 cmd_rx_offload_get_capa_parsed(
16100 	void *parsed_result,
16101 	__rte_unused struct cmdline *cl,
16102 	__rte_unused void *data)
16103 {
16104 	struct cmd_rx_offload_get_capa_result *res = parsed_result;
16105 	struct rte_eth_dev_info dev_info;
16106 	portid_t port_id = res->port_id;
16107 	uint64_t queue_offloads;
16108 	uint64_t port_offloads;
16109 	int ret;
16110 
16111 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16112 	if (ret != 0)
16113 		return;
16114 
16115 	queue_offloads = dev_info.rx_queue_offload_capa;
16116 	port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16117 
16118 	printf("Rx Offloading Capabilities of port %d :\n", port_id);
16119 	printf("  Per Queue :");
16120 	print_rx_offloads(queue_offloads);
16121 
16122 	printf("\n");
16123 	printf("  Per Port  :");
16124 	print_rx_offloads(port_offloads);
16125 	printf("\n\n");
16126 }
16127 
16128 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16129 	.f = cmd_rx_offload_get_capa_parsed,
16130 	.data = NULL,
16131 	.help_str = "show port <port_id> rx_offload capabilities",
16132 	.tokens = {
16133 		(void *)&cmd_rx_offload_get_capa_show,
16134 		(void *)&cmd_rx_offload_get_capa_port,
16135 		(void *)&cmd_rx_offload_get_capa_port_id,
16136 		(void *)&cmd_rx_offload_get_capa_rx_offload,
16137 		(void *)&cmd_rx_offload_get_capa_capabilities,
16138 		NULL,
16139 	}
16140 };
16141 
16142 /* Get Rx offloads configuration */
16143 struct cmd_rx_offload_get_configuration_result {
16144 	cmdline_fixed_string_t show;
16145 	cmdline_fixed_string_t port;
16146 	portid_t port_id;
16147 	cmdline_fixed_string_t rx_offload;
16148 	cmdline_fixed_string_t configuration;
16149 };
16150 
16151 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16152 	TOKEN_STRING_INITIALIZER
16153 		(struct cmd_rx_offload_get_configuration_result,
16154 		 show, "show");
16155 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16156 	TOKEN_STRING_INITIALIZER
16157 		(struct cmd_rx_offload_get_configuration_result,
16158 		 port, "port");
16159 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16160 	TOKEN_NUM_INITIALIZER
16161 		(struct cmd_rx_offload_get_configuration_result,
16162 		 port_id, RTE_UINT16);
16163 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16164 	TOKEN_STRING_INITIALIZER
16165 		(struct cmd_rx_offload_get_configuration_result,
16166 		 rx_offload, "rx_offload");
16167 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16168 	TOKEN_STRING_INITIALIZER
16169 		(struct cmd_rx_offload_get_configuration_result,
16170 		 configuration, "configuration");
16171 
16172 static void
16173 cmd_rx_offload_get_configuration_parsed(
16174 	void *parsed_result,
16175 	__rte_unused struct cmdline *cl,
16176 	__rte_unused void *data)
16177 {
16178 	struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16179 	struct rte_eth_dev_info dev_info;
16180 	portid_t port_id = res->port_id;
16181 	struct rte_port *port = &ports[port_id];
16182 	struct rte_eth_conf dev_conf;
16183 	uint64_t port_offloads;
16184 	uint64_t queue_offloads;
16185 	uint16_t nb_rx_queues;
16186 	int q;
16187 	int ret;
16188 
16189 	printf("Rx Offloading Configuration of port %d :\n", port_id);
16190 
16191 	ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16192 	if (ret != 0)
16193 		return;
16194 
16195 	port_offloads = dev_conf.rxmode.offloads;
16196 	printf("  Port :");
16197 	print_rx_offloads(port_offloads);
16198 	printf("\n");
16199 
16200 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16201 	if (ret != 0)
16202 		return;
16203 
16204 	nb_rx_queues = dev_info.nb_rx_queues;
16205 	for (q = 0; q < nb_rx_queues; q++) {
16206 		queue_offloads = port->rx_conf[q].offloads;
16207 		printf("  Queue[%2d] :", q);
16208 		print_rx_offloads(queue_offloads);
16209 		printf("\n");
16210 	}
16211 	printf("\n");
16212 }
16213 
16214 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16215 	.f = cmd_rx_offload_get_configuration_parsed,
16216 	.data = NULL,
16217 	.help_str = "show port <port_id> rx_offload configuration",
16218 	.tokens = {
16219 		(void *)&cmd_rx_offload_get_configuration_show,
16220 		(void *)&cmd_rx_offload_get_configuration_port,
16221 		(void *)&cmd_rx_offload_get_configuration_port_id,
16222 		(void *)&cmd_rx_offload_get_configuration_rx_offload,
16223 		(void *)&cmd_rx_offload_get_configuration_configuration,
16224 		NULL,
16225 	}
16226 };
16227 
16228 /* Enable/Disable a per port offloading */
16229 struct cmd_config_per_port_rx_offload_result {
16230 	cmdline_fixed_string_t port;
16231 	cmdline_fixed_string_t config;
16232 	portid_t port_id;
16233 	cmdline_fixed_string_t rx_offload;
16234 	cmdline_fixed_string_t offload;
16235 	cmdline_fixed_string_t on_off;
16236 };
16237 
16238 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16239 	TOKEN_STRING_INITIALIZER
16240 		(struct cmd_config_per_port_rx_offload_result,
16241 		 port, "port");
16242 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16243 	TOKEN_STRING_INITIALIZER
16244 		(struct cmd_config_per_port_rx_offload_result,
16245 		 config, "config");
16246 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16247 	TOKEN_NUM_INITIALIZER
16248 		(struct cmd_config_per_port_rx_offload_result,
16249 		 port_id, RTE_UINT16);
16250 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16251 	TOKEN_STRING_INITIALIZER
16252 		(struct cmd_config_per_port_rx_offload_result,
16253 		 rx_offload, "rx_offload");
16254 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16255 	TOKEN_STRING_INITIALIZER
16256 		(struct cmd_config_per_port_rx_offload_result,
16257 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16258 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16259 			   "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16260 			   "scatter#buffer_split#timestamp#security#"
16261 			   "keep_crc#rss_hash");
16262 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16263 	TOKEN_STRING_INITIALIZER
16264 		(struct cmd_config_per_port_rx_offload_result,
16265 		 on_off, "on#off");
16266 
16267 static uint64_t
16268 search_rx_offload(const char *name)
16269 {
16270 	uint64_t single_offload;
16271 	const char *single_name;
16272 	int found = 0;
16273 	unsigned int bit;
16274 
16275 	single_offload = 1;
16276 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16277 		single_name = rte_eth_dev_rx_offload_name(single_offload);
16278 		if (!strcasecmp(single_name, name)) {
16279 			found = 1;
16280 			break;
16281 		}
16282 		single_offload <<= 1;
16283 	}
16284 
16285 	if (found)
16286 		return single_offload;
16287 
16288 	return 0;
16289 }
16290 
16291 static void
16292 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16293 				__rte_unused struct cmdline *cl,
16294 				__rte_unused void *data)
16295 {
16296 	struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16297 	portid_t port_id = res->port_id;
16298 	struct rte_eth_dev_info dev_info;
16299 	struct rte_port *port = &ports[port_id];
16300 	uint64_t single_offload;
16301 	uint16_t nb_rx_queues;
16302 	int q;
16303 	int ret;
16304 
16305 	if (port->port_status != RTE_PORT_STOPPED) {
16306 		fprintf(stderr,
16307 			"Error: Can't config offload when Port %d is not stopped\n",
16308 			port_id);
16309 		return;
16310 	}
16311 
16312 	single_offload = search_rx_offload(res->offload);
16313 	if (single_offload == 0) {
16314 		fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16315 		return;
16316 	}
16317 
16318 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16319 	if (ret != 0)
16320 		return;
16321 
16322 	nb_rx_queues = dev_info.nb_rx_queues;
16323 	if (!strcmp(res->on_off, "on")) {
16324 		port->dev_conf.rxmode.offloads |= single_offload;
16325 		for (q = 0; q < nb_rx_queues; q++)
16326 			port->rx_conf[q].offloads |= single_offload;
16327 	} else {
16328 		port->dev_conf.rxmode.offloads &= ~single_offload;
16329 		for (q = 0; q < nb_rx_queues; q++)
16330 			port->rx_conf[q].offloads &= ~single_offload;
16331 	}
16332 
16333 	cmd_reconfig_device_queue(port_id, 1, 1);
16334 }
16335 
16336 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16337 	.f = cmd_config_per_port_rx_offload_parsed,
16338 	.data = NULL,
16339 	.help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16340 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16341 		    "macsec_strip|header_split|vlan_filter|vlan_extend|"
16342 		    "jumbo_frame|scatter|buffer_split|timestamp|security|"
16343 		    "keep_crc|rss_hash on|off",
16344 	.tokens = {
16345 		(void *)&cmd_config_per_port_rx_offload_result_port,
16346 		(void *)&cmd_config_per_port_rx_offload_result_config,
16347 		(void *)&cmd_config_per_port_rx_offload_result_port_id,
16348 		(void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16349 		(void *)&cmd_config_per_port_rx_offload_result_offload,
16350 		(void *)&cmd_config_per_port_rx_offload_result_on_off,
16351 		NULL,
16352 	}
16353 };
16354 
16355 /* Enable/Disable a per queue offloading */
16356 struct cmd_config_per_queue_rx_offload_result {
16357 	cmdline_fixed_string_t port;
16358 	portid_t port_id;
16359 	cmdline_fixed_string_t rxq;
16360 	uint16_t queue_id;
16361 	cmdline_fixed_string_t rx_offload;
16362 	cmdline_fixed_string_t offload;
16363 	cmdline_fixed_string_t on_off;
16364 };
16365 
16366 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16367 	TOKEN_STRING_INITIALIZER
16368 		(struct cmd_config_per_queue_rx_offload_result,
16369 		 port, "port");
16370 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16371 	TOKEN_NUM_INITIALIZER
16372 		(struct cmd_config_per_queue_rx_offload_result,
16373 		 port_id, RTE_UINT16);
16374 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16375 	TOKEN_STRING_INITIALIZER
16376 		(struct cmd_config_per_queue_rx_offload_result,
16377 		 rxq, "rxq");
16378 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16379 	TOKEN_NUM_INITIALIZER
16380 		(struct cmd_config_per_queue_rx_offload_result,
16381 		 queue_id, RTE_UINT16);
16382 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16383 	TOKEN_STRING_INITIALIZER
16384 		(struct cmd_config_per_queue_rx_offload_result,
16385 		 rx_offload, "rx_offload");
16386 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16387 	TOKEN_STRING_INITIALIZER
16388 		(struct cmd_config_per_queue_rx_offload_result,
16389 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16390 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16391 			   "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16392 			   "scatter#buffer_split#timestamp#security#keep_crc");
16393 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16394 	TOKEN_STRING_INITIALIZER
16395 		(struct cmd_config_per_queue_rx_offload_result,
16396 		 on_off, "on#off");
16397 
16398 static void
16399 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16400 				__rte_unused struct cmdline *cl,
16401 				__rte_unused void *data)
16402 {
16403 	struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16404 	struct rte_eth_dev_info dev_info;
16405 	portid_t port_id = res->port_id;
16406 	uint16_t queue_id = res->queue_id;
16407 	struct rte_port *port = &ports[port_id];
16408 	uint64_t single_offload;
16409 	int ret;
16410 
16411 	if (port->port_status != RTE_PORT_STOPPED) {
16412 		fprintf(stderr,
16413 			"Error: Can't config offload when Port %d is not stopped\n",
16414 			port_id);
16415 		return;
16416 	}
16417 
16418 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16419 	if (ret != 0)
16420 		return;
16421 
16422 	if (queue_id >= dev_info.nb_rx_queues) {
16423 		fprintf(stderr,
16424 			"Error: input queue_id should be 0 ... %d\n",
16425 			dev_info.nb_rx_queues - 1);
16426 		return;
16427 	}
16428 
16429 	single_offload = search_rx_offload(res->offload);
16430 	if (single_offload == 0) {
16431 		fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16432 		return;
16433 	}
16434 
16435 	if (!strcmp(res->on_off, "on"))
16436 		port->rx_conf[queue_id].offloads |= single_offload;
16437 	else
16438 		port->rx_conf[queue_id].offloads &= ~single_offload;
16439 
16440 	cmd_reconfig_device_queue(port_id, 1, 1);
16441 }
16442 
16443 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16444 	.f = cmd_config_per_queue_rx_offload_parsed,
16445 	.data = NULL,
16446 	.help_str = "port <port_id> rxq <queue_id> rx_offload "
16447 		    "vlan_strip|ipv4_cksum|"
16448 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16449 		    "macsec_strip|header_split|vlan_filter|vlan_extend|"
16450 		    "jumbo_frame|scatter|buffer_split|timestamp|security|"
16451 		    "keep_crc on|off",
16452 	.tokens = {
16453 		(void *)&cmd_config_per_queue_rx_offload_result_port,
16454 		(void *)&cmd_config_per_queue_rx_offload_result_port_id,
16455 		(void *)&cmd_config_per_queue_rx_offload_result_rxq,
16456 		(void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16457 		(void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16458 		(void *)&cmd_config_per_queue_rx_offload_result_offload,
16459 		(void *)&cmd_config_per_queue_rx_offload_result_on_off,
16460 		NULL,
16461 	}
16462 };
16463 
16464 /* Get Tx offloads capabilities */
16465 struct cmd_tx_offload_get_capa_result {
16466 	cmdline_fixed_string_t show;
16467 	cmdline_fixed_string_t port;
16468 	portid_t port_id;
16469 	cmdline_fixed_string_t tx_offload;
16470 	cmdline_fixed_string_t capabilities;
16471 };
16472 
16473 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16474 	TOKEN_STRING_INITIALIZER
16475 		(struct cmd_tx_offload_get_capa_result,
16476 		 show, "show");
16477 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16478 	TOKEN_STRING_INITIALIZER
16479 		(struct cmd_tx_offload_get_capa_result,
16480 		 port, "port");
16481 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16482 	TOKEN_NUM_INITIALIZER
16483 		(struct cmd_tx_offload_get_capa_result,
16484 		 port_id, RTE_UINT16);
16485 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16486 	TOKEN_STRING_INITIALIZER
16487 		(struct cmd_tx_offload_get_capa_result,
16488 		 tx_offload, "tx_offload");
16489 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16490 	TOKEN_STRING_INITIALIZER
16491 		(struct cmd_tx_offload_get_capa_result,
16492 		 capabilities, "capabilities");
16493 
16494 static void
16495 print_tx_offloads(uint64_t offloads)
16496 {
16497 	uint64_t single_offload;
16498 	int begin;
16499 	int end;
16500 	int bit;
16501 
16502 	if (offloads == 0)
16503 		return;
16504 
16505 	begin = __builtin_ctzll(offloads);
16506 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16507 
16508 	single_offload = 1ULL << begin;
16509 	for (bit = begin; bit < end; bit++) {
16510 		if (offloads & single_offload)
16511 			printf(" %s",
16512 			       rte_eth_dev_tx_offload_name(single_offload));
16513 		single_offload <<= 1;
16514 	}
16515 }
16516 
16517 static void
16518 cmd_tx_offload_get_capa_parsed(
16519 	void *parsed_result,
16520 	__rte_unused struct cmdline *cl,
16521 	__rte_unused void *data)
16522 {
16523 	struct cmd_tx_offload_get_capa_result *res = parsed_result;
16524 	struct rte_eth_dev_info dev_info;
16525 	portid_t port_id = res->port_id;
16526 	uint64_t queue_offloads;
16527 	uint64_t port_offloads;
16528 	int ret;
16529 
16530 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16531 	if (ret != 0)
16532 		return;
16533 
16534 	queue_offloads = dev_info.tx_queue_offload_capa;
16535 	port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16536 
16537 	printf("Tx Offloading Capabilities of port %d :\n", port_id);
16538 	printf("  Per Queue :");
16539 	print_tx_offloads(queue_offloads);
16540 
16541 	printf("\n");
16542 	printf("  Per Port  :");
16543 	print_tx_offloads(port_offloads);
16544 	printf("\n\n");
16545 }
16546 
16547 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16548 	.f = cmd_tx_offload_get_capa_parsed,
16549 	.data = NULL,
16550 	.help_str = "show port <port_id> tx_offload capabilities",
16551 	.tokens = {
16552 		(void *)&cmd_tx_offload_get_capa_show,
16553 		(void *)&cmd_tx_offload_get_capa_port,
16554 		(void *)&cmd_tx_offload_get_capa_port_id,
16555 		(void *)&cmd_tx_offload_get_capa_tx_offload,
16556 		(void *)&cmd_tx_offload_get_capa_capabilities,
16557 		NULL,
16558 	}
16559 };
16560 
16561 /* Get Tx offloads configuration */
16562 struct cmd_tx_offload_get_configuration_result {
16563 	cmdline_fixed_string_t show;
16564 	cmdline_fixed_string_t port;
16565 	portid_t port_id;
16566 	cmdline_fixed_string_t tx_offload;
16567 	cmdline_fixed_string_t configuration;
16568 };
16569 
16570 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16571 	TOKEN_STRING_INITIALIZER
16572 		(struct cmd_tx_offload_get_configuration_result,
16573 		 show, "show");
16574 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16575 	TOKEN_STRING_INITIALIZER
16576 		(struct cmd_tx_offload_get_configuration_result,
16577 		 port, "port");
16578 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16579 	TOKEN_NUM_INITIALIZER
16580 		(struct cmd_tx_offload_get_configuration_result,
16581 		 port_id, RTE_UINT16);
16582 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16583 	TOKEN_STRING_INITIALIZER
16584 		(struct cmd_tx_offload_get_configuration_result,
16585 		 tx_offload, "tx_offload");
16586 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16587 	TOKEN_STRING_INITIALIZER
16588 		(struct cmd_tx_offload_get_configuration_result,
16589 		 configuration, "configuration");
16590 
16591 static void
16592 cmd_tx_offload_get_configuration_parsed(
16593 	void *parsed_result,
16594 	__rte_unused struct cmdline *cl,
16595 	__rte_unused void *data)
16596 {
16597 	struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16598 	struct rte_eth_dev_info dev_info;
16599 	portid_t port_id = res->port_id;
16600 	struct rte_port *port = &ports[port_id];
16601 	struct rte_eth_conf dev_conf;
16602 	uint64_t port_offloads;
16603 	uint64_t queue_offloads;
16604 	uint16_t nb_tx_queues;
16605 	int q;
16606 	int ret;
16607 
16608 	printf("Tx Offloading Configuration of port %d :\n", port_id);
16609 
16610 	ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16611 	if (ret != 0)
16612 		return;
16613 
16614 	port_offloads = dev_conf.txmode.offloads;
16615 	printf("  Port :");
16616 	print_tx_offloads(port_offloads);
16617 	printf("\n");
16618 
16619 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16620 	if (ret != 0)
16621 		return;
16622 
16623 	nb_tx_queues = dev_info.nb_tx_queues;
16624 	for (q = 0; q < nb_tx_queues; q++) {
16625 		queue_offloads = port->tx_conf[q].offloads;
16626 		printf("  Queue[%2d] :", q);
16627 		print_tx_offloads(queue_offloads);
16628 		printf("\n");
16629 	}
16630 	printf("\n");
16631 }
16632 
16633 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16634 	.f = cmd_tx_offload_get_configuration_parsed,
16635 	.data = NULL,
16636 	.help_str = "show port <port_id> tx_offload configuration",
16637 	.tokens = {
16638 		(void *)&cmd_tx_offload_get_configuration_show,
16639 		(void *)&cmd_tx_offload_get_configuration_port,
16640 		(void *)&cmd_tx_offload_get_configuration_port_id,
16641 		(void *)&cmd_tx_offload_get_configuration_tx_offload,
16642 		(void *)&cmd_tx_offload_get_configuration_configuration,
16643 		NULL,
16644 	}
16645 };
16646 
16647 /* Enable/Disable a per port offloading */
16648 struct cmd_config_per_port_tx_offload_result {
16649 	cmdline_fixed_string_t port;
16650 	cmdline_fixed_string_t config;
16651 	portid_t port_id;
16652 	cmdline_fixed_string_t tx_offload;
16653 	cmdline_fixed_string_t offload;
16654 	cmdline_fixed_string_t on_off;
16655 };
16656 
16657 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16658 	TOKEN_STRING_INITIALIZER
16659 		(struct cmd_config_per_port_tx_offload_result,
16660 		 port, "port");
16661 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16662 	TOKEN_STRING_INITIALIZER
16663 		(struct cmd_config_per_port_tx_offload_result,
16664 		 config, "config");
16665 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16666 	TOKEN_NUM_INITIALIZER
16667 		(struct cmd_config_per_port_tx_offload_result,
16668 		 port_id, RTE_UINT16);
16669 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16670 	TOKEN_STRING_INITIALIZER
16671 		(struct cmd_config_per_port_tx_offload_result,
16672 		 tx_offload, "tx_offload");
16673 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16674 	TOKEN_STRING_INITIALIZER
16675 		(struct cmd_config_per_port_tx_offload_result,
16676 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16677 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16678 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16679 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16680 			  "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16681 			  "send_on_timestamp");
16682 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16683 	TOKEN_STRING_INITIALIZER
16684 		(struct cmd_config_per_port_tx_offload_result,
16685 		 on_off, "on#off");
16686 
16687 static uint64_t
16688 search_tx_offload(const char *name)
16689 {
16690 	uint64_t single_offload;
16691 	const char *single_name;
16692 	int found = 0;
16693 	unsigned int bit;
16694 
16695 	single_offload = 1;
16696 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16697 		single_name = rte_eth_dev_tx_offload_name(single_offload);
16698 		if (single_name == NULL)
16699 			break;
16700 		if (!strcasecmp(single_name, name)) {
16701 			found = 1;
16702 			break;
16703 		} else if (!strcasecmp(single_name, "UNKNOWN"))
16704 			break;
16705 		single_offload <<= 1;
16706 	}
16707 
16708 	if (found)
16709 		return single_offload;
16710 
16711 	return 0;
16712 }
16713 
16714 static void
16715 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16716 				__rte_unused struct cmdline *cl,
16717 				__rte_unused void *data)
16718 {
16719 	struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16720 	portid_t port_id = res->port_id;
16721 	struct rte_eth_dev_info dev_info;
16722 	struct rte_port *port = &ports[port_id];
16723 	uint64_t single_offload;
16724 	uint16_t nb_tx_queues;
16725 	int q;
16726 	int ret;
16727 
16728 	if (port->port_status != RTE_PORT_STOPPED) {
16729 		fprintf(stderr,
16730 			"Error: Can't config offload when Port %d is not stopped\n",
16731 			port_id);
16732 		return;
16733 	}
16734 
16735 	single_offload = search_tx_offload(res->offload);
16736 	if (single_offload == 0) {
16737 		fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16738 		return;
16739 	}
16740 
16741 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16742 	if (ret != 0)
16743 		return;
16744 
16745 	nb_tx_queues = dev_info.nb_tx_queues;
16746 	if (!strcmp(res->on_off, "on")) {
16747 		port->dev_conf.txmode.offloads |= single_offload;
16748 		for (q = 0; q < nb_tx_queues; q++)
16749 			port->tx_conf[q].offloads |= single_offload;
16750 	} else {
16751 		port->dev_conf.txmode.offloads &= ~single_offload;
16752 		for (q = 0; q < nb_tx_queues; q++)
16753 			port->tx_conf[q].offloads &= ~single_offload;
16754 	}
16755 
16756 	cmd_reconfig_device_queue(port_id, 1, 1);
16757 }
16758 
16759 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16760 	.f = cmd_config_per_port_tx_offload_parsed,
16761 	.data = NULL,
16762 	.help_str = "port config <port_id> tx_offload "
16763 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16764 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16765 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16766 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16767 		    "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16768 		    "send_on_timestamp on|off",
16769 	.tokens = {
16770 		(void *)&cmd_config_per_port_tx_offload_result_port,
16771 		(void *)&cmd_config_per_port_tx_offload_result_config,
16772 		(void *)&cmd_config_per_port_tx_offload_result_port_id,
16773 		(void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16774 		(void *)&cmd_config_per_port_tx_offload_result_offload,
16775 		(void *)&cmd_config_per_port_tx_offload_result_on_off,
16776 		NULL,
16777 	}
16778 };
16779 
16780 /* Enable/Disable a per queue offloading */
16781 struct cmd_config_per_queue_tx_offload_result {
16782 	cmdline_fixed_string_t port;
16783 	portid_t port_id;
16784 	cmdline_fixed_string_t txq;
16785 	uint16_t queue_id;
16786 	cmdline_fixed_string_t tx_offload;
16787 	cmdline_fixed_string_t offload;
16788 	cmdline_fixed_string_t on_off;
16789 };
16790 
16791 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16792 	TOKEN_STRING_INITIALIZER
16793 		(struct cmd_config_per_queue_tx_offload_result,
16794 		 port, "port");
16795 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16796 	TOKEN_NUM_INITIALIZER
16797 		(struct cmd_config_per_queue_tx_offload_result,
16798 		 port_id, RTE_UINT16);
16799 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16800 	TOKEN_STRING_INITIALIZER
16801 		(struct cmd_config_per_queue_tx_offload_result,
16802 		 txq, "txq");
16803 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16804 	TOKEN_NUM_INITIALIZER
16805 		(struct cmd_config_per_queue_tx_offload_result,
16806 		 queue_id, RTE_UINT16);
16807 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16808 	TOKEN_STRING_INITIALIZER
16809 		(struct cmd_config_per_queue_tx_offload_result,
16810 		 tx_offload, "tx_offload");
16811 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16812 	TOKEN_STRING_INITIALIZER
16813 		(struct cmd_config_per_queue_tx_offload_result,
16814 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16815 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16816 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16817 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16818 			  "mt_lockfree#multi_segs#mbuf_fast_free#security");
16819 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16820 	TOKEN_STRING_INITIALIZER
16821 		(struct cmd_config_per_queue_tx_offload_result,
16822 		 on_off, "on#off");
16823 
16824 static void
16825 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16826 				__rte_unused struct cmdline *cl,
16827 				__rte_unused void *data)
16828 {
16829 	struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16830 	struct rte_eth_dev_info dev_info;
16831 	portid_t port_id = res->port_id;
16832 	uint16_t queue_id = res->queue_id;
16833 	struct rte_port *port = &ports[port_id];
16834 	uint64_t single_offload;
16835 	int ret;
16836 
16837 	if (port->port_status != RTE_PORT_STOPPED) {
16838 		fprintf(stderr,
16839 			"Error: Can't config offload when Port %d is not stopped\n",
16840 			port_id);
16841 		return;
16842 	}
16843 
16844 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16845 	if (ret != 0)
16846 		return;
16847 
16848 	if (queue_id >= dev_info.nb_tx_queues) {
16849 		fprintf(stderr,
16850 			"Error: input queue_id should be 0 ... %d\n",
16851 			dev_info.nb_tx_queues - 1);
16852 		return;
16853 	}
16854 
16855 	single_offload = search_tx_offload(res->offload);
16856 	if (single_offload == 0) {
16857 		fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16858 		return;
16859 	}
16860 
16861 	if (!strcmp(res->on_off, "on"))
16862 		port->tx_conf[queue_id].offloads |= single_offload;
16863 	else
16864 		port->tx_conf[queue_id].offloads &= ~single_offload;
16865 
16866 	cmd_reconfig_device_queue(port_id, 1, 1);
16867 }
16868 
16869 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16870 	.f = cmd_config_per_queue_tx_offload_parsed,
16871 	.data = NULL,
16872 	.help_str = "port <port_id> txq <queue_id> tx_offload "
16873 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16874 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16875 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16876 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16877 		    "mt_lockfree|multi_segs|mbuf_fast_free|security "
16878 		    "on|off",
16879 	.tokens = {
16880 		(void *)&cmd_config_per_queue_tx_offload_result_port,
16881 		(void *)&cmd_config_per_queue_tx_offload_result_port_id,
16882 		(void *)&cmd_config_per_queue_tx_offload_result_txq,
16883 		(void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16884 		(void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16885 		(void *)&cmd_config_per_queue_tx_offload_result_offload,
16886 		(void *)&cmd_config_per_queue_tx_offload_result_on_off,
16887 		NULL,
16888 	}
16889 };
16890 
16891 /* *** configure tx_metadata for specific port *** */
16892 struct cmd_config_tx_metadata_specific_result {
16893 	cmdline_fixed_string_t port;
16894 	cmdline_fixed_string_t keyword;
16895 	uint16_t port_id;
16896 	cmdline_fixed_string_t item;
16897 	uint32_t value;
16898 };
16899 
16900 static void
16901 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16902 				__rte_unused struct cmdline *cl,
16903 				__rte_unused void *data)
16904 {
16905 	struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16906 
16907 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16908 		return;
16909 	ports[res->port_id].tx_metadata = res->value;
16910 	/* Add/remove callback to insert valid metadata in every Tx packet. */
16911 	if (ports[res->port_id].tx_metadata)
16912 		add_tx_md_callback(res->port_id);
16913 	else
16914 		remove_tx_md_callback(res->port_id);
16915 	rte_flow_dynf_metadata_register();
16916 }
16917 
16918 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16919 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16920 			port, "port");
16921 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16922 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16923 			keyword, "config");
16924 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16925 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16926 			port_id, RTE_UINT16);
16927 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16928 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16929 			item, "tx_metadata");
16930 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16931 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16932 			value, RTE_UINT32);
16933 
16934 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16935 	.f = cmd_config_tx_metadata_specific_parsed,
16936 	.data = NULL,
16937 	.help_str = "port config <port_id> tx_metadata <value>",
16938 	.tokens = {
16939 		(void *)&cmd_config_tx_metadata_specific_port,
16940 		(void *)&cmd_config_tx_metadata_specific_keyword,
16941 		(void *)&cmd_config_tx_metadata_specific_id,
16942 		(void *)&cmd_config_tx_metadata_specific_item,
16943 		(void *)&cmd_config_tx_metadata_specific_value,
16944 		NULL,
16945 	},
16946 };
16947 
16948 /* *** set dynf *** */
16949 struct cmd_config_tx_dynf_specific_result {
16950 	cmdline_fixed_string_t port;
16951 	cmdline_fixed_string_t keyword;
16952 	uint16_t port_id;
16953 	cmdline_fixed_string_t item;
16954 	cmdline_fixed_string_t name;
16955 	cmdline_fixed_string_t value;
16956 };
16957 
16958 static void
16959 cmd_config_dynf_specific_parsed(void *parsed_result,
16960 				__rte_unused struct cmdline *cl,
16961 				__rte_unused void *data)
16962 {
16963 	struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16964 	struct rte_mbuf_dynflag desc_flag;
16965 	int flag;
16966 	uint64_t old_port_flags;
16967 
16968 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16969 		return;
16970 	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16971 	if (flag <= 0) {
16972 		if (strlcpy(desc_flag.name, res->name,
16973 			    RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16974 			fprintf(stderr, "Flag name too long\n");
16975 			return;
16976 		}
16977 		desc_flag.flags = 0;
16978 		flag = rte_mbuf_dynflag_register(&desc_flag);
16979 		if (flag < 0) {
16980 			fprintf(stderr, "Can't register flag\n");
16981 			return;
16982 		}
16983 		strcpy(dynf_names[flag], desc_flag.name);
16984 	}
16985 	old_port_flags = ports[res->port_id].mbuf_dynf;
16986 	if (!strcmp(res->value, "set")) {
16987 		ports[res->port_id].mbuf_dynf |= 1UL << flag;
16988 		if (old_port_flags == 0)
16989 			add_tx_dynf_callback(res->port_id);
16990 	} else {
16991 		ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16992 		if (ports[res->port_id].mbuf_dynf == 0)
16993 			remove_tx_dynf_callback(res->port_id);
16994 	}
16995 }
16996 
16997 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16998 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16999 			keyword, "port");
17000 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
17001 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17002 			keyword, "config");
17003 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
17004 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17005 			port_id, RTE_UINT16);
17006 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
17007 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17008 			item, "dynf");
17009 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
17010 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17011 			name, NULL);
17012 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
17013 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17014 			value, "set#clear");
17015 
17016 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
17017 	.f = cmd_config_dynf_specific_parsed,
17018 	.data = NULL,
17019 	.help_str = "port config <port id> dynf <name> set|clear",
17020 	.tokens = {
17021 		(void *)&cmd_config_tx_dynf_specific_port,
17022 		(void *)&cmd_config_tx_dynf_specific_keyword,
17023 		(void *)&cmd_config_tx_dynf_specific_port_id,
17024 		(void *)&cmd_config_tx_dynf_specific_item,
17025 		(void *)&cmd_config_tx_dynf_specific_name,
17026 		(void *)&cmd_config_tx_dynf_specific_value,
17027 		NULL,
17028 	},
17029 };
17030 
17031 /* *** display tx_metadata per port configuration *** */
17032 struct cmd_show_tx_metadata_result {
17033 	cmdline_fixed_string_t cmd_show;
17034 	cmdline_fixed_string_t cmd_port;
17035 	cmdline_fixed_string_t cmd_keyword;
17036 	portid_t cmd_pid;
17037 };
17038 
17039 static void
17040 cmd_show_tx_metadata_parsed(void *parsed_result,
17041 		__rte_unused struct cmdline *cl,
17042 		__rte_unused void *data)
17043 {
17044 	struct cmd_show_tx_metadata_result *res = parsed_result;
17045 
17046 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17047 		fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17048 		return;
17049 	}
17050 	if (!strcmp(res->cmd_keyword, "tx_metadata")) {
17051 		printf("Port %u tx_metadata: %u\n", res->cmd_pid,
17052 		       ports[res->cmd_pid].tx_metadata);
17053 	}
17054 }
17055 
17056 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
17057 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17058 			cmd_show, "show");
17059 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
17060 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17061 			cmd_port, "port");
17062 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
17063 	TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
17064 			cmd_pid, RTE_UINT16);
17065 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
17066 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17067 			cmd_keyword, "tx_metadata");
17068 
17069 cmdline_parse_inst_t cmd_show_tx_metadata = {
17070 	.f = cmd_show_tx_metadata_parsed,
17071 	.data = NULL,
17072 	.help_str = "show port <port_id> tx_metadata",
17073 	.tokens = {
17074 		(void *)&cmd_show_tx_metadata_show,
17075 		(void *)&cmd_show_tx_metadata_port,
17076 		(void *)&cmd_show_tx_metadata_pid,
17077 		(void *)&cmd_show_tx_metadata_keyword,
17078 		NULL,
17079 	},
17080 };
17081 
17082 /* *** show fec capability per port configuration *** */
17083 struct cmd_show_fec_capability_result {
17084 	cmdline_fixed_string_t cmd_show;
17085 	cmdline_fixed_string_t cmd_port;
17086 	cmdline_fixed_string_t cmd_fec;
17087 	cmdline_fixed_string_t cmd_keyword;
17088 	portid_t cmd_pid;
17089 };
17090 
17091 static void
17092 cmd_show_fec_capability_parsed(void *parsed_result,
17093 		__rte_unused struct cmdline *cl,
17094 		__rte_unused void *data)
17095 {
17096 	struct cmd_show_fec_capability_result *res = parsed_result;
17097 	struct rte_eth_fec_capa *speed_fec_capa;
17098 	unsigned int num;
17099 	int ret;
17100 
17101 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17102 		fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17103 		return;
17104 	}
17105 
17106 	ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
17107 	if (ret == -ENOTSUP) {
17108 		fprintf(stderr, "Function not implemented\n");
17109 		return;
17110 	} else if (ret < 0) {
17111 		fprintf(stderr, "Get FEC capability failed: %d\n", ret);
17112 		return;
17113 	}
17114 
17115 	num = (unsigned int)ret;
17116 	speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
17117 	if (speed_fec_capa == NULL) {
17118 		fprintf(stderr, "Failed to alloc FEC capability buffer\n");
17119 		return;
17120 	}
17121 
17122 	ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
17123 	if (ret < 0) {
17124 		fprintf(stderr, "Error getting FEC capability: %d\n", ret);
17125 		goto out;
17126 	}
17127 
17128 	show_fec_capability(num, speed_fec_capa);
17129 out:
17130 	free(speed_fec_capa);
17131 }
17132 
17133 cmdline_parse_token_string_t cmd_show_fec_capability_show =
17134 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17135 			cmd_show, "show");
17136 cmdline_parse_token_string_t cmd_show_fec_capability_port =
17137 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17138 			cmd_port, "port");
17139 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
17140 	TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
17141 			cmd_pid, RTE_UINT16);
17142 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
17143 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17144 			cmd_fec, "fec");
17145 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
17146 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17147 			cmd_keyword, "capabilities");
17148 
17149 cmdline_parse_inst_t cmd_show_capability = {
17150 	.f = cmd_show_fec_capability_parsed,
17151 	.data = NULL,
17152 	.help_str = "show port <port_id> fec capabilities",
17153 	.tokens = {
17154 		(void *)&cmd_show_fec_capability_show,
17155 		(void *)&cmd_show_fec_capability_port,
17156 		(void *)&cmd_show_fec_capability_pid,
17157 		(void *)&cmd_show_fec_capability_fec,
17158 		(void *)&cmd_show_fec_capability_keyword,
17159 		NULL,
17160 	},
17161 };
17162 
17163 /* *** show fec mode per port configuration *** */
17164 struct cmd_show_fec_metadata_result {
17165 	cmdline_fixed_string_t cmd_show;
17166 	cmdline_fixed_string_t cmd_port;
17167 	cmdline_fixed_string_t cmd_keyword;
17168 	portid_t cmd_pid;
17169 };
17170 
17171 static void
17172 cmd_show_fec_mode_parsed(void *parsed_result,
17173 		__rte_unused struct cmdline *cl,
17174 		__rte_unused void *data)
17175 {
17176 #define FEC_NAME_SIZE 16
17177 	struct cmd_show_fec_metadata_result *res = parsed_result;
17178 	uint32_t mode;
17179 	char buf[FEC_NAME_SIZE];
17180 	int ret;
17181 
17182 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17183 		fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17184 		return;
17185 	}
17186 	ret = rte_eth_fec_get(res->cmd_pid, &mode);
17187 	if (ret == -ENOTSUP) {
17188 		fprintf(stderr, "Function not implemented\n");
17189 		return;
17190 	} else if (ret < 0) {
17191 		fprintf(stderr, "Get FEC mode failed\n");
17192 		return;
17193 	}
17194 
17195 	switch (mode) {
17196 	case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
17197 		strlcpy(buf, "off", sizeof(buf));
17198 		break;
17199 	case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
17200 		strlcpy(buf, "auto", sizeof(buf));
17201 		break;
17202 	case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
17203 		strlcpy(buf, "baser", sizeof(buf));
17204 		break;
17205 	case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
17206 		strlcpy(buf, "rs", sizeof(buf));
17207 		break;
17208 	default:
17209 		return;
17210 	}
17211 
17212 	printf("%s\n", buf);
17213 }
17214 
17215 cmdline_parse_token_string_t cmd_show_fec_mode_show =
17216 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17217 			cmd_show, "show");
17218 cmdline_parse_token_string_t cmd_show_fec_mode_port =
17219 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17220 			cmd_port, "port");
17221 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
17222 	TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
17223 			cmd_pid, RTE_UINT16);
17224 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
17225 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17226 			cmd_keyword, "fec_mode");
17227 
17228 cmdline_parse_inst_t cmd_show_fec_mode = {
17229 	.f = cmd_show_fec_mode_parsed,
17230 	.data = NULL,
17231 	.help_str = "show port <port_id> fec_mode",
17232 	.tokens = {
17233 		(void *)&cmd_show_fec_mode_show,
17234 		(void *)&cmd_show_fec_mode_port,
17235 		(void *)&cmd_show_fec_mode_pid,
17236 		(void *)&cmd_show_fec_mode_keyword,
17237 		NULL,
17238 	},
17239 };
17240 
17241 /* *** set fec mode per port configuration *** */
17242 struct cmd_set_port_fec_mode {
17243 	cmdline_fixed_string_t set;
17244 	cmdline_fixed_string_t port;
17245 	portid_t port_id;
17246 	cmdline_fixed_string_t fec_mode;
17247 	cmdline_fixed_string_t fec_value;
17248 };
17249 
17250 /* Common CLI fields for set fec mode */
17251 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
17252 	TOKEN_STRING_INITIALIZER
17253 		(struct cmd_set_port_fec_mode,
17254 		 set, "set");
17255 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
17256 	TOKEN_STRING_INITIALIZER
17257 		(struct cmd_set_port_fec_mode,
17258 		 port, "port");
17259 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
17260 	TOKEN_NUM_INITIALIZER
17261 		(struct cmd_set_port_fec_mode,
17262 		 port_id, RTE_UINT16);
17263 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
17264 	TOKEN_STRING_INITIALIZER
17265 		(struct cmd_set_port_fec_mode,
17266 		 fec_mode, "fec_mode");
17267 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
17268 	TOKEN_STRING_INITIALIZER
17269 		(struct cmd_set_port_fec_mode,
17270 		 fec_value, NULL);
17271 
17272 static void
17273 cmd_set_port_fec_mode_parsed(
17274 	void *parsed_result,
17275 	__rte_unused struct cmdline *cl,
17276 	__rte_unused void *data)
17277 {
17278 	struct cmd_set_port_fec_mode *res = parsed_result;
17279 	uint16_t port_id = res->port_id;
17280 	uint32_t fec_capa;
17281 	int ret;
17282 
17283 	ret = parse_fec_mode(res->fec_value, &fec_capa);
17284 	if (ret < 0) {
17285 		fprintf(stderr, "Unknown fec mode: %s for port %d\n",
17286 				res->fec_value,	port_id);
17287 		return;
17288 	}
17289 
17290 	ret = rte_eth_fec_set(port_id, fec_capa);
17291 	if (ret == -ENOTSUP) {
17292 		fprintf(stderr, "Function not implemented\n");
17293 		return;
17294 	} else if (ret < 0) {
17295 		fprintf(stderr, "Set FEC mode failed\n");
17296 		return;
17297 	}
17298 }
17299 
17300 cmdline_parse_inst_t cmd_set_fec_mode = {
17301 	.f = cmd_set_port_fec_mode_parsed,
17302 	.data = NULL,
17303 	.help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17304 	.tokens = {
17305 		(void *)&cmd_set_port_fec_mode_set,
17306 		(void *)&cmd_set_port_fec_mode_port,
17307 		(void *)&cmd_set_port_fec_mode_port_id,
17308 		(void *)&cmd_set_port_fec_mode_str,
17309 		(void *)&cmd_set_port_fec_mode_value,
17310 		NULL,
17311 	},
17312 };
17313 
17314 /* show port supported ptypes */
17315 
17316 /* Common result structure for show port ptypes */
17317 struct cmd_show_port_supported_ptypes_result {
17318 	cmdline_fixed_string_t show;
17319 	cmdline_fixed_string_t port;
17320 	portid_t port_id;
17321 	cmdline_fixed_string_t ptypes;
17322 };
17323 
17324 /* Common CLI fields for show port ptypes */
17325 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17326 	TOKEN_STRING_INITIALIZER
17327 		(struct cmd_show_port_supported_ptypes_result,
17328 		 show, "show");
17329 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17330 	TOKEN_STRING_INITIALIZER
17331 		(struct cmd_show_port_supported_ptypes_result,
17332 		 port, "port");
17333 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17334 	TOKEN_NUM_INITIALIZER
17335 		(struct cmd_show_port_supported_ptypes_result,
17336 		 port_id, RTE_UINT16);
17337 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17338 	TOKEN_STRING_INITIALIZER
17339 		(struct cmd_show_port_supported_ptypes_result,
17340 		 ptypes, "ptypes");
17341 
17342 static void
17343 cmd_show_port_supported_ptypes_parsed(
17344 	void *parsed_result,
17345 	__rte_unused struct cmdline *cl,
17346 	__rte_unused void *data)
17347 {
17348 #define RSVD_PTYPE_MASK       0xf0000000
17349 #define MAX_PTYPES_PER_LAYER  16
17350 #define LTYPE_NAMESIZE        32
17351 #define PTYPE_NAMESIZE        256
17352 	struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17353 	char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17354 	uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17355 	uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17356 	uint16_t port_id = res->port_id;
17357 	int ret, i;
17358 
17359 	ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17360 	if (ret < 0)
17361 		return;
17362 
17363 	while (ptype_mask != RSVD_PTYPE_MASK) {
17364 
17365 		switch (ptype_mask) {
17366 		case RTE_PTYPE_L2_MASK:
17367 			strlcpy(ltype, "L2", sizeof(ltype));
17368 			break;
17369 		case RTE_PTYPE_L3_MASK:
17370 			strlcpy(ltype, "L3", sizeof(ltype));
17371 			break;
17372 		case RTE_PTYPE_L4_MASK:
17373 			strlcpy(ltype, "L4", sizeof(ltype));
17374 			break;
17375 		case RTE_PTYPE_TUNNEL_MASK:
17376 			strlcpy(ltype, "Tunnel", sizeof(ltype));
17377 			break;
17378 		case RTE_PTYPE_INNER_L2_MASK:
17379 			strlcpy(ltype, "Inner L2", sizeof(ltype));
17380 			break;
17381 		case RTE_PTYPE_INNER_L3_MASK:
17382 			strlcpy(ltype, "Inner L3", sizeof(ltype));
17383 			break;
17384 		case RTE_PTYPE_INNER_L4_MASK:
17385 			strlcpy(ltype, "Inner L4", sizeof(ltype));
17386 			break;
17387 		default:
17388 			return;
17389 		}
17390 
17391 		ret = rte_eth_dev_get_supported_ptypes(res->port_id,
17392 						       ptype_mask, ptypes,
17393 						       MAX_PTYPES_PER_LAYER);
17394 
17395 		if (ret > 0)
17396 			printf("Supported %s ptypes:\n", ltype);
17397 		else
17398 			printf("%s ptypes unsupported\n", ltype);
17399 
17400 		for (i = 0; i < ret; ++i) {
17401 			rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
17402 			printf("%s\n", buf);
17403 		}
17404 
17405 		ptype_mask <<= 4;
17406 	}
17407 }
17408 
17409 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
17410 	.f = cmd_show_port_supported_ptypes_parsed,
17411 	.data = NULL,
17412 	.help_str = "show port <port_id> ptypes",
17413 	.tokens = {
17414 		(void *)&cmd_show_port_supported_ptypes_show,
17415 		(void *)&cmd_show_port_supported_ptypes_port,
17416 		(void *)&cmd_show_port_supported_ptypes_port_id,
17417 		(void *)&cmd_show_port_supported_ptypes_ptypes,
17418 		NULL,
17419 	},
17420 };
17421 
17422 /* *** display rx/tx descriptor status *** */
17423 struct cmd_show_rx_tx_desc_status_result {
17424 	cmdline_fixed_string_t cmd_show;
17425 	cmdline_fixed_string_t cmd_port;
17426 	cmdline_fixed_string_t cmd_keyword;
17427 	cmdline_fixed_string_t cmd_desc;
17428 	cmdline_fixed_string_t cmd_status;
17429 	portid_t cmd_pid;
17430 	portid_t cmd_qid;
17431 	portid_t cmd_did;
17432 };
17433 
17434 static void
17435 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17436 		__rte_unused struct cmdline *cl,
17437 		__rte_unused void *data)
17438 {
17439 	struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17440 	int rc;
17441 
17442 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17443 		fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17444 		return;
17445 	}
17446 
17447 	if (!strcmp(res->cmd_keyword, "rxq")) {
17448 		rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17449 					     res->cmd_did);
17450 		if (rc < 0) {
17451 			fprintf(stderr,
17452 				"Invalid input: queue id = %d, desc id = %d\n",
17453 				res->cmd_qid, res->cmd_did);
17454 			return;
17455 		}
17456 		if (rc == RTE_ETH_RX_DESC_AVAIL)
17457 			printf("Desc status = AVAILABLE\n");
17458 		else if (rc == RTE_ETH_RX_DESC_DONE)
17459 			printf("Desc status = DONE\n");
17460 		else
17461 			printf("Desc status = UNAVAILABLE\n");
17462 	} else if (!strcmp(res->cmd_keyword, "txq")) {
17463 		rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17464 					     res->cmd_did);
17465 		if (rc < 0) {
17466 			fprintf(stderr,
17467 				"Invalid input: queue id = %d, desc id = %d\n",
17468 				res->cmd_qid, res->cmd_did);
17469 			return;
17470 		}
17471 		if (rc == RTE_ETH_TX_DESC_FULL)
17472 			printf("Desc status = FULL\n");
17473 		else if (rc == RTE_ETH_TX_DESC_DONE)
17474 			printf("Desc status = DONE\n");
17475 		else
17476 			printf("Desc status = UNAVAILABLE\n");
17477 	}
17478 }
17479 
17480 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17481 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17482 			cmd_show, "show");
17483 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17484 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17485 			cmd_port, "port");
17486 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17487 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17488 			cmd_pid, RTE_UINT16);
17489 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17490 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17491 			cmd_keyword, "rxq#txq");
17492 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17493 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17494 			cmd_qid, RTE_UINT16);
17495 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17496 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17497 			cmd_desc, "desc");
17498 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17499 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17500 			cmd_did, RTE_UINT16);
17501 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17502 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17503 			cmd_status, "status");
17504 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17505 	.f = cmd_show_rx_tx_desc_status_parsed,
17506 	.data = NULL,
17507 	.help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17508 		"status",
17509 	.tokens = {
17510 		(void *)&cmd_show_rx_tx_desc_status_show,
17511 		(void *)&cmd_show_rx_tx_desc_status_port,
17512 		(void *)&cmd_show_rx_tx_desc_status_pid,
17513 		(void *)&cmd_show_rx_tx_desc_status_keyword,
17514 		(void *)&cmd_show_rx_tx_desc_status_qid,
17515 		(void *)&cmd_show_rx_tx_desc_status_desc,
17516 		(void *)&cmd_show_rx_tx_desc_status_did,
17517 		(void *)&cmd_show_rx_tx_desc_status_status,
17518 		NULL,
17519 	},
17520 };
17521 
17522 /* *** display rx queue desc used count *** */
17523 struct cmd_show_rx_queue_desc_used_count_result {
17524 	cmdline_fixed_string_t cmd_show;
17525 	cmdline_fixed_string_t cmd_port;
17526 	cmdline_fixed_string_t cmd_rxq;
17527 	cmdline_fixed_string_t cmd_desc;
17528 	cmdline_fixed_string_t cmd_used;
17529 	cmdline_fixed_string_t cmd_count;
17530 	portid_t cmd_pid;
17531 	portid_t cmd_qid;
17532 };
17533 
17534 static void
17535 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
17536 		__rte_unused struct cmdline *cl,
17537 		__rte_unused void *data)
17538 {
17539 	struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
17540 	int rc;
17541 
17542 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17543 		fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17544 		return;
17545 	}
17546 
17547 	rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
17548 	if (rc < 0) {
17549 		fprintf(stderr, "Invalid queueid = %d\n", res->cmd_qid);
17550 		return;
17551 	}
17552 	printf("Used desc count = %d\n", rc);
17553 }
17554 
17555 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
17556 	TOKEN_STRING_INITIALIZER
17557 		(struct cmd_show_rx_queue_desc_used_count_result,
17558 		 cmd_show, "show");
17559 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
17560 	TOKEN_STRING_INITIALIZER
17561 		(struct cmd_show_rx_queue_desc_used_count_result,
17562 		 cmd_port, "port");
17563 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
17564 	TOKEN_NUM_INITIALIZER
17565 		(struct cmd_show_rx_queue_desc_used_count_result,
17566 		 cmd_pid, RTE_UINT16);
17567 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
17568 	TOKEN_STRING_INITIALIZER
17569 		(struct cmd_show_rx_queue_desc_used_count_result,
17570 		 cmd_rxq, "rxq");
17571 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
17572 	TOKEN_NUM_INITIALIZER
17573 		(struct cmd_show_rx_queue_desc_used_count_result,
17574 		 cmd_qid, RTE_UINT16);
17575 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
17576 	TOKEN_STRING_INITIALIZER
17577 		(struct cmd_show_rx_queue_desc_used_count_result,
17578 		 cmd_count, "desc");
17579 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
17580 	TOKEN_STRING_INITIALIZER
17581 		(struct cmd_show_rx_queue_desc_used_count_result,
17582 		 cmd_count, "used");
17583 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
17584 	TOKEN_STRING_INITIALIZER
17585 		(struct cmd_show_rx_queue_desc_used_count_result,
17586 		 cmd_count, "count");
17587 cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
17588 	.f = cmd_show_rx_queue_desc_used_count_parsed,
17589 	.data = NULL,
17590 	.help_str = "show port <port_id> rxq <queue_id> desc used count",
17591 	.tokens = {
17592 		(void *)&cmd_show_rx_queue_desc_used_count_show,
17593 		(void *)&cmd_show_rx_queue_desc_used_count_port,
17594 		(void *)&cmd_show_rx_queue_desc_used_count_pid,
17595 		(void *)&cmd_show_rx_queue_desc_used_count_rxq,
17596 		(void *)&cmd_show_rx_queue_desc_used_count_qid,
17597 		(void *)&cmd_show_rx_queue_desc_used_count_desc,
17598 		(void *)&cmd_show_rx_queue_desc_used_count_used,
17599 		(void *)&cmd_show_rx_queue_desc_used_count_count,
17600 		NULL,
17601 	},
17602 };
17603 
17604 /* Common result structure for set port ptypes */
17605 struct cmd_set_port_ptypes_result {
17606 	cmdline_fixed_string_t set;
17607 	cmdline_fixed_string_t port;
17608 	portid_t port_id;
17609 	cmdline_fixed_string_t ptype_mask;
17610 	uint32_t mask;
17611 };
17612 
17613 /* Common CLI fields for set port ptypes */
17614 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17615 	TOKEN_STRING_INITIALIZER
17616 		(struct cmd_set_port_ptypes_result,
17617 		 set, "set");
17618 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17619 	TOKEN_STRING_INITIALIZER
17620 		(struct cmd_set_port_ptypes_result,
17621 		 port, "port");
17622 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17623 	TOKEN_NUM_INITIALIZER
17624 		(struct cmd_set_port_ptypes_result,
17625 		 port_id, RTE_UINT16);
17626 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17627 	TOKEN_STRING_INITIALIZER
17628 		(struct cmd_set_port_ptypes_result,
17629 		 ptype_mask, "ptype_mask");
17630 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17631 	TOKEN_NUM_INITIALIZER
17632 		(struct cmd_set_port_ptypes_result,
17633 		 mask, RTE_UINT32);
17634 
17635 static void
17636 cmd_set_port_ptypes_parsed(
17637 	void *parsed_result,
17638 	__rte_unused struct cmdline *cl,
17639 	__rte_unused void *data)
17640 {
17641 	struct cmd_set_port_ptypes_result *res = parsed_result;
17642 #define PTYPE_NAMESIZE        256
17643 	char ptype_name[PTYPE_NAMESIZE];
17644 	uint16_t port_id = res->port_id;
17645 	uint32_t ptype_mask = res->mask;
17646 	int ret, i;
17647 
17648 	ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17649 					       NULL, 0);
17650 	if (ret <= 0) {
17651 		fprintf(stderr, "Port %d doesn't support any ptypes.\n",
17652 			port_id);
17653 		return;
17654 	}
17655 
17656 	uint32_t ptypes[ret];
17657 
17658 	ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17659 	if (ret < 0) {
17660 		fprintf(stderr, "Unable to set requested ptypes for Port %d\n",
17661 			port_id);
17662 		return;
17663 	}
17664 
17665 	printf("Successfully set following ptypes for Port %d\n", port_id);
17666 	for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17667 		rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17668 		printf("%s\n", ptype_name);
17669 	}
17670 
17671 	clear_ptypes = false;
17672 }
17673 
17674 cmdline_parse_inst_t cmd_set_port_ptypes = {
17675 	.f = cmd_set_port_ptypes_parsed,
17676 	.data = NULL,
17677 	.help_str = "set port <port_id> ptype_mask <mask>",
17678 	.tokens = {
17679 		(void *)&cmd_set_port_ptypes_set,
17680 		(void *)&cmd_set_port_ptypes_port,
17681 		(void *)&cmd_set_port_ptypes_port_id,
17682 		(void *)&cmd_set_port_ptypes_mask_str,
17683 		(void *)&cmd_set_port_ptypes_mask_u32,
17684 		NULL,
17685 	},
17686 };
17687 
17688 /* *** display mac addresses added to a port *** */
17689 struct cmd_showport_macs_result {
17690 	cmdline_fixed_string_t cmd_show;
17691 	cmdline_fixed_string_t cmd_port;
17692 	cmdline_fixed_string_t cmd_keyword;
17693 	portid_t cmd_pid;
17694 };
17695 
17696 static void
17697 cmd_showport_macs_parsed(void *parsed_result,
17698 		__rte_unused struct cmdline *cl,
17699 		__rte_unused void *data)
17700 {
17701 	struct cmd_showport_macs_result *res = parsed_result;
17702 
17703 	if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17704 		return;
17705 
17706 	if (!strcmp(res->cmd_keyword, "macs"))
17707 		show_macs(res->cmd_pid);
17708 	else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17709 		show_mcast_macs(res->cmd_pid);
17710 }
17711 
17712 cmdline_parse_token_string_t cmd_showport_macs_show =
17713 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17714 			cmd_show, "show");
17715 cmdline_parse_token_string_t cmd_showport_macs_port =
17716 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17717 			cmd_port, "port");
17718 cmdline_parse_token_num_t cmd_showport_macs_pid =
17719 	TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17720 			cmd_pid, RTE_UINT16);
17721 cmdline_parse_token_string_t cmd_showport_macs_keyword =
17722 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17723 			cmd_keyword, "macs#mcast_macs");
17724 
17725 cmdline_parse_inst_t cmd_showport_macs = {
17726 	.f = cmd_showport_macs_parsed,
17727 	.data = NULL,
17728 	.help_str = "show port <port_id> macs|mcast_macs",
17729 	.tokens = {
17730 		(void *)&cmd_showport_macs_show,
17731 		(void *)&cmd_showport_macs_port,
17732 		(void *)&cmd_showport_macs_pid,
17733 		(void *)&cmd_showport_macs_keyword,
17734 		NULL,
17735 	},
17736 };
17737 
17738 /* *** show flow transfer proxy port ID for the given port *** */
17739 struct cmd_show_port_flow_transfer_proxy_result {
17740 	cmdline_fixed_string_t show;
17741 	cmdline_fixed_string_t port;
17742 	portid_t port_id;
17743 	cmdline_fixed_string_t flow;
17744 	cmdline_fixed_string_t transfer;
17745 	cmdline_fixed_string_t proxy;
17746 };
17747 
17748 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_show =
17749 	TOKEN_STRING_INITIALIZER
17750 		(struct cmd_show_port_flow_transfer_proxy_result,
17751 		 show, "show");
17752 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_port =
17753 	TOKEN_STRING_INITIALIZER
17754 		(struct cmd_show_port_flow_transfer_proxy_result,
17755 		 port, "port");
17756 cmdline_parse_token_num_t cmd_show_port_flow_transfer_proxy_port_id =
17757 	TOKEN_NUM_INITIALIZER
17758 		(struct cmd_show_port_flow_transfer_proxy_result,
17759 		 port_id, RTE_UINT16);
17760 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_flow =
17761 	TOKEN_STRING_INITIALIZER
17762 		(struct cmd_show_port_flow_transfer_proxy_result,
17763 		 flow, "flow");
17764 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_transfer =
17765 	TOKEN_STRING_INITIALIZER
17766 		(struct cmd_show_port_flow_transfer_proxy_result,
17767 		 transfer, "transfer");
17768 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_proxy =
17769 	TOKEN_STRING_INITIALIZER
17770 		(struct cmd_show_port_flow_transfer_proxy_result,
17771 		 proxy, "proxy");
17772 
17773 static void
17774 cmd_show_port_flow_transfer_proxy_parsed(void *parsed_result,
17775 					 __rte_unused struct cmdline *cl,
17776 					 __rte_unused void *data)
17777 {
17778 	struct cmd_show_port_flow_transfer_proxy_result *res = parsed_result;
17779 	portid_t proxy_port_id;
17780 	int ret;
17781 
17782 	printf("\n");
17783 
17784 	ret = rte_flow_pick_transfer_proxy(res->port_id, &proxy_port_id, NULL);
17785 	if (ret != 0) {
17786 		fprintf(stderr, "Failed to pick transfer proxy: %s\n",
17787 			rte_strerror(-ret));
17788 		return;
17789 	}
17790 
17791 	printf("Transfer proxy port ID: %u\n\n", proxy_port_id);
17792 }
17793 
17794 cmdline_parse_inst_t cmd_show_port_flow_transfer_proxy = {
17795 	.f = cmd_show_port_flow_transfer_proxy_parsed,
17796 	.data = NULL,
17797 	.help_str = "show port <port_id> flow transfer proxy",
17798 	.tokens = {
17799 		(void *)&cmd_show_port_flow_transfer_proxy_show,
17800 		(void *)&cmd_show_port_flow_transfer_proxy_port,
17801 		(void *)&cmd_show_port_flow_transfer_proxy_port_id,
17802 		(void *)&cmd_show_port_flow_transfer_proxy_flow,
17803 		(void *)&cmd_show_port_flow_transfer_proxy_transfer,
17804 		(void *)&cmd_show_port_flow_transfer_proxy_proxy,
17805 		NULL,
17806 	}
17807 };
17808 
17809 /* ******************************************************************************** */
17810 
17811 /* list of instructions */
17812 cmdline_parse_ctx_t main_ctx[] = {
17813 	(cmdline_parse_inst_t *)&cmd_help_brief,
17814 	(cmdline_parse_inst_t *)&cmd_help_long,
17815 	(cmdline_parse_inst_t *)&cmd_quit,
17816 	(cmdline_parse_inst_t *)&cmd_load_from_file,
17817 	(cmdline_parse_inst_t *)&cmd_showport,
17818 	(cmdline_parse_inst_t *)&cmd_showqueue,
17819 	(cmdline_parse_inst_t *)&cmd_showeeprom,
17820 	(cmdline_parse_inst_t *)&cmd_showportall,
17821 	(cmdline_parse_inst_t *)&cmd_representor_info,
17822 	(cmdline_parse_inst_t *)&cmd_showdevice,
17823 	(cmdline_parse_inst_t *)&cmd_showcfg,
17824 	(cmdline_parse_inst_t *)&cmd_showfwdall,
17825 	(cmdline_parse_inst_t *)&cmd_start,
17826 	(cmdline_parse_inst_t *)&cmd_start_tx_first,
17827 	(cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17828 	(cmdline_parse_inst_t *)&cmd_set_link_up,
17829 	(cmdline_parse_inst_t *)&cmd_set_link_down,
17830 	(cmdline_parse_inst_t *)&cmd_reset,
17831 	(cmdline_parse_inst_t *)&cmd_set_numbers,
17832 	(cmdline_parse_inst_t *)&cmd_set_log,
17833 	(cmdline_parse_inst_t *)&cmd_set_rxoffs,
17834 	(cmdline_parse_inst_t *)&cmd_set_rxpkts,
17835 	(cmdline_parse_inst_t *)&cmd_set_txpkts,
17836 	(cmdline_parse_inst_t *)&cmd_set_txsplit,
17837 	(cmdline_parse_inst_t *)&cmd_set_txtimes,
17838 	(cmdline_parse_inst_t *)&cmd_set_fwd_list,
17839 	(cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17840 	(cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17841 	(cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17842 	(cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17843 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17844 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17845 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17846 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17847 	(cmdline_parse_inst_t *)&cmd_set_flush_rx,
17848 	(cmdline_parse_inst_t *)&cmd_set_link_check,
17849 	(cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17850 	(cmdline_parse_inst_t *)&cmd_set_bypass_event,
17851 	(cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17852 	(cmdline_parse_inst_t *)&cmd_show_bypass_config,
17853 #ifdef RTE_NET_BOND
17854 	(cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17855 	(cmdline_parse_inst_t *) &cmd_show_bonding_config,
17856 	(cmdline_parse_inst_t *) &cmd_show_bonding_lacp_info,
17857 	(cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17858 	(cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17859 	(cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17860 	(cmdline_parse_inst_t *) &cmd_create_bonded_device,
17861 	(cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17862 	(cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17863 	(cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17864 	(cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17865 	(cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17866 #endif
17867 	(cmdline_parse_inst_t *)&cmd_vlan_offload,
17868 	(cmdline_parse_inst_t *)&cmd_vlan_tpid,
17869 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17870 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17871 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17872 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17873 	(cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17874 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17875 	(cmdline_parse_inst_t *)&cmd_csum_set,
17876 	(cmdline_parse_inst_t *)&cmd_csum_show,
17877 	(cmdline_parse_inst_t *)&cmd_csum_tunnel,
17878 	(cmdline_parse_inst_t *)&cmd_tso_set,
17879 	(cmdline_parse_inst_t *)&cmd_tso_show,
17880 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17881 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17882 #ifdef RTE_LIB_GRO
17883 	(cmdline_parse_inst_t *)&cmd_gro_enable,
17884 	(cmdline_parse_inst_t *)&cmd_gro_flush,
17885 	(cmdline_parse_inst_t *)&cmd_gro_show,
17886 #endif
17887 #ifdef RTE_LIB_GSO
17888 	(cmdline_parse_inst_t *)&cmd_gso_enable,
17889 	(cmdline_parse_inst_t *)&cmd_gso_size,
17890 	(cmdline_parse_inst_t *)&cmd_gso_show,
17891 #endif
17892 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17893 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17894 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17895 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17896 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17897 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17898 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17899 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17900 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17901 	(cmdline_parse_inst_t *)&cmd_link_flow_control_show,
17902 	(cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17903 	(cmdline_parse_inst_t *)&cmd_queue_priority_flow_control_set,
17904 	(cmdline_parse_inst_t *)&cmd_config_dcb,
17905 	(cmdline_parse_inst_t *)&cmd_read_reg,
17906 	(cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17907 	(cmdline_parse_inst_t *)&cmd_read_reg_bit,
17908 	(cmdline_parse_inst_t *)&cmd_write_reg,
17909 	(cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17910 	(cmdline_parse_inst_t *)&cmd_write_reg_bit,
17911 	(cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17912 	(cmdline_parse_inst_t *)&cmd_stop,
17913 	(cmdline_parse_inst_t *)&cmd_mac_addr,
17914 	(cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17915 	(cmdline_parse_inst_t *)&cmd_set_qmap,
17916 	(cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17917 	(cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17918 	(cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17919 	(cmdline_parse_inst_t *)&cmd_operate_port,
17920 	(cmdline_parse_inst_t *)&cmd_operate_specific_port,
17921 	(cmdline_parse_inst_t *)&cmd_operate_attach_port,
17922 	(cmdline_parse_inst_t *)&cmd_operate_detach_port,
17923 	(cmdline_parse_inst_t *)&cmd_operate_detach_device,
17924 	(cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17925 	(cmdline_parse_inst_t *)&cmd_config_speed_all,
17926 	(cmdline_parse_inst_t *)&cmd_config_speed_specific,
17927 	(cmdline_parse_inst_t *)&cmd_config_loopback_all,
17928 	(cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17929 	(cmdline_parse_inst_t *)&cmd_config_rx_tx,
17930 	(cmdline_parse_inst_t *)&cmd_config_mtu,
17931 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17932 	(cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17933 	(cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17934 	(cmdline_parse_inst_t *)&cmd_config_rss,
17935 	(cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17936 	(cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17937 	(cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17938 	(cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17939 	(cmdline_parse_inst_t *)&cmd_config_rss_reta,
17940 	(cmdline_parse_inst_t *)&cmd_showport_reta,
17941 	(cmdline_parse_inst_t *)&cmd_showport_macs,
17942 	(cmdline_parse_inst_t *)&cmd_show_port_flow_transfer_proxy,
17943 	(cmdline_parse_inst_t *)&cmd_config_burst,
17944 	(cmdline_parse_inst_t *)&cmd_config_thresh,
17945 	(cmdline_parse_inst_t *)&cmd_config_threshold,
17946 	(cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17947 	(cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17948 	(cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17949 	(cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17950 	(cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17951 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17952 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17953 	(cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17954 	(cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs,
17955 	(cmdline_parse_inst_t *)&cmd_dump,
17956 	(cmdline_parse_inst_t *)&cmd_dump_one,
17957 #ifdef RTE_NET_I40E
17958 	(cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17959 #endif
17960 	(cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17961 	(cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17962 	(cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17963 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17964 	(cmdline_parse_inst_t *)&cmd_flow,
17965 	(cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17966 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17967 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17968 	(cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17969 	(cmdline_parse_inst_t *)&cmd_create_port_meter,
17970 	(cmdline_parse_inst_t *)&cmd_enable_port_meter,
17971 	(cmdline_parse_inst_t *)&cmd_disable_port_meter,
17972 	(cmdline_parse_inst_t *)&cmd_del_port_meter,
17973 	(cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
17974 	(cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17975 	(cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17976 	(cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17977 	(cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17978 	(cmdline_parse_inst_t *)&cmd_mcast_addr,
17979 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17980 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17981 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17982 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17983 	(cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17984 	(cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17985 	(cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17986 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17987 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17988 	(cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17989 	(cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17990 	(cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17991 	(cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17992 	(cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17993 	(cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17994 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17995 	(cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17996 	(cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17997 	(cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17998 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17999 	(cmdline_parse_inst_t *)&cmd_vf_max_bw,
18000 	(cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18001 	(cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18002 	(cmdline_parse_inst_t *)&cmd_strict_link_prio,
18003 	(cmdline_parse_inst_t *)&cmd_tc_min_bw,
18004 	(cmdline_parse_inst_t *)&cmd_set_vxlan,
18005 	(cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18006 	(cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18007 	(cmdline_parse_inst_t *)&cmd_set_nvgre,
18008 	(cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18009 	(cmdline_parse_inst_t *)&cmd_set_l2_encap,
18010 	(cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18011 	(cmdline_parse_inst_t *)&cmd_set_l2_decap,
18012 	(cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18013 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18014 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18015 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18016 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18017 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18018 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18019 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18020 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18021 	(cmdline_parse_inst_t *)&cmd_set_conntrack_common,
18022 	(cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
18023 	(cmdline_parse_inst_t *)&cmd_ddp_add,
18024 	(cmdline_parse_inst_t *)&cmd_ddp_del,
18025 	(cmdline_parse_inst_t *)&cmd_ddp_get_list,
18026 	(cmdline_parse_inst_t *)&cmd_ddp_get_info,
18027 	(cmdline_parse_inst_t *)&cmd_cfg_input_set,
18028 	(cmdline_parse_inst_t *)&cmd_clear_input_set,
18029 	(cmdline_parse_inst_t *)&cmd_show_vf_stats,
18030 	(cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18031 	(cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
18032 	(cmdline_parse_inst_t *)&cmd_set_port_ptypes,
18033 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18034 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18035 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18036 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18037 
18038 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18039 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18040 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18041 	(cmdline_parse_inst_t *)&cmd_queue_region,
18042 	(cmdline_parse_inst_t *)&cmd_region_flowtype,
18043 	(cmdline_parse_inst_t *)&cmd_user_priority_region,
18044 	(cmdline_parse_inst_t *)&cmd_flush_queue_region,
18045 	(cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18046 	(cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18047 	(cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18048 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18049 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18050 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18051 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18052 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18053 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18054 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18055 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18056 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18057 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18058 	(cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18059 	(cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
18060 	(cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18061 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18062 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18063 	(cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18064 	(cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18065 	(cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18066 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18067 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18068 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18069 	(cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18070 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18071 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18072 	(cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18073 	(cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18074 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18075 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18076 	(cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18077 	(cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18078 #ifdef RTE_LIB_BPF
18079 	(cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18080 	(cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18081 #endif
18082 	(cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18083 	(cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18084 	(cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
18085 	(cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
18086 	(cmdline_parse_inst_t *)&cmd_set_raw,
18087 	(cmdline_parse_inst_t *)&cmd_show_set_raw,
18088 	(cmdline_parse_inst_t *)&cmd_show_set_raw_all,
18089 	(cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
18090 	(cmdline_parse_inst_t *)&cmd_show_fec_mode,
18091 	(cmdline_parse_inst_t *)&cmd_set_fec_mode,
18092 	(cmdline_parse_inst_t *)&cmd_show_capability,
18093 	(cmdline_parse_inst_t *)&cmd_set_flex_is_pattern,
18094 	(cmdline_parse_inst_t *)&cmd_set_flex_spec_pattern,
18095 	NULL,
18096 };
18097 
18098 /* read cmdline commands from file */
18099 void
18100 cmdline_read_from_file(const char *filename)
18101 {
18102 	struct cmdline *cl;
18103 
18104 	cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18105 	if (cl == NULL) {
18106 		fprintf(stderr,
18107 			"Failed to create file based cmdline context: %s\n",
18108 			filename);
18109 		return;
18110 	}
18111 
18112 	cmdline_interact(cl);
18113 	cmdline_quit(cl);
18114 
18115 	cmdline_free(cl);
18116 
18117 	printf("Read CLI commands from %s\n", filename);
18118 }
18119 
18120 /* prompt function, called from main on MAIN lcore */
18121 void
18122 prompt(void)
18123 {
18124 	int ret;
18125 	/* initialize non-constant commands */
18126 	cmd_set_fwd_mode_init();
18127 	cmd_set_fwd_retry_mode_init();
18128 
18129 	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18130 	if (testpmd_cl == NULL)
18131 		return;
18132 
18133 	ret = atexit(prompt_exit);
18134 	if (ret != 0)
18135 		fprintf(stderr, "Cannot set exit function for cmdline\n");
18136 
18137 	cmdline_interact(testpmd_cl);
18138 	if (ret != 0)
18139 		cmdline_stdin_exit(testpmd_cl);
18140 }
18141 
18142 void
18143 prompt_exit(void)
18144 {
18145 	if (testpmd_cl != NULL) {
18146 		cmdline_quit(testpmd_cl);
18147 		cmdline_stdin_exit(testpmd_cl);
18148 	}
18149 }
18150 
18151 static void
18152 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18153 {
18154 	if (id == (portid_t)RTE_PORT_ALL) {
18155 		portid_t pid;
18156 
18157 		RTE_ETH_FOREACH_DEV(pid) {
18158 			/* check if need_reconfig has been set to 1 */
18159 			if (ports[pid].need_reconfig == 0)
18160 				ports[pid].need_reconfig = dev;
18161 			/* check if need_reconfig_queues has been set to 1 */
18162 			if (ports[pid].need_reconfig_queues == 0)
18163 				ports[pid].need_reconfig_queues = queue;
18164 		}
18165 	} else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18166 		/* check if need_reconfig has been set to 1 */
18167 		if (ports[id].need_reconfig == 0)
18168 			ports[id].need_reconfig = dev;
18169 		/* check if need_reconfig_queues has been set to 1 */
18170 		if (ports[id].need_reconfig_queues == 0)
18171 			ports[id].need_reconfig_queues = queue;
18172 	}
18173 }
18174