xref: /dpdk/app/test-pmd/cmdline.c (revision e0a43946)
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 <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16 
17 #include <sys/queue.h>
18 
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44 
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_LIBRTE_PMD_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_LIBRTE_IXGBE_PMD
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_LIBRTE_I40E_PMD
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_LIBRTE_BNXT_PMD
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73 
74 static struct cmdline *testpmd_cl;
75 
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77 
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80 	cmdline_fixed_string_t help;
81 };
82 
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87 	cmdline_printf(
88 		cl,
89 		"\n"
90 		"Help is available for the following sections:\n\n"
91 		"    help control                    : Start and stop forwarding.\n"
92 		"    help display                    : Displaying port, stats and config "
93 		"information.\n"
94 		"    help config                     : Configuration information.\n"
95 		"    help ports                      : Configuring ports.\n"
96 		"    help registers                  : Reading and setting port registers.\n"
97 		"    help filters                    : Filters configuration help.\n"
98 		"    help traffic_management         : Traffic Management commands.\n"
99 		"    help devices                    : Device related cmds.\n"
100 		"    help all                        : All of the above sections.\n\n"
101 	);
102 
103 }
104 
105 cmdline_parse_token_string_t cmd_help_brief_help =
106 	TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107 
108 cmdline_parse_inst_t cmd_help_brief = {
109 	.f = cmd_help_brief_parsed,
110 	.data = NULL,
111 	.help_str = "help: Show help",
112 	.tokens = {
113 		(void *)&cmd_help_brief_help,
114 		NULL,
115 	},
116 };
117 
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120 	cmdline_fixed_string_t help;
121 	cmdline_fixed_string_t section;
122 };
123 
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __rte_unused void *data)
127 {
128 	int show_all = 0;
129 	struct cmd_help_long_result *res = parsed_result;
130 
131 	if (!strcmp(res->section, "all"))
132 		show_all = 1;
133 
134 	if (show_all || !strcmp(res->section, "control")) {
135 
136 		cmdline_printf(
137 			cl,
138 			"\n"
139 			"Control forwarding:\n"
140 			"-------------------\n\n"
141 
142 			"start\n"
143 			"    Start packet forwarding with current configuration.\n\n"
144 
145 			"start tx_first\n"
146 			"    Start packet forwarding with current config"
147 			" after sending one burst of packets.\n\n"
148 
149 			"stop\n"
150 			"    Stop packet forwarding, and display accumulated"
151 			" statistics.\n\n"
152 
153 			"quit\n"
154 			"    Quit to prompt.\n\n"
155 		);
156 	}
157 
158 	if (show_all || !strcmp(res->section, "display")) {
159 
160 		cmdline_printf(
161 			cl,
162 			"\n"
163 			"Display:\n"
164 			"--------\n\n"
165 
166 			"show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
167 			"    Display information for port_id, or all.\n\n"
168 
169 			"show port X rss reta (size) (mask0,mask1,...)\n"
170 			"    Display the rss redirection table entry indicated"
171 			" by masks on port X. size is used to indicate the"
172 			" hardware supported reta size\n\n"
173 
174 			"show port (port_id) rss-hash [key]\n"
175 			"    Display the RSS hash functions and RSS hash key of port\n\n"
176 
177 			"clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
178 			"    Clear information for port_id, or all.\n\n"
179 
180 			"show (rxq|txq) info (port_id) (queue_id)\n"
181 			"    Display information for configured RX/TX queue.\n\n"
182 
183 			"show config (rxtx|cores|fwd|txpkts)\n"
184 			"    Display the given configuration.\n\n"
185 
186 			"read rxd (port_id) (queue_id) (rxd_id)\n"
187 			"    Display an RX descriptor of a port RX queue.\n\n"
188 
189 			"read txd (port_id) (queue_id) (txd_id)\n"
190 			"    Display a TX descriptor of a port TX queue.\n\n"
191 
192 			"ddp get list (port_id)\n"
193 			"    Get ddp profile info list\n\n"
194 
195 			"ddp get info (profile_path)\n"
196 			"    Get ddp profile information.\n\n"
197 
198 			"show vf stats (port_id) (vf_id)\n"
199 			"    Display a VF's statistics.\n\n"
200 
201 			"clear vf stats (port_id) (vf_id)\n"
202 			"    Reset a VF's statistics.\n\n"
203 
204 			"show port (port_id) pctype mapping\n"
205 			"    Get flow ptype to pctype mapping on a port\n\n"
206 
207 			"show port meter stats (port_id) (meter_id) (clear)\n"
208 			"    Get meter stats on a port\n\n"
209 
210 			"show fwd stats all\n"
211 			"    Display statistics for all fwd engines.\n\n"
212 
213 			"clear fwd stats all\n"
214 			"    Clear statistics for all fwd engines.\n\n"
215 
216 			"show port (port_id) rx_offload capabilities\n"
217 			"    List all per queue and per port Rx offloading"
218 			" capabilities of a port\n\n"
219 
220 			"show port (port_id) rx_offload configuration\n"
221 			"    List port level and all queue level"
222 			" Rx offloading configuration\n\n"
223 
224 			"show port (port_id) tx_offload capabilities\n"
225 			"    List all per queue and per port"
226 			" Tx offloading capabilities of a port\n\n"
227 
228 			"show port (port_id) tx_offload configuration\n"
229 			"    List port level and all queue level"
230 			" Tx offloading configuration\n\n"
231 
232 			"show port (port_id) tx_metadata\n"
233 			"    Show Tx metadata value set"
234 			" for a specific port\n\n"
235 
236 			"show port (port_id) ptypes\n"
237 			"    Show port supported ptypes"
238 			" for a specific port\n\n"
239 
240 			"show device info (<identifier>|all)"
241 			"       Show general information about devices probed.\n\n"
242 
243 			"show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
244 			"       Show status of rx|tx descriptor.\n\n"
245 
246 			"show port (port_id) macs|mcast_macs"
247 			"       Display list of mac addresses added to port.\n\n"
248 		);
249 	}
250 
251 	if (show_all || !strcmp(res->section, "config")) {
252 		cmdline_printf(
253 			cl,
254 			"\n"
255 			"Configuration:\n"
256 			"--------------\n"
257 			"Configuration changes only become active when"
258 			" forwarding is started/restarted.\n\n"
259 
260 			"set default\n"
261 			"    Reset forwarding to the default configuration.\n\n"
262 
263 			"set verbose (level)\n"
264 			"    Set the debug verbosity level X.\n\n"
265 
266 			"set log global|(type) (level)\n"
267 			"    Set the log level.\n\n"
268 
269 			"set nbport (num)\n"
270 			"    Set number of ports.\n\n"
271 
272 			"set nbcore (num)\n"
273 			"    Set number of cores.\n\n"
274 
275 			"set coremask (mask)\n"
276 			"    Set the forwarding cores hexadecimal mask.\n\n"
277 
278 			"set portmask (mask)\n"
279 			"    Set the forwarding ports hexadecimal mask.\n\n"
280 
281 			"set burst (num)\n"
282 			"    Set number of packets per burst.\n\n"
283 
284 			"set burst tx delay (microseconds) retry (num)\n"
285 			"    Set the transmit delay time and number of retries,"
286 			" effective when retry is enabled.\n\n"
287 
288 			"set txpkts (x[,y]*)\n"
289 			"    Set the length of each segment of TXONLY"
290 			" and optionally CSUM packets.\n\n"
291 
292 			"set txsplit (off|on|rand)\n"
293 			"    Set the split policy for the TX packets."
294 			" Right now only applicable for CSUM and TXONLY"
295 			" modes\n\n"
296 
297 			"set corelist (x[,y]*)\n"
298 			"    Set the list of forwarding cores.\n\n"
299 
300 			"set portlist (x[,y]*)\n"
301 			"    Set the list of forwarding ports.\n\n"
302 
303 			"set port setup on (iterator|event)\n"
304 			"    Select how attached port is retrieved for setup.\n\n"
305 
306 			"set tx loopback (port_id) (on|off)\n"
307 			"    Enable or disable tx loopback.\n\n"
308 
309 			"set all queues drop (port_id) (on|off)\n"
310 			"    Set drop enable bit for all queues.\n\n"
311 
312 			"set vf split drop (port_id) (vf_id) (on|off)\n"
313 			"    Set split drop enable bit for a VF from the PF.\n\n"
314 
315 			"set vf mac antispoof (port_id) (vf_id) (on|off).\n"
316 			"    Set MAC antispoof for a VF from the PF.\n\n"
317 
318 			"set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
319 			"    Enable MACsec offload.\n\n"
320 
321 			"set macsec offload (port_id) off\n"
322 			"    Disable MACsec offload.\n\n"
323 
324 			"set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
325 			"    Configure MACsec secure connection (SC).\n\n"
326 
327 			"set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
328 			"    Configure MACsec secure association (SA).\n\n"
329 
330 			"set vf broadcast (port_id) (vf_id) (on|off)\n"
331 			"    Set VF broadcast for a VF from the PF.\n\n"
332 
333 			"vlan set stripq (on|off) (port_id,queue_id)\n"
334 			"    Set the VLAN strip for a queue on a port.\n\n"
335 
336 			"set vf vlan stripq (port_id) (vf_id) (on|off)\n"
337 			"    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
338 
339 			"set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
340 			"    Set VLAN insert for a VF from the PF.\n\n"
341 
342 			"set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
343 			"    Set VLAN antispoof for a VF from the PF.\n\n"
344 
345 			"set vf vlan tag (port_id) (vf_id) (on|off)\n"
346 			"    Set VLAN tag for a VF from the PF.\n\n"
347 
348 			"set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
349 			"    Set a VF's max bandwidth(Mbps).\n\n"
350 
351 			"set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
352 			"    Set all TCs' min bandwidth(%%) on a VF.\n\n"
353 
354 			"set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
355 			"    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
356 
357 			"set tx strict-link-priority (port_id) (tc_bitmap)\n"
358 			"    Set some TCs' strict link priority mode on a physical port.\n\n"
359 
360 			"set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
361 			"    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
362 
363 			"vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
364 			"    Set the VLAN strip or filter or qinq strip or extend\n\n"
365 
366 			"vlan set (inner|outer) tpid (value) (port_id)\n"
367 			"    Set the VLAN TPID for Packet Filtering on"
368 			" a port\n\n"
369 
370 			"rx_vlan add (vlan_id|all) (port_id)\n"
371 			"    Add a vlan_id, or all identifiers, to the set"
372 			" of VLAN identifiers filtered by port_id.\n\n"
373 
374 			"rx_vlan rm (vlan_id|all) (port_id)\n"
375 			"    Remove a vlan_id, or all identifiers, from the set"
376 			" of VLAN identifiers filtered by port_id.\n\n"
377 
378 			"rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
379 			"    Add a vlan_id, to the set of VLAN identifiers"
380 			"filtered for VF(s) from port_id.\n\n"
381 
382 			"rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
383 			"    Remove a vlan_id, to the set of VLAN identifiers"
384 			"filtered for VF(s) from port_id.\n\n"
385 
386 			"tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
387 			"(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
388 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
389 			"   add a tunnel filter of a port.\n\n"
390 
391 			"tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
392 			"(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
393 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
394 			"   remove a tunnel filter of a port.\n\n"
395 
396 			"rx_vxlan_port add (udp_port) (port_id)\n"
397 			"    Add an UDP port for VXLAN packet filter on a port\n\n"
398 
399 			"rx_vxlan_port rm (udp_port) (port_id)\n"
400 			"    Remove an UDP port for VXLAN packet filter on a port\n\n"
401 
402 			"tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
403 			"    Set hardware insertion of VLAN IDs (single or double VLAN "
404 			"depends on the number of VLAN IDs) in packets sent on a port.\n\n"
405 
406 			"tx_vlan set pvid port_id vlan_id (on|off)\n"
407 			"    Set port based TX VLAN insertion.\n\n"
408 
409 			"tx_vlan reset (port_id)\n"
410 			"    Disable hardware insertion of a VLAN header in"
411 			" packets sent on a port.\n\n"
412 
413 			"csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
414 			"    Select hardware or software calculation of the"
415 			" checksum when transmitting a packet using the"
416 			" csum forward engine.\n"
417 			"    ip|udp|tcp|sctp always concern the inner layer.\n"
418 			"    outer-ip concerns the outer IP layer in"
419 			"    outer-udp concerns the outer UDP layer in"
420 			" case the packet is recognized as a tunnel packet by"
421 			" the forward engine (vxlan, gre and ipip are supported)\n"
422 			"    Please check the NIC datasheet for HW limits.\n\n"
423 
424 			"csum parse-tunnel (on|off) (tx_port_id)\n"
425 			"    If disabled, treat tunnel packets as non-tunneled"
426 			" packets (treat inner headers as payload). The port\n"
427 			"    argument is the port used for TX in csum forward"
428 			" engine.\n\n"
429 
430 			"csum show (port_id)\n"
431 			"    Display tx checksum offload configuration\n\n"
432 
433 			"tso set (segsize) (portid)\n"
434 			"    Enable TCP Segmentation Offload in csum forward"
435 			" engine.\n"
436 			"    Please check the NIC datasheet for HW limits.\n\n"
437 
438 			"tso show (portid)"
439 			"    Display the status of TCP Segmentation Offload.\n\n"
440 
441 			"set port (port_id) gro on|off\n"
442 			"    Enable or disable Generic Receive Offload in"
443 			" csum forwarding engine.\n\n"
444 
445 			"show port (port_id) gro\n"
446 			"    Display GRO configuration.\n\n"
447 
448 			"set gro flush (cycles)\n"
449 			"    Set the cycle to flush GROed packets from"
450 			" reassembly tables.\n\n"
451 
452 			"set port (port_id) gso (on|off)"
453 			"    Enable or disable Generic Segmentation Offload in"
454 			" csum forwarding engine.\n\n"
455 
456 			"set gso segsz (length)\n"
457 			"    Set max packet length for output GSO segments,"
458 			" including packet header and payload.\n\n"
459 
460 			"show port (port_id) gso\n"
461 			"    Show GSO configuration.\n\n"
462 
463 			"set fwd (%s)\n"
464 			"    Set packet forwarding mode.\n\n"
465 
466 			"mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
467 			"    Add a MAC address on port_id.\n\n"
468 
469 			"mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
470 			"    Remove a MAC address from port_id.\n\n"
471 
472 			"mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
473 			"    Set the default MAC address for port_id.\n\n"
474 
475 			"mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
476 			"    Add a MAC address for a VF on the port.\n\n"
477 
478 			"set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
479 			"    Set the MAC address for a VF from the PF.\n\n"
480 
481 			"set eth-peer (port_id) (peer_addr)\n"
482 			"    set the peer address for certain port.\n\n"
483 
484 			"set port (port_id) uta (mac_address|all) (on|off)\n"
485 			"    Add/Remove a or all unicast hash filter(s)"
486 			"from port X.\n\n"
487 
488 			"set promisc (port_id|all) (on|off)\n"
489 			"    Set the promiscuous mode on port_id, or all.\n\n"
490 
491 			"set allmulti (port_id|all) (on|off)\n"
492 			"    Set the allmulti mode on port_id, or all.\n\n"
493 
494 			"set vf promisc (port_id) (vf_id) (on|off)\n"
495 			"    Set unicast promiscuous mode for a VF from the PF.\n\n"
496 
497 			"set vf allmulti (port_id) (vf_id) (on|off)\n"
498 			"    Set multicast promiscuous mode for a VF from the PF.\n\n"
499 
500 			"set flow_ctrl rx (on|off) tx (on|off) (high_water)"
501 			" (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
502 			" (on|off) autoneg (on|off) (port_id)\n"
503 			"set flow_ctrl rx (on|off) (portid)\n"
504 			"set flow_ctrl tx (on|off) (portid)\n"
505 			"set flow_ctrl high_water (high_water) (portid)\n"
506 			"set flow_ctrl low_water (low_water) (portid)\n"
507 			"set flow_ctrl pause_time (pause_time) (portid)\n"
508 			"set flow_ctrl send_xon (send_xon) (portid)\n"
509 			"set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
510 			"set flow_ctrl autoneg (on|off) (port_id)\n"
511 			"    Set the link flow control parameter on a port.\n\n"
512 
513 			"set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
514 			" (low_water) (pause_time) (priority) (port_id)\n"
515 			"    Set the priority flow control parameter on a"
516 			" port.\n\n"
517 
518 			"set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
519 			"    Set statistics mapping (qmapping 0..15) for RX/TX"
520 			" queue on port.\n"
521 			"    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
522 			" on port 0 to mapping 5.\n\n"
523 
524 			"set xstats-hide-zero on|off\n"
525 			"    Set the option to hide the zero values"
526 			" for xstats display.\n"
527 
528 			"set port (port_id) vf (vf_id) rx|tx on|off\n"
529 			"    Enable/Disable a VF receive/tranmit from a port\n\n"
530 
531 			"set port (port_id) vf (vf_id) (mac_addr)"
532 			" (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
533 			"   Add/Remove unicast or multicast MAC addr filter"
534 			" for a VF.\n\n"
535 
536 			"set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
537 			"|MPE) (on|off)\n"
538 			"    AUPE:accepts untagged VLAN;"
539 			"ROPE:accept unicast hash\n\n"
540 			"    BAM:accepts broadcast packets;"
541 			"MPE:accepts all multicast packets\n\n"
542 			"    Enable/Disable a VF receive mode of a port\n\n"
543 
544 			"set port (port_id) queue (queue_id) rate (rate_num)\n"
545 			"    Set rate limit for a queue of a port\n\n"
546 
547 			"set port (port_id) vf (vf_id) rate (rate_num) "
548 			"queue_mask (queue_mask_value)\n"
549 			"    Set rate limit for queues in VF of a port\n\n"
550 
551 			"set port (port_id) mirror-rule (rule_id)"
552 			" (pool-mirror-up|pool-mirror-down|vlan-mirror)"
553 			" (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
554 			"   Set pool or vlan type mirror rule on a port.\n"
555 			"   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
556 			" dst-pool 0 on' enable mirror traffic with vlan 0,1"
557 			" to pool 0.\n\n"
558 
559 			"set port (port_id) mirror-rule (rule_id)"
560 			" (uplink-mirror|downlink-mirror) dst-pool"
561 			" (pool_id) (on|off)\n"
562 			"   Set uplink or downlink type mirror rule on a port.\n"
563 			"   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
564 			" 0 on' enable mirror income traffic to pool 0.\n\n"
565 
566 			"reset port (port_id) mirror-rule (rule_id)\n"
567 			"   Reset a mirror rule.\n\n"
568 
569 			"set flush_rx (on|off)\n"
570 			"   Flush (default) or don't flush RX streams before"
571 			" forwarding. Mainly used with PCAP drivers.\n\n"
572 
573 			"set bypass mode (normal|bypass|isolate) (port_id)\n"
574 			"   Set the bypass mode for the lowest port on bypass enabled"
575 			" NIC.\n\n"
576 
577 			"set bypass event (timeout|os_on|os_off|power_on|power_off) "
578 			"mode (normal|bypass|isolate) (port_id)\n"
579 			"   Set the event required to initiate specified bypass mode for"
580 			" the lowest port on a bypass enabled NIC where:\n"
581 			"       timeout   = enable bypass after watchdog timeout.\n"
582 			"       os_on     = enable bypass when OS/board is powered on.\n"
583 			"       os_off    = enable bypass when OS/board is powered off.\n"
584 			"       power_on  = enable bypass when power supply is turned on.\n"
585 			"       power_off = enable bypass when power supply is turned off."
586 			"\n\n"
587 
588 			"set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
589 			"   Set the bypass watchdog timeout to 'n' seconds"
590 			" where 0 = instant.\n\n"
591 
592 			"show bypass config (port_id)\n"
593 			"   Show the bypass configuration for a bypass enabled NIC"
594 			" using the lowest port on the NIC.\n\n"
595 
596 #ifdef RTE_LIBRTE_PMD_BOND
597 			"create bonded device (mode) (socket)\n"
598 			"	Create a new bonded device with specific bonding mode and socket.\n\n"
599 
600 			"add bonding slave (slave_id) (port_id)\n"
601 			"	Add a slave device to a bonded device.\n\n"
602 
603 			"remove bonding slave (slave_id) (port_id)\n"
604 			"	Remove a slave device from a bonded device.\n\n"
605 
606 			"set bonding mode (value) (port_id)\n"
607 			"	Set the bonding mode on a bonded device.\n\n"
608 
609 			"set bonding primary (slave_id) (port_id)\n"
610 			"	Set the primary slave for a bonded device.\n\n"
611 
612 			"show bonding config (port_id)\n"
613 			"	Show the bonding config for port_id.\n\n"
614 
615 			"set bonding mac_addr (port_id) (address)\n"
616 			"	Set the MAC address of a bonded device.\n\n"
617 
618 			"set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
619 			"	Set Aggregation mode for IEEE802.3AD (mode 4)"
620 
621 			"set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
622 			"	Set the transmit balance policy for bonded device running in balance mode.\n\n"
623 
624 			"set bonding mon_period (port_id) (value)\n"
625 			"	Set the bonding link status monitoring polling period in ms.\n\n"
626 
627 			"set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
628 			"	Enable/disable dedicated queues for LACP control traffic.\n\n"
629 
630 #endif
631 			"set link-up port (port_id)\n"
632 			"	Set link up for a port.\n\n"
633 
634 			"set link-down port (port_id)\n"
635 			"	Set link down for a port.\n\n"
636 
637 			"E-tag set insertion on port-tag-id (value)"
638 			" port (port_id) vf (vf_id)\n"
639 			"    Enable E-tag insertion for a VF on a port\n\n"
640 
641 			"E-tag set insertion off port (port_id) vf (vf_id)\n"
642 			"    Disable E-tag insertion for a VF on a port\n\n"
643 
644 			"E-tag set stripping (on|off) port (port_id)\n"
645 			"    Enable/disable E-tag stripping on a port\n\n"
646 
647 			"E-tag set forwarding (on|off) port (port_id)\n"
648 			"    Enable/disable E-tag based forwarding"
649 			" on a port\n\n"
650 
651 			"E-tag set filter add e-tag-id (value) dst-pool"
652 			" (pool_id) port (port_id)\n"
653 			"    Add an E-tag forwarding filter on a port\n\n"
654 
655 			"E-tag set filter del e-tag-id (value) port (port_id)\n"
656 			"    Delete an E-tag forwarding filter on a port\n\n"
657 
658 			"ddp add (port_id) (profile_path[,backup_profile_path])\n"
659 			"    Load a profile package on a port\n\n"
660 
661 			"ddp del (port_id) (backup_profile_path)\n"
662 			"    Delete a profile package from a port\n\n"
663 
664 			"ptype mapping get (port_id) (valid_only)\n"
665 			"    Get ptype mapping on a port\n\n"
666 
667 			"ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
668 			"    Replace target with the pkt_type in ptype mapping\n\n"
669 
670 			"ptype mapping reset (port_id)\n"
671 			"    Reset ptype mapping on a port\n\n"
672 
673 			"ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
674 			"    Update a ptype mapping item on a port\n\n"
675 
676 			"set port (port_id) ptype_mask (ptype_mask)\n"
677 			"    set packet types classification for a specific port\n\n"
678 
679 			"set port (port_id) queue-region region_id (value) "
680 			"queue_start_index (value) queue_num (value)\n"
681 			"    Set a queue region on a port\n\n"
682 
683 			"set port (port_id) queue-region region_id (value) "
684 			"flowtype (value)\n"
685 			"    Set a flowtype region index on a port\n\n"
686 
687 			"set port (port_id) queue-region UP (value) region_id (value)\n"
688 			"    Set the mapping of User Priority to "
689 			"queue region on a port\n\n"
690 
691 			"set port (port_id) queue-region flush (on|off)\n"
692 			"    flush all queue region related configuration\n\n"
693 
694 			"show port meter cap (port_id)\n"
695 			"    Show port meter capability information\n\n"
696 
697 			"add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
698 			"    meter profile add - srtcm rfc 2697\n\n"
699 
700 			"add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
701 			"    meter profile add - trtcm rfc 2698\n\n"
702 
703 			"add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
704 			"    meter profile add - trtcm rfc 4115\n\n"
705 
706 			"del port meter profile (port_id) (profile_id)\n"
707 			"    meter profile delete\n\n"
708 
709 			"create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
710 			"(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
711 			"(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
712 			"(dscp_tbl_entry63)]\n"
713 			"    meter create\n\n"
714 
715 			"enable port meter (port_id) (mtr_id)\n"
716 			"    meter enable\n\n"
717 
718 			"disable port meter (port_id) (mtr_id)\n"
719 			"    meter disable\n\n"
720 
721 			"del port meter (port_id) (mtr_id)\n"
722 			"    meter delete\n\n"
723 
724 			"set port meter profile (port_id) (mtr_id) (profile_id)\n"
725 			"    meter update meter profile\n\n"
726 
727 			"set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
728 			"(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
729 			"    update meter dscp table entries\n\n"
730 
731 			"set port meter policer action (port_id) (mtr_id) (action_mask)\n"
732 			"(action0) [(action1) (action2)]\n"
733 			"    meter update policer action\n\n"
734 
735 			"set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
736 			"    meter update stats\n\n"
737 
738 			"show port (port_id) queue-region\n"
739 			"    show all queue region related configuration info\n\n"
740 
741 			, list_pkt_forwarding_modes()
742 		);
743 	}
744 
745 	if (show_all || !strcmp(res->section, "ports")) {
746 
747 		cmdline_printf(
748 			cl,
749 			"\n"
750 			"Port Operations:\n"
751 			"----------------\n\n"
752 
753 			"port start (port_id|all)\n"
754 			"    Start all ports or port_id.\n\n"
755 
756 			"port stop (port_id|all)\n"
757 			"    Stop all ports or port_id.\n\n"
758 
759 			"port close (port_id|all)\n"
760 			"    Close all ports or port_id.\n\n"
761 
762 			"port reset (port_id|all)\n"
763 			"    Reset all ports or port_id.\n\n"
764 
765 			"port attach (ident)\n"
766 			"    Attach physical or virtual dev by pci address or virtual device name\n\n"
767 
768 			"port detach (port_id)\n"
769 			"    Detach physical or virtual dev by port_id\n\n"
770 
771 			"port config (port_id|all)"
772 			" speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
773 			" duplex (half|full|auto)\n"
774 			"    Set speed and duplex for all ports or port_id\n\n"
775 
776 			"port config (port_id|all) loopback (mode)\n"
777 			"    Set loopback mode for all ports or port_id\n\n"
778 
779 			"port config all (rxq|txq|rxd|txd) (value)\n"
780 			"    Set number for rxq/txq/rxd/txd.\n\n"
781 
782 			"port config all max-pkt-len (value)\n"
783 			"    Set the max packet length.\n\n"
784 
785 			"port config all max-lro-pkt-size (value)\n"
786 			"    Set the max LRO aggregated packet size.\n\n"
787 
788 			"port config all drop-en (on|off)\n"
789 			"    Enable or disable packet drop on all RX queues of all ports when no "
790 			"receive buffers available.\n\n"
791 
792 			"port config all rss (all|default|ip|tcp|udp|sctp|"
793 			"ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
794 			"    Set the RSS mode.\n\n"
795 
796 			"port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
797 			"    Set the RSS redirection table.\n\n"
798 
799 			"port config (port_id) dcb vt (on|off) (traffic_class)"
800 			" pfc (on|off)\n"
801 			"    Set the DCB mode.\n\n"
802 
803 			"port config all burst (value)\n"
804 			"    Set the number of packets per burst.\n\n"
805 
806 			"port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
807 			" (value)\n"
808 			"    Set the ring prefetch/host/writeback threshold"
809 			" for tx/rx queue.\n\n"
810 
811 			"port config all (txfreet|txrst|rxfreet) (value)\n"
812 			"    Set free threshold for rx/tx, or set"
813 			" tx rs bit threshold.\n\n"
814 			"port config mtu X value\n"
815 			"    Set the MTU of port X to a given value\n\n"
816 
817 			"port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
818 			"    Set a rx/tx queue's ring size configuration, the new"
819 			" value will take effect after command that (re-)start the port"
820 			" or command that setup the specific queue\n\n"
821 
822 			"port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
823 			"    Start/stop a rx/tx queue of port X. Only take effect"
824 			" when port X is started\n\n"
825 
826 			"port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
827 			"    Switch on/off a deferred start of port X rx/tx queue. Only"
828 			" take effect when port X is stopped.\n\n"
829 
830 			"port (port_id) (rxq|txq) (queue_id) setup\n"
831 			"    Setup a rx/tx queue of port X.\n\n"
832 
833 			"port config (port_id|all) l2-tunnel E-tag ether-type"
834 			" (value)\n"
835 			"    Set the value of E-tag ether-type.\n\n"
836 
837 			"port config (port_id|all) l2-tunnel E-tag"
838 			" (enable|disable)\n"
839 			"    Enable/disable the E-tag support.\n\n"
840 
841 			"port config (port_id) pctype mapping reset\n"
842 			"    Reset flow type to pctype mapping on a port\n\n"
843 
844 			"port config (port_id) pctype mapping update"
845 			" (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
846 			"    Update a flow type to pctype mapping item on a port\n\n"
847 
848 			"port config (port_id) pctype (pctype_id) hash_inset|"
849 			"fdir_inset|fdir_flx_inset get|set|clear field\n"
850 			" (field_idx)\n"
851 			"    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
852 
853 			"port config (port_id) pctype (pctype_id) hash_inset|"
854 			"fdir_inset|fdir_flx_inset clear all"
855 			"    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
856 
857 			"port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
858 			"    Add/remove UDP tunnel port for tunneling offload\n\n"
859 
860 			"port config <port_id> rx_offload vlan_strip|"
861 			"ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
862 			"outer_ipv4_cksum|macsec_strip|header_split|"
863 			"vlan_filter|vlan_extend|jumbo_frame|"
864 			"scatter|timestamp|security|keep_crc on|off\n"
865 			"     Enable or disable a per port Rx offloading"
866 			" on all Rx queues of a port\n\n"
867 
868 			"port (port_id) rxq (queue_id) rx_offload vlan_strip|"
869 			"ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
870 			"outer_ipv4_cksum|macsec_strip|header_split|"
871 			"vlan_filter|vlan_extend|jumbo_frame|"
872 			"scatter|timestamp|security|keep_crc on|off\n"
873 			"    Enable or disable a per queue Rx offloading"
874 			" only on a specific Rx queue\n\n"
875 
876 			"port config (port_id) tx_offload vlan_insert|"
877 			"ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
878 			"udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
879 			"gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
880 			"macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
881 			"security on|off\n"
882 			"    Enable or disable a per port Tx offloading"
883 			" on all Tx queues of a port\n\n"
884 
885 			"port (port_id) txq (queue_id) tx_offload vlan_insert|"
886 			"ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
887 			"udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
888 			"gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
889 			"|mt_lockfree|multi_segs|mbuf_fast_free|security"
890 			" on|off\n"
891 			"    Enable or disable a per queue Tx offloading"
892 			" only on a specific Tx queue\n\n"
893 
894 			"bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
895 			"    Load an eBPF program as a callback"
896 			" for particular RX/TX queue\n\n"
897 
898 			"bpf-unload rx|tx (port) (queue)\n"
899 			"    Unload previously loaded eBPF program"
900 			" for particular RX/TX queue\n\n"
901 
902 			"port config (port_id) tx_metadata (value)\n"
903 			"    Set Tx metadata value per port. Testpmd will add this value"
904 			" to any Tx packet sent from this port\n\n"
905 
906 			"port config (port_id) dynf (name) set|clear\n"
907 			"    Register a dynf and Set/clear this flag on Tx. "
908 			"Testpmd will set this value to any Tx packet "
909 			"sent from this port\n\n"
910 		);
911 	}
912 
913 	if (show_all || !strcmp(res->section, "registers")) {
914 
915 		cmdline_printf(
916 			cl,
917 			"\n"
918 			"Registers:\n"
919 			"----------\n\n"
920 
921 			"read reg (port_id) (address)\n"
922 			"    Display value of a port register.\n\n"
923 
924 			"read regfield (port_id) (address) (bit_x) (bit_y)\n"
925 			"    Display a port register bit field.\n\n"
926 
927 			"read regbit (port_id) (address) (bit_x)\n"
928 			"    Display a single port register bit.\n\n"
929 
930 			"write reg (port_id) (address) (value)\n"
931 			"    Set value of a port register.\n\n"
932 
933 			"write regfield (port_id) (address) (bit_x) (bit_y)"
934 			" (value)\n"
935 			"    Set bit field of a port register.\n\n"
936 
937 			"write regbit (port_id) (address) (bit_x) (value)\n"
938 			"    Set single bit value of a port register.\n\n"
939 		);
940 	}
941 	if (show_all || !strcmp(res->section, "filters")) {
942 
943 		cmdline_printf(
944 			cl,
945 			"\n"
946 			"filters:\n"
947 			"--------\n\n"
948 
949 			"ethertype_filter (port_id) (add|del)"
950 			" (mac_addr|mac_ignr) (mac_address) ethertype"
951 			" (ether_type) (drop|fwd) queue (queue_id)\n"
952 			"    Add/Del an ethertype filter.\n\n"
953 
954 			"2tuple_filter (port_id) (add|del)"
955 			" dst_port (dst_port_value) protocol (protocol_value)"
956 			" mask (mask_value) tcp_flags (tcp_flags_value)"
957 			" priority (prio_value) queue (queue_id)\n"
958 			"    Add/Del a 2tuple filter.\n\n"
959 
960 			"5tuple_filter (port_id) (add|del)"
961 			" dst_ip (dst_address) src_ip (src_address)"
962 			" dst_port (dst_port_value) src_port (src_port_value)"
963 			" protocol (protocol_value)"
964 			" mask (mask_value) tcp_flags (tcp_flags_value)"
965 			" priority (prio_value) queue (queue_id)\n"
966 			"    Add/Del a 5tuple filter.\n\n"
967 
968 			"syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
969 			"    Add/Del syn filter.\n\n"
970 
971 			"flex_filter (port_id) (add|del) len (len_value)"
972 			" bytes (bytes_value) mask (mask_value)"
973 			" priority (prio_value) queue (queue_id)\n"
974 			"    Add/Del a flex filter.\n\n"
975 
976 			"flow_director_filter (port_id) mode IP (add|del|update)"
977 			" flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
978 			" src (src_ip_address) dst (dst_ip_address)"
979 			" tos (tos_value) proto (proto_value) ttl (ttl_value)"
980 			" vlan (vlan_value) flexbytes (flexbytes_value)"
981 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
982 			" fd_id (fd_id_value)\n"
983 			"    Add/Del an IP type flow director filter.\n\n"
984 
985 			"flow_director_filter (port_id) mode IP (add|del|update)"
986 			" flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
987 			" src (src_ip_address) (src_port)"
988 			" dst (dst_ip_address) (dst_port)"
989 			" tos (tos_value) ttl (ttl_value)"
990 			" vlan (vlan_value) flexbytes (flexbytes_value)"
991 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
992 			" fd_id (fd_id_value)\n"
993 			"    Add/Del an UDP/TCP type flow director filter.\n\n"
994 
995 			"flow_director_filter (port_id) mode IP (add|del|update)"
996 			" flow (ipv4-sctp|ipv6-sctp)"
997 			" src (src_ip_address) (src_port)"
998 			" dst (dst_ip_address) (dst_port)"
999 			" tag (verification_tag) "
1000 			" tos (tos_value) ttl (ttl_value)"
1001 			" vlan (vlan_value)"
1002 			" flexbytes (flexbytes_value) (drop|fwd)"
1003 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1004 			"    Add/Del a SCTP type flow director filter.\n\n"
1005 
1006 			"flow_director_filter (port_id) mode IP (add|del|update)"
1007 			" flow l2_payload ether (ethertype)"
1008 			" flexbytes (flexbytes_value) (drop|fwd)"
1009 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1010 			"    Add/Del a l2 payload type flow director filter.\n\n"
1011 
1012 			"flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1013 			" mac (mac_address) vlan (vlan_value)"
1014 			" flexbytes (flexbytes_value) (drop|fwd)"
1015 			" queue (queue_id) fd_id (fd_id_value)\n"
1016 			"    Add/Del a MAC-VLAN flow director filter.\n\n"
1017 
1018 			"flow_director_filter (port_id) mode Tunnel (add|del|update)"
1019 			" mac (mac_address) vlan (vlan_value)"
1020 			" tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1021 			" flexbytes (flexbytes_value) (drop|fwd)"
1022 			" queue (queue_id) fd_id (fd_id_value)\n"
1023 			"    Add/Del a Tunnel flow director filter.\n\n"
1024 
1025 			"flow_director_filter (port_id) mode raw (add|del|update)"
1026 			" flow (flow_id) (drop|fwd) queue (queue_id)"
1027 			" fd_id (fd_id_value) packet (packet file name)\n"
1028 			"    Add/Del a raw type flow director filter.\n\n"
1029 
1030 			"flush_flow_director (port_id)\n"
1031 			"    Flush all flow director entries of a device.\n\n"
1032 
1033 			"flow_director_mask (port_id) mode IP vlan (vlan_value)"
1034 			" src_mask (ipv4_src) (ipv6_src) (src_port)"
1035 			" dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1036 			"    Set flow director IP mask.\n\n"
1037 
1038 			"flow_director_mask (port_id) mode MAC-VLAN"
1039 			" vlan (vlan_value)\n"
1040 			"    Set flow director MAC-VLAN mask.\n\n"
1041 
1042 			"flow_director_mask (port_id) mode Tunnel"
1043 			" vlan (vlan_value) mac (mac_value)"
1044 			" tunnel-type (tunnel_type_value)"
1045 			" tunnel-id (tunnel_id_value)\n"
1046 			"    Set flow director Tunnel mask.\n\n"
1047 
1048 			"flow_director_flex_mask (port_id)"
1049 			" flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1050 			"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1051 			" (mask)\n"
1052 			"    Configure mask of flex payload.\n\n"
1053 
1054 			"flow_director_flex_payload (port_id)"
1055 			" (raw|l2|l3|l4) (config)\n"
1056 			"    Configure flex payload selection.\n\n"
1057 
1058 			"get_sym_hash_ena_per_port (port_id)\n"
1059 			"    get symmetric hash enable configuration per port.\n\n"
1060 
1061 			"set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1062 			"    set symmetric hash enable configuration per port"
1063 			" to enable or disable.\n\n"
1064 
1065 			"get_hash_global_config (port_id)\n"
1066 			"    Get the global configurations of hash filters.\n\n"
1067 
1068 			"set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1069 			" (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1070 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1071 			" (enable|disable)\n"
1072 			"    Set the global configurations of hash filters.\n\n"
1073 
1074 			"set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1075 			"ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1076 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1077 			"l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1078 			"src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1079 			"ipv6-next-header|udp-src-port|udp-dst-port|"
1080 			"tcp-src-port|tcp-dst-port|sctp-src-port|"
1081 			"sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1082 			"fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1083 			"fld-8th|none) (select|add)\n"
1084 			"    Set the input set for hash.\n\n"
1085 
1086 			"set_fdir_input_set (port_id) "
1087 			"(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1088 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1089 			"l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1090 			"dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1091 			"ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1092 			"udp-dst-port|tcp-src-port|tcp-dst-port|"
1093 			"sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1094 			" (select|add)\n"
1095 			"    Set the input set for FDir.\n\n"
1096 
1097 			"flow validate {port_id}"
1098 			" [group {group_id}] [priority {level}]"
1099 			" [ingress] [egress]"
1100 			" pattern {item} [/ {item} [...]] / end"
1101 			" actions {action} [/ {action} [...]] / end\n"
1102 			"    Check whether a flow rule can be created.\n\n"
1103 
1104 			"flow create {port_id}"
1105 			" [group {group_id}] [priority {level}]"
1106 			" [ingress] [egress]"
1107 			" pattern {item} [/ {item} [...]] / end"
1108 			" actions {action} [/ {action} [...]] / end\n"
1109 			"    Create a flow rule.\n\n"
1110 
1111 			"flow destroy {port_id} rule {rule_id} [...]\n"
1112 			"    Destroy specific flow rules.\n\n"
1113 
1114 			"flow flush {port_id}\n"
1115 			"    Destroy all flow rules.\n\n"
1116 
1117 			"flow query {port_id} {rule_id} {action}\n"
1118 			"    Query an existing flow rule.\n\n"
1119 
1120 			"flow list {port_id} [group {group_id}] [...]\n"
1121 			"    List existing flow rules sorted by priority,"
1122 			" filtered by group identifiers.\n\n"
1123 
1124 			"flow isolate {port_id} {boolean}\n"
1125 			"    Restrict ingress traffic to the defined"
1126 			" flow rules\n\n"
1127 
1128 			"flow aged {port_id} [destroy]\n"
1129 			"    List and destroy aged flows"
1130 			" flow rules\n\n"
1131 
1132 			"set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1133 			" (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1134 			" (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1135 			"       Configure the VXLAN encapsulation for flows.\n\n"
1136 
1137 			"set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1138 			" udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1139 			" ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1140 			" eth-dst (eth-dst)\n"
1141 			"       Configure the VXLAN encapsulation for flows.\n\n"
1142 
1143 			"set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1144 			" (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1145 			" ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1146 			" eth-dst (eth-dst)\n"
1147 			"       Configure the VXLAN encapsulation for flows.\n\n"
1148 
1149 			"set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1150 			" (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1151 			" (eth-dst)\n"
1152 			"       Configure the NVGRE encapsulation for flows.\n\n"
1153 
1154 			"set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1155 			" ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1156 			" eth-src (eth-src) eth-dst (eth-dst)\n"
1157 			"       Configure the NVGRE encapsulation for flows.\n\n"
1158 
1159 			"set raw_encap {flow items}\n"
1160 			"	Configure the encapsulation with raw data.\n\n"
1161 
1162 			"set raw_decap {flow items}\n"
1163 			"	Configure the decapsulation with raw data.\n\n"
1164 
1165 		);
1166 	}
1167 
1168 	if (show_all || !strcmp(res->section, "traffic_management")) {
1169 		cmdline_printf(
1170 			cl,
1171 			"\n"
1172 			"Traffic Management:\n"
1173 			"--------------\n"
1174 			"show port tm cap (port_id)\n"
1175 			"       Display the port TM capability.\n\n"
1176 
1177 			"show port tm level cap (port_id) (level_id)\n"
1178 			"       Display the port TM hierarchical level capability.\n\n"
1179 
1180 			"show port tm node cap (port_id) (node_id)\n"
1181 			"       Display the port TM node capability.\n\n"
1182 
1183 			"show port tm node type (port_id) (node_id)\n"
1184 			"       Display the port TM node type.\n\n"
1185 
1186 			"show port tm node stats (port_id) (node_id) (clear)\n"
1187 			"       Display the port TM node stats.\n\n"
1188 
1189 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1190 			"set port tm hierarchy default (port_id)\n"
1191 			"       Set default traffic Management hierarchy on a port\n\n"
1192 #endif
1193 
1194 			"add port tm node shaper profile (port_id) (shaper_profile_id)"
1195 			" (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1196 			" (packet_length_adjust)\n"
1197 			"       Add port tm node private shaper profile.\n\n"
1198 
1199 			"del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1200 			"       Delete port tm node private shaper profile.\n\n"
1201 
1202 			"add port tm node shared shaper (port_id) (shared_shaper_id)"
1203 			" (shaper_profile_id)\n"
1204 			"       Add/update port tm node shared shaper.\n\n"
1205 
1206 			"del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1207 			"       Delete port tm node shared shaper.\n\n"
1208 
1209 			"set port tm node shaper profile (port_id) (node_id)"
1210 			" (shaper_profile_id)\n"
1211 			"       Set port tm node shaper profile.\n\n"
1212 
1213 			"add port tm node wred profile (port_id) (wred_profile_id)"
1214 			" (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1215 			" (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1216 			" (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1217 			"       Add port tm node wred profile.\n\n"
1218 
1219 			"del port tm node wred profile (port_id) (wred_profile_id)\n"
1220 			"       Delete port tm node wred profile.\n\n"
1221 
1222 			"add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1223 			" (priority) (weight) (level_id) (shaper_profile_id)"
1224 			" (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1225 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1226 			"       Add port tm nonleaf node.\n\n"
1227 
1228 			"add port tm leaf node (port_id) (node_id) (parent_node_id)"
1229 			" (priority) (weight) (level_id) (shaper_profile_id)"
1230 			" (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1231 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1232 			"       Add port tm leaf node.\n\n"
1233 
1234 			"del port tm node (port_id) (node_id)\n"
1235 			"       Delete port tm node.\n\n"
1236 
1237 			"set port tm node parent (port_id) (node_id) (parent_node_id)"
1238 			" (priority) (weight)\n"
1239 			"       Set port tm node parent.\n\n"
1240 
1241 			"suspend port tm node (port_id) (node_id)"
1242 			"       Suspend tm node.\n\n"
1243 
1244 			"resume port tm node (port_id) (node_id)"
1245 			"       Resume tm node.\n\n"
1246 
1247 			"port tm hierarchy commit (port_id) (clean_on_fail)\n"
1248 			"       Commit tm hierarchy.\n\n"
1249 
1250 			"set port tm mark ip_ecn (port) (green) (yellow)"
1251 			" (red)\n"
1252 			"    Enables/Disables the traffic management marking"
1253 			" for IP ECN (Explicit Congestion Notification)"
1254 			" packets on a given port\n\n"
1255 
1256 			"set port tm mark ip_dscp (port) (green) (yellow)"
1257 			" (red)\n"
1258 			"    Enables/Disables the traffic management marking"
1259 			" on the port for IP dscp packets\n\n"
1260 
1261 			"set port tm mark vlan_dei (port) (green) (yellow)"
1262 			" (red)\n"
1263 			"    Enables/Disables the traffic management marking"
1264 			" on the port for VLAN packets with DEI enabled\n\n"
1265 		);
1266 	}
1267 
1268 	if (show_all || !strcmp(res->section, "devices")) {
1269 		cmdline_printf(
1270 			cl,
1271 			"\n"
1272 			"Device Operations:\n"
1273 			"--------------\n"
1274 			"device detach (identifier)\n"
1275 			"       Detach device by identifier.\n\n"
1276 		);
1277 	}
1278 
1279 }
1280 
1281 cmdline_parse_token_string_t cmd_help_long_help =
1282 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1283 
1284 cmdline_parse_token_string_t cmd_help_long_section =
1285 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1286 			"all#control#display#config#"
1287 			"ports#registers#filters#traffic_management#devices");
1288 
1289 cmdline_parse_inst_t cmd_help_long = {
1290 	.f = cmd_help_long_parsed,
1291 	.data = NULL,
1292 	.help_str = "help all|control|display|config|ports|register|"
1293 		"filters|traffic_management|devices: "
1294 		"Show help",
1295 	.tokens = {
1296 		(void *)&cmd_help_long_help,
1297 		(void *)&cmd_help_long_section,
1298 		NULL,
1299 	},
1300 };
1301 
1302 
1303 /* *** start/stop/close all ports *** */
1304 struct cmd_operate_port_result {
1305 	cmdline_fixed_string_t keyword;
1306 	cmdline_fixed_string_t name;
1307 	cmdline_fixed_string_t value;
1308 };
1309 
1310 static void cmd_operate_port_parsed(void *parsed_result,
1311 				__rte_unused struct cmdline *cl,
1312 				__rte_unused void *data)
1313 {
1314 	struct cmd_operate_port_result *res = parsed_result;
1315 
1316 	if (!strcmp(res->name, "start"))
1317 		start_port(RTE_PORT_ALL);
1318 	else if (!strcmp(res->name, "stop"))
1319 		stop_port(RTE_PORT_ALL);
1320 	else if (!strcmp(res->name, "close"))
1321 		close_port(RTE_PORT_ALL);
1322 	else if (!strcmp(res->name, "reset"))
1323 		reset_port(RTE_PORT_ALL);
1324 	else
1325 		printf("Unknown parameter\n");
1326 }
1327 
1328 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1329 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1330 								"port");
1331 cmdline_parse_token_string_t cmd_operate_port_all_port =
1332 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1333 						"start#stop#close#reset");
1334 cmdline_parse_token_string_t cmd_operate_port_all_all =
1335 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1336 
1337 cmdline_parse_inst_t cmd_operate_port = {
1338 	.f = cmd_operate_port_parsed,
1339 	.data = NULL,
1340 	.help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1341 	.tokens = {
1342 		(void *)&cmd_operate_port_all_cmd,
1343 		(void *)&cmd_operate_port_all_port,
1344 		(void *)&cmd_operate_port_all_all,
1345 		NULL,
1346 	},
1347 };
1348 
1349 /* *** start/stop/close specific port *** */
1350 struct cmd_operate_specific_port_result {
1351 	cmdline_fixed_string_t keyword;
1352 	cmdline_fixed_string_t name;
1353 	uint8_t value;
1354 };
1355 
1356 static void cmd_operate_specific_port_parsed(void *parsed_result,
1357 			__rte_unused struct cmdline *cl,
1358 				__rte_unused void *data)
1359 {
1360 	struct cmd_operate_specific_port_result *res = parsed_result;
1361 
1362 	if (!strcmp(res->name, "start"))
1363 		start_port(res->value);
1364 	else if (!strcmp(res->name, "stop"))
1365 		stop_port(res->value);
1366 	else if (!strcmp(res->name, "close"))
1367 		close_port(res->value);
1368 	else if (!strcmp(res->name, "reset"))
1369 		reset_port(res->value);
1370 	else
1371 		printf("Unknown parameter\n");
1372 }
1373 
1374 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1375 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1376 							keyword, "port");
1377 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1378 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1379 						name, "start#stop#close#reset");
1380 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1381 	TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1382 							value, UINT8);
1383 
1384 cmdline_parse_inst_t cmd_operate_specific_port = {
1385 	.f = cmd_operate_specific_port_parsed,
1386 	.data = NULL,
1387 	.help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1388 	.tokens = {
1389 		(void *)&cmd_operate_specific_port_cmd,
1390 		(void *)&cmd_operate_specific_port_port,
1391 		(void *)&cmd_operate_specific_port_id,
1392 		NULL,
1393 	},
1394 };
1395 
1396 /* *** enable port setup (after attach) via iterator or event *** */
1397 struct cmd_set_port_setup_on_result {
1398 	cmdline_fixed_string_t set;
1399 	cmdline_fixed_string_t port;
1400 	cmdline_fixed_string_t setup;
1401 	cmdline_fixed_string_t on;
1402 	cmdline_fixed_string_t mode;
1403 };
1404 
1405 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1406 				__rte_unused struct cmdline *cl,
1407 				__rte_unused void *data)
1408 {
1409 	struct cmd_set_port_setup_on_result *res = parsed_result;
1410 
1411 	if (strcmp(res->mode, "event") == 0)
1412 		setup_on_probe_event = true;
1413 	else if (strcmp(res->mode, "iterator") == 0)
1414 		setup_on_probe_event = false;
1415 	else
1416 		printf("Unknown mode\n");
1417 }
1418 
1419 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1420 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1421 			set, "set");
1422 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1423 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1424 			port, "port");
1425 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1426 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1427 			setup, "setup");
1428 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1429 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1430 			on, "on");
1431 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1432 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1433 			mode, "iterator#event");
1434 
1435 cmdline_parse_inst_t cmd_set_port_setup_on = {
1436 	.f = cmd_set_port_setup_on_parsed,
1437 	.data = NULL,
1438 	.help_str = "set port setup on iterator|event",
1439 	.tokens = {
1440 		(void *)&cmd_set_port_setup_on_set,
1441 		(void *)&cmd_set_port_setup_on_port,
1442 		(void *)&cmd_set_port_setup_on_setup,
1443 		(void *)&cmd_set_port_setup_on_on,
1444 		(void *)&cmd_set_port_setup_on_mode,
1445 		NULL,
1446 	},
1447 };
1448 
1449 /* *** attach a specified port *** */
1450 struct cmd_operate_attach_port_result {
1451 	cmdline_fixed_string_t port;
1452 	cmdline_fixed_string_t keyword;
1453 	cmdline_multi_string_t identifier;
1454 };
1455 
1456 static void cmd_operate_attach_port_parsed(void *parsed_result,
1457 				__rte_unused struct cmdline *cl,
1458 				__rte_unused void *data)
1459 {
1460 	struct cmd_operate_attach_port_result *res = parsed_result;
1461 
1462 	if (!strcmp(res->keyword, "attach"))
1463 		attach_port(res->identifier);
1464 	else
1465 		printf("Unknown parameter\n");
1466 }
1467 
1468 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1469 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1470 			port, "port");
1471 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1472 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1473 			keyword, "attach");
1474 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1475 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1476 			identifier, TOKEN_STRING_MULTI);
1477 
1478 cmdline_parse_inst_t cmd_operate_attach_port = {
1479 	.f = cmd_operate_attach_port_parsed,
1480 	.data = NULL,
1481 	.help_str = "port attach <identifier>: "
1482 		"(identifier: pci address or virtual dev name)",
1483 	.tokens = {
1484 		(void *)&cmd_operate_attach_port_port,
1485 		(void *)&cmd_operate_attach_port_keyword,
1486 		(void *)&cmd_operate_attach_port_identifier,
1487 		NULL,
1488 	},
1489 };
1490 
1491 /* *** detach a specified port *** */
1492 struct cmd_operate_detach_port_result {
1493 	cmdline_fixed_string_t port;
1494 	cmdline_fixed_string_t keyword;
1495 	portid_t port_id;
1496 };
1497 
1498 static void cmd_operate_detach_port_parsed(void *parsed_result,
1499 				__rte_unused struct cmdline *cl,
1500 				__rte_unused void *data)
1501 {
1502 	struct cmd_operate_detach_port_result *res = parsed_result;
1503 
1504 	if (!strcmp(res->keyword, "detach")) {
1505 		RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1506 		detach_port_device(res->port_id);
1507 	} else {
1508 		printf("Unknown parameter\n");
1509 	}
1510 }
1511 
1512 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1513 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1514 			port, "port");
1515 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1516 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1517 			keyword, "detach");
1518 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1519 	TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1520 			port_id, UINT16);
1521 
1522 cmdline_parse_inst_t cmd_operate_detach_port = {
1523 	.f = cmd_operate_detach_port_parsed,
1524 	.data = NULL,
1525 	.help_str = "port detach <port_id>",
1526 	.tokens = {
1527 		(void *)&cmd_operate_detach_port_port,
1528 		(void *)&cmd_operate_detach_port_keyword,
1529 		(void *)&cmd_operate_detach_port_port_id,
1530 		NULL,
1531 	},
1532 };
1533 
1534 /* *** detach device by identifier *** */
1535 struct cmd_operate_detach_device_result {
1536 	cmdline_fixed_string_t device;
1537 	cmdline_fixed_string_t keyword;
1538 	cmdline_fixed_string_t identifier;
1539 };
1540 
1541 static void cmd_operate_detach_device_parsed(void *parsed_result,
1542 				__rte_unused struct cmdline *cl,
1543 				__rte_unused void *data)
1544 {
1545 	struct cmd_operate_detach_device_result *res = parsed_result;
1546 
1547 	if (!strcmp(res->keyword, "detach"))
1548 		detach_devargs(res->identifier);
1549 	else
1550 		printf("Unknown parameter\n");
1551 }
1552 
1553 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1554 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1555 			device, "device");
1556 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1557 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1558 			keyword, "detach");
1559 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1560 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1561 			identifier, NULL);
1562 
1563 cmdline_parse_inst_t cmd_operate_detach_device = {
1564 	.f = cmd_operate_detach_device_parsed,
1565 	.data = NULL,
1566 	.help_str = "device detach <identifier>:"
1567 		"(identifier: pci address or virtual dev name)",
1568 	.tokens = {
1569 		(void *)&cmd_operate_detach_device_device,
1570 		(void *)&cmd_operate_detach_device_keyword,
1571 		(void *)&cmd_operate_detach_device_identifier,
1572 		NULL,
1573 	},
1574 };
1575 /* *** configure speed for all ports *** */
1576 struct cmd_config_speed_all {
1577 	cmdline_fixed_string_t port;
1578 	cmdline_fixed_string_t keyword;
1579 	cmdline_fixed_string_t all;
1580 	cmdline_fixed_string_t item1;
1581 	cmdline_fixed_string_t item2;
1582 	cmdline_fixed_string_t value1;
1583 	cmdline_fixed_string_t value2;
1584 };
1585 
1586 static int
1587 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1588 {
1589 
1590 	int duplex;
1591 
1592 	if (!strcmp(duplexstr, "half")) {
1593 		duplex = ETH_LINK_HALF_DUPLEX;
1594 	} else if (!strcmp(duplexstr, "full")) {
1595 		duplex = ETH_LINK_FULL_DUPLEX;
1596 	} else if (!strcmp(duplexstr, "auto")) {
1597 		duplex = ETH_LINK_FULL_DUPLEX;
1598 	} else {
1599 		printf("Unknown duplex parameter\n");
1600 		return -1;
1601 	}
1602 
1603 	if (!strcmp(speedstr, "10")) {
1604 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1605 				ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1606 	} else if (!strcmp(speedstr, "100")) {
1607 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1608 				ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1609 	} else {
1610 		if (duplex != ETH_LINK_FULL_DUPLEX) {
1611 			printf("Invalid speed/duplex parameters\n");
1612 			return -1;
1613 		}
1614 		if (!strcmp(speedstr, "1000")) {
1615 			*speed = ETH_LINK_SPEED_1G;
1616 		} else if (!strcmp(speedstr, "10000")) {
1617 			*speed = ETH_LINK_SPEED_10G;
1618 		} else if (!strcmp(speedstr, "25000")) {
1619 			*speed = ETH_LINK_SPEED_25G;
1620 		} else if (!strcmp(speedstr, "40000")) {
1621 			*speed = ETH_LINK_SPEED_40G;
1622 		} else if (!strcmp(speedstr, "50000")) {
1623 			*speed = ETH_LINK_SPEED_50G;
1624 		} else if (!strcmp(speedstr, "100000")) {
1625 			*speed = ETH_LINK_SPEED_100G;
1626 		} else if (!strcmp(speedstr, "200000")) {
1627 			*speed = ETH_LINK_SPEED_200G;
1628 		} else if (!strcmp(speedstr, "auto")) {
1629 			*speed = ETH_LINK_SPEED_AUTONEG;
1630 		} else {
1631 			printf("Unknown speed parameter\n");
1632 			return -1;
1633 		}
1634 	}
1635 
1636 	return 0;
1637 }
1638 
1639 static void
1640 cmd_config_speed_all_parsed(void *parsed_result,
1641 			__rte_unused struct cmdline *cl,
1642 			__rte_unused void *data)
1643 {
1644 	struct cmd_config_speed_all *res = parsed_result;
1645 	uint32_t link_speed;
1646 	portid_t pid;
1647 
1648 	if (!all_ports_stopped()) {
1649 		printf("Please stop all ports first\n");
1650 		return;
1651 	}
1652 
1653 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1654 			&link_speed) < 0)
1655 		return;
1656 
1657 	RTE_ETH_FOREACH_DEV(pid) {
1658 		ports[pid].dev_conf.link_speeds = link_speed;
1659 	}
1660 
1661 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1662 }
1663 
1664 cmdline_parse_token_string_t cmd_config_speed_all_port =
1665 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1666 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1667 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1668 							"config");
1669 cmdline_parse_token_string_t cmd_config_speed_all_all =
1670 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1671 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1672 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1673 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1674 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1675 				"10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1676 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1677 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1678 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1679 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1680 						"half#full#auto");
1681 
1682 cmdline_parse_inst_t cmd_config_speed_all = {
1683 	.f = cmd_config_speed_all_parsed,
1684 	.data = NULL,
1685 	.help_str = "port config all speed "
1686 		"10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1687 							"half|full|auto",
1688 	.tokens = {
1689 		(void *)&cmd_config_speed_all_port,
1690 		(void *)&cmd_config_speed_all_keyword,
1691 		(void *)&cmd_config_speed_all_all,
1692 		(void *)&cmd_config_speed_all_item1,
1693 		(void *)&cmd_config_speed_all_value1,
1694 		(void *)&cmd_config_speed_all_item2,
1695 		(void *)&cmd_config_speed_all_value2,
1696 		NULL,
1697 	},
1698 };
1699 
1700 /* *** configure speed for specific port *** */
1701 struct cmd_config_speed_specific {
1702 	cmdline_fixed_string_t port;
1703 	cmdline_fixed_string_t keyword;
1704 	portid_t id;
1705 	cmdline_fixed_string_t item1;
1706 	cmdline_fixed_string_t item2;
1707 	cmdline_fixed_string_t value1;
1708 	cmdline_fixed_string_t value2;
1709 };
1710 
1711 static void
1712 cmd_config_speed_specific_parsed(void *parsed_result,
1713 				__rte_unused struct cmdline *cl,
1714 				__rte_unused void *data)
1715 {
1716 	struct cmd_config_speed_specific *res = parsed_result;
1717 	uint32_t link_speed;
1718 
1719 	if (!all_ports_stopped()) {
1720 		printf("Please stop all ports first\n");
1721 		return;
1722 	}
1723 
1724 	if (port_id_is_invalid(res->id, ENABLED_WARN))
1725 		return;
1726 
1727 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1728 			&link_speed) < 0)
1729 		return;
1730 
1731 	ports[res->id].dev_conf.link_speeds = link_speed;
1732 
1733 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1734 }
1735 
1736 
1737 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1738 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1739 								"port");
1740 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1741 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1742 								"config");
1743 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1744 	TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1745 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1746 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1747 								"speed");
1748 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1749 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1750 				"10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1751 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1752 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1753 								"duplex");
1754 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1755 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1756 							"half#full#auto");
1757 
1758 cmdline_parse_inst_t cmd_config_speed_specific = {
1759 	.f = cmd_config_speed_specific_parsed,
1760 	.data = NULL,
1761 	.help_str = "port config <port_id> speed "
1762 		"10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1763 							"half|full|auto",
1764 	.tokens = {
1765 		(void *)&cmd_config_speed_specific_port,
1766 		(void *)&cmd_config_speed_specific_keyword,
1767 		(void *)&cmd_config_speed_specific_id,
1768 		(void *)&cmd_config_speed_specific_item1,
1769 		(void *)&cmd_config_speed_specific_value1,
1770 		(void *)&cmd_config_speed_specific_item2,
1771 		(void *)&cmd_config_speed_specific_value2,
1772 		NULL,
1773 	},
1774 };
1775 
1776 /* *** configure loopback for all ports *** */
1777 struct cmd_config_loopback_all {
1778 	cmdline_fixed_string_t port;
1779 	cmdline_fixed_string_t keyword;
1780 	cmdline_fixed_string_t all;
1781 	cmdline_fixed_string_t item;
1782 	uint32_t mode;
1783 };
1784 
1785 static void
1786 cmd_config_loopback_all_parsed(void *parsed_result,
1787 			__rte_unused struct cmdline *cl,
1788 			__rte_unused void *data)
1789 {
1790 	struct cmd_config_loopback_all *res = parsed_result;
1791 	portid_t pid;
1792 
1793 	if (!all_ports_stopped()) {
1794 		printf("Please stop all ports first\n");
1795 		return;
1796 	}
1797 
1798 	RTE_ETH_FOREACH_DEV(pid) {
1799 		ports[pid].dev_conf.lpbk_mode = res->mode;
1800 	}
1801 
1802 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1803 }
1804 
1805 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1806 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1807 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1808 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1809 							"config");
1810 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1811 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1812 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1813 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1814 							"loopback");
1815 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1816 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1817 
1818 cmdline_parse_inst_t cmd_config_loopback_all = {
1819 	.f = cmd_config_loopback_all_parsed,
1820 	.data = NULL,
1821 	.help_str = "port config all loopback <mode>",
1822 	.tokens = {
1823 		(void *)&cmd_config_loopback_all_port,
1824 		(void *)&cmd_config_loopback_all_keyword,
1825 		(void *)&cmd_config_loopback_all_all,
1826 		(void *)&cmd_config_loopback_all_item,
1827 		(void *)&cmd_config_loopback_all_mode,
1828 		NULL,
1829 	},
1830 };
1831 
1832 /* *** configure loopback for specific port *** */
1833 struct cmd_config_loopback_specific {
1834 	cmdline_fixed_string_t port;
1835 	cmdline_fixed_string_t keyword;
1836 	uint16_t port_id;
1837 	cmdline_fixed_string_t item;
1838 	uint32_t mode;
1839 };
1840 
1841 static void
1842 cmd_config_loopback_specific_parsed(void *parsed_result,
1843 				__rte_unused struct cmdline *cl,
1844 				__rte_unused void *data)
1845 {
1846 	struct cmd_config_loopback_specific *res = parsed_result;
1847 
1848 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1849 		return;
1850 
1851 	if (!port_is_stopped(res->port_id)) {
1852 		printf("Please stop port %u first\n", res->port_id);
1853 		return;
1854 	}
1855 
1856 	ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1857 
1858 	cmd_reconfig_device_queue(res->port_id, 1, 1);
1859 }
1860 
1861 
1862 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1863 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1864 								"port");
1865 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1866 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1867 								"config");
1868 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1869 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1870 								UINT16);
1871 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1872 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1873 								"loopback");
1874 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1875 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1876 			      UINT32);
1877 
1878 cmdline_parse_inst_t cmd_config_loopback_specific = {
1879 	.f = cmd_config_loopback_specific_parsed,
1880 	.data = NULL,
1881 	.help_str = "port config <port_id> loopback <mode>",
1882 	.tokens = {
1883 		(void *)&cmd_config_loopback_specific_port,
1884 		(void *)&cmd_config_loopback_specific_keyword,
1885 		(void *)&cmd_config_loopback_specific_id,
1886 		(void *)&cmd_config_loopback_specific_item,
1887 		(void *)&cmd_config_loopback_specific_mode,
1888 		NULL,
1889 	},
1890 };
1891 
1892 /* *** configure txq/rxq, txd/rxd *** */
1893 struct cmd_config_rx_tx {
1894 	cmdline_fixed_string_t port;
1895 	cmdline_fixed_string_t keyword;
1896 	cmdline_fixed_string_t all;
1897 	cmdline_fixed_string_t name;
1898 	uint16_t value;
1899 };
1900 
1901 static void
1902 cmd_config_rx_tx_parsed(void *parsed_result,
1903 			__rte_unused struct cmdline *cl,
1904 			__rte_unused void *data)
1905 {
1906 	struct cmd_config_rx_tx *res = parsed_result;
1907 
1908 	if (!all_ports_stopped()) {
1909 		printf("Please stop all ports first\n");
1910 		return;
1911 	}
1912 	if (!strcmp(res->name, "rxq")) {
1913 		if (!res->value && !nb_txq) {
1914 			printf("Warning: Either rx or tx queues should be non zero\n");
1915 			return;
1916 		}
1917 		if (check_nb_rxq(res->value) != 0)
1918 			return;
1919 		nb_rxq = res->value;
1920 	}
1921 	else if (!strcmp(res->name, "txq")) {
1922 		if (!res->value && !nb_rxq) {
1923 			printf("Warning: Either rx or tx queues should be non zero\n");
1924 			return;
1925 		}
1926 		if (check_nb_txq(res->value) != 0)
1927 			return;
1928 		nb_txq = res->value;
1929 	}
1930 	else if (!strcmp(res->name, "rxd")) {
1931 		if (check_nb_rxd(res->value) != 0)
1932 			return;
1933 		nb_rxd = res->value;
1934 	} else if (!strcmp(res->name, "txd")) {
1935 		if (check_nb_txd(res->value) != 0)
1936 			return;
1937 
1938 		nb_txd = res->value;
1939 	} else {
1940 		printf("Unknown parameter\n");
1941 		return;
1942 	}
1943 
1944 	fwd_config_setup();
1945 
1946 	init_port_config();
1947 
1948 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1949 }
1950 
1951 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1952 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1953 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1954 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1955 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1956 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1957 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1958 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1959 						"rxq#txq#rxd#txd");
1960 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1961 	TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1962 
1963 cmdline_parse_inst_t cmd_config_rx_tx = {
1964 	.f = cmd_config_rx_tx_parsed,
1965 	.data = NULL,
1966 	.help_str = "port config all rxq|txq|rxd|txd <value>",
1967 	.tokens = {
1968 		(void *)&cmd_config_rx_tx_port,
1969 		(void *)&cmd_config_rx_tx_keyword,
1970 		(void *)&cmd_config_rx_tx_all,
1971 		(void *)&cmd_config_rx_tx_name,
1972 		(void *)&cmd_config_rx_tx_value,
1973 		NULL,
1974 	},
1975 };
1976 
1977 /* *** config max packet length *** */
1978 struct cmd_config_max_pkt_len_result {
1979 	cmdline_fixed_string_t port;
1980 	cmdline_fixed_string_t keyword;
1981 	cmdline_fixed_string_t all;
1982 	cmdline_fixed_string_t name;
1983 	uint32_t value;
1984 };
1985 
1986 static void
1987 cmd_config_max_pkt_len_parsed(void *parsed_result,
1988 				__rte_unused struct cmdline *cl,
1989 				__rte_unused void *data)
1990 {
1991 	struct cmd_config_max_pkt_len_result *res = parsed_result;
1992 	portid_t pid;
1993 
1994 	if (!all_ports_stopped()) {
1995 		printf("Please stop all ports first\n");
1996 		return;
1997 	}
1998 
1999 	RTE_ETH_FOREACH_DEV(pid) {
2000 		struct rte_port *port = &ports[pid];
2001 		uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2002 
2003 		if (!strcmp(res->name, "max-pkt-len")) {
2004 			if (res->value < RTE_ETHER_MIN_LEN) {
2005 				printf("max-pkt-len can not be less than %d\n",
2006 						RTE_ETHER_MIN_LEN);
2007 				return;
2008 			}
2009 			if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2010 				return;
2011 
2012 			port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2013 			if (res->value > RTE_ETHER_MAX_LEN)
2014 				rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2015 			else
2016 				rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2017 			port->dev_conf.rxmode.offloads = rx_offloads;
2018 		} else {
2019 			printf("Unknown parameter\n");
2020 			return;
2021 		}
2022 	}
2023 
2024 	init_port_config();
2025 
2026 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2027 }
2028 
2029 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2030 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2031 								"port");
2032 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2033 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2034 								"config");
2035 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2036 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2037 								"all");
2038 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2039 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2040 								"max-pkt-len");
2041 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2042 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2043 								UINT32);
2044 
2045 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2046 	.f = cmd_config_max_pkt_len_parsed,
2047 	.data = NULL,
2048 	.help_str = "port config all max-pkt-len <value>",
2049 	.tokens = {
2050 		(void *)&cmd_config_max_pkt_len_port,
2051 		(void *)&cmd_config_max_pkt_len_keyword,
2052 		(void *)&cmd_config_max_pkt_len_all,
2053 		(void *)&cmd_config_max_pkt_len_name,
2054 		(void *)&cmd_config_max_pkt_len_value,
2055 		NULL,
2056 	},
2057 };
2058 
2059 /* *** config max LRO aggregated packet size *** */
2060 struct cmd_config_max_lro_pkt_size_result {
2061 	cmdline_fixed_string_t port;
2062 	cmdline_fixed_string_t keyword;
2063 	cmdline_fixed_string_t all;
2064 	cmdline_fixed_string_t name;
2065 	uint32_t value;
2066 };
2067 
2068 static void
2069 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2070 				__rte_unused struct cmdline *cl,
2071 				__rte_unused void *data)
2072 {
2073 	struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2074 	portid_t pid;
2075 
2076 	if (!all_ports_stopped()) {
2077 		printf("Please stop all ports first\n");
2078 		return;
2079 	}
2080 
2081 	RTE_ETH_FOREACH_DEV(pid) {
2082 		struct rte_port *port = &ports[pid];
2083 
2084 		if (!strcmp(res->name, "max-lro-pkt-size")) {
2085 			if (res->value ==
2086 					port->dev_conf.rxmode.max_lro_pkt_size)
2087 				return;
2088 
2089 			port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2090 		} else {
2091 			printf("Unknown parameter\n");
2092 			return;
2093 		}
2094 	}
2095 
2096 	init_port_config();
2097 
2098 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2099 }
2100 
2101 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2102 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2103 				 port, "port");
2104 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2105 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2106 				 keyword, "config");
2107 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2108 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2109 				 all, "all");
2110 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2111 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2112 				 name, "max-lro-pkt-size");
2113 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2114 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2115 			      value, UINT32);
2116 
2117 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2118 	.f = cmd_config_max_lro_pkt_size_parsed,
2119 	.data = NULL,
2120 	.help_str = "port config all max-lro-pkt-size <value>",
2121 	.tokens = {
2122 		(void *)&cmd_config_max_lro_pkt_size_port,
2123 		(void *)&cmd_config_max_lro_pkt_size_keyword,
2124 		(void *)&cmd_config_max_lro_pkt_size_all,
2125 		(void *)&cmd_config_max_lro_pkt_size_name,
2126 		(void *)&cmd_config_max_lro_pkt_size_value,
2127 		NULL,
2128 	},
2129 };
2130 
2131 /* *** configure port MTU *** */
2132 struct cmd_config_mtu_result {
2133 	cmdline_fixed_string_t port;
2134 	cmdline_fixed_string_t keyword;
2135 	cmdline_fixed_string_t mtu;
2136 	portid_t port_id;
2137 	uint16_t value;
2138 };
2139 
2140 static void
2141 cmd_config_mtu_parsed(void *parsed_result,
2142 		      __rte_unused struct cmdline *cl,
2143 		      __rte_unused void *data)
2144 {
2145 	struct cmd_config_mtu_result *res = parsed_result;
2146 
2147 	if (res->value < RTE_ETHER_MIN_LEN) {
2148 		printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2149 		return;
2150 	}
2151 	port_mtu_set(res->port_id, res->value);
2152 }
2153 
2154 cmdline_parse_token_string_t cmd_config_mtu_port =
2155 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2156 				 "port");
2157 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2158 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2159 				 "config");
2160 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2161 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2162 				 "mtu");
2163 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2164 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2165 cmdline_parse_token_num_t cmd_config_mtu_value =
2166 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2167 
2168 cmdline_parse_inst_t cmd_config_mtu = {
2169 	.f = cmd_config_mtu_parsed,
2170 	.data = NULL,
2171 	.help_str = "port config mtu <port_id> <value>",
2172 	.tokens = {
2173 		(void *)&cmd_config_mtu_port,
2174 		(void *)&cmd_config_mtu_keyword,
2175 		(void *)&cmd_config_mtu_mtu,
2176 		(void *)&cmd_config_mtu_port_id,
2177 		(void *)&cmd_config_mtu_value,
2178 		NULL,
2179 	},
2180 };
2181 
2182 /* *** configure rx mode *** */
2183 struct cmd_config_rx_mode_flag {
2184 	cmdline_fixed_string_t port;
2185 	cmdline_fixed_string_t keyword;
2186 	cmdline_fixed_string_t all;
2187 	cmdline_fixed_string_t name;
2188 	cmdline_fixed_string_t value;
2189 };
2190 
2191 static void
2192 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2193 				__rte_unused struct cmdline *cl,
2194 				__rte_unused void *data)
2195 {
2196 	struct cmd_config_rx_mode_flag *res = parsed_result;
2197 
2198 	if (!all_ports_stopped()) {
2199 		printf("Please stop all ports first\n");
2200 		return;
2201 	}
2202 
2203 	if (!strcmp(res->name, "drop-en")) {
2204 		if (!strcmp(res->value, "on"))
2205 			rx_drop_en = 1;
2206 		else if (!strcmp(res->value, "off"))
2207 			rx_drop_en = 0;
2208 		else {
2209 			printf("Unknown parameter\n");
2210 			return;
2211 		}
2212 	} else {
2213 		printf("Unknown parameter\n");
2214 		return;
2215 	}
2216 
2217 	init_port_config();
2218 
2219 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2220 }
2221 
2222 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2223 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2224 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2225 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2226 								"config");
2227 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2228 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2229 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2230 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2231 					"drop-en");
2232 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2233 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2234 							"on#off");
2235 
2236 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2237 	.f = cmd_config_rx_mode_flag_parsed,
2238 	.data = NULL,
2239 	.help_str = "port config all drop-en on|off",
2240 	.tokens = {
2241 		(void *)&cmd_config_rx_mode_flag_port,
2242 		(void *)&cmd_config_rx_mode_flag_keyword,
2243 		(void *)&cmd_config_rx_mode_flag_all,
2244 		(void *)&cmd_config_rx_mode_flag_name,
2245 		(void *)&cmd_config_rx_mode_flag_value,
2246 		NULL,
2247 	},
2248 };
2249 
2250 /* *** configure rss *** */
2251 struct cmd_config_rss {
2252 	cmdline_fixed_string_t port;
2253 	cmdline_fixed_string_t keyword;
2254 	cmdline_fixed_string_t all;
2255 	cmdline_fixed_string_t name;
2256 	cmdline_fixed_string_t value;
2257 };
2258 
2259 static void
2260 cmd_config_rss_parsed(void *parsed_result,
2261 			__rte_unused struct cmdline *cl,
2262 			__rte_unused void *data)
2263 {
2264 	struct cmd_config_rss *res = parsed_result;
2265 	struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2266 	struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2267 	int use_default = 0;
2268 	int all_updated = 1;
2269 	int diag;
2270 	uint16_t i;
2271 	int ret;
2272 
2273 	if (!strcmp(res->value, "all"))
2274 		rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2275 			ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2276 			ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2277 			ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2278 	else if (!strcmp(res->value, "eth"))
2279 		rss_conf.rss_hf = ETH_RSS_ETH;
2280 	else if (!strcmp(res->value, "vlan"))
2281 		rss_conf.rss_hf = ETH_RSS_VLAN;
2282 	else if (!strcmp(res->value, "ip"))
2283 		rss_conf.rss_hf = ETH_RSS_IP;
2284 	else if (!strcmp(res->value, "udp"))
2285 		rss_conf.rss_hf = ETH_RSS_UDP;
2286 	else if (!strcmp(res->value, "tcp"))
2287 		rss_conf.rss_hf = ETH_RSS_TCP;
2288 	else if (!strcmp(res->value, "sctp"))
2289 		rss_conf.rss_hf = ETH_RSS_SCTP;
2290 	else if (!strcmp(res->value, "ether"))
2291 		rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2292 	else if (!strcmp(res->value, "port"))
2293 		rss_conf.rss_hf = ETH_RSS_PORT;
2294 	else if (!strcmp(res->value, "vxlan"))
2295 		rss_conf.rss_hf = ETH_RSS_VXLAN;
2296 	else if (!strcmp(res->value, "geneve"))
2297 		rss_conf.rss_hf = ETH_RSS_GENEVE;
2298 	else if (!strcmp(res->value, "nvgre"))
2299 		rss_conf.rss_hf = ETH_RSS_NVGRE;
2300 	else if (!strcmp(res->value, "l3-src-only"))
2301 		rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2302 	else if (!strcmp(res->value, "l3-dst-only"))
2303 		rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2304 	else if (!strcmp(res->value, "l4-src-only"))
2305 		rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2306 	else if (!strcmp(res->value, "l4-dst-only"))
2307 		rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2308 	else if (!strcmp(res->value, "l2-src-only"))
2309 		rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2310 	else if (!strcmp(res->value, "l2-dst-only"))
2311 		rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2312 	else if (!strcmp(res->value, "l2tpv3"))
2313 		rss_conf.rss_hf = ETH_RSS_L2TPV3;
2314 	else if (!strcmp(res->value, "esp"))
2315 		rss_conf.rss_hf = ETH_RSS_ESP;
2316 	else if (!strcmp(res->value, "ah"))
2317 		rss_conf.rss_hf = ETH_RSS_AH;
2318 	else if (!strcmp(res->value, "pfcp"))
2319 		rss_conf.rss_hf = ETH_RSS_PFCP;
2320 	else if (!strcmp(res->value, "pppoe"))
2321 		rss_conf.rss_hf = ETH_RSS_PPPOE;
2322 	else if (!strcmp(res->value, "gtpu"))
2323 		rss_conf.rss_hf = ETH_RSS_GTPU;
2324 	else if (!strcmp(res->value, "none"))
2325 		rss_conf.rss_hf = 0;
2326 	else if (!strcmp(res->value, "default"))
2327 		use_default = 1;
2328 	else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2329 						atoi(res->value) < 64)
2330 		rss_conf.rss_hf = 1ULL << atoi(res->value);
2331 	else {
2332 		printf("Unknown parameter\n");
2333 		return;
2334 	}
2335 	rss_conf.rss_key = NULL;
2336 	/* Update global configuration for RSS types. */
2337 	RTE_ETH_FOREACH_DEV(i) {
2338 		struct rte_eth_rss_conf local_rss_conf;
2339 
2340 		ret = eth_dev_info_get_print_err(i, &dev_info);
2341 		if (ret != 0)
2342 			return;
2343 
2344 		if (use_default)
2345 			rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2346 
2347 		local_rss_conf = rss_conf;
2348 		local_rss_conf.rss_hf = rss_conf.rss_hf &
2349 			dev_info.flow_type_rss_offloads;
2350 		if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2351 			printf("Port %u modified RSS hash function based on hardware support,"
2352 				"requested:%#"PRIx64" configured:%#"PRIx64"\n",
2353 				i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2354 		}
2355 		diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2356 		if (diag < 0) {
2357 			all_updated = 0;
2358 			printf("Configuration of RSS hash at ethernet port %d "
2359 				"failed with error (%d): %s.\n",
2360 				i, -diag, strerror(-diag));
2361 		}
2362 	}
2363 	if (all_updated && !use_default) {
2364 		rss_hf = rss_conf.rss_hf;
2365 		printf("rss_hf %#"PRIx64"\n", rss_hf);
2366 	}
2367 }
2368 
2369 cmdline_parse_token_string_t cmd_config_rss_port =
2370 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2371 cmdline_parse_token_string_t cmd_config_rss_keyword =
2372 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2373 cmdline_parse_token_string_t cmd_config_rss_all =
2374 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2375 cmdline_parse_token_string_t cmd_config_rss_name =
2376 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2377 cmdline_parse_token_string_t cmd_config_rss_value =
2378 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2379 
2380 cmdline_parse_inst_t cmd_config_rss = {
2381 	.f = cmd_config_rss_parsed,
2382 	.data = NULL,
2383 	.help_str = "port config all rss "
2384 		"all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2385 		"nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|<flowtype_id>",
2386 	.tokens = {
2387 		(void *)&cmd_config_rss_port,
2388 		(void *)&cmd_config_rss_keyword,
2389 		(void *)&cmd_config_rss_all,
2390 		(void *)&cmd_config_rss_name,
2391 		(void *)&cmd_config_rss_value,
2392 		NULL,
2393 	},
2394 };
2395 
2396 /* *** configure rss hash key *** */
2397 struct cmd_config_rss_hash_key {
2398 	cmdline_fixed_string_t port;
2399 	cmdline_fixed_string_t config;
2400 	portid_t port_id;
2401 	cmdline_fixed_string_t rss_hash_key;
2402 	cmdline_fixed_string_t rss_type;
2403 	cmdline_fixed_string_t key;
2404 };
2405 
2406 static uint8_t
2407 hexa_digit_to_value(char hexa_digit)
2408 {
2409 	if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2410 		return (uint8_t) (hexa_digit - '0');
2411 	if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2412 		return (uint8_t) ((hexa_digit - 'a') + 10);
2413 	if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2414 		return (uint8_t) ((hexa_digit - 'A') + 10);
2415 	/* Invalid hexa digit */
2416 	return 0xFF;
2417 }
2418 
2419 static uint8_t
2420 parse_and_check_key_hexa_digit(char *key, int idx)
2421 {
2422 	uint8_t hexa_v;
2423 
2424 	hexa_v = hexa_digit_to_value(key[idx]);
2425 	if (hexa_v == 0xFF)
2426 		printf("invalid key: character %c at position %d is not a "
2427 		       "valid hexa digit\n", key[idx], idx);
2428 	return hexa_v;
2429 }
2430 
2431 static void
2432 cmd_config_rss_hash_key_parsed(void *parsed_result,
2433 			       __rte_unused struct cmdline *cl,
2434 			       __rte_unused void *data)
2435 {
2436 	struct cmd_config_rss_hash_key *res = parsed_result;
2437 	uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2438 	uint8_t xdgt0;
2439 	uint8_t xdgt1;
2440 	int i;
2441 	struct rte_eth_dev_info dev_info;
2442 	uint8_t hash_key_size;
2443 	uint32_t key_len;
2444 	int ret;
2445 
2446 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2447 	if (ret != 0)
2448 		return;
2449 
2450 	if (dev_info.hash_key_size > 0 &&
2451 			dev_info.hash_key_size <= sizeof(hash_key))
2452 		hash_key_size = dev_info.hash_key_size;
2453 	else {
2454 		printf("dev_info did not provide a valid hash key size\n");
2455 		return;
2456 	}
2457 	/* Check the length of the RSS hash key */
2458 	key_len = strlen(res->key);
2459 	if (key_len != (hash_key_size * 2)) {
2460 		printf("key length: %d invalid - key must be a string of %d"
2461 			   " hexa-decimal numbers\n",
2462 			   (int) key_len, hash_key_size * 2);
2463 		return;
2464 	}
2465 	/* Translate RSS hash key into binary representation */
2466 	for (i = 0; i < hash_key_size; i++) {
2467 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2468 		if (xdgt0 == 0xFF)
2469 			return;
2470 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2471 		if (xdgt1 == 0xFF)
2472 			return;
2473 		hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2474 	}
2475 	port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2476 			hash_key_size);
2477 }
2478 
2479 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2480 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2481 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2482 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2483 				 "config");
2484 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2485 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2486 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2487 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2488 				 rss_hash_key, "rss-hash-key");
2489 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2490 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2491 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2492 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2493 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2494 				 "ipv6-tcp-ex#ipv6-udp-ex#"
2495 				 "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2496 				 "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2497 				 "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2498 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2499 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2500 
2501 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2502 	.f = cmd_config_rss_hash_key_parsed,
2503 	.data = NULL,
2504 	.help_str = "port config <port_id> rss-hash-key "
2505 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2506 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2507 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2508 		"l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2509 		"l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2510 		"l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2511 		"<string of hex digits (variable length, NIC dependent)>",
2512 	.tokens = {
2513 		(void *)&cmd_config_rss_hash_key_port,
2514 		(void *)&cmd_config_rss_hash_key_config,
2515 		(void *)&cmd_config_rss_hash_key_port_id,
2516 		(void *)&cmd_config_rss_hash_key_rss_hash_key,
2517 		(void *)&cmd_config_rss_hash_key_rss_type,
2518 		(void *)&cmd_config_rss_hash_key_value,
2519 		NULL,
2520 	},
2521 };
2522 
2523 /* *** configure port rxq/txq ring size *** */
2524 struct cmd_config_rxtx_ring_size {
2525 	cmdline_fixed_string_t port;
2526 	cmdline_fixed_string_t config;
2527 	portid_t portid;
2528 	cmdline_fixed_string_t rxtxq;
2529 	uint16_t qid;
2530 	cmdline_fixed_string_t rsize;
2531 	uint16_t size;
2532 };
2533 
2534 static void
2535 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2536 				 __rte_unused struct cmdline *cl,
2537 				 __rte_unused void *data)
2538 {
2539 	struct cmd_config_rxtx_ring_size *res = parsed_result;
2540 	struct rte_port *port;
2541 	uint8_t isrx;
2542 
2543 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2544 		return;
2545 
2546 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2547 		printf("Invalid port id\n");
2548 		return;
2549 	}
2550 
2551 	port = &ports[res->portid];
2552 
2553 	if (!strcmp(res->rxtxq, "rxq"))
2554 		isrx = 1;
2555 	else if (!strcmp(res->rxtxq, "txq"))
2556 		isrx = 0;
2557 	else {
2558 		printf("Unknown parameter\n");
2559 		return;
2560 	}
2561 
2562 	if (isrx && rx_queue_id_is_invalid(res->qid))
2563 		return;
2564 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2565 		return;
2566 
2567 	if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2568 		printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2569 		       rx_free_thresh);
2570 		return;
2571 	}
2572 
2573 	if (isrx)
2574 		port->nb_rx_desc[res->qid] = res->size;
2575 	else
2576 		port->nb_tx_desc[res->qid] = res->size;
2577 
2578 	cmd_reconfig_device_queue(res->portid, 0, 1);
2579 }
2580 
2581 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2582 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2583 				 port, "port");
2584 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2585 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2586 				 config, "config");
2587 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2588 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2589 				 portid, UINT16);
2590 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2591 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2592 				 rxtxq, "rxq#txq");
2593 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2594 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2595 			      qid, UINT16);
2596 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2597 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2598 				 rsize, "ring_size");
2599 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2600 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2601 			      size, UINT16);
2602 
2603 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2604 	.f = cmd_config_rxtx_ring_size_parsed,
2605 	.data = NULL,
2606 	.help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2607 	.tokens = {
2608 		(void *)&cmd_config_rxtx_ring_size_port,
2609 		(void *)&cmd_config_rxtx_ring_size_config,
2610 		(void *)&cmd_config_rxtx_ring_size_portid,
2611 		(void *)&cmd_config_rxtx_ring_size_rxtxq,
2612 		(void *)&cmd_config_rxtx_ring_size_qid,
2613 		(void *)&cmd_config_rxtx_ring_size_rsize,
2614 		(void *)&cmd_config_rxtx_ring_size_size,
2615 		NULL,
2616 	},
2617 };
2618 
2619 /* *** configure port rxq/txq start/stop *** */
2620 struct cmd_config_rxtx_queue {
2621 	cmdline_fixed_string_t port;
2622 	portid_t portid;
2623 	cmdline_fixed_string_t rxtxq;
2624 	uint16_t qid;
2625 	cmdline_fixed_string_t opname;
2626 };
2627 
2628 static void
2629 cmd_config_rxtx_queue_parsed(void *parsed_result,
2630 			__rte_unused struct cmdline *cl,
2631 			__rte_unused void *data)
2632 {
2633 	struct cmd_config_rxtx_queue *res = parsed_result;
2634 	uint8_t isrx;
2635 	uint8_t isstart;
2636 	int ret = 0;
2637 
2638 	if (test_done == 0) {
2639 		printf("Please stop forwarding first\n");
2640 		return;
2641 	}
2642 
2643 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2644 		return;
2645 
2646 	if (port_is_started(res->portid) != 1) {
2647 		printf("Please start port %u first\n", res->portid);
2648 		return;
2649 	}
2650 
2651 	if (!strcmp(res->rxtxq, "rxq"))
2652 		isrx = 1;
2653 	else if (!strcmp(res->rxtxq, "txq"))
2654 		isrx = 0;
2655 	else {
2656 		printf("Unknown parameter\n");
2657 		return;
2658 	}
2659 
2660 	if (isrx && rx_queue_id_is_invalid(res->qid))
2661 		return;
2662 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2663 		return;
2664 
2665 	if (!strcmp(res->opname, "start"))
2666 		isstart = 1;
2667 	else if (!strcmp(res->opname, "stop"))
2668 		isstart = 0;
2669 	else {
2670 		printf("Unknown parameter\n");
2671 		return;
2672 	}
2673 
2674 	if (isstart && isrx)
2675 		ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2676 	else if (!isstart && isrx)
2677 		ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2678 	else if (isstart && !isrx)
2679 		ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2680 	else
2681 		ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2682 
2683 	if (ret == -ENOTSUP)
2684 		printf("Function not supported in PMD driver\n");
2685 }
2686 
2687 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2688 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2689 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2690 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2691 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2692 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2693 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2694 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2695 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2696 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2697 						"start#stop");
2698 
2699 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2700 	.f = cmd_config_rxtx_queue_parsed,
2701 	.data = NULL,
2702 	.help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2703 	.tokens = {
2704 		(void *)&cmd_config_rxtx_queue_port,
2705 		(void *)&cmd_config_rxtx_queue_portid,
2706 		(void *)&cmd_config_rxtx_queue_rxtxq,
2707 		(void *)&cmd_config_rxtx_queue_qid,
2708 		(void *)&cmd_config_rxtx_queue_opname,
2709 		NULL,
2710 	},
2711 };
2712 
2713 /* *** configure port rxq/txq deferred start on/off *** */
2714 struct cmd_config_deferred_start_rxtx_queue {
2715 	cmdline_fixed_string_t port;
2716 	portid_t port_id;
2717 	cmdline_fixed_string_t rxtxq;
2718 	uint16_t qid;
2719 	cmdline_fixed_string_t opname;
2720 	cmdline_fixed_string_t state;
2721 };
2722 
2723 static void
2724 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2725 			__rte_unused struct cmdline *cl,
2726 			__rte_unused void *data)
2727 {
2728 	struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2729 	struct rte_port *port;
2730 	uint8_t isrx;
2731 	uint8_t ison;
2732 	uint8_t needreconfig = 0;
2733 
2734 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2735 		return;
2736 
2737 	if (port_is_started(res->port_id) != 0) {
2738 		printf("Please stop port %u first\n", res->port_id);
2739 		return;
2740 	}
2741 
2742 	port = &ports[res->port_id];
2743 
2744 	isrx = !strcmp(res->rxtxq, "rxq");
2745 
2746 	if (isrx && rx_queue_id_is_invalid(res->qid))
2747 		return;
2748 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2749 		return;
2750 
2751 	ison = !strcmp(res->state, "on");
2752 
2753 	if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2754 		port->rx_conf[res->qid].rx_deferred_start = ison;
2755 		needreconfig = 1;
2756 	} else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2757 		port->tx_conf[res->qid].tx_deferred_start = ison;
2758 		needreconfig = 1;
2759 	}
2760 
2761 	if (needreconfig)
2762 		cmd_reconfig_device_queue(res->port_id, 0, 1);
2763 }
2764 
2765 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2766 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2767 						port, "port");
2768 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2769 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2770 						port_id, UINT16);
2771 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2772 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2773 						rxtxq, "rxq#txq");
2774 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2775 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2776 						qid, UINT16);
2777 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2778 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2779 						opname, "deferred_start");
2780 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2781 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2782 						state, "on#off");
2783 
2784 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2785 	.f = cmd_config_deferred_start_rxtx_queue_parsed,
2786 	.data = NULL,
2787 	.help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2788 	.tokens = {
2789 		(void *)&cmd_config_deferred_start_rxtx_queue_port,
2790 		(void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2791 		(void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2792 		(void *)&cmd_config_deferred_start_rxtx_queue_qid,
2793 		(void *)&cmd_config_deferred_start_rxtx_queue_opname,
2794 		(void *)&cmd_config_deferred_start_rxtx_queue_state,
2795 		NULL,
2796 	},
2797 };
2798 
2799 /* *** configure port rxq/txq setup *** */
2800 struct cmd_setup_rxtx_queue {
2801 	cmdline_fixed_string_t port;
2802 	portid_t portid;
2803 	cmdline_fixed_string_t rxtxq;
2804 	uint16_t qid;
2805 	cmdline_fixed_string_t setup;
2806 };
2807 
2808 /* Common CLI fields for queue setup */
2809 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2810 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2811 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2812 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2813 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2814 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2815 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2816 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2817 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2818 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2819 
2820 static void
2821 cmd_setup_rxtx_queue_parsed(
2822 	void *parsed_result,
2823 	__rte_unused struct cmdline *cl,
2824 	__rte_unused void *data)
2825 {
2826 	struct cmd_setup_rxtx_queue *res = parsed_result;
2827 	struct rte_port *port;
2828 	struct rte_mempool *mp;
2829 	unsigned int socket_id;
2830 	uint8_t isrx = 0;
2831 	int ret;
2832 
2833 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2834 		return;
2835 
2836 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2837 		printf("Invalid port id\n");
2838 		return;
2839 	}
2840 
2841 	if (!strcmp(res->rxtxq, "rxq"))
2842 		isrx = 1;
2843 	else if (!strcmp(res->rxtxq, "txq"))
2844 		isrx = 0;
2845 	else {
2846 		printf("Unknown parameter\n");
2847 		return;
2848 	}
2849 
2850 	if (isrx && rx_queue_id_is_invalid(res->qid)) {
2851 		printf("Invalid rx queue\n");
2852 		return;
2853 	} else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2854 		printf("Invalid tx queue\n");
2855 		return;
2856 	}
2857 
2858 	port = &ports[res->portid];
2859 	if (isrx) {
2860 		socket_id = rxring_numa[res->portid];
2861 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2862 			socket_id = port->socket_id;
2863 
2864 		mp = mbuf_pool_find(socket_id);
2865 		if (mp == NULL) {
2866 			printf("Failed to setup RX queue: "
2867 				"No mempool allocation"
2868 				" on the socket %d\n",
2869 				rxring_numa[res->portid]);
2870 			return;
2871 		}
2872 		ret = rte_eth_rx_queue_setup(res->portid,
2873 					     res->qid,
2874 					     port->nb_rx_desc[res->qid],
2875 					     socket_id,
2876 					     &port->rx_conf[res->qid],
2877 					     mp);
2878 		if (ret)
2879 			printf("Failed to setup RX queue\n");
2880 	} else {
2881 		socket_id = txring_numa[res->portid];
2882 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2883 			socket_id = port->socket_id;
2884 
2885 		ret = rte_eth_tx_queue_setup(res->portid,
2886 					     res->qid,
2887 					     port->nb_tx_desc[res->qid],
2888 					     socket_id,
2889 					     &port->tx_conf[res->qid]);
2890 		if (ret)
2891 			printf("Failed to setup TX queue\n");
2892 	}
2893 }
2894 
2895 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2896 	.f = cmd_setup_rxtx_queue_parsed,
2897 	.data = NULL,
2898 	.help_str = "port <port_id> rxq|txq <queue_idx> setup",
2899 	.tokens = {
2900 		(void *)&cmd_setup_rxtx_queue_port,
2901 		(void *)&cmd_setup_rxtx_queue_portid,
2902 		(void *)&cmd_setup_rxtx_queue_rxtxq,
2903 		(void *)&cmd_setup_rxtx_queue_qid,
2904 		(void *)&cmd_setup_rxtx_queue_setup,
2905 		NULL,
2906 	},
2907 };
2908 
2909 
2910 /* *** Configure RSS RETA *** */
2911 struct cmd_config_rss_reta {
2912 	cmdline_fixed_string_t port;
2913 	cmdline_fixed_string_t keyword;
2914 	portid_t port_id;
2915 	cmdline_fixed_string_t name;
2916 	cmdline_fixed_string_t list_name;
2917 	cmdline_fixed_string_t list_of_items;
2918 };
2919 
2920 static int
2921 parse_reta_config(const char *str,
2922 		  struct rte_eth_rss_reta_entry64 *reta_conf,
2923 		  uint16_t nb_entries)
2924 {
2925 	int i;
2926 	unsigned size;
2927 	uint16_t hash_index, idx, shift;
2928 	uint16_t nb_queue;
2929 	char s[256];
2930 	const char *p, *p0 = str;
2931 	char *end;
2932 	enum fieldnames {
2933 		FLD_HASH_INDEX = 0,
2934 		FLD_QUEUE,
2935 		_NUM_FLD
2936 	};
2937 	unsigned long int_fld[_NUM_FLD];
2938 	char *str_fld[_NUM_FLD];
2939 
2940 	while ((p = strchr(p0,'(')) != NULL) {
2941 		++p;
2942 		if((p0 = strchr(p,')')) == NULL)
2943 			return -1;
2944 
2945 		size = p0 - p;
2946 		if(size >= sizeof(s))
2947 			return -1;
2948 
2949 		snprintf(s, sizeof(s), "%.*s", size, p);
2950 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2951 			return -1;
2952 		for (i = 0; i < _NUM_FLD; i++) {
2953 			errno = 0;
2954 			int_fld[i] = strtoul(str_fld[i], &end, 0);
2955 			if (errno != 0 || end == str_fld[i] ||
2956 					int_fld[i] > 65535)
2957 				return -1;
2958 		}
2959 
2960 		hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2961 		nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2962 
2963 		if (hash_index >= nb_entries) {
2964 			printf("Invalid RETA hash index=%d\n", hash_index);
2965 			return -1;
2966 		}
2967 
2968 		idx = hash_index / RTE_RETA_GROUP_SIZE;
2969 		shift = hash_index % RTE_RETA_GROUP_SIZE;
2970 		reta_conf[idx].mask |= (1ULL << shift);
2971 		reta_conf[idx].reta[shift] = nb_queue;
2972 	}
2973 
2974 	return 0;
2975 }
2976 
2977 static void
2978 cmd_set_rss_reta_parsed(void *parsed_result,
2979 			__rte_unused struct cmdline *cl,
2980 			__rte_unused void *data)
2981 {
2982 	int ret;
2983 	struct rte_eth_dev_info dev_info;
2984 	struct rte_eth_rss_reta_entry64 reta_conf[8];
2985 	struct cmd_config_rss_reta *res = parsed_result;
2986 
2987 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2988 	if (ret != 0)
2989 		return;
2990 
2991 	if (dev_info.reta_size == 0) {
2992 		printf("Redirection table size is 0 which is "
2993 					"invalid for RSS\n");
2994 		return;
2995 	} else
2996 		printf("The reta size of port %d is %u\n",
2997 			res->port_id, dev_info.reta_size);
2998 	if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2999 		printf("Currently do not support more than %u entries of "
3000 			"redirection table\n", ETH_RSS_RETA_SIZE_512);
3001 		return;
3002 	}
3003 
3004 	memset(reta_conf, 0, sizeof(reta_conf));
3005 	if (!strcmp(res->list_name, "reta")) {
3006 		if (parse_reta_config(res->list_of_items, reta_conf,
3007 						dev_info.reta_size)) {
3008 			printf("Invalid RSS Redirection Table "
3009 					"config entered\n");
3010 			return;
3011 		}
3012 		ret = rte_eth_dev_rss_reta_update(res->port_id,
3013 				reta_conf, dev_info.reta_size);
3014 		if (ret != 0)
3015 			printf("Bad redirection table parameter, "
3016 					"return code = %d \n", ret);
3017 	}
3018 }
3019 
3020 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3021 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3022 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3023 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3024 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3025 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3026 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3027 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3028 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3029 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3030 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3031         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3032                                  NULL);
3033 cmdline_parse_inst_t cmd_config_rss_reta = {
3034 	.f = cmd_set_rss_reta_parsed,
3035 	.data = NULL,
3036 	.help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3037 	.tokens = {
3038 		(void *)&cmd_config_rss_reta_port,
3039 		(void *)&cmd_config_rss_reta_keyword,
3040 		(void *)&cmd_config_rss_reta_port_id,
3041 		(void *)&cmd_config_rss_reta_name,
3042 		(void *)&cmd_config_rss_reta_list_name,
3043 		(void *)&cmd_config_rss_reta_list_of_items,
3044 		NULL,
3045 	},
3046 };
3047 
3048 /* *** SHOW PORT RETA INFO *** */
3049 struct cmd_showport_reta {
3050 	cmdline_fixed_string_t show;
3051 	cmdline_fixed_string_t port;
3052 	portid_t port_id;
3053 	cmdline_fixed_string_t rss;
3054 	cmdline_fixed_string_t reta;
3055 	uint16_t size;
3056 	cmdline_fixed_string_t list_of_items;
3057 };
3058 
3059 static int
3060 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3061 			   uint16_t nb_entries,
3062 			   char *str)
3063 {
3064 	uint32_t size;
3065 	const char *p, *p0 = str;
3066 	char s[256];
3067 	char *end;
3068 	char *str_fld[8];
3069 	uint16_t i;
3070 	uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3071 			RTE_RETA_GROUP_SIZE;
3072 	int ret;
3073 
3074 	p = strchr(p0, '(');
3075 	if (p == NULL)
3076 		return -1;
3077 	p++;
3078 	p0 = strchr(p, ')');
3079 	if (p0 == NULL)
3080 		return -1;
3081 	size = p0 - p;
3082 	if (size >= sizeof(s)) {
3083 		printf("The string size exceeds the internal buffer size\n");
3084 		return -1;
3085 	}
3086 	snprintf(s, sizeof(s), "%.*s", size, p);
3087 	ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3088 	if (ret <= 0 || ret != num) {
3089 		printf("The bits of masks do not match the number of "
3090 					"reta entries: %u\n", num);
3091 		return -1;
3092 	}
3093 	for (i = 0; i < ret; i++)
3094 		conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3095 
3096 	return 0;
3097 }
3098 
3099 static void
3100 cmd_showport_reta_parsed(void *parsed_result,
3101 			 __rte_unused struct cmdline *cl,
3102 			 __rte_unused void *data)
3103 {
3104 	struct cmd_showport_reta *res = parsed_result;
3105 	struct rte_eth_rss_reta_entry64 reta_conf[8];
3106 	struct rte_eth_dev_info dev_info;
3107 	uint16_t max_reta_size;
3108 	int ret;
3109 
3110 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3111 	if (ret != 0)
3112 		return;
3113 
3114 	max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3115 	if (res->size == 0 || res->size > max_reta_size) {
3116 		printf("Invalid redirection table size: %u (1-%u)\n",
3117 			res->size, max_reta_size);
3118 		return;
3119 	}
3120 
3121 	memset(reta_conf, 0, sizeof(reta_conf));
3122 	if (showport_parse_reta_config(reta_conf, res->size,
3123 				res->list_of_items) < 0) {
3124 		printf("Invalid string: %s for reta masks\n",
3125 					res->list_of_items);
3126 		return;
3127 	}
3128 	port_rss_reta_info(res->port_id, reta_conf, res->size);
3129 }
3130 
3131 cmdline_parse_token_string_t cmd_showport_reta_show =
3132 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3133 cmdline_parse_token_string_t cmd_showport_reta_port =
3134 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3135 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3136 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3137 cmdline_parse_token_string_t cmd_showport_reta_rss =
3138 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3139 cmdline_parse_token_string_t cmd_showport_reta_reta =
3140 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3141 cmdline_parse_token_num_t cmd_showport_reta_size =
3142 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3143 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3144 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3145 					list_of_items, NULL);
3146 
3147 cmdline_parse_inst_t cmd_showport_reta = {
3148 	.f = cmd_showport_reta_parsed,
3149 	.data = NULL,
3150 	.help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3151 	.tokens = {
3152 		(void *)&cmd_showport_reta_show,
3153 		(void *)&cmd_showport_reta_port,
3154 		(void *)&cmd_showport_reta_port_id,
3155 		(void *)&cmd_showport_reta_rss,
3156 		(void *)&cmd_showport_reta_reta,
3157 		(void *)&cmd_showport_reta_size,
3158 		(void *)&cmd_showport_reta_list_of_items,
3159 		NULL,
3160 	},
3161 };
3162 
3163 /* *** Show RSS hash configuration *** */
3164 struct cmd_showport_rss_hash {
3165 	cmdline_fixed_string_t show;
3166 	cmdline_fixed_string_t port;
3167 	portid_t port_id;
3168 	cmdline_fixed_string_t rss_hash;
3169 	cmdline_fixed_string_t rss_type;
3170 	cmdline_fixed_string_t key; /* optional argument */
3171 };
3172 
3173 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3174 				__rte_unused struct cmdline *cl,
3175 				void *show_rss_key)
3176 {
3177 	struct cmd_showport_rss_hash *res = parsed_result;
3178 
3179 	port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3180 }
3181 
3182 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3183 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3184 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3185 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3186 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3187 	TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3188 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3189 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3190 				 "rss-hash");
3191 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3192 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3193 
3194 cmdline_parse_inst_t cmd_showport_rss_hash = {
3195 	.f = cmd_showport_rss_hash_parsed,
3196 	.data = NULL,
3197 	.help_str = "show port <port_id> rss-hash",
3198 	.tokens = {
3199 		(void *)&cmd_showport_rss_hash_show,
3200 		(void *)&cmd_showport_rss_hash_port,
3201 		(void *)&cmd_showport_rss_hash_port_id,
3202 		(void *)&cmd_showport_rss_hash_rss_hash,
3203 		NULL,
3204 	},
3205 };
3206 
3207 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3208 	.f = cmd_showport_rss_hash_parsed,
3209 	.data = (void *)1,
3210 	.help_str = "show port <port_id> rss-hash key",
3211 	.tokens = {
3212 		(void *)&cmd_showport_rss_hash_show,
3213 		(void *)&cmd_showport_rss_hash_port,
3214 		(void *)&cmd_showport_rss_hash_port_id,
3215 		(void *)&cmd_showport_rss_hash_rss_hash,
3216 		(void *)&cmd_showport_rss_hash_rss_key,
3217 		NULL,
3218 	},
3219 };
3220 
3221 /* *** Configure DCB *** */
3222 struct cmd_config_dcb {
3223 	cmdline_fixed_string_t port;
3224 	cmdline_fixed_string_t config;
3225 	portid_t port_id;
3226 	cmdline_fixed_string_t dcb;
3227 	cmdline_fixed_string_t vt;
3228 	cmdline_fixed_string_t vt_en;
3229 	uint8_t num_tcs;
3230 	cmdline_fixed_string_t pfc;
3231 	cmdline_fixed_string_t pfc_en;
3232 };
3233 
3234 static void
3235 cmd_config_dcb_parsed(void *parsed_result,
3236                         __rte_unused struct cmdline *cl,
3237                         __rte_unused void *data)
3238 {
3239 	struct cmd_config_dcb *res = parsed_result;
3240 	portid_t port_id = res->port_id;
3241 	struct rte_port *port;
3242 	uint8_t pfc_en;
3243 	int ret;
3244 
3245 	port = &ports[port_id];
3246 	/** Check if the port is not started **/
3247 	if (port->port_status != RTE_PORT_STOPPED) {
3248 		printf("Please stop port %d first\n", port_id);
3249 		return;
3250 	}
3251 
3252 	if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3253 		printf("The invalid number of traffic class,"
3254 			" only 4 or 8 allowed.\n");
3255 		return;
3256 	}
3257 
3258 	if (nb_fwd_lcores < res->num_tcs) {
3259 		printf("nb_cores shouldn't be less than number of TCs.\n");
3260 		return;
3261 	}
3262 	if (!strncmp(res->pfc_en, "on", 2))
3263 		pfc_en = 1;
3264 	else
3265 		pfc_en = 0;
3266 
3267 	/* DCB in VT mode */
3268 	if (!strncmp(res->vt_en, "on", 2))
3269 		ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3270 				(enum rte_eth_nb_tcs)res->num_tcs,
3271 				pfc_en);
3272 	else
3273 		ret = init_port_dcb_config(port_id, DCB_ENABLED,
3274 				(enum rte_eth_nb_tcs)res->num_tcs,
3275 				pfc_en);
3276 
3277 
3278 	if (ret != 0) {
3279 		printf("Cannot initialize network ports.\n");
3280 		return;
3281 	}
3282 
3283 	cmd_reconfig_device_queue(port_id, 1, 1);
3284 }
3285 
3286 cmdline_parse_token_string_t cmd_config_dcb_port =
3287         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3288 cmdline_parse_token_string_t cmd_config_dcb_config =
3289         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3290 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3291 	TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3292 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3293         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3294 cmdline_parse_token_string_t cmd_config_dcb_vt =
3295         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3296 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3297         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3298 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3299         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3300 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3301         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3302 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3303         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3304 
3305 cmdline_parse_inst_t cmd_config_dcb = {
3306 	.f = cmd_config_dcb_parsed,
3307 	.data = NULL,
3308 	.help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3309 	.tokens = {
3310 		(void *)&cmd_config_dcb_port,
3311 		(void *)&cmd_config_dcb_config,
3312 		(void *)&cmd_config_dcb_port_id,
3313 		(void *)&cmd_config_dcb_dcb,
3314 		(void *)&cmd_config_dcb_vt,
3315 		(void *)&cmd_config_dcb_vt_en,
3316 		(void *)&cmd_config_dcb_num_tcs,
3317 		(void *)&cmd_config_dcb_pfc,
3318 		(void *)&cmd_config_dcb_pfc_en,
3319                 NULL,
3320         },
3321 };
3322 
3323 /* *** configure number of packets per burst *** */
3324 struct cmd_config_burst {
3325 	cmdline_fixed_string_t port;
3326 	cmdline_fixed_string_t keyword;
3327 	cmdline_fixed_string_t all;
3328 	cmdline_fixed_string_t name;
3329 	uint16_t value;
3330 };
3331 
3332 static void
3333 cmd_config_burst_parsed(void *parsed_result,
3334 			__rte_unused struct cmdline *cl,
3335 			__rte_unused void *data)
3336 {
3337 	struct cmd_config_burst *res = parsed_result;
3338 	struct rte_eth_dev_info dev_info;
3339 	uint16_t rec_nb_pkts;
3340 	int ret;
3341 
3342 	if (!all_ports_stopped()) {
3343 		printf("Please stop all ports first\n");
3344 		return;
3345 	}
3346 
3347 	if (!strcmp(res->name, "burst")) {
3348 		if (res->value == 0) {
3349 			/* If user gives a value of zero, query the PMD for
3350 			 * its recommended Rx burst size. Testpmd uses a single
3351 			 * size for all ports, so assume all ports are the same
3352 			 * NIC model and use the values from Port 0.
3353 			 */
3354 			ret = eth_dev_info_get_print_err(0, &dev_info);
3355 			if (ret != 0)
3356 				return;
3357 
3358 			rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3359 
3360 			if (rec_nb_pkts == 0) {
3361 				printf("PMD does not recommend a burst size.\n"
3362 					"User provided value must be between"
3363 					" 1 and %d\n", MAX_PKT_BURST);
3364 				return;
3365 			} else if (rec_nb_pkts > MAX_PKT_BURST) {
3366 				printf("PMD recommended burst size of %d"
3367 					" exceeds maximum value of %d\n",
3368 					rec_nb_pkts, MAX_PKT_BURST);
3369 				return;
3370 			}
3371 			printf("Using PMD-provided burst value of %d\n",
3372 				rec_nb_pkts);
3373 			nb_pkt_per_burst = rec_nb_pkts;
3374 		} else if (res->value > MAX_PKT_BURST) {
3375 			printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3376 			return;
3377 		} else
3378 			nb_pkt_per_burst = res->value;
3379 	} else {
3380 		printf("Unknown parameter\n");
3381 		return;
3382 	}
3383 
3384 	init_port_config();
3385 
3386 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3387 }
3388 
3389 cmdline_parse_token_string_t cmd_config_burst_port =
3390 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3391 cmdline_parse_token_string_t cmd_config_burst_keyword =
3392 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3393 cmdline_parse_token_string_t cmd_config_burst_all =
3394 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3395 cmdline_parse_token_string_t cmd_config_burst_name =
3396 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3397 cmdline_parse_token_num_t cmd_config_burst_value =
3398 	TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3399 
3400 cmdline_parse_inst_t cmd_config_burst = {
3401 	.f = cmd_config_burst_parsed,
3402 	.data = NULL,
3403 	.help_str = "port config all burst <value>",
3404 	.tokens = {
3405 		(void *)&cmd_config_burst_port,
3406 		(void *)&cmd_config_burst_keyword,
3407 		(void *)&cmd_config_burst_all,
3408 		(void *)&cmd_config_burst_name,
3409 		(void *)&cmd_config_burst_value,
3410 		NULL,
3411 	},
3412 };
3413 
3414 /* *** configure rx/tx queues *** */
3415 struct cmd_config_thresh {
3416 	cmdline_fixed_string_t port;
3417 	cmdline_fixed_string_t keyword;
3418 	cmdline_fixed_string_t all;
3419 	cmdline_fixed_string_t name;
3420 	uint8_t value;
3421 };
3422 
3423 static void
3424 cmd_config_thresh_parsed(void *parsed_result,
3425 			__rte_unused struct cmdline *cl,
3426 			__rte_unused void *data)
3427 {
3428 	struct cmd_config_thresh *res = parsed_result;
3429 
3430 	if (!all_ports_stopped()) {
3431 		printf("Please stop all ports first\n");
3432 		return;
3433 	}
3434 
3435 	if (!strcmp(res->name, "txpt"))
3436 		tx_pthresh = res->value;
3437 	else if(!strcmp(res->name, "txht"))
3438 		tx_hthresh = res->value;
3439 	else if(!strcmp(res->name, "txwt"))
3440 		tx_wthresh = res->value;
3441 	else if(!strcmp(res->name, "rxpt"))
3442 		rx_pthresh = res->value;
3443 	else if(!strcmp(res->name, "rxht"))
3444 		rx_hthresh = res->value;
3445 	else if(!strcmp(res->name, "rxwt"))
3446 		rx_wthresh = res->value;
3447 	else {
3448 		printf("Unknown parameter\n");
3449 		return;
3450 	}
3451 
3452 	init_port_config();
3453 
3454 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3455 }
3456 
3457 cmdline_parse_token_string_t cmd_config_thresh_port =
3458 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3459 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3460 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3461 cmdline_parse_token_string_t cmd_config_thresh_all =
3462 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3463 cmdline_parse_token_string_t cmd_config_thresh_name =
3464 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3465 				"txpt#txht#txwt#rxpt#rxht#rxwt");
3466 cmdline_parse_token_num_t cmd_config_thresh_value =
3467 	TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3468 
3469 cmdline_parse_inst_t cmd_config_thresh = {
3470 	.f = cmd_config_thresh_parsed,
3471 	.data = NULL,
3472 	.help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3473 	.tokens = {
3474 		(void *)&cmd_config_thresh_port,
3475 		(void *)&cmd_config_thresh_keyword,
3476 		(void *)&cmd_config_thresh_all,
3477 		(void *)&cmd_config_thresh_name,
3478 		(void *)&cmd_config_thresh_value,
3479 		NULL,
3480 	},
3481 };
3482 
3483 /* *** configure free/rs threshold *** */
3484 struct cmd_config_threshold {
3485 	cmdline_fixed_string_t port;
3486 	cmdline_fixed_string_t keyword;
3487 	cmdline_fixed_string_t all;
3488 	cmdline_fixed_string_t name;
3489 	uint16_t value;
3490 };
3491 
3492 static void
3493 cmd_config_threshold_parsed(void *parsed_result,
3494 			__rte_unused struct cmdline *cl,
3495 			__rte_unused void *data)
3496 {
3497 	struct cmd_config_threshold *res = parsed_result;
3498 
3499 	if (!all_ports_stopped()) {
3500 		printf("Please stop all ports first\n");
3501 		return;
3502 	}
3503 
3504 	if (!strcmp(res->name, "txfreet"))
3505 		tx_free_thresh = res->value;
3506 	else if (!strcmp(res->name, "txrst"))
3507 		tx_rs_thresh = res->value;
3508 	else if (!strcmp(res->name, "rxfreet"))
3509 		rx_free_thresh = res->value;
3510 	else {
3511 		printf("Unknown parameter\n");
3512 		return;
3513 	}
3514 
3515 	init_port_config();
3516 
3517 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3518 }
3519 
3520 cmdline_parse_token_string_t cmd_config_threshold_port =
3521 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3522 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3523 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3524 								"config");
3525 cmdline_parse_token_string_t cmd_config_threshold_all =
3526 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3527 cmdline_parse_token_string_t cmd_config_threshold_name =
3528 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3529 						"txfreet#txrst#rxfreet");
3530 cmdline_parse_token_num_t cmd_config_threshold_value =
3531 	TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3532 
3533 cmdline_parse_inst_t cmd_config_threshold = {
3534 	.f = cmd_config_threshold_parsed,
3535 	.data = NULL,
3536 	.help_str = "port config all txfreet|txrst|rxfreet <value>",
3537 	.tokens = {
3538 		(void *)&cmd_config_threshold_port,
3539 		(void *)&cmd_config_threshold_keyword,
3540 		(void *)&cmd_config_threshold_all,
3541 		(void *)&cmd_config_threshold_name,
3542 		(void *)&cmd_config_threshold_value,
3543 		NULL,
3544 	},
3545 };
3546 
3547 /* *** stop *** */
3548 struct cmd_stop_result {
3549 	cmdline_fixed_string_t stop;
3550 };
3551 
3552 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3553 			    __rte_unused struct cmdline *cl,
3554 			    __rte_unused void *data)
3555 {
3556 	stop_packet_forwarding();
3557 }
3558 
3559 cmdline_parse_token_string_t cmd_stop_stop =
3560 	TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3561 
3562 cmdline_parse_inst_t cmd_stop = {
3563 	.f = cmd_stop_parsed,
3564 	.data = NULL,
3565 	.help_str = "stop: Stop packet forwarding",
3566 	.tokens = {
3567 		(void *)&cmd_stop_stop,
3568 		NULL,
3569 	},
3570 };
3571 
3572 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3573 
3574 unsigned int
3575 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3576 		unsigned int *parsed_items, int check_unique_values)
3577 {
3578 	unsigned int nb_item;
3579 	unsigned int value;
3580 	unsigned int i;
3581 	unsigned int j;
3582 	int value_ok;
3583 	char c;
3584 
3585 	/*
3586 	 * First parse all items in the list and store their value.
3587 	 */
3588 	value = 0;
3589 	nb_item = 0;
3590 	value_ok = 0;
3591 	for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3592 		c = str[i];
3593 		if ((c >= '0') && (c <= '9')) {
3594 			value = (unsigned int) (value * 10 + (c - '0'));
3595 			value_ok = 1;
3596 			continue;
3597 		}
3598 		if (c != ',') {
3599 			printf("character %c is not a decimal digit\n", c);
3600 			return 0;
3601 		}
3602 		if (! value_ok) {
3603 			printf("No valid value before comma\n");
3604 			return 0;
3605 		}
3606 		if (nb_item < max_items) {
3607 			parsed_items[nb_item] = value;
3608 			value_ok = 0;
3609 			value = 0;
3610 		}
3611 		nb_item++;
3612 	}
3613 	if (nb_item >= max_items) {
3614 		printf("Number of %s = %u > %u (maximum items)\n",
3615 		       item_name, nb_item + 1, max_items);
3616 		return 0;
3617 	}
3618 	parsed_items[nb_item++] = value;
3619 	if (! check_unique_values)
3620 		return nb_item;
3621 
3622 	/*
3623 	 * Then, check that all values in the list are differents.
3624 	 * No optimization here...
3625 	 */
3626 	for (i = 0; i < nb_item; i++) {
3627 		for (j = i + 1; j < nb_item; j++) {
3628 			if (parsed_items[j] == parsed_items[i]) {
3629 				printf("duplicated %s %u at index %u and %u\n",
3630 				       item_name, parsed_items[i], i, j);
3631 				return 0;
3632 			}
3633 		}
3634 	}
3635 	return nb_item;
3636 }
3637 
3638 struct cmd_set_list_result {
3639 	cmdline_fixed_string_t cmd_keyword;
3640 	cmdline_fixed_string_t list_name;
3641 	cmdline_fixed_string_t list_of_items;
3642 };
3643 
3644 static void cmd_set_list_parsed(void *parsed_result,
3645 				__rte_unused struct cmdline *cl,
3646 				__rte_unused void *data)
3647 {
3648 	struct cmd_set_list_result *res;
3649 	union {
3650 		unsigned int lcorelist[RTE_MAX_LCORE];
3651 		unsigned int portlist[RTE_MAX_ETHPORTS];
3652 	} parsed_items;
3653 	unsigned int nb_item;
3654 
3655 	if (test_done == 0) {
3656 		printf("Please stop forwarding first\n");
3657 		return;
3658 	}
3659 
3660 	res = parsed_result;
3661 	if (!strcmp(res->list_name, "corelist")) {
3662 		nb_item = parse_item_list(res->list_of_items, "core",
3663 					  RTE_MAX_LCORE,
3664 					  parsed_items.lcorelist, 1);
3665 		if (nb_item > 0) {
3666 			set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3667 			fwd_config_setup();
3668 		}
3669 		return;
3670 	}
3671 	if (!strcmp(res->list_name, "portlist")) {
3672 		nb_item = parse_item_list(res->list_of_items, "port",
3673 					  RTE_MAX_ETHPORTS,
3674 					  parsed_items.portlist, 1);
3675 		if (nb_item > 0) {
3676 			set_fwd_ports_list(parsed_items.portlist, nb_item);
3677 			fwd_config_setup();
3678 		}
3679 	}
3680 }
3681 
3682 cmdline_parse_token_string_t cmd_set_list_keyword =
3683 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3684 				 "set");
3685 cmdline_parse_token_string_t cmd_set_list_name =
3686 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3687 				 "corelist#portlist");
3688 cmdline_parse_token_string_t cmd_set_list_of_items =
3689 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3690 				 NULL);
3691 
3692 cmdline_parse_inst_t cmd_set_fwd_list = {
3693 	.f = cmd_set_list_parsed,
3694 	.data = NULL,
3695 	.help_str = "set corelist|portlist <list0[,list1]*>",
3696 	.tokens = {
3697 		(void *)&cmd_set_list_keyword,
3698 		(void *)&cmd_set_list_name,
3699 		(void *)&cmd_set_list_of_items,
3700 		NULL,
3701 	},
3702 };
3703 
3704 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3705 
3706 struct cmd_setmask_result {
3707 	cmdline_fixed_string_t set;
3708 	cmdline_fixed_string_t mask;
3709 	uint64_t hexavalue;
3710 };
3711 
3712 static void cmd_set_mask_parsed(void *parsed_result,
3713 				__rte_unused struct cmdline *cl,
3714 				__rte_unused void *data)
3715 {
3716 	struct cmd_setmask_result *res = parsed_result;
3717 
3718 	if (test_done == 0) {
3719 		printf("Please stop forwarding first\n");
3720 		return;
3721 	}
3722 	if (!strcmp(res->mask, "coremask")) {
3723 		set_fwd_lcores_mask(res->hexavalue);
3724 		fwd_config_setup();
3725 	} else if (!strcmp(res->mask, "portmask")) {
3726 		set_fwd_ports_mask(res->hexavalue);
3727 		fwd_config_setup();
3728 	}
3729 }
3730 
3731 cmdline_parse_token_string_t cmd_setmask_set =
3732 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3733 cmdline_parse_token_string_t cmd_setmask_mask =
3734 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3735 				 "coremask#portmask");
3736 cmdline_parse_token_num_t cmd_setmask_value =
3737 	TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3738 
3739 cmdline_parse_inst_t cmd_set_fwd_mask = {
3740 	.f = cmd_set_mask_parsed,
3741 	.data = NULL,
3742 	.help_str = "set coremask|portmask <hexadecimal value>",
3743 	.tokens = {
3744 		(void *)&cmd_setmask_set,
3745 		(void *)&cmd_setmask_mask,
3746 		(void *)&cmd_setmask_value,
3747 		NULL,
3748 	},
3749 };
3750 
3751 /*
3752  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3753  */
3754 struct cmd_set_result {
3755 	cmdline_fixed_string_t set;
3756 	cmdline_fixed_string_t what;
3757 	uint16_t value;
3758 };
3759 
3760 static void cmd_set_parsed(void *parsed_result,
3761 			   __rte_unused struct cmdline *cl,
3762 			   __rte_unused void *data)
3763 {
3764 	struct cmd_set_result *res = parsed_result;
3765 	if (!strcmp(res->what, "nbport")) {
3766 		set_fwd_ports_number(res->value);
3767 		fwd_config_setup();
3768 	} else if (!strcmp(res->what, "nbcore")) {
3769 		set_fwd_lcores_number(res->value);
3770 		fwd_config_setup();
3771 	} else if (!strcmp(res->what, "burst"))
3772 		set_nb_pkt_per_burst(res->value);
3773 	else if (!strcmp(res->what, "verbose"))
3774 		set_verbose_level(res->value);
3775 }
3776 
3777 cmdline_parse_token_string_t cmd_set_set =
3778 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3779 cmdline_parse_token_string_t cmd_set_what =
3780 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3781 				 "nbport#nbcore#burst#verbose");
3782 cmdline_parse_token_num_t cmd_set_value =
3783 	TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3784 
3785 cmdline_parse_inst_t cmd_set_numbers = {
3786 	.f = cmd_set_parsed,
3787 	.data = NULL,
3788 	.help_str = "set nbport|nbcore|burst|verbose <value>",
3789 	.tokens = {
3790 		(void *)&cmd_set_set,
3791 		(void *)&cmd_set_what,
3792 		(void *)&cmd_set_value,
3793 		NULL,
3794 	},
3795 };
3796 
3797 /* *** SET LOG LEVEL CONFIGURATION *** */
3798 
3799 struct cmd_set_log_result {
3800 	cmdline_fixed_string_t set;
3801 	cmdline_fixed_string_t log;
3802 	cmdline_fixed_string_t type;
3803 	uint32_t level;
3804 };
3805 
3806 static void
3807 cmd_set_log_parsed(void *parsed_result,
3808 		   __rte_unused struct cmdline *cl,
3809 		   __rte_unused void *data)
3810 {
3811 	struct cmd_set_log_result *res;
3812 	int ret;
3813 
3814 	res = parsed_result;
3815 	if (!strcmp(res->type, "global"))
3816 		rte_log_set_global_level(res->level);
3817 	else {
3818 		ret = rte_log_set_level_regexp(res->type, res->level);
3819 		if (ret < 0)
3820 			printf("Unable to set log level\n");
3821 	}
3822 }
3823 
3824 cmdline_parse_token_string_t cmd_set_log_set =
3825 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3826 cmdline_parse_token_string_t cmd_set_log_log =
3827 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3828 cmdline_parse_token_string_t cmd_set_log_type =
3829 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3830 cmdline_parse_token_num_t cmd_set_log_level =
3831 	TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3832 
3833 cmdline_parse_inst_t cmd_set_log = {
3834 	.f = cmd_set_log_parsed,
3835 	.data = NULL,
3836 	.help_str = "set log global|<type> <level>",
3837 	.tokens = {
3838 		(void *)&cmd_set_log_set,
3839 		(void *)&cmd_set_log_log,
3840 		(void *)&cmd_set_log_type,
3841 		(void *)&cmd_set_log_level,
3842 		NULL,
3843 	},
3844 };
3845 
3846 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3847 
3848 struct cmd_set_txpkts_result {
3849 	cmdline_fixed_string_t cmd_keyword;
3850 	cmdline_fixed_string_t txpkts;
3851 	cmdline_fixed_string_t seg_lengths;
3852 };
3853 
3854 static void
3855 cmd_set_txpkts_parsed(void *parsed_result,
3856 		      __rte_unused struct cmdline *cl,
3857 		      __rte_unused void *data)
3858 {
3859 	struct cmd_set_txpkts_result *res;
3860 	unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3861 	unsigned int nb_segs;
3862 
3863 	res = parsed_result;
3864 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3865 				  RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3866 	if (nb_segs > 0)
3867 		set_tx_pkt_segments(seg_lengths, nb_segs);
3868 }
3869 
3870 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3871 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3872 				 cmd_keyword, "set");
3873 cmdline_parse_token_string_t cmd_set_txpkts_name =
3874 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3875 				 txpkts, "txpkts");
3876 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3877 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3878 				 seg_lengths, NULL);
3879 
3880 cmdline_parse_inst_t cmd_set_txpkts = {
3881 	.f = cmd_set_txpkts_parsed,
3882 	.data = NULL,
3883 	.help_str = "set txpkts <len0[,len1]*>",
3884 	.tokens = {
3885 		(void *)&cmd_set_txpkts_keyword,
3886 		(void *)&cmd_set_txpkts_name,
3887 		(void *)&cmd_set_txpkts_lengths,
3888 		NULL,
3889 	},
3890 };
3891 
3892 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3893 
3894 struct cmd_set_txsplit_result {
3895 	cmdline_fixed_string_t cmd_keyword;
3896 	cmdline_fixed_string_t txsplit;
3897 	cmdline_fixed_string_t mode;
3898 };
3899 
3900 static void
3901 cmd_set_txsplit_parsed(void *parsed_result,
3902 		      __rte_unused struct cmdline *cl,
3903 		      __rte_unused void *data)
3904 {
3905 	struct cmd_set_txsplit_result *res;
3906 
3907 	res = parsed_result;
3908 	set_tx_pkt_split(res->mode);
3909 }
3910 
3911 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3912 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3913 				 cmd_keyword, "set");
3914 cmdline_parse_token_string_t cmd_set_txsplit_name =
3915 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3916 				 txsplit, "txsplit");
3917 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3918 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3919 				 mode, NULL);
3920 
3921 cmdline_parse_inst_t cmd_set_txsplit = {
3922 	.f = cmd_set_txsplit_parsed,
3923 	.data = NULL,
3924 	.help_str = "set txsplit on|off|rand",
3925 	.tokens = {
3926 		(void *)&cmd_set_txsplit_keyword,
3927 		(void *)&cmd_set_txsplit_name,
3928 		(void *)&cmd_set_txsplit_mode,
3929 		NULL,
3930 	},
3931 };
3932 
3933 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3934 struct cmd_rx_vlan_filter_all_result {
3935 	cmdline_fixed_string_t rx_vlan;
3936 	cmdline_fixed_string_t what;
3937 	cmdline_fixed_string_t all;
3938 	portid_t port_id;
3939 };
3940 
3941 static void
3942 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3943 			      __rte_unused struct cmdline *cl,
3944 			      __rte_unused void *data)
3945 {
3946 	struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3947 
3948 	if (!strcmp(res->what, "add"))
3949 		rx_vlan_all_filter_set(res->port_id, 1);
3950 	else
3951 		rx_vlan_all_filter_set(res->port_id, 0);
3952 }
3953 
3954 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3955 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3956 				 rx_vlan, "rx_vlan");
3957 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3958 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3959 				 what, "add#rm");
3960 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3961 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3962 				 all, "all");
3963 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3964 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3965 			      port_id, UINT16);
3966 
3967 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3968 	.f = cmd_rx_vlan_filter_all_parsed,
3969 	.data = NULL,
3970 	.help_str = "rx_vlan add|rm all <port_id>: "
3971 		"Add/Remove all identifiers to/from the set of VLAN "
3972 		"identifiers filtered by a port",
3973 	.tokens = {
3974 		(void *)&cmd_rx_vlan_filter_all_rx_vlan,
3975 		(void *)&cmd_rx_vlan_filter_all_what,
3976 		(void *)&cmd_rx_vlan_filter_all_all,
3977 		(void *)&cmd_rx_vlan_filter_all_portid,
3978 		NULL,
3979 	},
3980 };
3981 
3982 /* *** VLAN OFFLOAD SET ON A PORT *** */
3983 struct cmd_vlan_offload_result {
3984 	cmdline_fixed_string_t vlan;
3985 	cmdline_fixed_string_t set;
3986 	cmdline_fixed_string_t vlan_type;
3987 	cmdline_fixed_string_t what;
3988 	cmdline_fixed_string_t on;
3989 	cmdline_fixed_string_t port_id;
3990 };
3991 
3992 static void
3993 cmd_vlan_offload_parsed(void *parsed_result,
3994 			  __rte_unused struct cmdline *cl,
3995 			  __rte_unused void *data)
3996 {
3997 	int on;
3998 	struct cmd_vlan_offload_result *res = parsed_result;
3999 	char *str;
4000 	int i, len = 0;
4001 	portid_t port_id = 0;
4002 	unsigned int tmp;
4003 
4004 	str = res->port_id;
4005 	len = strnlen(str, STR_TOKEN_SIZE);
4006 	i = 0;
4007 	/* Get port_id first */
4008 	while(i < len){
4009 		if(str[i] == ',')
4010 			break;
4011 
4012 		i++;
4013 	}
4014 	str[i]='\0';
4015 	tmp = strtoul(str, NULL, 0);
4016 	/* If port_id greater that what portid_t can represent, return */
4017 	if(tmp >= RTE_MAX_ETHPORTS)
4018 		return;
4019 	port_id = (portid_t)tmp;
4020 
4021 	if (!strcmp(res->on, "on"))
4022 		on = 1;
4023 	else
4024 		on = 0;
4025 
4026 	if (!strcmp(res->what, "strip"))
4027 		rx_vlan_strip_set(port_id,  on);
4028 	else if(!strcmp(res->what, "stripq")){
4029 		uint16_t queue_id = 0;
4030 
4031 		/* No queue_id, return */
4032 		if(i + 1 >= len) {
4033 			printf("must specify (port,queue_id)\n");
4034 			return;
4035 		}
4036 		tmp = strtoul(str + i + 1, NULL, 0);
4037 		/* If queue_id greater that what 16-bits can represent, return */
4038 		if(tmp > 0xffff)
4039 			return;
4040 
4041 		queue_id = (uint16_t)tmp;
4042 		rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4043 	}
4044 	else if (!strcmp(res->what, "filter"))
4045 		rx_vlan_filter_set(port_id, on);
4046 	else if (!strcmp(res->what, "qinq_strip"))
4047 		rx_vlan_qinq_strip_set(port_id, on);
4048 	else
4049 		vlan_extend_set(port_id, on);
4050 
4051 	return;
4052 }
4053 
4054 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4055 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4056 				 vlan, "vlan");
4057 cmdline_parse_token_string_t cmd_vlan_offload_set =
4058 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4059 				 set, "set");
4060 cmdline_parse_token_string_t cmd_vlan_offload_what =
4061 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4062 				what, "strip#filter#qinq_strip#extend#stripq");
4063 cmdline_parse_token_string_t cmd_vlan_offload_on =
4064 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4065 			      on, "on#off");
4066 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4067 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4068 			      port_id, NULL);
4069 
4070 cmdline_parse_inst_t cmd_vlan_offload = {
4071 	.f = cmd_vlan_offload_parsed,
4072 	.data = NULL,
4073 	.help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4074 		"<port_id[,queue_id]>: "
4075 		"Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4076 	.tokens = {
4077 		(void *)&cmd_vlan_offload_vlan,
4078 		(void *)&cmd_vlan_offload_set,
4079 		(void *)&cmd_vlan_offload_what,
4080 		(void *)&cmd_vlan_offload_on,
4081 		(void *)&cmd_vlan_offload_portid,
4082 		NULL,
4083 	},
4084 };
4085 
4086 /* *** VLAN TPID SET ON A PORT *** */
4087 struct cmd_vlan_tpid_result {
4088 	cmdline_fixed_string_t vlan;
4089 	cmdline_fixed_string_t set;
4090 	cmdline_fixed_string_t vlan_type;
4091 	cmdline_fixed_string_t what;
4092 	uint16_t tp_id;
4093 	portid_t port_id;
4094 };
4095 
4096 static void
4097 cmd_vlan_tpid_parsed(void *parsed_result,
4098 			  __rte_unused struct cmdline *cl,
4099 			  __rte_unused void *data)
4100 {
4101 	struct cmd_vlan_tpid_result *res = parsed_result;
4102 	enum rte_vlan_type vlan_type;
4103 
4104 	if (!strcmp(res->vlan_type, "inner"))
4105 		vlan_type = ETH_VLAN_TYPE_INNER;
4106 	else if (!strcmp(res->vlan_type, "outer"))
4107 		vlan_type = ETH_VLAN_TYPE_OUTER;
4108 	else {
4109 		printf("Unknown vlan type\n");
4110 		return;
4111 	}
4112 	vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4113 }
4114 
4115 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4116 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4117 				 vlan, "vlan");
4118 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4119 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4120 				 set, "set");
4121 cmdline_parse_token_string_t cmd_vlan_type =
4122 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4123 				 vlan_type, "inner#outer");
4124 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4125 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4126 				 what, "tpid");
4127 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4128 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4129 			      tp_id, UINT16);
4130 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4131 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4132 			      port_id, UINT16);
4133 
4134 cmdline_parse_inst_t cmd_vlan_tpid = {
4135 	.f = cmd_vlan_tpid_parsed,
4136 	.data = NULL,
4137 	.help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4138 		"Set the VLAN Ether type",
4139 	.tokens = {
4140 		(void *)&cmd_vlan_tpid_vlan,
4141 		(void *)&cmd_vlan_tpid_set,
4142 		(void *)&cmd_vlan_type,
4143 		(void *)&cmd_vlan_tpid_what,
4144 		(void *)&cmd_vlan_tpid_tpid,
4145 		(void *)&cmd_vlan_tpid_portid,
4146 		NULL,
4147 	},
4148 };
4149 
4150 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4151 struct cmd_rx_vlan_filter_result {
4152 	cmdline_fixed_string_t rx_vlan;
4153 	cmdline_fixed_string_t what;
4154 	uint16_t vlan_id;
4155 	portid_t port_id;
4156 };
4157 
4158 static void
4159 cmd_rx_vlan_filter_parsed(void *parsed_result,
4160 			  __rte_unused struct cmdline *cl,
4161 			  __rte_unused void *data)
4162 {
4163 	struct cmd_rx_vlan_filter_result *res = parsed_result;
4164 
4165 	if (!strcmp(res->what, "add"))
4166 		rx_vft_set(res->port_id, res->vlan_id, 1);
4167 	else
4168 		rx_vft_set(res->port_id, res->vlan_id, 0);
4169 }
4170 
4171 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4172 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4173 				 rx_vlan, "rx_vlan");
4174 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4175 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4176 				 what, "add#rm");
4177 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4178 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4179 			      vlan_id, UINT16);
4180 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4181 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4182 			      port_id, UINT16);
4183 
4184 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4185 	.f = cmd_rx_vlan_filter_parsed,
4186 	.data = NULL,
4187 	.help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4188 		"Add/Remove a VLAN identifier to/from the set of VLAN "
4189 		"identifiers filtered by a port",
4190 	.tokens = {
4191 		(void *)&cmd_rx_vlan_filter_rx_vlan,
4192 		(void *)&cmd_rx_vlan_filter_what,
4193 		(void *)&cmd_rx_vlan_filter_vlanid,
4194 		(void *)&cmd_rx_vlan_filter_portid,
4195 		NULL,
4196 	},
4197 };
4198 
4199 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4200 struct cmd_tx_vlan_set_result {
4201 	cmdline_fixed_string_t tx_vlan;
4202 	cmdline_fixed_string_t set;
4203 	portid_t port_id;
4204 	uint16_t vlan_id;
4205 };
4206 
4207 static void
4208 cmd_tx_vlan_set_parsed(void *parsed_result,
4209 		       __rte_unused struct cmdline *cl,
4210 		       __rte_unused void *data)
4211 {
4212 	struct cmd_tx_vlan_set_result *res = parsed_result;
4213 
4214 	if (!port_is_stopped(res->port_id)) {
4215 		printf("Please stop port %d first\n", res->port_id);
4216 		return;
4217 	}
4218 
4219 	tx_vlan_set(res->port_id, res->vlan_id);
4220 
4221 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4222 }
4223 
4224 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4225 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4226 				 tx_vlan, "tx_vlan");
4227 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4228 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4229 				 set, "set");
4230 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4231 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4232 			      port_id, UINT16);
4233 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4234 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4235 			      vlan_id, UINT16);
4236 
4237 cmdline_parse_inst_t cmd_tx_vlan_set = {
4238 	.f = cmd_tx_vlan_set_parsed,
4239 	.data = NULL,
4240 	.help_str = "tx_vlan set <port_id> <vlan_id>: "
4241 		"Enable hardware insertion of a single VLAN header "
4242 		"with a given TAG Identifier in packets sent on a port",
4243 	.tokens = {
4244 		(void *)&cmd_tx_vlan_set_tx_vlan,
4245 		(void *)&cmd_tx_vlan_set_set,
4246 		(void *)&cmd_tx_vlan_set_portid,
4247 		(void *)&cmd_tx_vlan_set_vlanid,
4248 		NULL,
4249 	},
4250 };
4251 
4252 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4253 struct cmd_tx_vlan_set_qinq_result {
4254 	cmdline_fixed_string_t tx_vlan;
4255 	cmdline_fixed_string_t set;
4256 	portid_t port_id;
4257 	uint16_t vlan_id;
4258 	uint16_t vlan_id_outer;
4259 };
4260 
4261 static void
4262 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4263 			    __rte_unused struct cmdline *cl,
4264 			    __rte_unused void *data)
4265 {
4266 	struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4267 
4268 	if (!port_is_stopped(res->port_id)) {
4269 		printf("Please stop port %d first\n", res->port_id);
4270 		return;
4271 	}
4272 
4273 	tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4274 
4275 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4276 }
4277 
4278 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4279 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4280 		tx_vlan, "tx_vlan");
4281 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4282 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4283 		set, "set");
4284 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4285 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4286 		port_id, UINT16);
4287 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4288 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4289 		vlan_id, UINT16);
4290 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4291 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4292 		vlan_id_outer, UINT16);
4293 
4294 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4295 	.f = cmd_tx_vlan_set_qinq_parsed,
4296 	.data = NULL,
4297 	.help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4298 		"Enable hardware insertion of double VLAN header "
4299 		"with given TAG Identifiers in packets sent on a port",
4300 	.tokens = {
4301 		(void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4302 		(void *)&cmd_tx_vlan_set_qinq_set,
4303 		(void *)&cmd_tx_vlan_set_qinq_portid,
4304 		(void *)&cmd_tx_vlan_set_qinq_vlanid,
4305 		(void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4306 		NULL,
4307 	},
4308 };
4309 
4310 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4311 struct cmd_tx_vlan_set_pvid_result {
4312 	cmdline_fixed_string_t tx_vlan;
4313 	cmdline_fixed_string_t set;
4314 	cmdline_fixed_string_t pvid;
4315 	portid_t port_id;
4316 	uint16_t vlan_id;
4317 	cmdline_fixed_string_t mode;
4318 };
4319 
4320 static void
4321 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4322 			    __rte_unused struct cmdline *cl,
4323 			    __rte_unused void *data)
4324 {
4325 	struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4326 
4327 	if (strcmp(res->mode, "on") == 0)
4328 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4329 	else
4330 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4331 }
4332 
4333 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4334 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4335 				 tx_vlan, "tx_vlan");
4336 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4337 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4338 				 set, "set");
4339 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4340 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4341 				 pvid, "pvid");
4342 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4343 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4344 			     port_id, UINT16);
4345 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4346 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4347 			      vlan_id, UINT16);
4348 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4349 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4350 				 mode, "on#off");
4351 
4352 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4353 	.f = cmd_tx_vlan_set_pvid_parsed,
4354 	.data = NULL,
4355 	.help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4356 	.tokens = {
4357 		(void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4358 		(void *)&cmd_tx_vlan_set_pvid_set,
4359 		(void *)&cmd_tx_vlan_set_pvid_pvid,
4360 		(void *)&cmd_tx_vlan_set_pvid_port_id,
4361 		(void *)&cmd_tx_vlan_set_pvid_vlan_id,
4362 		(void *)&cmd_tx_vlan_set_pvid_mode,
4363 		NULL,
4364 	},
4365 };
4366 
4367 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4368 struct cmd_tx_vlan_reset_result {
4369 	cmdline_fixed_string_t tx_vlan;
4370 	cmdline_fixed_string_t reset;
4371 	portid_t port_id;
4372 };
4373 
4374 static void
4375 cmd_tx_vlan_reset_parsed(void *parsed_result,
4376 			 __rte_unused struct cmdline *cl,
4377 			 __rte_unused void *data)
4378 {
4379 	struct cmd_tx_vlan_reset_result *res = parsed_result;
4380 
4381 	if (!port_is_stopped(res->port_id)) {
4382 		printf("Please stop port %d first\n", res->port_id);
4383 		return;
4384 	}
4385 
4386 	tx_vlan_reset(res->port_id);
4387 
4388 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4389 }
4390 
4391 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4392 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4393 				 tx_vlan, "tx_vlan");
4394 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4395 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4396 				 reset, "reset");
4397 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4398 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4399 			      port_id, UINT16);
4400 
4401 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4402 	.f = cmd_tx_vlan_reset_parsed,
4403 	.data = NULL,
4404 	.help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4405 		"VLAN header in packets sent on a port",
4406 	.tokens = {
4407 		(void *)&cmd_tx_vlan_reset_tx_vlan,
4408 		(void *)&cmd_tx_vlan_reset_reset,
4409 		(void *)&cmd_tx_vlan_reset_portid,
4410 		NULL,
4411 	},
4412 };
4413 
4414 
4415 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4416 struct cmd_csum_result {
4417 	cmdline_fixed_string_t csum;
4418 	cmdline_fixed_string_t mode;
4419 	cmdline_fixed_string_t proto;
4420 	cmdline_fixed_string_t hwsw;
4421 	portid_t port_id;
4422 };
4423 
4424 static void
4425 csum_show(int port_id)
4426 {
4427 	struct rte_eth_dev_info dev_info;
4428 	uint64_t tx_offloads;
4429 	int ret;
4430 
4431 	tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4432 	printf("Parse tunnel is %s\n",
4433 		(ports[port_id].parse_tunnel) ? "on" : "off");
4434 	printf("IP checksum offload is %s\n",
4435 		(tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4436 	printf("UDP checksum offload is %s\n",
4437 		(tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4438 	printf("TCP checksum offload is %s\n",
4439 		(tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4440 	printf("SCTP checksum offload is %s\n",
4441 		(tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4442 	printf("Outer-Ip checksum offload is %s\n",
4443 		(tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4444 	printf("Outer-Udp checksum offload is %s\n",
4445 		(tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4446 
4447 	/* display warnings if configuration is not supported by the NIC */
4448 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
4449 	if (ret != 0)
4450 		return;
4451 
4452 	if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4453 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4454 		printf("Warning: hardware IP checksum enabled but not "
4455 			"supported by port %d\n", port_id);
4456 	}
4457 	if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4458 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4459 		printf("Warning: hardware UDP checksum enabled but not "
4460 			"supported by port %d\n", port_id);
4461 	}
4462 	if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4463 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4464 		printf("Warning: hardware TCP checksum enabled but not "
4465 			"supported by port %d\n", port_id);
4466 	}
4467 	if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4468 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4469 		printf("Warning: hardware SCTP checksum enabled but not "
4470 			"supported by port %d\n", port_id);
4471 	}
4472 	if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4473 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4474 		printf("Warning: hardware outer IP checksum enabled but not "
4475 			"supported by port %d\n", port_id);
4476 	}
4477 	if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4478 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4479 			== 0) {
4480 		printf("Warning: hardware outer UDP checksum enabled but not "
4481 			"supported by port %d\n", port_id);
4482 	}
4483 }
4484 
4485 static void
4486 cmd_config_queue_tx_offloads(struct rte_port *port)
4487 {
4488 	int k;
4489 
4490 	/* Apply queue tx offloads configuration */
4491 	for (k = 0; k < port->dev_info.max_rx_queues; k++)
4492 		port->tx_conf[k].offloads =
4493 			port->dev_conf.txmode.offloads;
4494 }
4495 
4496 static void
4497 cmd_csum_parsed(void *parsed_result,
4498 		       __rte_unused struct cmdline *cl,
4499 		       __rte_unused void *data)
4500 {
4501 	struct cmd_csum_result *res = parsed_result;
4502 	int hw = 0;
4503 	uint64_t csum_offloads = 0;
4504 	struct rte_eth_dev_info dev_info;
4505 	int ret;
4506 
4507 	if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4508 		printf("invalid port %d\n", res->port_id);
4509 		return;
4510 	}
4511 	if (!port_is_stopped(res->port_id)) {
4512 		printf("Please stop port %d first\n", res->port_id);
4513 		return;
4514 	}
4515 
4516 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4517 	if (ret != 0)
4518 		return;
4519 
4520 	if (!strcmp(res->mode, "set")) {
4521 
4522 		if (!strcmp(res->hwsw, "hw"))
4523 			hw = 1;
4524 
4525 		if (!strcmp(res->proto, "ip")) {
4526 			if (hw == 0 || (dev_info.tx_offload_capa &
4527 						DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4528 				csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4529 			} else {
4530 				printf("IP checksum offload is not supported "
4531 				       "by port %u\n", res->port_id);
4532 			}
4533 		} else if (!strcmp(res->proto, "udp")) {
4534 			if (hw == 0 || (dev_info.tx_offload_capa &
4535 						DEV_TX_OFFLOAD_UDP_CKSUM)) {
4536 				csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4537 			} else {
4538 				printf("UDP checksum offload is not supported "
4539 				       "by port %u\n", res->port_id);
4540 			}
4541 		} else if (!strcmp(res->proto, "tcp")) {
4542 			if (hw == 0 || (dev_info.tx_offload_capa &
4543 						DEV_TX_OFFLOAD_TCP_CKSUM)) {
4544 				csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4545 			} else {
4546 				printf("TCP checksum offload is not supported "
4547 				       "by port %u\n", res->port_id);
4548 			}
4549 		} else if (!strcmp(res->proto, "sctp")) {
4550 			if (hw == 0 || (dev_info.tx_offload_capa &
4551 						DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4552 				csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4553 			} else {
4554 				printf("SCTP checksum offload is not supported "
4555 				       "by port %u\n", res->port_id);
4556 			}
4557 		} else if (!strcmp(res->proto, "outer-ip")) {
4558 			if (hw == 0 || (dev_info.tx_offload_capa &
4559 					DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4560 				csum_offloads |=
4561 						DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4562 			} else {
4563 				printf("Outer IP checksum offload is not "
4564 				       "supported by port %u\n", res->port_id);
4565 			}
4566 		} else if (!strcmp(res->proto, "outer-udp")) {
4567 			if (hw == 0 || (dev_info.tx_offload_capa &
4568 					DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4569 				csum_offloads |=
4570 						DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4571 			} else {
4572 				printf("Outer UDP checksum offload is not "
4573 				       "supported by port %u\n", res->port_id);
4574 			}
4575 		}
4576 
4577 		if (hw) {
4578 			ports[res->port_id].dev_conf.txmode.offloads |=
4579 							csum_offloads;
4580 		} else {
4581 			ports[res->port_id].dev_conf.txmode.offloads &=
4582 							(~csum_offloads);
4583 		}
4584 		cmd_config_queue_tx_offloads(&ports[res->port_id]);
4585 	}
4586 	csum_show(res->port_id);
4587 
4588 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4589 }
4590 
4591 cmdline_parse_token_string_t cmd_csum_csum =
4592 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4593 				csum, "csum");
4594 cmdline_parse_token_string_t cmd_csum_mode =
4595 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4596 				mode, "set");
4597 cmdline_parse_token_string_t cmd_csum_proto =
4598 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4599 				proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4600 cmdline_parse_token_string_t cmd_csum_hwsw =
4601 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4602 				hwsw, "hw#sw");
4603 cmdline_parse_token_num_t cmd_csum_portid =
4604 	TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4605 				port_id, UINT16);
4606 
4607 cmdline_parse_inst_t cmd_csum_set = {
4608 	.f = cmd_csum_parsed,
4609 	.data = NULL,
4610 	.help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4611 		"Enable/Disable hardware calculation of L3/L4 checksum when "
4612 		"using csum forward engine",
4613 	.tokens = {
4614 		(void *)&cmd_csum_csum,
4615 		(void *)&cmd_csum_mode,
4616 		(void *)&cmd_csum_proto,
4617 		(void *)&cmd_csum_hwsw,
4618 		(void *)&cmd_csum_portid,
4619 		NULL,
4620 	},
4621 };
4622 
4623 cmdline_parse_token_string_t cmd_csum_mode_show =
4624 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4625 				mode, "show");
4626 
4627 cmdline_parse_inst_t cmd_csum_show = {
4628 	.f = cmd_csum_parsed,
4629 	.data = NULL,
4630 	.help_str = "csum show <port_id>: Show checksum offload configuration",
4631 	.tokens = {
4632 		(void *)&cmd_csum_csum,
4633 		(void *)&cmd_csum_mode_show,
4634 		(void *)&cmd_csum_portid,
4635 		NULL,
4636 	},
4637 };
4638 
4639 /* Enable/disable tunnel parsing */
4640 struct cmd_csum_tunnel_result {
4641 	cmdline_fixed_string_t csum;
4642 	cmdline_fixed_string_t parse;
4643 	cmdline_fixed_string_t onoff;
4644 	portid_t port_id;
4645 };
4646 
4647 static void
4648 cmd_csum_tunnel_parsed(void *parsed_result,
4649 		       __rte_unused struct cmdline *cl,
4650 		       __rte_unused void *data)
4651 {
4652 	struct cmd_csum_tunnel_result *res = parsed_result;
4653 
4654 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4655 		return;
4656 
4657 	if (!strcmp(res->onoff, "on"))
4658 		ports[res->port_id].parse_tunnel = 1;
4659 	else
4660 		ports[res->port_id].parse_tunnel = 0;
4661 
4662 	csum_show(res->port_id);
4663 }
4664 
4665 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4666 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4667 				csum, "csum");
4668 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4669 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4670 				parse, "parse-tunnel");
4671 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4672 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4673 				onoff, "on#off");
4674 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4675 	TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4676 				port_id, UINT16);
4677 
4678 cmdline_parse_inst_t cmd_csum_tunnel = {
4679 	.f = cmd_csum_tunnel_parsed,
4680 	.data = NULL,
4681 	.help_str = "csum parse-tunnel on|off <port_id>: "
4682 		"Enable/Disable parsing of tunnels for csum engine",
4683 	.tokens = {
4684 		(void *)&cmd_csum_tunnel_csum,
4685 		(void *)&cmd_csum_tunnel_parse,
4686 		(void *)&cmd_csum_tunnel_onoff,
4687 		(void *)&cmd_csum_tunnel_portid,
4688 		NULL,
4689 	},
4690 };
4691 
4692 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4693 struct cmd_tso_set_result {
4694 	cmdline_fixed_string_t tso;
4695 	cmdline_fixed_string_t mode;
4696 	uint16_t tso_segsz;
4697 	portid_t port_id;
4698 };
4699 
4700 static void
4701 cmd_tso_set_parsed(void *parsed_result,
4702 		       __rte_unused struct cmdline *cl,
4703 		       __rte_unused void *data)
4704 {
4705 	struct cmd_tso_set_result *res = parsed_result;
4706 	struct rte_eth_dev_info dev_info;
4707 	int ret;
4708 
4709 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4710 		return;
4711 	if (!port_is_stopped(res->port_id)) {
4712 		printf("Please stop port %d first\n", res->port_id);
4713 		return;
4714 	}
4715 
4716 	if (!strcmp(res->mode, "set"))
4717 		ports[res->port_id].tso_segsz = res->tso_segsz;
4718 
4719 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4720 	if (ret != 0)
4721 		return;
4722 
4723 	if ((ports[res->port_id].tso_segsz != 0) &&
4724 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4725 		printf("Error: TSO is not supported by port %d\n",
4726 		       res->port_id);
4727 		return;
4728 	}
4729 
4730 	if (ports[res->port_id].tso_segsz == 0) {
4731 		ports[res->port_id].dev_conf.txmode.offloads &=
4732 						~DEV_TX_OFFLOAD_TCP_TSO;
4733 		printf("TSO for non-tunneled packets is disabled\n");
4734 	} else {
4735 		ports[res->port_id].dev_conf.txmode.offloads |=
4736 						DEV_TX_OFFLOAD_TCP_TSO;
4737 		printf("TSO segment size for non-tunneled packets is %d\n",
4738 			ports[res->port_id].tso_segsz);
4739 	}
4740 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
4741 
4742 	/* display warnings if configuration is not supported by the NIC */
4743 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4744 	if (ret != 0)
4745 		return;
4746 
4747 	if ((ports[res->port_id].tso_segsz != 0) &&
4748 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4749 		printf("Warning: TSO enabled but not "
4750 			"supported by port %d\n", res->port_id);
4751 	}
4752 
4753 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4754 }
4755 
4756 cmdline_parse_token_string_t cmd_tso_set_tso =
4757 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4758 				tso, "tso");
4759 cmdline_parse_token_string_t cmd_tso_set_mode =
4760 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4761 				mode, "set");
4762 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4763 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4764 				tso_segsz, UINT16);
4765 cmdline_parse_token_num_t cmd_tso_set_portid =
4766 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4767 				port_id, UINT16);
4768 
4769 cmdline_parse_inst_t cmd_tso_set = {
4770 	.f = cmd_tso_set_parsed,
4771 	.data = NULL,
4772 	.help_str = "tso set <tso_segsz> <port_id>: "
4773 		"Set TSO segment size of non-tunneled packets for csum engine "
4774 		"(0 to disable)",
4775 	.tokens = {
4776 		(void *)&cmd_tso_set_tso,
4777 		(void *)&cmd_tso_set_mode,
4778 		(void *)&cmd_tso_set_tso_segsz,
4779 		(void *)&cmd_tso_set_portid,
4780 		NULL,
4781 	},
4782 };
4783 
4784 cmdline_parse_token_string_t cmd_tso_show_mode =
4785 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4786 				mode, "show");
4787 
4788 
4789 cmdline_parse_inst_t cmd_tso_show = {
4790 	.f = cmd_tso_set_parsed,
4791 	.data = NULL,
4792 	.help_str = "tso show <port_id>: "
4793 		"Show TSO segment size of non-tunneled packets for csum engine",
4794 	.tokens = {
4795 		(void *)&cmd_tso_set_tso,
4796 		(void *)&cmd_tso_show_mode,
4797 		(void *)&cmd_tso_set_portid,
4798 		NULL,
4799 	},
4800 };
4801 
4802 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4803 struct cmd_tunnel_tso_set_result {
4804 	cmdline_fixed_string_t tso;
4805 	cmdline_fixed_string_t mode;
4806 	uint16_t tso_segsz;
4807 	portid_t port_id;
4808 };
4809 
4810 static struct rte_eth_dev_info
4811 check_tunnel_tso_nic_support(portid_t port_id)
4812 {
4813 	struct rte_eth_dev_info dev_info;
4814 
4815 	if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4816 		return dev_info;
4817 
4818 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4819 		printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4820 		       "not enabled for port %d\n", port_id);
4821 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4822 		printf("Warning: GRE TUNNEL TSO	not supported therefore "
4823 		       "not enabled for port %d\n", port_id);
4824 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4825 		printf("Warning: IPIP TUNNEL TSO not supported therefore "
4826 		       "not enabled for port %d\n", port_id);
4827 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4828 		printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4829 		       "not enabled for port %d\n", port_id);
4830 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4831 		printf("Warning: IP TUNNEL TSO not supported therefore "
4832 		       "not enabled for port %d\n", port_id);
4833 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4834 		printf("Warning: UDP TUNNEL TSO not supported therefore "
4835 		       "not enabled for port %d\n", port_id);
4836 	return dev_info;
4837 }
4838 
4839 static void
4840 cmd_tunnel_tso_set_parsed(void *parsed_result,
4841 			  __rte_unused struct cmdline *cl,
4842 			  __rte_unused void *data)
4843 {
4844 	struct cmd_tunnel_tso_set_result *res = parsed_result;
4845 	struct rte_eth_dev_info dev_info;
4846 
4847 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4848 		return;
4849 	if (!port_is_stopped(res->port_id)) {
4850 		printf("Please stop port %d first\n", res->port_id);
4851 		return;
4852 	}
4853 
4854 	if (!strcmp(res->mode, "set"))
4855 		ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4856 
4857 	dev_info = check_tunnel_tso_nic_support(res->port_id);
4858 	if (ports[res->port_id].tunnel_tso_segsz == 0) {
4859 		ports[res->port_id].dev_conf.txmode.offloads &=
4860 			~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4861 			  DEV_TX_OFFLOAD_GRE_TNL_TSO |
4862 			  DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4863 			  DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4864 			  DEV_TX_OFFLOAD_IP_TNL_TSO |
4865 			  DEV_TX_OFFLOAD_UDP_TNL_TSO);
4866 		printf("TSO for tunneled packets is disabled\n");
4867 	} else {
4868 		uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4869 					 DEV_TX_OFFLOAD_GRE_TNL_TSO |
4870 					 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4871 					 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4872 					 DEV_TX_OFFLOAD_IP_TNL_TSO |
4873 					 DEV_TX_OFFLOAD_UDP_TNL_TSO);
4874 
4875 		ports[res->port_id].dev_conf.txmode.offloads |=
4876 			(tso_offloads & dev_info.tx_offload_capa);
4877 		printf("TSO segment size for tunneled packets is %d\n",
4878 			ports[res->port_id].tunnel_tso_segsz);
4879 
4880 		/* Below conditions are needed to make it work:
4881 		 * (1) tunnel TSO is supported by the NIC;
4882 		 * (2) "csum parse_tunnel" must be set so that tunneled pkts
4883 		 * are recognized;
4884 		 * (3) for tunneled pkts with outer L3 of IPv4,
4885 		 * "csum set outer-ip" must be set to hw, because after tso,
4886 		 * total_len of outer IP header is changed, and the checksum
4887 		 * of outer IP header calculated by sw should be wrong; that
4888 		 * is not necessary for IPv6 tunneled pkts because there's no
4889 		 * checksum in IP header anymore.
4890 		 */
4891 
4892 		if (!ports[res->port_id].parse_tunnel)
4893 			printf("Warning: csum parse_tunnel must be set "
4894 				"so that tunneled packets are recognized\n");
4895 		if (!(ports[res->port_id].dev_conf.txmode.offloads &
4896 		      DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4897 			printf("Warning: csum set outer-ip must be set to hw "
4898 				"if outer L3 is IPv4; not necessary for IPv6\n");
4899 	}
4900 
4901 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
4902 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4903 }
4904 
4905 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4906 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4907 				tso, "tunnel_tso");
4908 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4909 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4910 				mode, "set");
4911 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4912 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4913 				tso_segsz, UINT16);
4914 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4915 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4916 				port_id, UINT16);
4917 
4918 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4919 	.f = cmd_tunnel_tso_set_parsed,
4920 	.data = NULL,
4921 	.help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4922 		"Set TSO segment size of tunneled packets for csum engine "
4923 		"(0 to disable)",
4924 	.tokens = {
4925 		(void *)&cmd_tunnel_tso_set_tso,
4926 		(void *)&cmd_tunnel_tso_set_mode,
4927 		(void *)&cmd_tunnel_tso_set_tso_segsz,
4928 		(void *)&cmd_tunnel_tso_set_portid,
4929 		NULL,
4930 	},
4931 };
4932 
4933 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4934 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4935 				mode, "show");
4936 
4937 
4938 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4939 	.f = cmd_tunnel_tso_set_parsed,
4940 	.data = NULL,
4941 	.help_str = "tunnel_tso show <port_id> "
4942 		"Show TSO segment size of tunneled packets for csum engine",
4943 	.tokens = {
4944 		(void *)&cmd_tunnel_tso_set_tso,
4945 		(void *)&cmd_tunnel_tso_show_mode,
4946 		(void *)&cmd_tunnel_tso_set_portid,
4947 		NULL,
4948 	},
4949 };
4950 
4951 /* *** SET GRO FOR A PORT *** */
4952 struct cmd_gro_enable_result {
4953 	cmdline_fixed_string_t cmd_set;
4954 	cmdline_fixed_string_t cmd_port;
4955 	cmdline_fixed_string_t cmd_keyword;
4956 	cmdline_fixed_string_t cmd_onoff;
4957 	portid_t cmd_pid;
4958 };
4959 
4960 static void
4961 cmd_gro_enable_parsed(void *parsed_result,
4962 		__rte_unused struct cmdline *cl,
4963 		__rte_unused void *data)
4964 {
4965 	struct cmd_gro_enable_result *res;
4966 
4967 	res = parsed_result;
4968 	if (!strcmp(res->cmd_keyword, "gro"))
4969 		setup_gro(res->cmd_onoff, res->cmd_pid);
4970 }
4971 
4972 cmdline_parse_token_string_t cmd_gro_enable_set =
4973 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4974 			cmd_set, "set");
4975 cmdline_parse_token_string_t cmd_gro_enable_port =
4976 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4977 			cmd_keyword, "port");
4978 cmdline_parse_token_num_t cmd_gro_enable_pid =
4979 	TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4980 			cmd_pid, UINT16);
4981 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4982 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4983 			cmd_keyword, "gro");
4984 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4985 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4986 			cmd_onoff, "on#off");
4987 
4988 cmdline_parse_inst_t cmd_gro_enable = {
4989 	.f = cmd_gro_enable_parsed,
4990 	.data = NULL,
4991 	.help_str = "set port <port_id> gro on|off",
4992 	.tokens = {
4993 		(void *)&cmd_gro_enable_set,
4994 		(void *)&cmd_gro_enable_port,
4995 		(void *)&cmd_gro_enable_pid,
4996 		(void *)&cmd_gro_enable_keyword,
4997 		(void *)&cmd_gro_enable_onoff,
4998 		NULL,
4999 	},
5000 };
5001 
5002 /* *** DISPLAY GRO CONFIGURATION *** */
5003 struct cmd_gro_show_result {
5004 	cmdline_fixed_string_t cmd_show;
5005 	cmdline_fixed_string_t cmd_port;
5006 	cmdline_fixed_string_t cmd_keyword;
5007 	portid_t cmd_pid;
5008 };
5009 
5010 static void
5011 cmd_gro_show_parsed(void *parsed_result,
5012 		__rte_unused struct cmdline *cl,
5013 		__rte_unused void *data)
5014 {
5015 	struct cmd_gro_show_result *res;
5016 
5017 	res = parsed_result;
5018 	if (!strcmp(res->cmd_keyword, "gro"))
5019 		show_gro(res->cmd_pid);
5020 }
5021 
5022 cmdline_parse_token_string_t cmd_gro_show_show =
5023 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5024 			cmd_show, "show");
5025 cmdline_parse_token_string_t cmd_gro_show_port =
5026 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5027 			cmd_port, "port");
5028 cmdline_parse_token_num_t cmd_gro_show_pid =
5029 	TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5030 			cmd_pid, UINT16);
5031 cmdline_parse_token_string_t cmd_gro_show_keyword =
5032 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5033 			cmd_keyword, "gro");
5034 
5035 cmdline_parse_inst_t cmd_gro_show = {
5036 	.f = cmd_gro_show_parsed,
5037 	.data = NULL,
5038 	.help_str = "show port <port_id> gro",
5039 	.tokens = {
5040 		(void *)&cmd_gro_show_show,
5041 		(void *)&cmd_gro_show_port,
5042 		(void *)&cmd_gro_show_pid,
5043 		(void *)&cmd_gro_show_keyword,
5044 		NULL,
5045 	},
5046 };
5047 
5048 /* *** SET FLUSH CYCLES FOR GRO *** */
5049 struct cmd_gro_flush_result {
5050 	cmdline_fixed_string_t cmd_set;
5051 	cmdline_fixed_string_t cmd_keyword;
5052 	cmdline_fixed_string_t cmd_flush;
5053 	uint8_t cmd_cycles;
5054 };
5055 
5056 static void
5057 cmd_gro_flush_parsed(void *parsed_result,
5058 		__rte_unused struct cmdline *cl,
5059 		__rte_unused void *data)
5060 {
5061 	struct cmd_gro_flush_result *res;
5062 
5063 	res = parsed_result;
5064 	if ((!strcmp(res->cmd_keyword, "gro")) &&
5065 			(!strcmp(res->cmd_flush, "flush")))
5066 		setup_gro_flush_cycles(res->cmd_cycles);
5067 }
5068 
5069 cmdline_parse_token_string_t cmd_gro_flush_set =
5070 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5071 			cmd_set, "set");
5072 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5073 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5074 			cmd_keyword, "gro");
5075 cmdline_parse_token_string_t cmd_gro_flush_flush =
5076 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5077 			cmd_flush, "flush");
5078 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5079 	TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5080 			cmd_cycles, UINT8);
5081 
5082 cmdline_parse_inst_t cmd_gro_flush = {
5083 	.f = cmd_gro_flush_parsed,
5084 	.data = NULL,
5085 	.help_str = "set gro flush <cycles>",
5086 	.tokens = {
5087 		(void *)&cmd_gro_flush_set,
5088 		(void *)&cmd_gro_flush_keyword,
5089 		(void *)&cmd_gro_flush_flush,
5090 		(void *)&cmd_gro_flush_cycles,
5091 		NULL,
5092 	},
5093 };
5094 
5095 /* *** ENABLE/DISABLE GSO *** */
5096 struct cmd_gso_enable_result {
5097 	cmdline_fixed_string_t cmd_set;
5098 	cmdline_fixed_string_t cmd_port;
5099 	cmdline_fixed_string_t cmd_keyword;
5100 	cmdline_fixed_string_t cmd_mode;
5101 	portid_t cmd_pid;
5102 };
5103 
5104 static void
5105 cmd_gso_enable_parsed(void *parsed_result,
5106 		__rte_unused struct cmdline *cl,
5107 		__rte_unused void *data)
5108 {
5109 	struct cmd_gso_enable_result *res;
5110 
5111 	res = parsed_result;
5112 	if (!strcmp(res->cmd_keyword, "gso"))
5113 		setup_gso(res->cmd_mode, res->cmd_pid);
5114 }
5115 
5116 cmdline_parse_token_string_t cmd_gso_enable_set =
5117 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5118 			cmd_set, "set");
5119 cmdline_parse_token_string_t cmd_gso_enable_port =
5120 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5121 			cmd_port, "port");
5122 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5123 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5124 			cmd_keyword, "gso");
5125 cmdline_parse_token_string_t cmd_gso_enable_mode =
5126 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5127 			cmd_mode, "on#off");
5128 cmdline_parse_token_num_t cmd_gso_enable_pid =
5129 	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5130 			cmd_pid, UINT16);
5131 
5132 cmdline_parse_inst_t cmd_gso_enable = {
5133 	.f = cmd_gso_enable_parsed,
5134 	.data = NULL,
5135 	.help_str = "set port <port_id> gso on|off",
5136 	.tokens = {
5137 		(void *)&cmd_gso_enable_set,
5138 		(void *)&cmd_gso_enable_port,
5139 		(void *)&cmd_gso_enable_pid,
5140 		(void *)&cmd_gso_enable_keyword,
5141 		(void *)&cmd_gso_enable_mode,
5142 		NULL,
5143 	},
5144 };
5145 
5146 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5147 struct cmd_gso_size_result {
5148 	cmdline_fixed_string_t cmd_set;
5149 	cmdline_fixed_string_t cmd_keyword;
5150 	cmdline_fixed_string_t cmd_segsz;
5151 	uint16_t cmd_size;
5152 };
5153 
5154 static void
5155 cmd_gso_size_parsed(void *parsed_result,
5156 		       __rte_unused struct cmdline *cl,
5157 		       __rte_unused void *data)
5158 {
5159 	struct cmd_gso_size_result *res = parsed_result;
5160 
5161 	if (test_done == 0) {
5162 		printf("Before setting GSO segsz, please first"
5163 				" stop forwarding\n");
5164 		return;
5165 	}
5166 
5167 	if (!strcmp(res->cmd_keyword, "gso") &&
5168 			!strcmp(res->cmd_segsz, "segsz")) {
5169 		if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5170 			printf("gso_size should be larger than %zu."
5171 					" Please input a legal value\n",
5172 					RTE_GSO_SEG_SIZE_MIN);
5173 		else
5174 			gso_max_segment_size = res->cmd_size;
5175 	}
5176 }
5177 
5178 cmdline_parse_token_string_t cmd_gso_size_set =
5179 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5180 				cmd_set, "set");
5181 cmdline_parse_token_string_t cmd_gso_size_keyword =
5182 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5183 				cmd_keyword, "gso");
5184 cmdline_parse_token_string_t cmd_gso_size_segsz =
5185 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5186 				cmd_segsz, "segsz");
5187 cmdline_parse_token_num_t cmd_gso_size_size =
5188 	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5189 				cmd_size, UINT16);
5190 
5191 cmdline_parse_inst_t cmd_gso_size = {
5192 	.f = cmd_gso_size_parsed,
5193 	.data = NULL,
5194 	.help_str = "set gso segsz <length>",
5195 	.tokens = {
5196 		(void *)&cmd_gso_size_set,
5197 		(void *)&cmd_gso_size_keyword,
5198 		(void *)&cmd_gso_size_segsz,
5199 		(void *)&cmd_gso_size_size,
5200 		NULL,
5201 	},
5202 };
5203 
5204 /* *** SHOW GSO CONFIGURATION *** */
5205 struct cmd_gso_show_result {
5206 	cmdline_fixed_string_t cmd_show;
5207 	cmdline_fixed_string_t cmd_port;
5208 	cmdline_fixed_string_t cmd_keyword;
5209 	portid_t cmd_pid;
5210 };
5211 
5212 static void
5213 cmd_gso_show_parsed(void *parsed_result,
5214 		       __rte_unused struct cmdline *cl,
5215 		       __rte_unused void *data)
5216 {
5217 	struct cmd_gso_show_result *res = parsed_result;
5218 
5219 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5220 		printf("invalid port id %u\n", res->cmd_pid);
5221 		return;
5222 	}
5223 	if (!strcmp(res->cmd_keyword, "gso")) {
5224 		if (gso_ports[res->cmd_pid].enable) {
5225 			printf("Max GSO'd packet size: %uB\n"
5226 					"Supported GSO types: TCP/IPv4, "
5227 					"UDP/IPv4, VxLAN with inner "
5228 					"TCP/IPv4 packet, GRE with inner "
5229 					"TCP/IPv4 packet\n",
5230 					gso_max_segment_size);
5231 		} else
5232 			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5233 	}
5234 }
5235 
5236 cmdline_parse_token_string_t cmd_gso_show_show =
5237 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5238 		cmd_show, "show");
5239 cmdline_parse_token_string_t cmd_gso_show_port =
5240 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5241 		cmd_port, "port");
5242 cmdline_parse_token_string_t cmd_gso_show_keyword =
5243 	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5244 				cmd_keyword, "gso");
5245 cmdline_parse_token_num_t cmd_gso_show_pid =
5246 	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5247 				cmd_pid, UINT16);
5248 
5249 cmdline_parse_inst_t cmd_gso_show = {
5250 	.f = cmd_gso_show_parsed,
5251 	.data = NULL,
5252 	.help_str = "show port <port_id> gso",
5253 	.tokens = {
5254 		(void *)&cmd_gso_show_show,
5255 		(void *)&cmd_gso_show_port,
5256 		(void *)&cmd_gso_show_pid,
5257 		(void *)&cmd_gso_show_keyword,
5258 		NULL,
5259 	},
5260 };
5261 
5262 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5263 struct cmd_set_flush_rx {
5264 	cmdline_fixed_string_t set;
5265 	cmdline_fixed_string_t flush_rx;
5266 	cmdline_fixed_string_t mode;
5267 };
5268 
5269 static void
5270 cmd_set_flush_rx_parsed(void *parsed_result,
5271 		__rte_unused struct cmdline *cl,
5272 		__rte_unused void *data)
5273 {
5274 	struct cmd_set_flush_rx *res = parsed_result;
5275 	no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5276 }
5277 
5278 cmdline_parse_token_string_t cmd_setflushrx_set =
5279 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5280 			set, "set");
5281 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5282 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5283 			flush_rx, "flush_rx");
5284 cmdline_parse_token_string_t cmd_setflushrx_mode =
5285 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5286 			mode, "on#off");
5287 
5288 
5289 cmdline_parse_inst_t cmd_set_flush_rx = {
5290 	.f = cmd_set_flush_rx_parsed,
5291 	.help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5292 	.data = NULL,
5293 	.tokens = {
5294 		(void *)&cmd_setflushrx_set,
5295 		(void *)&cmd_setflushrx_flush_rx,
5296 		(void *)&cmd_setflushrx_mode,
5297 		NULL,
5298 	},
5299 };
5300 
5301 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5302 struct cmd_set_link_check {
5303 	cmdline_fixed_string_t set;
5304 	cmdline_fixed_string_t link_check;
5305 	cmdline_fixed_string_t mode;
5306 };
5307 
5308 static void
5309 cmd_set_link_check_parsed(void *parsed_result,
5310 		__rte_unused struct cmdline *cl,
5311 		__rte_unused void *data)
5312 {
5313 	struct cmd_set_link_check *res = parsed_result;
5314 	no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5315 }
5316 
5317 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5318 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5319 			set, "set");
5320 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5321 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5322 			link_check, "link_check");
5323 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5324 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5325 			mode, "on#off");
5326 
5327 
5328 cmdline_parse_inst_t cmd_set_link_check = {
5329 	.f = cmd_set_link_check_parsed,
5330 	.help_str = "set link_check on|off: Enable/Disable link status check "
5331 	            "when starting/stopping a port",
5332 	.data = NULL,
5333 	.tokens = {
5334 		(void *)&cmd_setlinkcheck_set,
5335 		(void *)&cmd_setlinkcheck_link_check,
5336 		(void *)&cmd_setlinkcheck_mode,
5337 		NULL,
5338 	},
5339 };
5340 
5341 /* *** SET NIC BYPASS MODE *** */
5342 struct cmd_set_bypass_mode_result {
5343 	cmdline_fixed_string_t set;
5344 	cmdline_fixed_string_t bypass;
5345 	cmdline_fixed_string_t mode;
5346 	cmdline_fixed_string_t value;
5347 	portid_t port_id;
5348 };
5349 
5350 static void
5351 cmd_set_bypass_mode_parsed(void *parsed_result,
5352 		__rte_unused struct cmdline *cl,
5353 		__rte_unused void *data)
5354 {
5355 	struct cmd_set_bypass_mode_result *res = parsed_result;
5356 	portid_t port_id = res->port_id;
5357 	int32_t rc = -EINVAL;
5358 
5359 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5360 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5361 
5362 	if (!strcmp(res->value, "bypass"))
5363 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5364 	else if (!strcmp(res->value, "isolate"))
5365 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5366 	else
5367 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5368 
5369 	/* Set the bypass mode for the relevant port. */
5370 	rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5371 #endif
5372 	if (rc != 0)
5373 		printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5374 }
5375 
5376 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5377 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5378 			set, "set");
5379 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5380 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5381 			bypass, "bypass");
5382 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5383 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5384 			mode, "mode");
5385 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5386 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5387 			value, "normal#bypass#isolate");
5388 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5389 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5390 				port_id, UINT16);
5391 
5392 cmdline_parse_inst_t cmd_set_bypass_mode = {
5393 	.f = cmd_set_bypass_mode_parsed,
5394 	.help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5395 	            "Set the NIC bypass mode for port_id",
5396 	.data = NULL,
5397 	.tokens = {
5398 		(void *)&cmd_setbypass_mode_set,
5399 		(void *)&cmd_setbypass_mode_bypass,
5400 		(void *)&cmd_setbypass_mode_mode,
5401 		(void *)&cmd_setbypass_mode_value,
5402 		(void *)&cmd_setbypass_mode_port,
5403 		NULL,
5404 	},
5405 };
5406 
5407 /* *** SET NIC BYPASS EVENT *** */
5408 struct cmd_set_bypass_event_result {
5409 	cmdline_fixed_string_t set;
5410 	cmdline_fixed_string_t bypass;
5411 	cmdline_fixed_string_t event;
5412 	cmdline_fixed_string_t event_value;
5413 	cmdline_fixed_string_t mode;
5414 	cmdline_fixed_string_t mode_value;
5415 	portid_t port_id;
5416 };
5417 
5418 static void
5419 cmd_set_bypass_event_parsed(void *parsed_result,
5420 		__rte_unused struct cmdline *cl,
5421 		__rte_unused void *data)
5422 {
5423 	int32_t rc = -EINVAL;
5424 	struct cmd_set_bypass_event_result *res = parsed_result;
5425 	portid_t port_id = res->port_id;
5426 
5427 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5428 	uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5429 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5430 
5431 	if (!strcmp(res->event_value, "timeout"))
5432 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5433 	else if (!strcmp(res->event_value, "os_on"))
5434 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5435 	else if (!strcmp(res->event_value, "os_off"))
5436 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5437 	else if (!strcmp(res->event_value, "power_on"))
5438 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5439 	else if (!strcmp(res->event_value, "power_off"))
5440 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5441 	else
5442 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5443 
5444 	if (!strcmp(res->mode_value, "bypass"))
5445 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5446 	else if (!strcmp(res->mode_value, "isolate"))
5447 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5448 	else
5449 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5450 
5451 	/* Set the watchdog timeout. */
5452 	if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5453 
5454 		rc = -EINVAL;
5455 		if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5456 			rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5457 							   bypass_timeout);
5458 		}
5459 		if (rc != 0) {
5460 			printf("Failed to set timeout value %u "
5461 			"for port %d, errto code: %d.\n",
5462 			bypass_timeout, port_id, rc);
5463 		}
5464 	}
5465 
5466 	/* Set the bypass event to transition to bypass mode. */
5467 	rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5468 					      bypass_mode);
5469 #endif
5470 
5471 	if (rc != 0)
5472 		printf("\t Failed to set bypass event for port = %d.\n",
5473 		       port_id);
5474 }
5475 
5476 cmdline_parse_token_string_t cmd_setbypass_event_set =
5477 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5478 			set, "set");
5479 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5480 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5481 			bypass, "bypass");
5482 cmdline_parse_token_string_t cmd_setbypass_event_event =
5483 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5484 			event, "event");
5485 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5486 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5487 			event_value, "none#timeout#os_off#os_on#power_on#power_off");
5488 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5489 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5490 			mode, "mode");
5491 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5492 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5493 			mode_value, "normal#bypass#isolate");
5494 cmdline_parse_token_num_t cmd_setbypass_event_port =
5495 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5496 				port_id, UINT16);
5497 
5498 cmdline_parse_inst_t cmd_set_bypass_event = {
5499 	.f = cmd_set_bypass_event_parsed,
5500 	.help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5501 		"power_off mode normal|bypass|isolate <port_id>: "
5502 		"Set the NIC bypass event mode for port_id",
5503 	.data = NULL,
5504 	.tokens = {
5505 		(void *)&cmd_setbypass_event_set,
5506 		(void *)&cmd_setbypass_event_bypass,
5507 		(void *)&cmd_setbypass_event_event,
5508 		(void *)&cmd_setbypass_event_event_value,
5509 		(void *)&cmd_setbypass_event_mode,
5510 		(void *)&cmd_setbypass_event_mode_value,
5511 		(void *)&cmd_setbypass_event_port,
5512 		NULL,
5513 	},
5514 };
5515 
5516 
5517 /* *** SET NIC BYPASS TIMEOUT *** */
5518 struct cmd_set_bypass_timeout_result {
5519 	cmdline_fixed_string_t set;
5520 	cmdline_fixed_string_t bypass;
5521 	cmdline_fixed_string_t timeout;
5522 	cmdline_fixed_string_t value;
5523 };
5524 
5525 static void
5526 cmd_set_bypass_timeout_parsed(void *parsed_result,
5527 		__rte_unused struct cmdline *cl,
5528 		__rte_unused void *data)
5529 {
5530 	__rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5531 
5532 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5533 	if (!strcmp(res->value, "1.5"))
5534 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5535 	else if (!strcmp(res->value, "2"))
5536 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5537 	else if (!strcmp(res->value, "3"))
5538 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5539 	else if (!strcmp(res->value, "4"))
5540 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5541 	else if (!strcmp(res->value, "8"))
5542 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5543 	else if (!strcmp(res->value, "16"))
5544 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5545 	else if (!strcmp(res->value, "32"))
5546 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5547 	else
5548 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5549 #endif
5550 }
5551 
5552 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5553 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5554 			set, "set");
5555 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5556 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5557 			bypass, "bypass");
5558 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5559 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5560 			timeout, "timeout");
5561 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5562 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5563 			value, "0#1.5#2#3#4#8#16#32");
5564 
5565 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5566 	.f = cmd_set_bypass_timeout_parsed,
5567 	.help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5568 		"Set the NIC bypass watchdog timeout in seconds",
5569 	.data = NULL,
5570 	.tokens = {
5571 		(void *)&cmd_setbypass_timeout_set,
5572 		(void *)&cmd_setbypass_timeout_bypass,
5573 		(void *)&cmd_setbypass_timeout_timeout,
5574 		(void *)&cmd_setbypass_timeout_value,
5575 		NULL,
5576 	},
5577 };
5578 
5579 /* *** SHOW NIC BYPASS MODE *** */
5580 struct cmd_show_bypass_config_result {
5581 	cmdline_fixed_string_t show;
5582 	cmdline_fixed_string_t bypass;
5583 	cmdline_fixed_string_t config;
5584 	portid_t port_id;
5585 };
5586 
5587 static void
5588 cmd_show_bypass_config_parsed(void *parsed_result,
5589 		__rte_unused struct cmdline *cl,
5590 		__rte_unused void *data)
5591 {
5592 	struct cmd_show_bypass_config_result *res = parsed_result;
5593 	portid_t port_id = res->port_id;
5594 	int rc = -EINVAL;
5595 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5596 	uint32_t event_mode;
5597 	uint32_t bypass_mode;
5598 	uint32_t timeout = bypass_timeout;
5599 	unsigned int i;
5600 
5601 	static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5602 		{"off", "1.5", "2", "3", "4", "8", "16", "32"};
5603 	static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5604 		{"UNKNOWN", "normal", "bypass", "isolate"};
5605 	static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5606 		"NONE",
5607 		"OS/board on",
5608 		"power supply on",
5609 		"OS/board off",
5610 		"power supply off",
5611 		"timeout"};
5612 
5613 	/* Display the bypass mode.*/
5614 	if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5615 		printf("\tFailed to get bypass mode for port = %d\n", port_id);
5616 		return;
5617 	}
5618 	else {
5619 		if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5620 			bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5621 
5622 		printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5623 	}
5624 
5625 	/* Display the bypass timeout.*/
5626 	if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5627 		timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5628 
5629 	printf("\tbypass timeout = %s\n", timeouts[timeout]);
5630 
5631 	/* Display the bypass events and associated modes. */
5632 	for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5633 
5634 		if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5635 			printf("\tFailed to get bypass mode for event = %s\n",
5636 				events[i]);
5637 		} else {
5638 			if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5639 				event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5640 
5641 			printf("\tbypass event: %-16s = %s\n", events[i],
5642 				modes[event_mode]);
5643 		}
5644 	}
5645 #endif
5646 	if (rc != 0)
5647 		printf("\tFailed to get bypass configuration for port = %d\n",
5648 		       port_id);
5649 }
5650 
5651 cmdline_parse_token_string_t cmd_showbypass_config_show =
5652 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5653 			show, "show");
5654 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5655 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5656 			bypass, "bypass");
5657 cmdline_parse_token_string_t cmd_showbypass_config_config =
5658 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5659 			config, "config");
5660 cmdline_parse_token_num_t cmd_showbypass_config_port =
5661 	TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5662 				port_id, UINT16);
5663 
5664 cmdline_parse_inst_t cmd_show_bypass_config = {
5665 	.f = cmd_show_bypass_config_parsed,
5666 	.help_str = "show bypass config <port_id>: "
5667 	            "Show the NIC bypass config for port_id",
5668 	.data = NULL,
5669 	.tokens = {
5670 		(void *)&cmd_showbypass_config_show,
5671 		(void *)&cmd_showbypass_config_bypass,
5672 		(void *)&cmd_showbypass_config_config,
5673 		(void *)&cmd_showbypass_config_port,
5674 		NULL,
5675 	},
5676 };
5677 
5678 #ifdef RTE_LIBRTE_PMD_BOND
5679 /* *** SET BONDING MODE *** */
5680 struct cmd_set_bonding_mode_result {
5681 	cmdline_fixed_string_t set;
5682 	cmdline_fixed_string_t bonding;
5683 	cmdline_fixed_string_t mode;
5684 	uint8_t value;
5685 	portid_t port_id;
5686 };
5687 
5688 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5689 		__rte_unused  struct cmdline *cl,
5690 		__rte_unused void *data)
5691 {
5692 	struct cmd_set_bonding_mode_result *res = parsed_result;
5693 	portid_t port_id = res->port_id;
5694 
5695 	/* Set the bonding mode for the relevant port. */
5696 	if (0 != rte_eth_bond_mode_set(port_id, res->value))
5697 		printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5698 }
5699 
5700 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5701 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5702 		set, "set");
5703 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5704 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5705 		bonding, "bonding");
5706 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5707 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5708 		mode, "mode");
5709 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5710 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5711 		value, UINT8);
5712 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5713 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5714 		port_id, UINT16);
5715 
5716 cmdline_parse_inst_t cmd_set_bonding_mode = {
5717 		.f = cmd_set_bonding_mode_parsed,
5718 		.help_str = "set bonding mode <mode_value> <port_id>: "
5719 			"Set the bonding mode for port_id",
5720 		.data = NULL,
5721 		.tokens = {
5722 				(void *) &cmd_setbonding_mode_set,
5723 				(void *) &cmd_setbonding_mode_bonding,
5724 				(void *) &cmd_setbonding_mode_mode,
5725 				(void *) &cmd_setbonding_mode_value,
5726 				(void *) &cmd_setbonding_mode_port,
5727 				NULL
5728 		}
5729 };
5730 
5731 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5732 struct cmd_set_bonding_lacp_dedicated_queues_result {
5733 	cmdline_fixed_string_t set;
5734 	cmdline_fixed_string_t bonding;
5735 	cmdline_fixed_string_t lacp;
5736 	cmdline_fixed_string_t dedicated_queues;
5737 	portid_t port_id;
5738 	cmdline_fixed_string_t mode;
5739 };
5740 
5741 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5742 		__rte_unused  struct cmdline *cl,
5743 		__rte_unused void *data)
5744 {
5745 	struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5746 	portid_t port_id = res->port_id;
5747 	struct rte_port *port;
5748 
5749 	port = &ports[port_id];
5750 
5751 	/** Check if the port is not started **/
5752 	if (port->port_status != RTE_PORT_STOPPED) {
5753 		printf("Please stop port %d first\n", port_id);
5754 		return;
5755 	}
5756 
5757 	if (!strcmp(res->mode, "enable")) {
5758 		if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5759 			printf("Dedicate queues for LACP control packets"
5760 					" enabled\n");
5761 		else
5762 			printf("Enabling dedicate queues for LACP control "
5763 					"packets on port %d failed\n", port_id);
5764 	} else if (!strcmp(res->mode, "disable")) {
5765 		if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5766 			printf("Dedicated queues for LACP control packets "
5767 					"disabled\n");
5768 		else
5769 			printf("Disabling dedicated queues for LACP control "
5770 					"traffic on port %d failed\n", port_id);
5771 	}
5772 }
5773 
5774 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5775 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5776 		set, "set");
5777 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5778 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5779 		bonding, "bonding");
5780 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5781 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5782 		lacp, "lacp");
5783 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5784 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5785 		dedicated_queues, "dedicated_queues");
5786 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5787 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5788 		port_id, UINT16);
5789 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5790 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5791 		mode, "enable#disable");
5792 
5793 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5794 		.f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5795 		.help_str = "set bonding lacp dedicated_queues <port_id> "
5796 			"enable|disable: "
5797 			"Enable/disable dedicated queues for LACP control traffic for port_id",
5798 		.data = NULL,
5799 		.tokens = {
5800 			(void *)&cmd_setbonding_lacp_dedicated_queues_set,
5801 			(void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5802 			(void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5803 			(void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5804 			(void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5805 			(void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5806 			NULL
5807 		}
5808 };
5809 
5810 /* *** SET BALANCE XMIT POLICY *** */
5811 struct cmd_set_bonding_balance_xmit_policy_result {
5812 	cmdline_fixed_string_t set;
5813 	cmdline_fixed_string_t bonding;
5814 	cmdline_fixed_string_t balance_xmit_policy;
5815 	portid_t port_id;
5816 	cmdline_fixed_string_t policy;
5817 };
5818 
5819 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5820 		__rte_unused  struct cmdline *cl,
5821 		__rte_unused void *data)
5822 {
5823 	struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5824 	portid_t port_id = res->port_id;
5825 	uint8_t policy;
5826 
5827 	if (!strcmp(res->policy, "l2")) {
5828 		policy = BALANCE_XMIT_POLICY_LAYER2;
5829 	} else if (!strcmp(res->policy, "l23")) {
5830 		policy = BALANCE_XMIT_POLICY_LAYER23;
5831 	} else if (!strcmp(res->policy, "l34")) {
5832 		policy = BALANCE_XMIT_POLICY_LAYER34;
5833 	} else {
5834 		printf("\t Invalid xmit policy selection");
5835 		return;
5836 	}
5837 
5838 	/* Set the bonding mode for the relevant port. */
5839 	if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5840 		printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5841 				port_id);
5842 	}
5843 }
5844 
5845 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5846 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5847 		set, "set");
5848 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5849 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5850 		bonding, "bonding");
5851 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5852 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5853 		balance_xmit_policy, "balance_xmit_policy");
5854 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5855 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5856 		port_id, UINT16);
5857 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5858 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5859 		policy, "l2#l23#l34");
5860 
5861 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5862 		.f = cmd_set_bonding_balance_xmit_policy_parsed,
5863 		.help_str = "set bonding balance_xmit_policy <port_id> "
5864 			"l2|l23|l34: "
5865 			"Set the bonding balance_xmit_policy for port_id",
5866 		.data = NULL,
5867 		.tokens = {
5868 				(void *)&cmd_setbonding_balance_xmit_policy_set,
5869 				(void *)&cmd_setbonding_balance_xmit_policy_bonding,
5870 				(void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5871 				(void *)&cmd_setbonding_balance_xmit_policy_port,
5872 				(void *)&cmd_setbonding_balance_xmit_policy_policy,
5873 				NULL
5874 		}
5875 };
5876 
5877 /* *** SHOW NIC BONDING CONFIGURATION *** */
5878 struct cmd_show_bonding_config_result {
5879 	cmdline_fixed_string_t show;
5880 	cmdline_fixed_string_t bonding;
5881 	cmdline_fixed_string_t config;
5882 	portid_t port_id;
5883 };
5884 
5885 static void cmd_show_bonding_config_parsed(void *parsed_result,
5886 		__rte_unused  struct cmdline *cl,
5887 		__rte_unused void *data)
5888 {
5889 	struct cmd_show_bonding_config_result *res = parsed_result;
5890 	int bonding_mode, agg_mode;
5891 	portid_t slaves[RTE_MAX_ETHPORTS];
5892 	int num_slaves, num_active_slaves;
5893 	int primary_id;
5894 	int i;
5895 	portid_t port_id = res->port_id;
5896 
5897 	/* Display the bonding mode.*/
5898 	bonding_mode = rte_eth_bond_mode_get(port_id);
5899 	if (bonding_mode < 0) {
5900 		printf("\tFailed to get bonding mode for port = %d\n", port_id);
5901 		return;
5902 	} else
5903 		printf("\tBonding mode: %d\n", bonding_mode);
5904 
5905 	if (bonding_mode == BONDING_MODE_BALANCE) {
5906 		int balance_xmit_policy;
5907 
5908 		balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5909 		if (balance_xmit_policy < 0) {
5910 			printf("\tFailed to get balance xmit policy for port = %d\n",
5911 					port_id);
5912 			return;
5913 		} else {
5914 			printf("\tBalance Xmit Policy: ");
5915 
5916 			switch (balance_xmit_policy) {
5917 			case BALANCE_XMIT_POLICY_LAYER2:
5918 				printf("BALANCE_XMIT_POLICY_LAYER2");
5919 				break;
5920 			case BALANCE_XMIT_POLICY_LAYER23:
5921 				printf("BALANCE_XMIT_POLICY_LAYER23");
5922 				break;
5923 			case BALANCE_XMIT_POLICY_LAYER34:
5924 				printf("BALANCE_XMIT_POLICY_LAYER34");
5925 				break;
5926 			}
5927 			printf("\n");
5928 		}
5929 	}
5930 
5931 	if (bonding_mode == BONDING_MODE_8023AD) {
5932 		agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5933 		printf("\tIEEE802.3AD Aggregator Mode: ");
5934 		switch (agg_mode) {
5935 		case AGG_BANDWIDTH:
5936 			printf("bandwidth");
5937 			break;
5938 		case AGG_STABLE:
5939 			printf("stable");
5940 			break;
5941 		case AGG_COUNT:
5942 			printf("count");
5943 			break;
5944 		}
5945 		printf("\n");
5946 	}
5947 
5948 	num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5949 
5950 	if (num_slaves < 0) {
5951 		printf("\tFailed to get slave list for port = %d\n", port_id);
5952 		return;
5953 	}
5954 	if (num_slaves > 0) {
5955 		printf("\tSlaves (%d): [", num_slaves);
5956 		for (i = 0; i < num_slaves - 1; i++)
5957 			printf("%d ", slaves[i]);
5958 
5959 		printf("%d]\n", slaves[num_slaves - 1]);
5960 	} else {
5961 		printf("\tSlaves: []\n");
5962 
5963 	}
5964 
5965 	num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5966 			RTE_MAX_ETHPORTS);
5967 
5968 	if (num_active_slaves < 0) {
5969 		printf("\tFailed to get active slave list for port = %d\n", port_id);
5970 		return;
5971 	}
5972 	if (num_active_slaves > 0) {
5973 		printf("\tActive Slaves (%d): [", num_active_slaves);
5974 		for (i = 0; i < num_active_slaves - 1; i++)
5975 			printf("%d ", slaves[i]);
5976 
5977 		printf("%d]\n", slaves[num_active_slaves - 1]);
5978 
5979 	} else {
5980 		printf("\tActive Slaves: []\n");
5981 
5982 	}
5983 
5984 	primary_id = rte_eth_bond_primary_get(port_id);
5985 	if (primary_id < 0) {
5986 		printf("\tFailed to get primary slave for port = %d\n", port_id);
5987 		return;
5988 	} else
5989 		printf("\tPrimary: [%d]\n", primary_id);
5990 
5991 }
5992 
5993 cmdline_parse_token_string_t cmd_showbonding_config_show =
5994 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5995 		show, "show");
5996 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5997 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5998 		bonding, "bonding");
5999 cmdline_parse_token_string_t cmd_showbonding_config_config =
6000 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6001 		config, "config");
6002 cmdline_parse_token_num_t cmd_showbonding_config_port =
6003 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6004 		port_id, UINT16);
6005 
6006 cmdline_parse_inst_t cmd_show_bonding_config = {
6007 		.f = cmd_show_bonding_config_parsed,
6008 		.help_str = "show bonding config <port_id>: "
6009 			"Show the bonding config for port_id",
6010 		.data = NULL,
6011 		.tokens = {
6012 				(void *)&cmd_showbonding_config_show,
6013 				(void *)&cmd_showbonding_config_bonding,
6014 				(void *)&cmd_showbonding_config_config,
6015 				(void *)&cmd_showbonding_config_port,
6016 				NULL
6017 		}
6018 };
6019 
6020 /* *** SET BONDING PRIMARY *** */
6021 struct cmd_set_bonding_primary_result {
6022 	cmdline_fixed_string_t set;
6023 	cmdline_fixed_string_t bonding;
6024 	cmdline_fixed_string_t primary;
6025 	portid_t slave_id;
6026 	portid_t port_id;
6027 };
6028 
6029 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6030 		__rte_unused  struct cmdline *cl,
6031 		__rte_unused void *data)
6032 {
6033 	struct cmd_set_bonding_primary_result *res = parsed_result;
6034 	portid_t master_port_id = res->port_id;
6035 	portid_t slave_port_id = res->slave_id;
6036 
6037 	/* Set the primary slave for a bonded device. */
6038 	if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6039 		printf("\t Failed to set primary slave for port = %d.\n",
6040 				master_port_id);
6041 		return;
6042 	}
6043 	init_port_config();
6044 }
6045 
6046 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6047 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6048 		set, "set");
6049 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6050 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6051 		bonding, "bonding");
6052 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6053 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6054 		primary, "primary");
6055 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6056 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6057 		slave_id, UINT16);
6058 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6059 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6060 		port_id, UINT16);
6061 
6062 cmdline_parse_inst_t cmd_set_bonding_primary = {
6063 		.f = cmd_set_bonding_primary_parsed,
6064 		.help_str = "set bonding primary <slave_id> <port_id>: "
6065 			"Set the primary slave for port_id",
6066 		.data = NULL,
6067 		.tokens = {
6068 				(void *)&cmd_setbonding_primary_set,
6069 				(void *)&cmd_setbonding_primary_bonding,
6070 				(void *)&cmd_setbonding_primary_primary,
6071 				(void *)&cmd_setbonding_primary_slave,
6072 				(void *)&cmd_setbonding_primary_port,
6073 				NULL
6074 		}
6075 };
6076 
6077 /* *** ADD SLAVE *** */
6078 struct cmd_add_bonding_slave_result {
6079 	cmdline_fixed_string_t add;
6080 	cmdline_fixed_string_t bonding;
6081 	cmdline_fixed_string_t slave;
6082 	portid_t slave_id;
6083 	portid_t port_id;
6084 };
6085 
6086 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6087 		__rte_unused  struct cmdline *cl,
6088 		__rte_unused void *data)
6089 {
6090 	struct cmd_add_bonding_slave_result *res = parsed_result;
6091 	portid_t master_port_id = res->port_id;
6092 	portid_t slave_port_id = res->slave_id;
6093 
6094 	/* add the slave for a bonded device. */
6095 	if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6096 		printf("\t Failed to add slave %d to master port = %d.\n",
6097 				slave_port_id, master_port_id);
6098 		return;
6099 	}
6100 	init_port_config();
6101 	set_port_slave_flag(slave_port_id);
6102 }
6103 
6104 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6105 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6106 		add, "add");
6107 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6108 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6109 		bonding, "bonding");
6110 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6111 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6112 		slave, "slave");
6113 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6114 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6115 		slave_id, UINT16);
6116 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6117 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6118 		port_id, UINT16);
6119 
6120 cmdline_parse_inst_t cmd_add_bonding_slave = {
6121 		.f = cmd_add_bonding_slave_parsed,
6122 		.help_str = "add bonding slave <slave_id> <port_id>: "
6123 			"Add a slave device to a bonded device",
6124 		.data = NULL,
6125 		.tokens = {
6126 				(void *)&cmd_addbonding_slave_add,
6127 				(void *)&cmd_addbonding_slave_bonding,
6128 				(void *)&cmd_addbonding_slave_slave,
6129 				(void *)&cmd_addbonding_slave_slaveid,
6130 				(void *)&cmd_addbonding_slave_port,
6131 				NULL
6132 		}
6133 };
6134 
6135 /* *** REMOVE SLAVE *** */
6136 struct cmd_remove_bonding_slave_result {
6137 	cmdline_fixed_string_t remove;
6138 	cmdline_fixed_string_t bonding;
6139 	cmdline_fixed_string_t slave;
6140 	portid_t slave_id;
6141 	portid_t port_id;
6142 };
6143 
6144 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6145 		__rte_unused  struct cmdline *cl,
6146 		__rte_unused void *data)
6147 {
6148 	struct cmd_remove_bonding_slave_result *res = parsed_result;
6149 	portid_t master_port_id = res->port_id;
6150 	portid_t slave_port_id = res->slave_id;
6151 
6152 	/* remove the slave from a bonded device. */
6153 	if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6154 		printf("\t Failed to remove slave %d from master port = %d.\n",
6155 				slave_port_id, master_port_id);
6156 		return;
6157 	}
6158 	init_port_config();
6159 	clear_port_slave_flag(slave_port_id);
6160 }
6161 
6162 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6163 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6164 				remove, "remove");
6165 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6166 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6167 				bonding, "bonding");
6168 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6169 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6170 				slave, "slave");
6171 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6172 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6173 				slave_id, UINT16);
6174 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6175 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6176 				port_id, UINT16);
6177 
6178 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6179 		.f = cmd_remove_bonding_slave_parsed,
6180 		.help_str = "remove bonding slave <slave_id> <port_id>: "
6181 			"Remove a slave device from a bonded device",
6182 		.data = NULL,
6183 		.tokens = {
6184 				(void *)&cmd_removebonding_slave_remove,
6185 				(void *)&cmd_removebonding_slave_bonding,
6186 				(void *)&cmd_removebonding_slave_slave,
6187 				(void *)&cmd_removebonding_slave_slaveid,
6188 				(void *)&cmd_removebonding_slave_port,
6189 				NULL
6190 		}
6191 };
6192 
6193 /* *** CREATE BONDED DEVICE *** */
6194 struct cmd_create_bonded_device_result {
6195 	cmdline_fixed_string_t create;
6196 	cmdline_fixed_string_t bonded;
6197 	cmdline_fixed_string_t device;
6198 	uint8_t mode;
6199 	uint8_t socket;
6200 };
6201 
6202 static int bond_dev_num = 0;
6203 
6204 static void cmd_create_bonded_device_parsed(void *parsed_result,
6205 		__rte_unused  struct cmdline *cl,
6206 		__rte_unused void *data)
6207 {
6208 	struct cmd_create_bonded_device_result *res = parsed_result;
6209 	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6210 	int port_id;
6211 	int ret;
6212 
6213 	if (test_done == 0) {
6214 		printf("Please stop forwarding first\n");
6215 		return;
6216 	}
6217 
6218 	snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6219 			bond_dev_num++);
6220 
6221 	/* Create a new bonded device. */
6222 	port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6223 	if (port_id < 0) {
6224 		printf("\t Failed to create bonded device.\n");
6225 		return;
6226 	} else {
6227 		printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6228 				port_id);
6229 
6230 		/* Update number of ports */
6231 		nb_ports = rte_eth_dev_count_avail();
6232 		reconfig(port_id, res->socket);
6233 		ret = rte_eth_promiscuous_enable(port_id);
6234 		if (ret != 0)
6235 			printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6236 				port_id, rte_strerror(-ret));
6237 
6238 		ports[port_id].need_setup = 0;
6239 		ports[port_id].port_status = RTE_PORT_STOPPED;
6240 	}
6241 
6242 }
6243 
6244 cmdline_parse_token_string_t cmd_createbonded_device_create =
6245 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6246 				create, "create");
6247 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6248 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6249 				bonded, "bonded");
6250 cmdline_parse_token_string_t cmd_createbonded_device_device =
6251 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6252 				device, "device");
6253 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6254 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6255 				mode, UINT8);
6256 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6257 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6258 				socket, UINT8);
6259 
6260 cmdline_parse_inst_t cmd_create_bonded_device = {
6261 		.f = cmd_create_bonded_device_parsed,
6262 		.help_str = "create bonded device <mode> <socket>: "
6263 			"Create a new bonded device with specific bonding mode and socket",
6264 		.data = NULL,
6265 		.tokens = {
6266 				(void *)&cmd_createbonded_device_create,
6267 				(void *)&cmd_createbonded_device_bonded,
6268 				(void *)&cmd_createbonded_device_device,
6269 				(void *)&cmd_createbonded_device_mode,
6270 				(void *)&cmd_createbonded_device_socket,
6271 				NULL
6272 		}
6273 };
6274 
6275 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6276 struct cmd_set_bond_mac_addr_result {
6277 	cmdline_fixed_string_t set;
6278 	cmdline_fixed_string_t bonding;
6279 	cmdline_fixed_string_t mac_addr;
6280 	uint16_t port_num;
6281 	struct rte_ether_addr address;
6282 };
6283 
6284 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6285 		__rte_unused  struct cmdline *cl,
6286 		__rte_unused void *data)
6287 {
6288 	struct cmd_set_bond_mac_addr_result *res = parsed_result;
6289 	int ret;
6290 
6291 	if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6292 		return;
6293 
6294 	ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6295 
6296 	/* check the return value and print it if is < 0 */
6297 	if (ret < 0)
6298 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6299 }
6300 
6301 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6302 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6303 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6304 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6305 				"bonding");
6306 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6307 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6308 				"mac_addr");
6309 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6310 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6311 				port_num, UINT16);
6312 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6313 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6314 
6315 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6316 		.f = cmd_set_bond_mac_addr_parsed,
6317 		.data = (void *) 0,
6318 		.help_str = "set bonding mac_addr <port_id> <mac_addr>",
6319 		.tokens = {
6320 				(void *)&cmd_set_bond_mac_addr_set,
6321 				(void *)&cmd_set_bond_mac_addr_bonding,
6322 				(void *)&cmd_set_bond_mac_addr_mac,
6323 				(void *)&cmd_set_bond_mac_addr_portnum,
6324 				(void *)&cmd_set_bond_mac_addr_addr,
6325 				NULL
6326 		}
6327 };
6328 
6329 
6330 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6331 struct cmd_set_bond_mon_period_result {
6332 	cmdline_fixed_string_t set;
6333 	cmdline_fixed_string_t bonding;
6334 	cmdline_fixed_string_t mon_period;
6335 	uint16_t port_num;
6336 	uint32_t period_ms;
6337 };
6338 
6339 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6340 		__rte_unused  struct cmdline *cl,
6341 		__rte_unused void *data)
6342 {
6343 	struct cmd_set_bond_mon_period_result *res = parsed_result;
6344 	int ret;
6345 
6346 	ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6347 
6348 	/* check the return value and print it if is < 0 */
6349 	if (ret < 0)
6350 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6351 }
6352 
6353 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6354 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6355 				set, "set");
6356 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6357 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6358 				bonding, "bonding");
6359 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6360 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6361 				mon_period,	"mon_period");
6362 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6363 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6364 				port_num, UINT16);
6365 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6366 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6367 				period_ms, UINT32);
6368 
6369 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6370 		.f = cmd_set_bond_mon_period_parsed,
6371 		.data = (void *) 0,
6372 		.help_str = "set bonding mon_period <port_id> <period_ms>",
6373 		.tokens = {
6374 				(void *)&cmd_set_bond_mon_period_set,
6375 				(void *)&cmd_set_bond_mon_period_bonding,
6376 				(void *)&cmd_set_bond_mon_period_mon_period,
6377 				(void *)&cmd_set_bond_mon_period_portnum,
6378 				(void *)&cmd_set_bond_mon_period_period_ms,
6379 				NULL
6380 		}
6381 };
6382 
6383 
6384 
6385 struct cmd_set_bonding_agg_mode_policy_result {
6386 	cmdline_fixed_string_t set;
6387 	cmdline_fixed_string_t bonding;
6388 	cmdline_fixed_string_t agg_mode;
6389 	uint16_t port_num;
6390 	cmdline_fixed_string_t policy;
6391 };
6392 
6393 
6394 static void
6395 cmd_set_bonding_agg_mode(void *parsed_result,
6396 		__rte_unused struct cmdline *cl,
6397 		__rte_unused void *data)
6398 {
6399 	struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6400 	uint8_t policy = AGG_BANDWIDTH;
6401 
6402 	if (!strcmp(res->policy, "bandwidth"))
6403 		policy = AGG_BANDWIDTH;
6404 	else if (!strcmp(res->policy, "stable"))
6405 		policy = AGG_STABLE;
6406 	else if (!strcmp(res->policy, "count"))
6407 		policy = AGG_COUNT;
6408 
6409 	rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6410 }
6411 
6412 
6413 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6414 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6415 				set, "set");
6416 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6417 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6418 				bonding, "bonding");
6419 
6420 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6421 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6422 				agg_mode, "agg_mode");
6423 
6424 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6425 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6426 				port_num, UINT16);
6427 
6428 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6429 	TOKEN_STRING_INITIALIZER(
6430 			struct cmd_set_bonding_balance_xmit_policy_result,
6431 		policy, "stable#bandwidth#count");
6432 
6433 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6434 	.f = cmd_set_bonding_agg_mode,
6435 	.data = (void *) 0,
6436 	.help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6437 	.tokens = {
6438 			(void *)&cmd_set_bonding_agg_mode_set,
6439 			(void *)&cmd_set_bonding_agg_mode_bonding,
6440 			(void *)&cmd_set_bonding_agg_mode_agg_mode,
6441 			(void *)&cmd_set_bonding_agg_mode_portnum,
6442 			(void *)&cmd_set_bonding_agg_mode_policy_string,
6443 			NULL
6444 		}
6445 };
6446 
6447 
6448 #endif /* RTE_LIBRTE_PMD_BOND */
6449 
6450 /* *** SET FORWARDING MODE *** */
6451 struct cmd_set_fwd_mode_result {
6452 	cmdline_fixed_string_t set;
6453 	cmdline_fixed_string_t fwd;
6454 	cmdline_fixed_string_t mode;
6455 };
6456 
6457 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6458 				    __rte_unused struct cmdline *cl,
6459 				    __rte_unused void *data)
6460 {
6461 	struct cmd_set_fwd_mode_result *res = parsed_result;
6462 
6463 	retry_enabled = 0;
6464 	set_pkt_forwarding_mode(res->mode);
6465 }
6466 
6467 cmdline_parse_token_string_t cmd_setfwd_set =
6468 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6469 cmdline_parse_token_string_t cmd_setfwd_fwd =
6470 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6471 cmdline_parse_token_string_t cmd_setfwd_mode =
6472 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6473 		"" /* defined at init */);
6474 
6475 cmdline_parse_inst_t cmd_set_fwd_mode = {
6476 	.f = cmd_set_fwd_mode_parsed,
6477 	.data = NULL,
6478 	.help_str = NULL, /* defined at init */
6479 	.tokens = {
6480 		(void *)&cmd_setfwd_set,
6481 		(void *)&cmd_setfwd_fwd,
6482 		(void *)&cmd_setfwd_mode,
6483 		NULL,
6484 	},
6485 };
6486 
6487 static void cmd_set_fwd_mode_init(void)
6488 {
6489 	char *modes, *c;
6490 	static char token[128];
6491 	static char help[256];
6492 	cmdline_parse_token_string_t *token_struct;
6493 
6494 	modes = list_pkt_forwarding_modes();
6495 	snprintf(help, sizeof(help), "set fwd %s: "
6496 		"Set packet forwarding mode", modes);
6497 	cmd_set_fwd_mode.help_str = help;
6498 
6499 	/* string token separator is # */
6500 	for (c = token; *modes != '\0'; modes++)
6501 		if (*modes == '|')
6502 			*c++ = '#';
6503 		else
6504 			*c++ = *modes;
6505 	token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6506 	token_struct->string_data.str = token;
6507 }
6508 
6509 /* *** SET RETRY FORWARDING MODE *** */
6510 struct cmd_set_fwd_retry_mode_result {
6511 	cmdline_fixed_string_t set;
6512 	cmdline_fixed_string_t fwd;
6513 	cmdline_fixed_string_t mode;
6514 	cmdline_fixed_string_t retry;
6515 };
6516 
6517 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6518 			    __rte_unused struct cmdline *cl,
6519 			    __rte_unused void *data)
6520 {
6521 	struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6522 
6523 	retry_enabled = 1;
6524 	set_pkt_forwarding_mode(res->mode);
6525 }
6526 
6527 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6528 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6529 			set, "set");
6530 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6531 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6532 			fwd, "fwd");
6533 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6534 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6535 			mode,
6536 		"" /* defined at init */);
6537 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6538 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6539 			retry, "retry");
6540 
6541 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6542 	.f = cmd_set_fwd_retry_mode_parsed,
6543 	.data = NULL,
6544 	.help_str = NULL, /* defined at init */
6545 	.tokens = {
6546 		(void *)&cmd_setfwd_retry_set,
6547 		(void *)&cmd_setfwd_retry_fwd,
6548 		(void *)&cmd_setfwd_retry_mode,
6549 		(void *)&cmd_setfwd_retry_retry,
6550 		NULL,
6551 	},
6552 };
6553 
6554 static void cmd_set_fwd_retry_mode_init(void)
6555 {
6556 	char *modes, *c;
6557 	static char token[128];
6558 	static char help[256];
6559 	cmdline_parse_token_string_t *token_struct;
6560 
6561 	modes = list_pkt_forwarding_retry_modes();
6562 	snprintf(help, sizeof(help), "set fwd %s retry: "
6563 		"Set packet forwarding mode with retry", modes);
6564 	cmd_set_fwd_retry_mode.help_str = help;
6565 
6566 	/* string token separator is # */
6567 	for (c = token; *modes != '\0'; modes++)
6568 		if (*modes == '|')
6569 			*c++ = '#';
6570 		else
6571 			*c++ = *modes;
6572 	token_struct = (cmdline_parse_token_string_t *)
6573 		cmd_set_fwd_retry_mode.tokens[2];
6574 	token_struct->string_data.str = token;
6575 }
6576 
6577 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6578 struct cmd_set_burst_tx_retry_result {
6579 	cmdline_fixed_string_t set;
6580 	cmdline_fixed_string_t burst;
6581 	cmdline_fixed_string_t tx;
6582 	cmdline_fixed_string_t delay;
6583 	uint32_t time;
6584 	cmdline_fixed_string_t retry;
6585 	uint32_t retry_num;
6586 };
6587 
6588 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6589 					__rte_unused struct cmdline *cl,
6590 					__rte_unused void *data)
6591 {
6592 	struct cmd_set_burst_tx_retry_result *res = parsed_result;
6593 
6594 	if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6595 		&& !strcmp(res->tx, "tx")) {
6596 		if (!strcmp(res->delay, "delay"))
6597 			burst_tx_delay_time = res->time;
6598 		if (!strcmp(res->retry, "retry"))
6599 			burst_tx_retry_num = res->retry_num;
6600 	}
6601 
6602 }
6603 
6604 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6605 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6606 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6607 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6608 				 "burst");
6609 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6610 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6611 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6612 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6613 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6614 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6615 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6616 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6617 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6618 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6619 
6620 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6621 	.f = cmd_set_burst_tx_retry_parsed,
6622 	.help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6623 	.tokens = {
6624 		(void *)&cmd_set_burst_tx_retry_set,
6625 		(void *)&cmd_set_burst_tx_retry_burst,
6626 		(void *)&cmd_set_burst_tx_retry_tx,
6627 		(void *)&cmd_set_burst_tx_retry_delay,
6628 		(void *)&cmd_set_burst_tx_retry_time,
6629 		(void *)&cmd_set_burst_tx_retry_retry,
6630 		(void *)&cmd_set_burst_tx_retry_retry_num,
6631 		NULL,
6632 	},
6633 };
6634 
6635 /* *** SET PROMISC MODE *** */
6636 struct cmd_set_promisc_mode_result {
6637 	cmdline_fixed_string_t set;
6638 	cmdline_fixed_string_t promisc;
6639 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6640 	uint16_t port_num;               /* valid if "allports" argument == 0 */
6641 	cmdline_fixed_string_t mode;
6642 };
6643 
6644 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6645 					__rte_unused struct cmdline *cl,
6646 					void *allports)
6647 {
6648 	struct cmd_set_promisc_mode_result *res = parsed_result;
6649 	int enable;
6650 	portid_t i;
6651 
6652 	if (!strcmp(res->mode, "on"))
6653 		enable = 1;
6654 	else
6655 		enable = 0;
6656 
6657 	/* all ports */
6658 	if (allports) {
6659 		RTE_ETH_FOREACH_DEV(i)
6660 			eth_set_promisc_mode(i, enable);
6661 	} else {
6662 		eth_set_promisc_mode(res->port_num, enable);
6663 	}
6664 }
6665 
6666 cmdline_parse_token_string_t cmd_setpromisc_set =
6667 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6668 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6669 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6670 				 "promisc");
6671 cmdline_parse_token_string_t cmd_setpromisc_portall =
6672 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6673 				 "all");
6674 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6675 	TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6676 			      UINT16);
6677 cmdline_parse_token_string_t cmd_setpromisc_mode =
6678 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6679 				 "on#off");
6680 
6681 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6682 	.f = cmd_set_promisc_mode_parsed,
6683 	.data = (void *)1,
6684 	.help_str = "set promisc all on|off: Set promisc mode for all ports",
6685 	.tokens = {
6686 		(void *)&cmd_setpromisc_set,
6687 		(void *)&cmd_setpromisc_promisc,
6688 		(void *)&cmd_setpromisc_portall,
6689 		(void *)&cmd_setpromisc_mode,
6690 		NULL,
6691 	},
6692 };
6693 
6694 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6695 	.f = cmd_set_promisc_mode_parsed,
6696 	.data = (void *)0,
6697 	.help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6698 	.tokens = {
6699 		(void *)&cmd_setpromisc_set,
6700 		(void *)&cmd_setpromisc_promisc,
6701 		(void *)&cmd_setpromisc_portnum,
6702 		(void *)&cmd_setpromisc_mode,
6703 		NULL,
6704 	},
6705 };
6706 
6707 /* *** SET ALLMULTI MODE *** */
6708 struct cmd_set_allmulti_mode_result {
6709 	cmdline_fixed_string_t set;
6710 	cmdline_fixed_string_t allmulti;
6711 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6712 	uint16_t port_num;               /* valid if "allports" argument == 0 */
6713 	cmdline_fixed_string_t mode;
6714 };
6715 
6716 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6717 					__rte_unused struct cmdline *cl,
6718 					void *allports)
6719 {
6720 	struct cmd_set_allmulti_mode_result *res = parsed_result;
6721 	int enable;
6722 	portid_t i;
6723 
6724 	if (!strcmp(res->mode, "on"))
6725 		enable = 1;
6726 	else
6727 		enable = 0;
6728 
6729 	/* all ports */
6730 	if (allports) {
6731 		RTE_ETH_FOREACH_DEV(i) {
6732 			eth_set_allmulticast_mode(i, enable);
6733 		}
6734 	}
6735 	else {
6736 		eth_set_allmulticast_mode(res->port_num, enable);
6737 	}
6738 }
6739 
6740 cmdline_parse_token_string_t cmd_setallmulti_set =
6741 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6742 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6743 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6744 				 "allmulti");
6745 cmdline_parse_token_string_t cmd_setallmulti_portall =
6746 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6747 				 "all");
6748 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6749 	TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6750 			      UINT16);
6751 cmdline_parse_token_string_t cmd_setallmulti_mode =
6752 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6753 				 "on#off");
6754 
6755 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6756 	.f = cmd_set_allmulti_mode_parsed,
6757 	.data = (void *)1,
6758 	.help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6759 	.tokens = {
6760 		(void *)&cmd_setallmulti_set,
6761 		(void *)&cmd_setallmulti_allmulti,
6762 		(void *)&cmd_setallmulti_portall,
6763 		(void *)&cmd_setallmulti_mode,
6764 		NULL,
6765 	},
6766 };
6767 
6768 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6769 	.f = cmd_set_allmulti_mode_parsed,
6770 	.data = (void *)0,
6771 	.help_str = "set allmulti <port_id> on|off: "
6772 		"Set allmulti mode on port_id",
6773 	.tokens = {
6774 		(void *)&cmd_setallmulti_set,
6775 		(void *)&cmd_setallmulti_allmulti,
6776 		(void *)&cmd_setallmulti_portnum,
6777 		(void *)&cmd_setallmulti_mode,
6778 		NULL,
6779 	},
6780 };
6781 
6782 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6783 struct cmd_link_flow_ctrl_set_result {
6784 	cmdline_fixed_string_t set;
6785 	cmdline_fixed_string_t flow_ctrl;
6786 	cmdline_fixed_string_t rx;
6787 	cmdline_fixed_string_t rx_lfc_mode;
6788 	cmdline_fixed_string_t tx;
6789 	cmdline_fixed_string_t tx_lfc_mode;
6790 	cmdline_fixed_string_t mac_ctrl_frame_fwd;
6791 	cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6792 	cmdline_fixed_string_t autoneg_str;
6793 	cmdline_fixed_string_t autoneg;
6794 	cmdline_fixed_string_t hw_str;
6795 	uint32_t high_water;
6796 	cmdline_fixed_string_t lw_str;
6797 	uint32_t low_water;
6798 	cmdline_fixed_string_t pt_str;
6799 	uint16_t pause_time;
6800 	cmdline_fixed_string_t xon_str;
6801 	uint16_t send_xon;
6802 	portid_t port_id;
6803 };
6804 
6805 cmdline_parse_token_string_t cmd_lfc_set_set =
6806 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6807 				set, "set");
6808 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6809 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6810 				flow_ctrl, "flow_ctrl");
6811 cmdline_parse_token_string_t cmd_lfc_set_rx =
6812 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6813 				rx, "rx");
6814 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6815 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6816 				rx_lfc_mode, "on#off");
6817 cmdline_parse_token_string_t cmd_lfc_set_tx =
6818 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6819 				tx, "tx");
6820 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6821 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6822 				tx_lfc_mode, "on#off");
6823 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6824 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6825 				hw_str, "high_water");
6826 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6827 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6828 				high_water, UINT32);
6829 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6830 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6831 				lw_str, "low_water");
6832 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6833 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6834 				low_water, UINT32);
6835 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6836 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6837 				pt_str, "pause_time");
6838 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6839 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6840 				pause_time, UINT16);
6841 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6842 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6843 				xon_str, "send_xon");
6844 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6845 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6846 				send_xon, UINT16);
6847 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6848 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6849 				mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6850 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6851 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6852 				mac_ctrl_frame_fwd_mode, "on#off");
6853 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6854 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6855 				autoneg_str, "autoneg");
6856 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6857 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6858 				autoneg, "on#off");
6859 cmdline_parse_token_num_t cmd_lfc_set_portid =
6860 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6861 				port_id, UINT16);
6862 
6863 /* forward declaration */
6864 static void
6865 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6866 			      void *data);
6867 
6868 cmdline_parse_inst_t cmd_link_flow_control_set = {
6869 	.f = cmd_link_flow_ctrl_set_parsed,
6870 	.data = NULL,
6871 	.help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6872 		"<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6873 		"autoneg on|off <port_id>: Configure the Ethernet flow control",
6874 	.tokens = {
6875 		(void *)&cmd_lfc_set_set,
6876 		(void *)&cmd_lfc_set_flow_ctrl,
6877 		(void *)&cmd_lfc_set_rx,
6878 		(void *)&cmd_lfc_set_rx_mode,
6879 		(void *)&cmd_lfc_set_tx,
6880 		(void *)&cmd_lfc_set_tx_mode,
6881 		(void *)&cmd_lfc_set_high_water,
6882 		(void *)&cmd_lfc_set_low_water,
6883 		(void *)&cmd_lfc_set_pause_time,
6884 		(void *)&cmd_lfc_set_send_xon,
6885 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6886 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6887 		(void *)&cmd_lfc_set_autoneg_str,
6888 		(void *)&cmd_lfc_set_autoneg,
6889 		(void *)&cmd_lfc_set_portid,
6890 		NULL,
6891 	},
6892 };
6893 
6894 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6895 	.f = cmd_link_flow_ctrl_set_parsed,
6896 	.data = (void *)&cmd_link_flow_control_set_rx,
6897 	.help_str = "set flow_ctrl rx on|off <port_id>: "
6898 		"Change rx flow control parameter",
6899 	.tokens = {
6900 		(void *)&cmd_lfc_set_set,
6901 		(void *)&cmd_lfc_set_flow_ctrl,
6902 		(void *)&cmd_lfc_set_rx,
6903 		(void *)&cmd_lfc_set_rx_mode,
6904 		(void *)&cmd_lfc_set_portid,
6905 		NULL,
6906 	},
6907 };
6908 
6909 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6910 	.f = cmd_link_flow_ctrl_set_parsed,
6911 	.data = (void *)&cmd_link_flow_control_set_tx,
6912 	.help_str = "set flow_ctrl tx on|off <port_id>: "
6913 		"Change tx flow control parameter",
6914 	.tokens = {
6915 		(void *)&cmd_lfc_set_set,
6916 		(void *)&cmd_lfc_set_flow_ctrl,
6917 		(void *)&cmd_lfc_set_tx,
6918 		(void *)&cmd_lfc_set_tx_mode,
6919 		(void *)&cmd_lfc_set_portid,
6920 		NULL,
6921 	},
6922 };
6923 
6924 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6925 	.f = cmd_link_flow_ctrl_set_parsed,
6926 	.data = (void *)&cmd_link_flow_control_set_hw,
6927 	.help_str = "set flow_ctrl high_water <value> <port_id>: "
6928 		"Change high water flow control parameter",
6929 	.tokens = {
6930 		(void *)&cmd_lfc_set_set,
6931 		(void *)&cmd_lfc_set_flow_ctrl,
6932 		(void *)&cmd_lfc_set_high_water_str,
6933 		(void *)&cmd_lfc_set_high_water,
6934 		(void *)&cmd_lfc_set_portid,
6935 		NULL,
6936 	},
6937 };
6938 
6939 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6940 	.f = cmd_link_flow_ctrl_set_parsed,
6941 	.data = (void *)&cmd_link_flow_control_set_lw,
6942 	.help_str = "set flow_ctrl low_water <value> <port_id>: "
6943 		"Change low water flow control parameter",
6944 	.tokens = {
6945 		(void *)&cmd_lfc_set_set,
6946 		(void *)&cmd_lfc_set_flow_ctrl,
6947 		(void *)&cmd_lfc_set_low_water_str,
6948 		(void *)&cmd_lfc_set_low_water,
6949 		(void *)&cmd_lfc_set_portid,
6950 		NULL,
6951 	},
6952 };
6953 
6954 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6955 	.f = cmd_link_flow_ctrl_set_parsed,
6956 	.data = (void *)&cmd_link_flow_control_set_pt,
6957 	.help_str = "set flow_ctrl pause_time <value> <port_id>: "
6958 		"Change pause time flow control parameter",
6959 	.tokens = {
6960 		(void *)&cmd_lfc_set_set,
6961 		(void *)&cmd_lfc_set_flow_ctrl,
6962 		(void *)&cmd_lfc_set_pause_time_str,
6963 		(void *)&cmd_lfc_set_pause_time,
6964 		(void *)&cmd_lfc_set_portid,
6965 		NULL,
6966 	},
6967 };
6968 
6969 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6970 	.f = cmd_link_flow_ctrl_set_parsed,
6971 	.data = (void *)&cmd_link_flow_control_set_xon,
6972 	.help_str = "set flow_ctrl send_xon <value> <port_id>: "
6973 		"Change send_xon flow control parameter",
6974 	.tokens = {
6975 		(void *)&cmd_lfc_set_set,
6976 		(void *)&cmd_lfc_set_flow_ctrl,
6977 		(void *)&cmd_lfc_set_send_xon_str,
6978 		(void *)&cmd_lfc_set_send_xon,
6979 		(void *)&cmd_lfc_set_portid,
6980 		NULL,
6981 	},
6982 };
6983 
6984 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6985 	.f = cmd_link_flow_ctrl_set_parsed,
6986 	.data = (void *)&cmd_link_flow_control_set_macfwd,
6987 	.help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6988 		"Change mac ctrl fwd flow control parameter",
6989 	.tokens = {
6990 		(void *)&cmd_lfc_set_set,
6991 		(void *)&cmd_lfc_set_flow_ctrl,
6992 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6993 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6994 		(void *)&cmd_lfc_set_portid,
6995 		NULL,
6996 	},
6997 };
6998 
6999 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7000 	.f = cmd_link_flow_ctrl_set_parsed,
7001 	.data = (void *)&cmd_link_flow_control_set_autoneg,
7002 	.help_str = "set flow_ctrl autoneg on|off <port_id>: "
7003 		"Change autoneg flow control parameter",
7004 	.tokens = {
7005 		(void *)&cmd_lfc_set_set,
7006 		(void *)&cmd_lfc_set_flow_ctrl,
7007 		(void *)&cmd_lfc_set_autoneg_str,
7008 		(void *)&cmd_lfc_set_autoneg,
7009 		(void *)&cmd_lfc_set_portid,
7010 		NULL,
7011 	},
7012 };
7013 
7014 static void
7015 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7016 			      __rte_unused struct cmdline *cl,
7017 			      void *data)
7018 {
7019 	struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7020 	cmdline_parse_inst_t *cmd = data;
7021 	struct rte_eth_fc_conf fc_conf;
7022 	int rx_fc_en = 0;
7023 	int tx_fc_en = 0;
7024 	int ret;
7025 
7026 	/*
7027 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7028 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7029 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7030 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7031 	 */
7032 	static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7033 			{RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7034 	};
7035 
7036 	/* Partial command line, retrieve current configuration */
7037 	if (cmd) {
7038 		ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7039 		if (ret != 0) {
7040 			printf("cannot get current flow ctrl parameters, return"
7041 			       "code = %d\n", ret);
7042 			return;
7043 		}
7044 
7045 		if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7046 		    (fc_conf.mode == RTE_FC_FULL))
7047 			rx_fc_en = 1;
7048 		if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7049 		    (fc_conf.mode == RTE_FC_FULL))
7050 			tx_fc_en = 1;
7051 	}
7052 
7053 	if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7054 		rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7055 
7056 	if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7057 		tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7058 
7059 	fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7060 
7061 	if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7062 		fc_conf.high_water = res->high_water;
7063 
7064 	if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7065 		fc_conf.low_water = res->low_water;
7066 
7067 	if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7068 		fc_conf.pause_time = res->pause_time;
7069 
7070 	if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7071 		fc_conf.send_xon = res->send_xon;
7072 
7073 	if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7074 		if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7075 			fc_conf.mac_ctrl_frame_fwd = 1;
7076 		else
7077 			fc_conf.mac_ctrl_frame_fwd = 0;
7078 	}
7079 
7080 	if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7081 		fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7082 
7083 	ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7084 	if (ret != 0)
7085 		printf("bad flow contrl parameter, return code = %d \n", ret);
7086 }
7087 
7088 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7089 struct cmd_priority_flow_ctrl_set_result {
7090 	cmdline_fixed_string_t set;
7091 	cmdline_fixed_string_t pfc_ctrl;
7092 	cmdline_fixed_string_t rx;
7093 	cmdline_fixed_string_t rx_pfc_mode;
7094 	cmdline_fixed_string_t tx;
7095 	cmdline_fixed_string_t tx_pfc_mode;
7096 	uint32_t high_water;
7097 	uint32_t low_water;
7098 	uint16_t pause_time;
7099 	uint8_t  priority;
7100 	portid_t port_id;
7101 };
7102 
7103 static void
7104 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7105 		       __rte_unused struct cmdline *cl,
7106 		       __rte_unused void *data)
7107 {
7108 	struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7109 	struct rte_eth_pfc_conf pfc_conf;
7110 	int rx_fc_enable, tx_fc_enable;
7111 	int ret;
7112 
7113 	/*
7114 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7115 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7116 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7117 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7118 	 */
7119 	static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7120 		{RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7121 	};
7122 
7123 	memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7124 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7125 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7126 	pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7127 	pfc_conf.fc.high_water = res->high_water;
7128 	pfc_conf.fc.low_water  = res->low_water;
7129 	pfc_conf.fc.pause_time = res->pause_time;
7130 	pfc_conf.priority      = res->priority;
7131 
7132 	ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7133 	if (ret != 0)
7134 		printf("bad priority flow contrl parameter, return code = %d \n", ret);
7135 }
7136 
7137 cmdline_parse_token_string_t cmd_pfc_set_set =
7138 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7139 				set, "set");
7140 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7141 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7142 				pfc_ctrl, "pfc_ctrl");
7143 cmdline_parse_token_string_t cmd_pfc_set_rx =
7144 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7145 				rx, "rx");
7146 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7147 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7148 				rx_pfc_mode, "on#off");
7149 cmdline_parse_token_string_t cmd_pfc_set_tx =
7150 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7151 				tx, "tx");
7152 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7153 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7154 				tx_pfc_mode, "on#off");
7155 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7156 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7157 				high_water, UINT32);
7158 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7159 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7160 				low_water, UINT32);
7161 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7162 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7163 				pause_time, UINT16);
7164 cmdline_parse_token_num_t cmd_pfc_set_priority =
7165 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7166 				priority, UINT8);
7167 cmdline_parse_token_num_t cmd_pfc_set_portid =
7168 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7169 				port_id, UINT16);
7170 
7171 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7172 	.f = cmd_priority_flow_ctrl_set_parsed,
7173 	.data = NULL,
7174 	.help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7175 		"<pause_time> <priority> <port_id>: "
7176 		"Configure the Ethernet priority flow control",
7177 	.tokens = {
7178 		(void *)&cmd_pfc_set_set,
7179 		(void *)&cmd_pfc_set_flow_ctrl,
7180 		(void *)&cmd_pfc_set_rx,
7181 		(void *)&cmd_pfc_set_rx_mode,
7182 		(void *)&cmd_pfc_set_tx,
7183 		(void *)&cmd_pfc_set_tx_mode,
7184 		(void *)&cmd_pfc_set_high_water,
7185 		(void *)&cmd_pfc_set_low_water,
7186 		(void *)&cmd_pfc_set_pause_time,
7187 		(void *)&cmd_pfc_set_priority,
7188 		(void *)&cmd_pfc_set_portid,
7189 		NULL,
7190 	},
7191 };
7192 
7193 /* *** RESET CONFIGURATION *** */
7194 struct cmd_reset_result {
7195 	cmdline_fixed_string_t reset;
7196 	cmdline_fixed_string_t def;
7197 };
7198 
7199 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7200 			     struct cmdline *cl,
7201 			     __rte_unused void *data)
7202 {
7203 	cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7204 	set_def_fwd_config();
7205 }
7206 
7207 cmdline_parse_token_string_t cmd_reset_set =
7208 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7209 cmdline_parse_token_string_t cmd_reset_def =
7210 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7211 				 "default");
7212 
7213 cmdline_parse_inst_t cmd_reset = {
7214 	.f = cmd_reset_parsed,
7215 	.data = NULL,
7216 	.help_str = "set default: Reset default forwarding configuration",
7217 	.tokens = {
7218 		(void *)&cmd_reset_set,
7219 		(void *)&cmd_reset_def,
7220 		NULL,
7221 	},
7222 };
7223 
7224 /* *** START FORWARDING *** */
7225 struct cmd_start_result {
7226 	cmdline_fixed_string_t start;
7227 };
7228 
7229 cmdline_parse_token_string_t cmd_start_start =
7230 	TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7231 
7232 static void cmd_start_parsed(__rte_unused void *parsed_result,
7233 			     __rte_unused struct cmdline *cl,
7234 			     __rte_unused void *data)
7235 {
7236 	start_packet_forwarding(0);
7237 }
7238 
7239 cmdline_parse_inst_t cmd_start = {
7240 	.f = cmd_start_parsed,
7241 	.data = NULL,
7242 	.help_str = "start: Start packet forwarding",
7243 	.tokens = {
7244 		(void *)&cmd_start_start,
7245 		NULL,
7246 	},
7247 };
7248 
7249 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7250 struct cmd_start_tx_first_result {
7251 	cmdline_fixed_string_t start;
7252 	cmdline_fixed_string_t tx_first;
7253 };
7254 
7255 static void
7256 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7257 			  __rte_unused struct cmdline *cl,
7258 			  __rte_unused void *data)
7259 {
7260 	start_packet_forwarding(1);
7261 }
7262 
7263 cmdline_parse_token_string_t cmd_start_tx_first_start =
7264 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7265 				 "start");
7266 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7267 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7268 				 tx_first, "tx_first");
7269 
7270 cmdline_parse_inst_t cmd_start_tx_first = {
7271 	.f = cmd_start_tx_first_parsed,
7272 	.data = NULL,
7273 	.help_str = "start tx_first: Start packet forwarding, "
7274 		"after sending 1 burst of packets",
7275 	.tokens = {
7276 		(void *)&cmd_start_tx_first_start,
7277 		(void *)&cmd_start_tx_first_tx_first,
7278 		NULL,
7279 	},
7280 };
7281 
7282 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7283 struct cmd_start_tx_first_n_result {
7284 	cmdline_fixed_string_t start;
7285 	cmdline_fixed_string_t tx_first;
7286 	uint32_t tx_num;
7287 };
7288 
7289 static void
7290 cmd_start_tx_first_n_parsed(void *parsed_result,
7291 			  __rte_unused struct cmdline *cl,
7292 			  __rte_unused void *data)
7293 {
7294 	struct cmd_start_tx_first_n_result *res = parsed_result;
7295 
7296 	start_packet_forwarding(res->tx_num);
7297 }
7298 
7299 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7300 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7301 			start, "start");
7302 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7303 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7304 			tx_first, "tx_first");
7305 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7306 	TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7307 			tx_num, UINT32);
7308 
7309 cmdline_parse_inst_t cmd_start_tx_first_n = {
7310 	.f = cmd_start_tx_first_n_parsed,
7311 	.data = NULL,
7312 	.help_str = "start tx_first <num>: "
7313 		"packet forwarding, after sending <num> bursts of packets",
7314 	.tokens = {
7315 		(void *)&cmd_start_tx_first_n_start,
7316 		(void *)&cmd_start_tx_first_n_tx_first,
7317 		(void *)&cmd_start_tx_first_n_tx_num,
7318 		NULL,
7319 	},
7320 };
7321 
7322 /* *** SET LINK UP *** */
7323 struct cmd_set_link_up_result {
7324 	cmdline_fixed_string_t set;
7325 	cmdline_fixed_string_t link_up;
7326 	cmdline_fixed_string_t port;
7327 	portid_t port_id;
7328 };
7329 
7330 cmdline_parse_token_string_t cmd_set_link_up_set =
7331 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7332 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7333 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7334 				"link-up");
7335 cmdline_parse_token_string_t cmd_set_link_up_port =
7336 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7337 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7338 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7339 
7340 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7341 			     __rte_unused struct cmdline *cl,
7342 			     __rte_unused void *data)
7343 {
7344 	struct cmd_set_link_up_result *res = parsed_result;
7345 	dev_set_link_up(res->port_id);
7346 }
7347 
7348 cmdline_parse_inst_t cmd_set_link_up = {
7349 	.f = cmd_set_link_up_parsed,
7350 	.data = NULL,
7351 	.help_str = "set link-up port <port id>",
7352 	.tokens = {
7353 		(void *)&cmd_set_link_up_set,
7354 		(void *)&cmd_set_link_up_link_up,
7355 		(void *)&cmd_set_link_up_port,
7356 		(void *)&cmd_set_link_up_port_id,
7357 		NULL,
7358 	},
7359 };
7360 
7361 /* *** SET LINK DOWN *** */
7362 struct cmd_set_link_down_result {
7363 	cmdline_fixed_string_t set;
7364 	cmdline_fixed_string_t link_down;
7365 	cmdline_fixed_string_t port;
7366 	portid_t port_id;
7367 };
7368 
7369 cmdline_parse_token_string_t cmd_set_link_down_set =
7370 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7371 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7372 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7373 				"link-down");
7374 cmdline_parse_token_string_t cmd_set_link_down_port =
7375 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7376 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7377 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7378 
7379 static void cmd_set_link_down_parsed(
7380 				__rte_unused void *parsed_result,
7381 				__rte_unused struct cmdline *cl,
7382 				__rte_unused void *data)
7383 {
7384 	struct cmd_set_link_down_result *res = parsed_result;
7385 	dev_set_link_down(res->port_id);
7386 }
7387 
7388 cmdline_parse_inst_t cmd_set_link_down = {
7389 	.f = cmd_set_link_down_parsed,
7390 	.data = NULL,
7391 	.help_str = "set link-down port <port id>",
7392 	.tokens = {
7393 		(void *)&cmd_set_link_down_set,
7394 		(void *)&cmd_set_link_down_link_down,
7395 		(void *)&cmd_set_link_down_port,
7396 		(void *)&cmd_set_link_down_port_id,
7397 		NULL,
7398 	},
7399 };
7400 
7401 /* *** SHOW CFG *** */
7402 struct cmd_showcfg_result {
7403 	cmdline_fixed_string_t show;
7404 	cmdline_fixed_string_t cfg;
7405 	cmdline_fixed_string_t what;
7406 };
7407 
7408 static void cmd_showcfg_parsed(void *parsed_result,
7409 			       __rte_unused struct cmdline *cl,
7410 			       __rte_unused void *data)
7411 {
7412 	struct cmd_showcfg_result *res = parsed_result;
7413 	if (!strcmp(res->what, "rxtx"))
7414 		rxtx_config_display();
7415 	else if (!strcmp(res->what, "cores"))
7416 		fwd_lcores_config_display();
7417 	else if (!strcmp(res->what, "fwd"))
7418 		pkt_fwd_config_display(&cur_fwd_config);
7419 	else if (!strcmp(res->what, "txpkts"))
7420 		show_tx_pkt_segments();
7421 }
7422 
7423 cmdline_parse_token_string_t cmd_showcfg_show =
7424 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7425 cmdline_parse_token_string_t cmd_showcfg_port =
7426 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7427 cmdline_parse_token_string_t cmd_showcfg_what =
7428 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7429 				 "rxtx#cores#fwd#txpkts");
7430 
7431 cmdline_parse_inst_t cmd_showcfg = {
7432 	.f = cmd_showcfg_parsed,
7433 	.data = NULL,
7434 	.help_str = "show config rxtx|cores|fwd|txpkts",
7435 	.tokens = {
7436 		(void *)&cmd_showcfg_show,
7437 		(void *)&cmd_showcfg_port,
7438 		(void *)&cmd_showcfg_what,
7439 		NULL,
7440 	},
7441 };
7442 
7443 /* *** SHOW ALL PORT INFO *** */
7444 struct cmd_showportall_result {
7445 	cmdline_fixed_string_t show;
7446 	cmdline_fixed_string_t port;
7447 	cmdline_fixed_string_t what;
7448 	cmdline_fixed_string_t all;
7449 };
7450 
7451 static void cmd_showportall_parsed(void *parsed_result,
7452 				__rte_unused struct cmdline *cl,
7453 				__rte_unused void *data)
7454 {
7455 	portid_t i;
7456 
7457 	struct cmd_showportall_result *res = parsed_result;
7458 	if (!strcmp(res->show, "clear")) {
7459 		if (!strcmp(res->what, "stats"))
7460 			RTE_ETH_FOREACH_DEV(i)
7461 				nic_stats_clear(i);
7462 		else if (!strcmp(res->what, "xstats"))
7463 			RTE_ETH_FOREACH_DEV(i)
7464 				nic_xstats_clear(i);
7465 	} else if (!strcmp(res->what, "info"))
7466 		RTE_ETH_FOREACH_DEV(i)
7467 			port_infos_display(i);
7468 	else if (!strcmp(res->what, "summary")) {
7469 		port_summary_header_display();
7470 		RTE_ETH_FOREACH_DEV(i)
7471 			port_summary_display(i);
7472 	}
7473 	else if (!strcmp(res->what, "stats"))
7474 		RTE_ETH_FOREACH_DEV(i)
7475 			nic_stats_display(i);
7476 	else if (!strcmp(res->what, "xstats"))
7477 		RTE_ETH_FOREACH_DEV(i)
7478 			nic_xstats_display(i);
7479 	else if (!strcmp(res->what, "fdir"))
7480 		RTE_ETH_FOREACH_DEV(i)
7481 			fdir_get_infos(i);
7482 	else if (!strcmp(res->what, "stat_qmap"))
7483 		RTE_ETH_FOREACH_DEV(i)
7484 			nic_stats_mapping_display(i);
7485 	else if (!strcmp(res->what, "dcb_tc"))
7486 		RTE_ETH_FOREACH_DEV(i)
7487 			port_dcb_info_display(i);
7488 	else if (!strcmp(res->what, "cap"))
7489 		RTE_ETH_FOREACH_DEV(i)
7490 			port_offload_cap_display(i);
7491 }
7492 
7493 cmdline_parse_token_string_t cmd_showportall_show =
7494 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7495 				 "show#clear");
7496 cmdline_parse_token_string_t cmd_showportall_port =
7497 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7498 cmdline_parse_token_string_t cmd_showportall_what =
7499 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7500 				 "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7501 cmdline_parse_token_string_t cmd_showportall_all =
7502 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7503 cmdline_parse_inst_t cmd_showportall = {
7504 	.f = cmd_showportall_parsed,
7505 	.data = NULL,
7506 	.help_str = "show|clear port "
7507 		"info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7508 	.tokens = {
7509 		(void *)&cmd_showportall_show,
7510 		(void *)&cmd_showportall_port,
7511 		(void *)&cmd_showportall_what,
7512 		(void *)&cmd_showportall_all,
7513 		NULL,
7514 	},
7515 };
7516 
7517 /* *** SHOW PORT INFO *** */
7518 struct cmd_showport_result {
7519 	cmdline_fixed_string_t show;
7520 	cmdline_fixed_string_t port;
7521 	cmdline_fixed_string_t what;
7522 	uint16_t portnum;
7523 };
7524 
7525 static void cmd_showport_parsed(void *parsed_result,
7526 				__rte_unused struct cmdline *cl,
7527 				__rte_unused void *data)
7528 {
7529 	struct cmd_showport_result *res = parsed_result;
7530 	if (!strcmp(res->show, "clear")) {
7531 		if (!strcmp(res->what, "stats"))
7532 			nic_stats_clear(res->portnum);
7533 		else if (!strcmp(res->what, "xstats"))
7534 			nic_xstats_clear(res->portnum);
7535 	} else if (!strcmp(res->what, "info"))
7536 		port_infos_display(res->portnum);
7537 	else if (!strcmp(res->what, "summary")) {
7538 		port_summary_header_display();
7539 		port_summary_display(res->portnum);
7540 	}
7541 	else if (!strcmp(res->what, "stats"))
7542 		nic_stats_display(res->portnum);
7543 	else if (!strcmp(res->what, "xstats"))
7544 		nic_xstats_display(res->portnum);
7545 	else if (!strcmp(res->what, "fdir"))
7546 		 fdir_get_infos(res->portnum);
7547 	else if (!strcmp(res->what, "stat_qmap"))
7548 		nic_stats_mapping_display(res->portnum);
7549 	else if (!strcmp(res->what, "dcb_tc"))
7550 		port_dcb_info_display(res->portnum);
7551 	else if (!strcmp(res->what, "cap"))
7552 		port_offload_cap_display(res->portnum);
7553 }
7554 
7555 cmdline_parse_token_string_t cmd_showport_show =
7556 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7557 				 "show#clear");
7558 cmdline_parse_token_string_t cmd_showport_port =
7559 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7560 cmdline_parse_token_string_t cmd_showport_what =
7561 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7562 				 "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7563 cmdline_parse_token_num_t cmd_showport_portnum =
7564 	TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7565 
7566 cmdline_parse_inst_t cmd_showport = {
7567 	.f = cmd_showport_parsed,
7568 	.data = NULL,
7569 	.help_str = "show|clear port "
7570 		"info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7571 		"<port_id>",
7572 	.tokens = {
7573 		(void *)&cmd_showport_show,
7574 		(void *)&cmd_showport_port,
7575 		(void *)&cmd_showport_what,
7576 		(void *)&cmd_showport_portnum,
7577 		NULL,
7578 	},
7579 };
7580 
7581 /* *** SHOW DEVICE INFO *** */
7582 struct cmd_showdevice_result {
7583 	cmdline_fixed_string_t show;
7584 	cmdline_fixed_string_t device;
7585 	cmdline_fixed_string_t what;
7586 	cmdline_fixed_string_t identifier;
7587 };
7588 
7589 static void cmd_showdevice_parsed(void *parsed_result,
7590 				__rte_unused struct cmdline *cl,
7591 				__rte_unused void *data)
7592 {
7593 	struct cmd_showdevice_result *res = parsed_result;
7594 	if (!strcmp(res->what, "info")) {
7595 		if (!strcmp(res->identifier, "all"))
7596 			device_infos_display(NULL);
7597 		else
7598 			device_infos_display(res->identifier);
7599 	}
7600 }
7601 
7602 cmdline_parse_token_string_t cmd_showdevice_show =
7603 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7604 				 "show");
7605 cmdline_parse_token_string_t cmd_showdevice_device =
7606 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7607 cmdline_parse_token_string_t cmd_showdevice_what =
7608 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7609 				 "info");
7610 cmdline_parse_token_string_t cmd_showdevice_identifier =
7611 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7612 			identifier, NULL);
7613 
7614 cmdline_parse_inst_t cmd_showdevice = {
7615 	.f = cmd_showdevice_parsed,
7616 	.data = NULL,
7617 	.help_str = "show device info <identifier>|all",
7618 	.tokens = {
7619 		(void *)&cmd_showdevice_show,
7620 		(void *)&cmd_showdevice_device,
7621 		(void *)&cmd_showdevice_what,
7622 		(void *)&cmd_showdevice_identifier,
7623 		NULL,
7624 	},
7625 };
7626 /* *** SHOW QUEUE INFO *** */
7627 struct cmd_showqueue_result {
7628 	cmdline_fixed_string_t show;
7629 	cmdline_fixed_string_t type;
7630 	cmdline_fixed_string_t what;
7631 	uint16_t portnum;
7632 	uint16_t queuenum;
7633 };
7634 
7635 static void
7636 cmd_showqueue_parsed(void *parsed_result,
7637 	__rte_unused struct cmdline *cl,
7638 	__rte_unused void *data)
7639 {
7640 	struct cmd_showqueue_result *res = parsed_result;
7641 
7642 	if (!strcmp(res->type, "rxq"))
7643 		rx_queue_infos_display(res->portnum, res->queuenum);
7644 	else if (!strcmp(res->type, "txq"))
7645 		tx_queue_infos_display(res->portnum, res->queuenum);
7646 }
7647 
7648 cmdline_parse_token_string_t cmd_showqueue_show =
7649 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7650 cmdline_parse_token_string_t cmd_showqueue_type =
7651 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7652 cmdline_parse_token_string_t cmd_showqueue_what =
7653 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7654 cmdline_parse_token_num_t cmd_showqueue_portnum =
7655 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7656 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7657 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7658 
7659 cmdline_parse_inst_t cmd_showqueue = {
7660 	.f = cmd_showqueue_parsed,
7661 	.data = NULL,
7662 	.help_str = "show rxq|txq info <port_id> <queue_id>",
7663 	.tokens = {
7664 		(void *)&cmd_showqueue_show,
7665 		(void *)&cmd_showqueue_type,
7666 		(void *)&cmd_showqueue_what,
7667 		(void *)&cmd_showqueue_portnum,
7668 		(void *)&cmd_showqueue_queuenum,
7669 		NULL,
7670 	},
7671 };
7672 
7673 /* show/clear fwd engine statistics */
7674 struct fwd_result {
7675 	cmdline_fixed_string_t action;
7676 	cmdline_fixed_string_t fwd;
7677 	cmdline_fixed_string_t stats;
7678 	cmdline_fixed_string_t all;
7679 };
7680 
7681 cmdline_parse_token_string_t cmd_fwd_action =
7682 	TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7683 cmdline_parse_token_string_t cmd_fwd_fwd =
7684 	TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7685 cmdline_parse_token_string_t cmd_fwd_stats =
7686 	TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7687 cmdline_parse_token_string_t cmd_fwd_all =
7688 	TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7689 
7690 static void
7691 cmd_showfwdall_parsed(void *parsed_result,
7692 		      __rte_unused struct cmdline *cl,
7693 		      __rte_unused void *data)
7694 {
7695 	struct fwd_result *res = parsed_result;
7696 
7697 	if (!strcmp(res->action, "show"))
7698 		fwd_stats_display();
7699 	else
7700 		fwd_stats_reset();
7701 }
7702 
7703 static cmdline_parse_inst_t cmd_showfwdall = {
7704 	.f = cmd_showfwdall_parsed,
7705 	.data = NULL,
7706 	.help_str = "show|clear fwd stats all",
7707 	.tokens = {
7708 		(void *)&cmd_fwd_action,
7709 		(void *)&cmd_fwd_fwd,
7710 		(void *)&cmd_fwd_stats,
7711 		(void *)&cmd_fwd_all,
7712 		NULL,
7713 	},
7714 };
7715 
7716 /* *** READ PORT REGISTER *** */
7717 struct cmd_read_reg_result {
7718 	cmdline_fixed_string_t read;
7719 	cmdline_fixed_string_t reg;
7720 	portid_t port_id;
7721 	uint32_t reg_off;
7722 };
7723 
7724 static void
7725 cmd_read_reg_parsed(void *parsed_result,
7726 		    __rte_unused struct cmdline *cl,
7727 		    __rte_unused void *data)
7728 {
7729 	struct cmd_read_reg_result *res = parsed_result;
7730 	port_reg_display(res->port_id, res->reg_off);
7731 }
7732 
7733 cmdline_parse_token_string_t cmd_read_reg_read =
7734 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7735 cmdline_parse_token_string_t cmd_read_reg_reg =
7736 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7737 cmdline_parse_token_num_t cmd_read_reg_port_id =
7738 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7739 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7740 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7741 
7742 cmdline_parse_inst_t cmd_read_reg = {
7743 	.f = cmd_read_reg_parsed,
7744 	.data = NULL,
7745 	.help_str = "read reg <port_id> <reg_off>",
7746 	.tokens = {
7747 		(void *)&cmd_read_reg_read,
7748 		(void *)&cmd_read_reg_reg,
7749 		(void *)&cmd_read_reg_port_id,
7750 		(void *)&cmd_read_reg_reg_off,
7751 		NULL,
7752 	},
7753 };
7754 
7755 /* *** READ PORT REGISTER BIT FIELD *** */
7756 struct cmd_read_reg_bit_field_result {
7757 	cmdline_fixed_string_t read;
7758 	cmdline_fixed_string_t regfield;
7759 	portid_t port_id;
7760 	uint32_t reg_off;
7761 	uint8_t bit1_pos;
7762 	uint8_t bit2_pos;
7763 };
7764 
7765 static void
7766 cmd_read_reg_bit_field_parsed(void *parsed_result,
7767 			      __rte_unused struct cmdline *cl,
7768 			      __rte_unused void *data)
7769 {
7770 	struct cmd_read_reg_bit_field_result *res = parsed_result;
7771 	port_reg_bit_field_display(res->port_id, res->reg_off,
7772 				   res->bit1_pos, res->bit2_pos);
7773 }
7774 
7775 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7776 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7777 				 "read");
7778 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7779 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7780 				 regfield, "regfield");
7781 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7782 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7783 			      UINT16);
7784 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7785 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7786 			      UINT32);
7787 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7788 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7789 			      UINT8);
7790 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7791 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7792 			      UINT8);
7793 
7794 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7795 	.f = cmd_read_reg_bit_field_parsed,
7796 	.data = NULL,
7797 	.help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7798 	"Read register bit field between bit_x and bit_y included",
7799 	.tokens = {
7800 		(void *)&cmd_read_reg_bit_field_read,
7801 		(void *)&cmd_read_reg_bit_field_regfield,
7802 		(void *)&cmd_read_reg_bit_field_port_id,
7803 		(void *)&cmd_read_reg_bit_field_reg_off,
7804 		(void *)&cmd_read_reg_bit_field_bit1_pos,
7805 		(void *)&cmd_read_reg_bit_field_bit2_pos,
7806 		NULL,
7807 	},
7808 };
7809 
7810 /* *** READ PORT REGISTER BIT *** */
7811 struct cmd_read_reg_bit_result {
7812 	cmdline_fixed_string_t read;
7813 	cmdline_fixed_string_t regbit;
7814 	portid_t port_id;
7815 	uint32_t reg_off;
7816 	uint8_t bit_pos;
7817 };
7818 
7819 static void
7820 cmd_read_reg_bit_parsed(void *parsed_result,
7821 			__rte_unused struct cmdline *cl,
7822 			__rte_unused void *data)
7823 {
7824 	struct cmd_read_reg_bit_result *res = parsed_result;
7825 	port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7826 }
7827 
7828 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7829 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7830 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7831 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7832 				 regbit, "regbit");
7833 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7834 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7835 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7836 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7837 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7838 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7839 
7840 cmdline_parse_inst_t cmd_read_reg_bit = {
7841 	.f = cmd_read_reg_bit_parsed,
7842 	.data = NULL,
7843 	.help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7844 	.tokens = {
7845 		(void *)&cmd_read_reg_bit_read,
7846 		(void *)&cmd_read_reg_bit_regbit,
7847 		(void *)&cmd_read_reg_bit_port_id,
7848 		(void *)&cmd_read_reg_bit_reg_off,
7849 		(void *)&cmd_read_reg_bit_bit_pos,
7850 		NULL,
7851 	},
7852 };
7853 
7854 /* *** WRITE PORT REGISTER *** */
7855 struct cmd_write_reg_result {
7856 	cmdline_fixed_string_t write;
7857 	cmdline_fixed_string_t reg;
7858 	portid_t port_id;
7859 	uint32_t reg_off;
7860 	uint32_t value;
7861 };
7862 
7863 static void
7864 cmd_write_reg_parsed(void *parsed_result,
7865 		     __rte_unused struct cmdline *cl,
7866 		     __rte_unused void *data)
7867 {
7868 	struct cmd_write_reg_result *res = parsed_result;
7869 	port_reg_set(res->port_id, res->reg_off, res->value);
7870 }
7871 
7872 cmdline_parse_token_string_t cmd_write_reg_write =
7873 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7874 cmdline_parse_token_string_t cmd_write_reg_reg =
7875 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7876 cmdline_parse_token_num_t cmd_write_reg_port_id =
7877 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7878 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7879 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7880 cmdline_parse_token_num_t cmd_write_reg_value =
7881 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7882 
7883 cmdline_parse_inst_t cmd_write_reg = {
7884 	.f = cmd_write_reg_parsed,
7885 	.data = NULL,
7886 	.help_str = "write reg <port_id> <reg_off> <reg_value>",
7887 	.tokens = {
7888 		(void *)&cmd_write_reg_write,
7889 		(void *)&cmd_write_reg_reg,
7890 		(void *)&cmd_write_reg_port_id,
7891 		(void *)&cmd_write_reg_reg_off,
7892 		(void *)&cmd_write_reg_value,
7893 		NULL,
7894 	},
7895 };
7896 
7897 /* *** WRITE PORT REGISTER BIT FIELD *** */
7898 struct cmd_write_reg_bit_field_result {
7899 	cmdline_fixed_string_t write;
7900 	cmdline_fixed_string_t regfield;
7901 	portid_t port_id;
7902 	uint32_t reg_off;
7903 	uint8_t bit1_pos;
7904 	uint8_t bit2_pos;
7905 	uint32_t value;
7906 };
7907 
7908 static void
7909 cmd_write_reg_bit_field_parsed(void *parsed_result,
7910 			       __rte_unused struct cmdline *cl,
7911 			       __rte_unused void *data)
7912 {
7913 	struct cmd_write_reg_bit_field_result *res = parsed_result;
7914 	port_reg_bit_field_set(res->port_id, res->reg_off,
7915 			  res->bit1_pos, res->bit2_pos, res->value);
7916 }
7917 
7918 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7919 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7920 				 "write");
7921 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7922 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7923 				 regfield, "regfield");
7924 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7925 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7926 			      UINT16);
7927 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7928 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7929 			      UINT32);
7930 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7931 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7932 			      UINT8);
7933 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7934 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7935 			      UINT8);
7936 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7937 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7938 			      UINT32);
7939 
7940 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7941 	.f = cmd_write_reg_bit_field_parsed,
7942 	.data = NULL,
7943 	.help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7944 		"<reg_value>: "
7945 		"Set register bit field between bit_x and bit_y included",
7946 	.tokens = {
7947 		(void *)&cmd_write_reg_bit_field_write,
7948 		(void *)&cmd_write_reg_bit_field_regfield,
7949 		(void *)&cmd_write_reg_bit_field_port_id,
7950 		(void *)&cmd_write_reg_bit_field_reg_off,
7951 		(void *)&cmd_write_reg_bit_field_bit1_pos,
7952 		(void *)&cmd_write_reg_bit_field_bit2_pos,
7953 		(void *)&cmd_write_reg_bit_field_value,
7954 		NULL,
7955 	},
7956 };
7957 
7958 /* *** WRITE PORT REGISTER BIT *** */
7959 struct cmd_write_reg_bit_result {
7960 	cmdline_fixed_string_t write;
7961 	cmdline_fixed_string_t regbit;
7962 	portid_t port_id;
7963 	uint32_t reg_off;
7964 	uint8_t bit_pos;
7965 	uint8_t value;
7966 };
7967 
7968 static void
7969 cmd_write_reg_bit_parsed(void *parsed_result,
7970 			 __rte_unused struct cmdline *cl,
7971 			 __rte_unused void *data)
7972 {
7973 	struct cmd_write_reg_bit_result *res = parsed_result;
7974 	port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7975 }
7976 
7977 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7978 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7979 				 "write");
7980 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7981 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7982 				 regbit, "regbit");
7983 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7984 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7985 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7986 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7987 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7988 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7989 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7990 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7991 
7992 cmdline_parse_inst_t cmd_write_reg_bit = {
7993 	.f = cmd_write_reg_bit_parsed,
7994 	.data = NULL,
7995 	.help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7996 		"0 <= bit_x <= 31",
7997 	.tokens = {
7998 		(void *)&cmd_write_reg_bit_write,
7999 		(void *)&cmd_write_reg_bit_regbit,
8000 		(void *)&cmd_write_reg_bit_port_id,
8001 		(void *)&cmd_write_reg_bit_reg_off,
8002 		(void *)&cmd_write_reg_bit_bit_pos,
8003 		(void *)&cmd_write_reg_bit_value,
8004 		NULL,
8005 	},
8006 };
8007 
8008 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8009 struct cmd_read_rxd_txd_result {
8010 	cmdline_fixed_string_t read;
8011 	cmdline_fixed_string_t rxd_txd;
8012 	portid_t port_id;
8013 	uint16_t queue_id;
8014 	uint16_t desc_id;
8015 };
8016 
8017 static void
8018 cmd_read_rxd_txd_parsed(void *parsed_result,
8019 			__rte_unused struct cmdline *cl,
8020 			__rte_unused void *data)
8021 {
8022 	struct cmd_read_rxd_txd_result *res = parsed_result;
8023 
8024 	if (!strcmp(res->rxd_txd, "rxd"))
8025 		rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8026 	else if (!strcmp(res->rxd_txd, "txd"))
8027 		tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8028 }
8029 
8030 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8031 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8032 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8033 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8034 				 "rxd#txd");
8035 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8036 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8037 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8038 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8039 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8040 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8041 
8042 cmdline_parse_inst_t cmd_read_rxd_txd = {
8043 	.f = cmd_read_rxd_txd_parsed,
8044 	.data = NULL,
8045 	.help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8046 	.tokens = {
8047 		(void *)&cmd_read_rxd_txd_read,
8048 		(void *)&cmd_read_rxd_txd_rxd_txd,
8049 		(void *)&cmd_read_rxd_txd_port_id,
8050 		(void *)&cmd_read_rxd_txd_queue_id,
8051 		(void *)&cmd_read_rxd_txd_desc_id,
8052 		NULL,
8053 	},
8054 };
8055 
8056 /* *** QUIT *** */
8057 struct cmd_quit_result {
8058 	cmdline_fixed_string_t quit;
8059 };
8060 
8061 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8062 			    struct cmdline *cl,
8063 			    __rte_unused void *data)
8064 {
8065 	cmdline_quit(cl);
8066 }
8067 
8068 cmdline_parse_token_string_t cmd_quit_quit =
8069 	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8070 
8071 cmdline_parse_inst_t cmd_quit = {
8072 	.f = cmd_quit_parsed,
8073 	.data = NULL,
8074 	.help_str = "quit: Exit application",
8075 	.tokens = {
8076 		(void *)&cmd_quit_quit,
8077 		NULL,
8078 	},
8079 };
8080 
8081 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8082 struct cmd_mac_addr_result {
8083 	cmdline_fixed_string_t mac_addr_cmd;
8084 	cmdline_fixed_string_t what;
8085 	uint16_t port_num;
8086 	struct rte_ether_addr address;
8087 };
8088 
8089 static void cmd_mac_addr_parsed(void *parsed_result,
8090 		__rte_unused struct cmdline *cl,
8091 		__rte_unused void *data)
8092 {
8093 	struct cmd_mac_addr_result *res = parsed_result;
8094 	int ret;
8095 
8096 	if (strcmp(res->what, "add") == 0)
8097 		ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8098 	else if (strcmp(res->what, "set") == 0)
8099 		ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8100 						       &res->address);
8101 	else
8102 		ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8103 
8104 	/* check the return value and print it if is < 0 */
8105 	if(ret < 0)
8106 		printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8107 
8108 }
8109 
8110 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8111 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8112 				"mac_addr");
8113 cmdline_parse_token_string_t cmd_mac_addr_what =
8114 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8115 				"add#remove#set");
8116 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8117 		TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8118 					UINT16);
8119 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8120 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8121 
8122 cmdline_parse_inst_t cmd_mac_addr = {
8123 	.f = cmd_mac_addr_parsed,
8124 	.data = (void *)0,
8125 	.help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8126 			"Add/Remove/Set MAC address on port_id",
8127 	.tokens = {
8128 		(void *)&cmd_mac_addr_cmd,
8129 		(void *)&cmd_mac_addr_what,
8130 		(void *)&cmd_mac_addr_portnum,
8131 		(void *)&cmd_mac_addr_addr,
8132 		NULL,
8133 	},
8134 };
8135 
8136 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8137 struct cmd_eth_peer_result {
8138 	cmdline_fixed_string_t set;
8139 	cmdline_fixed_string_t eth_peer;
8140 	portid_t port_id;
8141 	cmdline_fixed_string_t peer_addr;
8142 };
8143 
8144 static void cmd_set_eth_peer_parsed(void *parsed_result,
8145 			__rte_unused struct cmdline *cl,
8146 			__rte_unused void *data)
8147 {
8148 		struct cmd_eth_peer_result *res = parsed_result;
8149 
8150 		if (test_done == 0) {
8151 			printf("Please stop forwarding first\n");
8152 			return;
8153 		}
8154 		if (!strcmp(res->eth_peer, "eth-peer")) {
8155 			set_fwd_eth_peer(res->port_id, res->peer_addr);
8156 			fwd_config_setup();
8157 		}
8158 }
8159 cmdline_parse_token_string_t cmd_eth_peer_set =
8160 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8161 cmdline_parse_token_string_t cmd_eth_peer =
8162 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8163 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8164 	TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8165 cmdline_parse_token_string_t cmd_eth_peer_addr =
8166 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8167 
8168 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8169 	.f = cmd_set_eth_peer_parsed,
8170 	.data = NULL,
8171 	.help_str = "set eth-peer <port_id> <peer_mac>",
8172 	.tokens = {
8173 		(void *)&cmd_eth_peer_set,
8174 		(void *)&cmd_eth_peer,
8175 		(void *)&cmd_eth_peer_port_id,
8176 		(void *)&cmd_eth_peer_addr,
8177 		NULL,
8178 	},
8179 };
8180 
8181 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8182 struct cmd_set_qmap_result {
8183 	cmdline_fixed_string_t set;
8184 	cmdline_fixed_string_t qmap;
8185 	cmdline_fixed_string_t what;
8186 	portid_t port_id;
8187 	uint16_t queue_id;
8188 	uint8_t map_value;
8189 };
8190 
8191 static void
8192 cmd_set_qmap_parsed(void *parsed_result,
8193 		       __rte_unused struct cmdline *cl,
8194 		       __rte_unused void *data)
8195 {
8196 	struct cmd_set_qmap_result *res = parsed_result;
8197 	int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8198 
8199 	set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8200 }
8201 
8202 cmdline_parse_token_string_t cmd_setqmap_set =
8203 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8204 				 set, "set");
8205 cmdline_parse_token_string_t cmd_setqmap_qmap =
8206 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8207 				 qmap, "stat_qmap");
8208 cmdline_parse_token_string_t cmd_setqmap_what =
8209 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8210 				 what, "tx#rx");
8211 cmdline_parse_token_num_t cmd_setqmap_portid =
8212 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8213 			      port_id, UINT16);
8214 cmdline_parse_token_num_t cmd_setqmap_queueid =
8215 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8216 			      queue_id, UINT16);
8217 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8218 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8219 			      map_value, UINT8);
8220 
8221 cmdline_parse_inst_t cmd_set_qmap = {
8222 	.f = cmd_set_qmap_parsed,
8223 	.data = NULL,
8224 	.help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8225 		"Set statistics mapping value on tx|rx queue_id of port_id",
8226 	.tokens = {
8227 		(void *)&cmd_setqmap_set,
8228 		(void *)&cmd_setqmap_qmap,
8229 		(void *)&cmd_setqmap_what,
8230 		(void *)&cmd_setqmap_portid,
8231 		(void *)&cmd_setqmap_queueid,
8232 		(void *)&cmd_setqmap_mapvalue,
8233 		NULL,
8234 	},
8235 };
8236 
8237 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8238 struct cmd_set_xstats_hide_zero_result {
8239 	cmdline_fixed_string_t keyword;
8240 	cmdline_fixed_string_t name;
8241 	cmdline_fixed_string_t on_off;
8242 };
8243 
8244 static void
8245 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8246 			__rte_unused struct cmdline *cl,
8247 			__rte_unused void *data)
8248 {
8249 	struct cmd_set_xstats_hide_zero_result *res;
8250 	uint16_t on_off = 0;
8251 
8252 	res = parsed_result;
8253 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8254 	set_xstats_hide_zero(on_off);
8255 }
8256 
8257 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8258 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8259 				 keyword, "set");
8260 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8261 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8262 				 name, "xstats-hide-zero");
8263 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8264 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8265 				 on_off, "on#off");
8266 
8267 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8268 	.f = cmd_set_xstats_hide_zero_parsed,
8269 	.data = NULL,
8270 	.help_str = "set xstats-hide-zero on|off",
8271 	.tokens = {
8272 		(void *)&cmd_set_xstats_hide_zero_keyword,
8273 		(void *)&cmd_set_xstats_hide_zero_name,
8274 		(void *)&cmd_set_xstats_hide_zero_on_off,
8275 		NULL,
8276 	},
8277 };
8278 
8279 /* *** CONFIGURE UNICAST HASH TABLE *** */
8280 struct cmd_set_uc_hash_table {
8281 	cmdline_fixed_string_t set;
8282 	cmdline_fixed_string_t port;
8283 	portid_t port_id;
8284 	cmdline_fixed_string_t what;
8285 	struct rte_ether_addr address;
8286 	cmdline_fixed_string_t mode;
8287 };
8288 
8289 static void
8290 cmd_set_uc_hash_parsed(void *parsed_result,
8291 		       __rte_unused struct cmdline *cl,
8292 		       __rte_unused void *data)
8293 {
8294 	int ret=0;
8295 	struct cmd_set_uc_hash_table *res = parsed_result;
8296 
8297 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8298 
8299 	if (strcmp(res->what, "uta") == 0)
8300 		ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8301 						&res->address,(uint8_t)is_on);
8302 	if (ret < 0)
8303 		printf("bad unicast hash table parameter, return code = %d \n", ret);
8304 
8305 }
8306 
8307 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8308 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8309 				 set, "set");
8310 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8311 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8312 				 port, "port");
8313 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8314 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8315 			      port_id, UINT16);
8316 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8317 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8318 				 what, "uta");
8319 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8320 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8321 				address);
8322 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8323 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8324 				 mode, "on#off");
8325 
8326 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8327 	.f = cmd_set_uc_hash_parsed,
8328 	.data = NULL,
8329 	.help_str = "set port <port_id> uta <mac_addr> on|off)",
8330 	.tokens = {
8331 		(void *)&cmd_set_uc_hash_set,
8332 		(void *)&cmd_set_uc_hash_port,
8333 		(void *)&cmd_set_uc_hash_portid,
8334 		(void *)&cmd_set_uc_hash_what,
8335 		(void *)&cmd_set_uc_hash_mac,
8336 		(void *)&cmd_set_uc_hash_mode,
8337 		NULL,
8338 	},
8339 };
8340 
8341 struct cmd_set_uc_all_hash_table {
8342 	cmdline_fixed_string_t set;
8343 	cmdline_fixed_string_t port;
8344 	portid_t port_id;
8345 	cmdline_fixed_string_t what;
8346 	cmdline_fixed_string_t value;
8347 	cmdline_fixed_string_t mode;
8348 };
8349 
8350 static void
8351 cmd_set_uc_all_hash_parsed(void *parsed_result,
8352 		       __rte_unused struct cmdline *cl,
8353 		       __rte_unused void *data)
8354 {
8355 	int ret=0;
8356 	struct cmd_set_uc_all_hash_table *res = parsed_result;
8357 
8358 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8359 
8360 	if ((strcmp(res->what, "uta") == 0) &&
8361 		(strcmp(res->value, "all") == 0))
8362 		ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8363 	if (ret < 0)
8364 		printf("bad unicast hash table parameter,"
8365 			"return code = %d \n", ret);
8366 }
8367 
8368 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8369 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8370 				 set, "set");
8371 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8372 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8373 				 port, "port");
8374 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8375 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8376 			      port_id, UINT16);
8377 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8378 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8379 				 what, "uta");
8380 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8381 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8382 				value,"all");
8383 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8384 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8385 				 mode, "on#off");
8386 
8387 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8388 	.f = cmd_set_uc_all_hash_parsed,
8389 	.data = NULL,
8390 	.help_str = "set port <port_id> uta all on|off",
8391 	.tokens = {
8392 		(void *)&cmd_set_uc_all_hash_set,
8393 		(void *)&cmd_set_uc_all_hash_port,
8394 		(void *)&cmd_set_uc_all_hash_portid,
8395 		(void *)&cmd_set_uc_all_hash_what,
8396 		(void *)&cmd_set_uc_all_hash_value,
8397 		(void *)&cmd_set_uc_all_hash_mode,
8398 		NULL,
8399 	},
8400 };
8401 
8402 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8403 struct cmd_set_vf_macvlan_filter {
8404 	cmdline_fixed_string_t set;
8405 	cmdline_fixed_string_t port;
8406 	portid_t port_id;
8407 	cmdline_fixed_string_t vf;
8408 	uint8_t vf_id;
8409 	struct rte_ether_addr address;
8410 	cmdline_fixed_string_t filter_type;
8411 	cmdline_fixed_string_t mode;
8412 };
8413 
8414 static void
8415 cmd_set_vf_macvlan_parsed(void *parsed_result,
8416 		       __rte_unused struct cmdline *cl,
8417 		       __rte_unused void *data)
8418 {
8419 	int is_on, ret = 0;
8420 	struct cmd_set_vf_macvlan_filter *res = parsed_result;
8421 	struct rte_eth_mac_filter filter;
8422 
8423 	memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8424 
8425 	rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8426 
8427 	/* set VF MAC filter */
8428 	filter.is_vf = 1;
8429 
8430 	/* set VF ID */
8431 	filter.dst_id = res->vf_id;
8432 
8433 	if (!strcmp(res->filter_type, "exact-mac"))
8434 		filter.filter_type = RTE_MAC_PERFECT_MATCH;
8435 	else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8436 		filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8437 	else if (!strcmp(res->filter_type, "hashmac"))
8438 		filter.filter_type = RTE_MAC_HASH_MATCH;
8439 	else if (!strcmp(res->filter_type, "hashmac-vlan"))
8440 		filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8441 
8442 	is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8443 
8444 	if (is_on)
8445 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8446 					RTE_ETH_FILTER_MACVLAN,
8447 					RTE_ETH_FILTER_ADD,
8448 					 &filter);
8449 	else
8450 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8451 					RTE_ETH_FILTER_MACVLAN,
8452 					RTE_ETH_FILTER_DELETE,
8453 					&filter);
8454 
8455 	if (ret < 0)
8456 		printf("bad set MAC hash parameter, return code = %d\n", ret);
8457 
8458 }
8459 
8460 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8461 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8462 				 set, "set");
8463 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8464 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8465 				 port, "port");
8466 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8467 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8468 			      port_id, UINT16);
8469 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8470 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8471 				 vf, "vf");
8472 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8473 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8474 				vf_id, UINT8);
8475 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8476 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8477 				address);
8478 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8479 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8480 				filter_type, "exact-mac#exact-mac-vlan"
8481 				"#hashmac#hashmac-vlan");
8482 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8483 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8484 				 mode, "on#off");
8485 
8486 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8487 	.f = cmd_set_vf_macvlan_parsed,
8488 	.data = NULL,
8489 	.help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8490 		"exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8491 		"Exact match rule: exact match of MAC or MAC and VLAN; "
8492 		"hash match rule: hash match of MAC and exact match of VLAN",
8493 	.tokens = {
8494 		(void *)&cmd_set_vf_macvlan_set,
8495 		(void *)&cmd_set_vf_macvlan_port,
8496 		(void *)&cmd_set_vf_macvlan_portid,
8497 		(void *)&cmd_set_vf_macvlan_vf,
8498 		(void *)&cmd_set_vf_macvlan_vf_id,
8499 		(void *)&cmd_set_vf_macvlan_mac,
8500 		(void *)&cmd_set_vf_macvlan_filter_type,
8501 		(void *)&cmd_set_vf_macvlan_mode,
8502 		NULL,
8503 	},
8504 };
8505 
8506 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8507 struct cmd_set_vf_traffic {
8508 	cmdline_fixed_string_t set;
8509 	cmdline_fixed_string_t port;
8510 	portid_t port_id;
8511 	cmdline_fixed_string_t vf;
8512 	uint8_t vf_id;
8513 	cmdline_fixed_string_t what;
8514 	cmdline_fixed_string_t mode;
8515 };
8516 
8517 static void
8518 cmd_set_vf_traffic_parsed(void *parsed_result,
8519 		       __rte_unused struct cmdline *cl,
8520 		       __rte_unused void *data)
8521 {
8522 	struct cmd_set_vf_traffic *res = parsed_result;
8523 	int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8524 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8525 
8526 	set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8527 }
8528 
8529 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8530 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8531 				 set, "set");
8532 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8533 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8534 				 port, "port");
8535 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8536 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8537 			      port_id, UINT16);
8538 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8539 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8540 				 vf, "vf");
8541 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8542 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8543 			      vf_id, UINT8);
8544 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8545 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8546 				 what, "tx#rx");
8547 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8548 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8549 				 mode, "on#off");
8550 
8551 cmdline_parse_inst_t cmd_set_vf_traffic = {
8552 	.f = cmd_set_vf_traffic_parsed,
8553 	.data = NULL,
8554 	.help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8555 	.tokens = {
8556 		(void *)&cmd_setvf_traffic_set,
8557 		(void *)&cmd_setvf_traffic_port,
8558 		(void *)&cmd_setvf_traffic_portid,
8559 		(void *)&cmd_setvf_traffic_vf,
8560 		(void *)&cmd_setvf_traffic_vfid,
8561 		(void *)&cmd_setvf_traffic_what,
8562 		(void *)&cmd_setvf_traffic_mode,
8563 		NULL,
8564 	},
8565 };
8566 
8567 /* *** CONFIGURE VF RECEIVE MODE *** */
8568 struct cmd_set_vf_rxmode {
8569 	cmdline_fixed_string_t set;
8570 	cmdline_fixed_string_t port;
8571 	portid_t port_id;
8572 	cmdline_fixed_string_t vf;
8573 	uint8_t vf_id;
8574 	cmdline_fixed_string_t what;
8575 	cmdline_fixed_string_t mode;
8576 	cmdline_fixed_string_t on;
8577 };
8578 
8579 static void
8580 cmd_set_vf_rxmode_parsed(void *parsed_result,
8581 		       __rte_unused struct cmdline *cl,
8582 		       __rte_unused void *data)
8583 {
8584 	int ret = -ENOTSUP;
8585 	uint16_t vf_rxmode = 0;
8586 	struct cmd_set_vf_rxmode *res = parsed_result;
8587 
8588 	int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8589 	if (!strcmp(res->what,"rxmode")) {
8590 		if (!strcmp(res->mode, "AUPE"))
8591 			vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8592 		else if (!strcmp(res->mode, "ROPE"))
8593 			vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8594 		else if (!strcmp(res->mode, "BAM"))
8595 			vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8596 		else if (!strncmp(res->mode, "MPE",3))
8597 			vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8598 	}
8599 
8600 	RTE_SET_USED(is_on);
8601 
8602 #ifdef RTE_LIBRTE_IXGBE_PMD
8603 	if (ret == -ENOTSUP)
8604 		ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8605 						  vf_rxmode, (uint8_t)is_on);
8606 #endif
8607 #ifdef RTE_LIBRTE_BNXT_PMD
8608 	if (ret == -ENOTSUP)
8609 		ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8610 						 vf_rxmode, (uint8_t)is_on);
8611 #endif
8612 	if (ret < 0)
8613 		printf("bad VF receive mode parameter, return code = %d \n",
8614 		ret);
8615 }
8616 
8617 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8618 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8619 				 set, "set");
8620 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8621 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8622 				 port, "port");
8623 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8624 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8625 			      port_id, UINT16);
8626 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8627 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8628 				 vf, "vf");
8629 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8630 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8631 			      vf_id, UINT8);
8632 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8633 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8634 				 what, "rxmode");
8635 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8636 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8637 				 mode, "AUPE#ROPE#BAM#MPE");
8638 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8639 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8640 				 on, "on#off");
8641 
8642 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8643 	.f = cmd_set_vf_rxmode_parsed,
8644 	.data = NULL,
8645 	.help_str = "set port <port_id> vf <vf_id> rxmode "
8646 		"AUPE|ROPE|BAM|MPE on|off",
8647 	.tokens = {
8648 		(void *)&cmd_set_vf_rxmode_set,
8649 		(void *)&cmd_set_vf_rxmode_port,
8650 		(void *)&cmd_set_vf_rxmode_portid,
8651 		(void *)&cmd_set_vf_rxmode_vf,
8652 		(void *)&cmd_set_vf_rxmode_vfid,
8653 		(void *)&cmd_set_vf_rxmode_what,
8654 		(void *)&cmd_set_vf_rxmode_mode,
8655 		(void *)&cmd_set_vf_rxmode_on,
8656 		NULL,
8657 	},
8658 };
8659 
8660 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8661 struct cmd_vf_mac_addr_result {
8662 	cmdline_fixed_string_t mac_addr_cmd;
8663 	cmdline_fixed_string_t what;
8664 	cmdline_fixed_string_t port;
8665 	uint16_t port_num;
8666 	cmdline_fixed_string_t vf;
8667 	uint8_t vf_num;
8668 	struct rte_ether_addr address;
8669 };
8670 
8671 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8672 		__rte_unused struct cmdline *cl,
8673 		__rte_unused void *data)
8674 {
8675 	struct cmd_vf_mac_addr_result *res = parsed_result;
8676 	int ret = -ENOTSUP;
8677 
8678 	if (strcmp(res->what, "add") != 0)
8679 		return;
8680 
8681 #ifdef RTE_LIBRTE_I40E_PMD
8682 	if (ret == -ENOTSUP)
8683 		ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8684 						   &res->address);
8685 #endif
8686 #ifdef RTE_LIBRTE_BNXT_PMD
8687 	if (ret == -ENOTSUP)
8688 		ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8689 						res->vf_num);
8690 #endif
8691 
8692 	if(ret < 0)
8693 		printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8694 
8695 }
8696 
8697 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8698 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8699 				mac_addr_cmd,"mac_addr");
8700 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8701 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8702 				what,"add");
8703 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8704 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8705 				port,"port");
8706 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8707 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8708 				port_num, UINT16);
8709 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8710 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8711 				vf,"vf");
8712 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8713 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8714 				vf_num, UINT8);
8715 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8716 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8717 				address);
8718 
8719 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8720 	.f = cmd_vf_mac_addr_parsed,
8721 	.data = (void *)0,
8722 	.help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8723 		"Add MAC address filtering for a VF on port_id",
8724 	.tokens = {
8725 		(void *)&cmd_vf_mac_addr_cmd,
8726 		(void *)&cmd_vf_mac_addr_what,
8727 		(void *)&cmd_vf_mac_addr_port,
8728 		(void *)&cmd_vf_mac_addr_portnum,
8729 		(void *)&cmd_vf_mac_addr_vf,
8730 		(void *)&cmd_vf_mac_addr_vfnum,
8731 		(void *)&cmd_vf_mac_addr_addr,
8732 		NULL,
8733 	},
8734 };
8735 
8736 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8737 struct cmd_vf_rx_vlan_filter {
8738 	cmdline_fixed_string_t rx_vlan;
8739 	cmdline_fixed_string_t what;
8740 	uint16_t vlan_id;
8741 	cmdline_fixed_string_t port;
8742 	portid_t port_id;
8743 	cmdline_fixed_string_t vf;
8744 	uint64_t vf_mask;
8745 };
8746 
8747 static void
8748 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8749 			  __rte_unused struct cmdline *cl,
8750 			  __rte_unused void *data)
8751 {
8752 	struct cmd_vf_rx_vlan_filter *res = parsed_result;
8753 	int ret = -ENOTSUP;
8754 
8755 	__rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8756 
8757 #ifdef RTE_LIBRTE_IXGBE_PMD
8758 	if (ret == -ENOTSUP)
8759 		ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8760 				res->vlan_id, res->vf_mask, is_add);
8761 #endif
8762 #ifdef RTE_LIBRTE_I40E_PMD
8763 	if (ret == -ENOTSUP)
8764 		ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8765 				res->vlan_id, res->vf_mask, is_add);
8766 #endif
8767 #ifdef RTE_LIBRTE_BNXT_PMD
8768 	if (ret == -ENOTSUP)
8769 		ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8770 				res->vlan_id, res->vf_mask, is_add);
8771 #endif
8772 
8773 	switch (ret) {
8774 	case 0:
8775 		break;
8776 	case -EINVAL:
8777 		printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8778 				res->vlan_id, res->vf_mask);
8779 		break;
8780 	case -ENODEV:
8781 		printf("invalid port_id %d\n", res->port_id);
8782 		break;
8783 	case -ENOTSUP:
8784 		printf("function not implemented or supported\n");
8785 		break;
8786 	default:
8787 		printf("programming error: (%s)\n", strerror(-ret));
8788 	}
8789 }
8790 
8791 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8792 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8793 				 rx_vlan, "rx_vlan");
8794 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8795 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8796 				 what, "add#rm");
8797 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8798 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8799 			      vlan_id, UINT16);
8800 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8801 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8802 				 port, "port");
8803 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8804 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8805 			      port_id, UINT16);
8806 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8807 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8808 				 vf, "vf");
8809 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8810 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8811 			      vf_mask, UINT64);
8812 
8813 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8814 	.f = cmd_vf_rx_vlan_filter_parsed,
8815 	.data = NULL,
8816 	.help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8817 		"(vf_mask = hexadecimal VF mask)",
8818 	.tokens = {
8819 		(void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8820 		(void *)&cmd_vf_rx_vlan_filter_what,
8821 		(void *)&cmd_vf_rx_vlan_filter_vlanid,
8822 		(void *)&cmd_vf_rx_vlan_filter_port,
8823 		(void *)&cmd_vf_rx_vlan_filter_portid,
8824 		(void *)&cmd_vf_rx_vlan_filter_vf,
8825 		(void *)&cmd_vf_rx_vlan_filter_vf_mask,
8826 		NULL,
8827 	},
8828 };
8829 
8830 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8831 struct cmd_queue_rate_limit_result {
8832 	cmdline_fixed_string_t set;
8833 	cmdline_fixed_string_t port;
8834 	uint16_t port_num;
8835 	cmdline_fixed_string_t queue;
8836 	uint8_t queue_num;
8837 	cmdline_fixed_string_t rate;
8838 	uint16_t rate_num;
8839 };
8840 
8841 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8842 		__rte_unused struct cmdline *cl,
8843 		__rte_unused void *data)
8844 {
8845 	struct cmd_queue_rate_limit_result *res = parsed_result;
8846 	int ret = 0;
8847 
8848 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8849 		&& (strcmp(res->queue, "queue") == 0)
8850 		&& (strcmp(res->rate, "rate") == 0))
8851 		ret = set_queue_rate_limit(res->port_num, res->queue_num,
8852 					res->rate_num);
8853 	if (ret < 0)
8854 		printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8855 
8856 }
8857 
8858 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8859 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8860 				set, "set");
8861 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8862 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8863 				port, "port");
8864 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8865 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8866 				port_num, UINT16);
8867 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8868 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8869 				queue, "queue");
8870 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8871 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8872 				queue_num, UINT8);
8873 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8874 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8875 				rate, "rate");
8876 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8877 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8878 				rate_num, UINT16);
8879 
8880 cmdline_parse_inst_t cmd_queue_rate_limit = {
8881 	.f = cmd_queue_rate_limit_parsed,
8882 	.data = (void *)0,
8883 	.help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8884 		"Set rate limit for a queue on port_id",
8885 	.tokens = {
8886 		(void *)&cmd_queue_rate_limit_set,
8887 		(void *)&cmd_queue_rate_limit_port,
8888 		(void *)&cmd_queue_rate_limit_portnum,
8889 		(void *)&cmd_queue_rate_limit_queue,
8890 		(void *)&cmd_queue_rate_limit_queuenum,
8891 		(void *)&cmd_queue_rate_limit_rate,
8892 		(void *)&cmd_queue_rate_limit_ratenum,
8893 		NULL,
8894 	},
8895 };
8896 
8897 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8898 struct cmd_vf_rate_limit_result {
8899 	cmdline_fixed_string_t set;
8900 	cmdline_fixed_string_t port;
8901 	uint16_t port_num;
8902 	cmdline_fixed_string_t vf;
8903 	uint8_t vf_num;
8904 	cmdline_fixed_string_t rate;
8905 	uint16_t rate_num;
8906 	cmdline_fixed_string_t q_msk;
8907 	uint64_t q_msk_val;
8908 };
8909 
8910 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8911 		__rte_unused struct cmdline *cl,
8912 		__rte_unused void *data)
8913 {
8914 	struct cmd_vf_rate_limit_result *res = parsed_result;
8915 	int ret = 0;
8916 
8917 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8918 		&& (strcmp(res->vf, "vf") == 0)
8919 		&& (strcmp(res->rate, "rate") == 0)
8920 		&& (strcmp(res->q_msk, "queue_mask") == 0))
8921 		ret = set_vf_rate_limit(res->port_num, res->vf_num,
8922 					res->rate_num, res->q_msk_val);
8923 	if (ret < 0)
8924 		printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8925 
8926 }
8927 
8928 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8929 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8930 				set, "set");
8931 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8932 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8933 				port, "port");
8934 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8935 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8936 				port_num, UINT16);
8937 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8938 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8939 				vf, "vf");
8940 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8941 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8942 				vf_num, UINT8);
8943 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8944 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8945 				rate, "rate");
8946 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8947 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8948 				rate_num, UINT16);
8949 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8950 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8951 				q_msk, "queue_mask");
8952 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8953 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8954 				q_msk_val, UINT64);
8955 
8956 cmdline_parse_inst_t cmd_vf_rate_limit = {
8957 	.f = cmd_vf_rate_limit_parsed,
8958 	.data = (void *)0,
8959 	.help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8960 		"queue_mask <queue_mask_value>: "
8961 		"Set rate limit for queues of VF on port_id",
8962 	.tokens = {
8963 		(void *)&cmd_vf_rate_limit_set,
8964 		(void *)&cmd_vf_rate_limit_port,
8965 		(void *)&cmd_vf_rate_limit_portnum,
8966 		(void *)&cmd_vf_rate_limit_vf,
8967 		(void *)&cmd_vf_rate_limit_vfnum,
8968 		(void *)&cmd_vf_rate_limit_rate,
8969 		(void *)&cmd_vf_rate_limit_ratenum,
8970 		(void *)&cmd_vf_rate_limit_q_msk,
8971 		(void *)&cmd_vf_rate_limit_q_msk_val,
8972 		NULL,
8973 	},
8974 };
8975 
8976 /* *** ADD TUNNEL FILTER OF A PORT *** */
8977 struct cmd_tunnel_filter_result {
8978 	cmdline_fixed_string_t cmd;
8979 	cmdline_fixed_string_t what;
8980 	portid_t port_id;
8981 	struct rte_ether_addr outer_mac;
8982 	struct rte_ether_addr inner_mac;
8983 	cmdline_ipaddr_t ip_value;
8984 	uint16_t inner_vlan;
8985 	cmdline_fixed_string_t tunnel_type;
8986 	cmdline_fixed_string_t filter_type;
8987 	uint32_t tenant_id;
8988 	uint16_t queue_num;
8989 };
8990 
8991 static void
8992 cmd_tunnel_filter_parsed(void *parsed_result,
8993 			  __rte_unused struct cmdline *cl,
8994 			  __rte_unused void *data)
8995 {
8996 	struct cmd_tunnel_filter_result *res = parsed_result;
8997 	struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8998 	int ret = 0;
8999 
9000 	memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9001 
9002 	rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9003 	rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9004 	tunnel_filter_conf.inner_vlan = res->inner_vlan;
9005 
9006 	if (res->ip_value.family == AF_INET) {
9007 		tunnel_filter_conf.ip_addr.ipv4_addr =
9008 			res->ip_value.addr.ipv4.s_addr;
9009 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9010 	} else {
9011 		memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9012 			&(res->ip_value.addr.ipv6),
9013 			sizeof(struct in6_addr));
9014 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9015 	}
9016 
9017 	if (!strcmp(res->filter_type, "imac-ivlan"))
9018 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9019 	else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9020 		tunnel_filter_conf.filter_type =
9021 			RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9022 	else if (!strcmp(res->filter_type, "imac-tenid"))
9023 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9024 	else if (!strcmp(res->filter_type, "imac"))
9025 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9026 	else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9027 		tunnel_filter_conf.filter_type =
9028 			RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9029 	else if (!strcmp(res->filter_type, "oip"))
9030 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9031 	else if (!strcmp(res->filter_type, "iip"))
9032 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9033 	else {
9034 		printf("The filter type is not supported");
9035 		return;
9036 	}
9037 
9038 	if (!strcmp(res->tunnel_type, "vxlan"))
9039 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9040 	else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9041 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9042 	else if (!strcmp(res->tunnel_type, "nvgre"))
9043 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9044 	else if (!strcmp(res->tunnel_type, "ipingre"))
9045 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9046 	else {
9047 		printf("The tunnel type %s not supported.\n", res->tunnel_type);
9048 		return;
9049 	}
9050 
9051 	tunnel_filter_conf.tenant_id = res->tenant_id;
9052 	tunnel_filter_conf.queue_id = res->queue_num;
9053 	if (!strcmp(res->what, "add"))
9054 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9055 					RTE_ETH_FILTER_TUNNEL,
9056 					RTE_ETH_FILTER_ADD,
9057 					&tunnel_filter_conf);
9058 	else
9059 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9060 					RTE_ETH_FILTER_TUNNEL,
9061 					RTE_ETH_FILTER_DELETE,
9062 					&tunnel_filter_conf);
9063 	if (ret < 0)
9064 		printf("cmd_tunnel_filter_parsed error: (%s)\n",
9065 				strerror(-ret));
9066 
9067 }
9068 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9069 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9070 	cmd, "tunnel_filter");
9071 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9072 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9073 	what, "add#rm");
9074 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9075 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9076 	port_id, UINT16);
9077 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9078 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9079 	outer_mac);
9080 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9081 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9082 	inner_mac);
9083 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9084 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9085 	inner_vlan, UINT16);
9086 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9087 	TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9088 	ip_value);
9089 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9090 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9091 	tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9092 
9093 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9094 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9095 	filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9096 		"imac#omac-imac-tenid");
9097 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9098 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9099 	tenant_id, UINT32);
9100 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9101 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9102 	queue_num, UINT16);
9103 
9104 cmdline_parse_inst_t cmd_tunnel_filter = {
9105 	.f = cmd_tunnel_filter_parsed,
9106 	.data = (void *)0,
9107 	.help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9108 		"<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9109 		"imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9110 		"<queue_id>: Add/Rm tunnel filter of a port",
9111 	.tokens = {
9112 		(void *)&cmd_tunnel_filter_cmd,
9113 		(void *)&cmd_tunnel_filter_what,
9114 		(void *)&cmd_tunnel_filter_port_id,
9115 		(void *)&cmd_tunnel_filter_outer_mac,
9116 		(void *)&cmd_tunnel_filter_inner_mac,
9117 		(void *)&cmd_tunnel_filter_ip_value,
9118 		(void *)&cmd_tunnel_filter_innner_vlan,
9119 		(void *)&cmd_tunnel_filter_tunnel_type,
9120 		(void *)&cmd_tunnel_filter_filter_type,
9121 		(void *)&cmd_tunnel_filter_tenant_id,
9122 		(void *)&cmd_tunnel_filter_queue_num,
9123 		NULL,
9124 	},
9125 };
9126 
9127 /* *** CONFIGURE TUNNEL UDP PORT *** */
9128 struct cmd_tunnel_udp_config {
9129 	cmdline_fixed_string_t cmd;
9130 	cmdline_fixed_string_t what;
9131 	uint16_t udp_port;
9132 	portid_t port_id;
9133 };
9134 
9135 static void
9136 cmd_tunnel_udp_config_parsed(void *parsed_result,
9137 			  __rte_unused struct cmdline *cl,
9138 			  __rte_unused void *data)
9139 {
9140 	struct cmd_tunnel_udp_config *res = parsed_result;
9141 	struct rte_eth_udp_tunnel tunnel_udp;
9142 	int ret;
9143 
9144 	tunnel_udp.udp_port = res->udp_port;
9145 
9146 	if (!strcmp(res->cmd, "rx_vxlan_port"))
9147 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9148 
9149 	if (!strcmp(res->what, "add"))
9150 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9151 						      &tunnel_udp);
9152 	else
9153 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9154 							 &tunnel_udp);
9155 
9156 	if (ret < 0)
9157 		printf("udp tunneling add error: (%s)\n", strerror(-ret));
9158 }
9159 
9160 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9161 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9162 				cmd, "rx_vxlan_port");
9163 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9164 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9165 				what, "add#rm");
9166 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9167 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9168 				udp_port, UINT16);
9169 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9170 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9171 				port_id, UINT16);
9172 
9173 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9174 	.f = cmd_tunnel_udp_config_parsed,
9175 	.data = (void *)0,
9176 	.help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9177 		"Add/Remove a tunneling UDP port filter",
9178 	.tokens = {
9179 		(void *)&cmd_tunnel_udp_config_cmd,
9180 		(void *)&cmd_tunnel_udp_config_what,
9181 		(void *)&cmd_tunnel_udp_config_udp_port,
9182 		(void *)&cmd_tunnel_udp_config_port_id,
9183 		NULL,
9184 	},
9185 };
9186 
9187 struct cmd_config_tunnel_udp_port {
9188 	cmdline_fixed_string_t port;
9189 	cmdline_fixed_string_t config;
9190 	portid_t port_id;
9191 	cmdline_fixed_string_t udp_tunnel_port;
9192 	cmdline_fixed_string_t action;
9193 	cmdline_fixed_string_t tunnel_type;
9194 	uint16_t udp_port;
9195 };
9196 
9197 static void
9198 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9199 			       __rte_unused struct cmdline *cl,
9200 			       __rte_unused void *data)
9201 {
9202 	struct cmd_config_tunnel_udp_port *res = parsed_result;
9203 	struct rte_eth_udp_tunnel tunnel_udp;
9204 	int ret = 0;
9205 
9206 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9207 		return;
9208 
9209 	tunnel_udp.udp_port = res->udp_port;
9210 
9211 	if (!strcmp(res->tunnel_type, "vxlan")) {
9212 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9213 	} else if (!strcmp(res->tunnel_type, "geneve")) {
9214 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9215 	} else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9216 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9217 	} else {
9218 		printf("Invalid tunnel type\n");
9219 		return;
9220 	}
9221 
9222 	if (!strcmp(res->action, "add"))
9223 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9224 						      &tunnel_udp);
9225 	else
9226 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9227 							 &tunnel_udp);
9228 
9229 	if (ret < 0)
9230 		printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9231 }
9232 
9233 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9234 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9235 				 "port");
9236 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9237 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9238 				 "config");
9239 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9240 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9241 			      UINT16);
9242 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9243 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9244 				 udp_tunnel_port,
9245 				 "udp_tunnel_port");
9246 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9247 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9248 				 "add#rm");
9249 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9250 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9251 				 "vxlan#geneve#vxlan-gpe");
9252 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9253 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9254 			      UINT16);
9255 
9256 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9257 	.f = cmd_cfg_tunnel_udp_port_parsed,
9258 	.data = NULL,
9259 	.help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9260 	.tokens = {
9261 		(void *)&cmd_config_tunnel_udp_port_port,
9262 		(void *)&cmd_config_tunnel_udp_port_config,
9263 		(void *)&cmd_config_tunnel_udp_port_port_id,
9264 		(void *)&cmd_config_tunnel_udp_port_tunnel_port,
9265 		(void *)&cmd_config_tunnel_udp_port_action,
9266 		(void *)&cmd_config_tunnel_udp_port_tunnel_type,
9267 		(void *)&cmd_config_tunnel_udp_port_value,
9268 		NULL,
9269 	},
9270 };
9271 
9272 /* *** GLOBAL CONFIG *** */
9273 struct cmd_global_config_result {
9274 	cmdline_fixed_string_t cmd;
9275 	portid_t port_id;
9276 	cmdline_fixed_string_t cfg_type;
9277 	uint8_t len;
9278 };
9279 
9280 static void
9281 cmd_global_config_parsed(void *parsed_result,
9282 			 __rte_unused struct cmdline *cl,
9283 			 __rte_unused void *data)
9284 {
9285 	struct cmd_global_config_result *res = parsed_result;
9286 	struct rte_eth_global_cfg conf;
9287 	int ret;
9288 
9289 	memset(&conf, 0, sizeof(conf));
9290 	conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9291 	conf.cfg.gre_key_len = res->len;
9292 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9293 				      RTE_ETH_FILTER_SET, &conf);
9294 	if (ret != 0)
9295 		printf("Global config error\n");
9296 }
9297 
9298 cmdline_parse_token_string_t cmd_global_config_cmd =
9299 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9300 		"global_config");
9301 cmdline_parse_token_num_t cmd_global_config_port_id =
9302 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9303 			       UINT16);
9304 cmdline_parse_token_string_t cmd_global_config_type =
9305 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9306 		cfg_type, "gre-key-len");
9307 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9308 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9309 		len, UINT8);
9310 
9311 cmdline_parse_inst_t cmd_global_config = {
9312 	.f = cmd_global_config_parsed,
9313 	.data = (void *)NULL,
9314 	.help_str = "global_config <port_id> gre-key-len <key_len>",
9315 	.tokens = {
9316 		(void *)&cmd_global_config_cmd,
9317 		(void *)&cmd_global_config_port_id,
9318 		(void *)&cmd_global_config_type,
9319 		(void *)&cmd_global_config_gre_key_len,
9320 		NULL,
9321 	},
9322 };
9323 
9324 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9325 struct cmd_set_mirror_mask_result {
9326 	cmdline_fixed_string_t set;
9327 	cmdline_fixed_string_t port;
9328 	portid_t port_id;
9329 	cmdline_fixed_string_t mirror;
9330 	uint8_t rule_id;
9331 	cmdline_fixed_string_t what;
9332 	cmdline_fixed_string_t value;
9333 	cmdline_fixed_string_t dstpool;
9334 	uint8_t dstpool_id;
9335 	cmdline_fixed_string_t on;
9336 };
9337 
9338 cmdline_parse_token_string_t cmd_mirror_mask_set =
9339 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9340 				set, "set");
9341 cmdline_parse_token_string_t cmd_mirror_mask_port =
9342 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9343 				port, "port");
9344 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9345 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9346 				port_id, UINT16);
9347 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9348 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9349 				mirror, "mirror-rule");
9350 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9351 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9352 				rule_id, UINT8);
9353 cmdline_parse_token_string_t cmd_mirror_mask_what =
9354 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9355 				what, "pool-mirror-up#pool-mirror-down"
9356 				      "#vlan-mirror");
9357 cmdline_parse_token_string_t cmd_mirror_mask_value =
9358 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9359 				value, NULL);
9360 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9361 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9362 				dstpool, "dst-pool");
9363 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9364 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9365 				dstpool_id, UINT8);
9366 cmdline_parse_token_string_t cmd_mirror_mask_on =
9367 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9368 				on, "on#off");
9369 
9370 static void
9371 cmd_set_mirror_mask_parsed(void *parsed_result,
9372 		       __rte_unused struct cmdline *cl,
9373 		       __rte_unused void *data)
9374 {
9375 	int ret,nb_item,i;
9376 	struct cmd_set_mirror_mask_result *res = parsed_result;
9377 	struct rte_eth_mirror_conf mr_conf;
9378 
9379 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9380 
9381 	unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9382 
9383 	mr_conf.dst_pool = res->dstpool_id;
9384 
9385 	if (!strcmp(res->what, "pool-mirror-up")) {
9386 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9387 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9388 	} else if (!strcmp(res->what, "pool-mirror-down")) {
9389 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9390 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9391 	} else if (!strcmp(res->what, "vlan-mirror")) {
9392 		mr_conf.rule_type = ETH_MIRROR_VLAN;
9393 		nb_item = parse_item_list(res->value, "vlan",
9394 				ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9395 		if (nb_item <= 0)
9396 			return;
9397 
9398 		for (i = 0; i < nb_item; i++) {
9399 			if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9400 				printf("Invalid vlan_id: must be < 4096\n");
9401 				return;
9402 			}
9403 
9404 			mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9405 			mr_conf.vlan.vlan_mask |= 1ULL << i;
9406 		}
9407 	}
9408 
9409 	if (!strcmp(res->on, "on"))
9410 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9411 						res->rule_id, 1);
9412 	else
9413 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9414 						res->rule_id, 0);
9415 	if (ret < 0)
9416 		printf("mirror rule add error: (%s)\n", strerror(-ret));
9417 }
9418 
9419 cmdline_parse_inst_t cmd_set_mirror_mask = {
9420 		.f = cmd_set_mirror_mask_parsed,
9421 		.data = NULL,
9422 		.help_str = "set port <port_id> mirror-rule <rule_id> "
9423 			"pool-mirror-up|pool-mirror-down|vlan-mirror "
9424 			"<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9425 		.tokens = {
9426 			(void *)&cmd_mirror_mask_set,
9427 			(void *)&cmd_mirror_mask_port,
9428 			(void *)&cmd_mirror_mask_portid,
9429 			(void *)&cmd_mirror_mask_mirror,
9430 			(void *)&cmd_mirror_mask_ruleid,
9431 			(void *)&cmd_mirror_mask_what,
9432 			(void *)&cmd_mirror_mask_value,
9433 			(void *)&cmd_mirror_mask_dstpool,
9434 			(void *)&cmd_mirror_mask_poolid,
9435 			(void *)&cmd_mirror_mask_on,
9436 			NULL,
9437 		},
9438 };
9439 
9440 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9441 struct cmd_set_mirror_link_result {
9442 	cmdline_fixed_string_t set;
9443 	cmdline_fixed_string_t port;
9444 	portid_t port_id;
9445 	cmdline_fixed_string_t mirror;
9446 	uint8_t rule_id;
9447 	cmdline_fixed_string_t what;
9448 	cmdline_fixed_string_t dstpool;
9449 	uint8_t dstpool_id;
9450 	cmdline_fixed_string_t on;
9451 };
9452 
9453 cmdline_parse_token_string_t cmd_mirror_link_set =
9454 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9455 				 set, "set");
9456 cmdline_parse_token_string_t cmd_mirror_link_port =
9457 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9458 				port, "port");
9459 cmdline_parse_token_num_t cmd_mirror_link_portid =
9460 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9461 				port_id, UINT16);
9462 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9463 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9464 				mirror, "mirror-rule");
9465 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9466 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9467 			    rule_id, UINT8);
9468 cmdline_parse_token_string_t cmd_mirror_link_what =
9469 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9470 				what, "uplink-mirror#downlink-mirror");
9471 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9472 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9473 				dstpool, "dst-pool");
9474 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9475 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9476 				dstpool_id, UINT8);
9477 cmdline_parse_token_string_t cmd_mirror_link_on =
9478 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9479 				on, "on#off");
9480 
9481 static void
9482 cmd_set_mirror_link_parsed(void *parsed_result,
9483 		       __rte_unused struct cmdline *cl,
9484 		       __rte_unused void *data)
9485 {
9486 	int ret;
9487 	struct cmd_set_mirror_link_result *res = parsed_result;
9488 	struct rte_eth_mirror_conf mr_conf;
9489 
9490 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9491 	if (!strcmp(res->what, "uplink-mirror"))
9492 		mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9493 	else
9494 		mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9495 
9496 	mr_conf.dst_pool = res->dstpool_id;
9497 
9498 	if (!strcmp(res->on, "on"))
9499 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9500 						res->rule_id, 1);
9501 	else
9502 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9503 						res->rule_id, 0);
9504 
9505 	/* check the return value and print it if is < 0 */
9506 	if (ret < 0)
9507 		printf("mirror rule add error: (%s)\n", strerror(-ret));
9508 
9509 }
9510 
9511 cmdline_parse_inst_t cmd_set_mirror_link = {
9512 		.f = cmd_set_mirror_link_parsed,
9513 		.data = NULL,
9514 		.help_str = "set port <port_id> mirror-rule <rule_id> "
9515 			"uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9516 		.tokens = {
9517 			(void *)&cmd_mirror_link_set,
9518 			(void *)&cmd_mirror_link_port,
9519 			(void *)&cmd_mirror_link_portid,
9520 			(void *)&cmd_mirror_link_mirror,
9521 			(void *)&cmd_mirror_link_ruleid,
9522 			(void *)&cmd_mirror_link_what,
9523 			(void *)&cmd_mirror_link_dstpool,
9524 			(void *)&cmd_mirror_link_poolid,
9525 			(void *)&cmd_mirror_link_on,
9526 			NULL,
9527 		},
9528 };
9529 
9530 /* *** RESET VM MIRROR RULE *** */
9531 struct cmd_rm_mirror_rule_result {
9532 	cmdline_fixed_string_t reset;
9533 	cmdline_fixed_string_t port;
9534 	portid_t port_id;
9535 	cmdline_fixed_string_t mirror;
9536 	uint8_t rule_id;
9537 };
9538 
9539 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9540 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9541 				 reset, "reset");
9542 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9543 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9544 				port, "port");
9545 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9546 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9547 				port_id, UINT16);
9548 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9549 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9550 				mirror, "mirror-rule");
9551 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9552 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9553 				rule_id, UINT8);
9554 
9555 static void
9556 cmd_reset_mirror_rule_parsed(void *parsed_result,
9557 		       __rte_unused struct cmdline *cl,
9558 		       __rte_unused void *data)
9559 {
9560 	int ret;
9561 	struct cmd_set_mirror_link_result *res = parsed_result;
9562         /* check rule_id */
9563 	ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9564 	if(ret < 0)
9565 		printf("mirror rule remove error: (%s)\n", strerror(-ret));
9566 }
9567 
9568 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9569 		.f = cmd_reset_mirror_rule_parsed,
9570 		.data = NULL,
9571 		.help_str = "reset port <port_id> mirror-rule <rule_id>",
9572 		.tokens = {
9573 			(void *)&cmd_rm_mirror_rule_reset,
9574 			(void *)&cmd_rm_mirror_rule_port,
9575 			(void *)&cmd_rm_mirror_rule_portid,
9576 			(void *)&cmd_rm_mirror_rule_mirror,
9577 			(void *)&cmd_rm_mirror_rule_ruleid,
9578 			NULL,
9579 		},
9580 };
9581 
9582 /* ******************************************************************************** */
9583 
9584 struct cmd_dump_result {
9585 	cmdline_fixed_string_t dump;
9586 };
9587 
9588 static void
9589 dump_struct_sizes(void)
9590 {
9591 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9592 	DUMP_SIZE(struct rte_mbuf);
9593 	DUMP_SIZE(struct rte_mempool);
9594 	DUMP_SIZE(struct rte_ring);
9595 #undef DUMP_SIZE
9596 }
9597 
9598 
9599 /* Dump the socket memory statistics on console */
9600 static void
9601 dump_socket_mem(FILE *f)
9602 {
9603 	struct rte_malloc_socket_stats socket_stats;
9604 	unsigned int i;
9605 	size_t total = 0;
9606 	size_t alloc = 0;
9607 	size_t free = 0;
9608 	unsigned int n_alloc = 0;
9609 	unsigned int n_free = 0;
9610 	static size_t last_allocs;
9611 	static size_t last_total;
9612 
9613 
9614 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9615 		if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9616 		    !socket_stats.heap_totalsz_bytes)
9617 			continue;
9618 		total += socket_stats.heap_totalsz_bytes;
9619 		alloc += socket_stats.heap_allocsz_bytes;
9620 		free += socket_stats.heap_freesz_bytes;
9621 		n_alloc += socket_stats.alloc_count;
9622 		n_free += socket_stats.free_count;
9623 		fprintf(f,
9624 			"Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9625 			i,
9626 			(double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9627 			(double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9628 			(double)socket_stats.heap_allocsz_bytes * 100 /
9629 			(double)socket_stats.heap_totalsz_bytes,
9630 			(double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9631 			socket_stats.alloc_count,
9632 			socket_stats.free_count);
9633 	}
9634 	fprintf(f,
9635 		"Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9636 		(double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9637 		(double)alloc * 100 / (double)total,
9638 		(double)free / (1024 * 1024),
9639 		n_alloc, n_free);
9640 	if (last_allocs)
9641 		fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9642 			((double)total - (double)last_total) / (1024 * 1024),
9643 			(double)(alloc - (double)last_allocs) / 1024 / 1024);
9644 	last_allocs = alloc;
9645 	last_total = total;
9646 }
9647 
9648 static void cmd_dump_parsed(void *parsed_result,
9649 			    __rte_unused struct cmdline *cl,
9650 			    __rte_unused void *data)
9651 {
9652 	struct cmd_dump_result *res = parsed_result;
9653 
9654 	if (!strcmp(res->dump, "dump_physmem"))
9655 		rte_dump_physmem_layout(stdout);
9656 	else if (!strcmp(res->dump, "dump_socket_mem"))
9657 		dump_socket_mem(stdout);
9658 	else if (!strcmp(res->dump, "dump_memzone"))
9659 		rte_memzone_dump(stdout);
9660 	else if (!strcmp(res->dump, "dump_struct_sizes"))
9661 		dump_struct_sizes();
9662 	else if (!strcmp(res->dump, "dump_ring"))
9663 		rte_ring_list_dump(stdout);
9664 	else if (!strcmp(res->dump, "dump_mempool"))
9665 		rte_mempool_list_dump(stdout);
9666 	else if (!strcmp(res->dump, "dump_devargs"))
9667 		rte_devargs_dump(stdout);
9668 	else if (!strcmp(res->dump, "dump_log_types"))
9669 		rte_log_dump(stdout);
9670 }
9671 
9672 cmdline_parse_token_string_t cmd_dump_dump =
9673 	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9674 		"dump_physmem#"
9675 		"dump_memzone#"
9676 		"dump_socket_mem#"
9677 		"dump_struct_sizes#"
9678 		"dump_ring#"
9679 		"dump_mempool#"
9680 		"dump_devargs#"
9681 		"dump_log_types");
9682 
9683 cmdline_parse_inst_t cmd_dump = {
9684 	.f = cmd_dump_parsed,  /* function to call */
9685 	.data = NULL,      /* 2nd arg of func */
9686 	.help_str = "Dump status",
9687 	.tokens = {        /* token list, NULL terminated */
9688 		(void *)&cmd_dump_dump,
9689 		NULL,
9690 	},
9691 };
9692 
9693 /* ******************************************************************************** */
9694 
9695 struct cmd_dump_one_result {
9696 	cmdline_fixed_string_t dump;
9697 	cmdline_fixed_string_t name;
9698 };
9699 
9700 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9701 				__rte_unused void *data)
9702 {
9703 	struct cmd_dump_one_result *res = parsed_result;
9704 
9705 	if (!strcmp(res->dump, "dump_ring")) {
9706 		struct rte_ring *r;
9707 		r = rte_ring_lookup(res->name);
9708 		if (r == NULL) {
9709 			cmdline_printf(cl, "Cannot find ring\n");
9710 			return;
9711 		}
9712 		rte_ring_dump(stdout, r);
9713 	} else if (!strcmp(res->dump, "dump_mempool")) {
9714 		struct rte_mempool *mp;
9715 		mp = rte_mempool_lookup(res->name);
9716 		if (mp == NULL) {
9717 			cmdline_printf(cl, "Cannot find mempool\n");
9718 			return;
9719 		}
9720 		rte_mempool_dump(stdout, mp);
9721 	}
9722 }
9723 
9724 cmdline_parse_token_string_t cmd_dump_one_dump =
9725 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9726 				 "dump_ring#dump_mempool");
9727 
9728 cmdline_parse_token_string_t cmd_dump_one_name =
9729 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9730 
9731 cmdline_parse_inst_t cmd_dump_one = {
9732 	.f = cmd_dump_one_parsed,  /* function to call */
9733 	.data = NULL,      /* 2nd arg of func */
9734 	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9735 	.tokens = {        /* token list, NULL terminated */
9736 		(void *)&cmd_dump_one_dump,
9737 		(void *)&cmd_dump_one_name,
9738 		NULL,
9739 	},
9740 };
9741 
9742 /* *** Add/Del syn filter *** */
9743 struct cmd_syn_filter_result {
9744 	cmdline_fixed_string_t filter;
9745 	portid_t port_id;
9746 	cmdline_fixed_string_t ops;
9747 	cmdline_fixed_string_t priority;
9748 	cmdline_fixed_string_t high;
9749 	cmdline_fixed_string_t queue;
9750 	uint16_t queue_id;
9751 };
9752 
9753 static void
9754 cmd_syn_filter_parsed(void *parsed_result,
9755 			__rte_unused struct cmdline *cl,
9756 			__rte_unused void *data)
9757 {
9758 	struct cmd_syn_filter_result *res = parsed_result;
9759 	struct rte_eth_syn_filter syn_filter;
9760 	int ret = 0;
9761 
9762 	ret = rte_eth_dev_filter_supported(res->port_id,
9763 					RTE_ETH_FILTER_SYN);
9764 	if (ret < 0) {
9765 		printf("syn filter is not supported on port %u.\n",
9766 				res->port_id);
9767 		return;
9768 	}
9769 
9770 	memset(&syn_filter, 0, sizeof(syn_filter));
9771 
9772 	if (!strcmp(res->ops, "add")) {
9773 		if (!strcmp(res->high, "high"))
9774 			syn_filter.hig_pri = 1;
9775 		else
9776 			syn_filter.hig_pri = 0;
9777 
9778 		syn_filter.queue = res->queue_id;
9779 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9780 						RTE_ETH_FILTER_SYN,
9781 						RTE_ETH_FILTER_ADD,
9782 						&syn_filter);
9783 	} else
9784 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9785 						RTE_ETH_FILTER_SYN,
9786 						RTE_ETH_FILTER_DELETE,
9787 						&syn_filter);
9788 
9789 	if (ret < 0)
9790 		printf("syn filter programming error: (%s)\n",
9791 				strerror(-ret));
9792 }
9793 
9794 cmdline_parse_token_string_t cmd_syn_filter_filter =
9795 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9796 	filter, "syn_filter");
9797 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9798 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9799 	port_id, UINT16);
9800 cmdline_parse_token_string_t cmd_syn_filter_ops =
9801 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9802 	ops, "add#del");
9803 cmdline_parse_token_string_t cmd_syn_filter_priority =
9804 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9805 				priority, "priority");
9806 cmdline_parse_token_string_t cmd_syn_filter_high =
9807 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9808 				high, "high#low");
9809 cmdline_parse_token_string_t cmd_syn_filter_queue =
9810 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9811 				queue, "queue");
9812 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9813 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9814 				queue_id, UINT16);
9815 
9816 cmdline_parse_inst_t cmd_syn_filter = {
9817 	.f = cmd_syn_filter_parsed,
9818 	.data = NULL,
9819 	.help_str = "syn_filter <port_id> add|del priority high|low queue "
9820 		"<queue_id>: Add/Delete syn filter",
9821 	.tokens = {
9822 		(void *)&cmd_syn_filter_filter,
9823 		(void *)&cmd_syn_filter_port_id,
9824 		(void *)&cmd_syn_filter_ops,
9825 		(void *)&cmd_syn_filter_priority,
9826 		(void *)&cmd_syn_filter_high,
9827 		(void *)&cmd_syn_filter_queue,
9828 		(void *)&cmd_syn_filter_queue_id,
9829 		NULL,
9830 	},
9831 };
9832 
9833 /* *** queue region set *** */
9834 struct cmd_queue_region_result {
9835 	cmdline_fixed_string_t set;
9836 	cmdline_fixed_string_t port;
9837 	portid_t port_id;
9838 	cmdline_fixed_string_t cmd;
9839 	cmdline_fixed_string_t region;
9840 	uint8_t  region_id;
9841 	cmdline_fixed_string_t queue_start_index;
9842 	uint8_t  queue_id;
9843 	cmdline_fixed_string_t queue_num;
9844 	uint8_t  queue_num_value;
9845 };
9846 
9847 static void
9848 cmd_queue_region_parsed(void *parsed_result,
9849 			__rte_unused struct cmdline *cl,
9850 			__rte_unused void *data)
9851 {
9852 	struct cmd_queue_region_result *res = parsed_result;
9853 	int ret = -ENOTSUP;
9854 #ifdef RTE_LIBRTE_I40E_PMD
9855 	struct rte_pmd_i40e_queue_region_conf region_conf;
9856 	enum rte_pmd_i40e_queue_region_op op_type;
9857 #endif
9858 
9859 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9860 		return;
9861 
9862 #ifdef RTE_LIBRTE_I40E_PMD
9863 	memset(&region_conf, 0, sizeof(region_conf));
9864 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9865 	region_conf.region_id = res->region_id;
9866 	region_conf.queue_num = res->queue_num_value;
9867 	region_conf.queue_start_index = res->queue_id;
9868 
9869 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9870 				op_type, &region_conf);
9871 #endif
9872 
9873 	switch (ret) {
9874 	case 0:
9875 		break;
9876 	case -ENOTSUP:
9877 		printf("function not implemented or supported\n");
9878 		break;
9879 	default:
9880 		printf("queue region config error: (%s)\n", strerror(-ret));
9881 	}
9882 }
9883 
9884 cmdline_parse_token_string_t cmd_queue_region_set =
9885 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9886 		set, "set");
9887 cmdline_parse_token_string_t cmd_queue_region_port =
9888 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9889 cmdline_parse_token_num_t cmd_queue_region_port_id =
9890 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9891 				port_id, UINT16);
9892 cmdline_parse_token_string_t cmd_queue_region_cmd =
9893 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9894 				 cmd, "queue-region");
9895 cmdline_parse_token_string_t cmd_queue_region_id =
9896 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9897 				region, "region_id");
9898 cmdline_parse_token_num_t cmd_queue_region_index =
9899 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9900 				region_id, UINT8);
9901 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9902 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9903 				queue_start_index, "queue_start_index");
9904 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9905 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9906 				queue_id, UINT8);
9907 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9908 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9909 				queue_num, "queue_num");
9910 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9911 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9912 				queue_num_value, UINT8);
9913 
9914 cmdline_parse_inst_t cmd_queue_region = {
9915 	.f = cmd_queue_region_parsed,
9916 	.data = NULL,
9917 	.help_str = "set port <port_id> queue-region region_id <value> "
9918 		"queue_start_index <value> queue_num <value>: Set a queue region",
9919 	.tokens = {
9920 		(void *)&cmd_queue_region_set,
9921 		(void *)&cmd_queue_region_port,
9922 		(void *)&cmd_queue_region_port_id,
9923 		(void *)&cmd_queue_region_cmd,
9924 		(void *)&cmd_queue_region_id,
9925 		(void *)&cmd_queue_region_index,
9926 		(void *)&cmd_queue_region_queue_start_index,
9927 		(void *)&cmd_queue_region_queue_id,
9928 		(void *)&cmd_queue_region_queue_num,
9929 		(void *)&cmd_queue_region_queue_num_value,
9930 		NULL,
9931 	},
9932 };
9933 
9934 /* *** queue region and flowtype set *** */
9935 struct cmd_region_flowtype_result {
9936 	cmdline_fixed_string_t set;
9937 	cmdline_fixed_string_t port;
9938 	portid_t port_id;
9939 	cmdline_fixed_string_t cmd;
9940 	cmdline_fixed_string_t region;
9941 	uint8_t  region_id;
9942 	cmdline_fixed_string_t flowtype;
9943 	uint8_t  flowtype_id;
9944 };
9945 
9946 static void
9947 cmd_region_flowtype_parsed(void *parsed_result,
9948 			__rte_unused struct cmdline *cl,
9949 			__rte_unused void *data)
9950 {
9951 	struct cmd_region_flowtype_result *res = parsed_result;
9952 	int ret = -ENOTSUP;
9953 #ifdef RTE_LIBRTE_I40E_PMD
9954 	struct rte_pmd_i40e_queue_region_conf region_conf;
9955 	enum rte_pmd_i40e_queue_region_op op_type;
9956 #endif
9957 
9958 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9959 		return;
9960 
9961 #ifdef RTE_LIBRTE_I40E_PMD
9962 	memset(&region_conf, 0, sizeof(region_conf));
9963 
9964 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9965 	region_conf.region_id = res->region_id;
9966 	region_conf.hw_flowtype = res->flowtype_id;
9967 
9968 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9969 			op_type, &region_conf);
9970 #endif
9971 
9972 	switch (ret) {
9973 	case 0:
9974 		break;
9975 	case -ENOTSUP:
9976 		printf("function not implemented or supported\n");
9977 		break;
9978 	default:
9979 		printf("region flowtype config error: (%s)\n", strerror(-ret));
9980 	}
9981 }
9982 
9983 cmdline_parse_token_string_t cmd_region_flowtype_set =
9984 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9985 				set, "set");
9986 cmdline_parse_token_string_t cmd_region_flowtype_port =
9987 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9988 				port, "port");
9989 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9990 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9991 				port_id, UINT16);
9992 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9993 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9994 				cmd, "queue-region");
9995 cmdline_parse_token_string_t cmd_region_flowtype_index =
9996 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9997 				region, "region_id");
9998 cmdline_parse_token_num_t cmd_region_flowtype_id =
9999 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10000 				region_id, UINT8);
10001 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10002 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10003 				flowtype, "flowtype");
10004 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10005 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10006 				flowtype_id, UINT8);
10007 cmdline_parse_inst_t cmd_region_flowtype = {
10008 	.f = cmd_region_flowtype_parsed,
10009 	.data = NULL,
10010 	.help_str = "set port <port_id> queue-region region_id <value> "
10011 		"flowtype <value>: Set a flowtype region index",
10012 	.tokens = {
10013 		(void *)&cmd_region_flowtype_set,
10014 		(void *)&cmd_region_flowtype_port,
10015 		(void *)&cmd_region_flowtype_port_index,
10016 		(void *)&cmd_region_flowtype_cmd,
10017 		(void *)&cmd_region_flowtype_index,
10018 		(void *)&cmd_region_flowtype_id,
10019 		(void *)&cmd_region_flowtype_flow_index,
10020 		(void *)&cmd_region_flowtype_flow_id,
10021 		NULL,
10022 	},
10023 };
10024 
10025 /* *** User Priority (UP) to queue region (region_id) set *** */
10026 struct cmd_user_priority_region_result {
10027 	cmdline_fixed_string_t set;
10028 	cmdline_fixed_string_t port;
10029 	portid_t port_id;
10030 	cmdline_fixed_string_t cmd;
10031 	cmdline_fixed_string_t user_priority;
10032 	uint8_t  user_priority_id;
10033 	cmdline_fixed_string_t region;
10034 	uint8_t  region_id;
10035 };
10036 
10037 static void
10038 cmd_user_priority_region_parsed(void *parsed_result,
10039 			__rte_unused struct cmdline *cl,
10040 			__rte_unused void *data)
10041 {
10042 	struct cmd_user_priority_region_result *res = parsed_result;
10043 	int ret = -ENOTSUP;
10044 #ifdef RTE_LIBRTE_I40E_PMD
10045 	struct rte_pmd_i40e_queue_region_conf region_conf;
10046 	enum rte_pmd_i40e_queue_region_op op_type;
10047 #endif
10048 
10049 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10050 		return;
10051 
10052 #ifdef RTE_LIBRTE_I40E_PMD
10053 	memset(&region_conf, 0, sizeof(region_conf));
10054 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10055 	region_conf.user_priority = res->user_priority_id;
10056 	region_conf.region_id = res->region_id;
10057 
10058 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10059 				op_type, &region_conf);
10060 #endif
10061 
10062 	switch (ret) {
10063 	case 0:
10064 		break;
10065 	case -ENOTSUP:
10066 		printf("function not implemented or supported\n");
10067 		break;
10068 	default:
10069 		printf("user_priority region config error: (%s)\n",
10070 				strerror(-ret));
10071 	}
10072 }
10073 
10074 cmdline_parse_token_string_t cmd_user_priority_region_set =
10075 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10076 				set, "set");
10077 cmdline_parse_token_string_t cmd_user_priority_region_port =
10078 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10079 				port, "port");
10080 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10081 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10082 				port_id, UINT16);
10083 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10084 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10085 				cmd, "queue-region");
10086 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10087 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10088 				user_priority, "UP");
10089 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10090 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10091 				user_priority_id, UINT8);
10092 cmdline_parse_token_string_t cmd_user_priority_region_region =
10093 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10094 				region, "region_id");
10095 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10096 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10097 				region_id, UINT8);
10098 
10099 cmdline_parse_inst_t cmd_user_priority_region = {
10100 	.f = cmd_user_priority_region_parsed,
10101 	.data = NULL,
10102 	.help_str = "set port <port_id> queue-region UP <value> "
10103 		"region_id <value>: Set the mapping of User Priority (UP) "
10104 		"to queue region (region_id) ",
10105 	.tokens = {
10106 		(void *)&cmd_user_priority_region_set,
10107 		(void *)&cmd_user_priority_region_port,
10108 		(void *)&cmd_user_priority_region_port_index,
10109 		(void *)&cmd_user_priority_region_cmd,
10110 		(void *)&cmd_user_priority_region_UP,
10111 		(void *)&cmd_user_priority_region_UP_id,
10112 		(void *)&cmd_user_priority_region_region,
10113 		(void *)&cmd_user_priority_region_region_id,
10114 		NULL,
10115 	},
10116 };
10117 
10118 /* *** flush all queue region related configuration *** */
10119 struct cmd_flush_queue_region_result {
10120 	cmdline_fixed_string_t set;
10121 	cmdline_fixed_string_t port;
10122 	portid_t port_id;
10123 	cmdline_fixed_string_t cmd;
10124 	cmdline_fixed_string_t flush;
10125 	cmdline_fixed_string_t what;
10126 };
10127 
10128 static void
10129 cmd_flush_queue_region_parsed(void *parsed_result,
10130 			__rte_unused struct cmdline *cl,
10131 			__rte_unused void *data)
10132 {
10133 	struct cmd_flush_queue_region_result *res = parsed_result;
10134 	int ret = -ENOTSUP;
10135 #ifdef RTE_LIBRTE_I40E_PMD
10136 	struct rte_pmd_i40e_queue_region_conf region_conf;
10137 	enum rte_pmd_i40e_queue_region_op op_type;
10138 #endif
10139 
10140 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10141 		return;
10142 
10143 #ifdef RTE_LIBRTE_I40E_PMD
10144 	memset(&region_conf, 0, sizeof(region_conf));
10145 
10146 	if (strcmp(res->what, "on") == 0)
10147 		op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10148 	else
10149 		op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10150 
10151 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10152 				op_type, &region_conf);
10153 #endif
10154 
10155 	switch (ret) {
10156 	case 0:
10157 		break;
10158 	case -ENOTSUP:
10159 		printf("function not implemented or supported\n");
10160 		break;
10161 	default:
10162 		printf("queue region config flush error: (%s)\n",
10163 				strerror(-ret));
10164 	}
10165 }
10166 
10167 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10168 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10169 				set, "set");
10170 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10171 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10172 				port, "port");
10173 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10174 	TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10175 				port_id, UINT16);
10176 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10177 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10178 				cmd, "queue-region");
10179 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10180 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10181 				flush, "flush");
10182 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10183 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10184 				what, "on#off");
10185 
10186 cmdline_parse_inst_t cmd_flush_queue_region = {
10187 	.f = cmd_flush_queue_region_parsed,
10188 	.data = NULL,
10189 	.help_str = "set port <port_id> queue-region flush on|off"
10190 		": flush all queue region related configuration",
10191 	.tokens = {
10192 		(void *)&cmd_flush_queue_region_set,
10193 		(void *)&cmd_flush_queue_region_port,
10194 		(void *)&cmd_flush_queue_region_port_index,
10195 		(void *)&cmd_flush_queue_region_cmd,
10196 		(void *)&cmd_flush_queue_region_flush,
10197 		(void *)&cmd_flush_queue_region_what,
10198 		NULL,
10199 	},
10200 };
10201 
10202 /* *** get all queue region related configuration info *** */
10203 struct cmd_show_queue_region_info {
10204 	cmdline_fixed_string_t show;
10205 	cmdline_fixed_string_t port;
10206 	portid_t port_id;
10207 	cmdline_fixed_string_t cmd;
10208 };
10209 
10210 static void
10211 cmd_show_queue_region_info_parsed(void *parsed_result,
10212 			__rte_unused struct cmdline *cl,
10213 			__rte_unused void *data)
10214 {
10215 	struct cmd_show_queue_region_info *res = parsed_result;
10216 	int ret = -ENOTSUP;
10217 #ifdef RTE_LIBRTE_I40E_PMD
10218 	struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10219 	enum rte_pmd_i40e_queue_region_op op_type;
10220 #endif
10221 
10222 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10223 		return;
10224 
10225 #ifdef RTE_LIBRTE_I40E_PMD
10226 	memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10227 
10228 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10229 
10230 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10231 					op_type, &rte_pmd_regions);
10232 
10233 	port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10234 #endif
10235 
10236 	switch (ret) {
10237 	case 0:
10238 		break;
10239 	case -ENOTSUP:
10240 		printf("function not implemented or supported\n");
10241 		break;
10242 	default:
10243 		printf("queue region config info show error: (%s)\n",
10244 				strerror(-ret));
10245 	}
10246 }
10247 
10248 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10249 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10250 				show, "show");
10251 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10252 	TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10253 				port, "port");
10254 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10255 	TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10256 				port_id, UINT16);
10257 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10258 	TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10259 				cmd, "queue-region");
10260 
10261 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10262 	.f = cmd_show_queue_region_info_parsed,
10263 	.data = NULL,
10264 	.help_str = "show port <port_id> queue-region"
10265 		": show all queue region related configuration info",
10266 	.tokens = {
10267 		(void *)&cmd_show_queue_region_info_get,
10268 		(void *)&cmd_show_queue_region_info_port,
10269 		(void *)&cmd_show_queue_region_info_port_index,
10270 		(void *)&cmd_show_queue_region_info_cmd,
10271 		NULL,
10272 	},
10273 };
10274 
10275 /* *** ADD/REMOVE A 2tuple FILTER *** */
10276 struct cmd_2tuple_filter_result {
10277 	cmdline_fixed_string_t filter;
10278 	portid_t port_id;
10279 	cmdline_fixed_string_t ops;
10280 	cmdline_fixed_string_t dst_port;
10281 	uint16_t dst_port_value;
10282 	cmdline_fixed_string_t protocol;
10283 	uint8_t protocol_value;
10284 	cmdline_fixed_string_t mask;
10285 	uint8_t  mask_value;
10286 	cmdline_fixed_string_t tcp_flags;
10287 	uint8_t tcp_flags_value;
10288 	cmdline_fixed_string_t priority;
10289 	uint8_t  priority_value;
10290 	cmdline_fixed_string_t queue;
10291 	uint16_t  queue_id;
10292 };
10293 
10294 static void
10295 cmd_2tuple_filter_parsed(void *parsed_result,
10296 			__rte_unused struct cmdline *cl,
10297 			__rte_unused void *data)
10298 {
10299 	struct rte_eth_ntuple_filter filter;
10300 	struct cmd_2tuple_filter_result *res = parsed_result;
10301 	int ret = 0;
10302 
10303 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10304 	if (ret < 0) {
10305 		printf("ntuple filter is not supported on port %u.\n",
10306 			res->port_id);
10307 		return;
10308 	}
10309 
10310 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10311 
10312 	filter.flags = RTE_2TUPLE_FLAGS;
10313 	filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10314 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10315 	filter.proto = res->protocol_value;
10316 	filter.priority = res->priority_value;
10317 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10318 		printf("nonzero tcp_flags is only meaningful"
10319 			" when protocol is TCP.\n");
10320 		return;
10321 	}
10322 	if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10323 		printf("invalid TCP flags.\n");
10324 		return;
10325 	}
10326 
10327 	if (res->tcp_flags_value != 0) {
10328 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10329 		filter.tcp_flags = res->tcp_flags_value;
10330 	}
10331 
10332 	/* need convert to big endian. */
10333 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10334 	filter.queue = res->queue_id;
10335 
10336 	if (!strcmp(res->ops, "add"))
10337 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10338 				RTE_ETH_FILTER_NTUPLE,
10339 				RTE_ETH_FILTER_ADD,
10340 				&filter);
10341 	else
10342 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10343 				RTE_ETH_FILTER_NTUPLE,
10344 				RTE_ETH_FILTER_DELETE,
10345 				&filter);
10346 	if (ret < 0)
10347 		printf("2tuple filter programming error: (%s)\n",
10348 			strerror(-ret));
10349 
10350 }
10351 
10352 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10353 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10354 				 filter, "2tuple_filter");
10355 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10356 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10357 				port_id, UINT16);
10358 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10359 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10360 				 ops, "add#del");
10361 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10362 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10363 				dst_port, "dst_port");
10364 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10365 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10366 				dst_port_value, UINT16);
10367 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10368 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10369 				protocol, "protocol");
10370 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10371 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10372 				protocol_value, UINT8);
10373 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10374 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10375 				mask, "mask");
10376 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10377 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10378 				mask_value, INT8);
10379 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10380 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10381 				tcp_flags, "tcp_flags");
10382 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10383 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10384 				tcp_flags_value, UINT8);
10385 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10386 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10387 				priority, "priority");
10388 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10389 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10390 				priority_value, UINT8);
10391 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10392 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10393 				queue, "queue");
10394 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10395 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10396 				queue_id, UINT16);
10397 
10398 cmdline_parse_inst_t cmd_2tuple_filter = {
10399 	.f = cmd_2tuple_filter_parsed,
10400 	.data = NULL,
10401 	.help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10402 		"<value> mask <value> tcp_flags <value> priority <value> queue "
10403 		"<queue_id>: Add a 2tuple filter",
10404 	.tokens = {
10405 		(void *)&cmd_2tuple_filter_filter,
10406 		(void *)&cmd_2tuple_filter_port_id,
10407 		(void *)&cmd_2tuple_filter_ops,
10408 		(void *)&cmd_2tuple_filter_dst_port,
10409 		(void *)&cmd_2tuple_filter_dst_port_value,
10410 		(void *)&cmd_2tuple_filter_protocol,
10411 		(void *)&cmd_2tuple_filter_protocol_value,
10412 		(void *)&cmd_2tuple_filter_mask,
10413 		(void *)&cmd_2tuple_filter_mask_value,
10414 		(void *)&cmd_2tuple_filter_tcp_flags,
10415 		(void *)&cmd_2tuple_filter_tcp_flags_value,
10416 		(void *)&cmd_2tuple_filter_priority,
10417 		(void *)&cmd_2tuple_filter_priority_value,
10418 		(void *)&cmd_2tuple_filter_queue,
10419 		(void *)&cmd_2tuple_filter_queue_id,
10420 		NULL,
10421 	},
10422 };
10423 
10424 /* *** ADD/REMOVE A 5tuple FILTER *** */
10425 struct cmd_5tuple_filter_result {
10426 	cmdline_fixed_string_t filter;
10427 	portid_t port_id;
10428 	cmdline_fixed_string_t ops;
10429 	cmdline_fixed_string_t dst_ip;
10430 	cmdline_ipaddr_t dst_ip_value;
10431 	cmdline_fixed_string_t src_ip;
10432 	cmdline_ipaddr_t src_ip_value;
10433 	cmdline_fixed_string_t dst_port;
10434 	uint16_t dst_port_value;
10435 	cmdline_fixed_string_t src_port;
10436 	uint16_t src_port_value;
10437 	cmdline_fixed_string_t protocol;
10438 	uint8_t protocol_value;
10439 	cmdline_fixed_string_t mask;
10440 	uint8_t  mask_value;
10441 	cmdline_fixed_string_t tcp_flags;
10442 	uint8_t tcp_flags_value;
10443 	cmdline_fixed_string_t priority;
10444 	uint8_t  priority_value;
10445 	cmdline_fixed_string_t queue;
10446 	uint16_t  queue_id;
10447 };
10448 
10449 static void
10450 cmd_5tuple_filter_parsed(void *parsed_result,
10451 			__rte_unused struct cmdline *cl,
10452 			__rte_unused void *data)
10453 {
10454 	struct rte_eth_ntuple_filter filter;
10455 	struct cmd_5tuple_filter_result *res = parsed_result;
10456 	int ret = 0;
10457 
10458 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10459 	if (ret < 0) {
10460 		printf("ntuple filter is not supported on port %u.\n",
10461 			res->port_id);
10462 		return;
10463 	}
10464 
10465 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10466 
10467 	filter.flags = RTE_5TUPLE_FLAGS;
10468 	filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10469 	filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10470 	filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10471 	filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10472 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10473 	filter.proto = res->protocol_value;
10474 	filter.priority = res->priority_value;
10475 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10476 		printf("nonzero tcp_flags is only meaningful"
10477 			" when protocol is TCP.\n");
10478 		return;
10479 	}
10480 	if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10481 		printf("invalid TCP flags.\n");
10482 		return;
10483 	}
10484 
10485 	if (res->tcp_flags_value != 0) {
10486 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10487 		filter.tcp_flags = res->tcp_flags_value;
10488 	}
10489 
10490 	if (res->dst_ip_value.family == AF_INET)
10491 		/* no need to convert, already big endian. */
10492 		filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10493 	else {
10494 		if (filter.dst_ip_mask == 0) {
10495 			printf("can not support ipv6 involved compare.\n");
10496 			return;
10497 		}
10498 		filter.dst_ip = 0;
10499 	}
10500 
10501 	if (res->src_ip_value.family == AF_INET)
10502 		/* no need to convert, already big endian. */
10503 		filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10504 	else {
10505 		if (filter.src_ip_mask == 0) {
10506 			printf("can not support ipv6 involved compare.\n");
10507 			return;
10508 		}
10509 		filter.src_ip = 0;
10510 	}
10511 	/* need convert to big endian. */
10512 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10513 	filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10514 	filter.queue = res->queue_id;
10515 
10516 	if (!strcmp(res->ops, "add"))
10517 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10518 				RTE_ETH_FILTER_NTUPLE,
10519 				RTE_ETH_FILTER_ADD,
10520 				&filter);
10521 	else
10522 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10523 				RTE_ETH_FILTER_NTUPLE,
10524 				RTE_ETH_FILTER_DELETE,
10525 				&filter);
10526 	if (ret < 0)
10527 		printf("5tuple filter programming error: (%s)\n",
10528 			strerror(-ret));
10529 }
10530 
10531 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10532 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10533 				 filter, "5tuple_filter");
10534 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10535 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10536 				port_id, UINT16);
10537 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10538 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10539 				 ops, "add#del");
10540 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10541 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10542 				dst_ip, "dst_ip");
10543 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10544 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10545 				dst_ip_value);
10546 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10547 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10548 				src_ip, "src_ip");
10549 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10550 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10551 				src_ip_value);
10552 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10553 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10554 				dst_port, "dst_port");
10555 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10556 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10557 				dst_port_value, UINT16);
10558 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10559 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10560 				src_port, "src_port");
10561 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10562 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10563 				src_port_value, UINT16);
10564 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10565 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10566 				protocol, "protocol");
10567 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10568 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10569 				protocol_value, UINT8);
10570 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10571 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10572 				mask, "mask");
10573 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10574 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10575 				mask_value, INT8);
10576 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10577 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10578 				tcp_flags, "tcp_flags");
10579 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10580 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10581 				tcp_flags_value, UINT8);
10582 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10583 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10584 				priority, "priority");
10585 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10586 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10587 				priority_value, UINT8);
10588 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10589 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10590 				queue, "queue");
10591 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10592 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10593 				queue_id, UINT16);
10594 
10595 cmdline_parse_inst_t cmd_5tuple_filter = {
10596 	.f = cmd_5tuple_filter_parsed,
10597 	.data = NULL,
10598 	.help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10599 		"src_ip <value> dst_port <value> src_port <value> "
10600 		"protocol <value>  mask <value> tcp_flags <value> "
10601 		"priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10602 	.tokens = {
10603 		(void *)&cmd_5tuple_filter_filter,
10604 		(void *)&cmd_5tuple_filter_port_id,
10605 		(void *)&cmd_5tuple_filter_ops,
10606 		(void *)&cmd_5tuple_filter_dst_ip,
10607 		(void *)&cmd_5tuple_filter_dst_ip_value,
10608 		(void *)&cmd_5tuple_filter_src_ip,
10609 		(void *)&cmd_5tuple_filter_src_ip_value,
10610 		(void *)&cmd_5tuple_filter_dst_port,
10611 		(void *)&cmd_5tuple_filter_dst_port_value,
10612 		(void *)&cmd_5tuple_filter_src_port,
10613 		(void *)&cmd_5tuple_filter_src_port_value,
10614 		(void *)&cmd_5tuple_filter_protocol,
10615 		(void *)&cmd_5tuple_filter_protocol_value,
10616 		(void *)&cmd_5tuple_filter_mask,
10617 		(void *)&cmd_5tuple_filter_mask_value,
10618 		(void *)&cmd_5tuple_filter_tcp_flags,
10619 		(void *)&cmd_5tuple_filter_tcp_flags_value,
10620 		(void *)&cmd_5tuple_filter_priority,
10621 		(void *)&cmd_5tuple_filter_priority_value,
10622 		(void *)&cmd_5tuple_filter_queue,
10623 		(void *)&cmd_5tuple_filter_queue_id,
10624 		NULL,
10625 	},
10626 };
10627 
10628 /* *** ADD/REMOVE A flex FILTER *** */
10629 struct cmd_flex_filter_result {
10630 	cmdline_fixed_string_t filter;
10631 	cmdline_fixed_string_t ops;
10632 	portid_t port_id;
10633 	cmdline_fixed_string_t len;
10634 	uint8_t len_value;
10635 	cmdline_fixed_string_t bytes;
10636 	cmdline_fixed_string_t bytes_value;
10637 	cmdline_fixed_string_t mask;
10638 	cmdline_fixed_string_t mask_value;
10639 	cmdline_fixed_string_t priority;
10640 	uint8_t priority_value;
10641 	cmdline_fixed_string_t queue;
10642 	uint16_t queue_id;
10643 };
10644 
10645 static int xdigit2val(unsigned char c)
10646 {
10647 	int val;
10648 	if (isdigit(c))
10649 		val = c - '0';
10650 	else if (isupper(c))
10651 		val = c - 'A' + 10;
10652 	else
10653 		val = c - 'a' + 10;
10654 	return val;
10655 }
10656 
10657 static void
10658 cmd_flex_filter_parsed(void *parsed_result,
10659 			  __rte_unused struct cmdline *cl,
10660 			  __rte_unused void *data)
10661 {
10662 	int ret = 0;
10663 	struct rte_eth_flex_filter filter;
10664 	struct cmd_flex_filter_result *res = parsed_result;
10665 	char *bytes_ptr, *mask_ptr;
10666 	uint16_t len, i, j = 0;
10667 	char c;
10668 	int val;
10669 	uint8_t byte = 0;
10670 
10671 	if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10672 		printf("the len exceed the max length 128\n");
10673 		return;
10674 	}
10675 	memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10676 	filter.len = res->len_value;
10677 	filter.priority = res->priority_value;
10678 	filter.queue = res->queue_id;
10679 	bytes_ptr = res->bytes_value;
10680 	mask_ptr = res->mask_value;
10681 
10682 	 /* translate bytes string to array. */
10683 	if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10684 		(bytes_ptr[1] == 'X')))
10685 		bytes_ptr += 2;
10686 	len = strnlen(bytes_ptr, res->len_value * 2);
10687 	if (len == 0 || (len % 8 != 0)) {
10688 		printf("please check len and bytes input\n");
10689 		return;
10690 	}
10691 	for (i = 0; i < len; i++) {
10692 		c = bytes_ptr[i];
10693 		if (isxdigit(c) == 0) {
10694 			/* invalid characters. */
10695 			printf("invalid input\n");
10696 			return;
10697 		}
10698 		val = xdigit2val(c);
10699 		if (i % 2) {
10700 			byte |= val;
10701 			filter.bytes[j] = byte;
10702 			printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10703 			j++;
10704 			byte = 0;
10705 		} else
10706 			byte |= val << 4;
10707 	}
10708 	printf("\n");
10709 	 /* translate mask string to uint8_t array. */
10710 	if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10711 		(mask_ptr[1] == 'X')))
10712 		mask_ptr += 2;
10713 	len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10714 	if (len == 0) {
10715 		printf("invalid input\n");
10716 		return;
10717 	}
10718 	j = 0;
10719 	byte = 0;
10720 	for (i = 0; i < len; i++) {
10721 		c = mask_ptr[i];
10722 		if (isxdigit(c) == 0) {
10723 			/* invalid characters. */
10724 			printf("invalid input\n");
10725 			return;
10726 		}
10727 		val = xdigit2val(c);
10728 		if (i % 2) {
10729 			byte |= val;
10730 			filter.mask[j] = byte;
10731 			printf("mask[%d]:%02x ", j, filter.mask[j]);
10732 			j++;
10733 			byte = 0;
10734 		} else
10735 			byte |= val << 4;
10736 	}
10737 	printf("\n");
10738 
10739 	if (!strcmp(res->ops, "add"))
10740 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10741 				RTE_ETH_FILTER_FLEXIBLE,
10742 				RTE_ETH_FILTER_ADD,
10743 				&filter);
10744 	else
10745 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10746 				RTE_ETH_FILTER_FLEXIBLE,
10747 				RTE_ETH_FILTER_DELETE,
10748 				&filter);
10749 
10750 	if (ret < 0)
10751 		printf("flex filter setting error: (%s)\n", strerror(-ret));
10752 }
10753 
10754 cmdline_parse_token_string_t cmd_flex_filter_filter =
10755 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10756 				filter, "flex_filter");
10757 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10758 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10759 				port_id, UINT16);
10760 cmdline_parse_token_string_t cmd_flex_filter_ops =
10761 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10762 				ops, "add#del");
10763 cmdline_parse_token_string_t cmd_flex_filter_len =
10764 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10765 				len, "len");
10766 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10767 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10768 				len_value, UINT8);
10769 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10770 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10771 				bytes, "bytes");
10772 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10773 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10774 				bytes_value, NULL);
10775 cmdline_parse_token_string_t cmd_flex_filter_mask =
10776 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10777 				mask, "mask");
10778 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10779 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10780 				mask_value, NULL);
10781 cmdline_parse_token_string_t cmd_flex_filter_priority =
10782 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10783 				priority, "priority");
10784 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10785 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10786 				priority_value, UINT8);
10787 cmdline_parse_token_string_t cmd_flex_filter_queue =
10788 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10789 				queue, "queue");
10790 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10791 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10792 				queue_id, UINT16);
10793 cmdline_parse_inst_t cmd_flex_filter = {
10794 	.f = cmd_flex_filter_parsed,
10795 	.data = NULL,
10796 	.help_str = "flex_filter <port_id> add|del len <value> bytes "
10797 		"<value> mask <value> priority <value> queue <queue_id>: "
10798 		"Add/Del a flex filter",
10799 	.tokens = {
10800 		(void *)&cmd_flex_filter_filter,
10801 		(void *)&cmd_flex_filter_port_id,
10802 		(void *)&cmd_flex_filter_ops,
10803 		(void *)&cmd_flex_filter_len,
10804 		(void *)&cmd_flex_filter_len_value,
10805 		(void *)&cmd_flex_filter_bytes,
10806 		(void *)&cmd_flex_filter_bytes_value,
10807 		(void *)&cmd_flex_filter_mask,
10808 		(void *)&cmd_flex_filter_mask_value,
10809 		(void *)&cmd_flex_filter_priority,
10810 		(void *)&cmd_flex_filter_priority_value,
10811 		(void *)&cmd_flex_filter_queue,
10812 		(void *)&cmd_flex_filter_queue_id,
10813 		NULL,
10814 	},
10815 };
10816 
10817 /* *** Filters Control *** */
10818 
10819 /* *** deal with ethertype filter *** */
10820 struct cmd_ethertype_filter_result {
10821 	cmdline_fixed_string_t filter;
10822 	portid_t port_id;
10823 	cmdline_fixed_string_t ops;
10824 	cmdline_fixed_string_t mac;
10825 	struct rte_ether_addr mac_addr;
10826 	cmdline_fixed_string_t ethertype;
10827 	uint16_t ethertype_value;
10828 	cmdline_fixed_string_t drop;
10829 	cmdline_fixed_string_t queue;
10830 	uint16_t  queue_id;
10831 };
10832 
10833 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10834 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10835 				 filter, "ethertype_filter");
10836 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10837 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10838 			      port_id, UINT16);
10839 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10840 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10841 				 ops, "add#del");
10842 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10843 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10844 				 mac, "mac_addr#mac_ignr");
10845 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10846 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10847 				     mac_addr);
10848 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10849 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10850 				 ethertype, "ethertype");
10851 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10852 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10853 			      ethertype_value, UINT16);
10854 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10855 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10856 				 drop, "drop#fwd");
10857 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10858 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10859 				 queue, "queue");
10860 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10861 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10862 			      queue_id, UINT16);
10863 
10864 static void
10865 cmd_ethertype_filter_parsed(void *parsed_result,
10866 			  __rte_unused struct cmdline *cl,
10867 			  __rte_unused void *data)
10868 {
10869 	struct cmd_ethertype_filter_result *res = parsed_result;
10870 	struct rte_eth_ethertype_filter filter;
10871 	int ret = 0;
10872 
10873 	ret = rte_eth_dev_filter_supported(res->port_id,
10874 			RTE_ETH_FILTER_ETHERTYPE);
10875 	if (ret < 0) {
10876 		printf("ethertype filter is not supported on port %u.\n",
10877 			res->port_id);
10878 		return;
10879 	}
10880 
10881 	memset(&filter, 0, sizeof(filter));
10882 	if (!strcmp(res->mac, "mac_addr")) {
10883 		filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10884 		rte_memcpy(&filter.mac_addr, &res->mac_addr,
10885 			sizeof(struct rte_ether_addr));
10886 	}
10887 	if (!strcmp(res->drop, "drop"))
10888 		filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10889 	filter.ether_type = res->ethertype_value;
10890 	filter.queue = res->queue_id;
10891 
10892 	if (!strcmp(res->ops, "add"))
10893 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10894 				RTE_ETH_FILTER_ETHERTYPE,
10895 				RTE_ETH_FILTER_ADD,
10896 				&filter);
10897 	else
10898 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10899 				RTE_ETH_FILTER_ETHERTYPE,
10900 				RTE_ETH_FILTER_DELETE,
10901 				&filter);
10902 	if (ret < 0)
10903 		printf("ethertype filter programming error: (%s)\n",
10904 			strerror(-ret));
10905 }
10906 
10907 cmdline_parse_inst_t cmd_ethertype_filter = {
10908 	.f = cmd_ethertype_filter_parsed,
10909 	.data = NULL,
10910 	.help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10911 		"<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10912 		"Add or delete an ethertype filter entry",
10913 	.tokens = {
10914 		(void *)&cmd_ethertype_filter_filter,
10915 		(void *)&cmd_ethertype_filter_port_id,
10916 		(void *)&cmd_ethertype_filter_ops,
10917 		(void *)&cmd_ethertype_filter_mac,
10918 		(void *)&cmd_ethertype_filter_mac_addr,
10919 		(void *)&cmd_ethertype_filter_ethertype,
10920 		(void *)&cmd_ethertype_filter_ethertype_value,
10921 		(void *)&cmd_ethertype_filter_drop,
10922 		(void *)&cmd_ethertype_filter_queue,
10923 		(void *)&cmd_ethertype_filter_queue_id,
10924 		NULL,
10925 	},
10926 };
10927 
10928 /* *** deal with flow director filter *** */
10929 struct cmd_flow_director_result {
10930 	cmdline_fixed_string_t flow_director_filter;
10931 	portid_t port_id;
10932 	cmdline_fixed_string_t mode;
10933 	cmdline_fixed_string_t mode_value;
10934 	cmdline_fixed_string_t ops;
10935 	cmdline_fixed_string_t flow;
10936 	cmdline_fixed_string_t flow_type;
10937 	cmdline_fixed_string_t ether;
10938 	uint16_t ether_type;
10939 	cmdline_fixed_string_t src;
10940 	cmdline_ipaddr_t ip_src;
10941 	uint16_t port_src;
10942 	cmdline_fixed_string_t dst;
10943 	cmdline_ipaddr_t ip_dst;
10944 	uint16_t port_dst;
10945 	cmdline_fixed_string_t verify_tag;
10946 	uint32_t verify_tag_value;
10947 	cmdline_fixed_string_t tos;
10948 	uint8_t tos_value;
10949 	cmdline_fixed_string_t proto;
10950 	uint8_t proto_value;
10951 	cmdline_fixed_string_t ttl;
10952 	uint8_t ttl_value;
10953 	cmdline_fixed_string_t vlan;
10954 	uint16_t vlan_value;
10955 	cmdline_fixed_string_t flexbytes;
10956 	cmdline_fixed_string_t flexbytes_value;
10957 	cmdline_fixed_string_t pf_vf;
10958 	cmdline_fixed_string_t drop;
10959 	cmdline_fixed_string_t queue;
10960 	uint16_t  queue_id;
10961 	cmdline_fixed_string_t fd_id;
10962 	uint32_t  fd_id_value;
10963 	cmdline_fixed_string_t mac;
10964 	struct rte_ether_addr mac_addr;
10965 	cmdline_fixed_string_t tunnel;
10966 	cmdline_fixed_string_t tunnel_type;
10967 	cmdline_fixed_string_t tunnel_id;
10968 	uint32_t tunnel_id_value;
10969 	cmdline_fixed_string_t packet;
10970 	char filepath[];
10971 };
10972 
10973 static inline int
10974 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10975 {
10976 	char s[256];
10977 	const char *p, *p0 = q_arg;
10978 	char *end;
10979 	unsigned long int_fld;
10980 	char *str_fld[max_num];
10981 	int i;
10982 	unsigned size;
10983 	int ret = -1;
10984 
10985 	p = strchr(p0, '(');
10986 	if (p == NULL)
10987 		return -1;
10988 	++p;
10989 	p0 = strchr(p, ')');
10990 	if (p0 == NULL)
10991 		return -1;
10992 
10993 	size = p0 - p;
10994 	if (size >= sizeof(s))
10995 		return -1;
10996 
10997 	snprintf(s, sizeof(s), "%.*s", size, p);
10998 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10999 	if (ret < 0 || ret > max_num)
11000 		return -1;
11001 	for (i = 0; i < ret; i++) {
11002 		errno = 0;
11003 		int_fld = strtoul(str_fld[i], &end, 0);
11004 		if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11005 			return -1;
11006 		flexbytes[i] = (uint8_t)int_fld;
11007 	}
11008 	return ret;
11009 }
11010 
11011 static uint16_t
11012 str2flowtype(char *string)
11013 {
11014 	uint8_t i = 0;
11015 	static const struct {
11016 		char str[32];
11017 		uint16_t type;
11018 	} flowtype_str[] = {
11019 		{"raw", RTE_ETH_FLOW_RAW},
11020 		{"ipv4", RTE_ETH_FLOW_IPV4},
11021 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11022 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11023 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11024 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11025 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11026 		{"ipv6", RTE_ETH_FLOW_IPV6},
11027 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11028 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11029 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11030 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11031 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11032 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11033 	};
11034 
11035 	for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11036 		if (!strcmp(flowtype_str[i].str, string))
11037 			return flowtype_str[i].type;
11038 	}
11039 
11040 	if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11041 		return (uint16_t)atoi(string);
11042 
11043 	return RTE_ETH_FLOW_UNKNOWN;
11044 }
11045 
11046 static enum rte_eth_fdir_tunnel_type
11047 str2fdir_tunneltype(char *string)
11048 {
11049 	uint8_t i = 0;
11050 
11051 	static const struct {
11052 		char str[32];
11053 		enum rte_eth_fdir_tunnel_type type;
11054 	} tunneltype_str[] = {
11055 		{"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11056 		{"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11057 	};
11058 
11059 	for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11060 		if (!strcmp(tunneltype_str[i].str, string))
11061 			return tunneltype_str[i].type;
11062 	}
11063 	return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11064 }
11065 
11066 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11067 do { \
11068 	if ((ip_addr).family == AF_INET) \
11069 		(ip) = (ip_addr).addr.ipv4.s_addr; \
11070 	else { \
11071 		printf("invalid parameter.\n"); \
11072 		return; \
11073 	} \
11074 } while (0)
11075 
11076 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11077 do { \
11078 	if ((ip_addr).family == AF_INET6) \
11079 		rte_memcpy(&(ip), \
11080 				 &((ip_addr).addr.ipv6), \
11081 				 sizeof(struct in6_addr)); \
11082 	else { \
11083 		printf("invalid parameter.\n"); \
11084 		return; \
11085 	} \
11086 } while (0)
11087 
11088 static void
11089 cmd_flow_director_filter_parsed(void *parsed_result,
11090 			  __rte_unused struct cmdline *cl,
11091 			  __rte_unused void *data)
11092 {
11093 	struct cmd_flow_director_result *res = parsed_result;
11094 	struct rte_eth_fdir_filter entry;
11095 	uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11096 	char *end;
11097 	unsigned long vf_id;
11098 	int ret = 0;
11099 
11100 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11101 	if (ret < 0) {
11102 		printf("flow director is not supported on port %u.\n",
11103 			res->port_id);
11104 		return;
11105 	}
11106 	memset(flexbytes, 0, sizeof(flexbytes));
11107 	memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11108 
11109 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11110 		if (strcmp(res->mode_value, "MAC-VLAN")) {
11111 			printf("Please set mode to MAC-VLAN.\n");
11112 			return;
11113 		}
11114 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11115 		if (strcmp(res->mode_value, "Tunnel")) {
11116 			printf("Please set mode to Tunnel.\n");
11117 			return;
11118 		}
11119 	} else {
11120 		if (!strcmp(res->mode_value, "raw")) {
11121 #ifdef RTE_LIBRTE_I40E_PMD
11122 			struct rte_pmd_i40e_flow_type_mapping
11123 					mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11124 			struct rte_pmd_i40e_pkt_template_conf conf;
11125 			uint16_t flow_type = str2flowtype(res->flow_type);
11126 			uint16_t i, port = res->port_id;
11127 			uint8_t add;
11128 
11129 			memset(&conf, 0, sizeof(conf));
11130 
11131 			if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11132 				printf("Invalid flow type specified.\n");
11133 				return;
11134 			}
11135 			ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11136 								 mapping);
11137 			if (ret)
11138 				return;
11139 			if (mapping[flow_type].pctype == 0ULL) {
11140 				printf("Invalid flow type specified.\n");
11141 				return;
11142 			}
11143 			for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11144 				if (mapping[flow_type].pctype & (1ULL << i)) {
11145 					conf.input.pctype = i;
11146 					break;
11147 				}
11148 			}
11149 
11150 			conf.input.packet = open_file(res->filepath,
11151 						&conf.input.length);
11152 			if (!conf.input.packet)
11153 				return;
11154 			if (!strcmp(res->drop, "drop"))
11155 				conf.action.behavior =
11156 					RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11157 			else
11158 				conf.action.behavior =
11159 					RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11160 			conf.action.report_status =
11161 					RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11162 			conf.action.rx_queue = res->queue_id;
11163 			conf.soft_id = res->fd_id_value;
11164 			add  = strcmp(res->ops, "del") ? 1 : 0;
11165 			ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11166 									&conf,
11167 									add);
11168 			if (ret < 0)
11169 				printf("flow director config error: (%s)\n",
11170 				       strerror(-ret));
11171 			close_file(conf.input.packet);
11172 #endif
11173 			return;
11174 		} else if (strcmp(res->mode_value, "IP")) {
11175 			printf("Please set mode to IP or raw.\n");
11176 			return;
11177 		}
11178 		entry.input.flow_type = str2flowtype(res->flow_type);
11179 	}
11180 
11181 	ret = parse_flexbytes(res->flexbytes_value,
11182 					flexbytes,
11183 					RTE_ETH_FDIR_MAX_FLEXLEN);
11184 	if (ret < 0) {
11185 		printf("error: Cannot parse flexbytes input.\n");
11186 		return;
11187 	}
11188 
11189 	switch (entry.input.flow_type) {
11190 	case RTE_ETH_FLOW_FRAG_IPV4:
11191 	case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11192 		entry.input.flow.ip4_flow.proto = res->proto_value;
11193 		/* fall-through */
11194 	case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11195 	case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11196 		IPV4_ADDR_TO_UINT(res->ip_dst,
11197 			entry.input.flow.ip4_flow.dst_ip);
11198 		IPV4_ADDR_TO_UINT(res->ip_src,
11199 			entry.input.flow.ip4_flow.src_ip);
11200 		entry.input.flow.ip4_flow.tos = res->tos_value;
11201 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
11202 		/* need convert to big endian. */
11203 		entry.input.flow.udp4_flow.dst_port =
11204 				rte_cpu_to_be_16(res->port_dst);
11205 		entry.input.flow.udp4_flow.src_port =
11206 				rte_cpu_to_be_16(res->port_src);
11207 		break;
11208 	case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11209 		IPV4_ADDR_TO_UINT(res->ip_dst,
11210 			entry.input.flow.sctp4_flow.ip.dst_ip);
11211 		IPV4_ADDR_TO_UINT(res->ip_src,
11212 			entry.input.flow.sctp4_flow.ip.src_ip);
11213 		entry.input.flow.ip4_flow.tos = res->tos_value;
11214 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
11215 		/* need convert to big endian. */
11216 		entry.input.flow.sctp4_flow.dst_port =
11217 				rte_cpu_to_be_16(res->port_dst);
11218 		entry.input.flow.sctp4_flow.src_port =
11219 				rte_cpu_to_be_16(res->port_src);
11220 		entry.input.flow.sctp4_flow.verify_tag =
11221 				rte_cpu_to_be_32(res->verify_tag_value);
11222 		break;
11223 	case RTE_ETH_FLOW_FRAG_IPV6:
11224 	case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11225 		entry.input.flow.ipv6_flow.proto = res->proto_value;
11226 		/* fall-through */
11227 	case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11228 	case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11229 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
11230 			entry.input.flow.ipv6_flow.dst_ip);
11231 		IPV6_ADDR_TO_ARRAY(res->ip_src,
11232 			entry.input.flow.ipv6_flow.src_ip);
11233 		entry.input.flow.ipv6_flow.tc = res->tos_value;
11234 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11235 		/* need convert to big endian. */
11236 		entry.input.flow.udp6_flow.dst_port =
11237 				rte_cpu_to_be_16(res->port_dst);
11238 		entry.input.flow.udp6_flow.src_port =
11239 				rte_cpu_to_be_16(res->port_src);
11240 		break;
11241 	case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11242 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
11243 			entry.input.flow.sctp6_flow.ip.dst_ip);
11244 		IPV6_ADDR_TO_ARRAY(res->ip_src,
11245 			entry.input.flow.sctp6_flow.ip.src_ip);
11246 		entry.input.flow.ipv6_flow.tc = res->tos_value;
11247 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11248 		/* need convert to big endian. */
11249 		entry.input.flow.sctp6_flow.dst_port =
11250 				rte_cpu_to_be_16(res->port_dst);
11251 		entry.input.flow.sctp6_flow.src_port =
11252 				rte_cpu_to_be_16(res->port_src);
11253 		entry.input.flow.sctp6_flow.verify_tag =
11254 				rte_cpu_to_be_32(res->verify_tag_value);
11255 		break;
11256 	case RTE_ETH_FLOW_L2_PAYLOAD:
11257 		entry.input.flow.l2_flow.ether_type =
11258 			rte_cpu_to_be_16(res->ether_type);
11259 		break;
11260 	default:
11261 		break;
11262 	}
11263 
11264 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11265 		rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11266 				 &res->mac_addr,
11267 				 sizeof(struct rte_ether_addr));
11268 
11269 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11270 		rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11271 				 &res->mac_addr,
11272 				 sizeof(struct rte_ether_addr));
11273 		entry.input.flow.tunnel_flow.tunnel_type =
11274 			str2fdir_tunneltype(res->tunnel_type);
11275 		entry.input.flow.tunnel_flow.tunnel_id =
11276 			rte_cpu_to_be_32(res->tunnel_id_value);
11277 	}
11278 
11279 	rte_memcpy(entry.input.flow_ext.flexbytes,
11280 		   flexbytes,
11281 		   RTE_ETH_FDIR_MAX_FLEXLEN);
11282 
11283 	entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11284 
11285 	entry.action.flex_off = 0;  /*use 0 by default */
11286 	if (!strcmp(res->drop, "drop"))
11287 		entry.action.behavior = RTE_ETH_FDIR_REJECT;
11288 	else
11289 		entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11290 
11291 	if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11292 	    fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11293 		if (!strcmp(res->pf_vf, "pf"))
11294 			entry.input.flow_ext.is_vf = 0;
11295 		else if (!strncmp(res->pf_vf, "vf", 2)) {
11296 			struct rte_eth_dev_info dev_info;
11297 
11298 			ret = eth_dev_info_get_print_err(res->port_id,
11299 						&dev_info);
11300 			if (ret != 0)
11301 				return;
11302 
11303 			errno = 0;
11304 			vf_id = strtoul(res->pf_vf + 2, &end, 10);
11305 			if (errno != 0 || *end != '\0' ||
11306 			    vf_id >= dev_info.max_vfs) {
11307 				printf("invalid parameter %s.\n", res->pf_vf);
11308 				return;
11309 			}
11310 			entry.input.flow_ext.is_vf = 1;
11311 			entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11312 		} else {
11313 			printf("invalid parameter %s.\n", res->pf_vf);
11314 			return;
11315 		}
11316 	}
11317 
11318 	/* set to report FD ID by default */
11319 	entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11320 	entry.action.rx_queue = res->queue_id;
11321 	entry.soft_id = res->fd_id_value;
11322 	if (!strcmp(res->ops, "add"))
11323 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11324 					     RTE_ETH_FILTER_ADD, &entry);
11325 	else if (!strcmp(res->ops, "del"))
11326 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11327 					     RTE_ETH_FILTER_DELETE, &entry);
11328 	else
11329 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11330 					     RTE_ETH_FILTER_UPDATE, &entry);
11331 	if (ret < 0)
11332 		printf("flow director programming error: (%s)\n",
11333 			strerror(-ret));
11334 }
11335 
11336 cmdline_parse_token_string_t cmd_flow_director_filter =
11337 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11338 				 flow_director_filter, "flow_director_filter");
11339 cmdline_parse_token_num_t cmd_flow_director_port_id =
11340 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11341 			      port_id, UINT16);
11342 cmdline_parse_token_string_t cmd_flow_director_ops =
11343 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11344 				 ops, "add#del#update");
11345 cmdline_parse_token_string_t cmd_flow_director_flow =
11346 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11347 				 flow, "flow");
11348 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11349 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11350 		flow_type, NULL);
11351 cmdline_parse_token_string_t cmd_flow_director_ether =
11352 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11353 				 ether, "ether");
11354 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11355 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11356 			      ether_type, UINT16);
11357 cmdline_parse_token_string_t cmd_flow_director_src =
11358 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11359 				 src, "src");
11360 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11361 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11362 				 ip_src);
11363 cmdline_parse_token_num_t cmd_flow_director_port_src =
11364 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11365 			      port_src, UINT16);
11366 cmdline_parse_token_string_t cmd_flow_director_dst =
11367 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11368 				 dst, "dst");
11369 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11370 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11371 				 ip_dst);
11372 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11373 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11374 			      port_dst, UINT16);
11375 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11376 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11377 				  verify_tag, "verify_tag");
11378 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11379 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11380 			      verify_tag_value, UINT32);
11381 cmdline_parse_token_string_t cmd_flow_director_tos =
11382 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11383 				 tos, "tos");
11384 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11385 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11386 			      tos_value, UINT8);
11387 cmdline_parse_token_string_t cmd_flow_director_proto =
11388 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11389 				 proto, "proto");
11390 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11391 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11392 			      proto_value, UINT8);
11393 cmdline_parse_token_string_t cmd_flow_director_ttl =
11394 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11395 				 ttl, "ttl");
11396 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11397 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11398 			      ttl_value, UINT8);
11399 cmdline_parse_token_string_t cmd_flow_director_vlan =
11400 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11401 				 vlan, "vlan");
11402 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11403 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11404 			      vlan_value, UINT16);
11405 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11406 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11407 				 flexbytes, "flexbytes");
11408 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11409 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11410 			      flexbytes_value, NULL);
11411 cmdline_parse_token_string_t cmd_flow_director_drop =
11412 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11413 				 drop, "drop#fwd");
11414 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11415 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11416 			      pf_vf, NULL);
11417 cmdline_parse_token_string_t cmd_flow_director_queue =
11418 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11419 				 queue, "queue");
11420 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11421 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11422 			      queue_id, UINT16);
11423 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11424 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11425 				 fd_id, "fd_id");
11426 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11427 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11428 			      fd_id_value, UINT32);
11429 
11430 cmdline_parse_token_string_t cmd_flow_director_mode =
11431 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11432 				 mode, "mode");
11433 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11434 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11435 				 mode_value, "IP");
11436 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11437 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11438 				 mode_value, "MAC-VLAN");
11439 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11440 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11441 				 mode_value, "Tunnel");
11442 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11443 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11444 				 mode_value, "raw");
11445 cmdline_parse_token_string_t cmd_flow_director_mac =
11446 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11447 				 mac, "mac");
11448 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11449 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11450 				    mac_addr);
11451 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11452 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11453 				 tunnel, "tunnel");
11454 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11455 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11456 				 tunnel_type, "NVGRE#VxLAN");
11457 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11458 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11459 				 tunnel_id, "tunnel-id");
11460 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11461 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11462 			      tunnel_id_value, UINT32);
11463 cmdline_parse_token_string_t cmd_flow_director_packet =
11464 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11465 				 packet, "packet");
11466 cmdline_parse_token_string_t cmd_flow_director_filepath =
11467 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11468 				 filepath, NULL);
11469 
11470 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11471 	.f = cmd_flow_director_filter_parsed,
11472 	.data = NULL,
11473 	.help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11474 		" ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11475 		"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11476 		"l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11477 		"proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11478 		"flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11479 		"fd_id <fd_id_value>: "
11480 		"Add or delete an ip flow director entry on NIC",
11481 	.tokens = {
11482 		(void *)&cmd_flow_director_filter,
11483 		(void *)&cmd_flow_director_port_id,
11484 		(void *)&cmd_flow_director_mode,
11485 		(void *)&cmd_flow_director_mode_ip,
11486 		(void *)&cmd_flow_director_ops,
11487 		(void *)&cmd_flow_director_flow,
11488 		(void *)&cmd_flow_director_flow_type,
11489 		(void *)&cmd_flow_director_src,
11490 		(void *)&cmd_flow_director_ip_src,
11491 		(void *)&cmd_flow_director_dst,
11492 		(void *)&cmd_flow_director_ip_dst,
11493 		(void *)&cmd_flow_director_tos,
11494 		(void *)&cmd_flow_director_tos_value,
11495 		(void *)&cmd_flow_director_proto,
11496 		(void *)&cmd_flow_director_proto_value,
11497 		(void *)&cmd_flow_director_ttl,
11498 		(void *)&cmd_flow_director_ttl_value,
11499 		(void *)&cmd_flow_director_vlan,
11500 		(void *)&cmd_flow_director_vlan_value,
11501 		(void *)&cmd_flow_director_flexbytes,
11502 		(void *)&cmd_flow_director_flexbytes_value,
11503 		(void *)&cmd_flow_director_drop,
11504 		(void *)&cmd_flow_director_pf_vf,
11505 		(void *)&cmd_flow_director_queue,
11506 		(void *)&cmd_flow_director_queue_id,
11507 		(void *)&cmd_flow_director_fd_id,
11508 		(void *)&cmd_flow_director_fd_id_value,
11509 		NULL,
11510 	},
11511 };
11512 
11513 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11514 	.f = cmd_flow_director_filter_parsed,
11515 	.data = NULL,
11516 	.help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11517 		"director entry on NIC",
11518 	.tokens = {
11519 		(void *)&cmd_flow_director_filter,
11520 		(void *)&cmd_flow_director_port_id,
11521 		(void *)&cmd_flow_director_mode,
11522 		(void *)&cmd_flow_director_mode_ip,
11523 		(void *)&cmd_flow_director_ops,
11524 		(void *)&cmd_flow_director_flow,
11525 		(void *)&cmd_flow_director_flow_type,
11526 		(void *)&cmd_flow_director_src,
11527 		(void *)&cmd_flow_director_ip_src,
11528 		(void *)&cmd_flow_director_port_src,
11529 		(void *)&cmd_flow_director_dst,
11530 		(void *)&cmd_flow_director_ip_dst,
11531 		(void *)&cmd_flow_director_port_dst,
11532 		(void *)&cmd_flow_director_tos,
11533 		(void *)&cmd_flow_director_tos_value,
11534 		(void *)&cmd_flow_director_ttl,
11535 		(void *)&cmd_flow_director_ttl_value,
11536 		(void *)&cmd_flow_director_vlan,
11537 		(void *)&cmd_flow_director_vlan_value,
11538 		(void *)&cmd_flow_director_flexbytes,
11539 		(void *)&cmd_flow_director_flexbytes_value,
11540 		(void *)&cmd_flow_director_drop,
11541 		(void *)&cmd_flow_director_pf_vf,
11542 		(void *)&cmd_flow_director_queue,
11543 		(void *)&cmd_flow_director_queue_id,
11544 		(void *)&cmd_flow_director_fd_id,
11545 		(void *)&cmd_flow_director_fd_id_value,
11546 		NULL,
11547 	},
11548 };
11549 
11550 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11551 	.f = cmd_flow_director_filter_parsed,
11552 	.data = NULL,
11553 	.help_str = "flow_director_filter ... : Add or delete a sctp flow "
11554 		"director entry on NIC",
11555 	.tokens = {
11556 		(void *)&cmd_flow_director_filter,
11557 		(void *)&cmd_flow_director_port_id,
11558 		(void *)&cmd_flow_director_mode,
11559 		(void *)&cmd_flow_director_mode_ip,
11560 		(void *)&cmd_flow_director_ops,
11561 		(void *)&cmd_flow_director_flow,
11562 		(void *)&cmd_flow_director_flow_type,
11563 		(void *)&cmd_flow_director_src,
11564 		(void *)&cmd_flow_director_ip_src,
11565 		(void *)&cmd_flow_director_port_src,
11566 		(void *)&cmd_flow_director_dst,
11567 		(void *)&cmd_flow_director_ip_dst,
11568 		(void *)&cmd_flow_director_port_dst,
11569 		(void *)&cmd_flow_director_verify_tag,
11570 		(void *)&cmd_flow_director_verify_tag_value,
11571 		(void *)&cmd_flow_director_tos,
11572 		(void *)&cmd_flow_director_tos_value,
11573 		(void *)&cmd_flow_director_ttl,
11574 		(void *)&cmd_flow_director_ttl_value,
11575 		(void *)&cmd_flow_director_vlan,
11576 		(void *)&cmd_flow_director_vlan_value,
11577 		(void *)&cmd_flow_director_flexbytes,
11578 		(void *)&cmd_flow_director_flexbytes_value,
11579 		(void *)&cmd_flow_director_drop,
11580 		(void *)&cmd_flow_director_pf_vf,
11581 		(void *)&cmd_flow_director_queue,
11582 		(void *)&cmd_flow_director_queue_id,
11583 		(void *)&cmd_flow_director_fd_id,
11584 		(void *)&cmd_flow_director_fd_id_value,
11585 		NULL,
11586 	},
11587 };
11588 
11589 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11590 	.f = cmd_flow_director_filter_parsed,
11591 	.data = NULL,
11592 	.help_str = "flow_director_filter ... : Add or delete a L2 flow "
11593 		"director entry on NIC",
11594 	.tokens = {
11595 		(void *)&cmd_flow_director_filter,
11596 		(void *)&cmd_flow_director_port_id,
11597 		(void *)&cmd_flow_director_mode,
11598 		(void *)&cmd_flow_director_mode_ip,
11599 		(void *)&cmd_flow_director_ops,
11600 		(void *)&cmd_flow_director_flow,
11601 		(void *)&cmd_flow_director_flow_type,
11602 		(void *)&cmd_flow_director_ether,
11603 		(void *)&cmd_flow_director_ether_type,
11604 		(void *)&cmd_flow_director_flexbytes,
11605 		(void *)&cmd_flow_director_flexbytes_value,
11606 		(void *)&cmd_flow_director_drop,
11607 		(void *)&cmd_flow_director_pf_vf,
11608 		(void *)&cmd_flow_director_queue,
11609 		(void *)&cmd_flow_director_queue_id,
11610 		(void *)&cmd_flow_director_fd_id,
11611 		(void *)&cmd_flow_director_fd_id_value,
11612 		NULL,
11613 	},
11614 };
11615 
11616 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11617 	.f = cmd_flow_director_filter_parsed,
11618 	.data = NULL,
11619 	.help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11620 		"director entry on NIC",
11621 	.tokens = {
11622 		(void *)&cmd_flow_director_filter,
11623 		(void *)&cmd_flow_director_port_id,
11624 		(void *)&cmd_flow_director_mode,
11625 		(void *)&cmd_flow_director_mode_mac_vlan,
11626 		(void *)&cmd_flow_director_ops,
11627 		(void *)&cmd_flow_director_mac,
11628 		(void *)&cmd_flow_director_mac_addr,
11629 		(void *)&cmd_flow_director_vlan,
11630 		(void *)&cmd_flow_director_vlan_value,
11631 		(void *)&cmd_flow_director_flexbytes,
11632 		(void *)&cmd_flow_director_flexbytes_value,
11633 		(void *)&cmd_flow_director_drop,
11634 		(void *)&cmd_flow_director_queue,
11635 		(void *)&cmd_flow_director_queue_id,
11636 		(void *)&cmd_flow_director_fd_id,
11637 		(void *)&cmd_flow_director_fd_id_value,
11638 		NULL,
11639 	},
11640 };
11641 
11642 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11643 	.f = cmd_flow_director_filter_parsed,
11644 	.data = NULL,
11645 	.help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11646 		"director entry on NIC",
11647 	.tokens = {
11648 		(void *)&cmd_flow_director_filter,
11649 		(void *)&cmd_flow_director_port_id,
11650 		(void *)&cmd_flow_director_mode,
11651 		(void *)&cmd_flow_director_mode_tunnel,
11652 		(void *)&cmd_flow_director_ops,
11653 		(void *)&cmd_flow_director_mac,
11654 		(void *)&cmd_flow_director_mac_addr,
11655 		(void *)&cmd_flow_director_vlan,
11656 		(void *)&cmd_flow_director_vlan_value,
11657 		(void *)&cmd_flow_director_tunnel,
11658 		(void *)&cmd_flow_director_tunnel_type,
11659 		(void *)&cmd_flow_director_tunnel_id,
11660 		(void *)&cmd_flow_director_tunnel_id_value,
11661 		(void *)&cmd_flow_director_flexbytes,
11662 		(void *)&cmd_flow_director_flexbytes_value,
11663 		(void *)&cmd_flow_director_drop,
11664 		(void *)&cmd_flow_director_queue,
11665 		(void *)&cmd_flow_director_queue_id,
11666 		(void *)&cmd_flow_director_fd_id,
11667 		(void *)&cmd_flow_director_fd_id_value,
11668 		NULL,
11669 	},
11670 };
11671 
11672 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11673 	.f = cmd_flow_director_filter_parsed,
11674 	.data = NULL,
11675 	.help_str = "flow_director_filter ... : Add or delete a raw flow "
11676 		"director entry on NIC",
11677 	.tokens = {
11678 		(void *)&cmd_flow_director_filter,
11679 		(void *)&cmd_flow_director_port_id,
11680 		(void *)&cmd_flow_director_mode,
11681 		(void *)&cmd_flow_director_mode_raw,
11682 		(void *)&cmd_flow_director_ops,
11683 		(void *)&cmd_flow_director_flow,
11684 		(void *)&cmd_flow_director_flow_type,
11685 		(void *)&cmd_flow_director_drop,
11686 		(void *)&cmd_flow_director_queue,
11687 		(void *)&cmd_flow_director_queue_id,
11688 		(void *)&cmd_flow_director_fd_id,
11689 		(void *)&cmd_flow_director_fd_id_value,
11690 		(void *)&cmd_flow_director_packet,
11691 		(void *)&cmd_flow_director_filepath,
11692 		NULL,
11693 	},
11694 };
11695 
11696 struct cmd_flush_flow_director_result {
11697 	cmdline_fixed_string_t flush_flow_director;
11698 	portid_t port_id;
11699 };
11700 
11701 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11702 	TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11703 				 flush_flow_director, "flush_flow_director");
11704 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11705 	TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11706 			      port_id, UINT16);
11707 
11708 static void
11709 cmd_flush_flow_director_parsed(void *parsed_result,
11710 			  __rte_unused struct cmdline *cl,
11711 			  __rte_unused void *data)
11712 {
11713 	struct cmd_flow_director_result *res = parsed_result;
11714 	int ret = 0;
11715 
11716 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11717 	if (ret < 0) {
11718 		printf("flow director is not supported on port %u.\n",
11719 			res->port_id);
11720 		return;
11721 	}
11722 
11723 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11724 			RTE_ETH_FILTER_FLUSH, NULL);
11725 	if (ret < 0)
11726 		printf("flow director table flushing error: (%s)\n",
11727 			strerror(-ret));
11728 }
11729 
11730 cmdline_parse_inst_t cmd_flush_flow_director = {
11731 	.f = cmd_flush_flow_director_parsed,
11732 	.data = NULL,
11733 	.help_str = "flush_flow_director <port_id>: "
11734 		"Flush all flow director entries of a device on NIC",
11735 	.tokens = {
11736 		(void *)&cmd_flush_flow_director_flush,
11737 		(void *)&cmd_flush_flow_director_port_id,
11738 		NULL,
11739 	},
11740 };
11741 
11742 /* *** deal with flow director mask *** */
11743 struct cmd_flow_director_mask_result {
11744 	cmdline_fixed_string_t flow_director_mask;
11745 	portid_t port_id;
11746 	cmdline_fixed_string_t mode;
11747 	cmdline_fixed_string_t mode_value;
11748 	cmdline_fixed_string_t vlan;
11749 	uint16_t vlan_mask;
11750 	cmdline_fixed_string_t src_mask;
11751 	cmdline_ipaddr_t ipv4_src;
11752 	cmdline_ipaddr_t ipv6_src;
11753 	uint16_t port_src;
11754 	cmdline_fixed_string_t dst_mask;
11755 	cmdline_ipaddr_t ipv4_dst;
11756 	cmdline_ipaddr_t ipv6_dst;
11757 	uint16_t port_dst;
11758 	cmdline_fixed_string_t mac;
11759 	uint8_t mac_addr_byte_mask;
11760 	cmdline_fixed_string_t tunnel_id;
11761 	uint32_t tunnel_id_mask;
11762 	cmdline_fixed_string_t tunnel_type;
11763 	uint8_t tunnel_type_mask;
11764 };
11765 
11766 static void
11767 cmd_flow_director_mask_parsed(void *parsed_result,
11768 			  __rte_unused struct cmdline *cl,
11769 			  __rte_unused void *data)
11770 {
11771 	struct cmd_flow_director_mask_result *res = parsed_result;
11772 	struct rte_eth_fdir_masks *mask;
11773 	struct rte_port *port;
11774 
11775 	port = &ports[res->port_id];
11776 	/** Check if the port is not started **/
11777 	if (port->port_status != RTE_PORT_STOPPED) {
11778 		printf("Please stop port %d first\n", res->port_id);
11779 		return;
11780 	}
11781 
11782 	mask = &port->dev_conf.fdir_conf.mask;
11783 
11784 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11785 		if (strcmp(res->mode_value, "MAC-VLAN")) {
11786 			printf("Please set mode to MAC-VLAN.\n");
11787 			return;
11788 		}
11789 
11790 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11791 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11792 		if (strcmp(res->mode_value, "Tunnel")) {
11793 			printf("Please set mode to Tunnel.\n");
11794 			return;
11795 		}
11796 
11797 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11798 		mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11799 		mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11800 		mask->tunnel_type_mask = res->tunnel_type_mask;
11801 	} else {
11802 		if (strcmp(res->mode_value, "IP")) {
11803 			printf("Please set mode to IP.\n");
11804 			return;
11805 		}
11806 
11807 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11808 		IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11809 		IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11810 		IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11811 		IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11812 		mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11813 		mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11814 	}
11815 
11816 	cmd_reconfig_device_queue(res->port_id, 1, 1);
11817 }
11818 
11819 cmdline_parse_token_string_t cmd_flow_director_mask =
11820 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11821 				 flow_director_mask, "flow_director_mask");
11822 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11823 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11824 			      port_id, UINT16);
11825 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11826 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11827 				 vlan, "vlan");
11828 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11829 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11830 			      vlan_mask, UINT16);
11831 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11832 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11833 				 src_mask, "src_mask");
11834 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11835 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11836 				 ipv4_src);
11837 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11838 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11839 				 ipv6_src);
11840 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11841 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11842 			      port_src, UINT16);
11843 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11844 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11845 				 dst_mask, "dst_mask");
11846 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11847 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11848 				 ipv4_dst);
11849 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11850 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11851 				 ipv6_dst);
11852 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11853 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11854 			      port_dst, UINT16);
11855 
11856 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11857 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11858 				 mode, "mode");
11859 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11860 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11861 				 mode_value, "IP");
11862 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11863 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11864 				 mode_value, "MAC-VLAN");
11865 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11866 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11867 				 mode_value, "Tunnel");
11868 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11869 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11870 				 mac, "mac");
11871 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11872 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11873 			      mac_addr_byte_mask, UINT8);
11874 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11875 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11876 				 tunnel_type, "tunnel-type");
11877 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11878 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11879 			      tunnel_type_mask, UINT8);
11880 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11881 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11882 				 tunnel_id, "tunnel-id");
11883 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11884 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11885 			      tunnel_id_mask, UINT32);
11886 
11887 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11888 	.f = cmd_flow_director_mask_parsed,
11889 	.data = NULL,
11890 	.help_str = "flow_director_mask ... : "
11891 		"Set IP mode flow director's mask on NIC",
11892 	.tokens = {
11893 		(void *)&cmd_flow_director_mask,
11894 		(void *)&cmd_flow_director_mask_port_id,
11895 		(void *)&cmd_flow_director_mask_mode,
11896 		(void *)&cmd_flow_director_mask_mode_ip,
11897 		(void *)&cmd_flow_director_mask_vlan,
11898 		(void *)&cmd_flow_director_mask_vlan_value,
11899 		(void *)&cmd_flow_director_mask_src,
11900 		(void *)&cmd_flow_director_mask_ipv4_src,
11901 		(void *)&cmd_flow_director_mask_ipv6_src,
11902 		(void *)&cmd_flow_director_mask_port_src,
11903 		(void *)&cmd_flow_director_mask_dst,
11904 		(void *)&cmd_flow_director_mask_ipv4_dst,
11905 		(void *)&cmd_flow_director_mask_ipv6_dst,
11906 		(void *)&cmd_flow_director_mask_port_dst,
11907 		NULL,
11908 	},
11909 };
11910 
11911 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11912 	.f = cmd_flow_director_mask_parsed,
11913 	.data = NULL,
11914 	.help_str = "flow_director_mask ... : Set MAC VLAN mode "
11915 		"flow director's mask on NIC",
11916 	.tokens = {
11917 		(void *)&cmd_flow_director_mask,
11918 		(void *)&cmd_flow_director_mask_port_id,
11919 		(void *)&cmd_flow_director_mask_mode,
11920 		(void *)&cmd_flow_director_mask_mode_mac_vlan,
11921 		(void *)&cmd_flow_director_mask_vlan,
11922 		(void *)&cmd_flow_director_mask_vlan_value,
11923 		NULL,
11924 	},
11925 };
11926 
11927 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11928 	.f = cmd_flow_director_mask_parsed,
11929 	.data = NULL,
11930 	.help_str = "flow_director_mask ... : Set tunnel mode "
11931 		"flow director's mask on NIC",
11932 	.tokens = {
11933 		(void *)&cmd_flow_director_mask,
11934 		(void *)&cmd_flow_director_mask_port_id,
11935 		(void *)&cmd_flow_director_mask_mode,
11936 		(void *)&cmd_flow_director_mask_mode_tunnel,
11937 		(void *)&cmd_flow_director_mask_vlan,
11938 		(void *)&cmd_flow_director_mask_vlan_value,
11939 		(void *)&cmd_flow_director_mask_mac,
11940 		(void *)&cmd_flow_director_mask_mac_value,
11941 		(void *)&cmd_flow_director_mask_tunnel_type,
11942 		(void *)&cmd_flow_director_mask_tunnel_type_value,
11943 		(void *)&cmd_flow_director_mask_tunnel_id,
11944 		(void *)&cmd_flow_director_mask_tunnel_id_value,
11945 		NULL,
11946 	},
11947 };
11948 
11949 /* *** deal with flow director mask on flexible payload *** */
11950 struct cmd_flow_director_flex_mask_result {
11951 	cmdline_fixed_string_t flow_director_flexmask;
11952 	portid_t port_id;
11953 	cmdline_fixed_string_t flow;
11954 	cmdline_fixed_string_t flow_type;
11955 	cmdline_fixed_string_t mask;
11956 };
11957 
11958 static void
11959 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11960 			  __rte_unused struct cmdline *cl,
11961 			  __rte_unused void *data)
11962 {
11963 	struct cmd_flow_director_flex_mask_result *res = parsed_result;
11964 	struct rte_eth_fdir_info fdir_info;
11965 	struct rte_eth_fdir_flex_mask flex_mask;
11966 	struct rte_port *port;
11967 	uint64_t flow_type_mask;
11968 	uint16_t i;
11969 	int ret;
11970 
11971 	port = &ports[res->port_id];
11972 	/** Check if the port is not started **/
11973 	if (port->port_status != RTE_PORT_STOPPED) {
11974 		printf("Please stop port %d first\n", res->port_id);
11975 		return;
11976 	}
11977 
11978 	memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11979 	ret = parse_flexbytes(res->mask,
11980 			flex_mask.mask,
11981 			RTE_ETH_FDIR_MAX_FLEXLEN);
11982 	if (ret < 0) {
11983 		printf("error: Cannot parse mask input.\n");
11984 		return;
11985 	}
11986 
11987 	memset(&fdir_info, 0, sizeof(fdir_info));
11988 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11989 				RTE_ETH_FILTER_INFO, &fdir_info);
11990 	if (ret < 0) {
11991 		printf("Cannot get FDir filter info\n");
11992 		return;
11993 	}
11994 
11995 	if (!strcmp(res->flow_type, "none")) {
11996 		/* means don't specify the flow type */
11997 		flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11998 		for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11999 			memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
12000 			       0, sizeof(struct rte_eth_fdir_flex_mask));
12001 		port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12002 		rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12003 				 &flex_mask,
12004 				 sizeof(struct rte_eth_fdir_flex_mask));
12005 		cmd_reconfig_device_queue(res->port_id, 1, 1);
12006 		return;
12007 	}
12008 	flow_type_mask = fdir_info.flow_types_mask[0];
12009 	if (!strcmp(res->flow_type, "all")) {
12010 		if (!flow_type_mask) {
12011 			printf("No flow type supported\n");
12012 			return;
12013 		}
12014 		for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12015 			if (flow_type_mask & (1ULL << i)) {
12016 				flex_mask.flow_type = i;
12017 				fdir_set_flex_mask(res->port_id, &flex_mask);
12018 			}
12019 		}
12020 		cmd_reconfig_device_queue(res->port_id, 1, 1);
12021 		return;
12022 	}
12023 	flex_mask.flow_type = str2flowtype(res->flow_type);
12024 	if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12025 		printf("Flow type %s not supported on port %d\n",
12026 				res->flow_type, res->port_id);
12027 		return;
12028 	}
12029 	fdir_set_flex_mask(res->port_id, &flex_mask);
12030 	cmd_reconfig_device_queue(res->port_id, 1, 1);
12031 }
12032 
12033 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12034 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12035 				 flow_director_flexmask,
12036 				 "flow_director_flex_mask");
12037 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12038 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12039 			      port_id, UINT16);
12040 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12041 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12042 				 flow, "flow");
12043 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12044 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12045 		flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12046 		"ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12047 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12048 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12049 				 mask, NULL);
12050 
12051 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12052 	.f = cmd_flow_director_flex_mask_parsed,
12053 	.data = NULL,
12054 	.help_str = "flow_director_flex_mask ... : "
12055 		"Set flow director's flex mask on NIC",
12056 	.tokens = {
12057 		(void *)&cmd_flow_director_flexmask,
12058 		(void *)&cmd_flow_director_flexmask_port_id,
12059 		(void *)&cmd_flow_director_flexmask_flow,
12060 		(void *)&cmd_flow_director_flexmask_flow_type,
12061 		(void *)&cmd_flow_director_flexmask_mask,
12062 		NULL,
12063 	},
12064 };
12065 
12066 /* *** deal with flow director flexible payload configuration *** */
12067 struct cmd_flow_director_flexpayload_result {
12068 	cmdline_fixed_string_t flow_director_flexpayload;
12069 	portid_t port_id;
12070 	cmdline_fixed_string_t payload_layer;
12071 	cmdline_fixed_string_t payload_cfg;
12072 };
12073 
12074 static inline int
12075 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12076 {
12077 	char s[256];
12078 	const char *p, *p0 = q_arg;
12079 	char *end;
12080 	unsigned long int_fld;
12081 	char *str_fld[max_num];
12082 	int i;
12083 	unsigned size;
12084 	int ret = -1;
12085 
12086 	p = strchr(p0, '(');
12087 	if (p == NULL)
12088 		return -1;
12089 	++p;
12090 	p0 = strchr(p, ')');
12091 	if (p0 == NULL)
12092 		return -1;
12093 
12094 	size = p0 - p;
12095 	if (size >= sizeof(s))
12096 		return -1;
12097 
12098 	snprintf(s, sizeof(s), "%.*s", size, p);
12099 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12100 	if (ret < 0 || ret > max_num)
12101 		return -1;
12102 	for (i = 0; i < ret; i++) {
12103 		errno = 0;
12104 		int_fld = strtoul(str_fld[i], &end, 0);
12105 		if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12106 			return -1;
12107 		offsets[i] = (uint16_t)int_fld;
12108 	}
12109 	return ret;
12110 }
12111 
12112 static void
12113 cmd_flow_director_flxpld_parsed(void *parsed_result,
12114 			  __rte_unused struct cmdline *cl,
12115 			  __rte_unused void *data)
12116 {
12117 	struct cmd_flow_director_flexpayload_result *res = parsed_result;
12118 	struct rte_eth_flex_payload_cfg flex_cfg;
12119 	struct rte_port *port;
12120 	int ret = 0;
12121 
12122 	port = &ports[res->port_id];
12123 	/** Check if the port is not started **/
12124 	if (port->port_status != RTE_PORT_STOPPED) {
12125 		printf("Please stop port %d first\n", res->port_id);
12126 		return;
12127 	}
12128 
12129 	memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12130 
12131 	if (!strcmp(res->payload_layer, "raw"))
12132 		flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12133 	else if (!strcmp(res->payload_layer, "l2"))
12134 		flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12135 	else if (!strcmp(res->payload_layer, "l3"))
12136 		flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12137 	else if (!strcmp(res->payload_layer, "l4"))
12138 		flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12139 
12140 	ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12141 			    RTE_ETH_FDIR_MAX_FLEXLEN);
12142 	if (ret < 0) {
12143 		printf("error: Cannot parse flex payload input.\n");
12144 		return;
12145 	}
12146 
12147 	fdir_set_flex_payload(res->port_id, &flex_cfg);
12148 	cmd_reconfig_device_queue(res->port_id, 1, 1);
12149 }
12150 
12151 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12152 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12153 				 flow_director_flexpayload,
12154 				 "flow_director_flex_payload");
12155 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12156 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12157 			      port_id, UINT16);
12158 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12159 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12160 				 payload_layer, "raw#l2#l3#l4");
12161 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12162 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12163 				 payload_cfg, NULL);
12164 
12165 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12166 	.f = cmd_flow_director_flxpld_parsed,
12167 	.data = NULL,
12168 	.help_str = "flow_director_flexpayload ... : "
12169 		"Set flow director's flex payload on NIC",
12170 	.tokens = {
12171 		(void *)&cmd_flow_director_flexpayload,
12172 		(void *)&cmd_flow_director_flexpayload_port_id,
12173 		(void *)&cmd_flow_director_flexpayload_payload_layer,
12174 		(void *)&cmd_flow_director_flexpayload_payload_cfg,
12175 		NULL,
12176 	},
12177 };
12178 
12179 /* Generic flow interface command. */
12180 extern cmdline_parse_inst_t cmd_flow;
12181 
12182 /* *** Classification Filters Control *** */
12183 /* *** Get symmetric hash enable per port *** */
12184 struct cmd_get_sym_hash_ena_per_port_result {
12185 	cmdline_fixed_string_t get_sym_hash_ena_per_port;
12186 	portid_t port_id;
12187 };
12188 
12189 static void
12190 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12191 				 __rte_unused struct cmdline *cl,
12192 				 __rte_unused void *data)
12193 {
12194 	struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12195 	struct rte_eth_hash_filter_info info;
12196 	int ret;
12197 
12198 	if (rte_eth_dev_filter_supported(res->port_id,
12199 				RTE_ETH_FILTER_HASH) < 0) {
12200 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12201 							res->port_id);
12202 		return;
12203 	}
12204 
12205 	memset(&info, 0, sizeof(info));
12206 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12207 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12208 						RTE_ETH_FILTER_GET, &info);
12209 
12210 	if (ret < 0) {
12211 		printf("Cannot get symmetric hash enable per port "
12212 					"on port %u\n", res->port_id);
12213 		return;
12214 	}
12215 
12216 	printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12217 				"enabled" : "disabled", res->port_id);
12218 }
12219 
12220 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12221 	TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12222 		get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12223 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12224 	TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12225 		port_id, UINT16);
12226 
12227 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12228 	.f = cmd_get_sym_hash_per_port_parsed,
12229 	.data = NULL,
12230 	.help_str = "get_sym_hash_ena_per_port <port_id>",
12231 	.tokens = {
12232 		(void *)&cmd_get_sym_hash_ena_per_port_all,
12233 		(void *)&cmd_get_sym_hash_ena_per_port_port_id,
12234 		NULL,
12235 	},
12236 };
12237 
12238 /* *** Set symmetric hash enable per port *** */
12239 struct cmd_set_sym_hash_ena_per_port_result {
12240 	cmdline_fixed_string_t set_sym_hash_ena_per_port;
12241 	cmdline_fixed_string_t enable;
12242 	portid_t port_id;
12243 };
12244 
12245 static void
12246 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12247 				 __rte_unused struct cmdline *cl,
12248 				 __rte_unused void *data)
12249 {
12250 	struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12251 	struct rte_eth_hash_filter_info info;
12252 	int ret;
12253 
12254 	if (rte_eth_dev_filter_supported(res->port_id,
12255 				RTE_ETH_FILTER_HASH) < 0) {
12256 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12257 							res->port_id);
12258 		return;
12259 	}
12260 
12261 	memset(&info, 0, sizeof(info));
12262 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12263 	if (!strcmp(res->enable, "enable"))
12264 		info.info.enable = 1;
12265 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12266 					RTE_ETH_FILTER_SET, &info);
12267 	if (ret < 0) {
12268 		printf("Cannot set symmetric hash enable per port on "
12269 					"port %u\n", res->port_id);
12270 		return;
12271 	}
12272 	printf("Symmetric hash has been set to %s on port %u\n",
12273 					res->enable, res->port_id);
12274 }
12275 
12276 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12277 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12278 		set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12279 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12280 	TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12281 		port_id, UINT16);
12282 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12283 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12284 		enable, "enable#disable");
12285 
12286 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12287 	.f = cmd_set_sym_hash_per_port_parsed,
12288 	.data = NULL,
12289 	.help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12290 	.tokens = {
12291 		(void *)&cmd_set_sym_hash_ena_per_port_all,
12292 		(void *)&cmd_set_sym_hash_ena_per_port_port_id,
12293 		(void *)&cmd_set_sym_hash_ena_per_port_enable,
12294 		NULL,
12295 	},
12296 };
12297 
12298 /* Get global config of hash function */
12299 struct cmd_get_hash_global_config_result {
12300 	cmdline_fixed_string_t get_hash_global_config;
12301 	portid_t port_id;
12302 };
12303 
12304 static char *
12305 flowtype_to_str(uint16_t ftype)
12306 {
12307 	uint16_t i;
12308 	static struct {
12309 		char str[16];
12310 		uint16_t ftype;
12311 	} ftype_table[] = {
12312 		{"ipv4", RTE_ETH_FLOW_IPV4},
12313 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12314 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12315 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12316 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12317 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12318 		{"ipv6", RTE_ETH_FLOW_IPV6},
12319 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12320 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12321 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12322 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12323 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12324 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12325 		{"port", RTE_ETH_FLOW_PORT},
12326 		{"vxlan", RTE_ETH_FLOW_VXLAN},
12327 		{"geneve", RTE_ETH_FLOW_GENEVE},
12328 		{"nvgre", RTE_ETH_FLOW_NVGRE},
12329 		{"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12330 	};
12331 
12332 	for (i = 0; i < RTE_DIM(ftype_table); i++) {
12333 		if (ftype_table[i].ftype == ftype)
12334 			return ftype_table[i].str;
12335 	}
12336 
12337 	return NULL;
12338 }
12339 
12340 static void
12341 cmd_get_hash_global_config_parsed(void *parsed_result,
12342 				  __rte_unused struct cmdline *cl,
12343 				  __rte_unused void *data)
12344 {
12345 	struct cmd_get_hash_global_config_result *res = parsed_result;
12346 	struct rte_eth_hash_filter_info info;
12347 	uint32_t idx, offset;
12348 	uint16_t i;
12349 	char *str;
12350 	int ret;
12351 
12352 	if (rte_eth_dev_filter_supported(res->port_id,
12353 			RTE_ETH_FILTER_HASH) < 0) {
12354 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12355 							res->port_id);
12356 		return;
12357 	}
12358 
12359 	memset(&info, 0, sizeof(info));
12360 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12361 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12362 					RTE_ETH_FILTER_GET, &info);
12363 	if (ret < 0) {
12364 		printf("Cannot get hash global configurations by port %d\n",
12365 							res->port_id);
12366 		return;
12367 	}
12368 
12369 	switch (info.info.global_conf.hash_func) {
12370 	case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12371 		printf("Hash function is Toeplitz\n");
12372 		break;
12373 	case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12374 		printf("Hash function is Simple XOR\n");
12375 		break;
12376 	case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12377 		printf("Hash function is Symmetric Toeplitz\n");
12378 		break;
12379 	default:
12380 		printf("Unknown hash function\n");
12381 		break;
12382 	}
12383 
12384 	for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12385 		idx = i / UINT64_BIT;
12386 		offset = i % UINT64_BIT;
12387 		if (!(info.info.global_conf.valid_bit_mask[idx] &
12388 						(1ULL << offset)))
12389 			continue;
12390 		str = flowtype_to_str(i);
12391 		if (!str)
12392 			continue;
12393 		printf("Symmetric hash is %s globally for flow type %s "
12394 							"by port %d\n",
12395 			((info.info.global_conf.sym_hash_enable_mask[idx] &
12396 			(1ULL << offset)) ? "enabled" : "disabled"), str,
12397 							res->port_id);
12398 	}
12399 }
12400 
12401 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12402 	TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12403 		get_hash_global_config, "get_hash_global_config");
12404 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12405 	TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12406 		port_id, UINT16);
12407 
12408 cmdline_parse_inst_t cmd_get_hash_global_config = {
12409 	.f = cmd_get_hash_global_config_parsed,
12410 	.data = NULL,
12411 	.help_str = "get_hash_global_config <port_id>",
12412 	.tokens = {
12413 		(void *)&cmd_get_hash_global_config_all,
12414 		(void *)&cmd_get_hash_global_config_port_id,
12415 		NULL,
12416 	},
12417 };
12418 
12419 /* Set global config of hash function */
12420 struct cmd_set_hash_global_config_result {
12421 	cmdline_fixed_string_t set_hash_global_config;
12422 	portid_t port_id;
12423 	cmdline_fixed_string_t hash_func;
12424 	cmdline_fixed_string_t flow_type;
12425 	cmdline_fixed_string_t enable;
12426 };
12427 
12428 static void
12429 cmd_set_hash_global_config_parsed(void *parsed_result,
12430 				  __rte_unused struct cmdline *cl,
12431 				  __rte_unused void *data)
12432 {
12433 	struct cmd_set_hash_global_config_result *res = parsed_result;
12434 	struct rte_eth_hash_filter_info info;
12435 	uint32_t ftype, idx, offset;
12436 	int ret;
12437 
12438 	if (rte_eth_dev_filter_supported(res->port_id,
12439 				RTE_ETH_FILTER_HASH) < 0) {
12440 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12441 							res->port_id);
12442 		return;
12443 	}
12444 	memset(&info, 0, sizeof(info));
12445 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12446 	if (!strcmp(res->hash_func, "toeplitz"))
12447 		info.info.global_conf.hash_func =
12448 			RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12449 	else if (!strcmp(res->hash_func, "simple_xor"))
12450 		info.info.global_conf.hash_func =
12451 			RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12452 	else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12453 		info.info.global_conf.hash_func =
12454 			RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12455 	else if (!strcmp(res->hash_func, "default"))
12456 		info.info.global_conf.hash_func =
12457 			RTE_ETH_HASH_FUNCTION_DEFAULT;
12458 
12459 	ftype = str2flowtype(res->flow_type);
12460 	idx = ftype / UINT64_BIT;
12461 	offset = ftype % UINT64_BIT;
12462 	info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12463 	if (!strcmp(res->enable, "enable"))
12464 		info.info.global_conf.sym_hash_enable_mask[idx] |=
12465 						(1ULL << offset);
12466 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12467 					RTE_ETH_FILTER_SET, &info);
12468 	if (ret < 0)
12469 		printf("Cannot set global hash configurations by port %d\n",
12470 							res->port_id);
12471 	else
12472 		printf("Global hash configurations have been set "
12473 			"successfully by port %d\n", res->port_id);
12474 }
12475 
12476 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12477 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12478 		set_hash_global_config, "set_hash_global_config");
12479 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12480 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12481 		port_id, UINT16);
12482 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12483 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12484 		hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12485 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12486 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12487 		flow_type,
12488 		"ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12489 		"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12490 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12491 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12492 		enable, "enable#disable");
12493 
12494 cmdline_parse_inst_t cmd_set_hash_global_config = {
12495 	.f = cmd_set_hash_global_config_parsed,
12496 	.data = NULL,
12497 	.help_str = "set_hash_global_config <port_id> "
12498 		"toeplitz|simple_xor|symmetric_toeplitz|default "
12499 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12500 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12501 		"l2_payload enable|disable",
12502 	.tokens = {
12503 		(void *)&cmd_set_hash_global_config_all,
12504 		(void *)&cmd_set_hash_global_config_port_id,
12505 		(void *)&cmd_set_hash_global_config_hash_func,
12506 		(void *)&cmd_set_hash_global_config_flow_type,
12507 		(void *)&cmd_set_hash_global_config_enable,
12508 		NULL,
12509 	},
12510 };
12511 
12512 /* Set hash input set */
12513 struct cmd_set_hash_input_set_result {
12514 	cmdline_fixed_string_t set_hash_input_set;
12515 	portid_t port_id;
12516 	cmdline_fixed_string_t flow_type;
12517 	cmdline_fixed_string_t inset_field;
12518 	cmdline_fixed_string_t select;
12519 };
12520 
12521 static enum rte_eth_input_set_field
12522 str2inset(char *string)
12523 {
12524 	uint16_t i;
12525 
12526 	static const struct {
12527 		char str[32];
12528 		enum rte_eth_input_set_field inset;
12529 	} inset_table[] = {
12530 		{"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12531 		{"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12532 		{"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12533 		{"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12534 		{"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12535 		{"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12536 		{"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12537 		{"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12538 		{"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12539 		{"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12540 		{"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12541 		{"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12542 		{"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12543 		{"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12544 		{"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12545 		{"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12546 		{"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12547 		{"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12548 		{"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12549 		{"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12550 		{"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12551 		{"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12552 		{"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12553 		{"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12554 		{"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12555 		{"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12556 		{"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12557 		{"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12558 		{"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12559 		{"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12560 		{"none", RTE_ETH_INPUT_SET_NONE},
12561 	};
12562 
12563 	for (i = 0; i < RTE_DIM(inset_table); i++) {
12564 		if (!strcmp(string, inset_table[i].str))
12565 			return inset_table[i].inset;
12566 	}
12567 
12568 	return RTE_ETH_INPUT_SET_UNKNOWN;
12569 }
12570 
12571 static void
12572 cmd_set_hash_input_set_parsed(void *parsed_result,
12573 			      __rte_unused struct cmdline *cl,
12574 			      __rte_unused void *data)
12575 {
12576 	struct cmd_set_hash_input_set_result *res = parsed_result;
12577 	struct rte_eth_hash_filter_info info;
12578 
12579 	memset(&info, 0, sizeof(info));
12580 	info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12581 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12582 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12583 	info.info.input_set_conf.inset_size = 1;
12584 	if (!strcmp(res->select, "select"))
12585 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12586 	else if (!strcmp(res->select, "add"))
12587 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12588 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12589 				RTE_ETH_FILTER_SET, &info);
12590 }
12591 
12592 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12593 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12594 		set_hash_input_set, "set_hash_input_set");
12595 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12596 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12597 		port_id, UINT16);
12598 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12599 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12600 		flow_type, NULL);
12601 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12602 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12603 		inset_field,
12604 		"ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12605 		"ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12606 		"udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12607 		"sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12608 		"fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12609 		"fld-8th#none");
12610 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12611 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12612 		select, "select#add");
12613 
12614 cmdline_parse_inst_t cmd_set_hash_input_set = {
12615 	.f = cmd_set_hash_input_set_parsed,
12616 	.data = NULL,
12617 	.help_str = "set_hash_input_set <port_id> "
12618 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12619 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12620 	"ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12621 	"ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12622 	"tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12623 	"gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12624 	"fld-7th|fld-8th|none select|add",
12625 	.tokens = {
12626 		(void *)&cmd_set_hash_input_set_cmd,
12627 		(void *)&cmd_set_hash_input_set_port_id,
12628 		(void *)&cmd_set_hash_input_set_flow_type,
12629 		(void *)&cmd_set_hash_input_set_field,
12630 		(void *)&cmd_set_hash_input_set_select,
12631 		NULL,
12632 	},
12633 };
12634 
12635 /* Set flow director input set */
12636 struct cmd_set_fdir_input_set_result {
12637 	cmdline_fixed_string_t set_fdir_input_set;
12638 	portid_t port_id;
12639 	cmdline_fixed_string_t flow_type;
12640 	cmdline_fixed_string_t inset_field;
12641 	cmdline_fixed_string_t select;
12642 };
12643 
12644 static void
12645 cmd_set_fdir_input_set_parsed(void *parsed_result,
12646 	__rte_unused struct cmdline *cl,
12647 	__rte_unused void *data)
12648 {
12649 	struct cmd_set_fdir_input_set_result *res = parsed_result;
12650 	struct rte_eth_fdir_filter_info info;
12651 
12652 	memset(&info, 0, sizeof(info));
12653 	info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12654 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12655 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12656 	info.info.input_set_conf.inset_size = 1;
12657 	if (!strcmp(res->select, "select"))
12658 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12659 	else if (!strcmp(res->select, "add"))
12660 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12661 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12662 		RTE_ETH_FILTER_SET, &info);
12663 }
12664 
12665 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12666 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12667 	set_fdir_input_set, "set_fdir_input_set");
12668 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12669 	TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12670 	port_id, UINT16);
12671 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12672 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12673 	flow_type,
12674 	"ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12675 	"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12676 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12677 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12678 	inset_field,
12679 	"ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12680 	"ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12681 	"ipv6-hop-limits#udp-src-port#udp-dst-port#"
12682 	"tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12683 	"sctp-veri-tag#none");
12684 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12685 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12686 	select, "select#add");
12687 
12688 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12689 	.f = cmd_set_fdir_input_set_parsed,
12690 	.data = NULL,
12691 	.help_str = "set_fdir_input_set <port_id> "
12692 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12693 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12694 	"ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12695 	"ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12696 	"ipv6-hop-limits|udp-src-port|udp-dst-port|"
12697 	"tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12698 	"sctp-veri-tag|none select|add",
12699 	.tokens = {
12700 		(void *)&cmd_set_fdir_input_set_cmd,
12701 		(void *)&cmd_set_fdir_input_set_port_id,
12702 		(void *)&cmd_set_fdir_input_set_flow_type,
12703 		(void *)&cmd_set_fdir_input_set_field,
12704 		(void *)&cmd_set_fdir_input_set_select,
12705 		NULL,
12706 	},
12707 };
12708 
12709 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12710 struct cmd_mcast_addr_result {
12711 	cmdline_fixed_string_t mcast_addr_cmd;
12712 	cmdline_fixed_string_t what;
12713 	uint16_t port_num;
12714 	struct rte_ether_addr mc_addr;
12715 };
12716 
12717 static void cmd_mcast_addr_parsed(void *parsed_result,
12718 		__rte_unused struct cmdline *cl,
12719 		__rte_unused void *data)
12720 {
12721 	struct cmd_mcast_addr_result *res = parsed_result;
12722 
12723 	if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12724 		printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12725 		       res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12726 		       res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12727 		       res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12728 		return;
12729 	}
12730 	if (strcmp(res->what, "add") == 0)
12731 		mcast_addr_add(res->port_num, &res->mc_addr);
12732 	else
12733 		mcast_addr_remove(res->port_num, &res->mc_addr);
12734 }
12735 
12736 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12737 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12738 				 mcast_addr_cmd, "mcast_addr");
12739 cmdline_parse_token_string_t cmd_mcast_addr_what =
12740 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12741 				 "add#remove");
12742 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12743 	TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12744 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12745 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12746 
12747 cmdline_parse_inst_t cmd_mcast_addr = {
12748 	.f = cmd_mcast_addr_parsed,
12749 	.data = (void *)0,
12750 	.help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12751 		"Add/Remove multicast MAC address on port_id",
12752 	.tokens = {
12753 		(void *)&cmd_mcast_addr_cmd,
12754 		(void *)&cmd_mcast_addr_what,
12755 		(void *)&cmd_mcast_addr_portnum,
12756 		(void *)&cmd_mcast_addr_addr,
12757 		NULL,
12758 	},
12759 };
12760 
12761 /* l2 tunnel config
12762  * only support E-tag now.
12763  */
12764 
12765 /* Ether type config */
12766 struct cmd_config_l2_tunnel_eth_type_result {
12767 	cmdline_fixed_string_t port;
12768 	cmdline_fixed_string_t config;
12769 	cmdline_fixed_string_t all;
12770 	portid_t id;
12771 	cmdline_fixed_string_t l2_tunnel;
12772 	cmdline_fixed_string_t l2_tunnel_type;
12773 	cmdline_fixed_string_t eth_type;
12774 	uint16_t eth_type_val;
12775 };
12776 
12777 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12778 	TOKEN_STRING_INITIALIZER
12779 		(struct cmd_config_l2_tunnel_eth_type_result,
12780 		 port, "port");
12781 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12782 	TOKEN_STRING_INITIALIZER
12783 		(struct cmd_config_l2_tunnel_eth_type_result,
12784 		 config, "config");
12785 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12786 	TOKEN_STRING_INITIALIZER
12787 		(struct cmd_config_l2_tunnel_eth_type_result,
12788 		 all, "all");
12789 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12790 	TOKEN_NUM_INITIALIZER
12791 		(struct cmd_config_l2_tunnel_eth_type_result,
12792 		 id, UINT16);
12793 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12794 	TOKEN_STRING_INITIALIZER
12795 		(struct cmd_config_l2_tunnel_eth_type_result,
12796 		 l2_tunnel, "l2-tunnel");
12797 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12798 	TOKEN_STRING_INITIALIZER
12799 		(struct cmd_config_l2_tunnel_eth_type_result,
12800 		 l2_tunnel_type, "E-tag");
12801 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12802 	TOKEN_STRING_INITIALIZER
12803 		(struct cmd_config_l2_tunnel_eth_type_result,
12804 		 eth_type, "ether-type");
12805 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12806 	TOKEN_NUM_INITIALIZER
12807 		(struct cmd_config_l2_tunnel_eth_type_result,
12808 		 eth_type_val, UINT16);
12809 
12810 static enum rte_eth_tunnel_type
12811 str2fdir_l2_tunnel_type(char *string)
12812 {
12813 	uint32_t i = 0;
12814 
12815 	static const struct {
12816 		char str[32];
12817 		enum rte_eth_tunnel_type type;
12818 	} l2_tunnel_type_str[] = {
12819 		{"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12820 	};
12821 
12822 	for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12823 		if (!strcmp(l2_tunnel_type_str[i].str, string))
12824 			return l2_tunnel_type_str[i].type;
12825 	}
12826 	return RTE_TUNNEL_TYPE_NONE;
12827 }
12828 
12829 /* ether type config for all ports */
12830 static void
12831 cmd_config_l2_tunnel_eth_type_all_parsed
12832 	(void *parsed_result,
12833 	 __rte_unused struct cmdline *cl,
12834 	 __rte_unused void *data)
12835 {
12836 	struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12837 	struct rte_eth_l2_tunnel_conf entry;
12838 	portid_t pid;
12839 
12840 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12841 	entry.ether_type = res->eth_type_val;
12842 
12843 	RTE_ETH_FOREACH_DEV(pid) {
12844 		rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12845 	}
12846 }
12847 
12848 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12849 	.f = cmd_config_l2_tunnel_eth_type_all_parsed,
12850 	.data = NULL,
12851 	.help_str = "port config all l2-tunnel E-tag ether-type <value>",
12852 	.tokens = {
12853 		(void *)&cmd_config_l2_tunnel_eth_type_port,
12854 		(void *)&cmd_config_l2_tunnel_eth_type_config,
12855 		(void *)&cmd_config_l2_tunnel_eth_type_all_str,
12856 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12857 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12858 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12859 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12860 		NULL,
12861 	},
12862 };
12863 
12864 /* ether type config for a specific port */
12865 static void
12866 cmd_config_l2_tunnel_eth_type_specific_parsed(
12867 	void *parsed_result,
12868 	__rte_unused struct cmdline *cl,
12869 	__rte_unused void *data)
12870 {
12871 	struct cmd_config_l2_tunnel_eth_type_result *res =
12872 		 parsed_result;
12873 	struct rte_eth_l2_tunnel_conf entry;
12874 
12875 	if (port_id_is_invalid(res->id, ENABLED_WARN))
12876 		return;
12877 
12878 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12879 	entry.ether_type = res->eth_type_val;
12880 
12881 	rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12882 }
12883 
12884 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12885 	.f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12886 	.data = NULL,
12887 	.help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12888 	.tokens = {
12889 		(void *)&cmd_config_l2_tunnel_eth_type_port,
12890 		(void *)&cmd_config_l2_tunnel_eth_type_config,
12891 		(void *)&cmd_config_l2_tunnel_eth_type_id,
12892 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12893 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12894 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12895 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12896 		NULL,
12897 	},
12898 };
12899 
12900 /* Enable/disable l2 tunnel */
12901 struct cmd_config_l2_tunnel_en_dis_result {
12902 	cmdline_fixed_string_t port;
12903 	cmdline_fixed_string_t config;
12904 	cmdline_fixed_string_t all;
12905 	portid_t id;
12906 	cmdline_fixed_string_t l2_tunnel;
12907 	cmdline_fixed_string_t l2_tunnel_type;
12908 	cmdline_fixed_string_t en_dis;
12909 };
12910 
12911 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12912 	TOKEN_STRING_INITIALIZER
12913 		(struct cmd_config_l2_tunnel_en_dis_result,
12914 		 port, "port");
12915 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12916 	TOKEN_STRING_INITIALIZER
12917 		(struct cmd_config_l2_tunnel_en_dis_result,
12918 		 config, "config");
12919 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12920 	TOKEN_STRING_INITIALIZER
12921 		(struct cmd_config_l2_tunnel_en_dis_result,
12922 		 all, "all");
12923 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12924 	TOKEN_NUM_INITIALIZER
12925 		(struct cmd_config_l2_tunnel_en_dis_result,
12926 		 id, UINT16);
12927 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12928 	TOKEN_STRING_INITIALIZER
12929 		(struct cmd_config_l2_tunnel_en_dis_result,
12930 		 l2_tunnel, "l2-tunnel");
12931 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12932 	TOKEN_STRING_INITIALIZER
12933 		(struct cmd_config_l2_tunnel_en_dis_result,
12934 		 l2_tunnel_type, "E-tag");
12935 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12936 	TOKEN_STRING_INITIALIZER
12937 		(struct cmd_config_l2_tunnel_en_dis_result,
12938 		 en_dis, "enable#disable");
12939 
12940 /* enable/disable l2 tunnel for all ports */
12941 static void
12942 cmd_config_l2_tunnel_en_dis_all_parsed(
12943 	void *parsed_result,
12944 	__rte_unused struct cmdline *cl,
12945 	__rte_unused void *data)
12946 {
12947 	struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12948 	struct rte_eth_l2_tunnel_conf entry;
12949 	portid_t pid;
12950 	uint8_t en;
12951 
12952 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12953 
12954 	if (!strcmp("enable", res->en_dis))
12955 		en = 1;
12956 	else
12957 		en = 0;
12958 
12959 	RTE_ETH_FOREACH_DEV(pid) {
12960 		rte_eth_dev_l2_tunnel_offload_set(pid,
12961 						  &entry,
12962 						  ETH_L2_TUNNEL_ENABLE_MASK,
12963 						  en);
12964 	}
12965 }
12966 
12967 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12968 	.f = cmd_config_l2_tunnel_en_dis_all_parsed,
12969 	.data = NULL,
12970 	.help_str = "port config all l2-tunnel E-tag enable|disable",
12971 	.tokens = {
12972 		(void *)&cmd_config_l2_tunnel_en_dis_port,
12973 		(void *)&cmd_config_l2_tunnel_en_dis_config,
12974 		(void *)&cmd_config_l2_tunnel_en_dis_all_str,
12975 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12976 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12977 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12978 		NULL,
12979 	},
12980 };
12981 
12982 /* enable/disable l2 tunnel for a port */
12983 static void
12984 cmd_config_l2_tunnel_en_dis_specific_parsed(
12985 	void *parsed_result,
12986 	__rte_unused struct cmdline *cl,
12987 	__rte_unused void *data)
12988 {
12989 	struct cmd_config_l2_tunnel_en_dis_result *res =
12990 		parsed_result;
12991 	struct rte_eth_l2_tunnel_conf entry;
12992 
12993 	if (port_id_is_invalid(res->id, ENABLED_WARN))
12994 		return;
12995 
12996 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12997 
12998 	if (!strcmp("enable", res->en_dis))
12999 		rte_eth_dev_l2_tunnel_offload_set(res->id,
13000 						  &entry,
13001 						  ETH_L2_TUNNEL_ENABLE_MASK,
13002 						  1);
13003 	else
13004 		rte_eth_dev_l2_tunnel_offload_set(res->id,
13005 						  &entry,
13006 						  ETH_L2_TUNNEL_ENABLE_MASK,
13007 						  0);
13008 }
13009 
13010 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13011 	.f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13012 	.data = NULL,
13013 	.help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13014 	.tokens = {
13015 		(void *)&cmd_config_l2_tunnel_en_dis_port,
13016 		(void *)&cmd_config_l2_tunnel_en_dis_config,
13017 		(void *)&cmd_config_l2_tunnel_en_dis_id,
13018 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13019 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13020 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13021 		NULL,
13022 	},
13023 };
13024 
13025 /* E-tag configuration */
13026 
13027 /* Common result structure for all E-tag configuration */
13028 struct cmd_config_e_tag_result {
13029 	cmdline_fixed_string_t e_tag;
13030 	cmdline_fixed_string_t set;
13031 	cmdline_fixed_string_t insertion;
13032 	cmdline_fixed_string_t stripping;
13033 	cmdline_fixed_string_t forwarding;
13034 	cmdline_fixed_string_t filter;
13035 	cmdline_fixed_string_t add;
13036 	cmdline_fixed_string_t del;
13037 	cmdline_fixed_string_t on;
13038 	cmdline_fixed_string_t off;
13039 	cmdline_fixed_string_t on_off;
13040 	cmdline_fixed_string_t port_tag_id;
13041 	uint32_t port_tag_id_val;
13042 	cmdline_fixed_string_t e_tag_id;
13043 	uint16_t e_tag_id_val;
13044 	cmdline_fixed_string_t dst_pool;
13045 	uint8_t dst_pool_val;
13046 	cmdline_fixed_string_t port;
13047 	portid_t port_id;
13048 	cmdline_fixed_string_t vf;
13049 	uint8_t vf_id;
13050 };
13051 
13052 /* Common CLI fields for all E-tag configuration */
13053 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13054 	TOKEN_STRING_INITIALIZER
13055 		(struct cmd_config_e_tag_result,
13056 		 e_tag, "E-tag");
13057 cmdline_parse_token_string_t cmd_config_e_tag_set =
13058 	TOKEN_STRING_INITIALIZER
13059 		(struct cmd_config_e_tag_result,
13060 		 set, "set");
13061 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13062 	TOKEN_STRING_INITIALIZER
13063 		(struct cmd_config_e_tag_result,
13064 		 insertion, "insertion");
13065 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13066 	TOKEN_STRING_INITIALIZER
13067 		(struct cmd_config_e_tag_result,
13068 		 stripping, "stripping");
13069 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13070 	TOKEN_STRING_INITIALIZER
13071 		(struct cmd_config_e_tag_result,
13072 		 forwarding, "forwarding");
13073 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13074 	TOKEN_STRING_INITIALIZER
13075 		(struct cmd_config_e_tag_result,
13076 		 filter, "filter");
13077 cmdline_parse_token_string_t cmd_config_e_tag_add =
13078 	TOKEN_STRING_INITIALIZER
13079 		(struct cmd_config_e_tag_result,
13080 		 add, "add");
13081 cmdline_parse_token_string_t cmd_config_e_tag_del =
13082 	TOKEN_STRING_INITIALIZER
13083 		(struct cmd_config_e_tag_result,
13084 		 del, "del");
13085 cmdline_parse_token_string_t cmd_config_e_tag_on =
13086 	TOKEN_STRING_INITIALIZER
13087 		(struct cmd_config_e_tag_result,
13088 		 on, "on");
13089 cmdline_parse_token_string_t cmd_config_e_tag_off =
13090 	TOKEN_STRING_INITIALIZER
13091 		(struct cmd_config_e_tag_result,
13092 		 off, "off");
13093 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13094 	TOKEN_STRING_INITIALIZER
13095 		(struct cmd_config_e_tag_result,
13096 		 on_off, "on#off");
13097 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13098 	TOKEN_STRING_INITIALIZER
13099 		(struct cmd_config_e_tag_result,
13100 		 port_tag_id, "port-tag-id");
13101 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13102 	TOKEN_NUM_INITIALIZER
13103 		(struct cmd_config_e_tag_result,
13104 		 port_tag_id_val, UINT32);
13105 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13106 	TOKEN_STRING_INITIALIZER
13107 		(struct cmd_config_e_tag_result,
13108 		 e_tag_id, "e-tag-id");
13109 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13110 	TOKEN_NUM_INITIALIZER
13111 		(struct cmd_config_e_tag_result,
13112 		 e_tag_id_val, UINT16);
13113 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13114 	TOKEN_STRING_INITIALIZER
13115 		(struct cmd_config_e_tag_result,
13116 		 dst_pool, "dst-pool");
13117 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13118 	TOKEN_NUM_INITIALIZER
13119 		(struct cmd_config_e_tag_result,
13120 		 dst_pool_val, UINT8);
13121 cmdline_parse_token_string_t cmd_config_e_tag_port =
13122 	TOKEN_STRING_INITIALIZER
13123 		(struct cmd_config_e_tag_result,
13124 		 port, "port");
13125 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13126 	TOKEN_NUM_INITIALIZER
13127 		(struct cmd_config_e_tag_result,
13128 		 port_id, UINT16);
13129 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13130 	TOKEN_STRING_INITIALIZER
13131 		(struct cmd_config_e_tag_result,
13132 		 vf, "vf");
13133 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13134 	TOKEN_NUM_INITIALIZER
13135 		(struct cmd_config_e_tag_result,
13136 		 vf_id, UINT8);
13137 
13138 /* E-tag insertion configuration */
13139 static void
13140 cmd_config_e_tag_insertion_en_parsed(
13141 	void *parsed_result,
13142 	__rte_unused struct cmdline *cl,
13143 	__rte_unused void *data)
13144 {
13145 	struct cmd_config_e_tag_result *res =
13146 		parsed_result;
13147 	struct rte_eth_l2_tunnel_conf entry;
13148 
13149 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13150 		return;
13151 
13152 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13153 	entry.tunnel_id = res->port_tag_id_val;
13154 	entry.vf_id = res->vf_id;
13155 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13156 					  &entry,
13157 					  ETH_L2_TUNNEL_INSERTION_MASK,
13158 					  1);
13159 }
13160 
13161 static void
13162 cmd_config_e_tag_insertion_dis_parsed(
13163 	void *parsed_result,
13164 	__rte_unused struct cmdline *cl,
13165 	__rte_unused void *data)
13166 {
13167 	struct cmd_config_e_tag_result *res =
13168 		parsed_result;
13169 	struct rte_eth_l2_tunnel_conf entry;
13170 
13171 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13172 		return;
13173 
13174 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13175 	entry.vf_id = res->vf_id;
13176 
13177 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13178 					  &entry,
13179 					  ETH_L2_TUNNEL_INSERTION_MASK,
13180 					  0);
13181 }
13182 
13183 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13184 	.f = cmd_config_e_tag_insertion_en_parsed,
13185 	.data = NULL,
13186 	.help_str = "E-tag ... : E-tag insertion enable",
13187 	.tokens = {
13188 		(void *)&cmd_config_e_tag_e_tag,
13189 		(void *)&cmd_config_e_tag_set,
13190 		(void *)&cmd_config_e_tag_insertion,
13191 		(void *)&cmd_config_e_tag_on,
13192 		(void *)&cmd_config_e_tag_port_tag_id,
13193 		(void *)&cmd_config_e_tag_port_tag_id_val,
13194 		(void *)&cmd_config_e_tag_port,
13195 		(void *)&cmd_config_e_tag_port_id,
13196 		(void *)&cmd_config_e_tag_vf,
13197 		(void *)&cmd_config_e_tag_vf_id,
13198 		NULL,
13199 	},
13200 };
13201 
13202 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13203 	.f = cmd_config_e_tag_insertion_dis_parsed,
13204 	.data = NULL,
13205 	.help_str = "E-tag ... : E-tag insertion disable",
13206 	.tokens = {
13207 		(void *)&cmd_config_e_tag_e_tag,
13208 		(void *)&cmd_config_e_tag_set,
13209 		(void *)&cmd_config_e_tag_insertion,
13210 		(void *)&cmd_config_e_tag_off,
13211 		(void *)&cmd_config_e_tag_port,
13212 		(void *)&cmd_config_e_tag_port_id,
13213 		(void *)&cmd_config_e_tag_vf,
13214 		(void *)&cmd_config_e_tag_vf_id,
13215 		NULL,
13216 	},
13217 };
13218 
13219 /* E-tag stripping configuration */
13220 static void
13221 cmd_config_e_tag_stripping_parsed(
13222 	void *parsed_result,
13223 	__rte_unused struct cmdline *cl,
13224 	__rte_unused void *data)
13225 {
13226 	struct cmd_config_e_tag_result *res =
13227 		parsed_result;
13228 	struct rte_eth_l2_tunnel_conf entry;
13229 
13230 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13231 		return;
13232 
13233 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13234 
13235 	if (!strcmp(res->on_off, "on"))
13236 		rte_eth_dev_l2_tunnel_offload_set
13237 			(res->port_id,
13238 			 &entry,
13239 			 ETH_L2_TUNNEL_STRIPPING_MASK,
13240 			 1);
13241 	else
13242 		rte_eth_dev_l2_tunnel_offload_set
13243 			(res->port_id,
13244 			 &entry,
13245 			 ETH_L2_TUNNEL_STRIPPING_MASK,
13246 			 0);
13247 }
13248 
13249 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13250 	.f = cmd_config_e_tag_stripping_parsed,
13251 	.data = NULL,
13252 	.help_str = "E-tag ... : E-tag stripping enable/disable",
13253 	.tokens = {
13254 		(void *)&cmd_config_e_tag_e_tag,
13255 		(void *)&cmd_config_e_tag_set,
13256 		(void *)&cmd_config_e_tag_stripping,
13257 		(void *)&cmd_config_e_tag_on_off,
13258 		(void *)&cmd_config_e_tag_port,
13259 		(void *)&cmd_config_e_tag_port_id,
13260 		NULL,
13261 	},
13262 };
13263 
13264 /* E-tag forwarding configuration */
13265 static void
13266 cmd_config_e_tag_forwarding_parsed(
13267 	void *parsed_result,
13268 	__rte_unused struct cmdline *cl,
13269 	__rte_unused void *data)
13270 {
13271 	struct cmd_config_e_tag_result *res = parsed_result;
13272 	struct rte_eth_l2_tunnel_conf entry;
13273 
13274 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13275 		return;
13276 
13277 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13278 
13279 	if (!strcmp(res->on_off, "on"))
13280 		rte_eth_dev_l2_tunnel_offload_set
13281 			(res->port_id,
13282 			 &entry,
13283 			 ETH_L2_TUNNEL_FORWARDING_MASK,
13284 			 1);
13285 	else
13286 		rte_eth_dev_l2_tunnel_offload_set
13287 			(res->port_id,
13288 			 &entry,
13289 			 ETH_L2_TUNNEL_FORWARDING_MASK,
13290 			 0);
13291 }
13292 
13293 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13294 	.f = cmd_config_e_tag_forwarding_parsed,
13295 	.data = NULL,
13296 	.help_str = "E-tag ... : E-tag forwarding enable/disable",
13297 	.tokens = {
13298 		(void *)&cmd_config_e_tag_e_tag,
13299 		(void *)&cmd_config_e_tag_set,
13300 		(void *)&cmd_config_e_tag_forwarding,
13301 		(void *)&cmd_config_e_tag_on_off,
13302 		(void *)&cmd_config_e_tag_port,
13303 		(void *)&cmd_config_e_tag_port_id,
13304 		NULL,
13305 	},
13306 };
13307 
13308 /* E-tag filter configuration */
13309 static void
13310 cmd_config_e_tag_filter_add_parsed(
13311 	void *parsed_result,
13312 	__rte_unused struct cmdline *cl,
13313 	__rte_unused void *data)
13314 {
13315 	struct cmd_config_e_tag_result *res = parsed_result;
13316 	struct rte_eth_l2_tunnel_conf entry;
13317 	int ret = 0;
13318 
13319 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13320 		return;
13321 
13322 	if (res->e_tag_id_val > 0x3fff) {
13323 		printf("e-tag-id must be equal or less than 0x3fff.\n");
13324 		return;
13325 	}
13326 
13327 	ret = rte_eth_dev_filter_supported(res->port_id,
13328 					   RTE_ETH_FILTER_L2_TUNNEL);
13329 	if (ret < 0) {
13330 		printf("E-tag filter is not supported on port %u.\n",
13331 		       res->port_id);
13332 		return;
13333 	}
13334 
13335 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13336 	entry.tunnel_id = res->e_tag_id_val;
13337 	entry.pool = res->dst_pool_val;
13338 
13339 	ret = rte_eth_dev_filter_ctrl(res->port_id,
13340 				      RTE_ETH_FILTER_L2_TUNNEL,
13341 				      RTE_ETH_FILTER_ADD,
13342 				      &entry);
13343 	if (ret < 0)
13344 		printf("E-tag filter programming error: (%s)\n",
13345 		       strerror(-ret));
13346 }
13347 
13348 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13349 	.f = cmd_config_e_tag_filter_add_parsed,
13350 	.data = NULL,
13351 	.help_str = "E-tag ... : E-tag filter add",
13352 	.tokens = {
13353 		(void *)&cmd_config_e_tag_e_tag,
13354 		(void *)&cmd_config_e_tag_set,
13355 		(void *)&cmd_config_e_tag_filter,
13356 		(void *)&cmd_config_e_tag_add,
13357 		(void *)&cmd_config_e_tag_e_tag_id,
13358 		(void *)&cmd_config_e_tag_e_tag_id_val,
13359 		(void *)&cmd_config_e_tag_dst_pool,
13360 		(void *)&cmd_config_e_tag_dst_pool_val,
13361 		(void *)&cmd_config_e_tag_port,
13362 		(void *)&cmd_config_e_tag_port_id,
13363 		NULL,
13364 	},
13365 };
13366 
13367 static void
13368 cmd_config_e_tag_filter_del_parsed(
13369 	void *parsed_result,
13370 	__rte_unused struct cmdline *cl,
13371 	__rte_unused void *data)
13372 {
13373 	struct cmd_config_e_tag_result *res = parsed_result;
13374 	struct rte_eth_l2_tunnel_conf entry;
13375 	int ret = 0;
13376 
13377 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13378 		return;
13379 
13380 	if (res->e_tag_id_val > 0x3fff) {
13381 		printf("e-tag-id must be less than 0x3fff.\n");
13382 		return;
13383 	}
13384 
13385 	ret = rte_eth_dev_filter_supported(res->port_id,
13386 					   RTE_ETH_FILTER_L2_TUNNEL);
13387 	if (ret < 0) {
13388 		printf("E-tag filter is not supported on port %u.\n",
13389 		       res->port_id);
13390 		return;
13391 	}
13392 
13393 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13394 	entry.tunnel_id = res->e_tag_id_val;
13395 
13396 	ret = rte_eth_dev_filter_ctrl(res->port_id,
13397 				      RTE_ETH_FILTER_L2_TUNNEL,
13398 				      RTE_ETH_FILTER_DELETE,
13399 				      &entry);
13400 	if (ret < 0)
13401 		printf("E-tag filter programming error: (%s)\n",
13402 		       strerror(-ret));
13403 }
13404 
13405 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13406 	.f = cmd_config_e_tag_filter_del_parsed,
13407 	.data = NULL,
13408 	.help_str = "E-tag ... : E-tag filter delete",
13409 	.tokens = {
13410 		(void *)&cmd_config_e_tag_e_tag,
13411 		(void *)&cmd_config_e_tag_set,
13412 		(void *)&cmd_config_e_tag_filter,
13413 		(void *)&cmd_config_e_tag_del,
13414 		(void *)&cmd_config_e_tag_e_tag_id,
13415 		(void *)&cmd_config_e_tag_e_tag_id_val,
13416 		(void *)&cmd_config_e_tag_port,
13417 		(void *)&cmd_config_e_tag_port_id,
13418 		NULL,
13419 	},
13420 };
13421 
13422 /* vf vlan anti spoof configuration */
13423 
13424 /* Common result structure for vf vlan anti spoof */
13425 struct cmd_vf_vlan_anti_spoof_result {
13426 	cmdline_fixed_string_t set;
13427 	cmdline_fixed_string_t vf;
13428 	cmdline_fixed_string_t vlan;
13429 	cmdline_fixed_string_t antispoof;
13430 	portid_t port_id;
13431 	uint32_t vf_id;
13432 	cmdline_fixed_string_t on_off;
13433 };
13434 
13435 /* Common CLI fields for vf vlan anti spoof enable disable */
13436 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13437 	TOKEN_STRING_INITIALIZER
13438 		(struct cmd_vf_vlan_anti_spoof_result,
13439 		 set, "set");
13440 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13441 	TOKEN_STRING_INITIALIZER
13442 		(struct cmd_vf_vlan_anti_spoof_result,
13443 		 vf, "vf");
13444 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13445 	TOKEN_STRING_INITIALIZER
13446 		(struct cmd_vf_vlan_anti_spoof_result,
13447 		 vlan, "vlan");
13448 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13449 	TOKEN_STRING_INITIALIZER
13450 		(struct cmd_vf_vlan_anti_spoof_result,
13451 		 antispoof, "antispoof");
13452 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13453 	TOKEN_NUM_INITIALIZER
13454 		(struct cmd_vf_vlan_anti_spoof_result,
13455 		 port_id, UINT16);
13456 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13457 	TOKEN_NUM_INITIALIZER
13458 		(struct cmd_vf_vlan_anti_spoof_result,
13459 		 vf_id, UINT32);
13460 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13461 	TOKEN_STRING_INITIALIZER
13462 		(struct cmd_vf_vlan_anti_spoof_result,
13463 		 on_off, "on#off");
13464 
13465 static void
13466 cmd_set_vf_vlan_anti_spoof_parsed(
13467 	void *parsed_result,
13468 	__rte_unused struct cmdline *cl,
13469 	__rte_unused void *data)
13470 {
13471 	struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13472 	int ret = -ENOTSUP;
13473 
13474 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13475 
13476 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13477 		return;
13478 
13479 #ifdef RTE_LIBRTE_IXGBE_PMD
13480 	if (ret == -ENOTSUP)
13481 		ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13482 				res->vf_id, is_on);
13483 #endif
13484 #ifdef RTE_LIBRTE_I40E_PMD
13485 	if (ret == -ENOTSUP)
13486 		ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13487 				res->vf_id, is_on);
13488 #endif
13489 #ifdef RTE_LIBRTE_BNXT_PMD
13490 	if (ret == -ENOTSUP)
13491 		ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13492 				res->vf_id, is_on);
13493 #endif
13494 
13495 	switch (ret) {
13496 	case 0:
13497 		break;
13498 	case -EINVAL:
13499 		printf("invalid vf_id %d\n", res->vf_id);
13500 		break;
13501 	case -ENODEV:
13502 		printf("invalid port_id %d\n", res->port_id);
13503 		break;
13504 	case -ENOTSUP:
13505 		printf("function not implemented\n");
13506 		break;
13507 	default:
13508 		printf("programming error: (%s)\n", strerror(-ret));
13509 	}
13510 }
13511 
13512 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13513 	.f = cmd_set_vf_vlan_anti_spoof_parsed,
13514 	.data = NULL,
13515 	.help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13516 	.tokens = {
13517 		(void *)&cmd_vf_vlan_anti_spoof_set,
13518 		(void *)&cmd_vf_vlan_anti_spoof_vf,
13519 		(void *)&cmd_vf_vlan_anti_spoof_vlan,
13520 		(void *)&cmd_vf_vlan_anti_spoof_antispoof,
13521 		(void *)&cmd_vf_vlan_anti_spoof_port_id,
13522 		(void *)&cmd_vf_vlan_anti_spoof_vf_id,
13523 		(void *)&cmd_vf_vlan_anti_spoof_on_off,
13524 		NULL,
13525 	},
13526 };
13527 
13528 /* vf mac anti spoof configuration */
13529 
13530 /* Common result structure for vf mac anti spoof */
13531 struct cmd_vf_mac_anti_spoof_result {
13532 	cmdline_fixed_string_t set;
13533 	cmdline_fixed_string_t vf;
13534 	cmdline_fixed_string_t mac;
13535 	cmdline_fixed_string_t antispoof;
13536 	portid_t port_id;
13537 	uint32_t vf_id;
13538 	cmdline_fixed_string_t on_off;
13539 };
13540 
13541 /* Common CLI fields for vf mac anti spoof enable disable */
13542 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13543 	TOKEN_STRING_INITIALIZER
13544 		(struct cmd_vf_mac_anti_spoof_result,
13545 		 set, "set");
13546 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13547 	TOKEN_STRING_INITIALIZER
13548 		(struct cmd_vf_mac_anti_spoof_result,
13549 		 vf, "vf");
13550 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13551 	TOKEN_STRING_INITIALIZER
13552 		(struct cmd_vf_mac_anti_spoof_result,
13553 		 mac, "mac");
13554 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13555 	TOKEN_STRING_INITIALIZER
13556 		(struct cmd_vf_mac_anti_spoof_result,
13557 		 antispoof, "antispoof");
13558 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13559 	TOKEN_NUM_INITIALIZER
13560 		(struct cmd_vf_mac_anti_spoof_result,
13561 		 port_id, UINT16);
13562 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13563 	TOKEN_NUM_INITIALIZER
13564 		(struct cmd_vf_mac_anti_spoof_result,
13565 		 vf_id, UINT32);
13566 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13567 	TOKEN_STRING_INITIALIZER
13568 		(struct cmd_vf_mac_anti_spoof_result,
13569 		 on_off, "on#off");
13570 
13571 static void
13572 cmd_set_vf_mac_anti_spoof_parsed(
13573 	void *parsed_result,
13574 	__rte_unused struct cmdline *cl,
13575 	__rte_unused void *data)
13576 {
13577 	struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13578 	int ret = -ENOTSUP;
13579 
13580 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13581 
13582 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13583 		return;
13584 
13585 #ifdef RTE_LIBRTE_IXGBE_PMD
13586 	if (ret == -ENOTSUP)
13587 		ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13588 			res->vf_id, is_on);
13589 #endif
13590 #ifdef RTE_LIBRTE_I40E_PMD
13591 	if (ret == -ENOTSUP)
13592 		ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13593 			res->vf_id, is_on);
13594 #endif
13595 #ifdef RTE_LIBRTE_BNXT_PMD
13596 	if (ret == -ENOTSUP)
13597 		ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13598 			res->vf_id, is_on);
13599 #endif
13600 
13601 	switch (ret) {
13602 	case 0:
13603 		break;
13604 	case -EINVAL:
13605 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13606 		break;
13607 	case -ENODEV:
13608 		printf("invalid port_id %d\n", res->port_id);
13609 		break;
13610 	case -ENOTSUP:
13611 		printf("function not implemented\n");
13612 		break;
13613 	default:
13614 		printf("programming error: (%s)\n", strerror(-ret));
13615 	}
13616 }
13617 
13618 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13619 	.f = cmd_set_vf_mac_anti_spoof_parsed,
13620 	.data = NULL,
13621 	.help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13622 	.tokens = {
13623 		(void *)&cmd_vf_mac_anti_spoof_set,
13624 		(void *)&cmd_vf_mac_anti_spoof_vf,
13625 		(void *)&cmd_vf_mac_anti_spoof_mac,
13626 		(void *)&cmd_vf_mac_anti_spoof_antispoof,
13627 		(void *)&cmd_vf_mac_anti_spoof_port_id,
13628 		(void *)&cmd_vf_mac_anti_spoof_vf_id,
13629 		(void *)&cmd_vf_mac_anti_spoof_on_off,
13630 		NULL,
13631 	},
13632 };
13633 
13634 /* vf vlan strip queue configuration */
13635 
13636 /* Common result structure for vf mac anti spoof */
13637 struct cmd_vf_vlan_stripq_result {
13638 	cmdline_fixed_string_t set;
13639 	cmdline_fixed_string_t vf;
13640 	cmdline_fixed_string_t vlan;
13641 	cmdline_fixed_string_t stripq;
13642 	portid_t port_id;
13643 	uint16_t vf_id;
13644 	cmdline_fixed_string_t on_off;
13645 };
13646 
13647 /* Common CLI fields for vf vlan strip enable disable */
13648 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13649 	TOKEN_STRING_INITIALIZER
13650 		(struct cmd_vf_vlan_stripq_result,
13651 		 set, "set");
13652 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13653 	TOKEN_STRING_INITIALIZER
13654 		(struct cmd_vf_vlan_stripq_result,
13655 		 vf, "vf");
13656 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13657 	TOKEN_STRING_INITIALIZER
13658 		(struct cmd_vf_vlan_stripq_result,
13659 		 vlan, "vlan");
13660 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13661 	TOKEN_STRING_INITIALIZER
13662 		(struct cmd_vf_vlan_stripq_result,
13663 		 stripq, "stripq");
13664 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13665 	TOKEN_NUM_INITIALIZER
13666 		(struct cmd_vf_vlan_stripq_result,
13667 		 port_id, UINT16);
13668 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13669 	TOKEN_NUM_INITIALIZER
13670 		(struct cmd_vf_vlan_stripq_result,
13671 		 vf_id, UINT16);
13672 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13673 	TOKEN_STRING_INITIALIZER
13674 		(struct cmd_vf_vlan_stripq_result,
13675 		 on_off, "on#off");
13676 
13677 static void
13678 cmd_set_vf_vlan_stripq_parsed(
13679 	void *parsed_result,
13680 	__rte_unused struct cmdline *cl,
13681 	__rte_unused void *data)
13682 {
13683 	struct cmd_vf_vlan_stripq_result *res = parsed_result;
13684 	int ret = -ENOTSUP;
13685 
13686 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13687 
13688 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13689 		return;
13690 
13691 #ifdef RTE_LIBRTE_IXGBE_PMD
13692 	if (ret == -ENOTSUP)
13693 		ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13694 			res->vf_id, is_on);
13695 #endif
13696 #ifdef RTE_LIBRTE_I40E_PMD
13697 	if (ret == -ENOTSUP)
13698 		ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13699 			res->vf_id, is_on);
13700 #endif
13701 #ifdef RTE_LIBRTE_BNXT_PMD
13702 	if (ret == -ENOTSUP)
13703 		ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13704 			res->vf_id, is_on);
13705 #endif
13706 
13707 	switch (ret) {
13708 	case 0:
13709 		break;
13710 	case -EINVAL:
13711 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13712 		break;
13713 	case -ENODEV:
13714 		printf("invalid port_id %d\n", res->port_id);
13715 		break;
13716 	case -ENOTSUP:
13717 		printf("function not implemented\n");
13718 		break;
13719 	default:
13720 		printf("programming error: (%s)\n", strerror(-ret));
13721 	}
13722 }
13723 
13724 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13725 	.f = cmd_set_vf_vlan_stripq_parsed,
13726 	.data = NULL,
13727 	.help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13728 	.tokens = {
13729 		(void *)&cmd_vf_vlan_stripq_set,
13730 		(void *)&cmd_vf_vlan_stripq_vf,
13731 		(void *)&cmd_vf_vlan_stripq_vlan,
13732 		(void *)&cmd_vf_vlan_stripq_stripq,
13733 		(void *)&cmd_vf_vlan_stripq_port_id,
13734 		(void *)&cmd_vf_vlan_stripq_vf_id,
13735 		(void *)&cmd_vf_vlan_stripq_on_off,
13736 		NULL,
13737 	},
13738 };
13739 
13740 /* vf vlan insert configuration */
13741 
13742 /* Common result structure for vf vlan insert */
13743 struct cmd_vf_vlan_insert_result {
13744 	cmdline_fixed_string_t set;
13745 	cmdline_fixed_string_t vf;
13746 	cmdline_fixed_string_t vlan;
13747 	cmdline_fixed_string_t insert;
13748 	portid_t port_id;
13749 	uint16_t vf_id;
13750 	uint16_t vlan_id;
13751 };
13752 
13753 /* Common CLI fields for vf vlan insert enable disable */
13754 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13755 	TOKEN_STRING_INITIALIZER
13756 		(struct cmd_vf_vlan_insert_result,
13757 		 set, "set");
13758 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13759 	TOKEN_STRING_INITIALIZER
13760 		(struct cmd_vf_vlan_insert_result,
13761 		 vf, "vf");
13762 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13763 	TOKEN_STRING_INITIALIZER
13764 		(struct cmd_vf_vlan_insert_result,
13765 		 vlan, "vlan");
13766 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13767 	TOKEN_STRING_INITIALIZER
13768 		(struct cmd_vf_vlan_insert_result,
13769 		 insert, "insert");
13770 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13771 	TOKEN_NUM_INITIALIZER
13772 		(struct cmd_vf_vlan_insert_result,
13773 		 port_id, UINT16);
13774 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13775 	TOKEN_NUM_INITIALIZER
13776 		(struct cmd_vf_vlan_insert_result,
13777 		 vf_id, UINT16);
13778 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13779 	TOKEN_NUM_INITIALIZER
13780 		(struct cmd_vf_vlan_insert_result,
13781 		 vlan_id, UINT16);
13782 
13783 static void
13784 cmd_set_vf_vlan_insert_parsed(
13785 	void *parsed_result,
13786 	__rte_unused struct cmdline *cl,
13787 	__rte_unused void *data)
13788 {
13789 	struct cmd_vf_vlan_insert_result *res = parsed_result;
13790 	int ret = -ENOTSUP;
13791 
13792 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13793 		return;
13794 
13795 #ifdef RTE_LIBRTE_IXGBE_PMD
13796 	if (ret == -ENOTSUP)
13797 		ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13798 			res->vlan_id);
13799 #endif
13800 #ifdef RTE_LIBRTE_I40E_PMD
13801 	if (ret == -ENOTSUP)
13802 		ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13803 			res->vlan_id);
13804 #endif
13805 #ifdef RTE_LIBRTE_BNXT_PMD
13806 	if (ret == -ENOTSUP)
13807 		ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13808 			res->vlan_id);
13809 #endif
13810 
13811 	switch (ret) {
13812 	case 0:
13813 		break;
13814 	case -EINVAL:
13815 		printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13816 		break;
13817 	case -ENODEV:
13818 		printf("invalid port_id %d\n", res->port_id);
13819 		break;
13820 	case -ENOTSUP:
13821 		printf("function not implemented\n");
13822 		break;
13823 	default:
13824 		printf("programming error: (%s)\n", strerror(-ret));
13825 	}
13826 }
13827 
13828 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13829 	.f = cmd_set_vf_vlan_insert_parsed,
13830 	.data = NULL,
13831 	.help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13832 	.tokens = {
13833 		(void *)&cmd_vf_vlan_insert_set,
13834 		(void *)&cmd_vf_vlan_insert_vf,
13835 		(void *)&cmd_vf_vlan_insert_vlan,
13836 		(void *)&cmd_vf_vlan_insert_insert,
13837 		(void *)&cmd_vf_vlan_insert_port_id,
13838 		(void *)&cmd_vf_vlan_insert_vf_id,
13839 		(void *)&cmd_vf_vlan_insert_vlan_id,
13840 		NULL,
13841 	},
13842 };
13843 
13844 /* tx loopback configuration */
13845 
13846 /* Common result structure for tx loopback */
13847 struct cmd_tx_loopback_result {
13848 	cmdline_fixed_string_t set;
13849 	cmdline_fixed_string_t tx;
13850 	cmdline_fixed_string_t loopback;
13851 	portid_t port_id;
13852 	cmdline_fixed_string_t on_off;
13853 };
13854 
13855 /* Common CLI fields for tx loopback enable disable */
13856 cmdline_parse_token_string_t cmd_tx_loopback_set =
13857 	TOKEN_STRING_INITIALIZER
13858 		(struct cmd_tx_loopback_result,
13859 		 set, "set");
13860 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13861 	TOKEN_STRING_INITIALIZER
13862 		(struct cmd_tx_loopback_result,
13863 		 tx, "tx");
13864 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13865 	TOKEN_STRING_INITIALIZER
13866 		(struct cmd_tx_loopback_result,
13867 		 loopback, "loopback");
13868 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13869 	TOKEN_NUM_INITIALIZER
13870 		(struct cmd_tx_loopback_result,
13871 		 port_id, UINT16);
13872 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13873 	TOKEN_STRING_INITIALIZER
13874 		(struct cmd_tx_loopback_result,
13875 		 on_off, "on#off");
13876 
13877 static void
13878 cmd_set_tx_loopback_parsed(
13879 	void *parsed_result,
13880 	__rte_unused struct cmdline *cl,
13881 	__rte_unused void *data)
13882 {
13883 	struct cmd_tx_loopback_result *res = parsed_result;
13884 	int ret = -ENOTSUP;
13885 
13886 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13887 
13888 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13889 		return;
13890 
13891 #ifdef RTE_LIBRTE_IXGBE_PMD
13892 	if (ret == -ENOTSUP)
13893 		ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13894 #endif
13895 #ifdef RTE_LIBRTE_I40E_PMD
13896 	if (ret == -ENOTSUP)
13897 		ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13898 #endif
13899 #ifdef RTE_LIBRTE_BNXT_PMD
13900 	if (ret == -ENOTSUP)
13901 		ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13902 #endif
13903 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13904 	if (ret == -ENOTSUP)
13905 		ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13906 #endif
13907 
13908 	switch (ret) {
13909 	case 0:
13910 		break;
13911 	case -EINVAL:
13912 		printf("invalid is_on %d\n", is_on);
13913 		break;
13914 	case -ENODEV:
13915 		printf("invalid port_id %d\n", res->port_id);
13916 		break;
13917 	case -ENOTSUP:
13918 		printf("function not implemented\n");
13919 		break;
13920 	default:
13921 		printf("programming error: (%s)\n", strerror(-ret));
13922 	}
13923 }
13924 
13925 cmdline_parse_inst_t cmd_set_tx_loopback = {
13926 	.f = cmd_set_tx_loopback_parsed,
13927 	.data = NULL,
13928 	.help_str = "set tx loopback <port_id> on|off",
13929 	.tokens = {
13930 		(void *)&cmd_tx_loopback_set,
13931 		(void *)&cmd_tx_loopback_tx,
13932 		(void *)&cmd_tx_loopback_loopback,
13933 		(void *)&cmd_tx_loopback_port_id,
13934 		(void *)&cmd_tx_loopback_on_off,
13935 		NULL,
13936 	},
13937 };
13938 
13939 /* all queues drop enable configuration */
13940 
13941 /* Common result structure for all queues drop enable */
13942 struct cmd_all_queues_drop_en_result {
13943 	cmdline_fixed_string_t set;
13944 	cmdline_fixed_string_t all;
13945 	cmdline_fixed_string_t queues;
13946 	cmdline_fixed_string_t drop;
13947 	portid_t port_id;
13948 	cmdline_fixed_string_t on_off;
13949 };
13950 
13951 /* Common CLI fields for tx loopback enable disable */
13952 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13953 	TOKEN_STRING_INITIALIZER
13954 		(struct cmd_all_queues_drop_en_result,
13955 		 set, "set");
13956 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13957 	TOKEN_STRING_INITIALIZER
13958 		(struct cmd_all_queues_drop_en_result,
13959 		 all, "all");
13960 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13961 	TOKEN_STRING_INITIALIZER
13962 		(struct cmd_all_queues_drop_en_result,
13963 		 queues, "queues");
13964 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13965 	TOKEN_STRING_INITIALIZER
13966 		(struct cmd_all_queues_drop_en_result,
13967 		 drop, "drop");
13968 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13969 	TOKEN_NUM_INITIALIZER
13970 		(struct cmd_all_queues_drop_en_result,
13971 		 port_id, UINT16);
13972 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13973 	TOKEN_STRING_INITIALIZER
13974 		(struct cmd_all_queues_drop_en_result,
13975 		 on_off, "on#off");
13976 
13977 static void
13978 cmd_set_all_queues_drop_en_parsed(
13979 	void *parsed_result,
13980 	__rte_unused struct cmdline *cl,
13981 	__rte_unused void *data)
13982 {
13983 	struct cmd_all_queues_drop_en_result *res = parsed_result;
13984 	int ret = -ENOTSUP;
13985 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13986 
13987 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13988 		return;
13989 
13990 #ifdef RTE_LIBRTE_IXGBE_PMD
13991 	if (ret == -ENOTSUP)
13992 		ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13993 #endif
13994 #ifdef RTE_LIBRTE_BNXT_PMD
13995 	if (ret == -ENOTSUP)
13996 		ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13997 #endif
13998 	switch (ret) {
13999 	case 0:
14000 		break;
14001 	case -EINVAL:
14002 		printf("invalid is_on %d\n", is_on);
14003 		break;
14004 	case -ENODEV:
14005 		printf("invalid port_id %d\n", res->port_id);
14006 		break;
14007 	case -ENOTSUP:
14008 		printf("function not implemented\n");
14009 		break;
14010 	default:
14011 		printf("programming error: (%s)\n", strerror(-ret));
14012 	}
14013 }
14014 
14015 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14016 	.f = cmd_set_all_queues_drop_en_parsed,
14017 	.data = NULL,
14018 	.help_str = "set all queues drop <port_id> on|off",
14019 	.tokens = {
14020 		(void *)&cmd_all_queues_drop_en_set,
14021 		(void *)&cmd_all_queues_drop_en_all,
14022 		(void *)&cmd_all_queues_drop_en_queues,
14023 		(void *)&cmd_all_queues_drop_en_drop,
14024 		(void *)&cmd_all_queues_drop_en_port_id,
14025 		(void *)&cmd_all_queues_drop_en_on_off,
14026 		NULL,
14027 	},
14028 };
14029 
14030 /* vf split drop enable configuration */
14031 
14032 /* Common result structure for vf split drop enable */
14033 struct cmd_vf_split_drop_en_result {
14034 	cmdline_fixed_string_t set;
14035 	cmdline_fixed_string_t vf;
14036 	cmdline_fixed_string_t split;
14037 	cmdline_fixed_string_t drop;
14038 	portid_t port_id;
14039 	uint16_t vf_id;
14040 	cmdline_fixed_string_t on_off;
14041 };
14042 
14043 /* Common CLI fields for vf split drop enable disable */
14044 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14045 	TOKEN_STRING_INITIALIZER
14046 		(struct cmd_vf_split_drop_en_result,
14047 		 set, "set");
14048 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14049 	TOKEN_STRING_INITIALIZER
14050 		(struct cmd_vf_split_drop_en_result,
14051 		 vf, "vf");
14052 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14053 	TOKEN_STRING_INITIALIZER
14054 		(struct cmd_vf_split_drop_en_result,
14055 		 split, "split");
14056 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14057 	TOKEN_STRING_INITIALIZER
14058 		(struct cmd_vf_split_drop_en_result,
14059 		 drop, "drop");
14060 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14061 	TOKEN_NUM_INITIALIZER
14062 		(struct cmd_vf_split_drop_en_result,
14063 		 port_id, UINT16);
14064 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14065 	TOKEN_NUM_INITIALIZER
14066 		(struct cmd_vf_split_drop_en_result,
14067 		 vf_id, UINT16);
14068 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14069 	TOKEN_STRING_INITIALIZER
14070 		(struct cmd_vf_split_drop_en_result,
14071 		 on_off, "on#off");
14072 
14073 static void
14074 cmd_set_vf_split_drop_en_parsed(
14075 	void *parsed_result,
14076 	__rte_unused struct cmdline *cl,
14077 	__rte_unused void *data)
14078 {
14079 	struct cmd_vf_split_drop_en_result *res = parsed_result;
14080 	int ret = -ENOTSUP;
14081 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14082 
14083 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14084 		return;
14085 
14086 #ifdef RTE_LIBRTE_IXGBE_PMD
14087 	ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14088 			is_on);
14089 #endif
14090 	switch (ret) {
14091 	case 0:
14092 		break;
14093 	case -EINVAL:
14094 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14095 		break;
14096 	case -ENODEV:
14097 		printf("invalid port_id %d\n", res->port_id);
14098 		break;
14099 	case -ENOTSUP:
14100 		printf("not supported on port %d\n", res->port_id);
14101 		break;
14102 	default:
14103 		printf("programming error: (%s)\n", strerror(-ret));
14104 	}
14105 }
14106 
14107 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14108 	.f = cmd_set_vf_split_drop_en_parsed,
14109 	.data = NULL,
14110 	.help_str = "set vf split drop <port_id> <vf_id> on|off",
14111 	.tokens = {
14112 		(void *)&cmd_vf_split_drop_en_set,
14113 		(void *)&cmd_vf_split_drop_en_vf,
14114 		(void *)&cmd_vf_split_drop_en_split,
14115 		(void *)&cmd_vf_split_drop_en_drop,
14116 		(void *)&cmd_vf_split_drop_en_port_id,
14117 		(void *)&cmd_vf_split_drop_en_vf_id,
14118 		(void *)&cmd_vf_split_drop_en_on_off,
14119 		NULL,
14120 	},
14121 };
14122 
14123 /* vf mac address configuration */
14124 
14125 /* Common result structure for vf mac address */
14126 struct cmd_set_vf_mac_addr_result {
14127 	cmdline_fixed_string_t set;
14128 	cmdline_fixed_string_t vf;
14129 	cmdline_fixed_string_t mac;
14130 	cmdline_fixed_string_t addr;
14131 	portid_t port_id;
14132 	uint16_t vf_id;
14133 	struct rte_ether_addr mac_addr;
14134 
14135 };
14136 
14137 /* Common CLI fields for vf split drop enable disable */
14138 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14139 	TOKEN_STRING_INITIALIZER
14140 		(struct cmd_set_vf_mac_addr_result,
14141 		 set, "set");
14142 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14143 	TOKEN_STRING_INITIALIZER
14144 		(struct cmd_set_vf_mac_addr_result,
14145 		 vf, "vf");
14146 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14147 	TOKEN_STRING_INITIALIZER
14148 		(struct cmd_set_vf_mac_addr_result,
14149 		 mac, "mac");
14150 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14151 	TOKEN_STRING_INITIALIZER
14152 		(struct cmd_set_vf_mac_addr_result,
14153 		 addr, "addr");
14154 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14155 	TOKEN_NUM_INITIALIZER
14156 		(struct cmd_set_vf_mac_addr_result,
14157 		 port_id, UINT16);
14158 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14159 	TOKEN_NUM_INITIALIZER
14160 		(struct cmd_set_vf_mac_addr_result,
14161 		 vf_id, UINT16);
14162 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14163 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14164 		 mac_addr);
14165 
14166 static void
14167 cmd_set_vf_mac_addr_parsed(
14168 	void *parsed_result,
14169 	__rte_unused struct cmdline *cl,
14170 	__rte_unused void *data)
14171 {
14172 	struct cmd_set_vf_mac_addr_result *res = parsed_result;
14173 	int ret = -ENOTSUP;
14174 
14175 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14176 		return;
14177 
14178 #ifdef RTE_LIBRTE_IXGBE_PMD
14179 	if (ret == -ENOTSUP)
14180 		ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14181 				&res->mac_addr);
14182 #endif
14183 #ifdef RTE_LIBRTE_I40E_PMD
14184 	if (ret == -ENOTSUP)
14185 		ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14186 				&res->mac_addr);
14187 #endif
14188 #ifdef RTE_LIBRTE_BNXT_PMD
14189 	if (ret == -ENOTSUP)
14190 		ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14191 				&res->mac_addr);
14192 #endif
14193 
14194 	switch (ret) {
14195 	case 0:
14196 		break;
14197 	case -EINVAL:
14198 		printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14199 		break;
14200 	case -ENODEV:
14201 		printf("invalid port_id %d\n", res->port_id);
14202 		break;
14203 	case -ENOTSUP:
14204 		printf("function not implemented\n");
14205 		break;
14206 	default:
14207 		printf("programming error: (%s)\n", strerror(-ret));
14208 	}
14209 }
14210 
14211 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14212 	.f = cmd_set_vf_mac_addr_parsed,
14213 	.data = NULL,
14214 	.help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14215 	.tokens = {
14216 		(void *)&cmd_set_vf_mac_addr_set,
14217 		(void *)&cmd_set_vf_mac_addr_vf,
14218 		(void *)&cmd_set_vf_mac_addr_mac,
14219 		(void *)&cmd_set_vf_mac_addr_addr,
14220 		(void *)&cmd_set_vf_mac_addr_port_id,
14221 		(void *)&cmd_set_vf_mac_addr_vf_id,
14222 		(void *)&cmd_set_vf_mac_addr_mac_addr,
14223 		NULL,
14224 	},
14225 };
14226 
14227 /* MACsec configuration */
14228 
14229 /* Common result structure for MACsec offload enable */
14230 struct cmd_macsec_offload_on_result {
14231 	cmdline_fixed_string_t set;
14232 	cmdline_fixed_string_t macsec;
14233 	cmdline_fixed_string_t offload;
14234 	portid_t port_id;
14235 	cmdline_fixed_string_t on;
14236 	cmdline_fixed_string_t encrypt;
14237 	cmdline_fixed_string_t en_on_off;
14238 	cmdline_fixed_string_t replay_protect;
14239 	cmdline_fixed_string_t rp_on_off;
14240 };
14241 
14242 /* Common CLI fields for MACsec offload disable */
14243 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14244 	TOKEN_STRING_INITIALIZER
14245 		(struct cmd_macsec_offload_on_result,
14246 		 set, "set");
14247 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14248 	TOKEN_STRING_INITIALIZER
14249 		(struct cmd_macsec_offload_on_result,
14250 		 macsec, "macsec");
14251 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14252 	TOKEN_STRING_INITIALIZER
14253 		(struct cmd_macsec_offload_on_result,
14254 		 offload, "offload");
14255 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14256 	TOKEN_NUM_INITIALIZER
14257 		(struct cmd_macsec_offload_on_result,
14258 		 port_id, UINT16);
14259 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14260 	TOKEN_STRING_INITIALIZER
14261 		(struct cmd_macsec_offload_on_result,
14262 		 on, "on");
14263 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14264 	TOKEN_STRING_INITIALIZER
14265 		(struct cmd_macsec_offload_on_result,
14266 		 encrypt, "encrypt");
14267 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14268 	TOKEN_STRING_INITIALIZER
14269 		(struct cmd_macsec_offload_on_result,
14270 		 en_on_off, "on#off");
14271 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14272 	TOKEN_STRING_INITIALIZER
14273 		(struct cmd_macsec_offload_on_result,
14274 		 replay_protect, "replay-protect");
14275 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14276 	TOKEN_STRING_INITIALIZER
14277 		(struct cmd_macsec_offload_on_result,
14278 		 rp_on_off, "on#off");
14279 
14280 static void
14281 cmd_set_macsec_offload_on_parsed(
14282 	void *parsed_result,
14283 	__rte_unused struct cmdline *cl,
14284 	__rte_unused void *data)
14285 {
14286 	struct cmd_macsec_offload_on_result *res = parsed_result;
14287 	int ret = -ENOTSUP;
14288 	portid_t port_id = res->port_id;
14289 	int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14290 	int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14291 	struct rte_eth_dev_info dev_info;
14292 
14293 	if (port_id_is_invalid(port_id, ENABLED_WARN))
14294 		return;
14295 	if (!port_is_stopped(port_id)) {
14296 		printf("Please stop port %d first\n", port_id);
14297 		return;
14298 	}
14299 
14300 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
14301 	if (ret != 0)
14302 		return;
14303 
14304 	if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14305 #ifdef RTE_LIBRTE_IXGBE_PMD
14306 		ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14307 #endif
14308 	}
14309 	RTE_SET_USED(en);
14310 	RTE_SET_USED(rp);
14311 
14312 	switch (ret) {
14313 	case 0:
14314 		ports[port_id].dev_conf.txmode.offloads |=
14315 						DEV_TX_OFFLOAD_MACSEC_INSERT;
14316 		cmd_reconfig_device_queue(port_id, 1, 1);
14317 		break;
14318 	case -ENODEV:
14319 		printf("invalid port_id %d\n", port_id);
14320 		break;
14321 	case -ENOTSUP:
14322 		printf("not supported on port %d\n", port_id);
14323 		break;
14324 	default:
14325 		printf("programming error: (%s)\n", strerror(-ret));
14326 	}
14327 }
14328 
14329 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14330 	.f = cmd_set_macsec_offload_on_parsed,
14331 	.data = NULL,
14332 	.help_str = "set macsec offload <port_id> on "
14333 		"encrypt on|off replay-protect on|off",
14334 	.tokens = {
14335 		(void *)&cmd_macsec_offload_on_set,
14336 		(void *)&cmd_macsec_offload_on_macsec,
14337 		(void *)&cmd_macsec_offload_on_offload,
14338 		(void *)&cmd_macsec_offload_on_port_id,
14339 		(void *)&cmd_macsec_offload_on_on,
14340 		(void *)&cmd_macsec_offload_on_encrypt,
14341 		(void *)&cmd_macsec_offload_on_en_on_off,
14342 		(void *)&cmd_macsec_offload_on_replay_protect,
14343 		(void *)&cmd_macsec_offload_on_rp_on_off,
14344 		NULL,
14345 	},
14346 };
14347 
14348 /* Common result structure for MACsec offload disable */
14349 struct cmd_macsec_offload_off_result {
14350 	cmdline_fixed_string_t set;
14351 	cmdline_fixed_string_t macsec;
14352 	cmdline_fixed_string_t offload;
14353 	portid_t port_id;
14354 	cmdline_fixed_string_t off;
14355 };
14356 
14357 /* Common CLI fields for MACsec offload disable */
14358 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14359 	TOKEN_STRING_INITIALIZER
14360 		(struct cmd_macsec_offload_off_result,
14361 		 set, "set");
14362 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14363 	TOKEN_STRING_INITIALIZER
14364 		(struct cmd_macsec_offload_off_result,
14365 		 macsec, "macsec");
14366 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14367 	TOKEN_STRING_INITIALIZER
14368 		(struct cmd_macsec_offload_off_result,
14369 		 offload, "offload");
14370 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14371 	TOKEN_NUM_INITIALIZER
14372 		(struct cmd_macsec_offload_off_result,
14373 		 port_id, UINT16);
14374 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14375 	TOKEN_STRING_INITIALIZER
14376 		(struct cmd_macsec_offload_off_result,
14377 		 off, "off");
14378 
14379 static void
14380 cmd_set_macsec_offload_off_parsed(
14381 	void *parsed_result,
14382 	__rte_unused struct cmdline *cl,
14383 	__rte_unused void *data)
14384 {
14385 	struct cmd_macsec_offload_off_result *res = parsed_result;
14386 	int ret = -ENOTSUP;
14387 	struct rte_eth_dev_info dev_info;
14388 	portid_t port_id = res->port_id;
14389 
14390 	if (port_id_is_invalid(port_id, ENABLED_WARN))
14391 		return;
14392 	if (!port_is_stopped(port_id)) {
14393 		printf("Please stop port %d first\n", port_id);
14394 		return;
14395 	}
14396 
14397 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
14398 	if (ret != 0)
14399 		return;
14400 
14401 	if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14402 #ifdef RTE_LIBRTE_IXGBE_PMD
14403 		ret = rte_pmd_ixgbe_macsec_disable(port_id);
14404 #endif
14405 	}
14406 	switch (ret) {
14407 	case 0:
14408 		ports[port_id].dev_conf.txmode.offloads &=
14409 						~DEV_TX_OFFLOAD_MACSEC_INSERT;
14410 		cmd_reconfig_device_queue(port_id, 1, 1);
14411 		break;
14412 	case -ENODEV:
14413 		printf("invalid port_id %d\n", port_id);
14414 		break;
14415 	case -ENOTSUP:
14416 		printf("not supported on port %d\n", port_id);
14417 		break;
14418 	default:
14419 		printf("programming error: (%s)\n", strerror(-ret));
14420 	}
14421 }
14422 
14423 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14424 	.f = cmd_set_macsec_offload_off_parsed,
14425 	.data = NULL,
14426 	.help_str = "set macsec offload <port_id> off",
14427 	.tokens = {
14428 		(void *)&cmd_macsec_offload_off_set,
14429 		(void *)&cmd_macsec_offload_off_macsec,
14430 		(void *)&cmd_macsec_offload_off_offload,
14431 		(void *)&cmd_macsec_offload_off_port_id,
14432 		(void *)&cmd_macsec_offload_off_off,
14433 		NULL,
14434 	},
14435 };
14436 
14437 /* Common result structure for MACsec secure connection configure */
14438 struct cmd_macsec_sc_result {
14439 	cmdline_fixed_string_t set;
14440 	cmdline_fixed_string_t macsec;
14441 	cmdline_fixed_string_t sc;
14442 	cmdline_fixed_string_t tx_rx;
14443 	portid_t port_id;
14444 	struct rte_ether_addr mac;
14445 	uint16_t pi;
14446 };
14447 
14448 /* Common CLI fields for MACsec secure connection configure */
14449 cmdline_parse_token_string_t cmd_macsec_sc_set =
14450 	TOKEN_STRING_INITIALIZER
14451 		(struct cmd_macsec_sc_result,
14452 		 set, "set");
14453 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14454 	TOKEN_STRING_INITIALIZER
14455 		(struct cmd_macsec_sc_result,
14456 		 macsec, "macsec");
14457 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14458 	TOKEN_STRING_INITIALIZER
14459 		(struct cmd_macsec_sc_result,
14460 		 sc, "sc");
14461 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14462 	TOKEN_STRING_INITIALIZER
14463 		(struct cmd_macsec_sc_result,
14464 		 tx_rx, "tx#rx");
14465 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14466 	TOKEN_NUM_INITIALIZER
14467 		(struct cmd_macsec_sc_result,
14468 		 port_id, UINT16);
14469 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14470 	TOKEN_ETHERADDR_INITIALIZER
14471 		(struct cmd_macsec_sc_result,
14472 		 mac);
14473 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14474 	TOKEN_NUM_INITIALIZER
14475 		(struct cmd_macsec_sc_result,
14476 		 pi, UINT16);
14477 
14478 static void
14479 cmd_set_macsec_sc_parsed(
14480 	void *parsed_result,
14481 	__rte_unused struct cmdline *cl,
14482 	__rte_unused void *data)
14483 {
14484 	struct cmd_macsec_sc_result *res = parsed_result;
14485 	int ret = -ENOTSUP;
14486 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14487 
14488 #ifdef RTE_LIBRTE_IXGBE_PMD
14489 	ret = is_tx ?
14490 		rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14491 				res->mac.addr_bytes) :
14492 		rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14493 				res->mac.addr_bytes, res->pi);
14494 #endif
14495 	RTE_SET_USED(is_tx);
14496 
14497 	switch (ret) {
14498 	case 0:
14499 		break;
14500 	case -ENODEV:
14501 		printf("invalid port_id %d\n", res->port_id);
14502 		break;
14503 	case -ENOTSUP:
14504 		printf("not supported on port %d\n", res->port_id);
14505 		break;
14506 	default:
14507 		printf("programming error: (%s)\n", strerror(-ret));
14508 	}
14509 }
14510 
14511 cmdline_parse_inst_t cmd_set_macsec_sc = {
14512 	.f = cmd_set_macsec_sc_parsed,
14513 	.data = NULL,
14514 	.help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14515 	.tokens = {
14516 		(void *)&cmd_macsec_sc_set,
14517 		(void *)&cmd_macsec_sc_macsec,
14518 		(void *)&cmd_macsec_sc_sc,
14519 		(void *)&cmd_macsec_sc_tx_rx,
14520 		(void *)&cmd_macsec_sc_port_id,
14521 		(void *)&cmd_macsec_sc_mac,
14522 		(void *)&cmd_macsec_sc_pi,
14523 		NULL,
14524 	},
14525 };
14526 
14527 /* Common result structure for MACsec secure connection configure */
14528 struct cmd_macsec_sa_result {
14529 	cmdline_fixed_string_t set;
14530 	cmdline_fixed_string_t macsec;
14531 	cmdline_fixed_string_t sa;
14532 	cmdline_fixed_string_t tx_rx;
14533 	portid_t port_id;
14534 	uint8_t idx;
14535 	uint8_t an;
14536 	uint32_t pn;
14537 	cmdline_fixed_string_t key;
14538 };
14539 
14540 /* Common CLI fields for MACsec secure connection configure */
14541 cmdline_parse_token_string_t cmd_macsec_sa_set =
14542 	TOKEN_STRING_INITIALIZER
14543 		(struct cmd_macsec_sa_result,
14544 		 set, "set");
14545 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14546 	TOKEN_STRING_INITIALIZER
14547 		(struct cmd_macsec_sa_result,
14548 		 macsec, "macsec");
14549 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14550 	TOKEN_STRING_INITIALIZER
14551 		(struct cmd_macsec_sa_result,
14552 		 sa, "sa");
14553 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14554 	TOKEN_STRING_INITIALIZER
14555 		(struct cmd_macsec_sa_result,
14556 		 tx_rx, "tx#rx");
14557 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14558 	TOKEN_NUM_INITIALIZER
14559 		(struct cmd_macsec_sa_result,
14560 		 port_id, UINT16);
14561 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14562 	TOKEN_NUM_INITIALIZER
14563 		(struct cmd_macsec_sa_result,
14564 		 idx, UINT8);
14565 cmdline_parse_token_num_t cmd_macsec_sa_an =
14566 	TOKEN_NUM_INITIALIZER
14567 		(struct cmd_macsec_sa_result,
14568 		 an, UINT8);
14569 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14570 	TOKEN_NUM_INITIALIZER
14571 		(struct cmd_macsec_sa_result,
14572 		 pn, UINT32);
14573 cmdline_parse_token_string_t cmd_macsec_sa_key =
14574 	TOKEN_STRING_INITIALIZER
14575 		(struct cmd_macsec_sa_result,
14576 		 key, NULL);
14577 
14578 static void
14579 cmd_set_macsec_sa_parsed(
14580 	void *parsed_result,
14581 	__rte_unused struct cmdline *cl,
14582 	__rte_unused void *data)
14583 {
14584 	struct cmd_macsec_sa_result *res = parsed_result;
14585 	int ret = -ENOTSUP;
14586 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14587 	uint8_t key[16] = { 0 };
14588 	uint8_t xdgt0;
14589 	uint8_t xdgt1;
14590 	int key_len;
14591 	int i;
14592 
14593 	key_len = strlen(res->key) / 2;
14594 	if (key_len > 16)
14595 		key_len = 16;
14596 
14597 	for (i = 0; i < key_len; i++) {
14598 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14599 		if (xdgt0 == 0xFF)
14600 			return;
14601 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14602 		if (xdgt1 == 0xFF)
14603 			return;
14604 		key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14605 	}
14606 
14607 #ifdef RTE_LIBRTE_IXGBE_PMD
14608 	ret = is_tx ?
14609 		rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14610 			res->idx, res->an, res->pn, key) :
14611 		rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14612 			res->idx, res->an, res->pn, key);
14613 #endif
14614 	RTE_SET_USED(is_tx);
14615 	RTE_SET_USED(key);
14616 
14617 	switch (ret) {
14618 	case 0:
14619 		break;
14620 	case -EINVAL:
14621 		printf("invalid idx %d or an %d\n", res->idx, res->an);
14622 		break;
14623 	case -ENODEV:
14624 		printf("invalid port_id %d\n", res->port_id);
14625 		break;
14626 	case -ENOTSUP:
14627 		printf("not supported on port %d\n", res->port_id);
14628 		break;
14629 	default:
14630 		printf("programming error: (%s)\n", strerror(-ret));
14631 	}
14632 }
14633 
14634 cmdline_parse_inst_t cmd_set_macsec_sa = {
14635 	.f = cmd_set_macsec_sa_parsed,
14636 	.data = NULL,
14637 	.help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14638 	.tokens = {
14639 		(void *)&cmd_macsec_sa_set,
14640 		(void *)&cmd_macsec_sa_macsec,
14641 		(void *)&cmd_macsec_sa_sa,
14642 		(void *)&cmd_macsec_sa_tx_rx,
14643 		(void *)&cmd_macsec_sa_port_id,
14644 		(void *)&cmd_macsec_sa_idx,
14645 		(void *)&cmd_macsec_sa_an,
14646 		(void *)&cmd_macsec_sa_pn,
14647 		(void *)&cmd_macsec_sa_key,
14648 		NULL,
14649 	},
14650 };
14651 
14652 /* VF unicast promiscuous mode configuration */
14653 
14654 /* Common result structure for VF unicast promiscuous mode */
14655 struct cmd_vf_promisc_result {
14656 	cmdline_fixed_string_t set;
14657 	cmdline_fixed_string_t vf;
14658 	cmdline_fixed_string_t promisc;
14659 	portid_t port_id;
14660 	uint32_t vf_id;
14661 	cmdline_fixed_string_t on_off;
14662 };
14663 
14664 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14665 cmdline_parse_token_string_t cmd_vf_promisc_set =
14666 	TOKEN_STRING_INITIALIZER
14667 		(struct cmd_vf_promisc_result,
14668 		 set, "set");
14669 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14670 	TOKEN_STRING_INITIALIZER
14671 		(struct cmd_vf_promisc_result,
14672 		 vf, "vf");
14673 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14674 	TOKEN_STRING_INITIALIZER
14675 		(struct cmd_vf_promisc_result,
14676 		 promisc, "promisc");
14677 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14678 	TOKEN_NUM_INITIALIZER
14679 		(struct cmd_vf_promisc_result,
14680 		 port_id, UINT16);
14681 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14682 	TOKEN_NUM_INITIALIZER
14683 		(struct cmd_vf_promisc_result,
14684 		 vf_id, UINT32);
14685 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14686 	TOKEN_STRING_INITIALIZER
14687 		(struct cmd_vf_promisc_result,
14688 		 on_off, "on#off");
14689 
14690 static void
14691 cmd_set_vf_promisc_parsed(
14692 	void *parsed_result,
14693 	__rte_unused struct cmdline *cl,
14694 	__rte_unused void *data)
14695 {
14696 	struct cmd_vf_promisc_result *res = parsed_result;
14697 	int ret = -ENOTSUP;
14698 
14699 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14700 
14701 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14702 		return;
14703 
14704 #ifdef RTE_LIBRTE_I40E_PMD
14705 	ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14706 						  res->vf_id, is_on);
14707 #endif
14708 
14709 	switch (ret) {
14710 	case 0:
14711 		break;
14712 	case -EINVAL:
14713 		printf("invalid vf_id %d\n", res->vf_id);
14714 		break;
14715 	case -ENODEV:
14716 		printf("invalid port_id %d\n", res->port_id);
14717 		break;
14718 	case -ENOTSUP:
14719 		printf("function not implemented\n");
14720 		break;
14721 	default:
14722 		printf("programming error: (%s)\n", strerror(-ret));
14723 	}
14724 }
14725 
14726 cmdline_parse_inst_t cmd_set_vf_promisc = {
14727 	.f = cmd_set_vf_promisc_parsed,
14728 	.data = NULL,
14729 	.help_str = "set vf promisc <port_id> <vf_id> on|off: "
14730 		"Set unicast promiscuous mode for a VF from the PF",
14731 	.tokens = {
14732 		(void *)&cmd_vf_promisc_set,
14733 		(void *)&cmd_vf_promisc_vf,
14734 		(void *)&cmd_vf_promisc_promisc,
14735 		(void *)&cmd_vf_promisc_port_id,
14736 		(void *)&cmd_vf_promisc_vf_id,
14737 		(void *)&cmd_vf_promisc_on_off,
14738 		NULL,
14739 	},
14740 };
14741 
14742 /* VF multicast promiscuous mode configuration */
14743 
14744 /* Common result structure for VF multicast promiscuous mode */
14745 struct cmd_vf_allmulti_result {
14746 	cmdline_fixed_string_t set;
14747 	cmdline_fixed_string_t vf;
14748 	cmdline_fixed_string_t allmulti;
14749 	portid_t port_id;
14750 	uint32_t vf_id;
14751 	cmdline_fixed_string_t on_off;
14752 };
14753 
14754 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14755 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14756 	TOKEN_STRING_INITIALIZER
14757 		(struct cmd_vf_allmulti_result,
14758 		 set, "set");
14759 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14760 	TOKEN_STRING_INITIALIZER
14761 		(struct cmd_vf_allmulti_result,
14762 		 vf, "vf");
14763 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14764 	TOKEN_STRING_INITIALIZER
14765 		(struct cmd_vf_allmulti_result,
14766 		 allmulti, "allmulti");
14767 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14768 	TOKEN_NUM_INITIALIZER
14769 		(struct cmd_vf_allmulti_result,
14770 		 port_id, UINT16);
14771 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14772 	TOKEN_NUM_INITIALIZER
14773 		(struct cmd_vf_allmulti_result,
14774 		 vf_id, UINT32);
14775 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14776 	TOKEN_STRING_INITIALIZER
14777 		(struct cmd_vf_allmulti_result,
14778 		 on_off, "on#off");
14779 
14780 static void
14781 cmd_set_vf_allmulti_parsed(
14782 	void *parsed_result,
14783 	__rte_unused struct cmdline *cl,
14784 	__rte_unused void *data)
14785 {
14786 	struct cmd_vf_allmulti_result *res = parsed_result;
14787 	int ret = -ENOTSUP;
14788 
14789 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14790 
14791 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14792 		return;
14793 
14794 #ifdef RTE_LIBRTE_I40E_PMD
14795 	ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14796 						    res->vf_id, is_on);
14797 #endif
14798 
14799 	switch (ret) {
14800 	case 0:
14801 		break;
14802 	case -EINVAL:
14803 		printf("invalid vf_id %d\n", res->vf_id);
14804 		break;
14805 	case -ENODEV:
14806 		printf("invalid port_id %d\n", res->port_id);
14807 		break;
14808 	case -ENOTSUP:
14809 		printf("function not implemented\n");
14810 		break;
14811 	default:
14812 		printf("programming error: (%s)\n", strerror(-ret));
14813 	}
14814 }
14815 
14816 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14817 	.f = cmd_set_vf_allmulti_parsed,
14818 	.data = NULL,
14819 	.help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14820 		"Set multicast promiscuous mode for a VF from the PF",
14821 	.tokens = {
14822 		(void *)&cmd_vf_allmulti_set,
14823 		(void *)&cmd_vf_allmulti_vf,
14824 		(void *)&cmd_vf_allmulti_allmulti,
14825 		(void *)&cmd_vf_allmulti_port_id,
14826 		(void *)&cmd_vf_allmulti_vf_id,
14827 		(void *)&cmd_vf_allmulti_on_off,
14828 		NULL,
14829 	},
14830 };
14831 
14832 /* vf broadcast mode configuration */
14833 
14834 /* Common result structure for vf broadcast */
14835 struct cmd_set_vf_broadcast_result {
14836 	cmdline_fixed_string_t set;
14837 	cmdline_fixed_string_t vf;
14838 	cmdline_fixed_string_t broadcast;
14839 	portid_t port_id;
14840 	uint16_t vf_id;
14841 	cmdline_fixed_string_t on_off;
14842 };
14843 
14844 /* Common CLI fields for vf broadcast enable disable */
14845 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14846 	TOKEN_STRING_INITIALIZER
14847 		(struct cmd_set_vf_broadcast_result,
14848 		 set, "set");
14849 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14850 	TOKEN_STRING_INITIALIZER
14851 		(struct cmd_set_vf_broadcast_result,
14852 		 vf, "vf");
14853 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14854 	TOKEN_STRING_INITIALIZER
14855 		(struct cmd_set_vf_broadcast_result,
14856 		 broadcast, "broadcast");
14857 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14858 	TOKEN_NUM_INITIALIZER
14859 		(struct cmd_set_vf_broadcast_result,
14860 		 port_id, UINT16);
14861 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14862 	TOKEN_NUM_INITIALIZER
14863 		(struct cmd_set_vf_broadcast_result,
14864 		 vf_id, UINT16);
14865 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14866 	TOKEN_STRING_INITIALIZER
14867 		(struct cmd_set_vf_broadcast_result,
14868 		 on_off, "on#off");
14869 
14870 static void
14871 cmd_set_vf_broadcast_parsed(
14872 	void *parsed_result,
14873 	__rte_unused struct cmdline *cl,
14874 	__rte_unused void *data)
14875 {
14876 	struct cmd_set_vf_broadcast_result *res = parsed_result;
14877 	int ret = -ENOTSUP;
14878 
14879 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14880 
14881 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14882 		return;
14883 
14884 #ifdef RTE_LIBRTE_I40E_PMD
14885 	ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14886 					    res->vf_id, is_on);
14887 #endif
14888 
14889 	switch (ret) {
14890 	case 0:
14891 		break;
14892 	case -EINVAL:
14893 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14894 		break;
14895 	case -ENODEV:
14896 		printf("invalid port_id %d\n", res->port_id);
14897 		break;
14898 	case -ENOTSUP:
14899 		printf("function not implemented\n");
14900 		break;
14901 	default:
14902 		printf("programming error: (%s)\n", strerror(-ret));
14903 	}
14904 }
14905 
14906 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14907 	.f = cmd_set_vf_broadcast_parsed,
14908 	.data = NULL,
14909 	.help_str = "set vf broadcast <port_id> <vf_id> on|off",
14910 	.tokens = {
14911 		(void *)&cmd_set_vf_broadcast_set,
14912 		(void *)&cmd_set_vf_broadcast_vf,
14913 		(void *)&cmd_set_vf_broadcast_broadcast,
14914 		(void *)&cmd_set_vf_broadcast_port_id,
14915 		(void *)&cmd_set_vf_broadcast_vf_id,
14916 		(void *)&cmd_set_vf_broadcast_on_off,
14917 		NULL,
14918 	},
14919 };
14920 
14921 /* vf vlan tag configuration */
14922 
14923 /* Common result structure for vf vlan tag */
14924 struct cmd_set_vf_vlan_tag_result {
14925 	cmdline_fixed_string_t set;
14926 	cmdline_fixed_string_t vf;
14927 	cmdline_fixed_string_t vlan;
14928 	cmdline_fixed_string_t tag;
14929 	portid_t port_id;
14930 	uint16_t vf_id;
14931 	cmdline_fixed_string_t on_off;
14932 };
14933 
14934 /* Common CLI fields for vf vlan tag enable disable */
14935 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14936 	TOKEN_STRING_INITIALIZER
14937 		(struct cmd_set_vf_vlan_tag_result,
14938 		 set, "set");
14939 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14940 	TOKEN_STRING_INITIALIZER
14941 		(struct cmd_set_vf_vlan_tag_result,
14942 		 vf, "vf");
14943 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14944 	TOKEN_STRING_INITIALIZER
14945 		(struct cmd_set_vf_vlan_tag_result,
14946 		 vlan, "vlan");
14947 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14948 	TOKEN_STRING_INITIALIZER
14949 		(struct cmd_set_vf_vlan_tag_result,
14950 		 tag, "tag");
14951 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14952 	TOKEN_NUM_INITIALIZER
14953 		(struct cmd_set_vf_vlan_tag_result,
14954 		 port_id, UINT16);
14955 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14956 	TOKEN_NUM_INITIALIZER
14957 		(struct cmd_set_vf_vlan_tag_result,
14958 		 vf_id, UINT16);
14959 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14960 	TOKEN_STRING_INITIALIZER
14961 		(struct cmd_set_vf_vlan_tag_result,
14962 		 on_off, "on#off");
14963 
14964 static void
14965 cmd_set_vf_vlan_tag_parsed(
14966 	void *parsed_result,
14967 	__rte_unused struct cmdline *cl,
14968 	__rte_unused void *data)
14969 {
14970 	struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14971 	int ret = -ENOTSUP;
14972 
14973 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14974 
14975 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14976 		return;
14977 
14978 #ifdef RTE_LIBRTE_I40E_PMD
14979 	ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14980 					   res->vf_id, is_on);
14981 #endif
14982 
14983 	switch (ret) {
14984 	case 0:
14985 		break;
14986 	case -EINVAL:
14987 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14988 		break;
14989 	case -ENODEV:
14990 		printf("invalid port_id %d\n", res->port_id);
14991 		break;
14992 	case -ENOTSUP:
14993 		printf("function not implemented\n");
14994 		break;
14995 	default:
14996 		printf("programming error: (%s)\n", strerror(-ret));
14997 	}
14998 }
14999 
15000 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
15001 	.f = cmd_set_vf_vlan_tag_parsed,
15002 	.data = NULL,
15003 	.help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15004 	.tokens = {
15005 		(void *)&cmd_set_vf_vlan_tag_set,
15006 		(void *)&cmd_set_vf_vlan_tag_vf,
15007 		(void *)&cmd_set_vf_vlan_tag_vlan,
15008 		(void *)&cmd_set_vf_vlan_tag_tag,
15009 		(void *)&cmd_set_vf_vlan_tag_port_id,
15010 		(void *)&cmd_set_vf_vlan_tag_vf_id,
15011 		(void *)&cmd_set_vf_vlan_tag_on_off,
15012 		NULL,
15013 	},
15014 };
15015 
15016 /* Common definition of VF and TC TX bandwidth configuration */
15017 struct cmd_vf_tc_bw_result {
15018 	cmdline_fixed_string_t set;
15019 	cmdline_fixed_string_t vf;
15020 	cmdline_fixed_string_t tc;
15021 	cmdline_fixed_string_t tx;
15022 	cmdline_fixed_string_t min_bw;
15023 	cmdline_fixed_string_t max_bw;
15024 	cmdline_fixed_string_t strict_link_prio;
15025 	portid_t port_id;
15026 	uint16_t vf_id;
15027 	uint8_t tc_no;
15028 	uint32_t bw;
15029 	cmdline_fixed_string_t bw_list;
15030 	uint8_t tc_map;
15031 };
15032 
15033 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15034 	TOKEN_STRING_INITIALIZER
15035 		(struct cmd_vf_tc_bw_result,
15036 		 set, "set");
15037 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15038 	TOKEN_STRING_INITIALIZER
15039 		(struct cmd_vf_tc_bw_result,
15040 		 vf, "vf");
15041 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15042 	TOKEN_STRING_INITIALIZER
15043 		(struct cmd_vf_tc_bw_result,
15044 		 tc, "tc");
15045 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15046 	TOKEN_STRING_INITIALIZER
15047 		(struct cmd_vf_tc_bw_result,
15048 		 tx, "tx");
15049 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15050 	TOKEN_STRING_INITIALIZER
15051 		(struct cmd_vf_tc_bw_result,
15052 		 strict_link_prio, "strict-link-priority");
15053 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15054 	TOKEN_STRING_INITIALIZER
15055 		(struct cmd_vf_tc_bw_result,
15056 		 min_bw, "min-bandwidth");
15057 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15058 	TOKEN_STRING_INITIALIZER
15059 		(struct cmd_vf_tc_bw_result,
15060 		 max_bw, "max-bandwidth");
15061 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15062 	TOKEN_NUM_INITIALIZER
15063 		(struct cmd_vf_tc_bw_result,
15064 		 port_id, UINT16);
15065 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15066 	TOKEN_NUM_INITIALIZER
15067 		(struct cmd_vf_tc_bw_result,
15068 		 vf_id, UINT16);
15069 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15070 	TOKEN_NUM_INITIALIZER
15071 		(struct cmd_vf_tc_bw_result,
15072 		 tc_no, UINT8);
15073 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15074 	TOKEN_NUM_INITIALIZER
15075 		(struct cmd_vf_tc_bw_result,
15076 		 bw, UINT32);
15077 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15078 	TOKEN_STRING_INITIALIZER
15079 		(struct cmd_vf_tc_bw_result,
15080 		 bw_list, NULL);
15081 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15082 	TOKEN_NUM_INITIALIZER
15083 		(struct cmd_vf_tc_bw_result,
15084 		 tc_map, UINT8);
15085 
15086 /* VF max bandwidth setting */
15087 static void
15088 cmd_vf_max_bw_parsed(
15089 	void *parsed_result,
15090 	__rte_unused struct cmdline *cl,
15091 	__rte_unused void *data)
15092 {
15093 	struct cmd_vf_tc_bw_result *res = parsed_result;
15094 	int ret = -ENOTSUP;
15095 
15096 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15097 		return;
15098 
15099 #ifdef RTE_LIBRTE_I40E_PMD
15100 	ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15101 					 res->vf_id, res->bw);
15102 #endif
15103 
15104 	switch (ret) {
15105 	case 0:
15106 		break;
15107 	case -EINVAL:
15108 		printf("invalid vf_id %d or bandwidth %d\n",
15109 		       res->vf_id, res->bw);
15110 		break;
15111 	case -ENODEV:
15112 		printf("invalid port_id %d\n", res->port_id);
15113 		break;
15114 	case -ENOTSUP:
15115 		printf("function not implemented\n");
15116 		break;
15117 	default:
15118 		printf("programming error: (%s)\n", strerror(-ret));
15119 	}
15120 }
15121 
15122 cmdline_parse_inst_t cmd_vf_max_bw = {
15123 	.f = cmd_vf_max_bw_parsed,
15124 	.data = NULL,
15125 	.help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15126 	.tokens = {
15127 		(void *)&cmd_vf_tc_bw_set,
15128 		(void *)&cmd_vf_tc_bw_vf,
15129 		(void *)&cmd_vf_tc_bw_tx,
15130 		(void *)&cmd_vf_tc_bw_max_bw,
15131 		(void *)&cmd_vf_tc_bw_port_id,
15132 		(void *)&cmd_vf_tc_bw_vf_id,
15133 		(void *)&cmd_vf_tc_bw_bw,
15134 		NULL,
15135 	},
15136 };
15137 
15138 static int
15139 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15140 			   uint8_t *tc_num,
15141 			   char *str)
15142 {
15143 	uint32_t size;
15144 	const char *p, *p0 = str;
15145 	char s[256];
15146 	char *end;
15147 	char *str_fld[16];
15148 	uint16_t i;
15149 	int ret;
15150 
15151 	p = strchr(p0, '(');
15152 	if (p == NULL) {
15153 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15154 		return -1;
15155 	}
15156 	p++;
15157 	p0 = strchr(p, ')');
15158 	if (p0 == NULL) {
15159 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15160 		return -1;
15161 	}
15162 	size = p0 - p;
15163 	if (size >= sizeof(s)) {
15164 		printf("The string size exceeds the internal buffer size\n");
15165 		return -1;
15166 	}
15167 	snprintf(s, sizeof(s), "%.*s", size, p);
15168 	ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15169 	if (ret <= 0) {
15170 		printf("Failed to get the bandwidth list. ");
15171 		return -1;
15172 	}
15173 	*tc_num = ret;
15174 	for (i = 0; i < ret; i++)
15175 		bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15176 
15177 	return 0;
15178 }
15179 
15180 /* TC min bandwidth setting */
15181 static void
15182 cmd_vf_tc_min_bw_parsed(
15183 	void *parsed_result,
15184 	__rte_unused struct cmdline *cl,
15185 	__rte_unused void *data)
15186 {
15187 	struct cmd_vf_tc_bw_result *res = parsed_result;
15188 	uint8_t tc_num;
15189 	uint8_t bw[16];
15190 	int ret = -ENOTSUP;
15191 
15192 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15193 		return;
15194 
15195 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15196 	if (ret)
15197 		return;
15198 
15199 #ifdef RTE_LIBRTE_I40E_PMD
15200 	ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15201 					      tc_num, bw);
15202 #endif
15203 
15204 	switch (ret) {
15205 	case 0:
15206 		break;
15207 	case -EINVAL:
15208 		printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15209 		break;
15210 	case -ENODEV:
15211 		printf("invalid port_id %d\n", res->port_id);
15212 		break;
15213 	case -ENOTSUP:
15214 		printf("function not implemented\n");
15215 		break;
15216 	default:
15217 		printf("programming error: (%s)\n", strerror(-ret));
15218 	}
15219 }
15220 
15221 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15222 	.f = cmd_vf_tc_min_bw_parsed,
15223 	.data = NULL,
15224 	.help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15225 		    " <bw1, bw2, ...>",
15226 	.tokens = {
15227 		(void *)&cmd_vf_tc_bw_set,
15228 		(void *)&cmd_vf_tc_bw_vf,
15229 		(void *)&cmd_vf_tc_bw_tc,
15230 		(void *)&cmd_vf_tc_bw_tx,
15231 		(void *)&cmd_vf_tc_bw_min_bw,
15232 		(void *)&cmd_vf_tc_bw_port_id,
15233 		(void *)&cmd_vf_tc_bw_vf_id,
15234 		(void *)&cmd_vf_tc_bw_bw_list,
15235 		NULL,
15236 	},
15237 };
15238 
15239 static void
15240 cmd_tc_min_bw_parsed(
15241 	void *parsed_result,
15242 	__rte_unused struct cmdline *cl,
15243 	__rte_unused void *data)
15244 {
15245 	struct cmd_vf_tc_bw_result *res = parsed_result;
15246 	struct rte_port *port;
15247 	uint8_t tc_num;
15248 	uint8_t bw[16];
15249 	int ret = -ENOTSUP;
15250 
15251 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15252 		return;
15253 
15254 	port = &ports[res->port_id];
15255 	/** Check if the port is not started **/
15256 	if (port->port_status != RTE_PORT_STOPPED) {
15257 		printf("Please stop port %d first\n", res->port_id);
15258 		return;
15259 	}
15260 
15261 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15262 	if (ret)
15263 		return;
15264 
15265 #ifdef RTE_LIBRTE_IXGBE_PMD
15266 	ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15267 #endif
15268 
15269 	switch (ret) {
15270 	case 0:
15271 		break;
15272 	case -EINVAL:
15273 		printf("invalid bandwidth\n");
15274 		break;
15275 	case -ENODEV:
15276 		printf("invalid port_id %d\n", res->port_id);
15277 		break;
15278 	case -ENOTSUP:
15279 		printf("function not implemented\n");
15280 		break;
15281 	default:
15282 		printf("programming error: (%s)\n", strerror(-ret));
15283 	}
15284 }
15285 
15286 cmdline_parse_inst_t cmd_tc_min_bw = {
15287 	.f = cmd_tc_min_bw_parsed,
15288 	.data = NULL,
15289 	.help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15290 	.tokens = {
15291 		(void *)&cmd_vf_tc_bw_set,
15292 		(void *)&cmd_vf_tc_bw_tc,
15293 		(void *)&cmd_vf_tc_bw_tx,
15294 		(void *)&cmd_vf_tc_bw_min_bw,
15295 		(void *)&cmd_vf_tc_bw_port_id,
15296 		(void *)&cmd_vf_tc_bw_bw_list,
15297 		NULL,
15298 	},
15299 };
15300 
15301 /* TC max bandwidth setting */
15302 static void
15303 cmd_vf_tc_max_bw_parsed(
15304 	void *parsed_result,
15305 	__rte_unused struct cmdline *cl,
15306 	__rte_unused void *data)
15307 {
15308 	struct cmd_vf_tc_bw_result *res = parsed_result;
15309 	int ret = -ENOTSUP;
15310 
15311 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15312 		return;
15313 
15314 #ifdef RTE_LIBRTE_I40E_PMD
15315 	ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15316 					    res->tc_no, res->bw);
15317 #endif
15318 
15319 	switch (ret) {
15320 	case 0:
15321 		break;
15322 	case -EINVAL:
15323 		printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15324 		       res->vf_id, res->tc_no, res->bw);
15325 		break;
15326 	case -ENODEV:
15327 		printf("invalid port_id %d\n", res->port_id);
15328 		break;
15329 	case -ENOTSUP:
15330 		printf("function not implemented\n");
15331 		break;
15332 	default:
15333 		printf("programming error: (%s)\n", strerror(-ret));
15334 	}
15335 }
15336 
15337 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15338 	.f = cmd_vf_tc_max_bw_parsed,
15339 	.data = NULL,
15340 	.help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15341 		    " <bandwidth>",
15342 	.tokens = {
15343 		(void *)&cmd_vf_tc_bw_set,
15344 		(void *)&cmd_vf_tc_bw_vf,
15345 		(void *)&cmd_vf_tc_bw_tc,
15346 		(void *)&cmd_vf_tc_bw_tx,
15347 		(void *)&cmd_vf_tc_bw_max_bw,
15348 		(void *)&cmd_vf_tc_bw_port_id,
15349 		(void *)&cmd_vf_tc_bw_vf_id,
15350 		(void *)&cmd_vf_tc_bw_tc_no,
15351 		(void *)&cmd_vf_tc_bw_bw,
15352 		NULL,
15353 	},
15354 };
15355 
15356 
15357 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15358 
15359 /* *** Set Port default Traffic Management Hierarchy *** */
15360 struct cmd_set_port_tm_hierarchy_default_result {
15361 	cmdline_fixed_string_t set;
15362 	cmdline_fixed_string_t port;
15363 	cmdline_fixed_string_t tm;
15364 	cmdline_fixed_string_t hierarchy;
15365 	cmdline_fixed_string_t def;
15366 	portid_t port_id;
15367 };
15368 
15369 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15370 	TOKEN_STRING_INITIALIZER(
15371 		struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15372 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15373 	TOKEN_STRING_INITIALIZER(
15374 		struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15375 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15376 	TOKEN_STRING_INITIALIZER(
15377 		struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15378 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15379 	TOKEN_STRING_INITIALIZER(
15380 		struct cmd_set_port_tm_hierarchy_default_result,
15381 			hierarchy, "hierarchy");
15382 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15383 	TOKEN_STRING_INITIALIZER(
15384 		struct cmd_set_port_tm_hierarchy_default_result,
15385 			def, "default");
15386 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15387 	TOKEN_NUM_INITIALIZER(
15388 		struct cmd_set_port_tm_hierarchy_default_result,
15389 			port_id, UINT16);
15390 
15391 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15392 	__rte_unused struct cmdline *cl,
15393 	__rte_unused void *data)
15394 {
15395 	struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15396 	struct rte_port *p;
15397 	portid_t port_id = res->port_id;
15398 
15399 	if (port_id_is_invalid(port_id, ENABLED_WARN))
15400 		return;
15401 
15402 	p = &ports[port_id];
15403 
15404 	/* Forward mode: tm */
15405 	if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15406 		printf("  softnicfwd mode not enabled(error)\n");
15407 		return;
15408 	}
15409 
15410 	/* Set the default tm hierarchy */
15411 	p->softport.default_tm_hierarchy_enable = 1;
15412 }
15413 
15414 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15415 	.f = cmd_set_port_tm_hierarchy_default_parsed,
15416 	.data = NULL,
15417 	.help_str = "set port tm hierarchy default <port_id>",
15418 	.tokens = {
15419 		(void *)&cmd_set_port_tm_hierarchy_default_set,
15420 		(void *)&cmd_set_port_tm_hierarchy_default_port,
15421 		(void *)&cmd_set_port_tm_hierarchy_default_tm,
15422 		(void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15423 		(void *)&cmd_set_port_tm_hierarchy_default_default,
15424 		(void *)&cmd_set_port_tm_hierarchy_default_port_id,
15425 		NULL,
15426 	},
15427 };
15428 #endif
15429 
15430 /** Set VXLAN encapsulation details */
15431 struct cmd_set_vxlan_result {
15432 	cmdline_fixed_string_t set;
15433 	cmdline_fixed_string_t vxlan;
15434 	cmdline_fixed_string_t pos_token;
15435 	cmdline_fixed_string_t ip_version;
15436 	uint32_t vlan_present:1;
15437 	uint32_t vni;
15438 	uint16_t udp_src;
15439 	uint16_t udp_dst;
15440 	cmdline_ipaddr_t ip_src;
15441 	cmdline_ipaddr_t ip_dst;
15442 	uint16_t tci;
15443 	uint8_t tos;
15444 	uint8_t ttl;
15445 	struct rte_ether_addr eth_src;
15446 	struct rte_ether_addr eth_dst;
15447 };
15448 
15449 cmdline_parse_token_string_t cmd_set_vxlan_set =
15450 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15451 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15452 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15453 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15454 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15455 				 "vxlan-tos-ttl");
15456 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15457 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15458 				 "vxlan-with-vlan");
15459 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15460 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15461 				 "ip-version");
15462 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15463 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15464 				 "ipv4#ipv6");
15465 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15466 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15467 				 "vni");
15468 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15469 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15470 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15471 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15472 				 "udp-src");
15473 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15474 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15475 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15476 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15477 				 "udp-dst");
15478 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15479 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15480 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15481 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15482 				 "ip-tos");
15483 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15484 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15485 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15486 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15487 				 "ip-ttl");
15488 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15489 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15490 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15491 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15492 				 "ip-src");
15493 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15494 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15495 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15496 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15497 				 "ip-dst");
15498 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15499 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15500 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15501 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15502 				 "vlan-tci");
15503 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15504 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15505 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15506 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15507 				 "eth-src");
15508 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15509 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15510 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15511 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15512 				 "eth-dst");
15513 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15514 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15515 
15516 static void cmd_set_vxlan_parsed(void *parsed_result,
15517 	__rte_unused struct cmdline *cl,
15518 	__rte_unused void *data)
15519 {
15520 	struct cmd_set_vxlan_result *res = parsed_result;
15521 	union {
15522 		uint32_t vxlan_id;
15523 		uint8_t vni[4];
15524 	} id = {
15525 		.vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15526 	};
15527 
15528 	vxlan_encap_conf.select_tos_ttl = 0;
15529 	if (strcmp(res->vxlan, "vxlan") == 0)
15530 		vxlan_encap_conf.select_vlan = 0;
15531 	else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15532 		vxlan_encap_conf.select_vlan = 1;
15533 	else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15534 		vxlan_encap_conf.select_vlan = 0;
15535 		vxlan_encap_conf.select_tos_ttl = 1;
15536 	}
15537 	if (strcmp(res->ip_version, "ipv4") == 0)
15538 		vxlan_encap_conf.select_ipv4 = 1;
15539 	else if (strcmp(res->ip_version, "ipv6") == 0)
15540 		vxlan_encap_conf.select_ipv4 = 0;
15541 	else
15542 		return;
15543 	rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15544 	vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15545 	vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15546 	vxlan_encap_conf.ip_tos = res->tos;
15547 	vxlan_encap_conf.ip_ttl = res->ttl;
15548 	if (vxlan_encap_conf.select_ipv4) {
15549 		IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15550 		IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15551 	} else {
15552 		IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15553 		IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15554 	}
15555 	if (vxlan_encap_conf.select_vlan)
15556 		vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15557 	rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15558 		   RTE_ETHER_ADDR_LEN);
15559 	rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15560 		   RTE_ETHER_ADDR_LEN);
15561 }
15562 
15563 cmdline_parse_inst_t cmd_set_vxlan = {
15564 	.f = cmd_set_vxlan_parsed,
15565 	.data = NULL,
15566 	.help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15567 		" <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15568 		" eth-src <eth-src> eth-dst <eth-dst>",
15569 	.tokens = {
15570 		(void *)&cmd_set_vxlan_set,
15571 		(void *)&cmd_set_vxlan_vxlan,
15572 		(void *)&cmd_set_vxlan_ip_version,
15573 		(void *)&cmd_set_vxlan_ip_version_value,
15574 		(void *)&cmd_set_vxlan_vni,
15575 		(void *)&cmd_set_vxlan_vni_value,
15576 		(void *)&cmd_set_vxlan_udp_src,
15577 		(void *)&cmd_set_vxlan_udp_src_value,
15578 		(void *)&cmd_set_vxlan_udp_dst,
15579 		(void *)&cmd_set_vxlan_udp_dst_value,
15580 		(void *)&cmd_set_vxlan_ip_src,
15581 		(void *)&cmd_set_vxlan_ip_src_value,
15582 		(void *)&cmd_set_vxlan_ip_dst,
15583 		(void *)&cmd_set_vxlan_ip_dst_value,
15584 		(void *)&cmd_set_vxlan_eth_src,
15585 		(void *)&cmd_set_vxlan_eth_src_value,
15586 		(void *)&cmd_set_vxlan_eth_dst,
15587 		(void *)&cmd_set_vxlan_eth_dst_value,
15588 		NULL,
15589 	},
15590 };
15591 
15592 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15593 	.f = cmd_set_vxlan_parsed,
15594 	.data = NULL,
15595 	.help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15596 		" <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15597 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15598 		" eth-dst <eth-dst>",
15599 	.tokens = {
15600 		(void *)&cmd_set_vxlan_set,
15601 		(void *)&cmd_set_vxlan_vxlan_tos_ttl,
15602 		(void *)&cmd_set_vxlan_ip_version,
15603 		(void *)&cmd_set_vxlan_ip_version_value,
15604 		(void *)&cmd_set_vxlan_vni,
15605 		(void *)&cmd_set_vxlan_vni_value,
15606 		(void *)&cmd_set_vxlan_udp_src,
15607 		(void *)&cmd_set_vxlan_udp_src_value,
15608 		(void *)&cmd_set_vxlan_udp_dst,
15609 		(void *)&cmd_set_vxlan_udp_dst_value,
15610 		(void *)&cmd_set_vxlan_ip_tos,
15611 		(void *)&cmd_set_vxlan_ip_tos_value,
15612 		(void *)&cmd_set_vxlan_ip_ttl,
15613 		(void *)&cmd_set_vxlan_ip_ttl_value,
15614 		(void *)&cmd_set_vxlan_ip_src,
15615 		(void *)&cmd_set_vxlan_ip_src_value,
15616 		(void *)&cmd_set_vxlan_ip_dst,
15617 		(void *)&cmd_set_vxlan_ip_dst_value,
15618 		(void *)&cmd_set_vxlan_eth_src,
15619 		(void *)&cmd_set_vxlan_eth_src_value,
15620 		(void *)&cmd_set_vxlan_eth_dst,
15621 		(void *)&cmd_set_vxlan_eth_dst_value,
15622 		NULL,
15623 	},
15624 };
15625 
15626 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15627 	.f = cmd_set_vxlan_parsed,
15628 	.data = NULL,
15629 	.help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15630 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15631 		" <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15632 		" <eth-dst>",
15633 	.tokens = {
15634 		(void *)&cmd_set_vxlan_set,
15635 		(void *)&cmd_set_vxlan_vxlan_with_vlan,
15636 		(void *)&cmd_set_vxlan_ip_version,
15637 		(void *)&cmd_set_vxlan_ip_version_value,
15638 		(void *)&cmd_set_vxlan_vni,
15639 		(void *)&cmd_set_vxlan_vni_value,
15640 		(void *)&cmd_set_vxlan_udp_src,
15641 		(void *)&cmd_set_vxlan_udp_src_value,
15642 		(void *)&cmd_set_vxlan_udp_dst,
15643 		(void *)&cmd_set_vxlan_udp_dst_value,
15644 		(void *)&cmd_set_vxlan_ip_src,
15645 		(void *)&cmd_set_vxlan_ip_src_value,
15646 		(void *)&cmd_set_vxlan_ip_dst,
15647 		(void *)&cmd_set_vxlan_ip_dst_value,
15648 		(void *)&cmd_set_vxlan_vlan,
15649 		(void *)&cmd_set_vxlan_vlan_value,
15650 		(void *)&cmd_set_vxlan_eth_src,
15651 		(void *)&cmd_set_vxlan_eth_src_value,
15652 		(void *)&cmd_set_vxlan_eth_dst,
15653 		(void *)&cmd_set_vxlan_eth_dst_value,
15654 		NULL,
15655 	},
15656 };
15657 
15658 /** Set NVGRE encapsulation details */
15659 struct cmd_set_nvgre_result {
15660 	cmdline_fixed_string_t set;
15661 	cmdline_fixed_string_t nvgre;
15662 	cmdline_fixed_string_t pos_token;
15663 	cmdline_fixed_string_t ip_version;
15664 	uint32_t tni;
15665 	cmdline_ipaddr_t ip_src;
15666 	cmdline_ipaddr_t ip_dst;
15667 	uint16_t tci;
15668 	struct rte_ether_addr eth_src;
15669 	struct rte_ether_addr eth_dst;
15670 };
15671 
15672 cmdline_parse_token_string_t cmd_set_nvgre_set =
15673 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15674 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15675 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15676 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15677 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15678 				 "nvgre-with-vlan");
15679 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15680 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15681 				 "ip-version");
15682 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15683 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15684 				 "ipv4#ipv6");
15685 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15686 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15687 				 "tni");
15688 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15689 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15690 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15691 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15692 				 "ip-src");
15693 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15694 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15695 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15696 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15697 				 "ip-dst");
15698 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15699 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15700 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15701 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15702 				 "vlan-tci");
15703 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15704 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15705 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15706 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15707 				 "eth-src");
15708 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15709 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15710 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15711 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15712 				 "eth-dst");
15713 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15714 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15715 
15716 static void cmd_set_nvgre_parsed(void *parsed_result,
15717 	__rte_unused struct cmdline *cl,
15718 	__rte_unused void *data)
15719 {
15720 	struct cmd_set_nvgre_result *res = parsed_result;
15721 	union {
15722 		uint32_t nvgre_tni;
15723 		uint8_t tni[4];
15724 	} id = {
15725 		.nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15726 	};
15727 
15728 	if (strcmp(res->nvgre, "nvgre") == 0)
15729 		nvgre_encap_conf.select_vlan = 0;
15730 	else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15731 		nvgre_encap_conf.select_vlan = 1;
15732 	if (strcmp(res->ip_version, "ipv4") == 0)
15733 		nvgre_encap_conf.select_ipv4 = 1;
15734 	else if (strcmp(res->ip_version, "ipv6") == 0)
15735 		nvgre_encap_conf.select_ipv4 = 0;
15736 	else
15737 		return;
15738 	rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15739 	if (nvgre_encap_conf.select_ipv4) {
15740 		IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15741 		IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15742 	} else {
15743 		IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15744 		IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15745 	}
15746 	if (nvgre_encap_conf.select_vlan)
15747 		nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15748 	rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15749 		   RTE_ETHER_ADDR_LEN);
15750 	rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15751 		   RTE_ETHER_ADDR_LEN);
15752 }
15753 
15754 cmdline_parse_inst_t cmd_set_nvgre = {
15755 	.f = cmd_set_nvgre_parsed,
15756 	.data = NULL,
15757 	.help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15758 		" <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15759 		" eth-dst <eth-dst>",
15760 	.tokens = {
15761 		(void *)&cmd_set_nvgre_set,
15762 		(void *)&cmd_set_nvgre_nvgre,
15763 		(void *)&cmd_set_nvgre_ip_version,
15764 		(void *)&cmd_set_nvgre_ip_version_value,
15765 		(void *)&cmd_set_nvgre_tni,
15766 		(void *)&cmd_set_nvgre_tni_value,
15767 		(void *)&cmd_set_nvgre_ip_src,
15768 		(void *)&cmd_set_nvgre_ip_src_value,
15769 		(void *)&cmd_set_nvgre_ip_dst,
15770 		(void *)&cmd_set_nvgre_ip_dst_value,
15771 		(void *)&cmd_set_nvgre_eth_src,
15772 		(void *)&cmd_set_nvgre_eth_src_value,
15773 		(void *)&cmd_set_nvgre_eth_dst,
15774 		(void *)&cmd_set_nvgre_eth_dst_value,
15775 		NULL,
15776 	},
15777 };
15778 
15779 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15780 	.f = cmd_set_nvgre_parsed,
15781 	.data = NULL,
15782 	.help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15783 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15784 		" eth-src <eth-src> eth-dst <eth-dst>",
15785 	.tokens = {
15786 		(void *)&cmd_set_nvgre_set,
15787 		(void *)&cmd_set_nvgre_nvgre_with_vlan,
15788 		(void *)&cmd_set_nvgre_ip_version,
15789 		(void *)&cmd_set_nvgre_ip_version_value,
15790 		(void *)&cmd_set_nvgre_tni,
15791 		(void *)&cmd_set_nvgre_tni_value,
15792 		(void *)&cmd_set_nvgre_ip_src,
15793 		(void *)&cmd_set_nvgre_ip_src_value,
15794 		(void *)&cmd_set_nvgre_ip_dst,
15795 		(void *)&cmd_set_nvgre_ip_dst_value,
15796 		(void *)&cmd_set_nvgre_vlan,
15797 		(void *)&cmd_set_nvgre_vlan_value,
15798 		(void *)&cmd_set_nvgre_eth_src,
15799 		(void *)&cmd_set_nvgre_eth_src_value,
15800 		(void *)&cmd_set_nvgre_eth_dst,
15801 		(void *)&cmd_set_nvgre_eth_dst_value,
15802 		NULL,
15803 	},
15804 };
15805 
15806 /** Set L2 encapsulation details */
15807 struct cmd_set_l2_encap_result {
15808 	cmdline_fixed_string_t set;
15809 	cmdline_fixed_string_t l2_encap;
15810 	cmdline_fixed_string_t pos_token;
15811 	cmdline_fixed_string_t ip_version;
15812 	uint32_t vlan_present:1;
15813 	uint16_t tci;
15814 	struct rte_ether_addr eth_src;
15815 	struct rte_ether_addr eth_dst;
15816 };
15817 
15818 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15819 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15820 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15821 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15822 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15823 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15824 				 "l2_encap-with-vlan");
15825 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15826 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15827 				 "ip-version");
15828 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15829 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15830 				 "ipv4#ipv6");
15831 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15832 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15833 				 "vlan-tci");
15834 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15835 	TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15836 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15837 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15838 				 "eth-src");
15839 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15840 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15841 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15842 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15843 				 "eth-dst");
15844 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15845 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15846 
15847 static void cmd_set_l2_encap_parsed(void *parsed_result,
15848 	__rte_unused struct cmdline *cl,
15849 	__rte_unused void *data)
15850 {
15851 	struct cmd_set_l2_encap_result *res = parsed_result;
15852 
15853 	if (strcmp(res->l2_encap, "l2_encap") == 0)
15854 		l2_encap_conf.select_vlan = 0;
15855 	else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15856 		l2_encap_conf.select_vlan = 1;
15857 	if (strcmp(res->ip_version, "ipv4") == 0)
15858 		l2_encap_conf.select_ipv4 = 1;
15859 	else if (strcmp(res->ip_version, "ipv6") == 0)
15860 		l2_encap_conf.select_ipv4 = 0;
15861 	else
15862 		return;
15863 	if (l2_encap_conf.select_vlan)
15864 		l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15865 	rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15866 		   RTE_ETHER_ADDR_LEN);
15867 	rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15868 		   RTE_ETHER_ADDR_LEN);
15869 }
15870 
15871 cmdline_parse_inst_t cmd_set_l2_encap = {
15872 	.f = cmd_set_l2_encap_parsed,
15873 	.data = NULL,
15874 	.help_str = "set l2_encap ip-version ipv4|ipv6"
15875 		" eth-src <eth-src> eth-dst <eth-dst>",
15876 	.tokens = {
15877 		(void *)&cmd_set_l2_encap_set,
15878 		(void *)&cmd_set_l2_encap_l2_encap,
15879 		(void *)&cmd_set_l2_encap_ip_version,
15880 		(void *)&cmd_set_l2_encap_ip_version_value,
15881 		(void *)&cmd_set_l2_encap_eth_src,
15882 		(void *)&cmd_set_l2_encap_eth_src_value,
15883 		(void *)&cmd_set_l2_encap_eth_dst,
15884 		(void *)&cmd_set_l2_encap_eth_dst_value,
15885 		NULL,
15886 	},
15887 };
15888 
15889 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15890 	.f = cmd_set_l2_encap_parsed,
15891 	.data = NULL,
15892 	.help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15893 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15894 	.tokens = {
15895 		(void *)&cmd_set_l2_encap_set,
15896 		(void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15897 		(void *)&cmd_set_l2_encap_ip_version,
15898 		(void *)&cmd_set_l2_encap_ip_version_value,
15899 		(void *)&cmd_set_l2_encap_vlan,
15900 		(void *)&cmd_set_l2_encap_vlan_value,
15901 		(void *)&cmd_set_l2_encap_eth_src,
15902 		(void *)&cmd_set_l2_encap_eth_src_value,
15903 		(void *)&cmd_set_l2_encap_eth_dst,
15904 		(void *)&cmd_set_l2_encap_eth_dst_value,
15905 		NULL,
15906 	},
15907 };
15908 
15909 /** Set L2 decapsulation details */
15910 struct cmd_set_l2_decap_result {
15911 	cmdline_fixed_string_t set;
15912 	cmdline_fixed_string_t l2_decap;
15913 	cmdline_fixed_string_t pos_token;
15914 	uint32_t vlan_present:1;
15915 };
15916 
15917 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15918 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15919 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15920 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15921 				 "l2_decap");
15922 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15923 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15924 				 "l2_decap-with-vlan");
15925 
15926 static void cmd_set_l2_decap_parsed(void *parsed_result,
15927 	__rte_unused struct cmdline *cl,
15928 	__rte_unused void *data)
15929 {
15930 	struct cmd_set_l2_decap_result *res = parsed_result;
15931 
15932 	if (strcmp(res->l2_decap, "l2_decap") == 0)
15933 		l2_decap_conf.select_vlan = 0;
15934 	else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15935 		l2_decap_conf.select_vlan = 1;
15936 }
15937 
15938 cmdline_parse_inst_t cmd_set_l2_decap = {
15939 	.f = cmd_set_l2_decap_parsed,
15940 	.data = NULL,
15941 	.help_str = "set l2_decap",
15942 	.tokens = {
15943 		(void *)&cmd_set_l2_decap_set,
15944 		(void *)&cmd_set_l2_decap_l2_decap,
15945 		NULL,
15946 	},
15947 };
15948 
15949 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15950 	.f = cmd_set_l2_decap_parsed,
15951 	.data = NULL,
15952 	.help_str = "set l2_decap-with-vlan",
15953 	.tokens = {
15954 		(void *)&cmd_set_l2_decap_set,
15955 		(void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15956 		NULL,
15957 	},
15958 };
15959 
15960 /** Set MPLSoGRE encapsulation details */
15961 struct cmd_set_mplsogre_encap_result {
15962 	cmdline_fixed_string_t set;
15963 	cmdline_fixed_string_t mplsogre;
15964 	cmdline_fixed_string_t pos_token;
15965 	cmdline_fixed_string_t ip_version;
15966 	uint32_t vlan_present:1;
15967 	uint32_t label;
15968 	cmdline_ipaddr_t ip_src;
15969 	cmdline_ipaddr_t ip_dst;
15970 	uint16_t tci;
15971 	struct rte_ether_addr eth_src;
15972 	struct rte_ether_addr eth_dst;
15973 };
15974 
15975 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15976 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15977 				 "set");
15978 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15979 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15980 				 "mplsogre_encap");
15981 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15982 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15983 				 mplsogre, "mplsogre_encap-with-vlan");
15984 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15985 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15986 				 pos_token, "ip-version");
15987 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15988 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15989 				 ip_version, "ipv4#ipv6");
15990 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15991 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15992 				 pos_token, "label");
15993 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15994 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15995 			      UINT32);
15996 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15997 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15998 				 pos_token, "ip-src");
15999 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
16000 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
16001 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
16002 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16003 				 pos_token, "ip-dst");
16004 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16005 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16006 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16007 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16008 				 pos_token, "vlan-tci");
16009 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16010 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16011 			      UINT16);
16012 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16013 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16014 				 pos_token, "eth-src");
16015 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16016 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16017 				    eth_src);
16018 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16019 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16020 				 pos_token, "eth-dst");
16021 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16022 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16023 				    eth_dst);
16024 
16025 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16026 	__rte_unused struct cmdline *cl,
16027 	__rte_unused void *data)
16028 {
16029 	struct cmd_set_mplsogre_encap_result *res = parsed_result;
16030 	union {
16031 		uint32_t mplsogre_label;
16032 		uint8_t label[4];
16033 	} id = {
16034 		.mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16035 	};
16036 
16037 	if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16038 		mplsogre_encap_conf.select_vlan = 0;
16039 	else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16040 		mplsogre_encap_conf.select_vlan = 1;
16041 	if (strcmp(res->ip_version, "ipv4") == 0)
16042 		mplsogre_encap_conf.select_ipv4 = 1;
16043 	else if (strcmp(res->ip_version, "ipv6") == 0)
16044 		mplsogre_encap_conf.select_ipv4 = 0;
16045 	else
16046 		return;
16047 	rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16048 	if (mplsogre_encap_conf.select_ipv4) {
16049 		IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16050 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16051 	} else {
16052 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16053 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16054 	}
16055 	if (mplsogre_encap_conf.select_vlan)
16056 		mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16057 	rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16058 		   RTE_ETHER_ADDR_LEN);
16059 	rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16060 		   RTE_ETHER_ADDR_LEN);
16061 }
16062 
16063 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16064 	.f = cmd_set_mplsogre_encap_parsed,
16065 	.data = NULL,
16066 	.help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16067 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16068 		" eth-dst <eth-dst>",
16069 	.tokens = {
16070 		(void *)&cmd_set_mplsogre_encap_set,
16071 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16072 		(void *)&cmd_set_mplsogre_encap_ip_version,
16073 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
16074 		(void *)&cmd_set_mplsogre_encap_label,
16075 		(void *)&cmd_set_mplsogre_encap_label_value,
16076 		(void *)&cmd_set_mplsogre_encap_ip_src,
16077 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
16078 		(void *)&cmd_set_mplsogre_encap_ip_dst,
16079 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
16080 		(void *)&cmd_set_mplsogre_encap_eth_src,
16081 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
16082 		(void *)&cmd_set_mplsogre_encap_eth_dst,
16083 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
16084 		NULL,
16085 	},
16086 };
16087 
16088 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16089 	.f = cmd_set_mplsogre_encap_parsed,
16090 	.data = NULL,
16091 	.help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16092 		" label <label> ip-src <ip-src> ip-dst <ip-dst>"
16093 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16094 	.tokens = {
16095 		(void *)&cmd_set_mplsogre_encap_set,
16096 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16097 		(void *)&cmd_set_mplsogre_encap_ip_version,
16098 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
16099 		(void *)&cmd_set_mplsogre_encap_label,
16100 		(void *)&cmd_set_mplsogre_encap_label_value,
16101 		(void *)&cmd_set_mplsogre_encap_ip_src,
16102 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
16103 		(void *)&cmd_set_mplsogre_encap_ip_dst,
16104 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
16105 		(void *)&cmd_set_mplsogre_encap_vlan,
16106 		(void *)&cmd_set_mplsogre_encap_vlan_value,
16107 		(void *)&cmd_set_mplsogre_encap_eth_src,
16108 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
16109 		(void *)&cmd_set_mplsogre_encap_eth_dst,
16110 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
16111 		NULL,
16112 	},
16113 };
16114 
16115 /** Set MPLSoGRE decapsulation details */
16116 struct cmd_set_mplsogre_decap_result {
16117 	cmdline_fixed_string_t set;
16118 	cmdline_fixed_string_t mplsogre;
16119 	cmdline_fixed_string_t pos_token;
16120 	cmdline_fixed_string_t ip_version;
16121 	uint32_t vlan_present:1;
16122 };
16123 
16124 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16125 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16126 				 "set");
16127 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16128 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16129 				 "mplsogre_decap");
16130 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16131 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16132 				 mplsogre, "mplsogre_decap-with-vlan");
16133 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16134 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16135 				 pos_token, "ip-version");
16136 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16137 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16138 				 ip_version, "ipv4#ipv6");
16139 
16140 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16141 	__rte_unused struct cmdline *cl,
16142 	__rte_unused void *data)
16143 {
16144 	struct cmd_set_mplsogre_decap_result *res = parsed_result;
16145 
16146 	if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16147 		mplsogre_decap_conf.select_vlan = 0;
16148 	else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16149 		mplsogre_decap_conf.select_vlan = 1;
16150 	if (strcmp(res->ip_version, "ipv4") == 0)
16151 		mplsogre_decap_conf.select_ipv4 = 1;
16152 	else if (strcmp(res->ip_version, "ipv6") == 0)
16153 		mplsogre_decap_conf.select_ipv4 = 0;
16154 }
16155 
16156 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16157 	.f = cmd_set_mplsogre_decap_parsed,
16158 	.data = NULL,
16159 	.help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16160 	.tokens = {
16161 		(void *)&cmd_set_mplsogre_decap_set,
16162 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16163 		(void *)&cmd_set_mplsogre_decap_ip_version,
16164 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
16165 		NULL,
16166 	},
16167 };
16168 
16169 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16170 	.f = cmd_set_mplsogre_decap_parsed,
16171 	.data = NULL,
16172 	.help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16173 	.tokens = {
16174 		(void *)&cmd_set_mplsogre_decap_set,
16175 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16176 		(void *)&cmd_set_mplsogre_decap_ip_version,
16177 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
16178 		NULL,
16179 	},
16180 };
16181 
16182 /** Set MPLSoUDP encapsulation details */
16183 struct cmd_set_mplsoudp_encap_result {
16184 	cmdline_fixed_string_t set;
16185 	cmdline_fixed_string_t mplsoudp;
16186 	cmdline_fixed_string_t pos_token;
16187 	cmdline_fixed_string_t ip_version;
16188 	uint32_t vlan_present:1;
16189 	uint32_t label;
16190 	uint16_t udp_src;
16191 	uint16_t udp_dst;
16192 	cmdline_ipaddr_t ip_src;
16193 	cmdline_ipaddr_t ip_dst;
16194 	uint16_t tci;
16195 	struct rte_ether_addr eth_src;
16196 	struct rte_ether_addr eth_dst;
16197 };
16198 
16199 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16200 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16201 				 "set");
16202 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16203 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16204 				 "mplsoudp_encap");
16205 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16206 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16207 				 mplsoudp, "mplsoudp_encap-with-vlan");
16208 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16209 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16210 				 pos_token, "ip-version");
16211 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16212 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16213 				 ip_version, "ipv4#ipv6");
16214 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16215 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16216 				 pos_token, "label");
16217 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16218 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16219 			      UINT32);
16220 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16221 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16222 				 pos_token, "udp-src");
16223 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16224 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16225 			      UINT16);
16226 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16227 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16228 				 pos_token, "udp-dst");
16229 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16230 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16231 			      UINT16);
16232 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16233 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16234 				 pos_token, "ip-src");
16235 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16236 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16237 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16238 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16239 				 pos_token, "ip-dst");
16240 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16241 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16242 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16243 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16244 				 pos_token, "vlan-tci");
16245 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16246 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16247 			      UINT16);
16248 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16249 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16250 				 pos_token, "eth-src");
16251 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16252 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16253 				    eth_src);
16254 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16255 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16256 				 pos_token, "eth-dst");
16257 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16258 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16259 				    eth_dst);
16260 
16261 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16262 	__rte_unused struct cmdline *cl,
16263 	__rte_unused void *data)
16264 {
16265 	struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16266 	union {
16267 		uint32_t mplsoudp_label;
16268 		uint8_t label[4];
16269 	} id = {
16270 		.mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16271 	};
16272 
16273 	if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16274 		mplsoudp_encap_conf.select_vlan = 0;
16275 	else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16276 		mplsoudp_encap_conf.select_vlan = 1;
16277 	if (strcmp(res->ip_version, "ipv4") == 0)
16278 		mplsoudp_encap_conf.select_ipv4 = 1;
16279 	else if (strcmp(res->ip_version, "ipv6") == 0)
16280 		mplsoudp_encap_conf.select_ipv4 = 0;
16281 	else
16282 		return;
16283 	rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16284 	mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16285 	mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16286 	if (mplsoudp_encap_conf.select_ipv4) {
16287 		IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16288 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16289 	} else {
16290 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16291 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16292 	}
16293 	if (mplsoudp_encap_conf.select_vlan)
16294 		mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16295 	rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16296 		   RTE_ETHER_ADDR_LEN);
16297 	rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16298 		   RTE_ETHER_ADDR_LEN);
16299 }
16300 
16301 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16302 	.f = cmd_set_mplsoudp_encap_parsed,
16303 	.data = NULL,
16304 	.help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16305 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16306 		" ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16307 	.tokens = {
16308 		(void *)&cmd_set_mplsoudp_encap_set,
16309 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16310 		(void *)&cmd_set_mplsoudp_encap_ip_version,
16311 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
16312 		(void *)&cmd_set_mplsoudp_encap_label,
16313 		(void *)&cmd_set_mplsoudp_encap_label_value,
16314 		(void *)&cmd_set_mplsoudp_encap_udp_src,
16315 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
16316 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
16317 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16318 		(void *)&cmd_set_mplsoudp_encap_ip_src,
16319 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
16320 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
16321 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16322 		(void *)&cmd_set_mplsoudp_encap_eth_src,
16323 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
16324 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
16325 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16326 		NULL,
16327 	},
16328 };
16329 
16330 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16331 	.f = cmd_set_mplsoudp_encap_parsed,
16332 	.data = NULL,
16333 	.help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16334 		" label <label> udp-src <udp-src> udp-dst <udp-dst>"
16335 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16336 		" eth-src <eth-src> eth-dst <eth-dst>",
16337 	.tokens = {
16338 		(void *)&cmd_set_mplsoudp_encap_set,
16339 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16340 		(void *)&cmd_set_mplsoudp_encap_ip_version,
16341 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
16342 		(void *)&cmd_set_mplsoudp_encap_label,
16343 		(void *)&cmd_set_mplsoudp_encap_label_value,
16344 		(void *)&cmd_set_mplsoudp_encap_udp_src,
16345 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
16346 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
16347 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16348 		(void *)&cmd_set_mplsoudp_encap_ip_src,
16349 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
16350 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
16351 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16352 		(void *)&cmd_set_mplsoudp_encap_vlan,
16353 		(void *)&cmd_set_mplsoudp_encap_vlan_value,
16354 		(void *)&cmd_set_mplsoudp_encap_eth_src,
16355 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
16356 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
16357 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16358 		NULL,
16359 	},
16360 };
16361 
16362 /** Set MPLSoUDP decapsulation details */
16363 struct cmd_set_mplsoudp_decap_result {
16364 	cmdline_fixed_string_t set;
16365 	cmdline_fixed_string_t mplsoudp;
16366 	cmdline_fixed_string_t pos_token;
16367 	cmdline_fixed_string_t ip_version;
16368 	uint32_t vlan_present:1;
16369 };
16370 
16371 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16372 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16373 				 "set");
16374 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16375 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16376 				 "mplsoudp_decap");
16377 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16378 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16379 				 mplsoudp, "mplsoudp_decap-with-vlan");
16380 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16381 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16382 				 pos_token, "ip-version");
16383 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16384 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16385 				 ip_version, "ipv4#ipv6");
16386 
16387 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16388 	__rte_unused struct cmdline *cl,
16389 	__rte_unused void *data)
16390 {
16391 	struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16392 
16393 	if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16394 		mplsoudp_decap_conf.select_vlan = 0;
16395 	else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16396 		mplsoudp_decap_conf.select_vlan = 1;
16397 	if (strcmp(res->ip_version, "ipv4") == 0)
16398 		mplsoudp_decap_conf.select_ipv4 = 1;
16399 	else if (strcmp(res->ip_version, "ipv6") == 0)
16400 		mplsoudp_decap_conf.select_ipv4 = 0;
16401 }
16402 
16403 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16404 	.f = cmd_set_mplsoudp_decap_parsed,
16405 	.data = NULL,
16406 	.help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16407 	.tokens = {
16408 		(void *)&cmd_set_mplsoudp_decap_set,
16409 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16410 		(void *)&cmd_set_mplsoudp_decap_ip_version,
16411 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
16412 		NULL,
16413 	},
16414 };
16415 
16416 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16417 	.f = cmd_set_mplsoudp_decap_parsed,
16418 	.data = NULL,
16419 	.help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16420 	.tokens = {
16421 		(void *)&cmd_set_mplsoudp_decap_set,
16422 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16423 		(void *)&cmd_set_mplsoudp_decap_ip_version,
16424 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
16425 		NULL,
16426 	},
16427 };
16428 
16429 /* Strict link priority scheduling mode setting */
16430 static void
16431 cmd_strict_link_prio_parsed(
16432 	void *parsed_result,
16433 	__rte_unused struct cmdline *cl,
16434 	__rte_unused void *data)
16435 {
16436 	struct cmd_vf_tc_bw_result *res = parsed_result;
16437 	int ret = -ENOTSUP;
16438 
16439 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16440 		return;
16441 
16442 #ifdef RTE_LIBRTE_I40E_PMD
16443 	ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16444 #endif
16445 
16446 	switch (ret) {
16447 	case 0:
16448 		break;
16449 	case -EINVAL:
16450 		printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16451 		break;
16452 	case -ENODEV:
16453 		printf("invalid port_id %d\n", res->port_id);
16454 		break;
16455 	case -ENOTSUP:
16456 		printf("function not implemented\n");
16457 		break;
16458 	default:
16459 		printf("programming error: (%s)\n", strerror(-ret));
16460 	}
16461 }
16462 
16463 cmdline_parse_inst_t cmd_strict_link_prio = {
16464 	.f = cmd_strict_link_prio_parsed,
16465 	.data = NULL,
16466 	.help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16467 	.tokens = {
16468 		(void *)&cmd_vf_tc_bw_set,
16469 		(void *)&cmd_vf_tc_bw_tx,
16470 		(void *)&cmd_vf_tc_bw_strict_link_prio,
16471 		(void *)&cmd_vf_tc_bw_port_id,
16472 		(void *)&cmd_vf_tc_bw_tc_map,
16473 		NULL,
16474 	},
16475 };
16476 
16477 /* Load dynamic device personalization*/
16478 struct cmd_ddp_add_result {
16479 	cmdline_fixed_string_t ddp;
16480 	cmdline_fixed_string_t add;
16481 	portid_t port_id;
16482 	char filepath[];
16483 };
16484 
16485 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16486 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16487 cmdline_parse_token_string_t cmd_ddp_add_add =
16488 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16489 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16490 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16491 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16492 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16493 
16494 static void
16495 cmd_ddp_add_parsed(
16496 	void *parsed_result,
16497 	__rte_unused struct cmdline *cl,
16498 	__rte_unused void *data)
16499 {
16500 	struct cmd_ddp_add_result *res = parsed_result;
16501 	uint8_t *buff;
16502 	uint32_t size;
16503 	char *filepath;
16504 	char *file_fld[2];
16505 	int file_num;
16506 	int ret = -ENOTSUP;
16507 
16508 	if (!all_ports_stopped()) {
16509 		printf("Please stop all ports first\n");
16510 		return;
16511 	}
16512 
16513 	filepath = strdup(res->filepath);
16514 	if (filepath == NULL) {
16515 		printf("Failed to allocate memory\n");
16516 		return;
16517 	}
16518 	file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16519 
16520 	buff = open_file(file_fld[0], &size);
16521 	if (!buff) {
16522 		free((void *)filepath);
16523 		return;
16524 	}
16525 
16526 #ifdef RTE_LIBRTE_I40E_PMD
16527 	if (ret == -ENOTSUP)
16528 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16529 					       buff, size,
16530 					       RTE_PMD_I40E_PKG_OP_WR_ADD);
16531 #endif
16532 
16533 	if (ret == -EEXIST)
16534 		printf("Profile has already existed.\n");
16535 	else if (ret < 0)
16536 		printf("Failed to load profile.\n");
16537 	else if (file_num == 2)
16538 		save_file(file_fld[1], buff, size);
16539 
16540 	close_file(buff);
16541 	free((void *)filepath);
16542 }
16543 
16544 cmdline_parse_inst_t cmd_ddp_add = {
16545 	.f = cmd_ddp_add_parsed,
16546 	.data = NULL,
16547 	.help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16548 	.tokens = {
16549 		(void *)&cmd_ddp_add_ddp,
16550 		(void *)&cmd_ddp_add_add,
16551 		(void *)&cmd_ddp_add_port_id,
16552 		(void *)&cmd_ddp_add_filepath,
16553 		NULL,
16554 	},
16555 };
16556 
16557 /* Delete dynamic device personalization*/
16558 struct cmd_ddp_del_result {
16559 	cmdline_fixed_string_t ddp;
16560 	cmdline_fixed_string_t del;
16561 	portid_t port_id;
16562 	char filepath[];
16563 };
16564 
16565 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16566 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16567 cmdline_parse_token_string_t cmd_ddp_del_del =
16568 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16569 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16570 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16571 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16572 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16573 
16574 static void
16575 cmd_ddp_del_parsed(
16576 	void *parsed_result,
16577 	__rte_unused struct cmdline *cl,
16578 	__rte_unused void *data)
16579 {
16580 	struct cmd_ddp_del_result *res = parsed_result;
16581 	uint8_t *buff;
16582 	uint32_t size;
16583 	int ret = -ENOTSUP;
16584 
16585 	if (!all_ports_stopped()) {
16586 		printf("Please stop all ports first\n");
16587 		return;
16588 	}
16589 
16590 	buff = open_file(res->filepath, &size);
16591 	if (!buff)
16592 		return;
16593 
16594 #ifdef RTE_LIBRTE_I40E_PMD
16595 	if (ret == -ENOTSUP)
16596 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16597 					       buff, size,
16598 					       RTE_PMD_I40E_PKG_OP_WR_DEL);
16599 #endif
16600 
16601 	if (ret == -EACCES)
16602 		printf("Profile does not exist.\n");
16603 	else if (ret < 0)
16604 		printf("Failed to delete profile.\n");
16605 
16606 	close_file(buff);
16607 }
16608 
16609 cmdline_parse_inst_t cmd_ddp_del = {
16610 	.f = cmd_ddp_del_parsed,
16611 	.data = NULL,
16612 	.help_str = "ddp del <port_id> <backup_profile_path>",
16613 	.tokens = {
16614 		(void *)&cmd_ddp_del_ddp,
16615 		(void *)&cmd_ddp_del_del,
16616 		(void *)&cmd_ddp_del_port_id,
16617 		(void *)&cmd_ddp_del_filepath,
16618 		NULL,
16619 	},
16620 };
16621 
16622 /* Get dynamic device personalization profile info */
16623 struct cmd_ddp_info_result {
16624 	cmdline_fixed_string_t ddp;
16625 	cmdline_fixed_string_t get;
16626 	cmdline_fixed_string_t info;
16627 	char filepath[];
16628 };
16629 
16630 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16631 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16632 cmdline_parse_token_string_t cmd_ddp_info_get =
16633 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16634 cmdline_parse_token_string_t cmd_ddp_info_info =
16635 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16636 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16637 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16638 
16639 static void
16640 cmd_ddp_info_parsed(
16641 	void *parsed_result,
16642 	__rte_unused struct cmdline *cl,
16643 	__rte_unused void *data)
16644 {
16645 	struct cmd_ddp_info_result *res = parsed_result;
16646 	uint8_t *pkg;
16647 	uint32_t pkg_size;
16648 	int ret = -ENOTSUP;
16649 #ifdef RTE_LIBRTE_I40E_PMD
16650 	uint32_t i, j, n;
16651 	uint8_t *buff;
16652 	uint32_t buff_size = 0;
16653 	struct rte_pmd_i40e_profile_info info;
16654 	uint32_t dev_num = 0;
16655 	struct rte_pmd_i40e_ddp_device_id *devs;
16656 	uint32_t proto_num = 0;
16657 	struct rte_pmd_i40e_proto_info *proto = NULL;
16658 	uint32_t pctype_num = 0;
16659 	struct rte_pmd_i40e_ptype_info *pctype;
16660 	uint32_t ptype_num = 0;
16661 	struct rte_pmd_i40e_ptype_info *ptype;
16662 	uint8_t proto_id;
16663 
16664 #endif
16665 
16666 	pkg = open_file(res->filepath, &pkg_size);
16667 	if (!pkg)
16668 		return;
16669 
16670 #ifdef RTE_LIBRTE_I40E_PMD
16671 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16672 				(uint8_t *)&info, sizeof(info),
16673 				RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16674 	if (!ret) {
16675 		printf("Global Track id:       0x%x\n", info.track_id);
16676 		printf("Global Version:        %d.%d.%d.%d\n",
16677 			info.version.major,
16678 			info.version.minor,
16679 			info.version.update,
16680 			info.version.draft);
16681 		printf("Global Package name:   %s\n\n", info.name);
16682 	}
16683 
16684 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16685 				(uint8_t *)&info, sizeof(info),
16686 				RTE_PMD_I40E_PKG_INFO_HEADER);
16687 	if (!ret) {
16688 		printf("i40e Profile Track id: 0x%x\n", info.track_id);
16689 		printf("i40e Profile Version:  %d.%d.%d.%d\n",
16690 			info.version.major,
16691 			info.version.minor,
16692 			info.version.update,
16693 			info.version.draft);
16694 		printf("i40e Profile name:     %s\n\n", info.name);
16695 	}
16696 
16697 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16698 				(uint8_t *)&buff_size, sizeof(buff_size),
16699 				RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16700 	if (!ret && buff_size) {
16701 		buff = (uint8_t *)malloc(buff_size);
16702 		if (buff) {
16703 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16704 						buff, buff_size,
16705 						RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16706 			if (!ret)
16707 				printf("Package Notes:\n%s\n\n", buff);
16708 			free(buff);
16709 		}
16710 	}
16711 
16712 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16713 				(uint8_t *)&dev_num, sizeof(dev_num),
16714 				RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16715 	if (!ret && dev_num) {
16716 		buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16717 		devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16718 		if (devs) {
16719 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16720 						(uint8_t *)devs, buff_size,
16721 						RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16722 			if (!ret) {
16723 				printf("List of supported devices:\n");
16724 				for (i = 0; i < dev_num; i++) {
16725 					printf("  %04X:%04X %04X:%04X\n",
16726 						devs[i].vendor_dev_id >> 16,
16727 						devs[i].vendor_dev_id & 0xFFFF,
16728 						devs[i].sub_vendor_dev_id >> 16,
16729 						devs[i].sub_vendor_dev_id & 0xFFFF);
16730 				}
16731 				printf("\n");
16732 			}
16733 			free(devs);
16734 		}
16735 	}
16736 
16737 	/* get information about protocols and packet types */
16738 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16739 		(uint8_t *)&proto_num, sizeof(proto_num),
16740 		RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16741 	if (ret || !proto_num)
16742 		goto no_print_return;
16743 
16744 	buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16745 	proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16746 	if (!proto)
16747 		goto no_print_return;
16748 
16749 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16750 					buff_size,
16751 					RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16752 	if (!ret) {
16753 		printf("List of used protocols:\n");
16754 		for (i = 0; i < proto_num; i++)
16755 			printf("  %2u: %s\n", proto[i].proto_id,
16756 			       proto[i].name);
16757 		printf("\n");
16758 	}
16759 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16760 		(uint8_t *)&pctype_num, sizeof(pctype_num),
16761 		RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16762 	if (ret || !pctype_num)
16763 		goto no_print_pctypes;
16764 
16765 	buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16766 	pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16767 	if (!pctype)
16768 		goto no_print_pctypes;
16769 
16770 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16771 					buff_size,
16772 					RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16773 	if (ret) {
16774 		free(pctype);
16775 		goto no_print_pctypes;
16776 	}
16777 
16778 	printf("List of defined packet classification types:\n");
16779 	for (i = 0; i < pctype_num; i++) {
16780 		printf("  %2u:", pctype[i].ptype_id);
16781 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16782 			proto_id = pctype[i].protocols[j];
16783 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16784 				for (n = 0; n < proto_num; n++) {
16785 					if (proto[n].proto_id == proto_id) {
16786 						printf(" %s", proto[n].name);
16787 						break;
16788 					}
16789 				}
16790 			}
16791 		}
16792 		printf("\n");
16793 	}
16794 	printf("\n");
16795 	free(pctype);
16796 
16797 no_print_pctypes:
16798 
16799 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16800 					sizeof(ptype_num),
16801 					RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16802 	if (ret || !ptype_num)
16803 		goto no_print_return;
16804 
16805 	buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16806 	ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16807 	if (!ptype)
16808 		goto no_print_return;
16809 
16810 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16811 					buff_size,
16812 					RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16813 	if (ret) {
16814 		free(ptype);
16815 		goto no_print_return;
16816 	}
16817 	printf("List of defined packet types:\n");
16818 	for (i = 0; i < ptype_num; i++) {
16819 		printf("  %2u:", ptype[i].ptype_id);
16820 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16821 			proto_id = ptype[i].protocols[j];
16822 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16823 				for (n = 0; n < proto_num; n++) {
16824 					if (proto[n].proto_id == proto_id) {
16825 						printf(" %s", proto[n].name);
16826 						break;
16827 					}
16828 				}
16829 			}
16830 		}
16831 		printf("\n");
16832 	}
16833 	free(ptype);
16834 	printf("\n");
16835 
16836 	ret = 0;
16837 no_print_return:
16838 	if (proto)
16839 		free(proto);
16840 #endif
16841 	if (ret == -ENOTSUP)
16842 		printf("Function not supported in PMD driver\n");
16843 	close_file(pkg);
16844 }
16845 
16846 cmdline_parse_inst_t cmd_ddp_get_info = {
16847 	.f = cmd_ddp_info_parsed,
16848 	.data = NULL,
16849 	.help_str = "ddp get info <profile_path>",
16850 	.tokens = {
16851 		(void *)&cmd_ddp_info_ddp,
16852 		(void *)&cmd_ddp_info_get,
16853 		(void *)&cmd_ddp_info_info,
16854 		(void *)&cmd_ddp_info_filepath,
16855 		NULL,
16856 	},
16857 };
16858 
16859 /* Get dynamic device personalization profile info list*/
16860 #define PROFILE_INFO_SIZE 48
16861 #define MAX_PROFILE_NUM 16
16862 
16863 struct cmd_ddp_get_list_result {
16864 	cmdline_fixed_string_t ddp;
16865 	cmdline_fixed_string_t get;
16866 	cmdline_fixed_string_t list;
16867 	portid_t port_id;
16868 };
16869 
16870 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16871 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16872 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16873 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16874 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16875 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16876 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16877 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16878 
16879 static void
16880 cmd_ddp_get_list_parsed(
16881 	__rte_unused void *parsed_result,
16882 	__rte_unused struct cmdline *cl,
16883 	__rte_unused void *data)
16884 {
16885 #ifdef RTE_LIBRTE_I40E_PMD
16886 	struct cmd_ddp_get_list_result *res = parsed_result;
16887 	struct rte_pmd_i40e_profile_list *p_list;
16888 	struct rte_pmd_i40e_profile_info *p_info;
16889 	uint32_t p_num;
16890 	uint32_t size;
16891 	uint32_t i;
16892 #endif
16893 	int ret = -ENOTSUP;
16894 
16895 #ifdef RTE_LIBRTE_I40E_PMD
16896 	size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16897 	p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16898 	if (!p_list) {
16899 		printf("%s: Failed to malloc buffer\n", __func__);
16900 		return;
16901 	}
16902 
16903 	if (ret == -ENOTSUP)
16904 		ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16905 						(uint8_t *)p_list, size);
16906 
16907 	if (!ret) {
16908 		p_num = p_list->p_count;
16909 		printf("Profile number is: %d\n\n", p_num);
16910 
16911 		for (i = 0; i < p_num; i++) {
16912 			p_info = &p_list->p_info[i];
16913 			printf("Profile %d:\n", i);
16914 			printf("Track id:     0x%x\n", p_info->track_id);
16915 			printf("Version:      %d.%d.%d.%d\n",
16916 			       p_info->version.major,
16917 			       p_info->version.minor,
16918 			       p_info->version.update,
16919 			       p_info->version.draft);
16920 			printf("Profile name: %s\n\n", p_info->name);
16921 		}
16922 	}
16923 
16924 	free(p_list);
16925 #endif
16926 
16927 	if (ret < 0)
16928 		printf("Failed to get ddp list\n");
16929 }
16930 
16931 cmdline_parse_inst_t cmd_ddp_get_list = {
16932 	.f = cmd_ddp_get_list_parsed,
16933 	.data = NULL,
16934 	.help_str = "ddp get list <port_id>",
16935 	.tokens = {
16936 		(void *)&cmd_ddp_get_list_ddp,
16937 		(void *)&cmd_ddp_get_list_get,
16938 		(void *)&cmd_ddp_get_list_list,
16939 		(void *)&cmd_ddp_get_list_port_id,
16940 		NULL,
16941 	},
16942 };
16943 
16944 /* Configure input set */
16945 struct cmd_cfg_input_set_result {
16946 	cmdline_fixed_string_t port;
16947 	cmdline_fixed_string_t cfg;
16948 	portid_t port_id;
16949 	cmdline_fixed_string_t pctype;
16950 	uint8_t pctype_id;
16951 	cmdline_fixed_string_t inset_type;
16952 	cmdline_fixed_string_t opt;
16953 	cmdline_fixed_string_t field;
16954 	uint8_t field_idx;
16955 };
16956 
16957 static void
16958 cmd_cfg_input_set_parsed(
16959 	__rte_unused void *parsed_result,
16960 	__rte_unused struct cmdline *cl,
16961 	__rte_unused void *data)
16962 {
16963 #ifdef RTE_LIBRTE_I40E_PMD
16964 	struct cmd_cfg_input_set_result *res = parsed_result;
16965 	enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16966 	struct rte_pmd_i40e_inset inset;
16967 #endif
16968 	int ret = -ENOTSUP;
16969 
16970 	if (!all_ports_stopped()) {
16971 		printf("Please stop all ports first\n");
16972 		return;
16973 	}
16974 
16975 #ifdef RTE_LIBRTE_I40E_PMD
16976 	if (!strcmp(res->inset_type, "hash_inset"))
16977 		inset_type = INSET_HASH;
16978 	else if (!strcmp(res->inset_type, "fdir_inset"))
16979 		inset_type = INSET_FDIR;
16980 	else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16981 		inset_type = INSET_FDIR_FLX;
16982 	ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16983 				     &inset, inset_type);
16984 	if (ret) {
16985 		printf("Failed to get input set.\n");
16986 		return;
16987 	}
16988 
16989 	if (!strcmp(res->opt, "get")) {
16990 		ret = rte_pmd_i40e_inset_field_get(inset.inset,
16991 						   res->field_idx);
16992 		if (ret)
16993 			printf("Field index %d is enabled.\n", res->field_idx);
16994 		else
16995 			printf("Field index %d is disabled.\n", res->field_idx);
16996 		return;
16997 	} else if (!strcmp(res->opt, "set"))
16998 		ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16999 						   res->field_idx);
17000 	else if (!strcmp(res->opt, "clear"))
17001 		ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
17002 						     res->field_idx);
17003 	if (ret) {
17004 		printf("Failed to configure input set field.\n");
17005 		return;
17006 	}
17007 
17008 	ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17009 				     &inset, inset_type);
17010 	if (ret) {
17011 		printf("Failed to set input set.\n");
17012 		return;
17013 	}
17014 #endif
17015 
17016 	if (ret == -ENOTSUP)
17017 		printf("Function not supported\n");
17018 }
17019 
17020 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17021 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17022 				 port, "port");
17023 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17024 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17025 				 cfg, "config");
17026 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17027 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17028 			      port_id, UINT16);
17029 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17030 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17031 				 pctype, "pctype");
17032 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17033 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17034 			      pctype_id, UINT8);
17035 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17036 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17037 				 inset_type,
17038 				 "hash_inset#fdir_inset#fdir_flx_inset");
17039 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17040 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17041 				 opt, "get#set#clear");
17042 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17043 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17044 				 field, "field");
17045 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17046 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17047 			      field_idx, UINT8);
17048 
17049 cmdline_parse_inst_t cmd_cfg_input_set = {
17050 	.f = cmd_cfg_input_set_parsed,
17051 	.data = NULL,
17052 	.help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17053 		    "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17054 	.tokens = {
17055 		(void *)&cmd_cfg_input_set_port,
17056 		(void *)&cmd_cfg_input_set_cfg,
17057 		(void *)&cmd_cfg_input_set_port_id,
17058 		(void *)&cmd_cfg_input_set_pctype,
17059 		(void *)&cmd_cfg_input_set_pctype_id,
17060 		(void *)&cmd_cfg_input_set_inset_type,
17061 		(void *)&cmd_cfg_input_set_opt,
17062 		(void *)&cmd_cfg_input_set_field,
17063 		(void *)&cmd_cfg_input_set_field_idx,
17064 		NULL,
17065 	},
17066 };
17067 
17068 /* Clear input set */
17069 struct cmd_clear_input_set_result {
17070 	cmdline_fixed_string_t port;
17071 	cmdline_fixed_string_t cfg;
17072 	portid_t port_id;
17073 	cmdline_fixed_string_t pctype;
17074 	uint8_t pctype_id;
17075 	cmdline_fixed_string_t inset_type;
17076 	cmdline_fixed_string_t clear;
17077 	cmdline_fixed_string_t all;
17078 };
17079 
17080 static void
17081 cmd_clear_input_set_parsed(
17082 	__rte_unused void *parsed_result,
17083 	__rte_unused struct cmdline *cl,
17084 	__rte_unused void *data)
17085 {
17086 #ifdef RTE_LIBRTE_I40E_PMD
17087 	struct cmd_clear_input_set_result *res = parsed_result;
17088 	enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17089 	struct rte_pmd_i40e_inset inset;
17090 #endif
17091 	int ret = -ENOTSUP;
17092 
17093 	if (!all_ports_stopped()) {
17094 		printf("Please stop all ports first\n");
17095 		return;
17096 	}
17097 
17098 #ifdef RTE_LIBRTE_I40E_PMD
17099 	if (!strcmp(res->inset_type, "hash_inset"))
17100 		inset_type = INSET_HASH;
17101 	else if (!strcmp(res->inset_type, "fdir_inset"))
17102 		inset_type = INSET_FDIR;
17103 	else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17104 		inset_type = INSET_FDIR_FLX;
17105 
17106 	memset(&inset, 0, sizeof(inset));
17107 
17108 	ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17109 				     &inset, inset_type);
17110 	if (ret) {
17111 		printf("Failed to clear input set.\n");
17112 		return;
17113 	}
17114 
17115 #endif
17116 
17117 	if (ret == -ENOTSUP)
17118 		printf("Function not supported\n");
17119 }
17120 
17121 cmdline_parse_token_string_t cmd_clear_input_set_port =
17122 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17123 				 port, "port");
17124 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17125 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17126 				 cfg, "config");
17127 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17128 	TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17129 			      port_id, UINT16);
17130 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17131 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17132 				 pctype, "pctype");
17133 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17134 	TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17135 			      pctype_id, UINT8);
17136 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17137 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17138 				 inset_type,
17139 				 "hash_inset#fdir_inset#fdir_flx_inset");
17140 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17141 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17142 				 clear, "clear");
17143 cmdline_parse_token_string_t cmd_clear_input_set_all =
17144 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17145 				 all, "all");
17146 
17147 cmdline_parse_inst_t cmd_clear_input_set = {
17148 	.f = cmd_clear_input_set_parsed,
17149 	.data = NULL,
17150 	.help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17151 		    "fdir_inset|fdir_flx_inset clear all",
17152 	.tokens = {
17153 		(void *)&cmd_clear_input_set_port,
17154 		(void *)&cmd_clear_input_set_cfg,
17155 		(void *)&cmd_clear_input_set_port_id,
17156 		(void *)&cmd_clear_input_set_pctype,
17157 		(void *)&cmd_clear_input_set_pctype_id,
17158 		(void *)&cmd_clear_input_set_inset_type,
17159 		(void *)&cmd_clear_input_set_clear,
17160 		(void *)&cmd_clear_input_set_all,
17161 		NULL,
17162 	},
17163 };
17164 
17165 /* show vf stats */
17166 
17167 /* Common result structure for show vf stats */
17168 struct cmd_show_vf_stats_result {
17169 	cmdline_fixed_string_t show;
17170 	cmdline_fixed_string_t vf;
17171 	cmdline_fixed_string_t stats;
17172 	portid_t port_id;
17173 	uint16_t vf_id;
17174 };
17175 
17176 /* Common CLI fields show vf stats*/
17177 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17178 	TOKEN_STRING_INITIALIZER
17179 		(struct cmd_show_vf_stats_result,
17180 		 show, "show");
17181 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17182 	TOKEN_STRING_INITIALIZER
17183 		(struct cmd_show_vf_stats_result,
17184 		 vf, "vf");
17185 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17186 	TOKEN_STRING_INITIALIZER
17187 		(struct cmd_show_vf_stats_result,
17188 		 stats, "stats");
17189 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17190 	TOKEN_NUM_INITIALIZER
17191 		(struct cmd_show_vf_stats_result,
17192 		 port_id, UINT16);
17193 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17194 	TOKEN_NUM_INITIALIZER
17195 		(struct cmd_show_vf_stats_result,
17196 		 vf_id, UINT16);
17197 
17198 static void
17199 cmd_show_vf_stats_parsed(
17200 	void *parsed_result,
17201 	__rte_unused struct cmdline *cl,
17202 	__rte_unused void *data)
17203 {
17204 	struct cmd_show_vf_stats_result *res = parsed_result;
17205 	struct rte_eth_stats stats;
17206 	int ret = -ENOTSUP;
17207 	static const char *nic_stats_border = "########################";
17208 
17209 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17210 		return;
17211 
17212 	memset(&stats, 0, sizeof(stats));
17213 
17214 #ifdef RTE_LIBRTE_I40E_PMD
17215 	if (ret == -ENOTSUP)
17216 		ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17217 						res->vf_id,
17218 						&stats);
17219 #endif
17220 #ifdef RTE_LIBRTE_BNXT_PMD
17221 	if (ret == -ENOTSUP)
17222 		ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17223 						res->vf_id,
17224 						&stats);
17225 #endif
17226 
17227 	switch (ret) {
17228 	case 0:
17229 		break;
17230 	case -EINVAL:
17231 		printf("invalid vf_id %d\n", res->vf_id);
17232 		break;
17233 	case -ENODEV:
17234 		printf("invalid port_id %d\n", res->port_id);
17235 		break;
17236 	case -ENOTSUP:
17237 		printf("function not implemented\n");
17238 		break;
17239 	default:
17240 		printf("programming error: (%s)\n", strerror(-ret));
17241 	}
17242 
17243 	printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17244 		nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17245 
17246 	printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17247 	       "%-"PRIu64"\n",
17248 	       stats.ipackets, stats.imissed, stats.ibytes);
17249 	printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17250 	printf("  RX-nombuf:  %-10"PRIu64"\n",
17251 	       stats.rx_nombuf);
17252 	printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17253 	       "%-"PRIu64"\n",
17254 	       stats.opackets, stats.oerrors, stats.obytes);
17255 
17256 	printf("  %s############################%s\n",
17257 			       nic_stats_border, nic_stats_border);
17258 }
17259 
17260 cmdline_parse_inst_t cmd_show_vf_stats = {
17261 	.f = cmd_show_vf_stats_parsed,
17262 	.data = NULL,
17263 	.help_str = "show vf stats <port_id> <vf_id>",
17264 	.tokens = {
17265 		(void *)&cmd_show_vf_stats_show,
17266 		(void *)&cmd_show_vf_stats_vf,
17267 		(void *)&cmd_show_vf_stats_stats,
17268 		(void *)&cmd_show_vf_stats_port_id,
17269 		(void *)&cmd_show_vf_stats_vf_id,
17270 		NULL,
17271 	},
17272 };
17273 
17274 /* clear vf stats */
17275 
17276 /* Common result structure for clear vf stats */
17277 struct cmd_clear_vf_stats_result {
17278 	cmdline_fixed_string_t clear;
17279 	cmdline_fixed_string_t vf;
17280 	cmdline_fixed_string_t stats;
17281 	portid_t port_id;
17282 	uint16_t vf_id;
17283 };
17284 
17285 /* Common CLI fields clear vf stats*/
17286 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17287 	TOKEN_STRING_INITIALIZER
17288 		(struct cmd_clear_vf_stats_result,
17289 		 clear, "clear");
17290 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17291 	TOKEN_STRING_INITIALIZER
17292 		(struct cmd_clear_vf_stats_result,
17293 		 vf, "vf");
17294 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17295 	TOKEN_STRING_INITIALIZER
17296 		(struct cmd_clear_vf_stats_result,
17297 		 stats, "stats");
17298 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17299 	TOKEN_NUM_INITIALIZER
17300 		(struct cmd_clear_vf_stats_result,
17301 		 port_id, UINT16);
17302 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17303 	TOKEN_NUM_INITIALIZER
17304 		(struct cmd_clear_vf_stats_result,
17305 		 vf_id, UINT16);
17306 
17307 static void
17308 cmd_clear_vf_stats_parsed(
17309 	void *parsed_result,
17310 	__rte_unused struct cmdline *cl,
17311 	__rte_unused void *data)
17312 {
17313 	struct cmd_clear_vf_stats_result *res = parsed_result;
17314 	int ret = -ENOTSUP;
17315 
17316 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17317 		return;
17318 
17319 #ifdef RTE_LIBRTE_I40E_PMD
17320 	if (ret == -ENOTSUP)
17321 		ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17322 						  res->vf_id);
17323 #endif
17324 #ifdef RTE_LIBRTE_BNXT_PMD
17325 	if (ret == -ENOTSUP)
17326 		ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17327 						  res->vf_id);
17328 #endif
17329 
17330 	switch (ret) {
17331 	case 0:
17332 		break;
17333 	case -EINVAL:
17334 		printf("invalid vf_id %d\n", res->vf_id);
17335 		break;
17336 	case -ENODEV:
17337 		printf("invalid port_id %d\n", res->port_id);
17338 		break;
17339 	case -ENOTSUP:
17340 		printf("function not implemented\n");
17341 		break;
17342 	default:
17343 		printf("programming error: (%s)\n", strerror(-ret));
17344 	}
17345 }
17346 
17347 cmdline_parse_inst_t cmd_clear_vf_stats = {
17348 	.f = cmd_clear_vf_stats_parsed,
17349 	.data = NULL,
17350 	.help_str = "clear vf stats <port_id> <vf_id>",
17351 	.tokens = {
17352 		(void *)&cmd_clear_vf_stats_clear,
17353 		(void *)&cmd_clear_vf_stats_vf,
17354 		(void *)&cmd_clear_vf_stats_stats,
17355 		(void *)&cmd_clear_vf_stats_port_id,
17356 		(void *)&cmd_clear_vf_stats_vf_id,
17357 		NULL,
17358 	},
17359 };
17360 
17361 /* port config pctype mapping reset */
17362 
17363 /* Common result structure for port config pctype mapping reset */
17364 struct cmd_pctype_mapping_reset_result {
17365 	cmdline_fixed_string_t port;
17366 	cmdline_fixed_string_t config;
17367 	portid_t port_id;
17368 	cmdline_fixed_string_t pctype;
17369 	cmdline_fixed_string_t mapping;
17370 	cmdline_fixed_string_t reset;
17371 };
17372 
17373 /* Common CLI fields for port config pctype mapping reset*/
17374 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17375 	TOKEN_STRING_INITIALIZER
17376 		(struct cmd_pctype_mapping_reset_result,
17377 		 port, "port");
17378 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17379 	TOKEN_STRING_INITIALIZER
17380 		(struct cmd_pctype_mapping_reset_result,
17381 		 config, "config");
17382 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17383 	TOKEN_NUM_INITIALIZER
17384 		(struct cmd_pctype_mapping_reset_result,
17385 		 port_id, UINT16);
17386 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17387 	TOKEN_STRING_INITIALIZER
17388 		(struct cmd_pctype_mapping_reset_result,
17389 		 pctype, "pctype");
17390 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17391 	TOKEN_STRING_INITIALIZER
17392 		(struct cmd_pctype_mapping_reset_result,
17393 		 mapping, "mapping");
17394 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17395 	TOKEN_STRING_INITIALIZER
17396 		(struct cmd_pctype_mapping_reset_result,
17397 		 reset, "reset");
17398 
17399 static void
17400 cmd_pctype_mapping_reset_parsed(
17401 	void *parsed_result,
17402 	__rte_unused struct cmdline *cl,
17403 	__rte_unused void *data)
17404 {
17405 	struct cmd_pctype_mapping_reset_result *res = parsed_result;
17406 	int ret = -ENOTSUP;
17407 
17408 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17409 		return;
17410 
17411 #ifdef RTE_LIBRTE_I40E_PMD
17412 	ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17413 #endif
17414 
17415 	switch (ret) {
17416 	case 0:
17417 		break;
17418 	case -ENODEV:
17419 		printf("invalid port_id %d\n", res->port_id);
17420 		break;
17421 	case -ENOTSUP:
17422 		printf("function not implemented\n");
17423 		break;
17424 	default:
17425 		printf("programming error: (%s)\n", strerror(-ret));
17426 	}
17427 }
17428 
17429 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17430 	.f = cmd_pctype_mapping_reset_parsed,
17431 	.data = NULL,
17432 	.help_str = "port config <port_id> pctype mapping reset",
17433 	.tokens = {
17434 		(void *)&cmd_pctype_mapping_reset_port,
17435 		(void *)&cmd_pctype_mapping_reset_config,
17436 		(void *)&cmd_pctype_mapping_reset_port_id,
17437 		(void *)&cmd_pctype_mapping_reset_pctype,
17438 		(void *)&cmd_pctype_mapping_reset_mapping,
17439 		(void *)&cmd_pctype_mapping_reset_reset,
17440 		NULL,
17441 	},
17442 };
17443 
17444 /* show port pctype mapping */
17445 
17446 /* Common result structure for show port pctype mapping */
17447 struct cmd_pctype_mapping_get_result {
17448 	cmdline_fixed_string_t show;
17449 	cmdline_fixed_string_t port;
17450 	portid_t port_id;
17451 	cmdline_fixed_string_t pctype;
17452 	cmdline_fixed_string_t mapping;
17453 };
17454 
17455 /* Common CLI fields for pctype mapping get */
17456 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17457 	TOKEN_STRING_INITIALIZER
17458 		(struct cmd_pctype_mapping_get_result,
17459 		 show, "show");
17460 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17461 	TOKEN_STRING_INITIALIZER
17462 		(struct cmd_pctype_mapping_get_result,
17463 		 port, "port");
17464 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17465 	TOKEN_NUM_INITIALIZER
17466 		(struct cmd_pctype_mapping_get_result,
17467 		 port_id, UINT16);
17468 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17469 	TOKEN_STRING_INITIALIZER
17470 		(struct cmd_pctype_mapping_get_result,
17471 		 pctype, "pctype");
17472 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17473 	TOKEN_STRING_INITIALIZER
17474 		(struct cmd_pctype_mapping_get_result,
17475 		 mapping, "mapping");
17476 
17477 static void
17478 cmd_pctype_mapping_get_parsed(
17479 	void *parsed_result,
17480 	__rte_unused struct cmdline *cl,
17481 	__rte_unused void *data)
17482 {
17483 	struct cmd_pctype_mapping_get_result *res = parsed_result;
17484 	int ret = -ENOTSUP;
17485 #ifdef RTE_LIBRTE_I40E_PMD
17486 	struct rte_pmd_i40e_flow_type_mapping
17487 				mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17488 	int i, j, first_pctype;
17489 #endif
17490 
17491 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17492 		return;
17493 
17494 #ifdef RTE_LIBRTE_I40E_PMD
17495 	ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17496 #endif
17497 
17498 	switch (ret) {
17499 	case 0:
17500 		break;
17501 	case -ENODEV:
17502 		printf("invalid port_id %d\n", res->port_id);
17503 		return;
17504 	case -ENOTSUP:
17505 		printf("function not implemented\n");
17506 		return;
17507 	default:
17508 		printf("programming error: (%s)\n", strerror(-ret));
17509 		return;
17510 	}
17511 
17512 #ifdef RTE_LIBRTE_I40E_PMD
17513 	for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17514 		if (mapping[i].pctype != 0ULL) {
17515 			first_pctype = 1;
17516 
17517 			printf("pctype: ");
17518 			for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17519 				if (mapping[i].pctype & (1ULL << j)) {
17520 					printf(first_pctype ?
17521 					       "%02d" : ",%02d", j);
17522 					first_pctype = 0;
17523 				}
17524 			}
17525 			printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17526 		}
17527 	}
17528 #endif
17529 }
17530 
17531 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17532 	.f = cmd_pctype_mapping_get_parsed,
17533 	.data = NULL,
17534 	.help_str = "show port <port_id> pctype mapping",
17535 	.tokens = {
17536 		(void *)&cmd_pctype_mapping_get_show,
17537 		(void *)&cmd_pctype_mapping_get_port,
17538 		(void *)&cmd_pctype_mapping_get_port_id,
17539 		(void *)&cmd_pctype_mapping_get_pctype,
17540 		(void *)&cmd_pctype_mapping_get_mapping,
17541 		NULL,
17542 	},
17543 };
17544 
17545 /* port config pctype mapping update */
17546 
17547 /* Common result structure for port config pctype mapping update */
17548 struct cmd_pctype_mapping_update_result {
17549 	cmdline_fixed_string_t port;
17550 	cmdline_fixed_string_t config;
17551 	portid_t port_id;
17552 	cmdline_fixed_string_t pctype;
17553 	cmdline_fixed_string_t mapping;
17554 	cmdline_fixed_string_t update;
17555 	cmdline_fixed_string_t pctype_list;
17556 	uint16_t flow_type;
17557 };
17558 
17559 /* Common CLI fields for pctype mapping update*/
17560 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17561 	TOKEN_STRING_INITIALIZER
17562 		(struct cmd_pctype_mapping_update_result,
17563 		 port, "port");
17564 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17565 	TOKEN_STRING_INITIALIZER
17566 		(struct cmd_pctype_mapping_update_result,
17567 		 config, "config");
17568 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17569 	TOKEN_NUM_INITIALIZER
17570 		(struct cmd_pctype_mapping_update_result,
17571 		 port_id, UINT16);
17572 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17573 	TOKEN_STRING_INITIALIZER
17574 		(struct cmd_pctype_mapping_update_result,
17575 		 pctype, "pctype");
17576 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17577 	TOKEN_STRING_INITIALIZER
17578 		(struct cmd_pctype_mapping_update_result,
17579 		 mapping, "mapping");
17580 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17581 	TOKEN_STRING_INITIALIZER
17582 		(struct cmd_pctype_mapping_update_result,
17583 		 update, "update");
17584 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17585 	TOKEN_STRING_INITIALIZER
17586 		(struct cmd_pctype_mapping_update_result,
17587 		 pctype_list, NULL);
17588 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17589 	TOKEN_NUM_INITIALIZER
17590 		(struct cmd_pctype_mapping_update_result,
17591 		 flow_type, UINT16);
17592 
17593 static void
17594 cmd_pctype_mapping_update_parsed(
17595 	void *parsed_result,
17596 	__rte_unused struct cmdline *cl,
17597 	__rte_unused void *data)
17598 {
17599 	struct cmd_pctype_mapping_update_result *res = parsed_result;
17600 	int ret = -ENOTSUP;
17601 #ifdef RTE_LIBRTE_I40E_PMD
17602 	struct rte_pmd_i40e_flow_type_mapping mapping;
17603 	unsigned int i;
17604 	unsigned int nb_item;
17605 	unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17606 #endif
17607 
17608 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17609 		return;
17610 
17611 #ifdef RTE_LIBRTE_I40E_PMD
17612 	nb_item = parse_item_list(res->pctype_list, "pctypes",
17613 				  RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17614 	mapping.flow_type = res->flow_type;
17615 	for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17616 		mapping.pctype |= (1ULL << pctype_list[i]);
17617 	ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17618 						&mapping,
17619 						1,
17620 						0);
17621 #endif
17622 
17623 	switch (ret) {
17624 	case 0:
17625 		break;
17626 	case -EINVAL:
17627 		printf("invalid pctype or flow type\n");
17628 		break;
17629 	case -ENODEV:
17630 		printf("invalid port_id %d\n", res->port_id);
17631 		break;
17632 	case -ENOTSUP:
17633 		printf("function not implemented\n");
17634 		break;
17635 	default:
17636 		printf("programming error: (%s)\n", strerror(-ret));
17637 	}
17638 }
17639 
17640 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17641 	.f = cmd_pctype_mapping_update_parsed,
17642 	.data = NULL,
17643 	.help_str = "port config <port_id> pctype mapping update"
17644 	" <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17645 	.tokens = {
17646 		(void *)&cmd_pctype_mapping_update_port,
17647 		(void *)&cmd_pctype_mapping_update_config,
17648 		(void *)&cmd_pctype_mapping_update_port_id,
17649 		(void *)&cmd_pctype_mapping_update_pctype,
17650 		(void *)&cmd_pctype_mapping_update_mapping,
17651 		(void *)&cmd_pctype_mapping_update_update,
17652 		(void *)&cmd_pctype_mapping_update_pc_type,
17653 		(void *)&cmd_pctype_mapping_update_flow_type,
17654 		NULL,
17655 	},
17656 };
17657 
17658 /* ptype mapping get */
17659 
17660 /* Common result structure for ptype mapping get */
17661 struct cmd_ptype_mapping_get_result {
17662 	cmdline_fixed_string_t ptype;
17663 	cmdline_fixed_string_t mapping;
17664 	cmdline_fixed_string_t get;
17665 	portid_t port_id;
17666 	uint8_t valid_only;
17667 };
17668 
17669 /* Common CLI fields for ptype mapping get */
17670 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17671 	TOKEN_STRING_INITIALIZER
17672 		(struct cmd_ptype_mapping_get_result,
17673 		 ptype, "ptype");
17674 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17675 	TOKEN_STRING_INITIALIZER
17676 		(struct cmd_ptype_mapping_get_result,
17677 		 mapping, "mapping");
17678 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17679 	TOKEN_STRING_INITIALIZER
17680 		(struct cmd_ptype_mapping_get_result,
17681 		 get, "get");
17682 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17683 	TOKEN_NUM_INITIALIZER
17684 		(struct cmd_ptype_mapping_get_result,
17685 		 port_id, UINT16);
17686 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17687 	TOKEN_NUM_INITIALIZER
17688 		(struct cmd_ptype_mapping_get_result,
17689 		 valid_only, UINT8);
17690 
17691 static void
17692 cmd_ptype_mapping_get_parsed(
17693 	void *parsed_result,
17694 	__rte_unused struct cmdline *cl,
17695 	__rte_unused void *data)
17696 {
17697 	struct cmd_ptype_mapping_get_result *res = parsed_result;
17698 	int ret = -ENOTSUP;
17699 #ifdef RTE_LIBRTE_I40E_PMD
17700 	int max_ptype_num = 256;
17701 	struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17702 	uint16_t count;
17703 	int i;
17704 #endif
17705 
17706 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17707 		return;
17708 
17709 #ifdef RTE_LIBRTE_I40E_PMD
17710 	ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17711 					mapping,
17712 					max_ptype_num,
17713 					&count,
17714 					res->valid_only);
17715 #endif
17716 
17717 	switch (ret) {
17718 	case 0:
17719 		break;
17720 	case -ENODEV:
17721 		printf("invalid port_id %d\n", res->port_id);
17722 		break;
17723 	case -ENOTSUP:
17724 		printf("function not implemented\n");
17725 		break;
17726 	default:
17727 		printf("programming error: (%s)\n", strerror(-ret));
17728 	}
17729 
17730 #ifdef RTE_LIBRTE_I40E_PMD
17731 	if (!ret) {
17732 		for (i = 0; i < count; i++)
17733 			printf("%3d\t0x%08x\n",
17734 				mapping[i].hw_ptype, mapping[i].sw_ptype);
17735 	}
17736 #endif
17737 }
17738 
17739 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17740 	.f = cmd_ptype_mapping_get_parsed,
17741 	.data = NULL,
17742 	.help_str = "ptype mapping get <port_id> <valid_only>",
17743 	.tokens = {
17744 		(void *)&cmd_ptype_mapping_get_ptype,
17745 		(void *)&cmd_ptype_mapping_get_mapping,
17746 		(void *)&cmd_ptype_mapping_get_get,
17747 		(void *)&cmd_ptype_mapping_get_port_id,
17748 		(void *)&cmd_ptype_mapping_get_valid_only,
17749 		NULL,
17750 	},
17751 };
17752 
17753 /* ptype mapping replace */
17754 
17755 /* Common result structure for ptype mapping replace */
17756 struct cmd_ptype_mapping_replace_result {
17757 	cmdline_fixed_string_t ptype;
17758 	cmdline_fixed_string_t mapping;
17759 	cmdline_fixed_string_t replace;
17760 	portid_t port_id;
17761 	uint32_t target;
17762 	uint8_t mask;
17763 	uint32_t pkt_type;
17764 };
17765 
17766 /* Common CLI fields for ptype mapping replace */
17767 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17768 	TOKEN_STRING_INITIALIZER
17769 		(struct cmd_ptype_mapping_replace_result,
17770 		 ptype, "ptype");
17771 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17772 	TOKEN_STRING_INITIALIZER
17773 		(struct cmd_ptype_mapping_replace_result,
17774 		 mapping, "mapping");
17775 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17776 	TOKEN_STRING_INITIALIZER
17777 		(struct cmd_ptype_mapping_replace_result,
17778 		 replace, "replace");
17779 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17780 	TOKEN_NUM_INITIALIZER
17781 		(struct cmd_ptype_mapping_replace_result,
17782 		 port_id, UINT16);
17783 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17784 	TOKEN_NUM_INITIALIZER
17785 		(struct cmd_ptype_mapping_replace_result,
17786 		 target, UINT32);
17787 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17788 	TOKEN_NUM_INITIALIZER
17789 		(struct cmd_ptype_mapping_replace_result,
17790 		 mask, UINT8);
17791 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17792 	TOKEN_NUM_INITIALIZER
17793 		(struct cmd_ptype_mapping_replace_result,
17794 		 pkt_type, UINT32);
17795 
17796 static void
17797 cmd_ptype_mapping_replace_parsed(
17798 	void *parsed_result,
17799 	__rte_unused struct cmdline *cl,
17800 	__rte_unused void *data)
17801 {
17802 	struct cmd_ptype_mapping_replace_result *res = parsed_result;
17803 	int ret = -ENOTSUP;
17804 
17805 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17806 		return;
17807 
17808 #ifdef RTE_LIBRTE_I40E_PMD
17809 	ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17810 					res->target,
17811 					res->mask,
17812 					res->pkt_type);
17813 #endif
17814 
17815 	switch (ret) {
17816 	case 0:
17817 		break;
17818 	case -EINVAL:
17819 		printf("invalid ptype 0x%8x or 0x%8x\n",
17820 				res->target, res->pkt_type);
17821 		break;
17822 	case -ENODEV:
17823 		printf("invalid port_id %d\n", res->port_id);
17824 		break;
17825 	case -ENOTSUP:
17826 		printf("function not implemented\n");
17827 		break;
17828 	default:
17829 		printf("programming error: (%s)\n", strerror(-ret));
17830 	}
17831 }
17832 
17833 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17834 	.f = cmd_ptype_mapping_replace_parsed,
17835 	.data = NULL,
17836 	.help_str =
17837 		"ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17838 	.tokens = {
17839 		(void *)&cmd_ptype_mapping_replace_ptype,
17840 		(void *)&cmd_ptype_mapping_replace_mapping,
17841 		(void *)&cmd_ptype_mapping_replace_replace,
17842 		(void *)&cmd_ptype_mapping_replace_port_id,
17843 		(void *)&cmd_ptype_mapping_replace_target,
17844 		(void *)&cmd_ptype_mapping_replace_mask,
17845 		(void *)&cmd_ptype_mapping_replace_pkt_type,
17846 		NULL,
17847 	},
17848 };
17849 
17850 /* ptype mapping reset */
17851 
17852 /* Common result structure for ptype mapping reset */
17853 struct cmd_ptype_mapping_reset_result {
17854 	cmdline_fixed_string_t ptype;
17855 	cmdline_fixed_string_t mapping;
17856 	cmdline_fixed_string_t reset;
17857 	portid_t port_id;
17858 };
17859 
17860 /* Common CLI fields for ptype mapping reset*/
17861 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17862 	TOKEN_STRING_INITIALIZER
17863 		(struct cmd_ptype_mapping_reset_result,
17864 		 ptype, "ptype");
17865 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17866 	TOKEN_STRING_INITIALIZER
17867 		(struct cmd_ptype_mapping_reset_result,
17868 		 mapping, "mapping");
17869 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17870 	TOKEN_STRING_INITIALIZER
17871 		(struct cmd_ptype_mapping_reset_result,
17872 		 reset, "reset");
17873 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17874 	TOKEN_NUM_INITIALIZER
17875 		(struct cmd_ptype_mapping_reset_result,
17876 		 port_id, UINT16);
17877 
17878 static void
17879 cmd_ptype_mapping_reset_parsed(
17880 	void *parsed_result,
17881 	__rte_unused struct cmdline *cl,
17882 	__rte_unused void *data)
17883 {
17884 	struct cmd_ptype_mapping_reset_result *res = parsed_result;
17885 	int ret = -ENOTSUP;
17886 
17887 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17888 		return;
17889 
17890 #ifdef RTE_LIBRTE_I40E_PMD
17891 	ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17892 #endif
17893 
17894 	switch (ret) {
17895 	case 0:
17896 		break;
17897 	case -ENODEV:
17898 		printf("invalid port_id %d\n", res->port_id);
17899 		break;
17900 	case -ENOTSUP:
17901 		printf("function not implemented\n");
17902 		break;
17903 	default:
17904 		printf("programming error: (%s)\n", strerror(-ret));
17905 	}
17906 }
17907 
17908 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17909 	.f = cmd_ptype_mapping_reset_parsed,
17910 	.data = NULL,
17911 	.help_str = "ptype mapping reset <port_id>",
17912 	.tokens = {
17913 		(void *)&cmd_ptype_mapping_reset_ptype,
17914 		(void *)&cmd_ptype_mapping_reset_mapping,
17915 		(void *)&cmd_ptype_mapping_reset_reset,
17916 		(void *)&cmd_ptype_mapping_reset_port_id,
17917 		NULL,
17918 	},
17919 };
17920 
17921 /* ptype mapping update */
17922 
17923 /* Common result structure for ptype mapping update */
17924 struct cmd_ptype_mapping_update_result {
17925 	cmdline_fixed_string_t ptype;
17926 	cmdline_fixed_string_t mapping;
17927 	cmdline_fixed_string_t reset;
17928 	portid_t port_id;
17929 	uint8_t hw_ptype;
17930 	uint32_t sw_ptype;
17931 };
17932 
17933 /* Common CLI fields for ptype mapping update*/
17934 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17935 	TOKEN_STRING_INITIALIZER
17936 		(struct cmd_ptype_mapping_update_result,
17937 		 ptype, "ptype");
17938 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17939 	TOKEN_STRING_INITIALIZER
17940 		(struct cmd_ptype_mapping_update_result,
17941 		 mapping, "mapping");
17942 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17943 	TOKEN_STRING_INITIALIZER
17944 		(struct cmd_ptype_mapping_update_result,
17945 		 reset, "update");
17946 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17947 	TOKEN_NUM_INITIALIZER
17948 		(struct cmd_ptype_mapping_update_result,
17949 		 port_id, UINT16);
17950 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17951 	TOKEN_NUM_INITIALIZER
17952 		(struct cmd_ptype_mapping_update_result,
17953 		 hw_ptype, UINT8);
17954 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17955 	TOKEN_NUM_INITIALIZER
17956 		(struct cmd_ptype_mapping_update_result,
17957 		 sw_ptype, UINT32);
17958 
17959 static void
17960 cmd_ptype_mapping_update_parsed(
17961 	void *parsed_result,
17962 	__rte_unused struct cmdline *cl,
17963 	__rte_unused void *data)
17964 {
17965 	struct cmd_ptype_mapping_update_result *res = parsed_result;
17966 	int ret = -ENOTSUP;
17967 #ifdef RTE_LIBRTE_I40E_PMD
17968 	struct rte_pmd_i40e_ptype_mapping mapping;
17969 #endif
17970 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17971 		return;
17972 
17973 #ifdef RTE_LIBRTE_I40E_PMD
17974 	mapping.hw_ptype = res->hw_ptype;
17975 	mapping.sw_ptype = res->sw_ptype;
17976 	ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17977 						&mapping,
17978 						1,
17979 						0);
17980 #endif
17981 
17982 	switch (ret) {
17983 	case 0:
17984 		break;
17985 	case -EINVAL:
17986 		printf("invalid ptype 0x%8x\n", res->sw_ptype);
17987 		break;
17988 	case -ENODEV:
17989 		printf("invalid port_id %d\n", res->port_id);
17990 		break;
17991 	case -ENOTSUP:
17992 		printf("function not implemented\n");
17993 		break;
17994 	default:
17995 		printf("programming error: (%s)\n", strerror(-ret));
17996 	}
17997 }
17998 
17999 cmdline_parse_inst_t cmd_ptype_mapping_update = {
18000 	.f = cmd_ptype_mapping_update_parsed,
18001 	.data = NULL,
18002 	.help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
18003 	.tokens = {
18004 		(void *)&cmd_ptype_mapping_update_ptype,
18005 		(void *)&cmd_ptype_mapping_update_mapping,
18006 		(void *)&cmd_ptype_mapping_update_update,
18007 		(void *)&cmd_ptype_mapping_update_port_id,
18008 		(void *)&cmd_ptype_mapping_update_hw_ptype,
18009 		(void *)&cmd_ptype_mapping_update_sw_ptype,
18010 		NULL,
18011 	},
18012 };
18013 
18014 /* Common result structure for file commands */
18015 struct cmd_cmdfile_result {
18016 	cmdline_fixed_string_t load;
18017 	cmdline_fixed_string_t filename;
18018 };
18019 
18020 /* Common CLI fields for file commands */
18021 cmdline_parse_token_string_t cmd_load_cmdfile =
18022 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18023 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18024 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18025 
18026 static void
18027 cmd_load_from_file_parsed(
18028 	void *parsed_result,
18029 	__rte_unused struct cmdline *cl,
18030 	__rte_unused void *data)
18031 {
18032 	struct cmd_cmdfile_result *res = parsed_result;
18033 
18034 	cmdline_read_from_file(res->filename);
18035 }
18036 
18037 cmdline_parse_inst_t cmd_load_from_file = {
18038 	.f = cmd_load_from_file_parsed,
18039 	.data = NULL,
18040 	.help_str = "load <filename>",
18041 	.tokens = {
18042 		(void *)&cmd_load_cmdfile,
18043 		(void *)&cmd_load_cmdfile_filename,
18044 		NULL,
18045 	},
18046 };
18047 
18048 /* Get Rx offloads capabilities */
18049 struct cmd_rx_offload_get_capa_result {
18050 	cmdline_fixed_string_t show;
18051 	cmdline_fixed_string_t port;
18052 	portid_t port_id;
18053 	cmdline_fixed_string_t rx_offload;
18054 	cmdline_fixed_string_t capabilities;
18055 };
18056 
18057 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18058 	TOKEN_STRING_INITIALIZER
18059 		(struct cmd_rx_offload_get_capa_result,
18060 		 show, "show");
18061 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18062 	TOKEN_STRING_INITIALIZER
18063 		(struct cmd_rx_offload_get_capa_result,
18064 		 port, "port");
18065 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18066 	TOKEN_NUM_INITIALIZER
18067 		(struct cmd_rx_offload_get_capa_result,
18068 		 port_id, UINT16);
18069 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18070 	TOKEN_STRING_INITIALIZER
18071 		(struct cmd_rx_offload_get_capa_result,
18072 		 rx_offload, "rx_offload");
18073 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18074 	TOKEN_STRING_INITIALIZER
18075 		(struct cmd_rx_offload_get_capa_result,
18076 		 capabilities, "capabilities");
18077 
18078 static void
18079 print_rx_offloads(uint64_t offloads)
18080 {
18081 	uint64_t single_offload;
18082 	int begin;
18083 	int end;
18084 	int bit;
18085 
18086 	if (offloads == 0)
18087 		return;
18088 
18089 	begin = __builtin_ctzll(offloads);
18090 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18091 
18092 	single_offload = 1ULL << begin;
18093 	for (bit = begin; bit < end; bit++) {
18094 		if (offloads & single_offload)
18095 			printf(" %s",
18096 			       rte_eth_dev_rx_offload_name(single_offload));
18097 		single_offload <<= 1;
18098 	}
18099 }
18100 
18101 static void
18102 cmd_rx_offload_get_capa_parsed(
18103 	void *parsed_result,
18104 	__rte_unused struct cmdline *cl,
18105 	__rte_unused void *data)
18106 {
18107 	struct cmd_rx_offload_get_capa_result *res = parsed_result;
18108 	struct rte_eth_dev_info dev_info;
18109 	portid_t port_id = res->port_id;
18110 	uint64_t queue_offloads;
18111 	uint64_t port_offloads;
18112 	int ret;
18113 
18114 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18115 	if (ret != 0)
18116 		return;
18117 
18118 	queue_offloads = dev_info.rx_queue_offload_capa;
18119 	port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18120 
18121 	printf("Rx Offloading Capabilities of port %d :\n", port_id);
18122 	printf("  Per Queue :");
18123 	print_rx_offloads(queue_offloads);
18124 
18125 	printf("\n");
18126 	printf("  Per Port  :");
18127 	print_rx_offloads(port_offloads);
18128 	printf("\n\n");
18129 }
18130 
18131 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18132 	.f = cmd_rx_offload_get_capa_parsed,
18133 	.data = NULL,
18134 	.help_str = "show port <port_id> rx_offload capabilities",
18135 	.tokens = {
18136 		(void *)&cmd_rx_offload_get_capa_show,
18137 		(void *)&cmd_rx_offload_get_capa_port,
18138 		(void *)&cmd_rx_offload_get_capa_port_id,
18139 		(void *)&cmd_rx_offload_get_capa_rx_offload,
18140 		(void *)&cmd_rx_offload_get_capa_capabilities,
18141 		NULL,
18142 	}
18143 };
18144 
18145 /* Get Rx offloads configuration */
18146 struct cmd_rx_offload_get_configuration_result {
18147 	cmdline_fixed_string_t show;
18148 	cmdline_fixed_string_t port;
18149 	portid_t port_id;
18150 	cmdline_fixed_string_t rx_offload;
18151 	cmdline_fixed_string_t configuration;
18152 };
18153 
18154 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18155 	TOKEN_STRING_INITIALIZER
18156 		(struct cmd_rx_offload_get_configuration_result,
18157 		 show, "show");
18158 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18159 	TOKEN_STRING_INITIALIZER
18160 		(struct cmd_rx_offload_get_configuration_result,
18161 		 port, "port");
18162 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18163 	TOKEN_NUM_INITIALIZER
18164 		(struct cmd_rx_offload_get_configuration_result,
18165 		 port_id, UINT16);
18166 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18167 	TOKEN_STRING_INITIALIZER
18168 		(struct cmd_rx_offload_get_configuration_result,
18169 		 rx_offload, "rx_offload");
18170 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18171 	TOKEN_STRING_INITIALIZER
18172 		(struct cmd_rx_offload_get_configuration_result,
18173 		 configuration, "configuration");
18174 
18175 static void
18176 cmd_rx_offload_get_configuration_parsed(
18177 	void *parsed_result,
18178 	__rte_unused struct cmdline *cl,
18179 	__rte_unused void *data)
18180 {
18181 	struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18182 	struct rte_eth_dev_info dev_info;
18183 	portid_t port_id = res->port_id;
18184 	struct rte_port *port = &ports[port_id];
18185 	uint64_t port_offloads;
18186 	uint64_t queue_offloads;
18187 	uint16_t nb_rx_queues;
18188 	int q;
18189 	int ret;
18190 
18191 	printf("Rx Offloading Configuration of port %d :\n", port_id);
18192 
18193 	port_offloads = port->dev_conf.rxmode.offloads;
18194 	printf("  Port :");
18195 	print_rx_offloads(port_offloads);
18196 	printf("\n");
18197 
18198 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18199 	if (ret != 0)
18200 		return;
18201 
18202 	nb_rx_queues = dev_info.nb_rx_queues;
18203 	for (q = 0; q < nb_rx_queues; q++) {
18204 		queue_offloads = port->rx_conf[q].offloads;
18205 		printf("  Queue[%2d] :", q);
18206 		print_rx_offloads(queue_offloads);
18207 		printf("\n");
18208 	}
18209 	printf("\n");
18210 }
18211 
18212 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18213 	.f = cmd_rx_offload_get_configuration_parsed,
18214 	.data = NULL,
18215 	.help_str = "show port <port_id> rx_offload configuration",
18216 	.tokens = {
18217 		(void *)&cmd_rx_offload_get_configuration_show,
18218 		(void *)&cmd_rx_offload_get_configuration_port,
18219 		(void *)&cmd_rx_offload_get_configuration_port_id,
18220 		(void *)&cmd_rx_offload_get_configuration_rx_offload,
18221 		(void *)&cmd_rx_offload_get_configuration_configuration,
18222 		NULL,
18223 	}
18224 };
18225 
18226 /* Enable/Disable a per port offloading */
18227 struct cmd_config_per_port_rx_offload_result {
18228 	cmdline_fixed_string_t port;
18229 	cmdline_fixed_string_t config;
18230 	portid_t port_id;
18231 	cmdline_fixed_string_t rx_offload;
18232 	cmdline_fixed_string_t offload;
18233 	cmdline_fixed_string_t on_off;
18234 };
18235 
18236 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18237 	TOKEN_STRING_INITIALIZER
18238 		(struct cmd_config_per_port_rx_offload_result,
18239 		 port, "port");
18240 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18241 	TOKEN_STRING_INITIALIZER
18242 		(struct cmd_config_per_port_rx_offload_result,
18243 		 config, "config");
18244 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18245 	TOKEN_NUM_INITIALIZER
18246 		(struct cmd_config_per_port_rx_offload_result,
18247 		 port_id, UINT16);
18248 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18249 	TOKEN_STRING_INITIALIZER
18250 		(struct cmd_config_per_port_rx_offload_result,
18251 		 rx_offload, "rx_offload");
18252 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18253 	TOKEN_STRING_INITIALIZER
18254 		(struct cmd_config_per_port_rx_offload_result,
18255 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18256 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18257 			   "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18258 			   "scatter#timestamp#security#keep_crc#rss_hash");
18259 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18260 	TOKEN_STRING_INITIALIZER
18261 		(struct cmd_config_per_port_rx_offload_result,
18262 		 on_off, "on#off");
18263 
18264 static uint64_t
18265 search_rx_offload(const char *name)
18266 {
18267 	uint64_t single_offload;
18268 	const char *single_name;
18269 	int found = 0;
18270 	unsigned int bit;
18271 
18272 	single_offload = 1;
18273 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18274 		single_name = rte_eth_dev_rx_offload_name(single_offload);
18275 		if (!strcasecmp(single_name, name)) {
18276 			found = 1;
18277 			break;
18278 		}
18279 		single_offload <<= 1;
18280 	}
18281 
18282 	if (found)
18283 		return single_offload;
18284 
18285 	return 0;
18286 }
18287 
18288 static void
18289 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18290 				__rte_unused struct cmdline *cl,
18291 				__rte_unused void *data)
18292 {
18293 	struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18294 	portid_t port_id = res->port_id;
18295 	struct rte_eth_dev_info dev_info;
18296 	struct rte_port *port = &ports[port_id];
18297 	uint64_t single_offload;
18298 	uint16_t nb_rx_queues;
18299 	int q;
18300 	int ret;
18301 
18302 	if (port->port_status != RTE_PORT_STOPPED) {
18303 		printf("Error: Can't config offload when Port %d "
18304 		       "is not stopped\n", port_id);
18305 		return;
18306 	}
18307 
18308 	single_offload = search_rx_offload(res->offload);
18309 	if (single_offload == 0) {
18310 		printf("Unknown offload name: %s\n", res->offload);
18311 		return;
18312 	}
18313 
18314 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18315 	if (ret != 0)
18316 		return;
18317 
18318 	nb_rx_queues = dev_info.nb_rx_queues;
18319 	if (!strcmp(res->on_off, "on")) {
18320 		port->dev_conf.rxmode.offloads |= single_offload;
18321 		for (q = 0; q < nb_rx_queues; q++)
18322 			port->rx_conf[q].offloads |= single_offload;
18323 	} else {
18324 		port->dev_conf.rxmode.offloads &= ~single_offload;
18325 		for (q = 0; q < nb_rx_queues; q++)
18326 			port->rx_conf[q].offloads &= ~single_offload;
18327 	}
18328 
18329 	cmd_reconfig_device_queue(port_id, 1, 1);
18330 }
18331 
18332 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18333 	.f = cmd_config_per_port_rx_offload_parsed,
18334 	.data = NULL,
18335 	.help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18336 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18337 		    "macsec_strip|header_split|vlan_filter|vlan_extend|"
18338 		    "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18339 		    "on|off",
18340 	.tokens = {
18341 		(void *)&cmd_config_per_port_rx_offload_result_port,
18342 		(void *)&cmd_config_per_port_rx_offload_result_config,
18343 		(void *)&cmd_config_per_port_rx_offload_result_port_id,
18344 		(void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18345 		(void *)&cmd_config_per_port_rx_offload_result_offload,
18346 		(void *)&cmd_config_per_port_rx_offload_result_on_off,
18347 		NULL,
18348 	}
18349 };
18350 
18351 /* Enable/Disable a per queue offloading */
18352 struct cmd_config_per_queue_rx_offload_result {
18353 	cmdline_fixed_string_t port;
18354 	portid_t port_id;
18355 	cmdline_fixed_string_t rxq;
18356 	uint16_t queue_id;
18357 	cmdline_fixed_string_t rx_offload;
18358 	cmdline_fixed_string_t offload;
18359 	cmdline_fixed_string_t on_off;
18360 };
18361 
18362 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18363 	TOKEN_STRING_INITIALIZER
18364 		(struct cmd_config_per_queue_rx_offload_result,
18365 		 port, "port");
18366 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18367 	TOKEN_NUM_INITIALIZER
18368 		(struct cmd_config_per_queue_rx_offload_result,
18369 		 port_id, UINT16);
18370 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18371 	TOKEN_STRING_INITIALIZER
18372 		(struct cmd_config_per_queue_rx_offload_result,
18373 		 rxq, "rxq");
18374 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18375 	TOKEN_NUM_INITIALIZER
18376 		(struct cmd_config_per_queue_rx_offload_result,
18377 		 queue_id, UINT16);
18378 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18379 	TOKEN_STRING_INITIALIZER
18380 		(struct cmd_config_per_queue_rx_offload_result,
18381 		 rx_offload, "rx_offload");
18382 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18383 	TOKEN_STRING_INITIALIZER
18384 		(struct cmd_config_per_queue_rx_offload_result,
18385 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18386 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18387 			   "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18388 			   "scatter#timestamp#security#keep_crc");
18389 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18390 	TOKEN_STRING_INITIALIZER
18391 		(struct cmd_config_per_queue_rx_offload_result,
18392 		 on_off, "on#off");
18393 
18394 static void
18395 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18396 				__rte_unused struct cmdline *cl,
18397 				__rte_unused void *data)
18398 {
18399 	struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18400 	struct rte_eth_dev_info dev_info;
18401 	portid_t port_id = res->port_id;
18402 	uint16_t queue_id = res->queue_id;
18403 	struct rte_port *port = &ports[port_id];
18404 	uint64_t single_offload;
18405 	int ret;
18406 
18407 	if (port->port_status != RTE_PORT_STOPPED) {
18408 		printf("Error: Can't config offload when Port %d "
18409 		       "is not stopped\n", port_id);
18410 		return;
18411 	}
18412 
18413 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18414 	if (ret != 0)
18415 		return;
18416 
18417 	if (queue_id >= dev_info.nb_rx_queues) {
18418 		printf("Error: input queue_id should be 0 ... "
18419 		       "%d\n", dev_info.nb_rx_queues - 1);
18420 		return;
18421 	}
18422 
18423 	single_offload = search_rx_offload(res->offload);
18424 	if (single_offload == 0) {
18425 		printf("Unknown offload name: %s\n", res->offload);
18426 		return;
18427 	}
18428 
18429 	if (!strcmp(res->on_off, "on"))
18430 		port->rx_conf[queue_id].offloads |= single_offload;
18431 	else
18432 		port->rx_conf[queue_id].offloads &= ~single_offload;
18433 
18434 	cmd_reconfig_device_queue(port_id, 1, 1);
18435 }
18436 
18437 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18438 	.f = cmd_config_per_queue_rx_offload_parsed,
18439 	.data = NULL,
18440 	.help_str = "port <port_id> rxq <queue_id> rx_offload "
18441 		    "vlan_strip|ipv4_cksum|"
18442 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18443 		    "macsec_strip|header_split|vlan_filter|vlan_extend|"
18444 		    "jumbo_frame|scatter|timestamp|security|keep_crc "
18445 		    "on|off",
18446 	.tokens = {
18447 		(void *)&cmd_config_per_queue_rx_offload_result_port,
18448 		(void *)&cmd_config_per_queue_rx_offload_result_port_id,
18449 		(void *)&cmd_config_per_queue_rx_offload_result_rxq,
18450 		(void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18451 		(void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18452 		(void *)&cmd_config_per_queue_rx_offload_result_offload,
18453 		(void *)&cmd_config_per_queue_rx_offload_result_on_off,
18454 		NULL,
18455 	}
18456 };
18457 
18458 /* Get Tx offloads capabilities */
18459 struct cmd_tx_offload_get_capa_result {
18460 	cmdline_fixed_string_t show;
18461 	cmdline_fixed_string_t port;
18462 	portid_t port_id;
18463 	cmdline_fixed_string_t tx_offload;
18464 	cmdline_fixed_string_t capabilities;
18465 };
18466 
18467 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18468 	TOKEN_STRING_INITIALIZER
18469 		(struct cmd_tx_offload_get_capa_result,
18470 		 show, "show");
18471 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18472 	TOKEN_STRING_INITIALIZER
18473 		(struct cmd_tx_offload_get_capa_result,
18474 		 port, "port");
18475 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18476 	TOKEN_NUM_INITIALIZER
18477 		(struct cmd_tx_offload_get_capa_result,
18478 		 port_id, UINT16);
18479 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18480 	TOKEN_STRING_INITIALIZER
18481 		(struct cmd_tx_offload_get_capa_result,
18482 		 tx_offload, "tx_offload");
18483 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18484 	TOKEN_STRING_INITIALIZER
18485 		(struct cmd_tx_offload_get_capa_result,
18486 		 capabilities, "capabilities");
18487 
18488 static void
18489 print_tx_offloads(uint64_t offloads)
18490 {
18491 	uint64_t single_offload;
18492 	int begin;
18493 	int end;
18494 	int bit;
18495 
18496 	if (offloads == 0)
18497 		return;
18498 
18499 	begin = __builtin_ctzll(offloads);
18500 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18501 
18502 	single_offload = 1ULL << begin;
18503 	for (bit = begin; bit < end; bit++) {
18504 		if (offloads & single_offload)
18505 			printf(" %s",
18506 			       rte_eth_dev_tx_offload_name(single_offload));
18507 		single_offload <<= 1;
18508 	}
18509 }
18510 
18511 static void
18512 cmd_tx_offload_get_capa_parsed(
18513 	void *parsed_result,
18514 	__rte_unused struct cmdline *cl,
18515 	__rte_unused void *data)
18516 {
18517 	struct cmd_tx_offload_get_capa_result *res = parsed_result;
18518 	struct rte_eth_dev_info dev_info;
18519 	portid_t port_id = res->port_id;
18520 	uint64_t queue_offloads;
18521 	uint64_t port_offloads;
18522 	int ret;
18523 
18524 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18525 	if (ret != 0)
18526 		return;
18527 
18528 	queue_offloads = dev_info.tx_queue_offload_capa;
18529 	port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18530 
18531 	printf("Tx Offloading Capabilities of port %d :\n", port_id);
18532 	printf("  Per Queue :");
18533 	print_tx_offloads(queue_offloads);
18534 
18535 	printf("\n");
18536 	printf("  Per Port  :");
18537 	print_tx_offloads(port_offloads);
18538 	printf("\n\n");
18539 }
18540 
18541 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18542 	.f = cmd_tx_offload_get_capa_parsed,
18543 	.data = NULL,
18544 	.help_str = "show port <port_id> tx_offload capabilities",
18545 	.tokens = {
18546 		(void *)&cmd_tx_offload_get_capa_show,
18547 		(void *)&cmd_tx_offload_get_capa_port,
18548 		(void *)&cmd_tx_offload_get_capa_port_id,
18549 		(void *)&cmd_tx_offload_get_capa_tx_offload,
18550 		(void *)&cmd_tx_offload_get_capa_capabilities,
18551 		NULL,
18552 	}
18553 };
18554 
18555 /* Get Tx offloads configuration */
18556 struct cmd_tx_offload_get_configuration_result {
18557 	cmdline_fixed_string_t show;
18558 	cmdline_fixed_string_t port;
18559 	portid_t port_id;
18560 	cmdline_fixed_string_t tx_offload;
18561 	cmdline_fixed_string_t configuration;
18562 };
18563 
18564 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18565 	TOKEN_STRING_INITIALIZER
18566 		(struct cmd_tx_offload_get_configuration_result,
18567 		 show, "show");
18568 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18569 	TOKEN_STRING_INITIALIZER
18570 		(struct cmd_tx_offload_get_configuration_result,
18571 		 port, "port");
18572 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18573 	TOKEN_NUM_INITIALIZER
18574 		(struct cmd_tx_offload_get_configuration_result,
18575 		 port_id, UINT16);
18576 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18577 	TOKEN_STRING_INITIALIZER
18578 		(struct cmd_tx_offload_get_configuration_result,
18579 		 tx_offload, "tx_offload");
18580 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18581 	TOKEN_STRING_INITIALIZER
18582 		(struct cmd_tx_offload_get_configuration_result,
18583 		 configuration, "configuration");
18584 
18585 static void
18586 cmd_tx_offload_get_configuration_parsed(
18587 	void *parsed_result,
18588 	__rte_unused struct cmdline *cl,
18589 	__rte_unused void *data)
18590 {
18591 	struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18592 	struct rte_eth_dev_info dev_info;
18593 	portid_t port_id = res->port_id;
18594 	struct rte_port *port = &ports[port_id];
18595 	uint64_t port_offloads;
18596 	uint64_t queue_offloads;
18597 	uint16_t nb_tx_queues;
18598 	int q;
18599 	int ret;
18600 
18601 	printf("Tx Offloading Configuration of port %d :\n", port_id);
18602 
18603 	port_offloads = port->dev_conf.txmode.offloads;
18604 	printf("  Port :");
18605 	print_tx_offloads(port_offloads);
18606 	printf("\n");
18607 
18608 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18609 	if (ret != 0)
18610 		return;
18611 
18612 	nb_tx_queues = dev_info.nb_tx_queues;
18613 	for (q = 0; q < nb_tx_queues; q++) {
18614 		queue_offloads = port->tx_conf[q].offloads;
18615 		printf("  Queue[%2d] :", q);
18616 		print_tx_offloads(queue_offloads);
18617 		printf("\n");
18618 	}
18619 	printf("\n");
18620 }
18621 
18622 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18623 	.f = cmd_tx_offload_get_configuration_parsed,
18624 	.data = NULL,
18625 	.help_str = "show port <port_id> tx_offload configuration",
18626 	.tokens = {
18627 		(void *)&cmd_tx_offload_get_configuration_show,
18628 		(void *)&cmd_tx_offload_get_configuration_port,
18629 		(void *)&cmd_tx_offload_get_configuration_port_id,
18630 		(void *)&cmd_tx_offload_get_configuration_tx_offload,
18631 		(void *)&cmd_tx_offload_get_configuration_configuration,
18632 		NULL,
18633 	}
18634 };
18635 
18636 /* Enable/Disable a per port offloading */
18637 struct cmd_config_per_port_tx_offload_result {
18638 	cmdline_fixed_string_t port;
18639 	cmdline_fixed_string_t config;
18640 	portid_t port_id;
18641 	cmdline_fixed_string_t tx_offload;
18642 	cmdline_fixed_string_t offload;
18643 	cmdline_fixed_string_t on_off;
18644 };
18645 
18646 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18647 	TOKEN_STRING_INITIALIZER
18648 		(struct cmd_config_per_port_tx_offload_result,
18649 		 port, "port");
18650 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18651 	TOKEN_STRING_INITIALIZER
18652 		(struct cmd_config_per_port_tx_offload_result,
18653 		 config, "config");
18654 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18655 	TOKEN_NUM_INITIALIZER
18656 		(struct cmd_config_per_port_tx_offload_result,
18657 		 port_id, UINT16);
18658 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18659 	TOKEN_STRING_INITIALIZER
18660 		(struct cmd_config_per_port_tx_offload_result,
18661 		 tx_offload, "tx_offload");
18662 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18663 	TOKEN_STRING_INITIALIZER
18664 		(struct cmd_config_per_port_tx_offload_result,
18665 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18666 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18667 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18668 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18669 			  "mt_lockfree#multi_segs#mbuf_fast_free#security");
18670 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18671 	TOKEN_STRING_INITIALIZER
18672 		(struct cmd_config_per_port_tx_offload_result,
18673 		 on_off, "on#off");
18674 
18675 static uint64_t
18676 search_tx_offload(const char *name)
18677 {
18678 	uint64_t single_offload;
18679 	const char *single_name;
18680 	int found = 0;
18681 	unsigned int bit;
18682 
18683 	single_offload = 1;
18684 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18685 		single_name = rte_eth_dev_tx_offload_name(single_offload);
18686 		if (single_name == NULL)
18687 			break;
18688 		if (!strcasecmp(single_name, name)) {
18689 			found = 1;
18690 			break;
18691 		} else if (!strcasecmp(single_name, "UNKNOWN"))
18692 			break;
18693 		single_offload <<= 1;
18694 	}
18695 
18696 	if (found)
18697 		return single_offload;
18698 
18699 	return 0;
18700 }
18701 
18702 static void
18703 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18704 				__rte_unused struct cmdline *cl,
18705 				__rte_unused void *data)
18706 {
18707 	struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18708 	portid_t port_id = res->port_id;
18709 	struct rte_eth_dev_info dev_info;
18710 	struct rte_port *port = &ports[port_id];
18711 	uint64_t single_offload;
18712 	uint16_t nb_tx_queues;
18713 	int q;
18714 	int ret;
18715 
18716 	if (port->port_status != RTE_PORT_STOPPED) {
18717 		printf("Error: Can't config offload when Port %d "
18718 		       "is not stopped\n", port_id);
18719 		return;
18720 	}
18721 
18722 	single_offload = search_tx_offload(res->offload);
18723 	if (single_offload == 0) {
18724 		printf("Unknown offload name: %s\n", res->offload);
18725 		return;
18726 	}
18727 
18728 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18729 	if (ret != 0)
18730 		return;
18731 
18732 	nb_tx_queues = dev_info.nb_tx_queues;
18733 	if (!strcmp(res->on_off, "on")) {
18734 		port->dev_conf.txmode.offloads |= single_offload;
18735 		for (q = 0; q < nb_tx_queues; q++)
18736 			port->tx_conf[q].offloads |= single_offload;
18737 	} else {
18738 		port->dev_conf.txmode.offloads &= ~single_offload;
18739 		for (q = 0; q < nb_tx_queues; q++)
18740 			port->tx_conf[q].offloads &= ~single_offload;
18741 	}
18742 
18743 	cmd_reconfig_device_queue(port_id, 1, 1);
18744 }
18745 
18746 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18747 	.f = cmd_config_per_port_tx_offload_parsed,
18748 	.data = NULL,
18749 	.help_str = "port config <port_id> tx_offload "
18750 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18751 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18752 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18753 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18754 		    "mt_lockfree|multi_segs|mbuf_fast_free|security on|off",
18755 	.tokens = {
18756 		(void *)&cmd_config_per_port_tx_offload_result_port,
18757 		(void *)&cmd_config_per_port_tx_offload_result_config,
18758 		(void *)&cmd_config_per_port_tx_offload_result_port_id,
18759 		(void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18760 		(void *)&cmd_config_per_port_tx_offload_result_offload,
18761 		(void *)&cmd_config_per_port_tx_offload_result_on_off,
18762 		NULL,
18763 	}
18764 };
18765 
18766 /* Enable/Disable a per queue offloading */
18767 struct cmd_config_per_queue_tx_offload_result {
18768 	cmdline_fixed_string_t port;
18769 	portid_t port_id;
18770 	cmdline_fixed_string_t txq;
18771 	uint16_t queue_id;
18772 	cmdline_fixed_string_t tx_offload;
18773 	cmdline_fixed_string_t offload;
18774 	cmdline_fixed_string_t on_off;
18775 };
18776 
18777 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18778 	TOKEN_STRING_INITIALIZER
18779 		(struct cmd_config_per_queue_tx_offload_result,
18780 		 port, "port");
18781 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18782 	TOKEN_NUM_INITIALIZER
18783 		(struct cmd_config_per_queue_tx_offload_result,
18784 		 port_id, UINT16);
18785 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18786 	TOKEN_STRING_INITIALIZER
18787 		(struct cmd_config_per_queue_tx_offload_result,
18788 		 txq, "txq");
18789 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18790 	TOKEN_NUM_INITIALIZER
18791 		(struct cmd_config_per_queue_tx_offload_result,
18792 		 queue_id, UINT16);
18793 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18794 	TOKEN_STRING_INITIALIZER
18795 		(struct cmd_config_per_queue_tx_offload_result,
18796 		 tx_offload, "tx_offload");
18797 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18798 	TOKEN_STRING_INITIALIZER
18799 		(struct cmd_config_per_queue_tx_offload_result,
18800 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18801 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18802 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18803 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18804 			  "mt_lockfree#multi_segs#mbuf_fast_free#security");
18805 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18806 	TOKEN_STRING_INITIALIZER
18807 		(struct cmd_config_per_queue_tx_offload_result,
18808 		 on_off, "on#off");
18809 
18810 static void
18811 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18812 				__rte_unused struct cmdline *cl,
18813 				__rte_unused void *data)
18814 {
18815 	struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18816 	struct rte_eth_dev_info dev_info;
18817 	portid_t port_id = res->port_id;
18818 	uint16_t queue_id = res->queue_id;
18819 	struct rte_port *port = &ports[port_id];
18820 	uint64_t single_offload;
18821 	int ret;
18822 
18823 	if (port->port_status != RTE_PORT_STOPPED) {
18824 		printf("Error: Can't config offload when Port %d "
18825 		       "is not stopped\n", port_id);
18826 		return;
18827 	}
18828 
18829 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18830 	if (ret != 0)
18831 		return;
18832 
18833 	if (queue_id >= dev_info.nb_tx_queues) {
18834 		printf("Error: input queue_id should be 0 ... "
18835 		       "%d\n", dev_info.nb_tx_queues - 1);
18836 		return;
18837 	}
18838 
18839 	single_offload = search_tx_offload(res->offload);
18840 	if (single_offload == 0) {
18841 		printf("Unknown offload name: %s\n", res->offload);
18842 		return;
18843 	}
18844 
18845 	if (!strcmp(res->on_off, "on"))
18846 		port->tx_conf[queue_id].offloads |= single_offload;
18847 	else
18848 		port->tx_conf[queue_id].offloads &= ~single_offload;
18849 
18850 	cmd_reconfig_device_queue(port_id, 1, 1);
18851 }
18852 
18853 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18854 	.f = cmd_config_per_queue_tx_offload_parsed,
18855 	.data = NULL,
18856 	.help_str = "port <port_id> txq <queue_id> tx_offload "
18857 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18858 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18859 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18860 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18861 		    "mt_lockfree|multi_segs|mbuf_fast_free|security "
18862 		    "on|off",
18863 	.tokens = {
18864 		(void *)&cmd_config_per_queue_tx_offload_result_port,
18865 		(void *)&cmd_config_per_queue_tx_offload_result_port_id,
18866 		(void *)&cmd_config_per_queue_tx_offload_result_txq,
18867 		(void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18868 		(void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18869 		(void *)&cmd_config_per_queue_tx_offload_result_offload,
18870 		(void *)&cmd_config_per_queue_tx_offload_result_on_off,
18871 		NULL,
18872 	}
18873 };
18874 
18875 /* *** configure tx_metadata for specific port *** */
18876 struct cmd_config_tx_metadata_specific_result {
18877 	cmdline_fixed_string_t port;
18878 	cmdline_fixed_string_t keyword;
18879 	uint16_t port_id;
18880 	cmdline_fixed_string_t item;
18881 	uint32_t value;
18882 };
18883 
18884 static void
18885 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18886 				__rte_unused struct cmdline *cl,
18887 				__rte_unused void *data)
18888 {
18889 	struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18890 
18891 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18892 		return;
18893 	ports[res->port_id].tx_metadata = res->value;
18894 	/* Add/remove callback to insert valid metadata in every Tx packet. */
18895 	if (ports[res->port_id].tx_metadata)
18896 		add_tx_md_callback(res->port_id);
18897 	else
18898 		remove_tx_md_callback(res->port_id);
18899 	rte_flow_dynf_metadata_register();
18900 }
18901 
18902 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18903 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18904 			port, "port");
18905 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18906 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18907 			keyword, "config");
18908 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18909 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18910 			port_id, UINT16);
18911 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18912 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18913 			item, "tx_metadata");
18914 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18915 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18916 			value, UINT32);
18917 
18918 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18919 	.f = cmd_config_tx_metadata_specific_parsed,
18920 	.data = NULL,
18921 	.help_str = "port config <port_id> tx_metadata <value>",
18922 	.tokens = {
18923 		(void *)&cmd_config_tx_metadata_specific_port,
18924 		(void *)&cmd_config_tx_metadata_specific_keyword,
18925 		(void *)&cmd_config_tx_metadata_specific_id,
18926 		(void *)&cmd_config_tx_metadata_specific_item,
18927 		(void *)&cmd_config_tx_metadata_specific_value,
18928 		NULL,
18929 	},
18930 };
18931 
18932 /* *** set dynf *** */
18933 struct cmd_config_tx_dynf_specific_result {
18934 	cmdline_fixed_string_t port;
18935 	cmdline_fixed_string_t keyword;
18936 	uint16_t port_id;
18937 	cmdline_fixed_string_t item;
18938 	cmdline_fixed_string_t name;
18939 	cmdline_fixed_string_t value;
18940 };
18941 
18942 static void
18943 cmd_config_dynf_specific_parsed(void *parsed_result,
18944 				__rte_unused struct cmdline *cl,
18945 				__rte_unused void *data)
18946 {
18947 	struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18948 	struct rte_mbuf_dynflag desc_flag;
18949 	int flag;
18950 	uint64_t old_port_flags;
18951 
18952 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18953 		return;
18954 	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18955 	if (flag <= 0) {
18956 		if (strlcpy(desc_flag.name, res->name,
18957 			    RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18958 			printf("Flag name too long\n");
18959 			return;
18960 		}
18961 		desc_flag.flags = 0;
18962 		flag = rte_mbuf_dynflag_register(&desc_flag);
18963 		if (flag < 0) {
18964 			printf("Can't register flag\n");
18965 			return;
18966 		}
18967 		strcpy(dynf_names[flag], desc_flag.name);
18968 	}
18969 	old_port_flags = ports[res->port_id].mbuf_dynf;
18970 	if (!strcmp(res->value, "set")) {
18971 		ports[res->port_id].mbuf_dynf |= 1UL << flag;
18972 		if (old_port_flags == 0)
18973 			add_tx_dynf_callback(res->port_id);
18974 	} else {
18975 		ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18976 		if (ports[res->port_id].mbuf_dynf == 0)
18977 			remove_tx_dynf_callback(res->port_id);
18978 	}
18979 }
18980 
18981 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18982 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18983 			keyword, "port");
18984 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
18985 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18986 			keyword, "config");
18987 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
18988 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18989 			port_id, UINT16);
18990 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
18991 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18992 			item, "dynf");
18993 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
18994 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18995 			name, NULL);
18996 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
18997 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18998 			value, "set#clear");
18999 
19000 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
19001 	.f = cmd_config_dynf_specific_parsed,
19002 	.data = NULL,
19003 	.help_str = "port config <port id> dynf <name> set|clear",
19004 	.tokens = {
19005 		(void *)&cmd_config_tx_dynf_specific_port,
19006 		(void *)&cmd_config_tx_dynf_specific_keyword,
19007 		(void *)&cmd_config_tx_dynf_specific_port_id,
19008 		(void *)&cmd_config_tx_dynf_specific_item,
19009 		(void *)&cmd_config_tx_dynf_specific_name,
19010 		(void *)&cmd_config_tx_dynf_specific_value,
19011 		NULL,
19012 	},
19013 };
19014 
19015 /* *** display tx_metadata per port configuration *** */
19016 struct cmd_show_tx_metadata_result {
19017 	cmdline_fixed_string_t cmd_show;
19018 	cmdline_fixed_string_t cmd_port;
19019 	cmdline_fixed_string_t cmd_keyword;
19020 	portid_t cmd_pid;
19021 };
19022 
19023 static void
19024 cmd_show_tx_metadata_parsed(void *parsed_result,
19025 		__rte_unused struct cmdline *cl,
19026 		__rte_unused void *data)
19027 {
19028 	struct cmd_show_tx_metadata_result *res = parsed_result;
19029 
19030 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19031 		printf("invalid port id %u\n", res->cmd_pid);
19032 		return;
19033 	}
19034 	if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19035 		printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19036 		       ports[res->cmd_pid].tx_metadata);
19037 	}
19038 }
19039 
19040 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19041 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19042 			cmd_show, "show");
19043 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19044 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19045 			cmd_port, "port");
19046 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19047 	TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19048 			cmd_pid, UINT16);
19049 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19050 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19051 			cmd_keyword, "tx_metadata");
19052 
19053 cmdline_parse_inst_t cmd_show_tx_metadata = {
19054 	.f = cmd_show_tx_metadata_parsed,
19055 	.data = NULL,
19056 	.help_str = "show port <port_id> tx_metadata",
19057 	.tokens = {
19058 		(void *)&cmd_show_tx_metadata_show,
19059 		(void *)&cmd_show_tx_metadata_port,
19060 		(void *)&cmd_show_tx_metadata_pid,
19061 		(void *)&cmd_show_tx_metadata_keyword,
19062 		NULL,
19063 	},
19064 };
19065 
19066 /* show port supported ptypes */
19067 
19068 /* Common result structure for show port ptypes */
19069 struct cmd_show_port_supported_ptypes_result {
19070 	cmdline_fixed_string_t show;
19071 	cmdline_fixed_string_t port;
19072 	portid_t port_id;
19073 	cmdline_fixed_string_t ptypes;
19074 };
19075 
19076 /* Common CLI fields for show port ptypes */
19077 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19078 	TOKEN_STRING_INITIALIZER
19079 		(struct cmd_show_port_supported_ptypes_result,
19080 		 show, "show");
19081 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19082 	TOKEN_STRING_INITIALIZER
19083 		(struct cmd_show_port_supported_ptypes_result,
19084 		 port, "port");
19085 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19086 	TOKEN_NUM_INITIALIZER
19087 		(struct cmd_show_port_supported_ptypes_result,
19088 		 port_id, UINT16);
19089 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19090 	TOKEN_STRING_INITIALIZER
19091 		(struct cmd_show_port_supported_ptypes_result,
19092 		 ptypes, "ptypes");
19093 
19094 static void
19095 cmd_show_port_supported_ptypes_parsed(
19096 	void *parsed_result,
19097 	__rte_unused struct cmdline *cl,
19098 	__rte_unused void *data)
19099 {
19100 #define RSVD_PTYPE_MASK       0xf0000000
19101 #define MAX_PTYPES_PER_LAYER  16
19102 #define LTYPE_NAMESIZE        32
19103 #define PTYPE_NAMESIZE        256
19104 	struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19105 	char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19106 	uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19107 	uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19108 	uint16_t port_id = res->port_id;
19109 	int ret, i;
19110 
19111 	ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19112 	if (ret < 0)
19113 		return;
19114 
19115 	while (ptype_mask != RSVD_PTYPE_MASK) {
19116 
19117 		switch (ptype_mask) {
19118 		case RTE_PTYPE_L2_MASK:
19119 			strlcpy(ltype, "L2", sizeof(ltype));
19120 			break;
19121 		case RTE_PTYPE_L3_MASK:
19122 			strlcpy(ltype, "L3", sizeof(ltype));
19123 			break;
19124 		case RTE_PTYPE_L4_MASK:
19125 			strlcpy(ltype, "L4", sizeof(ltype));
19126 			break;
19127 		case RTE_PTYPE_TUNNEL_MASK:
19128 			strlcpy(ltype, "Tunnel", sizeof(ltype));
19129 			break;
19130 		case RTE_PTYPE_INNER_L2_MASK:
19131 			strlcpy(ltype, "Inner L2", sizeof(ltype));
19132 			break;
19133 		case RTE_PTYPE_INNER_L3_MASK:
19134 			strlcpy(ltype, "Inner L3", sizeof(ltype));
19135 			break;
19136 		case RTE_PTYPE_INNER_L4_MASK:
19137 			strlcpy(ltype, "Inner L4", sizeof(ltype));
19138 			break;
19139 		default:
19140 			return;
19141 		}
19142 
19143 		ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19144 						       ptype_mask, ptypes,
19145 						       MAX_PTYPES_PER_LAYER);
19146 
19147 		if (ret > 0)
19148 			printf("Supported %s ptypes:\n", ltype);
19149 		else
19150 			printf("%s ptypes unsupported\n", ltype);
19151 
19152 		for (i = 0; i < ret; ++i) {
19153 			rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19154 			printf("%s\n", buf);
19155 		}
19156 
19157 		ptype_mask <<= 4;
19158 	}
19159 }
19160 
19161 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19162 	.f = cmd_show_port_supported_ptypes_parsed,
19163 	.data = NULL,
19164 	.help_str = "show port <port_id> ptypes",
19165 	.tokens = {
19166 		(void *)&cmd_show_port_supported_ptypes_show,
19167 		(void *)&cmd_show_port_supported_ptypes_port,
19168 		(void *)&cmd_show_port_supported_ptypes_port_id,
19169 		(void *)&cmd_show_port_supported_ptypes_ptypes,
19170 		NULL,
19171 	},
19172 };
19173 
19174 /* *** display rx/tx descriptor status *** */
19175 struct cmd_show_rx_tx_desc_status_result {
19176 	cmdline_fixed_string_t cmd_show;
19177 	cmdline_fixed_string_t cmd_port;
19178 	cmdline_fixed_string_t cmd_keyword;
19179 	cmdline_fixed_string_t cmd_desc;
19180 	cmdline_fixed_string_t cmd_status;
19181 	portid_t cmd_pid;
19182 	portid_t cmd_qid;
19183 	portid_t cmd_did;
19184 };
19185 
19186 static void
19187 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19188 		__rte_unused struct cmdline *cl,
19189 		__rte_unused void *data)
19190 {
19191 	struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19192 	int rc;
19193 
19194 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19195 		printf("invalid port id %u\n", res->cmd_pid);
19196 		return;
19197 	}
19198 
19199 	if (!strcmp(res->cmd_keyword, "rxq")) {
19200 		rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19201 					     res->cmd_did);
19202 		if (rc < 0) {
19203 			printf("Invalid queueid = %d\n", res->cmd_qid);
19204 			return;
19205 		}
19206 		if (rc == RTE_ETH_RX_DESC_AVAIL)
19207 			printf("Desc status = AVAILABLE\n");
19208 		else if (rc == RTE_ETH_RX_DESC_DONE)
19209 			printf("Desc status = DONE\n");
19210 		else
19211 			printf("Desc status = UNAVAILABLE\n");
19212 	} else if (!strcmp(res->cmd_keyword, "txq")) {
19213 		rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19214 					     res->cmd_did);
19215 		if (rc < 0) {
19216 			printf("Invalid queueid = %d\n", res->cmd_qid);
19217 			return;
19218 		}
19219 		if (rc == RTE_ETH_TX_DESC_FULL)
19220 			printf("Desc status = FULL\n");
19221 		else if (rc == RTE_ETH_TX_DESC_DONE)
19222 			printf("Desc status = DONE\n");
19223 		else
19224 			printf("Desc status = UNAVAILABLE\n");
19225 	}
19226 }
19227 
19228 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19229 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19230 			cmd_show, "show");
19231 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19232 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19233 			cmd_port, "port");
19234 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19235 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19236 			cmd_pid, UINT16);
19237 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19238 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19239 			cmd_keyword, "rxq#txq");
19240 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19241 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19242 			cmd_qid, UINT16);
19243 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19244 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19245 			cmd_desc, "desc");
19246 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19247 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19248 			cmd_did, UINT16);
19249 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19250 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19251 			cmd_status, "status");
19252 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19253 	.f = cmd_show_rx_tx_desc_status_parsed,
19254 	.data = NULL,
19255 	.help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19256 		"status",
19257 	.tokens = {
19258 		(void *)&cmd_show_rx_tx_desc_status_show,
19259 		(void *)&cmd_show_rx_tx_desc_status_port,
19260 		(void *)&cmd_show_rx_tx_desc_status_pid,
19261 		(void *)&cmd_show_rx_tx_desc_status_keyword,
19262 		(void *)&cmd_show_rx_tx_desc_status_qid,
19263 		(void *)&cmd_show_rx_tx_desc_status_desc,
19264 		(void *)&cmd_show_rx_tx_desc_status_did,
19265 		(void *)&cmd_show_rx_tx_desc_status_status,
19266 		NULL,
19267 	},
19268 };
19269 
19270 /* Common result structure for set port ptypes */
19271 struct cmd_set_port_ptypes_result {
19272 	cmdline_fixed_string_t set;
19273 	cmdline_fixed_string_t port;
19274 	portid_t port_id;
19275 	cmdline_fixed_string_t ptype_mask;
19276 	uint32_t mask;
19277 };
19278 
19279 /* Common CLI fields for set port ptypes */
19280 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19281 	TOKEN_STRING_INITIALIZER
19282 		(struct cmd_set_port_ptypes_result,
19283 		 set, "set");
19284 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19285 	TOKEN_STRING_INITIALIZER
19286 		(struct cmd_set_port_ptypes_result,
19287 		 port, "port");
19288 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19289 	TOKEN_NUM_INITIALIZER
19290 		(struct cmd_set_port_ptypes_result,
19291 		 port_id, UINT16);
19292 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19293 	TOKEN_STRING_INITIALIZER
19294 		(struct cmd_set_port_ptypes_result,
19295 		 ptype_mask, "ptype_mask");
19296 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19297 	TOKEN_NUM_INITIALIZER
19298 		(struct cmd_set_port_ptypes_result,
19299 		 mask, UINT32);
19300 
19301 static void
19302 cmd_set_port_ptypes_parsed(
19303 	void *parsed_result,
19304 	__rte_unused struct cmdline *cl,
19305 	__rte_unused void *data)
19306 {
19307 	struct cmd_set_port_ptypes_result *res = parsed_result;
19308 #define PTYPE_NAMESIZE        256
19309 	char ptype_name[PTYPE_NAMESIZE];
19310 	uint16_t port_id = res->port_id;
19311 	uint32_t ptype_mask = res->mask;
19312 	int ret, i;
19313 
19314 	ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19315 					       NULL, 0);
19316 	if (ret <= 0) {
19317 		printf("Port %d doesn't support any ptypes.\n", port_id);
19318 		return;
19319 	}
19320 
19321 	uint32_t ptypes[ret];
19322 
19323 	ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19324 	if (ret < 0) {
19325 		printf("Unable to set requested ptypes for Port %d\n", port_id);
19326 		return;
19327 	}
19328 
19329 	printf("Successfully set following ptypes for Port %d\n", port_id);
19330 	for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19331 		rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19332 		printf("%s\n", ptype_name);
19333 	}
19334 
19335 	clear_ptypes = false;
19336 }
19337 
19338 cmdline_parse_inst_t cmd_set_port_ptypes = {
19339 	.f = cmd_set_port_ptypes_parsed,
19340 	.data = NULL,
19341 	.help_str = "set port <port_id> ptype_mask <mask>",
19342 	.tokens = {
19343 		(void *)&cmd_set_port_ptypes_set,
19344 		(void *)&cmd_set_port_ptypes_port,
19345 		(void *)&cmd_set_port_ptypes_port_id,
19346 		(void *)&cmd_set_port_ptypes_mask_str,
19347 		(void *)&cmd_set_port_ptypes_mask_u32,
19348 		NULL,
19349 	},
19350 };
19351 
19352 /* *** display mac addresses added to a port *** */
19353 struct cmd_showport_macs_result {
19354 	cmdline_fixed_string_t cmd_show;
19355 	cmdline_fixed_string_t cmd_port;
19356 	cmdline_fixed_string_t cmd_keyword;
19357 	portid_t cmd_pid;
19358 };
19359 
19360 static void
19361 cmd_showport_macs_parsed(void *parsed_result,
19362 		__rte_unused struct cmdline *cl,
19363 		__rte_unused void *data)
19364 {
19365 	struct cmd_showport_macs_result *res = parsed_result;
19366 
19367 	if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19368 		return;
19369 
19370 	if (!strcmp(res->cmd_keyword, "macs"))
19371 		show_macs(res->cmd_pid);
19372 	else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19373 		show_mcast_macs(res->cmd_pid);
19374 }
19375 
19376 cmdline_parse_token_string_t cmd_showport_macs_show =
19377 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19378 			cmd_show, "show");
19379 cmdline_parse_token_string_t cmd_showport_macs_port =
19380 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19381 			cmd_port, "port");
19382 cmdline_parse_token_num_t cmd_showport_macs_pid =
19383 	TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19384 			cmd_pid, UINT16);
19385 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19386 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19387 			cmd_keyword, "macs#mcast_macs");
19388 
19389 cmdline_parse_inst_t cmd_showport_macs = {
19390 	.f = cmd_showport_macs_parsed,
19391 	.data = NULL,
19392 	.help_str = "show port <port_id> macs|mcast_macs",
19393 	.tokens = {
19394 		(void *)&cmd_showport_macs_show,
19395 		(void *)&cmd_showport_macs_port,
19396 		(void *)&cmd_showport_macs_pid,
19397 		(void *)&cmd_showport_macs_keyword,
19398 		NULL,
19399 	},
19400 };
19401 
19402 /* ******************************************************************************** */
19403 
19404 /* list of instructions */
19405 cmdline_parse_ctx_t main_ctx[] = {
19406 	(cmdline_parse_inst_t *)&cmd_help_brief,
19407 	(cmdline_parse_inst_t *)&cmd_help_long,
19408 	(cmdline_parse_inst_t *)&cmd_quit,
19409 	(cmdline_parse_inst_t *)&cmd_load_from_file,
19410 	(cmdline_parse_inst_t *)&cmd_showport,
19411 	(cmdline_parse_inst_t *)&cmd_showqueue,
19412 	(cmdline_parse_inst_t *)&cmd_showportall,
19413 	(cmdline_parse_inst_t *)&cmd_showdevice,
19414 	(cmdline_parse_inst_t *)&cmd_showcfg,
19415 	(cmdline_parse_inst_t *)&cmd_showfwdall,
19416 	(cmdline_parse_inst_t *)&cmd_start,
19417 	(cmdline_parse_inst_t *)&cmd_start_tx_first,
19418 	(cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19419 	(cmdline_parse_inst_t *)&cmd_set_link_up,
19420 	(cmdline_parse_inst_t *)&cmd_set_link_down,
19421 	(cmdline_parse_inst_t *)&cmd_reset,
19422 	(cmdline_parse_inst_t *)&cmd_set_numbers,
19423 	(cmdline_parse_inst_t *)&cmd_set_log,
19424 	(cmdline_parse_inst_t *)&cmd_set_txpkts,
19425 	(cmdline_parse_inst_t *)&cmd_set_txsplit,
19426 	(cmdline_parse_inst_t *)&cmd_set_fwd_list,
19427 	(cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19428 	(cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19429 	(cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19430 	(cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19431 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19432 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19433 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19434 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19435 	(cmdline_parse_inst_t *)&cmd_set_flush_rx,
19436 	(cmdline_parse_inst_t *)&cmd_set_link_check,
19437 	(cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19438 	(cmdline_parse_inst_t *)&cmd_set_bypass_event,
19439 	(cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19440 	(cmdline_parse_inst_t *)&cmd_show_bypass_config,
19441 #ifdef RTE_LIBRTE_PMD_BOND
19442 	(cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19443 	(cmdline_parse_inst_t *) &cmd_show_bonding_config,
19444 	(cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19445 	(cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19446 	(cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19447 	(cmdline_parse_inst_t *) &cmd_create_bonded_device,
19448 	(cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19449 	(cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19450 	(cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19451 	(cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19452 	(cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19453 #endif
19454 	(cmdline_parse_inst_t *)&cmd_vlan_offload,
19455 	(cmdline_parse_inst_t *)&cmd_vlan_tpid,
19456 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19457 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19458 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19459 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19460 	(cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19461 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19462 	(cmdline_parse_inst_t *)&cmd_csum_set,
19463 	(cmdline_parse_inst_t *)&cmd_csum_show,
19464 	(cmdline_parse_inst_t *)&cmd_csum_tunnel,
19465 	(cmdline_parse_inst_t *)&cmd_tso_set,
19466 	(cmdline_parse_inst_t *)&cmd_tso_show,
19467 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19468 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19469 	(cmdline_parse_inst_t *)&cmd_gro_enable,
19470 	(cmdline_parse_inst_t *)&cmd_gro_flush,
19471 	(cmdline_parse_inst_t *)&cmd_gro_show,
19472 	(cmdline_parse_inst_t *)&cmd_gso_enable,
19473 	(cmdline_parse_inst_t *)&cmd_gso_size,
19474 	(cmdline_parse_inst_t *)&cmd_gso_show,
19475 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19476 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19477 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19478 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19479 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19480 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19481 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19482 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19483 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19484 	(cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19485 	(cmdline_parse_inst_t *)&cmd_config_dcb,
19486 	(cmdline_parse_inst_t *)&cmd_read_reg,
19487 	(cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19488 	(cmdline_parse_inst_t *)&cmd_read_reg_bit,
19489 	(cmdline_parse_inst_t *)&cmd_write_reg,
19490 	(cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19491 	(cmdline_parse_inst_t *)&cmd_write_reg_bit,
19492 	(cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19493 	(cmdline_parse_inst_t *)&cmd_stop,
19494 	(cmdline_parse_inst_t *)&cmd_mac_addr,
19495 	(cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19496 	(cmdline_parse_inst_t *)&cmd_set_qmap,
19497 	(cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19498 	(cmdline_parse_inst_t *)&cmd_operate_port,
19499 	(cmdline_parse_inst_t *)&cmd_operate_specific_port,
19500 	(cmdline_parse_inst_t *)&cmd_operate_attach_port,
19501 	(cmdline_parse_inst_t *)&cmd_operate_detach_port,
19502 	(cmdline_parse_inst_t *)&cmd_operate_detach_device,
19503 	(cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19504 	(cmdline_parse_inst_t *)&cmd_config_speed_all,
19505 	(cmdline_parse_inst_t *)&cmd_config_speed_specific,
19506 	(cmdline_parse_inst_t *)&cmd_config_loopback_all,
19507 	(cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19508 	(cmdline_parse_inst_t *)&cmd_config_rx_tx,
19509 	(cmdline_parse_inst_t *)&cmd_config_mtu,
19510 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19511 	(cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19512 	(cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19513 	(cmdline_parse_inst_t *)&cmd_config_rss,
19514 	(cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19515 	(cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19516 	(cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19517 	(cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19518 	(cmdline_parse_inst_t *)&cmd_config_rss_reta,
19519 	(cmdline_parse_inst_t *)&cmd_showport_reta,
19520 	(cmdline_parse_inst_t *)&cmd_showport_macs,
19521 	(cmdline_parse_inst_t *)&cmd_config_burst,
19522 	(cmdline_parse_inst_t *)&cmd_config_thresh,
19523 	(cmdline_parse_inst_t *)&cmd_config_threshold,
19524 	(cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19525 	(cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19526 	(cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19527 	(cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19528 	(cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19529 	(cmdline_parse_inst_t *)&cmd_tunnel_filter,
19530 	(cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19531 	(cmdline_parse_inst_t *)&cmd_global_config,
19532 	(cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19533 	(cmdline_parse_inst_t *)&cmd_set_mirror_link,
19534 	(cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19535 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19536 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19537 	(cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19538 	(cmdline_parse_inst_t *)&cmd_dump,
19539 	(cmdline_parse_inst_t *)&cmd_dump_one,
19540 	(cmdline_parse_inst_t *)&cmd_ethertype_filter,
19541 	(cmdline_parse_inst_t *)&cmd_syn_filter,
19542 	(cmdline_parse_inst_t *)&cmd_2tuple_filter,
19543 	(cmdline_parse_inst_t *)&cmd_5tuple_filter,
19544 	(cmdline_parse_inst_t *)&cmd_flex_filter,
19545 	(cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19546 	(cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19547 	(cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19548 	(cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19549 	(cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19550 	(cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19551 	(cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19552 	(cmdline_parse_inst_t *)&cmd_flush_flow_director,
19553 	(cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19554 	(cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19555 	(cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19556 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19557 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19558 	(cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19559 	(cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19560 	(cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19561 	(cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19562 	(cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19563 	(cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19564 	(cmdline_parse_inst_t *)&cmd_flow,
19565 	(cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19566 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19567 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19568 	(cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19569 	(cmdline_parse_inst_t *)&cmd_create_port_meter,
19570 	(cmdline_parse_inst_t *)&cmd_enable_port_meter,
19571 	(cmdline_parse_inst_t *)&cmd_disable_port_meter,
19572 	(cmdline_parse_inst_t *)&cmd_del_port_meter,
19573 	(cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19574 	(cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19575 	(cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19576 	(cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19577 	(cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19578 	(cmdline_parse_inst_t *)&cmd_mcast_addr,
19579 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19580 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19581 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19582 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19583 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19584 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19585 	(cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19586 	(cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19587 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19588 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19589 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19590 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19591 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19592 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19593 	(cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19594 	(cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19595 	(cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19596 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19597 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19598 	(cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19599 	(cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19600 	(cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19601 	(cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19602 	(cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19603 	(cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19604 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19605 	(cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19606 	(cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19607 	(cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19608 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19609 	(cmdline_parse_inst_t *)&cmd_vf_max_bw,
19610 	(cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19611 	(cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19612 	(cmdline_parse_inst_t *)&cmd_strict_link_prio,
19613 	(cmdline_parse_inst_t *)&cmd_tc_min_bw,
19614 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19615 	(cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19616 #endif
19617 	(cmdline_parse_inst_t *)&cmd_set_vxlan,
19618 	(cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19619 	(cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19620 	(cmdline_parse_inst_t *)&cmd_set_nvgre,
19621 	(cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19622 	(cmdline_parse_inst_t *)&cmd_set_l2_encap,
19623 	(cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19624 	(cmdline_parse_inst_t *)&cmd_set_l2_decap,
19625 	(cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19626 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19627 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19628 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19629 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19630 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19631 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19632 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19633 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19634 	(cmdline_parse_inst_t *)&cmd_ddp_add,
19635 	(cmdline_parse_inst_t *)&cmd_ddp_del,
19636 	(cmdline_parse_inst_t *)&cmd_ddp_get_list,
19637 	(cmdline_parse_inst_t *)&cmd_ddp_get_info,
19638 	(cmdline_parse_inst_t *)&cmd_cfg_input_set,
19639 	(cmdline_parse_inst_t *)&cmd_clear_input_set,
19640 	(cmdline_parse_inst_t *)&cmd_show_vf_stats,
19641 	(cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19642 	(cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19643 	(cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19644 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19645 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19646 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19647 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19648 
19649 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19650 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19651 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19652 	(cmdline_parse_inst_t *)&cmd_queue_region,
19653 	(cmdline_parse_inst_t *)&cmd_region_flowtype,
19654 	(cmdline_parse_inst_t *)&cmd_user_priority_region,
19655 	(cmdline_parse_inst_t *)&cmd_flush_queue_region,
19656 	(cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19657 	(cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19658 	(cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19659 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19660 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19661 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19662 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19663 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19664 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19665 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19666 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19667 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19668 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19669 	(cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19670 	(cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19671 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19672 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19673 	(cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19674 	(cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19675 	(cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19676 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19677 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19678 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19679 	(cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19680 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19681 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19682 	(cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19683 	(cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19684 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19685 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19686 	(cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19687 	(cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19688 #ifdef RTE_LIBRTE_BPF
19689 	(cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19690 	(cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19691 #endif
19692 	(cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19693 	(cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19694 	(cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19695 	(cmdline_parse_inst_t *)&cmd_set_raw,
19696 	(cmdline_parse_inst_t *)&cmd_show_set_raw,
19697 	(cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19698 	(cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19699 	NULL,
19700 };
19701 
19702 /* read cmdline commands from file */
19703 void
19704 cmdline_read_from_file(const char *filename)
19705 {
19706 	struct cmdline *cl;
19707 
19708 	cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19709 	if (cl == NULL) {
19710 		printf("Failed to create file based cmdline context: %s\n",
19711 		       filename);
19712 		return;
19713 	}
19714 
19715 	cmdline_interact(cl);
19716 	cmdline_quit(cl);
19717 
19718 	cmdline_free(cl);
19719 
19720 	printf("Read CLI commands from %s\n", filename);
19721 }
19722 
19723 /* prompt function, called from main on MASTER lcore */
19724 void
19725 prompt(void)
19726 {
19727 	/* initialize non-constant commands */
19728 	cmd_set_fwd_mode_init();
19729 	cmd_set_fwd_retry_mode_init();
19730 
19731 	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19732 	if (testpmd_cl == NULL)
19733 		return;
19734 	cmdline_interact(testpmd_cl);
19735 	cmdline_stdin_exit(testpmd_cl);
19736 }
19737 
19738 void
19739 prompt_exit(void)
19740 {
19741 	if (testpmd_cl != NULL)
19742 		cmdline_quit(testpmd_cl);
19743 }
19744 
19745 static void
19746 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19747 {
19748 	if (id == (portid_t)RTE_PORT_ALL) {
19749 		portid_t pid;
19750 
19751 		RTE_ETH_FOREACH_DEV(pid) {
19752 			/* check if need_reconfig has been set to 1 */
19753 			if (ports[pid].need_reconfig == 0)
19754 				ports[pid].need_reconfig = dev;
19755 			/* check if need_reconfig_queues has been set to 1 */
19756 			if (ports[pid].need_reconfig_queues == 0)
19757 				ports[pid].need_reconfig_queues = queue;
19758 		}
19759 	} else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19760 		/* check if need_reconfig has been set to 1 */
19761 		if (ports[id].need_reconfig == 0)
19762 			ports[id].need_reconfig = dev;
19763 		/* check if need_reconfig_queues has been set to 1 */
19764 		if (ports[id].need_reconfig_queues == 0)
19765 			ports[id].need_reconfig_queues = queue;
19766 	}
19767 }
19768