xref: /dpdk/app/test-pmd/cmdline.c (revision 10b71caecbe1cddcbb65c050ca775fba575e88db)
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 txtimes (x, y)\n"
298 			"    Set the scheduling on timestamps"
299 			" timings for the TXONLY mode\n\n"
300 
301 			"set corelist (x[,y]*)\n"
302 			"    Set the list of forwarding cores.\n\n"
303 
304 			"set portlist (x[,y]*)\n"
305 			"    Set the list of forwarding ports.\n\n"
306 
307 			"set port setup on (iterator|event)\n"
308 			"    Select how attached port is retrieved for setup.\n\n"
309 
310 			"set tx loopback (port_id) (on|off)\n"
311 			"    Enable or disable tx loopback.\n\n"
312 
313 			"set all queues drop (port_id) (on|off)\n"
314 			"    Set drop enable bit for all queues.\n\n"
315 
316 			"set vf split drop (port_id) (vf_id) (on|off)\n"
317 			"    Set split drop enable bit for a VF from the PF.\n\n"
318 
319 			"set vf mac antispoof (port_id) (vf_id) (on|off).\n"
320 			"    Set MAC antispoof for a VF from the PF.\n\n"
321 
322 			"set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
323 			"    Enable MACsec offload.\n\n"
324 
325 			"set macsec offload (port_id) off\n"
326 			"    Disable MACsec offload.\n\n"
327 
328 			"set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
329 			"    Configure MACsec secure connection (SC).\n\n"
330 
331 			"set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
332 			"    Configure MACsec secure association (SA).\n\n"
333 
334 			"set vf broadcast (port_id) (vf_id) (on|off)\n"
335 			"    Set VF broadcast for a VF from the PF.\n\n"
336 
337 			"vlan set stripq (on|off) (port_id,queue_id)\n"
338 			"    Set the VLAN strip for a queue on a port.\n\n"
339 
340 			"set vf vlan stripq (port_id) (vf_id) (on|off)\n"
341 			"    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
342 
343 			"set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
344 			"    Set VLAN insert for a VF from the PF.\n\n"
345 
346 			"set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
347 			"    Set VLAN antispoof for a VF from the PF.\n\n"
348 
349 			"set vf vlan tag (port_id) (vf_id) (on|off)\n"
350 			"    Set VLAN tag for a VF from the PF.\n\n"
351 
352 			"set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
353 			"    Set a VF's max bandwidth(Mbps).\n\n"
354 
355 			"set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
356 			"    Set all TCs' min bandwidth(%%) on a VF.\n\n"
357 
358 			"set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
359 			"    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
360 
361 			"set tx strict-link-priority (port_id) (tc_bitmap)\n"
362 			"    Set some TCs' strict link priority mode on a physical port.\n\n"
363 
364 			"set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
365 			"    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
366 
367 			"vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
368 			"    Set the VLAN strip or filter or qinq strip or extend\n\n"
369 
370 			"vlan set (inner|outer) tpid (value) (port_id)\n"
371 			"    Set the VLAN TPID for Packet Filtering on"
372 			" a port\n\n"
373 
374 			"rx_vlan add (vlan_id|all) (port_id)\n"
375 			"    Add a vlan_id, or all identifiers, to the set"
376 			" of VLAN identifiers filtered by port_id.\n\n"
377 
378 			"rx_vlan rm (vlan_id|all) (port_id)\n"
379 			"    Remove a vlan_id, or all identifiers, from the set"
380 			" of VLAN identifiers filtered by port_id.\n\n"
381 
382 			"rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
383 			"    Add a vlan_id, to the set of VLAN identifiers"
384 			"filtered for VF(s) from port_id.\n\n"
385 
386 			"rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
387 			"    Remove a vlan_id, to the set of VLAN identifiers"
388 			"filtered for VF(s) from port_id.\n\n"
389 
390 			"tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
391 			"(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
392 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
393 			"   add a tunnel filter of a port.\n\n"
394 
395 			"tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
396 			"(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
397 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
398 			"   remove a tunnel filter of a port.\n\n"
399 
400 			"rx_vxlan_port add (udp_port) (port_id)\n"
401 			"    Add an UDP port for VXLAN packet filter on a port\n\n"
402 
403 			"rx_vxlan_port rm (udp_port) (port_id)\n"
404 			"    Remove an UDP port for VXLAN packet filter on a port\n\n"
405 
406 			"tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
407 			"    Set hardware insertion of VLAN IDs (single or double VLAN "
408 			"depends on the number of VLAN IDs) in packets sent on a port.\n\n"
409 
410 			"tx_vlan set pvid port_id vlan_id (on|off)\n"
411 			"    Set port based TX VLAN insertion.\n\n"
412 
413 			"tx_vlan reset (port_id)\n"
414 			"    Disable hardware insertion of a VLAN header in"
415 			" packets sent on a port.\n\n"
416 
417 			"csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
418 			"    Select hardware or software calculation of the"
419 			" checksum when transmitting a packet using the"
420 			" csum forward engine.\n"
421 			"    ip|udp|tcp|sctp always concern the inner layer.\n"
422 			"    outer-ip concerns the outer IP layer in"
423 			"    outer-udp concerns the outer UDP layer in"
424 			" case the packet is recognized as a tunnel packet by"
425 			" the forward engine (vxlan, gre and ipip are supported)\n"
426 			"    Please check the NIC datasheet for HW limits.\n\n"
427 
428 			"csum parse-tunnel (on|off) (tx_port_id)\n"
429 			"    If disabled, treat tunnel packets as non-tunneled"
430 			" packets (treat inner headers as payload). The port\n"
431 			"    argument is the port used for TX in csum forward"
432 			" engine.\n\n"
433 
434 			"csum show (port_id)\n"
435 			"    Display tx checksum offload configuration\n\n"
436 
437 			"tso set (segsize) (portid)\n"
438 			"    Enable TCP Segmentation Offload in csum forward"
439 			" engine.\n"
440 			"    Please check the NIC datasheet for HW limits.\n\n"
441 
442 			"tso show (portid)"
443 			"    Display the status of TCP Segmentation Offload.\n\n"
444 
445 			"set port (port_id) gro on|off\n"
446 			"    Enable or disable Generic Receive Offload in"
447 			" csum forwarding engine.\n\n"
448 
449 			"show port (port_id) gro\n"
450 			"    Display GRO configuration.\n\n"
451 
452 			"set gro flush (cycles)\n"
453 			"    Set the cycle to flush GROed packets from"
454 			" reassembly tables.\n\n"
455 
456 			"set port (port_id) gso (on|off)"
457 			"    Enable or disable Generic Segmentation Offload in"
458 			" csum forwarding engine.\n\n"
459 
460 			"set gso segsz (length)\n"
461 			"    Set max packet length for output GSO segments,"
462 			" including packet header and payload.\n\n"
463 
464 			"show port (port_id) gso\n"
465 			"    Show GSO configuration.\n\n"
466 
467 			"set fwd (%s)\n"
468 			"    Set packet forwarding mode.\n\n"
469 
470 			"mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
471 			"    Add a MAC address on port_id.\n\n"
472 
473 			"mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
474 			"    Remove a MAC address from port_id.\n\n"
475 
476 			"mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
477 			"    Set the default MAC address for port_id.\n\n"
478 
479 			"mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
480 			"    Add a MAC address for a VF on the port.\n\n"
481 
482 			"set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
483 			"    Set the MAC address for a VF from the PF.\n\n"
484 
485 			"set eth-peer (port_id) (peer_addr)\n"
486 			"    set the peer address for certain port.\n\n"
487 
488 			"set port (port_id) uta (mac_address|all) (on|off)\n"
489 			"    Add/Remove a or all unicast hash filter(s)"
490 			"from port X.\n\n"
491 
492 			"set promisc (port_id|all) (on|off)\n"
493 			"    Set the promiscuous mode on port_id, or all.\n\n"
494 
495 			"set allmulti (port_id|all) (on|off)\n"
496 			"    Set the allmulti mode on port_id, or all.\n\n"
497 
498 			"set vf promisc (port_id) (vf_id) (on|off)\n"
499 			"    Set unicast promiscuous mode for a VF from the PF.\n\n"
500 
501 			"set vf allmulti (port_id) (vf_id) (on|off)\n"
502 			"    Set multicast promiscuous mode for a VF from the PF.\n\n"
503 
504 			"set flow_ctrl rx (on|off) tx (on|off) (high_water)"
505 			" (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
506 			" (on|off) autoneg (on|off) (port_id)\n"
507 			"set flow_ctrl rx (on|off) (portid)\n"
508 			"set flow_ctrl tx (on|off) (portid)\n"
509 			"set flow_ctrl high_water (high_water) (portid)\n"
510 			"set flow_ctrl low_water (low_water) (portid)\n"
511 			"set flow_ctrl pause_time (pause_time) (portid)\n"
512 			"set flow_ctrl send_xon (send_xon) (portid)\n"
513 			"set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
514 			"set flow_ctrl autoneg (on|off) (port_id)\n"
515 			"    Set the link flow control parameter on a port.\n\n"
516 
517 			"set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
518 			" (low_water) (pause_time) (priority) (port_id)\n"
519 			"    Set the priority flow control parameter on a"
520 			" port.\n\n"
521 
522 			"set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
523 			"    Set statistics mapping (qmapping 0..15) for RX/TX"
524 			" queue on port.\n"
525 			"    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
526 			" on port 0 to mapping 5.\n\n"
527 
528 			"set xstats-hide-zero on|off\n"
529 			"    Set the option to hide the zero values"
530 			" for xstats display.\n"
531 
532 			"set port (port_id) vf (vf_id) rx|tx on|off\n"
533 			"    Enable/Disable a VF receive/tranmit from a port\n\n"
534 
535 			"set port (port_id) vf (vf_id) (mac_addr)"
536 			" (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
537 			"   Add/Remove unicast or multicast MAC addr filter"
538 			" for a VF.\n\n"
539 
540 			"set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
541 			"|MPE) (on|off)\n"
542 			"    AUPE:accepts untagged VLAN;"
543 			"ROPE:accept unicast hash\n\n"
544 			"    BAM:accepts broadcast packets;"
545 			"MPE:accepts all multicast packets\n\n"
546 			"    Enable/Disable a VF receive mode of a port\n\n"
547 
548 			"set port (port_id) queue (queue_id) rate (rate_num)\n"
549 			"    Set rate limit for a queue of a port\n\n"
550 
551 			"set port (port_id) vf (vf_id) rate (rate_num) "
552 			"queue_mask (queue_mask_value)\n"
553 			"    Set rate limit for queues in VF of a port\n\n"
554 
555 			"set port (port_id) mirror-rule (rule_id)"
556 			" (pool-mirror-up|pool-mirror-down|vlan-mirror)"
557 			" (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
558 			"   Set pool or vlan type mirror rule on a port.\n"
559 			"   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
560 			" dst-pool 0 on' enable mirror traffic with vlan 0,1"
561 			" to pool 0.\n\n"
562 
563 			"set port (port_id) mirror-rule (rule_id)"
564 			" (uplink-mirror|downlink-mirror) dst-pool"
565 			" (pool_id) (on|off)\n"
566 			"   Set uplink or downlink type mirror rule on a port.\n"
567 			"   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
568 			" 0 on' enable mirror income traffic to pool 0.\n\n"
569 
570 			"reset port (port_id) mirror-rule (rule_id)\n"
571 			"   Reset a mirror rule.\n\n"
572 
573 			"set flush_rx (on|off)\n"
574 			"   Flush (default) or don't flush RX streams before"
575 			" forwarding. Mainly used with PCAP drivers.\n\n"
576 
577 			"set bypass mode (normal|bypass|isolate) (port_id)\n"
578 			"   Set the bypass mode for the lowest port on bypass enabled"
579 			" NIC.\n\n"
580 
581 			"set bypass event (timeout|os_on|os_off|power_on|power_off) "
582 			"mode (normal|bypass|isolate) (port_id)\n"
583 			"   Set the event required to initiate specified bypass mode for"
584 			" the lowest port on a bypass enabled NIC where:\n"
585 			"       timeout   = enable bypass after watchdog timeout.\n"
586 			"       os_on     = enable bypass when OS/board is powered on.\n"
587 			"       os_off    = enable bypass when OS/board is powered off.\n"
588 			"       power_on  = enable bypass when power supply is turned on.\n"
589 			"       power_off = enable bypass when power supply is turned off."
590 			"\n\n"
591 
592 			"set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
593 			"   Set the bypass watchdog timeout to 'n' seconds"
594 			" where 0 = instant.\n\n"
595 
596 			"show bypass config (port_id)\n"
597 			"   Show the bypass configuration for a bypass enabled NIC"
598 			" using the lowest port on the NIC.\n\n"
599 
600 #ifdef RTE_LIBRTE_PMD_BOND
601 			"create bonded device (mode) (socket)\n"
602 			"	Create a new bonded device with specific bonding mode and socket.\n\n"
603 
604 			"add bonding slave (slave_id) (port_id)\n"
605 			"	Add a slave device to a bonded device.\n\n"
606 
607 			"remove bonding slave (slave_id) (port_id)\n"
608 			"	Remove a slave device from a bonded device.\n\n"
609 
610 			"set bonding mode (value) (port_id)\n"
611 			"	Set the bonding mode on a bonded device.\n\n"
612 
613 			"set bonding primary (slave_id) (port_id)\n"
614 			"	Set the primary slave for a bonded device.\n\n"
615 
616 			"show bonding config (port_id)\n"
617 			"	Show the bonding config for port_id.\n\n"
618 
619 			"set bonding mac_addr (port_id) (address)\n"
620 			"	Set the MAC address of a bonded device.\n\n"
621 
622 			"set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
623 			"	Set Aggregation mode for IEEE802.3AD (mode 4)"
624 
625 			"set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
626 			"	Set the transmit balance policy for bonded device running in balance mode.\n\n"
627 
628 			"set bonding mon_period (port_id) (value)\n"
629 			"	Set the bonding link status monitoring polling period in ms.\n\n"
630 
631 			"set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
632 			"	Enable/disable dedicated queues for LACP control traffic.\n\n"
633 
634 #endif
635 			"set link-up port (port_id)\n"
636 			"	Set link up for a port.\n\n"
637 
638 			"set link-down port (port_id)\n"
639 			"	Set link down for a port.\n\n"
640 
641 			"E-tag set insertion on port-tag-id (value)"
642 			" port (port_id) vf (vf_id)\n"
643 			"    Enable E-tag insertion for a VF on a port\n\n"
644 
645 			"E-tag set insertion off port (port_id) vf (vf_id)\n"
646 			"    Disable E-tag insertion for a VF on a port\n\n"
647 
648 			"E-tag set stripping (on|off) port (port_id)\n"
649 			"    Enable/disable E-tag stripping on a port\n\n"
650 
651 			"E-tag set forwarding (on|off) port (port_id)\n"
652 			"    Enable/disable E-tag based forwarding"
653 			" on a port\n\n"
654 
655 			"E-tag set filter add e-tag-id (value) dst-pool"
656 			" (pool_id) port (port_id)\n"
657 			"    Add an E-tag forwarding filter on a port\n\n"
658 
659 			"E-tag set filter del e-tag-id (value) port (port_id)\n"
660 			"    Delete an E-tag forwarding filter on a port\n\n"
661 
662 			"ddp add (port_id) (profile_path[,backup_profile_path])\n"
663 			"    Load a profile package on a port\n\n"
664 
665 			"ddp del (port_id) (backup_profile_path)\n"
666 			"    Delete a profile package from a port\n\n"
667 
668 			"ptype mapping get (port_id) (valid_only)\n"
669 			"    Get ptype mapping on a port\n\n"
670 
671 			"ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
672 			"    Replace target with the pkt_type in ptype mapping\n\n"
673 
674 			"ptype mapping reset (port_id)\n"
675 			"    Reset ptype mapping on a port\n\n"
676 
677 			"ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
678 			"    Update a ptype mapping item on a port\n\n"
679 
680 			"set port (port_id) ptype_mask (ptype_mask)\n"
681 			"    set packet types classification for a specific port\n\n"
682 
683 			"set port (port_id) queue-region region_id (value) "
684 			"queue_start_index (value) queue_num (value)\n"
685 			"    Set a queue region on a port\n\n"
686 
687 			"set port (port_id) queue-region region_id (value) "
688 			"flowtype (value)\n"
689 			"    Set a flowtype region index on a port\n\n"
690 
691 			"set port (port_id) queue-region UP (value) region_id (value)\n"
692 			"    Set the mapping of User Priority to "
693 			"queue region on a port\n\n"
694 
695 			"set port (port_id) queue-region flush (on|off)\n"
696 			"    flush all queue region related configuration\n\n"
697 
698 			"show port meter cap (port_id)\n"
699 			"    Show port meter capability information\n\n"
700 
701 			"add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
702 			"    meter profile add - srtcm rfc 2697\n\n"
703 
704 			"add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
705 			"    meter profile add - trtcm rfc 2698\n\n"
706 
707 			"add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
708 			"    meter profile add - trtcm rfc 4115\n\n"
709 
710 			"del port meter profile (port_id) (profile_id)\n"
711 			"    meter profile delete\n\n"
712 
713 			"create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
714 			"(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
715 			"(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
716 			"(dscp_tbl_entry63)]\n"
717 			"    meter create\n\n"
718 
719 			"enable port meter (port_id) (mtr_id)\n"
720 			"    meter enable\n\n"
721 
722 			"disable port meter (port_id) (mtr_id)\n"
723 			"    meter disable\n\n"
724 
725 			"del port meter (port_id) (mtr_id)\n"
726 			"    meter delete\n\n"
727 
728 			"set port meter profile (port_id) (mtr_id) (profile_id)\n"
729 			"    meter update meter profile\n\n"
730 
731 			"set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
732 			"(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
733 			"    update meter dscp table entries\n\n"
734 
735 			"set port meter policer action (port_id) (mtr_id) (action_mask)\n"
736 			"(action0) [(action1) (action2)]\n"
737 			"    meter update policer action\n\n"
738 
739 			"set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
740 			"    meter update stats\n\n"
741 
742 			"show port (port_id) queue-region\n"
743 			"    show all queue region related configuration info\n\n"
744 
745 			, list_pkt_forwarding_modes()
746 		);
747 	}
748 
749 	if (show_all || !strcmp(res->section, "ports")) {
750 
751 		cmdline_printf(
752 			cl,
753 			"\n"
754 			"Port Operations:\n"
755 			"----------------\n\n"
756 
757 			"port start (port_id|all)\n"
758 			"    Start all ports or port_id.\n\n"
759 
760 			"port stop (port_id|all)\n"
761 			"    Stop all ports or port_id.\n\n"
762 
763 			"port close (port_id|all)\n"
764 			"    Close all ports or port_id.\n\n"
765 
766 			"port reset (port_id|all)\n"
767 			"    Reset all ports or port_id.\n\n"
768 
769 			"port attach (ident)\n"
770 			"    Attach physical or virtual dev by pci address or virtual device name\n\n"
771 
772 			"port detach (port_id)\n"
773 			"    Detach physical or virtual dev by port_id\n\n"
774 
775 			"port config (port_id|all)"
776 			" speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
777 			" duplex (half|full|auto)\n"
778 			"    Set speed and duplex for all ports or port_id\n\n"
779 
780 			"port config (port_id|all) loopback (mode)\n"
781 			"    Set loopback mode for all ports or port_id\n\n"
782 
783 			"port config all (rxq|txq|rxd|txd) (value)\n"
784 			"    Set number for rxq/txq/rxd/txd.\n\n"
785 
786 			"port config all max-pkt-len (value)\n"
787 			"    Set the max packet length.\n\n"
788 
789 			"port config all max-lro-pkt-size (value)\n"
790 			"    Set the max LRO aggregated packet size.\n\n"
791 
792 			"port config all drop-en (on|off)\n"
793 			"    Enable or disable packet drop on all RX queues of all ports when no "
794 			"receive buffers available.\n\n"
795 
796 			"port config all rss (all|default|ip|tcp|udp|sctp|"
797 			"ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
798 			"    Set the RSS mode.\n\n"
799 
800 			"port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
801 			"    Set the RSS redirection table.\n\n"
802 
803 			"port config (port_id) dcb vt (on|off) (traffic_class)"
804 			" pfc (on|off)\n"
805 			"    Set the DCB mode.\n\n"
806 
807 			"port config all burst (value)\n"
808 			"    Set the number of packets per burst.\n\n"
809 
810 			"port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
811 			" (value)\n"
812 			"    Set the ring prefetch/host/writeback threshold"
813 			" for tx/rx queue.\n\n"
814 
815 			"port config all (txfreet|txrst|rxfreet) (value)\n"
816 			"    Set free threshold for rx/tx, or set"
817 			" tx rs bit threshold.\n\n"
818 			"port config mtu X value\n"
819 			"    Set the MTU of port X to a given value\n\n"
820 
821 			"port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
822 			"    Set a rx/tx queue's ring size configuration, the new"
823 			" value will take effect after command that (re-)start the port"
824 			" or command that setup the specific queue\n\n"
825 
826 			"port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
827 			"    Start/stop a rx/tx queue of port X. Only take effect"
828 			" when port X is started\n\n"
829 
830 			"port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
831 			"    Switch on/off a deferred start of port X rx/tx queue. Only"
832 			" take effect when port X is stopped.\n\n"
833 
834 			"port (port_id) (rxq|txq) (queue_id) setup\n"
835 			"    Setup a rx/tx queue of port X.\n\n"
836 
837 			"port config (port_id|all) l2-tunnel E-tag ether-type"
838 			" (value)\n"
839 			"    Set the value of E-tag ether-type.\n\n"
840 
841 			"port config (port_id|all) l2-tunnel E-tag"
842 			" (enable|disable)\n"
843 			"    Enable/disable the E-tag support.\n\n"
844 
845 			"port config (port_id) pctype mapping reset\n"
846 			"    Reset flow type to pctype mapping on a port\n\n"
847 
848 			"port config (port_id) pctype mapping update"
849 			" (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
850 			"    Update a flow type to pctype mapping item on a port\n\n"
851 
852 			"port config (port_id) pctype (pctype_id) hash_inset|"
853 			"fdir_inset|fdir_flx_inset get|set|clear field\n"
854 			" (field_idx)\n"
855 			"    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
856 
857 			"port config (port_id) pctype (pctype_id) hash_inset|"
858 			"fdir_inset|fdir_flx_inset clear all"
859 			"    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
860 
861 			"port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
862 			"    Add/remove UDP tunnel port for tunneling offload\n\n"
863 
864 			"port config <port_id> rx_offload vlan_strip|"
865 			"ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
866 			"outer_ipv4_cksum|macsec_strip|header_split|"
867 			"vlan_filter|vlan_extend|jumbo_frame|"
868 			"scatter|timestamp|security|keep_crc on|off\n"
869 			"     Enable or disable a per port Rx offloading"
870 			" on all Rx queues of a port\n\n"
871 
872 			"port (port_id) rxq (queue_id) rx_offload vlan_strip|"
873 			"ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
874 			"outer_ipv4_cksum|macsec_strip|header_split|"
875 			"vlan_filter|vlan_extend|jumbo_frame|"
876 			"scatter|timestamp|security|keep_crc on|off\n"
877 			"    Enable or disable a per queue Rx offloading"
878 			" only on a specific Rx queue\n\n"
879 
880 			"port config (port_id) tx_offload vlan_insert|"
881 			"ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
882 			"udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
883 			"gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
884 			"macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
885 			"security on|off\n"
886 			"    Enable or disable a per port Tx offloading"
887 			" on all Tx queues of a port\n\n"
888 
889 			"port (port_id) txq (queue_id) tx_offload vlan_insert|"
890 			"ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
891 			"udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
892 			"gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
893 			"|mt_lockfree|multi_segs|mbuf_fast_free|security"
894 			" on|off\n"
895 			"    Enable or disable a per queue Tx offloading"
896 			" only on a specific Tx queue\n\n"
897 
898 			"bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
899 			"    Load an eBPF program as a callback"
900 			" for particular RX/TX queue\n\n"
901 
902 			"bpf-unload rx|tx (port) (queue)\n"
903 			"    Unload previously loaded eBPF program"
904 			" for particular RX/TX queue\n\n"
905 
906 			"port config (port_id) tx_metadata (value)\n"
907 			"    Set Tx metadata value per port. Testpmd will add this value"
908 			" to any Tx packet sent from this port\n\n"
909 
910 			"port config (port_id) dynf (name) set|clear\n"
911 			"    Register a dynf and Set/clear this flag on Tx. "
912 			"Testpmd will set this value to any Tx packet "
913 			"sent from this port\n\n"
914 		);
915 	}
916 
917 	if (show_all || !strcmp(res->section, "registers")) {
918 
919 		cmdline_printf(
920 			cl,
921 			"\n"
922 			"Registers:\n"
923 			"----------\n\n"
924 
925 			"read reg (port_id) (address)\n"
926 			"    Display value of a port register.\n\n"
927 
928 			"read regfield (port_id) (address) (bit_x) (bit_y)\n"
929 			"    Display a port register bit field.\n\n"
930 
931 			"read regbit (port_id) (address) (bit_x)\n"
932 			"    Display a single port register bit.\n\n"
933 
934 			"write reg (port_id) (address) (value)\n"
935 			"    Set value of a port register.\n\n"
936 
937 			"write regfield (port_id) (address) (bit_x) (bit_y)"
938 			" (value)\n"
939 			"    Set bit field of a port register.\n\n"
940 
941 			"write regbit (port_id) (address) (bit_x) (value)\n"
942 			"    Set single bit value of a port register.\n\n"
943 		);
944 	}
945 	if (show_all || !strcmp(res->section, "filters")) {
946 
947 		cmdline_printf(
948 			cl,
949 			"\n"
950 			"filters:\n"
951 			"--------\n\n"
952 
953 			"ethertype_filter (port_id) (add|del)"
954 			" (mac_addr|mac_ignr) (mac_address) ethertype"
955 			" (ether_type) (drop|fwd) queue (queue_id)\n"
956 			"    Add/Del an ethertype filter.\n\n"
957 
958 			"2tuple_filter (port_id) (add|del)"
959 			" dst_port (dst_port_value) protocol (protocol_value)"
960 			" mask (mask_value) tcp_flags (tcp_flags_value)"
961 			" priority (prio_value) queue (queue_id)\n"
962 			"    Add/Del a 2tuple filter.\n\n"
963 
964 			"5tuple_filter (port_id) (add|del)"
965 			" dst_ip (dst_address) src_ip (src_address)"
966 			" dst_port (dst_port_value) src_port (src_port_value)"
967 			" protocol (protocol_value)"
968 			" mask (mask_value) tcp_flags (tcp_flags_value)"
969 			" priority (prio_value) queue (queue_id)\n"
970 			"    Add/Del a 5tuple filter.\n\n"
971 
972 			"syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
973 			"    Add/Del syn filter.\n\n"
974 
975 			"flex_filter (port_id) (add|del) len (len_value)"
976 			" bytes (bytes_value) mask (mask_value)"
977 			" priority (prio_value) queue (queue_id)\n"
978 			"    Add/Del a flex filter.\n\n"
979 
980 			"flow_director_filter (port_id) mode IP (add|del|update)"
981 			" flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
982 			" src (src_ip_address) dst (dst_ip_address)"
983 			" tos (tos_value) proto (proto_value) ttl (ttl_value)"
984 			" vlan (vlan_value) flexbytes (flexbytes_value)"
985 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
986 			" fd_id (fd_id_value)\n"
987 			"    Add/Del an IP type flow director filter.\n\n"
988 
989 			"flow_director_filter (port_id) mode IP (add|del|update)"
990 			" flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
991 			" src (src_ip_address) (src_port)"
992 			" dst (dst_ip_address) (dst_port)"
993 			" tos (tos_value) ttl (ttl_value)"
994 			" vlan (vlan_value) flexbytes (flexbytes_value)"
995 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
996 			" fd_id (fd_id_value)\n"
997 			"    Add/Del an UDP/TCP type flow director filter.\n\n"
998 
999 			"flow_director_filter (port_id) mode IP (add|del|update)"
1000 			" flow (ipv4-sctp|ipv6-sctp)"
1001 			" src (src_ip_address) (src_port)"
1002 			" dst (dst_ip_address) (dst_port)"
1003 			" tag (verification_tag) "
1004 			" tos (tos_value) ttl (ttl_value)"
1005 			" vlan (vlan_value)"
1006 			" flexbytes (flexbytes_value) (drop|fwd)"
1007 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1008 			"    Add/Del a SCTP type flow director filter.\n\n"
1009 
1010 			"flow_director_filter (port_id) mode IP (add|del|update)"
1011 			" flow l2_payload ether (ethertype)"
1012 			" flexbytes (flexbytes_value) (drop|fwd)"
1013 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1014 			"    Add/Del a l2 payload type flow director filter.\n\n"
1015 
1016 			"flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1017 			" mac (mac_address) vlan (vlan_value)"
1018 			" flexbytes (flexbytes_value) (drop|fwd)"
1019 			" queue (queue_id) fd_id (fd_id_value)\n"
1020 			"    Add/Del a MAC-VLAN flow director filter.\n\n"
1021 
1022 			"flow_director_filter (port_id) mode Tunnel (add|del|update)"
1023 			" mac (mac_address) vlan (vlan_value)"
1024 			" tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1025 			" flexbytes (flexbytes_value) (drop|fwd)"
1026 			" queue (queue_id) fd_id (fd_id_value)\n"
1027 			"    Add/Del a Tunnel flow director filter.\n\n"
1028 
1029 			"flow_director_filter (port_id) mode raw (add|del|update)"
1030 			" flow (flow_id) (drop|fwd) queue (queue_id)"
1031 			" fd_id (fd_id_value) packet (packet file name)\n"
1032 			"    Add/Del a raw type flow director filter.\n\n"
1033 
1034 			"flush_flow_director (port_id)\n"
1035 			"    Flush all flow director entries of a device.\n\n"
1036 
1037 			"flow_director_mask (port_id) mode IP vlan (vlan_value)"
1038 			" src_mask (ipv4_src) (ipv6_src) (src_port)"
1039 			" dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1040 			"    Set flow director IP mask.\n\n"
1041 
1042 			"flow_director_mask (port_id) mode MAC-VLAN"
1043 			" vlan (vlan_value)\n"
1044 			"    Set flow director MAC-VLAN mask.\n\n"
1045 
1046 			"flow_director_mask (port_id) mode Tunnel"
1047 			" vlan (vlan_value) mac (mac_value)"
1048 			" tunnel-type (tunnel_type_value)"
1049 			" tunnel-id (tunnel_id_value)\n"
1050 			"    Set flow director Tunnel mask.\n\n"
1051 
1052 			"flow_director_flex_mask (port_id)"
1053 			" flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1054 			"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1055 			" (mask)\n"
1056 			"    Configure mask of flex payload.\n\n"
1057 
1058 			"flow_director_flex_payload (port_id)"
1059 			" (raw|l2|l3|l4) (config)\n"
1060 			"    Configure flex payload selection.\n\n"
1061 
1062 			"get_sym_hash_ena_per_port (port_id)\n"
1063 			"    get symmetric hash enable configuration per port.\n\n"
1064 
1065 			"set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1066 			"    set symmetric hash enable configuration per port"
1067 			" to enable or disable.\n\n"
1068 
1069 			"get_hash_global_config (port_id)\n"
1070 			"    Get the global configurations of hash filters.\n\n"
1071 
1072 			"set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1073 			" (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1074 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1075 			" (enable|disable)\n"
1076 			"    Set the global configurations of hash filters.\n\n"
1077 
1078 			"set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1079 			"ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1080 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1081 			"l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1082 			"src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1083 			"ipv6-next-header|udp-src-port|udp-dst-port|"
1084 			"tcp-src-port|tcp-dst-port|sctp-src-port|"
1085 			"sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1086 			"fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1087 			"fld-8th|none) (select|add)\n"
1088 			"    Set the input set for hash.\n\n"
1089 
1090 			"set_fdir_input_set (port_id) "
1091 			"(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1092 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1093 			"l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1094 			"dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1095 			"ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1096 			"udp-dst-port|tcp-src-port|tcp-dst-port|"
1097 			"sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1098 			" (select|add)\n"
1099 			"    Set the input set for FDir.\n\n"
1100 
1101 			"flow validate {port_id}"
1102 			" [group {group_id}] [priority {level}]"
1103 			" [ingress] [egress]"
1104 			" pattern {item} [/ {item} [...]] / end"
1105 			" actions {action} [/ {action} [...]] / end\n"
1106 			"    Check whether a flow rule can be created.\n\n"
1107 
1108 			"flow create {port_id}"
1109 			" [group {group_id}] [priority {level}]"
1110 			" [ingress] [egress]"
1111 			" pattern {item} [/ {item} [...]] / end"
1112 			" actions {action} [/ {action} [...]] / end\n"
1113 			"    Create a flow rule.\n\n"
1114 
1115 			"flow destroy {port_id} rule {rule_id} [...]\n"
1116 			"    Destroy specific flow rules.\n\n"
1117 
1118 			"flow flush {port_id}\n"
1119 			"    Destroy all flow rules.\n\n"
1120 
1121 			"flow query {port_id} {rule_id} {action}\n"
1122 			"    Query an existing flow rule.\n\n"
1123 
1124 			"flow list {port_id} [group {group_id}] [...]\n"
1125 			"    List existing flow rules sorted by priority,"
1126 			" filtered by group identifiers.\n\n"
1127 
1128 			"flow isolate {port_id} {boolean}\n"
1129 			"    Restrict ingress traffic to the defined"
1130 			" flow rules\n\n"
1131 
1132 			"flow aged {port_id} [destroy]\n"
1133 			"    List and destroy aged flows"
1134 			" flow rules\n\n"
1135 
1136 			"set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1137 			" (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1138 			" (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1139 			"       Configure the VXLAN encapsulation for flows.\n\n"
1140 
1141 			"set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1142 			" udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1143 			" ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1144 			" eth-dst (eth-dst)\n"
1145 			"       Configure the VXLAN encapsulation for flows.\n\n"
1146 
1147 			"set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1148 			" (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1149 			" ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1150 			" eth-dst (eth-dst)\n"
1151 			"       Configure the VXLAN encapsulation for flows.\n\n"
1152 
1153 			"set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1154 			" (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1155 			" (eth-dst)\n"
1156 			"       Configure the NVGRE encapsulation for flows.\n\n"
1157 
1158 			"set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1159 			" ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1160 			" eth-src (eth-src) eth-dst (eth-dst)\n"
1161 			"       Configure the NVGRE encapsulation for flows.\n\n"
1162 
1163 			"set raw_encap {flow items}\n"
1164 			"	Configure the encapsulation with raw data.\n\n"
1165 
1166 			"set raw_decap {flow items}\n"
1167 			"	Configure the decapsulation with raw data.\n\n"
1168 
1169 		);
1170 	}
1171 
1172 	if (show_all || !strcmp(res->section, "traffic_management")) {
1173 		cmdline_printf(
1174 			cl,
1175 			"\n"
1176 			"Traffic Management:\n"
1177 			"--------------\n"
1178 			"show port tm cap (port_id)\n"
1179 			"       Display the port TM capability.\n\n"
1180 
1181 			"show port tm level cap (port_id) (level_id)\n"
1182 			"       Display the port TM hierarchical level capability.\n\n"
1183 
1184 			"show port tm node cap (port_id) (node_id)\n"
1185 			"       Display the port TM node capability.\n\n"
1186 
1187 			"show port tm node type (port_id) (node_id)\n"
1188 			"       Display the port TM node type.\n\n"
1189 
1190 			"show port tm node stats (port_id) (node_id) (clear)\n"
1191 			"       Display the port TM node stats.\n\n"
1192 
1193 			"add port tm node shaper profile (port_id) (shaper_profile_id)"
1194 			" (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1195 			" (packet_length_adjust)\n"
1196 			"       Add port tm node private shaper profile.\n\n"
1197 
1198 			"del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1199 			"       Delete port tm node private shaper profile.\n\n"
1200 
1201 			"add port tm node shared shaper (port_id) (shared_shaper_id)"
1202 			" (shaper_profile_id)\n"
1203 			"       Add/update port tm node shared shaper.\n\n"
1204 
1205 			"del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1206 			"       Delete port tm node shared shaper.\n\n"
1207 
1208 			"set port tm node shaper profile (port_id) (node_id)"
1209 			" (shaper_profile_id)\n"
1210 			"       Set port tm node shaper profile.\n\n"
1211 
1212 			"add port tm node wred profile (port_id) (wred_profile_id)"
1213 			" (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1214 			" (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1215 			" (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1216 			"       Add port tm node wred profile.\n\n"
1217 
1218 			"del port tm node wred profile (port_id) (wred_profile_id)\n"
1219 			"       Delete port tm node wred profile.\n\n"
1220 
1221 			"add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1222 			" (priority) (weight) (level_id) (shaper_profile_id)"
1223 			" (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1224 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1225 			"       Add port tm nonleaf node.\n\n"
1226 
1227 			"add port tm leaf node (port_id) (node_id) (parent_node_id)"
1228 			" (priority) (weight) (level_id) (shaper_profile_id)"
1229 			" (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1230 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1231 			"       Add port tm leaf node.\n\n"
1232 
1233 			"del port tm node (port_id) (node_id)\n"
1234 			"       Delete port tm node.\n\n"
1235 
1236 			"set port tm node parent (port_id) (node_id) (parent_node_id)"
1237 			" (priority) (weight)\n"
1238 			"       Set port tm node parent.\n\n"
1239 
1240 			"suspend port tm node (port_id) (node_id)"
1241 			"       Suspend tm node.\n\n"
1242 
1243 			"resume port tm node (port_id) (node_id)"
1244 			"       Resume tm node.\n\n"
1245 
1246 			"port tm hierarchy commit (port_id) (clean_on_fail)\n"
1247 			"       Commit tm hierarchy.\n\n"
1248 
1249 			"set port tm mark ip_ecn (port) (green) (yellow)"
1250 			" (red)\n"
1251 			"    Enables/Disables the traffic management marking"
1252 			" for IP ECN (Explicit Congestion Notification)"
1253 			" packets on a given port\n\n"
1254 
1255 			"set port tm mark ip_dscp (port) (green) (yellow)"
1256 			" (red)\n"
1257 			"    Enables/Disables the traffic management marking"
1258 			" on the port for IP dscp packets\n\n"
1259 
1260 			"set port tm mark vlan_dei (port) (green) (yellow)"
1261 			" (red)\n"
1262 			"    Enables/Disables the traffic management marking"
1263 			" on the port for VLAN packets with DEI enabled\n\n"
1264 		);
1265 	}
1266 
1267 	if (show_all || !strcmp(res->section, "devices")) {
1268 		cmdline_printf(
1269 			cl,
1270 			"\n"
1271 			"Device Operations:\n"
1272 			"--------------\n"
1273 			"device detach (identifier)\n"
1274 			"       Detach device by identifier.\n\n"
1275 		);
1276 	}
1277 
1278 }
1279 
1280 cmdline_parse_token_string_t cmd_help_long_help =
1281 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1282 
1283 cmdline_parse_token_string_t cmd_help_long_section =
1284 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1285 			"all#control#display#config#"
1286 			"ports#registers#filters#traffic_management#devices");
1287 
1288 cmdline_parse_inst_t cmd_help_long = {
1289 	.f = cmd_help_long_parsed,
1290 	.data = NULL,
1291 	.help_str = "help all|control|display|config|ports|register|"
1292 		"filters|traffic_management|devices: "
1293 		"Show help",
1294 	.tokens = {
1295 		(void *)&cmd_help_long_help,
1296 		(void *)&cmd_help_long_section,
1297 		NULL,
1298 	},
1299 };
1300 
1301 
1302 /* *** start/stop/close all ports *** */
1303 struct cmd_operate_port_result {
1304 	cmdline_fixed_string_t keyword;
1305 	cmdline_fixed_string_t name;
1306 	cmdline_fixed_string_t value;
1307 };
1308 
1309 static void cmd_operate_port_parsed(void *parsed_result,
1310 				__rte_unused struct cmdline *cl,
1311 				__rte_unused void *data)
1312 {
1313 	struct cmd_operate_port_result *res = parsed_result;
1314 
1315 	if (!strcmp(res->name, "start"))
1316 		start_port(RTE_PORT_ALL);
1317 	else if (!strcmp(res->name, "stop"))
1318 		stop_port(RTE_PORT_ALL);
1319 	else if (!strcmp(res->name, "close"))
1320 		close_port(RTE_PORT_ALL);
1321 	else if (!strcmp(res->name, "reset"))
1322 		reset_port(RTE_PORT_ALL);
1323 	else
1324 		printf("Unknown parameter\n");
1325 }
1326 
1327 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1328 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1329 								"port");
1330 cmdline_parse_token_string_t cmd_operate_port_all_port =
1331 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1332 						"start#stop#close#reset");
1333 cmdline_parse_token_string_t cmd_operate_port_all_all =
1334 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1335 
1336 cmdline_parse_inst_t cmd_operate_port = {
1337 	.f = cmd_operate_port_parsed,
1338 	.data = NULL,
1339 	.help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1340 	.tokens = {
1341 		(void *)&cmd_operate_port_all_cmd,
1342 		(void *)&cmd_operate_port_all_port,
1343 		(void *)&cmd_operate_port_all_all,
1344 		NULL,
1345 	},
1346 };
1347 
1348 /* *** start/stop/close specific port *** */
1349 struct cmd_operate_specific_port_result {
1350 	cmdline_fixed_string_t keyword;
1351 	cmdline_fixed_string_t name;
1352 	uint8_t value;
1353 };
1354 
1355 static void cmd_operate_specific_port_parsed(void *parsed_result,
1356 			__rte_unused struct cmdline *cl,
1357 				__rte_unused void *data)
1358 {
1359 	struct cmd_operate_specific_port_result *res = parsed_result;
1360 
1361 	if (!strcmp(res->name, "start"))
1362 		start_port(res->value);
1363 	else if (!strcmp(res->name, "stop"))
1364 		stop_port(res->value);
1365 	else if (!strcmp(res->name, "close"))
1366 		close_port(res->value);
1367 	else if (!strcmp(res->name, "reset"))
1368 		reset_port(res->value);
1369 	else
1370 		printf("Unknown parameter\n");
1371 }
1372 
1373 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1374 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1375 							keyword, "port");
1376 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1377 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1378 						name, "start#stop#close#reset");
1379 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1380 	TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1381 							value, UINT8);
1382 
1383 cmdline_parse_inst_t cmd_operate_specific_port = {
1384 	.f = cmd_operate_specific_port_parsed,
1385 	.data = NULL,
1386 	.help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1387 	.tokens = {
1388 		(void *)&cmd_operate_specific_port_cmd,
1389 		(void *)&cmd_operate_specific_port_port,
1390 		(void *)&cmd_operate_specific_port_id,
1391 		NULL,
1392 	},
1393 };
1394 
1395 /* *** enable port setup (after attach) via iterator or event *** */
1396 struct cmd_set_port_setup_on_result {
1397 	cmdline_fixed_string_t set;
1398 	cmdline_fixed_string_t port;
1399 	cmdline_fixed_string_t setup;
1400 	cmdline_fixed_string_t on;
1401 	cmdline_fixed_string_t mode;
1402 };
1403 
1404 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1405 				__rte_unused struct cmdline *cl,
1406 				__rte_unused void *data)
1407 {
1408 	struct cmd_set_port_setup_on_result *res = parsed_result;
1409 
1410 	if (strcmp(res->mode, "event") == 0)
1411 		setup_on_probe_event = true;
1412 	else if (strcmp(res->mode, "iterator") == 0)
1413 		setup_on_probe_event = false;
1414 	else
1415 		printf("Unknown mode\n");
1416 }
1417 
1418 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1419 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1420 			set, "set");
1421 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1422 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1423 			port, "port");
1424 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1425 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1426 			setup, "setup");
1427 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1428 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1429 			on, "on");
1430 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1431 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1432 			mode, "iterator#event");
1433 
1434 cmdline_parse_inst_t cmd_set_port_setup_on = {
1435 	.f = cmd_set_port_setup_on_parsed,
1436 	.data = NULL,
1437 	.help_str = "set port setup on iterator|event",
1438 	.tokens = {
1439 		(void *)&cmd_set_port_setup_on_set,
1440 		(void *)&cmd_set_port_setup_on_port,
1441 		(void *)&cmd_set_port_setup_on_setup,
1442 		(void *)&cmd_set_port_setup_on_on,
1443 		(void *)&cmd_set_port_setup_on_mode,
1444 		NULL,
1445 	},
1446 };
1447 
1448 /* *** attach a specified port *** */
1449 struct cmd_operate_attach_port_result {
1450 	cmdline_fixed_string_t port;
1451 	cmdline_fixed_string_t keyword;
1452 	cmdline_multi_string_t identifier;
1453 };
1454 
1455 static void cmd_operate_attach_port_parsed(void *parsed_result,
1456 				__rte_unused struct cmdline *cl,
1457 				__rte_unused void *data)
1458 {
1459 	struct cmd_operate_attach_port_result *res = parsed_result;
1460 
1461 	if (!strcmp(res->keyword, "attach"))
1462 		attach_port(res->identifier);
1463 	else
1464 		printf("Unknown parameter\n");
1465 }
1466 
1467 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1468 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1469 			port, "port");
1470 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1471 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1472 			keyword, "attach");
1473 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1474 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1475 			identifier, TOKEN_STRING_MULTI);
1476 
1477 cmdline_parse_inst_t cmd_operate_attach_port = {
1478 	.f = cmd_operate_attach_port_parsed,
1479 	.data = NULL,
1480 	.help_str = "port attach <identifier>: "
1481 		"(identifier: pci address or virtual dev name)",
1482 	.tokens = {
1483 		(void *)&cmd_operate_attach_port_port,
1484 		(void *)&cmd_operate_attach_port_keyword,
1485 		(void *)&cmd_operate_attach_port_identifier,
1486 		NULL,
1487 	},
1488 };
1489 
1490 /* *** detach a specified port *** */
1491 struct cmd_operate_detach_port_result {
1492 	cmdline_fixed_string_t port;
1493 	cmdline_fixed_string_t keyword;
1494 	portid_t port_id;
1495 };
1496 
1497 static void cmd_operate_detach_port_parsed(void *parsed_result,
1498 				__rte_unused struct cmdline *cl,
1499 				__rte_unused void *data)
1500 {
1501 	struct cmd_operate_detach_port_result *res = parsed_result;
1502 
1503 	if (!strcmp(res->keyword, "detach")) {
1504 		RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1505 		detach_port_device(res->port_id);
1506 	} else {
1507 		printf("Unknown parameter\n");
1508 	}
1509 }
1510 
1511 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1512 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1513 			port, "port");
1514 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1515 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1516 			keyword, "detach");
1517 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1518 	TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1519 			port_id, UINT16);
1520 
1521 cmdline_parse_inst_t cmd_operate_detach_port = {
1522 	.f = cmd_operate_detach_port_parsed,
1523 	.data = NULL,
1524 	.help_str = "port detach <port_id>",
1525 	.tokens = {
1526 		(void *)&cmd_operate_detach_port_port,
1527 		(void *)&cmd_operate_detach_port_keyword,
1528 		(void *)&cmd_operate_detach_port_port_id,
1529 		NULL,
1530 	},
1531 };
1532 
1533 /* *** detach device by identifier *** */
1534 struct cmd_operate_detach_device_result {
1535 	cmdline_fixed_string_t device;
1536 	cmdline_fixed_string_t keyword;
1537 	cmdline_fixed_string_t identifier;
1538 };
1539 
1540 static void cmd_operate_detach_device_parsed(void *parsed_result,
1541 				__rte_unused struct cmdline *cl,
1542 				__rte_unused void *data)
1543 {
1544 	struct cmd_operate_detach_device_result *res = parsed_result;
1545 
1546 	if (!strcmp(res->keyword, "detach"))
1547 		detach_devargs(res->identifier);
1548 	else
1549 		printf("Unknown parameter\n");
1550 }
1551 
1552 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1553 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1554 			device, "device");
1555 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1556 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1557 			keyword, "detach");
1558 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1559 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1560 			identifier, NULL);
1561 
1562 cmdline_parse_inst_t cmd_operate_detach_device = {
1563 	.f = cmd_operate_detach_device_parsed,
1564 	.data = NULL,
1565 	.help_str = "device detach <identifier>:"
1566 		"(identifier: pci address or virtual dev name)",
1567 	.tokens = {
1568 		(void *)&cmd_operate_detach_device_device,
1569 		(void *)&cmd_operate_detach_device_keyword,
1570 		(void *)&cmd_operate_detach_device_identifier,
1571 		NULL,
1572 	},
1573 };
1574 /* *** configure speed for all ports *** */
1575 struct cmd_config_speed_all {
1576 	cmdline_fixed_string_t port;
1577 	cmdline_fixed_string_t keyword;
1578 	cmdline_fixed_string_t all;
1579 	cmdline_fixed_string_t item1;
1580 	cmdline_fixed_string_t item2;
1581 	cmdline_fixed_string_t value1;
1582 	cmdline_fixed_string_t value2;
1583 };
1584 
1585 static int
1586 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1587 {
1588 
1589 	int duplex;
1590 
1591 	if (!strcmp(duplexstr, "half")) {
1592 		duplex = ETH_LINK_HALF_DUPLEX;
1593 	} else if (!strcmp(duplexstr, "full")) {
1594 		duplex = ETH_LINK_FULL_DUPLEX;
1595 	} else if (!strcmp(duplexstr, "auto")) {
1596 		duplex = ETH_LINK_FULL_DUPLEX;
1597 	} else {
1598 		printf("Unknown duplex parameter\n");
1599 		return -1;
1600 	}
1601 
1602 	if (!strcmp(speedstr, "10")) {
1603 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1604 				ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1605 	} else if (!strcmp(speedstr, "100")) {
1606 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1607 				ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1608 	} else {
1609 		if (duplex != ETH_LINK_FULL_DUPLEX) {
1610 			printf("Invalid speed/duplex parameters\n");
1611 			return -1;
1612 		}
1613 		if (!strcmp(speedstr, "1000")) {
1614 			*speed = ETH_LINK_SPEED_1G;
1615 		} else if (!strcmp(speedstr, "10000")) {
1616 			*speed = ETH_LINK_SPEED_10G;
1617 		} else if (!strcmp(speedstr, "25000")) {
1618 			*speed = ETH_LINK_SPEED_25G;
1619 		} else if (!strcmp(speedstr, "40000")) {
1620 			*speed = ETH_LINK_SPEED_40G;
1621 		} else if (!strcmp(speedstr, "50000")) {
1622 			*speed = ETH_LINK_SPEED_50G;
1623 		} else if (!strcmp(speedstr, "100000")) {
1624 			*speed = ETH_LINK_SPEED_100G;
1625 		} else if (!strcmp(speedstr, "200000")) {
1626 			*speed = ETH_LINK_SPEED_200G;
1627 		} else if (!strcmp(speedstr, "auto")) {
1628 			*speed = ETH_LINK_SPEED_AUTONEG;
1629 		} else {
1630 			printf("Unknown speed parameter\n");
1631 			return -1;
1632 		}
1633 	}
1634 
1635 	return 0;
1636 }
1637 
1638 static void
1639 cmd_config_speed_all_parsed(void *parsed_result,
1640 			__rte_unused struct cmdline *cl,
1641 			__rte_unused void *data)
1642 {
1643 	struct cmd_config_speed_all *res = parsed_result;
1644 	uint32_t link_speed;
1645 	portid_t pid;
1646 
1647 	if (!all_ports_stopped()) {
1648 		printf("Please stop all ports first\n");
1649 		return;
1650 	}
1651 
1652 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1653 			&link_speed) < 0)
1654 		return;
1655 
1656 	RTE_ETH_FOREACH_DEV(pid) {
1657 		ports[pid].dev_conf.link_speeds = link_speed;
1658 	}
1659 
1660 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1661 }
1662 
1663 cmdline_parse_token_string_t cmd_config_speed_all_port =
1664 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1665 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1666 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1667 							"config");
1668 cmdline_parse_token_string_t cmd_config_speed_all_all =
1669 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1670 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1671 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1672 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1673 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1674 				"10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1675 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1676 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1677 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1678 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1679 						"half#full#auto");
1680 
1681 cmdline_parse_inst_t cmd_config_speed_all = {
1682 	.f = cmd_config_speed_all_parsed,
1683 	.data = NULL,
1684 	.help_str = "port config all speed "
1685 		"10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1686 							"half|full|auto",
1687 	.tokens = {
1688 		(void *)&cmd_config_speed_all_port,
1689 		(void *)&cmd_config_speed_all_keyword,
1690 		(void *)&cmd_config_speed_all_all,
1691 		(void *)&cmd_config_speed_all_item1,
1692 		(void *)&cmd_config_speed_all_value1,
1693 		(void *)&cmd_config_speed_all_item2,
1694 		(void *)&cmd_config_speed_all_value2,
1695 		NULL,
1696 	},
1697 };
1698 
1699 /* *** configure speed for specific port *** */
1700 struct cmd_config_speed_specific {
1701 	cmdline_fixed_string_t port;
1702 	cmdline_fixed_string_t keyword;
1703 	portid_t id;
1704 	cmdline_fixed_string_t item1;
1705 	cmdline_fixed_string_t item2;
1706 	cmdline_fixed_string_t value1;
1707 	cmdline_fixed_string_t value2;
1708 };
1709 
1710 static void
1711 cmd_config_speed_specific_parsed(void *parsed_result,
1712 				__rte_unused struct cmdline *cl,
1713 				__rte_unused void *data)
1714 {
1715 	struct cmd_config_speed_specific *res = parsed_result;
1716 	uint32_t link_speed;
1717 
1718 	if (!all_ports_stopped()) {
1719 		printf("Please stop all ports first\n");
1720 		return;
1721 	}
1722 
1723 	if (port_id_is_invalid(res->id, ENABLED_WARN))
1724 		return;
1725 
1726 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1727 			&link_speed) < 0)
1728 		return;
1729 
1730 	ports[res->id].dev_conf.link_speeds = link_speed;
1731 
1732 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1733 }
1734 
1735 
1736 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1737 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1738 								"port");
1739 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1740 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1741 								"config");
1742 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1743 	TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1744 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1745 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1746 								"speed");
1747 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1748 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1749 				"10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1750 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1751 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1752 								"duplex");
1753 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1754 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1755 							"half#full#auto");
1756 
1757 cmdline_parse_inst_t cmd_config_speed_specific = {
1758 	.f = cmd_config_speed_specific_parsed,
1759 	.data = NULL,
1760 	.help_str = "port config <port_id> speed "
1761 		"10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1762 							"half|full|auto",
1763 	.tokens = {
1764 		(void *)&cmd_config_speed_specific_port,
1765 		(void *)&cmd_config_speed_specific_keyword,
1766 		(void *)&cmd_config_speed_specific_id,
1767 		(void *)&cmd_config_speed_specific_item1,
1768 		(void *)&cmd_config_speed_specific_value1,
1769 		(void *)&cmd_config_speed_specific_item2,
1770 		(void *)&cmd_config_speed_specific_value2,
1771 		NULL,
1772 	},
1773 };
1774 
1775 /* *** configure loopback for all ports *** */
1776 struct cmd_config_loopback_all {
1777 	cmdline_fixed_string_t port;
1778 	cmdline_fixed_string_t keyword;
1779 	cmdline_fixed_string_t all;
1780 	cmdline_fixed_string_t item;
1781 	uint32_t mode;
1782 };
1783 
1784 static void
1785 cmd_config_loopback_all_parsed(void *parsed_result,
1786 			__rte_unused struct cmdline *cl,
1787 			__rte_unused void *data)
1788 {
1789 	struct cmd_config_loopback_all *res = parsed_result;
1790 	portid_t pid;
1791 
1792 	if (!all_ports_stopped()) {
1793 		printf("Please stop all ports first\n");
1794 		return;
1795 	}
1796 
1797 	RTE_ETH_FOREACH_DEV(pid) {
1798 		ports[pid].dev_conf.lpbk_mode = res->mode;
1799 	}
1800 
1801 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1802 }
1803 
1804 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1805 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1806 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1807 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1808 							"config");
1809 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1810 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1811 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1812 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1813 							"loopback");
1814 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1815 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1816 
1817 cmdline_parse_inst_t cmd_config_loopback_all = {
1818 	.f = cmd_config_loopback_all_parsed,
1819 	.data = NULL,
1820 	.help_str = "port config all loopback <mode>",
1821 	.tokens = {
1822 		(void *)&cmd_config_loopback_all_port,
1823 		(void *)&cmd_config_loopback_all_keyword,
1824 		(void *)&cmd_config_loopback_all_all,
1825 		(void *)&cmd_config_loopback_all_item,
1826 		(void *)&cmd_config_loopback_all_mode,
1827 		NULL,
1828 	},
1829 };
1830 
1831 /* *** configure loopback for specific port *** */
1832 struct cmd_config_loopback_specific {
1833 	cmdline_fixed_string_t port;
1834 	cmdline_fixed_string_t keyword;
1835 	uint16_t port_id;
1836 	cmdline_fixed_string_t item;
1837 	uint32_t mode;
1838 };
1839 
1840 static void
1841 cmd_config_loopback_specific_parsed(void *parsed_result,
1842 				__rte_unused struct cmdline *cl,
1843 				__rte_unused void *data)
1844 {
1845 	struct cmd_config_loopback_specific *res = parsed_result;
1846 
1847 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1848 		return;
1849 
1850 	if (!port_is_stopped(res->port_id)) {
1851 		printf("Please stop port %u first\n", res->port_id);
1852 		return;
1853 	}
1854 
1855 	ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1856 
1857 	cmd_reconfig_device_queue(res->port_id, 1, 1);
1858 }
1859 
1860 
1861 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1862 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1863 								"port");
1864 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1865 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1866 								"config");
1867 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1868 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1869 								UINT16);
1870 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1871 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1872 								"loopback");
1873 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1874 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1875 			      UINT32);
1876 
1877 cmdline_parse_inst_t cmd_config_loopback_specific = {
1878 	.f = cmd_config_loopback_specific_parsed,
1879 	.data = NULL,
1880 	.help_str = "port config <port_id> loopback <mode>",
1881 	.tokens = {
1882 		(void *)&cmd_config_loopback_specific_port,
1883 		(void *)&cmd_config_loopback_specific_keyword,
1884 		(void *)&cmd_config_loopback_specific_id,
1885 		(void *)&cmd_config_loopback_specific_item,
1886 		(void *)&cmd_config_loopback_specific_mode,
1887 		NULL,
1888 	},
1889 };
1890 
1891 /* *** configure txq/rxq, txd/rxd *** */
1892 struct cmd_config_rx_tx {
1893 	cmdline_fixed_string_t port;
1894 	cmdline_fixed_string_t keyword;
1895 	cmdline_fixed_string_t all;
1896 	cmdline_fixed_string_t name;
1897 	uint16_t value;
1898 };
1899 
1900 static void
1901 cmd_config_rx_tx_parsed(void *parsed_result,
1902 			__rte_unused struct cmdline *cl,
1903 			__rte_unused void *data)
1904 {
1905 	struct cmd_config_rx_tx *res = parsed_result;
1906 
1907 	if (!all_ports_stopped()) {
1908 		printf("Please stop all ports first\n");
1909 		return;
1910 	}
1911 	if (!strcmp(res->name, "rxq")) {
1912 		if (!res->value && !nb_txq) {
1913 			printf("Warning: Either rx or tx queues should be non zero\n");
1914 			return;
1915 		}
1916 		if (check_nb_rxq(res->value) != 0)
1917 			return;
1918 		nb_rxq = res->value;
1919 	}
1920 	else if (!strcmp(res->name, "txq")) {
1921 		if (!res->value && !nb_rxq) {
1922 			printf("Warning: Either rx or tx queues should be non zero\n");
1923 			return;
1924 		}
1925 		if (check_nb_txq(res->value) != 0)
1926 			return;
1927 		nb_txq = res->value;
1928 	}
1929 	else if (!strcmp(res->name, "rxd")) {
1930 		if (check_nb_rxd(res->value) != 0)
1931 			return;
1932 		nb_rxd = res->value;
1933 	} else if (!strcmp(res->name, "txd")) {
1934 		if (check_nb_txd(res->value) != 0)
1935 			return;
1936 
1937 		nb_txd = res->value;
1938 	} else {
1939 		printf("Unknown parameter\n");
1940 		return;
1941 	}
1942 
1943 	fwd_config_setup();
1944 
1945 	init_port_config();
1946 
1947 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1948 }
1949 
1950 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1951 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1952 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1953 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1954 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1955 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1956 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1957 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1958 						"rxq#txq#rxd#txd");
1959 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1960 	TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1961 
1962 cmdline_parse_inst_t cmd_config_rx_tx = {
1963 	.f = cmd_config_rx_tx_parsed,
1964 	.data = NULL,
1965 	.help_str = "port config all rxq|txq|rxd|txd <value>",
1966 	.tokens = {
1967 		(void *)&cmd_config_rx_tx_port,
1968 		(void *)&cmd_config_rx_tx_keyword,
1969 		(void *)&cmd_config_rx_tx_all,
1970 		(void *)&cmd_config_rx_tx_name,
1971 		(void *)&cmd_config_rx_tx_value,
1972 		NULL,
1973 	},
1974 };
1975 
1976 /* *** config max packet length *** */
1977 struct cmd_config_max_pkt_len_result {
1978 	cmdline_fixed_string_t port;
1979 	cmdline_fixed_string_t keyword;
1980 	cmdline_fixed_string_t all;
1981 	cmdline_fixed_string_t name;
1982 	uint32_t value;
1983 };
1984 
1985 static void
1986 cmd_config_max_pkt_len_parsed(void *parsed_result,
1987 				__rte_unused struct cmdline *cl,
1988 				__rte_unused void *data)
1989 {
1990 	struct cmd_config_max_pkt_len_result *res = parsed_result;
1991 	portid_t pid;
1992 
1993 	if (!all_ports_stopped()) {
1994 		printf("Please stop all ports first\n");
1995 		return;
1996 	}
1997 
1998 	RTE_ETH_FOREACH_DEV(pid) {
1999 		struct rte_port *port = &ports[pid];
2000 		uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2001 
2002 		if (!strcmp(res->name, "max-pkt-len")) {
2003 			if (res->value < RTE_ETHER_MIN_LEN) {
2004 				printf("max-pkt-len can not be less than %d\n",
2005 						RTE_ETHER_MIN_LEN);
2006 				return;
2007 			}
2008 			if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2009 				return;
2010 
2011 			port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2012 			if (res->value > RTE_ETHER_MAX_LEN)
2013 				rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2014 			else
2015 				rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2016 			port->dev_conf.rxmode.offloads = rx_offloads;
2017 		} else {
2018 			printf("Unknown parameter\n");
2019 			return;
2020 		}
2021 	}
2022 
2023 	init_port_config();
2024 
2025 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2026 }
2027 
2028 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2029 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2030 								"port");
2031 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2032 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2033 								"config");
2034 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2035 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2036 								"all");
2037 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2038 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2039 								"max-pkt-len");
2040 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2041 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2042 								UINT32);
2043 
2044 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2045 	.f = cmd_config_max_pkt_len_parsed,
2046 	.data = NULL,
2047 	.help_str = "port config all max-pkt-len <value>",
2048 	.tokens = {
2049 		(void *)&cmd_config_max_pkt_len_port,
2050 		(void *)&cmd_config_max_pkt_len_keyword,
2051 		(void *)&cmd_config_max_pkt_len_all,
2052 		(void *)&cmd_config_max_pkt_len_name,
2053 		(void *)&cmd_config_max_pkt_len_value,
2054 		NULL,
2055 	},
2056 };
2057 
2058 /* *** config max LRO aggregated packet size *** */
2059 struct cmd_config_max_lro_pkt_size_result {
2060 	cmdline_fixed_string_t port;
2061 	cmdline_fixed_string_t keyword;
2062 	cmdline_fixed_string_t all;
2063 	cmdline_fixed_string_t name;
2064 	uint32_t value;
2065 };
2066 
2067 static void
2068 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2069 				__rte_unused struct cmdline *cl,
2070 				__rte_unused void *data)
2071 {
2072 	struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2073 	portid_t pid;
2074 
2075 	if (!all_ports_stopped()) {
2076 		printf("Please stop all ports first\n");
2077 		return;
2078 	}
2079 
2080 	RTE_ETH_FOREACH_DEV(pid) {
2081 		struct rte_port *port = &ports[pid];
2082 
2083 		if (!strcmp(res->name, "max-lro-pkt-size")) {
2084 			if (res->value ==
2085 					port->dev_conf.rxmode.max_lro_pkt_size)
2086 				return;
2087 
2088 			port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2089 		} else {
2090 			printf("Unknown parameter\n");
2091 			return;
2092 		}
2093 	}
2094 
2095 	init_port_config();
2096 
2097 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2098 }
2099 
2100 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2101 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2102 				 port, "port");
2103 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2104 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2105 				 keyword, "config");
2106 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2107 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2108 				 all, "all");
2109 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2110 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2111 				 name, "max-lro-pkt-size");
2112 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2113 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2114 			      value, UINT32);
2115 
2116 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2117 	.f = cmd_config_max_lro_pkt_size_parsed,
2118 	.data = NULL,
2119 	.help_str = "port config all max-lro-pkt-size <value>",
2120 	.tokens = {
2121 		(void *)&cmd_config_max_lro_pkt_size_port,
2122 		(void *)&cmd_config_max_lro_pkt_size_keyword,
2123 		(void *)&cmd_config_max_lro_pkt_size_all,
2124 		(void *)&cmd_config_max_lro_pkt_size_name,
2125 		(void *)&cmd_config_max_lro_pkt_size_value,
2126 		NULL,
2127 	},
2128 };
2129 
2130 /* *** configure port MTU *** */
2131 struct cmd_config_mtu_result {
2132 	cmdline_fixed_string_t port;
2133 	cmdline_fixed_string_t keyword;
2134 	cmdline_fixed_string_t mtu;
2135 	portid_t port_id;
2136 	uint16_t value;
2137 };
2138 
2139 static void
2140 cmd_config_mtu_parsed(void *parsed_result,
2141 		      __rte_unused struct cmdline *cl,
2142 		      __rte_unused void *data)
2143 {
2144 	struct cmd_config_mtu_result *res = parsed_result;
2145 
2146 	if (res->value < RTE_ETHER_MIN_LEN) {
2147 		printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2148 		return;
2149 	}
2150 	port_mtu_set(res->port_id, res->value);
2151 }
2152 
2153 cmdline_parse_token_string_t cmd_config_mtu_port =
2154 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2155 				 "port");
2156 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2157 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2158 				 "config");
2159 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2160 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2161 				 "mtu");
2162 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2163 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2164 cmdline_parse_token_num_t cmd_config_mtu_value =
2165 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2166 
2167 cmdline_parse_inst_t cmd_config_mtu = {
2168 	.f = cmd_config_mtu_parsed,
2169 	.data = NULL,
2170 	.help_str = "port config mtu <port_id> <value>",
2171 	.tokens = {
2172 		(void *)&cmd_config_mtu_port,
2173 		(void *)&cmd_config_mtu_keyword,
2174 		(void *)&cmd_config_mtu_mtu,
2175 		(void *)&cmd_config_mtu_port_id,
2176 		(void *)&cmd_config_mtu_value,
2177 		NULL,
2178 	},
2179 };
2180 
2181 /* *** configure rx mode *** */
2182 struct cmd_config_rx_mode_flag {
2183 	cmdline_fixed_string_t port;
2184 	cmdline_fixed_string_t keyword;
2185 	cmdline_fixed_string_t all;
2186 	cmdline_fixed_string_t name;
2187 	cmdline_fixed_string_t value;
2188 };
2189 
2190 static void
2191 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2192 				__rte_unused struct cmdline *cl,
2193 				__rte_unused void *data)
2194 {
2195 	struct cmd_config_rx_mode_flag *res = parsed_result;
2196 
2197 	if (!all_ports_stopped()) {
2198 		printf("Please stop all ports first\n");
2199 		return;
2200 	}
2201 
2202 	if (!strcmp(res->name, "drop-en")) {
2203 		if (!strcmp(res->value, "on"))
2204 			rx_drop_en = 1;
2205 		else if (!strcmp(res->value, "off"))
2206 			rx_drop_en = 0;
2207 		else {
2208 			printf("Unknown parameter\n");
2209 			return;
2210 		}
2211 	} else {
2212 		printf("Unknown parameter\n");
2213 		return;
2214 	}
2215 
2216 	init_port_config();
2217 
2218 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2219 }
2220 
2221 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2222 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2223 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2224 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2225 								"config");
2226 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2227 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2228 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2229 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2230 					"drop-en");
2231 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2232 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2233 							"on#off");
2234 
2235 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2236 	.f = cmd_config_rx_mode_flag_parsed,
2237 	.data = NULL,
2238 	.help_str = "port config all drop-en on|off",
2239 	.tokens = {
2240 		(void *)&cmd_config_rx_mode_flag_port,
2241 		(void *)&cmd_config_rx_mode_flag_keyword,
2242 		(void *)&cmd_config_rx_mode_flag_all,
2243 		(void *)&cmd_config_rx_mode_flag_name,
2244 		(void *)&cmd_config_rx_mode_flag_value,
2245 		NULL,
2246 	},
2247 };
2248 
2249 /* *** configure rss *** */
2250 struct cmd_config_rss {
2251 	cmdline_fixed_string_t port;
2252 	cmdline_fixed_string_t keyword;
2253 	cmdline_fixed_string_t all;
2254 	cmdline_fixed_string_t name;
2255 	cmdline_fixed_string_t value;
2256 };
2257 
2258 static void
2259 cmd_config_rss_parsed(void *parsed_result,
2260 			__rte_unused struct cmdline *cl,
2261 			__rte_unused void *data)
2262 {
2263 	struct cmd_config_rss *res = parsed_result;
2264 	struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2265 	struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2266 	int use_default = 0;
2267 	int all_updated = 1;
2268 	int diag;
2269 	uint16_t i;
2270 	int ret;
2271 
2272 	if (!strcmp(res->value, "all"))
2273 		rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2274 			ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2275 			ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2276 			ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2277 	else if (!strcmp(res->value, "eth"))
2278 		rss_conf.rss_hf = ETH_RSS_ETH;
2279 	else if (!strcmp(res->value, "vlan"))
2280 		rss_conf.rss_hf = ETH_RSS_VLAN;
2281 	else if (!strcmp(res->value, "ip"))
2282 		rss_conf.rss_hf = ETH_RSS_IP;
2283 	else if (!strcmp(res->value, "udp"))
2284 		rss_conf.rss_hf = ETH_RSS_UDP;
2285 	else if (!strcmp(res->value, "tcp"))
2286 		rss_conf.rss_hf = ETH_RSS_TCP;
2287 	else if (!strcmp(res->value, "sctp"))
2288 		rss_conf.rss_hf = ETH_RSS_SCTP;
2289 	else if (!strcmp(res->value, "ether"))
2290 		rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2291 	else if (!strcmp(res->value, "port"))
2292 		rss_conf.rss_hf = ETH_RSS_PORT;
2293 	else if (!strcmp(res->value, "vxlan"))
2294 		rss_conf.rss_hf = ETH_RSS_VXLAN;
2295 	else if (!strcmp(res->value, "geneve"))
2296 		rss_conf.rss_hf = ETH_RSS_GENEVE;
2297 	else if (!strcmp(res->value, "nvgre"))
2298 		rss_conf.rss_hf = ETH_RSS_NVGRE;
2299 	else if (!strcmp(res->value, "l3-pre32"))
2300 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2301 	else if (!strcmp(res->value, "l3-pre40"))
2302 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2303 	else if (!strcmp(res->value, "l3-pre48"))
2304 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2305 	else if (!strcmp(res->value, "l3-pre56"))
2306 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2307 	else if (!strcmp(res->value, "l3-pre64"))
2308 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2309 	else if (!strcmp(res->value, "l3-pre96"))
2310 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2311 	else if (!strcmp(res->value, "l3-src-only"))
2312 		rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2313 	else if (!strcmp(res->value, "l3-dst-only"))
2314 		rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2315 	else if (!strcmp(res->value, "l4-src-only"))
2316 		rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2317 	else if (!strcmp(res->value, "l4-dst-only"))
2318 		rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2319 	else if (!strcmp(res->value, "l2-src-only"))
2320 		rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2321 	else if (!strcmp(res->value, "l2-dst-only"))
2322 		rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2323 	else if (!strcmp(res->value, "l2tpv3"))
2324 		rss_conf.rss_hf = ETH_RSS_L2TPV3;
2325 	else if (!strcmp(res->value, "esp"))
2326 		rss_conf.rss_hf = ETH_RSS_ESP;
2327 	else if (!strcmp(res->value, "ah"))
2328 		rss_conf.rss_hf = ETH_RSS_AH;
2329 	else if (!strcmp(res->value, "pfcp"))
2330 		rss_conf.rss_hf = ETH_RSS_PFCP;
2331 	else if (!strcmp(res->value, "pppoe"))
2332 		rss_conf.rss_hf = ETH_RSS_PPPOE;
2333 	else if (!strcmp(res->value, "gtpu"))
2334 		rss_conf.rss_hf = ETH_RSS_GTPU;
2335 	else if (!strcmp(res->value, "none"))
2336 		rss_conf.rss_hf = 0;
2337 	else if (!strcmp(res->value, "default"))
2338 		use_default = 1;
2339 	else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2340 						atoi(res->value) < 64)
2341 		rss_conf.rss_hf = 1ULL << atoi(res->value);
2342 	else {
2343 		printf("Unknown parameter\n");
2344 		return;
2345 	}
2346 	rss_conf.rss_key = NULL;
2347 	/* Update global configuration for RSS types. */
2348 	RTE_ETH_FOREACH_DEV(i) {
2349 		struct rte_eth_rss_conf local_rss_conf;
2350 
2351 		ret = eth_dev_info_get_print_err(i, &dev_info);
2352 		if (ret != 0)
2353 			return;
2354 
2355 		if (use_default)
2356 			rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2357 
2358 		local_rss_conf = rss_conf;
2359 		local_rss_conf.rss_hf = rss_conf.rss_hf &
2360 			dev_info.flow_type_rss_offloads;
2361 		if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2362 			printf("Port %u modified RSS hash function based on hardware support,"
2363 				"requested:%#"PRIx64" configured:%#"PRIx64"\n",
2364 				i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2365 		}
2366 		diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2367 		if (diag < 0) {
2368 			all_updated = 0;
2369 			printf("Configuration of RSS hash at ethernet port %d "
2370 				"failed with error (%d): %s.\n",
2371 				i, -diag, strerror(-diag));
2372 		}
2373 	}
2374 	if (all_updated && !use_default) {
2375 		rss_hf = rss_conf.rss_hf;
2376 		printf("rss_hf %#"PRIx64"\n", rss_hf);
2377 	}
2378 }
2379 
2380 cmdline_parse_token_string_t cmd_config_rss_port =
2381 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2382 cmdline_parse_token_string_t cmd_config_rss_keyword =
2383 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2384 cmdline_parse_token_string_t cmd_config_rss_all =
2385 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2386 cmdline_parse_token_string_t cmd_config_rss_name =
2387 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2388 cmdline_parse_token_string_t cmd_config_rss_value =
2389 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2390 
2391 cmdline_parse_inst_t cmd_config_rss = {
2392 	.f = cmd_config_rss_parsed,
2393 	.data = NULL,
2394 	.help_str = "port config all rss "
2395 		"all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2396 		"nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|<flowtype_id>",
2397 	.tokens = {
2398 		(void *)&cmd_config_rss_port,
2399 		(void *)&cmd_config_rss_keyword,
2400 		(void *)&cmd_config_rss_all,
2401 		(void *)&cmd_config_rss_name,
2402 		(void *)&cmd_config_rss_value,
2403 		NULL,
2404 	},
2405 };
2406 
2407 /* *** configure rss hash key *** */
2408 struct cmd_config_rss_hash_key {
2409 	cmdline_fixed_string_t port;
2410 	cmdline_fixed_string_t config;
2411 	portid_t port_id;
2412 	cmdline_fixed_string_t rss_hash_key;
2413 	cmdline_fixed_string_t rss_type;
2414 	cmdline_fixed_string_t key;
2415 };
2416 
2417 static uint8_t
2418 hexa_digit_to_value(char hexa_digit)
2419 {
2420 	if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2421 		return (uint8_t) (hexa_digit - '0');
2422 	if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2423 		return (uint8_t) ((hexa_digit - 'a') + 10);
2424 	if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2425 		return (uint8_t) ((hexa_digit - 'A') + 10);
2426 	/* Invalid hexa digit */
2427 	return 0xFF;
2428 }
2429 
2430 static uint8_t
2431 parse_and_check_key_hexa_digit(char *key, int idx)
2432 {
2433 	uint8_t hexa_v;
2434 
2435 	hexa_v = hexa_digit_to_value(key[idx]);
2436 	if (hexa_v == 0xFF)
2437 		printf("invalid key: character %c at position %d is not a "
2438 		       "valid hexa digit\n", key[idx], idx);
2439 	return hexa_v;
2440 }
2441 
2442 static void
2443 cmd_config_rss_hash_key_parsed(void *parsed_result,
2444 			       __rte_unused struct cmdline *cl,
2445 			       __rte_unused void *data)
2446 {
2447 	struct cmd_config_rss_hash_key *res = parsed_result;
2448 	uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2449 	uint8_t xdgt0;
2450 	uint8_t xdgt1;
2451 	int i;
2452 	struct rte_eth_dev_info dev_info;
2453 	uint8_t hash_key_size;
2454 	uint32_t key_len;
2455 	int ret;
2456 
2457 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2458 	if (ret != 0)
2459 		return;
2460 
2461 	if (dev_info.hash_key_size > 0 &&
2462 			dev_info.hash_key_size <= sizeof(hash_key))
2463 		hash_key_size = dev_info.hash_key_size;
2464 	else {
2465 		printf("dev_info did not provide a valid hash key size\n");
2466 		return;
2467 	}
2468 	/* Check the length of the RSS hash key */
2469 	key_len = strlen(res->key);
2470 	if (key_len != (hash_key_size * 2)) {
2471 		printf("key length: %d invalid - key must be a string of %d"
2472 			   " hexa-decimal numbers\n",
2473 			   (int) key_len, hash_key_size * 2);
2474 		return;
2475 	}
2476 	/* Translate RSS hash key into binary representation */
2477 	for (i = 0; i < hash_key_size; i++) {
2478 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2479 		if (xdgt0 == 0xFF)
2480 			return;
2481 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2482 		if (xdgt1 == 0xFF)
2483 			return;
2484 		hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2485 	}
2486 	port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2487 			hash_key_size);
2488 }
2489 
2490 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2491 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2492 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2493 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2494 				 "config");
2495 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2496 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2497 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2498 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2499 				 rss_hash_key, "rss-hash-key");
2500 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2501 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2502 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2503 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2504 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2505 				 "ipv6-tcp-ex#ipv6-udp-ex#"
2506 				 "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2507 				 "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2508 				 "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2509 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2510 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2511 
2512 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2513 	.f = cmd_config_rss_hash_key_parsed,
2514 	.data = NULL,
2515 	.help_str = "port config <port_id> rss-hash-key "
2516 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2517 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2518 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2519 		"l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2520 		"l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2521 		"l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2522 		"<string of hex digits (variable length, NIC dependent)>",
2523 	.tokens = {
2524 		(void *)&cmd_config_rss_hash_key_port,
2525 		(void *)&cmd_config_rss_hash_key_config,
2526 		(void *)&cmd_config_rss_hash_key_port_id,
2527 		(void *)&cmd_config_rss_hash_key_rss_hash_key,
2528 		(void *)&cmd_config_rss_hash_key_rss_type,
2529 		(void *)&cmd_config_rss_hash_key_value,
2530 		NULL,
2531 	},
2532 };
2533 
2534 /* *** configure port rxq/txq ring size *** */
2535 struct cmd_config_rxtx_ring_size {
2536 	cmdline_fixed_string_t port;
2537 	cmdline_fixed_string_t config;
2538 	portid_t portid;
2539 	cmdline_fixed_string_t rxtxq;
2540 	uint16_t qid;
2541 	cmdline_fixed_string_t rsize;
2542 	uint16_t size;
2543 };
2544 
2545 static void
2546 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2547 				 __rte_unused struct cmdline *cl,
2548 				 __rte_unused void *data)
2549 {
2550 	struct cmd_config_rxtx_ring_size *res = parsed_result;
2551 	struct rte_port *port;
2552 	uint8_t isrx;
2553 
2554 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2555 		return;
2556 
2557 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2558 		printf("Invalid port id\n");
2559 		return;
2560 	}
2561 
2562 	port = &ports[res->portid];
2563 
2564 	if (!strcmp(res->rxtxq, "rxq"))
2565 		isrx = 1;
2566 	else if (!strcmp(res->rxtxq, "txq"))
2567 		isrx = 0;
2568 	else {
2569 		printf("Unknown parameter\n");
2570 		return;
2571 	}
2572 
2573 	if (isrx && rx_queue_id_is_invalid(res->qid))
2574 		return;
2575 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2576 		return;
2577 
2578 	if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2579 		printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2580 		       rx_free_thresh);
2581 		return;
2582 	}
2583 
2584 	if (isrx)
2585 		port->nb_rx_desc[res->qid] = res->size;
2586 	else
2587 		port->nb_tx_desc[res->qid] = res->size;
2588 
2589 	cmd_reconfig_device_queue(res->portid, 0, 1);
2590 }
2591 
2592 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2593 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2594 				 port, "port");
2595 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2596 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2597 				 config, "config");
2598 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2599 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2600 				 portid, UINT16);
2601 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2602 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2603 				 rxtxq, "rxq#txq");
2604 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2605 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2606 			      qid, UINT16);
2607 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2608 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2609 				 rsize, "ring_size");
2610 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2611 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2612 			      size, UINT16);
2613 
2614 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2615 	.f = cmd_config_rxtx_ring_size_parsed,
2616 	.data = NULL,
2617 	.help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2618 	.tokens = {
2619 		(void *)&cmd_config_rxtx_ring_size_port,
2620 		(void *)&cmd_config_rxtx_ring_size_config,
2621 		(void *)&cmd_config_rxtx_ring_size_portid,
2622 		(void *)&cmd_config_rxtx_ring_size_rxtxq,
2623 		(void *)&cmd_config_rxtx_ring_size_qid,
2624 		(void *)&cmd_config_rxtx_ring_size_rsize,
2625 		(void *)&cmd_config_rxtx_ring_size_size,
2626 		NULL,
2627 	},
2628 };
2629 
2630 /* *** configure port rxq/txq start/stop *** */
2631 struct cmd_config_rxtx_queue {
2632 	cmdline_fixed_string_t port;
2633 	portid_t portid;
2634 	cmdline_fixed_string_t rxtxq;
2635 	uint16_t qid;
2636 	cmdline_fixed_string_t opname;
2637 };
2638 
2639 static void
2640 cmd_config_rxtx_queue_parsed(void *parsed_result,
2641 			__rte_unused struct cmdline *cl,
2642 			__rte_unused void *data)
2643 {
2644 	struct cmd_config_rxtx_queue *res = parsed_result;
2645 	uint8_t isrx;
2646 	uint8_t isstart;
2647 	int ret = 0;
2648 
2649 	if (test_done == 0) {
2650 		printf("Please stop forwarding first\n");
2651 		return;
2652 	}
2653 
2654 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2655 		return;
2656 
2657 	if (port_is_started(res->portid) != 1) {
2658 		printf("Please start port %u first\n", res->portid);
2659 		return;
2660 	}
2661 
2662 	if (!strcmp(res->rxtxq, "rxq"))
2663 		isrx = 1;
2664 	else if (!strcmp(res->rxtxq, "txq"))
2665 		isrx = 0;
2666 	else {
2667 		printf("Unknown parameter\n");
2668 		return;
2669 	}
2670 
2671 	if (isrx && rx_queue_id_is_invalid(res->qid))
2672 		return;
2673 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2674 		return;
2675 
2676 	if (!strcmp(res->opname, "start"))
2677 		isstart = 1;
2678 	else if (!strcmp(res->opname, "stop"))
2679 		isstart = 0;
2680 	else {
2681 		printf("Unknown parameter\n");
2682 		return;
2683 	}
2684 
2685 	if (isstart && isrx)
2686 		ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2687 	else if (!isstart && isrx)
2688 		ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2689 	else if (isstart && !isrx)
2690 		ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2691 	else
2692 		ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2693 
2694 	if (ret == -ENOTSUP)
2695 		printf("Function not supported in PMD driver\n");
2696 }
2697 
2698 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2699 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2700 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2701 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2702 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2703 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2704 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2705 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2706 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2707 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2708 						"start#stop");
2709 
2710 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2711 	.f = cmd_config_rxtx_queue_parsed,
2712 	.data = NULL,
2713 	.help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2714 	.tokens = {
2715 		(void *)&cmd_config_rxtx_queue_port,
2716 		(void *)&cmd_config_rxtx_queue_portid,
2717 		(void *)&cmd_config_rxtx_queue_rxtxq,
2718 		(void *)&cmd_config_rxtx_queue_qid,
2719 		(void *)&cmd_config_rxtx_queue_opname,
2720 		NULL,
2721 	},
2722 };
2723 
2724 /* *** configure port rxq/txq deferred start on/off *** */
2725 struct cmd_config_deferred_start_rxtx_queue {
2726 	cmdline_fixed_string_t port;
2727 	portid_t port_id;
2728 	cmdline_fixed_string_t rxtxq;
2729 	uint16_t qid;
2730 	cmdline_fixed_string_t opname;
2731 	cmdline_fixed_string_t state;
2732 };
2733 
2734 static void
2735 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2736 			__rte_unused struct cmdline *cl,
2737 			__rte_unused void *data)
2738 {
2739 	struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2740 	struct rte_port *port;
2741 	uint8_t isrx;
2742 	uint8_t ison;
2743 	uint8_t needreconfig = 0;
2744 
2745 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2746 		return;
2747 
2748 	if (port_is_started(res->port_id) != 0) {
2749 		printf("Please stop port %u first\n", res->port_id);
2750 		return;
2751 	}
2752 
2753 	port = &ports[res->port_id];
2754 
2755 	isrx = !strcmp(res->rxtxq, "rxq");
2756 
2757 	if (isrx && rx_queue_id_is_invalid(res->qid))
2758 		return;
2759 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2760 		return;
2761 
2762 	ison = !strcmp(res->state, "on");
2763 
2764 	if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2765 		port->rx_conf[res->qid].rx_deferred_start = ison;
2766 		needreconfig = 1;
2767 	} else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2768 		port->tx_conf[res->qid].tx_deferred_start = ison;
2769 		needreconfig = 1;
2770 	}
2771 
2772 	if (needreconfig)
2773 		cmd_reconfig_device_queue(res->port_id, 0, 1);
2774 }
2775 
2776 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2777 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2778 						port, "port");
2779 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2780 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2781 						port_id, UINT16);
2782 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2783 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2784 						rxtxq, "rxq#txq");
2785 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2786 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2787 						qid, UINT16);
2788 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2789 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2790 						opname, "deferred_start");
2791 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2792 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2793 						state, "on#off");
2794 
2795 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2796 	.f = cmd_config_deferred_start_rxtx_queue_parsed,
2797 	.data = NULL,
2798 	.help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2799 	.tokens = {
2800 		(void *)&cmd_config_deferred_start_rxtx_queue_port,
2801 		(void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2802 		(void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2803 		(void *)&cmd_config_deferred_start_rxtx_queue_qid,
2804 		(void *)&cmd_config_deferred_start_rxtx_queue_opname,
2805 		(void *)&cmd_config_deferred_start_rxtx_queue_state,
2806 		NULL,
2807 	},
2808 };
2809 
2810 /* *** configure port rxq/txq setup *** */
2811 struct cmd_setup_rxtx_queue {
2812 	cmdline_fixed_string_t port;
2813 	portid_t portid;
2814 	cmdline_fixed_string_t rxtxq;
2815 	uint16_t qid;
2816 	cmdline_fixed_string_t setup;
2817 };
2818 
2819 /* Common CLI fields for queue setup */
2820 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2821 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2822 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2823 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2824 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2825 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2826 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2827 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2828 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2829 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2830 
2831 static void
2832 cmd_setup_rxtx_queue_parsed(
2833 	void *parsed_result,
2834 	__rte_unused struct cmdline *cl,
2835 	__rte_unused void *data)
2836 {
2837 	struct cmd_setup_rxtx_queue *res = parsed_result;
2838 	struct rte_port *port;
2839 	struct rte_mempool *mp;
2840 	unsigned int socket_id;
2841 	uint8_t isrx = 0;
2842 	int ret;
2843 
2844 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2845 		return;
2846 
2847 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2848 		printf("Invalid port id\n");
2849 		return;
2850 	}
2851 
2852 	if (!strcmp(res->rxtxq, "rxq"))
2853 		isrx = 1;
2854 	else if (!strcmp(res->rxtxq, "txq"))
2855 		isrx = 0;
2856 	else {
2857 		printf("Unknown parameter\n");
2858 		return;
2859 	}
2860 
2861 	if (isrx && rx_queue_id_is_invalid(res->qid)) {
2862 		printf("Invalid rx queue\n");
2863 		return;
2864 	} else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2865 		printf("Invalid tx queue\n");
2866 		return;
2867 	}
2868 
2869 	port = &ports[res->portid];
2870 	if (isrx) {
2871 		socket_id = rxring_numa[res->portid];
2872 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2873 			socket_id = port->socket_id;
2874 
2875 		mp = mbuf_pool_find(socket_id);
2876 		if (mp == NULL) {
2877 			printf("Failed to setup RX queue: "
2878 				"No mempool allocation"
2879 				" on the socket %d\n",
2880 				rxring_numa[res->portid]);
2881 			return;
2882 		}
2883 		ret = rte_eth_rx_queue_setup(res->portid,
2884 					     res->qid,
2885 					     port->nb_rx_desc[res->qid],
2886 					     socket_id,
2887 					     &port->rx_conf[res->qid],
2888 					     mp);
2889 		if (ret)
2890 			printf("Failed to setup RX queue\n");
2891 	} else {
2892 		socket_id = txring_numa[res->portid];
2893 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2894 			socket_id = port->socket_id;
2895 
2896 		ret = rte_eth_tx_queue_setup(res->portid,
2897 					     res->qid,
2898 					     port->nb_tx_desc[res->qid],
2899 					     socket_id,
2900 					     &port->tx_conf[res->qid]);
2901 		if (ret)
2902 			printf("Failed to setup TX queue\n");
2903 	}
2904 }
2905 
2906 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2907 	.f = cmd_setup_rxtx_queue_parsed,
2908 	.data = NULL,
2909 	.help_str = "port <port_id> rxq|txq <queue_idx> setup",
2910 	.tokens = {
2911 		(void *)&cmd_setup_rxtx_queue_port,
2912 		(void *)&cmd_setup_rxtx_queue_portid,
2913 		(void *)&cmd_setup_rxtx_queue_rxtxq,
2914 		(void *)&cmd_setup_rxtx_queue_qid,
2915 		(void *)&cmd_setup_rxtx_queue_setup,
2916 		NULL,
2917 	},
2918 };
2919 
2920 
2921 /* *** Configure RSS RETA *** */
2922 struct cmd_config_rss_reta {
2923 	cmdline_fixed_string_t port;
2924 	cmdline_fixed_string_t keyword;
2925 	portid_t port_id;
2926 	cmdline_fixed_string_t name;
2927 	cmdline_fixed_string_t list_name;
2928 	cmdline_fixed_string_t list_of_items;
2929 };
2930 
2931 static int
2932 parse_reta_config(const char *str,
2933 		  struct rte_eth_rss_reta_entry64 *reta_conf,
2934 		  uint16_t nb_entries)
2935 {
2936 	int i;
2937 	unsigned size;
2938 	uint16_t hash_index, idx, shift;
2939 	uint16_t nb_queue;
2940 	char s[256];
2941 	const char *p, *p0 = str;
2942 	char *end;
2943 	enum fieldnames {
2944 		FLD_HASH_INDEX = 0,
2945 		FLD_QUEUE,
2946 		_NUM_FLD
2947 	};
2948 	unsigned long int_fld[_NUM_FLD];
2949 	char *str_fld[_NUM_FLD];
2950 
2951 	while ((p = strchr(p0,'(')) != NULL) {
2952 		++p;
2953 		if((p0 = strchr(p,')')) == NULL)
2954 			return -1;
2955 
2956 		size = p0 - p;
2957 		if(size >= sizeof(s))
2958 			return -1;
2959 
2960 		snprintf(s, sizeof(s), "%.*s", size, p);
2961 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2962 			return -1;
2963 		for (i = 0; i < _NUM_FLD; i++) {
2964 			errno = 0;
2965 			int_fld[i] = strtoul(str_fld[i], &end, 0);
2966 			if (errno != 0 || end == str_fld[i] ||
2967 					int_fld[i] > 65535)
2968 				return -1;
2969 		}
2970 
2971 		hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2972 		nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2973 
2974 		if (hash_index >= nb_entries) {
2975 			printf("Invalid RETA hash index=%d\n", hash_index);
2976 			return -1;
2977 		}
2978 
2979 		idx = hash_index / RTE_RETA_GROUP_SIZE;
2980 		shift = hash_index % RTE_RETA_GROUP_SIZE;
2981 		reta_conf[idx].mask |= (1ULL << shift);
2982 		reta_conf[idx].reta[shift] = nb_queue;
2983 	}
2984 
2985 	return 0;
2986 }
2987 
2988 static void
2989 cmd_set_rss_reta_parsed(void *parsed_result,
2990 			__rte_unused struct cmdline *cl,
2991 			__rte_unused void *data)
2992 {
2993 	int ret;
2994 	struct rte_eth_dev_info dev_info;
2995 	struct rte_eth_rss_reta_entry64 reta_conf[8];
2996 	struct cmd_config_rss_reta *res = parsed_result;
2997 
2998 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2999 	if (ret != 0)
3000 		return;
3001 
3002 	if (dev_info.reta_size == 0) {
3003 		printf("Redirection table size is 0 which is "
3004 					"invalid for RSS\n");
3005 		return;
3006 	} else
3007 		printf("The reta size of port %d is %u\n",
3008 			res->port_id, dev_info.reta_size);
3009 	if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3010 		printf("Currently do not support more than %u entries of "
3011 			"redirection table\n", ETH_RSS_RETA_SIZE_512);
3012 		return;
3013 	}
3014 
3015 	memset(reta_conf, 0, sizeof(reta_conf));
3016 	if (!strcmp(res->list_name, "reta")) {
3017 		if (parse_reta_config(res->list_of_items, reta_conf,
3018 						dev_info.reta_size)) {
3019 			printf("Invalid RSS Redirection Table "
3020 					"config entered\n");
3021 			return;
3022 		}
3023 		ret = rte_eth_dev_rss_reta_update(res->port_id,
3024 				reta_conf, dev_info.reta_size);
3025 		if (ret != 0)
3026 			printf("Bad redirection table parameter, "
3027 					"return code = %d \n", ret);
3028 	}
3029 }
3030 
3031 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3032 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3033 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3034 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3035 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3036 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3037 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3038 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3039 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3040 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3041 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3042         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3043                                  NULL);
3044 cmdline_parse_inst_t cmd_config_rss_reta = {
3045 	.f = cmd_set_rss_reta_parsed,
3046 	.data = NULL,
3047 	.help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3048 	.tokens = {
3049 		(void *)&cmd_config_rss_reta_port,
3050 		(void *)&cmd_config_rss_reta_keyword,
3051 		(void *)&cmd_config_rss_reta_port_id,
3052 		(void *)&cmd_config_rss_reta_name,
3053 		(void *)&cmd_config_rss_reta_list_name,
3054 		(void *)&cmd_config_rss_reta_list_of_items,
3055 		NULL,
3056 	},
3057 };
3058 
3059 /* *** SHOW PORT RETA INFO *** */
3060 struct cmd_showport_reta {
3061 	cmdline_fixed_string_t show;
3062 	cmdline_fixed_string_t port;
3063 	portid_t port_id;
3064 	cmdline_fixed_string_t rss;
3065 	cmdline_fixed_string_t reta;
3066 	uint16_t size;
3067 	cmdline_fixed_string_t list_of_items;
3068 };
3069 
3070 static int
3071 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3072 			   uint16_t nb_entries,
3073 			   char *str)
3074 {
3075 	uint32_t size;
3076 	const char *p, *p0 = str;
3077 	char s[256];
3078 	char *end;
3079 	char *str_fld[8];
3080 	uint16_t i;
3081 	uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3082 			RTE_RETA_GROUP_SIZE;
3083 	int ret;
3084 
3085 	p = strchr(p0, '(');
3086 	if (p == NULL)
3087 		return -1;
3088 	p++;
3089 	p0 = strchr(p, ')');
3090 	if (p0 == NULL)
3091 		return -1;
3092 	size = p0 - p;
3093 	if (size >= sizeof(s)) {
3094 		printf("The string size exceeds the internal buffer size\n");
3095 		return -1;
3096 	}
3097 	snprintf(s, sizeof(s), "%.*s", size, p);
3098 	ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3099 	if (ret <= 0 || ret != num) {
3100 		printf("The bits of masks do not match the number of "
3101 					"reta entries: %u\n", num);
3102 		return -1;
3103 	}
3104 	for (i = 0; i < ret; i++)
3105 		conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3106 
3107 	return 0;
3108 }
3109 
3110 static void
3111 cmd_showport_reta_parsed(void *parsed_result,
3112 			 __rte_unused struct cmdline *cl,
3113 			 __rte_unused void *data)
3114 {
3115 	struct cmd_showport_reta *res = parsed_result;
3116 	struct rte_eth_rss_reta_entry64 reta_conf[8];
3117 	struct rte_eth_dev_info dev_info;
3118 	uint16_t max_reta_size;
3119 	int ret;
3120 
3121 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3122 	if (ret != 0)
3123 		return;
3124 
3125 	max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3126 	if (res->size == 0 || res->size > max_reta_size) {
3127 		printf("Invalid redirection table size: %u (1-%u)\n",
3128 			res->size, max_reta_size);
3129 		return;
3130 	}
3131 
3132 	memset(reta_conf, 0, sizeof(reta_conf));
3133 	if (showport_parse_reta_config(reta_conf, res->size,
3134 				res->list_of_items) < 0) {
3135 		printf("Invalid string: %s for reta masks\n",
3136 					res->list_of_items);
3137 		return;
3138 	}
3139 	port_rss_reta_info(res->port_id, reta_conf, res->size);
3140 }
3141 
3142 cmdline_parse_token_string_t cmd_showport_reta_show =
3143 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3144 cmdline_parse_token_string_t cmd_showport_reta_port =
3145 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3146 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3147 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3148 cmdline_parse_token_string_t cmd_showport_reta_rss =
3149 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3150 cmdline_parse_token_string_t cmd_showport_reta_reta =
3151 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3152 cmdline_parse_token_num_t cmd_showport_reta_size =
3153 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3154 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3155 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3156 					list_of_items, NULL);
3157 
3158 cmdline_parse_inst_t cmd_showport_reta = {
3159 	.f = cmd_showport_reta_parsed,
3160 	.data = NULL,
3161 	.help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3162 	.tokens = {
3163 		(void *)&cmd_showport_reta_show,
3164 		(void *)&cmd_showport_reta_port,
3165 		(void *)&cmd_showport_reta_port_id,
3166 		(void *)&cmd_showport_reta_rss,
3167 		(void *)&cmd_showport_reta_reta,
3168 		(void *)&cmd_showport_reta_size,
3169 		(void *)&cmd_showport_reta_list_of_items,
3170 		NULL,
3171 	},
3172 };
3173 
3174 /* *** Show RSS hash configuration *** */
3175 struct cmd_showport_rss_hash {
3176 	cmdline_fixed_string_t show;
3177 	cmdline_fixed_string_t port;
3178 	portid_t port_id;
3179 	cmdline_fixed_string_t rss_hash;
3180 	cmdline_fixed_string_t rss_type;
3181 	cmdline_fixed_string_t key; /* optional argument */
3182 };
3183 
3184 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3185 				__rte_unused struct cmdline *cl,
3186 				void *show_rss_key)
3187 {
3188 	struct cmd_showport_rss_hash *res = parsed_result;
3189 
3190 	port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3191 }
3192 
3193 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3194 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3195 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3196 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3197 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3198 	TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3199 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3200 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3201 				 "rss-hash");
3202 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3203 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3204 
3205 cmdline_parse_inst_t cmd_showport_rss_hash = {
3206 	.f = cmd_showport_rss_hash_parsed,
3207 	.data = NULL,
3208 	.help_str = "show port <port_id> rss-hash",
3209 	.tokens = {
3210 		(void *)&cmd_showport_rss_hash_show,
3211 		(void *)&cmd_showport_rss_hash_port,
3212 		(void *)&cmd_showport_rss_hash_port_id,
3213 		(void *)&cmd_showport_rss_hash_rss_hash,
3214 		NULL,
3215 	},
3216 };
3217 
3218 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3219 	.f = cmd_showport_rss_hash_parsed,
3220 	.data = (void *)1,
3221 	.help_str = "show port <port_id> rss-hash key",
3222 	.tokens = {
3223 		(void *)&cmd_showport_rss_hash_show,
3224 		(void *)&cmd_showport_rss_hash_port,
3225 		(void *)&cmd_showport_rss_hash_port_id,
3226 		(void *)&cmd_showport_rss_hash_rss_hash,
3227 		(void *)&cmd_showport_rss_hash_rss_key,
3228 		NULL,
3229 	},
3230 };
3231 
3232 /* *** Configure DCB *** */
3233 struct cmd_config_dcb {
3234 	cmdline_fixed_string_t port;
3235 	cmdline_fixed_string_t config;
3236 	portid_t port_id;
3237 	cmdline_fixed_string_t dcb;
3238 	cmdline_fixed_string_t vt;
3239 	cmdline_fixed_string_t vt_en;
3240 	uint8_t num_tcs;
3241 	cmdline_fixed_string_t pfc;
3242 	cmdline_fixed_string_t pfc_en;
3243 };
3244 
3245 static void
3246 cmd_config_dcb_parsed(void *parsed_result,
3247                         __rte_unused struct cmdline *cl,
3248                         __rte_unused void *data)
3249 {
3250 	struct cmd_config_dcb *res = parsed_result;
3251 	portid_t port_id = res->port_id;
3252 	struct rte_port *port;
3253 	uint8_t pfc_en;
3254 	int ret;
3255 
3256 	port = &ports[port_id];
3257 	/** Check if the port is not started **/
3258 	if (port->port_status != RTE_PORT_STOPPED) {
3259 		printf("Please stop port %d first\n", port_id);
3260 		return;
3261 	}
3262 
3263 	if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3264 		printf("The invalid number of traffic class,"
3265 			" only 4 or 8 allowed.\n");
3266 		return;
3267 	}
3268 
3269 	if (nb_fwd_lcores < res->num_tcs) {
3270 		printf("nb_cores shouldn't be less than number of TCs.\n");
3271 		return;
3272 	}
3273 	if (!strncmp(res->pfc_en, "on", 2))
3274 		pfc_en = 1;
3275 	else
3276 		pfc_en = 0;
3277 
3278 	/* DCB in VT mode */
3279 	if (!strncmp(res->vt_en, "on", 2))
3280 		ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3281 				(enum rte_eth_nb_tcs)res->num_tcs,
3282 				pfc_en);
3283 	else
3284 		ret = init_port_dcb_config(port_id, DCB_ENABLED,
3285 				(enum rte_eth_nb_tcs)res->num_tcs,
3286 				pfc_en);
3287 
3288 
3289 	if (ret != 0) {
3290 		printf("Cannot initialize network ports.\n");
3291 		return;
3292 	}
3293 
3294 	cmd_reconfig_device_queue(port_id, 1, 1);
3295 }
3296 
3297 cmdline_parse_token_string_t cmd_config_dcb_port =
3298         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3299 cmdline_parse_token_string_t cmd_config_dcb_config =
3300         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3301 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3302 	TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3303 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3304         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3305 cmdline_parse_token_string_t cmd_config_dcb_vt =
3306         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3307 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3308         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3309 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3310         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3311 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3312         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3313 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3314         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3315 
3316 cmdline_parse_inst_t cmd_config_dcb = {
3317 	.f = cmd_config_dcb_parsed,
3318 	.data = NULL,
3319 	.help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3320 	.tokens = {
3321 		(void *)&cmd_config_dcb_port,
3322 		(void *)&cmd_config_dcb_config,
3323 		(void *)&cmd_config_dcb_port_id,
3324 		(void *)&cmd_config_dcb_dcb,
3325 		(void *)&cmd_config_dcb_vt,
3326 		(void *)&cmd_config_dcb_vt_en,
3327 		(void *)&cmd_config_dcb_num_tcs,
3328 		(void *)&cmd_config_dcb_pfc,
3329 		(void *)&cmd_config_dcb_pfc_en,
3330                 NULL,
3331         },
3332 };
3333 
3334 /* *** configure number of packets per burst *** */
3335 struct cmd_config_burst {
3336 	cmdline_fixed_string_t port;
3337 	cmdline_fixed_string_t keyword;
3338 	cmdline_fixed_string_t all;
3339 	cmdline_fixed_string_t name;
3340 	uint16_t value;
3341 };
3342 
3343 static void
3344 cmd_config_burst_parsed(void *parsed_result,
3345 			__rte_unused struct cmdline *cl,
3346 			__rte_unused void *data)
3347 {
3348 	struct cmd_config_burst *res = parsed_result;
3349 	struct rte_eth_dev_info dev_info;
3350 	uint16_t rec_nb_pkts;
3351 	int ret;
3352 
3353 	if (!all_ports_stopped()) {
3354 		printf("Please stop all ports first\n");
3355 		return;
3356 	}
3357 
3358 	if (!strcmp(res->name, "burst")) {
3359 		if (res->value == 0) {
3360 			/* If user gives a value of zero, query the PMD for
3361 			 * its recommended Rx burst size. Testpmd uses a single
3362 			 * size for all ports, so assume all ports are the same
3363 			 * NIC model and use the values from Port 0.
3364 			 */
3365 			ret = eth_dev_info_get_print_err(0, &dev_info);
3366 			if (ret != 0)
3367 				return;
3368 
3369 			rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3370 
3371 			if (rec_nb_pkts == 0) {
3372 				printf("PMD does not recommend a burst size.\n"
3373 					"User provided value must be between"
3374 					" 1 and %d\n", MAX_PKT_BURST);
3375 				return;
3376 			} else if (rec_nb_pkts > MAX_PKT_BURST) {
3377 				printf("PMD recommended burst size of %d"
3378 					" exceeds maximum value of %d\n",
3379 					rec_nb_pkts, MAX_PKT_BURST);
3380 				return;
3381 			}
3382 			printf("Using PMD-provided burst value of %d\n",
3383 				rec_nb_pkts);
3384 			nb_pkt_per_burst = rec_nb_pkts;
3385 		} else if (res->value > MAX_PKT_BURST) {
3386 			printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3387 			return;
3388 		} else
3389 			nb_pkt_per_burst = res->value;
3390 	} else {
3391 		printf("Unknown parameter\n");
3392 		return;
3393 	}
3394 
3395 	init_port_config();
3396 
3397 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3398 }
3399 
3400 cmdline_parse_token_string_t cmd_config_burst_port =
3401 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3402 cmdline_parse_token_string_t cmd_config_burst_keyword =
3403 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3404 cmdline_parse_token_string_t cmd_config_burst_all =
3405 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3406 cmdline_parse_token_string_t cmd_config_burst_name =
3407 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3408 cmdline_parse_token_num_t cmd_config_burst_value =
3409 	TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3410 
3411 cmdline_parse_inst_t cmd_config_burst = {
3412 	.f = cmd_config_burst_parsed,
3413 	.data = NULL,
3414 	.help_str = "port config all burst <value>",
3415 	.tokens = {
3416 		(void *)&cmd_config_burst_port,
3417 		(void *)&cmd_config_burst_keyword,
3418 		(void *)&cmd_config_burst_all,
3419 		(void *)&cmd_config_burst_name,
3420 		(void *)&cmd_config_burst_value,
3421 		NULL,
3422 	},
3423 };
3424 
3425 /* *** configure rx/tx queues *** */
3426 struct cmd_config_thresh {
3427 	cmdline_fixed_string_t port;
3428 	cmdline_fixed_string_t keyword;
3429 	cmdline_fixed_string_t all;
3430 	cmdline_fixed_string_t name;
3431 	uint8_t value;
3432 };
3433 
3434 static void
3435 cmd_config_thresh_parsed(void *parsed_result,
3436 			__rte_unused struct cmdline *cl,
3437 			__rte_unused void *data)
3438 {
3439 	struct cmd_config_thresh *res = parsed_result;
3440 
3441 	if (!all_ports_stopped()) {
3442 		printf("Please stop all ports first\n");
3443 		return;
3444 	}
3445 
3446 	if (!strcmp(res->name, "txpt"))
3447 		tx_pthresh = res->value;
3448 	else if(!strcmp(res->name, "txht"))
3449 		tx_hthresh = res->value;
3450 	else if(!strcmp(res->name, "txwt"))
3451 		tx_wthresh = res->value;
3452 	else if(!strcmp(res->name, "rxpt"))
3453 		rx_pthresh = res->value;
3454 	else if(!strcmp(res->name, "rxht"))
3455 		rx_hthresh = res->value;
3456 	else if(!strcmp(res->name, "rxwt"))
3457 		rx_wthresh = res->value;
3458 	else {
3459 		printf("Unknown parameter\n");
3460 		return;
3461 	}
3462 
3463 	init_port_config();
3464 
3465 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3466 }
3467 
3468 cmdline_parse_token_string_t cmd_config_thresh_port =
3469 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3470 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3471 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3472 cmdline_parse_token_string_t cmd_config_thresh_all =
3473 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3474 cmdline_parse_token_string_t cmd_config_thresh_name =
3475 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3476 				"txpt#txht#txwt#rxpt#rxht#rxwt");
3477 cmdline_parse_token_num_t cmd_config_thresh_value =
3478 	TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3479 
3480 cmdline_parse_inst_t cmd_config_thresh = {
3481 	.f = cmd_config_thresh_parsed,
3482 	.data = NULL,
3483 	.help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3484 	.tokens = {
3485 		(void *)&cmd_config_thresh_port,
3486 		(void *)&cmd_config_thresh_keyword,
3487 		(void *)&cmd_config_thresh_all,
3488 		(void *)&cmd_config_thresh_name,
3489 		(void *)&cmd_config_thresh_value,
3490 		NULL,
3491 	},
3492 };
3493 
3494 /* *** configure free/rs threshold *** */
3495 struct cmd_config_threshold {
3496 	cmdline_fixed_string_t port;
3497 	cmdline_fixed_string_t keyword;
3498 	cmdline_fixed_string_t all;
3499 	cmdline_fixed_string_t name;
3500 	uint16_t value;
3501 };
3502 
3503 static void
3504 cmd_config_threshold_parsed(void *parsed_result,
3505 			__rte_unused struct cmdline *cl,
3506 			__rte_unused void *data)
3507 {
3508 	struct cmd_config_threshold *res = parsed_result;
3509 
3510 	if (!all_ports_stopped()) {
3511 		printf("Please stop all ports first\n");
3512 		return;
3513 	}
3514 
3515 	if (!strcmp(res->name, "txfreet"))
3516 		tx_free_thresh = res->value;
3517 	else if (!strcmp(res->name, "txrst"))
3518 		tx_rs_thresh = res->value;
3519 	else if (!strcmp(res->name, "rxfreet"))
3520 		rx_free_thresh = res->value;
3521 	else {
3522 		printf("Unknown parameter\n");
3523 		return;
3524 	}
3525 
3526 	init_port_config();
3527 
3528 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3529 }
3530 
3531 cmdline_parse_token_string_t cmd_config_threshold_port =
3532 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3533 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3534 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3535 								"config");
3536 cmdline_parse_token_string_t cmd_config_threshold_all =
3537 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3538 cmdline_parse_token_string_t cmd_config_threshold_name =
3539 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3540 						"txfreet#txrst#rxfreet");
3541 cmdline_parse_token_num_t cmd_config_threshold_value =
3542 	TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3543 
3544 cmdline_parse_inst_t cmd_config_threshold = {
3545 	.f = cmd_config_threshold_parsed,
3546 	.data = NULL,
3547 	.help_str = "port config all txfreet|txrst|rxfreet <value>",
3548 	.tokens = {
3549 		(void *)&cmd_config_threshold_port,
3550 		(void *)&cmd_config_threshold_keyword,
3551 		(void *)&cmd_config_threshold_all,
3552 		(void *)&cmd_config_threshold_name,
3553 		(void *)&cmd_config_threshold_value,
3554 		NULL,
3555 	},
3556 };
3557 
3558 /* *** stop *** */
3559 struct cmd_stop_result {
3560 	cmdline_fixed_string_t stop;
3561 };
3562 
3563 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3564 			    __rte_unused struct cmdline *cl,
3565 			    __rte_unused void *data)
3566 {
3567 	stop_packet_forwarding();
3568 }
3569 
3570 cmdline_parse_token_string_t cmd_stop_stop =
3571 	TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3572 
3573 cmdline_parse_inst_t cmd_stop = {
3574 	.f = cmd_stop_parsed,
3575 	.data = NULL,
3576 	.help_str = "stop: Stop packet forwarding",
3577 	.tokens = {
3578 		(void *)&cmd_stop_stop,
3579 		NULL,
3580 	},
3581 };
3582 
3583 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3584 
3585 unsigned int
3586 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3587 		unsigned int *parsed_items, int check_unique_values)
3588 {
3589 	unsigned int nb_item;
3590 	unsigned int value;
3591 	unsigned int i;
3592 	unsigned int j;
3593 	int value_ok;
3594 	char c;
3595 
3596 	/*
3597 	 * First parse all items in the list and store their value.
3598 	 */
3599 	value = 0;
3600 	nb_item = 0;
3601 	value_ok = 0;
3602 	for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3603 		c = str[i];
3604 		if ((c >= '0') && (c <= '9')) {
3605 			value = (unsigned int) (value * 10 + (c - '0'));
3606 			value_ok = 1;
3607 			continue;
3608 		}
3609 		if (c != ',') {
3610 			printf("character %c is not a decimal digit\n", c);
3611 			return 0;
3612 		}
3613 		if (! value_ok) {
3614 			printf("No valid value before comma\n");
3615 			return 0;
3616 		}
3617 		if (nb_item < max_items) {
3618 			parsed_items[nb_item] = value;
3619 			value_ok = 0;
3620 			value = 0;
3621 		}
3622 		nb_item++;
3623 	}
3624 	if (nb_item >= max_items) {
3625 		printf("Number of %s = %u > %u (maximum items)\n",
3626 		       item_name, nb_item + 1, max_items);
3627 		return 0;
3628 	}
3629 	parsed_items[nb_item++] = value;
3630 	if (! check_unique_values)
3631 		return nb_item;
3632 
3633 	/*
3634 	 * Then, check that all values in the list are differents.
3635 	 * No optimization here...
3636 	 */
3637 	for (i = 0; i < nb_item; i++) {
3638 		for (j = i + 1; j < nb_item; j++) {
3639 			if (parsed_items[j] == parsed_items[i]) {
3640 				printf("duplicated %s %u at index %u and %u\n",
3641 				       item_name, parsed_items[i], i, j);
3642 				return 0;
3643 			}
3644 		}
3645 	}
3646 	return nb_item;
3647 }
3648 
3649 struct cmd_set_list_result {
3650 	cmdline_fixed_string_t cmd_keyword;
3651 	cmdline_fixed_string_t list_name;
3652 	cmdline_fixed_string_t list_of_items;
3653 };
3654 
3655 static void cmd_set_list_parsed(void *parsed_result,
3656 				__rte_unused struct cmdline *cl,
3657 				__rte_unused void *data)
3658 {
3659 	struct cmd_set_list_result *res;
3660 	union {
3661 		unsigned int lcorelist[RTE_MAX_LCORE];
3662 		unsigned int portlist[RTE_MAX_ETHPORTS];
3663 	} parsed_items;
3664 	unsigned int nb_item;
3665 
3666 	if (test_done == 0) {
3667 		printf("Please stop forwarding first\n");
3668 		return;
3669 	}
3670 
3671 	res = parsed_result;
3672 	if (!strcmp(res->list_name, "corelist")) {
3673 		nb_item = parse_item_list(res->list_of_items, "core",
3674 					  RTE_MAX_LCORE,
3675 					  parsed_items.lcorelist, 1);
3676 		if (nb_item > 0) {
3677 			set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3678 			fwd_config_setup();
3679 		}
3680 		return;
3681 	}
3682 	if (!strcmp(res->list_name, "portlist")) {
3683 		nb_item = parse_item_list(res->list_of_items, "port",
3684 					  RTE_MAX_ETHPORTS,
3685 					  parsed_items.portlist, 1);
3686 		if (nb_item > 0) {
3687 			set_fwd_ports_list(parsed_items.portlist, nb_item);
3688 			fwd_config_setup();
3689 		}
3690 	}
3691 }
3692 
3693 cmdline_parse_token_string_t cmd_set_list_keyword =
3694 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3695 				 "set");
3696 cmdline_parse_token_string_t cmd_set_list_name =
3697 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3698 				 "corelist#portlist");
3699 cmdline_parse_token_string_t cmd_set_list_of_items =
3700 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3701 				 NULL);
3702 
3703 cmdline_parse_inst_t cmd_set_fwd_list = {
3704 	.f = cmd_set_list_parsed,
3705 	.data = NULL,
3706 	.help_str = "set corelist|portlist <list0[,list1]*>",
3707 	.tokens = {
3708 		(void *)&cmd_set_list_keyword,
3709 		(void *)&cmd_set_list_name,
3710 		(void *)&cmd_set_list_of_items,
3711 		NULL,
3712 	},
3713 };
3714 
3715 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3716 
3717 struct cmd_setmask_result {
3718 	cmdline_fixed_string_t set;
3719 	cmdline_fixed_string_t mask;
3720 	uint64_t hexavalue;
3721 };
3722 
3723 static void cmd_set_mask_parsed(void *parsed_result,
3724 				__rte_unused struct cmdline *cl,
3725 				__rte_unused void *data)
3726 {
3727 	struct cmd_setmask_result *res = parsed_result;
3728 
3729 	if (test_done == 0) {
3730 		printf("Please stop forwarding first\n");
3731 		return;
3732 	}
3733 	if (!strcmp(res->mask, "coremask")) {
3734 		set_fwd_lcores_mask(res->hexavalue);
3735 		fwd_config_setup();
3736 	} else if (!strcmp(res->mask, "portmask")) {
3737 		set_fwd_ports_mask(res->hexavalue);
3738 		fwd_config_setup();
3739 	}
3740 }
3741 
3742 cmdline_parse_token_string_t cmd_setmask_set =
3743 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3744 cmdline_parse_token_string_t cmd_setmask_mask =
3745 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3746 				 "coremask#portmask");
3747 cmdline_parse_token_num_t cmd_setmask_value =
3748 	TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3749 
3750 cmdline_parse_inst_t cmd_set_fwd_mask = {
3751 	.f = cmd_set_mask_parsed,
3752 	.data = NULL,
3753 	.help_str = "set coremask|portmask <hexadecimal value>",
3754 	.tokens = {
3755 		(void *)&cmd_setmask_set,
3756 		(void *)&cmd_setmask_mask,
3757 		(void *)&cmd_setmask_value,
3758 		NULL,
3759 	},
3760 };
3761 
3762 /*
3763  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3764  */
3765 struct cmd_set_result {
3766 	cmdline_fixed_string_t set;
3767 	cmdline_fixed_string_t what;
3768 	uint16_t value;
3769 };
3770 
3771 static void cmd_set_parsed(void *parsed_result,
3772 			   __rte_unused struct cmdline *cl,
3773 			   __rte_unused void *data)
3774 {
3775 	struct cmd_set_result *res = parsed_result;
3776 	if (!strcmp(res->what, "nbport")) {
3777 		set_fwd_ports_number(res->value);
3778 		fwd_config_setup();
3779 	} else if (!strcmp(res->what, "nbcore")) {
3780 		set_fwd_lcores_number(res->value);
3781 		fwd_config_setup();
3782 	} else if (!strcmp(res->what, "burst"))
3783 		set_nb_pkt_per_burst(res->value);
3784 	else if (!strcmp(res->what, "verbose"))
3785 		set_verbose_level(res->value);
3786 }
3787 
3788 cmdline_parse_token_string_t cmd_set_set =
3789 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3790 cmdline_parse_token_string_t cmd_set_what =
3791 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3792 				 "nbport#nbcore#burst#verbose");
3793 cmdline_parse_token_num_t cmd_set_value =
3794 	TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3795 
3796 cmdline_parse_inst_t cmd_set_numbers = {
3797 	.f = cmd_set_parsed,
3798 	.data = NULL,
3799 	.help_str = "set nbport|nbcore|burst|verbose <value>",
3800 	.tokens = {
3801 		(void *)&cmd_set_set,
3802 		(void *)&cmd_set_what,
3803 		(void *)&cmd_set_value,
3804 		NULL,
3805 	},
3806 };
3807 
3808 /* *** SET LOG LEVEL CONFIGURATION *** */
3809 
3810 struct cmd_set_log_result {
3811 	cmdline_fixed_string_t set;
3812 	cmdline_fixed_string_t log;
3813 	cmdline_fixed_string_t type;
3814 	uint32_t level;
3815 };
3816 
3817 static void
3818 cmd_set_log_parsed(void *parsed_result,
3819 		   __rte_unused struct cmdline *cl,
3820 		   __rte_unused void *data)
3821 {
3822 	struct cmd_set_log_result *res;
3823 	int ret;
3824 
3825 	res = parsed_result;
3826 	if (!strcmp(res->type, "global"))
3827 		rte_log_set_global_level(res->level);
3828 	else {
3829 		ret = rte_log_set_level_regexp(res->type, res->level);
3830 		if (ret < 0)
3831 			printf("Unable to set log level\n");
3832 	}
3833 }
3834 
3835 cmdline_parse_token_string_t cmd_set_log_set =
3836 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3837 cmdline_parse_token_string_t cmd_set_log_log =
3838 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3839 cmdline_parse_token_string_t cmd_set_log_type =
3840 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3841 cmdline_parse_token_num_t cmd_set_log_level =
3842 	TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3843 
3844 cmdline_parse_inst_t cmd_set_log = {
3845 	.f = cmd_set_log_parsed,
3846 	.data = NULL,
3847 	.help_str = "set log global|<type> <level>",
3848 	.tokens = {
3849 		(void *)&cmd_set_log_set,
3850 		(void *)&cmd_set_log_log,
3851 		(void *)&cmd_set_log_type,
3852 		(void *)&cmd_set_log_level,
3853 		NULL,
3854 	},
3855 };
3856 
3857 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3858 
3859 struct cmd_set_txpkts_result {
3860 	cmdline_fixed_string_t cmd_keyword;
3861 	cmdline_fixed_string_t txpkts;
3862 	cmdline_fixed_string_t seg_lengths;
3863 };
3864 
3865 static void
3866 cmd_set_txpkts_parsed(void *parsed_result,
3867 		      __rte_unused struct cmdline *cl,
3868 		      __rte_unused void *data)
3869 {
3870 	struct cmd_set_txpkts_result *res;
3871 	unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3872 	unsigned int nb_segs;
3873 
3874 	res = parsed_result;
3875 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3876 				  RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3877 	if (nb_segs > 0)
3878 		set_tx_pkt_segments(seg_lengths, nb_segs);
3879 }
3880 
3881 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3882 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3883 				 cmd_keyword, "set");
3884 cmdline_parse_token_string_t cmd_set_txpkts_name =
3885 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3886 				 txpkts, "txpkts");
3887 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3888 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3889 				 seg_lengths, NULL);
3890 
3891 cmdline_parse_inst_t cmd_set_txpkts = {
3892 	.f = cmd_set_txpkts_parsed,
3893 	.data = NULL,
3894 	.help_str = "set txpkts <len0[,len1]*>",
3895 	.tokens = {
3896 		(void *)&cmd_set_txpkts_keyword,
3897 		(void *)&cmd_set_txpkts_name,
3898 		(void *)&cmd_set_txpkts_lengths,
3899 		NULL,
3900 	},
3901 };
3902 
3903 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3904 
3905 struct cmd_set_txsplit_result {
3906 	cmdline_fixed_string_t cmd_keyword;
3907 	cmdline_fixed_string_t txsplit;
3908 	cmdline_fixed_string_t mode;
3909 };
3910 
3911 static void
3912 cmd_set_txsplit_parsed(void *parsed_result,
3913 		      __rte_unused struct cmdline *cl,
3914 		      __rte_unused void *data)
3915 {
3916 	struct cmd_set_txsplit_result *res;
3917 
3918 	res = parsed_result;
3919 	set_tx_pkt_split(res->mode);
3920 }
3921 
3922 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3923 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3924 				 cmd_keyword, "set");
3925 cmdline_parse_token_string_t cmd_set_txsplit_name =
3926 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3927 				 txsplit, "txsplit");
3928 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3929 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3930 				 mode, NULL);
3931 
3932 cmdline_parse_inst_t cmd_set_txsplit = {
3933 	.f = cmd_set_txsplit_parsed,
3934 	.data = NULL,
3935 	.help_str = "set txsplit on|off|rand",
3936 	.tokens = {
3937 		(void *)&cmd_set_txsplit_keyword,
3938 		(void *)&cmd_set_txsplit_name,
3939 		(void *)&cmd_set_txsplit_mode,
3940 		NULL,
3941 	},
3942 };
3943 
3944 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3945 
3946 struct cmd_set_txtimes_result {
3947 	cmdline_fixed_string_t cmd_keyword;
3948 	cmdline_fixed_string_t txtimes;
3949 	cmdline_fixed_string_t tx_times;
3950 };
3951 
3952 static void
3953 cmd_set_txtimes_parsed(void *parsed_result,
3954 		       __rte_unused struct cmdline *cl,
3955 		       __rte_unused void *data)
3956 {
3957 	struct cmd_set_txtimes_result *res;
3958 	unsigned int tx_times[2] = {0, 0};
3959 	unsigned int n_times;
3960 
3961 	res = parsed_result;
3962 	n_times = parse_item_list(res->tx_times, "tx times",
3963 				  2, tx_times, 0);
3964 	if (n_times == 2)
3965 		set_tx_pkt_times(tx_times);
3966 }
3967 
3968 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3969 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3970 				 cmd_keyword, "set");
3971 cmdline_parse_token_string_t cmd_set_txtimes_name =
3972 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3973 				 txtimes, "txtimes");
3974 cmdline_parse_token_string_t cmd_set_txtimes_value =
3975 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3976 				 tx_times, NULL);
3977 
3978 cmdline_parse_inst_t cmd_set_txtimes = {
3979 	.f = cmd_set_txtimes_parsed,
3980 	.data = NULL,
3981 	.help_str = "set txtimes <inter_burst>,<intra_burst>",
3982 	.tokens = {
3983 		(void *)&cmd_set_txtimes_keyword,
3984 		(void *)&cmd_set_txtimes_name,
3985 		(void *)&cmd_set_txtimes_value,
3986 		NULL,
3987 	},
3988 };
3989 
3990 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3991 struct cmd_rx_vlan_filter_all_result {
3992 	cmdline_fixed_string_t rx_vlan;
3993 	cmdline_fixed_string_t what;
3994 	cmdline_fixed_string_t all;
3995 	portid_t port_id;
3996 };
3997 
3998 static void
3999 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4000 			      __rte_unused struct cmdline *cl,
4001 			      __rte_unused void *data)
4002 {
4003 	struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4004 
4005 	if (!strcmp(res->what, "add"))
4006 		rx_vlan_all_filter_set(res->port_id, 1);
4007 	else
4008 		rx_vlan_all_filter_set(res->port_id, 0);
4009 }
4010 
4011 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4012 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4013 				 rx_vlan, "rx_vlan");
4014 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4015 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4016 				 what, "add#rm");
4017 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4018 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4019 				 all, "all");
4020 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4021 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4022 			      port_id, UINT16);
4023 
4024 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4025 	.f = cmd_rx_vlan_filter_all_parsed,
4026 	.data = NULL,
4027 	.help_str = "rx_vlan add|rm all <port_id>: "
4028 		"Add/Remove all identifiers to/from the set of VLAN "
4029 		"identifiers filtered by a port",
4030 	.tokens = {
4031 		(void *)&cmd_rx_vlan_filter_all_rx_vlan,
4032 		(void *)&cmd_rx_vlan_filter_all_what,
4033 		(void *)&cmd_rx_vlan_filter_all_all,
4034 		(void *)&cmd_rx_vlan_filter_all_portid,
4035 		NULL,
4036 	},
4037 };
4038 
4039 /* *** VLAN OFFLOAD SET ON A PORT *** */
4040 struct cmd_vlan_offload_result {
4041 	cmdline_fixed_string_t vlan;
4042 	cmdline_fixed_string_t set;
4043 	cmdline_fixed_string_t vlan_type;
4044 	cmdline_fixed_string_t what;
4045 	cmdline_fixed_string_t on;
4046 	cmdline_fixed_string_t port_id;
4047 };
4048 
4049 static void
4050 cmd_vlan_offload_parsed(void *parsed_result,
4051 			  __rte_unused struct cmdline *cl,
4052 			  __rte_unused void *data)
4053 {
4054 	int on;
4055 	struct cmd_vlan_offload_result *res = parsed_result;
4056 	char *str;
4057 	int i, len = 0;
4058 	portid_t port_id = 0;
4059 	unsigned int tmp;
4060 
4061 	str = res->port_id;
4062 	len = strnlen(str, STR_TOKEN_SIZE);
4063 	i = 0;
4064 	/* Get port_id first */
4065 	while(i < len){
4066 		if(str[i] == ',')
4067 			break;
4068 
4069 		i++;
4070 	}
4071 	str[i]='\0';
4072 	tmp = strtoul(str, NULL, 0);
4073 	/* If port_id greater that what portid_t can represent, return */
4074 	if(tmp >= RTE_MAX_ETHPORTS)
4075 		return;
4076 	port_id = (portid_t)tmp;
4077 
4078 	if (!strcmp(res->on, "on"))
4079 		on = 1;
4080 	else
4081 		on = 0;
4082 
4083 	if (!strcmp(res->what, "strip"))
4084 		rx_vlan_strip_set(port_id,  on);
4085 	else if(!strcmp(res->what, "stripq")){
4086 		uint16_t queue_id = 0;
4087 
4088 		/* No queue_id, return */
4089 		if(i + 1 >= len) {
4090 			printf("must specify (port,queue_id)\n");
4091 			return;
4092 		}
4093 		tmp = strtoul(str + i + 1, NULL, 0);
4094 		/* If queue_id greater that what 16-bits can represent, return */
4095 		if(tmp > 0xffff)
4096 			return;
4097 
4098 		queue_id = (uint16_t)tmp;
4099 		rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4100 	}
4101 	else if (!strcmp(res->what, "filter"))
4102 		rx_vlan_filter_set(port_id, on);
4103 	else if (!strcmp(res->what, "qinq_strip"))
4104 		rx_vlan_qinq_strip_set(port_id, on);
4105 	else
4106 		vlan_extend_set(port_id, on);
4107 
4108 	return;
4109 }
4110 
4111 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4112 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4113 				 vlan, "vlan");
4114 cmdline_parse_token_string_t cmd_vlan_offload_set =
4115 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4116 				 set, "set");
4117 cmdline_parse_token_string_t cmd_vlan_offload_what =
4118 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4119 				what, "strip#filter#qinq_strip#extend#stripq");
4120 cmdline_parse_token_string_t cmd_vlan_offload_on =
4121 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4122 			      on, "on#off");
4123 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4124 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4125 			      port_id, NULL);
4126 
4127 cmdline_parse_inst_t cmd_vlan_offload = {
4128 	.f = cmd_vlan_offload_parsed,
4129 	.data = NULL,
4130 	.help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4131 		"<port_id[,queue_id]>: "
4132 		"Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4133 	.tokens = {
4134 		(void *)&cmd_vlan_offload_vlan,
4135 		(void *)&cmd_vlan_offload_set,
4136 		(void *)&cmd_vlan_offload_what,
4137 		(void *)&cmd_vlan_offload_on,
4138 		(void *)&cmd_vlan_offload_portid,
4139 		NULL,
4140 	},
4141 };
4142 
4143 /* *** VLAN TPID SET ON A PORT *** */
4144 struct cmd_vlan_tpid_result {
4145 	cmdline_fixed_string_t vlan;
4146 	cmdline_fixed_string_t set;
4147 	cmdline_fixed_string_t vlan_type;
4148 	cmdline_fixed_string_t what;
4149 	uint16_t tp_id;
4150 	portid_t port_id;
4151 };
4152 
4153 static void
4154 cmd_vlan_tpid_parsed(void *parsed_result,
4155 			  __rte_unused struct cmdline *cl,
4156 			  __rte_unused void *data)
4157 {
4158 	struct cmd_vlan_tpid_result *res = parsed_result;
4159 	enum rte_vlan_type vlan_type;
4160 
4161 	if (!strcmp(res->vlan_type, "inner"))
4162 		vlan_type = ETH_VLAN_TYPE_INNER;
4163 	else if (!strcmp(res->vlan_type, "outer"))
4164 		vlan_type = ETH_VLAN_TYPE_OUTER;
4165 	else {
4166 		printf("Unknown vlan type\n");
4167 		return;
4168 	}
4169 	vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4170 }
4171 
4172 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4173 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4174 				 vlan, "vlan");
4175 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4176 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4177 				 set, "set");
4178 cmdline_parse_token_string_t cmd_vlan_type =
4179 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4180 				 vlan_type, "inner#outer");
4181 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4182 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4183 				 what, "tpid");
4184 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4185 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4186 			      tp_id, UINT16);
4187 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4188 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4189 			      port_id, UINT16);
4190 
4191 cmdline_parse_inst_t cmd_vlan_tpid = {
4192 	.f = cmd_vlan_tpid_parsed,
4193 	.data = NULL,
4194 	.help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4195 		"Set the VLAN Ether type",
4196 	.tokens = {
4197 		(void *)&cmd_vlan_tpid_vlan,
4198 		(void *)&cmd_vlan_tpid_set,
4199 		(void *)&cmd_vlan_type,
4200 		(void *)&cmd_vlan_tpid_what,
4201 		(void *)&cmd_vlan_tpid_tpid,
4202 		(void *)&cmd_vlan_tpid_portid,
4203 		NULL,
4204 	},
4205 };
4206 
4207 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4208 struct cmd_rx_vlan_filter_result {
4209 	cmdline_fixed_string_t rx_vlan;
4210 	cmdline_fixed_string_t what;
4211 	uint16_t vlan_id;
4212 	portid_t port_id;
4213 };
4214 
4215 static void
4216 cmd_rx_vlan_filter_parsed(void *parsed_result,
4217 			  __rte_unused struct cmdline *cl,
4218 			  __rte_unused void *data)
4219 {
4220 	struct cmd_rx_vlan_filter_result *res = parsed_result;
4221 
4222 	if (!strcmp(res->what, "add"))
4223 		rx_vft_set(res->port_id, res->vlan_id, 1);
4224 	else
4225 		rx_vft_set(res->port_id, res->vlan_id, 0);
4226 }
4227 
4228 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4229 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4230 				 rx_vlan, "rx_vlan");
4231 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4232 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4233 				 what, "add#rm");
4234 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4235 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4236 			      vlan_id, UINT16);
4237 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4238 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4239 			      port_id, UINT16);
4240 
4241 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4242 	.f = cmd_rx_vlan_filter_parsed,
4243 	.data = NULL,
4244 	.help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4245 		"Add/Remove a VLAN identifier to/from the set of VLAN "
4246 		"identifiers filtered by a port",
4247 	.tokens = {
4248 		(void *)&cmd_rx_vlan_filter_rx_vlan,
4249 		(void *)&cmd_rx_vlan_filter_what,
4250 		(void *)&cmd_rx_vlan_filter_vlanid,
4251 		(void *)&cmd_rx_vlan_filter_portid,
4252 		NULL,
4253 	},
4254 };
4255 
4256 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4257 struct cmd_tx_vlan_set_result {
4258 	cmdline_fixed_string_t tx_vlan;
4259 	cmdline_fixed_string_t set;
4260 	portid_t port_id;
4261 	uint16_t vlan_id;
4262 };
4263 
4264 static void
4265 cmd_tx_vlan_set_parsed(void *parsed_result,
4266 		       __rte_unused struct cmdline *cl,
4267 		       __rte_unused void *data)
4268 {
4269 	struct cmd_tx_vlan_set_result *res = parsed_result;
4270 
4271 	if (!port_is_stopped(res->port_id)) {
4272 		printf("Please stop port %d first\n", res->port_id);
4273 		return;
4274 	}
4275 
4276 	tx_vlan_set(res->port_id, res->vlan_id);
4277 
4278 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4279 }
4280 
4281 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4282 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4283 				 tx_vlan, "tx_vlan");
4284 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4285 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4286 				 set, "set");
4287 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4288 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4289 			      port_id, UINT16);
4290 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4291 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4292 			      vlan_id, UINT16);
4293 
4294 cmdline_parse_inst_t cmd_tx_vlan_set = {
4295 	.f = cmd_tx_vlan_set_parsed,
4296 	.data = NULL,
4297 	.help_str = "tx_vlan set <port_id> <vlan_id>: "
4298 		"Enable hardware insertion of a single VLAN header "
4299 		"with a given TAG Identifier in packets sent on a port",
4300 	.tokens = {
4301 		(void *)&cmd_tx_vlan_set_tx_vlan,
4302 		(void *)&cmd_tx_vlan_set_set,
4303 		(void *)&cmd_tx_vlan_set_portid,
4304 		(void *)&cmd_tx_vlan_set_vlanid,
4305 		NULL,
4306 	},
4307 };
4308 
4309 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4310 struct cmd_tx_vlan_set_qinq_result {
4311 	cmdline_fixed_string_t tx_vlan;
4312 	cmdline_fixed_string_t set;
4313 	portid_t port_id;
4314 	uint16_t vlan_id;
4315 	uint16_t vlan_id_outer;
4316 };
4317 
4318 static void
4319 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4320 			    __rte_unused struct cmdline *cl,
4321 			    __rte_unused void *data)
4322 {
4323 	struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4324 
4325 	if (!port_is_stopped(res->port_id)) {
4326 		printf("Please stop port %d first\n", res->port_id);
4327 		return;
4328 	}
4329 
4330 	tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4331 
4332 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4333 }
4334 
4335 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4336 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4337 		tx_vlan, "tx_vlan");
4338 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4339 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4340 		set, "set");
4341 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4342 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4343 		port_id, UINT16);
4344 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4345 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4346 		vlan_id, UINT16);
4347 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4348 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4349 		vlan_id_outer, UINT16);
4350 
4351 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4352 	.f = cmd_tx_vlan_set_qinq_parsed,
4353 	.data = NULL,
4354 	.help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4355 		"Enable hardware insertion of double VLAN header "
4356 		"with given TAG Identifiers in packets sent on a port",
4357 	.tokens = {
4358 		(void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4359 		(void *)&cmd_tx_vlan_set_qinq_set,
4360 		(void *)&cmd_tx_vlan_set_qinq_portid,
4361 		(void *)&cmd_tx_vlan_set_qinq_vlanid,
4362 		(void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4363 		NULL,
4364 	},
4365 };
4366 
4367 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4368 struct cmd_tx_vlan_set_pvid_result {
4369 	cmdline_fixed_string_t tx_vlan;
4370 	cmdline_fixed_string_t set;
4371 	cmdline_fixed_string_t pvid;
4372 	portid_t port_id;
4373 	uint16_t vlan_id;
4374 	cmdline_fixed_string_t mode;
4375 };
4376 
4377 static void
4378 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4379 			    __rte_unused struct cmdline *cl,
4380 			    __rte_unused void *data)
4381 {
4382 	struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4383 
4384 	if (strcmp(res->mode, "on") == 0)
4385 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4386 	else
4387 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4388 }
4389 
4390 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4391 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4392 				 tx_vlan, "tx_vlan");
4393 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4394 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4395 				 set, "set");
4396 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4397 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4398 				 pvid, "pvid");
4399 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4400 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4401 			     port_id, UINT16);
4402 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4403 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4404 			      vlan_id, UINT16);
4405 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4406 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4407 				 mode, "on#off");
4408 
4409 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4410 	.f = cmd_tx_vlan_set_pvid_parsed,
4411 	.data = NULL,
4412 	.help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4413 	.tokens = {
4414 		(void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4415 		(void *)&cmd_tx_vlan_set_pvid_set,
4416 		(void *)&cmd_tx_vlan_set_pvid_pvid,
4417 		(void *)&cmd_tx_vlan_set_pvid_port_id,
4418 		(void *)&cmd_tx_vlan_set_pvid_vlan_id,
4419 		(void *)&cmd_tx_vlan_set_pvid_mode,
4420 		NULL,
4421 	},
4422 };
4423 
4424 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4425 struct cmd_tx_vlan_reset_result {
4426 	cmdline_fixed_string_t tx_vlan;
4427 	cmdline_fixed_string_t reset;
4428 	portid_t port_id;
4429 };
4430 
4431 static void
4432 cmd_tx_vlan_reset_parsed(void *parsed_result,
4433 			 __rte_unused struct cmdline *cl,
4434 			 __rte_unused void *data)
4435 {
4436 	struct cmd_tx_vlan_reset_result *res = parsed_result;
4437 
4438 	if (!port_is_stopped(res->port_id)) {
4439 		printf("Please stop port %d first\n", res->port_id);
4440 		return;
4441 	}
4442 
4443 	tx_vlan_reset(res->port_id);
4444 
4445 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4446 }
4447 
4448 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4449 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4450 				 tx_vlan, "tx_vlan");
4451 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4452 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4453 				 reset, "reset");
4454 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4455 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4456 			      port_id, UINT16);
4457 
4458 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4459 	.f = cmd_tx_vlan_reset_parsed,
4460 	.data = NULL,
4461 	.help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4462 		"VLAN header in packets sent on a port",
4463 	.tokens = {
4464 		(void *)&cmd_tx_vlan_reset_tx_vlan,
4465 		(void *)&cmd_tx_vlan_reset_reset,
4466 		(void *)&cmd_tx_vlan_reset_portid,
4467 		NULL,
4468 	},
4469 };
4470 
4471 
4472 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4473 struct cmd_csum_result {
4474 	cmdline_fixed_string_t csum;
4475 	cmdline_fixed_string_t mode;
4476 	cmdline_fixed_string_t proto;
4477 	cmdline_fixed_string_t hwsw;
4478 	portid_t port_id;
4479 };
4480 
4481 static void
4482 csum_show(int port_id)
4483 {
4484 	struct rte_eth_dev_info dev_info;
4485 	uint64_t tx_offloads;
4486 	int ret;
4487 
4488 	tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4489 	printf("Parse tunnel is %s\n",
4490 		(ports[port_id].parse_tunnel) ? "on" : "off");
4491 	printf("IP checksum offload is %s\n",
4492 		(tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4493 	printf("UDP checksum offload is %s\n",
4494 		(tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4495 	printf("TCP checksum offload is %s\n",
4496 		(tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4497 	printf("SCTP checksum offload is %s\n",
4498 		(tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4499 	printf("Outer-Ip checksum offload is %s\n",
4500 		(tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4501 	printf("Outer-Udp checksum offload is %s\n",
4502 		(tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4503 
4504 	/* display warnings if configuration is not supported by the NIC */
4505 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
4506 	if (ret != 0)
4507 		return;
4508 
4509 	if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4510 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4511 		printf("Warning: hardware IP checksum enabled but not "
4512 			"supported by port %d\n", port_id);
4513 	}
4514 	if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4515 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4516 		printf("Warning: hardware UDP checksum enabled but not "
4517 			"supported by port %d\n", port_id);
4518 	}
4519 	if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4520 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4521 		printf("Warning: hardware TCP checksum enabled but not "
4522 			"supported by port %d\n", port_id);
4523 	}
4524 	if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4525 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4526 		printf("Warning: hardware SCTP checksum enabled but not "
4527 			"supported by port %d\n", port_id);
4528 	}
4529 	if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4530 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4531 		printf("Warning: hardware outer IP checksum enabled but not "
4532 			"supported by port %d\n", port_id);
4533 	}
4534 	if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4535 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4536 			== 0) {
4537 		printf("Warning: hardware outer UDP checksum enabled but not "
4538 			"supported by port %d\n", port_id);
4539 	}
4540 }
4541 
4542 static void
4543 cmd_config_queue_tx_offloads(struct rte_port *port)
4544 {
4545 	int k;
4546 
4547 	/* Apply queue tx offloads configuration */
4548 	for (k = 0; k < port->dev_info.max_rx_queues; k++)
4549 		port->tx_conf[k].offloads =
4550 			port->dev_conf.txmode.offloads;
4551 }
4552 
4553 static void
4554 cmd_csum_parsed(void *parsed_result,
4555 		       __rte_unused struct cmdline *cl,
4556 		       __rte_unused void *data)
4557 {
4558 	struct cmd_csum_result *res = parsed_result;
4559 	int hw = 0;
4560 	uint64_t csum_offloads = 0;
4561 	struct rte_eth_dev_info dev_info;
4562 	int ret;
4563 
4564 	if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4565 		printf("invalid port %d\n", res->port_id);
4566 		return;
4567 	}
4568 	if (!port_is_stopped(res->port_id)) {
4569 		printf("Please stop port %d first\n", res->port_id);
4570 		return;
4571 	}
4572 
4573 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4574 	if (ret != 0)
4575 		return;
4576 
4577 	if (!strcmp(res->mode, "set")) {
4578 
4579 		if (!strcmp(res->hwsw, "hw"))
4580 			hw = 1;
4581 
4582 		if (!strcmp(res->proto, "ip")) {
4583 			if (hw == 0 || (dev_info.tx_offload_capa &
4584 						DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4585 				csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4586 			} else {
4587 				printf("IP checksum offload is not supported "
4588 				       "by port %u\n", res->port_id);
4589 			}
4590 		} else if (!strcmp(res->proto, "udp")) {
4591 			if (hw == 0 || (dev_info.tx_offload_capa &
4592 						DEV_TX_OFFLOAD_UDP_CKSUM)) {
4593 				csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4594 			} else {
4595 				printf("UDP checksum offload is not supported "
4596 				       "by port %u\n", res->port_id);
4597 			}
4598 		} else if (!strcmp(res->proto, "tcp")) {
4599 			if (hw == 0 || (dev_info.tx_offload_capa &
4600 						DEV_TX_OFFLOAD_TCP_CKSUM)) {
4601 				csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4602 			} else {
4603 				printf("TCP checksum offload is not supported "
4604 				       "by port %u\n", res->port_id);
4605 			}
4606 		} else if (!strcmp(res->proto, "sctp")) {
4607 			if (hw == 0 || (dev_info.tx_offload_capa &
4608 						DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4609 				csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4610 			} else {
4611 				printf("SCTP checksum offload is not supported "
4612 				       "by port %u\n", res->port_id);
4613 			}
4614 		} else if (!strcmp(res->proto, "outer-ip")) {
4615 			if (hw == 0 || (dev_info.tx_offload_capa &
4616 					DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4617 				csum_offloads |=
4618 						DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4619 			} else {
4620 				printf("Outer IP checksum offload is not "
4621 				       "supported by port %u\n", res->port_id);
4622 			}
4623 		} else if (!strcmp(res->proto, "outer-udp")) {
4624 			if (hw == 0 || (dev_info.tx_offload_capa &
4625 					DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4626 				csum_offloads |=
4627 						DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4628 			} else {
4629 				printf("Outer UDP checksum offload is not "
4630 				       "supported by port %u\n", res->port_id);
4631 			}
4632 		}
4633 
4634 		if (hw) {
4635 			ports[res->port_id].dev_conf.txmode.offloads |=
4636 							csum_offloads;
4637 		} else {
4638 			ports[res->port_id].dev_conf.txmode.offloads &=
4639 							(~csum_offloads);
4640 		}
4641 		cmd_config_queue_tx_offloads(&ports[res->port_id]);
4642 	}
4643 	csum_show(res->port_id);
4644 
4645 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4646 }
4647 
4648 cmdline_parse_token_string_t cmd_csum_csum =
4649 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4650 				csum, "csum");
4651 cmdline_parse_token_string_t cmd_csum_mode =
4652 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4653 				mode, "set");
4654 cmdline_parse_token_string_t cmd_csum_proto =
4655 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4656 				proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4657 cmdline_parse_token_string_t cmd_csum_hwsw =
4658 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4659 				hwsw, "hw#sw");
4660 cmdline_parse_token_num_t cmd_csum_portid =
4661 	TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4662 				port_id, UINT16);
4663 
4664 cmdline_parse_inst_t cmd_csum_set = {
4665 	.f = cmd_csum_parsed,
4666 	.data = NULL,
4667 	.help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4668 		"Enable/Disable hardware calculation of L3/L4 checksum when "
4669 		"using csum forward engine",
4670 	.tokens = {
4671 		(void *)&cmd_csum_csum,
4672 		(void *)&cmd_csum_mode,
4673 		(void *)&cmd_csum_proto,
4674 		(void *)&cmd_csum_hwsw,
4675 		(void *)&cmd_csum_portid,
4676 		NULL,
4677 	},
4678 };
4679 
4680 cmdline_parse_token_string_t cmd_csum_mode_show =
4681 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4682 				mode, "show");
4683 
4684 cmdline_parse_inst_t cmd_csum_show = {
4685 	.f = cmd_csum_parsed,
4686 	.data = NULL,
4687 	.help_str = "csum show <port_id>: Show checksum offload configuration",
4688 	.tokens = {
4689 		(void *)&cmd_csum_csum,
4690 		(void *)&cmd_csum_mode_show,
4691 		(void *)&cmd_csum_portid,
4692 		NULL,
4693 	},
4694 };
4695 
4696 /* Enable/disable tunnel parsing */
4697 struct cmd_csum_tunnel_result {
4698 	cmdline_fixed_string_t csum;
4699 	cmdline_fixed_string_t parse;
4700 	cmdline_fixed_string_t onoff;
4701 	portid_t port_id;
4702 };
4703 
4704 static void
4705 cmd_csum_tunnel_parsed(void *parsed_result,
4706 		       __rte_unused struct cmdline *cl,
4707 		       __rte_unused void *data)
4708 {
4709 	struct cmd_csum_tunnel_result *res = parsed_result;
4710 
4711 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4712 		return;
4713 
4714 	if (!strcmp(res->onoff, "on"))
4715 		ports[res->port_id].parse_tunnel = 1;
4716 	else
4717 		ports[res->port_id].parse_tunnel = 0;
4718 
4719 	csum_show(res->port_id);
4720 }
4721 
4722 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4723 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4724 				csum, "csum");
4725 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4726 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4727 				parse, "parse-tunnel");
4728 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4729 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4730 				onoff, "on#off");
4731 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4732 	TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4733 				port_id, UINT16);
4734 
4735 cmdline_parse_inst_t cmd_csum_tunnel = {
4736 	.f = cmd_csum_tunnel_parsed,
4737 	.data = NULL,
4738 	.help_str = "csum parse-tunnel on|off <port_id>: "
4739 		"Enable/Disable parsing of tunnels for csum engine",
4740 	.tokens = {
4741 		(void *)&cmd_csum_tunnel_csum,
4742 		(void *)&cmd_csum_tunnel_parse,
4743 		(void *)&cmd_csum_tunnel_onoff,
4744 		(void *)&cmd_csum_tunnel_portid,
4745 		NULL,
4746 	},
4747 };
4748 
4749 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4750 struct cmd_tso_set_result {
4751 	cmdline_fixed_string_t tso;
4752 	cmdline_fixed_string_t mode;
4753 	uint16_t tso_segsz;
4754 	portid_t port_id;
4755 };
4756 
4757 static void
4758 cmd_tso_set_parsed(void *parsed_result,
4759 		       __rte_unused struct cmdline *cl,
4760 		       __rte_unused void *data)
4761 {
4762 	struct cmd_tso_set_result *res = parsed_result;
4763 	struct rte_eth_dev_info dev_info;
4764 	int ret;
4765 
4766 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4767 		return;
4768 	if (!port_is_stopped(res->port_id)) {
4769 		printf("Please stop port %d first\n", res->port_id);
4770 		return;
4771 	}
4772 
4773 	if (!strcmp(res->mode, "set"))
4774 		ports[res->port_id].tso_segsz = res->tso_segsz;
4775 
4776 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4777 	if (ret != 0)
4778 		return;
4779 
4780 	if ((ports[res->port_id].tso_segsz != 0) &&
4781 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4782 		printf("Error: TSO is not supported by port %d\n",
4783 		       res->port_id);
4784 		return;
4785 	}
4786 
4787 	if (ports[res->port_id].tso_segsz == 0) {
4788 		ports[res->port_id].dev_conf.txmode.offloads &=
4789 						~DEV_TX_OFFLOAD_TCP_TSO;
4790 		printf("TSO for non-tunneled packets is disabled\n");
4791 	} else {
4792 		ports[res->port_id].dev_conf.txmode.offloads |=
4793 						DEV_TX_OFFLOAD_TCP_TSO;
4794 		printf("TSO segment size for non-tunneled packets is %d\n",
4795 			ports[res->port_id].tso_segsz);
4796 	}
4797 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
4798 
4799 	/* display warnings if configuration is not supported by the NIC */
4800 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4801 	if (ret != 0)
4802 		return;
4803 
4804 	if ((ports[res->port_id].tso_segsz != 0) &&
4805 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4806 		printf("Warning: TSO enabled but not "
4807 			"supported by port %d\n", res->port_id);
4808 	}
4809 
4810 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4811 }
4812 
4813 cmdline_parse_token_string_t cmd_tso_set_tso =
4814 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4815 				tso, "tso");
4816 cmdline_parse_token_string_t cmd_tso_set_mode =
4817 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4818 				mode, "set");
4819 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4820 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4821 				tso_segsz, UINT16);
4822 cmdline_parse_token_num_t cmd_tso_set_portid =
4823 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4824 				port_id, UINT16);
4825 
4826 cmdline_parse_inst_t cmd_tso_set = {
4827 	.f = cmd_tso_set_parsed,
4828 	.data = NULL,
4829 	.help_str = "tso set <tso_segsz> <port_id>: "
4830 		"Set TSO segment size of non-tunneled packets for csum engine "
4831 		"(0 to disable)",
4832 	.tokens = {
4833 		(void *)&cmd_tso_set_tso,
4834 		(void *)&cmd_tso_set_mode,
4835 		(void *)&cmd_tso_set_tso_segsz,
4836 		(void *)&cmd_tso_set_portid,
4837 		NULL,
4838 	},
4839 };
4840 
4841 cmdline_parse_token_string_t cmd_tso_show_mode =
4842 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4843 				mode, "show");
4844 
4845 
4846 cmdline_parse_inst_t cmd_tso_show = {
4847 	.f = cmd_tso_set_parsed,
4848 	.data = NULL,
4849 	.help_str = "tso show <port_id>: "
4850 		"Show TSO segment size of non-tunneled packets for csum engine",
4851 	.tokens = {
4852 		(void *)&cmd_tso_set_tso,
4853 		(void *)&cmd_tso_show_mode,
4854 		(void *)&cmd_tso_set_portid,
4855 		NULL,
4856 	},
4857 };
4858 
4859 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4860 struct cmd_tunnel_tso_set_result {
4861 	cmdline_fixed_string_t tso;
4862 	cmdline_fixed_string_t mode;
4863 	uint16_t tso_segsz;
4864 	portid_t port_id;
4865 };
4866 
4867 static struct rte_eth_dev_info
4868 check_tunnel_tso_nic_support(portid_t port_id)
4869 {
4870 	struct rte_eth_dev_info dev_info;
4871 
4872 	if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4873 		return dev_info;
4874 
4875 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4876 		printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4877 		       "not enabled for port %d\n", port_id);
4878 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4879 		printf("Warning: GRE TUNNEL TSO	not supported therefore "
4880 		       "not enabled for port %d\n", port_id);
4881 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4882 		printf("Warning: IPIP TUNNEL TSO not supported therefore "
4883 		       "not enabled for port %d\n", port_id);
4884 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4885 		printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4886 		       "not enabled for port %d\n", port_id);
4887 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4888 		printf("Warning: IP TUNNEL TSO not supported therefore "
4889 		       "not enabled for port %d\n", port_id);
4890 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4891 		printf("Warning: UDP TUNNEL TSO not supported therefore "
4892 		       "not enabled for port %d\n", port_id);
4893 	return dev_info;
4894 }
4895 
4896 static void
4897 cmd_tunnel_tso_set_parsed(void *parsed_result,
4898 			  __rte_unused struct cmdline *cl,
4899 			  __rte_unused void *data)
4900 {
4901 	struct cmd_tunnel_tso_set_result *res = parsed_result;
4902 	struct rte_eth_dev_info dev_info;
4903 
4904 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4905 		return;
4906 	if (!port_is_stopped(res->port_id)) {
4907 		printf("Please stop port %d first\n", res->port_id);
4908 		return;
4909 	}
4910 
4911 	if (!strcmp(res->mode, "set"))
4912 		ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4913 
4914 	dev_info = check_tunnel_tso_nic_support(res->port_id);
4915 	if (ports[res->port_id].tunnel_tso_segsz == 0) {
4916 		ports[res->port_id].dev_conf.txmode.offloads &=
4917 			~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4918 			  DEV_TX_OFFLOAD_GRE_TNL_TSO |
4919 			  DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4920 			  DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4921 			  DEV_TX_OFFLOAD_IP_TNL_TSO |
4922 			  DEV_TX_OFFLOAD_UDP_TNL_TSO);
4923 		printf("TSO for tunneled packets is disabled\n");
4924 	} else {
4925 		uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4926 					 DEV_TX_OFFLOAD_GRE_TNL_TSO |
4927 					 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4928 					 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4929 					 DEV_TX_OFFLOAD_IP_TNL_TSO |
4930 					 DEV_TX_OFFLOAD_UDP_TNL_TSO);
4931 
4932 		ports[res->port_id].dev_conf.txmode.offloads |=
4933 			(tso_offloads & dev_info.tx_offload_capa);
4934 		printf("TSO segment size for tunneled packets is %d\n",
4935 			ports[res->port_id].tunnel_tso_segsz);
4936 
4937 		/* Below conditions are needed to make it work:
4938 		 * (1) tunnel TSO is supported by the NIC;
4939 		 * (2) "csum parse_tunnel" must be set so that tunneled pkts
4940 		 * are recognized;
4941 		 * (3) for tunneled pkts with outer L3 of IPv4,
4942 		 * "csum set outer-ip" must be set to hw, because after tso,
4943 		 * total_len of outer IP header is changed, and the checksum
4944 		 * of outer IP header calculated by sw should be wrong; that
4945 		 * is not necessary for IPv6 tunneled pkts because there's no
4946 		 * checksum in IP header anymore.
4947 		 */
4948 
4949 		if (!ports[res->port_id].parse_tunnel)
4950 			printf("Warning: csum parse_tunnel must be set "
4951 				"so that tunneled packets are recognized\n");
4952 		if (!(ports[res->port_id].dev_conf.txmode.offloads &
4953 		      DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4954 			printf("Warning: csum set outer-ip must be set to hw "
4955 				"if outer L3 is IPv4; not necessary for IPv6\n");
4956 	}
4957 
4958 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
4959 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4960 }
4961 
4962 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4963 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4964 				tso, "tunnel_tso");
4965 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4966 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4967 				mode, "set");
4968 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4969 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4970 				tso_segsz, UINT16);
4971 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4972 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4973 				port_id, UINT16);
4974 
4975 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4976 	.f = cmd_tunnel_tso_set_parsed,
4977 	.data = NULL,
4978 	.help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4979 		"Set TSO segment size of tunneled packets for csum engine "
4980 		"(0 to disable)",
4981 	.tokens = {
4982 		(void *)&cmd_tunnel_tso_set_tso,
4983 		(void *)&cmd_tunnel_tso_set_mode,
4984 		(void *)&cmd_tunnel_tso_set_tso_segsz,
4985 		(void *)&cmd_tunnel_tso_set_portid,
4986 		NULL,
4987 	},
4988 };
4989 
4990 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4991 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4992 				mode, "show");
4993 
4994 
4995 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4996 	.f = cmd_tunnel_tso_set_parsed,
4997 	.data = NULL,
4998 	.help_str = "tunnel_tso show <port_id> "
4999 		"Show TSO segment size of tunneled packets for csum engine",
5000 	.tokens = {
5001 		(void *)&cmd_tunnel_tso_set_tso,
5002 		(void *)&cmd_tunnel_tso_show_mode,
5003 		(void *)&cmd_tunnel_tso_set_portid,
5004 		NULL,
5005 	},
5006 };
5007 
5008 /* *** SET GRO FOR A PORT *** */
5009 struct cmd_gro_enable_result {
5010 	cmdline_fixed_string_t cmd_set;
5011 	cmdline_fixed_string_t cmd_port;
5012 	cmdline_fixed_string_t cmd_keyword;
5013 	cmdline_fixed_string_t cmd_onoff;
5014 	portid_t cmd_pid;
5015 };
5016 
5017 static void
5018 cmd_gro_enable_parsed(void *parsed_result,
5019 		__rte_unused struct cmdline *cl,
5020 		__rte_unused void *data)
5021 {
5022 	struct cmd_gro_enable_result *res;
5023 
5024 	res = parsed_result;
5025 	if (!strcmp(res->cmd_keyword, "gro"))
5026 		setup_gro(res->cmd_onoff, res->cmd_pid);
5027 }
5028 
5029 cmdline_parse_token_string_t cmd_gro_enable_set =
5030 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5031 			cmd_set, "set");
5032 cmdline_parse_token_string_t cmd_gro_enable_port =
5033 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5034 			cmd_keyword, "port");
5035 cmdline_parse_token_num_t cmd_gro_enable_pid =
5036 	TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5037 			cmd_pid, UINT16);
5038 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5039 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5040 			cmd_keyword, "gro");
5041 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5042 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5043 			cmd_onoff, "on#off");
5044 
5045 cmdline_parse_inst_t cmd_gro_enable = {
5046 	.f = cmd_gro_enable_parsed,
5047 	.data = NULL,
5048 	.help_str = "set port <port_id> gro on|off",
5049 	.tokens = {
5050 		(void *)&cmd_gro_enable_set,
5051 		(void *)&cmd_gro_enable_port,
5052 		(void *)&cmd_gro_enable_pid,
5053 		(void *)&cmd_gro_enable_keyword,
5054 		(void *)&cmd_gro_enable_onoff,
5055 		NULL,
5056 	},
5057 };
5058 
5059 /* *** DISPLAY GRO CONFIGURATION *** */
5060 struct cmd_gro_show_result {
5061 	cmdline_fixed_string_t cmd_show;
5062 	cmdline_fixed_string_t cmd_port;
5063 	cmdline_fixed_string_t cmd_keyword;
5064 	portid_t cmd_pid;
5065 };
5066 
5067 static void
5068 cmd_gro_show_parsed(void *parsed_result,
5069 		__rte_unused struct cmdline *cl,
5070 		__rte_unused void *data)
5071 {
5072 	struct cmd_gro_show_result *res;
5073 
5074 	res = parsed_result;
5075 	if (!strcmp(res->cmd_keyword, "gro"))
5076 		show_gro(res->cmd_pid);
5077 }
5078 
5079 cmdline_parse_token_string_t cmd_gro_show_show =
5080 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5081 			cmd_show, "show");
5082 cmdline_parse_token_string_t cmd_gro_show_port =
5083 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5084 			cmd_port, "port");
5085 cmdline_parse_token_num_t cmd_gro_show_pid =
5086 	TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5087 			cmd_pid, UINT16);
5088 cmdline_parse_token_string_t cmd_gro_show_keyword =
5089 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5090 			cmd_keyword, "gro");
5091 
5092 cmdline_parse_inst_t cmd_gro_show = {
5093 	.f = cmd_gro_show_parsed,
5094 	.data = NULL,
5095 	.help_str = "show port <port_id> gro",
5096 	.tokens = {
5097 		(void *)&cmd_gro_show_show,
5098 		(void *)&cmd_gro_show_port,
5099 		(void *)&cmd_gro_show_pid,
5100 		(void *)&cmd_gro_show_keyword,
5101 		NULL,
5102 	},
5103 };
5104 
5105 /* *** SET FLUSH CYCLES FOR GRO *** */
5106 struct cmd_gro_flush_result {
5107 	cmdline_fixed_string_t cmd_set;
5108 	cmdline_fixed_string_t cmd_keyword;
5109 	cmdline_fixed_string_t cmd_flush;
5110 	uint8_t cmd_cycles;
5111 };
5112 
5113 static void
5114 cmd_gro_flush_parsed(void *parsed_result,
5115 		__rte_unused struct cmdline *cl,
5116 		__rte_unused void *data)
5117 {
5118 	struct cmd_gro_flush_result *res;
5119 
5120 	res = parsed_result;
5121 	if ((!strcmp(res->cmd_keyword, "gro")) &&
5122 			(!strcmp(res->cmd_flush, "flush")))
5123 		setup_gro_flush_cycles(res->cmd_cycles);
5124 }
5125 
5126 cmdline_parse_token_string_t cmd_gro_flush_set =
5127 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5128 			cmd_set, "set");
5129 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5130 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5131 			cmd_keyword, "gro");
5132 cmdline_parse_token_string_t cmd_gro_flush_flush =
5133 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5134 			cmd_flush, "flush");
5135 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5136 	TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5137 			cmd_cycles, UINT8);
5138 
5139 cmdline_parse_inst_t cmd_gro_flush = {
5140 	.f = cmd_gro_flush_parsed,
5141 	.data = NULL,
5142 	.help_str = "set gro flush <cycles>",
5143 	.tokens = {
5144 		(void *)&cmd_gro_flush_set,
5145 		(void *)&cmd_gro_flush_keyword,
5146 		(void *)&cmd_gro_flush_flush,
5147 		(void *)&cmd_gro_flush_cycles,
5148 		NULL,
5149 	},
5150 };
5151 
5152 /* *** ENABLE/DISABLE GSO *** */
5153 struct cmd_gso_enable_result {
5154 	cmdline_fixed_string_t cmd_set;
5155 	cmdline_fixed_string_t cmd_port;
5156 	cmdline_fixed_string_t cmd_keyword;
5157 	cmdline_fixed_string_t cmd_mode;
5158 	portid_t cmd_pid;
5159 };
5160 
5161 static void
5162 cmd_gso_enable_parsed(void *parsed_result,
5163 		__rte_unused struct cmdline *cl,
5164 		__rte_unused void *data)
5165 {
5166 	struct cmd_gso_enable_result *res;
5167 
5168 	res = parsed_result;
5169 	if (!strcmp(res->cmd_keyword, "gso"))
5170 		setup_gso(res->cmd_mode, res->cmd_pid);
5171 }
5172 
5173 cmdline_parse_token_string_t cmd_gso_enable_set =
5174 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5175 			cmd_set, "set");
5176 cmdline_parse_token_string_t cmd_gso_enable_port =
5177 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5178 			cmd_port, "port");
5179 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5180 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5181 			cmd_keyword, "gso");
5182 cmdline_parse_token_string_t cmd_gso_enable_mode =
5183 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5184 			cmd_mode, "on#off");
5185 cmdline_parse_token_num_t cmd_gso_enable_pid =
5186 	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5187 			cmd_pid, UINT16);
5188 
5189 cmdline_parse_inst_t cmd_gso_enable = {
5190 	.f = cmd_gso_enable_parsed,
5191 	.data = NULL,
5192 	.help_str = "set port <port_id> gso on|off",
5193 	.tokens = {
5194 		(void *)&cmd_gso_enable_set,
5195 		(void *)&cmd_gso_enable_port,
5196 		(void *)&cmd_gso_enable_pid,
5197 		(void *)&cmd_gso_enable_keyword,
5198 		(void *)&cmd_gso_enable_mode,
5199 		NULL,
5200 	},
5201 };
5202 
5203 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5204 struct cmd_gso_size_result {
5205 	cmdline_fixed_string_t cmd_set;
5206 	cmdline_fixed_string_t cmd_keyword;
5207 	cmdline_fixed_string_t cmd_segsz;
5208 	uint16_t cmd_size;
5209 };
5210 
5211 static void
5212 cmd_gso_size_parsed(void *parsed_result,
5213 		       __rte_unused struct cmdline *cl,
5214 		       __rte_unused void *data)
5215 {
5216 	struct cmd_gso_size_result *res = parsed_result;
5217 
5218 	if (test_done == 0) {
5219 		printf("Before setting GSO segsz, please first"
5220 				" stop forwarding\n");
5221 		return;
5222 	}
5223 
5224 	if (!strcmp(res->cmd_keyword, "gso") &&
5225 			!strcmp(res->cmd_segsz, "segsz")) {
5226 		if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5227 			printf("gso_size should be larger than %zu."
5228 					" Please input a legal value\n",
5229 					RTE_GSO_SEG_SIZE_MIN);
5230 		else
5231 			gso_max_segment_size = res->cmd_size;
5232 	}
5233 }
5234 
5235 cmdline_parse_token_string_t cmd_gso_size_set =
5236 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5237 				cmd_set, "set");
5238 cmdline_parse_token_string_t cmd_gso_size_keyword =
5239 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5240 				cmd_keyword, "gso");
5241 cmdline_parse_token_string_t cmd_gso_size_segsz =
5242 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5243 				cmd_segsz, "segsz");
5244 cmdline_parse_token_num_t cmd_gso_size_size =
5245 	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5246 				cmd_size, UINT16);
5247 
5248 cmdline_parse_inst_t cmd_gso_size = {
5249 	.f = cmd_gso_size_parsed,
5250 	.data = NULL,
5251 	.help_str = "set gso segsz <length>",
5252 	.tokens = {
5253 		(void *)&cmd_gso_size_set,
5254 		(void *)&cmd_gso_size_keyword,
5255 		(void *)&cmd_gso_size_segsz,
5256 		(void *)&cmd_gso_size_size,
5257 		NULL,
5258 	},
5259 };
5260 
5261 /* *** SHOW GSO CONFIGURATION *** */
5262 struct cmd_gso_show_result {
5263 	cmdline_fixed_string_t cmd_show;
5264 	cmdline_fixed_string_t cmd_port;
5265 	cmdline_fixed_string_t cmd_keyword;
5266 	portid_t cmd_pid;
5267 };
5268 
5269 static void
5270 cmd_gso_show_parsed(void *parsed_result,
5271 		       __rte_unused struct cmdline *cl,
5272 		       __rte_unused void *data)
5273 {
5274 	struct cmd_gso_show_result *res = parsed_result;
5275 
5276 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5277 		printf("invalid port id %u\n", res->cmd_pid);
5278 		return;
5279 	}
5280 	if (!strcmp(res->cmd_keyword, "gso")) {
5281 		if (gso_ports[res->cmd_pid].enable) {
5282 			printf("Max GSO'd packet size: %uB\n"
5283 					"Supported GSO types: TCP/IPv4, "
5284 					"UDP/IPv4, VxLAN with inner "
5285 					"TCP/IPv4 packet, GRE with inner "
5286 					"TCP/IPv4 packet\n",
5287 					gso_max_segment_size);
5288 		} else
5289 			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5290 	}
5291 }
5292 
5293 cmdline_parse_token_string_t cmd_gso_show_show =
5294 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5295 		cmd_show, "show");
5296 cmdline_parse_token_string_t cmd_gso_show_port =
5297 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5298 		cmd_port, "port");
5299 cmdline_parse_token_string_t cmd_gso_show_keyword =
5300 	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5301 				cmd_keyword, "gso");
5302 cmdline_parse_token_num_t cmd_gso_show_pid =
5303 	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5304 				cmd_pid, UINT16);
5305 
5306 cmdline_parse_inst_t cmd_gso_show = {
5307 	.f = cmd_gso_show_parsed,
5308 	.data = NULL,
5309 	.help_str = "show port <port_id> gso",
5310 	.tokens = {
5311 		(void *)&cmd_gso_show_show,
5312 		(void *)&cmd_gso_show_port,
5313 		(void *)&cmd_gso_show_pid,
5314 		(void *)&cmd_gso_show_keyword,
5315 		NULL,
5316 	},
5317 };
5318 
5319 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5320 struct cmd_set_flush_rx {
5321 	cmdline_fixed_string_t set;
5322 	cmdline_fixed_string_t flush_rx;
5323 	cmdline_fixed_string_t mode;
5324 };
5325 
5326 static void
5327 cmd_set_flush_rx_parsed(void *parsed_result,
5328 		__rte_unused struct cmdline *cl,
5329 		__rte_unused void *data)
5330 {
5331 	struct cmd_set_flush_rx *res = parsed_result;
5332 	no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5333 }
5334 
5335 cmdline_parse_token_string_t cmd_setflushrx_set =
5336 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5337 			set, "set");
5338 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5339 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5340 			flush_rx, "flush_rx");
5341 cmdline_parse_token_string_t cmd_setflushrx_mode =
5342 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5343 			mode, "on#off");
5344 
5345 
5346 cmdline_parse_inst_t cmd_set_flush_rx = {
5347 	.f = cmd_set_flush_rx_parsed,
5348 	.help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5349 	.data = NULL,
5350 	.tokens = {
5351 		(void *)&cmd_setflushrx_set,
5352 		(void *)&cmd_setflushrx_flush_rx,
5353 		(void *)&cmd_setflushrx_mode,
5354 		NULL,
5355 	},
5356 };
5357 
5358 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5359 struct cmd_set_link_check {
5360 	cmdline_fixed_string_t set;
5361 	cmdline_fixed_string_t link_check;
5362 	cmdline_fixed_string_t mode;
5363 };
5364 
5365 static void
5366 cmd_set_link_check_parsed(void *parsed_result,
5367 		__rte_unused struct cmdline *cl,
5368 		__rte_unused void *data)
5369 {
5370 	struct cmd_set_link_check *res = parsed_result;
5371 	no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5372 }
5373 
5374 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5375 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5376 			set, "set");
5377 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5378 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5379 			link_check, "link_check");
5380 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5381 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5382 			mode, "on#off");
5383 
5384 
5385 cmdline_parse_inst_t cmd_set_link_check = {
5386 	.f = cmd_set_link_check_parsed,
5387 	.help_str = "set link_check on|off: Enable/Disable link status check "
5388 	            "when starting/stopping a port",
5389 	.data = NULL,
5390 	.tokens = {
5391 		(void *)&cmd_setlinkcheck_set,
5392 		(void *)&cmd_setlinkcheck_link_check,
5393 		(void *)&cmd_setlinkcheck_mode,
5394 		NULL,
5395 	},
5396 };
5397 
5398 /* *** SET NIC BYPASS MODE *** */
5399 struct cmd_set_bypass_mode_result {
5400 	cmdline_fixed_string_t set;
5401 	cmdline_fixed_string_t bypass;
5402 	cmdline_fixed_string_t mode;
5403 	cmdline_fixed_string_t value;
5404 	portid_t port_id;
5405 };
5406 
5407 static void
5408 cmd_set_bypass_mode_parsed(void *parsed_result,
5409 		__rte_unused struct cmdline *cl,
5410 		__rte_unused void *data)
5411 {
5412 	struct cmd_set_bypass_mode_result *res = parsed_result;
5413 	portid_t port_id = res->port_id;
5414 	int32_t rc = -EINVAL;
5415 
5416 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5417 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5418 
5419 	if (!strcmp(res->value, "bypass"))
5420 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5421 	else if (!strcmp(res->value, "isolate"))
5422 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5423 	else
5424 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5425 
5426 	/* Set the bypass mode for the relevant port. */
5427 	rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5428 #endif
5429 	if (rc != 0)
5430 		printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5431 }
5432 
5433 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5434 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5435 			set, "set");
5436 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5437 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5438 			bypass, "bypass");
5439 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5440 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5441 			mode, "mode");
5442 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5443 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5444 			value, "normal#bypass#isolate");
5445 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5446 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5447 				port_id, UINT16);
5448 
5449 cmdline_parse_inst_t cmd_set_bypass_mode = {
5450 	.f = cmd_set_bypass_mode_parsed,
5451 	.help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5452 	            "Set the NIC bypass mode for port_id",
5453 	.data = NULL,
5454 	.tokens = {
5455 		(void *)&cmd_setbypass_mode_set,
5456 		(void *)&cmd_setbypass_mode_bypass,
5457 		(void *)&cmd_setbypass_mode_mode,
5458 		(void *)&cmd_setbypass_mode_value,
5459 		(void *)&cmd_setbypass_mode_port,
5460 		NULL,
5461 	},
5462 };
5463 
5464 /* *** SET NIC BYPASS EVENT *** */
5465 struct cmd_set_bypass_event_result {
5466 	cmdline_fixed_string_t set;
5467 	cmdline_fixed_string_t bypass;
5468 	cmdline_fixed_string_t event;
5469 	cmdline_fixed_string_t event_value;
5470 	cmdline_fixed_string_t mode;
5471 	cmdline_fixed_string_t mode_value;
5472 	portid_t port_id;
5473 };
5474 
5475 static void
5476 cmd_set_bypass_event_parsed(void *parsed_result,
5477 		__rte_unused struct cmdline *cl,
5478 		__rte_unused void *data)
5479 {
5480 	int32_t rc = -EINVAL;
5481 	struct cmd_set_bypass_event_result *res = parsed_result;
5482 	portid_t port_id = res->port_id;
5483 
5484 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5485 	uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5486 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5487 
5488 	if (!strcmp(res->event_value, "timeout"))
5489 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5490 	else if (!strcmp(res->event_value, "os_on"))
5491 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5492 	else if (!strcmp(res->event_value, "os_off"))
5493 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5494 	else if (!strcmp(res->event_value, "power_on"))
5495 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5496 	else if (!strcmp(res->event_value, "power_off"))
5497 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5498 	else
5499 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5500 
5501 	if (!strcmp(res->mode_value, "bypass"))
5502 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5503 	else if (!strcmp(res->mode_value, "isolate"))
5504 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5505 	else
5506 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5507 
5508 	/* Set the watchdog timeout. */
5509 	if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5510 
5511 		rc = -EINVAL;
5512 		if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5513 			rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5514 							   bypass_timeout);
5515 		}
5516 		if (rc != 0) {
5517 			printf("Failed to set timeout value %u "
5518 			"for port %d, errto code: %d.\n",
5519 			bypass_timeout, port_id, rc);
5520 		}
5521 	}
5522 
5523 	/* Set the bypass event to transition to bypass mode. */
5524 	rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5525 					      bypass_mode);
5526 #endif
5527 
5528 	if (rc != 0)
5529 		printf("\t Failed to set bypass event for port = %d.\n",
5530 		       port_id);
5531 }
5532 
5533 cmdline_parse_token_string_t cmd_setbypass_event_set =
5534 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5535 			set, "set");
5536 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5537 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5538 			bypass, "bypass");
5539 cmdline_parse_token_string_t cmd_setbypass_event_event =
5540 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5541 			event, "event");
5542 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5543 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5544 			event_value, "none#timeout#os_off#os_on#power_on#power_off");
5545 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5546 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5547 			mode, "mode");
5548 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5549 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5550 			mode_value, "normal#bypass#isolate");
5551 cmdline_parse_token_num_t cmd_setbypass_event_port =
5552 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5553 				port_id, UINT16);
5554 
5555 cmdline_parse_inst_t cmd_set_bypass_event = {
5556 	.f = cmd_set_bypass_event_parsed,
5557 	.help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5558 		"power_off mode normal|bypass|isolate <port_id>: "
5559 		"Set the NIC bypass event mode for port_id",
5560 	.data = NULL,
5561 	.tokens = {
5562 		(void *)&cmd_setbypass_event_set,
5563 		(void *)&cmd_setbypass_event_bypass,
5564 		(void *)&cmd_setbypass_event_event,
5565 		(void *)&cmd_setbypass_event_event_value,
5566 		(void *)&cmd_setbypass_event_mode,
5567 		(void *)&cmd_setbypass_event_mode_value,
5568 		(void *)&cmd_setbypass_event_port,
5569 		NULL,
5570 	},
5571 };
5572 
5573 
5574 /* *** SET NIC BYPASS TIMEOUT *** */
5575 struct cmd_set_bypass_timeout_result {
5576 	cmdline_fixed_string_t set;
5577 	cmdline_fixed_string_t bypass;
5578 	cmdline_fixed_string_t timeout;
5579 	cmdline_fixed_string_t value;
5580 };
5581 
5582 static void
5583 cmd_set_bypass_timeout_parsed(void *parsed_result,
5584 		__rte_unused struct cmdline *cl,
5585 		__rte_unused void *data)
5586 {
5587 	__rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5588 
5589 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5590 	if (!strcmp(res->value, "1.5"))
5591 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5592 	else if (!strcmp(res->value, "2"))
5593 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5594 	else if (!strcmp(res->value, "3"))
5595 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5596 	else if (!strcmp(res->value, "4"))
5597 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5598 	else if (!strcmp(res->value, "8"))
5599 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5600 	else if (!strcmp(res->value, "16"))
5601 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5602 	else if (!strcmp(res->value, "32"))
5603 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5604 	else
5605 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5606 #endif
5607 }
5608 
5609 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5610 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5611 			set, "set");
5612 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5613 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5614 			bypass, "bypass");
5615 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5616 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5617 			timeout, "timeout");
5618 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5619 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5620 			value, "0#1.5#2#3#4#8#16#32");
5621 
5622 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5623 	.f = cmd_set_bypass_timeout_parsed,
5624 	.help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5625 		"Set the NIC bypass watchdog timeout in seconds",
5626 	.data = NULL,
5627 	.tokens = {
5628 		(void *)&cmd_setbypass_timeout_set,
5629 		(void *)&cmd_setbypass_timeout_bypass,
5630 		(void *)&cmd_setbypass_timeout_timeout,
5631 		(void *)&cmd_setbypass_timeout_value,
5632 		NULL,
5633 	},
5634 };
5635 
5636 /* *** SHOW NIC BYPASS MODE *** */
5637 struct cmd_show_bypass_config_result {
5638 	cmdline_fixed_string_t show;
5639 	cmdline_fixed_string_t bypass;
5640 	cmdline_fixed_string_t config;
5641 	portid_t port_id;
5642 };
5643 
5644 static void
5645 cmd_show_bypass_config_parsed(void *parsed_result,
5646 		__rte_unused struct cmdline *cl,
5647 		__rte_unused void *data)
5648 {
5649 	struct cmd_show_bypass_config_result *res = parsed_result;
5650 	portid_t port_id = res->port_id;
5651 	int rc = -EINVAL;
5652 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5653 	uint32_t event_mode;
5654 	uint32_t bypass_mode;
5655 	uint32_t timeout = bypass_timeout;
5656 	unsigned int i;
5657 
5658 	static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5659 		{"off", "1.5", "2", "3", "4", "8", "16", "32"};
5660 	static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5661 		{"UNKNOWN", "normal", "bypass", "isolate"};
5662 	static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5663 		"NONE",
5664 		"OS/board on",
5665 		"power supply on",
5666 		"OS/board off",
5667 		"power supply off",
5668 		"timeout"};
5669 
5670 	/* Display the bypass mode.*/
5671 	if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5672 		printf("\tFailed to get bypass mode for port = %d\n", port_id);
5673 		return;
5674 	}
5675 	else {
5676 		if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5677 			bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5678 
5679 		printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5680 	}
5681 
5682 	/* Display the bypass timeout.*/
5683 	if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5684 		timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5685 
5686 	printf("\tbypass timeout = %s\n", timeouts[timeout]);
5687 
5688 	/* Display the bypass events and associated modes. */
5689 	for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5690 
5691 		if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5692 			printf("\tFailed to get bypass mode for event = %s\n",
5693 				events[i]);
5694 		} else {
5695 			if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5696 				event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5697 
5698 			printf("\tbypass event: %-16s = %s\n", events[i],
5699 				modes[event_mode]);
5700 		}
5701 	}
5702 #endif
5703 	if (rc != 0)
5704 		printf("\tFailed to get bypass configuration for port = %d\n",
5705 		       port_id);
5706 }
5707 
5708 cmdline_parse_token_string_t cmd_showbypass_config_show =
5709 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5710 			show, "show");
5711 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5712 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5713 			bypass, "bypass");
5714 cmdline_parse_token_string_t cmd_showbypass_config_config =
5715 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5716 			config, "config");
5717 cmdline_parse_token_num_t cmd_showbypass_config_port =
5718 	TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5719 				port_id, UINT16);
5720 
5721 cmdline_parse_inst_t cmd_show_bypass_config = {
5722 	.f = cmd_show_bypass_config_parsed,
5723 	.help_str = "show bypass config <port_id>: "
5724 	            "Show the NIC bypass config for port_id",
5725 	.data = NULL,
5726 	.tokens = {
5727 		(void *)&cmd_showbypass_config_show,
5728 		(void *)&cmd_showbypass_config_bypass,
5729 		(void *)&cmd_showbypass_config_config,
5730 		(void *)&cmd_showbypass_config_port,
5731 		NULL,
5732 	},
5733 };
5734 
5735 #ifdef RTE_LIBRTE_PMD_BOND
5736 /* *** SET BONDING MODE *** */
5737 struct cmd_set_bonding_mode_result {
5738 	cmdline_fixed_string_t set;
5739 	cmdline_fixed_string_t bonding;
5740 	cmdline_fixed_string_t mode;
5741 	uint8_t value;
5742 	portid_t port_id;
5743 };
5744 
5745 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5746 		__rte_unused  struct cmdline *cl,
5747 		__rte_unused void *data)
5748 {
5749 	struct cmd_set_bonding_mode_result *res = parsed_result;
5750 	portid_t port_id = res->port_id;
5751 
5752 	/* Set the bonding mode for the relevant port. */
5753 	if (0 != rte_eth_bond_mode_set(port_id, res->value))
5754 		printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5755 }
5756 
5757 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5758 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5759 		set, "set");
5760 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5761 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5762 		bonding, "bonding");
5763 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5764 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5765 		mode, "mode");
5766 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5767 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5768 		value, UINT8);
5769 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5770 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5771 		port_id, UINT16);
5772 
5773 cmdline_parse_inst_t cmd_set_bonding_mode = {
5774 		.f = cmd_set_bonding_mode_parsed,
5775 		.help_str = "set bonding mode <mode_value> <port_id>: "
5776 			"Set the bonding mode for port_id",
5777 		.data = NULL,
5778 		.tokens = {
5779 				(void *) &cmd_setbonding_mode_set,
5780 				(void *) &cmd_setbonding_mode_bonding,
5781 				(void *) &cmd_setbonding_mode_mode,
5782 				(void *) &cmd_setbonding_mode_value,
5783 				(void *) &cmd_setbonding_mode_port,
5784 				NULL
5785 		}
5786 };
5787 
5788 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5789 struct cmd_set_bonding_lacp_dedicated_queues_result {
5790 	cmdline_fixed_string_t set;
5791 	cmdline_fixed_string_t bonding;
5792 	cmdline_fixed_string_t lacp;
5793 	cmdline_fixed_string_t dedicated_queues;
5794 	portid_t port_id;
5795 	cmdline_fixed_string_t mode;
5796 };
5797 
5798 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5799 		__rte_unused  struct cmdline *cl,
5800 		__rte_unused void *data)
5801 {
5802 	struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5803 	portid_t port_id = res->port_id;
5804 	struct rte_port *port;
5805 
5806 	port = &ports[port_id];
5807 
5808 	/** Check if the port is not started **/
5809 	if (port->port_status != RTE_PORT_STOPPED) {
5810 		printf("Please stop port %d first\n", port_id);
5811 		return;
5812 	}
5813 
5814 	if (!strcmp(res->mode, "enable")) {
5815 		if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5816 			printf("Dedicate queues for LACP control packets"
5817 					" enabled\n");
5818 		else
5819 			printf("Enabling dedicate queues for LACP control "
5820 					"packets on port %d failed\n", port_id);
5821 	} else if (!strcmp(res->mode, "disable")) {
5822 		if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5823 			printf("Dedicated queues for LACP control packets "
5824 					"disabled\n");
5825 		else
5826 			printf("Disabling dedicated queues for LACP control "
5827 					"traffic on port %d failed\n", port_id);
5828 	}
5829 }
5830 
5831 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5832 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5833 		set, "set");
5834 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5835 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5836 		bonding, "bonding");
5837 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5838 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5839 		lacp, "lacp");
5840 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5841 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5842 		dedicated_queues, "dedicated_queues");
5843 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5844 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5845 		port_id, UINT16);
5846 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5847 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5848 		mode, "enable#disable");
5849 
5850 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5851 		.f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5852 		.help_str = "set bonding lacp dedicated_queues <port_id> "
5853 			"enable|disable: "
5854 			"Enable/disable dedicated queues for LACP control traffic for port_id",
5855 		.data = NULL,
5856 		.tokens = {
5857 			(void *)&cmd_setbonding_lacp_dedicated_queues_set,
5858 			(void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5859 			(void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5860 			(void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5861 			(void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5862 			(void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5863 			NULL
5864 		}
5865 };
5866 
5867 /* *** SET BALANCE XMIT POLICY *** */
5868 struct cmd_set_bonding_balance_xmit_policy_result {
5869 	cmdline_fixed_string_t set;
5870 	cmdline_fixed_string_t bonding;
5871 	cmdline_fixed_string_t balance_xmit_policy;
5872 	portid_t port_id;
5873 	cmdline_fixed_string_t policy;
5874 };
5875 
5876 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5877 		__rte_unused  struct cmdline *cl,
5878 		__rte_unused void *data)
5879 {
5880 	struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5881 	portid_t port_id = res->port_id;
5882 	uint8_t policy;
5883 
5884 	if (!strcmp(res->policy, "l2")) {
5885 		policy = BALANCE_XMIT_POLICY_LAYER2;
5886 	} else if (!strcmp(res->policy, "l23")) {
5887 		policy = BALANCE_XMIT_POLICY_LAYER23;
5888 	} else if (!strcmp(res->policy, "l34")) {
5889 		policy = BALANCE_XMIT_POLICY_LAYER34;
5890 	} else {
5891 		printf("\t Invalid xmit policy selection");
5892 		return;
5893 	}
5894 
5895 	/* Set the bonding mode for the relevant port. */
5896 	if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5897 		printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5898 				port_id);
5899 	}
5900 }
5901 
5902 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5903 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5904 		set, "set");
5905 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5906 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5907 		bonding, "bonding");
5908 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5909 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5910 		balance_xmit_policy, "balance_xmit_policy");
5911 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5912 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5913 		port_id, UINT16);
5914 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5915 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5916 		policy, "l2#l23#l34");
5917 
5918 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5919 		.f = cmd_set_bonding_balance_xmit_policy_parsed,
5920 		.help_str = "set bonding balance_xmit_policy <port_id> "
5921 			"l2|l23|l34: "
5922 			"Set the bonding balance_xmit_policy for port_id",
5923 		.data = NULL,
5924 		.tokens = {
5925 				(void *)&cmd_setbonding_balance_xmit_policy_set,
5926 				(void *)&cmd_setbonding_balance_xmit_policy_bonding,
5927 				(void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5928 				(void *)&cmd_setbonding_balance_xmit_policy_port,
5929 				(void *)&cmd_setbonding_balance_xmit_policy_policy,
5930 				NULL
5931 		}
5932 };
5933 
5934 /* *** SHOW NIC BONDING CONFIGURATION *** */
5935 struct cmd_show_bonding_config_result {
5936 	cmdline_fixed_string_t show;
5937 	cmdline_fixed_string_t bonding;
5938 	cmdline_fixed_string_t config;
5939 	portid_t port_id;
5940 };
5941 
5942 static void cmd_show_bonding_config_parsed(void *parsed_result,
5943 		__rte_unused  struct cmdline *cl,
5944 		__rte_unused void *data)
5945 {
5946 	struct cmd_show_bonding_config_result *res = parsed_result;
5947 	int bonding_mode, agg_mode;
5948 	portid_t slaves[RTE_MAX_ETHPORTS];
5949 	int num_slaves, num_active_slaves;
5950 	int primary_id;
5951 	int i;
5952 	portid_t port_id = res->port_id;
5953 
5954 	/* Display the bonding mode.*/
5955 	bonding_mode = rte_eth_bond_mode_get(port_id);
5956 	if (bonding_mode < 0) {
5957 		printf("\tFailed to get bonding mode for port = %d\n", port_id);
5958 		return;
5959 	} else
5960 		printf("\tBonding mode: %d\n", bonding_mode);
5961 
5962 	if (bonding_mode == BONDING_MODE_BALANCE) {
5963 		int balance_xmit_policy;
5964 
5965 		balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5966 		if (balance_xmit_policy < 0) {
5967 			printf("\tFailed to get balance xmit policy for port = %d\n",
5968 					port_id);
5969 			return;
5970 		} else {
5971 			printf("\tBalance Xmit Policy: ");
5972 
5973 			switch (balance_xmit_policy) {
5974 			case BALANCE_XMIT_POLICY_LAYER2:
5975 				printf("BALANCE_XMIT_POLICY_LAYER2");
5976 				break;
5977 			case BALANCE_XMIT_POLICY_LAYER23:
5978 				printf("BALANCE_XMIT_POLICY_LAYER23");
5979 				break;
5980 			case BALANCE_XMIT_POLICY_LAYER34:
5981 				printf("BALANCE_XMIT_POLICY_LAYER34");
5982 				break;
5983 			}
5984 			printf("\n");
5985 		}
5986 	}
5987 
5988 	if (bonding_mode == BONDING_MODE_8023AD) {
5989 		agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5990 		printf("\tIEEE802.3AD Aggregator Mode: ");
5991 		switch (agg_mode) {
5992 		case AGG_BANDWIDTH:
5993 			printf("bandwidth");
5994 			break;
5995 		case AGG_STABLE:
5996 			printf("stable");
5997 			break;
5998 		case AGG_COUNT:
5999 			printf("count");
6000 			break;
6001 		}
6002 		printf("\n");
6003 	}
6004 
6005 	num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6006 
6007 	if (num_slaves < 0) {
6008 		printf("\tFailed to get slave list for port = %d\n", port_id);
6009 		return;
6010 	}
6011 	if (num_slaves > 0) {
6012 		printf("\tSlaves (%d): [", num_slaves);
6013 		for (i = 0; i < num_slaves - 1; i++)
6014 			printf("%d ", slaves[i]);
6015 
6016 		printf("%d]\n", slaves[num_slaves - 1]);
6017 	} else {
6018 		printf("\tSlaves: []\n");
6019 
6020 	}
6021 
6022 	num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6023 			RTE_MAX_ETHPORTS);
6024 
6025 	if (num_active_slaves < 0) {
6026 		printf("\tFailed to get active slave list for port = %d\n", port_id);
6027 		return;
6028 	}
6029 	if (num_active_slaves > 0) {
6030 		printf("\tActive Slaves (%d): [", num_active_slaves);
6031 		for (i = 0; i < num_active_slaves - 1; i++)
6032 			printf("%d ", slaves[i]);
6033 
6034 		printf("%d]\n", slaves[num_active_slaves - 1]);
6035 
6036 	} else {
6037 		printf("\tActive Slaves: []\n");
6038 
6039 	}
6040 
6041 	primary_id = rte_eth_bond_primary_get(port_id);
6042 	if (primary_id < 0) {
6043 		printf("\tFailed to get primary slave for port = %d\n", port_id);
6044 		return;
6045 	} else
6046 		printf("\tPrimary: [%d]\n", primary_id);
6047 
6048 }
6049 
6050 cmdline_parse_token_string_t cmd_showbonding_config_show =
6051 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6052 		show, "show");
6053 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6054 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6055 		bonding, "bonding");
6056 cmdline_parse_token_string_t cmd_showbonding_config_config =
6057 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6058 		config, "config");
6059 cmdline_parse_token_num_t cmd_showbonding_config_port =
6060 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6061 		port_id, UINT16);
6062 
6063 cmdline_parse_inst_t cmd_show_bonding_config = {
6064 		.f = cmd_show_bonding_config_parsed,
6065 		.help_str = "show bonding config <port_id>: "
6066 			"Show the bonding config for port_id",
6067 		.data = NULL,
6068 		.tokens = {
6069 				(void *)&cmd_showbonding_config_show,
6070 				(void *)&cmd_showbonding_config_bonding,
6071 				(void *)&cmd_showbonding_config_config,
6072 				(void *)&cmd_showbonding_config_port,
6073 				NULL
6074 		}
6075 };
6076 
6077 /* *** SET BONDING PRIMARY *** */
6078 struct cmd_set_bonding_primary_result {
6079 	cmdline_fixed_string_t set;
6080 	cmdline_fixed_string_t bonding;
6081 	cmdline_fixed_string_t primary;
6082 	portid_t slave_id;
6083 	portid_t port_id;
6084 };
6085 
6086 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6087 		__rte_unused  struct cmdline *cl,
6088 		__rte_unused void *data)
6089 {
6090 	struct cmd_set_bonding_primary_result *res = parsed_result;
6091 	portid_t master_port_id = res->port_id;
6092 	portid_t slave_port_id = res->slave_id;
6093 
6094 	/* Set the primary slave for a bonded device. */
6095 	if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6096 		printf("\t Failed to set primary slave for port = %d.\n",
6097 				master_port_id);
6098 		return;
6099 	}
6100 	init_port_config();
6101 }
6102 
6103 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6104 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6105 		set, "set");
6106 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6107 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6108 		bonding, "bonding");
6109 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6110 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6111 		primary, "primary");
6112 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6113 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6114 		slave_id, UINT16);
6115 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6116 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6117 		port_id, UINT16);
6118 
6119 cmdline_parse_inst_t cmd_set_bonding_primary = {
6120 		.f = cmd_set_bonding_primary_parsed,
6121 		.help_str = "set bonding primary <slave_id> <port_id>: "
6122 			"Set the primary slave for port_id",
6123 		.data = NULL,
6124 		.tokens = {
6125 				(void *)&cmd_setbonding_primary_set,
6126 				(void *)&cmd_setbonding_primary_bonding,
6127 				(void *)&cmd_setbonding_primary_primary,
6128 				(void *)&cmd_setbonding_primary_slave,
6129 				(void *)&cmd_setbonding_primary_port,
6130 				NULL
6131 		}
6132 };
6133 
6134 /* *** ADD SLAVE *** */
6135 struct cmd_add_bonding_slave_result {
6136 	cmdline_fixed_string_t add;
6137 	cmdline_fixed_string_t bonding;
6138 	cmdline_fixed_string_t slave;
6139 	portid_t slave_id;
6140 	portid_t port_id;
6141 };
6142 
6143 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6144 		__rte_unused  struct cmdline *cl,
6145 		__rte_unused void *data)
6146 {
6147 	struct cmd_add_bonding_slave_result *res = parsed_result;
6148 	portid_t master_port_id = res->port_id;
6149 	portid_t slave_port_id = res->slave_id;
6150 
6151 	/* add the slave for a bonded device. */
6152 	if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6153 		printf("\t Failed to add slave %d to master port = %d.\n",
6154 				slave_port_id, master_port_id);
6155 		return;
6156 	}
6157 	init_port_config();
6158 	set_port_slave_flag(slave_port_id);
6159 }
6160 
6161 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6162 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6163 		add, "add");
6164 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6165 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6166 		bonding, "bonding");
6167 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6168 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6169 		slave, "slave");
6170 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6171 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6172 		slave_id, UINT16);
6173 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6174 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6175 		port_id, UINT16);
6176 
6177 cmdline_parse_inst_t cmd_add_bonding_slave = {
6178 		.f = cmd_add_bonding_slave_parsed,
6179 		.help_str = "add bonding slave <slave_id> <port_id>: "
6180 			"Add a slave device to a bonded device",
6181 		.data = NULL,
6182 		.tokens = {
6183 				(void *)&cmd_addbonding_slave_add,
6184 				(void *)&cmd_addbonding_slave_bonding,
6185 				(void *)&cmd_addbonding_slave_slave,
6186 				(void *)&cmd_addbonding_slave_slaveid,
6187 				(void *)&cmd_addbonding_slave_port,
6188 				NULL
6189 		}
6190 };
6191 
6192 /* *** REMOVE SLAVE *** */
6193 struct cmd_remove_bonding_slave_result {
6194 	cmdline_fixed_string_t remove;
6195 	cmdline_fixed_string_t bonding;
6196 	cmdline_fixed_string_t slave;
6197 	portid_t slave_id;
6198 	portid_t port_id;
6199 };
6200 
6201 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6202 		__rte_unused  struct cmdline *cl,
6203 		__rte_unused void *data)
6204 {
6205 	struct cmd_remove_bonding_slave_result *res = parsed_result;
6206 	portid_t master_port_id = res->port_id;
6207 	portid_t slave_port_id = res->slave_id;
6208 
6209 	/* remove the slave from a bonded device. */
6210 	if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6211 		printf("\t Failed to remove slave %d from master port = %d.\n",
6212 				slave_port_id, master_port_id);
6213 		return;
6214 	}
6215 	init_port_config();
6216 	clear_port_slave_flag(slave_port_id);
6217 }
6218 
6219 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6220 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6221 				remove, "remove");
6222 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6223 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6224 				bonding, "bonding");
6225 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6226 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6227 				slave, "slave");
6228 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6229 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6230 				slave_id, UINT16);
6231 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6232 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6233 				port_id, UINT16);
6234 
6235 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6236 		.f = cmd_remove_bonding_slave_parsed,
6237 		.help_str = "remove bonding slave <slave_id> <port_id>: "
6238 			"Remove a slave device from a bonded device",
6239 		.data = NULL,
6240 		.tokens = {
6241 				(void *)&cmd_removebonding_slave_remove,
6242 				(void *)&cmd_removebonding_slave_bonding,
6243 				(void *)&cmd_removebonding_slave_slave,
6244 				(void *)&cmd_removebonding_slave_slaveid,
6245 				(void *)&cmd_removebonding_slave_port,
6246 				NULL
6247 		}
6248 };
6249 
6250 /* *** CREATE BONDED DEVICE *** */
6251 struct cmd_create_bonded_device_result {
6252 	cmdline_fixed_string_t create;
6253 	cmdline_fixed_string_t bonded;
6254 	cmdline_fixed_string_t device;
6255 	uint8_t mode;
6256 	uint8_t socket;
6257 };
6258 
6259 static int bond_dev_num = 0;
6260 
6261 static void cmd_create_bonded_device_parsed(void *parsed_result,
6262 		__rte_unused  struct cmdline *cl,
6263 		__rte_unused void *data)
6264 {
6265 	struct cmd_create_bonded_device_result *res = parsed_result;
6266 	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6267 	int port_id;
6268 	int ret;
6269 
6270 	if (test_done == 0) {
6271 		printf("Please stop forwarding first\n");
6272 		return;
6273 	}
6274 
6275 	snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6276 			bond_dev_num++);
6277 
6278 	/* Create a new bonded device. */
6279 	port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6280 	if (port_id < 0) {
6281 		printf("\t Failed to create bonded device.\n");
6282 		return;
6283 	} else {
6284 		printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6285 				port_id);
6286 
6287 		/* Update number of ports */
6288 		nb_ports = rte_eth_dev_count_avail();
6289 		reconfig(port_id, res->socket);
6290 		ret = rte_eth_promiscuous_enable(port_id);
6291 		if (ret != 0)
6292 			printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6293 				port_id, rte_strerror(-ret));
6294 
6295 		ports[port_id].need_setup = 0;
6296 		ports[port_id].port_status = RTE_PORT_STOPPED;
6297 	}
6298 
6299 }
6300 
6301 cmdline_parse_token_string_t cmd_createbonded_device_create =
6302 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6303 				create, "create");
6304 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6305 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6306 				bonded, "bonded");
6307 cmdline_parse_token_string_t cmd_createbonded_device_device =
6308 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6309 				device, "device");
6310 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6311 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6312 				mode, UINT8);
6313 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6314 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6315 				socket, UINT8);
6316 
6317 cmdline_parse_inst_t cmd_create_bonded_device = {
6318 		.f = cmd_create_bonded_device_parsed,
6319 		.help_str = "create bonded device <mode> <socket>: "
6320 			"Create a new bonded device with specific bonding mode and socket",
6321 		.data = NULL,
6322 		.tokens = {
6323 				(void *)&cmd_createbonded_device_create,
6324 				(void *)&cmd_createbonded_device_bonded,
6325 				(void *)&cmd_createbonded_device_device,
6326 				(void *)&cmd_createbonded_device_mode,
6327 				(void *)&cmd_createbonded_device_socket,
6328 				NULL
6329 		}
6330 };
6331 
6332 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6333 struct cmd_set_bond_mac_addr_result {
6334 	cmdline_fixed_string_t set;
6335 	cmdline_fixed_string_t bonding;
6336 	cmdline_fixed_string_t mac_addr;
6337 	uint16_t port_num;
6338 	struct rte_ether_addr address;
6339 };
6340 
6341 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6342 		__rte_unused  struct cmdline *cl,
6343 		__rte_unused void *data)
6344 {
6345 	struct cmd_set_bond_mac_addr_result *res = parsed_result;
6346 	int ret;
6347 
6348 	if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6349 		return;
6350 
6351 	ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6352 
6353 	/* check the return value and print it if is < 0 */
6354 	if (ret < 0)
6355 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6356 }
6357 
6358 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6359 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6360 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6361 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6362 				"bonding");
6363 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6364 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6365 				"mac_addr");
6366 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6367 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6368 				port_num, UINT16);
6369 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6370 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6371 
6372 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6373 		.f = cmd_set_bond_mac_addr_parsed,
6374 		.data = (void *) 0,
6375 		.help_str = "set bonding mac_addr <port_id> <mac_addr>",
6376 		.tokens = {
6377 				(void *)&cmd_set_bond_mac_addr_set,
6378 				(void *)&cmd_set_bond_mac_addr_bonding,
6379 				(void *)&cmd_set_bond_mac_addr_mac,
6380 				(void *)&cmd_set_bond_mac_addr_portnum,
6381 				(void *)&cmd_set_bond_mac_addr_addr,
6382 				NULL
6383 		}
6384 };
6385 
6386 
6387 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6388 struct cmd_set_bond_mon_period_result {
6389 	cmdline_fixed_string_t set;
6390 	cmdline_fixed_string_t bonding;
6391 	cmdline_fixed_string_t mon_period;
6392 	uint16_t port_num;
6393 	uint32_t period_ms;
6394 };
6395 
6396 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6397 		__rte_unused  struct cmdline *cl,
6398 		__rte_unused void *data)
6399 {
6400 	struct cmd_set_bond_mon_period_result *res = parsed_result;
6401 	int ret;
6402 
6403 	ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6404 
6405 	/* check the return value and print it if is < 0 */
6406 	if (ret < 0)
6407 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6408 }
6409 
6410 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6411 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6412 				set, "set");
6413 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6414 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6415 				bonding, "bonding");
6416 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6417 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6418 				mon_period,	"mon_period");
6419 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6420 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6421 				port_num, UINT16);
6422 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6423 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6424 				period_ms, UINT32);
6425 
6426 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6427 		.f = cmd_set_bond_mon_period_parsed,
6428 		.data = (void *) 0,
6429 		.help_str = "set bonding mon_period <port_id> <period_ms>",
6430 		.tokens = {
6431 				(void *)&cmd_set_bond_mon_period_set,
6432 				(void *)&cmd_set_bond_mon_period_bonding,
6433 				(void *)&cmd_set_bond_mon_period_mon_period,
6434 				(void *)&cmd_set_bond_mon_period_portnum,
6435 				(void *)&cmd_set_bond_mon_period_period_ms,
6436 				NULL
6437 		}
6438 };
6439 
6440 
6441 
6442 struct cmd_set_bonding_agg_mode_policy_result {
6443 	cmdline_fixed_string_t set;
6444 	cmdline_fixed_string_t bonding;
6445 	cmdline_fixed_string_t agg_mode;
6446 	uint16_t port_num;
6447 	cmdline_fixed_string_t policy;
6448 };
6449 
6450 
6451 static void
6452 cmd_set_bonding_agg_mode(void *parsed_result,
6453 		__rte_unused struct cmdline *cl,
6454 		__rte_unused void *data)
6455 {
6456 	struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6457 	uint8_t policy = AGG_BANDWIDTH;
6458 
6459 	if (!strcmp(res->policy, "bandwidth"))
6460 		policy = AGG_BANDWIDTH;
6461 	else if (!strcmp(res->policy, "stable"))
6462 		policy = AGG_STABLE;
6463 	else if (!strcmp(res->policy, "count"))
6464 		policy = AGG_COUNT;
6465 
6466 	rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6467 }
6468 
6469 
6470 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6471 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6472 				set, "set");
6473 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6474 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6475 				bonding, "bonding");
6476 
6477 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6478 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6479 				agg_mode, "agg_mode");
6480 
6481 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6482 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6483 				port_num, UINT16);
6484 
6485 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6486 	TOKEN_STRING_INITIALIZER(
6487 			struct cmd_set_bonding_balance_xmit_policy_result,
6488 		policy, "stable#bandwidth#count");
6489 
6490 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6491 	.f = cmd_set_bonding_agg_mode,
6492 	.data = (void *) 0,
6493 	.help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6494 	.tokens = {
6495 			(void *)&cmd_set_bonding_agg_mode_set,
6496 			(void *)&cmd_set_bonding_agg_mode_bonding,
6497 			(void *)&cmd_set_bonding_agg_mode_agg_mode,
6498 			(void *)&cmd_set_bonding_agg_mode_portnum,
6499 			(void *)&cmd_set_bonding_agg_mode_policy_string,
6500 			NULL
6501 		}
6502 };
6503 
6504 
6505 #endif /* RTE_LIBRTE_PMD_BOND */
6506 
6507 /* *** SET FORWARDING MODE *** */
6508 struct cmd_set_fwd_mode_result {
6509 	cmdline_fixed_string_t set;
6510 	cmdline_fixed_string_t fwd;
6511 	cmdline_fixed_string_t mode;
6512 };
6513 
6514 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6515 				    __rte_unused struct cmdline *cl,
6516 				    __rte_unused void *data)
6517 {
6518 	struct cmd_set_fwd_mode_result *res = parsed_result;
6519 
6520 	retry_enabled = 0;
6521 	set_pkt_forwarding_mode(res->mode);
6522 }
6523 
6524 cmdline_parse_token_string_t cmd_setfwd_set =
6525 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6526 cmdline_parse_token_string_t cmd_setfwd_fwd =
6527 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6528 cmdline_parse_token_string_t cmd_setfwd_mode =
6529 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6530 		"" /* defined at init */);
6531 
6532 cmdline_parse_inst_t cmd_set_fwd_mode = {
6533 	.f = cmd_set_fwd_mode_parsed,
6534 	.data = NULL,
6535 	.help_str = NULL, /* defined at init */
6536 	.tokens = {
6537 		(void *)&cmd_setfwd_set,
6538 		(void *)&cmd_setfwd_fwd,
6539 		(void *)&cmd_setfwd_mode,
6540 		NULL,
6541 	},
6542 };
6543 
6544 static void cmd_set_fwd_mode_init(void)
6545 {
6546 	char *modes, *c;
6547 	static char token[128];
6548 	static char help[256];
6549 	cmdline_parse_token_string_t *token_struct;
6550 
6551 	modes = list_pkt_forwarding_modes();
6552 	snprintf(help, sizeof(help), "set fwd %s: "
6553 		"Set packet forwarding mode", modes);
6554 	cmd_set_fwd_mode.help_str = help;
6555 
6556 	/* string token separator is # */
6557 	for (c = token; *modes != '\0'; modes++)
6558 		if (*modes == '|')
6559 			*c++ = '#';
6560 		else
6561 			*c++ = *modes;
6562 	token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6563 	token_struct->string_data.str = token;
6564 }
6565 
6566 /* *** SET RETRY FORWARDING MODE *** */
6567 struct cmd_set_fwd_retry_mode_result {
6568 	cmdline_fixed_string_t set;
6569 	cmdline_fixed_string_t fwd;
6570 	cmdline_fixed_string_t mode;
6571 	cmdline_fixed_string_t retry;
6572 };
6573 
6574 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6575 			    __rte_unused struct cmdline *cl,
6576 			    __rte_unused void *data)
6577 {
6578 	struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6579 
6580 	retry_enabled = 1;
6581 	set_pkt_forwarding_mode(res->mode);
6582 }
6583 
6584 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6585 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6586 			set, "set");
6587 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6588 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6589 			fwd, "fwd");
6590 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6591 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6592 			mode,
6593 		"" /* defined at init */);
6594 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6595 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6596 			retry, "retry");
6597 
6598 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6599 	.f = cmd_set_fwd_retry_mode_parsed,
6600 	.data = NULL,
6601 	.help_str = NULL, /* defined at init */
6602 	.tokens = {
6603 		(void *)&cmd_setfwd_retry_set,
6604 		(void *)&cmd_setfwd_retry_fwd,
6605 		(void *)&cmd_setfwd_retry_mode,
6606 		(void *)&cmd_setfwd_retry_retry,
6607 		NULL,
6608 	},
6609 };
6610 
6611 static void cmd_set_fwd_retry_mode_init(void)
6612 {
6613 	char *modes, *c;
6614 	static char token[128];
6615 	static char help[256];
6616 	cmdline_parse_token_string_t *token_struct;
6617 
6618 	modes = list_pkt_forwarding_retry_modes();
6619 	snprintf(help, sizeof(help), "set fwd %s retry: "
6620 		"Set packet forwarding mode with retry", modes);
6621 	cmd_set_fwd_retry_mode.help_str = help;
6622 
6623 	/* string token separator is # */
6624 	for (c = token; *modes != '\0'; modes++)
6625 		if (*modes == '|')
6626 			*c++ = '#';
6627 		else
6628 			*c++ = *modes;
6629 	token_struct = (cmdline_parse_token_string_t *)
6630 		cmd_set_fwd_retry_mode.tokens[2];
6631 	token_struct->string_data.str = token;
6632 }
6633 
6634 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6635 struct cmd_set_burst_tx_retry_result {
6636 	cmdline_fixed_string_t set;
6637 	cmdline_fixed_string_t burst;
6638 	cmdline_fixed_string_t tx;
6639 	cmdline_fixed_string_t delay;
6640 	uint32_t time;
6641 	cmdline_fixed_string_t retry;
6642 	uint32_t retry_num;
6643 };
6644 
6645 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6646 					__rte_unused struct cmdline *cl,
6647 					__rte_unused void *data)
6648 {
6649 	struct cmd_set_burst_tx_retry_result *res = parsed_result;
6650 
6651 	if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6652 		&& !strcmp(res->tx, "tx")) {
6653 		if (!strcmp(res->delay, "delay"))
6654 			burst_tx_delay_time = res->time;
6655 		if (!strcmp(res->retry, "retry"))
6656 			burst_tx_retry_num = res->retry_num;
6657 	}
6658 
6659 }
6660 
6661 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6662 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6663 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6664 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6665 				 "burst");
6666 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6667 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6668 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6669 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6670 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6671 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6672 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6673 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6674 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6675 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6676 
6677 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6678 	.f = cmd_set_burst_tx_retry_parsed,
6679 	.help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6680 	.tokens = {
6681 		(void *)&cmd_set_burst_tx_retry_set,
6682 		(void *)&cmd_set_burst_tx_retry_burst,
6683 		(void *)&cmd_set_burst_tx_retry_tx,
6684 		(void *)&cmd_set_burst_tx_retry_delay,
6685 		(void *)&cmd_set_burst_tx_retry_time,
6686 		(void *)&cmd_set_burst_tx_retry_retry,
6687 		(void *)&cmd_set_burst_tx_retry_retry_num,
6688 		NULL,
6689 	},
6690 };
6691 
6692 /* *** SET PROMISC MODE *** */
6693 struct cmd_set_promisc_mode_result {
6694 	cmdline_fixed_string_t set;
6695 	cmdline_fixed_string_t promisc;
6696 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6697 	uint16_t port_num;               /* valid if "allports" argument == 0 */
6698 	cmdline_fixed_string_t mode;
6699 };
6700 
6701 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6702 					__rte_unused struct cmdline *cl,
6703 					void *allports)
6704 {
6705 	struct cmd_set_promisc_mode_result *res = parsed_result;
6706 	int enable;
6707 	portid_t i;
6708 
6709 	if (!strcmp(res->mode, "on"))
6710 		enable = 1;
6711 	else
6712 		enable = 0;
6713 
6714 	/* all ports */
6715 	if (allports) {
6716 		RTE_ETH_FOREACH_DEV(i)
6717 			eth_set_promisc_mode(i, enable);
6718 	} else {
6719 		eth_set_promisc_mode(res->port_num, enable);
6720 	}
6721 }
6722 
6723 cmdline_parse_token_string_t cmd_setpromisc_set =
6724 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6725 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6726 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6727 				 "promisc");
6728 cmdline_parse_token_string_t cmd_setpromisc_portall =
6729 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6730 				 "all");
6731 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6732 	TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6733 			      UINT16);
6734 cmdline_parse_token_string_t cmd_setpromisc_mode =
6735 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6736 				 "on#off");
6737 
6738 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6739 	.f = cmd_set_promisc_mode_parsed,
6740 	.data = (void *)1,
6741 	.help_str = "set promisc all on|off: Set promisc mode for all ports",
6742 	.tokens = {
6743 		(void *)&cmd_setpromisc_set,
6744 		(void *)&cmd_setpromisc_promisc,
6745 		(void *)&cmd_setpromisc_portall,
6746 		(void *)&cmd_setpromisc_mode,
6747 		NULL,
6748 	},
6749 };
6750 
6751 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6752 	.f = cmd_set_promisc_mode_parsed,
6753 	.data = (void *)0,
6754 	.help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6755 	.tokens = {
6756 		(void *)&cmd_setpromisc_set,
6757 		(void *)&cmd_setpromisc_promisc,
6758 		(void *)&cmd_setpromisc_portnum,
6759 		(void *)&cmd_setpromisc_mode,
6760 		NULL,
6761 	},
6762 };
6763 
6764 /* *** SET ALLMULTI MODE *** */
6765 struct cmd_set_allmulti_mode_result {
6766 	cmdline_fixed_string_t set;
6767 	cmdline_fixed_string_t allmulti;
6768 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6769 	uint16_t port_num;               /* valid if "allports" argument == 0 */
6770 	cmdline_fixed_string_t mode;
6771 };
6772 
6773 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6774 					__rte_unused struct cmdline *cl,
6775 					void *allports)
6776 {
6777 	struct cmd_set_allmulti_mode_result *res = parsed_result;
6778 	int enable;
6779 	portid_t i;
6780 
6781 	if (!strcmp(res->mode, "on"))
6782 		enable = 1;
6783 	else
6784 		enable = 0;
6785 
6786 	/* all ports */
6787 	if (allports) {
6788 		RTE_ETH_FOREACH_DEV(i) {
6789 			eth_set_allmulticast_mode(i, enable);
6790 		}
6791 	}
6792 	else {
6793 		eth_set_allmulticast_mode(res->port_num, enable);
6794 	}
6795 }
6796 
6797 cmdline_parse_token_string_t cmd_setallmulti_set =
6798 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6799 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6800 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6801 				 "allmulti");
6802 cmdline_parse_token_string_t cmd_setallmulti_portall =
6803 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6804 				 "all");
6805 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6806 	TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6807 			      UINT16);
6808 cmdline_parse_token_string_t cmd_setallmulti_mode =
6809 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6810 				 "on#off");
6811 
6812 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6813 	.f = cmd_set_allmulti_mode_parsed,
6814 	.data = (void *)1,
6815 	.help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6816 	.tokens = {
6817 		(void *)&cmd_setallmulti_set,
6818 		(void *)&cmd_setallmulti_allmulti,
6819 		(void *)&cmd_setallmulti_portall,
6820 		(void *)&cmd_setallmulti_mode,
6821 		NULL,
6822 	},
6823 };
6824 
6825 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6826 	.f = cmd_set_allmulti_mode_parsed,
6827 	.data = (void *)0,
6828 	.help_str = "set allmulti <port_id> on|off: "
6829 		"Set allmulti mode on port_id",
6830 	.tokens = {
6831 		(void *)&cmd_setallmulti_set,
6832 		(void *)&cmd_setallmulti_allmulti,
6833 		(void *)&cmd_setallmulti_portnum,
6834 		(void *)&cmd_setallmulti_mode,
6835 		NULL,
6836 	},
6837 };
6838 
6839 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6840 struct cmd_link_flow_ctrl_set_result {
6841 	cmdline_fixed_string_t set;
6842 	cmdline_fixed_string_t flow_ctrl;
6843 	cmdline_fixed_string_t rx;
6844 	cmdline_fixed_string_t rx_lfc_mode;
6845 	cmdline_fixed_string_t tx;
6846 	cmdline_fixed_string_t tx_lfc_mode;
6847 	cmdline_fixed_string_t mac_ctrl_frame_fwd;
6848 	cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6849 	cmdline_fixed_string_t autoneg_str;
6850 	cmdline_fixed_string_t autoneg;
6851 	cmdline_fixed_string_t hw_str;
6852 	uint32_t high_water;
6853 	cmdline_fixed_string_t lw_str;
6854 	uint32_t low_water;
6855 	cmdline_fixed_string_t pt_str;
6856 	uint16_t pause_time;
6857 	cmdline_fixed_string_t xon_str;
6858 	uint16_t send_xon;
6859 	portid_t port_id;
6860 };
6861 
6862 cmdline_parse_token_string_t cmd_lfc_set_set =
6863 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6864 				set, "set");
6865 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6866 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6867 				flow_ctrl, "flow_ctrl");
6868 cmdline_parse_token_string_t cmd_lfc_set_rx =
6869 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6870 				rx, "rx");
6871 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6872 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6873 				rx_lfc_mode, "on#off");
6874 cmdline_parse_token_string_t cmd_lfc_set_tx =
6875 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6876 				tx, "tx");
6877 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6878 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6879 				tx_lfc_mode, "on#off");
6880 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6881 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6882 				hw_str, "high_water");
6883 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6884 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6885 				high_water, UINT32);
6886 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6887 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6888 				lw_str, "low_water");
6889 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6890 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6891 				low_water, UINT32);
6892 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6893 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6894 				pt_str, "pause_time");
6895 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6896 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6897 				pause_time, UINT16);
6898 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6899 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6900 				xon_str, "send_xon");
6901 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6902 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6903 				send_xon, UINT16);
6904 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6905 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6906 				mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6907 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6908 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6909 				mac_ctrl_frame_fwd_mode, "on#off");
6910 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6911 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6912 				autoneg_str, "autoneg");
6913 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6914 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6915 				autoneg, "on#off");
6916 cmdline_parse_token_num_t cmd_lfc_set_portid =
6917 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6918 				port_id, UINT16);
6919 
6920 /* forward declaration */
6921 static void
6922 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6923 			      void *data);
6924 
6925 cmdline_parse_inst_t cmd_link_flow_control_set = {
6926 	.f = cmd_link_flow_ctrl_set_parsed,
6927 	.data = NULL,
6928 	.help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6929 		"<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6930 		"autoneg on|off <port_id>: Configure the Ethernet flow control",
6931 	.tokens = {
6932 		(void *)&cmd_lfc_set_set,
6933 		(void *)&cmd_lfc_set_flow_ctrl,
6934 		(void *)&cmd_lfc_set_rx,
6935 		(void *)&cmd_lfc_set_rx_mode,
6936 		(void *)&cmd_lfc_set_tx,
6937 		(void *)&cmd_lfc_set_tx_mode,
6938 		(void *)&cmd_lfc_set_high_water,
6939 		(void *)&cmd_lfc_set_low_water,
6940 		(void *)&cmd_lfc_set_pause_time,
6941 		(void *)&cmd_lfc_set_send_xon,
6942 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6943 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6944 		(void *)&cmd_lfc_set_autoneg_str,
6945 		(void *)&cmd_lfc_set_autoneg,
6946 		(void *)&cmd_lfc_set_portid,
6947 		NULL,
6948 	},
6949 };
6950 
6951 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6952 	.f = cmd_link_flow_ctrl_set_parsed,
6953 	.data = (void *)&cmd_link_flow_control_set_rx,
6954 	.help_str = "set flow_ctrl rx on|off <port_id>: "
6955 		"Change rx flow control parameter",
6956 	.tokens = {
6957 		(void *)&cmd_lfc_set_set,
6958 		(void *)&cmd_lfc_set_flow_ctrl,
6959 		(void *)&cmd_lfc_set_rx,
6960 		(void *)&cmd_lfc_set_rx_mode,
6961 		(void *)&cmd_lfc_set_portid,
6962 		NULL,
6963 	},
6964 };
6965 
6966 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6967 	.f = cmd_link_flow_ctrl_set_parsed,
6968 	.data = (void *)&cmd_link_flow_control_set_tx,
6969 	.help_str = "set flow_ctrl tx on|off <port_id>: "
6970 		"Change tx flow control parameter",
6971 	.tokens = {
6972 		(void *)&cmd_lfc_set_set,
6973 		(void *)&cmd_lfc_set_flow_ctrl,
6974 		(void *)&cmd_lfc_set_tx,
6975 		(void *)&cmd_lfc_set_tx_mode,
6976 		(void *)&cmd_lfc_set_portid,
6977 		NULL,
6978 	},
6979 };
6980 
6981 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6982 	.f = cmd_link_flow_ctrl_set_parsed,
6983 	.data = (void *)&cmd_link_flow_control_set_hw,
6984 	.help_str = "set flow_ctrl high_water <value> <port_id>: "
6985 		"Change high water flow control parameter",
6986 	.tokens = {
6987 		(void *)&cmd_lfc_set_set,
6988 		(void *)&cmd_lfc_set_flow_ctrl,
6989 		(void *)&cmd_lfc_set_high_water_str,
6990 		(void *)&cmd_lfc_set_high_water,
6991 		(void *)&cmd_lfc_set_portid,
6992 		NULL,
6993 	},
6994 };
6995 
6996 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6997 	.f = cmd_link_flow_ctrl_set_parsed,
6998 	.data = (void *)&cmd_link_flow_control_set_lw,
6999 	.help_str = "set flow_ctrl low_water <value> <port_id>: "
7000 		"Change low water flow control parameter",
7001 	.tokens = {
7002 		(void *)&cmd_lfc_set_set,
7003 		(void *)&cmd_lfc_set_flow_ctrl,
7004 		(void *)&cmd_lfc_set_low_water_str,
7005 		(void *)&cmd_lfc_set_low_water,
7006 		(void *)&cmd_lfc_set_portid,
7007 		NULL,
7008 	},
7009 };
7010 
7011 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7012 	.f = cmd_link_flow_ctrl_set_parsed,
7013 	.data = (void *)&cmd_link_flow_control_set_pt,
7014 	.help_str = "set flow_ctrl pause_time <value> <port_id>: "
7015 		"Change pause time flow control parameter",
7016 	.tokens = {
7017 		(void *)&cmd_lfc_set_set,
7018 		(void *)&cmd_lfc_set_flow_ctrl,
7019 		(void *)&cmd_lfc_set_pause_time_str,
7020 		(void *)&cmd_lfc_set_pause_time,
7021 		(void *)&cmd_lfc_set_portid,
7022 		NULL,
7023 	},
7024 };
7025 
7026 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7027 	.f = cmd_link_flow_ctrl_set_parsed,
7028 	.data = (void *)&cmd_link_flow_control_set_xon,
7029 	.help_str = "set flow_ctrl send_xon <value> <port_id>: "
7030 		"Change send_xon flow control parameter",
7031 	.tokens = {
7032 		(void *)&cmd_lfc_set_set,
7033 		(void *)&cmd_lfc_set_flow_ctrl,
7034 		(void *)&cmd_lfc_set_send_xon_str,
7035 		(void *)&cmd_lfc_set_send_xon,
7036 		(void *)&cmd_lfc_set_portid,
7037 		NULL,
7038 	},
7039 };
7040 
7041 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7042 	.f = cmd_link_flow_ctrl_set_parsed,
7043 	.data = (void *)&cmd_link_flow_control_set_macfwd,
7044 	.help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7045 		"Change mac ctrl fwd flow control parameter",
7046 	.tokens = {
7047 		(void *)&cmd_lfc_set_set,
7048 		(void *)&cmd_lfc_set_flow_ctrl,
7049 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7050 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7051 		(void *)&cmd_lfc_set_portid,
7052 		NULL,
7053 	},
7054 };
7055 
7056 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7057 	.f = cmd_link_flow_ctrl_set_parsed,
7058 	.data = (void *)&cmd_link_flow_control_set_autoneg,
7059 	.help_str = "set flow_ctrl autoneg on|off <port_id>: "
7060 		"Change autoneg flow control parameter",
7061 	.tokens = {
7062 		(void *)&cmd_lfc_set_set,
7063 		(void *)&cmd_lfc_set_flow_ctrl,
7064 		(void *)&cmd_lfc_set_autoneg_str,
7065 		(void *)&cmd_lfc_set_autoneg,
7066 		(void *)&cmd_lfc_set_portid,
7067 		NULL,
7068 	},
7069 };
7070 
7071 static void
7072 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7073 			      __rte_unused struct cmdline *cl,
7074 			      void *data)
7075 {
7076 	struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7077 	cmdline_parse_inst_t *cmd = data;
7078 	struct rte_eth_fc_conf fc_conf;
7079 	int rx_fc_en = 0;
7080 	int tx_fc_en = 0;
7081 	int ret;
7082 
7083 	/*
7084 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7085 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7086 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7087 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7088 	 */
7089 	static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7090 			{RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7091 	};
7092 
7093 	/* Partial command line, retrieve current configuration */
7094 	if (cmd) {
7095 		ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7096 		if (ret != 0) {
7097 			printf("cannot get current flow ctrl parameters, return"
7098 			       "code = %d\n", ret);
7099 			return;
7100 		}
7101 
7102 		if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7103 		    (fc_conf.mode == RTE_FC_FULL))
7104 			rx_fc_en = 1;
7105 		if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7106 		    (fc_conf.mode == RTE_FC_FULL))
7107 			tx_fc_en = 1;
7108 	}
7109 
7110 	if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7111 		rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7112 
7113 	if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7114 		tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7115 
7116 	fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7117 
7118 	if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7119 		fc_conf.high_water = res->high_water;
7120 
7121 	if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7122 		fc_conf.low_water = res->low_water;
7123 
7124 	if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7125 		fc_conf.pause_time = res->pause_time;
7126 
7127 	if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7128 		fc_conf.send_xon = res->send_xon;
7129 
7130 	if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7131 		if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7132 			fc_conf.mac_ctrl_frame_fwd = 1;
7133 		else
7134 			fc_conf.mac_ctrl_frame_fwd = 0;
7135 	}
7136 
7137 	if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7138 		fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7139 
7140 	ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7141 	if (ret != 0)
7142 		printf("bad flow contrl parameter, return code = %d \n", ret);
7143 }
7144 
7145 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7146 struct cmd_priority_flow_ctrl_set_result {
7147 	cmdline_fixed_string_t set;
7148 	cmdline_fixed_string_t pfc_ctrl;
7149 	cmdline_fixed_string_t rx;
7150 	cmdline_fixed_string_t rx_pfc_mode;
7151 	cmdline_fixed_string_t tx;
7152 	cmdline_fixed_string_t tx_pfc_mode;
7153 	uint32_t high_water;
7154 	uint32_t low_water;
7155 	uint16_t pause_time;
7156 	uint8_t  priority;
7157 	portid_t port_id;
7158 };
7159 
7160 static void
7161 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7162 		       __rte_unused struct cmdline *cl,
7163 		       __rte_unused void *data)
7164 {
7165 	struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7166 	struct rte_eth_pfc_conf pfc_conf;
7167 	int rx_fc_enable, tx_fc_enable;
7168 	int ret;
7169 
7170 	/*
7171 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7172 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7173 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7174 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7175 	 */
7176 	static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7177 		{RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7178 	};
7179 
7180 	memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7181 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7182 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7183 	pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7184 	pfc_conf.fc.high_water = res->high_water;
7185 	pfc_conf.fc.low_water  = res->low_water;
7186 	pfc_conf.fc.pause_time = res->pause_time;
7187 	pfc_conf.priority      = res->priority;
7188 
7189 	ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7190 	if (ret != 0)
7191 		printf("bad priority flow contrl parameter, return code = %d \n", ret);
7192 }
7193 
7194 cmdline_parse_token_string_t cmd_pfc_set_set =
7195 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7196 				set, "set");
7197 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7198 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7199 				pfc_ctrl, "pfc_ctrl");
7200 cmdline_parse_token_string_t cmd_pfc_set_rx =
7201 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7202 				rx, "rx");
7203 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7204 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7205 				rx_pfc_mode, "on#off");
7206 cmdline_parse_token_string_t cmd_pfc_set_tx =
7207 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7208 				tx, "tx");
7209 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7210 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7211 				tx_pfc_mode, "on#off");
7212 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7213 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7214 				high_water, UINT32);
7215 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7216 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7217 				low_water, UINT32);
7218 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7219 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7220 				pause_time, UINT16);
7221 cmdline_parse_token_num_t cmd_pfc_set_priority =
7222 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7223 				priority, UINT8);
7224 cmdline_parse_token_num_t cmd_pfc_set_portid =
7225 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7226 				port_id, UINT16);
7227 
7228 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7229 	.f = cmd_priority_flow_ctrl_set_parsed,
7230 	.data = NULL,
7231 	.help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7232 		"<pause_time> <priority> <port_id>: "
7233 		"Configure the Ethernet priority flow control",
7234 	.tokens = {
7235 		(void *)&cmd_pfc_set_set,
7236 		(void *)&cmd_pfc_set_flow_ctrl,
7237 		(void *)&cmd_pfc_set_rx,
7238 		(void *)&cmd_pfc_set_rx_mode,
7239 		(void *)&cmd_pfc_set_tx,
7240 		(void *)&cmd_pfc_set_tx_mode,
7241 		(void *)&cmd_pfc_set_high_water,
7242 		(void *)&cmd_pfc_set_low_water,
7243 		(void *)&cmd_pfc_set_pause_time,
7244 		(void *)&cmd_pfc_set_priority,
7245 		(void *)&cmd_pfc_set_portid,
7246 		NULL,
7247 	},
7248 };
7249 
7250 /* *** RESET CONFIGURATION *** */
7251 struct cmd_reset_result {
7252 	cmdline_fixed_string_t reset;
7253 	cmdline_fixed_string_t def;
7254 };
7255 
7256 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7257 			     struct cmdline *cl,
7258 			     __rte_unused void *data)
7259 {
7260 	cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7261 	set_def_fwd_config();
7262 }
7263 
7264 cmdline_parse_token_string_t cmd_reset_set =
7265 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7266 cmdline_parse_token_string_t cmd_reset_def =
7267 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7268 				 "default");
7269 
7270 cmdline_parse_inst_t cmd_reset = {
7271 	.f = cmd_reset_parsed,
7272 	.data = NULL,
7273 	.help_str = "set default: Reset default forwarding configuration",
7274 	.tokens = {
7275 		(void *)&cmd_reset_set,
7276 		(void *)&cmd_reset_def,
7277 		NULL,
7278 	},
7279 };
7280 
7281 /* *** START FORWARDING *** */
7282 struct cmd_start_result {
7283 	cmdline_fixed_string_t start;
7284 };
7285 
7286 cmdline_parse_token_string_t cmd_start_start =
7287 	TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7288 
7289 static void cmd_start_parsed(__rte_unused void *parsed_result,
7290 			     __rte_unused struct cmdline *cl,
7291 			     __rte_unused void *data)
7292 {
7293 	start_packet_forwarding(0);
7294 }
7295 
7296 cmdline_parse_inst_t cmd_start = {
7297 	.f = cmd_start_parsed,
7298 	.data = NULL,
7299 	.help_str = "start: Start packet forwarding",
7300 	.tokens = {
7301 		(void *)&cmd_start_start,
7302 		NULL,
7303 	},
7304 };
7305 
7306 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7307 struct cmd_start_tx_first_result {
7308 	cmdline_fixed_string_t start;
7309 	cmdline_fixed_string_t tx_first;
7310 };
7311 
7312 static void
7313 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7314 			  __rte_unused struct cmdline *cl,
7315 			  __rte_unused void *data)
7316 {
7317 	start_packet_forwarding(1);
7318 }
7319 
7320 cmdline_parse_token_string_t cmd_start_tx_first_start =
7321 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7322 				 "start");
7323 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7324 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7325 				 tx_first, "tx_first");
7326 
7327 cmdline_parse_inst_t cmd_start_tx_first = {
7328 	.f = cmd_start_tx_first_parsed,
7329 	.data = NULL,
7330 	.help_str = "start tx_first: Start packet forwarding, "
7331 		"after sending 1 burst of packets",
7332 	.tokens = {
7333 		(void *)&cmd_start_tx_first_start,
7334 		(void *)&cmd_start_tx_first_tx_first,
7335 		NULL,
7336 	},
7337 };
7338 
7339 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7340 struct cmd_start_tx_first_n_result {
7341 	cmdline_fixed_string_t start;
7342 	cmdline_fixed_string_t tx_first;
7343 	uint32_t tx_num;
7344 };
7345 
7346 static void
7347 cmd_start_tx_first_n_parsed(void *parsed_result,
7348 			  __rte_unused struct cmdline *cl,
7349 			  __rte_unused void *data)
7350 {
7351 	struct cmd_start_tx_first_n_result *res = parsed_result;
7352 
7353 	start_packet_forwarding(res->tx_num);
7354 }
7355 
7356 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7357 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7358 			start, "start");
7359 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7360 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7361 			tx_first, "tx_first");
7362 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7363 	TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7364 			tx_num, UINT32);
7365 
7366 cmdline_parse_inst_t cmd_start_tx_first_n = {
7367 	.f = cmd_start_tx_first_n_parsed,
7368 	.data = NULL,
7369 	.help_str = "start tx_first <num>: "
7370 		"packet forwarding, after sending <num> bursts of packets",
7371 	.tokens = {
7372 		(void *)&cmd_start_tx_first_n_start,
7373 		(void *)&cmd_start_tx_first_n_tx_first,
7374 		(void *)&cmd_start_tx_first_n_tx_num,
7375 		NULL,
7376 	},
7377 };
7378 
7379 /* *** SET LINK UP *** */
7380 struct cmd_set_link_up_result {
7381 	cmdline_fixed_string_t set;
7382 	cmdline_fixed_string_t link_up;
7383 	cmdline_fixed_string_t port;
7384 	portid_t port_id;
7385 };
7386 
7387 cmdline_parse_token_string_t cmd_set_link_up_set =
7388 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7389 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7390 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7391 				"link-up");
7392 cmdline_parse_token_string_t cmd_set_link_up_port =
7393 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7394 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7395 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7396 
7397 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7398 			     __rte_unused struct cmdline *cl,
7399 			     __rte_unused void *data)
7400 {
7401 	struct cmd_set_link_up_result *res = parsed_result;
7402 	dev_set_link_up(res->port_id);
7403 }
7404 
7405 cmdline_parse_inst_t cmd_set_link_up = {
7406 	.f = cmd_set_link_up_parsed,
7407 	.data = NULL,
7408 	.help_str = "set link-up port <port id>",
7409 	.tokens = {
7410 		(void *)&cmd_set_link_up_set,
7411 		(void *)&cmd_set_link_up_link_up,
7412 		(void *)&cmd_set_link_up_port,
7413 		(void *)&cmd_set_link_up_port_id,
7414 		NULL,
7415 	},
7416 };
7417 
7418 /* *** SET LINK DOWN *** */
7419 struct cmd_set_link_down_result {
7420 	cmdline_fixed_string_t set;
7421 	cmdline_fixed_string_t link_down;
7422 	cmdline_fixed_string_t port;
7423 	portid_t port_id;
7424 };
7425 
7426 cmdline_parse_token_string_t cmd_set_link_down_set =
7427 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7428 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7429 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7430 				"link-down");
7431 cmdline_parse_token_string_t cmd_set_link_down_port =
7432 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7433 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7434 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7435 
7436 static void cmd_set_link_down_parsed(
7437 				__rte_unused void *parsed_result,
7438 				__rte_unused struct cmdline *cl,
7439 				__rte_unused void *data)
7440 {
7441 	struct cmd_set_link_down_result *res = parsed_result;
7442 	dev_set_link_down(res->port_id);
7443 }
7444 
7445 cmdline_parse_inst_t cmd_set_link_down = {
7446 	.f = cmd_set_link_down_parsed,
7447 	.data = NULL,
7448 	.help_str = "set link-down port <port id>",
7449 	.tokens = {
7450 		(void *)&cmd_set_link_down_set,
7451 		(void *)&cmd_set_link_down_link_down,
7452 		(void *)&cmd_set_link_down_port,
7453 		(void *)&cmd_set_link_down_port_id,
7454 		NULL,
7455 	},
7456 };
7457 
7458 /* *** SHOW CFG *** */
7459 struct cmd_showcfg_result {
7460 	cmdline_fixed_string_t show;
7461 	cmdline_fixed_string_t cfg;
7462 	cmdline_fixed_string_t what;
7463 };
7464 
7465 static void cmd_showcfg_parsed(void *parsed_result,
7466 			       __rte_unused struct cmdline *cl,
7467 			       __rte_unused void *data)
7468 {
7469 	struct cmd_showcfg_result *res = parsed_result;
7470 	if (!strcmp(res->what, "rxtx"))
7471 		rxtx_config_display();
7472 	else if (!strcmp(res->what, "cores"))
7473 		fwd_lcores_config_display();
7474 	else if (!strcmp(res->what, "fwd"))
7475 		pkt_fwd_config_display(&cur_fwd_config);
7476 	else if (!strcmp(res->what, "txpkts"))
7477 		show_tx_pkt_segments();
7478 	else if (!strcmp(res->what, "txtimes"))
7479 		show_tx_pkt_times();
7480 }
7481 
7482 cmdline_parse_token_string_t cmd_showcfg_show =
7483 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7484 cmdline_parse_token_string_t cmd_showcfg_port =
7485 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7486 cmdline_parse_token_string_t cmd_showcfg_what =
7487 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7488 				 "rxtx#cores#fwd#txpkts#txtimes");
7489 
7490 cmdline_parse_inst_t cmd_showcfg = {
7491 	.f = cmd_showcfg_parsed,
7492 	.data = NULL,
7493 	.help_str = "show config rxtx|cores|fwd|txpkts|txtimes",
7494 	.tokens = {
7495 		(void *)&cmd_showcfg_show,
7496 		(void *)&cmd_showcfg_port,
7497 		(void *)&cmd_showcfg_what,
7498 		NULL,
7499 	},
7500 };
7501 
7502 /* *** SHOW ALL PORT INFO *** */
7503 struct cmd_showportall_result {
7504 	cmdline_fixed_string_t show;
7505 	cmdline_fixed_string_t port;
7506 	cmdline_fixed_string_t what;
7507 	cmdline_fixed_string_t all;
7508 };
7509 
7510 static void cmd_showportall_parsed(void *parsed_result,
7511 				__rte_unused struct cmdline *cl,
7512 				__rte_unused void *data)
7513 {
7514 	portid_t i;
7515 
7516 	struct cmd_showportall_result *res = parsed_result;
7517 	if (!strcmp(res->show, "clear")) {
7518 		if (!strcmp(res->what, "stats"))
7519 			RTE_ETH_FOREACH_DEV(i)
7520 				nic_stats_clear(i);
7521 		else if (!strcmp(res->what, "xstats"))
7522 			RTE_ETH_FOREACH_DEV(i)
7523 				nic_xstats_clear(i);
7524 	} else if (!strcmp(res->what, "info"))
7525 		RTE_ETH_FOREACH_DEV(i)
7526 			port_infos_display(i);
7527 	else if (!strcmp(res->what, "summary")) {
7528 		port_summary_header_display();
7529 		RTE_ETH_FOREACH_DEV(i)
7530 			port_summary_display(i);
7531 	}
7532 	else if (!strcmp(res->what, "stats"))
7533 		RTE_ETH_FOREACH_DEV(i)
7534 			nic_stats_display(i);
7535 	else if (!strcmp(res->what, "xstats"))
7536 		RTE_ETH_FOREACH_DEV(i)
7537 			nic_xstats_display(i);
7538 	else if (!strcmp(res->what, "fdir"))
7539 		RTE_ETH_FOREACH_DEV(i)
7540 			fdir_get_infos(i);
7541 	else if (!strcmp(res->what, "stat_qmap"))
7542 		RTE_ETH_FOREACH_DEV(i)
7543 			nic_stats_mapping_display(i);
7544 	else if (!strcmp(res->what, "dcb_tc"))
7545 		RTE_ETH_FOREACH_DEV(i)
7546 			port_dcb_info_display(i);
7547 	else if (!strcmp(res->what, "cap"))
7548 		RTE_ETH_FOREACH_DEV(i)
7549 			port_offload_cap_display(i);
7550 }
7551 
7552 cmdline_parse_token_string_t cmd_showportall_show =
7553 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7554 				 "show#clear");
7555 cmdline_parse_token_string_t cmd_showportall_port =
7556 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7557 cmdline_parse_token_string_t cmd_showportall_what =
7558 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7559 				 "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7560 cmdline_parse_token_string_t cmd_showportall_all =
7561 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7562 cmdline_parse_inst_t cmd_showportall = {
7563 	.f = cmd_showportall_parsed,
7564 	.data = NULL,
7565 	.help_str = "show|clear port "
7566 		"info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7567 	.tokens = {
7568 		(void *)&cmd_showportall_show,
7569 		(void *)&cmd_showportall_port,
7570 		(void *)&cmd_showportall_what,
7571 		(void *)&cmd_showportall_all,
7572 		NULL,
7573 	},
7574 };
7575 
7576 /* *** SHOW PORT INFO *** */
7577 struct cmd_showport_result {
7578 	cmdline_fixed_string_t show;
7579 	cmdline_fixed_string_t port;
7580 	cmdline_fixed_string_t what;
7581 	uint16_t portnum;
7582 };
7583 
7584 static void cmd_showport_parsed(void *parsed_result,
7585 				__rte_unused struct cmdline *cl,
7586 				__rte_unused void *data)
7587 {
7588 	struct cmd_showport_result *res = parsed_result;
7589 	if (!strcmp(res->show, "clear")) {
7590 		if (!strcmp(res->what, "stats"))
7591 			nic_stats_clear(res->portnum);
7592 		else if (!strcmp(res->what, "xstats"))
7593 			nic_xstats_clear(res->portnum);
7594 	} else if (!strcmp(res->what, "info"))
7595 		port_infos_display(res->portnum);
7596 	else if (!strcmp(res->what, "summary")) {
7597 		port_summary_header_display();
7598 		port_summary_display(res->portnum);
7599 	}
7600 	else if (!strcmp(res->what, "stats"))
7601 		nic_stats_display(res->portnum);
7602 	else if (!strcmp(res->what, "xstats"))
7603 		nic_xstats_display(res->portnum);
7604 	else if (!strcmp(res->what, "fdir"))
7605 		 fdir_get_infos(res->portnum);
7606 	else if (!strcmp(res->what, "stat_qmap"))
7607 		nic_stats_mapping_display(res->portnum);
7608 	else if (!strcmp(res->what, "dcb_tc"))
7609 		port_dcb_info_display(res->portnum);
7610 	else if (!strcmp(res->what, "cap"))
7611 		port_offload_cap_display(res->portnum);
7612 }
7613 
7614 cmdline_parse_token_string_t cmd_showport_show =
7615 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7616 				 "show#clear");
7617 cmdline_parse_token_string_t cmd_showport_port =
7618 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7619 cmdline_parse_token_string_t cmd_showport_what =
7620 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7621 				 "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7622 cmdline_parse_token_num_t cmd_showport_portnum =
7623 	TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7624 
7625 cmdline_parse_inst_t cmd_showport = {
7626 	.f = cmd_showport_parsed,
7627 	.data = NULL,
7628 	.help_str = "show|clear port "
7629 		"info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7630 		"<port_id>",
7631 	.tokens = {
7632 		(void *)&cmd_showport_show,
7633 		(void *)&cmd_showport_port,
7634 		(void *)&cmd_showport_what,
7635 		(void *)&cmd_showport_portnum,
7636 		NULL,
7637 	},
7638 };
7639 
7640 /* *** SHOW DEVICE INFO *** */
7641 struct cmd_showdevice_result {
7642 	cmdline_fixed_string_t show;
7643 	cmdline_fixed_string_t device;
7644 	cmdline_fixed_string_t what;
7645 	cmdline_fixed_string_t identifier;
7646 };
7647 
7648 static void cmd_showdevice_parsed(void *parsed_result,
7649 				__rte_unused struct cmdline *cl,
7650 				__rte_unused void *data)
7651 {
7652 	struct cmd_showdevice_result *res = parsed_result;
7653 	if (!strcmp(res->what, "info")) {
7654 		if (!strcmp(res->identifier, "all"))
7655 			device_infos_display(NULL);
7656 		else
7657 			device_infos_display(res->identifier);
7658 	}
7659 }
7660 
7661 cmdline_parse_token_string_t cmd_showdevice_show =
7662 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7663 				 "show");
7664 cmdline_parse_token_string_t cmd_showdevice_device =
7665 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7666 cmdline_parse_token_string_t cmd_showdevice_what =
7667 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7668 				 "info");
7669 cmdline_parse_token_string_t cmd_showdevice_identifier =
7670 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7671 			identifier, NULL);
7672 
7673 cmdline_parse_inst_t cmd_showdevice = {
7674 	.f = cmd_showdevice_parsed,
7675 	.data = NULL,
7676 	.help_str = "show device info <identifier>|all",
7677 	.tokens = {
7678 		(void *)&cmd_showdevice_show,
7679 		(void *)&cmd_showdevice_device,
7680 		(void *)&cmd_showdevice_what,
7681 		(void *)&cmd_showdevice_identifier,
7682 		NULL,
7683 	},
7684 };
7685 /* *** SHOW QUEUE INFO *** */
7686 struct cmd_showqueue_result {
7687 	cmdline_fixed_string_t show;
7688 	cmdline_fixed_string_t type;
7689 	cmdline_fixed_string_t what;
7690 	uint16_t portnum;
7691 	uint16_t queuenum;
7692 };
7693 
7694 static void
7695 cmd_showqueue_parsed(void *parsed_result,
7696 	__rte_unused struct cmdline *cl,
7697 	__rte_unused void *data)
7698 {
7699 	struct cmd_showqueue_result *res = parsed_result;
7700 
7701 	if (!strcmp(res->type, "rxq"))
7702 		rx_queue_infos_display(res->portnum, res->queuenum);
7703 	else if (!strcmp(res->type, "txq"))
7704 		tx_queue_infos_display(res->portnum, res->queuenum);
7705 }
7706 
7707 cmdline_parse_token_string_t cmd_showqueue_show =
7708 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7709 cmdline_parse_token_string_t cmd_showqueue_type =
7710 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7711 cmdline_parse_token_string_t cmd_showqueue_what =
7712 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7713 cmdline_parse_token_num_t cmd_showqueue_portnum =
7714 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7715 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7716 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7717 
7718 cmdline_parse_inst_t cmd_showqueue = {
7719 	.f = cmd_showqueue_parsed,
7720 	.data = NULL,
7721 	.help_str = "show rxq|txq info <port_id> <queue_id>",
7722 	.tokens = {
7723 		(void *)&cmd_showqueue_show,
7724 		(void *)&cmd_showqueue_type,
7725 		(void *)&cmd_showqueue_what,
7726 		(void *)&cmd_showqueue_portnum,
7727 		(void *)&cmd_showqueue_queuenum,
7728 		NULL,
7729 	},
7730 };
7731 
7732 /* show/clear fwd engine statistics */
7733 struct fwd_result {
7734 	cmdline_fixed_string_t action;
7735 	cmdline_fixed_string_t fwd;
7736 	cmdline_fixed_string_t stats;
7737 	cmdline_fixed_string_t all;
7738 };
7739 
7740 cmdline_parse_token_string_t cmd_fwd_action =
7741 	TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7742 cmdline_parse_token_string_t cmd_fwd_fwd =
7743 	TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7744 cmdline_parse_token_string_t cmd_fwd_stats =
7745 	TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7746 cmdline_parse_token_string_t cmd_fwd_all =
7747 	TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7748 
7749 static void
7750 cmd_showfwdall_parsed(void *parsed_result,
7751 		      __rte_unused struct cmdline *cl,
7752 		      __rte_unused void *data)
7753 {
7754 	struct fwd_result *res = parsed_result;
7755 
7756 	if (!strcmp(res->action, "show"))
7757 		fwd_stats_display();
7758 	else
7759 		fwd_stats_reset();
7760 }
7761 
7762 static cmdline_parse_inst_t cmd_showfwdall = {
7763 	.f = cmd_showfwdall_parsed,
7764 	.data = NULL,
7765 	.help_str = "show|clear fwd stats all",
7766 	.tokens = {
7767 		(void *)&cmd_fwd_action,
7768 		(void *)&cmd_fwd_fwd,
7769 		(void *)&cmd_fwd_stats,
7770 		(void *)&cmd_fwd_all,
7771 		NULL,
7772 	},
7773 };
7774 
7775 /* *** READ PORT REGISTER *** */
7776 struct cmd_read_reg_result {
7777 	cmdline_fixed_string_t read;
7778 	cmdline_fixed_string_t reg;
7779 	portid_t port_id;
7780 	uint32_t reg_off;
7781 };
7782 
7783 static void
7784 cmd_read_reg_parsed(void *parsed_result,
7785 		    __rte_unused struct cmdline *cl,
7786 		    __rte_unused void *data)
7787 {
7788 	struct cmd_read_reg_result *res = parsed_result;
7789 	port_reg_display(res->port_id, res->reg_off);
7790 }
7791 
7792 cmdline_parse_token_string_t cmd_read_reg_read =
7793 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7794 cmdline_parse_token_string_t cmd_read_reg_reg =
7795 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7796 cmdline_parse_token_num_t cmd_read_reg_port_id =
7797 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7798 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7799 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7800 
7801 cmdline_parse_inst_t cmd_read_reg = {
7802 	.f = cmd_read_reg_parsed,
7803 	.data = NULL,
7804 	.help_str = "read reg <port_id> <reg_off>",
7805 	.tokens = {
7806 		(void *)&cmd_read_reg_read,
7807 		(void *)&cmd_read_reg_reg,
7808 		(void *)&cmd_read_reg_port_id,
7809 		(void *)&cmd_read_reg_reg_off,
7810 		NULL,
7811 	},
7812 };
7813 
7814 /* *** READ PORT REGISTER BIT FIELD *** */
7815 struct cmd_read_reg_bit_field_result {
7816 	cmdline_fixed_string_t read;
7817 	cmdline_fixed_string_t regfield;
7818 	portid_t port_id;
7819 	uint32_t reg_off;
7820 	uint8_t bit1_pos;
7821 	uint8_t bit2_pos;
7822 };
7823 
7824 static void
7825 cmd_read_reg_bit_field_parsed(void *parsed_result,
7826 			      __rte_unused struct cmdline *cl,
7827 			      __rte_unused void *data)
7828 {
7829 	struct cmd_read_reg_bit_field_result *res = parsed_result;
7830 	port_reg_bit_field_display(res->port_id, res->reg_off,
7831 				   res->bit1_pos, res->bit2_pos);
7832 }
7833 
7834 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7835 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7836 				 "read");
7837 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7838 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7839 				 regfield, "regfield");
7840 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7841 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7842 			      UINT16);
7843 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7844 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7845 			      UINT32);
7846 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7847 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7848 			      UINT8);
7849 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7850 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7851 			      UINT8);
7852 
7853 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7854 	.f = cmd_read_reg_bit_field_parsed,
7855 	.data = NULL,
7856 	.help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7857 	"Read register bit field between bit_x and bit_y included",
7858 	.tokens = {
7859 		(void *)&cmd_read_reg_bit_field_read,
7860 		(void *)&cmd_read_reg_bit_field_regfield,
7861 		(void *)&cmd_read_reg_bit_field_port_id,
7862 		(void *)&cmd_read_reg_bit_field_reg_off,
7863 		(void *)&cmd_read_reg_bit_field_bit1_pos,
7864 		(void *)&cmd_read_reg_bit_field_bit2_pos,
7865 		NULL,
7866 	},
7867 };
7868 
7869 /* *** READ PORT REGISTER BIT *** */
7870 struct cmd_read_reg_bit_result {
7871 	cmdline_fixed_string_t read;
7872 	cmdline_fixed_string_t regbit;
7873 	portid_t port_id;
7874 	uint32_t reg_off;
7875 	uint8_t bit_pos;
7876 };
7877 
7878 static void
7879 cmd_read_reg_bit_parsed(void *parsed_result,
7880 			__rte_unused struct cmdline *cl,
7881 			__rte_unused void *data)
7882 {
7883 	struct cmd_read_reg_bit_result *res = parsed_result;
7884 	port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7885 }
7886 
7887 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7888 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7889 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7890 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7891 				 regbit, "regbit");
7892 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7893 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7894 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7895 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7896 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7897 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7898 
7899 cmdline_parse_inst_t cmd_read_reg_bit = {
7900 	.f = cmd_read_reg_bit_parsed,
7901 	.data = NULL,
7902 	.help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7903 	.tokens = {
7904 		(void *)&cmd_read_reg_bit_read,
7905 		(void *)&cmd_read_reg_bit_regbit,
7906 		(void *)&cmd_read_reg_bit_port_id,
7907 		(void *)&cmd_read_reg_bit_reg_off,
7908 		(void *)&cmd_read_reg_bit_bit_pos,
7909 		NULL,
7910 	},
7911 };
7912 
7913 /* *** WRITE PORT REGISTER *** */
7914 struct cmd_write_reg_result {
7915 	cmdline_fixed_string_t write;
7916 	cmdline_fixed_string_t reg;
7917 	portid_t port_id;
7918 	uint32_t reg_off;
7919 	uint32_t value;
7920 };
7921 
7922 static void
7923 cmd_write_reg_parsed(void *parsed_result,
7924 		     __rte_unused struct cmdline *cl,
7925 		     __rte_unused void *data)
7926 {
7927 	struct cmd_write_reg_result *res = parsed_result;
7928 	port_reg_set(res->port_id, res->reg_off, res->value);
7929 }
7930 
7931 cmdline_parse_token_string_t cmd_write_reg_write =
7932 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7933 cmdline_parse_token_string_t cmd_write_reg_reg =
7934 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7935 cmdline_parse_token_num_t cmd_write_reg_port_id =
7936 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7937 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7938 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7939 cmdline_parse_token_num_t cmd_write_reg_value =
7940 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7941 
7942 cmdline_parse_inst_t cmd_write_reg = {
7943 	.f = cmd_write_reg_parsed,
7944 	.data = NULL,
7945 	.help_str = "write reg <port_id> <reg_off> <reg_value>",
7946 	.tokens = {
7947 		(void *)&cmd_write_reg_write,
7948 		(void *)&cmd_write_reg_reg,
7949 		(void *)&cmd_write_reg_port_id,
7950 		(void *)&cmd_write_reg_reg_off,
7951 		(void *)&cmd_write_reg_value,
7952 		NULL,
7953 	},
7954 };
7955 
7956 /* *** WRITE PORT REGISTER BIT FIELD *** */
7957 struct cmd_write_reg_bit_field_result {
7958 	cmdline_fixed_string_t write;
7959 	cmdline_fixed_string_t regfield;
7960 	portid_t port_id;
7961 	uint32_t reg_off;
7962 	uint8_t bit1_pos;
7963 	uint8_t bit2_pos;
7964 	uint32_t value;
7965 };
7966 
7967 static void
7968 cmd_write_reg_bit_field_parsed(void *parsed_result,
7969 			       __rte_unused struct cmdline *cl,
7970 			       __rte_unused void *data)
7971 {
7972 	struct cmd_write_reg_bit_field_result *res = parsed_result;
7973 	port_reg_bit_field_set(res->port_id, res->reg_off,
7974 			  res->bit1_pos, res->bit2_pos, res->value);
7975 }
7976 
7977 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7978 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7979 				 "write");
7980 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7981 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7982 				 regfield, "regfield");
7983 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7984 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7985 			      UINT16);
7986 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7987 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7988 			      UINT32);
7989 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7990 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7991 			      UINT8);
7992 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7993 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7994 			      UINT8);
7995 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7996 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7997 			      UINT32);
7998 
7999 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8000 	.f = cmd_write_reg_bit_field_parsed,
8001 	.data = NULL,
8002 	.help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8003 		"<reg_value>: "
8004 		"Set register bit field between bit_x and bit_y included",
8005 	.tokens = {
8006 		(void *)&cmd_write_reg_bit_field_write,
8007 		(void *)&cmd_write_reg_bit_field_regfield,
8008 		(void *)&cmd_write_reg_bit_field_port_id,
8009 		(void *)&cmd_write_reg_bit_field_reg_off,
8010 		(void *)&cmd_write_reg_bit_field_bit1_pos,
8011 		(void *)&cmd_write_reg_bit_field_bit2_pos,
8012 		(void *)&cmd_write_reg_bit_field_value,
8013 		NULL,
8014 	},
8015 };
8016 
8017 /* *** WRITE PORT REGISTER BIT *** */
8018 struct cmd_write_reg_bit_result {
8019 	cmdline_fixed_string_t write;
8020 	cmdline_fixed_string_t regbit;
8021 	portid_t port_id;
8022 	uint32_t reg_off;
8023 	uint8_t bit_pos;
8024 	uint8_t value;
8025 };
8026 
8027 static void
8028 cmd_write_reg_bit_parsed(void *parsed_result,
8029 			 __rte_unused struct cmdline *cl,
8030 			 __rte_unused void *data)
8031 {
8032 	struct cmd_write_reg_bit_result *res = parsed_result;
8033 	port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8034 }
8035 
8036 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8037 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8038 				 "write");
8039 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8040 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8041 				 regbit, "regbit");
8042 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8043 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8044 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8045 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8046 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8047 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8048 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8049 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8050 
8051 cmdline_parse_inst_t cmd_write_reg_bit = {
8052 	.f = cmd_write_reg_bit_parsed,
8053 	.data = NULL,
8054 	.help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8055 		"0 <= bit_x <= 31",
8056 	.tokens = {
8057 		(void *)&cmd_write_reg_bit_write,
8058 		(void *)&cmd_write_reg_bit_regbit,
8059 		(void *)&cmd_write_reg_bit_port_id,
8060 		(void *)&cmd_write_reg_bit_reg_off,
8061 		(void *)&cmd_write_reg_bit_bit_pos,
8062 		(void *)&cmd_write_reg_bit_value,
8063 		NULL,
8064 	},
8065 };
8066 
8067 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8068 struct cmd_read_rxd_txd_result {
8069 	cmdline_fixed_string_t read;
8070 	cmdline_fixed_string_t rxd_txd;
8071 	portid_t port_id;
8072 	uint16_t queue_id;
8073 	uint16_t desc_id;
8074 };
8075 
8076 static void
8077 cmd_read_rxd_txd_parsed(void *parsed_result,
8078 			__rte_unused struct cmdline *cl,
8079 			__rte_unused void *data)
8080 {
8081 	struct cmd_read_rxd_txd_result *res = parsed_result;
8082 
8083 	if (!strcmp(res->rxd_txd, "rxd"))
8084 		rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8085 	else if (!strcmp(res->rxd_txd, "txd"))
8086 		tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8087 }
8088 
8089 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8090 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8091 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8092 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8093 				 "rxd#txd");
8094 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8095 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8096 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8097 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8098 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8099 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8100 
8101 cmdline_parse_inst_t cmd_read_rxd_txd = {
8102 	.f = cmd_read_rxd_txd_parsed,
8103 	.data = NULL,
8104 	.help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8105 	.tokens = {
8106 		(void *)&cmd_read_rxd_txd_read,
8107 		(void *)&cmd_read_rxd_txd_rxd_txd,
8108 		(void *)&cmd_read_rxd_txd_port_id,
8109 		(void *)&cmd_read_rxd_txd_queue_id,
8110 		(void *)&cmd_read_rxd_txd_desc_id,
8111 		NULL,
8112 	},
8113 };
8114 
8115 /* *** QUIT *** */
8116 struct cmd_quit_result {
8117 	cmdline_fixed_string_t quit;
8118 };
8119 
8120 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8121 			    struct cmdline *cl,
8122 			    __rte_unused void *data)
8123 {
8124 	cmdline_quit(cl);
8125 }
8126 
8127 cmdline_parse_token_string_t cmd_quit_quit =
8128 	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8129 
8130 cmdline_parse_inst_t cmd_quit = {
8131 	.f = cmd_quit_parsed,
8132 	.data = NULL,
8133 	.help_str = "quit: Exit application",
8134 	.tokens = {
8135 		(void *)&cmd_quit_quit,
8136 		NULL,
8137 	},
8138 };
8139 
8140 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8141 struct cmd_mac_addr_result {
8142 	cmdline_fixed_string_t mac_addr_cmd;
8143 	cmdline_fixed_string_t what;
8144 	uint16_t port_num;
8145 	struct rte_ether_addr address;
8146 };
8147 
8148 static void cmd_mac_addr_parsed(void *parsed_result,
8149 		__rte_unused struct cmdline *cl,
8150 		__rte_unused void *data)
8151 {
8152 	struct cmd_mac_addr_result *res = parsed_result;
8153 	int ret;
8154 
8155 	if (strcmp(res->what, "add") == 0)
8156 		ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8157 	else if (strcmp(res->what, "set") == 0)
8158 		ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8159 						       &res->address);
8160 	else
8161 		ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8162 
8163 	/* check the return value and print it if is < 0 */
8164 	if(ret < 0)
8165 		printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8166 
8167 }
8168 
8169 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8170 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8171 				"mac_addr");
8172 cmdline_parse_token_string_t cmd_mac_addr_what =
8173 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8174 				"add#remove#set");
8175 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8176 		TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8177 					UINT16);
8178 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8179 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8180 
8181 cmdline_parse_inst_t cmd_mac_addr = {
8182 	.f = cmd_mac_addr_parsed,
8183 	.data = (void *)0,
8184 	.help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8185 			"Add/Remove/Set MAC address on port_id",
8186 	.tokens = {
8187 		(void *)&cmd_mac_addr_cmd,
8188 		(void *)&cmd_mac_addr_what,
8189 		(void *)&cmd_mac_addr_portnum,
8190 		(void *)&cmd_mac_addr_addr,
8191 		NULL,
8192 	},
8193 };
8194 
8195 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8196 struct cmd_eth_peer_result {
8197 	cmdline_fixed_string_t set;
8198 	cmdline_fixed_string_t eth_peer;
8199 	portid_t port_id;
8200 	cmdline_fixed_string_t peer_addr;
8201 };
8202 
8203 static void cmd_set_eth_peer_parsed(void *parsed_result,
8204 			__rte_unused struct cmdline *cl,
8205 			__rte_unused void *data)
8206 {
8207 		struct cmd_eth_peer_result *res = parsed_result;
8208 
8209 		if (test_done == 0) {
8210 			printf("Please stop forwarding first\n");
8211 			return;
8212 		}
8213 		if (!strcmp(res->eth_peer, "eth-peer")) {
8214 			set_fwd_eth_peer(res->port_id, res->peer_addr);
8215 			fwd_config_setup();
8216 		}
8217 }
8218 cmdline_parse_token_string_t cmd_eth_peer_set =
8219 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8220 cmdline_parse_token_string_t cmd_eth_peer =
8221 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8222 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8223 	TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8224 cmdline_parse_token_string_t cmd_eth_peer_addr =
8225 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8226 
8227 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8228 	.f = cmd_set_eth_peer_parsed,
8229 	.data = NULL,
8230 	.help_str = "set eth-peer <port_id> <peer_mac>",
8231 	.tokens = {
8232 		(void *)&cmd_eth_peer_set,
8233 		(void *)&cmd_eth_peer,
8234 		(void *)&cmd_eth_peer_port_id,
8235 		(void *)&cmd_eth_peer_addr,
8236 		NULL,
8237 	},
8238 };
8239 
8240 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8241 struct cmd_set_qmap_result {
8242 	cmdline_fixed_string_t set;
8243 	cmdline_fixed_string_t qmap;
8244 	cmdline_fixed_string_t what;
8245 	portid_t port_id;
8246 	uint16_t queue_id;
8247 	uint8_t map_value;
8248 };
8249 
8250 static void
8251 cmd_set_qmap_parsed(void *parsed_result,
8252 		       __rte_unused struct cmdline *cl,
8253 		       __rte_unused void *data)
8254 {
8255 	struct cmd_set_qmap_result *res = parsed_result;
8256 	int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8257 
8258 	set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8259 }
8260 
8261 cmdline_parse_token_string_t cmd_setqmap_set =
8262 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8263 				 set, "set");
8264 cmdline_parse_token_string_t cmd_setqmap_qmap =
8265 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8266 				 qmap, "stat_qmap");
8267 cmdline_parse_token_string_t cmd_setqmap_what =
8268 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8269 				 what, "tx#rx");
8270 cmdline_parse_token_num_t cmd_setqmap_portid =
8271 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8272 			      port_id, UINT16);
8273 cmdline_parse_token_num_t cmd_setqmap_queueid =
8274 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8275 			      queue_id, UINT16);
8276 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8277 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8278 			      map_value, UINT8);
8279 
8280 cmdline_parse_inst_t cmd_set_qmap = {
8281 	.f = cmd_set_qmap_parsed,
8282 	.data = NULL,
8283 	.help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8284 		"Set statistics mapping value on tx|rx queue_id of port_id",
8285 	.tokens = {
8286 		(void *)&cmd_setqmap_set,
8287 		(void *)&cmd_setqmap_qmap,
8288 		(void *)&cmd_setqmap_what,
8289 		(void *)&cmd_setqmap_portid,
8290 		(void *)&cmd_setqmap_queueid,
8291 		(void *)&cmd_setqmap_mapvalue,
8292 		NULL,
8293 	},
8294 };
8295 
8296 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8297 struct cmd_set_xstats_hide_zero_result {
8298 	cmdline_fixed_string_t keyword;
8299 	cmdline_fixed_string_t name;
8300 	cmdline_fixed_string_t on_off;
8301 };
8302 
8303 static void
8304 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8305 			__rte_unused struct cmdline *cl,
8306 			__rte_unused void *data)
8307 {
8308 	struct cmd_set_xstats_hide_zero_result *res;
8309 	uint16_t on_off = 0;
8310 
8311 	res = parsed_result;
8312 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8313 	set_xstats_hide_zero(on_off);
8314 }
8315 
8316 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8317 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8318 				 keyword, "set");
8319 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8320 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8321 				 name, "xstats-hide-zero");
8322 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8323 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8324 				 on_off, "on#off");
8325 
8326 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8327 	.f = cmd_set_xstats_hide_zero_parsed,
8328 	.data = NULL,
8329 	.help_str = "set xstats-hide-zero on|off",
8330 	.tokens = {
8331 		(void *)&cmd_set_xstats_hide_zero_keyword,
8332 		(void *)&cmd_set_xstats_hide_zero_name,
8333 		(void *)&cmd_set_xstats_hide_zero_on_off,
8334 		NULL,
8335 	},
8336 };
8337 
8338 /* *** CONFIGURE UNICAST HASH TABLE *** */
8339 struct cmd_set_uc_hash_table {
8340 	cmdline_fixed_string_t set;
8341 	cmdline_fixed_string_t port;
8342 	portid_t port_id;
8343 	cmdline_fixed_string_t what;
8344 	struct rte_ether_addr address;
8345 	cmdline_fixed_string_t mode;
8346 };
8347 
8348 static void
8349 cmd_set_uc_hash_parsed(void *parsed_result,
8350 		       __rte_unused struct cmdline *cl,
8351 		       __rte_unused void *data)
8352 {
8353 	int ret=0;
8354 	struct cmd_set_uc_hash_table *res = parsed_result;
8355 
8356 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8357 
8358 	if (strcmp(res->what, "uta") == 0)
8359 		ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8360 						&res->address,(uint8_t)is_on);
8361 	if (ret < 0)
8362 		printf("bad unicast hash table parameter, return code = %d \n", ret);
8363 
8364 }
8365 
8366 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8367 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8368 				 set, "set");
8369 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8370 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8371 				 port, "port");
8372 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8373 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8374 			      port_id, UINT16);
8375 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8376 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8377 				 what, "uta");
8378 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8379 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8380 				address);
8381 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8382 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8383 				 mode, "on#off");
8384 
8385 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8386 	.f = cmd_set_uc_hash_parsed,
8387 	.data = NULL,
8388 	.help_str = "set port <port_id> uta <mac_addr> on|off)",
8389 	.tokens = {
8390 		(void *)&cmd_set_uc_hash_set,
8391 		(void *)&cmd_set_uc_hash_port,
8392 		(void *)&cmd_set_uc_hash_portid,
8393 		(void *)&cmd_set_uc_hash_what,
8394 		(void *)&cmd_set_uc_hash_mac,
8395 		(void *)&cmd_set_uc_hash_mode,
8396 		NULL,
8397 	},
8398 };
8399 
8400 struct cmd_set_uc_all_hash_table {
8401 	cmdline_fixed_string_t set;
8402 	cmdline_fixed_string_t port;
8403 	portid_t port_id;
8404 	cmdline_fixed_string_t what;
8405 	cmdline_fixed_string_t value;
8406 	cmdline_fixed_string_t mode;
8407 };
8408 
8409 static void
8410 cmd_set_uc_all_hash_parsed(void *parsed_result,
8411 		       __rte_unused struct cmdline *cl,
8412 		       __rte_unused void *data)
8413 {
8414 	int ret=0;
8415 	struct cmd_set_uc_all_hash_table *res = parsed_result;
8416 
8417 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8418 
8419 	if ((strcmp(res->what, "uta") == 0) &&
8420 		(strcmp(res->value, "all") == 0))
8421 		ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8422 	if (ret < 0)
8423 		printf("bad unicast hash table parameter,"
8424 			"return code = %d \n", ret);
8425 }
8426 
8427 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8428 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8429 				 set, "set");
8430 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8431 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8432 				 port, "port");
8433 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8434 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8435 			      port_id, UINT16);
8436 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8437 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8438 				 what, "uta");
8439 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8440 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8441 				value,"all");
8442 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8443 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8444 				 mode, "on#off");
8445 
8446 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8447 	.f = cmd_set_uc_all_hash_parsed,
8448 	.data = NULL,
8449 	.help_str = "set port <port_id> uta all on|off",
8450 	.tokens = {
8451 		(void *)&cmd_set_uc_all_hash_set,
8452 		(void *)&cmd_set_uc_all_hash_port,
8453 		(void *)&cmd_set_uc_all_hash_portid,
8454 		(void *)&cmd_set_uc_all_hash_what,
8455 		(void *)&cmd_set_uc_all_hash_value,
8456 		(void *)&cmd_set_uc_all_hash_mode,
8457 		NULL,
8458 	},
8459 };
8460 
8461 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8462 struct cmd_set_vf_macvlan_filter {
8463 	cmdline_fixed_string_t set;
8464 	cmdline_fixed_string_t port;
8465 	portid_t port_id;
8466 	cmdline_fixed_string_t vf;
8467 	uint8_t vf_id;
8468 	struct rte_ether_addr address;
8469 	cmdline_fixed_string_t filter_type;
8470 	cmdline_fixed_string_t mode;
8471 };
8472 
8473 static void
8474 cmd_set_vf_macvlan_parsed(void *parsed_result,
8475 		       __rte_unused struct cmdline *cl,
8476 		       __rte_unused void *data)
8477 {
8478 	int is_on, ret = 0;
8479 	struct cmd_set_vf_macvlan_filter *res = parsed_result;
8480 	struct rte_eth_mac_filter filter;
8481 
8482 	memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8483 
8484 	rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8485 
8486 	/* set VF MAC filter */
8487 	filter.is_vf = 1;
8488 
8489 	/* set VF ID */
8490 	filter.dst_id = res->vf_id;
8491 
8492 	if (!strcmp(res->filter_type, "exact-mac"))
8493 		filter.filter_type = RTE_MAC_PERFECT_MATCH;
8494 	else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8495 		filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8496 	else if (!strcmp(res->filter_type, "hashmac"))
8497 		filter.filter_type = RTE_MAC_HASH_MATCH;
8498 	else if (!strcmp(res->filter_type, "hashmac-vlan"))
8499 		filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8500 
8501 	is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8502 
8503 	if (is_on)
8504 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8505 					RTE_ETH_FILTER_MACVLAN,
8506 					RTE_ETH_FILTER_ADD,
8507 					 &filter);
8508 	else
8509 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8510 					RTE_ETH_FILTER_MACVLAN,
8511 					RTE_ETH_FILTER_DELETE,
8512 					&filter);
8513 
8514 	if (ret < 0)
8515 		printf("bad set MAC hash parameter, return code = %d\n", ret);
8516 
8517 }
8518 
8519 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8520 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8521 				 set, "set");
8522 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8523 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8524 				 port, "port");
8525 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8526 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8527 			      port_id, UINT16);
8528 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8529 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8530 				 vf, "vf");
8531 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8532 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8533 				vf_id, UINT8);
8534 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8535 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8536 				address);
8537 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8538 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8539 				filter_type, "exact-mac#exact-mac-vlan"
8540 				"#hashmac#hashmac-vlan");
8541 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8542 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8543 				 mode, "on#off");
8544 
8545 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8546 	.f = cmd_set_vf_macvlan_parsed,
8547 	.data = NULL,
8548 	.help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8549 		"exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8550 		"Exact match rule: exact match of MAC or MAC and VLAN; "
8551 		"hash match rule: hash match of MAC and exact match of VLAN",
8552 	.tokens = {
8553 		(void *)&cmd_set_vf_macvlan_set,
8554 		(void *)&cmd_set_vf_macvlan_port,
8555 		(void *)&cmd_set_vf_macvlan_portid,
8556 		(void *)&cmd_set_vf_macvlan_vf,
8557 		(void *)&cmd_set_vf_macvlan_vf_id,
8558 		(void *)&cmd_set_vf_macvlan_mac,
8559 		(void *)&cmd_set_vf_macvlan_filter_type,
8560 		(void *)&cmd_set_vf_macvlan_mode,
8561 		NULL,
8562 	},
8563 };
8564 
8565 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8566 struct cmd_set_vf_traffic {
8567 	cmdline_fixed_string_t set;
8568 	cmdline_fixed_string_t port;
8569 	portid_t port_id;
8570 	cmdline_fixed_string_t vf;
8571 	uint8_t vf_id;
8572 	cmdline_fixed_string_t what;
8573 	cmdline_fixed_string_t mode;
8574 };
8575 
8576 static void
8577 cmd_set_vf_traffic_parsed(void *parsed_result,
8578 		       __rte_unused struct cmdline *cl,
8579 		       __rte_unused void *data)
8580 {
8581 	struct cmd_set_vf_traffic *res = parsed_result;
8582 	int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8583 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8584 
8585 	set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8586 }
8587 
8588 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8589 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8590 				 set, "set");
8591 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8592 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8593 				 port, "port");
8594 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8595 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8596 			      port_id, UINT16);
8597 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8598 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8599 				 vf, "vf");
8600 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8601 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8602 			      vf_id, UINT8);
8603 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8604 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8605 				 what, "tx#rx");
8606 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8607 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8608 				 mode, "on#off");
8609 
8610 cmdline_parse_inst_t cmd_set_vf_traffic = {
8611 	.f = cmd_set_vf_traffic_parsed,
8612 	.data = NULL,
8613 	.help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8614 	.tokens = {
8615 		(void *)&cmd_setvf_traffic_set,
8616 		(void *)&cmd_setvf_traffic_port,
8617 		(void *)&cmd_setvf_traffic_portid,
8618 		(void *)&cmd_setvf_traffic_vf,
8619 		(void *)&cmd_setvf_traffic_vfid,
8620 		(void *)&cmd_setvf_traffic_what,
8621 		(void *)&cmd_setvf_traffic_mode,
8622 		NULL,
8623 	},
8624 };
8625 
8626 /* *** CONFIGURE VF RECEIVE MODE *** */
8627 struct cmd_set_vf_rxmode {
8628 	cmdline_fixed_string_t set;
8629 	cmdline_fixed_string_t port;
8630 	portid_t port_id;
8631 	cmdline_fixed_string_t vf;
8632 	uint8_t vf_id;
8633 	cmdline_fixed_string_t what;
8634 	cmdline_fixed_string_t mode;
8635 	cmdline_fixed_string_t on;
8636 };
8637 
8638 static void
8639 cmd_set_vf_rxmode_parsed(void *parsed_result,
8640 		       __rte_unused struct cmdline *cl,
8641 		       __rte_unused void *data)
8642 {
8643 	int ret = -ENOTSUP;
8644 	uint16_t vf_rxmode = 0;
8645 	struct cmd_set_vf_rxmode *res = parsed_result;
8646 
8647 	int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8648 	if (!strcmp(res->what,"rxmode")) {
8649 		if (!strcmp(res->mode, "AUPE"))
8650 			vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8651 		else if (!strcmp(res->mode, "ROPE"))
8652 			vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8653 		else if (!strcmp(res->mode, "BAM"))
8654 			vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8655 		else if (!strncmp(res->mode, "MPE",3))
8656 			vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8657 	}
8658 
8659 	RTE_SET_USED(is_on);
8660 
8661 #ifdef RTE_LIBRTE_IXGBE_PMD
8662 	if (ret == -ENOTSUP)
8663 		ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8664 						  vf_rxmode, (uint8_t)is_on);
8665 #endif
8666 #ifdef RTE_LIBRTE_BNXT_PMD
8667 	if (ret == -ENOTSUP)
8668 		ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8669 						 vf_rxmode, (uint8_t)is_on);
8670 #endif
8671 	if (ret < 0)
8672 		printf("bad VF receive mode parameter, return code = %d \n",
8673 		ret);
8674 }
8675 
8676 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8677 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8678 				 set, "set");
8679 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8680 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8681 				 port, "port");
8682 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8683 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8684 			      port_id, UINT16);
8685 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8686 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8687 				 vf, "vf");
8688 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8689 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8690 			      vf_id, UINT8);
8691 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8692 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8693 				 what, "rxmode");
8694 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8695 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8696 				 mode, "AUPE#ROPE#BAM#MPE");
8697 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8698 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8699 				 on, "on#off");
8700 
8701 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8702 	.f = cmd_set_vf_rxmode_parsed,
8703 	.data = NULL,
8704 	.help_str = "set port <port_id> vf <vf_id> rxmode "
8705 		"AUPE|ROPE|BAM|MPE on|off",
8706 	.tokens = {
8707 		(void *)&cmd_set_vf_rxmode_set,
8708 		(void *)&cmd_set_vf_rxmode_port,
8709 		(void *)&cmd_set_vf_rxmode_portid,
8710 		(void *)&cmd_set_vf_rxmode_vf,
8711 		(void *)&cmd_set_vf_rxmode_vfid,
8712 		(void *)&cmd_set_vf_rxmode_what,
8713 		(void *)&cmd_set_vf_rxmode_mode,
8714 		(void *)&cmd_set_vf_rxmode_on,
8715 		NULL,
8716 	},
8717 };
8718 
8719 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8720 struct cmd_vf_mac_addr_result {
8721 	cmdline_fixed_string_t mac_addr_cmd;
8722 	cmdline_fixed_string_t what;
8723 	cmdline_fixed_string_t port;
8724 	uint16_t port_num;
8725 	cmdline_fixed_string_t vf;
8726 	uint8_t vf_num;
8727 	struct rte_ether_addr address;
8728 };
8729 
8730 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8731 		__rte_unused struct cmdline *cl,
8732 		__rte_unused void *data)
8733 {
8734 	struct cmd_vf_mac_addr_result *res = parsed_result;
8735 	int ret = -ENOTSUP;
8736 
8737 	if (strcmp(res->what, "add") != 0)
8738 		return;
8739 
8740 #ifdef RTE_LIBRTE_I40E_PMD
8741 	if (ret == -ENOTSUP)
8742 		ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8743 						   &res->address);
8744 #endif
8745 #ifdef RTE_LIBRTE_BNXT_PMD
8746 	if (ret == -ENOTSUP)
8747 		ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8748 						res->vf_num);
8749 #endif
8750 
8751 	if(ret < 0)
8752 		printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8753 
8754 }
8755 
8756 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8757 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8758 				mac_addr_cmd,"mac_addr");
8759 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8760 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8761 				what,"add");
8762 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8763 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8764 				port,"port");
8765 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8766 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8767 				port_num, UINT16);
8768 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8769 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8770 				vf,"vf");
8771 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8772 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8773 				vf_num, UINT8);
8774 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8775 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8776 				address);
8777 
8778 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8779 	.f = cmd_vf_mac_addr_parsed,
8780 	.data = (void *)0,
8781 	.help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8782 		"Add MAC address filtering for a VF on port_id",
8783 	.tokens = {
8784 		(void *)&cmd_vf_mac_addr_cmd,
8785 		(void *)&cmd_vf_mac_addr_what,
8786 		(void *)&cmd_vf_mac_addr_port,
8787 		(void *)&cmd_vf_mac_addr_portnum,
8788 		(void *)&cmd_vf_mac_addr_vf,
8789 		(void *)&cmd_vf_mac_addr_vfnum,
8790 		(void *)&cmd_vf_mac_addr_addr,
8791 		NULL,
8792 	},
8793 };
8794 
8795 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8796 struct cmd_vf_rx_vlan_filter {
8797 	cmdline_fixed_string_t rx_vlan;
8798 	cmdline_fixed_string_t what;
8799 	uint16_t vlan_id;
8800 	cmdline_fixed_string_t port;
8801 	portid_t port_id;
8802 	cmdline_fixed_string_t vf;
8803 	uint64_t vf_mask;
8804 };
8805 
8806 static void
8807 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8808 			  __rte_unused struct cmdline *cl,
8809 			  __rte_unused void *data)
8810 {
8811 	struct cmd_vf_rx_vlan_filter *res = parsed_result;
8812 	int ret = -ENOTSUP;
8813 
8814 	__rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8815 
8816 #ifdef RTE_LIBRTE_IXGBE_PMD
8817 	if (ret == -ENOTSUP)
8818 		ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8819 				res->vlan_id, res->vf_mask, is_add);
8820 #endif
8821 #ifdef RTE_LIBRTE_I40E_PMD
8822 	if (ret == -ENOTSUP)
8823 		ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8824 				res->vlan_id, res->vf_mask, is_add);
8825 #endif
8826 #ifdef RTE_LIBRTE_BNXT_PMD
8827 	if (ret == -ENOTSUP)
8828 		ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8829 				res->vlan_id, res->vf_mask, is_add);
8830 #endif
8831 
8832 	switch (ret) {
8833 	case 0:
8834 		break;
8835 	case -EINVAL:
8836 		printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8837 				res->vlan_id, res->vf_mask);
8838 		break;
8839 	case -ENODEV:
8840 		printf("invalid port_id %d\n", res->port_id);
8841 		break;
8842 	case -ENOTSUP:
8843 		printf("function not implemented or supported\n");
8844 		break;
8845 	default:
8846 		printf("programming error: (%s)\n", strerror(-ret));
8847 	}
8848 }
8849 
8850 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8851 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8852 				 rx_vlan, "rx_vlan");
8853 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8854 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8855 				 what, "add#rm");
8856 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8857 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8858 			      vlan_id, UINT16);
8859 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8860 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8861 				 port, "port");
8862 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8863 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8864 			      port_id, UINT16);
8865 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8866 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8867 				 vf, "vf");
8868 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8869 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8870 			      vf_mask, UINT64);
8871 
8872 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8873 	.f = cmd_vf_rx_vlan_filter_parsed,
8874 	.data = NULL,
8875 	.help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8876 		"(vf_mask = hexadecimal VF mask)",
8877 	.tokens = {
8878 		(void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8879 		(void *)&cmd_vf_rx_vlan_filter_what,
8880 		(void *)&cmd_vf_rx_vlan_filter_vlanid,
8881 		(void *)&cmd_vf_rx_vlan_filter_port,
8882 		(void *)&cmd_vf_rx_vlan_filter_portid,
8883 		(void *)&cmd_vf_rx_vlan_filter_vf,
8884 		(void *)&cmd_vf_rx_vlan_filter_vf_mask,
8885 		NULL,
8886 	},
8887 };
8888 
8889 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8890 struct cmd_queue_rate_limit_result {
8891 	cmdline_fixed_string_t set;
8892 	cmdline_fixed_string_t port;
8893 	uint16_t port_num;
8894 	cmdline_fixed_string_t queue;
8895 	uint8_t queue_num;
8896 	cmdline_fixed_string_t rate;
8897 	uint16_t rate_num;
8898 };
8899 
8900 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8901 		__rte_unused struct cmdline *cl,
8902 		__rte_unused void *data)
8903 {
8904 	struct cmd_queue_rate_limit_result *res = parsed_result;
8905 	int ret = 0;
8906 
8907 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8908 		&& (strcmp(res->queue, "queue") == 0)
8909 		&& (strcmp(res->rate, "rate") == 0))
8910 		ret = set_queue_rate_limit(res->port_num, res->queue_num,
8911 					res->rate_num);
8912 	if (ret < 0)
8913 		printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8914 
8915 }
8916 
8917 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8918 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8919 				set, "set");
8920 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8921 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8922 				port, "port");
8923 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8924 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8925 				port_num, UINT16);
8926 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8927 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8928 				queue, "queue");
8929 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8930 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8931 				queue_num, UINT8);
8932 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8933 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8934 				rate, "rate");
8935 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8936 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8937 				rate_num, UINT16);
8938 
8939 cmdline_parse_inst_t cmd_queue_rate_limit = {
8940 	.f = cmd_queue_rate_limit_parsed,
8941 	.data = (void *)0,
8942 	.help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8943 		"Set rate limit for a queue on port_id",
8944 	.tokens = {
8945 		(void *)&cmd_queue_rate_limit_set,
8946 		(void *)&cmd_queue_rate_limit_port,
8947 		(void *)&cmd_queue_rate_limit_portnum,
8948 		(void *)&cmd_queue_rate_limit_queue,
8949 		(void *)&cmd_queue_rate_limit_queuenum,
8950 		(void *)&cmd_queue_rate_limit_rate,
8951 		(void *)&cmd_queue_rate_limit_ratenum,
8952 		NULL,
8953 	},
8954 };
8955 
8956 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8957 struct cmd_vf_rate_limit_result {
8958 	cmdline_fixed_string_t set;
8959 	cmdline_fixed_string_t port;
8960 	uint16_t port_num;
8961 	cmdline_fixed_string_t vf;
8962 	uint8_t vf_num;
8963 	cmdline_fixed_string_t rate;
8964 	uint16_t rate_num;
8965 	cmdline_fixed_string_t q_msk;
8966 	uint64_t q_msk_val;
8967 };
8968 
8969 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8970 		__rte_unused struct cmdline *cl,
8971 		__rte_unused void *data)
8972 {
8973 	struct cmd_vf_rate_limit_result *res = parsed_result;
8974 	int ret = 0;
8975 
8976 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8977 		&& (strcmp(res->vf, "vf") == 0)
8978 		&& (strcmp(res->rate, "rate") == 0)
8979 		&& (strcmp(res->q_msk, "queue_mask") == 0))
8980 		ret = set_vf_rate_limit(res->port_num, res->vf_num,
8981 					res->rate_num, res->q_msk_val);
8982 	if (ret < 0)
8983 		printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8984 
8985 }
8986 
8987 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8988 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8989 				set, "set");
8990 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8991 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8992 				port, "port");
8993 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8994 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8995 				port_num, UINT16);
8996 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8997 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8998 				vf, "vf");
8999 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9000 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9001 				vf_num, UINT8);
9002 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9003 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9004 				rate, "rate");
9005 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9006 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9007 				rate_num, UINT16);
9008 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9009 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9010 				q_msk, "queue_mask");
9011 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9012 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9013 				q_msk_val, UINT64);
9014 
9015 cmdline_parse_inst_t cmd_vf_rate_limit = {
9016 	.f = cmd_vf_rate_limit_parsed,
9017 	.data = (void *)0,
9018 	.help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9019 		"queue_mask <queue_mask_value>: "
9020 		"Set rate limit for queues of VF on port_id",
9021 	.tokens = {
9022 		(void *)&cmd_vf_rate_limit_set,
9023 		(void *)&cmd_vf_rate_limit_port,
9024 		(void *)&cmd_vf_rate_limit_portnum,
9025 		(void *)&cmd_vf_rate_limit_vf,
9026 		(void *)&cmd_vf_rate_limit_vfnum,
9027 		(void *)&cmd_vf_rate_limit_rate,
9028 		(void *)&cmd_vf_rate_limit_ratenum,
9029 		(void *)&cmd_vf_rate_limit_q_msk,
9030 		(void *)&cmd_vf_rate_limit_q_msk_val,
9031 		NULL,
9032 	},
9033 };
9034 
9035 /* *** ADD TUNNEL FILTER OF A PORT *** */
9036 struct cmd_tunnel_filter_result {
9037 	cmdline_fixed_string_t cmd;
9038 	cmdline_fixed_string_t what;
9039 	portid_t port_id;
9040 	struct rte_ether_addr outer_mac;
9041 	struct rte_ether_addr inner_mac;
9042 	cmdline_ipaddr_t ip_value;
9043 	uint16_t inner_vlan;
9044 	cmdline_fixed_string_t tunnel_type;
9045 	cmdline_fixed_string_t filter_type;
9046 	uint32_t tenant_id;
9047 	uint16_t queue_num;
9048 };
9049 
9050 static void
9051 cmd_tunnel_filter_parsed(void *parsed_result,
9052 			  __rte_unused struct cmdline *cl,
9053 			  __rte_unused void *data)
9054 {
9055 	struct cmd_tunnel_filter_result *res = parsed_result;
9056 	struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
9057 	int ret = 0;
9058 
9059 	memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9060 
9061 	rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9062 	rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9063 	tunnel_filter_conf.inner_vlan = res->inner_vlan;
9064 
9065 	if (res->ip_value.family == AF_INET) {
9066 		tunnel_filter_conf.ip_addr.ipv4_addr =
9067 			res->ip_value.addr.ipv4.s_addr;
9068 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9069 	} else {
9070 		memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9071 			&(res->ip_value.addr.ipv6),
9072 			sizeof(struct in6_addr));
9073 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9074 	}
9075 
9076 	if (!strcmp(res->filter_type, "imac-ivlan"))
9077 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9078 	else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9079 		tunnel_filter_conf.filter_type =
9080 			RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9081 	else if (!strcmp(res->filter_type, "imac-tenid"))
9082 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9083 	else if (!strcmp(res->filter_type, "imac"))
9084 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9085 	else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9086 		tunnel_filter_conf.filter_type =
9087 			RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9088 	else if (!strcmp(res->filter_type, "oip"))
9089 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9090 	else if (!strcmp(res->filter_type, "iip"))
9091 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9092 	else {
9093 		printf("The filter type is not supported");
9094 		return;
9095 	}
9096 
9097 	if (!strcmp(res->tunnel_type, "vxlan"))
9098 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9099 	else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9100 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9101 	else if (!strcmp(res->tunnel_type, "nvgre"))
9102 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9103 	else if (!strcmp(res->tunnel_type, "ipingre"))
9104 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9105 	else {
9106 		printf("The tunnel type %s not supported.\n", res->tunnel_type);
9107 		return;
9108 	}
9109 
9110 	tunnel_filter_conf.tenant_id = res->tenant_id;
9111 	tunnel_filter_conf.queue_id = res->queue_num;
9112 	if (!strcmp(res->what, "add"))
9113 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9114 					RTE_ETH_FILTER_TUNNEL,
9115 					RTE_ETH_FILTER_ADD,
9116 					&tunnel_filter_conf);
9117 	else
9118 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9119 					RTE_ETH_FILTER_TUNNEL,
9120 					RTE_ETH_FILTER_DELETE,
9121 					&tunnel_filter_conf);
9122 	if (ret < 0)
9123 		printf("cmd_tunnel_filter_parsed error: (%s)\n",
9124 				strerror(-ret));
9125 
9126 }
9127 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9128 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9129 	cmd, "tunnel_filter");
9130 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9131 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9132 	what, "add#rm");
9133 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9134 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9135 	port_id, UINT16);
9136 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9137 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9138 	outer_mac);
9139 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9140 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9141 	inner_mac);
9142 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9143 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9144 	inner_vlan, UINT16);
9145 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9146 	TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9147 	ip_value);
9148 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9149 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9150 	tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9151 
9152 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9153 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9154 	filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9155 		"imac#omac-imac-tenid");
9156 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9157 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9158 	tenant_id, UINT32);
9159 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9160 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9161 	queue_num, UINT16);
9162 
9163 cmdline_parse_inst_t cmd_tunnel_filter = {
9164 	.f = cmd_tunnel_filter_parsed,
9165 	.data = (void *)0,
9166 	.help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9167 		"<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9168 		"imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9169 		"<queue_id>: Add/Rm tunnel filter of a port",
9170 	.tokens = {
9171 		(void *)&cmd_tunnel_filter_cmd,
9172 		(void *)&cmd_tunnel_filter_what,
9173 		(void *)&cmd_tunnel_filter_port_id,
9174 		(void *)&cmd_tunnel_filter_outer_mac,
9175 		(void *)&cmd_tunnel_filter_inner_mac,
9176 		(void *)&cmd_tunnel_filter_ip_value,
9177 		(void *)&cmd_tunnel_filter_innner_vlan,
9178 		(void *)&cmd_tunnel_filter_tunnel_type,
9179 		(void *)&cmd_tunnel_filter_filter_type,
9180 		(void *)&cmd_tunnel_filter_tenant_id,
9181 		(void *)&cmd_tunnel_filter_queue_num,
9182 		NULL,
9183 	},
9184 };
9185 
9186 /* *** CONFIGURE TUNNEL UDP PORT *** */
9187 struct cmd_tunnel_udp_config {
9188 	cmdline_fixed_string_t cmd;
9189 	cmdline_fixed_string_t what;
9190 	uint16_t udp_port;
9191 	portid_t port_id;
9192 };
9193 
9194 static void
9195 cmd_tunnel_udp_config_parsed(void *parsed_result,
9196 			  __rte_unused struct cmdline *cl,
9197 			  __rte_unused void *data)
9198 {
9199 	struct cmd_tunnel_udp_config *res = parsed_result;
9200 	struct rte_eth_udp_tunnel tunnel_udp;
9201 	int ret;
9202 
9203 	tunnel_udp.udp_port = res->udp_port;
9204 
9205 	if (!strcmp(res->cmd, "rx_vxlan_port"))
9206 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9207 
9208 	if (!strcmp(res->what, "add"))
9209 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9210 						      &tunnel_udp);
9211 	else
9212 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9213 							 &tunnel_udp);
9214 
9215 	if (ret < 0)
9216 		printf("udp tunneling add error: (%s)\n", strerror(-ret));
9217 }
9218 
9219 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9220 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9221 				cmd, "rx_vxlan_port");
9222 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9223 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9224 				what, "add#rm");
9225 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9226 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9227 				udp_port, UINT16);
9228 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9229 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9230 				port_id, UINT16);
9231 
9232 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9233 	.f = cmd_tunnel_udp_config_parsed,
9234 	.data = (void *)0,
9235 	.help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9236 		"Add/Remove a tunneling UDP port filter",
9237 	.tokens = {
9238 		(void *)&cmd_tunnel_udp_config_cmd,
9239 		(void *)&cmd_tunnel_udp_config_what,
9240 		(void *)&cmd_tunnel_udp_config_udp_port,
9241 		(void *)&cmd_tunnel_udp_config_port_id,
9242 		NULL,
9243 	},
9244 };
9245 
9246 struct cmd_config_tunnel_udp_port {
9247 	cmdline_fixed_string_t port;
9248 	cmdline_fixed_string_t config;
9249 	portid_t port_id;
9250 	cmdline_fixed_string_t udp_tunnel_port;
9251 	cmdline_fixed_string_t action;
9252 	cmdline_fixed_string_t tunnel_type;
9253 	uint16_t udp_port;
9254 };
9255 
9256 static void
9257 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9258 			       __rte_unused struct cmdline *cl,
9259 			       __rte_unused void *data)
9260 {
9261 	struct cmd_config_tunnel_udp_port *res = parsed_result;
9262 	struct rte_eth_udp_tunnel tunnel_udp;
9263 	int ret = 0;
9264 
9265 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9266 		return;
9267 
9268 	tunnel_udp.udp_port = res->udp_port;
9269 
9270 	if (!strcmp(res->tunnel_type, "vxlan")) {
9271 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9272 	} else if (!strcmp(res->tunnel_type, "geneve")) {
9273 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9274 	} else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9275 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9276 	} else {
9277 		printf("Invalid tunnel type\n");
9278 		return;
9279 	}
9280 
9281 	if (!strcmp(res->action, "add"))
9282 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9283 						      &tunnel_udp);
9284 	else
9285 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9286 							 &tunnel_udp);
9287 
9288 	if (ret < 0)
9289 		printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9290 }
9291 
9292 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9293 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9294 				 "port");
9295 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9296 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9297 				 "config");
9298 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9299 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9300 			      UINT16);
9301 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9302 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9303 				 udp_tunnel_port,
9304 				 "udp_tunnel_port");
9305 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9306 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9307 				 "add#rm");
9308 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9309 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9310 				 "vxlan#geneve#vxlan-gpe");
9311 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9312 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9313 			      UINT16);
9314 
9315 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9316 	.f = cmd_cfg_tunnel_udp_port_parsed,
9317 	.data = NULL,
9318 	.help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9319 	.tokens = {
9320 		(void *)&cmd_config_tunnel_udp_port_port,
9321 		(void *)&cmd_config_tunnel_udp_port_config,
9322 		(void *)&cmd_config_tunnel_udp_port_port_id,
9323 		(void *)&cmd_config_tunnel_udp_port_tunnel_port,
9324 		(void *)&cmd_config_tunnel_udp_port_action,
9325 		(void *)&cmd_config_tunnel_udp_port_tunnel_type,
9326 		(void *)&cmd_config_tunnel_udp_port_value,
9327 		NULL,
9328 	},
9329 };
9330 
9331 /* *** GLOBAL CONFIG *** */
9332 struct cmd_global_config_result {
9333 	cmdline_fixed_string_t cmd;
9334 	portid_t port_id;
9335 	cmdline_fixed_string_t cfg_type;
9336 	uint8_t len;
9337 };
9338 
9339 static void
9340 cmd_global_config_parsed(void *parsed_result,
9341 			 __rte_unused struct cmdline *cl,
9342 			 __rte_unused void *data)
9343 {
9344 	struct cmd_global_config_result *res = parsed_result;
9345 	struct rte_eth_global_cfg conf;
9346 	int ret;
9347 
9348 	memset(&conf, 0, sizeof(conf));
9349 	conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9350 	conf.cfg.gre_key_len = res->len;
9351 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9352 				      RTE_ETH_FILTER_SET, &conf);
9353 #ifdef RTE_LIBRTE_I40E_PMD
9354 	if (ret == -ENOTSUP)
9355 		ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9356 #endif
9357 	if (ret != 0)
9358 		printf("Global config error\n");
9359 }
9360 
9361 cmdline_parse_token_string_t cmd_global_config_cmd =
9362 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9363 		"global_config");
9364 cmdline_parse_token_num_t cmd_global_config_port_id =
9365 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9366 			       UINT16);
9367 cmdline_parse_token_string_t cmd_global_config_type =
9368 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9369 		cfg_type, "gre-key-len");
9370 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9371 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9372 		len, UINT8);
9373 
9374 cmdline_parse_inst_t cmd_global_config = {
9375 	.f = cmd_global_config_parsed,
9376 	.data = (void *)NULL,
9377 	.help_str = "global_config <port_id> gre-key-len <key_len>",
9378 	.tokens = {
9379 		(void *)&cmd_global_config_cmd,
9380 		(void *)&cmd_global_config_port_id,
9381 		(void *)&cmd_global_config_type,
9382 		(void *)&cmd_global_config_gre_key_len,
9383 		NULL,
9384 	},
9385 };
9386 
9387 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9388 struct cmd_set_mirror_mask_result {
9389 	cmdline_fixed_string_t set;
9390 	cmdline_fixed_string_t port;
9391 	portid_t port_id;
9392 	cmdline_fixed_string_t mirror;
9393 	uint8_t rule_id;
9394 	cmdline_fixed_string_t what;
9395 	cmdline_fixed_string_t value;
9396 	cmdline_fixed_string_t dstpool;
9397 	uint8_t dstpool_id;
9398 	cmdline_fixed_string_t on;
9399 };
9400 
9401 cmdline_parse_token_string_t cmd_mirror_mask_set =
9402 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9403 				set, "set");
9404 cmdline_parse_token_string_t cmd_mirror_mask_port =
9405 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9406 				port, "port");
9407 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9408 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9409 				port_id, UINT16);
9410 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9411 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9412 				mirror, "mirror-rule");
9413 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9414 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9415 				rule_id, UINT8);
9416 cmdline_parse_token_string_t cmd_mirror_mask_what =
9417 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9418 				what, "pool-mirror-up#pool-mirror-down"
9419 				      "#vlan-mirror");
9420 cmdline_parse_token_string_t cmd_mirror_mask_value =
9421 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9422 				value, NULL);
9423 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9424 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9425 				dstpool, "dst-pool");
9426 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9427 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9428 				dstpool_id, UINT8);
9429 cmdline_parse_token_string_t cmd_mirror_mask_on =
9430 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9431 				on, "on#off");
9432 
9433 static void
9434 cmd_set_mirror_mask_parsed(void *parsed_result,
9435 		       __rte_unused struct cmdline *cl,
9436 		       __rte_unused void *data)
9437 {
9438 	int ret,nb_item,i;
9439 	struct cmd_set_mirror_mask_result *res = parsed_result;
9440 	struct rte_eth_mirror_conf mr_conf;
9441 
9442 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9443 
9444 	unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9445 
9446 	mr_conf.dst_pool = res->dstpool_id;
9447 
9448 	if (!strcmp(res->what, "pool-mirror-up")) {
9449 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9450 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9451 	} else if (!strcmp(res->what, "pool-mirror-down")) {
9452 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9453 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9454 	} else if (!strcmp(res->what, "vlan-mirror")) {
9455 		mr_conf.rule_type = ETH_MIRROR_VLAN;
9456 		nb_item = parse_item_list(res->value, "vlan",
9457 				ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9458 		if (nb_item <= 0)
9459 			return;
9460 
9461 		for (i = 0; i < nb_item; i++) {
9462 			if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9463 				printf("Invalid vlan_id: must be < 4096\n");
9464 				return;
9465 			}
9466 
9467 			mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9468 			mr_conf.vlan.vlan_mask |= 1ULL << i;
9469 		}
9470 	}
9471 
9472 	if (!strcmp(res->on, "on"))
9473 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9474 						res->rule_id, 1);
9475 	else
9476 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9477 						res->rule_id, 0);
9478 	if (ret < 0)
9479 		printf("mirror rule add error: (%s)\n", strerror(-ret));
9480 }
9481 
9482 cmdline_parse_inst_t cmd_set_mirror_mask = {
9483 		.f = cmd_set_mirror_mask_parsed,
9484 		.data = NULL,
9485 		.help_str = "set port <port_id> mirror-rule <rule_id> "
9486 			"pool-mirror-up|pool-mirror-down|vlan-mirror "
9487 			"<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9488 		.tokens = {
9489 			(void *)&cmd_mirror_mask_set,
9490 			(void *)&cmd_mirror_mask_port,
9491 			(void *)&cmd_mirror_mask_portid,
9492 			(void *)&cmd_mirror_mask_mirror,
9493 			(void *)&cmd_mirror_mask_ruleid,
9494 			(void *)&cmd_mirror_mask_what,
9495 			(void *)&cmd_mirror_mask_value,
9496 			(void *)&cmd_mirror_mask_dstpool,
9497 			(void *)&cmd_mirror_mask_poolid,
9498 			(void *)&cmd_mirror_mask_on,
9499 			NULL,
9500 		},
9501 };
9502 
9503 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9504 struct cmd_set_mirror_link_result {
9505 	cmdline_fixed_string_t set;
9506 	cmdline_fixed_string_t port;
9507 	portid_t port_id;
9508 	cmdline_fixed_string_t mirror;
9509 	uint8_t rule_id;
9510 	cmdline_fixed_string_t what;
9511 	cmdline_fixed_string_t dstpool;
9512 	uint8_t dstpool_id;
9513 	cmdline_fixed_string_t on;
9514 };
9515 
9516 cmdline_parse_token_string_t cmd_mirror_link_set =
9517 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9518 				 set, "set");
9519 cmdline_parse_token_string_t cmd_mirror_link_port =
9520 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9521 				port, "port");
9522 cmdline_parse_token_num_t cmd_mirror_link_portid =
9523 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9524 				port_id, UINT16);
9525 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9526 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9527 				mirror, "mirror-rule");
9528 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9529 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9530 			    rule_id, UINT8);
9531 cmdline_parse_token_string_t cmd_mirror_link_what =
9532 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9533 				what, "uplink-mirror#downlink-mirror");
9534 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9535 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9536 				dstpool, "dst-pool");
9537 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9538 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9539 				dstpool_id, UINT8);
9540 cmdline_parse_token_string_t cmd_mirror_link_on =
9541 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9542 				on, "on#off");
9543 
9544 static void
9545 cmd_set_mirror_link_parsed(void *parsed_result,
9546 		       __rte_unused struct cmdline *cl,
9547 		       __rte_unused void *data)
9548 {
9549 	int ret;
9550 	struct cmd_set_mirror_link_result *res = parsed_result;
9551 	struct rte_eth_mirror_conf mr_conf;
9552 
9553 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9554 	if (!strcmp(res->what, "uplink-mirror"))
9555 		mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9556 	else
9557 		mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9558 
9559 	mr_conf.dst_pool = res->dstpool_id;
9560 
9561 	if (!strcmp(res->on, "on"))
9562 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9563 						res->rule_id, 1);
9564 	else
9565 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9566 						res->rule_id, 0);
9567 
9568 	/* check the return value and print it if is < 0 */
9569 	if (ret < 0)
9570 		printf("mirror rule add error: (%s)\n", strerror(-ret));
9571 
9572 }
9573 
9574 cmdline_parse_inst_t cmd_set_mirror_link = {
9575 		.f = cmd_set_mirror_link_parsed,
9576 		.data = NULL,
9577 		.help_str = "set port <port_id> mirror-rule <rule_id> "
9578 			"uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9579 		.tokens = {
9580 			(void *)&cmd_mirror_link_set,
9581 			(void *)&cmd_mirror_link_port,
9582 			(void *)&cmd_mirror_link_portid,
9583 			(void *)&cmd_mirror_link_mirror,
9584 			(void *)&cmd_mirror_link_ruleid,
9585 			(void *)&cmd_mirror_link_what,
9586 			(void *)&cmd_mirror_link_dstpool,
9587 			(void *)&cmd_mirror_link_poolid,
9588 			(void *)&cmd_mirror_link_on,
9589 			NULL,
9590 		},
9591 };
9592 
9593 /* *** RESET VM MIRROR RULE *** */
9594 struct cmd_rm_mirror_rule_result {
9595 	cmdline_fixed_string_t reset;
9596 	cmdline_fixed_string_t port;
9597 	portid_t port_id;
9598 	cmdline_fixed_string_t mirror;
9599 	uint8_t rule_id;
9600 };
9601 
9602 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9603 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9604 				 reset, "reset");
9605 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9606 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9607 				port, "port");
9608 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9609 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9610 				port_id, UINT16);
9611 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9612 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9613 				mirror, "mirror-rule");
9614 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9615 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9616 				rule_id, UINT8);
9617 
9618 static void
9619 cmd_reset_mirror_rule_parsed(void *parsed_result,
9620 		       __rte_unused struct cmdline *cl,
9621 		       __rte_unused void *data)
9622 {
9623 	int ret;
9624 	struct cmd_set_mirror_link_result *res = parsed_result;
9625         /* check rule_id */
9626 	ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9627 	if(ret < 0)
9628 		printf("mirror rule remove error: (%s)\n", strerror(-ret));
9629 }
9630 
9631 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9632 		.f = cmd_reset_mirror_rule_parsed,
9633 		.data = NULL,
9634 		.help_str = "reset port <port_id> mirror-rule <rule_id>",
9635 		.tokens = {
9636 			(void *)&cmd_rm_mirror_rule_reset,
9637 			(void *)&cmd_rm_mirror_rule_port,
9638 			(void *)&cmd_rm_mirror_rule_portid,
9639 			(void *)&cmd_rm_mirror_rule_mirror,
9640 			(void *)&cmd_rm_mirror_rule_ruleid,
9641 			NULL,
9642 		},
9643 };
9644 
9645 /* ******************************************************************************** */
9646 
9647 struct cmd_dump_result {
9648 	cmdline_fixed_string_t dump;
9649 };
9650 
9651 static void
9652 dump_struct_sizes(void)
9653 {
9654 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9655 	DUMP_SIZE(struct rte_mbuf);
9656 	DUMP_SIZE(struct rte_mempool);
9657 	DUMP_SIZE(struct rte_ring);
9658 #undef DUMP_SIZE
9659 }
9660 
9661 
9662 /* Dump the socket memory statistics on console */
9663 static void
9664 dump_socket_mem(FILE *f)
9665 {
9666 	struct rte_malloc_socket_stats socket_stats;
9667 	unsigned int i;
9668 	size_t total = 0;
9669 	size_t alloc = 0;
9670 	size_t free = 0;
9671 	unsigned int n_alloc = 0;
9672 	unsigned int n_free = 0;
9673 	static size_t last_allocs;
9674 	static size_t last_total;
9675 
9676 
9677 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9678 		if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9679 		    !socket_stats.heap_totalsz_bytes)
9680 			continue;
9681 		total += socket_stats.heap_totalsz_bytes;
9682 		alloc += socket_stats.heap_allocsz_bytes;
9683 		free += socket_stats.heap_freesz_bytes;
9684 		n_alloc += socket_stats.alloc_count;
9685 		n_free += socket_stats.free_count;
9686 		fprintf(f,
9687 			"Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9688 			i,
9689 			(double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9690 			(double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9691 			(double)socket_stats.heap_allocsz_bytes * 100 /
9692 			(double)socket_stats.heap_totalsz_bytes,
9693 			(double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9694 			socket_stats.alloc_count,
9695 			socket_stats.free_count);
9696 	}
9697 	fprintf(f,
9698 		"Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9699 		(double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9700 		(double)alloc * 100 / (double)total,
9701 		(double)free / (1024 * 1024),
9702 		n_alloc, n_free);
9703 	if (last_allocs)
9704 		fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9705 			((double)total - (double)last_total) / (1024 * 1024),
9706 			(double)(alloc - (double)last_allocs) / 1024 / 1024);
9707 	last_allocs = alloc;
9708 	last_total = total;
9709 }
9710 
9711 static void cmd_dump_parsed(void *parsed_result,
9712 			    __rte_unused struct cmdline *cl,
9713 			    __rte_unused void *data)
9714 {
9715 	struct cmd_dump_result *res = parsed_result;
9716 
9717 	if (!strcmp(res->dump, "dump_physmem"))
9718 		rte_dump_physmem_layout(stdout);
9719 	else if (!strcmp(res->dump, "dump_socket_mem"))
9720 		dump_socket_mem(stdout);
9721 	else if (!strcmp(res->dump, "dump_memzone"))
9722 		rte_memzone_dump(stdout);
9723 	else if (!strcmp(res->dump, "dump_struct_sizes"))
9724 		dump_struct_sizes();
9725 	else if (!strcmp(res->dump, "dump_ring"))
9726 		rte_ring_list_dump(stdout);
9727 	else if (!strcmp(res->dump, "dump_mempool"))
9728 		rte_mempool_list_dump(stdout);
9729 	else if (!strcmp(res->dump, "dump_devargs"))
9730 		rte_devargs_dump(stdout);
9731 	else if (!strcmp(res->dump, "dump_log_types"))
9732 		rte_log_dump(stdout);
9733 }
9734 
9735 cmdline_parse_token_string_t cmd_dump_dump =
9736 	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9737 		"dump_physmem#"
9738 		"dump_memzone#"
9739 		"dump_socket_mem#"
9740 		"dump_struct_sizes#"
9741 		"dump_ring#"
9742 		"dump_mempool#"
9743 		"dump_devargs#"
9744 		"dump_log_types");
9745 
9746 cmdline_parse_inst_t cmd_dump = {
9747 	.f = cmd_dump_parsed,  /* function to call */
9748 	.data = NULL,      /* 2nd arg of func */
9749 	.help_str = "Dump status",
9750 	.tokens = {        /* token list, NULL terminated */
9751 		(void *)&cmd_dump_dump,
9752 		NULL,
9753 	},
9754 };
9755 
9756 /* ******************************************************************************** */
9757 
9758 struct cmd_dump_one_result {
9759 	cmdline_fixed_string_t dump;
9760 	cmdline_fixed_string_t name;
9761 };
9762 
9763 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9764 				__rte_unused void *data)
9765 {
9766 	struct cmd_dump_one_result *res = parsed_result;
9767 
9768 	if (!strcmp(res->dump, "dump_ring")) {
9769 		struct rte_ring *r;
9770 		r = rte_ring_lookup(res->name);
9771 		if (r == NULL) {
9772 			cmdline_printf(cl, "Cannot find ring\n");
9773 			return;
9774 		}
9775 		rte_ring_dump(stdout, r);
9776 	} else if (!strcmp(res->dump, "dump_mempool")) {
9777 		struct rte_mempool *mp;
9778 		mp = rte_mempool_lookup(res->name);
9779 		if (mp == NULL) {
9780 			cmdline_printf(cl, "Cannot find mempool\n");
9781 			return;
9782 		}
9783 		rte_mempool_dump(stdout, mp);
9784 	}
9785 }
9786 
9787 cmdline_parse_token_string_t cmd_dump_one_dump =
9788 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9789 				 "dump_ring#dump_mempool");
9790 
9791 cmdline_parse_token_string_t cmd_dump_one_name =
9792 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9793 
9794 cmdline_parse_inst_t cmd_dump_one = {
9795 	.f = cmd_dump_one_parsed,  /* function to call */
9796 	.data = NULL,      /* 2nd arg of func */
9797 	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9798 	.tokens = {        /* token list, NULL terminated */
9799 		(void *)&cmd_dump_one_dump,
9800 		(void *)&cmd_dump_one_name,
9801 		NULL,
9802 	},
9803 };
9804 
9805 /* *** Add/Del syn filter *** */
9806 struct cmd_syn_filter_result {
9807 	cmdline_fixed_string_t filter;
9808 	portid_t port_id;
9809 	cmdline_fixed_string_t ops;
9810 	cmdline_fixed_string_t priority;
9811 	cmdline_fixed_string_t high;
9812 	cmdline_fixed_string_t queue;
9813 	uint16_t queue_id;
9814 };
9815 
9816 static void
9817 cmd_syn_filter_parsed(void *parsed_result,
9818 			__rte_unused struct cmdline *cl,
9819 			__rte_unused void *data)
9820 {
9821 	struct cmd_syn_filter_result *res = parsed_result;
9822 	struct rte_eth_syn_filter syn_filter;
9823 	int ret = 0;
9824 
9825 	ret = rte_eth_dev_filter_supported(res->port_id,
9826 					RTE_ETH_FILTER_SYN);
9827 	if (ret < 0) {
9828 		printf("syn filter is not supported on port %u.\n",
9829 				res->port_id);
9830 		return;
9831 	}
9832 
9833 	memset(&syn_filter, 0, sizeof(syn_filter));
9834 
9835 	if (!strcmp(res->ops, "add")) {
9836 		if (!strcmp(res->high, "high"))
9837 			syn_filter.hig_pri = 1;
9838 		else
9839 			syn_filter.hig_pri = 0;
9840 
9841 		syn_filter.queue = res->queue_id;
9842 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9843 						RTE_ETH_FILTER_SYN,
9844 						RTE_ETH_FILTER_ADD,
9845 						&syn_filter);
9846 	} else
9847 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9848 						RTE_ETH_FILTER_SYN,
9849 						RTE_ETH_FILTER_DELETE,
9850 						&syn_filter);
9851 
9852 	if (ret < 0)
9853 		printf("syn filter programming error: (%s)\n",
9854 				strerror(-ret));
9855 }
9856 
9857 cmdline_parse_token_string_t cmd_syn_filter_filter =
9858 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9859 	filter, "syn_filter");
9860 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9861 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9862 	port_id, UINT16);
9863 cmdline_parse_token_string_t cmd_syn_filter_ops =
9864 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9865 	ops, "add#del");
9866 cmdline_parse_token_string_t cmd_syn_filter_priority =
9867 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9868 				priority, "priority");
9869 cmdline_parse_token_string_t cmd_syn_filter_high =
9870 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9871 				high, "high#low");
9872 cmdline_parse_token_string_t cmd_syn_filter_queue =
9873 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9874 				queue, "queue");
9875 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9876 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9877 				queue_id, UINT16);
9878 
9879 cmdline_parse_inst_t cmd_syn_filter = {
9880 	.f = cmd_syn_filter_parsed,
9881 	.data = NULL,
9882 	.help_str = "syn_filter <port_id> add|del priority high|low queue "
9883 		"<queue_id>: Add/Delete syn filter",
9884 	.tokens = {
9885 		(void *)&cmd_syn_filter_filter,
9886 		(void *)&cmd_syn_filter_port_id,
9887 		(void *)&cmd_syn_filter_ops,
9888 		(void *)&cmd_syn_filter_priority,
9889 		(void *)&cmd_syn_filter_high,
9890 		(void *)&cmd_syn_filter_queue,
9891 		(void *)&cmd_syn_filter_queue_id,
9892 		NULL,
9893 	},
9894 };
9895 
9896 /* *** queue region set *** */
9897 struct cmd_queue_region_result {
9898 	cmdline_fixed_string_t set;
9899 	cmdline_fixed_string_t port;
9900 	portid_t port_id;
9901 	cmdline_fixed_string_t cmd;
9902 	cmdline_fixed_string_t region;
9903 	uint8_t  region_id;
9904 	cmdline_fixed_string_t queue_start_index;
9905 	uint8_t  queue_id;
9906 	cmdline_fixed_string_t queue_num;
9907 	uint8_t  queue_num_value;
9908 };
9909 
9910 static void
9911 cmd_queue_region_parsed(void *parsed_result,
9912 			__rte_unused struct cmdline *cl,
9913 			__rte_unused void *data)
9914 {
9915 	struct cmd_queue_region_result *res = parsed_result;
9916 	int ret = -ENOTSUP;
9917 #ifdef RTE_LIBRTE_I40E_PMD
9918 	struct rte_pmd_i40e_queue_region_conf region_conf;
9919 	enum rte_pmd_i40e_queue_region_op op_type;
9920 #endif
9921 
9922 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9923 		return;
9924 
9925 #ifdef RTE_LIBRTE_I40E_PMD
9926 	memset(&region_conf, 0, sizeof(region_conf));
9927 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9928 	region_conf.region_id = res->region_id;
9929 	region_conf.queue_num = res->queue_num_value;
9930 	region_conf.queue_start_index = res->queue_id;
9931 
9932 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9933 				op_type, &region_conf);
9934 #endif
9935 
9936 	switch (ret) {
9937 	case 0:
9938 		break;
9939 	case -ENOTSUP:
9940 		printf("function not implemented or supported\n");
9941 		break;
9942 	default:
9943 		printf("queue region config error: (%s)\n", strerror(-ret));
9944 	}
9945 }
9946 
9947 cmdline_parse_token_string_t cmd_queue_region_set =
9948 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9949 		set, "set");
9950 cmdline_parse_token_string_t cmd_queue_region_port =
9951 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9952 cmdline_parse_token_num_t cmd_queue_region_port_id =
9953 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9954 				port_id, UINT16);
9955 cmdline_parse_token_string_t cmd_queue_region_cmd =
9956 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9957 				 cmd, "queue-region");
9958 cmdline_parse_token_string_t cmd_queue_region_id =
9959 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9960 				region, "region_id");
9961 cmdline_parse_token_num_t cmd_queue_region_index =
9962 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9963 				region_id, UINT8);
9964 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9965 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9966 				queue_start_index, "queue_start_index");
9967 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9968 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9969 				queue_id, UINT8);
9970 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9971 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9972 				queue_num, "queue_num");
9973 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9974 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9975 				queue_num_value, UINT8);
9976 
9977 cmdline_parse_inst_t cmd_queue_region = {
9978 	.f = cmd_queue_region_parsed,
9979 	.data = NULL,
9980 	.help_str = "set port <port_id> queue-region region_id <value> "
9981 		"queue_start_index <value> queue_num <value>: Set a queue region",
9982 	.tokens = {
9983 		(void *)&cmd_queue_region_set,
9984 		(void *)&cmd_queue_region_port,
9985 		(void *)&cmd_queue_region_port_id,
9986 		(void *)&cmd_queue_region_cmd,
9987 		(void *)&cmd_queue_region_id,
9988 		(void *)&cmd_queue_region_index,
9989 		(void *)&cmd_queue_region_queue_start_index,
9990 		(void *)&cmd_queue_region_queue_id,
9991 		(void *)&cmd_queue_region_queue_num,
9992 		(void *)&cmd_queue_region_queue_num_value,
9993 		NULL,
9994 	},
9995 };
9996 
9997 /* *** queue region and flowtype set *** */
9998 struct cmd_region_flowtype_result {
9999 	cmdline_fixed_string_t set;
10000 	cmdline_fixed_string_t port;
10001 	portid_t port_id;
10002 	cmdline_fixed_string_t cmd;
10003 	cmdline_fixed_string_t region;
10004 	uint8_t  region_id;
10005 	cmdline_fixed_string_t flowtype;
10006 	uint8_t  flowtype_id;
10007 };
10008 
10009 static void
10010 cmd_region_flowtype_parsed(void *parsed_result,
10011 			__rte_unused struct cmdline *cl,
10012 			__rte_unused void *data)
10013 {
10014 	struct cmd_region_flowtype_result *res = parsed_result;
10015 	int ret = -ENOTSUP;
10016 #ifdef RTE_LIBRTE_I40E_PMD
10017 	struct rte_pmd_i40e_queue_region_conf region_conf;
10018 	enum rte_pmd_i40e_queue_region_op op_type;
10019 #endif
10020 
10021 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10022 		return;
10023 
10024 #ifdef RTE_LIBRTE_I40E_PMD
10025 	memset(&region_conf, 0, sizeof(region_conf));
10026 
10027 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10028 	region_conf.region_id = res->region_id;
10029 	region_conf.hw_flowtype = res->flowtype_id;
10030 
10031 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10032 			op_type, &region_conf);
10033 #endif
10034 
10035 	switch (ret) {
10036 	case 0:
10037 		break;
10038 	case -ENOTSUP:
10039 		printf("function not implemented or supported\n");
10040 		break;
10041 	default:
10042 		printf("region flowtype config error: (%s)\n", strerror(-ret));
10043 	}
10044 }
10045 
10046 cmdline_parse_token_string_t cmd_region_flowtype_set =
10047 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10048 				set, "set");
10049 cmdline_parse_token_string_t cmd_region_flowtype_port =
10050 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10051 				port, "port");
10052 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10053 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10054 				port_id, UINT16);
10055 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10056 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10057 				cmd, "queue-region");
10058 cmdline_parse_token_string_t cmd_region_flowtype_index =
10059 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10060 				region, "region_id");
10061 cmdline_parse_token_num_t cmd_region_flowtype_id =
10062 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10063 				region_id, UINT8);
10064 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10065 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10066 				flowtype, "flowtype");
10067 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10068 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10069 				flowtype_id, UINT8);
10070 cmdline_parse_inst_t cmd_region_flowtype = {
10071 	.f = cmd_region_flowtype_parsed,
10072 	.data = NULL,
10073 	.help_str = "set port <port_id> queue-region region_id <value> "
10074 		"flowtype <value>: Set a flowtype region index",
10075 	.tokens = {
10076 		(void *)&cmd_region_flowtype_set,
10077 		(void *)&cmd_region_flowtype_port,
10078 		(void *)&cmd_region_flowtype_port_index,
10079 		(void *)&cmd_region_flowtype_cmd,
10080 		(void *)&cmd_region_flowtype_index,
10081 		(void *)&cmd_region_flowtype_id,
10082 		(void *)&cmd_region_flowtype_flow_index,
10083 		(void *)&cmd_region_flowtype_flow_id,
10084 		NULL,
10085 	},
10086 };
10087 
10088 /* *** User Priority (UP) to queue region (region_id) set *** */
10089 struct cmd_user_priority_region_result {
10090 	cmdline_fixed_string_t set;
10091 	cmdline_fixed_string_t port;
10092 	portid_t port_id;
10093 	cmdline_fixed_string_t cmd;
10094 	cmdline_fixed_string_t user_priority;
10095 	uint8_t  user_priority_id;
10096 	cmdline_fixed_string_t region;
10097 	uint8_t  region_id;
10098 };
10099 
10100 static void
10101 cmd_user_priority_region_parsed(void *parsed_result,
10102 			__rte_unused struct cmdline *cl,
10103 			__rte_unused void *data)
10104 {
10105 	struct cmd_user_priority_region_result *res = parsed_result;
10106 	int ret = -ENOTSUP;
10107 #ifdef RTE_LIBRTE_I40E_PMD
10108 	struct rte_pmd_i40e_queue_region_conf region_conf;
10109 	enum rte_pmd_i40e_queue_region_op op_type;
10110 #endif
10111 
10112 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10113 		return;
10114 
10115 #ifdef RTE_LIBRTE_I40E_PMD
10116 	memset(&region_conf, 0, sizeof(region_conf));
10117 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10118 	region_conf.user_priority = res->user_priority_id;
10119 	region_conf.region_id = res->region_id;
10120 
10121 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10122 				op_type, &region_conf);
10123 #endif
10124 
10125 	switch (ret) {
10126 	case 0:
10127 		break;
10128 	case -ENOTSUP:
10129 		printf("function not implemented or supported\n");
10130 		break;
10131 	default:
10132 		printf("user_priority region config error: (%s)\n",
10133 				strerror(-ret));
10134 	}
10135 }
10136 
10137 cmdline_parse_token_string_t cmd_user_priority_region_set =
10138 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10139 				set, "set");
10140 cmdline_parse_token_string_t cmd_user_priority_region_port =
10141 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10142 				port, "port");
10143 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10144 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10145 				port_id, UINT16);
10146 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10147 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10148 				cmd, "queue-region");
10149 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10150 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10151 				user_priority, "UP");
10152 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10153 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10154 				user_priority_id, UINT8);
10155 cmdline_parse_token_string_t cmd_user_priority_region_region =
10156 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10157 				region, "region_id");
10158 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10159 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10160 				region_id, UINT8);
10161 
10162 cmdline_parse_inst_t cmd_user_priority_region = {
10163 	.f = cmd_user_priority_region_parsed,
10164 	.data = NULL,
10165 	.help_str = "set port <port_id> queue-region UP <value> "
10166 		"region_id <value>: Set the mapping of User Priority (UP) "
10167 		"to queue region (region_id) ",
10168 	.tokens = {
10169 		(void *)&cmd_user_priority_region_set,
10170 		(void *)&cmd_user_priority_region_port,
10171 		(void *)&cmd_user_priority_region_port_index,
10172 		(void *)&cmd_user_priority_region_cmd,
10173 		(void *)&cmd_user_priority_region_UP,
10174 		(void *)&cmd_user_priority_region_UP_id,
10175 		(void *)&cmd_user_priority_region_region,
10176 		(void *)&cmd_user_priority_region_region_id,
10177 		NULL,
10178 	},
10179 };
10180 
10181 /* *** flush all queue region related configuration *** */
10182 struct cmd_flush_queue_region_result {
10183 	cmdline_fixed_string_t set;
10184 	cmdline_fixed_string_t port;
10185 	portid_t port_id;
10186 	cmdline_fixed_string_t cmd;
10187 	cmdline_fixed_string_t flush;
10188 	cmdline_fixed_string_t what;
10189 };
10190 
10191 static void
10192 cmd_flush_queue_region_parsed(void *parsed_result,
10193 			__rte_unused struct cmdline *cl,
10194 			__rte_unused void *data)
10195 {
10196 	struct cmd_flush_queue_region_result *res = parsed_result;
10197 	int ret = -ENOTSUP;
10198 #ifdef RTE_LIBRTE_I40E_PMD
10199 	struct rte_pmd_i40e_queue_region_conf region_conf;
10200 	enum rte_pmd_i40e_queue_region_op op_type;
10201 #endif
10202 
10203 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10204 		return;
10205 
10206 #ifdef RTE_LIBRTE_I40E_PMD
10207 	memset(&region_conf, 0, sizeof(region_conf));
10208 
10209 	if (strcmp(res->what, "on") == 0)
10210 		op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10211 	else
10212 		op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10213 
10214 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10215 				op_type, &region_conf);
10216 #endif
10217 
10218 	switch (ret) {
10219 	case 0:
10220 		break;
10221 	case -ENOTSUP:
10222 		printf("function not implemented or supported\n");
10223 		break;
10224 	default:
10225 		printf("queue region config flush error: (%s)\n",
10226 				strerror(-ret));
10227 	}
10228 }
10229 
10230 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10231 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10232 				set, "set");
10233 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10234 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10235 				port, "port");
10236 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10237 	TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10238 				port_id, UINT16);
10239 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10240 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10241 				cmd, "queue-region");
10242 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10243 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10244 				flush, "flush");
10245 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10246 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10247 				what, "on#off");
10248 
10249 cmdline_parse_inst_t cmd_flush_queue_region = {
10250 	.f = cmd_flush_queue_region_parsed,
10251 	.data = NULL,
10252 	.help_str = "set port <port_id> queue-region flush on|off"
10253 		": flush all queue region related configuration",
10254 	.tokens = {
10255 		(void *)&cmd_flush_queue_region_set,
10256 		(void *)&cmd_flush_queue_region_port,
10257 		(void *)&cmd_flush_queue_region_port_index,
10258 		(void *)&cmd_flush_queue_region_cmd,
10259 		(void *)&cmd_flush_queue_region_flush,
10260 		(void *)&cmd_flush_queue_region_what,
10261 		NULL,
10262 	},
10263 };
10264 
10265 /* *** get all queue region related configuration info *** */
10266 struct cmd_show_queue_region_info {
10267 	cmdline_fixed_string_t show;
10268 	cmdline_fixed_string_t port;
10269 	portid_t port_id;
10270 	cmdline_fixed_string_t cmd;
10271 };
10272 
10273 static void
10274 cmd_show_queue_region_info_parsed(void *parsed_result,
10275 			__rte_unused struct cmdline *cl,
10276 			__rte_unused void *data)
10277 {
10278 	struct cmd_show_queue_region_info *res = parsed_result;
10279 	int ret = -ENOTSUP;
10280 #ifdef RTE_LIBRTE_I40E_PMD
10281 	struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10282 	enum rte_pmd_i40e_queue_region_op op_type;
10283 #endif
10284 
10285 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10286 		return;
10287 
10288 #ifdef RTE_LIBRTE_I40E_PMD
10289 	memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10290 
10291 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10292 
10293 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10294 					op_type, &rte_pmd_regions);
10295 
10296 	port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10297 #endif
10298 
10299 	switch (ret) {
10300 	case 0:
10301 		break;
10302 	case -ENOTSUP:
10303 		printf("function not implemented or supported\n");
10304 		break;
10305 	default:
10306 		printf("queue region config info show error: (%s)\n",
10307 				strerror(-ret));
10308 	}
10309 }
10310 
10311 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10312 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10313 				show, "show");
10314 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10315 	TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10316 				port, "port");
10317 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10318 	TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10319 				port_id, UINT16);
10320 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10321 	TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10322 				cmd, "queue-region");
10323 
10324 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10325 	.f = cmd_show_queue_region_info_parsed,
10326 	.data = NULL,
10327 	.help_str = "show port <port_id> queue-region"
10328 		": show all queue region related configuration info",
10329 	.tokens = {
10330 		(void *)&cmd_show_queue_region_info_get,
10331 		(void *)&cmd_show_queue_region_info_port,
10332 		(void *)&cmd_show_queue_region_info_port_index,
10333 		(void *)&cmd_show_queue_region_info_cmd,
10334 		NULL,
10335 	},
10336 };
10337 
10338 /* *** ADD/REMOVE A 2tuple FILTER *** */
10339 struct cmd_2tuple_filter_result {
10340 	cmdline_fixed_string_t filter;
10341 	portid_t port_id;
10342 	cmdline_fixed_string_t ops;
10343 	cmdline_fixed_string_t dst_port;
10344 	uint16_t dst_port_value;
10345 	cmdline_fixed_string_t protocol;
10346 	uint8_t protocol_value;
10347 	cmdline_fixed_string_t mask;
10348 	uint8_t  mask_value;
10349 	cmdline_fixed_string_t tcp_flags;
10350 	uint8_t tcp_flags_value;
10351 	cmdline_fixed_string_t priority;
10352 	uint8_t  priority_value;
10353 	cmdline_fixed_string_t queue;
10354 	uint16_t  queue_id;
10355 };
10356 
10357 static void
10358 cmd_2tuple_filter_parsed(void *parsed_result,
10359 			__rte_unused struct cmdline *cl,
10360 			__rte_unused void *data)
10361 {
10362 	struct rte_eth_ntuple_filter filter;
10363 	struct cmd_2tuple_filter_result *res = parsed_result;
10364 	int ret = 0;
10365 
10366 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10367 	if (ret < 0) {
10368 		printf("ntuple filter is not supported on port %u.\n",
10369 			res->port_id);
10370 		return;
10371 	}
10372 
10373 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10374 
10375 	filter.flags = RTE_2TUPLE_FLAGS;
10376 	filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10377 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10378 	filter.proto = res->protocol_value;
10379 	filter.priority = res->priority_value;
10380 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10381 		printf("nonzero tcp_flags is only meaningful"
10382 			" when protocol is TCP.\n");
10383 		return;
10384 	}
10385 	if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10386 		printf("invalid TCP flags.\n");
10387 		return;
10388 	}
10389 
10390 	if (res->tcp_flags_value != 0) {
10391 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10392 		filter.tcp_flags = res->tcp_flags_value;
10393 	}
10394 
10395 	/* need convert to big endian. */
10396 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10397 	filter.queue = res->queue_id;
10398 
10399 	if (!strcmp(res->ops, "add"))
10400 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10401 				RTE_ETH_FILTER_NTUPLE,
10402 				RTE_ETH_FILTER_ADD,
10403 				&filter);
10404 	else
10405 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10406 				RTE_ETH_FILTER_NTUPLE,
10407 				RTE_ETH_FILTER_DELETE,
10408 				&filter);
10409 	if (ret < 0)
10410 		printf("2tuple filter programming error: (%s)\n",
10411 			strerror(-ret));
10412 
10413 }
10414 
10415 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10416 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10417 				 filter, "2tuple_filter");
10418 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10419 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10420 				port_id, UINT16);
10421 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10422 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10423 				 ops, "add#del");
10424 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10425 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10426 				dst_port, "dst_port");
10427 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10428 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10429 				dst_port_value, UINT16);
10430 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10431 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10432 				protocol, "protocol");
10433 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10434 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10435 				protocol_value, UINT8);
10436 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10437 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10438 				mask, "mask");
10439 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10440 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10441 				mask_value, INT8);
10442 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10443 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10444 				tcp_flags, "tcp_flags");
10445 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10446 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10447 				tcp_flags_value, UINT8);
10448 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10449 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10450 				priority, "priority");
10451 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10452 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10453 				priority_value, UINT8);
10454 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10455 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10456 				queue, "queue");
10457 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10458 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10459 				queue_id, UINT16);
10460 
10461 cmdline_parse_inst_t cmd_2tuple_filter = {
10462 	.f = cmd_2tuple_filter_parsed,
10463 	.data = NULL,
10464 	.help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10465 		"<value> mask <value> tcp_flags <value> priority <value> queue "
10466 		"<queue_id>: Add a 2tuple filter",
10467 	.tokens = {
10468 		(void *)&cmd_2tuple_filter_filter,
10469 		(void *)&cmd_2tuple_filter_port_id,
10470 		(void *)&cmd_2tuple_filter_ops,
10471 		(void *)&cmd_2tuple_filter_dst_port,
10472 		(void *)&cmd_2tuple_filter_dst_port_value,
10473 		(void *)&cmd_2tuple_filter_protocol,
10474 		(void *)&cmd_2tuple_filter_protocol_value,
10475 		(void *)&cmd_2tuple_filter_mask,
10476 		(void *)&cmd_2tuple_filter_mask_value,
10477 		(void *)&cmd_2tuple_filter_tcp_flags,
10478 		(void *)&cmd_2tuple_filter_tcp_flags_value,
10479 		(void *)&cmd_2tuple_filter_priority,
10480 		(void *)&cmd_2tuple_filter_priority_value,
10481 		(void *)&cmd_2tuple_filter_queue,
10482 		(void *)&cmd_2tuple_filter_queue_id,
10483 		NULL,
10484 	},
10485 };
10486 
10487 /* *** ADD/REMOVE A 5tuple FILTER *** */
10488 struct cmd_5tuple_filter_result {
10489 	cmdline_fixed_string_t filter;
10490 	portid_t port_id;
10491 	cmdline_fixed_string_t ops;
10492 	cmdline_fixed_string_t dst_ip;
10493 	cmdline_ipaddr_t dst_ip_value;
10494 	cmdline_fixed_string_t src_ip;
10495 	cmdline_ipaddr_t src_ip_value;
10496 	cmdline_fixed_string_t dst_port;
10497 	uint16_t dst_port_value;
10498 	cmdline_fixed_string_t src_port;
10499 	uint16_t src_port_value;
10500 	cmdline_fixed_string_t protocol;
10501 	uint8_t protocol_value;
10502 	cmdline_fixed_string_t mask;
10503 	uint8_t  mask_value;
10504 	cmdline_fixed_string_t tcp_flags;
10505 	uint8_t tcp_flags_value;
10506 	cmdline_fixed_string_t priority;
10507 	uint8_t  priority_value;
10508 	cmdline_fixed_string_t queue;
10509 	uint16_t  queue_id;
10510 };
10511 
10512 static void
10513 cmd_5tuple_filter_parsed(void *parsed_result,
10514 			__rte_unused struct cmdline *cl,
10515 			__rte_unused void *data)
10516 {
10517 	struct rte_eth_ntuple_filter filter;
10518 	struct cmd_5tuple_filter_result *res = parsed_result;
10519 	int ret = 0;
10520 
10521 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10522 	if (ret < 0) {
10523 		printf("ntuple filter is not supported on port %u.\n",
10524 			res->port_id);
10525 		return;
10526 	}
10527 
10528 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10529 
10530 	filter.flags = RTE_5TUPLE_FLAGS;
10531 	filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10532 	filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10533 	filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10534 	filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10535 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10536 	filter.proto = res->protocol_value;
10537 	filter.priority = res->priority_value;
10538 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10539 		printf("nonzero tcp_flags is only meaningful"
10540 			" when protocol is TCP.\n");
10541 		return;
10542 	}
10543 	if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10544 		printf("invalid TCP flags.\n");
10545 		return;
10546 	}
10547 
10548 	if (res->tcp_flags_value != 0) {
10549 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10550 		filter.tcp_flags = res->tcp_flags_value;
10551 	}
10552 
10553 	if (res->dst_ip_value.family == AF_INET)
10554 		/* no need to convert, already big endian. */
10555 		filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10556 	else {
10557 		if (filter.dst_ip_mask == 0) {
10558 			printf("can not support ipv6 involved compare.\n");
10559 			return;
10560 		}
10561 		filter.dst_ip = 0;
10562 	}
10563 
10564 	if (res->src_ip_value.family == AF_INET)
10565 		/* no need to convert, already big endian. */
10566 		filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10567 	else {
10568 		if (filter.src_ip_mask == 0) {
10569 			printf("can not support ipv6 involved compare.\n");
10570 			return;
10571 		}
10572 		filter.src_ip = 0;
10573 	}
10574 	/* need convert to big endian. */
10575 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10576 	filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10577 	filter.queue = res->queue_id;
10578 
10579 	if (!strcmp(res->ops, "add"))
10580 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10581 				RTE_ETH_FILTER_NTUPLE,
10582 				RTE_ETH_FILTER_ADD,
10583 				&filter);
10584 	else
10585 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10586 				RTE_ETH_FILTER_NTUPLE,
10587 				RTE_ETH_FILTER_DELETE,
10588 				&filter);
10589 	if (ret < 0)
10590 		printf("5tuple filter programming error: (%s)\n",
10591 			strerror(-ret));
10592 }
10593 
10594 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10595 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10596 				 filter, "5tuple_filter");
10597 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10598 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10599 				port_id, UINT16);
10600 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10601 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10602 				 ops, "add#del");
10603 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10604 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10605 				dst_ip, "dst_ip");
10606 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10607 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10608 				dst_ip_value);
10609 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10610 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10611 				src_ip, "src_ip");
10612 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10613 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10614 				src_ip_value);
10615 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10616 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10617 				dst_port, "dst_port");
10618 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10619 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10620 				dst_port_value, UINT16);
10621 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10622 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10623 				src_port, "src_port");
10624 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10625 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10626 				src_port_value, UINT16);
10627 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10628 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10629 				protocol, "protocol");
10630 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10631 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10632 				protocol_value, UINT8);
10633 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10634 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10635 				mask, "mask");
10636 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10637 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10638 				mask_value, INT8);
10639 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10640 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10641 				tcp_flags, "tcp_flags");
10642 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10643 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10644 				tcp_flags_value, UINT8);
10645 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10646 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10647 				priority, "priority");
10648 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10649 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10650 				priority_value, UINT8);
10651 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10652 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10653 				queue, "queue");
10654 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10655 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10656 				queue_id, UINT16);
10657 
10658 cmdline_parse_inst_t cmd_5tuple_filter = {
10659 	.f = cmd_5tuple_filter_parsed,
10660 	.data = NULL,
10661 	.help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10662 		"src_ip <value> dst_port <value> src_port <value> "
10663 		"protocol <value>  mask <value> tcp_flags <value> "
10664 		"priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10665 	.tokens = {
10666 		(void *)&cmd_5tuple_filter_filter,
10667 		(void *)&cmd_5tuple_filter_port_id,
10668 		(void *)&cmd_5tuple_filter_ops,
10669 		(void *)&cmd_5tuple_filter_dst_ip,
10670 		(void *)&cmd_5tuple_filter_dst_ip_value,
10671 		(void *)&cmd_5tuple_filter_src_ip,
10672 		(void *)&cmd_5tuple_filter_src_ip_value,
10673 		(void *)&cmd_5tuple_filter_dst_port,
10674 		(void *)&cmd_5tuple_filter_dst_port_value,
10675 		(void *)&cmd_5tuple_filter_src_port,
10676 		(void *)&cmd_5tuple_filter_src_port_value,
10677 		(void *)&cmd_5tuple_filter_protocol,
10678 		(void *)&cmd_5tuple_filter_protocol_value,
10679 		(void *)&cmd_5tuple_filter_mask,
10680 		(void *)&cmd_5tuple_filter_mask_value,
10681 		(void *)&cmd_5tuple_filter_tcp_flags,
10682 		(void *)&cmd_5tuple_filter_tcp_flags_value,
10683 		(void *)&cmd_5tuple_filter_priority,
10684 		(void *)&cmd_5tuple_filter_priority_value,
10685 		(void *)&cmd_5tuple_filter_queue,
10686 		(void *)&cmd_5tuple_filter_queue_id,
10687 		NULL,
10688 	},
10689 };
10690 
10691 /* *** ADD/REMOVE A flex FILTER *** */
10692 struct cmd_flex_filter_result {
10693 	cmdline_fixed_string_t filter;
10694 	cmdline_fixed_string_t ops;
10695 	portid_t port_id;
10696 	cmdline_fixed_string_t len;
10697 	uint8_t len_value;
10698 	cmdline_fixed_string_t bytes;
10699 	cmdline_fixed_string_t bytes_value;
10700 	cmdline_fixed_string_t mask;
10701 	cmdline_fixed_string_t mask_value;
10702 	cmdline_fixed_string_t priority;
10703 	uint8_t priority_value;
10704 	cmdline_fixed_string_t queue;
10705 	uint16_t queue_id;
10706 };
10707 
10708 static int xdigit2val(unsigned char c)
10709 {
10710 	int val;
10711 	if (isdigit(c))
10712 		val = c - '0';
10713 	else if (isupper(c))
10714 		val = c - 'A' + 10;
10715 	else
10716 		val = c - 'a' + 10;
10717 	return val;
10718 }
10719 
10720 static void
10721 cmd_flex_filter_parsed(void *parsed_result,
10722 			  __rte_unused struct cmdline *cl,
10723 			  __rte_unused void *data)
10724 {
10725 	int ret = 0;
10726 	struct rte_eth_flex_filter filter;
10727 	struct cmd_flex_filter_result *res = parsed_result;
10728 	char *bytes_ptr, *mask_ptr;
10729 	uint16_t len, i, j = 0;
10730 	char c;
10731 	int val;
10732 	uint8_t byte = 0;
10733 
10734 	if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10735 		printf("the len exceed the max length 128\n");
10736 		return;
10737 	}
10738 	memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10739 	filter.len = res->len_value;
10740 	filter.priority = res->priority_value;
10741 	filter.queue = res->queue_id;
10742 	bytes_ptr = res->bytes_value;
10743 	mask_ptr = res->mask_value;
10744 
10745 	 /* translate bytes string to array. */
10746 	if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10747 		(bytes_ptr[1] == 'X')))
10748 		bytes_ptr += 2;
10749 	len = strnlen(bytes_ptr, res->len_value * 2);
10750 	if (len == 0 || (len % 8 != 0)) {
10751 		printf("please check len and bytes input\n");
10752 		return;
10753 	}
10754 	for (i = 0; i < len; i++) {
10755 		c = bytes_ptr[i];
10756 		if (isxdigit(c) == 0) {
10757 			/* invalid characters. */
10758 			printf("invalid input\n");
10759 			return;
10760 		}
10761 		val = xdigit2val(c);
10762 		if (i % 2) {
10763 			byte |= val;
10764 			filter.bytes[j] = byte;
10765 			printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10766 			j++;
10767 			byte = 0;
10768 		} else
10769 			byte |= val << 4;
10770 	}
10771 	printf("\n");
10772 	 /* translate mask string to uint8_t array. */
10773 	if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10774 		(mask_ptr[1] == 'X')))
10775 		mask_ptr += 2;
10776 	len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10777 	if (len == 0) {
10778 		printf("invalid input\n");
10779 		return;
10780 	}
10781 	j = 0;
10782 	byte = 0;
10783 	for (i = 0; i < len; i++) {
10784 		c = mask_ptr[i];
10785 		if (isxdigit(c) == 0) {
10786 			/* invalid characters. */
10787 			printf("invalid input\n");
10788 			return;
10789 		}
10790 		val = xdigit2val(c);
10791 		if (i % 2) {
10792 			byte |= val;
10793 			filter.mask[j] = byte;
10794 			printf("mask[%d]:%02x ", j, filter.mask[j]);
10795 			j++;
10796 			byte = 0;
10797 		} else
10798 			byte |= val << 4;
10799 	}
10800 	printf("\n");
10801 
10802 	if (!strcmp(res->ops, "add"))
10803 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10804 				RTE_ETH_FILTER_FLEXIBLE,
10805 				RTE_ETH_FILTER_ADD,
10806 				&filter);
10807 	else
10808 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10809 				RTE_ETH_FILTER_FLEXIBLE,
10810 				RTE_ETH_FILTER_DELETE,
10811 				&filter);
10812 
10813 	if (ret < 0)
10814 		printf("flex filter setting error: (%s)\n", strerror(-ret));
10815 }
10816 
10817 cmdline_parse_token_string_t cmd_flex_filter_filter =
10818 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10819 				filter, "flex_filter");
10820 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10821 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10822 				port_id, UINT16);
10823 cmdline_parse_token_string_t cmd_flex_filter_ops =
10824 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10825 				ops, "add#del");
10826 cmdline_parse_token_string_t cmd_flex_filter_len =
10827 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10828 				len, "len");
10829 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10830 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10831 				len_value, UINT8);
10832 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10833 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10834 				bytes, "bytes");
10835 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10836 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10837 				bytes_value, NULL);
10838 cmdline_parse_token_string_t cmd_flex_filter_mask =
10839 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10840 				mask, "mask");
10841 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10842 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10843 				mask_value, NULL);
10844 cmdline_parse_token_string_t cmd_flex_filter_priority =
10845 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10846 				priority, "priority");
10847 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10848 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10849 				priority_value, UINT8);
10850 cmdline_parse_token_string_t cmd_flex_filter_queue =
10851 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10852 				queue, "queue");
10853 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10854 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10855 				queue_id, UINT16);
10856 cmdline_parse_inst_t cmd_flex_filter = {
10857 	.f = cmd_flex_filter_parsed,
10858 	.data = NULL,
10859 	.help_str = "flex_filter <port_id> add|del len <value> bytes "
10860 		"<value> mask <value> priority <value> queue <queue_id>: "
10861 		"Add/Del a flex filter",
10862 	.tokens = {
10863 		(void *)&cmd_flex_filter_filter,
10864 		(void *)&cmd_flex_filter_port_id,
10865 		(void *)&cmd_flex_filter_ops,
10866 		(void *)&cmd_flex_filter_len,
10867 		(void *)&cmd_flex_filter_len_value,
10868 		(void *)&cmd_flex_filter_bytes,
10869 		(void *)&cmd_flex_filter_bytes_value,
10870 		(void *)&cmd_flex_filter_mask,
10871 		(void *)&cmd_flex_filter_mask_value,
10872 		(void *)&cmd_flex_filter_priority,
10873 		(void *)&cmd_flex_filter_priority_value,
10874 		(void *)&cmd_flex_filter_queue,
10875 		(void *)&cmd_flex_filter_queue_id,
10876 		NULL,
10877 	},
10878 };
10879 
10880 /* *** Filters Control *** */
10881 
10882 /* *** deal with ethertype filter *** */
10883 struct cmd_ethertype_filter_result {
10884 	cmdline_fixed_string_t filter;
10885 	portid_t port_id;
10886 	cmdline_fixed_string_t ops;
10887 	cmdline_fixed_string_t mac;
10888 	struct rte_ether_addr mac_addr;
10889 	cmdline_fixed_string_t ethertype;
10890 	uint16_t ethertype_value;
10891 	cmdline_fixed_string_t drop;
10892 	cmdline_fixed_string_t queue;
10893 	uint16_t  queue_id;
10894 };
10895 
10896 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10897 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10898 				 filter, "ethertype_filter");
10899 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10900 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10901 			      port_id, UINT16);
10902 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10903 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10904 				 ops, "add#del");
10905 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10906 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10907 				 mac, "mac_addr#mac_ignr");
10908 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10909 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10910 				     mac_addr);
10911 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10912 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10913 				 ethertype, "ethertype");
10914 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10915 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10916 			      ethertype_value, UINT16);
10917 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10918 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10919 				 drop, "drop#fwd");
10920 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10921 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10922 				 queue, "queue");
10923 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10924 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10925 			      queue_id, UINT16);
10926 
10927 static void
10928 cmd_ethertype_filter_parsed(void *parsed_result,
10929 			  __rte_unused struct cmdline *cl,
10930 			  __rte_unused void *data)
10931 {
10932 	struct cmd_ethertype_filter_result *res = parsed_result;
10933 	struct rte_eth_ethertype_filter filter;
10934 	int ret = 0;
10935 
10936 	ret = rte_eth_dev_filter_supported(res->port_id,
10937 			RTE_ETH_FILTER_ETHERTYPE);
10938 	if (ret < 0) {
10939 		printf("ethertype filter is not supported on port %u.\n",
10940 			res->port_id);
10941 		return;
10942 	}
10943 
10944 	memset(&filter, 0, sizeof(filter));
10945 	if (!strcmp(res->mac, "mac_addr")) {
10946 		filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10947 		rte_memcpy(&filter.mac_addr, &res->mac_addr,
10948 			sizeof(struct rte_ether_addr));
10949 	}
10950 	if (!strcmp(res->drop, "drop"))
10951 		filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10952 	filter.ether_type = res->ethertype_value;
10953 	filter.queue = res->queue_id;
10954 
10955 	if (!strcmp(res->ops, "add"))
10956 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10957 				RTE_ETH_FILTER_ETHERTYPE,
10958 				RTE_ETH_FILTER_ADD,
10959 				&filter);
10960 	else
10961 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10962 				RTE_ETH_FILTER_ETHERTYPE,
10963 				RTE_ETH_FILTER_DELETE,
10964 				&filter);
10965 	if (ret < 0)
10966 		printf("ethertype filter programming error: (%s)\n",
10967 			strerror(-ret));
10968 }
10969 
10970 cmdline_parse_inst_t cmd_ethertype_filter = {
10971 	.f = cmd_ethertype_filter_parsed,
10972 	.data = NULL,
10973 	.help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10974 		"<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10975 		"Add or delete an ethertype filter entry",
10976 	.tokens = {
10977 		(void *)&cmd_ethertype_filter_filter,
10978 		(void *)&cmd_ethertype_filter_port_id,
10979 		(void *)&cmd_ethertype_filter_ops,
10980 		(void *)&cmd_ethertype_filter_mac,
10981 		(void *)&cmd_ethertype_filter_mac_addr,
10982 		(void *)&cmd_ethertype_filter_ethertype,
10983 		(void *)&cmd_ethertype_filter_ethertype_value,
10984 		(void *)&cmd_ethertype_filter_drop,
10985 		(void *)&cmd_ethertype_filter_queue,
10986 		(void *)&cmd_ethertype_filter_queue_id,
10987 		NULL,
10988 	},
10989 };
10990 
10991 /* *** deal with flow director filter *** */
10992 struct cmd_flow_director_result {
10993 	cmdline_fixed_string_t flow_director_filter;
10994 	portid_t port_id;
10995 	cmdline_fixed_string_t mode;
10996 	cmdline_fixed_string_t mode_value;
10997 	cmdline_fixed_string_t ops;
10998 	cmdline_fixed_string_t flow;
10999 	cmdline_fixed_string_t flow_type;
11000 	cmdline_fixed_string_t ether;
11001 	uint16_t ether_type;
11002 	cmdline_fixed_string_t src;
11003 	cmdline_ipaddr_t ip_src;
11004 	uint16_t port_src;
11005 	cmdline_fixed_string_t dst;
11006 	cmdline_ipaddr_t ip_dst;
11007 	uint16_t port_dst;
11008 	cmdline_fixed_string_t verify_tag;
11009 	uint32_t verify_tag_value;
11010 	cmdline_fixed_string_t tos;
11011 	uint8_t tos_value;
11012 	cmdline_fixed_string_t proto;
11013 	uint8_t proto_value;
11014 	cmdline_fixed_string_t ttl;
11015 	uint8_t ttl_value;
11016 	cmdline_fixed_string_t vlan;
11017 	uint16_t vlan_value;
11018 	cmdline_fixed_string_t flexbytes;
11019 	cmdline_fixed_string_t flexbytes_value;
11020 	cmdline_fixed_string_t pf_vf;
11021 	cmdline_fixed_string_t drop;
11022 	cmdline_fixed_string_t queue;
11023 	uint16_t  queue_id;
11024 	cmdline_fixed_string_t fd_id;
11025 	uint32_t  fd_id_value;
11026 	cmdline_fixed_string_t mac;
11027 	struct rte_ether_addr mac_addr;
11028 	cmdline_fixed_string_t tunnel;
11029 	cmdline_fixed_string_t tunnel_type;
11030 	cmdline_fixed_string_t tunnel_id;
11031 	uint32_t tunnel_id_value;
11032 	cmdline_fixed_string_t packet;
11033 	char filepath[];
11034 };
11035 
11036 static inline int
11037 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
11038 {
11039 	char s[256];
11040 	const char *p, *p0 = q_arg;
11041 	char *end;
11042 	unsigned long int_fld;
11043 	char *str_fld[max_num];
11044 	int i;
11045 	unsigned size;
11046 	int ret = -1;
11047 
11048 	p = strchr(p0, '(');
11049 	if (p == NULL)
11050 		return -1;
11051 	++p;
11052 	p0 = strchr(p, ')');
11053 	if (p0 == NULL)
11054 		return -1;
11055 
11056 	size = p0 - p;
11057 	if (size >= sizeof(s))
11058 		return -1;
11059 
11060 	snprintf(s, sizeof(s), "%.*s", size, p);
11061 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11062 	if (ret < 0 || ret > max_num)
11063 		return -1;
11064 	for (i = 0; i < ret; i++) {
11065 		errno = 0;
11066 		int_fld = strtoul(str_fld[i], &end, 0);
11067 		if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11068 			return -1;
11069 		flexbytes[i] = (uint8_t)int_fld;
11070 	}
11071 	return ret;
11072 }
11073 
11074 static uint16_t
11075 str2flowtype(char *string)
11076 {
11077 	uint8_t i = 0;
11078 	static const struct {
11079 		char str[32];
11080 		uint16_t type;
11081 	} flowtype_str[] = {
11082 		{"raw", RTE_ETH_FLOW_RAW},
11083 		{"ipv4", RTE_ETH_FLOW_IPV4},
11084 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11085 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11086 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11087 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11088 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11089 		{"ipv6", RTE_ETH_FLOW_IPV6},
11090 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11091 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11092 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11093 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11094 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11095 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11096 	};
11097 
11098 	for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11099 		if (!strcmp(flowtype_str[i].str, string))
11100 			return flowtype_str[i].type;
11101 	}
11102 
11103 	if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11104 		return (uint16_t)atoi(string);
11105 
11106 	return RTE_ETH_FLOW_UNKNOWN;
11107 }
11108 
11109 static enum rte_eth_fdir_tunnel_type
11110 str2fdir_tunneltype(char *string)
11111 {
11112 	uint8_t i = 0;
11113 
11114 	static const struct {
11115 		char str[32];
11116 		enum rte_eth_fdir_tunnel_type type;
11117 	} tunneltype_str[] = {
11118 		{"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11119 		{"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11120 	};
11121 
11122 	for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11123 		if (!strcmp(tunneltype_str[i].str, string))
11124 			return tunneltype_str[i].type;
11125 	}
11126 	return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11127 }
11128 
11129 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11130 do { \
11131 	if ((ip_addr).family == AF_INET) \
11132 		(ip) = (ip_addr).addr.ipv4.s_addr; \
11133 	else { \
11134 		printf("invalid parameter.\n"); \
11135 		return; \
11136 	} \
11137 } while (0)
11138 
11139 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11140 do { \
11141 	if ((ip_addr).family == AF_INET6) \
11142 		rte_memcpy(&(ip), \
11143 				 &((ip_addr).addr.ipv6), \
11144 				 sizeof(struct in6_addr)); \
11145 	else { \
11146 		printf("invalid parameter.\n"); \
11147 		return; \
11148 	} \
11149 } while (0)
11150 
11151 static void
11152 cmd_flow_director_filter_parsed(void *parsed_result,
11153 			  __rte_unused struct cmdline *cl,
11154 			  __rte_unused void *data)
11155 {
11156 	struct cmd_flow_director_result *res = parsed_result;
11157 	struct rte_eth_fdir_filter entry;
11158 	uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11159 	char *end;
11160 	unsigned long vf_id;
11161 	int ret = 0;
11162 
11163 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11164 	if (ret < 0) {
11165 		printf("flow director is not supported on port %u.\n",
11166 			res->port_id);
11167 		return;
11168 	}
11169 	memset(flexbytes, 0, sizeof(flexbytes));
11170 	memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11171 
11172 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11173 		if (strcmp(res->mode_value, "MAC-VLAN")) {
11174 			printf("Please set mode to MAC-VLAN.\n");
11175 			return;
11176 		}
11177 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11178 		if (strcmp(res->mode_value, "Tunnel")) {
11179 			printf("Please set mode to Tunnel.\n");
11180 			return;
11181 		}
11182 	} else {
11183 		if (!strcmp(res->mode_value, "raw")) {
11184 #ifdef RTE_LIBRTE_I40E_PMD
11185 			struct rte_pmd_i40e_flow_type_mapping
11186 					mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11187 			struct rte_pmd_i40e_pkt_template_conf conf;
11188 			uint16_t flow_type = str2flowtype(res->flow_type);
11189 			uint16_t i, port = res->port_id;
11190 			uint8_t add;
11191 
11192 			memset(&conf, 0, sizeof(conf));
11193 
11194 			if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11195 				printf("Invalid flow type specified.\n");
11196 				return;
11197 			}
11198 			ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11199 								 mapping);
11200 			if (ret)
11201 				return;
11202 			if (mapping[flow_type].pctype == 0ULL) {
11203 				printf("Invalid flow type specified.\n");
11204 				return;
11205 			}
11206 			for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11207 				if (mapping[flow_type].pctype & (1ULL << i)) {
11208 					conf.input.pctype = i;
11209 					break;
11210 				}
11211 			}
11212 
11213 			conf.input.packet = open_file(res->filepath,
11214 						&conf.input.length);
11215 			if (!conf.input.packet)
11216 				return;
11217 			if (!strcmp(res->drop, "drop"))
11218 				conf.action.behavior =
11219 					RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11220 			else
11221 				conf.action.behavior =
11222 					RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11223 			conf.action.report_status =
11224 					RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11225 			conf.action.rx_queue = res->queue_id;
11226 			conf.soft_id = res->fd_id_value;
11227 			add  = strcmp(res->ops, "del") ? 1 : 0;
11228 			ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11229 									&conf,
11230 									add);
11231 			if (ret < 0)
11232 				printf("flow director config error: (%s)\n",
11233 				       strerror(-ret));
11234 			close_file(conf.input.packet);
11235 #endif
11236 			return;
11237 		} else if (strcmp(res->mode_value, "IP")) {
11238 			printf("Please set mode to IP or raw.\n");
11239 			return;
11240 		}
11241 		entry.input.flow_type = str2flowtype(res->flow_type);
11242 	}
11243 
11244 	ret = parse_flexbytes(res->flexbytes_value,
11245 					flexbytes,
11246 					RTE_ETH_FDIR_MAX_FLEXLEN);
11247 	if (ret < 0) {
11248 		printf("error: Cannot parse flexbytes input.\n");
11249 		return;
11250 	}
11251 
11252 	switch (entry.input.flow_type) {
11253 	case RTE_ETH_FLOW_FRAG_IPV4:
11254 	case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11255 		entry.input.flow.ip4_flow.proto = res->proto_value;
11256 		/* fall-through */
11257 	case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11258 	case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11259 		IPV4_ADDR_TO_UINT(res->ip_dst,
11260 			entry.input.flow.ip4_flow.dst_ip);
11261 		IPV4_ADDR_TO_UINT(res->ip_src,
11262 			entry.input.flow.ip4_flow.src_ip);
11263 		entry.input.flow.ip4_flow.tos = res->tos_value;
11264 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
11265 		/* need convert to big endian. */
11266 		entry.input.flow.udp4_flow.dst_port =
11267 				rte_cpu_to_be_16(res->port_dst);
11268 		entry.input.flow.udp4_flow.src_port =
11269 				rte_cpu_to_be_16(res->port_src);
11270 		break;
11271 	case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11272 		IPV4_ADDR_TO_UINT(res->ip_dst,
11273 			entry.input.flow.sctp4_flow.ip.dst_ip);
11274 		IPV4_ADDR_TO_UINT(res->ip_src,
11275 			entry.input.flow.sctp4_flow.ip.src_ip);
11276 		entry.input.flow.ip4_flow.tos = res->tos_value;
11277 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
11278 		/* need convert to big endian. */
11279 		entry.input.flow.sctp4_flow.dst_port =
11280 				rte_cpu_to_be_16(res->port_dst);
11281 		entry.input.flow.sctp4_flow.src_port =
11282 				rte_cpu_to_be_16(res->port_src);
11283 		entry.input.flow.sctp4_flow.verify_tag =
11284 				rte_cpu_to_be_32(res->verify_tag_value);
11285 		break;
11286 	case RTE_ETH_FLOW_FRAG_IPV6:
11287 	case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11288 		entry.input.flow.ipv6_flow.proto = res->proto_value;
11289 		/* fall-through */
11290 	case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11291 	case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11292 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
11293 			entry.input.flow.ipv6_flow.dst_ip);
11294 		IPV6_ADDR_TO_ARRAY(res->ip_src,
11295 			entry.input.flow.ipv6_flow.src_ip);
11296 		entry.input.flow.ipv6_flow.tc = res->tos_value;
11297 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11298 		/* need convert to big endian. */
11299 		entry.input.flow.udp6_flow.dst_port =
11300 				rte_cpu_to_be_16(res->port_dst);
11301 		entry.input.flow.udp6_flow.src_port =
11302 				rte_cpu_to_be_16(res->port_src);
11303 		break;
11304 	case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11305 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
11306 			entry.input.flow.sctp6_flow.ip.dst_ip);
11307 		IPV6_ADDR_TO_ARRAY(res->ip_src,
11308 			entry.input.flow.sctp6_flow.ip.src_ip);
11309 		entry.input.flow.ipv6_flow.tc = res->tos_value;
11310 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11311 		/* need convert to big endian. */
11312 		entry.input.flow.sctp6_flow.dst_port =
11313 				rte_cpu_to_be_16(res->port_dst);
11314 		entry.input.flow.sctp6_flow.src_port =
11315 				rte_cpu_to_be_16(res->port_src);
11316 		entry.input.flow.sctp6_flow.verify_tag =
11317 				rte_cpu_to_be_32(res->verify_tag_value);
11318 		break;
11319 	case RTE_ETH_FLOW_L2_PAYLOAD:
11320 		entry.input.flow.l2_flow.ether_type =
11321 			rte_cpu_to_be_16(res->ether_type);
11322 		break;
11323 	default:
11324 		break;
11325 	}
11326 
11327 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11328 		rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11329 				 &res->mac_addr,
11330 				 sizeof(struct rte_ether_addr));
11331 
11332 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11333 		rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11334 				 &res->mac_addr,
11335 				 sizeof(struct rte_ether_addr));
11336 		entry.input.flow.tunnel_flow.tunnel_type =
11337 			str2fdir_tunneltype(res->tunnel_type);
11338 		entry.input.flow.tunnel_flow.tunnel_id =
11339 			rte_cpu_to_be_32(res->tunnel_id_value);
11340 	}
11341 
11342 	rte_memcpy(entry.input.flow_ext.flexbytes,
11343 		   flexbytes,
11344 		   RTE_ETH_FDIR_MAX_FLEXLEN);
11345 
11346 	entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11347 
11348 	entry.action.flex_off = 0;  /*use 0 by default */
11349 	if (!strcmp(res->drop, "drop"))
11350 		entry.action.behavior = RTE_ETH_FDIR_REJECT;
11351 	else
11352 		entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11353 
11354 	if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11355 	    fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11356 		if (!strcmp(res->pf_vf, "pf"))
11357 			entry.input.flow_ext.is_vf = 0;
11358 		else if (!strncmp(res->pf_vf, "vf", 2)) {
11359 			struct rte_eth_dev_info dev_info;
11360 
11361 			ret = eth_dev_info_get_print_err(res->port_id,
11362 						&dev_info);
11363 			if (ret != 0)
11364 				return;
11365 
11366 			errno = 0;
11367 			vf_id = strtoul(res->pf_vf + 2, &end, 10);
11368 			if (errno != 0 || *end != '\0' ||
11369 			    vf_id >= dev_info.max_vfs) {
11370 				printf("invalid parameter %s.\n", res->pf_vf);
11371 				return;
11372 			}
11373 			entry.input.flow_ext.is_vf = 1;
11374 			entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11375 		} else {
11376 			printf("invalid parameter %s.\n", res->pf_vf);
11377 			return;
11378 		}
11379 	}
11380 
11381 	/* set to report FD ID by default */
11382 	entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11383 	entry.action.rx_queue = res->queue_id;
11384 	entry.soft_id = res->fd_id_value;
11385 	if (!strcmp(res->ops, "add"))
11386 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11387 					     RTE_ETH_FILTER_ADD, &entry);
11388 	else if (!strcmp(res->ops, "del"))
11389 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11390 					     RTE_ETH_FILTER_DELETE, &entry);
11391 	else
11392 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11393 					     RTE_ETH_FILTER_UPDATE, &entry);
11394 	if (ret < 0)
11395 		printf("flow director programming error: (%s)\n",
11396 			strerror(-ret));
11397 }
11398 
11399 cmdline_parse_token_string_t cmd_flow_director_filter =
11400 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11401 				 flow_director_filter, "flow_director_filter");
11402 cmdline_parse_token_num_t cmd_flow_director_port_id =
11403 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11404 			      port_id, UINT16);
11405 cmdline_parse_token_string_t cmd_flow_director_ops =
11406 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11407 				 ops, "add#del#update");
11408 cmdline_parse_token_string_t cmd_flow_director_flow =
11409 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11410 				 flow, "flow");
11411 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11412 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11413 		flow_type, NULL);
11414 cmdline_parse_token_string_t cmd_flow_director_ether =
11415 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11416 				 ether, "ether");
11417 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11418 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11419 			      ether_type, UINT16);
11420 cmdline_parse_token_string_t cmd_flow_director_src =
11421 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11422 				 src, "src");
11423 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11424 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11425 				 ip_src);
11426 cmdline_parse_token_num_t cmd_flow_director_port_src =
11427 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11428 			      port_src, UINT16);
11429 cmdline_parse_token_string_t cmd_flow_director_dst =
11430 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11431 				 dst, "dst");
11432 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11433 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11434 				 ip_dst);
11435 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11436 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11437 			      port_dst, UINT16);
11438 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11439 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11440 				  verify_tag, "verify_tag");
11441 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11442 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11443 			      verify_tag_value, UINT32);
11444 cmdline_parse_token_string_t cmd_flow_director_tos =
11445 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11446 				 tos, "tos");
11447 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11448 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11449 			      tos_value, UINT8);
11450 cmdline_parse_token_string_t cmd_flow_director_proto =
11451 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11452 				 proto, "proto");
11453 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11454 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11455 			      proto_value, UINT8);
11456 cmdline_parse_token_string_t cmd_flow_director_ttl =
11457 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11458 				 ttl, "ttl");
11459 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11460 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11461 			      ttl_value, UINT8);
11462 cmdline_parse_token_string_t cmd_flow_director_vlan =
11463 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11464 				 vlan, "vlan");
11465 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11466 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11467 			      vlan_value, UINT16);
11468 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11469 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11470 				 flexbytes, "flexbytes");
11471 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11472 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11473 			      flexbytes_value, NULL);
11474 cmdline_parse_token_string_t cmd_flow_director_drop =
11475 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11476 				 drop, "drop#fwd");
11477 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11478 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11479 			      pf_vf, NULL);
11480 cmdline_parse_token_string_t cmd_flow_director_queue =
11481 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11482 				 queue, "queue");
11483 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11484 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11485 			      queue_id, UINT16);
11486 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11487 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11488 				 fd_id, "fd_id");
11489 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11490 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11491 			      fd_id_value, UINT32);
11492 
11493 cmdline_parse_token_string_t cmd_flow_director_mode =
11494 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11495 				 mode, "mode");
11496 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11497 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11498 				 mode_value, "IP");
11499 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11500 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11501 				 mode_value, "MAC-VLAN");
11502 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11503 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11504 				 mode_value, "Tunnel");
11505 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11506 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11507 				 mode_value, "raw");
11508 cmdline_parse_token_string_t cmd_flow_director_mac =
11509 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11510 				 mac, "mac");
11511 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11512 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11513 				    mac_addr);
11514 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11515 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11516 				 tunnel, "tunnel");
11517 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11518 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11519 				 tunnel_type, "NVGRE#VxLAN");
11520 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11521 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11522 				 tunnel_id, "tunnel-id");
11523 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11524 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11525 			      tunnel_id_value, UINT32);
11526 cmdline_parse_token_string_t cmd_flow_director_packet =
11527 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11528 				 packet, "packet");
11529 cmdline_parse_token_string_t cmd_flow_director_filepath =
11530 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11531 				 filepath, NULL);
11532 
11533 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11534 	.f = cmd_flow_director_filter_parsed,
11535 	.data = NULL,
11536 	.help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11537 		" ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11538 		"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11539 		"l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11540 		"proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11541 		"flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11542 		"fd_id <fd_id_value>: "
11543 		"Add or delete an ip flow director entry on NIC",
11544 	.tokens = {
11545 		(void *)&cmd_flow_director_filter,
11546 		(void *)&cmd_flow_director_port_id,
11547 		(void *)&cmd_flow_director_mode,
11548 		(void *)&cmd_flow_director_mode_ip,
11549 		(void *)&cmd_flow_director_ops,
11550 		(void *)&cmd_flow_director_flow,
11551 		(void *)&cmd_flow_director_flow_type,
11552 		(void *)&cmd_flow_director_src,
11553 		(void *)&cmd_flow_director_ip_src,
11554 		(void *)&cmd_flow_director_dst,
11555 		(void *)&cmd_flow_director_ip_dst,
11556 		(void *)&cmd_flow_director_tos,
11557 		(void *)&cmd_flow_director_tos_value,
11558 		(void *)&cmd_flow_director_proto,
11559 		(void *)&cmd_flow_director_proto_value,
11560 		(void *)&cmd_flow_director_ttl,
11561 		(void *)&cmd_flow_director_ttl_value,
11562 		(void *)&cmd_flow_director_vlan,
11563 		(void *)&cmd_flow_director_vlan_value,
11564 		(void *)&cmd_flow_director_flexbytes,
11565 		(void *)&cmd_flow_director_flexbytes_value,
11566 		(void *)&cmd_flow_director_drop,
11567 		(void *)&cmd_flow_director_pf_vf,
11568 		(void *)&cmd_flow_director_queue,
11569 		(void *)&cmd_flow_director_queue_id,
11570 		(void *)&cmd_flow_director_fd_id,
11571 		(void *)&cmd_flow_director_fd_id_value,
11572 		NULL,
11573 	},
11574 };
11575 
11576 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11577 	.f = cmd_flow_director_filter_parsed,
11578 	.data = NULL,
11579 	.help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11580 		"director entry on NIC",
11581 	.tokens = {
11582 		(void *)&cmd_flow_director_filter,
11583 		(void *)&cmd_flow_director_port_id,
11584 		(void *)&cmd_flow_director_mode,
11585 		(void *)&cmd_flow_director_mode_ip,
11586 		(void *)&cmd_flow_director_ops,
11587 		(void *)&cmd_flow_director_flow,
11588 		(void *)&cmd_flow_director_flow_type,
11589 		(void *)&cmd_flow_director_src,
11590 		(void *)&cmd_flow_director_ip_src,
11591 		(void *)&cmd_flow_director_port_src,
11592 		(void *)&cmd_flow_director_dst,
11593 		(void *)&cmd_flow_director_ip_dst,
11594 		(void *)&cmd_flow_director_port_dst,
11595 		(void *)&cmd_flow_director_tos,
11596 		(void *)&cmd_flow_director_tos_value,
11597 		(void *)&cmd_flow_director_ttl,
11598 		(void *)&cmd_flow_director_ttl_value,
11599 		(void *)&cmd_flow_director_vlan,
11600 		(void *)&cmd_flow_director_vlan_value,
11601 		(void *)&cmd_flow_director_flexbytes,
11602 		(void *)&cmd_flow_director_flexbytes_value,
11603 		(void *)&cmd_flow_director_drop,
11604 		(void *)&cmd_flow_director_pf_vf,
11605 		(void *)&cmd_flow_director_queue,
11606 		(void *)&cmd_flow_director_queue_id,
11607 		(void *)&cmd_flow_director_fd_id,
11608 		(void *)&cmd_flow_director_fd_id_value,
11609 		NULL,
11610 	},
11611 };
11612 
11613 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11614 	.f = cmd_flow_director_filter_parsed,
11615 	.data = NULL,
11616 	.help_str = "flow_director_filter ... : Add or delete a sctp flow "
11617 		"director entry on NIC",
11618 	.tokens = {
11619 		(void *)&cmd_flow_director_filter,
11620 		(void *)&cmd_flow_director_port_id,
11621 		(void *)&cmd_flow_director_mode,
11622 		(void *)&cmd_flow_director_mode_ip,
11623 		(void *)&cmd_flow_director_ops,
11624 		(void *)&cmd_flow_director_flow,
11625 		(void *)&cmd_flow_director_flow_type,
11626 		(void *)&cmd_flow_director_src,
11627 		(void *)&cmd_flow_director_ip_src,
11628 		(void *)&cmd_flow_director_port_src,
11629 		(void *)&cmd_flow_director_dst,
11630 		(void *)&cmd_flow_director_ip_dst,
11631 		(void *)&cmd_flow_director_port_dst,
11632 		(void *)&cmd_flow_director_verify_tag,
11633 		(void *)&cmd_flow_director_verify_tag_value,
11634 		(void *)&cmd_flow_director_tos,
11635 		(void *)&cmd_flow_director_tos_value,
11636 		(void *)&cmd_flow_director_ttl,
11637 		(void *)&cmd_flow_director_ttl_value,
11638 		(void *)&cmd_flow_director_vlan,
11639 		(void *)&cmd_flow_director_vlan_value,
11640 		(void *)&cmd_flow_director_flexbytes,
11641 		(void *)&cmd_flow_director_flexbytes_value,
11642 		(void *)&cmd_flow_director_drop,
11643 		(void *)&cmd_flow_director_pf_vf,
11644 		(void *)&cmd_flow_director_queue,
11645 		(void *)&cmd_flow_director_queue_id,
11646 		(void *)&cmd_flow_director_fd_id,
11647 		(void *)&cmd_flow_director_fd_id_value,
11648 		NULL,
11649 	},
11650 };
11651 
11652 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11653 	.f = cmd_flow_director_filter_parsed,
11654 	.data = NULL,
11655 	.help_str = "flow_director_filter ... : Add or delete a L2 flow "
11656 		"director entry on NIC",
11657 	.tokens = {
11658 		(void *)&cmd_flow_director_filter,
11659 		(void *)&cmd_flow_director_port_id,
11660 		(void *)&cmd_flow_director_mode,
11661 		(void *)&cmd_flow_director_mode_ip,
11662 		(void *)&cmd_flow_director_ops,
11663 		(void *)&cmd_flow_director_flow,
11664 		(void *)&cmd_flow_director_flow_type,
11665 		(void *)&cmd_flow_director_ether,
11666 		(void *)&cmd_flow_director_ether_type,
11667 		(void *)&cmd_flow_director_flexbytes,
11668 		(void *)&cmd_flow_director_flexbytes_value,
11669 		(void *)&cmd_flow_director_drop,
11670 		(void *)&cmd_flow_director_pf_vf,
11671 		(void *)&cmd_flow_director_queue,
11672 		(void *)&cmd_flow_director_queue_id,
11673 		(void *)&cmd_flow_director_fd_id,
11674 		(void *)&cmd_flow_director_fd_id_value,
11675 		NULL,
11676 	},
11677 };
11678 
11679 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11680 	.f = cmd_flow_director_filter_parsed,
11681 	.data = NULL,
11682 	.help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11683 		"director entry on NIC",
11684 	.tokens = {
11685 		(void *)&cmd_flow_director_filter,
11686 		(void *)&cmd_flow_director_port_id,
11687 		(void *)&cmd_flow_director_mode,
11688 		(void *)&cmd_flow_director_mode_mac_vlan,
11689 		(void *)&cmd_flow_director_ops,
11690 		(void *)&cmd_flow_director_mac,
11691 		(void *)&cmd_flow_director_mac_addr,
11692 		(void *)&cmd_flow_director_vlan,
11693 		(void *)&cmd_flow_director_vlan_value,
11694 		(void *)&cmd_flow_director_flexbytes,
11695 		(void *)&cmd_flow_director_flexbytes_value,
11696 		(void *)&cmd_flow_director_drop,
11697 		(void *)&cmd_flow_director_queue,
11698 		(void *)&cmd_flow_director_queue_id,
11699 		(void *)&cmd_flow_director_fd_id,
11700 		(void *)&cmd_flow_director_fd_id_value,
11701 		NULL,
11702 	},
11703 };
11704 
11705 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11706 	.f = cmd_flow_director_filter_parsed,
11707 	.data = NULL,
11708 	.help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11709 		"director entry on NIC",
11710 	.tokens = {
11711 		(void *)&cmd_flow_director_filter,
11712 		(void *)&cmd_flow_director_port_id,
11713 		(void *)&cmd_flow_director_mode,
11714 		(void *)&cmd_flow_director_mode_tunnel,
11715 		(void *)&cmd_flow_director_ops,
11716 		(void *)&cmd_flow_director_mac,
11717 		(void *)&cmd_flow_director_mac_addr,
11718 		(void *)&cmd_flow_director_vlan,
11719 		(void *)&cmd_flow_director_vlan_value,
11720 		(void *)&cmd_flow_director_tunnel,
11721 		(void *)&cmd_flow_director_tunnel_type,
11722 		(void *)&cmd_flow_director_tunnel_id,
11723 		(void *)&cmd_flow_director_tunnel_id_value,
11724 		(void *)&cmd_flow_director_flexbytes,
11725 		(void *)&cmd_flow_director_flexbytes_value,
11726 		(void *)&cmd_flow_director_drop,
11727 		(void *)&cmd_flow_director_queue,
11728 		(void *)&cmd_flow_director_queue_id,
11729 		(void *)&cmd_flow_director_fd_id,
11730 		(void *)&cmd_flow_director_fd_id_value,
11731 		NULL,
11732 	},
11733 };
11734 
11735 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11736 	.f = cmd_flow_director_filter_parsed,
11737 	.data = NULL,
11738 	.help_str = "flow_director_filter ... : Add or delete a raw flow "
11739 		"director entry on NIC",
11740 	.tokens = {
11741 		(void *)&cmd_flow_director_filter,
11742 		(void *)&cmd_flow_director_port_id,
11743 		(void *)&cmd_flow_director_mode,
11744 		(void *)&cmd_flow_director_mode_raw,
11745 		(void *)&cmd_flow_director_ops,
11746 		(void *)&cmd_flow_director_flow,
11747 		(void *)&cmd_flow_director_flow_type,
11748 		(void *)&cmd_flow_director_drop,
11749 		(void *)&cmd_flow_director_queue,
11750 		(void *)&cmd_flow_director_queue_id,
11751 		(void *)&cmd_flow_director_fd_id,
11752 		(void *)&cmd_flow_director_fd_id_value,
11753 		(void *)&cmd_flow_director_packet,
11754 		(void *)&cmd_flow_director_filepath,
11755 		NULL,
11756 	},
11757 };
11758 
11759 struct cmd_flush_flow_director_result {
11760 	cmdline_fixed_string_t flush_flow_director;
11761 	portid_t port_id;
11762 };
11763 
11764 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11765 	TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11766 				 flush_flow_director, "flush_flow_director");
11767 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11768 	TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11769 			      port_id, UINT16);
11770 
11771 static void
11772 cmd_flush_flow_director_parsed(void *parsed_result,
11773 			  __rte_unused struct cmdline *cl,
11774 			  __rte_unused void *data)
11775 {
11776 	struct cmd_flow_director_result *res = parsed_result;
11777 	int ret = 0;
11778 
11779 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11780 	if (ret < 0) {
11781 		printf("flow director is not supported on port %u.\n",
11782 			res->port_id);
11783 		return;
11784 	}
11785 
11786 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11787 			RTE_ETH_FILTER_FLUSH, NULL);
11788 	if (ret < 0)
11789 		printf("flow director table flushing error: (%s)\n",
11790 			strerror(-ret));
11791 }
11792 
11793 cmdline_parse_inst_t cmd_flush_flow_director = {
11794 	.f = cmd_flush_flow_director_parsed,
11795 	.data = NULL,
11796 	.help_str = "flush_flow_director <port_id>: "
11797 		"Flush all flow director entries of a device on NIC",
11798 	.tokens = {
11799 		(void *)&cmd_flush_flow_director_flush,
11800 		(void *)&cmd_flush_flow_director_port_id,
11801 		NULL,
11802 	},
11803 };
11804 
11805 /* *** deal with flow director mask *** */
11806 struct cmd_flow_director_mask_result {
11807 	cmdline_fixed_string_t flow_director_mask;
11808 	portid_t port_id;
11809 	cmdline_fixed_string_t mode;
11810 	cmdline_fixed_string_t mode_value;
11811 	cmdline_fixed_string_t vlan;
11812 	uint16_t vlan_mask;
11813 	cmdline_fixed_string_t src_mask;
11814 	cmdline_ipaddr_t ipv4_src;
11815 	cmdline_ipaddr_t ipv6_src;
11816 	uint16_t port_src;
11817 	cmdline_fixed_string_t dst_mask;
11818 	cmdline_ipaddr_t ipv4_dst;
11819 	cmdline_ipaddr_t ipv6_dst;
11820 	uint16_t port_dst;
11821 	cmdline_fixed_string_t mac;
11822 	uint8_t mac_addr_byte_mask;
11823 	cmdline_fixed_string_t tunnel_id;
11824 	uint32_t tunnel_id_mask;
11825 	cmdline_fixed_string_t tunnel_type;
11826 	uint8_t tunnel_type_mask;
11827 };
11828 
11829 static void
11830 cmd_flow_director_mask_parsed(void *parsed_result,
11831 			  __rte_unused struct cmdline *cl,
11832 			  __rte_unused void *data)
11833 {
11834 	struct cmd_flow_director_mask_result *res = parsed_result;
11835 	struct rte_eth_fdir_masks *mask;
11836 	struct rte_port *port;
11837 
11838 	port = &ports[res->port_id];
11839 	/** Check if the port is not started **/
11840 	if (port->port_status != RTE_PORT_STOPPED) {
11841 		printf("Please stop port %d first\n", res->port_id);
11842 		return;
11843 	}
11844 
11845 	mask = &port->dev_conf.fdir_conf.mask;
11846 
11847 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11848 		if (strcmp(res->mode_value, "MAC-VLAN")) {
11849 			printf("Please set mode to MAC-VLAN.\n");
11850 			return;
11851 		}
11852 
11853 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11854 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11855 		if (strcmp(res->mode_value, "Tunnel")) {
11856 			printf("Please set mode to Tunnel.\n");
11857 			return;
11858 		}
11859 
11860 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11861 		mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11862 		mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11863 		mask->tunnel_type_mask = res->tunnel_type_mask;
11864 	} else {
11865 		if (strcmp(res->mode_value, "IP")) {
11866 			printf("Please set mode to IP.\n");
11867 			return;
11868 		}
11869 
11870 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11871 		IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11872 		IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11873 		IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11874 		IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11875 		mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11876 		mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11877 	}
11878 
11879 	cmd_reconfig_device_queue(res->port_id, 1, 1);
11880 }
11881 
11882 cmdline_parse_token_string_t cmd_flow_director_mask =
11883 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11884 				 flow_director_mask, "flow_director_mask");
11885 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11886 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11887 			      port_id, UINT16);
11888 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11889 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11890 				 vlan, "vlan");
11891 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11892 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11893 			      vlan_mask, UINT16);
11894 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11895 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11896 				 src_mask, "src_mask");
11897 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11898 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11899 				 ipv4_src);
11900 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11901 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11902 				 ipv6_src);
11903 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11904 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11905 			      port_src, UINT16);
11906 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11907 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11908 				 dst_mask, "dst_mask");
11909 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11910 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11911 				 ipv4_dst);
11912 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11913 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11914 				 ipv6_dst);
11915 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11916 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11917 			      port_dst, UINT16);
11918 
11919 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11920 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11921 				 mode, "mode");
11922 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11923 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11924 				 mode_value, "IP");
11925 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11926 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11927 				 mode_value, "MAC-VLAN");
11928 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11929 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11930 				 mode_value, "Tunnel");
11931 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11932 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11933 				 mac, "mac");
11934 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11935 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11936 			      mac_addr_byte_mask, UINT8);
11937 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11938 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11939 				 tunnel_type, "tunnel-type");
11940 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11941 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11942 			      tunnel_type_mask, UINT8);
11943 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11944 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11945 				 tunnel_id, "tunnel-id");
11946 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11947 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11948 			      tunnel_id_mask, UINT32);
11949 
11950 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11951 	.f = cmd_flow_director_mask_parsed,
11952 	.data = NULL,
11953 	.help_str = "flow_director_mask ... : "
11954 		"Set IP mode flow director's mask on NIC",
11955 	.tokens = {
11956 		(void *)&cmd_flow_director_mask,
11957 		(void *)&cmd_flow_director_mask_port_id,
11958 		(void *)&cmd_flow_director_mask_mode,
11959 		(void *)&cmd_flow_director_mask_mode_ip,
11960 		(void *)&cmd_flow_director_mask_vlan,
11961 		(void *)&cmd_flow_director_mask_vlan_value,
11962 		(void *)&cmd_flow_director_mask_src,
11963 		(void *)&cmd_flow_director_mask_ipv4_src,
11964 		(void *)&cmd_flow_director_mask_ipv6_src,
11965 		(void *)&cmd_flow_director_mask_port_src,
11966 		(void *)&cmd_flow_director_mask_dst,
11967 		(void *)&cmd_flow_director_mask_ipv4_dst,
11968 		(void *)&cmd_flow_director_mask_ipv6_dst,
11969 		(void *)&cmd_flow_director_mask_port_dst,
11970 		NULL,
11971 	},
11972 };
11973 
11974 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11975 	.f = cmd_flow_director_mask_parsed,
11976 	.data = NULL,
11977 	.help_str = "flow_director_mask ... : Set MAC VLAN mode "
11978 		"flow director's mask on NIC",
11979 	.tokens = {
11980 		(void *)&cmd_flow_director_mask,
11981 		(void *)&cmd_flow_director_mask_port_id,
11982 		(void *)&cmd_flow_director_mask_mode,
11983 		(void *)&cmd_flow_director_mask_mode_mac_vlan,
11984 		(void *)&cmd_flow_director_mask_vlan,
11985 		(void *)&cmd_flow_director_mask_vlan_value,
11986 		NULL,
11987 	},
11988 };
11989 
11990 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11991 	.f = cmd_flow_director_mask_parsed,
11992 	.data = NULL,
11993 	.help_str = "flow_director_mask ... : Set tunnel mode "
11994 		"flow director's mask on NIC",
11995 	.tokens = {
11996 		(void *)&cmd_flow_director_mask,
11997 		(void *)&cmd_flow_director_mask_port_id,
11998 		(void *)&cmd_flow_director_mask_mode,
11999 		(void *)&cmd_flow_director_mask_mode_tunnel,
12000 		(void *)&cmd_flow_director_mask_vlan,
12001 		(void *)&cmd_flow_director_mask_vlan_value,
12002 		(void *)&cmd_flow_director_mask_mac,
12003 		(void *)&cmd_flow_director_mask_mac_value,
12004 		(void *)&cmd_flow_director_mask_tunnel_type,
12005 		(void *)&cmd_flow_director_mask_tunnel_type_value,
12006 		(void *)&cmd_flow_director_mask_tunnel_id,
12007 		(void *)&cmd_flow_director_mask_tunnel_id_value,
12008 		NULL,
12009 	},
12010 };
12011 
12012 /* *** deal with flow director mask on flexible payload *** */
12013 struct cmd_flow_director_flex_mask_result {
12014 	cmdline_fixed_string_t flow_director_flexmask;
12015 	portid_t port_id;
12016 	cmdline_fixed_string_t flow;
12017 	cmdline_fixed_string_t flow_type;
12018 	cmdline_fixed_string_t mask;
12019 };
12020 
12021 static void
12022 cmd_flow_director_flex_mask_parsed(void *parsed_result,
12023 			  __rte_unused struct cmdline *cl,
12024 			  __rte_unused void *data)
12025 {
12026 	struct cmd_flow_director_flex_mask_result *res = parsed_result;
12027 	struct rte_eth_fdir_info fdir_info;
12028 	struct rte_eth_fdir_flex_mask flex_mask;
12029 	struct rte_port *port;
12030 	uint64_t flow_type_mask;
12031 	uint16_t i;
12032 	int ret;
12033 
12034 	port = &ports[res->port_id];
12035 	/** Check if the port is not started **/
12036 	if (port->port_status != RTE_PORT_STOPPED) {
12037 		printf("Please stop port %d first\n", res->port_id);
12038 		return;
12039 	}
12040 
12041 	memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
12042 	ret = parse_flexbytes(res->mask,
12043 			flex_mask.mask,
12044 			RTE_ETH_FDIR_MAX_FLEXLEN);
12045 	if (ret < 0) {
12046 		printf("error: Cannot parse mask input.\n");
12047 		return;
12048 	}
12049 
12050 	memset(&fdir_info, 0, sizeof(fdir_info));
12051 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12052 				RTE_ETH_FILTER_INFO, &fdir_info);
12053 	if (ret < 0) {
12054 		printf("Cannot get FDir filter info\n");
12055 		return;
12056 	}
12057 
12058 	if (!strcmp(res->flow_type, "none")) {
12059 		/* means don't specify the flow type */
12060 		flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
12061 		for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
12062 			memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
12063 			       0, sizeof(struct rte_eth_fdir_flex_mask));
12064 		port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12065 		rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12066 				 &flex_mask,
12067 				 sizeof(struct rte_eth_fdir_flex_mask));
12068 		cmd_reconfig_device_queue(res->port_id, 1, 1);
12069 		return;
12070 	}
12071 	flow_type_mask = fdir_info.flow_types_mask[0];
12072 	if (!strcmp(res->flow_type, "all")) {
12073 		if (!flow_type_mask) {
12074 			printf("No flow type supported\n");
12075 			return;
12076 		}
12077 		for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12078 			if (flow_type_mask & (1ULL << i)) {
12079 				flex_mask.flow_type = i;
12080 				fdir_set_flex_mask(res->port_id, &flex_mask);
12081 			}
12082 		}
12083 		cmd_reconfig_device_queue(res->port_id, 1, 1);
12084 		return;
12085 	}
12086 	flex_mask.flow_type = str2flowtype(res->flow_type);
12087 	if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12088 		printf("Flow type %s not supported on port %d\n",
12089 				res->flow_type, res->port_id);
12090 		return;
12091 	}
12092 	fdir_set_flex_mask(res->port_id, &flex_mask);
12093 	cmd_reconfig_device_queue(res->port_id, 1, 1);
12094 }
12095 
12096 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12097 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12098 				 flow_director_flexmask,
12099 				 "flow_director_flex_mask");
12100 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12101 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12102 			      port_id, UINT16);
12103 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12104 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12105 				 flow, "flow");
12106 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12107 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12108 		flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12109 		"ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12110 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12111 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12112 				 mask, NULL);
12113 
12114 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12115 	.f = cmd_flow_director_flex_mask_parsed,
12116 	.data = NULL,
12117 	.help_str = "flow_director_flex_mask ... : "
12118 		"Set flow director's flex mask on NIC",
12119 	.tokens = {
12120 		(void *)&cmd_flow_director_flexmask,
12121 		(void *)&cmd_flow_director_flexmask_port_id,
12122 		(void *)&cmd_flow_director_flexmask_flow,
12123 		(void *)&cmd_flow_director_flexmask_flow_type,
12124 		(void *)&cmd_flow_director_flexmask_mask,
12125 		NULL,
12126 	},
12127 };
12128 
12129 /* *** deal with flow director flexible payload configuration *** */
12130 struct cmd_flow_director_flexpayload_result {
12131 	cmdline_fixed_string_t flow_director_flexpayload;
12132 	portid_t port_id;
12133 	cmdline_fixed_string_t payload_layer;
12134 	cmdline_fixed_string_t payload_cfg;
12135 };
12136 
12137 static inline int
12138 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12139 {
12140 	char s[256];
12141 	const char *p, *p0 = q_arg;
12142 	char *end;
12143 	unsigned long int_fld;
12144 	char *str_fld[max_num];
12145 	int i;
12146 	unsigned size;
12147 	int ret = -1;
12148 
12149 	p = strchr(p0, '(');
12150 	if (p == NULL)
12151 		return -1;
12152 	++p;
12153 	p0 = strchr(p, ')');
12154 	if (p0 == NULL)
12155 		return -1;
12156 
12157 	size = p0 - p;
12158 	if (size >= sizeof(s))
12159 		return -1;
12160 
12161 	snprintf(s, sizeof(s), "%.*s", size, p);
12162 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12163 	if (ret < 0 || ret > max_num)
12164 		return -1;
12165 	for (i = 0; i < ret; i++) {
12166 		errno = 0;
12167 		int_fld = strtoul(str_fld[i], &end, 0);
12168 		if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12169 			return -1;
12170 		offsets[i] = (uint16_t)int_fld;
12171 	}
12172 	return ret;
12173 }
12174 
12175 static void
12176 cmd_flow_director_flxpld_parsed(void *parsed_result,
12177 			  __rte_unused struct cmdline *cl,
12178 			  __rte_unused void *data)
12179 {
12180 	struct cmd_flow_director_flexpayload_result *res = parsed_result;
12181 	struct rte_eth_flex_payload_cfg flex_cfg;
12182 	struct rte_port *port;
12183 	int ret = 0;
12184 
12185 	port = &ports[res->port_id];
12186 	/** Check if the port is not started **/
12187 	if (port->port_status != RTE_PORT_STOPPED) {
12188 		printf("Please stop port %d first\n", res->port_id);
12189 		return;
12190 	}
12191 
12192 	memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12193 
12194 	if (!strcmp(res->payload_layer, "raw"))
12195 		flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12196 	else if (!strcmp(res->payload_layer, "l2"))
12197 		flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12198 	else if (!strcmp(res->payload_layer, "l3"))
12199 		flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12200 	else if (!strcmp(res->payload_layer, "l4"))
12201 		flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12202 
12203 	ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12204 			    RTE_ETH_FDIR_MAX_FLEXLEN);
12205 	if (ret < 0) {
12206 		printf("error: Cannot parse flex payload input.\n");
12207 		return;
12208 	}
12209 
12210 	fdir_set_flex_payload(res->port_id, &flex_cfg);
12211 	cmd_reconfig_device_queue(res->port_id, 1, 1);
12212 }
12213 
12214 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12215 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12216 				 flow_director_flexpayload,
12217 				 "flow_director_flex_payload");
12218 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12219 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12220 			      port_id, UINT16);
12221 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12222 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12223 				 payload_layer, "raw#l2#l3#l4");
12224 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12225 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12226 				 payload_cfg, NULL);
12227 
12228 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12229 	.f = cmd_flow_director_flxpld_parsed,
12230 	.data = NULL,
12231 	.help_str = "flow_director_flexpayload ... : "
12232 		"Set flow director's flex payload on NIC",
12233 	.tokens = {
12234 		(void *)&cmd_flow_director_flexpayload,
12235 		(void *)&cmd_flow_director_flexpayload_port_id,
12236 		(void *)&cmd_flow_director_flexpayload_payload_layer,
12237 		(void *)&cmd_flow_director_flexpayload_payload_cfg,
12238 		NULL,
12239 	},
12240 };
12241 
12242 /* Generic flow interface command. */
12243 extern cmdline_parse_inst_t cmd_flow;
12244 
12245 /* *** Classification Filters Control *** */
12246 /* *** Get symmetric hash enable per port *** */
12247 struct cmd_get_sym_hash_ena_per_port_result {
12248 	cmdline_fixed_string_t get_sym_hash_ena_per_port;
12249 	portid_t port_id;
12250 };
12251 
12252 static void
12253 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12254 				 __rte_unused struct cmdline *cl,
12255 				 __rte_unused void *data)
12256 {
12257 	struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12258 	struct rte_eth_hash_filter_info info;
12259 	int ret;
12260 
12261 	if (rte_eth_dev_filter_supported(res->port_id,
12262 				RTE_ETH_FILTER_HASH) < 0) {
12263 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12264 							res->port_id);
12265 		return;
12266 	}
12267 
12268 	memset(&info, 0, sizeof(info));
12269 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12270 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12271 						RTE_ETH_FILTER_GET, &info);
12272 
12273 	if (ret < 0) {
12274 		printf("Cannot get symmetric hash enable per port "
12275 					"on port %u\n", res->port_id);
12276 		return;
12277 	}
12278 
12279 	printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12280 				"enabled" : "disabled", res->port_id);
12281 }
12282 
12283 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12284 	TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12285 		get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12286 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12287 	TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12288 		port_id, UINT16);
12289 
12290 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12291 	.f = cmd_get_sym_hash_per_port_parsed,
12292 	.data = NULL,
12293 	.help_str = "get_sym_hash_ena_per_port <port_id>",
12294 	.tokens = {
12295 		(void *)&cmd_get_sym_hash_ena_per_port_all,
12296 		(void *)&cmd_get_sym_hash_ena_per_port_port_id,
12297 		NULL,
12298 	},
12299 };
12300 
12301 /* *** Set symmetric hash enable per port *** */
12302 struct cmd_set_sym_hash_ena_per_port_result {
12303 	cmdline_fixed_string_t set_sym_hash_ena_per_port;
12304 	cmdline_fixed_string_t enable;
12305 	portid_t port_id;
12306 };
12307 
12308 static void
12309 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12310 				 __rte_unused struct cmdline *cl,
12311 				 __rte_unused void *data)
12312 {
12313 	struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12314 	struct rte_eth_hash_filter_info info;
12315 	int ret;
12316 
12317 	if (rte_eth_dev_filter_supported(res->port_id,
12318 				RTE_ETH_FILTER_HASH) < 0) {
12319 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12320 							res->port_id);
12321 		return;
12322 	}
12323 
12324 	memset(&info, 0, sizeof(info));
12325 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12326 	if (!strcmp(res->enable, "enable"))
12327 		info.info.enable = 1;
12328 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12329 					RTE_ETH_FILTER_SET, &info);
12330 	if (ret < 0) {
12331 		printf("Cannot set symmetric hash enable per port on "
12332 					"port %u\n", res->port_id);
12333 		return;
12334 	}
12335 	printf("Symmetric hash has been set to %s on port %u\n",
12336 					res->enable, res->port_id);
12337 }
12338 
12339 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12340 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12341 		set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12342 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12343 	TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12344 		port_id, UINT16);
12345 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12346 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12347 		enable, "enable#disable");
12348 
12349 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12350 	.f = cmd_set_sym_hash_per_port_parsed,
12351 	.data = NULL,
12352 	.help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12353 	.tokens = {
12354 		(void *)&cmd_set_sym_hash_ena_per_port_all,
12355 		(void *)&cmd_set_sym_hash_ena_per_port_port_id,
12356 		(void *)&cmd_set_sym_hash_ena_per_port_enable,
12357 		NULL,
12358 	},
12359 };
12360 
12361 /* Get global config of hash function */
12362 struct cmd_get_hash_global_config_result {
12363 	cmdline_fixed_string_t get_hash_global_config;
12364 	portid_t port_id;
12365 };
12366 
12367 static char *
12368 flowtype_to_str(uint16_t ftype)
12369 {
12370 	uint16_t i;
12371 	static struct {
12372 		char str[16];
12373 		uint16_t ftype;
12374 	} ftype_table[] = {
12375 		{"ipv4", RTE_ETH_FLOW_IPV4},
12376 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12377 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12378 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12379 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12380 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12381 		{"ipv6", RTE_ETH_FLOW_IPV6},
12382 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12383 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12384 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12385 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12386 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12387 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12388 		{"port", RTE_ETH_FLOW_PORT},
12389 		{"vxlan", RTE_ETH_FLOW_VXLAN},
12390 		{"geneve", RTE_ETH_FLOW_GENEVE},
12391 		{"nvgre", RTE_ETH_FLOW_NVGRE},
12392 		{"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12393 	};
12394 
12395 	for (i = 0; i < RTE_DIM(ftype_table); i++) {
12396 		if (ftype_table[i].ftype == ftype)
12397 			return ftype_table[i].str;
12398 	}
12399 
12400 	return NULL;
12401 }
12402 
12403 static void
12404 cmd_get_hash_global_config_parsed(void *parsed_result,
12405 				  __rte_unused struct cmdline *cl,
12406 				  __rte_unused void *data)
12407 {
12408 	struct cmd_get_hash_global_config_result *res = parsed_result;
12409 	struct rte_eth_hash_filter_info info;
12410 	uint32_t idx, offset;
12411 	uint16_t i;
12412 	char *str;
12413 	int ret;
12414 
12415 	if (rte_eth_dev_filter_supported(res->port_id,
12416 			RTE_ETH_FILTER_HASH) < 0) {
12417 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12418 							res->port_id);
12419 		return;
12420 	}
12421 
12422 	memset(&info, 0, sizeof(info));
12423 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12424 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12425 					RTE_ETH_FILTER_GET, &info);
12426 	if (ret < 0) {
12427 		printf("Cannot get hash global configurations by port %d\n",
12428 							res->port_id);
12429 		return;
12430 	}
12431 
12432 	switch (info.info.global_conf.hash_func) {
12433 	case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12434 		printf("Hash function is Toeplitz\n");
12435 		break;
12436 	case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12437 		printf("Hash function is Simple XOR\n");
12438 		break;
12439 	case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12440 		printf("Hash function is Symmetric Toeplitz\n");
12441 		break;
12442 	default:
12443 		printf("Unknown hash function\n");
12444 		break;
12445 	}
12446 
12447 	for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12448 		idx = i / UINT64_BIT;
12449 		offset = i % UINT64_BIT;
12450 		if (!(info.info.global_conf.valid_bit_mask[idx] &
12451 						(1ULL << offset)))
12452 			continue;
12453 		str = flowtype_to_str(i);
12454 		if (!str)
12455 			continue;
12456 		printf("Symmetric hash is %s globally for flow type %s "
12457 							"by port %d\n",
12458 			((info.info.global_conf.sym_hash_enable_mask[idx] &
12459 			(1ULL << offset)) ? "enabled" : "disabled"), str,
12460 							res->port_id);
12461 	}
12462 }
12463 
12464 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12465 	TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12466 		get_hash_global_config, "get_hash_global_config");
12467 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12468 	TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12469 		port_id, UINT16);
12470 
12471 cmdline_parse_inst_t cmd_get_hash_global_config = {
12472 	.f = cmd_get_hash_global_config_parsed,
12473 	.data = NULL,
12474 	.help_str = "get_hash_global_config <port_id>",
12475 	.tokens = {
12476 		(void *)&cmd_get_hash_global_config_all,
12477 		(void *)&cmd_get_hash_global_config_port_id,
12478 		NULL,
12479 	},
12480 };
12481 
12482 /* Set global config of hash function */
12483 struct cmd_set_hash_global_config_result {
12484 	cmdline_fixed_string_t set_hash_global_config;
12485 	portid_t port_id;
12486 	cmdline_fixed_string_t hash_func;
12487 	cmdline_fixed_string_t flow_type;
12488 	cmdline_fixed_string_t enable;
12489 };
12490 
12491 static void
12492 cmd_set_hash_global_config_parsed(void *parsed_result,
12493 				  __rte_unused struct cmdline *cl,
12494 				  __rte_unused void *data)
12495 {
12496 	struct cmd_set_hash_global_config_result *res = parsed_result;
12497 	struct rte_eth_hash_filter_info info;
12498 	uint32_t ftype, idx, offset;
12499 	int ret;
12500 
12501 	if (rte_eth_dev_filter_supported(res->port_id,
12502 				RTE_ETH_FILTER_HASH) < 0) {
12503 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12504 							res->port_id);
12505 		return;
12506 	}
12507 	memset(&info, 0, sizeof(info));
12508 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12509 	if (!strcmp(res->hash_func, "toeplitz"))
12510 		info.info.global_conf.hash_func =
12511 			RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12512 	else if (!strcmp(res->hash_func, "simple_xor"))
12513 		info.info.global_conf.hash_func =
12514 			RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12515 	else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12516 		info.info.global_conf.hash_func =
12517 			RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12518 	else if (!strcmp(res->hash_func, "default"))
12519 		info.info.global_conf.hash_func =
12520 			RTE_ETH_HASH_FUNCTION_DEFAULT;
12521 
12522 	ftype = str2flowtype(res->flow_type);
12523 	idx = ftype / UINT64_BIT;
12524 	offset = ftype % UINT64_BIT;
12525 	info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12526 	if (!strcmp(res->enable, "enable"))
12527 		info.info.global_conf.sym_hash_enable_mask[idx] |=
12528 						(1ULL << offset);
12529 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12530 					RTE_ETH_FILTER_SET, &info);
12531 	if (ret < 0)
12532 		printf("Cannot set global hash configurations by port %d\n",
12533 							res->port_id);
12534 	else
12535 		printf("Global hash configurations have been set "
12536 			"successfully by port %d\n", res->port_id);
12537 }
12538 
12539 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12540 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12541 		set_hash_global_config, "set_hash_global_config");
12542 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12543 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12544 		port_id, UINT16);
12545 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12546 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12547 		hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12548 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12549 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12550 		flow_type,
12551 		"ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12552 		"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12553 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12554 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12555 		enable, "enable#disable");
12556 
12557 cmdline_parse_inst_t cmd_set_hash_global_config = {
12558 	.f = cmd_set_hash_global_config_parsed,
12559 	.data = NULL,
12560 	.help_str = "set_hash_global_config <port_id> "
12561 		"toeplitz|simple_xor|symmetric_toeplitz|default "
12562 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12563 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12564 		"l2_payload enable|disable",
12565 	.tokens = {
12566 		(void *)&cmd_set_hash_global_config_all,
12567 		(void *)&cmd_set_hash_global_config_port_id,
12568 		(void *)&cmd_set_hash_global_config_hash_func,
12569 		(void *)&cmd_set_hash_global_config_flow_type,
12570 		(void *)&cmd_set_hash_global_config_enable,
12571 		NULL,
12572 	},
12573 };
12574 
12575 /* Set hash input set */
12576 struct cmd_set_hash_input_set_result {
12577 	cmdline_fixed_string_t set_hash_input_set;
12578 	portid_t port_id;
12579 	cmdline_fixed_string_t flow_type;
12580 	cmdline_fixed_string_t inset_field;
12581 	cmdline_fixed_string_t select;
12582 };
12583 
12584 static enum rte_eth_input_set_field
12585 str2inset(char *string)
12586 {
12587 	uint16_t i;
12588 
12589 	static const struct {
12590 		char str[32];
12591 		enum rte_eth_input_set_field inset;
12592 	} inset_table[] = {
12593 		{"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12594 		{"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12595 		{"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12596 		{"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12597 		{"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12598 		{"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12599 		{"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12600 		{"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12601 		{"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12602 		{"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12603 		{"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12604 		{"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12605 		{"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12606 		{"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12607 		{"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12608 		{"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12609 		{"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12610 		{"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12611 		{"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12612 		{"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12613 		{"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12614 		{"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12615 		{"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12616 		{"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12617 		{"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12618 		{"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12619 		{"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12620 		{"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12621 		{"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12622 		{"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12623 		{"none", RTE_ETH_INPUT_SET_NONE},
12624 	};
12625 
12626 	for (i = 0; i < RTE_DIM(inset_table); i++) {
12627 		if (!strcmp(string, inset_table[i].str))
12628 			return inset_table[i].inset;
12629 	}
12630 
12631 	return RTE_ETH_INPUT_SET_UNKNOWN;
12632 }
12633 
12634 static void
12635 cmd_set_hash_input_set_parsed(void *parsed_result,
12636 			      __rte_unused struct cmdline *cl,
12637 			      __rte_unused void *data)
12638 {
12639 	struct cmd_set_hash_input_set_result *res = parsed_result;
12640 	struct rte_eth_hash_filter_info info;
12641 
12642 	memset(&info, 0, sizeof(info));
12643 	info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12644 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12645 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12646 	info.info.input_set_conf.inset_size = 1;
12647 	if (!strcmp(res->select, "select"))
12648 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12649 	else if (!strcmp(res->select, "add"))
12650 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12651 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12652 				RTE_ETH_FILTER_SET, &info);
12653 }
12654 
12655 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12656 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12657 		set_hash_input_set, "set_hash_input_set");
12658 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12659 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12660 		port_id, UINT16);
12661 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12662 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12663 		flow_type, NULL);
12664 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12665 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12666 		inset_field,
12667 		"ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12668 		"ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12669 		"udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12670 		"sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12671 		"fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12672 		"fld-8th#none");
12673 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12674 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12675 		select, "select#add");
12676 
12677 cmdline_parse_inst_t cmd_set_hash_input_set = {
12678 	.f = cmd_set_hash_input_set_parsed,
12679 	.data = NULL,
12680 	.help_str = "set_hash_input_set <port_id> "
12681 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12682 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12683 	"ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12684 	"ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12685 	"tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12686 	"gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12687 	"fld-7th|fld-8th|none select|add",
12688 	.tokens = {
12689 		(void *)&cmd_set_hash_input_set_cmd,
12690 		(void *)&cmd_set_hash_input_set_port_id,
12691 		(void *)&cmd_set_hash_input_set_flow_type,
12692 		(void *)&cmd_set_hash_input_set_field,
12693 		(void *)&cmd_set_hash_input_set_select,
12694 		NULL,
12695 	},
12696 };
12697 
12698 /* Set flow director input set */
12699 struct cmd_set_fdir_input_set_result {
12700 	cmdline_fixed_string_t set_fdir_input_set;
12701 	portid_t port_id;
12702 	cmdline_fixed_string_t flow_type;
12703 	cmdline_fixed_string_t inset_field;
12704 	cmdline_fixed_string_t select;
12705 };
12706 
12707 static void
12708 cmd_set_fdir_input_set_parsed(void *parsed_result,
12709 	__rte_unused struct cmdline *cl,
12710 	__rte_unused void *data)
12711 {
12712 	struct cmd_set_fdir_input_set_result *res = parsed_result;
12713 	struct rte_eth_fdir_filter_info info;
12714 
12715 	memset(&info, 0, sizeof(info));
12716 	info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12717 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12718 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12719 	info.info.input_set_conf.inset_size = 1;
12720 	if (!strcmp(res->select, "select"))
12721 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12722 	else if (!strcmp(res->select, "add"))
12723 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12724 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12725 		RTE_ETH_FILTER_SET, &info);
12726 }
12727 
12728 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12729 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12730 	set_fdir_input_set, "set_fdir_input_set");
12731 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12732 	TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12733 	port_id, UINT16);
12734 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12735 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12736 	flow_type,
12737 	"ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12738 	"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12739 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12740 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12741 	inset_field,
12742 	"ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12743 	"ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12744 	"ipv6-hop-limits#udp-src-port#udp-dst-port#"
12745 	"tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12746 	"sctp-veri-tag#none");
12747 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12748 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12749 	select, "select#add");
12750 
12751 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12752 	.f = cmd_set_fdir_input_set_parsed,
12753 	.data = NULL,
12754 	.help_str = "set_fdir_input_set <port_id> "
12755 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12756 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12757 	"ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12758 	"ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12759 	"ipv6-hop-limits|udp-src-port|udp-dst-port|"
12760 	"tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12761 	"sctp-veri-tag|none select|add",
12762 	.tokens = {
12763 		(void *)&cmd_set_fdir_input_set_cmd,
12764 		(void *)&cmd_set_fdir_input_set_port_id,
12765 		(void *)&cmd_set_fdir_input_set_flow_type,
12766 		(void *)&cmd_set_fdir_input_set_field,
12767 		(void *)&cmd_set_fdir_input_set_select,
12768 		NULL,
12769 	},
12770 };
12771 
12772 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12773 struct cmd_mcast_addr_result {
12774 	cmdline_fixed_string_t mcast_addr_cmd;
12775 	cmdline_fixed_string_t what;
12776 	uint16_t port_num;
12777 	struct rte_ether_addr mc_addr;
12778 };
12779 
12780 static void cmd_mcast_addr_parsed(void *parsed_result,
12781 		__rte_unused struct cmdline *cl,
12782 		__rte_unused void *data)
12783 {
12784 	struct cmd_mcast_addr_result *res = parsed_result;
12785 
12786 	if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12787 		printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12788 		       res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12789 		       res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12790 		       res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12791 		return;
12792 	}
12793 	if (strcmp(res->what, "add") == 0)
12794 		mcast_addr_add(res->port_num, &res->mc_addr);
12795 	else
12796 		mcast_addr_remove(res->port_num, &res->mc_addr);
12797 }
12798 
12799 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12800 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12801 				 mcast_addr_cmd, "mcast_addr");
12802 cmdline_parse_token_string_t cmd_mcast_addr_what =
12803 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12804 				 "add#remove");
12805 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12806 	TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12807 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12808 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12809 
12810 cmdline_parse_inst_t cmd_mcast_addr = {
12811 	.f = cmd_mcast_addr_parsed,
12812 	.data = (void *)0,
12813 	.help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12814 		"Add/Remove multicast MAC address on port_id",
12815 	.tokens = {
12816 		(void *)&cmd_mcast_addr_cmd,
12817 		(void *)&cmd_mcast_addr_what,
12818 		(void *)&cmd_mcast_addr_portnum,
12819 		(void *)&cmd_mcast_addr_addr,
12820 		NULL,
12821 	},
12822 };
12823 
12824 /* l2 tunnel config
12825  * only support E-tag now.
12826  */
12827 
12828 /* Ether type config */
12829 struct cmd_config_l2_tunnel_eth_type_result {
12830 	cmdline_fixed_string_t port;
12831 	cmdline_fixed_string_t config;
12832 	cmdline_fixed_string_t all;
12833 	portid_t id;
12834 	cmdline_fixed_string_t l2_tunnel;
12835 	cmdline_fixed_string_t l2_tunnel_type;
12836 	cmdline_fixed_string_t eth_type;
12837 	uint16_t eth_type_val;
12838 };
12839 
12840 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12841 	TOKEN_STRING_INITIALIZER
12842 		(struct cmd_config_l2_tunnel_eth_type_result,
12843 		 port, "port");
12844 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12845 	TOKEN_STRING_INITIALIZER
12846 		(struct cmd_config_l2_tunnel_eth_type_result,
12847 		 config, "config");
12848 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12849 	TOKEN_STRING_INITIALIZER
12850 		(struct cmd_config_l2_tunnel_eth_type_result,
12851 		 all, "all");
12852 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12853 	TOKEN_NUM_INITIALIZER
12854 		(struct cmd_config_l2_tunnel_eth_type_result,
12855 		 id, UINT16);
12856 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12857 	TOKEN_STRING_INITIALIZER
12858 		(struct cmd_config_l2_tunnel_eth_type_result,
12859 		 l2_tunnel, "l2-tunnel");
12860 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12861 	TOKEN_STRING_INITIALIZER
12862 		(struct cmd_config_l2_tunnel_eth_type_result,
12863 		 l2_tunnel_type, "E-tag");
12864 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12865 	TOKEN_STRING_INITIALIZER
12866 		(struct cmd_config_l2_tunnel_eth_type_result,
12867 		 eth_type, "ether-type");
12868 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12869 	TOKEN_NUM_INITIALIZER
12870 		(struct cmd_config_l2_tunnel_eth_type_result,
12871 		 eth_type_val, UINT16);
12872 
12873 static enum rte_eth_tunnel_type
12874 str2fdir_l2_tunnel_type(char *string)
12875 {
12876 	uint32_t i = 0;
12877 
12878 	static const struct {
12879 		char str[32];
12880 		enum rte_eth_tunnel_type type;
12881 	} l2_tunnel_type_str[] = {
12882 		{"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12883 	};
12884 
12885 	for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12886 		if (!strcmp(l2_tunnel_type_str[i].str, string))
12887 			return l2_tunnel_type_str[i].type;
12888 	}
12889 	return RTE_TUNNEL_TYPE_NONE;
12890 }
12891 
12892 /* ether type config for all ports */
12893 static void
12894 cmd_config_l2_tunnel_eth_type_all_parsed
12895 	(void *parsed_result,
12896 	 __rte_unused struct cmdline *cl,
12897 	 __rte_unused void *data)
12898 {
12899 	struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12900 	struct rte_eth_l2_tunnel_conf entry;
12901 	portid_t pid;
12902 
12903 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12904 	entry.ether_type = res->eth_type_val;
12905 
12906 	RTE_ETH_FOREACH_DEV(pid) {
12907 		rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12908 	}
12909 }
12910 
12911 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12912 	.f = cmd_config_l2_tunnel_eth_type_all_parsed,
12913 	.data = NULL,
12914 	.help_str = "port config all l2-tunnel E-tag ether-type <value>",
12915 	.tokens = {
12916 		(void *)&cmd_config_l2_tunnel_eth_type_port,
12917 		(void *)&cmd_config_l2_tunnel_eth_type_config,
12918 		(void *)&cmd_config_l2_tunnel_eth_type_all_str,
12919 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12920 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12921 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12922 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12923 		NULL,
12924 	},
12925 };
12926 
12927 /* ether type config for a specific port */
12928 static void
12929 cmd_config_l2_tunnel_eth_type_specific_parsed(
12930 	void *parsed_result,
12931 	__rte_unused struct cmdline *cl,
12932 	__rte_unused void *data)
12933 {
12934 	struct cmd_config_l2_tunnel_eth_type_result *res =
12935 		 parsed_result;
12936 	struct rte_eth_l2_tunnel_conf entry;
12937 
12938 	if (port_id_is_invalid(res->id, ENABLED_WARN))
12939 		return;
12940 
12941 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12942 	entry.ether_type = res->eth_type_val;
12943 
12944 	rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12945 }
12946 
12947 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12948 	.f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12949 	.data = NULL,
12950 	.help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12951 	.tokens = {
12952 		(void *)&cmd_config_l2_tunnel_eth_type_port,
12953 		(void *)&cmd_config_l2_tunnel_eth_type_config,
12954 		(void *)&cmd_config_l2_tunnel_eth_type_id,
12955 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12956 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12957 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12958 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12959 		NULL,
12960 	},
12961 };
12962 
12963 /* Enable/disable l2 tunnel */
12964 struct cmd_config_l2_tunnel_en_dis_result {
12965 	cmdline_fixed_string_t port;
12966 	cmdline_fixed_string_t config;
12967 	cmdline_fixed_string_t all;
12968 	portid_t id;
12969 	cmdline_fixed_string_t l2_tunnel;
12970 	cmdline_fixed_string_t l2_tunnel_type;
12971 	cmdline_fixed_string_t en_dis;
12972 };
12973 
12974 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12975 	TOKEN_STRING_INITIALIZER
12976 		(struct cmd_config_l2_tunnel_en_dis_result,
12977 		 port, "port");
12978 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12979 	TOKEN_STRING_INITIALIZER
12980 		(struct cmd_config_l2_tunnel_en_dis_result,
12981 		 config, "config");
12982 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12983 	TOKEN_STRING_INITIALIZER
12984 		(struct cmd_config_l2_tunnel_en_dis_result,
12985 		 all, "all");
12986 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12987 	TOKEN_NUM_INITIALIZER
12988 		(struct cmd_config_l2_tunnel_en_dis_result,
12989 		 id, UINT16);
12990 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12991 	TOKEN_STRING_INITIALIZER
12992 		(struct cmd_config_l2_tunnel_en_dis_result,
12993 		 l2_tunnel, "l2-tunnel");
12994 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12995 	TOKEN_STRING_INITIALIZER
12996 		(struct cmd_config_l2_tunnel_en_dis_result,
12997 		 l2_tunnel_type, "E-tag");
12998 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12999 	TOKEN_STRING_INITIALIZER
13000 		(struct cmd_config_l2_tunnel_en_dis_result,
13001 		 en_dis, "enable#disable");
13002 
13003 /* enable/disable l2 tunnel for all ports */
13004 static void
13005 cmd_config_l2_tunnel_en_dis_all_parsed(
13006 	void *parsed_result,
13007 	__rte_unused struct cmdline *cl,
13008 	__rte_unused void *data)
13009 {
13010 	struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
13011 	struct rte_eth_l2_tunnel_conf entry;
13012 	portid_t pid;
13013 	uint8_t en;
13014 
13015 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13016 
13017 	if (!strcmp("enable", res->en_dis))
13018 		en = 1;
13019 	else
13020 		en = 0;
13021 
13022 	RTE_ETH_FOREACH_DEV(pid) {
13023 		rte_eth_dev_l2_tunnel_offload_set(pid,
13024 						  &entry,
13025 						  ETH_L2_TUNNEL_ENABLE_MASK,
13026 						  en);
13027 	}
13028 }
13029 
13030 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
13031 	.f = cmd_config_l2_tunnel_en_dis_all_parsed,
13032 	.data = NULL,
13033 	.help_str = "port config all l2-tunnel E-tag enable|disable",
13034 	.tokens = {
13035 		(void *)&cmd_config_l2_tunnel_en_dis_port,
13036 		(void *)&cmd_config_l2_tunnel_en_dis_config,
13037 		(void *)&cmd_config_l2_tunnel_en_dis_all_str,
13038 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13039 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13040 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13041 		NULL,
13042 	},
13043 };
13044 
13045 /* enable/disable l2 tunnel for a port */
13046 static void
13047 cmd_config_l2_tunnel_en_dis_specific_parsed(
13048 	void *parsed_result,
13049 	__rte_unused struct cmdline *cl,
13050 	__rte_unused void *data)
13051 {
13052 	struct cmd_config_l2_tunnel_en_dis_result *res =
13053 		parsed_result;
13054 	struct rte_eth_l2_tunnel_conf entry;
13055 
13056 	if (port_id_is_invalid(res->id, ENABLED_WARN))
13057 		return;
13058 
13059 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13060 
13061 	if (!strcmp("enable", res->en_dis))
13062 		rte_eth_dev_l2_tunnel_offload_set(res->id,
13063 						  &entry,
13064 						  ETH_L2_TUNNEL_ENABLE_MASK,
13065 						  1);
13066 	else
13067 		rte_eth_dev_l2_tunnel_offload_set(res->id,
13068 						  &entry,
13069 						  ETH_L2_TUNNEL_ENABLE_MASK,
13070 						  0);
13071 }
13072 
13073 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13074 	.f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13075 	.data = NULL,
13076 	.help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13077 	.tokens = {
13078 		(void *)&cmd_config_l2_tunnel_en_dis_port,
13079 		(void *)&cmd_config_l2_tunnel_en_dis_config,
13080 		(void *)&cmd_config_l2_tunnel_en_dis_id,
13081 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13082 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13083 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13084 		NULL,
13085 	},
13086 };
13087 
13088 /* E-tag configuration */
13089 
13090 /* Common result structure for all E-tag configuration */
13091 struct cmd_config_e_tag_result {
13092 	cmdline_fixed_string_t e_tag;
13093 	cmdline_fixed_string_t set;
13094 	cmdline_fixed_string_t insertion;
13095 	cmdline_fixed_string_t stripping;
13096 	cmdline_fixed_string_t forwarding;
13097 	cmdline_fixed_string_t filter;
13098 	cmdline_fixed_string_t add;
13099 	cmdline_fixed_string_t del;
13100 	cmdline_fixed_string_t on;
13101 	cmdline_fixed_string_t off;
13102 	cmdline_fixed_string_t on_off;
13103 	cmdline_fixed_string_t port_tag_id;
13104 	uint32_t port_tag_id_val;
13105 	cmdline_fixed_string_t e_tag_id;
13106 	uint16_t e_tag_id_val;
13107 	cmdline_fixed_string_t dst_pool;
13108 	uint8_t dst_pool_val;
13109 	cmdline_fixed_string_t port;
13110 	portid_t port_id;
13111 	cmdline_fixed_string_t vf;
13112 	uint8_t vf_id;
13113 };
13114 
13115 /* Common CLI fields for all E-tag configuration */
13116 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13117 	TOKEN_STRING_INITIALIZER
13118 		(struct cmd_config_e_tag_result,
13119 		 e_tag, "E-tag");
13120 cmdline_parse_token_string_t cmd_config_e_tag_set =
13121 	TOKEN_STRING_INITIALIZER
13122 		(struct cmd_config_e_tag_result,
13123 		 set, "set");
13124 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13125 	TOKEN_STRING_INITIALIZER
13126 		(struct cmd_config_e_tag_result,
13127 		 insertion, "insertion");
13128 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13129 	TOKEN_STRING_INITIALIZER
13130 		(struct cmd_config_e_tag_result,
13131 		 stripping, "stripping");
13132 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13133 	TOKEN_STRING_INITIALIZER
13134 		(struct cmd_config_e_tag_result,
13135 		 forwarding, "forwarding");
13136 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13137 	TOKEN_STRING_INITIALIZER
13138 		(struct cmd_config_e_tag_result,
13139 		 filter, "filter");
13140 cmdline_parse_token_string_t cmd_config_e_tag_add =
13141 	TOKEN_STRING_INITIALIZER
13142 		(struct cmd_config_e_tag_result,
13143 		 add, "add");
13144 cmdline_parse_token_string_t cmd_config_e_tag_del =
13145 	TOKEN_STRING_INITIALIZER
13146 		(struct cmd_config_e_tag_result,
13147 		 del, "del");
13148 cmdline_parse_token_string_t cmd_config_e_tag_on =
13149 	TOKEN_STRING_INITIALIZER
13150 		(struct cmd_config_e_tag_result,
13151 		 on, "on");
13152 cmdline_parse_token_string_t cmd_config_e_tag_off =
13153 	TOKEN_STRING_INITIALIZER
13154 		(struct cmd_config_e_tag_result,
13155 		 off, "off");
13156 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13157 	TOKEN_STRING_INITIALIZER
13158 		(struct cmd_config_e_tag_result,
13159 		 on_off, "on#off");
13160 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13161 	TOKEN_STRING_INITIALIZER
13162 		(struct cmd_config_e_tag_result,
13163 		 port_tag_id, "port-tag-id");
13164 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13165 	TOKEN_NUM_INITIALIZER
13166 		(struct cmd_config_e_tag_result,
13167 		 port_tag_id_val, UINT32);
13168 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13169 	TOKEN_STRING_INITIALIZER
13170 		(struct cmd_config_e_tag_result,
13171 		 e_tag_id, "e-tag-id");
13172 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13173 	TOKEN_NUM_INITIALIZER
13174 		(struct cmd_config_e_tag_result,
13175 		 e_tag_id_val, UINT16);
13176 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13177 	TOKEN_STRING_INITIALIZER
13178 		(struct cmd_config_e_tag_result,
13179 		 dst_pool, "dst-pool");
13180 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13181 	TOKEN_NUM_INITIALIZER
13182 		(struct cmd_config_e_tag_result,
13183 		 dst_pool_val, UINT8);
13184 cmdline_parse_token_string_t cmd_config_e_tag_port =
13185 	TOKEN_STRING_INITIALIZER
13186 		(struct cmd_config_e_tag_result,
13187 		 port, "port");
13188 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13189 	TOKEN_NUM_INITIALIZER
13190 		(struct cmd_config_e_tag_result,
13191 		 port_id, UINT16);
13192 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13193 	TOKEN_STRING_INITIALIZER
13194 		(struct cmd_config_e_tag_result,
13195 		 vf, "vf");
13196 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13197 	TOKEN_NUM_INITIALIZER
13198 		(struct cmd_config_e_tag_result,
13199 		 vf_id, UINT8);
13200 
13201 /* E-tag insertion configuration */
13202 static void
13203 cmd_config_e_tag_insertion_en_parsed(
13204 	void *parsed_result,
13205 	__rte_unused struct cmdline *cl,
13206 	__rte_unused void *data)
13207 {
13208 	struct cmd_config_e_tag_result *res =
13209 		parsed_result;
13210 	struct rte_eth_l2_tunnel_conf entry;
13211 
13212 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13213 		return;
13214 
13215 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13216 	entry.tunnel_id = res->port_tag_id_val;
13217 	entry.vf_id = res->vf_id;
13218 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13219 					  &entry,
13220 					  ETH_L2_TUNNEL_INSERTION_MASK,
13221 					  1);
13222 }
13223 
13224 static void
13225 cmd_config_e_tag_insertion_dis_parsed(
13226 	void *parsed_result,
13227 	__rte_unused struct cmdline *cl,
13228 	__rte_unused void *data)
13229 {
13230 	struct cmd_config_e_tag_result *res =
13231 		parsed_result;
13232 	struct rte_eth_l2_tunnel_conf entry;
13233 
13234 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13235 		return;
13236 
13237 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13238 	entry.vf_id = res->vf_id;
13239 
13240 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13241 					  &entry,
13242 					  ETH_L2_TUNNEL_INSERTION_MASK,
13243 					  0);
13244 }
13245 
13246 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13247 	.f = cmd_config_e_tag_insertion_en_parsed,
13248 	.data = NULL,
13249 	.help_str = "E-tag ... : E-tag insertion enable",
13250 	.tokens = {
13251 		(void *)&cmd_config_e_tag_e_tag,
13252 		(void *)&cmd_config_e_tag_set,
13253 		(void *)&cmd_config_e_tag_insertion,
13254 		(void *)&cmd_config_e_tag_on,
13255 		(void *)&cmd_config_e_tag_port_tag_id,
13256 		(void *)&cmd_config_e_tag_port_tag_id_val,
13257 		(void *)&cmd_config_e_tag_port,
13258 		(void *)&cmd_config_e_tag_port_id,
13259 		(void *)&cmd_config_e_tag_vf,
13260 		(void *)&cmd_config_e_tag_vf_id,
13261 		NULL,
13262 	},
13263 };
13264 
13265 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13266 	.f = cmd_config_e_tag_insertion_dis_parsed,
13267 	.data = NULL,
13268 	.help_str = "E-tag ... : E-tag insertion disable",
13269 	.tokens = {
13270 		(void *)&cmd_config_e_tag_e_tag,
13271 		(void *)&cmd_config_e_tag_set,
13272 		(void *)&cmd_config_e_tag_insertion,
13273 		(void *)&cmd_config_e_tag_off,
13274 		(void *)&cmd_config_e_tag_port,
13275 		(void *)&cmd_config_e_tag_port_id,
13276 		(void *)&cmd_config_e_tag_vf,
13277 		(void *)&cmd_config_e_tag_vf_id,
13278 		NULL,
13279 	},
13280 };
13281 
13282 /* E-tag stripping configuration */
13283 static void
13284 cmd_config_e_tag_stripping_parsed(
13285 	void *parsed_result,
13286 	__rte_unused struct cmdline *cl,
13287 	__rte_unused void *data)
13288 {
13289 	struct cmd_config_e_tag_result *res =
13290 		parsed_result;
13291 	struct rte_eth_l2_tunnel_conf entry;
13292 
13293 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13294 		return;
13295 
13296 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13297 
13298 	if (!strcmp(res->on_off, "on"))
13299 		rte_eth_dev_l2_tunnel_offload_set
13300 			(res->port_id,
13301 			 &entry,
13302 			 ETH_L2_TUNNEL_STRIPPING_MASK,
13303 			 1);
13304 	else
13305 		rte_eth_dev_l2_tunnel_offload_set
13306 			(res->port_id,
13307 			 &entry,
13308 			 ETH_L2_TUNNEL_STRIPPING_MASK,
13309 			 0);
13310 }
13311 
13312 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13313 	.f = cmd_config_e_tag_stripping_parsed,
13314 	.data = NULL,
13315 	.help_str = "E-tag ... : E-tag stripping enable/disable",
13316 	.tokens = {
13317 		(void *)&cmd_config_e_tag_e_tag,
13318 		(void *)&cmd_config_e_tag_set,
13319 		(void *)&cmd_config_e_tag_stripping,
13320 		(void *)&cmd_config_e_tag_on_off,
13321 		(void *)&cmd_config_e_tag_port,
13322 		(void *)&cmd_config_e_tag_port_id,
13323 		NULL,
13324 	},
13325 };
13326 
13327 /* E-tag forwarding configuration */
13328 static void
13329 cmd_config_e_tag_forwarding_parsed(
13330 	void *parsed_result,
13331 	__rte_unused struct cmdline *cl,
13332 	__rte_unused void *data)
13333 {
13334 	struct cmd_config_e_tag_result *res = parsed_result;
13335 	struct rte_eth_l2_tunnel_conf entry;
13336 
13337 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13338 		return;
13339 
13340 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13341 
13342 	if (!strcmp(res->on_off, "on"))
13343 		rte_eth_dev_l2_tunnel_offload_set
13344 			(res->port_id,
13345 			 &entry,
13346 			 ETH_L2_TUNNEL_FORWARDING_MASK,
13347 			 1);
13348 	else
13349 		rte_eth_dev_l2_tunnel_offload_set
13350 			(res->port_id,
13351 			 &entry,
13352 			 ETH_L2_TUNNEL_FORWARDING_MASK,
13353 			 0);
13354 }
13355 
13356 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13357 	.f = cmd_config_e_tag_forwarding_parsed,
13358 	.data = NULL,
13359 	.help_str = "E-tag ... : E-tag forwarding enable/disable",
13360 	.tokens = {
13361 		(void *)&cmd_config_e_tag_e_tag,
13362 		(void *)&cmd_config_e_tag_set,
13363 		(void *)&cmd_config_e_tag_forwarding,
13364 		(void *)&cmd_config_e_tag_on_off,
13365 		(void *)&cmd_config_e_tag_port,
13366 		(void *)&cmd_config_e_tag_port_id,
13367 		NULL,
13368 	},
13369 };
13370 
13371 /* E-tag filter configuration */
13372 static void
13373 cmd_config_e_tag_filter_add_parsed(
13374 	void *parsed_result,
13375 	__rte_unused struct cmdline *cl,
13376 	__rte_unused void *data)
13377 {
13378 	struct cmd_config_e_tag_result *res = parsed_result;
13379 	struct rte_eth_l2_tunnel_conf entry;
13380 	int ret = 0;
13381 
13382 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13383 		return;
13384 
13385 	if (res->e_tag_id_val > 0x3fff) {
13386 		printf("e-tag-id must be equal or less than 0x3fff.\n");
13387 		return;
13388 	}
13389 
13390 	ret = rte_eth_dev_filter_supported(res->port_id,
13391 					   RTE_ETH_FILTER_L2_TUNNEL);
13392 	if (ret < 0) {
13393 		printf("E-tag filter is not supported on port %u.\n",
13394 		       res->port_id);
13395 		return;
13396 	}
13397 
13398 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13399 	entry.tunnel_id = res->e_tag_id_val;
13400 	entry.pool = res->dst_pool_val;
13401 
13402 	ret = rte_eth_dev_filter_ctrl(res->port_id,
13403 				      RTE_ETH_FILTER_L2_TUNNEL,
13404 				      RTE_ETH_FILTER_ADD,
13405 				      &entry);
13406 	if (ret < 0)
13407 		printf("E-tag filter programming error: (%s)\n",
13408 		       strerror(-ret));
13409 }
13410 
13411 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13412 	.f = cmd_config_e_tag_filter_add_parsed,
13413 	.data = NULL,
13414 	.help_str = "E-tag ... : E-tag filter add",
13415 	.tokens = {
13416 		(void *)&cmd_config_e_tag_e_tag,
13417 		(void *)&cmd_config_e_tag_set,
13418 		(void *)&cmd_config_e_tag_filter,
13419 		(void *)&cmd_config_e_tag_add,
13420 		(void *)&cmd_config_e_tag_e_tag_id,
13421 		(void *)&cmd_config_e_tag_e_tag_id_val,
13422 		(void *)&cmd_config_e_tag_dst_pool,
13423 		(void *)&cmd_config_e_tag_dst_pool_val,
13424 		(void *)&cmd_config_e_tag_port,
13425 		(void *)&cmd_config_e_tag_port_id,
13426 		NULL,
13427 	},
13428 };
13429 
13430 static void
13431 cmd_config_e_tag_filter_del_parsed(
13432 	void *parsed_result,
13433 	__rte_unused struct cmdline *cl,
13434 	__rte_unused void *data)
13435 {
13436 	struct cmd_config_e_tag_result *res = parsed_result;
13437 	struct rte_eth_l2_tunnel_conf entry;
13438 	int ret = 0;
13439 
13440 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13441 		return;
13442 
13443 	if (res->e_tag_id_val > 0x3fff) {
13444 		printf("e-tag-id must be less than 0x3fff.\n");
13445 		return;
13446 	}
13447 
13448 	ret = rte_eth_dev_filter_supported(res->port_id,
13449 					   RTE_ETH_FILTER_L2_TUNNEL);
13450 	if (ret < 0) {
13451 		printf("E-tag filter is not supported on port %u.\n",
13452 		       res->port_id);
13453 		return;
13454 	}
13455 
13456 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13457 	entry.tunnel_id = res->e_tag_id_val;
13458 
13459 	ret = rte_eth_dev_filter_ctrl(res->port_id,
13460 				      RTE_ETH_FILTER_L2_TUNNEL,
13461 				      RTE_ETH_FILTER_DELETE,
13462 				      &entry);
13463 	if (ret < 0)
13464 		printf("E-tag filter programming error: (%s)\n",
13465 		       strerror(-ret));
13466 }
13467 
13468 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13469 	.f = cmd_config_e_tag_filter_del_parsed,
13470 	.data = NULL,
13471 	.help_str = "E-tag ... : E-tag filter delete",
13472 	.tokens = {
13473 		(void *)&cmd_config_e_tag_e_tag,
13474 		(void *)&cmd_config_e_tag_set,
13475 		(void *)&cmd_config_e_tag_filter,
13476 		(void *)&cmd_config_e_tag_del,
13477 		(void *)&cmd_config_e_tag_e_tag_id,
13478 		(void *)&cmd_config_e_tag_e_tag_id_val,
13479 		(void *)&cmd_config_e_tag_port,
13480 		(void *)&cmd_config_e_tag_port_id,
13481 		NULL,
13482 	},
13483 };
13484 
13485 /* vf vlan anti spoof configuration */
13486 
13487 /* Common result structure for vf vlan anti spoof */
13488 struct cmd_vf_vlan_anti_spoof_result {
13489 	cmdline_fixed_string_t set;
13490 	cmdline_fixed_string_t vf;
13491 	cmdline_fixed_string_t vlan;
13492 	cmdline_fixed_string_t antispoof;
13493 	portid_t port_id;
13494 	uint32_t vf_id;
13495 	cmdline_fixed_string_t on_off;
13496 };
13497 
13498 /* Common CLI fields for vf vlan anti spoof enable disable */
13499 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13500 	TOKEN_STRING_INITIALIZER
13501 		(struct cmd_vf_vlan_anti_spoof_result,
13502 		 set, "set");
13503 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13504 	TOKEN_STRING_INITIALIZER
13505 		(struct cmd_vf_vlan_anti_spoof_result,
13506 		 vf, "vf");
13507 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13508 	TOKEN_STRING_INITIALIZER
13509 		(struct cmd_vf_vlan_anti_spoof_result,
13510 		 vlan, "vlan");
13511 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13512 	TOKEN_STRING_INITIALIZER
13513 		(struct cmd_vf_vlan_anti_spoof_result,
13514 		 antispoof, "antispoof");
13515 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13516 	TOKEN_NUM_INITIALIZER
13517 		(struct cmd_vf_vlan_anti_spoof_result,
13518 		 port_id, UINT16);
13519 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13520 	TOKEN_NUM_INITIALIZER
13521 		(struct cmd_vf_vlan_anti_spoof_result,
13522 		 vf_id, UINT32);
13523 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13524 	TOKEN_STRING_INITIALIZER
13525 		(struct cmd_vf_vlan_anti_spoof_result,
13526 		 on_off, "on#off");
13527 
13528 static void
13529 cmd_set_vf_vlan_anti_spoof_parsed(
13530 	void *parsed_result,
13531 	__rte_unused struct cmdline *cl,
13532 	__rte_unused void *data)
13533 {
13534 	struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13535 	int ret = -ENOTSUP;
13536 
13537 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13538 
13539 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13540 		return;
13541 
13542 #ifdef RTE_LIBRTE_IXGBE_PMD
13543 	if (ret == -ENOTSUP)
13544 		ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13545 				res->vf_id, is_on);
13546 #endif
13547 #ifdef RTE_LIBRTE_I40E_PMD
13548 	if (ret == -ENOTSUP)
13549 		ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13550 				res->vf_id, is_on);
13551 #endif
13552 #ifdef RTE_LIBRTE_BNXT_PMD
13553 	if (ret == -ENOTSUP)
13554 		ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13555 				res->vf_id, is_on);
13556 #endif
13557 
13558 	switch (ret) {
13559 	case 0:
13560 		break;
13561 	case -EINVAL:
13562 		printf("invalid vf_id %d\n", res->vf_id);
13563 		break;
13564 	case -ENODEV:
13565 		printf("invalid port_id %d\n", res->port_id);
13566 		break;
13567 	case -ENOTSUP:
13568 		printf("function not implemented\n");
13569 		break;
13570 	default:
13571 		printf("programming error: (%s)\n", strerror(-ret));
13572 	}
13573 }
13574 
13575 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13576 	.f = cmd_set_vf_vlan_anti_spoof_parsed,
13577 	.data = NULL,
13578 	.help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13579 	.tokens = {
13580 		(void *)&cmd_vf_vlan_anti_spoof_set,
13581 		(void *)&cmd_vf_vlan_anti_spoof_vf,
13582 		(void *)&cmd_vf_vlan_anti_spoof_vlan,
13583 		(void *)&cmd_vf_vlan_anti_spoof_antispoof,
13584 		(void *)&cmd_vf_vlan_anti_spoof_port_id,
13585 		(void *)&cmd_vf_vlan_anti_spoof_vf_id,
13586 		(void *)&cmd_vf_vlan_anti_spoof_on_off,
13587 		NULL,
13588 	},
13589 };
13590 
13591 /* vf mac anti spoof configuration */
13592 
13593 /* Common result structure for vf mac anti spoof */
13594 struct cmd_vf_mac_anti_spoof_result {
13595 	cmdline_fixed_string_t set;
13596 	cmdline_fixed_string_t vf;
13597 	cmdline_fixed_string_t mac;
13598 	cmdline_fixed_string_t antispoof;
13599 	portid_t port_id;
13600 	uint32_t vf_id;
13601 	cmdline_fixed_string_t on_off;
13602 };
13603 
13604 /* Common CLI fields for vf mac anti spoof enable disable */
13605 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13606 	TOKEN_STRING_INITIALIZER
13607 		(struct cmd_vf_mac_anti_spoof_result,
13608 		 set, "set");
13609 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13610 	TOKEN_STRING_INITIALIZER
13611 		(struct cmd_vf_mac_anti_spoof_result,
13612 		 vf, "vf");
13613 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13614 	TOKEN_STRING_INITIALIZER
13615 		(struct cmd_vf_mac_anti_spoof_result,
13616 		 mac, "mac");
13617 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13618 	TOKEN_STRING_INITIALIZER
13619 		(struct cmd_vf_mac_anti_spoof_result,
13620 		 antispoof, "antispoof");
13621 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13622 	TOKEN_NUM_INITIALIZER
13623 		(struct cmd_vf_mac_anti_spoof_result,
13624 		 port_id, UINT16);
13625 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13626 	TOKEN_NUM_INITIALIZER
13627 		(struct cmd_vf_mac_anti_spoof_result,
13628 		 vf_id, UINT32);
13629 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13630 	TOKEN_STRING_INITIALIZER
13631 		(struct cmd_vf_mac_anti_spoof_result,
13632 		 on_off, "on#off");
13633 
13634 static void
13635 cmd_set_vf_mac_anti_spoof_parsed(
13636 	void *parsed_result,
13637 	__rte_unused struct cmdline *cl,
13638 	__rte_unused void *data)
13639 {
13640 	struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13641 	int ret = -ENOTSUP;
13642 
13643 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13644 
13645 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13646 		return;
13647 
13648 #ifdef RTE_LIBRTE_IXGBE_PMD
13649 	if (ret == -ENOTSUP)
13650 		ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13651 			res->vf_id, is_on);
13652 #endif
13653 #ifdef RTE_LIBRTE_I40E_PMD
13654 	if (ret == -ENOTSUP)
13655 		ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13656 			res->vf_id, is_on);
13657 #endif
13658 #ifdef RTE_LIBRTE_BNXT_PMD
13659 	if (ret == -ENOTSUP)
13660 		ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13661 			res->vf_id, is_on);
13662 #endif
13663 
13664 	switch (ret) {
13665 	case 0:
13666 		break;
13667 	case -EINVAL:
13668 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13669 		break;
13670 	case -ENODEV:
13671 		printf("invalid port_id %d\n", res->port_id);
13672 		break;
13673 	case -ENOTSUP:
13674 		printf("function not implemented\n");
13675 		break;
13676 	default:
13677 		printf("programming error: (%s)\n", strerror(-ret));
13678 	}
13679 }
13680 
13681 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13682 	.f = cmd_set_vf_mac_anti_spoof_parsed,
13683 	.data = NULL,
13684 	.help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13685 	.tokens = {
13686 		(void *)&cmd_vf_mac_anti_spoof_set,
13687 		(void *)&cmd_vf_mac_anti_spoof_vf,
13688 		(void *)&cmd_vf_mac_anti_spoof_mac,
13689 		(void *)&cmd_vf_mac_anti_spoof_antispoof,
13690 		(void *)&cmd_vf_mac_anti_spoof_port_id,
13691 		(void *)&cmd_vf_mac_anti_spoof_vf_id,
13692 		(void *)&cmd_vf_mac_anti_spoof_on_off,
13693 		NULL,
13694 	},
13695 };
13696 
13697 /* vf vlan strip queue configuration */
13698 
13699 /* Common result structure for vf mac anti spoof */
13700 struct cmd_vf_vlan_stripq_result {
13701 	cmdline_fixed_string_t set;
13702 	cmdline_fixed_string_t vf;
13703 	cmdline_fixed_string_t vlan;
13704 	cmdline_fixed_string_t stripq;
13705 	portid_t port_id;
13706 	uint16_t vf_id;
13707 	cmdline_fixed_string_t on_off;
13708 };
13709 
13710 /* Common CLI fields for vf vlan strip enable disable */
13711 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13712 	TOKEN_STRING_INITIALIZER
13713 		(struct cmd_vf_vlan_stripq_result,
13714 		 set, "set");
13715 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13716 	TOKEN_STRING_INITIALIZER
13717 		(struct cmd_vf_vlan_stripq_result,
13718 		 vf, "vf");
13719 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13720 	TOKEN_STRING_INITIALIZER
13721 		(struct cmd_vf_vlan_stripq_result,
13722 		 vlan, "vlan");
13723 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13724 	TOKEN_STRING_INITIALIZER
13725 		(struct cmd_vf_vlan_stripq_result,
13726 		 stripq, "stripq");
13727 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13728 	TOKEN_NUM_INITIALIZER
13729 		(struct cmd_vf_vlan_stripq_result,
13730 		 port_id, UINT16);
13731 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13732 	TOKEN_NUM_INITIALIZER
13733 		(struct cmd_vf_vlan_stripq_result,
13734 		 vf_id, UINT16);
13735 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13736 	TOKEN_STRING_INITIALIZER
13737 		(struct cmd_vf_vlan_stripq_result,
13738 		 on_off, "on#off");
13739 
13740 static void
13741 cmd_set_vf_vlan_stripq_parsed(
13742 	void *parsed_result,
13743 	__rte_unused struct cmdline *cl,
13744 	__rte_unused void *data)
13745 {
13746 	struct cmd_vf_vlan_stripq_result *res = parsed_result;
13747 	int ret = -ENOTSUP;
13748 
13749 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13750 
13751 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13752 		return;
13753 
13754 #ifdef RTE_LIBRTE_IXGBE_PMD
13755 	if (ret == -ENOTSUP)
13756 		ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13757 			res->vf_id, is_on);
13758 #endif
13759 #ifdef RTE_LIBRTE_I40E_PMD
13760 	if (ret == -ENOTSUP)
13761 		ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13762 			res->vf_id, is_on);
13763 #endif
13764 #ifdef RTE_LIBRTE_BNXT_PMD
13765 	if (ret == -ENOTSUP)
13766 		ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13767 			res->vf_id, is_on);
13768 #endif
13769 
13770 	switch (ret) {
13771 	case 0:
13772 		break;
13773 	case -EINVAL:
13774 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13775 		break;
13776 	case -ENODEV:
13777 		printf("invalid port_id %d\n", res->port_id);
13778 		break;
13779 	case -ENOTSUP:
13780 		printf("function not implemented\n");
13781 		break;
13782 	default:
13783 		printf("programming error: (%s)\n", strerror(-ret));
13784 	}
13785 }
13786 
13787 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13788 	.f = cmd_set_vf_vlan_stripq_parsed,
13789 	.data = NULL,
13790 	.help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13791 	.tokens = {
13792 		(void *)&cmd_vf_vlan_stripq_set,
13793 		(void *)&cmd_vf_vlan_stripq_vf,
13794 		(void *)&cmd_vf_vlan_stripq_vlan,
13795 		(void *)&cmd_vf_vlan_stripq_stripq,
13796 		(void *)&cmd_vf_vlan_stripq_port_id,
13797 		(void *)&cmd_vf_vlan_stripq_vf_id,
13798 		(void *)&cmd_vf_vlan_stripq_on_off,
13799 		NULL,
13800 	},
13801 };
13802 
13803 /* vf vlan insert configuration */
13804 
13805 /* Common result structure for vf vlan insert */
13806 struct cmd_vf_vlan_insert_result {
13807 	cmdline_fixed_string_t set;
13808 	cmdline_fixed_string_t vf;
13809 	cmdline_fixed_string_t vlan;
13810 	cmdline_fixed_string_t insert;
13811 	portid_t port_id;
13812 	uint16_t vf_id;
13813 	uint16_t vlan_id;
13814 };
13815 
13816 /* Common CLI fields for vf vlan insert enable disable */
13817 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13818 	TOKEN_STRING_INITIALIZER
13819 		(struct cmd_vf_vlan_insert_result,
13820 		 set, "set");
13821 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13822 	TOKEN_STRING_INITIALIZER
13823 		(struct cmd_vf_vlan_insert_result,
13824 		 vf, "vf");
13825 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13826 	TOKEN_STRING_INITIALIZER
13827 		(struct cmd_vf_vlan_insert_result,
13828 		 vlan, "vlan");
13829 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13830 	TOKEN_STRING_INITIALIZER
13831 		(struct cmd_vf_vlan_insert_result,
13832 		 insert, "insert");
13833 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13834 	TOKEN_NUM_INITIALIZER
13835 		(struct cmd_vf_vlan_insert_result,
13836 		 port_id, UINT16);
13837 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13838 	TOKEN_NUM_INITIALIZER
13839 		(struct cmd_vf_vlan_insert_result,
13840 		 vf_id, UINT16);
13841 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13842 	TOKEN_NUM_INITIALIZER
13843 		(struct cmd_vf_vlan_insert_result,
13844 		 vlan_id, UINT16);
13845 
13846 static void
13847 cmd_set_vf_vlan_insert_parsed(
13848 	void *parsed_result,
13849 	__rte_unused struct cmdline *cl,
13850 	__rte_unused void *data)
13851 {
13852 	struct cmd_vf_vlan_insert_result *res = parsed_result;
13853 	int ret = -ENOTSUP;
13854 
13855 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13856 		return;
13857 
13858 #ifdef RTE_LIBRTE_IXGBE_PMD
13859 	if (ret == -ENOTSUP)
13860 		ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13861 			res->vlan_id);
13862 #endif
13863 #ifdef RTE_LIBRTE_I40E_PMD
13864 	if (ret == -ENOTSUP)
13865 		ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13866 			res->vlan_id);
13867 #endif
13868 #ifdef RTE_LIBRTE_BNXT_PMD
13869 	if (ret == -ENOTSUP)
13870 		ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13871 			res->vlan_id);
13872 #endif
13873 
13874 	switch (ret) {
13875 	case 0:
13876 		break;
13877 	case -EINVAL:
13878 		printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13879 		break;
13880 	case -ENODEV:
13881 		printf("invalid port_id %d\n", res->port_id);
13882 		break;
13883 	case -ENOTSUP:
13884 		printf("function not implemented\n");
13885 		break;
13886 	default:
13887 		printf("programming error: (%s)\n", strerror(-ret));
13888 	}
13889 }
13890 
13891 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13892 	.f = cmd_set_vf_vlan_insert_parsed,
13893 	.data = NULL,
13894 	.help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13895 	.tokens = {
13896 		(void *)&cmd_vf_vlan_insert_set,
13897 		(void *)&cmd_vf_vlan_insert_vf,
13898 		(void *)&cmd_vf_vlan_insert_vlan,
13899 		(void *)&cmd_vf_vlan_insert_insert,
13900 		(void *)&cmd_vf_vlan_insert_port_id,
13901 		(void *)&cmd_vf_vlan_insert_vf_id,
13902 		(void *)&cmd_vf_vlan_insert_vlan_id,
13903 		NULL,
13904 	},
13905 };
13906 
13907 /* tx loopback configuration */
13908 
13909 /* Common result structure for tx loopback */
13910 struct cmd_tx_loopback_result {
13911 	cmdline_fixed_string_t set;
13912 	cmdline_fixed_string_t tx;
13913 	cmdline_fixed_string_t loopback;
13914 	portid_t port_id;
13915 	cmdline_fixed_string_t on_off;
13916 };
13917 
13918 /* Common CLI fields for tx loopback enable disable */
13919 cmdline_parse_token_string_t cmd_tx_loopback_set =
13920 	TOKEN_STRING_INITIALIZER
13921 		(struct cmd_tx_loopback_result,
13922 		 set, "set");
13923 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13924 	TOKEN_STRING_INITIALIZER
13925 		(struct cmd_tx_loopback_result,
13926 		 tx, "tx");
13927 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13928 	TOKEN_STRING_INITIALIZER
13929 		(struct cmd_tx_loopback_result,
13930 		 loopback, "loopback");
13931 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13932 	TOKEN_NUM_INITIALIZER
13933 		(struct cmd_tx_loopback_result,
13934 		 port_id, UINT16);
13935 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13936 	TOKEN_STRING_INITIALIZER
13937 		(struct cmd_tx_loopback_result,
13938 		 on_off, "on#off");
13939 
13940 static void
13941 cmd_set_tx_loopback_parsed(
13942 	void *parsed_result,
13943 	__rte_unused struct cmdline *cl,
13944 	__rte_unused void *data)
13945 {
13946 	struct cmd_tx_loopback_result *res = parsed_result;
13947 	int ret = -ENOTSUP;
13948 
13949 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13950 
13951 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13952 		return;
13953 
13954 #ifdef RTE_LIBRTE_IXGBE_PMD
13955 	if (ret == -ENOTSUP)
13956 		ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13957 #endif
13958 #ifdef RTE_LIBRTE_I40E_PMD
13959 	if (ret == -ENOTSUP)
13960 		ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13961 #endif
13962 #ifdef RTE_LIBRTE_BNXT_PMD
13963 	if (ret == -ENOTSUP)
13964 		ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13965 #endif
13966 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13967 	if (ret == -ENOTSUP)
13968 		ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13969 #endif
13970 
13971 	switch (ret) {
13972 	case 0:
13973 		break;
13974 	case -EINVAL:
13975 		printf("invalid is_on %d\n", is_on);
13976 		break;
13977 	case -ENODEV:
13978 		printf("invalid port_id %d\n", res->port_id);
13979 		break;
13980 	case -ENOTSUP:
13981 		printf("function not implemented\n");
13982 		break;
13983 	default:
13984 		printf("programming error: (%s)\n", strerror(-ret));
13985 	}
13986 }
13987 
13988 cmdline_parse_inst_t cmd_set_tx_loopback = {
13989 	.f = cmd_set_tx_loopback_parsed,
13990 	.data = NULL,
13991 	.help_str = "set tx loopback <port_id> on|off",
13992 	.tokens = {
13993 		(void *)&cmd_tx_loopback_set,
13994 		(void *)&cmd_tx_loopback_tx,
13995 		(void *)&cmd_tx_loopback_loopback,
13996 		(void *)&cmd_tx_loopback_port_id,
13997 		(void *)&cmd_tx_loopback_on_off,
13998 		NULL,
13999 	},
14000 };
14001 
14002 /* all queues drop enable configuration */
14003 
14004 /* Common result structure for all queues drop enable */
14005 struct cmd_all_queues_drop_en_result {
14006 	cmdline_fixed_string_t set;
14007 	cmdline_fixed_string_t all;
14008 	cmdline_fixed_string_t queues;
14009 	cmdline_fixed_string_t drop;
14010 	portid_t port_id;
14011 	cmdline_fixed_string_t on_off;
14012 };
14013 
14014 /* Common CLI fields for tx loopback enable disable */
14015 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
14016 	TOKEN_STRING_INITIALIZER
14017 		(struct cmd_all_queues_drop_en_result,
14018 		 set, "set");
14019 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
14020 	TOKEN_STRING_INITIALIZER
14021 		(struct cmd_all_queues_drop_en_result,
14022 		 all, "all");
14023 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
14024 	TOKEN_STRING_INITIALIZER
14025 		(struct cmd_all_queues_drop_en_result,
14026 		 queues, "queues");
14027 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
14028 	TOKEN_STRING_INITIALIZER
14029 		(struct cmd_all_queues_drop_en_result,
14030 		 drop, "drop");
14031 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
14032 	TOKEN_NUM_INITIALIZER
14033 		(struct cmd_all_queues_drop_en_result,
14034 		 port_id, UINT16);
14035 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
14036 	TOKEN_STRING_INITIALIZER
14037 		(struct cmd_all_queues_drop_en_result,
14038 		 on_off, "on#off");
14039 
14040 static void
14041 cmd_set_all_queues_drop_en_parsed(
14042 	void *parsed_result,
14043 	__rte_unused struct cmdline *cl,
14044 	__rte_unused void *data)
14045 {
14046 	struct cmd_all_queues_drop_en_result *res = parsed_result;
14047 	int ret = -ENOTSUP;
14048 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14049 
14050 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14051 		return;
14052 
14053 #ifdef RTE_LIBRTE_IXGBE_PMD
14054 	if (ret == -ENOTSUP)
14055 		ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
14056 #endif
14057 #ifdef RTE_LIBRTE_BNXT_PMD
14058 	if (ret == -ENOTSUP)
14059 		ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
14060 #endif
14061 	switch (ret) {
14062 	case 0:
14063 		break;
14064 	case -EINVAL:
14065 		printf("invalid is_on %d\n", is_on);
14066 		break;
14067 	case -ENODEV:
14068 		printf("invalid port_id %d\n", res->port_id);
14069 		break;
14070 	case -ENOTSUP:
14071 		printf("function not implemented\n");
14072 		break;
14073 	default:
14074 		printf("programming error: (%s)\n", strerror(-ret));
14075 	}
14076 }
14077 
14078 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14079 	.f = cmd_set_all_queues_drop_en_parsed,
14080 	.data = NULL,
14081 	.help_str = "set all queues drop <port_id> on|off",
14082 	.tokens = {
14083 		(void *)&cmd_all_queues_drop_en_set,
14084 		(void *)&cmd_all_queues_drop_en_all,
14085 		(void *)&cmd_all_queues_drop_en_queues,
14086 		(void *)&cmd_all_queues_drop_en_drop,
14087 		(void *)&cmd_all_queues_drop_en_port_id,
14088 		(void *)&cmd_all_queues_drop_en_on_off,
14089 		NULL,
14090 	},
14091 };
14092 
14093 /* vf split drop enable configuration */
14094 
14095 /* Common result structure for vf split drop enable */
14096 struct cmd_vf_split_drop_en_result {
14097 	cmdline_fixed_string_t set;
14098 	cmdline_fixed_string_t vf;
14099 	cmdline_fixed_string_t split;
14100 	cmdline_fixed_string_t drop;
14101 	portid_t port_id;
14102 	uint16_t vf_id;
14103 	cmdline_fixed_string_t on_off;
14104 };
14105 
14106 /* Common CLI fields for vf split drop enable disable */
14107 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14108 	TOKEN_STRING_INITIALIZER
14109 		(struct cmd_vf_split_drop_en_result,
14110 		 set, "set");
14111 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14112 	TOKEN_STRING_INITIALIZER
14113 		(struct cmd_vf_split_drop_en_result,
14114 		 vf, "vf");
14115 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14116 	TOKEN_STRING_INITIALIZER
14117 		(struct cmd_vf_split_drop_en_result,
14118 		 split, "split");
14119 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14120 	TOKEN_STRING_INITIALIZER
14121 		(struct cmd_vf_split_drop_en_result,
14122 		 drop, "drop");
14123 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14124 	TOKEN_NUM_INITIALIZER
14125 		(struct cmd_vf_split_drop_en_result,
14126 		 port_id, UINT16);
14127 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14128 	TOKEN_NUM_INITIALIZER
14129 		(struct cmd_vf_split_drop_en_result,
14130 		 vf_id, UINT16);
14131 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14132 	TOKEN_STRING_INITIALIZER
14133 		(struct cmd_vf_split_drop_en_result,
14134 		 on_off, "on#off");
14135 
14136 static void
14137 cmd_set_vf_split_drop_en_parsed(
14138 	void *parsed_result,
14139 	__rte_unused struct cmdline *cl,
14140 	__rte_unused void *data)
14141 {
14142 	struct cmd_vf_split_drop_en_result *res = parsed_result;
14143 	int ret = -ENOTSUP;
14144 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14145 
14146 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14147 		return;
14148 
14149 #ifdef RTE_LIBRTE_IXGBE_PMD
14150 	ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14151 			is_on);
14152 #endif
14153 	switch (ret) {
14154 	case 0:
14155 		break;
14156 	case -EINVAL:
14157 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14158 		break;
14159 	case -ENODEV:
14160 		printf("invalid port_id %d\n", res->port_id);
14161 		break;
14162 	case -ENOTSUP:
14163 		printf("not supported on port %d\n", res->port_id);
14164 		break;
14165 	default:
14166 		printf("programming error: (%s)\n", strerror(-ret));
14167 	}
14168 }
14169 
14170 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14171 	.f = cmd_set_vf_split_drop_en_parsed,
14172 	.data = NULL,
14173 	.help_str = "set vf split drop <port_id> <vf_id> on|off",
14174 	.tokens = {
14175 		(void *)&cmd_vf_split_drop_en_set,
14176 		(void *)&cmd_vf_split_drop_en_vf,
14177 		(void *)&cmd_vf_split_drop_en_split,
14178 		(void *)&cmd_vf_split_drop_en_drop,
14179 		(void *)&cmd_vf_split_drop_en_port_id,
14180 		(void *)&cmd_vf_split_drop_en_vf_id,
14181 		(void *)&cmd_vf_split_drop_en_on_off,
14182 		NULL,
14183 	},
14184 };
14185 
14186 /* vf mac address configuration */
14187 
14188 /* Common result structure for vf mac address */
14189 struct cmd_set_vf_mac_addr_result {
14190 	cmdline_fixed_string_t set;
14191 	cmdline_fixed_string_t vf;
14192 	cmdline_fixed_string_t mac;
14193 	cmdline_fixed_string_t addr;
14194 	portid_t port_id;
14195 	uint16_t vf_id;
14196 	struct rte_ether_addr mac_addr;
14197 
14198 };
14199 
14200 /* Common CLI fields for vf split drop enable disable */
14201 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14202 	TOKEN_STRING_INITIALIZER
14203 		(struct cmd_set_vf_mac_addr_result,
14204 		 set, "set");
14205 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14206 	TOKEN_STRING_INITIALIZER
14207 		(struct cmd_set_vf_mac_addr_result,
14208 		 vf, "vf");
14209 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14210 	TOKEN_STRING_INITIALIZER
14211 		(struct cmd_set_vf_mac_addr_result,
14212 		 mac, "mac");
14213 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14214 	TOKEN_STRING_INITIALIZER
14215 		(struct cmd_set_vf_mac_addr_result,
14216 		 addr, "addr");
14217 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14218 	TOKEN_NUM_INITIALIZER
14219 		(struct cmd_set_vf_mac_addr_result,
14220 		 port_id, UINT16);
14221 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14222 	TOKEN_NUM_INITIALIZER
14223 		(struct cmd_set_vf_mac_addr_result,
14224 		 vf_id, UINT16);
14225 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14226 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14227 		 mac_addr);
14228 
14229 static void
14230 cmd_set_vf_mac_addr_parsed(
14231 	void *parsed_result,
14232 	__rte_unused struct cmdline *cl,
14233 	__rte_unused void *data)
14234 {
14235 	struct cmd_set_vf_mac_addr_result *res = parsed_result;
14236 	int ret = -ENOTSUP;
14237 
14238 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14239 		return;
14240 
14241 #ifdef RTE_LIBRTE_IXGBE_PMD
14242 	if (ret == -ENOTSUP)
14243 		ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14244 				&res->mac_addr);
14245 #endif
14246 #ifdef RTE_LIBRTE_I40E_PMD
14247 	if (ret == -ENOTSUP)
14248 		ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14249 				&res->mac_addr);
14250 #endif
14251 #ifdef RTE_LIBRTE_BNXT_PMD
14252 	if (ret == -ENOTSUP)
14253 		ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14254 				&res->mac_addr);
14255 #endif
14256 
14257 	switch (ret) {
14258 	case 0:
14259 		break;
14260 	case -EINVAL:
14261 		printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14262 		break;
14263 	case -ENODEV:
14264 		printf("invalid port_id %d\n", res->port_id);
14265 		break;
14266 	case -ENOTSUP:
14267 		printf("function not implemented\n");
14268 		break;
14269 	default:
14270 		printf("programming error: (%s)\n", strerror(-ret));
14271 	}
14272 }
14273 
14274 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14275 	.f = cmd_set_vf_mac_addr_parsed,
14276 	.data = NULL,
14277 	.help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14278 	.tokens = {
14279 		(void *)&cmd_set_vf_mac_addr_set,
14280 		(void *)&cmd_set_vf_mac_addr_vf,
14281 		(void *)&cmd_set_vf_mac_addr_mac,
14282 		(void *)&cmd_set_vf_mac_addr_addr,
14283 		(void *)&cmd_set_vf_mac_addr_port_id,
14284 		(void *)&cmd_set_vf_mac_addr_vf_id,
14285 		(void *)&cmd_set_vf_mac_addr_mac_addr,
14286 		NULL,
14287 	},
14288 };
14289 
14290 /* MACsec configuration */
14291 
14292 /* Common result structure for MACsec offload enable */
14293 struct cmd_macsec_offload_on_result {
14294 	cmdline_fixed_string_t set;
14295 	cmdline_fixed_string_t macsec;
14296 	cmdline_fixed_string_t offload;
14297 	portid_t port_id;
14298 	cmdline_fixed_string_t on;
14299 	cmdline_fixed_string_t encrypt;
14300 	cmdline_fixed_string_t en_on_off;
14301 	cmdline_fixed_string_t replay_protect;
14302 	cmdline_fixed_string_t rp_on_off;
14303 };
14304 
14305 /* Common CLI fields for MACsec offload disable */
14306 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14307 	TOKEN_STRING_INITIALIZER
14308 		(struct cmd_macsec_offload_on_result,
14309 		 set, "set");
14310 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14311 	TOKEN_STRING_INITIALIZER
14312 		(struct cmd_macsec_offload_on_result,
14313 		 macsec, "macsec");
14314 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14315 	TOKEN_STRING_INITIALIZER
14316 		(struct cmd_macsec_offload_on_result,
14317 		 offload, "offload");
14318 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14319 	TOKEN_NUM_INITIALIZER
14320 		(struct cmd_macsec_offload_on_result,
14321 		 port_id, UINT16);
14322 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14323 	TOKEN_STRING_INITIALIZER
14324 		(struct cmd_macsec_offload_on_result,
14325 		 on, "on");
14326 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14327 	TOKEN_STRING_INITIALIZER
14328 		(struct cmd_macsec_offload_on_result,
14329 		 encrypt, "encrypt");
14330 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14331 	TOKEN_STRING_INITIALIZER
14332 		(struct cmd_macsec_offload_on_result,
14333 		 en_on_off, "on#off");
14334 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14335 	TOKEN_STRING_INITIALIZER
14336 		(struct cmd_macsec_offload_on_result,
14337 		 replay_protect, "replay-protect");
14338 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14339 	TOKEN_STRING_INITIALIZER
14340 		(struct cmd_macsec_offload_on_result,
14341 		 rp_on_off, "on#off");
14342 
14343 static void
14344 cmd_set_macsec_offload_on_parsed(
14345 	void *parsed_result,
14346 	__rte_unused struct cmdline *cl,
14347 	__rte_unused void *data)
14348 {
14349 	struct cmd_macsec_offload_on_result *res = parsed_result;
14350 	int ret = -ENOTSUP;
14351 	portid_t port_id = res->port_id;
14352 	int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14353 	int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14354 	struct rte_eth_dev_info dev_info;
14355 
14356 	if (port_id_is_invalid(port_id, ENABLED_WARN))
14357 		return;
14358 	if (!port_is_stopped(port_id)) {
14359 		printf("Please stop port %d first\n", port_id);
14360 		return;
14361 	}
14362 
14363 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
14364 	if (ret != 0)
14365 		return;
14366 
14367 	if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14368 #ifdef RTE_LIBRTE_IXGBE_PMD
14369 		ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14370 #endif
14371 	}
14372 	RTE_SET_USED(en);
14373 	RTE_SET_USED(rp);
14374 
14375 	switch (ret) {
14376 	case 0:
14377 		ports[port_id].dev_conf.txmode.offloads |=
14378 						DEV_TX_OFFLOAD_MACSEC_INSERT;
14379 		cmd_reconfig_device_queue(port_id, 1, 1);
14380 		break;
14381 	case -ENODEV:
14382 		printf("invalid port_id %d\n", port_id);
14383 		break;
14384 	case -ENOTSUP:
14385 		printf("not supported on port %d\n", port_id);
14386 		break;
14387 	default:
14388 		printf("programming error: (%s)\n", strerror(-ret));
14389 	}
14390 }
14391 
14392 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14393 	.f = cmd_set_macsec_offload_on_parsed,
14394 	.data = NULL,
14395 	.help_str = "set macsec offload <port_id> on "
14396 		"encrypt on|off replay-protect on|off",
14397 	.tokens = {
14398 		(void *)&cmd_macsec_offload_on_set,
14399 		(void *)&cmd_macsec_offload_on_macsec,
14400 		(void *)&cmd_macsec_offload_on_offload,
14401 		(void *)&cmd_macsec_offload_on_port_id,
14402 		(void *)&cmd_macsec_offload_on_on,
14403 		(void *)&cmd_macsec_offload_on_encrypt,
14404 		(void *)&cmd_macsec_offload_on_en_on_off,
14405 		(void *)&cmd_macsec_offload_on_replay_protect,
14406 		(void *)&cmd_macsec_offload_on_rp_on_off,
14407 		NULL,
14408 	},
14409 };
14410 
14411 /* Common result structure for MACsec offload disable */
14412 struct cmd_macsec_offload_off_result {
14413 	cmdline_fixed_string_t set;
14414 	cmdline_fixed_string_t macsec;
14415 	cmdline_fixed_string_t offload;
14416 	portid_t port_id;
14417 	cmdline_fixed_string_t off;
14418 };
14419 
14420 /* Common CLI fields for MACsec offload disable */
14421 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14422 	TOKEN_STRING_INITIALIZER
14423 		(struct cmd_macsec_offload_off_result,
14424 		 set, "set");
14425 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14426 	TOKEN_STRING_INITIALIZER
14427 		(struct cmd_macsec_offload_off_result,
14428 		 macsec, "macsec");
14429 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14430 	TOKEN_STRING_INITIALIZER
14431 		(struct cmd_macsec_offload_off_result,
14432 		 offload, "offload");
14433 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14434 	TOKEN_NUM_INITIALIZER
14435 		(struct cmd_macsec_offload_off_result,
14436 		 port_id, UINT16);
14437 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14438 	TOKEN_STRING_INITIALIZER
14439 		(struct cmd_macsec_offload_off_result,
14440 		 off, "off");
14441 
14442 static void
14443 cmd_set_macsec_offload_off_parsed(
14444 	void *parsed_result,
14445 	__rte_unused struct cmdline *cl,
14446 	__rte_unused void *data)
14447 {
14448 	struct cmd_macsec_offload_off_result *res = parsed_result;
14449 	int ret = -ENOTSUP;
14450 	struct rte_eth_dev_info dev_info;
14451 	portid_t port_id = res->port_id;
14452 
14453 	if (port_id_is_invalid(port_id, ENABLED_WARN))
14454 		return;
14455 	if (!port_is_stopped(port_id)) {
14456 		printf("Please stop port %d first\n", port_id);
14457 		return;
14458 	}
14459 
14460 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
14461 	if (ret != 0)
14462 		return;
14463 
14464 	if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14465 #ifdef RTE_LIBRTE_IXGBE_PMD
14466 		ret = rte_pmd_ixgbe_macsec_disable(port_id);
14467 #endif
14468 	}
14469 	switch (ret) {
14470 	case 0:
14471 		ports[port_id].dev_conf.txmode.offloads &=
14472 						~DEV_TX_OFFLOAD_MACSEC_INSERT;
14473 		cmd_reconfig_device_queue(port_id, 1, 1);
14474 		break;
14475 	case -ENODEV:
14476 		printf("invalid port_id %d\n", port_id);
14477 		break;
14478 	case -ENOTSUP:
14479 		printf("not supported on port %d\n", port_id);
14480 		break;
14481 	default:
14482 		printf("programming error: (%s)\n", strerror(-ret));
14483 	}
14484 }
14485 
14486 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14487 	.f = cmd_set_macsec_offload_off_parsed,
14488 	.data = NULL,
14489 	.help_str = "set macsec offload <port_id> off",
14490 	.tokens = {
14491 		(void *)&cmd_macsec_offload_off_set,
14492 		(void *)&cmd_macsec_offload_off_macsec,
14493 		(void *)&cmd_macsec_offload_off_offload,
14494 		(void *)&cmd_macsec_offload_off_port_id,
14495 		(void *)&cmd_macsec_offload_off_off,
14496 		NULL,
14497 	},
14498 };
14499 
14500 /* Common result structure for MACsec secure connection configure */
14501 struct cmd_macsec_sc_result {
14502 	cmdline_fixed_string_t set;
14503 	cmdline_fixed_string_t macsec;
14504 	cmdline_fixed_string_t sc;
14505 	cmdline_fixed_string_t tx_rx;
14506 	portid_t port_id;
14507 	struct rte_ether_addr mac;
14508 	uint16_t pi;
14509 };
14510 
14511 /* Common CLI fields for MACsec secure connection configure */
14512 cmdline_parse_token_string_t cmd_macsec_sc_set =
14513 	TOKEN_STRING_INITIALIZER
14514 		(struct cmd_macsec_sc_result,
14515 		 set, "set");
14516 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14517 	TOKEN_STRING_INITIALIZER
14518 		(struct cmd_macsec_sc_result,
14519 		 macsec, "macsec");
14520 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14521 	TOKEN_STRING_INITIALIZER
14522 		(struct cmd_macsec_sc_result,
14523 		 sc, "sc");
14524 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14525 	TOKEN_STRING_INITIALIZER
14526 		(struct cmd_macsec_sc_result,
14527 		 tx_rx, "tx#rx");
14528 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14529 	TOKEN_NUM_INITIALIZER
14530 		(struct cmd_macsec_sc_result,
14531 		 port_id, UINT16);
14532 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14533 	TOKEN_ETHERADDR_INITIALIZER
14534 		(struct cmd_macsec_sc_result,
14535 		 mac);
14536 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14537 	TOKEN_NUM_INITIALIZER
14538 		(struct cmd_macsec_sc_result,
14539 		 pi, UINT16);
14540 
14541 static void
14542 cmd_set_macsec_sc_parsed(
14543 	void *parsed_result,
14544 	__rte_unused struct cmdline *cl,
14545 	__rte_unused void *data)
14546 {
14547 	struct cmd_macsec_sc_result *res = parsed_result;
14548 	int ret = -ENOTSUP;
14549 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14550 
14551 #ifdef RTE_LIBRTE_IXGBE_PMD
14552 	ret = is_tx ?
14553 		rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14554 				res->mac.addr_bytes) :
14555 		rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14556 				res->mac.addr_bytes, res->pi);
14557 #endif
14558 	RTE_SET_USED(is_tx);
14559 
14560 	switch (ret) {
14561 	case 0:
14562 		break;
14563 	case -ENODEV:
14564 		printf("invalid port_id %d\n", res->port_id);
14565 		break;
14566 	case -ENOTSUP:
14567 		printf("not supported on port %d\n", res->port_id);
14568 		break;
14569 	default:
14570 		printf("programming error: (%s)\n", strerror(-ret));
14571 	}
14572 }
14573 
14574 cmdline_parse_inst_t cmd_set_macsec_sc = {
14575 	.f = cmd_set_macsec_sc_parsed,
14576 	.data = NULL,
14577 	.help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14578 	.tokens = {
14579 		(void *)&cmd_macsec_sc_set,
14580 		(void *)&cmd_macsec_sc_macsec,
14581 		(void *)&cmd_macsec_sc_sc,
14582 		(void *)&cmd_macsec_sc_tx_rx,
14583 		(void *)&cmd_macsec_sc_port_id,
14584 		(void *)&cmd_macsec_sc_mac,
14585 		(void *)&cmd_macsec_sc_pi,
14586 		NULL,
14587 	},
14588 };
14589 
14590 /* Common result structure for MACsec secure connection configure */
14591 struct cmd_macsec_sa_result {
14592 	cmdline_fixed_string_t set;
14593 	cmdline_fixed_string_t macsec;
14594 	cmdline_fixed_string_t sa;
14595 	cmdline_fixed_string_t tx_rx;
14596 	portid_t port_id;
14597 	uint8_t idx;
14598 	uint8_t an;
14599 	uint32_t pn;
14600 	cmdline_fixed_string_t key;
14601 };
14602 
14603 /* Common CLI fields for MACsec secure connection configure */
14604 cmdline_parse_token_string_t cmd_macsec_sa_set =
14605 	TOKEN_STRING_INITIALIZER
14606 		(struct cmd_macsec_sa_result,
14607 		 set, "set");
14608 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14609 	TOKEN_STRING_INITIALIZER
14610 		(struct cmd_macsec_sa_result,
14611 		 macsec, "macsec");
14612 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14613 	TOKEN_STRING_INITIALIZER
14614 		(struct cmd_macsec_sa_result,
14615 		 sa, "sa");
14616 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14617 	TOKEN_STRING_INITIALIZER
14618 		(struct cmd_macsec_sa_result,
14619 		 tx_rx, "tx#rx");
14620 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14621 	TOKEN_NUM_INITIALIZER
14622 		(struct cmd_macsec_sa_result,
14623 		 port_id, UINT16);
14624 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14625 	TOKEN_NUM_INITIALIZER
14626 		(struct cmd_macsec_sa_result,
14627 		 idx, UINT8);
14628 cmdline_parse_token_num_t cmd_macsec_sa_an =
14629 	TOKEN_NUM_INITIALIZER
14630 		(struct cmd_macsec_sa_result,
14631 		 an, UINT8);
14632 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14633 	TOKEN_NUM_INITIALIZER
14634 		(struct cmd_macsec_sa_result,
14635 		 pn, UINT32);
14636 cmdline_parse_token_string_t cmd_macsec_sa_key =
14637 	TOKEN_STRING_INITIALIZER
14638 		(struct cmd_macsec_sa_result,
14639 		 key, NULL);
14640 
14641 static void
14642 cmd_set_macsec_sa_parsed(
14643 	void *parsed_result,
14644 	__rte_unused struct cmdline *cl,
14645 	__rte_unused void *data)
14646 {
14647 	struct cmd_macsec_sa_result *res = parsed_result;
14648 	int ret = -ENOTSUP;
14649 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14650 	uint8_t key[16] = { 0 };
14651 	uint8_t xdgt0;
14652 	uint8_t xdgt1;
14653 	int key_len;
14654 	int i;
14655 
14656 	key_len = strlen(res->key) / 2;
14657 	if (key_len > 16)
14658 		key_len = 16;
14659 
14660 	for (i = 0; i < key_len; i++) {
14661 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14662 		if (xdgt0 == 0xFF)
14663 			return;
14664 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14665 		if (xdgt1 == 0xFF)
14666 			return;
14667 		key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14668 	}
14669 
14670 #ifdef RTE_LIBRTE_IXGBE_PMD
14671 	ret = is_tx ?
14672 		rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14673 			res->idx, res->an, res->pn, key) :
14674 		rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14675 			res->idx, res->an, res->pn, key);
14676 #endif
14677 	RTE_SET_USED(is_tx);
14678 	RTE_SET_USED(key);
14679 
14680 	switch (ret) {
14681 	case 0:
14682 		break;
14683 	case -EINVAL:
14684 		printf("invalid idx %d or an %d\n", res->idx, res->an);
14685 		break;
14686 	case -ENODEV:
14687 		printf("invalid port_id %d\n", res->port_id);
14688 		break;
14689 	case -ENOTSUP:
14690 		printf("not supported on port %d\n", res->port_id);
14691 		break;
14692 	default:
14693 		printf("programming error: (%s)\n", strerror(-ret));
14694 	}
14695 }
14696 
14697 cmdline_parse_inst_t cmd_set_macsec_sa = {
14698 	.f = cmd_set_macsec_sa_parsed,
14699 	.data = NULL,
14700 	.help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14701 	.tokens = {
14702 		(void *)&cmd_macsec_sa_set,
14703 		(void *)&cmd_macsec_sa_macsec,
14704 		(void *)&cmd_macsec_sa_sa,
14705 		(void *)&cmd_macsec_sa_tx_rx,
14706 		(void *)&cmd_macsec_sa_port_id,
14707 		(void *)&cmd_macsec_sa_idx,
14708 		(void *)&cmd_macsec_sa_an,
14709 		(void *)&cmd_macsec_sa_pn,
14710 		(void *)&cmd_macsec_sa_key,
14711 		NULL,
14712 	},
14713 };
14714 
14715 /* VF unicast promiscuous mode configuration */
14716 
14717 /* Common result structure for VF unicast promiscuous mode */
14718 struct cmd_vf_promisc_result {
14719 	cmdline_fixed_string_t set;
14720 	cmdline_fixed_string_t vf;
14721 	cmdline_fixed_string_t promisc;
14722 	portid_t port_id;
14723 	uint32_t vf_id;
14724 	cmdline_fixed_string_t on_off;
14725 };
14726 
14727 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14728 cmdline_parse_token_string_t cmd_vf_promisc_set =
14729 	TOKEN_STRING_INITIALIZER
14730 		(struct cmd_vf_promisc_result,
14731 		 set, "set");
14732 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14733 	TOKEN_STRING_INITIALIZER
14734 		(struct cmd_vf_promisc_result,
14735 		 vf, "vf");
14736 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14737 	TOKEN_STRING_INITIALIZER
14738 		(struct cmd_vf_promisc_result,
14739 		 promisc, "promisc");
14740 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14741 	TOKEN_NUM_INITIALIZER
14742 		(struct cmd_vf_promisc_result,
14743 		 port_id, UINT16);
14744 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14745 	TOKEN_NUM_INITIALIZER
14746 		(struct cmd_vf_promisc_result,
14747 		 vf_id, UINT32);
14748 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14749 	TOKEN_STRING_INITIALIZER
14750 		(struct cmd_vf_promisc_result,
14751 		 on_off, "on#off");
14752 
14753 static void
14754 cmd_set_vf_promisc_parsed(
14755 	void *parsed_result,
14756 	__rte_unused struct cmdline *cl,
14757 	__rte_unused void *data)
14758 {
14759 	struct cmd_vf_promisc_result *res = parsed_result;
14760 	int ret = -ENOTSUP;
14761 
14762 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14763 
14764 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14765 		return;
14766 
14767 #ifdef RTE_LIBRTE_I40E_PMD
14768 	ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14769 						  res->vf_id, is_on);
14770 #endif
14771 
14772 	switch (ret) {
14773 	case 0:
14774 		break;
14775 	case -EINVAL:
14776 		printf("invalid vf_id %d\n", res->vf_id);
14777 		break;
14778 	case -ENODEV:
14779 		printf("invalid port_id %d\n", res->port_id);
14780 		break;
14781 	case -ENOTSUP:
14782 		printf("function not implemented\n");
14783 		break;
14784 	default:
14785 		printf("programming error: (%s)\n", strerror(-ret));
14786 	}
14787 }
14788 
14789 cmdline_parse_inst_t cmd_set_vf_promisc = {
14790 	.f = cmd_set_vf_promisc_parsed,
14791 	.data = NULL,
14792 	.help_str = "set vf promisc <port_id> <vf_id> on|off: "
14793 		"Set unicast promiscuous mode for a VF from the PF",
14794 	.tokens = {
14795 		(void *)&cmd_vf_promisc_set,
14796 		(void *)&cmd_vf_promisc_vf,
14797 		(void *)&cmd_vf_promisc_promisc,
14798 		(void *)&cmd_vf_promisc_port_id,
14799 		(void *)&cmd_vf_promisc_vf_id,
14800 		(void *)&cmd_vf_promisc_on_off,
14801 		NULL,
14802 	},
14803 };
14804 
14805 /* VF multicast promiscuous mode configuration */
14806 
14807 /* Common result structure for VF multicast promiscuous mode */
14808 struct cmd_vf_allmulti_result {
14809 	cmdline_fixed_string_t set;
14810 	cmdline_fixed_string_t vf;
14811 	cmdline_fixed_string_t allmulti;
14812 	portid_t port_id;
14813 	uint32_t vf_id;
14814 	cmdline_fixed_string_t on_off;
14815 };
14816 
14817 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14818 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14819 	TOKEN_STRING_INITIALIZER
14820 		(struct cmd_vf_allmulti_result,
14821 		 set, "set");
14822 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14823 	TOKEN_STRING_INITIALIZER
14824 		(struct cmd_vf_allmulti_result,
14825 		 vf, "vf");
14826 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14827 	TOKEN_STRING_INITIALIZER
14828 		(struct cmd_vf_allmulti_result,
14829 		 allmulti, "allmulti");
14830 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14831 	TOKEN_NUM_INITIALIZER
14832 		(struct cmd_vf_allmulti_result,
14833 		 port_id, UINT16);
14834 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14835 	TOKEN_NUM_INITIALIZER
14836 		(struct cmd_vf_allmulti_result,
14837 		 vf_id, UINT32);
14838 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14839 	TOKEN_STRING_INITIALIZER
14840 		(struct cmd_vf_allmulti_result,
14841 		 on_off, "on#off");
14842 
14843 static void
14844 cmd_set_vf_allmulti_parsed(
14845 	void *parsed_result,
14846 	__rte_unused struct cmdline *cl,
14847 	__rte_unused void *data)
14848 {
14849 	struct cmd_vf_allmulti_result *res = parsed_result;
14850 	int ret = -ENOTSUP;
14851 
14852 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14853 
14854 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14855 		return;
14856 
14857 #ifdef RTE_LIBRTE_I40E_PMD
14858 	ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14859 						    res->vf_id, is_on);
14860 #endif
14861 
14862 	switch (ret) {
14863 	case 0:
14864 		break;
14865 	case -EINVAL:
14866 		printf("invalid vf_id %d\n", res->vf_id);
14867 		break;
14868 	case -ENODEV:
14869 		printf("invalid port_id %d\n", res->port_id);
14870 		break;
14871 	case -ENOTSUP:
14872 		printf("function not implemented\n");
14873 		break;
14874 	default:
14875 		printf("programming error: (%s)\n", strerror(-ret));
14876 	}
14877 }
14878 
14879 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14880 	.f = cmd_set_vf_allmulti_parsed,
14881 	.data = NULL,
14882 	.help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14883 		"Set multicast promiscuous mode for a VF from the PF",
14884 	.tokens = {
14885 		(void *)&cmd_vf_allmulti_set,
14886 		(void *)&cmd_vf_allmulti_vf,
14887 		(void *)&cmd_vf_allmulti_allmulti,
14888 		(void *)&cmd_vf_allmulti_port_id,
14889 		(void *)&cmd_vf_allmulti_vf_id,
14890 		(void *)&cmd_vf_allmulti_on_off,
14891 		NULL,
14892 	},
14893 };
14894 
14895 /* vf broadcast mode configuration */
14896 
14897 /* Common result structure for vf broadcast */
14898 struct cmd_set_vf_broadcast_result {
14899 	cmdline_fixed_string_t set;
14900 	cmdline_fixed_string_t vf;
14901 	cmdline_fixed_string_t broadcast;
14902 	portid_t port_id;
14903 	uint16_t vf_id;
14904 	cmdline_fixed_string_t on_off;
14905 };
14906 
14907 /* Common CLI fields for vf broadcast enable disable */
14908 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14909 	TOKEN_STRING_INITIALIZER
14910 		(struct cmd_set_vf_broadcast_result,
14911 		 set, "set");
14912 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14913 	TOKEN_STRING_INITIALIZER
14914 		(struct cmd_set_vf_broadcast_result,
14915 		 vf, "vf");
14916 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14917 	TOKEN_STRING_INITIALIZER
14918 		(struct cmd_set_vf_broadcast_result,
14919 		 broadcast, "broadcast");
14920 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14921 	TOKEN_NUM_INITIALIZER
14922 		(struct cmd_set_vf_broadcast_result,
14923 		 port_id, UINT16);
14924 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14925 	TOKEN_NUM_INITIALIZER
14926 		(struct cmd_set_vf_broadcast_result,
14927 		 vf_id, UINT16);
14928 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14929 	TOKEN_STRING_INITIALIZER
14930 		(struct cmd_set_vf_broadcast_result,
14931 		 on_off, "on#off");
14932 
14933 static void
14934 cmd_set_vf_broadcast_parsed(
14935 	void *parsed_result,
14936 	__rte_unused struct cmdline *cl,
14937 	__rte_unused void *data)
14938 {
14939 	struct cmd_set_vf_broadcast_result *res = parsed_result;
14940 	int ret = -ENOTSUP;
14941 
14942 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14943 
14944 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14945 		return;
14946 
14947 #ifdef RTE_LIBRTE_I40E_PMD
14948 	ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14949 					    res->vf_id, is_on);
14950 #endif
14951 
14952 	switch (ret) {
14953 	case 0:
14954 		break;
14955 	case -EINVAL:
14956 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14957 		break;
14958 	case -ENODEV:
14959 		printf("invalid port_id %d\n", res->port_id);
14960 		break;
14961 	case -ENOTSUP:
14962 		printf("function not implemented\n");
14963 		break;
14964 	default:
14965 		printf("programming error: (%s)\n", strerror(-ret));
14966 	}
14967 }
14968 
14969 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14970 	.f = cmd_set_vf_broadcast_parsed,
14971 	.data = NULL,
14972 	.help_str = "set vf broadcast <port_id> <vf_id> on|off",
14973 	.tokens = {
14974 		(void *)&cmd_set_vf_broadcast_set,
14975 		(void *)&cmd_set_vf_broadcast_vf,
14976 		(void *)&cmd_set_vf_broadcast_broadcast,
14977 		(void *)&cmd_set_vf_broadcast_port_id,
14978 		(void *)&cmd_set_vf_broadcast_vf_id,
14979 		(void *)&cmd_set_vf_broadcast_on_off,
14980 		NULL,
14981 	},
14982 };
14983 
14984 /* vf vlan tag configuration */
14985 
14986 /* Common result structure for vf vlan tag */
14987 struct cmd_set_vf_vlan_tag_result {
14988 	cmdline_fixed_string_t set;
14989 	cmdline_fixed_string_t vf;
14990 	cmdline_fixed_string_t vlan;
14991 	cmdline_fixed_string_t tag;
14992 	portid_t port_id;
14993 	uint16_t vf_id;
14994 	cmdline_fixed_string_t on_off;
14995 };
14996 
14997 /* Common CLI fields for vf vlan tag enable disable */
14998 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14999 	TOKEN_STRING_INITIALIZER
15000 		(struct cmd_set_vf_vlan_tag_result,
15001 		 set, "set");
15002 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
15003 	TOKEN_STRING_INITIALIZER
15004 		(struct cmd_set_vf_vlan_tag_result,
15005 		 vf, "vf");
15006 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
15007 	TOKEN_STRING_INITIALIZER
15008 		(struct cmd_set_vf_vlan_tag_result,
15009 		 vlan, "vlan");
15010 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
15011 	TOKEN_STRING_INITIALIZER
15012 		(struct cmd_set_vf_vlan_tag_result,
15013 		 tag, "tag");
15014 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
15015 	TOKEN_NUM_INITIALIZER
15016 		(struct cmd_set_vf_vlan_tag_result,
15017 		 port_id, UINT16);
15018 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
15019 	TOKEN_NUM_INITIALIZER
15020 		(struct cmd_set_vf_vlan_tag_result,
15021 		 vf_id, UINT16);
15022 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
15023 	TOKEN_STRING_INITIALIZER
15024 		(struct cmd_set_vf_vlan_tag_result,
15025 		 on_off, "on#off");
15026 
15027 static void
15028 cmd_set_vf_vlan_tag_parsed(
15029 	void *parsed_result,
15030 	__rte_unused struct cmdline *cl,
15031 	__rte_unused void *data)
15032 {
15033 	struct cmd_set_vf_vlan_tag_result *res = parsed_result;
15034 	int ret = -ENOTSUP;
15035 
15036 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15037 
15038 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15039 		return;
15040 
15041 #ifdef RTE_LIBRTE_I40E_PMD
15042 	ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
15043 					   res->vf_id, is_on);
15044 #endif
15045 
15046 	switch (ret) {
15047 	case 0:
15048 		break;
15049 	case -EINVAL:
15050 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15051 		break;
15052 	case -ENODEV:
15053 		printf("invalid port_id %d\n", res->port_id);
15054 		break;
15055 	case -ENOTSUP:
15056 		printf("function not implemented\n");
15057 		break;
15058 	default:
15059 		printf("programming error: (%s)\n", strerror(-ret));
15060 	}
15061 }
15062 
15063 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
15064 	.f = cmd_set_vf_vlan_tag_parsed,
15065 	.data = NULL,
15066 	.help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15067 	.tokens = {
15068 		(void *)&cmd_set_vf_vlan_tag_set,
15069 		(void *)&cmd_set_vf_vlan_tag_vf,
15070 		(void *)&cmd_set_vf_vlan_tag_vlan,
15071 		(void *)&cmd_set_vf_vlan_tag_tag,
15072 		(void *)&cmd_set_vf_vlan_tag_port_id,
15073 		(void *)&cmd_set_vf_vlan_tag_vf_id,
15074 		(void *)&cmd_set_vf_vlan_tag_on_off,
15075 		NULL,
15076 	},
15077 };
15078 
15079 /* Common definition of VF and TC TX bandwidth configuration */
15080 struct cmd_vf_tc_bw_result {
15081 	cmdline_fixed_string_t set;
15082 	cmdline_fixed_string_t vf;
15083 	cmdline_fixed_string_t tc;
15084 	cmdline_fixed_string_t tx;
15085 	cmdline_fixed_string_t min_bw;
15086 	cmdline_fixed_string_t max_bw;
15087 	cmdline_fixed_string_t strict_link_prio;
15088 	portid_t port_id;
15089 	uint16_t vf_id;
15090 	uint8_t tc_no;
15091 	uint32_t bw;
15092 	cmdline_fixed_string_t bw_list;
15093 	uint8_t tc_map;
15094 };
15095 
15096 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15097 	TOKEN_STRING_INITIALIZER
15098 		(struct cmd_vf_tc_bw_result,
15099 		 set, "set");
15100 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15101 	TOKEN_STRING_INITIALIZER
15102 		(struct cmd_vf_tc_bw_result,
15103 		 vf, "vf");
15104 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15105 	TOKEN_STRING_INITIALIZER
15106 		(struct cmd_vf_tc_bw_result,
15107 		 tc, "tc");
15108 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15109 	TOKEN_STRING_INITIALIZER
15110 		(struct cmd_vf_tc_bw_result,
15111 		 tx, "tx");
15112 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15113 	TOKEN_STRING_INITIALIZER
15114 		(struct cmd_vf_tc_bw_result,
15115 		 strict_link_prio, "strict-link-priority");
15116 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15117 	TOKEN_STRING_INITIALIZER
15118 		(struct cmd_vf_tc_bw_result,
15119 		 min_bw, "min-bandwidth");
15120 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15121 	TOKEN_STRING_INITIALIZER
15122 		(struct cmd_vf_tc_bw_result,
15123 		 max_bw, "max-bandwidth");
15124 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15125 	TOKEN_NUM_INITIALIZER
15126 		(struct cmd_vf_tc_bw_result,
15127 		 port_id, UINT16);
15128 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15129 	TOKEN_NUM_INITIALIZER
15130 		(struct cmd_vf_tc_bw_result,
15131 		 vf_id, UINT16);
15132 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15133 	TOKEN_NUM_INITIALIZER
15134 		(struct cmd_vf_tc_bw_result,
15135 		 tc_no, UINT8);
15136 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15137 	TOKEN_NUM_INITIALIZER
15138 		(struct cmd_vf_tc_bw_result,
15139 		 bw, UINT32);
15140 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15141 	TOKEN_STRING_INITIALIZER
15142 		(struct cmd_vf_tc_bw_result,
15143 		 bw_list, NULL);
15144 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15145 	TOKEN_NUM_INITIALIZER
15146 		(struct cmd_vf_tc_bw_result,
15147 		 tc_map, UINT8);
15148 
15149 /* VF max bandwidth setting */
15150 static void
15151 cmd_vf_max_bw_parsed(
15152 	void *parsed_result,
15153 	__rte_unused struct cmdline *cl,
15154 	__rte_unused void *data)
15155 {
15156 	struct cmd_vf_tc_bw_result *res = parsed_result;
15157 	int ret = -ENOTSUP;
15158 
15159 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15160 		return;
15161 
15162 #ifdef RTE_LIBRTE_I40E_PMD
15163 	ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15164 					 res->vf_id, res->bw);
15165 #endif
15166 
15167 	switch (ret) {
15168 	case 0:
15169 		break;
15170 	case -EINVAL:
15171 		printf("invalid vf_id %d or bandwidth %d\n",
15172 		       res->vf_id, res->bw);
15173 		break;
15174 	case -ENODEV:
15175 		printf("invalid port_id %d\n", res->port_id);
15176 		break;
15177 	case -ENOTSUP:
15178 		printf("function not implemented\n");
15179 		break;
15180 	default:
15181 		printf("programming error: (%s)\n", strerror(-ret));
15182 	}
15183 }
15184 
15185 cmdline_parse_inst_t cmd_vf_max_bw = {
15186 	.f = cmd_vf_max_bw_parsed,
15187 	.data = NULL,
15188 	.help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15189 	.tokens = {
15190 		(void *)&cmd_vf_tc_bw_set,
15191 		(void *)&cmd_vf_tc_bw_vf,
15192 		(void *)&cmd_vf_tc_bw_tx,
15193 		(void *)&cmd_vf_tc_bw_max_bw,
15194 		(void *)&cmd_vf_tc_bw_port_id,
15195 		(void *)&cmd_vf_tc_bw_vf_id,
15196 		(void *)&cmd_vf_tc_bw_bw,
15197 		NULL,
15198 	},
15199 };
15200 
15201 static int
15202 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15203 			   uint8_t *tc_num,
15204 			   char *str)
15205 {
15206 	uint32_t size;
15207 	const char *p, *p0 = str;
15208 	char s[256];
15209 	char *end;
15210 	char *str_fld[16];
15211 	uint16_t i;
15212 	int ret;
15213 
15214 	p = strchr(p0, '(');
15215 	if (p == NULL) {
15216 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15217 		return -1;
15218 	}
15219 	p++;
15220 	p0 = strchr(p, ')');
15221 	if (p0 == NULL) {
15222 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15223 		return -1;
15224 	}
15225 	size = p0 - p;
15226 	if (size >= sizeof(s)) {
15227 		printf("The string size exceeds the internal buffer size\n");
15228 		return -1;
15229 	}
15230 	snprintf(s, sizeof(s), "%.*s", size, p);
15231 	ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15232 	if (ret <= 0) {
15233 		printf("Failed to get the bandwidth list. ");
15234 		return -1;
15235 	}
15236 	*tc_num = ret;
15237 	for (i = 0; i < ret; i++)
15238 		bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15239 
15240 	return 0;
15241 }
15242 
15243 /* TC min bandwidth setting */
15244 static void
15245 cmd_vf_tc_min_bw_parsed(
15246 	void *parsed_result,
15247 	__rte_unused struct cmdline *cl,
15248 	__rte_unused void *data)
15249 {
15250 	struct cmd_vf_tc_bw_result *res = parsed_result;
15251 	uint8_t tc_num;
15252 	uint8_t bw[16];
15253 	int ret = -ENOTSUP;
15254 
15255 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15256 		return;
15257 
15258 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15259 	if (ret)
15260 		return;
15261 
15262 #ifdef RTE_LIBRTE_I40E_PMD
15263 	ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15264 					      tc_num, bw);
15265 #endif
15266 
15267 	switch (ret) {
15268 	case 0:
15269 		break;
15270 	case -EINVAL:
15271 		printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15272 		break;
15273 	case -ENODEV:
15274 		printf("invalid port_id %d\n", res->port_id);
15275 		break;
15276 	case -ENOTSUP:
15277 		printf("function not implemented\n");
15278 		break;
15279 	default:
15280 		printf("programming error: (%s)\n", strerror(-ret));
15281 	}
15282 }
15283 
15284 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15285 	.f = cmd_vf_tc_min_bw_parsed,
15286 	.data = NULL,
15287 	.help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15288 		    " <bw1, bw2, ...>",
15289 	.tokens = {
15290 		(void *)&cmd_vf_tc_bw_set,
15291 		(void *)&cmd_vf_tc_bw_vf,
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_vf_id,
15297 		(void *)&cmd_vf_tc_bw_bw_list,
15298 		NULL,
15299 	},
15300 };
15301 
15302 static void
15303 cmd_tc_min_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 	struct rte_port *port;
15310 	uint8_t tc_num;
15311 	uint8_t bw[16];
15312 	int ret = -ENOTSUP;
15313 
15314 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15315 		return;
15316 
15317 	port = &ports[res->port_id];
15318 	/** Check if the port is not started **/
15319 	if (port->port_status != RTE_PORT_STOPPED) {
15320 		printf("Please stop port %d first\n", res->port_id);
15321 		return;
15322 	}
15323 
15324 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15325 	if (ret)
15326 		return;
15327 
15328 #ifdef RTE_LIBRTE_IXGBE_PMD
15329 	ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15330 #endif
15331 
15332 	switch (ret) {
15333 	case 0:
15334 		break;
15335 	case -EINVAL:
15336 		printf("invalid bandwidth\n");
15337 		break;
15338 	case -ENODEV:
15339 		printf("invalid port_id %d\n", res->port_id);
15340 		break;
15341 	case -ENOTSUP:
15342 		printf("function not implemented\n");
15343 		break;
15344 	default:
15345 		printf("programming error: (%s)\n", strerror(-ret));
15346 	}
15347 }
15348 
15349 cmdline_parse_inst_t cmd_tc_min_bw = {
15350 	.f = cmd_tc_min_bw_parsed,
15351 	.data = NULL,
15352 	.help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15353 	.tokens = {
15354 		(void *)&cmd_vf_tc_bw_set,
15355 		(void *)&cmd_vf_tc_bw_tc,
15356 		(void *)&cmd_vf_tc_bw_tx,
15357 		(void *)&cmd_vf_tc_bw_min_bw,
15358 		(void *)&cmd_vf_tc_bw_port_id,
15359 		(void *)&cmd_vf_tc_bw_bw_list,
15360 		NULL,
15361 	},
15362 };
15363 
15364 /* TC max bandwidth setting */
15365 static void
15366 cmd_vf_tc_max_bw_parsed(
15367 	void *parsed_result,
15368 	__rte_unused struct cmdline *cl,
15369 	__rte_unused void *data)
15370 {
15371 	struct cmd_vf_tc_bw_result *res = parsed_result;
15372 	int ret = -ENOTSUP;
15373 
15374 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15375 		return;
15376 
15377 #ifdef RTE_LIBRTE_I40E_PMD
15378 	ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15379 					    res->tc_no, res->bw);
15380 #endif
15381 
15382 	switch (ret) {
15383 	case 0:
15384 		break;
15385 	case -EINVAL:
15386 		printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15387 		       res->vf_id, res->tc_no, res->bw);
15388 		break;
15389 	case -ENODEV:
15390 		printf("invalid port_id %d\n", res->port_id);
15391 		break;
15392 	case -ENOTSUP:
15393 		printf("function not implemented\n");
15394 		break;
15395 	default:
15396 		printf("programming error: (%s)\n", strerror(-ret));
15397 	}
15398 }
15399 
15400 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15401 	.f = cmd_vf_tc_max_bw_parsed,
15402 	.data = NULL,
15403 	.help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15404 		    " <bandwidth>",
15405 	.tokens = {
15406 		(void *)&cmd_vf_tc_bw_set,
15407 		(void *)&cmd_vf_tc_bw_vf,
15408 		(void *)&cmd_vf_tc_bw_tc,
15409 		(void *)&cmd_vf_tc_bw_tx,
15410 		(void *)&cmd_vf_tc_bw_max_bw,
15411 		(void *)&cmd_vf_tc_bw_port_id,
15412 		(void *)&cmd_vf_tc_bw_vf_id,
15413 		(void *)&cmd_vf_tc_bw_tc_no,
15414 		(void *)&cmd_vf_tc_bw_bw,
15415 		NULL,
15416 	},
15417 };
15418 
15419 /** Set VXLAN encapsulation details */
15420 struct cmd_set_vxlan_result {
15421 	cmdline_fixed_string_t set;
15422 	cmdline_fixed_string_t vxlan;
15423 	cmdline_fixed_string_t pos_token;
15424 	cmdline_fixed_string_t ip_version;
15425 	uint32_t vlan_present:1;
15426 	uint32_t vni;
15427 	uint16_t udp_src;
15428 	uint16_t udp_dst;
15429 	cmdline_ipaddr_t ip_src;
15430 	cmdline_ipaddr_t ip_dst;
15431 	uint16_t tci;
15432 	uint8_t tos;
15433 	uint8_t ttl;
15434 	struct rte_ether_addr eth_src;
15435 	struct rte_ether_addr eth_dst;
15436 };
15437 
15438 cmdline_parse_token_string_t cmd_set_vxlan_set =
15439 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15440 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15441 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15442 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15443 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15444 				 "vxlan-tos-ttl");
15445 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15446 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15447 				 "vxlan-with-vlan");
15448 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15449 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15450 				 "ip-version");
15451 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15452 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15453 				 "ipv4#ipv6");
15454 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15455 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15456 				 "vni");
15457 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15458 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15459 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15460 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15461 				 "udp-src");
15462 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15463 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15464 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15465 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15466 				 "udp-dst");
15467 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15468 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15469 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15470 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15471 				 "ip-tos");
15472 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15473 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15474 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15475 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15476 				 "ip-ttl");
15477 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15478 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15479 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15480 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15481 				 "ip-src");
15482 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15483 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15484 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15485 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15486 				 "ip-dst");
15487 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15488 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15489 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15490 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15491 				 "vlan-tci");
15492 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15493 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15494 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15495 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15496 				 "eth-src");
15497 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15498 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15499 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15500 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15501 				 "eth-dst");
15502 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15503 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15504 
15505 static void cmd_set_vxlan_parsed(void *parsed_result,
15506 	__rte_unused struct cmdline *cl,
15507 	__rte_unused void *data)
15508 {
15509 	struct cmd_set_vxlan_result *res = parsed_result;
15510 	union {
15511 		uint32_t vxlan_id;
15512 		uint8_t vni[4];
15513 	} id = {
15514 		.vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15515 	};
15516 
15517 	vxlan_encap_conf.select_tos_ttl = 0;
15518 	if (strcmp(res->vxlan, "vxlan") == 0)
15519 		vxlan_encap_conf.select_vlan = 0;
15520 	else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15521 		vxlan_encap_conf.select_vlan = 1;
15522 	else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15523 		vxlan_encap_conf.select_vlan = 0;
15524 		vxlan_encap_conf.select_tos_ttl = 1;
15525 	}
15526 	if (strcmp(res->ip_version, "ipv4") == 0)
15527 		vxlan_encap_conf.select_ipv4 = 1;
15528 	else if (strcmp(res->ip_version, "ipv6") == 0)
15529 		vxlan_encap_conf.select_ipv4 = 0;
15530 	else
15531 		return;
15532 	rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15533 	vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15534 	vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15535 	vxlan_encap_conf.ip_tos = res->tos;
15536 	vxlan_encap_conf.ip_ttl = res->ttl;
15537 	if (vxlan_encap_conf.select_ipv4) {
15538 		IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15539 		IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15540 	} else {
15541 		IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15542 		IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15543 	}
15544 	if (vxlan_encap_conf.select_vlan)
15545 		vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15546 	rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15547 		   RTE_ETHER_ADDR_LEN);
15548 	rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15549 		   RTE_ETHER_ADDR_LEN);
15550 }
15551 
15552 cmdline_parse_inst_t cmd_set_vxlan = {
15553 	.f = cmd_set_vxlan_parsed,
15554 	.data = NULL,
15555 	.help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15556 		" <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15557 		" eth-src <eth-src> eth-dst <eth-dst>",
15558 	.tokens = {
15559 		(void *)&cmd_set_vxlan_set,
15560 		(void *)&cmd_set_vxlan_vxlan,
15561 		(void *)&cmd_set_vxlan_ip_version,
15562 		(void *)&cmd_set_vxlan_ip_version_value,
15563 		(void *)&cmd_set_vxlan_vni,
15564 		(void *)&cmd_set_vxlan_vni_value,
15565 		(void *)&cmd_set_vxlan_udp_src,
15566 		(void *)&cmd_set_vxlan_udp_src_value,
15567 		(void *)&cmd_set_vxlan_udp_dst,
15568 		(void *)&cmd_set_vxlan_udp_dst_value,
15569 		(void *)&cmd_set_vxlan_ip_src,
15570 		(void *)&cmd_set_vxlan_ip_src_value,
15571 		(void *)&cmd_set_vxlan_ip_dst,
15572 		(void *)&cmd_set_vxlan_ip_dst_value,
15573 		(void *)&cmd_set_vxlan_eth_src,
15574 		(void *)&cmd_set_vxlan_eth_src_value,
15575 		(void *)&cmd_set_vxlan_eth_dst,
15576 		(void *)&cmd_set_vxlan_eth_dst_value,
15577 		NULL,
15578 	},
15579 };
15580 
15581 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15582 	.f = cmd_set_vxlan_parsed,
15583 	.data = NULL,
15584 	.help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15585 		" <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15586 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15587 		" eth-dst <eth-dst>",
15588 	.tokens = {
15589 		(void *)&cmd_set_vxlan_set,
15590 		(void *)&cmd_set_vxlan_vxlan_tos_ttl,
15591 		(void *)&cmd_set_vxlan_ip_version,
15592 		(void *)&cmd_set_vxlan_ip_version_value,
15593 		(void *)&cmd_set_vxlan_vni,
15594 		(void *)&cmd_set_vxlan_vni_value,
15595 		(void *)&cmd_set_vxlan_udp_src,
15596 		(void *)&cmd_set_vxlan_udp_src_value,
15597 		(void *)&cmd_set_vxlan_udp_dst,
15598 		(void *)&cmd_set_vxlan_udp_dst_value,
15599 		(void *)&cmd_set_vxlan_ip_tos,
15600 		(void *)&cmd_set_vxlan_ip_tos_value,
15601 		(void *)&cmd_set_vxlan_ip_ttl,
15602 		(void *)&cmd_set_vxlan_ip_ttl_value,
15603 		(void *)&cmd_set_vxlan_ip_src,
15604 		(void *)&cmd_set_vxlan_ip_src_value,
15605 		(void *)&cmd_set_vxlan_ip_dst,
15606 		(void *)&cmd_set_vxlan_ip_dst_value,
15607 		(void *)&cmd_set_vxlan_eth_src,
15608 		(void *)&cmd_set_vxlan_eth_src_value,
15609 		(void *)&cmd_set_vxlan_eth_dst,
15610 		(void *)&cmd_set_vxlan_eth_dst_value,
15611 		NULL,
15612 	},
15613 };
15614 
15615 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15616 	.f = cmd_set_vxlan_parsed,
15617 	.data = NULL,
15618 	.help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15619 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15620 		" <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15621 		" <eth-dst>",
15622 	.tokens = {
15623 		(void *)&cmd_set_vxlan_set,
15624 		(void *)&cmd_set_vxlan_vxlan_with_vlan,
15625 		(void *)&cmd_set_vxlan_ip_version,
15626 		(void *)&cmd_set_vxlan_ip_version_value,
15627 		(void *)&cmd_set_vxlan_vni,
15628 		(void *)&cmd_set_vxlan_vni_value,
15629 		(void *)&cmd_set_vxlan_udp_src,
15630 		(void *)&cmd_set_vxlan_udp_src_value,
15631 		(void *)&cmd_set_vxlan_udp_dst,
15632 		(void *)&cmd_set_vxlan_udp_dst_value,
15633 		(void *)&cmd_set_vxlan_ip_src,
15634 		(void *)&cmd_set_vxlan_ip_src_value,
15635 		(void *)&cmd_set_vxlan_ip_dst,
15636 		(void *)&cmd_set_vxlan_ip_dst_value,
15637 		(void *)&cmd_set_vxlan_vlan,
15638 		(void *)&cmd_set_vxlan_vlan_value,
15639 		(void *)&cmd_set_vxlan_eth_src,
15640 		(void *)&cmd_set_vxlan_eth_src_value,
15641 		(void *)&cmd_set_vxlan_eth_dst,
15642 		(void *)&cmd_set_vxlan_eth_dst_value,
15643 		NULL,
15644 	},
15645 };
15646 
15647 /** Set NVGRE encapsulation details */
15648 struct cmd_set_nvgre_result {
15649 	cmdline_fixed_string_t set;
15650 	cmdline_fixed_string_t nvgre;
15651 	cmdline_fixed_string_t pos_token;
15652 	cmdline_fixed_string_t ip_version;
15653 	uint32_t tni;
15654 	cmdline_ipaddr_t ip_src;
15655 	cmdline_ipaddr_t ip_dst;
15656 	uint16_t tci;
15657 	struct rte_ether_addr eth_src;
15658 	struct rte_ether_addr eth_dst;
15659 };
15660 
15661 cmdline_parse_token_string_t cmd_set_nvgre_set =
15662 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15663 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15664 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15665 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15666 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15667 				 "nvgre-with-vlan");
15668 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15669 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15670 				 "ip-version");
15671 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15672 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15673 				 "ipv4#ipv6");
15674 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15675 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15676 				 "tni");
15677 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15678 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15679 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15680 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15681 				 "ip-src");
15682 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15683 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15684 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15685 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15686 				 "ip-dst");
15687 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15688 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15689 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15690 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15691 				 "vlan-tci");
15692 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15693 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15694 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15695 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15696 				 "eth-src");
15697 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15698 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15699 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15700 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15701 				 "eth-dst");
15702 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15703 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15704 
15705 static void cmd_set_nvgre_parsed(void *parsed_result,
15706 	__rte_unused struct cmdline *cl,
15707 	__rte_unused void *data)
15708 {
15709 	struct cmd_set_nvgre_result *res = parsed_result;
15710 	union {
15711 		uint32_t nvgre_tni;
15712 		uint8_t tni[4];
15713 	} id = {
15714 		.nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15715 	};
15716 
15717 	if (strcmp(res->nvgre, "nvgre") == 0)
15718 		nvgre_encap_conf.select_vlan = 0;
15719 	else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15720 		nvgre_encap_conf.select_vlan = 1;
15721 	if (strcmp(res->ip_version, "ipv4") == 0)
15722 		nvgre_encap_conf.select_ipv4 = 1;
15723 	else if (strcmp(res->ip_version, "ipv6") == 0)
15724 		nvgre_encap_conf.select_ipv4 = 0;
15725 	else
15726 		return;
15727 	rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15728 	if (nvgre_encap_conf.select_ipv4) {
15729 		IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15730 		IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15731 	} else {
15732 		IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15733 		IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15734 	}
15735 	if (nvgre_encap_conf.select_vlan)
15736 		nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15737 	rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15738 		   RTE_ETHER_ADDR_LEN);
15739 	rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15740 		   RTE_ETHER_ADDR_LEN);
15741 }
15742 
15743 cmdline_parse_inst_t cmd_set_nvgre = {
15744 	.f = cmd_set_nvgre_parsed,
15745 	.data = NULL,
15746 	.help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15747 		" <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15748 		" eth-dst <eth-dst>",
15749 	.tokens = {
15750 		(void *)&cmd_set_nvgre_set,
15751 		(void *)&cmd_set_nvgre_nvgre,
15752 		(void *)&cmd_set_nvgre_ip_version,
15753 		(void *)&cmd_set_nvgre_ip_version_value,
15754 		(void *)&cmd_set_nvgre_tni,
15755 		(void *)&cmd_set_nvgre_tni_value,
15756 		(void *)&cmd_set_nvgre_ip_src,
15757 		(void *)&cmd_set_nvgre_ip_src_value,
15758 		(void *)&cmd_set_nvgre_ip_dst,
15759 		(void *)&cmd_set_nvgre_ip_dst_value,
15760 		(void *)&cmd_set_nvgre_eth_src,
15761 		(void *)&cmd_set_nvgre_eth_src_value,
15762 		(void *)&cmd_set_nvgre_eth_dst,
15763 		(void *)&cmd_set_nvgre_eth_dst_value,
15764 		NULL,
15765 	},
15766 };
15767 
15768 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15769 	.f = cmd_set_nvgre_parsed,
15770 	.data = NULL,
15771 	.help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15772 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15773 		" eth-src <eth-src> eth-dst <eth-dst>",
15774 	.tokens = {
15775 		(void *)&cmd_set_nvgre_set,
15776 		(void *)&cmd_set_nvgre_nvgre_with_vlan,
15777 		(void *)&cmd_set_nvgre_ip_version,
15778 		(void *)&cmd_set_nvgre_ip_version_value,
15779 		(void *)&cmd_set_nvgre_tni,
15780 		(void *)&cmd_set_nvgre_tni_value,
15781 		(void *)&cmd_set_nvgre_ip_src,
15782 		(void *)&cmd_set_nvgre_ip_src_value,
15783 		(void *)&cmd_set_nvgre_ip_dst,
15784 		(void *)&cmd_set_nvgre_ip_dst_value,
15785 		(void *)&cmd_set_nvgre_vlan,
15786 		(void *)&cmd_set_nvgre_vlan_value,
15787 		(void *)&cmd_set_nvgre_eth_src,
15788 		(void *)&cmd_set_nvgre_eth_src_value,
15789 		(void *)&cmd_set_nvgre_eth_dst,
15790 		(void *)&cmd_set_nvgre_eth_dst_value,
15791 		NULL,
15792 	},
15793 };
15794 
15795 /** Set L2 encapsulation details */
15796 struct cmd_set_l2_encap_result {
15797 	cmdline_fixed_string_t set;
15798 	cmdline_fixed_string_t l2_encap;
15799 	cmdline_fixed_string_t pos_token;
15800 	cmdline_fixed_string_t ip_version;
15801 	uint32_t vlan_present:1;
15802 	uint16_t tci;
15803 	struct rte_ether_addr eth_src;
15804 	struct rte_ether_addr eth_dst;
15805 };
15806 
15807 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15808 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15809 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15810 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15811 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15812 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15813 				 "l2_encap-with-vlan");
15814 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15815 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15816 				 "ip-version");
15817 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15818 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15819 				 "ipv4#ipv6");
15820 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15821 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15822 				 "vlan-tci");
15823 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15824 	TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15825 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15826 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15827 				 "eth-src");
15828 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15829 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15830 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15831 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15832 				 "eth-dst");
15833 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15834 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15835 
15836 static void cmd_set_l2_encap_parsed(void *parsed_result,
15837 	__rte_unused struct cmdline *cl,
15838 	__rte_unused void *data)
15839 {
15840 	struct cmd_set_l2_encap_result *res = parsed_result;
15841 
15842 	if (strcmp(res->l2_encap, "l2_encap") == 0)
15843 		l2_encap_conf.select_vlan = 0;
15844 	else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15845 		l2_encap_conf.select_vlan = 1;
15846 	if (strcmp(res->ip_version, "ipv4") == 0)
15847 		l2_encap_conf.select_ipv4 = 1;
15848 	else if (strcmp(res->ip_version, "ipv6") == 0)
15849 		l2_encap_conf.select_ipv4 = 0;
15850 	else
15851 		return;
15852 	if (l2_encap_conf.select_vlan)
15853 		l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15854 	rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15855 		   RTE_ETHER_ADDR_LEN);
15856 	rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15857 		   RTE_ETHER_ADDR_LEN);
15858 }
15859 
15860 cmdline_parse_inst_t cmd_set_l2_encap = {
15861 	.f = cmd_set_l2_encap_parsed,
15862 	.data = NULL,
15863 	.help_str = "set l2_encap ip-version ipv4|ipv6"
15864 		" eth-src <eth-src> eth-dst <eth-dst>",
15865 	.tokens = {
15866 		(void *)&cmd_set_l2_encap_set,
15867 		(void *)&cmd_set_l2_encap_l2_encap,
15868 		(void *)&cmd_set_l2_encap_ip_version,
15869 		(void *)&cmd_set_l2_encap_ip_version_value,
15870 		(void *)&cmd_set_l2_encap_eth_src,
15871 		(void *)&cmd_set_l2_encap_eth_src_value,
15872 		(void *)&cmd_set_l2_encap_eth_dst,
15873 		(void *)&cmd_set_l2_encap_eth_dst_value,
15874 		NULL,
15875 	},
15876 };
15877 
15878 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15879 	.f = cmd_set_l2_encap_parsed,
15880 	.data = NULL,
15881 	.help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15882 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15883 	.tokens = {
15884 		(void *)&cmd_set_l2_encap_set,
15885 		(void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15886 		(void *)&cmd_set_l2_encap_ip_version,
15887 		(void *)&cmd_set_l2_encap_ip_version_value,
15888 		(void *)&cmd_set_l2_encap_vlan,
15889 		(void *)&cmd_set_l2_encap_vlan_value,
15890 		(void *)&cmd_set_l2_encap_eth_src,
15891 		(void *)&cmd_set_l2_encap_eth_src_value,
15892 		(void *)&cmd_set_l2_encap_eth_dst,
15893 		(void *)&cmd_set_l2_encap_eth_dst_value,
15894 		NULL,
15895 	},
15896 };
15897 
15898 /** Set L2 decapsulation details */
15899 struct cmd_set_l2_decap_result {
15900 	cmdline_fixed_string_t set;
15901 	cmdline_fixed_string_t l2_decap;
15902 	cmdline_fixed_string_t pos_token;
15903 	uint32_t vlan_present:1;
15904 };
15905 
15906 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15907 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15908 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15909 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15910 				 "l2_decap");
15911 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15912 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15913 				 "l2_decap-with-vlan");
15914 
15915 static void cmd_set_l2_decap_parsed(void *parsed_result,
15916 	__rte_unused struct cmdline *cl,
15917 	__rte_unused void *data)
15918 {
15919 	struct cmd_set_l2_decap_result *res = parsed_result;
15920 
15921 	if (strcmp(res->l2_decap, "l2_decap") == 0)
15922 		l2_decap_conf.select_vlan = 0;
15923 	else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15924 		l2_decap_conf.select_vlan = 1;
15925 }
15926 
15927 cmdline_parse_inst_t cmd_set_l2_decap = {
15928 	.f = cmd_set_l2_decap_parsed,
15929 	.data = NULL,
15930 	.help_str = "set l2_decap",
15931 	.tokens = {
15932 		(void *)&cmd_set_l2_decap_set,
15933 		(void *)&cmd_set_l2_decap_l2_decap,
15934 		NULL,
15935 	},
15936 };
15937 
15938 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15939 	.f = cmd_set_l2_decap_parsed,
15940 	.data = NULL,
15941 	.help_str = "set l2_decap-with-vlan",
15942 	.tokens = {
15943 		(void *)&cmd_set_l2_decap_set,
15944 		(void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15945 		NULL,
15946 	},
15947 };
15948 
15949 /** Set MPLSoGRE encapsulation details */
15950 struct cmd_set_mplsogre_encap_result {
15951 	cmdline_fixed_string_t set;
15952 	cmdline_fixed_string_t mplsogre;
15953 	cmdline_fixed_string_t pos_token;
15954 	cmdline_fixed_string_t ip_version;
15955 	uint32_t vlan_present:1;
15956 	uint32_t label;
15957 	cmdline_ipaddr_t ip_src;
15958 	cmdline_ipaddr_t ip_dst;
15959 	uint16_t tci;
15960 	struct rte_ether_addr eth_src;
15961 	struct rte_ether_addr eth_dst;
15962 };
15963 
15964 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15965 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15966 				 "set");
15967 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15968 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15969 				 "mplsogre_encap");
15970 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15971 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15972 				 mplsogre, "mplsogre_encap-with-vlan");
15973 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15974 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15975 				 pos_token, "ip-version");
15976 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15977 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15978 				 ip_version, "ipv4#ipv6");
15979 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15980 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15981 				 pos_token, "label");
15982 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15983 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15984 			      UINT32);
15985 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15986 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15987 				 pos_token, "ip-src");
15988 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15989 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15990 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15991 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15992 				 pos_token, "ip-dst");
15993 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15994 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15995 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15996 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15997 				 pos_token, "vlan-tci");
15998 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15999 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16000 			      UINT16);
16001 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16002 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16003 				 pos_token, "eth-src");
16004 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16005 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16006 				    eth_src);
16007 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16008 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16009 				 pos_token, "eth-dst");
16010 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16011 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16012 				    eth_dst);
16013 
16014 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16015 	__rte_unused struct cmdline *cl,
16016 	__rte_unused void *data)
16017 {
16018 	struct cmd_set_mplsogre_encap_result *res = parsed_result;
16019 	union {
16020 		uint32_t mplsogre_label;
16021 		uint8_t label[4];
16022 	} id = {
16023 		.mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16024 	};
16025 
16026 	if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16027 		mplsogre_encap_conf.select_vlan = 0;
16028 	else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16029 		mplsogre_encap_conf.select_vlan = 1;
16030 	if (strcmp(res->ip_version, "ipv4") == 0)
16031 		mplsogre_encap_conf.select_ipv4 = 1;
16032 	else if (strcmp(res->ip_version, "ipv6") == 0)
16033 		mplsogre_encap_conf.select_ipv4 = 0;
16034 	else
16035 		return;
16036 	rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16037 	if (mplsogre_encap_conf.select_ipv4) {
16038 		IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16039 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16040 	} else {
16041 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16042 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16043 	}
16044 	if (mplsogre_encap_conf.select_vlan)
16045 		mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16046 	rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16047 		   RTE_ETHER_ADDR_LEN);
16048 	rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16049 		   RTE_ETHER_ADDR_LEN);
16050 }
16051 
16052 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16053 	.f = cmd_set_mplsogre_encap_parsed,
16054 	.data = NULL,
16055 	.help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16056 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16057 		" eth-dst <eth-dst>",
16058 	.tokens = {
16059 		(void *)&cmd_set_mplsogre_encap_set,
16060 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16061 		(void *)&cmd_set_mplsogre_encap_ip_version,
16062 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
16063 		(void *)&cmd_set_mplsogre_encap_label,
16064 		(void *)&cmd_set_mplsogre_encap_label_value,
16065 		(void *)&cmd_set_mplsogre_encap_ip_src,
16066 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
16067 		(void *)&cmd_set_mplsogre_encap_ip_dst,
16068 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
16069 		(void *)&cmd_set_mplsogre_encap_eth_src,
16070 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
16071 		(void *)&cmd_set_mplsogre_encap_eth_dst,
16072 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
16073 		NULL,
16074 	},
16075 };
16076 
16077 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16078 	.f = cmd_set_mplsogre_encap_parsed,
16079 	.data = NULL,
16080 	.help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16081 		" label <label> ip-src <ip-src> ip-dst <ip-dst>"
16082 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16083 	.tokens = {
16084 		(void *)&cmd_set_mplsogre_encap_set,
16085 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16086 		(void *)&cmd_set_mplsogre_encap_ip_version,
16087 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
16088 		(void *)&cmd_set_mplsogre_encap_label,
16089 		(void *)&cmd_set_mplsogre_encap_label_value,
16090 		(void *)&cmd_set_mplsogre_encap_ip_src,
16091 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
16092 		(void *)&cmd_set_mplsogre_encap_ip_dst,
16093 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
16094 		(void *)&cmd_set_mplsogre_encap_vlan,
16095 		(void *)&cmd_set_mplsogre_encap_vlan_value,
16096 		(void *)&cmd_set_mplsogre_encap_eth_src,
16097 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
16098 		(void *)&cmd_set_mplsogre_encap_eth_dst,
16099 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
16100 		NULL,
16101 	},
16102 };
16103 
16104 /** Set MPLSoGRE decapsulation details */
16105 struct cmd_set_mplsogre_decap_result {
16106 	cmdline_fixed_string_t set;
16107 	cmdline_fixed_string_t mplsogre;
16108 	cmdline_fixed_string_t pos_token;
16109 	cmdline_fixed_string_t ip_version;
16110 	uint32_t vlan_present:1;
16111 };
16112 
16113 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16114 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16115 				 "set");
16116 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16117 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16118 				 "mplsogre_decap");
16119 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16120 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16121 				 mplsogre, "mplsogre_decap-with-vlan");
16122 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16123 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16124 				 pos_token, "ip-version");
16125 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16126 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16127 				 ip_version, "ipv4#ipv6");
16128 
16129 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16130 	__rte_unused struct cmdline *cl,
16131 	__rte_unused void *data)
16132 {
16133 	struct cmd_set_mplsogre_decap_result *res = parsed_result;
16134 
16135 	if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16136 		mplsogre_decap_conf.select_vlan = 0;
16137 	else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16138 		mplsogre_decap_conf.select_vlan = 1;
16139 	if (strcmp(res->ip_version, "ipv4") == 0)
16140 		mplsogre_decap_conf.select_ipv4 = 1;
16141 	else if (strcmp(res->ip_version, "ipv6") == 0)
16142 		mplsogre_decap_conf.select_ipv4 = 0;
16143 }
16144 
16145 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16146 	.f = cmd_set_mplsogre_decap_parsed,
16147 	.data = NULL,
16148 	.help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16149 	.tokens = {
16150 		(void *)&cmd_set_mplsogre_decap_set,
16151 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16152 		(void *)&cmd_set_mplsogre_decap_ip_version,
16153 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
16154 		NULL,
16155 	},
16156 };
16157 
16158 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16159 	.f = cmd_set_mplsogre_decap_parsed,
16160 	.data = NULL,
16161 	.help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16162 	.tokens = {
16163 		(void *)&cmd_set_mplsogre_decap_set,
16164 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16165 		(void *)&cmd_set_mplsogre_decap_ip_version,
16166 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
16167 		NULL,
16168 	},
16169 };
16170 
16171 /** Set MPLSoUDP encapsulation details */
16172 struct cmd_set_mplsoudp_encap_result {
16173 	cmdline_fixed_string_t set;
16174 	cmdline_fixed_string_t mplsoudp;
16175 	cmdline_fixed_string_t pos_token;
16176 	cmdline_fixed_string_t ip_version;
16177 	uint32_t vlan_present:1;
16178 	uint32_t label;
16179 	uint16_t udp_src;
16180 	uint16_t udp_dst;
16181 	cmdline_ipaddr_t ip_src;
16182 	cmdline_ipaddr_t ip_dst;
16183 	uint16_t tci;
16184 	struct rte_ether_addr eth_src;
16185 	struct rte_ether_addr eth_dst;
16186 };
16187 
16188 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16189 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16190 				 "set");
16191 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16192 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16193 				 "mplsoudp_encap");
16194 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16195 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16196 				 mplsoudp, "mplsoudp_encap-with-vlan");
16197 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16198 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16199 				 pos_token, "ip-version");
16200 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16201 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16202 				 ip_version, "ipv4#ipv6");
16203 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16204 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16205 				 pos_token, "label");
16206 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16207 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16208 			      UINT32);
16209 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16210 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16211 				 pos_token, "udp-src");
16212 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16213 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16214 			      UINT16);
16215 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16216 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16217 				 pos_token, "udp-dst");
16218 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16219 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16220 			      UINT16);
16221 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16222 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16223 				 pos_token, "ip-src");
16224 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16225 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16226 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16227 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16228 				 pos_token, "ip-dst");
16229 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16230 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16231 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16232 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16233 				 pos_token, "vlan-tci");
16234 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16235 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16236 			      UINT16);
16237 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16238 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16239 				 pos_token, "eth-src");
16240 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16241 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16242 				    eth_src);
16243 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16244 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16245 				 pos_token, "eth-dst");
16246 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16247 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16248 				    eth_dst);
16249 
16250 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16251 	__rte_unused struct cmdline *cl,
16252 	__rte_unused void *data)
16253 {
16254 	struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16255 	union {
16256 		uint32_t mplsoudp_label;
16257 		uint8_t label[4];
16258 	} id = {
16259 		.mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16260 	};
16261 
16262 	if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16263 		mplsoudp_encap_conf.select_vlan = 0;
16264 	else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16265 		mplsoudp_encap_conf.select_vlan = 1;
16266 	if (strcmp(res->ip_version, "ipv4") == 0)
16267 		mplsoudp_encap_conf.select_ipv4 = 1;
16268 	else if (strcmp(res->ip_version, "ipv6") == 0)
16269 		mplsoudp_encap_conf.select_ipv4 = 0;
16270 	else
16271 		return;
16272 	rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16273 	mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16274 	mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16275 	if (mplsoudp_encap_conf.select_ipv4) {
16276 		IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16277 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16278 	} else {
16279 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16280 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16281 	}
16282 	if (mplsoudp_encap_conf.select_vlan)
16283 		mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16284 	rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16285 		   RTE_ETHER_ADDR_LEN);
16286 	rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16287 		   RTE_ETHER_ADDR_LEN);
16288 }
16289 
16290 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16291 	.f = cmd_set_mplsoudp_encap_parsed,
16292 	.data = NULL,
16293 	.help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16294 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16295 		" ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16296 	.tokens = {
16297 		(void *)&cmd_set_mplsoudp_encap_set,
16298 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16299 		(void *)&cmd_set_mplsoudp_encap_ip_version,
16300 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
16301 		(void *)&cmd_set_mplsoudp_encap_label,
16302 		(void *)&cmd_set_mplsoudp_encap_label_value,
16303 		(void *)&cmd_set_mplsoudp_encap_udp_src,
16304 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
16305 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
16306 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16307 		(void *)&cmd_set_mplsoudp_encap_ip_src,
16308 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
16309 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
16310 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16311 		(void *)&cmd_set_mplsoudp_encap_eth_src,
16312 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
16313 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
16314 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16315 		NULL,
16316 	},
16317 };
16318 
16319 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16320 	.f = cmd_set_mplsoudp_encap_parsed,
16321 	.data = NULL,
16322 	.help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16323 		" label <label> udp-src <udp-src> udp-dst <udp-dst>"
16324 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16325 		" eth-src <eth-src> eth-dst <eth-dst>",
16326 	.tokens = {
16327 		(void *)&cmd_set_mplsoudp_encap_set,
16328 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16329 		(void *)&cmd_set_mplsoudp_encap_ip_version,
16330 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
16331 		(void *)&cmd_set_mplsoudp_encap_label,
16332 		(void *)&cmd_set_mplsoudp_encap_label_value,
16333 		(void *)&cmd_set_mplsoudp_encap_udp_src,
16334 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
16335 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
16336 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16337 		(void *)&cmd_set_mplsoudp_encap_ip_src,
16338 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
16339 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
16340 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16341 		(void *)&cmd_set_mplsoudp_encap_vlan,
16342 		(void *)&cmd_set_mplsoudp_encap_vlan_value,
16343 		(void *)&cmd_set_mplsoudp_encap_eth_src,
16344 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
16345 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
16346 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16347 		NULL,
16348 	},
16349 };
16350 
16351 /** Set MPLSoUDP decapsulation details */
16352 struct cmd_set_mplsoudp_decap_result {
16353 	cmdline_fixed_string_t set;
16354 	cmdline_fixed_string_t mplsoudp;
16355 	cmdline_fixed_string_t pos_token;
16356 	cmdline_fixed_string_t ip_version;
16357 	uint32_t vlan_present:1;
16358 };
16359 
16360 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16361 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16362 				 "set");
16363 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16364 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16365 				 "mplsoudp_decap");
16366 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16367 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16368 				 mplsoudp, "mplsoudp_decap-with-vlan");
16369 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16370 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16371 				 pos_token, "ip-version");
16372 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16373 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16374 				 ip_version, "ipv4#ipv6");
16375 
16376 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16377 	__rte_unused struct cmdline *cl,
16378 	__rte_unused void *data)
16379 {
16380 	struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16381 
16382 	if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16383 		mplsoudp_decap_conf.select_vlan = 0;
16384 	else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16385 		mplsoudp_decap_conf.select_vlan = 1;
16386 	if (strcmp(res->ip_version, "ipv4") == 0)
16387 		mplsoudp_decap_conf.select_ipv4 = 1;
16388 	else if (strcmp(res->ip_version, "ipv6") == 0)
16389 		mplsoudp_decap_conf.select_ipv4 = 0;
16390 }
16391 
16392 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16393 	.f = cmd_set_mplsoudp_decap_parsed,
16394 	.data = NULL,
16395 	.help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16396 	.tokens = {
16397 		(void *)&cmd_set_mplsoudp_decap_set,
16398 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16399 		(void *)&cmd_set_mplsoudp_decap_ip_version,
16400 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
16401 		NULL,
16402 	},
16403 };
16404 
16405 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16406 	.f = cmd_set_mplsoudp_decap_parsed,
16407 	.data = NULL,
16408 	.help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16409 	.tokens = {
16410 		(void *)&cmd_set_mplsoudp_decap_set,
16411 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16412 		(void *)&cmd_set_mplsoudp_decap_ip_version,
16413 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
16414 		NULL,
16415 	},
16416 };
16417 
16418 /* Strict link priority scheduling mode setting */
16419 static void
16420 cmd_strict_link_prio_parsed(
16421 	void *parsed_result,
16422 	__rte_unused struct cmdline *cl,
16423 	__rte_unused void *data)
16424 {
16425 	struct cmd_vf_tc_bw_result *res = parsed_result;
16426 	int ret = -ENOTSUP;
16427 
16428 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16429 		return;
16430 
16431 #ifdef RTE_LIBRTE_I40E_PMD
16432 	ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16433 #endif
16434 
16435 	switch (ret) {
16436 	case 0:
16437 		break;
16438 	case -EINVAL:
16439 		printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16440 		break;
16441 	case -ENODEV:
16442 		printf("invalid port_id %d\n", res->port_id);
16443 		break;
16444 	case -ENOTSUP:
16445 		printf("function not implemented\n");
16446 		break;
16447 	default:
16448 		printf("programming error: (%s)\n", strerror(-ret));
16449 	}
16450 }
16451 
16452 cmdline_parse_inst_t cmd_strict_link_prio = {
16453 	.f = cmd_strict_link_prio_parsed,
16454 	.data = NULL,
16455 	.help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16456 	.tokens = {
16457 		(void *)&cmd_vf_tc_bw_set,
16458 		(void *)&cmd_vf_tc_bw_tx,
16459 		(void *)&cmd_vf_tc_bw_strict_link_prio,
16460 		(void *)&cmd_vf_tc_bw_port_id,
16461 		(void *)&cmd_vf_tc_bw_tc_map,
16462 		NULL,
16463 	},
16464 };
16465 
16466 /* Load dynamic device personalization*/
16467 struct cmd_ddp_add_result {
16468 	cmdline_fixed_string_t ddp;
16469 	cmdline_fixed_string_t add;
16470 	portid_t port_id;
16471 	char filepath[];
16472 };
16473 
16474 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16475 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16476 cmdline_parse_token_string_t cmd_ddp_add_add =
16477 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16478 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16479 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16480 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16481 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16482 
16483 static void
16484 cmd_ddp_add_parsed(
16485 	void *parsed_result,
16486 	__rte_unused struct cmdline *cl,
16487 	__rte_unused void *data)
16488 {
16489 	struct cmd_ddp_add_result *res = parsed_result;
16490 	uint8_t *buff;
16491 	uint32_t size;
16492 	char *filepath;
16493 	char *file_fld[2];
16494 	int file_num;
16495 	int ret = -ENOTSUP;
16496 
16497 	if (!all_ports_stopped()) {
16498 		printf("Please stop all ports first\n");
16499 		return;
16500 	}
16501 
16502 	filepath = strdup(res->filepath);
16503 	if (filepath == NULL) {
16504 		printf("Failed to allocate memory\n");
16505 		return;
16506 	}
16507 	file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16508 
16509 	buff = open_file(file_fld[0], &size);
16510 	if (!buff) {
16511 		free((void *)filepath);
16512 		return;
16513 	}
16514 
16515 #ifdef RTE_LIBRTE_I40E_PMD
16516 	if (ret == -ENOTSUP)
16517 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16518 					       buff, size,
16519 					       RTE_PMD_I40E_PKG_OP_WR_ADD);
16520 #endif
16521 
16522 	if (ret == -EEXIST)
16523 		printf("Profile has already existed.\n");
16524 	else if (ret < 0)
16525 		printf("Failed to load profile.\n");
16526 	else if (file_num == 2)
16527 		save_file(file_fld[1], buff, size);
16528 
16529 	close_file(buff);
16530 	free((void *)filepath);
16531 }
16532 
16533 cmdline_parse_inst_t cmd_ddp_add = {
16534 	.f = cmd_ddp_add_parsed,
16535 	.data = NULL,
16536 	.help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16537 	.tokens = {
16538 		(void *)&cmd_ddp_add_ddp,
16539 		(void *)&cmd_ddp_add_add,
16540 		(void *)&cmd_ddp_add_port_id,
16541 		(void *)&cmd_ddp_add_filepath,
16542 		NULL,
16543 	},
16544 };
16545 
16546 /* Delete dynamic device personalization*/
16547 struct cmd_ddp_del_result {
16548 	cmdline_fixed_string_t ddp;
16549 	cmdline_fixed_string_t del;
16550 	portid_t port_id;
16551 	char filepath[];
16552 };
16553 
16554 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16555 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16556 cmdline_parse_token_string_t cmd_ddp_del_del =
16557 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16558 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16559 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16560 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16561 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16562 
16563 static void
16564 cmd_ddp_del_parsed(
16565 	void *parsed_result,
16566 	__rte_unused struct cmdline *cl,
16567 	__rte_unused void *data)
16568 {
16569 	struct cmd_ddp_del_result *res = parsed_result;
16570 	uint8_t *buff;
16571 	uint32_t size;
16572 	int ret = -ENOTSUP;
16573 
16574 	if (!all_ports_stopped()) {
16575 		printf("Please stop all ports first\n");
16576 		return;
16577 	}
16578 
16579 	buff = open_file(res->filepath, &size);
16580 	if (!buff)
16581 		return;
16582 
16583 #ifdef RTE_LIBRTE_I40E_PMD
16584 	if (ret == -ENOTSUP)
16585 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16586 					       buff, size,
16587 					       RTE_PMD_I40E_PKG_OP_WR_DEL);
16588 #endif
16589 
16590 	if (ret == -EACCES)
16591 		printf("Profile does not exist.\n");
16592 	else if (ret < 0)
16593 		printf("Failed to delete profile.\n");
16594 
16595 	close_file(buff);
16596 }
16597 
16598 cmdline_parse_inst_t cmd_ddp_del = {
16599 	.f = cmd_ddp_del_parsed,
16600 	.data = NULL,
16601 	.help_str = "ddp del <port_id> <backup_profile_path>",
16602 	.tokens = {
16603 		(void *)&cmd_ddp_del_ddp,
16604 		(void *)&cmd_ddp_del_del,
16605 		(void *)&cmd_ddp_del_port_id,
16606 		(void *)&cmd_ddp_del_filepath,
16607 		NULL,
16608 	},
16609 };
16610 
16611 /* Get dynamic device personalization profile info */
16612 struct cmd_ddp_info_result {
16613 	cmdline_fixed_string_t ddp;
16614 	cmdline_fixed_string_t get;
16615 	cmdline_fixed_string_t info;
16616 	char filepath[];
16617 };
16618 
16619 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16620 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16621 cmdline_parse_token_string_t cmd_ddp_info_get =
16622 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16623 cmdline_parse_token_string_t cmd_ddp_info_info =
16624 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16625 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16626 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16627 
16628 static void
16629 cmd_ddp_info_parsed(
16630 	void *parsed_result,
16631 	__rte_unused struct cmdline *cl,
16632 	__rte_unused void *data)
16633 {
16634 	struct cmd_ddp_info_result *res = parsed_result;
16635 	uint8_t *pkg;
16636 	uint32_t pkg_size;
16637 	int ret = -ENOTSUP;
16638 #ifdef RTE_LIBRTE_I40E_PMD
16639 	uint32_t i, j, n;
16640 	uint8_t *buff;
16641 	uint32_t buff_size = 0;
16642 	struct rte_pmd_i40e_profile_info info;
16643 	uint32_t dev_num = 0;
16644 	struct rte_pmd_i40e_ddp_device_id *devs;
16645 	uint32_t proto_num = 0;
16646 	struct rte_pmd_i40e_proto_info *proto = NULL;
16647 	uint32_t pctype_num = 0;
16648 	struct rte_pmd_i40e_ptype_info *pctype;
16649 	uint32_t ptype_num = 0;
16650 	struct rte_pmd_i40e_ptype_info *ptype;
16651 	uint8_t proto_id;
16652 
16653 #endif
16654 
16655 	pkg = open_file(res->filepath, &pkg_size);
16656 	if (!pkg)
16657 		return;
16658 
16659 #ifdef RTE_LIBRTE_I40E_PMD
16660 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16661 				(uint8_t *)&info, sizeof(info),
16662 				RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16663 	if (!ret) {
16664 		printf("Global Track id:       0x%x\n", info.track_id);
16665 		printf("Global Version:        %d.%d.%d.%d\n",
16666 			info.version.major,
16667 			info.version.minor,
16668 			info.version.update,
16669 			info.version.draft);
16670 		printf("Global Package name:   %s\n\n", info.name);
16671 	}
16672 
16673 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16674 				(uint8_t *)&info, sizeof(info),
16675 				RTE_PMD_I40E_PKG_INFO_HEADER);
16676 	if (!ret) {
16677 		printf("i40e Profile Track id: 0x%x\n", info.track_id);
16678 		printf("i40e Profile Version:  %d.%d.%d.%d\n",
16679 			info.version.major,
16680 			info.version.minor,
16681 			info.version.update,
16682 			info.version.draft);
16683 		printf("i40e Profile name:     %s\n\n", info.name);
16684 	}
16685 
16686 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16687 				(uint8_t *)&buff_size, sizeof(buff_size),
16688 				RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16689 	if (!ret && buff_size) {
16690 		buff = (uint8_t *)malloc(buff_size);
16691 		if (buff) {
16692 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16693 						buff, buff_size,
16694 						RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16695 			if (!ret)
16696 				printf("Package Notes:\n%s\n\n", buff);
16697 			free(buff);
16698 		}
16699 	}
16700 
16701 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16702 				(uint8_t *)&dev_num, sizeof(dev_num),
16703 				RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16704 	if (!ret && dev_num) {
16705 		buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16706 		devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16707 		if (devs) {
16708 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16709 						(uint8_t *)devs, buff_size,
16710 						RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16711 			if (!ret) {
16712 				printf("List of supported devices:\n");
16713 				for (i = 0; i < dev_num; i++) {
16714 					printf("  %04X:%04X %04X:%04X\n",
16715 						devs[i].vendor_dev_id >> 16,
16716 						devs[i].vendor_dev_id & 0xFFFF,
16717 						devs[i].sub_vendor_dev_id >> 16,
16718 						devs[i].sub_vendor_dev_id & 0xFFFF);
16719 				}
16720 				printf("\n");
16721 			}
16722 			free(devs);
16723 		}
16724 	}
16725 
16726 	/* get information about protocols and packet types */
16727 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16728 		(uint8_t *)&proto_num, sizeof(proto_num),
16729 		RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16730 	if (ret || !proto_num)
16731 		goto no_print_return;
16732 
16733 	buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16734 	proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16735 	if (!proto)
16736 		goto no_print_return;
16737 
16738 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16739 					buff_size,
16740 					RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16741 	if (!ret) {
16742 		printf("List of used protocols:\n");
16743 		for (i = 0; i < proto_num; i++)
16744 			printf("  %2u: %s\n", proto[i].proto_id,
16745 			       proto[i].name);
16746 		printf("\n");
16747 	}
16748 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16749 		(uint8_t *)&pctype_num, sizeof(pctype_num),
16750 		RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16751 	if (ret || !pctype_num)
16752 		goto no_print_pctypes;
16753 
16754 	buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16755 	pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16756 	if (!pctype)
16757 		goto no_print_pctypes;
16758 
16759 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16760 					buff_size,
16761 					RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16762 	if (ret) {
16763 		free(pctype);
16764 		goto no_print_pctypes;
16765 	}
16766 
16767 	printf("List of defined packet classification types:\n");
16768 	for (i = 0; i < pctype_num; i++) {
16769 		printf("  %2u:", pctype[i].ptype_id);
16770 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16771 			proto_id = pctype[i].protocols[j];
16772 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16773 				for (n = 0; n < proto_num; n++) {
16774 					if (proto[n].proto_id == proto_id) {
16775 						printf(" %s", proto[n].name);
16776 						break;
16777 					}
16778 				}
16779 			}
16780 		}
16781 		printf("\n");
16782 	}
16783 	printf("\n");
16784 	free(pctype);
16785 
16786 no_print_pctypes:
16787 
16788 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16789 					sizeof(ptype_num),
16790 					RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16791 	if (ret || !ptype_num)
16792 		goto no_print_return;
16793 
16794 	buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16795 	ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16796 	if (!ptype)
16797 		goto no_print_return;
16798 
16799 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16800 					buff_size,
16801 					RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16802 	if (ret) {
16803 		free(ptype);
16804 		goto no_print_return;
16805 	}
16806 	printf("List of defined packet types:\n");
16807 	for (i = 0; i < ptype_num; i++) {
16808 		printf("  %2u:", ptype[i].ptype_id);
16809 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16810 			proto_id = ptype[i].protocols[j];
16811 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16812 				for (n = 0; n < proto_num; n++) {
16813 					if (proto[n].proto_id == proto_id) {
16814 						printf(" %s", proto[n].name);
16815 						break;
16816 					}
16817 				}
16818 			}
16819 		}
16820 		printf("\n");
16821 	}
16822 	free(ptype);
16823 	printf("\n");
16824 
16825 	ret = 0;
16826 no_print_return:
16827 	if (proto)
16828 		free(proto);
16829 #endif
16830 	if (ret == -ENOTSUP)
16831 		printf("Function not supported in PMD driver\n");
16832 	close_file(pkg);
16833 }
16834 
16835 cmdline_parse_inst_t cmd_ddp_get_info = {
16836 	.f = cmd_ddp_info_parsed,
16837 	.data = NULL,
16838 	.help_str = "ddp get info <profile_path>",
16839 	.tokens = {
16840 		(void *)&cmd_ddp_info_ddp,
16841 		(void *)&cmd_ddp_info_get,
16842 		(void *)&cmd_ddp_info_info,
16843 		(void *)&cmd_ddp_info_filepath,
16844 		NULL,
16845 	},
16846 };
16847 
16848 /* Get dynamic device personalization profile info list*/
16849 #define PROFILE_INFO_SIZE 48
16850 #define MAX_PROFILE_NUM 16
16851 
16852 struct cmd_ddp_get_list_result {
16853 	cmdline_fixed_string_t ddp;
16854 	cmdline_fixed_string_t get;
16855 	cmdline_fixed_string_t list;
16856 	portid_t port_id;
16857 };
16858 
16859 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16860 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16861 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16862 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16863 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16864 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16865 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16866 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16867 
16868 static void
16869 cmd_ddp_get_list_parsed(
16870 	__rte_unused void *parsed_result,
16871 	__rte_unused struct cmdline *cl,
16872 	__rte_unused void *data)
16873 {
16874 #ifdef RTE_LIBRTE_I40E_PMD
16875 	struct cmd_ddp_get_list_result *res = parsed_result;
16876 	struct rte_pmd_i40e_profile_list *p_list;
16877 	struct rte_pmd_i40e_profile_info *p_info;
16878 	uint32_t p_num;
16879 	uint32_t size;
16880 	uint32_t i;
16881 #endif
16882 	int ret = -ENOTSUP;
16883 
16884 #ifdef RTE_LIBRTE_I40E_PMD
16885 	size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16886 	p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16887 	if (!p_list) {
16888 		printf("%s: Failed to malloc buffer\n", __func__);
16889 		return;
16890 	}
16891 
16892 	if (ret == -ENOTSUP)
16893 		ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16894 						(uint8_t *)p_list, size);
16895 
16896 	if (!ret) {
16897 		p_num = p_list->p_count;
16898 		printf("Profile number is: %d\n\n", p_num);
16899 
16900 		for (i = 0; i < p_num; i++) {
16901 			p_info = &p_list->p_info[i];
16902 			printf("Profile %d:\n", i);
16903 			printf("Track id:     0x%x\n", p_info->track_id);
16904 			printf("Version:      %d.%d.%d.%d\n",
16905 			       p_info->version.major,
16906 			       p_info->version.minor,
16907 			       p_info->version.update,
16908 			       p_info->version.draft);
16909 			printf("Profile name: %s\n\n", p_info->name);
16910 		}
16911 	}
16912 
16913 	free(p_list);
16914 #endif
16915 
16916 	if (ret < 0)
16917 		printf("Failed to get ddp list\n");
16918 }
16919 
16920 cmdline_parse_inst_t cmd_ddp_get_list = {
16921 	.f = cmd_ddp_get_list_parsed,
16922 	.data = NULL,
16923 	.help_str = "ddp get list <port_id>",
16924 	.tokens = {
16925 		(void *)&cmd_ddp_get_list_ddp,
16926 		(void *)&cmd_ddp_get_list_get,
16927 		(void *)&cmd_ddp_get_list_list,
16928 		(void *)&cmd_ddp_get_list_port_id,
16929 		NULL,
16930 	},
16931 };
16932 
16933 /* Configure input set */
16934 struct cmd_cfg_input_set_result {
16935 	cmdline_fixed_string_t port;
16936 	cmdline_fixed_string_t cfg;
16937 	portid_t port_id;
16938 	cmdline_fixed_string_t pctype;
16939 	uint8_t pctype_id;
16940 	cmdline_fixed_string_t inset_type;
16941 	cmdline_fixed_string_t opt;
16942 	cmdline_fixed_string_t field;
16943 	uint8_t field_idx;
16944 };
16945 
16946 static void
16947 cmd_cfg_input_set_parsed(
16948 	__rte_unused void *parsed_result,
16949 	__rte_unused struct cmdline *cl,
16950 	__rte_unused void *data)
16951 {
16952 #ifdef RTE_LIBRTE_I40E_PMD
16953 	struct cmd_cfg_input_set_result *res = parsed_result;
16954 	enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16955 	struct rte_pmd_i40e_inset inset;
16956 #endif
16957 	int ret = -ENOTSUP;
16958 
16959 	if (!all_ports_stopped()) {
16960 		printf("Please stop all ports first\n");
16961 		return;
16962 	}
16963 
16964 #ifdef RTE_LIBRTE_I40E_PMD
16965 	if (!strcmp(res->inset_type, "hash_inset"))
16966 		inset_type = INSET_HASH;
16967 	else if (!strcmp(res->inset_type, "fdir_inset"))
16968 		inset_type = INSET_FDIR;
16969 	else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16970 		inset_type = INSET_FDIR_FLX;
16971 	ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16972 				     &inset, inset_type);
16973 	if (ret) {
16974 		printf("Failed to get input set.\n");
16975 		return;
16976 	}
16977 
16978 	if (!strcmp(res->opt, "get")) {
16979 		ret = rte_pmd_i40e_inset_field_get(inset.inset,
16980 						   res->field_idx);
16981 		if (ret)
16982 			printf("Field index %d is enabled.\n", res->field_idx);
16983 		else
16984 			printf("Field index %d is disabled.\n", res->field_idx);
16985 		return;
16986 	} else if (!strcmp(res->opt, "set"))
16987 		ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16988 						   res->field_idx);
16989 	else if (!strcmp(res->opt, "clear"))
16990 		ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16991 						     res->field_idx);
16992 	if (ret) {
16993 		printf("Failed to configure input set field.\n");
16994 		return;
16995 	}
16996 
16997 	ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16998 				     &inset, inset_type);
16999 	if (ret) {
17000 		printf("Failed to set input set.\n");
17001 		return;
17002 	}
17003 #endif
17004 
17005 	if (ret == -ENOTSUP)
17006 		printf("Function not supported\n");
17007 }
17008 
17009 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17010 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17011 				 port, "port");
17012 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17013 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17014 				 cfg, "config");
17015 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17016 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17017 			      port_id, UINT16);
17018 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17019 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17020 				 pctype, "pctype");
17021 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17022 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17023 			      pctype_id, UINT8);
17024 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17025 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17026 				 inset_type,
17027 				 "hash_inset#fdir_inset#fdir_flx_inset");
17028 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17029 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17030 				 opt, "get#set#clear");
17031 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17032 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17033 				 field, "field");
17034 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17035 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17036 			      field_idx, UINT8);
17037 
17038 cmdline_parse_inst_t cmd_cfg_input_set = {
17039 	.f = cmd_cfg_input_set_parsed,
17040 	.data = NULL,
17041 	.help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17042 		    "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17043 	.tokens = {
17044 		(void *)&cmd_cfg_input_set_port,
17045 		(void *)&cmd_cfg_input_set_cfg,
17046 		(void *)&cmd_cfg_input_set_port_id,
17047 		(void *)&cmd_cfg_input_set_pctype,
17048 		(void *)&cmd_cfg_input_set_pctype_id,
17049 		(void *)&cmd_cfg_input_set_inset_type,
17050 		(void *)&cmd_cfg_input_set_opt,
17051 		(void *)&cmd_cfg_input_set_field,
17052 		(void *)&cmd_cfg_input_set_field_idx,
17053 		NULL,
17054 	},
17055 };
17056 
17057 /* Clear input set */
17058 struct cmd_clear_input_set_result {
17059 	cmdline_fixed_string_t port;
17060 	cmdline_fixed_string_t cfg;
17061 	portid_t port_id;
17062 	cmdline_fixed_string_t pctype;
17063 	uint8_t pctype_id;
17064 	cmdline_fixed_string_t inset_type;
17065 	cmdline_fixed_string_t clear;
17066 	cmdline_fixed_string_t all;
17067 };
17068 
17069 static void
17070 cmd_clear_input_set_parsed(
17071 	__rte_unused void *parsed_result,
17072 	__rte_unused struct cmdline *cl,
17073 	__rte_unused void *data)
17074 {
17075 #ifdef RTE_LIBRTE_I40E_PMD
17076 	struct cmd_clear_input_set_result *res = parsed_result;
17077 	enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17078 	struct rte_pmd_i40e_inset inset;
17079 #endif
17080 	int ret = -ENOTSUP;
17081 
17082 	if (!all_ports_stopped()) {
17083 		printf("Please stop all ports first\n");
17084 		return;
17085 	}
17086 
17087 #ifdef RTE_LIBRTE_I40E_PMD
17088 	if (!strcmp(res->inset_type, "hash_inset"))
17089 		inset_type = INSET_HASH;
17090 	else if (!strcmp(res->inset_type, "fdir_inset"))
17091 		inset_type = INSET_FDIR;
17092 	else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17093 		inset_type = INSET_FDIR_FLX;
17094 
17095 	memset(&inset, 0, sizeof(inset));
17096 
17097 	ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17098 				     &inset, inset_type);
17099 	if (ret) {
17100 		printf("Failed to clear input set.\n");
17101 		return;
17102 	}
17103 
17104 #endif
17105 
17106 	if (ret == -ENOTSUP)
17107 		printf("Function not supported\n");
17108 }
17109 
17110 cmdline_parse_token_string_t cmd_clear_input_set_port =
17111 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17112 				 port, "port");
17113 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17114 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17115 				 cfg, "config");
17116 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17117 	TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17118 			      port_id, UINT16);
17119 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17120 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17121 				 pctype, "pctype");
17122 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17123 	TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17124 			      pctype_id, UINT8);
17125 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17126 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17127 				 inset_type,
17128 				 "hash_inset#fdir_inset#fdir_flx_inset");
17129 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17130 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17131 				 clear, "clear");
17132 cmdline_parse_token_string_t cmd_clear_input_set_all =
17133 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17134 				 all, "all");
17135 
17136 cmdline_parse_inst_t cmd_clear_input_set = {
17137 	.f = cmd_clear_input_set_parsed,
17138 	.data = NULL,
17139 	.help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17140 		    "fdir_inset|fdir_flx_inset clear all",
17141 	.tokens = {
17142 		(void *)&cmd_clear_input_set_port,
17143 		(void *)&cmd_clear_input_set_cfg,
17144 		(void *)&cmd_clear_input_set_port_id,
17145 		(void *)&cmd_clear_input_set_pctype,
17146 		(void *)&cmd_clear_input_set_pctype_id,
17147 		(void *)&cmd_clear_input_set_inset_type,
17148 		(void *)&cmd_clear_input_set_clear,
17149 		(void *)&cmd_clear_input_set_all,
17150 		NULL,
17151 	},
17152 };
17153 
17154 /* show vf stats */
17155 
17156 /* Common result structure for show vf stats */
17157 struct cmd_show_vf_stats_result {
17158 	cmdline_fixed_string_t show;
17159 	cmdline_fixed_string_t vf;
17160 	cmdline_fixed_string_t stats;
17161 	portid_t port_id;
17162 	uint16_t vf_id;
17163 };
17164 
17165 /* Common CLI fields show vf stats*/
17166 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17167 	TOKEN_STRING_INITIALIZER
17168 		(struct cmd_show_vf_stats_result,
17169 		 show, "show");
17170 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17171 	TOKEN_STRING_INITIALIZER
17172 		(struct cmd_show_vf_stats_result,
17173 		 vf, "vf");
17174 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17175 	TOKEN_STRING_INITIALIZER
17176 		(struct cmd_show_vf_stats_result,
17177 		 stats, "stats");
17178 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17179 	TOKEN_NUM_INITIALIZER
17180 		(struct cmd_show_vf_stats_result,
17181 		 port_id, UINT16);
17182 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17183 	TOKEN_NUM_INITIALIZER
17184 		(struct cmd_show_vf_stats_result,
17185 		 vf_id, UINT16);
17186 
17187 static void
17188 cmd_show_vf_stats_parsed(
17189 	void *parsed_result,
17190 	__rte_unused struct cmdline *cl,
17191 	__rte_unused void *data)
17192 {
17193 	struct cmd_show_vf_stats_result *res = parsed_result;
17194 	struct rte_eth_stats stats;
17195 	int ret = -ENOTSUP;
17196 	static const char *nic_stats_border = "########################";
17197 
17198 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17199 		return;
17200 
17201 	memset(&stats, 0, sizeof(stats));
17202 
17203 #ifdef RTE_LIBRTE_I40E_PMD
17204 	if (ret == -ENOTSUP)
17205 		ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17206 						res->vf_id,
17207 						&stats);
17208 #endif
17209 #ifdef RTE_LIBRTE_BNXT_PMD
17210 	if (ret == -ENOTSUP)
17211 		ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17212 						res->vf_id,
17213 						&stats);
17214 #endif
17215 
17216 	switch (ret) {
17217 	case 0:
17218 		break;
17219 	case -EINVAL:
17220 		printf("invalid vf_id %d\n", res->vf_id);
17221 		break;
17222 	case -ENODEV:
17223 		printf("invalid port_id %d\n", res->port_id);
17224 		break;
17225 	case -ENOTSUP:
17226 		printf("function not implemented\n");
17227 		break;
17228 	default:
17229 		printf("programming error: (%s)\n", strerror(-ret));
17230 	}
17231 
17232 	printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17233 		nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17234 
17235 	printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17236 	       "%-"PRIu64"\n",
17237 	       stats.ipackets, stats.imissed, stats.ibytes);
17238 	printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17239 	printf("  RX-nombuf:  %-10"PRIu64"\n",
17240 	       stats.rx_nombuf);
17241 	printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17242 	       "%-"PRIu64"\n",
17243 	       stats.opackets, stats.oerrors, stats.obytes);
17244 
17245 	printf("  %s############################%s\n",
17246 			       nic_stats_border, nic_stats_border);
17247 }
17248 
17249 cmdline_parse_inst_t cmd_show_vf_stats = {
17250 	.f = cmd_show_vf_stats_parsed,
17251 	.data = NULL,
17252 	.help_str = "show vf stats <port_id> <vf_id>",
17253 	.tokens = {
17254 		(void *)&cmd_show_vf_stats_show,
17255 		(void *)&cmd_show_vf_stats_vf,
17256 		(void *)&cmd_show_vf_stats_stats,
17257 		(void *)&cmd_show_vf_stats_port_id,
17258 		(void *)&cmd_show_vf_stats_vf_id,
17259 		NULL,
17260 	},
17261 };
17262 
17263 /* clear vf stats */
17264 
17265 /* Common result structure for clear vf stats */
17266 struct cmd_clear_vf_stats_result {
17267 	cmdline_fixed_string_t clear;
17268 	cmdline_fixed_string_t vf;
17269 	cmdline_fixed_string_t stats;
17270 	portid_t port_id;
17271 	uint16_t vf_id;
17272 };
17273 
17274 /* Common CLI fields clear vf stats*/
17275 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17276 	TOKEN_STRING_INITIALIZER
17277 		(struct cmd_clear_vf_stats_result,
17278 		 clear, "clear");
17279 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17280 	TOKEN_STRING_INITIALIZER
17281 		(struct cmd_clear_vf_stats_result,
17282 		 vf, "vf");
17283 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17284 	TOKEN_STRING_INITIALIZER
17285 		(struct cmd_clear_vf_stats_result,
17286 		 stats, "stats");
17287 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17288 	TOKEN_NUM_INITIALIZER
17289 		(struct cmd_clear_vf_stats_result,
17290 		 port_id, UINT16);
17291 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17292 	TOKEN_NUM_INITIALIZER
17293 		(struct cmd_clear_vf_stats_result,
17294 		 vf_id, UINT16);
17295 
17296 static void
17297 cmd_clear_vf_stats_parsed(
17298 	void *parsed_result,
17299 	__rte_unused struct cmdline *cl,
17300 	__rte_unused void *data)
17301 {
17302 	struct cmd_clear_vf_stats_result *res = parsed_result;
17303 	int ret = -ENOTSUP;
17304 
17305 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17306 		return;
17307 
17308 #ifdef RTE_LIBRTE_I40E_PMD
17309 	if (ret == -ENOTSUP)
17310 		ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17311 						  res->vf_id);
17312 #endif
17313 #ifdef RTE_LIBRTE_BNXT_PMD
17314 	if (ret == -ENOTSUP)
17315 		ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17316 						  res->vf_id);
17317 #endif
17318 
17319 	switch (ret) {
17320 	case 0:
17321 		break;
17322 	case -EINVAL:
17323 		printf("invalid vf_id %d\n", res->vf_id);
17324 		break;
17325 	case -ENODEV:
17326 		printf("invalid port_id %d\n", res->port_id);
17327 		break;
17328 	case -ENOTSUP:
17329 		printf("function not implemented\n");
17330 		break;
17331 	default:
17332 		printf("programming error: (%s)\n", strerror(-ret));
17333 	}
17334 }
17335 
17336 cmdline_parse_inst_t cmd_clear_vf_stats = {
17337 	.f = cmd_clear_vf_stats_parsed,
17338 	.data = NULL,
17339 	.help_str = "clear vf stats <port_id> <vf_id>",
17340 	.tokens = {
17341 		(void *)&cmd_clear_vf_stats_clear,
17342 		(void *)&cmd_clear_vf_stats_vf,
17343 		(void *)&cmd_clear_vf_stats_stats,
17344 		(void *)&cmd_clear_vf_stats_port_id,
17345 		(void *)&cmd_clear_vf_stats_vf_id,
17346 		NULL,
17347 	},
17348 };
17349 
17350 /* port config pctype mapping reset */
17351 
17352 /* Common result structure for port config pctype mapping reset */
17353 struct cmd_pctype_mapping_reset_result {
17354 	cmdline_fixed_string_t port;
17355 	cmdline_fixed_string_t config;
17356 	portid_t port_id;
17357 	cmdline_fixed_string_t pctype;
17358 	cmdline_fixed_string_t mapping;
17359 	cmdline_fixed_string_t reset;
17360 };
17361 
17362 /* Common CLI fields for port config pctype mapping reset*/
17363 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17364 	TOKEN_STRING_INITIALIZER
17365 		(struct cmd_pctype_mapping_reset_result,
17366 		 port, "port");
17367 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17368 	TOKEN_STRING_INITIALIZER
17369 		(struct cmd_pctype_mapping_reset_result,
17370 		 config, "config");
17371 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17372 	TOKEN_NUM_INITIALIZER
17373 		(struct cmd_pctype_mapping_reset_result,
17374 		 port_id, UINT16);
17375 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17376 	TOKEN_STRING_INITIALIZER
17377 		(struct cmd_pctype_mapping_reset_result,
17378 		 pctype, "pctype");
17379 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17380 	TOKEN_STRING_INITIALIZER
17381 		(struct cmd_pctype_mapping_reset_result,
17382 		 mapping, "mapping");
17383 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17384 	TOKEN_STRING_INITIALIZER
17385 		(struct cmd_pctype_mapping_reset_result,
17386 		 reset, "reset");
17387 
17388 static void
17389 cmd_pctype_mapping_reset_parsed(
17390 	void *parsed_result,
17391 	__rte_unused struct cmdline *cl,
17392 	__rte_unused void *data)
17393 {
17394 	struct cmd_pctype_mapping_reset_result *res = parsed_result;
17395 	int ret = -ENOTSUP;
17396 
17397 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17398 		return;
17399 
17400 #ifdef RTE_LIBRTE_I40E_PMD
17401 	ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17402 #endif
17403 
17404 	switch (ret) {
17405 	case 0:
17406 		break;
17407 	case -ENODEV:
17408 		printf("invalid port_id %d\n", res->port_id);
17409 		break;
17410 	case -ENOTSUP:
17411 		printf("function not implemented\n");
17412 		break;
17413 	default:
17414 		printf("programming error: (%s)\n", strerror(-ret));
17415 	}
17416 }
17417 
17418 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17419 	.f = cmd_pctype_mapping_reset_parsed,
17420 	.data = NULL,
17421 	.help_str = "port config <port_id> pctype mapping reset",
17422 	.tokens = {
17423 		(void *)&cmd_pctype_mapping_reset_port,
17424 		(void *)&cmd_pctype_mapping_reset_config,
17425 		(void *)&cmd_pctype_mapping_reset_port_id,
17426 		(void *)&cmd_pctype_mapping_reset_pctype,
17427 		(void *)&cmd_pctype_mapping_reset_mapping,
17428 		(void *)&cmd_pctype_mapping_reset_reset,
17429 		NULL,
17430 	},
17431 };
17432 
17433 /* show port pctype mapping */
17434 
17435 /* Common result structure for show port pctype mapping */
17436 struct cmd_pctype_mapping_get_result {
17437 	cmdline_fixed_string_t show;
17438 	cmdline_fixed_string_t port;
17439 	portid_t port_id;
17440 	cmdline_fixed_string_t pctype;
17441 	cmdline_fixed_string_t mapping;
17442 };
17443 
17444 /* Common CLI fields for pctype mapping get */
17445 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17446 	TOKEN_STRING_INITIALIZER
17447 		(struct cmd_pctype_mapping_get_result,
17448 		 show, "show");
17449 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17450 	TOKEN_STRING_INITIALIZER
17451 		(struct cmd_pctype_mapping_get_result,
17452 		 port, "port");
17453 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17454 	TOKEN_NUM_INITIALIZER
17455 		(struct cmd_pctype_mapping_get_result,
17456 		 port_id, UINT16);
17457 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17458 	TOKEN_STRING_INITIALIZER
17459 		(struct cmd_pctype_mapping_get_result,
17460 		 pctype, "pctype");
17461 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17462 	TOKEN_STRING_INITIALIZER
17463 		(struct cmd_pctype_mapping_get_result,
17464 		 mapping, "mapping");
17465 
17466 static void
17467 cmd_pctype_mapping_get_parsed(
17468 	void *parsed_result,
17469 	__rte_unused struct cmdline *cl,
17470 	__rte_unused void *data)
17471 {
17472 	struct cmd_pctype_mapping_get_result *res = parsed_result;
17473 	int ret = -ENOTSUP;
17474 #ifdef RTE_LIBRTE_I40E_PMD
17475 	struct rte_pmd_i40e_flow_type_mapping
17476 				mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17477 	int i, j, first_pctype;
17478 #endif
17479 
17480 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17481 		return;
17482 
17483 #ifdef RTE_LIBRTE_I40E_PMD
17484 	ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17485 #endif
17486 
17487 	switch (ret) {
17488 	case 0:
17489 		break;
17490 	case -ENODEV:
17491 		printf("invalid port_id %d\n", res->port_id);
17492 		return;
17493 	case -ENOTSUP:
17494 		printf("function not implemented\n");
17495 		return;
17496 	default:
17497 		printf("programming error: (%s)\n", strerror(-ret));
17498 		return;
17499 	}
17500 
17501 #ifdef RTE_LIBRTE_I40E_PMD
17502 	for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17503 		if (mapping[i].pctype != 0ULL) {
17504 			first_pctype = 1;
17505 
17506 			printf("pctype: ");
17507 			for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17508 				if (mapping[i].pctype & (1ULL << j)) {
17509 					printf(first_pctype ?
17510 					       "%02d" : ",%02d", j);
17511 					first_pctype = 0;
17512 				}
17513 			}
17514 			printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17515 		}
17516 	}
17517 #endif
17518 }
17519 
17520 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17521 	.f = cmd_pctype_mapping_get_parsed,
17522 	.data = NULL,
17523 	.help_str = "show port <port_id> pctype mapping",
17524 	.tokens = {
17525 		(void *)&cmd_pctype_mapping_get_show,
17526 		(void *)&cmd_pctype_mapping_get_port,
17527 		(void *)&cmd_pctype_mapping_get_port_id,
17528 		(void *)&cmd_pctype_mapping_get_pctype,
17529 		(void *)&cmd_pctype_mapping_get_mapping,
17530 		NULL,
17531 	},
17532 };
17533 
17534 /* port config pctype mapping update */
17535 
17536 /* Common result structure for port config pctype mapping update */
17537 struct cmd_pctype_mapping_update_result {
17538 	cmdline_fixed_string_t port;
17539 	cmdline_fixed_string_t config;
17540 	portid_t port_id;
17541 	cmdline_fixed_string_t pctype;
17542 	cmdline_fixed_string_t mapping;
17543 	cmdline_fixed_string_t update;
17544 	cmdline_fixed_string_t pctype_list;
17545 	uint16_t flow_type;
17546 };
17547 
17548 /* Common CLI fields for pctype mapping update*/
17549 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17550 	TOKEN_STRING_INITIALIZER
17551 		(struct cmd_pctype_mapping_update_result,
17552 		 port, "port");
17553 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17554 	TOKEN_STRING_INITIALIZER
17555 		(struct cmd_pctype_mapping_update_result,
17556 		 config, "config");
17557 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17558 	TOKEN_NUM_INITIALIZER
17559 		(struct cmd_pctype_mapping_update_result,
17560 		 port_id, UINT16);
17561 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17562 	TOKEN_STRING_INITIALIZER
17563 		(struct cmd_pctype_mapping_update_result,
17564 		 pctype, "pctype");
17565 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17566 	TOKEN_STRING_INITIALIZER
17567 		(struct cmd_pctype_mapping_update_result,
17568 		 mapping, "mapping");
17569 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17570 	TOKEN_STRING_INITIALIZER
17571 		(struct cmd_pctype_mapping_update_result,
17572 		 update, "update");
17573 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17574 	TOKEN_STRING_INITIALIZER
17575 		(struct cmd_pctype_mapping_update_result,
17576 		 pctype_list, NULL);
17577 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17578 	TOKEN_NUM_INITIALIZER
17579 		(struct cmd_pctype_mapping_update_result,
17580 		 flow_type, UINT16);
17581 
17582 static void
17583 cmd_pctype_mapping_update_parsed(
17584 	void *parsed_result,
17585 	__rte_unused struct cmdline *cl,
17586 	__rte_unused void *data)
17587 {
17588 	struct cmd_pctype_mapping_update_result *res = parsed_result;
17589 	int ret = -ENOTSUP;
17590 #ifdef RTE_LIBRTE_I40E_PMD
17591 	struct rte_pmd_i40e_flow_type_mapping mapping;
17592 	unsigned int i;
17593 	unsigned int nb_item;
17594 	unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17595 #endif
17596 
17597 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17598 		return;
17599 
17600 #ifdef RTE_LIBRTE_I40E_PMD
17601 	nb_item = parse_item_list(res->pctype_list, "pctypes",
17602 				  RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17603 	mapping.flow_type = res->flow_type;
17604 	for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17605 		mapping.pctype |= (1ULL << pctype_list[i]);
17606 	ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17607 						&mapping,
17608 						1,
17609 						0);
17610 #endif
17611 
17612 	switch (ret) {
17613 	case 0:
17614 		break;
17615 	case -EINVAL:
17616 		printf("invalid pctype or flow type\n");
17617 		break;
17618 	case -ENODEV:
17619 		printf("invalid port_id %d\n", res->port_id);
17620 		break;
17621 	case -ENOTSUP:
17622 		printf("function not implemented\n");
17623 		break;
17624 	default:
17625 		printf("programming error: (%s)\n", strerror(-ret));
17626 	}
17627 }
17628 
17629 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17630 	.f = cmd_pctype_mapping_update_parsed,
17631 	.data = NULL,
17632 	.help_str = "port config <port_id> pctype mapping update"
17633 	" <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17634 	.tokens = {
17635 		(void *)&cmd_pctype_mapping_update_port,
17636 		(void *)&cmd_pctype_mapping_update_config,
17637 		(void *)&cmd_pctype_mapping_update_port_id,
17638 		(void *)&cmd_pctype_mapping_update_pctype,
17639 		(void *)&cmd_pctype_mapping_update_mapping,
17640 		(void *)&cmd_pctype_mapping_update_update,
17641 		(void *)&cmd_pctype_mapping_update_pc_type,
17642 		(void *)&cmd_pctype_mapping_update_flow_type,
17643 		NULL,
17644 	},
17645 };
17646 
17647 /* ptype mapping get */
17648 
17649 /* Common result structure for ptype mapping get */
17650 struct cmd_ptype_mapping_get_result {
17651 	cmdline_fixed_string_t ptype;
17652 	cmdline_fixed_string_t mapping;
17653 	cmdline_fixed_string_t get;
17654 	portid_t port_id;
17655 	uint8_t valid_only;
17656 };
17657 
17658 /* Common CLI fields for ptype mapping get */
17659 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17660 	TOKEN_STRING_INITIALIZER
17661 		(struct cmd_ptype_mapping_get_result,
17662 		 ptype, "ptype");
17663 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17664 	TOKEN_STRING_INITIALIZER
17665 		(struct cmd_ptype_mapping_get_result,
17666 		 mapping, "mapping");
17667 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17668 	TOKEN_STRING_INITIALIZER
17669 		(struct cmd_ptype_mapping_get_result,
17670 		 get, "get");
17671 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17672 	TOKEN_NUM_INITIALIZER
17673 		(struct cmd_ptype_mapping_get_result,
17674 		 port_id, UINT16);
17675 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17676 	TOKEN_NUM_INITIALIZER
17677 		(struct cmd_ptype_mapping_get_result,
17678 		 valid_only, UINT8);
17679 
17680 static void
17681 cmd_ptype_mapping_get_parsed(
17682 	void *parsed_result,
17683 	__rte_unused struct cmdline *cl,
17684 	__rte_unused void *data)
17685 {
17686 	struct cmd_ptype_mapping_get_result *res = parsed_result;
17687 	int ret = -ENOTSUP;
17688 #ifdef RTE_LIBRTE_I40E_PMD
17689 	int max_ptype_num = 256;
17690 	struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17691 	uint16_t count;
17692 	int i;
17693 #endif
17694 
17695 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17696 		return;
17697 
17698 #ifdef RTE_LIBRTE_I40E_PMD
17699 	ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17700 					mapping,
17701 					max_ptype_num,
17702 					&count,
17703 					res->valid_only);
17704 #endif
17705 
17706 	switch (ret) {
17707 	case 0:
17708 		break;
17709 	case -ENODEV:
17710 		printf("invalid port_id %d\n", res->port_id);
17711 		break;
17712 	case -ENOTSUP:
17713 		printf("function not implemented\n");
17714 		break;
17715 	default:
17716 		printf("programming error: (%s)\n", strerror(-ret));
17717 	}
17718 
17719 #ifdef RTE_LIBRTE_I40E_PMD
17720 	if (!ret) {
17721 		for (i = 0; i < count; i++)
17722 			printf("%3d\t0x%08x\n",
17723 				mapping[i].hw_ptype, mapping[i].sw_ptype);
17724 	}
17725 #endif
17726 }
17727 
17728 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17729 	.f = cmd_ptype_mapping_get_parsed,
17730 	.data = NULL,
17731 	.help_str = "ptype mapping get <port_id> <valid_only>",
17732 	.tokens = {
17733 		(void *)&cmd_ptype_mapping_get_ptype,
17734 		(void *)&cmd_ptype_mapping_get_mapping,
17735 		(void *)&cmd_ptype_mapping_get_get,
17736 		(void *)&cmd_ptype_mapping_get_port_id,
17737 		(void *)&cmd_ptype_mapping_get_valid_only,
17738 		NULL,
17739 	},
17740 };
17741 
17742 /* ptype mapping replace */
17743 
17744 /* Common result structure for ptype mapping replace */
17745 struct cmd_ptype_mapping_replace_result {
17746 	cmdline_fixed_string_t ptype;
17747 	cmdline_fixed_string_t mapping;
17748 	cmdline_fixed_string_t replace;
17749 	portid_t port_id;
17750 	uint32_t target;
17751 	uint8_t mask;
17752 	uint32_t pkt_type;
17753 };
17754 
17755 /* Common CLI fields for ptype mapping replace */
17756 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17757 	TOKEN_STRING_INITIALIZER
17758 		(struct cmd_ptype_mapping_replace_result,
17759 		 ptype, "ptype");
17760 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17761 	TOKEN_STRING_INITIALIZER
17762 		(struct cmd_ptype_mapping_replace_result,
17763 		 mapping, "mapping");
17764 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17765 	TOKEN_STRING_INITIALIZER
17766 		(struct cmd_ptype_mapping_replace_result,
17767 		 replace, "replace");
17768 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17769 	TOKEN_NUM_INITIALIZER
17770 		(struct cmd_ptype_mapping_replace_result,
17771 		 port_id, UINT16);
17772 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17773 	TOKEN_NUM_INITIALIZER
17774 		(struct cmd_ptype_mapping_replace_result,
17775 		 target, UINT32);
17776 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17777 	TOKEN_NUM_INITIALIZER
17778 		(struct cmd_ptype_mapping_replace_result,
17779 		 mask, UINT8);
17780 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17781 	TOKEN_NUM_INITIALIZER
17782 		(struct cmd_ptype_mapping_replace_result,
17783 		 pkt_type, UINT32);
17784 
17785 static void
17786 cmd_ptype_mapping_replace_parsed(
17787 	void *parsed_result,
17788 	__rte_unused struct cmdline *cl,
17789 	__rte_unused void *data)
17790 {
17791 	struct cmd_ptype_mapping_replace_result *res = parsed_result;
17792 	int ret = -ENOTSUP;
17793 
17794 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17795 		return;
17796 
17797 #ifdef RTE_LIBRTE_I40E_PMD
17798 	ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17799 					res->target,
17800 					res->mask,
17801 					res->pkt_type);
17802 #endif
17803 
17804 	switch (ret) {
17805 	case 0:
17806 		break;
17807 	case -EINVAL:
17808 		printf("invalid ptype 0x%8x or 0x%8x\n",
17809 				res->target, res->pkt_type);
17810 		break;
17811 	case -ENODEV:
17812 		printf("invalid port_id %d\n", res->port_id);
17813 		break;
17814 	case -ENOTSUP:
17815 		printf("function not implemented\n");
17816 		break;
17817 	default:
17818 		printf("programming error: (%s)\n", strerror(-ret));
17819 	}
17820 }
17821 
17822 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17823 	.f = cmd_ptype_mapping_replace_parsed,
17824 	.data = NULL,
17825 	.help_str =
17826 		"ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17827 	.tokens = {
17828 		(void *)&cmd_ptype_mapping_replace_ptype,
17829 		(void *)&cmd_ptype_mapping_replace_mapping,
17830 		(void *)&cmd_ptype_mapping_replace_replace,
17831 		(void *)&cmd_ptype_mapping_replace_port_id,
17832 		(void *)&cmd_ptype_mapping_replace_target,
17833 		(void *)&cmd_ptype_mapping_replace_mask,
17834 		(void *)&cmd_ptype_mapping_replace_pkt_type,
17835 		NULL,
17836 	},
17837 };
17838 
17839 /* ptype mapping reset */
17840 
17841 /* Common result structure for ptype mapping reset */
17842 struct cmd_ptype_mapping_reset_result {
17843 	cmdline_fixed_string_t ptype;
17844 	cmdline_fixed_string_t mapping;
17845 	cmdline_fixed_string_t reset;
17846 	portid_t port_id;
17847 };
17848 
17849 /* Common CLI fields for ptype mapping reset*/
17850 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17851 	TOKEN_STRING_INITIALIZER
17852 		(struct cmd_ptype_mapping_reset_result,
17853 		 ptype, "ptype");
17854 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17855 	TOKEN_STRING_INITIALIZER
17856 		(struct cmd_ptype_mapping_reset_result,
17857 		 mapping, "mapping");
17858 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17859 	TOKEN_STRING_INITIALIZER
17860 		(struct cmd_ptype_mapping_reset_result,
17861 		 reset, "reset");
17862 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17863 	TOKEN_NUM_INITIALIZER
17864 		(struct cmd_ptype_mapping_reset_result,
17865 		 port_id, UINT16);
17866 
17867 static void
17868 cmd_ptype_mapping_reset_parsed(
17869 	void *parsed_result,
17870 	__rte_unused struct cmdline *cl,
17871 	__rte_unused void *data)
17872 {
17873 	struct cmd_ptype_mapping_reset_result *res = parsed_result;
17874 	int ret = -ENOTSUP;
17875 
17876 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17877 		return;
17878 
17879 #ifdef RTE_LIBRTE_I40E_PMD
17880 	ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17881 #endif
17882 
17883 	switch (ret) {
17884 	case 0:
17885 		break;
17886 	case -ENODEV:
17887 		printf("invalid port_id %d\n", res->port_id);
17888 		break;
17889 	case -ENOTSUP:
17890 		printf("function not implemented\n");
17891 		break;
17892 	default:
17893 		printf("programming error: (%s)\n", strerror(-ret));
17894 	}
17895 }
17896 
17897 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17898 	.f = cmd_ptype_mapping_reset_parsed,
17899 	.data = NULL,
17900 	.help_str = "ptype mapping reset <port_id>",
17901 	.tokens = {
17902 		(void *)&cmd_ptype_mapping_reset_ptype,
17903 		(void *)&cmd_ptype_mapping_reset_mapping,
17904 		(void *)&cmd_ptype_mapping_reset_reset,
17905 		(void *)&cmd_ptype_mapping_reset_port_id,
17906 		NULL,
17907 	},
17908 };
17909 
17910 /* ptype mapping update */
17911 
17912 /* Common result structure for ptype mapping update */
17913 struct cmd_ptype_mapping_update_result {
17914 	cmdline_fixed_string_t ptype;
17915 	cmdline_fixed_string_t mapping;
17916 	cmdline_fixed_string_t reset;
17917 	portid_t port_id;
17918 	uint8_t hw_ptype;
17919 	uint32_t sw_ptype;
17920 };
17921 
17922 /* Common CLI fields for ptype mapping update*/
17923 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17924 	TOKEN_STRING_INITIALIZER
17925 		(struct cmd_ptype_mapping_update_result,
17926 		 ptype, "ptype");
17927 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17928 	TOKEN_STRING_INITIALIZER
17929 		(struct cmd_ptype_mapping_update_result,
17930 		 mapping, "mapping");
17931 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17932 	TOKEN_STRING_INITIALIZER
17933 		(struct cmd_ptype_mapping_update_result,
17934 		 reset, "update");
17935 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17936 	TOKEN_NUM_INITIALIZER
17937 		(struct cmd_ptype_mapping_update_result,
17938 		 port_id, UINT16);
17939 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17940 	TOKEN_NUM_INITIALIZER
17941 		(struct cmd_ptype_mapping_update_result,
17942 		 hw_ptype, UINT8);
17943 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17944 	TOKEN_NUM_INITIALIZER
17945 		(struct cmd_ptype_mapping_update_result,
17946 		 sw_ptype, UINT32);
17947 
17948 static void
17949 cmd_ptype_mapping_update_parsed(
17950 	void *parsed_result,
17951 	__rte_unused struct cmdline *cl,
17952 	__rte_unused void *data)
17953 {
17954 	struct cmd_ptype_mapping_update_result *res = parsed_result;
17955 	int ret = -ENOTSUP;
17956 #ifdef RTE_LIBRTE_I40E_PMD
17957 	struct rte_pmd_i40e_ptype_mapping mapping;
17958 #endif
17959 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17960 		return;
17961 
17962 #ifdef RTE_LIBRTE_I40E_PMD
17963 	mapping.hw_ptype = res->hw_ptype;
17964 	mapping.sw_ptype = res->sw_ptype;
17965 	ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17966 						&mapping,
17967 						1,
17968 						0);
17969 #endif
17970 
17971 	switch (ret) {
17972 	case 0:
17973 		break;
17974 	case -EINVAL:
17975 		printf("invalid ptype 0x%8x\n", res->sw_ptype);
17976 		break;
17977 	case -ENODEV:
17978 		printf("invalid port_id %d\n", res->port_id);
17979 		break;
17980 	case -ENOTSUP:
17981 		printf("function not implemented\n");
17982 		break;
17983 	default:
17984 		printf("programming error: (%s)\n", strerror(-ret));
17985 	}
17986 }
17987 
17988 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17989 	.f = cmd_ptype_mapping_update_parsed,
17990 	.data = NULL,
17991 	.help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17992 	.tokens = {
17993 		(void *)&cmd_ptype_mapping_update_ptype,
17994 		(void *)&cmd_ptype_mapping_update_mapping,
17995 		(void *)&cmd_ptype_mapping_update_update,
17996 		(void *)&cmd_ptype_mapping_update_port_id,
17997 		(void *)&cmd_ptype_mapping_update_hw_ptype,
17998 		(void *)&cmd_ptype_mapping_update_sw_ptype,
17999 		NULL,
18000 	},
18001 };
18002 
18003 /* Common result structure for file commands */
18004 struct cmd_cmdfile_result {
18005 	cmdline_fixed_string_t load;
18006 	cmdline_fixed_string_t filename;
18007 };
18008 
18009 /* Common CLI fields for file commands */
18010 cmdline_parse_token_string_t cmd_load_cmdfile =
18011 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18012 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18013 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18014 
18015 static void
18016 cmd_load_from_file_parsed(
18017 	void *parsed_result,
18018 	__rte_unused struct cmdline *cl,
18019 	__rte_unused void *data)
18020 {
18021 	struct cmd_cmdfile_result *res = parsed_result;
18022 
18023 	cmdline_read_from_file(res->filename);
18024 }
18025 
18026 cmdline_parse_inst_t cmd_load_from_file = {
18027 	.f = cmd_load_from_file_parsed,
18028 	.data = NULL,
18029 	.help_str = "load <filename>",
18030 	.tokens = {
18031 		(void *)&cmd_load_cmdfile,
18032 		(void *)&cmd_load_cmdfile_filename,
18033 		NULL,
18034 	},
18035 };
18036 
18037 /* Get Rx offloads capabilities */
18038 struct cmd_rx_offload_get_capa_result {
18039 	cmdline_fixed_string_t show;
18040 	cmdline_fixed_string_t port;
18041 	portid_t port_id;
18042 	cmdline_fixed_string_t rx_offload;
18043 	cmdline_fixed_string_t capabilities;
18044 };
18045 
18046 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18047 	TOKEN_STRING_INITIALIZER
18048 		(struct cmd_rx_offload_get_capa_result,
18049 		 show, "show");
18050 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18051 	TOKEN_STRING_INITIALIZER
18052 		(struct cmd_rx_offload_get_capa_result,
18053 		 port, "port");
18054 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18055 	TOKEN_NUM_INITIALIZER
18056 		(struct cmd_rx_offload_get_capa_result,
18057 		 port_id, UINT16);
18058 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18059 	TOKEN_STRING_INITIALIZER
18060 		(struct cmd_rx_offload_get_capa_result,
18061 		 rx_offload, "rx_offload");
18062 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18063 	TOKEN_STRING_INITIALIZER
18064 		(struct cmd_rx_offload_get_capa_result,
18065 		 capabilities, "capabilities");
18066 
18067 static void
18068 print_rx_offloads(uint64_t offloads)
18069 {
18070 	uint64_t single_offload;
18071 	int begin;
18072 	int end;
18073 	int bit;
18074 
18075 	if (offloads == 0)
18076 		return;
18077 
18078 	begin = __builtin_ctzll(offloads);
18079 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18080 
18081 	single_offload = 1ULL << begin;
18082 	for (bit = begin; bit < end; bit++) {
18083 		if (offloads & single_offload)
18084 			printf(" %s",
18085 			       rte_eth_dev_rx_offload_name(single_offload));
18086 		single_offload <<= 1;
18087 	}
18088 }
18089 
18090 static void
18091 cmd_rx_offload_get_capa_parsed(
18092 	void *parsed_result,
18093 	__rte_unused struct cmdline *cl,
18094 	__rte_unused void *data)
18095 {
18096 	struct cmd_rx_offload_get_capa_result *res = parsed_result;
18097 	struct rte_eth_dev_info dev_info;
18098 	portid_t port_id = res->port_id;
18099 	uint64_t queue_offloads;
18100 	uint64_t port_offloads;
18101 	int ret;
18102 
18103 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18104 	if (ret != 0)
18105 		return;
18106 
18107 	queue_offloads = dev_info.rx_queue_offload_capa;
18108 	port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18109 
18110 	printf("Rx Offloading Capabilities of port %d :\n", port_id);
18111 	printf("  Per Queue :");
18112 	print_rx_offloads(queue_offloads);
18113 
18114 	printf("\n");
18115 	printf("  Per Port  :");
18116 	print_rx_offloads(port_offloads);
18117 	printf("\n\n");
18118 }
18119 
18120 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18121 	.f = cmd_rx_offload_get_capa_parsed,
18122 	.data = NULL,
18123 	.help_str = "show port <port_id> rx_offload capabilities",
18124 	.tokens = {
18125 		(void *)&cmd_rx_offload_get_capa_show,
18126 		(void *)&cmd_rx_offload_get_capa_port,
18127 		(void *)&cmd_rx_offload_get_capa_port_id,
18128 		(void *)&cmd_rx_offload_get_capa_rx_offload,
18129 		(void *)&cmd_rx_offload_get_capa_capabilities,
18130 		NULL,
18131 	}
18132 };
18133 
18134 /* Get Rx offloads configuration */
18135 struct cmd_rx_offload_get_configuration_result {
18136 	cmdline_fixed_string_t show;
18137 	cmdline_fixed_string_t port;
18138 	portid_t port_id;
18139 	cmdline_fixed_string_t rx_offload;
18140 	cmdline_fixed_string_t configuration;
18141 };
18142 
18143 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18144 	TOKEN_STRING_INITIALIZER
18145 		(struct cmd_rx_offload_get_configuration_result,
18146 		 show, "show");
18147 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18148 	TOKEN_STRING_INITIALIZER
18149 		(struct cmd_rx_offload_get_configuration_result,
18150 		 port, "port");
18151 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18152 	TOKEN_NUM_INITIALIZER
18153 		(struct cmd_rx_offload_get_configuration_result,
18154 		 port_id, UINT16);
18155 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18156 	TOKEN_STRING_INITIALIZER
18157 		(struct cmd_rx_offload_get_configuration_result,
18158 		 rx_offload, "rx_offload");
18159 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18160 	TOKEN_STRING_INITIALIZER
18161 		(struct cmd_rx_offload_get_configuration_result,
18162 		 configuration, "configuration");
18163 
18164 static void
18165 cmd_rx_offload_get_configuration_parsed(
18166 	void *parsed_result,
18167 	__rte_unused struct cmdline *cl,
18168 	__rte_unused void *data)
18169 {
18170 	struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18171 	struct rte_eth_dev_info dev_info;
18172 	portid_t port_id = res->port_id;
18173 	struct rte_port *port = &ports[port_id];
18174 	uint64_t port_offloads;
18175 	uint64_t queue_offloads;
18176 	uint16_t nb_rx_queues;
18177 	int q;
18178 	int ret;
18179 
18180 	printf("Rx Offloading Configuration of port %d :\n", port_id);
18181 
18182 	port_offloads = port->dev_conf.rxmode.offloads;
18183 	printf("  Port :");
18184 	print_rx_offloads(port_offloads);
18185 	printf("\n");
18186 
18187 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18188 	if (ret != 0)
18189 		return;
18190 
18191 	nb_rx_queues = dev_info.nb_rx_queues;
18192 	for (q = 0; q < nb_rx_queues; q++) {
18193 		queue_offloads = port->rx_conf[q].offloads;
18194 		printf("  Queue[%2d] :", q);
18195 		print_rx_offloads(queue_offloads);
18196 		printf("\n");
18197 	}
18198 	printf("\n");
18199 }
18200 
18201 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18202 	.f = cmd_rx_offload_get_configuration_parsed,
18203 	.data = NULL,
18204 	.help_str = "show port <port_id> rx_offload configuration",
18205 	.tokens = {
18206 		(void *)&cmd_rx_offload_get_configuration_show,
18207 		(void *)&cmd_rx_offload_get_configuration_port,
18208 		(void *)&cmd_rx_offload_get_configuration_port_id,
18209 		(void *)&cmd_rx_offload_get_configuration_rx_offload,
18210 		(void *)&cmd_rx_offload_get_configuration_configuration,
18211 		NULL,
18212 	}
18213 };
18214 
18215 /* Enable/Disable a per port offloading */
18216 struct cmd_config_per_port_rx_offload_result {
18217 	cmdline_fixed_string_t port;
18218 	cmdline_fixed_string_t config;
18219 	portid_t port_id;
18220 	cmdline_fixed_string_t rx_offload;
18221 	cmdline_fixed_string_t offload;
18222 	cmdline_fixed_string_t on_off;
18223 };
18224 
18225 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18226 	TOKEN_STRING_INITIALIZER
18227 		(struct cmd_config_per_port_rx_offload_result,
18228 		 port, "port");
18229 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18230 	TOKEN_STRING_INITIALIZER
18231 		(struct cmd_config_per_port_rx_offload_result,
18232 		 config, "config");
18233 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18234 	TOKEN_NUM_INITIALIZER
18235 		(struct cmd_config_per_port_rx_offload_result,
18236 		 port_id, UINT16);
18237 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18238 	TOKEN_STRING_INITIALIZER
18239 		(struct cmd_config_per_port_rx_offload_result,
18240 		 rx_offload, "rx_offload");
18241 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18242 	TOKEN_STRING_INITIALIZER
18243 		(struct cmd_config_per_port_rx_offload_result,
18244 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18245 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18246 			   "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18247 			   "scatter#timestamp#security#keep_crc#rss_hash");
18248 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18249 	TOKEN_STRING_INITIALIZER
18250 		(struct cmd_config_per_port_rx_offload_result,
18251 		 on_off, "on#off");
18252 
18253 static uint64_t
18254 search_rx_offload(const char *name)
18255 {
18256 	uint64_t single_offload;
18257 	const char *single_name;
18258 	int found = 0;
18259 	unsigned int bit;
18260 
18261 	single_offload = 1;
18262 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18263 		single_name = rte_eth_dev_rx_offload_name(single_offload);
18264 		if (!strcasecmp(single_name, name)) {
18265 			found = 1;
18266 			break;
18267 		}
18268 		single_offload <<= 1;
18269 	}
18270 
18271 	if (found)
18272 		return single_offload;
18273 
18274 	return 0;
18275 }
18276 
18277 static void
18278 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18279 				__rte_unused struct cmdline *cl,
18280 				__rte_unused void *data)
18281 {
18282 	struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18283 	portid_t port_id = res->port_id;
18284 	struct rte_eth_dev_info dev_info;
18285 	struct rte_port *port = &ports[port_id];
18286 	uint64_t single_offload;
18287 	uint16_t nb_rx_queues;
18288 	int q;
18289 	int ret;
18290 
18291 	if (port->port_status != RTE_PORT_STOPPED) {
18292 		printf("Error: Can't config offload when Port %d "
18293 		       "is not stopped\n", port_id);
18294 		return;
18295 	}
18296 
18297 	single_offload = search_rx_offload(res->offload);
18298 	if (single_offload == 0) {
18299 		printf("Unknown offload name: %s\n", res->offload);
18300 		return;
18301 	}
18302 
18303 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18304 	if (ret != 0)
18305 		return;
18306 
18307 	nb_rx_queues = dev_info.nb_rx_queues;
18308 	if (!strcmp(res->on_off, "on")) {
18309 		port->dev_conf.rxmode.offloads |= single_offload;
18310 		for (q = 0; q < nb_rx_queues; q++)
18311 			port->rx_conf[q].offloads |= single_offload;
18312 	} else {
18313 		port->dev_conf.rxmode.offloads &= ~single_offload;
18314 		for (q = 0; q < nb_rx_queues; q++)
18315 			port->rx_conf[q].offloads &= ~single_offload;
18316 	}
18317 
18318 	cmd_reconfig_device_queue(port_id, 1, 1);
18319 }
18320 
18321 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18322 	.f = cmd_config_per_port_rx_offload_parsed,
18323 	.data = NULL,
18324 	.help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18325 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18326 		    "macsec_strip|header_split|vlan_filter|vlan_extend|"
18327 		    "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18328 		    "on|off",
18329 	.tokens = {
18330 		(void *)&cmd_config_per_port_rx_offload_result_port,
18331 		(void *)&cmd_config_per_port_rx_offload_result_config,
18332 		(void *)&cmd_config_per_port_rx_offload_result_port_id,
18333 		(void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18334 		(void *)&cmd_config_per_port_rx_offload_result_offload,
18335 		(void *)&cmd_config_per_port_rx_offload_result_on_off,
18336 		NULL,
18337 	}
18338 };
18339 
18340 /* Enable/Disable a per queue offloading */
18341 struct cmd_config_per_queue_rx_offload_result {
18342 	cmdline_fixed_string_t port;
18343 	portid_t port_id;
18344 	cmdline_fixed_string_t rxq;
18345 	uint16_t queue_id;
18346 	cmdline_fixed_string_t rx_offload;
18347 	cmdline_fixed_string_t offload;
18348 	cmdline_fixed_string_t on_off;
18349 };
18350 
18351 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18352 	TOKEN_STRING_INITIALIZER
18353 		(struct cmd_config_per_queue_rx_offload_result,
18354 		 port, "port");
18355 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18356 	TOKEN_NUM_INITIALIZER
18357 		(struct cmd_config_per_queue_rx_offload_result,
18358 		 port_id, UINT16);
18359 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18360 	TOKEN_STRING_INITIALIZER
18361 		(struct cmd_config_per_queue_rx_offload_result,
18362 		 rxq, "rxq");
18363 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18364 	TOKEN_NUM_INITIALIZER
18365 		(struct cmd_config_per_queue_rx_offload_result,
18366 		 queue_id, UINT16);
18367 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18368 	TOKEN_STRING_INITIALIZER
18369 		(struct cmd_config_per_queue_rx_offload_result,
18370 		 rx_offload, "rx_offload");
18371 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18372 	TOKEN_STRING_INITIALIZER
18373 		(struct cmd_config_per_queue_rx_offload_result,
18374 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18375 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18376 			   "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18377 			   "scatter#timestamp#security#keep_crc");
18378 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18379 	TOKEN_STRING_INITIALIZER
18380 		(struct cmd_config_per_queue_rx_offload_result,
18381 		 on_off, "on#off");
18382 
18383 static void
18384 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18385 				__rte_unused struct cmdline *cl,
18386 				__rte_unused void *data)
18387 {
18388 	struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18389 	struct rte_eth_dev_info dev_info;
18390 	portid_t port_id = res->port_id;
18391 	uint16_t queue_id = res->queue_id;
18392 	struct rte_port *port = &ports[port_id];
18393 	uint64_t single_offload;
18394 	int ret;
18395 
18396 	if (port->port_status != RTE_PORT_STOPPED) {
18397 		printf("Error: Can't config offload when Port %d "
18398 		       "is not stopped\n", port_id);
18399 		return;
18400 	}
18401 
18402 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18403 	if (ret != 0)
18404 		return;
18405 
18406 	if (queue_id >= dev_info.nb_rx_queues) {
18407 		printf("Error: input queue_id should be 0 ... "
18408 		       "%d\n", dev_info.nb_rx_queues - 1);
18409 		return;
18410 	}
18411 
18412 	single_offload = search_rx_offload(res->offload);
18413 	if (single_offload == 0) {
18414 		printf("Unknown offload name: %s\n", res->offload);
18415 		return;
18416 	}
18417 
18418 	if (!strcmp(res->on_off, "on"))
18419 		port->rx_conf[queue_id].offloads |= single_offload;
18420 	else
18421 		port->rx_conf[queue_id].offloads &= ~single_offload;
18422 
18423 	cmd_reconfig_device_queue(port_id, 1, 1);
18424 }
18425 
18426 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18427 	.f = cmd_config_per_queue_rx_offload_parsed,
18428 	.data = NULL,
18429 	.help_str = "port <port_id> rxq <queue_id> rx_offload "
18430 		    "vlan_strip|ipv4_cksum|"
18431 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18432 		    "macsec_strip|header_split|vlan_filter|vlan_extend|"
18433 		    "jumbo_frame|scatter|timestamp|security|keep_crc "
18434 		    "on|off",
18435 	.tokens = {
18436 		(void *)&cmd_config_per_queue_rx_offload_result_port,
18437 		(void *)&cmd_config_per_queue_rx_offload_result_port_id,
18438 		(void *)&cmd_config_per_queue_rx_offload_result_rxq,
18439 		(void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18440 		(void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18441 		(void *)&cmd_config_per_queue_rx_offload_result_offload,
18442 		(void *)&cmd_config_per_queue_rx_offload_result_on_off,
18443 		NULL,
18444 	}
18445 };
18446 
18447 /* Get Tx offloads capabilities */
18448 struct cmd_tx_offload_get_capa_result {
18449 	cmdline_fixed_string_t show;
18450 	cmdline_fixed_string_t port;
18451 	portid_t port_id;
18452 	cmdline_fixed_string_t tx_offload;
18453 	cmdline_fixed_string_t capabilities;
18454 };
18455 
18456 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18457 	TOKEN_STRING_INITIALIZER
18458 		(struct cmd_tx_offload_get_capa_result,
18459 		 show, "show");
18460 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18461 	TOKEN_STRING_INITIALIZER
18462 		(struct cmd_tx_offload_get_capa_result,
18463 		 port, "port");
18464 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18465 	TOKEN_NUM_INITIALIZER
18466 		(struct cmd_tx_offload_get_capa_result,
18467 		 port_id, UINT16);
18468 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18469 	TOKEN_STRING_INITIALIZER
18470 		(struct cmd_tx_offload_get_capa_result,
18471 		 tx_offload, "tx_offload");
18472 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18473 	TOKEN_STRING_INITIALIZER
18474 		(struct cmd_tx_offload_get_capa_result,
18475 		 capabilities, "capabilities");
18476 
18477 static void
18478 print_tx_offloads(uint64_t offloads)
18479 {
18480 	uint64_t single_offload;
18481 	int begin;
18482 	int end;
18483 	int bit;
18484 
18485 	if (offloads == 0)
18486 		return;
18487 
18488 	begin = __builtin_ctzll(offloads);
18489 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18490 
18491 	single_offload = 1ULL << begin;
18492 	for (bit = begin; bit < end; bit++) {
18493 		if (offloads & single_offload)
18494 			printf(" %s",
18495 			       rte_eth_dev_tx_offload_name(single_offload));
18496 		single_offload <<= 1;
18497 	}
18498 }
18499 
18500 static void
18501 cmd_tx_offload_get_capa_parsed(
18502 	void *parsed_result,
18503 	__rte_unused struct cmdline *cl,
18504 	__rte_unused void *data)
18505 {
18506 	struct cmd_tx_offload_get_capa_result *res = parsed_result;
18507 	struct rte_eth_dev_info dev_info;
18508 	portid_t port_id = res->port_id;
18509 	uint64_t queue_offloads;
18510 	uint64_t port_offloads;
18511 	int ret;
18512 
18513 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18514 	if (ret != 0)
18515 		return;
18516 
18517 	queue_offloads = dev_info.tx_queue_offload_capa;
18518 	port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18519 
18520 	printf("Tx Offloading Capabilities of port %d :\n", port_id);
18521 	printf("  Per Queue :");
18522 	print_tx_offloads(queue_offloads);
18523 
18524 	printf("\n");
18525 	printf("  Per Port  :");
18526 	print_tx_offloads(port_offloads);
18527 	printf("\n\n");
18528 }
18529 
18530 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18531 	.f = cmd_tx_offload_get_capa_parsed,
18532 	.data = NULL,
18533 	.help_str = "show port <port_id> tx_offload capabilities",
18534 	.tokens = {
18535 		(void *)&cmd_tx_offload_get_capa_show,
18536 		(void *)&cmd_tx_offload_get_capa_port,
18537 		(void *)&cmd_tx_offload_get_capa_port_id,
18538 		(void *)&cmd_tx_offload_get_capa_tx_offload,
18539 		(void *)&cmd_tx_offload_get_capa_capabilities,
18540 		NULL,
18541 	}
18542 };
18543 
18544 /* Get Tx offloads configuration */
18545 struct cmd_tx_offload_get_configuration_result {
18546 	cmdline_fixed_string_t show;
18547 	cmdline_fixed_string_t port;
18548 	portid_t port_id;
18549 	cmdline_fixed_string_t tx_offload;
18550 	cmdline_fixed_string_t configuration;
18551 };
18552 
18553 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18554 	TOKEN_STRING_INITIALIZER
18555 		(struct cmd_tx_offload_get_configuration_result,
18556 		 show, "show");
18557 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18558 	TOKEN_STRING_INITIALIZER
18559 		(struct cmd_tx_offload_get_configuration_result,
18560 		 port, "port");
18561 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18562 	TOKEN_NUM_INITIALIZER
18563 		(struct cmd_tx_offload_get_configuration_result,
18564 		 port_id, UINT16);
18565 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18566 	TOKEN_STRING_INITIALIZER
18567 		(struct cmd_tx_offload_get_configuration_result,
18568 		 tx_offload, "tx_offload");
18569 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18570 	TOKEN_STRING_INITIALIZER
18571 		(struct cmd_tx_offload_get_configuration_result,
18572 		 configuration, "configuration");
18573 
18574 static void
18575 cmd_tx_offload_get_configuration_parsed(
18576 	void *parsed_result,
18577 	__rte_unused struct cmdline *cl,
18578 	__rte_unused void *data)
18579 {
18580 	struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18581 	struct rte_eth_dev_info dev_info;
18582 	portid_t port_id = res->port_id;
18583 	struct rte_port *port = &ports[port_id];
18584 	uint64_t port_offloads;
18585 	uint64_t queue_offloads;
18586 	uint16_t nb_tx_queues;
18587 	int q;
18588 	int ret;
18589 
18590 	printf("Tx Offloading Configuration of port %d :\n", port_id);
18591 
18592 	port_offloads = port->dev_conf.txmode.offloads;
18593 	printf("  Port :");
18594 	print_tx_offloads(port_offloads);
18595 	printf("\n");
18596 
18597 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18598 	if (ret != 0)
18599 		return;
18600 
18601 	nb_tx_queues = dev_info.nb_tx_queues;
18602 	for (q = 0; q < nb_tx_queues; q++) {
18603 		queue_offloads = port->tx_conf[q].offloads;
18604 		printf("  Queue[%2d] :", q);
18605 		print_tx_offloads(queue_offloads);
18606 		printf("\n");
18607 	}
18608 	printf("\n");
18609 }
18610 
18611 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18612 	.f = cmd_tx_offload_get_configuration_parsed,
18613 	.data = NULL,
18614 	.help_str = "show port <port_id> tx_offload configuration",
18615 	.tokens = {
18616 		(void *)&cmd_tx_offload_get_configuration_show,
18617 		(void *)&cmd_tx_offload_get_configuration_port,
18618 		(void *)&cmd_tx_offload_get_configuration_port_id,
18619 		(void *)&cmd_tx_offload_get_configuration_tx_offload,
18620 		(void *)&cmd_tx_offload_get_configuration_configuration,
18621 		NULL,
18622 	}
18623 };
18624 
18625 /* Enable/Disable a per port offloading */
18626 struct cmd_config_per_port_tx_offload_result {
18627 	cmdline_fixed_string_t port;
18628 	cmdline_fixed_string_t config;
18629 	portid_t port_id;
18630 	cmdline_fixed_string_t tx_offload;
18631 	cmdline_fixed_string_t offload;
18632 	cmdline_fixed_string_t on_off;
18633 };
18634 
18635 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18636 	TOKEN_STRING_INITIALIZER
18637 		(struct cmd_config_per_port_tx_offload_result,
18638 		 port, "port");
18639 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18640 	TOKEN_STRING_INITIALIZER
18641 		(struct cmd_config_per_port_tx_offload_result,
18642 		 config, "config");
18643 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18644 	TOKEN_NUM_INITIALIZER
18645 		(struct cmd_config_per_port_tx_offload_result,
18646 		 port_id, UINT16);
18647 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18648 	TOKEN_STRING_INITIALIZER
18649 		(struct cmd_config_per_port_tx_offload_result,
18650 		 tx_offload, "tx_offload");
18651 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18652 	TOKEN_STRING_INITIALIZER
18653 		(struct cmd_config_per_port_tx_offload_result,
18654 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18655 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18656 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18657 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18658 			  "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18659 			  "send_on_timestamp");
18660 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18661 	TOKEN_STRING_INITIALIZER
18662 		(struct cmd_config_per_port_tx_offload_result,
18663 		 on_off, "on#off");
18664 
18665 static uint64_t
18666 search_tx_offload(const char *name)
18667 {
18668 	uint64_t single_offload;
18669 	const char *single_name;
18670 	int found = 0;
18671 	unsigned int bit;
18672 
18673 	single_offload = 1;
18674 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18675 		single_name = rte_eth_dev_tx_offload_name(single_offload);
18676 		if (single_name == NULL)
18677 			break;
18678 		if (!strcasecmp(single_name, name)) {
18679 			found = 1;
18680 			break;
18681 		} else if (!strcasecmp(single_name, "UNKNOWN"))
18682 			break;
18683 		single_offload <<= 1;
18684 	}
18685 
18686 	if (found)
18687 		return single_offload;
18688 
18689 	return 0;
18690 }
18691 
18692 static void
18693 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18694 				__rte_unused struct cmdline *cl,
18695 				__rte_unused void *data)
18696 {
18697 	struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18698 	portid_t port_id = res->port_id;
18699 	struct rte_eth_dev_info dev_info;
18700 	struct rte_port *port = &ports[port_id];
18701 	uint64_t single_offload;
18702 	uint16_t nb_tx_queues;
18703 	int q;
18704 	int ret;
18705 
18706 	if (port->port_status != RTE_PORT_STOPPED) {
18707 		printf("Error: Can't config offload when Port %d "
18708 		       "is not stopped\n", port_id);
18709 		return;
18710 	}
18711 
18712 	single_offload = search_tx_offload(res->offload);
18713 	if (single_offload == 0) {
18714 		printf("Unknown offload name: %s\n", res->offload);
18715 		return;
18716 	}
18717 
18718 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18719 	if (ret != 0)
18720 		return;
18721 
18722 	nb_tx_queues = dev_info.nb_tx_queues;
18723 	if (!strcmp(res->on_off, "on")) {
18724 		port->dev_conf.txmode.offloads |= single_offload;
18725 		for (q = 0; q < nb_tx_queues; q++)
18726 			port->tx_conf[q].offloads |= single_offload;
18727 	} else {
18728 		port->dev_conf.txmode.offloads &= ~single_offload;
18729 		for (q = 0; q < nb_tx_queues; q++)
18730 			port->tx_conf[q].offloads &= ~single_offload;
18731 	}
18732 
18733 	cmd_reconfig_device_queue(port_id, 1, 1);
18734 }
18735 
18736 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18737 	.f = cmd_config_per_port_tx_offload_parsed,
18738 	.data = NULL,
18739 	.help_str = "port config <port_id> tx_offload "
18740 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18741 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18742 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18743 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18744 		    "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18745 		    "send_on_timestamp on|off",
18746 	.tokens = {
18747 		(void *)&cmd_config_per_port_tx_offload_result_port,
18748 		(void *)&cmd_config_per_port_tx_offload_result_config,
18749 		(void *)&cmd_config_per_port_tx_offload_result_port_id,
18750 		(void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18751 		(void *)&cmd_config_per_port_tx_offload_result_offload,
18752 		(void *)&cmd_config_per_port_tx_offload_result_on_off,
18753 		NULL,
18754 	}
18755 };
18756 
18757 /* Enable/Disable a per queue offloading */
18758 struct cmd_config_per_queue_tx_offload_result {
18759 	cmdline_fixed_string_t port;
18760 	portid_t port_id;
18761 	cmdline_fixed_string_t txq;
18762 	uint16_t queue_id;
18763 	cmdline_fixed_string_t tx_offload;
18764 	cmdline_fixed_string_t offload;
18765 	cmdline_fixed_string_t on_off;
18766 };
18767 
18768 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18769 	TOKEN_STRING_INITIALIZER
18770 		(struct cmd_config_per_queue_tx_offload_result,
18771 		 port, "port");
18772 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18773 	TOKEN_NUM_INITIALIZER
18774 		(struct cmd_config_per_queue_tx_offload_result,
18775 		 port_id, UINT16);
18776 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18777 	TOKEN_STRING_INITIALIZER
18778 		(struct cmd_config_per_queue_tx_offload_result,
18779 		 txq, "txq");
18780 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18781 	TOKEN_NUM_INITIALIZER
18782 		(struct cmd_config_per_queue_tx_offload_result,
18783 		 queue_id, UINT16);
18784 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18785 	TOKEN_STRING_INITIALIZER
18786 		(struct cmd_config_per_queue_tx_offload_result,
18787 		 tx_offload, "tx_offload");
18788 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18789 	TOKEN_STRING_INITIALIZER
18790 		(struct cmd_config_per_queue_tx_offload_result,
18791 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18792 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18793 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18794 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18795 			  "mt_lockfree#multi_segs#mbuf_fast_free#security");
18796 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18797 	TOKEN_STRING_INITIALIZER
18798 		(struct cmd_config_per_queue_tx_offload_result,
18799 		 on_off, "on#off");
18800 
18801 static void
18802 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18803 				__rte_unused struct cmdline *cl,
18804 				__rte_unused void *data)
18805 {
18806 	struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18807 	struct rte_eth_dev_info dev_info;
18808 	portid_t port_id = res->port_id;
18809 	uint16_t queue_id = res->queue_id;
18810 	struct rte_port *port = &ports[port_id];
18811 	uint64_t single_offload;
18812 	int ret;
18813 
18814 	if (port->port_status != RTE_PORT_STOPPED) {
18815 		printf("Error: Can't config offload when Port %d "
18816 		       "is not stopped\n", port_id);
18817 		return;
18818 	}
18819 
18820 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18821 	if (ret != 0)
18822 		return;
18823 
18824 	if (queue_id >= dev_info.nb_tx_queues) {
18825 		printf("Error: input queue_id should be 0 ... "
18826 		       "%d\n", dev_info.nb_tx_queues - 1);
18827 		return;
18828 	}
18829 
18830 	single_offload = search_tx_offload(res->offload);
18831 	if (single_offload == 0) {
18832 		printf("Unknown offload name: %s\n", res->offload);
18833 		return;
18834 	}
18835 
18836 	if (!strcmp(res->on_off, "on"))
18837 		port->tx_conf[queue_id].offloads |= single_offload;
18838 	else
18839 		port->tx_conf[queue_id].offloads &= ~single_offload;
18840 
18841 	cmd_reconfig_device_queue(port_id, 1, 1);
18842 }
18843 
18844 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18845 	.f = cmd_config_per_queue_tx_offload_parsed,
18846 	.data = NULL,
18847 	.help_str = "port <port_id> txq <queue_id> tx_offload "
18848 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18849 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18850 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18851 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18852 		    "mt_lockfree|multi_segs|mbuf_fast_free|security "
18853 		    "on|off",
18854 	.tokens = {
18855 		(void *)&cmd_config_per_queue_tx_offload_result_port,
18856 		(void *)&cmd_config_per_queue_tx_offload_result_port_id,
18857 		(void *)&cmd_config_per_queue_tx_offload_result_txq,
18858 		(void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18859 		(void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18860 		(void *)&cmd_config_per_queue_tx_offload_result_offload,
18861 		(void *)&cmd_config_per_queue_tx_offload_result_on_off,
18862 		NULL,
18863 	}
18864 };
18865 
18866 /* *** configure tx_metadata for specific port *** */
18867 struct cmd_config_tx_metadata_specific_result {
18868 	cmdline_fixed_string_t port;
18869 	cmdline_fixed_string_t keyword;
18870 	uint16_t port_id;
18871 	cmdline_fixed_string_t item;
18872 	uint32_t value;
18873 };
18874 
18875 static void
18876 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18877 				__rte_unused struct cmdline *cl,
18878 				__rte_unused void *data)
18879 {
18880 	struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18881 
18882 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18883 		return;
18884 	ports[res->port_id].tx_metadata = res->value;
18885 	/* Add/remove callback to insert valid metadata in every Tx packet. */
18886 	if (ports[res->port_id].tx_metadata)
18887 		add_tx_md_callback(res->port_id);
18888 	else
18889 		remove_tx_md_callback(res->port_id);
18890 	rte_flow_dynf_metadata_register();
18891 }
18892 
18893 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18894 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18895 			port, "port");
18896 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18897 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18898 			keyword, "config");
18899 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18900 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18901 			port_id, UINT16);
18902 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18903 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18904 			item, "tx_metadata");
18905 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18906 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18907 			value, UINT32);
18908 
18909 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18910 	.f = cmd_config_tx_metadata_specific_parsed,
18911 	.data = NULL,
18912 	.help_str = "port config <port_id> tx_metadata <value>",
18913 	.tokens = {
18914 		(void *)&cmd_config_tx_metadata_specific_port,
18915 		(void *)&cmd_config_tx_metadata_specific_keyword,
18916 		(void *)&cmd_config_tx_metadata_specific_id,
18917 		(void *)&cmd_config_tx_metadata_specific_item,
18918 		(void *)&cmd_config_tx_metadata_specific_value,
18919 		NULL,
18920 	},
18921 };
18922 
18923 /* *** set dynf *** */
18924 struct cmd_config_tx_dynf_specific_result {
18925 	cmdline_fixed_string_t port;
18926 	cmdline_fixed_string_t keyword;
18927 	uint16_t port_id;
18928 	cmdline_fixed_string_t item;
18929 	cmdline_fixed_string_t name;
18930 	cmdline_fixed_string_t value;
18931 };
18932 
18933 static void
18934 cmd_config_dynf_specific_parsed(void *parsed_result,
18935 				__rte_unused struct cmdline *cl,
18936 				__rte_unused void *data)
18937 {
18938 	struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18939 	struct rte_mbuf_dynflag desc_flag;
18940 	int flag;
18941 	uint64_t old_port_flags;
18942 
18943 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18944 		return;
18945 	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18946 	if (flag <= 0) {
18947 		if (strlcpy(desc_flag.name, res->name,
18948 			    RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18949 			printf("Flag name too long\n");
18950 			return;
18951 		}
18952 		desc_flag.flags = 0;
18953 		flag = rte_mbuf_dynflag_register(&desc_flag);
18954 		if (flag < 0) {
18955 			printf("Can't register flag\n");
18956 			return;
18957 		}
18958 		strcpy(dynf_names[flag], desc_flag.name);
18959 	}
18960 	old_port_flags = ports[res->port_id].mbuf_dynf;
18961 	if (!strcmp(res->value, "set")) {
18962 		ports[res->port_id].mbuf_dynf |= 1UL << flag;
18963 		if (old_port_flags == 0)
18964 			add_tx_dynf_callback(res->port_id);
18965 	} else {
18966 		ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18967 		if (ports[res->port_id].mbuf_dynf == 0)
18968 			remove_tx_dynf_callback(res->port_id);
18969 	}
18970 }
18971 
18972 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18973 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18974 			keyword, "port");
18975 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
18976 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18977 			keyword, "config");
18978 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
18979 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18980 			port_id, UINT16);
18981 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
18982 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18983 			item, "dynf");
18984 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
18985 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18986 			name, NULL);
18987 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
18988 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18989 			value, "set#clear");
18990 
18991 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
18992 	.f = cmd_config_dynf_specific_parsed,
18993 	.data = NULL,
18994 	.help_str = "port config <port id> dynf <name> set|clear",
18995 	.tokens = {
18996 		(void *)&cmd_config_tx_dynf_specific_port,
18997 		(void *)&cmd_config_tx_dynf_specific_keyword,
18998 		(void *)&cmd_config_tx_dynf_specific_port_id,
18999 		(void *)&cmd_config_tx_dynf_specific_item,
19000 		(void *)&cmd_config_tx_dynf_specific_name,
19001 		(void *)&cmd_config_tx_dynf_specific_value,
19002 		NULL,
19003 	},
19004 };
19005 
19006 /* *** display tx_metadata per port configuration *** */
19007 struct cmd_show_tx_metadata_result {
19008 	cmdline_fixed_string_t cmd_show;
19009 	cmdline_fixed_string_t cmd_port;
19010 	cmdline_fixed_string_t cmd_keyword;
19011 	portid_t cmd_pid;
19012 };
19013 
19014 static void
19015 cmd_show_tx_metadata_parsed(void *parsed_result,
19016 		__rte_unused struct cmdline *cl,
19017 		__rte_unused void *data)
19018 {
19019 	struct cmd_show_tx_metadata_result *res = parsed_result;
19020 
19021 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19022 		printf("invalid port id %u\n", res->cmd_pid);
19023 		return;
19024 	}
19025 	if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19026 		printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19027 		       ports[res->cmd_pid].tx_metadata);
19028 	}
19029 }
19030 
19031 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19032 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19033 			cmd_show, "show");
19034 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19035 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19036 			cmd_port, "port");
19037 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19038 	TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19039 			cmd_pid, UINT16);
19040 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19041 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19042 			cmd_keyword, "tx_metadata");
19043 
19044 cmdline_parse_inst_t cmd_show_tx_metadata = {
19045 	.f = cmd_show_tx_metadata_parsed,
19046 	.data = NULL,
19047 	.help_str = "show port <port_id> tx_metadata",
19048 	.tokens = {
19049 		(void *)&cmd_show_tx_metadata_show,
19050 		(void *)&cmd_show_tx_metadata_port,
19051 		(void *)&cmd_show_tx_metadata_pid,
19052 		(void *)&cmd_show_tx_metadata_keyword,
19053 		NULL,
19054 	},
19055 };
19056 
19057 /* show port supported ptypes */
19058 
19059 /* Common result structure for show port ptypes */
19060 struct cmd_show_port_supported_ptypes_result {
19061 	cmdline_fixed_string_t show;
19062 	cmdline_fixed_string_t port;
19063 	portid_t port_id;
19064 	cmdline_fixed_string_t ptypes;
19065 };
19066 
19067 /* Common CLI fields for show port ptypes */
19068 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19069 	TOKEN_STRING_INITIALIZER
19070 		(struct cmd_show_port_supported_ptypes_result,
19071 		 show, "show");
19072 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19073 	TOKEN_STRING_INITIALIZER
19074 		(struct cmd_show_port_supported_ptypes_result,
19075 		 port, "port");
19076 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19077 	TOKEN_NUM_INITIALIZER
19078 		(struct cmd_show_port_supported_ptypes_result,
19079 		 port_id, UINT16);
19080 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19081 	TOKEN_STRING_INITIALIZER
19082 		(struct cmd_show_port_supported_ptypes_result,
19083 		 ptypes, "ptypes");
19084 
19085 static void
19086 cmd_show_port_supported_ptypes_parsed(
19087 	void *parsed_result,
19088 	__rte_unused struct cmdline *cl,
19089 	__rte_unused void *data)
19090 {
19091 #define RSVD_PTYPE_MASK       0xf0000000
19092 #define MAX_PTYPES_PER_LAYER  16
19093 #define LTYPE_NAMESIZE        32
19094 #define PTYPE_NAMESIZE        256
19095 	struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19096 	char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19097 	uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19098 	uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19099 	uint16_t port_id = res->port_id;
19100 	int ret, i;
19101 
19102 	ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19103 	if (ret < 0)
19104 		return;
19105 
19106 	while (ptype_mask != RSVD_PTYPE_MASK) {
19107 
19108 		switch (ptype_mask) {
19109 		case RTE_PTYPE_L2_MASK:
19110 			strlcpy(ltype, "L2", sizeof(ltype));
19111 			break;
19112 		case RTE_PTYPE_L3_MASK:
19113 			strlcpy(ltype, "L3", sizeof(ltype));
19114 			break;
19115 		case RTE_PTYPE_L4_MASK:
19116 			strlcpy(ltype, "L4", sizeof(ltype));
19117 			break;
19118 		case RTE_PTYPE_TUNNEL_MASK:
19119 			strlcpy(ltype, "Tunnel", sizeof(ltype));
19120 			break;
19121 		case RTE_PTYPE_INNER_L2_MASK:
19122 			strlcpy(ltype, "Inner L2", sizeof(ltype));
19123 			break;
19124 		case RTE_PTYPE_INNER_L3_MASK:
19125 			strlcpy(ltype, "Inner L3", sizeof(ltype));
19126 			break;
19127 		case RTE_PTYPE_INNER_L4_MASK:
19128 			strlcpy(ltype, "Inner L4", sizeof(ltype));
19129 			break;
19130 		default:
19131 			return;
19132 		}
19133 
19134 		ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19135 						       ptype_mask, ptypes,
19136 						       MAX_PTYPES_PER_LAYER);
19137 
19138 		if (ret > 0)
19139 			printf("Supported %s ptypes:\n", ltype);
19140 		else
19141 			printf("%s ptypes unsupported\n", ltype);
19142 
19143 		for (i = 0; i < ret; ++i) {
19144 			rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19145 			printf("%s\n", buf);
19146 		}
19147 
19148 		ptype_mask <<= 4;
19149 	}
19150 }
19151 
19152 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19153 	.f = cmd_show_port_supported_ptypes_parsed,
19154 	.data = NULL,
19155 	.help_str = "show port <port_id> ptypes",
19156 	.tokens = {
19157 		(void *)&cmd_show_port_supported_ptypes_show,
19158 		(void *)&cmd_show_port_supported_ptypes_port,
19159 		(void *)&cmd_show_port_supported_ptypes_port_id,
19160 		(void *)&cmd_show_port_supported_ptypes_ptypes,
19161 		NULL,
19162 	},
19163 };
19164 
19165 /* *** display rx/tx descriptor status *** */
19166 struct cmd_show_rx_tx_desc_status_result {
19167 	cmdline_fixed_string_t cmd_show;
19168 	cmdline_fixed_string_t cmd_port;
19169 	cmdline_fixed_string_t cmd_keyword;
19170 	cmdline_fixed_string_t cmd_desc;
19171 	cmdline_fixed_string_t cmd_status;
19172 	portid_t cmd_pid;
19173 	portid_t cmd_qid;
19174 	portid_t cmd_did;
19175 };
19176 
19177 static void
19178 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19179 		__rte_unused struct cmdline *cl,
19180 		__rte_unused void *data)
19181 {
19182 	struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19183 	int rc;
19184 
19185 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19186 		printf("invalid port id %u\n", res->cmd_pid);
19187 		return;
19188 	}
19189 
19190 	if (!strcmp(res->cmd_keyword, "rxq")) {
19191 		rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19192 					     res->cmd_did);
19193 		if (rc < 0) {
19194 			printf("Invalid queueid = %d\n", res->cmd_qid);
19195 			return;
19196 		}
19197 		if (rc == RTE_ETH_RX_DESC_AVAIL)
19198 			printf("Desc status = AVAILABLE\n");
19199 		else if (rc == RTE_ETH_RX_DESC_DONE)
19200 			printf("Desc status = DONE\n");
19201 		else
19202 			printf("Desc status = UNAVAILABLE\n");
19203 	} else if (!strcmp(res->cmd_keyword, "txq")) {
19204 		rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19205 					     res->cmd_did);
19206 		if (rc < 0) {
19207 			printf("Invalid queueid = %d\n", res->cmd_qid);
19208 			return;
19209 		}
19210 		if (rc == RTE_ETH_TX_DESC_FULL)
19211 			printf("Desc status = FULL\n");
19212 		else if (rc == RTE_ETH_TX_DESC_DONE)
19213 			printf("Desc status = DONE\n");
19214 		else
19215 			printf("Desc status = UNAVAILABLE\n");
19216 	}
19217 }
19218 
19219 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19220 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19221 			cmd_show, "show");
19222 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19223 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19224 			cmd_port, "port");
19225 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19226 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19227 			cmd_pid, UINT16);
19228 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19229 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19230 			cmd_keyword, "rxq#txq");
19231 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19232 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19233 			cmd_qid, UINT16);
19234 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19235 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19236 			cmd_desc, "desc");
19237 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19238 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19239 			cmd_did, UINT16);
19240 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19241 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19242 			cmd_status, "status");
19243 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19244 	.f = cmd_show_rx_tx_desc_status_parsed,
19245 	.data = NULL,
19246 	.help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19247 		"status",
19248 	.tokens = {
19249 		(void *)&cmd_show_rx_tx_desc_status_show,
19250 		(void *)&cmd_show_rx_tx_desc_status_port,
19251 		(void *)&cmd_show_rx_tx_desc_status_pid,
19252 		(void *)&cmd_show_rx_tx_desc_status_keyword,
19253 		(void *)&cmd_show_rx_tx_desc_status_qid,
19254 		(void *)&cmd_show_rx_tx_desc_status_desc,
19255 		(void *)&cmd_show_rx_tx_desc_status_did,
19256 		(void *)&cmd_show_rx_tx_desc_status_status,
19257 		NULL,
19258 	},
19259 };
19260 
19261 /* Common result structure for set port ptypes */
19262 struct cmd_set_port_ptypes_result {
19263 	cmdline_fixed_string_t set;
19264 	cmdline_fixed_string_t port;
19265 	portid_t port_id;
19266 	cmdline_fixed_string_t ptype_mask;
19267 	uint32_t mask;
19268 };
19269 
19270 /* Common CLI fields for set port ptypes */
19271 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19272 	TOKEN_STRING_INITIALIZER
19273 		(struct cmd_set_port_ptypes_result,
19274 		 set, "set");
19275 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19276 	TOKEN_STRING_INITIALIZER
19277 		(struct cmd_set_port_ptypes_result,
19278 		 port, "port");
19279 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19280 	TOKEN_NUM_INITIALIZER
19281 		(struct cmd_set_port_ptypes_result,
19282 		 port_id, UINT16);
19283 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19284 	TOKEN_STRING_INITIALIZER
19285 		(struct cmd_set_port_ptypes_result,
19286 		 ptype_mask, "ptype_mask");
19287 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19288 	TOKEN_NUM_INITIALIZER
19289 		(struct cmd_set_port_ptypes_result,
19290 		 mask, UINT32);
19291 
19292 static void
19293 cmd_set_port_ptypes_parsed(
19294 	void *parsed_result,
19295 	__rte_unused struct cmdline *cl,
19296 	__rte_unused void *data)
19297 {
19298 	struct cmd_set_port_ptypes_result *res = parsed_result;
19299 #define PTYPE_NAMESIZE        256
19300 	char ptype_name[PTYPE_NAMESIZE];
19301 	uint16_t port_id = res->port_id;
19302 	uint32_t ptype_mask = res->mask;
19303 	int ret, i;
19304 
19305 	ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19306 					       NULL, 0);
19307 	if (ret <= 0) {
19308 		printf("Port %d doesn't support any ptypes.\n", port_id);
19309 		return;
19310 	}
19311 
19312 	uint32_t ptypes[ret];
19313 
19314 	ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19315 	if (ret < 0) {
19316 		printf("Unable to set requested ptypes for Port %d\n", port_id);
19317 		return;
19318 	}
19319 
19320 	printf("Successfully set following ptypes for Port %d\n", port_id);
19321 	for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19322 		rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19323 		printf("%s\n", ptype_name);
19324 	}
19325 
19326 	clear_ptypes = false;
19327 }
19328 
19329 cmdline_parse_inst_t cmd_set_port_ptypes = {
19330 	.f = cmd_set_port_ptypes_parsed,
19331 	.data = NULL,
19332 	.help_str = "set port <port_id> ptype_mask <mask>",
19333 	.tokens = {
19334 		(void *)&cmd_set_port_ptypes_set,
19335 		(void *)&cmd_set_port_ptypes_port,
19336 		(void *)&cmd_set_port_ptypes_port_id,
19337 		(void *)&cmd_set_port_ptypes_mask_str,
19338 		(void *)&cmd_set_port_ptypes_mask_u32,
19339 		NULL,
19340 	},
19341 };
19342 
19343 /* *** display mac addresses added to a port *** */
19344 struct cmd_showport_macs_result {
19345 	cmdline_fixed_string_t cmd_show;
19346 	cmdline_fixed_string_t cmd_port;
19347 	cmdline_fixed_string_t cmd_keyword;
19348 	portid_t cmd_pid;
19349 };
19350 
19351 static void
19352 cmd_showport_macs_parsed(void *parsed_result,
19353 		__rte_unused struct cmdline *cl,
19354 		__rte_unused void *data)
19355 {
19356 	struct cmd_showport_macs_result *res = parsed_result;
19357 
19358 	if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19359 		return;
19360 
19361 	if (!strcmp(res->cmd_keyword, "macs"))
19362 		show_macs(res->cmd_pid);
19363 	else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19364 		show_mcast_macs(res->cmd_pid);
19365 }
19366 
19367 cmdline_parse_token_string_t cmd_showport_macs_show =
19368 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19369 			cmd_show, "show");
19370 cmdline_parse_token_string_t cmd_showport_macs_port =
19371 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19372 			cmd_port, "port");
19373 cmdline_parse_token_num_t cmd_showport_macs_pid =
19374 	TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19375 			cmd_pid, UINT16);
19376 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19377 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19378 			cmd_keyword, "macs#mcast_macs");
19379 
19380 cmdline_parse_inst_t cmd_showport_macs = {
19381 	.f = cmd_showport_macs_parsed,
19382 	.data = NULL,
19383 	.help_str = "show port <port_id> macs|mcast_macs",
19384 	.tokens = {
19385 		(void *)&cmd_showport_macs_show,
19386 		(void *)&cmd_showport_macs_port,
19387 		(void *)&cmd_showport_macs_pid,
19388 		(void *)&cmd_showport_macs_keyword,
19389 		NULL,
19390 	},
19391 };
19392 
19393 /* ******************************************************************************** */
19394 
19395 /* list of instructions */
19396 cmdline_parse_ctx_t main_ctx[] = {
19397 	(cmdline_parse_inst_t *)&cmd_help_brief,
19398 	(cmdline_parse_inst_t *)&cmd_help_long,
19399 	(cmdline_parse_inst_t *)&cmd_quit,
19400 	(cmdline_parse_inst_t *)&cmd_load_from_file,
19401 	(cmdline_parse_inst_t *)&cmd_showport,
19402 	(cmdline_parse_inst_t *)&cmd_showqueue,
19403 	(cmdline_parse_inst_t *)&cmd_showportall,
19404 	(cmdline_parse_inst_t *)&cmd_showdevice,
19405 	(cmdline_parse_inst_t *)&cmd_showcfg,
19406 	(cmdline_parse_inst_t *)&cmd_showfwdall,
19407 	(cmdline_parse_inst_t *)&cmd_start,
19408 	(cmdline_parse_inst_t *)&cmd_start_tx_first,
19409 	(cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19410 	(cmdline_parse_inst_t *)&cmd_set_link_up,
19411 	(cmdline_parse_inst_t *)&cmd_set_link_down,
19412 	(cmdline_parse_inst_t *)&cmd_reset,
19413 	(cmdline_parse_inst_t *)&cmd_set_numbers,
19414 	(cmdline_parse_inst_t *)&cmd_set_log,
19415 	(cmdline_parse_inst_t *)&cmd_set_txpkts,
19416 	(cmdline_parse_inst_t *)&cmd_set_txsplit,
19417 	(cmdline_parse_inst_t *)&cmd_set_txtimes,
19418 	(cmdline_parse_inst_t *)&cmd_set_fwd_list,
19419 	(cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19420 	(cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19421 	(cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19422 	(cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19423 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19424 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19425 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19426 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19427 	(cmdline_parse_inst_t *)&cmd_set_flush_rx,
19428 	(cmdline_parse_inst_t *)&cmd_set_link_check,
19429 	(cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19430 	(cmdline_parse_inst_t *)&cmd_set_bypass_event,
19431 	(cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19432 	(cmdline_parse_inst_t *)&cmd_show_bypass_config,
19433 #ifdef RTE_LIBRTE_PMD_BOND
19434 	(cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19435 	(cmdline_parse_inst_t *) &cmd_show_bonding_config,
19436 	(cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19437 	(cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19438 	(cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19439 	(cmdline_parse_inst_t *) &cmd_create_bonded_device,
19440 	(cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19441 	(cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19442 	(cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19443 	(cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19444 	(cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19445 #endif
19446 	(cmdline_parse_inst_t *)&cmd_vlan_offload,
19447 	(cmdline_parse_inst_t *)&cmd_vlan_tpid,
19448 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19449 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19450 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19451 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19452 	(cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19453 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19454 	(cmdline_parse_inst_t *)&cmd_csum_set,
19455 	(cmdline_parse_inst_t *)&cmd_csum_show,
19456 	(cmdline_parse_inst_t *)&cmd_csum_tunnel,
19457 	(cmdline_parse_inst_t *)&cmd_tso_set,
19458 	(cmdline_parse_inst_t *)&cmd_tso_show,
19459 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19460 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19461 	(cmdline_parse_inst_t *)&cmd_gro_enable,
19462 	(cmdline_parse_inst_t *)&cmd_gro_flush,
19463 	(cmdline_parse_inst_t *)&cmd_gro_show,
19464 	(cmdline_parse_inst_t *)&cmd_gso_enable,
19465 	(cmdline_parse_inst_t *)&cmd_gso_size,
19466 	(cmdline_parse_inst_t *)&cmd_gso_show,
19467 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19468 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19469 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19470 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19471 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19472 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19473 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19474 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19475 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19476 	(cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19477 	(cmdline_parse_inst_t *)&cmd_config_dcb,
19478 	(cmdline_parse_inst_t *)&cmd_read_reg,
19479 	(cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19480 	(cmdline_parse_inst_t *)&cmd_read_reg_bit,
19481 	(cmdline_parse_inst_t *)&cmd_write_reg,
19482 	(cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19483 	(cmdline_parse_inst_t *)&cmd_write_reg_bit,
19484 	(cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19485 	(cmdline_parse_inst_t *)&cmd_stop,
19486 	(cmdline_parse_inst_t *)&cmd_mac_addr,
19487 	(cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19488 	(cmdline_parse_inst_t *)&cmd_set_qmap,
19489 	(cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19490 	(cmdline_parse_inst_t *)&cmd_operate_port,
19491 	(cmdline_parse_inst_t *)&cmd_operate_specific_port,
19492 	(cmdline_parse_inst_t *)&cmd_operate_attach_port,
19493 	(cmdline_parse_inst_t *)&cmd_operate_detach_port,
19494 	(cmdline_parse_inst_t *)&cmd_operate_detach_device,
19495 	(cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19496 	(cmdline_parse_inst_t *)&cmd_config_speed_all,
19497 	(cmdline_parse_inst_t *)&cmd_config_speed_specific,
19498 	(cmdline_parse_inst_t *)&cmd_config_loopback_all,
19499 	(cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19500 	(cmdline_parse_inst_t *)&cmd_config_rx_tx,
19501 	(cmdline_parse_inst_t *)&cmd_config_mtu,
19502 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19503 	(cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19504 	(cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19505 	(cmdline_parse_inst_t *)&cmd_config_rss,
19506 	(cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19507 	(cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19508 	(cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19509 	(cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19510 	(cmdline_parse_inst_t *)&cmd_config_rss_reta,
19511 	(cmdline_parse_inst_t *)&cmd_showport_reta,
19512 	(cmdline_parse_inst_t *)&cmd_showport_macs,
19513 	(cmdline_parse_inst_t *)&cmd_config_burst,
19514 	(cmdline_parse_inst_t *)&cmd_config_thresh,
19515 	(cmdline_parse_inst_t *)&cmd_config_threshold,
19516 	(cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19517 	(cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19518 	(cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19519 	(cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19520 	(cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19521 	(cmdline_parse_inst_t *)&cmd_tunnel_filter,
19522 	(cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19523 	(cmdline_parse_inst_t *)&cmd_global_config,
19524 	(cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19525 	(cmdline_parse_inst_t *)&cmd_set_mirror_link,
19526 	(cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19527 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19528 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19529 	(cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19530 	(cmdline_parse_inst_t *)&cmd_dump,
19531 	(cmdline_parse_inst_t *)&cmd_dump_one,
19532 	(cmdline_parse_inst_t *)&cmd_ethertype_filter,
19533 	(cmdline_parse_inst_t *)&cmd_syn_filter,
19534 	(cmdline_parse_inst_t *)&cmd_2tuple_filter,
19535 	(cmdline_parse_inst_t *)&cmd_5tuple_filter,
19536 	(cmdline_parse_inst_t *)&cmd_flex_filter,
19537 	(cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19538 	(cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19539 	(cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19540 	(cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19541 	(cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19542 	(cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19543 	(cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19544 	(cmdline_parse_inst_t *)&cmd_flush_flow_director,
19545 	(cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19546 	(cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19547 	(cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19548 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19549 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19550 	(cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19551 	(cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19552 	(cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19553 	(cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19554 	(cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19555 	(cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19556 	(cmdline_parse_inst_t *)&cmd_flow,
19557 	(cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19558 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19559 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19560 	(cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19561 	(cmdline_parse_inst_t *)&cmd_create_port_meter,
19562 	(cmdline_parse_inst_t *)&cmd_enable_port_meter,
19563 	(cmdline_parse_inst_t *)&cmd_disable_port_meter,
19564 	(cmdline_parse_inst_t *)&cmd_del_port_meter,
19565 	(cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19566 	(cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19567 	(cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19568 	(cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19569 	(cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19570 	(cmdline_parse_inst_t *)&cmd_mcast_addr,
19571 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19572 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19573 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19574 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19575 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19576 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19577 	(cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19578 	(cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19579 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19580 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19581 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19582 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19583 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19584 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19585 	(cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19586 	(cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19587 	(cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19588 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19589 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19590 	(cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19591 	(cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19592 	(cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19593 	(cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19594 	(cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19595 	(cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19596 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19597 	(cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19598 	(cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19599 	(cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19600 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19601 	(cmdline_parse_inst_t *)&cmd_vf_max_bw,
19602 	(cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19603 	(cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19604 	(cmdline_parse_inst_t *)&cmd_strict_link_prio,
19605 	(cmdline_parse_inst_t *)&cmd_tc_min_bw,
19606 	(cmdline_parse_inst_t *)&cmd_set_vxlan,
19607 	(cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19608 	(cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19609 	(cmdline_parse_inst_t *)&cmd_set_nvgre,
19610 	(cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19611 	(cmdline_parse_inst_t *)&cmd_set_l2_encap,
19612 	(cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19613 	(cmdline_parse_inst_t *)&cmd_set_l2_decap,
19614 	(cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19615 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19616 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19617 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19618 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19619 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19620 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19621 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19622 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19623 	(cmdline_parse_inst_t *)&cmd_ddp_add,
19624 	(cmdline_parse_inst_t *)&cmd_ddp_del,
19625 	(cmdline_parse_inst_t *)&cmd_ddp_get_list,
19626 	(cmdline_parse_inst_t *)&cmd_ddp_get_info,
19627 	(cmdline_parse_inst_t *)&cmd_cfg_input_set,
19628 	(cmdline_parse_inst_t *)&cmd_clear_input_set,
19629 	(cmdline_parse_inst_t *)&cmd_show_vf_stats,
19630 	(cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19631 	(cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19632 	(cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19633 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19634 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19635 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19636 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19637 
19638 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19639 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19640 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19641 	(cmdline_parse_inst_t *)&cmd_queue_region,
19642 	(cmdline_parse_inst_t *)&cmd_region_flowtype,
19643 	(cmdline_parse_inst_t *)&cmd_user_priority_region,
19644 	(cmdline_parse_inst_t *)&cmd_flush_queue_region,
19645 	(cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19646 	(cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19647 	(cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19648 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19649 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19650 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19651 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19652 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19653 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19654 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19655 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19656 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19657 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19658 	(cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19659 	(cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19660 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19661 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19662 	(cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19663 	(cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19664 	(cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19665 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19666 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19667 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19668 	(cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19669 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19670 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19671 	(cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19672 	(cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19673 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19674 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19675 	(cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19676 	(cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19677 #ifdef RTE_LIBRTE_BPF
19678 	(cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19679 	(cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19680 #endif
19681 	(cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19682 	(cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19683 	(cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19684 	(cmdline_parse_inst_t *)&cmd_set_raw,
19685 	(cmdline_parse_inst_t *)&cmd_show_set_raw,
19686 	(cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19687 	(cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19688 	NULL,
19689 };
19690 
19691 /* read cmdline commands from file */
19692 void
19693 cmdline_read_from_file(const char *filename)
19694 {
19695 	struct cmdline *cl;
19696 
19697 	cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19698 	if (cl == NULL) {
19699 		printf("Failed to create file based cmdline context: %s\n",
19700 		       filename);
19701 		return;
19702 	}
19703 
19704 	cmdline_interact(cl);
19705 	cmdline_quit(cl);
19706 
19707 	cmdline_free(cl);
19708 
19709 	printf("Read CLI commands from %s\n", filename);
19710 }
19711 
19712 /* prompt function, called from main on MASTER lcore */
19713 void
19714 prompt(void)
19715 {
19716 	/* initialize non-constant commands */
19717 	cmd_set_fwd_mode_init();
19718 	cmd_set_fwd_retry_mode_init();
19719 
19720 	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19721 	if (testpmd_cl == NULL)
19722 		return;
19723 	cmdline_interact(testpmd_cl);
19724 	cmdline_stdin_exit(testpmd_cl);
19725 }
19726 
19727 void
19728 prompt_exit(void)
19729 {
19730 	if (testpmd_cl != NULL)
19731 		cmdline_quit(testpmd_cl);
19732 }
19733 
19734 static void
19735 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19736 {
19737 	if (id == (portid_t)RTE_PORT_ALL) {
19738 		portid_t pid;
19739 
19740 		RTE_ETH_FOREACH_DEV(pid) {
19741 			/* check if need_reconfig has been set to 1 */
19742 			if (ports[pid].need_reconfig == 0)
19743 				ports[pid].need_reconfig = dev;
19744 			/* check if need_reconfig_queues has been set to 1 */
19745 			if (ports[pid].need_reconfig_queues == 0)
19746 				ports[pid].need_reconfig_queues = queue;
19747 		}
19748 	} else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19749 		/* check if need_reconfig has been set to 1 */
19750 		if (ports[id].need_reconfig == 0)
19751 			ports[id].need_reconfig = dev;
19752 		/* check if need_reconfig_queues has been set to 1 */
19753 		if (ports[id].need_reconfig_queues == 0)
19754 			ports[id].need_reconfig_queues = queue;
19755 	}
19756 }
19757