xref: /dpdk/app/test-pmd/cmdline.c (revision 29416001)
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 port_id (module_eeprom|eeprom)\n"
170 			"    Display the module EEPROM or EEPROM information for port_id.\n\n"
171 
172 			"show port X rss reta (size) (mask0,mask1,...)\n"
173 			"    Display the rss redirection table entry indicated"
174 			" by masks on port X. size is used to indicate the"
175 			" hardware supported reta size\n\n"
176 
177 			"show port (port_id) rss-hash [key]\n"
178 			"    Display the RSS hash functions and RSS hash key of port\n\n"
179 
180 			"clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
181 			"    Clear information for port_id, or all.\n\n"
182 
183 			"show (rxq|txq) info (port_id) (queue_id)\n"
184 			"    Display information for configured RX/TX queue.\n\n"
185 
186 			"show config (rxtx|cores|fwd|txpkts)\n"
187 			"    Display the given configuration.\n\n"
188 
189 			"read rxd (port_id) (queue_id) (rxd_id)\n"
190 			"    Display an RX descriptor of a port RX queue.\n\n"
191 
192 			"read txd (port_id) (queue_id) (txd_id)\n"
193 			"    Display a TX descriptor of a port TX queue.\n\n"
194 
195 			"ddp get list (port_id)\n"
196 			"    Get ddp profile info list\n\n"
197 
198 			"ddp get info (profile_path)\n"
199 			"    Get ddp profile information.\n\n"
200 
201 			"show vf stats (port_id) (vf_id)\n"
202 			"    Display a VF's statistics.\n\n"
203 
204 			"clear vf stats (port_id) (vf_id)\n"
205 			"    Reset a VF's statistics.\n\n"
206 
207 			"show port (port_id) pctype mapping\n"
208 			"    Get flow ptype to pctype mapping on a port\n\n"
209 
210 			"show port meter stats (port_id) (meter_id) (clear)\n"
211 			"    Get meter stats on a port\n\n"
212 
213 			"show fwd stats all\n"
214 			"    Display statistics for all fwd engines.\n\n"
215 
216 			"clear fwd stats all\n"
217 			"    Clear statistics for all fwd engines.\n\n"
218 
219 			"show port (port_id) rx_offload capabilities\n"
220 			"    List all per queue and per port Rx offloading"
221 			" capabilities of a port\n\n"
222 
223 			"show port (port_id) rx_offload configuration\n"
224 			"    List port level and all queue level"
225 			" Rx offloading configuration\n\n"
226 
227 			"show port (port_id) tx_offload capabilities\n"
228 			"    List all per queue and per port"
229 			" Tx offloading capabilities of a port\n\n"
230 
231 			"show port (port_id) tx_offload configuration\n"
232 			"    List port level and all queue level"
233 			" Tx offloading configuration\n\n"
234 
235 			"show port (port_id) tx_metadata\n"
236 			"    Show Tx metadata value set"
237 			" for a specific port\n\n"
238 
239 			"show port (port_id) ptypes\n"
240 			"    Show port supported ptypes"
241 			" for a specific port\n\n"
242 
243 			"show device info (<identifier>|all)"
244 			"       Show general information about devices probed.\n\n"
245 
246 			"show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
247 			"       Show status of rx|tx descriptor.\n\n"
248 
249 			"show port (port_id) macs|mcast_macs"
250 			"       Display list of mac addresses added to port.\n\n"
251 
252 			"show port (port_id) fec capabilities"
253 			"	Show fec capabilities of a port.\n\n"
254 
255 			"show port (port_id) fec_mode"
256 			"	Show fec mode of a port.\n\n"
257 		);
258 	}
259 
260 	if (show_all || !strcmp(res->section, "config")) {
261 		cmdline_printf(
262 			cl,
263 			"\n"
264 			"Configuration:\n"
265 			"--------------\n"
266 			"Configuration changes only become active when"
267 			" forwarding is started/restarted.\n\n"
268 
269 			"set default\n"
270 			"    Reset forwarding to the default configuration.\n\n"
271 
272 			"set verbose (level)\n"
273 			"    Set the debug verbosity level X.\n\n"
274 
275 			"set log global|(type) (level)\n"
276 			"    Set the log level.\n\n"
277 
278 			"set nbport (num)\n"
279 			"    Set number of ports.\n\n"
280 
281 			"set nbcore (num)\n"
282 			"    Set number of cores.\n\n"
283 
284 			"set coremask (mask)\n"
285 			"    Set the forwarding cores hexadecimal mask.\n\n"
286 
287 			"set portmask (mask)\n"
288 			"    Set the forwarding ports hexadecimal mask.\n\n"
289 
290 			"set burst (num)\n"
291 			"    Set number of packets per burst.\n\n"
292 
293 			"set burst tx delay (microseconds) retry (num)\n"
294 			"    Set the transmit delay time and number of retries,"
295 			" effective when retry is enabled.\n\n"
296 
297 			"set txpkts (x[,y]*)\n"
298 			"    Set the length of each segment of TXONLY"
299 			" and optionally CSUM packets.\n\n"
300 
301 			"set txsplit (off|on|rand)\n"
302 			"    Set the split policy for the TX packets."
303 			" Right now only applicable for CSUM and TXONLY"
304 			" modes\n\n"
305 
306 			"set txtimes (x, y)\n"
307 			"    Set the scheduling on timestamps"
308 			" timings for the TXONLY mode\n\n"
309 
310 			"set corelist (x[,y]*)\n"
311 			"    Set the list of forwarding cores.\n\n"
312 
313 			"set portlist (x[,y]*)\n"
314 			"    Set the list of forwarding ports.\n\n"
315 
316 			"set port setup on (iterator|event)\n"
317 			"    Select how attached port is retrieved for setup.\n\n"
318 
319 			"set tx loopback (port_id) (on|off)\n"
320 			"    Enable or disable tx loopback.\n\n"
321 
322 			"set all queues drop (port_id) (on|off)\n"
323 			"    Set drop enable bit for all queues.\n\n"
324 
325 			"set vf split drop (port_id) (vf_id) (on|off)\n"
326 			"    Set split drop enable bit for a VF from the PF.\n\n"
327 
328 			"set vf mac antispoof (port_id) (vf_id) (on|off).\n"
329 			"    Set MAC antispoof for a VF from the PF.\n\n"
330 
331 			"set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
332 			"    Enable MACsec offload.\n\n"
333 
334 			"set macsec offload (port_id) off\n"
335 			"    Disable MACsec offload.\n\n"
336 
337 			"set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
338 			"    Configure MACsec secure connection (SC).\n\n"
339 
340 			"set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
341 			"    Configure MACsec secure association (SA).\n\n"
342 
343 			"set vf broadcast (port_id) (vf_id) (on|off)\n"
344 			"    Set VF broadcast for a VF from the PF.\n\n"
345 
346 			"vlan set stripq (on|off) (port_id,queue_id)\n"
347 			"    Set the VLAN strip for a queue on a port.\n\n"
348 
349 			"set vf vlan stripq (port_id) (vf_id) (on|off)\n"
350 			"    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
351 
352 			"set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
353 			"    Set VLAN insert for a VF from the PF.\n\n"
354 
355 			"set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
356 			"    Set VLAN antispoof for a VF from the PF.\n\n"
357 
358 			"set vf vlan tag (port_id) (vf_id) (on|off)\n"
359 			"    Set VLAN tag for a VF from the PF.\n\n"
360 
361 			"set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
362 			"    Set a VF's max bandwidth(Mbps).\n\n"
363 
364 			"set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
365 			"    Set all TCs' min bandwidth(%%) on a VF.\n\n"
366 
367 			"set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
368 			"    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
369 
370 			"set tx strict-link-priority (port_id) (tc_bitmap)\n"
371 			"    Set some TCs' strict link priority mode on a physical port.\n\n"
372 
373 			"set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
374 			"    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
375 
376 			"vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
377 			"    Set the VLAN strip or filter or qinq strip or extend\n\n"
378 
379 			"vlan set (inner|outer) tpid (value) (port_id)\n"
380 			"    Set the VLAN TPID for Packet Filtering on"
381 			" a port\n\n"
382 
383 			"rx_vlan add (vlan_id|all) (port_id)\n"
384 			"    Add a vlan_id, or all identifiers, to the set"
385 			" of VLAN identifiers filtered by port_id.\n\n"
386 
387 			"rx_vlan rm (vlan_id|all) (port_id)\n"
388 			"    Remove a vlan_id, or all identifiers, from the set"
389 			" of VLAN identifiers filtered by port_id.\n\n"
390 
391 			"rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
392 			"    Add a vlan_id, to the set of VLAN identifiers"
393 			"filtered for VF(s) from port_id.\n\n"
394 
395 			"rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
396 			"    Remove a vlan_id, to the set of VLAN identifiers"
397 			"filtered for VF(s) from port_id.\n\n"
398 
399 			"tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
400 			"(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
401 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
402 			"   add a tunnel filter of a port.\n\n"
403 
404 			"tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
405 			"(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
406 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
407 			"   remove a tunnel filter of a port.\n\n"
408 
409 			"rx_vxlan_port add (udp_port) (port_id)\n"
410 			"    Add an UDP port for VXLAN packet filter on a port\n\n"
411 
412 			"rx_vxlan_port rm (udp_port) (port_id)\n"
413 			"    Remove an UDP port for VXLAN packet filter on a port\n\n"
414 
415 			"tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
416 			"    Set hardware insertion of VLAN IDs (single or double VLAN "
417 			"depends on the number of VLAN IDs) in packets sent on a port.\n\n"
418 
419 			"tx_vlan set pvid port_id vlan_id (on|off)\n"
420 			"    Set port based TX VLAN insertion.\n\n"
421 
422 			"tx_vlan reset (port_id)\n"
423 			"    Disable hardware insertion of a VLAN header in"
424 			" packets sent on a port.\n\n"
425 
426 			"csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
427 			"    Select hardware or software calculation of the"
428 			" checksum when transmitting a packet using the"
429 			" csum forward engine.\n"
430 			"    ip|udp|tcp|sctp always concern the inner layer.\n"
431 			"    outer-ip concerns the outer IP layer in"
432 			"    outer-udp concerns the outer UDP layer in"
433 			" case the packet is recognized as a tunnel packet by"
434 			" the forward engine (vxlan, gre and ipip are supported)\n"
435 			"    Please check the NIC datasheet for HW limits.\n\n"
436 
437 			"csum parse-tunnel (on|off) (tx_port_id)\n"
438 			"    If disabled, treat tunnel packets as non-tunneled"
439 			" packets (treat inner headers as payload). The port\n"
440 			"    argument is the port used for TX in csum forward"
441 			" engine.\n\n"
442 
443 			"csum show (port_id)\n"
444 			"    Display tx checksum offload configuration\n\n"
445 
446 			"tso set (segsize) (portid)\n"
447 			"    Enable TCP Segmentation Offload in csum forward"
448 			" engine.\n"
449 			"    Please check the NIC datasheet for HW limits.\n\n"
450 
451 			"tso show (portid)"
452 			"    Display the status of TCP Segmentation Offload.\n\n"
453 
454 			"set port (port_id) gro on|off\n"
455 			"    Enable or disable Generic Receive Offload in"
456 			" csum forwarding engine.\n\n"
457 
458 			"show port (port_id) gro\n"
459 			"    Display GRO configuration.\n\n"
460 
461 			"set gro flush (cycles)\n"
462 			"    Set the cycle to flush GROed packets from"
463 			" reassembly tables.\n\n"
464 
465 			"set port (port_id) gso (on|off)"
466 			"    Enable or disable Generic Segmentation Offload in"
467 			" csum forwarding engine.\n\n"
468 
469 			"set gso segsz (length)\n"
470 			"    Set max packet length for output GSO segments,"
471 			" including packet header and payload.\n\n"
472 
473 			"show port (port_id) gso\n"
474 			"    Show GSO configuration.\n\n"
475 
476 			"set fwd (%s)\n"
477 			"    Set packet forwarding mode.\n\n"
478 
479 			"mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
480 			"    Add a MAC address on port_id.\n\n"
481 
482 			"mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
483 			"    Remove a MAC address from port_id.\n\n"
484 
485 			"mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
486 			"    Set the default MAC address for port_id.\n\n"
487 
488 			"mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
489 			"    Add a MAC address for a VF on the port.\n\n"
490 
491 			"set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
492 			"    Set the MAC address for a VF from the PF.\n\n"
493 
494 			"set eth-peer (port_id) (peer_addr)\n"
495 			"    set the peer address for certain port.\n\n"
496 
497 			"set port (port_id) uta (mac_address|all) (on|off)\n"
498 			"    Add/Remove a or all unicast hash filter(s)"
499 			"from port X.\n\n"
500 
501 			"set promisc (port_id|all) (on|off)\n"
502 			"    Set the promiscuous mode on port_id, or all.\n\n"
503 
504 			"set allmulti (port_id|all) (on|off)\n"
505 			"    Set the allmulti mode on port_id, or all.\n\n"
506 
507 			"set vf promisc (port_id) (vf_id) (on|off)\n"
508 			"    Set unicast promiscuous mode for a VF from the PF.\n\n"
509 
510 			"set vf allmulti (port_id) (vf_id) (on|off)\n"
511 			"    Set multicast promiscuous mode for a VF from the PF.\n\n"
512 
513 			"set flow_ctrl rx (on|off) tx (on|off) (high_water)"
514 			" (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
515 			" (on|off) autoneg (on|off) (port_id)\n"
516 			"set flow_ctrl rx (on|off) (portid)\n"
517 			"set flow_ctrl tx (on|off) (portid)\n"
518 			"set flow_ctrl high_water (high_water) (portid)\n"
519 			"set flow_ctrl low_water (low_water) (portid)\n"
520 			"set flow_ctrl pause_time (pause_time) (portid)\n"
521 			"set flow_ctrl send_xon (send_xon) (portid)\n"
522 			"set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
523 			"set flow_ctrl autoneg (on|off) (port_id)\n"
524 			"    Set the link flow control parameter on a port.\n\n"
525 
526 			"set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
527 			" (low_water) (pause_time) (priority) (port_id)\n"
528 			"    Set the priority flow control parameter on a"
529 			" port.\n\n"
530 
531 			"set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
532 			"    Set statistics mapping (qmapping 0..15) for RX/TX"
533 			" queue on port.\n"
534 			"    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
535 			" on port 0 to mapping 5.\n\n"
536 
537 			"set xstats-hide-zero on|off\n"
538 			"    Set the option to hide the zero values"
539 			" for xstats display.\n"
540 
541 			"set record-core-cycles on|off\n"
542 			"    Set the option to enable measurement of CPU cycles.\n"
543 
544 			"set record-burst-stats on|off\n"
545 			"    Set the option to enable display of RX and TX bursts.\n"
546 
547 			"set port (port_id) vf (vf_id) rx|tx on|off\n"
548 			"    Enable/Disable a VF receive/tranmit from a port\n\n"
549 
550 			"set port (port_id) vf (vf_id) (mac_addr)"
551 			" (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
552 			"   Add/Remove unicast or multicast MAC addr filter"
553 			" for a VF.\n\n"
554 
555 			"set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
556 			"|MPE) (on|off)\n"
557 			"    AUPE:accepts untagged VLAN;"
558 			"ROPE:accept unicast hash\n\n"
559 			"    BAM:accepts broadcast packets;"
560 			"MPE:accepts all multicast packets\n\n"
561 			"    Enable/Disable a VF receive mode of a port\n\n"
562 
563 			"set port (port_id) queue (queue_id) rate (rate_num)\n"
564 			"    Set rate limit for a queue of a port\n\n"
565 
566 			"set port (port_id) vf (vf_id) rate (rate_num) "
567 			"queue_mask (queue_mask_value)\n"
568 			"    Set rate limit for queues in VF of a port\n\n"
569 
570 			"set port (port_id) mirror-rule (rule_id)"
571 			" (pool-mirror-up|pool-mirror-down|vlan-mirror)"
572 			" (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
573 			"   Set pool or vlan type mirror rule on a port.\n"
574 			"   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
575 			" dst-pool 0 on' enable mirror traffic with vlan 0,1"
576 			" to pool 0.\n\n"
577 
578 			"set port (port_id) mirror-rule (rule_id)"
579 			" (uplink-mirror|downlink-mirror) dst-pool"
580 			" (pool_id) (on|off)\n"
581 			"   Set uplink or downlink type mirror rule on a port.\n"
582 			"   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
583 			" 0 on' enable mirror income traffic to pool 0.\n\n"
584 
585 			"reset port (port_id) mirror-rule (rule_id)\n"
586 			"   Reset a mirror rule.\n\n"
587 
588 			"set flush_rx (on|off)\n"
589 			"   Flush (default) or don't flush RX streams before"
590 			" forwarding. Mainly used with PCAP drivers.\n\n"
591 
592 			"set bypass mode (normal|bypass|isolate) (port_id)\n"
593 			"   Set the bypass mode for the lowest port on bypass enabled"
594 			" NIC.\n\n"
595 
596 			"set bypass event (timeout|os_on|os_off|power_on|power_off) "
597 			"mode (normal|bypass|isolate) (port_id)\n"
598 			"   Set the event required to initiate specified bypass mode for"
599 			" the lowest port on a bypass enabled NIC where:\n"
600 			"       timeout   = enable bypass after watchdog timeout.\n"
601 			"       os_on     = enable bypass when OS/board is powered on.\n"
602 			"       os_off    = enable bypass when OS/board is powered off.\n"
603 			"       power_on  = enable bypass when power supply is turned on.\n"
604 			"       power_off = enable bypass when power supply is turned off."
605 			"\n\n"
606 
607 			"set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
608 			"   Set the bypass watchdog timeout to 'n' seconds"
609 			" where 0 = instant.\n\n"
610 
611 			"show bypass config (port_id)\n"
612 			"   Show the bypass configuration for a bypass enabled NIC"
613 			" using the lowest port on the NIC.\n\n"
614 
615 #ifdef RTE_LIBRTE_PMD_BOND
616 			"create bonded device (mode) (socket)\n"
617 			"	Create a new bonded device with specific bonding mode and socket.\n\n"
618 
619 			"add bonding slave (slave_id) (port_id)\n"
620 			"	Add a slave device to a bonded device.\n\n"
621 
622 			"remove bonding slave (slave_id) (port_id)\n"
623 			"	Remove a slave device from a bonded device.\n\n"
624 
625 			"set bonding mode (value) (port_id)\n"
626 			"	Set the bonding mode on a bonded device.\n\n"
627 
628 			"set bonding primary (slave_id) (port_id)\n"
629 			"	Set the primary slave for a bonded device.\n\n"
630 
631 			"show bonding config (port_id)\n"
632 			"	Show the bonding config for port_id.\n\n"
633 
634 			"set bonding mac_addr (port_id) (address)\n"
635 			"	Set the MAC address of a bonded device.\n\n"
636 
637 			"set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
638 			"	Set Aggregation mode for IEEE802.3AD (mode 4)"
639 
640 			"set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
641 			"	Set the transmit balance policy for bonded device running in balance mode.\n\n"
642 
643 			"set bonding mon_period (port_id) (value)\n"
644 			"	Set the bonding link status monitoring polling period in ms.\n\n"
645 
646 			"set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
647 			"	Enable/disable dedicated queues for LACP control traffic.\n\n"
648 
649 #endif
650 			"set link-up port (port_id)\n"
651 			"	Set link up for a port.\n\n"
652 
653 			"set link-down port (port_id)\n"
654 			"	Set link down for a port.\n\n"
655 
656 			"E-tag set insertion on port-tag-id (value)"
657 			" port (port_id) vf (vf_id)\n"
658 			"    Enable E-tag insertion for a VF on a port\n\n"
659 
660 			"E-tag set insertion off port (port_id) vf (vf_id)\n"
661 			"    Disable E-tag insertion for a VF on a port\n\n"
662 
663 			"E-tag set stripping (on|off) port (port_id)\n"
664 			"    Enable/disable E-tag stripping on a port\n\n"
665 
666 			"E-tag set forwarding (on|off) port (port_id)\n"
667 			"    Enable/disable E-tag based forwarding"
668 			" on a port\n\n"
669 
670 			"E-tag set filter add e-tag-id (value) dst-pool"
671 			" (pool_id) port (port_id)\n"
672 			"    Add an E-tag forwarding filter on a port\n\n"
673 
674 			"E-tag set filter del e-tag-id (value) port (port_id)\n"
675 			"    Delete an E-tag forwarding filter on a port\n\n"
676 
677 			"ddp add (port_id) (profile_path[,backup_profile_path])\n"
678 			"    Load a profile package on a port\n\n"
679 
680 			"ddp del (port_id) (backup_profile_path)\n"
681 			"    Delete a profile package from a port\n\n"
682 
683 			"ptype mapping get (port_id) (valid_only)\n"
684 			"    Get ptype mapping on a port\n\n"
685 
686 			"ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
687 			"    Replace target with the pkt_type in ptype mapping\n\n"
688 
689 			"ptype mapping reset (port_id)\n"
690 			"    Reset ptype mapping on a port\n\n"
691 
692 			"ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
693 			"    Update a ptype mapping item on a port\n\n"
694 
695 			"set port (port_id) ptype_mask (ptype_mask)\n"
696 			"    set packet types classification for a specific port\n\n"
697 
698 			"set port (port_id) queue-region region_id (value) "
699 			"queue_start_index (value) queue_num (value)\n"
700 			"    Set a queue region on a port\n\n"
701 
702 			"set port (port_id) queue-region region_id (value) "
703 			"flowtype (value)\n"
704 			"    Set a flowtype region index on a port\n\n"
705 
706 			"set port (port_id) queue-region UP (value) region_id (value)\n"
707 			"    Set the mapping of User Priority to "
708 			"queue region on a port\n\n"
709 
710 			"set port (port_id) queue-region flush (on|off)\n"
711 			"    flush all queue region related configuration\n\n"
712 
713 			"show port meter cap (port_id)\n"
714 			"    Show port meter capability information\n\n"
715 
716 			"add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
717 			"    meter profile add - srtcm rfc 2697\n\n"
718 
719 			"add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
720 			"    meter profile add - trtcm rfc 2698\n\n"
721 
722 			"add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
723 			"    meter profile add - trtcm rfc 4115\n\n"
724 
725 			"del port meter profile (port_id) (profile_id)\n"
726 			"    meter profile delete\n\n"
727 
728 			"create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
729 			"(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
730 			"(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
731 			"(dscp_tbl_entry63)]\n"
732 			"    meter create\n\n"
733 
734 			"enable port meter (port_id) (mtr_id)\n"
735 			"    meter enable\n\n"
736 
737 			"disable port meter (port_id) (mtr_id)\n"
738 			"    meter disable\n\n"
739 
740 			"del port meter (port_id) (mtr_id)\n"
741 			"    meter delete\n\n"
742 
743 			"set port meter profile (port_id) (mtr_id) (profile_id)\n"
744 			"    meter update meter profile\n\n"
745 
746 			"set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
747 			"(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
748 			"    update meter dscp table entries\n\n"
749 
750 			"set port meter policer action (port_id) (mtr_id) (action_mask)\n"
751 			"(action0) [(action1) (action2)]\n"
752 			"    meter update policer action\n\n"
753 
754 			"set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
755 			"    meter update stats\n\n"
756 
757 			"show port (port_id) queue-region\n"
758 			"    show all queue region related configuration info\n\n"
759 
760 			"set port (port_id) fec_mode auto|off|rs|baser\n"
761 			"    set fec mode for a specific port\n\n"
762 
763 			, list_pkt_forwarding_modes()
764 		);
765 	}
766 
767 	if (show_all || !strcmp(res->section, "ports")) {
768 
769 		cmdline_printf(
770 			cl,
771 			"\n"
772 			"Port Operations:\n"
773 			"----------------\n\n"
774 
775 			"port start (port_id|all)\n"
776 			"    Start all ports or port_id.\n\n"
777 
778 			"port stop (port_id|all)\n"
779 			"    Stop all ports or port_id.\n\n"
780 
781 			"port close (port_id|all)\n"
782 			"    Close all ports or port_id.\n\n"
783 
784 			"port reset (port_id|all)\n"
785 			"    Reset all ports or port_id.\n\n"
786 
787 			"port attach (ident)\n"
788 			"    Attach physical or virtual dev by pci address or virtual device name\n\n"
789 
790 			"port detach (port_id)\n"
791 			"    Detach physical or virtual dev by port_id\n\n"
792 
793 			"port config (port_id|all)"
794 			" speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
795 			" duplex (half|full|auto)\n"
796 			"    Set speed and duplex for all ports or port_id\n\n"
797 
798 			"port config (port_id|all) loopback (mode)\n"
799 			"    Set loopback mode for all ports or port_id\n\n"
800 
801 			"port config all (rxq|txq|rxd|txd) (value)\n"
802 			"    Set number for rxq/txq/rxd/txd.\n\n"
803 
804 			"port config all max-pkt-len (value)\n"
805 			"    Set the max packet length.\n\n"
806 
807 			"port config all max-lro-pkt-size (value)\n"
808 			"    Set the max LRO aggregated packet size.\n\n"
809 
810 			"port config all drop-en (on|off)\n"
811 			"    Enable or disable packet drop on all RX queues of all ports when no "
812 			"receive buffers available.\n\n"
813 
814 			"port config all rss (all|default|ip|tcp|udp|sctp|"
815 			"ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|level-default|"
816 			"level-outer|level-inner|<flowtype_id>)\n"
817 			"    Set the RSS mode.\n\n"
818 
819 			"port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
820 			"    Set the RSS redirection table.\n\n"
821 
822 			"port config (port_id) dcb vt (on|off) (traffic_class)"
823 			" pfc (on|off)\n"
824 			"    Set the DCB mode.\n\n"
825 
826 			"port config all burst (value)\n"
827 			"    Set the number of packets per burst.\n\n"
828 
829 			"port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
830 			" (value)\n"
831 			"    Set the ring prefetch/host/writeback threshold"
832 			" for tx/rx queue.\n\n"
833 
834 			"port config all (txfreet|txrst|rxfreet) (value)\n"
835 			"    Set free threshold for rx/tx, or set"
836 			" tx rs bit threshold.\n\n"
837 			"port config mtu X value\n"
838 			"    Set the MTU of port X to a given value\n\n"
839 
840 			"port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
841 			"    Set a rx/tx queue's ring size configuration, the new"
842 			" value will take effect after command that (re-)start the port"
843 			" or command that setup the specific queue\n\n"
844 
845 			"port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
846 			"    Start/stop a rx/tx queue of port X. Only take effect"
847 			" when port X is started\n\n"
848 
849 			"port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
850 			"    Switch on/off a deferred start of port X rx/tx queue. Only"
851 			" take effect when port X is stopped.\n\n"
852 
853 			"port (port_id) (rxq|txq) (queue_id) setup\n"
854 			"    Setup a rx/tx queue of port X.\n\n"
855 
856 			"port config (port_id|all) l2-tunnel E-tag ether-type"
857 			" (value)\n"
858 			"    Set the value of E-tag ether-type.\n\n"
859 
860 			"port config (port_id|all) l2-tunnel E-tag"
861 			" (enable|disable)\n"
862 			"    Enable/disable the E-tag support.\n\n"
863 
864 			"port config (port_id) pctype mapping reset\n"
865 			"    Reset flow type to pctype mapping on a port\n\n"
866 
867 			"port config (port_id) pctype mapping update"
868 			" (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
869 			"    Update a flow type to pctype mapping item on a port\n\n"
870 
871 			"port config (port_id) pctype (pctype_id) hash_inset|"
872 			"fdir_inset|fdir_flx_inset get|set|clear field\n"
873 			" (field_idx)\n"
874 			"    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
875 
876 			"port config (port_id) pctype (pctype_id) hash_inset|"
877 			"fdir_inset|fdir_flx_inset clear all"
878 			"    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
879 
880 			"port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
881 			"    Add/remove UDP tunnel port for tunneling offload\n\n"
882 
883 			"port config <port_id> rx_offload vlan_strip|"
884 			"ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
885 			"outer_ipv4_cksum|macsec_strip|header_split|"
886 			"vlan_filter|vlan_extend|jumbo_frame|"
887 			"scatter|timestamp|security|keep_crc on|off\n"
888 			"     Enable or disable a per port Rx offloading"
889 			" on all Rx queues of a port\n\n"
890 
891 			"port (port_id) rxq (queue_id) rx_offload vlan_strip|"
892 			"ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
893 			"outer_ipv4_cksum|macsec_strip|header_split|"
894 			"vlan_filter|vlan_extend|jumbo_frame|"
895 			"scatter|timestamp|security|keep_crc on|off\n"
896 			"    Enable or disable a per queue Rx offloading"
897 			" only on a specific Rx queue\n\n"
898 
899 			"port config (port_id) tx_offload vlan_insert|"
900 			"ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
901 			"udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
902 			"gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
903 			"macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
904 			"security on|off\n"
905 			"    Enable or disable a per port Tx offloading"
906 			" on all Tx queues of a port\n\n"
907 
908 			"port (port_id) txq (queue_id) tx_offload vlan_insert|"
909 			"ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
910 			"udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
911 			"gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
912 			"|mt_lockfree|multi_segs|mbuf_fast_free|security"
913 			" on|off\n"
914 			"    Enable or disable a per queue Tx offloading"
915 			" only on a specific Tx queue\n\n"
916 
917 			"bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
918 			"    Load an eBPF program as a callback"
919 			" for particular RX/TX queue\n\n"
920 
921 			"bpf-unload rx|tx (port) (queue)\n"
922 			"    Unload previously loaded eBPF program"
923 			" for particular RX/TX queue\n\n"
924 
925 			"port config (port_id) tx_metadata (value)\n"
926 			"    Set Tx metadata value per port. Testpmd will add this value"
927 			" to any Tx packet sent from this port\n\n"
928 
929 			"port config (port_id) dynf (name) set|clear\n"
930 			"    Register a dynf and Set/clear this flag on Tx. "
931 			"Testpmd will set this value to any Tx packet "
932 			"sent from this port\n\n"
933 		);
934 	}
935 
936 	if (show_all || !strcmp(res->section, "registers")) {
937 
938 		cmdline_printf(
939 			cl,
940 			"\n"
941 			"Registers:\n"
942 			"----------\n\n"
943 
944 			"read reg (port_id) (address)\n"
945 			"    Display value of a port register.\n\n"
946 
947 			"read regfield (port_id) (address) (bit_x) (bit_y)\n"
948 			"    Display a port register bit field.\n\n"
949 
950 			"read regbit (port_id) (address) (bit_x)\n"
951 			"    Display a single port register bit.\n\n"
952 
953 			"write reg (port_id) (address) (value)\n"
954 			"    Set value of a port register.\n\n"
955 
956 			"write regfield (port_id) (address) (bit_x) (bit_y)"
957 			" (value)\n"
958 			"    Set bit field of a port register.\n\n"
959 
960 			"write regbit (port_id) (address) (bit_x) (value)\n"
961 			"    Set single bit value of a port register.\n\n"
962 		);
963 	}
964 	if (show_all || !strcmp(res->section, "filters")) {
965 
966 		cmdline_printf(
967 			cl,
968 			"\n"
969 			"filters:\n"
970 			"--------\n\n"
971 
972 			"ethertype_filter (port_id) (add|del)"
973 			" (mac_addr|mac_ignr) (mac_address) ethertype"
974 			" (ether_type) (drop|fwd) queue (queue_id)\n"
975 			"    Add/Del an ethertype filter.\n\n"
976 
977 			"2tuple_filter (port_id) (add|del)"
978 			" dst_port (dst_port_value) protocol (protocol_value)"
979 			" mask (mask_value) tcp_flags (tcp_flags_value)"
980 			" priority (prio_value) queue (queue_id)\n"
981 			"    Add/Del a 2tuple filter.\n\n"
982 
983 			"5tuple_filter (port_id) (add|del)"
984 			" dst_ip (dst_address) src_ip (src_address)"
985 			" dst_port (dst_port_value) src_port (src_port_value)"
986 			" protocol (protocol_value)"
987 			" mask (mask_value) tcp_flags (tcp_flags_value)"
988 			" priority (prio_value) queue (queue_id)\n"
989 			"    Add/Del a 5tuple filter.\n\n"
990 
991 			"syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
992 			"    Add/Del syn filter.\n\n"
993 
994 			"flex_filter (port_id) (add|del) len (len_value)"
995 			" bytes (bytes_value) mask (mask_value)"
996 			" priority (prio_value) queue (queue_id)\n"
997 			"    Add/Del a flex filter.\n\n"
998 
999 			"flow_director_filter (port_id) mode IP (add|del|update)"
1000 			" flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
1001 			" src (src_ip_address) dst (dst_ip_address)"
1002 			" tos (tos_value) proto (proto_value) ttl (ttl_value)"
1003 			" vlan (vlan_value) flexbytes (flexbytes_value)"
1004 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1005 			" fd_id (fd_id_value)\n"
1006 			"    Add/Del an IP type flow director filter.\n\n"
1007 
1008 			"flow_director_filter (port_id) mode IP (add|del|update)"
1009 			" flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
1010 			" src (src_ip_address) (src_port)"
1011 			" dst (dst_ip_address) (dst_port)"
1012 			" tos (tos_value) ttl (ttl_value)"
1013 			" vlan (vlan_value) flexbytes (flexbytes_value)"
1014 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1015 			" fd_id (fd_id_value)\n"
1016 			"    Add/Del an UDP/TCP type flow director filter.\n\n"
1017 
1018 			"flow_director_filter (port_id) mode IP (add|del|update)"
1019 			" flow (ipv4-sctp|ipv6-sctp)"
1020 			" src (src_ip_address) (src_port)"
1021 			" dst (dst_ip_address) (dst_port)"
1022 			" tag (verification_tag) "
1023 			" tos (tos_value) ttl (ttl_value)"
1024 			" vlan (vlan_value)"
1025 			" flexbytes (flexbytes_value) (drop|fwd)"
1026 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1027 			"    Add/Del a SCTP type flow director filter.\n\n"
1028 
1029 			"flow_director_filter (port_id) mode IP (add|del|update)"
1030 			" flow l2_payload ether (ethertype)"
1031 			" flexbytes (flexbytes_value) (drop|fwd)"
1032 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1033 			"    Add/Del a l2 payload type flow director filter.\n\n"
1034 
1035 			"flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1036 			" mac (mac_address) vlan (vlan_value)"
1037 			" flexbytes (flexbytes_value) (drop|fwd)"
1038 			" queue (queue_id) fd_id (fd_id_value)\n"
1039 			"    Add/Del a MAC-VLAN flow director filter.\n\n"
1040 
1041 			"flow_director_filter (port_id) mode Tunnel (add|del|update)"
1042 			" mac (mac_address) vlan (vlan_value)"
1043 			" tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1044 			" flexbytes (flexbytes_value) (drop|fwd)"
1045 			" queue (queue_id) fd_id (fd_id_value)\n"
1046 			"    Add/Del a Tunnel flow director filter.\n\n"
1047 
1048 			"flow_director_filter (port_id) mode raw (add|del|update)"
1049 			" flow (flow_id) (drop|fwd) queue (queue_id)"
1050 			" fd_id (fd_id_value) packet (packet file name)\n"
1051 			"    Add/Del a raw type flow director filter.\n\n"
1052 
1053 			"flush_flow_director (port_id)\n"
1054 			"    Flush all flow director entries of a device.\n\n"
1055 
1056 			"flow_director_mask (port_id) mode IP vlan (vlan_value)"
1057 			" src_mask (ipv4_src) (ipv6_src) (src_port)"
1058 			" dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1059 			"    Set flow director IP mask.\n\n"
1060 
1061 			"flow_director_mask (port_id) mode MAC-VLAN"
1062 			" vlan (vlan_value)\n"
1063 			"    Set flow director MAC-VLAN mask.\n\n"
1064 
1065 			"flow_director_mask (port_id) mode Tunnel"
1066 			" vlan (vlan_value) mac (mac_value)"
1067 			" tunnel-type (tunnel_type_value)"
1068 			" tunnel-id (tunnel_id_value)\n"
1069 			"    Set flow director Tunnel mask.\n\n"
1070 
1071 			"flow_director_flex_mask (port_id)"
1072 			" flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1073 			"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1074 			" (mask)\n"
1075 			"    Configure mask of flex payload.\n\n"
1076 
1077 			"flow_director_flex_payload (port_id)"
1078 			" (raw|l2|l3|l4) (config)\n"
1079 			"    Configure flex payload selection.\n\n"
1080 
1081 			"get_sym_hash_ena_per_port (port_id)\n"
1082 			"    get symmetric hash enable configuration per port.\n\n"
1083 
1084 			"set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1085 			"    set symmetric hash enable configuration per port"
1086 			" to enable or disable.\n\n"
1087 
1088 			"get_hash_global_config (port_id)\n"
1089 			"    Get the global configurations of hash filters.\n\n"
1090 
1091 			"set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1092 			" (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1093 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1094 			" (enable|disable)\n"
1095 			"    Set the global configurations of hash filters.\n\n"
1096 
1097 			"set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1098 			"ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1099 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1100 			"l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1101 			"src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1102 			"ipv6-next-header|udp-src-port|udp-dst-port|"
1103 			"tcp-src-port|tcp-dst-port|sctp-src-port|"
1104 			"sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1105 			"fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1106 			"fld-8th|none) (select|add)\n"
1107 			"    Set the input set for hash.\n\n"
1108 
1109 			"set_fdir_input_set (port_id) "
1110 			"(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1111 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1112 			"l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1113 			"dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1114 			"ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1115 			"udp-dst-port|tcp-src-port|tcp-dst-port|"
1116 			"sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1117 			" (select|add)\n"
1118 			"    Set the input set for FDir.\n\n"
1119 
1120 			"flow validate {port_id}"
1121 			" [group {group_id}] [priority {level}]"
1122 			" [ingress] [egress]"
1123 			" pattern {item} [/ {item} [...]] / end"
1124 			" actions {action} [/ {action} [...]] / end\n"
1125 			"    Check whether a flow rule can be created.\n\n"
1126 
1127 			"flow create {port_id}"
1128 			" [group {group_id}] [priority {level}]"
1129 			" [ingress] [egress]"
1130 			" pattern {item} [/ {item} [...]] / end"
1131 			" actions {action} [/ {action} [...]] / end\n"
1132 			"    Create a flow rule.\n\n"
1133 
1134 			"flow destroy {port_id} rule {rule_id} [...]\n"
1135 			"    Destroy specific flow rules.\n\n"
1136 
1137 			"flow flush {port_id}\n"
1138 			"    Destroy all flow rules.\n\n"
1139 
1140 			"flow query {port_id} {rule_id} {action}\n"
1141 			"    Query an existing flow rule.\n\n"
1142 
1143 			"flow list {port_id} [group {group_id}] [...]\n"
1144 			"    List existing flow rules sorted by priority,"
1145 			" filtered by group identifiers.\n\n"
1146 
1147 			"flow isolate {port_id} {boolean}\n"
1148 			"    Restrict ingress traffic to the defined"
1149 			" flow rules\n\n"
1150 
1151 			"flow aged {port_id} [destroy]\n"
1152 			"    List and destroy aged flows"
1153 			" flow rules\n\n"
1154 
1155 			"set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1156 			" (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1157 			" (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1158 			"       Configure the VXLAN encapsulation for flows.\n\n"
1159 
1160 			"set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1161 			" udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1162 			" ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1163 			" eth-dst (eth-dst)\n"
1164 			"       Configure the VXLAN encapsulation for flows.\n\n"
1165 
1166 			"set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1167 			" (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1168 			" ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1169 			" eth-dst (eth-dst)\n"
1170 			"       Configure the VXLAN encapsulation for flows.\n\n"
1171 
1172 			"set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1173 			" (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1174 			" (eth-dst)\n"
1175 			"       Configure the NVGRE encapsulation for flows.\n\n"
1176 
1177 			"set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1178 			" ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1179 			" eth-src (eth-src) eth-dst (eth-dst)\n"
1180 			"       Configure the NVGRE encapsulation for flows.\n\n"
1181 
1182 			"set raw_encap {flow items}\n"
1183 			"	Configure the encapsulation with raw data.\n\n"
1184 
1185 			"set raw_decap {flow items}\n"
1186 			"	Configure the decapsulation with raw data.\n\n"
1187 
1188 		);
1189 	}
1190 
1191 	if (show_all || !strcmp(res->section, "traffic_management")) {
1192 		cmdline_printf(
1193 			cl,
1194 			"\n"
1195 			"Traffic Management:\n"
1196 			"--------------\n"
1197 			"show port tm cap (port_id)\n"
1198 			"       Display the port TM capability.\n\n"
1199 
1200 			"show port tm level cap (port_id) (level_id)\n"
1201 			"       Display the port TM hierarchical level capability.\n\n"
1202 
1203 			"show port tm node cap (port_id) (node_id)\n"
1204 			"       Display the port TM node capability.\n\n"
1205 
1206 			"show port tm node type (port_id) (node_id)\n"
1207 			"       Display the port TM node type.\n\n"
1208 
1209 			"show port tm node stats (port_id) (node_id) (clear)\n"
1210 			"       Display the port TM node stats.\n\n"
1211 
1212 			"add port tm node shaper profile (port_id) (shaper_profile_id)"
1213 			" (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1214 			" (packet_length_adjust) (packet_mode)\n"
1215 			"       Add port tm node private shaper profile.\n\n"
1216 
1217 			"del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1218 			"       Delete port tm node private shaper profile.\n\n"
1219 
1220 			"add port tm node shared shaper (port_id) (shared_shaper_id)"
1221 			" (shaper_profile_id)\n"
1222 			"       Add/update port tm node shared shaper.\n\n"
1223 
1224 			"del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1225 			"       Delete port tm node shared shaper.\n\n"
1226 
1227 			"set port tm node shaper profile (port_id) (node_id)"
1228 			" (shaper_profile_id)\n"
1229 			"       Set port tm node shaper profile.\n\n"
1230 
1231 			"add port tm node wred profile (port_id) (wred_profile_id)"
1232 			" (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1233 			" (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1234 			" (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1235 			"       Add port tm node wred profile.\n\n"
1236 
1237 			"del port tm node wred profile (port_id) (wred_profile_id)\n"
1238 			"       Delete port tm node wred profile.\n\n"
1239 
1240 			"add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1241 			" (priority) (weight) (level_id) (shaper_profile_id)"
1242 			" (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1243 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1244 			"       Add port tm nonleaf node.\n\n"
1245 
1246 			"add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1247 			" (priority) (weight) (level_id) (shaper_profile_id)"
1248 			" (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1249 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1250 			"       Add port tm nonleaf node with pkt mode enabled.\n\n"
1251 
1252 			"add port tm leaf node (port_id) (node_id) (parent_node_id)"
1253 			" (priority) (weight) (level_id) (shaper_profile_id)"
1254 			" (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1255 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1256 			"       Add port tm leaf node.\n\n"
1257 
1258 			"del port tm node (port_id) (node_id)\n"
1259 			"       Delete port tm node.\n\n"
1260 
1261 			"set port tm node parent (port_id) (node_id) (parent_node_id)"
1262 			" (priority) (weight)\n"
1263 			"       Set port tm node parent.\n\n"
1264 
1265 			"suspend port tm node (port_id) (node_id)"
1266 			"       Suspend tm node.\n\n"
1267 
1268 			"resume port tm node (port_id) (node_id)"
1269 			"       Resume tm node.\n\n"
1270 
1271 			"port tm hierarchy commit (port_id) (clean_on_fail)\n"
1272 			"       Commit tm hierarchy.\n\n"
1273 
1274 			"set port tm mark ip_ecn (port) (green) (yellow)"
1275 			" (red)\n"
1276 			"    Enables/Disables the traffic management marking"
1277 			" for IP ECN (Explicit Congestion Notification)"
1278 			" packets on a given port\n\n"
1279 
1280 			"set port tm mark ip_dscp (port) (green) (yellow)"
1281 			" (red)\n"
1282 			"    Enables/Disables the traffic management marking"
1283 			" on the port for IP dscp packets\n\n"
1284 
1285 			"set port tm mark vlan_dei (port) (green) (yellow)"
1286 			" (red)\n"
1287 			"    Enables/Disables the traffic management marking"
1288 			" on the port for VLAN packets with DEI enabled\n\n"
1289 		);
1290 	}
1291 
1292 	if (show_all || !strcmp(res->section, "devices")) {
1293 		cmdline_printf(
1294 			cl,
1295 			"\n"
1296 			"Device Operations:\n"
1297 			"--------------\n"
1298 			"device detach (identifier)\n"
1299 			"       Detach device by identifier.\n\n"
1300 		);
1301 	}
1302 
1303 }
1304 
1305 cmdline_parse_token_string_t cmd_help_long_help =
1306 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1307 
1308 cmdline_parse_token_string_t cmd_help_long_section =
1309 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1310 			"all#control#display#config#"
1311 			"ports#registers#filters#traffic_management#devices");
1312 
1313 cmdline_parse_inst_t cmd_help_long = {
1314 	.f = cmd_help_long_parsed,
1315 	.data = NULL,
1316 	.help_str = "help all|control|display|config|ports|register|"
1317 		"filters|traffic_management|devices: "
1318 		"Show help",
1319 	.tokens = {
1320 		(void *)&cmd_help_long_help,
1321 		(void *)&cmd_help_long_section,
1322 		NULL,
1323 	},
1324 };
1325 
1326 
1327 /* *** start/stop/close all ports *** */
1328 struct cmd_operate_port_result {
1329 	cmdline_fixed_string_t keyword;
1330 	cmdline_fixed_string_t name;
1331 	cmdline_fixed_string_t value;
1332 };
1333 
1334 static void cmd_operate_port_parsed(void *parsed_result,
1335 				__rte_unused struct cmdline *cl,
1336 				__rte_unused void *data)
1337 {
1338 	struct cmd_operate_port_result *res = parsed_result;
1339 
1340 	if (!strcmp(res->name, "start"))
1341 		start_port(RTE_PORT_ALL);
1342 	else if (!strcmp(res->name, "stop"))
1343 		stop_port(RTE_PORT_ALL);
1344 	else if (!strcmp(res->name, "close"))
1345 		close_port(RTE_PORT_ALL);
1346 	else if (!strcmp(res->name, "reset"))
1347 		reset_port(RTE_PORT_ALL);
1348 	else
1349 		printf("Unknown parameter\n");
1350 }
1351 
1352 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1353 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1354 								"port");
1355 cmdline_parse_token_string_t cmd_operate_port_all_port =
1356 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1357 						"start#stop#close#reset");
1358 cmdline_parse_token_string_t cmd_operate_port_all_all =
1359 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1360 
1361 cmdline_parse_inst_t cmd_operate_port = {
1362 	.f = cmd_operate_port_parsed,
1363 	.data = NULL,
1364 	.help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1365 	.tokens = {
1366 		(void *)&cmd_operate_port_all_cmd,
1367 		(void *)&cmd_operate_port_all_port,
1368 		(void *)&cmd_operate_port_all_all,
1369 		NULL,
1370 	},
1371 };
1372 
1373 /* *** start/stop/close specific port *** */
1374 struct cmd_operate_specific_port_result {
1375 	cmdline_fixed_string_t keyword;
1376 	cmdline_fixed_string_t name;
1377 	uint8_t value;
1378 };
1379 
1380 static void cmd_operate_specific_port_parsed(void *parsed_result,
1381 			__rte_unused struct cmdline *cl,
1382 				__rte_unused void *data)
1383 {
1384 	struct cmd_operate_specific_port_result *res = parsed_result;
1385 
1386 	if (!strcmp(res->name, "start"))
1387 		start_port(res->value);
1388 	else if (!strcmp(res->name, "stop"))
1389 		stop_port(res->value);
1390 	else if (!strcmp(res->name, "close"))
1391 		close_port(res->value);
1392 	else if (!strcmp(res->name, "reset"))
1393 		reset_port(res->value);
1394 	else
1395 		printf("Unknown parameter\n");
1396 }
1397 
1398 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1399 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1400 							keyword, "port");
1401 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1402 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1403 						name, "start#stop#close#reset");
1404 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1405 	TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1406 							value, UINT8);
1407 
1408 cmdline_parse_inst_t cmd_operate_specific_port = {
1409 	.f = cmd_operate_specific_port_parsed,
1410 	.data = NULL,
1411 	.help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1412 	.tokens = {
1413 		(void *)&cmd_operate_specific_port_cmd,
1414 		(void *)&cmd_operate_specific_port_port,
1415 		(void *)&cmd_operate_specific_port_id,
1416 		NULL,
1417 	},
1418 };
1419 
1420 /* *** enable port setup (after attach) via iterator or event *** */
1421 struct cmd_set_port_setup_on_result {
1422 	cmdline_fixed_string_t set;
1423 	cmdline_fixed_string_t port;
1424 	cmdline_fixed_string_t setup;
1425 	cmdline_fixed_string_t on;
1426 	cmdline_fixed_string_t mode;
1427 };
1428 
1429 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1430 				__rte_unused struct cmdline *cl,
1431 				__rte_unused void *data)
1432 {
1433 	struct cmd_set_port_setup_on_result *res = parsed_result;
1434 
1435 	if (strcmp(res->mode, "event") == 0)
1436 		setup_on_probe_event = true;
1437 	else if (strcmp(res->mode, "iterator") == 0)
1438 		setup_on_probe_event = false;
1439 	else
1440 		printf("Unknown mode\n");
1441 }
1442 
1443 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1444 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1445 			set, "set");
1446 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1447 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1448 			port, "port");
1449 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1450 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1451 			setup, "setup");
1452 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1453 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1454 			on, "on");
1455 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1456 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1457 			mode, "iterator#event");
1458 
1459 cmdline_parse_inst_t cmd_set_port_setup_on = {
1460 	.f = cmd_set_port_setup_on_parsed,
1461 	.data = NULL,
1462 	.help_str = "set port setup on iterator|event",
1463 	.tokens = {
1464 		(void *)&cmd_set_port_setup_on_set,
1465 		(void *)&cmd_set_port_setup_on_port,
1466 		(void *)&cmd_set_port_setup_on_setup,
1467 		(void *)&cmd_set_port_setup_on_on,
1468 		(void *)&cmd_set_port_setup_on_mode,
1469 		NULL,
1470 	},
1471 };
1472 
1473 /* *** attach a specified port *** */
1474 struct cmd_operate_attach_port_result {
1475 	cmdline_fixed_string_t port;
1476 	cmdline_fixed_string_t keyword;
1477 	cmdline_multi_string_t identifier;
1478 };
1479 
1480 static void cmd_operate_attach_port_parsed(void *parsed_result,
1481 				__rte_unused struct cmdline *cl,
1482 				__rte_unused void *data)
1483 {
1484 	struct cmd_operate_attach_port_result *res = parsed_result;
1485 
1486 	if (!strcmp(res->keyword, "attach"))
1487 		attach_port(res->identifier);
1488 	else
1489 		printf("Unknown parameter\n");
1490 }
1491 
1492 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1493 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1494 			port, "port");
1495 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1496 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1497 			keyword, "attach");
1498 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1499 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1500 			identifier, TOKEN_STRING_MULTI);
1501 
1502 cmdline_parse_inst_t cmd_operate_attach_port = {
1503 	.f = cmd_operate_attach_port_parsed,
1504 	.data = NULL,
1505 	.help_str = "port attach <identifier>: "
1506 		"(identifier: pci address or virtual dev name)",
1507 	.tokens = {
1508 		(void *)&cmd_operate_attach_port_port,
1509 		(void *)&cmd_operate_attach_port_keyword,
1510 		(void *)&cmd_operate_attach_port_identifier,
1511 		NULL,
1512 	},
1513 };
1514 
1515 /* *** detach a specified port *** */
1516 struct cmd_operate_detach_port_result {
1517 	cmdline_fixed_string_t port;
1518 	cmdline_fixed_string_t keyword;
1519 	portid_t port_id;
1520 };
1521 
1522 static void cmd_operate_detach_port_parsed(void *parsed_result,
1523 				__rte_unused struct cmdline *cl,
1524 				__rte_unused void *data)
1525 {
1526 	struct cmd_operate_detach_port_result *res = parsed_result;
1527 
1528 	if (!strcmp(res->keyword, "detach")) {
1529 		RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1530 		detach_port_device(res->port_id);
1531 	} else {
1532 		printf("Unknown parameter\n");
1533 	}
1534 }
1535 
1536 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1537 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1538 			port, "port");
1539 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1540 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1541 			keyword, "detach");
1542 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1543 	TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1544 			port_id, UINT16);
1545 
1546 cmdline_parse_inst_t cmd_operate_detach_port = {
1547 	.f = cmd_operate_detach_port_parsed,
1548 	.data = NULL,
1549 	.help_str = "port detach <port_id>",
1550 	.tokens = {
1551 		(void *)&cmd_operate_detach_port_port,
1552 		(void *)&cmd_operate_detach_port_keyword,
1553 		(void *)&cmd_operate_detach_port_port_id,
1554 		NULL,
1555 	},
1556 };
1557 
1558 /* *** detach device by identifier *** */
1559 struct cmd_operate_detach_device_result {
1560 	cmdline_fixed_string_t device;
1561 	cmdline_fixed_string_t keyword;
1562 	cmdline_fixed_string_t identifier;
1563 };
1564 
1565 static void cmd_operate_detach_device_parsed(void *parsed_result,
1566 				__rte_unused struct cmdline *cl,
1567 				__rte_unused void *data)
1568 {
1569 	struct cmd_operate_detach_device_result *res = parsed_result;
1570 
1571 	if (!strcmp(res->keyword, "detach"))
1572 		detach_devargs(res->identifier);
1573 	else
1574 		printf("Unknown parameter\n");
1575 }
1576 
1577 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1578 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1579 			device, "device");
1580 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1581 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1582 			keyword, "detach");
1583 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1584 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1585 			identifier, NULL);
1586 
1587 cmdline_parse_inst_t cmd_operate_detach_device = {
1588 	.f = cmd_operate_detach_device_parsed,
1589 	.data = NULL,
1590 	.help_str = "device detach <identifier>:"
1591 		"(identifier: pci address or virtual dev name)",
1592 	.tokens = {
1593 		(void *)&cmd_operate_detach_device_device,
1594 		(void *)&cmd_operate_detach_device_keyword,
1595 		(void *)&cmd_operate_detach_device_identifier,
1596 		NULL,
1597 	},
1598 };
1599 /* *** configure speed for all ports *** */
1600 struct cmd_config_speed_all {
1601 	cmdline_fixed_string_t port;
1602 	cmdline_fixed_string_t keyword;
1603 	cmdline_fixed_string_t all;
1604 	cmdline_fixed_string_t item1;
1605 	cmdline_fixed_string_t item2;
1606 	cmdline_fixed_string_t value1;
1607 	cmdline_fixed_string_t value2;
1608 };
1609 
1610 static int
1611 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1612 {
1613 
1614 	int duplex;
1615 
1616 	if (!strcmp(duplexstr, "half")) {
1617 		duplex = ETH_LINK_HALF_DUPLEX;
1618 	} else if (!strcmp(duplexstr, "full")) {
1619 		duplex = ETH_LINK_FULL_DUPLEX;
1620 	} else if (!strcmp(duplexstr, "auto")) {
1621 		duplex = ETH_LINK_FULL_DUPLEX;
1622 	} else {
1623 		printf("Unknown duplex parameter\n");
1624 		return -1;
1625 	}
1626 
1627 	if (!strcmp(speedstr, "10")) {
1628 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1629 				ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1630 	} else if (!strcmp(speedstr, "100")) {
1631 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1632 				ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1633 	} else {
1634 		if (duplex != ETH_LINK_FULL_DUPLEX) {
1635 			printf("Invalid speed/duplex parameters\n");
1636 			return -1;
1637 		}
1638 		if (!strcmp(speedstr, "1000")) {
1639 			*speed = ETH_LINK_SPEED_1G;
1640 		} else if (!strcmp(speedstr, "10000")) {
1641 			*speed = ETH_LINK_SPEED_10G;
1642 		} else if (!strcmp(speedstr, "25000")) {
1643 			*speed = ETH_LINK_SPEED_25G;
1644 		} else if (!strcmp(speedstr, "40000")) {
1645 			*speed = ETH_LINK_SPEED_40G;
1646 		} else if (!strcmp(speedstr, "50000")) {
1647 			*speed = ETH_LINK_SPEED_50G;
1648 		} else if (!strcmp(speedstr, "100000")) {
1649 			*speed = ETH_LINK_SPEED_100G;
1650 		} else if (!strcmp(speedstr, "200000")) {
1651 			*speed = ETH_LINK_SPEED_200G;
1652 		} else if (!strcmp(speedstr, "auto")) {
1653 			*speed = ETH_LINK_SPEED_AUTONEG;
1654 		} else {
1655 			printf("Unknown speed parameter\n");
1656 			return -1;
1657 		}
1658 	}
1659 
1660 	return 0;
1661 }
1662 
1663 static void
1664 cmd_config_speed_all_parsed(void *parsed_result,
1665 			__rte_unused struct cmdline *cl,
1666 			__rte_unused void *data)
1667 {
1668 	struct cmd_config_speed_all *res = parsed_result;
1669 	uint32_t link_speed;
1670 	portid_t pid;
1671 
1672 	if (!all_ports_stopped()) {
1673 		printf("Please stop all ports first\n");
1674 		return;
1675 	}
1676 
1677 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1678 			&link_speed) < 0)
1679 		return;
1680 
1681 	RTE_ETH_FOREACH_DEV(pid) {
1682 		ports[pid].dev_conf.link_speeds = link_speed;
1683 	}
1684 
1685 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1686 }
1687 
1688 cmdline_parse_token_string_t cmd_config_speed_all_port =
1689 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1690 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1691 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1692 							"config");
1693 cmdline_parse_token_string_t cmd_config_speed_all_all =
1694 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1695 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1696 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1697 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1698 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1699 				"10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1700 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1701 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1702 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1703 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1704 						"half#full#auto");
1705 
1706 cmdline_parse_inst_t cmd_config_speed_all = {
1707 	.f = cmd_config_speed_all_parsed,
1708 	.data = NULL,
1709 	.help_str = "port config all speed "
1710 		"10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1711 							"half|full|auto",
1712 	.tokens = {
1713 		(void *)&cmd_config_speed_all_port,
1714 		(void *)&cmd_config_speed_all_keyword,
1715 		(void *)&cmd_config_speed_all_all,
1716 		(void *)&cmd_config_speed_all_item1,
1717 		(void *)&cmd_config_speed_all_value1,
1718 		(void *)&cmd_config_speed_all_item2,
1719 		(void *)&cmd_config_speed_all_value2,
1720 		NULL,
1721 	},
1722 };
1723 
1724 /* *** configure speed for specific port *** */
1725 struct cmd_config_speed_specific {
1726 	cmdline_fixed_string_t port;
1727 	cmdline_fixed_string_t keyword;
1728 	portid_t id;
1729 	cmdline_fixed_string_t item1;
1730 	cmdline_fixed_string_t item2;
1731 	cmdline_fixed_string_t value1;
1732 	cmdline_fixed_string_t value2;
1733 };
1734 
1735 static void
1736 cmd_config_speed_specific_parsed(void *parsed_result,
1737 				__rte_unused struct cmdline *cl,
1738 				__rte_unused void *data)
1739 {
1740 	struct cmd_config_speed_specific *res = parsed_result;
1741 	uint32_t link_speed;
1742 
1743 	if (!all_ports_stopped()) {
1744 		printf("Please stop all ports first\n");
1745 		return;
1746 	}
1747 
1748 	if (port_id_is_invalid(res->id, ENABLED_WARN))
1749 		return;
1750 
1751 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1752 			&link_speed) < 0)
1753 		return;
1754 
1755 	ports[res->id].dev_conf.link_speeds = link_speed;
1756 
1757 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1758 }
1759 
1760 
1761 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1762 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1763 								"port");
1764 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1765 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1766 								"config");
1767 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1768 	TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1769 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1770 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1771 								"speed");
1772 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1773 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1774 				"10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1775 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1776 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1777 								"duplex");
1778 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1779 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1780 							"half#full#auto");
1781 
1782 cmdline_parse_inst_t cmd_config_speed_specific = {
1783 	.f = cmd_config_speed_specific_parsed,
1784 	.data = NULL,
1785 	.help_str = "port config <port_id> speed "
1786 		"10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1787 							"half|full|auto",
1788 	.tokens = {
1789 		(void *)&cmd_config_speed_specific_port,
1790 		(void *)&cmd_config_speed_specific_keyword,
1791 		(void *)&cmd_config_speed_specific_id,
1792 		(void *)&cmd_config_speed_specific_item1,
1793 		(void *)&cmd_config_speed_specific_value1,
1794 		(void *)&cmd_config_speed_specific_item2,
1795 		(void *)&cmd_config_speed_specific_value2,
1796 		NULL,
1797 	},
1798 };
1799 
1800 /* *** configure loopback for all ports *** */
1801 struct cmd_config_loopback_all {
1802 	cmdline_fixed_string_t port;
1803 	cmdline_fixed_string_t keyword;
1804 	cmdline_fixed_string_t all;
1805 	cmdline_fixed_string_t item;
1806 	uint32_t mode;
1807 };
1808 
1809 static void
1810 cmd_config_loopback_all_parsed(void *parsed_result,
1811 			__rte_unused struct cmdline *cl,
1812 			__rte_unused void *data)
1813 {
1814 	struct cmd_config_loopback_all *res = parsed_result;
1815 	portid_t pid;
1816 
1817 	if (!all_ports_stopped()) {
1818 		printf("Please stop all ports first\n");
1819 		return;
1820 	}
1821 
1822 	RTE_ETH_FOREACH_DEV(pid) {
1823 		ports[pid].dev_conf.lpbk_mode = res->mode;
1824 	}
1825 
1826 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1827 }
1828 
1829 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1830 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1831 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1832 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1833 							"config");
1834 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1835 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1836 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1837 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1838 							"loopback");
1839 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1840 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1841 
1842 cmdline_parse_inst_t cmd_config_loopback_all = {
1843 	.f = cmd_config_loopback_all_parsed,
1844 	.data = NULL,
1845 	.help_str = "port config all loopback <mode>",
1846 	.tokens = {
1847 		(void *)&cmd_config_loopback_all_port,
1848 		(void *)&cmd_config_loopback_all_keyword,
1849 		(void *)&cmd_config_loopback_all_all,
1850 		(void *)&cmd_config_loopback_all_item,
1851 		(void *)&cmd_config_loopback_all_mode,
1852 		NULL,
1853 	},
1854 };
1855 
1856 /* *** configure loopback for specific port *** */
1857 struct cmd_config_loopback_specific {
1858 	cmdline_fixed_string_t port;
1859 	cmdline_fixed_string_t keyword;
1860 	uint16_t port_id;
1861 	cmdline_fixed_string_t item;
1862 	uint32_t mode;
1863 };
1864 
1865 static void
1866 cmd_config_loopback_specific_parsed(void *parsed_result,
1867 				__rte_unused struct cmdline *cl,
1868 				__rte_unused void *data)
1869 {
1870 	struct cmd_config_loopback_specific *res = parsed_result;
1871 
1872 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1873 		return;
1874 
1875 	if (!port_is_stopped(res->port_id)) {
1876 		printf("Please stop port %u first\n", res->port_id);
1877 		return;
1878 	}
1879 
1880 	ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1881 
1882 	cmd_reconfig_device_queue(res->port_id, 1, 1);
1883 }
1884 
1885 
1886 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1887 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1888 								"port");
1889 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1890 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1891 								"config");
1892 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1893 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1894 								UINT16);
1895 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1896 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1897 								"loopback");
1898 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1899 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1900 			      UINT32);
1901 
1902 cmdline_parse_inst_t cmd_config_loopback_specific = {
1903 	.f = cmd_config_loopback_specific_parsed,
1904 	.data = NULL,
1905 	.help_str = "port config <port_id> loopback <mode>",
1906 	.tokens = {
1907 		(void *)&cmd_config_loopback_specific_port,
1908 		(void *)&cmd_config_loopback_specific_keyword,
1909 		(void *)&cmd_config_loopback_specific_id,
1910 		(void *)&cmd_config_loopback_specific_item,
1911 		(void *)&cmd_config_loopback_specific_mode,
1912 		NULL,
1913 	},
1914 };
1915 
1916 /* *** configure txq/rxq, txd/rxd *** */
1917 struct cmd_config_rx_tx {
1918 	cmdline_fixed_string_t port;
1919 	cmdline_fixed_string_t keyword;
1920 	cmdline_fixed_string_t all;
1921 	cmdline_fixed_string_t name;
1922 	uint16_t value;
1923 };
1924 
1925 static void
1926 cmd_config_rx_tx_parsed(void *parsed_result,
1927 			__rte_unused struct cmdline *cl,
1928 			__rte_unused void *data)
1929 {
1930 	struct cmd_config_rx_tx *res = parsed_result;
1931 
1932 	if (!all_ports_stopped()) {
1933 		printf("Please stop all ports first\n");
1934 		return;
1935 	}
1936 	if (!strcmp(res->name, "rxq")) {
1937 		if (!res->value && !nb_txq) {
1938 			printf("Warning: Either rx or tx queues should be non zero\n");
1939 			return;
1940 		}
1941 		if (check_nb_rxq(res->value) != 0)
1942 			return;
1943 		nb_rxq = res->value;
1944 	}
1945 	else if (!strcmp(res->name, "txq")) {
1946 		if (!res->value && !nb_rxq) {
1947 			printf("Warning: Either rx or tx queues should be non zero\n");
1948 			return;
1949 		}
1950 		if (check_nb_txq(res->value) != 0)
1951 			return;
1952 		nb_txq = res->value;
1953 	}
1954 	else if (!strcmp(res->name, "rxd")) {
1955 		if (check_nb_rxd(res->value) != 0)
1956 			return;
1957 		nb_rxd = res->value;
1958 	} else if (!strcmp(res->name, "txd")) {
1959 		if (check_nb_txd(res->value) != 0)
1960 			return;
1961 
1962 		nb_txd = res->value;
1963 	} else {
1964 		printf("Unknown parameter\n");
1965 		return;
1966 	}
1967 
1968 	fwd_config_setup();
1969 
1970 	init_port_config();
1971 
1972 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1973 }
1974 
1975 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1976 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1977 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1978 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1979 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1980 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1981 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1982 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1983 						"rxq#txq#rxd#txd");
1984 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1985 	TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1986 
1987 cmdline_parse_inst_t cmd_config_rx_tx = {
1988 	.f = cmd_config_rx_tx_parsed,
1989 	.data = NULL,
1990 	.help_str = "port config all rxq|txq|rxd|txd <value>",
1991 	.tokens = {
1992 		(void *)&cmd_config_rx_tx_port,
1993 		(void *)&cmd_config_rx_tx_keyword,
1994 		(void *)&cmd_config_rx_tx_all,
1995 		(void *)&cmd_config_rx_tx_name,
1996 		(void *)&cmd_config_rx_tx_value,
1997 		NULL,
1998 	},
1999 };
2000 
2001 /* *** config max packet length *** */
2002 struct cmd_config_max_pkt_len_result {
2003 	cmdline_fixed_string_t port;
2004 	cmdline_fixed_string_t keyword;
2005 	cmdline_fixed_string_t all;
2006 	cmdline_fixed_string_t name;
2007 	uint32_t value;
2008 };
2009 
2010 static void
2011 cmd_config_max_pkt_len_parsed(void *parsed_result,
2012 				__rte_unused struct cmdline *cl,
2013 				__rte_unused void *data)
2014 {
2015 	struct cmd_config_max_pkt_len_result *res = parsed_result;
2016 	portid_t pid;
2017 
2018 	if (!all_ports_stopped()) {
2019 		printf("Please stop all ports first\n");
2020 		return;
2021 	}
2022 
2023 	RTE_ETH_FOREACH_DEV(pid) {
2024 		struct rte_port *port = &ports[pid];
2025 		uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2026 
2027 		if (!strcmp(res->name, "max-pkt-len")) {
2028 			if (res->value < RTE_ETHER_MIN_LEN) {
2029 				printf("max-pkt-len can not be less than %d\n",
2030 						RTE_ETHER_MIN_LEN);
2031 				return;
2032 			}
2033 			if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2034 				return;
2035 
2036 			port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2037 			if (res->value > RTE_ETHER_MAX_LEN)
2038 				rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2039 			else
2040 				rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2041 			port->dev_conf.rxmode.offloads = rx_offloads;
2042 		} else {
2043 			printf("Unknown parameter\n");
2044 			return;
2045 		}
2046 	}
2047 
2048 	init_port_config();
2049 
2050 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2051 }
2052 
2053 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2054 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2055 								"port");
2056 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2057 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2058 								"config");
2059 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2060 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2061 								"all");
2062 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2063 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2064 								"max-pkt-len");
2065 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2066 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2067 								UINT32);
2068 
2069 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2070 	.f = cmd_config_max_pkt_len_parsed,
2071 	.data = NULL,
2072 	.help_str = "port config all max-pkt-len <value>",
2073 	.tokens = {
2074 		(void *)&cmd_config_max_pkt_len_port,
2075 		(void *)&cmd_config_max_pkt_len_keyword,
2076 		(void *)&cmd_config_max_pkt_len_all,
2077 		(void *)&cmd_config_max_pkt_len_name,
2078 		(void *)&cmd_config_max_pkt_len_value,
2079 		NULL,
2080 	},
2081 };
2082 
2083 /* *** config max LRO aggregated packet size *** */
2084 struct cmd_config_max_lro_pkt_size_result {
2085 	cmdline_fixed_string_t port;
2086 	cmdline_fixed_string_t keyword;
2087 	cmdline_fixed_string_t all;
2088 	cmdline_fixed_string_t name;
2089 	uint32_t value;
2090 };
2091 
2092 static void
2093 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2094 				__rte_unused struct cmdline *cl,
2095 				__rte_unused void *data)
2096 {
2097 	struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2098 	portid_t pid;
2099 
2100 	if (!all_ports_stopped()) {
2101 		printf("Please stop all ports first\n");
2102 		return;
2103 	}
2104 
2105 	RTE_ETH_FOREACH_DEV(pid) {
2106 		struct rte_port *port = &ports[pid];
2107 
2108 		if (!strcmp(res->name, "max-lro-pkt-size")) {
2109 			if (res->value ==
2110 					port->dev_conf.rxmode.max_lro_pkt_size)
2111 				return;
2112 
2113 			port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2114 		} else {
2115 			printf("Unknown parameter\n");
2116 			return;
2117 		}
2118 	}
2119 
2120 	init_port_config();
2121 
2122 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2123 }
2124 
2125 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2126 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2127 				 port, "port");
2128 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2129 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2130 				 keyword, "config");
2131 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2132 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2133 				 all, "all");
2134 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2135 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2136 				 name, "max-lro-pkt-size");
2137 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2138 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2139 			      value, UINT32);
2140 
2141 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2142 	.f = cmd_config_max_lro_pkt_size_parsed,
2143 	.data = NULL,
2144 	.help_str = "port config all max-lro-pkt-size <value>",
2145 	.tokens = {
2146 		(void *)&cmd_config_max_lro_pkt_size_port,
2147 		(void *)&cmd_config_max_lro_pkt_size_keyword,
2148 		(void *)&cmd_config_max_lro_pkt_size_all,
2149 		(void *)&cmd_config_max_lro_pkt_size_name,
2150 		(void *)&cmd_config_max_lro_pkt_size_value,
2151 		NULL,
2152 	},
2153 };
2154 
2155 /* *** configure port MTU *** */
2156 struct cmd_config_mtu_result {
2157 	cmdline_fixed_string_t port;
2158 	cmdline_fixed_string_t keyword;
2159 	cmdline_fixed_string_t mtu;
2160 	portid_t port_id;
2161 	uint16_t value;
2162 };
2163 
2164 static void
2165 cmd_config_mtu_parsed(void *parsed_result,
2166 		      __rte_unused struct cmdline *cl,
2167 		      __rte_unused void *data)
2168 {
2169 	struct cmd_config_mtu_result *res = parsed_result;
2170 
2171 	if (res->value < RTE_ETHER_MIN_LEN) {
2172 		printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2173 		return;
2174 	}
2175 	port_mtu_set(res->port_id, res->value);
2176 }
2177 
2178 cmdline_parse_token_string_t cmd_config_mtu_port =
2179 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2180 				 "port");
2181 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2182 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2183 				 "config");
2184 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2185 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2186 				 "mtu");
2187 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2188 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2189 cmdline_parse_token_num_t cmd_config_mtu_value =
2190 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2191 
2192 cmdline_parse_inst_t cmd_config_mtu = {
2193 	.f = cmd_config_mtu_parsed,
2194 	.data = NULL,
2195 	.help_str = "port config mtu <port_id> <value>",
2196 	.tokens = {
2197 		(void *)&cmd_config_mtu_port,
2198 		(void *)&cmd_config_mtu_keyword,
2199 		(void *)&cmd_config_mtu_mtu,
2200 		(void *)&cmd_config_mtu_port_id,
2201 		(void *)&cmd_config_mtu_value,
2202 		NULL,
2203 	},
2204 };
2205 
2206 /* *** configure rx mode *** */
2207 struct cmd_config_rx_mode_flag {
2208 	cmdline_fixed_string_t port;
2209 	cmdline_fixed_string_t keyword;
2210 	cmdline_fixed_string_t all;
2211 	cmdline_fixed_string_t name;
2212 	cmdline_fixed_string_t value;
2213 };
2214 
2215 static void
2216 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2217 				__rte_unused struct cmdline *cl,
2218 				__rte_unused void *data)
2219 {
2220 	struct cmd_config_rx_mode_flag *res = parsed_result;
2221 
2222 	if (!all_ports_stopped()) {
2223 		printf("Please stop all ports first\n");
2224 		return;
2225 	}
2226 
2227 	if (!strcmp(res->name, "drop-en")) {
2228 		if (!strcmp(res->value, "on"))
2229 			rx_drop_en = 1;
2230 		else if (!strcmp(res->value, "off"))
2231 			rx_drop_en = 0;
2232 		else {
2233 			printf("Unknown parameter\n");
2234 			return;
2235 		}
2236 	} else {
2237 		printf("Unknown parameter\n");
2238 		return;
2239 	}
2240 
2241 	init_port_config();
2242 
2243 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2244 }
2245 
2246 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2247 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2248 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2249 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2250 								"config");
2251 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2252 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2253 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2254 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2255 					"drop-en");
2256 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2257 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2258 							"on#off");
2259 
2260 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2261 	.f = cmd_config_rx_mode_flag_parsed,
2262 	.data = NULL,
2263 	.help_str = "port config all drop-en on|off",
2264 	.tokens = {
2265 		(void *)&cmd_config_rx_mode_flag_port,
2266 		(void *)&cmd_config_rx_mode_flag_keyword,
2267 		(void *)&cmd_config_rx_mode_flag_all,
2268 		(void *)&cmd_config_rx_mode_flag_name,
2269 		(void *)&cmd_config_rx_mode_flag_value,
2270 		NULL,
2271 	},
2272 };
2273 
2274 /* *** configure rss *** */
2275 struct cmd_config_rss {
2276 	cmdline_fixed_string_t port;
2277 	cmdline_fixed_string_t keyword;
2278 	cmdline_fixed_string_t all;
2279 	cmdline_fixed_string_t name;
2280 	cmdline_fixed_string_t value;
2281 };
2282 
2283 static void
2284 cmd_config_rss_parsed(void *parsed_result,
2285 			__rte_unused struct cmdline *cl,
2286 			__rte_unused void *data)
2287 {
2288 	struct cmd_config_rss *res = parsed_result;
2289 	struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2290 	struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2291 	int use_default = 0;
2292 	int all_updated = 1;
2293 	int diag;
2294 	uint16_t i;
2295 	int ret;
2296 
2297 	if (!strcmp(res->value, "all"))
2298 		rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2299 			ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2300 			ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2301 			ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2302 	else if (!strcmp(res->value, "eth"))
2303 		rss_conf.rss_hf = ETH_RSS_ETH;
2304 	else if (!strcmp(res->value, "vlan"))
2305 		rss_conf.rss_hf = ETH_RSS_VLAN;
2306 	else if (!strcmp(res->value, "ip"))
2307 		rss_conf.rss_hf = ETH_RSS_IP;
2308 	else if (!strcmp(res->value, "udp"))
2309 		rss_conf.rss_hf = ETH_RSS_UDP;
2310 	else if (!strcmp(res->value, "tcp"))
2311 		rss_conf.rss_hf = ETH_RSS_TCP;
2312 	else if (!strcmp(res->value, "sctp"))
2313 		rss_conf.rss_hf = ETH_RSS_SCTP;
2314 	else if (!strcmp(res->value, "ether"))
2315 		rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2316 	else if (!strcmp(res->value, "port"))
2317 		rss_conf.rss_hf = ETH_RSS_PORT;
2318 	else if (!strcmp(res->value, "vxlan"))
2319 		rss_conf.rss_hf = ETH_RSS_VXLAN;
2320 	else if (!strcmp(res->value, "geneve"))
2321 		rss_conf.rss_hf = ETH_RSS_GENEVE;
2322 	else if (!strcmp(res->value, "nvgre"))
2323 		rss_conf.rss_hf = ETH_RSS_NVGRE;
2324 	else if (!strcmp(res->value, "l3-pre32"))
2325 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2326 	else if (!strcmp(res->value, "l3-pre40"))
2327 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2328 	else if (!strcmp(res->value, "l3-pre48"))
2329 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2330 	else if (!strcmp(res->value, "l3-pre56"))
2331 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2332 	else if (!strcmp(res->value, "l3-pre64"))
2333 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2334 	else if (!strcmp(res->value, "l3-pre96"))
2335 		rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2336 	else if (!strcmp(res->value, "l3-src-only"))
2337 		rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2338 	else if (!strcmp(res->value, "l3-dst-only"))
2339 		rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2340 	else if (!strcmp(res->value, "l4-src-only"))
2341 		rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2342 	else if (!strcmp(res->value, "l4-dst-only"))
2343 		rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2344 	else if (!strcmp(res->value, "l2-src-only"))
2345 		rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2346 	else if (!strcmp(res->value, "l2-dst-only"))
2347 		rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2348 	else if (!strcmp(res->value, "l2tpv3"))
2349 		rss_conf.rss_hf = ETH_RSS_L2TPV3;
2350 	else if (!strcmp(res->value, "esp"))
2351 		rss_conf.rss_hf = ETH_RSS_ESP;
2352 	else if (!strcmp(res->value, "ah"))
2353 		rss_conf.rss_hf = ETH_RSS_AH;
2354 	else if (!strcmp(res->value, "pfcp"))
2355 		rss_conf.rss_hf = ETH_RSS_PFCP;
2356 	else if (!strcmp(res->value, "pppoe"))
2357 		rss_conf.rss_hf = ETH_RSS_PPPOE;
2358 	else if (!strcmp(res->value, "gtpu"))
2359 		rss_conf.rss_hf = ETH_RSS_GTPU;
2360 	else if (!strcmp(res->value, "none"))
2361 		rss_conf.rss_hf = 0;
2362 	else if (!strcmp(res->value, "level-default")) {
2363 		rss_hf &= (~ETH_RSS_LEVEL_MASK);
2364 		rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2365 	} else if (!strcmp(res->value, "level-outer")) {
2366 		rss_hf &= (~ETH_RSS_LEVEL_MASK);
2367 		rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2368 	} else if (!strcmp(res->value, "level-inner")) {
2369 		rss_hf &= (~ETH_RSS_LEVEL_MASK);
2370 		rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2371 	} else if (!strcmp(res->value, "default"))
2372 		use_default = 1;
2373 	else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2374 						atoi(res->value) < 64)
2375 		rss_conf.rss_hf = 1ULL << atoi(res->value);
2376 	else {
2377 		printf("Unknown parameter\n");
2378 		return;
2379 	}
2380 	rss_conf.rss_key = NULL;
2381 	/* Update global configuration for RSS types. */
2382 	RTE_ETH_FOREACH_DEV(i) {
2383 		struct rte_eth_rss_conf local_rss_conf;
2384 
2385 		ret = eth_dev_info_get_print_err(i, &dev_info);
2386 		if (ret != 0)
2387 			return;
2388 
2389 		if (use_default)
2390 			rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2391 
2392 		local_rss_conf = rss_conf;
2393 		local_rss_conf.rss_hf = rss_conf.rss_hf &
2394 			dev_info.flow_type_rss_offloads;
2395 		if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2396 			printf("Port %u modified RSS hash function based on hardware support,"
2397 				"requested:%#"PRIx64" configured:%#"PRIx64"\n",
2398 				i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2399 		}
2400 		diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2401 		if (diag < 0) {
2402 			all_updated = 0;
2403 			printf("Configuration of RSS hash at ethernet port %d "
2404 				"failed with error (%d): %s.\n",
2405 				i, -diag, strerror(-diag));
2406 		}
2407 	}
2408 	if (all_updated && !use_default) {
2409 		rss_hf = rss_conf.rss_hf;
2410 		printf("rss_hf %#"PRIx64"\n", rss_hf);
2411 	}
2412 }
2413 
2414 cmdline_parse_token_string_t cmd_config_rss_port =
2415 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2416 cmdline_parse_token_string_t cmd_config_rss_keyword =
2417 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2418 cmdline_parse_token_string_t cmd_config_rss_all =
2419 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2420 cmdline_parse_token_string_t cmd_config_rss_name =
2421 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2422 cmdline_parse_token_string_t cmd_config_rss_value =
2423 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2424 
2425 cmdline_parse_inst_t cmd_config_rss = {
2426 	.f = cmd_config_rss_parsed,
2427 	.data = NULL,
2428 	.help_str = "port config all rss "
2429 		"all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2430 		"nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2431 		"level-outer|level-inner|<flowtype_id>",
2432 	.tokens = {
2433 		(void *)&cmd_config_rss_port,
2434 		(void *)&cmd_config_rss_keyword,
2435 		(void *)&cmd_config_rss_all,
2436 		(void *)&cmd_config_rss_name,
2437 		(void *)&cmd_config_rss_value,
2438 		NULL,
2439 	},
2440 };
2441 
2442 /* *** configure rss hash key *** */
2443 struct cmd_config_rss_hash_key {
2444 	cmdline_fixed_string_t port;
2445 	cmdline_fixed_string_t config;
2446 	portid_t port_id;
2447 	cmdline_fixed_string_t rss_hash_key;
2448 	cmdline_fixed_string_t rss_type;
2449 	cmdline_fixed_string_t key;
2450 };
2451 
2452 static uint8_t
2453 hexa_digit_to_value(char hexa_digit)
2454 {
2455 	if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2456 		return (uint8_t) (hexa_digit - '0');
2457 	if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2458 		return (uint8_t) ((hexa_digit - 'a') + 10);
2459 	if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2460 		return (uint8_t) ((hexa_digit - 'A') + 10);
2461 	/* Invalid hexa digit */
2462 	return 0xFF;
2463 }
2464 
2465 static uint8_t
2466 parse_and_check_key_hexa_digit(char *key, int idx)
2467 {
2468 	uint8_t hexa_v;
2469 
2470 	hexa_v = hexa_digit_to_value(key[idx]);
2471 	if (hexa_v == 0xFF)
2472 		printf("invalid key: character %c at position %d is not a "
2473 		       "valid hexa digit\n", key[idx], idx);
2474 	return hexa_v;
2475 }
2476 
2477 static void
2478 cmd_config_rss_hash_key_parsed(void *parsed_result,
2479 			       __rte_unused struct cmdline *cl,
2480 			       __rte_unused void *data)
2481 {
2482 	struct cmd_config_rss_hash_key *res = parsed_result;
2483 	uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2484 	uint8_t xdgt0;
2485 	uint8_t xdgt1;
2486 	int i;
2487 	struct rte_eth_dev_info dev_info;
2488 	uint8_t hash_key_size;
2489 	uint32_t key_len;
2490 	int ret;
2491 
2492 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2493 	if (ret != 0)
2494 		return;
2495 
2496 	if (dev_info.hash_key_size > 0 &&
2497 			dev_info.hash_key_size <= sizeof(hash_key))
2498 		hash_key_size = dev_info.hash_key_size;
2499 	else {
2500 		printf("dev_info did not provide a valid hash key size\n");
2501 		return;
2502 	}
2503 	/* Check the length of the RSS hash key */
2504 	key_len = strlen(res->key);
2505 	if (key_len != (hash_key_size * 2)) {
2506 		printf("key length: %d invalid - key must be a string of %d"
2507 			   " hexa-decimal numbers\n",
2508 			   (int) key_len, hash_key_size * 2);
2509 		return;
2510 	}
2511 	/* Translate RSS hash key into binary representation */
2512 	for (i = 0; i < hash_key_size; i++) {
2513 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2514 		if (xdgt0 == 0xFF)
2515 			return;
2516 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2517 		if (xdgt1 == 0xFF)
2518 			return;
2519 		hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2520 	}
2521 	port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2522 			hash_key_size);
2523 }
2524 
2525 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2526 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2527 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2528 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2529 				 "config");
2530 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2531 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2532 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2533 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2534 				 rss_hash_key, "rss-hash-key");
2535 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2536 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2537 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2538 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2539 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2540 				 "ipv6-tcp-ex#ipv6-udp-ex#"
2541 				 "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2542 				 "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2543 				 "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2544 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2545 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2546 
2547 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2548 	.f = cmd_config_rss_hash_key_parsed,
2549 	.data = NULL,
2550 	.help_str = "port config <port_id> rss-hash-key "
2551 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2552 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2553 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2554 		"l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2555 		"l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2556 		"l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2557 		"<string of hex digits (variable length, NIC dependent)>",
2558 	.tokens = {
2559 		(void *)&cmd_config_rss_hash_key_port,
2560 		(void *)&cmd_config_rss_hash_key_config,
2561 		(void *)&cmd_config_rss_hash_key_port_id,
2562 		(void *)&cmd_config_rss_hash_key_rss_hash_key,
2563 		(void *)&cmd_config_rss_hash_key_rss_type,
2564 		(void *)&cmd_config_rss_hash_key_value,
2565 		NULL,
2566 	},
2567 };
2568 
2569 /* *** configure port rxq/txq ring size *** */
2570 struct cmd_config_rxtx_ring_size {
2571 	cmdline_fixed_string_t port;
2572 	cmdline_fixed_string_t config;
2573 	portid_t portid;
2574 	cmdline_fixed_string_t rxtxq;
2575 	uint16_t qid;
2576 	cmdline_fixed_string_t rsize;
2577 	uint16_t size;
2578 };
2579 
2580 static void
2581 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2582 				 __rte_unused struct cmdline *cl,
2583 				 __rte_unused void *data)
2584 {
2585 	struct cmd_config_rxtx_ring_size *res = parsed_result;
2586 	struct rte_port *port;
2587 	uint8_t isrx;
2588 
2589 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2590 		return;
2591 
2592 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2593 		printf("Invalid port id\n");
2594 		return;
2595 	}
2596 
2597 	port = &ports[res->portid];
2598 
2599 	if (!strcmp(res->rxtxq, "rxq"))
2600 		isrx = 1;
2601 	else if (!strcmp(res->rxtxq, "txq"))
2602 		isrx = 0;
2603 	else {
2604 		printf("Unknown parameter\n");
2605 		return;
2606 	}
2607 
2608 	if (isrx && rx_queue_id_is_invalid(res->qid))
2609 		return;
2610 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2611 		return;
2612 
2613 	if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2614 		printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2615 		       rx_free_thresh);
2616 		return;
2617 	}
2618 
2619 	if (isrx)
2620 		port->nb_rx_desc[res->qid] = res->size;
2621 	else
2622 		port->nb_tx_desc[res->qid] = res->size;
2623 
2624 	cmd_reconfig_device_queue(res->portid, 0, 1);
2625 }
2626 
2627 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2628 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2629 				 port, "port");
2630 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2631 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2632 				 config, "config");
2633 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2634 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2635 				 portid, UINT16);
2636 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2637 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2638 				 rxtxq, "rxq#txq");
2639 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2640 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2641 			      qid, UINT16);
2642 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2643 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2644 				 rsize, "ring_size");
2645 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2646 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2647 			      size, UINT16);
2648 
2649 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2650 	.f = cmd_config_rxtx_ring_size_parsed,
2651 	.data = NULL,
2652 	.help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2653 	.tokens = {
2654 		(void *)&cmd_config_rxtx_ring_size_port,
2655 		(void *)&cmd_config_rxtx_ring_size_config,
2656 		(void *)&cmd_config_rxtx_ring_size_portid,
2657 		(void *)&cmd_config_rxtx_ring_size_rxtxq,
2658 		(void *)&cmd_config_rxtx_ring_size_qid,
2659 		(void *)&cmd_config_rxtx_ring_size_rsize,
2660 		(void *)&cmd_config_rxtx_ring_size_size,
2661 		NULL,
2662 	},
2663 };
2664 
2665 /* *** configure port rxq/txq start/stop *** */
2666 struct cmd_config_rxtx_queue {
2667 	cmdline_fixed_string_t port;
2668 	portid_t portid;
2669 	cmdline_fixed_string_t rxtxq;
2670 	uint16_t qid;
2671 	cmdline_fixed_string_t opname;
2672 };
2673 
2674 static void
2675 cmd_config_rxtx_queue_parsed(void *parsed_result,
2676 			__rte_unused struct cmdline *cl,
2677 			__rte_unused void *data)
2678 {
2679 	struct cmd_config_rxtx_queue *res = parsed_result;
2680 	uint8_t isrx;
2681 	uint8_t isstart;
2682 	int ret = 0;
2683 
2684 	if (test_done == 0) {
2685 		printf("Please stop forwarding first\n");
2686 		return;
2687 	}
2688 
2689 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2690 		return;
2691 
2692 	if (port_is_started(res->portid) != 1) {
2693 		printf("Please start port %u first\n", res->portid);
2694 		return;
2695 	}
2696 
2697 	if (!strcmp(res->rxtxq, "rxq"))
2698 		isrx = 1;
2699 	else if (!strcmp(res->rxtxq, "txq"))
2700 		isrx = 0;
2701 	else {
2702 		printf("Unknown parameter\n");
2703 		return;
2704 	}
2705 
2706 	if (isrx && rx_queue_id_is_invalid(res->qid))
2707 		return;
2708 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2709 		return;
2710 
2711 	if (!strcmp(res->opname, "start"))
2712 		isstart = 1;
2713 	else if (!strcmp(res->opname, "stop"))
2714 		isstart = 0;
2715 	else {
2716 		printf("Unknown parameter\n");
2717 		return;
2718 	}
2719 
2720 	if (isstart && isrx)
2721 		ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2722 	else if (!isstart && isrx)
2723 		ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2724 	else if (isstart && !isrx)
2725 		ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2726 	else
2727 		ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2728 
2729 	if (ret == -ENOTSUP)
2730 		printf("Function not supported in PMD driver\n");
2731 }
2732 
2733 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2734 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2735 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2736 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2737 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2738 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2739 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2740 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2741 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2742 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2743 						"start#stop");
2744 
2745 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2746 	.f = cmd_config_rxtx_queue_parsed,
2747 	.data = NULL,
2748 	.help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2749 	.tokens = {
2750 		(void *)&cmd_config_rxtx_queue_port,
2751 		(void *)&cmd_config_rxtx_queue_portid,
2752 		(void *)&cmd_config_rxtx_queue_rxtxq,
2753 		(void *)&cmd_config_rxtx_queue_qid,
2754 		(void *)&cmd_config_rxtx_queue_opname,
2755 		NULL,
2756 	},
2757 };
2758 
2759 /* *** configure port rxq/txq deferred start on/off *** */
2760 struct cmd_config_deferred_start_rxtx_queue {
2761 	cmdline_fixed_string_t port;
2762 	portid_t port_id;
2763 	cmdline_fixed_string_t rxtxq;
2764 	uint16_t qid;
2765 	cmdline_fixed_string_t opname;
2766 	cmdline_fixed_string_t state;
2767 };
2768 
2769 static void
2770 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2771 			__rte_unused struct cmdline *cl,
2772 			__rte_unused void *data)
2773 {
2774 	struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2775 	struct rte_port *port;
2776 	uint8_t isrx;
2777 	uint8_t ison;
2778 	uint8_t needreconfig = 0;
2779 
2780 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2781 		return;
2782 
2783 	if (port_is_started(res->port_id) != 0) {
2784 		printf("Please stop port %u first\n", res->port_id);
2785 		return;
2786 	}
2787 
2788 	port = &ports[res->port_id];
2789 
2790 	isrx = !strcmp(res->rxtxq, "rxq");
2791 
2792 	if (isrx && rx_queue_id_is_invalid(res->qid))
2793 		return;
2794 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2795 		return;
2796 
2797 	ison = !strcmp(res->state, "on");
2798 
2799 	if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2800 		port->rx_conf[res->qid].rx_deferred_start = ison;
2801 		needreconfig = 1;
2802 	} else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2803 		port->tx_conf[res->qid].tx_deferred_start = ison;
2804 		needreconfig = 1;
2805 	}
2806 
2807 	if (needreconfig)
2808 		cmd_reconfig_device_queue(res->port_id, 0, 1);
2809 }
2810 
2811 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2812 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2813 						port, "port");
2814 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2815 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2816 						port_id, UINT16);
2817 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2818 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2819 						rxtxq, "rxq#txq");
2820 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2821 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2822 						qid, UINT16);
2823 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2824 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2825 						opname, "deferred_start");
2826 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2827 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2828 						state, "on#off");
2829 
2830 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2831 	.f = cmd_config_deferred_start_rxtx_queue_parsed,
2832 	.data = NULL,
2833 	.help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2834 	.tokens = {
2835 		(void *)&cmd_config_deferred_start_rxtx_queue_port,
2836 		(void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2837 		(void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2838 		(void *)&cmd_config_deferred_start_rxtx_queue_qid,
2839 		(void *)&cmd_config_deferred_start_rxtx_queue_opname,
2840 		(void *)&cmd_config_deferred_start_rxtx_queue_state,
2841 		NULL,
2842 	},
2843 };
2844 
2845 /* *** configure port rxq/txq setup *** */
2846 struct cmd_setup_rxtx_queue {
2847 	cmdline_fixed_string_t port;
2848 	portid_t portid;
2849 	cmdline_fixed_string_t rxtxq;
2850 	uint16_t qid;
2851 	cmdline_fixed_string_t setup;
2852 };
2853 
2854 /* Common CLI fields for queue setup */
2855 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2856 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2857 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2858 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2859 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2860 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2861 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2862 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2863 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2864 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2865 
2866 static void
2867 cmd_setup_rxtx_queue_parsed(
2868 	void *parsed_result,
2869 	__rte_unused struct cmdline *cl,
2870 	__rte_unused void *data)
2871 {
2872 	struct cmd_setup_rxtx_queue *res = parsed_result;
2873 	struct rte_port *port;
2874 	struct rte_mempool *mp;
2875 	unsigned int socket_id;
2876 	uint8_t isrx = 0;
2877 	int ret;
2878 
2879 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2880 		return;
2881 
2882 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2883 		printf("Invalid port id\n");
2884 		return;
2885 	}
2886 
2887 	if (!strcmp(res->rxtxq, "rxq"))
2888 		isrx = 1;
2889 	else if (!strcmp(res->rxtxq, "txq"))
2890 		isrx = 0;
2891 	else {
2892 		printf("Unknown parameter\n");
2893 		return;
2894 	}
2895 
2896 	if (isrx && rx_queue_id_is_invalid(res->qid)) {
2897 		printf("Invalid rx queue\n");
2898 		return;
2899 	} else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2900 		printf("Invalid tx queue\n");
2901 		return;
2902 	}
2903 
2904 	port = &ports[res->portid];
2905 	if (isrx) {
2906 		socket_id = rxring_numa[res->portid];
2907 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2908 			socket_id = port->socket_id;
2909 
2910 		mp = mbuf_pool_find(socket_id);
2911 		if (mp == NULL) {
2912 			printf("Failed to setup RX queue: "
2913 				"No mempool allocation"
2914 				" on the socket %d\n",
2915 				rxring_numa[res->portid]);
2916 			return;
2917 		}
2918 		ret = rte_eth_rx_queue_setup(res->portid,
2919 					     res->qid,
2920 					     port->nb_rx_desc[res->qid],
2921 					     socket_id,
2922 					     &port->rx_conf[res->qid],
2923 					     mp);
2924 		if (ret)
2925 			printf("Failed to setup RX queue\n");
2926 	} else {
2927 		socket_id = txring_numa[res->portid];
2928 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2929 			socket_id = port->socket_id;
2930 
2931 		ret = rte_eth_tx_queue_setup(res->portid,
2932 					     res->qid,
2933 					     port->nb_tx_desc[res->qid],
2934 					     socket_id,
2935 					     &port->tx_conf[res->qid]);
2936 		if (ret)
2937 			printf("Failed to setup TX queue\n");
2938 	}
2939 }
2940 
2941 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2942 	.f = cmd_setup_rxtx_queue_parsed,
2943 	.data = NULL,
2944 	.help_str = "port <port_id> rxq|txq <queue_idx> setup",
2945 	.tokens = {
2946 		(void *)&cmd_setup_rxtx_queue_port,
2947 		(void *)&cmd_setup_rxtx_queue_portid,
2948 		(void *)&cmd_setup_rxtx_queue_rxtxq,
2949 		(void *)&cmd_setup_rxtx_queue_qid,
2950 		(void *)&cmd_setup_rxtx_queue_setup,
2951 		NULL,
2952 	},
2953 };
2954 
2955 
2956 /* *** Configure RSS RETA *** */
2957 struct cmd_config_rss_reta {
2958 	cmdline_fixed_string_t port;
2959 	cmdline_fixed_string_t keyword;
2960 	portid_t port_id;
2961 	cmdline_fixed_string_t name;
2962 	cmdline_fixed_string_t list_name;
2963 	cmdline_fixed_string_t list_of_items;
2964 };
2965 
2966 static int
2967 parse_reta_config(const char *str,
2968 		  struct rte_eth_rss_reta_entry64 *reta_conf,
2969 		  uint16_t nb_entries)
2970 {
2971 	int i;
2972 	unsigned size;
2973 	uint16_t hash_index, idx, shift;
2974 	uint16_t nb_queue;
2975 	char s[256];
2976 	const char *p, *p0 = str;
2977 	char *end;
2978 	enum fieldnames {
2979 		FLD_HASH_INDEX = 0,
2980 		FLD_QUEUE,
2981 		_NUM_FLD
2982 	};
2983 	unsigned long int_fld[_NUM_FLD];
2984 	char *str_fld[_NUM_FLD];
2985 
2986 	while ((p = strchr(p0,'(')) != NULL) {
2987 		++p;
2988 		if((p0 = strchr(p,')')) == NULL)
2989 			return -1;
2990 
2991 		size = p0 - p;
2992 		if(size >= sizeof(s))
2993 			return -1;
2994 
2995 		snprintf(s, sizeof(s), "%.*s", size, p);
2996 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2997 			return -1;
2998 		for (i = 0; i < _NUM_FLD; i++) {
2999 			errno = 0;
3000 			int_fld[i] = strtoul(str_fld[i], &end, 0);
3001 			if (errno != 0 || end == str_fld[i] ||
3002 					int_fld[i] > 65535)
3003 				return -1;
3004 		}
3005 
3006 		hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
3007 		nb_queue = (uint16_t)int_fld[FLD_QUEUE];
3008 
3009 		if (hash_index >= nb_entries) {
3010 			printf("Invalid RETA hash index=%d\n", hash_index);
3011 			return -1;
3012 		}
3013 
3014 		idx = hash_index / RTE_RETA_GROUP_SIZE;
3015 		shift = hash_index % RTE_RETA_GROUP_SIZE;
3016 		reta_conf[idx].mask |= (1ULL << shift);
3017 		reta_conf[idx].reta[shift] = nb_queue;
3018 	}
3019 
3020 	return 0;
3021 }
3022 
3023 static void
3024 cmd_set_rss_reta_parsed(void *parsed_result,
3025 			__rte_unused struct cmdline *cl,
3026 			__rte_unused void *data)
3027 {
3028 	int ret;
3029 	struct rte_eth_dev_info dev_info;
3030 	struct rte_eth_rss_reta_entry64 reta_conf[8];
3031 	struct cmd_config_rss_reta *res = parsed_result;
3032 
3033 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3034 	if (ret != 0)
3035 		return;
3036 
3037 	if (dev_info.reta_size == 0) {
3038 		printf("Redirection table size is 0 which is "
3039 					"invalid for RSS\n");
3040 		return;
3041 	} else
3042 		printf("The reta size of port %d is %u\n",
3043 			res->port_id, dev_info.reta_size);
3044 	if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3045 		printf("Currently do not support more than %u entries of "
3046 			"redirection table\n", ETH_RSS_RETA_SIZE_512);
3047 		return;
3048 	}
3049 
3050 	memset(reta_conf, 0, sizeof(reta_conf));
3051 	if (!strcmp(res->list_name, "reta")) {
3052 		if (parse_reta_config(res->list_of_items, reta_conf,
3053 						dev_info.reta_size)) {
3054 			printf("Invalid RSS Redirection Table "
3055 					"config entered\n");
3056 			return;
3057 		}
3058 		ret = rte_eth_dev_rss_reta_update(res->port_id,
3059 				reta_conf, dev_info.reta_size);
3060 		if (ret != 0)
3061 			printf("Bad redirection table parameter, "
3062 					"return code = %d \n", ret);
3063 	}
3064 }
3065 
3066 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3067 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3068 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3069 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3070 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3071 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3072 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3073 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3074 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3075 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3076 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3077         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3078                                  NULL);
3079 cmdline_parse_inst_t cmd_config_rss_reta = {
3080 	.f = cmd_set_rss_reta_parsed,
3081 	.data = NULL,
3082 	.help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3083 	.tokens = {
3084 		(void *)&cmd_config_rss_reta_port,
3085 		(void *)&cmd_config_rss_reta_keyword,
3086 		(void *)&cmd_config_rss_reta_port_id,
3087 		(void *)&cmd_config_rss_reta_name,
3088 		(void *)&cmd_config_rss_reta_list_name,
3089 		(void *)&cmd_config_rss_reta_list_of_items,
3090 		NULL,
3091 	},
3092 };
3093 
3094 /* *** SHOW PORT RETA INFO *** */
3095 struct cmd_showport_reta {
3096 	cmdline_fixed_string_t show;
3097 	cmdline_fixed_string_t port;
3098 	portid_t port_id;
3099 	cmdline_fixed_string_t rss;
3100 	cmdline_fixed_string_t reta;
3101 	uint16_t size;
3102 	cmdline_fixed_string_t list_of_items;
3103 };
3104 
3105 static int
3106 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3107 			   uint16_t nb_entries,
3108 			   char *str)
3109 {
3110 	uint32_t size;
3111 	const char *p, *p0 = str;
3112 	char s[256];
3113 	char *end;
3114 	char *str_fld[8];
3115 	uint16_t i;
3116 	uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3117 			RTE_RETA_GROUP_SIZE;
3118 	int ret;
3119 
3120 	p = strchr(p0, '(');
3121 	if (p == NULL)
3122 		return -1;
3123 	p++;
3124 	p0 = strchr(p, ')');
3125 	if (p0 == NULL)
3126 		return -1;
3127 	size = p0 - p;
3128 	if (size >= sizeof(s)) {
3129 		printf("The string size exceeds the internal buffer size\n");
3130 		return -1;
3131 	}
3132 	snprintf(s, sizeof(s), "%.*s", size, p);
3133 	ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3134 	if (ret <= 0 || ret != num) {
3135 		printf("The bits of masks do not match the number of "
3136 					"reta entries: %u\n", num);
3137 		return -1;
3138 	}
3139 	for (i = 0; i < ret; i++)
3140 		conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3141 
3142 	return 0;
3143 }
3144 
3145 static void
3146 cmd_showport_reta_parsed(void *parsed_result,
3147 			 __rte_unused struct cmdline *cl,
3148 			 __rte_unused void *data)
3149 {
3150 	struct cmd_showport_reta *res = parsed_result;
3151 	struct rte_eth_rss_reta_entry64 reta_conf[8];
3152 	struct rte_eth_dev_info dev_info;
3153 	uint16_t max_reta_size;
3154 	int ret;
3155 
3156 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3157 	if (ret != 0)
3158 		return;
3159 
3160 	max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3161 	if (res->size == 0 || res->size > max_reta_size) {
3162 		printf("Invalid redirection table size: %u (1-%u)\n",
3163 			res->size, max_reta_size);
3164 		return;
3165 	}
3166 
3167 	memset(reta_conf, 0, sizeof(reta_conf));
3168 	if (showport_parse_reta_config(reta_conf, res->size,
3169 				res->list_of_items) < 0) {
3170 		printf("Invalid string: %s for reta masks\n",
3171 					res->list_of_items);
3172 		return;
3173 	}
3174 	port_rss_reta_info(res->port_id, reta_conf, res->size);
3175 }
3176 
3177 cmdline_parse_token_string_t cmd_showport_reta_show =
3178 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3179 cmdline_parse_token_string_t cmd_showport_reta_port =
3180 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3181 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3182 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3183 cmdline_parse_token_string_t cmd_showport_reta_rss =
3184 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3185 cmdline_parse_token_string_t cmd_showport_reta_reta =
3186 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3187 cmdline_parse_token_num_t cmd_showport_reta_size =
3188 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3189 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3190 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3191 					list_of_items, NULL);
3192 
3193 cmdline_parse_inst_t cmd_showport_reta = {
3194 	.f = cmd_showport_reta_parsed,
3195 	.data = NULL,
3196 	.help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3197 	.tokens = {
3198 		(void *)&cmd_showport_reta_show,
3199 		(void *)&cmd_showport_reta_port,
3200 		(void *)&cmd_showport_reta_port_id,
3201 		(void *)&cmd_showport_reta_rss,
3202 		(void *)&cmd_showport_reta_reta,
3203 		(void *)&cmd_showport_reta_size,
3204 		(void *)&cmd_showport_reta_list_of_items,
3205 		NULL,
3206 	},
3207 };
3208 
3209 /* *** Show RSS hash configuration *** */
3210 struct cmd_showport_rss_hash {
3211 	cmdline_fixed_string_t show;
3212 	cmdline_fixed_string_t port;
3213 	portid_t port_id;
3214 	cmdline_fixed_string_t rss_hash;
3215 	cmdline_fixed_string_t rss_type;
3216 	cmdline_fixed_string_t key; /* optional argument */
3217 };
3218 
3219 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3220 				__rte_unused struct cmdline *cl,
3221 				void *show_rss_key)
3222 {
3223 	struct cmd_showport_rss_hash *res = parsed_result;
3224 
3225 	port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3226 }
3227 
3228 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3229 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3230 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3231 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3232 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3233 	TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3234 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3235 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3236 				 "rss-hash");
3237 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3238 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3239 
3240 cmdline_parse_inst_t cmd_showport_rss_hash = {
3241 	.f = cmd_showport_rss_hash_parsed,
3242 	.data = NULL,
3243 	.help_str = "show port <port_id> rss-hash",
3244 	.tokens = {
3245 		(void *)&cmd_showport_rss_hash_show,
3246 		(void *)&cmd_showport_rss_hash_port,
3247 		(void *)&cmd_showport_rss_hash_port_id,
3248 		(void *)&cmd_showport_rss_hash_rss_hash,
3249 		NULL,
3250 	},
3251 };
3252 
3253 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3254 	.f = cmd_showport_rss_hash_parsed,
3255 	.data = (void *)1,
3256 	.help_str = "show port <port_id> rss-hash key",
3257 	.tokens = {
3258 		(void *)&cmd_showport_rss_hash_show,
3259 		(void *)&cmd_showport_rss_hash_port,
3260 		(void *)&cmd_showport_rss_hash_port_id,
3261 		(void *)&cmd_showport_rss_hash_rss_hash,
3262 		(void *)&cmd_showport_rss_hash_rss_key,
3263 		NULL,
3264 	},
3265 };
3266 
3267 /* *** Configure DCB *** */
3268 struct cmd_config_dcb {
3269 	cmdline_fixed_string_t port;
3270 	cmdline_fixed_string_t config;
3271 	portid_t port_id;
3272 	cmdline_fixed_string_t dcb;
3273 	cmdline_fixed_string_t vt;
3274 	cmdline_fixed_string_t vt_en;
3275 	uint8_t num_tcs;
3276 	cmdline_fixed_string_t pfc;
3277 	cmdline_fixed_string_t pfc_en;
3278 };
3279 
3280 static void
3281 cmd_config_dcb_parsed(void *parsed_result,
3282                         __rte_unused struct cmdline *cl,
3283                         __rte_unused void *data)
3284 {
3285 	struct cmd_config_dcb *res = parsed_result;
3286 	portid_t port_id = res->port_id;
3287 	struct rte_port *port;
3288 	uint8_t pfc_en;
3289 	int ret;
3290 
3291 	port = &ports[port_id];
3292 	/** Check if the port is not started **/
3293 	if (port->port_status != RTE_PORT_STOPPED) {
3294 		printf("Please stop port %d first\n", port_id);
3295 		return;
3296 	}
3297 
3298 	if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3299 		printf("The invalid number of traffic class,"
3300 			" only 4 or 8 allowed.\n");
3301 		return;
3302 	}
3303 
3304 	if (nb_fwd_lcores < res->num_tcs) {
3305 		printf("nb_cores shouldn't be less than number of TCs.\n");
3306 		return;
3307 	}
3308 	if (!strncmp(res->pfc_en, "on", 2))
3309 		pfc_en = 1;
3310 	else
3311 		pfc_en = 0;
3312 
3313 	/* DCB in VT mode */
3314 	if (!strncmp(res->vt_en, "on", 2))
3315 		ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3316 				(enum rte_eth_nb_tcs)res->num_tcs,
3317 				pfc_en);
3318 	else
3319 		ret = init_port_dcb_config(port_id, DCB_ENABLED,
3320 				(enum rte_eth_nb_tcs)res->num_tcs,
3321 				pfc_en);
3322 
3323 
3324 	if (ret != 0) {
3325 		printf("Cannot initialize network ports.\n");
3326 		return;
3327 	}
3328 
3329 	cmd_reconfig_device_queue(port_id, 1, 1);
3330 }
3331 
3332 cmdline_parse_token_string_t cmd_config_dcb_port =
3333         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3334 cmdline_parse_token_string_t cmd_config_dcb_config =
3335         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3336 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3337 	TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3338 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3339         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3340 cmdline_parse_token_string_t cmd_config_dcb_vt =
3341         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3342 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3343         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3344 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3345         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3346 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3347         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3348 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3349         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3350 
3351 cmdline_parse_inst_t cmd_config_dcb = {
3352 	.f = cmd_config_dcb_parsed,
3353 	.data = NULL,
3354 	.help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3355 	.tokens = {
3356 		(void *)&cmd_config_dcb_port,
3357 		(void *)&cmd_config_dcb_config,
3358 		(void *)&cmd_config_dcb_port_id,
3359 		(void *)&cmd_config_dcb_dcb,
3360 		(void *)&cmd_config_dcb_vt,
3361 		(void *)&cmd_config_dcb_vt_en,
3362 		(void *)&cmd_config_dcb_num_tcs,
3363 		(void *)&cmd_config_dcb_pfc,
3364 		(void *)&cmd_config_dcb_pfc_en,
3365                 NULL,
3366         },
3367 };
3368 
3369 /* *** configure number of packets per burst *** */
3370 struct cmd_config_burst {
3371 	cmdline_fixed_string_t port;
3372 	cmdline_fixed_string_t keyword;
3373 	cmdline_fixed_string_t all;
3374 	cmdline_fixed_string_t name;
3375 	uint16_t value;
3376 };
3377 
3378 static void
3379 cmd_config_burst_parsed(void *parsed_result,
3380 			__rte_unused struct cmdline *cl,
3381 			__rte_unused void *data)
3382 {
3383 	struct cmd_config_burst *res = parsed_result;
3384 	struct rte_eth_dev_info dev_info;
3385 	uint16_t rec_nb_pkts;
3386 	int ret;
3387 
3388 	if (!all_ports_stopped()) {
3389 		printf("Please stop all ports first\n");
3390 		return;
3391 	}
3392 
3393 	if (!strcmp(res->name, "burst")) {
3394 		if (res->value == 0) {
3395 			/* If user gives a value of zero, query the PMD for
3396 			 * its recommended Rx burst size. Testpmd uses a single
3397 			 * size for all ports, so assume all ports are the same
3398 			 * NIC model and use the values from Port 0.
3399 			 */
3400 			ret = eth_dev_info_get_print_err(0, &dev_info);
3401 			if (ret != 0)
3402 				return;
3403 
3404 			rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3405 
3406 			if (rec_nb_pkts == 0) {
3407 				printf("PMD does not recommend a burst size.\n"
3408 					"User provided value must be between"
3409 					" 1 and %d\n", MAX_PKT_BURST);
3410 				return;
3411 			} else if (rec_nb_pkts > MAX_PKT_BURST) {
3412 				printf("PMD recommended burst size of %d"
3413 					" exceeds maximum value of %d\n",
3414 					rec_nb_pkts, MAX_PKT_BURST);
3415 				return;
3416 			}
3417 			printf("Using PMD-provided burst value of %d\n",
3418 				rec_nb_pkts);
3419 			nb_pkt_per_burst = rec_nb_pkts;
3420 		} else if (res->value > MAX_PKT_BURST) {
3421 			printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3422 			return;
3423 		} else
3424 			nb_pkt_per_burst = res->value;
3425 	} else {
3426 		printf("Unknown parameter\n");
3427 		return;
3428 	}
3429 
3430 	init_port_config();
3431 
3432 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3433 }
3434 
3435 cmdline_parse_token_string_t cmd_config_burst_port =
3436 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3437 cmdline_parse_token_string_t cmd_config_burst_keyword =
3438 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3439 cmdline_parse_token_string_t cmd_config_burst_all =
3440 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3441 cmdline_parse_token_string_t cmd_config_burst_name =
3442 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3443 cmdline_parse_token_num_t cmd_config_burst_value =
3444 	TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3445 
3446 cmdline_parse_inst_t cmd_config_burst = {
3447 	.f = cmd_config_burst_parsed,
3448 	.data = NULL,
3449 	.help_str = "port config all burst <value>",
3450 	.tokens = {
3451 		(void *)&cmd_config_burst_port,
3452 		(void *)&cmd_config_burst_keyword,
3453 		(void *)&cmd_config_burst_all,
3454 		(void *)&cmd_config_burst_name,
3455 		(void *)&cmd_config_burst_value,
3456 		NULL,
3457 	},
3458 };
3459 
3460 /* *** configure rx/tx queues *** */
3461 struct cmd_config_thresh {
3462 	cmdline_fixed_string_t port;
3463 	cmdline_fixed_string_t keyword;
3464 	cmdline_fixed_string_t all;
3465 	cmdline_fixed_string_t name;
3466 	uint8_t value;
3467 };
3468 
3469 static void
3470 cmd_config_thresh_parsed(void *parsed_result,
3471 			__rte_unused struct cmdline *cl,
3472 			__rte_unused void *data)
3473 {
3474 	struct cmd_config_thresh *res = parsed_result;
3475 
3476 	if (!all_ports_stopped()) {
3477 		printf("Please stop all ports first\n");
3478 		return;
3479 	}
3480 
3481 	if (!strcmp(res->name, "txpt"))
3482 		tx_pthresh = res->value;
3483 	else if(!strcmp(res->name, "txht"))
3484 		tx_hthresh = res->value;
3485 	else if(!strcmp(res->name, "txwt"))
3486 		tx_wthresh = res->value;
3487 	else if(!strcmp(res->name, "rxpt"))
3488 		rx_pthresh = res->value;
3489 	else if(!strcmp(res->name, "rxht"))
3490 		rx_hthresh = res->value;
3491 	else if(!strcmp(res->name, "rxwt"))
3492 		rx_wthresh = res->value;
3493 	else {
3494 		printf("Unknown parameter\n");
3495 		return;
3496 	}
3497 
3498 	init_port_config();
3499 
3500 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3501 }
3502 
3503 cmdline_parse_token_string_t cmd_config_thresh_port =
3504 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3505 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3506 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3507 cmdline_parse_token_string_t cmd_config_thresh_all =
3508 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3509 cmdline_parse_token_string_t cmd_config_thresh_name =
3510 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3511 				"txpt#txht#txwt#rxpt#rxht#rxwt");
3512 cmdline_parse_token_num_t cmd_config_thresh_value =
3513 	TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3514 
3515 cmdline_parse_inst_t cmd_config_thresh = {
3516 	.f = cmd_config_thresh_parsed,
3517 	.data = NULL,
3518 	.help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3519 	.tokens = {
3520 		(void *)&cmd_config_thresh_port,
3521 		(void *)&cmd_config_thresh_keyword,
3522 		(void *)&cmd_config_thresh_all,
3523 		(void *)&cmd_config_thresh_name,
3524 		(void *)&cmd_config_thresh_value,
3525 		NULL,
3526 	},
3527 };
3528 
3529 /* *** configure free/rs threshold *** */
3530 struct cmd_config_threshold {
3531 	cmdline_fixed_string_t port;
3532 	cmdline_fixed_string_t keyword;
3533 	cmdline_fixed_string_t all;
3534 	cmdline_fixed_string_t name;
3535 	uint16_t value;
3536 };
3537 
3538 static void
3539 cmd_config_threshold_parsed(void *parsed_result,
3540 			__rte_unused struct cmdline *cl,
3541 			__rte_unused void *data)
3542 {
3543 	struct cmd_config_threshold *res = parsed_result;
3544 
3545 	if (!all_ports_stopped()) {
3546 		printf("Please stop all ports first\n");
3547 		return;
3548 	}
3549 
3550 	if (!strcmp(res->name, "txfreet"))
3551 		tx_free_thresh = res->value;
3552 	else if (!strcmp(res->name, "txrst"))
3553 		tx_rs_thresh = res->value;
3554 	else if (!strcmp(res->name, "rxfreet"))
3555 		rx_free_thresh = res->value;
3556 	else {
3557 		printf("Unknown parameter\n");
3558 		return;
3559 	}
3560 
3561 	init_port_config();
3562 
3563 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3564 }
3565 
3566 cmdline_parse_token_string_t cmd_config_threshold_port =
3567 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3568 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3569 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3570 								"config");
3571 cmdline_parse_token_string_t cmd_config_threshold_all =
3572 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3573 cmdline_parse_token_string_t cmd_config_threshold_name =
3574 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3575 						"txfreet#txrst#rxfreet");
3576 cmdline_parse_token_num_t cmd_config_threshold_value =
3577 	TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3578 
3579 cmdline_parse_inst_t cmd_config_threshold = {
3580 	.f = cmd_config_threshold_parsed,
3581 	.data = NULL,
3582 	.help_str = "port config all txfreet|txrst|rxfreet <value>",
3583 	.tokens = {
3584 		(void *)&cmd_config_threshold_port,
3585 		(void *)&cmd_config_threshold_keyword,
3586 		(void *)&cmd_config_threshold_all,
3587 		(void *)&cmd_config_threshold_name,
3588 		(void *)&cmd_config_threshold_value,
3589 		NULL,
3590 	},
3591 };
3592 
3593 /* *** stop *** */
3594 struct cmd_stop_result {
3595 	cmdline_fixed_string_t stop;
3596 };
3597 
3598 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3599 			    __rte_unused struct cmdline *cl,
3600 			    __rte_unused void *data)
3601 {
3602 	stop_packet_forwarding();
3603 }
3604 
3605 cmdline_parse_token_string_t cmd_stop_stop =
3606 	TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3607 
3608 cmdline_parse_inst_t cmd_stop = {
3609 	.f = cmd_stop_parsed,
3610 	.data = NULL,
3611 	.help_str = "stop: Stop packet forwarding",
3612 	.tokens = {
3613 		(void *)&cmd_stop_stop,
3614 		NULL,
3615 	},
3616 };
3617 
3618 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3619 
3620 unsigned int
3621 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3622 		unsigned int *parsed_items, int check_unique_values)
3623 {
3624 	unsigned int nb_item;
3625 	unsigned int value;
3626 	unsigned int i;
3627 	unsigned int j;
3628 	int value_ok;
3629 	char c;
3630 
3631 	/*
3632 	 * First parse all items in the list and store their value.
3633 	 */
3634 	value = 0;
3635 	nb_item = 0;
3636 	value_ok = 0;
3637 	for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3638 		c = str[i];
3639 		if ((c >= '0') && (c <= '9')) {
3640 			value = (unsigned int) (value * 10 + (c - '0'));
3641 			value_ok = 1;
3642 			continue;
3643 		}
3644 		if (c != ',') {
3645 			printf("character %c is not a decimal digit\n", c);
3646 			return 0;
3647 		}
3648 		if (! value_ok) {
3649 			printf("No valid value before comma\n");
3650 			return 0;
3651 		}
3652 		if (nb_item < max_items) {
3653 			parsed_items[nb_item] = value;
3654 			value_ok = 0;
3655 			value = 0;
3656 		}
3657 		nb_item++;
3658 	}
3659 	if (nb_item >= max_items) {
3660 		printf("Number of %s = %u > %u (maximum items)\n",
3661 		       item_name, nb_item + 1, max_items);
3662 		return 0;
3663 	}
3664 	parsed_items[nb_item++] = value;
3665 	if (! check_unique_values)
3666 		return nb_item;
3667 
3668 	/*
3669 	 * Then, check that all values in the list are differents.
3670 	 * No optimization here...
3671 	 */
3672 	for (i = 0; i < nb_item; i++) {
3673 		for (j = i + 1; j < nb_item; j++) {
3674 			if (parsed_items[j] == parsed_items[i]) {
3675 				printf("duplicated %s %u at index %u and %u\n",
3676 				       item_name, parsed_items[i], i, j);
3677 				return 0;
3678 			}
3679 		}
3680 	}
3681 	return nb_item;
3682 }
3683 
3684 struct cmd_set_list_result {
3685 	cmdline_fixed_string_t cmd_keyword;
3686 	cmdline_fixed_string_t list_name;
3687 	cmdline_fixed_string_t list_of_items;
3688 };
3689 
3690 static void cmd_set_list_parsed(void *parsed_result,
3691 				__rte_unused struct cmdline *cl,
3692 				__rte_unused void *data)
3693 {
3694 	struct cmd_set_list_result *res;
3695 	union {
3696 		unsigned int lcorelist[RTE_MAX_LCORE];
3697 		unsigned int portlist[RTE_MAX_ETHPORTS];
3698 	} parsed_items;
3699 	unsigned int nb_item;
3700 
3701 	if (test_done == 0) {
3702 		printf("Please stop forwarding first\n");
3703 		return;
3704 	}
3705 
3706 	res = parsed_result;
3707 	if (!strcmp(res->list_name, "corelist")) {
3708 		nb_item = parse_item_list(res->list_of_items, "core",
3709 					  RTE_MAX_LCORE,
3710 					  parsed_items.lcorelist, 1);
3711 		if (nb_item > 0) {
3712 			set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3713 			fwd_config_setup();
3714 		}
3715 		return;
3716 	}
3717 	if (!strcmp(res->list_name, "portlist")) {
3718 		nb_item = parse_item_list(res->list_of_items, "port",
3719 					  RTE_MAX_ETHPORTS,
3720 					  parsed_items.portlist, 1);
3721 		if (nb_item > 0) {
3722 			set_fwd_ports_list(parsed_items.portlist, nb_item);
3723 			fwd_config_setup();
3724 		}
3725 	}
3726 }
3727 
3728 cmdline_parse_token_string_t cmd_set_list_keyword =
3729 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3730 				 "set");
3731 cmdline_parse_token_string_t cmd_set_list_name =
3732 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3733 				 "corelist#portlist");
3734 cmdline_parse_token_string_t cmd_set_list_of_items =
3735 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3736 				 NULL);
3737 
3738 cmdline_parse_inst_t cmd_set_fwd_list = {
3739 	.f = cmd_set_list_parsed,
3740 	.data = NULL,
3741 	.help_str = "set corelist|portlist <list0[,list1]*>",
3742 	.tokens = {
3743 		(void *)&cmd_set_list_keyword,
3744 		(void *)&cmd_set_list_name,
3745 		(void *)&cmd_set_list_of_items,
3746 		NULL,
3747 	},
3748 };
3749 
3750 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3751 
3752 struct cmd_setmask_result {
3753 	cmdline_fixed_string_t set;
3754 	cmdline_fixed_string_t mask;
3755 	uint64_t hexavalue;
3756 };
3757 
3758 static void cmd_set_mask_parsed(void *parsed_result,
3759 				__rte_unused struct cmdline *cl,
3760 				__rte_unused void *data)
3761 {
3762 	struct cmd_setmask_result *res = parsed_result;
3763 
3764 	if (test_done == 0) {
3765 		printf("Please stop forwarding first\n");
3766 		return;
3767 	}
3768 	if (!strcmp(res->mask, "coremask")) {
3769 		set_fwd_lcores_mask(res->hexavalue);
3770 		fwd_config_setup();
3771 	} else if (!strcmp(res->mask, "portmask")) {
3772 		set_fwd_ports_mask(res->hexavalue);
3773 		fwd_config_setup();
3774 	}
3775 }
3776 
3777 cmdline_parse_token_string_t cmd_setmask_set =
3778 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3779 cmdline_parse_token_string_t cmd_setmask_mask =
3780 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3781 				 "coremask#portmask");
3782 cmdline_parse_token_num_t cmd_setmask_value =
3783 	TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3784 
3785 cmdline_parse_inst_t cmd_set_fwd_mask = {
3786 	.f = cmd_set_mask_parsed,
3787 	.data = NULL,
3788 	.help_str = "set coremask|portmask <hexadecimal value>",
3789 	.tokens = {
3790 		(void *)&cmd_setmask_set,
3791 		(void *)&cmd_setmask_mask,
3792 		(void *)&cmd_setmask_value,
3793 		NULL,
3794 	},
3795 };
3796 
3797 /*
3798  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3799  */
3800 struct cmd_set_result {
3801 	cmdline_fixed_string_t set;
3802 	cmdline_fixed_string_t what;
3803 	uint16_t value;
3804 };
3805 
3806 static void cmd_set_parsed(void *parsed_result,
3807 			   __rte_unused struct cmdline *cl,
3808 			   __rte_unused void *data)
3809 {
3810 	struct cmd_set_result *res = parsed_result;
3811 	if (!strcmp(res->what, "nbport")) {
3812 		set_fwd_ports_number(res->value);
3813 		fwd_config_setup();
3814 	} else if (!strcmp(res->what, "nbcore")) {
3815 		set_fwd_lcores_number(res->value);
3816 		fwd_config_setup();
3817 	} else if (!strcmp(res->what, "burst"))
3818 		set_nb_pkt_per_burst(res->value);
3819 	else if (!strcmp(res->what, "verbose"))
3820 		set_verbose_level(res->value);
3821 }
3822 
3823 cmdline_parse_token_string_t cmd_set_set =
3824 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3825 cmdline_parse_token_string_t cmd_set_what =
3826 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3827 				 "nbport#nbcore#burst#verbose");
3828 cmdline_parse_token_num_t cmd_set_value =
3829 	TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3830 
3831 cmdline_parse_inst_t cmd_set_numbers = {
3832 	.f = cmd_set_parsed,
3833 	.data = NULL,
3834 	.help_str = "set nbport|nbcore|burst|verbose <value>",
3835 	.tokens = {
3836 		(void *)&cmd_set_set,
3837 		(void *)&cmd_set_what,
3838 		(void *)&cmd_set_value,
3839 		NULL,
3840 	},
3841 };
3842 
3843 /* *** SET LOG LEVEL CONFIGURATION *** */
3844 
3845 struct cmd_set_log_result {
3846 	cmdline_fixed_string_t set;
3847 	cmdline_fixed_string_t log;
3848 	cmdline_fixed_string_t type;
3849 	uint32_t level;
3850 };
3851 
3852 static void
3853 cmd_set_log_parsed(void *parsed_result,
3854 		   __rte_unused struct cmdline *cl,
3855 		   __rte_unused void *data)
3856 {
3857 	struct cmd_set_log_result *res;
3858 	int ret;
3859 
3860 	res = parsed_result;
3861 	if (!strcmp(res->type, "global"))
3862 		rte_log_set_global_level(res->level);
3863 	else {
3864 		ret = rte_log_set_level_regexp(res->type, res->level);
3865 		if (ret < 0)
3866 			printf("Unable to set log level\n");
3867 	}
3868 }
3869 
3870 cmdline_parse_token_string_t cmd_set_log_set =
3871 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3872 cmdline_parse_token_string_t cmd_set_log_log =
3873 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3874 cmdline_parse_token_string_t cmd_set_log_type =
3875 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3876 cmdline_parse_token_num_t cmd_set_log_level =
3877 	TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3878 
3879 cmdline_parse_inst_t cmd_set_log = {
3880 	.f = cmd_set_log_parsed,
3881 	.data = NULL,
3882 	.help_str = "set log global|<type> <level>",
3883 	.tokens = {
3884 		(void *)&cmd_set_log_set,
3885 		(void *)&cmd_set_log_log,
3886 		(void *)&cmd_set_log_type,
3887 		(void *)&cmd_set_log_level,
3888 		NULL,
3889 	},
3890 };
3891 
3892 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3893 
3894 struct cmd_set_txpkts_result {
3895 	cmdline_fixed_string_t cmd_keyword;
3896 	cmdline_fixed_string_t txpkts;
3897 	cmdline_fixed_string_t seg_lengths;
3898 };
3899 
3900 static void
3901 cmd_set_txpkts_parsed(void *parsed_result,
3902 		      __rte_unused struct cmdline *cl,
3903 		      __rte_unused void *data)
3904 {
3905 	struct cmd_set_txpkts_result *res;
3906 	unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3907 	unsigned int nb_segs;
3908 
3909 	res = parsed_result;
3910 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3911 				  RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3912 	if (nb_segs > 0)
3913 		set_tx_pkt_segments(seg_lengths, nb_segs);
3914 }
3915 
3916 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3917 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3918 				 cmd_keyword, "set");
3919 cmdline_parse_token_string_t cmd_set_txpkts_name =
3920 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3921 				 txpkts, "txpkts");
3922 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3923 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3924 				 seg_lengths, NULL);
3925 
3926 cmdline_parse_inst_t cmd_set_txpkts = {
3927 	.f = cmd_set_txpkts_parsed,
3928 	.data = NULL,
3929 	.help_str = "set txpkts <len0[,len1]*>",
3930 	.tokens = {
3931 		(void *)&cmd_set_txpkts_keyword,
3932 		(void *)&cmd_set_txpkts_name,
3933 		(void *)&cmd_set_txpkts_lengths,
3934 		NULL,
3935 	},
3936 };
3937 
3938 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3939 
3940 struct cmd_set_txsplit_result {
3941 	cmdline_fixed_string_t cmd_keyword;
3942 	cmdline_fixed_string_t txsplit;
3943 	cmdline_fixed_string_t mode;
3944 };
3945 
3946 static void
3947 cmd_set_txsplit_parsed(void *parsed_result,
3948 		      __rte_unused struct cmdline *cl,
3949 		      __rte_unused void *data)
3950 {
3951 	struct cmd_set_txsplit_result *res;
3952 
3953 	res = parsed_result;
3954 	set_tx_pkt_split(res->mode);
3955 }
3956 
3957 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3958 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3959 				 cmd_keyword, "set");
3960 cmdline_parse_token_string_t cmd_set_txsplit_name =
3961 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3962 				 txsplit, "txsplit");
3963 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3964 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3965 				 mode, NULL);
3966 
3967 cmdline_parse_inst_t cmd_set_txsplit = {
3968 	.f = cmd_set_txsplit_parsed,
3969 	.data = NULL,
3970 	.help_str = "set txsplit on|off|rand",
3971 	.tokens = {
3972 		(void *)&cmd_set_txsplit_keyword,
3973 		(void *)&cmd_set_txsplit_name,
3974 		(void *)&cmd_set_txsplit_mode,
3975 		NULL,
3976 	},
3977 };
3978 
3979 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3980 
3981 struct cmd_set_txtimes_result {
3982 	cmdline_fixed_string_t cmd_keyword;
3983 	cmdline_fixed_string_t txtimes;
3984 	cmdline_fixed_string_t tx_times;
3985 };
3986 
3987 static void
3988 cmd_set_txtimes_parsed(void *parsed_result,
3989 		       __rte_unused struct cmdline *cl,
3990 		       __rte_unused void *data)
3991 {
3992 	struct cmd_set_txtimes_result *res;
3993 	unsigned int tx_times[2] = {0, 0};
3994 	unsigned int n_times;
3995 
3996 	res = parsed_result;
3997 	n_times = parse_item_list(res->tx_times, "tx times",
3998 				  2, tx_times, 0);
3999 	if (n_times == 2)
4000 		set_tx_pkt_times(tx_times);
4001 }
4002 
4003 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4004 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4005 				 cmd_keyword, "set");
4006 cmdline_parse_token_string_t cmd_set_txtimes_name =
4007 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4008 				 txtimes, "txtimes");
4009 cmdline_parse_token_string_t cmd_set_txtimes_value =
4010 	TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4011 				 tx_times, NULL);
4012 
4013 cmdline_parse_inst_t cmd_set_txtimes = {
4014 	.f = cmd_set_txtimes_parsed,
4015 	.data = NULL,
4016 	.help_str = "set txtimes <inter_burst>,<intra_burst>",
4017 	.tokens = {
4018 		(void *)&cmd_set_txtimes_keyword,
4019 		(void *)&cmd_set_txtimes_name,
4020 		(void *)&cmd_set_txtimes_value,
4021 		NULL,
4022 	},
4023 };
4024 
4025 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4026 struct cmd_rx_vlan_filter_all_result {
4027 	cmdline_fixed_string_t rx_vlan;
4028 	cmdline_fixed_string_t what;
4029 	cmdline_fixed_string_t all;
4030 	portid_t port_id;
4031 };
4032 
4033 static void
4034 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4035 			      __rte_unused struct cmdline *cl,
4036 			      __rte_unused void *data)
4037 {
4038 	struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4039 
4040 	if (!strcmp(res->what, "add"))
4041 		rx_vlan_all_filter_set(res->port_id, 1);
4042 	else
4043 		rx_vlan_all_filter_set(res->port_id, 0);
4044 }
4045 
4046 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4047 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4048 				 rx_vlan, "rx_vlan");
4049 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4050 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4051 				 what, "add#rm");
4052 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4053 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4054 				 all, "all");
4055 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4056 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4057 			      port_id, UINT16);
4058 
4059 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4060 	.f = cmd_rx_vlan_filter_all_parsed,
4061 	.data = NULL,
4062 	.help_str = "rx_vlan add|rm all <port_id>: "
4063 		"Add/Remove all identifiers to/from the set of VLAN "
4064 		"identifiers filtered by a port",
4065 	.tokens = {
4066 		(void *)&cmd_rx_vlan_filter_all_rx_vlan,
4067 		(void *)&cmd_rx_vlan_filter_all_what,
4068 		(void *)&cmd_rx_vlan_filter_all_all,
4069 		(void *)&cmd_rx_vlan_filter_all_portid,
4070 		NULL,
4071 	},
4072 };
4073 
4074 /* *** VLAN OFFLOAD SET ON A PORT *** */
4075 struct cmd_vlan_offload_result {
4076 	cmdline_fixed_string_t vlan;
4077 	cmdline_fixed_string_t set;
4078 	cmdline_fixed_string_t vlan_type;
4079 	cmdline_fixed_string_t what;
4080 	cmdline_fixed_string_t on;
4081 	cmdline_fixed_string_t port_id;
4082 };
4083 
4084 static void
4085 cmd_vlan_offload_parsed(void *parsed_result,
4086 			  __rte_unused struct cmdline *cl,
4087 			  __rte_unused void *data)
4088 {
4089 	int on;
4090 	struct cmd_vlan_offload_result *res = parsed_result;
4091 	char *str;
4092 	int i, len = 0;
4093 	portid_t port_id = 0;
4094 	unsigned int tmp;
4095 
4096 	str = res->port_id;
4097 	len = strnlen(str, STR_TOKEN_SIZE);
4098 	i = 0;
4099 	/* Get port_id first */
4100 	while(i < len){
4101 		if(str[i] == ',')
4102 			break;
4103 
4104 		i++;
4105 	}
4106 	str[i]='\0';
4107 	tmp = strtoul(str, NULL, 0);
4108 	/* If port_id greater that what portid_t can represent, return */
4109 	if(tmp >= RTE_MAX_ETHPORTS)
4110 		return;
4111 	port_id = (portid_t)tmp;
4112 
4113 	if (!strcmp(res->on, "on"))
4114 		on = 1;
4115 	else
4116 		on = 0;
4117 
4118 	if (!strcmp(res->what, "strip"))
4119 		rx_vlan_strip_set(port_id,  on);
4120 	else if(!strcmp(res->what, "stripq")){
4121 		uint16_t queue_id = 0;
4122 
4123 		/* No queue_id, return */
4124 		if(i + 1 >= len) {
4125 			printf("must specify (port,queue_id)\n");
4126 			return;
4127 		}
4128 		tmp = strtoul(str + i + 1, NULL, 0);
4129 		/* If queue_id greater that what 16-bits can represent, return */
4130 		if(tmp > 0xffff)
4131 			return;
4132 
4133 		queue_id = (uint16_t)tmp;
4134 		rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4135 	}
4136 	else if (!strcmp(res->what, "filter"))
4137 		rx_vlan_filter_set(port_id, on);
4138 	else if (!strcmp(res->what, "qinq_strip"))
4139 		rx_vlan_qinq_strip_set(port_id, on);
4140 	else
4141 		vlan_extend_set(port_id, on);
4142 
4143 	return;
4144 }
4145 
4146 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4147 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4148 				 vlan, "vlan");
4149 cmdline_parse_token_string_t cmd_vlan_offload_set =
4150 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4151 				 set, "set");
4152 cmdline_parse_token_string_t cmd_vlan_offload_what =
4153 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4154 				what, "strip#filter#qinq_strip#extend#stripq");
4155 cmdline_parse_token_string_t cmd_vlan_offload_on =
4156 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4157 			      on, "on#off");
4158 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4159 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4160 			      port_id, NULL);
4161 
4162 cmdline_parse_inst_t cmd_vlan_offload = {
4163 	.f = cmd_vlan_offload_parsed,
4164 	.data = NULL,
4165 	.help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4166 		"<port_id[,queue_id]>: "
4167 		"Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4168 	.tokens = {
4169 		(void *)&cmd_vlan_offload_vlan,
4170 		(void *)&cmd_vlan_offload_set,
4171 		(void *)&cmd_vlan_offload_what,
4172 		(void *)&cmd_vlan_offload_on,
4173 		(void *)&cmd_vlan_offload_portid,
4174 		NULL,
4175 	},
4176 };
4177 
4178 /* *** VLAN TPID SET ON A PORT *** */
4179 struct cmd_vlan_tpid_result {
4180 	cmdline_fixed_string_t vlan;
4181 	cmdline_fixed_string_t set;
4182 	cmdline_fixed_string_t vlan_type;
4183 	cmdline_fixed_string_t what;
4184 	uint16_t tp_id;
4185 	portid_t port_id;
4186 };
4187 
4188 static void
4189 cmd_vlan_tpid_parsed(void *parsed_result,
4190 			  __rte_unused struct cmdline *cl,
4191 			  __rte_unused void *data)
4192 {
4193 	struct cmd_vlan_tpid_result *res = parsed_result;
4194 	enum rte_vlan_type vlan_type;
4195 
4196 	if (!strcmp(res->vlan_type, "inner"))
4197 		vlan_type = ETH_VLAN_TYPE_INNER;
4198 	else if (!strcmp(res->vlan_type, "outer"))
4199 		vlan_type = ETH_VLAN_TYPE_OUTER;
4200 	else {
4201 		printf("Unknown vlan type\n");
4202 		return;
4203 	}
4204 	vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4205 }
4206 
4207 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4208 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4209 				 vlan, "vlan");
4210 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4211 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4212 				 set, "set");
4213 cmdline_parse_token_string_t cmd_vlan_type =
4214 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4215 				 vlan_type, "inner#outer");
4216 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4217 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4218 				 what, "tpid");
4219 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4220 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4221 			      tp_id, UINT16);
4222 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4223 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4224 			      port_id, UINT16);
4225 
4226 cmdline_parse_inst_t cmd_vlan_tpid = {
4227 	.f = cmd_vlan_tpid_parsed,
4228 	.data = NULL,
4229 	.help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4230 		"Set the VLAN Ether type",
4231 	.tokens = {
4232 		(void *)&cmd_vlan_tpid_vlan,
4233 		(void *)&cmd_vlan_tpid_set,
4234 		(void *)&cmd_vlan_type,
4235 		(void *)&cmd_vlan_tpid_what,
4236 		(void *)&cmd_vlan_tpid_tpid,
4237 		(void *)&cmd_vlan_tpid_portid,
4238 		NULL,
4239 	},
4240 };
4241 
4242 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4243 struct cmd_rx_vlan_filter_result {
4244 	cmdline_fixed_string_t rx_vlan;
4245 	cmdline_fixed_string_t what;
4246 	uint16_t vlan_id;
4247 	portid_t port_id;
4248 };
4249 
4250 static void
4251 cmd_rx_vlan_filter_parsed(void *parsed_result,
4252 			  __rte_unused struct cmdline *cl,
4253 			  __rte_unused void *data)
4254 {
4255 	struct cmd_rx_vlan_filter_result *res = parsed_result;
4256 
4257 	if (!strcmp(res->what, "add"))
4258 		rx_vft_set(res->port_id, res->vlan_id, 1);
4259 	else
4260 		rx_vft_set(res->port_id, res->vlan_id, 0);
4261 }
4262 
4263 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4264 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4265 				 rx_vlan, "rx_vlan");
4266 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4267 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4268 				 what, "add#rm");
4269 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4270 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4271 			      vlan_id, UINT16);
4272 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4273 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4274 			      port_id, UINT16);
4275 
4276 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4277 	.f = cmd_rx_vlan_filter_parsed,
4278 	.data = NULL,
4279 	.help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4280 		"Add/Remove a VLAN identifier to/from the set of VLAN "
4281 		"identifiers filtered by a port",
4282 	.tokens = {
4283 		(void *)&cmd_rx_vlan_filter_rx_vlan,
4284 		(void *)&cmd_rx_vlan_filter_what,
4285 		(void *)&cmd_rx_vlan_filter_vlanid,
4286 		(void *)&cmd_rx_vlan_filter_portid,
4287 		NULL,
4288 	},
4289 };
4290 
4291 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4292 struct cmd_tx_vlan_set_result {
4293 	cmdline_fixed_string_t tx_vlan;
4294 	cmdline_fixed_string_t set;
4295 	portid_t port_id;
4296 	uint16_t vlan_id;
4297 };
4298 
4299 static void
4300 cmd_tx_vlan_set_parsed(void *parsed_result,
4301 		       __rte_unused struct cmdline *cl,
4302 		       __rte_unused void *data)
4303 {
4304 	struct cmd_tx_vlan_set_result *res = parsed_result;
4305 
4306 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4307 		return;
4308 
4309 	if (!port_is_stopped(res->port_id)) {
4310 		printf("Please stop port %d first\n", res->port_id);
4311 		return;
4312 	}
4313 
4314 	tx_vlan_set(res->port_id, res->vlan_id);
4315 
4316 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4317 }
4318 
4319 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4320 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4321 				 tx_vlan, "tx_vlan");
4322 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4323 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4324 				 set, "set");
4325 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4326 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4327 			      port_id, UINT16);
4328 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4329 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4330 			      vlan_id, UINT16);
4331 
4332 cmdline_parse_inst_t cmd_tx_vlan_set = {
4333 	.f = cmd_tx_vlan_set_parsed,
4334 	.data = NULL,
4335 	.help_str = "tx_vlan set <port_id> <vlan_id>: "
4336 		"Enable hardware insertion of a single VLAN header "
4337 		"with a given TAG Identifier in packets sent on a port",
4338 	.tokens = {
4339 		(void *)&cmd_tx_vlan_set_tx_vlan,
4340 		(void *)&cmd_tx_vlan_set_set,
4341 		(void *)&cmd_tx_vlan_set_portid,
4342 		(void *)&cmd_tx_vlan_set_vlanid,
4343 		NULL,
4344 	},
4345 };
4346 
4347 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4348 struct cmd_tx_vlan_set_qinq_result {
4349 	cmdline_fixed_string_t tx_vlan;
4350 	cmdline_fixed_string_t set;
4351 	portid_t port_id;
4352 	uint16_t vlan_id;
4353 	uint16_t vlan_id_outer;
4354 };
4355 
4356 static void
4357 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4358 			    __rte_unused struct cmdline *cl,
4359 			    __rte_unused void *data)
4360 {
4361 	struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4362 
4363 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4364 		return;
4365 
4366 	if (!port_is_stopped(res->port_id)) {
4367 		printf("Please stop port %d first\n", res->port_id);
4368 		return;
4369 	}
4370 
4371 	tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4372 
4373 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4374 }
4375 
4376 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4377 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4378 		tx_vlan, "tx_vlan");
4379 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4380 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4381 		set, "set");
4382 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4383 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4384 		port_id, UINT16);
4385 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4386 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4387 		vlan_id, UINT16);
4388 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4389 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4390 		vlan_id_outer, UINT16);
4391 
4392 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4393 	.f = cmd_tx_vlan_set_qinq_parsed,
4394 	.data = NULL,
4395 	.help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4396 		"Enable hardware insertion of double VLAN header "
4397 		"with given TAG Identifiers in packets sent on a port",
4398 	.tokens = {
4399 		(void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4400 		(void *)&cmd_tx_vlan_set_qinq_set,
4401 		(void *)&cmd_tx_vlan_set_qinq_portid,
4402 		(void *)&cmd_tx_vlan_set_qinq_vlanid,
4403 		(void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4404 		NULL,
4405 	},
4406 };
4407 
4408 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4409 struct cmd_tx_vlan_set_pvid_result {
4410 	cmdline_fixed_string_t tx_vlan;
4411 	cmdline_fixed_string_t set;
4412 	cmdline_fixed_string_t pvid;
4413 	portid_t port_id;
4414 	uint16_t vlan_id;
4415 	cmdline_fixed_string_t mode;
4416 };
4417 
4418 static void
4419 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4420 			    __rte_unused struct cmdline *cl,
4421 			    __rte_unused void *data)
4422 {
4423 	struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4424 
4425 	if (strcmp(res->mode, "on") == 0)
4426 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4427 	else
4428 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4429 }
4430 
4431 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4432 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4433 				 tx_vlan, "tx_vlan");
4434 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4435 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4436 				 set, "set");
4437 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4438 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4439 				 pvid, "pvid");
4440 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4441 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4442 			     port_id, UINT16);
4443 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4444 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4445 			      vlan_id, UINT16);
4446 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4447 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4448 				 mode, "on#off");
4449 
4450 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4451 	.f = cmd_tx_vlan_set_pvid_parsed,
4452 	.data = NULL,
4453 	.help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4454 	.tokens = {
4455 		(void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4456 		(void *)&cmd_tx_vlan_set_pvid_set,
4457 		(void *)&cmd_tx_vlan_set_pvid_pvid,
4458 		(void *)&cmd_tx_vlan_set_pvid_port_id,
4459 		(void *)&cmd_tx_vlan_set_pvid_vlan_id,
4460 		(void *)&cmd_tx_vlan_set_pvid_mode,
4461 		NULL,
4462 	},
4463 };
4464 
4465 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4466 struct cmd_tx_vlan_reset_result {
4467 	cmdline_fixed_string_t tx_vlan;
4468 	cmdline_fixed_string_t reset;
4469 	portid_t port_id;
4470 };
4471 
4472 static void
4473 cmd_tx_vlan_reset_parsed(void *parsed_result,
4474 			 __rte_unused struct cmdline *cl,
4475 			 __rte_unused void *data)
4476 {
4477 	struct cmd_tx_vlan_reset_result *res = parsed_result;
4478 
4479 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4480 		return;
4481 
4482 	if (!port_is_stopped(res->port_id)) {
4483 		printf("Please stop port %d first\n", res->port_id);
4484 		return;
4485 	}
4486 
4487 	tx_vlan_reset(res->port_id);
4488 
4489 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4490 }
4491 
4492 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4493 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4494 				 tx_vlan, "tx_vlan");
4495 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4496 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4497 				 reset, "reset");
4498 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4499 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4500 			      port_id, UINT16);
4501 
4502 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4503 	.f = cmd_tx_vlan_reset_parsed,
4504 	.data = NULL,
4505 	.help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4506 		"VLAN header in packets sent on a port",
4507 	.tokens = {
4508 		(void *)&cmd_tx_vlan_reset_tx_vlan,
4509 		(void *)&cmd_tx_vlan_reset_reset,
4510 		(void *)&cmd_tx_vlan_reset_portid,
4511 		NULL,
4512 	},
4513 };
4514 
4515 
4516 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4517 struct cmd_csum_result {
4518 	cmdline_fixed_string_t csum;
4519 	cmdline_fixed_string_t mode;
4520 	cmdline_fixed_string_t proto;
4521 	cmdline_fixed_string_t hwsw;
4522 	portid_t port_id;
4523 };
4524 
4525 static void
4526 csum_show(int port_id)
4527 {
4528 	struct rte_eth_dev_info dev_info;
4529 	uint64_t tx_offloads;
4530 	int ret;
4531 
4532 	tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4533 	printf("Parse tunnel is %s\n",
4534 		(ports[port_id].parse_tunnel) ? "on" : "off");
4535 	printf("IP checksum offload is %s\n",
4536 		(tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4537 	printf("UDP checksum offload is %s\n",
4538 		(tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4539 	printf("TCP checksum offload is %s\n",
4540 		(tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4541 	printf("SCTP checksum offload is %s\n",
4542 		(tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4543 	printf("Outer-Ip checksum offload is %s\n",
4544 		(tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4545 	printf("Outer-Udp checksum offload is %s\n",
4546 		(tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4547 
4548 	/* display warnings if configuration is not supported by the NIC */
4549 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
4550 	if (ret != 0)
4551 		return;
4552 
4553 	if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4554 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4555 		printf("Warning: hardware IP checksum enabled but not "
4556 			"supported by port %d\n", port_id);
4557 	}
4558 	if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4559 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4560 		printf("Warning: hardware UDP checksum enabled but not "
4561 			"supported by port %d\n", port_id);
4562 	}
4563 	if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4564 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4565 		printf("Warning: hardware TCP checksum enabled but not "
4566 			"supported by port %d\n", port_id);
4567 	}
4568 	if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4569 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4570 		printf("Warning: hardware SCTP checksum enabled but not "
4571 			"supported by port %d\n", port_id);
4572 	}
4573 	if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4574 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4575 		printf("Warning: hardware outer IP checksum enabled but not "
4576 			"supported by port %d\n", port_id);
4577 	}
4578 	if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4579 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4580 			== 0) {
4581 		printf("Warning: hardware outer UDP checksum enabled but not "
4582 			"supported by port %d\n", port_id);
4583 	}
4584 }
4585 
4586 static void
4587 cmd_config_queue_tx_offloads(struct rte_port *port)
4588 {
4589 	int k;
4590 
4591 	/* Apply queue tx offloads configuration */
4592 	for (k = 0; k < port->dev_info.max_rx_queues; k++)
4593 		port->tx_conf[k].offloads =
4594 			port->dev_conf.txmode.offloads;
4595 }
4596 
4597 static void
4598 cmd_csum_parsed(void *parsed_result,
4599 		       __rte_unused struct cmdline *cl,
4600 		       __rte_unused void *data)
4601 {
4602 	struct cmd_csum_result *res = parsed_result;
4603 	int hw = 0;
4604 	uint64_t csum_offloads = 0;
4605 	struct rte_eth_dev_info dev_info;
4606 	int ret;
4607 
4608 	if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4609 		printf("invalid port %d\n", res->port_id);
4610 		return;
4611 	}
4612 	if (!port_is_stopped(res->port_id)) {
4613 		printf("Please stop port %d first\n", res->port_id);
4614 		return;
4615 	}
4616 
4617 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4618 	if (ret != 0)
4619 		return;
4620 
4621 	if (!strcmp(res->mode, "set")) {
4622 
4623 		if (!strcmp(res->hwsw, "hw"))
4624 			hw = 1;
4625 
4626 		if (!strcmp(res->proto, "ip")) {
4627 			if (hw == 0 || (dev_info.tx_offload_capa &
4628 						DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4629 				csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4630 			} else {
4631 				printf("IP checksum offload is not supported "
4632 				       "by port %u\n", res->port_id);
4633 			}
4634 		} else if (!strcmp(res->proto, "udp")) {
4635 			if (hw == 0 || (dev_info.tx_offload_capa &
4636 						DEV_TX_OFFLOAD_UDP_CKSUM)) {
4637 				csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4638 			} else {
4639 				printf("UDP checksum offload is not supported "
4640 				       "by port %u\n", res->port_id);
4641 			}
4642 		} else if (!strcmp(res->proto, "tcp")) {
4643 			if (hw == 0 || (dev_info.tx_offload_capa &
4644 						DEV_TX_OFFLOAD_TCP_CKSUM)) {
4645 				csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4646 			} else {
4647 				printf("TCP checksum offload is not supported "
4648 				       "by port %u\n", res->port_id);
4649 			}
4650 		} else if (!strcmp(res->proto, "sctp")) {
4651 			if (hw == 0 || (dev_info.tx_offload_capa &
4652 						DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4653 				csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4654 			} else {
4655 				printf("SCTP checksum offload is not supported "
4656 				       "by port %u\n", res->port_id);
4657 			}
4658 		} else if (!strcmp(res->proto, "outer-ip")) {
4659 			if (hw == 0 || (dev_info.tx_offload_capa &
4660 					DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4661 				csum_offloads |=
4662 						DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4663 			} else {
4664 				printf("Outer IP checksum offload is not "
4665 				       "supported by port %u\n", res->port_id);
4666 			}
4667 		} else if (!strcmp(res->proto, "outer-udp")) {
4668 			if (hw == 0 || (dev_info.tx_offload_capa &
4669 					DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4670 				csum_offloads |=
4671 						DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4672 			} else {
4673 				printf("Outer UDP checksum offload is not "
4674 				       "supported by port %u\n", res->port_id);
4675 			}
4676 		}
4677 
4678 		if (hw) {
4679 			ports[res->port_id].dev_conf.txmode.offloads |=
4680 							csum_offloads;
4681 		} else {
4682 			ports[res->port_id].dev_conf.txmode.offloads &=
4683 							(~csum_offloads);
4684 		}
4685 		cmd_config_queue_tx_offloads(&ports[res->port_id]);
4686 	}
4687 	csum_show(res->port_id);
4688 
4689 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4690 }
4691 
4692 cmdline_parse_token_string_t cmd_csum_csum =
4693 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4694 				csum, "csum");
4695 cmdline_parse_token_string_t cmd_csum_mode =
4696 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4697 				mode, "set");
4698 cmdline_parse_token_string_t cmd_csum_proto =
4699 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4700 				proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4701 cmdline_parse_token_string_t cmd_csum_hwsw =
4702 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4703 				hwsw, "hw#sw");
4704 cmdline_parse_token_num_t cmd_csum_portid =
4705 	TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4706 				port_id, UINT16);
4707 
4708 cmdline_parse_inst_t cmd_csum_set = {
4709 	.f = cmd_csum_parsed,
4710 	.data = NULL,
4711 	.help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4712 		"Enable/Disable hardware calculation of L3/L4 checksum when "
4713 		"using csum forward engine",
4714 	.tokens = {
4715 		(void *)&cmd_csum_csum,
4716 		(void *)&cmd_csum_mode,
4717 		(void *)&cmd_csum_proto,
4718 		(void *)&cmd_csum_hwsw,
4719 		(void *)&cmd_csum_portid,
4720 		NULL,
4721 	},
4722 };
4723 
4724 cmdline_parse_token_string_t cmd_csum_mode_show =
4725 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4726 				mode, "show");
4727 
4728 cmdline_parse_inst_t cmd_csum_show = {
4729 	.f = cmd_csum_parsed,
4730 	.data = NULL,
4731 	.help_str = "csum show <port_id>: Show checksum offload configuration",
4732 	.tokens = {
4733 		(void *)&cmd_csum_csum,
4734 		(void *)&cmd_csum_mode_show,
4735 		(void *)&cmd_csum_portid,
4736 		NULL,
4737 	},
4738 };
4739 
4740 /* Enable/disable tunnel parsing */
4741 struct cmd_csum_tunnel_result {
4742 	cmdline_fixed_string_t csum;
4743 	cmdline_fixed_string_t parse;
4744 	cmdline_fixed_string_t onoff;
4745 	portid_t port_id;
4746 };
4747 
4748 static void
4749 cmd_csum_tunnel_parsed(void *parsed_result,
4750 		       __rte_unused struct cmdline *cl,
4751 		       __rte_unused void *data)
4752 {
4753 	struct cmd_csum_tunnel_result *res = parsed_result;
4754 
4755 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4756 		return;
4757 
4758 	if (!strcmp(res->onoff, "on"))
4759 		ports[res->port_id].parse_tunnel = 1;
4760 	else
4761 		ports[res->port_id].parse_tunnel = 0;
4762 
4763 	csum_show(res->port_id);
4764 }
4765 
4766 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4767 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4768 				csum, "csum");
4769 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4770 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4771 				parse, "parse-tunnel");
4772 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4773 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4774 				onoff, "on#off");
4775 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4776 	TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4777 				port_id, UINT16);
4778 
4779 cmdline_parse_inst_t cmd_csum_tunnel = {
4780 	.f = cmd_csum_tunnel_parsed,
4781 	.data = NULL,
4782 	.help_str = "csum parse-tunnel on|off <port_id>: "
4783 		"Enable/Disable parsing of tunnels for csum engine",
4784 	.tokens = {
4785 		(void *)&cmd_csum_tunnel_csum,
4786 		(void *)&cmd_csum_tunnel_parse,
4787 		(void *)&cmd_csum_tunnel_onoff,
4788 		(void *)&cmd_csum_tunnel_portid,
4789 		NULL,
4790 	},
4791 };
4792 
4793 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4794 struct cmd_tso_set_result {
4795 	cmdline_fixed_string_t tso;
4796 	cmdline_fixed_string_t mode;
4797 	uint16_t tso_segsz;
4798 	portid_t port_id;
4799 };
4800 
4801 static void
4802 cmd_tso_set_parsed(void *parsed_result,
4803 		       __rte_unused struct cmdline *cl,
4804 		       __rte_unused void *data)
4805 {
4806 	struct cmd_tso_set_result *res = parsed_result;
4807 	struct rte_eth_dev_info dev_info;
4808 	int ret;
4809 
4810 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4811 		return;
4812 	if (!port_is_stopped(res->port_id)) {
4813 		printf("Please stop port %d first\n", res->port_id);
4814 		return;
4815 	}
4816 
4817 	if (!strcmp(res->mode, "set"))
4818 		ports[res->port_id].tso_segsz = res->tso_segsz;
4819 
4820 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4821 	if (ret != 0)
4822 		return;
4823 
4824 	if ((ports[res->port_id].tso_segsz != 0) &&
4825 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4826 		printf("Error: TSO is not supported by port %d\n",
4827 		       res->port_id);
4828 		return;
4829 	}
4830 
4831 	if (ports[res->port_id].tso_segsz == 0) {
4832 		ports[res->port_id].dev_conf.txmode.offloads &=
4833 						~DEV_TX_OFFLOAD_TCP_TSO;
4834 		printf("TSO for non-tunneled packets is disabled\n");
4835 	} else {
4836 		ports[res->port_id].dev_conf.txmode.offloads |=
4837 						DEV_TX_OFFLOAD_TCP_TSO;
4838 		printf("TSO segment size for non-tunneled packets is %d\n",
4839 			ports[res->port_id].tso_segsz);
4840 	}
4841 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
4842 
4843 	/* display warnings if configuration is not supported by the NIC */
4844 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4845 	if (ret != 0)
4846 		return;
4847 
4848 	if ((ports[res->port_id].tso_segsz != 0) &&
4849 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4850 		printf("Warning: TSO enabled but not "
4851 			"supported by port %d\n", res->port_id);
4852 	}
4853 
4854 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4855 }
4856 
4857 cmdline_parse_token_string_t cmd_tso_set_tso =
4858 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4859 				tso, "tso");
4860 cmdline_parse_token_string_t cmd_tso_set_mode =
4861 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4862 				mode, "set");
4863 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4864 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4865 				tso_segsz, UINT16);
4866 cmdline_parse_token_num_t cmd_tso_set_portid =
4867 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4868 				port_id, UINT16);
4869 
4870 cmdline_parse_inst_t cmd_tso_set = {
4871 	.f = cmd_tso_set_parsed,
4872 	.data = NULL,
4873 	.help_str = "tso set <tso_segsz> <port_id>: "
4874 		"Set TSO segment size of non-tunneled packets for csum engine "
4875 		"(0 to disable)",
4876 	.tokens = {
4877 		(void *)&cmd_tso_set_tso,
4878 		(void *)&cmd_tso_set_mode,
4879 		(void *)&cmd_tso_set_tso_segsz,
4880 		(void *)&cmd_tso_set_portid,
4881 		NULL,
4882 	},
4883 };
4884 
4885 cmdline_parse_token_string_t cmd_tso_show_mode =
4886 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4887 				mode, "show");
4888 
4889 
4890 cmdline_parse_inst_t cmd_tso_show = {
4891 	.f = cmd_tso_set_parsed,
4892 	.data = NULL,
4893 	.help_str = "tso show <port_id>: "
4894 		"Show TSO segment size of non-tunneled packets for csum engine",
4895 	.tokens = {
4896 		(void *)&cmd_tso_set_tso,
4897 		(void *)&cmd_tso_show_mode,
4898 		(void *)&cmd_tso_set_portid,
4899 		NULL,
4900 	},
4901 };
4902 
4903 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4904 struct cmd_tunnel_tso_set_result {
4905 	cmdline_fixed_string_t tso;
4906 	cmdline_fixed_string_t mode;
4907 	uint16_t tso_segsz;
4908 	portid_t port_id;
4909 };
4910 
4911 static struct rte_eth_dev_info
4912 check_tunnel_tso_nic_support(portid_t port_id)
4913 {
4914 	struct rte_eth_dev_info dev_info;
4915 
4916 	if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4917 		return dev_info;
4918 
4919 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4920 		printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4921 		       "not enabled for port %d\n", port_id);
4922 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4923 		printf("Warning: GRE TUNNEL TSO	not supported therefore "
4924 		       "not enabled for port %d\n", port_id);
4925 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4926 		printf("Warning: IPIP TUNNEL TSO not supported therefore "
4927 		       "not enabled for port %d\n", port_id);
4928 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4929 		printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4930 		       "not enabled for port %d\n", port_id);
4931 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4932 		printf("Warning: IP TUNNEL TSO not supported therefore "
4933 		       "not enabled for port %d\n", port_id);
4934 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4935 		printf("Warning: UDP TUNNEL TSO not supported therefore "
4936 		       "not enabled for port %d\n", port_id);
4937 	return dev_info;
4938 }
4939 
4940 static void
4941 cmd_tunnel_tso_set_parsed(void *parsed_result,
4942 			  __rte_unused struct cmdline *cl,
4943 			  __rte_unused void *data)
4944 {
4945 	struct cmd_tunnel_tso_set_result *res = parsed_result;
4946 	struct rte_eth_dev_info dev_info;
4947 
4948 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4949 		return;
4950 	if (!port_is_stopped(res->port_id)) {
4951 		printf("Please stop port %d first\n", res->port_id);
4952 		return;
4953 	}
4954 
4955 	if (!strcmp(res->mode, "set"))
4956 		ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4957 
4958 	dev_info = check_tunnel_tso_nic_support(res->port_id);
4959 	if (ports[res->port_id].tunnel_tso_segsz == 0) {
4960 		ports[res->port_id].dev_conf.txmode.offloads &=
4961 			~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4962 			  DEV_TX_OFFLOAD_GRE_TNL_TSO |
4963 			  DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4964 			  DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4965 			  DEV_TX_OFFLOAD_IP_TNL_TSO |
4966 			  DEV_TX_OFFLOAD_UDP_TNL_TSO);
4967 		printf("TSO for tunneled packets is disabled\n");
4968 	} else {
4969 		uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4970 					 DEV_TX_OFFLOAD_GRE_TNL_TSO |
4971 					 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4972 					 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4973 					 DEV_TX_OFFLOAD_IP_TNL_TSO |
4974 					 DEV_TX_OFFLOAD_UDP_TNL_TSO);
4975 
4976 		ports[res->port_id].dev_conf.txmode.offloads |=
4977 			(tso_offloads & dev_info.tx_offload_capa);
4978 		printf("TSO segment size for tunneled packets is %d\n",
4979 			ports[res->port_id].tunnel_tso_segsz);
4980 
4981 		/* Below conditions are needed to make it work:
4982 		 * (1) tunnel TSO is supported by the NIC;
4983 		 * (2) "csum parse_tunnel" must be set so that tunneled pkts
4984 		 * are recognized;
4985 		 * (3) for tunneled pkts with outer L3 of IPv4,
4986 		 * "csum set outer-ip" must be set to hw, because after tso,
4987 		 * total_len of outer IP header is changed, and the checksum
4988 		 * of outer IP header calculated by sw should be wrong; that
4989 		 * is not necessary for IPv6 tunneled pkts because there's no
4990 		 * checksum in IP header anymore.
4991 		 */
4992 
4993 		if (!ports[res->port_id].parse_tunnel)
4994 			printf("Warning: csum parse_tunnel must be set "
4995 				"so that tunneled packets are recognized\n");
4996 		if (!(ports[res->port_id].dev_conf.txmode.offloads &
4997 		      DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4998 			printf("Warning: csum set outer-ip must be set to hw "
4999 				"if outer L3 is IPv4; not necessary for IPv6\n");
5000 	}
5001 
5002 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
5003 	cmd_reconfig_device_queue(res->port_id, 1, 1);
5004 }
5005 
5006 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5007 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5008 				tso, "tunnel_tso");
5009 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5010 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5011 				mode, "set");
5012 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5013 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5014 				tso_segsz, UINT16);
5015 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5016 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5017 				port_id, UINT16);
5018 
5019 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5020 	.f = cmd_tunnel_tso_set_parsed,
5021 	.data = NULL,
5022 	.help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5023 		"Set TSO segment size of tunneled packets for csum engine "
5024 		"(0 to disable)",
5025 	.tokens = {
5026 		(void *)&cmd_tunnel_tso_set_tso,
5027 		(void *)&cmd_tunnel_tso_set_mode,
5028 		(void *)&cmd_tunnel_tso_set_tso_segsz,
5029 		(void *)&cmd_tunnel_tso_set_portid,
5030 		NULL,
5031 	},
5032 };
5033 
5034 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5035 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5036 				mode, "show");
5037 
5038 
5039 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5040 	.f = cmd_tunnel_tso_set_parsed,
5041 	.data = NULL,
5042 	.help_str = "tunnel_tso show <port_id> "
5043 		"Show TSO segment size of tunneled packets for csum engine",
5044 	.tokens = {
5045 		(void *)&cmd_tunnel_tso_set_tso,
5046 		(void *)&cmd_tunnel_tso_show_mode,
5047 		(void *)&cmd_tunnel_tso_set_portid,
5048 		NULL,
5049 	},
5050 };
5051 
5052 /* *** SET GRO FOR A PORT *** */
5053 struct cmd_gro_enable_result {
5054 	cmdline_fixed_string_t cmd_set;
5055 	cmdline_fixed_string_t cmd_port;
5056 	cmdline_fixed_string_t cmd_keyword;
5057 	cmdline_fixed_string_t cmd_onoff;
5058 	portid_t cmd_pid;
5059 };
5060 
5061 static void
5062 cmd_gro_enable_parsed(void *parsed_result,
5063 		__rte_unused struct cmdline *cl,
5064 		__rte_unused void *data)
5065 {
5066 	struct cmd_gro_enable_result *res;
5067 
5068 	res = parsed_result;
5069 	if (!strcmp(res->cmd_keyword, "gro"))
5070 		setup_gro(res->cmd_onoff, res->cmd_pid);
5071 }
5072 
5073 cmdline_parse_token_string_t cmd_gro_enable_set =
5074 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5075 			cmd_set, "set");
5076 cmdline_parse_token_string_t cmd_gro_enable_port =
5077 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5078 			cmd_keyword, "port");
5079 cmdline_parse_token_num_t cmd_gro_enable_pid =
5080 	TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5081 			cmd_pid, UINT16);
5082 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5083 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5084 			cmd_keyword, "gro");
5085 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5086 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5087 			cmd_onoff, "on#off");
5088 
5089 cmdline_parse_inst_t cmd_gro_enable = {
5090 	.f = cmd_gro_enable_parsed,
5091 	.data = NULL,
5092 	.help_str = "set port <port_id> gro on|off",
5093 	.tokens = {
5094 		(void *)&cmd_gro_enable_set,
5095 		(void *)&cmd_gro_enable_port,
5096 		(void *)&cmd_gro_enable_pid,
5097 		(void *)&cmd_gro_enable_keyword,
5098 		(void *)&cmd_gro_enable_onoff,
5099 		NULL,
5100 	},
5101 };
5102 
5103 /* *** DISPLAY GRO CONFIGURATION *** */
5104 struct cmd_gro_show_result {
5105 	cmdline_fixed_string_t cmd_show;
5106 	cmdline_fixed_string_t cmd_port;
5107 	cmdline_fixed_string_t cmd_keyword;
5108 	portid_t cmd_pid;
5109 };
5110 
5111 static void
5112 cmd_gro_show_parsed(void *parsed_result,
5113 		__rte_unused struct cmdline *cl,
5114 		__rte_unused void *data)
5115 {
5116 	struct cmd_gro_show_result *res;
5117 
5118 	res = parsed_result;
5119 	if (!strcmp(res->cmd_keyword, "gro"))
5120 		show_gro(res->cmd_pid);
5121 }
5122 
5123 cmdline_parse_token_string_t cmd_gro_show_show =
5124 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5125 			cmd_show, "show");
5126 cmdline_parse_token_string_t cmd_gro_show_port =
5127 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5128 			cmd_port, "port");
5129 cmdline_parse_token_num_t cmd_gro_show_pid =
5130 	TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5131 			cmd_pid, UINT16);
5132 cmdline_parse_token_string_t cmd_gro_show_keyword =
5133 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5134 			cmd_keyword, "gro");
5135 
5136 cmdline_parse_inst_t cmd_gro_show = {
5137 	.f = cmd_gro_show_parsed,
5138 	.data = NULL,
5139 	.help_str = "show port <port_id> gro",
5140 	.tokens = {
5141 		(void *)&cmd_gro_show_show,
5142 		(void *)&cmd_gro_show_port,
5143 		(void *)&cmd_gro_show_pid,
5144 		(void *)&cmd_gro_show_keyword,
5145 		NULL,
5146 	},
5147 };
5148 
5149 /* *** SET FLUSH CYCLES FOR GRO *** */
5150 struct cmd_gro_flush_result {
5151 	cmdline_fixed_string_t cmd_set;
5152 	cmdline_fixed_string_t cmd_keyword;
5153 	cmdline_fixed_string_t cmd_flush;
5154 	uint8_t cmd_cycles;
5155 };
5156 
5157 static void
5158 cmd_gro_flush_parsed(void *parsed_result,
5159 		__rte_unused struct cmdline *cl,
5160 		__rte_unused void *data)
5161 {
5162 	struct cmd_gro_flush_result *res;
5163 
5164 	res = parsed_result;
5165 	if ((!strcmp(res->cmd_keyword, "gro")) &&
5166 			(!strcmp(res->cmd_flush, "flush")))
5167 		setup_gro_flush_cycles(res->cmd_cycles);
5168 }
5169 
5170 cmdline_parse_token_string_t cmd_gro_flush_set =
5171 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5172 			cmd_set, "set");
5173 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5174 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5175 			cmd_keyword, "gro");
5176 cmdline_parse_token_string_t cmd_gro_flush_flush =
5177 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5178 			cmd_flush, "flush");
5179 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5180 	TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5181 			cmd_cycles, UINT8);
5182 
5183 cmdline_parse_inst_t cmd_gro_flush = {
5184 	.f = cmd_gro_flush_parsed,
5185 	.data = NULL,
5186 	.help_str = "set gro flush <cycles>",
5187 	.tokens = {
5188 		(void *)&cmd_gro_flush_set,
5189 		(void *)&cmd_gro_flush_keyword,
5190 		(void *)&cmd_gro_flush_flush,
5191 		(void *)&cmd_gro_flush_cycles,
5192 		NULL,
5193 	},
5194 };
5195 
5196 /* *** ENABLE/DISABLE GSO *** */
5197 struct cmd_gso_enable_result {
5198 	cmdline_fixed_string_t cmd_set;
5199 	cmdline_fixed_string_t cmd_port;
5200 	cmdline_fixed_string_t cmd_keyword;
5201 	cmdline_fixed_string_t cmd_mode;
5202 	portid_t cmd_pid;
5203 };
5204 
5205 static void
5206 cmd_gso_enable_parsed(void *parsed_result,
5207 		__rte_unused struct cmdline *cl,
5208 		__rte_unused void *data)
5209 {
5210 	struct cmd_gso_enable_result *res;
5211 
5212 	res = parsed_result;
5213 	if (!strcmp(res->cmd_keyword, "gso"))
5214 		setup_gso(res->cmd_mode, res->cmd_pid);
5215 }
5216 
5217 cmdline_parse_token_string_t cmd_gso_enable_set =
5218 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5219 			cmd_set, "set");
5220 cmdline_parse_token_string_t cmd_gso_enable_port =
5221 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5222 			cmd_port, "port");
5223 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5224 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5225 			cmd_keyword, "gso");
5226 cmdline_parse_token_string_t cmd_gso_enable_mode =
5227 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5228 			cmd_mode, "on#off");
5229 cmdline_parse_token_num_t cmd_gso_enable_pid =
5230 	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5231 			cmd_pid, UINT16);
5232 
5233 cmdline_parse_inst_t cmd_gso_enable = {
5234 	.f = cmd_gso_enable_parsed,
5235 	.data = NULL,
5236 	.help_str = "set port <port_id> gso on|off",
5237 	.tokens = {
5238 		(void *)&cmd_gso_enable_set,
5239 		(void *)&cmd_gso_enable_port,
5240 		(void *)&cmd_gso_enable_pid,
5241 		(void *)&cmd_gso_enable_keyword,
5242 		(void *)&cmd_gso_enable_mode,
5243 		NULL,
5244 	},
5245 };
5246 
5247 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5248 struct cmd_gso_size_result {
5249 	cmdline_fixed_string_t cmd_set;
5250 	cmdline_fixed_string_t cmd_keyword;
5251 	cmdline_fixed_string_t cmd_segsz;
5252 	uint16_t cmd_size;
5253 };
5254 
5255 static void
5256 cmd_gso_size_parsed(void *parsed_result,
5257 		       __rte_unused struct cmdline *cl,
5258 		       __rte_unused void *data)
5259 {
5260 	struct cmd_gso_size_result *res = parsed_result;
5261 
5262 	if (test_done == 0) {
5263 		printf("Before setting GSO segsz, please first"
5264 				" stop forwarding\n");
5265 		return;
5266 	}
5267 
5268 	if (!strcmp(res->cmd_keyword, "gso") &&
5269 			!strcmp(res->cmd_segsz, "segsz")) {
5270 		if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5271 			printf("gso_size should be larger than %zu."
5272 					" Please input a legal value\n",
5273 					RTE_GSO_SEG_SIZE_MIN);
5274 		else
5275 			gso_max_segment_size = res->cmd_size;
5276 	}
5277 }
5278 
5279 cmdline_parse_token_string_t cmd_gso_size_set =
5280 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5281 				cmd_set, "set");
5282 cmdline_parse_token_string_t cmd_gso_size_keyword =
5283 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5284 				cmd_keyword, "gso");
5285 cmdline_parse_token_string_t cmd_gso_size_segsz =
5286 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5287 				cmd_segsz, "segsz");
5288 cmdline_parse_token_num_t cmd_gso_size_size =
5289 	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5290 				cmd_size, UINT16);
5291 
5292 cmdline_parse_inst_t cmd_gso_size = {
5293 	.f = cmd_gso_size_parsed,
5294 	.data = NULL,
5295 	.help_str = "set gso segsz <length>",
5296 	.tokens = {
5297 		(void *)&cmd_gso_size_set,
5298 		(void *)&cmd_gso_size_keyword,
5299 		(void *)&cmd_gso_size_segsz,
5300 		(void *)&cmd_gso_size_size,
5301 		NULL,
5302 	},
5303 };
5304 
5305 /* *** SHOW GSO CONFIGURATION *** */
5306 struct cmd_gso_show_result {
5307 	cmdline_fixed_string_t cmd_show;
5308 	cmdline_fixed_string_t cmd_port;
5309 	cmdline_fixed_string_t cmd_keyword;
5310 	portid_t cmd_pid;
5311 };
5312 
5313 static void
5314 cmd_gso_show_parsed(void *parsed_result,
5315 		       __rte_unused struct cmdline *cl,
5316 		       __rte_unused void *data)
5317 {
5318 	struct cmd_gso_show_result *res = parsed_result;
5319 
5320 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5321 		printf("invalid port id %u\n", res->cmd_pid);
5322 		return;
5323 	}
5324 	if (!strcmp(res->cmd_keyword, "gso")) {
5325 		if (gso_ports[res->cmd_pid].enable) {
5326 			printf("Max GSO'd packet size: %uB\n"
5327 					"Supported GSO types: TCP/IPv4, "
5328 					"UDP/IPv4, VxLAN with inner "
5329 					"TCP/IPv4 packet, GRE with inner "
5330 					"TCP/IPv4 packet\n",
5331 					gso_max_segment_size);
5332 		} else
5333 			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5334 	}
5335 }
5336 
5337 cmdline_parse_token_string_t cmd_gso_show_show =
5338 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5339 		cmd_show, "show");
5340 cmdline_parse_token_string_t cmd_gso_show_port =
5341 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5342 		cmd_port, "port");
5343 cmdline_parse_token_string_t cmd_gso_show_keyword =
5344 	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5345 				cmd_keyword, "gso");
5346 cmdline_parse_token_num_t cmd_gso_show_pid =
5347 	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5348 				cmd_pid, UINT16);
5349 
5350 cmdline_parse_inst_t cmd_gso_show = {
5351 	.f = cmd_gso_show_parsed,
5352 	.data = NULL,
5353 	.help_str = "show port <port_id> gso",
5354 	.tokens = {
5355 		(void *)&cmd_gso_show_show,
5356 		(void *)&cmd_gso_show_port,
5357 		(void *)&cmd_gso_show_pid,
5358 		(void *)&cmd_gso_show_keyword,
5359 		NULL,
5360 	},
5361 };
5362 
5363 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5364 struct cmd_set_flush_rx {
5365 	cmdline_fixed_string_t set;
5366 	cmdline_fixed_string_t flush_rx;
5367 	cmdline_fixed_string_t mode;
5368 };
5369 
5370 static void
5371 cmd_set_flush_rx_parsed(void *parsed_result,
5372 		__rte_unused struct cmdline *cl,
5373 		__rte_unused void *data)
5374 {
5375 	struct cmd_set_flush_rx *res = parsed_result;
5376 	no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5377 }
5378 
5379 cmdline_parse_token_string_t cmd_setflushrx_set =
5380 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5381 			set, "set");
5382 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5383 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5384 			flush_rx, "flush_rx");
5385 cmdline_parse_token_string_t cmd_setflushrx_mode =
5386 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5387 			mode, "on#off");
5388 
5389 
5390 cmdline_parse_inst_t cmd_set_flush_rx = {
5391 	.f = cmd_set_flush_rx_parsed,
5392 	.help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5393 	.data = NULL,
5394 	.tokens = {
5395 		(void *)&cmd_setflushrx_set,
5396 		(void *)&cmd_setflushrx_flush_rx,
5397 		(void *)&cmd_setflushrx_mode,
5398 		NULL,
5399 	},
5400 };
5401 
5402 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5403 struct cmd_set_link_check {
5404 	cmdline_fixed_string_t set;
5405 	cmdline_fixed_string_t link_check;
5406 	cmdline_fixed_string_t mode;
5407 };
5408 
5409 static void
5410 cmd_set_link_check_parsed(void *parsed_result,
5411 		__rte_unused struct cmdline *cl,
5412 		__rte_unused void *data)
5413 {
5414 	struct cmd_set_link_check *res = parsed_result;
5415 	no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5416 }
5417 
5418 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5419 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5420 			set, "set");
5421 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5422 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5423 			link_check, "link_check");
5424 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5425 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5426 			mode, "on#off");
5427 
5428 
5429 cmdline_parse_inst_t cmd_set_link_check = {
5430 	.f = cmd_set_link_check_parsed,
5431 	.help_str = "set link_check on|off: Enable/Disable link status check "
5432 	            "when starting/stopping a port",
5433 	.data = NULL,
5434 	.tokens = {
5435 		(void *)&cmd_setlinkcheck_set,
5436 		(void *)&cmd_setlinkcheck_link_check,
5437 		(void *)&cmd_setlinkcheck_mode,
5438 		NULL,
5439 	},
5440 };
5441 
5442 /* *** SET NIC BYPASS MODE *** */
5443 struct cmd_set_bypass_mode_result {
5444 	cmdline_fixed_string_t set;
5445 	cmdline_fixed_string_t bypass;
5446 	cmdline_fixed_string_t mode;
5447 	cmdline_fixed_string_t value;
5448 	portid_t port_id;
5449 };
5450 
5451 static void
5452 cmd_set_bypass_mode_parsed(void *parsed_result,
5453 		__rte_unused struct cmdline *cl,
5454 		__rte_unused void *data)
5455 {
5456 	struct cmd_set_bypass_mode_result *res = parsed_result;
5457 	portid_t port_id = res->port_id;
5458 	int32_t rc = -EINVAL;
5459 
5460 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5461 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5462 
5463 	if (!strcmp(res->value, "bypass"))
5464 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5465 	else if (!strcmp(res->value, "isolate"))
5466 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5467 	else
5468 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5469 
5470 	/* Set the bypass mode for the relevant port. */
5471 	rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5472 #endif
5473 	if (rc != 0)
5474 		printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5475 }
5476 
5477 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5478 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5479 			set, "set");
5480 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5481 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5482 			bypass, "bypass");
5483 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5484 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5485 			mode, "mode");
5486 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5487 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5488 			value, "normal#bypass#isolate");
5489 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5490 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5491 				port_id, UINT16);
5492 
5493 cmdline_parse_inst_t cmd_set_bypass_mode = {
5494 	.f = cmd_set_bypass_mode_parsed,
5495 	.help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5496 	            "Set the NIC bypass mode for port_id",
5497 	.data = NULL,
5498 	.tokens = {
5499 		(void *)&cmd_setbypass_mode_set,
5500 		(void *)&cmd_setbypass_mode_bypass,
5501 		(void *)&cmd_setbypass_mode_mode,
5502 		(void *)&cmd_setbypass_mode_value,
5503 		(void *)&cmd_setbypass_mode_port,
5504 		NULL,
5505 	},
5506 };
5507 
5508 /* *** SET NIC BYPASS EVENT *** */
5509 struct cmd_set_bypass_event_result {
5510 	cmdline_fixed_string_t set;
5511 	cmdline_fixed_string_t bypass;
5512 	cmdline_fixed_string_t event;
5513 	cmdline_fixed_string_t event_value;
5514 	cmdline_fixed_string_t mode;
5515 	cmdline_fixed_string_t mode_value;
5516 	portid_t port_id;
5517 };
5518 
5519 static void
5520 cmd_set_bypass_event_parsed(void *parsed_result,
5521 		__rte_unused struct cmdline *cl,
5522 		__rte_unused void *data)
5523 {
5524 	int32_t rc = -EINVAL;
5525 	struct cmd_set_bypass_event_result *res = parsed_result;
5526 	portid_t port_id = res->port_id;
5527 
5528 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5529 	uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5530 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5531 
5532 	if (!strcmp(res->event_value, "timeout"))
5533 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5534 	else if (!strcmp(res->event_value, "os_on"))
5535 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5536 	else if (!strcmp(res->event_value, "os_off"))
5537 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5538 	else if (!strcmp(res->event_value, "power_on"))
5539 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5540 	else if (!strcmp(res->event_value, "power_off"))
5541 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5542 	else
5543 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5544 
5545 	if (!strcmp(res->mode_value, "bypass"))
5546 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5547 	else if (!strcmp(res->mode_value, "isolate"))
5548 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5549 	else
5550 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5551 
5552 	/* Set the watchdog timeout. */
5553 	if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5554 
5555 		rc = -EINVAL;
5556 		if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5557 			rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5558 							   bypass_timeout);
5559 		}
5560 		if (rc != 0) {
5561 			printf("Failed to set timeout value %u "
5562 			"for port %d, errto code: %d.\n",
5563 			bypass_timeout, port_id, rc);
5564 		}
5565 	}
5566 
5567 	/* Set the bypass event to transition to bypass mode. */
5568 	rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5569 					      bypass_mode);
5570 #endif
5571 
5572 	if (rc != 0)
5573 		printf("\t Failed to set bypass event for port = %d.\n",
5574 		       port_id);
5575 }
5576 
5577 cmdline_parse_token_string_t cmd_setbypass_event_set =
5578 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5579 			set, "set");
5580 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5581 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5582 			bypass, "bypass");
5583 cmdline_parse_token_string_t cmd_setbypass_event_event =
5584 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5585 			event, "event");
5586 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5587 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5588 			event_value, "none#timeout#os_off#os_on#power_on#power_off");
5589 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5590 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5591 			mode, "mode");
5592 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5593 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5594 			mode_value, "normal#bypass#isolate");
5595 cmdline_parse_token_num_t cmd_setbypass_event_port =
5596 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5597 				port_id, UINT16);
5598 
5599 cmdline_parse_inst_t cmd_set_bypass_event = {
5600 	.f = cmd_set_bypass_event_parsed,
5601 	.help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5602 		"power_off mode normal|bypass|isolate <port_id>: "
5603 		"Set the NIC bypass event mode for port_id",
5604 	.data = NULL,
5605 	.tokens = {
5606 		(void *)&cmd_setbypass_event_set,
5607 		(void *)&cmd_setbypass_event_bypass,
5608 		(void *)&cmd_setbypass_event_event,
5609 		(void *)&cmd_setbypass_event_event_value,
5610 		(void *)&cmd_setbypass_event_mode,
5611 		(void *)&cmd_setbypass_event_mode_value,
5612 		(void *)&cmd_setbypass_event_port,
5613 		NULL,
5614 	},
5615 };
5616 
5617 
5618 /* *** SET NIC BYPASS TIMEOUT *** */
5619 struct cmd_set_bypass_timeout_result {
5620 	cmdline_fixed_string_t set;
5621 	cmdline_fixed_string_t bypass;
5622 	cmdline_fixed_string_t timeout;
5623 	cmdline_fixed_string_t value;
5624 };
5625 
5626 static void
5627 cmd_set_bypass_timeout_parsed(void *parsed_result,
5628 		__rte_unused struct cmdline *cl,
5629 		__rte_unused void *data)
5630 {
5631 	__rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5632 
5633 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5634 	if (!strcmp(res->value, "1.5"))
5635 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5636 	else if (!strcmp(res->value, "2"))
5637 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5638 	else if (!strcmp(res->value, "3"))
5639 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5640 	else if (!strcmp(res->value, "4"))
5641 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5642 	else if (!strcmp(res->value, "8"))
5643 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5644 	else if (!strcmp(res->value, "16"))
5645 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5646 	else if (!strcmp(res->value, "32"))
5647 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5648 	else
5649 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5650 #endif
5651 }
5652 
5653 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5654 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5655 			set, "set");
5656 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5657 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5658 			bypass, "bypass");
5659 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5660 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5661 			timeout, "timeout");
5662 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5663 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5664 			value, "0#1.5#2#3#4#8#16#32");
5665 
5666 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5667 	.f = cmd_set_bypass_timeout_parsed,
5668 	.help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5669 		"Set the NIC bypass watchdog timeout in seconds",
5670 	.data = NULL,
5671 	.tokens = {
5672 		(void *)&cmd_setbypass_timeout_set,
5673 		(void *)&cmd_setbypass_timeout_bypass,
5674 		(void *)&cmd_setbypass_timeout_timeout,
5675 		(void *)&cmd_setbypass_timeout_value,
5676 		NULL,
5677 	},
5678 };
5679 
5680 /* *** SHOW NIC BYPASS MODE *** */
5681 struct cmd_show_bypass_config_result {
5682 	cmdline_fixed_string_t show;
5683 	cmdline_fixed_string_t bypass;
5684 	cmdline_fixed_string_t config;
5685 	portid_t port_id;
5686 };
5687 
5688 static void
5689 cmd_show_bypass_config_parsed(void *parsed_result,
5690 		__rte_unused struct cmdline *cl,
5691 		__rte_unused void *data)
5692 {
5693 	struct cmd_show_bypass_config_result *res = parsed_result;
5694 	portid_t port_id = res->port_id;
5695 	int rc = -EINVAL;
5696 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5697 	uint32_t event_mode;
5698 	uint32_t bypass_mode;
5699 	uint32_t timeout = bypass_timeout;
5700 	unsigned int i;
5701 
5702 	static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5703 		{"off", "1.5", "2", "3", "4", "8", "16", "32"};
5704 	static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5705 		{"UNKNOWN", "normal", "bypass", "isolate"};
5706 	static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5707 		"NONE",
5708 		"OS/board on",
5709 		"power supply on",
5710 		"OS/board off",
5711 		"power supply off",
5712 		"timeout"};
5713 
5714 	/* Display the bypass mode.*/
5715 	if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5716 		printf("\tFailed to get bypass mode for port = %d\n", port_id);
5717 		return;
5718 	}
5719 	else {
5720 		if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5721 			bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5722 
5723 		printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5724 	}
5725 
5726 	/* Display the bypass timeout.*/
5727 	if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5728 		timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5729 
5730 	printf("\tbypass timeout = %s\n", timeouts[timeout]);
5731 
5732 	/* Display the bypass events and associated modes. */
5733 	for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5734 
5735 		if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5736 			printf("\tFailed to get bypass mode for event = %s\n",
5737 				events[i]);
5738 		} else {
5739 			if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5740 				event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5741 
5742 			printf("\tbypass event: %-16s = %s\n", events[i],
5743 				modes[event_mode]);
5744 		}
5745 	}
5746 #endif
5747 	if (rc != 0)
5748 		printf("\tFailed to get bypass configuration for port = %d\n",
5749 		       port_id);
5750 }
5751 
5752 cmdline_parse_token_string_t cmd_showbypass_config_show =
5753 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5754 			show, "show");
5755 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5756 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5757 			bypass, "bypass");
5758 cmdline_parse_token_string_t cmd_showbypass_config_config =
5759 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5760 			config, "config");
5761 cmdline_parse_token_num_t cmd_showbypass_config_port =
5762 	TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5763 				port_id, UINT16);
5764 
5765 cmdline_parse_inst_t cmd_show_bypass_config = {
5766 	.f = cmd_show_bypass_config_parsed,
5767 	.help_str = "show bypass config <port_id>: "
5768 	            "Show the NIC bypass config for port_id",
5769 	.data = NULL,
5770 	.tokens = {
5771 		(void *)&cmd_showbypass_config_show,
5772 		(void *)&cmd_showbypass_config_bypass,
5773 		(void *)&cmd_showbypass_config_config,
5774 		(void *)&cmd_showbypass_config_port,
5775 		NULL,
5776 	},
5777 };
5778 
5779 #ifdef RTE_LIBRTE_PMD_BOND
5780 /* *** SET BONDING MODE *** */
5781 struct cmd_set_bonding_mode_result {
5782 	cmdline_fixed_string_t set;
5783 	cmdline_fixed_string_t bonding;
5784 	cmdline_fixed_string_t mode;
5785 	uint8_t value;
5786 	portid_t port_id;
5787 };
5788 
5789 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5790 		__rte_unused  struct cmdline *cl,
5791 		__rte_unused void *data)
5792 {
5793 	struct cmd_set_bonding_mode_result *res = parsed_result;
5794 	portid_t port_id = res->port_id;
5795 
5796 	/* Set the bonding mode for the relevant port. */
5797 	if (0 != rte_eth_bond_mode_set(port_id, res->value))
5798 		printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5799 }
5800 
5801 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5802 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5803 		set, "set");
5804 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5805 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5806 		bonding, "bonding");
5807 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5808 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5809 		mode, "mode");
5810 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5811 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5812 		value, UINT8);
5813 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5814 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5815 		port_id, UINT16);
5816 
5817 cmdline_parse_inst_t cmd_set_bonding_mode = {
5818 		.f = cmd_set_bonding_mode_parsed,
5819 		.help_str = "set bonding mode <mode_value> <port_id>: "
5820 			"Set the bonding mode for port_id",
5821 		.data = NULL,
5822 		.tokens = {
5823 				(void *) &cmd_setbonding_mode_set,
5824 				(void *) &cmd_setbonding_mode_bonding,
5825 				(void *) &cmd_setbonding_mode_mode,
5826 				(void *) &cmd_setbonding_mode_value,
5827 				(void *) &cmd_setbonding_mode_port,
5828 				NULL
5829 		}
5830 };
5831 
5832 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5833 struct cmd_set_bonding_lacp_dedicated_queues_result {
5834 	cmdline_fixed_string_t set;
5835 	cmdline_fixed_string_t bonding;
5836 	cmdline_fixed_string_t lacp;
5837 	cmdline_fixed_string_t dedicated_queues;
5838 	portid_t port_id;
5839 	cmdline_fixed_string_t mode;
5840 };
5841 
5842 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5843 		__rte_unused  struct cmdline *cl,
5844 		__rte_unused void *data)
5845 {
5846 	struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5847 	portid_t port_id = res->port_id;
5848 	struct rte_port *port;
5849 
5850 	port = &ports[port_id];
5851 
5852 	/** Check if the port is not started **/
5853 	if (port->port_status != RTE_PORT_STOPPED) {
5854 		printf("Please stop port %d first\n", port_id);
5855 		return;
5856 	}
5857 
5858 	if (!strcmp(res->mode, "enable")) {
5859 		if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5860 			printf("Dedicate queues for LACP control packets"
5861 					" enabled\n");
5862 		else
5863 			printf("Enabling dedicate queues for LACP control "
5864 					"packets on port %d failed\n", port_id);
5865 	} else if (!strcmp(res->mode, "disable")) {
5866 		if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5867 			printf("Dedicated queues for LACP control packets "
5868 					"disabled\n");
5869 		else
5870 			printf("Disabling dedicated queues for LACP control "
5871 					"traffic on port %d failed\n", port_id);
5872 	}
5873 }
5874 
5875 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5876 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5877 		set, "set");
5878 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5879 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5880 		bonding, "bonding");
5881 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5882 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5883 		lacp, "lacp");
5884 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5885 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5886 		dedicated_queues, "dedicated_queues");
5887 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5888 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5889 		port_id, UINT16);
5890 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5891 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5892 		mode, "enable#disable");
5893 
5894 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5895 		.f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5896 		.help_str = "set bonding lacp dedicated_queues <port_id> "
5897 			"enable|disable: "
5898 			"Enable/disable dedicated queues for LACP control traffic for port_id",
5899 		.data = NULL,
5900 		.tokens = {
5901 			(void *)&cmd_setbonding_lacp_dedicated_queues_set,
5902 			(void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5903 			(void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5904 			(void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5905 			(void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5906 			(void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5907 			NULL
5908 		}
5909 };
5910 
5911 /* *** SET BALANCE XMIT POLICY *** */
5912 struct cmd_set_bonding_balance_xmit_policy_result {
5913 	cmdline_fixed_string_t set;
5914 	cmdline_fixed_string_t bonding;
5915 	cmdline_fixed_string_t balance_xmit_policy;
5916 	portid_t port_id;
5917 	cmdline_fixed_string_t policy;
5918 };
5919 
5920 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5921 		__rte_unused  struct cmdline *cl,
5922 		__rte_unused void *data)
5923 {
5924 	struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5925 	portid_t port_id = res->port_id;
5926 	uint8_t policy;
5927 
5928 	if (!strcmp(res->policy, "l2")) {
5929 		policy = BALANCE_XMIT_POLICY_LAYER2;
5930 	} else if (!strcmp(res->policy, "l23")) {
5931 		policy = BALANCE_XMIT_POLICY_LAYER23;
5932 	} else if (!strcmp(res->policy, "l34")) {
5933 		policy = BALANCE_XMIT_POLICY_LAYER34;
5934 	} else {
5935 		printf("\t Invalid xmit policy selection");
5936 		return;
5937 	}
5938 
5939 	/* Set the bonding mode for the relevant port. */
5940 	if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5941 		printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5942 				port_id);
5943 	}
5944 }
5945 
5946 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5947 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5948 		set, "set");
5949 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5950 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5951 		bonding, "bonding");
5952 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5953 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5954 		balance_xmit_policy, "balance_xmit_policy");
5955 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5956 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5957 		port_id, UINT16);
5958 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5959 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5960 		policy, "l2#l23#l34");
5961 
5962 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5963 		.f = cmd_set_bonding_balance_xmit_policy_parsed,
5964 		.help_str = "set bonding balance_xmit_policy <port_id> "
5965 			"l2|l23|l34: "
5966 			"Set the bonding balance_xmit_policy for port_id",
5967 		.data = NULL,
5968 		.tokens = {
5969 				(void *)&cmd_setbonding_balance_xmit_policy_set,
5970 				(void *)&cmd_setbonding_balance_xmit_policy_bonding,
5971 				(void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5972 				(void *)&cmd_setbonding_balance_xmit_policy_port,
5973 				(void *)&cmd_setbonding_balance_xmit_policy_policy,
5974 				NULL
5975 		}
5976 };
5977 
5978 /* *** SHOW NIC BONDING CONFIGURATION *** */
5979 struct cmd_show_bonding_config_result {
5980 	cmdline_fixed_string_t show;
5981 	cmdline_fixed_string_t bonding;
5982 	cmdline_fixed_string_t config;
5983 	portid_t port_id;
5984 };
5985 
5986 static void cmd_show_bonding_config_parsed(void *parsed_result,
5987 		__rte_unused  struct cmdline *cl,
5988 		__rte_unused void *data)
5989 {
5990 	struct cmd_show_bonding_config_result *res = parsed_result;
5991 	int bonding_mode, agg_mode;
5992 	portid_t slaves[RTE_MAX_ETHPORTS];
5993 	int num_slaves, num_active_slaves;
5994 	int primary_id;
5995 	int i;
5996 	portid_t port_id = res->port_id;
5997 
5998 	/* Display the bonding mode.*/
5999 	bonding_mode = rte_eth_bond_mode_get(port_id);
6000 	if (bonding_mode < 0) {
6001 		printf("\tFailed to get bonding mode for port = %d\n", port_id);
6002 		return;
6003 	} else
6004 		printf("\tBonding mode: %d\n", bonding_mode);
6005 
6006 	if (bonding_mode == BONDING_MODE_BALANCE) {
6007 		int balance_xmit_policy;
6008 
6009 		balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6010 		if (balance_xmit_policy < 0) {
6011 			printf("\tFailed to get balance xmit policy for port = %d\n",
6012 					port_id);
6013 			return;
6014 		} else {
6015 			printf("\tBalance Xmit Policy: ");
6016 
6017 			switch (balance_xmit_policy) {
6018 			case BALANCE_XMIT_POLICY_LAYER2:
6019 				printf("BALANCE_XMIT_POLICY_LAYER2");
6020 				break;
6021 			case BALANCE_XMIT_POLICY_LAYER23:
6022 				printf("BALANCE_XMIT_POLICY_LAYER23");
6023 				break;
6024 			case BALANCE_XMIT_POLICY_LAYER34:
6025 				printf("BALANCE_XMIT_POLICY_LAYER34");
6026 				break;
6027 			}
6028 			printf("\n");
6029 		}
6030 	}
6031 
6032 	if (bonding_mode == BONDING_MODE_8023AD) {
6033 		agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6034 		printf("\tIEEE802.3AD Aggregator Mode: ");
6035 		switch (agg_mode) {
6036 		case AGG_BANDWIDTH:
6037 			printf("bandwidth");
6038 			break;
6039 		case AGG_STABLE:
6040 			printf("stable");
6041 			break;
6042 		case AGG_COUNT:
6043 			printf("count");
6044 			break;
6045 		}
6046 		printf("\n");
6047 	}
6048 
6049 	num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6050 
6051 	if (num_slaves < 0) {
6052 		printf("\tFailed to get slave list for port = %d\n", port_id);
6053 		return;
6054 	}
6055 	if (num_slaves > 0) {
6056 		printf("\tSlaves (%d): [", num_slaves);
6057 		for (i = 0; i < num_slaves - 1; i++)
6058 			printf("%d ", slaves[i]);
6059 
6060 		printf("%d]\n", slaves[num_slaves - 1]);
6061 	} else {
6062 		printf("\tSlaves: []\n");
6063 
6064 	}
6065 
6066 	num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6067 			RTE_MAX_ETHPORTS);
6068 
6069 	if (num_active_slaves < 0) {
6070 		printf("\tFailed to get active slave list for port = %d\n", port_id);
6071 		return;
6072 	}
6073 	if (num_active_slaves > 0) {
6074 		printf("\tActive Slaves (%d): [", num_active_slaves);
6075 		for (i = 0; i < num_active_slaves - 1; i++)
6076 			printf("%d ", slaves[i]);
6077 
6078 		printf("%d]\n", slaves[num_active_slaves - 1]);
6079 
6080 	} else {
6081 		printf("\tActive Slaves: []\n");
6082 
6083 	}
6084 
6085 	primary_id = rte_eth_bond_primary_get(port_id);
6086 	if (primary_id < 0) {
6087 		printf("\tFailed to get primary slave for port = %d\n", port_id);
6088 		return;
6089 	} else
6090 		printf("\tPrimary: [%d]\n", primary_id);
6091 
6092 }
6093 
6094 cmdline_parse_token_string_t cmd_showbonding_config_show =
6095 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6096 		show, "show");
6097 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6098 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6099 		bonding, "bonding");
6100 cmdline_parse_token_string_t cmd_showbonding_config_config =
6101 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6102 		config, "config");
6103 cmdline_parse_token_num_t cmd_showbonding_config_port =
6104 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6105 		port_id, UINT16);
6106 
6107 cmdline_parse_inst_t cmd_show_bonding_config = {
6108 		.f = cmd_show_bonding_config_parsed,
6109 		.help_str = "show bonding config <port_id>: "
6110 			"Show the bonding config for port_id",
6111 		.data = NULL,
6112 		.tokens = {
6113 				(void *)&cmd_showbonding_config_show,
6114 				(void *)&cmd_showbonding_config_bonding,
6115 				(void *)&cmd_showbonding_config_config,
6116 				(void *)&cmd_showbonding_config_port,
6117 				NULL
6118 		}
6119 };
6120 
6121 /* *** SET BONDING PRIMARY *** */
6122 struct cmd_set_bonding_primary_result {
6123 	cmdline_fixed_string_t set;
6124 	cmdline_fixed_string_t bonding;
6125 	cmdline_fixed_string_t primary;
6126 	portid_t slave_id;
6127 	portid_t port_id;
6128 };
6129 
6130 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6131 		__rte_unused  struct cmdline *cl,
6132 		__rte_unused void *data)
6133 {
6134 	struct cmd_set_bonding_primary_result *res = parsed_result;
6135 	portid_t master_port_id = res->port_id;
6136 	portid_t slave_port_id = res->slave_id;
6137 
6138 	/* Set the primary slave for a bonded device. */
6139 	if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6140 		printf("\t Failed to set primary slave for port = %d.\n",
6141 				master_port_id);
6142 		return;
6143 	}
6144 	init_port_config();
6145 }
6146 
6147 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6148 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6149 		set, "set");
6150 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6151 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6152 		bonding, "bonding");
6153 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6154 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6155 		primary, "primary");
6156 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6157 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6158 		slave_id, UINT16);
6159 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6160 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6161 		port_id, UINT16);
6162 
6163 cmdline_parse_inst_t cmd_set_bonding_primary = {
6164 		.f = cmd_set_bonding_primary_parsed,
6165 		.help_str = "set bonding primary <slave_id> <port_id>: "
6166 			"Set the primary slave for port_id",
6167 		.data = NULL,
6168 		.tokens = {
6169 				(void *)&cmd_setbonding_primary_set,
6170 				(void *)&cmd_setbonding_primary_bonding,
6171 				(void *)&cmd_setbonding_primary_primary,
6172 				(void *)&cmd_setbonding_primary_slave,
6173 				(void *)&cmd_setbonding_primary_port,
6174 				NULL
6175 		}
6176 };
6177 
6178 /* *** ADD SLAVE *** */
6179 struct cmd_add_bonding_slave_result {
6180 	cmdline_fixed_string_t add;
6181 	cmdline_fixed_string_t bonding;
6182 	cmdline_fixed_string_t slave;
6183 	portid_t slave_id;
6184 	portid_t port_id;
6185 };
6186 
6187 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6188 		__rte_unused  struct cmdline *cl,
6189 		__rte_unused void *data)
6190 {
6191 	struct cmd_add_bonding_slave_result *res = parsed_result;
6192 	portid_t master_port_id = res->port_id;
6193 	portid_t slave_port_id = res->slave_id;
6194 
6195 	/* add the slave for a bonded device. */
6196 	if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6197 		printf("\t Failed to add slave %d to master port = %d.\n",
6198 				slave_port_id, master_port_id);
6199 		return;
6200 	}
6201 	init_port_config();
6202 	set_port_slave_flag(slave_port_id);
6203 }
6204 
6205 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6206 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6207 		add, "add");
6208 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6209 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6210 		bonding, "bonding");
6211 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6212 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6213 		slave, "slave");
6214 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6215 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6216 		slave_id, UINT16);
6217 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6218 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6219 		port_id, UINT16);
6220 
6221 cmdline_parse_inst_t cmd_add_bonding_slave = {
6222 		.f = cmd_add_bonding_slave_parsed,
6223 		.help_str = "add bonding slave <slave_id> <port_id>: "
6224 			"Add a slave device to a bonded device",
6225 		.data = NULL,
6226 		.tokens = {
6227 				(void *)&cmd_addbonding_slave_add,
6228 				(void *)&cmd_addbonding_slave_bonding,
6229 				(void *)&cmd_addbonding_slave_slave,
6230 				(void *)&cmd_addbonding_slave_slaveid,
6231 				(void *)&cmd_addbonding_slave_port,
6232 				NULL
6233 		}
6234 };
6235 
6236 /* *** REMOVE SLAVE *** */
6237 struct cmd_remove_bonding_slave_result {
6238 	cmdline_fixed_string_t remove;
6239 	cmdline_fixed_string_t bonding;
6240 	cmdline_fixed_string_t slave;
6241 	portid_t slave_id;
6242 	portid_t port_id;
6243 };
6244 
6245 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6246 		__rte_unused  struct cmdline *cl,
6247 		__rte_unused void *data)
6248 {
6249 	struct cmd_remove_bonding_slave_result *res = parsed_result;
6250 	portid_t master_port_id = res->port_id;
6251 	portid_t slave_port_id = res->slave_id;
6252 
6253 	/* remove the slave from a bonded device. */
6254 	if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6255 		printf("\t Failed to remove slave %d from master port = %d.\n",
6256 				slave_port_id, master_port_id);
6257 		return;
6258 	}
6259 	init_port_config();
6260 	clear_port_slave_flag(slave_port_id);
6261 }
6262 
6263 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6264 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6265 				remove, "remove");
6266 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6267 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6268 				bonding, "bonding");
6269 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6270 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6271 				slave, "slave");
6272 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6273 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6274 				slave_id, UINT16);
6275 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6276 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6277 				port_id, UINT16);
6278 
6279 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6280 		.f = cmd_remove_bonding_slave_parsed,
6281 		.help_str = "remove bonding slave <slave_id> <port_id>: "
6282 			"Remove a slave device from a bonded device",
6283 		.data = NULL,
6284 		.tokens = {
6285 				(void *)&cmd_removebonding_slave_remove,
6286 				(void *)&cmd_removebonding_slave_bonding,
6287 				(void *)&cmd_removebonding_slave_slave,
6288 				(void *)&cmd_removebonding_slave_slaveid,
6289 				(void *)&cmd_removebonding_slave_port,
6290 				NULL
6291 		}
6292 };
6293 
6294 /* *** CREATE BONDED DEVICE *** */
6295 struct cmd_create_bonded_device_result {
6296 	cmdline_fixed_string_t create;
6297 	cmdline_fixed_string_t bonded;
6298 	cmdline_fixed_string_t device;
6299 	uint8_t mode;
6300 	uint8_t socket;
6301 };
6302 
6303 static int bond_dev_num = 0;
6304 
6305 static void cmd_create_bonded_device_parsed(void *parsed_result,
6306 		__rte_unused  struct cmdline *cl,
6307 		__rte_unused void *data)
6308 {
6309 	struct cmd_create_bonded_device_result *res = parsed_result;
6310 	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6311 	int port_id;
6312 	int ret;
6313 
6314 	if (test_done == 0) {
6315 		printf("Please stop forwarding first\n");
6316 		return;
6317 	}
6318 
6319 	snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6320 			bond_dev_num++);
6321 
6322 	/* Create a new bonded device. */
6323 	port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6324 	if (port_id < 0) {
6325 		printf("\t Failed to create bonded device.\n");
6326 		return;
6327 	} else {
6328 		printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6329 				port_id);
6330 
6331 		/* Update number of ports */
6332 		nb_ports = rte_eth_dev_count_avail();
6333 		reconfig(port_id, res->socket);
6334 		ret = rte_eth_promiscuous_enable(port_id);
6335 		if (ret != 0)
6336 			printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6337 				port_id, rte_strerror(-ret));
6338 
6339 		ports[port_id].need_setup = 0;
6340 		ports[port_id].port_status = RTE_PORT_STOPPED;
6341 	}
6342 
6343 }
6344 
6345 cmdline_parse_token_string_t cmd_createbonded_device_create =
6346 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6347 				create, "create");
6348 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6349 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6350 				bonded, "bonded");
6351 cmdline_parse_token_string_t cmd_createbonded_device_device =
6352 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6353 				device, "device");
6354 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6355 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6356 				mode, UINT8);
6357 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6358 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6359 				socket, UINT8);
6360 
6361 cmdline_parse_inst_t cmd_create_bonded_device = {
6362 		.f = cmd_create_bonded_device_parsed,
6363 		.help_str = "create bonded device <mode> <socket>: "
6364 			"Create a new bonded device with specific bonding mode and socket",
6365 		.data = NULL,
6366 		.tokens = {
6367 				(void *)&cmd_createbonded_device_create,
6368 				(void *)&cmd_createbonded_device_bonded,
6369 				(void *)&cmd_createbonded_device_device,
6370 				(void *)&cmd_createbonded_device_mode,
6371 				(void *)&cmd_createbonded_device_socket,
6372 				NULL
6373 		}
6374 };
6375 
6376 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6377 struct cmd_set_bond_mac_addr_result {
6378 	cmdline_fixed_string_t set;
6379 	cmdline_fixed_string_t bonding;
6380 	cmdline_fixed_string_t mac_addr;
6381 	uint16_t port_num;
6382 	struct rte_ether_addr address;
6383 };
6384 
6385 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6386 		__rte_unused  struct cmdline *cl,
6387 		__rte_unused void *data)
6388 {
6389 	struct cmd_set_bond_mac_addr_result *res = parsed_result;
6390 	int ret;
6391 
6392 	if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6393 		return;
6394 
6395 	ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6396 
6397 	/* check the return value and print it if is < 0 */
6398 	if (ret < 0)
6399 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6400 }
6401 
6402 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6403 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6404 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6405 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6406 				"bonding");
6407 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6408 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6409 				"mac_addr");
6410 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6411 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6412 				port_num, UINT16);
6413 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6414 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6415 
6416 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6417 		.f = cmd_set_bond_mac_addr_parsed,
6418 		.data = (void *) 0,
6419 		.help_str = "set bonding mac_addr <port_id> <mac_addr>",
6420 		.tokens = {
6421 				(void *)&cmd_set_bond_mac_addr_set,
6422 				(void *)&cmd_set_bond_mac_addr_bonding,
6423 				(void *)&cmd_set_bond_mac_addr_mac,
6424 				(void *)&cmd_set_bond_mac_addr_portnum,
6425 				(void *)&cmd_set_bond_mac_addr_addr,
6426 				NULL
6427 		}
6428 };
6429 
6430 
6431 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6432 struct cmd_set_bond_mon_period_result {
6433 	cmdline_fixed_string_t set;
6434 	cmdline_fixed_string_t bonding;
6435 	cmdline_fixed_string_t mon_period;
6436 	uint16_t port_num;
6437 	uint32_t period_ms;
6438 };
6439 
6440 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6441 		__rte_unused  struct cmdline *cl,
6442 		__rte_unused void *data)
6443 {
6444 	struct cmd_set_bond_mon_period_result *res = parsed_result;
6445 	int ret;
6446 
6447 	ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6448 
6449 	/* check the return value and print it if is < 0 */
6450 	if (ret < 0)
6451 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6452 }
6453 
6454 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6455 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6456 				set, "set");
6457 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6458 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6459 				bonding, "bonding");
6460 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6461 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6462 				mon_period,	"mon_period");
6463 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6464 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6465 				port_num, UINT16);
6466 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6467 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6468 				period_ms, UINT32);
6469 
6470 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6471 		.f = cmd_set_bond_mon_period_parsed,
6472 		.data = (void *) 0,
6473 		.help_str = "set bonding mon_period <port_id> <period_ms>",
6474 		.tokens = {
6475 				(void *)&cmd_set_bond_mon_period_set,
6476 				(void *)&cmd_set_bond_mon_period_bonding,
6477 				(void *)&cmd_set_bond_mon_period_mon_period,
6478 				(void *)&cmd_set_bond_mon_period_portnum,
6479 				(void *)&cmd_set_bond_mon_period_period_ms,
6480 				NULL
6481 		}
6482 };
6483 
6484 
6485 
6486 struct cmd_set_bonding_agg_mode_policy_result {
6487 	cmdline_fixed_string_t set;
6488 	cmdline_fixed_string_t bonding;
6489 	cmdline_fixed_string_t agg_mode;
6490 	uint16_t port_num;
6491 	cmdline_fixed_string_t policy;
6492 };
6493 
6494 
6495 static void
6496 cmd_set_bonding_agg_mode(void *parsed_result,
6497 		__rte_unused struct cmdline *cl,
6498 		__rte_unused void *data)
6499 {
6500 	struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6501 	uint8_t policy = AGG_BANDWIDTH;
6502 
6503 	if (!strcmp(res->policy, "bandwidth"))
6504 		policy = AGG_BANDWIDTH;
6505 	else if (!strcmp(res->policy, "stable"))
6506 		policy = AGG_STABLE;
6507 	else if (!strcmp(res->policy, "count"))
6508 		policy = AGG_COUNT;
6509 
6510 	rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6511 }
6512 
6513 
6514 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6515 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6516 				set, "set");
6517 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6518 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6519 				bonding, "bonding");
6520 
6521 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6522 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6523 				agg_mode, "agg_mode");
6524 
6525 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6526 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6527 				port_num, UINT16);
6528 
6529 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6530 	TOKEN_STRING_INITIALIZER(
6531 			struct cmd_set_bonding_balance_xmit_policy_result,
6532 		policy, "stable#bandwidth#count");
6533 
6534 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6535 	.f = cmd_set_bonding_agg_mode,
6536 	.data = (void *) 0,
6537 	.help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6538 	.tokens = {
6539 			(void *)&cmd_set_bonding_agg_mode_set,
6540 			(void *)&cmd_set_bonding_agg_mode_bonding,
6541 			(void *)&cmd_set_bonding_agg_mode_agg_mode,
6542 			(void *)&cmd_set_bonding_agg_mode_portnum,
6543 			(void *)&cmd_set_bonding_agg_mode_policy_string,
6544 			NULL
6545 		}
6546 };
6547 
6548 
6549 #endif /* RTE_LIBRTE_PMD_BOND */
6550 
6551 /* *** SET FORWARDING MODE *** */
6552 struct cmd_set_fwd_mode_result {
6553 	cmdline_fixed_string_t set;
6554 	cmdline_fixed_string_t fwd;
6555 	cmdline_fixed_string_t mode;
6556 };
6557 
6558 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6559 				    __rte_unused struct cmdline *cl,
6560 				    __rte_unused void *data)
6561 {
6562 	struct cmd_set_fwd_mode_result *res = parsed_result;
6563 
6564 	retry_enabled = 0;
6565 	set_pkt_forwarding_mode(res->mode);
6566 }
6567 
6568 cmdline_parse_token_string_t cmd_setfwd_set =
6569 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6570 cmdline_parse_token_string_t cmd_setfwd_fwd =
6571 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6572 cmdline_parse_token_string_t cmd_setfwd_mode =
6573 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6574 		"" /* defined at init */);
6575 
6576 cmdline_parse_inst_t cmd_set_fwd_mode = {
6577 	.f = cmd_set_fwd_mode_parsed,
6578 	.data = NULL,
6579 	.help_str = NULL, /* defined at init */
6580 	.tokens = {
6581 		(void *)&cmd_setfwd_set,
6582 		(void *)&cmd_setfwd_fwd,
6583 		(void *)&cmd_setfwd_mode,
6584 		NULL,
6585 	},
6586 };
6587 
6588 static void cmd_set_fwd_mode_init(void)
6589 {
6590 	char *modes, *c;
6591 	static char token[128];
6592 	static char help[256];
6593 	cmdline_parse_token_string_t *token_struct;
6594 
6595 	modes = list_pkt_forwarding_modes();
6596 	snprintf(help, sizeof(help), "set fwd %s: "
6597 		"Set packet forwarding mode", modes);
6598 	cmd_set_fwd_mode.help_str = help;
6599 
6600 	/* string token separator is # */
6601 	for (c = token; *modes != '\0'; modes++)
6602 		if (*modes == '|')
6603 			*c++ = '#';
6604 		else
6605 			*c++ = *modes;
6606 	token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6607 	token_struct->string_data.str = token;
6608 }
6609 
6610 /* *** SET RETRY FORWARDING MODE *** */
6611 struct cmd_set_fwd_retry_mode_result {
6612 	cmdline_fixed_string_t set;
6613 	cmdline_fixed_string_t fwd;
6614 	cmdline_fixed_string_t mode;
6615 	cmdline_fixed_string_t retry;
6616 };
6617 
6618 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6619 			    __rte_unused struct cmdline *cl,
6620 			    __rte_unused void *data)
6621 {
6622 	struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6623 
6624 	retry_enabled = 1;
6625 	set_pkt_forwarding_mode(res->mode);
6626 }
6627 
6628 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6629 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6630 			set, "set");
6631 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6632 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6633 			fwd, "fwd");
6634 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6635 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6636 			mode,
6637 		"" /* defined at init */);
6638 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6639 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6640 			retry, "retry");
6641 
6642 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6643 	.f = cmd_set_fwd_retry_mode_parsed,
6644 	.data = NULL,
6645 	.help_str = NULL, /* defined at init */
6646 	.tokens = {
6647 		(void *)&cmd_setfwd_retry_set,
6648 		(void *)&cmd_setfwd_retry_fwd,
6649 		(void *)&cmd_setfwd_retry_mode,
6650 		(void *)&cmd_setfwd_retry_retry,
6651 		NULL,
6652 	},
6653 };
6654 
6655 static void cmd_set_fwd_retry_mode_init(void)
6656 {
6657 	char *modes, *c;
6658 	static char token[128];
6659 	static char help[256];
6660 	cmdline_parse_token_string_t *token_struct;
6661 
6662 	modes = list_pkt_forwarding_retry_modes();
6663 	snprintf(help, sizeof(help), "set fwd %s retry: "
6664 		"Set packet forwarding mode with retry", modes);
6665 	cmd_set_fwd_retry_mode.help_str = help;
6666 
6667 	/* string token separator is # */
6668 	for (c = token; *modes != '\0'; modes++)
6669 		if (*modes == '|')
6670 			*c++ = '#';
6671 		else
6672 			*c++ = *modes;
6673 	token_struct = (cmdline_parse_token_string_t *)
6674 		cmd_set_fwd_retry_mode.tokens[2];
6675 	token_struct->string_data.str = token;
6676 }
6677 
6678 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6679 struct cmd_set_burst_tx_retry_result {
6680 	cmdline_fixed_string_t set;
6681 	cmdline_fixed_string_t burst;
6682 	cmdline_fixed_string_t tx;
6683 	cmdline_fixed_string_t delay;
6684 	uint32_t time;
6685 	cmdline_fixed_string_t retry;
6686 	uint32_t retry_num;
6687 };
6688 
6689 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6690 					__rte_unused struct cmdline *cl,
6691 					__rte_unused void *data)
6692 {
6693 	struct cmd_set_burst_tx_retry_result *res = parsed_result;
6694 
6695 	if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6696 		&& !strcmp(res->tx, "tx")) {
6697 		if (!strcmp(res->delay, "delay"))
6698 			burst_tx_delay_time = res->time;
6699 		if (!strcmp(res->retry, "retry"))
6700 			burst_tx_retry_num = res->retry_num;
6701 	}
6702 
6703 }
6704 
6705 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6706 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6707 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6708 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6709 				 "burst");
6710 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6711 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6712 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6713 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6714 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6715 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6716 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6717 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6718 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6719 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6720 
6721 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6722 	.f = cmd_set_burst_tx_retry_parsed,
6723 	.help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6724 	.tokens = {
6725 		(void *)&cmd_set_burst_tx_retry_set,
6726 		(void *)&cmd_set_burst_tx_retry_burst,
6727 		(void *)&cmd_set_burst_tx_retry_tx,
6728 		(void *)&cmd_set_burst_tx_retry_delay,
6729 		(void *)&cmd_set_burst_tx_retry_time,
6730 		(void *)&cmd_set_burst_tx_retry_retry,
6731 		(void *)&cmd_set_burst_tx_retry_retry_num,
6732 		NULL,
6733 	},
6734 };
6735 
6736 /* *** SET PROMISC MODE *** */
6737 struct cmd_set_promisc_mode_result {
6738 	cmdline_fixed_string_t set;
6739 	cmdline_fixed_string_t promisc;
6740 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6741 	uint16_t port_num;               /* valid if "allports" argument == 0 */
6742 	cmdline_fixed_string_t mode;
6743 };
6744 
6745 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6746 					__rte_unused struct cmdline *cl,
6747 					void *allports)
6748 {
6749 	struct cmd_set_promisc_mode_result *res = parsed_result;
6750 	int enable;
6751 	portid_t i;
6752 
6753 	if (!strcmp(res->mode, "on"))
6754 		enable = 1;
6755 	else
6756 		enable = 0;
6757 
6758 	/* all ports */
6759 	if (allports) {
6760 		RTE_ETH_FOREACH_DEV(i)
6761 			eth_set_promisc_mode(i, enable);
6762 	} else {
6763 		eth_set_promisc_mode(res->port_num, enable);
6764 	}
6765 }
6766 
6767 cmdline_parse_token_string_t cmd_setpromisc_set =
6768 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6769 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6770 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6771 				 "promisc");
6772 cmdline_parse_token_string_t cmd_setpromisc_portall =
6773 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6774 				 "all");
6775 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6776 	TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6777 			      UINT16);
6778 cmdline_parse_token_string_t cmd_setpromisc_mode =
6779 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6780 				 "on#off");
6781 
6782 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6783 	.f = cmd_set_promisc_mode_parsed,
6784 	.data = (void *)1,
6785 	.help_str = "set promisc all on|off: Set promisc mode for all ports",
6786 	.tokens = {
6787 		(void *)&cmd_setpromisc_set,
6788 		(void *)&cmd_setpromisc_promisc,
6789 		(void *)&cmd_setpromisc_portall,
6790 		(void *)&cmd_setpromisc_mode,
6791 		NULL,
6792 	},
6793 };
6794 
6795 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6796 	.f = cmd_set_promisc_mode_parsed,
6797 	.data = (void *)0,
6798 	.help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6799 	.tokens = {
6800 		(void *)&cmd_setpromisc_set,
6801 		(void *)&cmd_setpromisc_promisc,
6802 		(void *)&cmd_setpromisc_portnum,
6803 		(void *)&cmd_setpromisc_mode,
6804 		NULL,
6805 	},
6806 };
6807 
6808 /* *** SET ALLMULTI MODE *** */
6809 struct cmd_set_allmulti_mode_result {
6810 	cmdline_fixed_string_t set;
6811 	cmdline_fixed_string_t allmulti;
6812 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6813 	uint16_t port_num;               /* valid if "allports" argument == 0 */
6814 	cmdline_fixed_string_t mode;
6815 };
6816 
6817 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6818 					__rte_unused struct cmdline *cl,
6819 					void *allports)
6820 {
6821 	struct cmd_set_allmulti_mode_result *res = parsed_result;
6822 	int enable;
6823 	portid_t i;
6824 
6825 	if (!strcmp(res->mode, "on"))
6826 		enable = 1;
6827 	else
6828 		enable = 0;
6829 
6830 	/* all ports */
6831 	if (allports) {
6832 		RTE_ETH_FOREACH_DEV(i) {
6833 			eth_set_allmulticast_mode(i, enable);
6834 		}
6835 	}
6836 	else {
6837 		eth_set_allmulticast_mode(res->port_num, enable);
6838 	}
6839 }
6840 
6841 cmdline_parse_token_string_t cmd_setallmulti_set =
6842 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6843 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6844 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6845 				 "allmulti");
6846 cmdline_parse_token_string_t cmd_setallmulti_portall =
6847 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6848 				 "all");
6849 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6850 	TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6851 			      UINT16);
6852 cmdline_parse_token_string_t cmd_setallmulti_mode =
6853 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6854 				 "on#off");
6855 
6856 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6857 	.f = cmd_set_allmulti_mode_parsed,
6858 	.data = (void *)1,
6859 	.help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6860 	.tokens = {
6861 		(void *)&cmd_setallmulti_set,
6862 		(void *)&cmd_setallmulti_allmulti,
6863 		(void *)&cmd_setallmulti_portall,
6864 		(void *)&cmd_setallmulti_mode,
6865 		NULL,
6866 	},
6867 };
6868 
6869 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6870 	.f = cmd_set_allmulti_mode_parsed,
6871 	.data = (void *)0,
6872 	.help_str = "set allmulti <port_id> on|off: "
6873 		"Set allmulti mode on port_id",
6874 	.tokens = {
6875 		(void *)&cmd_setallmulti_set,
6876 		(void *)&cmd_setallmulti_allmulti,
6877 		(void *)&cmd_setallmulti_portnum,
6878 		(void *)&cmd_setallmulti_mode,
6879 		NULL,
6880 	},
6881 };
6882 
6883 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6884 struct cmd_link_flow_ctrl_set_result {
6885 	cmdline_fixed_string_t set;
6886 	cmdline_fixed_string_t flow_ctrl;
6887 	cmdline_fixed_string_t rx;
6888 	cmdline_fixed_string_t rx_lfc_mode;
6889 	cmdline_fixed_string_t tx;
6890 	cmdline_fixed_string_t tx_lfc_mode;
6891 	cmdline_fixed_string_t mac_ctrl_frame_fwd;
6892 	cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6893 	cmdline_fixed_string_t autoneg_str;
6894 	cmdline_fixed_string_t autoneg;
6895 	cmdline_fixed_string_t hw_str;
6896 	uint32_t high_water;
6897 	cmdline_fixed_string_t lw_str;
6898 	uint32_t low_water;
6899 	cmdline_fixed_string_t pt_str;
6900 	uint16_t pause_time;
6901 	cmdline_fixed_string_t xon_str;
6902 	uint16_t send_xon;
6903 	portid_t port_id;
6904 };
6905 
6906 cmdline_parse_token_string_t cmd_lfc_set_set =
6907 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6908 				set, "set");
6909 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6910 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6911 				flow_ctrl, "flow_ctrl");
6912 cmdline_parse_token_string_t cmd_lfc_set_rx =
6913 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6914 				rx, "rx");
6915 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6916 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6917 				rx_lfc_mode, "on#off");
6918 cmdline_parse_token_string_t cmd_lfc_set_tx =
6919 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6920 				tx, "tx");
6921 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6922 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6923 				tx_lfc_mode, "on#off");
6924 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6925 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6926 				hw_str, "high_water");
6927 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6928 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6929 				high_water, UINT32);
6930 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6931 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6932 				lw_str, "low_water");
6933 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6934 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6935 				low_water, UINT32);
6936 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6937 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6938 				pt_str, "pause_time");
6939 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6940 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6941 				pause_time, UINT16);
6942 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6943 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6944 				xon_str, "send_xon");
6945 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6946 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6947 				send_xon, UINT16);
6948 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6949 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6950 				mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6951 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6952 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6953 				mac_ctrl_frame_fwd_mode, "on#off");
6954 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6955 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6956 				autoneg_str, "autoneg");
6957 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6958 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6959 				autoneg, "on#off");
6960 cmdline_parse_token_num_t cmd_lfc_set_portid =
6961 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6962 				port_id, UINT16);
6963 
6964 /* forward declaration */
6965 static void
6966 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6967 			      void *data);
6968 
6969 cmdline_parse_inst_t cmd_link_flow_control_set = {
6970 	.f = cmd_link_flow_ctrl_set_parsed,
6971 	.data = NULL,
6972 	.help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6973 		"<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6974 		"autoneg on|off <port_id>: Configure the Ethernet flow control",
6975 	.tokens = {
6976 		(void *)&cmd_lfc_set_set,
6977 		(void *)&cmd_lfc_set_flow_ctrl,
6978 		(void *)&cmd_lfc_set_rx,
6979 		(void *)&cmd_lfc_set_rx_mode,
6980 		(void *)&cmd_lfc_set_tx,
6981 		(void *)&cmd_lfc_set_tx_mode,
6982 		(void *)&cmd_lfc_set_high_water,
6983 		(void *)&cmd_lfc_set_low_water,
6984 		(void *)&cmd_lfc_set_pause_time,
6985 		(void *)&cmd_lfc_set_send_xon,
6986 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6987 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6988 		(void *)&cmd_lfc_set_autoneg_str,
6989 		(void *)&cmd_lfc_set_autoneg,
6990 		(void *)&cmd_lfc_set_portid,
6991 		NULL,
6992 	},
6993 };
6994 
6995 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6996 	.f = cmd_link_flow_ctrl_set_parsed,
6997 	.data = (void *)&cmd_link_flow_control_set_rx,
6998 	.help_str = "set flow_ctrl rx on|off <port_id>: "
6999 		"Change rx flow control parameter",
7000 	.tokens = {
7001 		(void *)&cmd_lfc_set_set,
7002 		(void *)&cmd_lfc_set_flow_ctrl,
7003 		(void *)&cmd_lfc_set_rx,
7004 		(void *)&cmd_lfc_set_rx_mode,
7005 		(void *)&cmd_lfc_set_portid,
7006 		NULL,
7007 	},
7008 };
7009 
7010 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7011 	.f = cmd_link_flow_ctrl_set_parsed,
7012 	.data = (void *)&cmd_link_flow_control_set_tx,
7013 	.help_str = "set flow_ctrl tx on|off <port_id>: "
7014 		"Change tx flow control parameter",
7015 	.tokens = {
7016 		(void *)&cmd_lfc_set_set,
7017 		(void *)&cmd_lfc_set_flow_ctrl,
7018 		(void *)&cmd_lfc_set_tx,
7019 		(void *)&cmd_lfc_set_tx_mode,
7020 		(void *)&cmd_lfc_set_portid,
7021 		NULL,
7022 	},
7023 };
7024 
7025 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7026 	.f = cmd_link_flow_ctrl_set_parsed,
7027 	.data = (void *)&cmd_link_flow_control_set_hw,
7028 	.help_str = "set flow_ctrl high_water <value> <port_id>: "
7029 		"Change high water flow control parameter",
7030 	.tokens = {
7031 		(void *)&cmd_lfc_set_set,
7032 		(void *)&cmd_lfc_set_flow_ctrl,
7033 		(void *)&cmd_lfc_set_high_water_str,
7034 		(void *)&cmd_lfc_set_high_water,
7035 		(void *)&cmd_lfc_set_portid,
7036 		NULL,
7037 	},
7038 };
7039 
7040 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7041 	.f = cmd_link_flow_ctrl_set_parsed,
7042 	.data = (void *)&cmd_link_flow_control_set_lw,
7043 	.help_str = "set flow_ctrl low_water <value> <port_id>: "
7044 		"Change low water flow control parameter",
7045 	.tokens = {
7046 		(void *)&cmd_lfc_set_set,
7047 		(void *)&cmd_lfc_set_flow_ctrl,
7048 		(void *)&cmd_lfc_set_low_water_str,
7049 		(void *)&cmd_lfc_set_low_water,
7050 		(void *)&cmd_lfc_set_portid,
7051 		NULL,
7052 	},
7053 };
7054 
7055 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7056 	.f = cmd_link_flow_ctrl_set_parsed,
7057 	.data = (void *)&cmd_link_flow_control_set_pt,
7058 	.help_str = "set flow_ctrl pause_time <value> <port_id>: "
7059 		"Change pause time flow control parameter",
7060 	.tokens = {
7061 		(void *)&cmd_lfc_set_set,
7062 		(void *)&cmd_lfc_set_flow_ctrl,
7063 		(void *)&cmd_lfc_set_pause_time_str,
7064 		(void *)&cmd_lfc_set_pause_time,
7065 		(void *)&cmd_lfc_set_portid,
7066 		NULL,
7067 	},
7068 };
7069 
7070 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7071 	.f = cmd_link_flow_ctrl_set_parsed,
7072 	.data = (void *)&cmd_link_flow_control_set_xon,
7073 	.help_str = "set flow_ctrl send_xon <value> <port_id>: "
7074 		"Change send_xon flow control parameter",
7075 	.tokens = {
7076 		(void *)&cmd_lfc_set_set,
7077 		(void *)&cmd_lfc_set_flow_ctrl,
7078 		(void *)&cmd_lfc_set_send_xon_str,
7079 		(void *)&cmd_lfc_set_send_xon,
7080 		(void *)&cmd_lfc_set_portid,
7081 		NULL,
7082 	},
7083 };
7084 
7085 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7086 	.f = cmd_link_flow_ctrl_set_parsed,
7087 	.data = (void *)&cmd_link_flow_control_set_macfwd,
7088 	.help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7089 		"Change mac ctrl fwd flow control parameter",
7090 	.tokens = {
7091 		(void *)&cmd_lfc_set_set,
7092 		(void *)&cmd_lfc_set_flow_ctrl,
7093 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7094 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7095 		(void *)&cmd_lfc_set_portid,
7096 		NULL,
7097 	},
7098 };
7099 
7100 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7101 	.f = cmd_link_flow_ctrl_set_parsed,
7102 	.data = (void *)&cmd_link_flow_control_set_autoneg,
7103 	.help_str = "set flow_ctrl autoneg on|off <port_id>: "
7104 		"Change autoneg flow control parameter",
7105 	.tokens = {
7106 		(void *)&cmd_lfc_set_set,
7107 		(void *)&cmd_lfc_set_flow_ctrl,
7108 		(void *)&cmd_lfc_set_autoneg_str,
7109 		(void *)&cmd_lfc_set_autoneg,
7110 		(void *)&cmd_lfc_set_portid,
7111 		NULL,
7112 	},
7113 };
7114 
7115 static void
7116 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7117 			      __rte_unused struct cmdline *cl,
7118 			      void *data)
7119 {
7120 	struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7121 	cmdline_parse_inst_t *cmd = data;
7122 	struct rte_eth_fc_conf fc_conf;
7123 	int rx_fc_en = 0;
7124 	int tx_fc_en = 0;
7125 	int ret;
7126 
7127 	/*
7128 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7129 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7130 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7131 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7132 	 */
7133 	static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7134 			{RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7135 	};
7136 
7137 	/* Partial command line, retrieve current configuration */
7138 	if (cmd) {
7139 		ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7140 		if (ret != 0) {
7141 			printf("cannot get current flow ctrl parameters, return"
7142 			       "code = %d\n", ret);
7143 			return;
7144 		}
7145 
7146 		if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7147 		    (fc_conf.mode == RTE_FC_FULL))
7148 			rx_fc_en = 1;
7149 		if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7150 		    (fc_conf.mode == RTE_FC_FULL))
7151 			tx_fc_en = 1;
7152 	}
7153 
7154 	if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7155 		rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7156 
7157 	if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7158 		tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7159 
7160 	fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7161 
7162 	if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7163 		fc_conf.high_water = res->high_water;
7164 
7165 	if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7166 		fc_conf.low_water = res->low_water;
7167 
7168 	if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7169 		fc_conf.pause_time = res->pause_time;
7170 
7171 	if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7172 		fc_conf.send_xon = res->send_xon;
7173 
7174 	if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7175 		if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7176 			fc_conf.mac_ctrl_frame_fwd = 1;
7177 		else
7178 			fc_conf.mac_ctrl_frame_fwd = 0;
7179 	}
7180 
7181 	if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7182 		fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7183 
7184 	ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7185 	if (ret != 0)
7186 		printf("bad flow contrl parameter, return code = %d \n", ret);
7187 }
7188 
7189 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7190 struct cmd_priority_flow_ctrl_set_result {
7191 	cmdline_fixed_string_t set;
7192 	cmdline_fixed_string_t pfc_ctrl;
7193 	cmdline_fixed_string_t rx;
7194 	cmdline_fixed_string_t rx_pfc_mode;
7195 	cmdline_fixed_string_t tx;
7196 	cmdline_fixed_string_t tx_pfc_mode;
7197 	uint32_t high_water;
7198 	uint32_t low_water;
7199 	uint16_t pause_time;
7200 	uint8_t  priority;
7201 	portid_t port_id;
7202 };
7203 
7204 static void
7205 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7206 		       __rte_unused struct cmdline *cl,
7207 		       __rte_unused void *data)
7208 {
7209 	struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7210 	struct rte_eth_pfc_conf pfc_conf;
7211 	int rx_fc_enable, tx_fc_enable;
7212 	int ret;
7213 
7214 	/*
7215 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7216 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7217 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7218 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7219 	 */
7220 	static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7221 		{RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7222 	};
7223 
7224 	memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7225 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7226 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7227 	pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7228 	pfc_conf.fc.high_water = res->high_water;
7229 	pfc_conf.fc.low_water  = res->low_water;
7230 	pfc_conf.fc.pause_time = res->pause_time;
7231 	pfc_conf.priority      = res->priority;
7232 
7233 	ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7234 	if (ret != 0)
7235 		printf("bad priority flow contrl parameter, return code = %d \n", ret);
7236 }
7237 
7238 cmdline_parse_token_string_t cmd_pfc_set_set =
7239 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7240 				set, "set");
7241 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7242 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7243 				pfc_ctrl, "pfc_ctrl");
7244 cmdline_parse_token_string_t cmd_pfc_set_rx =
7245 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7246 				rx, "rx");
7247 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7248 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7249 				rx_pfc_mode, "on#off");
7250 cmdline_parse_token_string_t cmd_pfc_set_tx =
7251 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7252 				tx, "tx");
7253 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7254 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7255 				tx_pfc_mode, "on#off");
7256 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7257 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7258 				high_water, UINT32);
7259 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7260 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7261 				low_water, UINT32);
7262 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7263 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7264 				pause_time, UINT16);
7265 cmdline_parse_token_num_t cmd_pfc_set_priority =
7266 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7267 				priority, UINT8);
7268 cmdline_parse_token_num_t cmd_pfc_set_portid =
7269 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7270 				port_id, UINT16);
7271 
7272 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7273 	.f = cmd_priority_flow_ctrl_set_parsed,
7274 	.data = NULL,
7275 	.help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7276 		"<pause_time> <priority> <port_id>: "
7277 		"Configure the Ethernet priority flow control",
7278 	.tokens = {
7279 		(void *)&cmd_pfc_set_set,
7280 		(void *)&cmd_pfc_set_flow_ctrl,
7281 		(void *)&cmd_pfc_set_rx,
7282 		(void *)&cmd_pfc_set_rx_mode,
7283 		(void *)&cmd_pfc_set_tx,
7284 		(void *)&cmd_pfc_set_tx_mode,
7285 		(void *)&cmd_pfc_set_high_water,
7286 		(void *)&cmd_pfc_set_low_water,
7287 		(void *)&cmd_pfc_set_pause_time,
7288 		(void *)&cmd_pfc_set_priority,
7289 		(void *)&cmd_pfc_set_portid,
7290 		NULL,
7291 	},
7292 };
7293 
7294 /* *** RESET CONFIGURATION *** */
7295 struct cmd_reset_result {
7296 	cmdline_fixed_string_t reset;
7297 	cmdline_fixed_string_t def;
7298 };
7299 
7300 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7301 			     struct cmdline *cl,
7302 			     __rte_unused void *data)
7303 {
7304 	cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7305 	set_def_fwd_config();
7306 }
7307 
7308 cmdline_parse_token_string_t cmd_reset_set =
7309 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7310 cmdline_parse_token_string_t cmd_reset_def =
7311 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7312 				 "default");
7313 
7314 cmdline_parse_inst_t cmd_reset = {
7315 	.f = cmd_reset_parsed,
7316 	.data = NULL,
7317 	.help_str = "set default: Reset default forwarding configuration",
7318 	.tokens = {
7319 		(void *)&cmd_reset_set,
7320 		(void *)&cmd_reset_def,
7321 		NULL,
7322 	},
7323 };
7324 
7325 /* *** START FORWARDING *** */
7326 struct cmd_start_result {
7327 	cmdline_fixed_string_t start;
7328 };
7329 
7330 cmdline_parse_token_string_t cmd_start_start =
7331 	TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7332 
7333 static void cmd_start_parsed(__rte_unused void *parsed_result,
7334 			     __rte_unused struct cmdline *cl,
7335 			     __rte_unused void *data)
7336 {
7337 	start_packet_forwarding(0);
7338 }
7339 
7340 cmdline_parse_inst_t cmd_start = {
7341 	.f = cmd_start_parsed,
7342 	.data = NULL,
7343 	.help_str = "start: Start packet forwarding",
7344 	.tokens = {
7345 		(void *)&cmd_start_start,
7346 		NULL,
7347 	},
7348 };
7349 
7350 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7351 struct cmd_start_tx_first_result {
7352 	cmdline_fixed_string_t start;
7353 	cmdline_fixed_string_t tx_first;
7354 };
7355 
7356 static void
7357 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7358 			  __rte_unused struct cmdline *cl,
7359 			  __rte_unused void *data)
7360 {
7361 	start_packet_forwarding(1);
7362 }
7363 
7364 cmdline_parse_token_string_t cmd_start_tx_first_start =
7365 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7366 				 "start");
7367 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7368 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7369 				 tx_first, "tx_first");
7370 
7371 cmdline_parse_inst_t cmd_start_tx_first = {
7372 	.f = cmd_start_tx_first_parsed,
7373 	.data = NULL,
7374 	.help_str = "start tx_first: Start packet forwarding, "
7375 		"after sending 1 burst of packets",
7376 	.tokens = {
7377 		(void *)&cmd_start_tx_first_start,
7378 		(void *)&cmd_start_tx_first_tx_first,
7379 		NULL,
7380 	},
7381 };
7382 
7383 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7384 struct cmd_start_tx_first_n_result {
7385 	cmdline_fixed_string_t start;
7386 	cmdline_fixed_string_t tx_first;
7387 	uint32_t tx_num;
7388 };
7389 
7390 static void
7391 cmd_start_tx_first_n_parsed(void *parsed_result,
7392 			  __rte_unused struct cmdline *cl,
7393 			  __rte_unused void *data)
7394 {
7395 	struct cmd_start_tx_first_n_result *res = parsed_result;
7396 
7397 	start_packet_forwarding(res->tx_num);
7398 }
7399 
7400 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7401 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7402 			start, "start");
7403 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7404 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7405 			tx_first, "tx_first");
7406 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7407 	TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7408 			tx_num, UINT32);
7409 
7410 cmdline_parse_inst_t cmd_start_tx_first_n = {
7411 	.f = cmd_start_tx_first_n_parsed,
7412 	.data = NULL,
7413 	.help_str = "start tx_first <num>: "
7414 		"packet forwarding, after sending <num> bursts of packets",
7415 	.tokens = {
7416 		(void *)&cmd_start_tx_first_n_start,
7417 		(void *)&cmd_start_tx_first_n_tx_first,
7418 		(void *)&cmd_start_tx_first_n_tx_num,
7419 		NULL,
7420 	},
7421 };
7422 
7423 /* *** SET LINK UP *** */
7424 struct cmd_set_link_up_result {
7425 	cmdline_fixed_string_t set;
7426 	cmdline_fixed_string_t link_up;
7427 	cmdline_fixed_string_t port;
7428 	portid_t port_id;
7429 };
7430 
7431 cmdline_parse_token_string_t cmd_set_link_up_set =
7432 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7433 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7434 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7435 				"link-up");
7436 cmdline_parse_token_string_t cmd_set_link_up_port =
7437 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7438 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7439 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7440 
7441 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7442 			     __rte_unused struct cmdline *cl,
7443 			     __rte_unused void *data)
7444 {
7445 	struct cmd_set_link_up_result *res = parsed_result;
7446 	dev_set_link_up(res->port_id);
7447 }
7448 
7449 cmdline_parse_inst_t cmd_set_link_up = {
7450 	.f = cmd_set_link_up_parsed,
7451 	.data = NULL,
7452 	.help_str = "set link-up port <port id>",
7453 	.tokens = {
7454 		(void *)&cmd_set_link_up_set,
7455 		(void *)&cmd_set_link_up_link_up,
7456 		(void *)&cmd_set_link_up_port,
7457 		(void *)&cmd_set_link_up_port_id,
7458 		NULL,
7459 	},
7460 };
7461 
7462 /* *** SET LINK DOWN *** */
7463 struct cmd_set_link_down_result {
7464 	cmdline_fixed_string_t set;
7465 	cmdline_fixed_string_t link_down;
7466 	cmdline_fixed_string_t port;
7467 	portid_t port_id;
7468 };
7469 
7470 cmdline_parse_token_string_t cmd_set_link_down_set =
7471 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7472 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7473 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7474 				"link-down");
7475 cmdline_parse_token_string_t cmd_set_link_down_port =
7476 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7477 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7478 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7479 
7480 static void cmd_set_link_down_parsed(
7481 				__rte_unused void *parsed_result,
7482 				__rte_unused struct cmdline *cl,
7483 				__rte_unused void *data)
7484 {
7485 	struct cmd_set_link_down_result *res = parsed_result;
7486 	dev_set_link_down(res->port_id);
7487 }
7488 
7489 cmdline_parse_inst_t cmd_set_link_down = {
7490 	.f = cmd_set_link_down_parsed,
7491 	.data = NULL,
7492 	.help_str = "set link-down port <port id>",
7493 	.tokens = {
7494 		(void *)&cmd_set_link_down_set,
7495 		(void *)&cmd_set_link_down_link_down,
7496 		(void *)&cmd_set_link_down_port,
7497 		(void *)&cmd_set_link_down_port_id,
7498 		NULL,
7499 	},
7500 };
7501 
7502 /* *** SHOW CFG *** */
7503 struct cmd_showcfg_result {
7504 	cmdline_fixed_string_t show;
7505 	cmdline_fixed_string_t cfg;
7506 	cmdline_fixed_string_t what;
7507 };
7508 
7509 static void cmd_showcfg_parsed(void *parsed_result,
7510 			       __rte_unused struct cmdline *cl,
7511 			       __rte_unused void *data)
7512 {
7513 	struct cmd_showcfg_result *res = parsed_result;
7514 	if (!strcmp(res->what, "rxtx"))
7515 		rxtx_config_display();
7516 	else if (!strcmp(res->what, "cores"))
7517 		fwd_lcores_config_display();
7518 	else if (!strcmp(res->what, "fwd"))
7519 		pkt_fwd_config_display(&cur_fwd_config);
7520 	else if (!strcmp(res->what, "txpkts"))
7521 		show_tx_pkt_segments();
7522 	else if (!strcmp(res->what, "txtimes"))
7523 		show_tx_pkt_times();
7524 }
7525 
7526 cmdline_parse_token_string_t cmd_showcfg_show =
7527 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7528 cmdline_parse_token_string_t cmd_showcfg_port =
7529 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7530 cmdline_parse_token_string_t cmd_showcfg_what =
7531 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7532 				 "rxtx#cores#fwd#txpkts#txtimes");
7533 
7534 cmdline_parse_inst_t cmd_showcfg = {
7535 	.f = cmd_showcfg_parsed,
7536 	.data = NULL,
7537 	.help_str = "show config rxtx|cores|fwd|txpkts|txtimes",
7538 	.tokens = {
7539 		(void *)&cmd_showcfg_show,
7540 		(void *)&cmd_showcfg_port,
7541 		(void *)&cmd_showcfg_what,
7542 		NULL,
7543 	},
7544 };
7545 
7546 /* *** SHOW ALL PORT INFO *** */
7547 struct cmd_showportall_result {
7548 	cmdline_fixed_string_t show;
7549 	cmdline_fixed_string_t port;
7550 	cmdline_fixed_string_t what;
7551 	cmdline_fixed_string_t all;
7552 };
7553 
7554 static void cmd_showportall_parsed(void *parsed_result,
7555 				__rte_unused struct cmdline *cl,
7556 				__rte_unused void *data)
7557 {
7558 	portid_t i;
7559 
7560 	struct cmd_showportall_result *res = parsed_result;
7561 	if (!strcmp(res->show, "clear")) {
7562 		if (!strcmp(res->what, "stats"))
7563 			RTE_ETH_FOREACH_DEV(i)
7564 				nic_stats_clear(i);
7565 		else if (!strcmp(res->what, "xstats"))
7566 			RTE_ETH_FOREACH_DEV(i)
7567 				nic_xstats_clear(i);
7568 	} else if (!strcmp(res->what, "info"))
7569 		RTE_ETH_FOREACH_DEV(i)
7570 			port_infos_display(i);
7571 	else if (!strcmp(res->what, "summary")) {
7572 		port_summary_header_display();
7573 		RTE_ETH_FOREACH_DEV(i)
7574 			port_summary_display(i);
7575 	}
7576 	else if (!strcmp(res->what, "stats"))
7577 		RTE_ETH_FOREACH_DEV(i)
7578 			nic_stats_display(i);
7579 	else if (!strcmp(res->what, "xstats"))
7580 		RTE_ETH_FOREACH_DEV(i)
7581 			nic_xstats_display(i);
7582 	else if (!strcmp(res->what, "fdir"))
7583 		RTE_ETH_FOREACH_DEV(i)
7584 			fdir_get_infos(i);
7585 	else if (!strcmp(res->what, "stat_qmap"))
7586 		RTE_ETH_FOREACH_DEV(i)
7587 			nic_stats_mapping_display(i);
7588 	else if (!strcmp(res->what, "dcb_tc"))
7589 		RTE_ETH_FOREACH_DEV(i)
7590 			port_dcb_info_display(i);
7591 	else if (!strcmp(res->what, "cap"))
7592 		RTE_ETH_FOREACH_DEV(i)
7593 			port_offload_cap_display(i);
7594 }
7595 
7596 cmdline_parse_token_string_t cmd_showportall_show =
7597 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7598 				 "show#clear");
7599 cmdline_parse_token_string_t cmd_showportall_port =
7600 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7601 cmdline_parse_token_string_t cmd_showportall_what =
7602 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7603 				 "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7604 cmdline_parse_token_string_t cmd_showportall_all =
7605 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7606 cmdline_parse_inst_t cmd_showportall = {
7607 	.f = cmd_showportall_parsed,
7608 	.data = NULL,
7609 	.help_str = "show|clear port "
7610 		"info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7611 	.tokens = {
7612 		(void *)&cmd_showportall_show,
7613 		(void *)&cmd_showportall_port,
7614 		(void *)&cmd_showportall_what,
7615 		(void *)&cmd_showportall_all,
7616 		NULL,
7617 	},
7618 };
7619 
7620 /* *** SHOW PORT INFO *** */
7621 struct cmd_showport_result {
7622 	cmdline_fixed_string_t show;
7623 	cmdline_fixed_string_t port;
7624 	cmdline_fixed_string_t what;
7625 	uint16_t portnum;
7626 };
7627 
7628 static void cmd_showport_parsed(void *parsed_result,
7629 				__rte_unused struct cmdline *cl,
7630 				__rte_unused void *data)
7631 {
7632 	struct cmd_showport_result *res = parsed_result;
7633 	if (!strcmp(res->show, "clear")) {
7634 		if (!strcmp(res->what, "stats"))
7635 			nic_stats_clear(res->portnum);
7636 		else if (!strcmp(res->what, "xstats"))
7637 			nic_xstats_clear(res->portnum);
7638 	} else if (!strcmp(res->what, "info"))
7639 		port_infos_display(res->portnum);
7640 	else if (!strcmp(res->what, "summary")) {
7641 		port_summary_header_display();
7642 		port_summary_display(res->portnum);
7643 	}
7644 	else if (!strcmp(res->what, "stats"))
7645 		nic_stats_display(res->portnum);
7646 	else if (!strcmp(res->what, "xstats"))
7647 		nic_xstats_display(res->portnum);
7648 	else if (!strcmp(res->what, "fdir"))
7649 		 fdir_get_infos(res->portnum);
7650 	else if (!strcmp(res->what, "stat_qmap"))
7651 		nic_stats_mapping_display(res->portnum);
7652 	else if (!strcmp(res->what, "dcb_tc"))
7653 		port_dcb_info_display(res->portnum);
7654 	else if (!strcmp(res->what, "cap"))
7655 		port_offload_cap_display(res->portnum);
7656 }
7657 
7658 cmdline_parse_token_string_t cmd_showport_show =
7659 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7660 				 "show#clear");
7661 cmdline_parse_token_string_t cmd_showport_port =
7662 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7663 cmdline_parse_token_string_t cmd_showport_what =
7664 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7665 				 "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7666 cmdline_parse_token_num_t cmd_showport_portnum =
7667 	TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7668 
7669 cmdline_parse_inst_t cmd_showport = {
7670 	.f = cmd_showport_parsed,
7671 	.data = NULL,
7672 	.help_str = "show|clear port "
7673 		"info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7674 		"<port_id>",
7675 	.tokens = {
7676 		(void *)&cmd_showport_show,
7677 		(void *)&cmd_showport_port,
7678 		(void *)&cmd_showport_what,
7679 		(void *)&cmd_showport_portnum,
7680 		NULL,
7681 	},
7682 };
7683 
7684 /* *** SHOW DEVICE INFO *** */
7685 struct cmd_showdevice_result {
7686 	cmdline_fixed_string_t show;
7687 	cmdline_fixed_string_t device;
7688 	cmdline_fixed_string_t what;
7689 	cmdline_fixed_string_t identifier;
7690 };
7691 
7692 static void cmd_showdevice_parsed(void *parsed_result,
7693 				__rte_unused struct cmdline *cl,
7694 				__rte_unused void *data)
7695 {
7696 	struct cmd_showdevice_result *res = parsed_result;
7697 	if (!strcmp(res->what, "info")) {
7698 		if (!strcmp(res->identifier, "all"))
7699 			device_infos_display(NULL);
7700 		else
7701 			device_infos_display(res->identifier);
7702 	}
7703 }
7704 
7705 cmdline_parse_token_string_t cmd_showdevice_show =
7706 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7707 				 "show");
7708 cmdline_parse_token_string_t cmd_showdevice_device =
7709 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7710 cmdline_parse_token_string_t cmd_showdevice_what =
7711 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7712 				 "info");
7713 cmdline_parse_token_string_t cmd_showdevice_identifier =
7714 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7715 			identifier, NULL);
7716 
7717 cmdline_parse_inst_t cmd_showdevice = {
7718 	.f = cmd_showdevice_parsed,
7719 	.data = NULL,
7720 	.help_str = "show device info <identifier>|all",
7721 	.tokens = {
7722 		(void *)&cmd_showdevice_show,
7723 		(void *)&cmd_showdevice_device,
7724 		(void *)&cmd_showdevice_what,
7725 		(void *)&cmd_showdevice_identifier,
7726 		NULL,
7727 	},
7728 };
7729 
7730 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7731 struct cmd_showeeprom_result {
7732 	cmdline_fixed_string_t show;
7733 	cmdline_fixed_string_t port;
7734 	uint16_t portnum;
7735 	cmdline_fixed_string_t type;
7736 };
7737 
7738 static void cmd_showeeprom_parsed(void *parsed_result,
7739 		__rte_unused struct cmdline *cl,
7740 		__rte_unused void *data)
7741 {
7742 	struct cmd_showeeprom_result *res = parsed_result;
7743 
7744 	if (!strcmp(res->type, "eeprom"))
7745 		port_eeprom_display(res->portnum);
7746 	else if (!strcmp(res->type, "module_eeprom"))
7747 		port_module_eeprom_display(res->portnum);
7748 	else
7749 		printf("Unknown argument\n");
7750 }
7751 
7752 cmdline_parse_token_string_t cmd_showeeprom_show =
7753 	TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7754 cmdline_parse_token_string_t cmd_showeeprom_port =
7755 	TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7756 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7757 	TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, UINT16);
7758 cmdline_parse_token_string_t cmd_showeeprom_type =
7759 	TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7760 
7761 cmdline_parse_inst_t cmd_showeeprom = {
7762 	.f = cmd_showeeprom_parsed,
7763 	.data = NULL,
7764 	.help_str = "show port <port_id> module_eeprom|eeprom",
7765 	.tokens = {
7766 		(void *)&cmd_showeeprom_show,
7767 		(void *)&cmd_showeeprom_port,
7768 		(void *)&cmd_showeeprom_portnum,
7769 		(void *)&cmd_showeeprom_type,
7770 		NULL,
7771 	},
7772 };
7773 
7774 /* *** SHOW QUEUE INFO *** */
7775 struct cmd_showqueue_result {
7776 	cmdline_fixed_string_t show;
7777 	cmdline_fixed_string_t type;
7778 	cmdline_fixed_string_t what;
7779 	uint16_t portnum;
7780 	uint16_t queuenum;
7781 };
7782 
7783 static void
7784 cmd_showqueue_parsed(void *parsed_result,
7785 	__rte_unused struct cmdline *cl,
7786 	__rte_unused void *data)
7787 {
7788 	struct cmd_showqueue_result *res = parsed_result;
7789 
7790 	if (!strcmp(res->type, "rxq"))
7791 		rx_queue_infos_display(res->portnum, res->queuenum);
7792 	else if (!strcmp(res->type, "txq"))
7793 		tx_queue_infos_display(res->portnum, res->queuenum);
7794 }
7795 
7796 cmdline_parse_token_string_t cmd_showqueue_show =
7797 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7798 cmdline_parse_token_string_t cmd_showqueue_type =
7799 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7800 cmdline_parse_token_string_t cmd_showqueue_what =
7801 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7802 cmdline_parse_token_num_t cmd_showqueue_portnum =
7803 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7804 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7805 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7806 
7807 cmdline_parse_inst_t cmd_showqueue = {
7808 	.f = cmd_showqueue_parsed,
7809 	.data = NULL,
7810 	.help_str = "show rxq|txq info <port_id> <queue_id>",
7811 	.tokens = {
7812 		(void *)&cmd_showqueue_show,
7813 		(void *)&cmd_showqueue_type,
7814 		(void *)&cmd_showqueue_what,
7815 		(void *)&cmd_showqueue_portnum,
7816 		(void *)&cmd_showqueue_queuenum,
7817 		NULL,
7818 	},
7819 };
7820 
7821 /* show/clear fwd engine statistics */
7822 struct fwd_result {
7823 	cmdline_fixed_string_t action;
7824 	cmdline_fixed_string_t fwd;
7825 	cmdline_fixed_string_t stats;
7826 	cmdline_fixed_string_t all;
7827 };
7828 
7829 cmdline_parse_token_string_t cmd_fwd_action =
7830 	TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7831 cmdline_parse_token_string_t cmd_fwd_fwd =
7832 	TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7833 cmdline_parse_token_string_t cmd_fwd_stats =
7834 	TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7835 cmdline_parse_token_string_t cmd_fwd_all =
7836 	TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7837 
7838 static void
7839 cmd_showfwdall_parsed(void *parsed_result,
7840 		      __rte_unused struct cmdline *cl,
7841 		      __rte_unused void *data)
7842 {
7843 	struct fwd_result *res = parsed_result;
7844 
7845 	if (!strcmp(res->action, "show"))
7846 		fwd_stats_display();
7847 	else
7848 		fwd_stats_reset();
7849 }
7850 
7851 static cmdline_parse_inst_t cmd_showfwdall = {
7852 	.f = cmd_showfwdall_parsed,
7853 	.data = NULL,
7854 	.help_str = "show|clear fwd stats all",
7855 	.tokens = {
7856 		(void *)&cmd_fwd_action,
7857 		(void *)&cmd_fwd_fwd,
7858 		(void *)&cmd_fwd_stats,
7859 		(void *)&cmd_fwd_all,
7860 		NULL,
7861 	},
7862 };
7863 
7864 /* *** READ PORT REGISTER *** */
7865 struct cmd_read_reg_result {
7866 	cmdline_fixed_string_t read;
7867 	cmdline_fixed_string_t reg;
7868 	portid_t port_id;
7869 	uint32_t reg_off;
7870 };
7871 
7872 static void
7873 cmd_read_reg_parsed(void *parsed_result,
7874 		    __rte_unused struct cmdline *cl,
7875 		    __rte_unused void *data)
7876 {
7877 	struct cmd_read_reg_result *res = parsed_result;
7878 	port_reg_display(res->port_id, res->reg_off);
7879 }
7880 
7881 cmdline_parse_token_string_t cmd_read_reg_read =
7882 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7883 cmdline_parse_token_string_t cmd_read_reg_reg =
7884 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7885 cmdline_parse_token_num_t cmd_read_reg_port_id =
7886 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7887 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7888 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7889 
7890 cmdline_parse_inst_t cmd_read_reg = {
7891 	.f = cmd_read_reg_parsed,
7892 	.data = NULL,
7893 	.help_str = "read reg <port_id> <reg_off>",
7894 	.tokens = {
7895 		(void *)&cmd_read_reg_read,
7896 		(void *)&cmd_read_reg_reg,
7897 		(void *)&cmd_read_reg_port_id,
7898 		(void *)&cmd_read_reg_reg_off,
7899 		NULL,
7900 	},
7901 };
7902 
7903 /* *** READ PORT REGISTER BIT FIELD *** */
7904 struct cmd_read_reg_bit_field_result {
7905 	cmdline_fixed_string_t read;
7906 	cmdline_fixed_string_t regfield;
7907 	portid_t port_id;
7908 	uint32_t reg_off;
7909 	uint8_t bit1_pos;
7910 	uint8_t bit2_pos;
7911 };
7912 
7913 static void
7914 cmd_read_reg_bit_field_parsed(void *parsed_result,
7915 			      __rte_unused struct cmdline *cl,
7916 			      __rte_unused void *data)
7917 {
7918 	struct cmd_read_reg_bit_field_result *res = parsed_result;
7919 	port_reg_bit_field_display(res->port_id, res->reg_off,
7920 				   res->bit1_pos, res->bit2_pos);
7921 }
7922 
7923 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7924 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7925 				 "read");
7926 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7927 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7928 				 regfield, "regfield");
7929 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7930 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7931 			      UINT16);
7932 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7933 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7934 			      UINT32);
7935 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7936 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7937 			      UINT8);
7938 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7939 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7940 			      UINT8);
7941 
7942 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7943 	.f = cmd_read_reg_bit_field_parsed,
7944 	.data = NULL,
7945 	.help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7946 	"Read register bit field between bit_x and bit_y included",
7947 	.tokens = {
7948 		(void *)&cmd_read_reg_bit_field_read,
7949 		(void *)&cmd_read_reg_bit_field_regfield,
7950 		(void *)&cmd_read_reg_bit_field_port_id,
7951 		(void *)&cmd_read_reg_bit_field_reg_off,
7952 		(void *)&cmd_read_reg_bit_field_bit1_pos,
7953 		(void *)&cmd_read_reg_bit_field_bit2_pos,
7954 		NULL,
7955 	},
7956 };
7957 
7958 /* *** READ PORT REGISTER BIT *** */
7959 struct cmd_read_reg_bit_result {
7960 	cmdline_fixed_string_t read;
7961 	cmdline_fixed_string_t regbit;
7962 	portid_t port_id;
7963 	uint32_t reg_off;
7964 	uint8_t bit_pos;
7965 };
7966 
7967 static void
7968 cmd_read_reg_bit_parsed(void *parsed_result,
7969 			__rte_unused struct cmdline *cl,
7970 			__rte_unused void *data)
7971 {
7972 	struct cmd_read_reg_bit_result *res = parsed_result;
7973 	port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7974 }
7975 
7976 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7977 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7978 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7979 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7980 				 regbit, "regbit");
7981 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7982 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7983 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7984 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7985 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7986 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7987 
7988 cmdline_parse_inst_t cmd_read_reg_bit = {
7989 	.f = cmd_read_reg_bit_parsed,
7990 	.data = NULL,
7991 	.help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7992 	.tokens = {
7993 		(void *)&cmd_read_reg_bit_read,
7994 		(void *)&cmd_read_reg_bit_regbit,
7995 		(void *)&cmd_read_reg_bit_port_id,
7996 		(void *)&cmd_read_reg_bit_reg_off,
7997 		(void *)&cmd_read_reg_bit_bit_pos,
7998 		NULL,
7999 	},
8000 };
8001 
8002 /* *** WRITE PORT REGISTER *** */
8003 struct cmd_write_reg_result {
8004 	cmdline_fixed_string_t write;
8005 	cmdline_fixed_string_t reg;
8006 	portid_t port_id;
8007 	uint32_t reg_off;
8008 	uint32_t value;
8009 };
8010 
8011 static void
8012 cmd_write_reg_parsed(void *parsed_result,
8013 		     __rte_unused struct cmdline *cl,
8014 		     __rte_unused void *data)
8015 {
8016 	struct cmd_write_reg_result *res = parsed_result;
8017 	port_reg_set(res->port_id, res->reg_off, res->value);
8018 }
8019 
8020 cmdline_parse_token_string_t cmd_write_reg_write =
8021 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8022 cmdline_parse_token_string_t cmd_write_reg_reg =
8023 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8024 cmdline_parse_token_num_t cmd_write_reg_port_id =
8025 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
8026 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8027 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
8028 cmdline_parse_token_num_t cmd_write_reg_value =
8029 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
8030 
8031 cmdline_parse_inst_t cmd_write_reg = {
8032 	.f = cmd_write_reg_parsed,
8033 	.data = NULL,
8034 	.help_str = "write reg <port_id> <reg_off> <reg_value>",
8035 	.tokens = {
8036 		(void *)&cmd_write_reg_write,
8037 		(void *)&cmd_write_reg_reg,
8038 		(void *)&cmd_write_reg_port_id,
8039 		(void *)&cmd_write_reg_reg_off,
8040 		(void *)&cmd_write_reg_value,
8041 		NULL,
8042 	},
8043 };
8044 
8045 /* *** WRITE PORT REGISTER BIT FIELD *** */
8046 struct cmd_write_reg_bit_field_result {
8047 	cmdline_fixed_string_t write;
8048 	cmdline_fixed_string_t regfield;
8049 	portid_t port_id;
8050 	uint32_t reg_off;
8051 	uint8_t bit1_pos;
8052 	uint8_t bit2_pos;
8053 	uint32_t value;
8054 };
8055 
8056 static void
8057 cmd_write_reg_bit_field_parsed(void *parsed_result,
8058 			       __rte_unused struct cmdline *cl,
8059 			       __rte_unused void *data)
8060 {
8061 	struct cmd_write_reg_bit_field_result *res = parsed_result;
8062 	port_reg_bit_field_set(res->port_id, res->reg_off,
8063 			  res->bit1_pos, res->bit2_pos, res->value);
8064 }
8065 
8066 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8067 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8068 				 "write");
8069 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8070 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8071 				 regfield, "regfield");
8072 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8073 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8074 			      UINT16);
8075 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8076 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8077 			      UINT32);
8078 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8079 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8080 			      UINT8);
8081 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8082 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8083 			      UINT8);
8084 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8085 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8086 			      UINT32);
8087 
8088 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8089 	.f = cmd_write_reg_bit_field_parsed,
8090 	.data = NULL,
8091 	.help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8092 		"<reg_value>: "
8093 		"Set register bit field between bit_x and bit_y included",
8094 	.tokens = {
8095 		(void *)&cmd_write_reg_bit_field_write,
8096 		(void *)&cmd_write_reg_bit_field_regfield,
8097 		(void *)&cmd_write_reg_bit_field_port_id,
8098 		(void *)&cmd_write_reg_bit_field_reg_off,
8099 		(void *)&cmd_write_reg_bit_field_bit1_pos,
8100 		(void *)&cmd_write_reg_bit_field_bit2_pos,
8101 		(void *)&cmd_write_reg_bit_field_value,
8102 		NULL,
8103 	},
8104 };
8105 
8106 /* *** WRITE PORT REGISTER BIT *** */
8107 struct cmd_write_reg_bit_result {
8108 	cmdline_fixed_string_t write;
8109 	cmdline_fixed_string_t regbit;
8110 	portid_t port_id;
8111 	uint32_t reg_off;
8112 	uint8_t bit_pos;
8113 	uint8_t value;
8114 };
8115 
8116 static void
8117 cmd_write_reg_bit_parsed(void *parsed_result,
8118 			 __rte_unused struct cmdline *cl,
8119 			 __rte_unused void *data)
8120 {
8121 	struct cmd_write_reg_bit_result *res = parsed_result;
8122 	port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8123 }
8124 
8125 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8126 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8127 				 "write");
8128 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8129 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8130 				 regbit, "regbit");
8131 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8132 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8133 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8134 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8135 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8136 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8137 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8138 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8139 
8140 cmdline_parse_inst_t cmd_write_reg_bit = {
8141 	.f = cmd_write_reg_bit_parsed,
8142 	.data = NULL,
8143 	.help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8144 		"0 <= bit_x <= 31",
8145 	.tokens = {
8146 		(void *)&cmd_write_reg_bit_write,
8147 		(void *)&cmd_write_reg_bit_regbit,
8148 		(void *)&cmd_write_reg_bit_port_id,
8149 		(void *)&cmd_write_reg_bit_reg_off,
8150 		(void *)&cmd_write_reg_bit_bit_pos,
8151 		(void *)&cmd_write_reg_bit_value,
8152 		NULL,
8153 	},
8154 };
8155 
8156 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8157 struct cmd_read_rxd_txd_result {
8158 	cmdline_fixed_string_t read;
8159 	cmdline_fixed_string_t rxd_txd;
8160 	portid_t port_id;
8161 	uint16_t queue_id;
8162 	uint16_t desc_id;
8163 };
8164 
8165 static void
8166 cmd_read_rxd_txd_parsed(void *parsed_result,
8167 			__rte_unused struct cmdline *cl,
8168 			__rte_unused void *data)
8169 {
8170 	struct cmd_read_rxd_txd_result *res = parsed_result;
8171 
8172 	if (!strcmp(res->rxd_txd, "rxd"))
8173 		rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8174 	else if (!strcmp(res->rxd_txd, "txd"))
8175 		tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8176 }
8177 
8178 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8179 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8180 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8181 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8182 				 "rxd#txd");
8183 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8184 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8185 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8186 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8187 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8188 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8189 
8190 cmdline_parse_inst_t cmd_read_rxd_txd = {
8191 	.f = cmd_read_rxd_txd_parsed,
8192 	.data = NULL,
8193 	.help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8194 	.tokens = {
8195 		(void *)&cmd_read_rxd_txd_read,
8196 		(void *)&cmd_read_rxd_txd_rxd_txd,
8197 		(void *)&cmd_read_rxd_txd_port_id,
8198 		(void *)&cmd_read_rxd_txd_queue_id,
8199 		(void *)&cmd_read_rxd_txd_desc_id,
8200 		NULL,
8201 	},
8202 };
8203 
8204 /* *** QUIT *** */
8205 struct cmd_quit_result {
8206 	cmdline_fixed_string_t quit;
8207 };
8208 
8209 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8210 			    struct cmdline *cl,
8211 			    __rte_unused void *data)
8212 {
8213 	cmdline_quit(cl);
8214 }
8215 
8216 cmdline_parse_token_string_t cmd_quit_quit =
8217 	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8218 
8219 cmdline_parse_inst_t cmd_quit = {
8220 	.f = cmd_quit_parsed,
8221 	.data = NULL,
8222 	.help_str = "quit: Exit application",
8223 	.tokens = {
8224 		(void *)&cmd_quit_quit,
8225 		NULL,
8226 	},
8227 };
8228 
8229 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8230 struct cmd_mac_addr_result {
8231 	cmdline_fixed_string_t mac_addr_cmd;
8232 	cmdline_fixed_string_t what;
8233 	uint16_t port_num;
8234 	struct rte_ether_addr address;
8235 };
8236 
8237 static void cmd_mac_addr_parsed(void *parsed_result,
8238 		__rte_unused struct cmdline *cl,
8239 		__rte_unused void *data)
8240 {
8241 	struct cmd_mac_addr_result *res = parsed_result;
8242 	int ret;
8243 
8244 	if (strcmp(res->what, "add") == 0)
8245 		ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8246 	else if (strcmp(res->what, "set") == 0)
8247 		ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8248 						       &res->address);
8249 	else
8250 		ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8251 
8252 	/* check the return value and print it if is < 0 */
8253 	if(ret < 0)
8254 		printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8255 
8256 }
8257 
8258 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8259 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8260 				"mac_addr");
8261 cmdline_parse_token_string_t cmd_mac_addr_what =
8262 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8263 				"add#remove#set");
8264 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8265 		TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8266 					UINT16);
8267 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8268 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8269 
8270 cmdline_parse_inst_t cmd_mac_addr = {
8271 	.f = cmd_mac_addr_parsed,
8272 	.data = (void *)0,
8273 	.help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8274 			"Add/Remove/Set MAC address on port_id",
8275 	.tokens = {
8276 		(void *)&cmd_mac_addr_cmd,
8277 		(void *)&cmd_mac_addr_what,
8278 		(void *)&cmd_mac_addr_portnum,
8279 		(void *)&cmd_mac_addr_addr,
8280 		NULL,
8281 	},
8282 };
8283 
8284 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8285 struct cmd_eth_peer_result {
8286 	cmdline_fixed_string_t set;
8287 	cmdline_fixed_string_t eth_peer;
8288 	portid_t port_id;
8289 	cmdline_fixed_string_t peer_addr;
8290 };
8291 
8292 static void cmd_set_eth_peer_parsed(void *parsed_result,
8293 			__rte_unused struct cmdline *cl,
8294 			__rte_unused void *data)
8295 {
8296 		struct cmd_eth_peer_result *res = parsed_result;
8297 
8298 		if (test_done == 0) {
8299 			printf("Please stop forwarding first\n");
8300 			return;
8301 		}
8302 		if (!strcmp(res->eth_peer, "eth-peer")) {
8303 			set_fwd_eth_peer(res->port_id, res->peer_addr);
8304 			fwd_config_setup();
8305 		}
8306 }
8307 cmdline_parse_token_string_t cmd_eth_peer_set =
8308 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8309 cmdline_parse_token_string_t cmd_eth_peer =
8310 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8311 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8312 	TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8313 cmdline_parse_token_string_t cmd_eth_peer_addr =
8314 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8315 
8316 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8317 	.f = cmd_set_eth_peer_parsed,
8318 	.data = NULL,
8319 	.help_str = "set eth-peer <port_id> <peer_mac>",
8320 	.tokens = {
8321 		(void *)&cmd_eth_peer_set,
8322 		(void *)&cmd_eth_peer,
8323 		(void *)&cmd_eth_peer_port_id,
8324 		(void *)&cmd_eth_peer_addr,
8325 		NULL,
8326 	},
8327 };
8328 
8329 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8330 struct cmd_set_qmap_result {
8331 	cmdline_fixed_string_t set;
8332 	cmdline_fixed_string_t qmap;
8333 	cmdline_fixed_string_t what;
8334 	portid_t port_id;
8335 	uint16_t queue_id;
8336 	uint8_t map_value;
8337 };
8338 
8339 static void
8340 cmd_set_qmap_parsed(void *parsed_result,
8341 		       __rte_unused struct cmdline *cl,
8342 		       __rte_unused void *data)
8343 {
8344 	struct cmd_set_qmap_result *res = parsed_result;
8345 	int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8346 
8347 	set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8348 }
8349 
8350 cmdline_parse_token_string_t cmd_setqmap_set =
8351 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8352 				 set, "set");
8353 cmdline_parse_token_string_t cmd_setqmap_qmap =
8354 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8355 				 qmap, "stat_qmap");
8356 cmdline_parse_token_string_t cmd_setqmap_what =
8357 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8358 				 what, "tx#rx");
8359 cmdline_parse_token_num_t cmd_setqmap_portid =
8360 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8361 			      port_id, UINT16);
8362 cmdline_parse_token_num_t cmd_setqmap_queueid =
8363 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8364 			      queue_id, UINT16);
8365 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8366 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8367 			      map_value, UINT8);
8368 
8369 cmdline_parse_inst_t cmd_set_qmap = {
8370 	.f = cmd_set_qmap_parsed,
8371 	.data = NULL,
8372 	.help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8373 		"Set statistics mapping value on tx|rx queue_id of port_id",
8374 	.tokens = {
8375 		(void *)&cmd_setqmap_set,
8376 		(void *)&cmd_setqmap_qmap,
8377 		(void *)&cmd_setqmap_what,
8378 		(void *)&cmd_setqmap_portid,
8379 		(void *)&cmd_setqmap_queueid,
8380 		(void *)&cmd_setqmap_mapvalue,
8381 		NULL,
8382 	},
8383 };
8384 
8385 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8386 struct cmd_set_xstats_hide_zero_result {
8387 	cmdline_fixed_string_t keyword;
8388 	cmdline_fixed_string_t name;
8389 	cmdline_fixed_string_t on_off;
8390 };
8391 
8392 static void
8393 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8394 			__rte_unused struct cmdline *cl,
8395 			__rte_unused void *data)
8396 {
8397 	struct cmd_set_xstats_hide_zero_result *res;
8398 	uint16_t on_off = 0;
8399 
8400 	res = parsed_result;
8401 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8402 	set_xstats_hide_zero(on_off);
8403 }
8404 
8405 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8406 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8407 				 keyword, "set");
8408 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8409 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8410 				 name, "xstats-hide-zero");
8411 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8412 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8413 				 on_off, "on#off");
8414 
8415 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8416 	.f = cmd_set_xstats_hide_zero_parsed,
8417 	.data = NULL,
8418 	.help_str = "set xstats-hide-zero on|off",
8419 	.tokens = {
8420 		(void *)&cmd_set_xstats_hide_zero_keyword,
8421 		(void *)&cmd_set_xstats_hide_zero_name,
8422 		(void *)&cmd_set_xstats_hide_zero_on_off,
8423 		NULL,
8424 	},
8425 };
8426 
8427 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8428 struct cmd_set_record_core_cycles_result {
8429 	cmdline_fixed_string_t keyword;
8430 	cmdline_fixed_string_t name;
8431 	cmdline_fixed_string_t on_off;
8432 };
8433 
8434 static void
8435 cmd_set_record_core_cycles_parsed(void *parsed_result,
8436 			__rte_unused struct cmdline *cl,
8437 			__rte_unused void *data)
8438 {
8439 	struct cmd_set_record_core_cycles_result *res;
8440 	uint16_t on_off = 0;
8441 
8442 	res = parsed_result;
8443 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8444 	set_record_core_cycles(on_off);
8445 }
8446 
8447 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8448 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8449 				 keyword, "set");
8450 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8451 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8452 				 name, "record-core-cycles");
8453 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8454 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8455 				 on_off, "on#off");
8456 
8457 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8458 	.f = cmd_set_record_core_cycles_parsed,
8459 	.data = NULL,
8460 	.help_str = "set record-core-cycles on|off",
8461 	.tokens = {
8462 		(void *)&cmd_set_record_core_cycles_keyword,
8463 		(void *)&cmd_set_record_core_cycles_name,
8464 		(void *)&cmd_set_record_core_cycles_on_off,
8465 		NULL,
8466 	},
8467 };
8468 
8469 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8470 struct cmd_set_record_burst_stats_result {
8471 	cmdline_fixed_string_t keyword;
8472 	cmdline_fixed_string_t name;
8473 	cmdline_fixed_string_t on_off;
8474 };
8475 
8476 static void
8477 cmd_set_record_burst_stats_parsed(void *parsed_result,
8478 			__rte_unused struct cmdline *cl,
8479 			__rte_unused void *data)
8480 {
8481 	struct cmd_set_record_burst_stats_result *res;
8482 	uint16_t on_off = 0;
8483 
8484 	res = parsed_result;
8485 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8486 	set_record_burst_stats(on_off);
8487 }
8488 
8489 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8490 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8491 				 keyword, "set");
8492 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8493 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8494 				 name, "record-burst-stats");
8495 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8496 	TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8497 				 on_off, "on#off");
8498 
8499 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8500 	.f = cmd_set_record_burst_stats_parsed,
8501 	.data = NULL,
8502 	.help_str = "set record-burst-stats on|off",
8503 	.tokens = {
8504 		(void *)&cmd_set_record_burst_stats_keyword,
8505 		(void *)&cmd_set_record_burst_stats_name,
8506 		(void *)&cmd_set_record_burst_stats_on_off,
8507 		NULL,
8508 	},
8509 };
8510 
8511 /* *** CONFIGURE UNICAST HASH TABLE *** */
8512 struct cmd_set_uc_hash_table {
8513 	cmdline_fixed_string_t set;
8514 	cmdline_fixed_string_t port;
8515 	portid_t port_id;
8516 	cmdline_fixed_string_t what;
8517 	struct rte_ether_addr address;
8518 	cmdline_fixed_string_t mode;
8519 };
8520 
8521 static void
8522 cmd_set_uc_hash_parsed(void *parsed_result,
8523 		       __rte_unused struct cmdline *cl,
8524 		       __rte_unused void *data)
8525 {
8526 	int ret=0;
8527 	struct cmd_set_uc_hash_table *res = parsed_result;
8528 
8529 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8530 
8531 	if (strcmp(res->what, "uta") == 0)
8532 		ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8533 						&res->address,(uint8_t)is_on);
8534 	if (ret < 0)
8535 		printf("bad unicast hash table parameter, return code = %d \n", ret);
8536 
8537 }
8538 
8539 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8540 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8541 				 set, "set");
8542 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8543 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8544 				 port, "port");
8545 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8546 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8547 			      port_id, UINT16);
8548 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8549 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8550 				 what, "uta");
8551 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8552 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8553 				address);
8554 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8555 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8556 				 mode, "on#off");
8557 
8558 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8559 	.f = cmd_set_uc_hash_parsed,
8560 	.data = NULL,
8561 	.help_str = "set port <port_id> uta <mac_addr> on|off)",
8562 	.tokens = {
8563 		(void *)&cmd_set_uc_hash_set,
8564 		(void *)&cmd_set_uc_hash_port,
8565 		(void *)&cmd_set_uc_hash_portid,
8566 		(void *)&cmd_set_uc_hash_what,
8567 		(void *)&cmd_set_uc_hash_mac,
8568 		(void *)&cmd_set_uc_hash_mode,
8569 		NULL,
8570 	},
8571 };
8572 
8573 struct cmd_set_uc_all_hash_table {
8574 	cmdline_fixed_string_t set;
8575 	cmdline_fixed_string_t port;
8576 	portid_t port_id;
8577 	cmdline_fixed_string_t what;
8578 	cmdline_fixed_string_t value;
8579 	cmdline_fixed_string_t mode;
8580 };
8581 
8582 static void
8583 cmd_set_uc_all_hash_parsed(void *parsed_result,
8584 		       __rte_unused struct cmdline *cl,
8585 		       __rte_unused void *data)
8586 {
8587 	int ret=0;
8588 	struct cmd_set_uc_all_hash_table *res = parsed_result;
8589 
8590 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8591 
8592 	if ((strcmp(res->what, "uta") == 0) &&
8593 		(strcmp(res->value, "all") == 0))
8594 		ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8595 	if (ret < 0)
8596 		printf("bad unicast hash table parameter,"
8597 			"return code = %d \n", ret);
8598 }
8599 
8600 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8601 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8602 				 set, "set");
8603 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8604 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8605 				 port, "port");
8606 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8607 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8608 			      port_id, UINT16);
8609 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8610 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8611 				 what, "uta");
8612 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8613 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8614 				value,"all");
8615 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8616 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8617 				 mode, "on#off");
8618 
8619 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8620 	.f = cmd_set_uc_all_hash_parsed,
8621 	.data = NULL,
8622 	.help_str = "set port <port_id> uta all on|off",
8623 	.tokens = {
8624 		(void *)&cmd_set_uc_all_hash_set,
8625 		(void *)&cmd_set_uc_all_hash_port,
8626 		(void *)&cmd_set_uc_all_hash_portid,
8627 		(void *)&cmd_set_uc_all_hash_what,
8628 		(void *)&cmd_set_uc_all_hash_value,
8629 		(void *)&cmd_set_uc_all_hash_mode,
8630 		NULL,
8631 	},
8632 };
8633 
8634 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8635 struct cmd_set_vf_macvlan_filter {
8636 	cmdline_fixed_string_t set;
8637 	cmdline_fixed_string_t port;
8638 	portid_t port_id;
8639 	cmdline_fixed_string_t vf;
8640 	uint8_t vf_id;
8641 	struct rte_ether_addr address;
8642 	cmdline_fixed_string_t filter_type;
8643 	cmdline_fixed_string_t mode;
8644 };
8645 
8646 static void
8647 cmd_set_vf_macvlan_parsed(void *parsed_result,
8648 		       __rte_unused struct cmdline *cl,
8649 		       __rte_unused void *data)
8650 {
8651 	int is_on, ret = 0;
8652 	struct cmd_set_vf_macvlan_filter *res = parsed_result;
8653 	struct rte_eth_mac_filter filter;
8654 
8655 	memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8656 
8657 	rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8658 
8659 	/* set VF MAC filter */
8660 	filter.is_vf = 1;
8661 
8662 	/* set VF ID */
8663 	filter.dst_id = res->vf_id;
8664 
8665 	if (!strcmp(res->filter_type, "exact-mac"))
8666 		filter.filter_type = RTE_MAC_PERFECT_MATCH;
8667 	else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8668 		filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8669 	else if (!strcmp(res->filter_type, "hashmac"))
8670 		filter.filter_type = RTE_MAC_HASH_MATCH;
8671 	else if (!strcmp(res->filter_type, "hashmac-vlan"))
8672 		filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8673 
8674 	is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8675 
8676 	if (is_on)
8677 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8678 					RTE_ETH_FILTER_MACVLAN,
8679 					RTE_ETH_FILTER_ADD,
8680 					 &filter);
8681 	else
8682 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8683 					RTE_ETH_FILTER_MACVLAN,
8684 					RTE_ETH_FILTER_DELETE,
8685 					&filter);
8686 
8687 	if (ret < 0)
8688 		printf("bad set MAC hash parameter, return code = %d\n", ret);
8689 
8690 }
8691 
8692 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8693 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8694 				 set, "set");
8695 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8696 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8697 				 port, "port");
8698 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8699 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8700 			      port_id, UINT16);
8701 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8702 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8703 				 vf, "vf");
8704 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8705 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8706 				vf_id, UINT8);
8707 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8708 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8709 				address);
8710 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8711 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8712 				filter_type, "exact-mac#exact-mac-vlan"
8713 				"#hashmac#hashmac-vlan");
8714 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8715 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8716 				 mode, "on#off");
8717 
8718 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8719 	.f = cmd_set_vf_macvlan_parsed,
8720 	.data = NULL,
8721 	.help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8722 		"exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8723 		"Exact match rule: exact match of MAC or MAC and VLAN; "
8724 		"hash match rule: hash match of MAC and exact match of VLAN",
8725 	.tokens = {
8726 		(void *)&cmd_set_vf_macvlan_set,
8727 		(void *)&cmd_set_vf_macvlan_port,
8728 		(void *)&cmd_set_vf_macvlan_portid,
8729 		(void *)&cmd_set_vf_macvlan_vf,
8730 		(void *)&cmd_set_vf_macvlan_vf_id,
8731 		(void *)&cmd_set_vf_macvlan_mac,
8732 		(void *)&cmd_set_vf_macvlan_filter_type,
8733 		(void *)&cmd_set_vf_macvlan_mode,
8734 		NULL,
8735 	},
8736 };
8737 
8738 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8739 struct cmd_set_vf_traffic {
8740 	cmdline_fixed_string_t set;
8741 	cmdline_fixed_string_t port;
8742 	portid_t port_id;
8743 	cmdline_fixed_string_t vf;
8744 	uint8_t vf_id;
8745 	cmdline_fixed_string_t what;
8746 	cmdline_fixed_string_t mode;
8747 };
8748 
8749 static void
8750 cmd_set_vf_traffic_parsed(void *parsed_result,
8751 		       __rte_unused struct cmdline *cl,
8752 		       __rte_unused void *data)
8753 {
8754 	struct cmd_set_vf_traffic *res = parsed_result;
8755 	int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8756 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8757 
8758 	set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8759 }
8760 
8761 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8762 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8763 				 set, "set");
8764 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8765 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8766 				 port, "port");
8767 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8768 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8769 			      port_id, UINT16);
8770 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8771 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8772 				 vf, "vf");
8773 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8774 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8775 			      vf_id, UINT8);
8776 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8777 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8778 				 what, "tx#rx");
8779 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8780 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8781 				 mode, "on#off");
8782 
8783 cmdline_parse_inst_t cmd_set_vf_traffic = {
8784 	.f = cmd_set_vf_traffic_parsed,
8785 	.data = NULL,
8786 	.help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8787 	.tokens = {
8788 		(void *)&cmd_setvf_traffic_set,
8789 		(void *)&cmd_setvf_traffic_port,
8790 		(void *)&cmd_setvf_traffic_portid,
8791 		(void *)&cmd_setvf_traffic_vf,
8792 		(void *)&cmd_setvf_traffic_vfid,
8793 		(void *)&cmd_setvf_traffic_what,
8794 		(void *)&cmd_setvf_traffic_mode,
8795 		NULL,
8796 	},
8797 };
8798 
8799 /* *** CONFIGURE VF RECEIVE MODE *** */
8800 struct cmd_set_vf_rxmode {
8801 	cmdline_fixed_string_t set;
8802 	cmdline_fixed_string_t port;
8803 	portid_t port_id;
8804 	cmdline_fixed_string_t vf;
8805 	uint8_t vf_id;
8806 	cmdline_fixed_string_t what;
8807 	cmdline_fixed_string_t mode;
8808 	cmdline_fixed_string_t on;
8809 };
8810 
8811 static void
8812 cmd_set_vf_rxmode_parsed(void *parsed_result,
8813 		       __rte_unused struct cmdline *cl,
8814 		       __rte_unused void *data)
8815 {
8816 	int ret = -ENOTSUP;
8817 	uint16_t vf_rxmode = 0;
8818 	struct cmd_set_vf_rxmode *res = parsed_result;
8819 
8820 	int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8821 	if (!strcmp(res->what,"rxmode")) {
8822 		if (!strcmp(res->mode, "AUPE"))
8823 			vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8824 		else if (!strcmp(res->mode, "ROPE"))
8825 			vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8826 		else if (!strcmp(res->mode, "BAM"))
8827 			vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8828 		else if (!strncmp(res->mode, "MPE",3))
8829 			vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8830 	}
8831 
8832 	RTE_SET_USED(is_on);
8833 
8834 #ifdef RTE_LIBRTE_IXGBE_PMD
8835 	if (ret == -ENOTSUP)
8836 		ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8837 						  vf_rxmode, (uint8_t)is_on);
8838 #endif
8839 #ifdef RTE_LIBRTE_BNXT_PMD
8840 	if (ret == -ENOTSUP)
8841 		ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8842 						 vf_rxmode, (uint8_t)is_on);
8843 #endif
8844 	if (ret < 0)
8845 		printf("bad VF receive mode parameter, return code = %d \n",
8846 		ret);
8847 }
8848 
8849 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8850 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8851 				 set, "set");
8852 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8853 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8854 				 port, "port");
8855 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8856 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8857 			      port_id, UINT16);
8858 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8859 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8860 				 vf, "vf");
8861 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8862 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8863 			      vf_id, UINT8);
8864 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8865 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8866 				 what, "rxmode");
8867 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8868 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8869 				 mode, "AUPE#ROPE#BAM#MPE");
8870 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8871 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8872 				 on, "on#off");
8873 
8874 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8875 	.f = cmd_set_vf_rxmode_parsed,
8876 	.data = NULL,
8877 	.help_str = "set port <port_id> vf <vf_id> rxmode "
8878 		"AUPE|ROPE|BAM|MPE on|off",
8879 	.tokens = {
8880 		(void *)&cmd_set_vf_rxmode_set,
8881 		(void *)&cmd_set_vf_rxmode_port,
8882 		(void *)&cmd_set_vf_rxmode_portid,
8883 		(void *)&cmd_set_vf_rxmode_vf,
8884 		(void *)&cmd_set_vf_rxmode_vfid,
8885 		(void *)&cmd_set_vf_rxmode_what,
8886 		(void *)&cmd_set_vf_rxmode_mode,
8887 		(void *)&cmd_set_vf_rxmode_on,
8888 		NULL,
8889 	},
8890 };
8891 
8892 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8893 struct cmd_vf_mac_addr_result {
8894 	cmdline_fixed_string_t mac_addr_cmd;
8895 	cmdline_fixed_string_t what;
8896 	cmdline_fixed_string_t port;
8897 	uint16_t port_num;
8898 	cmdline_fixed_string_t vf;
8899 	uint8_t vf_num;
8900 	struct rte_ether_addr address;
8901 };
8902 
8903 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8904 		__rte_unused struct cmdline *cl,
8905 		__rte_unused void *data)
8906 {
8907 	struct cmd_vf_mac_addr_result *res = parsed_result;
8908 	int ret = -ENOTSUP;
8909 
8910 	if (strcmp(res->what, "add") != 0)
8911 		return;
8912 
8913 #ifdef RTE_LIBRTE_I40E_PMD
8914 	if (ret == -ENOTSUP)
8915 		ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8916 						   &res->address);
8917 #endif
8918 #ifdef RTE_LIBRTE_BNXT_PMD
8919 	if (ret == -ENOTSUP)
8920 		ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8921 						res->vf_num);
8922 #endif
8923 
8924 	if(ret < 0)
8925 		printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8926 
8927 }
8928 
8929 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8930 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8931 				mac_addr_cmd,"mac_addr");
8932 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8933 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8934 				what,"add");
8935 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8936 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8937 				port,"port");
8938 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8939 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8940 				port_num, UINT16);
8941 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8942 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8943 				vf,"vf");
8944 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8945 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8946 				vf_num, UINT8);
8947 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8948 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8949 				address);
8950 
8951 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8952 	.f = cmd_vf_mac_addr_parsed,
8953 	.data = (void *)0,
8954 	.help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8955 		"Add MAC address filtering for a VF on port_id",
8956 	.tokens = {
8957 		(void *)&cmd_vf_mac_addr_cmd,
8958 		(void *)&cmd_vf_mac_addr_what,
8959 		(void *)&cmd_vf_mac_addr_port,
8960 		(void *)&cmd_vf_mac_addr_portnum,
8961 		(void *)&cmd_vf_mac_addr_vf,
8962 		(void *)&cmd_vf_mac_addr_vfnum,
8963 		(void *)&cmd_vf_mac_addr_addr,
8964 		NULL,
8965 	},
8966 };
8967 
8968 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8969 struct cmd_vf_rx_vlan_filter {
8970 	cmdline_fixed_string_t rx_vlan;
8971 	cmdline_fixed_string_t what;
8972 	uint16_t vlan_id;
8973 	cmdline_fixed_string_t port;
8974 	portid_t port_id;
8975 	cmdline_fixed_string_t vf;
8976 	uint64_t vf_mask;
8977 };
8978 
8979 static void
8980 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8981 			  __rte_unused struct cmdline *cl,
8982 			  __rte_unused void *data)
8983 {
8984 	struct cmd_vf_rx_vlan_filter *res = parsed_result;
8985 	int ret = -ENOTSUP;
8986 
8987 	__rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8988 
8989 #ifdef RTE_LIBRTE_IXGBE_PMD
8990 	if (ret == -ENOTSUP)
8991 		ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8992 				res->vlan_id, res->vf_mask, is_add);
8993 #endif
8994 #ifdef RTE_LIBRTE_I40E_PMD
8995 	if (ret == -ENOTSUP)
8996 		ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8997 				res->vlan_id, res->vf_mask, is_add);
8998 #endif
8999 #ifdef RTE_LIBRTE_BNXT_PMD
9000 	if (ret == -ENOTSUP)
9001 		ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9002 				res->vlan_id, res->vf_mask, is_add);
9003 #endif
9004 
9005 	switch (ret) {
9006 	case 0:
9007 		break;
9008 	case -EINVAL:
9009 		printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
9010 				res->vlan_id, res->vf_mask);
9011 		break;
9012 	case -ENODEV:
9013 		printf("invalid port_id %d\n", res->port_id);
9014 		break;
9015 	case -ENOTSUP:
9016 		printf("function not implemented or supported\n");
9017 		break;
9018 	default:
9019 		printf("programming error: (%s)\n", strerror(-ret));
9020 	}
9021 }
9022 
9023 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9024 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9025 				 rx_vlan, "rx_vlan");
9026 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9027 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9028 				 what, "add#rm");
9029 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9030 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9031 			      vlan_id, UINT16);
9032 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9033 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9034 				 port, "port");
9035 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9036 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9037 			      port_id, UINT16);
9038 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9039 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9040 				 vf, "vf");
9041 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9042 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9043 			      vf_mask, UINT64);
9044 
9045 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9046 	.f = cmd_vf_rx_vlan_filter_parsed,
9047 	.data = NULL,
9048 	.help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9049 		"(vf_mask = hexadecimal VF mask)",
9050 	.tokens = {
9051 		(void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9052 		(void *)&cmd_vf_rx_vlan_filter_what,
9053 		(void *)&cmd_vf_rx_vlan_filter_vlanid,
9054 		(void *)&cmd_vf_rx_vlan_filter_port,
9055 		(void *)&cmd_vf_rx_vlan_filter_portid,
9056 		(void *)&cmd_vf_rx_vlan_filter_vf,
9057 		(void *)&cmd_vf_rx_vlan_filter_vf_mask,
9058 		NULL,
9059 	},
9060 };
9061 
9062 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9063 struct cmd_queue_rate_limit_result {
9064 	cmdline_fixed_string_t set;
9065 	cmdline_fixed_string_t port;
9066 	uint16_t port_num;
9067 	cmdline_fixed_string_t queue;
9068 	uint8_t queue_num;
9069 	cmdline_fixed_string_t rate;
9070 	uint16_t rate_num;
9071 };
9072 
9073 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9074 		__rte_unused struct cmdline *cl,
9075 		__rte_unused void *data)
9076 {
9077 	struct cmd_queue_rate_limit_result *res = parsed_result;
9078 	int ret = 0;
9079 
9080 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9081 		&& (strcmp(res->queue, "queue") == 0)
9082 		&& (strcmp(res->rate, "rate") == 0))
9083 		ret = set_queue_rate_limit(res->port_num, res->queue_num,
9084 					res->rate_num);
9085 	if (ret < 0)
9086 		printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
9087 
9088 }
9089 
9090 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9091 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9092 				set, "set");
9093 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9094 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9095 				port, "port");
9096 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9097 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9098 				port_num, UINT16);
9099 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9100 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9101 				queue, "queue");
9102 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9103 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9104 				queue_num, UINT8);
9105 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9106 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9107 				rate, "rate");
9108 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9109 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9110 				rate_num, UINT16);
9111 
9112 cmdline_parse_inst_t cmd_queue_rate_limit = {
9113 	.f = cmd_queue_rate_limit_parsed,
9114 	.data = (void *)0,
9115 	.help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9116 		"Set rate limit for a queue on port_id",
9117 	.tokens = {
9118 		(void *)&cmd_queue_rate_limit_set,
9119 		(void *)&cmd_queue_rate_limit_port,
9120 		(void *)&cmd_queue_rate_limit_portnum,
9121 		(void *)&cmd_queue_rate_limit_queue,
9122 		(void *)&cmd_queue_rate_limit_queuenum,
9123 		(void *)&cmd_queue_rate_limit_rate,
9124 		(void *)&cmd_queue_rate_limit_ratenum,
9125 		NULL,
9126 	},
9127 };
9128 
9129 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9130 struct cmd_vf_rate_limit_result {
9131 	cmdline_fixed_string_t set;
9132 	cmdline_fixed_string_t port;
9133 	uint16_t port_num;
9134 	cmdline_fixed_string_t vf;
9135 	uint8_t vf_num;
9136 	cmdline_fixed_string_t rate;
9137 	uint16_t rate_num;
9138 	cmdline_fixed_string_t q_msk;
9139 	uint64_t q_msk_val;
9140 };
9141 
9142 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9143 		__rte_unused struct cmdline *cl,
9144 		__rte_unused void *data)
9145 {
9146 	struct cmd_vf_rate_limit_result *res = parsed_result;
9147 	int ret = 0;
9148 
9149 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9150 		&& (strcmp(res->vf, "vf") == 0)
9151 		&& (strcmp(res->rate, "rate") == 0)
9152 		&& (strcmp(res->q_msk, "queue_mask") == 0))
9153 		ret = set_vf_rate_limit(res->port_num, res->vf_num,
9154 					res->rate_num, res->q_msk_val);
9155 	if (ret < 0)
9156 		printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9157 
9158 }
9159 
9160 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9161 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9162 				set, "set");
9163 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9164 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9165 				port, "port");
9166 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9167 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9168 				port_num, UINT16);
9169 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9170 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9171 				vf, "vf");
9172 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9173 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9174 				vf_num, UINT8);
9175 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9176 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9177 				rate, "rate");
9178 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9179 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9180 				rate_num, UINT16);
9181 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9182 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9183 				q_msk, "queue_mask");
9184 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9185 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9186 				q_msk_val, UINT64);
9187 
9188 cmdline_parse_inst_t cmd_vf_rate_limit = {
9189 	.f = cmd_vf_rate_limit_parsed,
9190 	.data = (void *)0,
9191 	.help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9192 		"queue_mask <queue_mask_value>: "
9193 		"Set rate limit for queues of VF on port_id",
9194 	.tokens = {
9195 		(void *)&cmd_vf_rate_limit_set,
9196 		(void *)&cmd_vf_rate_limit_port,
9197 		(void *)&cmd_vf_rate_limit_portnum,
9198 		(void *)&cmd_vf_rate_limit_vf,
9199 		(void *)&cmd_vf_rate_limit_vfnum,
9200 		(void *)&cmd_vf_rate_limit_rate,
9201 		(void *)&cmd_vf_rate_limit_ratenum,
9202 		(void *)&cmd_vf_rate_limit_q_msk,
9203 		(void *)&cmd_vf_rate_limit_q_msk_val,
9204 		NULL,
9205 	},
9206 };
9207 
9208 /* *** ADD TUNNEL FILTER OF A PORT *** */
9209 struct cmd_tunnel_filter_result {
9210 	cmdline_fixed_string_t cmd;
9211 	cmdline_fixed_string_t what;
9212 	portid_t port_id;
9213 	struct rte_ether_addr outer_mac;
9214 	struct rte_ether_addr inner_mac;
9215 	cmdline_ipaddr_t ip_value;
9216 	uint16_t inner_vlan;
9217 	cmdline_fixed_string_t tunnel_type;
9218 	cmdline_fixed_string_t filter_type;
9219 	uint32_t tenant_id;
9220 	uint16_t queue_num;
9221 };
9222 
9223 static void
9224 cmd_tunnel_filter_parsed(void *parsed_result,
9225 			  __rte_unused struct cmdline *cl,
9226 			  __rte_unused void *data)
9227 {
9228 	struct cmd_tunnel_filter_result *res = parsed_result;
9229 	struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
9230 	int ret = 0;
9231 
9232 	memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9233 
9234 	rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9235 	rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9236 	tunnel_filter_conf.inner_vlan = res->inner_vlan;
9237 
9238 	if (res->ip_value.family == AF_INET) {
9239 		tunnel_filter_conf.ip_addr.ipv4_addr =
9240 			res->ip_value.addr.ipv4.s_addr;
9241 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9242 	} else {
9243 		memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9244 			&(res->ip_value.addr.ipv6),
9245 			sizeof(struct in6_addr));
9246 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9247 	}
9248 
9249 	if (!strcmp(res->filter_type, "imac-ivlan"))
9250 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9251 	else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9252 		tunnel_filter_conf.filter_type =
9253 			RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9254 	else if (!strcmp(res->filter_type, "imac-tenid"))
9255 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9256 	else if (!strcmp(res->filter_type, "imac"))
9257 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9258 	else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9259 		tunnel_filter_conf.filter_type =
9260 			RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9261 	else if (!strcmp(res->filter_type, "oip"))
9262 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9263 	else if (!strcmp(res->filter_type, "iip"))
9264 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9265 	else {
9266 		printf("The filter type is not supported");
9267 		return;
9268 	}
9269 
9270 	if (!strcmp(res->tunnel_type, "vxlan"))
9271 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9272 	else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9273 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9274 	else if (!strcmp(res->tunnel_type, "nvgre"))
9275 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9276 	else if (!strcmp(res->tunnel_type, "ipingre"))
9277 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9278 	else {
9279 		printf("The tunnel type %s not supported.\n", res->tunnel_type);
9280 		return;
9281 	}
9282 
9283 	tunnel_filter_conf.tenant_id = res->tenant_id;
9284 	tunnel_filter_conf.queue_id = res->queue_num;
9285 	if (!strcmp(res->what, "add"))
9286 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9287 					RTE_ETH_FILTER_TUNNEL,
9288 					RTE_ETH_FILTER_ADD,
9289 					&tunnel_filter_conf);
9290 	else
9291 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9292 					RTE_ETH_FILTER_TUNNEL,
9293 					RTE_ETH_FILTER_DELETE,
9294 					&tunnel_filter_conf);
9295 	if (ret < 0)
9296 		printf("cmd_tunnel_filter_parsed error: (%s)\n",
9297 				strerror(-ret));
9298 
9299 }
9300 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9301 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9302 	cmd, "tunnel_filter");
9303 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9304 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9305 	what, "add#rm");
9306 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9307 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9308 	port_id, UINT16);
9309 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9310 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9311 	outer_mac);
9312 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9313 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9314 	inner_mac);
9315 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9316 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9317 	inner_vlan, UINT16);
9318 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9319 	TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9320 	ip_value);
9321 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9322 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9323 	tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9324 
9325 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9326 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9327 	filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9328 		"imac#omac-imac-tenid");
9329 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9330 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9331 	tenant_id, UINT32);
9332 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9333 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9334 	queue_num, UINT16);
9335 
9336 cmdline_parse_inst_t cmd_tunnel_filter = {
9337 	.f = cmd_tunnel_filter_parsed,
9338 	.data = (void *)0,
9339 	.help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9340 		"<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9341 		"imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9342 		"<queue_id>: Add/Rm tunnel filter of a port",
9343 	.tokens = {
9344 		(void *)&cmd_tunnel_filter_cmd,
9345 		(void *)&cmd_tunnel_filter_what,
9346 		(void *)&cmd_tunnel_filter_port_id,
9347 		(void *)&cmd_tunnel_filter_outer_mac,
9348 		(void *)&cmd_tunnel_filter_inner_mac,
9349 		(void *)&cmd_tunnel_filter_ip_value,
9350 		(void *)&cmd_tunnel_filter_innner_vlan,
9351 		(void *)&cmd_tunnel_filter_tunnel_type,
9352 		(void *)&cmd_tunnel_filter_filter_type,
9353 		(void *)&cmd_tunnel_filter_tenant_id,
9354 		(void *)&cmd_tunnel_filter_queue_num,
9355 		NULL,
9356 	},
9357 };
9358 
9359 /* *** CONFIGURE TUNNEL UDP PORT *** */
9360 struct cmd_tunnel_udp_config {
9361 	cmdline_fixed_string_t cmd;
9362 	cmdline_fixed_string_t what;
9363 	uint16_t udp_port;
9364 	portid_t port_id;
9365 };
9366 
9367 static void
9368 cmd_tunnel_udp_config_parsed(void *parsed_result,
9369 			  __rte_unused struct cmdline *cl,
9370 			  __rte_unused void *data)
9371 {
9372 	struct cmd_tunnel_udp_config *res = parsed_result;
9373 	struct rte_eth_udp_tunnel tunnel_udp;
9374 	int ret;
9375 
9376 	tunnel_udp.udp_port = res->udp_port;
9377 
9378 	if (!strcmp(res->cmd, "rx_vxlan_port"))
9379 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9380 
9381 	if (!strcmp(res->what, "add"))
9382 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9383 						      &tunnel_udp);
9384 	else
9385 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9386 							 &tunnel_udp);
9387 
9388 	if (ret < 0)
9389 		printf("udp tunneling add error: (%s)\n", strerror(-ret));
9390 }
9391 
9392 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9393 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9394 				cmd, "rx_vxlan_port");
9395 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9396 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9397 				what, "add#rm");
9398 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9399 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9400 				udp_port, UINT16);
9401 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9402 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9403 				port_id, UINT16);
9404 
9405 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9406 	.f = cmd_tunnel_udp_config_parsed,
9407 	.data = (void *)0,
9408 	.help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9409 		"Add/Remove a tunneling UDP port filter",
9410 	.tokens = {
9411 		(void *)&cmd_tunnel_udp_config_cmd,
9412 		(void *)&cmd_tunnel_udp_config_what,
9413 		(void *)&cmd_tunnel_udp_config_udp_port,
9414 		(void *)&cmd_tunnel_udp_config_port_id,
9415 		NULL,
9416 	},
9417 };
9418 
9419 struct cmd_config_tunnel_udp_port {
9420 	cmdline_fixed_string_t port;
9421 	cmdline_fixed_string_t config;
9422 	portid_t port_id;
9423 	cmdline_fixed_string_t udp_tunnel_port;
9424 	cmdline_fixed_string_t action;
9425 	cmdline_fixed_string_t tunnel_type;
9426 	uint16_t udp_port;
9427 };
9428 
9429 static void
9430 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9431 			       __rte_unused struct cmdline *cl,
9432 			       __rte_unused void *data)
9433 {
9434 	struct cmd_config_tunnel_udp_port *res = parsed_result;
9435 	struct rte_eth_udp_tunnel tunnel_udp;
9436 	int ret = 0;
9437 
9438 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9439 		return;
9440 
9441 	tunnel_udp.udp_port = res->udp_port;
9442 
9443 	if (!strcmp(res->tunnel_type, "vxlan")) {
9444 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9445 	} else if (!strcmp(res->tunnel_type, "geneve")) {
9446 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9447 	} else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9448 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9449 	} else {
9450 		printf("Invalid tunnel type\n");
9451 		return;
9452 	}
9453 
9454 	if (!strcmp(res->action, "add"))
9455 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9456 						      &tunnel_udp);
9457 	else
9458 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9459 							 &tunnel_udp);
9460 
9461 	if (ret < 0)
9462 		printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9463 }
9464 
9465 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9466 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9467 				 "port");
9468 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9469 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9470 				 "config");
9471 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9472 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9473 			      UINT16);
9474 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9475 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9476 				 udp_tunnel_port,
9477 				 "udp_tunnel_port");
9478 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9479 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9480 				 "add#rm");
9481 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9482 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9483 				 "vxlan#geneve#vxlan-gpe");
9484 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9485 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9486 			      UINT16);
9487 
9488 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9489 	.f = cmd_cfg_tunnel_udp_port_parsed,
9490 	.data = NULL,
9491 	.help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9492 	.tokens = {
9493 		(void *)&cmd_config_tunnel_udp_port_port,
9494 		(void *)&cmd_config_tunnel_udp_port_config,
9495 		(void *)&cmd_config_tunnel_udp_port_port_id,
9496 		(void *)&cmd_config_tunnel_udp_port_tunnel_port,
9497 		(void *)&cmd_config_tunnel_udp_port_action,
9498 		(void *)&cmd_config_tunnel_udp_port_tunnel_type,
9499 		(void *)&cmd_config_tunnel_udp_port_value,
9500 		NULL,
9501 	},
9502 };
9503 
9504 /* *** GLOBAL CONFIG *** */
9505 struct cmd_global_config_result {
9506 	cmdline_fixed_string_t cmd;
9507 	portid_t port_id;
9508 	cmdline_fixed_string_t cfg_type;
9509 	uint8_t len;
9510 };
9511 
9512 static void
9513 cmd_global_config_parsed(void *parsed_result,
9514 			 __rte_unused struct cmdline *cl,
9515 			 __rte_unused void *data)
9516 {
9517 	struct cmd_global_config_result *res = parsed_result;
9518 	struct rte_eth_global_cfg conf;
9519 	int ret;
9520 
9521 	memset(&conf, 0, sizeof(conf));
9522 	conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9523 	conf.cfg.gre_key_len = res->len;
9524 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9525 				      RTE_ETH_FILTER_SET, &conf);
9526 #ifdef RTE_LIBRTE_I40E_PMD
9527 	if (ret == -ENOTSUP)
9528 		ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9529 #endif
9530 	if (ret != 0)
9531 		printf("Global config error\n");
9532 }
9533 
9534 cmdline_parse_token_string_t cmd_global_config_cmd =
9535 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9536 		"global_config");
9537 cmdline_parse_token_num_t cmd_global_config_port_id =
9538 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9539 			       UINT16);
9540 cmdline_parse_token_string_t cmd_global_config_type =
9541 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9542 		cfg_type, "gre-key-len");
9543 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9544 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9545 		len, UINT8);
9546 
9547 cmdline_parse_inst_t cmd_global_config = {
9548 	.f = cmd_global_config_parsed,
9549 	.data = (void *)NULL,
9550 	.help_str = "global_config <port_id> gre-key-len <key_len>",
9551 	.tokens = {
9552 		(void *)&cmd_global_config_cmd,
9553 		(void *)&cmd_global_config_port_id,
9554 		(void *)&cmd_global_config_type,
9555 		(void *)&cmd_global_config_gre_key_len,
9556 		NULL,
9557 	},
9558 };
9559 
9560 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9561 struct cmd_set_mirror_mask_result {
9562 	cmdline_fixed_string_t set;
9563 	cmdline_fixed_string_t port;
9564 	portid_t port_id;
9565 	cmdline_fixed_string_t mirror;
9566 	uint8_t rule_id;
9567 	cmdline_fixed_string_t what;
9568 	cmdline_fixed_string_t value;
9569 	cmdline_fixed_string_t dstpool;
9570 	uint8_t dstpool_id;
9571 	cmdline_fixed_string_t on;
9572 };
9573 
9574 cmdline_parse_token_string_t cmd_mirror_mask_set =
9575 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9576 				set, "set");
9577 cmdline_parse_token_string_t cmd_mirror_mask_port =
9578 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9579 				port, "port");
9580 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9581 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9582 				port_id, UINT16);
9583 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9584 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9585 				mirror, "mirror-rule");
9586 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9587 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9588 				rule_id, UINT8);
9589 cmdline_parse_token_string_t cmd_mirror_mask_what =
9590 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9591 				what, "pool-mirror-up#pool-mirror-down"
9592 				      "#vlan-mirror");
9593 cmdline_parse_token_string_t cmd_mirror_mask_value =
9594 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9595 				value, NULL);
9596 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9597 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9598 				dstpool, "dst-pool");
9599 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9600 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9601 				dstpool_id, UINT8);
9602 cmdline_parse_token_string_t cmd_mirror_mask_on =
9603 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9604 				on, "on#off");
9605 
9606 static void
9607 cmd_set_mirror_mask_parsed(void *parsed_result,
9608 		       __rte_unused struct cmdline *cl,
9609 		       __rte_unused void *data)
9610 {
9611 	int ret,nb_item,i;
9612 	struct cmd_set_mirror_mask_result *res = parsed_result;
9613 	struct rte_eth_mirror_conf mr_conf;
9614 
9615 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9616 
9617 	unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9618 
9619 	mr_conf.dst_pool = res->dstpool_id;
9620 
9621 	if (!strcmp(res->what, "pool-mirror-up")) {
9622 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9623 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9624 	} else if (!strcmp(res->what, "pool-mirror-down")) {
9625 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9626 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9627 	} else if (!strcmp(res->what, "vlan-mirror")) {
9628 		mr_conf.rule_type = ETH_MIRROR_VLAN;
9629 		nb_item = parse_item_list(res->value, "vlan",
9630 				ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9631 		if (nb_item <= 0)
9632 			return;
9633 
9634 		for (i = 0; i < nb_item; i++) {
9635 			if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9636 				printf("Invalid vlan_id: must be < 4096\n");
9637 				return;
9638 			}
9639 
9640 			mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9641 			mr_conf.vlan.vlan_mask |= 1ULL << i;
9642 		}
9643 	}
9644 
9645 	if (!strcmp(res->on, "on"))
9646 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9647 						res->rule_id, 1);
9648 	else
9649 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9650 						res->rule_id, 0);
9651 	if (ret < 0)
9652 		printf("mirror rule add error: (%s)\n", strerror(-ret));
9653 }
9654 
9655 cmdline_parse_inst_t cmd_set_mirror_mask = {
9656 		.f = cmd_set_mirror_mask_parsed,
9657 		.data = NULL,
9658 		.help_str = "set port <port_id> mirror-rule <rule_id> "
9659 			"pool-mirror-up|pool-mirror-down|vlan-mirror "
9660 			"<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9661 		.tokens = {
9662 			(void *)&cmd_mirror_mask_set,
9663 			(void *)&cmd_mirror_mask_port,
9664 			(void *)&cmd_mirror_mask_portid,
9665 			(void *)&cmd_mirror_mask_mirror,
9666 			(void *)&cmd_mirror_mask_ruleid,
9667 			(void *)&cmd_mirror_mask_what,
9668 			(void *)&cmd_mirror_mask_value,
9669 			(void *)&cmd_mirror_mask_dstpool,
9670 			(void *)&cmd_mirror_mask_poolid,
9671 			(void *)&cmd_mirror_mask_on,
9672 			NULL,
9673 		},
9674 };
9675 
9676 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9677 struct cmd_set_mirror_link_result {
9678 	cmdline_fixed_string_t set;
9679 	cmdline_fixed_string_t port;
9680 	portid_t port_id;
9681 	cmdline_fixed_string_t mirror;
9682 	uint8_t rule_id;
9683 	cmdline_fixed_string_t what;
9684 	cmdline_fixed_string_t dstpool;
9685 	uint8_t dstpool_id;
9686 	cmdline_fixed_string_t on;
9687 };
9688 
9689 cmdline_parse_token_string_t cmd_mirror_link_set =
9690 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9691 				 set, "set");
9692 cmdline_parse_token_string_t cmd_mirror_link_port =
9693 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9694 				port, "port");
9695 cmdline_parse_token_num_t cmd_mirror_link_portid =
9696 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9697 				port_id, UINT16);
9698 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9699 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9700 				mirror, "mirror-rule");
9701 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9702 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9703 			    rule_id, UINT8);
9704 cmdline_parse_token_string_t cmd_mirror_link_what =
9705 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9706 				what, "uplink-mirror#downlink-mirror");
9707 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9708 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9709 				dstpool, "dst-pool");
9710 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9711 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9712 				dstpool_id, UINT8);
9713 cmdline_parse_token_string_t cmd_mirror_link_on =
9714 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9715 				on, "on#off");
9716 
9717 static void
9718 cmd_set_mirror_link_parsed(void *parsed_result,
9719 		       __rte_unused struct cmdline *cl,
9720 		       __rte_unused void *data)
9721 {
9722 	int ret;
9723 	struct cmd_set_mirror_link_result *res = parsed_result;
9724 	struct rte_eth_mirror_conf mr_conf;
9725 
9726 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9727 	if (!strcmp(res->what, "uplink-mirror"))
9728 		mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9729 	else
9730 		mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9731 
9732 	mr_conf.dst_pool = res->dstpool_id;
9733 
9734 	if (!strcmp(res->on, "on"))
9735 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9736 						res->rule_id, 1);
9737 	else
9738 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9739 						res->rule_id, 0);
9740 
9741 	/* check the return value and print it if is < 0 */
9742 	if (ret < 0)
9743 		printf("mirror rule add error: (%s)\n", strerror(-ret));
9744 
9745 }
9746 
9747 cmdline_parse_inst_t cmd_set_mirror_link = {
9748 		.f = cmd_set_mirror_link_parsed,
9749 		.data = NULL,
9750 		.help_str = "set port <port_id> mirror-rule <rule_id> "
9751 			"uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9752 		.tokens = {
9753 			(void *)&cmd_mirror_link_set,
9754 			(void *)&cmd_mirror_link_port,
9755 			(void *)&cmd_mirror_link_portid,
9756 			(void *)&cmd_mirror_link_mirror,
9757 			(void *)&cmd_mirror_link_ruleid,
9758 			(void *)&cmd_mirror_link_what,
9759 			(void *)&cmd_mirror_link_dstpool,
9760 			(void *)&cmd_mirror_link_poolid,
9761 			(void *)&cmd_mirror_link_on,
9762 			NULL,
9763 		},
9764 };
9765 
9766 /* *** RESET VM MIRROR RULE *** */
9767 struct cmd_rm_mirror_rule_result {
9768 	cmdline_fixed_string_t reset;
9769 	cmdline_fixed_string_t port;
9770 	portid_t port_id;
9771 	cmdline_fixed_string_t mirror;
9772 	uint8_t rule_id;
9773 };
9774 
9775 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9776 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9777 				 reset, "reset");
9778 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9779 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9780 				port, "port");
9781 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9782 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9783 				port_id, UINT16);
9784 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9785 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9786 				mirror, "mirror-rule");
9787 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9788 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9789 				rule_id, UINT8);
9790 
9791 static void
9792 cmd_reset_mirror_rule_parsed(void *parsed_result,
9793 		       __rte_unused struct cmdline *cl,
9794 		       __rte_unused void *data)
9795 {
9796 	int ret;
9797 	struct cmd_set_mirror_link_result *res = parsed_result;
9798         /* check rule_id */
9799 	ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9800 	if(ret < 0)
9801 		printf("mirror rule remove error: (%s)\n", strerror(-ret));
9802 }
9803 
9804 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9805 		.f = cmd_reset_mirror_rule_parsed,
9806 		.data = NULL,
9807 		.help_str = "reset port <port_id> mirror-rule <rule_id>",
9808 		.tokens = {
9809 			(void *)&cmd_rm_mirror_rule_reset,
9810 			(void *)&cmd_rm_mirror_rule_port,
9811 			(void *)&cmd_rm_mirror_rule_portid,
9812 			(void *)&cmd_rm_mirror_rule_mirror,
9813 			(void *)&cmd_rm_mirror_rule_ruleid,
9814 			NULL,
9815 		},
9816 };
9817 
9818 /* ******************************************************************************** */
9819 
9820 struct cmd_dump_result {
9821 	cmdline_fixed_string_t dump;
9822 };
9823 
9824 static void
9825 dump_struct_sizes(void)
9826 {
9827 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9828 	DUMP_SIZE(struct rte_mbuf);
9829 	DUMP_SIZE(struct rte_mempool);
9830 	DUMP_SIZE(struct rte_ring);
9831 #undef DUMP_SIZE
9832 }
9833 
9834 
9835 /* Dump the socket memory statistics on console */
9836 static void
9837 dump_socket_mem(FILE *f)
9838 {
9839 	struct rte_malloc_socket_stats socket_stats;
9840 	unsigned int i;
9841 	size_t total = 0;
9842 	size_t alloc = 0;
9843 	size_t free = 0;
9844 	unsigned int n_alloc = 0;
9845 	unsigned int n_free = 0;
9846 	static size_t last_allocs;
9847 	static size_t last_total;
9848 
9849 
9850 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9851 		if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9852 		    !socket_stats.heap_totalsz_bytes)
9853 			continue;
9854 		total += socket_stats.heap_totalsz_bytes;
9855 		alloc += socket_stats.heap_allocsz_bytes;
9856 		free += socket_stats.heap_freesz_bytes;
9857 		n_alloc += socket_stats.alloc_count;
9858 		n_free += socket_stats.free_count;
9859 		fprintf(f,
9860 			"Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9861 			i,
9862 			(double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9863 			(double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9864 			(double)socket_stats.heap_allocsz_bytes * 100 /
9865 			(double)socket_stats.heap_totalsz_bytes,
9866 			(double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9867 			socket_stats.alloc_count,
9868 			socket_stats.free_count);
9869 	}
9870 	fprintf(f,
9871 		"Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9872 		(double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9873 		(double)alloc * 100 / (double)total,
9874 		(double)free / (1024 * 1024),
9875 		n_alloc, n_free);
9876 	if (last_allocs)
9877 		fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9878 			((double)total - (double)last_total) / (1024 * 1024),
9879 			(double)(alloc - (double)last_allocs) / 1024 / 1024);
9880 	last_allocs = alloc;
9881 	last_total = total;
9882 }
9883 
9884 static void cmd_dump_parsed(void *parsed_result,
9885 			    __rte_unused struct cmdline *cl,
9886 			    __rte_unused void *data)
9887 {
9888 	struct cmd_dump_result *res = parsed_result;
9889 
9890 	if (!strcmp(res->dump, "dump_physmem"))
9891 		rte_dump_physmem_layout(stdout);
9892 	else if (!strcmp(res->dump, "dump_socket_mem"))
9893 		dump_socket_mem(stdout);
9894 	else if (!strcmp(res->dump, "dump_memzone"))
9895 		rte_memzone_dump(stdout);
9896 	else if (!strcmp(res->dump, "dump_struct_sizes"))
9897 		dump_struct_sizes();
9898 	else if (!strcmp(res->dump, "dump_ring"))
9899 		rte_ring_list_dump(stdout);
9900 	else if (!strcmp(res->dump, "dump_mempool"))
9901 		rte_mempool_list_dump(stdout);
9902 	else if (!strcmp(res->dump, "dump_devargs"))
9903 		rte_devargs_dump(stdout);
9904 	else if (!strcmp(res->dump, "dump_log_types"))
9905 		rte_log_dump(stdout);
9906 }
9907 
9908 cmdline_parse_token_string_t cmd_dump_dump =
9909 	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9910 		"dump_physmem#"
9911 		"dump_memzone#"
9912 		"dump_socket_mem#"
9913 		"dump_struct_sizes#"
9914 		"dump_ring#"
9915 		"dump_mempool#"
9916 		"dump_devargs#"
9917 		"dump_log_types");
9918 
9919 cmdline_parse_inst_t cmd_dump = {
9920 	.f = cmd_dump_parsed,  /* function to call */
9921 	.data = NULL,      /* 2nd arg of func */
9922 	.help_str = "Dump status",
9923 	.tokens = {        /* token list, NULL terminated */
9924 		(void *)&cmd_dump_dump,
9925 		NULL,
9926 	},
9927 };
9928 
9929 /* ******************************************************************************** */
9930 
9931 struct cmd_dump_one_result {
9932 	cmdline_fixed_string_t dump;
9933 	cmdline_fixed_string_t name;
9934 };
9935 
9936 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9937 				__rte_unused void *data)
9938 {
9939 	struct cmd_dump_one_result *res = parsed_result;
9940 
9941 	if (!strcmp(res->dump, "dump_ring")) {
9942 		struct rte_ring *r;
9943 		r = rte_ring_lookup(res->name);
9944 		if (r == NULL) {
9945 			cmdline_printf(cl, "Cannot find ring\n");
9946 			return;
9947 		}
9948 		rte_ring_dump(stdout, r);
9949 	} else if (!strcmp(res->dump, "dump_mempool")) {
9950 		struct rte_mempool *mp;
9951 		mp = rte_mempool_lookup(res->name);
9952 		if (mp == NULL) {
9953 			cmdline_printf(cl, "Cannot find mempool\n");
9954 			return;
9955 		}
9956 		rte_mempool_dump(stdout, mp);
9957 	}
9958 }
9959 
9960 cmdline_parse_token_string_t cmd_dump_one_dump =
9961 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9962 				 "dump_ring#dump_mempool");
9963 
9964 cmdline_parse_token_string_t cmd_dump_one_name =
9965 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9966 
9967 cmdline_parse_inst_t cmd_dump_one = {
9968 	.f = cmd_dump_one_parsed,  /* function to call */
9969 	.data = NULL,      /* 2nd arg of func */
9970 	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9971 	.tokens = {        /* token list, NULL terminated */
9972 		(void *)&cmd_dump_one_dump,
9973 		(void *)&cmd_dump_one_name,
9974 		NULL,
9975 	},
9976 };
9977 
9978 /* *** Add/Del syn filter *** */
9979 struct cmd_syn_filter_result {
9980 	cmdline_fixed_string_t filter;
9981 	portid_t port_id;
9982 	cmdline_fixed_string_t ops;
9983 	cmdline_fixed_string_t priority;
9984 	cmdline_fixed_string_t high;
9985 	cmdline_fixed_string_t queue;
9986 	uint16_t queue_id;
9987 };
9988 
9989 static void
9990 cmd_syn_filter_parsed(void *parsed_result,
9991 			__rte_unused struct cmdline *cl,
9992 			__rte_unused void *data)
9993 {
9994 	struct cmd_syn_filter_result *res = parsed_result;
9995 	struct rte_eth_syn_filter syn_filter;
9996 	int ret = 0;
9997 
9998 	ret = rte_eth_dev_filter_supported(res->port_id,
9999 					RTE_ETH_FILTER_SYN);
10000 	if (ret < 0) {
10001 		printf("syn filter is not supported on port %u.\n",
10002 				res->port_id);
10003 		return;
10004 	}
10005 
10006 	memset(&syn_filter, 0, sizeof(syn_filter));
10007 
10008 	if (!strcmp(res->ops, "add")) {
10009 		if (!strcmp(res->high, "high"))
10010 			syn_filter.hig_pri = 1;
10011 		else
10012 			syn_filter.hig_pri = 0;
10013 
10014 		syn_filter.queue = res->queue_id;
10015 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10016 						RTE_ETH_FILTER_SYN,
10017 						RTE_ETH_FILTER_ADD,
10018 						&syn_filter);
10019 	} else
10020 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10021 						RTE_ETH_FILTER_SYN,
10022 						RTE_ETH_FILTER_DELETE,
10023 						&syn_filter);
10024 
10025 	if (ret < 0)
10026 		printf("syn filter programming error: (%s)\n",
10027 				strerror(-ret));
10028 }
10029 
10030 cmdline_parse_token_string_t cmd_syn_filter_filter =
10031 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10032 	filter, "syn_filter");
10033 cmdline_parse_token_num_t cmd_syn_filter_port_id =
10034 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10035 	port_id, UINT16);
10036 cmdline_parse_token_string_t cmd_syn_filter_ops =
10037 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10038 	ops, "add#del");
10039 cmdline_parse_token_string_t cmd_syn_filter_priority =
10040 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10041 				priority, "priority");
10042 cmdline_parse_token_string_t cmd_syn_filter_high =
10043 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10044 				high, "high#low");
10045 cmdline_parse_token_string_t cmd_syn_filter_queue =
10046 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10047 				queue, "queue");
10048 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
10049 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10050 				queue_id, UINT16);
10051 
10052 cmdline_parse_inst_t cmd_syn_filter = {
10053 	.f = cmd_syn_filter_parsed,
10054 	.data = NULL,
10055 	.help_str = "syn_filter <port_id> add|del priority high|low queue "
10056 		"<queue_id>: Add/Delete syn filter",
10057 	.tokens = {
10058 		(void *)&cmd_syn_filter_filter,
10059 		(void *)&cmd_syn_filter_port_id,
10060 		(void *)&cmd_syn_filter_ops,
10061 		(void *)&cmd_syn_filter_priority,
10062 		(void *)&cmd_syn_filter_high,
10063 		(void *)&cmd_syn_filter_queue,
10064 		(void *)&cmd_syn_filter_queue_id,
10065 		NULL,
10066 	},
10067 };
10068 
10069 /* *** queue region set *** */
10070 struct cmd_queue_region_result {
10071 	cmdline_fixed_string_t set;
10072 	cmdline_fixed_string_t port;
10073 	portid_t port_id;
10074 	cmdline_fixed_string_t cmd;
10075 	cmdline_fixed_string_t region;
10076 	uint8_t  region_id;
10077 	cmdline_fixed_string_t queue_start_index;
10078 	uint8_t  queue_id;
10079 	cmdline_fixed_string_t queue_num;
10080 	uint8_t  queue_num_value;
10081 };
10082 
10083 static void
10084 cmd_queue_region_parsed(void *parsed_result,
10085 			__rte_unused struct cmdline *cl,
10086 			__rte_unused void *data)
10087 {
10088 	struct cmd_queue_region_result *res = parsed_result;
10089 	int ret = -ENOTSUP;
10090 #ifdef RTE_LIBRTE_I40E_PMD
10091 	struct rte_pmd_i40e_queue_region_conf region_conf;
10092 	enum rte_pmd_i40e_queue_region_op op_type;
10093 #endif
10094 
10095 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10096 		return;
10097 
10098 #ifdef RTE_LIBRTE_I40E_PMD
10099 	memset(&region_conf, 0, sizeof(region_conf));
10100 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10101 	region_conf.region_id = res->region_id;
10102 	region_conf.queue_num = res->queue_num_value;
10103 	region_conf.queue_start_index = res->queue_id;
10104 
10105 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10106 				op_type, &region_conf);
10107 #endif
10108 
10109 	switch (ret) {
10110 	case 0:
10111 		break;
10112 	case -ENOTSUP:
10113 		printf("function not implemented or supported\n");
10114 		break;
10115 	default:
10116 		printf("queue region config error: (%s)\n", strerror(-ret));
10117 	}
10118 }
10119 
10120 cmdline_parse_token_string_t cmd_queue_region_set =
10121 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10122 		set, "set");
10123 cmdline_parse_token_string_t cmd_queue_region_port =
10124 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10125 cmdline_parse_token_num_t cmd_queue_region_port_id =
10126 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10127 				port_id, UINT16);
10128 cmdline_parse_token_string_t cmd_queue_region_cmd =
10129 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10130 				 cmd, "queue-region");
10131 cmdline_parse_token_string_t cmd_queue_region_id =
10132 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10133 				region, "region_id");
10134 cmdline_parse_token_num_t cmd_queue_region_index =
10135 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10136 				region_id, UINT8);
10137 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10138 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10139 				queue_start_index, "queue_start_index");
10140 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10141 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10142 				queue_id, UINT8);
10143 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10144 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10145 				queue_num, "queue_num");
10146 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10147 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10148 				queue_num_value, UINT8);
10149 
10150 cmdline_parse_inst_t cmd_queue_region = {
10151 	.f = cmd_queue_region_parsed,
10152 	.data = NULL,
10153 	.help_str = "set port <port_id> queue-region region_id <value> "
10154 		"queue_start_index <value> queue_num <value>: Set a queue region",
10155 	.tokens = {
10156 		(void *)&cmd_queue_region_set,
10157 		(void *)&cmd_queue_region_port,
10158 		(void *)&cmd_queue_region_port_id,
10159 		(void *)&cmd_queue_region_cmd,
10160 		(void *)&cmd_queue_region_id,
10161 		(void *)&cmd_queue_region_index,
10162 		(void *)&cmd_queue_region_queue_start_index,
10163 		(void *)&cmd_queue_region_queue_id,
10164 		(void *)&cmd_queue_region_queue_num,
10165 		(void *)&cmd_queue_region_queue_num_value,
10166 		NULL,
10167 	},
10168 };
10169 
10170 /* *** queue region and flowtype set *** */
10171 struct cmd_region_flowtype_result {
10172 	cmdline_fixed_string_t set;
10173 	cmdline_fixed_string_t port;
10174 	portid_t port_id;
10175 	cmdline_fixed_string_t cmd;
10176 	cmdline_fixed_string_t region;
10177 	uint8_t  region_id;
10178 	cmdline_fixed_string_t flowtype;
10179 	uint8_t  flowtype_id;
10180 };
10181 
10182 static void
10183 cmd_region_flowtype_parsed(void *parsed_result,
10184 			__rte_unused struct cmdline *cl,
10185 			__rte_unused void *data)
10186 {
10187 	struct cmd_region_flowtype_result *res = parsed_result;
10188 	int ret = -ENOTSUP;
10189 #ifdef RTE_LIBRTE_I40E_PMD
10190 	struct rte_pmd_i40e_queue_region_conf region_conf;
10191 	enum rte_pmd_i40e_queue_region_op op_type;
10192 #endif
10193 
10194 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10195 		return;
10196 
10197 #ifdef RTE_LIBRTE_I40E_PMD
10198 	memset(&region_conf, 0, sizeof(region_conf));
10199 
10200 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10201 	region_conf.region_id = res->region_id;
10202 	region_conf.hw_flowtype = res->flowtype_id;
10203 
10204 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10205 			op_type, &region_conf);
10206 #endif
10207 
10208 	switch (ret) {
10209 	case 0:
10210 		break;
10211 	case -ENOTSUP:
10212 		printf("function not implemented or supported\n");
10213 		break;
10214 	default:
10215 		printf("region flowtype config error: (%s)\n", strerror(-ret));
10216 	}
10217 }
10218 
10219 cmdline_parse_token_string_t cmd_region_flowtype_set =
10220 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10221 				set, "set");
10222 cmdline_parse_token_string_t cmd_region_flowtype_port =
10223 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10224 				port, "port");
10225 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10226 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10227 				port_id, UINT16);
10228 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10229 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10230 				cmd, "queue-region");
10231 cmdline_parse_token_string_t cmd_region_flowtype_index =
10232 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10233 				region, "region_id");
10234 cmdline_parse_token_num_t cmd_region_flowtype_id =
10235 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10236 				region_id, UINT8);
10237 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10238 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10239 				flowtype, "flowtype");
10240 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10241 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10242 				flowtype_id, UINT8);
10243 cmdline_parse_inst_t cmd_region_flowtype = {
10244 	.f = cmd_region_flowtype_parsed,
10245 	.data = NULL,
10246 	.help_str = "set port <port_id> queue-region region_id <value> "
10247 		"flowtype <value>: Set a flowtype region index",
10248 	.tokens = {
10249 		(void *)&cmd_region_flowtype_set,
10250 		(void *)&cmd_region_flowtype_port,
10251 		(void *)&cmd_region_flowtype_port_index,
10252 		(void *)&cmd_region_flowtype_cmd,
10253 		(void *)&cmd_region_flowtype_index,
10254 		(void *)&cmd_region_flowtype_id,
10255 		(void *)&cmd_region_flowtype_flow_index,
10256 		(void *)&cmd_region_flowtype_flow_id,
10257 		NULL,
10258 	},
10259 };
10260 
10261 /* *** User Priority (UP) to queue region (region_id) set *** */
10262 struct cmd_user_priority_region_result {
10263 	cmdline_fixed_string_t set;
10264 	cmdline_fixed_string_t port;
10265 	portid_t port_id;
10266 	cmdline_fixed_string_t cmd;
10267 	cmdline_fixed_string_t user_priority;
10268 	uint8_t  user_priority_id;
10269 	cmdline_fixed_string_t region;
10270 	uint8_t  region_id;
10271 };
10272 
10273 static void
10274 cmd_user_priority_region_parsed(void *parsed_result,
10275 			__rte_unused struct cmdline *cl,
10276 			__rte_unused void *data)
10277 {
10278 	struct cmd_user_priority_region_result *res = parsed_result;
10279 	int ret = -ENOTSUP;
10280 #ifdef RTE_LIBRTE_I40E_PMD
10281 	struct rte_pmd_i40e_queue_region_conf region_conf;
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(&region_conf, 0, sizeof(region_conf));
10290 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10291 	region_conf.user_priority = res->user_priority_id;
10292 	region_conf.region_id = res->region_id;
10293 
10294 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10295 				op_type, &region_conf);
10296 #endif
10297 
10298 	switch (ret) {
10299 	case 0:
10300 		break;
10301 	case -ENOTSUP:
10302 		printf("function not implemented or supported\n");
10303 		break;
10304 	default:
10305 		printf("user_priority region config error: (%s)\n",
10306 				strerror(-ret));
10307 	}
10308 }
10309 
10310 cmdline_parse_token_string_t cmd_user_priority_region_set =
10311 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10312 				set, "set");
10313 cmdline_parse_token_string_t cmd_user_priority_region_port =
10314 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10315 				port, "port");
10316 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10317 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10318 				port_id, UINT16);
10319 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10320 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10321 				cmd, "queue-region");
10322 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10323 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10324 				user_priority, "UP");
10325 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10326 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10327 				user_priority_id, UINT8);
10328 cmdline_parse_token_string_t cmd_user_priority_region_region =
10329 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10330 				region, "region_id");
10331 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10332 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10333 				region_id, UINT8);
10334 
10335 cmdline_parse_inst_t cmd_user_priority_region = {
10336 	.f = cmd_user_priority_region_parsed,
10337 	.data = NULL,
10338 	.help_str = "set port <port_id> queue-region UP <value> "
10339 		"region_id <value>: Set the mapping of User Priority (UP) "
10340 		"to queue region (region_id) ",
10341 	.tokens = {
10342 		(void *)&cmd_user_priority_region_set,
10343 		(void *)&cmd_user_priority_region_port,
10344 		(void *)&cmd_user_priority_region_port_index,
10345 		(void *)&cmd_user_priority_region_cmd,
10346 		(void *)&cmd_user_priority_region_UP,
10347 		(void *)&cmd_user_priority_region_UP_id,
10348 		(void *)&cmd_user_priority_region_region,
10349 		(void *)&cmd_user_priority_region_region_id,
10350 		NULL,
10351 	},
10352 };
10353 
10354 /* *** flush all queue region related configuration *** */
10355 struct cmd_flush_queue_region_result {
10356 	cmdline_fixed_string_t set;
10357 	cmdline_fixed_string_t port;
10358 	portid_t port_id;
10359 	cmdline_fixed_string_t cmd;
10360 	cmdline_fixed_string_t flush;
10361 	cmdline_fixed_string_t what;
10362 };
10363 
10364 static void
10365 cmd_flush_queue_region_parsed(void *parsed_result,
10366 			__rte_unused struct cmdline *cl,
10367 			__rte_unused void *data)
10368 {
10369 	struct cmd_flush_queue_region_result *res = parsed_result;
10370 	int ret = -ENOTSUP;
10371 #ifdef RTE_LIBRTE_I40E_PMD
10372 	struct rte_pmd_i40e_queue_region_conf region_conf;
10373 	enum rte_pmd_i40e_queue_region_op op_type;
10374 #endif
10375 
10376 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10377 		return;
10378 
10379 #ifdef RTE_LIBRTE_I40E_PMD
10380 	memset(&region_conf, 0, sizeof(region_conf));
10381 
10382 	if (strcmp(res->what, "on") == 0)
10383 		op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10384 	else
10385 		op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10386 
10387 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10388 				op_type, &region_conf);
10389 #endif
10390 
10391 	switch (ret) {
10392 	case 0:
10393 		break;
10394 	case -ENOTSUP:
10395 		printf("function not implemented or supported\n");
10396 		break;
10397 	default:
10398 		printf("queue region config flush error: (%s)\n",
10399 				strerror(-ret));
10400 	}
10401 }
10402 
10403 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10404 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10405 				set, "set");
10406 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10407 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10408 				port, "port");
10409 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10410 	TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10411 				port_id, UINT16);
10412 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10413 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10414 				cmd, "queue-region");
10415 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10416 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10417 				flush, "flush");
10418 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10419 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10420 				what, "on#off");
10421 
10422 cmdline_parse_inst_t cmd_flush_queue_region = {
10423 	.f = cmd_flush_queue_region_parsed,
10424 	.data = NULL,
10425 	.help_str = "set port <port_id> queue-region flush on|off"
10426 		": flush all queue region related configuration",
10427 	.tokens = {
10428 		(void *)&cmd_flush_queue_region_set,
10429 		(void *)&cmd_flush_queue_region_port,
10430 		(void *)&cmd_flush_queue_region_port_index,
10431 		(void *)&cmd_flush_queue_region_cmd,
10432 		(void *)&cmd_flush_queue_region_flush,
10433 		(void *)&cmd_flush_queue_region_what,
10434 		NULL,
10435 	},
10436 };
10437 
10438 /* *** get all queue region related configuration info *** */
10439 struct cmd_show_queue_region_info {
10440 	cmdline_fixed_string_t show;
10441 	cmdline_fixed_string_t port;
10442 	portid_t port_id;
10443 	cmdline_fixed_string_t cmd;
10444 };
10445 
10446 static void
10447 cmd_show_queue_region_info_parsed(void *parsed_result,
10448 			__rte_unused struct cmdline *cl,
10449 			__rte_unused void *data)
10450 {
10451 	struct cmd_show_queue_region_info *res = parsed_result;
10452 	int ret = -ENOTSUP;
10453 #ifdef RTE_LIBRTE_I40E_PMD
10454 	struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10455 	enum rte_pmd_i40e_queue_region_op op_type;
10456 #endif
10457 
10458 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10459 		return;
10460 
10461 #ifdef RTE_LIBRTE_I40E_PMD
10462 	memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10463 
10464 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10465 
10466 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10467 					op_type, &rte_pmd_regions);
10468 
10469 	port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10470 #endif
10471 
10472 	switch (ret) {
10473 	case 0:
10474 		break;
10475 	case -ENOTSUP:
10476 		printf("function not implemented or supported\n");
10477 		break;
10478 	default:
10479 		printf("queue region config info show error: (%s)\n",
10480 				strerror(-ret));
10481 	}
10482 }
10483 
10484 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10485 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10486 				show, "show");
10487 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10488 	TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10489 				port, "port");
10490 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10491 	TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10492 				port_id, UINT16);
10493 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10494 	TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10495 				cmd, "queue-region");
10496 
10497 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10498 	.f = cmd_show_queue_region_info_parsed,
10499 	.data = NULL,
10500 	.help_str = "show port <port_id> queue-region"
10501 		": show all queue region related configuration info",
10502 	.tokens = {
10503 		(void *)&cmd_show_queue_region_info_get,
10504 		(void *)&cmd_show_queue_region_info_port,
10505 		(void *)&cmd_show_queue_region_info_port_index,
10506 		(void *)&cmd_show_queue_region_info_cmd,
10507 		NULL,
10508 	},
10509 };
10510 
10511 /* *** ADD/REMOVE A 2tuple FILTER *** */
10512 struct cmd_2tuple_filter_result {
10513 	cmdline_fixed_string_t filter;
10514 	portid_t port_id;
10515 	cmdline_fixed_string_t ops;
10516 	cmdline_fixed_string_t dst_port;
10517 	uint16_t dst_port_value;
10518 	cmdline_fixed_string_t protocol;
10519 	uint8_t protocol_value;
10520 	cmdline_fixed_string_t mask;
10521 	uint8_t  mask_value;
10522 	cmdline_fixed_string_t tcp_flags;
10523 	uint8_t tcp_flags_value;
10524 	cmdline_fixed_string_t priority;
10525 	uint8_t  priority_value;
10526 	cmdline_fixed_string_t queue;
10527 	uint16_t  queue_id;
10528 };
10529 
10530 static void
10531 cmd_2tuple_filter_parsed(void *parsed_result,
10532 			__rte_unused struct cmdline *cl,
10533 			__rte_unused void *data)
10534 {
10535 	struct rte_eth_ntuple_filter filter;
10536 	struct cmd_2tuple_filter_result *res = parsed_result;
10537 	int ret = 0;
10538 
10539 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10540 	if (ret < 0) {
10541 		printf("ntuple filter is not supported on port %u.\n",
10542 			res->port_id);
10543 		return;
10544 	}
10545 
10546 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10547 
10548 	filter.flags = RTE_2TUPLE_FLAGS;
10549 	filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10550 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10551 	filter.proto = res->protocol_value;
10552 	filter.priority = res->priority_value;
10553 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10554 		printf("nonzero tcp_flags is only meaningful"
10555 			" when protocol is TCP.\n");
10556 		return;
10557 	}
10558 	if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10559 		printf("invalid TCP flags.\n");
10560 		return;
10561 	}
10562 
10563 	if (res->tcp_flags_value != 0) {
10564 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10565 		filter.tcp_flags = res->tcp_flags_value;
10566 	}
10567 
10568 	/* need convert to big endian. */
10569 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10570 	filter.queue = res->queue_id;
10571 
10572 	if (!strcmp(res->ops, "add"))
10573 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10574 				RTE_ETH_FILTER_NTUPLE,
10575 				RTE_ETH_FILTER_ADD,
10576 				&filter);
10577 	else
10578 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10579 				RTE_ETH_FILTER_NTUPLE,
10580 				RTE_ETH_FILTER_DELETE,
10581 				&filter);
10582 	if (ret < 0)
10583 		printf("2tuple filter programming error: (%s)\n",
10584 			strerror(-ret));
10585 
10586 }
10587 
10588 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10589 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10590 				 filter, "2tuple_filter");
10591 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10592 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10593 				port_id, UINT16);
10594 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10595 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10596 				 ops, "add#del");
10597 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10598 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10599 				dst_port, "dst_port");
10600 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10601 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10602 				dst_port_value, UINT16);
10603 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10604 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10605 				protocol, "protocol");
10606 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10607 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10608 				protocol_value, UINT8);
10609 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10610 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10611 				mask, "mask");
10612 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10613 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10614 				mask_value, INT8);
10615 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10616 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10617 				tcp_flags, "tcp_flags");
10618 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10619 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10620 				tcp_flags_value, UINT8);
10621 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10622 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10623 				priority, "priority");
10624 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10625 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10626 				priority_value, UINT8);
10627 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10628 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10629 				queue, "queue");
10630 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10631 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10632 				queue_id, UINT16);
10633 
10634 cmdline_parse_inst_t cmd_2tuple_filter = {
10635 	.f = cmd_2tuple_filter_parsed,
10636 	.data = NULL,
10637 	.help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10638 		"<value> mask <value> tcp_flags <value> priority <value> queue "
10639 		"<queue_id>: Add a 2tuple filter",
10640 	.tokens = {
10641 		(void *)&cmd_2tuple_filter_filter,
10642 		(void *)&cmd_2tuple_filter_port_id,
10643 		(void *)&cmd_2tuple_filter_ops,
10644 		(void *)&cmd_2tuple_filter_dst_port,
10645 		(void *)&cmd_2tuple_filter_dst_port_value,
10646 		(void *)&cmd_2tuple_filter_protocol,
10647 		(void *)&cmd_2tuple_filter_protocol_value,
10648 		(void *)&cmd_2tuple_filter_mask,
10649 		(void *)&cmd_2tuple_filter_mask_value,
10650 		(void *)&cmd_2tuple_filter_tcp_flags,
10651 		(void *)&cmd_2tuple_filter_tcp_flags_value,
10652 		(void *)&cmd_2tuple_filter_priority,
10653 		(void *)&cmd_2tuple_filter_priority_value,
10654 		(void *)&cmd_2tuple_filter_queue,
10655 		(void *)&cmd_2tuple_filter_queue_id,
10656 		NULL,
10657 	},
10658 };
10659 
10660 /* *** ADD/REMOVE A 5tuple FILTER *** */
10661 struct cmd_5tuple_filter_result {
10662 	cmdline_fixed_string_t filter;
10663 	portid_t port_id;
10664 	cmdline_fixed_string_t ops;
10665 	cmdline_fixed_string_t dst_ip;
10666 	cmdline_ipaddr_t dst_ip_value;
10667 	cmdline_fixed_string_t src_ip;
10668 	cmdline_ipaddr_t src_ip_value;
10669 	cmdline_fixed_string_t dst_port;
10670 	uint16_t dst_port_value;
10671 	cmdline_fixed_string_t src_port;
10672 	uint16_t src_port_value;
10673 	cmdline_fixed_string_t protocol;
10674 	uint8_t protocol_value;
10675 	cmdline_fixed_string_t mask;
10676 	uint8_t  mask_value;
10677 	cmdline_fixed_string_t tcp_flags;
10678 	uint8_t tcp_flags_value;
10679 	cmdline_fixed_string_t priority;
10680 	uint8_t  priority_value;
10681 	cmdline_fixed_string_t queue;
10682 	uint16_t  queue_id;
10683 };
10684 
10685 static void
10686 cmd_5tuple_filter_parsed(void *parsed_result,
10687 			__rte_unused struct cmdline *cl,
10688 			__rte_unused void *data)
10689 {
10690 	struct rte_eth_ntuple_filter filter;
10691 	struct cmd_5tuple_filter_result *res = parsed_result;
10692 	int ret = 0;
10693 
10694 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10695 	if (ret < 0) {
10696 		printf("ntuple filter is not supported on port %u.\n",
10697 			res->port_id);
10698 		return;
10699 	}
10700 
10701 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10702 
10703 	filter.flags = RTE_5TUPLE_FLAGS;
10704 	filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10705 	filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10706 	filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10707 	filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10708 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10709 	filter.proto = res->protocol_value;
10710 	filter.priority = res->priority_value;
10711 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10712 		printf("nonzero tcp_flags is only meaningful"
10713 			" when protocol is TCP.\n");
10714 		return;
10715 	}
10716 	if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10717 		printf("invalid TCP flags.\n");
10718 		return;
10719 	}
10720 
10721 	if (res->tcp_flags_value != 0) {
10722 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10723 		filter.tcp_flags = res->tcp_flags_value;
10724 	}
10725 
10726 	if (res->dst_ip_value.family == AF_INET)
10727 		/* no need to convert, already big endian. */
10728 		filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10729 	else {
10730 		if (filter.dst_ip_mask == 0) {
10731 			printf("can not support ipv6 involved compare.\n");
10732 			return;
10733 		}
10734 		filter.dst_ip = 0;
10735 	}
10736 
10737 	if (res->src_ip_value.family == AF_INET)
10738 		/* no need to convert, already big endian. */
10739 		filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10740 	else {
10741 		if (filter.src_ip_mask == 0) {
10742 			printf("can not support ipv6 involved compare.\n");
10743 			return;
10744 		}
10745 		filter.src_ip = 0;
10746 	}
10747 	/* need convert to big endian. */
10748 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10749 	filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10750 	filter.queue = res->queue_id;
10751 
10752 	if (!strcmp(res->ops, "add"))
10753 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10754 				RTE_ETH_FILTER_NTUPLE,
10755 				RTE_ETH_FILTER_ADD,
10756 				&filter);
10757 	else
10758 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10759 				RTE_ETH_FILTER_NTUPLE,
10760 				RTE_ETH_FILTER_DELETE,
10761 				&filter);
10762 	if (ret < 0)
10763 		printf("5tuple filter programming error: (%s)\n",
10764 			strerror(-ret));
10765 }
10766 
10767 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10768 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10769 				 filter, "5tuple_filter");
10770 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10771 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10772 				port_id, UINT16);
10773 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10774 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10775 				 ops, "add#del");
10776 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10777 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10778 				dst_ip, "dst_ip");
10779 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10780 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10781 				dst_ip_value);
10782 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10783 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10784 				src_ip, "src_ip");
10785 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10786 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10787 				src_ip_value);
10788 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10789 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10790 				dst_port, "dst_port");
10791 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10792 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10793 				dst_port_value, UINT16);
10794 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10795 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10796 				src_port, "src_port");
10797 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10798 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10799 				src_port_value, UINT16);
10800 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10801 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10802 				protocol, "protocol");
10803 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10804 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10805 				protocol_value, UINT8);
10806 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10807 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10808 				mask, "mask");
10809 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10810 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10811 				mask_value, INT8);
10812 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10813 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10814 				tcp_flags, "tcp_flags");
10815 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10816 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10817 				tcp_flags_value, UINT8);
10818 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10819 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10820 				priority, "priority");
10821 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10822 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10823 				priority_value, UINT8);
10824 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10825 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10826 				queue, "queue");
10827 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10828 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10829 				queue_id, UINT16);
10830 
10831 cmdline_parse_inst_t cmd_5tuple_filter = {
10832 	.f = cmd_5tuple_filter_parsed,
10833 	.data = NULL,
10834 	.help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10835 		"src_ip <value> dst_port <value> src_port <value> "
10836 		"protocol <value>  mask <value> tcp_flags <value> "
10837 		"priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10838 	.tokens = {
10839 		(void *)&cmd_5tuple_filter_filter,
10840 		(void *)&cmd_5tuple_filter_port_id,
10841 		(void *)&cmd_5tuple_filter_ops,
10842 		(void *)&cmd_5tuple_filter_dst_ip,
10843 		(void *)&cmd_5tuple_filter_dst_ip_value,
10844 		(void *)&cmd_5tuple_filter_src_ip,
10845 		(void *)&cmd_5tuple_filter_src_ip_value,
10846 		(void *)&cmd_5tuple_filter_dst_port,
10847 		(void *)&cmd_5tuple_filter_dst_port_value,
10848 		(void *)&cmd_5tuple_filter_src_port,
10849 		(void *)&cmd_5tuple_filter_src_port_value,
10850 		(void *)&cmd_5tuple_filter_protocol,
10851 		(void *)&cmd_5tuple_filter_protocol_value,
10852 		(void *)&cmd_5tuple_filter_mask,
10853 		(void *)&cmd_5tuple_filter_mask_value,
10854 		(void *)&cmd_5tuple_filter_tcp_flags,
10855 		(void *)&cmd_5tuple_filter_tcp_flags_value,
10856 		(void *)&cmd_5tuple_filter_priority,
10857 		(void *)&cmd_5tuple_filter_priority_value,
10858 		(void *)&cmd_5tuple_filter_queue,
10859 		(void *)&cmd_5tuple_filter_queue_id,
10860 		NULL,
10861 	},
10862 };
10863 
10864 /* *** ADD/REMOVE A flex FILTER *** */
10865 struct cmd_flex_filter_result {
10866 	cmdline_fixed_string_t filter;
10867 	cmdline_fixed_string_t ops;
10868 	portid_t port_id;
10869 	cmdline_fixed_string_t len;
10870 	uint8_t len_value;
10871 	cmdline_fixed_string_t bytes;
10872 	cmdline_fixed_string_t bytes_value;
10873 	cmdline_fixed_string_t mask;
10874 	cmdline_fixed_string_t mask_value;
10875 	cmdline_fixed_string_t priority;
10876 	uint8_t priority_value;
10877 	cmdline_fixed_string_t queue;
10878 	uint16_t queue_id;
10879 };
10880 
10881 static int xdigit2val(unsigned char c)
10882 {
10883 	int val;
10884 	if (isdigit(c))
10885 		val = c - '0';
10886 	else if (isupper(c))
10887 		val = c - 'A' + 10;
10888 	else
10889 		val = c - 'a' + 10;
10890 	return val;
10891 }
10892 
10893 static void
10894 cmd_flex_filter_parsed(void *parsed_result,
10895 			  __rte_unused struct cmdline *cl,
10896 			  __rte_unused void *data)
10897 {
10898 	int ret = 0;
10899 	struct rte_eth_flex_filter filter;
10900 	struct cmd_flex_filter_result *res = parsed_result;
10901 	char *bytes_ptr, *mask_ptr;
10902 	uint16_t len, i, j = 0;
10903 	char c;
10904 	int val;
10905 	uint8_t byte = 0;
10906 
10907 	if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10908 		printf("the len exceed the max length 128\n");
10909 		return;
10910 	}
10911 	memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10912 	filter.len = res->len_value;
10913 	filter.priority = res->priority_value;
10914 	filter.queue = res->queue_id;
10915 	bytes_ptr = res->bytes_value;
10916 	mask_ptr = res->mask_value;
10917 
10918 	 /* translate bytes string to array. */
10919 	if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10920 		(bytes_ptr[1] == 'X')))
10921 		bytes_ptr += 2;
10922 	len = strnlen(bytes_ptr, res->len_value * 2);
10923 	if (len == 0 || (len % 8 != 0)) {
10924 		printf("please check len and bytes input\n");
10925 		return;
10926 	}
10927 	for (i = 0; i < len; i++) {
10928 		c = bytes_ptr[i];
10929 		if (isxdigit(c) == 0) {
10930 			/* invalid characters. */
10931 			printf("invalid input\n");
10932 			return;
10933 		}
10934 		val = xdigit2val(c);
10935 		if (i % 2) {
10936 			byte |= val;
10937 			filter.bytes[j] = byte;
10938 			printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10939 			j++;
10940 			byte = 0;
10941 		} else
10942 			byte |= val << 4;
10943 	}
10944 	printf("\n");
10945 	 /* translate mask string to uint8_t array. */
10946 	if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10947 		(mask_ptr[1] == 'X')))
10948 		mask_ptr += 2;
10949 	len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10950 	if (len == 0) {
10951 		printf("invalid input\n");
10952 		return;
10953 	}
10954 	j = 0;
10955 	byte = 0;
10956 	for (i = 0; i < len; i++) {
10957 		c = mask_ptr[i];
10958 		if (isxdigit(c) == 0) {
10959 			/* invalid characters. */
10960 			printf("invalid input\n");
10961 			return;
10962 		}
10963 		val = xdigit2val(c);
10964 		if (i % 2) {
10965 			byte |= val;
10966 			filter.mask[j] = byte;
10967 			printf("mask[%d]:%02x ", j, filter.mask[j]);
10968 			j++;
10969 			byte = 0;
10970 		} else
10971 			byte |= val << 4;
10972 	}
10973 	printf("\n");
10974 
10975 	if (!strcmp(res->ops, "add"))
10976 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10977 				RTE_ETH_FILTER_FLEXIBLE,
10978 				RTE_ETH_FILTER_ADD,
10979 				&filter);
10980 	else
10981 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10982 				RTE_ETH_FILTER_FLEXIBLE,
10983 				RTE_ETH_FILTER_DELETE,
10984 				&filter);
10985 
10986 	if (ret < 0)
10987 		printf("flex filter setting error: (%s)\n", strerror(-ret));
10988 }
10989 
10990 cmdline_parse_token_string_t cmd_flex_filter_filter =
10991 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10992 				filter, "flex_filter");
10993 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10994 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10995 				port_id, UINT16);
10996 cmdline_parse_token_string_t cmd_flex_filter_ops =
10997 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10998 				ops, "add#del");
10999 cmdline_parse_token_string_t cmd_flex_filter_len =
11000 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11001 				len, "len");
11002 cmdline_parse_token_num_t cmd_flex_filter_len_value =
11003 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11004 				len_value, UINT8);
11005 cmdline_parse_token_string_t cmd_flex_filter_bytes =
11006 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11007 				bytes, "bytes");
11008 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
11009 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11010 				bytes_value, NULL);
11011 cmdline_parse_token_string_t cmd_flex_filter_mask =
11012 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11013 				mask, "mask");
11014 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
11015 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11016 				mask_value, NULL);
11017 cmdline_parse_token_string_t cmd_flex_filter_priority =
11018 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11019 				priority, "priority");
11020 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
11021 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11022 				priority_value, UINT8);
11023 cmdline_parse_token_string_t cmd_flex_filter_queue =
11024 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11025 				queue, "queue");
11026 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
11027 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11028 				queue_id, UINT16);
11029 cmdline_parse_inst_t cmd_flex_filter = {
11030 	.f = cmd_flex_filter_parsed,
11031 	.data = NULL,
11032 	.help_str = "flex_filter <port_id> add|del len <value> bytes "
11033 		"<value> mask <value> priority <value> queue <queue_id>: "
11034 		"Add/Del a flex filter",
11035 	.tokens = {
11036 		(void *)&cmd_flex_filter_filter,
11037 		(void *)&cmd_flex_filter_port_id,
11038 		(void *)&cmd_flex_filter_ops,
11039 		(void *)&cmd_flex_filter_len,
11040 		(void *)&cmd_flex_filter_len_value,
11041 		(void *)&cmd_flex_filter_bytes,
11042 		(void *)&cmd_flex_filter_bytes_value,
11043 		(void *)&cmd_flex_filter_mask,
11044 		(void *)&cmd_flex_filter_mask_value,
11045 		(void *)&cmd_flex_filter_priority,
11046 		(void *)&cmd_flex_filter_priority_value,
11047 		(void *)&cmd_flex_filter_queue,
11048 		(void *)&cmd_flex_filter_queue_id,
11049 		NULL,
11050 	},
11051 };
11052 
11053 /* *** Filters Control *** */
11054 
11055 /* *** deal with ethertype filter *** */
11056 struct cmd_ethertype_filter_result {
11057 	cmdline_fixed_string_t filter;
11058 	portid_t port_id;
11059 	cmdline_fixed_string_t ops;
11060 	cmdline_fixed_string_t mac;
11061 	struct rte_ether_addr mac_addr;
11062 	cmdline_fixed_string_t ethertype;
11063 	uint16_t ethertype_value;
11064 	cmdline_fixed_string_t drop;
11065 	cmdline_fixed_string_t queue;
11066 	uint16_t  queue_id;
11067 };
11068 
11069 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
11070 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11071 				 filter, "ethertype_filter");
11072 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
11073 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11074 			      port_id, UINT16);
11075 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
11076 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11077 				 ops, "add#del");
11078 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
11079 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11080 				 mac, "mac_addr#mac_ignr");
11081 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
11082 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
11083 				     mac_addr);
11084 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
11085 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11086 				 ethertype, "ethertype");
11087 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
11088 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11089 			      ethertype_value, UINT16);
11090 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
11091 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11092 				 drop, "drop#fwd");
11093 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
11094 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11095 				 queue, "queue");
11096 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
11097 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11098 			      queue_id, UINT16);
11099 
11100 static void
11101 cmd_ethertype_filter_parsed(void *parsed_result,
11102 			  __rte_unused struct cmdline *cl,
11103 			  __rte_unused void *data)
11104 {
11105 	struct cmd_ethertype_filter_result *res = parsed_result;
11106 	struct rte_eth_ethertype_filter filter;
11107 	int ret = 0;
11108 
11109 	ret = rte_eth_dev_filter_supported(res->port_id,
11110 			RTE_ETH_FILTER_ETHERTYPE);
11111 	if (ret < 0) {
11112 		printf("ethertype filter is not supported on port %u.\n",
11113 			res->port_id);
11114 		return;
11115 	}
11116 
11117 	memset(&filter, 0, sizeof(filter));
11118 	if (!strcmp(res->mac, "mac_addr")) {
11119 		filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
11120 		rte_memcpy(&filter.mac_addr, &res->mac_addr,
11121 			sizeof(struct rte_ether_addr));
11122 	}
11123 	if (!strcmp(res->drop, "drop"))
11124 		filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
11125 	filter.ether_type = res->ethertype_value;
11126 	filter.queue = res->queue_id;
11127 
11128 	if (!strcmp(res->ops, "add"))
11129 		ret = rte_eth_dev_filter_ctrl(res->port_id,
11130 				RTE_ETH_FILTER_ETHERTYPE,
11131 				RTE_ETH_FILTER_ADD,
11132 				&filter);
11133 	else
11134 		ret = rte_eth_dev_filter_ctrl(res->port_id,
11135 				RTE_ETH_FILTER_ETHERTYPE,
11136 				RTE_ETH_FILTER_DELETE,
11137 				&filter);
11138 	if (ret < 0)
11139 		printf("ethertype filter programming error: (%s)\n",
11140 			strerror(-ret));
11141 }
11142 
11143 cmdline_parse_inst_t cmd_ethertype_filter = {
11144 	.f = cmd_ethertype_filter_parsed,
11145 	.data = NULL,
11146 	.help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
11147 		"<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
11148 		"Add or delete an ethertype filter entry",
11149 	.tokens = {
11150 		(void *)&cmd_ethertype_filter_filter,
11151 		(void *)&cmd_ethertype_filter_port_id,
11152 		(void *)&cmd_ethertype_filter_ops,
11153 		(void *)&cmd_ethertype_filter_mac,
11154 		(void *)&cmd_ethertype_filter_mac_addr,
11155 		(void *)&cmd_ethertype_filter_ethertype,
11156 		(void *)&cmd_ethertype_filter_ethertype_value,
11157 		(void *)&cmd_ethertype_filter_drop,
11158 		(void *)&cmd_ethertype_filter_queue,
11159 		(void *)&cmd_ethertype_filter_queue_id,
11160 		NULL,
11161 	},
11162 };
11163 
11164 /* *** deal with flow director filter *** */
11165 struct cmd_flow_director_result {
11166 	cmdline_fixed_string_t flow_director_filter;
11167 	portid_t port_id;
11168 	cmdline_fixed_string_t mode;
11169 	cmdline_fixed_string_t mode_value;
11170 	cmdline_fixed_string_t ops;
11171 	cmdline_fixed_string_t flow;
11172 	cmdline_fixed_string_t flow_type;
11173 	cmdline_fixed_string_t ether;
11174 	uint16_t ether_type;
11175 	cmdline_fixed_string_t src;
11176 	cmdline_ipaddr_t ip_src;
11177 	uint16_t port_src;
11178 	cmdline_fixed_string_t dst;
11179 	cmdline_ipaddr_t ip_dst;
11180 	uint16_t port_dst;
11181 	cmdline_fixed_string_t verify_tag;
11182 	uint32_t verify_tag_value;
11183 	cmdline_fixed_string_t tos;
11184 	uint8_t tos_value;
11185 	cmdline_fixed_string_t proto;
11186 	uint8_t proto_value;
11187 	cmdline_fixed_string_t ttl;
11188 	uint8_t ttl_value;
11189 	cmdline_fixed_string_t vlan;
11190 	uint16_t vlan_value;
11191 	cmdline_fixed_string_t flexbytes;
11192 	cmdline_fixed_string_t flexbytes_value;
11193 	cmdline_fixed_string_t pf_vf;
11194 	cmdline_fixed_string_t drop;
11195 	cmdline_fixed_string_t queue;
11196 	uint16_t  queue_id;
11197 	cmdline_fixed_string_t fd_id;
11198 	uint32_t  fd_id_value;
11199 	cmdline_fixed_string_t mac;
11200 	struct rte_ether_addr mac_addr;
11201 	cmdline_fixed_string_t tunnel;
11202 	cmdline_fixed_string_t tunnel_type;
11203 	cmdline_fixed_string_t tunnel_id;
11204 	uint32_t tunnel_id_value;
11205 	cmdline_fixed_string_t packet;
11206 	char filepath[];
11207 };
11208 
11209 static inline int
11210 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
11211 {
11212 	char s[256];
11213 	const char *p, *p0 = q_arg;
11214 	char *end;
11215 	unsigned long int_fld;
11216 	char *str_fld[max_num];
11217 	int i;
11218 	unsigned size;
11219 	int ret = -1;
11220 
11221 	p = strchr(p0, '(');
11222 	if (p == NULL)
11223 		return -1;
11224 	++p;
11225 	p0 = strchr(p, ')');
11226 	if (p0 == NULL)
11227 		return -1;
11228 
11229 	size = p0 - p;
11230 	if (size >= sizeof(s))
11231 		return -1;
11232 
11233 	snprintf(s, sizeof(s), "%.*s", size, p);
11234 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11235 	if (ret < 0 || ret > max_num)
11236 		return -1;
11237 	for (i = 0; i < ret; i++) {
11238 		errno = 0;
11239 		int_fld = strtoul(str_fld[i], &end, 0);
11240 		if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11241 			return -1;
11242 		flexbytes[i] = (uint8_t)int_fld;
11243 	}
11244 	return ret;
11245 }
11246 
11247 static uint16_t
11248 str2flowtype(char *string)
11249 {
11250 	uint8_t i = 0;
11251 	static const struct {
11252 		char str[32];
11253 		uint16_t type;
11254 	} flowtype_str[] = {
11255 		{"raw", RTE_ETH_FLOW_RAW},
11256 		{"ipv4", RTE_ETH_FLOW_IPV4},
11257 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11258 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11259 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11260 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11261 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11262 		{"ipv6", RTE_ETH_FLOW_IPV6},
11263 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11264 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11265 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11266 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11267 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11268 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11269 	};
11270 
11271 	for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11272 		if (!strcmp(flowtype_str[i].str, string))
11273 			return flowtype_str[i].type;
11274 	}
11275 
11276 	if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11277 		return (uint16_t)atoi(string);
11278 
11279 	return RTE_ETH_FLOW_UNKNOWN;
11280 }
11281 
11282 static enum rte_eth_fdir_tunnel_type
11283 str2fdir_tunneltype(char *string)
11284 {
11285 	uint8_t i = 0;
11286 
11287 	static const struct {
11288 		char str[32];
11289 		enum rte_eth_fdir_tunnel_type type;
11290 	} tunneltype_str[] = {
11291 		{"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11292 		{"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11293 	};
11294 
11295 	for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11296 		if (!strcmp(tunneltype_str[i].str, string))
11297 			return tunneltype_str[i].type;
11298 	}
11299 	return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11300 }
11301 
11302 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11303 do { \
11304 	if ((ip_addr).family == AF_INET) \
11305 		(ip) = (ip_addr).addr.ipv4.s_addr; \
11306 	else { \
11307 		printf("invalid parameter.\n"); \
11308 		return; \
11309 	} \
11310 } while (0)
11311 
11312 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11313 do { \
11314 	if ((ip_addr).family == AF_INET6) \
11315 		rte_memcpy(&(ip), \
11316 				 &((ip_addr).addr.ipv6), \
11317 				 sizeof(struct in6_addr)); \
11318 	else { \
11319 		printf("invalid parameter.\n"); \
11320 		return; \
11321 	} \
11322 } while (0)
11323 
11324 static void
11325 cmd_flow_director_filter_parsed(void *parsed_result,
11326 			  __rte_unused struct cmdline *cl,
11327 			  __rte_unused void *data)
11328 {
11329 	struct cmd_flow_director_result *res = parsed_result;
11330 	struct rte_eth_fdir_filter entry;
11331 	uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11332 	char *end;
11333 	unsigned long vf_id;
11334 	int ret = 0;
11335 
11336 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11337 	if (ret < 0) {
11338 		printf("flow director is not supported on port %u.\n",
11339 			res->port_id);
11340 		return;
11341 	}
11342 	memset(flexbytes, 0, sizeof(flexbytes));
11343 	memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11344 
11345 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11346 		if (strcmp(res->mode_value, "MAC-VLAN")) {
11347 			printf("Please set mode to MAC-VLAN.\n");
11348 			return;
11349 		}
11350 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11351 		if (strcmp(res->mode_value, "Tunnel")) {
11352 			printf("Please set mode to Tunnel.\n");
11353 			return;
11354 		}
11355 	} else {
11356 		if (!strcmp(res->mode_value, "raw")) {
11357 #ifdef RTE_LIBRTE_I40E_PMD
11358 			struct rte_pmd_i40e_flow_type_mapping
11359 					mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11360 			struct rte_pmd_i40e_pkt_template_conf conf;
11361 			uint16_t flow_type = str2flowtype(res->flow_type);
11362 			uint16_t i, port = res->port_id;
11363 			uint8_t add;
11364 
11365 			memset(&conf, 0, sizeof(conf));
11366 
11367 			if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11368 				printf("Invalid flow type specified.\n");
11369 				return;
11370 			}
11371 			ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11372 								 mapping);
11373 			if (ret)
11374 				return;
11375 			if (mapping[flow_type].pctype == 0ULL) {
11376 				printf("Invalid flow type specified.\n");
11377 				return;
11378 			}
11379 			for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11380 				if (mapping[flow_type].pctype & (1ULL << i)) {
11381 					conf.input.pctype = i;
11382 					break;
11383 				}
11384 			}
11385 
11386 			conf.input.packet = open_file(res->filepath,
11387 						&conf.input.length);
11388 			if (!conf.input.packet)
11389 				return;
11390 			if (!strcmp(res->drop, "drop"))
11391 				conf.action.behavior =
11392 					RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11393 			else
11394 				conf.action.behavior =
11395 					RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11396 			conf.action.report_status =
11397 					RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11398 			conf.action.rx_queue = res->queue_id;
11399 			conf.soft_id = res->fd_id_value;
11400 			add  = strcmp(res->ops, "del") ? 1 : 0;
11401 			ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11402 									&conf,
11403 									add);
11404 			if (ret < 0)
11405 				printf("flow director config error: (%s)\n",
11406 				       strerror(-ret));
11407 			close_file(conf.input.packet);
11408 #endif
11409 			return;
11410 		} else if (strcmp(res->mode_value, "IP")) {
11411 			printf("Please set mode to IP or raw.\n");
11412 			return;
11413 		}
11414 		entry.input.flow_type = str2flowtype(res->flow_type);
11415 	}
11416 
11417 	ret = parse_flexbytes(res->flexbytes_value,
11418 					flexbytes,
11419 					RTE_ETH_FDIR_MAX_FLEXLEN);
11420 	if (ret < 0) {
11421 		printf("error: Cannot parse flexbytes input.\n");
11422 		return;
11423 	}
11424 
11425 	switch (entry.input.flow_type) {
11426 	case RTE_ETH_FLOW_FRAG_IPV4:
11427 	case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11428 		entry.input.flow.ip4_flow.proto = res->proto_value;
11429 		/* fall-through */
11430 	case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11431 	case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11432 		IPV4_ADDR_TO_UINT(res->ip_dst,
11433 			entry.input.flow.ip4_flow.dst_ip);
11434 		IPV4_ADDR_TO_UINT(res->ip_src,
11435 			entry.input.flow.ip4_flow.src_ip);
11436 		entry.input.flow.ip4_flow.tos = res->tos_value;
11437 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
11438 		/* need convert to big endian. */
11439 		entry.input.flow.udp4_flow.dst_port =
11440 				rte_cpu_to_be_16(res->port_dst);
11441 		entry.input.flow.udp4_flow.src_port =
11442 				rte_cpu_to_be_16(res->port_src);
11443 		break;
11444 	case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11445 		IPV4_ADDR_TO_UINT(res->ip_dst,
11446 			entry.input.flow.sctp4_flow.ip.dst_ip);
11447 		IPV4_ADDR_TO_UINT(res->ip_src,
11448 			entry.input.flow.sctp4_flow.ip.src_ip);
11449 		entry.input.flow.ip4_flow.tos = res->tos_value;
11450 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
11451 		/* need convert to big endian. */
11452 		entry.input.flow.sctp4_flow.dst_port =
11453 				rte_cpu_to_be_16(res->port_dst);
11454 		entry.input.flow.sctp4_flow.src_port =
11455 				rte_cpu_to_be_16(res->port_src);
11456 		entry.input.flow.sctp4_flow.verify_tag =
11457 				rte_cpu_to_be_32(res->verify_tag_value);
11458 		break;
11459 	case RTE_ETH_FLOW_FRAG_IPV6:
11460 	case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11461 		entry.input.flow.ipv6_flow.proto = res->proto_value;
11462 		/* fall-through */
11463 	case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11464 	case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11465 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
11466 			entry.input.flow.ipv6_flow.dst_ip);
11467 		IPV6_ADDR_TO_ARRAY(res->ip_src,
11468 			entry.input.flow.ipv6_flow.src_ip);
11469 		entry.input.flow.ipv6_flow.tc = res->tos_value;
11470 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11471 		/* need convert to big endian. */
11472 		entry.input.flow.udp6_flow.dst_port =
11473 				rte_cpu_to_be_16(res->port_dst);
11474 		entry.input.flow.udp6_flow.src_port =
11475 				rte_cpu_to_be_16(res->port_src);
11476 		break;
11477 	case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11478 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
11479 			entry.input.flow.sctp6_flow.ip.dst_ip);
11480 		IPV6_ADDR_TO_ARRAY(res->ip_src,
11481 			entry.input.flow.sctp6_flow.ip.src_ip);
11482 		entry.input.flow.ipv6_flow.tc = res->tos_value;
11483 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11484 		/* need convert to big endian. */
11485 		entry.input.flow.sctp6_flow.dst_port =
11486 				rte_cpu_to_be_16(res->port_dst);
11487 		entry.input.flow.sctp6_flow.src_port =
11488 				rte_cpu_to_be_16(res->port_src);
11489 		entry.input.flow.sctp6_flow.verify_tag =
11490 				rte_cpu_to_be_32(res->verify_tag_value);
11491 		break;
11492 	case RTE_ETH_FLOW_L2_PAYLOAD:
11493 		entry.input.flow.l2_flow.ether_type =
11494 			rte_cpu_to_be_16(res->ether_type);
11495 		break;
11496 	default:
11497 		break;
11498 	}
11499 
11500 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11501 		rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11502 				 &res->mac_addr,
11503 				 sizeof(struct rte_ether_addr));
11504 
11505 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11506 		rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11507 				 &res->mac_addr,
11508 				 sizeof(struct rte_ether_addr));
11509 		entry.input.flow.tunnel_flow.tunnel_type =
11510 			str2fdir_tunneltype(res->tunnel_type);
11511 		entry.input.flow.tunnel_flow.tunnel_id =
11512 			rte_cpu_to_be_32(res->tunnel_id_value);
11513 	}
11514 
11515 	rte_memcpy(entry.input.flow_ext.flexbytes,
11516 		   flexbytes,
11517 		   RTE_ETH_FDIR_MAX_FLEXLEN);
11518 
11519 	entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11520 
11521 	entry.action.flex_off = 0;  /*use 0 by default */
11522 	if (!strcmp(res->drop, "drop"))
11523 		entry.action.behavior = RTE_ETH_FDIR_REJECT;
11524 	else
11525 		entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11526 
11527 	if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11528 	    fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11529 		if (!strcmp(res->pf_vf, "pf"))
11530 			entry.input.flow_ext.is_vf = 0;
11531 		else if (!strncmp(res->pf_vf, "vf", 2)) {
11532 			struct rte_eth_dev_info dev_info;
11533 
11534 			ret = eth_dev_info_get_print_err(res->port_id,
11535 						&dev_info);
11536 			if (ret != 0)
11537 				return;
11538 
11539 			errno = 0;
11540 			vf_id = strtoul(res->pf_vf + 2, &end, 10);
11541 			if (errno != 0 || *end != '\0' ||
11542 			    vf_id >= dev_info.max_vfs) {
11543 				printf("invalid parameter %s.\n", res->pf_vf);
11544 				return;
11545 			}
11546 			entry.input.flow_ext.is_vf = 1;
11547 			entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11548 		} else {
11549 			printf("invalid parameter %s.\n", res->pf_vf);
11550 			return;
11551 		}
11552 	}
11553 
11554 	/* set to report FD ID by default */
11555 	entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11556 	entry.action.rx_queue = res->queue_id;
11557 	entry.soft_id = res->fd_id_value;
11558 	if (!strcmp(res->ops, "add"))
11559 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11560 					     RTE_ETH_FILTER_ADD, &entry);
11561 	else if (!strcmp(res->ops, "del"))
11562 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11563 					     RTE_ETH_FILTER_DELETE, &entry);
11564 	else
11565 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11566 					     RTE_ETH_FILTER_UPDATE, &entry);
11567 	if (ret < 0)
11568 		printf("flow director programming error: (%s)\n",
11569 			strerror(-ret));
11570 }
11571 
11572 cmdline_parse_token_string_t cmd_flow_director_filter =
11573 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11574 				 flow_director_filter, "flow_director_filter");
11575 cmdline_parse_token_num_t cmd_flow_director_port_id =
11576 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11577 			      port_id, UINT16);
11578 cmdline_parse_token_string_t cmd_flow_director_ops =
11579 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11580 				 ops, "add#del#update");
11581 cmdline_parse_token_string_t cmd_flow_director_flow =
11582 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11583 				 flow, "flow");
11584 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11585 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11586 		flow_type, NULL);
11587 cmdline_parse_token_string_t cmd_flow_director_ether =
11588 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11589 				 ether, "ether");
11590 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11591 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11592 			      ether_type, UINT16);
11593 cmdline_parse_token_string_t cmd_flow_director_src =
11594 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11595 				 src, "src");
11596 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11597 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11598 				 ip_src);
11599 cmdline_parse_token_num_t cmd_flow_director_port_src =
11600 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11601 			      port_src, UINT16);
11602 cmdline_parse_token_string_t cmd_flow_director_dst =
11603 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11604 				 dst, "dst");
11605 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11606 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11607 				 ip_dst);
11608 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11609 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11610 			      port_dst, UINT16);
11611 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11612 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11613 				  verify_tag, "verify_tag");
11614 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11615 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11616 			      verify_tag_value, UINT32);
11617 cmdline_parse_token_string_t cmd_flow_director_tos =
11618 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11619 				 tos, "tos");
11620 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11621 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11622 			      tos_value, UINT8);
11623 cmdline_parse_token_string_t cmd_flow_director_proto =
11624 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11625 				 proto, "proto");
11626 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11627 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11628 			      proto_value, UINT8);
11629 cmdline_parse_token_string_t cmd_flow_director_ttl =
11630 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11631 				 ttl, "ttl");
11632 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11633 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11634 			      ttl_value, UINT8);
11635 cmdline_parse_token_string_t cmd_flow_director_vlan =
11636 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11637 				 vlan, "vlan");
11638 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11639 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11640 			      vlan_value, UINT16);
11641 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11642 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11643 				 flexbytes, "flexbytes");
11644 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11645 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11646 			      flexbytes_value, NULL);
11647 cmdline_parse_token_string_t cmd_flow_director_drop =
11648 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11649 				 drop, "drop#fwd");
11650 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11651 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11652 			      pf_vf, NULL);
11653 cmdline_parse_token_string_t cmd_flow_director_queue =
11654 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11655 				 queue, "queue");
11656 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11657 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11658 			      queue_id, UINT16);
11659 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11660 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11661 				 fd_id, "fd_id");
11662 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11663 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11664 			      fd_id_value, UINT32);
11665 
11666 cmdline_parse_token_string_t cmd_flow_director_mode =
11667 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11668 				 mode, "mode");
11669 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11670 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11671 				 mode_value, "IP");
11672 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11673 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11674 				 mode_value, "MAC-VLAN");
11675 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11676 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11677 				 mode_value, "Tunnel");
11678 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11679 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11680 				 mode_value, "raw");
11681 cmdline_parse_token_string_t cmd_flow_director_mac =
11682 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11683 				 mac, "mac");
11684 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11685 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11686 				    mac_addr);
11687 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11688 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11689 				 tunnel, "tunnel");
11690 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11691 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11692 				 tunnel_type, "NVGRE#VxLAN");
11693 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11694 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11695 				 tunnel_id, "tunnel-id");
11696 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11697 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11698 			      tunnel_id_value, UINT32);
11699 cmdline_parse_token_string_t cmd_flow_director_packet =
11700 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11701 				 packet, "packet");
11702 cmdline_parse_token_string_t cmd_flow_director_filepath =
11703 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11704 				 filepath, NULL);
11705 
11706 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11707 	.f = cmd_flow_director_filter_parsed,
11708 	.data = NULL,
11709 	.help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11710 		" ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11711 		"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11712 		"l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11713 		"proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11714 		"flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11715 		"fd_id <fd_id_value>: "
11716 		"Add or delete an ip flow director entry on NIC",
11717 	.tokens = {
11718 		(void *)&cmd_flow_director_filter,
11719 		(void *)&cmd_flow_director_port_id,
11720 		(void *)&cmd_flow_director_mode,
11721 		(void *)&cmd_flow_director_mode_ip,
11722 		(void *)&cmd_flow_director_ops,
11723 		(void *)&cmd_flow_director_flow,
11724 		(void *)&cmd_flow_director_flow_type,
11725 		(void *)&cmd_flow_director_src,
11726 		(void *)&cmd_flow_director_ip_src,
11727 		(void *)&cmd_flow_director_dst,
11728 		(void *)&cmd_flow_director_ip_dst,
11729 		(void *)&cmd_flow_director_tos,
11730 		(void *)&cmd_flow_director_tos_value,
11731 		(void *)&cmd_flow_director_proto,
11732 		(void *)&cmd_flow_director_proto_value,
11733 		(void *)&cmd_flow_director_ttl,
11734 		(void *)&cmd_flow_director_ttl_value,
11735 		(void *)&cmd_flow_director_vlan,
11736 		(void *)&cmd_flow_director_vlan_value,
11737 		(void *)&cmd_flow_director_flexbytes,
11738 		(void *)&cmd_flow_director_flexbytes_value,
11739 		(void *)&cmd_flow_director_drop,
11740 		(void *)&cmd_flow_director_pf_vf,
11741 		(void *)&cmd_flow_director_queue,
11742 		(void *)&cmd_flow_director_queue_id,
11743 		(void *)&cmd_flow_director_fd_id,
11744 		(void *)&cmd_flow_director_fd_id_value,
11745 		NULL,
11746 	},
11747 };
11748 
11749 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11750 	.f = cmd_flow_director_filter_parsed,
11751 	.data = NULL,
11752 	.help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11753 		"director entry on NIC",
11754 	.tokens = {
11755 		(void *)&cmd_flow_director_filter,
11756 		(void *)&cmd_flow_director_port_id,
11757 		(void *)&cmd_flow_director_mode,
11758 		(void *)&cmd_flow_director_mode_ip,
11759 		(void *)&cmd_flow_director_ops,
11760 		(void *)&cmd_flow_director_flow,
11761 		(void *)&cmd_flow_director_flow_type,
11762 		(void *)&cmd_flow_director_src,
11763 		(void *)&cmd_flow_director_ip_src,
11764 		(void *)&cmd_flow_director_port_src,
11765 		(void *)&cmd_flow_director_dst,
11766 		(void *)&cmd_flow_director_ip_dst,
11767 		(void *)&cmd_flow_director_port_dst,
11768 		(void *)&cmd_flow_director_tos,
11769 		(void *)&cmd_flow_director_tos_value,
11770 		(void *)&cmd_flow_director_ttl,
11771 		(void *)&cmd_flow_director_ttl_value,
11772 		(void *)&cmd_flow_director_vlan,
11773 		(void *)&cmd_flow_director_vlan_value,
11774 		(void *)&cmd_flow_director_flexbytes,
11775 		(void *)&cmd_flow_director_flexbytes_value,
11776 		(void *)&cmd_flow_director_drop,
11777 		(void *)&cmd_flow_director_pf_vf,
11778 		(void *)&cmd_flow_director_queue,
11779 		(void *)&cmd_flow_director_queue_id,
11780 		(void *)&cmd_flow_director_fd_id,
11781 		(void *)&cmd_flow_director_fd_id_value,
11782 		NULL,
11783 	},
11784 };
11785 
11786 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11787 	.f = cmd_flow_director_filter_parsed,
11788 	.data = NULL,
11789 	.help_str = "flow_director_filter ... : Add or delete a sctp flow "
11790 		"director entry on NIC",
11791 	.tokens = {
11792 		(void *)&cmd_flow_director_filter,
11793 		(void *)&cmd_flow_director_port_id,
11794 		(void *)&cmd_flow_director_mode,
11795 		(void *)&cmd_flow_director_mode_ip,
11796 		(void *)&cmd_flow_director_ops,
11797 		(void *)&cmd_flow_director_flow,
11798 		(void *)&cmd_flow_director_flow_type,
11799 		(void *)&cmd_flow_director_src,
11800 		(void *)&cmd_flow_director_ip_src,
11801 		(void *)&cmd_flow_director_port_src,
11802 		(void *)&cmd_flow_director_dst,
11803 		(void *)&cmd_flow_director_ip_dst,
11804 		(void *)&cmd_flow_director_port_dst,
11805 		(void *)&cmd_flow_director_verify_tag,
11806 		(void *)&cmd_flow_director_verify_tag_value,
11807 		(void *)&cmd_flow_director_tos,
11808 		(void *)&cmd_flow_director_tos_value,
11809 		(void *)&cmd_flow_director_ttl,
11810 		(void *)&cmd_flow_director_ttl_value,
11811 		(void *)&cmd_flow_director_vlan,
11812 		(void *)&cmd_flow_director_vlan_value,
11813 		(void *)&cmd_flow_director_flexbytes,
11814 		(void *)&cmd_flow_director_flexbytes_value,
11815 		(void *)&cmd_flow_director_drop,
11816 		(void *)&cmd_flow_director_pf_vf,
11817 		(void *)&cmd_flow_director_queue,
11818 		(void *)&cmd_flow_director_queue_id,
11819 		(void *)&cmd_flow_director_fd_id,
11820 		(void *)&cmd_flow_director_fd_id_value,
11821 		NULL,
11822 	},
11823 };
11824 
11825 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11826 	.f = cmd_flow_director_filter_parsed,
11827 	.data = NULL,
11828 	.help_str = "flow_director_filter ... : Add or delete a L2 flow "
11829 		"director entry on NIC",
11830 	.tokens = {
11831 		(void *)&cmd_flow_director_filter,
11832 		(void *)&cmd_flow_director_port_id,
11833 		(void *)&cmd_flow_director_mode,
11834 		(void *)&cmd_flow_director_mode_ip,
11835 		(void *)&cmd_flow_director_ops,
11836 		(void *)&cmd_flow_director_flow,
11837 		(void *)&cmd_flow_director_flow_type,
11838 		(void *)&cmd_flow_director_ether,
11839 		(void *)&cmd_flow_director_ether_type,
11840 		(void *)&cmd_flow_director_flexbytes,
11841 		(void *)&cmd_flow_director_flexbytes_value,
11842 		(void *)&cmd_flow_director_drop,
11843 		(void *)&cmd_flow_director_pf_vf,
11844 		(void *)&cmd_flow_director_queue,
11845 		(void *)&cmd_flow_director_queue_id,
11846 		(void *)&cmd_flow_director_fd_id,
11847 		(void *)&cmd_flow_director_fd_id_value,
11848 		NULL,
11849 	},
11850 };
11851 
11852 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11853 	.f = cmd_flow_director_filter_parsed,
11854 	.data = NULL,
11855 	.help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11856 		"director entry on NIC",
11857 	.tokens = {
11858 		(void *)&cmd_flow_director_filter,
11859 		(void *)&cmd_flow_director_port_id,
11860 		(void *)&cmd_flow_director_mode,
11861 		(void *)&cmd_flow_director_mode_mac_vlan,
11862 		(void *)&cmd_flow_director_ops,
11863 		(void *)&cmd_flow_director_mac,
11864 		(void *)&cmd_flow_director_mac_addr,
11865 		(void *)&cmd_flow_director_vlan,
11866 		(void *)&cmd_flow_director_vlan_value,
11867 		(void *)&cmd_flow_director_flexbytes,
11868 		(void *)&cmd_flow_director_flexbytes_value,
11869 		(void *)&cmd_flow_director_drop,
11870 		(void *)&cmd_flow_director_queue,
11871 		(void *)&cmd_flow_director_queue_id,
11872 		(void *)&cmd_flow_director_fd_id,
11873 		(void *)&cmd_flow_director_fd_id_value,
11874 		NULL,
11875 	},
11876 };
11877 
11878 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11879 	.f = cmd_flow_director_filter_parsed,
11880 	.data = NULL,
11881 	.help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11882 		"director entry on NIC",
11883 	.tokens = {
11884 		(void *)&cmd_flow_director_filter,
11885 		(void *)&cmd_flow_director_port_id,
11886 		(void *)&cmd_flow_director_mode,
11887 		(void *)&cmd_flow_director_mode_tunnel,
11888 		(void *)&cmd_flow_director_ops,
11889 		(void *)&cmd_flow_director_mac,
11890 		(void *)&cmd_flow_director_mac_addr,
11891 		(void *)&cmd_flow_director_vlan,
11892 		(void *)&cmd_flow_director_vlan_value,
11893 		(void *)&cmd_flow_director_tunnel,
11894 		(void *)&cmd_flow_director_tunnel_type,
11895 		(void *)&cmd_flow_director_tunnel_id,
11896 		(void *)&cmd_flow_director_tunnel_id_value,
11897 		(void *)&cmd_flow_director_flexbytes,
11898 		(void *)&cmd_flow_director_flexbytes_value,
11899 		(void *)&cmd_flow_director_drop,
11900 		(void *)&cmd_flow_director_queue,
11901 		(void *)&cmd_flow_director_queue_id,
11902 		(void *)&cmd_flow_director_fd_id,
11903 		(void *)&cmd_flow_director_fd_id_value,
11904 		NULL,
11905 	},
11906 };
11907 
11908 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11909 	.f = cmd_flow_director_filter_parsed,
11910 	.data = NULL,
11911 	.help_str = "flow_director_filter ... : Add or delete a raw flow "
11912 		"director entry on NIC",
11913 	.tokens = {
11914 		(void *)&cmd_flow_director_filter,
11915 		(void *)&cmd_flow_director_port_id,
11916 		(void *)&cmd_flow_director_mode,
11917 		(void *)&cmd_flow_director_mode_raw,
11918 		(void *)&cmd_flow_director_ops,
11919 		(void *)&cmd_flow_director_flow,
11920 		(void *)&cmd_flow_director_flow_type,
11921 		(void *)&cmd_flow_director_drop,
11922 		(void *)&cmd_flow_director_queue,
11923 		(void *)&cmd_flow_director_queue_id,
11924 		(void *)&cmd_flow_director_fd_id,
11925 		(void *)&cmd_flow_director_fd_id_value,
11926 		(void *)&cmd_flow_director_packet,
11927 		(void *)&cmd_flow_director_filepath,
11928 		NULL,
11929 	},
11930 };
11931 
11932 struct cmd_flush_flow_director_result {
11933 	cmdline_fixed_string_t flush_flow_director;
11934 	portid_t port_id;
11935 };
11936 
11937 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11938 	TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11939 				 flush_flow_director, "flush_flow_director");
11940 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11941 	TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11942 			      port_id, UINT16);
11943 
11944 static void
11945 cmd_flush_flow_director_parsed(void *parsed_result,
11946 			  __rte_unused struct cmdline *cl,
11947 			  __rte_unused void *data)
11948 {
11949 	struct cmd_flow_director_result *res = parsed_result;
11950 	int ret = 0;
11951 
11952 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11953 	if (ret < 0) {
11954 		printf("flow director is not supported on port %u.\n",
11955 			res->port_id);
11956 		return;
11957 	}
11958 
11959 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11960 			RTE_ETH_FILTER_FLUSH, NULL);
11961 	if (ret < 0)
11962 		printf("flow director table flushing error: (%s)\n",
11963 			strerror(-ret));
11964 }
11965 
11966 cmdline_parse_inst_t cmd_flush_flow_director = {
11967 	.f = cmd_flush_flow_director_parsed,
11968 	.data = NULL,
11969 	.help_str = "flush_flow_director <port_id>: "
11970 		"Flush all flow director entries of a device on NIC",
11971 	.tokens = {
11972 		(void *)&cmd_flush_flow_director_flush,
11973 		(void *)&cmd_flush_flow_director_port_id,
11974 		NULL,
11975 	},
11976 };
11977 
11978 /* *** deal with flow director mask *** */
11979 struct cmd_flow_director_mask_result {
11980 	cmdline_fixed_string_t flow_director_mask;
11981 	portid_t port_id;
11982 	cmdline_fixed_string_t mode;
11983 	cmdline_fixed_string_t mode_value;
11984 	cmdline_fixed_string_t vlan;
11985 	uint16_t vlan_mask;
11986 	cmdline_fixed_string_t src_mask;
11987 	cmdline_ipaddr_t ipv4_src;
11988 	cmdline_ipaddr_t ipv6_src;
11989 	uint16_t port_src;
11990 	cmdline_fixed_string_t dst_mask;
11991 	cmdline_ipaddr_t ipv4_dst;
11992 	cmdline_ipaddr_t ipv6_dst;
11993 	uint16_t port_dst;
11994 	cmdline_fixed_string_t mac;
11995 	uint8_t mac_addr_byte_mask;
11996 	cmdline_fixed_string_t tunnel_id;
11997 	uint32_t tunnel_id_mask;
11998 	cmdline_fixed_string_t tunnel_type;
11999 	uint8_t tunnel_type_mask;
12000 };
12001 
12002 static void
12003 cmd_flow_director_mask_parsed(void *parsed_result,
12004 			  __rte_unused struct cmdline *cl,
12005 			  __rte_unused void *data)
12006 {
12007 	struct cmd_flow_director_mask_result *res = parsed_result;
12008 	struct rte_eth_fdir_masks *mask;
12009 	struct rte_port *port;
12010 
12011 	port = &ports[res->port_id];
12012 	/** Check if the port is not started **/
12013 	if (port->port_status != RTE_PORT_STOPPED) {
12014 		printf("Please stop port %d first\n", res->port_id);
12015 		return;
12016 	}
12017 
12018 	mask = &port->dev_conf.fdir_conf.mask;
12019 
12020 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
12021 		if (strcmp(res->mode_value, "MAC-VLAN")) {
12022 			printf("Please set mode to MAC-VLAN.\n");
12023 			return;
12024 		}
12025 
12026 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12027 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
12028 		if (strcmp(res->mode_value, "Tunnel")) {
12029 			printf("Please set mode to Tunnel.\n");
12030 			return;
12031 		}
12032 
12033 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12034 		mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
12035 		mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
12036 		mask->tunnel_type_mask = res->tunnel_type_mask;
12037 	} else {
12038 		if (strcmp(res->mode_value, "IP")) {
12039 			printf("Please set mode to IP.\n");
12040 			return;
12041 		}
12042 
12043 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12044 		IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
12045 		IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
12046 		IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
12047 		IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
12048 		mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
12049 		mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
12050 	}
12051 
12052 	cmd_reconfig_device_queue(res->port_id, 1, 1);
12053 }
12054 
12055 cmdline_parse_token_string_t cmd_flow_director_mask =
12056 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12057 				 flow_director_mask, "flow_director_mask");
12058 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
12059 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12060 			      port_id, UINT16);
12061 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
12062 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12063 				 vlan, "vlan");
12064 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
12065 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12066 			      vlan_mask, UINT16);
12067 cmdline_parse_token_string_t cmd_flow_director_mask_src =
12068 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12069 				 src_mask, "src_mask");
12070 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
12071 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12072 				 ipv4_src);
12073 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
12074 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12075 				 ipv6_src);
12076 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
12077 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12078 			      port_src, UINT16);
12079 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
12080 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12081 				 dst_mask, "dst_mask");
12082 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
12083 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12084 				 ipv4_dst);
12085 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
12086 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12087 				 ipv6_dst);
12088 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
12089 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12090 			      port_dst, UINT16);
12091 
12092 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
12093 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12094 				 mode, "mode");
12095 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
12096 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12097 				 mode_value, "IP");
12098 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
12099 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12100 				 mode_value, "MAC-VLAN");
12101 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
12102 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12103 				 mode_value, "Tunnel");
12104 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
12105 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12106 				 mac, "mac");
12107 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
12108 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12109 			      mac_addr_byte_mask, UINT8);
12110 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
12111 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12112 				 tunnel_type, "tunnel-type");
12113 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
12114 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12115 			      tunnel_type_mask, UINT8);
12116 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
12117 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12118 				 tunnel_id, "tunnel-id");
12119 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
12120 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12121 			      tunnel_id_mask, UINT32);
12122 
12123 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
12124 	.f = cmd_flow_director_mask_parsed,
12125 	.data = NULL,
12126 	.help_str = "flow_director_mask ... : "
12127 		"Set IP mode flow director's mask on NIC",
12128 	.tokens = {
12129 		(void *)&cmd_flow_director_mask,
12130 		(void *)&cmd_flow_director_mask_port_id,
12131 		(void *)&cmd_flow_director_mask_mode,
12132 		(void *)&cmd_flow_director_mask_mode_ip,
12133 		(void *)&cmd_flow_director_mask_vlan,
12134 		(void *)&cmd_flow_director_mask_vlan_value,
12135 		(void *)&cmd_flow_director_mask_src,
12136 		(void *)&cmd_flow_director_mask_ipv4_src,
12137 		(void *)&cmd_flow_director_mask_ipv6_src,
12138 		(void *)&cmd_flow_director_mask_port_src,
12139 		(void *)&cmd_flow_director_mask_dst,
12140 		(void *)&cmd_flow_director_mask_ipv4_dst,
12141 		(void *)&cmd_flow_director_mask_ipv6_dst,
12142 		(void *)&cmd_flow_director_mask_port_dst,
12143 		NULL,
12144 	},
12145 };
12146 
12147 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
12148 	.f = cmd_flow_director_mask_parsed,
12149 	.data = NULL,
12150 	.help_str = "flow_director_mask ... : Set MAC VLAN mode "
12151 		"flow director's mask on NIC",
12152 	.tokens = {
12153 		(void *)&cmd_flow_director_mask,
12154 		(void *)&cmd_flow_director_mask_port_id,
12155 		(void *)&cmd_flow_director_mask_mode,
12156 		(void *)&cmd_flow_director_mask_mode_mac_vlan,
12157 		(void *)&cmd_flow_director_mask_vlan,
12158 		(void *)&cmd_flow_director_mask_vlan_value,
12159 		NULL,
12160 	},
12161 };
12162 
12163 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
12164 	.f = cmd_flow_director_mask_parsed,
12165 	.data = NULL,
12166 	.help_str = "flow_director_mask ... : Set tunnel mode "
12167 		"flow director's mask on NIC",
12168 	.tokens = {
12169 		(void *)&cmd_flow_director_mask,
12170 		(void *)&cmd_flow_director_mask_port_id,
12171 		(void *)&cmd_flow_director_mask_mode,
12172 		(void *)&cmd_flow_director_mask_mode_tunnel,
12173 		(void *)&cmd_flow_director_mask_vlan,
12174 		(void *)&cmd_flow_director_mask_vlan_value,
12175 		(void *)&cmd_flow_director_mask_mac,
12176 		(void *)&cmd_flow_director_mask_mac_value,
12177 		(void *)&cmd_flow_director_mask_tunnel_type,
12178 		(void *)&cmd_flow_director_mask_tunnel_type_value,
12179 		(void *)&cmd_flow_director_mask_tunnel_id,
12180 		(void *)&cmd_flow_director_mask_tunnel_id_value,
12181 		NULL,
12182 	},
12183 };
12184 
12185 /* *** deal with flow director mask on flexible payload *** */
12186 struct cmd_flow_director_flex_mask_result {
12187 	cmdline_fixed_string_t flow_director_flexmask;
12188 	portid_t port_id;
12189 	cmdline_fixed_string_t flow;
12190 	cmdline_fixed_string_t flow_type;
12191 	cmdline_fixed_string_t mask;
12192 };
12193 
12194 static void
12195 cmd_flow_director_flex_mask_parsed(void *parsed_result,
12196 			  __rte_unused struct cmdline *cl,
12197 			  __rte_unused void *data)
12198 {
12199 	struct cmd_flow_director_flex_mask_result *res = parsed_result;
12200 	struct rte_eth_fdir_info fdir_info;
12201 	struct rte_eth_fdir_flex_mask flex_mask;
12202 	struct rte_port *port;
12203 	uint64_t flow_type_mask;
12204 	uint16_t i;
12205 	int ret;
12206 
12207 	port = &ports[res->port_id];
12208 	/** Check if the port is not started **/
12209 	if (port->port_status != RTE_PORT_STOPPED) {
12210 		printf("Please stop port %d first\n", res->port_id);
12211 		return;
12212 	}
12213 
12214 	memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
12215 	ret = parse_flexbytes(res->mask,
12216 			flex_mask.mask,
12217 			RTE_ETH_FDIR_MAX_FLEXLEN);
12218 	if (ret < 0) {
12219 		printf("error: Cannot parse mask input.\n");
12220 		return;
12221 	}
12222 
12223 	memset(&fdir_info, 0, sizeof(fdir_info));
12224 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12225 				RTE_ETH_FILTER_INFO, &fdir_info);
12226 	if (ret < 0) {
12227 		printf("Cannot get FDir filter info\n");
12228 		return;
12229 	}
12230 
12231 	if (!strcmp(res->flow_type, "none")) {
12232 		/* means don't specify the flow type */
12233 		flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
12234 		for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
12235 			memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
12236 			       0, sizeof(struct rte_eth_fdir_flex_mask));
12237 		port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12238 		rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12239 				 &flex_mask,
12240 				 sizeof(struct rte_eth_fdir_flex_mask));
12241 		cmd_reconfig_device_queue(res->port_id, 1, 1);
12242 		return;
12243 	}
12244 	flow_type_mask = fdir_info.flow_types_mask[0];
12245 	if (!strcmp(res->flow_type, "all")) {
12246 		if (!flow_type_mask) {
12247 			printf("No flow type supported\n");
12248 			return;
12249 		}
12250 		for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12251 			if (flow_type_mask & (1ULL << i)) {
12252 				flex_mask.flow_type = i;
12253 				fdir_set_flex_mask(res->port_id, &flex_mask);
12254 			}
12255 		}
12256 		cmd_reconfig_device_queue(res->port_id, 1, 1);
12257 		return;
12258 	}
12259 	flex_mask.flow_type = str2flowtype(res->flow_type);
12260 	if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12261 		printf("Flow type %s not supported on port %d\n",
12262 				res->flow_type, res->port_id);
12263 		return;
12264 	}
12265 	fdir_set_flex_mask(res->port_id, &flex_mask);
12266 	cmd_reconfig_device_queue(res->port_id, 1, 1);
12267 }
12268 
12269 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12270 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12271 				 flow_director_flexmask,
12272 				 "flow_director_flex_mask");
12273 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12274 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12275 			      port_id, UINT16);
12276 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12277 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12278 				 flow, "flow");
12279 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12280 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12281 		flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12282 		"ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12283 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12284 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12285 				 mask, NULL);
12286 
12287 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12288 	.f = cmd_flow_director_flex_mask_parsed,
12289 	.data = NULL,
12290 	.help_str = "flow_director_flex_mask ... : "
12291 		"Set flow director's flex mask on NIC",
12292 	.tokens = {
12293 		(void *)&cmd_flow_director_flexmask,
12294 		(void *)&cmd_flow_director_flexmask_port_id,
12295 		(void *)&cmd_flow_director_flexmask_flow,
12296 		(void *)&cmd_flow_director_flexmask_flow_type,
12297 		(void *)&cmd_flow_director_flexmask_mask,
12298 		NULL,
12299 	},
12300 };
12301 
12302 /* *** deal with flow director flexible payload configuration *** */
12303 struct cmd_flow_director_flexpayload_result {
12304 	cmdline_fixed_string_t flow_director_flexpayload;
12305 	portid_t port_id;
12306 	cmdline_fixed_string_t payload_layer;
12307 	cmdline_fixed_string_t payload_cfg;
12308 };
12309 
12310 static inline int
12311 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12312 {
12313 	char s[256];
12314 	const char *p, *p0 = q_arg;
12315 	char *end;
12316 	unsigned long int_fld;
12317 	char *str_fld[max_num];
12318 	int i;
12319 	unsigned size;
12320 	int ret = -1;
12321 
12322 	p = strchr(p0, '(');
12323 	if (p == NULL)
12324 		return -1;
12325 	++p;
12326 	p0 = strchr(p, ')');
12327 	if (p0 == NULL)
12328 		return -1;
12329 
12330 	size = p0 - p;
12331 	if (size >= sizeof(s))
12332 		return -1;
12333 
12334 	snprintf(s, sizeof(s), "%.*s", size, p);
12335 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12336 	if (ret < 0 || ret > max_num)
12337 		return -1;
12338 	for (i = 0; i < ret; i++) {
12339 		errno = 0;
12340 		int_fld = strtoul(str_fld[i], &end, 0);
12341 		if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12342 			return -1;
12343 		offsets[i] = (uint16_t)int_fld;
12344 	}
12345 	return ret;
12346 }
12347 
12348 static void
12349 cmd_flow_director_flxpld_parsed(void *parsed_result,
12350 			  __rte_unused struct cmdline *cl,
12351 			  __rte_unused void *data)
12352 {
12353 	struct cmd_flow_director_flexpayload_result *res = parsed_result;
12354 	struct rte_eth_flex_payload_cfg flex_cfg;
12355 	struct rte_port *port;
12356 	int ret = 0;
12357 
12358 	port = &ports[res->port_id];
12359 	/** Check if the port is not started **/
12360 	if (port->port_status != RTE_PORT_STOPPED) {
12361 		printf("Please stop port %d first\n", res->port_id);
12362 		return;
12363 	}
12364 
12365 	memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12366 
12367 	if (!strcmp(res->payload_layer, "raw"))
12368 		flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12369 	else if (!strcmp(res->payload_layer, "l2"))
12370 		flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12371 	else if (!strcmp(res->payload_layer, "l3"))
12372 		flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12373 	else if (!strcmp(res->payload_layer, "l4"))
12374 		flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12375 
12376 	ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12377 			    RTE_ETH_FDIR_MAX_FLEXLEN);
12378 	if (ret < 0) {
12379 		printf("error: Cannot parse flex payload input.\n");
12380 		return;
12381 	}
12382 
12383 	fdir_set_flex_payload(res->port_id, &flex_cfg);
12384 	cmd_reconfig_device_queue(res->port_id, 1, 1);
12385 }
12386 
12387 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12388 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12389 				 flow_director_flexpayload,
12390 				 "flow_director_flex_payload");
12391 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12392 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12393 			      port_id, UINT16);
12394 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12395 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12396 				 payload_layer, "raw#l2#l3#l4");
12397 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12398 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12399 				 payload_cfg, NULL);
12400 
12401 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12402 	.f = cmd_flow_director_flxpld_parsed,
12403 	.data = NULL,
12404 	.help_str = "flow_director_flexpayload ... : "
12405 		"Set flow director's flex payload on NIC",
12406 	.tokens = {
12407 		(void *)&cmd_flow_director_flexpayload,
12408 		(void *)&cmd_flow_director_flexpayload_port_id,
12409 		(void *)&cmd_flow_director_flexpayload_payload_layer,
12410 		(void *)&cmd_flow_director_flexpayload_payload_cfg,
12411 		NULL,
12412 	},
12413 };
12414 
12415 /* Generic flow interface command. */
12416 extern cmdline_parse_inst_t cmd_flow;
12417 
12418 /* *** Classification Filters Control *** */
12419 /* *** Get symmetric hash enable per port *** */
12420 struct cmd_get_sym_hash_ena_per_port_result {
12421 	cmdline_fixed_string_t get_sym_hash_ena_per_port;
12422 	portid_t port_id;
12423 };
12424 
12425 static void
12426 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12427 				 __rte_unused struct cmdline *cl,
12428 				 __rte_unused void *data)
12429 {
12430 	struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12431 	struct rte_eth_hash_filter_info info;
12432 	int ret;
12433 
12434 	if (rte_eth_dev_filter_supported(res->port_id,
12435 				RTE_ETH_FILTER_HASH) < 0) {
12436 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12437 							res->port_id);
12438 		return;
12439 	}
12440 
12441 	memset(&info, 0, sizeof(info));
12442 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12443 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12444 						RTE_ETH_FILTER_GET, &info);
12445 
12446 	if (ret < 0) {
12447 		printf("Cannot get symmetric hash enable per port "
12448 					"on port %u\n", res->port_id);
12449 		return;
12450 	}
12451 
12452 	printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12453 				"enabled" : "disabled", res->port_id);
12454 }
12455 
12456 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12457 	TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12458 		get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12459 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12460 	TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12461 		port_id, UINT16);
12462 
12463 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12464 	.f = cmd_get_sym_hash_per_port_parsed,
12465 	.data = NULL,
12466 	.help_str = "get_sym_hash_ena_per_port <port_id>",
12467 	.tokens = {
12468 		(void *)&cmd_get_sym_hash_ena_per_port_all,
12469 		(void *)&cmd_get_sym_hash_ena_per_port_port_id,
12470 		NULL,
12471 	},
12472 };
12473 
12474 /* *** Set symmetric hash enable per port *** */
12475 struct cmd_set_sym_hash_ena_per_port_result {
12476 	cmdline_fixed_string_t set_sym_hash_ena_per_port;
12477 	cmdline_fixed_string_t enable;
12478 	portid_t port_id;
12479 };
12480 
12481 static void
12482 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12483 				 __rte_unused struct cmdline *cl,
12484 				 __rte_unused void *data)
12485 {
12486 	struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12487 	struct rte_eth_hash_filter_info info;
12488 	int ret;
12489 
12490 	if (rte_eth_dev_filter_supported(res->port_id,
12491 				RTE_ETH_FILTER_HASH) < 0) {
12492 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12493 							res->port_id);
12494 		return;
12495 	}
12496 
12497 	memset(&info, 0, sizeof(info));
12498 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12499 	if (!strcmp(res->enable, "enable"))
12500 		info.info.enable = 1;
12501 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12502 					RTE_ETH_FILTER_SET, &info);
12503 	if (ret < 0) {
12504 		printf("Cannot set symmetric hash enable per port on "
12505 					"port %u\n", res->port_id);
12506 		return;
12507 	}
12508 	printf("Symmetric hash has been set to %s on port %u\n",
12509 					res->enable, res->port_id);
12510 }
12511 
12512 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12513 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12514 		set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12515 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12516 	TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12517 		port_id, UINT16);
12518 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12519 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12520 		enable, "enable#disable");
12521 
12522 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12523 	.f = cmd_set_sym_hash_per_port_parsed,
12524 	.data = NULL,
12525 	.help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12526 	.tokens = {
12527 		(void *)&cmd_set_sym_hash_ena_per_port_all,
12528 		(void *)&cmd_set_sym_hash_ena_per_port_port_id,
12529 		(void *)&cmd_set_sym_hash_ena_per_port_enable,
12530 		NULL,
12531 	},
12532 };
12533 
12534 /* Get global config of hash function */
12535 struct cmd_get_hash_global_config_result {
12536 	cmdline_fixed_string_t get_hash_global_config;
12537 	portid_t port_id;
12538 };
12539 
12540 static char *
12541 flowtype_to_str(uint16_t ftype)
12542 {
12543 	uint16_t i;
12544 	static struct {
12545 		char str[16];
12546 		uint16_t ftype;
12547 	} ftype_table[] = {
12548 		{"ipv4", RTE_ETH_FLOW_IPV4},
12549 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12550 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12551 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12552 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12553 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12554 		{"ipv6", RTE_ETH_FLOW_IPV6},
12555 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12556 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12557 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12558 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12559 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12560 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12561 		{"port", RTE_ETH_FLOW_PORT},
12562 		{"vxlan", RTE_ETH_FLOW_VXLAN},
12563 		{"geneve", RTE_ETH_FLOW_GENEVE},
12564 		{"nvgre", RTE_ETH_FLOW_NVGRE},
12565 		{"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12566 	};
12567 
12568 	for (i = 0; i < RTE_DIM(ftype_table); i++) {
12569 		if (ftype_table[i].ftype == ftype)
12570 			return ftype_table[i].str;
12571 	}
12572 
12573 	return NULL;
12574 }
12575 
12576 static void
12577 cmd_get_hash_global_config_parsed(void *parsed_result,
12578 				  __rte_unused struct cmdline *cl,
12579 				  __rte_unused void *data)
12580 {
12581 	struct cmd_get_hash_global_config_result *res = parsed_result;
12582 	struct rte_eth_hash_filter_info info;
12583 	uint32_t idx, offset;
12584 	uint16_t i;
12585 	char *str;
12586 	int ret;
12587 
12588 	if (rte_eth_dev_filter_supported(res->port_id,
12589 			RTE_ETH_FILTER_HASH) < 0) {
12590 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12591 							res->port_id);
12592 		return;
12593 	}
12594 
12595 	memset(&info, 0, sizeof(info));
12596 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12597 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12598 					RTE_ETH_FILTER_GET, &info);
12599 	if (ret < 0) {
12600 		printf("Cannot get hash global configurations by port %d\n",
12601 							res->port_id);
12602 		return;
12603 	}
12604 
12605 	switch (info.info.global_conf.hash_func) {
12606 	case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12607 		printf("Hash function is Toeplitz\n");
12608 		break;
12609 	case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12610 		printf("Hash function is Simple XOR\n");
12611 		break;
12612 	case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12613 		printf("Hash function is Symmetric Toeplitz\n");
12614 		break;
12615 	default:
12616 		printf("Unknown hash function\n");
12617 		break;
12618 	}
12619 
12620 	for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12621 		idx = i / UINT64_BIT;
12622 		offset = i % UINT64_BIT;
12623 		if (!(info.info.global_conf.valid_bit_mask[idx] &
12624 						(1ULL << offset)))
12625 			continue;
12626 		str = flowtype_to_str(i);
12627 		if (!str)
12628 			continue;
12629 		printf("Symmetric hash is %s globally for flow type %s "
12630 							"by port %d\n",
12631 			((info.info.global_conf.sym_hash_enable_mask[idx] &
12632 			(1ULL << offset)) ? "enabled" : "disabled"), str,
12633 							res->port_id);
12634 	}
12635 }
12636 
12637 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12638 	TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12639 		get_hash_global_config, "get_hash_global_config");
12640 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12641 	TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12642 		port_id, UINT16);
12643 
12644 cmdline_parse_inst_t cmd_get_hash_global_config = {
12645 	.f = cmd_get_hash_global_config_parsed,
12646 	.data = NULL,
12647 	.help_str = "get_hash_global_config <port_id>",
12648 	.tokens = {
12649 		(void *)&cmd_get_hash_global_config_all,
12650 		(void *)&cmd_get_hash_global_config_port_id,
12651 		NULL,
12652 	},
12653 };
12654 
12655 /* Set global config of hash function */
12656 struct cmd_set_hash_global_config_result {
12657 	cmdline_fixed_string_t set_hash_global_config;
12658 	portid_t port_id;
12659 	cmdline_fixed_string_t hash_func;
12660 	cmdline_fixed_string_t flow_type;
12661 	cmdline_fixed_string_t enable;
12662 };
12663 
12664 static void
12665 cmd_set_hash_global_config_parsed(void *parsed_result,
12666 				  __rte_unused struct cmdline *cl,
12667 				  __rte_unused void *data)
12668 {
12669 	struct cmd_set_hash_global_config_result *res = parsed_result;
12670 	struct rte_eth_hash_filter_info info;
12671 	uint32_t ftype, idx, offset;
12672 	int ret;
12673 
12674 	if (rte_eth_dev_filter_supported(res->port_id,
12675 				RTE_ETH_FILTER_HASH) < 0) {
12676 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12677 							res->port_id);
12678 		return;
12679 	}
12680 	memset(&info, 0, sizeof(info));
12681 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12682 	if (!strcmp(res->hash_func, "toeplitz"))
12683 		info.info.global_conf.hash_func =
12684 			RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12685 	else if (!strcmp(res->hash_func, "simple_xor"))
12686 		info.info.global_conf.hash_func =
12687 			RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12688 	else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12689 		info.info.global_conf.hash_func =
12690 			RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12691 	else if (!strcmp(res->hash_func, "default"))
12692 		info.info.global_conf.hash_func =
12693 			RTE_ETH_HASH_FUNCTION_DEFAULT;
12694 
12695 	ftype = str2flowtype(res->flow_type);
12696 	idx = ftype / UINT64_BIT;
12697 	offset = ftype % UINT64_BIT;
12698 	info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12699 	if (!strcmp(res->enable, "enable"))
12700 		info.info.global_conf.sym_hash_enable_mask[idx] |=
12701 						(1ULL << offset);
12702 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12703 					RTE_ETH_FILTER_SET, &info);
12704 	if (ret < 0)
12705 		printf("Cannot set global hash configurations by port %d\n",
12706 							res->port_id);
12707 	else
12708 		printf("Global hash configurations have been set "
12709 			"successfully by port %d\n", res->port_id);
12710 }
12711 
12712 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12713 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12714 		set_hash_global_config, "set_hash_global_config");
12715 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12716 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12717 		port_id, UINT16);
12718 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12719 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12720 		hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12721 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12722 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12723 		flow_type,
12724 		"ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12725 		"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12726 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12727 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12728 		enable, "enable#disable");
12729 
12730 cmdline_parse_inst_t cmd_set_hash_global_config = {
12731 	.f = cmd_set_hash_global_config_parsed,
12732 	.data = NULL,
12733 	.help_str = "set_hash_global_config <port_id> "
12734 		"toeplitz|simple_xor|symmetric_toeplitz|default "
12735 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12736 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12737 		"l2_payload enable|disable",
12738 	.tokens = {
12739 		(void *)&cmd_set_hash_global_config_all,
12740 		(void *)&cmd_set_hash_global_config_port_id,
12741 		(void *)&cmd_set_hash_global_config_hash_func,
12742 		(void *)&cmd_set_hash_global_config_flow_type,
12743 		(void *)&cmd_set_hash_global_config_enable,
12744 		NULL,
12745 	},
12746 };
12747 
12748 /* Set hash input set */
12749 struct cmd_set_hash_input_set_result {
12750 	cmdline_fixed_string_t set_hash_input_set;
12751 	portid_t port_id;
12752 	cmdline_fixed_string_t flow_type;
12753 	cmdline_fixed_string_t inset_field;
12754 	cmdline_fixed_string_t select;
12755 };
12756 
12757 static enum rte_eth_input_set_field
12758 str2inset(char *string)
12759 {
12760 	uint16_t i;
12761 
12762 	static const struct {
12763 		char str[32];
12764 		enum rte_eth_input_set_field inset;
12765 	} inset_table[] = {
12766 		{"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12767 		{"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12768 		{"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12769 		{"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12770 		{"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12771 		{"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12772 		{"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12773 		{"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12774 		{"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12775 		{"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12776 		{"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12777 		{"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12778 		{"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12779 		{"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12780 		{"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12781 		{"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12782 		{"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12783 		{"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12784 		{"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12785 		{"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12786 		{"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12787 		{"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12788 		{"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12789 		{"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12790 		{"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12791 		{"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12792 		{"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12793 		{"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12794 		{"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12795 		{"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12796 		{"none", RTE_ETH_INPUT_SET_NONE},
12797 	};
12798 
12799 	for (i = 0; i < RTE_DIM(inset_table); i++) {
12800 		if (!strcmp(string, inset_table[i].str))
12801 			return inset_table[i].inset;
12802 	}
12803 
12804 	return RTE_ETH_INPUT_SET_UNKNOWN;
12805 }
12806 
12807 static void
12808 cmd_set_hash_input_set_parsed(void *parsed_result,
12809 			      __rte_unused struct cmdline *cl,
12810 			      __rte_unused void *data)
12811 {
12812 	struct cmd_set_hash_input_set_result *res = parsed_result;
12813 	struct rte_eth_hash_filter_info info;
12814 
12815 	memset(&info, 0, sizeof(info));
12816 	info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12817 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12818 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12819 	info.info.input_set_conf.inset_size = 1;
12820 	if (!strcmp(res->select, "select"))
12821 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12822 	else if (!strcmp(res->select, "add"))
12823 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12824 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12825 				RTE_ETH_FILTER_SET, &info);
12826 }
12827 
12828 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12829 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12830 		set_hash_input_set, "set_hash_input_set");
12831 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12832 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12833 		port_id, UINT16);
12834 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12835 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12836 		flow_type, NULL);
12837 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12838 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12839 		inset_field,
12840 		"ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12841 		"ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12842 		"udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12843 		"sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12844 		"fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12845 		"fld-8th#none");
12846 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12847 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12848 		select, "select#add");
12849 
12850 cmdline_parse_inst_t cmd_set_hash_input_set = {
12851 	.f = cmd_set_hash_input_set_parsed,
12852 	.data = NULL,
12853 	.help_str = "set_hash_input_set <port_id> "
12854 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12855 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12856 	"ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12857 	"ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12858 	"tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12859 	"gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12860 	"fld-7th|fld-8th|none select|add",
12861 	.tokens = {
12862 		(void *)&cmd_set_hash_input_set_cmd,
12863 		(void *)&cmd_set_hash_input_set_port_id,
12864 		(void *)&cmd_set_hash_input_set_flow_type,
12865 		(void *)&cmd_set_hash_input_set_field,
12866 		(void *)&cmd_set_hash_input_set_select,
12867 		NULL,
12868 	},
12869 };
12870 
12871 /* Set flow director input set */
12872 struct cmd_set_fdir_input_set_result {
12873 	cmdline_fixed_string_t set_fdir_input_set;
12874 	portid_t port_id;
12875 	cmdline_fixed_string_t flow_type;
12876 	cmdline_fixed_string_t inset_field;
12877 	cmdline_fixed_string_t select;
12878 };
12879 
12880 static void
12881 cmd_set_fdir_input_set_parsed(void *parsed_result,
12882 	__rte_unused struct cmdline *cl,
12883 	__rte_unused void *data)
12884 {
12885 	struct cmd_set_fdir_input_set_result *res = parsed_result;
12886 	struct rte_eth_fdir_filter_info info;
12887 
12888 	memset(&info, 0, sizeof(info));
12889 	info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12890 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12891 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12892 	info.info.input_set_conf.inset_size = 1;
12893 	if (!strcmp(res->select, "select"))
12894 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12895 	else if (!strcmp(res->select, "add"))
12896 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12897 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12898 		RTE_ETH_FILTER_SET, &info);
12899 }
12900 
12901 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12902 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12903 	set_fdir_input_set, "set_fdir_input_set");
12904 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12905 	TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12906 	port_id, UINT16);
12907 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12908 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12909 	flow_type,
12910 	"ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12911 	"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12912 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12913 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12914 	inset_field,
12915 	"ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12916 	"ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12917 	"ipv6-hop-limits#udp-src-port#udp-dst-port#"
12918 	"tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12919 	"sctp-veri-tag#none");
12920 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12921 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12922 	select, "select#add");
12923 
12924 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12925 	.f = cmd_set_fdir_input_set_parsed,
12926 	.data = NULL,
12927 	.help_str = "set_fdir_input_set <port_id> "
12928 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12929 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12930 	"ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12931 	"ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12932 	"ipv6-hop-limits|udp-src-port|udp-dst-port|"
12933 	"tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12934 	"sctp-veri-tag|none select|add",
12935 	.tokens = {
12936 		(void *)&cmd_set_fdir_input_set_cmd,
12937 		(void *)&cmd_set_fdir_input_set_port_id,
12938 		(void *)&cmd_set_fdir_input_set_flow_type,
12939 		(void *)&cmd_set_fdir_input_set_field,
12940 		(void *)&cmd_set_fdir_input_set_select,
12941 		NULL,
12942 	},
12943 };
12944 
12945 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12946 struct cmd_mcast_addr_result {
12947 	cmdline_fixed_string_t mcast_addr_cmd;
12948 	cmdline_fixed_string_t what;
12949 	uint16_t port_num;
12950 	struct rte_ether_addr mc_addr;
12951 };
12952 
12953 static void cmd_mcast_addr_parsed(void *parsed_result,
12954 		__rte_unused struct cmdline *cl,
12955 		__rte_unused void *data)
12956 {
12957 	struct cmd_mcast_addr_result *res = parsed_result;
12958 
12959 	if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12960 		printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12961 		       res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12962 		       res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12963 		       res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12964 		return;
12965 	}
12966 	if (strcmp(res->what, "add") == 0)
12967 		mcast_addr_add(res->port_num, &res->mc_addr);
12968 	else
12969 		mcast_addr_remove(res->port_num, &res->mc_addr);
12970 }
12971 
12972 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12973 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12974 				 mcast_addr_cmd, "mcast_addr");
12975 cmdline_parse_token_string_t cmd_mcast_addr_what =
12976 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12977 				 "add#remove");
12978 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12979 	TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12980 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12981 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12982 
12983 cmdline_parse_inst_t cmd_mcast_addr = {
12984 	.f = cmd_mcast_addr_parsed,
12985 	.data = (void *)0,
12986 	.help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12987 		"Add/Remove multicast MAC address on port_id",
12988 	.tokens = {
12989 		(void *)&cmd_mcast_addr_cmd,
12990 		(void *)&cmd_mcast_addr_what,
12991 		(void *)&cmd_mcast_addr_portnum,
12992 		(void *)&cmd_mcast_addr_addr,
12993 		NULL,
12994 	},
12995 };
12996 
12997 /* l2 tunnel config
12998  * only support E-tag now.
12999  */
13000 
13001 /* Ether type config */
13002 struct cmd_config_l2_tunnel_eth_type_result {
13003 	cmdline_fixed_string_t port;
13004 	cmdline_fixed_string_t config;
13005 	cmdline_fixed_string_t all;
13006 	portid_t id;
13007 	cmdline_fixed_string_t l2_tunnel;
13008 	cmdline_fixed_string_t l2_tunnel_type;
13009 	cmdline_fixed_string_t eth_type;
13010 	uint16_t eth_type_val;
13011 };
13012 
13013 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
13014 	TOKEN_STRING_INITIALIZER
13015 		(struct cmd_config_l2_tunnel_eth_type_result,
13016 		 port, "port");
13017 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
13018 	TOKEN_STRING_INITIALIZER
13019 		(struct cmd_config_l2_tunnel_eth_type_result,
13020 		 config, "config");
13021 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
13022 	TOKEN_STRING_INITIALIZER
13023 		(struct cmd_config_l2_tunnel_eth_type_result,
13024 		 all, "all");
13025 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
13026 	TOKEN_NUM_INITIALIZER
13027 		(struct cmd_config_l2_tunnel_eth_type_result,
13028 		 id, UINT16);
13029 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
13030 	TOKEN_STRING_INITIALIZER
13031 		(struct cmd_config_l2_tunnel_eth_type_result,
13032 		 l2_tunnel, "l2-tunnel");
13033 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
13034 	TOKEN_STRING_INITIALIZER
13035 		(struct cmd_config_l2_tunnel_eth_type_result,
13036 		 l2_tunnel_type, "E-tag");
13037 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
13038 	TOKEN_STRING_INITIALIZER
13039 		(struct cmd_config_l2_tunnel_eth_type_result,
13040 		 eth_type, "ether-type");
13041 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
13042 	TOKEN_NUM_INITIALIZER
13043 		(struct cmd_config_l2_tunnel_eth_type_result,
13044 		 eth_type_val, UINT16);
13045 
13046 static enum rte_eth_tunnel_type
13047 str2fdir_l2_tunnel_type(char *string)
13048 {
13049 	uint32_t i = 0;
13050 
13051 	static const struct {
13052 		char str[32];
13053 		enum rte_eth_tunnel_type type;
13054 	} l2_tunnel_type_str[] = {
13055 		{"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
13056 	};
13057 
13058 	for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
13059 		if (!strcmp(l2_tunnel_type_str[i].str, string))
13060 			return l2_tunnel_type_str[i].type;
13061 	}
13062 	return RTE_TUNNEL_TYPE_NONE;
13063 }
13064 
13065 /* ether type config for all ports */
13066 static void
13067 cmd_config_l2_tunnel_eth_type_all_parsed
13068 	(void *parsed_result,
13069 	 __rte_unused struct cmdline *cl,
13070 	 __rte_unused void *data)
13071 {
13072 	struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
13073 	struct rte_eth_l2_tunnel_conf entry;
13074 	portid_t pid;
13075 
13076 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13077 	entry.ether_type = res->eth_type_val;
13078 
13079 	RTE_ETH_FOREACH_DEV(pid) {
13080 		rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
13081 	}
13082 }
13083 
13084 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
13085 	.f = cmd_config_l2_tunnel_eth_type_all_parsed,
13086 	.data = NULL,
13087 	.help_str = "port config all l2-tunnel E-tag ether-type <value>",
13088 	.tokens = {
13089 		(void *)&cmd_config_l2_tunnel_eth_type_port,
13090 		(void *)&cmd_config_l2_tunnel_eth_type_config,
13091 		(void *)&cmd_config_l2_tunnel_eth_type_all_str,
13092 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13093 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13094 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13095 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13096 		NULL,
13097 	},
13098 };
13099 
13100 /* ether type config for a specific port */
13101 static void
13102 cmd_config_l2_tunnel_eth_type_specific_parsed(
13103 	void *parsed_result,
13104 	__rte_unused struct cmdline *cl,
13105 	__rte_unused void *data)
13106 {
13107 	struct cmd_config_l2_tunnel_eth_type_result *res =
13108 		 parsed_result;
13109 	struct rte_eth_l2_tunnel_conf entry;
13110 
13111 	if (port_id_is_invalid(res->id, ENABLED_WARN))
13112 		return;
13113 
13114 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13115 	entry.ether_type = res->eth_type_val;
13116 
13117 	rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
13118 }
13119 
13120 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
13121 	.f = cmd_config_l2_tunnel_eth_type_specific_parsed,
13122 	.data = NULL,
13123 	.help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
13124 	.tokens = {
13125 		(void *)&cmd_config_l2_tunnel_eth_type_port,
13126 		(void *)&cmd_config_l2_tunnel_eth_type_config,
13127 		(void *)&cmd_config_l2_tunnel_eth_type_id,
13128 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13129 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13130 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13131 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13132 		NULL,
13133 	},
13134 };
13135 
13136 /* Enable/disable l2 tunnel */
13137 struct cmd_config_l2_tunnel_en_dis_result {
13138 	cmdline_fixed_string_t port;
13139 	cmdline_fixed_string_t config;
13140 	cmdline_fixed_string_t all;
13141 	portid_t id;
13142 	cmdline_fixed_string_t l2_tunnel;
13143 	cmdline_fixed_string_t l2_tunnel_type;
13144 	cmdline_fixed_string_t en_dis;
13145 };
13146 
13147 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
13148 	TOKEN_STRING_INITIALIZER
13149 		(struct cmd_config_l2_tunnel_en_dis_result,
13150 		 port, "port");
13151 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
13152 	TOKEN_STRING_INITIALIZER
13153 		(struct cmd_config_l2_tunnel_en_dis_result,
13154 		 config, "config");
13155 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
13156 	TOKEN_STRING_INITIALIZER
13157 		(struct cmd_config_l2_tunnel_en_dis_result,
13158 		 all, "all");
13159 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
13160 	TOKEN_NUM_INITIALIZER
13161 		(struct cmd_config_l2_tunnel_en_dis_result,
13162 		 id, UINT16);
13163 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
13164 	TOKEN_STRING_INITIALIZER
13165 		(struct cmd_config_l2_tunnel_en_dis_result,
13166 		 l2_tunnel, "l2-tunnel");
13167 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
13168 	TOKEN_STRING_INITIALIZER
13169 		(struct cmd_config_l2_tunnel_en_dis_result,
13170 		 l2_tunnel_type, "E-tag");
13171 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
13172 	TOKEN_STRING_INITIALIZER
13173 		(struct cmd_config_l2_tunnel_en_dis_result,
13174 		 en_dis, "enable#disable");
13175 
13176 /* enable/disable l2 tunnel for all ports */
13177 static void
13178 cmd_config_l2_tunnel_en_dis_all_parsed(
13179 	void *parsed_result,
13180 	__rte_unused struct cmdline *cl,
13181 	__rte_unused void *data)
13182 {
13183 	struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
13184 	struct rte_eth_l2_tunnel_conf entry;
13185 	portid_t pid;
13186 	uint8_t en;
13187 
13188 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13189 
13190 	if (!strcmp("enable", res->en_dis))
13191 		en = 1;
13192 	else
13193 		en = 0;
13194 
13195 	RTE_ETH_FOREACH_DEV(pid) {
13196 		rte_eth_dev_l2_tunnel_offload_set(pid,
13197 						  &entry,
13198 						  ETH_L2_TUNNEL_ENABLE_MASK,
13199 						  en);
13200 	}
13201 }
13202 
13203 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
13204 	.f = cmd_config_l2_tunnel_en_dis_all_parsed,
13205 	.data = NULL,
13206 	.help_str = "port config all l2-tunnel E-tag enable|disable",
13207 	.tokens = {
13208 		(void *)&cmd_config_l2_tunnel_en_dis_port,
13209 		(void *)&cmd_config_l2_tunnel_en_dis_config,
13210 		(void *)&cmd_config_l2_tunnel_en_dis_all_str,
13211 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13212 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13213 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13214 		NULL,
13215 	},
13216 };
13217 
13218 /* enable/disable l2 tunnel for a port */
13219 static void
13220 cmd_config_l2_tunnel_en_dis_specific_parsed(
13221 	void *parsed_result,
13222 	__rte_unused struct cmdline *cl,
13223 	__rte_unused void *data)
13224 {
13225 	struct cmd_config_l2_tunnel_en_dis_result *res =
13226 		parsed_result;
13227 	struct rte_eth_l2_tunnel_conf entry;
13228 
13229 	if (port_id_is_invalid(res->id, ENABLED_WARN))
13230 		return;
13231 
13232 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13233 
13234 	if (!strcmp("enable", res->en_dis))
13235 		rte_eth_dev_l2_tunnel_offload_set(res->id,
13236 						  &entry,
13237 						  ETH_L2_TUNNEL_ENABLE_MASK,
13238 						  1);
13239 	else
13240 		rte_eth_dev_l2_tunnel_offload_set(res->id,
13241 						  &entry,
13242 						  ETH_L2_TUNNEL_ENABLE_MASK,
13243 						  0);
13244 }
13245 
13246 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13247 	.f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13248 	.data = NULL,
13249 	.help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13250 	.tokens = {
13251 		(void *)&cmd_config_l2_tunnel_en_dis_port,
13252 		(void *)&cmd_config_l2_tunnel_en_dis_config,
13253 		(void *)&cmd_config_l2_tunnel_en_dis_id,
13254 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13255 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13256 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13257 		NULL,
13258 	},
13259 };
13260 
13261 /* E-tag configuration */
13262 
13263 /* Common result structure for all E-tag configuration */
13264 struct cmd_config_e_tag_result {
13265 	cmdline_fixed_string_t e_tag;
13266 	cmdline_fixed_string_t set;
13267 	cmdline_fixed_string_t insertion;
13268 	cmdline_fixed_string_t stripping;
13269 	cmdline_fixed_string_t forwarding;
13270 	cmdline_fixed_string_t filter;
13271 	cmdline_fixed_string_t add;
13272 	cmdline_fixed_string_t del;
13273 	cmdline_fixed_string_t on;
13274 	cmdline_fixed_string_t off;
13275 	cmdline_fixed_string_t on_off;
13276 	cmdline_fixed_string_t port_tag_id;
13277 	uint32_t port_tag_id_val;
13278 	cmdline_fixed_string_t e_tag_id;
13279 	uint16_t e_tag_id_val;
13280 	cmdline_fixed_string_t dst_pool;
13281 	uint8_t dst_pool_val;
13282 	cmdline_fixed_string_t port;
13283 	portid_t port_id;
13284 	cmdline_fixed_string_t vf;
13285 	uint8_t vf_id;
13286 };
13287 
13288 /* Common CLI fields for all E-tag configuration */
13289 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13290 	TOKEN_STRING_INITIALIZER
13291 		(struct cmd_config_e_tag_result,
13292 		 e_tag, "E-tag");
13293 cmdline_parse_token_string_t cmd_config_e_tag_set =
13294 	TOKEN_STRING_INITIALIZER
13295 		(struct cmd_config_e_tag_result,
13296 		 set, "set");
13297 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13298 	TOKEN_STRING_INITIALIZER
13299 		(struct cmd_config_e_tag_result,
13300 		 insertion, "insertion");
13301 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13302 	TOKEN_STRING_INITIALIZER
13303 		(struct cmd_config_e_tag_result,
13304 		 stripping, "stripping");
13305 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13306 	TOKEN_STRING_INITIALIZER
13307 		(struct cmd_config_e_tag_result,
13308 		 forwarding, "forwarding");
13309 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13310 	TOKEN_STRING_INITIALIZER
13311 		(struct cmd_config_e_tag_result,
13312 		 filter, "filter");
13313 cmdline_parse_token_string_t cmd_config_e_tag_add =
13314 	TOKEN_STRING_INITIALIZER
13315 		(struct cmd_config_e_tag_result,
13316 		 add, "add");
13317 cmdline_parse_token_string_t cmd_config_e_tag_del =
13318 	TOKEN_STRING_INITIALIZER
13319 		(struct cmd_config_e_tag_result,
13320 		 del, "del");
13321 cmdline_parse_token_string_t cmd_config_e_tag_on =
13322 	TOKEN_STRING_INITIALIZER
13323 		(struct cmd_config_e_tag_result,
13324 		 on, "on");
13325 cmdline_parse_token_string_t cmd_config_e_tag_off =
13326 	TOKEN_STRING_INITIALIZER
13327 		(struct cmd_config_e_tag_result,
13328 		 off, "off");
13329 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13330 	TOKEN_STRING_INITIALIZER
13331 		(struct cmd_config_e_tag_result,
13332 		 on_off, "on#off");
13333 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13334 	TOKEN_STRING_INITIALIZER
13335 		(struct cmd_config_e_tag_result,
13336 		 port_tag_id, "port-tag-id");
13337 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13338 	TOKEN_NUM_INITIALIZER
13339 		(struct cmd_config_e_tag_result,
13340 		 port_tag_id_val, UINT32);
13341 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13342 	TOKEN_STRING_INITIALIZER
13343 		(struct cmd_config_e_tag_result,
13344 		 e_tag_id, "e-tag-id");
13345 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13346 	TOKEN_NUM_INITIALIZER
13347 		(struct cmd_config_e_tag_result,
13348 		 e_tag_id_val, UINT16);
13349 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13350 	TOKEN_STRING_INITIALIZER
13351 		(struct cmd_config_e_tag_result,
13352 		 dst_pool, "dst-pool");
13353 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13354 	TOKEN_NUM_INITIALIZER
13355 		(struct cmd_config_e_tag_result,
13356 		 dst_pool_val, UINT8);
13357 cmdline_parse_token_string_t cmd_config_e_tag_port =
13358 	TOKEN_STRING_INITIALIZER
13359 		(struct cmd_config_e_tag_result,
13360 		 port, "port");
13361 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13362 	TOKEN_NUM_INITIALIZER
13363 		(struct cmd_config_e_tag_result,
13364 		 port_id, UINT16);
13365 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13366 	TOKEN_STRING_INITIALIZER
13367 		(struct cmd_config_e_tag_result,
13368 		 vf, "vf");
13369 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13370 	TOKEN_NUM_INITIALIZER
13371 		(struct cmd_config_e_tag_result,
13372 		 vf_id, UINT8);
13373 
13374 /* E-tag insertion configuration */
13375 static void
13376 cmd_config_e_tag_insertion_en_parsed(
13377 	void *parsed_result,
13378 	__rte_unused struct cmdline *cl,
13379 	__rte_unused void *data)
13380 {
13381 	struct cmd_config_e_tag_result *res =
13382 		parsed_result;
13383 	struct rte_eth_l2_tunnel_conf entry;
13384 
13385 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13386 		return;
13387 
13388 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13389 	entry.tunnel_id = res->port_tag_id_val;
13390 	entry.vf_id = res->vf_id;
13391 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13392 					  &entry,
13393 					  ETH_L2_TUNNEL_INSERTION_MASK,
13394 					  1);
13395 }
13396 
13397 static void
13398 cmd_config_e_tag_insertion_dis_parsed(
13399 	void *parsed_result,
13400 	__rte_unused struct cmdline *cl,
13401 	__rte_unused void *data)
13402 {
13403 	struct cmd_config_e_tag_result *res =
13404 		parsed_result;
13405 	struct rte_eth_l2_tunnel_conf entry;
13406 
13407 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13408 		return;
13409 
13410 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13411 	entry.vf_id = res->vf_id;
13412 
13413 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13414 					  &entry,
13415 					  ETH_L2_TUNNEL_INSERTION_MASK,
13416 					  0);
13417 }
13418 
13419 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13420 	.f = cmd_config_e_tag_insertion_en_parsed,
13421 	.data = NULL,
13422 	.help_str = "E-tag ... : E-tag insertion enable",
13423 	.tokens = {
13424 		(void *)&cmd_config_e_tag_e_tag,
13425 		(void *)&cmd_config_e_tag_set,
13426 		(void *)&cmd_config_e_tag_insertion,
13427 		(void *)&cmd_config_e_tag_on,
13428 		(void *)&cmd_config_e_tag_port_tag_id,
13429 		(void *)&cmd_config_e_tag_port_tag_id_val,
13430 		(void *)&cmd_config_e_tag_port,
13431 		(void *)&cmd_config_e_tag_port_id,
13432 		(void *)&cmd_config_e_tag_vf,
13433 		(void *)&cmd_config_e_tag_vf_id,
13434 		NULL,
13435 	},
13436 };
13437 
13438 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13439 	.f = cmd_config_e_tag_insertion_dis_parsed,
13440 	.data = NULL,
13441 	.help_str = "E-tag ... : E-tag insertion disable",
13442 	.tokens = {
13443 		(void *)&cmd_config_e_tag_e_tag,
13444 		(void *)&cmd_config_e_tag_set,
13445 		(void *)&cmd_config_e_tag_insertion,
13446 		(void *)&cmd_config_e_tag_off,
13447 		(void *)&cmd_config_e_tag_port,
13448 		(void *)&cmd_config_e_tag_port_id,
13449 		(void *)&cmd_config_e_tag_vf,
13450 		(void *)&cmd_config_e_tag_vf_id,
13451 		NULL,
13452 	},
13453 };
13454 
13455 /* E-tag stripping configuration */
13456 static void
13457 cmd_config_e_tag_stripping_parsed(
13458 	void *parsed_result,
13459 	__rte_unused struct cmdline *cl,
13460 	__rte_unused void *data)
13461 {
13462 	struct cmd_config_e_tag_result *res =
13463 		parsed_result;
13464 	struct rte_eth_l2_tunnel_conf entry;
13465 
13466 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13467 		return;
13468 
13469 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13470 
13471 	if (!strcmp(res->on_off, "on"))
13472 		rte_eth_dev_l2_tunnel_offload_set
13473 			(res->port_id,
13474 			 &entry,
13475 			 ETH_L2_TUNNEL_STRIPPING_MASK,
13476 			 1);
13477 	else
13478 		rte_eth_dev_l2_tunnel_offload_set
13479 			(res->port_id,
13480 			 &entry,
13481 			 ETH_L2_TUNNEL_STRIPPING_MASK,
13482 			 0);
13483 }
13484 
13485 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13486 	.f = cmd_config_e_tag_stripping_parsed,
13487 	.data = NULL,
13488 	.help_str = "E-tag ... : E-tag stripping enable/disable",
13489 	.tokens = {
13490 		(void *)&cmd_config_e_tag_e_tag,
13491 		(void *)&cmd_config_e_tag_set,
13492 		(void *)&cmd_config_e_tag_stripping,
13493 		(void *)&cmd_config_e_tag_on_off,
13494 		(void *)&cmd_config_e_tag_port,
13495 		(void *)&cmd_config_e_tag_port_id,
13496 		NULL,
13497 	},
13498 };
13499 
13500 /* E-tag forwarding configuration */
13501 static void
13502 cmd_config_e_tag_forwarding_parsed(
13503 	void *parsed_result,
13504 	__rte_unused struct cmdline *cl,
13505 	__rte_unused void *data)
13506 {
13507 	struct cmd_config_e_tag_result *res = parsed_result;
13508 	struct rte_eth_l2_tunnel_conf entry;
13509 
13510 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13511 		return;
13512 
13513 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13514 
13515 	if (!strcmp(res->on_off, "on"))
13516 		rte_eth_dev_l2_tunnel_offload_set
13517 			(res->port_id,
13518 			 &entry,
13519 			 ETH_L2_TUNNEL_FORWARDING_MASK,
13520 			 1);
13521 	else
13522 		rte_eth_dev_l2_tunnel_offload_set
13523 			(res->port_id,
13524 			 &entry,
13525 			 ETH_L2_TUNNEL_FORWARDING_MASK,
13526 			 0);
13527 }
13528 
13529 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13530 	.f = cmd_config_e_tag_forwarding_parsed,
13531 	.data = NULL,
13532 	.help_str = "E-tag ... : E-tag forwarding enable/disable",
13533 	.tokens = {
13534 		(void *)&cmd_config_e_tag_e_tag,
13535 		(void *)&cmd_config_e_tag_set,
13536 		(void *)&cmd_config_e_tag_forwarding,
13537 		(void *)&cmd_config_e_tag_on_off,
13538 		(void *)&cmd_config_e_tag_port,
13539 		(void *)&cmd_config_e_tag_port_id,
13540 		NULL,
13541 	},
13542 };
13543 
13544 /* E-tag filter configuration */
13545 static void
13546 cmd_config_e_tag_filter_add_parsed(
13547 	void *parsed_result,
13548 	__rte_unused struct cmdline *cl,
13549 	__rte_unused void *data)
13550 {
13551 	struct cmd_config_e_tag_result *res = parsed_result;
13552 	struct rte_eth_l2_tunnel_conf entry;
13553 	int ret = 0;
13554 
13555 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13556 		return;
13557 
13558 	if (res->e_tag_id_val > 0x3fff) {
13559 		printf("e-tag-id must be equal or less than 0x3fff.\n");
13560 		return;
13561 	}
13562 
13563 	ret = rte_eth_dev_filter_supported(res->port_id,
13564 					   RTE_ETH_FILTER_L2_TUNNEL);
13565 	if (ret < 0) {
13566 		printf("E-tag filter is not supported on port %u.\n",
13567 		       res->port_id);
13568 		return;
13569 	}
13570 
13571 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13572 	entry.tunnel_id = res->e_tag_id_val;
13573 	entry.pool = res->dst_pool_val;
13574 
13575 	ret = rte_eth_dev_filter_ctrl(res->port_id,
13576 				      RTE_ETH_FILTER_L2_TUNNEL,
13577 				      RTE_ETH_FILTER_ADD,
13578 				      &entry);
13579 	if (ret < 0)
13580 		printf("E-tag filter programming error: (%s)\n",
13581 		       strerror(-ret));
13582 }
13583 
13584 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13585 	.f = cmd_config_e_tag_filter_add_parsed,
13586 	.data = NULL,
13587 	.help_str = "E-tag ... : E-tag filter add",
13588 	.tokens = {
13589 		(void *)&cmd_config_e_tag_e_tag,
13590 		(void *)&cmd_config_e_tag_set,
13591 		(void *)&cmd_config_e_tag_filter,
13592 		(void *)&cmd_config_e_tag_add,
13593 		(void *)&cmd_config_e_tag_e_tag_id,
13594 		(void *)&cmd_config_e_tag_e_tag_id_val,
13595 		(void *)&cmd_config_e_tag_dst_pool,
13596 		(void *)&cmd_config_e_tag_dst_pool_val,
13597 		(void *)&cmd_config_e_tag_port,
13598 		(void *)&cmd_config_e_tag_port_id,
13599 		NULL,
13600 	},
13601 };
13602 
13603 static void
13604 cmd_config_e_tag_filter_del_parsed(
13605 	void *parsed_result,
13606 	__rte_unused struct cmdline *cl,
13607 	__rte_unused void *data)
13608 {
13609 	struct cmd_config_e_tag_result *res = parsed_result;
13610 	struct rte_eth_l2_tunnel_conf entry;
13611 	int ret = 0;
13612 
13613 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13614 		return;
13615 
13616 	if (res->e_tag_id_val > 0x3fff) {
13617 		printf("e-tag-id must be less than 0x3fff.\n");
13618 		return;
13619 	}
13620 
13621 	ret = rte_eth_dev_filter_supported(res->port_id,
13622 					   RTE_ETH_FILTER_L2_TUNNEL);
13623 	if (ret < 0) {
13624 		printf("E-tag filter is not supported on port %u.\n",
13625 		       res->port_id);
13626 		return;
13627 	}
13628 
13629 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13630 	entry.tunnel_id = res->e_tag_id_val;
13631 
13632 	ret = rte_eth_dev_filter_ctrl(res->port_id,
13633 				      RTE_ETH_FILTER_L2_TUNNEL,
13634 				      RTE_ETH_FILTER_DELETE,
13635 				      &entry);
13636 	if (ret < 0)
13637 		printf("E-tag filter programming error: (%s)\n",
13638 		       strerror(-ret));
13639 }
13640 
13641 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13642 	.f = cmd_config_e_tag_filter_del_parsed,
13643 	.data = NULL,
13644 	.help_str = "E-tag ... : E-tag filter delete",
13645 	.tokens = {
13646 		(void *)&cmd_config_e_tag_e_tag,
13647 		(void *)&cmd_config_e_tag_set,
13648 		(void *)&cmd_config_e_tag_filter,
13649 		(void *)&cmd_config_e_tag_del,
13650 		(void *)&cmd_config_e_tag_e_tag_id,
13651 		(void *)&cmd_config_e_tag_e_tag_id_val,
13652 		(void *)&cmd_config_e_tag_port,
13653 		(void *)&cmd_config_e_tag_port_id,
13654 		NULL,
13655 	},
13656 };
13657 
13658 /* vf vlan anti spoof configuration */
13659 
13660 /* Common result structure for vf vlan anti spoof */
13661 struct cmd_vf_vlan_anti_spoof_result {
13662 	cmdline_fixed_string_t set;
13663 	cmdline_fixed_string_t vf;
13664 	cmdline_fixed_string_t vlan;
13665 	cmdline_fixed_string_t antispoof;
13666 	portid_t port_id;
13667 	uint32_t vf_id;
13668 	cmdline_fixed_string_t on_off;
13669 };
13670 
13671 /* Common CLI fields for vf vlan anti spoof enable disable */
13672 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13673 	TOKEN_STRING_INITIALIZER
13674 		(struct cmd_vf_vlan_anti_spoof_result,
13675 		 set, "set");
13676 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13677 	TOKEN_STRING_INITIALIZER
13678 		(struct cmd_vf_vlan_anti_spoof_result,
13679 		 vf, "vf");
13680 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13681 	TOKEN_STRING_INITIALIZER
13682 		(struct cmd_vf_vlan_anti_spoof_result,
13683 		 vlan, "vlan");
13684 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13685 	TOKEN_STRING_INITIALIZER
13686 		(struct cmd_vf_vlan_anti_spoof_result,
13687 		 antispoof, "antispoof");
13688 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13689 	TOKEN_NUM_INITIALIZER
13690 		(struct cmd_vf_vlan_anti_spoof_result,
13691 		 port_id, UINT16);
13692 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13693 	TOKEN_NUM_INITIALIZER
13694 		(struct cmd_vf_vlan_anti_spoof_result,
13695 		 vf_id, UINT32);
13696 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13697 	TOKEN_STRING_INITIALIZER
13698 		(struct cmd_vf_vlan_anti_spoof_result,
13699 		 on_off, "on#off");
13700 
13701 static void
13702 cmd_set_vf_vlan_anti_spoof_parsed(
13703 	void *parsed_result,
13704 	__rte_unused struct cmdline *cl,
13705 	__rte_unused void *data)
13706 {
13707 	struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13708 	int ret = -ENOTSUP;
13709 
13710 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13711 
13712 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13713 		return;
13714 
13715 #ifdef RTE_LIBRTE_IXGBE_PMD
13716 	if (ret == -ENOTSUP)
13717 		ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13718 				res->vf_id, is_on);
13719 #endif
13720 #ifdef RTE_LIBRTE_I40E_PMD
13721 	if (ret == -ENOTSUP)
13722 		ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13723 				res->vf_id, is_on);
13724 #endif
13725 #ifdef RTE_LIBRTE_BNXT_PMD
13726 	if (ret == -ENOTSUP)
13727 		ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13728 				res->vf_id, is_on);
13729 #endif
13730 
13731 	switch (ret) {
13732 	case 0:
13733 		break;
13734 	case -EINVAL:
13735 		printf("invalid vf_id %d\n", res->vf_id);
13736 		break;
13737 	case -ENODEV:
13738 		printf("invalid port_id %d\n", res->port_id);
13739 		break;
13740 	case -ENOTSUP:
13741 		printf("function not implemented\n");
13742 		break;
13743 	default:
13744 		printf("programming error: (%s)\n", strerror(-ret));
13745 	}
13746 }
13747 
13748 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13749 	.f = cmd_set_vf_vlan_anti_spoof_parsed,
13750 	.data = NULL,
13751 	.help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13752 	.tokens = {
13753 		(void *)&cmd_vf_vlan_anti_spoof_set,
13754 		(void *)&cmd_vf_vlan_anti_spoof_vf,
13755 		(void *)&cmd_vf_vlan_anti_spoof_vlan,
13756 		(void *)&cmd_vf_vlan_anti_spoof_antispoof,
13757 		(void *)&cmd_vf_vlan_anti_spoof_port_id,
13758 		(void *)&cmd_vf_vlan_anti_spoof_vf_id,
13759 		(void *)&cmd_vf_vlan_anti_spoof_on_off,
13760 		NULL,
13761 	},
13762 };
13763 
13764 /* vf mac anti spoof configuration */
13765 
13766 /* Common result structure for vf mac anti spoof */
13767 struct cmd_vf_mac_anti_spoof_result {
13768 	cmdline_fixed_string_t set;
13769 	cmdline_fixed_string_t vf;
13770 	cmdline_fixed_string_t mac;
13771 	cmdline_fixed_string_t antispoof;
13772 	portid_t port_id;
13773 	uint32_t vf_id;
13774 	cmdline_fixed_string_t on_off;
13775 };
13776 
13777 /* Common CLI fields for vf mac anti spoof enable disable */
13778 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13779 	TOKEN_STRING_INITIALIZER
13780 		(struct cmd_vf_mac_anti_spoof_result,
13781 		 set, "set");
13782 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13783 	TOKEN_STRING_INITIALIZER
13784 		(struct cmd_vf_mac_anti_spoof_result,
13785 		 vf, "vf");
13786 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13787 	TOKEN_STRING_INITIALIZER
13788 		(struct cmd_vf_mac_anti_spoof_result,
13789 		 mac, "mac");
13790 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13791 	TOKEN_STRING_INITIALIZER
13792 		(struct cmd_vf_mac_anti_spoof_result,
13793 		 antispoof, "antispoof");
13794 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13795 	TOKEN_NUM_INITIALIZER
13796 		(struct cmd_vf_mac_anti_spoof_result,
13797 		 port_id, UINT16);
13798 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13799 	TOKEN_NUM_INITIALIZER
13800 		(struct cmd_vf_mac_anti_spoof_result,
13801 		 vf_id, UINT32);
13802 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13803 	TOKEN_STRING_INITIALIZER
13804 		(struct cmd_vf_mac_anti_spoof_result,
13805 		 on_off, "on#off");
13806 
13807 static void
13808 cmd_set_vf_mac_anti_spoof_parsed(
13809 	void *parsed_result,
13810 	__rte_unused struct cmdline *cl,
13811 	__rte_unused void *data)
13812 {
13813 	struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13814 	int ret = -ENOTSUP;
13815 
13816 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13817 
13818 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13819 		return;
13820 
13821 #ifdef RTE_LIBRTE_IXGBE_PMD
13822 	if (ret == -ENOTSUP)
13823 		ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13824 			res->vf_id, is_on);
13825 #endif
13826 #ifdef RTE_LIBRTE_I40E_PMD
13827 	if (ret == -ENOTSUP)
13828 		ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13829 			res->vf_id, is_on);
13830 #endif
13831 #ifdef RTE_LIBRTE_BNXT_PMD
13832 	if (ret == -ENOTSUP)
13833 		ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13834 			res->vf_id, is_on);
13835 #endif
13836 
13837 	switch (ret) {
13838 	case 0:
13839 		break;
13840 	case -EINVAL:
13841 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13842 		break;
13843 	case -ENODEV:
13844 		printf("invalid port_id %d\n", res->port_id);
13845 		break;
13846 	case -ENOTSUP:
13847 		printf("function not implemented\n");
13848 		break;
13849 	default:
13850 		printf("programming error: (%s)\n", strerror(-ret));
13851 	}
13852 }
13853 
13854 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13855 	.f = cmd_set_vf_mac_anti_spoof_parsed,
13856 	.data = NULL,
13857 	.help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13858 	.tokens = {
13859 		(void *)&cmd_vf_mac_anti_spoof_set,
13860 		(void *)&cmd_vf_mac_anti_spoof_vf,
13861 		(void *)&cmd_vf_mac_anti_spoof_mac,
13862 		(void *)&cmd_vf_mac_anti_spoof_antispoof,
13863 		(void *)&cmd_vf_mac_anti_spoof_port_id,
13864 		(void *)&cmd_vf_mac_anti_spoof_vf_id,
13865 		(void *)&cmd_vf_mac_anti_spoof_on_off,
13866 		NULL,
13867 	},
13868 };
13869 
13870 /* vf vlan strip queue configuration */
13871 
13872 /* Common result structure for vf mac anti spoof */
13873 struct cmd_vf_vlan_stripq_result {
13874 	cmdline_fixed_string_t set;
13875 	cmdline_fixed_string_t vf;
13876 	cmdline_fixed_string_t vlan;
13877 	cmdline_fixed_string_t stripq;
13878 	portid_t port_id;
13879 	uint16_t vf_id;
13880 	cmdline_fixed_string_t on_off;
13881 };
13882 
13883 /* Common CLI fields for vf vlan strip enable disable */
13884 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13885 	TOKEN_STRING_INITIALIZER
13886 		(struct cmd_vf_vlan_stripq_result,
13887 		 set, "set");
13888 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13889 	TOKEN_STRING_INITIALIZER
13890 		(struct cmd_vf_vlan_stripq_result,
13891 		 vf, "vf");
13892 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13893 	TOKEN_STRING_INITIALIZER
13894 		(struct cmd_vf_vlan_stripq_result,
13895 		 vlan, "vlan");
13896 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13897 	TOKEN_STRING_INITIALIZER
13898 		(struct cmd_vf_vlan_stripq_result,
13899 		 stripq, "stripq");
13900 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13901 	TOKEN_NUM_INITIALIZER
13902 		(struct cmd_vf_vlan_stripq_result,
13903 		 port_id, UINT16);
13904 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13905 	TOKEN_NUM_INITIALIZER
13906 		(struct cmd_vf_vlan_stripq_result,
13907 		 vf_id, UINT16);
13908 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13909 	TOKEN_STRING_INITIALIZER
13910 		(struct cmd_vf_vlan_stripq_result,
13911 		 on_off, "on#off");
13912 
13913 static void
13914 cmd_set_vf_vlan_stripq_parsed(
13915 	void *parsed_result,
13916 	__rte_unused struct cmdline *cl,
13917 	__rte_unused void *data)
13918 {
13919 	struct cmd_vf_vlan_stripq_result *res = parsed_result;
13920 	int ret = -ENOTSUP;
13921 
13922 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13923 
13924 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13925 		return;
13926 
13927 #ifdef RTE_LIBRTE_IXGBE_PMD
13928 	if (ret == -ENOTSUP)
13929 		ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13930 			res->vf_id, is_on);
13931 #endif
13932 #ifdef RTE_LIBRTE_I40E_PMD
13933 	if (ret == -ENOTSUP)
13934 		ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13935 			res->vf_id, is_on);
13936 #endif
13937 #ifdef RTE_LIBRTE_BNXT_PMD
13938 	if (ret == -ENOTSUP)
13939 		ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13940 			res->vf_id, is_on);
13941 #endif
13942 
13943 	switch (ret) {
13944 	case 0:
13945 		break;
13946 	case -EINVAL:
13947 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13948 		break;
13949 	case -ENODEV:
13950 		printf("invalid port_id %d\n", res->port_id);
13951 		break;
13952 	case -ENOTSUP:
13953 		printf("function not implemented\n");
13954 		break;
13955 	default:
13956 		printf("programming error: (%s)\n", strerror(-ret));
13957 	}
13958 }
13959 
13960 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13961 	.f = cmd_set_vf_vlan_stripq_parsed,
13962 	.data = NULL,
13963 	.help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13964 	.tokens = {
13965 		(void *)&cmd_vf_vlan_stripq_set,
13966 		(void *)&cmd_vf_vlan_stripq_vf,
13967 		(void *)&cmd_vf_vlan_stripq_vlan,
13968 		(void *)&cmd_vf_vlan_stripq_stripq,
13969 		(void *)&cmd_vf_vlan_stripq_port_id,
13970 		(void *)&cmd_vf_vlan_stripq_vf_id,
13971 		(void *)&cmd_vf_vlan_stripq_on_off,
13972 		NULL,
13973 	},
13974 };
13975 
13976 /* vf vlan insert configuration */
13977 
13978 /* Common result structure for vf vlan insert */
13979 struct cmd_vf_vlan_insert_result {
13980 	cmdline_fixed_string_t set;
13981 	cmdline_fixed_string_t vf;
13982 	cmdline_fixed_string_t vlan;
13983 	cmdline_fixed_string_t insert;
13984 	portid_t port_id;
13985 	uint16_t vf_id;
13986 	uint16_t vlan_id;
13987 };
13988 
13989 /* Common CLI fields for vf vlan insert enable disable */
13990 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13991 	TOKEN_STRING_INITIALIZER
13992 		(struct cmd_vf_vlan_insert_result,
13993 		 set, "set");
13994 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13995 	TOKEN_STRING_INITIALIZER
13996 		(struct cmd_vf_vlan_insert_result,
13997 		 vf, "vf");
13998 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13999 	TOKEN_STRING_INITIALIZER
14000 		(struct cmd_vf_vlan_insert_result,
14001 		 vlan, "vlan");
14002 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
14003 	TOKEN_STRING_INITIALIZER
14004 		(struct cmd_vf_vlan_insert_result,
14005 		 insert, "insert");
14006 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
14007 	TOKEN_NUM_INITIALIZER
14008 		(struct cmd_vf_vlan_insert_result,
14009 		 port_id, UINT16);
14010 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
14011 	TOKEN_NUM_INITIALIZER
14012 		(struct cmd_vf_vlan_insert_result,
14013 		 vf_id, UINT16);
14014 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
14015 	TOKEN_NUM_INITIALIZER
14016 		(struct cmd_vf_vlan_insert_result,
14017 		 vlan_id, UINT16);
14018 
14019 static void
14020 cmd_set_vf_vlan_insert_parsed(
14021 	void *parsed_result,
14022 	__rte_unused struct cmdline *cl,
14023 	__rte_unused void *data)
14024 {
14025 	struct cmd_vf_vlan_insert_result *res = parsed_result;
14026 	int ret = -ENOTSUP;
14027 
14028 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14029 		return;
14030 
14031 #ifdef RTE_LIBRTE_IXGBE_PMD
14032 	if (ret == -ENOTSUP)
14033 		ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
14034 			res->vlan_id);
14035 #endif
14036 #ifdef RTE_LIBRTE_I40E_PMD
14037 	if (ret == -ENOTSUP)
14038 		ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
14039 			res->vlan_id);
14040 #endif
14041 #ifdef RTE_LIBRTE_BNXT_PMD
14042 	if (ret == -ENOTSUP)
14043 		ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
14044 			res->vlan_id);
14045 #endif
14046 
14047 	switch (ret) {
14048 	case 0:
14049 		break;
14050 	case -EINVAL:
14051 		printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
14052 		break;
14053 	case -ENODEV:
14054 		printf("invalid port_id %d\n", res->port_id);
14055 		break;
14056 	case -ENOTSUP:
14057 		printf("function not implemented\n");
14058 		break;
14059 	default:
14060 		printf("programming error: (%s)\n", strerror(-ret));
14061 	}
14062 }
14063 
14064 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
14065 	.f = cmd_set_vf_vlan_insert_parsed,
14066 	.data = NULL,
14067 	.help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
14068 	.tokens = {
14069 		(void *)&cmd_vf_vlan_insert_set,
14070 		(void *)&cmd_vf_vlan_insert_vf,
14071 		(void *)&cmd_vf_vlan_insert_vlan,
14072 		(void *)&cmd_vf_vlan_insert_insert,
14073 		(void *)&cmd_vf_vlan_insert_port_id,
14074 		(void *)&cmd_vf_vlan_insert_vf_id,
14075 		(void *)&cmd_vf_vlan_insert_vlan_id,
14076 		NULL,
14077 	},
14078 };
14079 
14080 /* tx loopback configuration */
14081 
14082 /* Common result structure for tx loopback */
14083 struct cmd_tx_loopback_result {
14084 	cmdline_fixed_string_t set;
14085 	cmdline_fixed_string_t tx;
14086 	cmdline_fixed_string_t loopback;
14087 	portid_t port_id;
14088 	cmdline_fixed_string_t on_off;
14089 };
14090 
14091 /* Common CLI fields for tx loopback enable disable */
14092 cmdline_parse_token_string_t cmd_tx_loopback_set =
14093 	TOKEN_STRING_INITIALIZER
14094 		(struct cmd_tx_loopback_result,
14095 		 set, "set");
14096 cmdline_parse_token_string_t cmd_tx_loopback_tx =
14097 	TOKEN_STRING_INITIALIZER
14098 		(struct cmd_tx_loopback_result,
14099 		 tx, "tx");
14100 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
14101 	TOKEN_STRING_INITIALIZER
14102 		(struct cmd_tx_loopback_result,
14103 		 loopback, "loopback");
14104 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
14105 	TOKEN_NUM_INITIALIZER
14106 		(struct cmd_tx_loopback_result,
14107 		 port_id, UINT16);
14108 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
14109 	TOKEN_STRING_INITIALIZER
14110 		(struct cmd_tx_loopback_result,
14111 		 on_off, "on#off");
14112 
14113 static void
14114 cmd_set_tx_loopback_parsed(
14115 	void *parsed_result,
14116 	__rte_unused struct cmdline *cl,
14117 	__rte_unused void *data)
14118 {
14119 	struct cmd_tx_loopback_result *res = parsed_result;
14120 	int ret = -ENOTSUP;
14121 
14122 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14123 
14124 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14125 		return;
14126 
14127 #ifdef RTE_LIBRTE_IXGBE_PMD
14128 	if (ret == -ENOTSUP)
14129 		ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
14130 #endif
14131 #ifdef RTE_LIBRTE_I40E_PMD
14132 	if (ret == -ENOTSUP)
14133 		ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
14134 #endif
14135 #ifdef RTE_LIBRTE_BNXT_PMD
14136 	if (ret == -ENOTSUP)
14137 		ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
14138 #endif
14139 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
14140 	if (ret == -ENOTSUP)
14141 		ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
14142 #endif
14143 
14144 	switch (ret) {
14145 	case 0:
14146 		break;
14147 	case -EINVAL:
14148 		printf("invalid is_on %d\n", is_on);
14149 		break;
14150 	case -ENODEV:
14151 		printf("invalid port_id %d\n", res->port_id);
14152 		break;
14153 	case -ENOTSUP:
14154 		printf("function not implemented\n");
14155 		break;
14156 	default:
14157 		printf("programming error: (%s)\n", strerror(-ret));
14158 	}
14159 }
14160 
14161 cmdline_parse_inst_t cmd_set_tx_loopback = {
14162 	.f = cmd_set_tx_loopback_parsed,
14163 	.data = NULL,
14164 	.help_str = "set tx loopback <port_id> on|off",
14165 	.tokens = {
14166 		(void *)&cmd_tx_loopback_set,
14167 		(void *)&cmd_tx_loopback_tx,
14168 		(void *)&cmd_tx_loopback_loopback,
14169 		(void *)&cmd_tx_loopback_port_id,
14170 		(void *)&cmd_tx_loopback_on_off,
14171 		NULL,
14172 	},
14173 };
14174 
14175 /* all queues drop enable configuration */
14176 
14177 /* Common result structure for all queues drop enable */
14178 struct cmd_all_queues_drop_en_result {
14179 	cmdline_fixed_string_t set;
14180 	cmdline_fixed_string_t all;
14181 	cmdline_fixed_string_t queues;
14182 	cmdline_fixed_string_t drop;
14183 	portid_t port_id;
14184 	cmdline_fixed_string_t on_off;
14185 };
14186 
14187 /* Common CLI fields for tx loopback enable disable */
14188 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
14189 	TOKEN_STRING_INITIALIZER
14190 		(struct cmd_all_queues_drop_en_result,
14191 		 set, "set");
14192 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
14193 	TOKEN_STRING_INITIALIZER
14194 		(struct cmd_all_queues_drop_en_result,
14195 		 all, "all");
14196 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
14197 	TOKEN_STRING_INITIALIZER
14198 		(struct cmd_all_queues_drop_en_result,
14199 		 queues, "queues");
14200 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
14201 	TOKEN_STRING_INITIALIZER
14202 		(struct cmd_all_queues_drop_en_result,
14203 		 drop, "drop");
14204 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
14205 	TOKEN_NUM_INITIALIZER
14206 		(struct cmd_all_queues_drop_en_result,
14207 		 port_id, UINT16);
14208 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
14209 	TOKEN_STRING_INITIALIZER
14210 		(struct cmd_all_queues_drop_en_result,
14211 		 on_off, "on#off");
14212 
14213 static void
14214 cmd_set_all_queues_drop_en_parsed(
14215 	void *parsed_result,
14216 	__rte_unused struct cmdline *cl,
14217 	__rte_unused void *data)
14218 {
14219 	struct cmd_all_queues_drop_en_result *res = parsed_result;
14220 	int ret = -ENOTSUP;
14221 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14222 
14223 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14224 		return;
14225 
14226 #ifdef RTE_LIBRTE_IXGBE_PMD
14227 	if (ret == -ENOTSUP)
14228 		ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
14229 #endif
14230 #ifdef RTE_LIBRTE_BNXT_PMD
14231 	if (ret == -ENOTSUP)
14232 		ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
14233 #endif
14234 	switch (ret) {
14235 	case 0:
14236 		break;
14237 	case -EINVAL:
14238 		printf("invalid is_on %d\n", is_on);
14239 		break;
14240 	case -ENODEV:
14241 		printf("invalid port_id %d\n", res->port_id);
14242 		break;
14243 	case -ENOTSUP:
14244 		printf("function not implemented\n");
14245 		break;
14246 	default:
14247 		printf("programming error: (%s)\n", strerror(-ret));
14248 	}
14249 }
14250 
14251 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14252 	.f = cmd_set_all_queues_drop_en_parsed,
14253 	.data = NULL,
14254 	.help_str = "set all queues drop <port_id> on|off",
14255 	.tokens = {
14256 		(void *)&cmd_all_queues_drop_en_set,
14257 		(void *)&cmd_all_queues_drop_en_all,
14258 		(void *)&cmd_all_queues_drop_en_queues,
14259 		(void *)&cmd_all_queues_drop_en_drop,
14260 		(void *)&cmd_all_queues_drop_en_port_id,
14261 		(void *)&cmd_all_queues_drop_en_on_off,
14262 		NULL,
14263 	},
14264 };
14265 
14266 /* vf split drop enable configuration */
14267 
14268 /* Common result structure for vf split drop enable */
14269 struct cmd_vf_split_drop_en_result {
14270 	cmdline_fixed_string_t set;
14271 	cmdline_fixed_string_t vf;
14272 	cmdline_fixed_string_t split;
14273 	cmdline_fixed_string_t drop;
14274 	portid_t port_id;
14275 	uint16_t vf_id;
14276 	cmdline_fixed_string_t on_off;
14277 };
14278 
14279 /* Common CLI fields for vf split drop enable disable */
14280 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14281 	TOKEN_STRING_INITIALIZER
14282 		(struct cmd_vf_split_drop_en_result,
14283 		 set, "set");
14284 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14285 	TOKEN_STRING_INITIALIZER
14286 		(struct cmd_vf_split_drop_en_result,
14287 		 vf, "vf");
14288 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14289 	TOKEN_STRING_INITIALIZER
14290 		(struct cmd_vf_split_drop_en_result,
14291 		 split, "split");
14292 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14293 	TOKEN_STRING_INITIALIZER
14294 		(struct cmd_vf_split_drop_en_result,
14295 		 drop, "drop");
14296 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14297 	TOKEN_NUM_INITIALIZER
14298 		(struct cmd_vf_split_drop_en_result,
14299 		 port_id, UINT16);
14300 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14301 	TOKEN_NUM_INITIALIZER
14302 		(struct cmd_vf_split_drop_en_result,
14303 		 vf_id, UINT16);
14304 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14305 	TOKEN_STRING_INITIALIZER
14306 		(struct cmd_vf_split_drop_en_result,
14307 		 on_off, "on#off");
14308 
14309 static void
14310 cmd_set_vf_split_drop_en_parsed(
14311 	void *parsed_result,
14312 	__rte_unused struct cmdline *cl,
14313 	__rte_unused void *data)
14314 {
14315 	struct cmd_vf_split_drop_en_result *res = parsed_result;
14316 	int ret = -ENOTSUP;
14317 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14318 
14319 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14320 		return;
14321 
14322 #ifdef RTE_LIBRTE_IXGBE_PMD
14323 	ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14324 			is_on);
14325 #endif
14326 	switch (ret) {
14327 	case 0:
14328 		break;
14329 	case -EINVAL:
14330 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14331 		break;
14332 	case -ENODEV:
14333 		printf("invalid port_id %d\n", res->port_id);
14334 		break;
14335 	case -ENOTSUP:
14336 		printf("not supported on port %d\n", res->port_id);
14337 		break;
14338 	default:
14339 		printf("programming error: (%s)\n", strerror(-ret));
14340 	}
14341 }
14342 
14343 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14344 	.f = cmd_set_vf_split_drop_en_parsed,
14345 	.data = NULL,
14346 	.help_str = "set vf split drop <port_id> <vf_id> on|off",
14347 	.tokens = {
14348 		(void *)&cmd_vf_split_drop_en_set,
14349 		(void *)&cmd_vf_split_drop_en_vf,
14350 		(void *)&cmd_vf_split_drop_en_split,
14351 		(void *)&cmd_vf_split_drop_en_drop,
14352 		(void *)&cmd_vf_split_drop_en_port_id,
14353 		(void *)&cmd_vf_split_drop_en_vf_id,
14354 		(void *)&cmd_vf_split_drop_en_on_off,
14355 		NULL,
14356 	},
14357 };
14358 
14359 /* vf mac address configuration */
14360 
14361 /* Common result structure for vf mac address */
14362 struct cmd_set_vf_mac_addr_result {
14363 	cmdline_fixed_string_t set;
14364 	cmdline_fixed_string_t vf;
14365 	cmdline_fixed_string_t mac;
14366 	cmdline_fixed_string_t addr;
14367 	portid_t port_id;
14368 	uint16_t vf_id;
14369 	struct rte_ether_addr mac_addr;
14370 
14371 };
14372 
14373 /* Common CLI fields for vf split drop enable disable */
14374 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14375 	TOKEN_STRING_INITIALIZER
14376 		(struct cmd_set_vf_mac_addr_result,
14377 		 set, "set");
14378 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14379 	TOKEN_STRING_INITIALIZER
14380 		(struct cmd_set_vf_mac_addr_result,
14381 		 vf, "vf");
14382 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14383 	TOKEN_STRING_INITIALIZER
14384 		(struct cmd_set_vf_mac_addr_result,
14385 		 mac, "mac");
14386 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14387 	TOKEN_STRING_INITIALIZER
14388 		(struct cmd_set_vf_mac_addr_result,
14389 		 addr, "addr");
14390 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14391 	TOKEN_NUM_INITIALIZER
14392 		(struct cmd_set_vf_mac_addr_result,
14393 		 port_id, UINT16);
14394 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14395 	TOKEN_NUM_INITIALIZER
14396 		(struct cmd_set_vf_mac_addr_result,
14397 		 vf_id, UINT16);
14398 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14399 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14400 		 mac_addr);
14401 
14402 static void
14403 cmd_set_vf_mac_addr_parsed(
14404 	void *parsed_result,
14405 	__rte_unused struct cmdline *cl,
14406 	__rte_unused void *data)
14407 {
14408 	struct cmd_set_vf_mac_addr_result *res = parsed_result;
14409 	int ret = -ENOTSUP;
14410 
14411 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14412 		return;
14413 
14414 #ifdef RTE_LIBRTE_IXGBE_PMD
14415 	if (ret == -ENOTSUP)
14416 		ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14417 				&res->mac_addr);
14418 #endif
14419 #ifdef RTE_LIBRTE_I40E_PMD
14420 	if (ret == -ENOTSUP)
14421 		ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14422 				&res->mac_addr);
14423 #endif
14424 #ifdef RTE_LIBRTE_BNXT_PMD
14425 	if (ret == -ENOTSUP)
14426 		ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14427 				&res->mac_addr);
14428 #endif
14429 
14430 	switch (ret) {
14431 	case 0:
14432 		break;
14433 	case -EINVAL:
14434 		printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14435 		break;
14436 	case -ENODEV:
14437 		printf("invalid port_id %d\n", res->port_id);
14438 		break;
14439 	case -ENOTSUP:
14440 		printf("function not implemented\n");
14441 		break;
14442 	default:
14443 		printf("programming error: (%s)\n", strerror(-ret));
14444 	}
14445 }
14446 
14447 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14448 	.f = cmd_set_vf_mac_addr_parsed,
14449 	.data = NULL,
14450 	.help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14451 	.tokens = {
14452 		(void *)&cmd_set_vf_mac_addr_set,
14453 		(void *)&cmd_set_vf_mac_addr_vf,
14454 		(void *)&cmd_set_vf_mac_addr_mac,
14455 		(void *)&cmd_set_vf_mac_addr_addr,
14456 		(void *)&cmd_set_vf_mac_addr_port_id,
14457 		(void *)&cmd_set_vf_mac_addr_vf_id,
14458 		(void *)&cmd_set_vf_mac_addr_mac_addr,
14459 		NULL,
14460 	},
14461 };
14462 
14463 /* MACsec configuration */
14464 
14465 /* Common result structure for MACsec offload enable */
14466 struct cmd_macsec_offload_on_result {
14467 	cmdline_fixed_string_t set;
14468 	cmdline_fixed_string_t macsec;
14469 	cmdline_fixed_string_t offload;
14470 	portid_t port_id;
14471 	cmdline_fixed_string_t on;
14472 	cmdline_fixed_string_t encrypt;
14473 	cmdline_fixed_string_t en_on_off;
14474 	cmdline_fixed_string_t replay_protect;
14475 	cmdline_fixed_string_t rp_on_off;
14476 };
14477 
14478 /* Common CLI fields for MACsec offload disable */
14479 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14480 	TOKEN_STRING_INITIALIZER
14481 		(struct cmd_macsec_offload_on_result,
14482 		 set, "set");
14483 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14484 	TOKEN_STRING_INITIALIZER
14485 		(struct cmd_macsec_offload_on_result,
14486 		 macsec, "macsec");
14487 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14488 	TOKEN_STRING_INITIALIZER
14489 		(struct cmd_macsec_offload_on_result,
14490 		 offload, "offload");
14491 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14492 	TOKEN_NUM_INITIALIZER
14493 		(struct cmd_macsec_offload_on_result,
14494 		 port_id, UINT16);
14495 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14496 	TOKEN_STRING_INITIALIZER
14497 		(struct cmd_macsec_offload_on_result,
14498 		 on, "on");
14499 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14500 	TOKEN_STRING_INITIALIZER
14501 		(struct cmd_macsec_offload_on_result,
14502 		 encrypt, "encrypt");
14503 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14504 	TOKEN_STRING_INITIALIZER
14505 		(struct cmd_macsec_offload_on_result,
14506 		 en_on_off, "on#off");
14507 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14508 	TOKEN_STRING_INITIALIZER
14509 		(struct cmd_macsec_offload_on_result,
14510 		 replay_protect, "replay-protect");
14511 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14512 	TOKEN_STRING_INITIALIZER
14513 		(struct cmd_macsec_offload_on_result,
14514 		 rp_on_off, "on#off");
14515 
14516 static void
14517 cmd_set_macsec_offload_on_parsed(
14518 	void *parsed_result,
14519 	__rte_unused struct cmdline *cl,
14520 	__rte_unused void *data)
14521 {
14522 	struct cmd_macsec_offload_on_result *res = parsed_result;
14523 	int ret = -ENOTSUP;
14524 	portid_t port_id = res->port_id;
14525 	int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14526 	int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14527 	struct rte_eth_dev_info dev_info;
14528 
14529 	if (port_id_is_invalid(port_id, ENABLED_WARN))
14530 		return;
14531 	if (!port_is_stopped(port_id)) {
14532 		printf("Please stop port %d first\n", port_id);
14533 		return;
14534 	}
14535 
14536 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
14537 	if (ret != 0)
14538 		return;
14539 
14540 	if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14541 #ifdef RTE_LIBRTE_IXGBE_PMD
14542 		ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14543 #endif
14544 	}
14545 	RTE_SET_USED(en);
14546 	RTE_SET_USED(rp);
14547 
14548 	switch (ret) {
14549 	case 0:
14550 		ports[port_id].dev_conf.txmode.offloads |=
14551 						DEV_TX_OFFLOAD_MACSEC_INSERT;
14552 		cmd_reconfig_device_queue(port_id, 1, 1);
14553 		break;
14554 	case -ENODEV:
14555 		printf("invalid port_id %d\n", port_id);
14556 		break;
14557 	case -ENOTSUP:
14558 		printf("not supported on port %d\n", port_id);
14559 		break;
14560 	default:
14561 		printf("programming error: (%s)\n", strerror(-ret));
14562 	}
14563 }
14564 
14565 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14566 	.f = cmd_set_macsec_offload_on_parsed,
14567 	.data = NULL,
14568 	.help_str = "set macsec offload <port_id> on "
14569 		"encrypt on|off replay-protect on|off",
14570 	.tokens = {
14571 		(void *)&cmd_macsec_offload_on_set,
14572 		(void *)&cmd_macsec_offload_on_macsec,
14573 		(void *)&cmd_macsec_offload_on_offload,
14574 		(void *)&cmd_macsec_offload_on_port_id,
14575 		(void *)&cmd_macsec_offload_on_on,
14576 		(void *)&cmd_macsec_offload_on_encrypt,
14577 		(void *)&cmd_macsec_offload_on_en_on_off,
14578 		(void *)&cmd_macsec_offload_on_replay_protect,
14579 		(void *)&cmd_macsec_offload_on_rp_on_off,
14580 		NULL,
14581 	},
14582 };
14583 
14584 /* Common result structure for MACsec offload disable */
14585 struct cmd_macsec_offload_off_result {
14586 	cmdline_fixed_string_t set;
14587 	cmdline_fixed_string_t macsec;
14588 	cmdline_fixed_string_t offload;
14589 	portid_t port_id;
14590 	cmdline_fixed_string_t off;
14591 };
14592 
14593 /* Common CLI fields for MACsec offload disable */
14594 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14595 	TOKEN_STRING_INITIALIZER
14596 		(struct cmd_macsec_offload_off_result,
14597 		 set, "set");
14598 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14599 	TOKEN_STRING_INITIALIZER
14600 		(struct cmd_macsec_offload_off_result,
14601 		 macsec, "macsec");
14602 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14603 	TOKEN_STRING_INITIALIZER
14604 		(struct cmd_macsec_offload_off_result,
14605 		 offload, "offload");
14606 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14607 	TOKEN_NUM_INITIALIZER
14608 		(struct cmd_macsec_offload_off_result,
14609 		 port_id, UINT16);
14610 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14611 	TOKEN_STRING_INITIALIZER
14612 		(struct cmd_macsec_offload_off_result,
14613 		 off, "off");
14614 
14615 static void
14616 cmd_set_macsec_offload_off_parsed(
14617 	void *parsed_result,
14618 	__rte_unused struct cmdline *cl,
14619 	__rte_unused void *data)
14620 {
14621 	struct cmd_macsec_offload_off_result *res = parsed_result;
14622 	int ret = -ENOTSUP;
14623 	struct rte_eth_dev_info dev_info;
14624 	portid_t port_id = res->port_id;
14625 
14626 	if (port_id_is_invalid(port_id, ENABLED_WARN))
14627 		return;
14628 	if (!port_is_stopped(port_id)) {
14629 		printf("Please stop port %d first\n", port_id);
14630 		return;
14631 	}
14632 
14633 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
14634 	if (ret != 0)
14635 		return;
14636 
14637 	if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14638 #ifdef RTE_LIBRTE_IXGBE_PMD
14639 		ret = rte_pmd_ixgbe_macsec_disable(port_id);
14640 #endif
14641 	}
14642 	switch (ret) {
14643 	case 0:
14644 		ports[port_id].dev_conf.txmode.offloads &=
14645 						~DEV_TX_OFFLOAD_MACSEC_INSERT;
14646 		cmd_reconfig_device_queue(port_id, 1, 1);
14647 		break;
14648 	case -ENODEV:
14649 		printf("invalid port_id %d\n", port_id);
14650 		break;
14651 	case -ENOTSUP:
14652 		printf("not supported on port %d\n", port_id);
14653 		break;
14654 	default:
14655 		printf("programming error: (%s)\n", strerror(-ret));
14656 	}
14657 }
14658 
14659 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14660 	.f = cmd_set_macsec_offload_off_parsed,
14661 	.data = NULL,
14662 	.help_str = "set macsec offload <port_id> off",
14663 	.tokens = {
14664 		(void *)&cmd_macsec_offload_off_set,
14665 		(void *)&cmd_macsec_offload_off_macsec,
14666 		(void *)&cmd_macsec_offload_off_offload,
14667 		(void *)&cmd_macsec_offload_off_port_id,
14668 		(void *)&cmd_macsec_offload_off_off,
14669 		NULL,
14670 	},
14671 };
14672 
14673 /* Common result structure for MACsec secure connection configure */
14674 struct cmd_macsec_sc_result {
14675 	cmdline_fixed_string_t set;
14676 	cmdline_fixed_string_t macsec;
14677 	cmdline_fixed_string_t sc;
14678 	cmdline_fixed_string_t tx_rx;
14679 	portid_t port_id;
14680 	struct rte_ether_addr mac;
14681 	uint16_t pi;
14682 };
14683 
14684 /* Common CLI fields for MACsec secure connection configure */
14685 cmdline_parse_token_string_t cmd_macsec_sc_set =
14686 	TOKEN_STRING_INITIALIZER
14687 		(struct cmd_macsec_sc_result,
14688 		 set, "set");
14689 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14690 	TOKEN_STRING_INITIALIZER
14691 		(struct cmd_macsec_sc_result,
14692 		 macsec, "macsec");
14693 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14694 	TOKEN_STRING_INITIALIZER
14695 		(struct cmd_macsec_sc_result,
14696 		 sc, "sc");
14697 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14698 	TOKEN_STRING_INITIALIZER
14699 		(struct cmd_macsec_sc_result,
14700 		 tx_rx, "tx#rx");
14701 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14702 	TOKEN_NUM_INITIALIZER
14703 		(struct cmd_macsec_sc_result,
14704 		 port_id, UINT16);
14705 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14706 	TOKEN_ETHERADDR_INITIALIZER
14707 		(struct cmd_macsec_sc_result,
14708 		 mac);
14709 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14710 	TOKEN_NUM_INITIALIZER
14711 		(struct cmd_macsec_sc_result,
14712 		 pi, UINT16);
14713 
14714 static void
14715 cmd_set_macsec_sc_parsed(
14716 	void *parsed_result,
14717 	__rte_unused struct cmdline *cl,
14718 	__rte_unused void *data)
14719 {
14720 	struct cmd_macsec_sc_result *res = parsed_result;
14721 	int ret = -ENOTSUP;
14722 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14723 
14724 #ifdef RTE_LIBRTE_IXGBE_PMD
14725 	ret = is_tx ?
14726 		rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14727 				res->mac.addr_bytes) :
14728 		rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14729 				res->mac.addr_bytes, res->pi);
14730 #endif
14731 	RTE_SET_USED(is_tx);
14732 
14733 	switch (ret) {
14734 	case 0:
14735 		break;
14736 	case -ENODEV:
14737 		printf("invalid port_id %d\n", res->port_id);
14738 		break;
14739 	case -ENOTSUP:
14740 		printf("not supported on port %d\n", res->port_id);
14741 		break;
14742 	default:
14743 		printf("programming error: (%s)\n", strerror(-ret));
14744 	}
14745 }
14746 
14747 cmdline_parse_inst_t cmd_set_macsec_sc = {
14748 	.f = cmd_set_macsec_sc_parsed,
14749 	.data = NULL,
14750 	.help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14751 	.tokens = {
14752 		(void *)&cmd_macsec_sc_set,
14753 		(void *)&cmd_macsec_sc_macsec,
14754 		(void *)&cmd_macsec_sc_sc,
14755 		(void *)&cmd_macsec_sc_tx_rx,
14756 		(void *)&cmd_macsec_sc_port_id,
14757 		(void *)&cmd_macsec_sc_mac,
14758 		(void *)&cmd_macsec_sc_pi,
14759 		NULL,
14760 	},
14761 };
14762 
14763 /* Common result structure for MACsec secure connection configure */
14764 struct cmd_macsec_sa_result {
14765 	cmdline_fixed_string_t set;
14766 	cmdline_fixed_string_t macsec;
14767 	cmdline_fixed_string_t sa;
14768 	cmdline_fixed_string_t tx_rx;
14769 	portid_t port_id;
14770 	uint8_t idx;
14771 	uint8_t an;
14772 	uint32_t pn;
14773 	cmdline_fixed_string_t key;
14774 };
14775 
14776 /* Common CLI fields for MACsec secure connection configure */
14777 cmdline_parse_token_string_t cmd_macsec_sa_set =
14778 	TOKEN_STRING_INITIALIZER
14779 		(struct cmd_macsec_sa_result,
14780 		 set, "set");
14781 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14782 	TOKEN_STRING_INITIALIZER
14783 		(struct cmd_macsec_sa_result,
14784 		 macsec, "macsec");
14785 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14786 	TOKEN_STRING_INITIALIZER
14787 		(struct cmd_macsec_sa_result,
14788 		 sa, "sa");
14789 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14790 	TOKEN_STRING_INITIALIZER
14791 		(struct cmd_macsec_sa_result,
14792 		 tx_rx, "tx#rx");
14793 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14794 	TOKEN_NUM_INITIALIZER
14795 		(struct cmd_macsec_sa_result,
14796 		 port_id, UINT16);
14797 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14798 	TOKEN_NUM_INITIALIZER
14799 		(struct cmd_macsec_sa_result,
14800 		 idx, UINT8);
14801 cmdline_parse_token_num_t cmd_macsec_sa_an =
14802 	TOKEN_NUM_INITIALIZER
14803 		(struct cmd_macsec_sa_result,
14804 		 an, UINT8);
14805 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14806 	TOKEN_NUM_INITIALIZER
14807 		(struct cmd_macsec_sa_result,
14808 		 pn, UINT32);
14809 cmdline_parse_token_string_t cmd_macsec_sa_key =
14810 	TOKEN_STRING_INITIALIZER
14811 		(struct cmd_macsec_sa_result,
14812 		 key, NULL);
14813 
14814 static void
14815 cmd_set_macsec_sa_parsed(
14816 	void *parsed_result,
14817 	__rte_unused struct cmdline *cl,
14818 	__rte_unused void *data)
14819 {
14820 	struct cmd_macsec_sa_result *res = parsed_result;
14821 	int ret = -ENOTSUP;
14822 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14823 	uint8_t key[16] = { 0 };
14824 	uint8_t xdgt0;
14825 	uint8_t xdgt1;
14826 	int key_len;
14827 	int i;
14828 
14829 	key_len = strlen(res->key) / 2;
14830 	if (key_len > 16)
14831 		key_len = 16;
14832 
14833 	for (i = 0; i < key_len; i++) {
14834 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14835 		if (xdgt0 == 0xFF)
14836 			return;
14837 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14838 		if (xdgt1 == 0xFF)
14839 			return;
14840 		key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14841 	}
14842 
14843 #ifdef RTE_LIBRTE_IXGBE_PMD
14844 	ret = is_tx ?
14845 		rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14846 			res->idx, res->an, res->pn, key) :
14847 		rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14848 			res->idx, res->an, res->pn, key);
14849 #endif
14850 	RTE_SET_USED(is_tx);
14851 	RTE_SET_USED(key);
14852 
14853 	switch (ret) {
14854 	case 0:
14855 		break;
14856 	case -EINVAL:
14857 		printf("invalid idx %d or an %d\n", res->idx, res->an);
14858 		break;
14859 	case -ENODEV:
14860 		printf("invalid port_id %d\n", res->port_id);
14861 		break;
14862 	case -ENOTSUP:
14863 		printf("not supported on port %d\n", res->port_id);
14864 		break;
14865 	default:
14866 		printf("programming error: (%s)\n", strerror(-ret));
14867 	}
14868 }
14869 
14870 cmdline_parse_inst_t cmd_set_macsec_sa = {
14871 	.f = cmd_set_macsec_sa_parsed,
14872 	.data = NULL,
14873 	.help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14874 	.tokens = {
14875 		(void *)&cmd_macsec_sa_set,
14876 		(void *)&cmd_macsec_sa_macsec,
14877 		(void *)&cmd_macsec_sa_sa,
14878 		(void *)&cmd_macsec_sa_tx_rx,
14879 		(void *)&cmd_macsec_sa_port_id,
14880 		(void *)&cmd_macsec_sa_idx,
14881 		(void *)&cmd_macsec_sa_an,
14882 		(void *)&cmd_macsec_sa_pn,
14883 		(void *)&cmd_macsec_sa_key,
14884 		NULL,
14885 	},
14886 };
14887 
14888 /* VF unicast promiscuous mode configuration */
14889 
14890 /* Common result structure for VF unicast promiscuous mode */
14891 struct cmd_vf_promisc_result {
14892 	cmdline_fixed_string_t set;
14893 	cmdline_fixed_string_t vf;
14894 	cmdline_fixed_string_t promisc;
14895 	portid_t port_id;
14896 	uint32_t vf_id;
14897 	cmdline_fixed_string_t on_off;
14898 };
14899 
14900 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14901 cmdline_parse_token_string_t cmd_vf_promisc_set =
14902 	TOKEN_STRING_INITIALIZER
14903 		(struct cmd_vf_promisc_result,
14904 		 set, "set");
14905 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14906 	TOKEN_STRING_INITIALIZER
14907 		(struct cmd_vf_promisc_result,
14908 		 vf, "vf");
14909 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14910 	TOKEN_STRING_INITIALIZER
14911 		(struct cmd_vf_promisc_result,
14912 		 promisc, "promisc");
14913 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14914 	TOKEN_NUM_INITIALIZER
14915 		(struct cmd_vf_promisc_result,
14916 		 port_id, UINT16);
14917 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14918 	TOKEN_NUM_INITIALIZER
14919 		(struct cmd_vf_promisc_result,
14920 		 vf_id, UINT32);
14921 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14922 	TOKEN_STRING_INITIALIZER
14923 		(struct cmd_vf_promisc_result,
14924 		 on_off, "on#off");
14925 
14926 static void
14927 cmd_set_vf_promisc_parsed(
14928 	void *parsed_result,
14929 	__rte_unused struct cmdline *cl,
14930 	__rte_unused void *data)
14931 {
14932 	struct cmd_vf_promisc_result *res = parsed_result;
14933 	int ret = -ENOTSUP;
14934 
14935 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14936 
14937 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14938 		return;
14939 
14940 #ifdef RTE_LIBRTE_I40E_PMD
14941 	ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14942 						  res->vf_id, is_on);
14943 #endif
14944 
14945 	switch (ret) {
14946 	case 0:
14947 		break;
14948 	case -EINVAL:
14949 		printf("invalid vf_id %d\n", res->vf_id);
14950 		break;
14951 	case -ENODEV:
14952 		printf("invalid port_id %d\n", res->port_id);
14953 		break;
14954 	case -ENOTSUP:
14955 		printf("function not implemented\n");
14956 		break;
14957 	default:
14958 		printf("programming error: (%s)\n", strerror(-ret));
14959 	}
14960 }
14961 
14962 cmdline_parse_inst_t cmd_set_vf_promisc = {
14963 	.f = cmd_set_vf_promisc_parsed,
14964 	.data = NULL,
14965 	.help_str = "set vf promisc <port_id> <vf_id> on|off: "
14966 		"Set unicast promiscuous mode for a VF from the PF",
14967 	.tokens = {
14968 		(void *)&cmd_vf_promisc_set,
14969 		(void *)&cmd_vf_promisc_vf,
14970 		(void *)&cmd_vf_promisc_promisc,
14971 		(void *)&cmd_vf_promisc_port_id,
14972 		(void *)&cmd_vf_promisc_vf_id,
14973 		(void *)&cmd_vf_promisc_on_off,
14974 		NULL,
14975 	},
14976 };
14977 
14978 /* VF multicast promiscuous mode configuration */
14979 
14980 /* Common result structure for VF multicast promiscuous mode */
14981 struct cmd_vf_allmulti_result {
14982 	cmdline_fixed_string_t set;
14983 	cmdline_fixed_string_t vf;
14984 	cmdline_fixed_string_t allmulti;
14985 	portid_t port_id;
14986 	uint32_t vf_id;
14987 	cmdline_fixed_string_t on_off;
14988 };
14989 
14990 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14991 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14992 	TOKEN_STRING_INITIALIZER
14993 		(struct cmd_vf_allmulti_result,
14994 		 set, "set");
14995 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14996 	TOKEN_STRING_INITIALIZER
14997 		(struct cmd_vf_allmulti_result,
14998 		 vf, "vf");
14999 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
15000 	TOKEN_STRING_INITIALIZER
15001 		(struct cmd_vf_allmulti_result,
15002 		 allmulti, "allmulti");
15003 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
15004 	TOKEN_NUM_INITIALIZER
15005 		(struct cmd_vf_allmulti_result,
15006 		 port_id, UINT16);
15007 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
15008 	TOKEN_NUM_INITIALIZER
15009 		(struct cmd_vf_allmulti_result,
15010 		 vf_id, UINT32);
15011 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
15012 	TOKEN_STRING_INITIALIZER
15013 		(struct cmd_vf_allmulti_result,
15014 		 on_off, "on#off");
15015 
15016 static void
15017 cmd_set_vf_allmulti_parsed(
15018 	void *parsed_result,
15019 	__rte_unused struct cmdline *cl,
15020 	__rte_unused void *data)
15021 {
15022 	struct cmd_vf_allmulti_result *res = parsed_result;
15023 	int ret = -ENOTSUP;
15024 
15025 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15026 
15027 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15028 		return;
15029 
15030 #ifdef RTE_LIBRTE_I40E_PMD
15031 	ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
15032 						    res->vf_id, is_on);
15033 #endif
15034 
15035 	switch (ret) {
15036 	case 0:
15037 		break;
15038 	case -EINVAL:
15039 		printf("invalid vf_id %d\n", res->vf_id);
15040 		break;
15041 	case -ENODEV:
15042 		printf("invalid port_id %d\n", res->port_id);
15043 		break;
15044 	case -ENOTSUP:
15045 		printf("function not implemented\n");
15046 		break;
15047 	default:
15048 		printf("programming error: (%s)\n", strerror(-ret));
15049 	}
15050 }
15051 
15052 cmdline_parse_inst_t cmd_set_vf_allmulti = {
15053 	.f = cmd_set_vf_allmulti_parsed,
15054 	.data = NULL,
15055 	.help_str = "set vf allmulti <port_id> <vf_id> on|off: "
15056 		"Set multicast promiscuous mode for a VF from the PF",
15057 	.tokens = {
15058 		(void *)&cmd_vf_allmulti_set,
15059 		(void *)&cmd_vf_allmulti_vf,
15060 		(void *)&cmd_vf_allmulti_allmulti,
15061 		(void *)&cmd_vf_allmulti_port_id,
15062 		(void *)&cmd_vf_allmulti_vf_id,
15063 		(void *)&cmd_vf_allmulti_on_off,
15064 		NULL,
15065 	},
15066 };
15067 
15068 /* vf broadcast mode configuration */
15069 
15070 /* Common result structure for vf broadcast */
15071 struct cmd_set_vf_broadcast_result {
15072 	cmdline_fixed_string_t set;
15073 	cmdline_fixed_string_t vf;
15074 	cmdline_fixed_string_t broadcast;
15075 	portid_t port_id;
15076 	uint16_t vf_id;
15077 	cmdline_fixed_string_t on_off;
15078 };
15079 
15080 /* Common CLI fields for vf broadcast enable disable */
15081 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
15082 	TOKEN_STRING_INITIALIZER
15083 		(struct cmd_set_vf_broadcast_result,
15084 		 set, "set");
15085 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
15086 	TOKEN_STRING_INITIALIZER
15087 		(struct cmd_set_vf_broadcast_result,
15088 		 vf, "vf");
15089 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
15090 	TOKEN_STRING_INITIALIZER
15091 		(struct cmd_set_vf_broadcast_result,
15092 		 broadcast, "broadcast");
15093 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
15094 	TOKEN_NUM_INITIALIZER
15095 		(struct cmd_set_vf_broadcast_result,
15096 		 port_id, UINT16);
15097 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
15098 	TOKEN_NUM_INITIALIZER
15099 		(struct cmd_set_vf_broadcast_result,
15100 		 vf_id, UINT16);
15101 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
15102 	TOKEN_STRING_INITIALIZER
15103 		(struct cmd_set_vf_broadcast_result,
15104 		 on_off, "on#off");
15105 
15106 static void
15107 cmd_set_vf_broadcast_parsed(
15108 	void *parsed_result,
15109 	__rte_unused struct cmdline *cl,
15110 	__rte_unused void *data)
15111 {
15112 	struct cmd_set_vf_broadcast_result *res = parsed_result;
15113 	int ret = -ENOTSUP;
15114 
15115 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15116 
15117 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15118 		return;
15119 
15120 #ifdef RTE_LIBRTE_I40E_PMD
15121 	ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
15122 					    res->vf_id, is_on);
15123 #endif
15124 
15125 	switch (ret) {
15126 	case 0:
15127 		break;
15128 	case -EINVAL:
15129 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15130 		break;
15131 	case -ENODEV:
15132 		printf("invalid port_id %d\n", res->port_id);
15133 		break;
15134 	case -ENOTSUP:
15135 		printf("function not implemented\n");
15136 		break;
15137 	default:
15138 		printf("programming error: (%s)\n", strerror(-ret));
15139 	}
15140 }
15141 
15142 cmdline_parse_inst_t cmd_set_vf_broadcast = {
15143 	.f = cmd_set_vf_broadcast_parsed,
15144 	.data = NULL,
15145 	.help_str = "set vf broadcast <port_id> <vf_id> on|off",
15146 	.tokens = {
15147 		(void *)&cmd_set_vf_broadcast_set,
15148 		(void *)&cmd_set_vf_broadcast_vf,
15149 		(void *)&cmd_set_vf_broadcast_broadcast,
15150 		(void *)&cmd_set_vf_broadcast_port_id,
15151 		(void *)&cmd_set_vf_broadcast_vf_id,
15152 		(void *)&cmd_set_vf_broadcast_on_off,
15153 		NULL,
15154 	},
15155 };
15156 
15157 /* vf vlan tag configuration */
15158 
15159 /* Common result structure for vf vlan tag */
15160 struct cmd_set_vf_vlan_tag_result {
15161 	cmdline_fixed_string_t set;
15162 	cmdline_fixed_string_t vf;
15163 	cmdline_fixed_string_t vlan;
15164 	cmdline_fixed_string_t tag;
15165 	portid_t port_id;
15166 	uint16_t vf_id;
15167 	cmdline_fixed_string_t on_off;
15168 };
15169 
15170 /* Common CLI fields for vf vlan tag enable disable */
15171 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
15172 	TOKEN_STRING_INITIALIZER
15173 		(struct cmd_set_vf_vlan_tag_result,
15174 		 set, "set");
15175 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
15176 	TOKEN_STRING_INITIALIZER
15177 		(struct cmd_set_vf_vlan_tag_result,
15178 		 vf, "vf");
15179 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
15180 	TOKEN_STRING_INITIALIZER
15181 		(struct cmd_set_vf_vlan_tag_result,
15182 		 vlan, "vlan");
15183 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
15184 	TOKEN_STRING_INITIALIZER
15185 		(struct cmd_set_vf_vlan_tag_result,
15186 		 tag, "tag");
15187 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
15188 	TOKEN_NUM_INITIALIZER
15189 		(struct cmd_set_vf_vlan_tag_result,
15190 		 port_id, UINT16);
15191 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
15192 	TOKEN_NUM_INITIALIZER
15193 		(struct cmd_set_vf_vlan_tag_result,
15194 		 vf_id, UINT16);
15195 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
15196 	TOKEN_STRING_INITIALIZER
15197 		(struct cmd_set_vf_vlan_tag_result,
15198 		 on_off, "on#off");
15199 
15200 static void
15201 cmd_set_vf_vlan_tag_parsed(
15202 	void *parsed_result,
15203 	__rte_unused struct cmdline *cl,
15204 	__rte_unused void *data)
15205 {
15206 	struct cmd_set_vf_vlan_tag_result *res = parsed_result;
15207 	int ret = -ENOTSUP;
15208 
15209 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15210 
15211 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15212 		return;
15213 
15214 #ifdef RTE_LIBRTE_I40E_PMD
15215 	ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
15216 					   res->vf_id, is_on);
15217 #endif
15218 
15219 	switch (ret) {
15220 	case 0:
15221 		break;
15222 	case -EINVAL:
15223 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15224 		break;
15225 	case -ENODEV:
15226 		printf("invalid port_id %d\n", res->port_id);
15227 		break;
15228 	case -ENOTSUP:
15229 		printf("function not implemented\n");
15230 		break;
15231 	default:
15232 		printf("programming error: (%s)\n", strerror(-ret));
15233 	}
15234 }
15235 
15236 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
15237 	.f = cmd_set_vf_vlan_tag_parsed,
15238 	.data = NULL,
15239 	.help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15240 	.tokens = {
15241 		(void *)&cmd_set_vf_vlan_tag_set,
15242 		(void *)&cmd_set_vf_vlan_tag_vf,
15243 		(void *)&cmd_set_vf_vlan_tag_vlan,
15244 		(void *)&cmd_set_vf_vlan_tag_tag,
15245 		(void *)&cmd_set_vf_vlan_tag_port_id,
15246 		(void *)&cmd_set_vf_vlan_tag_vf_id,
15247 		(void *)&cmd_set_vf_vlan_tag_on_off,
15248 		NULL,
15249 	},
15250 };
15251 
15252 /* Common definition of VF and TC TX bandwidth configuration */
15253 struct cmd_vf_tc_bw_result {
15254 	cmdline_fixed_string_t set;
15255 	cmdline_fixed_string_t vf;
15256 	cmdline_fixed_string_t tc;
15257 	cmdline_fixed_string_t tx;
15258 	cmdline_fixed_string_t min_bw;
15259 	cmdline_fixed_string_t max_bw;
15260 	cmdline_fixed_string_t strict_link_prio;
15261 	portid_t port_id;
15262 	uint16_t vf_id;
15263 	uint8_t tc_no;
15264 	uint32_t bw;
15265 	cmdline_fixed_string_t bw_list;
15266 	uint8_t tc_map;
15267 };
15268 
15269 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15270 	TOKEN_STRING_INITIALIZER
15271 		(struct cmd_vf_tc_bw_result,
15272 		 set, "set");
15273 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15274 	TOKEN_STRING_INITIALIZER
15275 		(struct cmd_vf_tc_bw_result,
15276 		 vf, "vf");
15277 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15278 	TOKEN_STRING_INITIALIZER
15279 		(struct cmd_vf_tc_bw_result,
15280 		 tc, "tc");
15281 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15282 	TOKEN_STRING_INITIALIZER
15283 		(struct cmd_vf_tc_bw_result,
15284 		 tx, "tx");
15285 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15286 	TOKEN_STRING_INITIALIZER
15287 		(struct cmd_vf_tc_bw_result,
15288 		 strict_link_prio, "strict-link-priority");
15289 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15290 	TOKEN_STRING_INITIALIZER
15291 		(struct cmd_vf_tc_bw_result,
15292 		 min_bw, "min-bandwidth");
15293 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15294 	TOKEN_STRING_INITIALIZER
15295 		(struct cmd_vf_tc_bw_result,
15296 		 max_bw, "max-bandwidth");
15297 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15298 	TOKEN_NUM_INITIALIZER
15299 		(struct cmd_vf_tc_bw_result,
15300 		 port_id, UINT16);
15301 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15302 	TOKEN_NUM_INITIALIZER
15303 		(struct cmd_vf_tc_bw_result,
15304 		 vf_id, UINT16);
15305 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15306 	TOKEN_NUM_INITIALIZER
15307 		(struct cmd_vf_tc_bw_result,
15308 		 tc_no, UINT8);
15309 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15310 	TOKEN_NUM_INITIALIZER
15311 		(struct cmd_vf_tc_bw_result,
15312 		 bw, UINT32);
15313 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15314 	TOKEN_STRING_INITIALIZER
15315 		(struct cmd_vf_tc_bw_result,
15316 		 bw_list, NULL);
15317 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15318 	TOKEN_NUM_INITIALIZER
15319 		(struct cmd_vf_tc_bw_result,
15320 		 tc_map, UINT8);
15321 
15322 /* VF max bandwidth setting */
15323 static void
15324 cmd_vf_max_bw_parsed(
15325 	void *parsed_result,
15326 	__rte_unused struct cmdline *cl,
15327 	__rte_unused void *data)
15328 {
15329 	struct cmd_vf_tc_bw_result *res = parsed_result;
15330 	int ret = -ENOTSUP;
15331 
15332 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15333 		return;
15334 
15335 #ifdef RTE_LIBRTE_I40E_PMD
15336 	ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15337 					 res->vf_id, res->bw);
15338 #endif
15339 
15340 	switch (ret) {
15341 	case 0:
15342 		break;
15343 	case -EINVAL:
15344 		printf("invalid vf_id %d or bandwidth %d\n",
15345 		       res->vf_id, res->bw);
15346 		break;
15347 	case -ENODEV:
15348 		printf("invalid port_id %d\n", res->port_id);
15349 		break;
15350 	case -ENOTSUP:
15351 		printf("function not implemented\n");
15352 		break;
15353 	default:
15354 		printf("programming error: (%s)\n", strerror(-ret));
15355 	}
15356 }
15357 
15358 cmdline_parse_inst_t cmd_vf_max_bw = {
15359 	.f = cmd_vf_max_bw_parsed,
15360 	.data = NULL,
15361 	.help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15362 	.tokens = {
15363 		(void *)&cmd_vf_tc_bw_set,
15364 		(void *)&cmd_vf_tc_bw_vf,
15365 		(void *)&cmd_vf_tc_bw_tx,
15366 		(void *)&cmd_vf_tc_bw_max_bw,
15367 		(void *)&cmd_vf_tc_bw_port_id,
15368 		(void *)&cmd_vf_tc_bw_vf_id,
15369 		(void *)&cmd_vf_tc_bw_bw,
15370 		NULL,
15371 	},
15372 };
15373 
15374 static int
15375 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15376 			   uint8_t *tc_num,
15377 			   char *str)
15378 {
15379 	uint32_t size;
15380 	const char *p, *p0 = str;
15381 	char s[256];
15382 	char *end;
15383 	char *str_fld[16];
15384 	uint16_t i;
15385 	int ret;
15386 
15387 	p = strchr(p0, '(');
15388 	if (p == NULL) {
15389 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15390 		return -1;
15391 	}
15392 	p++;
15393 	p0 = strchr(p, ')');
15394 	if (p0 == NULL) {
15395 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15396 		return -1;
15397 	}
15398 	size = p0 - p;
15399 	if (size >= sizeof(s)) {
15400 		printf("The string size exceeds the internal buffer size\n");
15401 		return -1;
15402 	}
15403 	snprintf(s, sizeof(s), "%.*s", size, p);
15404 	ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15405 	if (ret <= 0) {
15406 		printf("Failed to get the bandwidth list. ");
15407 		return -1;
15408 	}
15409 	*tc_num = ret;
15410 	for (i = 0; i < ret; i++)
15411 		bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15412 
15413 	return 0;
15414 }
15415 
15416 /* TC min bandwidth setting */
15417 static void
15418 cmd_vf_tc_min_bw_parsed(
15419 	void *parsed_result,
15420 	__rte_unused struct cmdline *cl,
15421 	__rte_unused void *data)
15422 {
15423 	struct cmd_vf_tc_bw_result *res = parsed_result;
15424 	uint8_t tc_num;
15425 	uint8_t bw[16];
15426 	int ret = -ENOTSUP;
15427 
15428 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15429 		return;
15430 
15431 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15432 	if (ret)
15433 		return;
15434 
15435 #ifdef RTE_LIBRTE_I40E_PMD
15436 	ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15437 					      tc_num, bw);
15438 #endif
15439 
15440 	switch (ret) {
15441 	case 0:
15442 		break;
15443 	case -EINVAL:
15444 		printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15445 		break;
15446 	case -ENODEV:
15447 		printf("invalid port_id %d\n", res->port_id);
15448 		break;
15449 	case -ENOTSUP:
15450 		printf("function not implemented\n");
15451 		break;
15452 	default:
15453 		printf("programming error: (%s)\n", strerror(-ret));
15454 	}
15455 }
15456 
15457 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15458 	.f = cmd_vf_tc_min_bw_parsed,
15459 	.data = NULL,
15460 	.help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15461 		    " <bw1, bw2, ...>",
15462 	.tokens = {
15463 		(void *)&cmd_vf_tc_bw_set,
15464 		(void *)&cmd_vf_tc_bw_vf,
15465 		(void *)&cmd_vf_tc_bw_tc,
15466 		(void *)&cmd_vf_tc_bw_tx,
15467 		(void *)&cmd_vf_tc_bw_min_bw,
15468 		(void *)&cmd_vf_tc_bw_port_id,
15469 		(void *)&cmd_vf_tc_bw_vf_id,
15470 		(void *)&cmd_vf_tc_bw_bw_list,
15471 		NULL,
15472 	},
15473 };
15474 
15475 static void
15476 cmd_tc_min_bw_parsed(
15477 	void *parsed_result,
15478 	__rte_unused struct cmdline *cl,
15479 	__rte_unused void *data)
15480 {
15481 	struct cmd_vf_tc_bw_result *res = parsed_result;
15482 	struct rte_port *port;
15483 	uint8_t tc_num;
15484 	uint8_t bw[16];
15485 	int ret = -ENOTSUP;
15486 
15487 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15488 		return;
15489 
15490 	port = &ports[res->port_id];
15491 	/** Check if the port is not started **/
15492 	if (port->port_status != RTE_PORT_STOPPED) {
15493 		printf("Please stop port %d first\n", res->port_id);
15494 		return;
15495 	}
15496 
15497 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15498 	if (ret)
15499 		return;
15500 
15501 #ifdef RTE_LIBRTE_IXGBE_PMD
15502 	ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15503 #endif
15504 
15505 	switch (ret) {
15506 	case 0:
15507 		break;
15508 	case -EINVAL:
15509 		printf("invalid bandwidth\n");
15510 		break;
15511 	case -ENODEV:
15512 		printf("invalid port_id %d\n", res->port_id);
15513 		break;
15514 	case -ENOTSUP:
15515 		printf("function not implemented\n");
15516 		break;
15517 	default:
15518 		printf("programming error: (%s)\n", strerror(-ret));
15519 	}
15520 }
15521 
15522 cmdline_parse_inst_t cmd_tc_min_bw = {
15523 	.f = cmd_tc_min_bw_parsed,
15524 	.data = NULL,
15525 	.help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15526 	.tokens = {
15527 		(void *)&cmd_vf_tc_bw_set,
15528 		(void *)&cmd_vf_tc_bw_tc,
15529 		(void *)&cmd_vf_tc_bw_tx,
15530 		(void *)&cmd_vf_tc_bw_min_bw,
15531 		(void *)&cmd_vf_tc_bw_port_id,
15532 		(void *)&cmd_vf_tc_bw_bw_list,
15533 		NULL,
15534 	},
15535 };
15536 
15537 /* TC max bandwidth setting */
15538 static void
15539 cmd_vf_tc_max_bw_parsed(
15540 	void *parsed_result,
15541 	__rte_unused struct cmdline *cl,
15542 	__rte_unused void *data)
15543 {
15544 	struct cmd_vf_tc_bw_result *res = parsed_result;
15545 	int ret = -ENOTSUP;
15546 
15547 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15548 		return;
15549 
15550 #ifdef RTE_LIBRTE_I40E_PMD
15551 	ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15552 					    res->tc_no, res->bw);
15553 #endif
15554 
15555 	switch (ret) {
15556 	case 0:
15557 		break;
15558 	case -EINVAL:
15559 		printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15560 		       res->vf_id, res->tc_no, res->bw);
15561 		break;
15562 	case -ENODEV:
15563 		printf("invalid port_id %d\n", res->port_id);
15564 		break;
15565 	case -ENOTSUP:
15566 		printf("function not implemented\n");
15567 		break;
15568 	default:
15569 		printf("programming error: (%s)\n", strerror(-ret));
15570 	}
15571 }
15572 
15573 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15574 	.f = cmd_vf_tc_max_bw_parsed,
15575 	.data = NULL,
15576 	.help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15577 		    " <bandwidth>",
15578 	.tokens = {
15579 		(void *)&cmd_vf_tc_bw_set,
15580 		(void *)&cmd_vf_tc_bw_vf,
15581 		(void *)&cmd_vf_tc_bw_tc,
15582 		(void *)&cmd_vf_tc_bw_tx,
15583 		(void *)&cmd_vf_tc_bw_max_bw,
15584 		(void *)&cmd_vf_tc_bw_port_id,
15585 		(void *)&cmd_vf_tc_bw_vf_id,
15586 		(void *)&cmd_vf_tc_bw_tc_no,
15587 		(void *)&cmd_vf_tc_bw_bw,
15588 		NULL,
15589 	},
15590 };
15591 
15592 /** Set VXLAN encapsulation details */
15593 struct cmd_set_vxlan_result {
15594 	cmdline_fixed_string_t set;
15595 	cmdline_fixed_string_t vxlan;
15596 	cmdline_fixed_string_t pos_token;
15597 	cmdline_fixed_string_t ip_version;
15598 	uint32_t vlan_present:1;
15599 	uint32_t vni;
15600 	uint16_t udp_src;
15601 	uint16_t udp_dst;
15602 	cmdline_ipaddr_t ip_src;
15603 	cmdline_ipaddr_t ip_dst;
15604 	uint16_t tci;
15605 	uint8_t tos;
15606 	uint8_t ttl;
15607 	struct rte_ether_addr eth_src;
15608 	struct rte_ether_addr eth_dst;
15609 };
15610 
15611 cmdline_parse_token_string_t cmd_set_vxlan_set =
15612 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15613 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15614 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15615 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15616 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15617 				 "vxlan-tos-ttl");
15618 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15619 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15620 				 "vxlan-with-vlan");
15621 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15622 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15623 				 "ip-version");
15624 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15625 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15626 				 "ipv4#ipv6");
15627 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15628 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15629 				 "vni");
15630 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15631 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15632 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15633 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15634 				 "udp-src");
15635 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15636 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15637 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15638 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15639 				 "udp-dst");
15640 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15641 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15642 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15643 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15644 				 "ip-tos");
15645 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15646 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15647 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15648 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15649 				 "ip-ttl");
15650 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15651 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15652 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15653 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15654 				 "ip-src");
15655 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15656 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15657 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15658 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15659 				 "ip-dst");
15660 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15661 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15662 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15663 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15664 				 "vlan-tci");
15665 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15666 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15667 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15668 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15669 				 "eth-src");
15670 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15671 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15672 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15673 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15674 				 "eth-dst");
15675 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15676 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15677 
15678 static void cmd_set_vxlan_parsed(void *parsed_result,
15679 	__rte_unused struct cmdline *cl,
15680 	__rte_unused void *data)
15681 {
15682 	struct cmd_set_vxlan_result *res = parsed_result;
15683 	union {
15684 		uint32_t vxlan_id;
15685 		uint8_t vni[4];
15686 	} id = {
15687 		.vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15688 	};
15689 
15690 	vxlan_encap_conf.select_tos_ttl = 0;
15691 	if (strcmp(res->vxlan, "vxlan") == 0)
15692 		vxlan_encap_conf.select_vlan = 0;
15693 	else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15694 		vxlan_encap_conf.select_vlan = 1;
15695 	else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15696 		vxlan_encap_conf.select_vlan = 0;
15697 		vxlan_encap_conf.select_tos_ttl = 1;
15698 	}
15699 	if (strcmp(res->ip_version, "ipv4") == 0)
15700 		vxlan_encap_conf.select_ipv4 = 1;
15701 	else if (strcmp(res->ip_version, "ipv6") == 0)
15702 		vxlan_encap_conf.select_ipv4 = 0;
15703 	else
15704 		return;
15705 	rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15706 	vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15707 	vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15708 	vxlan_encap_conf.ip_tos = res->tos;
15709 	vxlan_encap_conf.ip_ttl = res->ttl;
15710 	if (vxlan_encap_conf.select_ipv4) {
15711 		IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15712 		IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15713 	} else {
15714 		IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15715 		IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15716 	}
15717 	if (vxlan_encap_conf.select_vlan)
15718 		vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15719 	rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15720 		   RTE_ETHER_ADDR_LEN);
15721 	rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15722 		   RTE_ETHER_ADDR_LEN);
15723 }
15724 
15725 cmdline_parse_inst_t cmd_set_vxlan = {
15726 	.f = cmd_set_vxlan_parsed,
15727 	.data = NULL,
15728 	.help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15729 		" <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15730 		" eth-src <eth-src> eth-dst <eth-dst>",
15731 	.tokens = {
15732 		(void *)&cmd_set_vxlan_set,
15733 		(void *)&cmd_set_vxlan_vxlan,
15734 		(void *)&cmd_set_vxlan_ip_version,
15735 		(void *)&cmd_set_vxlan_ip_version_value,
15736 		(void *)&cmd_set_vxlan_vni,
15737 		(void *)&cmd_set_vxlan_vni_value,
15738 		(void *)&cmd_set_vxlan_udp_src,
15739 		(void *)&cmd_set_vxlan_udp_src_value,
15740 		(void *)&cmd_set_vxlan_udp_dst,
15741 		(void *)&cmd_set_vxlan_udp_dst_value,
15742 		(void *)&cmd_set_vxlan_ip_src,
15743 		(void *)&cmd_set_vxlan_ip_src_value,
15744 		(void *)&cmd_set_vxlan_ip_dst,
15745 		(void *)&cmd_set_vxlan_ip_dst_value,
15746 		(void *)&cmd_set_vxlan_eth_src,
15747 		(void *)&cmd_set_vxlan_eth_src_value,
15748 		(void *)&cmd_set_vxlan_eth_dst,
15749 		(void *)&cmd_set_vxlan_eth_dst_value,
15750 		NULL,
15751 	},
15752 };
15753 
15754 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15755 	.f = cmd_set_vxlan_parsed,
15756 	.data = NULL,
15757 	.help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15758 		" <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15759 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15760 		" eth-dst <eth-dst>",
15761 	.tokens = {
15762 		(void *)&cmd_set_vxlan_set,
15763 		(void *)&cmd_set_vxlan_vxlan_tos_ttl,
15764 		(void *)&cmd_set_vxlan_ip_version,
15765 		(void *)&cmd_set_vxlan_ip_version_value,
15766 		(void *)&cmd_set_vxlan_vni,
15767 		(void *)&cmd_set_vxlan_vni_value,
15768 		(void *)&cmd_set_vxlan_udp_src,
15769 		(void *)&cmd_set_vxlan_udp_src_value,
15770 		(void *)&cmd_set_vxlan_udp_dst,
15771 		(void *)&cmd_set_vxlan_udp_dst_value,
15772 		(void *)&cmd_set_vxlan_ip_tos,
15773 		(void *)&cmd_set_vxlan_ip_tos_value,
15774 		(void *)&cmd_set_vxlan_ip_ttl,
15775 		(void *)&cmd_set_vxlan_ip_ttl_value,
15776 		(void *)&cmd_set_vxlan_ip_src,
15777 		(void *)&cmd_set_vxlan_ip_src_value,
15778 		(void *)&cmd_set_vxlan_ip_dst,
15779 		(void *)&cmd_set_vxlan_ip_dst_value,
15780 		(void *)&cmd_set_vxlan_eth_src,
15781 		(void *)&cmd_set_vxlan_eth_src_value,
15782 		(void *)&cmd_set_vxlan_eth_dst,
15783 		(void *)&cmd_set_vxlan_eth_dst_value,
15784 		NULL,
15785 	},
15786 };
15787 
15788 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15789 	.f = cmd_set_vxlan_parsed,
15790 	.data = NULL,
15791 	.help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15792 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15793 		" <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15794 		" <eth-dst>",
15795 	.tokens = {
15796 		(void *)&cmd_set_vxlan_set,
15797 		(void *)&cmd_set_vxlan_vxlan_with_vlan,
15798 		(void *)&cmd_set_vxlan_ip_version,
15799 		(void *)&cmd_set_vxlan_ip_version_value,
15800 		(void *)&cmd_set_vxlan_vni,
15801 		(void *)&cmd_set_vxlan_vni_value,
15802 		(void *)&cmd_set_vxlan_udp_src,
15803 		(void *)&cmd_set_vxlan_udp_src_value,
15804 		(void *)&cmd_set_vxlan_udp_dst,
15805 		(void *)&cmd_set_vxlan_udp_dst_value,
15806 		(void *)&cmd_set_vxlan_ip_src,
15807 		(void *)&cmd_set_vxlan_ip_src_value,
15808 		(void *)&cmd_set_vxlan_ip_dst,
15809 		(void *)&cmd_set_vxlan_ip_dst_value,
15810 		(void *)&cmd_set_vxlan_vlan,
15811 		(void *)&cmd_set_vxlan_vlan_value,
15812 		(void *)&cmd_set_vxlan_eth_src,
15813 		(void *)&cmd_set_vxlan_eth_src_value,
15814 		(void *)&cmd_set_vxlan_eth_dst,
15815 		(void *)&cmd_set_vxlan_eth_dst_value,
15816 		NULL,
15817 	},
15818 };
15819 
15820 /** Set NVGRE encapsulation details */
15821 struct cmd_set_nvgre_result {
15822 	cmdline_fixed_string_t set;
15823 	cmdline_fixed_string_t nvgre;
15824 	cmdline_fixed_string_t pos_token;
15825 	cmdline_fixed_string_t ip_version;
15826 	uint32_t tni;
15827 	cmdline_ipaddr_t ip_src;
15828 	cmdline_ipaddr_t ip_dst;
15829 	uint16_t tci;
15830 	struct rte_ether_addr eth_src;
15831 	struct rte_ether_addr eth_dst;
15832 };
15833 
15834 cmdline_parse_token_string_t cmd_set_nvgre_set =
15835 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15836 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15837 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15838 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15839 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15840 				 "nvgre-with-vlan");
15841 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15842 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15843 				 "ip-version");
15844 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15845 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15846 				 "ipv4#ipv6");
15847 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15848 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15849 				 "tni");
15850 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15851 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15852 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15853 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15854 				 "ip-src");
15855 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15856 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15857 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15858 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15859 				 "ip-dst");
15860 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15861 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15862 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15863 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15864 				 "vlan-tci");
15865 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15866 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15867 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15868 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15869 				 "eth-src");
15870 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15871 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15872 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15873 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15874 				 "eth-dst");
15875 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15876 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15877 
15878 static void cmd_set_nvgre_parsed(void *parsed_result,
15879 	__rte_unused struct cmdline *cl,
15880 	__rte_unused void *data)
15881 {
15882 	struct cmd_set_nvgre_result *res = parsed_result;
15883 	union {
15884 		uint32_t nvgre_tni;
15885 		uint8_t tni[4];
15886 	} id = {
15887 		.nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15888 	};
15889 
15890 	if (strcmp(res->nvgre, "nvgre") == 0)
15891 		nvgre_encap_conf.select_vlan = 0;
15892 	else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15893 		nvgre_encap_conf.select_vlan = 1;
15894 	if (strcmp(res->ip_version, "ipv4") == 0)
15895 		nvgre_encap_conf.select_ipv4 = 1;
15896 	else if (strcmp(res->ip_version, "ipv6") == 0)
15897 		nvgre_encap_conf.select_ipv4 = 0;
15898 	else
15899 		return;
15900 	rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15901 	if (nvgre_encap_conf.select_ipv4) {
15902 		IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15903 		IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15904 	} else {
15905 		IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15906 		IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15907 	}
15908 	if (nvgre_encap_conf.select_vlan)
15909 		nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15910 	rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15911 		   RTE_ETHER_ADDR_LEN);
15912 	rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15913 		   RTE_ETHER_ADDR_LEN);
15914 }
15915 
15916 cmdline_parse_inst_t cmd_set_nvgre = {
15917 	.f = cmd_set_nvgre_parsed,
15918 	.data = NULL,
15919 	.help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15920 		" <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15921 		" eth-dst <eth-dst>",
15922 	.tokens = {
15923 		(void *)&cmd_set_nvgre_set,
15924 		(void *)&cmd_set_nvgre_nvgre,
15925 		(void *)&cmd_set_nvgre_ip_version,
15926 		(void *)&cmd_set_nvgre_ip_version_value,
15927 		(void *)&cmd_set_nvgre_tni,
15928 		(void *)&cmd_set_nvgre_tni_value,
15929 		(void *)&cmd_set_nvgre_ip_src,
15930 		(void *)&cmd_set_nvgre_ip_src_value,
15931 		(void *)&cmd_set_nvgre_ip_dst,
15932 		(void *)&cmd_set_nvgre_ip_dst_value,
15933 		(void *)&cmd_set_nvgre_eth_src,
15934 		(void *)&cmd_set_nvgre_eth_src_value,
15935 		(void *)&cmd_set_nvgre_eth_dst,
15936 		(void *)&cmd_set_nvgre_eth_dst_value,
15937 		NULL,
15938 	},
15939 };
15940 
15941 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15942 	.f = cmd_set_nvgre_parsed,
15943 	.data = NULL,
15944 	.help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15945 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15946 		" eth-src <eth-src> eth-dst <eth-dst>",
15947 	.tokens = {
15948 		(void *)&cmd_set_nvgre_set,
15949 		(void *)&cmd_set_nvgre_nvgre_with_vlan,
15950 		(void *)&cmd_set_nvgre_ip_version,
15951 		(void *)&cmd_set_nvgre_ip_version_value,
15952 		(void *)&cmd_set_nvgre_tni,
15953 		(void *)&cmd_set_nvgre_tni_value,
15954 		(void *)&cmd_set_nvgre_ip_src,
15955 		(void *)&cmd_set_nvgre_ip_src_value,
15956 		(void *)&cmd_set_nvgre_ip_dst,
15957 		(void *)&cmd_set_nvgre_ip_dst_value,
15958 		(void *)&cmd_set_nvgre_vlan,
15959 		(void *)&cmd_set_nvgre_vlan_value,
15960 		(void *)&cmd_set_nvgre_eth_src,
15961 		(void *)&cmd_set_nvgre_eth_src_value,
15962 		(void *)&cmd_set_nvgre_eth_dst,
15963 		(void *)&cmd_set_nvgre_eth_dst_value,
15964 		NULL,
15965 	},
15966 };
15967 
15968 /** Set L2 encapsulation details */
15969 struct cmd_set_l2_encap_result {
15970 	cmdline_fixed_string_t set;
15971 	cmdline_fixed_string_t l2_encap;
15972 	cmdline_fixed_string_t pos_token;
15973 	cmdline_fixed_string_t ip_version;
15974 	uint32_t vlan_present:1;
15975 	uint16_t tci;
15976 	struct rte_ether_addr eth_src;
15977 	struct rte_ether_addr eth_dst;
15978 };
15979 
15980 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15981 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15982 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15983 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15984 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15985 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15986 				 "l2_encap-with-vlan");
15987 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15988 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15989 				 "ip-version");
15990 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15991 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15992 				 "ipv4#ipv6");
15993 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15994 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15995 				 "vlan-tci");
15996 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15997 	TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15998 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15999 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16000 				 "eth-src");
16001 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
16002 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
16003 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
16004 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16005 				 "eth-dst");
16006 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
16007 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
16008 
16009 static void cmd_set_l2_encap_parsed(void *parsed_result,
16010 	__rte_unused struct cmdline *cl,
16011 	__rte_unused void *data)
16012 {
16013 	struct cmd_set_l2_encap_result *res = parsed_result;
16014 
16015 	if (strcmp(res->l2_encap, "l2_encap") == 0)
16016 		l2_encap_conf.select_vlan = 0;
16017 	else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
16018 		l2_encap_conf.select_vlan = 1;
16019 	if (strcmp(res->ip_version, "ipv4") == 0)
16020 		l2_encap_conf.select_ipv4 = 1;
16021 	else if (strcmp(res->ip_version, "ipv6") == 0)
16022 		l2_encap_conf.select_ipv4 = 0;
16023 	else
16024 		return;
16025 	if (l2_encap_conf.select_vlan)
16026 		l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16027 	rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
16028 		   RTE_ETHER_ADDR_LEN);
16029 	rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16030 		   RTE_ETHER_ADDR_LEN);
16031 }
16032 
16033 cmdline_parse_inst_t cmd_set_l2_encap = {
16034 	.f = cmd_set_l2_encap_parsed,
16035 	.data = NULL,
16036 	.help_str = "set l2_encap ip-version ipv4|ipv6"
16037 		" eth-src <eth-src> eth-dst <eth-dst>",
16038 	.tokens = {
16039 		(void *)&cmd_set_l2_encap_set,
16040 		(void *)&cmd_set_l2_encap_l2_encap,
16041 		(void *)&cmd_set_l2_encap_ip_version,
16042 		(void *)&cmd_set_l2_encap_ip_version_value,
16043 		(void *)&cmd_set_l2_encap_eth_src,
16044 		(void *)&cmd_set_l2_encap_eth_src_value,
16045 		(void *)&cmd_set_l2_encap_eth_dst,
16046 		(void *)&cmd_set_l2_encap_eth_dst_value,
16047 		NULL,
16048 	},
16049 };
16050 
16051 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
16052 	.f = cmd_set_l2_encap_parsed,
16053 	.data = NULL,
16054 	.help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
16055 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16056 	.tokens = {
16057 		(void *)&cmd_set_l2_encap_set,
16058 		(void *)&cmd_set_l2_encap_l2_encap_with_vlan,
16059 		(void *)&cmd_set_l2_encap_ip_version,
16060 		(void *)&cmd_set_l2_encap_ip_version_value,
16061 		(void *)&cmd_set_l2_encap_vlan,
16062 		(void *)&cmd_set_l2_encap_vlan_value,
16063 		(void *)&cmd_set_l2_encap_eth_src,
16064 		(void *)&cmd_set_l2_encap_eth_src_value,
16065 		(void *)&cmd_set_l2_encap_eth_dst,
16066 		(void *)&cmd_set_l2_encap_eth_dst_value,
16067 		NULL,
16068 	},
16069 };
16070 
16071 /** Set L2 decapsulation details */
16072 struct cmd_set_l2_decap_result {
16073 	cmdline_fixed_string_t set;
16074 	cmdline_fixed_string_t l2_decap;
16075 	cmdline_fixed_string_t pos_token;
16076 	uint32_t vlan_present:1;
16077 };
16078 
16079 cmdline_parse_token_string_t cmd_set_l2_decap_set =
16080 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
16081 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
16082 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16083 				 "l2_decap");
16084 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
16085 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16086 				 "l2_decap-with-vlan");
16087 
16088 static void cmd_set_l2_decap_parsed(void *parsed_result,
16089 	__rte_unused struct cmdline *cl,
16090 	__rte_unused void *data)
16091 {
16092 	struct cmd_set_l2_decap_result *res = parsed_result;
16093 
16094 	if (strcmp(res->l2_decap, "l2_decap") == 0)
16095 		l2_decap_conf.select_vlan = 0;
16096 	else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
16097 		l2_decap_conf.select_vlan = 1;
16098 }
16099 
16100 cmdline_parse_inst_t cmd_set_l2_decap = {
16101 	.f = cmd_set_l2_decap_parsed,
16102 	.data = NULL,
16103 	.help_str = "set l2_decap",
16104 	.tokens = {
16105 		(void *)&cmd_set_l2_decap_set,
16106 		(void *)&cmd_set_l2_decap_l2_decap,
16107 		NULL,
16108 	},
16109 };
16110 
16111 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
16112 	.f = cmd_set_l2_decap_parsed,
16113 	.data = NULL,
16114 	.help_str = "set l2_decap-with-vlan",
16115 	.tokens = {
16116 		(void *)&cmd_set_l2_decap_set,
16117 		(void *)&cmd_set_l2_decap_l2_decap_with_vlan,
16118 		NULL,
16119 	},
16120 };
16121 
16122 /** Set MPLSoGRE encapsulation details */
16123 struct cmd_set_mplsogre_encap_result {
16124 	cmdline_fixed_string_t set;
16125 	cmdline_fixed_string_t mplsogre;
16126 	cmdline_fixed_string_t pos_token;
16127 	cmdline_fixed_string_t ip_version;
16128 	uint32_t vlan_present:1;
16129 	uint32_t label;
16130 	cmdline_ipaddr_t ip_src;
16131 	cmdline_ipaddr_t ip_dst;
16132 	uint16_t tci;
16133 	struct rte_ether_addr eth_src;
16134 	struct rte_ether_addr eth_dst;
16135 };
16136 
16137 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
16138 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
16139 				 "set");
16140 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
16141 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
16142 				 "mplsogre_encap");
16143 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
16144 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16145 				 mplsogre, "mplsogre_encap-with-vlan");
16146 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
16147 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16148 				 pos_token, "ip-version");
16149 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
16150 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16151 				 ip_version, "ipv4#ipv6");
16152 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
16153 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16154 				 pos_token, "label");
16155 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
16156 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
16157 			      UINT32);
16158 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
16159 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16160 				 pos_token, "ip-src");
16161 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
16162 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
16163 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
16164 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16165 				 pos_token, "ip-dst");
16166 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16167 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16168 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16169 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16170 				 pos_token, "vlan-tci");
16171 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16172 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16173 			      UINT16);
16174 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16175 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16176 				 pos_token, "eth-src");
16177 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16178 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16179 				    eth_src);
16180 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16181 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16182 				 pos_token, "eth-dst");
16183 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16184 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16185 				    eth_dst);
16186 
16187 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16188 	__rte_unused struct cmdline *cl,
16189 	__rte_unused void *data)
16190 {
16191 	struct cmd_set_mplsogre_encap_result *res = parsed_result;
16192 	union {
16193 		uint32_t mplsogre_label;
16194 		uint8_t label[4];
16195 	} id = {
16196 		.mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16197 	};
16198 
16199 	if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16200 		mplsogre_encap_conf.select_vlan = 0;
16201 	else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16202 		mplsogre_encap_conf.select_vlan = 1;
16203 	if (strcmp(res->ip_version, "ipv4") == 0)
16204 		mplsogre_encap_conf.select_ipv4 = 1;
16205 	else if (strcmp(res->ip_version, "ipv6") == 0)
16206 		mplsogre_encap_conf.select_ipv4 = 0;
16207 	else
16208 		return;
16209 	rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16210 	if (mplsogre_encap_conf.select_ipv4) {
16211 		IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16212 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16213 	} else {
16214 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16215 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16216 	}
16217 	if (mplsogre_encap_conf.select_vlan)
16218 		mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16219 	rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16220 		   RTE_ETHER_ADDR_LEN);
16221 	rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16222 		   RTE_ETHER_ADDR_LEN);
16223 }
16224 
16225 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16226 	.f = cmd_set_mplsogre_encap_parsed,
16227 	.data = NULL,
16228 	.help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16229 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16230 		" eth-dst <eth-dst>",
16231 	.tokens = {
16232 		(void *)&cmd_set_mplsogre_encap_set,
16233 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16234 		(void *)&cmd_set_mplsogre_encap_ip_version,
16235 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
16236 		(void *)&cmd_set_mplsogre_encap_label,
16237 		(void *)&cmd_set_mplsogre_encap_label_value,
16238 		(void *)&cmd_set_mplsogre_encap_ip_src,
16239 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
16240 		(void *)&cmd_set_mplsogre_encap_ip_dst,
16241 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
16242 		(void *)&cmd_set_mplsogre_encap_eth_src,
16243 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
16244 		(void *)&cmd_set_mplsogre_encap_eth_dst,
16245 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
16246 		NULL,
16247 	},
16248 };
16249 
16250 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16251 	.f = cmd_set_mplsogre_encap_parsed,
16252 	.data = NULL,
16253 	.help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16254 		" label <label> ip-src <ip-src> ip-dst <ip-dst>"
16255 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16256 	.tokens = {
16257 		(void *)&cmd_set_mplsogre_encap_set,
16258 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16259 		(void *)&cmd_set_mplsogre_encap_ip_version,
16260 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
16261 		(void *)&cmd_set_mplsogre_encap_label,
16262 		(void *)&cmd_set_mplsogre_encap_label_value,
16263 		(void *)&cmd_set_mplsogre_encap_ip_src,
16264 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
16265 		(void *)&cmd_set_mplsogre_encap_ip_dst,
16266 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
16267 		(void *)&cmd_set_mplsogre_encap_vlan,
16268 		(void *)&cmd_set_mplsogre_encap_vlan_value,
16269 		(void *)&cmd_set_mplsogre_encap_eth_src,
16270 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
16271 		(void *)&cmd_set_mplsogre_encap_eth_dst,
16272 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
16273 		NULL,
16274 	},
16275 };
16276 
16277 /** Set MPLSoGRE decapsulation details */
16278 struct cmd_set_mplsogre_decap_result {
16279 	cmdline_fixed_string_t set;
16280 	cmdline_fixed_string_t mplsogre;
16281 	cmdline_fixed_string_t pos_token;
16282 	cmdline_fixed_string_t ip_version;
16283 	uint32_t vlan_present:1;
16284 };
16285 
16286 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16287 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16288 				 "set");
16289 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16290 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16291 				 "mplsogre_decap");
16292 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16293 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16294 				 mplsogre, "mplsogre_decap-with-vlan");
16295 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16296 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16297 				 pos_token, "ip-version");
16298 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16299 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16300 				 ip_version, "ipv4#ipv6");
16301 
16302 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16303 	__rte_unused struct cmdline *cl,
16304 	__rte_unused void *data)
16305 {
16306 	struct cmd_set_mplsogre_decap_result *res = parsed_result;
16307 
16308 	if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16309 		mplsogre_decap_conf.select_vlan = 0;
16310 	else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16311 		mplsogre_decap_conf.select_vlan = 1;
16312 	if (strcmp(res->ip_version, "ipv4") == 0)
16313 		mplsogre_decap_conf.select_ipv4 = 1;
16314 	else if (strcmp(res->ip_version, "ipv6") == 0)
16315 		mplsogre_decap_conf.select_ipv4 = 0;
16316 }
16317 
16318 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16319 	.f = cmd_set_mplsogre_decap_parsed,
16320 	.data = NULL,
16321 	.help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16322 	.tokens = {
16323 		(void *)&cmd_set_mplsogre_decap_set,
16324 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16325 		(void *)&cmd_set_mplsogre_decap_ip_version,
16326 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
16327 		NULL,
16328 	},
16329 };
16330 
16331 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16332 	.f = cmd_set_mplsogre_decap_parsed,
16333 	.data = NULL,
16334 	.help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16335 	.tokens = {
16336 		(void *)&cmd_set_mplsogre_decap_set,
16337 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16338 		(void *)&cmd_set_mplsogre_decap_ip_version,
16339 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
16340 		NULL,
16341 	},
16342 };
16343 
16344 /** Set MPLSoUDP encapsulation details */
16345 struct cmd_set_mplsoudp_encap_result {
16346 	cmdline_fixed_string_t set;
16347 	cmdline_fixed_string_t mplsoudp;
16348 	cmdline_fixed_string_t pos_token;
16349 	cmdline_fixed_string_t ip_version;
16350 	uint32_t vlan_present:1;
16351 	uint32_t label;
16352 	uint16_t udp_src;
16353 	uint16_t udp_dst;
16354 	cmdline_ipaddr_t ip_src;
16355 	cmdline_ipaddr_t ip_dst;
16356 	uint16_t tci;
16357 	struct rte_ether_addr eth_src;
16358 	struct rte_ether_addr eth_dst;
16359 };
16360 
16361 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16362 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16363 				 "set");
16364 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16365 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16366 				 "mplsoudp_encap");
16367 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16368 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16369 				 mplsoudp, "mplsoudp_encap-with-vlan");
16370 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16371 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16372 				 pos_token, "ip-version");
16373 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16374 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16375 				 ip_version, "ipv4#ipv6");
16376 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16377 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16378 				 pos_token, "label");
16379 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16380 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16381 			      UINT32);
16382 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16383 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16384 				 pos_token, "udp-src");
16385 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16386 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16387 			      UINT16);
16388 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16389 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16390 				 pos_token, "udp-dst");
16391 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16392 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16393 			      UINT16);
16394 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16395 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16396 				 pos_token, "ip-src");
16397 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16398 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16399 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16400 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16401 				 pos_token, "ip-dst");
16402 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16403 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16404 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16405 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16406 				 pos_token, "vlan-tci");
16407 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16408 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16409 			      UINT16);
16410 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16411 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16412 				 pos_token, "eth-src");
16413 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16414 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16415 				    eth_src);
16416 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16417 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16418 				 pos_token, "eth-dst");
16419 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16420 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16421 				    eth_dst);
16422 
16423 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16424 	__rte_unused struct cmdline *cl,
16425 	__rte_unused void *data)
16426 {
16427 	struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16428 	union {
16429 		uint32_t mplsoudp_label;
16430 		uint8_t label[4];
16431 	} id = {
16432 		.mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16433 	};
16434 
16435 	if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16436 		mplsoudp_encap_conf.select_vlan = 0;
16437 	else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16438 		mplsoudp_encap_conf.select_vlan = 1;
16439 	if (strcmp(res->ip_version, "ipv4") == 0)
16440 		mplsoudp_encap_conf.select_ipv4 = 1;
16441 	else if (strcmp(res->ip_version, "ipv6") == 0)
16442 		mplsoudp_encap_conf.select_ipv4 = 0;
16443 	else
16444 		return;
16445 	rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16446 	mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16447 	mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16448 	if (mplsoudp_encap_conf.select_ipv4) {
16449 		IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16450 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16451 	} else {
16452 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16453 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16454 	}
16455 	if (mplsoudp_encap_conf.select_vlan)
16456 		mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16457 	rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16458 		   RTE_ETHER_ADDR_LEN);
16459 	rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16460 		   RTE_ETHER_ADDR_LEN);
16461 }
16462 
16463 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16464 	.f = cmd_set_mplsoudp_encap_parsed,
16465 	.data = NULL,
16466 	.help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16467 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16468 		" ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16469 	.tokens = {
16470 		(void *)&cmd_set_mplsoudp_encap_set,
16471 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16472 		(void *)&cmd_set_mplsoudp_encap_ip_version,
16473 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
16474 		(void *)&cmd_set_mplsoudp_encap_label,
16475 		(void *)&cmd_set_mplsoudp_encap_label_value,
16476 		(void *)&cmd_set_mplsoudp_encap_udp_src,
16477 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
16478 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
16479 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16480 		(void *)&cmd_set_mplsoudp_encap_ip_src,
16481 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
16482 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
16483 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16484 		(void *)&cmd_set_mplsoudp_encap_eth_src,
16485 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
16486 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
16487 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16488 		NULL,
16489 	},
16490 };
16491 
16492 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16493 	.f = cmd_set_mplsoudp_encap_parsed,
16494 	.data = NULL,
16495 	.help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16496 		" label <label> udp-src <udp-src> udp-dst <udp-dst>"
16497 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16498 		" eth-src <eth-src> eth-dst <eth-dst>",
16499 	.tokens = {
16500 		(void *)&cmd_set_mplsoudp_encap_set,
16501 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16502 		(void *)&cmd_set_mplsoudp_encap_ip_version,
16503 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
16504 		(void *)&cmd_set_mplsoudp_encap_label,
16505 		(void *)&cmd_set_mplsoudp_encap_label_value,
16506 		(void *)&cmd_set_mplsoudp_encap_udp_src,
16507 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
16508 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
16509 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16510 		(void *)&cmd_set_mplsoudp_encap_ip_src,
16511 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
16512 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
16513 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16514 		(void *)&cmd_set_mplsoudp_encap_vlan,
16515 		(void *)&cmd_set_mplsoudp_encap_vlan_value,
16516 		(void *)&cmd_set_mplsoudp_encap_eth_src,
16517 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
16518 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
16519 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16520 		NULL,
16521 	},
16522 };
16523 
16524 /** Set MPLSoUDP decapsulation details */
16525 struct cmd_set_mplsoudp_decap_result {
16526 	cmdline_fixed_string_t set;
16527 	cmdline_fixed_string_t mplsoudp;
16528 	cmdline_fixed_string_t pos_token;
16529 	cmdline_fixed_string_t ip_version;
16530 	uint32_t vlan_present:1;
16531 };
16532 
16533 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16534 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16535 				 "set");
16536 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16537 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16538 				 "mplsoudp_decap");
16539 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16540 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16541 				 mplsoudp, "mplsoudp_decap-with-vlan");
16542 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16543 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16544 				 pos_token, "ip-version");
16545 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16546 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16547 				 ip_version, "ipv4#ipv6");
16548 
16549 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16550 	__rte_unused struct cmdline *cl,
16551 	__rte_unused void *data)
16552 {
16553 	struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16554 
16555 	if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16556 		mplsoudp_decap_conf.select_vlan = 0;
16557 	else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16558 		mplsoudp_decap_conf.select_vlan = 1;
16559 	if (strcmp(res->ip_version, "ipv4") == 0)
16560 		mplsoudp_decap_conf.select_ipv4 = 1;
16561 	else if (strcmp(res->ip_version, "ipv6") == 0)
16562 		mplsoudp_decap_conf.select_ipv4 = 0;
16563 }
16564 
16565 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16566 	.f = cmd_set_mplsoudp_decap_parsed,
16567 	.data = NULL,
16568 	.help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16569 	.tokens = {
16570 		(void *)&cmd_set_mplsoudp_decap_set,
16571 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16572 		(void *)&cmd_set_mplsoudp_decap_ip_version,
16573 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
16574 		NULL,
16575 	},
16576 };
16577 
16578 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16579 	.f = cmd_set_mplsoudp_decap_parsed,
16580 	.data = NULL,
16581 	.help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16582 	.tokens = {
16583 		(void *)&cmd_set_mplsoudp_decap_set,
16584 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16585 		(void *)&cmd_set_mplsoudp_decap_ip_version,
16586 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
16587 		NULL,
16588 	},
16589 };
16590 
16591 /* Strict link priority scheduling mode setting */
16592 static void
16593 cmd_strict_link_prio_parsed(
16594 	void *parsed_result,
16595 	__rte_unused struct cmdline *cl,
16596 	__rte_unused void *data)
16597 {
16598 	struct cmd_vf_tc_bw_result *res = parsed_result;
16599 	int ret = -ENOTSUP;
16600 
16601 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16602 		return;
16603 
16604 #ifdef RTE_LIBRTE_I40E_PMD
16605 	ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16606 #endif
16607 
16608 	switch (ret) {
16609 	case 0:
16610 		break;
16611 	case -EINVAL:
16612 		printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16613 		break;
16614 	case -ENODEV:
16615 		printf("invalid port_id %d\n", res->port_id);
16616 		break;
16617 	case -ENOTSUP:
16618 		printf("function not implemented\n");
16619 		break;
16620 	default:
16621 		printf("programming error: (%s)\n", strerror(-ret));
16622 	}
16623 }
16624 
16625 cmdline_parse_inst_t cmd_strict_link_prio = {
16626 	.f = cmd_strict_link_prio_parsed,
16627 	.data = NULL,
16628 	.help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16629 	.tokens = {
16630 		(void *)&cmd_vf_tc_bw_set,
16631 		(void *)&cmd_vf_tc_bw_tx,
16632 		(void *)&cmd_vf_tc_bw_strict_link_prio,
16633 		(void *)&cmd_vf_tc_bw_port_id,
16634 		(void *)&cmd_vf_tc_bw_tc_map,
16635 		NULL,
16636 	},
16637 };
16638 
16639 /* Load dynamic device personalization*/
16640 struct cmd_ddp_add_result {
16641 	cmdline_fixed_string_t ddp;
16642 	cmdline_fixed_string_t add;
16643 	portid_t port_id;
16644 	char filepath[];
16645 };
16646 
16647 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16648 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16649 cmdline_parse_token_string_t cmd_ddp_add_add =
16650 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16651 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16652 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16653 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16654 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16655 
16656 static void
16657 cmd_ddp_add_parsed(
16658 	void *parsed_result,
16659 	__rte_unused struct cmdline *cl,
16660 	__rte_unused void *data)
16661 {
16662 	struct cmd_ddp_add_result *res = parsed_result;
16663 	uint8_t *buff;
16664 	uint32_t size;
16665 	char *filepath;
16666 	char *file_fld[2];
16667 	int file_num;
16668 	int ret = -ENOTSUP;
16669 
16670 	if (!all_ports_stopped()) {
16671 		printf("Please stop all ports first\n");
16672 		return;
16673 	}
16674 
16675 	filepath = strdup(res->filepath);
16676 	if (filepath == NULL) {
16677 		printf("Failed to allocate memory\n");
16678 		return;
16679 	}
16680 	file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16681 
16682 	buff = open_file(file_fld[0], &size);
16683 	if (!buff) {
16684 		free((void *)filepath);
16685 		return;
16686 	}
16687 
16688 #ifdef RTE_LIBRTE_I40E_PMD
16689 	if (ret == -ENOTSUP)
16690 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16691 					       buff, size,
16692 					       RTE_PMD_I40E_PKG_OP_WR_ADD);
16693 #endif
16694 
16695 	if (ret == -EEXIST)
16696 		printf("Profile has already existed.\n");
16697 	else if (ret < 0)
16698 		printf("Failed to load profile.\n");
16699 	else if (file_num == 2)
16700 		save_file(file_fld[1], buff, size);
16701 
16702 	close_file(buff);
16703 	free((void *)filepath);
16704 }
16705 
16706 cmdline_parse_inst_t cmd_ddp_add = {
16707 	.f = cmd_ddp_add_parsed,
16708 	.data = NULL,
16709 	.help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16710 	.tokens = {
16711 		(void *)&cmd_ddp_add_ddp,
16712 		(void *)&cmd_ddp_add_add,
16713 		(void *)&cmd_ddp_add_port_id,
16714 		(void *)&cmd_ddp_add_filepath,
16715 		NULL,
16716 	},
16717 };
16718 
16719 /* Delete dynamic device personalization*/
16720 struct cmd_ddp_del_result {
16721 	cmdline_fixed_string_t ddp;
16722 	cmdline_fixed_string_t del;
16723 	portid_t port_id;
16724 	char filepath[];
16725 };
16726 
16727 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16728 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16729 cmdline_parse_token_string_t cmd_ddp_del_del =
16730 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16731 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16732 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16733 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16734 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16735 
16736 static void
16737 cmd_ddp_del_parsed(
16738 	void *parsed_result,
16739 	__rte_unused struct cmdline *cl,
16740 	__rte_unused void *data)
16741 {
16742 	struct cmd_ddp_del_result *res = parsed_result;
16743 	uint8_t *buff;
16744 	uint32_t size;
16745 	int ret = -ENOTSUP;
16746 
16747 	if (!all_ports_stopped()) {
16748 		printf("Please stop all ports first\n");
16749 		return;
16750 	}
16751 
16752 	buff = open_file(res->filepath, &size);
16753 	if (!buff)
16754 		return;
16755 
16756 #ifdef RTE_LIBRTE_I40E_PMD
16757 	if (ret == -ENOTSUP)
16758 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16759 					       buff, size,
16760 					       RTE_PMD_I40E_PKG_OP_WR_DEL);
16761 #endif
16762 
16763 	if (ret == -EACCES)
16764 		printf("Profile does not exist.\n");
16765 	else if (ret < 0)
16766 		printf("Failed to delete profile.\n");
16767 
16768 	close_file(buff);
16769 }
16770 
16771 cmdline_parse_inst_t cmd_ddp_del = {
16772 	.f = cmd_ddp_del_parsed,
16773 	.data = NULL,
16774 	.help_str = "ddp del <port_id> <backup_profile_path>",
16775 	.tokens = {
16776 		(void *)&cmd_ddp_del_ddp,
16777 		(void *)&cmd_ddp_del_del,
16778 		(void *)&cmd_ddp_del_port_id,
16779 		(void *)&cmd_ddp_del_filepath,
16780 		NULL,
16781 	},
16782 };
16783 
16784 /* Get dynamic device personalization profile info */
16785 struct cmd_ddp_info_result {
16786 	cmdline_fixed_string_t ddp;
16787 	cmdline_fixed_string_t get;
16788 	cmdline_fixed_string_t info;
16789 	char filepath[];
16790 };
16791 
16792 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16793 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16794 cmdline_parse_token_string_t cmd_ddp_info_get =
16795 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16796 cmdline_parse_token_string_t cmd_ddp_info_info =
16797 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16798 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16799 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16800 
16801 static void
16802 cmd_ddp_info_parsed(
16803 	void *parsed_result,
16804 	__rte_unused struct cmdline *cl,
16805 	__rte_unused void *data)
16806 {
16807 	struct cmd_ddp_info_result *res = parsed_result;
16808 	uint8_t *pkg;
16809 	uint32_t pkg_size;
16810 	int ret = -ENOTSUP;
16811 #ifdef RTE_LIBRTE_I40E_PMD
16812 	uint32_t i, j, n;
16813 	uint8_t *buff;
16814 	uint32_t buff_size = 0;
16815 	struct rte_pmd_i40e_profile_info info;
16816 	uint32_t dev_num = 0;
16817 	struct rte_pmd_i40e_ddp_device_id *devs;
16818 	uint32_t proto_num = 0;
16819 	struct rte_pmd_i40e_proto_info *proto = NULL;
16820 	uint32_t pctype_num = 0;
16821 	struct rte_pmd_i40e_ptype_info *pctype;
16822 	uint32_t ptype_num = 0;
16823 	struct rte_pmd_i40e_ptype_info *ptype;
16824 	uint8_t proto_id;
16825 
16826 #endif
16827 
16828 	pkg = open_file(res->filepath, &pkg_size);
16829 	if (!pkg)
16830 		return;
16831 
16832 #ifdef RTE_LIBRTE_I40E_PMD
16833 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16834 				(uint8_t *)&info, sizeof(info),
16835 				RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16836 	if (!ret) {
16837 		printf("Global Track id:       0x%x\n", info.track_id);
16838 		printf("Global Version:        %d.%d.%d.%d\n",
16839 			info.version.major,
16840 			info.version.minor,
16841 			info.version.update,
16842 			info.version.draft);
16843 		printf("Global Package name:   %s\n\n", info.name);
16844 	}
16845 
16846 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16847 				(uint8_t *)&info, sizeof(info),
16848 				RTE_PMD_I40E_PKG_INFO_HEADER);
16849 	if (!ret) {
16850 		printf("i40e Profile Track id: 0x%x\n", info.track_id);
16851 		printf("i40e Profile Version:  %d.%d.%d.%d\n",
16852 			info.version.major,
16853 			info.version.minor,
16854 			info.version.update,
16855 			info.version.draft);
16856 		printf("i40e Profile name:     %s\n\n", info.name);
16857 	}
16858 
16859 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16860 				(uint8_t *)&buff_size, sizeof(buff_size),
16861 				RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16862 	if (!ret && buff_size) {
16863 		buff = (uint8_t *)malloc(buff_size);
16864 		if (buff) {
16865 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16866 						buff, buff_size,
16867 						RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16868 			if (!ret)
16869 				printf("Package Notes:\n%s\n\n", buff);
16870 			free(buff);
16871 		}
16872 	}
16873 
16874 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16875 				(uint8_t *)&dev_num, sizeof(dev_num),
16876 				RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16877 	if (!ret && dev_num) {
16878 		buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16879 		devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16880 		if (devs) {
16881 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16882 						(uint8_t *)devs, buff_size,
16883 						RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16884 			if (!ret) {
16885 				printf("List of supported devices:\n");
16886 				for (i = 0; i < dev_num; i++) {
16887 					printf("  %04X:%04X %04X:%04X\n",
16888 						devs[i].vendor_dev_id >> 16,
16889 						devs[i].vendor_dev_id & 0xFFFF,
16890 						devs[i].sub_vendor_dev_id >> 16,
16891 						devs[i].sub_vendor_dev_id & 0xFFFF);
16892 				}
16893 				printf("\n");
16894 			}
16895 			free(devs);
16896 		}
16897 	}
16898 
16899 	/* get information about protocols and packet types */
16900 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16901 		(uint8_t *)&proto_num, sizeof(proto_num),
16902 		RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16903 	if (ret || !proto_num)
16904 		goto no_print_return;
16905 
16906 	buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16907 	proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16908 	if (!proto)
16909 		goto no_print_return;
16910 
16911 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16912 					buff_size,
16913 					RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16914 	if (!ret) {
16915 		printf("List of used protocols:\n");
16916 		for (i = 0; i < proto_num; i++)
16917 			printf("  %2u: %s\n", proto[i].proto_id,
16918 			       proto[i].name);
16919 		printf("\n");
16920 	}
16921 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16922 		(uint8_t *)&pctype_num, sizeof(pctype_num),
16923 		RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16924 	if (ret || !pctype_num)
16925 		goto no_print_pctypes;
16926 
16927 	buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16928 	pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16929 	if (!pctype)
16930 		goto no_print_pctypes;
16931 
16932 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16933 					buff_size,
16934 					RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16935 	if (ret) {
16936 		free(pctype);
16937 		goto no_print_pctypes;
16938 	}
16939 
16940 	printf("List of defined packet classification types:\n");
16941 	for (i = 0; i < pctype_num; i++) {
16942 		printf("  %2u:", pctype[i].ptype_id);
16943 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16944 			proto_id = pctype[i].protocols[j];
16945 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16946 				for (n = 0; n < proto_num; n++) {
16947 					if (proto[n].proto_id == proto_id) {
16948 						printf(" %s", proto[n].name);
16949 						break;
16950 					}
16951 				}
16952 			}
16953 		}
16954 		printf("\n");
16955 	}
16956 	printf("\n");
16957 	free(pctype);
16958 
16959 no_print_pctypes:
16960 
16961 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16962 					sizeof(ptype_num),
16963 					RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16964 	if (ret || !ptype_num)
16965 		goto no_print_return;
16966 
16967 	buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16968 	ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16969 	if (!ptype)
16970 		goto no_print_return;
16971 
16972 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16973 					buff_size,
16974 					RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16975 	if (ret) {
16976 		free(ptype);
16977 		goto no_print_return;
16978 	}
16979 	printf("List of defined packet types:\n");
16980 	for (i = 0; i < ptype_num; i++) {
16981 		printf("  %2u:", ptype[i].ptype_id);
16982 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16983 			proto_id = ptype[i].protocols[j];
16984 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16985 				for (n = 0; n < proto_num; n++) {
16986 					if (proto[n].proto_id == proto_id) {
16987 						printf(" %s", proto[n].name);
16988 						break;
16989 					}
16990 				}
16991 			}
16992 		}
16993 		printf("\n");
16994 	}
16995 	free(ptype);
16996 	printf("\n");
16997 
16998 	ret = 0;
16999 no_print_return:
17000 	if (proto)
17001 		free(proto);
17002 #endif
17003 	if (ret == -ENOTSUP)
17004 		printf("Function not supported in PMD driver\n");
17005 	close_file(pkg);
17006 }
17007 
17008 cmdline_parse_inst_t cmd_ddp_get_info = {
17009 	.f = cmd_ddp_info_parsed,
17010 	.data = NULL,
17011 	.help_str = "ddp get info <profile_path>",
17012 	.tokens = {
17013 		(void *)&cmd_ddp_info_ddp,
17014 		(void *)&cmd_ddp_info_get,
17015 		(void *)&cmd_ddp_info_info,
17016 		(void *)&cmd_ddp_info_filepath,
17017 		NULL,
17018 	},
17019 };
17020 
17021 /* Get dynamic device personalization profile info list*/
17022 #define PROFILE_INFO_SIZE 48
17023 #define MAX_PROFILE_NUM 16
17024 
17025 struct cmd_ddp_get_list_result {
17026 	cmdline_fixed_string_t ddp;
17027 	cmdline_fixed_string_t get;
17028 	cmdline_fixed_string_t list;
17029 	portid_t port_id;
17030 };
17031 
17032 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
17033 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
17034 cmdline_parse_token_string_t cmd_ddp_get_list_get =
17035 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
17036 cmdline_parse_token_string_t cmd_ddp_get_list_list =
17037 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
17038 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
17039 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
17040 
17041 static void
17042 cmd_ddp_get_list_parsed(
17043 	__rte_unused void *parsed_result,
17044 	__rte_unused struct cmdline *cl,
17045 	__rte_unused void *data)
17046 {
17047 #ifdef RTE_LIBRTE_I40E_PMD
17048 	struct cmd_ddp_get_list_result *res = parsed_result;
17049 	struct rte_pmd_i40e_profile_list *p_list;
17050 	struct rte_pmd_i40e_profile_info *p_info;
17051 	uint32_t p_num;
17052 	uint32_t size;
17053 	uint32_t i;
17054 #endif
17055 	int ret = -ENOTSUP;
17056 
17057 #ifdef RTE_LIBRTE_I40E_PMD
17058 	size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
17059 	p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
17060 	if (!p_list) {
17061 		printf("%s: Failed to malloc buffer\n", __func__);
17062 		return;
17063 	}
17064 
17065 	if (ret == -ENOTSUP)
17066 		ret = rte_pmd_i40e_get_ddp_list(res->port_id,
17067 						(uint8_t *)p_list, size);
17068 
17069 	if (!ret) {
17070 		p_num = p_list->p_count;
17071 		printf("Profile number is: %d\n\n", p_num);
17072 
17073 		for (i = 0; i < p_num; i++) {
17074 			p_info = &p_list->p_info[i];
17075 			printf("Profile %d:\n", i);
17076 			printf("Track id:     0x%x\n", p_info->track_id);
17077 			printf("Version:      %d.%d.%d.%d\n",
17078 			       p_info->version.major,
17079 			       p_info->version.minor,
17080 			       p_info->version.update,
17081 			       p_info->version.draft);
17082 			printf("Profile name: %s\n\n", p_info->name);
17083 		}
17084 	}
17085 
17086 	free(p_list);
17087 #endif
17088 
17089 	if (ret < 0)
17090 		printf("Failed to get ddp list\n");
17091 }
17092 
17093 cmdline_parse_inst_t cmd_ddp_get_list = {
17094 	.f = cmd_ddp_get_list_parsed,
17095 	.data = NULL,
17096 	.help_str = "ddp get list <port_id>",
17097 	.tokens = {
17098 		(void *)&cmd_ddp_get_list_ddp,
17099 		(void *)&cmd_ddp_get_list_get,
17100 		(void *)&cmd_ddp_get_list_list,
17101 		(void *)&cmd_ddp_get_list_port_id,
17102 		NULL,
17103 	},
17104 };
17105 
17106 /* Configure input set */
17107 struct cmd_cfg_input_set_result {
17108 	cmdline_fixed_string_t port;
17109 	cmdline_fixed_string_t cfg;
17110 	portid_t port_id;
17111 	cmdline_fixed_string_t pctype;
17112 	uint8_t pctype_id;
17113 	cmdline_fixed_string_t inset_type;
17114 	cmdline_fixed_string_t opt;
17115 	cmdline_fixed_string_t field;
17116 	uint8_t field_idx;
17117 };
17118 
17119 static void
17120 cmd_cfg_input_set_parsed(
17121 	__rte_unused void *parsed_result,
17122 	__rte_unused struct cmdline *cl,
17123 	__rte_unused void *data)
17124 {
17125 #ifdef RTE_LIBRTE_I40E_PMD
17126 	struct cmd_cfg_input_set_result *res = parsed_result;
17127 	enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17128 	struct rte_pmd_i40e_inset inset;
17129 #endif
17130 	int ret = -ENOTSUP;
17131 
17132 	if (!all_ports_stopped()) {
17133 		printf("Please stop all ports first\n");
17134 		return;
17135 	}
17136 
17137 #ifdef RTE_LIBRTE_I40E_PMD
17138 	if (!strcmp(res->inset_type, "hash_inset"))
17139 		inset_type = INSET_HASH;
17140 	else if (!strcmp(res->inset_type, "fdir_inset"))
17141 		inset_type = INSET_FDIR;
17142 	else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17143 		inset_type = INSET_FDIR_FLX;
17144 	ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
17145 				     &inset, inset_type);
17146 	if (ret) {
17147 		printf("Failed to get input set.\n");
17148 		return;
17149 	}
17150 
17151 	if (!strcmp(res->opt, "get")) {
17152 		ret = rte_pmd_i40e_inset_field_get(inset.inset,
17153 						   res->field_idx);
17154 		if (ret)
17155 			printf("Field index %d is enabled.\n", res->field_idx);
17156 		else
17157 			printf("Field index %d is disabled.\n", res->field_idx);
17158 		return;
17159 	} else if (!strcmp(res->opt, "set"))
17160 		ret = rte_pmd_i40e_inset_field_set(&inset.inset,
17161 						   res->field_idx);
17162 	else if (!strcmp(res->opt, "clear"))
17163 		ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
17164 						     res->field_idx);
17165 	if (ret) {
17166 		printf("Failed to configure input set field.\n");
17167 		return;
17168 	}
17169 
17170 	ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17171 				     &inset, inset_type);
17172 	if (ret) {
17173 		printf("Failed to set input set.\n");
17174 		return;
17175 	}
17176 #endif
17177 
17178 	if (ret == -ENOTSUP)
17179 		printf("Function not supported\n");
17180 }
17181 
17182 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17183 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17184 				 port, "port");
17185 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17186 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17187 				 cfg, "config");
17188 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17189 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17190 			      port_id, UINT16);
17191 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17192 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17193 				 pctype, "pctype");
17194 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17195 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17196 			      pctype_id, UINT8);
17197 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17198 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17199 				 inset_type,
17200 				 "hash_inset#fdir_inset#fdir_flx_inset");
17201 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17202 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17203 				 opt, "get#set#clear");
17204 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17205 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17206 				 field, "field");
17207 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17208 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17209 			      field_idx, UINT8);
17210 
17211 cmdline_parse_inst_t cmd_cfg_input_set = {
17212 	.f = cmd_cfg_input_set_parsed,
17213 	.data = NULL,
17214 	.help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17215 		    "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17216 	.tokens = {
17217 		(void *)&cmd_cfg_input_set_port,
17218 		(void *)&cmd_cfg_input_set_cfg,
17219 		(void *)&cmd_cfg_input_set_port_id,
17220 		(void *)&cmd_cfg_input_set_pctype,
17221 		(void *)&cmd_cfg_input_set_pctype_id,
17222 		(void *)&cmd_cfg_input_set_inset_type,
17223 		(void *)&cmd_cfg_input_set_opt,
17224 		(void *)&cmd_cfg_input_set_field,
17225 		(void *)&cmd_cfg_input_set_field_idx,
17226 		NULL,
17227 	},
17228 };
17229 
17230 /* Clear input set */
17231 struct cmd_clear_input_set_result {
17232 	cmdline_fixed_string_t port;
17233 	cmdline_fixed_string_t cfg;
17234 	portid_t port_id;
17235 	cmdline_fixed_string_t pctype;
17236 	uint8_t pctype_id;
17237 	cmdline_fixed_string_t inset_type;
17238 	cmdline_fixed_string_t clear;
17239 	cmdline_fixed_string_t all;
17240 };
17241 
17242 static void
17243 cmd_clear_input_set_parsed(
17244 	__rte_unused void *parsed_result,
17245 	__rte_unused struct cmdline *cl,
17246 	__rte_unused void *data)
17247 {
17248 #ifdef RTE_LIBRTE_I40E_PMD
17249 	struct cmd_clear_input_set_result *res = parsed_result;
17250 	enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17251 	struct rte_pmd_i40e_inset inset;
17252 #endif
17253 	int ret = -ENOTSUP;
17254 
17255 	if (!all_ports_stopped()) {
17256 		printf("Please stop all ports first\n");
17257 		return;
17258 	}
17259 
17260 #ifdef RTE_LIBRTE_I40E_PMD
17261 	if (!strcmp(res->inset_type, "hash_inset"))
17262 		inset_type = INSET_HASH;
17263 	else if (!strcmp(res->inset_type, "fdir_inset"))
17264 		inset_type = INSET_FDIR;
17265 	else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17266 		inset_type = INSET_FDIR_FLX;
17267 
17268 	memset(&inset, 0, sizeof(inset));
17269 
17270 	ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17271 				     &inset, inset_type);
17272 	if (ret) {
17273 		printf("Failed to clear input set.\n");
17274 		return;
17275 	}
17276 
17277 #endif
17278 
17279 	if (ret == -ENOTSUP)
17280 		printf("Function not supported\n");
17281 }
17282 
17283 cmdline_parse_token_string_t cmd_clear_input_set_port =
17284 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17285 				 port, "port");
17286 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17287 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17288 				 cfg, "config");
17289 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17290 	TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17291 			      port_id, UINT16);
17292 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17293 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17294 				 pctype, "pctype");
17295 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17296 	TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17297 			      pctype_id, UINT8);
17298 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17299 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17300 				 inset_type,
17301 				 "hash_inset#fdir_inset#fdir_flx_inset");
17302 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17303 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17304 				 clear, "clear");
17305 cmdline_parse_token_string_t cmd_clear_input_set_all =
17306 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17307 				 all, "all");
17308 
17309 cmdline_parse_inst_t cmd_clear_input_set = {
17310 	.f = cmd_clear_input_set_parsed,
17311 	.data = NULL,
17312 	.help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17313 		    "fdir_inset|fdir_flx_inset clear all",
17314 	.tokens = {
17315 		(void *)&cmd_clear_input_set_port,
17316 		(void *)&cmd_clear_input_set_cfg,
17317 		(void *)&cmd_clear_input_set_port_id,
17318 		(void *)&cmd_clear_input_set_pctype,
17319 		(void *)&cmd_clear_input_set_pctype_id,
17320 		(void *)&cmd_clear_input_set_inset_type,
17321 		(void *)&cmd_clear_input_set_clear,
17322 		(void *)&cmd_clear_input_set_all,
17323 		NULL,
17324 	},
17325 };
17326 
17327 /* show vf stats */
17328 
17329 /* Common result structure for show vf stats */
17330 struct cmd_show_vf_stats_result {
17331 	cmdline_fixed_string_t show;
17332 	cmdline_fixed_string_t vf;
17333 	cmdline_fixed_string_t stats;
17334 	portid_t port_id;
17335 	uint16_t vf_id;
17336 };
17337 
17338 /* Common CLI fields show vf stats*/
17339 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17340 	TOKEN_STRING_INITIALIZER
17341 		(struct cmd_show_vf_stats_result,
17342 		 show, "show");
17343 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17344 	TOKEN_STRING_INITIALIZER
17345 		(struct cmd_show_vf_stats_result,
17346 		 vf, "vf");
17347 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17348 	TOKEN_STRING_INITIALIZER
17349 		(struct cmd_show_vf_stats_result,
17350 		 stats, "stats");
17351 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17352 	TOKEN_NUM_INITIALIZER
17353 		(struct cmd_show_vf_stats_result,
17354 		 port_id, UINT16);
17355 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17356 	TOKEN_NUM_INITIALIZER
17357 		(struct cmd_show_vf_stats_result,
17358 		 vf_id, UINT16);
17359 
17360 static void
17361 cmd_show_vf_stats_parsed(
17362 	void *parsed_result,
17363 	__rte_unused struct cmdline *cl,
17364 	__rte_unused void *data)
17365 {
17366 	struct cmd_show_vf_stats_result *res = parsed_result;
17367 	struct rte_eth_stats stats;
17368 	int ret = -ENOTSUP;
17369 	static const char *nic_stats_border = "########################";
17370 
17371 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17372 		return;
17373 
17374 	memset(&stats, 0, sizeof(stats));
17375 
17376 #ifdef RTE_LIBRTE_I40E_PMD
17377 	if (ret == -ENOTSUP)
17378 		ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17379 						res->vf_id,
17380 						&stats);
17381 #endif
17382 #ifdef RTE_LIBRTE_BNXT_PMD
17383 	if (ret == -ENOTSUP)
17384 		ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17385 						res->vf_id,
17386 						&stats);
17387 #endif
17388 
17389 	switch (ret) {
17390 	case 0:
17391 		break;
17392 	case -EINVAL:
17393 		printf("invalid vf_id %d\n", res->vf_id);
17394 		break;
17395 	case -ENODEV:
17396 		printf("invalid port_id %d\n", res->port_id);
17397 		break;
17398 	case -ENOTSUP:
17399 		printf("function not implemented\n");
17400 		break;
17401 	default:
17402 		printf("programming error: (%s)\n", strerror(-ret));
17403 	}
17404 
17405 	printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17406 		nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17407 
17408 	printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17409 	       "%-"PRIu64"\n",
17410 	       stats.ipackets, stats.imissed, stats.ibytes);
17411 	printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17412 	printf("  RX-nombuf:  %-10"PRIu64"\n",
17413 	       stats.rx_nombuf);
17414 	printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17415 	       "%-"PRIu64"\n",
17416 	       stats.opackets, stats.oerrors, stats.obytes);
17417 
17418 	printf("  %s############################%s\n",
17419 			       nic_stats_border, nic_stats_border);
17420 }
17421 
17422 cmdline_parse_inst_t cmd_show_vf_stats = {
17423 	.f = cmd_show_vf_stats_parsed,
17424 	.data = NULL,
17425 	.help_str = "show vf stats <port_id> <vf_id>",
17426 	.tokens = {
17427 		(void *)&cmd_show_vf_stats_show,
17428 		(void *)&cmd_show_vf_stats_vf,
17429 		(void *)&cmd_show_vf_stats_stats,
17430 		(void *)&cmd_show_vf_stats_port_id,
17431 		(void *)&cmd_show_vf_stats_vf_id,
17432 		NULL,
17433 	},
17434 };
17435 
17436 /* clear vf stats */
17437 
17438 /* Common result structure for clear vf stats */
17439 struct cmd_clear_vf_stats_result {
17440 	cmdline_fixed_string_t clear;
17441 	cmdline_fixed_string_t vf;
17442 	cmdline_fixed_string_t stats;
17443 	portid_t port_id;
17444 	uint16_t vf_id;
17445 };
17446 
17447 /* Common CLI fields clear vf stats*/
17448 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17449 	TOKEN_STRING_INITIALIZER
17450 		(struct cmd_clear_vf_stats_result,
17451 		 clear, "clear");
17452 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17453 	TOKEN_STRING_INITIALIZER
17454 		(struct cmd_clear_vf_stats_result,
17455 		 vf, "vf");
17456 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17457 	TOKEN_STRING_INITIALIZER
17458 		(struct cmd_clear_vf_stats_result,
17459 		 stats, "stats");
17460 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17461 	TOKEN_NUM_INITIALIZER
17462 		(struct cmd_clear_vf_stats_result,
17463 		 port_id, UINT16);
17464 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17465 	TOKEN_NUM_INITIALIZER
17466 		(struct cmd_clear_vf_stats_result,
17467 		 vf_id, UINT16);
17468 
17469 static void
17470 cmd_clear_vf_stats_parsed(
17471 	void *parsed_result,
17472 	__rte_unused struct cmdline *cl,
17473 	__rte_unused void *data)
17474 {
17475 	struct cmd_clear_vf_stats_result *res = parsed_result;
17476 	int ret = -ENOTSUP;
17477 
17478 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17479 		return;
17480 
17481 #ifdef RTE_LIBRTE_I40E_PMD
17482 	if (ret == -ENOTSUP)
17483 		ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17484 						  res->vf_id);
17485 #endif
17486 #ifdef RTE_LIBRTE_BNXT_PMD
17487 	if (ret == -ENOTSUP)
17488 		ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17489 						  res->vf_id);
17490 #endif
17491 
17492 	switch (ret) {
17493 	case 0:
17494 		break;
17495 	case -EINVAL:
17496 		printf("invalid vf_id %d\n", res->vf_id);
17497 		break;
17498 	case -ENODEV:
17499 		printf("invalid port_id %d\n", res->port_id);
17500 		break;
17501 	case -ENOTSUP:
17502 		printf("function not implemented\n");
17503 		break;
17504 	default:
17505 		printf("programming error: (%s)\n", strerror(-ret));
17506 	}
17507 }
17508 
17509 cmdline_parse_inst_t cmd_clear_vf_stats = {
17510 	.f = cmd_clear_vf_stats_parsed,
17511 	.data = NULL,
17512 	.help_str = "clear vf stats <port_id> <vf_id>",
17513 	.tokens = {
17514 		(void *)&cmd_clear_vf_stats_clear,
17515 		(void *)&cmd_clear_vf_stats_vf,
17516 		(void *)&cmd_clear_vf_stats_stats,
17517 		(void *)&cmd_clear_vf_stats_port_id,
17518 		(void *)&cmd_clear_vf_stats_vf_id,
17519 		NULL,
17520 	},
17521 };
17522 
17523 /* port config pctype mapping reset */
17524 
17525 /* Common result structure for port config pctype mapping reset */
17526 struct cmd_pctype_mapping_reset_result {
17527 	cmdline_fixed_string_t port;
17528 	cmdline_fixed_string_t config;
17529 	portid_t port_id;
17530 	cmdline_fixed_string_t pctype;
17531 	cmdline_fixed_string_t mapping;
17532 	cmdline_fixed_string_t reset;
17533 };
17534 
17535 /* Common CLI fields for port config pctype mapping reset*/
17536 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17537 	TOKEN_STRING_INITIALIZER
17538 		(struct cmd_pctype_mapping_reset_result,
17539 		 port, "port");
17540 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17541 	TOKEN_STRING_INITIALIZER
17542 		(struct cmd_pctype_mapping_reset_result,
17543 		 config, "config");
17544 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17545 	TOKEN_NUM_INITIALIZER
17546 		(struct cmd_pctype_mapping_reset_result,
17547 		 port_id, UINT16);
17548 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17549 	TOKEN_STRING_INITIALIZER
17550 		(struct cmd_pctype_mapping_reset_result,
17551 		 pctype, "pctype");
17552 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17553 	TOKEN_STRING_INITIALIZER
17554 		(struct cmd_pctype_mapping_reset_result,
17555 		 mapping, "mapping");
17556 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17557 	TOKEN_STRING_INITIALIZER
17558 		(struct cmd_pctype_mapping_reset_result,
17559 		 reset, "reset");
17560 
17561 static void
17562 cmd_pctype_mapping_reset_parsed(
17563 	void *parsed_result,
17564 	__rte_unused struct cmdline *cl,
17565 	__rte_unused void *data)
17566 {
17567 	struct cmd_pctype_mapping_reset_result *res = parsed_result;
17568 	int ret = -ENOTSUP;
17569 
17570 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17571 		return;
17572 
17573 #ifdef RTE_LIBRTE_I40E_PMD
17574 	ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17575 #endif
17576 
17577 	switch (ret) {
17578 	case 0:
17579 		break;
17580 	case -ENODEV:
17581 		printf("invalid port_id %d\n", res->port_id);
17582 		break;
17583 	case -ENOTSUP:
17584 		printf("function not implemented\n");
17585 		break;
17586 	default:
17587 		printf("programming error: (%s)\n", strerror(-ret));
17588 	}
17589 }
17590 
17591 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17592 	.f = cmd_pctype_mapping_reset_parsed,
17593 	.data = NULL,
17594 	.help_str = "port config <port_id> pctype mapping reset",
17595 	.tokens = {
17596 		(void *)&cmd_pctype_mapping_reset_port,
17597 		(void *)&cmd_pctype_mapping_reset_config,
17598 		(void *)&cmd_pctype_mapping_reset_port_id,
17599 		(void *)&cmd_pctype_mapping_reset_pctype,
17600 		(void *)&cmd_pctype_mapping_reset_mapping,
17601 		(void *)&cmd_pctype_mapping_reset_reset,
17602 		NULL,
17603 	},
17604 };
17605 
17606 /* show port pctype mapping */
17607 
17608 /* Common result structure for show port pctype mapping */
17609 struct cmd_pctype_mapping_get_result {
17610 	cmdline_fixed_string_t show;
17611 	cmdline_fixed_string_t port;
17612 	portid_t port_id;
17613 	cmdline_fixed_string_t pctype;
17614 	cmdline_fixed_string_t mapping;
17615 };
17616 
17617 /* Common CLI fields for pctype mapping get */
17618 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17619 	TOKEN_STRING_INITIALIZER
17620 		(struct cmd_pctype_mapping_get_result,
17621 		 show, "show");
17622 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17623 	TOKEN_STRING_INITIALIZER
17624 		(struct cmd_pctype_mapping_get_result,
17625 		 port, "port");
17626 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17627 	TOKEN_NUM_INITIALIZER
17628 		(struct cmd_pctype_mapping_get_result,
17629 		 port_id, UINT16);
17630 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17631 	TOKEN_STRING_INITIALIZER
17632 		(struct cmd_pctype_mapping_get_result,
17633 		 pctype, "pctype");
17634 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17635 	TOKEN_STRING_INITIALIZER
17636 		(struct cmd_pctype_mapping_get_result,
17637 		 mapping, "mapping");
17638 
17639 static void
17640 cmd_pctype_mapping_get_parsed(
17641 	void *parsed_result,
17642 	__rte_unused struct cmdline *cl,
17643 	__rte_unused void *data)
17644 {
17645 	struct cmd_pctype_mapping_get_result *res = parsed_result;
17646 	int ret = -ENOTSUP;
17647 #ifdef RTE_LIBRTE_I40E_PMD
17648 	struct rte_pmd_i40e_flow_type_mapping
17649 				mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17650 	int i, j, first_pctype;
17651 #endif
17652 
17653 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17654 		return;
17655 
17656 #ifdef RTE_LIBRTE_I40E_PMD
17657 	ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17658 #endif
17659 
17660 	switch (ret) {
17661 	case 0:
17662 		break;
17663 	case -ENODEV:
17664 		printf("invalid port_id %d\n", res->port_id);
17665 		return;
17666 	case -ENOTSUP:
17667 		printf("function not implemented\n");
17668 		return;
17669 	default:
17670 		printf("programming error: (%s)\n", strerror(-ret));
17671 		return;
17672 	}
17673 
17674 #ifdef RTE_LIBRTE_I40E_PMD
17675 	for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17676 		if (mapping[i].pctype != 0ULL) {
17677 			first_pctype = 1;
17678 
17679 			printf("pctype: ");
17680 			for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17681 				if (mapping[i].pctype & (1ULL << j)) {
17682 					printf(first_pctype ?
17683 					       "%02d" : ",%02d", j);
17684 					first_pctype = 0;
17685 				}
17686 			}
17687 			printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17688 		}
17689 	}
17690 #endif
17691 }
17692 
17693 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17694 	.f = cmd_pctype_mapping_get_parsed,
17695 	.data = NULL,
17696 	.help_str = "show port <port_id> pctype mapping",
17697 	.tokens = {
17698 		(void *)&cmd_pctype_mapping_get_show,
17699 		(void *)&cmd_pctype_mapping_get_port,
17700 		(void *)&cmd_pctype_mapping_get_port_id,
17701 		(void *)&cmd_pctype_mapping_get_pctype,
17702 		(void *)&cmd_pctype_mapping_get_mapping,
17703 		NULL,
17704 	},
17705 };
17706 
17707 /* port config pctype mapping update */
17708 
17709 /* Common result structure for port config pctype mapping update */
17710 struct cmd_pctype_mapping_update_result {
17711 	cmdline_fixed_string_t port;
17712 	cmdline_fixed_string_t config;
17713 	portid_t port_id;
17714 	cmdline_fixed_string_t pctype;
17715 	cmdline_fixed_string_t mapping;
17716 	cmdline_fixed_string_t update;
17717 	cmdline_fixed_string_t pctype_list;
17718 	uint16_t flow_type;
17719 };
17720 
17721 /* Common CLI fields for pctype mapping update*/
17722 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17723 	TOKEN_STRING_INITIALIZER
17724 		(struct cmd_pctype_mapping_update_result,
17725 		 port, "port");
17726 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17727 	TOKEN_STRING_INITIALIZER
17728 		(struct cmd_pctype_mapping_update_result,
17729 		 config, "config");
17730 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17731 	TOKEN_NUM_INITIALIZER
17732 		(struct cmd_pctype_mapping_update_result,
17733 		 port_id, UINT16);
17734 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17735 	TOKEN_STRING_INITIALIZER
17736 		(struct cmd_pctype_mapping_update_result,
17737 		 pctype, "pctype");
17738 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17739 	TOKEN_STRING_INITIALIZER
17740 		(struct cmd_pctype_mapping_update_result,
17741 		 mapping, "mapping");
17742 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17743 	TOKEN_STRING_INITIALIZER
17744 		(struct cmd_pctype_mapping_update_result,
17745 		 update, "update");
17746 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17747 	TOKEN_STRING_INITIALIZER
17748 		(struct cmd_pctype_mapping_update_result,
17749 		 pctype_list, NULL);
17750 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17751 	TOKEN_NUM_INITIALIZER
17752 		(struct cmd_pctype_mapping_update_result,
17753 		 flow_type, UINT16);
17754 
17755 static void
17756 cmd_pctype_mapping_update_parsed(
17757 	void *parsed_result,
17758 	__rte_unused struct cmdline *cl,
17759 	__rte_unused void *data)
17760 {
17761 	struct cmd_pctype_mapping_update_result *res = parsed_result;
17762 	int ret = -ENOTSUP;
17763 #ifdef RTE_LIBRTE_I40E_PMD
17764 	struct rte_pmd_i40e_flow_type_mapping mapping;
17765 	unsigned int i;
17766 	unsigned int nb_item;
17767 	unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17768 #endif
17769 
17770 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17771 		return;
17772 
17773 #ifdef RTE_LIBRTE_I40E_PMD
17774 	nb_item = parse_item_list(res->pctype_list, "pctypes",
17775 				  RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17776 	mapping.flow_type = res->flow_type;
17777 	for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17778 		mapping.pctype |= (1ULL << pctype_list[i]);
17779 	ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17780 						&mapping,
17781 						1,
17782 						0);
17783 #endif
17784 
17785 	switch (ret) {
17786 	case 0:
17787 		break;
17788 	case -EINVAL:
17789 		printf("invalid pctype or flow type\n");
17790 		break;
17791 	case -ENODEV:
17792 		printf("invalid port_id %d\n", res->port_id);
17793 		break;
17794 	case -ENOTSUP:
17795 		printf("function not implemented\n");
17796 		break;
17797 	default:
17798 		printf("programming error: (%s)\n", strerror(-ret));
17799 	}
17800 }
17801 
17802 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17803 	.f = cmd_pctype_mapping_update_parsed,
17804 	.data = NULL,
17805 	.help_str = "port config <port_id> pctype mapping update"
17806 	" <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17807 	.tokens = {
17808 		(void *)&cmd_pctype_mapping_update_port,
17809 		(void *)&cmd_pctype_mapping_update_config,
17810 		(void *)&cmd_pctype_mapping_update_port_id,
17811 		(void *)&cmd_pctype_mapping_update_pctype,
17812 		(void *)&cmd_pctype_mapping_update_mapping,
17813 		(void *)&cmd_pctype_mapping_update_update,
17814 		(void *)&cmd_pctype_mapping_update_pc_type,
17815 		(void *)&cmd_pctype_mapping_update_flow_type,
17816 		NULL,
17817 	},
17818 };
17819 
17820 /* ptype mapping get */
17821 
17822 /* Common result structure for ptype mapping get */
17823 struct cmd_ptype_mapping_get_result {
17824 	cmdline_fixed_string_t ptype;
17825 	cmdline_fixed_string_t mapping;
17826 	cmdline_fixed_string_t get;
17827 	portid_t port_id;
17828 	uint8_t valid_only;
17829 };
17830 
17831 /* Common CLI fields for ptype mapping get */
17832 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17833 	TOKEN_STRING_INITIALIZER
17834 		(struct cmd_ptype_mapping_get_result,
17835 		 ptype, "ptype");
17836 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17837 	TOKEN_STRING_INITIALIZER
17838 		(struct cmd_ptype_mapping_get_result,
17839 		 mapping, "mapping");
17840 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17841 	TOKEN_STRING_INITIALIZER
17842 		(struct cmd_ptype_mapping_get_result,
17843 		 get, "get");
17844 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17845 	TOKEN_NUM_INITIALIZER
17846 		(struct cmd_ptype_mapping_get_result,
17847 		 port_id, UINT16);
17848 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17849 	TOKEN_NUM_INITIALIZER
17850 		(struct cmd_ptype_mapping_get_result,
17851 		 valid_only, UINT8);
17852 
17853 static void
17854 cmd_ptype_mapping_get_parsed(
17855 	void *parsed_result,
17856 	__rte_unused struct cmdline *cl,
17857 	__rte_unused void *data)
17858 {
17859 	struct cmd_ptype_mapping_get_result *res = parsed_result;
17860 	int ret = -ENOTSUP;
17861 #ifdef RTE_LIBRTE_I40E_PMD
17862 	int max_ptype_num = 256;
17863 	struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17864 	uint16_t count;
17865 	int i;
17866 #endif
17867 
17868 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17869 		return;
17870 
17871 #ifdef RTE_LIBRTE_I40E_PMD
17872 	ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17873 					mapping,
17874 					max_ptype_num,
17875 					&count,
17876 					res->valid_only);
17877 #endif
17878 
17879 	switch (ret) {
17880 	case 0:
17881 		break;
17882 	case -ENODEV:
17883 		printf("invalid port_id %d\n", res->port_id);
17884 		break;
17885 	case -ENOTSUP:
17886 		printf("function not implemented\n");
17887 		break;
17888 	default:
17889 		printf("programming error: (%s)\n", strerror(-ret));
17890 	}
17891 
17892 #ifdef RTE_LIBRTE_I40E_PMD
17893 	if (!ret) {
17894 		for (i = 0; i < count; i++)
17895 			printf("%3d\t0x%08x\n",
17896 				mapping[i].hw_ptype, mapping[i].sw_ptype);
17897 	}
17898 #endif
17899 }
17900 
17901 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17902 	.f = cmd_ptype_mapping_get_parsed,
17903 	.data = NULL,
17904 	.help_str = "ptype mapping get <port_id> <valid_only>",
17905 	.tokens = {
17906 		(void *)&cmd_ptype_mapping_get_ptype,
17907 		(void *)&cmd_ptype_mapping_get_mapping,
17908 		(void *)&cmd_ptype_mapping_get_get,
17909 		(void *)&cmd_ptype_mapping_get_port_id,
17910 		(void *)&cmd_ptype_mapping_get_valid_only,
17911 		NULL,
17912 	},
17913 };
17914 
17915 /* ptype mapping replace */
17916 
17917 /* Common result structure for ptype mapping replace */
17918 struct cmd_ptype_mapping_replace_result {
17919 	cmdline_fixed_string_t ptype;
17920 	cmdline_fixed_string_t mapping;
17921 	cmdline_fixed_string_t replace;
17922 	portid_t port_id;
17923 	uint32_t target;
17924 	uint8_t mask;
17925 	uint32_t pkt_type;
17926 };
17927 
17928 /* Common CLI fields for ptype mapping replace */
17929 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17930 	TOKEN_STRING_INITIALIZER
17931 		(struct cmd_ptype_mapping_replace_result,
17932 		 ptype, "ptype");
17933 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17934 	TOKEN_STRING_INITIALIZER
17935 		(struct cmd_ptype_mapping_replace_result,
17936 		 mapping, "mapping");
17937 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17938 	TOKEN_STRING_INITIALIZER
17939 		(struct cmd_ptype_mapping_replace_result,
17940 		 replace, "replace");
17941 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17942 	TOKEN_NUM_INITIALIZER
17943 		(struct cmd_ptype_mapping_replace_result,
17944 		 port_id, UINT16);
17945 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17946 	TOKEN_NUM_INITIALIZER
17947 		(struct cmd_ptype_mapping_replace_result,
17948 		 target, UINT32);
17949 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17950 	TOKEN_NUM_INITIALIZER
17951 		(struct cmd_ptype_mapping_replace_result,
17952 		 mask, UINT8);
17953 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17954 	TOKEN_NUM_INITIALIZER
17955 		(struct cmd_ptype_mapping_replace_result,
17956 		 pkt_type, UINT32);
17957 
17958 static void
17959 cmd_ptype_mapping_replace_parsed(
17960 	void *parsed_result,
17961 	__rte_unused struct cmdline *cl,
17962 	__rte_unused void *data)
17963 {
17964 	struct cmd_ptype_mapping_replace_result *res = parsed_result;
17965 	int ret = -ENOTSUP;
17966 
17967 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17968 		return;
17969 
17970 #ifdef RTE_LIBRTE_I40E_PMD
17971 	ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17972 					res->target,
17973 					res->mask,
17974 					res->pkt_type);
17975 #endif
17976 
17977 	switch (ret) {
17978 	case 0:
17979 		break;
17980 	case -EINVAL:
17981 		printf("invalid ptype 0x%8x or 0x%8x\n",
17982 				res->target, res->pkt_type);
17983 		break;
17984 	case -ENODEV:
17985 		printf("invalid port_id %d\n", res->port_id);
17986 		break;
17987 	case -ENOTSUP:
17988 		printf("function not implemented\n");
17989 		break;
17990 	default:
17991 		printf("programming error: (%s)\n", strerror(-ret));
17992 	}
17993 }
17994 
17995 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17996 	.f = cmd_ptype_mapping_replace_parsed,
17997 	.data = NULL,
17998 	.help_str =
17999 		"ptype mapping replace <port_id> <target> <mask> <pkt_type>",
18000 	.tokens = {
18001 		(void *)&cmd_ptype_mapping_replace_ptype,
18002 		(void *)&cmd_ptype_mapping_replace_mapping,
18003 		(void *)&cmd_ptype_mapping_replace_replace,
18004 		(void *)&cmd_ptype_mapping_replace_port_id,
18005 		(void *)&cmd_ptype_mapping_replace_target,
18006 		(void *)&cmd_ptype_mapping_replace_mask,
18007 		(void *)&cmd_ptype_mapping_replace_pkt_type,
18008 		NULL,
18009 	},
18010 };
18011 
18012 /* ptype mapping reset */
18013 
18014 /* Common result structure for ptype mapping reset */
18015 struct cmd_ptype_mapping_reset_result {
18016 	cmdline_fixed_string_t ptype;
18017 	cmdline_fixed_string_t mapping;
18018 	cmdline_fixed_string_t reset;
18019 	portid_t port_id;
18020 };
18021 
18022 /* Common CLI fields for ptype mapping reset*/
18023 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
18024 	TOKEN_STRING_INITIALIZER
18025 		(struct cmd_ptype_mapping_reset_result,
18026 		 ptype, "ptype");
18027 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
18028 	TOKEN_STRING_INITIALIZER
18029 		(struct cmd_ptype_mapping_reset_result,
18030 		 mapping, "mapping");
18031 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
18032 	TOKEN_STRING_INITIALIZER
18033 		(struct cmd_ptype_mapping_reset_result,
18034 		 reset, "reset");
18035 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
18036 	TOKEN_NUM_INITIALIZER
18037 		(struct cmd_ptype_mapping_reset_result,
18038 		 port_id, UINT16);
18039 
18040 static void
18041 cmd_ptype_mapping_reset_parsed(
18042 	void *parsed_result,
18043 	__rte_unused struct cmdline *cl,
18044 	__rte_unused void *data)
18045 {
18046 	struct cmd_ptype_mapping_reset_result *res = parsed_result;
18047 	int ret = -ENOTSUP;
18048 
18049 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18050 		return;
18051 
18052 #ifdef RTE_LIBRTE_I40E_PMD
18053 	ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
18054 #endif
18055 
18056 	switch (ret) {
18057 	case 0:
18058 		break;
18059 	case -ENODEV:
18060 		printf("invalid port_id %d\n", res->port_id);
18061 		break;
18062 	case -ENOTSUP:
18063 		printf("function not implemented\n");
18064 		break;
18065 	default:
18066 		printf("programming error: (%s)\n", strerror(-ret));
18067 	}
18068 }
18069 
18070 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
18071 	.f = cmd_ptype_mapping_reset_parsed,
18072 	.data = NULL,
18073 	.help_str = "ptype mapping reset <port_id>",
18074 	.tokens = {
18075 		(void *)&cmd_ptype_mapping_reset_ptype,
18076 		(void *)&cmd_ptype_mapping_reset_mapping,
18077 		(void *)&cmd_ptype_mapping_reset_reset,
18078 		(void *)&cmd_ptype_mapping_reset_port_id,
18079 		NULL,
18080 	},
18081 };
18082 
18083 /* ptype mapping update */
18084 
18085 /* Common result structure for ptype mapping update */
18086 struct cmd_ptype_mapping_update_result {
18087 	cmdline_fixed_string_t ptype;
18088 	cmdline_fixed_string_t mapping;
18089 	cmdline_fixed_string_t reset;
18090 	portid_t port_id;
18091 	uint8_t hw_ptype;
18092 	uint32_t sw_ptype;
18093 };
18094 
18095 /* Common CLI fields for ptype mapping update*/
18096 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
18097 	TOKEN_STRING_INITIALIZER
18098 		(struct cmd_ptype_mapping_update_result,
18099 		 ptype, "ptype");
18100 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
18101 	TOKEN_STRING_INITIALIZER
18102 		(struct cmd_ptype_mapping_update_result,
18103 		 mapping, "mapping");
18104 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
18105 	TOKEN_STRING_INITIALIZER
18106 		(struct cmd_ptype_mapping_update_result,
18107 		 reset, "update");
18108 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
18109 	TOKEN_NUM_INITIALIZER
18110 		(struct cmd_ptype_mapping_update_result,
18111 		 port_id, UINT16);
18112 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
18113 	TOKEN_NUM_INITIALIZER
18114 		(struct cmd_ptype_mapping_update_result,
18115 		 hw_ptype, UINT8);
18116 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
18117 	TOKEN_NUM_INITIALIZER
18118 		(struct cmd_ptype_mapping_update_result,
18119 		 sw_ptype, UINT32);
18120 
18121 static void
18122 cmd_ptype_mapping_update_parsed(
18123 	void *parsed_result,
18124 	__rte_unused struct cmdline *cl,
18125 	__rte_unused void *data)
18126 {
18127 	struct cmd_ptype_mapping_update_result *res = parsed_result;
18128 	int ret = -ENOTSUP;
18129 #ifdef RTE_LIBRTE_I40E_PMD
18130 	struct rte_pmd_i40e_ptype_mapping mapping;
18131 #endif
18132 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18133 		return;
18134 
18135 #ifdef RTE_LIBRTE_I40E_PMD
18136 	mapping.hw_ptype = res->hw_ptype;
18137 	mapping.sw_ptype = res->sw_ptype;
18138 	ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
18139 						&mapping,
18140 						1,
18141 						0);
18142 #endif
18143 
18144 	switch (ret) {
18145 	case 0:
18146 		break;
18147 	case -EINVAL:
18148 		printf("invalid ptype 0x%8x\n", res->sw_ptype);
18149 		break;
18150 	case -ENODEV:
18151 		printf("invalid port_id %d\n", res->port_id);
18152 		break;
18153 	case -ENOTSUP:
18154 		printf("function not implemented\n");
18155 		break;
18156 	default:
18157 		printf("programming error: (%s)\n", strerror(-ret));
18158 	}
18159 }
18160 
18161 cmdline_parse_inst_t cmd_ptype_mapping_update = {
18162 	.f = cmd_ptype_mapping_update_parsed,
18163 	.data = NULL,
18164 	.help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
18165 	.tokens = {
18166 		(void *)&cmd_ptype_mapping_update_ptype,
18167 		(void *)&cmd_ptype_mapping_update_mapping,
18168 		(void *)&cmd_ptype_mapping_update_update,
18169 		(void *)&cmd_ptype_mapping_update_port_id,
18170 		(void *)&cmd_ptype_mapping_update_hw_ptype,
18171 		(void *)&cmd_ptype_mapping_update_sw_ptype,
18172 		NULL,
18173 	},
18174 };
18175 
18176 /* Common result structure for file commands */
18177 struct cmd_cmdfile_result {
18178 	cmdline_fixed_string_t load;
18179 	cmdline_fixed_string_t filename;
18180 };
18181 
18182 /* Common CLI fields for file commands */
18183 cmdline_parse_token_string_t cmd_load_cmdfile =
18184 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18185 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18186 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18187 
18188 static void
18189 cmd_load_from_file_parsed(
18190 	void *parsed_result,
18191 	__rte_unused struct cmdline *cl,
18192 	__rte_unused void *data)
18193 {
18194 	struct cmd_cmdfile_result *res = parsed_result;
18195 
18196 	cmdline_read_from_file(res->filename);
18197 }
18198 
18199 cmdline_parse_inst_t cmd_load_from_file = {
18200 	.f = cmd_load_from_file_parsed,
18201 	.data = NULL,
18202 	.help_str = "load <filename>",
18203 	.tokens = {
18204 		(void *)&cmd_load_cmdfile,
18205 		(void *)&cmd_load_cmdfile_filename,
18206 		NULL,
18207 	},
18208 };
18209 
18210 /* Get Rx offloads capabilities */
18211 struct cmd_rx_offload_get_capa_result {
18212 	cmdline_fixed_string_t show;
18213 	cmdline_fixed_string_t port;
18214 	portid_t port_id;
18215 	cmdline_fixed_string_t rx_offload;
18216 	cmdline_fixed_string_t capabilities;
18217 };
18218 
18219 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18220 	TOKEN_STRING_INITIALIZER
18221 		(struct cmd_rx_offload_get_capa_result,
18222 		 show, "show");
18223 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18224 	TOKEN_STRING_INITIALIZER
18225 		(struct cmd_rx_offload_get_capa_result,
18226 		 port, "port");
18227 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18228 	TOKEN_NUM_INITIALIZER
18229 		(struct cmd_rx_offload_get_capa_result,
18230 		 port_id, UINT16);
18231 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18232 	TOKEN_STRING_INITIALIZER
18233 		(struct cmd_rx_offload_get_capa_result,
18234 		 rx_offload, "rx_offload");
18235 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18236 	TOKEN_STRING_INITIALIZER
18237 		(struct cmd_rx_offload_get_capa_result,
18238 		 capabilities, "capabilities");
18239 
18240 static void
18241 print_rx_offloads(uint64_t offloads)
18242 {
18243 	uint64_t single_offload;
18244 	int begin;
18245 	int end;
18246 	int bit;
18247 
18248 	if (offloads == 0)
18249 		return;
18250 
18251 	begin = __builtin_ctzll(offloads);
18252 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18253 
18254 	single_offload = 1ULL << begin;
18255 	for (bit = begin; bit < end; bit++) {
18256 		if (offloads & single_offload)
18257 			printf(" %s",
18258 			       rte_eth_dev_rx_offload_name(single_offload));
18259 		single_offload <<= 1;
18260 	}
18261 }
18262 
18263 static void
18264 cmd_rx_offload_get_capa_parsed(
18265 	void *parsed_result,
18266 	__rte_unused struct cmdline *cl,
18267 	__rte_unused void *data)
18268 {
18269 	struct cmd_rx_offload_get_capa_result *res = parsed_result;
18270 	struct rte_eth_dev_info dev_info;
18271 	portid_t port_id = res->port_id;
18272 	uint64_t queue_offloads;
18273 	uint64_t port_offloads;
18274 	int ret;
18275 
18276 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18277 	if (ret != 0)
18278 		return;
18279 
18280 	queue_offloads = dev_info.rx_queue_offload_capa;
18281 	port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18282 
18283 	printf("Rx Offloading Capabilities of port %d :\n", port_id);
18284 	printf("  Per Queue :");
18285 	print_rx_offloads(queue_offloads);
18286 
18287 	printf("\n");
18288 	printf("  Per Port  :");
18289 	print_rx_offloads(port_offloads);
18290 	printf("\n\n");
18291 }
18292 
18293 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18294 	.f = cmd_rx_offload_get_capa_parsed,
18295 	.data = NULL,
18296 	.help_str = "show port <port_id> rx_offload capabilities",
18297 	.tokens = {
18298 		(void *)&cmd_rx_offload_get_capa_show,
18299 		(void *)&cmd_rx_offload_get_capa_port,
18300 		(void *)&cmd_rx_offload_get_capa_port_id,
18301 		(void *)&cmd_rx_offload_get_capa_rx_offload,
18302 		(void *)&cmd_rx_offload_get_capa_capabilities,
18303 		NULL,
18304 	}
18305 };
18306 
18307 /* Get Rx offloads configuration */
18308 struct cmd_rx_offload_get_configuration_result {
18309 	cmdline_fixed_string_t show;
18310 	cmdline_fixed_string_t port;
18311 	portid_t port_id;
18312 	cmdline_fixed_string_t rx_offload;
18313 	cmdline_fixed_string_t configuration;
18314 };
18315 
18316 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18317 	TOKEN_STRING_INITIALIZER
18318 		(struct cmd_rx_offload_get_configuration_result,
18319 		 show, "show");
18320 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18321 	TOKEN_STRING_INITIALIZER
18322 		(struct cmd_rx_offload_get_configuration_result,
18323 		 port, "port");
18324 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18325 	TOKEN_NUM_INITIALIZER
18326 		(struct cmd_rx_offload_get_configuration_result,
18327 		 port_id, UINT16);
18328 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18329 	TOKEN_STRING_INITIALIZER
18330 		(struct cmd_rx_offload_get_configuration_result,
18331 		 rx_offload, "rx_offload");
18332 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18333 	TOKEN_STRING_INITIALIZER
18334 		(struct cmd_rx_offload_get_configuration_result,
18335 		 configuration, "configuration");
18336 
18337 static void
18338 cmd_rx_offload_get_configuration_parsed(
18339 	void *parsed_result,
18340 	__rte_unused struct cmdline *cl,
18341 	__rte_unused void *data)
18342 {
18343 	struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18344 	struct rte_eth_dev_info dev_info;
18345 	portid_t port_id = res->port_id;
18346 	struct rte_port *port = &ports[port_id];
18347 	uint64_t port_offloads;
18348 	uint64_t queue_offloads;
18349 	uint16_t nb_rx_queues;
18350 	int q;
18351 	int ret;
18352 
18353 	printf("Rx Offloading Configuration of port %d :\n", port_id);
18354 
18355 	port_offloads = port->dev_conf.rxmode.offloads;
18356 	printf("  Port :");
18357 	print_rx_offloads(port_offloads);
18358 	printf("\n");
18359 
18360 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18361 	if (ret != 0)
18362 		return;
18363 
18364 	nb_rx_queues = dev_info.nb_rx_queues;
18365 	for (q = 0; q < nb_rx_queues; q++) {
18366 		queue_offloads = port->rx_conf[q].offloads;
18367 		printf("  Queue[%2d] :", q);
18368 		print_rx_offloads(queue_offloads);
18369 		printf("\n");
18370 	}
18371 	printf("\n");
18372 }
18373 
18374 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18375 	.f = cmd_rx_offload_get_configuration_parsed,
18376 	.data = NULL,
18377 	.help_str = "show port <port_id> rx_offload configuration",
18378 	.tokens = {
18379 		(void *)&cmd_rx_offload_get_configuration_show,
18380 		(void *)&cmd_rx_offload_get_configuration_port,
18381 		(void *)&cmd_rx_offload_get_configuration_port_id,
18382 		(void *)&cmd_rx_offload_get_configuration_rx_offload,
18383 		(void *)&cmd_rx_offload_get_configuration_configuration,
18384 		NULL,
18385 	}
18386 };
18387 
18388 /* Enable/Disable a per port offloading */
18389 struct cmd_config_per_port_rx_offload_result {
18390 	cmdline_fixed_string_t port;
18391 	cmdline_fixed_string_t config;
18392 	portid_t port_id;
18393 	cmdline_fixed_string_t rx_offload;
18394 	cmdline_fixed_string_t offload;
18395 	cmdline_fixed_string_t on_off;
18396 };
18397 
18398 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18399 	TOKEN_STRING_INITIALIZER
18400 		(struct cmd_config_per_port_rx_offload_result,
18401 		 port, "port");
18402 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18403 	TOKEN_STRING_INITIALIZER
18404 		(struct cmd_config_per_port_rx_offload_result,
18405 		 config, "config");
18406 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18407 	TOKEN_NUM_INITIALIZER
18408 		(struct cmd_config_per_port_rx_offload_result,
18409 		 port_id, UINT16);
18410 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18411 	TOKEN_STRING_INITIALIZER
18412 		(struct cmd_config_per_port_rx_offload_result,
18413 		 rx_offload, "rx_offload");
18414 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18415 	TOKEN_STRING_INITIALIZER
18416 		(struct cmd_config_per_port_rx_offload_result,
18417 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18418 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18419 			   "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18420 			   "scatter#timestamp#security#keep_crc#rss_hash");
18421 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18422 	TOKEN_STRING_INITIALIZER
18423 		(struct cmd_config_per_port_rx_offload_result,
18424 		 on_off, "on#off");
18425 
18426 static uint64_t
18427 search_rx_offload(const char *name)
18428 {
18429 	uint64_t single_offload;
18430 	const char *single_name;
18431 	int found = 0;
18432 	unsigned int bit;
18433 
18434 	single_offload = 1;
18435 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18436 		single_name = rte_eth_dev_rx_offload_name(single_offload);
18437 		if (!strcasecmp(single_name, name)) {
18438 			found = 1;
18439 			break;
18440 		}
18441 		single_offload <<= 1;
18442 	}
18443 
18444 	if (found)
18445 		return single_offload;
18446 
18447 	return 0;
18448 }
18449 
18450 static void
18451 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18452 				__rte_unused struct cmdline *cl,
18453 				__rte_unused void *data)
18454 {
18455 	struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18456 	portid_t port_id = res->port_id;
18457 	struct rte_eth_dev_info dev_info;
18458 	struct rte_port *port = &ports[port_id];
18459 	uint64_t single_offload;
18460 	uint16_t nb_rx_queues;
18461 	int q;
18462 	int ret;
18463 
18464 	if (port->port_status != RTE_PORT_STOPPED) {
18465 		printf("Error: Can't config offload when Port %d "
18466 		       "is not stopped\n", port_id);
18467 		return;
18468 	}
18469 
18470 	single_offload = search_rx_offload(res->offload);
18471 	if (single_offload == 0) {
18472 		printf("Unknown offload name: %s\n", res->offload);
18473 		return;
18474 	}
18475 
18476 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18477 	if (ret != 0)
18478 		return;
18479 
18480 	nb_rx_queues = dev_info.nb_rx_queues;
18481 	if (!strcmp(res->on_off, "on")) {
18482 		port->dev_conf.rxmode.offloads |= single_offload;
18483 		for (q = 0; q < nb_rx_queues; q++)
18484 			port->rx_conf[q].offloads |= single_offload;
18485 	} else {
18486 		port->dev_conf.rxmode.offloads &= ~single_offload;
18487 		for (q = 0; q < nb_rx_queues; q++)
18488 			port->rx_conf[q].offloads &= ~single_offload;
18489 	}
18490 
18491 	cmd_reconfig_device_queue(port_id, 1, 1);
18492 }
18493 
18494 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18495 	.f = cmd_config_per_port_rx_offload_parsed,
18496 	.data = NULL,
18497 	.help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18498 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18499 		    "macsec_strip|header_split|vlan_filter|vlan_extend|"
18500 		    "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18501 		    "on|off",
18502 	.tokens = {
18503 		(void *)&cmd_config_per_port_rx_offload_result_port,
18504 		(void *)&cmd_config_per_port_rx_offload_result_config,
18505 		(void *)&cmd_config_per_port_rx_offload_result_port_id,
18506 		(void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18507 		(void *)&cmd_config_per_port_rx_offload_result_offload,
18508 		(void *)&cmd_config_per_port_rx_offload_result_on_off,
18509 		NULL,
18510 	}
18511 };
18512 
18513 /* Enable/Disable a per queue offloading */
18514 struct cmd_config_per_queue_rx_offload_result {
18515 	cmdline_fixed_string_t port;
18516 	portid_t port_id;
18517 	cmdline_fixed_string_t rxq;
18518 	uint16_t queue_id;
18519 	cmdline_fixed_string_t rx_offload;
18520 	cmdline_fixed_string_t offload;
18521 	cmdline_fixed_string_t on_off;
18522 };
18523 
18524 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18525 	TOKEN_STRING_INITIALIZER
18526 		(struct cmd_config_per_queue_rx_offload_result,
18527 		 port, "port");
18528 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18529 	TOKEN_NUM_INITIALIZER
18530 		(struct cmd_config_per_queue_rx_offload_result,
18531 		 port_id, UINT16);
18532 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18533 	TOKEN_STRING_INITIALIZER
18534 		(struct cmd_config_per_queue_rx_offload_result,
18535 		 rxq, "rxq");
18536 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18537 	TOKEN_NUM_INITIALIZER
18538 		(struct cmd_config_per_queue_rx_offload_result,
18539 		 queue_id, UINT16);
18540 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18541 	TOKEN_STRING_INITIALIZER
18542 		(struct cmd_config_per_queue_rx_offload_result,
18543 		 rx_offload, "rx_offload");
18544 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18545 	TOKEN_STRING_INITIALIZER
18546 		(struct cmd_config_per_queue_rx_offload_result,
18547 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18548 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18549 			   "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18550 			   "scatter#timestamp#security#keep_crc");
18551 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18552 	TOKEN_STRING_INITIALIZER
18553 		(struct cmd_config_per_queue_rx_offload_result,
18554 		 on_off, "on#off");
18555 
18556 static void
18557 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18558 				__rte_unused struct cmdline *cl,
18559 				__rte_unused void *data)
18560 {
18561 	struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18562 	struct rte_eth_dev_info dev_info;
18563 	portid_t port_id = res->port_id;
18564 	uint16_t queue_id = res->queue_id;
18565 	struct rte_port *port = &ports[port_id];
18566 	uint64_t single_offload;
18567 	int ret;
18568 
18569 	if (port->port_status != RTE_PORT_STOPPED) {
18570 		printf("Error: Can't config offload when Port %d "
18571 		       "is not stopped\n", port_id);
18572 		return;
18573 	}
18574 
18575 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18576 	if (ret != 0)
18577 		return;
18578 
18579 	if (queue_id >= dev_info.nb_rx_queues) {
18580 		printf("Error: input queue_id should be 0 ... "
18581 		       "%d\n", dev_info.nb_rx_queues - 1);
18582 		return;
18583 	}
18584 
18585 	single_offload = search_rx_offload(res->offload);
18586 	if (single_offload == 0) {
18587 		printf("Unknown offload name: %s\n", res->offload);
18588 		return;
18589 	}
18590 
18591 	if (!strcmp(res->on_off, "on"))
18592 		port->rx_conf[queue_id].offloads |= single_offload;
18593 	else
18594 		port->rx_conf[queue_id].offloads &= ~single_offload;
18595 
18596 	cmd_reconfig_device_queue(port_id, 1, 1);
18597 }
18598 
18599 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18600 	.f = cmd_config_per_queue_rx_offload_parsed,
18601 	.data = NULL,
18602 	.help_str = "port <port_id> rxq <queue_id> rx_offload "
18603 		    "vlan_strip|ipv4_cksum|"
18604 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18605 		    "macsec_strip|header_split|vlan_filter|vlan_extend|"
18606 		    "jumbo_frame|scatter|timestamp|security|keep_crc "
18607 		    "on|off",
18608 	.tokens = {
18609 		(void *)&cmd_config_per_queue_rx_offload_result_port,
18610 		(void *)&cmd_config_per_queue_rx_offload_result_port_id,
18611 		(void *)&cmd_config_per_queue_rx_offload_result_rxq,
18612 		(void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18613 		(void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18614 		(void *)&cmd_config_per_queue_rx_offload_result_offload,
18615 		(void *)&cmd_config_per_queue_rx_offload_result_on_off,
18616 		NULL,
18617 	}
18618 };
18619 
18620 /* Get Tx offloads capabilities */
18621 struct cmd_tx_offload_get_capa_result {
18622 	cmdline_fixed_string_t show;
18623 	cmdline_fixed_string_t port;
18624 	portid_t port_id;
18625 	cmdline_fixed_string_t tx_offload;
18626 	cmdline_fixed_string_t capabilities;
18627 };
18628 
18629 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18630 	TOKEN_STRING_INITIALIZER
18631 		(struct cmd_tx_offload_get_capa_result,
18632 		 show, "show");
18633 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18634 	TOKEN_STRING_INITIALIZER
18635 		(struct cmd_tx_offload_get_capa_result,
18636 		 port, "port");
18637 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18638 	TOKEN_NUM_INITIALIZER
18639 		(struct cmd_tx_offload_get_capa_result,
18640 		 port_id, UINT16);
18641 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18642 	TOKEN_STRING_INITIALIZER
18643 		(struct cmd_tx_offload_get_capa_result,
18644 		 tx_offload, "tx_offload");
18645 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18646 	TOKEN_STRING_INITIALIZER
18647 		(struct cmd_tx_offload_get_capa_result,
18648 		 capabilities, "capabilities");
18649 
18650 static void
18651 print_tx_offloads(uint64_t offloads)
18652 {
18653 	uint64_t single_offload;
18654 	int begin;
18655 	int end;
18656 	int bit;
18657 
18658 	if (offloads == 0)
18659 		return;
18660 
18661 	begin = __builtin_ctzll(offloads);
18662 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18663 
18664 	single_offload = 1ULL << begin;
18665 	for (bit = begin; bit < end; bit++) {
18666 		if (offloads & single_offload)
18667 			printf(" %s",
18668 			       rte_eth_dev_tx_offload_name(single_offload));
18669 		single_offload <<= 1;
18670 	}
18671 }
18672 
18673 static void
18674 cmd_tx_offload_get_capa_parsed(
18675 	void *parsed_result,
18676 	__rte_unused struct cmdline *cl,
18677 	__rte_unused void *data)
18678 {
18679 	struct cmd_tx_offload_get_capa_result *res = parsed_result;
18680 	struct rte_eth_dev_info dev_info;
18681 	portid_t port_id = res->port_id;
18682 	uint64_t queue_offloads;
18683 	uint64_t port_offloads;
18684 	int ret;
18685 
18686 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18687 	if (ret != 0)
18688 		return;
18689 
18690 	queue_offloads = dev_info.tx_queue_offload_capa;
18691 	port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18692 
18693 	printf("Tx Offloading Capabilities of port %d :\n", port_id);
18694 	printf("  Per Queue :");
18695 	print_tx_offloads(queue_offloads);
18696 
18697 	printf("\n");
18698 	printf("  Per Port  :");
18699 	print_tx_offloads(port_offloads);
18700 	printf("\n\n");
18701 }
18702 
18703 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18704 	.f = cmd_tx_offload_get_capa_parsed,
18705 	.data = NULL,
18706 	.help_str = "show port <port_id> tx_offload capabilities",
18707 	.tokens = {
18708 		(void *)&cmd_tx_offload_get_capa_show,
18709 		(void *)&cmd_tx_offload_get_capa_port,
18710 		(void *)&cmd_tx_offload_get_capa_port_id,
18711 		(void *)&cmd_tx_offload_get_capa_tx_offload,
18712 		(void *)&cmd_tx_offload_get_capa_capabilities,
18713 		NULL,
18714 	}
18715 };
18716 
18717 /* Get Tx offloads configuration */
18718 struct cmd_tx_offload_get_configuration_result {
18719 	cmdline_fixed_string_t show;
18720 	cmdline_fixed_string_t port;
18721 	portid_t port_id;
18722 	cmdline_fixed_string_t tx_offload;
18723 	cmdline_fixed_string_t configuration;
18724 };
18725 
18726 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18727 	TOKEN_STRING_INITIALIZER
18728 		(struct cmd_tx_offload_get_configuration_result,
18729 		 show, "show");
18730 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18731 	TOKEN_STRING_INITIALIZER
18732 		(struct cmd_tx_offload_get_configuration_result,
18733 		 port, "port");
18734 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18735 	TOKEN_NUM_INITIALIZER
18736 		(struct cmd_tx_offload_get_configuration_result,
18737 		 port_id, UINT16);
18738 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18739 	TOKEN_STRING_INITIALIZER
18740 		(struct cmd_tx_offload_get_configuration_result,
18741 		 tx_offload, "tx_offload");
18742 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18743 	TOKEN_STRING_INITIALIZER
18744 		(struct cmd_tx_offload_get_configuration_result,
18745 		 configuration, "configuration");
18746 
18747 static void
18748 cmd_tx_offload_get_configuration_parsed(
18749 	void *parsed_result,
18750 	__rte_unused struct cmdline *cl,
18751 	__rte_unused void *data)
18752 {
18753 	struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18754 	struct rte_eth_dev_info dev_info;
18755 	portid_t port_id = res->port_id;
18756 	struct rte_port *port = &ports[port_id];
18757 	uint64_t port_offloads;
18758 	uint64_t queue_offloads;
18759 	uint16_t nb_tx_queues;
18760 	int q;
18761 	int ret;
18762 
18763 	printf("Tx Offloading Configuration of port %d :\n", port_id);
18764 
18765 	port_offloads = port->dev_conf.txmode.offloads;
18766 	printf("  Port :");
18767 	print_tx_offloads(port_offloads);
18768 	printf("\n");
18769 
18770 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18771 	if (ret != 0)
18772 		return;
18773 
18774 	nb_tx_queues = dev_info.nb_tx_queues;
18775 	for (q = 0; q < nb_tx_queues; q++) {
18776 		queue_offloads = port->tx_conf[q].offloads;
18777 		printf("  Queue[%2d] :", q);
18778 		print_tx_offloads(queue_offloads);
18779 		printf("\n");
18780 	}
18781 	printf("\n");
18782 }
18783 
18784 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18785 	.f = cmd_tx_offload_get_configuration_parsed,
18786 	.data = NULL,
18787 	.help_str = "show port <port_id> tx_offload configuration",
18788 	.tokens = {
18789 		(void *)&cmd_tx_offload_get_configuration_show,
18790 		(void *)&cmd_tx_offload_get_configuration_port,
18791 		(void *)&cmd_tx_offload_get_configuration_port_id,
18792 		(void *)&cmd_tx_offload_get_configuration_tx_offload,
18793 		(void *)&cmd_tx_offload_get_configuration_configuration,
18794 		NULL,
18795 	}
18796 };
18797 
18798 /* Enable/Disable a per port offloading */
18799 struct cmd_config_per_port_tx_offload_result {
18800 	cmdline_fixed_string_t port;
18801 	cmdline_fixed_string_t config;
18802 	portid_t port_id;
18803 	cmdline_fixed_string_t tx_offload;
18804 	cmdline_fixed_string_t offload;
18805 	cmdline_fixed_string_t on_off;
18806 };
18807 
18808 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18809 	TOKEN_STRING_INITIALIZER
18810 		(struct cmd_config_per_port_tx_offload_result,
18811 		 port, "port");
18812 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18813 	TOKEN_STRING_INITIALIZER
18814 		(struct cmd_config_per_port_tx_offload_result,
18815 		 config, "config");
18816 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18817 	TOKEN_NUM_INITIALIZER
18818 		(struct cmd_config_per_port_tx_offload_result,
18819 		 port_id, UINT16);
18820 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18821 	TOKEN_STRING_INITIALIZER
18822 		(struct cmd_config_per_port_tx_offload_result,
18823 		 tx_offload, "tx_offload");
18824 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18825 	TOKEN_STRING_INITIALIZER
18826 		(struct cmd_config_per_port_tx_offload_result,
18827 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18828 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18829 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18830 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18831 			  "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18832 			  "send_on_timestamp");
18833 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18834 	TOKEN_STRING_INITIALIZER
18835 		(struct cmd_config_per_port_tx_offload_result,
18836 		 on_off, "on#off");
18837 
18838 static uint64_t
18839 search_tx_offload(const char *name)
18840 {
18841 	uint64_t single_offload;
18842 	const char *single_name;
18843 	int found = 0;
18844 	unsigned int bit;
18845 
18846 	single_offload = 1;
18847 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18848 		single_name = rte_eth_dev_tx_offload_name(single_offload);
18849 		if (single_name == NULL)
18850 			break;
18851 		if (!strcasecmp(single_name, name)) {
18852 			found = 1;
18853 			break;
18854 		} else if (!strcasecmp(single_name, "UNKNOWN"))
18855 			break;
18856 		single_offload <<= 1;
18857 	}
18858 
18859 	if (found)
18860 		return single_offload;
18861 
18862 	return 0;
18863 }
18864 
18865 static void
18866 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18867 				__rte_unused struct cmdline *cl,
18868 				__rte_unused void *data)
18869 {
18870 	struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18871 	portid_t port_id = res->port_id;
18872 	struct rte_eth_dev_info dev_info;
18873 	struct rte_port *port = &ports[port_id];
18874 	uint64_t single_offload;
18875 	uint16_t nb_tx_queues;
18876 	int q;
18877 	int ret;
18878 
18879 	if (port->port_status != RTE_PORT_STOPPED) {
18880 		printf("Error: Can't config offload when Port %d "
18881 		       "is not stopped\n", port_id);
18882 		return;
18883 	}
18884 
18885 	single_offload = search_tx_offload(res->offload);
18886 	if (single_offload == 0) {
18887 		printf("Unknown offload name: %s\n", res->offload);
18888 		return;
18889 	}
18890 
18891 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18892 	if (ret != 0)
18893 		return;
18894 
18895 	nb_tx_queues = dev_info.nb_tx_queues;
18896 	if (!strcmp(res->on_off, "on")) {
18897 		port->dev_conf.txmode.offloads |= single_offload;
18898 		for (q = 0; q < nb_tx_queues; q++)
18899 			port->tx_conf[q].offloads |= single_offload;
18900 	} else {
18901 		port->dev_conf.txmode.offloads &= ~single_offload;
18902 		for (q = 0; q < nb_tx_queues; q++)
18903 			port->tx_conf[q].offloads &= ~single_offload;
18904 	}
18905 
18906 	cmd_reconfig_device_queue(port_id, 1, 1);
18907 }
18908 
18909 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18910 	.f = cmd_config_per_port_tx_offload_parsed,
18911 	.data = NULL,
18912 	.help_str = "port config <port_id> tx_offload "
18913 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18914 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18915 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18916 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18917 		    "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18918 		    "send_on_timestamp on|off",
18919 	.tokens = {
18920 		(void *)&cmd_config_per_port_tx_offload_result_port,
18921 		(void *)&cmd_config_per_port_tx_offload_result_config,
18922 		(void *)&cmd_config_per_port_tx_offload_result_port_id,
18923 		(void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18924 		(void *)&cmd_config_per_port_tx_offload_result_offload,
18925 		(void *)&cmd_config_per_port_tx_offload_result_on_off,
18926 		NULL,
18927 	}
18928 };
18929 
18930 /* Enable/Disable a per queue offloading */
18931 struct cmd_config_per_queue_tx_offload_result {
18932 	cmdline_fixed_string_t port;
18933 	portid_t port_id;
18934 	cmdline_fixed_string_t txq;
18935 	uint16_t queue_id;
18936 	cmdline_fixed_string_t tx_offload;
18937 	cmdline_fixed_string_t offload;
18938 	cmdline_fixed_string_t on_off;
18939 };
18940 
18941 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18942 	TOKEN_STRING_INITIALIZER
18943 		(struct cmd_config_per_queue_tx_offload_result,
18944 		 port, "port");
18945 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18946 	TOKEN_NUM_INITIALIZER
18947 		(struct cmd_config_per_queue_tx_offload_result,
18948 		 port_id, UINT16);
18949 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18950 	TOKEN_STRING_INITIALIZER
18951 		(struct cmd_config_per_queue_tx_offload_result,
18952 		 txq, "txq");
18953 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18954 	TOKEN_NUM_INITIALIZER
18955 		(struct cmd_config_per_queue_tx_offload_result,
18956 		 queue_id, UINT16);
18957 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18958 	TOKEN_STRING_INITIALIZER
18959 		(struct cmd_config_per_queue_tx_offload_result,
18960 		 tx_offload, "tx_offload");
18961 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18962 	TOKEN_STRING_INITIALIZER
18963 		(struct cmd_config_per_queue_tx_offload_result,
18964 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18965 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18966 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18967 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18968 			  "mt_lockfree#multi_segs#mbuf_fast_free#security");
18969 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18970 	TOKEN_STRING_INITIALIZER
18971 		(struct cmd_config_per_queue_tx_offload_result,
18972 		 on_off, "on#off");
18973 
18974 static void
18975 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18976 				__rte_unused struct cmdline *cl,
18977 				__rte_unused void *data)
18978 {
18979 	struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18980 	struct rte_eth_dev_info dev_info;
18981 	portid_t port_id = res->port_id;
18982 	uint16_t queue_id = res->queue_id;
18983 	struct rte_port *port = &ports[port_id];
18984 	uint64_t single_offload;
18985 	int ret;
18986 
18987 	if (port->port_status != RTE_PORT_STOPPED) {
18988 		printf("Error: Can't config offload when Port %d "
18989 		       "is not stopped\n", port_id);
18990 		return;
18991 	}
18992 
18993 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18994 	if (ret != 0)
18995 		return;
18996 
18997 	if (queue_id >= dev_info.nb_tx_queues) {
18998 		printf("Error: input queue_id should be 0 ... "
18999 		       "%d\n", dev_info.nb_tx_queues - 1);
19000 		return;
19001 	}
19002 
19003 	single_offload = search_tx_offload(res->offload);
19004 	if (single_offload == 0) {
19005 		printf("Unknown offload name: %s\n", res->offload);
19006 		return;
19007 	}
19008 
19009 	if (!strcmp(res->on_off, "on"))
19010 		port->tx_conf[queue_id].offloads |= single_offload;
19011 	else
19012 		port->tx_conf[queue_id].offloads &= ~single_offload;
19013 
19014 	cmd_reconfig_device_queue(port_id, 1, 1);
19015 }
19016 
19017 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
19018 	.f = cmd_config_per_queue_tx_offload_parsed,
19019 	.data = NULL,
19020 	.help_str = "port <port_id> txq <queue_id> tx_offload "
19021 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
19022 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
19023 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
19024 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
19025 		    "mt_lockfree|multi_segs|mbuf_fast_free|security "
19026 		    "on|off",
19027 	.tokens = {
19028 		(void *)&cmd_config_per_queue_tx_offload_result_port,
19029 		(void *)&cmd_config_per_queue_tx_offload_result_port_id,
19030 		(void *)&cmd_config_per_queue_tx_offload_result_txq,
19031 		(void *)&cmd_config_per_queue_tx_offload_result_queue_id,
19032 		(void *)&cmd_config_per_queue_tx_offload_result_txoffload,
19033 		(void *)&cmd_config_per_queue_tx_offload_result_offload,
19034 		(void *)&cmd_config_per_queue_tx_offload_result_on_off,
19035 		NULL,
19036 	}
19037 };
19038 
19039 /* *** configure tx_metadata for specific port *** */
19040 struct cmd_config_tx_metadata_specific_result {
19041 	cmdline_fixed_string_t port;
19042 	cmdline_fixed_string_t keyword;
19043 	uint16_t port_id;
19044 	cmdline_fixed_string_t item;
19045 	uint32_t value;
19046 };
19047 
19048 static void
19049 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
19050 				__rte_unused struct cmdline *cl,
19051 				__rte_unused void *data)
19052 {
19053 	struct cmd_config_tx_metadata_specific_result *res = parsed_result;
19054 
19055 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19056 		return;
19057 	ports[res->port_id].tx_metadata = res->value;
19058 	/* Add/remove callback to insert valid metadata in every Tx packet. */
19059 	if (ports[res->port_id].tx_metadata)
19060 		add_tx_md_callback(res->port_id);
19061 	else
19062 		remove_tx_md_callback(res->port_id);
19063 	rte_flow_dynf_metadata_register();
19064 }
19065 
19066 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
19067 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19068 			port, "port");
19069 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
19070 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19071 			keyword, "config");
19072 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
19073 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19074 			port_id, UINT16);
19075 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
19076 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19077 			item, "tx_metadata");
19078 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
19079 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19080 			value, UINT32);
19081 
19082 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
19083 	.f = cmd_config_tx_metadata_specific_parsed,
19084 	.data = NULL,
19085 	.help_str = "port config <port_id> tx_metadata <value>",
19086 	.tokens = {
19087 		(void *)&cmd_config_tx_metadata_specific_port,
19088 		(void *)&cmd_config_tx_metadata_specific_keyword,
19089 		(void *)&cmd_config_tx_metadata_specific_id,
19090 		(void *)&cmd_config_tx_metadata_specific_item,
19091 		(void *)&cmd_config_tx_metadata_specific_value,
19092 		NULL,
19093 	},
19094 };
19095 
19096 /* *** set dynf *** */
19097 struct cmd_config_tx_dynf_specific_result {
19098 	cmdline_fixed_string_t port;
19099 	cmdline_fixed_string_t keyword;
19100 	uint16_t port_id;
19101 	cmdline_fixed_string_t item;
19102 	cmdline_fixed_string_t name;
19103 	cmdline_fixed_string_t value;
19104 };
19105 
19106 static void
19107 cmd_config_dynf_specific_parsed(void *parsed_result,
19108 				__rte_unused struct cmdline *cl,
19109 				__rte_unused void *data)
19110 {
19111 	struct cmd_config_tx_dynf_specific_result *res = parsed_result;
19112 	struct rte_mbuf_dynflag desc_flag;
19113 	int flag;
19114 	uint64_t old_port_flags;
19115 
19116 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19117 		return;
19118 	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
19119 	if (flag <= 0) {
19120 		if (strlcpy(desc_flag.name, res->name,
19121 			    RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
19122 			printf("Flag name too long\n");
19123 			return;
19124 		}
19125 		desc_flag.flags = 0;
19126 		flag = rte_mbuf_dynflag_register(&desc_flag);
19127 		if (flag < 0) {
19128 			printf("Can't register flag\n");
19129 			return;
19130 		}
19131 		strcpy(dynf_names[flag], desc_flag.name);
19132 	}
19133 	old_port_flags = ports[res->port_id].mbuf_dynf;
19134 	if (!strcmp(res->value, "set")) {
19135 		ports[res->port_id].mbuf_dynf |= 1UL << flag;
19136 		if (old_port_flags == 0)
19137 			add_tx_dynf_callback(res->port_id);
19138 	} else {
19139 		ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
19140 		if (ports[res->port_id].mbuf_dynf == 0)
19141 			remove_tx_dynf_callback(res->port_id);
19142 	}
19143 }
19144 
19145 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
19146 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19147 			keyword, "port");
19148 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
19149 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19150 			keyword, "config");
19151 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
19152 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19153 			port_id, UINT16);
19154 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
19155 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19156 			item, "dynf");
19157 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
19158 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19159 			name, NULL);
19160 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
19161 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19162 			value, "set#clear");
19163 
19164 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
19165 	.f = cmd_config_dynf_specific_parsed,
19166 	.data = NULL,
19167 	.help_str = "port config <port id> dynf <name> set|clear",
19168 	.tokens = {
19169 		(void *)&cmd_config_tx_dynf_specific_port,
19170 		(void *)&cmd_config_tx_dynf_specific_keyword,
19171 		(void *)&cmd_config_tx_dynf_specific_port_id,
19172 		(void *)&cmd_config_tx_dynf_specific_item,
19173 		(void *)&cmd_config_tx_dynf_specific_name,
19174 		(void *)&cmd_config_tx_dynf_specific_value,
19175 		NULL,
19176 	},
19177 };
19178 
19179 /* *** display tx_metadata per port configuration *** */
19180 struct cmd_show_tx_metadata_result {
19181 	cmdline_fixed_string_t cmd_show;
19182 	cmdline_fixed_string_t cmd_port;
19183 	cmdline_fixed_string_t cmd_keyword;
19184 	portid_t cmd_pid;
19185 };
19186 
19187 static void
19188 cmd_show_tx_metadata_parsed(void *parsed_result,
19189 		__rte_unused struct cmdline *cl,
19190 		__rte_unused void *data)
19191 {
19192 	struct cmd_show_tx_metadata_result *res = parsed_result;
19193 
19194 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19195 		printf("invalid port id %u\n", res->cmd_pid);
19196 		return;
19197 	}
19198 	if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19199 		printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19200 		       ports[res->cmd_pid].tx_metadata);
19201 	}
19202 }
19203 
19204 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19205 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19206 			cmd_show, "show");
19207 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19208 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19209 			cmd_port, "port");
19210 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19211 	TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19212 			cmd_pid, UINT16);
19213 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19214 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19215 			cmd_keyword, "tx_metadata");
19216 
19217 cmdline_parse_inst_t cmd_show_tx_metadata = {
19218 	.f = cmd_show_tx_metadata_parsed,
19219 	.data = NULL,
19220 	.help_str = "show port <port_id> tx_metadata",
19221 	.tokens = {
19222 		(void *)&cmd_show_tx_metadata_show,
19223 		(void *)&cmd_show_tx_metadata_port,
19224 		(void *)&cmd_show_tx_metadata_pid,
19225 		(void *)&cmd_show_tx_metadata_keyword,
19226 		NULL,
19227 	},
19228 };
19229 
19230 /* *** show fec capability per port configuration *** */
19231 struct cmd_show_fec_capability_result {
19232 	cmdline_fixed_string_t cmd_show;
19233 	cmdline_fixed_string_t cmd_port;
19234 	cmdline_fixed_string_t cmd_fec;
19235 	cmdline_fixed_string_t cmd_keyword;
19236 	portid_t cmd_pid;
19237 };
19238 
19239 static void
19240 cmd_show_fec_capability_parsed(void *parsed_result,
19241 		__rte_unused struct cmdline *cl,
19242 		__rte_unused void *data)
19243 {
19244 #define FEC_CAP_NUM 2
19245 	struct cmd_show_fec_capability_result *res = parsed_result;
19246 	struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
19247 	unsigned int num = FEC_CAP_NUM;
19248 	unsigned int ret_num;
19249 	int ret;
19250 
19251 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19252 		printf("Invalid port id %u\n", res->cmd_pid);
19253 		return;
19254 	}
19255 
19256 	ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
19257 	if (ret == -ENOTSUP) {
19258 		printf("Function not implemented\n");
19259 		return;
19260 	} else if (ret < 0) {
19261 		printf("Get FEC capability failed\n");
19262 		return;
19263 	}
19264 
19265 	ret_num = (unsigned int)ret;
19266 	show_fec_capability(ret_num, speed_fec_capa);
19267 }
19268 
19269 cmdline_parse_token_string_t cmd_show_fec_capability_show =
19270 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19271 			cmd_show, "show");
19272 cmdline_parse_token_string_t cmd_show_fec_capability_port =
19273 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19274 			cmd_port, "port");
19275 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
19276 	TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
19277 			cmd_pid, UINT16);
19278 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
19279 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19280 			cmd_fec, "fec");
19281 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
19282 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19283 			cmd_keyword, "capabilities");
19284 
19285 cmdline_parse_inst_t cmd_show_capability = {
19286 	.f = cmd_show_fec_capability_parsed,
19287 	.data = NULL,
19288 	.help_str = "show port <port_id> fec capabilities",
19289 	.tokens = {
19290 		(void *)&cmd_show_fec_capability_show,
19291 		(void *)&cmd_show_fec_capability_port,
19292 		(void *)&cmd_show_fec_capability_pid,
19293 		(void *)&cmd_show_fec_capability_fec,
19294 		(void *)&cmd_show_fec_capability_keyword,
19295 		NULL,
19296 	},
19297 };
19298 
19299 /* *** show fec mode per port configuration *** */
19300 struct cmd_show_fec_metadata_result {
19301 	cmdline_fixed_string_t cmd_show;
19302 	cmdline_fixed_string_t cmd_port;
19303 	cmdline_fixed_string_t cmd_keyword;
19304 	portid_t cmd_pid;
19305 };
19306 
19307 static void
19308 cmd_show_fec_mode_parsed(void *parsed_result,
19309 		__rte_unused struct cmdline *cl,
19310 		__rte_unused void *data)
19311 {
19312 #define FEC_NAME_SIZE 16
19313 	struct cmd_show_fec_metadata_result *res = parsed_result;
19314 	uint32_t mode;
19315 	char buf[FEC_NAME_SIZE];
19316 	int ret;
19317 
19318 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19319 		printf("Invalid port id %u\n", res->cmd_pid);
19320 		return;
19321 	}
19322 	ret = rte_eth_fec_get(res->cmd_pid, &mode);
19323 	if (ret == -ENOTSUP) {
19324 		printf("Function not implemented\n");
19325 		return;
19326 	} else if (ret < 0) {
19327 		printf("Get FEC mode failed\n");
19328 		return;
19329 	}
19330 
19331 	switch (mode) {
19332 	case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
19333 		strlcpy(buf, "off", sizeof(buf));
19334 		break;
19335 	case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
19336 		strlcpy(buf, "auto", sizeof(buf));
19337 		break;
19338 	case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
19339 		strlcpy(buf, "baser", sizeof(buf));
19340 		break;
19341 	case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
19342 		strlcpy(buf, "rs", sizeof(buf));
19343 		break;
19344 	default:
19345 		return;
19346 	}
19347 
19348 	printf("%s\n", buf);
19349 }
19350 
19351 cmdline_parse_token_string_t cmd_show_fec_mode_show =
19352 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19353 			cmd_show, "show");
19354 cmdline_parse_token_string_t cmd_show_fec_mode_port =
19355 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19356 			cmd_port, "port");
19357 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
19358 	TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
19359 			cmd_pid, UINT16);
19360 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
19361 	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19362 			cmd_keyword, "fec_mode");
19363 
19364 cmdline_parse_inst_t cmd_show_fec_mode = {
19365 	.f = cmd_show_fec_mode_parsed,
19366 	.data = NULL,
19367 	.help_str = "show port <port_id> fec_mode",
19368 	.tokens = {
19369 		(void *)&cmd_show_fec_mode_show,
19370 		(void *)&cmd_show_fec_mode_port,
19371 		(void *)&cmd_show_fec_mode_pid,
19372 		(void *)&cmd_show_fec_mode_keyword,
19373 		NULL,
19374 	},
19375 };
19376 
19377 /* *** set fec mode per port configuration *** */
19378 struct cmd_set_port_fec_mode {
19379 	cmdline_fixed_string_t set;
19380 	cmdline_fixed_string_t port;
19381 	portid_t port_id;
19382 	cmdline_fixed_string_t fec_mode;
19383 	cmdline_fixed_string_t fec_value;
19384 };
19385 
19386 /* Common CLI fields for set fec mode */
19387 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
19388 	TOKEN_STRING_INITIALIZER
19389 		(struct cmd_set_port_fec_mode,
19390 		 set, "set");
19391 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
19392 	TOKEN_STRING_INITIALIZER
19393 		(struct cmd_set_port_fec_mode,
19394 		 port, "port");
19395 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
19396 	TOKEN_NUM_INITIALIZER
19397 		(struct cmd_set_port_fec_mode,
19398 		 port_id, UINT16);
19399 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
19400 	TOKEN_STRING_INITIALIZER
19401 		(struct cmd_set_port_fec_mode,
19402 		 fec_mode, "fec_mode");
19403 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
19404 	TOKEN_STRING_INITIALIZER
19405 		(struct cmd_set_port_fec_mode,
19406 		 fec_value, NULL);
19407 
19408 static void
19409 cmd_set_port_fec_mode_parsed(
19410 	void *parsed_result,
19411 	__rte_unused struct cmdline *cl,
19412 	__rte_unused void *data)
19413 {
19414 	struct cmd_set_port_fec_mode *res = parsed_result;
19415 	uint16_t port_id = res->port_id;
19416 	uint32_t mode;
19417 	int ret;
19418 
19419 	ret = parse_fec_mode(res->fec_value, &mode);
19420 	if (ret < 0) {
19421 		printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
19422 			port_id);
19423 		return;
19424 	}
19425 
19426 	ret = rte_eth_fec_set(port_id, mode);
19427 	if (ret == -ENOTSUP) {
19428 		printf("Function not implemented\n");
19429 		return;
19430 	} else if (ret < 0) {
19431 		printf("Set FEC mode failed\n");
19432 		return;
19433 	}
19434 }
19435 
19436 cmdline_parse_inst_t cmd_set_fec_mode = {
19437 	.f = cmd_set_port_fec_mode_parsed,
19438 	.data = NULL,
19439 	.help_str = "set port <port_id> fec_mode auto|off|rs|baser",
19440 	.tokens = {
19441 		(void *)&cmd_set_port_fec_mode_set,
19442 		(void *)&cmd_set_port_fec_mode_port,
19443 		(void *)&cmd_set_port_fec_mode_port_id,
19444 		(void *)&cmd_set_port_fec_mode_str,
19445 		(void *)&cmd_set_port_fec_mode_value,
19446 		NULL,
19447 	},
19448 };
19449 
19450 /* show port supported ptypes */
19451 
19452 /* Common result structure for show port ptypes */
19453 struct cmd_show_port_supported_ptypes_result {
19454 	cmdline_fixed_string_t show;
19455 	cmdline_fixed_string_t port;
19456 	portid_t port_id;
19457 	cmdline_fixed_string_t ptypes;
19458 };
19459 
19460 /* Common CLI fields for show port ptypes */
19461 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19462 	TOKEN_STRING_INITIALIZER
19463 		(struct cmd_show_port_supported_ptypes_result,
19464 		 show, "show");
19465 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19466 	TOKEN_STRING_INITIALIZER
19467 		(struct cmd_show_port_supported_ptypes_result,
19468 		 port, "port");
19469 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19470 	TOKEN_NUM_INITIALIZER
19471 		(struct cmd_show_port_supported_ptypes_result,
19472 		 port_id, UINT16);
19473 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19474 	TOKEN_STRING_INITIALIZER
19475 		(struct cmd_show_port_supported_ptypes_result,
19476 		 ptypes, "ptypes");
19477 
19478 static void
19479 cmd_show_port_supported_ptypes_parsed(
19480 	void *parsed_result,
19481 	__rte_unused struct cmdline *cl,
19482 	__rte_unused void *data)
19483 {
19484 #define RSVD_PTYPE_MASK       0xf0000000
19485 #define MAX_PTYPES_PER_LAYER  16
19486 #define LTYPE_NAMESIZE        32
19487 #define PTYPE_NAMESIZE        256
19488 	struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19489 	char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19490 	uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19491 	uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19492 	uint16_t port_id = res->port_id;
19493 	int ret, i;
19494 
19495 	ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19496 	if (ret < 0)
19497 		return;
19498 
19499 	while (ptype_mask != RSVD_PTYPE_MASK) {
19500 
19501 		switch (ptype_mask) {
19502 		case RTE_PTYPE_L2_MASK:
19503 			strlcpy(ltype, "L2", sizeof(ltype));
19504 			break;
19505 		case RTE_PTYPE_L3_MASK:
19506 			strlcpy(ltype, "L3", sizeof(ltype));
19507 			break;
19508 		case RTE_PTYPE_L4_MASK:
19509 			strlcpy(ltype, "L4", sizeof(ltype));
19510 			break;
19511 		case RTE_PTYPE_TUNNEL_MASK:
19512 			strlcpy(ltype, "Tunnel", sizeof(ltype));
19513 			break;
19514 		case RTE_PTYPE_INNER_L2_MASK:
19515 			strlcpy(ltype, "Inner L2", sizeof(ltype));
19516 			break;
19517 		case RTE_PTYPE_INNER_L3_MASK:
19518 			strlcpy(ltype, "Inner L3", sizeof(ltype));
19519 			break;
19520 		case RTE_PTYPE_INNER_L4_MASK:
19521 			strlcpy(ltype, "Inner L4", sizeof(ltype));
19522 			break;
19523 		default:
19524 			return;
19525 		}
19526 
19527 		ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19528 						       ptype_mask, ptypes,
19529 						       MAX_PTYPES_PER_LAYER);
19530 
19531 		if (ret > 0)
19532 			printf("Supported %s ptypes:\n", ltype);
19533 		else
19534 			printf("%s ptypes unsupported\n", ltype);
19535 
19536 		for (i = 0; i < ret; ++i) {
19537 			rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19538 			printf("%s\n", buf);
19539 		}
19540 
19541 		ptype_mask <<= 4;
19542 	}
19543 }
19544 
19545 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19546 	.f = cmd_show_port_supported_ptypes_parsed,
19547 	.data = NULL,
19548 	.help_str = "show port <port_id> ptypes",
19549 	.tokens = {
19550 		(void *)&cmd_show_port_supported_ptypes_show,
19551 		(void *)&cmd_show_port_supported_ptypes_port,
19552 		(void *)&cmd_show_port_supported_ptypes_port_id,
19553 		(void *)&cmd_show_port_supported_ptypes_ptypes,
19554 		NULL,
19555 	},
19556 };
19557 
19558 /* *** display rx/tx descriptor status *** */
19559 struct cmd_show_rx_tx_desc_status_result {
19560 	cmdline_fixed_string_t cmd_show;
19561 	cmdline_fixed_string_t cmd_port;
19562 	cmdline_fixed_string_t cmd_keyword;
19563 	cmdline_fixed_string_t cmd_desc;
19564 	cmdline_fixed_string_t cmd_status;
19565 	portid_t cmd_pid;
19566 	portid_t cmd_qid;
19567 	portid_t cmd_did;
19568 };
19569 
19570 static void
19571 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19572 		__rte_unused struct cmdline *cl,
19573 		__rte_unused void *data)
19574 {
19575 	struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19576 	int rc;
19577 
19578 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19579 		printf("invalid port id %u\n", res->cmd_pid);
19580 		return;
19581 	}
19582 
19583 	if (!strcmp(res->cmd_keyword, "rxq")) {
19584 		rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19585 					     res->cmd_did);
19586 		if (rc < 0) {
19587 			printf("Invalid queueid = %d\n", res->cmd_qid);
19588 			return;
19589 		}
19590 		if (rc == RTE_ETH_RX_DESC_AVAIL)
19591 			printf("Desc status = AVAILABLE\n");
19592 		else if (rc == RTE_ETH_RX_DESC_DONE)
19593 			printf("Desc status = DONE\n");
19594 		else
19595 			printf("Desc status = UNAVAILABLE\n");
19596 	} else if (!strcmp(res->cmd_keyword, "txq")) {
19597 		rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19598 					     res->cmd_did);
19599 		if (rc < 0) {
19600 			printf("Invalid queueid = %d\n", res->cmd_qid);
19601 			return;
19602 		}
19603 		if (rc == RTE_ETH_TX_DESC_FULL)
19604 			printf("Desc status = FULL\n");
19605 		else if (rc == RTE_ETH_TX_DESC_DONE)
19606 			printf("Desc status = DONE\n");
19607 		else
19608 			printf("Desc status = UNAVAILABLE\n");
19609 	}
19610 }
19611 
19612 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19613 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19614 			cmd_show, "show");
19615 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19616 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19617 			cmd_port, "port");
19618 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19619 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19620 			cmd_pid, UINT16);
19621 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19622 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19623 			cmd_keyword, "rxq#txq");
19624 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19625 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19626 			cmd_qid, UINT16);
19627 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19628 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19629 			cmd_desc, "desc");
19630 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19631 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19632 			cmd_did, UINT16);
19633 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19634 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19635 			cmd_status, "status");
19636 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19637 	.f = cmd_show_rx_tx_desc_status_parsed,
19638 	.data = NULL,
19639 	.help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19640 		"status",
19641 	.tokens = {
19642 		(void *)&cmd_show_rx_tx_desc_status_show,
19643 		(void *)&cmd_show_rx_tx_desc_status_port,
19644 		(void *)&cmd_show_rx_tx_desc_status_pid,
19645 		(void *)&cmd_show_rx_tx_desc_status_keyword,
19646 		(void *)&cmd_show_rx_tx_desc_status_qid,
19647 		(void *)&cmd_show_rx_tx_desc_status_desc,
19648 		(void *)&cmd_show_rx_tx_desc_status_did,
19649 		(void *)&cmd_show_rx_tx_desc_status_status,
19650 		NULL,
19651 	},
19652 };
19653 
19654 /* Common result structure for set port ptypes */
19655 struct cmd_set_port_ptypes_result {
19656 	cmdline_fixed_string_t set;
19657 	cmdline_fixed_string_t port;
19658 	portid_t port_id;
19659 	cmdline_fixed_string_t ptype_mask;
19660 	uint32_t mask;
19661 };
19662 
19663 /* Common CLI fields for set port ptypes */
19664 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19665 	TOKEN_STRING_INITIALIZER
19666 		(struct cmd_set_port_ptypes_result,
19667 		 set, "set");
19668 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19669 	TOKEN_STRING_INITIALIZER
19670 		(struct cmd_set_port_ptypes_result,
19671 		 port, "port");
19672 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19673 	TOKEN_NUM_INITIALIZER
19674 		(struct cmd_set_port_ptypes_result,
19675 		 port_id, UINT16);
19676 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19677 	TOKEN_STRING_INITIALIZER
19678 		(struct cmd_set_port_ptypes_result,
19679 		 ptype_mask, "ptype_mask");
19680 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19681 	TOKEN_NUM_INITIALIZER
19682 		(struct cmd_set_port_ptypes_result,
19683 		 mask, UINT32);
19684 
19685 static void
19686 cmd_set_port_ptypes_parsed(
19687 	void *parsed_result,
19688 	__rte_unused struct cmdline *cl,
19689 	__rte_unused void *data)
19690 {
19691 	struct cmd_set_port_ptypes_result *res = parsed_result;
19692 #define PTYPE_NAMESIZE        256
19693 	char ptype_name[PTYPE_NAMESIZE];
19694 	uint16_t port_id = res->port_id;
19695 	uint32_t ptype_mask = res->mask;
19696 	int ret, i;
19697 
19698 	ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19699 					       NULL, 0);
19700 	if (ret <= 0) {
19701 		printf("Port %d doesn't support any ptypes.\n", port_id);
19702 		return;
19703 	}
19704 
19705 	uint32_t ptypes[ret];
19706 
19707 	ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19708 	if (ret < 0) {
19709 		printf("Unable to set requested ptypes for Port %d\n", port_id);
19710 		return;
19711 	}
19712 
19713 	printf("Successfully set following ptypes for Port %d\n", port_id);
19714 	for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19715 		rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19716 		printf("%s\n", ptype_name);
19717 	}
19718 
19719 	clear_ptypes = false;
19720 }
19721 
19722 cmdline_parse_inst_t cmd_set_port_ptypes = {
19723 	.f = cmd_set_port_ptypes_parsed,
19724 	.data = NULL,
19725 	.help_str = "set port <port_id> ptype_mask <mask>",
19726 	.tokens = {
19727 		(void *)&cmd_set_port_ptypes_set,
19728 		(void *)&cmd_set_port_ptypes_port,
19729 		(void *)&cmd_set_port_ptypes_port_id,
19730 		(void *)&cmd_set_port_ptypes_mask_str,
19731 		(void *)&cmd_set_port_ptypes_mask_u32,
19732 		NULL,
19733 	},
19734 };
19735 
19736 /* *** display mac addresses added to a port *** */
19737 struct cmd_showport_macs_result {
19738 	cmdline_fixed_string_t cmd_show;
19739 	cmdline_fixed_string_t cmd_port;
19740 	cmdline_fixed_string_t cmd_keyword;
19741 	portid_t cmd_pid;
19742 };
19743 
19744 static void
19745 cmd_showport_macs_parsed(void *parsed_result,
19746 		__rte_unused struct cmdline *cl,
19747 		__rte_unused void *data)
19748 {
19749 	struct cmd_showport_macs_result *res = parsed_result;
19750 
19751 	if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19752 		return;
19753 
19754 	if (!strcmp(res->cmd_keyword, "macs"))
19755 		show_macs(res->cmd_pid);
19756 	else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19757 		show_mcast_macs(res->cmd_pid);
19758 }
19759 
19760 cmdline_parse_token_string_t cmd_showport_macs_show =
19761 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19762 			cmd_show, "show");
19763 cmdline_parse_token_string_t cmd_showport_macs_port =
19764 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19765 			cmd_port, "port");
19766 cmdline_parse_token_num_t cmd_showport_macs_pid =
19767 	TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19768 			cmd_pid, UINT16);
19769 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19770 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19771 			cmd_keyword, "macs#mcast_macs");
19772 
19773 cmdline_parse_inst_t cmd_showport_macs = {
19774 	.f = cmd_showport_macs_parsed,
19775 	.data = NULL,
19776 	.help_str = "show port <port_id> macs|mcast_macs",
19777 	.tokens = {
19778 		(void *)&cmd_showport_macs_show,
19779 		(void *)&cmd_showport_macs_port,
19780 		(void *)&cmd_showport_macs_pid,
19781 		(void *)&cmd_showport_macs_keyword,
19782 		NULL,
19783 	},
19784 };
19785 
19786 /* ******************************************************************************** */
19787 
19788 /* list of instructions */
19789 cmdline_parse_ctx_t main_ctx[] = {
19790 	(cmdline_parse_inst_t *)&cmd_help_brief,
19791 	(cmdline_parse_inst_t *)&cmd_help_long,
19792 	(cmdline_parse_inst_t *)&cmd_quit,
19793 	(cmdline_parse_inst_t *)&cmd_load_from_file,
19794 	(cmdline_parse_inst_t *)&cmd_showport,
19795 	(cmdline_parse_inst_t *)&cmd_showqueue,
19796 	(cmdline_parse_inst_t *)&cmd_showeeprom,
19797 	(cmdline_parse_inst_t *)&cmd_showportall,
19798 	(cmdline_parse_inst_t *)&cmd_showdevice,
19799 	(cmdline_parse_inst_t *)&cmd_showcfg,
19800 	(cmdline_parse_inst_t *)&cmd_showfwdall,
19801 	(cmdline_parse_inst_t *)&cmd_start,
19802 	(cmdline_parse_inst_t *)&cmd_start_tx_first,
19803 	(cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19804 	(cmdline_parse_inst_t *)&cmd_set_link_up,
19805 	(cmdline_parse_inst_t *)&cmd_set_link_down,
19806 	(cmdline_parse_inst_t *)&cmd_reset,
19807 	(cmdline_parse_inst_t *)&cmd_set_numbers,
19808 	(cmdline_parse_inst_t *)&cmd_set_log,
19809 	(cmdline_parse_inst_t *)&cmd_set_txpkts,
19810 	(cmdline_parse_inst_t *)&cmd_set_txsplit,
19811 	(cmdline_parse_inst_t *)&cmd_set_txtimes,
19812 	(cmdline_parse_inst_t *)&cmd_set_fwd_list,
19813 	(cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19814 	(cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19815 	(cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19816 	(cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19817 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19818 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19819 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19820 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19821 	(cmdline_parse_inst_t *)&cmd_set_flush_rx,
19822 	(cmdline_parse_inst_t *)&cmd_set_link_check,
19823 	(cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19824 	(cmdline_parse_inst_t *)&cmd_set_bypass_event,
19825 	(cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19826 	(cmdline_parse_inst_t *)&cmd_show_bypass_config,
19827 #ifdef RTE_LIBRTE_PMD_BOND
19828 	(cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19829 	(cmdline_parse_inst_t *) &cmd_show_bonding_config,
19830 	(cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19831 	(cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19832 	(cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19833 	(cmdline_parse_inst_t *) &cmd_create_bonded_device,
19834 	(cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19835 	(cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19836 	(cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19837 	(cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19838 	(cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19839 #endif
19840 	(cmdline_parse_inst_t *)&cmd_vlan_offload,
19841 	(cmdline_parse_inst_t *)&cmd_vlan_tpid,
19842 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19843 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19844 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19845 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19846 	(cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19847 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19848 	(cmdline_parse_inst_t *)&cmd_csum_set,
19849 	(cmdline_parse_inst_t *)&cmd_csum_show,
19850 	(cmdline_parse_inst_t *)&cmd_csum_tunnel,
19851 	(cmdline_parse_inst_t *)&cmd_tso_set,
19852 	(cmdline_parse_inst_t *)&cmd_tso_show,
19853 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19854 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19855 	(cmdline_parse_inst_t *)&cmd_gro_enable,
19856 	(cmdline_parse_inst_t *)&cmd_gro_flush,
19857 	(cmdline_parse_inst_t *)&cmd_gro_show,
19858 	(cmdline_parse_inst_t *)&cmd_gso_enable,
19859 	(cmdline_parse_inst_t *)&cmd_gso_size,
19860 	(cmdline_parse_inst_t *)&cmd_gso_show,
19861 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19862 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19863 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19864 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19865 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19866 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19867 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19868 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19869 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19870 	(cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19871 	(cmdline_parse_inst_t *)&cmd_config_dcb,
19872 	(cmdline_parse_inst_t *)&cmd_read_reg,
19873 	(cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19874 	(cmdline_parse_inst_t *)&cmd_read_reg_bit,
19875 	(cmdline_parse_inst_t *)&cmd_write_reg,
19876 	(cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19877 	(cmdline_parse_inst_t *)&cmd_write_reg_bit,
19878 	(cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19879 	(cmdline_parse_inst_t *)&cmd_stop,
19880 	(cmdline_parse_inst_t *)&cmd_mac_addr,
19881 	(cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19882 	(cmdline_parse_inst_t *)&cmd_set_qmap,
19883 	(cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19884 	(cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
19885 	(cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
19886 	(cmdline_parse_inst_t *)&cmd_operate_port,
19887 	(cmdline_parse_inst_t *)&cmd_operate_specific_port,
19888 	(cmdline_parse_inst_t *)&cmd_operate_attach_port,
19889 	(cmdline_parse_inst_t *)&cmd_operate_detach_port,
19890 	(cmdline_parse_inst_t *)&cmd_operate_detach_device,
19891 	(cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19892 	(cmdline_parse_inst_t *)&cmd_config_speed_all,
19893 	(cmdline_parse_inst_t *)&cmd_config_speed_specific,
19894 	(cmdline_parse_inst_t *)&cmd_config_loopback_all,
19895 	(cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19896 	(cmdline_parse_inst_t *)&cmd_config_rx_tx,
19897 	(cmdline_parse_inst_t *)&cmd_config_mtu,
19898 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19899 	(cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19900 	(cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19901 	(cmdline_parse_inst_t *)&cmd_config_rss,
19902 	(cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19903 	(cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19904 	(cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19905 	(cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19906 	(cmdline_parse_inst_t *)&cmd_config_rss_reta,
19907 	(cmdline_parse_inst_t *)&cmd_showport_reta,
19908 	(cmdline_parse_inst_t *)&cmd_showport_macs,
19909 	(cmdline_parse_inst_t *)&cmd_config_burst,
19910 	(cmdline_parse_inst_t *)&cmd_config_thresh,
19911 	(cmdline_parse_inst_t *)&cmd_config_threshold,
19912 	(cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19913 	(cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19914 	(cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19915 	(cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19916 	(cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19917 	(cmdline_parse_inst_t *)&cmd_tunnel_filter,
19918 	(cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19919 	(cmdline_parse_inst_t *)&cmd_global_config,
19920 	(cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19921 	(cmdline_parse_inst_t *)&cmd_set_mirror_link,
19922 	(cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19923 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19924 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19925 	(cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19926 	(cmdline_parse_inst_t *)&cmd_dump,
19927 	(cmdline_parse_inst_t *)&cmd_dump_one,
19928 	(cmdline_parse_inst_t *)&cmd_ethertype_filter,
19929 	(cmdline_parse_inst_t *)&cmd_syn_filter,
19930 	(cmdline_parse_inst_t *)&cmd_2tuple_filter,
19931 	(cmdline_parse_inst_t *)&cmd_5tuple_filter,
19932 	(cmdline_parse_inst_t *)&cmd_flex_filter,
19933 	(cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19934 	(cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19935 	(cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19936 	(cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19937 	(cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19938 	(cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19939 	(cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19940 	(cmdline_parse_inst_t *)&cmd_flush_flow_director,
19941 	(cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19942 	(cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19943 	(cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19944 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19945 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19946 	(cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19947 	(cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19948 	(cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19949 	(cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19950 	(cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19951 	(cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19952 	(cmdline_parse_inst_t *)&cmd_flow,
19953 	(cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19954 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19955 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19956 	(cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19957 	(cmdline_parse_inst_t *)&cmd_create_port_meter,
19958 	(cmdline_parse_inst_t *)&cmd_enable_port_meter,
19959 	(cmdline_parse_inst_t *)&cmd_disable_port_meter,
19960 	(cmdline_parse_inst_t *)&cmd_del_port_meter,
19961 	(cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19962 	(cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19963 	(cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19964 	(cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19965 	(cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19966 	(cmdline_parse_inst_t *)&cmd_mcast_addr,
19967 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19968 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19969 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19970 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19971 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19972 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19973 	(cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19974 	(cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19975 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19976 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19977 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19978 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19979 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19980 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19981 	(cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19982 	(cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19983 	(cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19984 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19985 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19986 	(cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19987 	(cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19988 	(cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19989 	(cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19990 	(cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19991 	(cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19992 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19993 	(cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19994 	(cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19995 	(cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19996 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19997 	(cmdline_parse_inst_t *)&cmd_vf_max_bw,
19998 	(cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19999 	(cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
20000 	(cmdline_parse_inst_t *)&cmd_strict_link_prio,
20001 	(cmdline_parse_inst_t *)&cmd_tc_min_bw,
20002 	(cmdline_parse_inst_t *)&cmd_set_vxlan,
20003 	(cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
20004 	(cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
20005 	(cmdline_parse_inst_t *)&cmd_set_nvgre,
20006 	(cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
20007 	(cmdline_parse_inst_t *)&cmd_set_l2_encap,
20008 	(cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
20009 	(cmdline_parse_inst_t *)&cmd_set_l2_decap,
20010 	(cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
20011 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
20012 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
20013 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
20014 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
20015 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
20016 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
20017 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
20018 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
20019 	(cmdline_parse_inst_t *)&cmd_ddp_add,
20020 	(cmdline_parse_inst_t *)&cmd_ddp_del,
20021 	(cmdline_parse_inst_t *)&cmd_ddp_get_list,
20022 	(cmdline_parse_inst_t *)&cmd_ddp_get_info,
20023 	(cmdline_parse_inst_t *)&cmd_cfg_input_set,
20024 	(cmdline_parse_inst_t *)&cmd_clear_input_set,
20025 	(cmdline_parse_inst_t *)&cmd_show_vf_stats,
20026 	(cmdline_parse_inst_t *)&cmd_clear_vf_stats,
20027 	(cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
20028 	(cmdline_parse_inst_t *)&cmd_set_port_ptypes,
20029 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
20030 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
20031 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
20032 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
20033 
20034 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
20035 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
20036 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
20037 	(cmdline_parse_inst_t *)&cmd_queue_region,
20038 	(cmdline_parse_inst_t *)&cmd_region_flowtype,
20039 	(cmdline_parse_inst_t *)&cmd_user_priority_region,
20040 	(cmdline_parse_inst_t *)&cmd_flush_queue_region,
20041 	(cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
20042 	(cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
20043 	(cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
20044 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
20045 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
20046 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
20047 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
20048 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
20049 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
20050 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
20051 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
20052 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
20053 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
20054 	(cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
20055 	(cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
20056 	(cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
20057 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node,
20058 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
20059 	(cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
20060 	(cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
20061 	(cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
20062 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
20063 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
20064 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
20065 	(cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
20066 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
20067 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
20068 	(cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
20069 	(cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
20070 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
20071 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
20072 	(cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
20073 	(cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
20074 #ifdef RTE_LIBRTE_BPF
20075 	(cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
20076 	(cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
20077 #endif
20078 	(cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
20079 	(cmdline_parse_inst_t *)&cmd_show_tx_metadata,
20080 	(cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
20081 	(cmdline_parse_inst_t *)&cmd_set_raw,
20082 	(cmdline_parse_inst_t *)&cmd_show_set_raw,
20083 	(cmdline_parse_inst_t *)&cmd_show_set_raw_all,
20084 	(cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
20085 	(cmdline_parse_inst_t *)&cmd_show_fec_mode,
20086 	(cmdline_parse_inst_t *)&cmd_set_fec_mode,
20087 	(cmdline_parse_inst_t *)&cmd_show_capability,
20088 	NULL,
20089 };
20090 
20091 /* read cmdline commands from file */
20092 void
20093 cmdline_read_from_file(const char *filename)
20094 {
20095 	struct cmdline *cl;
20096 
20097 	cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
20098 	if (cl == NULL) {
20099 		printf("Failed to create file based cmdline context: %s\n",
20100 		       filename);
20101 		return;
20102 	}
20103 
20104 	cmdline_interact(cl);
20105 	cmdline_quit(cl);
20106 
20107 	cmdline_free(cl);
20108 
20109 	printf("Read CLI commands from %s\n", filename);
20110 }
20111 
20112 /* prompt function, called from main on MASTER lcore */
20113 void
20114 prompt(void)
20115 {
20116 	/* initialize non-constant commands */
20117 	cmd_set_fwd_mode_init();
20118 	cmd_set_fwd_retry_mode_init();
20119 
20120 	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
20121 	if (testpmd_cl == NULL)
20122 		return;
20123 	cmdline_interact(testpmd_cl);
20124 	cmdline_stdin_exit(testpmd_cl);
20125 }
20126 
20127 void
20128 prompt_exit(void)
20129 {
20130 	if (testpmd_cl != NULL)
20131 		cmdline_quit(testpmd_cl);
20132 }
20133 
20134 static void
20135 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
20136 {
20137 	if (id == (portid_t)RTE_PORT_ALL) {
20138 		portid_t pid;
20139 
20140 		RTE_ETH_FOREACH_DEV(pid) {
20141 			/* check if need_reconfig has been set to 1 */
20142 			if (ports[pid].need_reconfig == 0)
20143 				ports[pid].need_reconfig = dev;
20144 			/* check if need_reconfig_queues has been set to 1 */
20145 			if (ports[pid].need_reconfig_queues == 0)
20146 				ports[pid].need_reconfig_queues = queue;
20147 		}
20148 	} else if (!port_id_is_invalid(id, DISABLED_WARN)) {
20149 		/* check if need_reconfig has been set to 1 */
20150 		if (ports[id].need_reconfig == 0)
20151 			ports[id].need_reconfig = dev;
20152 		/* check if need_reconfig_queues has been set to 1 */
20153 		if (ports[id].need_reconfig_queues == 0)
20154 			ports[id].need_reconfig_queues = queue;
20155 	}
20156 }
20157