xref: /dpdk/app/test-pmd/cmdline.c (revision 97b914f4e715565d53d38ac6e04815b9be5e58a9)
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 	port_mtu_set(res->port_id, res->value);
2054 }
2055 
2056 cmdline_parse_token_string_t cmd_config_mtu_port =
2057 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2058 				 "port");
2059 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2060 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2061 				 "config");
2062 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2063 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2064 				 "mtu");
2065 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2066 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2067 				 RTE_UINT16);
2068 cmdline_parse_token_num_t cmd_config_mtu_value =
2069 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2070 				 RTE_UINT16);
2071 
2072 cmdline_parse_inst_t cmd_config_mtu = {
2073 	.f = cmd_config_mtu_parsed,
2074 	.data = NULL,
2075 	.help_str = "port config mtu <port_id> <value>",
2076 	.tokens = {
2077 		(void *)&cmd_config_mtu_port,
2078 		(void *)&cmd_config_mtu_keyword,
2079 		(void *)&cmd_config_mtu_mtu,
2080 		(void *)&cmd_config_mtu_port_id,
2081 		(void *)&cmd_config_mtu_value,
2082 		NULL,
2083 	},
2084 };
2085 
2086 /* *** configure rx mode *** */
2087 struct cmd_config_rx_mode_flag {
2088 	cmdline_fixed_string_t port;
2089 	cmdline_fixed_string_t keyword;
2090 	cmdline_fixed_string_t all;
2091 	cmdline_fixed_string_t name;
2092 	cmdline_fixed_string_t value;
2093 };
2094 
2095 static void
2096 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2097 				__rte_unused struct cmdline *cl,
2098 				__rte_unused void *data)
2099 {
2100 	struct cmd_config_rx_mode_flag *res = parsed_result;
2101 
2102 	if (!all_ports_stopped()) {
2103 		fprintf(stderr, "Please stop all ports first\n");
2104 		return;
2105 	}
2106 
2107 	if (!strcmp(res->name, "drop-en")) {
2108 		if (!strcmp(res->value, "on"))
2109 			rx_drop_en = 1;
2110 		else if (!strcmp(res->value, "off"))
2111 			rx_drop_en = 0;
2112 		else {
2113 			fprintf(stderr, "Unknown parameter\n");
2114 			return;
2115 		}
2116 	} else {
2117 		fprintf(stderr, "Unknown parameter\n");
2118 		return;
2119 	}
2120 
2121 	init_port_config();
2122 
2123 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2124 }
2125 
2126 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2127 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2128 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2129 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2130 								"config");
2131 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2132 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2133 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2134 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2135 					"drop-en");
2136 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2137 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2138 							"on#off");
2139 
2140 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2141 	.f = cmd_config_rx_mode_flag_parsed,
2142 	.data = NULL,
2143 	.help_str = "port config all drop-en on|off",
2144 	.tokens = {
2145 		(void *)&cmd_config_rx_mode_flag_port,
2146 		(void *)&cmd_config_rx_mode_flag_keyword,
2147 		(void *)&cmd_config_rx_mode_flag_all,
2148 		(void *)&cmd_config_rx_mode_flag_name,
2149 		(void *)&cmd_config_rx_mode_flag_value,
2150 		NULL,
2151 	},
2152 };
2153 
2154 /* *** configure rss *** */
2155 struct cmd_config_rss {
2156 	cmdline_fixed_string_t port;
2157 	cmdline_fixed_string_t keyword;
2158 	cmdline_fixed_string_t all;
2159 	cmdline_fixed_string_t name;
2160 	cmdline_fixed_string_t value;
2161 };
2162 
2163 static void
2164 cmd_config_rss_parsed(void *parsed_result,
2165 			__rte_unused struct cmdline *cl,
2166 			__rte_unused void *data)
2167 {
2168 	struct cmd_config_rss *res = parsed_result;
2169 	struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2170 	struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2171 	int use_default = 0;
2172 	int all_updated = 1;
2173 	int diag;
2174 	uint16_t i;
2175 	int ret;
2176 
2177 	if (!strcmp(res->value, "all"))
2178 		rss_conf.rss_hf = RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP |
2179 			RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP |
2180 			RTE_ETH_RSS_L2_PAYLOAD | RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP |
2181 			RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP | RTE_ETH_RSS_GTPU |
2182 			RTE_ETH_RSS_ECPRI | RTE_ETH_RSS_L2TPV2;
2183 	else if (!strcmp(res->value, "eth"))
2184 		rss_conf.rss_hf = RTE_ETH_RSS_ETH;
2185 	else if (!strcmp(res->value, "vlan"))
2186 		rss_conf.rss_hf = RTE_ETH_RSS_VLAN;
2187 	else if (!strcmp(res->value, "ip"))
2188 		rss_conf.rss_hf = RTE_ETH_RSS_IP;
2189 	else if (!strcmp(res->value, "udp"))
2190 		rss_conf.rss_hf = RTE_ETH_RSS_UDP;
2191 	else if (!strcmp(res->value, "tcp"))
2192 		rss_conf.rss_hf = RTE_ETH_RSS_TCP;
2193 	else if (!strcmp(res->value, "sctp"))
2194 		rss_conf.rss_hf = RTE_ETH_RSS_SCTP;
2195 	else if (!strcmp(res->value, "ether"))
2196 		rss_conf.rss_hf = RTE_ETH_RSS_L2_PAYLOAD;
2197 	else if (!strcmp(res->value, "port"))
2198 		rss_conf.rss_hf = RTE_ETH_RSS_PORT;
2199 	else if (!strcmp(res->value, "vxlan"))
2200 		rss_conf.rss_hf = RTE_ETH_RSS_VXLAN;
2201 	else if (!strcmp(res->value, "geneve"))
2202 		rss_conf.rss_hf = RTE_ETH_RSS_GENEVE;
2203 	else if (!strcmp(res->value, "nvgre"))
2204 		rss_conf.rss_hf = RTE_ETH_RSS_NVGRE;
2205 	else if (!strcmp(res->value, "l3-pre32"))
2206 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2207 	else if (!strcmp(res->value, "l3-pre40"))
2208 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2209 	else if (!strcmp(res->value, "l3-pre48"))
2210 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2211 	else if (!strcmp(res->value, "l3-pre56"))
2212 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2213 	else if (!strcmp(res->value, "l3-pre64"))
2214 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2215 	else if (!strcmp(res->value, "l3-pre96"))
2216 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2217 	else if (!strcmp(res->value, "l3-src-only"))
2218 		rss_conf.rss_hf = RTE_ETH_RSS_L3_SRC_ONLY;
2219 	else if (!strcmp(res->value, "l3-dst-only"))
2220 		rss_conf.rss_hf = RTE_ETH_RSS_L3_DST_ONLY;
2221 	else if (!strcmp(res->value, "l4-src-only"))
2222 		rss_conf.rss_hf = RTE_ETH_RSS_L4_SRC_ONLY;
2223 	else if (!strcmp(res->value, "l4-dst-only"))
2224 		rss_conf.rss_hf = RTE_ETH_RSS_L4_DST_ONLY;
2225 	else if (!strcmp(res->value, "l2-src-only"))
2226 		rss_conf.rss_hf = RTE_ETH_RSS_L2_SRC_ONLY;
2227 	else if (!strcmp(res->value, "l2-dst-only"))
2228 		rss_conf.rss_hf = RTE_ETH_RSS_L2_DST_ONLY;
2229 	else if (!strcmp(res->value, "l2tpv3"))
2230 		rss_conf.rss_hf = RTE_ETH_RSS_L2TPV3;
2231 	else if (!strcmp(res->value, "esp"))
2232 		rss_conf.rss_hf = RTE_ETH_RSS_ESP;
2233 	else if (!strcmp(res->value, "ah"))
2234 		rss_conf.rss_hf = RTE_ETH_RSS_AH;
2235 	else if (!strcmp(res->value, "pfcp"))
2236 		rss_conf.rss_hf = RTE_ETH_RSS_PFCP;
2237 	else if (!strcmp(res->value, "pppoe"))
2238 		rss_conf.rss_hf = RTE_ETH_RSS_PPPOE;
2239 	else if (!strcmp(res->value, "gtpu"))
2240 		rss_conf.rss_hf = RTE_ETH_RSS_GTPU;
2241 	else if (!strcmp(res->value, "ecpri"))
2242 		rss_conf.rss_hf = RTE_ETH_RSS_ECPRI;
2243 	else if (!strcmp(res->value, "mpls"))
2244 		rss_conf.rss_hf = RTE_ETH_RSS_MPLS;
2245 	else if (!strcmp(res->value, "ipv4-chksum"))
2246 		rss_conf.rss_hf = RTE_ETH_RSS_IPV4_CHKSUM;
2247 	else if (!strcmp(res->value, "l2tpv2"))
2248 		rss_conf.rss_hf = RTE_ETH_RSS_L2TPV2;
2249 	else if (!strcmp(res->value, "none"))
2250 		rss_conf.rss_hf = 0;
2251 	else if (!strcmp(res->value, "level-default")) {
2252 		rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2253 		rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_PMD_DEFAULT);
2254 	} else if (!strcmp(res->value, "level-outer")) {
2255 		rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2256 		rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_OUTERMOST);
2257 	} else if (!strcmp(res->value, "level-inner")) {
2258 		rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2259 		rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_INNERMOST);
2260 	} else if (!strcmp(res->value, "default"))
2261 		use_default = 1;
2262 	else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2263 						atoi(res->value) < 64)
2264 		rss_conf.rss_hf = 1ULL << atoi(res->value);
2265 	else {
2266 		fprintf(stderr, "Unknown parameter\n");
2267 		return;
2268 	}
2269 	rss_conf.rss_key = NULL;
2270 	/* Update global configuration for RSS types. */
2271 	RTE_ETH_FOREACH_DEV(i) {
2272 		struct rte_eth_rss_conf local_rss_conf;
2273 
2274 		ret = eth_dev_info_get_print_err(i, &dev_info);
2275 		if (ret != 0)
2276 			return;
2277 
2278 		if (use_default)
2279 			rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2280 
2281 		local_rss_conf = rss_conf;
2282 		local_rss_conf.rss_hf = rss_conf.rss_hf &
2283 			dev_info.flow_type_rss_offloads;
2284 		if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2285 			printf("Port %u modified RSS hash function based on hardware support,"
2286 				"requested:%#"PRIx64" configured:%#"PRIx64"\n",
2287 				i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2288 		}
2289 		diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2290 		if (diag < 0) {
2291 			all_updated = 0;
2292 			fprintf(stderr,
2293 				"Configuration of RSS hash at ethernet port %d failed with error (%d): %s.\n",
2294 				i, -diag, strerror(-diag));
2295 		}
2296 	}
2297 	if (all_updated && !use_default) {
2298 		rss_hf = rss_conf.rss_hf;
2299 		printf("rss_hf %#"PRIx64"\n", rss_hf);
2300 	}
2301 }
2302 
2303 cmdline_parse_token_string_t cmd_config_rss_port =
2304 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2305 cmdline_parse_token_string_t cmd_config_rss_keyword =
2306 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2307 cmdline_parse_token_string_t cmd_config_rss_all =
2308 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2309 cmdline_parse_token_string_t cmd_config_rss_name =
2310 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2311 cmdline_parse_token_string_t cmd_config_rss_value =
2312 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2313 
2314 cmdline_parse_inst_t cmd_config_rss = {
2315 	.f = cmd_config_rss_parsed,
2316 	.data = NULL,
2317 	.help_str = "port config all rss "
2318 		"all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2319 		"nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|ipv4-chksum|l2tpv2|"
2320 		"none|level-default|level-outer|level-inner|<flowtype_id>",
2321 	.tokens = {
2322 		(void *)&cmd_config_rss_port,
2323 		(void *)&cmd_config_rss_keyword,
2324 		(void *)&cmd_config_rss_all,
2325 		(void *)&cmd_config_rss_name,
2326 		(void *)&cmd_config_rss_value,
2327 		NULL,
2328 	},
2329 };
2330 
2331 /* *** configure rss hash key *** */
2332 struct cmd_config_rss_hash_key {
2333 	cmdline_fixed_string_t port;
2334 	cmdline_fixed_string_t config;
2335 	portid_t port_id;
2336 	cmdline_fixed_string_t rss_hash_key;
2337 	cmdline_fixed_string_t rss_type;
2338 	cmdline_fixed_string_t key;
2339 };
2340 
2341 static uint8_t
2342 hexa_digit_to_value(char hexa_digit)
2343 {
2344 	if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2345 		return (uint8_t) (hexa_digit - '0');
2346 	if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2347 		return (uint8_t) ((hexa_digit - 'a') + 10);
2348 	if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2349 		return (uint8_t) ((hexa_digit - 'A') + 10);
2350 	/* Invalid hexa digit */
2351 	return 0xFF;
2352 }
2353 
2354 static uint8_t
2355 parse_and_check_key_hexa_digit(char *key, int idx)
2356 {
2357 	uint8_t hexa_v;
2358 
2359 	hexa_v = hexa_digit_to_value(key[idx]);
2360 	if (hexa_v == 0xFF)
2361 		fprintf(stderr,
2362 			"invalid key: character %c at position %d is not a valid hexa digit\n",
2363 			key[idx], idx);
2364 	return hexa_v;
2365 }
2366 
2367 static void
2368 cmd_config_rss_hash_key_parsed(void *parsed_result,
2369 			       __rte_unused struct cmdline *cl,
2370 			       __rte_unused void *data)
2371 {
2372 	struct cmd_config_rss_hash_key *res = parsed_result;
2373 	uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2374 	uint8_t xdgt0;
2375 	uint8_t xdgt1;
2376 	int i;
2377 	struct rte_eth_dev_info dev_info;
2378 	uint8_t hash_key_size;
2379 	uint32_t key_len;
2380 	int ret;
2381 
2382 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2383 	if (ret != 0)
2384 		return;
2385 
2386 	if (dev_info.hash_key_size > 0 &&
2387 			dev_info.hash_key_size <= sizeof(hash_key))
2388 		hash_key_size = dev_info.hash_key_size;
2389 	else {
2390 		fprintf(stderr,
2391 			"dev_info did not provide a valid hash key size\n");
2392 		return;
2393 	}
2394 	/* Check the length of the RSS hash key */
2395 	key_len = strlen(res->key);
2396 	if (key_len != (hash_key_size * 2)) {
2397 		fprintf(stderr,
2398 			"key length: %d invalid - key must be a string of %d hexa-decimal numbers\n",
2399 			(int)key_len, hash_key_size * 2);
2400 		return;
2401 	}
2402 	/* Translate RSS hash key into binary representation */
2403 	for (i = 0; i < hash_key_size; i++) {
2404 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2405 		if (xdgt0 == 0xFF)
2406 			return;
2407 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2408 		if (xdgt1 == 0xFF)
2409 			return;
2410 		hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2411 	}
2412 	port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2413 			hash_key_size);
2414 }
2415 
2416 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2417 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2418 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2419 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2420 				 "config");
2421 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2422 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2423 				 RTE_UINT16);
2424 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2425 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2426 				 rss_hash_key, "rss-hash-key");
2427 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2428 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2429 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2430 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2431 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2432 				 "ipv6-tcp-ex#ipv6-udp-ex#"
2433 				 "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2434 				 "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2435 				 "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls#l2tpv2");
2436 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2437 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2438 
2439 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2440 	.f = cmd_config_rss_hash_key_parsed,
2441 	.data = NULL,
2442 	.help_str = "port config <port_id> rss-hash-key "
2443 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2444 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2445 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2446 		"l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2447 		"l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2448 		"l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls|l2tpv2 "
2449 		"<string of hex digits (variable length, NIC dependent)>",
2450 	.tokens = {
2451 		(void *)&cmd_config_rss_hash_key_port,
2452 		(void *)&cmd_config_rss_hash_key_config,
2453 		(void *)&cmd_config_rss_hash_key_port_id,
2454 		(void *)&cmd_config_rss_hash_key_rss_hash_key,
2455 		(void *)&cmd_config_rss_hash_key_rss_type,
2456 		(void *)&cmd_config_rss_hash_key_value,
2457 		NULL,
2458 	},
2459 };
2460 
2461 /* *** cleanup txq mbufs *** */
2462 struct cmd_cleanup_txq_mbufs_result {
2463 	cmdline_fixed_string_t port;
2464 	cmdline_fixed_string_t keyword;
2465 	cmdline_fixed_string_t name;
2466 	uint16_t port_id;
2467 	uint16_t queue_id;
2468 	uint32_t free_cnt;
2469 };
2470 
2471 static void
2472 cmd_cleanup_txq_mbufs_parsed(void *parsed_result,
2473 			     __rte_unused struct cmdline *cl,
2474 			     __rte_unused void *data)
2475 {
2476 	struct cmd_cleanup_txq_mbufs_result *res = parsed_result;
2477 	uint16_t port_id = res->port_id;
2478 	uint16_t queue_id = res->queue_id;
2479 	uint32_t free_cnt = res->free_cnt;
2480 	struct rte_eth_txq_info qinfo;
2481 	int ret;
2482 
2483 	if (test_done == 0) {
2484 		fprintf(stderr, "Please stop forwarding first\n");
2485 		return;
2486 	}
2487 
2488 	if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) {
2489 		fprintf(stderr, "Failed to get port %u Tx queue %u info\n",
2490 			port_id, queue_id);
2491 		return;
2492 	}
2493 
2494 	if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
2495 		fprintf(stderr, "Tx queue %u not started\n", queue_id);
2496 		return;
2497 	}
2498 
2499 	ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt);
2500 	if (ret < 0) {
2501 		fprintf(stderr,
2502 			"Failed to cleanup mbuf for port %u Tx queue %u error desc: %s(%d)\n",
2503 			port_id, queue_id, strerror(-ret), ret);
2504 		return;
2505 	}
2506 
2507 	printf("Cleanup port %u Tx queue %u mbuf nums: %u\n",
2508 	       port_id, queue_id, ret);
2509 }
2510 
2511 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port =
2512 	TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port,
2513 				 "port");
2514 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup =
2515 	TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword,
2516 				 "cleanup");
2517 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id =
2518 	TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id,
2519 			      RTE_UINT16);
2520 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq =
2521 	TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name,
2522 				 "txq");
2523 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id =
2524 	TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id,
2525 			      RTE_UINT16);
2526 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt =
2527 	TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt,
2528 			      RTE_UINT32);
2529 
2530 cmdline_parse_inst_t cmd_cleanup_txq_mbufs = {
2531 	.f = cmd_cleanup_txq_mbufs_parsed,
2532 	.data = NULL,
2533 	.help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>",
2534 	.tokens = {
2535 		(void *)&cmd_cleanup_txq_mbufs_port,
2536 		(void *)&cmd_cleanup_txq_mbufs_cleanup,
2537 		(void *)&cmd_cleanup_txq_mbufs_port_id,
2538 		(void *)&cmd_cleanup_txq_mbufs_txq,
2539 		(void *)&cmd_cleanup_txq_mbufs_queue_id,
2540 		(void *)&cmd_cleanup_txq_mbufs_free_cnt,
2541 		NULL,
2542 	},
2543 };
2544 
2545 /* *** configure port rxq/txq ring size *** */
2546 struct cmd_config_rxtx_ring_size {
2547 	cmdline_fixed_string_t port;
2548 	cmdline_fixed_string_t config;
2549 	portid_t portid;
2550 	cmdline_fixed_string_t rxtxq;
2551 	uint16_t qid;
2552 	cmdline_fixed_string_t rsize;
2553 	uint16_t size;
2554 };
2555 
2556 static void
2557 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2558 				 __rte_unused struct cmdline *cl,
2559 				 __rte_unused void *data)
2560 {
2561 	struct cmd_config_rxtx_ring_size *res = parsed_result;
2562 	struct rte_port *port;
2563 	uint8_t isrx;
2564 
2565 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2566 		return;
2567 
2568 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2569 		fprintf(stderr, "Invalid port id\n");
2570 		return;
2571 	}
2572 
2573 	port = &ports[res->portid];
2574 
2575 	if (!strcmp(res->rxtxq, "rxq"))
2576 		isrx = 1;
2577 	else if (!strcmp(res->rxtxq, "txq"))
2578 		isrx = 0;
2579 	else {
2580 		fprintf(stderr, "Unknown parameter\n");
2581 		return;
2582 	}
2583 
2584 	if (isrx && rx_queue_id_is_invalid(res->qid))
2585 		return;
2586 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2587 		return;
2588 
2589 	if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2590 		fprintf(stderr,
2591 			"Invalid rx ring_size, must > rx_free_thresh: %d\n",
2592 			rx_free_thresh);
2593 		return;
2594 	}
2595 
2596 	if (isrx)
2597 		port->nb_rx_desc[res->qid] = res->size;
2598 	else
2599 		port->nb_tx_desc[res->qid] = res->size;
2600 
2601 	cmd_reconfig_device_queue(res->portid, 0, 1);
2602 }
2603 
2604 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2605 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2606 				 port, "port");
2607 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2608 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2609 				 config, "config");
2610 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2611 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2612 				 portid, RTE_UINT16);
2613 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2614 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2615 				 rxtxq, "rxq#txq");
2616 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2617 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2618 			      qid, RTE_UINT16);
2619 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2620 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2621 				 rsize, "ring_size");
2622 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2623 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2624 			      size, RTE_UINT16);
2625 
2626 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2627 	.f = cmd_config_rxtx_ring_size_parsed,
2628 	.data = NULL,
2629 	.help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2630 	.tokens = {
2631 		(void *)&cmd_config_rxtx_ring_size_port,
2632 		(void *)&cmd_config_rxtx_ring_size_config,
2633 		(void *)&cmd_config_rxtx_ring_size_portid,
2634 		(void *)&cmd_config_rxtx_ring_size_rxtxq,
2635 		(void *)&cmd_config_rxtx_ring_size_qid,
2636 		(void *)&cmd_config_rxtx_ring_size_rsize,
2637 		(void *)&cmd_config_rxtx_ring_size_size,
2638 		NULL,
2639 	},
2640 };
2641 
2642 /* *** configure port rxq/txq start/stop *** */
2643 struct cmd_config_rxtx_queue {
2644 	cmdline_fixed_string_t port;
2645 	portid_t portid;
2646 	cmdline_fixed_string_t rxtxq;
2647 	uint16_t qid;
2648 	cmdline_fixed_string_t opname;
2649 };
2650 
2651 static void
2652 cmd_config_rxtx_queue_parsed(void *parsed_result,
2653 			__rte_unused struct cmdline *cl,
2654 			__rte_unused void *data)
2655 {
2656 	struct cmd_config_rxtx_queue *res = parsed_result;
2657 	uint8_t isrx;
2658 	uint8_t isstart;
2659 	int ret = 0;
2660 
2661 	if (test_done == 0) {
2662 		fprintf(stderr, "Please stop forwarding first\n");
2663 		return;
2664 	}
2665 
2666 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2667 		return;
2668 
2669 	if (port_is_started(res->portid) != 1) {
2670 		fprintf(stderr, "Please start port %u first\n", res->portid);
2671 		return;
2672 	}
2673 
2674 	if (!strcmp(res->rxtxq, "rxq"))
2675 		isrx = 1;
2676 	else if (!strcmp(res->rxtxq, "txq"))
2677 		isrx = 0;
2678 	else {
2679 		fprintf(stderr, "Unknown parameter\n");
2680 		return;
2681 	}
2682 
2683 	if (isrx && rx_queue_id_is_invalid(res->qid))
2684 		return;
2685 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2686 		return;
2687 
2688 	if (!strcmp(res->opname, "start"))
2689 		isstart = 1;
2690 	else if (!strcmp(res->opname, "stop"))
2691 		isstart = 0;
2692 	else {
2693 		fprintf(stderr, "Unknown parameter\n");
2694 		return;
2695 	}
2696 
2697 	if (isstart && isrx)
2698 		ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2699 	else if (!isstart && isrx)
2700 		ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2701 	else if (isstart && !isrx)
2702 		ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2703 	else
2704 		ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2705 
2706 	if (ret == -ENOTSUP)
2707 		fprintf(stderr, "Function not supported in PMD\n");
2708 }
2709 
2710 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2711 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2712 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2713 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2714 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2715 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2716 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2717 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2718 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2719 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2720 						"start#stop");
2721 
2722 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2723 	.f = cmd_config_rxtx_queue_parsed,
2724 	.data = NULL,
2725 	.help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2726 	.tokens = {
2727 		(void *)&cmd_config_rxtx_queue_port,
2728 		(void *)&cmd_config_rxtx_queue_portid,
2729 		(void *)&cmd_config_rxtx_queue_rxtxq,
2730 		(void *)&cmd_config_rxtx_queue_qid,
2731 		(void *)&cmd_config_rxtx_queue_opname,
2732 		NULL,
2733 	},
2734 };
2735 
2736 /* *** configure port rxq/txq deferred start on/off *** */
2737 struct cmd_config_deferred_start_rxtx_queue {
2738 	cmdline_fixed_string_t port;
2739 	portid_t port_id;
2740 	cmdline_fixed_string_t rxtxq;
2741 	uint16_t qid;
2742 	cmdline_fixed_string_t opname;
2743 	cmdline_fixed_string_t state;
2744 };
2745 
2746 static void
2747 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2748 			__rte_unused struct cmdline *cl,
2749 			__rte_unused void *data)
2750 {
2751 	struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2752 	struct rte_port *port;
2753 	uint8_t isrx;
2754 	uint8_t ison;
2755 	uint8_t needreconfig = 0;
2756 
2757 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2758 		return;
2759 
2760 	if (port_is_started(res->port_id) != 0) {
2761 		fprintf(stderr, "Please stop port %u first\n", res->port_id);
2762 		return;
2763 	}
2764 
2765 	port = &ports[res->port_id];
2766 
2767 	isrx = !strcmp(res->rxtxq, "rxq");
2768 
2769 	if (isrx && rx_queue_id_is_invalid(res->qid))
2770 		return;
2771 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2772 		return;
2773 
2774 	ison = !strcmp(res->state, "on");
2775 
2776 	if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2777 		port->rx_conf[res->qid].rx_deferred_start = ison;
2778 		needreconfig = 1;
2779 	} else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2780 		port->tx_conf[res->qid].tx_deferred_start = ison;
2781 		needreconfig = 1;
2782 	}
2783 
2784 	if (needreconfig)
2785 		cmd_reconfig_device_queue(res->port_id, 0, 1);
2786 }
2787 
2788 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2789 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2790 						port, "port");
2791 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2792 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2793 						port_id, RTE_UINT16);
2794 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2795 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2796 						rxtxq, "rxq#txq");
2797 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2798 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2799 						qid, RTE_UINT16);
2800 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2801 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2802 						opname, "deferred_start");
2803 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2804 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2805 						state, "on#off");
2806 
2807 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2808 	.f = cmd_config_deferred_start_rxtx_queue_parsed,
2809 	.data = NULL,
2810 	.help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2811 	.tokens = {
2812 		(void *)&cmd_config_deferred_start_rxtx_queue_port,
2813 		(void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2814 		(void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2815 		(void *)&cmd_config_deferred_start_rxtx_queue_qid,
2816 		(void *)&cmd_config_deferred_start_rxtx_queue_opname,
2817 		(void *)&cmd_config_deferred_start_rxtx_queue_state,
2818 		NULL,
2819 	},
2820 };
2821 
2822 /* *** configure port rxq/txq setup *** */
2823 struct cmd_setup_rxtx_queue {
2824 	cmdline_fixed_string_t port;
2825 	portid_t portid;
2826 	cmdline_fixed_string_t rxtxq;
2827 	uint16_t qid;
2828 	cmdline_fixed_string_t setup;
2829 };
2830 
2831 /* Common CLI fields for queue setup */
2832 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2833 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2834 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2835 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2836 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2837 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2838 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2839 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2840 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2841 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2842 
2843 static void
2844 cmd_setup_rxtx_queue_parsed(
2845 	void *parsed_result,
2846 	__rte_unused struct cmdline *cl,
2847 	__rte_unused void *data)
2848 {
2849 	struct cmd_setup_rxtx_queue *res = parsed_result;
2850 	struct rte_port *port;
2851 	struct rte_mempool *mp;
2852 	unsigned int socket_id;
2853 	uint8_t isrx = 0;
2854 	int ret;
2855 
2856 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2857 		return;
2858 
2859 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2860 		fprintf(stderr, "Invalid port id\n");
2861 		return;
2862 	}
2863 
2864 	if (!strcmp(res->rxtxq, "rxq"))
2865 		isrx = 1;
2866 	else if (!strcmp(res->rxtxq, "txq"))
2867 		isrx = 0;
2868 	else {
2869 		fprintf(stderr, "Unknown parameter\n");
2870 		return;
2871 	}
2872 
2873 	if (isrx && rx_queue_id_is_invalid(res->qid)) {
2874 		fprintf(stderr, "Invalid rx queue\n");
2875 		return;
2876 	} else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2877 		fprintf(stderr, "Invalid tx queue\n");
2878 		return;
2879 	}
2880 
2881 	port = &ports[res->portid];
2882 	if (isrx) {
2883 		socket_id = rxring_numa[res->portid];
2884 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2885 			socket_id = port->socket_id;
2886 
2887 		mp = mbuf_pool_find(socket_id, 0);
2888 		if (mp == NULL) {
2889 			fprintf(stderr,
2890 				"Failed to setup RX queue: No mempool allocation on the socket %d\n",
2891 				rxring_numa[res->portid]);
2892 			return;
2893 		}
2894 		ret = rx_queue_setup(res->portid,
2895 				     res->qid,
2896 				     port->nb_rx_desc[res->qid],
2897 				     socket_id,
2898 				     &port->rx_conf[res->qid],
2899 				     mp);
2900 		if (ret)
2901 			fprintf(stderr, "Failed to setup RX queue\n");
2902 	} else {
2903 		socket_id = txring_numa[res->portid];
2904 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2905 			socket_id = port->socket_id;
2906 
2907 		if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
2908 			fprintf(stderr,
2909 				"Failed to setup TX queue: not enough descriptors\n");
2910 			return;
2911 		}
2912 		ret = rte_eth_tx_queue_setup(res->portid,
2913 					     res->qid,
2914 					     port->nb_tx_desc[res->qid],
2915 					     socket_id,
2916 					     &port->tx_conf[res->qid]);
2917 		if (ret)
2918 			fprintf(stderr, "Failed to setup TX queue\n");
2919 	}
2920 }
2921 
2922 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2923 	.f = cmd_setup_rxtx_queue_parsed,
2924 	.data = NULL,
2925 	.help_str = "port <port_id> rxq|txq <queue_idx> setup",
2926 	.tokens = {
2927 		(void *)&cmd_setup_rxtx_queue_port,
2928 		(void *)&cmd_setup_rxtx_queue_portid,
2929 		(void *)&cmd_setup_rxtx_queue_rxtxq,
2930 		(void *)&cmd_setup_rxtx_queue_qid,
2931 		(void *)&cmd_setup_rxtx_queue_setup,
2932 		NULL,
2933 	},
2934 };
2935 
2936 
2937 /* *** Configure RSS RETA *** */
2938 struct cmd_config_rss_reta {
2939 	cmdline_fixed_string_t port;
2940 	cmdline_fixed_string_t keyword;
2941 	portid_t port_id;
2942 	cmdline_fixed_string_t name;
2943 	cmdline_fixed_string_t list_name;
2944 	cmdline_fixed_string_t list_of_items;
2945 };
2946 
2947 static int
2948 parse_reta_config(const char *str,
2949 		  struct rte_eth_rss_reta_entry64 *reta_conf,
2950 		  uint16_t nb_entries)
2951 {
2952 	int i;
2953 	unsigned size;
2954 	uint16_t hash_index, idx, shift;
2955 	uint16_t nb_queue;
2956 	char s[256];
2957 	const char *p, *p0 = str;
2958 	char *end;
2959 	enum fieldnames {
2960 		FLD_HASH_INDEX = 0,
2961 		FLD_QUEUE,
2962 		_NUM_FLD
2963 	};
2964 	unsigned long int_fld[_NUM_FLD];
2965 	char *str_fld[_NUM_FLD];
2966 
2967 	while ((p = strchr(p0,'(')) != NULL) {
2968 		++p;
2969 		if((p0 = strchr(p,')')) == NULL)
2970 			return -1;
2971 
2972 		size = p0 - p;
2973 		if(size >= sizeof(s))
2974 			return -1;
2975 
2976 		snprintf(s, sizeof(s), "%.*s", size, p);
2977 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2978 			return -1;
2979 		for (i = 0; i < _NUM_FLD; i++) {
2980 			errno = 0;
2981 			int_fld[i] = strtoul(str_fld[i], &end, 0);
2982 			if (errno != 0 || end == str_fld[i] ||
2983 					int_fld[i] > 65535)
2984 				return -1;
2985 		}
2986 
2987 		hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2988 		nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2989 
2990 		if (hash_index >= nb_entries) {
2991 			fprintf(stderr, "Invalid RETA hash index=%d\n",
2992 				hash_index);
2993 			return -1;
2994 		}
2995 
2996 		idx = hash_index / RTE_ETH_RETA_GROUP_SIZE;
2997 		shift = hash_index % RTE_ETH_RETA_GROUP_SIZE;
2998 		reta_conf[idx].mask |= (1ULL << shift);
2999 		reta_conf[idx].reta[shift] = nb_queue;
3000 	}
3001 
3002 	return 0;
3003 }
3004 
3005 static void
3006 cmd_set_rss_reta_parsed(void *parsed_result,
3007 			__rte_unused struct cmdline *cl,
3008 			__rte_unused void *data)
3009 {
3010 	int ret;
3011 	struct rte_eth_dev_info dev_info;
3012 	struct rte_eth_rss_reta_entry64 reta_conf[8];
3013 	struct cmd_config_rss_reta *res = parsed_result;
3014 
3015 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3016 	if (ret != 0)
3017 		return;
3018 
3019 	if (dev_info.reta_size == 0) {
3020 		fprintf(stderr,
3021 			"Redirection table size is 0 which is invalid for RSS\n");
3022 		return;
3023 	} else
3024 		printf("The reta size of port %d is %u\n",
3025 			res->port_id, dev_info.reta_size);
3026 	if (dev_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
3027 		fprintf(stderr,
3028 			"Currently do not support more than %u entries of redirection table\n",
3029 			RTE_ETH_RSS_RETA_SIZE_512);
3030 		return;
3031 	}
3032 
3033 	memset(reta_conf, 0, sizeof(reta_conf));
3034 	if (!strcmp(res->list_name, "reta")) {
3035 		if (parse_reta_config(res->list_of_items, reta_conf,
3036 						dev_info.reta_size)) {
3037 			fprintf(stderr,
3038 				"Invalid RSS Redirection Table config entered\n");
3039 			return;
3040 		}
3041 		ret = rte_eth_dev_rss_reta_update(res->port_id,
3042 				reta_conf, dev_info.reta_size);
3043 		if (ret != 0)
3044 			fprintf(stderr,
3045 				"Bad redirection table parameter, return code = %d\n",
3046 				ret);
3047 	}
3048 }
3049 
3050 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3051 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3052 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3053 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3054 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3055 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
3056 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3057 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3058 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3059 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3060 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3061         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3062                                  NULL);
3063 cmdline_parse_inst_t cmd_config_rss_reta = {
3064 	.f = cmd_set_rss_reta_parsed,
3065 	.data = NULL,
3066 	.help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3067 	.tokens = {
3068 		(void *)&cmd_config_rss_reta_port,
3069 		(void *)&cmd_config_rss_reta_keyword,
3070 		(void *)&cmd_config_rss_reta_port_id,
3071 		(void *)&cmd_config_rss_reta_name,
3072 		(void *)&cmd_config_rss_reta_list_name,
3073 		(void *)&cmd_config_rss_reta_list_of_items,
3074 		NULL,
3075 	},
3076 };
3077 
3078 /* *** SHOW PORT RETA INFO *** */
3079 struct cmd_showport_reta {
3080 	cmdline_fixed_string_t show;
3081 	cmdline_fixed_string_t port;
3082 	portid_t port_id;
3083 	cmdline_fixed_string_t rss;
3084 	cmdline_fixed_string_t reta;
3085 	uint16_t size;
3086 	cmdline_fixed_string_t list_of_items;
3087 };
3088 
3089 static int
3090 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3091 			   uint16_t nb_entries,
3092 			   char *str)
3093 {
3094 	uint32_t size;
3095 	const char *p, *p0 = str;
3096 	char s[256];
3097 	char *end;
3098 	char *str_fld[8];
3099 	uint16_t i;
3100 	uint16_t num = (nb_entries + RTE_ETH_RETA_GROUP_SIZE - 1) /
3101 			RTE_ETH_RETA_GROUP_SIZE;
3102 	int ret;
3103 
3104 	p = strchr(p0, '(');
3105 	if (p == NULL)
3106 		return -1;
3107 	p++;
3108 	p0 = strchr(p, ')');
3109 	if (p0 == NULL)
3110 		return -1;
3111 	size = p0 - p;
3112 	if (size >= sizeof(s)) {
3113 		fprintf(stderr,
3114 			"The string size exceeds the internal buffer size\n");
3115 		return -1;
3116 	}
3117 	snprintf(s, sizeof(s), "%.*s", size, p);
3118 	ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3119 	if (ret <= 0 || ret != num) {
3120 		fprintf(stderr,
3121 			"The bits of masks do not match the number of reta entries: %u\n",
3122 			num);
3123 		return -1;
3124 	}
3125 	for (i = 0; i < ret; i++)
3126 		conf[i].mask = (uint64_t)strtoull(str_fld[i], &end, 0);
3127 
3128 	return 0;
3129 }
3130 
3131 static void
3132 cmd_showport_reta_parsed(void *parsed_result,
3133 			 __rte_unused struct cmdline *cl,
3134 			 __rte_unused void *data)
3135 {
3136 	struct cmd_showport_reta *res = parsed_result;
3137 	struct rte_eth_rss_reta_entry64 reta_conf[8];
3138 	struct rte_eth_dev_info dev_info;
3139 	uint16_t max_reta_size;
3140 	int ret;
3141 
3142 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3143 	if (ret != 0)
3144 		return;
3145 
3146 	max_reta_size = RTE_MIN(dev_info.reta_size, RTE_ETH_RSS_RETA_SIZE_512);
3147 	if (res->size == 0 || res->size > max_reta_size) {
3148 		fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n",
3149 			res->size, max_reta_size);
3150 		return;
3151 	}
3152 
3153 	memset(reta_conf, 0, sizeof(reta_conf));
3154 	if (showport_parse_reta_config(reta_conf, res->size,
3155 				res->list_of_items) < 0) {
3156 		fprintf(stderr, "Invalid string: %s for reta masks\n",
3157 			res->list_of_items);
3158 		return;
3159 	}
3160 	port_rss_reta_info(res->port_id, reta_conf, res->size);
3161 }
3162 
3163 cmdline_parse_token_string_t cmd_showport_reta_show =
3164 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3165 cmdline_parse_token_string_t cmd_showport_reta_port =
3166 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3167 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3168 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3169 cmdline_parse_token_string_t cmd_showport_reta_rss =
3170 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3171 cmdline_parse_token_string_t cmd_showport_reta_reta =
3172 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3173 cmdline_parse_token_num_t cmd_showport_reta_size =
3174 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3175 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3176 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3177 					list_of_items, NULL);
3178 
3179 cmdline_parse_inst_t cmd_showport_reta = {
3180 	.f = cmd_showport_reta_parsed,
3181 	.data = NULL,
3182 	.help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3183 	.tokens = {
3184 		(void *)&cmd_showport_reta_show,
3185 		(void *)&cmd_showport_reta_port,
3186 		(void *)&cmd_showport_reta_port_id,
3187 		(void *)&cmd_showport_reta_rss,
3188 		(void *)&cmd_showport_reta_reta,
3189 		(void *)&cmd_showport_reta_size,
3190 		(void *)&cmd_showport_reta_list_of_items,
3191 		NULL,
3192 	},
3193 };
3194 
3195 /* *** Show RSS hash configuration *** */
3196 struct cmd_showport_rss_hash {
3197 	cmdline_fixed_string_t show;
3198 	cmdline_fixed_string_t port;
3199 	portid_t port_id;
3200 	cmdline_fixed_string_t rss_hash;
3201 	cmdline_fixed_string_t rss_type;
3202 	cmdline_fixed_string_t key; /* optional argument */
3203 };
3204 
3205 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3206 				__rte_unused struct cmdline *cl,
3207 				void *show_rss_key)
3208 {
3209 	struct cmd_showport_rss_hash *res = parsed_result;
3210 
3211 	port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3212 }
3213 
3214 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3215 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3216 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3217 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3218 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3219 	TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3220 				 RTE_UINT16);
3221 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3222 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3223 				 "rss-hash");
3224 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3225 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3226 
3227 cmdline_parse_inst_t cmd_showport_rss_hash = {
3228 	.f = cmd_showport_rss_hash_parsed,
3229 	.data = NULL,
3230 	.help_str = "show port <port_id> rss-hash",
3231 	.tokens = {
3232 		(void *)&cmd_showport_rss_hash_show,
3233 		(void *)&cmd_showport_rss_hash_port,
3234 		(void *)&cmd_showport_rss_hash_port_id,
3235 		(void *)&cmd_showport_rss_hash_rss_hash,
3236 		NULL,
3237 	},
3238 };
3239 
3240 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3241 	.f = cmd_showport_rss_hash_parsed,
3242 	.data = (void *)1,
3243 	.help_str = "show port <port_id> rss-hash key",
3244 	.tokens = {
3245 		(void *)&cmd_showport_rss_hash_show,
3246 		(void *)&cmd_showport_rss_hash_port,
3247 		(void *)&cmd_showport_rss_hash_port_id,
3248 		(void *)&cmd_showport_rss_hash_rss_hash,
3249 		(void *)&cmd_showport_rss_hash_rss_key,
3250 		NULL,
3251 	},
3252 };
3253 
3254 /* *** Configure DCB *** */
3255 struct cmd_config_dcb {
3256 	cmdline_fixed_string_t port;
3257 	cmdline_fixed_string_t config;
3258 	portid_t port_id;
3259 	cmdline_fixed_string_t dcb;
3260 	cmdline_fixed_string_t vt;
3261 	cmdline_fixed_string_t vt_en;
3262 	uint8_t num_tcs;
3263 	cmdline_fixed_string_t pfc;
3264 	cmdline_fixed_string_t pfc_en;
3265 };
3266 
3267 static void
3268 cmd_config_dcb_parsed(void *parsed_result,
3269                         __rte_unused struct cmdline *cl,
3270                         __rte_unused void *data)
3271 {
3272 	struct cmd_config_dcb *res = parsed_result;
3273 	struct rte_eth_dcb_info dcb_info;
3274 	portid_t port_id = res->port_id;
3275 	struct rte_port *port;
3276 	uint8_t pfc_en;
3277 	int ret;
3278 
3279 	port = &ports[port_id];
3280 	/** Check if the port is not started **/
3281 	if (port->port_status != RTE_PORT_STOPPED) {
3282 		fprintf(stderr, "Please stop port %d first\n", port_id);
3283 		return;
3284 	}
3285 
3286 	if ((res->num_tcs != RTE_ETH_4_TCS) && (res->num_tcs != RTE_ETH_8_TCS)) {
3287 		fprintf(stderr,
3288 			"The invalid number of traffic class, only 4 or 8 allowed.\n");
3289 		return;
3290 	}
3291 
3292 	if (nb_fwd_lcores < res->num_tcs) {
3293 		fprintf(stderr,
3294 			"nb_cores shouldn't be less than number of TCs.\n");
3295 		return;
3296 	}
3297 
3298 	/* Check whether the port supports the report of DCB info. */
3299 	ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3300 	if (ret == -ENOTSUP) {
3301 		fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n");
3302 		return;
3303 	}
3304 
3305 	if (!strncmp(res->pfc_en, "on", 2))
3306 		pfc_en = 1;
3307 	else
3308 		pfc_en = 0;
3309 
3310 	/* DCB in VT mode */
3311 	if (!strncmp(res->vt_en, "on", 2))
3312 		ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3313 				(enum rte_eth_nb_tcs)res->num_tcs,
3314 				pfc_en);
3315 	else
3316 		ret = init_port_dcb_config(port_id, DCB_ENABLED,
3317 				(enum rte_eth_nb_tcs)res->num_tcs,
3318 				pfc_en);
3319 	if (ret != 0) {
3320 		fprintf(stderr, "Cannot initialize network ports.\n");
3321 		return;
3322 	}
3323 
3324 	fwd_config_setup();
3325 
3326 	cmd_reconfig_device_queue(port_id, 1, 1);
3327 }
3328 
3329 cmdline_parse_token_string_t cmd_config_dcb_port =
3330         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3331 cmdline_parse_token_string_t cmd_config_dcb_config =
3332         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3333 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3334 	TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3335 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3336         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3337 cmdline_parse_token_string_t cmd_config_dcb_vt =
3338         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3339 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3340         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3341 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3342 	TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3343 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3344         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3345 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3346         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3347 
3348 cmdline_parse_inst_t cmd_config_dcb = {
3349 	.f = cmd_config_dcb_parsed,
3350 	.data = NULL,
3351 	.help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3352 	.tokens = {
3353 		(void *)&cmd_config_dcb_port,
3354 		(void *)&cmd_config_dcb_config,
3355 		(void *)&cmd_config_dcb_port_id,
3356 		(void *)&cmd_config_dcb_dcb,
3357 		(void *)&cmd_config_dcb_vt,
3358 		(void *)&cmd_config_dcb_vt_en,
3359 		(void *)&cmd_config_dcb_num_tcs,
3360 		(void *)&cmd_config_dcb_pfc,
3361 		(void *)&cmd_config_dcb_pfc_en,
3362                 NULL,
3363         },
3364 };
3365 
3366 /* *** configure number of packets per burst *** */
3367 struct cmd_config_burst {
3368 	cmdline_fixed_string_t port;
3369 	cmdline_fixed_string_t keyword;
3370 	cmdline_fixed_string_t all;
3371 	cmdline_fixed_string_t name;
3372 	uint16_t value;
3373 };
3374 
3375 static void
3376 cmd_config_burst_parsed(void *parsed_result,
3377 			__rte_unused struct cmdline *cl,
3378 			__rte_unused void *data)
3379 {
3380 	struct cmd_config_burst *res = parsed_result;
3381 	struct rte_eth_dev_info dev_info;
3382 	uint16_t rec_nb_pkts;
3383 	int ret;
3384 
3385 	if (!all_ports_stopped()) {
3386 		fprintf(stderr, "Please stop all ports first\n");
3387 		return;
3388 	}
3389 
3390 	if (!strcmp(res->name, "burst")) {
3391 		if (res->value == 0) {
3392 			/* If user gives a value of zero, query the PMD for
3393 			 * its recommended Rx burst size. Testpmd uses a single
3394 			 * size for all ports, so assume all ports are the same
3395 			 * NIC model and use the values from Port 0.
3396 			 */
3397 			ret = eth_dev_info_get_print_err(0, &dev_info);
3398 			if (ret != 0)
3399 				return;
3400 
3401 			rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3402 
3403 			if (rec_nb_pkts == 0) {
3404 				printf("PMD does not recommend a burst size.\n"
3405 					"User provided value must be between"
3406 					" 1 and %d\n", MAX_PKT_BURST);
3407 				return;
3408 			} else if (rec_nb_pkts > MAX_PKT_BURST) {
3409 				printf("PMD recommended burst size of %d"
3410 					" exceeds maximum value of %d\n",
3411 					rec_nb_pkts, MAX_PKT_BURST);
3412 				return;
3413 			}
3414 			printf("Using PMD-provided burst value of %d\n",
3415 				rec_nb_pkts);
3416 			nb_pkt_per_burst = rec_nb_pkts;
3417 		} else if (res->value > MAX_PKT_BURST) {
3418 			fprintf(stderr, "burst must be >= 1 && <= %d\n",
3419 				MAX_PKT_BURST);
3420 			return;
3421 		} else
3422 			nb_pkt_per_burst = res->value;
3423 	} else {
3424 		fprintf(stderr, "Unknown parameter\n");
3425 		return;
3426 	}
3427 
3428 	init_port_config();
3429 
3430 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3431 }
3432 
3433 cmdline_parse_token_string_t cmd_config_burst_port =
3434 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3435 cmdline_parse_token_string_t cmd_config_burst_keyword =
3436 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3437 cmdline_parse_token_string_t cmd_config_burst_all =
3438 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3439 cmdline_parse_token_string_t cmd_config_burst_name =
3440 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3441 cmdline_parse_token_num_t cmd_config_burst_value =
3442 	TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3443 
3444 cmdline_parse_inst_t cmd_config_burst = {
3445 	.f = cmd_config_burst_parsed,
3446 	.data = NULL,
3447 	.help_str = "port config all burst <value>",
3448 	.tokens = {
3449 		(void *)&cmd_config_burst_port,
3450 		(void *)&cmd_config_burst_keyword,
3451 		(void *)&cmd_config_burst_all,
3452 		(void *)&cmd_config_burst_name,
3453 		(void *)&cmd_config_burst_value,
3454 		NULL,
3455 	},
3456 };
3457 
3458 /* *** configure rx/tx queues *** */
3459 struct cmd_config_thresh {
3460 	cmdline_fixed_string_t port;
3461 	cmdline_fixed_string_t keyword;
3462 	cmdline_fixed_string_t all;
3463 	cmdline_fixed_string_t name;
3464 	uint8_t value;
3465 };
3466 
3467 static void
3468 cmd_config_thresh_parsed(void *parsed_result,
3469 			__rte_unused struct cmdline *cl,
3470 			__rte_unused void *data)
3471 {
3472 	struct cmd_config_thresh *res = parsed_result;
3473 
3474 	if (!all_ports_stopped()) {
3475 		fprintf(stderr, "Please stop all ports first\n");
3476 		return;
3477 	}
3478 
3479 	if (!strcmp(res->name, "txpt"))
3480 		tx_pthresh = res->value;
3481 	else if(!strcmp(res->name, "txht"))
3482 		tx_hthresh = res->value;
3483 	else if(!strcmp(res->name, "txwt"))
3484 		tx_wthresh = res->value;
3485 	else if(!strcmp(res->name, "rxpt"))
3486 		rx_pthresh = res->value;
3487 	else if(!strcmp(res->name, "rxht"))
3488 		rx_hthresh = res->value;
3489 	else if(!strcmp(res->name, "rxwt"))
3490 		rx_wthresh = res->value;
3491 	else {
3492 		fprintf(stderr, "Unknown parameter\n");
3493 		return;
3494 	}
3495 
3496 	init_port_config();
3497 
3498 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3499 }
3500 
3501 cmdline_parse_token_string_t cmd_config_thresh_port =
3502 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3503 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3504 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3505 cmdline_parse_token_string_t cmd_config_thresh_all =
3506 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3507 cmdline_parse_token_string_t cmd_config_thresh_name =
3508 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3509 				"txpt#txht#txwt#rxpt#rxht#rxwt");
3510 cmdline_parse_token_num_t cmd_config_thresh_value =
3511 	TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3512 
3513 cmdline_parse_inst_t cmd_config_thresh = {
3514 	.f = cmd_config_thresh_parsed,
3515 	.data = NULL,
3516 	.help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3517 	.tokens = {
3518 		(void *)&cmd_config_thresh_port,
3519 		(void *)&cmd_config_thresh_keyword,
3520 		(void *)&cmd_config_thresh_all,
3521 		(void *)&cmd_config_thresh_name,
3522 		(void *)&cmd_config_thresh_value,
3523 		NULL,
3524 	},
3525 };
3526 
3527 /* *** configure free/rs threshold *** */
3528 struct cmd_config_threshold {
3529 	cmdline_fixed_string_t port;
3530 	cmdline_fixed_string_t keyword;
3531 	cmdline_fixed_string_t all;
3532 	cmdline_fixed_string_t name;
3533 	uint16_t value;
3534 };
3535 
3536 static void
3537 cmd_config_threshold_parsed(void *parsed_result,
3538 			__rte_unused struct cmdline *cl,
3539 			__rte_unused void *data)
3540 {
3541 	struct cmd_config_threshold *res = parsed_result;
3542 
3543 	if (!all_ports_stopped()) {
3544 		fprintf(stderr, "Please stop all ports first\n");
3545 		return;
3546 	}
3547 
3548 	if (!strcmp(res->name, "txfreet"))
3549 		tx_free_thresh = res->value;
3550 	else if (!strcmp(res->name, "txrst"))
3551 		tx_rs_thresh = res->value;
3552 	else if (!strcmp(res->name, "rxfreet"))
3553 		rx_free_thresh = res->value;
3554 	else {
3555 		fprintf(stderr, "Unknown parameter\n");
3556 		return;
3557 	}
3558 
3559 	init_port_config();
3560 
3561 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3562 }
3563 
3564 cmdline_parse_token_string_t cmd_config_threshold_port =
3565 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3566 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3567 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3568 								"config");
3569 cmdline_parse_token_string_t cmd_config_threshold_all =
3570 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3571 cmdline_parse_token_string_t cmd_config_threshold_name =
3572 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3573 						"txfreet#txrst#rxfreet");
3574 cmdline_parse_token_num_t cmd_config_threshold_value =
3575 	TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3576 
3577 cmdline_parse_inst_t cmd_config_threshold = {
3578 	.f = cmd_config_threshold_parsed,
3579 	.data = NULL,
3580 	.help_str = "port config all txfreet|txrst|rxfreet <value>",
3581 	.tokens = {
3582 		(void *)&cmd_config_threshold_port,
3583 		(void *)&cmd_config_threshold_keyword,
3584 		(void *)&cmd_config_threshold_all,
3585 		(void *)&cmd_config_threshold_name,
3586 		(void *)&cmd_config_threshold_value,
3587 		NULL,
3588 	},
3589 };
3590 
3591 /* *** stop *** */
3592 struct cmd_stop_result {
3593 	cmdline_fixed_string_t stop;
3594 };
3595 
3596 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3597 			    __rte_unused struct cmdline *cl,
3598 			    __rte_unused void *data)
3599 {
3600 	stop_packet_forwarding();
3601 }
3602 
3603 cmdline_parse_token_string_t cmd_stop_stop =
3604 	TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3605 
3606 cmdline_parse_inst_t cmd_stop = {
3607 	.f = cmd_stop_parsed,
3608 	.data = NULL,
3609 	.help_str = "stop: Stop packet forwarding",
3610 	.tokens = {
3611 		(void *)&cmd_stop_stop,
3612 		NULL,
3613 	},
3614 };
3615 
3616 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3617 
3618 unsigned int
3619 parse_item_list(const char *str, const char *item_name, unsigned int max_items,
3620 		unsigned int *parsed_items, int check_unique_values)
3621 {
3622 	unsigned int nb_item;
3623 	unsigned int value;
3624 	unsigned int i;
3625 	unsigned int j;
3626 	int value_ok;
3627 	char c;
3628 
3629 	/*
3630 	 * First parse all items in the list and store their value.
3631 	 */
3632 	value = 0;
3633 	nb_item = 0;
3634 	value_ok = 0;
3635 	for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3636 		c = str[i];
3637 		if ((c >= '0') && (c <= '9')) {
3638 			value = (unsigned int) (value * 10 + (c - '0'));
3639 			value_ok = 1;
3640 			continue;
3641 		}
3642 		if (c != ',') {
3643 			fprintf(stderr, "character %c is not a decimal digit\n", c);
3644 			return 0;
3645 		}
3646 		if (! value_ok) {
3647 			fprintf(stderr, "No valid value before comma\n");
3648 			return 0;
3649 		}
3650 		if (nb_item < max_items) {
3651 			parsed_items[nb_item] = value;
3652 			value_ok = 0;
3653 			value = 0;
3654 		}
3655 		nb_item++;
3656 	}
3657 	if (nb_item >= max_items) {
3658 		fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3659 			item_name, nb_item + 1, max_items);
3660 		return 0;
3661 	}
3662 	parsed_items[nb_item++] = value;
3663 	if (! check_unique_values)
3664 		return nb_item;
3665 
3666 	/*
3667 	 * Then, check that all values in the list are different.
3668 	 * No optimization here...
3669 	 */
3670 	for (i = 0; i < nb_item; i++) {
3671 		for (j = i + 1; j < nb_item; j++) {
3672 			if (parsed_items[j] == parsed_items[i]) {
3673 				fprintf(stderr,
3674 					"duplicated %s %u at index %u and %u\n",
3675 					item_name, parsed_items[i], i, j);
3676 				return 0;
3677 			}
3678 		}
3679 	}
3680 	return nb_item;
3681 }
3682 
3683 struct cmd_set_list_result {
3684 	cmdline_fixed_string_t cmd_keyword;
3685 	cmdline_fixed_string_t list_name;
3686 	cmdline_fixed_string_t list_of_items;
3687 };
3688 
3689 static void cmd_set_list_parsed(void *parsed_result,
3690 				__rte_unused struct cmdline *cl,
3691 				__rte_unused void *data)
3692 {
3693 	struct cmd_set_list_result *res;
3694 	union {
3695 		unsigned int lcorelist[RTE_MAX_LCORE];
3696 		unsigned int portlist[RTE_MAX_ETHPORTS];
3697 	} parsed_items;
3698 	unsigned int nb_item;
3699 
3700 	if (test_done == 0) {
3701 		fprintf(stderr, "Please stop forwarding first\n");
3702 		return;
3703 	}
3704 
3705 	res = parsed_result;
3706 	if (!strcmp(res->list_name, "corelist")) {
3707 		nb_item = parse_item_list(res->list_of_items, "core",
3708 					  RTE_MAX_LCORE,
3709 					  parsed_items.lcorelist, 1);
3710 		if (nb_item > 0) {
3711 			set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3712 			fwd_config_setup();
3713 		}
3714 		return;
3715 	}
3716 	if (!strcmp(res->list_name, "portlist")) {
3717 		nb_item = parse_item_list(res->list_of_items, "port",
3718 					  RTE_MAX_ETHPORTS,
3719 					  parsed_items.portlist, 1);
3720 		if (nb_item > 0) {
3721 			set_fwd_ports_list(parsed_items.portlist, nb_item);
3722 			fwd_config_setup();
3723 		}
3724 	}
3725 }
3726 
3727 cmdline_parse_token_string_t cmd_set_list_keyword =
3728 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3729 				 "set");
3730 cmdline_parse_token_string_t cmd_set_list_name =
3731 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3732 				 "corelist#portlist");
3733 cmdline_parse_token_string_t cmd_set_list_of_items =
3734 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3735 				 NULL);
3736 
3737 cmdline_parse_inst_t cmd_set_fwd_list = {
3738 	.f = cmd_set_list_parsed,
3739 	.data = NULL,
3740 	.help_str = "set corelist|portlist <list0[,list1]*>",
3741 	.tokens = {
3742 		(void *)&cmd_set_list_keyword,
3743 		(void *)&cmd_set_list_name,
3744 		(void *)&cmd_set_list_of_items,
3745 		NULL,
3746 	},
3747 };
3748 
3749 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3750 
3751 struct cmd_setmask_result {
3752 	cmdline_fixed_string_t set;
3753 	cmdline_fixed_string_t mask;
3754 	uint64_t hexavalue;
3755 };
3756 
3757 static void cmd_set_mask_parsed(void *parsed_result,
3758 				__rte_unused struct cmdline *cl,
3759 				__rte_unused void *data)
3760 {
3761 	struct cmd_setmask_result *res = parsed_result;
3762 
3763 	if (test_done == 0) {
3764 		fprintf(stderr, "Please stop forwarding first\n");
3765 		return;
3766 	}
3767 	if (!strcmp(res->mask, "coremask")) {
3768 		set_fwd_lcores_mask(res->hexavalue);
3769 		fwd_config_setup();
3770 	} else if (!strcmp(res->mask, "portmask")) {
3771 		set_fwd_ports_mask(res->hexavalue);
3772 		fwd_config_setup();
3773 	}
3774 }
3775 
3776 cmdline_parse_token_string_t cmd_setmask_set =
3777 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3778 cmdline_parse_token_string_t cmd_setmask_mask =
3779 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3780 				 "coremask#portmask");
3781 cmdline_parse_token_num_t cmd_setmask_value =
3782 	TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3783 
3784 cmdline_parse_inst_t cmd_set_fwd_mask = {
3785 	.f = cmd_set_mask_parsed,
3786 	.data = NULL,
3787 	.help_str = "set coremask|portmask <hexadecimal value>",
3788 	.tokens = {
3789 		(void *)&cmd_setmask_set,
3790 		(void *)&cmd_setmask_mask,
3791 		(void *)&cmd_setmask_value,
3792 		NULL,
3793 	},
3794 };
3795 
3796 /*
3797  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3798  */
3799 struct cmd_set_result {
3800 	cmdline_fixed_string_t set;
3801 	cmdline_fixed_string_t what;
3802 	uint16_t value;
3803 };
3804 
3805 static void cmd_set_parsed(void *parsed_result,
3806 			   __rte_unused struct cmdline *cl,
3807 			   __rte_unused void *data)
3808 {
3809 	struct cmd_set_result *res = parsed_result;
3810 	if (!strcmp(res->what, "nbport")) {
3811 		set_fwd_ports_number(res->value);
3812 		fwd_config_setup();
3813 	} else if (!strcmp(res->what, "nbcore")) {
3814 		set_fwd_lcores_number(res->value);
3815 		fwd_config_setup();
3816 	} else if (!strcmp(res->what, "burst"))
3817 		set_nb_pkt_per_burst(res->value);
3818 	else if (!strcmp(res->what, "verbose"))
3819 		set_verbose_level(res->value);
3820 }
3821 
3822 cmdline_parse_token_string_t cmd_set_set =
3823 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3824 cmdline_parse_token_string_t cmd_set_what =
3825 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3826 				 "nbport#nbcore#burst#verbose");
3827 cmdline_parse_token_num_t cmd_set_value =
3828 	TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3829 
3830 cmdline_parse_inst_t cmd_set_numbers = {
3831 	.f = cmd_set_parsed,
3832 	.data = NULL,
3833 	.help_str = "set nbport|nbcore|burst|verbose <value>",
3834 	.tokens = {
3835 		(void *)&cmd_set_set,
3836 		(void *)&cmd_set_what,
3837 		(void *)&cmd_set_value,
3838 		NULL,
3839 	},
3840 };
3841 
3842 /* *** SET LOG LEVEL CONFIGURATION *** */
3843 
3844 struct cmd_set_log_result {
3845 	cmdline_fixed_string_t set;
3846 	cmdline_fixed_string_t log;
3847 	cmdline_fixed_string_t type;
3848 	uint32_t level;
3849 };
3850 
3851 static void
3852 cmd_set_log_parsed(void *parsed_result,
3853 		   __rte_unused struct cmdline *cl,
3854 		   __rte_unused void *data)
3855 {
3856 	struct cmd_set_log_result *res;
3857 	int ret;
3858 
3859 	res = parsed_result;
3860 	if (!strcmp(res->type, "global"))
3861 		rte_log_set_global_level(res->level);
3862 	else {
3863 		ret = rte_log_set_level_regexp(res->type, res->level);
3864 		if (ret < 0)
3865 			fprintf(stderr, "Unable to set log level\n");
3866 	}
3867 }
3868 
3869 cmdline_parse_token_string_t cmd_set_log_set =
3870 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3871 cmdline_parse_token_string_t cmd_set_log_log =
3872 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3873 cmdline_parse_token_string_t cmd_set_log_type =
3874 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3875 cmdline_parse_token_num_t cmd_set_log_level =
3876 	TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3877 
3878 cmdline_parse_inst_t cmd_set_log = {
3879 	.f = cmd_set_log_parsed,
3880 	.data = NULL,
3881 	.help_str = "set log global|<type> <level>",
3882 	.tokens = {
3883 		(void *)&cmd_set_log_set,
3884 		(void *)&cmd_set_log_log,
3885 		(void *)&cmd_set_log_type,
3886 		(void *)&cmd_set_log_level,
3887 		NULL,
3888 	},
3889 };
3890 
3891 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3892 
3893 struct cmd_set_rxoffs_result {
3894 	cmdline_fixed_string_t cmd_keyword;
3895 	cmdline_fixed_string_t rxoffs;
3896 	cmdline_fixed_string_t seg_offsets;
3897 };
3898 
3899 static void
3900 cmd_set_rxoffs_parsed(void *parsed_result,
3901 		      __rte_unused struct cmdline *cl,
3902 		      __rte_unused void *data)
3903 {
3904 	struct cmd_set_rxoffs_result *res;
3905 	unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3906 	unsigned int nb_segs;
3907 
3908 	res = parsed_result;
3909 	nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3910 				  MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3911 	if (nb_segs > 0)
3912 		set_rx_pkt_offsets(seg_offsets, nb_segs);
3913 	cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3914 }
3915 
3916 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3917 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3918 				 cmd_keyword, "set");
3919 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3920 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3921 				 rxoffs, "rxoffs");
3922 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3923 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3924 				 seg_offsets, NULL);
3925 
3926 cmdline_parse_inst_t cmd_set_rxoffs = {
3927 	.f = cmd_set_rxoffs_parsed,
3928 	.data = NULL,
3929 	.help_str = "set rxoffs <len0[,len1]*>",
3930 	.tokens = {
3931 		(void *)&cmd_set_rxoffs_keyword,
3932 		(void *)&cmd_set_rxoffs_name,
3933 		(void *)&cmd_set_rxoffs_offsets,
3934 		NULL,
3935 	},
3936 };
3937 
3938 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3939 
3940 struct cmd_set_rxpkts_result {
3941 	cmdline_fixed_string_t cmd_keyword;
3942 	cmdline_fixed_string_t rxpkts;
3943 	cmdline_fixed_string_t seg_lengths;
3944 };
3945 
3946 static void
3947 cmd_set_rxpkts_parsed(void *parsed_result,
3948 		      __rte_unused struct cmdline *cl,
3949 		      __rte_unused void *data)
3950 {
3951 	struct cmd_set_rxpkts_result *res;
3952 	unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3953 	unsigned int nb_segs;
3954 
3955 	res = parsed_result;
3956 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3957 				  MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3958 	if (nb_segs > 0)
3959 		set_rx_pkt_segments(seg_lengths, nb_segs);
3960 	cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3961 }
3962 
3963 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3964 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3965 				 cmd_keyword, "set");
3966 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3967 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3968 				 rxpkts, "rxpkts");
3969 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3970 	TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3971 				 seg_lengths, NULL);
3972 
3973 cmdline_parse_inst_t cmd_set_rxpkts = {
3974 	.f = cmd_set_rxpkts_parsed,
3975 	.data = NULL,
3976 	.help_str = "set rxpkts <len0[,len1]*>",
3977 	.tokens = {
3978 		(void *)&cmd_set_rxpkts_keyword,
3979 		(void *)&cmd_set_rxpkts_name,
3980 		(void *)&cmd_set_rxpkts_lengths,
3981 		NULL,
3982 	},
3983 };
3984 
3985 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3986 
3987 struct cmd_set_txpkts_result {
3988 	cmdline_fixed_string_t cmd_keyword;
3989 	cmdline_fixed_string_t txpkts;
3990 	cmdline_fixed_string_t seg_lengths;
3991 };
3992 
3993 static void
3994 cmd_set_txpkts_parsed(void *parsed_result,
3995 		      __rte_unused struct cmdline *cl,
3996 		      __rte_unused void *data)
3997 {
3998 	struct cmd_set_txpkts_result *res;
3999 	unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
4000 	unsigned int nb_segs;
4001 
4002 	res = parsed_result;
4003 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
4004 				  RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
4005 	if (nb_segs > 0)
4006 		set_tx_pkt_segments(seg_lengths, nb_segs);
4007 }
4008 
4009 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4010 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4011 				 cmd_keyword, "set");
4012 cmdline_parse_token_string_t cmd_set_txpkts_name =
4013 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4014 				 txpkts, "txpkts");
4015 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4016 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4017 				 seg_lengths, NULL);
4018 
4019 cmdline_parse_inst_t cmd_set_txpkts = {
4020 	.f = cmd_set_txpkts_parsed,
4021 	.data = NULL,
4022 	.help_str = "set txpkts <len0[,len1]*>",
4023 	.tokens = {
4024 		(void *)&cmd_set_txpkts_keyword,
4025 		(void *)&cmd_set_txpkts_name,
4026 		(void *)&cmd_set_txpkts_lengths,
4027 		NULL,
4028 	},
4029 };
4030 
4031 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4032 
4033 struct cmd_set_txsplit_result {
4034 	cmdline_fixed_string_t cmd_keyword;
4035 	cmdline_fixed_string_t txsplit;
4036 	cmdline_fixed_string_t mode;
4037 };
4038 
4039 static void
4040 cmd_set_txsplit_parsed(void *parsed_result,
4041 		      __rte_unused struct cmdline *cl,
4042 		      __rte_unused void *data)
4043 {
4044 	struct cmd_set_txsplit_result *res;
4045 
4046 	res = parsed_result;
4047 	set_tx_pkt_split(res->mode);
4048 }
4049 
4050 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4051 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4052 				 cmd_keyword, "set");
4053 cmdline_parse_token_string_t cmd_set_txsplit_name =
4054 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4055 				 txsplit, "txsplit");
4056 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4057 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4058 				 mode, NULL);
4059 
4060 cmdline_parse_inst_t cmd_set_txsplit = {
4061 	.f = cmd_set_txsplit_parsed,
4062 	.data = NULL,
4063 	.help_str = "set txsplit on|off|rand",
4064 	.tokens = {
4065 		(void *)&cmd_set_txsplit_keyword,
4066 		(void *)&cmd_set_txsplit_name,
4067 		(void *)&cmd_set_txsplit_mode,
4068 		NULL,
4069 	},
4070 };
4071 
4072 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4073 
4074 struct cmd_set_txtimes_result {
4075 	cmdline_fixed_string_t cmd_keyword;
4076 	cmdline_fixed_string_t txtimes;
4077 	cmdline_fixed_string_t tx_times;
4078 };
4079 
4080 static void
4081 cmd_set_txtimes_parsed(void *parsed_result,
4082 		       __rte_unused struct cmdline *cl,
4083 		       __rte_unused void *data)
4084 {
4085 	struct cmd_set_txtimes_result *res;
4086 	unsigned int tx_times[2] = {0, 0};
4087 	unsigned int n_times;
4088 
4089 	res = parsed_result;
4090 	n_times = parse_item_list(res->tx_times, "tx times",
4091 				  2, tx_times, 0);
4092 	if (n_times == 2)
4093 		set_tx_pkt_times(tx_times);
4094 }
4095 
4096 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4097 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4098 				 cmd_keyword, "set");
4099 cmdline_parse_token_string_t cmd_set_txtimes_name =
4100 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4101 				 txtimes, "txtimes");
4102 cmdline_parse_token_string_t cmd_set_txtimes_value =
4103 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4104 				 tx_times, NULL);
4105 
4106 cmdline_parse_inst_t cmd_set_txtimes = {
4107 	.f = cmd_set_txtimes_parsed,
4108 	.data = NULL,
4109 	.help_str = "set txtimes <inter_burst>,<intra_burst>",
4110 	.tokens = {
4111 		(void *)&cmd_set_txtimes_keyword,
4112 		(void *)&cmd_set_txtimes_name,
4113 		(void *)&cmd_set_txtimes_value,
4114 		NULL,
4115 	},
4116 };
4117 
4118 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4119 struct cmd_rx_vlan_filter_all_result {
4120 	cmdline_fixed_string_t rx_vlan;
4121 	cmdline_fixed_string_t what;
4122 	cmdline_fixed_string_t all;
4123 	portid_t port_id;
4124 };
4125 
4126 static void
4127 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4128 			      __rte_unused struct cmdline *cl,
4129 			      __rte_unused void *data)
4130 {
4131 	struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4132 
4133 	if (!strcmp(res->what, "add"))
4134 		rx_vlan_all_filter_set(res->port_id, 1);
4135 	else
4136 		rx_vlan_all_filter_set(res->port_id, 0);
4137 }
4138 
4139 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4140 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4141 				 rx_vlan, "rx_vlan");
4142 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4143 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4144 				 what, "add#rm");
4145 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4146 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4147 				 all, "all");
4148 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4149 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4150 			      port_id, RTE_UINT16);
4151 
4152 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4153 	.f = cmd_rx_vlan_filter_all_parsed,
4154 	.data = NULL,
4155 	.help_str = "rx_vlan add|rm all <port_id>: "
4156 		"Add/Remove all identifiers to/from the set of VLAN "
4157 		"identifiers filtered by a port",
4158 	.tokens = {
4159 		(void *)&cmd_rx_vlan_filter_all_rx_vlan,
4160 		(void *)&cmd_rx_vlan_filter_all_what,
4161 		(void *)&cmd_rx_vlan_filter_all_all,
4162 		(void *)&cmd_rx_vlan_filter_all_portid,
4163 		NULL,
4164 	},
4165 };
4166 
4167 /* *** VLAN OFFLOAD SET ON A PORT *** */
4168 struct cmd_vlan_offload_result {
4169 	cmdline_fixed_string_t vlan;
4170 	cmdline_fixed_string_t set;
4171 	cmdline_fixed_string_t vlan_type;
4172 	cmdline_fixed_string_t what;
4173 	cmdline_fixed_string_t on;
4174 	cmdline_fixed_string_t port_id;
4175 };
4176 
4177 static void
4178 cmd_vlan_offload_parsed(void *parsed_result,
4179 			  __rte_unused struct cmdline *cl,
4180 			  __rte_unused void *data)
4181 {
4182 	int on;
4183 	struct cmd_vlan_offload_result *res = parsed_result;
4184 	char *str;
4185 	int i, len = 0;
4186 	portid_t port_id = 0;
4187 	unsigned int tmp;
4188 
4189 	str = res->port_id;
4190 	len = strnlen(str, STR_TOKEN_SIZE);
4191 	i = 0;
4192 	/* Get port_id first */
4193 	while(i < len){
4194 		if(str[i] == ',')
4195 			break;
4196 
4197 		i++;
4198 	}
4199 	str[i]='\0';
4200 	tmp = strtoul(str, NULL, 0);
4201 	/* If port_id greater that what portid_t can represent, return */
4202 	if(tmp >= RTE_MAX_ETHPORTS)
4203 		return;
4204 	port_id = (portid_t)tmp;
4205 
4206 	if (!strcmp(res->on, "on"))
4207 		on = 1;
4208 	else
4209 		on = 0;
4210 
4211 	if (!strcmp(res->what, "strip"))
4212 		rx_vlan_strip_set(port_id,  on);
4213 	else if(!strcmp(res->what, "stripq")){
4214 		uint16_t queue_id = 0;
4215 
4216 		/* No queue_id, return */
4217 		if(i + 1 >= len) {
4218 			fprintf(stderr, "must specify (port,queue_id)\n");
4219 			return;
4220 		}
4221 		tmp = strtoul(str + i + 1, NULL, 0);
4222 		/* If queue_id greater that what 16-bits can represent, return */
4223 		if(tmp > 0xffff)
4224 			return;
4225 
4226 		queue_id = (uint16_t)tmp;
4227 		rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4228 	}
4229 	else if (!strcmp(res->what, "filter"))
4230 		rx_vlan_filter_set(port_id, on);
4231 	else if (!strcmp(res->what, "qinq_strip"))
4232 		rx_vlan_qinq_strip_set(port_id, on);
4233 	else
4234 		vlan_extend_set(port_id, on);
4235 
4236 	return;
4237 }
4238 
4239 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4240 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4241 				 vlan, "vlan");
4242 cmdline_parse_token_string_t cmd_vlan_offload_set =
4243 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4244 				 set, "set");
4245 cmdline_parse_token_string_t cmd_vlan_offload_what =
4246 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4247 				what, "strip#filter#qinq_strip#extend#stripq");
4248 cmdline_parse_token_string_t cmd_vlan_offload_on =
4249 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4250 			      on, "on#off");
4251 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4252 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4253 			      port_id, NULL);
4254 
4255 cmdline_parse_inst_t cmd_vlan_offload = {
4256 	.f = cmd_vlan_offload_parsed,
4257 	.data = NULL,
4258 	.help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4259 		"<port_id[,queue_id]>: "
4260 		"Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4261 	.tokens = {
4262 		(void *)&cmd_vlan_offload_vlan,
4263 		(void *)&cmd_vlan_offload_set,
4264 		(void *)&cmd_vlan_offload_what,
4265 		(void *)&cmd_vlan_offload_on,
4266 		(void *)&cmd_vlan_offload_portid,
4267 		NULL,
4268 	},
4269 };
4270 
4271 /* *** VLAN TPID SET ON A PORT *** */
4272 struct cmd_vlan_tpid_result {
4273 	cmdline_fixed_string_t vlan;
4274 	cmdline_fixed_string_t set;
4275 	cmdline_fixed_string_t vlan_type;
4276 	cmdline_fixed_string_t what;
4277 	uint16_t tp_id;
4278 	portid_t port_id;
4279 };
4280 
4281 static void
4282 cmd_vlan_tpid_parsed(void *parsed_result,
4283 			  __rte_unused struct cmdline *cl,
4284 			  __rte_unused void *data)
4285 {
4286 	struct cmd_vlan_tpid_result *res = parsed_result;
4287 	enum rte_vlan_type vlan_type;
4288 
4289 	if (!strcmp(res->vlan_type, "inner"))
4290 		vlan_type = RTE_ETH_VLAN_TYPE_INNER;
4291 	else if (!strcmp(res->vlan_type, "outer"))
4292 		vlan_type = RTE_ETH_VLAN_TYPE_OUTER;
4293 	else {
4294 		fprintf(stderr, "Unknown vlan type\n");
4295 		return;
4296 	}
4297 	vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4298 }
4299 
4300 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4301 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4302 				 vlan, "vlan");
4303 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4304 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4305 				 set, "set");
4306 cmdline_parse_token_string_t cmd_vlan_type =
4307 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4308 				 vlan_type, "inner#outer");
4309 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4310 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4311 				 what, "tpid");
4312 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4313 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4314 			      tp_id, RTE_UINT16);
4315 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4316 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4317 			      port_id, RTE_UINT16);
4318 
4319 cmdline_parse_inst_t cmd_vlan_tpid = {
4320 	.f = cmd_vlan_tpid_parsed,
4321 	.data = NULL,
4322 	.help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4323 		"Set the VLAN Ether type",
4324 	.tokens = {
4325 		(void *)&cmd_vlan_tpid_vlan,
4326 		(void *)&cmd_vlan_tpid_set,
4327 		(void *)&cmd_vlan_type,
4328 		(void *)&cmd_vlan_tpid_what,
4329 		(void *)&cmd_vlan_tpid_tpid,
4330 		(void *)&cmd_vlan_tpid_portid,
4331 		NULL,
4332 	},
4333 };
4334 
4335 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4336 struct cmd_rx_vlan_filter_result {
4337 	cmdline_fixed_string_t rx_vlan;
4338 	cmdline_fixed_string_t what;
4339 	uint16_t vlan_id;
4340 	portid_t port_id;
4341 };
4342 
4343 static void
4344 cmd_rx_vlan_filter_parsed(void *parsed_result,
4345 			  __rte_unused struct cmdline *cl,
4346 			  __rte_unused void *data)
4347 {
4348 	struct cmd_rx_vlan_filter_result *res = parsed_result;
4349 
4350 	if (!strcmp(res->what, "add"))
4351 		rx_vft_set(res->port_id, res->vlan_id, 1);
4352 	else
4353 		rx_vft_set(res->port_id, res->vlan_id, 0);
4354 }
4355 
4356 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4357 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4358 				 rx_vlan, "rx_vlan");
4359 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4360 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4361 				 what, "add#rm");
4362 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4363 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4364 			      vlan_id, RTE_UINT16);
4365 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4366 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4367 			      port_id, RTE_UINT16);
4368 
4369 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4370 	.f = cmd_rx_vlan_filter_parsed,
4371 	.data = NULL,
4372 	.help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4373 		"Add/Remove a VLAN identifier to/from the set of VLAN "
4374 		"identifiers filtered by a port",
4375 	.tokens = {
4376 		(void *)&cmd_rx_vlan_filter_rx_vlan,
4377 		(void *)&cmd_rx_vlan_filter_what,
4378 		(void *)&cmd_rx_vlan_filter_vlanid,
4379 		(void *)&cmd_rx_vlan_filter_portid,
4380 		NULL,
4381 	},
4382 };
4383 
4384 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4385 struct cmd_tx_vlan_set_result {
4386 	cmdline_fixed_string_t tx_vlan;
4387 	cmdline_fixed_string_t set;
4388 	portid_t port_id;
4389 	uint16_t vlan_id;
4390 };
4391 
4392 static void
4393 cmd_tx_vlan_set_parsed(void *parsed_result,
4394 		       __rte_unused struct cmdline *cl,
4395 		       __rte_unused void *data)
4396 {
4397 	struct cmd_tx_vlan_set_result *res = parsed_result;
4398 
4399 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4400 		return;
4401 
4402 	if (!port_is_stopped(res->port_id)) {
4403 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4404 		return;
4405 	}
4406 
4407 	tx_vlan_set(res->port_id, res->vlan_id);
4408 
4409 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4410 }
4411 
4412 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4413 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4414 				 tx_vlan, "tx_vlan");
4415 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4416 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4417 				 set, "set");
4418 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4419 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4420 			      port_id, RTE_UINT16);
4421 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4422 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4423 			      vlan_id, RTE_UINT16);
4424 
4425 cmdline_parse_inst_t cmd_tx_vlan_set = {
4426 	.f = cmd_tx_vlan_set_parsed,
4427 	.data = NULL,
4428 	.help_str = "tx_vlan set <port_id> <vlan_id>: "
4429 		"Enable hardware insertion of a single VLAN header "
4430 		"with a given TAG Identifier in packets sent on a port",
4431 	.tokens = {
4432 		(void *)&cmd_tx_vlan_set_tx_vlan,
4433 		(void *)&cmd_tx_vlan_set_set,
4434 		(void *)&cmd_tx_vlan_set_portid,
4435 		(void *)&cmd_tx_vlan_set_vlanid,
4436 		NULL,
4437 	},
4438 };
4439 
4440 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4441 struct cmd_tx_vlan_set_qinq_result {
4442 	cmdline_fixed_string_t tx_vlan;
4443 	cmdline_fixed_string_t set;
4444 	portid_t port_id;
4445 	uint16_t vlan_id;
4446 	uint16_t vlan_id_outer;
4447 };
4448 
4449 static void
4450 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4451 			    __rte_unused struct cmdline *cl,
4452 			    __rte_unused void *data)
4453 {
4454 	struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4455 
4456 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4457 		return;
4458 
4459 	if (!port_is_stopped(res->port_id)) {
4460 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4461 		return;
4462 	}
4463 
4464 	tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4465 
4466 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4467 }
4468 
4469 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4470 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4471 		tx_vlan, "tx_vlan");
4472 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4473 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4474 		set, "set");
4475 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4476 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4477 		port_id, RTE_UINT16);
4478 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4479 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4480 		vlan_id, RTE_UINT16);
4481 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4482 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4483 		vlan_id_outer, RTE_UINT16);
4484 
4485 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4486 	.f = cmd_tx_vlan_set_qinq_parsed,
4487 	.data = NULL,
4488 	.help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4489 		"Enable hardware insertion of double VLAN header "
4490 		"with given TAG Identifiers in packets sent on a port",
4491 	.tokens = {
4492 		(void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4493 		(void *)&cmd_tx_vlan_set_qinq_set,
4494 		(void *)&cmd_tx_vlan_set_qinq_portid,
4495 		(void *)&cmd_tx_vlan_set_qinq_vlanid,
4496 		(void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4497 		NULL,
4498 	},
4499 };
4500 
4501 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4502 struct cmd_tx_vlan_set_pvid_result {
4503 	cmdline_fixed_string_t tx_vlan;
4504 	cmdline_fixed_string_t set;
4505 	cmdline_fixed_string_t pvid;
4506 	portid_t port_id;
4507 	uint16_t vlan_id;
4508 	cmdline_fixed_string_t mode;
4509 };
4510 
4511 static void
4512 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4513 			    __rte_unused struct cmdline *cl,
4514 			    __rte_unused void *data)
4515 {
4516 	struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4517 
4518 	if (strcmp(res->mode, "on") == 0)
4519 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4520 	else
4521 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4522 }
4523 
4524 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4525 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4526 				 tx_vlan, "tx_vlan");
4527 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4528 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4529 				 set, "set");
4530 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4531 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4532 				 pvid, "pvid");
4533 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4534 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4535 			     port_id, RTE_UINT16);
4536 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4537 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4538 			      vlan_id, RTE_UINT16);
4539 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4540 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4541 				 mode, "on#off");
4542 
4543 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4544 	.f = cmd_tx_vlan_set_pvid_parsed,
4545 	.data = NULL,
4546 	.help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4547 	.tokens = {
4548 		(void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4549 		(void *)&cmd_tx_vlan_set_pvid_set,
4550 		(void *)&cmd_tx_vlan_set_pvid_pvid,
4551 		(void *)&cmd_tx_vlan_set_pvid_port_id,
4552 		(void *)&cmd_tx_vlan_set_pvid_vlan_id,
4553 		(void *)&cmd_tx_vlan_set_pvid_mode,
4554 		NULL,
4555 	},
4556 };
4557 
4558 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4559 struct cmd_tx_vlan_reset_result {
4560 	cmdline_fixed_string_t tx_vlan;
4561 	cmdline_fixed_string_t reset;
4562 	portid_t port_id;
4563 };
4564 
4565 static void
4566 cmd_tx_vlan_reset_parsed(void *parsed_result,
4567 			 __rte_unused struct cmdline *cl,
4568 			 __rte_unused void *data)
4569 {
4570 	struct cmd_tx_vlan_reset_result *res = parsed_result;
4571 
4572 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4573 		return;
4574 
4575 	if (!port_is_stopped(res->port_id)) {
4576 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4577 		return;
4578 	}
4579 
4580 	tx_vlan_reset(res->port_id);
4581 
4582 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4583 }
4584 
4585 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4586 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4587 				 tx_vlan, "tx_vlan");
4588 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4589 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4590 				 reset, "reset");
4591 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4592 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4593 			      port_id, RTE_UINT16);
4594 
4595 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4596 	.f = cmd_tx_vlan_reset_parsed,
4597 	.data = NULL,
4598 	.help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4599 		"VLAN header in packets sent on a port",
4600 	.tokens = {
4601 		(void *)&cmd_tx_vlan_reset_tx_vlan,
4602 		(void *)&cmd_tx_vlan_reset_reset,
4603 		(void *)&cmd_tx_vlan_reset_portid,
4604 		NULL,
4605 	},
4606 };
4607 
4608 
4609 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4610 struct cmd_csum_result {
4611 	cmdline_fixed_string_t csum;
4612 	cmdline_fixed_string_t mode;
4613 	cmdline_fixed_string_t proto;
4614 	cmdline_fixed_string_t hwsw;
4615 	portid_t port_id;
4616 };
4617 
4618 static void
4619 csum_show(int port_id)
4620 {
4621 	struct rte_eth_dev_info dev_info;
4622 	uint64_t tx_offloads;
4623 	int ret;
4624 
4625 	tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4626 	printf("Parse tunnel is %s\n",
4627 		(ports[port_id].parse_tunnel) ? "on" : "off");
4628 	printf("IP checksum offload is %s\n",
4629 		(tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4630 	printf("UDP checksum offload is %s\n",
4631 		(tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4632 	printf("TCP checksum offload is %s\n",
4633 		(tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4634 	printf("SCTP checksum offload is %s\n",
4635 		(tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4636 	printf("Outer-Ip checksum offload is %s\n",
4637 		(tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4638 	printf("Outer-Udp checksum offload is %s\n",
4639 		(tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4640 
4641 	/* display warnings if configuration is not supported by the NIC */
4642 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
4643 	if (ret != 0)
4644 		return;
4645 
4646 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) &&
4647 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4648 		fprintf(stderr,
4649 			"Warning: hardware IP checksum enabled but not supported by port %d\n",
4650 			port_id);
4651 	}
4652 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) &&
4653 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) == 0) {
4654 		fprintf(stderr,
4655 			"Warning: hardware UDP checksum enabled but not supported by port %d\n",
4656 			port_id);
4657 	}
4658 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) &&
4659 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) == 0) {
4660 		fprintf(stderr,
4661 			"Warning: hardware TCP checksum enabled but not supported by port %d\n",
4662 			port_id);
4663 	}
4664 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) &&
4665 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4666 		fprintf(stderr,
4667 			"Warning: hardware SCTP checksum enabled but not supported by port %d\n",
4668 			port_id);
4669 	}
4670 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4671 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4672 		fprintf(stderr,
4673 			"Warning: hardware outer IP checksum enabled but not supported by port %d\n",
4674 			port_id);
4675 	}
4676 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4677 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
4678 			== 0) {
4679 		fprintf(stderr,
4680 			"Warning: hardware outer UDP checksum enabled but not supported by port %d\n",
4681 			port_id);
4682 	}
4683 }
4684 
4685 static void
4686 cmd_config_queue_tx_offloads(struct rte_port *port)
4687 {
4688 	int k;
4689 
4690 	/* Apply queue tx offloads configuration */
4691 	for (k = 0; k < port->dev_info.max_tx_queues; k++)
4692 		port->tx_conf[k].offloads =
4693 			port->dev_conf.txmode.offloads;
4694 }
4695 
4696 static void
4697 cmd_csum_parsed(void *parsed_result,
4698 		       __rte_unused struct cmdline *cl,
4699 		       __rte_unused void *data)
4700 {
4701 	struct cmd_csum_result *res = parsed_result;
4702 	int hw = 0;
4703 	uint64_t csum_offloads = 0;
4704 	struct rte_eth_dev_info dev_info;
4705 	int ret;
4706 
4707 	if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4708 		fprintf(stderr, "invalid port %d\n", res->port_id);
4709 		return;
4710 	}
4711 	if (!port_is_stopped(res->port_id)) {
4712 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4713 		return;
4714 	}
4715 
4716 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4717 	if (ret != 0)
4718 		return;
4719 
4720 	if (!strcmp(res->mode, "set")) {
4721 
4722 		if (!strcmp(res->hwsw, "hw"))
4723 			hw = 1;
4724 
4725 		if (!strcmp(res->proto, "ip")) {
4726 			if (hw == 0 || (dev_info.tx_offload_capa &
4727 						RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)) {
4728 				csum_offloads |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
4729 			} else {
4730 				fprintf(stderr,
4731 					"IP checksum offload is not supported by port %u\n",
4732 					res->port_id);
4733 			}
4734 		} else if (!strcmp(res->proto, "udp")) {
4735 			if (hw == 0 || (dev_info.tx_offload_capa &
4736 						RTE_ETH_TX_OFFLOAD_UDP_CKSUM)) {
4737 				csum_offloads |= RTE_ETH_TX_OFFLOAD_UDP_CKSUM;
4738 			} else {
4739 				fprintf(stderr,
4740 					"UDP checksum offload is not supported by port %u\n",
4741 					res->port_id);
4742 			}
4743 		} else if (!strcmp(res->proto, "tcp")) {
4744 			if (hw == 0 || (dev_info.tx_offload_capa &
4745 						RTE_ETH_TX_OFFLOAD_TCP_CKSUM)) {
4746 				csum_offloads |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
4747 			} else {
4748 				fprintf(stderr,
4749 					"TCP checksum offload is not supported by port %u\n",
4750 					res->port_id);
4751 			}
4752 		} else if (!strcmp(res->proto, "sctp")) {
4753 			if (hw == 0 || (dev_info.tx_offload_capa &
4754 						RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)) {
4755 				csum_offloads |= RTE_ETH_TX_OFFLOAD_SCTP_CKSUM;
4756 			} else {
4757 				fprintf(stderr,
4758 					"SCTP checksum offload is not supported by port %u\n",
4759 					res->port_id);
4760 			}
4761 		} else if (!strcmp(res->proto, "outer-ip")) {
4762 			if (hw == 0 || (dev_info.tx_offload_capa &
4763 					RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4764 				csum_offloads |=
4765 						RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4766 			} else {
4767 				fprintf(stderr,
4768 					"Outer IP checksum offload is not supported by port %u\n",
4769 					res->port_id);
4770 			}
4771 		} else if (!strcmp(res->proto, "outer-udp")) {
4772 			if (hw == 0 || (dev_info.tx_offload_capa &
4773 					RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4774 				csum_offloads |=
4775 						RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
4776 			} else {
4777 				fprintf(stderr,
4778 					"Outer UDP checksum offload is not supported by port %u\n",
4779 					res->port_id);
4780 			}
4781 		}
4782 
4783 		if (hw) {
4784 			ports[res->port_id].dev_conf.txmode.offloads |=
4785 							csum_offloads;
4786 		} else {
4787 			ports[res->port_id].dev_conf.txmode.offloads &=
4788 							(~csum_offloads);
4789 		}
4790 		cmd_config_queue_tx_offloads(&ports[res->port_id]);
4791 	}
4792 	csum_show(res->port_id);
4793 
4794 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4795 }
4796 
4797 cmdline_parse_token_string_t cmd_csum_csum =
4798 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4799 				csum, "csum");
4800 cmdline_parse_token_string_t cmd_csum_mode =
4801 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4802 				mode, "set");
4803 cmdline_parse_token_string_t cmd_csum_proto =
4804 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4805 				proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4806 cmdline_parse_token_string_t cmd_csum_hwsw =
4807 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4808 				hwsw, "hw#sw");
4809 cmdline_parse_token_num_t cmd_csum_portid =
4810 	TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4811 				port_id, RTE_UINT16);
4812 
4813 cmdline_parse_inst_t cmd_csum_set = {
4814 	.f = cmd_csum_parsed,
4815 	.data = NULL,
4816 	.help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4817 		"Enable/Disable hardware calculation of L3/L4 checksum when "
4818 		"using csum forward engine",
4819 	.tokens = {
4820 		(void *)&cmd_csum_csum,
4821 		(void *)&cmd_csum_mode,
4822 		(void *)&cmd_csum_proto,
4823 		(void *)&cmd_csum_hwsw,
4824 		(void *)&cmd_csum_portid,
4825 		NULL,
4826 	},
4827 };
4828 
4829 cmdline_parse_token_string_t cmd_csum_mode_show =
4830 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4831 				mode, "show");
4832 
4833 cmdline_parse_inst_t cmd_csum_show = {
4834 	.f = cmd_csum_parsed,
4835 	.data = NULL,
4836 	.help_str = "csum show <port_id>: Show checksum offload configuration",
4837 	.tokens = {
4838 		(void *)&cmd_csum_csum,
4839 		(void *)&cmd_csum_mode_show,
4840 		(void *)&cmd_csum_portid,
4841 		NULL,
4842 	},
4843 };
4844 
4845 /* Enable/disable tunnel parsing */
4846 struct cmd_csum_tunnel_result {
4847 	cmdline_fixed_string_t csum;
4848 	cmdline_fixed_string_t parse;
4849 	cmdline_fixed_string_t onoff;
4850 	portid_t port_id;
4851 };
4852 
4853 static void
4854 cmd_csum_tunnel_parsed(void *parsed_result,
4855 		       __rte_unused struct cmdline *cl,
4856 		       __rte_unused void *data)
4857 {
4858 	struct cmd_csum_tunnel_result *res = parsed_result;
4859 
4860 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4861 		return;
4862 
4863 	if (!strcmp(res->onoff, "on"))
4864 		ports[res->port_id].parse_tunnel = 1;
4865 	else
4866 		ports[res->port_id].parse_tunnel = 0;
4867 
4868 	csum_show(res->port_id);
4869 }
4870 
4871 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4872 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4873 				csum, "csum");
4874 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4875 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4876 				parse, "parse-tunnel");
4877 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4878 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4879 				onoff, "on#off");
4880 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4881 	TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4882 				port_id, RTE_UINT16);
4883 
4884 cmdline_parse_inst_t cmd_csum_tunnel = {
4885 	.f = cmd_csum_tunnel_parsed,
4886 	.data = NULL,
4887 	.help_str = "csum parse-tunnel on|off <port_id>: "
4888 		"Enable/Disable parsing of tunnels for csum engine",
4889 	.tokens = {
4890 		(void *)&cmd_csum_tunnel_csum,
4891 		(void *)&cmd_csum_tunnel_parse,
4892 		(void *)&cmd_csum_tunnel_onoff,
4893 		(void *)&cmd_csum_tunnel_portid,
4894 		NULL,
4895 	},
4896 };
4897 
4898 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4899 struct cmd_tso_set_result {
4900 	cmdline_fixed_string_t tso;
4901 	cmdline_fixed_string_t mode;
4902 	uint16_t tso_segsz;
4903 	portid_t port_id;
4904 };
4905 
4906 static void
4907 cmd_tso_set_parsed(void *parsed_result,
4908 		       __rte_unused struct cmdline *cl,
4909 		       __rte_unused void *data)
4910 {
4911 	struct cmd_tso_set_result *res = parsed_result;
4912 	struct rte_eth_dev_info dev_info;
4913 	int ret;
4914 
4915 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4916 		return;
4917 	if (!port_is_stopped(res->port_id)) {
4918 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
4919 		return;
4920 	}
4921 
4922 	if (!strcmp(res->mode, "set"))
4923 		ports[res->port_id].tso_segsz = res->tso_segsz;
4924 
4925 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4926 	if (ret != 0)
4927 		return;
4928 
4929 	if ((ports[res->port_id].tso_segsz != 0) &&
4930 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4931 		fprintf(stderr, "Error: TSO is not supported by port %d\n",
4932 			res->port_id);
4933 		return;
4934 	}
4935 
4936 	if (ports[res->port_id].tso_segsz == 0) {
4937 		ports[res->port_id].dev_conf.txmode.offloads &=
4938 						~RTE_ETH_TX_OFFLOAD_TCP_TSO;
4939 		printf("TSO for non-tunneled packets is disabled\n");
4940 	} else {
4941 		ports[res->port_id].dev_conf.txmode.offloads |=
4942 						RTE_ETH_TX_OFFLOAD_TCP_TSO;
4943 		printf("TSO segment size for non-tunneled packets is %d\n",
4944 			ports[res->port_id].tso_segsz);
4945 	}
4946 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
4947 
4948 	/* display warnings if configuration is not supported by the NIC */
4949 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4950 	if (ret != 0)
4951 		return;
4952 
4953 	if ((ports[res->port_id].tso_segsz != 0) &&
4954 		(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4955 		fprintf(stderr,
4956 			"Warning: TSO enabled but not supported by port %d\n",
4957 			res->port_id);
4958 	}
4959 
4960 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4961 }
4962 
4963 cmdline_parse_token_string_t cmd_tso_set_tso =
4964 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4965 				tso, "tso");
4966 cmdline_parse_token_string_t cmd_tso_set_mode =
4967 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4968 				mode, "set");
4969 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4970 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4971 				tso_segsz, RTE_UINT16);
4972 cmdline_parse_token_num_t cmd_tso_set_portid =
4973 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4974 				port_id, RTE_UINT16);
4975 
4976 cmdline_parse_inst_t cmd_tso_set = {
4977 	.f = cmd_tso_set_parsed,
4978 	.data = NULL,
4979 	.help_str = "tso set <tso_segsz> <port_id>: "
4980 		"Set TSO segment size of non-tunneled packets for csum engine "
4981 		"(0 to disable)",
4982 	.tokens = {
4983 		(void *)&cmd_tso_set_tso,
4984 		(void *)&cmd_tso_set_mode,
4985 		(void *)&cmd_tso_set_tso_segsz,
4986 		(void *)&cmd_tso_set_portid,
4987 		NULL,
4988 	},
4989 };
4990 
4991 cmdline_parse_token_string_t cmd_tso_show_mode =
4992 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4993 				mode, "show");
4994 
4995 
4996 cmdline_parse_inst_t cmd_tso_show = {
4997 	.f = cmd_tso_set_parsed,
4998 	.data = NULL,
4999 	.help_str = "tso show <port_id>: "
5000 		"Show TSO segment size of non-tunneled packets for csum engine",
5001 	.tokens = {
5002 		(void *)&cmd_tso_set_tso,
5003 		(void *)&cmd_tso_show_mode,
5004 		(void *)&cmd_tso_set_portid,
5005 		NULL,
5006 	},
5007 };
5008 
5009 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5010 struct cmd_tunnel_tso_set_result {
5011 	cmdline_fixed_string_t tso;
5012 	cmdline_fixed_string_t mode;
5013 	uint16_t tso_segsz;
5014 	portid_t port_id;
5015 };
5016 
5017 static struct rte_eth_dev_info
5018 check_tunnel_tso_nic_support(portid_t port_id)
5019 {
5020 	struct rte_eth_dev_info dev_info;
5021 
5022 	if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5023 		return dev_info;
5024 
5025 	if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO))
5026 		fprintf(stderr,
5027 			"Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n",
5028 			port_id);
5029 	if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO))
5030 		fprintf(stderr,
5031 			"Warning: GRE 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_IPIP_TNL_TSO))
5034 		fprintf(stderr,
5035 			"Warning: IPIP 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_GENEVE_TNL_TSO))
5038 		fprintf(stderr,
5039 			"Warning: GENEVE 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_IP_TNL_TSO))
5042 		fprintf(stderr,
5043 			"Warning: IP 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_UDP_TNL_TSO))
5046 		fprintf(stderr,
5047 			"Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n",
5048 			port_id);
5049 	return dev_info;
5050 }
5051 
5052 static void
5053 cmd_tunnel_tso_set_parsed(void *parsed_result,
5054 			  __rte_unused struct cmdline *cl,
5055 			  __rte_unused void *data)
5056 {
5057 	struct cmd_tunnel_tso_set_result *res = parsed_result;
5058 	struct rte_eth_dev_info dev_info;
5059 
5060 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5061 		return;
5062 	if (!port_is_stopped(res->port_id)) {
5063 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
5064 		return;
5065 	}
5066 
5067 	if (!strcmp(res->mode, "set"))
5068 		ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5069 
5070 	dev_info = check_tunnel_tso_nic_support(res->port_id);
5071 	if (ports[res->port_id].tunnel_tso_segsz == 0) {
5072 		ports[res->port_id].dev_conf.txmode.offloads &=
5073 			~(RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5074 			  RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5075 			  RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5076 			  RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5077 			  RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5078 			  RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5079 		printf("TSO for tunneled packets is disabled\n");
5080 	} else {
5081 		uint64_t tso_offloads = (RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5082 					 RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5083 					 RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5084 					 RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5085 					 RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5086 					 RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5087 
5088 		ports[res->port_id].dev_conf.txmode.offloads |=
5089 			(tso_offloads & dev_info.tx_offload_capa);
5090 		printf("TSO segment size for tunneled packets is %d\n",
5091 			ports[res->port_id].tunnel_tso_segsz);
5092 
5093 		/* Below conditions are needed to make it work:
5094 		 * (1) tunnel TSO is supported by the NIC;
5095 		 * (2) "csum parse_tunnel" must be set so that tunneled pkts
5096 		 * are recognized;
5097 		 * (3) for tunneled pkts with outer L3 of IPv4,
5098 		 * "csum set outer-ip" must be set to hw, because after tso,
5099 		 * total_len of outer IP header is changed, and the checksum
5100 		 * of outer IP header calculated by sw should be wrong; that
5101 		 * is not necessary for IPv6 tunneled pkts because there's no
5102 		 * checksum in IP header anymore.
5103 		 */
5104 
5105 		if (!ports[res->port_id].parse_tunnel)
5106 			fprintf(stderr,
5107 				"Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n");
5108 		if (!(ports[res->port_id].dev_conf.txmode.offloads &
5109 		      RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5110 			fprintf(stderr,
5111 				"Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n");
5112 	}
5113 
5114 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
5115 	cmd_reconfig_device_queue(res->port_id, 1, 1);
5116 }
5117 
5118 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5119 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5120 				tso, "tunnel_tso");
5121 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5122 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5123 				mode, "set");
5124 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5125 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5126 				tso_segsz, RTE_UINT16);
5127 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5128 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5129 				port_id, RTE_UINT16);
5130 
5131 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5132 	.f = cmd_tunnel_tso_set_parsed,
5133 	.data = NULL,
5134 	.help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5135 		"Set TSO segment size of tunneled packets for csum engine "
5136 		"(0 to disable)",
5137 	.tokens = {
5138 		(void *)&cmd_tunnel_tso_set_tso,
5139 		(void *)&cmd_tunnel_tso_set_mode,
5140 		(void *)&cmd_tunnel_tso_set_tso_segsz,
5141 		(void *)&cmd_tunnel_tso_set_portid,
5142 		NULL,
5143 	},
5144 };
5145 
5146 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5147 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5148 				mode, "show");
5149 
5150 
5151 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5152 	.f = cmd_tunnel_tso_set_parsed,
5153 	.data = NULL,
5154 	.help_str = "tunnel_tso show <port_id> "
5155 		"Show TSO segment size of tunneled packets for csum engine",
5156 	.tokens = {
5157 		(void *)&cmd_tunnel_tso_set_tso,
5158 		(void *)&cmd_tunnel_tso_show_mode,
5159 		(void *)&cmd_tunnel_tso_set_portid,
5160 		NULL,
5161 	},
5162 };
5163 
5164 #ifdef RTE_LIB_GRO
5165 /* *** SET GRO FOR A PORT *** */
5166 struct cmd_gro_enable_result {
5167 	cmdline_fixed_string_t cmd_set;
5168 	cmdline_fixed_string_t cmd_port;
5169 	cmdline_fixed_string_t cmd_keyword;
5170 	cmdline_fixed_string_t cmd_onoff;
5171 	portid_t cmd_pid;
5172 };
5173 
5174 static void
5175 cmd_gro_enable_parsed(void *parsed_result,
5176 		__rte_unused struct cmdline *cl,
5177 		__rte_unused void *data)
5178 {
5179 	struct cmd_gro_enable_result *res;
5180 
5181 	res = parsed_result;
5182 	if (!strcmp(res->cmd_keyword, "gro"))
5183 		setup_gro(res->cmd_onoff, res->cmd_pid);
5184 }
5185 
5186 cmdline_parse_token_string_t cmd_gro_enable_set =
5187 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5188 			cmd_set, "set");
5189 cmdline_parse_token_string_t cmd_gro_enable_port =
5190 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5191 			cmd_keyword, "port");
5192 cmdline_parse_token_num_t cmd_gro_enable_pid =
5193 	TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5194 			cmd_pid, RTE_UINT16);
5195 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5196 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5197 			cmd_keyword, "gro");
5198 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5199 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5200 			cmd_onoff, "on#off");
5201 
5202 cmdline_parse_inst_t cmd_gro_enable = {
5203 	.f = cmd_gro_enable_parsed,
5204 	.data = NULL,
5205 	.help_str = "set port <port_id> gro on|off",
5206 	.tokens = {
5207 		(void *)&cmd_gro_enable_set,
5208 		(void *)&cmd_gro_enable_port,
5209 		(void *)&cmd_gro_enable_pid,
5210 		(void *)&cmd_gro_enable_keyword,
5211 		(void *)&cmd_gro_enable_onoff,
5212 		NULL,
5213 	},
5214 };
5215 
5216 /* *** DISPLAY GRO CONFIGURATION *** */
5217 struct cmd_gro_show_result {
5218 	cmdline_fixed_string_t cmd_show;
5219 	cmdline_fixed_string_t cmd_port;
5220 	cmdline_fixed_string_t cmd_keyword;
5221 	portid_t cmd_pid;
5222 };
5223 
5224 static void
5225 cmd_gro_show_parsed(void *parsed_result,
5226 		__rte_unused struct cmdline *cl,
5227 		__rte_unused void *data)
5228 {
5229 	struct cmd_gro_show_result *res;
5230 
5231 	res = parsed_result;
5232 	if (!strcmp(res->cmd_keyword, "gro"))
5233 		show_gro(res->cmd_pid);
5234 }
5235 
5236 cmdline_parse_token_string_t cmd_gro_show_show =
5237 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5238 			cmd_show, "show");
5239 cmdline_parse_token_string_t cmd_gro_show_port =
5240 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5241 			cmd_port, "port");
5242 cmdline_parse_token_num_t cmd_gro_show_pid =
5243 	TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5244 			cmd_pid, RTE_UINT16);
5245 cmdline_parse_token_string_t cmd_gro_show_keyword =
5246 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5247 			cmd_keyword, "gro");
5248 
5249 cmdline_parse_inst_t cmd_gro_show = {
5250 	.f = cmd_gro_show_parsed,
5251 	.data = NULL,
5252 	.help_str = "show port <port_id> gro",
5253 	.tokens = {
5254 		(void *)&cmd_gro_show_show,
5255 		(void *)&cmd_gro_show_port,
5256 		(void *)&cmd_gro_show_pid,
5257 		(void *)&cmd_gro_show_keyword,
5258 		NULL,
5259 	},
5260 };
5261 
5262 /* *** SET FLUSH CYCLES FOR GRO *** */
5263 struct cmd_gro_flush_result {
5264 	cmdline_fixed_string_t cmd_set;
5265 	cmdline_fixed_string_t cmd_keyword;
5266 	cmdline_fixed_string_t cmd_flush;
5267 	uint8_t cmd_cycles;
5268 };
5269 
5270 static void
5271 cmd_gro_flush_parsed(void *parsed_result,
5272 		__rte_unused struct cmdline *cl,
5273 		__rte_unused void *data)
5274 {
5275 	struct cmd_gro_flush_result *res;
5276 
5277 	res = parsed_result;
5278 	if ((!strcmp(res->cmd_keyword, "gro")) &&
5279 			(!strcmp(res->cmd_flush, "flush")))
5280 		setup_gro_flush_cycles(res->cmd_cycles);
5281 }
5282 
5283 cmdline_parse_token_string_t cmd_gro_flush_set =
5284 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5285 			cmd_set, "set");
5286 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5287 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5288 			cmd_keyword, "gro");
5289 cmdline_parse_token_string_t cmd_gro_flush_flush =
5290 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5291 			cmd_flush, "flush");
5292 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5293 	TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5294 			cmd_cycles, RTE_UINT8);
5295 
5296 cmdline_parse_inst_t cmd_gro_flush = {
5297 	.f = cmd_gro_flush_parsed,
5298 	.data = NULL,
5299 	.help_str = "set gro flush <cycles>",
5300 	.tokens = {
5301 		(void *)&cmd_gro_flush_set,
5302 		(void *)&cmd_gro_flush_keyword,
5303 		(void *)&cmd_gro_flush_flush,
5304 		(void *)&cmd_gro_flush_cycles,
5305 		NULL,
5306 	},
5307 };
5308 #endif /* RTE_LIB_GRO */
5309 
5310 #ifdef RTE_LIB_GSO
5311 /* *** ENABLE/DISABLE GSO *** */
5312 struct cmd_gso_enable_result {
5313 	cmdline_fixed_string_t cmd_set;
5314 	cmdline_fixed_string_t cmd_port;
5315 	cmdline_fixed_string_t cmd_keyword;
5316 	cmdline_fixed_string_t cmd_mode;
5317 	portid_t cmd_pid;
5318 };
5319 
5320 static void
5321 cmd_gso_enable_parsed(void *parsed_result,
5322 		__rte_unused struct cmdline *cl,
5323 		__rte_unused void *data)
5324 {
5325 	struct cmd_gso_enable_result *res;
5326 
5327 	res = parsed_result;
5328 	if (!strcmp(res->cmd_keyword, "gso"))
5329 		setup_gso(res->cmd_mode, res->cmd_pid);
5330 }
5331 
5332 cmdline_parse_token_string_t cmd_gso_enable_set =
5333 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5334 			cmd_set, "set");
5335 cmdline_parse_token_string_t cmd_gso_enable_port =
5336 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5337 			cmd_port, "port");
5338 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5339 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5340 			cmd_keyword, "gso");
5341 cmdline_parse_token_string_t cmd_gso_enable_mode =
5342 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5343 			cmd_mode, "on#off");
5344 cmdline_parse_token_num_t cmd_gso_enable_pid =
5345 	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5346 			cmd_pid, RTE_UINT16);
5347 
5348 cmdline_parse_inst_t cmd_gso_enable = {
5349 	.f = cmd_gso_enable_parsed,
5350 	.data = NULL,
5351 	.help_str = "set port <port_id> gso on|off",
5352 	.tokens = {
5353 		(void *)&cmd_gso_enable_set,
5354 		(void *)&cmd_gso_enable_port,
5355 		(void *)&cmd_gso_enable_pid,
5356 		(void *)&cmd_gso_enable_keyword,
5357 		(void *)&cmd_gso_enable_mode,
5358 		NULL,
5359 	},
5360 };
5361 
5362 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5363 struct cmd_gso_size_result {
5364 	cmdline_fixed_string_t cmd_set;
5365 	cmdline_fixed_string_t cmd_keyword;
5366 	cmdline_fixed_string_t cmd_segsz;
5367 	uint16_t cmd_size;
5368 };
5369 
5370 static void
5371 cmd_gso_size_parsed(void *parsed_result,
5372 		       __rte_unused struct cmdline *cl,
5373 		       __rte_unused void *data)
5374 {
5375 	struct cmd_gso_size_result *res = parsed_result;
5376 
5377 	if (test_done == 0) {
5378 		fprintf(stderr,
5379 			"Before setting GSO segsz, please first stop forwarding\n");
5380 		return;
5381 	}
5382 
5383 	if (!strcmp(res->cmd_keyword, "gso") &&
5384 			!strcmp(res->cmd_segsz, "segsz")) {
5385 		if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5386 			fprintf(stderr,
5387 				"gso_size should be larger than %zu. Please input a legal value\n",
5388 				RTE_GSO_SEG_SIZE_MIN);
5389 		else
5390 			gso_max_segment_size = res->cmd_size;
5391 	}
5392 }
5393 
5394 cmdline_parse_token_string_t cmd_gso_size_set =
5395 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5396 				cmd_set, "set");
5397 cmdline_parse_token_string_t cmd_gso_size_keyword =
5398 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5399 				cmd_keyword, "gso");
5400 cmdline_parse_token_string_t cmd_gso_size_segsz =
5401 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5402 				cmd_segsz, "segsz");
5403 cmdline_parse_token_num_t cmd_gso_size_size =
5404 	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5405 				cmd_size, RTE_UINT16);
5406 
5407 cmdline_parse_inst_t cmd_gso_size = {
5408 	.f = cmd_gso_size_parsed,
5409 	.data = NULL,
5410 	.help_str = "set gso segsz <length>",
5411 	.tokens = {
5412 		(void *)&cmd_gso_size_set,
5413 		(void *)&cmd_gso_size_keyword,
5414 		(void *)&cmd_gso_size_segsz,
5415 		(void *)&cmd_gso_size_size,
5416 		NULL,
5417 	},
5418 };
5419 
5420 /* *** SHOW GSO CONFIGURATION *** */
5421 struct cmd_gso_show_result {
5422 	cmdline_fixed_string_t cmd_show;
5423 	cmdline_fixed_string_t cmd_port;
5424 	cmdline_fixed_string_t cmd_keyword;
5425 	portid_t cmd_pid;
5426 };
5427 
5428 static void
5429 cmd_gso_show_parsed(void *parsed_result,
5430 		       __rte_unused struct cmdline *cl,
5431 		       __rte_unused void *data)
5432 {
5433 	struct cmd_gso_show_result *res = parsed_result;
5434 
5435 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5436 		fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
5437 		return;
5438 	}
5439 	if (!strcmp(res->cmd_keyword, "gso")) {
5440 		if (gso_ports[res->cmd_pid].enable) {
5441 			printf("Max GSO'd packet size: %uB\n"
5442 					"Supported GSO types: TCP/IPv4, "
5443 					"UDP/IPv4, VxLAN with inner "
5444 					"TCP/IPv4 packet, GRE with inner "
5445 					"TCP/IPv4 packet\n",
5446 					gso_max_segment_size);
5447 		} else
5448 			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5449 	}
5450 }
5451 
5452 cmdline_parse_token_string_t cmd_gso_show_show =
5453 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5454 		cmd_show, "show");
5455 cmdline_parse_token_string_t cmd_gso_show_port =
5456 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5457 		cmd_port, "port");
5458 cmdline_parse_token_string_t cmd_gso_show_keyword =
5459 	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5460 				cmd_keyword, "gso");
5461 cmdline_parse_token_num_t cmd_gso_show_pid =
5462 	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5463 				cmd_pid, RTE_UINT16);
5464 
5465 cmdline_parse_inst_t cmd_gso_show = {
5466 	.f = cmd_gso_show_parsed,
5467 	.data = NULL,
5468 	.help_str = "show port <port_id> gso",
5469 	.tokens = {
5470 		(void *)&cmd_gso_show_show,
5471 		(void *)&cmd_gso_show_port,
5472 		(void *)&cmd_gso_show_pid,
5473 		(void *)&cmd_gso_show_keyword,
5474 		NULL,
5475 	},
5476 };
5477 #endif /* RTE_LIB_GSO */
5478 
5479 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5480 struct cmd_set_flush_rx {
5481 	cmdline_fixed_string_t set;
5482 	cmdline_fixed_string_t flush_rx;
5483 	cmdline_fixed_string_t mode;
5484 };
5485 
5486 static void
5487 cmd_set_flush_rx_parsed(void *parsed_result,
5488 		__rte_unused struct cmdline *cl,
5489 		__rte_unused void *data)
5490 {
5491 	struct cmd_set_flush_rx *res = parsed_result;
5492 
5493 	if (num_procs > 1 && (strcmp(res->mode, "on") == 0)) {
5494 		printf("multi-process doesn't support to flush Rx queues.\n");
5495 		return;
5496 	}
5497 
5498 	no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5499 }
5500 
5501 cmdline_parse_token_string_t cmd_setflushrx_set =
5502 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5503 			set, "set");
5504 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5505 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5506 			flush_rx, "flush_rx");
5507 cmdline_parse_token_string_t cmd_setflushrx_mode =
5508 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5509 			mode, "on#off");
5510 
5511 
5512 cmdline_parse_inst_t cmd_set_flush_rx = {
5513 	.f = cmd_set_flush_rx_parsed,
5514 	.help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5515 	.data = NULL,
5516 	.tokens = {
5517 		(void *)&cmd_setflushrx_set,
5518 		(void *)&cmd_setflushrx_flush_rx,
5519 		(void *)&cmd_setflushrx_mode,
5520 		NULL,
5521 	},
5522 };
5523 
5524 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5525 struct cmd_set_link_check {
5526 	cmdline_fixed_string_t set;
5527 	cmdline_fixed_string_t link_check;
5528 	cmdline_fixed_string_t mode;
5529 };
5530 
5531 static void
5532 cmd_set_link_check_parsed(void *parsed_result,
5533 		__rte_unused struct cmdline *cl,
5534 		__rte_unused void *data)
5535 {
5536 	struct cmd_set_link_check *res = parsed_result;
5537 	no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5538 }
5539 
5540 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5541 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5542 			set, "set");
5543 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5544 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5545 			link_check, "link_check");
5546 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5547 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5548 			mode, "on#off");
5549 
5550 
5551 cmdline_parse_inst_t cmd_set_link_check = {
5552 	.f = cmd_set_link_check_parsed,
5553 	.help_str = "set link_check on|off: Enable/Disable link status check "
5554 	            "when starting/stopping a port",
5555 	.data = NULL,
5556 	.tokens = {
5557 		(void *)&cmd_setlinkcheck_set,
5558 		(void *)&cmd_setlinkcheck_link_check,
5559 		(void *)&cmd_setlinkcheck_mode,
5560 		NULL,
5561 	},
5562 };
5563 
5564 /* *** SET NIC BYPASS MODE *** */
5565 struct cmd_set_bypass_mode_result {
5566 	cmdline_fixed_string_t set;
5567 	cmdline_fixed_string_t bypass;
5568 	cmdline_fixed_string_t mode;
5569 	cmdline_fixed_string_t value;
5570 	portid_t port_id;
5571 };
5572 
5573 static void
5574 cmd_set_bypass_mode_parsed(void *parsed_result,
5575 		__rte_unused struct cmdline *cl,
5576 		__rte_unused void *data)
5577 {
5578 	struct cmd_set_bypass_mode_result *res = parsed_result;
5579 	portid_t port_id = res->port_id;
5580 	int32_t rc = -EINVAL;
5581 
5582 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5583 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5584 
5585 	if (!strcmp(res->value, "bypass"))
5586 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5587 	else if (!strcmp(res->value, "isolate"))
5588 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5589 	else
5590 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5591 
5592 	/* Set the bypass mode for the relevant port. */
5593 	rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5594 #endif
5595 	if (rc != 0)
5596 		fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n",
5597 			port_id);
5598 }
5599 
5600 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5601 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5602 			set, "set");
5603 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5604 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5605 			bypass, "bypass");
5606 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5607 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5608 			mode, "mode");
5609 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5610 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5611 			value, "normal#bypass#isolate");
5612 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5613 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5614 				port_id, RTE_UINT16);
5615 
5616 cmdline_parse_inst_t cmd_set_bypass_mode = {
5617 	.f = cmd_set_bypass_mode_parsed,
5618 	.help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5619 	            "Set the NIC bypass mode for port_id",
5620 	.data = NULL,
5621 	.tokens = {
5622 		(void *)&cmd_setbypass_mode_set,
5623 		(void *)&cmd_setbypass_mode_bypass,
5624 		(void *)&cmd_setbypass_mode_mode,
5625 		(void *)&cmd_setbypass_mode_value,
5626 		(void *)&cmd_setbypass_mode_port,
5627 		NULL,
5628 	},
5629 };
5630 
5631 /* *** SET NIC BYPASS EVENT *** */
5632 struct cmd_set_bypass_event_result {
5633 	cmdline_fixed_string_t set;
5634 	cmdline_fixed_string_t bypass;
5635 	cmdline_fixed_string_t event;
5636 	cmdline_fixed_string_t event_value;
5637 	cmdline_fixed_string_t mode;
5638 	cmdline_fixed_string_t mode_value;
5639 	portid_t port_id;
5640 };
5641 
5642 static void
5643 cmd_set_bypass_event_parsed(void *parsed_result,
5644 		__rte_unused struct cmdline *cl,
5645 		__rte_unused void *data)
5646 {
5647 	int32_t rc = -EINVAL;
5648 	struct cmd_set_bypass_event_result *res = parsed_result;
5649 	portid_t port_id = res->port_id;
5650 
5651 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5652 	uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5653 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5654 
5655 	if (!strcmp(res->event_value, "timeout"))
5656 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5657 	else if (!strcmp(res->event_value, "os_on"))
5658 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5659 	else if (!strcmp(res->event_value, "os_off"))
5660 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5661 	else if (!strcmp(res->event_value, "power_on"))
5662 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5663 	else if (!strcmp(res->event_value, "power_off"))
5664 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5665 	else
5666 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5667 
5668 	if (!strcmp(res->mode_value, "bypass"))
5669 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5670 	else if (!strcmp(res->mode_value, "isolate"))
5671 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5672 	else
5673 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5674 
5675 	/* Set the watchdog timeout. */
5676 	if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5677 
5678 		rc = -EINVAL;
5679 		if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5680 			rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5681 							   bypass_timeout);
5682 		}
5683 		if (rc != 0) {
5684 			fprintf(stderr,
5685 				"Failed to set timeout value %u for port %d, errto code: %d.\n",
5686 				bypass_timeout, port_id, rc);
5687 		}
5688 	}
5689 
5690 	/* Set the bypass event to transition to bypass mode. */
5691 	rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5692 					      bypass_mode);
5693 #endif
5694 
5695 	if (rc != 0)
5696 		fprintf(stderr, "\t Failed to set bypass event for port = %d.\n",
5697 			port_id);
5698 }
5699 
5700 cmdline_parse_token_string_t cmd_setbypass_event_set =
5701 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5702 			set, "set");
5703 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5704 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5705 			bypass, "bypass");
5706 cmdline_parse_token_string_t cmd_setbypass_event_event =
5707 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5708 			event, "event");
5709 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5710 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5711 			event_value, "none#timeout#os_off#os_on#power_on#power_off");
5712 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5713 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5714 			mode, "mode");
5715 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5716 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5717 			mode_value, "normal#bypass#isolate");
5718 cmdline_parse_token_num_t cmd_setbypass_event_port =
5719 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5720 				port_id, RTE_UINT16);
5721 
5722 cmdline_parse_inst_t cmd_set_bypass_event = {
5723 	.f = cmd_set_bypass_event_parsed,
5724 	.help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5725 		"power_off mode normal|bypass|isolate <port_id>: "
5726 		"Set the NIC bypass event mode for port_id",
5727 	.data = NULL,
5728 	.tokens = {
5729 		(void *)&cmd_setbypass_event_set,
5730 		(void *)&cmd_setbypass_event_bypass,
5731 		(void *)&cmd_setbypass_event_event,
5732 		(void *)&cmd_setbypass_event_event_value,
5733 		(void *)&cmd_setbypass_event_mode,
5734 		(void *)&cmd_setbypass_event_mode_value,
5735 		(void *)&cmd_setbypass_event_port,
5736 		NULL,
5737 	},
5738 };
5739 
5740 
5741 /* *** SET NIC BYPASS TIMEOUT *** */
5742 struct cmd_set_bypass_timeout_result {
5743 	cmdline_fixed_string_t set;
5744 	cmdline_fixed_string_t bypass;
5745 	cmdline_fixed_string_t timeout;
5746 	cmdline_fixed_string_t value;
5747 };
5748 
5749 static void
5750 cmd_set_bypass_timeout_parsed(void *parsed_result,
5751 		__rte_unused struct cmdline *cl,
5752 		__rte_unused void *data)
5753 {
5754 	__rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5755 
5756 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5757 	if (!strcmp(res->value, "1.5"))
5758 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5759 	else if (!strcmp(res->value, "2"))
5760 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5761 	else if (!strcmp(res->value, "3"))
5762 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5763 	else if (!strcmp(res->value, "4"))
5764 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5765 	else if (!strcmp(res->value, "8"))
5766 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5767 	else if (!strcmp(res->value, "16"))
5768 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5769 	else if (!strcmp(res->value, "32"))
5770 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5771 	else
5772 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5773 #endif
5774 }
5775 
5776 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5777 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5778 			set, "set");
5779 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5780 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5781 			bypass, "bypass");
5782 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5783 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5784 			timeout, "timeout");
5785 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5786 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5787 			value, "0#1.5#2#3#4#8#16#32");
5788 
5789 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5790 	.f = cmd_set_bypass_timeout_parsed,
5791 	.help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5792 		"Set the NIC bypass watchdog timeout in seconds",
5793 	.data = NULL,
5794 	.tokens = {
5795 		(void *)&cmd_setbypass_timeout_set,
5796 		(void *)&cmd_setbypass_timeout_bypass,
5797 		(void *)&cmd_setbypass_timeout_timeout,
5798 		(void *)&cmd_setbypass_timeout_value,
5799 		NULL,
5800 	},
5801 };
5802 
5803 /* *** SHOW NIC BYPASS MODE *** */
5804 struct cmd_show_bypass_config_result {
5805 	cmdline_fixed_string_t show;
5806 	cmdline_fixed_string_t bypass;
5807 	cmdline_fixed_string_t config;
5808 	portid_t port_id;
5809 };
5810 
5811 static void
5812 cmd_show_bypass_config_parsed(void *parsed_result,
5813 		__rte_unused struct cmdline *cl,
5814 		__rte_unused void *data)
5815 {
5816 	struct cmd_show_bypass_config_result *res = parsed_result;
5817 	portid_t port_id = res->port_id;
5818 	int rc = -EINVAL;
5819 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5820 	uint32_t event_mode;
5821 	uint32_t bypass_mode;
5822 	uint32_t timeout = bypass_timeout;
5823 	unsigned int i;
5824 
5825 	static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5826 		{"off", "1.5", "2", "3", "4", "8", "16", "32"};
5827 	static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5828 		{"UNKNOWN", "normal", "bypass", "isolate"};
5829 	static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5830 		"NONE",
5831 		"OS/board on",
5832 		"power supply on",
5833 		"OS/board off",
5834 		"power supply off",
5835 		"timeout"};
5836 
5837 	/* Display the bypass mode.*/
5838 	if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5839 		fprintf(stderr, "\tFailed to get bypass mode for port = %d\n",
5840 			port_id);
5841 		return;
5842 	}
5843 	else {
5844 		if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5845 			bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5846 
5847 		printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5848 	}
5849 
5850 	/* Display the bypass timeout.*/
5851 	if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5852 		timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5853 
5854 	printf("\tbypass timeout = %s\n", timeouts[timeout]);
5855 
5856 	/* Display the bypass events and associated modes. */
5857 	for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5858 
5859 		if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5860 			fprintf(stderr,
5861 				"\tFailed to get bypass mode for event = %s\n",
5862 				events[i]);
5863 		} else {
5864 			if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5865 				event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5866 
5867 			printf("\tbypass event: %-16s = %s\n", events[i],
5868 				modes[event_mode]);
5869 		}
5870 	}
5871 #endif
5872 	if (rc != 0)
5873 		fprintf(stderr,
5874 			"\tFailed to get bypass configuration for port = %d\n",
5875 		       port_id);
5876 }
5877 
5878 cmdline_parse_token_string_t cmd_showbypass_config_show =
5879 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5880 			show, "show");
5881 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5882 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5883 			bypass, "bypass");
5884 cmdline_parse_token_string_t cmd_showbypass_config_config =
5885 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5886 			config, "config");
5887 cmdline_parse_token_num_t cmd_showbypass_config_port =
5888 	TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5889 				port_id, RTE_UINT16);
5890 
5891 cmdline_parse_inst_t cmd_show_bypass_config = {
5892 	.f = cmd_show_bypass_config_parsed,
5893 	.help_str = "show bypass config <port_id>: "
5894 	            "Show the NIC bypass config for port_id",
5895 	.data = NULL,
5896 	.tokens = {
5897 		(void *)&cmd_showbypass_config_show,
5898 		(void *)&cmd_showbypass_config_bypass,
5899 		(void *)&cmd_showbypass_config_config,
5900 		(void *)&cmd_showbypass_config_port,
5901 		NULL,
5902 	},
5903 };
5904 
5905 #ifdef RTE_NET_BOND
5906 /* *** SET BONDING MODE *** */
5907 struct cmd_set_bonding_mode_result {
5908 	cmdline_fixed_string_t set;
5909 	cmdline_fixed_string_t bonding;
5910 	cmdline_fixed_string_t mode;
5911 	uint8_t value;
5912 	portid_t port_id;
5913 };
5914 
5915 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5916 		__rte_unused  struct cmdline *cl,
5917 		__rte_unused void *data)
5918 {
5919 	struct cmd_set_bonding_mode_result *res = parsed_result;
5920 	portid_t port_id = res->port_id;
5921 	struct rte_port *port = &ports[port_id];
5922 
5923 	/*
5924 	 * Bonding mode changed means resources of device changed, like whether
5925 	 * started rte timer or not. Device should be restarted when resources
5926 	 * of device changed.
5927 	 */
5928 	if (port->port_status != RTE_PORT_STOPPED) {
5929 		fprintf(stderr,
5930 			"\t Error: Can't set bonding mode when port %d is not stopped\n",
5931 			port_id);
5932 		return;
5933 	}
5934 
5935 	/* Set the bonding mode for the relevant port. */
5936 	if (0 != rte_eth_bond_mode_set(port_id, res->value))
5937 		fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
5938 			port_id);
5939 }
5940 
5941 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5942 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5943 		set, "set");
5944 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5945 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5946 		bonding, "bonding");
5947 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5948 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5949 		mode, "mode");
5950 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5951 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5952 		value, RTE_UINT8);
5953 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5954 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5955 		port_id, RTE_UINT16);
5956 
5957 cmdline_parse_inst_t cmd_set_bonding_mode = {
5958 		.f = cmd_set_bonding_mode_parsed,
5959 		.help_str = "set bonding mode <mode_value> <port_id>: "
5960 			"Set the bonding mode for port_id",
5961 		.data = NULL,
5962 		.tokens = {
5963 				(void *) &cmd_setbonding_mode_set,
5964 				(void *) &cmd_setbonding_mode_bonding,
5965 				(void *) &cmd_setbonding_mode_mode,
5966 				(void *) &cmd_setbonding_mode_value,
5967 				(void *) &cmd_setbonding_mode_port,
5968 				NULL
5969 		}
5970 };
5971 
5972 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5973 struct cmd_set_bonding_lacp_dedicated_queues_result {
5974 	cmdline_fixed_string_t set;
5975 	cmdline_fixed_string_t bonding;
5976 	cmdline_fixed_string_t lacp;
5977 	cmdline_fixed_string_t dedicated_queues;
5978 	portid_t port_id;
5979 	cmdline_fixed_string_t mode;
5980 };
5981 
5982 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5983 		__rte_unused  struct cmdline *cl,
5984 		__rte_unused void *data)
5985 {
5986 	struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5987 	portid_t port_id = res->port_id;
5988 	struct rte_port *port;
5989 
5990 	port = &ports[port_id];
5991 
5992 	/** Check if the port is not started **/
5993 	if (port->port_status != RTE_PORT_STOPPED) {
5994 		fprintf(stderr, "Please stop port %d first\n", port_id);
5995 		return;
5996 	}
5997 
5998 	if (!strcmp(res->mode, "enable")) {
5999 		if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
6000 			printf("Dedicate queues for LACP control packets"
6001 					" enabled\n");
6002 		else
6003 			printf("Enabling dedicate queues for LACP control "
6004 					"packets on port %d failed\n", port_id);
6005 	} else if (!strcmp(res->mode, "disable")) {
6006 		if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
6007 			printf("Dedicated queues for LACP control packets "
6008 					"disabled\n");
6009 		else
6010 			printf("Disabling dedicated queues for LACP control "
6011 					"traffic on port %d failed\n", port_id);
6012 	}
6013 }
6014 
6015 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
6016 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6017 		set, "set");
6018 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
6019 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6020 		bonding, "bonding");
6021 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
6022 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6023 		lacp, "lacp");
6024 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
6025 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6026 		dedicated_queues, "dedicated_queues");
6027 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6028 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6029 		port_id, RTE_UINT16);
6030 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6031 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6032 		mode, "enable#disable");
6033 
6034 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6035 		.f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6036 		.help_str = "set bonding lacp dedicated_queues <port_id> "
6037 			"enable|disable: "
6038 			"Enable/disable dedicated queues for LACP control traffic for port_id",
6039 		.data = NULL,
6040 		.tokens = {
6041 			(void *)&cmd_setbonding_lacp_dedicated_queues_set,
6042 			(void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6043 			(void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6044 			(void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6045 			(void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6046 			(void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6047 			NULL
6048 		}
6049 };
6050 
6051 /* *** SET BALANCE XMIT POLICY *** */
6052 struct cmd_set_bonding_balance_xmit_policy_result {
6053 	cmdline_fixed_string_t set;
6054 	cmdline_fixed_string_t bonding;
6055 	cmdline_fixed_string_t balance_xmit_policy;
6056 	portid_t port_id;
6057 	cmdline_fixed_string_t policy;
6058 };
6059 
6060 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6061 		__rte_unused  struct cmdline *cl,
6062 		__rte_unused void *data)
6063 {
6064 	struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6065 	portid_t port_id = res->port_id;
6066 	uint8_t policy;
6067 
6068 	if (!strcmp(res->policy, "l2")) {
6069 		policy = BALANCE_XMIT_POLICY_LAYER2;
6070 	} else if (!strcmp(res->policy, "l23")) {
6071 		policy = BALANCE_XMIT_POLICY_LAYER23;
6072 	} else if (!strcmp(res->policy, "l34")) {
6073 		policy = BALANCE_XMIT_POLICY_LAYER34;
6074 	} else {
6075 		fprintf(stderr, "\t Invalid xmit policy selection");
6076 		return;
6077 	}
6078 
6079 	/* Set the bonding mode for the relevant port. */
6080 	if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6081 		fprintf(stderr,
6082 			"\t Failed to set bonding balance xmit policy for port = %d.\n",
6083 			port_id);
6084 	}
6085 }
6086 
6087 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6088 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6089 		set, "set");
6090 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6091 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6092 		bonding, "bonding");
6093 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6094 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6095 		balance_xmit_policy, "balance_xmit_policy");
6096 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6097 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6098 		port_id, RTE_UINT16);
6099 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6100 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6101 		policy, "l2#l23#l34");
6102 
6103 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6104 		.f = cmd_set_bonding_balance_xmit_policy_parsed,
6105 		.help_str = "set bonding balance_xmit_policy <port_id> "
6106 			"l2|l23|l34: "
6107 			"Set the bonding balance_xmit_policy for port_id",
6108 		.data = NULL,
6109 		.tokens = {
6110 				(void *)&cmd_setbonding_balance_xmit_policy_set,
6111 				(void *)&cmd_setbonding_balance_xmit_policy_bonding,
6112 				(void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6113 				(void *)&cmd_setbonding_balance_xmit_policy_port,
6114 				(void *)&cmd_setbonding_balance_xmit_policy_policy,
6115 				NULL
6116 		}
6117 };
6118 
6119 /* *** SHOW IEEE802.3 BONDING INFORMATION *** */
6120 struct cmd_show_bonding_lacp_info_result {
6121 	cmdline_fixed_string_t show;
6122 	cmdline_fixed_string_t bonding;
6123 	cmdline_fixed_string_t lacp;
6124 	cmdline_fixed_string_t info;
6125 	portid_t port_id;
6126 };
6127 
6128 static void port_param_show(struct port_params *params)
6129 {
6130 	char buf[RTE_ETHER_ADDR_FMT_SIZE];
6131 
6132 	printf("\t\tsystem priority: %u\n", params->system_priority);
6133 	rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &params->system);
6134 	printf("\t\tsystem mac address: %s\n", buf);
6135 	printf("\t\tport key: %u\n", params->key);
6136 	printf("\t\tport priority: %u\n", params->port_priority);
6137 	printf("\t\tport number: %u\n", params->port_number);
6138 }
6139 
6140 static void lacp_slave_info_show(struct rte_eth_bond_8023ad_slave_info *info)
6141 {
6142 	char a_state[256] = { 0 };
6143 	char p_state[256] = { 0 };
6144 	int a_len = 0;
6145 	int p_len = 0;
6146 	uint32_t i;
6147 
6148 	static const char * const state[] = {
6149 		"ACTIVE",
6150 		"TIMEOUT",
6151 		"AGGREGATION",
6152 		"SYNCHRONIZATION",
6153 		"COLLECTING",
6154 		"DISTRIBUTING",
6155 		"DEFAULTED",
6156 		"EXPIRED"
6157 	};
6158 	static const char * const selection[] = {
6159 		"UNSELECTED",
6160 		"STANDBY",
6161 		"SELECTED"
6162 	};
6163 
6164 	for (i = 0; i < RTE_DIM(state); i++) {
6165 		if ((info->actor_state >> i) & 1)
6166 			a_len += snprintf(&a_state[a_len],
6167 						RTE_DIM(a_state) - a_len, "%s ",
6168 						state[i]);
6169 
6170 		if ((info->partner_state >> i) & 1)
6171 			p_len += snprintf(&p_state[p_len],
6172 						RTE_DIM(p_state) - p_len, "%s ",
6173 						state[i]);
6174 	}
6175 	printf("\tAggregator port id: %u\n", info->agg_port_id);
6176 	printf("\tselection: %s\n", selection[info->selected]);
6177 	printf("\tActor detail info:\n");
6178 	port_param_show(&info->actor);
6179 	printf("\t\tport state: %s\n", a_state);
6180 	printf("\tPartner detail info:\n");
6181 	port_param_show(&info->partner);
6182 	printf("\t\tport state: %s\n", p_state);
6183 	printf("\n");
6184 }
6185 
6186 static void lacp_conf_show(struct rte_eth_bond_8023ad_conf *conf)
6187 {
6188 	printf("\tfast period: %u ms\n", conf->fast_periodic_ms);
6189 	printf("\tslow period: %u ms\n", conf->slow_periodic_ms);
6190 	printf("\tshort timeout: %u ms\n", conf->short_timeout_ms);
6191 	printf("\tlong timeout: %u ms\n", conf->long_timeout_ms);
6192 	printf("\taggregate wait timeout: %u ms\n",
6193 			conf->aggregate_wait_timeout_ms);
6194 	printf("\ttx period: %u ms\n", conf->tx_period_ms);
6195 	printf("\trx marker period: %u ms\n", conf->rx_marker_period_ms);
6196 	printf("\tupdate timeout: %u ms\n", conf->update_timeout_ms);
6197 	switch (conf->agg_selection) {
6198 	case AGG_BANDWIDTH:
6199 		printf("\taggregation mode: bandwidth\n");
6200 		break;
6201 	case AGG_STABLE:
6202 		printf("\taggregation mode: stable\n");
6203 		break;
6204 	case AGG_COUNT:
6205 		printf("\taggregation mode: count\n");
6206 		break;
6207 	default:
6208 		printf("\taggregation mode: invalid\n");
6209 		break;
6210 	}
6211 
6212 	printf("\n");
6213 }
6214 
6215 static void cmd_show_bonding_lacp_info_parsed(void *parsed_result,
6216 		__rte_unused  struct cmdline *cl,
6217 		__rte_unused void *data)
6218 {
6219 	struct cmd_show_bonding_lacp_info_result *res = parsed_result;
6220 	struct rte_eth_bond_8023ad_slave_info slave_info;
6221 	struct rte_eth_bond_8023ad_conf port_conf;
6222 	portid_t slaves[RTE_MAX_ETHPORTS];
6223 	portid_t port_id = res->port_id;
6224 	int num_active_slaves;
6225 	int bonding_mode;
6226 	int i;
6227 	int ret;
6228 
6229 	bonding_mode = rte_eth_bond_mode_get(port_id);
6230 	if (bonding_mode != BONDING_MODE_8023AD) {
6231 		fprintf(stderr, "\tBonding mode is not mode 4\n");
6232 		return;
6233 	}
6234 
6235 	num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6236 			RTE_MAX_ETHPORTS);
6237 	if (num_active_slaves < 0) {
6238 		fprintf(stderr, "\tFailed to get active slave list for port = %u\n",
6239 				port_id);
6240 		return;
6241 	}
6242 	if (num_active_slaves == 0)
6243 		fprintf(stderr, "\tIEEE802.3 port %u has no active slave\n",
6244 			port_id);
6245 
6246 	printf("\tIEEE802.3 port: %u\n", port_id);
6247 	ret = rte_eth_bond_8023ad_conf_get(port_id, &port_conf);
6248 	if (ret) {
6249 		fprintf(stderr, "\tGet bonded device %u info failed\n",
6250 			port_id);
6251 		return;
6252 	}
6253 	lacp_conf_show(&port_conf);
6254 
6255 	for (i = 0; i < num_active_slaves; i++) {
6256 		ret = rte_eth_bond_8023ad_slave_info(port_id, slaves[i],
6257 				&slave_info);
6258 		if (ret) {
6259 			fprintf(stderr, "\tGet slave device %u info failed\n",
6260 				slaves[i]);
6261 			return;
6262 		}
6263 		printf("\tSlave Port: %u\n", slaves[i]);
6264 		lacp_slave_info_show(&slave_info);
6265 	}
6266 }
6267 
6268 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_show =
6269 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6270 		show, "show");
6271 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_bonding =
6272 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6273 		bonding, "bonding");
6274 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_lacp =
6275 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6276 		bonding, "lacp");
6277 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_info =
6278 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6279 		info, "info");
6280 cmdline_parse_token_num_t cmd_show_bonding_lacp_info_port_id =
6281 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6282 		port_id, RTE_UINT16);
6283 
6284 cmdline_parse_inst_t cmd_show_bonding_lacp_info = {
6285 		.f = cmd_show_bonding_lacp_info_parsed,
6286 		.help_str = "show bonding lacp info <port_id> : "
6287 			"Show bonding IEEE802.3 information for port_id",
6288 		.data = NULL,
6289 		.tokens = {
6290 			(void *)&cmd_show_bonding_lacp_info_show,
6291 			(void *)&cmd_show_bonding_lacp_info_bonding,
6292 			(void *)&cmd_show_bonding_lacp_info_lacp,
6293 			(void *)&cmd_show_bonding_lacp_info_info,
6294 			(void *)&cmd_show_bonding_lacp_info_port_id,
6295 			NULL
6296 		}
6297 };
6298 
6299 /* *** SHOW NIC BONDING CONFIGURATION *** */
6300 struct cmd_show_bonding_config_result {
6301 	cmdline_fixed_string_t show;
6302 	cmdline_fixed_string_t bonding;
6303 	cmdline_fixed_string_t config;
6304 	portid_t port_id;
6305 };
6306 
6307 static void cmd_show_bonding_config_parsed(void *parsed_result,
6308 		__rte_unused  struct cmdline *cl,
6309 		__rte_unused void *data)
6310 {
6311 	struct cmd_show_bonding_config_result *res = parsed_result;
6312 	int bonding_mode, agg_mode;
6313 	portid_t slaves[RTE_MAX_ETHPORTS];
6314 	int num_slaves, num_active_slaves;
6315 	int primary_id;
6316 	int i;
6317 	portid_t port_id = res->port_id;
6318 
6319 	/* Display the bonding mode.*/
6320 	bonding_mode = rte_eth_bond_mode_get(port_id);
6321 	if (bonding_mode < 0) {
6322 		fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
6323 			port_id);
6324 		return;
6325 	} else
6326 		printf("\tBonding mode: %d\n", bonding_mode);
6327 
6328 	if (bonding_mode == BONDING_MODE_BALANCE ||
6329 		bonding_mode == BONDING_MODE_8023AD) {
6330 		int balance_xmit_policy;
6331 
6332 		balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6333 		if (balance_xmit_policy < 0) {
6334 			fprintf(stderr,
6335 				"\tFailed to get balance xmit policy for port = %d\n",
6336 				port_id);
6337 			return;
6338 		} else {
6339 			printf("\tBalance Xmit Policy: ");
6340 
6341 			switch (balance_xmit_policy) {
6342 			case BALANCE_XMIT_POLICY_LAYER2:
6343 				printf("BALANCE_XMIT_POLICY_LAYER2");
6344 				break;
6345 			case BALANCE_XMIT_POLICY_LAYER23:
6346 				printf("BALANCE_XMIT_POLICY_LAYER23");
6347 				break;
6348 			case BALANCE_XMIT_POLICY_LAYER34:
6349 				printf("BALANCE_XMIT_POLICY_LAYER34");
6350 				break;
6351 			}
6352 			printf("\n");
6353 		}
6354 	}
6355 
6356 	if (bonding_mode == BONDING_MODE_8023AD) {
6357 		agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6358 		printf("\tIEEE802.3AD Aggregator Mode: ");
6359 		switch (agg_mode) {
6360 		case AGG_BANDWIDTH:
6361 			printf("bandwidth");
6362 			break;
6363 		case AGG_STABLE:
6364 			printf("stable");
6365 			break;
6366 		case AGG_COUNT:
6367 			printf("count");
6368 			break;
6369 		}
6370 		printf("\n");
6371 	}
6372 
6373 	num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6374 
6375 	if (num_slaves < 0) {
6376 		fprintf(stderr, "\tFailed to get slave list for port = %d\n",
6377 			port_id);
6378 		return;
6379 	}
6380 	if (num_slaves > 0) {
6381 		printf("\tSlaves (%d): [", num_slaves);
6382 		for (i = 0; i < num_slaves - 1; i++)
6383 			printf("%d ", slaves[i]);
6384 
6385 		printf("%d]\n", slaves[num_slaves - 1]);
6386 	} else {
6387 		printf("\tSlaves: []\n");
6388 
6389 	}
6390 
6391 	num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6392 			RTE_MAX_ETHPORTS);
6393 
6394 	if (num_active_slaves < 0) {
6395 		fprintf(stderr,
6396 			"\tFailed to get active slave list for port = %d\n",
6397 			port_id);
6398 		return;
6399 	}
6400 	if (num_active_slaves > 0) {
6401 		printf("\tActive Slaves (%d): [", num_active_slaves);
6402 		for (i = 0; i < num_active_slaves - 1; i++)
6403 			printf("%d ", slaves[i]);
6404 
6405 		printf("%d]\n", slaves[num_active_slaves - 1]);
6406 
6407 	} else {
6408 		printf("\tActive Slaves: []\n");
6409 
6410 	}
6411 
6412 	primary_id = rte_eth_bond_primary_get(port_id);
6413 	if (primary_id < 0) {
6414 		fprintf(stderr, "\tFailed to get primary slave for port = %d\n",
6415 			port_id);
6416 		return;
6417 	} else
6418 		printf("\tPrimary: [%d]\n", primary_id);
6419 
6420 }
6421 
6422 cmdline_parse_token_string_t cmd_showbonding_config_show =
6423 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6424 		show, "show");
6425 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6426 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6427 		bonding, "bonding");
6428 cmdline_parse_token_string_t cmd_showbonding_config_config =
6429 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6430 		config, "config");
6431 cmdline_parse_token_num_t cmd_showbonding_config_port =
6432 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6433 		port_id, RTE_UINT16);
6434 
6435 cmdline_parse_inst_t cmd_show_bonding_config = {
6436 		.f = cmd_show_bonding_config_parsed,
6437 		.help_str = "show bonding config <port_id>: "
6438 			"Show the bonding config for port_id",
6439 		.data = NULL,
6440 		.tokens = {
6441 				(void *)&cmd_showbonding_config_show,
6442 				(void *)&cmd_showbonding_config_bonding,
6443 				(void *)&cmd_showbonding_config_config,
6444 				(void *)&cmd_showbonding_config_port,
6445 				NULL
6446 		}
6447 };
6448 
6449 /* *** SET BONDING PRIMARY *** */
6450 struct cmd_set_bonding_primary_result {
6451 	cmdline_fixed_string_t set;
6452 	cmdline_fixed_string_t bonding;
6453 	cmdline_fixed_string_t primary;
6454 	portid_t slave_id;
6455 	portid_t port_id;
6456 };
6457 
6458 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6459 		__rte_unused  struct cmdline *cl,
6460 		__rte_unused void *data)
6461 {
6462 	struct cmd_set_bonding_primary_result *res = parsed_result;
6463 	portid_t master_port_id = res->port_id;
6464 	portid_t slave_port_id = res->slave_id;
6465 
6466 	/* Set the primary slave for a bonded device. */
6467 	if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6468 		fprintf(stderr, "\t Failed to set primary slave for port = %d.\n",
6469 			master_port_id);
6470 		return;
6471 	}
6472 	init_port_config();
6473 }
6474 
6475 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6476 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6477 		set, "set");
6478 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6479 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6480 		bonding, "bonding");
6481 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6482 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6483 		primary, "primary");
6484 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6485 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6486 		slave_id, RTE_UINT16);
6487 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6488 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6489 		port_id, RTE_UINT16);
6490 
6491 cmdline_parse_inst_t cmd_set_bonding_primary = {
6492 		.f = cmd_set_bonding_primary_parsed,
6493 		.help_str = "set bonding primary <slave_id> <port_id>: "
6494 			"Set the primary slave for port_id",
6495 		.data = NULL,
6496 		.tokens = {
6497 				(void *)&cmd_setbonding_primary_set,
6498 				(void *)&cmd_setbonding_primary_bonding,
6499 				(void *)&cmd_setbonding_primary_primary,
6500 				(void *)&cmd_setbonding_primary_slave,
6501 				(void *)&cmd_setbonding_primary_port,
6502 				NULL
6503 		}
6504 };
6505 
6506 /* *** ADD SLAVE *** */
6507 struct cmd_add_bonding_slave_result {
6508 	cmdline_fixed_string_t add;
6509 	cmdline_fixed_string_t bonding;
6510 	cmdline_fixed_string_t slave;
6511 	portid_t slave_id;
6512 	portid_t port_id;
6513 };
6514 
6515 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6516 		__rte_unused  struct cmdline *cl,
6517 		__rte_unused void *data)
6518 {
6519 	struct cmd_add_bonding_slave_result *res = parsed_result;
6520 	portid_t master_port_id = res->port_id;
6521 	portid_t slave_port_id = res->slave_id;
6522 
6523 	/* add the slave for a bonded device. */
6524 	if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6525 		fprintf(stderr,
6526 			"\t Failed to add slave %d to master port = %d.\n",
6527 			slave_port_id, master_port_id);
6528 		return;
6529 	}
6530 	init_port_config();
6531 	set_port_slave_flag(slave_port_id);
6532 }
6533 
6534 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6535 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6536 		add, "add");
6537 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6538 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6539 		bonding, "bonding");
6540 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6541 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6542 		slave, "slave");
6543 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6544 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6545 		slave_id, RTE_UINT16);
6546 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6547 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6548 		port_id, RTE_UINT16);
6549 
6550 cmdline_parse_inst_t cmd_add_bonding_slave = {
6551 		.f = cmd_add_bonding_slave_parsed,
6552 		.help_str = "add bonding slave <slave_id> <port_id>: "
6553 			"Add a slave device to a bonded device",
6554 		.data = NULL,
6555 		.tokens = {
6556 				(void *)&cmd_addbonding_slave_add,
6557 				(void *)&cmd_addbonding_slave_bonding,
6558 				(void *)&cmd_addbonding_slave_slave,
6559 				(void *)&cmd_addbonding_slave_slaveid,
6560 				(void *)&cmd_addbonding_slave_port,
6561 				NULL
6562 		}
6563 };
6564 
6565 /* *** REMOVE SLAVE *** */
6566 struct cmd_remove_bonding_slave_result {
6567 	cmdline_fixed_string_t remove;
6568 	cmdline_fixed_string_t bonding;
6569 	cmdline_fixed_string_t slave;
6570 	portid_t slave_id;
6571 	portid_t port_id;
6572 };
6573 
6574 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6575 		__rte_unused  struct cmdline *cl,
6576 		__rte_unused void *data)
6577 {
6578 	struct cmd_remove_bonding_slave_result *res = parsed_result;
6579 	portid_t master_port_id = res->port_id;
6580 	portid_t slave_port_id = res->slave_id;
6581 
6582 	/* remove the slave from a bonded device. */
6583 	if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6584 		fprintf(stderr,
6585 			"\t Failed to remove slave %d from master port = %d.\n",
6586 			slave_port_id, master_port_id);
6587 		return;
6588 	}
6589 	init_port_config();
6590 	clear_port_slave_flag(slave_port_id);
6591 }
6592 
6593 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6594 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6595 				remove, "remove");
6596 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6597 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6598 				bonding, "bonding");
6599 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6600 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6601 				slave, "slave");
6602 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6603 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6604 				slave_id, RTE_UINT16);
6605 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6606 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6607 				port_id, RTE_UINT16);
6608 
6609 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6610 		.f = cmd_remove_bonding_slave_parsed,
6611 		.help_str = "remove bonding slave <slave_id> <port_id>: "
6612 			"Remove a slave device from a bonded device",
6613 		.data = NULL,
6614 		.tokens = {
6615 				(void *)&cmd_removebonding_slave_remove,
6616 				(void *)&cmd_removebonding_slave_bonding,
6617 				(void *)&cmd_removebonding_slave_slave,
6618 				(void *)&cmd_removebonding_slave_slaveid,
6619 				(void *)&cmd_removebonding_slave_port,
6620 				NULL
6621 		}
6622 };
6623 
6624 /* *** CREATE BONDED DEVICE *** */
6625 struct cmd_create_bonded_device_result {
6626 	cmdline_fixed_string_t create;
6627 	cmdline_fixed_string_t bonded;
6628 	cmdline_fixed_string_t device;
6629 	uint8_t mode;
6630 	uint8_t socket;
6631 };
6632 
6633 static int bond_dev_num = 0;
6634 
6635 static void cmd_create_bonded_device_parsed(void *parsed_result,
6636 		__rte_unused  struct cmdline *cl,
6637 		__rte_unused void *data)
6638 {
6639 	struct cmd_create_bonded_device_result *res = parsed_result;
6640 	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6641 	int port_id;
6642 	int ret;
6643 
6644 	if (test_done == 0) {
6645 		fprintf(stderr, "Please stop forwarding first\n");
6646 		return;
6647 	}
6648 
6649 	snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6650 			bond_dev_num++);
6651 
6652 	/* Create a new bonded device. */
6653 	port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6654 	if (port_id < 0) {
6655 		fprintf(stderr, "\t Failed to create bonded device.\n");
6656 		return;
6657 	} else {
6658 		printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6659 				port_id);
6660 
6661 		/* Update number of ports */
6662 		nb_ports = rte_eth_dev_count_avail();
6663 		reconfig(port_id, res->socket);
6664 		ret = rte_eth_promiscuous_enable(port_id);
6665 		if (ret != 0)
6666 			fprintf(stderr,
6667 				"Failed to enable promiscuous mode for port %u: %s - ignore\n",
6668 				port_id, rte_strerror(-ret));
6669 
6670 		ports[port_id].need_setup = 0;
6671 		ports[port_id].port_status = RTE_PORT_STOPPED;
6672 	}
6673 
6674 }
6675 
6676 cmdline_parse_token_string_t cmd_createbonded_device_create =
6677 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6678 				create, "create");
6679 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6680 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6681 				bonded, "bonded");
6682 cmdline_parse_token_string_t cmd_createbonded_device_device =
6683 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6684 				device, "device");
6685 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6686 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6687 				mode, RTE_UINT8);
6688 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6689 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6690 				socket, RTE_UINT8);
6691 
6692 cmdline_parse_inst_t cmd_create_bonded_device = {
6693 		.f = cmd_create_bonded_device_parsed,
6694 		.help_str = "create bonded device <mode> <socket>: "
6695 			"Create a new bonded device with specific bonding mode and socket",
6696 		.data = NULL,
6697 		.tokens = {
6698 				(void *)&cmd_createbonded_device_create,
6699 				(void *)&cmd_createbonded_device_bonded,
6700 				(void *)&cmd_createbonded_device_device,
6701 				(void *)&cmd_createbonded_device_mode,
6702 				(void *)&cmd_createbonded_device_socket,
6703 				NULL
6704 		}
6705 };
6706 
6707 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6708 struct cmd_set_bond_mac_addr_result {
6709 	cmdline_fixed_string_t set;
6710 	cmdline_fixed_string_t bonding;
6711 	cmdline_fixed_string_t mac_addr;
6712 	uint16_t port_num;
6713 	struct rte_ether_addr address;
6714 };
6715 
6716 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6717 		__rte_unused  struct cmdline *cl,
6718 		__rte_unused void *data)
6719 {
6720 	struct cmd_set_bond_mac_addr_result *res = parsed_result;
6721 	int ret;
6722 
6723 	if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6724 		return;
6725 
6726 	ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6727 
6728 	/* check the return value and print it if is < 0 */
6729 	if (ret < 0)
6730 		fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6731 			strerror(-ret));
6732 }
6733 
6734 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6735 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6736 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6737 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6738 				"bonding");
6739 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6740 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6741 				"mac_addr");
6742 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6743 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6744 				port_num, RTE_UINT16);
6745 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6746 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6747 
6748 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6749 		.f = cmd_set_bond_mac_addr_parsed,
6750 		.data = (void *) 0,
6751 		.help_str = "set bonding mac_addr <port_id> <mac_addr>",
6752 		.tokens = {
6753 				(void *)&cmd_set_bond_mac_addr_set,
6754 				(void *)&cmd_set_bond_mac_addr_bonding,
6755 				(void *)&cmd_set_bond_mac_addr_mac,
6756 				(void *)&cmd_set_bond_mac_addr_portnum,
6757 				(void *)&cmd_set_bond_mac_addr_addr,
6758 				NULL
6759 		}
6760 };
6761 
6762 
6763 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6764 struct cmd_set_bond_mon_period_result {
6765 	cmdline_fixed_string_t set;
6766 	cmdline_fixed_string_t bonding;
6767 	cmdline_fixed_string_t mon_period;
6768 	uint16_t port_num;
6769 	uint32_t period_ms;
6770 };
6771 
6772 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6773 		__rte_unused  struct cmdline *cl,
6774 		__rte_unused void *data)
6775 {
6776 	struct cmd_set_bond_mon_period_result *res = parsed_result;
6777 	int ret;
6778 
6779 	ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6780 
6781 	/* check the return value and print it if is < 0 */
6782 	if (ret < 0)
6783 		fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6784 			strerror(-ret));
6785 }
6786 
6787 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6788 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6789 				set, "set");
6790 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6791 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6792 				bonding, "bonding");
6793 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6794 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6795 				mon_period,	"mon_period");
6796 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6797 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6798 				port_num, RTE_UINT16);
6799 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6800 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6801 				period_ms, RTE_UINT32);
6802 
6803 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6804 		.f = cmd_set_bond_mon_period_parsed,
6805 		.data = (void *) 0,
6806 		.help_str = "set bonding mon_period <port_id> <period_ms>",
6807 		.tokens = {
6808 				(void *)&cmd_set_bond_mon_period_set,
6809 				(void *)&cmd_set_bond_mon_period_bonding,
6810 				(void *)&cmd_set_bond_mon_period_mon_period,
6811 				(void *)&cmd_set_bond_mon_period_portnum,
6812 				(void *)&cmd_set_bond_mon_period_period_ms,
6813 				NULL
6814 		}
6815 };
6816 
6817 
6818 
6819 struct cmd_set_bonding_agg_mode_policy_result {
6820 	cmdline_fixed_string_t set;
6821 	cmdline_fixed_string_t bonding;
6822 	cmdline_fixed_string_t agg_mode;
6823 	uint16_t port_num;
6824 	cmdline_fixed_string_t policy;
6825 };
6826 
6827 
6828 static void
6829 cmd_set_bonding_agg_mode(void *parsed_result,
6830 		__rte_unused struct cmdline *cl,
6831 		__rte_unused void *data)
6832 {
6833 	struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6834 	uint8_t policy = AGG_BANDWIDTH;
6835 
6836 	if (!strcmp(res->policy, "bandwidth"))
6837 		policy = AGG_BANDWIDTH;
6838 	else if (!strcmp(res->policy, "stable"))
6839 		policy = AGG_STABLE;
6840 	else if (!strcmp(res->policy, "count"))
6841 		policy = AGG_COUNT;
6842 
6843 	rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6844 }
6845 
6846 
6847 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6848 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6849 				set, "set");
6850 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6851 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6852 				bonding, "bonding");
6853 
6854 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6855 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6856 				agg_mode, "agg_mode");
6857 
6858 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6859 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6860 				port_num, RTE_UINT16);
6861 
6862 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6863 	TOKEN_STRING_INITIALIZER(
6864 			struct cmd_set_bonding_balance_xmit_policy_result,
6865 		policy, "stable#bandwidth#count");
6866 
6867 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6868 	.f = cmd_set_bonding_agg_mode,
6869 	.data = (void *) 0,
6870 	.help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6871 	.tokens = {
6872 			(void *)&cmd_set_bonding_agg_mode_set,
6873 			(void *)&cmd_set_bonding_agg_mode_bonding,
6874 			(void *)&cmd_set_bonding_agg_mode_agg_mode,
6875 			(void *)&cmd_set_bonding_agg_mode_portnum,
6876 			(void *)&cmd_set_bonding_agg_mode_policy_string,
6877 			NULL
6878 		}
6879 };
6880 
6881 
6882 #endif /* RTE_NET_BOND */
6883 
6884 /* *** SET FORWARDING MODE *** */
6885 struct cmd_set_fwd_mode_result {
6886 	cmdline_fixed_string_t set;
6887 	cmdline_fixed_string_t fwd;
6888 	cmdline_fixed_string_t mode;
6889 };
6890 
6891 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6892 				    __rte_unused struct cmdline *cl,
6893 				    __rte_unused void *data)
6894 {
6895 	struct cmd_set_fwd_mode_result *res = parsed_result;
6896 
6897 	retry_enabled = 0;
6898 	set_pkt_forwarding_mode(res->mode);
6899 }
6900 
6901 cmdline_parse_token_string_t cmd_setfwd_set =
6902 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6903 cmdline_parse_token_string_t cmd_setfwd_fwd =
6904 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6905 cmdline_parse_token_string_t cmd_setfwd_mode =
6906 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6907 		"" /* defined at init */);
6908 
6909 cmdline_parse_inst_t cmd_set_fwd_mode = {
6910 	.f = cmd_set_fwd_mode_parsed,
6911 	.data = NULL,
6912 	.help_str = NULL, /* defined at init */
6913 	.tokens = {
6914 		(void *)&cmd_setfwd_set,
6915 		(void *)&cmd_setfwd_fwd,
6916 		(void *)&cmd_setfwd_mode,
6917 		NULL,
6918 	},
6919 };
6920 
6921 static void cmd_set_fwd_mode_init(void)
6922 {
6923 	char *modes, *c;
6924 	static char token[128];
6925 	static char help[256];
6926 	cmdline_parse_token_string_t *token_struct;
6927 
6928 	modes = list_pkt_forwarding_modes();
6929 	snprintf(help, sizeof(help), "set fwd %s: "
6930 		"Set packet forwarding mode", modes);
6931 	cmd_set_fwd_mode.help_str = help;
6932 
6933 	/* string token separator is # */
6934 	for (c = token; *modes != '\0'; modes++)
6935 		if (*modes == '|')
6936 			*c++ = '#';
6937 		else
6938 			*c++ = *modes;
6939 	token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6940 	token_struct->string_data.str = token;
6941 }
6942 
6943 /* *** SET RETRY FORWARDING MODE *** */
6944 struct cmd_set_fwd_retry_mode_result {
6945 	cmdline_fixed_string_t set;
6946 	cmdline_fixed_string_t fwd;
6947 	cmdline_fixed_string_t mode;
6948 	cmdline_fixed_string_t retry;
6949 };
6950 
6951 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6952 			    __rte_unused struct cmdline *cl,
6953 			    __rte_unused void *data)
6954 {
6955 	struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6956 
6957 	retry_enabled = 1;
6958 	set_pkt_forwarding_mode(res->mode);
6959 }
6960 
6961 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6962 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6963 			set, "set");
6964 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6965 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6966 			fwd, "fwd");
6967 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6968 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6969 			mode,
6970 		"" /* defined at init */);
6971 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6972 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6973 			retry, "retry");
6974 
6975 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6976 	.f = cmd_set_fwd_retry_mode_parsed,
6977 	.data = NULL,
6978 	.help_str = NULL, /* defined at init */
6979 	.tokens = {
6980 		(void *)&cmd_setfwd_retry_set,
6981 		(void *)&cmd_setfwd_retry_fwd,
6982 		(void *)&cmd_setfwd_retry_mode,
6983 		(void *)&cmd_setfwd_retry_retry,
6984 		NULL,
6985 	},
6986 };
6987 
6988 static void cmd_set_fwd_retry_mode_init(void)
6989 {
6990 	char *modes, *c;
6991 	static char token[128];
6992 	static char help[256];
6993 	cmdline_parse_token_string_t *token_struct;
6994 
6995 	modes = list_pkt_forwarding_retry_modes();
6996 	snprintf(help, sizeof(help), "set fwd %s retry: "
6997 		"Set packet forwarding mode with retry", modes);
6998 	cmd_set_fwd_retry_mode.help_str = help;
6999 
7000 	/* string token separator is # */
7001 	for (c = token; *modes != '\0'; modes++)
7002 		if (*modes == '|')
7003 			*c++ = '#';
7004 		else
7005 			*c++ = *modes;
7006 	token_struct = (cmdline_parse_token_string_t *)
7007 		cmd_set_fwd_retry_mode.tokens[2];
7008 	token_struct->string_data.str = token;
7009 }
7010 
7011 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
7012 struct cmd_set_burst_tx_retry_result {
7013 	cmdline_fixed_string_t set;
7014 	cmdline_fixed_string_t burst;
7015 	cmdline_fixed_string_t tx;
7016 	cmdline_fixed_string_t delay;
7017 	uint32_t time;
7018 	cmdline_fixed_string_t retry;
7019 	uint32_t retry_num;
7020 };
7021 
7022 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
7023 					__rte_unused struct cmdline *cl,
7024 					__rte_unused void *data)
7025 {
7026 	struct cmd_set_burst_tx_retry_result *res = parsed_result;
7027 
7028 	if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
7029 		&& !strcmp(res->tx, "tx")) {
7030 		if (!strcmp(res->delay, "delay"))
7031 			burst_tx_delay_time = res->time;
7032 		if (!strcmp(res->retry, "retry"))
7033 			burst_tx_retry_num = res->retry_num;
7034 	}
7035 
7036 }
7037 
7038 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
7039 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
7040 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
7041 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
7042 				 "burst");
7043 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
7044 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
7045 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
7046 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
7047 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
7048 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
7049 				 RTE_UINT32);
7050 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
7051 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
7052 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
7053 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
7054 				 RTE_UINT32);
7055 
7056 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
7057 	.f = cmd_set_burst_tx_retry_parsed,
7058 	.help_str = "set burst tx delay <delay_usec> retry <num_retry>",
7059 	.tokens = {
7060 		(void *)&cmd_set_burst_tx_retry_set,
7061 		(void *)&cmd_set_burst_tx_retry_burst,
7062 		(void *)&cmd_set_burst_tx_retry_tx,
7063 		(void *)&cmd_set_burst_tx_retry_delay,
7064 		(void *)&cmd_set_burst_tx_retry_time,
7065 		(void *)&cmd_set_burst_tx_retry_retry,
7066 		(void *)&cmd_set_burst_tx_retry_retry_num,
7067 		NULL,
7068 	},
7069 };
7070 
7071 /* *** SET PROMISC MODE *** */
7072 struct cmd_set_promisc_mode_result {
7073 	cmdline_fixed_string_t set;
7074 	cmdline_fixed_string_t promisc;
7075 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7076 	uint16_t port_num;               /* valid if "allports" argument == 0 */
7077 	cmdline_fixed_string_t mode;
7078 };
7079 
7080 static void cmd_set_promisc_mode_parsed(void *parsed_result,
7081 					__rte_unused struct cmdline *cl,
7082 					void *allports)
7083 {
7084 	struct cmd_set_promisc_mode_result *res = parsed_result;
7085 	int enable;
7086 	portid_t i;
7087 
7088 	if (!strcmp(res->mode, "on"))
7089 		enable = 1;
7090 	else
7091 		enable = 0;
7092 
7093 	/* all ports */
7094 	if (allports) {
7095 		RTE_ETH_FOREACH_DEV(i)
7096 			eth_set_promisc_mode(i, enable);
7097 	} else {
7098 		eth_set_promisc_mode(res->port_num, enable);
7099 	}
7100 }
7101 
7102 cmdline_parse_token_string_t cmd_setpromisc_set =
7103 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
7104 cmdline_parse_token_string_t cmd_setpromisc_promisc =
7105 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
7106 				 "promisc");
7107 cmdline_parse_token_string_t cmd_setpromisc_portall =
7108 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
7109 				 "all");
7110 cmdline_parse_token_num_t cmd_setpromisc_portnum =
7111 	TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
7112 			      RTE_UINT16);
7113 cmdline_parse_token_string_t cmd_setpromisc_mode =
7114 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
7115 				 "on#off");
7116 
7117 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
7118 	.f = cmd_set_promisc_mode_parsed,
7119 	.data = (void *)1,
7120 	.help_str = "set promisc all on|off: Set promisc mode for all ports",
7121 	.tokens = {
7122 		(void *)&cmd_setpromisc_set,
7123 		(void *)&cmd_setpromisc_promisc,
7124 		(void *)&cmd_setpromisc_portall,
7125 		(void *)&cmd_setpromisc_mode,
7126 		NULL,
7127 	},
7128 };
7129 
7130 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
7131 	.f = cmd_set_promisc_mode_parsed,
7132 	.data = (void *)0,
7133 	.help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
7134 	.tokens = {
7135 		(void *)&cmd_setpromisc_set,
7136 		(void *)&cmd_setpromisc_promisc,
7137 		(void *)&cmd_setpromisc_portnum,
7138 		(void *)&cmd_setpromisc_mode,
7139 		NULL,
7140 	},
7141 };
7142 
7143 /* *** SET ALLMULTI MODE *** */
7144 struct cmd_set_allmulti_mode_result {
7145 	cmdline_fixed_string_t set;
7146 	cmdline_fixed_string_t allmulti;
7147 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7148 	uint16_t port_num;               /* valid if "allports" argument == 0 */
7149 	cmdline_fixed_string_t mode;
7150 };
7151 
7152 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
7153 					__rte_unused struct cmdline *cl,
7154 					void *allports)
7155 {
7156 	struct cmd_set_allmulti_mode_result *res = parsed_result;
7157 	int enable;
7158 	portid_t i;
7159 
7160 	if (!strcmp(res->mode, "on"))
7161 		enable = 1;
7162 	else
7163 		enable = 0;
7164 
7165 	/* all ports */
7166 	if (allports) {
7167 		RTE_ETH_FOREACH_DEV(i) {
7168 			eth_set_allmulticast_mode(i, enable);
7169 		}
7170 	}
7171 	else {
7172 		eth_set_allmulticast_mode(res->port_num, enable);
7173 	}
7174 }
7175 
7176 cmdline_parse_token_string_t cmd_setallmulti_set =
7177 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
7178 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
7179 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
7180 				 "allmulti");
7181 cmdline_parse_token_string_t cmd_setallmulti_portall =
7182 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
7183 				 "all");
7184 cmdline_parse_token_num_t cmd_setallmulti_portnum =
7185 	TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
7186 			      RTE_UINT16);
7187 cmdline_parse_token_string_t cmd_setallmulti_mode =
7188 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
7189 				 "on#off");
7190 
7191 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
7192 	.f = cmd_set_allmulti_mode_parsed,
7193 	.data = (void *)1,
7194 	.help_str = "set allmulti all on|off: Set allmulti mode for all ports",
7195 	.tokens = {
7196 		(void *)&cmd_setallmulti_set,
7197 		(void *)&cmd_setallmulti_allmulti,
7198 		(void *)&cmd_setallmulti_portall,
7199 		(void *)&cmd_setallmulti_mode,
7200 		NULL,
7201 	},
7202 };
7203 
7204 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
7205 	.f = cmd_set_allmulti_mode_parsed,
7206 	.data = (void *)0,
7207 	.help_str = "set allmulti <port_id> on|off: "
7208 		"Set allmulti mode on port_id",
7209 	.tokens = {
7210 		(void *)&cmd_setallmulti_set,
7211 		(void *)&cmd_setallmulti_allmulti,
7212 		(void *)&cmd_setallmulti_portnum,
7213 		(void *)&cmd_setallmulti_mode,
7214 		NULL,
7215 	},
7216 };
7217 
7218 /* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */
7219 struct cmd_link_flow_ctrl_show {
7220 	cmdline_fixed_string_t show;
7221 	cmdline_fixed_string_t port;
7222 	portid_t port_id;
7223 	cmdline_fixed_string_t flow_ctrl;
7224 };
7225 
7226 cmdline_parse_token_string_t cmd_lfc_show_show =
7227 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7228 				show, "show");
7229 cmdline_parse_token_string_t cmd_lfc_show_port =
7230 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7231 				port, "port");
7232 cmdline_parse_token_num_t cmd_lfc_show_portid =
7233 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show,
7234 				port_id, RTE_UINT16);
7235 cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl =
7236 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7237 				flow_ctrl, "flow_ctrl");
7238 
7239 static void
7240 cmd_link_flow_ctrl_show_parsed(void *parsed_result,
7241 			      __rte_unused struct cmdline *cl,
7242 			      __rte_unused void *data)
7243 {
7244 	struct cmd_link_flow_ctrl_show *res = parsed_result;
7245 	static const char *info_border = "*********************";
7246 	struct rte_eth_fc_conf fc_conf;
7247 	bool rx_fc_en = false;
7248 	bool tx_fc_en = false;
7249 	int ret;
7250 
7251 	ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7252 	if (ret != 0) {
7253 		fprintf(stderr,
7254 			"Failed to get current flow ctrl information: err = %d\n",
7255 			ret);
7256 		return;
7257 	}
7258 
7259 	if (fc_conf.mode == RTE_ETH_FC_RX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7260 		rx_fc_en = true;
7261 	if (fc_conf.mode == RTE_ETH_FC_TX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7262 		tx_fc_en = true;
7263 
7264 	printf("\n%s Flow control infos for port %-2d %s\n",
7265 		info_border, res->port_id, info_border);
7266 	printf("FC mode:\n");
7267 	printf("   Rx pause: %s\n", rx_fc_en ? "on" : "off");
7268 	printf("   Tx pause: %s\n", tx_fc_en ? "on" : "off");
7269 	printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off");
7270 	printf("Pause time: 0x%x\n", fc_conf.pause_time);
7271 	printf("High waterline: 0x%x\n", fc_conf.high_water);
7272 	printf("Low waterline: 0x%x\n", fc_conf.low_water);
7273 	printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off");
7274 	printf("Forward MAC control frames: %s\n",
7275 		fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
7276 	printf("\n%s**************   End  ***********%s\n",
7277 		info_border, info_border);
7278 }
7279 
7280 cmdline_parse_inst_t cmd_link_flow_control_show = {
7281 	.f = cmd_link_flow_ctrl_show_parsed,
7282 	.data = NULL,
7283 	.help_str = "show port <port_id> flow_ctrl",
7284 	.tokens = {
7285 		(void *)&cmd_lfc_show_show,
7286 		(void *)&cmd_lfc_show_port,
7287 		(void *)&cmd_lfc_show_portid,
7288 		(void *)&cmd_lfc_show_flow_ctrl,
7289 		NULL,
7290 	},
7291 };
7292 
7293 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7294 struct cmd_link_flow_ctrl_set_result {
7295 	cmdline_fixed_string_t set;
7296 	cmdline_fixed_string_t flow_ctrl;
7297 	cmdline_fixed_string_t rx;
7298 	cmdline_fixed_string_t rx_lfc_mode;
7299 	cmdline_fixed_string_t tx;
7300 	cmdline_fixed_string_t tx_lfc_mode;
7301 	cmdline_fixed_string_t mac_ctrl_frame_fwd;
7302 	cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7303 	cmdline_fixed_string_t autoneg_str;
7304 	cmdline_fixed_string_t autoneg;
7305 	cmdline_fixed_string_t hw_str;
7306 	uint32_t high_water;
7307 	cmdline_fixed_string_t lw_str;
7308 	uint32_t low_water;
7309 	cmdline_fixed_string_t pt_str;
7310 	uint16_t pause_time;
7311 	cmdline_fixed_string_t xon_str;
7312 	uint16_t send_xon;
7313 	portid_t port_id;
7314 };
7315 
7316 cmdline_parse_token_string_t cmd_lfc_set_set =
7317 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7318 				set, "set");
7319 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7320 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7321 				flow_ctrl, "flow_ctrl");
7322 cmdline_parse_token_string_t cmd_lfc_set_rx =
7323 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7324 				rx, "rx");
7325 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7326 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7327 				rx_lfc_mode, "on#off");
7328 cmdline_parse_token_string_t cmd_lfc_set_tx =
7329 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7330 				tx, "tx");
7331 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7332 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7333 				tx_lfc_mode, "on#off");
7334 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7335 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7336 				hw_str, "high_water");
7337 cmdline_parse_token_num_t cmd_lfc_set_high_water =
7338 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7339 				high_water, RTE_UINT32);
7340 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7341 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7342 				lw_str, "low_water");
7343 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7344 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7345 				low_water, RTE_UINT32);
7346 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7347 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7348 				pt_str, "pause_time");
7349 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7350 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7351 				pause_time, RTE_UINT16);
7352 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7353 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7354 				xon_str, "send_xon");
7355 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7356 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7357 				send_xon, RTE_UINT16);
7358 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7359 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7360 				mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7361 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7362 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7363 				mac_ctrl_frame_fwd_mode, "on#off");
7364 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7365 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7366 				autoneg_str, "autoneg");
7367 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7368 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7369 				autoneg, "on#off");
7370 cmdline_parse_token_num_t cmd_lfc_set_portid =
7371 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7372 				port_id, RTE_UINT16);
7373 
7374 /* forward declaration */
7375 static void
7376 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7377 			      void *data);
7378 
7379 cmdline_parse_inst_t cmd_link_flow_control_set = {
7380 	.f = cmd_link_flow_ctrl_set_parsed,
7381 	.data = NULL,
7382 	.help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7383 		"<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7384 		"autoneg on|off <port_id>: Configure the Ethernet flow control",
7385 	.tokens = {
7386 		(void *)&cmd_lfc_set_set,
7387 		(void *)&cmd_lfc_set_flow_ctrl,
7388 		(void *)&cmd_lfc_set_rx,
7389 		(void *)&cmd_lfc_set_rx_mode,
7390 		(void *)&cmd_lfc_set_tx,
7391 		(void *)&cmd_lfc_set_tx_mode,
7392 		(void *)&cmd_lfc_set_high_water,
7393 		(void *)&cmd_lfc_set_low_water,
7394 		(void *)&cmd_lfc_set_pause_time,
7395 		(void *)&cmd_lfc_set_send_xon,
7396 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7397 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7398 		(void *)&cmd_lfc_set_autoneg_str,
7399 		(void *)&cmd_lfc_set_autoneg,
7400 		(void *)&cmd_lfc_set_portid,
7401 		NULL,
7402 	},
7403 };
7404 
7405 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7406 	.f = cmd_link_flow_ctrl_set_parsed,
7407 	.data = (void *)&cmd_link_flow_control_set_rx,
7408 	.help_str = "set flow_ctrl rx on|off <port_id>: "
7409 		"Change rx flow control parameter",
7410 	.tokens = {
7411 		(void *)&cmd_lfc_set_set,
7412 		(void *)&cmd_lfc_set_flow_ctrl,
7413 		(void *)&cmd_lfc_set_rx,
7414 		(void *)&cmd_lfc_set_rx_mode,
7415 		(void *)&cmd_lfc_set_portid,
7416 		NULL,
7417 	},
7418 };
7419 
7420 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7421 	.f = cmd_link_flow_ctrl_set_parsed,
7422 	.data = (void *)&cmd_link_flow_control_set_tx,
7423 	.help_str = "set flow_ctrl tx on|off <port_id>: "
7424 		"Change tx flow control parameter",
7425 	.tokens = {
7426 		(void *)&cmd_lfc_set_set,
7427 		(void *)&cmd_lfc_set_flow_ctrl,
7428 		(void *)&cmd_lfc_set_tx,
7429 		(void *)&cmd_lfc_set_tx_mode,
7430 		(void *)&cmd_lfc_set_portid,
7431 		NULL,
7432 	},
7433 };
7434 
7435 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7436 	.f = cmd_link_flow_ctrl_set_parsed,
7437 	.data = (void *)&cmd_link_flow_control_set_hw,
7438 	.help_str = "set flow_ctrl high_water <value> <port_id>: "
7439 		"Change high water flow control parameter",
7440 	.tokens = {
7441 		(void *)&cmd_lfc_set_set,
7442 		(void *)&cmd_lfc_set_flow_ctrl,
7443 		(void *)&cmd_lfc_set_high_water_str,
7444 		(void *)&cmd_lfc_set_high_water,
7445 		(void *)&cmd_lfc_set_portid,
7446 		NULL,
7447 	},
7448 };
7449 
7450 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7451 	.f = cmd_link_flow_ctrl_set_parsed,
7452 	.data = (void *)&cmd_link_flow_control_set_lw,
7453 	.help_str = "set flow_ctrl low_water <value> <port_id>: "
7454 		"Change low water flow control parameter",
7455 	.tokens = {
7456 		(void *)&cmd_lfc_set_set,
7457 		(void *)&cmd_lfc_set_flow_ctrl,
7458 		(void *)&cmd_lfc_set_low_water_str,
7459 		(void *)&cmd_lfc_set_low_water,
7460 		(void *)&cmd_lfc_set_portid,
7461 		NULL,
7462 	},
7463 };
7464 
7465 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7466 	.f = cmd_link_flow_ctrl_set_parsed,
7467 	.data = (void *)&cmd_link_flow_control_set_pt,
7468 	.help_str = "set flow_ctrl pause_time <value> <port_id>: "
7469 		"Change pause time flow control parameter",
7470 	.tokens = {
7471 		(void *)&cmd_lfc_set_set,
7472 		(void *)&cmd_lfc_set_flow_ctrl,
7473 		(void *)&cmd_lfc_set_pause_time_str,
7474 		(void *)&cmd_lfc_set_pause_time,
7475 		(void *)&cmd_lfc_set_portid,
7476 		NULL,
7477 	},
7478 };
7479 
7480 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7481 	.f = cmd_link_flow_ctrl_set_parsed,
7482 	.data = (void *)&cmd_link_flow_control_set_xon,
7483 	.help_str = "set flow_ctrl send_xon <value> <port_id>: "
7484 		"Change send_xon flow control parameter",
7485 	.tokens = {
7486 		(void *)&cmd_lfc_set_set,
7487 		(void *)&cmd_lfc_set_flow_ctrl,
7488 		(void *)&cmd_lfc_set_send_xon_str,
7489 		(void *)&cmd_lfc_set_send_xon,
7490 		(void *)&cmd_lfc_set_portid,
7491 		NULL,
7492 	},
7493 };
7494 
7495 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7496 	.f = cmd_link_flow_ctrl_set_parsed,
7497 	.data = (void *)&cmd_link_flow_control_set_macfwd,
7498 	.help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7499 		"Change mac ctrl fwd flow control parameter",
7500 	.tokens = {
7501 		(void *)&cmd_lfc_set_set,
7502 		(void *)&cmd_lfc_set_flow_ctrl,
7503 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7504 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7505 		(void *)&cmd_lfc_set_portid,
7506 		NULL,
7507 	},
7508 };
7509 
7510 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7511 	.f = cmd_link_flow_ctrl_set_parsed,
7512 	.data = (void *)&cmd_link_flow_control_set_autoneg,
7513 	.help_str = "set flow_ctrl autoneg on|off <port_id>: "
7514 		"Change autoneg flow control parameter",
7515 	.tokens = {
7516 		(void *)&cmd_lfc_set_set,
7517 		(void *)&cmd_lfc_set_flow_ctrl,
7518 		(void *)&cmd_lfc_set_autoneg_str,
7519 		(void *)&cmd_lfc_set_autoneg,
7520 		(void *)&cmd_lfc_set_portid,
7521 		NULL,
7522 	},
7523 };
7524 
7525 static void
7526 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7527 			      __rte_unused struct cmdline *cl,
7528 			      void *data)
7529 {
7530 	struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7531 	cmdline_parse_inst_t *cmd = data;
7532 	struct rte_eth_fc_conf fc_conf;
7533 	int rx_fc_en = 0;
7534 	int tx_fc_en = 0;
7535 	int ret;
7536 
7537 	/*
7538 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7539 	 * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7540 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7541 	 * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7542 	 */
7543 	static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7544 			{RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7545 	};
7546 
7547 	/* Partial command line, retrieve current configuration */
7548 	if (cmd) {
7549 		ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7550 		if (ret != 0) {
7551 			fprintf(stderr,
7552 				"cannot get current flow ctrl parameters, return code = %d\n",
7553 				ret);
7554 			return;
7555 		}
7556 
7557 		if ((fc_conf.mode == RTE_ETH_FC_RX_PAUSE) ||
7558 		    (fc_conf.mode == RTE_ETH_FC_FULL))
7559 			rx_fc_en = 1;
7560 		if ((fc_conf.mode == RTE_ETH_FC_TX_PAUSE) ||
7561 		    (fc_conf.mode == RTE_ETH_FC_FULL))
7562 			tx_fc_en = 1;
7563 	}
7564 
7565 	if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7566 		rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7567 
7568 	if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7569 		tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7570 
7571 	fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7572 
7573 	if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7574 		fc_conf.high_water = res->high_water;
7575 
7576 	if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7577 		fc_conf.low_water = res->low_water;
7578 
7579 	if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7580 		fc_conf.pause_time = res->pause_time;
7581 
7582 	if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7583 		fc_conf.send_xon = res->send_xon;
7584 
7585 	if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7586 		if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7587 			fc_conf.mac_ctrl_frame_fwd = 1;
7588 		else
7589 			fc_conf.mac_ctrl_frame_fwd = 0;
7590 	}
7591 
7592 	if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7593 		fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7594 
7595 	ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7596 	if (ret != 0)
7597 		fprintf(stderr,
7598 			"bad flow control parameter, return code = %d\n",
7599 			ret);
7600 }
7601 
7602 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7603 struct cmd_priority_flow_ctrl_set_result {
7604 	cmdline_fixed_string_t set;
7605 	cmdline_fixed_string_t pfc_ctrl;
7606 	cmdline_fixed_string_t rx;
7607 	cmdline_fixed_string_t rx_pfc_mode;
7608 	cmdline_fixed_string_t tx;
7609 	cmdline_fixed_string_t tx_pfc_mode;
7610 	uint32_t high_water;
7611 	uint32_t low_water;
7612 	uint16_t pause_time;
7613 	uint8_t  priority;
7614 	portid_t port_id;
7615 };
7616 
7617 static void
7618 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7619 		       __rte_unused struct cmdline *cl,
7620 		       __rte_unused void *data)
7621 {
7622 	struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7623 	struct rte_eth_pfc_conf pfc_conf;
7624 	int rx_fc_enable, tx_fc_enable;
7625 	int ret;
7626 
7627 	/*
7628 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7629 	 * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7630 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7631 	 * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7632 	 */
7633 	static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7634 		{RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7635 	};
7636 
7637 	memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7638 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7639 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7640 	pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7641 	pfc_conf.fc.high_water = res->high_water;
7642 	pfc_conf.fc.low_water  = res->low_water;
7643 	pfc_conf.fc.pause_time = res->pause_time;
7644 	pfc_conf.priority      = res->priority;
7645 
7646 	ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7647 	if (ret != 0)
7648 		fprintf(stderr,
7649 			"bad priority flow control parameter, return code = %d\n",
7650 			ret);
7651 }
7652 
7653 cmdline_parse_token_string_t cmd_pfc_set_set =
7654 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7655 				set, "set");
7656 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7657 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7658 				pfc_ctrl, "pfc_ctrl");
7659 cmdline_parse_token_string_t cmd_pfc_set_rx =
7660 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7661 				rx, "rx");
7662 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7663 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7664 				rx_pfc_mode, "on#off");
7665 cmdline_parse_token_string_t cmd_pfc_set_tx =
7666 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7667 				tx, "tx");
7668 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7669 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7670 				tx_pfc_mode, "on#off");
7671 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7672 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7673 				high_water, RTE_UINT32);
7674 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7675 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7676 				low_water, RTE_UINT32);
7677 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7678 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7679 				pause_time, RTE_UINT16);
7680 cmdline_parse_token_num_t cmd_pfc_set_priority =
7681 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7682 				priority, RTE_UINT8);
7683 cmdline_parse_token_num_t cmd_pfc_set_portid =
7684 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7685 				port_id, RTE_UINT16);
7686 
7687 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7688 	.f = cmd_priority_flow_ctrl_set_parsed,
7689 	.data = NULL,
7690 	.help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7691 		"<pause_time> <priority> <port_id>: "
7692 		"Configure the Ethernet priority flow control",
7693 	.tokens = {
7694 		(void *)&cmd_pfc_set_set,
7695 		(void *)&cmd_pfc_set_flow_ctrl,
7696 		(void *)&cmd_pfc_set_rx,
7697 		(void *)&cmd_pfc_set_rx_mode,
7698 		(void *)&cmd_pfc_set_tx,
7699 		(void *)&cmd_pfc_set_tx_mode,
7700 		(void *)&cmd_pfc_set_high_water,
7701 		(void *)&cmd_pfc_set_low_water,
7702 		(void *)&cmd_pfc_set_pause_time,
7703 		(void *)&cmd_pfc_set_priority,
7704 		(void *)&cmd_pfc_set_portid,
7705 		NULL,
7706 	},
7707 };
7708 
7709 struct cmd_queue_priority_flow_ctrl_set_result {
7710 	cmdline_fixed_string_t set;
7711 	cmdline_fixed_string_t pfc_queue_ctrl;
7712 	portid_t port_id;
7713 	cmdline_fixed_string_t rx;
7714 	cmdline_fixed_string_t rx_pfc_mode;
7715 	uint16_t tx_qid;
7716 	uint8_t  tx_tc;
7717 	cmdline_fixed_string_t tx;
7718 	cmdline_fixed_string_t tx_pfc_mode;
7719 	uint16_t rx_qid;
7720 	uint8_t  rx_tc;
7721 	uint16_t pause_time;
7722 };
7723 
7724 static void
7725 cmd_queue_priority_flow_ctrl_set_parsed(void *parsed_result,
7726 					__rte_unused struct cmdline *cl,
7727 					__rte_unused void *data)
7728 {
7729 	struct cmd_queue_priority_flow_ctrl_set_result *res = parsed_result;
7730 	struct rte_eth_pfc_queue_conf pfc_queue_conf;
7731 	int rx_fc_enable, tx_fc_enable;
7732 	int ret;
7733 
7734 	/*
7735 	 * Rx on/off, flow control is enabled/disabled on RX side. This can
7736 	 * indicate the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx
7737 	 * side. Tx on/off, flow control is enabled/disabled on TX side. This
7738 	 * can indicate the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at
7739 	 * the Tx side.
7740 	 */
7741 	static enum rte_eth_fc_mode rx_tx_onoff_2_mode[2][2] = {
7742 		{RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE},
7743 		{RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7744 	};
7745 
7746 	memset(&pfc_queue_conf, 0, sizeof(struct rte_eth_pfc_queue_conf));
7747 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on", 2)) ? 1 : 0;
7748 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on", 2)) ? 1 : 0;
7749 	pfc_queue_conf.mode = rx_tx_onoff_2_mode[rx_fc_enable][tx_fc_enable];
7750 	pfc_queue_conf.rx_pause.tc  = res->tx_tc;
7751 	pfc_queue_conf.rx_pause.tx_qid = res->tx_qid;
7752 	pfc_queue_conf.tx_pause.tc  = res->rx_tc;
7753 	pfc_queue_conf.tx_pause.rx_qid  = res->rx_qid;
7754 	pfc_queue_conf.tx_pause.pause_time = res->pause_time;
7755 
7756 	ret = rte_eth_dev_priority_flow_ctrl_queue_configure(res->port_id,
7757 							     &pfc_queue_conf);
7758 	if (ret != 0) {
7759 		fprintf(stderr,
7760 			"bad queue priority flow control parameter, rc = %d\n",
7761 			ret);
7762 	}
7763 }
7764 
7765 cmdline_parse_token_string_t cmd_q_pfc_set_set =
7766 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7767 				set, "set");
7768 cmdline_parse_token_string_t cmd_q_pfc_set_flow_ctrl =
7769 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7770 				pfc_queue_ctrl, "pfc_queue_ctrl");
7771 cmdline_parse_token_num_t cmd_q_pfc_set_portid =
7772 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7773 				port_id, RTE_UINT16);
7774 cmdline_parse_token_string_t cmd_q_pfc_set_rx =
7775 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7776 				rx, "rx");
7777 cmdline_parse_token_string_t cmd_q_pfc_set_rx_mode =
7778 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7779 				rx_pfc_mode, "on#off");
7780 cmdline_parse_token_num_t cmd_q_pfc_set_tx_qid =
7781 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7782 				tx_qid, RTE_UINT16);
7783 cmdline_parse_token_num_t cmd_q_pfc_set_tx_tc =
7784 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7785 				tx_tc, RTE_UINT8);
7786 cmdline_parse_token_string_t cmd_q_pfc_set_tx =
7787 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7788 				tx, "tx");
7789 cmdline_parse_token_string_t cmd_q_pfc_set_tx_mode =
7790 	TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7791 				tx_pfc_mode, "on#off");
7792 cmdline_parse_token_num_t cmd_q_pfc_set_rx_qid =
7793 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7794 				rx_qid, RTE_UINT16);
7795 cmdline_parse_token_num_t cmd_q_pfc_set_rx_tc =
7796 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7797 				rx_tc, RTE_UINT8);
7798 cmdline_parse_token_num_t cmd_q_pfc_set_pause_time =
7799 	TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7800 				pause_time, RTE_UINT16);
7801 
7802 cmdline_parse_inst_t cmd_queue_priority_flow_control_set = {
7803 	.f = cmd_queue_priority_flow_ctrl_set_parsed,
7804 	.data = NULL,
7805 	.help_str = "set pfc_queue_ctrl <port_id> rx <on|off> <tx_qid> <tx_tc> "
7806 		"tx <on|off> <rx_qid> <rx_tc> <pause_time>: "
7807 		"Configure the Ethernet queue priority flow control",
7808 	.tokens = {
7809 		(void *)&cmd_q_pfc_set_set,
7810 		(void *)&cmd_q_pfc_set_flow_ctrl,
7811 		(void *)&cmd_q_pfc_set_portid,
7812 		(void *)&cmd_q_pfc_set_rx,
7813 		(void *)&cmd_q_pfc_set_rx_mode,
7814 		(void *)&cmd_q_pfc_set_tx_qid,
7815 		(void *)&cmd_q_pfc_set_tx_tc,
7816 		(void *)&cmd_q_pfc_set_tx,
7817 		(void *)&cmd_q_pfc_set_tx_mode,
7818 		(void *)&cmd_q_pfc_set_rx_qid,
7819 		(void *)&cmd_q_pfc_set_rx_tc,
7820 		(void *)&cmd_q_pfc_set_pause_time,
7821 		NULL,
7822 	},
7823 };
7824 
7825 /* *** RESET CONFIGURATION *** */
7826 struct cmd_reset_result {
7827 	cmdline_fixed_string_t reset;
7828 	cmdline_fixed_string_t def;
7829 };
7830 
7831 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7832 			     struct cmdline *cl,
7833 			     __rte_unused void *data)
7834 {
7835 	cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7836 	set_def_fwd_config();
7837 }
7838 
7839 cmdline_parse_token_string_t cmd_reset_set =
7840 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7841 cmdline_parse_token_string_t cmd_reset_def =
7842 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7843 				 "default");
7844 
7845 cmdline_parse_inst_t cmd_reset = {
7846 	.f = cmd_reset_parsed,
7847 	.data = NULL,
7848 	.help_str = "set default: Reset default forwarding configuration",
7849 	.tokens = {
7850 		(void *)&cmd_reset_set,
7851 		(void *)&cmd_reset_def,
7852 		NULL,
7853 	},
7854 };
7855 
7856 /* *** START FORWARDING *** */
7857 struct cmd_start_result {
7858 	cmdline_fixed_string_t start;
7859 };
7860 
7861 cmdline_parse_token_string_t cmd_start_start =
7862 	TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7863 
7864 static void cmd_start_parsed(__rte_unused void *parsed_result,
7865 			     __rte_unused struct cmdline *cl,
7866 			     __rte_unused void *data)
7867 {
7868 	start_packet_forwarding(0);
7869 }
7870 
7871 cmdline_parse_inst_t cmd_start = {
7872 	.f = cmd_start_parsed,
7873 	.data = NULL,
7874 	.help_str = "start: Start packet forwarding",
7875 	.tokens = {
7876 		(void *)&cmd_start_start,
7877 		NULL,
7878 	},
7879 };
7880 
7881 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7882 struct cmd_start_tx_first_result {
7883 	cmdline_fixed_string_t start;
7884 	cmdline_fixed_string_t tx_first;
7885 };
7886 
7887 static void
7888 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7889 			  __rte_unused struct cmdline *cl,
7890 			  __rte_unused void *data)
7891 {
7892 	start_packet_forwarding(1);
7893 }
7894 
7895 cmdline_parse_token_string_t cmd_start_tx_first_start =
7896 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7897 				 "start");
7898 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7899 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7900 				 tx_first, "tx_first");
7901 
7902 cmdline_parse_inst_t cmd_start_tx_first = {
7903 	.f = cmd_start_tx_first_parsed,
7904 	.data = NULL,
7905 	.help_str = "start tx_first: Start packet forwarding, "
7906 		"after sending 1 burst of packets",
7907 	.tokens = {
7908 		(void *)&cmd_start_tx_first_start,
7909 		(void *)&cmd_start_tx_first_tx_first,
7910 		NULL,
7911 	},
7912 };
7913 
7914 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7915 struct cmd_start_tx_first_n_result {
7916 	cmdline_fixed_string_t start;
7917 	cmdline_fixed_string_t tx_first;
7918 	uint32_t tx_num;
7919 };
7920 
7921 static void
7922 cmd_start_tx_first_n_parsed(void *parsed_result,
7923 			  __rte_unused struct cmdline *cl,
7924 			  __rte_unused void *data)
7925 {
7926 	struct cmd_start_tx_first_n_result *res = parsed_result;
7927 
7928 	start_packet_forwarding(res->tx_num);
7929 }
7930 
7931 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7932 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7933 			start, "start");
7934 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7935 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7936 			tx_first, "tx_first");
7937 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7938 	TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7939 			tx_num, RTE_UINT32);
7940 
7941 cmdline_parse_inst_t cmd_start_tx_first_n = {
7942 	.f = cmd_start_tx_first_n_parsed,
7943 	.data = NULL,
7944 	.help_str = "start tx_first <num>: "
7945 		"packet forwarding, after sending <num> bursts of packets",
7946 	.tokens = {
7947 		(void *)&cmd_start_tx_first_n_start,
7948 		(void *)&cmd_start_tx_first_n_tx_first,
7949 		(void *)&cmd_start_tx_first_n_tx_num,
7950 		NULL,
7951 	},
7952 };
7953 
7954 /* *** SET LINK UP *** */
7955 struct cmd_set_link_up_result {
7956 	cmdline_fixed_string_t set;
7957 	cmdline_fixed_string_t link_up;
7958 	cmdline_fixed_string_t port;
7959 	portid_t port_id;
7960 };
7961 
7962 cmdline_parse_token_string_t cmd_set_link_up_set =
7963 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7964 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7965 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7966 				"link-up");
7967 cmdline_parse_token_string_t cmd_set_link_up_port =
7968 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7969 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7970 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7971 				RTE_UINT16);
7972 
7973 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7974 			     __rte_unused struct cmdline *cl,
7975 			     __rte_unused void *data)
7976 {
7977 	struct cmd_set_link_up_result *res = parsed_result;
7978 	dev_set_link_up(res->port_id);
7979 }
7980 
7981 cmdline_parse_inst_t cmd_set_link_up = {
7982 	.f = cmd_set_link_up_parsed,
7983 	.data = NULL,
7984 	.help_str = "set link-up port <port id>",
7985 	.tokens = {
7986 		(void *)&cmd_set_link_up_set,
7987 		(void *)&cmd_set_link_up_link_up,
7988 		(void *)&cmd_set_link_up_port,
7989 		(void *)&cmd_set_link_up_port_id,
7990 		NULL,
7991 	},
7992 };
7993 
7994 /* *** SET LINK DOWN *** */
7995 struct cmd_set_link_down_result {
7996 	cmdline_fixed_string_t set;
7997 	cmdline_fixed_string_t link_down;
7998 	cmdline_fixed_string_t port;
7999 	portid_t port_id;
8000 };
8001 
8002 cmdline_parse_token_string_t cmd_set_link_down_set =
8003 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
8004 cmdline_parse_token_string_t cmd_set_link_down_link_down =
8005 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
8006 				"link-down");
8007 cmdline_parse_token_string_t cmd_set_link_down_port =
8008 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
8009 cmdline_parse_token_num_t cmd_set_link_down_port_id =
8010 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
8011 				RTE_UINT16);
8012 
8013 static void cmd_set_link_down_parsed(
8014 				__rte_unused void *parsed_result,
8015 				__rte_unused struct cmdline *cl,
8016 				__rte_unused void *data)
8017 {
8018 	struct cmd_set_link_down_result *res = parsed_result;
8019 	dev_set_link_down(res->port_id);
8020 }
8021 
8022 cmdline_parse_inst_t cmd_set_link_down = {
8023 	.f = cmd_set_link_down_parsed,
8024 	.data = NULL,
8025 	.help_str = "set link-down port <port id>",
8026 	.tokens = {
8027 		(void *)&cmd_set_link_down_set,
8028 		(void *)&cmd_set_link_down_link_down,
8029 		(void *)&cmd_set_link_down_port,
8030 		(void *)&cmd_set_link_down_port_id,
8031 		NULL,
8032 	},
8033 };
8034 
8035 /* *** SHOW CFG *** */
8036 struct cmd_showcfg_result {
8037 	cmdline_fixed_string_t show;
8038 	cmdline_fixed_string_t cfg;
8039 	cmdline_fixed_string_t what;
8040 };
8041 
8042 static void cmd_showcfg_parsed(void *parsed_result,
8043 			       __rte_unused struct cmdline *cl,
8044 			       __rte_unused void *data)
8045 {
8046 	struct cmd_showcfg_result *res = parsed_result;
8047 	if (!strcmp(res->what, "rxtx"))
8048 		rxtx_config_display();
8049 	else if (!strcmp(res->what, "cores"))
8050 		fwd_lcores_config_display();
8051 	else if (!strcmp(res->what, "fwd"))
8052 		pkt_fwd_config_display(&cur_fwd_config);
8053 	else if (!strcmp(res->what, "rxoffs"))
8054 		show_rx_pkt_offsets();
8055 	else if (!strcmp(res->what, "rxpkts"))
8056 		show_rx_pkt_segments();
8057 	else if (!strcmp(res->what, "txpkts"))
8058 		show_tx_pkt_segments();
8059 	else if (!strcmp(res->what, "txtimes"))
8060 		show_tx_pkt_times();
8061 }
8062 
8063 cmdline_parse_token_string_t cmd_showcfg_show =
8064 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
8065 cmdline_parse_token_string_t cmd_showcfg_port =
8066 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
8067 cmdline_parse_token_string_t cmd_showcfg_what =
8068 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
8069 				 "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
8070 
8071 cmdline_parse_inst_t cmd_showcfg = {
8072 	.f = cmd_showcfg_parsed,
8073 	.data = NULL,
8074 	.help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
8075 	.tokens = {
8076 		(void *)&cmd_showcfg_show,
8077 		(void *)&cmd_showcfg_port,
8078 		(void *)&cmd_showcfg_what,
8079 		NULL,
8080 	},
8081 };
8082 
8083 /* *** SHOW ALL PORT INFO *** */
8084 struct cmd_showportall_result {
8085 	cmdline_fixed_string_t show;
8086 	cmdline_fixed_string_t port;
8087 	cmdline_fixed_string_t what;
8088 	cmdline_fixed_string_t all;
8089 };
8090 
8091 static void cmd_showportall_parsed(void *parsed_result,
8092 				__rte_unused struct cmdline *cl,
8093 				__rte_unused void *data)
8094 {
8095 	portid_t i;
8096 
8097 	struct cmd_showportall_result *res = parsed_result;
8098 	if (!strcmp(res->show, "clear")) {
8099 		if (!strcmp(res->what, "stats"))
8100 			RTE_ETH_FOREACH_DEV(i)
8101 				nic_stats_clear(i);
8102 		else if (!strcmp(res->what, "xstats"))
8103 			RTE_ETH_FOREACH_DEV(i)
8104 				nic_xstats_clear(i);
8105 	} else if (!strcmp(res->what, "info"))
8106 		RTE_ETH_FOREACH_DEV(i)
8107 			port_infos_display(i);
8108 	else if (!strcmp(res->what, "summary")) {
8109 		port_summary_header_display();
8110 		RTE_ETH_FOREACH_DEV(i)
8111 			port_summary_display(i);
8112 	}
8113 	else if (!strcmp(res->what, "stats"))
8114 		RTE_ETH_FOREACH_DEV(i)
8115 			nic_stats_display(i);
8116 	else if (!strcmp(res->what, "xstats"))
8117 		RTE_ETH_FOREACH_DEV(i)
8118 			nic_xstats_display(i);
8119 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8120 	else if (!strcmp(res->what, "fdir"))
8121 		RTE_ETH_FOREACH_DEV(i)
8122 			fdir_get_infos(i);
8123 #endif
8124 	else if (!strcmp(res->what, "dcb_tc"))
8125 		RTE_ETH_FOREACH_DEV(i)
8126 			port_dcb_info_display(i);
8127 }
8128 
8129 cmdline_parse_token_string_t cmd_showportall_show =
8130 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
8131 				 "show#clear");
8132 cmdline_parse_token_string_t cmd_showportall_port =
8133 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
8134 cmdline_parse_token_string_t cmd_showportall_what =
8135 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
8136 				 "info#summary#stats#xstats#fdir#dcb_tc");
8137 cmdline_parse_token_string_t cmd_showportall_all =
8138 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
8139 cmdline_parse_inst_t cmd_showportall = {
8140 	.f = cmd_showportall_parsed,
8141 	.data = NULL,
8142 	.help_str = "show|clear port "
8143 		"info|summary|stats|xstats|fdir|dcb_tc all",
8144 	.tokens = {
8145 		(void *)&cmd_showportall_show,
8146 		(void *)&cmd_showportall_port,
8147 		(void *)&cmd_showportall_what,
8148 		(void *)&cmd_showportall_all,
8149 		NULL,
8150 	},
8151 };
8152 
8153 /* *** SHOW PORT INFO *** */
8154 struct cmd_showport_result {
8155 	cmdline_fixed_string_t show;
8156 	cmdline_fixed_string_t port;
8157 	cmdline_fixed_string_t what;
8158 	uint16_t portnum;
8159 };
8160 
8161 static void cmd_showport_parsed(void *parsed_result,
8162 				__rte_unused struct cmdline *cl,
8163 				__rte_unused void *data)
8164 {
8165 	struct cmd_showport_result *res = parsed_result;
8166 	if (!strcmp(res->show, "clear")) {
8167 		if (!strcmp(res->what, "stats"))
8168 			nic_stats_clear(res->portnum);
8169 		else if (!strcmp(res->what, "xstats"))
8170 			nic_xstats_clear(res->portnum);
8171 	} else if (!strcmp(res->what, "info"))
8172 		port_infos_display(res->portnum);
8173 	else if (!strcmp(res->what, "summary")) {
8174 		port_summary_header_display();
8175 		port_summary_display(res->portnum);
8176 	}
8177 	else if (!strcmp(res->what, "stats"))
8178 		nic_stats_display(res->portnum);
8179 	else if (!strcmp(res->what, "xstats"))
8180 		nic_xstats_display(res->portnum);
8181 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8182 	else if (!strcmp(res->what, "fdir"))
8183 		 fdir_get_infos(res->portnum);
8184 #endif
8185 	else if (!strcmp(res->what, "dcb_tc"))
8186 		port_dcb_info_display(res->portnum);
8187 }
8188 
8189 cmdline_parse_token_string_t cmd_showport_show =
8190 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
8191 				 "show#clear");
8192 cmdline_parse_token_string_t cmd_showport_port =
8193 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
8194 cmdline_parse_token_string_t cmd_showport_what =
8195 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
8196 				 "info#summary#stats#xstats#fdir#dcb_tc");
8197 cmdline_parse_token_num_t cmd_showport_portnum =
8198 	TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
8199 
8200 cmdline_parse_inst_t cmd_showport = {
8201 	.f = cmd_showport_parsed,
8202 	.data = NULL,
8203 	.help_str = "show|clear port "
8204 		"info|summary|stats|xstats|fdir|dcb_tc "
8205 		"<port_id>",
8206 	.tokens = {
8207 		(void *)&cmd_showport_show,
8208 		(void *)&cmd_showport_port,
8209 		(void *)&cmd_showport_what,
8210 		(void *)&cmd_showport_portnum,
8211 		NULL,
8212 	},
8213 };
8214 
8215 /* *** show port representors information *** */
8216 struct cmd_representor_info_result {
8217 	cmdline_fixed_string_t cmd_show;
8218 	cmdline_fixed_string_t cmd_port;
8219 	cmdline_fixed_string_t cmd_info;
8220 	cmdline_fixed_string_t cmd_keyword;
8221 	portid_t cmd_pid;
8222 };
8223 
8224 static void
8225 cmd_representor_info_parsed(void *parsed_result,
8226 		__rte_unused struct cmdline *cl,
8227 		__rte_unused void *data)
8228 {
8229 	struct cmd_representor_info_result *res = parsed_result;
8230 	struct rte_eth_representor_info *info;
8231 	struct rte_eth_representor_range *range;
8232 	uint32_t range_diff;
8233 	uint32_t i;
8234 	int ret;
8235 	int num;
8236 
8237 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
8238 		fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
8239 		return;
8240 	}
8241 
8242 	ret = rte_eth_representor_info_get(res->cmd_pid, NULL);
8243 	if (ret < 0) {
8244 		fprintf(stderr,
8245 			"Failed to get the number of representor info ranges for port %hu: %s\n",
8246 			res->cmd_pid, rte_strerror(-ret));
8247 		return;
8248 	}
8249 	num = ret;
8250 
8251 	info = calloc(1, sizeof(*info) + num * sizeof(info->ranges[0]));
8252 	if (info == NULL) {
8253 		fprintf(stderr,
8254 			"Failed to allocate memory for representor info for port %hu\n",
8255 			res->cmd_pid);
8256 		return;
8257 	}
8258 	info->nb_ranges_alloc = num;
8259 
8260 	ret = rte_eth_representor_info_get(res->cmd_pid, info);
8261 	if (ret < 0) {
8262 		fprintf(stderr,
8263 			"Failed to get the representor info for port %hu: %s\n",
8264 			res->cmd_pid, rte_strerror(-ret));
8265 		free(info);
8266 		return;
8267 	}
8268 
8269 	printf("Port controller: %hu\n", info->controller);
8270 	printf("Port PF: %hu\n", info->pf);
8271 
8272 	printf("Ranges: %u\n", info->nb_ranges);
8273 	for (i = 0; i < info->nb_ranges; i++) {
8274 		range = &info->ranges[i];
8275 		range_diff = range->id_end - range->id_base;
8276 
8277 		printf("%u. ", i + 1);
8278 		printf("'%s' ", range->name);
8279 		if (range_diff > 0)
8280 			printf("[%u-%u]: ", range->id_base, range->id_end);
8281 		else
8282 			printf("[%u]: ", range->id_base);
8283 
8284 		printf("Controller %d, PF %d", range->controller, range->pf);
8285 
8286 		switch (range->type) {
8287 		case RTE_ETH_REPRESENTOR_NONE:
8288 			printf(", NONE\n");
8289 			break;
8290 		case RTE_ETH_REPRESENTOR_VF:
8291 			if (range_diff > 0)
8292 				printf(", VF %d..%d\n", range->vf,
8293 				       range->vf + range_diff);
8294 			else
8295 				printf(", VF %d\n", range->vf);
8296 			break;
8297 		case RTE_ETH_REPRESENTOR_SF:
8298 			printf(", SF %d\n", range->sf);
8299 			break;
8300 		case RTE_ETH_REPRESENTOR_PF:
8301 			if (range_diff > 0)
8302 				printf("..%d\n", range->pf + range_diff);
8303 			else
8304 				printf("\n");
8305 			break;
8306 		default:
8307 			printf(", UNKNOWN TYPE %d\n", range->type);
8308 			break;
8309 		}
8310 	}
8311 
8312 	free(info);
8313 }
8314 
8315 cmdline_parse_token_string_t cmd_representor_info_show =
8316 	TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8317 			cmd_show, "show");
8318 cmdline_parse_token_string_t cmd_representor_info_port =
8319 	TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8320 			cmd_port, "port");
8321 cmdline_parse_token_string_t cmd_representor_info_info =
8322 	TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8323 			cmd_info, "info");
8324 cmdline_parse_token_num_t cmd_representor_info_pid =
8325 	TOKEN_NUM_INITIALIZER(struct cmd_representor_info_result,
8326 			cmd_pid, RTE_UINT16);
8327 cmdline_parse_token_string_t cmd_representor_info_keyword =
8328 	TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8329 			cmd_keyword, "representor");
8330 
8331 cmdline_parse_inst_t cmd_representor_info = {
8332 	.f = cmd_representor_info_parsed,
8333 	.data = NULL,
8334 	.help_str = "show port info <port_id> representor",
8335 	.tokens = {
8336 		(void *)&cmd_representor_info_show,
8337 		(void *)&cmd_representor_info_port,
8338 		(void *)&cmd_representor_info_info,
8339 		(void *)&cmd_representor_info_pid,
8340 		(void *)&cmd_representor_info_keyword,
8341 		NULL,
8342 	},
8343 };
8344 
8345 
8346 /* *** SHOW DEVICE INFO *** */
8347 struct cmd_showdevice_result {
8348 	cmdline_fixed_string_t show;
8349 	cmdline_fixed_string_t device;
8350 	cmdline_fixed_string_t what;
8351 	cmdline_fixed_string_t identifier;
8352 };
8353 
8354 static void cmd_showdevice_parsed(void *parsed_result,
8355 				__rte_unused struct cmdline *cl,
8356 				__rte_unused void *data)
8357 {
8358 	struct cmd_showdevice_result *res = parsed_result;
8359 	if (!strcmp(res->what, "info")) {
8360 		if (!strcmp(res->identifier, "all"))
8361 			device_infos_display(NULL);
8362 		else
8363 			device_infos_display(res->identifier);
8364 	}
8365 }
8366 
8367 cmdline_parse_token_string_t cmd_showdevice_show =
8368 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
8369 				 "show");
8370 cmdline_parse_token_string_t cmd_showdevice_device =
8371 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
8372 cmdline_parse_token_string_t cmd_showdevice_what =
8373 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
8374 				 "info");
8375 cmdline_parse_token_string_t cmd_showdevice_identifier =
8376 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
8377 			identifier, NULL);
8378 
8379 cmdline_parse_inst_t cmd_showdevice = {
8380 	.f = cmd_showdevice_parsed,
8381 	.data = NULL,
8382 	.help_str = "show device info <identifier>|all",
8383 	.tokens = {
8384 		(void *)&cmd_showdevice_show,
8385 		(void *)&cmd_showdevice_device,
8386 		(void *)&cmd_showdevice_what,
8387 		(void *)&cmd_showdevice_identifier,
8388 		NULL,
8389 	},
8390 };
8391 
8392 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
8393 struct cmd_showeeprom_result {
8394 	cmdline_fixed_string_t show;
8395 	cmdline_fixed_string_t port;
8396 	uint16_t portnum;
8397 	cmdline_fixed_string_t type;
8398 };
8399 
8400 static void cmd_showeeprom_parsed(void *parsed_result,
8401 		__rte_unused struct cmdline *cl,
8402 		__rte_unused void *data)
8403 {
8404 	struct cmd_showeeprom_result *res = parsed_result;
8405 
8406 	if (!strcmp(res->type, "eeprom"))
8407 		port_eeprom_display(res->portnum);
8408 	else if (!strcmp(res->type, "module_eeprom"))
8409 		port_module_eeprom_display(res->portnum);
8410 	else
8411 		fprintf(stderr, "Unknown argument\n");
8412 }
8413 
8414 cmdline_parse_token_string_t cmd_showeeprom_show =
8415 	TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
8416 cmdline_parse_token_string_t cmd_showeeprom_port =
8417 	TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
8418 cmdline_parse_token_num_t cmd_showeeprom_portnum =
8419 	TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
8420 			RTE_UINT16);
8421 cmdline_parse_token_string_t cmd_showeeprom_type =
8422 	TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
8423 
8424 cmdline_parse_inst_t cmd_showeeprom = {
8425 	.f = cmd_showeeprom_parsed,
8426 	.data = NULL,
8427 	.help_str = "show port <port_id> module_eeprom|eeprom",
8428 	.tokens = {
8429 		(void *)&cmd_showeeprom_show,
8430 		(void *)&cmd_showeeprom_port,
8431 		(void *)&cmd_showeeprom_portnum,
8432 		(void *)&cmd_showeeprom_type,
8433 		NULL,
8434 	},
8435 };
8436 
8437 /* *** SHOW QUEUE INFO *** */
8438 struct cmd_showqueue_result {
8439 	cmdline_fixed_string_t show;
8440 	cmdline_fixed_string_t type;
8441 	cmdline_fixed_string_t what;
8442 	uint16_t portnum;
8443 	uint16_t queuenum;
8444 };
8445 
8446 static void
8447 cmd_showqueue_parsed(void *parsed_result,
8448 	__rte_unused struct cmdline *cl,
8449 	__rte_unused void *data)
8450 {
8451 	struct cmd_showqueue_result *res = parsed_result;
8452 
8453 	if (!strcmp(res->type, "rxq"))
8454 		rx_queue_infos_display(res->portnum, res->queuenum);
8455 	else if (!strcmp(res->type, "txq"))
8456 		tx_queue_infos_display(res->portnum, res->queuenum);
8457 }
8458 
8459 cmdline_parse_token_string_t cmd_showqueue_show =
8460 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
8461 cmdline_parse_token_string_t cmd_showqueue_type =
8462 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
8463 cmdline_parse_token_string_t cmd_showqueue_what =
8464 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
8465 cmdline_parse_token_num_t cmd_showqueue_portnum =
8466 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
8467 		RTE_UINT16);
8468 cmdline_parse_token_num_t cmd_showqueue_queuenum =
8469 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
8470 		RTE_UINT16);
8471 
8472 cmdline_parse_inst_t cmd_showqueue = {
8473 	.f = cmd_showqueue_parsed,
8474 	.data = NULL,
8475 	.help_str = "show rxq|txq info <port_id> <queue_id>",
8476 	.tokens = {
8477 		(void *)&cmd_showqueue_show,
8478 		(void *)&cmd_showqueue_type,
8479 		(void *)&cmd_showqueue_what,
8480 		(void *)&cmd_showqueue_portnum,
8481 		(void *)&cmd_showqueue_queuenum,
8482 		NULL,
8483 	},
8484 };
8485 
8486 /* show/clear fwd engine statistics */
8487 struct fwd_result {
8488 	cmdline_fixed_string_t action;
8489 	cmdline_fixed_string_t fwd;
8490 	cmdline_fixed_string_t stats;
8491 	cmdline_fixed_string_t all;
8492 };
8493 
8494 cmdline_parse_token_string_t cmd_fwd_action =
8495 	TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
8496 cmdline_parse_token_string_t cmd_fwd_fwd =
8497 	TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
8498 cmdline_parse_token_string_t cmd_fwd_stats =
8499 	TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
8500 cmdline_parse_token_string_t cmd_fwd_all =
8501 	TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
8502 
8503 static void
8504 cmd_showfwdall_parsed(void *parsed_result,
8505 		      __rte_unused struct cmdline *cl,
8506 		      __rte_unused void *data)
8507 {
8508 	struct fwd_result *res = parsed_result;
8509 
8510 	if (!strcmp(res->action, "show"))
8511 		fwd_stats_display();
8512 	else
8513 		fwd_stats_reset();
8514 }
8515 
8516 static cmdline_parse_inst_t cmd_showfwdall = {
8517 	.f = cmd_showfwdall_parsed,
8518 	.data = NULL,
8519 	.help_str = "show|clear fwd stats all",
8520 	.tokens = {
8521 		(void *)&cmd_fwd_action,
8522 		(void *)&cmd_fwd_fwd,
8523 		(void *)&cmd_fwd_stats,
8524 		(void *)&cmd_fwd_all,
8525 		NULL,
8526 	},
8527 };
8528 
8529 /* *** READ PORT REGISTER *** */
8530 struct cmd_read_reg_result {
8531 	cmdline_fixed_string_t read;
8532 	cmdline_fixed_string_t reg;
8533 	portid_t port_id;
8534 	uint32_t reg_off;
8535 };
8536 
8537 static void
8538 cmd_read_reg_parsed(void *parsed_result,
8539 		    __rte_unused struct cmdline *cl,
8540 		    __rte_unused void *data)
8541 {
8542 	struct cmd_read_reg_result *res = parsed_result;
8543 	port_reg_display(res->port_id, res->reg_off);
8544 }
8545 
8546 cmdline_parse_token_string_t cmd_read_reg_read =
8547 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8548 cmdline_parse_token_string_t cmd_read_reg_reg =
8549 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8550 cmdline_parse_token_num_t cmd_read_reg_port_id =
8551 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
8552 cmdline_parse_token_num_t cmd_read_reg_reg_off =
8553 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
8554 
8555 cmdline_parse_inst_t cmd_read_reg = {
8556 	.f = cmd_read_reg_parsed,
8557 	.data = NULL,
8558 	.help_str = "read reg <port_id> <reg_off>",
8559 	.tokens = {
8560 		(void *)&cmd_read_reg_read,
8561 		(void *)&cmd_read_reg_reg,
8562 		(void *)&cmd_read_reg_port_id,
8563 		(void *)&cmd_read_reg_reg_off,
8564 		NULL,
8565 	},
8566 };
8567 
8568 /* *** READ PORT REGISTER BIT FIELD *** */
8569 struct cmd_read_reg_bit_field_result {
8570 	cmdline_fixed_string_t read;
8571 	cmdline_fixed_string_t regfield;
8572 	portid_t port_id;
8573 	uint32_t reg_off;
8574 	uint8_t bit1_pos;
8575 	uint8_t bit2_pos;
8576 };
8577 
8578 static void
8579 cmd_read_reg_bit_field_parsed(void *parsed_result,
8580 			      __rte_unused struct cmdline *cl,
8581 			      __rte_unused void *data)
8582 {
8583 	struct cmd_read_reg_bit_field_result *res = parsed_result;
8584 	port_reg_bit_field_display(res->port_id, res->reg_off,
8585 				   res->bit1_pos, res->bit2_pos);
8586 }
8587 
8588 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8589 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8590 				 "read");
8591 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8592 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8593 				 regfield, "regfield");
8594 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8595 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8596 			      RTE_UINT16);
8597 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8598 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8599 			      RTE_UINT32);
8600 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8601 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8602 			      RTE_UINT8);
8603 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8604 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8605 			      RTE_UINT8);
8606 
8607 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8608 	.f = cmd_read_reg_bit_field_parsed,
8609 	.data = NULL,
8610 	.help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8611 	"Read register bit field between bit_x and bit_y included",
8612 	.tokens = {
8613 		(void *)&cmd_read_reg_bit_field_read,
8614 		(void *)&cmd_read_reg_bit_field_regfield,
8615 		(void *)&cmd_read_reg_bit_field_port_id,
8616 		(void *)&cmd_read_reg_bit_field_reg_off,
8617 		(void *)&cmd_read_reg_bit_field_bit1_pos,
8618 		(void *)&cmd_read_reg_bit_field_bit2_pos,
8619 		NULL,
8620 	},
8621 };
8622 
8623 /* *** READ PORT REGISTER BIT *** */
8624 struct cmd_read_reg_bit_result {
8625 	cmdline_fixed_string_t read;
8626 	cmdline_fixed_string_t regbit;
8627 	portid_t port_id;
8628 	uint32_t reg_off;
8629 	uint8_t bit_pos;
8630 };
8631 
8632 static void
8633 cmd_read_reg_bit_parsed(void *parsed_result,
8634 			__rte_unused struct cmdline *cl,
8635 			__rte_unused void *data)
8636 {
8637 	struct cmd_read_reg_bit_result *res = parsed_result;
8638 	port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8639 }
8640 
8641 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8642 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8643 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8644 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8645 				 regbit, "regbit");
8646 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8647 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
8648 				 RTE_UINT16);
8649 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8650 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
8651 				 RTE_UINT32);
8652 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8653 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
8654 				 RTE_UINT8);
8655 
8656 cmdline_parse_inst_t cmd_read_reg_bit = {
8657 	.f = cmd_read_reg_bit_parsed,
8658 	.data = NULL,
8659 	.help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8660 	.tokens = {
8661 		(void *)&cmd_read_reg_bit_read,
8662 		(void *)&cmd_read_reg_bit_regbit,
8663 		(void *)&cmd_read_reg_bit_port_id,
8664 		(void *)&cmd_read_reg_bit_reg_off,
8665 		(void *)&cmd_read_reg_bit_bit_pos,
8666 		NULL,
8667 	},
8668 };
8669 
8670 /* *** WRITE PORT REGISTER *** */
8671 struct cmd_write_reg_result {
8672 	cmdline_fixed_string_t write;
8673 	cmdline_fixed_string_t reg;
8674 	portid_t port_id;
8675 	uint32_t reg_off;
8676 	uint32_t value;
8677 };
8678 
8679 static void
8680 cmd_write_reg_parsed(void *parsed_result,
8681 		     __rte_unused struct cmdline *cl,
8682 		     __rte_unused void *data)
8683 {
8684 	struct cmd_write_reg_result *res = parsed_result;
8685 	port_reg_set(res->port_id, res->reg_off, res->value);
8686 }
8687 
8688 cmdline_parse_token_string_t cmd_write_reg_write =
8689 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8690 cmdline_parse_token_string_t cmd_write_reg_reg =
8691 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8692 cmdline_parse_token_num_t cmd_write_reg_port_id =
8693 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8694 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8695 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8696 cmdline_parse_token_num_t cmd_write_reg_value =
8697 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8698 
8699 cmdline_parse_inst_t cmd_write_reg = {
8700 	.f = cmd_write_reg_parsed,
8701 	.data = NULL,
8702 	.help_str = "write reg <port_id> <reg_off> <reg_value>",
8703 	.tokens = {
8704 		(void *)&cmd_write_reg_write,
8705 		(void *)&cmd_write_reg_reg,
8706 		(void *)&cmd_write_reg_port_id,
8707 		(void *)&cmd_write_reg_reg_off,
8708 		(void *)&cmd_write_reg_value,
8709 		NULL,
8710 	},
8711 };
8712 
8713 /* *** WRITE PORT REGISTER BIT FIELD *** */
8714 struct cmd_write_reg_bit_field_result {
8715 	cmdline_fixed_string_t write;
8716 	cmdline_fixed_string_t regfield;
8717 	portid_t port_id;
8718 	uint32_t reg_off;
8719 	uint8_t bit1_pos;
8720 	uint8_t bit2_pos;
8721 	uint32_t value;
8722 };
8723 
8724 static void
8725 cmd_write_reg_bit_field_parsed(void *parsed_result,
8726 			       __rte_unused struct cmdline *cl,
8727 			       __rte_unused void *data)
8728 {
8729 	struct cmd_write_reg_bit_field_result *res = parsed_result;
8730 	port_reg_bit_field_set(res->port_id, res->reg_off,
8731 			  res->bit1_pos, res->bit2_pos, res->value);
8732 }
8733 
8734 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8735 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8736 				 "write");
8737 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8738 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8739 				 regfield, "regfield");
8740 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8741 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8742 			      RTE_UINT16);
8743 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8744 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8745 			      RTE_UINT32);
8746 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8747 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8748 			      RTE_UINT8);
8749 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8750 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8751 			      RTE_UINT8);
8752 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8753 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8754 			      RTE_UINT32);
8755 
8756 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8757 	.f = cmd_write_reg_bit_field_parsed,
8758 	.data = NULL,
8759 	.help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8760 		"<reg_value>: "
8761 		"Set register bit field between bit_x and bit_y included",
8762 	.tokens = {
8763 		(void *)&cmd_write_reg_bit_field_write,
8764 		(void *)&cmd_write_reg_bit_field_regfield,
8765 		(void *)&cmd_write_reg_bit_field_port_id,
8766 		(void *)&cmd_write_reg_bit_field_reg_off,
8767 		(void *)&cmd_write_reg_bit_field_bit1_pos,
8768 		(void *)&cmd_write_reg_bit_field_bit2_pos,
8769 		(void *)&cmd_write_reg_bit_field_value,
8770 		NULL,
8771 	},
8772 };
8773 
8774 /* *** WRITE PORT REGISTER BIT *** */
8775 struct cmd_write_reg_bit_result {
8776 	cmdline_fixed_string_t write;
8777 	cmdline_fixed_string_t regbit;
8778 	portid_t port_id;
8779 	uint32_t reg_off;
8780 	uint8_t bit_pos;
8781 	uint8_t value;
8782 };
8783 
8784 static void
8785 cmd_write_reg_bit_parsed(void *parsed_result,
8786 			 __rte_unused struct cmdline *cl,
8787 			 __rte_unused void *data)
8788 {
8789 	struct cmd_write_reg_bit_result *res = parsed_result;
8790 	port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8791 }
8792 
8793 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8794 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8795 				 "write");
8796 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8797 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8798 				 regbit, "regbit");
8799 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8800 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8801 				 RTE_UINT16);
8802 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8803 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8804 				 RTE_UINT32);
8805 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8806 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8807 				 RTE_UINT8);
8808 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8809 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8810 				 RTE_UINT8);
8811 
8812 cmdline_parse_inst_t cmd_write_reg_bit = {
8813 	.f = cmd_write_reg_bit_parsed,
8814 	.data = NULL,
8815 	.help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8816 		"0 <= bit_x <= 31",
8817 	.tokens = {
8818 		(void *)&cmd_write_reg_bit_write,
8819 		(void *)&cmd_write_reg_bit_regbit,
8820 		(void *)&cmd_write_reg_bit_port_id,
8821 		(void *)&cmd_write_reg_bit_reg_off,
8822 		(void *)&cmd_write_reg_bit_bit_pos,
8823 		(void *)&cmd_write_reg_bit_value,
8824 		NULL,
8825 	},
8826 };
8827 
8828 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8829 struct cmd_read_rxd_txd_result {
8830 	cmdline_fixed_string_t read;
8831 	cmdline_fixed_string_t rxd_txd;
8832 	portid_t port_id;
8833 	uint16_t queue_id;
8834 	uint16_t desc_id;
8835 };
8836 
8837 static void
8838 cmd_read_rxd_txd_parsed(void *parsed_result,
8839 			__rte_unused struct cmdline *cl,
8840 			__rte_unused void *data)
8841 {
8842 	struct cmd_read_rxd_txd_result *res = parsed_result;
8843 
8844 	if (!strcmp(res->rxd_txd, "rxd"))
8845 		rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8846 	else if (!strcmp(res->rxd_txd, "txd"))
8847 		tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8848 }
8849 
8850 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8851 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8852 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8853 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8854 				 "rxd#txd");
8855 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8856 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8857 				 RTE_UINT16);
8858 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8859 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8860 				 RTE_UINT16);
8861 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8862 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8863 				 RTE_UINT16);
8864 
8865 cmdline_parse_inst_t cmd_read_rxd_txd = {
8866 	.f = cmd_read_rxd_txd_parsed,
8867 	.data = NULL,
8868 	.help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8869 	.tokens = {
8870 		(void *)&cmd_read_rxd_txd_read,
8871 		(void *)&cmd_read_rxd_txd_rxd_txd,
8872 		(void *)&cmd_read_rxd_txd_port_id,
8873 		(void *)&cmd_read_rxd_txd_queue_id,
8874 		(void *)&cmd_read_rxd_txd_desc_id,
8875 		NULL,
8876 	},
8877 };
8878 
8879 /* *** QUIT *** */
8880 struct cmd_quit_result {
8881 	cmdline_fixed_string_t quit;
8882 };
8883 
8884 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8885 			    struct cmdline *cl,
8886 			    __rte_unused void *data)
8887 {
8888 	cmdline_quit(cl);
8889 }
8890 
8891 cmdline_parse_token_string_t cmd_quit_quit =
8892 	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8893 
8894 cmdline_parse_inst_t cmd_quit = {
8895 	.f = cmd_quit_parsed,
8896 	.data = NULL,
8897 	.help_str = "quit: Exit application",
8898 	.tokens = {
8899 		(void *)&cmd_quit_quit,
8900 		NULL,
8901 	},
8902 };
8903 
8904 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8905 struct cmd_mac_addr_result {
8906 	cmdline_fixed_string_t mac_addr_cmd;
8907 	cmdline_fixed_string_t what;
8908 	uint16_t port_num;
8909 	struct rte_ether_addr address;
8910 };
8911 
8912 static void cmd_mac_addr_parsed(void *parsed_result,
8913 		__rte_unused struct cmdline *cl,
8914 		__rte_unused void *data)
8915 {
8916 	struct cmd_mac_addr_result *res = parsed_result;
8917 	int ret;
8918 
8919 	if (strcmp(res->what, "add") == 0)
8920 		ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8921 	else if (strcmp(res->what, "set") == 0)
8922 		ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8923 						       &res->address);
8924 	else
8925 		ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8926 
8927 	/* check the return value and print it if is < 0 */
8928 	if(ret < 0)
8929 		fprintf(stderr, "mac_addr_cmd error: (%s)\n", strerror(-ret));
8930 
8931 }
8932 
8933 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8934 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8935 				"mac_addr");
8936 cmdline_parse_token_string_t cmd_mac_addr_what =
8937 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8938 				"add#remove#set");
8939 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8940 		TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8941 					RTE_UINT16);
8942 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8943 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8944 
8945 cmdline_parse_inst_t cmd_mac_addr = {
8946 	.f = cmd_mac_addr_parsed,
8947 	.data = (void *)0,
8948 	.help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8949 			"Add/Remove/Set MAC address on port_id",
8950 	.tokens = {
8951 		(void *)&cmd_mac_addr_cmd,
8952 		(void *)&cmd_mac_addr_what,
8953 		(void *)&cmd_mac_addr_portnum,
8954 		(void *)&cmd_mac_addr_addr,
8955 		NULL,
8956 	},
8957 };
8958 
8959 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8960 struct cmd_eth_peer_result {
8961 	cmdline_fixed_string_t set;
8962 	cmdline_fixed_string_t eth_peer;
8963 	portid_t port_id;
8964 	cmdline_fixed_string_t peer_addr;
8965 };
8966 
8967 static void cmd_set_eth_peer_parsed(void *parsed_result,
8968 			__rte_unused struct cmdline *cl,
8969 			__rte_unused void *data)
8970 {
8971 		struct cmd_eth_peer_result *res = parsed_result;
8972 
8973 		if (test_done == 0) {
8974 			fprintf(stderr, "Please stop forwarding first\n");
8975 			return;
8976 		}
8977 		if (!strcmp(res->eth_peer, "eth-peer")) {
8978 			set_fwd_eth_peer(res->port_id, res->peer_addr);
8979 			fwd_config_setup();
8980 		}
8981 }
8982 cmdline_parse_token_string_t cmd_eth_peer_set =
8983 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8984 cmdline_parse_token_string_t cmd_eth_peer =
8985 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8986 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8987 	TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8988 		RTE_UINT16);
8989 cmdline_parse_token_string_t cmd_eth_peer_addr =
8990 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8991 
8992 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8993 	.f = cmd_set_eth_peer_parsed,
8994 	.data = NULL,
8995 	.help_str = "set eth-peer <port_id> <peer_mac>",
8996 	.tokens = {
8997 		(void *)&cmd_eth_peer_set,
8998 		(void *)&cmd_eth_peer,
8999 		(void *)&cmd_eth_peer_port_id,
9000 		(void *)&cmd_eth_peer_addr,
9001 		NULL,
9002 	},
9003 };
9004 
9005 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
9006 struct cmd_set_qmap_result {
9007 	cmdline_fixed_string_t set;
9008 	cmdline_fixed_string_t qmap;
9009 	cmdline_fixed_string_t what;
9010 	portid_t port_id;
9011 	uint16_t queue_id;
9012 	uint8_t map_value;
9013 };
9014 
9015 static void
9016 cmd_set_qmap_parsed(void *parsed_result,
9017 		       __rte_unused struct cmdline *cl,
9018 		       __rte_unused void *data)
9019 {
9020 	struct cmd_set_qmap_result *res = parsed_result;
9021 	int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
9022 
9023 	set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
9024 }
9025 
9026 cmdline_parse_token_string_t cmd_setqmap_set =
9027 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9028 				 set, "set");
9029 cmdline_parse_token_string_t cmd_setqmap_qmap =
9030 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9031 				 qmap, "stat_qmap");
9032 cmdline_parse_token_string_t cmd_setqmap_what =
9033 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9034 				 what, "tx#rx");
9035 cmdline_parse_token_num_t cmd_setqmap_portid =
9036 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9037 			      port_id, RTE_UINT16);
9038 cmdline_parse_token_num_t cmd_setqmap_queueid =
9039 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9040 			      queue_id, RTE_UINT16);
9041 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
9042 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9043 			      map_value, RTE_UINT8);
9044 
9045 cmdline_parse_inst_t cmd_set_qmap = {
9046 	.f = cmd_set_qmap_parsed,
9047 	.data = NULL,
9048 	.help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
9049 		"Set statistics mapping value on tx|rx queue_id of port_id",
9050 	.tokens = {
9051 		(void *)&cmd_setqmap_set,
9052 		(void *)&cmd_setqmap_qmap,
9053 		(void *)&cmd_setqmap_what,
9054 		(void *)&cmd_setqmap_portid,
9055 		(void *)&cmd_setqmap_queueid,
9056 		(void *)&cmd_setqmap_mapvalue,
9057 		NULL,
9058 	},
9059 };
9060 
9061 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
9062 struct cmd_set_xstats_hide_zero_result {
9063 	cmdline_fixed_string_t keyword;
9064 	cmdline_fixed_string_t name;
9065 	cmdline_fixed_string_t on_off;
9066 };
9067 
9068 static void
9069 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
9070 			__rte_unused struct cmdline *cl,
9071 			__rte_unused void *data)
9072 {
9073 	struct cmd_set_xstats_hide_zero_result *res;
9074 	uint16_t on_off = 0;
9075 
9076 	res = parsed_result;
9077 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9078 	set_xstats_hide_zero(on_off);
9079 }
9080 
9081 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
9082 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9083 				 keyword, "set");
9084 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
9085 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9086 				 name, "xstats-hide-zero");
9087 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
9088 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9089 				 on_off, "on#off");
9090 
9091 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
9092 	.f = cmd_set_xstats_hide_zero_parsed,
9093 	.data = NULL,
9094 	.help_str = "set xstats-hide-zero on|off",
9095 	.tokens = {
9096 		(void *)&cmd_set_xstats_hide_zero_keyword,
9097 		(void *)&cmd_set_xstats_hide_zero_name,
9098 		(void *)&cmd_set_xstats_hide_zero_on_off,
9099 		NULL,
9100 	},
9101 };
9102 
9103 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
9104 struct cmd_set_record_core_cycles_result {
9105 	cmdline_fixed_string_t keyword;
9106 	cmdline_fixed_string_t name;
9107 	cmdline_fixed_string_t on_off;
9108 };
9109 
9110 static void
9111 cmd_set_record_core_cycles_parsed(void *parsed_result,
9112 			__rte_unused struct cmdline *cl,
9113 			__rte_unused void *data)
9114 {
9115 	struct cmd_set_record_core_cycles_result *res;
9116 	uint16_t on_off = 0;
9117 
9118 	res = parsed_result;
9119 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9120 	set_record_core_cycles(on_off);
9121 }
9122 
9123 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
9124 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9125 				 keyword, "set");
9126 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
9127 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9128 				 name, "record-core-cycles");
9129 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
9130 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9131 				 on_off, "on#off");
9132 
9133 cmdline_parse_inst_t cmd_set_record_core_cycles = {
9134 	.f = cmd_set_record_core_cycles_parsed,
9135 	.data = NULL,
9136 	.help_str = "set record-core-cycles on|off",
9137 	.tokens = {
9138 		(void *)&cmd_set_record_core_cycles_keyword,
9139 		(void *)&cmd_set_record_core_cycles_name,
9140 		(void *)&cmd_set_record_core_cycles_on_off,
9141 		NULL,
9142 	},
9143 };
9144 
9145 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
9146 struct cmd_set_record_burst_stats_result {
9147 	cmdline_fixed_string_t keyword;
9148 	cmdline_fixed_string_t name;
9149 	cmdline_fixed_string_t on_off;
9150 };
9151 
9152 static void
9153 cmd_set_record_burst_stats_parsed(void *parsed_result,
9154 			__rte_unused struct cmdline *cl,
9155 			__rte_unused void *data)
9156 {
9157 	struct cmd_set_record_burst_stats_result *res;
9158 	uint16_t on_off = 0;
9159 
9160 	res = parsed_result;
9161 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9162 	set_record_burst_stats(on_off);
9163 }
9164 
9165 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
9166 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9167 				 keyword, "set");
9168 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
9169 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9170 				 name, "record-burst-stats");
9171 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
9172 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9173 				 on_off, "on#off");
9174 
9175 cmdline_parse_inst_t cmd_set_record_burst_stats = {
9176 	.f = cmd_set_record_burst_stats_parsed,
9177 	.data = NULL,
9178 	.help_str = "set record-burst-stats on|off",
9179 	.tokens = {
9180 		(void *)&cmd_set_record_burst_stats_keyword,
9181 		(void *)&cmd_set_record_burst_stats_name,
9182 		(void *)&cmd_set_record_burst_stats_on_off,
9183 		NULL,
9184 	},
9185 };
9186 
9187 /* *** CONFIGURE UNICAST HASH TABLE *** */
9188 struct cmd_set_uc_hash_table {
9189 	cmdline_fixed_string_t set;
9190 	cmdline_fixed_string_t port;
9191 	portid_t port_id;
9192 	cmdline_fixed_string_t what;
9193 	struct rte_ether_addr address;
9194 	cmdline_fixed_string_t mode;
9195 };
9196 
9197 static void
9198 cmd_set_uc_hash_parsed(void *parsed_result,
9199 		       __rte_unused struct cmdline *cl,
9200 		       __rte_unused void *data)
9201 {
9202 	int ret=0;
9203 	struct cmd_set_uc_hash_table *res = parsed_result;
9204 
9205 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9206 
9207 	if (strcmp(res->what, "uta") == 0)
9208 		ret = rte_eth_dev_uc_hash_table_set(res->port_id,
9209 						&res->address,(uint8_t)is_on);
9210 	if (ret < 0)
9211 		fprintf(stderr,
9212 			"bad unicast hash table parameter, return code = %d\n",
9213 			ret);
9214 
9215 }
9216 
9217 cmdline_parse_token_string_t cmd_set_uc_hash_set =
9218 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9219 				 set, "set");
9220 cmdline_parse_token_string_t cmd_set_uc_hash_port =
9221 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9222 				 port, "port");
9223 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
9224 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
9225 			      port_id, RTE_UINT16);
9226 cmdline_parse_token_string_t cmd_set_uc_hash_what =
9227 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9228 				 what, "uta");
9229 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
9230 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
9231 				address);
9232 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
9233 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9234 				 mode, "on#off");
9235 
9236 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
9237 	.f = cmd_set_uc_hash_parsed,
9238 	.data = NULL,
9239 	.help_str = "set port <port_id> uta <mac_addr> on|off)",
9240 	.tokens = {
9241 		(void *)&cmd_set_uc_hash_set,
9242 		(void *)&cmd_set_uc_hash_port,
9243 		(void *)&cmd_set_uc_hash_portid,
9244 		(void *)&cmd_set_uc_hash_what,
9245 		(void *)&cmd_set_uc_hash_mac,
9246 		(void *)&cmd_set_uc_hash_mode,
9247 		NULL,
9248 	},
9249 };
9250 
9251 struct cmd_set_uc_all_hash_table {
9252 	cmdline_fixed_string_t set;
9253 	cmdline_fixed_string_t port;
9254 	portid_t port_id;
9255 	cmdline_fixed_string_t what;
9256 	cmdline_fixed_string_t value;
9257 	cmdline_fixed_string_t mode;
9258 };
9259 
9260 static void
9261 cmd_set_uc_all_hash_parsed(void *parsed_result,
9262 		       __rte_unused struct cmdline *cl,
9263 		       __rte_unused void *data)
9264 {
9265 	int ret=0;
9266 	struct cmd_set_uc_all_hash_table *res = parsed_result;
9267 
9268 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9269 
9270 	if ((strcmp(res->what, "uta") == 0) &&
9271 		(strcmp(res->value, "all") == 0))
9272 		ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
9273 	if (ret < 0)
9274 		fprintf(stderr,
9275 			"bad unicast hash table parameter, return code = %d\n",
9276 			ret);
9277 }
9278 
9279 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
9280 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9281 				 set, "set");
9282 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
9283 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9284 				 port, "port");
9285 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
9286 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
9287 			      port_id, RTE_UINT16);
9288 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
9289 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9290 				 what, "uta");
9291 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
9292 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9293 				value,"all");
9294 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
9295 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9296 				 mode, "on#off");
9297 
9298 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
9299 	.f = cmd_set_uc_all_hash_parsed,
9300 	.data = NULL,
9301 	.help_str = "set port <port_id> uta all on|off",
9302 	.tokens = {
9303 		(void *)&cmd_set_uc_all_hash_set,
9304 		(void *)&cmd_set_uc_all_hash_port,
9305 		(void *)&cmd_set_uc_all_hash_portid,
9306 		(void *)&cmd_set_uc_all_hash_what,
9307 		(void *)&cmd_set_uc_all_hash_value,
9308 		(void *)&cmd_set_uc_all_hash_mode,
9309 		NULL,
9310 	},
9311 };
9312 
9313 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
9314 struct cmd_set_vf_traffic {
9315 	cmdline_fixed_string_t set;
9316 	cmdline_fixed_string_t port;
9317 	portid_t port_id;
9318 	cmdline_fixed_string_t vf;
9319 	uint8_t vf_id;
9320 	cmdline_fixed_string_t what;
9321 	cmdline_fixed_string_t mode;
9322 };
9323 
9324 static void
9325 cmd_set_vf_traffic_parsed(void *parsed_result,
9326 		       __rte_unused struct cmdline *cl,
9327 		       __rte_unused void *data)
9328 {
9329 	struct cmd_set_vf_traffic *res = parsed_result;
9330 	int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
9331 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9332 
9333 	set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
9334 }
9335 
9336 cmdline_parse_token_string_t cmd_setvf_traffic_set =
9337 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9338 				 set, "set");
9339 cmdline_parse_token_string_t cmd_setvf_traffic_port =
9340 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9341 				 port, "port");
9342 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
9343 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9344 			      port_id, RTE_UINT16);
9345 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
9346 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9347 				 vf, "vf");
9348 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
9349 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9350 			      vf_id, RTE_UINT8);
9351 cmdline_parse_token_string_t cmd_setvf_traffic_what =
9352 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9353 				 what, "tx#rx");
9354 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
9355 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9356 				 mode, "on#off");
9357 
9358 cmdline_parse_inst_t cmd_set_vf_traffic = {
9359 	.f = cmd_set_vf_traffic_parsed,
9360 	.data = NULL,
9361 	.help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
9362 	.tokens = {
9363 		(void *)&cmd_setvf_traffic_set,
9364 		(void *)&cmd_setvf_traffic_port,
9365 		(void *)&cmd_setvf_traffic_portid,
9366 		(void *)&cmd_setvf_traffic_vf,
9367 		(void *)&cmd_setvf_traffic_vfid,
9368 		(void *)&cmd_setvf_traffic_what,
9369 		(void *)&cmd_setvf_traffic_mode,
9370 		NULL,
9371 	},
9372 };
9373 
9374 /* *** CONFIGURE VF RECEIVE MODE *** */
9375 struct cmd_set_vf_rxmode {
9376 	cmdline_fixed_string_t set;
9377 	cmdline_fixed_string_t port;
9378 	portid_t port_id;
9379 	cmdline_fixed_string_t vf;
9380 	uint8_t vf_id;
9381 	cmdline_fixed_string_t what;
9382 	cmdline_fixed_string_t mode;
9383 	cmdline_fixed_string_t on;
9384 };
9385 
9386 static void
9387 cmd_set_vf_rxmode_parsed(void *parsed_result,
9388 		       __rte_unused struct cmdline *cl,
9389 		       __rte_unused void *data)
9390 {
9391 	int ret = -ENOTSUP;
9392 	uint16_t vf_rxmode = 0;
9393 	struct cmd_set_vf_rxmode *res = parsed_result;
9394 
9395 	int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
9396 	if (!strcmp(res->what,"rxmode")) {
9397 		if (!strcmp(res->mode, "AUPE"))
9398 			vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_UNTAG;
9399 		else if (!strcmp(res->mode, "ROPE"))
9400 			vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_HASH_UC;
9401 		else if (!strcmp(res->mode, "BAM"))
9402 			vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_BROADCAST;
9403 		else if (!strncmp(res->mode, "MPE",3))
9404 			vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_MULTICAST;
9405 	}
9406 
9407 	RTE_SET_USED(is_on);
9408 	RTE_SET_USED(vf_rxmode);
9409 
9410 #ifdef RTE_NET_IXGBE
9411 	if (ret == -ENOTSUP)
9412 		ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
9413 						  vf_rxmode, (uint8_t)is_on);
9414 #endif
9415 #ifdef RTE_NET_BNXT
9416 	if (ret == -ENOTSUP)
9417 		ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
9418 						 vf_rxmode, (uint8_t)is_on);
9419 #endif
9420 	if (ret < 0)
9421 		fprintf(stderr,
9422 			"bad VF receive mode parameter, return code = %d\n",
9423 			ret);
9424 }
9425 
9426 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
9427 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9428 				 set, "set");
9429 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
9430 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9431 				 port, "port");
9432 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
9433 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9434 			      port_id, RTE_UINT16);
9435 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
9436 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9437 				 vf, "vf");
9438 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
9439 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9440 			      vf_id, RTE_UINT8);
9441 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
9442 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9443 				 what, "rxmode");
9444 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
9445 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9446 				 mode, "AUPE#ROPE#BAM#MPE");
9447 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
9448 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9449 				 on, "on#off");
9450 
9451 cmdline_parse_inst_t cmd_set_vf_rxmode = {
9452 	.f = cmd_set_vf_rxmode_parsed,
9453 	.data = NULL,
9454 	.help_str = "set port <port_id> vf <vf_id> rxmode "
9455 		"AUPE|ROPE|BAM|MPE on|off",
9456 	.tokens = {
9457 		(void *)&cmd_set_vf_rxmode_set,
9458 		(void *)&cmd_set_vf_rxmode_port,
9459 		(void *)&cmd_set_vf_rxmode_portid,
9460 		(void *)&cmd_set_vf_rxmode_vf,
9461 		(void *)&cmd_set_vf_rxmode_vfid,
9462 		(void *)&cmd_set_vf_rxmode_what,
9463 		(void *)&cmd_set_vf_rxmode_mode,
9464 		(void *)&cmd_set_vf_rxmode_on,
9465 		NULL,
9466 	},
9467 };
9468 
9469 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
9470 struct cmd_vf_mac_addr_result {
9471 	cmdline_fixed_string_t mac_addr_cmd;
9472 	cmdline_fixed_string_t what;
9473 	cmdline_fixed_string_t port;
9474 	uint16_t port_num;
9475 	cmdline_fixed_string_t vf;
9476 	uint8_t vf_num;
9477 	struct rte_ether_addr address;
9478 };
9479 
9480 static void cmd_vf_mac_addr_parsed(void *parsed_result,
9481 		__rte_unused struct cmdline *cl,
9482 		__rte_unused void *data)
9483 {
9484 	struct cmd_vf_mac_addr_result *res = parsed_result;
9485 	int ret = -ENOTSUP;
9486 
9487 	if (strcmp(res->what, "add") != 0)
9488 		return;
9489 
9490 #ifdef RTE_NET_I40E
9491 	if (ret == -ENOTSUP)
9492 		ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
9493 						   &res->address);
9494 #endif
9495 #ifdef RTE_NET_BNXT
9496 	if (ret == -ENOTSUP)
9497 		ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
9498 						res->vf_num);
9499 #endif
9500 
9501 	if(ret < 0)
9502 		fprintf(stderr, "vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
9503 
9504 }
9505 
9506 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
9507 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9508 				mac_addr_cmd,"mac_addr");
9509 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
9510 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9511 				what,"add");
9512 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
9513 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9514 				port,"port");
9515 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
9516 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9517 				port_num, RTE_UINT16);
9518 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
9519 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9520 				vf,"vf");
9521 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
9522 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9523 				vf_num, RTE_UINT8);
9524 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
9525 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
9526 				address);
9527 
9528 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
9529 	.f = cmd_vf_mac_addr_parsed,
9530 	.data = (void *)0,
9531 	.help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
9532 		"Add MAC address filtering for a VF on port_id",
9533 	.tokens = {
9534 		(void *)&cmd_vf_mac_addr_cmd,
9535 		(void *)&cmd_vf_mac_addr_what,
9536 		(void *)&cmd_vf_mac_addr_port,
9537 		(void *)&cmd_vf_mac_addr_portnum,
9538 		(void *)&cmd_vf_mac_addr_vf,
9539 		(void *)&cmd_vf_mac_addr_vfnum,
9540 		(void *)&cmd_vf_mac_addr_addr,
9541 		NULL,
9542 	},
9543 };
9544 
9545 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
9546 struct cmd_vf_rx_vlan_filter {
9547 	cmdline_fixed_string_t rx_vlan;
9548 	cmdline_fixed_string_t what;
9549 	uint16_t vlan_id;
9550 	cmdline_fixed_string_t port;
9551 	portid_t port_id;
9552 	cmdline_fixed_string_t vf;
9553 	uint64_t vf_mask;
9554 };
9555 
9556 static void
9557 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
9558 			  __rte_unused struct cmdline *cl,
9559 			  __rte_unused void *data)
9560 {
9561 	struct cmd_vf_rx_vlan_filter *res = parsed_result;
9562 	int ret = -ENOTSUP;
9563 
9564 	__rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9565 
9566 #ifdef RTE_NET_IXGBE
9567 	if (ret == -ENOTSUP)
9568 		ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9569 				res->vlan_id, res->vf_mask, is_add);
9570 #endif
9571 #ifdef RTE_NET_I40E
9572 	if (ret == -ENOTSUP)
9573 		ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9574 				res->vlan_id, res->vf_mask, is_add);
9575 #endif
9576 #ifdef RTE_NET_BNXT
9577 	if (ret == -ENOTSUP)
9578 		ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9579 				res->vlan_id, res->vf_mask, is_add);
9580 #endif
9581 
9582 	switch (ret) {
9583 	case 0:
9584 		break;
9585 	case -EINVAL:
9586 		fprintf(stderr, "invalid vlan_id %d or vf_mask %"PRIu64"\n",
9587 			res->vlan_id, res->vf_mask);
9588 		break;
9589 	case -ENODEV:
9590 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
9591 		break;
9592 	case -ENOTSUP:
9593 		fprintf(stderr, "function not implemented or supported\n");
9594 		break;
9595 	default:
9596 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
9597 	}
9598 }
9599 
9600 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9601 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9602 				 rx_vlan, "rx_vlan");
9603 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9604 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9605 				 what, "add#rm");
9606 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9607 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9608 			      vlan_id, RTE_UINT16);
9609 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9610 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9611 				 port, "port");
9612 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9613 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9614 			      port_id, RTE_UINT16);
9615 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9616 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9617 				 vf, "vf");
9618 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9619 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9620 			      vf_mask, RTE_UINT64);
9621 
9622 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9623 	.f = cmd_vf_rx_vlan_filter_parsed,
9624 	.data = NULL,
9625 	.help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9626 		"(vf_mask = hexadecimal VF mask)",
9627 	.tokens = {
9628 		(void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9629 		(void *)&cmd_vf_rx_vlan_filter_what,
9630 		(void *)&cmd_vf_rx_vlan_filter_vlanid,
9631 		(void *)&cmd_vf_rx_vlan_filter_port,
9632 		(void *)&cmd_vf_rx_vlan_filter_portid,
9633 		(void *)&cmd_vf_rx_vlan_filter_vf,
9634 		(void *)&cmd_vf_rx_vlan_filter_vf_mask,
9635 		NULL,
9636 	},
9637 };
9638 
9639 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9640 struct cmd_queue_rate_limit_result {
9641 	cmdline_fixed_string_t set;
9642 	cmdline_fixed_string_t port;
9643 	uint16_t port_num;
9644 	cmdline_fixed_string_t queue;
9645 	uint8_t queue_num;
9646 	cmdline_fixed_string_t rate;
9647 	uint16_t rate_num;
9648 };
9649 
9650 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9651 		__rte_unused struct cmdline *cl,
9652 		__rte_unused void *data)
9653 {
9654 	struct cmd_queue_rate_limit_result *res = parsed_result;
9655 	int ret = 0;
9656 
9657 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9658 		&& (strcmp(res->queue, "queue") == 0)
9659 		&& (strcmp(res->rate, "rate") == 0))
9660 		ret = set_queue_rate_limit(res->port_num, res->queue_num,
9661 					res->rate_num);
9662 	if (ret < 0)
9663 		fprintf(stderr, "queue_rate_limit_cmd error: (%s)\n",
9664 			strerror(-ret));
9665 
9666 }
9667 
9668 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9669 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9670 				set, "set");
9671 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9672 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9673 				port, "port");
9674 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9675 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9676 				port_num, RTE_UINT16);
9677 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9678 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9679 				queue, "queue");
9680 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9681 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9682 				queue_num, RTE_UINT8);
9683 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9684 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9685 				rate, "rate");
9686 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9687 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9688 				rate_num, RTE_UINT16);
9689 
9690 cmdline_parse_inst_t cmd_queue_rate_limit = {
9691 	.f = cmd_queue_rate_limit_parsed,
9692 	.data = (void *)0,
9693 	.help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9694 		"Set rate limit for a queue on port_id",
9695 	.tokens = {
9696 		(void *)&cmd_queue_rate_limit_set,
9697 		(void *)&cmd_queue_rate_limit_port,
9698 		(void *)&cmd_queue_rate_limit_portnum,
9699 		(void *)&cmd_queue_rate_limit_queue,
9700 		(void *)&cmd_queue_rate_limit_queuenum,
9701 		(void *)&cmd_queue_rate_limit_rate,
9702 		(void *)&cmd_queue_rate_limit_ratenum,
9703 		NULL,
9704 	},
9705 };
9706 
9707 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9708 struct cmd_vf_rate_limit_result {
9709 	cmdline_fixed_string_t set;
9710 	cmdline_fixed_string_t port;
9711 	uint16_t port_num;
9712 	cmdline_fixed_string_t vf;
9713 	uint8_t vf_num;
9714 	cmdline_fixed_string_t rate;
9715 	uint16_t rate_num;
9716 	cmdline_fixed_string_t q_msk;
9717 	uint64_t q_msk_val;
9718 };
9719 
9720 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9721 		__rte_unused struct cmdline *cl,
9722 		__rte_unused void *data)
9723 {
9724 	struct cmd_vf_rate_limit_result *res = parsed_result;
9725 	int ret = 0;
9726 
9727 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9728 		&& (strcmp(res->vf, "vf") == 0)
9729 		&& (strcmp(res->rate, "rate") == 0)
9730 		&& (strcmp(res->q_msk, "queue_mask") == 0))
9731 		ret = set_vf_rate_limit(res->port_num, res->vf_num,
9732 					res->rate_num, res->q_msk_val);
9733 	if (ret < 0)
9734 		fprintf(stderr, "vf_rate_limit_cmd error: (%s)\n",
9735 			strerror(-ret));
9736 
9737 }
9738 
9739 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9740 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9741 				set, "set");
9742 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9743 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9744 				port, "port");
9745 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9746 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9747 				port_num, RTE_UINT16);
9748 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9749 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9750 				vf, "vf");
9751 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9752 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9753 				vf_num, RTE_UINT8);
9754 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9755 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9756 				rate, "rate");
9757 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9758 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9759 				rate_num, RTE_UINT16);
9760 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9761 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9762 				q_msk, "queue_mask");
9763 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9764 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9765 				q_msk_val, RTE_UINT64);
9766 
9767 cmdline_parse_inst_t cmd_vf_rate_limit = {
9768 	.f = cmd_vf_rate_limit_parsed,
9769 	.data = (void *)0,
9770 	.help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9771 		"queue_mask <queue_mask_value>: "
9772 		"Set rate limit for queues of VF on port_id",
9773 	.tokens = {
9774 		(void *)&cmd_vf_rate_limit_set,
9775 		(void *)&cmd_vf_rate_limit_port,
9776 		(void *)&cmd_vf_rate_limit_portnum,
9777 		(void *)&cmd_vf_rate_limit_vf,
9778 		(void *)&cmd_vf_rate_limit_vfnum,
9779 		(void *)&cmd_vf_rate_limit_rate,
9780 		(void *)&cmd_vf_rate_limit_ratenum,
9781 		(void *)&cmd_vf_rate_limit_q_msk,
9782 		(void *)&cmd_vf_rate_limit_q_msk_val,
9783 		NULL,
9784 	},
9785 };
9786 
9787 /* *** CONFIGURE TUNNEL UDP PORT *** */
9788 struct cmd_tunnel_udp_config {
9789 	cmdline_fixed_string_t rx_vxlan_port;
9790 	cmdline_fixed_string_t what;
9791 	uint16_t udp_port;
9792 	portid_t port_id;
9793 };
9794 
9795 static void
9796 cmd_tunnel_udp_config_parsed(void *parsed_result,
9797 			  __rte_unused struct cmdline *cl,
9798 			  __rte_unused void *data)
9799 {
9800 	struct cmd_tunnel_udp_config *res = parsed_result;
9801 	struct rte_eth_udp_tunnel tunnel_udp;
9802 	int ret;
9803 
9804 	tunnel_udp.udp_port = res->udp_port;
9805 	tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9806 
9807 	if (!strcmp(res->what, "add"))
9808 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9809 						      &tunnel_udp);
9810 	else
9811 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9812 							 &tunnel_udp);
9813 
9814 	if (ret < 0)
9815 		fprintf(stderr, "udp tunneling add error: (%s)\n",
9816 			strerror(-ret));
9817 }
9818 
9819 cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
9820 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9821 				rx_vxlan_port, "rx_vxlan_port");
9822 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9823 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9824 				what, "add#rm");
9825 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9826 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9827 				udp_port, RTE_UINT16);
9828 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9829 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9830 				port_id, RTE_UINT16);
9831 
9832 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9833 	.f = cmd_tunnel_udp_config_parsed,
9834 	.data = (void *)0,
9835 	.help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9836 		"Add/Remove a tunneling UDP port filter",
9837 	.tokens = {
9838 		(void *)&cmd_tunnel_udp_config_rx_vxlan_port,
9839 		(void *)&cmd_tunnel_udp_config_what,
9840 		(void *)&cmd_tunnel_udp_config_udp_port,
9841 		(void *)&cmd_tunnel_udp_config_port_id,
9842 		NULL,
9843 	},
9844 };
9845 
9846 struct cmd_config_tunnel_udp_port {
9847 	cmdline_fixed_string_t port;
9848 	cmdline_fixed_string_t config;
9849 	portid_t port_id;
9850 	cmdline_fixed_string_t udp_tunnel_port;
9851 	cmdline_fixed_string_t action;
9852 	cmdline_fixed_string_t tunnel_type;
9853 	uint16_t udp_port;
9854 };
9855 
9856 static void
9857 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9858 			       __rte_unused struct cmdline *cl,
9859 			       __rte_unused void *data)
9860 {
9861 	struct cmd_config_tunnel_udp_port *res = parsed_result;
9862 	struct rte_eth_udp_tunnel tunnel_udp;
9863 	int ret = 0;
9864 
9865 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9866 		return;
9867 
9868 	tunnel_udp.udp_port = res->udp_port;
9869 
9870 	if (!strcmp(res->tunnel_type, "vxlan")) {
9871 		tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9872 	} else if (!strcmp(res->tunnel_type, "geneve")) {
9873 		tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_GENEVE;
9874 	} else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9875 		tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN_GPE;
9876 	} else if (!strcmp(res->tunnel_type, "ecpri")) {
9877 		tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_ECPRI;
9878 	} else {
9879 		fprintf(stderr, "Invalid tunnel type\n");
9880 		return;
9881 	}
9882 
9883 	if (!strcmp(res->action, "add"))
9884 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9885 						      &tunnel_udp);
9886 	else
9887 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9888 							 &tunnel_udp);
9889 
9890 	if (ret < 0)
9891 		fprintf(stderr, "udp tunneling port add error: (%s)\n",
9892 			strerror(-ret));
9893 }
9894 
9895 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9896 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9897 				 "port");
9898 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9899 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9900 				 "config");
9901 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9902 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9903 			      RTE_UINT16);
9904 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9905 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9906 				 udp_tunnel_port,
9907 				 "udp_tunnel_port");
9908 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9909 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9910 				 "add#rm");
9911 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9912 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9913 				 "vxlan#geneve#vxlan-gpe#ecpri");
9914 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9915 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9916 			      RTE_UINT16);
9917 
9918 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9919 	.f = cmd_cfg_tunnel_udp_port_parsed,
9920 	.data = NULL,
9921 	.help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9922 		"geneve|vxlan-gpe|ecpri <udp_port>",
9923 	.tokens = {
9924 		(void *)&cmd_config_tunnel_udp_port_port,
9925 		(void *)&cmd_config_tunnel_udp_port_config,
9926 		(void *)&cmd_config_tunnel_udp_port_port_id,
9927 		(void *)&cmd_config_tunnel_udp_port_tunnel_port,
9928 		(void *)&cmd_config_tunnel_udp_port_action,
9929 		(void *)&cmd_config_tunnel_udp_port_tunnel_type,
9930 		(void *)&cmd_config_tunnel_udp_port_value,
9931 		NULL,
9932 	},
9933 };
9934 
9935 /* ******************************************************************************** */
9936 
9937 struct cmd_dump_result {
9938 	cmdline_fixed_string_t dump;
9939 };
9940 
9941 static void
9942 dump_struct_sizes(void)
9943 {
9944 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9945 	DUMP_SIZE(struct rte_mbuf);
9946 	DUMP_SIZE(struct rte_mempool);
9947 	DUMP_SIZE(struct rte_ring);
9948 #undef DUMP_SIZE
9949 }
9950 
9951 
9952 /* Dump the socket memory statistics on console */
9953 static void
9954 dump_socket_mem(FILE *f)
9955 {
9956 	struct rte_malloc_socket_stats socket_stats;
9957 	unsigned int i;
9958 	size_t total = 0;
9959 	size_t alloc = 0;
9960 	size_t free = 0;
9961 	unsigned int n_alloc = 0;
9962 	unsigned int n_free = 0;
9963 	static size_t last_allocs;
9964 	static size_t last_total;
9965 
9966 
9967 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9968 		if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9969 		    !socket_stats.heap_totalsz_bytes)
9970 			continue;
9971 		total += socket_stats.heap_totalsz_bytes;
9972 		alloc += socket_stats.heap_allocsz_bytes;
9973 		free += socket_stats.heap_freesz_bytes;
9974 		n_alloc += socket_stats.alloc_count;
9975 		n_free += socket_stats.free_count;
9976 		fprintf(f,
9977 			"Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9978 			i,
9979 			(double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9980 			(double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9981 			(double)socket_stats.heap_allocsz_bytes * 100 /
9982 			(double)socket_stats.heap_totalsz_bytes,
9983 			(double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9984 			socket_stats.alloc_count,
9985 			socket_stats.free_count);
9986 	}
9987 	fprintf(f,
9988 		"Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9989 		(double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9990 		total ? ((double)alloc * 100 / (double)total) : 0,
9991 		(double)free / (1024 * 1024),
9992 		n_alloc, n_free);
9993 	if (last_allocs)
9994 		fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9995 			((double)total - (double)last_total) / (1024 * 1024),
9996 			(double)(alloc - (double)last_allocs) / 1024 / 1024);
9997 	last_allocs = alloc;
9998 	last_total = total;
9999 }
10000 
10001 static void cmd_dump_parsed(void *parsed_result,
10002 			    __rte_unused struct cmdline *cl,
10003 			    __rte_unused void *data)
10004 {
10005 	struct cmd_dump_result *res = parsed_result;
10006 
10007 	if (!strcmp(res->dump, "dump_physmem"))
10008 		rte_dump_physmem_layout(stdout);
10009 	else if (!strcmp(res->dump, "dump_socket_mem"))
10010 		dump_socket_mem(stdout);
10011 	else if (!strcmp(res->dump, "dump_memzone"))
10012 		rte_memzone_dump(stdout);
10013 	else if (!strcmp(res->dump, "dump_struct_sizes"))
10014 		dump_struct_sizes();
10015 	else if (!strcmp(res->dump, "dump_ring"))
10016 		rte_ring_list_dump(stdout);
10017 	else if (!strcmp(res->dump, "dump_mempool"))
10018 		rte_mempool_list_dump(stdout);
10019 	else if (!strcmp(res->dump, "dump_devargs"))
10020 		rte_devargs_dump(stdout);
10021 	else if (!strcmp(res->dump, "dump_log_types"))
10022 		rte_log_dump(stdout);
10023 }
10024 
10025 cmdline_parse_token_string_t cmd_dump_dump =
10026 	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
10027 		"dump_physmem#"
10028 		"dump_memzone#"
10029 		"dump_socket_mem#"
10030 		"dump_struct_sizes#"
10031 		"dump_ring#"
10032 		"dump_mempool#"
10033 		"dump_devargs#"
10034 		"dump_log_types");
10035 
10036 cmdline_parse_inst_t cmd_dump = {
10037 	.f = cmd_dump_parsed,  /* function to call */
10038 	.data = NULL,      /* 2nd arg of func */
10039 	.help_str = "Dump status",
10040 	.tokens = {        /* token list, NULL terminated */
10041 		(void *)&cmd_dump_dump,
10042 		NULL,
10043 	},
10044 };
10045 
10046 /* ******************************************************************************** */
10047 
10048 struct cmd_dump_one_result {
10049 	cmdline_fixed_string_t dump;
10050 	cmdline_fixed_string_t name;
10051 };
10052 
10053 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
10054 				__rte_unused void *data)
10055 {
10056 	struct cmd_dump_one_result *res = parsed_result;
10057 
10058 	if (!strcmp(res->dump, "dump_ring")) {
10059 		struct rte_ring *r;
10060 		r = rte_ring_lookup(res->name);
10061 		if (r == NULL) {
10062 			cmdline_printf(cl, "Cannot find ring\n");
10063 			return;
10064 		}
10065 		rte_ring_dump(stdout, r);
10066 	} else if (!strcmp(res->dump, "dump_mempool")) {
10067 		struct rte_mempool *mp;
10068 		mp = rte_mempool_lookup(res->name);
10069 		if (mp == NULL) {
10070 			cmdline_printf(cl, "Cannot find mempool\n");
10071 			return;
10072 		}
10073 		rte_mempool_dump(stdout, mp);
10074 	}
10075 }
10076 
10077 cmdline_parse_token_string_t cmd_dump_one_dump =
10078 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
10079 				 "dump_ring#dump_mempool");
10080 
10081 cmdline_parse_token_string_t cmd_dump_one_name =
10082 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
10083 
10084 cmdline_parse_inst_t cmd_dump_one = {
10085 	.f = cmd_dump_one_parsed,  /* function to call */
10086 	.data = NULL,      /* 2nd arg of func */
10087 	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
10088 	.tokens = {        /* token list, NULL terminated */
10089 		(void *)&cmd_dump_one_dump,
10090 		(void *)&cmd_dump_one_name,
10091 		NULL,
10092 	},
10093 };
10094 
10095 /* *** queue region set *** */
10096 struct cmd_queue_region_result {
10097 	cmdline_fixed_string_t set;
10098 	cmdline_fixed_string_t port;
10099 	portid_t port_id;
10100 	cmdline_fixed_string_t cmd;
10101 	cmdline_fixed_string_t region;
10102 	uint8_t  region_id;
10103 	cmdline_fixed_string_t queue_start_index;
10104 	uint8_t  queue_id;
10105 	cmdline_fixed_string_t queue_num;
10106 	uint8_t  queue_num_value;
10107 };
10108 
10109 static void
10110 cmd_queue_region_parsed(void *parsed_result,
10111 			__rte_unused struct cmdline *cl,
10112 			__rte_unused void *data)
10113 {
10114 	struct cmd_queue_region_result *res = parsed_result;
10115 	int ret = -ENOTSUP;
10116 #ifdef RTE_NET_I40E
10117 	struct rte_pmd_i40e_queue_region_conf region_conf;
10118 	enum rte_pmd_i40e_queue_region_op op_type;
10119 #endif
10120 
10121 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10122 		return;
10123 
10124 #ifdef RTE_NET_I40E
10125 	memset(&region_conf, 0, sizeof(region_conf));
10126 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10127 	region_conf.region_id = res->region_id;
10128 	region_conf.queue_num = res->queue_num_value;
10129 	region_conf.queue_start_index = res->queue_id;
10130 
10131 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10132 				op_type, &region_conf);
10133 #endif
10134 
10135 	switch (ret) {
10136 	case 0:
10137 		break;
10138 	case -ENOTSUP:
10139 		fprintf(stderr, "function not implemented or supported\n");
10140 		break;
10141 	default:
10142 		fprintf(stderr, "queue region config error: (%s)\n",
10143 			strerror(-ret));
10144 	}
10145 }
10146 
10147 cmdline_parse_token_string_t cmd_queue_region_set =
10148 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10149 		set, "set");
10150 cmdline_parse_token_string_t cmd_queue_region_port =
10151 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10152 cmdline_parse_token_num_t cmd_queue_region_port_id =
10153 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10154 				port_id, RTE_UINT16);
10155 cmdline_parse_token_string_t cmd_queue_region_cmd =
10156 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10157 				 cmd, "queue-region");
10158 cmdline_parse_token_string_t cmd_queue_region_id =
10159 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10160 				region, "region_id");
10161 cmdline_parse_token_num_t cmd_queue_region_index =
10162 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10163 				region_id, RTE_UINT8);
10164 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10165 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10166 				queue_start_index, "queue_start_index");
10167 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10168 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10169 				queue_id, RTE_UINT8);
10170 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10171 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10172 				queue_num, "queue_num");
10173 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10174 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10175 				queue_num_value, RTE_UINT8);
10176 
10177 cmdline_parse_inst_t cmd_queue_region = {
10178 	.f = cmd_queue_region_parsed,
10179 	.data = NULL,
10180 	.help_str = "set port <port_id> queue-region region_id <value> "
10181 		"queue_start_index <value> queue_num <value>: Set a queue region",
10182 	.tokens = {
10183 		(void *)&cmd_queue_region_set,
10184 		(void *)&cmd_queue_region_port,
10185 		(void *)&cmd_queue_region_port_id,
10186 		(void *)&cmd_queue_region_cmd,
10187 		(void *)&cmd_queue_region_id,
10188 		(void *)&cmd_queue_region_index,
10189 		(void *)&cmd_queue_region_queue_start_index,
10190 		(void *)&cmd_queue_region_queue_id,
10191 		(void *)&cmd_queue_region_queue_num,
10192 		(void *)&cmd_queue_region_queue_num_value,
10193 		NULL,
10194 	},
10195 };
10196 
10197 /* *** queue region and flowtype set *** */
10198 struct cmd_region_flowtype_result {
10199 	cmdline_fixed_string_t set;
10200 	cmdline_fixed_string_t port;
10201 	portid_t port_id;
10202 	cmdline_fixed_string_t cmd;
10203 	cmdline_fixed_string_t region;
10204 	uint8_t  region_id;
10205 	cmdline_fixed_string_t flowtype;
10206 	uint8_t  flowtype_id;
10207 };
10208 
10209 static void
10210 cmd_region_flowtype_parsed(void *parsed_result,
10211 			__rte_unused struct cmdline *cl,
10212 			__rte_unused void *data)
10213 {
10214 	struct cmd_region_flowtype_result *res = parsed_result;
10215 	int ret = -ENOTSUP;
10216 #ifdef RTE_NET_I40E
10217 	struct rte_pmd_i40e_queue_region_conf region_conf;
10218 	enum rte_pmd_i40e_queue_region_op op_type;
10219 #endif
10220 
10221 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10222 		return;
10223 
10224 #ifdef RTE_NET_I40E
10225 	memset(&region_conf, 0, sizeof(region_conf));
10226 
10227 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10228 	region_conf.region_id = res->region_id;
10229 	region_conf.hw_flowtype = res->flowtype_id;
10230 
10231 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10232 			op_type, &region_conf);
10233 #endif
10234 
10235 	switch (ret) {
10236 	case 0:
10237 		break;
10238 	case -ENOTSUP:
10239 		fprintf(stderr, "function not implemented or supported\n");
10240 		break;
10241 	default:
10242 		fprintf(stderr, "region flowtype config error: (%s)\n",
10243 			strerror(-ret));
10244 	}
10245 }
10246 
10247 cmdline_parse_token_string_t cmd_region_flowtype_set =
10248 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10249 				set, "set");
10250 cmdline_parse_token_string_t cmd_region_flowtype_port =
10251 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10252 				port, "port");
10253 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10254 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10255 				port_id, RTE_UINT16);
10256 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10257 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10258 				cmd, "queue-region");
10259 cmdline_parse_token_string_t cmd_region_flowtype_index =
10260 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10261 				region, "region_id");
10262 cmdline_parse_token_num_t cmd_region_flowtype_id =
10263 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10264 				region_id, RTE_UINT8);
10265 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10266 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10267 				flowtype, "flowtype");
10268 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10269 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10270 				flowtype_id, RTE_UINT8);
10271 cmdline_parse_inst_t cmd_region_flowtype = {
10272 	.f = cmd_region_flowtype_parsed,
10273 	.data = NULL,
10274 	.help_str = "set port <port_id> queue-region region_id <value> "
10275 		"flowtype <value>: Set a flowtype region index",
10276 	.tokens = {
10277 		(void *)&cmd_region_flowtype_set,
10278 		(void *)&cmd_region_flowtype_port,
10279 		(void *)&cmd_region_flowtype_port_index,
10280 		(void *)&cmd_region_flowtype_cmd,
10281 		(void *)&cmd_region_flowtype_index,
10282 		(void *)&cmd_region_flowtype_id,
10283 		(void *)&cmd_region_flowtype_flow_index,
10284 		(void *)&cmd_region_flowtype_flow_id,
10285 		NULL,
10286 	},
10287 };
10288 
10289 /* *** User Priority (UP) to queue region (region_id) set *** */
10290 struct cmd_user_priority_region_result {
10291 	cmdline_fixed_string_t set;
10292 	cmdline_fixed_string_t port;
10293 	portid_t port_id;
10294 	cmdline_fixed_string_t cmd;
10295 	cmdline_fixed_string_t user_priority;
10296 	uint8_t  user_priority_id;
10297 	cmdline_fixed_string_t region;
10298 	uint8_t  region_id;
10299 };
10300 
10301 static void
10302 cmd_user_priority_region_parsed(void *parsed_result,
10303 			__rte_unused struct cmdline *cl,
10304 			__rte_unused void *data)
10305 {
10306 	struct cmd_user_priority_region_result *res = parsed_result;
10307 	int ret = -ENOTSUP;
10308 #ifdef RTE_NET_I40E
10309 	struct rte_pmd_i40e_queue_region_conf region_conf;
10310 	enum rte_pmd_i40e_queue_region_op op_type;
10311 #endif
10312 
10313 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10314 		return;
10315 
10316 #ifdef RTE_NET_I40E
10317 	memset(&region_conf, 0, sizeof(region_conf));
10318 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10319 	region_conf.user_priority = res->user_priority_id;
10320 	region_conf.region_id = res->region_id;
10321 
10322 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10323 				op_type, &region_conf);
10324 #endif
10325 
10326 	switch (ret) {
10327 	case 0:
10328 		break;
10329 	case -ENOTSUP:
10330 		fprintf(stderr, "function not implemented or supported\n");
10331 		break;
10332 	default:
10333 		fprintf(stderr, "user_priority region config error: (%s)\n",
10334 			strerror(-ret));
10335 	}
10336 }
10337 
10338 cmdline_parse_token_string_t cmd_user_priority_region_set =
10339 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10340 				set, "set");
10341 cmdline_parse_token_string_t cmd_user_priority_region_port =
10342 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10343 				port, "port");
10344 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10345 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10346 				port_id, RTE_UINT16);
10347 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10348 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10349 				cmd, "queue-region");
10350 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10351 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10352 				user_priority, "UP");
10353 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10354 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10355 				user_priority_id, RTE_UINT8);
10356 cmdline_parse_token_string_t cmd_user_priority_region_region =
10357 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10358 				region, "region_id");
10359 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10360 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10361 				region_id, RTE_UINT8);
10362 
10363 cmdline_parse_inst_t cmd_user_priority_region = {
10364 	.f = cmd_user_priority_region_parsed,
10365 	.data = NULL,
10366 	.help_str = "set port <port_id> queue-region UP <value> "
10367 		"region_id <value>: Set the mapping of User Priority (UP) "
10368 		"to queue region (region_id) ",
10369 	.tokens = {
10370 		(void *)&cmd_user_priority_region_set,
10371 		(void *)&cmd_user_priority_region_port,
10372 		(void *)&cmd_user_priority_region_port_index,
10373 		(void *)&cmd_user_priority_region_cmd,
10374 		(void *)&cmd_user_priority_region_UP,
10375 		(void *)&cmd_user_priority_region_UP_id,
10376 		(void *)&cmd_user_priority_region_region,
10377 		(void *)&cmd_user_priority_region_region_id,
10378 		NULL,
10379 	},
10380 };
10381 
10382 /* *** flush all queue region related configuration *** */
10383 struct cmd_flush_queue_region_result {
10384 	cmdline_fixed_string_t set;
10385 	cmdline_fixed_string_t port;
10386 	portid_t port_id;
10387 	cmdline_fixed_string_t cmd;
10388 	cmdline_fixed_string_t flush;
10389 	cmdline_fixed_string_t what;
10390 };
10391 
10392 static void
10393 cmd_flush_queue_region_parsed(void *parsed_result,
10394 			__rte_unused struct cmdline *cl,
10395 			__rte_unused void *data)
10396 {
10397 	struct cmd_flush_queue_region_result *res = parsed_result;
10398 	int ret = -ENOTSUP;
10399 #ifdef RTE_NET_I40E
10400 	struct rte_pmd_i40e_queue_region_conf region_conf;
10401 	enum rte_pmd_i40e_queue_region_op op_type;
10402 #endif
10403 
10404 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10405 		return;
10406 
10407 #ifdef RTE_NET_I40E
10408 	memset(&region_conf, 0, sizeof(region_conf));
10409 
10410 	if (strcmp(res->what, "on") == 0)
10411 		op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10412 	else
10413 		op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10414 
10415 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10416 				op_type, &region_conf);
10417 #endif
10418 
10419 	switch (ret) {
10420 	case 0:
10421 		break;
10422 	case -ENOTSUP:
10423 		fprintf(stderr, "function not implemented or supported\n");
10424 		break;
10425 	default:
10426 		fprintf(stderr, "queue region config flush error: (%s)\n",
10427 			strerror(-ret));
10428 	}
10429 }
10430 
10431 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10432 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10433 				set, "set");
10434 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10435 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10436 				port, "port");
10437 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10438 	TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10439 				port_id, RTE_UINT16);
10440 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10441 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10442 				cmd, "queue-region");
10443 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10444 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10445 				flush, "flush");
10446 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10447 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10448 				what, "on#off");
10449 
10450 cmdline_parse_inst_t cmd_flush_queue_region = {
10451 	.f = cmd_flush_queue_region_parsed,
10452 	.data = NULL,
10453 	.help_str = "set port <port_id> queue-region flush on|off"
10454 		": flush all queue region related configuration",
10455 	.tokens = {
10456 		(void *)&cmd_flush_queue_region_set,
10457 		(void *)&cmd_flush_queue_region_port,
10458 		(void *)&cmd_flush_queue_region_port_index,
10459 		(void *)&cmd_flush_queue_region_cmd,
10460 		(void *)&cmd_flush_queue_region_flush,
10461 		(void *)&cmd_flush_queue_region_what,
10462 		NULL,
10463 	},
10464 };
10465 
10466 /* *** get all queue region related configuration info *** */
10467 struct cmd_show_queue_region_info {
10468 	cmdline_fixed_string_t show;
10469 	cmdline_fixed_string_t port;
10470 	portid_t port_id;
10471 	cmdline_fixed_string_t cmd;
10472 };
10473 
10474 static void
10475 cmd_show_queue_region_info_parsed(void *parsed_result,
10476 			__rte_unused struct cmdline *cl,
10477 			__rte_unused void *data)
10478 {
10479 	struct cmd_show_queue_region_info *res = parsed_result;
10480 	int ret = -ENOTSUP;
10481 #ifdef RTE_NET_I40E
10482 	struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10483 	enum rte_pmd_i40e_queue_region_op op_type;
10484 #endif
10485 
10486 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10487 		return;
10488 
10489 #ifdef RTE_NET_I40E
10490 	memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10491 
10492 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10493 
10494 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10495 					op_type, &rte_pmd_regions);
10496 
10497 	port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10498 #endif
10499 
10500 	switch (ret) {
10501 	case 0:
10502 		break;
10503 	case -ENOTSUP:
10504 		fprintf(stderr, "function not implemented or supported\n");
10505 		break;
10506 	default:
10507 		fprintf(stderr, "queue region config info show error: (%s)\n",
10508 			strerror(-ret));
10509 	}
10510 }
10511 
10512 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10513 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10514 				show, "show");
10515 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10516 	TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10517 				port, "port");
10518 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10519 	TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10520 				port_id, RTE_UINT16);
10521 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10522 	TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10523 				cmd, "queue-region");
10524 
10525 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10526 	.f = cmd_show_queue_region_info_parsed,
10527 	.data = NULL,
10528 	.help_str = "show port <port_id> queue-region"
10529 		": show all queue region related configuration info",
10530 	.tokens = {
10531 		(void *)&cmd_show_queue_region_info_get,
10532 		(void *)&cmd_show_queue_region_info_port,
10533 		(void *)&cmd_show_queue_region_info_port_index,
10534 		(void *)&cmd_show_queue_region_info_cmd,
10535 		NULL,
10536 	},
10537 };
10538 
10539 /* *** Filters Control *** */
10540 
10541 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10542 do { \
10543 	if ((ip_addr).family == AF_INET) \
10544 		(ip) = (ip_addr).addr.ipv4.s_addr; \
10545 	else { \
10546 		fprintf(stderr, "invalid parameter.\n"); \
10547 		return; \
10548 	} \
10549 } while (0)
10550 
10551 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10552 do { \
10553 	if ((ip_addr).family == AF_INET6) \
10554 		rte_memcpy(&(ip), \
10555 				 &((ip_addr).addr.ipv6), \
10556 				 sizeof(struct in6_addr)); \
10557 	else { \
10558 		fprintf(stderr, "invalid parameter.\n"); \
10559 		return; \
10560 	} \
10561 } while (0)
10562 
10563 #ifdef RTE_NET_I40E
10564 
10565 static uint16_t
10566 str2flowtype(char *string)
10567 {
10568 	uint8_t i = 0;
10569 	static const struct {
10570 		char str[32];
10571 		uint16_t type;
10572 	} flowtype_str[] = {
10573 		{"raw", RTE_ETH_FLOW_RAW},
10574 		{"ipv4", RTE_ETH_FLOW_IPV4},
10575 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10576 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10577 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10578 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10579 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10580 		{"ipv6", RTE_ETH_FLOW_IPV6},
10581 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10582 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10583 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10584 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10585 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10586 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10587 		{"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
10588 		{"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
10589 		{"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
10590 		{"gtpu", RTE_ETH_FLOW_GTPU},
10591 	};
10592 
10593 	for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10594 		if (!strcmp(flowtype_str[i].str, string))
10595 			return flowtype_str[i].type;
10596 	}
10597 
10598 	if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10599 		return (uint16_t)atoi(string);
10600 
10601 	return RTE_ETH_FLOW_UNKNOWN;
10602 }
10603 
10604 /* *** deal with flow director filter *** */
10605 struct cmd_flow_director_result {
10606 	cmdline_fixed_string_t flow_director_filter;
10607 	portid_t port_id;
10608 	cmdline_fixed_string_t mode;
10609 	cmdline_fixed_string_t mode_value;
10610 	cmdline_fixed_string_t ops;
10611 	cmdline_fixed_string_t flow;
10612 	cmdline_fixed_string_t flow_type;
10613 	cmdline_fixed_string_t drop;
10614 	cmdline_fixed_string_t queue;
10615 	uint16_t  queue_id;
10616 	cmdline_fixed_string_t fd_id;
10617 	uint32_t  fd_id_value;
10618 	cmdline_fixed_string_t packet;
10619 	char filepath[];
10620 };
10621 
10622 static void
10623 cmd_flow_director_filter_parsed(void *parsed_result,
10624 			  __rte_unused struct cmdline *cl,
10625 			  __rte_unused void *data)
10626 {
10627 	struct cmd_flow_director_result *res = parsed_result;
10628 	int ret = 0;
10629 	struct rte_pmd_i40e_flow_type_mapping
10630 			mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10631 	struct rte_pmd_i40e_pkt_template_conf conf;
10632 	uint16_t flow_type = str2flowtype(res->flow_type);
10633 	uint16_t i, port = res->port_id;
10634 	uint8_t add;
10635 
10636 	memset(&conf, 0, sizeof(conf));
10637 
10638 	if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10639 		fprintf(stderr, "Invalid flow type specified.\n");
10640 		return;
10641 	}
10642 	ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10643 						 mapping);
10644 	if (ret)
10645 		return;
10646 	if (mapping[flow_type].pctype == 0ULL) {
10647 		fprintf(stderr, "Invalid flow type specified.\n");
10648 		return;
10649 	}
10650 	for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10651 		if (mapping[flow_type].pctype & (1ULL << i)) {
10652 			conf.input.pctype = i;
10653 			break;
10654 		}
10655 	}
10656 
10657 	conf.input.packet = open_file(res->filepath,
10658 				&conf.input.length);
10659 	if (!conf.input.packet)
10660 		return;
10661 	if (!strcmp(res->drop, "drop"))
10662 		conf.action.behavior =
10663 			RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10664 	else
10665 		conf.action.behavior =
10666 			RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10667 	conf.action.report_status =
10668 			RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10669 	conf.action.rx_queue = res->queue_id;
10670 	conf.soft_id = res->fd_id_value;
10671 	add  = strcmp(res->ops, "del") ? 1 : 0;
10672 	ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10673 							&conf,
10674 							add);
10675 	if (ret < 0)
10676 		fprintf(stderr, "flow director config error: (%s)\n",
10677 			strerror(-ret));
10678 	close_file(conf.input.packet);
10679 }
10680 
10681 cmdline_parse_token_string_t cmd_flow_director_filter =
10682 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10683 				 flow_director_filter, "flow_director_filter");
10684 cmdline_parse_token_num_t cmd_flow_director_port_id =
10685 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10686 			      port_id, RTE_UINT16);
10687 cmdline_parse_token_string_t cmd_flow_director_ops =
10688 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10689 				 ops, "add#del#update");
10690 cmdline_parse_token_string_t cmd_flow_director_flow =
10691 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10692 				 flow, "flow");
10693 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10694 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10695 		flow_type, NULL);
10696 cmdline_parse_token_string_t cmd_flow_director_drop =
10697 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10698 				 drop, "drop#fwd");
10699 cmdline_parse_token_string_t cmd_flow_director_queue =
10700 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10701 				 queue, "queue");
10702 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10703 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10704 			      queue_id, RTE_UINT16);
10705 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10706 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10707 				 fd_id, "fd_id");
10708 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10709 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10710 			      fd_id_value, RTE_UINT32);
10711 
10712 cmdline_parse_token_string_t cmd_flow_director_mode =
10713 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10714 				 mode, "mode");
10715 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10716 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10717 				 mode_value, "raw");
10718 cmdline_parse_token_string_t cmd_flow_director_packet =
10719 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10720 				 packet, "packet");
10721 cmdline_parse_token_string_t cmd_flow_director_filepath =
10722 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10723 				 filepath, NULL);
10724 
10725 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10726 	.f = cmd_flow_director_filter_parsed,
10727 	.data = NULL,
10728 	.help_str = "flow_director_filter ... : Add or delete a raw flow "
10729 		"director entry on NIC",
10730 	.tokens = {
10731 		(void *)&cmd_flow_director_filter,
10732 		(void *)&cmd_flow_director_port_id,
10733 		(void *)&cmd_flow_director_mode,
10734 		(void *)&cmd_flow_director_mode_raw,
10735 		(void *)&cmd_flow_director_ops,
10736 		(void *)&cmd_flow_director_flow,
10737 		(void *)&cmd_flow_director_flow_type,
10738 		(void *)&cmd_flow_director_drop,
10739 		(void *)&cmd_flow_director_queue,
10740 		(void *)&cmd_flow_director_queue_id,
10741 		(void *)&cmd_flow_director_fd_id,
10742 		(void *)&cmd_flow_director_fd_id_value,
10743 		(void *)&cmd_flow_director_packet,
10744 		(void *)&cmd_flow_director_filepath,
10745 		NULL,
10746 	},
10747 };
10748 
10749 #endif /* RTE_NET_I40E */
10750 
10751 /* *** deal with flow director mask *** */
10752 struct cmd_flow_director_mask_result {
10753 	cmdline_fixed_string_t flow_director_mask;
10754 	portid_t port_id;
10755 	cmdline_fixed_string_t mode;
10756 	cmdline_fixed_string_t mode_value;
10757 	cmdline_fixed_string_t vlan;
10758 	uint16_t vlan_mask;
10759 	cmdline_fixed_string_t src_mask;
10760 	cmdline_ipaddr_t ipv4_src;
10761 	cmdline_ipaddr_t ipv6_src;
10762 	uint16_t port_src;
10763 	cmdline_fixed_string_t dst_mask;
10764 	cmdline_ipaddr_t ipv4_dst;
10765 	cmdline_ipaddr_t ipv6_dst;
10766 	uint16_t port_dst;
10767 	cmdline_fixed_string_t mac;
10768 	uint8_t mac_addr_byte_mask;
10769 	cmdline_fixed_string_t tunnel_id;
10770 	uint32_t tunnel_id_mask;
10771 	cmdline_fixed_string_t tunnel_type;
10772 	uint8_t tunnel_type_mask;
10773 };
10774 
10775 static void
10776 cmd_flow_director_mask_parsed(void *parsed_result,
10777 			  __rte_unused struct cmdline *cl,
10778 			  __rte_unused void *data)
10779 {
10780 	struct cmd_flow_director_mask_result *res = parsed_result;
10781 	struct rte_eth_fdir_masks *mask;
10782 	struct rte_port *port;
10783 
10784 	port = &ports[res->port_id];
10785 	/** Check if the port is not started **/
10786 	if (port->port_status != RTE_PORT_STOPPED) {
10787 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
10788 		return;
10789 	}
10790 
10791 	mask = &port->dev_conf.fdir_conf.mask;
10792 
10793 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10794 		if (strcmp(res->mode_value, "MAC-VLAN")) {
10795 			fprintf(stderr, "Please set mode to MAC-VLAN.\n");
10796 			return;
10797 		}
10798 
10799 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10800 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10801 		if (strcmp(res->mode_value, "Tunnel")) {
10802 			fprintf(stderr, "Please set mode to Tunnel.\n");
10803 			return;
10804 		}
10805 
10806 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10807 		mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10808 		mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10809 		mask->tunnel_type_mask = res->tunnel_type_mask;
10810 	} else {
10811 		if (strcmp(res->mode_value, "IP")) {
10812 			fprintf(stderr, "Please set mode to IP.\n");
10813 			return;
10814 		}
10815 
10816 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10817 		IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10818 		IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10819 		IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10820 		IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10821 		mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10822 		mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10823 	}
10824 
10825 	cmd_reconfig_device_queue(res->port_id, 1, 1);
10826 }
10827 
10828 cmdline_parse_token_string_t cmd_flow_director_mask =
10829 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10830 				 flow_director_mask, "flow_director_mask");
10831 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10832 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10833 			      port_id, RTE_UINT16);
10834 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10835 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10836 				 vlan, "vlan");
10837 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10838 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10839 			      vlan_mask, RTE_UINT16);
10840 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10841 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10842 				 src_mask, "src_mask");
10843 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10844 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10845 				 ipv4_src);
10846 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10847 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10848 				 ipv6_src);
10849 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10850 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10851 			      port_src, RTE_UINT16);
10852 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10853 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10854 				 dst_mask, "dst_mask");
10855 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10856 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10857 				 ipv4_dst);
10858 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10859 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10860 				 ipv6_dst);
10861 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10862 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10863 			      port_dst, RTE_UINT16);
10864 
10865 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10866 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10867 				 mode, "mode");
10868 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10869 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10870 				 mode_value, "IP");
10871 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10872 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10873 				 mode_value, "MAC-VLAN");
10874 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10875 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10876 				 mode_value, "Tunnel");
10877 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10878 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10879 				 mac, "mac");
10880 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10881 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10882 			      mac_addr_byte_mask, RTE_UINT8);
10883 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10884 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10885 				 tunnel_type, "tunnel-type");
10886 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10887 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10888 			      tunnel_type_mask, RTE_UINT8);
10889 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10890 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10891 				 tunnel_id, "tunnel-id");
10892 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10893 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10894 			      tunnel_id_mask, RTE_UINT32);
10895 
10896 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10897 	.f = cmd_flow_director_mask_parsed,
10898 	.data = NULL,
10899 	.help_str = "flow_director_mask ... : "
10900 		"Set IP mode flow director's mask on NIC",
10901 	.tokens = {
10902 		(void *)&cmd_flow_director_mask,
10903 		(void *)&cmd_flow_director_mask_port_id,
10904 		(void *)&cmd_flow_director_mask_mode,
10905 		(void *)&cmd_flow_director_mask_mode_ip,
10906 		(void *)&cmd_flow_director_mask_vlan,
10907 		(void *)&cmd_flow_director_mask_vlan_value,
10908 		(void *)&cmd_flow_director_mask_src,
10909 		(void *)&cmd_flow_director_mask_ipv4_src,
10910 		(void *)&cmd_flow_director_mask_ipv6_src,
10911 		(void *)&cmd_flow_director_mask_port_src,
10912 		(void *)&cmd_flow_director_mask_dst,
10913 		(void *)&cmd_flow_director_mask_ipv4_dst,
10914 		(void *)&cmd_flow_director_mask_ipv6_dst,
10915 		(void *)&cmd_flow_director_mask_port_dst,
10916 		NULL,
10917 	},
10918 };
10919 
10920 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10921 	.f = cmd_flow_director_mask_parsed,
10922 	.data = NULL,
10923 	.help_str = "flow_director_mask ... : Set MAC VLAN mode "
10924 		"flow director's mask on NIC",
10925 	.tokens = {
10926 		(void *)&cmd_flow_director_mask,
10927 		(void *)&cmd_flow_director_mask_port_id,
10928 		(void *)&cmd_flow_director_mask_mode,
10929 		(void *)&cmd_flow_director_mask_mode_mac_vlan,
10930 		(void *)&cmd_flow_director_mask_vlan,
10931 		(void *)&cmd_flow_director_mask_vlan_value,
10932 		NULL,
10933 	},
10934 };
10935 
10936 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10937 	.f = cmd_flow_director_mask_parsed,
10938 	.data = NULL,
10939 	.help_str = "flow_director_mask ... : Set tunnel mode "
10940 		"flow director's mask on NIC",
10941 	.tokens = {
10942 		(void *)&cmd_flow_director_mask,
10943 		(void *)&cmd_flow_director_mask_port_id,
10944 		(void *)&cmd_flow_director_mask_mode,
10945 		(void *)&cmd_flow_director_mask_mode_tunnel,
10946 		(void *)&cmd_flow_director_mask_vlan,
10947 		(void *)&cmd_flow_director_mask_vlan_value,
10948 		(void *)&cmd_flow_director_mask_mac,
10949 		(void *)&cmd_flow_director_mask_mac_value,
10950 		(void *)&cmd_flow_director_mask_tunnel_type,
10951 		(void *)&cmd_flow_director_mask_tunnel_type_value,
10952 		(void *)&cmd_flow_director_mask_tunnel_id,
10953 		(void *)&cmd_flow_director_mask_tunnel_id_value,
10954 		NULL,
10955 	},
10956 };
10957 
10958 /* *** deal with flow director flexible payload configuration *** */
10959 struct cmd_flow_director_flexpayload_result {
10960 	cmdline_fixed_string_t flow_director_flexpayload;
10961 	portid_t port_id;
10962 	cmdline_fixed_string_t payload_layer;
10963 	cmdline_fixed_string_t payload_cfg;
10964 };
10965 
10966 static inline int
10967 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10968 {
10969 	char s[256];
10970 	const char *p, *p0 = q_arg;
10971 	char *end;
10972 	unsigned long int_fld;
10973 	char *str_fld[max_num];
10974 	int i;
10975 	unsigned size;
10976 	int ret = -1;
10977 
10978 	p = strchr(p0, '(');
10979 	if (p == NULL)
10980 		return -1;
10981 	++p;
10982 	p0 = strchr(p, ')');
10983 	if (p0 == NULL)
10984 		return -1;
10985 
10986 	size = p0 - p;
10987 	if (size >= sizeof(s))
10988 		return -1;
10989 
10990 	snprintf(s, sizeof(s), "%.*s", size, p);
10991 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10992 	if (ret < 0 || ret > max_num)
10993 		return -1;
10994 	for (i = 0; i < ret; i++) {
10995 		errno = 0;
10996 		int_fld = strtoul(str_fld[i], &end, 0);
10997 		if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10998 			return -1;
10999 		offsets[i] = (uint16_t)int_fld;
11000 	}
11001 	return ret;
11002 }
11003 
11004 static void
11005 cmd_flow_director_flxpld_parsed(void *parsed_result,
11006 			  __rte_unused struct cmdline *cl,
11007 			  __rte_unused void *data)
11008 {
11009 	struct cmd_flow_director_flexpayload_result *res = parsed_result;
11010 	struct rte_eth_flex_payload_cfg flex_cfg;
11011 	struct rte_port *port;
11012 	int ret = 0;
11013 
11014 	port = &ports[res->port_id];
11015 	/** Check if the port is not started **/
11016 	if (port->port_status != RTE_PORT_STOPPED) {
11017 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
11018 		return;
11019 	}
11020 
11021 	memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11022 
11023 	if (!strcmp(res->payload_layer, "raw"))
11024 		flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11025 	else if (!strcmp(res->payload_layer, "l2"))
11026 		flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11027 	else if (!strcmp(res->payload_layer, "l3"))
11028 		flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11029 	else if (!strcmp(res->payload_layer, "l4"))
11030 		flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11031 
11032 	ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11033 			    RTE_ETH_FDIR_MAX_FLEXLEN);
11034 	if (ret < 0) {
11035 		fprintf(stderr, "error: Cannot parse flex payload input.\n");
11036 		return;
11037 	}
11038 
11039 	fdir_set_flex_payload(res->port_id, &flex_cfg);
11040 	cmd_reconfig_device_queue(res->port_id, 1, 1);
11041 }
11042 
11043 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11044 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11045 				 flow_director_flexpayload,
11046 				 "flow_director_flex_payload");
11047 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11048 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11049 			      port_id, RTE_UINT16);
11050 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11051 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11052 				 payload_layer, "raw#l2#l3#l4");
11053 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11054 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11055 				 payload_cfg, NULL);
11056 
11057 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11058 	.f = cmd_flow_director_flxpld_parsed,
11059 	.data = NULL,
11060 	.help_str = "flow_director_flexpayload ... : "
11061 		"Set flow director's flex payload on NIC",
11062 	.tokens = {
11063 		(void *)&cmd_flow_director_flexpayload,
11064 		(void *)&cmd_flow_director_flexpayload_port_id,
11065 		(void *)&cmd_flow_director_flexpayload_payload_layer,
11066 		(void *)&cmd_flow_director_flexpayload_payload_cfg,
11067 		NULL,
11068 	},
11069 };
11070 
11071 /* Generic flow interface command. */
11072 extern cmdline_parse_inst_t cmd_flow;
11073 
11074 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11075 struct cmd_mcast_addr_result {
11076 	cmdline_fixed_string_t mcast_addr_cmd;
11077 	cmdline_fixed_string_t what;
11078 	uint16_t port_num;
11079 	struct rte_ether_addr mc_addr;
11080 };
11081 
11082 static void cmd_mcast_addr_parsed(void *parsed_result,
11083 		__rte_unused struct cmdline *cl,
11084 		__rte_unused void *data)
11085 {
11086 	struct cmd_mcast_addr_result *res = parsed_result;
11087 
11088 	if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
11089 		fprintf(stderr,
11090 			"Invalid multicast addr " RTE_ETHER_ADDR_PRT_FMT "\n",
11091 			RTE_ETHER_ADDR_BYTES(&res->mc_addr));
11092 		return;
11093 	}
11094 	if (strcmp(res->what, "add") == 0)
11095 		mcast_addr_add(res->port_num, &res->mc_addr);
11096 	else
11097 		mcast_addr_remove(res->port_num, &res->mc_addr);
11098 }
11099 
11100 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11101 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11102 				 mcast_addr_cmd, "mcast_addr");
11103 cmdline_parse_token_string_t cmd_mcast_addr_what =
11104 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11105 				 "add#remove");
11106 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11107 	TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
11108 				 RTE_UINT16);
11109 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11110 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11111 
11112 cmdline_parse_inst_t cmd_mcast_addr = {
11113 	.f = cmd_mcast_addr_parsed,
11114 	.data = (void *)0,
11115 	.help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11116 		"Add/Remove multicast MAC address on port_id",
11117 	.tokens = {
11118 		(void *)&cmd_mcast_addr_cmd,
11119 		(void *)&cmd_mcast_addr_what,
11120 		(void *)&cmd_mcast_addr_portnum,
11121 		(void *)&cmd_mcast_addr_addr,
11122 		NULL,
11123 	},
11124 };
11125 
11126 /* vf vlan anti spoof configuration */
11127 
11128 /* Common result structure for vf vlan anti spoof */
11129 struct cmd_vf_vlan_anti_spoof_result {
11130 	cmdline_fixed_string_t set;
11131 	cmdline_fixed_string_t vf;
11132 	cmdline_fixed_string_t vlan;
11133 	cmdline_fixed_string_t antispoof;
11134 	portid_t port_id;
11135 	uint32_t vf_id;
11136 	cmdline_fixed_string_t on_off;
11137 };
11138 
11139 /* Common CLI fields for vf vlan anti spoof enable disable */
11140 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11141 	TOKEN_STRING_INITIALIZER
11142 		(struct cmd_vf_vlan_anti_spoof_result,
11143 		 set, "set");
11144 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11145 	TOKEN_STRING_INITIALIZER
11146 		(struct cmd_vf_vlan_anti_spoof_result,
11147 		 vf, "vf");
11148 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11149 	TOKEN_STRING_INITIALIZER
11150 		(struct cmd_vf_vlan_anti_spoof_result,
11151 		 vlan, "vlan");
11152 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11153 	TOKEN_STRING_INITIALIZER
11154 		(struct cmd_vf_vlan_anti_spoof_result,
11155 		 antispoof, "antispoof");
11156 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11157 	TOKEN_NUM_INITIALIZER
11158 		(struct cmd_vf_vlan_anti_spoof_result,
11159 		 port_id, RTE_UINT16);
11160 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11161 	TOKEN_NUM_INITIALIZER
11162 		(struct cmd_vf_vlan_anti_spoof_result,
11163 		 vf_id, RTE_UINT32);
11164 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11165 	TOKEN_STRING_INITIALIZER
11166 		(struct cmd_vf_vlan_anti_spoof_result,
11167 		 on_off, "on#off");
11168 
11169 static void
11170 cmd_set_vf_vlan_anti_spoof_parsed(
11171 	void *parsed_result,
11172 	__rte_unused struct cmdline *cl,
11173 	__rte_unused void *data)
11174 {
11175 	struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11176 	int ret = -ENOTSUP;
11177 
11178 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11179 
11180 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11181 		return;
11182 
11183 #ifdef RTE_NET_IXGBE
11184 	if (ret == -ENOTSUP)
11185 		ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11186 				res->vf_id, is_on);
11187 #endif
11188 #ifdef RTE_NET_I40E
11189 	if (ret == -ENOTSUP)
11190 		ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11191 				res->vf_id, is_on);
11192 #endif
11193 #ifdef RTE_NET_BNXT
11194 	if (ret == -ENOTSUP)
11195 		ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11196 				res->vf_id, is_on);
11197 #endif
11198 
11199 	switch (ret) {
11200 	case 0:
11201 		break;
11202 	case -EINVAL:
11203 		fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
11204 		break;
11205 	case -ENODEV:
11206 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11207 		break;
11208 	case -ENOTSUP:
11209 		fprintf(stderr, "function not implemented\n");
11210 		break;
11211 	default:
11212 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11213 	}
11214 }
11215 
11216 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11217 	.f = cmd_set_vf_vlan_anti_spoof_parsed,
11218 	.data = NULL,
11219 	.help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11220 	.tokens = {
11221 		(void *)&cmd_vf_vlan_anti_spoof_set,
11222 		(void *)&cmd_vf_vlan_anti_spoof_vf,
11223 		(void *)&cmd_vf_vlan_anti_spoof_vlan,
11224 		(void *)&cmd_vf_vlan_anti_spoof_antispoof,
11225 		(void *)&cmd_vf_vlan_anti_spoof_port_id,
11226 		(void *)&cmd_vf_vlan_anti_spoof_vf_id,
11227 		(void *)&cmd_vf_vlan_anti_spoof_on_off,
11228 		NULL,
11229 	},
11230 };
11231 
11232 /* vf mac anti spoof configuration */
11233 
11234 /* Common result structure for vf mac anti spoof */
11235 struct cmd_vf_mac_anti_spoof_result {
11236 	cmdline_fixed_string_t set;
11237 	cmdline_fixed_string_t vf;
11238 	cmdline_fixed_string_t mac;
11239 	cmdline_fixed_string_t antispoof;
11240 	portid_t port_id;
11241 	uint32_t vf_id;
11242 	cmdline_fixed_string_t on_off;
11243 };
11244 
11245 /* Common CLI fields for vf mac anti spoof enable disable */
11246 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11247 	TOKEN_STRING_INITIALIZER
11248 		(struct cmd_vf_mac_anti_spoof_result,
11249 		 set, "set");
11250 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11251 	TOKEN_STRING_INITIALIZER
11252 		(struct cmd_vf_mac_anti_spoof_result,
11253 		 vf, "vf");
11254 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11255 	TOKEN_STRING_INITIALIZER
11256 		(struct cmd_vf_mac_anti_spoof_result,
11257 		 mac, "mac");
11258 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11259 	TOKEN_STRING_INITIALIZER
11260 		(struct cmd_vf_mac_anti_spoof_result,
11261 		 antispoof, "antispoof");
11262 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11263 	TOKEN_NUM_INITIALIZER
11264 		(struct cmd_vf_mac_anti_spoof_result,
11265 		 port_id, RTE_UINT16);
11266 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11267 	TOKEN_NUM_INITIALIZER
11268 		(struct cmd_vf_mac_anti_spoof_result,
11269 		 vf_id, RTE_UINT32);
11270 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11271 	TOKEN_STRING_INITIALIZER
11272 		(struct cmd_vf_mac_anti_spoof_result,
11273 		 on_off, "on#off");
11274 
11275 static void
11276 cmd_set_vf_mac_anti_spoof_parsed(
11277 	void *parsed_result,
11278 	__rte_unused struct cmdline *cl,
11279 	__rte_unused void *data)
11280 {
11281 	struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11282 	int ret = -ENOTSUP;
11283 
11284 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11285 
11286 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11287 		return;
11288 
11289 #ifdef RTE_NET_IXGBE
11290 	if (ret == -ENOTSUP)
11291 		ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11292 			res->vf_id, is_on);
11293 #endif
11294 #ifdef RTE_NET_I40E
11295 	if (ret == -ENOTSUP)
11296 		ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11297 			res->vf_id, is_on);
11298 #endif
11299 #ifdef RTE_NET_BNXT
11300 	if (ret == -ENOTSUP)
11301 		ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11302 			res->vf_id, is_on);
11303 #endif
11304 
11305 	switch (ret) {
11306 	case 0:
11307 		break;
11308 	case -EINVAL:
11309 		fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11310 			res->vf_id, is_on);
11311 		break;
11312 	case -ENODEV:
11313 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11314 		break;
11315 	case -ENOTSUP:
11316 		fprintf(stderr, "function not implemented\n");
11317 		break;
11318 	default:
11319 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11320 	}
11321 }
11322 
11323 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11324 	.f = cmd_set_vf_mac_anti_spoof_parsed,
11325 	.data = NULL,
11326 	.help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11327 	.tokens = {
11328 		(void *)&cmd_vf_mac_anti_spoof_set,
11329 		(void *)&cmd_vf_mac_anti_spoof_vf,
11330 		(void *)&cmd_vf_mac_anti_spoof_mac,
11331 		(void *)&cmd_vf_mac_anti_spoof_antispoof,
11332 		(void *)&cmd_vf_mac_anti_spoof_port_id,
11333 		(void *)&cmd_vf_mac_anti_spoof_vf_id,
11334 		(void *)&cmd_vf_mac_anti_spoof_on_off,
11335 		NULL,
11336 	},
11337 };
11338 
11339 /* vf vlan strip queue configuration */
11340 
11341 /* Common result structure for vf mac anti spoof */
11342 struct cmd_vf_vlan_stripq_result {
11343 	cmdline_fixed_string_t set;
11344 	cmdline_fixed_string_t vf;
11345 	cmdline_fixed_string_t vlan;
11346 	cmdline_fixed_string_t stripq;
11347 	portid_t port_id;
11348 	uint16_t vf_id;
11349 	cmdline_fixed_string_t on_off;
11350 };
11351 
11352 /* Common CLI fields for vf vlan strip enable disable */
11353 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11354 	TOKEN_STRING_INITIALIZER
11355 		(struct cmd_vf_vlan_stripq_result,
11356 		 set, "set");
11357 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11358 	TOKEN_STRING_INITIALIZER
11359 		(struct cmd_vf_vlan_stripq_result,
11360 		 vf, "vf");
11361 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11362 	TOKEN_STRING_INITIALIZER
11363 		(struct cmd_vf_vlan_stripq_result,
11364 		 vlan, "vlan");
11365 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11366 	TOKEN_STRING_INITIALIZER
11367 		(struct cmd_vf_vlan_stripq_result,
11368 		 stripq, "stripq");
11369 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11370 	TOKEN_NUM_INITIALIZER
11371 		(struct cmd_vf_vlan_stripq_result,
11372 		 port_id, RTE_UINT16);
11373 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11374 	TOKEN_NUM_INITIALIZER
11375 		(struct cmd_vf_vlan_stripq_result,
11376 		 vf_id, RTE_UINT16);
11377 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11378 	TOKEN_STRING_INITIALIZER
11379 		(struct cmd_vf_vlan_stripq_result,
11380 		 on_off, "on#off");
11381 
11382 static void
11383 cmd_set_vf_vlan_stripq_parsed(
11384 	void *parsed_result,
11385 	__rte_unused struct cmdline *cl,
11386 	__rte_unused void *data)
11387 {
11388 	struct cmd_vf_vlan_stripq_result *res = parsed_result;
11389 	int ret = -ENOTSUP;
11390 
11391 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11392 
11393 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11394 		return;
11395 
11396 #ifdef RTE_NET_IXGBE
11397 	if (ret == -ENOTSUP)
11398 		ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11399 			res->vf_id, is_on);
11400 #endif
11401 #ifdef RTE_NET_I40E
11402 	if (ret == -ENOTSUP)
11403 		ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11404 			res->vf_id, is_on);
11405 #endif
11406 #ifdef RTE_NET_BNXT
11407 	if (ret == -ENOTSUP)
11408 		ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11409 			res->vf_id, is_on);
11410 #endif
11411 
11412 	switch (ret) {
11413 	case 0:
11414 		break;
11415 	case -EINVAL:
11416 		fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11417 			res->vf_id, is_on);
11418 		break;
11419 	case -ENODEV:
11420 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11421 		break;
11422 	case -ENOTSUP:
11423 		fprintf(stderr, "function not implemented\n");
11424 		break;
11425 	default:
11426 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11427 	}
11428 }
11429 
11430 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11431 	.f = cmd_set_vf_vlan_stripq_parsed,
11432 	.data = NULL,
11433 	.help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11434 	.tokens = {
11435 		(void *)&cmd_vf_vlan_stripq_set,
11436 		(void *)&cmd_vf_vlan_stripq_vf,
11437 		(void *)&cmd_vf_vlan_stripq_vlan,
11438 		(void *)&cmd_vf_vlan_stripq_stripq,
11439 		(void *)&cmd_vf_vlan_stripq_port_id,
11440 		(void *)&cmd_vf_vlan_stripq_vf_id,
11441 		(void *)&cmd_vf_vlan_stripq_on_off,
11442 		NULL,
11443 	},
11444 };
11445 
11446 /* vf vlan insert configuration */
11447 
11448 /* Common result structure for vf vlan insert */
11449 struct cmd_vf_vlan_insert_result {
11450 	cmdline_fixed_string_t set;
11451 	cmdline_fixed_string_t vf;
11452 	cmdline_fixed_string_t vlan;
11453 	cmdline_fixed_string_t insert;
11454 	portid_t port_id;
11455 	uint16_t vf_id;
11456 	uint16_t vlan_id;
11457 };
11458 
11459 /* Common CLI fields for vf vlan insert enable disable */
11460 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11461 	TOKEN_STRING_INITIALIZER
11462 		(struct cmd_vf_vlan_insert_result,
11463 		 set, "set");
11464 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11465 	TOKEN_STRING_INITIALIZER
11466 		(struct cmd_vf_vlan_insert_result,
11467 		 vf, "vf");
11468 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11469 	TOKEN_STRING_INITIALIZER
11470 		(struct cmd_vf_vlan_insert_result,
11471 		 vlan, "vlan");
11472 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11473 	TOKEN_STRING_INITIALIZER
11474 		(struct cmd_vf_vlan_insert_result,
11475 		 insert, "insert");
11476 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11477 	TOKEN_NUM_INITIALIZER
11478 		(struct cmd_vf_vlan_insert_result,
11479 		 port_id, RTE_UINT16);
11480 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11481 	TOKEN_NUM_INITIALIZER
11482 		(struct cmd_vf_vlan_insert_result,
11483 		 vf_id, RTE_UINT16);
11484 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11485 	TOKEN_NUM_INITIALIZER
11486 		(struct cmd_vf_vlan_insert_result,
11487 		 vlan_id, RTE_UINT16);
11488 
11489 static void
11490 cmd_set_vf_vlan_insert_parsed(
11491 	void *parsed_result,
11492 	__rte_unused struct cmdline *cl,
11493 	__rte_unused void *data)
11494 {
11495 	struct cmd_vf_vlan_insert_result *res = parsed_result;
11496 	int ret = -ENOTSUP;
11497 
11498 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11499 		return;
11500 
11501 #ifdef RTE_NET_IXGBE
11502 	if (ret == -ENOTSUP)
11503 		ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11504 			res->vlan_id);
11505 #endif
11506 #ifdef RTE_NET_I40E
11507 	if (ret == -ENOTSUP)
11508 		ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11509 			res->vlan_id);
11510 #endif
11511 #ifdef RTE_NET_BNXT
11512 	if (ret == -ENOTSUP)
11513 		ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11514 			res->vlan_id);
11515 #endif
11516 
11517 	switch (ret) {
11518 	case 0:
11519 		break;
11520 	case -EINVAL:
11521 		fprintf(stderr, "invalid vf_id %d or vlan_id %d\n",
11522 			res->vf_id, res->vlan_id);
11523 		break;
11524 	case -ENODEV:
11525 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11526 		break;
11527 	case -ENOTSUP:
11528 		fprintf(stderr, "function not implemented\n");
11529 		break;
11530 	default:
11531 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11532 	}
11533 }
11534 
11535 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11536 	.f = cmd_set_vf_vlan_insert_parsed,
11537 	.data = NULL,
11538 	.help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11539 	.tokens = {
11540 		(void *)&cmd_vf_vlan_insert_set,
11541 		(void *)&cmd_vf_vlan_insert_vf,
11542 		(void *)&cmd_vf_vlan_insert_vlan,
11543 		(void *)&cmd_vf_vlan_insert_insert,
11544 		(void *)&cmd_vf_vlan_insert_port_id,
11545 		(void *)&cmd_vf_vlan_insert_vf_id,
11546 		(void *)&cmd_vf_vlan_insert_vlan_id,
11547 		NULL,
11548 	},
11549 };
11550 
11551 /* tx loopback configuration */
11552 
11553 /* Common result structure for tx loopback */
11554 struct cmd_tx_loopback_result {
11555 	cmdline_fixed_string_t set;
11556 	cmdline_fixed_string_t tx;
11557 	cmdline_fixed_string_t loopback;
11558 	portid_t port_id;
11559 	cmdline_fixed_string_t on_off;
11560 };
11561 
11562 /* Common CLI fields for tx loopback enable disable */
11563 cmdline_parse_token_string_t cmd_tx_loopback_set =
11564 	TOKEN_STRING_INITIALIZER
11565 		(struct cmd_tx_loopback_result,
11566 		 set, "set");
11567 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11568 	TOKEN_STRING_INITIALIZER
11569 		(struct cmd_tx_loopback_result,
11570 		 tx, "tx");
11571 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11572 	TOKEN_STRING_INITIALIZER
11573 		(struct cmd_tx_loopback_result,
11574 		 loopback, "loopback");
11575 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11576 	TOKEN_NUM_INITIALIZER
11577 		(struct cmd_tx_loopback_result,
11578 		 port_id, RTE_UINT16);
11579 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11580 	TOKEN_STRING_INITIALIZER
11581 		(struct cmd_tx_loopback_result,
11582 		 on_off, "on#off");
11583 
11584 static void
11585 cmd_set_tx_loopback_parsed(
11586 	void *parsed_result,
11587 	__rte_unused struct cmdline *cl,
11588 	__rte_unused void *data)
11589 {
11590 	struct cmd_tx_loopback_result *res = parsed_result;
11591 	int ret = -ENOTSUP;
11592 
11593 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11594 
11595 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11596 		return;
11597 
11598 #ifdef RTE_NET_IXGBE
11599 	if (ret == -ENOTSUP)
11600 		ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11601 #endif
11602 #ifdef RTE_NET_I40E
11603 	if (ret == -ENOTSUP)
11604 		ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11605 #endif
11606 #ifdef RTE_NET_BNXT
11607 	if (ret == -ENOTSUP)
11608 		ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11609 #endif
11610 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11611 	if (ret == -ENOTSUP)
11612 		ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11613 #endif
11614 
11615 	switch (ret) {
11616 	case 0:
11617 		break;
11618 	case -EINVAL:
11619 		fprintf(stderr, "invalid is_on %d\n", is_on);
11620 		break;
11621 	case -ENODEV:
11622 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11623 		break;
11624 	case -ENOTSUP:
11625 		fprintf(stderr, "function not implemented\n");
11626 		break;
11627 	default:
11628 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11629 	}
11630 }
11631 
11632 cmdline_parse_inst_t cmd_set_tx_loopback = {
11633 	.f = cmd_set_tx_loopback_parsed,
11634 	.data = NULL,
11635 	.help_str = "set tx loopback <port_id> on|off",
11636 	.tokens = {
11637 		(void *)&cmd_tx_loopback_set,
11638 		(void *)&cmd_tx_loopback_tx,
11639 		(void *)&cmd_tx_loopback_loopback,
11640 		(void *)&cmd_tx_loopback_port_id,
11641 		(void *)&cmd_tx_loopback_on_off,
11642 		NULL,
11643 	},
11644 };
11645 
11646 /* all queues drop enable configuration */
11647 
11648 /* Common result structure for all queues drop enable */
11649 struct cmd_all_queues_drop_en_result {
11650 	cmdline_fixed_string_t set;
11651 	cmdline_fixed_string_t all;
11652 	cmdline_fixed_string_t queues;
11653 	cmdline_fixed_string_t drop;
11654 	portid_t port_id;
11655 	cmdline_fixed_string_t on_off;
11656 };
11657 
11658 /* Common CLI fields for tx loopback enable disable */
11659 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11660 	TOKEN_STRING_INITIALIZER
11661 		(struct cmd_all_queues_drop_en_result,
11662 		 set, "set");
11663 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11664 	TOKEN_STRING_INITIALIZER
11665 		(struct cmd_all_queues_drop_en_result,
11666 		 all, "all");
11667 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11668 	TOKEN_STRING_INITIALIZER
11669 		(struct cmd_all_queues_drop_en_result,
11670 		 queues, "queues");
11671 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11672 	TOKEN_STRING_INITIALIZER
11673 		(struct cmd_all_queues_drop_en_result,
11674 		 drop, "drop");
11675 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11676 	TOKEN_NUM_INITIALIZER
11677 		(struct cmd_all_queues_drop_en_result,
11678 		 port_id, RTE_UINT16);
11679 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11680 	TOKEN_STRING_INITIALIZER
11681 		(struct cmd_all_queues_drop_en_result,
11682 		 on_off, "on#off");
11683 
11684 static void
11685 cmd_set_all_queues_drop_en_parsed(
11686 	void *parsed_result,
11687 	__rte_unused struct cmdline *cl,
11688 	__rte_unused void *data)
11689 {
11690 	struct cmd_all_queues_drop_en_result *res = parsed_result;
11691 	int ret = -ENOTSUP;
11692 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11693 
11694 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11695 		return;
11696 
11697 #ifdef RTE_NET_IXGBE
11698 	if (ret == -ENOTSUP)
11699 		ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11700 #endif
11701 #ifdef RTE_NET_BNXT
11702 	if (ret == -ENOTSUP)
11703 		ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11704 #endif
11705 	switch (ret) {
11706 	case 0:
11707 		break;
11708 	case -EINVAL:
11709 		fprintf(stderr, "invalid is_on %d\n", is_on);
11710 		break;
11711 	case -ENODEV:
11712 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11713 		break;
11714 	case -ENOTSUP:
11715 		fprintf(stderr, "function not implemented\n");
11716 		break;
11717 	default:
11718 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11719 	}
11720 }
11721 
11722 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11723 	.f = cmd_set_all_queues_drop_en_parsed,
11724 	.data = NULL,
11725 	.help_str = "set all queues drop <port_id> on|off",
11726 	.tokens = {
11727 		(void *)&cmd_all_queues_drop_en_set,
11728 		(void *)&cmd_all_queues_drop_en_all,
11729 		(void *)&cmd_all_queues_drop_en_queues,
11730 		(void *)&cmd_all_queues_drop_en_drop,
11731 		(void *)&cmd_all_queues_drop_en_port_id,
11732 		(void *)&cmd_all_queues_drop_en_on_off,
11733 		NULL,
11734 	},
11735 };
11736 
11737 /* vf split drop enable configuration */
11738 
11739 /* Common result structure for vf split drop enable */
11740 struct cmd_vf_split_drop_en_result {
11741 	cmdline_fixed_string_t set;
11742 	cmdline_fixed_string_t vf;
11743 	cmdline_fixed_string_t split;
11744 	cmdline_fixed_string_t drop;
11745 	portid_t port_id;
11746 	uint16_t vf_id;
11747 	cmdline_fixed_string_t on_off;
11748 };
11749 
11750 /* Common CLI fields for vf split drop enable disable */
11751 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11752 	TOKEN_STRING_INITIALIZER
11753 		(struct cmd_vf_split_drop_en_result,
11754 		 set, "set");
11755 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11756 	TOKEN_STRING_INITIALIZER
11757 		(struct cmd_vf_split_drop_en_result,
11758 		 vf, "vf");
11759 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11760 	TOKEN_STRING_INITIALIZER
11761 		(struct cmd_vf_split_drop_en_result,
11762 		 split, "split");
11763 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11764 	TOKEN_STRING_INITIALIZER
11765 		(struct cmd_vf_split_drop_en_result,
11766 		 drop, "drop");
11767 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11768 	TOKEN_NUM_INITIALIZER
11769 		(struct cmd_vf_split_drop_en_result,
11770 		 port_id, RTE_UINT16);
11771 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11772 	TOKEN_NUM_INITIALIZER
11773 		(struct cmd_vf_split_drop_en_result,
11774 		 vf_id, RTE_UINT16);
11775 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11776 	TOKEN_STRING_INITIALIZER
11777 		(struct cmd_vf_split_drop_en_result,
11778 		 on_off, "on#off");
11779 
11780 static void
11781 cmd_set_vf_split_drop_en_parsed(
11782 	void *parsed_result,
11783 	__rte_unused struct cmdline *cl,
11784 	__rte_unused void *data)
11785 {
11786 	struct cmd_vf_split_drop_en_result *res = parsed_result;
11787 	int ret = -ENOTSUP;
11788 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11789 
11790 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11791 		return;
11792 
11793 #ifdef RTE_NET_IXGBE
11794 	ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11795 			is_on);
11796 #endif
11797 	switch (ret) {
11798 	case 0:
11799 		break;
11800 	case -EINVAL:
11801 		fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11802 			res->vf_id, is_on);
11803 		break;
11804 	case -ENODEV:
11805 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11806 		break;
11807 	case -ENOTSUP:
11808 		fprintf(stderr, "not supported on port %d\n", res->port_id);
11809 		break;
11810 	default:
11811 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11812 	}
11813 }
11814 
11815 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11816 	.f = cmd_set_vf_split_drop_en_parsed,
11817 	.data = NULL,
11818 	.help_str = "set vf split drop <port_id> <vf_id> on|off",
11819 	.tokens = {
11820 		(void *)&cmd_vf_split_drop_en_set,
11821 		(void *)&cmd_vf_split_drop_en_vf,
11822 		(void *)&cmd_vf_split_drop_en_split,
11823 		(void *)&cmd_vf_split_drop_en_drop,
11824 		(void *)&cmd_vf_split_drop_en_port_id,
11825 		(void *)&cmd_vf_split_drop_en_vf_id,
11826 		(void *)&cmd_vf_split_drop_en_on_off,
11827 		NULL,
11828 	},
11829 };
11830 
11831 /* vf mac address configuration */
11832 
11833 /* Common result structure for vf mac address */
11834 struct cmd_set_vf_mac_addr_result {
11835 	cmdline_fixed_string_t set;
11836 	cmdline_fixed_string_t vf;
11837 	cmdline_fixed_string_t mac;
11838 	cmdline_fixed_string_t addr;
11839 	portid_t port_id;
11840 	uint16_t vf_id;
11841 	struct rte_ether_addr mac_addr;
11842 
11843 };
11844 
11845 /* Common CLI fields for vf split drop enable disable */
11846 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11847 	TOKEN_STRING_INITIALIZER
11848 		(struct cmd_set_vf_mac_addr_result,
11849 		 set, "set");
11850 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11851 	TOKEN_STRING_INITIALIZER
11852 		(struct cmd_set_vf_mac_addr_result,
11853 		 vf, "vf");
11854 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11855 	TOKEN_STRING_INITIALIZER
11856 		(struct cmd_set_vf_mac_addr_result,
11857 		 mac, "mac");
11858 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11859 	TOKEN_STRING_INITIALIZER
11860 		(struct cmd_set_vf_mac_addr_result,
11861 		 addr, "addr");
11862 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11863 	TOKEN_NUM_INITIALIZER
11864 		(struct cmd_set_vf_mac_addr_result,
11865 		 port_id, RTE_UINT16);
11866 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11867 	TOKEN_NUM_INITIALIZER
11868 		(struct cmd_set_vf_mac_addr_result,
11869 		 vf_id, RTE_UINT16);
11870 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11871 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11872 		 mac_addr);
11873 
11874 static void
11875 cmd_set_vf_mac_addr_parsed(
11876 	void *parsed_result,
11877 	__rte_unused struct cmdline *cl,
11878 	__rte_unused void *data)
11879 {
11880 	struct cmd_set_vf_mac_addr_result *res = parsed_result;
11881 	int ret = -ENOTSUP;
11882 
11883 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11884 		return;
11885 
11886 #ifdef RTE_NET_IXGBE
11887 	if (ret == -ENOTSUP)
11888 		ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11889 				&res->mac_addr);
11890 #endif
11891 #ifdef RTE_NET_I40E
11892 	if (ret == -ENOTSUP)
11893 		ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11894 				&res->mac_addr);
11895 #endif
11896 #ifdef RTE_NET_BNXT
11897 	if (ret == -ENOTSUP)
11898 		ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11899 				&res->mac_addr);
11900 #endif
11901 
11902 	switch (ret) {
11903 	case 0:
11904 		break;
11905 	case -EINVAL:
11906 		fprintf(stderr, "invalid vf_id %d or mac_addr\n", res->vf_id);
11907 		break;
11908 	case -ENODEV:
11909 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
11910 		break;
11911 	case -ENOTSUP:
11912 		fprintf(stderr, "function not implemented\n");
11913 		break;
11914 	default:
11915 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11916 	}
11917 }
11918 
11919 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11920 	.f = cmd_set_vf_mac_addr_parsed,
11921 	.data = NULL,
11922 	.help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11923 	.tokens = {
11924 		(void *)&cmd_set_vf_mac_addr_set,
11925 		(void *)&cmd_set_vf_mac_addr_vf,
11926 		(void *)&cmd_set_vf_mac_addr_mac,
11927 		(void *)&cmd_set_vf_mac_addr_addr,
11928 		(void *)&cmd_set_vf_mac_addr_port_id,
11929 		(void *)&cmd_set_vf_mac_addr_vf_id,
11930 		(void *)&cmd_set_vf_mac_addr_mac_addr,
11931 		NULL,
11932 	},
11933 };
11934 
11935 /* MACsec configuration */
11936 
11937 /* Common result structure for MACsec offload enable */
11938 struct cmd_macsec_offload_on_result {
11939 	cmdline_fixed_string_t set;
11940 	cmdline_fixed_string_t macsec;
11941 	cmdline_fixed_string_t offload;
11942 	portid_t port_id;
11943 	cmdline_fixed_string_t on;
11944 	cmdline_fixed_string_t encrypt;
11945 	cmdline_fixed_string_t en_on_off;
11946 	cmdline_fixed_string_t replay_protect;
11947 	cmdline_fixed_string_t rp_on_off;
11948 };
11949 
11950 /* Common CLI fields for MACsec offload disable */
11951 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11952 	TOKEN_STRING_INITIALIZER
11953 		(struct cmd_macsec_offload_on_result,
11954 		 set, "set");
11955 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11956 	TOKEN_STRING_INITIALIZER
11957 		(struct cmd_macsec_offload_on_result,
11958 		 macsec, "macsec");
11959 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11960 	TOKEN_STRING_INITIALIZER
11961 		(struct cmd_macsec_offload_on_result,
11962 		 offload, "offload");
11963 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11964 	TOKEN_NUM_INITIALIZER
11965 		(struct cmd_macsec_offload_on_result,
11966 		 port_id, RTE_UINT16);
11967 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11968 	TOKEN_STRING_INITIALIZER
11969 		(struct cmd_macsec_offload_on_result,
11970 		 on, "on");
11971 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11972 	TOKEN_STRING_INITIALIZER
11973 		(struct cmd_macsec_offload_on_result,
11974 		 encrypt, "encrypt");
11975 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11976 	TOKEN_STRING_INITIALIZER
11977 		(struct cmd_macsec_offload_on_result,
11978 		 en_on_off, "on#off");
11979 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11980 	TOKEN_STRING_INITIALIZER
11981 		(struct cmd_macsec_offload_on_result,
11982 		 replay_protect, "replay-protect");
11983 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11984 	TOKEN_STRING_INITIALIZER
11985 		(struct cmd_macsec_offload_on_result,
11986 		 rp_on_off, "on#off");
11987 
11988 static void
11989 cmd_set_macsec_offload_on_parsed(
11990 	void *parsed_result,
11991 	__rte_unused struct cmdline *cl,
11992 	__rte_unused void *data)
11993 {
11994 	struct cmd_macsec_offload_on_result *res = parsed_result;
11995 	int ret = -ENOTSUP;
11996 	portid_t port_id = res->port_id;
11997 	int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11998 	int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11999 	struct rte_eth_dev_info dev_info;
12000 
12001 	if (port_id_is_invalid(port_id, ENABLED_WARN))
12002 		return;
12003 	if (!port_is_stopped(port_id)) {
12004 		fprintf(stderr, "Please stop port %d first\n", port_id);
12005 		return;
12006 	}
12007 
12008 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
12009 	if (ret != 0)
12010 		return;
12011 
12012 	if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
12013 #ifdef RTE_NET_IXGBE
12014 		ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12015 #endif
12016 	}
12017 	RTE_SET_USED(en);
12018 	RTE_SET_USED(rp);
12019 
12020 	switch (ret) {
12021 	case 0:
12022 		ports[port_id].dev_conf.txmode.offloads |=
12023 						RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
12024 		cmd_reconfig_device_queue(port_id, 1, 1);
12025 		break;
12026 	case -ENODEV:
12027 		fprintf(stderr, "invalid port_id %d\n", port_id);
12028 		break;
12029 	case -ENOTSUP:
12030 		fprintf(stderr, "not supported on port %d\n", port_id);
12031 		break;
12032 	default:
12033 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12034 	}
12035 }
12036 
12037 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12038 	.f = cmd_set_macsec_offload_on_parsed,
12039 	.data = NULL,
12040 	.help_str = "set macsec offload <port_id> on "
12041 		"encrypt on|off replay-protect on|off",
12042 	.tokens = {
12043 		(void *)&cmd_macsec_offload_on_set,
12044 		(void *)&cmd_macsec_offload_on_macsec,
12045 		(void *)&cmd_macsec_offload_on_offload,
12046 		(void *)&cmd_macsec_offload_on_port_id,
12047 		(void *)&cmd_macsec_offload_on_on,
12048 		(void *)&cmd_macsec_offload_on_encrypt,
12049 		(void *)&cmd_macsec_offload_on_en_on_off,
12050 		(void *)&cmd_macsec_offload_on_replay_protect,
12051 		(void *)&cmd_macsec_offload_on_rp_on_off,
12052 		NULL,
12053 	},
12054 };
12055 
12056 /* Common result structure for MACsec offload disable */
12057 struct cmd_macsec_offload_off_result {
12058 	cmdline_fixed_string_t set;
12059 	cmdline_fixed_string_t macsec;
12060 	cmdline_fixed_string_t offload;
12061 	portid_t port_id;
12062 	cmdline_fixed_string_t off;
12063 };
12064 
12065 /* Common CLI fields for MACsec offload disable */
12066 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12067 	TOKEN_STRING_INITIALIZER
12068 		(struct cmd_macsec_offload_off_result,
12069 		 set, "set");
12070 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12071 	TOKEN_STRING_INITIALIZER
12072 		(struct cmd_macsec_offload_off_result,
12073 		 macsec, "macsec");
12074 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12075 	TOKEN_STRING_INITIALIZER
12076 		(struct cmd_macsec_offload_off_result,
12077 		 offload, "offload");
12078 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12079 	TOKEN_NUM_INITIALIZER
12080 		(struct cmd_macsec_offload_off_result,
12081 		 port_id, RTE_UINT16);
12082 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12083 	TOKEN_STRING_INITIALIZER
12084 		(struct cmd_macsec_offload_off_result,
12085 		 off, "off");
12086 
12087 static void
12088 cmd_set_macsec_offload_off_parsed(
12089 	void *parsed_result,
12090 	__rte_unused struct cmdline *cl,
12091 	__rte_unused void *data)
12092 {
12093 	struct cmd_macsec_offload_off_result *res = parsed_result;
12094 	int ret = -ENOTSUP;
12095 	struct rte_eth_dev_info dev_info;
12096 	portid_t port_id = res->port_id;
12097 
12098 	if (port_id_is_invalid(port_id, ENABLED_WARN))
12099 		return;
12100 	if (!port_is_stopped(port_id)) {
12101 		fprintf(stderr, "Please stop port %d first\n", port_id);
12102 		return;
12103 	}
12104 
12105 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
12106 	if (ret != 0)
12107 		return;
12108 
12109 	if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
12110 #ifdef RTE_NET_IXGBE
12111 		ret = rte_pmd_ixgbe_macsec_disable(port_id);
12112 #endif
12113 	}
12114 	switch (ret) {
12115 	case 0:
12116 		ports[port_id].dev_conf.txmode.offloads &=
12117 						~RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
12118 		cmd_reconfig_device_queue(port_id, 1, 1);
12119 		break;
12120 	case -ENODEV:
12121 		fprintf(stderr, "invalid port_id %d\n", port_id);
12122 		break;
12123 	case -ENOTSUP:
12124 		fprintf(stderr, "not supported on port %d\n", port_id);
12125 		break;
12126 	default:
12127 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12128 	}
12129 }
12130 
12131 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12132 	.f = cmd_set_macsec_offload_off_parsed,
12133 	.data = NULL,
12134 	.help_str = "set macsec offload <port_id> off",
12135 	.tokens = {
12136 		(void *)&cmd_macsec_offload_off_set,
12137 		(void *)&cmd_macsec_offload_off_macsec,
12138 		(void *)&cmd_macsec_offload_off_offload,
12139 		(void *)&cmd_macsec_offload_off_port_id,
12140 		(void *)&cmd_macsec_offload_off_off,
12141 		NULL,
12142 	},
12143 };
12144 
12145 /* Common result structure for MACsec secure connection configure */
12146 struct cmd_macsec_sc_result {
12147 	cmdline_fixed_string_t set;
12148 	cmdline_fixed_string_t macsec;
12149 	cmdline_fixed_string_t sc;
12150 	cmdline_fixed_string_t tx_rx;
12151 	portid_t port_id;
12152 	struct rte_ether_addr mac;
12153 	uint16_t pi;
12154 };
12155 
12156 /* Common CLI fields for MACsec secure connection configure */
12157 cmdline_parse_token_string_t cmd_macsec_sc_set =
12158 	TOKEN_STRING_INITIALIZER
12159 		(struct cmd_macsec_sc_result,
12160 		 set, "set");
12161 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12162 	TOKEN_STRING_INITIALIZER
12163 		(struct cmd_macsec_sc_result,
12164 		 macsec, "macsec");
12165 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12166 	TOKEN_STRING_INITIALIZER
12167 		(struct cmd_macsec_sc_result,
12168 		 sc, "sc");
12169 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12170 	TOKEN_STRING_INITIALIZER
12171 		(struct cmd_macsec_sc_result,
12172 		 tx_rx, "tx#rx");
12173 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12174 	TOKEN_NUM_INITIALIZER
12175 		(struct cmd_macsec_sc_result,
12176 		 port_id, RTE_UINT16);
12177 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12178 	TOKEN_ETHERADDR_INITIALIZER
12179 		(struct cmd_macsec_sc_result,
12180 		 mac);
12181 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12182 	TOKEN_NUM_INITIALIZER
12183 		(struct cmd_macsec_sc_result,
12184 		 pi, RTE_UINT16);
12185 
12186 static void
12187 cmd_set_macsec_sc_parsed(
12188 	void *parsed_result,
12189 	__rte_unused struct cmdline *cl,
12190 	__rte_unused void *data)
12191 {
12192 	struct cmd_macsec_sc_result *res = parsed_result;
12193 	int ret = -ENOTSUP;
12194 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12195 
12196 #ifdef RTE_NET_IXGBE
12197 	ret = is_tx ?
12198 		rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12199 				res->mac.addr_bytes) :
12200 		rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12201 				res->mac.addr_bytes, res->pi);
12202 #endif
12203 	RTE_SET_USED(is_tx);
12204 
12205 	switch (ret) {
12206 	case 0:
12207 		break;
12208 	case -ENODEV:
12209 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12210 		break;
12211 	case -ENOTSUP:
12212 		fprintf(stderr, "not supported on port %d\n", res->port_id);
12213 		break;
12214 	default:
12215 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12216 	}
12217 }
12218 
12219 cmdline_parse_inst_t cmd_set_macsec_sc = {
12220 	.f = cmd_set_macsec_sc_parsed,
12221 	.data = NULL,
12222 	.help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12223 	.tokens = {
12224 		(void *)&cmd_macsec_sc_set,
12225 		(void *)&cmd_macsec_sc_macsec,
12226 		(void *)&cmd_macsec_sc_sc,
12227 		(void *)&cmd_macsec_sc_tx_rx,
12228 		(void *)&cmd_macsec_sc_port_id,
12229 		(void *)&cmd_macsec_sc_mac,
12230 		(void *)&cmd_macsec_sc_pi,
12231 		NULL,
12232 	},
12233 };
12234 
12235 /* Common result structure for MACsec secure connection configure */
12236 struct cmd_macsec_sa_result {
12237 	cmdline_fixed_string_t set;
12238 	cmdline_fixed_string_t macsec;
12239 	cmdline_fixed_string_t sa;
12240 	cmdline_fixed_string_t tx_rx;
12241 	portid_t port_id;
12242 	uint8_t idx;
12243 	uint8_t an;
12244 	uint32_t pn;
12245 	cmdline_fixed_string_t key;
12246 };
12247 
12248 /* Common CLI fields for MACsec secure connection configure */
12249 cmdline_parse_token_string_t cmd_macsec_sa_set =
12250 	TOKEN_STRING_INITIALIZER
12251 		(struct cmd_macsec_sa_result,
12252 		 set, "set");
12253 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12254 	TOKEN_STRING_INITIALIZER
12255 		(struct cmd_macsec_sa_result,
12256 		 macsec, "macsec");
12257 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12258 	TOKEN_STRING_INITIALIZER
12259 		(struct cmd_macsec_sa_result,
12260 		 sa, "sa");
12261 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12262 	TOKEN_STRING_INITIALIZER
12263 		(struct cmd_macsec_sa_result,
12264 		 tx_rx, "tx#rx");
12265 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12266 	TOKEN_NUM_INITIALIZER
12267 		(struct cmd_macsec_sa_result,
12268 		 port_id, RTE_UINT16);
12269 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12270 	TOKEN_NUM_INITIALIZER
12271 		(struct cmd_macsec_sa_result,
12272 		 idx, RTE_UINT8);
12273 cmdline_parse_token_num_t cmd_macsec_sa_an =
12274 	TOKEN_NUM_INITIALIZER
12275 		(struct cmd_macsec_sa_result,
12276 		 an, RTE_UINT8);
12277 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12278 	TOKEN_NUM_INITIALIZER
12279 		(struct cmd_macsec_sa_result,
12280 		 pn, RTE_UINT32);
12281 cmdline_parse_token_string_t cmd_macsec_sa_key =
12282 	TOKEN_STRING_INITIALIZER
12283 		(struct cmd_macsec_sa_result,
12284 		 key, NULL);
12285 
12286 static void
12287 cmd_set_macsec_sa_parsed(
12288 	void *parsed_result,
12289 	__rte_unused struct cmdline *cl,
12290 	__rte_unused void *data)
12291 {
12292 	struct cmd_macsec_sa_result *res = parsed_result;
12293 	int ret = -ENOTSUP;
12294 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12295 	uint8_t key[16] = { 0 };
12296 	uint8_t xdgt0;
12297 	uint8_t xdgt1;
12298 	int key_len;
12299 	int i;
12300 
12301 	key_len = strlen(res->key) / 2;
12302 	if (key_len > 16)
12303 		key_len = 16;
12304 
12305 	for (i = 0; i < key_len; i++) {
12306 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12307 		if (xdgt0 == 0xFF)
12308 			return;
12309 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12310 		if (xdgt1 == 0xFF)
12311 			return;
12312 		key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12313 	}
12314 
12315 #ifdef RTE_NET_IXGBE
12316 	ret = is_tx ?
12317 		rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12318 			res->idx, res->an, res->pn, key) :
12319 		rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12320 			res->idx, res->an, res->pn, key);
12321 #endif
12322 	RTE_SET_USED(is_tx);
12323 	RTE_SET_USED(key);
12324 
12325 	switch (ret) {
12326 	case 0:
12327 		break;
12328 	case -EINVAL:
12329 		fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an);
12330 		break;
12331 	case -ENODEV:
12332 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12333 		break;
12334 	case -ENOTSUP:
12335 		fprintf(stderr, "not supported on port %d\n", res->port_id);
12336 		break;
12337 	default:
12338 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12339 	}
12340 }
12341 
12342 cmdline_parse_inst_t cmd_set_macsec_sa = {
12343 	.f = cmd_set_macsec_sa_parsed,
12344 	.data = NULL,
12345 	.help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12346 	.tokens = {
12347 		(void *)&cmd_macsec_sa_set,
12348 		(void *)&cmd_macsec_sa_macsec,
12349 		(void *)&cmd_macsec_sa_sa,
12350 		(void *)&cmd_macsec_sa_tx_rx,
12351 		(void *)&cmd_macsec_sa_port_id,
12352 		(void *)&cmd_macsec_sa_idx,
12353 		(void *)&cmd_macsec_sa_an,
12354 		(void *)&cmd_macsec_sa_pn,
12355 		(void *)&cmd_macsec_sa_key,
12356 		NULL,
12357 	},
12358 };
12359 
12360 /* VF unicast promiscuous mode configuration */
12361 
12362 /* Common result structure for VF unicast promiscuous mode */
12363 struct cmd_vf_promisc_result {
12364 	cmdline_fixed_string_t set;
12365 	cmdline_fixed_string_t vf;
12366 	cmdline_fixed_string_t promisc;
12367 	portid_t port_id;
12368 	uint32_t vf_id;
12369 	cmdline_fixed_string_t on_off;
12370 };
12371 
12372 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12373 cmdline_parse_token_string_t cmd_vf_promisc_set =
12374 	TOKEN_STRING_INITIALIZER
12375 		(struct cmd_vf_promisc_result,
12376 		 set, "set");
12377 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12378 	TOKEN_STRING_INITIALIZER
12379 		(struct cmd_vf_promisc_result,
12380 		 vf, "vf");
12381 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12382 	TOKEN_STRING_INITIALIZER
12383 		(struct cmd_vf_promisc_result,
12384 		 promisc, "promisc");
12385 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12386 	TOKEN_NUM_INITIALIZER
12387 		(struct cmd_vf_promisc_result,
12388 		 port_id, RTE_UINT16);
12389 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12390 	TOKEN_NUM_INITIALIZER
12391 		(struct cmd_vf_promisc_result,
12392 		 vf_id, RTE_UINT32);
12393 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12394 	TOKEN_STRING_INITIALIZER
12395 		(struct cmd_vf_promisc_result,
12396 		 on_off, "on#off");
12397 
12398 static void
12399 cmd_set_vf_promisc_parsed(
12400 	void *parsed_result,
12401 	__rte_unused struct cmdline *cl,
12402 	__rte_unused void *data)
12403 {
12404 	struct cmd_vf_promisc_result *res = parsed_result;
12405 	int ret = -ENOTSUP;
12406 
12407 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12408 
12409 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12410 		return;
12411 
12412 #ifdef RTE_NET_I40E
12413 	ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12414 						  res->vf_id, is_on);
12415 #endif
12416 
12417 	switch (ret) {
12418 	case 0:
12419 		break;
12420 	case -EINVAL:
12421 		fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12422 		break;
12423 	case -ENODEV:
12424 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12425 		break;
12426 	case -ENOTSUP:
12427 		fprintf(stderr, "function not implemented\n");
12428 		break;
12429 	default:
12430 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12431 	}
12432 }
12433 
12434 cmdline_parse_inst_t cmd_set_vf_promisc = {
12435 	.f = cmd_set_vf_promisc_parsed,
12436 	.data = NULL,
12437 	.help_str = "set vf promisc <port_id> <vf_id> on|off: "
12438 		"Set unicast promiscuous mode for a VF from the PF",
12439 	.tokens = {
12440 		(void *)&cmd_vf_promisc_set,
12441 		(void *)&cmd_vf_promisc_vf,
12442 		(void *)&cmd_vf_promisc_promisc,
12443 		(void *)&cmd_vf_promisc_port_id,
12444 		(void *)&cmd_vf_promisc_vf_id,
12445 		(void *)&cmd_vf_promisc_on_off,
12446 		NULL,
12447 	},
12448 };
12449 
12450 /* VF multicast promiscuous mode configuration */
12451 
12452 /* Common result structure for VF multicast promiscuous mode */
12453 struct cmd_vf_allmulti_result {
12454 	cmdline_fixed_string_t set;
12455 	cmdline_fixed_string_t vf;
12456 	cmdline_fixed_string_t allmulti;
12457 	portid_t port_id;
12458 	uint32_t vf_id;
12459 	cmdline_fixed_string_t on_off;
12460 };
12461 
12462 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12463 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12464 	TOKEN_STRING_INITIALIZER
12465 		(struct cmd_vf_allmulti_result,
12466 		 set, "set");
12467 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12468 	TOKEN_STRING_INITIALIZER
12469 		(struct cmd_vf_allmulti_result,
12470 		 vf, "vf");
12471 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12472 	TOKEN_STRING_INITIALIZER
12473 		(struct cmd_vf_allmulti_result,
12474 		 allmulti, "allmulti");
12475 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12476 	TOKEN_NUM_INITIALIZER
12477 		(struct cmd_vf_allmulti_result,
12478 		 port_id, RTE_UINT16);
12479 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12480 	TOKEN_NUM_INITIALIZER
12481 		(struct cmd_vf_allmulti_result,
12482 		 vf_id, RTE_UINT32);
12483 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12484 	TOKEN_STRING_INITIALIZER
12485 		(struct cmd_vf_allmulti_result,
12486 		 on_off, "on#off");
12487 
12488 static void
12489 cmd_set_vf_allmulti_parsed(
12490 	void *parsed_result,
12491 	__rte_unused struct cmdline *cl,
12492 	__rte_unused void *data)
12493 {
12494 	struct cmd_vf_allmulti_result *res = parsed_result;
12495 	int ret = -ENOTSUP;
12496 
12497 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12498 
12499 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12500 		return;
12501 
12502 #ifdef RTE_NET_I40E
12503 	ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12504 						    res->vf_id, is_on);
12505 #endif
12506 
12507 	switch (ret) {
12508 	case 0:
12509 		break;
12510 	case -EINVAL:
12511 		fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12512 		break;
12513 	case -ENODEV:
12514 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12515 		break;
12516 	case -ENOTSUP:
12517 		fprintf(stderr, "function not implemented\n");
12518 		break;
12519 	default:
12520 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12521 	}
12522 }
12523 
12524 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12525 	.f = cmd_set_vf_allmulti_parsed,
12526 	.data = NULL,
12527 	.help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12528 		"Set multicast promiscuous mode for a VF from the PF",
12529 	.tokens = {
12530 		(void *)&cmd_vf_allmulti_set,
12531 		(void *)&cmd_vf_allmulti_vf,
12532 		(void *)&cmd_vf_allmulti_allmulti,
12533 		(void *)&cmd_vf_allmulti_port_id,
12534 		(void *)&cmd_vf_allmulti_vf_id,
12535 		(void *)&cmd_vf_allmulti_on_off,
12536 		NULL,
12537 	},
12538 };
12539 
12540 /* vf broadcast mode configuration */
12541 
12542 /* Common result structure for vf broadcast */
12543 struct cmd_set_vf_broadcast_result {
12544 	cmdline_fixed_string_t set;
12545 	cmdline_fixed_string_t vf;
12546 	cmdline_fixed_string_t broadcast;
12547 	portid_t port_id;
12548 	uint16_t vf_id;
12549 	cmdline_fixed_string_t on_off;
12550 };
12551 
12552 /* Common CLI fields for vf broadcast enable disable */
12553 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12554 	TOKEN_STRING_INITIALIZER
12555 		(struct cmd_set_vf_broadcast_result,
12556 		 set, "set");
12557 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12558 	TOKEN_STRING_INITIALIZER
12559 		(struct cmd_set_vf_broadcast_result,
12560 		 vf, "vf");
12561 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12562 	TOKEN_STRING_INITIALIZER
12563 		(struct cmd_set_vf_broadcast_result,
12564 		 broadcast, "broadcast");
12565 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12566 	TOKEN_NUM_INITIALIZER
12567 		(struct cmd_set_vf_broadcast_result,
12568 		 port_id, RTE_UINT16);
12569 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12570 	TOKEN_NUM_INITIALIZER
12571 		(struct cmd_set_vf_broadcast_result,
12572 		 vf_id, RTE_UINT16);
12573 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12574 	TOKEN_STRING_INITIALIZER
12575 		(struct cmd_set_vf_broadcast_result,
12576 		 on_off, "on#off");
12577 
12578 static void
12579 cmd_set_vf_broadcast_parsed(
12580 	void *parsed_result,
12581 	__rte_unused struct cmdline *cl,
12582 	__rte_unused void *data)
12583 {
12584 	struct cmd_set_vf_broadcast_result *res = parsed_result;
12585 	int ret = -ENOTSUP;
12586 
12587 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12588 
12589 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12590 		return;
12591 
12592 #ifdef RTE_NET_I40E
12593 	ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12594 					    res->vf_id, is_on);
12595 #endif
12596 
12597 	switch (ret) {
12598 	case 0:
12599 		break;
12600 	case -EINVAL:
12601 		fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12602 			res->vf_id, is_on);
12603 		break;
12604 	case -ENODEV:
12605 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12606 		break;
12607 	case -ENOTSUP:
12608 		fprintf(stderr, "function not implemented\n");
12609 		break;
12610 	default:
12611 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12612 	}
12613 }
12614 
12615 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12616 	.f = cmd_set_vf_broadcast_parsed,
12617 	.data = NULL,
12618 	.help_str = "set vf broadcast <port_id> <vf_id> on|off",
12619 	.tokens = {
12620 		(void *)&cmd_set_vf_broadcast_set,
12621 		(void *)&cmd_set_vf_broadcast_vf,
12622 		(void *)&cmd_set_vf_broadcast_broadcast,
12623 		(void *)&cmd_set_vf_broadcast_port_id,
12624 		(void *)&cmd_set_vf_broadcast_vf_id,
12625 		(void *)&cmd_set_vf_broadcast_on_off,
12626 		NULL,
12627 	},
12628 };
12629 
12630 /* vf vlan tag configuration */
12631 
12632 /* Common result structure for vf vlan tag */
12633 struct cmd_set_vf_vlan_tag_result {
12634 	cmdline_fixed_string_t set;
12635 	cmdline_fixed_string_t vf;
12636 	cmdline_fixed_string_t vlan;
12637 	cmdline_fixed_string_t tag;
12638 	portid_t port_id;
12639 	uint16_t vf_id;
12640 	cmdline_fixed_string_t on_off;
12641 };
12642 
12643 /* Common CLI fields for vf vlan tag enable disable */
12644 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12645 	TOKEN_STRING_INITIALIZER
12646 		(struct cmd_set_vf_vlan_tag_result,
12647 		 set, "set");
12648 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12649 	TOKEN_STRING_INITIALIZER
12650 		(struct cmd_set_vf_vlan_tag_result,
12651 		 vf, "vf");
12652 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12653 	TOKEN_STRING_INITIALIZER
12654 		(struct cmd_set_vf_vlan_tag_result,
12655 		 vlan, "vlan");
12656 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12657 	TOKEN_STRING_INITIALIZER
12658 		(struct cmd_set_vf_vlan_tag_result,
12659 		 tag, "tag");
12660 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12661 	TOKEN_NUM_INITIALIZER
12662 		(struct cmd_set_vf_vlan_tag_result,
12663 		 port_id, RTE_UINT16);
12664 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12665 	TOKEN_NUM_INITIALIZER
12666 		(struct cmd_set_vf_vlan_tag_result,
12667 		 vf_id, RTE_UINT16);
12668 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12669 	TOKEN_STRING_INITIALIZER
12670 		(struct cmd_set_vf_vlan_tag_result,
12671 		 on_off, "on#off");
12672 
12673 static void
12674 cmd_set_vf_vlan_tag_parsed(
12675 	void *parsed_result,
12676 	__rte_unused struct cmdline *cl,
12677 	__rte_unused void *data)
12678 {
12679 	struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12680 	int ret = -ENOTSUP;
12681 
12682 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12683 
12684 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12685 		return;
12686 
12687 #ifdef RTE_NET_I40E
12688 	ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12689 					   res->vf_id, is_on);
12690 #endif
12691 
12692 	switch (ret) {
12693 	case 0:
12694 		break;
12695 	case -EINVAL:
12696 		fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12697 			res->vf_id, is_on);
12698 		break;
12699 	case -ENODEV:
12700 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12701 		break;
12702 	case -ENOTSUP:
12703 		fprintf(stderr, "function not implemented\n");
12704 		break;
12705 	default:
12706 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12707 	}
12708 }
12709 
12710 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12711 	.f = cmd_set_vf_vlan_tag_parsed,
12712 	.data = NULL,
12713 	.help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12714 	.tokens = {
12715 		(void *)&cmd_set_vf_vlan_tag_set,
12716 		(void *)&cmd_set_vf_vlan_tag_vf,
12717 		(void *)&cmd_set_vf_vlan_tag_vlan,
12718 		(void *)&cmd_set_vf_vlan_tag_tag,
12719 		(void *)&cmd_set_vf_vlan_tag_port_id,
12720 		(void *)&cmd_set_vf_vlan_tag_vf_id,
12721 		(void *)&cmd_set_vf_vlan_tag_on_off,
12722 		NULL,
12723 	},
12724 };
12725 
12726 /* Common definition of VF and TC TX bandwidth configuration */
12727 struct cmd_vf_tc_bw_result {
12728 	cmdline_fixed_string_t set;
12729 	cmdline_fixed_string_t vf;
12730 	cmdline_fixed_string_t tc;
12731 	cmdline_fixed_string_t tx;
12732 	cmdline_fixed_string_t min_bw;
12733 	cmdline_fixed_string_t max_bw;
12734 	cmdline_fixed_string_t strict_link_prio;
12735 	portid_t port_id;
12736 	uint16_t vf_id;
12737 	uint8_t tc_no;
12738 	uint32_t bw;
12739 	cmdline_fixed_string_t bw_list;
12740 	uint8_t tc_map;
12741 };
12742 
12743 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12744 	TOKEN_STRING_INITIALIZER
12745 		(struct cmd_vf_tc_bw_result,
12746 		 set, "set");
12747 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12748 	TOKEN_STRING_INITIALIZER
12749 		(struct cmd_vf_tc_bw_result,
12750 		 vf, "vf");
12751 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12752 	TOKEN_STRING_INITIALIZER
12753 		(struct cmd_vf_tc_bw_result,
12754 		 tc, "tc");
12755 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12756 	TOKEN_STRING_INITIALIZER
12757 		(struct cmd_vf_tc_bw_result,
12758 		 tx, "tx");
12759 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12760 	TOKEN_STRING_INITIALIZER
12761 		(struct cmd_vf_tc_bw_result,
12762 		 strict_link_prio, "strict-link-priority");
12763 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12764 	TOKEN_STRING_INITIALIZER
12765 		(struct cmd_vf_tc_bw_result,
12766 		 min_bw, "min-bandwidth");
12767 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12768 	TOKEN_STRING_INITIALIZER
12769 		(struct cmd_vf_tc_bw_result,
12770 		 max_bw, "max-bandwidth");
12771 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12772 	TOKEN_NUM_INITIALIZER
12773 		(struct cmd_vf_tc_bw_result,
12774 		 port_id, RTE_UINT16);
12775 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12776 	TOKEN_NUM_INITIALIZER
12777 		(struct cmd_vf_tc_bw_result,
12778 		 vf_id, RTE_UINT16);
12779 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12780 	TOKEN_NUM_INITIALIZER
12781 		(struct cmd_vf_tc_bw_result,
12782 		 tc_no, RTE_UINT8);
12783 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12784 	TOKEN_NUM_INITIALIZER
12785 		(struct cmd_vf_tc_bw_result,
12786 		 bw, RTE_UINT32);
12787 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12788 	TOKEN_STRING_INITIALIZER
12789 		(struct cmd_vf_tc_bw_result,
12790 		 bw_list, NULL);
12791 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12792 	TOKEN_NUM_INITIALIZER
12793 		(struct cmd_vf_tc_bw_result,
12794 		 tc_map, RTE_UINT8);
12795 
12796 /* VF max bandwidth setting */
12797 static void
12798 cmd_vf_max_bw_parsed(
12799 	void *parsed_result,
12800 	__rte_unused struct cmdline *cl,
12801 	__rte_unused void *data)
12802 {
12803 	struct cmd_vf_tc_bw_result *res = parsed_result;
12804 	int ret = -ENOTSUP;
12805 
12806 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12807 		return;
12808 
12809 #ifdef RTE_NET_I40E
12810 	ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12811 					 res->vf_id, res->bw);
12812 #endif
12813 
12814 	switch (ret) {
12815 	case 0:
12816 		break;
12817 	case -EINVAL:
12818 		fprintf(stderr, "invalid vf_id %d or bandwidth %d\n",
12819 			res->vf_id, res->bw);
12820 		break;
12821 	case -ENODEV:
12822 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12823 		break;
12824 	case -ENOTSUP:
12825 		fprintf(stderr, "function not implemented\n");
12826 		break;
12827 	default:
12828 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12829 	}
12830 }
12831 
12832 cmdline_parse_inst_t cmd_vf_max_bw = {
12833 	.f = cmd_vf_max_bw_parsed,
12834 	.data = NULL,
12835 	.help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12836 	.tokens = {
12837 		(void *)&cmd_vf_tc_bw_set,
12838 		(void *)&cmd_vf_tc_bw_vf,
12839 		(void *)&cmd_vf_tc_bw_tx,
12840 		(void *)&cmd_vf_tc_bw_max_bw,
12841 		(void *)&cmd_vf_tc_bw_port_id,
12842 		(void *)&cmd_vf_tc_bw_vf_id,
12843 		(void *)&cmd_vf_tc_bw_bw,
12844 		NULL,
12845 	},
12846 };
12847 
12848 static int
12849 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12850 			   uint8_t *tc_num,
12851 			   char *str)
12852 {
12853 	uint32_t size;
12854 	const char *p, *p0 = str;
12855 	char s[256];
12856 	char *end;
12857 	char *str_fld[16];
12858 	uint16_t i;
12859 	int ret;
12860 
12861 	p = strchr(p0, '(');
12862 	if (p == NULL) {
12863 		fprintf(stderr,
12864 			"The bandwidth-list should be '(bw1, bw2, ...)'\n");
12865 		return -1;
12866 	}
12867 	p++;
12868 	p0 = strchr(p, ')');
12869 	if (p0 == NULL) {
12870 		fprintf(stderr,
12871 			"The bandwidth-list should be '(bw1, bw2, ...)'\n");
12872 		return -1;
12873 	}
12874 	size = p0 - p;
12875 	if (size >= sizeof(s)) {
12876 		fprintf(stderr,
12877 			"The string size exceeds the internal buffer size\n");
12878 		return -1;
12879 	}
12880 	snprintf(s, sizeof(s), "%.*s", size, p);
12881 	ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12882 	if (ret <= 0) {
12883 		fprintf(stderr, "Failed to get the bandwidth list.\n");
12884 		return -1;
12885 	}
12886 	*tc_num = ret;
12887 	for (i = 0; i < ret; i++)
12888 		bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12889 
12890 	return 0;
12891 }
12892 
12893 /* TC min bandwidth setting */
12894 static void
12895 cmd_vf_tc_min_bw_parsed(
12896 	void *parsed_result,
12897 	__rte_unused struct cmdline *cl,
12898 	__rte_unused void *data)
12899 {
12900 	struct cmd_vf_tc_bw_result *res = parsed_result;
12901 	uint8_t tc_num;
12902 	uint8_t bw[16];
12903 	int ret = -ENOTSUP;
12904 
12905 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12906 		return;
12907 
12908 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12909 	if (ret)
12910 		return;
12911 
12912 #ifdef RTE_NET_I40E
12913 	ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12914 					      tc_num, bw);
12915 #endif
12916 
12917 	switch (ret) {
12918 	case 0:
12919 		break;
12920 	case -EINVAL:
12921 		fprintf(stderr, "invalid vf_id %d or bandwidth\n", res->vf_id);
12922 		break;
12923 	case -ENODEV:
12924 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12925 		break;
12926 	case -ENOTSUP:
12927 		fprintf(stderr, "function not implemented\n");
12928 		break;
12929 	default:
12930 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12931 	}
12932 }
12933 
12934 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12935 	.f = cmd_vf_tc_min_bw_parsed,
12936 	.data = NULL,
12937 	.help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12938 		    " <bw1, bw2, ...>",
12939 	.tokens = {
12940 		(void *)&cmd_vf_tc_bw_set,
12941 		(void *)&cmd_vf_tc_bw_vf,
12942 		(void *)&cmd_vf_tc_bw_tc,
12943 		(void *)&cmd_vf_tc_bw_tx,
12944 		(void *)&cmd_vf_tc_bw_min_bw,
12945 		(void *)&cmd_vf_tc_bw_port_id,
12946 		(void *)&cmd_vf_tc_bw_vf_id,
12947 		(void *)&cmd_vf_tc_bw_bw_list,
12948 		NULL,
12949 	},
12950 };
12951 
12952 static void
12953 cmd_tc_min_bw_parsed(
12954 	void *parsed_result,
12955 	__rte_unused struct cmdline *cl,
12956 	__rte_unused void *data)
12957 {
12958 	struct cmd_vf_tc_bw_result *res = parsed_result;
12959 	struct rte_port *port;
12960 	uint8_t tc_num;
12961 	uint8_t bw[16];
12962 	int ret = -ENOTSUP;
12963 
12964 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12965 		return;
12966 
12967 	port = &ports[res->port_id];
12968 	/** Check if the port is not started **/
12969 	if (port->port_status != RTE_PORT_STOPPED) {
12970 		fprintf(stderr, "Please stop port %d first\n", res->port_id);
12971 		return;
12972 	}
12973 
12974 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12975 	if (ret)
12976 		return;
12977 
12978 #ifdef RTE_NET_IXGBE
12979 	ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12980 #endif
12981 
12982 	switch (ret) {
12983 	case 0:
12984 		break;
12985 	case -EINVAL:
12986 		fprintf(stderr, "invalid bandwidth\n");
12987 		break;
12988 	case -ENODEV:
12989 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
12990 		break;
12991 	case -ENOTSUP:
12992 		fprintf(stderr, "function not implemented\n");
12993 		break;
12994 	default:
12995 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12996 	}
12997 }
12998 
12999 cmdline_parse_inst_t cmd_tc_min_bw = {
13000 	.f = cmd_tc_min_bw_parsed,
13001 	.data = NULL,
13002 	.help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13003 	.tokens = {
13004 		(void *)&cmd_vf_tc_bw_set,
13005 		(void *)&cmd_vf_tc_bw_tc,
13006 		(void *)&cmd_vf_tc_bw_tx,
13007 		(void *)&cmd_vf_tc_bw_min_bw,
13008 		(void *)&cmd_vf_tc_bw_port_id,
13009 		(void *)&cmd_vf_tc_bw_bw_list,
13010 		NULL,
13011 	},
13012 };
13013 
13014 /* TC max bandwidth setting */
13015 static void
13016 cmd_vf_tc_max_bw_parsed(
13017 	void *parsed_result,
13018 	__rte_unused struct cmdline *cl,
13019 	__rte_unused void *data)
13020 {
13021 	struct cmd_vf_tc_bw_result *res = parsed_result;
13022 	int ret = -ENOTSUP;
13023 
13024 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13025 		return;
13026 
13027 #ifdef RTE_NET_I40E
13028 	ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13029 					    res->tc_no, res->bw);
13030 #endif
13031 
13032 	switch (ret) {
13033 	case 0:
13034 		break;
13035 	case -EINVAL:
13036 		fprintf(stderr,
13037 			"invalid vf_id %d, tc_no %d or bandwidth %d\n",
13038 			res->vf_id, res->tc_no, res->bw);
13039 		break;
13040 	case -ENODEV:
13041 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
13042 		break;
13043 	case -ENOTSUP:
13044 		fprintf(stderr, "function not implemented\n");
13045 		break;
13046 	default:
13047 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
13048 	}
13049 }
13050 
13051 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13052 	.f = cmd_vf_tc_max_bw_parsed,
13053 	.data = NULL,
13054 	.help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13055 		    " <bandwidth>",
13056 	.tokens = {
13057 		(void *)&cmd_vf_tc_bw_set,
13058 		(void *)&cmd_vf_tc_bw_vf,
13059 		(void *)&cmd_vf_tc_bw_tc,
13060 		(void *)&cmd_vf_tc_bw_tx,
13061 		(void *)&cmd_vf_tc_bw_max_bw,
13062 		(void *)&cmd_vf_tc_bw_port_id,
13063 		(void *)&cmd_vf_tc_bw_vf_id,
13064 		(void *)&cmd_vf_tc_bw_tc_no,
13065 		(void *)&cmd_vf_tc_bw_bw,
13066 		NULL,
13067 	},
13068 };
13069 
13070 /** Set VXLAN encapsulation details */
13071 struct cmd_set_vxlan_result {
13072 	cmdline_fixed_string_t set;
13073 	cmdline_fixed_string_t vxlan;
13074 	cmdline_fixed_string_t pos_token;
13075 	cmdline_fixed_string_t ip_version;
13076 	uint32_t vlan_present:1;
13077 	uint32_t vni;
13078 	uint16_t udp_src;
13079 	uint16_t udp_dst;
13080 	cmdline_ipaddr_t ip_src;
13081 	cmdline_ipaddr_t ip_dst;
13082 	uint16_t tci;
13083 	uint8_t tos;
13084 	uint8_t ttl;
13085 	struct rte_ether_addr eth_src;
13086 	struct rte_ether_addr eth_dst;
13087 };
13088 
13089 cmdline_parse_token_string_t cmd_set_vxlan_set =
13090 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
13091 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
13092 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
13093 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
13094 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13095 				 "vxlan-tos-ttl");
13096 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
13097 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13098 				 "vxlan-with-vlan");
13099 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
13100 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13101 				 "ip-version");
13102 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
13103 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
13104 				 "ipv4#ipv6");
13105 cmdline_parse_token_string_t cmd_set_vxlan_vni =
13106 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13107 				 "vni");
13108 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
13109 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
13110 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
13111 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13112 				 "udp-src");
13113 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
13114 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
13115 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
13116 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13117 				 "udp-dst");
13118 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
13119 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
13120 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
13121 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13122 				 "ip-tos");
13123 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
13124 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
13125 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
13126 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13127 				 "ip-ttl");
13128 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
13129 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
13130 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
13131 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13132 				 "ip-src");
13133 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
13134 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
13135 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
13136 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13137 				 "ip-dst");
13138 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
13139 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
13140 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
13141 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13142 				 "vlan-tci");
13143 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
13144 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
13145 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
13146 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13147 				 "eth-src");
13148 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
13149 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
13150 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
13151 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13152 				 "eth-dst");
13153 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
13154 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
13155 
13156 static void cmd_set_vxlan_parsed(void *parsed_result,
13157 	__rte_unused struct cmdline *cl,
13158 	__rte_unused void *data)
13159 {
13160 	struct cmd_set_vxlan_result *res = parsed_result;
13161 	union {
13162 		uint32_t vxlan_id;
13163 		uint8_t vni[4];
13164 	} id = {
13165 		.vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
13166 	};
13167 
13168 	vxlan_encap_conf.select_tos_ttl = 0;
13169 	if (strcmp(res->vxlan, "vxlan") == 0)
13170 		vxlan_encap_conf.select_vlan = 0;
13171 	else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
13172 		vxlan_encap_conf.select_vlan = 1;
13173 	else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
13174 		vxlan_encap_conf.select_vlan = 0;
13175 		vxlan_encap_conf.select_tos_ttl = 1;
13176 	}
13177 	if (strcmp(res->ip_version, "ipv4") == 0)
13178 		vxlan_encap_conf.select_ipv4 = 1;
13179 	else if (strcmp(res->ip_version, "ipv6") == 0)
13180 		vxlan_encap_conf.select_ipv4 = 0;
13181 	else
13182 		return;
13183 	rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
13184 	vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13185 	vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13186 	vxlan_encap_conf.ip_tos = res->tos;
13187 	vxlan_encap_conf.ip_ttl = res->ttl;
13188 	if (vxlan_encap_conf.select_ipv4) {
13189 		IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
13190 		IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
13191 	} else {
13192 		IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
13193 		IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
13194 	}
13195 	if (vxlan_encap_conf.select_vlan)
13196 		vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13197 	rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
13198 		   RTE_ETHER_ADDR_LEN);
13199 	rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13200 		   RTE_ETHER_ADDR_LEN);
13201 }
13202 
13203 cmdline_parse_inst_t cmd_set_vxlan = {
13204 	.f = cmd_set_vxlan_parsed,
13205 	.data = NULL,
13206 	.help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
13207 		" <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
13208 		" eth-src <eth-src> eth-dst <eth-dst>",
13209 	.tokens = {
13210 		(void *)&cmd_set_vxlan_set,
13211 		(void *)&cmd_set_vxlan_vxlan,
13212 		(void *)&cmd_set_vxlan_ip_version,
13213 		(void *)&cmd_set_vxlan_ip_version_value,
13214 		(void *)&cmd_set_vxlan_vni,
13215 		(void *)&cmd_set_vxlan_vni_value,
13216 		(void *)&cmd_set_vxlan_udp_src,
13217 		(void *)&cmd_set_vxlan_udp_src_value,
13218 		(void *)&cmd_set_vxlan_udp_dst,
13219 		(void *)&cmd_set_vxlan_udp_dst_value,
13220 		(void *)&cmd_set_vxlan_ip_src,
13221 		(void *)&cmd_set_vxlan_ip_src_value,
13222 		(void *)&cmd_set_vxlan_ip_dst,
13223 		(void *)&cmd_set_vxlan_ip_dst_value,
13224 		(void *)&cmd_set_vxlan_eth_src,
13225 		(void *)&cmd_set_vxlan_eth_src_value,
13226 		(void *)&cmd_set_vxlan_eth_dst,
13227 		(void *)&cmd_set_vxlan_eth_dst_value,
13228 		NULL,
13229 	},
13230 };
13231 
13232 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
13233 	.f = cmd_set_vxlan_parsed,
13234 	.data = NULL,
13235 	.help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
13236 		" <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
13237 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13238 		" eth-dst <eth-dst>",
13239 	.tokens = {
13240 		(void *)&cmd_set_vxlan_set,
13241 		(void *)&cmd_set_vxlan_vxlan_tos_ttl,
13242 		(void *)&cmd_set_vxlan_ip_version,
13243 		(void *)&cmd_set_vxlan_ip_version_value,
13244 		(void *)&cmd_set_vxlan_vni,
13245 		(void *)&cmd_set_vxlan_vni_value,
13246 		(void *)&cmd_set_vxlan_udp_src,
13247 		(void *)&cmd_set_vxlan_udp_src_value,
13248 		(void *)&cmd_set_vxlan_udp_dst,
13249 		(void *)&cmd_set_vxlan_udp_dst_value,
13250 		(void *)&cmd_set_vxlan_ip_tos,
13251 		(void *)&cmd_set_vxlan_ip_tos_value,
13252 		(void *)&cmd_set_vxlan_ip_ttl,
13253 		(void *)&cmd_set_vxlan_ip_ttl_value,
13254 		(void *)&cmd_set_vxlan_ip_src,
13255 		(void *)&cmd_set_vxlan_ip_src_value,
13256 		(void *)&cmd_set_vxlan_ip_dst,
13257 		(void *)&cmd_set_vxlan_ip_dst_value,
13258 		(void *)&cmd_set_vxlan_eth_src,
13259 		(void *)&cmd_set_vxlan_eth_src_value,
13260 		(void *)&cmd_set_vxlan_eth_dst,
13261 		(void *)&cmd_set_vxlan_eth_dst_value,
13262 		NULL,
13263 	},
13264 };
13265 
13266 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
13267 	.f = cmd_set_vxlan_parsed,
13268 	.data = NULL,
13269 	.help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
13270 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
13271 		" <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
13272 		" <eth-dst>",
13273 	.tokens = {
13274 		(void *)&cmd_set_vxlan_set,
13275 		(void *)&cmd_set_vxlan_vxlan_with_vlan,
13276 		(void *)&cmd_set_vxlan_ip_version,
13277 		(void *)&cmd_set_vxlan_ip_version_value,
13278 		(void *)&cmd_set_vxlan_vni,
13279 		(void *)&cmd_set_vxlan_vni_value,
13280 		(void *)&cmd_set_vxlan_udp_src,
13281 		(void *)&cmd_set_vxlan_udp_src_value,
13282 		(void *)&cmd_set_vxlan_udp_dst,
13283 		(void *)&cmd_set_vxlan_udp_dst_value,
13284 		(void *)&cmd_set_vxlan_ip_src,
13285 		(void *)&cmd_set_vxlan_ip_src_value,
13286 		(void *)&cmd_set_vxlan_ip_dst,
13287 		(void *)&cmd_set_vxlan_ip_dst_value,
13288 		(void *)&cmd_set_vxlan_vlan,
13289 		(void *)&cmd_set_vxlan_vlan_value,
13290 		(void *)&cmd_set_vxlan_eth_src,
13291 		(void *)&cmd_set_vxlan_eth_src_value,
13292 		(void *)&cmd_set_vxlan_eth_dst,
13293 		(void *)&cmd_set_vxlan_eth_dst_value,
13294 		NULL,
13295 	},
13296 };
13297 
13298 /** Set NVGRE encapsulation details */
13299 struct cmd_set_nvgre_result {
13300 	cmdline_fixed_string_t set;
13301 	cmdline_fixed_string_t nvgre;
13302 	cmdline_fixed_string_t pos_token;
13303 	cmdline_fixed_string_t ip_version;
13304 	uint32_t tni;
13305 	cmdline_ipaddr_t ip_src;
13306 	cmdline_ipaddr_t ip_dst;
13307 	uint16_t tci;
13308 	struct rte_ether_addr eth_src;
13309 	struct rte_ether_addr eth_dst;
13310 };
13311 
13312 cmdline_parse_token_string_t cmd_set_nvgre_set =
13313 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13314 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13315 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13316 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13317 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13318 				 "nvgre-with-vlan");
13319 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13320 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13321 				 "ip-version");
13322 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13323 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13324 				 "ipv4#ipv6");
13325 cmdline_parse_token_string_t cmd_set_nvgre_tni =
13326 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13327 				 "tni");
13328 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13329 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
13330 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13331 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13332 				 "ip-src");
13333 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13334 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13335 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13336 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13337 				 "ip-dst");
13338 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13339 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13340 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13341 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13342 				 "vlan-tci");
13343 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13344 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
13345 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13346 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13347 				 "eth-src");
13348 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13349 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13350 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13351 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13352 				 "eth-dst");
13353 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13354 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13355 
13356 static void cmd_set_nvgre_parsed(void *parsed_result,
13357 	__rte_unused struct cmdline *cl,
13358 	__rte_unused void *data)
13359 {
13360 	struct cmd_set_nvgre_result *res = parsed_result;
13361 	union {
13362 		uint32_t nvgre_tni;
13363 		uint8_t tni[4];
13364 	} id = {
13365 		.nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13366 	};
13367 
13368 	if (strcmp(res->nvgre, "nvgre") == 0)
13369 		nvgre_encap_conf.select_vlan = 0;
13370 	else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13371 		nvgre_encap_conf.select_vlan = 1;
13372 	if (strcmp(res->ip_version, "ipv4") == 0)
13373 		nvgre_encap_conf.select_ipv4 = 1;
13374 	else if (strcmp(res->ip_version, "ipv6") == 0)
13375 		nvgre_encap_conf.select_ipv4 = 0;
13376 	else
13377 		return;
13378 	rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13379 	if (nvgre_encap_conf.select_ipv4) {
13380 		IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13381 		IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13382 	} else {
13383 		IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13384 		IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13385 	}
13386 	if (nvgre_encap_conf.select_vlan)
13387 		nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13388 	rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13389 		   RTE_ETHER_ADDR_LEN);
13390 	rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13391 		   RTE_ETHER_ADDR_LEN);
13392 }
13393 
13394 cmdline_parse_inst_t cmd_set_nvgre = {
13395 	.f = cmd_set_nvgre_parsed,
13396 	.data = NULL,
13397 	.help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13398 		" <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13399 		" eth-dst <eth-dst>",
13400 	.tokens = {
13401 		(void *)&cmd_set_nvgre_set,
13402 		(void *)&cmd_set_nvgre_nvgre,
13403 		(void *)&cmd_set_nvgre_ip_version,
13404 		(void *)&cmd_set_nvgre_ip_version_value,
13405 		(void *)&cmd_set_nvgre_tni,
13406 		(void *)&cmd_set_nvgre_tni_value,
13407 		(void *)&cmd_set_nvgre_ip_src,
13408 		(void *)&cmd_set_nvgre_ip_src_value,
13409 		(void *)&cmd_set_nvgre_ip_dst,
13410 		(void *)&cmd_set_nvgre_ip_dst_value,
13411 		(void *)&cmd_set_nvgre_eth_src,
13412 		(void *)&cmd_set_nvgre_eth_src_value,
13413 		(void *)&cmd_set_nvgre_eth_dst,
13414 		(void *)&cmd_set_nvgre_eth_dst_value,
13415 		NULL,
13416 	},
13417 };
13418 
13419 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13420 	.f = cmd_set_nvgre_parsed,
13421 	.data = NULL,
13422 	.help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13423 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13424 		" eth-src <eth-src> eth-dst <eth-dst>",
13425 	.tokens = {
13426 		(void *)&cmd_set_nvgre_set,
13427 		(void *)&cmd_set_nvgre_nvgre_with_vlan,
13428 		(void *)&cmd_set_nvgre_ip_version,
13429 		(void *)&cmd_set_nvgre_ip_version_value,
13430 		(void *)&cmd_set_nvgre_tni,
13431 		(void *)&cmd_set_nvgre_tni_value,
13432 		(void *)&cmd_set_nvgre_ip_src,
13433 		(void *)&cmd_set_nvgre_ip_src_value,
13434 		(void *)&cmd_set_nvgre_ip_dst,
13435 		(void *)&cmd_set_nvgre_ip_dst_value,
13436 		(void *)&cmd_set_nvgre_vlan,
13437 		(void *)&cmd_set_nvgre_vlan_value,
13438 		(void *)&cmd_set_nvgre_eth_src,
13439 		(void *)&cmd_set_nvgre_eth_src_value,
13440 		(void *)&cmd_set_nvgre_eth_dst,
13441 		(void *)&cmd_set_nvgre_eth_dst_value,
13442 		NULL,
13443 	},
13444 };
13445 
13446 /** Set L2 encapsulation details */
13447 struct cmd_set_l2_encap_result {
13448 	cmdline_fixed_string_t set;
13449 	cmdline_fixed_string_t l2_encap;
13450 	cmdline_fixed_string_t pos_token;
13451 	cmdline_fixed_string_t ip_version;
13452 	uint32_t vlan_present:1;
13453 	uint16_t tci;
13454 	struct rte_ether_addr eth_src;
13455 	struct rte_ether_addr eth_dst;
13456 };
13457 
13458 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13459 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13460 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13461 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13462 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13463 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13464 				 "l2_encap-with-vlan");
13465 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13466 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13467 				 "ip-version");
13468 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13469 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13470 				 "ipv4#ipv6");
13471 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13472 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13473 				 "vlan-tci");
13474 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13475 	TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13476 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13477 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13478 				 "eth-src");
13479 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13480 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13481 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13482 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13483 				 "eth-dst");
13484 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13485 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13486 
13487 static void cmd_set_l2_encap_parsed(void *parsed_result,
13488 	__rte_unused struct cmdline *cl,
13489 	__rte_unused void *data)
13490 {
13491 	struct cmd_set_l2_encap_result *res = parsed_result;
13492 
13493 	if (strcmp(res->l2_encap, "l2_encap") == 0)
13494 		l2_encap_conf.select_vlan = 0;
13495 	else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13496 		l2_encap_conf.select_vlan = 1;
13497 	if (strcmp(res->ip_version, "ipv4") == 0)
13498 		l2_encap_conf.select_ipv4 = 1;
13499 	else if (strcmp(res->ip_version, "ipv6") == 0)
13500 		l2_encap_conf.select_ipv4 = 0;
13501 	else
13502 		return;
13503 	if (l2_encap_conf.select_vlan)
13504 		l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13505 	rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13506 		   RTE_ETHER_ADDR_LEN);
13507 	rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13508 		   RTE_ETHER_ADDR_LEN);
13509 }
13510 
13511 cmdline_parse_inst_t cmd_set_l2_encap = {
13512 	.f = cmd_set_l2_encap_parsed,
13513 	.data = NULL,
13514 	.help_str = "set l2_encap ip-version ipv4|ipv6"
13515 		" eth-src <eth-src> eth-dst <eth-dst>",
13516 	.tokens = {
13517 		(void *)&cmd_set_l2_encap_set,
13518 		(void *)&cmd_set_l2_encap_l2_encap,
13519 		(void *)&cmd_set_l2_encap_ip_version,
13520 		(void *)&cmd_set_l2_encap_ip_version_value,
13521 		(void *)&cmd_set_l2_encap_eth_src,
13522 		(void *)&cmd_set_l2_encap_eth_src_value,
13523 		(void *)&cmd_set_l2_encap_eth_dst,
13524 		(void *)&cmd_set_l2_encap_eth_dst_value,
13525 		NULL,
13526 	},
13527 };
13528 
13529 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13530 	.f = cmd_set_l2_encap_parsed,
13531 	.data = NULL,
13532 	.help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13533 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13534 	.tokens = {
13535 		(void *)&cmd_set_l2_encap_set,
13536 		(void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13537 		(void *)&cmd_set_l2_encap_ip_version,
13538 		(void *)&cmd_set_l2_encap_ip_version_value,
13539 		(void *)&cmd_set_l2_encap_vlan,
13540 		(void *)&cmd_set_l2_encap_vlan_value,
13541 		(void *)&cmd_set_l2_encap_eth_src,
13542 		(void *)&cmd_set_l2_encap_eth_src_value,
13543 		(void *)&cmd_set_l2_encap_eth_dst,
13544 		(void *)&cmd_set_l2_encap_eth_dst_value,
13545 		NULL,
13546 	},
13547 };
13548 
13549 /** Set L2 decapsulation details */
13550 struct cmd_set_l2_decap_result {
13551 	cmdline_fixed_string_t set;
13552 	cmdline_fixed_string_t l2_decap;
13553 	cmdline_fixed_string_t pos_token;
13554 	uint32_t vlan_present:1;
13555 };
13556 
13557 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13558 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13559 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13560 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13561 				 "l2_decap");
13562 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13563 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13564 				 "l2_decap-with-vlan");
13565 
13566 static void cmd_set_l2_decap_parsed(void *parsed_result,
13567 	__rte_unused struct cmdline *cl,
13568 	__rte_unused void *data)
13569 {
13570 	struct cmd_set_l2_decap_result *res = parsed_result;
13571 
13572 	if (strcmp(res->l2_decap, "l2_decap") == 0)
13573 		l2_decap_conf.select_vlan = 0;
13574 	else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13575 		l2_decap_conf.select_vlan = 1;
13576 }
13577 
13578 cmdline_parse_inst_t cmd_set_l2_decap = {
13579 	.f = cmd_set_l2_decap_parsed,
13580 	.data = NULL,
13581 	.help_str = "set l2_decap",
13582 	.tokens = {
13583 		(void *)&cmd_set_l2_decap_set,
13584 		(void *)&cmd_set_l2_decap_l2_decap,
13585 		NULL,
13586 	},
13587 };
13588 
13589 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13590 	.f = cmd_set_l2_decap_parsed,
13591 	.data = NULL,
13592 	.help_str = "set l2_decap-with-vlan",
13593 	.tokens = {
13594 		(void *)&cmd_set_l2_decap_set,
13595 		(void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13596 		NULL,
13597 	},
13598 };
13599 
13600 /** Set MPLSoGRE encapsulation details */
13601 struct cmd_set_mplsogre_encap_result {
13602 	cmdline_fixed_string_t set;
13603 	cmdline_fixed_string_t mplsogre;
13604 	cmdline_fixed_string_t pos_token;
13605 	cmdline_fixed_string_t ip_version;
13606 	uint32_t vlan_present:1;
13607 	uint32_t label;
13608 	cmdline_ipaddr_t ip_src;
13609 	cmdline_ipaddr_t ip_dst;
13610 	uint16_t tci;
13611 	struct rte_ether_addr eth_src;
13612 	struct rte_ether_addr eth_dst;
13613 };
13614 
13615 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13616 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13617 				 "set");
13618 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13619 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13620 				 "mplsogre_encap");
13621 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13622 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13623 				 mplsogre, "mplsogre_encap-with-vlan");
13624 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13625 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13626 				 pos_token, "ip-version");
13627 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13628 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13629 				 ip_version, "ipv4#ipv6");
13630 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13631 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13632 				 pos_token, "label");
13633 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13634 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13635 			      RTE_UINT32);
13636 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13637 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13638 				 pos_token, "ip-src");
13639 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13640 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13641 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13642 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13643 				 pos_token, "ip-dst");
13644 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13645 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13646 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13647 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13648 				 pos_token, "vlan-tci");
13649 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13650 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13651 			      RTE_UINT16);
13652 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13653 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13654 				 pos_token, "eth-src");
13655 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13656 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13657 				    eth_src);
13658 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13659 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13660 				 pos_token, "eth-dst");
13661 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13662 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13663 				    eth_dst);
13664 
13665 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13666 	__rte_unused struct cmdline *cl,
13667 	__rte_unused void *data)
13668 {
13669 	struct cmd_set_mplsogre_encap_result *res = parsed_result;
13670 	union {
13671 		uint32_t mplsogre_label;
13672 		uint8_t label[4];
13673 	} id = {
13674 		.mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13675 	};
13676 
13677 	if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13678 		mplsogre_encap_conf.select_vlan = 0;
13679 	else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13680 		mplsogre_encap_conf.select_vlan = 1;
13681 	if (strcmp(res->ip_version, "ipv4") == 0)
13682 		mplsogre_encap_conf.select_ipv4 = 1;
13683 	else if (strcmp(res->ip_version, "ipv6") == 0)
13684 		mplsogre_encap_conf.select_ipv4 = 0;
13685 	else
13686 		return;
13687 	rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13688 	if (mplsogre_encap_conf.select_ipv4) {
13689 		IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13690 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13691 	} else {
13692 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13693 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13694 	}
13695 	if (mplsogre_encap_conf.select_vlan)
13696 		mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13697 	rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13698 		   RTE_ETHER_ADDR_LEN);
13699 	rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13700 		   RTE_ETHER_ADDR_LEN);
13701 }
13702 
13703 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13704 	.f = cmd_set_mplsogre_encap_parsed,
13705 	.data = NULL,
13706 	.help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13707 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13708 		" eth-dst <eth-dst>",
13709 	.tokens = {
13710 		(void *)&cmd_set_mplsogre_encap_set,
13711 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13712 		(void *)&cmd_set_mplsogre_encap_ip_version,
13713 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
13714 		(void *)&cmd_set_mplsogre_encap_label,
13715 		(void *)&cmd_set_mplsogre_encap_label_value,
13716 		(void *)&cmd_set_mplsogre_encap_ip_src,
13717 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
13718 		(void *)&cmd_set_mplsogre_encap_ip_dst,
13719 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
13720 		(void *)&cmd_set_mplsogre_encap_eth_src,
13721 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
13722 		(void *)&cmd_set_mplsogre_encap_eth_dst,
13723 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
13724 		NULL,
13725 	},
13726 };
13727 
13728 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13729 	.f = cmd_set_mplsogre_encap_parsed,
13730 	.data = NULL,
13731 	.help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13732 		" label <label> ip-src <ip-src> ip-dst <ip-dst>"
13733 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13734 	.tokens = {
13735 		(void *)&cmd_set_mplsogre_encap_set,
13736 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13737 		(void *)&cmd_set_mplsogre_encap_ip_version,
13738 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
13739 		(void *)&cmd_set_mplsogre_encap_label,
13740 		(void *)&cmd_set_mplsogre_encap_label_value,
13741 		(void *)&cmd_set_mplsogre_encap_ip_src,
13742 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
13743 		(void *)&cmd_set_mplsogre_encap_ip_dst,
13744 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
13745 		(void *)&cmd_set_mplsogre_encap_vlan,
13746 		(void *)&cmd_set_mplsogre_encap_vlan_value,
13747 		(void *)&cmd_set_mplsogre_encap_eth_src,
13748 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
13749 		(void *)&cmd_set_mplsogre_encap_eth_dst,
13750 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
13751 		NULL,
13752 	},
13753 };
13754 
13755 /** Set MPLSoGRE decapsulation details */
13756 struct cmd_set_mplsogre_decap_result {
13757 	cmdline_fixed_string_t set;
13758 	cmdline_fixed_string_t mplsogre;
13759 	cmdline_fixed_string_t pos_token;
13760 	cmdline_fixed_string_t ip_version;
13761 	uint32_t vlan_present:1;
13762 };
13763 
13764 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13765 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13766 				 "set");
13767 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13768 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13769 				 "mplsogre_decap");
13770 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13771 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13772 				 mplsogre, "mplsogre_decap-with-vlan");
13773 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13774 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13775 				 pos_token, "ip-version");
13776 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13777 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13778 				 ip_version, "ipv4#ipv6");
13779 
13780 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13781 	__rte_unused struct cmdline *cl,
13782 	__rte_unused void *data)
13783 {
13784 	struct cmd_set_mplsogre_decap_result *res = parsed_result;
13785 
13786 	if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13787 		mplsogre_decap_conf.select_vlan = 0;
13788 	else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13789 		mplsogre_decap_conf.select_vlan = 1;
13790 	if (strcmp(res->ip_version, "ipv4") == 0)
13791 		mplsogre_decap_conf.select_ipv4 = 1;
13792 	else if (strcmp(res->ip_version, "ipv6") == 0)
13793 		mplsogre_decap_conf.select_ipv4 = 0;
13794 }
13795 
13796 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13797 	.f = cmd_set_mplsogre_decap_parsed,
13798 	.data = NULL,
13799 	.help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13800 	.tokens = {
13801 		(void *)&cmd_set_mplsogre_decap_set,
13802 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13803 		(void *)&cmd_set_mplsogre_decap_ip_version,
13804 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
13805 		NULL,
13806 	},
13807 };
13808 
13809 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13810 	.f = cmd_set_mplsogre_decap_parsed,
13811 	.data = NULL,
13812 	.help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13813 	.tokens = {
13814 		(void *)&cmd_set_mplsogre_decap_set,
13815 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13816 		(void *)&cmd_set_mplsogre_decap_ip_version,
13817 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
13818 		NULL,
13819 	},
13820 };
13821 
13822 /** Set MPLSoUDP encapsulation details */
13823 struct cmd_set_mplsoudp_encap_result {
13824 	cmdline_fixed_string_t set;
13825 	cmdline_fixed_string_t mplsoudp;
13826 	cmdline_fixed_string_t pos_token;
13827 	cmdline_fixed_string_t ip_version;
13828 	uint32_t vlan_present:1;
13829 	uint32_t label;
13830 	uint16_t udp_src;
13831 	uint16_t udp_dst;
13832 	cmdline_ipaddr_t ip_src;
13833 	cmdline_ipaddr_t ip_dst;
13834 	uint16_t tci;
13835 	struct rte_ether_addr eth_src;
13836 	struct rte_ether_addr eth_dst;
13837 };
13838 
13839 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13840 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13841 				 "set");
13842 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13843 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13844 				 "mplsoudp_encap");
13845 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13846 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13847 				 mplsoudp, "mplsoudp_encap-with-vlan");
13848 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13849 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13850 				 pos_token, "ip-version");
13851 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13852 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13853 				 ip_version, "ipv4#ipv6");
13854 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13855 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13856 				 pos_token, "label");
13857 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13858 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13859 			      RTE_UINT32);
13860 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13861 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13862 				 pos_token, "udp-src");
13863 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13864 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13865 			      RTE_UINT16);
13866 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13867 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13868 				 pos_token, "udp-dst");
13869 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13870 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13871 			      RTE_UINT16);
13872 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13873 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13874 				 pos_token, "ip-src");
13875 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13876 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13877 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13878 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13879 				 pos_token, "ip-dst");
13880 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13881 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13882 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13883 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13884 				 pos_token, "vlan-tci");
13885 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13886 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13887 			      RTE_UINT16);
13888 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13889 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13890 				 pos_token, "eth-src");
13891 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13892 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13893 				    eth_src);
13894 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13895 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13896 				 pos_token, "eth-dst");
13897 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13898 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13899 				    eth_dst);
13900 
13901 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13902 	__rte_unused struct cmdline *cl,
13903 	__rte_unused void *data)
13904 {
13905 	struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13906 	union {
13907 		uint32_t mplsoudp_label;
13908 		uint8_t label[4];
13909 	} id = {
13910 		.mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13911 	};
13912 
13913 	if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13914 		mplsoudp_encap_conf.select_vlan = 0;
13915 	else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13916 		mplsoudp_encap_conf.select_vlan = 1;
13917 	if (strcmp(res->ip_version, "ipv4") == 0)
13918 		mplsoudp_encap_conf.select_ipv4 = 1;
13919 	else if (strcmp(res->ip_version, "ipv6") == 0)
13920 		mplsoudp_encap_conf.select_ipv4 = 0;
13921 	else
13922 		return;
13923 	rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13924 	mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13925 	mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13926 	if (mplsoudp_encap_conf.select_ipv4) {
13927 		IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13928 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13929 	} else {
13930 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13931 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13932 	}
13933 	if (mplsoudp_encap_conf.select_vlan)
13934 		mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13935 	rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13936 		   RTE_ETHER_ADDR_LEN);
13937 	rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13938 		   RTE_ETHER_ADDR_LEN);
13939 }
13940 
13941 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13942 	.f = cmd_set_mplsoudp_encap_parsed,
13943 	.data = NULL,
13944 	.help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13945 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13946 		" ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13947 	.tokens = {
13948 		(void *)&cmd_set_mplsoudp_encap_set,
13949 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13950 		(void *)&cmd_set_mplsoudp_encap_ip_version,
13951 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
13952 		(void *)&cmd_set_mplsoudp_encap_label,
13953 		(void *)&cmd_set_mplsoudp_encap_label_value,
13954 		(void *)&cmd_set_mplsoudp_encap_udp_src,
13955 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
13956 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
13957 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13958 		(void *)&cmd_set_mplsoudp_encap_ip_src,
13959 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
13960 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
13961 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13962 		(void *)&cmd_set_mplsoudp_encap_eth_src,
13963 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
13964 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
13965 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13966 		NULL,
13967 	},
13968 };
13969 
13970 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13971 	.f = cmd_set_mplsoudp_encap_parsed,
13972 	.data = NULL,
13973 	.help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13974 		" label <label> udp-src <udp-src> udp-dst <udp-dst>"
13975 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13976 		" eth-src <eth-src> eth-dst <eth-dst>",
13977 	.tokens = {
13978 		(void *)&cmd_set_mplsoudp_encap_set,
13979 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13980 		(void *)&cmd_set_mplsoudp_encap_ip_version,
13981 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
13982 		(void *)&cmd_set_mplsoudp_encap_label,
13983 		(void *)&cmd_set_mplsoudp_encap_label_value,
13984 		(void *)&cmd_set_mplsoudp_encap_udp_src,
13985 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
13986 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
13987 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13988 		(void *)&cmd_set_mplsoudp_encap_ip_src,
13989 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
13990 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
13991 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13992 		(void *)&cmd_set_mplsoudp_encap_vlan,
13993 		(void *)&cmd_set_mplsoudp_encap_vlan_value,
13994 		(void *)&cmd_set_mplsoudp_encap_eth_src,
13995 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
13996 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
13997 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13998 		NULL,
13999 	},
14000 };
14001 
14002 /** Set MPLSoUDP decapsulation details */
14003 struct cmd_set_mplsoudp_decap_result {
14004 	cmdline_fixed_string_t set;
14005 	cmdline_fixed_string_t mplsoudp;
14006 	cmdline_fixed_string_t pos_token;
14007 	cmdline_fixed_string_t ip_version;
14008 	uint32_t vlan_present:1;
14009 };
14010 
14011 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
14012 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
14013 				 "set");
14014 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
14015 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
14016 				 "mplsoudp_decap");
14017 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
14018 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14019 				 mplsoudp, "mplsoudp_decap-with-vlan");
14020 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
14021 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14022 				 pos_token, "ip-version");
14023 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
14024 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14025 				 ip_version, "ipv4#ipv6");
14026 
14027 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
14028 	__rte_unused struct cmdline *cl,
14029 	__rte_unused void *data)
14030 {
14031 	struct cmd_set_mplsoudp_decap_result *res = parsed_result;
14032 
14033 	if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
14034 		mplsoudp_decap_conf.select_vlan = 0;
14035 	else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
14036 		mplsoudp_decap_conf.select_vlan = 1;
14037 	if (strcmp(res->ip_version, "ipv4") == 0)
14038 		mplsoudp_decap_conf.select_ipv4 = 1;
14039 	else if (strcmp(res->ip_version, "ipv6") == 0)
14040 		mplsoudp_decap_conf.select_ipv4 = 0;
14041 }
14042 
14043 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
14044 	.f = cmd_set_mplsoudp_decap_parsed,
14045 	.data = NULL,
14046 	.help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
14047 	.tokens = {
14048 		(void *)&cmd_set_mplsoudp_decap_set,
14049 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
14050 		(void *)&cmd_set_mplsoudp_decap_ip_version,
14051 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
14052 		NULL,
14053 	},
14054 };
14055 
14056 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
14057 	.f = cmd_set_mplsoudp_decap_parsed,
14058 	.data = NULL,
14059 	.help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
14060 	.tokens = {
14061 		(void *)&cmd_set_mplsoudp_decap_set,
14062 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
14063 		(void *)&cmd_set_mplsoudp_decap_ip_version,
14064 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
14065 		NULL,
14066 	},
14067 };
14068 
14069 /** Set connection tracking object common details */
14070 struct cmd_set_conntrack_common_result {
14071 	cmdline_fixed_string_t set;
14072 	cmdline_fixed_string_t conntrack;
14073 	cmdline_fixed_string_t common;
14074 	cmdline_fixed_string_t peer;
14075 	cmdline_fixed_string_t is_orig;
14076 	cmdline_fixed_string_t enable;
14077 	cmdline_fixed_string_t live;
14078 	cmdline_fixed_string_t sack;
14079 	cmdline_fixed_string_t cack;
14080 	cmdline_fixed_string_t last_dir;
14081 	cmdline_fixed_string_t liberal;
14082 	cmdline_fixed_string_t state;
14083 	cmdline_fixed_string_t max_ack_win;
14084 	cmdline_fixed_string_t retrans;
14085 	cmdline_fixed_string_t last_win;
14086 	cmdline_fixed_string_t last_seq;
14087 	cmdline_fixed_string_t last_ack;
14088 	cmdline_fixed_string_t last_end;
14089 	cmdline_fixed_string_t last_index;
14090 	uint8_t stat;
14091 	uint8_t factor;
14092 	uint16_t peer_port;
14093 	uint32_t is_original;
14094 	uint32_t en;
14095 	uint32_t is_live;
14096 	uint32_t s_ack;
14097 	uint32_t c_ack;
14098 	uint32_t ld;
14099 	uint32_t lb;
14100 	uint8_t re_num;
14101 	uint8_t li;
14102 	uint16_t lw;
14103 	uint32_t ls;
14104 	uint32_t la;
14105 	uint32_t le;
14106 };
14107 
14108 cmdline_parse_token_string_t cmd_set_conntrack_set =
14109 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14110 				 set, "set");
14111 cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
14112 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14113 				 conntrack, "conntrack");
14114 cmdline_parse_token_string_t cmd_set_conntrack_common_com =
14115 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14116 				 common, "com");
14117 cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
14118 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14119 				 peer, "peer");
14120 cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
14121 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14122 			      peer_port, RTE_UINT16);
14123 cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
14124 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14125 				 is_orig, "is_orig");
14126 cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
14127 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14128 			      is_original, RTE_UINT32);
14129 cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
14130 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14131 				 enable, "enable");
14132 cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
14133 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14134 			      en, RTE_UINT32);
14135 cmdline_parse_token_string_t cmd_set_conntrack_common_live =
14136 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14137 				 live, "live");
14138 cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
14139 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14140 			      is_live, RTE_UINT32);
14141 cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
14142 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14143 				 sack, "sack");
14144 cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
14145 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14146 			      s_ack, RTE_UINT32);
14147 cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
14148 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14149 				 cack, "cack");
14150 cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
14151 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14152 			      c_ack, RTE_UINT32);
14153 cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
14154 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14155 				 last_dir, "last_dir");
14156 cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
14157 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14158 			      ld, RTE_UINT32);
14159 cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
14160 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14161 				 liberal, "liberal");
14162 cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
14163 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14164 			      lb, RTE_UINT32);
14165 cmdline_parse_token_string_t cmd_set_conntrack_common_state =
14166 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14167 				 state, "state");
14168 cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
14169 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14170 			      stat, RTE_UINT8);
14171 cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
14172 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14173 				 max_ack_win, "max_ack_win");
14174 cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
14175 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14176 			      factor, RTE_UINT8);
14177 cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
14178 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14179 				 retrans, "r_lim");
14180 cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
14181 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14182 			      re_num, RTE_UINT8);
14183 cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
14184 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14185 				 last_win, "last_win");
14186 cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
14187 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14188 			      lw, RTE_UINT16);
14189 cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
14190 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14191 				 last_seq, "last_seq");
14192 cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
14193 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14194 			      ls, RTE_UINT32);
14195 cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
14196 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14197 				 last_ack, "last_ack");
14198 cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
14199 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14200 			      la, RTE_UINT32);
14201 cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
14202 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14203 				 last_end, "last_end");
14204 cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
14205 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14206 			      le, RTE_UINT32);
14207 cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
14208 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14209 				 last_index, "last_index");
14210 cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
14211 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14212 			      li, RTE_UINT8);
14213 
14214 static void cmd_set_conntrack_common_parsed(void *parsed_result,
14215 	__rte_unused struct cmdline *cl,
14216 	__rte_unused void *data)
14217 {
14218 	struct cmd_set_conntrack_common_result *res = parsed_result;
14219 
14220 	/* No need to swap to big endian. */
14221 	conntrack_context.peer_port = res->peer_port;
14222 	conntrack_context.is_original_dir = res->is_original;
14223 	conntrack_context.enable = res->en;
14224 	conntrack_context.live_connection = res->is_live;
14225 	conntrack_context.selective_ack = res->s_ack;
14226 	conntrack_context.challenge_ack_passed = res->c_ack;
14227 	conntrack_context.last_direction = res->ld;
14228 	conntrack_context.liberal_mode = res->lb;
14229 	conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
14230 	conntrack_context.max_ack_window = res->factor;
14231 	conntrack_context.retransmission_limit = res->re_num;
14232 	conntrack_context.last_window = res->lw;
14233 	conntrack_context.last_index =
14234 		(enum rte_flow_conntrack_tcp_last_index)res->li;
14235 	conntrack_context.last_seq = res->ls;
14236 	conntrack_context.last_ack = res->la;
14237 	conntrack_context.last_end = res->le;
14238 }
14239 
14240 cmdline_parse_inst_t cmd_set_conntrack_common = {
14241 	.f = cmd_set_conntrack_common_parsed,
14242 	.data = NULL,
14243 	.help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
14244 		" live <ack_seen> sack <en> cack <passed> last_dir <dir>"
14245 		" liberal <en> state <s> max_ack_win <factor> r_lim <num>"
14246 		" last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
14247 		" last_index <flag>",
14248 	.tokens = {
14249 		(void *)&cmd_set_conntrack_set,
14250 		(void *)&cmd_set_conntrack_conntrack,
14251 		(void *)&cmd_set_conntrack_common_com,
14252 		(void *)&cmd_set_conntrack_common_peer,
14253 		(void *)&cmd_set_conntrack_common_peer_value,
14254 		(void *)&cmd_set_conntrack_common_is_orig,
14255 		(void *)&cmd_set_conntrack_common_is_orig_value,
14256 		(void *)&cmd_set_conntrack_common_enable,
14257 		(void *)&cmd_set_conntrack_common_enable_value,
14258 		(void *)&cmd_set_conntrack_common_live,
14259 		(void *)&cmd_set_conntrack_common_live_value,
14260 		(void *)&cmd_set_conntrack_common_sack,
14261 		(void *)&cmd_set_conntrack_common_sack_value,
14262 		(void *)&cmd_set_conntrack_common_cack,
14263 		(void *)&cmd_set_conntrack_common_cack_value,
14264 		(void *)&cmd_set_conntrack_common_last_dir,
14265 		(void *)&cmd_set_conntrack_common_last_dir_value,
14266 		(void *)&cmd_set_conntrack_common_liberal,
14267 		(void *)&cmd_set_conntrack_common_liberal_value,
14268 		(void *)&cmd_set_conntrack_common_state,
14269 		(void *)&cmd_set_conntrack_common_state_value,
14270 		(void *)&cmd_set_conntrack_common_max_ackwin,
14271 		(void *)&cmd_set_conntrack_common_max_ackwin_value,
14272 		(void *)&cmd_set_conntrack_common_retrans,
14273 		(void *)&cmd_set_conntrack_common_retrans_value,
14274 		(void *)&cmd_set_conntrack_common_last_win,
14275 		(void *)&cmd_set_conntrack_common_last_win_value,
14276 		(void *)&cmd_set_conntrack_common_last_seq,
14277 		(void *)&cmd_set_conntrack_common_last_seq_value,
14278 		(void *)&cmd_set_conntrack_common_last_ack,
14279 		(void *)&cmd_set_conntrack_common_last_ack_value,
14280 		(void *)&cmd_set_conntrack_common_last_end,
14281 		(void *)&cmd_set_conntrack_common_last_end_value,
14282 		(void *)&cmd_set_conntrack_common_last_index,
14283 		(void *)&cmd_set_conntrack_common_last_index_value,
14284 		NULL,
14285 	},
14286 };
14287 
14288 /** Set connection tracking object both directions' details */
14289 struct cmd_set_conntrack_dir_result {
14290 	cmdline_fixed_string_t set;
14291 	cmdline_fixed_string_t conntrack;
14292 	cmdline_fixed_string_t dir;
14293 	cmdline_fixed_string_t scale;
14294 	cmdline_fixed_string_t fin;
14295 	cmdline_fixed_string_t ack_seen;
14296 	cmdline_fixed_string_t unack;
14297 	cmdline_fixed_string_t sent_end;
14298 	cmdline_fixed_string_t reply_end;
14299 	cmdline_fixed_string_t max_win;
14300 	cmdline_fixed_string_t max_ack;
14301 	uint32_t factor;
14302 	uint32_t f;
14303 	uint32_t as;
14304 	uint32_t un;
14305 	uint32_t se;
14306 	uint32_t re;
14307 	uint32_t mw;
14308 	uint32_t ma;
14309 };
14310 
14311 cmdline_parse_token_string_t cmd_set_conntrack_dir_set =
14312 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14313 				 set, "set");
14314 cmdline_parse_token_string_t cmd_set_conntrack_dir_conntrack =
14315 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14316 				 conntrack, "conntrack");
14317 cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
14318 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14319 				 dir, "orig#rply");
14320 cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
14321 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14322 				 scale, "scale");
14323 cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
14324 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14325 			      factor, RTE_UINT32);
14326 cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
14327 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14328 				 fin, "fin");
14329 cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
14330 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14331 			      f, RTE_UINT32);
14332 cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
14333 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14334 				 ack_seen, "acked");
14335 cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
14336 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14337 			      as, RTE_UINT32);
14338 cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
14339 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14340 				 unack, "unack_data");
14341 cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
14342 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14343 			      un, RTE_UINT32);
14344 cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
14345 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14346 				 sent_end, "sent_end");
14347 cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
14348 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14349 			      se, RTE_UINT32);
14350 cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
14351 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14352 				 reply_end, "reply_end");
14353 cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
14354 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14355 			      re, RTE_UINT32);
14356 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
14357 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14358 				 max_win, "max_win");
14359 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
14360 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14361 			      mw, RTE_UINT32);
14362 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
14363 	TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14364 				 max_ack, "max_ack");
14365 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
14366 	TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14367 			      ma, RTE_UINT32);
14368 
14369 static void cmd_set_conntrack_dir_parsed(void *parsed_result,
14370 	__rte_unused struct cmdline *cl,
14371 	__rte_unused void *data)
14372 {
14373 	struct cmd_set_conntrack_dir_result *res = parsed_result;
14374 	struct rte_flow_tcp_dir_param *dir = NULL;
14375 
14376 	if (strcmp(res->dir, "orig") == 0)
14377 		dir = &conntrack_context.original_dir;
14378 	else if (strcmp(res->dir, "rply") == 0)
14379 		dir = &conntrack_context.reply_dir;
14380 	else
14381 		return;
14382 	dir->scale = res->factor;
14383 	dir->close_initiated = res->f;
14384 	dir->last_ack_seen = res->as;
14385 	dir->data_unacked = res->un;
14386 	dir->sent_end = res->se;
14387 	dir->reply_end = res->re;
14388 	dir->max_ack = res->ma;
14389 	dir->max_win = res->mw;
14390 }
14391 
14392 cmdline_parse_inst_t cmd_set_conntrack_dir = {
14393 	.f = cmd_set_conntrack_dir_parsed,
14394 	.data = NULL,
14395 	.help_str = "set conntrack orig|rply scale <factor> fin <sent>"
14396 		    " acked <seen> unack_data <unack> sent_end <sent>"
14397 		    " reply_end <reply> max_win <win> max_ack <ack>",
14398 	.tokens = {
14399 		(void *)&cmd_set_conntrack_set,
14400 		(void *)&cmd_set_conntrack_conntrack,
14401 		(void *)&cmd_set_conntrack_dir_dir,
14402 		(void *)&cmd_set_conntrack_dir_scale,
14403 		(void *)&cmd_set_conntrack_dir_scale_value,
14404 		(void *)&cmd_set_conntrack_dir_fin,
14405 		(void *)&cmd_set_conntrack_dir_fin_value,
14406 		(void *)&cmd_set_conntrack_dir_ack,
14407 		(void *)&cmd_set_conntrack_dir_ack_value,
14408 		(void *)&cmd_set_conntrack_dir_unack_data,
14409 		(void *)&cmd_set_conntrack_dir_unack_data_value,
14410 		(void *)&cmd_set_conntrack_dir_sent_end,
14411 		(void *)&cmd_set_conntrack_dir_sent_end_value,
14412 		(void *)&cmd_set_conntrack_dir_reply_end,
14413 		(void *)&cmd_set_conntrack_dir_reply_end_value,
14414 		(void *)&cmd_set_conntrack_dir_max_win,
14415 		(void *)&cmd_set_conntrack_dir_max_win_value,
14416 		(void *)&cmd_set_conntrack_dir_max_ack,
14417 		(void *)&cmd_set_conntrack_dir_max_ack_value,
14418 		NULL,
14419 	},
14420 };
14421 
14422 /* Strict link priority scheduling mode setting */
14423 static void
14424 cmd_strict_link_prio_parsed(
14425 	void *parsed_result,
14426 	__rte_unused struct cmdline *cl,
14427 	__rte_unused void *data)
14428 {
14429 	struct cmd_vf_tc_bw_result *res = parsed_result;
14430 	int ret = -ENOTSUP;
14431 
14432 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14433 		return;
14434 
14435 #ifdef RTE_NET_I40E
14436 	ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14437 #endif
14438 
14439 	switch (ret) {
14440 	case 0:
14441 		break;
14442 	case -EINVAL:
14443 		fprintf(stderr, "invalid tc_bitmap 0x%x\n", res->tc_map);
14444 		break;
14445 	case -ENODEV:
14446 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
14447 		break;
14448 	case -ENOTSUP:
14449 		fprintf(stderr, "function not implemented\n");
14450 		break;
14451 	default:
14452 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
14453 	}
14454 }
14455 
14456 cmdline_parse_inst_t cmd_strict_link_prio = {
14457 	.f = cmd_strict_link_prio_parsed,
14458 	.data = NULL,
14459 	.help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14460 	.tokens = {
14461 		(void *)&cmd_vf_tc_bw_set,
14462 		(void *)&cmd_vf_tc_bw_tx,
14463 		(void *)&cmd_vf_tc_bw_strict_link_prio,
14464 		(void *)&cmd_vf_tc_bw_port_id,
14465 		(void *)&cmd_vf_tc_bw_tc_map,
14466 		NULL,
14467 	},
14468 };
14469 
14470 /* Load dynamic device personalization*/
14471 struct cmd_ddp_add_result {
14472 	cmdline_fixed_string_t ddp;
14473 	cmdline_fixed_string_t add;
14474 	portid_t port_id;
14475 	char filepath[];
14476 };
14477 
14478 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14479 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14480 cmdline_parse_token_string_t cmd_ddp_add_add =
14481 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14482 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14483 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
14484 		RTE_UINT16);
14485 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14486 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14487 
14488 static void
14489 cmd_ddp_add_parsed(
14490 	void *parsed_result,
14491 	__rte_unused struct cmdline *cl,
14492 	__rte_unused void *data)
14493 {
14494 	struct cmd_ddp_add_result *res = parsed_result;
14495 	uint8_t *buff;
14496 	uint32_t size;
14497 	char *filepath;
14498 	char *file_fld[2];
14499 	int file_num;
14500 	int ret = -ENOTSUP;
14501 
14502 	if (!all_ports_stopped()) {
14503 		fprintf(stderr, "Please stop all ports first\n");
14504 		return;
14505 	}
14506 
14507 	filepath = strdup(res->filepath);
14508 	if (filepath == NULL) {
14509 		fprintf(stderr, "Failed to allocate memory\n");
14510 		return;
14511 	}
14512 	file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14513 
14514 	buff = open_file(file_fld[0], &size);
14515 	if (!buff) {
14516 		free((void *)filepath);
14517 		return;
14518 	}
14519 
14520 #ifdef RTE_NET_I40E
14521 	if (ret == -ENOTSUP)
14522 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14523 					       buff, size,
14524 					       RTE_PMD_I40E_PKG_OP_WR_ADD);
14525 #endif
14526 
14527 	if (ret == -EEXIST)
14528 		fprintf(stderr, "Profile has already existed.\n");
14529 	else if (ret < 0)
14530 		fprintf(stderr, "Failed to load profile.\n");
14531 	else if (file_num == 2)
14532 		save_file(file_fld[1], buff, size);
14533 
14534 	close_file(buff);
14535 	free((void *)filepath);
14536 }
14537 
14538 cmdline_parse_inst_t cmd_ddp_add = {
14539 	.f = cmd_ddp_add_parsed,
14540 	.data = NULL,
14541 	.help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14542 	.tokens = {
14543 		(void *)&cmd_ddp_add_ddp,
14544 		(void *)&cmd_ddp_add_add,
14545 		(void *)&cmd_ddp_add_port_id,
14546 		(void *)&cmd_ddp_add_filepath,
14547 		NULL,
14548 	},
14549 };
14550 
14551 /* Delete dynamic device personalization*/
14552 struct cmd_ddp_del_result {
14553 	cmdline_fixed_string_t ddp;
14554 	cmdline_fixed_string_t del;
14555 	portid_t port_id;
14556 	char filepath[];
14557 };
14558 
14559 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14560 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14561 cmdline_parse_token_string_t cmd_ddp_del_del =
14562 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14563 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14564 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
14565 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14566 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14567 
14568 static void
14569 cmd_ddp_del_parsed(
14570 	void *parsed_result,
14571 	__rte_unused struct cmdline *cl,
14572 	__rte_unused void *data)
14573 {
14574 	struct cmd_ddp_del_result *res = parsed_result;
14575 	uint8_t *buff;
14576 	uint32_t size;
14577 	int ret = -ENOTSUP;
14578 
14579 	if (!all_ports_stopped()) {
14580 		fprintf(stderr, "Please stop all ports first\n");
14581 		return;
14582 	}
14583 
14584 	buff = open_file(res->filepath, &size);
14585 	if (!buff)
14586 		return;
14587 
14588 #ifdef RTE_NET_I40E
14589 	if (ret == -ENOTSUP)
14590 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14591 					       buff, size,
14592 					       RTE_PMD_I40E_PKG_OP_WR_DEL);
14593 #endif
14594 
14595 	if (ret == -EACCES)
14596 		fprintf(stderr, "Profile does not exist.\n");
14597 	else if (ret < 0)
14598 		fprintf(stderr, "Failed to delete profile.\n");
14599 
14600 	close_file(buff);
14601 }
14602 
14603 cmdline_parse_inst_t cmd_ddp_del = {
14604 	.f = cmd_ddp_del_parsed,
14605 	.data = NULL,
14606 	.help_str = "ddp del <port_id> <backup_profile_path>",
14607 	.tokens = {
14608 		(void *)&cmd_ddp_del_ddp,
14609 		(void *)&cmd_ddp_del_del,
14610 		(void *)&cmd_ddp_del_port_id,
14611 		(void *)&cmd_ddp_del_filepath,
14612 		NULL,
14613 	},
14614 };
14615 
14616 /* Get dynamic device personalization profile info */
14617 struct cmd_ddp_info_result {
14618 	cmdline_fixed_string_t ddp;
14619 	cmdline_fixed_string_t get;
14620 	cmdline_fixed_string_t info;
14621 	char filepath[];
14622 };
14623 
14624 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14625 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14626 cmdline_parse_token_string_t cmd_ddp_info_get =
14627 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14628 cmdline_parse_token_string_t cmd_ddp_info_info =
14629 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14630 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14631 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14632 
14633 static void
14634 cmd_ddp_info_parsed(
14635 	void *parsed_result,
14636 	__rte_unused struct cmdline *cl,
14637 	__rte_unused void *data)
14638 {
14639 	struct cmd_ddp_info_result *res = parsed_result;
14640 	uint8_t *pkg;
14641 	uint32_t pkg_size;
14642 	int ret = -ENOTSUP;
14643 #ifdef RTE_NET_I40E
14644 	uint32_t i, j, n;
14645 	uint8_t *buff;
14646 	uint32_t buff_size = 0;
14647 	struct rte_pmd_i40e_profile_info info;
14648 	uint32_t dev_num = 0;
14649 	struct rte_pmd_i40e_ddp_device_id *devs;
14650 	uint32_t proto_num = 0;
14651 	struct rte_pmd_i40e_proto_info *proto = NULL;
14652 	uint32_t pctype_num = 0;
14653 	struct rte_pmd_i40e_ptype_info *pctype;
14654 	uint32_t ptype_num = 0;
14655 	struct rte_pmd_i40e_ptype_info *ptype;
14656 	uint8_t proto_id;
14657 
14658 #endif
14659 
14660 	pkg = open_file(res->filepath, &pkg_size);
14661 	if (!pkg)
14662 		return;
14663 
14664 #ifdef RTE_NET_I40E
14665 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14666 				(uint8_t *)&info, sizeof(info),
14667 				RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14668 	if (!ret) {
14669 		printf("Global Track id:       0x%x\n", info.track_id);
14670 		printf("Global Version:        %d.%d.%d.%d\n",
14671 			info.version.major,
14672 			info.version.minor,
14673 			info.version.update,
14674 			info.version.draft);
14675 		printf("Global Package name:   %s\n\n", info.name);
14676 	}
14677 
14678 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14679 				(uint8_t *)&info, sizeof(info),
14680 				RTE_PMD_I40E_PKG_INFO_HEADER);
14681 	if (!ret) {
14682 		printf("i40e Profile Track id: 0x%x\n", info.track_id);
14683 		printf("i40e Profile Version:  %d.%d.%d.%d\n",
14684 			info.version.major,
14685 			info.version.minor,
14686 			info.version.update,
14687 			info.version.draft);
14688 		printf("i40e Profile name:     %s\n\n", info.name);
14689 	}
14690 
14691 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14692 				(uint8_t *)&buff_size, sizeof(buff_size),
14693 				RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14694 	if (!ret && buff_size) {
14695 		buff = (uint8_t *)malloc(buff_size);
14696 		if (buff) {
14697 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14698 						buff, buff_size,
14699 						RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14700 			if (!ret)
14701 				printf("Package Notes:\n%s\n\n", buff);
14702 			free(buff);
14703 		}
14704 	}
14705 
14706 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14707 				(uint8_t *)&dev_num, sizeof(dev_num),
14708 				RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14709 	if (!ret && dev_num) {
14710 		buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14711 		devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14712 		if (devs) {
14713 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14714 						(uint8_t *)devs, buff_size,
14715 						RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14716 			if (!ret) {
14717 				printf("List of supported devices:\n");
14718 				for (i = 0; i < dev_num; i++) {
14719 					printf("  %04X:%04X %04X:%04X\n",
14720 						devs[i].vendor_dev_id >> 16,
14721 						devs[i].vendor_dev_id & 0xFFFF,
14722 						devs[i].sub_vendor_dev_id >> 16,
14723 						devs[i].sub_vendor_dev_id & 0xFFFF);
14724 				}
14725 				printf("\n");
14726 			}
14727 			free(devs);
14728 		}
14729 	}
14730 
14731 	/* get information about protocols and packet types */
14732 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14733 		(uint8_t *)&proto_num, sizeof(proto_num),
14734 		RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14735 	if (ret || !proto_num)
14736 		goto no_print_return;
14737 
14738 	buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14739 	proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14740 	if (!proto)
14741 		goto no_print_return;
14742 
14743 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14744 					buff_size,
14745 					RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14746 	if (!ret) {
14747 		printf("List of used protocols:\n");
14748 		for (i = 0; i < proto_num; i++)
14749 			printf("  %2u: %s\n", proto[i].proto_id,
14750 			       proto[i].name);
14751 		printf("\n");
14752 	}
14753 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14754 		(uint8_t *)&pctype_num, sizeof(pctype_num),
14755 		RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14756 	if (ret || !pctype_num)
14757 		goto no_print_pctypes;
14758 
14759 	buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14760 	pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14761 	if (!pctype)
14762 		goto no_print_pctypes;
14763 
14764 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14765 					buff_size,
14766 					RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14767 	if (ret) {
14768 		free(pctype);
14769 		goto no_print_pctypes;
14770 	}
14771 
14772 	printf("List of defined packet classification types:\n");
14773 	for (i = 0; i < pctype_num; i++) {
14774 		printf("  %2u:", pctype[i].ptype_id);
14775 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14776 			proto_id = pctype[i].protocols[j];
14777 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14778 				for (n = 0; n < proto_num; n++) {
14779 					if (proto[n].proto_id == proto_id) {
14780 						printf(" %s", proto[n].name);
14781 						break;
14782 					}
14783 				}
14784 			}
14785 		}
14786 		printf("\n");
14787 	}
14788 	printf("\n");
14789 	free(pctype);
14790 
14791 no_print_pctypes:
14792 
14793 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14794 					sizeof(ptype_num),
14795 					RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14796 	if (ret || !ptype_num)
14797 		goto no_print_return;
14798 
14799 	buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14800 	ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14801 	if (!ptype)
14802 		goto no_print_return;
14803 
14804 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14805 					buff_size,
14806 					RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14807 	if (ret) {
14808 		free(ptype);
14809 		goto no_print_return;
14810 	}
14811 	printf("List of defined packet types:\n");
14812 	for (i = 0; i < ptype_num; i++) {
14813 		printf("  %2u:", ptype[i].ptype_id);
14814 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14815 			proto_id = ptype[i].protocols[j];
14816 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14817 				for (n = 0; n < proto_num; n++) {
14818 					if (proto[n].proto_id == proto_id) {
14819 						printf(" %s", proto[n].name);
14820 						break;
14821 					}
14822 				}
14823 			}
14824 		}
14825 		printf("\n");
14826 	}
14827 	free(ptype);
14828 	printf("\n");
14829 
14830 	ret = 0;
14831 no_print_return:
14832 	free(proto);
14833 #endif
14834 	if (ret == -ENOTSUP)
14835 		fprintf(stderr, "Function not supported in PMD\n");
14836 	close_file(pkg);
14837 }
14838 
14839 cmdline_parse_inst_t cmd_ddp_get_info = {
14840 	.f = cmd_ddp_info_parsed,
14841 	.data = NULL,
14842 	.help_str = "ddp get info <profile_path>",
14843 	.tokens = {
14844 		(void *)&cmd_ddp_info_ddp,
14845 		(void *)&cmd_ddp_info_get,
14846 		(void *)&cmd_ddp_info_info,
14847 		(void *)&cmd_ddp_info_filepath,
14848 		NULL,
14849 	},
14850 };
14851 
14852 /* Get dynamic device personalization profile info list*/
14853 #define PROFILE_INFO_SIZE 48
14854 #define MAX_PROFILE_NUM 16
14855 
14856 struct cmd_ddp_get_list_result {
14857 	cmdline_fixed_string_t ddp;
14858 	cmdline_fixed_string_t get;
14859 	cmdline_fixed_string_t list;
14860 	portid_t port_id;
14861 };
14862 
14863 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14864 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14865 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14866 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14867 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14868 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14869 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14870 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14871 		RTE_UINT16);
14872 
14873 static void
14874 cmd_ddp_get_list_parsed(
14875 	__rte_unused void *parsed_result,
14876 	__rte_unused struct cmdline *cl,
14877 	__rte_unused void *data)
14878 {
14879 #ifdef RTE_NET_I40E
14880 	struct cmd_ddp_get_list_result *res = parsed_result;
14881 	struct rte_pmd_i40e_profile_list *p_list;
14882 	struct rte_pmd_i40e_profile_info *p_info;
14883 	uint32_t p_num;
14884 	uint32_t size;
14885 	uint32_t i;
14886 #endif
14887 	int ret = -ENOTSUP;
14888 
14889 #ifdef RTE_NET_I40E
14890 	size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14891 	p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14892 	if (!p_list) {
14893 		fprintf(stderr, "%s: Failed to malloc buffer\n", __func__);
14894 		return;
14895 	}
14896 
14897 	if (ret == -ENOTSUP)
14898 		ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14899 						(uint8_t *)p_list, size);
14900 
14901 	if (!ret) {
14902 		p_num = p_list->p_count;
14903 		printf("Profile number is: %d\n\n", p_num);
14904 
14905 		for (i = 0; i < p_num; i++) {
14906 			p_info = &p_list->p_info[i];
14907 			printf("Profile %d:\n", i);
14908 			printf("Track id:     0x%x\n", p_info->track_id);
14909 			printf("Version:      %d.%d.%d.%d\n",
14910 			       p_info->version.major,
14911 			       p_info->version.minor,
14912 			       p_info->version.update,
14913 			       p_info->version.draft);
14914 			printf("Profile name: %s\n\n", p_info->name);
14915 		}
14916 	}
14917 
14918 	free(p_list);
14919 #endif
14920 
14921 	if (ret < 0)
14922 		fprintf(stderr, "Failed to get ddp list\n");
14923 }
14924 
14925 cmdline_parse_inst_t cmd_ddp_get_list = {
14926 	.f = cmd_ddp_get_list_parsed,
14927 	.data = NULL,
14928 	.help_str = "ddp get list <port_id>",
14929 	.tokens = {
14930 		(void *)&cmd_ddp_get_list_ddp,
14931 		(void *)&cmd_ddp_get_list_get,
14932 		(void *)&cmd_ddp_get_list_list,
14933 		(void *)&cmd_ddp_get_list_port_id,
14934 		NULL,
14935 	},
14936 };
14937 
14938 /* Configure input set */
14939 struct cmd_cfg_input_set_result {
14940 	cmdline_fixed_string_t port;
14941 	cmdline_fixed_string_t cfg;
14942 	portid_t port_id;
14943 	cmdline_fixed_string_t pctype;
14944 	uint8_t pctype_id;
14945 	cmdline_fixed_string_t inset_type;
14946 	cmdline_fixed_string_t opt;
14947 	cmdline_fixed_string_t field;
14948 	uint8_t field_idx;
14949 };
14950 
14951 static void
14952 cmd_cfg_input_set_parsed(
14953 	__rte_unused void *parsed_result,
14954 	__rte_unused struct cmdline *cl,
14955 	__rte_unused void *data)
14956 {
14957 #ifdef RTE_NET_I40E
14958 	struct cmd_cfg_input_set_result *res = parsed_result;
14959 	enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14960 	struct rte_pmd_i40e_inset inset;
14961 #endif
14962 	int ret = -ENOTSUP;
14963 
14964 	if (!all_ports_stopped()) {
14965 		fprintf(stderr, "Please stop all ports first\n");
14966 		return;
14967 	}
14968 
14969 #ifdef RTE_NET_I40E
14970 	if (!strcmp(res->inset_type, "hash_inset"))
14971 		inset_type = INSET_HASH;
14972 	else if (!strcmp(res->inset_type, "fdir_inset"))
14973 		inset_type = INSET_FDIR;
14974 	else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14975 		inset_type = INSET_FDIR_FLX;
14976 	ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14977 				     &inset, inset_type);
14978 	if (ret) {
14979 		fprintf(stderr, "Failed to get input set.\n");
14980 		return;
14981 	}
14982 
14983 	if (!strcmp(res->opt, "get")) {
14984 		ret = rte_pmd_i40e_inset_field_get(inset.inset,
14985 						   res->field_idx);
14986 		if (ret)
14987 			printf("Field index %d is enabled.\n", res->field_idx);
14988 		else
14989 			printf("Field index %d is disabled.\n", res->field_idx);
14990 		return;
14991 	} else if (!strcmp(res->opt, "set"))
14992 		ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14993 						   res->field_idx);
14994 	else if (!strcmp(res->opt, "clear"))
14995 		ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14996 						     res->field_idx);
14997 	if (ret) {
14998 		fprintf(stderr, "Failed to configure input set field.\n");
14999 		return;
15000 	}
15001 
15002 	ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15003 				     &inset, inset_type);
15004 	if (ret) {
15005 		fprintf(stderr, "Failed to set input set.\n");
15006 		return;
15007 	}
15008 #endif
15009 
15010 	if (ret == -ENOTSUP)
15011 		fprintf(stderr, "Function not supported\n");
15012 }
15013 
15014 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15015 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15016 				 port, "port");
15017 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15018 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15019 				 cfg, "config");
15020 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15021 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15022 			      port_id, RTE_UINT16);
15023 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15024 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15025 				 pctype, "pctype");
15026 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15027 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15028 			      pctype_id, RTE_UINT8);
15029 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15030 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15031 				 inset_type,
15032 				 "hash_inset#fdir_inset#fdir_flx_inset");
15033 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15034 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15035 				 opt, "get#set#clear");
15036 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15037 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15038 				 field, "field");
15039 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15040 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15041 			      field_idx, RTE_UINT8);
15042 
15043 cmdline_parse_inst_t cmd_cfg_input_set = {
15044 	.f = cmd_cfg_input_set_parsed,
15045 	.data = NULL,
15046 	.help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15047 		    "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15048 	.tokens = {
15049 		(void *)&cmd_cfg_input_set_port,
15050 		(void *)&cmd_cfg_input_set_cfg,
15051 		(void *)&cmd_cfg_input_set_port_id,
15052 		(void *)&cmd_cfg_input_set_pctype,
15053 		(void *)&cmd_cfg_input_set_pctype_id,
15054 		(void *)&cmd_cfg_input_set_inset_type,
15055 		(void *)&cmd_cfg_input_set_opt,
15056 		(void *)&cmd_cfg_input_set_field,
15057 		(void *)&cmd_cfg_input_set_field_idx,
15058 		NULL,
15059 	},
15060 };
15061 
15062 /* Clear input set */
15063 struct cmd_clear_input_set_result {
15064 	cmdline_fixed_string_t port;
15065 	cmdline_fixed_string_t cfg;
15066 	portid_t port_id;
15067 	cmdline_fixed_string_t pctype;
15068 	uint8_t pctype_id;
15069 	cmdline_fixed_string_t inset_type;
15070 	cmdline_fixed_string_t clear;
15071 	cmdline_fixed_string_t all;
15072 };
15073 
15074 static void
15075 cmd_clear_input_set_parsed(
15076 	__rte_unused void *parsed_result,
15077 	__rte_unused struct cmdline *cl,
15078 	__rte_unused void *data)
15079 {
15080 #ifdef RTE_NET_I40E
15081 	struct cmd_clear_input_set_result *res = parsed_result;
15082 	enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15083 	struct rte_pmd_i40e_inset inset;
15084 #endif
15085 	int ret = -ENOTSUP;
15086 
15087 	if (!all_ports_stopped()) {
15088 		fprintf(stderr, "Please stop all ports first\n");
15089 		return;
15090 	}
15091 
15092 #ifdef RTE_NET_I40E
15093 	if (!strcmp(res->inset_type, "hash_inset"))
15094 		inset_type = INSET_HASH;
15095 	else if (!strcmp(res->inset_type, "fdir_inset"))
15096 		inset_type = INSET_FDIR;
15097 	else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15098 		inset_type = INSET_FDIR_FLX;
15099 
15100 	memset(&inset, 0, sizeof(inset));
15101 
15102 	ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15103 				     &inset, inset_type);
15104 	if (ret) {
15105 		fprintf(stderr, "Failed to clear input set.\n");
15106 		return;
15107 	}
15108 
15109 #endif
15110 
15111 	if (ret == -ENOTSUP)
15112 		fprintf(stderr, "Function not supported\n");
15113 }
15114 
15115 cmdline_parse_token_string_t cmd_clear_input_set_port =
15116 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15117 				 port, "port");
15118 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15119 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15120 				 cfg, "config");
15121 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15122 	TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15123 			      port_id, RTE_UINT16);
15124 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15125 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15126 				 pctype, "pctype");
15127 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15128 	TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15129 			      pctype_id, RTE_UINT8);
15130 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15131 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15132 				 inset_type,
15133 				 "hash_inset#fdir_inset#fdir_flx_inset");
15134 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15135 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15136 				 clear, "clear");
15137 cmdline_parse_token_string_t cmd_clear_input_set_all =
15138 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15139 				 all, "all");
15140 
15141 cmdline_parse_inst_t cmd_clear_input_set = {
15142 	.f = cmd_clear_input_set_parsed,
15143 	.data = NULL,
15144 	.help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15145 		    "fdir_inset|fdir_flx_inset clear all",
15146 	.tokens = {
15147 		(void *)&cmd_clear_input_set_port,
15148 		(void *)&cmd_clear_input_set_cfg,
15149 		(void *)&cmd_clear_input_set_port_id,
15150 		(void *)&cmd_clear_input_set_pctype,
15151 		(void *)&cmd_clear_input_set_pctype_id,
15152 		(void *)&cmd_clear_input_set_inset_type,
15153 		(void *)&cmd_clear_input_set_clear,
15154 		(void *)&cmd_clear_input_set_all,
15155 		NULL,
15156 	},
15157 };
15158 
15159 /* show vf stats */
15160 
15161 /* Common result structure for show vf stats */
15162 struct cmd_show_vf_stats_result {
15163 	cmdline_fixed_string_t show;
15164 	cmdline_fixed_string_t vf;
15165 	cmdline_fixed_string_t stats;
15166 	portid_t port_id;
15167 	uint16_t vf_id;
15168 };
15169 
15170 /* Common CLI fields show vf stats*/
15171 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15172 	TOKEN_STRING_INITIALIZER
15173 		(struct cmd_show_vf_stats_result,
15174 		 show, "show");
15175 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15176 	TOKEN_STRING_INITIALIZER
15177 		(struct cmd_show_vf_stats_result,
15178 		 vf, "vf");
15179 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15180 	TOKEN_STRING_INITIALIZER
15181 		(struct cmd_show_vf_stats_result,
15182 		 stats, "stats");
15183 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15184 	TOKEN_NUM_INITIALIZER
15185 		(struct cmd_show_vf_stats_result,
15186 		 port_id, RTE_UINT16);
15187 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15188 	TOKEN_NUM_INITIALIZER
15189 		(struct cmd_show_vf_stats_result,
15190 		 vf_id, RTE_UINT16);
15191 
15192 static void
15193 cmd_show_vf_stats_parsed(
15194 	void *parsed_result,
15195 	__rte_unused struct cmdline *cl,
15196 	__rte_unused void *data)
15197 {
15198 	struct cmd_show_vf_stats_result *res = parsed_result;
15199 	struct rte_eth_stats stats;
15200 	int ret = -ENOTSUP;
15201 	static const char *nic_stats_border = "########################";
15202 
15203 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15204 		return;
15205 
15206 	memset(&stats, 0, sizeof(stats));
15207 
15208 #ifdef RTE_NET_I40E
15209 	if (ret == -ENOTSUP)
15210 		ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15211 						res->vf_id,
15212 						&stats);
15213 #endif
15214 #ifdef RTE_NET_BNXT
15215 	if (ret == -ENOTSUP)
15216 		ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15217 						res->vf_id,
15218 						&stats);
15219 #endif
15220 
15221 	switch (ret) {
15222 	case 0:
15223 		break;
15224 	case -EINVAL:
15225 		fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15226 		break;
15227 	case -ENODEV:
15228 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15229 		break;
15230 	case -ENOTSUP:
15231 		fprintf(stderr, "function not implemented\n");
15232 		break;
15233 	default:
15234 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15235 	}
15236 
15237 	printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15238 		nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15239 
15240 	printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15241 	       "%-"PRIu64"\n",
15242 	       stats.ipackets, stats.imissed, stats.ibytes);
15243 	printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15244 	printf("  RX-nombuf:  %-10"PRIu64"\n",
15245 	       stats.rx_nombuf);
15246 	printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15247 	       "%-"PRIu64"\n",
15248 	       stats.opackets, stats.oerrors, stats.obytes);
15249 
15250 	printf("  %s############################%s\n",
15251 			       nic_stats_border, nic_stats_border);
15252 }
15253 
15254 cmdline_parse_inst_t cmd_show_vf_stats = {
15255 	.f = cmd_show_vf_stats_parsed,
15256 	.data = NULL,
15257 	.help_str = "show vf stats <port_id> <vf_id>",
15258 	.tokens = {
15259 		(void *)&cmd_show_vf_stats_show,
15260 		(void *)&cmd_show_vf_stats_vf,
15261 		(void *)&cmd_show_vf_stats_stats,
15262 		(void *)&cmd_show_vf_stats_port_id,
15263 		(void *)&cmd_show_vf_stats_vf_id,
15264 		NULL,
15265 	},
15266 };
15267 
15268 /* clear vf stats */
15269 
15270 /* Common result structure for clear vf stats */
15271 struct cmd_clear_vf_stats_result {
15272 	cmdline_fixed_string_t clear;
15273 	cmdline_fixed_string_t vf;
15274 	cmdline_fixed_string_t stats;
15275 	portid_t port_id;
15276 	uint16_t vf_id;
15277 };
15278 
15279 /* Common CLI fields clear vf stats*/
15280 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15281 	TOKEN_STRING_INITIALIZER
15282 		(struct cmd_clear_vf_stats_result,
15283 		 clear, "clear");
15284 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15285 	TOKEN_STRING_INITIALIZER
15286 		(struct cmd_clear_vf_stats_result,
15287 		 vf, "vf");
15288 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15289 	TOKEN_STRING_INITIALIZER
15290 		(struct cmd_clear_vf_stats_result,
15291 		 stats, "stats");
15292 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15293 	TOKEN_NUM_INITIALIZER
15294 		(struct cmd_clear_vf_stats_result,
15295 		 port_id, RTE_UINT16);
15296 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15297 	TOKEN_NUM_INITIALIZER
15298 		(struct cmd_clear_vf_stats_result,
15299 		 vf_id, RTE_UINT16);
15300 
15301 static void
15302 cmd_clear_vf_stats_parsed(
15303 	void *parsed_result,
15304 	__rte_unused struct cmdline *cl,
15305 	__rte_unused void *data)
15306 {
15307 	struct cmd_clear_vf_stats_result *res = parsed_result;
15308 	int ret = -ENOTSUP;
15309 
15310 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15311 		return;
15312 
15313 #ifdef RTE_NET_I40E
15314 	if (ret == -ENOTSUP)
15315 		ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15316 						  res->vf_id);
15317 #endif
15318 #ifdef RTE_NET_BNXT
15319 	if (ret == -ENOTSUP)
15320 		ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15321 						  res->vf_id);
15322 #endif
15323 
15324 	switch (ret) {
15325 	case 0:
15326 		break;
15327 	case -EINVAL:
15328 		fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15329 		break;
15330 	case -ENODEV:
15331 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15332 		break;
15333 	case -ENOTSUP:
15334 		fprintf(stderr, "function not implemented\n");
15335 		break;
15336 	default:
15337 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15338 	}
15339 }
15340 
15341 cmdline_parse_inst_t cmd_clear_vf_stats = {
15342 	.f = cmd_clear_vf_stats_parsed,
15343 	.data = NULL,
15344 	.help_str = "clear vf stats <port_id> <vf_id>",
15345 	.tokens = {
15346 		(void *)&cmd_clear_vf_stats_clear,
15347 		(void *)&cmd_clear_vf_stats_vf,
15348 		(void *)&cmd_clear_vf_stats_stats,
15349 		(void *)&cmd_clear_vf_stats_port_id,
15350 		(void *)&cmd_clear_vf_stats_vf_id,
15351 		NULL,
15352 	},
15353 };
15354 
15355 /* port config pctype mapping reset */
15356 
15357 /* Common result structure for port config pctype mapping reset */
15358 struct cmd_pctype_mapping_reset_result {
15359 	cmdline_fixed_string_t port;
15360 	cmdline_fixed_string_t config;
15361 	portid_t port_id;
15362 	cmdline_fixed_string_t pctype;
15363 	cmdline_fixed_string_t mapping;
15364 	cmdline_fixed_string_t reset;
15365 };
15366 
15367 /* Common CLI fields for port config pctype mapping reset*/
15368 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15369 	TOKEN_STRING_INITIALIZER
15370 		(struct cmd_pctype_mapping_reset_result,
15371 		 port, "port");
15372 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15373 	TOKEN_STRING_INITIALIZER
15374 		(struct cmd_pctype_mapping_reset_result,
15375 		 config, "config");
15376 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15377 	TOKEN_NUM_INITIALIZER
15378 		(struct cmd_pctype_mapping_reset_result,
15379 		 port_id, RTE_UINT16);
15380 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15381 	TOKEN_STRING_INITIALIZER
15382 		(struct cmd_pctype_mapping_reset_result,
15383 		 pctype, "pctype");
15384 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15385 	TOKEN_STRING_INITIALIZER
15386 		(struct cmd_pctype_mapping_reset_result,
15387 		 mapping, "mapping");
15388 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15389 	TOKEN_STRING_INITIALIZER
15390 		(struct cmd_pctype_mapping_reset_result,
15391 		 reset, "reset");
15392 
15393 static void
15394 cmd_pctype_mapping_reset_parsed(
15395 	void *parsed_result,
15396 	__rte_unused struct cmdline *cl,
15397 	__rte_unused void *data)
15398 {
15399 	struct cmd_pctype_mapping_reset_result *res = parsed_result;
15400 	int ret = -ENOTSUP;
15401 
15402 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15403 		return;
15404 
15405 #ifdef RTE_NET_I40E
15406 	ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15407 #endif
15408 
15409 	switch (ret) {
15410 	case 0:
15411 		break;
15412 	case -ENODEV:
15413 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15414 		break;
15415 	case -ENOTSUP:
15416 		fprintf(stderr, "function not implemented\n");
15417 		break;
15418 	default:
15419 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15420 	}
15421 }
15422 
15423 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15424 	.f = cmd_pctype_mapping_reset_parsed,
15425 	.data = NULL,
15426 	.help_str = "port config <port_id> pctype mapping reset",
15427 	.tokens = {
15428 		(void *)&cmd_pctype_mapping_reset_port,
15429 		(void *)&cmd_pctype_mapping_reset_config,
15430 		(void *)&cmd_pctype_mapping_reset_port_id,
15431 		(void *)&cmd_pctype_mapping_reset_pctype,
15432 		(void *)&cmd_pctype_mapping_reset_mapping,
15433 		(void *)&cmd_pctype_mapping_reset_reset,
15434 		NULL,
15435 	},
15436 };
15437 
15438 /* show port pctype mapping */
15439 
15440 /* Common result structure for show port pctype mapping */
15441 struct cmd_pctype_mapping_get_result {
15442 	cmdline_fixed_string_t show;
15443 	cmdline_fixed_string_t port;
15444 	portid_t port_id;
15445 	cmdline_fixed_string_t pctype;
15446 	cmdline_fixed_string_t mapping;
15447 };
15448 
15449 /* Common CLI fields for pctype mapping get */
15450 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15451 	TOKEN_STRING_INITIALIZER
15452 		(struct cmd_pctype_mapping_get_result,
15453 		 show, "show");
15454 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15455 	TOKEN_STRING_INITIALIZER
15456 		(struct cmd_pctype_mapping_get_result,
15457 		 port, "port");
15458 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15459 	TOKEN_NUM_INITIALIZER
15460 		(struct cmd_pctype_mapping_get_result,
15461 		 port_id, RTE_UINT16);
15462 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15463 	TOKEN_STRING_INITIALIZER
15464 		(struct cmd_pctype_mapping_get_result,
15465 		 pctype, "pctype");
15466 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15467 	TOKEN_STRING_INITIALIZER
15468 		(struct cmd_pctype_mapping_get_result,
15469 		 mapping, "mapping");
15470 
15471 static void
15472 cmd_pctype_mapping_get_parsed(
15473 	void *parsed_result,
15474 	__rte_unused struct cmdline *cl,
15475 	__rte_unused void *data)
15476 {
15477 	struct cmd_pctype_mapping_get_result *res = parsed_result;
15478 	int ret = -ENOTSUP;
15479 #ifdef RTE_NET_I40E
15480 	struct rte_pmd_i40e_flow_type_mapping
15481 				mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15482 	int i, j, first_pctype;
15483 #endif
15484 
15485 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15486 		return;
15487 
15488 #ifdef RTE_NET_I40E
15489 	ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15490 #endif
15491 
15492 	switch (ret) {
15493 	case 0:
15494 		break;
15495 	case -ENODEV:
15496 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15497 		return;
15498 	case -ENOTSUP:
15499 		fprintf(stderr, "function not implemented\n");
15500 		return;
15501 	default:
15502 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15503 		return;
15504 	}
15505 
15506 #ifdef RTE_NET_I40E
15507 	for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15508 		if (mapping[i].pctype != 0ULL) {
15509 			first_pctype = 1;
15510 
15511 			printf("pctype: ");
15512 			for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15513 				if (mapping[i].pctype & (1ULL << j)) {
15514 					printf(first_pctype ?
15515 					       "%02d" : ",%02d", j);
15516 					first_pctype = 0;
15517 				}
15518 			}
15519 			printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15520 		}
15521 	}
15522 #endif
15523 }
15524 
15525 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15526 	.f = cmd_pctype_mapping_get_parsed,
15527 	.data = NULL,
15528 	.help_str = "show port <port_id> pctype mapping",
15529 	.tokens = {
15530 		(void *)&cmd_pctype_mapping_get_show,
15531 		(void *)&cmd_pctype_mapping_get_port,
15532 		(void *)&cmd_pctype_mapping_get_port_id,
15533 		(void *)&cmd_pctype_mapping_get_pctype,
15534 		(void *)&cmd_pctype_mapping_get_mapping,
15535 		NULL,
15536 	},
15537 };
15538 
15539 /* port config pctype mapping update */
15540 
15541 /* Common result structure for port config pctype mapping update */
15542 struct cmd_pctype_mapping_update_result {
15543 	cmdline_fixed_string_t port;
15544 	cmdline_fixed_string_t config;
15545 	portid_t port_id;
15546 	cmdline_fixed_string_t pctype;
15547 	cmdline_fixed_string_t mapping;
15548 	cmdline_fixed_string_t update;
15549 	cmdline_fixed_string_t pctype_list;
15550 	uint16_t flow_type;
15551 };
15552 
15553 /* Common CLI fields for pctype mapping update*/
15554 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15555 	TOKEN_STRING_INITIALIZER
15556 		(struct cmd_pctype_mapping_update_result,
15557 		 port, "port");
15558 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15559 	TOKEN_STRING_INITIALIZER
15560 		(struct cmd_pctype_mapping_update_result,
15561 		 config, "config");
15562 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15563 	TOKEN_NUM_INITIALIZER
15564 		(struct cmd_pctype_mapping_update_result,
15565 		 port_id, RTE_UINT16);
15566 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15567 	TOKEN_STRING_INITIALIZER
15568 		(struct cmd_pctype_mapping_update_result,
15569 		 pctype, "pctype");
15570 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15571 	TOKEN_STRING_INITIALIZER
15572 		(struct cmd_pctype_mapping_update_result,
15573 		 mapping, "mapping");
15574 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15575 	TOKEN_STRING_INITIALIZER
15576 		(struct cmd_pctype_mapping_update_result,
15577 		 update, "update");
15578 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15579 	TOKEN_STRING_INITIALIZER
15580 		(struct cmd_pctype_mapping_update_result,
15581 		 pctype_list, NULL);
15582 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15583 	TOKEN_NUM_INITIALIZER
15584 		(struct cmd_pctype_mapping_update_result,
15585 		 flow_type, RTE_UINT16);
15586 
15587 static void
15588 cmd_pctype_mapping_update_parsed(
15589 	void *parsed_result,
15590 	__rte_unused struct cmdline *cl,
15591 	__rte_unused void *data)
15592 {
15593 	struct cmd_pctype_mapping_update_result *res = parsed_result;
15594 	int ret = -ENOTSUP;
15595 #ifdef RTE_NET_I40E
15596 	struct rte_pmd_i40e_flow_type_mapping mapping;
15597 	unsigned int i;
15598 	unsigned int nb_item;
15599 	unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15600 #endif
15601 
15602 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15603 		return;
15604 
15605 #ifdef RTE_NET_I40E
15606 	nb_item = parse_item_list(res->pctype_list, "pctypes",
15607 				  RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15608 	mapping.flow_type = res->flow_type;
15609 	for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15610 		mapping.pctype |= (1ULL << pctype_list[i]);
15611 	ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15612 						&mapping,
15613 						1,
15614 						0);
15615 #endif
15616 
15617 	switch (ret) {
15618 	case 0:
15619 		break;
15620 	case -EINVAL:
15621 		fprintf(stderr, "invalid pctype or flow type\n");
15622 		break;
15623 	case -ENODEV:
15624 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15625 		break;
15626 	case -ENOTSUP:
15627 		fprintf(stderr, "function not implemented\n");
15628 		break;
15629 	default:
15630 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15631 	}
15632 }
15633 
15634 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15635 	.f = cmd_pctype_mapping_update_parsed,
15636 	.data = NULL,
15637 	.help_str = "port config <port_id> pctype mapping update"
15638 	" <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15639 	.tokens = {
15640 		(void *)&cmd_pctype_mapping_update_port,
15641 		(void *)&cmd_pctype_mapping_update_config,
15642 		(void *)&cmd_pctype_mapping_update_port_id,
15643 		(void *)&cmd_pctype_mapping_update_pctype,
15644 		(void *)&cmd_pctype_mapping_update_mapping,
15645 		(void *)&cmd_pctype_mapping_update_update,
15646 		(void *)&cmd_pctype_mapping_update_pc_type,
15647 		(void *)&cmd_pctype_mapping_update_flow_type,
15648 		NULL,
15649 	},
15650 };
15651 
15652 /* ptype mapping get */
15653 
15654 /* Common result structure for ptype mapping get */
15655 struct cmd_ptype_mapping_get_result {
15656 	cmdline_fixed_string_t ptype;
15657 	cmdline_fixed_string_t mapping;
15658 	cmdline_fixed_string_t get;
15659 	portid_t port_id;
15660 	uint8_t valid_only;
15661 };
15662 
15663 /* Common CLI fields for ptype mapping get */
15664 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15665 	TOKEN_STRING_INITIALIZER
15666 		(struct cmd_ptype_mapping_get_result,
15667 		 ptype, "ptype");
15668 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15669 	TOKEN_STRING_INITIALIZER
15670 		(struct cmd_ptype_mapping_get_result,
15671 		 mapping, "mapping");
15672 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15673 	TOKEN_STRING_INITIALIZER
15674 		(struct cmd_ptype_mapping_get_result,
15675 		 get, "get");
15676 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15677 	TOKEN_NUM_INITIALIZER
15678 		(struct cmd_ptype_mapping_get_result,
15679 		 port_id, RTE_UINT16);
15680 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15681 	TOKEN_NUM_INITIALIZER
15682 		(struct cmd_ptype_mapping_get_result,
15683 		 valid_only, RTE_UINT8);
15684 
15685 static void
15686 cmd_ptype_mapping_get_parsed(
15687 	void *parsed_result,
15688 	__rte_unused struct cmdline *cl,
15689 	__rte_unused void *data)
15690 {
15691 	struct cmd_ptype_mapping_get_result *res = parsed_result;
15692 	int ret = -ENOTSUP;
15693 #ifdef RTE_NET_I40E
15694 	int max_ptype_num = 256;
15695 	struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15696 	uint16_t count;
15697 	int i;
15698 #endif
15699 
15700 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15701 		return;
15702 
15703 #ifdef RTE_NET_I40E
15704 	ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15705 					mapping,
15706 					max_ptype_num,
15707 					&count,
15708 					res->valid_only);
15709 #endif
15710 
15711 	switch (ret) {
15712 	case 0:
15713 		break;
15714 	case -ENODEV:
15715 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15716 		break;
15717 	case -ENOTSUP:
15718 		fprintf(stderr, "function not implemented\n");
15719 		break;
15720 	default:
15721 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15722 	}
15723 
15724 #ifdef RTE_NET_I40E
15725 	if (!ret) {
15726 		for (i = 0; i < count; i++)
15727 			printf("%3d\t0x%08x\n",
15728 				mapping[i].hw_ptype, mapping[i].sw_ptype);
15729 	}
15730 #endif
15731 }
15732 
15733 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15734 	.f = cmd_ptype_mapping_get_parsed,
15735 	.data = NULL,
15736 	.help_str = "ptype mapping get <port_id> <valid_only>",
15737 	.tokens = {
15738 		(void *)&cmd_ptype_mapping_get_ptype,
15739 		(void *)&cmd_ptype_mapping_get_mapping,
15740 		(void *)&cmd_ptype_mapping_get_get,
15741 		(void *)&cmd_ptype_mapping_get_port_id,
15742 		(void *)&cmd_ptype_mapping_get_valid_only,
15743 		NULL,
15744 	},
15745 };
15746 
15747 /* ptype mapping replace */
15748 
15749 /* Common result structure for ptype mapping replace */
15750 struct cmd_ptype_mapping_replace_result {
15751 	cmdline_fixed_string_t ptype;
15752 	cmdline_fixed_string_t mapping;
15753 	cmdline_fixed_string_t replace;
15754 	portid_t port_id;
15755 	uint32_t target;
15756 	uint8_t mask;
15757 	uint32_t pkt_type;
15758 };
15759 
15760 /* Common CLI fields for ptype mapping replace */
15761 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15762 	TOKEN_STRING_INITIALIZER
15763 		(struct cmd_ptype_mapping_replace_result,
15764 		 ptype, "ptype");
15765 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15766 	TOKEN_STRING_INITIALIZER
15767 		(struct cmd_ptype_mapping_replace_result,
15768 		 mapping, "mapping");
15769 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15770 	TOKEN_STRING_INITIALIZER
15771 		(struct cmd_ptype_mapping_replace_result,
15772 		 replace, "replace");
15773 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15774 	TOKEN_NUM_INITIALIZER
15775 		(struct cmd_ptype_mapping_replace_result,
15776 		 port_id, RTE_UINT16);
15777 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15778 	TOKEN_NUM_INITIALIZER
15779 		(struct cmd_ptype_mapping_replace_result,
15780 		 target, RTE_UINT32);
15781 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15782 	TOKEN_NUM_INITIALIZER
15783 		(struct cmd_ptype_mapping_replace_result,
15784 		 mask, RTE_UINT8);
15785 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15786 	TOKEN_NUM_INITIALIZER
15787 		(struct cmd_ptype_mapping_replace_result,
15788 		 pkt_type, RTE_UINT32);
15789 
15790 static void
15791 cmd_ptype_mapping_replace_parsed(
15792 	void *parsed_result,
15793 	__rte_unused struct cmdline *cl,
15794 	__rte_unused void *data)
15795 {
15796 	struct cmd_ptype_mapping_replace_result *res = parsed_result;
15797 	int ret = -ENOTSUP;
15798 
15799 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15800 		return;
15801 
15802 #ifdef RTE_NET_I40E
15803 	ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15804 					res->target,
15805 					res->mask,
15806 					res->pkt_type);
15807 #endif
15808 
15809 	switch (ret) {
15810 	case 0:
15811 		break;
15812 	case -EINVAL:
15813 		fprintf(stderr, "invalid ptype 0x%8x or 0x%8x\n",
15814 			res->target, res->pkt_type);
15815 		break;
15816 	case -ENODEV:
15817 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15818 		break;
15819 	case -ENOTSUP:
15820 		fprintf(stderr, "function not implemented\n");
15821 		break;
15822 	default:
15823 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15824 	}
15825 }
15826 
15827 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15828 	.f = cmd_ptype_mapping_replace_parsed,
15829 	.data = NULL,
15830 	.help_str =
15831 		"ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15832 	.tokens = {
15833 		(void *)&cmd_ptype_mapping_replace_ptype,
15834 		(void *)&cmd_ptype_mapping_replace_mapping,
15835 		(void *)&cmd_ptype_mapping_replace_replace,
15836 		(void *)&cmd_ptype_mapping_replace_port_id,
15837 		(void *)&cmd_ptype_mapping_replace_target,
15838 		(void *)&cmd_ptype_mapping_replace_mask,
15839 		(void *)&cmd_ptype_mapping_replace_pkt_type,
15840 		NULL,
15841 	},
15842 };
15843 
15844 /* ptype mapping reset */
15845 
15846 /* Common result structure for ptype mapping reset */
15847 struct cmd_ptype_mapping_reset_result {
15848 	cmdline_fixed_string_t ptype;
15849 	cmdline_fixed_string_t mapping;
15850 	cmdline_fixed_string_t reset;
15851 	portid_t port_id;
15852 };
15853 
15854 /* Common CLI fields for ptype mapping reset*/
15855 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15856 	TOKEN_STRING_INITIALIZER
15857 		(struct cmd_ptype_mapping_reset_result,
15858 		 ptype, "ptype");
15859 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15860 	TOKEN_STRING_INITIALIZER
15861 		(struct cmd_ptype_mapping_reset_result,
15862 		 mapping, "mapping");
15863 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15864 	TOKEN_STRING_INITIALIZER
15865 		(struct cmd_ptype_mapping_reset_result,
15866 		 reset, "reset");
15867 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15868 	TOKEN_NUM_INITIALIZER
15869 		(struct cmd_ptype_mapping_reset_result,
15870 		 port_id, RTE_UINT16);
15871 
15872 static void
15873 cmd_ptype_mapping_reset_parsed(
15874 	void *parsed_result,
15875 	__rte_unused struct cmdline *cl,
15876 	__rte_unused void *data)
15877 {
15878 	struct cmd_ptype_mapping_reset_result *res = parsed_result;
15879 	int ret = -ENOTSUP;
15880 
15881 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15882 		return;
15883 
15884 #ifdef RTE_NET_I40E
15885 	ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15886 #endif
15887 
15888 	switch (ret) {
15889 	case 0:
15890 		break;
15891 	case -ENODEV:
15892 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15893 		break;
15894 	case -ENOTSUP:
15895 		fprintf(stderr, "function not implemented\n");
15896 		break;
15897 	default:
15898 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15899 	}
15900 }
15901 
15902 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15903 	.f = cmd_ptype_mapping_reset_parsed,
15904 	.data = NULL,
15905 	.help_str = "ptype mapping reset <port_id>",
15906 	.tokens = {
15907 		(void *)&cmd_ptype_mapping_reset_ptype,
15908 		(void *)&cmd_ptype_mapping_reset_mapping,
15909 		(void *)&cmd_ptype_mapping_reset_reset,
15910 		(void *)&cmd_ptype_mapping_reset_port_id,
15911 		NULL,
15912 	},
15913 };
15914 
15915 /* ptype mapping update */
15916 
15917 /* Common result structure for ptype mapping update */
15918 struct cmd_ptype_mapping_update_result {
15919 	cmdline_fixed_string_t ptype;
15920 	cmdline_fixed_string_t mapping;
15921 	cmdline_fixed_string_t reset;
15922 	portid_t port_id;
15923 	uint8_t hw_ptype;
15924 	uint32_t sw_ptype;
15925 };
15926 
15927 /* Common CLI fields for ptype mapping update*/
15928 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15929 	TOKEN_STRING_INITIALIZER
15930 		(struct cmd_ptype_mapping_update_result,
15931 		 ptype, "ptype");
15932 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15933 	TOKEN_STRING_INITIALIZER
15934 		(struct cmd_ptype_mapping_update_result,
15935 		 mapping, "mapping");
15936 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15937 	TOKEN_STRING_INITIALIZER
15938 		(struct cmd_ptype_mapping_update_result,
15939 		 reset, "update");
15940 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15941 	TOKEN_NUM_INITIALIZER
15942 		(struct cmd_ptype_mapping_update_result,
15943 		 port_id, RTE_UINT16);
15944 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15945 	TOKEN_NUM_INITIALIZER
15946 		(struct cmd_ptype_mapping_update_result,
15947 		 hw_ptype, RTE_UINT8);
15948 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15949 	TOKEN_NUM_INITIALIZER
15950 		(struct cmd_ptype_mapping_update_result,
15951 		 sw_ptype, RTE_UINT32);
15952 
15953 static void
15954 cmd_ptype_mapping_update_parsed(
15955 	void *parsed_result,
15956 	__rte_unused struct cmdline *cl,
15957 	__rte_unused void *data)
15958 {
15959 	struct cmd_ptype_mapping_update_result *res = parsed_result;
15960 	int ret = -ENOTSUP;
15961 #ifdef RTE_NET_I40E
15962 	struct rte_pmd_i40e_ptype_mapping mapping;
15963 #endif
15964 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15965 		return;
15966 
15967 #ifdef RTE_NET_I40E
15968 	mapping.hw_ptype = res->hw_ptype;
15969 	mapping.sw_ptype = res->sw_ptype;
15970 	ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15971 						&mapping,
15972 						1,
15973 						0);
15974 #endif
15975 
15976 	switch (ret) {
15977 	case 0:
15978 		break;
15979 	case -EINVAL:
15980 		fprintf(stderr, "invalid ptype 0x%8x\n", res->sw_ptype);
15981 		break;
15982 	case -ENODEV:
15983 		fprintf(stderr, "invalid port_id %d\n", res->port_id);
15984 		break;
15985 	case -ENOTSUP:
15986 		fprintf(stderr, "function not implemented\n");
15987 		break;
15988 	default:
15989 		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15990 	}
15991 }
15992 
15993 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15994 	.f = cmd_ptype_mapping_update_parsed,
15995 	.data = NULL,
15996 	.help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15997 	.tokens = {
15998 		(void *)&cmd_ptype_mapping_update_ptype,
15999 		(void *)&cmd_ptype_mapping_update_mapping,
16000 		(void *)&cmd_ptype_mapping_update_update,
16001 		(void *)&cmd_ptype_mapping_update_port_id,
16002 		(void *)&cmd_ptype_mapping_update_hw_ptype,
16003 		(void *)&cmd_ptype_mapping_update_sw_ptype,
16004 		NULL,
16005 	},
16006 };
16007 
16008 /* Common result structure for file commands */
16009 struct cmd_cmdfile_result {
16010 	cmdline_fixed_string_t load;
16011 	cmdline_fixed_string_t filename;
16012 };
16013 
16014 /* Common CLI fields for file commands */
16015 cmdline_parse_token_string_t cmd_load_cmdfile =
16016 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16017 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16018 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16019 
16020 static void
16021 cmd_load_from_file_parsed(
16022 	void *parsed_result,
16023 	__rte_unused struct cmdline *cl,
16024 	__rte_unused void *data)
16025 {
16026 	struct cmd_cmdfile_result *res = parsed_result;
16027 
16028 	cmdline_read_from_file(res->filename);
16029 }
16030 
16031 cmdline_parse_inst_t cmd_load_from_file = {
16032 	.f = cmd_load_from_file_parsed,
16033 	.data = NULL,
16034 	.help_str = "load <filename>",
16035 	.tokens = {
16036 		(void *)&cmd_load_cmdfile,
16037 		(void *)&cmd_load_cmdfile_filename,
16038 		NULL,
16039 	},
16040 };
16041 
16042 /* Get Rx offloads capabilities */
16043 struct cmd_rx_offload_get_capa_result {
16044 	cmdline_fixed_string_t show;
16045 	cmdline_fixed_string_t port;
16046 	portid_t port_id;
16047 	cmdline_fixed_string_t rx_offload;
16048 	cmdline_fixed_string_t capabilities;
16049 };
16050 
16051 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16052 	TOKEN_STRING_INITIALIZER
16053 		(struct cmd_rx_offload_get_capa_result,
16054 		 show, "show");
16055 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16056 	TOKEN_STRING_INITIALIZER
16057 		(struct cmd_rx_offload_get_capa_result,
16058 		 port, "port");
16059 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16060 	TOKEN_NUM_INITIALIZER
16061 		(struct cmd_rx_offload_get_capa_result,
16062 		 port_id, RTE_UINT16);
16063 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16064 	TOKEN_STRING_INITIALIZER
16065 		(struct cmd_rx_offload_get_capa_result,
16066 		 rx_offload, "rx_offload");
16067 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16068 	TOKEN_STRING_INITIALIZER
16069 		(struct cmd_rx_offload_get_capa_result,
16070 		 capabilities, "capabilities");
16071 
16072 static void
16073 print_rx_offloads(uint64_t offloads)
16074 {
16075 	uint64_t single_offload;
16076 	int begin;
16077 	int end;
16078 	int bit;
16079 
16080 	if (offloads == 0)
16081 		return;
16082 
16083 	begin = __builtin_ctzll(offloads);
16084 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16085 
16086 	single_offload = 1ULL << begin;
16087 	for (bit = begin; bit < end; bit++) {
16088 		if (offloads & single_offload)
16089 			printf(" %s",
16090 			       rte_eth_dev_rx_offload_name(single_offload));
16091 		single_offload <<= 1;
16092 	}
16093 }
16094 
16095 static void
16096 cmd_rx_offload_get_capa_parsed(
16097 	void *parsed_result,
16098 	__rte_unused struct cmdline *cl,
16099 	__rte_unused void *data)
16100 {
16101 	struct cmd_rx_offload_get_capa_result *res = parsed_result;
16102 	struct rte_eth_dev_info dev_info;
16103 	portid_t port_id = res->port_id;
16104 	uint64_t queue_offloads;
16105 	uint64_t port_offloads;
16106 	int ret;
16107 
16108 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16109 	if (ret != 0)
16110 		return;
16111 
16112 	queue_offloads = dev_info.rx_queue_offload_capa;
16113 	port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16114 
16115 	printf("Rx Offloading Capabilities of port %d :\n", port_id);
16116 	printf("  Per Queue :");
16117 	print_rx_offloads(queue_offloads);
16118 
16119 	printf("\n");
16120 	printf("  Per Port  :");
16121 	print_rx_offloads(port_offloads);
16122 	printf("\n\n");
16123 }
16124 
16125 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16126 	.f = cmd_rx_offload_get_capa_parsed,
16127 	.data = NULL,
16128 	.help_str = "show port <port_id> rx_offload capabilities",
16129 	.tokens = {
16130 		(void *)&cmd_rx_offload_get_capa_show,
16131 		(void *)&cmd_rx_offload_get_capa_port,
16132 		(void *)&cmd_rx_offload_get_capa_port_id,
16133 		(void *)&cmd_rx_offload_get_capa_rx_offload,
16134 		(void *)&cmd_rx_offload_get_capa_capabilities,
16135 		NULL,
16136 	}
16137 };
16138 
16139 /* Get Rx offloads configuration */
16140 struct cmd_rx_offload_get_configuration_result {
16141 	cmdline_fixed_string_t show;
16142 	cmdline_fixed_string_t port;
16143 	portid_t port_id;
16144 	cmdline_fixed_string_t rx_offload;
16145 	cmdline_fixed_string_t configuration;
16146 };
16147 
16148 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16149 	TOKEN_STRING_INITIALIZER
16150 		(struct cmd_rx_offload_get_configuration_result,
16151 		 show, "show");
16152 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16153 	TOKEN_STRING_INITIALIZER
16154 		(struct cmd_rx_offload_get_configuration_result,
16155 		 port, "port");
16156 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16157 	TOKEN_NUM_INITIALIZER
16158 		(struct cmd_rx_offload_get_configuration_result,
16159 		 port_id, RTE_UINT16);
16160 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16161 	TOKEN_STRING_INITIALIZER
16162 		(struct cmd_rx_offload_get_configuration_result,
16163 		 rx_offload, "rx_offload");
16164 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16165 	TOKEN_STRING_INITIALIZER
16166 		(struct cmd_rx_offload_get_configuration_result,
16167 		 configuration, "configuration");
16168 
16169 static void
16170 cmd_rx_offload_get_configuration_parsed(
16171 	void *parsed_result,
16172 	__rte_unused struct cmdline *cl,
16173 	__rte_unused void *data)
16174 {
16175 	struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16176 	struct rte_eth_dev_info dev_info;
16177 	portid_t port_id = res->port_id;
16178 	struct rte_port *port = &ports[port_id];
16179 	struct rte_eth_conf dev_conf;
16180 	uint64_t port_offloads;
16181 	uint64_t queue_offloads;
16182 	uint16_t nb_rx_queues;
16183 	int q;
16184 	int ret;
16185 
16186 	printf("Rx Offloading Configuration of port %d :\n", port_id);
16187 
16188 	ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16189 	if (ret != 0)
16190 		return;
16191 
16192 	port_offloads = dev_conf.rxmode.offloads;
16193 	printf("  Port :");
16194 	print_rx_offloads(port_offloads);
16195 	printf("\n");
16196 
16197 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16198 	if (ret != 0)
16199 		return;
16200 
16201 	nb_rx_queues = dev_info.nb_rx_queues;
16202 	for (q = 0; q < nb_rx_queues; q++) {
16203 		queue_offloads = port->rx_conf[q].offloads;
16204 		printf("  Queue[%2d] :", q);
16205 		print_rx_offloads(queue_offloads);
16206 		printf("\n");
16207 	}
16208 	printf("\n");
16209 }
16210 
16211 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16212 	.f = cmd_rx_offload_get_configuration_parsed,
16213 	.data = NULL,
16214 	.help_str = "show port <port_id> rx_offload configuration",
16215 	.tokens = {
16216 		(void *)&cmd_rx_offload_get_configuration_show,
16217 		(void *)&cmd_rx_offload_get_configuration_port,
16218 		(void *)&cmd_rx_offload_get_configuration_port_id,
16219 		(void *)&cmd_rx_offload_get_configuration_rx_offload,
16220 		(void *)&cmd_rx_offload_get_configuration_configuration,
16221 		NULL,
16222 	}
16223 };
16224 
16225 /* Enable/Disable a per port offloading */
16226 struct cmd_config_per_port_rx_offload_result {
16227 	cmdline_fixed_string_t port;
16228 	cmdline_fixed_string_t config;
16229 	portid_t port_id;
16230 	cmdline_fixed_string_t rx_offload;
16231 	cmdline_fixed_string_t offload;
16232 	cmdline_fixed_string_t on_off;
16233 };
16234 
16235 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16236 	TOKEN_STRING_INITIALIZER
16237 		(struct cmd_config_per_port_rx_offload_result,
16238 		 port, "port");
16239 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16240 	TOKEN_STRING_INITIALIZER
16241 		(struct cmd_config_per_port_rx_offload_result,
16242 		 config, "config");
16243 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16244 	TOKEN_NUM_INITIALIZER
16245 		(struct cmd_config_per_port_rx_offload_result,
16246 		 port_id, RTE_UINT16);
16247 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16248 	TOKEN_STRING_INITIALIZER
16249 		(struct cmd_config_per_port_rx_offload_result,
16250 		 rx_offload, "rx_offload");
16251 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16252 	TOKEN_STRING_INITIALIZER
16253 		(struct cmd_config_per_port_rx_offload_result,
16254 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16255 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16256 			   "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16257 			   "scatter#buffer_split#timestamp#security#"
16258 			   "keep_crc#rss_hash");
16259 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16260 	TOKEN_STRING_INITIALIZER
16261 		(struct cmd_config_per_port_rx_offload_result,
16262 		 on_off, "on#off");
16263 
16264 static uint64_t
16265 search_rx_offload(const char *name)
16266 {
16267 	uint64_t single_offload;
16268 	const char *single_name;
16269 	int found = 0;
16270 	unsigned int bit;
16271 
16272 	single_offload = 1;
16273 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16274 		single_name = rte_eth_dev_rx_offload_name(single_offload);
16275 		if (!strcasecmp(single_name, name)) {
16276 			found = 1;
16277 			break;
16278 		}
16279 		single_offload <<= 1;
16280 	}
16281 
16282 	if (found)
16283 		return single_offload;
16284 
16285 	return 0;
16286 }
16287 
16288 static void
16289 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16290 				__rte_unused struct cmdline *cl,
16291 				__rte_unused void *data)
16292 {
16293 	struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16294 	portid_t port_id = res->port_id;
16295 	struct rte_eth_dev_info dev_info;
16296 	struct rte_port *port = &ports[port_id];
16297 	uint64_t single_offload;
16298 	uint16_t nb_rx_queues;
16299 	int q;
16300 	int ret;
16301 
16302 	if (port->port_status != RTE_PORT_STOPPED) {
16303 		fprintf(stderr,
16304 			"Error: Can't config offload when Port %d is not stopped\n",
16305 			port_id);
16306 		return;
16307 	}
16308 
16309 	single_offload = search_rx_offload(res->offload);
16310 	if (single_offload == 0) {
16311 		fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16312 		return;
16313 	}
16314 
16315 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16316 	if (ret != 0)
16317 		return;
16318 
16319 	nb_rx_queues = dev_info.nb_rx_queues;
16320 	if (!strcmp(res->on_off, "on")) {
16321 		port->dev_conf.rxmode.offloads |= single_offload;
16322 		for (q = 0; q < nb_rx_queues; q++)
16323 			port->rx_conf[q].offloads |= single_offload;
16324 	} else {
16325 		port->dev_conf.rxmode.offloads &= ~single_offload;
16326 		for (q = 0; q < nb_rx_queues; q++)
16327 			port->rx_conf[q].offloads &= ~single_offload;
16328 	}
16329 
16330 	cmd_reconfig_device_queue(port_id, 1, 1);
16331 }
16332 
16333 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16334 	.f = cmd_config_per_port_rx_offload_parsed,
16335 	.data = NULL,
16336 	.help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16337 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16338 		    "macsec_strip|header_split|vlan_filter|vlan_extend|"
16339 		    "jumbo_frame|scatter|buffer_split|timestamp|security|"
16340 		    "keep_crc|rss_hash on|off",
16341 	.tokens = {
16342 		(void *)&cmd_config_per_port_rx_offload_result_port,
16343 		(void *)&cmd_config_per_port_rx_offload_result_config,
16344 		(void *)&cmd_config_per_port_rx_offload_result_port_id,
16345 		(void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16346 		(void *)&cmd_config_per_port_rx_offload_result_offload,
16347 		(void *)&cmd_config_per_port_rx_offload_result_on_off,
16348 		NULL,
16349 	}
16350 };
16351 
16352 /* Enable/Disable a per queue offloading */
16353 struct cmd_config_per_queue_rx_offload_result {
16354 	cmdline_fixed_string_t port;
16355 	portid_t port_id;
16356 	cmdline_fixed_string_t rxq;
16357 	uint16_t queue_id;
16358 	cmdline_fixed_string_t rx_offload;
16359 	cmdline_fixed_string_t offload;
16360 	cmdline_fixed_string_t on_off;
16361 };
16362 
16363 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16364 	TOKEN_STRING_INITIALIZER
16365 		(struct cmd_config_per_queue_rx_offload_result,
16366 		 port, "port");
16367 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16368 	TOKEN_NUM_INITIALIZER
16369 		(struct cmd_config_per_queue_rx_offload_result,
16370 		 port_id, RTE_UINT16);
16371 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16372 	TOKEN_STRING_INITIALIZER
16373 		(struct cmd_config_per_queue_rx_offload_result,
16374 		 rxq, "rxq");
16375 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16376 	TOKEN_NUM_INITIALIZER
16377 		(struct cmd_config_per_queue_rx_offload_result,
16378 		 queue_id, RTE_UINT16);
16379 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16380 	TOKEN_STRING_INITIALIZER
16381 		(struct cmd_config_per_queue_rx_offload_result,
16382 		 rx_offload, "rx_offload");
16383 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16384 	TOKEN_STRING_INITIALIZER
16385 		(struct cmd_config_per_queue_rx_offload_result,
16386 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16387 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16388 			   "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16389 			   "scatter#buffer_split#timestamp#security#keep_crc");
16390 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16391 	TOKEN_STRING_INITIALIZER
16392 		(struct cmd_config_per_queue_rx_offload_result,
16393 		 on_off, "on#off");
16394 
16395 static void
16396 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16397 				__rte_unused struct cmdline *cl,
16398 				__rte_unused void *data)
16399 {
16400 	struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16401 	struct rte_eth_dev_info dev_info;
16402 	portid_t port_id = res->port_id;
16403 	uint16_t queue_id = res->queue_id;
16404 	struct rte_port *port = &ports[port_id];
16405 	uint64_t single_offload;
16406 	int ret;
16407 
16408 	if (port->port_status != RTE_PORT_STOPPED) {
16409 		fprintf(stderr,
16410 			"Error: Can't config offload when Port %d is not stopped\n",
16411 			port_id);
16412 		return;
16413 	}
16414 
16415 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16416 	if (ret != 0)
16417 		return;
16418 
16419 	if (queue_id >= dev_info.nb_rx_queues) {
16420 		fprintf(stderr,
16421 			"Error: input queue_id should be 0 ... %d\n",
16422 			dev_info.nb_rx_queues - 1);
16423 		return;
16424 	}
16425 
16426 	single_offload = search_rx_offload(res->offload);
16427 	if (single_offload == 0) {
16428 		fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16429 		return;
16430 	}
16431 
16432 	if (!strcmp(res->on_off, "on"))
16433 		port->rx_conf[queue_id].offloads |= single_offload;
16434 	else
16435 		port->rx_conf[queue_id].offloads &= ~single_offload;
16436 
16437 	cmd_reconfig_device_queue(port_id, 1, 1);
16438 }
16439 
16440 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16441 	.f = cmd_config_per_queue_rx_offload_parsed,
16442 	.data = NULL,
16443 	.help_str = "port <port_id> rxq <queue_id> rx_offload "
16444 		    "vlan_strip|ipv4_cksum|"
16445 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16446 		    "macsec_strip|header_split|vlan_filter|vlan_extend|"
16447 		    "jumbo_frame|scatter|buffer_split|timestamp|security|"
16448 		    "keep_crc on|off",
16449 	.tokens = {
16450 		(void *)&cmd_config_per_queue_rx_offload_result_port,
16451 		(void *)&cmd_config_per_queue_rx_offload_result_port_id,
16452 		(void *)&cmd_config_per_queue_rx_offload_result_rxq,
16453 		(void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16454 		(void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16455 		(void *)&cmd_config_per_queue_rx_offload_result_offload,
16456 		(void *)&cmd_config_per_queue_rx_offload_result_on_off,
16457 		NULL,
16458 	}
16459 };
16460 
16461 /* Get Tx offloads capabilities */
16462 struct cmd_tx_offload_get_capa_result {
16463 	cmdline_fixed_string_t show;
16464 	cmdline_fixed_string_t port;
16465 	portid_t port_id;
16466 	cmdline_fixed_string_t tx_offload;
16467 	cmdline_fixed_string_t capabilities;
16468 };
16469 
16470 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16471 	TOKEN_STRING_INITIALIZER
16472 		(struct cmd_tx_offload_get_capa_result,
16473 		 show, "show");
16474 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16475 	TOKEN_STRING_INITIALIZER
16476 		(struct cmd_tx_offload_get_capa_result,
16477 		 port, "port");
16478 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16479 	TOKEN_NUM_INITIALIZER
16480 		(struct cmd_tx_offload_get_capa_result,
16481 		 port_id, RTE_UINT16);
16482 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16483 	TOKEN_STRING_INITIALIZER
16484 		(struct cmd_tx_offload_get_capa_result,
16485 		 tx_offload, "tx_offload");
16486 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16487 	TOKEN_STRING_INITIALIZER
16488 		(struct cmd_tx_offload_get_capa_result,
16489 		 capabilities, "capabilities");
16490 
16491 static void
16492 print_tx_offloads(uint64_t offloads)
16493 {
16494 	uint64_t single_offload;
16495 	int begin;
16496 	int end;
16497 	int bit;
16498 
16499 	if (offloads == 0)
16500 		return;
16501 
16502 	begin = __builtin_ctzll(offloads);
16503 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16504 
16505 	single_offload = 1ULL << begin;
16506 	for (bit = begin; bit < end; bit++) {
16507 		if (offloads & single_offload)
16508 			printf(" %s",
16509 			       rte_eth_dev_tx_offload_name(single_offload));
16510 		single_offload <<= 1;
16511 	}
16512 }
16513 
16514 static void
16515 cmd_tx_offload_get_capa_parsed(
16516 	void *parsed_result,
16517 	__rte_unused struct cmdline *cl,
16518 	__rte_unused void *data)
16519 {
16520 	struct cmd_tx_offload_get_capa_result *res = parsed_result;
16521 	struct rte_eth_dev_info dev_info;
16522 	portid_t port_id = res->port_id;
16523 	uint64_t queue_offloads;
16524 	uint64_t port_offloads;
16525 	int ret;
16526 
16527 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16528 	if (ret != 0)
16529 		return;
16530 
16531 	queue_offloads = dev_info.tx_queue_offload_capa;
16532 	port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16533 
16534 	printf("Tx Offloading Capabilities of port %d :\n", port_id);
16535 	printf("  Per Queue :");
16536 	print_tx_offloads(queue_offloads);
16537 
16538 	printf("\n");
16539 	printf("  Per Port  :");
16540 	print_tx_offloads(port_offloads);
16541 	printf("\n\n");
16542 }
16543 
16544 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16545 	.f = cmd_tx_offload_get_capa_parsed,
16546 	.data = NULL,
16547 	.help_str = "show port <port_id> tx_offload capabilities",
16548 	.tokens = {
16549 		(void *)&cmd_tx_offload_get_capa_show,
16550 		(void *)&cmd_tx_offload_get_capa_port,
16551 		(void *)&cmd_tx_offload_get_capa_port_id,
16552 		(void *)&cmd_tx_offload_get_capa_tx_offload,
16553 		(void *)&cmd_tx_offload_get_capa_capabilities,
16554 		NULL,
16555 	}
16556 };
16557 
16558 /* Get Tx offloads configuration */
16559 struct cmd_tx_offload_get_configuration_result {
16560 	cmdline_fixed_string_t show;
16561 	cmdline_fixed_string_t port;
16562 	portid_t port_id;
16563 	cmdline_fixed_string_t tx_offload;
16564 	cmdline_fixed_string_t configuration;
16565 };
16566 
16567 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16568 	TOKEN_STRING_INITIALIZER
16569 		(struct cmd_tx_offload_get_configuration_result,
16570 		 show, "show");
16571 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16572 	TOKEN_STRING_INITIALIZER
16573 		(struct cmd_tx_offload_get_configuration_result,
16574 		 port, "port");
16575 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16576 	TOKEN_NUM_INITIALIZER
16577 		(struct cmd_tx_offload_get_configuration_result,
16578 		 port_id, RTE_UINT16);
16579 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16580 	TOKEN_STRING_INITIALIZER
16581 		(struct cmd_tx_offload_get_configuration_result,
16582 		 tx_offload, "tx_offload");
16583 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16584 	TOKEN_STRING_INITIALIZER
16585 		(struct cmd_tx_offload_get_configuration_result,
16586 		 configuration, "configuration");
16587 
16588 static void
16589 cmd_tx_offload_get_configuration_parsed(
16590 	void *parsed_result,
16591 	__rte_unused struct cmdline *cl,
16592 	__rte_unused void *data)
16593 {
16594 	struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16595 	struct rte_eth_dev_info dev_info;
16596 	portid_t port_id = res->port_id;
16597 	struct rte_port *port = &ports[port_id];
16598 	struct rte_eth_conf dev_conf;
16599 	uint64_t port_offloads;
16600 	uint64_t queue_offloads;
16601 	uint16_t nb_tx_queues;
16602 	int q;
16603 	int ret;
16604 
16605 	printf("Tx Offloading Configuration of port %d :\n", port_id);
16606 
16607 	ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16608 	if (ret != 0)
16609 		return;
16610 
16611 	port_offloads = dev_conf.txmode.offloads;
16612 	printf("  Port :");
16613 	print_tx_offloads(port_offloads);
16614 	printf("\n");
16615 
16616 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16617 	if (ret != 0)
16618 		return;
16619 
16620 	nb_tx_queues = dev_info.nb_tx_queues;
16621 	for (q = 0; q < nb_tx_queues; q++) {
16622 		queue_offloads = port->tx_conf[q].offloads;
16623 		printf("  Queue[%2d] :", q);
16624 		print_tx_offloads(queue_offloads);
16625 		printf("\n");
16626 	}
16627 	printf("\n");
16628 }
16629 
16630 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16631 	.f = cmd_tx_offload_get_configuration_parsed,
16632 	.data = NULL,
16633 	.help_str = "show port <port_id> tx_offload configuration",
16634 	.tokens = {
16635 		(void *)&cmd_tx_offload_get_configuration_show,
16636 		(void *)&cmd_tx_offload_get_configuration_port,
16637 		(void *)&cmd_tx_offload_get_configuration_port_id,
16638 		(void *)&cmd_tx_offload_get_configuration_tx_offload,
16639 		(void *)&cmd_tx_offload_get_configuration_configuration,
16640 		NULL,
16641 	}
16642 };
16643 
16644 /* Enable/Disable a per port offloading */
16645 struct cmd_config_per_port_tx_offload_result {
16646 	cmdline_fixed_string_t port;
16647 	cmdline_fixed_string_t config;
16648 	portid_t port_id;
16649 	cmdline_fixed_string_t tx_offload;
16650 	cmdline_fixed_string_t offload;
16651 	cmdline_fixed_string_t on_off;
16652 };
16653 
16654 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16655 	TOKEN_STRING_INITIALIZER
16656 		(struct cmd_config_per_port_tx_offload_result,
16657 		 port, "port");
16658 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16659 	TOKEN_STRING_INITIALIZER
16660 		(struct cmd_config_per_port_tx_offload_result,
16661 		 config, "config");
16662 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16663 	TOKEN_NUM_INITIALIZER
16664 		(struct cmd_config_per_port_tx_offload_result,
16665 		 port_id, RTE_UINT16);
16666 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16667 	TOKEN_STRING_INITIALIZER
16668 		(struct cmd_config_per_port_tx_offload_result,
16669 		 tx_offload, "tx_offload");
16670 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16671 	TOKEN_STRING_INITIALIZER
16672 		(struct cmd_config_per_port_tx_offload_result,
16673 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16674 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16675 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16676 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16677 			  "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16678 			  "send_on_timestamp");
16679 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16680 	TOKEN_STRING_INITIALIZER
16681 		(struct cmd_config_per_port_tx_offload_result,
16682 		 on_off, "on#off");
16683 
16684 static uint64_t
16685 search_tx_offload(const char *name)
16686 {
16687 	uint64_t single_offload;
16688 	const char *single_name;
16689 	int found = 0;
16690 	unsigned int bit;
16691 
16692 	single_offload = 1;
16693 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16694 		single_name = rte_eth_dev_tx_offload_name(single_offload);
16695 		if (single_name == NULL)
16696 			break;
16697 		if (!strcasecmp(single_name, name)) {
16698 			found = 1;
16699 			break;
16700 		} else if (!strcasecmp(single_name, "UNKNOWN"))
16701 			break;
16702 		single_offload <<= 1;
16703 	}
16704 
16705 	if (found)
16706 		return single_offload;
16707 
16708 	return 0;
16709 }
16710 
16711 static void
16712 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16713 				__rte_unused struct cmdline *cl,
16714 				__rte_unused void *data)
16715 {
16716 	struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16717 	portid_t port_id = res->port_id;
16718 	struct rte_eth_dev_info dev_info;
16719 	struct rte_port *port = &ports[port_id];
16720 	uint64_t single_offload;
16721 	uint16_t nb_tx_queues;
16722 	int q;
16723 	int ret;
16724 
16725 	if (port->port_status != RTE_PORT_STOPPED) {
16726 		fprintf(stderr,
16727 			"Error: Can't config offload when Port %d is not stopped\n",
16728 			port_id);
16729 		return;
16730 	}
16731 
16732 	single_offload = search_tx_offload(res->offload);
16733 	if (single_offload == 0) {
16734 		fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16735 		return;
16736 	}
16737 
16738 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16739 	if (ret != 0)
16740 		return;
16741 
16742 	nb_tx_queues = dev_info.nb_tx_queues;
16743 	if (!strcmp(res->on_off, "on")) {
16744 		port->dev_conf.txmode.offloads |= single_offload;
16745 		for (q = 0; q < nb_tx_queues; q++)
16746 			port->tx_conf[q].offloads |= single_offload;
16747 	} else {
16748 		port->dev_conf.txmode.offloads &= ~single_offload;
16749 		for (q = 0; q < nb_tx_queues; q++)
16750 			port->tx_conf[q].offloads &= ~single_offload;
16751 	}
16752 
16753 	cmd_reconfig_device_queue(port_id, 1, 1);
16754 }
16755 
16756 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16757 	.f = cmd_config_per_port_tx_offload_parsed,
16758 	.data = NULL,
16759 	.help_str = "port config <port_id> tx_offload "
16760 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16761 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16762 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16763 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16764 		    "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16765 		    "send_on_timestamp on|off",
16766 	.tokens = {
16767 		(void *)&cmd_config_per_port_tx_offload_result_port,
16768 		(void *)&cmd_config_per_port_tx_offload_result_config,
16769 		(void *)&cmd_config_per_port_tx_offload_result_port_id,
16770 		(void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16771 		(void *)&cmd_config_per_port_tx_offload_result_offload,
16772 		(void *)&cmd_config_per_port_tx_offload_result_on_off,
16773 		NULL,
16774 	}
16775 };
16776 
16777 /* Enable/Disable a per queue offloading */
16778 struct cmd_config_per_queue_tx_offload_result {
16779 	cmdline_fixed_string_t port;
16780 	portid_t port_id;
16781 	cmdline_fixed_string_t txq;
16782 	uint16_t queue_id;
16783 	cmdline_fixed_string_t tx_offload;
16784 	cmdline_fixed_string_t offload;
16785 	cmdline_fixed_string_t on_off;
16786 };
16787 
16788 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16789 	TOKEN_STRING_INITIALIZER
16790 		(struct cmd_config_per_queue_tx_offload_result,
16791 		 port, "port");
16792 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16793 	TOKEN_NUM_INITIALIZER
16794 		(struct cmd_config_per_queue_tx_offload_result,
16795 		 port_id, RTE_UINT16);
16796 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16797 	TOKEN_STRING_INITIALIZER
16798 		(struct cmd_config_per_queue_tx_offload_result,
16799 		 txq, "txq");
16800 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16801 	TOKEN_NUM_INITIALIZER
16802 		(struct cmd_config_per_queue_tx_offload_result,
16803 		 queue_id, RTE_UINT16);
16804 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16805 	TOKEN_STRING_INITIALIZER
16806 		(struct cmd_config_per_queue_tx_offload_result,
16807 		 tx_offload, "tx_offload");
16808 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16809 	TOKEN_STRING_INITIALIZER
16810 		(struct cmd_config_per_queue_tx_offload_result,
16811 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16812 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16813 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16814 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16815 			  "mt_lockfree#multi_segs#mbuf_fast_free#security");
16816 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16817 	TOKEN_STRING_INITIALIZER
16818 		(struct cmd_config_per_queue_tx_offload_result,
16819 		 on_off, "on#off");
16820 
16821 static void
16822 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16823 				__rte_unused struct cmdline *cl,
16824 				__rte_unused void *data)
16825 {
16826 	struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16827 	struct rte_eth_dev_info dev_info;
16828 	portid_t port_id = res->port_id;
16829 	uint16_t queue_id = res->queue_id;
16830 	struct rte_port *port = &ports[port_id];
16831 	uint64_t single_offload;
16832 	int ret;
16833 
16834 	if (port->port_status != RTE_PORT_STOPPED) {
16835 		fprintf(stderr,
16836 			"Error: Can't config offload when Port %d is not stopped\n",
16837 			port_id);
16838 		return;
16839 	}
16840 
16841 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
16842 	if (ret != 0)
16843 		return;
16844 
16845 	if (queue_id >= dev_info.nb_tx_queues) {
16846 		fprintf(stderr,
16847 			"Error: input queue_id should be 0 ... %d\n",
16848 			dev_info.nb_tx_queues - 1);
16849 		return;
16850 	}
16851 
16852 	single_offload = search_tx_offload(res->offload);
16853 	if (single_offload == 0) {
16854 		fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16855 		return;
16856 	}
16857 
16858 	if (!strcmp(res->on_off, "on"))
16859 		port->tx_conf[queue_id].offloads |= single_offload;
16860 	else
16861 		port->tx_conf[queue_id].offloads &= ~single_offload;
16862 
16863 	cmd_reconfig_device_queue(port_id, 1, 1);
16864 }
16865 
16866 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16867 	.f = cmd_config_per_queue_tx_offload_parsed,
16868 	.data = NULL,
16869 	.help_str = "port <port_id> txq <queue_id> tx_offload "
16870 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16871 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16872 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16873 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16874 		    "mt_lockfree|multi_segs|mbuf_fast_free|security "
16875 		    "on|off",
16876 	.tokens = {
16877 		(void *)&cmd_config_per_queue_tx_offload_result_port,
16878 		(void *)&cmd_config_per_queue_tx_offload_result_port_id,
16879 		(void *)&cmd_config_per_queue_tx_offload_result_txq,
16880 		(void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16881 		(void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16882 		(void *)&cmd_config_per_queue_tx_offload_result_offload,
16883 		(void *)&cmd_config_per_queue_tx_offload_result_on_off,
16884 		NULL,
16885 	}
16886 };
16887 
16888 /* *** configure tx_metadata for specific port *** */
16889 struct cmd_config_tx_metadata_specific_result {
16890 	cmdline_fixed_string_t port;
16891 	cmdline_fixed_string_t keyword;
16892 	uint16_t port_id;
16893 	cmdline_fixed_string_t item;
16894 	uint32_t value;
16895 };
16896 
16897 static void
16898 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16899 				__rte_unused struct cmdline *cl,
16900 				__rte_unused void *data)
16901 {
16902 	struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16903 
16904 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16905 		return;
16906 	ports[res->port_id].tx_metadata = res->value;
16907 	/* Add/remove callback to insert valid metadata in every Tx packet. */
16908 	if (ports[res->port_id].tx_metadata)
16909 		add_tx_md_callback(res->port_id);
16910 	else
16911 		remove_tx_md_callback(res->port_id);
16912 	rte_flow_dynf_metadata_register();
16913 }
16914 
16915 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16916 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16917 			port, "port");
16918 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16919 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16920 			keyword, "config");
16921 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16922 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16923 			port_id, RTE_UINT16);
16924 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16925 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16926 			item, "tx_metadata");
16927 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16928 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16929 			value, RTE_UINT32);
16930 
16931 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16932 	.f = cmd_config_tx_metadata_specific_parsed,
16933 	.data = NULL,
16934 	.help_str = "port config <port_id> tx_metadata <value>",
16935 	.tokens = {
16936 		(void *)&cmd_config_tx_metadata_specific_port,
16937 		(void *)&cmd_config_tx_metadata_specific_keyword,
16938 		(void *)&cmd_config_tx_metadata_specific_id,
16939 		(void *)&cmd_config_tx_metadata_specific_item,
16940 		(void *)&cmd_config_tx_metadata_specific_value,
16941 		NULL,
16942 	},
16943 };
16944 
16945 /* *** set dynf *** */
16946 struct cmd_config_tx_dynf_specific_result {
16947 	cmdline_fixed_string_t port;
16948 	cmdline_fixed_string_t keyword;
16949 	uint16_t port_id;
16950 	cmdline_fixed_string_t item;
16951 	cmdline_fixed_string_t name;
16952 	cmdline_fixed_string_t value;
16953 };
16954 
16955 static void
16956 cmd_config_dynf_specific_parsed(void *parsed_result,
16957 				__rte_unused struct cmdline *cl,
16958 				__rte_unused void *data)
16959 {
16960 	struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16961 	struct rte_mbuf_dynflag desc_flag;
16962 	int flag;
16963 	uint64_t old_port_flags;
16964 
16965 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16966 		return;
16967 	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16968 	if (flag <= 0) {
16969 		if (strlcpy(desc_flag.name, res->name,
16970 			    RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16971 			fprintf(stderr, "Flag name too long\n");
16972 			return;
16973 		}
16974 		desc_flag.flags = 0;
16975 		flag = rte_mbuf_dynflag_register(&desc_flag);
16976 		if (flag < 0) {
16977 			fprintf(stderr, "Can't register flag\n");
16978 			return;
16979 		}
16980 		strcpy(dynf_names[flag], desc_flag.name);
16981 	}
16982 	old_port_flags = ports[res->port_id].mbuf_dynf;
16983 	if (!strcmp(res->value, "set")) {
16984 		ports[res->port_id].mbuf_dynf |= 1UL << flag;
16985 		if (old_port_flags == 0)
16986 			add_tx_dynf_callback(res->port_id);
16987 	} else {
16988 		ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16989 		if (ports[res->port_id].mbuf_dynf == 0)
16990 			remove_tx_dynf_callback(res->port_id);
16991 	}
16992 }
16993 
16994 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16995 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16996 			keyword, "port");
16997 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16998 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16999 			keyword, "config");
17000 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
17001 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17002 			port_id, RTE_UINT16);
17003 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
17004 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17005 			item, "dynf");
17006 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
17007 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17008 			name, NULL);
17009 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
17010 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17011 			value, "set#clear");
17012 
17013 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
17014 	.f = cmd_config_dynf_specific_parsed,
17015 	.data = NULL,
17016 	.help_str = "port config <port id> dynf <name> set|clear",
17017 	.tokens = {
17018 		(void *)&cmd_config_tx_dynf_specific_port,
17019 		(void *)&cmd_config_tx_dynf_specific_keyword,
17020 		(void *)&cmd_config_tx_dynf_specific_port_id,
17021 		(void *)&cmd_config_tx_dynf_specific_item,
17022 		(void *)&cmd_config_tx_dynf_specific_name,
17023 		(void *)&cmd_config_tx_dynf_specific_value,
17024 		NULL,
17025 	},
17026 };
17027 
17028 /* *** display tx_metadata per port configuration *** */
17029 struct cmd_show_tx_metadata_result {
17030 	cmdline_fixed_string_t cmd_show;
17031 	cmdline_fixed_string_t cmd_port;
17032 	cmdline_fixed_string_t cmd_keyword;
17033 	portid_t cmd_pid;
17034 };
17035 
17036 static void
17037 cmd_show_tx_metadata_parsed(void *parsed_result,
17038 		__rte_unused struct cmdline *cl,
17039 		__rte_unused void *data)
17040 {
17041 	struct cmd_show_tx_metadata_result *res = parsed_result;
17042 
17043 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17044 		fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17045 		return;
17046 	}
17047 	if (!strcmp(res->cmd_keyword, "tx_metadata")) {
17048 		printf("Port %u tx_metadata: %u\n", res->cmd_pid,
17049 		       ports[res->cmd_pid].tx_metadata);
17050 	}
17051 }
17052 
17053 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
17054 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17055 			cmd_show, "show");
17056 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
17057 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17058 			cmd_port, "port");
17059 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
17060 	TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
17061 			cmd_pid, RTE_UINT16);
17062 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
17063 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17064 			cmd_keyword, "tx_metadata");
17065 
17066 cmdline_parse_inst_t cmd_show_tx_metadata = {
17067 	.f = cmd_show_tx_metadata_parsed,
17068 	.data = NULL,
17069 	.help_str = "show port <port_id> tx_metadata",
17070 	.tokens = {
17071 		(void *)&cmd_show_tx_metadata_show,
17072 		(void *)&cmd_show_tx_metadata_port,
17073 		(void *)&cmd_show_tx_metadata_pid,
17074 		(void *)&cmd_show_tx_metadata_keyword,
17075 		NULL,
17076 	},
17077 };
17078 
17079 /* *** show fec capability per port configuration *** */
17080 struct cmd_show_fec_capability_result {
17081 	cmdline_fixed_string_t cmd_show;
17082 	cmdline_fixed_string_t cmd_port;
17083 	cmdline_fixed_string_t cmd_fec;
17084 	cmdline_fixed_string_t cmd_keyword;
17085 	portid_t cmd_pid;
17086 };
17087 
17088 static void
17089 cmd_show_fec_capability_parsed(void *parsed_result,
17090 		__rte_unused struct cmdline *cl,
17091 		__rte_unused void *data)
17092 {
17093 	struct cmd_show_fec_capability_result *res = parsed_result;
17094 	struct rte_eth_fec_capa *speed_fec_capa;
17095 	unsigned int num;
17096 	int ret;
17097 
17098 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17099 		fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17100 		return;
17101 	}
17102 
17103 	ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
17104 	if (ret == -ENOTSUP) {
17105 		fprintf(stderr, "Function not implemented\n");
17106 		return;
17107 	} else if (ret < 0) {
17108 		fprintf(stderr, "Get FEC capability failed: %d\n", ret);
17109 		return;
17110 	}
17111 
17112 	num = (unsigned int)ret;
17113 	speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
17114 	if (speed_fec_capa == NULL) {
17115 		fprintf(stderr, "Failed to alloc FEC capability buffer\n");
17116 		return;
17117 	}
17118 
17119 	ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
17120 	if (ret < 0) {
17121 		fprintf(stderr, "Error getting FEC capability: %d\n", ret);
17122 		goto out;
17123 	}
17124 
17125 	show_fec_capability(num, speed_fec_capa);
17126 out:
17127 	free(speed_fec_capa);
17128 }
17129 
17130 cmdline_parse_token_string_t cmd_show_fec_capability_show =
17131 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17132 			cmd_show, "show");
17133 cmdline_parse_token_string_t cmd_show_fec_capability_port =
17134 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17135 			cmd_port, "port");
17136 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
17137 	TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
17138 			cmd_pid, RTE_UINT16);
17139 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
17140 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17141 			cmd_fec, "fec");
17142 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
17143 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17144 			cmd_keyword, "capabilities");
17145 
17146 cmdline_parse_inst_t cmd_show_capability = {
17147 	.f = cmd_show_fec_capability_parsed,
17148 	.data = NULL,
17149 	.help_str = "show port <port_id> fec capabilities",
17150 	.tokens = {
17151 		(void *)&cmd_show_fec_capability_show,
17152 		(void *)&cmd_show_fec_capability_port,
17153 		(void *)&cmd_show_fec_capability_pid,
17154 		(void *)&cmd_show_fec_capability_fec,
17155 		(void *)&cmd_show_fec_capability_keyword,
17156 		NULL,
17157 	},
17158 };
17159 
17160 /* *** show fec mode per port configuration *** */
17161 struct cmd_show_fec_metadata_result {
17162 	cmdline_fixed_string_t cmd_show;
17163 	cmdline_fixed_string_t cmd_port;
17164 	cmdline_fixed_string_t cmd_keyword;
17165 	portid_t cmd_pid;
17166 };
17167 
17168 static void
17169 cmd_show_fec_mode_parsed(void *parsed_result,
17170 		__rte_unused struct cmdline *cl,
17171 		__rte_unused void *data)
17172 {
17173 #define FEC_NAME_SIZE 16
17174 	struct cmd_show_fec_metadata_result *res = parsed_result;
17175 	uint32_t mode;
17176 	char buf[FEC_NAME_SIZE];
17177 	int ret;
17178 
17179 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17180 		fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17181 		return;
17182 	}
17183 	ret = rte_eth_fec_get(res->cmd_pid, &mode);
17184 	if (ret == -ENOTSUP) {
17185 		fprintf(stderr, "Function not implemented\n");
17186 		return;
17187 	} else if (ret < 0) {
17188 		fprintf(stderr, "Get FEC mode failed\n");
17189 		return;
17190 	}
17191 
17192 	switch (mode) {
17193 	case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
17194 		strlcpy(buf, "off", sizeof(buf));
17195 		break;
17196 	case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
17197 		strlcpy(buf, "auto", sizeof(buf));
17198 		break;
17199 	case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
17200 		strlcpy(buf, "baser", sizeof(buf));
17201 		break;
17202 	case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
17203 		strlcpy(buf, "rs", sizeof(buf));
17204 		break;
17205 	default:
17206 		return;
17207 	}
17208 
17209 	printf("%s\n", buf);
17210 }
17211 
17212 cmdline_parse_token_string_t cmd_show_fec_mode_show =
17213 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17214 			cmd_show, "show");
17215 cmdline_parse_token_string_t cmd_show_fec_mode_port =
17216 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17217 			cmd_port, "port");
17218 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
17219 	TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
17220 			cmd_pid, RTE_UINT16);
17221 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
17222 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17223 			cmd_keyword, "fec_mode");
17224 
17225 cmdline_parse_inst_t cmd_show_fec_mode = {
17226 	.f = cmd_show_fec_mode_parsed,
17227 	.data = NULL,
17228 	.help_str = "show port <port_id> fec_mode",
17229 	.tokens = {
17230 		(void *)&cmd_show_fec_mode_show,
17231 		(void *)&cmd_show_fec_mode_port,
17232 		(void *)&cmd_show_fec_mode_pid,
17233 		(void *)&cmd_show_fec_mode_keyword,
17234 		NULL,
17235 	},
17236 };
17237 
17238 /* *** set fec mode per port configuration *** */
17239 struct cmd_set_port_fec_mode {
17240 	cmdline_fixed_string_t set;
17241 	cmdline_fixed_string_t port;
17242 	portid_t port_id;
17243 	cmdline_fixed_string_t fec_mode;
17244 	cmdline_fixed_string_t fec_value;
17245 };
17246 
17247 /* Common CLI fields for set fec mode */
17248 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
17249 	TOKEN_STRING_INITIALIZER
17250 		(struct cmd_set_port_fec_mode,
17251 		 set, "set");
17252 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
17253 	TOKEN_STRING_INITIALIZER
17254 		(struct cmd_set_port_fec_mode,
17255 		 port, "port");
17256 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
17257 	TOKEN_NUM_INITIALIZER
17258 		(struct cmd_set_port_fec_mode,
17259 		 port_id, RTE_UINT16);
17260 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
17261 	TOKEN_STRING_INITIALIZER
17262 		(struct cmd_set_port_fec_mode,
17263 		 fec_mode, "fec_mode");
17264 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
17265 	TOKEN_STRING_INITIALIZER
17266 		(struct cmd_set_port_fec_mode,
17267 		 fec_value, NULL);
17268 
17269 static void
17270 cmd_set_port_fec_mode_parsed(
17271 	void *parsed_result,
17272 	__rte_unused struct cmdline *cl,
17273 	__rte_unused void *data)
17274 {
17275 	struct cmd_set_port_fec_mode *res = parsed_result;
17276 	uint16_t port_id = res->port_id;
17277 	uint32_t fec_capa;
17278 	int ret;
17279 
17280 	ret = parse_fec_mode(res->fec_value, &fec_capa);
17281 	if (ret < 0) {
17282 		fprintf(stderr, "Unknown fec mode: %s for port %d\n",
17283 				res->fec_value,	port_id);
17284 		return;
17285 	}
17286 
17287 	ret = rte_eth_fec_set(port_id, fec_capa);
17288 	if (ret == -ENOTSUP) {
17289 		fprintf(stderr, "Function not implemented\n");
17290 		return;
17291 	} else if (ret < 0) {
17292 		fprintf(stderr, "Set FEC mode failed\n");
17293 		return;
17294 	}
17295 }
17296 
17297 cmdline_parse_inst_t cmd_set_fec_mode = {
17298 	.f = cmd_set_port_fec_mode_parsed,
17299 	.data = NULL,
17300 	.help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17301 	.tokens = {
17302 		(void *)&cmd_set_port_fec_mode_set,
17303 		(void *)&cmd_set_port_fec_mode_port,
17304 		(void *)&cmd_set_port_fec_mode_port_id,
17305 		(void *)&cmd_set_port_fec_mode_str,
17306 		(void *)&cmd_set_port_fec_mode_value,
17307 		NULL,
17308 	},
17309 };
17310 
17311 /* show port supported ptypes */
17312 
17313 /* Common result structure for show port ptypes */
17314 struct cmd_show_port_supported_ptypes_result {
17315 	cmdline_fixed_string_t show;
17316 	cmdline_fixed_string_t port;
17317 	portid_t port_id;
17318 	cmdline_fixed_string_t ptypes;
17319 };
17320 
17321 /* Common CLI fields for show port ptypes */
17322 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17323 	TOKEN_STRING_INITIALIZER
17324 		(struct cmd_show_port_supported_ptypes_result,
17325 		 show, "show");
17326 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17327 	TOKEN_STRING_INITIALIZER
17328 		(struct cmd_show_port_supported_ptypes_result,
17329 		 port, "port");
17330 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17331 	TOKEN_NUM_INITIALIZER
17332 		(struct cmd_show_port_supported_ptypes_result,
17333 		 port_id, RTE_UINT16);
17334 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17335 	TOKEN_STRING_INITIALIZER
17336 		(struct cmd_show_port_supported_ptypes_result,
17337 		 ptypes, "ptypes");
17338 
17339 static void
17340 cmd_show_port_supported_ptypes_parsed(
17341 	void *parsed_result,
17342 	__rte_unused struct cmdline *cl,
17343 	__rte_unused void *data)
17344 {
17345 #define RSVD_PTYPE_MASK       0xf0000000
17346 #define MAX_PTYPES_PER_LAYER  16
17347 #define LTYPE_NAMESIZE        32
17348 #define PTYPE_NAMESIZE        256
17349 	struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17350 	char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17351 	uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17352 	uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17353 	uint16_t port_id = res->port_id;
17354 	int ret, i;
17355 
17356 	ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17357 	if (ret < 0)
17358 		return;
17359 
17360 	while (ptype_mask != RSVD_PTYPE_MASK) {
17361 
17362 		switch (ptype_mask) {
17363 		case RTE_PTYPE_L2_MASK:
17364 			strlcpy(ltype, "L2", sizeof(ltype));
17365 			break;
17366 		case RTE_PTYPE_L3_MASK:
17367 			strlcpy(ltype, "L3", sizeof(ltype));
17368 			break;
17369 		case RTE_PTYPE_L4_MASK:
17370 			strlcpy(ltype, "L4", sizeof(ltype));
17371 			break;
17372 		case RTE_PTYPE_TUNNEL_MASK:
17373 			strlcpy(ltype, "Tunnel", sizeof(ltype));
17374 			break;
17375 		case RTE_PTYPE_INNER_L2_MASK:
17376 			strlcpy(ltype, "Inner L2", sizeof(ltype));
17377 			break;
17378 		case RTE_PTYPE_INNER_L3_MASK:
17379 			strlcpy(ltype, "Inner L3", sizeof(ltype));
17380 			break;
17381 		case RTE_PTYPE_INNER_L4_MASK:
17382 			strlcpy(ltype, "Inner L4", sizeof(ltype));
17383 			break;
17384 		default:
17385 			return;
17386 		}
17387 
17388 		ret = rte_eth_dev_get_supported_ptypes(res->port_id,
17389 						       ptype_mask, ptypes,
17390 						       MAX_PTYPES_PER_LAYER);
17391 
17392 		if (ret > 0)
17393 			printf("Supported %s ptypes:\n", ltype);
17394 		else
17395 			printf("%s ptypes unsupported\n", ltype);
17396 
17397 		for (i = 0; i < ret; ++i) {
17398 			rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
17399 			printf("%s\n", buf);
17400 		}
17401 
17402 		ptype_mask <<= 4;
17403 	}
17404 }
17405 
17406 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
17407 	.f = cmd_show_port_supported_ptypes_parsed,
17408 	.data = NULL,
17409 	.help_str = "show port <port_id> ptypes",
17410 	.tokens = {
17411 		(void *)&cmd_show_port_supported_ptypes_show,
17412 		(void *)&cmd_show_port_supported_ptypes_port,
17413 		(void *)&cmd_show_port_supported_ptypes_port_id,
17414 		(void *)&cmd_show_port_supported_ptypes_ptypes,
17415 		NULL,
17416 	},
17417 };
17418 
17419 /* *** display rx/tx descriptor status *** */
17420 struct cmd_show_rx_tx_desc_status_result {
17421 	cmdline_fixed_string_t cmd_show;
17422 	cmdline_fixed_string_t cmd_port;
17423 	cmdline_fixed_string_t cmd_keyword;
17424 	cmdline_fixed_string_t cmd_desc;
17425 	cmdline_fixed_string_t cmd_status;
17426 	portid_t cmd_pid;
17427 	portid_t cmd_qid;
17428 	portid_t cmd_did;
17429 };
17430 
17431 static void
17432 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17433 		__rte_unused struct cmdline *cl,
17434 		__rte_unused void *data)
17435 {
17436 	struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17437 	int rc;
17438 
17439 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17440 		fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17441 		return;
17442 	}
17443 
17444 	if (!strcmp(res->cmd_keyword, "rxq")) {
17445 		rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17446 					     res->cmd_did);
17447 		if (rc < 0) {
17448 			fprintf(stderr,
17449 				"Invalid input: queue id = %d, desc id = %d\n",
17450 				res->cmd_qid, res->cmd_did);
17451 			return;
17452 		}
17453 		if (rc == RTE_ETH_RX_DESC_AVAIL)
17454 			printf("Desc status = AVAILABLE\n");
17455 		else if (rc == RTE_ETH_RX_DESC_DONE)
17456 			printf("Desc status = DONE\n");
17457 		else
17458 			printf("Desc status = UNAVAILABLE\n");
17459 	} else if (!strcmp(res->cmd_keyword, "txq")) {
17460 		rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17461 					     res->cmd_did);
17462 		if (rc < 0) {
17463 			fprintf(stderr,
17464 				"Invalid input: queue id = %d, desc id = %d\n",
17465 				res->cmd_qid, res->cmd_did);
17466 			return;
17467 		}
17468 		if (rc == RTE_ETH_TX_DESC_FULL)
17469 			printf("Desc status = FULL\n");
17470 		else if (rc == RTE_ETH_TX_DESC_DONE)
17471 			printf("Desc status = DONE\n");
17472 		else
17473 			printf("Desc status = UNAVAILABLE\n");
17474 	}
17475 }
17476 
17477 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17478 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17479 			cmd_show, "show");
17480 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17481 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17482 			cmd_port, "port");
17483 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17484 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17485 			cmd_pid, RTE_UINT16);
17486 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17487 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17488 			cmd_keyword, "rxq#txq");
17489 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17490 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17491 			cmd_qid, RTE_UINT16);
17492 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17493 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17494 			cmd_desc, "desc");
17495 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17496 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17497 			cmd_did, RTE_UINT16);
17498 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17499 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17500 			cmd_status, "status");
17501 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17502 	.f = cmd_show_rx_tx_desc_status_parsed,
17503 	.data = NULL,
17504 	.help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17505 		"status",
17506 	.tokens = {
17507 		(void *)&cmd_show_rx_tx_desc_status_show,
17508 		(void *)&cmd_show_rx_tx_desc_status_port,
17509 		(void *)&cmd_show_rx_tx_desc_status_pid,
17510 		(void *)&cmd_show_rx_tx_desc_status_keyword,
17511 		(void *)&cmd_show_rx_tx_desc_status_qid,
17512 		(void *)&cmd_show_rx_tx_desc_status_desc,
17513 		(void *)&cmd_show_rx_tx_desc_status_did,
17514 		(void *)&cmd_show_rx_tx_desc_status_status,
17515 		NULL,
17516 	},
17517 };
17518 
17519 /* *** display rx queue desc used count *** */
17520 struct cmd_show_rx_queue_desc_used_count_result {
17521 	cmdline_fixed_string_t cmd_show;
17522 	cmdline_fixed_string_t cmd_port;
17523 	cmdline_fixed_string_t cmd_rxq;
17524 	cmdline_fixed_string_t cmd_desc;
17525 	cmdline_fixed_string_t cmd_used;
17526 	cmdline_fixed_string_t cmd_count;
17527 	portid_t cmd_pid;
17528 	portid_t cmd_qid;
17529 };
17530 
17531 static void
17532 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
17533 		__rte_unused struct cmdline *cl,
17534 		__rte_unused void *data)
17535 {
17536 	struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
17537 	int rc;
17538 
17539 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17540 		fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17541 		return;
17542 	}
17543 
17544 	rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
17545 	if (rc < 0) {
17546 		fprintf(stderr, "Invalid queueid = %d\n", res->cmd_qid);
17547 		return;
17548 	}
17549 	printf("Used desc count = %d\n", rc);
17550 }
17551 
17552 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
17553 	TOKEN_STRING_INITIALIZER
17554 		(struct cmd_show_rx_queue_desc_used_count_result,
17555 		 cmd_show, "show");
17556 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
17557 	TOKEN_STRING_INITIALIZER
17558 		(struct cmd_show_rx_queue_desc_used_count_result,
17559 		 cmd_port, "port");
17560 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
17561 	TOKEN_NUM_INITIALIZER
17562 		(struct cmd_show_rx_queue_desc_used_count_result,
17563 		 cmd_pid, RTE_UINT16);
17564 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
17565 	TOKEN_STRING_INITIALIZER
17566 		(struct cmd_show_rx_queue_desc_used_count_result,
17567 		 cmd_rxq, "rxq");
17568 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
17569 	TOKEN_NUM_INITIALIZER
17570 		(struct cmd_show_rx_queue_desc_used_count_result,
17571 		 cmd_qid, RTE_UINT16);
17572 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
17573 	TOKEN_STRING_INITIALIZER
17574 		(struct cmd_show_rx_queue_desc_used_count_result,
17575 		 cmd_count, "desc");
17576 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
17577 	TOKEN_STRING_INITIALIZER
17578 		(struct cmd_show_rx_queue_desc_used_count_result,
17579 		 cmd_count, "used");
17580 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
17581 	TOKEN_STRING_INITIALIZER
17582 		(struct cmd_show_rx_queue_desc_used_count_result,
17583 		 cmd_count, "count");
17584 cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
17585 	.f = cmd_show_rx_queue_desc_used_count_parsed,
17586 	.data = NULL,
17587 	.help_str = "show port <port_id> rxq <queue_id> desc used count",
17588 	.tokens = {
17589 		(void *)&cmd_show_rx_queue_desc_used_count_show,
17590 		(void *)&cmd_show_rx_queue_desc_used_count_port,
17591 		(void *)&cmd_show_rx_queue_desc_used_count_pid,
17592 		(void *)&cmd_show_rx_queue_desc_used_count_rxq,
17593 		(void *)&cmd_show_rx_queue_desc_used_count_qid,
17594 		(void *)&cmd_show_rx_queue_desc_used_count_desc,
17595 		(void *)&cmd_show_rx_queue_desc_used_count_used,
17596 		(void *)&cmd_show_rx_queue_desc_used_count_count,
17597 		NULL,
17598 	},
17599 };
17600 
17601 /* Common result structure for set port ptypes */
17602 struct cmd_set_port_ptypes_result {
17603 	cmdline_fixed_string_t set;
17604 	cmdline_fixed_string_t port;
17605 	portid_t port_id;
17606 	cmdline_fixed_string_t ptype_mask;
17607 	uint32_t mask;
17608 };
17609 
17610 /* Common CLI fields for set port ptypes */
17611 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17612 	TOKEN_STRING_INITIALIZER
17613 		(struct cmd_set_port_ptypes_result,
17614 		 set, "set");
17615 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17616 	TOKEN_STRING_INITIALIZER
17617 		(struct cmd_set_port_ptypes_result,
17618 		 port, "port");
17619 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17620 	TOKEN_NUM_INITIALIZER
17621 		(struct cmd_set_port_ptypes_result,
17622 		 port_id, RTE_UINT16);
17623 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17624 	TOKEN_STRING_INITIALIZER
17625 		(struct cmd_set_port_ptypes_result,
17626 		 ptype_mask, "ptype_mask");
17627 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17628 	TOKEN_NUM_INITIALIZER
17629 		(struct cmd_set_port_ptypes_result,
17630 		 mask, RTE_UINT32);
17631 
17632 static void
17633 cmd_set_port_ptypes_parsed(
17634 	void *parsed_result,
17635 	__rte_unused struct cmdline *cl,
17636 	__rte_unused void *data)
17637 {
17638 	struct cmd_set_port_ptypes_result *res = parsed_result;
17639 #define PTYPE_NAMESIZE        256
17640 	char ptype_name[PTYPE_NAMESIZE];
17641 	uint16_t port_id = res->port_id;
17642 	uint32_t ptype_mask = res->mask;
17643 	int ret, i;
17644 
17645 	ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17646 					       NULL, 0);
17647 	if (ret <= 0) {
17648 		fprintf(stderr, "Port %d doesn't support any ptypes.\n",
17649 			port_id);
17650 		return;
17651 	}
17652 
17653 	uint32_t ptypes[ret];
17654 
17655 	ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17656 	if (ret < 0) {
17657 		fprintf(stderr, "Unable to set requested ptypes for Port %d\n",
17658 			port_id);
17659 		return;
17660 	}
17661 
17662 	printf("Successfully set following ptypes for Port %d\n", port_id);
17663 	for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17664 		rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17665 		printf("%s\n", ptype_name);
17666 	}
17667 
17668 	clear_ptypes = false;
17669 }
17670 
17671 cmdline_parse_inst_t cmd_set_port_ptypes = {
17672 	.f = cmd_set_port_ptypes_parsed,
17673 	.data = NULL,
17674 	.help_str = "set port <port_id> ptype_mask <mask>",
17675 	.tokens = {
17676 		(void *)&cmd_set_port_ptypes_set,
17677 		(void *)&cmd_set_port_ptypes_port,
17678 		(void *)&cmd_set_port_ptypes_port_id,
17679 		(void *)&cmd_set_port_ptypes_mask_str,
17680 		(void *)&cmd_set_port_ptypes_mask_u32,
17681 		NULL,
17682 	},
17683 };
17684 
17685 /* *** display mac addresses added to a port *** */
17686 struct cmd_showport_macs_result {
17687 	cmdline_fixed_string_t cmd_show;
17688 	cmdline_fixed_string_t cmd_port;
17689 	cmdline_fixed_string_t cmd_keyword;
17690 	portid_t cmd_pid;
17691 };
17692 
17693 static void
17694 cmd_showport_macs_parsed(void *parsed_result,
17695 		__rte_unused struct cmdline *cl,
17696 		__rte_unused void *data)
17697 {
17698 	struct cmd_showport_macs_result *res = parsed_result;
17699 
17700 	if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17701 		return;
17702 
17703 	if (!strcmp(res->cmd_keyword, "macs"))
17704 		show_macs(res->cmd_pid);
17705 	else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17706 		show_mcast_macs(res->cmd_pid);
17707 }
17708 
17709 cmdline_parse_token_string_t cmd_showport_macs_show =
17710 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17711 			cmd_show, "show");
17712 cmdline_parse_token_string_t cmd_showport_macs_port =
17713 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17714 			cmd_port, "port");
17715 cmdline_parse_token_num_t cmd_showport_macs_pid =
17716 	TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17717 			cmd_pid, RTE_UINT16);
17718 cmdline_parse_token_string_t cmd_showport_macs_keyword =
17719 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17720 			cmd_keyword, "macs#mcast_macs");
17721 
17722 cmdline_parse_inst_t cmd_showport_macs = {
17723 	.f = cmd_showport_macs_parsed,
17724 	.data = NULL,
17725 	.help_str = "show port <port_id> macs|mcast_macs",
17726 	.tokens = {
17727 		(void *)&cmd_showport_macs_show,
17728 		(void *)&cmd_showport_macs_port,
17729 		(void *)&cmd_showport_macs_pid,
17730 		(void *)&cmd_showport_macs_keyword,
17731 		NULL,
17732 	},
17733 };
17734 
17735 /* *** show flow transfer proxy port ID for the given port *** */
17736 struct cmd_show_port_flow_transfer_proxy_result {
17737 	cmdline_fixed_string_t show;
17738 	cmdline_fixed_string_t port;
17739 	portid_t port_id;
17740 	cmdline_fixed_string_t flow;
17741 	cmdline_fixed_string_t transfer;
17742 	cmdline_fixed_string_t proxy;
17743 };
17744 
17745 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_show =
17746 	TOKEN_STRING_INITIALIZER
17747 		(struct cmd_show_port_flow_transfer_proxy_result,
17748 		 show, "show");
17749 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_port =
17750 	TOKEN_STRING_INITIALIZER
17751 		(struct cmd_show_port_flow_transfer_proxy_result,
17752 		 port, "port");
17753 cmdline_parse_token_num_t cmd_show_port_flow_transfer_proxy_port_id =
17754 	TOKEN_NUM_INITIALIZER
17755 		(struct cmd_show_port_flow_transfer_proxy_result,
17756 		 port_id, RTE_UINT16);
17757 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_flow =
17758 	TOKEN_STRING_INITIALIZER
17759 		(struct cmd_show_port_flow_transfer_proxy_result,
17760 		 flow, "flow");
17761 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_transfer =
17762 	TOKEN_STRING_INITIALIZER
17763 		(struct cmd_show_port_flow_transfer_proxy_result,
17764 		 transfer, "transfer");
17765 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_proxy =
17766 	TOKEN_STRING_INITIALIZER
17767 		(struct cmd_show_port_flow_transfer_proxy_result,
17768 		 proxy, "proxy");
17769 
17770 static void
17771 cmd_show_port_flow_transfer_proxy_parsed(void *parsed_result,
17772 					 __rte_unused struct cmdline *cl,
17773 					 __rte_unused void *data)
17774 {
17775 	struct cmd_show_port_flow_transfer_proxy_result *res = parsed_result;
17776 	portid_t proxy_port_id;
17777 	int ret;
17778 
17779 	printf("\n");
17780 
17781 	ret = rte_flow_pick_transfer_proxy(res->port_id, &proxy_port_id, NULL);
17782 	if (ret != 0) {
17783 		fprintf(stderr, "Failed to pick transfer proxy: %s\n",
17784 			rte_strerror(-ret));
17785 		return;
17786 	}
17787 
17788 	printf("Transfer proxy port ID: %u\n\n", proxy_port_id);
17789 }
17790 
17791 cmdline_parse_inst_t cmd_show_port_flow_transfer_proxy = {
17792 	.f = cmd_show_port_flow_transfer_proxy_parsed,
17793 	.data = NULL,
17794 	.help_str = "show port <port_id> flow transfer proxy",
17795 	.tokens = {
17796 		(void *)&cmd_show_port_flow_transfer_proxy_show,
17797 		(void *)&cmd_show_port_flow_transfer_proxy_port,
17798 		(void *)&cmd_show_port_flow_transfer_proxy_port_id,
17799 		(void *)&cmd_show_port_flow_transfer_proxy_flow,
17800 		(void *)&cmd_show_port_flow_transfer_proxy_transfer,
17801 		(void *)&cmd_show_port_flow_transfer_proxy_proxy,
17802 		NULL,
17803 	}
17804 };
17805 
17806 /* ******************************************************************************** */
17807 
17808 /* list of instructions */
17809 cmdline_parse_ctx_t main_ctx[] = {
17810 	(cmdline_parse_inst_t *)&cmd_help_brief,
17811 	(cmdline_parse_inst_t *)&cmd_help_long,
17812 	(cmdline_parse_inst_t *)&cmd_quit,
17813 	(cmdline_parse_inst_t *)&cmd_load_from_file,
17814 	(cmdline_parse_inst_t *)&cmd_showport,
17815 	(cmdline_parse_inst_t *)&cmd_showqueue,
17816 	(cmdline_parse_inst_t *)&cmd_showeeprom,
17817 	(cmdline_parse_inst_t *)&cmd_showportall,
17818 	(cmdline_parse_inst_t *)&cmd_representor_info,
17819 	(cmdline_parse_inst_t *)&cmd_showdevice,
17820 	(cmdline_parse_inst_t *)&cmd_showcfg,
17821 	(cmdline_parse_inst_t *)&cmd_showfwdall,
17822 	(cmdline_parse_inst_t *)&cmd_start,
17823 	(cmdline_parse_inst_t *)&cmd_start_tx_first,
17824 	(cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17825 	(cmdline_parse_inst_t *)&cmd_set_link_up,
17826 	(cmdline_parse_inst_t *)&cmd_set_link_down,
17827 	(cmdline_parse_inst_t *)&cmd_reset,
17828 	(cmdline_parse_inst_t *)&cmd_set_numbers,
17829 	(cmdline_parse_inst_t *)&cmd_set_log,
17830 	(cmdline_parse_inst_t *)&cmd_set_rxoffs,
17831 	(cmdline_parse_inst_t *)&cmd_set_rxpkts,
17832 	(cmdline_parse_inst_t *)&cmd_set_txpkts,
17833 	(cmdline_parse_inst_t *)&cmd_set_txsplit,
17834 	(cmdline_parse_inst_t *)&cmd_set_txtimes,
17835 	(cmdline_parse_inst_t *)&cmd_set_fwd_list,
17836 	(cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17837 	(cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17838 	(cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17839 	(cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17840 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17841 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17842 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17843 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17844 	(cmdline_parse_inst_t *)&cmd_set_flush_rx,
17845 	(cmdline_parse_inst_t *)&cmd_set_link_check,
17846 	(cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17847 	(cmdline_parse_inst_t *)&cmd_set_bypass_event,
17848 	(cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17849 	(cmdline_parse_inst_t *)&cmd_show_bypass_config,
17850 #ifdef RTE_NET_BOND
17851 	(cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17852 	(cmdline_parse_inst_t *) &cmd_show_bonding_config,
17853 	(cmdline_parse_inst_t *) &cmd_show_bonding_lacp_info,
17854 	(cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17855 	(cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17856 	(cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17857 	(cmdline_parse_inst_t *) &cmd_create_bonded_device,
17858 	(cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17859 	(cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17860 	(cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17861 	(cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17862 	(cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17863 #endif
17864 	(cmdline_parse_inst_t *)&cmd_vlan_offload,
17865 	(cmdline_parse_inst_t *)&cmd_vlan_tpid,
17866 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17867 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17868 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17869 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17870 	(cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17871 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17872 	(cmdline_parse_inst_t *)&cmd_csum_set,
17873 	(cmdline_parse_inst_t *)&cmd_csum_show,
17874 	(cmdline_parse_inst_t *)&cmd_csum_tunnel,
17875 	(cmdline_parse_inst_t *)&cmd_tso_set,
17876 	(cmdline_parse_inst_t *)&cmd_tso_show,
17877 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17878 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17879 #ifdef RTE_LIB_GRO
17880 	(cmdline_parse_inst_t *)&cmd_gro_enable,
17881 	(cmdline_parse_inst_t *)&cmd_gro_flush,
17882 	(cmdline_parse_inst_t *)&cmd_gro_show,
17883 #endif
17884 #ifdef RTE_LIB_GSO
17885 	(cmdline_parse_inst_t *)&cmd_gso_enable,
17886 	(cmdline_parse_inst_t *)&cmd_gso_size,
17887 	(cmdline_parse_inst_t *)&cmd_gso_show,
17888 #endif
17889 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17890 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17891 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17892 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17893 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17894 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17895 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17896 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17897 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17898 	(cmdline_parse_inst_t *)&cmd_link_flow_control_show,
17899 	(cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17900 	(cmdline_parse_inst_t *)&cmd_queue_priority_flow_control_set,
17901 	(cmdline_parse_inst_t *)&cmd_config_dcb,
17902 	(cmdline_parse_inst_t *)&cmd_read_reg,
17903 	(cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17904 	(cmdline_parse_inst_t *)&cmd_read_reg_bit,
17905 	(cmdline_parse_inst_t *)&cmd_write_reg,
17906 	(cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17907 	(cmdline_parse_inst_t *)&cmd_write_reg_bit,
17908 	(cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17909 	(cmdline_parse_inst_t *)&cmd_stop,
17910 	(cmdline_parse_inst_t *)&cmd_mac_addr,
17911 	(cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17912 	(cmdline_parse_inst_t *)&cmd_set_qmap,
17913 	(cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17914 	(cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17915 	(cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17916 	(cmdline_parse_inst_t *)&cmd_operate_port,
17917 	(cmdline_parse_inst_t *)&cmd_operate_specific_port,
17918 	(cmdline_parse_inst_t *)&cmd_operate_attach_port,
17919 	(cmdline_parse_inst_t *)&cmd_operate_detach_port,
17920 	(cmdline_parse_inst_t *)&cmd_operate_detach_device,
17921 	(cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17922 	(cmdline_parse_inst_t *)&cmd_config_speed_all,
17923 	(cmdline_parse_inst_t *)&cmd_config_speed_specific,
17924 	(cmdline_parse_inst_t *)&cmd_config_loopback_all,
17925 	(cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17926 	(cmdline_parse_inst_t *)&cmd_config_rx_tx,
17927 	(cmdline_parse_inst_t *)&cmd_config_mtu,
17928 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17929 	(cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17930 	(cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17931 	(cmdline_parse_inst_t *)&cmd_config_rss,
17932 	(cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17933 	(cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17934 	(cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17935 	(cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17936 	(cmdline_parse_inst_t *)&cmd_config_rss_reta,
17937 	(cmdline_parse_inst_t *)&cmd_showport_reta,
17938 	(cmdline_parse_inst_t *)&cmd_showport_macs,
17939 	(cmdline_parse_inst_t *)&cmd_show_port_flow_transfer_proxy,
17940 	(cmdline_parse_inst_t *)&cmd_config_burst,
17941 	(cmdline_parse_inst_t *)&cmd_config_thresh,
17942 	(cmdline_parse_inst_t *)&cmd_config_threshold,
17943 	(cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17944 	(cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17945 	(cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17946 	(cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17947 	(cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17948 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17949 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17950 	(cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17951 	(cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs,
17952 	(cmdline_parse_inst_t *)&cmd_dump,
17953 	(cmdline_parse_inst_t *)&cmd_dump_one,
17954 #ifdef RTE_NET_I40E
17955 	(cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17956 #endif
17957 	(cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17958 	(cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17959 	(cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17960 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17961 	(cmdline_parse_inst_t *)&cmd_flow,
17962 	(cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17963 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17964 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17965 	(cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17966 	(cmdline_parse_inst_t *)&cmd_create_port_meter,
17967 	(cmdline_parse_inst_t *)&cmd_enable_port_meter,
17968 	(cmdline_parse_inst_t *)&cmd_disable_port_meter,
17969 	(cmdline_parse_inst_t *)&cmd_del_port_meter,
17970 	(cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
17971 	(cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17972 	(cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17973 	(cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17974 	(cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17975 	(cmdline_parse_inst_t *)&cmd_mcast_addr,
17976 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17977 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17978 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17979 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17980 	(cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17981 	(cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17982 	(cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17983 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17984 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17985 	(cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17986 	(cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17987 	(cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17988 	(cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17989 	(cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17990 	(cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17991 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17992 	(cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17993 	(cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17994 	(cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17995 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17996 	(cmdline_parse_inst_t *)&cmd_vf_max_bw,
17997 	(cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17998 	(cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17999 	(cmdline_parse_inst_t *)&cmd_strict_link_prio,
18000 	(cmdline_parse_inst_t *)&cmd_tc_min_bw,
18001 	(cmdline_parse_inst_t *)&cmd_set_vxlan,
18002 	(cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18003 	(cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18004 	(cmdline_parse_inst_t *)&cmd_set_nvgre,
18005 	(cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18006 	(cmdline_parse_inst_t *)&cmd_set_l2_encap,
18007 	(cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18008 	(cmdline_parse_inst_t *)&cmd_set_l2_decap,
18009 	(cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18010 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18011 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18012 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18013 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18014 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18015 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18016 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18017 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18018 	(cmdline_parse_inst_t *)&cmd_set_conntrack_common,
18019 	(cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
18020 	(cmdline_parse_inst_t *)&cmd_ddp_add,
18021 	(cmdline_parse_inst_t *)&cmd_ddp_del,
18022 	(cmdline_parse_inst_t *)&cmd_ddp_get_list,
18023 	(cmdline_parse_inst_t *)&cmd_ddp_get_info,
18024 	(cmdline_parse_inst_t *)&cmd_cfg_input_set,
18025 	(cmdline_parse_inst_t *)&cmd_clear_input_set,
18026 	(cmdline_parse_inst_t *)&cmd_show_vf_stats,
18027 	(cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18028 	(cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
18029 	(cmdline_parse_inst_t *)&cmd_set_port_ptypes,
18030 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18031 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18032 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18033 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18034 
18035 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18036 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18037 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18038 	(cmdline_parse_inst_t *)&cmd_queue_region,
18039 	(cmdline_parse_inst_t *)&cmd_region_flowtype,
18040 	(cmdline_parse_inst_t *)&cmd_user_priority_region,
18041 	(cmdline_parse_inst_t *)&cmd_flush_queue_region,
18042 	(cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18043 	(cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18044 	(cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18045 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18046 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18047 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18048 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18049 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18050 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18051 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18052 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18053 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18054 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18055 	(cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18056 	(cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
18057 	(cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18058 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18059 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18060 	(cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18061 	(cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18062 	(cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18063 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18064 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18065 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18066 	(cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18067 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18068 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18069 	(cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18070 	(cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18071 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18072 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18073 	(cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18074 	(cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18075 #ifdef RTE_LIB_BPF
18076 	(cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18077 	(cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18078 #endif
18079 	(cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18080 	(cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18081 	(cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
18082 	(cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
18083 	(cmdline_parse_inst_t *)&cmd_set_raw,
18084 	(cmdline_parse_inst_t *)&cmd_show_set_raw,
18085 	(cmdline_parse_inst_t *)&cmd_show_set_raw_all,
18086 	(cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
18087 	(cmdline_parse_inst_t *)&cmd_show_fec_mode,
18088 	(cmdline_parse_inst_t *)&cmd_set_fec_mode,
18089 	(cmdline_parse_inst_t *)&cmd_show_capability,
18090 	(cmdline_parse_inst_t *)&cmd_set_flex_is_pattern,
18091 	(cmdline_parse_inst_t *)&cmd_set_flex_spec_pattern,
18092 	NULL,
18093 };
18094 
18095 /* read cmdline commands from file */
18096 void
18097 cmdline_read_from_file(const char *filename)
18098 {
18099 	struct cmdline *cl;
18100 
18101 	cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18102 	if (cl == NULL) {
18103 		fprintf(stderr,
18104 			"Failed to create file based cmdline context: %s\n",
18105 			filename);
18106 		return;
18107 	}
18108 
18109 	cmdline_interact(cl);
18110 	cmdline_quit(cl);
18111 
18112 	cmdline_free(cl);
18113 
18114 	printf("Read CLI commands from %s\n", filename);
18115 }
18116 
18117 /* prompt function, called from main on MAIN lcore */
18118 void
18119 prompt(void)
18120 {
18121 	int ret;
18122 	/* initialize non-constant commands */
18123 	cmd_set_fwd_mode_init();
18124 	cmd_set_fwd_retry_mode_init();
18125 
18126 	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18127 	if (testpmd_cl == NULL)
18128 		return;
18129 
18130 	ret = atexit(prompt_exit);
18131 	if (ret != 0)
18132 		fprintf(stderr, "Cannot set exit function for cmdline\n");
18133 
18134 	cmdline_interact(testpmd_cl);
18135 	if (ret != 0)
18136 		cmdline_stdin_exit(testpmd_cl);
18137 }
18138 
18139 void
18140 prompt_exit(void)
18141 {
18142 	if (testpmd_cl != NULL) {
18143 		cmdline_quit(testpmd_cl);
18144 		cmdline_stdin_exit(testpmd_cl);
18145 	}
18146 }
18147 
18148 static void
18149 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18150 {
18151 	if (id == (portid_t)RTE_PORT_ALL) {
18152 		portid_t pid;
18153 
18154 		RTE_ETH_FOREACH_DEV(pid) {
18155 			/* check if need_reconfig has been set to 1 */
18156 			if (ports[pid].need_reconfig == 0)
18157 				ports[pid].need_reconfig = dev;
18158 			/* check if need_reconfig_queues has been set to 1 */
18159 			if (ports[pid].need_reconfig_queues == 0)
18160 				ports[pid].need_reconfig_queues = queue;
18161 		}
18162 	} else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18163 		/* check if need_reconfig has been set to 1 */
18164 		if (ports[id].need_reconfig == 0)
18165 			ports[id].need_reconfig = dev;
18166 		/* check if need_reconfig_queues has been set to 1 */
18167 		if (ports[id].need_reconfig_queues == 0)
18168 			ports[id].need_reconfig_queues = queue;
18169 	}
18170 }
18171