xref: /dpdk/app/test-pmd/cmdline.c (revision 55e51c96243228317d25fd206d98fe2fa2b7da08)
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 #ifndef __linux__
15 #ifndef __FreeBSD__
16 #include <net/socket.h>
17 #else
18 #include <sys/socket.h>
19 #endif
20 #endif
21 #include <netinet/in.h>
22 
23 #include <sys/queue.h>
24 
25 #include <rte_common.h>
26 #include <rte_byteorder.h>
27 #include <rte_log.h>
28 #include <rte_debug.h>
29 #include <rte_cycles.h>
30 #include <rte_memory.h>
31 #include <rte_memzone.h>
32 #include <rte_malloc.h>
33 #include <rte_launch.h>
34 #include <rte_eal.h>
35 #include <rte_per_lcore.h>
36 #include <rte_lcore.h>
37 #include <rte_atomic.h>
38 #include <rte_branch_prediction.h>
39 #include <rte_ring.h>
40 #include <rte_mempool.h>
41 #include <rte_interrupts.h>
42 #include <rte_pci.h>
43 #include <rte_ether.h>
44 #include <rte_ethdev.h>
45 #include <rte_string_fns.h>
46 #include <rte_devargs.h>
47 #include <rte_flow.h>
48 #include <rte_gro.h>
49 
50 #include <cmdline_rdline.h>
51 #include <cmdline_parse.h>
52 #include <cmdline_parse_num.h>
53 #include <cmdline_parse_string.h>
54 #include <cmdline_parse_ipaddr.h>
55 #include <cmdline_parse_etheraddr.h>
56 #include <cmdline_socket.h>
57 #include <cmdline.h>
58 #ifdef RTE_LIBRTE_PMD_BOND
59 #include <rte_eth_bond.h>
60 #include <rte_eth_bond_8023ad.h>
61 #endif
62 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
63 #include <rte_pmd_dpaa.h>
64 #endif
65 #ifdef RTE_LIBRTE_IXGBE_PMD
66 #include <rte_pmd_ixgbe.h>
67 #endif
68 #ifdef RTE_LIBRTE_I40E_PMD
69 #include <rte_pmd_i40e.h>
70 #endif
71 #ifdef RTE_LIBRTE_BNXT_PMD
72 #include <rte_pmd_bnxt.h>
73 #endif
74 #include "testpmd.h"
75 #include "cmdline_mtr.h"
76 #include "cmdline_tm.h"
77 #include "bpf_cmd.h"
78 
79 static struct cmdline *testpmd_cl;
80 
81 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
82 
83 /* *** Help command with introduction. *** */
84 struct cmd_help_brief_result {
85 	cmdline_fixed_string_t help;
86 };
87 
88 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
89                                   struct cmdline *cl,
90                                   __attribute__((unused)) void *data)
91 {
92 	cmdline_printf(
93 		cl,
94 		"\n"
95 		"Help is available for the following sections:\n\n"
96 		"    help control                    : Start and stop forwarding.\n"
97 		"    help display                    : Displaying port, stats and config "
98 		"information.\n"
99 		"    help config                     : Configuration information.\n"
100 		"    help ports                      : Configuring ports.\n"
101 		"    help registers                  : Reading and setting port registers.\n"
102 		"    help filters                    : Filters configuration help.\n"
103 		"    help traffic_management         : Traffic Management commmands.\n"
104 		"    help devices                    : Device related cmds.\n"
105 		"    help all                        : All of the above sections.\n\n"
106 	);
107 
108 }
109 
110 cmdline_parse_token_string_t cmd_help_brief_help =
111 	TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
112 
113 cmdline_parse_inst_t cmd_help_brief = {
114 	.f = cmd_help_brief_parsed,
115 	.data = NULL,
116 	.help_str = "help: Show help",
117 	.tokens = {
118 		(void *)&cmd_help_brief_help,
119 		NULL,
120 	},
121 };
122 
123 /* *** Help command with help sections. *** */
124 struct cmd_help_long_result {
125 	cmdline_fixed_string_t help;
126 	cmdline_fixed_string_t section;
127 };
128 
129 static void cmd_help_long_parsed(void *parsed_result,
130                                  struct cmdline *cl,
131                                  __attribute__((unused)) void *data)
132 {
133 	int show_all = 0;
134 	struct cmd_help_long_result *res = parsed_result;
135 
136 	if (!strcmp(res->section, "all"))
137 		show_all = 1;
138 
139 	if (show_all || !strcmp(res->section, "control")) {
140 
141 		cmdline_printf(
142 			cl,
143 			"\n"
144 			"Control forwarding:\n"
145 			"-------------------\n\n"
146 
147 			"start\n"
148 			"    Start packet forwarding with current configuration.\n\n"
149 
150 			"start tx_first\n"
151 			"    Start packet forwarding with current config"
152 			" after sending one burst of packets.\n\n"
153 
154 			"stop\n"
155 			"    Stop packet forwarding, and display accumulated"
156 			" statistics.\n\n"
157 
158 			"quit\n"
159 			"    Quit to prompt.\n\n"
160 		);
161 	}
162 
163 	if (show_all || !strcmp(res->section, "display")) {
164 
165 		cmdline_printf(
166 			cl,
167 			"\n"
168 			"Display:\n"
169 			"--------\n\n"
170 
171 			"show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
172 			"    Display information for port_id, or all.\n\n"
173 
174 			"show port X rss reta (size) (mask0,mask1,...)\n"
175 			"    Display the rss redirection table entry indicated"
176 			" by masks on port X. size is used to indicate the"
177 			" hardware supported reta size\n\n"
178 
179 			"show port (port_id) rss-hash [key]\n"
180 			"    Display the RSS hash functions and RSS hash key of port\n\n"
181 
182 			"clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
183 			"    Clear information for port_id, or all.\n\n"
184 
185 			"show (rxq|txq) info (port_id) (queue_id)\n"
186 			"    Display information for configured RX/TX queue.\n\n"
187 
188 			"show config (rxtx|cores|fwd|txpkts)\n"
189 			"    Display the given configuration.\n\n"
190 
191 			"read rxd (port_id) (queue_id) (rxd_id)\n"
192 			"    Display an RX descriptor of a port RX queue.\n\n"
193 
194 			"read txd (port_id) (queue_id) (txd_id)\n"
195 			"    Display a TX descriptor of a port TX queue.\n\n"
196 
197 			"ddp get list (port_id)\n"
198 			"    Get ddp profile info list\n\n"
199 
200 			"ddp get info (profile_path)\n"
201 			"    Get ddp profile information.\n\n"
202 
203 			"show vf stats (port_id) (vf_id)\n"
204 			"    Display a VF's statistics.\n\n"
205 
206 			"clear vf stats (port_id) (vf_id)\n"
207 			"    Reset a VF's statistics.\n\n"
208 
209 			"show port (port_id) pctype mapping\n"
210 			"    Get flow ptype to pctype mapping on a port\n\n"
211 
212 			"show port meter stats (port_id) (meter_id) (clear)\n"
213 			"    Get meter stats on a port\n\n"
214 
215 			"show fwd stats all\n"
216 			"    Display statistics for all fwd engines.\n\n"
217 
218 			"clear fwd stats all\n"
219 			"    Clear statistics for all fwd engines.\n\n"
220 
221 			"show port (port_id) rx_offload capabilities\n"
222 			"    List all per queue and per port Rx offloading"
223 			" capabilities of a port\n\n"
224 
225 			"show port (port_id) rx_offload configuration\n"
226 			"    List port level and all queue level"
227 			" Rx offloading configuration\n\n"
228 
229 			"show port (port_id) tx_offload capabilities\n"
230 			"    List all per queue and per port"
231 			" Tx offloading capabilities of a port\n\n"
232 
233 			"show port (port_id) tx_offload configuration\n"
234 			"    List port level and all queue level"
235 			" Tx offloading configuration\n\n"
236 
237 			"show port (port_id) tx_metadata\n"
238 			"    Show Tx metadata value set"
239 			" for a specific port\n\n"
240 
241 			"show device info (<identifier>|all)"
242 			"       Show general information about devices probed.\n\n"
243 		);
244 	}
245 
246 	if (show_all || !strcmp(res->section, "config")) {
247 		cmdline_printf(
248 			cl,
249 			"\n"
250 			"Configuration:\n"
251 			"--------------\n"
252 			"Configuration changes only become active when"
253 			" forwarding is started/restarted.\n\n"
254 
255 			"set default\n"
256 			"    Reset forwarding to the default configuration.\n\n"
257 
258 			"set verbose (level)\n"
259 			"    Set the debug verbosity level X.\n\n"
260 
261 			"set log global|(type) (level)\n"
262 			"    Set the log level.\n\n"
263 
264 			"set nbport (num)\n"
265 			"    Set number of ports.\n\n"
266 
267 			"set nbcore (num)\n"
268 			"    Set number of cores.\n\n"
269 
270 			"set coremask (mask)\n"
271 			"    Set the forwarding cores hexadecimal mask.\n\n"
272 
273 			"set portmask (mask)\n"
274 			"    Set the forwarding ports hexadecimal mask.\n\n"
275 
276 			"set burst (num)\n"
277 			"    Set number of packets per burst.\n\n"
278 
279 			"set burst tx delay (microseconds) retry (num)\n"
280 			"    Set the transmit delay time and number of retries,"
281 			" effective when retry is enabled.\n\n"
282 
283 			"set txpkts (x[,y]*)\n"
284 			"    Set the length of each segment of TXONLY"
285 			" and optionally CSUM packets.\n\n"
286 
287 			"set txsplit (off|on|rand)\n"
288 			"    Set the split policy for the TX packets."
289 			" Right now only applicable for CSUM and TXONLY"
290 			" modes\n\n"
291 
292 			"set corelist (x[,y]*)\n"
293 			"    Set the list of forwarding cores.\n\n"
294 
295 			"set portlist (x[,y]*)\n"
296 			"    Set the list of forwarding ports.\n\n"
297 
298 			"set port setup on (iterator|event)\n"
299 			"    Select how attached port is retrieved for setup.\n\n"
300 
301 			"set tx loopback (port_id) (on|off)\n"
302 			"    Enable or disable tx loopback.\n\n"
303 
304 			"set all queues drop (port_id) (on|off)\n"
305 			"    Set drop enable bit for all queues.\n\n"
306 
307 			"set vf split drop (port_id) (vf_id) (on|off)\n"
308 			"    Set split drop enable bit for a VF from the PF.\n\n"
309 
310 			"set vf mac antispoof (port_id) (vf_id) (on|off).\n"
311 			"    Set MAC antispoof for a VF from the PF.\n\n"
312 
313 			"set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
314 			"    Enable MACsec offload.\n\n"
315 
316 			"set macsec offload (port_id) off\n"
317 			"    Disable MACsec offload.\n\n"
318 
319 			"set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
320 			"    Configure MACsec secure connection (SC).\n\n"
321 
322 			"set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
323 			"    Configure MACsec secure association (SA).\n\n"
324 
325 			"set vf broadcast (port_id) (vf_id) (on|off)\n"
326 			"    Set VF broadcast for a VF from the PF.\n\n"
327 
328 			"vlan set strip (on|off) (port_id)\n"
329 			"    Set the VLAN strip on a port.\n\n"
330 
331 			"vlan set stripq (on|off) (port_id,queue_id)\n"
332 			"    Set the VLAN strip for a queue on a port.\n\n"
333 
334 			"set vf vlan stripq (port_id) (vf_id) (on|off)\n"
335 			"    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
336 
337 			"set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
338 			"    Set VLAN insert for a VF from the PF.\n\n"
339 
340 			"set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
341 			"    Set VLAN antispoof for a VF from the PF.\n\n"
342 
343 			"set vf vlan tag (port_id) (vf_id) (on|off)\n"
344 			"    Set VLAN tag for a VF from the PF.\n\n"
345 
346 			"set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
347 			"    Set a VF's max bandwidth(Mbps).\n\n"
348 
349 			"set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
350 			"    Set all TCs' min bandwidth(%%) on a VF.\n\n"
351 
352 			"set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
353 			"    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
354 
355 			"set tx strict-link-priority (port_id) (tc_bitmap)\n"
356 			"    Set some TCs' strict link priority mode on a physical port.\n\n"
357 
358 			"set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
359 			"    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
360 
361 			"vlan set filter (on|off) (port_id)\n"
362 			"    Set the VLAN filter on a port.\n\n"
363 
364 			"vlan set qinq (on|off) (port_id)\n"
365 			"    Set the VLAN QinQ (extended queue in queue)"
366 			" on a port.\n\n"
367 
368 			"vlan set (inner|outer) tpid (value) (port_id)\n"
369 			"    Set the VLAN TPID for Packet Filtering on"
370 			" a port\n\n"
371 
372 			"rx_vlan add (vlan_id|all) (port_id)\n"
373 			"    Add a vlan_id, or all identifiers, to the set"
374 			" of VLAN identifiers filtered by port_id.\n\n"
375 
376 			"rx_vlan rm (vlan_id|all) (port_id)\n"
377 			"    Remove a vlan_id, or all identifiers, from the set"
378 			" of VLAN identifiers filtered by port_id.\n\n"
379 
380 			"rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
381 			"    Add a vlan_id, to the set of VLAN identifiers"
382 			"filtered for VF(s) from port_id.\n\n"
383 
384 			"rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
385 			"    Remove a vlan_id, to the set of VLAN identifiers"
386 			"filtered for VF(s) from port_id.\n\n"
387 
388 			"tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
389 			"(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
390 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
391 			"   add a tunnel filter of a port.\n\n"
392 
393 			"tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
394 			"(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
395 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
396 			"   remove a tunnel filter of a port.\n\n"
397 
398 			"rx_vxlan_port add (udp_port) (port_id)\n"
399 			"    Add an UDP port for VXLAN packet filter on a port\n\n"
400 
401 			"rx_vxlan_port rm (udp_port) (port_id)\n"
402 			"    Remove an UDP port for VXLAN packet filter on a port\n\n"
403 
404 			"tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
405 			"    Set hardware insertion of VLAN IDs (single or double VLAN "
406 			"depends on the number of VLAN IDs) in packets sent on a port.\n\n"
407 
408 			"tx_vlan set pvid port_id vlan_id (on|off)\n"
409 			"    Set port based TX VLAN insertion.\n\n"
410 
411 			"tx_vlan reset (port_id)\n"
412 			"    Disable hardware insertion of a VLAN header in"
413 			" packets sent on a port.\n\n"
414 
415 			"csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
416 			"    Select hardware or software calculation of the"
417 			" checksum when transmitting a packet using the"
418 			" csum forward engine.\n"
419 			"    ip|udp|tcp|sctp always concern the inner layer.\n"
420 			"    outer-ip concerns the outer IP layer in"
421 			"    outer-udp concerns the outer UDP layer in"
422 			" case the packet is recognized as a tunnel packet by"
423 			" the forward engine (vxlan, gre and ipip are supported)\n"
424 			"    Please check the NIC datasheet for HW limits.\n\n"
425 
426 			"csum parse-tunnel (on|off) (tx_port_id)\n"
427 			"    If disabled, treat tunnel packets as non-tunneled"
428 			" packets (treat inner headers as payload). The port\n"
429 			"    argument is the port used for TX in csum forward"
430 			" engine.\n\n"
431 
432 			"csum show (port_id)\n"
433 			"    Display tx checksum offload configuration\n\n"
434 
435 			"tso set (segsize) (portid)\n"
436 			"    Enable TCP Segmentation Offload in csum forward"
437 			" engine.\n"
438 			"    Please check the NIC datasheet for HW limits.\n\n"
439 
440 			"tso show (portid)"
441 			"    Display the status of TCP Segmentation Offload.\n\n"
442 
443 			"set port (port_id) gro on|off\n"
444 			"    Enable or disable Generic Receive Offload in"
445 			" csum forwarding engine.\n\n"
446 
447 			"show port (port_id) gro\n"
448 			"    Display GRO configuration.\n\n"
449 
450 			"set gro flush (cycles)\n"
451 			"    Set the cycle to flush GROed packets from"
452 			" reassembly tables.\n\n"
453 
454 			"set port (port_id) gso (on|off)"
455 			"    Enable or disable Generic Segmentation Offload in"
456 			" csum forwarding engine.\n\n"
457 
458 			"set gso segsz (length)\n"
459 			"    Set max packet length for output GSO segments,"
460 			" including packet header and payload.\n\n"
461 
462 			"show port (port_id) gso\n"
463 			"    Show GSO configuration.\n\n"
464 
465 			"set fwd (%s)\n"
466 			"    Set packet forwarding mode.\n\n"
467 
468 			"mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
469 			"    Add a MAC address on port_id.\n\n"
470 
471 			"mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
472 			"    Remove a MAC address from port_id.\n\n"
473 
474 			"mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
475 			"    Set the default MAC address for port_id.\n\n"
476 
477 			"mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
478 			"    Add a MAC address for a VF on the port.\n\n"
479 
480 			"set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
481 			"    Set the MAC address for a VF from the PF.\n\n"
482 
483 			"set eth-peer (port_id) (peer_addr)\n"
484 			"    set the peer address for certain port.\n\n"
485 
486 			"set port (port_id) uta (mac_address|all) (on|off)\n"
487 			"    Add/Remove a or all unicast hash filter(s)"
488 			"from port X.\n\n"
489 
490 			"set promisc (port_id|all) (on|off)\n"
491 			"    Set the promiscuous mode on port_id, or all.\n\n"
492 
493 			"set allmulti (port_id|all) (on|off)\n"
494 			"    Set the allmulti mode on port_id, or all.\n\n"
495 
496 			"set vf promisc (port_id) (vf_id) (on|off)\n"
497 			"    Set unicast promiscuous mode for a VF from the PF.\n\n"
498 
499 			"set vf allmulti (port_id) (vf_id) (on|off)\n"
500 			"    Set multicast promiscuous mode for a VF from the PF.\n\n"
501 
502 			"set flow_ctrl rx (on|off) tx (on|off) (high_water)"
503 			" (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
504 			" (on|off) autoneg (on|off) (port_id)\n"
505 			"set flow_ctrl rx (on|off) (portid)\n"
506 			"set flow_ctrl tx (on|off) (portid)\n"
507 			"set flow_ctrl high_water (high_water) (portid)\n"
508 			"set flow_ctrl low_water (low_water) (portid)\n"
509 			"set flow_ctrl pause_time (pause_time) (portid)\n"
510 			"set flow_ctrl send_xon (send_xon) (portid)\n"
511 			"set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
512 			"set flow_ctrl autoneg (on|off) (port_id)\n"
513 			"    Set the link flow control parameter on a port.\n\n"
514 
515 			"set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
516 			" (low_water) (pause_time) (priority) (port_id)\n"
517 			"    Set the priority flow control parameter on a"
518 			" port.\n\n"
519 
520 			"set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
521 			"    Set statistics mapping (qmapping 0..15) for RX/TX"
522 			" queue on port.\n"
523 			"    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
524 			" on port 0 to mapping 5.\n\n"
525 
526 			"set xstats-hide-zero on|off\n"
527 			"    Set the option to hide the zero values"
528 			" for xstats display.\n"
529 
530 			"set port (port_id) vf (vf_id) rx|tx on|off\n"
531 			"    Enable/Disable a VF receive/tranmit from a port\n\n"
532 
533 			"set port (port_id) vf (vf_id) (mac_addr)"
534 			" (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
535 			"   Add/Remove unicast or multicast MAC addr filter"
536 			" for a VF.\n\n"
537 
538 			"set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
539 			"|MPE) (on|off)\n"
540 			"    AUPE:accepts untagged VLAN;"
541 			"ROPE:accept unicast hash\n\n"
542 			"    BAM:accepts broadcast packets;"
543 			"MPE:accepts all multicast packets\n\n"
544 			"    Enable/Disable a VF receive mode of a port\n\n"
545 
546 			"set port (port_id) queue (queue_id) rate (rate_num)\n"
547 			"    Set rate limit for a queue of a port\n\n"
548 
549 			"set port (port_id) vf (vf_id) rate (rate_num) "
550 			"queue_mask (queue_mask_value)\n"
551 			"    Set rate limit for queues in VF of a port\n\n"
552 
553 			"set port (port_id) mirror-rule (rule_id)"
554 			" (pool-mirror-up|pool-mirror-down|vlan-mirror)"
555 			" (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
556 			"   Set pool or vlan type mirror rule on a port.\n"
557 			"   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
558 			" dst-pool 0 on' enable mirror traffic with vlan 0,1"
559 			" to pool 0.\n\n"
560 
561 			"set port (port_id) mirror-rule (rule_id)"
562 			" (uplink-mirror|downlink-mirror) dst-pool"
563 			" (pool_id) (on|off)\n"
564 			"   Set uplink or downlink type mirror rule on a port.\n"
565 			"   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
566 			" 0 on' enable mirror income traffic to pool 0.\n\n"
567 
568 			"reset port (port_id) mirror-rule (rule_id)\n"
569 			"   Reset a mirror rule.\n\n"
570 
571 			"set flush_rx (on|off)\n"
572 			"   Flush (default) or don't flush RX streams before"
573 			" forwarding. Mainly used with PCAP drivers.\n\n"
574 
575 			"set bypass mode (normal|bypass|isolate) (port_id)\n"
576 			"   Set the bypass mode for the lowest port on bypass enabled"
577 			" NIC.\n\n"
578 
579 			"set bypass event (timeout|os_on|os_off|power_on|power_off) "
580 			"mode (normal|bypass|isolate) (port_id)\n"
581 			"   Set the event required to initiate specified bypass mode for"
582 			" the lowest port on a bypass enabled NIC where:\n"
583 			"       timeout   = enable bypass after watchdog timeout.\n"
584 			"       os_on     = enable bypass when OS/board is powered on.\n"
585 			"       os_off    = enable bypass when OS/board is powered off.\n"
586 			"       power_on  = enable bypass when power supply is turned on.\n"
587 			"       power_off = enable bypass when power supply is turned off."
588 			"\n\n"
589 
590 			"set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
591 			"   Set the bypass watchdog timeout to 'n' seconds"
592 			" where 0 = instant.\n\n"
593 
594 			"show bypass config (port_id)\n"
595 			"   Show the bypass configuration for a bypass enabled NIC"
596 			" using the lowest port on the NIC.\n\n"
597 
598 #ifdef RTE_LIBRTE_PMD_BOND
599 			"create bonded device (mode) (socket)\n"
600 			"	Create a new bonded device with specific bonding mode and socket.\n\n"
601 
602 			"add bonding slave (slave_id) (port_id)\n"
603 			"	Add a slave device to a bonded device.\n\n"
604 
605 			"remove bonding slave (slave_id) (port_id)\n"
606 			"	Remove a slave device from a bonded device.\n\n"
607 
608 			"set bonding mode (value) (port_id)\n"
609 			"	Set the bonding mode on a bonded device.\n\n"
610 
611 			"set bonding primary (slave_id) (port_id)\n"
612 			"	Set the primary slave for a bonded device.\n\n"
613 
614 			"show bonding config (port_id)\n"
615 			"	Show the bonding config for port_id.\n\n"
616 
617 			"set bonding mac_addr (port_id) (address)\n"
618 			"	Set the MAC address of a bonded device.\n\n"
619 
620 			"set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
621 			"	Set Aggregation mode for IEEE802.3AD (mode 4)"
622 
623 			"set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
624 			"	Set the transmit balance policy for bonded device running in balance mode.\n\n"
625 
626 			"set bonding mon_period (port_id) (value)\n"
627 			"	Set the bonding link status monitoring polling period in ms.\n\n"
628 
629 			"set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
630 			"	Enable/disable dedicated queues for LACP control traffic.\n\n"
631 
632 #endif
633 			"set link-up port (port_id)\n"
634 			"	Set link up for a port.\n\n"
635 
636 			"set link-down port (port_id)\n"
637 			"	Set link down for a port.\n\n"
638 
639 			"E-tag set insertion on port-tag-id (value)"
640 			" port (port_id) vf (vf_id)\n"
641 			"    Enable E-tag insertion for a VF on a port\n\n"
642 
643 			"E-tag set insertion off port (port_id) vf (vf_id)\n"
644 			"    Disable E-tag insertion for a VF on a port\n\n"
645 
646 			"E-tag set stripping (on|off) port (port_id)\n"
647 			"    Enable/disable E-tag stripping on a port\n\n"
648 
649 			"E-tag set forwarding (on|off) port (port_id)\n"
650 			"    Enable/disable E-tag based forwarding"
651 			" on a port\n\n"
652 
653 			"E-tag set filter add e-tag-id (value) dst-pool"
654 			" (pool_id) port (port_id)\n"
655 			"    Add an E-tag forwarding filter on a port\n\n"
656 
657 			"E-tag set filter del e-tag-id (value) port (port_id)\n"
658 			"    Delete an E-tag forwarding filter on a port\n\n"
659 
660 			"ddp add (port_id) (profile_path[,backup_profile_path])\n"
661 			"    Load a profile package on a port\n\n"
662 
663 			"ddp del (port_id) (backup_profile_path)\n"
664 			"    Delete a profile package from a port\n\n"
665 
666 			"ptype mapping get (port_id) (valid_only)\n"
667 			"    Get ptype mapping on a port\n\n"
668 
669 			"ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
670 			"    Replace target with the pkt_type in ptype mapping\n\n"
671 
672 			"ptype mapping reset (port_id)\n"
673 			"    Reset ptype mapping on a port\n\n"
674 
675 			"ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
676 			"    Update a ptype mapping item on a port\n\n"
677 
678 			"set port (port_id) queue-region region_id (value) "
679 			"queue_start_index (value) queue_num (value)\n"
680 			"    Set a queue region on a port\n\n"
681 
682 			"set port (port_id) queue-region region_id (value) "
683 			"flowtype (value)\n"
684 			"    Set a flowtype region index on a port\n\n"
685 
686 			"set port (port_id) queue-region UP (value) region_id (value)\n"
687 			"    Set the mapping of User Priority to "
688 			"queue region on a port\n\n"
689 
690 			"set port (port_id) queue-region flush (on|off)\n"
691 			"    flush all queue region related configuration\n\n"
692 
693 			"show port meter cap (port_id)\n"
694 			"    Show port meter capability information\n\n"
695 
696 			"add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
697 			"    meter profile add - srtcm rfc 2697\n\n"
698 
699 			"add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
700 			"    meter profile add - trtcm rfc 2698\n\n"
701 
702 			"add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
703 			"    meter profile add - trtcm rfc 4115\n\n"
704 
705 			"del port meter profile (port_id) (profile_id)\n"
706 			"    meter profile delete\n\n"
707 
708 			"create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
709 			"(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
710 			"(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
711 			"(dscp_tbl_entry63)]\n"
712 			"    meter create\n\n"
713 
714 			"enable port meter (port_id) (mtr_id)\n"
715 			"    meter enable\n\n"
716 
717 			"disable port meter (port_id) (mtr_id)\n"
718 			"    meter disable\n\n"
719 
720 			"del port meter (port_id) (mtr_id)\n"
721 			"    meter delete\n\n"
722 
723 			"set port meter profile (port_id) (mtr_id) (profile_id)\n"
724 			"    meter update meter profile\n\n"
725 
726 			"set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
727 			"(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
728 			"    update meter dscp table entries\n\n"
729 
730 			"set port meter policer action (port_id) (mtr_id) (action_mask)\n"
731 			"(action0) [(action1) (action2)]\n"
732 			"    meter update policer action\n\n"
733 
734 			"set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
735 			"    meter update stats\n\n"
736 
737 			"show port (port_id) queue-region\n"
738 			"    show all queue region related configuration info\n\n"
739 
740 			, list_pkt_forwarding_modes()
741 		);
742 	}
743 
744 	if (show_all || !strcmp(res->section, "ports")) {
745 
746 		cmdline_printf(
747 			cl,
748 			"\n"
749 			"Port Operations:\n"
750 			"----------------\n\n"
751 
752 			"port start (port_id|all)\n"
753 			"    Start all ports or port_id.\n\n"
754 
755 			"port stop (port_id|all)\n"
756 			"    Stop all ports or port_id.\n\n"
757 
758 			"port close (port_id|all)\n"
759 			"    Close all ports or port_id.\n\n"
760 
761 			"port attach (ident)\n"
762 			"    Attach physical or virtual dev by pci address or virtual device name\n\n"
763 
764 			"port detach (port_id)\n"
765 			"    Detach physical or virtual dev by port_id\n\n"
766 
767 			"port config (port_id|all)"
768 			" speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
769 			" duplex (half|full|auto)\n"
770 			"    Set speed and duplex for all ports or port_id\n\n"
771 
772 			"port config (port_id|all) loopback (mode)\n"
773 			"    Set loopback mode for all ports or port_id\n\n"
774 
775 			"port config all (rxq|txq|rxd|txd) (value)\n"
776 			"    Set number for rxq/txq/rxd/txd.\n\n"
777 
778 			"port config all max-pkt-len (value)\n"
779 			"    Set the max packet length.\n\n"
780 
781 			"port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
782 			"hw-vlan-strip|hw-vlan-extend|drop-en)"
783 			" (on|off)\n"
784 			"    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
785 			" for ports.\n\n"
786 
787 			"port config all rss (all|default|ip|tcp|udp|sctp|"
788 			"ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
789 			"    Set the RSS mode.\n\n"
790 
791 			"port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
792 			"    Set the RSS redirection table.\n\n"
793 
794 			"port config (port_id) dcb vt (on|off) (traffic_class)"
795 			" pfc (on|off)\n"
796 			"    Set the DCB mode.\n\n"
797 
798 			"port config all burst (value)\n"
799 			"    Set the number of packets per burst.\n\n"
800 
801 			"port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
802 			" (value)\n"
803 			"    Set the ring prefetch/host/writeback threshold"
804 			" for tx/rx queue.\n\n"
805 
806 			"port config all (txfreet|txrst|rxfreet) (value)\n"
807 			"    Set free threshold for rx/tx, or set"
808 			" tx rs bit threshold.\n\n"
809 			"port config mtu X value\n"
810 			"    Set the MTU of port X to a given value\n\n"
811 
812 			"port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
813 			"    Set a rx/tx queue's ring size configuration, the new"
814 			" value will take effect after command that (re-)start the port"
815 			" or command that setup the specific queue\n\n"
816 
817 			"port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
818 			"    Start/stop a rx/tx queue of port X. Only take effect"
819 			" when port X is started\n\n"
820 
821 			"port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
822 			"    Switch on/off a deferred start of port X rx/tx queue. Only"
823 			" take effect when port X is stopped.\n\n"
824 
825 			"port (port_id) (rxq|txq) (queue_id) setup\n"
826 			"    Setup a rx/tx queue of port X.\n\n"
827 
828 			"port config (port_id|all) l2-tunnel E-tag ether-type"
829 			" (value)\n"
830 			"    Set the value of E-tag ether-type.\n\n"
831 
832 			"port config (port_id|all) l2-tunnel E-tag"
833 			" (enable|disable)\n"
834 			"    Enable/disable the E-tag support.\n\n"
835 
836 			"port config (port_id) pctype mapping reset\n"
837 			"    Reset flow type to pctype mapping on a port\n\n"
838 
839 			"port config (port_id) pctype mapping update"
840 			" (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
841 			"    Update a flow type to pctype mapping item on a port\n\n"
842 
843 			"port config (port_id) pctype (pctype_id) hash_inset|"
844 			"fdir_inset|fdir_flx_inset get|set|clear field\n"
845 			" (field_idx)\n"
846 			"    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
847 
848 			"port config (port_id) pctype (pctype_id) hash_inset|"
849 			"fdir_inset|fdir_flx_inset clear all"
850 			"    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
851 
852 			"port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
853 			"    Add/remove UDP tunnel port for tunneling offload\n\n"
854 
855 			"port config <port_id> rx_offload vlan_strip|"
856 			"ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
857 			"outer_ipv4_cksum|macsec_strip|header_split|"
858 			"vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
859 			"scatter|timestamp|security|keep_crc on|off\n"
860 			"     Enable or disable a per port Rx offloading"
861 			" on all Rx queues of a port\n\n"
862 
863 			"port (port_id) rxq (queue_id) rx_offload vlan_strip|"
864 			"ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
865 			"outer_ipv4_cksum|macsec_strip|header_split|"
866 			"vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
867 			"scatter|timestamp|security|keep_crc on|off\n"
868 			"    Enable or disable a per queue Rx offloading"
869 			" only on a specific Rx queue\n\n"
870 
871 			"port config (port_id) tx_offload vlan_insert|"
872 			"ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
873 			"udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
874 			"gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
875 			"macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
876 			"security|match_metadata on|off\n"
877 			"    Enable or disable a per port Tx offloading"
878 			" on all Tx queues of a port\n\n"
879 
880 			"port (port_id) txq (queue_id) tx_offload vlan_insert|"
881 			"ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
882 			"udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
883 			"gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
884 			"|mt_lockfree|multi_segs|mbuf_fast_free|security"
885 			" on|off\n"
886 			"    Enable or disable a per queue Tx offloading"
887 			" only on a specific Tx queue\n\n"
888 
889 			"bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
890 			"    Load an eBPF program as a callback"
891 			" for particular RX/TX queue\n\n"
892 
893 			"bpf-unload rx|tx (port) (queue)\n"
894 			"    Unload previously loaded eBPF program"
895 			" for particular RX/TX queue\n\n"
896 
897 			"port config (port_id) tx_metadata (value)\n"
898 			"    Set Tx metadata value per port. Testpmd will add this value"
899 			" to any Tx packet sent from this port\n\n"
900 		);
901 	}
902 
903 	if (show_all || !strcmp(res->section, "registers")) {
904 
905 		cmdline_printf(
906 			cl,
907 			"\n"
908 			"Registers:\n"
909 			"----------\n\n"
910 
911 			"read reg (port_id) (address)\n"
912 			"    Display value of a port register.\n\n"
913 
914 			"read regfield (port_id) (address) (bit_x) (bit_y)\n"
915 			"    Display a port register bit field.\n\n"
916 
917 			"read regbit (port_id) (address) (bit_x)\n"
918 			"    Display a single port register bit.\n\n"
919 
920 			"write reg (port_id) (address) (value)\n"
921 			"    Set value of a port register.\n\n"
922 
923 			"write regfield (port_id) (address) (bit_x) (bit_y)"
924 			" (value)\n"
925 			"    Set bit field of a port register.\n\n"
926 
927 			"write regbit (port_id) (address) (bit_x) (value)\n"
928 			"    Set single bit value of a port register.\n\n"
929 		);
930 	}
931 	if (show_all || !strcmp(res->section, "filters")) {
932 
933 		cmdline_printf(
934 			cl,
935 			"\n"
936 			"filters:\n"
937 			"--------\n\n"
938 
939 			"ethertype_filter (port_id) (add|del)"
940 			" (mac_addr|mac_ignr) (mac_address) ethertype"
941 			" (ether_type) (drop|fwd) queue (queue_id)\n"
942 			"    Add/Del an ethertype filter.\n\n"
943 
944 			"2tuple_filter (port_id) (add|del)"
945 			" dst_port (dst_port_value) protocol (protocol_value)"
946 			" mask (mask_value) tcp_flags (tcp_flags_value)"
947 			" priority (prio_value) queue (queue_id)\n"
948 			"    Add/Del a 2tuple filter.\n\n"
949 
950 			"5tuple_filter (port_id) (add|del)"
951 			" dst_ip (dst_address) src_ip (src_address)"
952 			" dst_port (dst_port_value) src_port (src_port_value)"
953 			" protocol (protocol_value)"
954 			" mask (mask_value) tcp_flags (tcp_flags_value)"
955 			" priority (prio_value) queue (queue_id)\n"
956 			"    Add/Del a 5tuple filter.\n\n"
957 
958 			"syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
959 			"    Add/Del syn filter.\n\n"
960 
961 			"flex_filter (port_id) (add|del) len (len_value)"
962 			" bytes (bytes_value) mask (mask_value)"
963 			" priority (prio_value) queue (queue_id)\n"
964 			"    Add/Del a flex filter.\n\n"
965 
966 			"flow_director_filter (port_id) mode IP (add|del|update)"
967 			" flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
968 			" src (src_ip_address) dst (dst_ip_address)"
969 			" tos (tos_value) proto (proto_value) ttl (ttl_value)"
970 			" vlan (vlan_value) flexbytes (flexbytes_value)"
971 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
972 			" fd_id (fd_id_value)\n"
973 			"    Add/Del an IP type flow director filter.\n\n"
974 
975 			"flow_director_filter (port_id) mode IP (add|del|update)"
976 			" flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
977 			" src (src_ip_address) (src_port)"
978 			" dst (dst_ip_address) (dst_port)"
979 			" tos (tos_value) ttl (ttl_value)"
980 			" vlan (vlan_value) flexbytes (flexbytes_value)"
981 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
982 			" fd_id (fd_id_value)\n"
983 			"    Add/Del an UDP/TCP type flow director filter.\n\n"
984 
985 			"flow_director_filter (port_id) mode IP (add|del|update)"
986 			" flow (ipv4-sctp|ipv6-sctp)"
987 			" src (src_ip_address) (src_port)"
988 			" dst (dst_ip_address) (dst_port)"
989 			" tag (verification_tag) "
990 			" tos (tos_value) ttl (ttl_value)"
991 			" vlan (vlan_value)"
992 			" flexbytes (flexbytes_value) (drop|fwd)"
993 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
994 			"    Add/Del a SCTP type flow director filter.\n\n"
995 
996 			"flow_director_filter (port_id) mode IP (add|del|update)"
997 			" flow l2_payload ether (ethertype)"
998 			" flexbytes (flexbytes_value) (drop|fwd)"
999 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1000 			"    Add/Del a l2 payload type flow director filter.\n\n"
1001 
1002 			"flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1003 			" mac (mac_address) vlan (vlan_value)"
1004 			" flexbytes (flexbytes_value) (drop|fwd)"
1005 			" queue (queue_id) fd_id (fd_id_value)\n"
1006 			"    Add/Del a MAC-VLAN flow director filter.\n\n"
1007 
1008 			"flow_director_filter (port_id) mode Tunnel (add|del|update)"
1009 			" mac (mac_address) vlan (vlan_value)"
1010 			" tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1011 			" flexbytes (flexbytes_value) (drop|fwd)"
1012 			" queue (queue_id) fd_id (fd_id_value)\n"
1013 			"    Add/Del a Tunnel flow director filter.\n\n"
1014 
1015 			"flow_director_filter (port_id) mode raw (add|del|update)"
1016 			" flow (flow_id) (drop|fwd) queue (queue_id)"
1017 			" fd_id (fd_id_value) packet (packet file name)\n"
1018 			"    Add/Del a raw type flow director filter.\n\n"
1019 
1020 			"flush_flow_director (port_id)\n"
1021 			"    Flush all flow director entries of a device.\n\n"
1022 
1023 			"flow_director_mask (port_id) mode IP vlan (vlan_value)"
1024 			" src_mask (ipv4_src) (ipv6_src) (src_port)"
1025 			" dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1026 			"    Set flow director IP mask.\n\n"
1027 
1028 			"flow_director_mask (port_id) mode MAC-VLAN"
1029 			" vlan (vlan_value)\n"
1030 			"    Set flow director MAC-VLAN mask.\n\n"
1031 
1032 			"flow_director_mask (port_id) mode Tunnel"
1033 			" vlan (vlan_value) mac (mac_value)"
1034 			" tunnel-type (tunnel_type_value)"
1035 			" tunnel-id (tunnel_id_value)\n"
1036 			"    Set flow director Tunnel mask.\n\n"
1037 
1038 			"flow_director_flex_mask (port_id)"
1039 			" flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1040 			"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1041 			" (mask)\n"
1042 			"    Configure mask of flex payload.\n\n"
1043 
1044 			"flow_director_flex_payload (port_id)"
1045 			" (raw|l2|l3|l4) (config)\n"
1046 			"    Configure flex payload selection.\n\n"
1047 
1048 			"get_sym_hash_ena_per_port (port_id)\n"
1049 			"    get symmetric hash enable configuration per port.\n\n"
1050 
1051 			"set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1052 			"    set symmetric hash enable configuration per port"
1053 			" to enable or disable.\n\n"
1054 
1055 			"get_hash_global_config (port_id)\n"
1056 			"    Get the global configurations of hash filters.\n\n"
1057 
1058 			"set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1059 			" (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1060 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1061 			" (enable|disable)\n"
1062 			"    Set the global configurations of hash filters.\n\n"
1063 
1064 			"set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1065 			"ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1066 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1067 			"l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1068 			"src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1069 			"ipv6-next-header|udp-src-port|udp-dst-port|"
1070 			"tcp-src-port|tcp-dst-port|sctp-src-port|"
1071 			"sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1072 			"fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1073 			"fld-8th|none) (select|add)\n"
1074 			"    Set the input set for hash.\n\n"
1075 
1076 			"set_fdir_input_set (port_id) "
1077 			"(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1078 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1079 			"l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1080 			"dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1081 			"ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1082 			"udp-dst-port|tcp-src-port|tcp-dst-port|"
1083 			"sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1084 			" (select|add)\n"
1085 			"    Set the input set for FDir.\n\n"
1086 
1087 			"flow validate {port_id}"
1088 			" [group {group_id}] [priority {level}]"
1089 			" [ingress] [egress]"
1090 			" pattern {item} [/ {item} [...]] / end"
1091 			" actions {action} [/ {action} [...]] / end\n"
1092 			"    Check whether a flow rule can be created.\n\n"
1093 
1094 			"flow create {port_id}"
1095 			" [group {group_id}] [priority {level}]"
1096 			" [ingress] [egress]"
1097 			" pattern {item} [/ {item} [...]] / end"
1098 			" actions {action} [/ {action} [...]] / end\n"
1099 			"    Create a flow rule.\n\n"
1100 
1101 			"flow destroy {port_id} rule {rule_id} [...]\n"
1102 			"    Destroy specific flow rules.\n\n"
1103 
1104 			"flow flush {port_id}\n"
1105 			"    Destroy all flow rules.\n\n"
1106 
1107 			"flow query {port_id} {rule_id} {action}\n"
1108 			"    Query an existing flow rule.\n\n"
1109 
1110 			"flow list {port_id} [group {group_id}] [...]\n"
1111 			"    List existing flow rules sorted by priority,"
1112 			" filtered by group identifiers.\n\n"
1113 
1114 			"flow isolate {port_id} {boolean}\n"
1115 			"    Restrict ingress traffic to the defined"
1116 			" flow rules\n\n"
1117 
1118 			"set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1119 			" (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1120 			" (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1121 			"       Configure the VXLAN encapsulation for flows.\n\n"
1122 
1123 			"set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1124 			" udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1125 			" ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1126 			" eth-dst (eth-dst)\n"
1127 			"       Configure the VXLAN encapsulation for flows.\n\n"
1128 
1129 			"set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1130 			" (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1131 			" ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1132 			" eth-dst (eth-dst)\n"
1133 			"       Configure the VXLAN encapsulation for flows.\n\n"
1134 
1135 			"set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1136 			" (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1137 			" (eth-dst)\n"
1138 			"       Configure the NVGRE encapsulation for flows.\n\n"
1139 
1140 			"set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1141 			" ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1142 			" eth-src (eth-src) eth-dst (eth-dst)\n"
1143 			"       Configure the NVGRE encapsulation for flows.\n\n"
1144 
1145 			"set raw_encap {flow items}\n"
1146 			"	Configure the encapsulation with raw data.\n\n"
1147 
1148 			"set raw_decap {flow items}\n"
1149 			"	Configure the decapsulation with raw data.\n\n"
1150 
1151 		);
1152 	}
1153 
1154 	if (show_all || !strcmp(res->section, "traffic_management")) {
1155 		cmdline_printf(
1156 			cl,
1157 			"\n"
1158 			"Traffic Management:\n"
1159 			"--------------\n"
1160 			"show port tm cap (port_id)\n"
1161 			"       Display the port TM capability.\n\n"
1162 
1163 			"show port tm level cap (port_id) (level_id)\n"
1164 			"       Display the port TM hierarchical level capability.\n\n"
1165 
1166 			"show port tm node cap (port_id) (node_id)\n"
1167 			"       Display the port TM node capability.\n\n"
1168 
1169 			"show port tm node type (port_id) (node_id)\n"
1170 			"       Display the port TM node type.\n\n"
1171 
1172 			"show port tm node stats (port_id) (node_id) (clear)\n"
1173 			"       Display the port TM node stats.\n\n"
1174 
1175 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1176 			"set port tm hierarchy default (port_id)\n"
1177 			"       Set default traffic Management hierarchy on a port\n\n"
1178 #endif
1179 
1180 			"add port tm node shaper profile (port_id) (shaper_profile_id)"
1181 			" (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1182 			" (packet_length_adjust)\n"
1183 			"       Add port tm node private shaper profile.\n\n"
1184 
1185 			"del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1186 			"       Delete port tm node private shaper profile.\n\n"
1187 
1188 			"add port tm node shared shaper (port_id) (shared_shaper_id)"
1189 			" (shaper_profile_id)\n"
1190 			"       Add/update port tm node shared shaper.\n\n"
1191 
1192 			"del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1193 			"       Delete port tm node shared shaper.\n\n"
1194 
1195 			"set port tm node shaper profile (port_id) (node_id)"
1196 			" (shaper_profile_id)\n"
1197 			"       Set port tm node shaper profile.\n\n"
1198 
1199 			"add port tm node wred profile (port_id) (wred_profile_id)"
1200 			" (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1201 			" (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1202 			" (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1203 			"       Add port tm node wred profile.\n\n"
1204 
1205 			"del port tm node wred profile (port_id) (wred_profile_id)\n"
1206 			"       Delete port tm node wred profile.\n\n"
1207 
1208 			"add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1209 			" (priority) (weight) (level_id) (shaper_profile_id)"
1210 			" (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1211 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1212 			"       Add port tm nonleaf node.\n\n"
1213 
1214 			"add port tm leaf node (port_id) (node_id) (parent_node_id)"
1215 			" (priority) (weight) (level_id) (shaper_profile_id)"
1216 			" (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1217 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1218 			"       Add port tm leaf node.\n\n"
1219 
1220 			"del port tm node (port_id) (node_id)\n"
1221 			"       Delete port tm node.\n\n"
1222 
1223 			"set port tm node parent (port_id) (node_id) (parent_node_id)"
1224 			" (priority) (weight)\n"
1225 			"       Set port tm node parent.\n\n"
1226 
1227 			"suspend port tm node (port_id) (node_id)"
1228 			"       Suspend tm node.\n\n"
1229 
1230 			"resume port tm node (port_id) (node_id)"
1231 			"       Resume tm node.\n\n"
1232 
1233 			"port tm hierarchy commit (port_id) (clean_on_fail)\n"
1234 			"       Commit tm hierarchy.\n\n"
1235 
1236 			"set port tm mark ip_ecn (port) (green) (yellow)"
1237 			" (red)\n"
1238 			"    Enables/Disables the traffic management marking"
1239 			" for IP ECN (Explicit Congestion Notification)"
1240 			" packets on a given port\n\n"
1241 
1242 			"set port tm mark ip_dscp (port) (green) (yellow)"
1243 			" (red)\n"
1244 			"    Enables/Disables the traffic management marking"
1245 			" on the port for IP dscp packets\n\n"
1246 
1247 			"set port tm mark vlan_dei (port) (green) (yellow)"
1248 			" (red)\n"
1249 			"    Enables/Disables the traffic management marking"
1250 			" on the port for VLAN packets with DEI enabled\n\n"
1251 		);
1252 	}
1253 
1254 	if (show_all || !strcmp(res->section, "devices")) {
1255 		cmdline_printf(
1256 			cl,
1257 			"\n"
1258 			"Device Operations:\n"
1259 			"--------------\n"
1260 			"device detach (identifier)\n"
1261 			"       Detach device by identifier.\n\n"
1262 		);
1263 	}
1264 
1265 }
1266 
1267 cmdline_parse_token_string_t cmd_help_long_help =
1268 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1269 
1270 cmdline_parse_token_string_t cmd_help_long_section =
1271 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1272 			"all#control#display#config#"
1273 			"ports#registers#filters#traffic_management#devices");
1274 
1275 cmdline_parse_inst_t cmd_help_long = {
1276 	.f = cmd_help_long_parsed,
1277 	.data = NULL,
1278 	.help_str = "help all|control|display|config|ports|register|"
1279 		"filters|traffic_management|devices: "
1280 		"Show help",
1281 	.tokens = {
1282 		(void *)&cmd_help_long_help,
1283 		(void *)&cmd_help_long_section,
1284 		NULL,
1285 	},
1286 };
1287 
1288 
1289 /* *** start/stop/close all ports *** */
1290 struct cmd_operate_port_result {
1291 	cmdline_fixed_string_t keyword;
1292 	cmdline_fixed_string_t name;
1293 	cmdline_fixed_string_t value;
1294 };
1295 
1296 static void cmd_operate_port_parsed(void *parsed_result,
1297 				__attribute__((unused)) struct cmdline *cl,
1298 				__attribute__((unused)) void *data)
1299 {
1300 	struct cmd_operate_port_result *res = parsed_result;
1301 
1302 	if (!strcmp(res->name, "start"))
1303 		start_port(RTE_PORT_ALL);
1304 	else if (!strcmp(res->name, "stop"))
1305 		stop_port(RTE_PORT_ALL);
1306 	else if (!strcmp(res->name, "close"))
1307 		close_port(RTE_PORT_ALL);
1308 	else if (!strcmp(res->name, "reset"))
1309 		reset_port(RTE_PORT_ALL);
1310 	else
1311 		printf("Unknown parameter\n");
1312 }
1313 
1314 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1315 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1316 								"port");
1317 cmdline_parse_token_string_t cmd_operate_port_all_port =
1318 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1319 						"start#stop#close#reset");
1320 cmdline_parse_token_string_t cmd_operate_port_all_all =
1321 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1322 
1323 cmdline_parse_inst_t cmd_operate_port = {
1324 	.f = cmd_operate_port_parsed,
1325 	.data = NULL,
1326 	.help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1327 	.tokens = {
1328 		(void *)&cmd_operate_port_all_cmd,
1329 		(void *)&cmd_operate_port_all_port,
1330 		(void *)&cmd_operate_port_all_all,
1331 		NULL,
1332 	},
1333 };
1334 
1335 /* *** start/stop/close specific port *** */
1336 struct cmd_operate_specific_port_result {
1337 	cmdline_fixed_string_t keyword;
1338 	cmdline_fixed_string_t name;
1339 	uint8_t value;
1340 };
1341 
1342 static void cmd_operate_specific_port_parsed(void *parsed_result,
1343 			__attribute__((unused)) struct cmdline *cl,
1344 				__attribute__((unused)) void *data)
1345 {
1346 	struct cmd_operate_specific_port_result *res = parsed_result;
1347 
1348 	if (!strcmp(res->name, "start"))
1349 		start_port(res->value);
1350 	else if (!strcmp(res->name, "stop"))
1351 		stop_port(res->value);
1352 	else if (!strcmp(res->name, "close"))
1353 		close_port(res->value);
1354 	else if (!strcmp(res->name, "reset"))
1355 		reset_port(res->value);
1356 	else
1357 		printf("Unknown parameter\n");
1358 }
1359 
1360 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1361 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1362 							keyword, "port");
1363 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1364 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1365 						name, "start#stop#close#reset");
1366 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1367 	TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1368 							value, UINT8);
1369 
1370 cmdline_parse_inst_t cmd_operate_specific_port = {
1371 	.f = cmd_operate_specific_port_parsed,
1372 	.data = NULL,
1373 	.help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1374 	.tokens = {
1375 		(void *)&cmd_operate_specific_port_cmd,
1376 		(void *)&cmd_operate_specific_port_port,
1377 		(void *)&cmd_operate_specific_port_id,
1378 		NULL,
1379 	},
1380 };
1381 
1382 /* *** enable port setup (after attach) via iterator or event *** */
1383 struct cmd_set_port_setup_on_result {
1384 	cmdline_fixed_string_t set;
1385 	cmdline_fixed_string_t port;
1386 	cmdline_fixed_string_t setup;
1387 	cmdline_fixed_string_t on;
1388 	cmdline_fixed_string_t mode;
1389 };
1390 
1391 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1392 				__attribute__((unused)) struct cmdline *cl,
1393 				__attribute__((unused)) void *data)
1394 {
1395 	struct cmd_set_port_setup_on_result *res = parsed_result;
1396 
1397 	if (strcmp(res->mode, "event") == 0)
1398 		setup_on_probe_event = true;
1399 	else if (strcmp(res->mode, "iterator") == 0)
1400 		setup_on_probe_event = false;
1401 	else
1402 		printf("Unknown mode\n");
1403 }
1404 
1405 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1406 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1407 			set, "set");
1408 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1409 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1410 			port, "port");
1411 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1412 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1413 			setup, "setup");
1414 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1415 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1416 			on, "on");
1417 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1418 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1419 			mode, "iterator#event");
1420 
1421 cmdline_parse_inst_t cmd_set_port_setup_on = {
1422 	.f = cmd_set_port_setup_on_parsed,
1423 	.data = NULL,
1424 	.help_str = "set port setup on iterator|event",
1425 	.tokens = {
1426 		(void *)&cmd_set_port_setup_on_set,
1427 		(void *)&cmd_set_port_setup_on_port,
1428 		(void *)&cmd_set_port_setup_on_setup,
1429 		(void *)&cmd_set_port_setup_on_on,
1430 		(void *)&cmd_set_port_setup_on_mode,
1431 		NULL,
1432 	},
1433 };
1434 
1435 /* *** attach a specified port *** */
1436 struct cmd_operate_attach_port_result {
1437 	cmdline_fixed_string_t port;
1438 	cmdline_fixed_string_t keyword;
1439 	cmdline_fixed_string_t identifier;
1440 };
1441 
1442 static void cmd_operate_attach_port_parsed(void *parsed_result,
1443 				__attribute__((unused)) struct cmdline *cl,
1444 				__attribute__((unused)) void *data)
1445 {
1446 	struct cmd_operate_attach_port_result *res = parsed_result;
1447 
1448 	if (!strcmp(res->keyword, "attach"))
1449 		attach_port(res->identifier);
1450 	else
1451 		printf("Unknown parameter\n");
1452 }
1453 
1454 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1455 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1456 			port, "port");
1457 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1458 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1459 			keyword, "attach");
1460 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1461 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1462 			identifier, NULL);
1463 
1464 cmdline_parse_inst_t cmd_operate_attach_port = {
1465 	.f = cmd_operate_attach_port_parsed,
1466 	.data = NULL,
1467 	.help_str = "port attach <identifier>: "
1468 		"(identifier: pci address or virtual dev name)",
1469 	.tokens = {
1470 		(void *)&cmd_operate_attach_port_port,
1471 		(void *)&cmd_operate_attach_port_keyword,
1472 		(void *)&cmd_operate_attach_port_identifier,
1473 		NULL,
1474 	},
1475 };
1476 
1477 /* *** detach a specified port *** */
1478 struct cmd_operate_detach_port_result {
1479 	cmdline_fixed_string_t port;
1480 	cmdline_fixed_string_t keyword;
1481 	portid_t port_id;
1482 };
1483 
1484 static void cmd_operate_detach_port_parsed(void *parsed_result,
1485 				__attribute__((unused)) struct cmdline *cl,
1486 				__attribute__((unused)) void *data)
1487 {
1488 	struct cmd_operate_detach_port_result *res = parsed_result;
1489 
1490 	if (!strcmp(res->keyword, "detach"))
1491 		detach_port_device(res->port_id);
1492 	else
1493 		printf("Unknown parameter\n");
1494 }
1495 
1496 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1497 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1498 			port, "port");
1499 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1500 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1501 			keyword, "detach");
1502 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1503 	TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1504 			port_id, UINT16);
1505 
1506 cmdline_parse_inst_t cmd_operate_detach_port = {
1507 	.f = cmd_operate_detach_port_parsed,
1508 	.data = NULL,
1509 	.help_str = "port detach <port_id>",
1510 	.tokens = {
1511 		(void *)&cmd_operate_detach_port_port,
1512 		(void *)&cmd_operate_detach_port_keyword,
1513 		(void *)&cmd_operate_detach_port_port_id,
1514 		NULL,
1515 	},
1516 };
1517 
1518 /* *** detach device by identifier *** */
1519 struct cmd_operate_detach_device_result {
1520 	cmdline_fixed_string_t device;
1521 	cmdline_fixed_string_t keyword;
1522 	cmdline_fixed_string_t identifier;
1523 };
1524 
1525 static void cmd_operate_detach_device_parsed(void *parsed_result,
1526 				__attribute__((unused)) struct cmdline *cl,
1527 				__attribute__((unused)) void *data)
1528 {
1529 	struct cmd_operate_detach_device_result *res = parsed_result;
1530 
1531 	if (!strcmp(res->keyword, "detach"))
1532 		detach_device(res->identifier);
1533 	else
1534 		printf("Unknown parameter\n");
1535 }
1536 
1537 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1538 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1539 			device, "device");
1540 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1541 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1542 			keyword, "detach");
1543 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1544 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1545 			identifier, NULL);
1546 
1547 cmdline_parse_inst_t cmd_operate_detach_device = {
1548 	.f = cmd_operate_detach_device_parsed,
1549 	.data = NULL,
1550 	.help_str = "device detach <identifier>:"
1551 		"(identifier: pci address or virtual dev name)",
1552 	.tokens = {
1553 		(void *)&cmd_operate_detach_device_device,
1554 		(void *)&cmd_operate_detach_device_keyword,
1555 		(void *)&cmd_operate_detach_device_identifier,
1556 		NULL,
1557 	},
1558 };
1559 /* *** configure speed for all ports *** */
1560 struct cmd_config_speed_all {
1561 	cmdline_fixed_string_t port;
1562 	cmdline_fixed_string_t keyword;
1563 	cmdline_fixed_string_t all;
1564 	cmdline_fixed_string_t item1;
1565 	cmdline_fixed_string_t item2;
1566 	cmdline_fixed_string_t value1;
1567 	cmdline_fixed_string_t value2;
1568 };
1569 
1570 static int
1571 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1572 {
1573 
1574 	int duplex;
1575 
1576 	if (!strcmp(duplexstr, "half")) {
1577 		duplex = ETH_LINK_HALF_DUPLEX;
1578 	} else if (!strcmp(duplexstr, "full")) {
1579 		duplex = ETH_LINK_FULL_DUPLEX;
1580 	} else if (!strcmp(duplexstr, "auto")) {
1581 		duplex = ETH_LINK_FULL_DUPLEX;
1582 	} else {
1583 		printf("Unknown duplex parameter\n");
1584 		return -1;
1585 	}
1586 
1587 	if (!strcmp(speedstr, "10")) {
1588 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1589 				ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1590 	} else if (!strcmp(speedstr, "100")) {
1591 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1592 				ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1593 	} else {
1594 		if (duplex != ETH_LINK_FULL_DUPLEX) {
1595 			printf("Invalid speed/duplex parameters\n");
1596 			return -1;
1597 		}
1598 		if (!strcmp(speedstr, "1000")) {
1599 			*speed = ETH_LINK_SPEED_1G;
1600 		} else if (!strcmp(speedstr, "10000")) {
1601 			*speed = ETH_LINK_SPEED_10G;
1602 		} else if (!strcmp(speedstr, "25000")) {
1603 			*speed = ETH_LINK_SPEED_25G;
1604 		} else if (!strcmp(speedstr, "40000")) {
1605 			*speed = ETH_LINK_SPEED_40G;
1606 		} else if (!strcmp(speedstr, "50000")) {
1607 			*speed = ETH_LINK_SPEED_50G;
1608 		} else if (!strcmp(speedstr, "100000")) {
1609 			*speed = ETH_LINK_SPEED_100G;
1610 		} else if (!strcmp(speedstr, "auto")) {
1611 			*speed = ETH_LINK_SPEED_AUTONEG;
1612 		} else {
1613 			printf("Unknown speed parameter\n");
1614 			return -1;
1615 		}
1616 	}
1617 
1618 	return 0;
1619 }
1620 
1621 static void
1622 cmd_config_speed_all_parsed(void *parsed_result,
1623 			__attribute__((unused)) struct cmdline *cl,
1624 			__attribute__((unused)) void *data)
1625 {
1626 	struct cmd_config_speed_all *res = parsed_result;
1627 	uint32_t link_speed;
1628 	portid_t pid;
1629 
1630 	if (!all_ports_stopped()) {
1631 		printf("Please stop all ports first\n");
1632 		return;
1633 	}
1634 
1635 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1636 			&link_speed) < 0)
1637 		return;
1638 
1639 	RTE_ETH_FOREACH_DEV(pid) {
1640 		ports[pid].dev_conf.link_speeds = link_speed;
1641 	}
1642 
1643 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1644 }
1645 
1646 cmdline_parse_token_string_t cmd_config_speed_all_port =
1647 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1648 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1649 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1650 							"config");
1651 cmdline_parse_token_string_t cmd_config_speed_all_all =
1652 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1653 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1654 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1655 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1656 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1657 				"10#100#1000#10000#25000#40000#50000#100000#auto");
1658 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1659 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1660 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1661 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1662 						"half#full#auto");
1663 
1664 cmdline_parse_inst_t cmd_config_speed_all = {
1665 	.f = cmd_config_speed_all_parsed,
1666 	.data = NULL,
1667 	.help_str = "port config all speed "
1668 		"10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1669 							"half|full|auto",
1670 	.tokens = {
1671 		(void *)&cmd_config_speed_all_port,
1672 		(void *)&cmd_config_speed_all_keyword,
1673 		(void *)&cmd_config_speed_all_all,
1674 		(void *)&cmd_config_speed_all_item1,
1675 		(void *)&cmd_config_speed_all_value1,
1676 		(void *)&cmd_config_speed_all_item2,
1677 		(void *)&cmd_config_speed_all_value2,
1678 		NULL,
1679 	},
1680 };
1681 
1682 /* *** configure speed for specific port *** */
1683 struct cmd_config_speed_specific {
1684 	cmdline_fixed_string_t port;
1685 	cmdline_fixed_string_t keyword;
1686 	portid_t id;
1687 	cmdline_fixed_string_t item1;
1688 	cmdline_fixed_string_t item2;
1689 	cmdline_fixed_string_t value1;
1690 	cmdline_fixed_string_t value2;
1691 };
1692 
1693 static void
1694 cmd_config_speed_specific_parsed(void *parsed_result,
1695 				__attribute__((unused)) struct cmdline *cl,
1696 				__attribute__((unused)) void *data)
1697 {
1698 	struct cmd_config_speed_specific *res = parsed_result;
1699 	uint32_t link_speed;
1700 
1701 	if (!all_ports_stopped()) {
1702 		printf("Please stop all ports first\n");
1703 		return;
1704 	}
1705 
1706 	if (port_id_is_invalid(res->id, ENABLED_WARN))
1707 		return;
1708 
1709 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1710 			&link_speed) < 0)
1711 		return;
1712 
1713 	ports[res->id].dev_conf.link_speeds = link_speed;
1714 
1715 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1716 }
1717 
1718 
1719 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1720 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1721 								"port");
1722 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1723 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1724 								"config");
1725 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1726 	TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1727 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1728 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1729 								"speed");
1730 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1731 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1732 				"10#100#1000#10000#25000#40000#50000#100000#auto");
1733 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1734 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1735 								"duplex");
1736 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1737 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1738 							"half#full#auto");
1739 
1740 cmdline_parse_inst_t cmd_config_speed_specific = {
1741 	.f = cmd_config_speed_specific_parsed,
1742 	.data = NULL,
1743 	.help_str = "port config <port_id> speed "
1744 		"10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1745 							"half|full|auto",
1746 	.tokens = {
1747 		(void *)&cmd_config_speed_specific_port,
1748 		(void *)&cmd_config_speed_specific_keyword,
1749 		(void *)&cmd_config_speed_specific_id,
1750 		(void *)&cmd_config_speed_specific_item1,
1751 		(void *)&cmd_config_speed_specific_value1,
1752 		(void *)&cmd_config_speed_specific_item2,
1753 		(void *)&cmd_config_speed_specific_value2,
1754 		NULL,
1755 	},
1756 };
1757 
1758 /* *** configure loopback for all ports *** */
1759 struct cmd_config_loopback_all {
1760 	cmdline_fixed_string_t port;
1761 	cmdline_fixed_string_t keyword;
1762 	cmdline_fixed_string_t all;
1763 	cmdline_fixed_string_t item;
1764 	uint32_t mode;
1765 };
1766 
1767 static void
1768 cmd_config_loopback_all_parsed(void *parsed_result,
1769 			__attribute__((unused)) struct cmdline *cl,
1770 			__attribute__((unused)) void *data)
1771 {
1772 	struct cmd_config_loopback_all *res = parsed_result;
1773 	portid_t pid;
1774 
1775 	if (!all_ports_stopped()) {
1776 		printf("Please stop all ports first\n");
1777 		return;
1778 	}
1779 
1780 	RTE_ETH_FOREACH_DEV(pid) {
1781 		ports[pid].dev_conf.lpbk_mode = res->mode;
1782 	}
1783 
1784 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1785 }
1786 
1787 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1788 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1789 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1790 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1791 							"config");
1792 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1793 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1794 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1795 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1796 							"loopback");
1797 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1798 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1799 
1800 cmdline_parse_inst_t cmd_config_loopback_all = {
1801 	.f = cmd_config_loopback_all_parsed,
1802 	.data = NULL,
1803 	.help_str = "port config all loopback <mode>",
1804 	.tokens = {
1805 		(void *)&cmd_config_loopback_all_port,
1806 		(void *)&cmd_config_loopback_all_keyword,
1807 		(void *)&cmd_config_loopback_all_all,
1808 		(void *)&cmd_config_loopback_all_item,
1809 		(void *)&cmd_config_loopback_all_mode,
1810 		NULL,
1811 	},
1812 };
1813 
1814 /* *** configure loopback for specific port *** */
1815 struct cmd_config_loopback_specific {
1816 	cmdline_fixed_string_t port;
1817 	cmdline_fixed_string_t keyword;
1818 	uint16_t port_id;
1819 	cmdline_fixed_string_t item;
1820 	uint32_t mode;
1821 };
1822 
1823 static void
1824 cmd_config_loopback_specific_parsed(void *parsed_result,
1825 				__attribute__((unused)) struct cmdline *cl,
1826 				__attribute__((unused)) void *data)
1827 {
1828 	struct cmd_config_loopback_specific *res = parsed_result;
1829 
1830 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1831 		return;
1832 
1833 	if (!port_is_stopped(res->port_id)) {
1834 		printf("Please stop port %u first\n", res->port_id);
1835 		return;
1836 	}
1837 
1838 	ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1839 
1840 	cmd_reconfig_device_queue(res->port_id, 1, 1);
1841 }
1842 
1843 
1844 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1845 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1846 								"port");
1847 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1848 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1849 								"config");
1850 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1851 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1852 								UINT16);
1853 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1854 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1855 								"loopback");
1856 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1857 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1858 			      UINT32);
1859 
1860 cmdline_parse_inst_t cmd_config_loopback_specific = {
1861 	.f = cmd_config_loopback_specific_parsed,
1862 	.data = NULL,
1863 	.help_str = "port config <port_id> loopback <mode>",
1864 	.tokens = {
1865 		(void *)&cmd_config_loopback_specific_port,
1866 		(void *)&cmd_config_loopback_specific_keyword,
1867 		(void *)&cmd_config_loopback_specific_id,
1868 		(void *)&cmd_config_loopback_specific_item,
1869 		(void *)&cmd_config_loopback_specific_mode,
1870 		NULL,
1871 	},
1872 };
1873 
1874 /* *** configure txq/rxq, txd/rxd *** */
1875 struct cmd_config_rx_tx {
1876 	cmdline_fixed_string_t port;
1877 	cmdline_fixed_string_t keyword;
1878 	cmdline_fixed_string_t all;
1879 	cmdline_fixed_string_t name;
1880 	uint16_t value;
1881 };
1882 
1883 static void
1884 cmd_config_rx_tx_parsed(void *parsed_result,
1885 			__attribute__((unused)) struct cmdline *cl,
1886 			__attribute__((unused)) void *data)
1887 {
1888 	struct cmd_config_rx_tx *res = parsed_result;
1889 
1890 	if (!all_ports_stopped()) {
1891 		printf("Please stop all ports first\n");
1892 		return;
1893 	}
1894 	if (!strcmp(res->name, "rxq")) {
1895 		if (!res->value && !nb_txq) {
1896 			printf("Warning: Either rx or tx queues should be non zero\n");
1897 			return;
1898 		}
1899 		if (check_nb_rxq(res->value) != 0)
1900 			return;
1901 		nb_rxq = res->value;
1902 	}
1903 	else if (!strcmp(res->name, "txq")) {
1904 		if (!res->value && !nb_rxq) {
1905 			printf("Warning: Either rx or tx queues should be non zero\n");
1906 			return;
1907 		}
1908 		if (check_nb_txq(res->value) != 0)
1909 			return;
1910 		nb_txq = res->value;
1911 	}
1912 	else if (!strcmp(res->name, "rxd")) {
1913 		if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1914 			printf("rxd %d invalid - must be > 0 && <= %d\n",
1915 					res->value, RTE_TEST_RX_DESC_MAX);
1916 			return;
1917 		}
1918 		nb_rxd = res->value;
1919 	} else if (!strcmp(res->name, "txd")) {
1920 		if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1921 			printf("txd %d invalid - must be > 0 && <= %d\n",
1922 					res->value, RTE_TEST_TX_DESC_MAX);
1923 			return;
1924 		}
1925 		nb_txd = res->value;
1926 	} else {
1927 		printf("Unknown parameter\n");
1928 		return;
1929 	}
1930 
1931 	fwd_config_setup();
1932 
1933 	init_port_config();
1934 
1935 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1936 }
1937 
1938 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1939 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1940 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1941 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1942 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1943 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1944 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1945 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1946 						"rxq#txq#rxd#txd");
1947 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1948 	TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1949 
1950 cmdline_parse_inst_t cmd_config_rx_tx = {
1951 	.f = cmd_config_rx_tx_parsed,
1952 	.data = NULL,
1953 	.help_str = "port config all rxq|txq|rxd|txd <value>",
1954 	.tokens = {
1955 		(void *)&cmd_config_rx_tx_port,
1956 		(void *)&cmd_config_rx_tx_keyword,
1957 		(void *)&cmd_config_rx_tx_all,
1958 		(void *)&cmd_config_rx_tx_name,
1959 		(void *)&cmd_config_rx_tx_value,
1960 		NULL,
1961 	},
1962 };
1963 
1964 /* *** config max packet length *** */
1965 struct cmd_config_max_pkt_len_result {
1966 	cmdline_fixed_string_t port;
1967 	cmdline_fixed_string_t keyword;
1968 	cmdline_fixed_string_t all;
1969 	cmdline_fixed_string_t name;
1970 	uint32_t value;
1971 };
1972 
1973 static void
1974 cmd_config_max_pkt_len_parsed(void *parsed_result,
1975 				__attribute__((unused)) struct cmdline *cl,
1976 				__attribute__((unused)) void *data)
1977 {
1978 	struct cmd_config_max_pkt_len_result *res = parsed_result;
1979 	portid_t pid;
1980 
1981 	if (!all_ports_stopped()) {
1982 		printf("Please stop all ports first\n");
1983 		return;
1984 	}
1985 
1986 	RTE_ETH_FOREACH_DEV(pid) {
1987 		struct rte_port *port = &ports[pid];
1988 		uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1989 
1990 		if (!strcmp(res->name, "max-pkt-len")) {
1991 			if (res->value < RTE_ETHER_MIN_LEN) {
1992 				printf("max-pkt-len can not be less than %d\n",
1993 						RTE_ETHER_MIN_LEN);
1994 				return;
1995 			}
1996 			if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1997 				return;
1998 
1999 			port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2000 			if (res->value > RTE_ETHER_MAX_LEN)
2001 				rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2002 			else
2003 				rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2004 			port->dev_conf.rxmode.offloads = rx_offloads;
2005 		} else {
2006 			printf("Unknown parameter\n");
2007 			return;
2008 		}
2009 	}
2010 
2011 	init_port_config();
2012 
2013 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2014 }
2015 
2016 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2017 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2018 								"port");
2019 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2020 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2021 								"config");
2022 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2023 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2024 								"all");
2025 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2026 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2027 								"max-pkt-len");
2028 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2029 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2030 								UINT32);
2031 
2032 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2033 	.f = cmd_config_max_pkt_len_parsed,
2034 	.data = NULL,
2035 	.help_str = "port config all max-pkt-len <value>",
2036 	.tokens = {
2037 		(void *)&cmd_config_max_pkt_len_port,
2038 		(void *)&cmd_config_max_pkt_len_keyword,
2039 		(void *)&cmd_config_max_pkt_len_all,
2040 		(void *)&cmd_config_max_pkt_len_name,
2041 		(void *)&cmd_config_max_pkt_len_value,
2042 		NULL,
2043 	},
2044 };
2045 
2046 /* *** configure port MTU *** */
2047 struct cmd_config_mtu_result {
2048 	cmdline_fixed_string_t port;
2049 	cmdline_fixed_string_t keyword;
2050 	cmdline_fixed_string_t mtu;
2051 	portid_t port_id;
2052 	uint16_t value;
2053 };
2054 
2055 static void
2056 cmd_config_mtu_parsed(void *parsed_result,
2057 		      __attribute__((unused)) struct cmdline *cl,
2058 		      __attribute__((unused)) void *data)
2059 {
2060 	struct cmd_config_mtu_result *res = parsed_result;
2061 
2062 	if (res->value < RTE_ETHER_MIN_LEN) {
2063 		printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2064 		return;
2065 	}
2066 	port_mtu_set(res->port_id, res->value);
2067 }
2068 
2069 cmdline_parse_token_string_t cmd_config_mtu_port =
2070 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2071 				 "port");
2072 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2073 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2074 				 "config");
2075 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2076 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2077 				 "mtu");
2078 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2079 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2080 cmdline_parse_token_num_t cmd_config_mtu_value =
2081 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2082 
2083 cmdline_parse_inst_t cmd_config_mtu = {
2084 	.f = cmd_config_mtu_parsed,
2085 	.data = NULL,
2086 	.help_str = "port config mtu <port_id> <value>",
2087 	.tokens = {
2088 		(void *)&cmd_config_mtu_port,
2089 		(void *)&cmd_config_mtu_keyword,
2090 		(void *)&cmd_config_mtu_mtu,
2091 		(void *)&cmd_config_mtu_port_id,
2092 		(void *)&cmd_config_mtu_value,
2093 		NULL,
2094 	},
2095 };
2096 
2097 /* *** configure rx mode *** */
2098 struct cmd_config_rx_mode_flag {
2099 	cmdline_fixed_string_t port;
2100 	cmdline_fixed_string_t keyword;
2101 	cmdline_fixed_string_t all;
2102 	cmdline_fixed_string_t name;
2103 	cmdline_fixed_string_t value;
2104 };
2105 
2106 static void
2107 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2108 				__attribute__((unused)) struct cmdline *cl,
2109 				__attribute__((unused)) void *data)
2110 {
2111 	struct cmd_config_rx_mode_flag *res = parsed_result;
2112 	portid_t pid;
2113 	int k;
2114 
2115 	if (!all_ports_stopped()) {
2116 		printf("Please stop all ports first\n");
2117 		return;
2118 	}
2119 
2120 	RTE_ETH_FOREACH_DEV(pid) {
2121 		struct rte_port *port;
2122 		uint64_t rx_offloads;
2123 
2124 		port = &ports[pid];
2125 		rx_offloads = port->dev_conf.rxmode.offloads;
2126 		if (!strcmp(res->name, "crc-strip")) {
2127 			if (!strcmp(res->value, "on")) {
2128 				rx_offloads &= ~DEV_RX_OFFLOAD_KEEP_CRC;
2129 			} else if (!strcmp(res->value, "off")) {
2130 				rx_offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
2131 			} else {
2132 				printf("Unknown parameter\n");
2133 				return;
2134 			}
2135 		} else if (!strcmp(res->name, "scatter")) {
2136 			if (!strcmp(res->value, "on")) {
2137 				rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
2138 			} else if (!strcmp(res->value, "off")) {
2139 				rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
2140 			} else {
2141 				printf("Unknown parameter\n");
2142 				return;
2143 			}
2144 		} else if (!strcmp(res->name, "rx-cksum")) {
2145 			if (!strcmp(res->value, "on"))
2146 				rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
2147 			else if (!strcmp(res->value, "off"))
2148 				rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
2149 			else {
2150 				printf("Unknown parameter\n");
2151 				return;
2152 			}
2153 		} else if (!strcmp(res->name, "rx-timestamp")) {
2154 			if (!strcmp(res->value, "on"))
2155 				rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
2156 			else if (!strcmp(res->value, "off"))
2157 				rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
2158 			else {
2159 				printf("Unknown parameter\n");
2160 				return;
2161 			}
2162 		} else if (!strcmp(res->name, "hw-vlan")) {
2163 			if (!strcmp(res->value, "on")) {
2164 				rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
2165 						DEV_RX_OFFLOAD_VLAN_STRIP);
2166 			} else if (!strcmp(res->value, "off")) {
2167 				rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
2168 						DEV_RX_OFFLOAD_VLAN_STRIP);
2169 			} else {
2170 				printf("Unknown parameter\n");
2171 				return;
2172 			}
2173 		} else if (!strcmp(res->name, "hw-vlan-filter")) {
2174 			if (!strcmp(res->value, "on"))
2175 				rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2176 			else if (!strcmp(res->value, "off"))
2177 				rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
2178 			else {
2179 				printf("Unknown parameter\n");
2180 				return;
2181 			}
2182 		} else if (!strcmp(res->name, "hw-vlan-strip")) {
2183 			if (!strcmp(res->value, "on"))
2184 				rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
2185 			else if (!strcmp(res->value, "off"))
2186 				rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
2187 			else {
2188 				printf("Unknown parameter\n");
2189 				return;
2190 			}
2191 		} else if (!strcmp(res->name, "hw-vlan-extend")) {
2192 			if (!strcmp(res->value, "on"))
2193 				rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
2194 			else if (!strcmp(res->value, "off"))
2195 				rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2196 			else {
2197 				printf("Unknown parameter\n");
2198 				return;
2199 			}
2200 		} else if (!strcmp(res->name, "drop-en")) {
2201 			if (!strcmp(res->value, "on"))
2202 				rx_drop_en = 1;
2203 			else if (!strcmp(res->value, "off"))
2204 				rx_drop_en = 0;
2205 			else {
2206 				printf("Unknown parameter\n");
2207 				return;
2208 			}
2209 		} else {
2210 			printf("Unknown parameter\n");
2211 			return;
2212 		}
2213 		port->dev_conf.rxmode.offloads = rx_offloads;
2214 		/* Apply Rx offloads configuration */
2215 		for (k = 0; k < port->dev_info.max_rx_queues; k++)
2216 			port->rx_conf[k].offloads =
2217 				port->dev_conf.rxmode.offloads;
2218 	}
2219 
2220 	init_port_config();
2221 
2222 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2223 }
2224 
2225 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2226 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2227 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2228 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2229 								"config");
2230 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2231 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2232 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2233 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2234 					"crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
2235 					"hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
2236 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2237 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2238 							"on#off");
2239 
2240 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2241 	.f = cmd_config_rx_mode_flag_parsed,
2242 	.data = NULL,
2243 	.help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
2244 		"hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
2245 	.tokens = {
2246 		(void *)&cmd_config_rx_mode_flag_port,
2247 		(void *)&cmd_config_rx_mode_flag_keyword,
2248 		(void *)&cmd_config_rx_mode_flag_all,
2249 		(void *)&cmd_config_rx_mode_flag_name,
2250 		(void *)&cmd_config_rx_mode_flag_value,
2251 		NULL,
2252 	},
2253 };
2254 
2255 /* *** configure rss *** */
2256 struct cmd_config_rss {
2257 	cmdline_fixed_string_t port;
2258 	cmdline_fixed_string_t keyword;
2259 	cmdline_fixed_string_t all;
2260 	cmdline_fixed_string_t name;
2261 	cmdline_fixed_string_t value;
2262 };
2263 
2264 static void
2265 cmd_config_rss_parsed(void *parsed_result,
2266 			__attribute__((unused)) struct cmdline *cl,
2267 			__attribute__((unused)) void *data)
2268 {
2269 	struct cmd_config_rss *res = parsed_result;
2270 	struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2271 	struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2272 	int use_default = 0;
2273 	int all_updated = 1;
2274 	int diag;
2275 	uint16_t i;
2276 
2277 	if (!strcmp(res->value, "all"))
2278 		rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2279 				ETH_RSS_UDP | ETH_RSS_SCTP |
2280 					ETH_RSS_L2_PAYLOAD;
2281 	else if (!strcmp(res->value, "ip"))
2282 		rss_conf.rss_hf = ETH_RSS_IP;
2283 	else if (!strcmp(res->value, "udp"))
2284 		rss_conf.rss_hf = ETH_RSS_UDP;
2285 	else if (!strcmp(res->value, "tcp"))
2286 		rss_conf.rss_hf = ETH_RSS_TCP;
2287 	else if (!strcmp(res->value, "sctp"))
2288 		rss_conf.rss_hf = ETH_RSS_SCTP;
2289 	else if (!strcmp(res->value, "ether"))
2290 		rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2291 	else if (!strcmp(res->value, "port"))
2292 		rss_conf.rss_hf = ETH_RSS_PORT;
2293 	else if (!strcmp(res->value, "vxlan"))
2294 		rss_conf.rss_hf = ETH_RSS_VXLAN;
2295 	else if (!strcmp(res->value, "geneve"))
2296 		rss_conf.rss_hf = ETH_RSS_GENEVE;
2297 	else if (!strcmp(res->value, "nvgre"))
2298 		rss_conf.rss_hf = ETH_RSS_NVGRE;
2299 	else if (!strcmp(res->value, "none"))
2300 		rss_conf.rss_hf = 0;
2301 	else if (!strcmp(res->value, "default"))
2302 		use_default = 1;
2303 	else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2304 						atoi(res->value) < 64)
2305 		rss_conf.rss_hf = 1ULL << atoi(res->value);
2306 	else {
2307 		printf("Unknown parameter\n");
2308 		return;
2309 	}
2310 	rss_conf.rss_key = NULL;
2311 	/* Update global configuration for RSS types. */
2312 	RTE_ETH_FOREACH_DEV(i) {
2313 		struct rte_eth_rss_conf local_rss_conf;
2314 
2315 		rte_eth_dev_info_get(i, &dev_info);
2316 		if (use_default)
2317 			rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2318 
2319 		local_rss_conf = rss_conf;
2320 		local_rss_conf.rss_hf = rss_conf.rss_hf &
2321 			dev_info.flow_type_rss_offloads;
2322 		if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2323 			printf("Port %u modified RSS hash function based on hardware support,"
2324 				"requested:%#"PRIx64" configured:%#"PRIx64"\n",
2325 				i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2326 		}
2327 		diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2328 		if (diag < 0) {
2329 			all_updated = 0;
2330 			printf("Configuration of RSS hash at ethernet port %d "
2331 				"failed with error (%d): %s.\n",
2332 				i, -diag, strerror(-diag));
2333 		}
2334 	}
2335 	if (all_updated && !use_default)
2336 		rss_hf = rss_conf.rss_hf;
2337 }
2338 
2339 cmdline_parse_token_string_t cmd_config_rss_port =
2340 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2341 cmdline_parse_token_string_t cmd_config_rss_keyword =
2342 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2343 cmdline_parse_token_string_t cmd_config_rss_all =
2344 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2345 cmdline_parse_token_string_t cmd_config_rss_name =
2346 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2347 cmdline_parse_token_string_t cmd_config_rss_value =
2348 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2349 
2350 cmdline_parse_inst_t cmd_config_rss = {
2351 	.f = cmd_config_rss_parsed,
2352 	.data = NULL,
2353 	.help_str = "port config all rss "
2354 		"all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2355 	.tokens = {
2356 		(void *)&cmd_config_rss_port,
2357 		(void *)&cmd_config_rss_keyword,
2358 		(void *)&cmd_config_rss_all,
2359 		(void *)&cmd_config_rss_name,
2360 		(void *)&cmd_config_rss_value,
2361 		NULL,
2362 	},
2363 };
2364 
2365 /* *** configure rss hash key *** */
2366 struct cmd_config_rss_hash_key {
2367 	cmdline_fixed_string_t port;
2368 	cmdline_fixed_string_t config;
2369 	portid_t port_id;
2370 	cmdline_fixed_string_t rss_hash_key;
2371 	cmdline_fixed_string_t rss_type;
2372 	cmdline_fixed_string_t key;
2373 };
2374 
2375 static uint8_t
2376 hexa_digit_to_value(char hexa_digit)
2377 {
2378 	if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2379 		return (uint8_t) (hexa_digit - '0');
2380 	if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2381 		return (uint8_t) ((hexa_digit - 'a') + 10);
2382 	if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2383 		return (uint8_t) ((hexa_digit - 'A') + 10);
2384 	/* Invalid hexa digit */
2385 	return 0xFF;
2386 }
2387 
2388 static uint8_t
2389 parse_and_check_key_hexa_digit(char *key, int idx)
2390 {
2391 	uint8_t hexa_v;
2392 
2393 	hexa_v = hexa_digit_to_value(key[idx]);
2394 	if (hexa_v == 0xFF)
2395 		printf("invalid key: character %c at position %d is not a "
2396 		       "valid hexa digit\n", key[idx], idx);
2397 	return hexa_v;
2398 }
2399 
2400 static void
2401 cmd_config_rss_hash_key_parsed(void *parsed_result,
2402 			       __attribute__((unused)) struct cmdline *cl,
2403 			       __attribute__((unused)) void *data)
2404 {
2405 	struct cmd_config_rss_hash_key *res = parsed_result;
2406 	uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2407 	uint8_t xdgt0;
2408 	uint8_t xdgt1;
2409 	int i;
2410 	struct rte_eth_dev_info dev_info;
2411 	uint8_t hash_key_size;
2412 	uint32_t key_len;
2413 
2414 	memset(&dev_info, 0, sizeof(dev_info));
2415 	rte_eth_dev_info_get(res->port_id, &dev_info);
2416 	if (dev_info.hash_key_size > 0 &&
2417 			dev_info.hash_key_size <= sizeof(hash_key))
2418 		hash_key_size = dev_info.hash_key_size;
2419 	else {
2420 		printf("dev_info did not provide a valid hash key size\n");
2421 		return;
2422 	}
2423 	/* Check the length of the RSS hash key */
2424 	key_len = strlen(res->key);
2425 	if (key_len != (hash_key_size * 2)) {
2426 		printf("key length: %d invalid - key must be a string of %d"
2427 			   " hexa-decimal numbers\n",
2428 			   (int) key_len, hash_key_size * 2);
2429 		return;
2430 	}
2431 	/* Translate RSS hash key into binary representation */
2432 	for (i = 0; i < hash_key_size; i++) {
2433 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2434 		if (xdgt0 == 0xFF)
2435 			return;
2436 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2437 		if (xdgt1 == 0xFF)
2438 			return;
2439 		hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2440 	}
2441 	port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2442 			hash_key_size);
2443 }
2444 
2445 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2446 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2447 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2448 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2449 				 "config");
2450 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2451 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2452 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2453 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2454 				 rss_hash_key, "rss-hash-key");
2455 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2456 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2457 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2458 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2459 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2460 				 "ipv6-tcp-ex#ipv6-udp-ex");
2461 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2462 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2463 
2464 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2465 	.f = cmd_config_rss_hash_key_parsed,
2466 	.data = NULL,
2467 	.help_str = "port config <port_id> rss-hash-key "
2468 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2469 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2470 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2471 		"<string of hex digits (variable length, NIC dependent)>",
2472 	.tokens = {
2473 		(void *)&cmd_config_rss_hash_key_port,
2474 		(void *)&cmd_config_rss_hash_key_config,
2475 		(void *)&cmd_config_rss_hash_key_port_id,
2476 		(void *)&cmd_config_rss_hash_key_rss_hash_key,
2477 		(void *)&cmd_config_rss_hash_key_rss_type,
2478 		(void *)&cmd_config_rss_hash_key_value,
2479 		NULL,
2480 	},
2481 };
2482 
2483 /* *** configure port rxq/txq ring size *** */
2484 struct cmd_config_rxtx_ring_size {
2485 	cmdline_fixed_string_t port;
2486 	cmdline_fixed_string_t config;
2487 	portid_t portid;
2488 	cmdline_fixed_string_t rxtxq;
2489 	uint16_t qid;
2490 	cmdline_fixed_string_t rsize;
2491 	uint16_t size;
2492 };
2493 
2494 static void
2495 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2496 				 __attribute__((unused)) struct cmdline *cl,
2497 				 __attribute__((unused)) void *data)
2498 {
2499 	struct cmd_config_rxtx_ring_size *res = parsed_result;
2500 	struct rte_port *port;
2501 	uint8_t isrx;
2502 
2503 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2504 		return;
2505 
2506 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2507 		printf("Invalid port id\n");
2508 		return;
2509 	}
2510 
2511 	port = &ports[res->portid];
2512 
2513 	if (!strcmp(res->rxtxq, "rxq"))
2514 		isrx = 1;
2515 	else if (!strcmp(res->rxtxq, "txq"))
2516 		isrx = 0;
2517 	else {
2518 		printf("Unknown parameter\n");
2519 		return;
2520 	}
2521 
2522 	if (isrx && rx_queue_id_is_invalid(res->qid))
2523 		return;
2524 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2525 		return;
2526 
2527 	if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2528 		printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2529 		       rx_free_thresh);
2530 		return;
2531 	}
2532 
2533 	if (isrx)
2534 		port->nb_rx_desc[res->qid] = res->size;
2535 	else
2536 		port->nb_tx_desc[res->qid] = res->size;
2537 
2538 	cmd_reconfig_device_queue(res->portid, 0, 1);
2539 }
2540 
2541 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2542 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2543 				 port, "port");
2544 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2545 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2546 				 config, "config");
2547 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2548 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2549 				 portid, UINT16);
2550 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2551 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2552 				 rxtxq, "rxq#txq");
2553 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2554 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2555 			      qid, UINT16);
2556 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2557 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2558 				 rsize, "ring_size");
2559 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2560 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2561 			      size, UINT16);
2562 
2563 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2564 	.f = cmd_config_rxtx_ring_size_parsed,
2565 	.data = NULL,
2566 	.help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2567 	.tokens = {
2568 		(void *)&cmd_config_rxtx_ring_size_port,
2569 		(void *)&cmd_config_rxtx_ring_size_config,
2570 		(void *)&cmd_config_rxtx_ring_size_portid,
2571 		(void *)&cmd_config_rxtx_ring_size_rxtxq,
2572 		(void *)&cmd_config_rxtx_ring_size_qid,
2573 		(void *)&cmd_config_rxtx_ring_size_rsize,
2574 		(void *)&cmd_config_rxtx_ring_size_size,
2575 		NULL,
2576 	},
2577 };
2578 
2579 /* *** configure port rxq/txq start/stop *** */
2580 struct cmd_config_rxtx_queue {
2581 	cmdline_fixed_string_t port;
2582 	portid_t portid;
2583 	cmdline_fixed_string_t rxtxq;
2584 	uint16_t qid;
2585 	cmdline_fixed_string_t opname;
2586 };
2587 
2588 static void
2589 cmd_config_rxtx_queue_parsed(void *parsed_result,
2590 			__attribute__((unused)) struct cmdline *cl,
2591 			__attribute__((unused)) void *data)
2592 {
2593 	struct cmd_config_rxtx_queue *res = parsed_result;
2594 	uint8_t isrx;
2595 	uint8_t isstart;
2596 	int ret = 0;
2597 
2598 	if (test_done == 0) {
2599 		printf("Please stop forwarding first\n");
2600 		return;
2601 	}
2602 
2603 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2604 		return;
2605 
2606 	if (port_is_started(res->portid) != 1) {
2607 		printf("Please start port %u first\n", res->portid);
2608 		return;
2609 	}
2610 
2611 	if (!strcmp(res->rxtxq, "rxq"))
2612 		isrx = 1;
2613 	else if (!strcmp(res->rxtxq, "txq"))
2614 		isrx = 0;
2615 	else {
2616 		printf("Unknown parameter\n");
2617 		return;
2618 	}
2619 
2620 	if (isrx && rx_queue_id_is_invalid(res->qid))
2621 		return;
2622 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2623 		return;
2624 
2625 	if (!strcmp(res->opname, "start"))
2626 		isstart = 1;
2627 	else if (!strcmp(res->opname, "stop"))
2628 		isstart = 0;
2629 	else {
2630 		printf("Unknown parameter\n");
2631 		return;
2632 	}
2633 
2634 	if (isstart && isrx)
2635 		ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2636 	else if (!isstart && isrx)
2637 		ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2638 	else if (isstart && !isrx)
2639 		ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2640 	else
2641 		ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2642 
2643 	if (ret == -ENOTSUP)
2644 		printf("Function not supported in PMD driver\n");
2645 }
2646 
2647 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2648 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2649 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2650 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2651 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2652 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2653 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2654 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2655 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2656 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2657 						"start#stop");
2658 
2659 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2660 	.f = cmd_config_rxtx_queue_parsed,
2661 	.data = NULL,
2662 	.help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2663 	.tokens = {
2664 		(void *)&cmd_config_rxtx_queue_port,
2665 		(void *)&cmd_config_rxtx_queue_portid,
2666 		(void *)&cmd_config_rxtx_queue_rxtxq,
2667 		(void *)&cmd_config_rxtx_queue_qid,
2668 		(void *)&cmd_config_rxtx_queue_opname,
2669 		NULL,
2670 	},
2671 };
2672 
2673 /* *** configure port rxq/txq deferred start on/off *** */
2674 struct cmd_config_deferred_start_rxtx_queue {
2675 	cmdline_fixed_string_t port;
2676 	portid_t port_id;
2677 	cmdline_fixed_string_t rxtxq;
2678 	uint16_t qid;
2679 	cmdline_fixed_string_t opname;
2680 	cmdline_fixed_string_t state;
2681 };
2682 
2683 static void
2684 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2685 			__attribute__((unused)) struct cmdline *cl,
2686 			__attribute__((unused)) void *data)
2687 {
2688 	struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2689 	struct rte_port *port;
2690 	uint8_t isrx;
2691 	uint8_t ison;
2692 	uint8_t needreconfig = 0;
2693 
2694 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2695 		return;
2696 
2697 	if (port_is_started(res->port_id) != 0) {
2698 		printf("Please stop port %u first\n", res->port_id);
2699 		return;
2700 	}
2701 
2702 	port = &ports[res->port_id];
2703 
2704 	isrx = !strcmp(res->rxtxq, "rxq");
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 	ison = !strcmp(res->state, "on");
2712 
2713 	if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2714 		port->rx_conf[res->qid].rx_deferred_start = ison;
2715 		needreconfig = 1;
2716 	} else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2717 		port->tx_conf[res->qid].tx_deferred_start = ison;
2718 		needreconfig = 1;
2719 	}
2720 
2721 	if (needreconfig)
2722 		cmd_reconfig_device_queue(res->port_id, 0, 1);
2723 }
2724 
2725 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2726 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2727 						port, "port");
2728 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2729 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2730 						port_id, UINT16);
2731 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2732 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2733 						rxtxq, "rxq#txq");
2734 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2735 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2736 						qid, UINT16);
2737 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2738 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2739 						opname, "deferred_start");
2740 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2741 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2742 						state, "on#off");
2743 
2744 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2745 	.f = cmd_config_deferred_start_rxtx_queue_parsed,
2746 	.data = NULL,
2747 	.help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2748 	.tokens = {
2749 		(void *)&cmd_config_deferred_start_rxtx_queue_port,
2750 		(void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2751 		(void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2752 		(void *)&cmd_config_deferred_start_rxtx_queue_qid,
2753 		(void *)&cmd_config_deferred_start_rxtx_queue_opname,
2754 		(void *)&cmd_config_deferred_start_rxtx_queue_state,
2755 		NULL,
2756 	},
2757 };
2758 
2759 /* *** configure port rxq/txq setup *** */
2760 struct cmd_setup_rxtx_queue {
2761 	cmdline_fixed_string_t port;
2762 	portid_t portid;
2763 	cmdline_fixed_string_t rxtxq;
2764 	uint16_t qid;
2765 	cmdline_fixed_string_t setup;
2766 };
2767 
2768 /* Common CLI fields for queue setup */
2769 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2770 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2771 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2772 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2773 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2774 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2775 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2776 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2777 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2778 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2779 
2780 static void
2781 cmd_setup_rxtx_queue_parsed(
2782 	void *parsed_result,
2783 	__attribute__((unused)) struct cmdline *cl,
2784 	__attribute__((unused)) void *data)
2785 {
2786 	struct cmd_setup_rxtx_queue *res = parsed_result;
2787 	struct rte_port *port;
2788 	struct rte_mempool *mp;
2789 	unsigned int socket_id;
2790 	uint8_t isrx = 0;
2791 	int ret;
2792 
2793 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2794 		return;
2795 
2796 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2797 		printf("Invalid port id\n");
2798 		return;
2799 	}
2800 
2801 	if (!strcmp(res->rxtxq, "rxq"))
2802 		isrx = 1;
2803 	else if (!strcmp(res->rxtxq, "txq"))
2804 		isrx = 0;
2805 	else {
2806 		printf("Unknown parameter\n");
2807 		return;
2808 	}
2809 
2810 	if (isrx && rx_queue_id_is_invalid(res->qid)) {
2811 		printf("Invalid rx queue\n");
2812 		return;
2813 	} else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2814 		printf("Invalid tx queue\n");
2815 		return;
2816 	}
2817 
2818 	port = &ports[res->portid];
2819 	if (isrx) {
2820 		socket_id = rxring_numa[res->portid];
2821 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2822 			socket_id = port->socket_id;
2823 
2824 		mp = mbuf_pool_find(socket_id);
2825 		if (mp == NULL) {
2826 			printf("Failed to setup RX queue: "
2827 				"No mempool allocation"
2828 				" on the socket %d\n",
2829 				rxring_numa[res->portid]);
2830 			return;
2831 		}
2832 		ret = rte_eth_rx_queue_setup(res->portid,
2833 					     res->qid,
2834 					     port->nb_rx_desc[res->qid],
2835 					     socket_id,
2836 					     &port->rx_conf[res->qid],
2837 					     mp);
2838 		if (ret)
2839 			printf("Failed to setup RX queue\n");
2840 	} else {
2841 		socket_id = txring_numa[res->portid];
2842 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2843 			socket_id = port->socket_id;
2844 
2845 		ret = rte_eth_tx_queue_setup(res->portid,
2846 					     res->qid,
2847 					     port->nb_tx_desc[res->qid],
2848 					     socket_id,
2849 					     &port->tx_conf[res->qid]);
2850 		if (ret)
2851 			printf("Failed to setup TX queue\n");
2852 	}
2853 }
2854 
2855 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2856 	.f = cmd_setup_rxtx_queue_parsed,
2857 	.data = NULL,
2858 	.help_str = "port <port_id> rxq|txq <queue_idx> setup",
2859 	.tokens = {
2860 		(void *)&cmd_setup_rxtx_queue_port,
2861 		(void *)&cmd_setup_rxtx_queue_portid,
2862 		(void *)&cmd_setup_rxtx_queue_rxtxq,
2863 		(void *)&cmd_setup_rxtx_queue_qid,
2864 		(void *)&cmd_setup_rxtx_queue_setup,
2865 		NULL,
2866 	},
2867 };
2868 
2869 
2870 /* *** Configure RSS RETA *** */
2871 struct cmd_config_rss_reta {
2872 	cmdline_fixed_string_t port;
2873 	cmdline_fixed_string_t keyword;
2874 	portid_t port_id;
2875 	cmdline_fixed_string_t name;
2876 	cmdline_fixed_string_t list_name;
2877 	cmdline_fixed_string_t list_of_items;
2878 };
2879 
2880 static int
2881 parse_reta_config(const char *str,
2882 		  struct rte_eth_rss_reta_entry64 *reta_conf,
2883 		  uint16_t nb_entries)
2884 {
2885 	int i;
2886 	unsigned size;
2887 	uint16_t hash_index, idx, shift;
2888 	uint16_t nb_queue;
2889 	char s[256];
2890 	const char *p, *p0 = str;
2891 	char *end;
2892 	enum fieldnames {
2893 		FLD_HASH_INDEX = 0,
2894 		FLD_QUEUE,
2895 		_NUM_FLD
2896 	};
2897 	unsigned long int_fld[_NUM_FLD];
2898 	char *str_fld[_NUM_FLD];
2899 
2900 	while ((p = strchr(p0,'(')) != NULL) {
2901 		++p;
2902 		if((p0 = strchr(p,')')) == NULL)
2903 			return -1;
2904 
2905 		size = p0 - p;
2906 		if(size >= sizeof(s))
2907 			return -1;
2908 
2909 		snprintf(s, sizeof(s), "%.*s", size, p);
2910 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2911 			return -1;
2912 		for (i = 0; i < _NUM_FLD; i++) {
2913 			errno = 0;
2914 			int_fld[i] = strtoul(str_fld[i], &end, 0);
2915 			if (errno != 0 || end == str_fld[i] ||
2916 					int_fld[i] > 65535)
2917 				return -1;
2918 		}
2919 
2920 		hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2921 		nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2922 
2923 		if (hash_index >= nb_entries) {
2924 			printf("Invalid RETA hash index=%d\n", hash_index);
2925 			return -1;
2926 		}
2927 
2928 		idx = hash_index / RTE_RETA_GROUP_SIZE;
2929 		shift = hash_index % RTE_RETA_GROUP_SIZE;
2930 		reta_conf[idx].mask |= (1ULL << shift);
2931 		reta_conf[idx].reta[shift] = nb_queue;
2932 	}
2933 
2934 	return 0;
2935 }
2936 
2937 static void
2938 cmd_set_rss_reta_parsed(void *parsed_result,
2939 			__attribute__((unused)) struct cmdline *cl,
2940 			__attribute__((unused)) void *data)
2941 {
2942 	int ret;
2943 	struct rte_eth_dev_info dev_info;
2944 	struct rte_eth_rss_reta_entry64 reta_conf[8];
2945 	struct cmd_config_rss_reta *res = parsed_result;
2946 
2947 	memset(&dev_info, 0, sizeof(dev_info));
2948 	rte_eth_dev_info_get(res->port_id, &dev_info);
2949 	if (dev_info.reta_size == 0) {
2950 		printf("Redirection table size is 0 which is "
2951 					"invalid for RSS\n");
2952 		return;
2953 	} else
2954 		printf("The reta size of port %d is %u\n",
2955 			res->port_id, dev_info.reta_size);
2956 	if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2957 		printf("Currently do not support more than %u entries of "
2958 			"redirection table\n", ETH_RSS_RETA_SIZE_512);
2959 		return;
2960 	}
2961 
2962 	memset(reta_conf, 0, sizeof(reta_conf));
2963 	if (!strcmp(res->list_name, "reta")) {
2964 		if (parse_reta_config(res->list_of_items, reta_conf,
2965 						dev_info.reta_size)) {
2966 			printf("Invalid RSS Redirection Table "
2967 					"config entered\n");
2968 			return;
2969 		}
2970 		ret = rte_eth_dev_rss_reta_update(res->port_id,
2971 				reta_conf, dev_info.reta_size);
2972 		if (ret != 0)
2973 			printf("Bad redirection table parameter, "
2974 					"return code = %d \n", ret);
2975 	}
2976 }
2977 
2978 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2979 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2980 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2981 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2982 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2983 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2984 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2985 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2986 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2987 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2988 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2989         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2990                                  NULL);
2991 cmdline_parse_inst_t cmd_config_rss_reta = {
2992 	.f = cmd_set_rss_reta_parsed,
2993 	.data = NULL,
2994 	.help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2995 	.tokens = {
2996 		(void *)&cmd_config_rss_reta_port,
2997 		(void *)&cmd_config_rss_reta_keyword,
2998 		(void *)&cmd_config_rss_reta_port_id,
2999 		(void *)&cmd_config_rss_reta_name,
3000 		(void *)&cmd_config_rss_reta_list_name,
3001 		(void *)&cmd_config_rss_reta_list_of_items,
3002 		NULL,
3003 	},
3004 };
3005 
3006 /* *** SHOW PORT RETA INFO *** */
3007 struct cmd_showport_reta {
3008 	cmdline_fixed_string_t show;
3009 	cmdline_fixed_string_t port;
3010 	portid_t port_id;
3011 	cmdline_fixed_string_t rss;
3012 	cmdline_fixed_string_t reta;
3013 	uint16_t size;
3014 	cmdline_fixed_string_t list_of_items;
3015 };
3016 
3017 static int
3018 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3019 			   uint16_t nb_entries,
3020 			   char *str)
3021 {
3022 	uint32_t size;
3023 	const char *p, *p0 = str;
3024 	char s[256];
3025 	char *end;
3026 	char *str_fld[8];
3027 	uint16_t i;
3028 	uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3029 			RTE_RETA_GROUP_SIZE;
3030 	int ret;
3031 
3032 	p = strchr(p0, '(');
3033 	if (p == NULL)
3034 		return -1;
3035 	p++;
3036 	p0 = strchr(p, ')');
3037 	if (p0 == NULL)
3038 		return -1;
3039 	size = p0 - p;
3040 	if (size >= sizeof(s)) {
3041 		printf("The string size exceeds the internal buffer size\n");
3042 		return -1;
3043 	}
3044 	snprintf(s, sizeof(s), "%.*s", size, p);
3045 	ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3046 	if (ret <= 0 || ret != num) {
3047 		printf("The bits of masks do not match the number of "
3048 					"reta entries: %u\n", num);
3049 		return -1;
3050 	}
3051 	for (i = 0; i < ret; i++)
3052 		conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3053 
3054 	return 0;
3055 }
3056 
3057 static void
3058 cmd_showport_reta_parsed(void *parsed_result,
3059 			 __attribute__((unused)) struct cmdline *cl,
3060 			 __attribute__((unused)) void *data)
3061 {
3062 	struct cmd_showport_reta *res = parsed_result;
3063 	struct rte_eth_rss_reta_entry64 reta_conf[8];
3064 	struct rte_eth_dev_info dev_info;
3065 	uint16_t max_reta_size;
3066 
3067 	memset(&dev_info, 0, sizeof(dev_info));
3068 	rte_eth_dev_info_get(res->port_id, &dev_info);
3069 	max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3070 	if (res->size == 0 || res->size > max_reta_size) {
3071 		printf("Invalid redirection table size: %u (1-%u)\n",
3072 			res->size, max_reta_size);
3073 		return;
3074 	}
3075 
3076 	memset(reta_conf, 0, sizeof(reta_conf));
3077 	if (showport_parse_reta_config(reta_conf, res->size,
3078 				res->list_of_items) < 0) {
3079 		printf("Invalid string: %s for reta masks\n",
3080 					res->list_of_items);
3081 		return;
3082 	}
3083 	port_rss_reta_info(res->port_id, reta_conf, res->size);
3084 }
3085 
3086 cmdline_parse_token_string_t cmd_showport_reta_show =
3087 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3088 cmdline_parse_token_string_t cmd_showport_reta_port =
3089 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3090 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3091 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3092 cmdline_parse_token_string_t cmd_showport_reta_rss =
3093 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3094 cmdline_parse_token_string_t cmd_showport_reta_reta =
3095 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3096 cmdline_parse_token_num_t cmd_showport_reta_size =
3097 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3098 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3099 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3100 					list_of_items, NULL);
3101 
3102 cmdline_parse_inst_t cmd_showport_reta = {
3103 	.f = cmd_showport_reta_parsed,
3104 	.data = NULL,
3105 	.help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3106 	.tokens = {
3107 		(void *)&cmd_showport_reta_show,
3108 		(void *)&cmd_showport_reta_port,
3109 		(void *)&cmd_showport_reta_port_id,
3110 		(void *)&cmd_showport_reta_rss,
3111 		(void *)&cmd_showport_reta_reta,
3112 		(void *)&cmd_showport_reta_size,
3113 		(void *)&cmd_showport_reta_list_of_items,
3114 		NULL,
3115 	},
3116 };
3117 
3118 /* *** Show RSS hash configuration *** */
3119 struct cmd_showport_rss_hash {
3120 	cmdline_fixed_string_t show;
3121 	cmdline_fixed_string_t port;
3122 	portid_t port_id;
3123 	cmdline_fixed_string_t rss_hash;
3124 	cmdline_fixed_string_t rss_type;
3125 	cmdline_fixed_string_t key; /* optional argument */
3126 };
3127 
3128 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3129 				__attribute__((unused)) struct cmdline *cl,
3130 				void *show_rss_key)
3131 {
3132 	struct cmd_showport_rss_hash *res = parsed_result;
3133 
3134 	port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3135 }
3136 
3137 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3138 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3139 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3140 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3141 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3142 	TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3143 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3144 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3145 				 "rss-hash");
3146 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3147 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3148 
3149 cmdline_parse_inst_t cmd_showport_rss_hash = {
3150 	.f = cmd_showport_rss_hash_parsed,
3151 	.data = NULL,
3152 	.help_str = "show port <port_id> rss-hash",
3153 	.tokens = {
3154 		(void *)&cmd_showport_rss_hash_show,
3155 		(void *)&cmd_showport_rss_hash_port,
3156 		(void *)&cmd_showport_rss_hash_port_id,
3157 		(void *)&cmd_showport_rss_hash_rss_hash,
3158 		NULL,
3159 	},
3160 };
3161 
3162 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3163 	.f = cmd_showport_rss_hash_parsed,
3164 	.data = (void *)1,
3165 	.help_str = "show port <port_id> rss-hash key",
3166 	.tokens = {
3167 		(void *)&cmd_showport_rss_hash_show,
3168 		(void *)&cmd_showport_rss_hash_port,
3169 		(void *)&cmd_showport_rss_hash_port_id,
3170 		(void *)&cmd_showport_rss_hash_rss_hash,
3171 		(void *)&cmd_showport_rss_hash_rss_key,
3172 		NULL,
3173 	},
3174 };
3175 
3176 /* *** Configure DCB *** */
3177 struct cmd_config_dcb {
3178 	cmdline_fixed_string_t port;
3179 	cmdline_fixed_string_t config;
3180 	portid_t port_id;
3181 	cmdline_fixed_string_t dcb;
3182 	cmdline_fixed_string_t vt;
3183 	cmdline_fixed_string_t vt_en;
3184 	uint8_t num_tcs;
3185 	cmdline_fixed_string_t pfc;
3186 	cmdline_fixed_string_t pfc_en;
3187 };
3188 
3189 static void
3190 cmd_config_dcb_parsed(void *parsed_result,
3191                         __attribute__((unused)) struct cmdline *cl,
3192                         __attribute__((unused)) void *data)
3193 {
3194 	struct cmd_config_dcb *res = parsed_result;
3195 	portid_t port_id = res->port_id;
3196 	struct rte_port *port;
3197 	uint8_t pfc_en;
3198 	int ret;
3199 
3200 	port = &ports[port_id];
3201 	/** Check if the port is not started **/
3202 	if (port->port_status != RTE_PORT_STOPPED) {
3203 		printf("Please stop port %d first\n", port_id);
3204 		return;
3205 	}
3206 
3207 	if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3208 		printf("The invalid number of traffic class,"
3209 			" only 4 or 8 allowed.\n");
3210 		return;
3211 	}
3212 
3213 	if (nb_fwd_lcores < res->num_tcs) {
3214 		printf("nb_cores shouldn't be less than number of TCs.\n");
3215 		return;
3216 	}
3217 	if (!strncmp(res->pfc_en, "on", 2))
3218 		pfc_en = 1;
3219 	else
3220 		pfc_en = 0;
3221 
3222 	/* DCB in VT mode */
3223 	if (!strncmp(res->vt_en, "on", 2))
3224 		ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3225 				(enum rte_eth_nb_tcs)res->num_tcs,
3226 				pfc_en);
3227 	else
3228 		ret = init_port_dcb_config(port_id, DCB_ENABLED,
3229 				(enum rte_eth_nb_tcs)res->num_tcs,
3230 				pfc_en);
3231 
3232 
3233 	if (ret != 0) {
3234 		printf("Cannot initialize network ports.\n");
3235 		return;
3236 	}
3237 
3238 	cmd_reconfig_device_queue(port_id, 1, 1);
3239 }
3240 
3241 cmdline_parse_token_string_t cmd_config_dcb_port =
3242         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3243 cmdline_parse_token_string_t cmd_config_dcb_config =
3244         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3245 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3246 	TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3247 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3248         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3249 cmdline_parse_token_string_t cmd_config_dcb_vt =
3250         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3251 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3252         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3253 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3254         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3255 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3256         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3257 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3258         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3259 
3260 cmdline_parse_inst_t cmd_config_dcb = {
3261 	.f = cmd_config_dcb_parsed,
3262 	.data = NULL,
3263 	.help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3264 	.tokens = {
3265 		(void *)&cmd_config_dcb_port,
3266 		(void *)&cmd_config_dcb_config,
3267 		(void *)&cmd_config_dcb_port_id,
3268 		(void *)&cmd_config_dcb_dcb,
3269 		(void *)&cmd_config_dcb_vt,
3270 		(void *)&cmd_config_dcb_vt_en,
3271 		(void *)&cmd_config_dcb_num_tcs,
3272 		(void *)&cmd_config_dcb_pfc,
3273 		(void *)&cmd_config_dcb_pfc_en,
3274                 NULL,
3275         },
3276 };
3277 
3278 /* *** configure number of packets per burst *** */
3279 struct cmd_config_burst {
3280 	cmdline_fixed_string_t port;
3281 	cmdline_fixed_string_t keyword;
3282 	cmdline_fixed_string_t all;
3283 	cmdline_fixed_string_t name;
3284 	uint16_t value;
3285 };
3286 
3287 static void
3288 cmd_config_burst_parsed(void *parsed_result,
3289 			__attribute__((unused)) struct cmdline *cl,
3290 			__attribute__((unused)) void *data)
3291 {
3292 	struct cmd_config_burst *res = parsed_result;
3293 	struct rte_eth_dev_info dev_info;
3294 	uint16_t rec_nb_pkts;
3295 
3296 	if (!all_ports_stopped()) {
3297 		printf("Please stop all ports first\n");
3298 		return;
3299 	}
3300 
3301 	if (!strcmp(res->name, "burst")) {
3302 		if (res->value == 0) {
3303 			/* If user gives a value of zero, query the PMD for
3304 			 * its recommended Rx burst size. Testpmd uses a single
3305 			 * size for all ports, so assume all ports are the same
3306 			 * NIC model and use the values from Port 0.
3307 			 */
3308 			rte_eth_dev_info_get(0, &dev_info);
3309 			rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3310 
3311 			if (rec_nb_pkts == 0) {
3312 				printf("PMD does not recommend a burst size.\n"
3313 					"User provided value must be between"
3314 					" 1 and %d\n", MAX_PKT_BURST);
3315 				return;
3316 			} else if (rec_nb_pkts > MAX_PKT_BURST) {
3317 				printf("PMD recommended burst size of %d"
3318 					" exceeds maximum value of %d\n",
3319 					rec_nb_pkts, MAX_PKT_BURST);
3320 				return;
3321 			}
3322 			printf("Using PMD-provided burst value of %d\n",
3323 				rec_nb_pkts);
3324 			nb_pkt_per_burst = rec_nb_pkts;
3325 		} else if (res->value > MAX_PKT_BURST) {
3326 			printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3327 			return;
3328 		} else
3329 			nb_pkt_per_burst = res->value;
3330 	} else {
3331 		printf("Unknown parameter\n");
3332 		return;
3333 	}
3334 
3335 	init_port_config();
3336 
3337 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3338 }
3339 
3340 cmdline_parse_token_string_t cmd_config_burst_port =
3341 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3342 cmdline_parse_token_string_t cmd_config_burst_keyword =
3343 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3344 cmdline_parse_token_string_t cmd_config_burst_all =
3345 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3346 cmdline_parse_token_string_t cmd_config_burst_name =
3347 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3348 cmdline_parse_token_num_t cmd_config_burst_value =
3349 	TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3350 
3351 cmdline_parse_inst_t cmd_config_burst = {
3352 	.f = cmd_config_burst_parsed,
3353 	.data = NULL,
3354 	.help_str = "port config all burst <value>",
3355 	.tokens = {
3356 		(void *)&cmd_config_burst_port,
3357 		(void *)&cmd_config_burst_keyword,
3358 		(void *)&cmd_config_burst_all,
3359 		(void *)&cmd_config_burst_name,
3360 		(void *)&cmd_config_burst_value,
3361 		NULL,
3362 	},
3363 };
3364 
3365 /* *** configure rx/tx queues *** */
3366 struct cmd_config_thresh {
3367 	cmdline_fixed_string_t port;
3368 	cmdline_fixed_string_t keyword;
3369 	cmdline_fixed_string_t all;
3370 	cmdline_fixed_string_t name;
3371 	uint8_t value;
3372 };
3373 
3374 static void
3375 cmd_config_thresh_parsed(void *parsed_result,
3376 			__attribute__((unused)) struct cmdline *cl,
3377 			__attribute__((unused)) void *data)
3378 {
3379 	struct cmd_config_thresh *res = parsed_result;
3380 
3381 	if (!all_ports_stopped()) {
3382 		printf("Please stop all ports first\n");
3383 		return;
3384 	}
3385 
3386 	if (!strcmp(res->name, "txpt"))
3387 		tx_pthresh = res->value;
3388 	else if(!strcmp(res->name, "txht"))
3389 		tx_hthresh = res->value;
3390 	else if(!strcmp(res->name, "txwt"))
3391 		tx_wthresh = res->value;
3392 	else if(!strcmp(res->name, "rxpt"))
3393 		rx_pthresh = res->value;
3394 	else if(!strcmp(res->name, "rxht"))
3395 		rx_hthresh = res->value;
3396 	else if(!strcmp(res->name, "rxwt"))
3397 		rx_wthresh = res->value;
3398 	else {
3399 		printf("Unknown parameter\n");
3400 		return;
3401 	}
3402 
3403 	init_port_config();
3404 
3405 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3406 }
3407 
3408 cmdline_parse_token_string_t cmd_config_thresh_port =
3409 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3410 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3411 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3412 cmdline_parse_token_string_t cmd_config_thresh_all =
3413 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3414 cmdline_parse_token_string_t cmd_config_thresh_name =
3415 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3416 				"txpt#txht#txwt#rxpt#rxht#rxwt");
3417 cmdline_parse_token_num_t cmd_config_thresh_value =
3418 	TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3419 
3420 cmdline_parse_inst_t cmd_config_thresh = {
3421 	.f = cmd_config_thresh_parsed,
3422 	.data = NULL,
3423 	.help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3424 	.tokens = {
3425 		(void *)&cmd_config_thresh_port,
3426 		(void *)&cmd_config_thresh_keyword,
3427 		(void *)&cmd_config_thresh_all,
3428 		(void *)&cmd_config_thresh_name,
3429 		(void *)&cmd_config_thresh_value,
3430 		NULL,
3431 	},
3432 };
3433 
3434 /* *** configure free/rs threshold *** */
3435 struct cmd_config_threshold {
3436 	cmdline_fixed_string_t port;
3437 	cmdline_fixed_string_t keyword;
3438 	cmdline_fixed_string_t all;
3439 	cmdline_fixed_string_t name;
3440 	uint16_t value;
3441 };
3442 
3443 static void
3444 cmd_config_threshold_parsed(void *parsed_result,
3445 			__attribute__((unused)) struct cmdline *cl,
3446 			__attribute__((unused)) void *data)
3447 {
3448 	struct cmd_config_threshold *res = parsed_result;
3449 
3450 	if (!all_ports_stopped()) {
3451 		printf("Please stop all ports first\n");
3452 		return;
3453 	}
3454 
3455 	if (!strcmp(res->name, "txfreet"))
3456 		tx_free_thresh = res->value;
3457 	else if (!strcmp(res->name, "txrst"))
3458 		tx_rs_thresh = res->value;
3459 	else if (!strcmp(res->name, "rxfreet"))
3460 		rx_free_thresh = res->value;
3461 	else {
3462 		printf("Unknown parameter\n");
3463 		return;
3464 	}
3465 
3466 	init_port_config();
3467 
3468 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3469 }
3470 
3471 cmdline_parse_token_string_t cmd_config_threshold_port =
3472 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3473 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3474 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3475 								"config");
3476 cmdline_parse_token_string_t cmd_config_threshold_all =
3477 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3478 cmdline_parse_token_string_t cmd_config_threshold_name =
3479 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3480 						"txfreet#txrst#rxfreet");
3481 cmdline_parse_token_num_t cmd_config_threshold_value =
3482 	TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3483 
3484 cmdline_parse_inst_t cmd_config_threshold = {
3485 	.f = cmd_config_threshold_parsed,
3486 	.data = NULL,
3487 	.help_str = "port config all txfreet|txrst|rxfreet <value>",
3488 	.tokens = {
3489 		(void *)&cmd_config_threshold_port,
3490 		(void *)&cmd_config_threshold_keyword,
3491 		(void *)&cmd_config_threshold_all,
3492 		(void *)&cmd_config_threshold_name,
3493 		(void *)&cmd_config_threshold_value,
3494 		NULL,
3495 	},
3496 };
3497 
3498 /* *** stop *** */
3499 struct cmd_stop_result {
3500 	cmdline_fixed_string_t stop;
3501 };
3502 
3503 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3504 			    __attribute__((unused)) struct cmdline *cl,
3505 			    __attribute__((unused)) void *data)
3506 {
3507 	stop_packet_forwarding();
3508 }
3509 
3510 cmdline_parse_token_string_t cmd_stop_stop =
3511 	TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3512 
3513 cmdline_parse_inst_t cmd_stop = {
3514 	.f = cmd_stop_parsed,
3515 	.data = NULL,
3516 	.help_str = "stop: Stop packet forwarding",
3517 	.tokens = {
3518 		(void *)&cmd_stop_stop,
3519 		NULL,
3520 	},
3521 };
3522 
3523 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3524 
3525 unsigned int
3526 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3527 		unsigned int *parsed_items, int check_unique_values)
3528 {
3529 	unsigned int nb_item;
3530 	unsigned int value;
3531 	unsigned int i;
3532 	unsigned int j;
3533 	int value_ok;
3534 	char c;
3535 
3536 	/*
3537 	 * First parse all items in the list and store their value.
3538 	 */
3539 	value = 0;
3540 	nb_item = 0;
3541 	value_ok = 0;
3542 	for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3543 		c = str[i];
3544 		if ((c >= '0') && (c <= '9')) {
3545 			value = (unsigned int) (value * 10 + (c - '0'));
3546 			value_ok = 1;
3547 			continue;
3548 		}
3549 		if (c != ',') {
3550 			printf("character %c is not a decimal digit\n", c);
3551 			return 0;
3552 		}
3553 		if (! value_ok) {
3554 			printf("No valid value before comma\n");
3555 			return 0;
3556 		}
3557 		if (nb_item < max_items) {
3558 			parsed_items[nb_item] = value;
3559 			value_ok = 0;
3560 			value = 0;
3561 		}
3562 		nb_item++;
3563 	}
3564 	if (nb_item >= max_items) {
3565 		printf("Number of %s = %u > %u (maximum items)\n",
3566 		       item_name, nb_item + 1, max_items);
3567 		return 0;
3568 	}
3569 	parsed_items[nb_item++] = value;
3570 	if (! check_unique_values)
3571 		return nb_item;
3572 
3573 	/*
3574 	 * Then, check that all values in the list are differents.
3575 	 * No optimization here...
3576 	 */
3577 	for (i = 0; i < nb_item; i++) {
3578 		for (j = i + 1; j < nb_item; j++) {
3579 			if (parsed_items[j] == parsed_items[i]) {
3580 				printf("duplicated %s %u at index %u and %u\n",
3581 				       item_name, parsed_items[i], i, j);
3582 				return 0;
3583 			}
3584 		}
3585 	}
3586 	return nb_item;
3587 }
3588 
3589 struct cmd_set_list_result {
3590 	cmdline_fixed_string_t cmd_keyword;
3591 	cmdline_fixed_string_t list_name;
3592 	cmdline_fixed_string_t list_of_items;
3593 };
3594 
3595 static void cmd_set_list_parsed(void *parsed_result,
3596 				__attribute__((unused)) struct cmdline *cl,
3597 				__attribute__((unused)) void *data)
3598 {
3599 	struct cmd_set_list_result *res;
3600 	union {
3601 		unsigned int lcorelist[RTE_MAX_LCORE];
3602 		unsigned int portlist[RTE_MAX_ETHPORTS];
3603 	} parsed_items;
3604 	unsigned int nb_item;
3605 
3606 	if (test_done == 0) {
3607 		printf("Please stop forwarding first\n");
3608 		return;
3609 	}
3610 
3611 	res = parsed_result;
3612 	if (!strcmp(res->list_name, "corelist")) {
3613 		nb_item = parse_item_list(res->list_of_items, "core",
3614 					  RTE_MAX_LCORE,
3615 					  parsed_items.lcorelist, 1);
3616 		if (nb_item > 0) {
3617 			set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3618 			fwd_config_setup();
3619 		}
3620 		return;
3621 	}
3622 	if (!strcmp(res->list_name, "portlist")) {
3623 		nb_item = parse_item_list(res->list_of_items, "port",
3624 					  RTE_MAX_ETHPORTS,
3625 					  parsed_items.portlist, 1);
3626 		if (nb_item > 0) {
3627 			set_fwd_ports_list(parsed_items.portlist, nb_item);
3628 			fwd_config_setup();
3629 		}
3630 	}
3631 }
3632 
3633 cmdline_parse_token_string_t cmd_set_list_keyword =
3634 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3635 				 "set");
3636 cmdline_parse_token_string_t cmd_set_list_name =
3637 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3638 				 "corelist#portlist");
3639 cmdline_parse_token_string_t cmd_set_list_of_items =
3640 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3641 				 NULL);
3642 
3643 cmdline_parse_inst_t cmd_set_fwd_list = {
3644 	.f = cmd_set_list_parsed,
3645 	.data = NULL,
3646 	.help_str = "set corelist|portlist <list0[,list1]*>",
3647 	.tokens = {
3648 		(void *)&cmd_set_list_keyword,
3649 		(void *)&cmd_set_list_name,
3650 		(void *)&cmd_set_list_of_items,
3651 		NULL,
3652 	},
3653 };
3654 
3655 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3656 
3657 struct cmd_setmask_result {
3658 	cmdline_fixed_string_t set;
3659 	cmdline_fixed_string_t mask;
3660 	uint64_t hexavalue;
3661 };
3662 
3663 static void cmd_set_mask_parsed(void *parsed_result,
3664 				__attribute__((unused)) struct cmdline *cl,
3665 				__attribute__((unused)) void *data)
3666 {
3667 	struct cmd_setmask_result *res = parsed_result;
3668 
3669 	if (test_done == 0) {
3670 		printf("Please stop forwarding first\n");
3671 		return;
3672 	}
3673 	if (!strcmp(res->mask, "coremask")) {
3674 		set_fwd_lcores_mask(res->hexavalue);
3675 		fwd_config_setup();
3676 	} else if (!strcmp(res->mask, "portmask")) {
3677 		set_fwd_ports_mask(res->hexavalue);
3678 		fwd_config_setup();
3679 	}
3680 }
3681 
3682 cmdline_parse_token_string_t cmd_setmask_set =
3683 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3684 cmdline_parse_token_string_t cmd_setmask_mask =
3685 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3686 				 "coremask#portmask");
3687 cmdline_parse_token_num_t cmd_setmask_value =
3688 	TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3689 
3690 cmdline_parse_inst_t cmd_set_fwd_mask = {
3691 	.f = cmd_set_mask_parsed,
3692 	.data = NULL,
3693 	.help_str = "set coremask|portmask <hexadecimal value>",
3694 	.tokens = {
3695 		(void *)&cmd_setmask_set,
3696 		(void *)&cmd_setmask_mask,
3697 		(void *)&cmd_setmask_value,
3698 		NULL,
3699 	},
3700 };
3701 
3702 /*
3703  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3704  */
3705 struct cmd_set_result {
3706 	cmdline_fixed_string_t set;
3707 	cmdline_fixed_string_t what;
3708 	uint16_t value;
3709 };
3710 
3711 static void cmd_set_parsed(void *parsed_result,
3712 			   __attribute__((unused)) struct cmdline *cl,
3713 			   __attribute__((unused)) void *data)
3714 {
3715 	struct cmd_set_result *res = parsed_result;
3716 	if (!strcmp(res->what, "nbport")) {
3717 		set_fwd_ports_number(res->value);
3718 		fwd_config_setup();
3719 	} else if (!strcmp(res->what, "nbcore")) {
3720 		set_fwd_lcores_number(res->value);
3721 		fwd_config_setup();
3722 	} else if (!strcmp(res->what, "burst"))
3723 		set_nb_pkt_per_burst(res->value);
3724 	else if (!strcmp(res->what, "verbose"))
3725 		set_verbose_level(res->value);
3726 }
3727 
3728 cmdline_parse_token_string_t cmd_set_set =
3729 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3730 cmdline_parse_token_string_t cmd_set_what =
3731 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3732 				 "nbport#nbcore#burst#verbose");
3733 cmdline_parse_token_num_t cmd_set_value =
3734 	TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3735 
3736 cmdline_parse_inst_t cmd_set_numbers = {
3737 	.f = cmd_set_parsed,
3738 	.data = NULL,
3739 	.help_str = "set nbport|nbcore|burst|verbose <value>",
3740 	.tokens = {
3741 		(void *)&cmd_set_set,
3742 		(void *)&cmd_set_what,
3743 		(void *)&cmd_set_value,
3744 		NULL,
3745 	},
3746 };
3747 
3748 /* *** SET LOG LEVEL CONFIGURATION *** */
3749 
3750 struct cmd_set_log_result {
3751 	cmdline_fixed_string_t set;
3752 	cmdline_fixed_string_t log;
3753 	cmdline_fixed_string_t type;
3754 	uint32_t level;
3755 };
3756 
3757 static void
3758 cmd_set_log_parsed(void *parsed_result,
3759 		   __attribute__((unused)) struct cmdline *cl,
3760 		   __attribute__((unused)) void *data)
3761 {
3762 	struct cmd_set_log_result *res;
3763 	int ret;
3764 
3765 	res = parsed_result;
3766 	if (!strcmp(res->type, "global"))
3767 		rte_log_set_global_level(res->level);
3768 	else {
3769 		ret = rte_log_set_level_regexp(res->type, res->level);
3770 		if (ret < 0)
3771 			printf("Unable to set log level\n");
3772 	}
3773 }
3774 
3775 cmdline_parse_token_string_t cmd_set_log_set =
3776 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3777 cmdline_parse_token_string_t cmd_set_log_log =
3778 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3779 cmdline_parse_token_string_t cmd_set_log_type =
3780 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3781 cmdline_parse_token_num_t cmd_set_log_level =
3782 	TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3783 
3784 cmdline_parse_inst_t cmd_set_log = {
3785 	.f = cmd_set_log_parsed,
3786 	.data = NULL,
3787 	.help_str = "set log global|<type> <level>",
3788 	.tokens = {
3789 		(void *)&cmd_set_log_set,
3790 		(void *)&cmd_set_log_log,
3791 		(void *)&cmd_set_log_type,
3792 		(void *)&cmd_set_log_level,
3793 		NULL,
3794 	},
3795 };
3796 
3797 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3798 
3799 struct cmd_set_txpkts_result {
3800 	cmdline_fixed_string_t cmd_keyword;
3801 	cmdline_fixed_string_t txpkts;
3802 	cmdline_fixed_string_t seg_lengths;
3803 };
3804 
3805 static void
3806 cmd_set_txpkts_parsed(void *parsed_result,
3807 		      __attribute__((unused)) struct cmdline *cl,
3808 		      __attribute__((unused)) void *data)
3809 {
3810 	struct cmd_set_txpkts_result *res;
3811 	unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3812 	unsigned int nb_segs;
3813 
3814 	res = parsed_result;
3815 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3816 				  RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3817 	if (nb_segs > 0)
3818 		set_tx_pkt_segments(seg_lengths, nb_segs);
3819 }
3820 
3821 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3822 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3823 				 cmd_keyword, "set");
3824 cmdline_parse_token_string_t cmd_set_txpkts_name =
3825 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3826 				 txpkts, "txpkts");
3827 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3828 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3829 				 seg_lengths, NULL);
3830 
3831 cmdline_parse_inst_t cmd_set_txpkts = {
3832 	.f = cmd_set_txpkts_parsed,
3833 	.data = NULL,
3834 	.help_str = "set txpkts <len0[,len1]*>",
3835 	.tokens = {
3836 		(void *)&cmd_set_txpkts_keyword,
3837 		(void *)&cmd_set_txpkts_name,
3838 		(void *)&cmd_set_txpkts_lengths,
3839 		NULL,
3840 	},
3841 };
3842 
3843 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3844 
3845 struct cmd_set_txsplit_result {
3846 	cmdline_fixed_string_t cmd_keyword;
3847 	cmdline_fixed_string_t txsplit;
3848 	cmdline_fixed_string_t mode;
3849 };
3850 
3851 static void
3852 cmd_set_txsplit_parsed(void *parsed_result,
3853 		      __attribute__((unused)) struct cmdline *cl,
3854 		      __attribute__((unused)) void *data)
3855 {
3856 	struct cmd_set_txsplit_result *res;
3857 
3858 	res = parsed_result;
3859 	set_tx_pkt_split(res->mode);
3860 }
3861 
3862 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3863 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3864 				 cmd_keyword, "set");
3865 cmdline_parse_token_string_t cmd_set_txsplit_name =
3866 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3867 				 txsplit, "txsplit");
3868 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3869 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3870 				 mode, NULL);
3871 
3872 cmdline_parse_inst_t cmd_set_txsplit = {
3873 	.f = cmd_set_txsplit_parsed,
3874 	.data = NULL,
3875 	.help_str = "set txsplit on|off|rand",
3876 	.tokens = {
3877 		(void *)&cmd_set_txsplit_keyword,
3878 		(void *)&cmd_set_txsplit_name,
3879 		(void *)&cmd_set_txsplit_mode,
3880 		NULL,
3881 	},
3882 };
3883 
3884 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3885 struct cmd_rx_vlan_filter_all_result {
3886 	cmdline_fixed_string_t rx_vlan;
3887 	cmdline_fixed_string_t what;
3888 	cmdline_fixed_string_t all;
3889 	portid_t port_id;
3890 };
3891 
3892 static void
3893 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3894 			      __attribute__((unused)) struct cmdline *cl,
3895 			      __attribute__((unused)) void *data)
3896 {
3897 	struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3898 
3899 	if (!strcmp(res->what, "add"))
3900 		rx_vlan_all_filter_set(res->port_id, 1);
3901 	else
3902 		rx_vlan_all_filter_set(res->port_id, 0);
3903 }
3904 
3905 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3906 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3907 				 rx_vlan, "rx_vlan");
3908 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3909 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3910 				 what, "add#rm");
3911 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3912 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3913 				 all, "all");
3914 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3915 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3916 			      port_id, UINT16);
3917 
3918 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3919 	.f = cmd_rx_vlan_filter_all_parsed,
3920 	.data = NULL,
3921 	.help_str = "rx_vlan add|rm all <port_id>: "
3922 		"Add/Remove all identifiers to/from the set of VLAN "
3923 		"identifiers filtered by a port",
3924 	.tokens = {
3925 		(void *)&cmd_rx_vlan_filter_all_rx_vlan,
3926 		(void *)&cmd_rx_vlan_filter_all_what,
3927 		(void *)&cmd_rx_vlan_filter_all_all,
3928 		(void *)&cmd_rx_vlan_filter_all_portid,
3929 		NULL,
3930 	},
3931 };
3932 
3933 /* *** VLAN OFFLOAD SET ON A PORT *** */
3934 struct cmd_vlan_offload_result {
3935 	cmdline_fixed_string_t vlan;
3936 	cmdline_fixed_string_t set;
3937 	cmdline_fixed_string_t vlan_type;
3938 	cmdline_fixed_string_t what;
3939 	cmdline_fixed_string_t on;
3940 	cmdline_fixed_string_t port_id;
3941 };
3942 
3943 static void
3944 cmd_vlan_offload_parsed(void *parsed_result,
3945 			  __attribute__((unused)) struct cmdline *cl,
3946 			  __attribute__((unused)) void *data)
3947 {
3948 	int on;
3949 	struct cmd_vlan_offload_result *res = parsed_result;
3950 	char *str;
3951 	int i, len = 0;
3952 	portid_t port_id = 0;
3953 	unsigned int tmp;
3954 
3955 	str = res->port_id;
3956 	len = strnlen(str, STR_TOKEN_SIZE);
3957 	i = 0;
3958 	/* Get port_id first */
3959 	while(i < len){
3960 		if(str[i] == ',')
3961 			break;
3962 
3963 		i++;
3964 	}
3965 	str[i]='\0';
3966 	tmp = strtoul(str, NULL, 0);
3967 	/* If port_id greater that what portid_t can represent, return */
3968 	if(tmp >= RTE_MAX_ETHPORTS)
3969 		return;
3970 	port_id = (portid_t)tmp;
3971 
3972 	if (!strcmp(res->on, "on"))
3973 		on = 1;
3974 	else
3975 		on = 0;
3976 
3977 	if (!strcmp(res->what, "strip"))
3978 		rx_vlan_strip_set(port_id,  on);
3979 	else if(!strcmp(res->what, "stripq")){
3980 		uint16_t queue_id = 0;
3981 
3982 		/* No queue_id, return */
3983 		if(i + 1 >= len) {
3984 			printf("must specify (port,queue_id)\n");
3985 			return;
3986 		}
3987 		tmp = strtoul(str + i + 1, NULL, 0);
3988 		/* If queue_id greater that what 16-bits can represent, return */
3989 		if(tmp > 0xffff)
3990 			return;
3991 
3992 		queue_id = (uint16_t)tmp;
3993 		rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3994 	}
3995 	else if (!strcmp(res->what, "filter"))
3996 		rx_vlan_filter_set(port_id, on);
3997 	else
3998 		vlan_extend_set(port_id, on);
3999 
4000 	return;
4001 }
4002 
4003 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4004 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4005 				 vlan, "vlan");
4006 cmdline_parse_token_string_t cmd_vlan_offload_set =
4007 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4008 				 set, "set");
4009 cmdline_parse_token_string_t cmd_vlan_offload_what =
4010 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4011 				 what, "strip#filter#qinq#stripq");
4012 cmdline_parse_token_string_t cmd_vlan_offload_on =
4013 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4014 			      on, "on#off");
4015 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4016 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4017 			      port_id, NULL);
4018 
4019 cmdline_parse_inst_t cmd_vlan_offload = {
4020 	.f = cmd_vlan_offload_parsed,
4021 	.data = NULL,
4022 	.help_str = "vlan set strip|filter|qinq|stripq on|off "
4023 		"<port_id[,queue_id]>: "
4024 		"Filter/Strip for rx side qinq(extended) for both rx/tx sides",
4025 	.tokens = {
4026 		(void *)&cmd_vlan_offload_vlan,
4027 		(void *)&cmd_vlan_offload_set,
4028 		(void *)&cmd_vlan_offload_what,
4029 		(void *)&cmd_vlan_offload_on,
4030 		(void *)&cmd_vlan_offload_portid,
4031 		NULL,
4032 	},
4033 };
4034 
4035 /* *** VLAN TPID SET ON A PORT *** */
4036 struct cmd_vlan_tpid_result {
4037 	cmdline_fixed_string_t vlan;
4038 	cmdline_fixed_string_t set;
4039 	cmdline_fixed_string_t vlan_type;
4040 	cmdline_fixed_string_t what;
4041 	uint16_t tp_id;
4042 	portid_t port_id;
4043 };
4044 
4045 static void
4046 cmd_vlan_tpid_parsed(void *parsed_result,
4047 			  __attribute__((unused)) struct cmdline *cl,
4048 			  __attribute__((unused)) void *data)
4049 {
4050 	struct cmd_vlan_tpid_result *res = parsed_result;
4051 	enum rte_vlan_type vlan_type;
4052 
4053 	if (!strcmp(res->vlan_type, "inner"))
4054 		vlan_type = ETH_VLAN_TYPE_INNER;
4055 	else if (!strcmp(res->vlan_type, "outer"))
4056 		vlan_type = ETH_VLAN_TYPE_OUTER;
4057 	else {
4058 		printf("Unknown vlan type\n");
4059 		return;
4060 	}
4061 	vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4062 }
4063 
4064 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4065 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4066 				 vlan, "vlan");
4067 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4068 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4069 				 set, "set");
4070 cmdline_parse_token_string_t cmd_vlan_type =
4071 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4072 				 vlan_type, "inner#outer");
4073 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4074 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4075 				 what, "tpid");
4076 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4077 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4078 			      tp_id, UINT16);
4079 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4080 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4081 			      port_id, UINT16);
4082 
4083 cmdline_parse_inst_t cmd_vlan_tpid = {
4084 	.f = cmd_vlan_tpid_parsed,
4085 	.data = NULL,
4086 	.help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4087 		"Set the VLAN Ether type",
4088 	.tokens = {
4089 		(void *)&cmd_vlan_tpid_vlan,
4090 		(void *)&cmd_vlan_tpid_set,
4091 		(void *)&cmd_vlan_type,
4092 		(void *)&cmd_vlan_tpid_what,
4093 		(void *)&cmd_vlan_tpid_tpid,
4094 		(void *)&cmd_vlan_tpid_portid,
4095 		NULL,
4096 	},
4097 };
4098 
4099 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4100 struct cmd_rx_vlan_filter_result {
4101 	cmdline_fixed_string_t rx_vlan;
4102 	cmdline_fixed_string_t what;
4103 	uint16_t vlan_id;
4104 	portid_t port_id;
4105 };
4106 
4107 static void
4108 cmd_rx_vlan_filter_parsed(void *parsed_result,
4109 			  __attribute__((unused)) struct cmdline *cl,
4110 			  __attribute__((unused)) void *data)
4111 {
4112 	struct cmd_rx_vlan_filter_result *res = parsed_result;
4113 
4114 	if (!strcmp(res->what, "add"))
4115 		rx_vft_set(res->port_id, res->vlan_id, 1);
4116 	else
4117 		rx_vft_set(res->port_id, res->vlan_id, 0);
4118 }
4119 
4120 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4121 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4122 				 rx_vlan, "rx_vlan");
4123 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4124 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4125 				 what, "add#rm");
4126 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4127 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4128 			      vlan_id, UINT16);
4129 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4130 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4131 			      port_id, UINT16);
4132 
4133 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4134 	.f = cmd_rx_vlan_filter_parsed,
4135 	.data = NULL,
4136 	.help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4137 		"Add/Remove a VLAN identifier to/from the set of VLAN "
4138 		"identifiers filtered by a port",
4139 	.tokens = {
4140 		(void *)&cmd_rx_vlan_filter_rx_vlan,
4141 		(void *)&cmd_rx_vlan_filter_what,
4142 		(void *)&cmd_rx_vlan_filter_vlanid,
4143 		(void *)&cmd_rx_vlan_filter_portid,
4144 		NULL,
4145 	},
4146 };
4147 
4148 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4149 struct cmd_tx_vlan_set_result {
4150 	cmdline_fixed_string_t tx_vlan;
4151 	cmdline_fixed_string_t set;
4152 	portid_t port_id;
4153 	uint16_t vlan_id;
4154 };
4155 
4156 static void
4157 cmd_tx_vlan_set_parsed(void *parsed_result,
4158 		       __attribute__((unused)) struct cmdline *cl,
4159 		       __attribute__((unused)) void *data)
4160 {
4161 	struct cmd_tx_vlan_set_result *res = parsed_result;
4162 
4163 	if (!port_is_stopped(res->port_id)) {
4164 		printf("Please stop port %d first\n", res->port_id);
4165 		return;
4166 	}
4167 
4168 	tx_vlan_set(res->port_id, res->vlan_id);
4169 
4170 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4171 }
4172 
4173 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4174 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4175 				 tx_vlan, "tx_vlan");
4176 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4177 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4178 				 set, "set");
4179 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4180 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4181 			      port_id, UINT16);
4182 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4183 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4184 			      vlan_id, UINT16);
4185 
4186 cmdline_parse_inst_t cmd_tx_vlan_set = {
4187 	.f = cmd_tx_vlan_set_parsed,
4188 	.data = NULL,
4189 	.help_str = "tx_vlan set <port_id> <vlan_id>: "
4190 		"Enable hardware insertion of a single VLAN header "
4191 		"with a given TAG Identifier in packets sent on a port",
4192 	.tokens = {
4193 		(void *)&cmd_tx_vlan_set_tx_vlan,
4194 		(void *)&cmd_tx_vlan_set_set,
4195 		(void *)&cmd_tx_vlan_set_portid,
4196 		(void *)&cmd_tx_vlan_set_vlanid,
4197 		NULL,
4198 	},
4199 };
4200 
4201 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4202 struct cmd_tx_vlan_set_qinq_result {
4203 	cmdline_fixed_string_t tx_vlan;
4204 	cmdline_fixed_string_t set;
4205 	portid_t port_id;
4206 	uint16_t vlan_id;
4207 	uint16_t vlan_id_outer;
4208 };
4209 
4210 static void
4211 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4212 			    __attribute__((unused)) struct cmdline *cl,
4213 			    __attribute__((unused)) void *data)
4214 {
4215 	struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4216 
4217 	if (!port_is_stopped(res->port_id)) {
4218 		printf("Please stop port %d first\n", res->port_id);
4219 		return;
4220 	}
4221 
4222 	tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4223 
4224 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4225 }
4226 
4227 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4228 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4229 		tx_vlan, "tx_vlan");
4230 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4231 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4232 		set, "set");
4233 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4234 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4235 		port_id, UINT16);
4236 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4237 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4238 		vlan_id, UINT16);
4239 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4240 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4241 		vlan_id_outer, UINT16);
4242 
4243 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4244 	.f = cmd_tx_vlan_set_qinq_parsed,
4245 	.data = NULL,
4246 	.help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4247 		"Enable hardware insertion of double VLAN header "
4248 		"with given TAG Identifiers in packets sent on a port",
4249 	.tokens = {
4250 		(void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4251 		(void *)&cmd_tx_vlan_set_qinq_set,
4252 		(void *)&cmd_tx_vlan_set_qinq_portid,
4253 		(void *)&cmd_tx_vlan_set_qinq_vlanid,
4254 		(void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4255 		NULL,
4256 	},
4257 };
4258 
4259 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4260 struct cmd_tx_vlan_set_pvid_result {
4261 	cmdline_fixed_string_t tx_vlan;
4262 	cmdline_fixed_string_t set;
4263 	cmdline_fixed_string_t pvid;
4264 	portid_t port_id;
4265 	uint16_t vlan_id;
4266 	cmdline_fixed_string_t mode;
4267 };
4268 
4269 static void
4270 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4271 			    __attribute__((unused)) struct cmdline *cl,
4272 			    __attribute__((unused)) void *data)
4273 {
4274 	struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4275 
4276 	if (strcmp(res->mode, "on") == 0)
4277 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4278 	else
4279 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4280 }
4281 
4282 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4283 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4284 				 tx_vlan, "tx_vlan");
4285 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4286 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4287 				 set, "set");
4288 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4289 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4290 				 pvid, "pvid");
4291 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4292 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4293 			     port_id, UINT16);
4294 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4295 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4296 			      vlan_id, UINT16);
4297 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4298 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4299 				 mode, "on#off");
4300 
4301 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4302 	.f = cmd_tx_vlan_set_pvid_parsed,
4303 	.data = NULL,
4304 	.help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4305 	.tokens = {
4306 		(void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4307 		(void *)&cmd_tx_vlan_set_pvid_set,
4308 		(void *)&cmd_tx_vlan_set_pvid_pvid,
4309 		(void *)&cmd_tx_vlan_set_pvid_port_id,
4310 		(void *)&cmd_tx_vlan_set_pvid_vlan_id,
4311 		(void *)&cmd_tx_vlan_set_pvid_mode,
4312 		NULL,
4313 	},
4314 };
4315 
4316 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4317 struct cmd_tx_vlan_reset_result {
4318 	cmdline_fixed_string_t tx_vlan;
4319 	cmdline_fixed_string_t reset;
4320 	portid_t port_id;
4321 };
4322 
4323 static void
4324 cmd_tx_vlan_reset_parsed(void *parsed_result,
4325 			 __attribute__((unused)) struct cmdline *cl,
4326 			 __attribute__((unused)) void *data)
4327 {
4328 	struct cmd_tx_vlan_reset_result *res = parsed_result;
4329 
4330 	if (!port_is_stopped(res->port_id)) {
4331 		printf("Please stop port %d first\n", res->port_id);
4332 		return;
4333 	}
4334 
4335 	tx_vlan_reset(res->port_id);
4336 
4337 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4338 }
4339 
4340 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4341 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4342 				 tx_vlan, "tx_vlan");
4343 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4344 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4345 				 reset, "reset");
4346 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4347 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4348 			      port_id, UINT16);
4349 
4350 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4351 	.f = cmd_tx_vlan_reset_parsed,
4352 	.data = NULL,
4353 	.help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4354 		"VLAN header in packets sent on a port",
4355 	.tokens = {
4356 		(void *)&cmd_tx_vlan_reset_tx_vlan,
4357 		(void *)&cmd_tx_vlan_reset_reset,
4358 		(void *)&cmd_tx_vlan_reset_portid,
4359 		NULL,
4360 	},
4361 };
4362 
4363 
4364 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4365 struct cmd_csum_result {
4366 	cmdline_fixed_string_t csum;
4367 	cmdline_fixed_string_t mode;
4368 	cmdline_fixed_string_t proto;
4369 	cmdline_fixed_string_t hwsw;
4370 	portid_t port_id;
4371 };
4372 
4373 static void
4374 csum_show(int port_id)
4375 {
4376 	struct rte_eth_dev_info dev_info;
4377 	uint64_t tx_offloads;
4378 
4379 	tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4380 	printf("Parse tunnel is %s\n",
4381 		(ports[port_id].parse_tunnel) ? "on" : "off");
4382 	printf("IP checksum offload is %s\n",
4383 		(tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4384 	printf("UDP checksum offload is %s\n",
4385 		(tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4386 	printf("TCP checksum offload is %s\n",
4387 		(tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4388 	printf("SCTP checksum offload is %s\n",
4389 		(tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4390 	printf("Outer-Ip checksum offload is %s\n",
4391 		(tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4392 	printf("Outer-Udp checksum offload is %s\n",
4393 		(tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4394 
4395 	/* display warnings if configuration is not supported by the NIC */
4396 	rte_eth_dev_info_get(port_id, &dev_info);
4397 	if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4398 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4399 		printf("Warning: hardware IP checksum enabled but not "
4400 			"supported by port %d\n", port_id);
4401 	}
4402 	if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4403 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4404 		printf("Warning: hardware UDP checksum enabled but not "
4405 			"supported by port %d\n", port_id);
4406 	}
4407 	if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4408 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4409 		printf("Warning: hardware TCP checksum enabled but not "
4410 			"supported by port %d\n", port_id);
4411 	}
4412 	if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4413 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4414 		printf("Warning: hardware SCTP checksum enabled but not "
4415 			"supported by port %d\n", port_id);
4416 	}
4417 	if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4418 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4419 		printf("Warning: hardware outer IP checksum enabled but not "
4420 			"supported by port %d\n", port_id);
4421 	}
4422 	if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4423 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4424 			== 0) {
4425 		printf("Warning: hardware outer UDP checksum enabled but not "
4426 			"supported by port %d\n", port_id);
4427 	}
4428 }
4429 
4430 static void
4431 cmd_config_queue_tx_offloads(struct rte_port *port)
4432 {
4433 	int k;
4434 
4435 	/* Apply queue tx offloads configuration */
4436 	for (k = 0; k < port->dev_info.max_rx_queues; k++)
4437 		port->tx_conf[k].offloads =
4438 			port->dev_conf.txmode.offloads;
4439 }
4440 
4441 static void
4442 cmd_csum_parsed(void *parsed_result,
4443 		       __attribute__((unused)) struct cmdline *cl,
4444 		       __attribute__((unused)) void *data)
4445 {
4446 	struct cmd_csum_result *res = parsed_result;
4447 	int hw = 0;
4448 	uint64_t csum_offloads = 0;
4449 	struct rte_eth_dev_info dev_info;
4450 
4451 	if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4452 		printf("invalid port %d\n", res->port_id);
4453 		return;
4454 	}
4455 	if (!port_is_stopped(res->port_id)) {
4456 		printf("Please stop port %d first\n", res->port_id);
4457 		return;
4458 	}
4459 
4460 	rte_eth_dev_info_get(res->port_id, &dev_info);
4461 	if (!strcmp(res->mode, "set")) {
4462 
4463 		if (!strcmp(res->hwsw, "hw"))
4464 			hw = 1;
4465 
4466 		if (!strcmp(res->proto, "ip")) {
4467 			if (hw == 0 || (dev_info.tx_offload_capa &
4468 						DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4469 				csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4470 			} else {
4471 				printf("IP checksum offload is not supported "
4472 				       "by port %u\n", res->port_id);
4473 			}
4474 		} else if (!strcmp(res->proto, "udp")) {
4475 			if (hw == 0 || (dev_info.tx_offload_capa &
4476 						DEV_TX_OFFLOAD_UDP_CKSUM)) {
4477 				csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4478 			} else {
4479 				printf("UDP checksum offload is not supported "
4480 				       "by port %u\n", res->port_id);
4481 			}
4482 		} else if (!strcmp(res->proto, "tcp")) {
4483 			if (hw == 0 || (dev_info.tx_offload_capa &
4484 						DEV_TX_OFFLOAD_TCP_CKSUM)) {
4485 				csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4486 			} else {
4487 				printf("TCP checksum offload is not supported "
4488 				       "by port %u\n", res->port_id);
4489 			}
4490 		} else if (!strcmp(res->proto, "sctp")) {
4491 			if (hw == 0 || (dev_info.tx_offload_capa &
4492 						DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4493 				csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4494 			} else {
4495 				printf("SCTP checksum offload is not supported "
4496 				       "by port %u\n", res->port_id);
4497 			}
4498 		} else if (!strcmp(res->proto, "outer-ip")) {
4499 			if (hw == 0 || (dev_info.tx_offload_capa &
4500 					DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4501 				csum_offloads |=
4502 						DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4503 			} else {
4504 				printf("Outer IP checksum offload is not "
4505 				       "supported by port %u\n", res->port_id);
4506 			}
4507 		} else if (!strcmp(res->proto, "outer-udp")) {
4508 			if (hw == 0 || (dev_info.tx_offload_capa &
4509 					DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4510 				csum_offloads |=
4511 						DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4512 			} else {
4513 				printf("Outer UDP checksum offload is not "
4514 				       "supported by port %u\n", res->port_id);
4515 			}
4516 		}
4517 
4518 		if (hw) {
4519 			ports[res->port_id].dev_conf.txmode.offloads |=
4520 							csum_offloads;
4521 		} else {
4522 			ports[res->port_id].dev_conf.txmode.offloads &=
4523 							(~csum_offloads);
4524 		}
4525 		cmd_config_queue_tx_offloads(&ports[res->port_id]);
4526 	}
4527 	csum_show(res->port_id);
4528 
4529 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4530 }
4531 
4532 cmdline_parse_token_string_t cmd_csum_csum =
4533 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4534 				csum, "csum");
4535 cmdline_parse_token_string_t cmd_csum_mode =
4536 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4537 				mode, "set");
4538 cmdline_parse_token_string_t cmd_csum_proto =
4539 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4540 				proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4541 cmdline_parse_token_string_t cmd_csum_hwsw =
4542 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4543 				hwsw, "hw#sw");
4544 cmdline_parse_token_num_t cmd_csum_portid =
4545 	TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4546 				port_id, UINT16);
4547 
4548 cmdline_parse_inst_t cmd_csum_set = {
4549 	.f = cmd_csum_parsed,
4550 	.data = NULL,
4551 	.help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4552 		"Enable/Disable hardware calculation of L3/L4 checksum when "
4553 		"using csum forward engine",
4554 	.tokens = {
4555 		(void *)&cmd_csum_csum,
4556 		(void *)&cmd_csum_mode,
4557 		(void *)&cmd_csum_proto,
4558 		(void *)&cmd_csum_hwsw,
4559 		(void *)&cmd_csum_portid,
4560 		NULL,
4561 	},
4562 };
4563 
4564 cmdline_parse_token_string_t cmd_csum_mode_show =
4565 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4566 				mode, "show");
4567 
4568 cmdline_parse_inst_t cmd_csum_show = {
4569 	.f = cmd_csum_parsed,
4570 	.data = NULL,
4571 	.help_str = "csum show <port_id>: Show checksum offload configuration",
4572 	.tokens = {
4573 		(void *)&cmd_csum_csum,
4574 		(void *)&cmd_csum_mode_show,
4575 		(void *)&cmd_csum_portid,
4576 		NULL,
4577 	},
4578 };
4579 
4580 /* Enable/disable tunnel parsing */
4581 struct cmd_csum_tunnel_result {
4582 	cmdline_fixed_string_t csum;
4583 	cmdline_fixed_string_t parse;
4584 	cmdline_fixed_string_t onoff;
4585 	portid_t port_id;
4586 };
4587 
4588 static void
4589 cmd_csum_tunnel_parsed(void *parsed_result,
4590 		       __attribute__((unused)) struct cmdline *cl,
4591 		       __attribute__((unused)) void *data)
4592 {
4593 	struct cmd_csum_tunnel_result *res = parsed_result;
4594 
4595 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4596 		return;
4597 
4598 	if (!strcmp(res->onoff, "on"))
4599 		ports[res->port_id].parse_tunnel = 1;
4600 	else
4601 		ports[res->port_id].parse_tunnel = 0;
4602 
4603 	csum_show(res->port_id);
4604 }
4605 
4606 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4607 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4608 				csum, "csum");
4609 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4610 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4611 				parse, "parse-tunnel");
4612 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4613 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4614 				onoff, "on#off");
4615 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4616 	TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4617 				port_id, UINT16);
4618 
4619 cmdline_parse_inst_t cmd_csum_tunnel = {
4620 	.f = cmd_csum_tunnel_parsed,
4621 	.data = NULL,
4622 	.help_str = "csum parse-tunnel on|off <port_id>: "
4623 		"Enable/Disable parsing of tunnels for csum engine",
4624 	.tokens = {
4625 		(void *)&cmd_csum_tunnel_csum,
4626 		(void *)&cmd_csum_tunnel_parse,
4627 		(void *)&cmd_csum_tunnel_onoff,
4628 		(void *)&cmd_csum_tunnel_portid,
4629 		NULL,
4630 	},
4631 };
4632 
4633 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4634 struct cmd_tso_set_result {
4635 	cmdline_fixed_string_t tso;
4636 	cmdline_fixed_string_t mode;
4637 	uint16_t tso_segsz;
4638 	portid_t port_id;
4639 };
4640 
4641 static void
4642 cmd_tso_set_parsed(void *parsed_result,
4643 		       __attribute__((unused)) struct cmdline *cl,
4644 		       __attribute__((unused)) void *data)
4645 {
4646 	struct cmd_tso_set_result *res = parsed_result;
4647 	struct rte_eth_dev_info dev_info;
4648 
4649 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4650 		return;
4651 	if (!port_is_stopped(res->port_id)) {
4652 		printf("Please stop port %d first\n", res->port_id);
4653 		return;
4654 	}
4655 
4656 	if (!strcmp(res->mode, "set"))
4657 		ports[res->port_id].tso_segsz = res->tso_segsz;
4658 
4659 	rte_eth_dev_info_get(res->port_id, &dev_info);
4660 	if ((ports[res->port_id].tso_segsz != 0) &&
4661 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4662 		printf("Error: TSO is not supported by port %d\n",
4663 		       res->port_id);
4664 		return;
4665 	}
4666 
4667 	if (ports[res->port_id].tso_segsz == 0) {
4668 		ports[res->port_id].dev_conf.txmode.offloads &=
4669 						~DEV_TX_OFFLOAD_TCP_TSO;
4670 		printf("TSO for non-tunneled packets is disabled\n");
4671 	} else {
4672 		ports[res->port_id].dev_conf.txmode.offloads |=
4673 						DEV_TX_OFFLOAD_TCP_TSO;
4674 		printf("TSO segment size for non-tunneled packets is %d\n",
4675 			ports[res->port_id].tso_segsz);
4676 	}
4677 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
4678 
4679 	/* display warnings if configuration is not supported by the NIC */
4680 	rte_eth_dev_info_get(res->port_id, &dev_info);
4681 	if ((ports[res->port_id].tso_segsz != 0) &&
4682 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4683 		printf("Warning: TSO enabled but not "
4684 			"supported by port %d\n", res->port_id);
4685 	}
4686 
4687 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4688 }
4689 
4690 cmdline_parse_token_string_t cmd_tso_set_tso =
4691 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4692 				tso, "tso");
4693 cmdline_parse_token_string_t cmd_tso_set_mode =
4694 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4695 				mode, "set");
4696 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4697 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4698 				tso_segsz, UINT16);
4699 cmdline_parse_token_num_t cmd_tso_set_portid =
4700 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4701 				port_id, UINT16);
4702 
4703 cmdline_parse_inst_t cmd_tso_set = {
4704 	.f = cmd_tso_set_parsed,
4705 	.data = NULL,
4706 	.help_str = "tso set <tso_segsz> <port_id>: "
4707 		"Set TSO segment size of non-tunneled packets for csum engine "
4708 		"(0 to disable)",
4709 	.tokens = {
4710 		(void *)&cmd_tso_set_tso,
4711 		(void *)&cmd_tso_set_mode,
4712 		(void *)&cmd_tso_set_tso_segsz,
4713 		(void *)&cmd_tso_set_portid,
4714 		NULL,
4715 	},
4716 };
4717 
4718 cmdline_parse_token_string_t cmd_tso_show_mode =
4719 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4720 				mode, "show");
4721 
4722 
4723 cmdline_parse_inst_t cmd_tso_show = {
4724 	.f = cmd_tso_set_parsed,
4725 	.data = NULL,
4726 	.help_str = "tso show <port_id>: "
4727 		"Show TSO segment size of non-tunneled packets for csum engine",
4728 	.tokens = {
4729 		(void *)&cmd_tso_set_tso,
4730 		(void *)&cmd_tso_show_mode,
4731 		(void *)&cmd_tso_set_portid,
4732 		NULL,
4733 	},
4734 };
4735 
4736 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4737 struct cmd_tunnel_tso_set_result {
4738 	cmdline_fixed_string_t tso;
4739 	cmdline_fixed_string_t mode;
4740 	uint16_t tso_segsz;
4741 	portid_t port_id;
4742 };
4743 
4744 static struct rte_eth_dev_info
4745 check_tunnel_tso_nic_support(portid_t port_id)
4746 {
4747 	struct rte_eth_dev_info dev_info;
4748 
4749 	rte_eth_dev_info_get(port_id, &dev_info);
4750 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4751 		printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4752 		       "not enabled for port %d\n", port_id);
4753 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4754 		printf("Warning: GRE TUNNEL TSO	not supported therefore "
4755 		       "not enabled for port %d\n", port_id);
4756 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4757 		printf("Warning: IPIP TUNNEL TSO not supported therefore "
4758 		       "not enabled for port %d\n", port_id);
4759 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4760 		printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4761 		       "not enabled for port %d\n", port_id);
4762 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4763 		printf("Warning: IP TUNNEL TSO not supported therefore "
4764 		       "not enabled for port %d\n", port_id);
4765 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4766 		printf("Warning: UDP TUNNEL TSO not supported therefore "
4767 		       "not enabled for port %d\n", port_id);
4768 	return dev_info;
4769 }
4770 
4771 static void
4772 cmd_tunnel_tso_set_parsed(void *parsed_result,
4773 			  __attribute__((unused)) struct cmdline *cl,
4774 			  __attribute__((unused)) void *data)
4775 {
4776 	struct cmd_tunnel_tso_set_result *res = parsed_result;
4777 	struct rte_eth_dev_info dev_info;
4778 
4779 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4780 		return;
4781 	if (!port_is_stopped(res->port_id)) {
4782 		printf("Please stop port %d first\n", res->port_id);
4783 		return;
4784 	}
4785 
4786 	if (!strcmp(res->mode, "set"))
4787 		ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4788 
4789 	dev_info = check_tunnel_tso_nic_support(res->port_id);
4790 	if (ports[res->port_id].tunnel_tso_segsz == 0) {
4791 		ports[res->port_id].dev_conf.txmode.offloads &=
4792 			~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4793 			  DEV_TX_OFFLOAD_GRE_TNL_TSO |
4794 			  DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4795 			  DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4796 			  DEV_TX_OFFLOAD_IP_TNL_TSO |
4797 			  DEV_TX_OFFLOAD_UDP_TNL_TSO);
4798 		printf("TSO for tunneled packets is disabled\n");
4799 	} else {
4800 		uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4801 					 DEV_TX_OFFLOAD_GRE_TNL_TSO |
4802 					 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4803 					 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4804 					 DEV_TX_OFFLOAD_IP_TNL_TSO |
4805 					 DEV_TX_OFFLOAD_UDP_TNL_TSO);
4806 
4807 		ports[res->port_id].dev_conf.txmode.offloads |=
4808 			(tso_offloads & dev_info.tx_offload_capa);
4809 		printf("TSO segment size for tunneled packets is %d\n",
4810 			ports[res->port_id].tunnel_tso_segsz);
4811 
4812 		/* Below conditions are needed to make it work:
4813 		 * (1) tunnel TSO is supported by the NIC;
4814 		 * (2) "csum parse_tunnel" must be set so that tunneled pkts
4815 		 * are recognized;
4816 		 * (3) for tunneled pkts with outer L3 of IPv4,
4817 		 * "csum set outer-ip" must be set to hw, because after tso,
4818 		 * total_len of outer IP header is changed, and the checksum
4819 		 * of outer IP header calculated by sw should be wrong; that
4820 		 * is not necessary for IPv6 tunneled pkts because there's no
4821 		 * checksum in IP header anymore.
4822 		 */
4823 
4824 		if (!ports[res->port_id].parse_tunnel)
4825 			printf("Warning: csum parse_tunnel must be set "
4826 				"so that tunneled packets are recognized\n");
4827 		if (!(ports[res->port_id].dev_conf.txmode.offloads &
4828 		      DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4829 			printf("Warning: csum set outer-ip must be set to hw "
4830 				"if outer L3 is IPv4; not necessary for IPv6\n");
4831 	}
4832 
4833 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
4834 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4835 }
4836 
4837 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4838 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4839 				tso, "tunnel_tso");
4840 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4841 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4842 				mode, "set");
4843 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4844 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4845 				tso_segsz, UINT16);
4846 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4847 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4848 				port_id, UINT16);
4849 
4850 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4851 	.f = cmd_tunnel_tso_set_parsed,
4852 	.data = NULL,
4853 	.help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4854 		"Set TSO segment size of tunneled packets for csum engine "
4855 		"(0 to disable)",
4856 	.tokens = {
4857 		(void *)&cmd_tunnel_tso_set_tso,
4858 		(void *)&cmd_tunnel_tso_set_mode,
4859 		(void *)&cmd_tunnel_tso_set_tso_segsz,
4860 		(void *)&cmd_tunnel_tso_set_portid,
4861 		NULL,
4862 	},
4863 };
4864 
4865 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4866 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4867 				mode, "show");
4868 
4869 
4870 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4871 	.f = cmd_tunnel_tso_set_parsed,
4872 	.data = NULL,
4873 	.help_str = "tunnel_tso show <port_id> "
4874 		"Show TSO segment size of tunneled packets for csum engine",
4875 	.tokens = {
4876 		(void *)&cmd_tunnel_tso_set_tso,
4877 		(void *)&cmd_tunnel_tso_show_mode,
4878 		(void *)&cmd_tunnel_tso_set_portid,
4879 		NULL,
4880 	},
4881 };
4882 
4883 /* *** SET GRO FOR A PORT *** */
4884 struct cmd_gro_enable_result {
4885 	cmdline_fixed_string_t cmd_set;
4886 	cmdline_fixed_string_t cmd_port;
4887 	cmdline_fixed_string_t cmd_keyword;
4888 	cmdline_fixed_string_t cmd_onoff;
4889 	portid_t cmd_pid;
4890 };
4891 
4892 static void
4893 cmd_gro_enable_parsed(void *parsed_result,
4894 		__attribute__((unused)) struct cmdline *cl,
4895 		__attribute__((unused)) void *data)
4896 {
4897 	struct cmd_gro_enable_result *res;
4898 
4899 	res = parsed_result;
4900 	if (!strcmp(res->cmd_keyword, "gro"))
4901 		setup_gro(res->cmd_onoff, res->cmd_pid);
4902 }
4903 
4904 cmdline_parse_token_string_t cmd_gro_enable_set =
4905 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4906 			cmd_set, "set");
4907 cmdline_parse_token_string_t cmd_gro_enable_port =
4908 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4909 			cmd_keyword, "port");
4910 cmdline_parse_token_num_t cmd_gro_enable_pid =
4911 	TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4912 			cmd_pid, UINT16);
4913 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4914 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4915 			cmd_keyword, "gro");
4916 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4917 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4918 			cmd_onoff, "on#off");
4919 
4920 cmdline_parse_inst_t cmd_gro_enable = {
4921 	.f = cmd_gro_enable_parsed,
4922 	.data = NULL,
4923 	.help_str = "set port <port_id> gro on|off",
4924 	.tokens = {
4925 		(void *)&cmd_gro_enable_set,
4926 		(void *)&cmd_gro_enable_port,
4927 		(void *)&cmd_gro_enable_pid,
4928 		(void *)&cmd_gro_enable_keyword,
4929 		(void *)&cmd_gro_enable_onoff,
4930 		NULL,
4931 	},
4932 };
4933 
4934 /* *** DISPLAY GRO CONFIGURATION *** */
4935 struct cmd_gro_show_result {
4936 	cmdline_fixed_string_t cmd_show;
4937 	cmdline_fixed_string_t cmd_port;
4938 	cmdline_fixed_string_t cmd_keyword;
4939 	portid_t cmd_pid;
4940 };
4941 
4942 static void
4943 cmd_gro_show_parsed(void *parsed_result,
4944 		__attribute__((unused)) struct cmdline *cl,
4945 		__attribute__((unused)) void *data)
4946 {
4947 	struct cmd_gro_show_result *res;
4948 
4949 	res = parsed_result;
4950 	if (!strcmp(res->cmd_keyword, "gro"))
4951 		show_gro(res->cmd_pid);
4952 }
4953 
4954 cmdline_parse_token_string_t cmd_gro_show_show =
4955 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4956 			cmd_show, "show");
4957 cmdline_parse_token_string_t cmd_gro_show_port =
4958 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4959 			cmd_port, "port");
4960 cmdline_parse_token_num_t cmd_gro_show_pid =
4961 	TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4962 			cmd_pid, UINT16);
4963 cmdline_parse_token_string_t cmd_gro_show_keyword =
4964 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4965 			cmd_keyword, "gro");
4966 
4967 cmdline_parse_inst_t cmd_gro_show = {
4968 	.f = cmd_gro_show_parsed,
4969 	.data = NULL,
4970 	.help_str = "show port <port_id> gro",
4971 	.tokens = {
4972 		(void *)&cmd_gro_show_show,
4973 		(void *)&cmd_gro_show_port,
4974 		(void *)&cmd_gro_show_pid,
4975 		(void *)&cmd_gro_show_keyword,
4976 		NULL,
4977 	},
4978 };
4979 
4980 /* *** SET FLUSH CYCLES FOR GRO *** */
4981 struct cmd_gro_flush_result {
4982 	cmdline_fixed_string_t cmd_set;
4983 	cmdline_fixed_string_t cmd_keyword;
4984 	cmdline_fixed_string_t cmd_flush;
4985 	uint8_t cmd_cycles;
4986 };
4987 
4988 static void
4989 cmd_gro_flush_parsed(void *parsed_result,
4990 		__attribute__((unused)) struct cmdline *cl,
4991 		__attribute__((unused)) void *data)
4992 {
4993 	struct cmd_gro_flush_result *res;
4994 
4995 	res = parsed_result;
4996 	if ((!strcmp(res->cmd_keyword, "gro")) &&
4997 			(!strcmp(res->cmd_flush, "flush")))
4998 		setup_gro_flush_cycles(res->cmd_cycles);
4999 }
5000 
5001 cmdline_parse_token_string_t cmd_gro_flush_set =
5002 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5003 			cmd_set, "set");
5004 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5005 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5006 			cmd_keyword, "gro");
5007 cmdline_parse_token_string_t cmd_gro_flush_flush =
5008 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5009 			cmd_flush, "flush");
5010 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5011 	TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5012 			cmd_cycles, UINT8);
5013 
5014 cmdline_parse_inst_t cmd_gro_flush = {
5015 	.f = cmd_gro_flush_parsed,
5016 	.data = NULL,
5017 	.help_str = "set gro flush <cycles>",
5018 	.tokens = {
5019 		(void *)&cmd_gro_flush_set,
5020 		(void *)&cmd_gro_flush_keyword,
5021 		(void *)&cmd_gro_flush_flush,
5022 		(void *)&cmd_gro_flush_cycles,
5023 		NULL,
5024 	},
5025 };
5026 
5027 /* *** ENABLE/DISABLE GSO *** */
5028 struct cmd_gso_enable_result {
5029 	cmdline_fixed_string_t cmd_set;
5030 	cmdline_fixed_string_t cmd_port;
5031 	cmdline_fixed_string_t cmd_keyword;
5032 	cmdline_fixed_string_t cmd_mode;
5033 	portid_t cmd_pid;
5034 };
5035 
5036 static void
5037 cmd_gso_enable_parsed(void *parsed_result,
5038 		__attribute__((unused)) struct cmdline *cl,
5039 		__attribute__((unused)) void *data)
5040 {
5041 	struct cmd_gso_enable_result *res;
5042 
5043 	res = parsed_result;
5044 	if (!strcmp(res->cmd_keyword, "gso"))
5045 		setup_gso(res->cmd_mode, res->cmd_pid);
5046 }
5047 
5048 cmdline_parse_token_string_t cmd_gso_enable_set =
5049 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5050 			cmd_set, "set");
5051 cmdline_parse_token_string_t cmd_gso_enable_port =
5052 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5053 			cmd_port, "port");
5054 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5055 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5056 			cmd_keyword, "gso");
5057 cmdline_parse_token_string_t cmd_gso_enable_mode =
5058 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5059 			cmd_mode, "on#off");
5060 cmdline_parse_token_num_t cmd_gso_enable_pid =
5061 	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5062 			cmd_pid, UINT16);
5063 
5064 cmdline_parse_inst_t cmd_gso_enable = {
5065 	.f = cmd_gso_enable_parsed,
5066 	.data = NULL,
5067 	.help_str = "set port <port_id> gso on|off",
5068 	.tokens = {
5069 		(void *)&cmd_gso_enable_set,
5070 		(void *)&cmd_gso_enable_port,
5071 		(void *)&cmd_gso_enable_pid,
5072 		(void *)&cmd_gso_enable_keyword,
5073 		(void *)&cmd_gso_enable_mode,
5074 		NULL,
5075 	},
5076 };
5077 
5078 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5079 struct cmd_gso_size_result {
5080 	cmdline_fixed_string_t cmd_set;
5081 	cmdline_fixed_string_t cmd_keyword;
5082 	cmdline_fixed_string_t cmd_segsz;
5083 	uint16_t cmd_size;
5084 };
5085 
5086 static void
5087 cmd_gso_size_parsed(void *parsed_result,
5088 		       __attribute__((unused)) struct cmdline *cl,
5089 		       __attribute__((unused)) void *data)
5090 {
5091 	struct cmd_gso_size_result *res = parsed_result;
5092 
5093 	if (test_done == 0) {
5094 		printf("Before setting GSO segsz, please first"
5095 				" stop fowarding\n");
5096 		return;
5097 	}
5098 
5099 	if (!strcmp(res->cmd_keyword, "gso") &&
5100 			!strcmp(res->cmd_segsz, "segsz")) {
5101 		if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5102 			printf("gso_size should be larger than %zu."
5103 					" Please input a legal value\n",
5104 					RTE_GSO_SEG_SIZE_MIN);
5105 		else
5106 			gso_max_segment_size = res->cmd_size;
5107 	}
5108 }
5109 
5110 cmdline_parse_token_string_t cmd_gso_size_set =
5111 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5112 				cmd_set, "set");
5113 cmdline_parse_token_string_t cmd_gso_size_keyword =
5114 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5115 				cmd_keyword, "gso");
5116 cmdline_parse_token_string_t cmd_gso_size_segsz =
5117 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5118 				cmd_segsz, "segsz");
5119 cmdline_parse_token_num_t cmd_gso_size_size =
5120 	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5121 				cmd_size, UINT16);
5122 
5123 cmdline_parse_inst_t cmd_gso_size = {
5124 	.f = cmd_gso_size_parsed,
5125 	.data = NULL,
5126 	.help_str = "set gso segsz <length>",
5127 	.tokens = {
5128 		(void *)&cmd_gso_size_set,
5129 		(void *)&cmd_gso_size_keyword,
5130 		(void *)&cmd_gso_size_segsz,
5131 		(void *)&cmd_gso_size_size,
5132 		NULL,
5133 	},
5134 };
5135 
5136 /* *** SHOW GSO CONFIGURATION *** */
5137 struct cmd_gso_show_result {
5138 	cmdline_fixed_string_t cmd_show;
5139 	cmdline_fixed_string_t cmd_port;
5140 	cmdline_fixed_string_t cmd_keyword;
5141 	portid_t cmd_pid;
5142 };
5143 
5144 static void
5145 cmd_gso_show_parsed(void *parsed_result,
5146 		       __attribute__((unused)) struct cmdline *cl,
5147 		       __attribute__((unused)) void *data)
5148 {
5149 	struct cmd_gso_show_result *res = parsed_result;
5150 
5151 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5152 		printf("invalid port id %u\n", res->cmd_pid);
5153 		return;
5154 	}
5155 	if (!strcmp(res->cmd_keyword, "gso")) {
5156 		if (gso_ports[res->cmd_pid].enable) {
5157 			printf("Max GSO'd packet size: %uB\n"
5158 					"Supported GSO types: TCP/IPv4, "
5159 					"UDP/IPv4, VxLAN with inner "
5160 					"TCP/IPv4 packet, GRE with inner "
5161 					"TCP/IPv4 packet\n",
5162 					gso_max_segment_size);
5163 		} else
5164 			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5165 	}
5166 }
5167 
5168 cmdline_parse_token_string_t cmd_gso_show_show =
5169 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5170 		cmd_show, "show");
5171 cmdline_parse_token_string_t cmd_gso_show_port =
5172 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5173 		cmd_port, "port");
5174 cmdline_parse_token_string_t cmd_gso_show_keyword =
5175 	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5176 				cmd_keyword, "gso");
5177 cmdline_parse_token_num_t cmd_gso_show_pid =
5178 	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5179 				cmd_pid, UINT16);
5180 
5181 cmdline_parse_inst_t cmd_gso_show = {
5182 	.f = cmd_gso_show_parsed,
5183 	.data = NULL,
5184 	.help_str = "show port <port_id> gso",
5185 	.tokens = {
5186 		(void *)&cmd_gso_show_show,
5187 		(void *)&cmd_gso_show_port,
5188 		(void *)&cmd_gso_show_pid,
5189 		(void *)&cmd_gso_show_keyword,
5190 		NULL,
5191 	},
5192 };
5193 
5194 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5195 struct cmd_set_flush_rx {
5196 	cmdline_fixed_string_t set;
5197 	cmdline_fixed_string_t flush_rx;
5198 	cmdline_fixed_string_t mode;
5199 };
5200 
5201 static void
5202 cmd_set_flush_rx_parsed(void *parsed_result,
5203 		__attribute__((unused)) struct cmdline *cl,
5204 		__attribute__((unused)) void *data)
5205 {
5206 	struct cmd_set_flush_rx *res = parsed_result;
5207 	no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5208 }
5209 
5210 cmdline_parse_token_string_t cmd_setflushrx_set =
5211 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5212 			set, "set");
5213 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5214 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5215 			flush_rx, "flush_rx");
5216 cmdline_parse_token_string_t cmd_setflushrx_mode =
5217 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5218 			mode, "on#off");
5219 
5220 
5221 cmdline_parse_inst_t cmd_set_flush_rx = {
5222 	.f = cmd_set_flush_rx_parsed,
5223 	.help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5224 	.data = NULL,
5225 	.tokens = {
5226 		(void *)&cmd_setflushrx_set,
5227 		(void *)&cmd_setflushrx_flush_rx,
5228 		(void *)&cmd_setflushrx_mode,
5229 		NULL,
5230 	},
5231 };
5232 
5233 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5234 struct cmd_set_link_check {
5235 	cmdline_fixed_string_t set;
5236 	cmdline_fixed_string_t link_check;
5237 	cmdline_fixed_string_t mode;
5238 };
5239 
5240 static void
5241 cmd_set_link_check_parsed(void *parsed_result,
5242 		__attribute__((unused)) struct cmdline *cl,
5243 		__attribute__((unused)) void *data)
5244 {
5245 	struct cmd_set_link_check *res = parsed_result;
5246 	no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5247 }
5248 
5249 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5250 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5251 			set, "set");
5252 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5253 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5254 			link_check, "link_check");
5255 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5256 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5257 			mode, "on#off");
5258 
5259 
5260 cmdline_parse_inst_t cmd_set_link_check = {
5261 	.f = cmd_set_link_check_parsed,
5262 	.help_str = "set link_check on|off: Enable/Disable link status check "
5263 	            "when starting/stopping a port",
5264 	.data = NULL,
5265 	.tokens = {
5266 		(void *)&cmd_setlinkcheck_set,
5267 		(void *)&cmd_setlinkcheck_link_check,
5268 		(void *)&cmd_setlinkcheck_mode,
5269 		NULL,
5270 	},
5271 };
5272 
5273 /* *** SET NIC BYPASS MODE *** */
5274 struct cmd_set_bypass_mode_result {
5275 	cmdline_fixed_string_t set;
5276 	cmdline_fixed_string_t bypass;
5277 	cmdline_fixed_string_t mode;
5278 	cmdline_fixed_string_t value;
5279 	portid_t port_id;
5280 };
5281 
5282 static void
5283 cmd_set_bypass_mode_parsed(void *parsed_result,
5284 		__attribute__((unused)) struct cmdline *cl,
5285 		__attribute__((unused)) void *data)
5286 {
5287 	struct cmd_set_bypass_mode_result *res = parsed_result;
5288 	portid_t port_id = res->port_id;
5289 	int32_t rc = -EINVAL;
5290 
5291 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5292 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5293 
5294 	if (!strcmp(res->value, "bypass"))
5295 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5296 	else if (!strcmp(res->value, "isolate"))
5297 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5298 	else
5299 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5300 
5301 	/* Set the bypass mode for the relevant port. */
5302 	rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5303 #endif
5304 	if (rc != 0)
5305 		printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5306 }
5307 
5308 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5309 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5310 			set, "set");
5311 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5312 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5313 			bypass, "bypass");
5314 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5315 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5316 			mode, "mode");
5317 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5318 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5319 			value, "normal#bypass#isolate");
5320 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5321 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5322 				port_id, UINT16);
5323 
5324 cmdline_parse_inst_t cmd_set_bypass_mode = {
5325 	.f = cmd_set_bypass_mode_parsed,
5326 	.help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5327 	            "Set the NIC bypass mode for port_id",
5328 	.data = NULL,
5329 	.tokens = {
5330 		(void *)&cmd_setbypass_mode_set,
5331 		(void *)&cmd_setbypass_mode_bypass,
5332 		(void *)&cmd_setbypass_mode_mode,
5333 		(void *)&cmd_setbypass_mode_value,
5334 		(void *)&cmd_setbypass_mode_port,
5335 		NULL,
5336 	},
5337 };
5338 
5339 /* *** SET NIC BYPASS EVENT *** */
5340 struct cmd_set_bypass_event_result {
5341 	cmdline_fixed_string_t set;
5342 	cmdline_fixed_string_t bypass;
5343 	cmdline_fixed_string_t event;
5344 	cmdline_fixed_string_t event_value;
5345 	cmdline_fixed_string_t mode;
5346 	cmdline_fixed_string_t mode_value;
5347 	portid_t port_id;
5348 };
5349 
5350 static void
5351 cmd_set_bypass_event_parsed(void *parsed_result,
5352 		__attribute__((unused)) struct cmdline *cl,
5353 		__attribute__((unused)) void *data)
5354 {
5355 	int32_t rc = -EINVAL;
5356 	struct cmd_set_bypass_event_result *res = parsed_result;
5357 	portid_t port_id = res->port_id;
5358 
5359 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5360 	uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5361 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5362 
5363 	if (!strcmp(res->event_value, "timeout"))
5364 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5365 	else if (!strcmp(res->event_value, "os_on"))
5366 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5367 	else if (!strcmp(res->event_value, "os_off"))
5368 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5369 	else if (!strcmp(res->event_value, "power_on"))
5370 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5371 	else if (!strcmp(res->event_value, "power_off"))
5372 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5373 	else
5374 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5375 
5376 	if (!strcmp(res->mode_value, "bypass"))
5377 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5378 	else if (!strcmp(res->mode_value, "isolate"))
5379 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5380 	else
5381 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5382 
5383 	/* Set the watchdog timeout. */
5384 	if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5385 
5386 		rc = -EINVAL;
5387 		if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5388 			rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5389 							   bypass_timeout);
5390 		}
5391 		if (rc != 0) {
5392 			printf("Failed to set timeout value %u "
5393 			"for port %d, errto code: %d.\n",
5394 			bypass_timeout, port_id, rc);
5395 		}
5396 	}
5397 
5398 	/* Set the bypass event to transition to bypass mode. */
5399 	rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5400 					      bypass_mode);
5401 #endif
5402 
5403 	if (rc != 0)
5404 		printf("\t Failed to set bypass event for port = %d.\n",
5405 		       port_id);
5406 }
5407 
5408 cmdline_parse_token_string_t cmd_setbypass_event_set =
5409 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5410 			set, "set");
5411 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5412 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5413 			bypass, "bypass");
5414 cmdline_parse_token_string_t cmd_setbypass_event_event =
5415 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5416 			event, "event");
5417 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5418 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5419 			event_value, "none#timeout#os_off#os_on#power_on#power_off");
5420 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5421 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5422 			mode, "mode");
5423 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5424 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5425 			mode_value, "normal#bypass#isolate");
5426 cmdline_parse_token_num_t cmd_setbypass_event_port =
5427 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5428 				port_id, UINT16);
5429 
5430 cmdline_parse_inst_t cmd_set_bypass_event = {
5431 	.f = cmd_set_bypass_event_parsed,
5432 	.help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5433 		"power_off mode normal|bypass|isolate <port_id>: "
5434 		"Set the NIC bypass event mode for port_id",
5435 	.data = NULL,
5436 	.tokens = {
5437 		(void *)&cmd_setbypass_event_set,
5438 		(void *)&cmd_setbypass_event_bypass,
5439 		(void *)&cmd_setbypass_event_event,
5440 		(void *)&cmd_setbypass_event_event_value,
5441 		(void *)&cmd_setbypass_event_mode,
5442 		(void *)&cmd_setbypass_event_mode_value,
5443 		(void *)&cmd_setbypass_event_port,
5444 		NULL,
5445 	},
5446 };
5447 
5448 
5449 /* *** SET NIC BYPASS TIMEOUT *** */
5450 struct cmd_set_bypass_timeout_result {
5451 	cmdline_fixed_string_t set;
5452 	cmdline_fixed_string_t bypass;
5453 	cmdline_fixed_string_t timeout;
5454 	cmdline_fixed_string_t value;
5455 };
5456 
5457 static void
5458 cmd_set_bypass_timeout_parsed(void *parsed_result,
5459 		__attribute__((unused)) struct cmdline *cl,
5460 		__attribute__((unused)) void *data)
5461 {
5462 	__rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5463 
5464 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5465 	if (!strcmp(res->value, "1.5"))
5466 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5467 	else if (!strcmp(res->value, "2"))
5468 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5469 	else if (!strcmp(res->value, "3"))
5470 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5471 	else if (!strcmp(res->value, "4"))
5472 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5473 	else if (!strcmp(res->value, "8"))
5474 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5475 	else if (!strcmp(res->value, "16"))
5476 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5477 	else if (!strcmp(res->value, "32"))
5478 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5479 	else
5480 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5481 #endif
5482 }
5483 
5484 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5485 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5486 			set, "set");
5487 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5488 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5489 			bypass, "bypass");
5490 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5491 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5492 			timeout, "timeout");
5493 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5494 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5495 			value, "0#1.5#2#3#4#8#16#32");
5496 
5497 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5498 	.f = cmd_set_bypass_timeout_parsed,
5499 	.help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5500 		"Set the NIC bypass watchdog timeout in seconds",
5501 	.data = NULL,
5502 	.tokens = {
5503 		(void *)&cmd_setbypass_timeout_set,
5504 		(void *)&cmd_setbypass_timeout_bypass,
5505 		(void *)&cmd_setbypass_timeout_timeout,
5506 		(void *)&cmd_setbypass_timeout_value,
5507 		NULL,
5508 	},
5509 };
5510 
5511 /* *** SHOW NIC BYPASS MODE *** */
5512 struct cmd_show_bypass_config_result {
5513 	cmdline_fixed_string_t show;
5514 	cmdline_fixed_string_t bypass;
5515 	cmdline_fixed_string_t config;
5516 	portid_t port_id;
5517 };
5518 
5519 static void
5520 cmd_show_bypass_config_parsed(void *parsed_result,
5521 		__attribute__((unused)) struct cmdline *cl,
5522 		__attribute__((unused)) void *data)
5523 {
5524 	struct cmd_show_bypass_config_result *res = parsed_result;
5525 	portid_t port_id = res->port_id;
5526 	int rc = -EINVAL;
5527 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5528 	uint32_t event_mode;
5529 	uint32_t bypass_mode;
5530 	uint32_t timeout = bypass_timeout;
5531 	int i;
5532 
5533 	static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5534 		{"off", "1.5", "2", "3", "4", "8", "16", "32"};
5535 	static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5536 		{"UNKNOWN", "normal", "bypass", "isolate"};
5537 	static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5538 		"NONE",
5539 		"OS/board on",
5540 		"power supply on",
5541 		"OS/board off",
5542 		"power supply off",
5543 		"timeout"};
5544 	int num_events = (sizeof events) / (sizeof events[0]);
5545 
5546 	/* Display the bypass mode.*/
5547 	if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5548 		printf("\tFailed to get bypass mode for port = %d\n", port_id);
5549 		return;
5550 	}
5551 	else {
5552 		if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5553 			bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5554 
5555 		printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5556 	}
5557 
5558 	/* Display the bypass timeout.*/
5559 	if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5560 		timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5561 
5562 	printf("\tbypass timeout = %s\n", timeouts[timeout]);
5563 
5564 	/* Display the bypass events and associated modes. */
5565 	for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5566 
5567 		if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5568 			printf("\tFailed to get bypass mode for event = %s\n",
5569 				events[i]);
5570 		} else {
5571 			if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5572 				event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5573 
5574 			printf("\tbypass event: %-16s = %s\n", events[i],
5575 				modes[event_mode]);
5576 		}
5577 	}
5578 #endif
5579 	if (rc != 0)
5580 		printf("\tFailed to get bypass configuration for port = %d\n",
5581 		       port_id);
5582 }
5583 
5584 cmdline_parse_token_string_t cmd_showbypass_config_show =
5585 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5586 			show, "show");
5587 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5588 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5589 			bypass, "bypass");
5590 cmdline_parse_token_string_t cmd_showbypass_config_config =
5591 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5592 			config, "config");
5593 cmdline_parse_token_num_t cmd_showbypass_config_port =
5594 	TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5595 				port_id, UINT16);
5596 
5597 cmdline_parse_inst_t cmd_show_bypass_config = {
5598 	.f = cmd_show_bypass_config_parsed,
5599 	.help_str = "show bypass config <port_id>: "
5600 	            "Show the NIC bypass config for port_id",
5601 	.data = NULL,
5602 	.tokens = {
5603 		(void *)&cmd_showbypass_config_show,
5604 		(void *)&cmd_showbypass_config_bypass,
5605 		(void *)&cmd_showbypass_config_config,
5606 		(void *)&cmd_showbypass_config_port,
5607 		NULL,
5608 	},
5609 };
5610 
5611 #ifdef RTE_LIBRTE_PMD_BOND
5612 /* *** SET BONDING MODE *** */
5613 struct cmd_set_bonding_mode_result {
5614 	cmdline_fixed_string_t set;
5615 	cmdline_fixed_string_t bonding;
5616 	cmdline_fixed_string_t mode;
5617 	uint8_t value;
5618 	portid_t port_id;
5619 };
5620 
5621 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5622 		__attribute__((unused))  struct cmdline *cl,
5623 		__attribute__((unused)) void *data)
5624 {
5625 	struct cmd_set_bonding_mode_result *res = parsed_result;
5626 	portid_t port_id = res->port_id;
5627 
5628 	/* Set the bonding mode for the relevant port. */
5629 	if (0 != rte_eth_bond_mode_set(port_id, res->value))
5630 		printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5631 }
5632 
5633 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5634 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5635 		set, "set");
5636 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5637 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5638 		bonding, "bonding");
5639 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5640 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5641 		mode, "mode");
5642 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5643 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5644 		value, UINT8);
5645 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5646 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5647 		port_id, UINT16);
5648 
5649 cmdline_parse_inst_t cmd_set_bonding_mode = {
5650 		.f = cmd_set_bonding_mode_parsed,
5651 		.help_str = "set bonding mode <mode_value> <port_id>: "
5652 			"Set the bonding mode for port_id",
5653 		.data = NULL,
5654 		.tokens = {
5655 				(void *) &cmd_setbonding_mode_set,
5656 				(void *) &cmd_setbonding_mode_bonding,
5657 				(void *) &cmd_setbonding_mode_mode,
5658 				(void *) &cmd_setbonding_mode_value,
5659 				(void *) &cmd_setbonding_mode_port,
5660 				NULL
5661 		}
5662 };
5663 
5664 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5665 struct cmd_set_bonding_lacp_dedicated_queues_result {
5666 	cmdline_fixed_string_t set;
5667 	cmdline_fixed_string_t bonding;
5668 	cmdline_fixed_string_t lacp;
5669 	cmdline_fixed_string_t dedicated_queues;
5670 	portid_t port_id;
5671 	cmdline_fixed_string_t mode;
5672 };
5673 
5674 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5675 		__attribute__((unused))  struct cmdline *cl,
5676 		__attribute__((unused)) void *data)
5677 {
5678 	struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5679 	portid_t port_id = res->port_id;
5680 	struct rte_port *port;
5681 
5682 	port = &ports[port_id];
5683 
5684 	/** Check if the port is not started **/
5685 	if (port->port_status != RTE_PORT_STOPPED) {
5686 		printf("Please stop port %d first\n", port_id);
5687 		return;
5688 	}
5689 
5690 	if (!strcmp(res->mode, "enable")) {
5691 		if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5692 			printf("Dedicate queues for LACP control packets"
5693 					" enabled\n");
5694 		else
5695 			printf("Enabling dedicate queues for LACP control "
5696 					"packets on port %d failed\n", port_id);
5697 	} else if (!strcmp(res->mode, "disable")) {
5698 		if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5699 			printf("Dedicated queues for LACP control packets "
5700 					"disabled\n");
5701 		else
5702 			printf("Disabling dedicated queues for LACP control "
5703 					"traffic on port %d failed\n", port_id);
5704 	}
5705 }
5706 
5707 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5708 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5709 		set, "set");
5710 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5711 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5712 		bonding, "bonding");
5713 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5714 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5715 		lacp, "lacp");
5716 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5717 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5718 		dedicated_queues, "dedicated_queues");
5719 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5720 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5721 		port_id, UINT16);
5722 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5723 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5724 		mode, "enable#disable");
5725 
5726 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5727 		.f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5728 		.help_str = "set bonding lacp dedicated_queues <port_id> "
5729 			"enable|disable: "
5730 			"Enable/disable dedicated queues for LACP control traffic for port_id",
5731 		.data = NULL,
5732 		.tokens = {
5733 			(void *)&cmd_setbonding_lacp_dedicated_queues_set,
5734 			(void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5735 			(void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5736 			(void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5737 			(void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5738 			(void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5739 			NULL
5740 		}
5741 };
5742 
5743 /* *** SET BALANCE XMIT POLICY *** */
5744 struct cmd_set_bonding_balance_xmit_policy_result {
5745 	cmdline_fixed_string_t set;
5746 	cmdline_fixed_string_t bonding;
5747 	cmdline_fixed_string_t balance_xmit_policy;
5748 	portid_t port_id;
5749 	cmdline_fixed_string_t policy;
5750 };
5751 
5752 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5753 		__attribute__((unused))  struct cmdline *cl,
5754 		__attribute__((unused)) void *data)
5755 {
5756 	struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5757 	portid_t port_id = res->port_id;
5758 	uint8_t policy;
5759 
5760 	if (!strcmp(res->policy, "l2")) {
5761 		policy = BALANCE_XMIT_POLICY_LAYER2;
5762 	} else if (!strcmp(res->policy, "l23")) {
5763 		policy = BALANCE_XMIT_POLICY_LAYER23;
5764 	} else if (!strcmp(res->policy, "l34")) {
5765 		policy = BALANCE_XMIT_POLICY_LAYER34;
5766 	} else {
5767 		printf("\t Invalid xmit policy selection");
5768 		return;
5769 	}
5770 
5771 	/* Set the bonding mode for the relevant port. */
5772 	if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5773 		printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5774 				port_id);
5775 	}
5776 }
5777 
5778 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5779 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5780 		set, "set");
5781 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5782 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5783 		bonding, "bonding");
5784 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5785 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5786 		balance_xmit_policy, "balance_xmit_policy");
5787 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5788 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5789 		port_id, UINT16);
5790 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5791 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5792 		policy, "l2#l23#l34");
5793 
5794 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5795 		.f = cmd_set_bonding_balance_xmit_policy_parsed,
5796 		.help_str = "set bonding balance_xmit_policy <port_id> "
5797 			"l2|l23|l34: "
5798 			"Set the bonding balance_xmit_policy for port_id",
5799 		.data = NULL,
5800 		.tokens = {
5801 				(void *)&cmd_setbonding_balance_xmit_policy_set,
5802 				(void *)&cmd_setbonding_balance_xmit_policy_bonding,
5803 				(void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5804 				(void *)&cmd_setbonding_balance_xmit_policy_port,
5805 				(void *)&cmd_setbonding_balance_xmit_policy_policy,
5806 				NULL
5807 		}
5808 };
5809 
5810 /* *** SHOW NIC BONDING CONFIGURATION *** */
5811 struct cmd_show_bonding_config_result {
5812 	cmdline_fixed_string_t show;
5813 	cmdline_fixed_string_t bonding;
5814 	cmdline_fixed_string_t config;
5815 	portid_t port_id;
5816 };
5817 
5818 static void cmd_show_bonding_config_parsed(void *parsed_result,
5819 		__attribute__((unused))  struct cmdline *cl,
5820 		__attribute__((unused)) void *data)
5821 {
5822 	struct cmd_show_bonding_config_result *res = parsed_result;
5823 	int bonding_mode, agg_mode;
5824 	portid_t slaves[RTE_MAX_ETHPORTS];
5825 	int num_slaves, num_active_slaves;
5826 	int primary_id;
5827 	int i;
5828 	portid_t port_id = res->port_id;
5829 
5830 	/* Display the bonding mode.*/
5831 	bonding_mode = rte_eth_bond_mode_get(port_id);
5832 	if (bonding_mode < 0) {
5833 		printf("\tFailed to get bonding mode for port = %d\n", port_id);
5834 		return;
5835 	} else
5836 		printf("\tBonding mode: %d\n", bonding_mode);
5837 
5838 	if (bonding_mode == BONDING_MODE_BALANCE) {
5839 		int balance_xmit_policy;
5840 
5841 		balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5842 		if (balance_xmit_policy < 0) {
5843 			printf("\tFailed to get balance xmit policy for port = %d\n",
5844 					port_id);
5845 			return;
5846 		} else {
5847 			printf("\tBalance Xmit Policy: ");
5848 
5849 			switch (balance_xmit_policy) {
5850 			case BALANCE_XMIT_POLICY_LAYER2:
5851 				printf("BALANCE_XMIT_POLICY_LAYER2");
5852 				break;
5853 			case BALANCE_XMIT_POLICY_LAYER23:
5854 				printf("BALANCE_XMIT_POLICY_LAYER23");
5855 				break;
5856 			case BALANCE_XMIT_POLICY_LAYER34:
5857 				printf("BALANCE_XMIT_POLICY_LAYER34");
5858 				break;
5859 			}
5860 			printf("\n");
5861 		}
5862 	}
5863 
5864 	if (bonding_mode == BONDING_MODE_8023AD) {
5865 		agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5866 		printf("\tIEEE802.3AD Aggregator Mode: ");
5867 		switch (agg_mode) {
5868 		case AGG_BANDWIDTH:
5869 			printf("bandwidth");
5870 			break;
5871 		case AGG_STABLE:
5872 			printf("stable");
5873 			break;
5874 		case AGG_COUNT:
5875 			printf("count");
5876 			break;
5877 		}
5878 		printf("\n");
5879 	}
5880 
5881 	num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5882 
5883 	if (num_slaves < 0) {
5884 		printf("\tFailed to get slave list for port = %d\n", port_id);
5885 		return;
5886 	}
5887 	if (num_slaves > 0) {
5888 		printf("\tSlaves (%d): [", num_slaves);
5889 		for (i = 0; i < num_slaves - 1; i++)
5890 			printf("%d ", slaves[i]);
5891 
5892 		printf("%d]\n", slaves[num_slaves - 1]);
5893 	} else {
5894 		printf("\tSlaves: []\n");
5895 
5896 	}
5897 
5898 	num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5899 			RTE_MAX_ETHPORTS);
5900 
5901 	if (num_active_slaves < 0) {
5902 		printf("\tFailed to get active slave list for port = %d\n", port_id);
5903 		return;
5904 	}
5905 	if (num_active_slaves > 0) {
5906 		printf("\tActive Slaves (%d): [", num_active_slaves);
5907 		for (i = 0; i < num_active_slaves - 1; i++)
5908 			printf("%d ", slaves[i]);
5909 
5910 		printf("%d]\n", slaves[num_active_slaves - 1]);
5911 
5912 	} else {
5913 		printf("\tActive Slaves: []\n");
5914 
5915 	}
5916 
5917 	primary_id = rte_eth_bond_primary_get(port_id);
5918 	if (primary_id < 0) {
5919 		printf("\tFailed to get primary slave for port = %d\n", port_id);
5920 		return;
5921 	} else
5922 		printf("\tPrimary: [%d]\n", primary_id);
5923 
5924 }
5925 
5926 cmdline_parse_token_string_t cmd_showbonding_config_show =
5927 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5928 		show, "show");
5929 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5930 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5931 		bonding, "bonding");
5932 cmdline_parse_token_string_t cmd_showbonding_config_config =
5933 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5934 		config, "config");
5935 cmdline_parse_token_num_t cmd_showbonding_config_port =
5936 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5937 		port_id, UINT16);
5938 
5939 cmdline_parse_inst_t cmd_show_bonding_config = {
5940 		.f = cmd_show_bonding_config_parsed,
5941 		.help_str = "show bonding config <port_id>: "
5942 			"Show the bonding config for port_id",
5943 		.data = NULL,
5944 		.tokens = {
5945 				(void *)&cmd_showbonding_config_show,
5946 				(void *)&cmd_showbonding_config_bonding,
5947 				(void *)&cmd_showbonding_config_config,
5948 				(void *)&cmd_showbonding_config_port,
5949 				NULL
5950 		}
5951 };
5952 
5953 /* *** SET BONDING PRIMARY *** */
5954 struct cmd_set_bonding_primary_result {
5955 	cmdline_fixed_string_t set;
5956 	cmdline_fixed_string_t bonding;
5957 	cmdline_fixed_string_t primary;
5958 	portid_t slave_id;
5959 	portid_t port_id;
5960 };
5961 
5962 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5963 		__attribute__((unused))  struct cmdline *cl,
5964 		__attribute__((unused)) void *data)
5965 {
5966 	struct cmd_set_bonding_primary_result *res = parsed_result;
5967 	portid_t master_port_id = res->port_id;
5968 	portid_t slave_port_id = res->slave_id;
5969 
5970 	/* Set the primary slave for a bonded device. */
5971 	if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5972 		printf("\t Failed to set primary slave for port = %d.\n",
5973 				master_port_id);
5974 		return;
5975 	}
5976 	init_port_config();
5977 }
5978 
5979 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5980 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5981 		set, "set");
5982 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5983 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5984 		bonding, "bonding");
5985 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5986 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5987 		primary, "primary");
5988 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5989 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5990 		slave_id, UINT16);
5991 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5992 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5993 		port_id, UINT16);
5994 
5995 cmdline_parse_inst_t cmd_set_bonding_primary = {
5996 		.f = cmd_set_bonding_primary_parsed,
5997 		.help_str = "set bonding primary <slave_id> <port_id>: "
5998 			"Set the primary slave for port_id",
5999 		.data = NULL,
6000 		.tokens = {
6001 				(void *)&cmd_setbonding_primary_set,
6002 				(void *)&cmd_setbonding_primary_bonding,
6003 				(void *)&cmd_setbonding_primary_primary,
6004 				(void *)&cmd_setbonding_primary_slave,
6005 				(void *)&cmd_setbonding_primary_port,
6006 				NULL
6007 		}
6008 };
6009 
6010 /* *** ADD SLAVE *** */
6011 struct cmd_add_bonding_slave_result {
6012 	cmdline_fixed_string_t add;
6013 	cmdline_fixed_string_t bonding;
6014 	cmdline_fixed_string_t slave;
6015 	portid_t slave_id;
6016 	portid_t port_id;
6017 };
6018 
6019 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6020 		__attribute__((unused))  struct cmdline *cl,
6021 		__attribute__((unused)) void *data)
6022 {
6023 	struct cmd_add_bonding_slave_result *res = parsed_result;
6024 	portid_t master_port_id = res->port_id;
6025 	portid_t slave_port_id = res->slave_id;
6026 
6027 	/* add the slave for a bonded device. */
6028 	if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6029 		printf("\t Failed to add slave %d to master port = %d.\n",
6030 				slave_port_id, master_port_id);
6031 		return;
6032 	}
6033 	init_port_config();
6034 	set_port_slave_flag(slave_port_id);
6035 }
6036 
6037 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6038 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6039 		add, "add");
6040 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6041 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6042 		bonding, "bonding");
6043 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6044 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6045 		slave, "slave");
6046 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6047 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6048 		slave_id, UINT16);
6049 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6050 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6051 		port_id, UINT16);
6052 
6053 cmdline_parse_inst_t cmd_add_bonding_slave = {
6054 		.f = cmd_add_bonding_slave_parsed,
6055 		.help_str = "add bonding slave <slave_id> <port_id>: "
6056 			"Add a slave device to a bonded device",
6057 		.data = NULL,
6058 		.tokens = {
6059 				(void *)&cmd_addbonding_slave_add,
6060 				(void *)&cmd_addbonding_slave_bonding,
6061 				(void *)&cmd_addbonding_slave_slave,
6062 				(void *)&cmd_addbonding_slave_slaveid,
6063 				(void *)&cmd_addbonding_slave_port,
6064 				NULL
6065 		}
6066 };
6067 
6068 /* *** REMOVE SLAVE *** */
6069 struct cmd_remove_bonding_slave_result {
6070 	cmdline_fixed_string_t remove;
6071 	cmdline_fixed_string_t bonding;
6072 	cmdline_fixed_string_t slave;
6073 	portid_t slave_id;
6074 	portid_t port_id;
6075 };
6076 
6077 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6078 		__attribute__((unused))  struct cmdline *cl,
6079 		__attribute__((unused)) void *data)
6080 {
6081 	struct cmd_remove_bonding_slave_result *res = parsed_result;
6082 	portid_t master_port_id = res->port_id;
6083 	portid_t slave_port_id = res->slave_id;
6084 
6085 	/* remove the slave from a bonded device. */
6086 	if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6087 		printf("\t Failed to remove slave %d from master port = %d.\n",
6088 				slave_port_id, master_port_id);
6089 		return;
6090 	}
6091 	init_port_config();
6092 	clear_port_slave_flag(slave_port_id);
6093 }
6094 
6095 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6096 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6097 				remove, "remove");
6098 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6099 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6100 				bonding, "bonding");
6101 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6102 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6103 				slave, "slave");
6104 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6105 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6106 				slave_id, UINT16);
6107 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6108 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6109 				port_id, UINT16);
6110 
6111 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6112 		.f = cmd_remove_bonding_slave_parsed,
6113 		.help_str = "remove bonding slave <slave_id> <port_id>: "
6114 			"Remove a slave device from a bonded device",
6115 		.data = NULL,
6116 		.tokens = {
6117 				(void *)&cmd_removebonding_slave_remove,
6118 				(void *)&cmd_removebonding_slave_bonding,
6119 				(void *)&cmd_removebonding_slave_slave,
6120 				(void *)&cmd_removebonding_slave_slaveid,
6121 				(void *)&cmd_removebonding_slave_port,
6122 				NULL
6123 		}
6124 };
6125 
6126 /* *** CREATE BONDED DEVICE *** */
6127 struct cmd_create_bonded_device_result {
6128 	cmdline_fixed_string_t create;
6129 	cmdline_fixed_string_t bonded;
6130 	cmdline_fixed_string_t device;
6131 	uint8_t mode;
6132 	uint8_t socket;
6133 };
6134 
6135 static int bond_dev_num = 0;
6136 
6137 static void cmd_create_bonded_device_parsed(void *parsed_result,
6138 		__attribute__((unused))  struct cmdline *cl,
6139 		__attribute__((unused)) void *data)
6140 {
6141 	struct cmd_create_bonded_device_result *res = parsed_result;
6142 	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6143 	int port_id;
6144 
6145 	if (test_done == 0) {
6146 		printf("Please stop forwarding first\n");
6147 		return;
6148 	}
6149 
6150 	snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6151 			bond_dev_num++);
6152 
6153 	/* Create a new bonded device. */
6154 	port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6155 	if (port_id < 0) {
6156 		printf("\t Failed to create bonded device.\n");
6157 		return;
6158 	} else {
6159 		printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6160 				port_id);
6161 
6162 		/* Update number of ports */
6163 		nb_ports = rte_eth_dev_count_avail();
6164 		reconfig(port_id, res->socket);
6165 		rte_eth_promiscuous_enable(port_id);
6166 		ports[port_id].need_setup = 0;
6167 		ports[port_id].port_status = RTE_PORT_STOPPED;
6168 	}
6169 
6170 }
6171 
6172 cmdline_parse_token_string_t cmd_createbonded_device_create =
6173 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6174 				create, "create");
6175 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6176 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6177 				bonded, "bonded");
6178 cmdline_parse_token_string_t cmd_createbonded_device_device =
6179 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6180 				device, "device");
6181 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6182 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6183 				mode, UINT8);
6184 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6185 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6186 				socket, UINT8);
6187 
6188 cmdline_parse_inst_t cmd_create_bonded_device = {
6189 		.f = cmd_create_bonded_device_parsed,
6190 		.help_str = "create bonded device <mode> <socket>: "
6191 			"Create a new bonded device with specific bonding mode and socket",
6192 		.data = NULL,
6193 		.tokens = {
6194 				(void *)&cmd_createbonded_device_create,
6195 				(void *)&cmd_createbonded_device_bonded,
6196 				(void *)&cmd_createbonded_device_device,
6197 				(void *)&cmd_createbonded_device_mode,
6198 				(void *)&cmd_createbonded_device_socket,
6199 				NULL
6200 		}
6201 };
6202 
6203 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6204 struct cmd_set_bond_mac_addr_result {
6205 	cmdline_fixed_string_t set;
6206 	cmdline_fixed_string_t bonding;
6207 	cmdline_fixed_string_t mac_addr;
6208 	uint16_t port_num;
6209 	struct rte_ether_addr address;
6210 };
6211 
6212 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6213 		__attribute__((unused))  struct cmdline *cl,
6214 		__attribute__((unused)) void *data)
6215 {
6216 	struct cmd_set_bond_mac_addr_result *res = parsed_result;
6217 	int ret;
6218 
6219 	if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6220 		return;
6221 
6222 	ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6223 
6224 	/* check the return value and print it if is < 0 */
6225 	if (ret < 0)
6226 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6227 }
6228 
6229 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6230 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6231 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6232 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6233 				"bonding");
6234 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6235 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6236 				"mac_addr");
6237 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6238 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6239 				port_num, UINT16);
6240 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6241 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6242 
6243 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6244 		.f = cmd_set_bond_mac_addr_parsed,
6245 		.data = (void *) 0,
6246 		.help_str = "set bonding mac_addr <port_id> <mac_addr>",
6247 		.tokens = {
6248 				(void *)&cmd_set_bond_mac_addr_set,
6249 				(void *)&cmd_set_bond_mac_addr_bonding,
6250 				(void *)&cmd_set_bond_mac_addr_mac,
6251 				(void *)&cmd_set_bond_mac_addr_portnum,
6252 				(void *)&cmd_set_bond_mac_addr_addr,
6253 				NULL
6254 		}
6255 };
6256 
6257 
6258 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6259 struct cmd_set_bond_mon_period_result {
6260 	cmdline_fixed_string_t set;
6261 	cmdline_fixed_string_t bonding;
6262 	cmdline_fixed_string_t mon_period;
6263 	uint16_t port_num;
6264 	uint32_t period_ms;
6265 };
6266 
6267 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6268 		__attribute__((unused))  struct cmdline *cl,
6269 		__attribute__((unused)) void *data)
6270 {
6271 	struct cmd_set_bond_mon_period_result *res = parsed_result;
6272 	int ret;
6273 
6274 	ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6275 
6276 	/* check the return value and print it if is < 0 */
6277 	if (ret < 0)
6278 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6279 }
6280 
6281 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6282 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6283 				set, "set");
6284 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6285 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6286 				bonding, "bonding");
6287 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6288 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6289 				mon_period,	"mon_period");
6290 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6291 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6292 				port_num, UINT16);
6293 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6294 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6295 				period_ms, UINT32);
6296 
6297 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6298 		.f = cmd_set_bond_mon_period_parsed,
6299 		.data = (void *) 0,
6300 		.help_str = "set bonding mon_period <port_id> <period_ms>",
6301 		.tokens = {
6302 				(void *)&cmd_set_bond_mon_period_set,
6303 				(void *)&cmd_set_bond_mon_period_bonding,
6304 				(void *)&cmd_set_bond_mon_period_mon_period,
6305 				(void *)&cmd_set_bond_mon_period_portnum,
6306 				(void *)&cmd_set_bond_mon_period_period_ms,
6307 				NULL
6308 		}
6309 };
6310 
6311 
6312 
6313 struct cmd_set_bonding_agg_mode_policy_result {
6314 	cmdline_fixed_string_t set;
6315 	cmdline_fixed_string_t bonding;
6316 	cmdline_fixed_string_t agg_mode;
6317 	uint16_t port_num;
6318 	cmdline_fixed_string_t policy;
6319 };
6320 
6321 
6322 static void
6323 cmd_set_bonding_agg_mode(void *parsed_result,
6324 		__attribute__((unused)) struct cmdline *cl,
6325 		__attribute__((unused)) void *data)
6326 {
6327 	struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6328 	uint8_t policy = AGG_BANDWIDTH;
6329 
6330 	if (!strcmp(res->policy, "bandwidth"))
6331 		policy = AGG_BANDWIDTH;
6332 	else if (!strcmp(res->policy, "stable"))
6333 		policy = AGG_STABLE;
6334 	else if (!strcmp(res->policy, "count"))
6335 		policy = AGG_COUNT;
6336 
6337 	rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6338 }
6339 
6340 
6341 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6342 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6343 				set, "set");
6344 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6345 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6346 				bonding, "bonding");
6347 
6348 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6349 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6350 				agg_mode, "agg_mode");
6351 
6352 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6353 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6354 				port_num, UINT16);
6355 
6356 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6357 	TOKEN_STRING_INITIALIZER(
6358 			struct cmd_set_bonding_balance_xmit_policy_result,
6359 		policy, "stable#bandwidth#count");
6360 
6361 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6362 	.f = cmd_set_bonding_agg_mode,
6363 	.data = (void *) 0,
6364 	.help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6365 	.tokens = {
6366 			(void *)&cmd_set_bonding_agg_mode_set,
6367 			(void *)&cmd_set_bonding_agg_mode_bonding,
6368 			(void *)&cmd_set_bonding_agg_mode_agg_mode,
6369 			(void *)&cmd_set_bonding_agg_mode_portnum,
6370 			(void *)&cmd_set_bonding_agg_mode_policy_string,
6371 			NULL
6372 		}
6373 };
6374 
6375 
6376 #endif /* RTE_LIBRTE_PMD_BOND */
6377 
6378 /* *** SET FORWARDING MODE *** */
6379 struct cmd_set_fwd_mode_result {
6380 	cmdline_fixed_string_t set;
6381 	cmdline_fixed_string_t fwd;
6382 	cmdline_fixed_string_t mode;
6383 };
6384 
6385 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6386 				    __attribute__((unused)) struct cmdline *cl,
6387 				    __attribute__((unused)) void *data)
6388 {
6389 	struct cmd_set_fwd_mode_result *res = parsed_result;
6390 
6391 	retry_enabled = 0;
6392 	set_pkt_forwarding_mode(res->mode);
6393 }
6394 
6395 cmdline_parse_token_string_t cmd_setfwd_set =
6396 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6397 cmdline_parse_token_string_t cmd_setfwd_fwd =
6398 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6399 cmdline_parse_token_string_t cmd_setfwd_mode =
6400 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6401 		"" /* defined at init */);
6402 
6403 cmdline_parse_inst_t cmd_set_fwd_mode = {
6404 	.f = cmd_set_fwd_mode_parsed,
6405 	.data = NULL,
6406 	.help_str = NULL, /* defined at init */
6407 	.tokens = {
6408 		(void *)&cmd_setfwd_set,
6409 		(void *)&cmd_setfwd_fwd,
6410 		(void *)&cmd_setfwd_mode,
6411 		NULL,
6412 	},
6413 };
6414 
6415 static void cmd_set_fwd_mode_init(void)
6416 {
6417 	char *modes, *c;
6418 	static char token[128];
6419 	static char help[256];
6420 	cmdline_parse_token_string_t *token_struct;
6421 
6422 	modes = list_pkt_forwarding_modes();
6423 	snprintf(help, sizeof(help), "set fwd %s: "
6424 		"Set packet forwarding mode", modes);
6425 	cmd_set_fwd_mode.help_str = help;
6426 
6427 	/* string token separator is # */
6428 	for (c = token; *modes != '\0'; modes++)
6429 		if (*modes == '|')
6430 			*c++ = '#';
6431 		else
6432 			*c++ = *modes;
6433 	token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6434 	token_struct->string_data.str = token;
6435 }
6436 
6437 /* *** SET RETRY FORWARDING MODE *** */
6438 struct cmd_set_fwd_retry_mode_result {
6439 	cmdline_fixed_string_t set;
6440 	cmdline_fixed_string_t fwd;
6441 	cmdline_fixed_string_t mode;
6442 	cmdline_fixed_string_t retry;
6443 };
6444 
6445 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6446 			    __attribute__((unused)) struct cmdline *cl,
6447 			    __attribute__((unused)) void *data)
6448 {
6449 	struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6450 
6451 	retry_enabled = 1;
6452 	set_pkt_forwarding_mode(res->mode);
6453 }
6454 
6455 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6456 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6457 			set, "set");
6458 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6459 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6460 			fwd, "fwd");
6461 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6462 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6463 			mode,
6464 		"" /* defined at init */);
6465 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6466 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6467 			retry, "retry");
6468 
6469 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6470 	.f = cmd_set_fwd_retry_mode_parsed,
6471 	.data = NULL,
6472 	.help_str = NULL, /* defined at init */
6473 	.tokens = {
6474 		(void *)&cmd_setfwd_retry_set,
6475 		(void *)&cmd_setfwd_retry_fwd,
6476 		(void *)&cmd_setfwd_retry_mode,
6477 		(void *)&cmd_setfwd_retry_retry,
6478 		NULL,
6479 	},
6480 };
6481 
6482 static void cmd_set_fwd_retry_mode_init(void)
6483 {
6484 	char *modes, *c;
6485 	static char token[128];
6486 	static char help[256];
6487 	cmdline_parse_token_string_t *token_struct;
6488 
6489 	modes = list_pkt_forwarding_retry_modes();
6490 	snprintf(help, sizeof(help), "set fwd %s retry: "
6491 		"Set packet forwarding mode with retry", modes);
6492 	cmd_set_fwd_retry_mode.help_str = help;
6493 
6494 	/* string token separator is # */
6495 	for (c = token; *modes != '\0'; modes++)
6496 		if (*modes == '|')
6497 			*c++ = '#';
6498 		else
6499 			*c++ = *modes;
6500 	token_struct = (cmdline_parse_token_string_t *)
6501 		cmd_set_fwd_retry_mode.tokens[2];
6502 	token_struct->string_data.str = token;
6503 }
6504 
6505 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6506 struct cmd_set_burst_tx_retry_result {
6507 	cmdline_fixed_string_t set;
6508 	cmdline_fixed_string_t burst;
6509 	cmdline_fixed_string_t tx;
6510 	cmdline_fixed_string_t delay;
6511 	uint32_t time;
6512 	cmdline_fixed_string_t retry;
6513 	uint32_t retry_num;
6514 };
6515 
6516 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6517 					__attribute__((unused)) struct cmdline *cl,
6518 					__attribute__((unused)) void *data)
6519 {
6520 	struct cmd_set_burst_tx_retry_result *res = parsed_result;
6521 
6522 	if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6523 		&& !strcmp(res->tx, "tx")) {
6524 		if (!strcmp(res->delay, "delay"))
6525 			burst_tx_delay_time = res->time;
6526 		if (!strcmp(res->retry, "retry"))
6527 			burst_tx_retry_num = res->retry_num;
6528 	}
6529 
6530 }
6531 
6532 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6533 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6534 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6535 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6536 				 "burst");
6537 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6538 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6539 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6540 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6541 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6542 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6543 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6544 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6545 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6546 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6547 
6548 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6549 	.f = cmd_set_burst_tx_retry_parsed,
6550 	.help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6551 	.tokens = {
6552 		(void *)&cmd_set_burst_tx_retry_set,
6553 		(void *)&cmd_set_burst_tx_retry_burst,
6554 		(void *)&cmd_set_burst_tx_retry_tx,
6555 		(void *)&cmd_set_burst_tx_retry_delay,
6556 		(void *)&cmd_set_burst_tx_retry_time,
6557 		(void *)&cmd_set_burst_tx_retry_retry,
6558 		(void *)&cmd_set_burst_tx_retry_retry_num,
6559 		NULL,
6560 	},
6561 };
6562 
6563 /* *** SET PROMISC MODE *** */
6564 struct cmd_set_promisc_mode_result {
6565 	cmdline_fixed_string_t set;
6566 	cmdline_fixed_string_t promisc;
6567 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6568 	uint16_t port_num;               /* valid if "allports" argument == 0 */
6569 	cmdline_fixed_string_t mode;
6570 };
6571 
6572 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6573 					__attribute__((unused)) struct cmdline *cl,
6574 					void *allports)
6575 {
6576 	struct cmd_set_promisc_mode_result *res = parsed_result;
6577 	int enable;
6578 	portid_t i;
6579 
6580 	if (!strcmp(res->mode, "on"))
6581 		enable = 1;
6582 	else
6583 		enable = 0;
6584 
6585 	/* all ports */
6586 	if (allports) {
6587 		RTE_ETH_FOREACH_DEV(i) {
6588 			if (enable)
6589 				rte_eth_promiscuous_enable(i);
6590 			else
6591 				rte_eth_promiscuous_disable(i);
6592 		}
6593 	}
6594 	else {
6595 		if (enable)
6596 			rte_eth_promiscuous_enable(res->port_num);
6597 		else
6598 			rte_eth_promiscuous_disable(res->port_num);
6599 	}
6600 }
6601 
6602 cmdline_parse_token_string_t cmd_setpromisc_set =
6603 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6604 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6605 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6606 				 "promisc");
6607 cmdline_parse_token_string_t cmd_setpromisc_portall =
6608 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6609 				 "all");
6610 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6611 	TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6612 			      UINT16);
6613 cmdline_parse_token_string_t cmd_setpromisc_mode =
6614 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6615 				 "on#off");
6616 
6617 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6618 	.f = cmd_set_promisc_mode_parsed,
6619 	.data = (void *)1,
6620 	.help_str = "set promisc all on|off: Set promisc mode for all ports",
6621 	.tokens = {
6622 		(void *)&cmd_setpromisc_set,
6623 		(void *)&cmd_setpromisc_promisc,
6624 		(void *)&cmd_setpromisc_portall,
6625 		(void *)&cmd_setpromisc_mode,
6626 		NULL,
6627 	},
6628 };
6629 
6630 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6631 	.f = cmd_set_promisc_mode_parsed,
6632 	.data = (void *)0,
6633 	.help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6634 	.tokens = {
6635 		(void *)&cmd_setpromisc_set,
6636 		(void *)&cmd_setpromisc_promisc,
6637 		(void *)&cmd_setpromisc_portnum,
6638 		(void *)&cmd_setpromisc_mode,
6639 		NULL,
6640 	},
6641 };
6642 
6643 /* *** SET ALLMULTI MODE *** */
6644 struct cmd_set_allmulti_mode_result {
6645 	cmdline_fixed_string_t set;
6646 	cmdline_fixed_string_t allmulti;
6647 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6648 	uint16_t port_num;               /* valid if "allports" argument == 0 */
6649 	cmdline_fixed_string_t mode;
6650 };
6651 
6652 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6653 					__attribute__((unused)) struct cmdline *cl,
6654 					void *allports)
6655 {
6656 	struct cmd_set_allmulti_mode_result *res = parsed_result;
6657 	int enable;
6658 	portid_t i;
6659 
6660 	if (!strcmp(res->mode, "on"))
6661 		enable = 1;
6662 	else
6663 		enable = 0;
6664 
6665 	/* all ports */
6666 	if (allports) {
6667 		RTE_ETH_FOREACH_DEV(i) {
6668 			if (enable)
6669 				rte_eth_allmulticast_enable(i);
6670 			else
6671 				rte_eth_allmulticast_disable(i);
6672 		}
6673 	}
6674 	else {
6675 		if (enable)
6676 			rte_eth_allmulticast_enable(res->port_num);
6677 		else
6678 			rte_eth_allmulticast_disable(res->port_num);
6679 	}
6680 }
6681 
6682 cmdline_parse_token_string_t cmd_setallmulti_set =
6683 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6684 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6685 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6686 				 "allmulti");
6687 cmdline_parse_token_string_t cmd_setallmulti_portall =
6688 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6689 				 "all");
6690 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6691 	TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6692 			      UINT16);
6693 cmdline_parse_token_string_t cmd_setallmulti_mode =
6694 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6695 				 "on#off");
6696 
6697 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6698 	.f = cmd_set_allmulti_mode_parsed,
6699 	.data = (void *)1,
6700 	.help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6701 	.tokens = {
6702 		(void *)&cmd_setallmulti_set,
6703 		(void *)&cmd_setallmulti_allmulti,
6704 		(void *)&cmd_setallmulti_portall,
6705 		(void *)&cmd_setallmulti_mode,
6706 		NULL,
6707 	},
6708 };
6709 
6710 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6711 	.f = cmd_set_allmulti_mode_parsed,
6712 	.data = (void *)0,
6713 	.help_str = "set allmulti <port_id> on|off: "
6714 		"Set allmulti mode on port_id",
6715 	.tokens = {
6716 		(void *)&cmd_setallmulti_set,
6717 		(void *)&cmd_setallmulti_allmulti,
6718 		(void *)&cmd_setallmulti_portnum,
6719 		(void *)&cmd_setallmulti_mode,
6720 		NULL,
6721 	},
6722 };
6723 
6724 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6725 struct cmd_link_flow_ctrl_set_result {
6726 	cmdline_fixed_string_t set;
6727 	cmdline_fixed_string_t flow_ctrl;
6728 	cmdline_fixed_string_t rx;
6729 	cmdline_fixed_string_t rx_lfc_mode;
6730 	cmdline_fixed_string_t tx;
6731 	cmdline_fixed_string_t tx_lfc_mode;
6732 	cmdline_fixed_string_t mac_ctrl_frame_fwd;
6733 	cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6734 	cmdline_fixed_string_t autoneg_str;
6735 	cmdline_fixed_string_t autoneg;
6736 	cmdline_fixed_string_t hw_str;
6737 	uint32_t high_water;
6738 	cmdline_fixed_string_t lw_str;
6739 	uint32_t low_water;
6740 	cmdline_fixed_string_t pt_str;
6741 	uint16_t pause_time;
6742 	cmdline_fixed_string_t xon_str;
6743 	uint16_t send_xon;
6744 	portid_t port_id;
6745 };
6746 
6747 cmdline_parse_token_string_t cmd_lfc_set_set =
6748 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6749 				set, "set");
6750 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6751 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6752 				flow_ctrl, "flow_ctrl");
6753 cmdline_parse_token_string_t cmd_lfc_set_rx =
6754 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6755 				rx, "rx");
6756 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6757 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6758 				rx_lfc_mode, "on#off");
6759 cmdline_parse_token_string_t cmd_lfc_set_tx =
6760 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6761 				tx, "tx");
6762 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6763 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6764 				tx_lfc_mode, "on#off");
6765 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6766 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6767 				hw_str, "high_water");
6768 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6769 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6770 				high_water, UINT32);
6771 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6772 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6773 				lw_str, "low_water");
6774 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6775 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6776 				low_water, UINT32);
6777 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6778 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6779 				pt_str, "pause_time");
6780 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6781 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6782 				pause_time, UINT16);
6783 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6784 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6785 				xon_str, "send_xon");
6786 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6787 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6788 				send_xon, UINT16);
6789 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6790 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6791 				mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6792 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6793 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6794 				mac_ctrl_frame_fwd_mode, "on#off");
6795 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6796 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6797 				autoneg_str, "autoneg");
6798 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6799 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6800 				autoneg, "on#off");
6801 cmdline_parse_token_num_t cmd_lfc_set_portid =
6802 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6803 				port_id, UINT16);
6804 
6805 /* forward declaration */
6806 static void
6807 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6808 			      void *data);
6809 
6810 cmdline_parse_inst_t cmd_link_flow_control_set = {
6811 	.f = cmd_link_flow_ctrl_set_parsed,
6812 	.data = NULL,
6813 	.help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6814 		"<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6815 		"autoneg on|off <port_id>: Configure the Ethernet flow control",
6816 	.tokens = {
6817 		(void *)&cmd_lfc_set_set,
6818 		(void *)&cmd_lfc_set_flow_ctrl,
6819 		(void *)&cmd_lfc_set_rx,
6820 		(void *)&cmd_lfc_set_rx_mode,
6821 		(void *)&cmd_lfc_set_tx,
6822 		(void *)&cmd_lfc_set_tx_mode,
6823 		(void *)&cmd_lfc_set_high_water,
6824 		(void *)&cmd_lfc_set_low_water,
6825 		(void *)&cmd_lfc_set_pause_time,
6826 		(void *)&cmd_lfc_set_send_xon,
6827 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6828 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6829 		(void *)&cmd_lfc_set_autoneg_str,
6830 		(void *)&cmd_lfc_set_autoneg,
6831 		(void *)&cmd_lfc_set_portid,
6832 		NULL,
6833 	},
6834 };
6835 
6836 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6837 	.f = cmd_link_flow_ctrl_set_parsed,
6838 	.data = (void *)&cmd_link_flow_control_set_rx,
6839 	.help_str = "set flow_ctrl rx on|off <port_id>: "
6840 		"Change rx flow control parameter",
6841 	.tokens = {
6842 		(void *)&cmd_lfc_set_set,
6843 		(void *)&cmd_lfc_set_flow_ctrl,
6844 		(void *)&cmd_lfc_set_rx,
6845 		(void *)&cmd_lfc_set_rx_mode,
6846 		(void *)&cmd_lfc_set_portid,
6847 		NULL,
6848 	},
6849 };
6850 
6851 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6852 	.f = cmd_link_flow_ctrl_set_parsed,
6853 	.data = (void *)&cmd_link_flow_control_set_tx,
6854 	.help_str = "set flow_ctrl tx on|off <port_id>: "
6855 		"Change tx flow control parameter",
6856 	.tokens = {
6857 		(void *)&cmd_lfc_set_set,
6858 		(void *)&cmd_lfc_set_flow_ctrl,
6859 		(void *)&cmd_lfc_set_tx,
6860 		(void *)&cmd_lfc_set_tx_mode,
6861 		(void *)&cmd_lfc_set_portid,
6862 		NULL,
6863 	},
6864 };
6865 
6866 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6867 	.f = cmd_link_flow_ctrl_set_parsed,
6868 	.data = (void *)&cmd_link_flow_control_set_hw,
6869 	.help_str = "set flow_ctrl high_water <value> <port_id>: "
6870 		"Change high water flow control parameter",
6871 	.tokens = {
6872 		(void *)&cmd_lfc_set_set,
6873 		(void *)&cmd_lfc_set_flow_ctrl,
6874 		(void *)&cmd_lfc_set_high_water_str,
6875 		(void *)&cmd_lfc_set_high_water,
6876 		(void *)&cmd_lfc_set_portid,
6877 		NULL,
6878 	},
6879 };
6880 
6881 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6882 	.f = cmd_link_flow_ctrl_set_parsed,
6883 	.data = (void *)&cmd_link_flow_control_set_lw,
6884 	.help_str = "set flow_ctrl low_water <value> <port_id>: "
6885 		"Change low water flow control parameter",
6886 	.tokens = {
6887 		(void *)&cmd_lfc_set_set,
6888 		(void *)&cmd_lfc_set_flow_ctrl,
6889 		(void *)&cmd_lfc_set_low_water_str,
6890 		(void *)&cmd_lfc_set_low_water,
6891 		(void *)&cmd_lfc_set_portid,
6892 		NULL,
6893 	},
6894 };
6895 
6896 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6897 	.f = cmd_link_flow_ctrl_set_parsed,
6898 	.data = (void *)&cmd_link_flow_control_set_pt,
6899 	.help_str = "set flow_ctrl pause_time <value> <port_id>: "
6900 		"Change pause time flow control parameter",
6901 	.tokens = {
6902 		(void *)&cmd_lfc_set_set,
6903 		(void *)&cmd_lfc_set_flow_ctrl,
6904 		(void *)&cmd_lfc_set_pause_time_str,
6905 		(void *)&cmd_lfc_set_pause_time,
6906 		(void *)&cmd_lfc_set_portid,
6907 		NULL,
6908 	},
6909 };
6910 
6911 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6912 	.f = cmd_link_flow_ctrl_set_parsed,
6913 	.data = (void *)&cmd_link_flow_control_set_xon,
6914 	.help_str = "set flow_ctrl send_xon <value> <port_id>: "
6915 		"Change send_xon flow control parameter",
6916 	.tokens = {
6917 		(void *)&cmd_lfc_set_set,
6918 		(void *)&cmd_lfc_set_flow_ctrl,
6919 		(void *)&cmd_lfc_set_send_xon_str,
6920 		(void *)&cmd_lfc_set_send_xon,
6921 		(void *)&cmd_lfc_set_portid,
6922 		NULL,
6923 	},
6924 };
6925 
6926 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6927 	.f = cmd_link_flow_ctrl_set_parsed,
6928 	.data = (void *)&cmd_link_flow_control_set_macfwd,
6929 	.help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6930 		"Change mac ctrl fwd flow control parameter",
6931 	.tokens = {
6932 		(void *)&cmd_lfc_set_set,
6933 		(void *)&cmd_lfc_set_flow_ctrl,
6934 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6935 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6936 		(void *)&cmd_lfc_set_portid,
6937 		NULL,
6938 	},
6939 };
6940 
6941 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6942 	.f = cmd_link_flow_ctrl_set_parsed,
6943 	.data = (void *)&cmd_link_flow_control_set_autoneg,
6944 	.help_str = "set flow_ctrl autoneg on|off <port_id>: "
6945 		"Change autoneg flow control parameter",
6946 	.tokens = {
6947 		(void *)&cmd_lfc_set_set,
6948 		(void *)&cmd_lfc_set_flow_ctrl,
6949 		(void *)&cmd_lfc_set_autoneg_str,
6950 		(void *)&cmd_lfc_set_autoneg,
6951 		(void *)&cmd_lfc_set_portid,
6952 		NULL,
6953 	},
6954 };
6955 
6956 static void
6957 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6958 			      __attribute__((unused)) struct cmdline *cl,
6959 			      void *data)
6960 {
6961 	struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6962 	cmdline_parse_inst_t *cmd = data;
6963 	struct rte_eth_fc_conf fc_conf;
6964 	int rx_fc_en = 0;
6965 	int tx_fc_en = 0;
6966 	int ret;
6967 
6968 	/*
6969 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6970 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6971 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6972 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6973 	 */
6974 	static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6975 			{RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6976 	};
6977 
6978 	/* Partial command line, retrieve current configuration */
6979 	if (cmd) {
6980 		ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6981 		if (ret != 0) {
6982 			printf("cannot get current flow ctrl parameters, return"
6983 			       "code = %d\n", ret);
6984 			return;
6985 		}
6986 
6987 		if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6988 		    (fc_conf.mode == RTE_FC_FULL))
6989 			rx_fc_en = 1;
6990 		if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6991 		    (fc_conf.mode == RTE_FC_FULL))
6992 			tx_fc_en = 1;
6993 	}
6994 
6995 	if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6996 		rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6997 
6998 	if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6999 		tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7000 
7001 	fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7002 
7003 	if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7004 		fc_conf.high_water = res->high_water;
7005 
7006 	if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7007 		fc_conf.low_water = res->low_water;
7008 
7009 	if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7010 		fc_conf.pause_time = res->pause_time;
7011 
7012 	if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7013 		fc_conf.send_xon = res->send_xon;
7014 
7015 	if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7016 		if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7017 			fc_conf.mac_ctrl_frame_fwd = 1;
7018 		else
7019 			fc_conf.mac_ctrl_frame_fwd = 0;
7020 	}
7021 
7022 	if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7023 		fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7024 
7025 	ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7026 	if (ret != 0)
7027 		printf("bad flow contrl parameter, return code = %d \n", ret);
7028 }
7029 
7030 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7031 struct cmd_priority_flow_ctrl_set_result {
7032 	cmdline_fixed_string_t set;
7033 	cmdline_fixed_string_t pfc_ctrl;
7034 	cmdline_fixed_string_t rx;
7035 	cmdline_fixed_string_t rx_pfc_mode;
7036 	cmdline_fixed_string_t tx;
7037 	cmdline_fixed_string_t tx_pfc_mode;
7038 	uint32_t high_water;
7039 	uint32_t low_water;
7040 	uint16_t pause_time;
7041 	uint8_t  priority;
7042 	portid_t port_id;
7043 };
7044 
7045 static void
7046 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7047 		       __attribute__((unused)) struct cmdline *cl,
7048 		       __attribute__((unused)) void *data)
7049 {
7050 	struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7051 	struct rte_eth_pfc_conf pfc_conf;
7052 	int rx_fc_enable, tx_fc_enable;
7053 	int ret;
7054 
7055 	/*
7056 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7057 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7058 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7059 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7060 	 */
7061 	static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7062 			{RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
7063 	};
7064 
7065 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7066 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7067 	pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7068 	pfc_conf.fc.high_water = res->high_water;
7069 	pfc_conf.fc.low_water  = res->low_water;
7070 	pfc_conf.fc.pause_time = res->pause_time;
7071 	pfc_conf.priority      = res->priority;
7072 
7073 	ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7074 	if (ret != 0)
7075 		printf("bad priority flow contrl parameter, return code = %d \n", ret);
7076 }
7077 
7078 cmdline_parse_token_string_t cmd_pfc_set_set =
7079 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7080 				set, "set");
7081 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7082 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7083 				pfc_ctrl, "pfc_ctrl");
7084 cmdline_parse_token_string_t cmd_pfc_set_rx =
7085 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7086 				rx, "rx");
7087 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7088 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7089 				rx_pfc_mode, "on#off");
7090 cmdline_parse_token_string_t cmd_pfc_set_tx =
7091 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7092 				tx, "tx");
7093 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7094 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7095 				tx_pfc_mode, "on#off");
7096 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7097 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7098 				high_water, UINT32);
7099 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7100 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7101 				low_water, UINT32);
7102 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7103 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7104 				pause_time, UINT16);
7105 cmdline_parse_token_num_t cmd_pfc_set_priority =
7106 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7107 				priority, UINT8);
7108 cmdline_parse_token_num_t cmd_pfc_set_portid =
7109 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7110 				port_id, UINT16);
7111 
7112 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7113 	.f = cmd_priority_flow_ctrl_set_parsed,
7114 	.data = NULL,
7115 	.help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7116 		"<pause_time> <priority> <port_id>: "
7117 		"Configure the Ethernet priority flow control",
7118 	.tokens = {
7119 		(void *)&cmd_pfc_set_set,
7120 		(void *)&cmd_pfc_set_flow_ctrl,
7121 		(void *)&cmd_pfc_set_rx,
7122 		(void *)&cmd_pfc_set_rx_mode,
7123 		(void *)&cmd_pfc_set_tx,
7124 		(void *)&cmd_pfc_set_tx_mode,
7125 		(void *)&cmd_pfc_set_high_water,
7126 		(void *)&cmd_pfc_set_low_water,
7127 		(void *)&cmd_pfc_set_pause_time,
7128 		(void *)&cmd_pfc_set_priority,
7129 		(void *)&cmd_pfc_set_portid,
7130 		NULL,
7131 	},
7132 };
7133 
7134 /* *** RESET CONFIGURATION *** */
7135 struct cmd_reset_result {
7136 	cmdline_fixed_string_t reset;
7137 	cmdline_fixed_string_t def;
7138 };
7139 
7140 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7141 			     struct cmdline *cl,
7142 			     __attribute__((unused)) void *data)
7143 {
7144 	cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7145 	set_def_fwd_config();
7146 }
7147 
7148 cmdline_parse_token_string_t cmd_reset_set =
7149 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7150 cmdline_parse_token_string_t cmd_reset_def =
7151 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7152 				 "default");
7153 
7154 cmdline_parse_inst_t cmd_reset = {
7155 	.f = cmd_reset_parsed,
7156 	.data = NULL,
7157 	.help_str = "set default: Reset default forwarding configuration",
7158 	.tokens = {
7159 		(void *)&cmd_reset_set,
7160 		(void *)&cmd_reset_def,
7161 		NULL,
7162 	},
7163 };
7164 
7165 /* *** START FORWARDING *** */
7166 struct cmd_start_result {
7167 	cmdline_fixed_string_t start;
7168 };
7169 
7170 cmdline_parse_token_string_t cmd_start_start =
7171 	TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7172 
7173 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7174 			     __attribute__((unused)) struct cmdline *cl,
7175 			     __attribute__((unused)) void *data)
7176 {
7177 	start_packet_forwarding(0);
7178 }
7179 
7180 cmdline_parse_inst_t cmd_start = {
7181 	.f = cmd_start_parsed,
7182 	.data = NULL,
7183 	.help_str = "start: Start packet forwarding",
7184 	.tokens = {
7185 		(void *)&cmd_start_start,
7186 		NULL,
7187 	},
7188 };
7189 
7190 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7191 struct cmd_start_tx_first_result {
7192 	cmdline_fixed_string_t start;
7193 	cmdline_fixed_string_t tx_first;
7194 };
7195 
7196 static void
7197 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7198 			  __attribute__((unused)) struct cmdline *cl,
7199 			  __attribute__((unused)) void *data)
7200 {
7201 	start_packet_forwarding(1);
7202 }
7203 
7204 cmdline_parse_token_string_t cmd_start_tx_first_start =
7205 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7206 				 "start");
7207 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7208 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7209 				 tx_first, "tx_first");
7210 
7211 cmdline_parse_inst_t cmd_start_tx_first = {
7212 	.f = cmd_start_tx_first_parsed,
7213 	.data = NULL,
7214 	.help_str = "start tx_first: Start packet forwarding, "
7215 		"after sending 1 burst of packets",
7216 	.tokens = {
7217 		(void *)&cmd_start_tx_first_start,
7218 		(void *)&cmd_start_tx_first_tx_first,
7219 		NULL,
7220 	},
7221 };
7222 
7223 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7224 struct cmd_start_tx_first_n_result {
7225 	cmdline_fixed_string_t start;
7226 	cmdline_fixed_string_t tx_first;
7227 	uint32_t tx_num;
7228 };
7229 
7230 static void
7231 cmd_start_tx_first_n_parsed(void *parsed_result,
7232 			  __attribute__((unused)) struct cmdline *cl,
7233 			  __attribute__((unused)) void *data)
7234 {
7235 	struct cmd_start_tx_first_n_result *res = parsed_result;
7236 
7237 	start_packet_forwarding(res->tx_num);
7238 }
7239 
7240 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7241 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7242 			start, "start");
7243 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7244 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7245 			tx_first, "tx_first");
7246 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7247 	TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7248 			tx_num, UINT32);
7249 
7250 cmdline_parse_inst_t cmd_start_tx_first_n = {
7251 	.f = cmd_start_tx_first_n_parsed,
7252 	.data = NULL,
7253 	.help_str = "start tx_first <num>: "
7254 		"packet forwarding, after sending <num> bursts of packets",
7255 	.tokens = {
7256 		(void *)&cmd_start_tx_first_n_start,
7257 		(void *)&cmd_start_tx_first_n_tx_first,
7258 		(void *)&cmd_start_tx_first_n_tx_num,
7259 		NULL,
7260 	},
7261 };
7262 
7263 /* *** SET LINK UP *** */
7264 struct cmd_set_link_up_result {
7265 	cmdline_fixed_string_t set;
7266 	cmdline_fixed_string_t link_up;
7267 	cmdline_fixed_string_t port;
7268 	portid_t port_id;
7269 };
7270 
7271 cmdline_parse_token_string_t cmd_set_link_up_set =
7272 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7273 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7274 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7275 				"link-up");
7276 cmdline_parse_token_string_t cmd_set_link_up_port =
7277 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7278 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7279 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7280 
7281 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7282 			     __attribute__((unused)) struct cmdline *cl,
7283 			     __attribute__((unused)) void *data)
7284 {
7285 	struct cmd_set_link_up_result *res = parsed_result;
7286 	dev_set_link_up(res->port_id);
7287 }
7288 
7289 cmdline_parse_inst_t cmd_set_link_up = {
7290 	.f = cmd_set_link_up_parsed,
7291 	.data = NULL,
7292 	.help_str = "set link-up port <port id>",
7293 	.tokens = {
7294 		(void *)&cmd_set_link_up_set,
7295 		(void *)&cmd_set_link_up_link_up,
7296 		(void *)&cmd_set_link_up_port,
7297 		(void *)&cmd_set_link_up_port_id,
7298 		NULL,
7299 	},
7300 };
7301 
7302 /* *** SET LINK DOWN *** */
7303 struct cmd_set_link_down_result {
7304 	cmdline_fixed_string_t set;
7305 	cmdline_fixed_string_t link_down;
7306 	cmdline_fixed_string_t port;
7307 	portid_t port_id;
7308 };
7309 
7310 cmdline_parse_token_string_t cmd_set_link_down_set =
7311 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7312 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7313 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7314 				"link-down");
7315 cmdline_parse_token_string_t cmd_set_link_down_port =
7316 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7317 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7318 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7319 
7320 static void cmd_set_link_down_parsed(
7321 				__attribute__((unused)) void *parsed_result,
7322 				__attribute__((unused)) struct cmdline *cl,
7323 				__attribute__((unused)) void *data)
7324 {
7325 	struct cmd_set_link_down_result *res = parsed_result;
7326 	dev_set_link_down(res->port_id);
7327 }
7328 
7329 cmdline_parse_inst_t cmd_set_link_down = {
7330 	.f = cmd_set_link_down_parsed,
7331 	.data = NULL,
7332 	.help_str = "set link-down port <port id>",
7333 	.tokens = {
7334 		(void *)&cmd_set_link_down_set,
7335 		(void *)&cmd_set_link_down_link_down,
7336 		(void *)&cmd_set_link_down_port,
7337 		(void *)&cmd_set_link_down_port_id,
7338 		NULL,
7339 	},
7340 };
7341 
7342 /* *** SHOW CFG *** */
7343 struct cmd_showcfg_result {
7344 	cmdline_fixed_string_t show;
7345 	cmdline_fixed_string_t cfg;
7346 	cmdline_fixed_string_t what;
7347 };
7348 
7349 static void cmd_showcfg_parsed(void *parsed_result,
7350 			       __attribute__((unused)) struct cmdline *cl,
7351 			       __attribute__((unused)) void *data)
7352 {
7353 	struct cmd_showcfg_result *res = parsed_result;
7354 	if (!strcmp(res->what, "rxtx"))
7355 		rxtx_config_display();
7356 	else if (!strcmp(res->what, "cores"))
7357 		fwd_lcores_config_display();
7358 	else if (!strcmp(res->what, "fwd"))
7359 		pkt_fwd_config_display(&cur_fwd_config);
7360 	else if (!strcmp(res->what, "txpkts"))
7361 		show_tx_pkt_segments();
7362 }
7363 
7364 cmdline_parse_token_string_t cmd_showcfg_show =
7365 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7366 cmdline_parse_token_string_t cmd_showcfg_port =
7367 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7368 cmdline_parse_token_string_t cmd_showcfg_what =
7369 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7370 				 "rxtx#cores#fwd#txpkts");
7371 
7372 cmdline_parse_inst_t cmd_showcfg = {
7373 	.f = cmd_showcfg_parsed,
7374 	.data = NULL,
7375 	.help_str = "show config rxtx|cores|fwd|txpkts",
7376 	.tokens = {
7377 		(void *)&cmd_showcfg_show,
7378 		(void *)&cmd_showcfg_port,
7379 		(void *)&cmd_showcfg_what,
7380 		NULL,
7381 	},
7382 };
7383 
7384 /* *** SHOW ALL PORT INFO *** */
7385 struct cmd_showportall_result {
7386 	cmdline_fixed_string_t show;
7387 	cmdline_fixed_string_t port;
7388 	cmdline_fixed_string_t what;
7389 	cmdline_fixed_string_t all;
7390 };
7391 
7392 static void cmd_showportall_parsed(void *parsed_result,
7393 				__attribute__((unused)) struct cmdline *cl,
7394 				__attribute__((unused)) void *data)
7395 {
7396 	portid_t i;
7397 
7398 	struct cmd_showportall_result *res = parsed_result;
7399 	if (!strcmp(res->show, "clear")) {
7400 		if (!strcmp(res->what, "stats"))
7401 			RTE_ETH_FOREACH_DEV(i)
7402 				nic_stats_clear(i);
7403 		else if (!strcmp(res->what, "xstats"))
7404 			RTE_ETH_FOREACH_DEV(i)
7405 				nic_xstats_clear(i);
7406 	} else if (!strcmp(res->what, "info"))
7407 		RTE_ETH_FOREACH_DEV(i)
7408 			port_infos_display(i);
7409 	else if (!strcmp(res->what, "summary")) {
7410 		port_summary_header_display();
7411 		RTE_ETH_FOREACH_DEV(i)
7412 			port_summary_display(i);
7413 	}
7414 	else if (!strcmp(res->what, "stats"))
7415 		RTE_ETH_FOREACH_DEV(i)
7416 			nic_stats_display(i);
7417 	else if (!strcmp(res->what, "xstats"))
7418 		RTE_ETH_FOREACH_DEV(i)
7419 			nic_xstats_display(i);
7420 	else if (!strcmp(res->what, "fdir"))
7421 		RTE_ETH_FOREACH_DEV(i)
7422 			fdir_get_infos(i);
7423 	else if (!strcmp(res->what, "stat_qmap"))
7424 		RTE_ETH_FOREACH_DEV(i)
7425 			nic_stats_mapping_display(i);
7426 	else if (!strcmp(res->what, "dcb_tc"))
7427 		RTE_ETH_FOREACH_DEV(i)
7428 			port_dcb_info_display(i);
7429 	else if (!strcmp(res->what, "cap"))
7430 		RTE_ETH_FOREACH_DEV(i)
7431 			port_offload_cap_display(i);
7432 }
7433 
7434 cmdline_parse_token_string_t cmd_showportall_show =
7435 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7436 				 "show#clear");
7437 cmdline_parse_token_string_t cmd_showportall_port =
7438 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7439 cmdline_parse_token_string_t cmd_showportall_what =
7440 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7441 				 "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7442 cmdline_parse_token_string_t cmd_showportall_all =
7443 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7444 cmdline_parse_inst_t cmd_showportall = {
7445 	.f = cmd_showportall_parsed,
7446 	.data = NULL,
7447 	.help_str = "show|clear port "
7448 		"info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7449 	.tokens = {
7450 		(void *)&cmd_showportall_show,
7451 		(void *)&cmd_showportall_port,
7452 		(void *)&cmd_showportall_what,
7453 		(void *)&cmd_showportall_all,
7454 		NULL,
7455 	},
7456 };
7457 
7458 /* *** SHOW PORT INFO *** */
7459 struct cmd_showport_result {
7460 	cmdline_fixed_string_t show;
7461 	cmdline_fixed_string_t port;
7462 	cmdline_fixed_string_t what;
7463 	uint16_t portnum;
7464 };
7465 
7466 static void cmd_showport_parsed(void *parsed_result,
7467 				__attribute__((unused)) struct cmdline *cl,
7468 				__attribute__((unused)) void *data)
7469 {
7470 	struct cmd_showport_result *res = parsed_result;
7471 	if (!strcmp(res->show, "clear")) {
7472 		if (!strcmp(res->what, "stats"))
7473 			nic_stats_clear(res->portnum);
7474 		else if (!strcmp(res->what, "xstats"))
7475 			nic_xstats_clear(res->portnum);
7476 	} else if (!strcmp(res->what, "info"))
7477 		port_infos_display(res->portnum);
7478 	else if (!strcmp(res->what, "summary")) {
7479 		port_summary_header_display();
7480 		port_summary_display(res->portnum);
7481 	}
7482 	else if (!strcmp(res->what, "stats"))
7483 		nic_stats_display(res->portnum);
7484 	else if (!strcmp(res->what, "xstats"))
7485 		nic_xstats_display(res->portnum);
7486 	else if (!strcmp(res->what, "fdir"))
7487 		 fdir_get_infos(res->portnum);
7488 	else if (!strcmp(res->what, "stat_qmap"))
7489 		nic_stats_mapping_display(res->portnum);
7490 	else if (!strcmp(res->what, "dcb_tc"))
7491 		port_dcb_info_display(res->portnum);
7492 	else if (!strcmp(res->what, "cap"))
7493 		port_offload_cap_display(res->portnum);
7494 }
7495 
7496 cmdline_parse_token_string_t cmd_showport_show =
7497 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7498 				 "show#clear");
7499 cmdline_parse_token_string_t cmd_showport_port =
7500 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7501 cmdline_parse_token_string_t cmd_showport_what =
7502 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7503 				 "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7504 cmdline_parse_token_num_t cmd_showport_portnum =
7505 	TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7506 
7507 cmdline_parse_inst_t cmd_showport = {
7508 	.f = cmd_showport_parsed,
7509 	.data = NULL,
7510 	.help_str = "show|clear port "
7511 		"info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7512 		"<port_id>",
7513 	.tokens = {
7514 		(void *)&cmd_showport_show,
7515 		(void *)&cmd_showport_port,
7516 		(void *)&cmd_showport_what,
7517 		(void *)&cmd_showport_portnum,
7518 		NULL,
7519 	},
7520 };
7521 
7522 /* *** SHOW DEVICE INFO *** */
7523 struct cmd_showdevice_result {
7524 	cmdline_fixed_string_t show;
7525 	cmdline_fixed_string_t device;
7526 	cmdline_fixed_string_t what;
7527 	cmdline_fixed_string_t identifier;
7528 };
7529 
7530 static void cmd_showdevice_parsed(void *parsed_result,
7531 				__attribute__((unused)) struct cmdline *cl,
7532 				__attribute__((unused)) void *data)
7533 {
7534 	struct cmd_showdevice_result *res = parsed_result;
7535 	if (!strcmp(res->what, "info")) {
7536 		if (!strcmp(res->identifier, "all"))
7537 			device_infos_display(NULL);
7538 		else
7539 			device_infos_display(res->identifier);
7540 	}
7541 }
7542 
7543 cmdline_parse_token_string_t cmd_showdevice_show =
7544 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7545 				 "show");
7546 cmdline_parse_token_string_t cmd_showdevice_device =
7547 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7548 cmdline_parse_token_string_t cmd_showdevice_what =
7549 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7550 				 "info");
7551 cmdline_parse_token_string_t cmd_showdevice_identifier =
7552 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7553 			identifier, NULL);
7554 
7555 cmdline_parse_inst_t cmd_showdevice = {
7556 	.f = cmd_showdevice_parsed,
7557 	.data = NULL,
7558 	.help_str = "show device info <identifier>|all",
7559 	.tokens = {
7560 		(void *)&cmd_showdevice_show,
7561 		(void *)&cmd_showdevice_device,
7562 		(void *)&cmd_showdevice_what,
7563 		(void *)&cmd_showdevice_identifier,
7564 		NULL,
7565 	},
7566 };
7567 /* *** SHOW QUEUE INFO *** */
7568 struct cmd_showqueue_result {
7569 	cmdline_fixed_string_t show;
7570 	cmdline_fixed_string_t type;
7571 	cmdline_fixed_string_t what;
7572 	uint16_t portnum;
7573 	uint16_t queuenum;
7574 };
7575 
7576 static void
7577 cmd_showqueue_parsed(void *parsed_result,
7578 	__attribute__((unused)) struct cmdline *cl,
7579 	__attribute__((unused)) void *data)
7580 {
7581 	struct cmd_showqueue_result *res = parsed_result;
7582 
7583 	if (!strcmp(res->type, "rxq"))
7584 		rx_queue_infos_display(res->portnum, res->queuenum);
7585 	else if (!strcmp(res->type, "txq"))
7586 		tx_queue_infos_display(res->portnum, res->queuenum);
7587 }
7588 
7589 cmdline_parse_token_string_t cmd_showqueue_show =
7590 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7591 cmdline_parse_token_string_t cmd_showqueue_type =
7592 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7593 cmdline_parse_token_string_t cmd_showqueue_what =
7594 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7595 cmdline_parse_token_num_t cmd_showqueue_portnum =
7596 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7597 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7598 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7599 
7600 cmdline_parse_inst_t cmd_showqueue = {
7601 	.f = cmd_showqueue_parsed,
7602 	.data = NULL,
7603 	.help_str = "show rxq|txq info <port_id> <queue_id>",
7604 	.tokens = {
7605 		(void *)&cmd_showqueue_show,
7606 		(void *)&cmd_showqueue_type,
7607 		(void *)&cmd_showqueue_what,
7608 		(void *)&cmd_showqueue_portnum,
7609 		(void *)&cmd_showqueue_queuenum,
7610 		NULL,
7611 	},
7612 };
7613 
7614 /* show/clear fwd engine statistics */
7615 struct fwd_result {
7616 	cmdline_fixed_string_t action;
7617 	cmdline_fixed_string_t fwd;
7618 	cmdline_fixed_string_t stats;
7619 	cmdline_fixed_string_t all;
7620 };
7621 
7622 cmdline_parse_token_string_t cmd_fwd_action =
7623 	TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7624 cmdline_parse_token_string_t cmd_fwd_fwd =
7625 	TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7626 cmdline_parse_token_string_t cmd_fwd_stats =
7627 	TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7628 cmdline_parse_token_string_t cmd_fwd_all =
7629 	TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7630 
7631 static void
7632 cmd_showfwdall_parsed(void *parsed_result,
7633 		      __rte_unused struct cmdline *cl,
7634 		      __rte_unused void *data)
7635 {
7636 	struct fwd_result *res = parsed_result;
7637 
7638 	if (!strcmp(res->action, "show"))
7639 		fwd_stats_display();
7640 	else
7641 		fwd_stats_reset();
7642 }
7643 
7644 static cmdline_parse_inst_t cmd_showfwdall = {
7645 	.f = cmd_showfwdall_parsed,
7646 	.data = NULL,
7647 	.help_str = "show|clear fwd stats all",
7648 	.tokens = {
7649 		(void *)&cmd_fwd_action,
7650 		(void *)&cmd_fwd_fwd,
7651 		(void *)&cmd_fwd_stats,
7652 		(void *)&cmd_fwd_all,
7653 		NULL,
7654 	},
7655 };
7656 
7657 /* *** READ PORT REGISTER *** */
7658 struct cmd_read_reg_result {
7659 	cmdline_fixed_string_t read;
7660 	cmdline_fixed_string_t reg;
7661 	portid_t port_id;
7662 	uint32_t reg_off;
7663 };
7664 
7665 static void
7666 cmd_read_reg_parsed(void *parsed_result,
7667 		    __attribute__((unused)) struct cmdline *cl,
7668 		    __attribute__((unused)) void *data)
7669 {
7670 	struct cmd_read_reg_result *res = parsed_result;
7671 	port_reg_display(res->port_id, res->reg_off);
7672 }
7673 
7674 cmdline_parse_token_string_t cmd_read_reg_read =
7675 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7676 cmdline_parse_token_string_t cmd_read_reg_reg =
7677 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7678 cmdline_parse_token_num_t cmd_read_reg_port_id =
7679 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7680 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7681 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7682 
7683 cmdline_parse_inst_t cmd_read_reg = {
7684 	.f = cmd_read_reg_parsed,
7685 	.data = NULL,
7686 	.help_str = "read reg <port_id> <reg_off>",
7687 	.tokens = {
7688 		(void *)&cmd_read_reg_read,
7689 		(void *)&cmd_read_reg_reg,
7690 		(void *)&cmd_read_reg_port_id,
7691 		(void *)&cmd_read_reg_reg_off,
7692 		NULL,
7693 	},
7694 };
7695 
7696 /* *** READ PORT REGISTER BIT FIELD *** */
7697 struct cmd_read_reg_bit_field_result {
7698 	cmdline_fixed_string_t read;
7699 	cmdline_fixed_string_t regfield;
7700 	portid_t port_id;
7701 	uint32_t reg_off;
7702 	uint8_t bit1_pos;
7703 	uint8_t bit2_pos;
7704 };
7705 
7706 static void
7707 cmd_read_reg_bit_field_parsed(void *parsed_result,
7708 			      __attribute__((unused)) struct cmdline *cl,
7709 			      __attribute__((unused)) void *data)
7710 {
7711 	struct cmd_read_reg_bit_field_result *res = parsed_result;
7712 	port_reg_bit_field_display(res->port_id, res->reg_off,
7713 				   res->bit1_pos, res->bit2_pos);
7714 }
7715 
7716 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7717 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7718 				 "read");
7719 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7720 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7721 				 regfield, "regfield");
7722 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7723 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7724 			      UINT16);
7725 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7726 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7727 			      UINT32);
7728 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7729 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7730 			      UINT8);
7731 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7732 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7733 			      UINT8);
7734 
7735 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7736 	.f = cmd_read_reg_bit_field_parsed,
7737 	.data = NULL,
7738 	.help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7739 	"Read register bit field between bit_x and bit_y included",
7740 	.tokens = {
7741 		(void *)&cmd_read_reg_bit_field_read,
7742 		(void *)&cmd_read_reg_bit_field_regfield,
7743 		(void *)&cmd_read_reg_bit_field_port_id,
7744 		(void *)&cmd_read_reg_bit_field_reg_off,
7745 		(void *)&cmd_read_reg_bit_field_bit1_pos,
7746 		(void *)&cmd_read_reg_bit_field_bit2_pos,
7747 		NULL,
7748 	},
7749 };
7750 
7751 /* *** READ PORT REGISTER BIT *** */
7752 struct cmd_read_reg_bit_result {
7753 	cmdline_fixed_string_t read;
7754 	cmdline_fixed_string_t regbit;
7755 	portid_t port_id;
7756 	uint32_t reg_off;
7757 	uint8_t bit_pos;
7758 };
7759 
7760 static void
7761 cmd_read_reg_bit_parsed(void *parsed_result,
7762 			__attribute__((unused)) struct cmdline *cl,
7763 			__attribute__((unused)) void *data)
7764 {
7765 	struct cmd_read_reg_bit_result *res = parsed_result;
7766 	port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7767 }
7768 
7769 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7770 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7771 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7772 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7773 				 regbit, "regbit");
7774 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7775 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7776 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7777 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7778 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7779 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7780 
7781 cmdline_parse_inst_t cmd_read_reg_bit = {
7782 	.f = cmd_read_reg_bit_parsed,
7783 	.data = NULL,
7784 	.help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7785 	.tokens = {
7786 		(void *)&cmd_read_reg_bit_read,
7787 		(void *)&cmd_read_reg_bit_regbit,
7788 		(void *)&cmd_read_reg_bit_port_id,
7789 		(void *)&cmd_read_reg_bit_reg_off,
7790 		(void *)&cmd_read_reg_bit_bit_pos,
7791 		NULL,
7792 	},
7793 };
7794 
7795 /* *** WRITE PORT REGISTER *** */
7796 struct cmd_write_reg_result {
7797 	cmdline_fixed_string_t write;
7798 	cmdline_fixed_string_t reg;
7799 	portid_t port_id;
7800 	uint32_t reg_off;
7801 	uint32_t value;
7802 };
7803 
7804 static void
7805 cmd_write_reg_parsed(void *parsed_result,
7806 		     __attribute__((unused)) struct cmdline *cl,
7807 		     __attribute__((unused)) void *data)
7808 {
7809 	struct cmd_write_reg_result *res = parsed_result;
7810 	port_reg_set(res->port_id, res->reg_off, res->value);
7811 }
7812 
7813 cmdline_parse_token_string_t cmd_write_reg_write =
7814 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7815 cmdline_parse_token_string_t cmd_write_reg_reg =
7816 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7817 cmdline_parse_token_num_t cmd_write_reg_port_id =
7818 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7819 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7820 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7821 cmdline_parse_token_num_t cmd_write_reg_value =
7822 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7823 
7824 cmdline_parse_inst_t cmd_write_reg = {
7825 	.f = cmd_write_reg_parsed,
7826 	.data = NULL,
7827 	.help_str = "write reg <port_id> <reg_off> <reg_value>",
7828 	.tokens = {
7829 		(void *)&cmd_write_reg_write,
7830 		(void *)&cmd_write_reg_reg,
7831 		(void *)&cmd_write_reg_port_id,
7832 		(void *)&cmd_write_reg_reg_off,
7833 		(void *)&cmd_write_reg_value,
7834 		NULL,
7835 	},
7836 };
7837 
7838 /* *** WRITE PORT REGISTER BIT FIELD *** */
7839 struct cmd_write_reg_bit_field_result {
7840 	cmdline_fixed_string_t write;
7841 	cmdline_fixed_string_t regfield;
7842 	portid_t port_id;
7843 	uint32_t reg_off;
7844 	uint8_t bit1_pos;
7845 	uint8_t bit2_pos;
7846 	uint32_t value;
7847 };
7848 
7849 static void
7850 cmd_write_reg_bit_field_parsed(void *parsed_result,
7851 			       __attribute__((unused)) struct cmdline *cl,
7852 			       __attribute__((unused)) void *data)
7853 {
7854 	struct cmd_write_reg_bit_field_result *res = parsed_result;
7855 	port_reg_bit_field_set(res->port_id, res->reg_off,
7856 			  res->bit1_pos, res->bit2_pos, res->value);
7857 }
7858 
7859 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7860 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7861 				 "write");
7862 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7863 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7864 				 regfield, "regfield");
7865 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7866 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7867 			      UINT16);
7868 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7869 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7870 			      UINT32);
7871 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7872 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7873 			      UINT8);
7874 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7875 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7876 			      UINT8);
7877 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7878 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7879 			      UINT32);
7880 
7881 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7882 	.f = cmd_write_reg_bit_field_parsed,
7883 	.data = NULL,
7884 	.help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7885 		"<reg_value>: "
7886 		"Set register bit field between bit_x and bit_y included",
7887 	.tokens = {
7888 		(void *)&cmd_write_reg_bit_field_write,
7889 		(void *)&cmd_write_reg_bit_field_regfield,
7890 		(void *)&cmd_write_reg_bit_field_port_id,
7891 		(void *)&cmd_write_reg_bit_field_reg_off,
7892 		(void *)&cmd_write_reg_bit_field_bit1_pos,
7893 		(void *)&cmd_write_reg_bit_field_bit2_pos,
7894 		(void *)&cmd_write_reg_bit_field_value,
7895 		NULL,
7896 	},
7897 };
7898 
7899 /* *** WRITE PORT REGISTER BIT *** */
7900 struct cmd_write_reg_bit_result {
7901 	cmdline_fixed_string_t write;
7902 	cmdline_fixed_string_t regbit;
7903 	portid_t port_id;
7904 	uint32_t reg_off;
7905 	uint8_t bit_pos;
7906 	uint8_t value;
7907 };
7908 
7909 static void
7910 cmd_write_reg_bit_parsed(void *parsed_result,
7911 			 __attribute__((unused)) struct cmdline *cl,
7912 			 __attribute__((unused)) void *data)
7913 {
7914 	struct cmd_write_reg_bit_result *res = parsed_result;
7915 	port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7916 }
7917 
7918 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7919 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7920 				 "write");
7921 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7922 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7923 				 regbit, "regbit");
7924 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7925 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7926 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7927 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7928 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7929 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7930 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7931 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7932 
7933 cmdline_parse_inst_t cmd_write_reg_bit = {
7934 	.f = cmd_write_reg_bit_parsed,
7935 	.data = NULL,
7936 	.help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7937 		"0 <= bit_x <= 31",
7938 	.tokens = {
7939 		(void *)&cmd_write_reg_bit_write,
7940 		(void *)&cmd_write_reg_bit_regbit,
7941 		(void *)&cmd_write_reg_bit_port_id,
7942 		(void *)&cmd_write_reg_bit_reg_off,
7943 		(void *)&cmd_write_reg_bit_bit_pos,
7944 		(void *)&cmd_write_reg_bit_value,
7945 		NULL,
7946 	},
7947 };
7948 
7949 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7950 struct cmd_read_rxd_txd_result {
7951 	cmdline_fixed_string_t read;
7952 	cmdline_fixed_string_t rxd_txd;
7953 	portid_t port_id;
7954 	uint16_t queue_id;
7955 	uint16_t desc_id;
7956 };
7957 
7958 static void
7959 cmd_read_rxd_txd_parsed(void *parsed_result,
7960 			__attribute__((unused)) struct cmdline *cl,
7961 			__attribute__((unused)) void *data)
7962 {
7963 	struct cmd_read_rxd_txd_result *res = parsed_result;
7964 
7965 	if (!strcmp(res->rxd_txd, "rxd"))
7966 		rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7967 	else if (!strcmp(res->rxd_txd, "txd"))
7968 		tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7969 }
7970 
7971 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7972 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7973 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7974 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7975 				 "rxd#txd");
7976 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7977 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7978 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7979 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7980 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7981 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7982 
7983 cmdline_parse_inst_t cmd_read_rxd_txd = {
7984 	.f = cmd_read_rxd_txd_parsed,
7985 	.data = NULL,
7986 	.help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7987 	.tokens = {
7988 		(void *)&cmd_read_rxd_txd_read,
7989 		(void *)&cmd_read_rxd_txd_rxd_txd,
7990 		(void *)&cmd_read_rxd_txd_port_id,
7991 		(void *)&cmd_read_rxd_txd_queue_id,
7992 		(void *)&cmd_read_rxd_txd_desc_id,
7993 		NULL,
7994 	},
7995 };
7996 
7997 /* *** QUIT *** */
7998 struct cmd_quit_result {
7999 	cmdline_fixed_string_t quit;
8000 };
8001 
8002 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
8003 			    struct cmdline *cl,
8004 			    __attribute__((unused)) void *data)
8005 {
8006 	cmdline_quit(cl);
8007 }
8008 
8009 cmdline_parse_token_string_t cmd_quit_quit =
8010 	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8011 
8012 cmdline_parse_inst_t cmd_quit = {
8013 	.f = cmd_quit_parsed,
8014 	.data = NULL,
8015 	.help_str = "quit: Exit application",
8016 	.tokens = {
8017 		(void *)&cmd_quit_quit,
8018 		NULL,
8019 	},
8020 };
8021 
8022 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8023 struct cmd_mac_addr_result {
8024 	cmdline_fixed_string_t mac_addr_cmd;
8025 	cmdline_fixed_string_t what;
8026 	uint16_t port_num;
8027 	struct rte_ether_addr address;
8028 };
8029 
8030 static void cmd_mac_addr_parsed(void *parsed_result,
8031 		__attribute__((unused)) struct cmdline *cl,
8032 		__attribute__((unused)) void *data)
8033 {
8034 	struct cmd_mac_addr_result *res = parsed_result;
8035 	int ret;
8036 
8037 	if (strcmp(res->what, "add") == 0)
8038 		ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8039 	else if (strcmp(res->what, "set") == 0)
8040 		ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8041 						       &res->address);
8042 	else
8043 		ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8044 
8045 	/* check the return value and print it if is < 0 */
8046 	if(ret < 0)
8047 		printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8048 
8049 }
8050 
8051 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8052 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8053 				"mac_addr");
8054 cmdline_parse_token_string_t cmd_mac_addr_what =
8055 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8056 				"add#remove#set");
8057 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8058 		TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8059 					UINT16);
8060 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8061 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8062 
8063 cmdline_parse_inst_t cmd_mac_addr = {
8064 	.f = cmd_mac_addr_parsed,
8065 	.data = (void *)0,
8066 	.help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8067 			"Add/Remove/Set MAC address on port_id",
8068 	.tokens = {
8069 		(void *)&cmd_mac_addr_cmd,
8070 		(void *)&cmd_mac_addr_what,
8071 		(void *)&cmd_mac_addr_portnum,
8072 		(void *)&cmd_mac_addr_addr,
8073 		NULL,
8074 	},
8075 };
8076 
8077 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8078 struct cmd_eth_peer_result {
8079 	cmdline_fixed_string_t set;
8080 	cmdline_fixed_string_t eth_peer;
8081 	portid_t port_id;
8082 	cmdline_fixed_string_t peer_addr;
8083 };
8084 
8085 static void cmd_set_eth_peer_parsed(void *parsed_result,
8086 			__attribute__((unused)) struct cmdline *cl,
8087 			__attribute__((unused)) void *data)
8088 {
8089 		struct cmd_eth_peer_result *res = parsed_result;
8090 
8091 		if (test_done == 0) {
8092 			printf("Please stop forwarding first\n");
8093 			return;
8094 		}
8095 		if (!strcmp(res->eth_peer, "eth-peer")) {
8096 			set_fwd_eth_peer(res->port_id, res->peer_addr);
8097 			fwd_config_setup();
8098 		}
8099 }
8100 cmdline_parse_token_string_t cmd_eth_peer_set =
8101 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8102 cmdline_parse_token_string_t cmd_eth_peer =
8103 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8104 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8105 	TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8106 cmdline_parse_token_string_t cmd_eth_peer_addr =
8107 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8108 
8109 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8110 	.f = cmd_set_eth_peer_parsed,
8111 	.data = NULL,
8112 	.help_str = "set eth-peer <port_id> <peer_mac>",
8113 	.tokens = {
8114 		(void *)&cmd_eth_peer_set,
8115 		(void *)&cmd_eth_peer,
8116 		(void *)&cmd_eth_peer_port_id,
8117 		(void *)&cmd_eth_peer_addr,
8118 		NULL,
8119 	},
8120 };
8121 
8122 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8123 struct cmd_set_qmap_result {
8124 	cmdline_fixed_string_t set;
8125 	cmdline_fixed_string_t qmap;
8126 	cmdline_fixed_string_t what;
8127 	portid_t port_id;
8128 	uint16_t queue_id;
8129 	uint8_t map_value;
8130 };
8131 
8132 static void
8133 cmd_set_qmap_parsed(void *parsed_result,
8134 		       __attribute__((unused)) struct cmdline *cl,
8135 		       __attribute__((unused)) void *data)
8136 {
8137 	struct cmd_set_qmap_result *res = parsed_result;
8138 	int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8139 
8140 	set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8141 }
8142 
8143 cmdline_parse_token_string_t cmd_setqmap_set =
8144 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8145 				 set, "set");
8146 cmdline_parse_token_string_t cmd_setqmap_qmap =
8147 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8148 				 qmap, "stat_qmap");
8149 cmdline_parse_token_string_t cmd_setqmap_what =
8150 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8151 				 what, "tx#rx");
8152 cmdline_parse_token_num_t cmd_setqmap_portid =
8153 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8154 			      port_id, UINT16);
8155 cmdline_parse_token_num_t cmd_setqmap_queueid =
8156 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8157 			      queue_id, UINT16);
8158 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8159 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8160 			      map_value, UINT8);
8161 
8162 cmdline_parse_inst_t cmd_set_qmap = {
8163 	.f = cmd_set_qmap_parsed,
8164 	.data = NULL,
8165 	.help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8166 		"Set statistics mapping value on tx|rx queue_id of port_id",
8167 	.tokens = {
8168 		(void *)&cmd_setqmap_set,
8169 		(void *)&cmd_setqmap_qmap,
8170 		(void *)&cmd_setqmap_what,
8171 		(void *)&cmd_setqmap_portid,
8172 		(void *)&cmd_setqmap_queueid,
8173 		(void *)&cmd_setqmap_mapvalue,
8174 		NULL,
8175 	},
8176 };
8177 
8178 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8179 struct cmd_set_xstats_hide_zero_result {
8180 	cmdline_fixed_string_t keyword;
8181 	cmdline_fixed_string_t name;
8182 	cmdline_fixed_string_t on_off;
8183 };
8184 
8185 static void
8186 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8187 			__attribute__((unused)) struct cmdline *cl,
8188 			__attribute__((unused)) void *data)
8189 {
8190 	struct cmd_set_xstats_hide_zero_result *res;
8191 	uint16_t on_off = 0;
8192 
8193 	res = parsed_result;
8194 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8195 	set_xstats_hide_zero(on_off);
8196 }
8197 
8198 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8199 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8200 				 keyword, "set");
8201 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8202 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8203 				 name, "xstats-hide-zero");
8204 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8205 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8206 				 on_off, "on#off");
8207 
8208 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8209 	.f = cmd_set_xstats_hide_zero_parsed,
8210 	.data = NULL,
8211 	.help_str = "set xstats-hide-zero on|off",
8212 	.tokens = {
8213 		(void *)&cmd_set_xstats_hide_zero_keyword,
8214 		(void *)&cmd_set_xstats_hide_zero_name,
8215 		(void *)&cmd_set_xstats_hide_zero_on_off,
8216 		NULL,
8217 	},
8218 };
8219 
8220 /* *** CONFIGURE UNICAST HASH TABLE *** */
8221 struct cmd_set_uc_hash_table {
8222 	cmdline_fixed_string_t set;
8223 	cmdline_fixed_string_t port;
8224 	portid_t port_id;
8225 	cmdline_fixed_string_t what;
8226 	struct rte_ether_addr address;
8227 	cmdline_fixed_string_t mode;
8228 };
8229 
8230 static void
8231 cmd_set_uc_hash_parsed(void *parsed_result,
8232 		       __attribute__((unused)) struct cmdline *cl,
8233 		       __attribute__((unused)) void *data)
8234 {
8235 	int ret=0;
8236 	struct cmd_set_uc_hash_table *res = parsed_result;
8237 
8238 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8239 
8240 	if (strcmp(res->what, "uta") == 0)
8241 		ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8242 						&res->address,(uint8_t)is_on);
8243 	if (ret < 0)
8244 		printf("bad unicast hash table parameter, return code = %d \n", ret);
8245 
8246 }
8247 
8248 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8249 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8250 				 set, "set");
8251 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8252 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8253 				 port, "port");
8254 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8255 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8256 			      port_id, UINT16);
8257 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8258 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8259 				 what, "uta");
8260 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8261 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8262 				address);
8263 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8264 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8265 				 mode, "on#off");
8266 
8267 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8268 	.f = cmd_set_uc_hash_parsed,
8269 	.data = NULL,
8270 	.help_str = "set port <port_id> uta <mac_addr> on|off)",
8271 	.tokens = {
8272 		(void *)&cmd_set_uc_hash_set,
8273 		(void *)&cmd_set_uc_hash_port,
8274 		(void *)&cmd_set_uc_hash_portid,
8275 		(void *)&cmd_set_uc_hash_what,
8276 		(void *)&cmd_set_uc_hash_mac,
8277 		(void *)&cmd_set_uc_hash_mode,
8278 		NULL,
8279 	},
8280 };
8281 
8282 struct cmd_set_uc_all_hash_table {
8283 	cmdline_fixed_string_t set;
8284 	cmdline_fixed_string_t port;
8285 	portid_t port_id;
8286 	cmdline_fixed_string_t what;
8287 	cmdline_fixed_string_t value;
8288 	cmdline_fixed_string_t mode;
8289 };
8290 
8291 static void
8292 cmd_set_uc_all_hash_parsed(void *parsed_result,
8293 		       __attribute__((unused)) struct cmdline *cl,
8294 		       __attribute__((unused)) void *data)
8295 {
8296 	int ret=0;
8297 	struct cmd_set_uc_all_hash_table *res = parsed_result;
8298 
8299 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8300 
8301 	if ((strcmp(res->what, "uta") == 0) &&
8302 		(strcmp(res->value, "all") == 0))
8303 		ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8304 	if (ret < 0)
8305 		printf("bad unicast hash table parameter,"
8306 			"return code = %d \n", ret);
8307 }
8308 
8309 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8310 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8311 				 set, "set");
8312 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8313 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8314 				 port, "port");
8315 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8316 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8317 			      port_id, UINT16);
8318 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8319 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8320 				 what, "uta");
8321 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8322 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8323 				value,"all");
8324 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8325 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8326 				 mode, "on#off");
8327 
8328 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8329 	.f = cmd_set_uc_all_hash_parsed,
8330 	.data = NULL,
8331 	.help_str = "set port <port_id> uta all on|off",
8332 	.tokens = {
8333 		(void *)&cmd_set_uc_all_hash_set,
8334 		(void *)&cmd_set_uc_all_hash_port,
8335 		(void *)&cmd_set_uc_all_hash_portid,
8336 		(void *)&cmd_set_uc_all_hash_what,
8337 		(void *)&cmd_set_uc_all_hash_value,
8338 		(void *)&cmd_set_uc_all_hash_mode,
8339 		NULL,
8340 	},
8341 };
8342 
8343 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8344 struct cmd_set_vf_macvlan_filter {
8345 	cmdline_fixed_string_t set;
8346 	cmdline_fixed_string_t port;
8347 	portid_t port_id;
8348 	cmdline_fixed_string_t vf;
8349 	uint8_t vf_id;
8350 	struct rte_ether_addr address;
8351 	cmdline_fixed_string_t filter_type;
8352 	cmdline_fixed_string_t mode;
8353 };
8354 
8355 static void
8356 cmd_set_vf_macvlan_parsed(void *parsed_result,
8357 		       __attribute__((unused)) struct cmdline *cl,
8358 		       __attribute__((unused)) void *data)
8359 {
8360 	int is_on, ret = 0;
8361 	struct cmd_set_vf_macvlan_filter *res = parsed_result;
8362 	struct rte_eth_mac_filter filter;
8363 
8364 	memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8365 
8366 	rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8367 
8368 	/* set VF MAC filter */
8369 	filter.is_vf = 1;
8370 
8371 	/* set VF ID */
8372 	filter.dst_id = res->vf_id;
8373 
8374 	if (!strcmp(res->filter_type, "exact-mac"))
8375 		filter.filter_type = RTE_MAC_PERFECT_MATCH;
8376 	else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8377 		filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8378 	else if (!strcmp(res->filter_type, "hashmac"))
8379 		filter.filter_type = RTE_MAC_HASH_MATCH;
8380 	else if (!strcmp(res->filter_type, "hashmac-vlan"))
8381 		filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8382 
8383 	is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8384 
8385 	if (is_on)
8386 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8387 					RTE_ETH_FILTER_MACVLAN,
8388 					RTE_ETH_FILTER_ADD,
8389 					 &filter);
8390 	else
8391 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8392 					RTE_ETH_FILTER_MACVLAN,
8393 					RTE_ETH_FILTER_DELETE,
8394 					&filter);
8395 
8396 	if (ret < 0)
8397 		printf("bad set MAC hash parameter, return code = %d\n", ret);
8398 
8399 }
8400 
8401 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8402 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8403 				 set, "set");
8404 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8405 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8406 				 port, "port");
8407 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8408 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8409 			      port_id, UINT16);
8410 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8411 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8412 				 vf, "vf");
8413 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8414 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8415 				vf_id, UINT8);
8416 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8417 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8418 				address);
8419 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8420 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8421 				filter_type, "exact-mac#exact-mac-vlan"
8422 				"#hashmac#hashmac-vlan");
8423 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8424 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8425 				 mode, "on#off");
8426 
8427 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8428 	.f = cmd_set_vf_macvlan_parsed,
8429 	.data = NULL,
8430 	.help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8431 		"exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8432 		"Exact match rule: exact match of MAC or MAC and VLAN; "
8433 		"hash match rule: hash match of MAC and exact match of VLAN",
8434 	.tokens = {
8435 		(void *)&cmd_set_vf_macvlan_set,
8436 		(void *)&cmd_set_vf_macvlan_port,
8437 		(void *)&cmd_set_vf_macvlan_portid,
8438 		(void *)&cmd_set_vf_macvlan_vf,
8439 		(void *)&cmd_set_vf_macvlan_vf_id,
8440 		(void *)&cmd_set_vf_macvlan_mac,
8441 		(void *)&cmd_set_vf_macvlan_filter_type,
8442 		(void *)&cmd_set_vf_macvlan_mode,
8443 		NULL,
8444 	},
8445 };
8446 
8447 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8448 struct cmd_set_vf_traffic {
8449 	cmdline_fixed_string_t set;
8450 	cmdline_fixed_string_t port;
8451 	portid_t port_id;
8452 	cmdline_fixed_string_t vf;
8453 	uint8_t vf_id;
8454 	cmdline_fixed_string_t what;
8455 	cmdline_fixed_string_t mode;
8456 };
8457 
8458 static void
8459 cmd_set_vf_traffic_parsed(void *parsed_result,
8460 		       __attribute__((unused)) struct cmdline *cl,
8461 		       __attribute__((unused)) void *data)
8462 {
8463 	struct cmd_set_vf_traffic *res = parsed_result;
8464 	int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8465 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8466 
8467 	set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8468 }
8469 
8470 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8471 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8472 				 set, "set");
8473 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8474 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8475 				 port, "port");
8476 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8477 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8478 			      port_id, UINT16);
8479 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8480 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8481 				 vf, "vf");
8482 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8483 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8484 			      vf_id, UINT8);
8485 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8486 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8487 				 what, "tx#rx");
8488 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8489 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8490 				 mode, "on#off");
8491 
8492 cmdline_parse_inst_t cmd_set_vf_traffic = {
8493 	.f = cmd_set_vf_traffic_parsed,
8494 	.data = NULL,
8495 	.help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8496 	.tokens = {
8497 		(void *)&cmd_setvf_traffic_set,
8498 		(void *)&cmd_setvf_traffic_port,
8499 		(void *)&cmd_setvf_traffic_portid,
8500 		(void *)&cmd_setvf_traffic_vf,
8501 		(void *)&cmd_setvf_traffic_vfid,
8502 		(void *)&cmd_setvf_traffic_what,
8503 		(void *)&cmd_setvf_traffic_mode,
8504 		NULL,
8505 	},
8506 };
8507 
8508 /* *** CONFIGURE VF RECEIVE MODE *** */
8509 struct cmd_set_vf_rxmode {
8510 	cmdline_fixed_string_t set;
8511 	cmdline_fixed_string_t port;
8512 	portid_t port_id;
8513 	cmdline_fixed_string_t vf;
8514 	uint8_t vf_id;
8515 	cmdline_fixed_string_t what;
8516 	cmdline_fixed_string_t mode;
8517 	cmdline_fixed_string_t on;
8518 };
8519 
8520 static void
8521 cmd_set_vf_rxmode_parsed(void *parsed_result,
8522 		       __attribute__((unused)) struct cmdline *cl,
8523 		       __attribute__((unused)) void *data)
8524 {
8525 	int ret = -ENOTSUP;
8526 	uint16_t rx_mode = 0;
8527 	struct cmd_set_vf_rxmode *res = parsed_result;
8528 
8529 	int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8530 	if (!strcmp(res->what,"rxmode")) {
8531 		if (!strcmp(res->mode, "AUPE"))
8532 			rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8533 		else if (!strcmp(res->mode, "ROPE"))
8534 			rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8535 		else if (!strcmp(res->mode, "BAM"))
8536 			rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8537 		else if (!strncmp(res->mode, "MPE",3))
8538 			rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8539 	}
8540 
8541 	RTE_SET_USED(is_on);
8542 
8543 #ifdef RTE_LIBRTE_IXGBE_PMD
8544 	if (ret == -ENOTSUP)
8545 		ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8546 						  rx_mode, (uint8_t)is_on);
8547 #endif
8548 #ifdef RTE_LIBRTE_BNXT_PMD
8549 	if (ret == -ENOTSUP)
8550 		ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8551 						 rx_mode, (uint8_t)is_on);
8552 #endif
8553 	if (ret < 0)
8554 		printf("bad VF receive mode parameter, return code = %d \n",
8555 		ret);
8556 }
8557 
8558 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8559 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8560 				 set, "set");
8561 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8562 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8563 				 port, "port");
8564 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8565 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8566 			      port_id, UINT16);
8567 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8568 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8569 				 vf, "vf");
8570 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8571 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8572 			      vf_id, UINT8);
8573 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8574 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8575 				 what, "rxmode");
8576 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8577 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8578 				 mode, "AUPE#ROPE#BAM#MPE");
8579 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8580 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8581 				 on, "on#off");
8582 
8583 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8584 	.f = cmd_set_vf_rxmode_parsed,
8585 	.data = NULL,
8586 	.help_str = "set port <port_id> vf <vf_id> rxmode "
8587 		"AUPE|ROPE|BAM|MPE on|off",
8588 	.tokens = {
8589 		(void *)&cmd_set_vf_rxmode_set,
8590 		(void *)&cmd_set_vf_rxmode_port,
8591 		(void *)&cmd_set_vf_rxmode_portid,
8592 		(void *)&cmd_set_vf_rxmode_vf,
8593 		(void *)&cmd_set_vf_rxmode_vfid,
8594 		(void *)&cmd_set_vf_rxmode_what,
8595 		(void *)&cmd_set_vf_rxmode_mode,
8596 		(void *)&cmd_set_vf_rxmode_on,
8597 		NULL,
8598 	},
8599 };
8600 
8601 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8602 struct cmd_vf_mac_addr_result {
8603 	cmdline_fixed_string_t mac_addr_cmd;
8604 	cmdline_fixed_string_t what;
8605 	cmdline_fixed_string_t port;
8606 	uint16_t port_num;
8607 	cmdline_fixed_string_t vf;
8608 	uint8_t vf_num;
8609 	struct rte_ether_addr address;
8610 };
8611 
8612 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8613 		__attribute__((unused)) struct cmdline *cl,
8614 		__attribute__((unused)) void *data)
8615 {
8616 	struct cmd_vf_mac_addr_result *res = parsed_result;
8617 	int ret = -ENOTSUP;
8618 
8619 	if (strcmp(res->what, "add") != 0)
8620 		return;
8621 
8622 #ifdef RTE_LIBRTE_I40E_PMD
8623 	if (ret == -ENOTSUP)
8624 		ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8625 						   &res->address);
8626 #endif
8627 #ifdef RTE_LIBRTE_BNXT_PMD
8628 	if (ret == -ENOTSUP)
8629 		ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8630 						res->vf_num);
8631 #endif
8632 
8633 	if(ret < 0)
8634 		printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8635 
8636 }
8637 
8638 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8639 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8640 				mac_addr_cmd,"mac_addr");
8641 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8642 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8643 				what,"add");
8644 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8645 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8646 				port,"port");
8647 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8648 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8649 				port_num, UINT16);
8650 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8651 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8652 				vf,"vf");
8653 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8654 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8655 				vf_num, UINT8);
8656 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8657 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8658 				address);
8659 
8660 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8661 	.f = cmd_vf_mac_addr_parsed,
8662 	.data = (void *)0,
8663 	.help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8664 		"Add MAC address filtering for a VF on port_id",
8665 	.tokens = {
8666 		(void *)&cmd_vf_mac_addr_cmd,
8667 		(void *)&cmd_vf_mac_addr_what,
8668 		(void *)&cmd_vf_mac_addr_port,
8669 		(void *)&cmd_vf_mac_addr_portnum,
8670 		(void *)&cmd_vf_mac_addr_vf,
8671 		(void *)&cmd_vf_mac_addr_vfnum,
8672 		(void *)&cmd_vf_mac_addr_addr,
8673 		NULL,
8674 	},
8675 };
8676 
8677 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8678 struct cmd_vf_rx_vlan_filter {
8679 	cmdline_fixed_string_t rx_vlan;
8680 	cmdline_fixed_string_t what;
8681 	uint16_t vlan_id;
8682 	cmdline_fixed_string_t port;
8683 	portid_t port_id;
8684 	cmdline_fixed_string_t vf;
8685 	uint64_t vf_mask;
8686 };
8687 
8688 static void
8689 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8690 			  __attribute__((unused)) struct cmdline *cl,
8691 			  __attribute__((unused)) void *data)
8692 {
8693 	struct cmd_vf_rx_vlan_filter *res = parsed_result;
8694 	int ret = -ENOTSUP;
8695 
8696 	__rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8697 
8698 #ifdef RTE_LIBRTE_IXGBE_PMD
8699 	if (ret == -ENOTSUP)
8700 		ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8701 				res->vlan_id, res->vf_mask, is_add);
8702 #endif
8703 #ifdef RTE_LIBRTE_I40E_PMD
8704 	if (ret == -ENOTSUP)
8705 		ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8706 				res->vlan_id, res->vf_mask, is_add);
8707 #endif
8708 #ifdef RTE_LIBRTE_BNXT_PMD
8709 	if (ret == -ENOTSUP)
8710 		ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8711 				res->vlan_id, res->vf_mask, is_add);
8712 #endif
8713 
8714 	switch (ret) {
8715 	case 0:
8716 		break;
8717 	case -EINVAL:
8718 		printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8719 				res->vlan_id, res->vf_mask);
8720 		break;
8721 	case -ENODEV:
8722 		printf("invalid port_id %d\n", res->port_id);
8723 		break;
8724 	case -ENOTSUP:
8725 		printf("function not implemented or supported\n");
8726 		break;
8727 	default:
8728 		printf("programming error: (%s)\n", strerror(-ret));
8729 	}
8730 }
8731 
8732 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8733 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8734 				 rx_vlan, "rx_vlan");
8735 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8736 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8737 				 what, "add#rm");
8738 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8739 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8740 			      vlan_id, UINT16);
8741 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8742 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8743 				 port, "port");
8744 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8745 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8746 			      port_id, UINT16);
8747 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8748 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8749 				 vf, "vf");
8750 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8751 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8752 			      vf_mask, UINT64);
8753 
8754 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8755 	.f = cmd_vf_rx_vlan_filter_parsed,
8756 	.data = NULL,
8757 	.help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8758 		"(vf_mask = hexadecimal VF mask)",
8759 	.tokens = {
8760 		(void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8761 		(void *)&cmd_vf_rx_vlan_filter_what,
8762 		(void *)&cmd_vf_rx_vlan_filter_vlanid,
8763 		(void *)&cmd_vf_rx_vlan_filter_port,
8764 		(void *)&cmd_vf_rx_vlan_filter_portid,
8765 		(void *)&cmd_vf_rx_vlan_filter_vf,
8766 		(void *)&cmd_vf_rx_vlan_filter_vf_mask,
8767 		NULL,
8768 	},
8769 };
8770 
8771 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8772 struct cmd_queue_rate_limit_result {
8773 	cmdline_fixed_string_t set;
8774 	cmdline_fixed_string_t port;
8775 	uint16_t port_num;
8776 	cmdline_fixed_string_t queue;
8777 	uint8_t queue_num;
8778 	cmdline_fixed_string_t rate;
8779 	uint16_t rate_num;
8780 };
8781 
8782 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8783 		__attribute__((unused)) struct cmdline *cl,
8784 		__attribute__((unused)) void *data)
8785 {
8786 	struct cmd_queue_rate_limit_result *res = parsed_result;
8787 	int ret = 0;
8788 
8789 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8790 		&& (strcmp(res->queue, "queue") == 0)
8791 		&& (strcmp(res->rate, "rate") == 0))
8792 		ret = set_queue_rate_limit(res->port_num, res->queue_num,
8793 					res->rate_num);
8794 	if (ret < 0)
8795 		printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8796 
8797 }
8798 
8799 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8800 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8801 				set, "set");
8802 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8803 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8804 				port, "port");
8805 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8806 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8807 				port_num, UINT16);
8808 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8809 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8810 				queue, "queue");
8811 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8812 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8813 				queue_num, UINT8);
8814 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8815 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8816 				rate, "rate");
8817 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8818 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8819 				rate_num, UINT16);
8820 
8821 cmdline_parse_inst_t cmd_queue_rate_limit = {
8822 	.f = cmd_queue_rate_limit_parsed,
8823 	.data = (void *)0,
8824 	.help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8825 		"Set rate limit for a queue on port_id",
8826 	.tokens = {
8827 		(void *)&cmd_queue_rate_limit_set,
8828 		(void *)&cmd_queue_rate_limit_port,
8829 		(void *)&cmd_queue_rate_limit_portnum,
8830 		(void *)&cmd_queue_rate_limit_queue,
8831 		(void *)&cmd_queue_rate_limit_queuenum,
8832 		(void *)&cmd_queue_rate_limit_rate,
8833 		(void *)&cmd_queue_rate_limit_ratenum,
8834 		NULL,
8835 	},
8836 };
8837 
8838 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8839 struct cmd_vf_rate_limit_result {
8840 	cmdline_fixed_string_t set;
8841 	cmdline_fixed_string_t port;
8842 	uint16_t port_num;
8843 	cmdline_fixed_string_t vf;
8844 	uint8_t vf_num;
8845 	cmdline_fixed_string_t rate;
8846 	uint16_t rate_num;
8847 	cmdline_fixed_string_t q_msk;
8848 	uint64_t q_msk_val;
8849 };
8850 
8851 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8852 		__attribute__((unused)) struct cmdline *cl,
8853 		__attribute__((unused)) void *data)
8854 {
8855 	struct cmd_vf_rate_limit_result *res = parsed_result;
8856 	int ret = 0;
8857 
8858 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8859 		&& (strcmp(res->vf, "vf") == 0)
8860 		&& (strcmp(res->rate, "rate") == 0)
8861 		&& (strcmp(res->q_msk, "queue_mask") == 0))
8862 		ret = set_vf_rate_limit(res->port_num, res->vf_num,
8863 					res->rate_num, res->q_msk_val);
8864 	if (ret < 0)
8865 		printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8866 
8867 }
8868 
8869 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8870 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8871 				set, "set");
8872 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8873 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8874 				port, "port");
8875 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8876 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8877 				port_num, UINT16);
8878 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8879 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8880 				vf, "vf");
8881 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8882 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8883 				vf_num, UINT8);
8884 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8885 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8886 				rate, "rate");
8887 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8888 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8889 				rate_num, UINT16);
8890 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8891 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8892 				q_msk, "queue_mask");
8893 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8894 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8895 				q_msk_val, UINT64);
8896 
8897 cmdline_parse_inst_t cmd_vf_rate_limit = {
8898 	.f = cmd_vf_rate_limit_parsed,
8899 	.data = (void *)0,
8900 	.help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8901 		"queue_mask <queue_mask_value>: "
8902 		"Set rate limit for queues of VF on port_id",
8903 	.tokens = {
8904 		(void *)&cmd_vf_rate_limit_set,
8905 		(void *)&cmd_vf_rate_limit_port,
8906 		(void *)&cmd_vf_rate_limit_portnum,
8907 		(void *)&cmd_vf_rate_limit_vf,
8908 		(void *)&cmd_vf_rate_limit_vfnum,
8909 		(void *)&cmd_vf_rate_limit_rate,
8910 		(void *)&cmd_vf_rate_limit_ratenum,
8911 		(void *)&cmd_vf_rate_limit_q_msk,
8912 		(void *)&cmd_vf_rate_limit_q_msk_val,
8913 		NULL,
8914 	},
8915 };
8916 
8917 /* *** ADD TUNNEL FILTER OF A PORT *** */
8918 struct cmd_tunnel_filter_result {
8919 	cmdline_fixed_string_t cmd;
8920 	cmdline_fixed_string_t what;
8921 	portid_t port_id;
8922 	struct rte_ether_addr outer_mac;
8923 	struct rte_ether_addr inner_mac;
8924 	cmdline_ipaddr_t ip_value;
8925 	uint16_t inner_vlan;
8926 	cmdline_fixed_string_t tunnel_type;
8927 	cmdline_fixed_string_t filter_type;
8928 	uint32_t tenant_id;
8929 	uint16_t queue_num;
8930 };
8931 
8932 static void
8933 cmd_tunnel_filter_parsed(void *parsed_result,
8934 			  __attribute__((unused)) struct cmdline *cl,
8935 			  __attribute__((unused)) void *data)
8936 {
8937 	struct cmd_tunnel_filter_result *res = parsed_result;
8938 	struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8939 	int ret = 0;
8940 
8941 	memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8942 
8943 	rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8944 	rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8945 	tunnel_filter_conf.inner_vlan = res->inner_vlan;
8946 
8947 	if (res->ip_value.family == AF_INET) {
8948 		tunnel_filter_conf.ip_addr.ipv4_addr =
8949 			res->ip_value.addr.ipv4.s_addr;
8950 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8951 	} else {
8952 		memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8953 			&(res->ip_value.addr.ipv6),
8954 			sizeof(struct in6_addr));
8955 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8956 	}
8957 
8958 	if (!strcmp(res->filter_type, "imac-ivlan"))
8959 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8960 	else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8961 		tunnel_filter_conf.filter_type =
8962 			RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8963 	else if (!strcmp(res->filter_type, "imac-tenid"))
8964 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8965 	else if (!strcmp(res->filter_type, "imac"))
8966 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8967 	else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8968 		tunnel_filter_conf.filter_type =
8969 			RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8970 	else if (!strcmp(res->filter_type, "oip"))
8971 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8972 	else if (!strcmp(res->filter_type, "iip"))
8973 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8974 	else {
8975 		printf("The filter type is not supported");
8976 		return;
8977 	}
8978 
8979 	if (!strcmp(res->tunnel_type, "vxlan"))
8980 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8981 	else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
8982 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8983 	else if (!strcmp(res->tunnel_type, "nvgre"))
8984 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8985 	else if (!strcmp(res->tunnel_type, "ipingre"))
8986 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8987 	else {
8988 		printf("The tunnel type %s not supported.\n", res->tunnel_type);
8989 		return;
8990 	}
8991 
8992 	tunnel_filter_conf.tenant_id = res->tenant_id;
8993 	tunnel_filter_conf.queue_id = res->queue_num;
8994 	if (!strcmp(res->what, "add"))
8995 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8996 					RTE_ETH_FILTER_TUNNEL,
8997 					RTE_ETH_FILTER_ADD,
8998 					&tunnel_filter_conf);
8999 	else
9000 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9001 					RTE_ETH_FILTER_TUNNEL,
9002 					RTE_ETH_FILTER_DELETE,
9003 					&tunnel_filter_conf);
9004 	if (ret < 0)
9005 		printf("cmd_tunnel_filter_parsed error: (%s)\n",
9006 				strerror(-ret));
9007 
9008 }
9009 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9010 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9011 	cmd, "tunnel_filter");
9012 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9013 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9014 	what, "add#rm");
9015 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9016 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9017 	port_id, UINT16);
9018 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9019 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9020 	outer_mac);
9021 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9022 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9023 	inner_mac);
9024 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9025 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9026 	inner_vlan, UINT16);
9027 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9028 	TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9029 	ip_value);
9030 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9031 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9032 	tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9033 
9034 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9035 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9036 	filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9037 		"imac#omac-imac-tenid");
9038 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9039 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9040 	tenant_id, UINT32);
9041 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9042 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9043 	queue_num, UINT16);
9044 
9045 cmdline_parse_inst_t cmd_tunnel_filter = {
9046 	.f = cmd_tunnel_filter_parsed,
9047 	.data = (void *)0,
9048 	.help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9049 		"<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9050 		"imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9051 		"<queue_id>: Add/Rm tunnel filter of a port",
9052 	.tokens = {
9053 		(void *)&cmd_tunnel_filter_cmd,
9054 		(void *)&cmd_tunnel_filter_what,
9055 		(void *)&cmd_tunnel_filter_port_id,
9056 		(void *)&cmd_tunnel_filter_outer_mac,
9057 		(void *)&cmd_tunnel_filter_inner_mac,
9058 		(void *)&cmd_tunnel_filter_ip_value,
9059 		(void *)&cmd_tunnel_filter_innner_vlan,
9060 		(void *)&cmd_tunnel_filter_tunnel_type,
9061 		(void *)&cmd_tunnel_filter_filter_type,
9062 		(void *)&cmd_tunnel_filter_tenant_id,
9063 		(void *)&cmd_tunnel_filter_queue_num,
9064 		NULL,
9065 	},
9066 };
9067 
9068 /* *** CONFIGURE TUNNEL UDP PORT *** */
9069 struct cmd_tunnel_udp_config {
9070 	cmdline_fixed_string_t cmd;
9071 	cmdline_fixed_string_t what;
9072 	uint16_t udp_port;
9073 	portid_t port_id;
9074 };
9075 
9076 static void
9077 cmd_tunnel_udp_config_parsed(void *parsed_result,
9078 			  __attribute__((unused)) struct cmdline *cl,
9079 			  __attribute__((unused)) void *data)
9080 {
9081 	struct cmd_tunnel_udp_config *res = parsed_result;
9082 	struct rte_eth_udp_tunnel tunnel_udp;
9083 	int ret;
9084 
9085 	tunnel_udp.udp_port = res->udp_port;
9086 
9087 	if (!strcmp(res->cmd, "rx_vxlan_port"))
9088 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9089 
9090 	if (!strcmp(res->what, "add"))
9091 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9092 						      &tunnel_udp);
9093 	else
9094 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9095 							 &tunnel_udp);
9096 
9097 	if (ret < 0)
9098 		printf("udp tunneling add error: (%s)\n", strerror(-ret));
9099 }
9100 
9101 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9102 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9103 				cmd, "rx_vxlan_port");
9104 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9105 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9106 				what, "add#rm");
9107 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9108 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9109 				udp_port, UINT16);
9110 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9111 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9112 				port_id, UINT16);
9113 
9114 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9115 	.f = cmd_tunnel_udp_config_parsed,
9116 	.data = (void *)0,
9117 	.help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9118 		"Add/Remove a tunneling UDP port filter",
9119 	.tokens = {
9120 		(void *)&cmd_tunnel_udp_config_cmd,
9121 		(void *)&cmd_tunnel_udp_config_what,
9122 		(void *)&cmd_tunnel_udp_config_udp_port,
9123 		(void *)&cmd_tunnel_udp_config_port_id,
9124 		NULL,
9125 	},
9126 };
9127 
9128 struct cmd_config_tunnel_udp_port {
9129 	cmdline_fixed_string_t port;
9130 	cmdline_fixed_string_t config;
9131 	portid_t port_id;
9132 	cmdline_fixed_string_t udp_tunnel_port;
9133 	cmdline_fixed_string_t action;
9134 	cmdline_fixed_string_t tunnel_type;
9135 	uint16_t udp_port;
9136 };
9137 
9138 static void
9139 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9140 			       __attribute__((unused)) struct cmdline *cl,
9141 			       __attribute__((unused)) void *data)
9142 {
9143 	struct cmd_config_tunnel_udp_port *res = parsed_result;
9144 	struct rte_eth_udp_tunnel tunnel_udp;
9145 	int ret = 0;
9146 
9147 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9148 		return;
9149 
9150 	tunnel_udp.udp_port = res->udp_port;
9151 
9152 	if (!strcmp(res->tunnel_type, "vxlan")) {
9153 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9154 	} else if (!strcmp(res->tunnel_type, "geneve")) {
9155 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9156 	} else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9157 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9158 	} else {
9159 		printf("Invalid tunnel type\n");
9160 		return;
9161 	}
9162 
9163 	if (!strcmp(res->action, "add"))
9164 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9165 						      &tunnel_udp);
9166 	else
9167 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9168 							 &tunnel_udp);
9169 
9170 	if (ret < 0)
9171 		printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9172 }
9173 
9174 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9175 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9176 				 "port");
9177 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9178 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9179 				 "config");
9180 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9181 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9182 			      UINT16);
9183 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9184 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9185 				 udp_tunnel_port,
9186 				 "udp_tunnel_port");
9187 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9188 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9189 				 "add#rm");
9190 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9191 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9192 				 "vxlan#geneve#vxlan-gpe");
9193 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9194 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9195 			      UINT16);
9196 
9197 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9198 	.f = cmd_cfg_tunnel_udp_port_parsed,
9199 	.data = NULL,
9200 	.help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9201 	.tokens = {
9202 		(void *)&cmd_config_tunnel_udp_port_port,
9203 		(void *)&cmd_config_tunnel_udp_port_config,
9204 		(void *)&cmd_config_tunnel_udp_port_port_id,
9205 		(void *)&cmd_config_tunnel_udp_port_tunnel_port,
9206 		(void *)&cmd_config_tunnel_udp_port_action,
9207 		(void *)&cmd_config_tunnel_udp_port_tunnel_type,
9208 		(void *)&cmd_config_tunnel_udp_port_value,
9209 		NULL,
9210 	},
9211 };
9212 
9213 /* *** GLOBAL CONFIG *** */
9214 struct cmd_global_config_result {
9215 	cmdline_fixed_string_t cmd;
9216 	portid_t port_id;
9217 	cmdline_fixed_string_t cfg_type;
9218 	uint8_t len;
9219 };
9220 
9221 static void
9222 cmd_global_config_parsed(void *parsed_result,
9223 			 __attribute__((unused)) struct cmdline *cl,
9224 			 __attribute__((unused)) void *data)
9225 {
9226 	struct cmd_global_config_result *res = parsed_result;
9227 	struct rte_eth_global_cfg conf;
9228 	int ret;
9229 
9230 	memset(&conf, 0, sizeof(conf));
9231 	conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9232 	conf.cfg.gre_key_len = res->len;
9233 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9234 				      RTE_ETH_FILTER_SET, &conf);
9235 	if (ret != 0)
9236 		printf("Global config error\n");
9237 }
9238 
9239 cmdline_parse_token_string_t cmd_global_config_cmd =
9240 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9241 		"global_config");
9242 cmdline_parse_token_num_t cmd_global_config_port_id =
9243 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9244 			       UINT16);
9245 cmdline_parse_token_string_t cmd_global_config_type =
9246 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9247 		cfg_type, "gre-key-len");
9248 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9249 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9250 		len, UINT8);
9251 
9252 cmdline_parse_inst_t cmd_global_config = {
9253 	.f = cmd_global_config_parsed,
9254 	.data = (void *)NULL,
9255 	.help_str = "global_config <port_id> gre-key-len <key_len>",
9256 	.tokens = {
9257 		(void *)&cmd_global_config_cmd,
9258 		(void *)&cmd_global_config_port_id,
9259 		(void *)&cmd_global_config_type,
9260 		(void *)&cmd_global_config_gre_key_len,
9261 		NULL,
9262 	},
9263 };
9264 
9265 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9266 struct cmd_set_mirror_mask_result {
9267 	cmdline_fixed_string_t set;
9268 	cmdline_fixed_string_t port;
9269 	portid_t port_id;
9270 	cmdline_fixed_string_t mirror;
9271 	uint8_t rule_id;
9272 	cmdline_fixed_string_t what;
9273 	cmdline_fixed_string_t value;
9274 	cmdline_fixed_string_t dstpool;
9275 	uint8_t dstpool_id;
9276 	cmdline_fixed_string_t on;
9277 };
9278 
9279 cmdline_parse_token_string_t cmd_mirror_mask_set =
9280 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9281 				set, "set");
9282 cmdline_parse_token_string_t cmd_mirror_mask_port =
9283 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9284 				port, "port");
9285 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9286 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9287 				port_id, UINT16);
9288 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9289 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9290 				mirror, "mirror-rule");
9291 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9292 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9293 				rule_id, UINT8);
9294 cmdline_parse_token_string_t cmd_mirror_mask_what =
9295 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9296 				what, "pool-mirror-up#pool-mirror-down"
9297 				      "#vlan-mirror");
9298 cmdline_parse_token_string_t cmd_mirror_mask_value =
9299 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9300 				value, NULL);
9301 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9302 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9303 				dstpool, "dst-pool");
9304 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9305 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9306 				dstpool_id, UINT8);
9307 cmdline_parse_token_string_t cmd_mirror_mask_on =
9308 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9309 				on, "on#off");
9310 
9311 static void
9312 cmd_set_mirror_mask_parsed(void *parsed_result,
9313 		       __attribute__((unused)) struct cmdline *cl,
9314 		       __attribute__((unused)) void *data)
9315 {
9316 	int ret,nb_item,i;
9317 	struct cmd_set_mirror_mask_result *res = parsed_result;
9318 	struct rte_eth_mirror_conf mr_conf;
9319 
9320 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9321 
9322 	unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9323 
9324 	mr_conf.dst_pool = res->dstpool_id;
9325 
9326 	if (!strcmp(res->what, "pool-mirror-up")) {
9327 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9328 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9329 	} else if (!strcmp(res->what, "pool-mirror-down")) {
9330 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9331 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9332 	} else if (!strcmp(res->what, "vlan-mirror")) {
9333 		mr_conf.rule_type = ETH_MIRROR_VLAN;
9334 		nb_item = parse_item_list(res->value, "vlan",
9335 				ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9336 		if (nb_item <= 0)
9337 			return;
9338 
9339 		for (i = 0; i < nb_item; i++) {
9340 			if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9341 				printf("Invalid vlan_id: must be < 4096\n");
9342 				return;
9343 			}
9344 
9345 			mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9346 			mr_conf.vlan.vlan_mask |= 1ULL << i;
9347 		}
9348 	}
9349 
9350 	if (!strcmp(res->on, "on"))
9351 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9352 						res->rule_id, 1);
9353 	else
9354 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9355 						res->rule_id, 0);
9356 	if (ret < 0)
9357 		printf("mirror rule add error: (%s)\n", strerror(-ret));
9358 }
9359 
9360 cmdline_parse_inst_t cmd_set_mirror_mask = {
9361 		.f = cmd_set_mirror_mask_parsed,
9362 		.data = NULL,
9363 		.help_str = "set port <port_id> mirror-rule <rule_id> "
9364 			"pool-mirror-up|pool-mirror-down|vlan-mirror "
9365 			"<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9366 		.tokens = {
9367 			(void *)&cmd_mirror_mask_set,
9368 			(void *)&cmd_mirror_mask_port,
9369 			(void *)&cmd_mirror_mask_portid,
9370 			(void *)&cmd_mirror_mask_mirror,
9371 			(void *)&cmd_mirror_mask_ruleid,
9372 			(void *)&cmd_mirror_mask_what,
9373 			(void *)&cmd_mirror_mask_value,
9374 			(void *)&cmd_mirror_mask_dstpool,
9375 			(void *)&cmd_mirror_mask_poolid,
9376 			(void *)&cmd_mirror_mask_on,
9377 			NULL,
9378 		},
9379 };
9380 
9381 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9382 struct cmd_set_mirror_link_result {
9383 	cmdline_fixed_string_t set;
9384 	cmdline_fixed_string_t port;
9385 	portid_t port_id;
9386 	cmdline_fixed_string_t mirror;
9387 	uint8_t rule_id;
9388 	cmdline_fixed_string_t what;
9389 	cmdline_fixed_string_t dstpool;
9390 	uint8_t dstpool_id;
9391 	cmdline_fixed_string_t on;
9392 };
9393 
9394 cmdline_parse_token_string_t cmd_mirror_link_set =
9395 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9396 				 set, "set");
9397 cmdline_parse_token_string_t cmd_mirror_link_port =
9398 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9399 				port, "port");
9400 cmdline_parse_token_num_t cmd_mirror_link_portid =
9401 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9402 				port_id, UINT16);
9403 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9404 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9405 				mirror, "mirror-rule");
9406 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9407 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9408 			    rule_id, UINT8);
9409 cmdline_parse_token_string_t cmd_mirror_link_what =
9410 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9411 				what, "uplink-mirror#downlink-mirror");
9412 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9413 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9414 				dstpool, "dst-pool");
9415 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9416 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9417 				dstpool_id, UINT8);
9418 cmdline_parse_token_string_t cmd_mirror_link_on =
9419 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9420 				on, "on#off");
9421 
9422 static void
9423 cmd_set_mirror_link_parsed(void *parsed_result,
9424 		       __attribute__((unused)) struct cmdline *cl,
9425 		       __attribute__((unused)) void *data)
9426 {
9427 	int ret;
9428 	struct cmd_set_mirror_link_result *res = parsed_result;
9429 	struct rte_eth_mirror_conf mr_conf;
9430 
9431 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9432 	if (!strcmp(res->what, "uplink-mirror"))
9433 		mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9434 	else
9435 		mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9436 
9437 	mr_conf.dst_pool = res->dstpool_id;
9438 
9439 	if (!strcmp(res->on, "on"))
9440 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9441 						res->rule_id, 1);
9442 	else
9443 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9444 						res->rule_id, 0);
9445 
9446 	/* check the return value and print it if is < 0 */
9447 	if (ret < 0)
9448 		printf("mirror rule add error: (%s)\n", strerror(-ret));
9449 
9450 }
9451 
9452 cmdline_parse_inst_t cmd_set_mirror_link = {
9453 		.f = cmd_set_mirror_link_parsed,
9454 		.data = NULL,
9455 		.help_str = "set port <port_id> mirror-rule <rule_id> "
9456 			"uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9457 		.tokens = {
9458 			(void *)&cmd_mirror_link_set,
9459 			(void *)&cmd_mirror_link_port,
9460 			(void *)&cmd_mirror_link_portid,
9461 			(void *)&cmd_mirror_link_mirror,
9462 			(void *)&cmd_mirror_link_ruleid,
9463 			(void *)&cmd_mirror_link_what,
9464 			(void *)&cmd_mirror_link_dstpool,
9465 			(void *)&cmd_mirror_link_poolid,
9466 			(void *)&cmd_mirror_link_on,
9467 			NULL,
9468 		},
9469 };
9470 
9471 /* *** RESET VM MIRROR RULE *** */
9472 struct cmd_rm_mirror_rule_result {
9473 	cmdline_fixed_string_t reset;
9474 	cmdline_fixed_string_t port;
9475 	portid_t port_id;
9476 	cmdline_fixed_string_t mirror;
9477 	uint8_t rule_id;
9478 };
9479 
9480 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9481 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9482 				 reset, "reset");
9483 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9484 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9485 				port, "port");
9486 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9487 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9488 				port_id, UINT16);
9489 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9490 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9491 				mirror, "mirror-rule");
9492 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9493 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9494 				rule_id, UINT8);
9495 
9496 static void
9497 cmd_reset_mirror_rule_parsed(void *parsed_result,
9498 		       __attribute__((unused)) struct cmdline *cl,
9499 		       __attribute__((unused)) void *data)
9500 {
9501 	int ret;
9502 	struct cmd_set_mirror_link_result *res = parsed_result;
9503         /* check rule_id */
9504 	ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9505 	if(ret < 0)
9506 		printf("mirror rule remove error: (%s)\n", strerror(-ret));
9507 }
9508 
9509 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9510 		.f = cmd_reset_mirror_rule_parsed,
9511 		.data = NULL,
9512 		.help_str = "reset port <port_id> mirror-rule <rule_id>",
9513 		.tokens = {
9514 			(void *)&cmd_rm_mirror_rule_reset,
9515 			(void *)&cmd_rm_mirror_rule_port,
9516 			(void *)&cmd_rm_mirror_rule_portid,
9517 			(void *)&cmd_rm_mirror_rule_mirror,
9518 			(void *)&cmd_rm_mirror_rule_ruleid,
9519 			NULL,
9520 		},
9521 };
9522 
9523 /* ******************************************************************************** */
9524 
9525 struct cmd_dump_result {
9526 	cmdline_fixed_string_t dump;
9527 };
9528 
9529 static void
9530 dump_struct_sizes(void)
9531 {
9532 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9533 	DUMP_SIZE(struct rte_mbuf);
9534 	DUMP_SIZE(struct rte_mempool);
9535 	DUMP_SIZE(struct rte_ring);
9536 #undef DUMP_SIZE
9537 }
9538 
9539 static void cmd_dump_parsed(void *parsed_result,
9540 			    __attribute__((unused)) struct cmdline *cl,
9541 			    __attribute__((unused)) void *data)
9542 {
9543 	struct cmd_dump_result *res = parsed_result;
9544 
9545 	if (!strcmp(res->dump, "dump_physmem"))
9546 		rte_dump_physmem_layout(stdout);
9547 	else if (!strcmp(res->dump, "dump_memzone"))
9548 		rte_memzone_dump(stdout);
9549 	else if (!strcmp(res->dump, "dump_struct_sizes"))
9550 		dump_struct_sizes();
9551 	else if (!strcmp(res->dump, "dump_ring"))
9552 		rte_ring_list_dump(stdout);
9553 	else if (!strcmp(res->dump, "dump_mempool"))
9554 		rte_mempool_list_dump(stdout);
9555 	else if (!strcmp(res->dump, "dump_devargs"))
9556 		rte_devargs_dump(stdout);
9557 	else if (!strcmp(res->dump, "dump_log_types"))
9558 		rte_log_dump(stdout);
9559 }
9560 
9561 cmdline_parse_token_string_t cmd_dump_dump =
9562 	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9563 		"dump_physmem#"
9564 		"dump_memzone#"
9565 		"dump_struct_sizes#"
9566 		"dump_ring#"
9567 		"dump_mempool#"
9568 		"dump_devargs#"
9569 		"dump_log_types");
9570 
9571 cmdline_parse_inst_t cmd_dump = {
9572 	.f = cmd_dump_parsed,  /* function to call */
9573 	.data = NULL,      /* 2nd arg of func */
9574 	.help_str = "Dump status",
9575 	.tokens = {        /* token list, NULL terminated */
9576 		(void *)&cmd_dump_dump,
9577 		NULL,
9578 	},
9579 };
9580 
9581 /* ******************************************************************************** */
9582 
9583 struct cmd_dump_one_result {
9584 	cmdline_fixed_string_t dump;
9585 	cmdline_fixed_string_t name;
9586 };
9587 
9588 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9589 				__attribute__((unused)) void *data)
9590 {
9591 	struct cmd_dump_one_result *res = parsed_result;
9592 
9593 	if (!strcmp(res->dump, "dump_ring")) {
9594 		struct rte_ring *r;
9595 		r = rte_ring_lookup(res->name);
9596 		if (r == NULL) {
9597 			cmdline_printf(cl, "Cannot find ring\n");
9598 			return;
9599 		}
9600 		rte_ring_dump(stdout, r);
9601 	} else if (!strcmp(res->dump, "dump_mempool")) {
9602 		struct rte_mempool *mp;
9603 		mp = rte_mempool_lookup(res->name);
9604 		if (mp == NULL) {
9605 			cmdline_printf(cl, "Cannot find mempool\n");
9606 			return;
9607 		}
9608 		rte_mempool_dump(stdout, mp);
9609 	}
9610 }
9611 
9612 cmdline_parse_token_string_t cmd_dump_one_dump =
9613 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9614 				 "dump_ring#dump_mempool");
9615 
9616 cmdline_parse_token_string_t cmd_dump_one_name =
9617 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9618 
9619 cmdline_parse_inst_t cmd_dump_one = {
9620 	.f = cmd_dump_one_parsed,  /* function to call */
9621 	.data = NULL,      /* 2nd arg of func */
9622 	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9623 	.tokens = {        /* token list, NULL terminated */
9624 		(void *)&cmd_dump_one_dump,
9625 		(void *)&cmd_dump_one_name,
9626 		NULL,
9627 	},
9628 };
9629 
9630 /* *** Add/Del syn filter *** */
9631 struct cmd_syn_filter_result {
9632 	cmdline_fixed_string_t filter;
9633 	portid_t port_id;
9634 	cmdline_fixed_string_t ops;
9635 	cmdline_fixed_string_t priority;
9636 	cmdline_fixed_string_t high;
9637 	cmdline_fixed_string_t queue;
9638 	uint16_t queue_id;
9639 };
9640 
9641 static void
9642 cmd_syn_filter_parsed(void *parsed_result,
9643 			__attribute__((unused)) struct cmdline *cl,
9644 			__attribute__((unused)) void *data)
9645 {
9646 	struct cmd_syn_filter_result *res = parsed_result;
9647 	struct rte_eth_syn_filter syn_filter;
9648 	int ret = 0;
9649 
9650 	ret = rte_eth_dev_filter_supported(res->port_id,
9651 					RTE_ETH_FILTER_SYN);
9652 	if (ret < 0) {
9653 		printf("syn filter is not supported on port %u.\n",
9654 				res->port_id);
9655 		return;
9656 	}
9657 
9658 	memset(&syn_filter, 0, sizeof(syn_filter));
9659 
9660 	if (!strcmp(res->ops, "add")) {
9661 		if (!strcmp(res->high, "high"))
9662 			syn_filter.hig_pri = 1;
9663 		else
9664 			syn_filter.hig_pri = 0;
9665 
9666 		syn_filter.queue = res->queue_id;
9667 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9668 						RTE_ETH_FILTER_SYN,
9669 						RTE_ETH_FILTER_ADD,
9670 						&syn_filter);
9671 	} else
9672 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9673 						RTE_ETH_FILTER_SYN,
9674 						RTE_ETH_FILTER_DELETE,
9675 						&syn_filter);
9676 
9677 	if (ret < 0)
9678 		printf("syn filter programming error: (%s)\n",
9679 				strerror(-ret));
9680 }
9681 
9682 cmdline_parse_token_string_t cmd_syn_filter_filter =
9683 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9684 	filter, "syn_filter");
9685 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9686 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9687 	port_id, UINT16);
9688 cmdline_parse_token_string_t cmd_syn_filter_ops =
9689 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9690 	ops, "add#del");
9691 cmdline_parse_token_string_t cmd_syn_filter_priority =
9692 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9693 				priority, "priority");
9694 cmdline_parse_token_string_t cmd_syn_filter_high =
9695 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9696 				high, "high#low");
9697 cmdline_parse_token_string_t cmd_syn_filter_queue =
9698 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9699 				queue, "queue");
9700 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9701 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9702 				queue_id, UINT16);
9703 
9704 cmdline_parse_inst_t cmd_syn_filter = {
9705 	.f = cmd_syn_filter_parsed,
9706 	.data = NULL,
9707 	.help_str = "syn_filter <port_id> add|del priority high|low queue "
9708 		"<queue_id>: Add/Delete syn filter",
9709 	.tokens = {
9710 		(void *)&cmd_syn_filter_filter,
9711 		(void *)&cmd_syn_filter_port_id,
9712 		(void *)&cmd_syn_filter_ops,
9713 		(void *)&cmd_syn_filter_priority,
9714 		(void *)&cmd_syn_filter_high,
9715 		(void *)&cmd_syn_filter_queue,
9716 		(void *)&cmd_syn_filter_queue_id,
9717 		NULL,
9718 	},
9719 };
9720 
9721 /* *** queue region set *** */
9722 struct cmd_queue_region_result {
9723 	cmdline_fixed_string_t set;
9724 	cmdline_fixed_string_t port;
9725 	portid_t port_id;
9726 	cmdline_fixed_string_t cmd;
9727 	cmdline_fixed_string_t region;
9728 	uint8_t  region_id;
9729 	cmdline_fixed_string_t queue_start_index;
9730 	uint8_t  queue_id;
9731 	cmdline_fixed_string_t queue_num;
9732 	uint8_t  queue_num_value;
9733 };
9734 
9735 static void
9736 cmd_queue_region_parsed(void *parsed_result,
9737 			__attribute__((unused)) struct cmdline *cl,
9738 			__attribute__((unused)) void *data)
9739 {
9740 	struct cmd_queue_region_result *res = parsed_result;
9741 	int ret = -ENOTSUP;
9742 #ifdef RTE_LIBRTE_I40E_PMD
9743 	struct rte_pmd_i40e_queue_region_conf region_conf;
9744 	enum rte_pmd_i40e_queue_region_op op_type;
9745 #endif
9746 
9747 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9748 		return;
9749 
9750 #ifdef RTE_LIBRTE_I40E_PMD
9751 	memset(&region_conf, 0, sizeof(region_conf));
9752 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9753 	region_conf.region_id = res->region_id;
9754 	region_conf.queue_num = res->queue_num_value;
9755 	region_conf.queue_start_index = res->queue_id;
9756 
9757 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9758 				op_type, &region_conf);
9759 #endif
9760 
9761 	switch (ret) {
9762 	case 0:
9763 		break;
9764 	case -ENOTSUP:
9765 		printf("function not implemented or supported\n");
9766 		break;
9767 	default:
9768 		printf("queue region config error: (%s)\n", strerror(-ret));
9769 	}
9770 }
9771 
9772 cmdline_parse_token_string_t cmd_queue_region_set =
9773 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9774 		set, "set");
9775 cmdline_parse_token_string_t cmd_queue_region_port =
9776 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9777 cmdline_parse_token_num_t cmd_queue_region_port_id =
9778 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9779 				port_id, UINT16);
9780 cmdline_parse_token_string_t cmd_queue_region_cmd =
9781 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9782 				 cmd, "queue-region");
9783 cmdline_parse_token_string_t cmd_queue_region_id =
9784 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9785 				region, "region_id");
9786 cmdline_parse_token_num_t cmd_queue_region_index =
9787 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9788 				region_id, UINT8);
9789 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9790 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9791 				queue_start_index, "queue_start_index");
9792 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9793 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9794 				queue_id, UINT8);
9795 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9796 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9797 				queue_num, "queue_num");
9798 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9799 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9800 				queue_num_value, UINT8);
9801 
9802 cmdline_parse_inst_t cmd_queue_region = {
9803 	.f = cmd_queue_region_parsed,
9804 	.data = NULL,
9805 	.help_str = "set port <port_id> queue-region region_id <value> "
9806 		"queue_start_index <value> queue_num <value>: Set a queue region",
9807 	.tokens = {
9808 		(void *)&cmd_queue_region_set,
9809 		(void *)&cmd_queue_region_port,
9810 		(void *)&cmd_queue_region_port_id,
9811 		(void *)&cmd_queue_region_cmd,
9812 		(void *)&cmd_queue_region_id,
9813 		(void *)&cmd_queue_region_index,
9814 		(void *)&cmd_queue_region_queue_start_index,
9815 		(void *)&cmd_queue_region_queue_id,
9816 		(void *)&cmd_queue_region_queue_num,
9817 		(void *)&cmd_queue_region_queue_num_value,
9818 		NULL,
9819 	},
9820 };
9821 
9822 /* *** queue region and flowtype set *** */
9823 struct cmd_region_flowtype_result {
9824 	cmdline_fixed_string_t set;
9825 	cmdline_fixed_string_t port;
9826 	portid_t port_id;
9827 	cmdline_fixed_string_t cmd;
9828 	cmdline_fixed_string_t region;
9829 	uint8_t  region_id;
9830 	cmdline_fixed_string_t flowtype;
9831 	uint8_t  flowtype_id;
9832 };
9833 
9834 static void
9835 cmd_region_flowtype_parsed(void *parsed_result,
9836 			__attribute__((unused)) struct cmdline *cl,
9837 			__attribute__((unused)) void *data)
9838 {
9839 	struct cmd_region_flowtype_result *res = parsed_result;
9840 	int ret = -ENOTSUP;
9841 #ifdef RTE_LIBRTE_I40E_PMD
9842 	struct rte_pmd_i40e_queue_region_conf region_conf;
9843 	enum rte_pmd_i40e_queue_region_op op_type;
9844 #endif
9845 
9846 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9847 		return;
9848 
9849 #ifdef RTE_LIBRTE_I40E_PMD
9850 	memset(&region_conf, 0, sizeof(region_conf));
9851 
9852 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9853 	region_conf.region_id = res->region_id;
9854 	region_conf.hw_flowtype = res->flowtype_id;
9855 
9856 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9857 			op_type, &region_conf);
9858 #endif
9859 
9860 	switch (ret) {
9861 	case 0:
9862 		break;
9863 	case -ENOTSUP:
9864 		printf("function not implemented or supported\n");
9865 		break;
9866 	default:
9867 		printf("region flowtype config error: (%s)\n", strerror(-ret));
9868 	}
9869 }
9870 
9871 cmdline_parse_token_string_t cmd_region_flowtype_set =
9872 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9873 				set, "set");
9874 cmdline_parse_token_string_t cmd_region_flowtype_port =
9875 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9876 				port, "port");
9877 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9878 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9879 				port_id, UINT16);
9880 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9881 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9882 				cmd, "queue-region");
9883 cmdline_parse_token_string_t cmd_region_flowtype_index =
9884 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9885 				region, "region_id");
9886 cmdline_parse_token_num_t cmd_region_flowtype_id =
9887 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9888 				region_id, UINT8);
9889 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9890 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9891 				flowtype, "flowtype");
9892 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9893 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9894 				flowtype_id, UINT8);
9895 cmdline_parse_inst_t cmd_region_flowtype = {
9896 	.f = cmd_region_flowtype_parsed,
9897 	.data = NULL,
9898 	.help_str = "set port <port_id> queue-region region_id <value> "
9899 		"flowtype <value>: Set a flowtype region index",
9900 	.tokens = {
9901 		(void *)&cmd_region_flowtype_set,
9902 		(void *)&cmd_region_flowtype_port,
9903 		(void *)&cmd_region_flowtype_port_index,
9904 		(void *)&cmd_region_flowtype_cmd,
9905 		(void *)&cmd_region_flowtype_index,
9906 		(void *)&cmd_region_flowtype_id,
9907 		(void *)&cmd_region_flowtype_flow_index,
9908 		(void *)&cmd_region_flowtype_flow_id,
9909 		NULL,
9910 	},
9911 };
9912 
9913 /* *** User Priority (UP) to queue region (region_id) set *** */
9914 struct cmd_user_priority_region_result {
9915 	cmdline_fixed_string_t set;
9916 	cmdline_fixed_string_t port;
9917 	portid_t port_id;
9918 	cmdline_fixed_string_t cmd;
9919 	cmdline_fixed_string_t user_priority;
9920 	uint8_t  user_priority_id;
9921 	cmdline_fixed_string_t region;
9922 	uint8_t  region_id;
9923 };
9924 
9925 static void
9926 cmd_user_priority_region_parsed(void *parsed_result,
9927 			__attribute__((unused)) struct cmdline *cl,
9928 			__attribute__((unused)) void *data)
9929 {
9930 	struct cmd_user_priority_region_result *res = parsed_result;
9931 	int ret = -ENOTSUP;
9932 #ifdef RTE_LIBRTE_I40E_PMD
9933 	struct rte_pmd_i40e_queue_region_conf region_conf;
9934 	enum rte_pmd_i40e_queue_region_op op_type;
9935 #endif
9936 
9937 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9938 		return;
9939 
9940 #ifdef RTE_LIBRTE_I40E_PMD
9941 	memset(&region_conf, 0, sizeof(region_conf));
9942 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9943 	region_conf.user_priority = res->user_priority_id;
9944 	region_conf.region_id = res->region_id;
9945 
9946 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9947 				op_type, &region_conf);
9948 #endif
9949 
9950 	switch (ret) {
9951 	case 0:
9952 		break;
9953 	case -ENOTSUP:
9954 		printf("function not implemented or supported\n");
9955 		break;
9956 	default:
9957 		printf("user_priority region config error: (%s)\n",
9958 				strerror(-ret));
9959 	}
9960 }
9961 
9962 cmdline_parse_token_string_t cmd_user_priority_region_set =
9963 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9964 				set, "set");
9965 cmdline_parse_token_string_t cmd_user_priority_region_port =
9966 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9967 				port, "port");
9968 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9969 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9970 				port_id, UINT16);
9971 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9972 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9973 				cmd, "queue-region");
9974 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9975 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9976 				user_priority, "UP");
9977 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9978 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9979 				user_priority_id, UINT8);
9980 cmdline_parse_token_string_t cmd_user_priority_region_region =
9981 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9982 				region, "region_id");
9983 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9984 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9985 				region_id, UINT8);
9986 
9987 cmdline_parse_inst_t cmd_user_priority_region = {
9988 	.f = cmd_user_priority_region_parsed,
9989 	.data = NULL,
9990 	.help_str = "set port <port_id> queue-region UP <value> "
9991 		"region_id <value>: Set the mapping of User Priority (UP) "
9992 		"to queue region (region_id) ",
9993 	.tokens = {
9994 		(void *)&cmd_user_priority_region_set,
9995 		(void *)&cmd_user_priority_region_port,
9996 		(void *)&cmd_user_priority_region_port_index,
9997 		(void *)&cmd_user_priority_region_cmd,
9998 		(void *)&cmd_user_priority_region_UP,
9999 		(void *)&cmd_user_priority_region_UP_id,
10000 		(void *)&cmd_user_priority_region_region,
10001 		(void *)&cmd_user_priority_region_region_id,
10002 		NULL,
10003 	},
10004 };
10005 
10006 /* *** flush all queue region related configuration *** */
10007 struct cmd_flush_queue_region_result {
10008 	cmdline_fixed_string_t set;
10009 	cmdline_fixed_string_t port;
10010 	portid_t port_id;
10011 	cmdline_fixed_string_t cmd;
10012 	cmdline_fixed_string_t flush;
10013 	cmdline_fixed_string_t what;
10014 };
10015 
10016 static void
10017 cmd_flush_queue_region_parsed(void *parsed_result,
10018 			__attribute__((unused)) struct cmdline *cl,
10019 			__attribute__((unused)) void *data)
10020 {
10021 	struct cmd_flush_queue_region_result *res = parsed_result;
10022 	int ret = -ENOTSUP;
10023 #ifdef RTE_LIBRTE_I40E_PMD
10024 	struct rte_pmd_i40e_queue_region_conf region_conf;
10025 	enum rte_pmd_i40e_queue_region_op op_type;
10026 #endif
10027 
10028 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10029 		return;
10030 
10031 #ifdef RTE_LIBRTE_I40E_PMD
10032 	memset(&region_conf, 0, sizeof(region_conf));
10033 
10034 	if (strcmp(res->what, "on") == 0)
10035 		op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10036 	else
10037 		op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10038 
10039 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10040 				op_type, &region_conf);
10041 #endif
10042 
10043 	switch (ret) {
10044 	case 0:
10045 		break;
10046 	case -ENOTSUP:
10047 		printf("function not implemented or supported\n");
10048 		break;
10049 	default:
10050 		printf("queue region config flush error: (%s)\n",
10051 				strerror(-ret));
10052 	}
10053 }
10054 
10055 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10056 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10057 				set, "set");
10058 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10059 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10060 				port, "port");
10061 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10062 	TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10063 				port_id, UINT16);
10064 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10065 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10066 				cmd, "queue-region");
10067 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10068 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10069 				flush, "flush");
10070 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10071 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10072 				what, "on#off");
10073 
10074 cmdline_parse_inst_t cmd_flush_queue_region = {
10075 	.f = cmd_flush_queue_region_parsed,
10076 	.data = NULL,
10077 	.help_str = "set port <port_id> queue-region flush on|off"
10078 		": flush all queue region related configuration",
10079 	.tokens = {
10080 		(void *)&cmd_flush_queue_region_set,
10081 		(void *)&cmd_flush_queue_region_port,
10082 		(void *)&cmd_flush_queue_region_port_index,
10083 		(void *)&cmd_flush_queue_region_cmd,
10084 		(void *)&cmd_flush_queue_region_flush,
10085 		(void *)&cmd_flush_queue_region_what,
10086 		NULL,
10087 	},
10088 };
10089 
10090 /* *** get all queue region related configuration info *** */
10091 struct cmd_show_queue_region_info {
10092 	cmdline_fixed_string_t show;
10093 	cmdline_fixed_string_t port;
10094 	portid_t port_id;
10095 	cmdline_fixed_string_t cmd;
10096 };
10097 
10098 static void
10099 cmd_show_queue_region_info_parsed(void *parsed_result,
10100 			__attribute__((unused)) struct cmdline *cl,
10101 			__attribute__((unused)) void *data)
10102 {
10103 	struct cmd_show_queue_region_info *res = parsed_result;
10104 	int ret = -ENOTSUP;
10105 #ifdef RTE_LIBRTE_I40E_PMD
10106 	struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10107 	enum rte_pmd_i40e_queue_region_op op_type;
10108 #endif
10109 
10110 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10111 		return;
10112 
10113 #ifdef RTE_LIBRTE_I40E_PMD
10114 	memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10115 
10116 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10117 
10118 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10119 					op_type, &rte_pmd_regions);
10120 
10121 	port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10122 #endif
10123 
10124 	switch (ret) {
10125 	case 0:
10126 		break;
10127 	case -ENOTSUP:
10128 		printf("function not implemented or supported\n");
10129 		break;
10130 	default:
10131 		printf("queue region config info show error: (%s)\n",
10132 				strerror(-ret));
10133 	}
10134 }
10135 
10136 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10137 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10138 				show, "show");
10139 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10140 	TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10141 				port, "port");
10142 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10143 	TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10144 				port_id, UINT16);
10145 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10146 	TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10147 				cmd, "queue-region");
10148 
10149 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10150 	.f = cmd_show_queue_region_info_parsed,
10151 	.data = NULL,
10152 	.help_str = "show port <port_id> queue-region"
10153 		": show all queue region related configuration info",
10154 	.tokens = {
10155 		(void *)&cmd_show_queue_region_info_get,
10156 		(void *)&cmd_show_queue_region_info_port,
10157 		(void *)&cmd_show_queue_region_info_port_index,
10158 		(void *)&cmd_show_queue_region_info_cmd,
10159 		NULL,
10160 	},
10161 };
10162 
10163 /* *** ADD/REMOVE A 2tuple FILTER *** */
10164 struct cmd_2tuple_filter_result {
10165 	cmdline_fixed_string_t filter;
10166 	portid_t port_id;
10167 	cmdline_fixed_string_t ops;
10168 	cmdline_fixed_string_t dst_port;
10169 	uint16_t dst_port_value;
10170 	cmdline_fixed_string_t protocol;
10171 	uint8_t protocol_value;
10172 	cmdline_fixed_string_t mask;
10173 	uint8_t  mask_value;
10174 	cmdline_fixed_string_t tcp_flags;
10175 	uint8_t tcp_flags_value;
10176 	cmdline_fixed_string_t priority;
10177 	uint8_t  priority_value;
10178 	cmdline_fixed_string_t queue;
10179 	uint16_t  queue_id;
10180 };
10181 
10182 static void
10183 cmd_2tuple_filter_parsed(void *parsed_result,
10184 			__attribute__((unused)) struct cmdline *cl,
10185 			__attribute__((unused)) void *data)
10186 {
10187 	struct rte_eth_ntuple_filter filter;
10188 	struct cmd_2tuple_filter_result *res = parsed_result;
10189 	int ret = 0;
10190 
10191 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10192 	if (ret < 0) {
10193 		printf("ntuple filter is not supported on port %u.\n",
10194 			res->port_id);
10195 		return;
10196 	}
10197 
10198 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10199 
10200 	filter.flags = RTE_2TUPLE_FLAGS;
10201 	filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10202 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10203 	filter.proto = res->protocol_value;
10204 	filter.priority = res->priority_value;
10205 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10206 		printf("nonzero tcp_flags is only meaningful"
10207 			" when protocol is TCP.\n");
10208 		return;
10209 	}
10210 	if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10211 		printf("invalid TCP flags.\n");
10212 		return;
10213 	}
10214 
10215 	if (res->tcp_flags_value != 0) {
10216 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10217 		filter.tcp_flags = res->tcp_flags_value;
10218 	}
10219 
10220 	/* need convert to big endian. */
10221 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10222 	filter.queue = res->queue_id;
10223 
10224 	if (!strcmp(res->ops, "add"))
10225 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10226 				RTE_ETH_FILTER_NTUPLE,
10227 				RTE_ETH_FILTER_ADD,
10228 				&filter);
10229 	else
10230 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10231 				RTE_ETH_FILTER_NTUPLE,
10232 				RTE_ETH_FILTER_DELETE,
10233 				&filter);
10234 	if (ret < 0)
10235 		printf("2tuple filter programming error: (%s)\n",
10236 			strerror(-ret));
10237 
10238 }
10239 
10240 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10241 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10242 				 filter, "2tuple_filter");
10243 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10244 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10245 				port_id, UINT16);
10246 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10247 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10248 				 ops, "add#del");
10249 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10250 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10251 				dst_port, "dst_port");
10252 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10253 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10254 				dst_port_value, UINT16);
10255 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10256 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10257 				protocol, "protocol");
10258 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10259 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10260 				protocol_value, UINT8);
10261 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10262 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10263 				mask, "mask");
10264 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10265 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10266 				mask_value, INT8);
10267 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10268 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10269 				tcp_flags, "tcp_flags");
10270 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10271 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10272 				tcp_flags_value, UINT8);
10273 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10274 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10275 				priority, "priority");
10276 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10277 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10278 				priority_value, UINT8);
10279 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10280 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10281 				queue, "queue");
10282 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10283 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10284 				queue_id, UINT16);
10285 
10286 cmdline_parse_inst_t cmd_2tuple_filter = {
10287 	.f = cmd_2tuple_filter_parsed,
10288 	.data = NULL,
10289 	.help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10290 		"<value> mask <value> tcp_flags <value> priority <value> queue "
10291 		"<queue_id>: Add a 2tuple filter",
10292 	.tokens = {
10293 		(void *)&cmd_2tuple_filter_filter,
10294 		(void *)&cmd_2tuple_filter_port_id,
10295 		(void *)&cmd_2tuple_filter_ops,
10296 		(void *)&cmd_2tuple_filter_dst_port,
10297 		(void *)&cmd_2tuple_filter_dst_port_value,
10298 		(void *)&cmd_2tuple_filter_protocol,
10299 		(void *)&cmd_2tuple_filter_protocol_value,
10300 		(void *)&cmd_2tuple_filter_mask,
10301 		(void *)&cmd_2tuple_filter_mask_value,
10302 		(void *)&cmd_2tuple_filter_tcp_flags,
10303 		(void *)&cmd_2tuple_filter_tcp_flags_value,
10304 		(void *)&cmd_2tuple_filter_priority,
10305 		(void *)&cmd_2tuple_filter_priority_value,
10306 		(void *)&cmd_2tuple_filter_queue,
10307 		(void *)&cmd_2tuple_filter_queue_id,
10308 		NULL,
10309 	},
10310 };
10311 
10312 /* *** ADD/REMOVE A 5tuple FILTER *** */
10313 struct cmd_5tuple_filter_result {
10314 	cmdline_fixed_string_t filter;
10315 	portid_t port_id;
10316 	cmdline_fixed_string_t ops;
10317 	cmdline_fixed_string_t dst_ip;
10318 	cmdline_ipaddr_t dst_ip_value;
10319 	cmdline_fixed_string_t src_ip;
10320 	cmdline_ipaddr_t src_ip_value;
10321 	cmdline_fixed_string_t dst_port;
10322 	uint16_t dst_port_value;
10323 	cmdline_fixed_string_t src_port;
10324 	uint16_t src_port_value;
10325 	cmdline_fixed_string_t protocol;
10326 	uint8_t protocol_value;
10327 	cmdline_fixed_string_t mask;
10328 	uint8_t  mask_value;
10329 	cmdline_fixed_string_t tcp_flags;
10330 	uint8_t tcp_flags_value;
10331 	cmdline_fixed_string_t priority;
10332 	uint8_t  priority_value;
10333 	cmdline_fixed_string_t queue;
10334 	uint16_t  queue_id;
10335 };
10336 
10337 static void
10338 cmd_5tuple_filter_parsed(void *parsed_result,
10339 			__attribute__((unused)) struct cmdline *cl,
10340 			__attribute__((unused)) void *data)
10341 {
10342 	struct rte_eth_ntuple_filter filter;
10343 	struct cmd_5tuple_filter_result *res = parsed_result;
10344 	int ret = 0;
10345 
10346 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10347 	if (ret < 0) {
10348 		printf("ntuple filter is not supported on port %u.\n",
10349 			res->port_id);
10350 		return;
10351 	}
10352 
10353 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10354 
10355 	filter.flags = RTE_5TUPLE_FLAGS;
10356 	filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10357 	filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10358 	filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10359 	filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10360 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10361 	filter.proto = res->protocol_value;
10362 	filter.priority = res->priority_value;
10363 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10364 		printf("nonzero tcp_flags is only meaningful"
10365 			" when protocol is TCP.\n");
10366 		return;
10367 	}
10368 	if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10369 		printf("invalid TCP flags.\n");
10370 		return;
10371 	}
10372 
10373 	if (res->tcp_flags_value != 0) {
10374 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10375 		filter.tcp_flags = res->tcp_flags_value;
10376 	}
10377 
10378 	if (res->dst_ip_value.family == AF_INET)
10379 		/* no need to convert, already big endian. */
10380 		filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10381 	else {
10382 		if (filter.dst_ip_mask == 0) {
10383 			printf("can not support ipv6 involved compare.\n");
10384 			return;
10385 		}
10386 		filter.dst_ip = 0;
10387 	}
10388 
10389 	if (res->src_ip_value.family == AF_INET)
10390 		/* no need to convert, already big endian. */
10391 		filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10392 	else {
10393 		if (filter.src_ip_mask == 0) {
10394 			printf("can not support ipv6 involved compare.\n");
10395 			return;
10396 		}
10397 		filter.src_ip = 0;
10398 	}
10399 	/* need convert to big endian. */
10400 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10401 	filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10402 	filter.queue = res->queue_id;
10403 
10404 	if (!strcmp(res->ops, "add"))
10405 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10406 				RTE_ETH_FILTER_NTUPLE,
10407 				RTE_ETH_FILTER_ADD,
10408 				&filter);
10409 	else
10410 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10411 				RTE_ETH_FILTER_NTUPLE,
10412 				RTE_ETH_FILTER_DELETE,
10413 				&filter);
10414 	if (ret < 0)
10415 		printf("5tuple filter programming error: (%s)\n",
10416 			strerror(-ret));
10417 }
10418 
10419 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10420 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10421 				 filter, "5tuple_filter");
10422 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10423 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10424 				port_id, UINT16);
10425 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10426 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10427 				 ops, "add#del");
10428 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10429 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10430 				dst_ip, "dst_ip");
10431 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10432 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10433 				dst_ip_value);
10434 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10435 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10436 				src_ip, "src_ip");
10437 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10438 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10439 				src_ip_value);
10440 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10441 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10442 				dst_port, "dst_port");
10443 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10444 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10445 				dst_port_value, UINT16);
10446 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10447 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10448 				src_port, "src_port");
10449 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10450 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10451 				src_port_value, UINT16);
10452 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10453 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10454 				protocol, "protocol");
10455 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10456 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10457 				protocol_value, UINT8);
10458 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10459 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10460 				mask, "mask");
10461 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10462 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10463 				mask_value, INT8);
10464 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10465 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10466 				tcp_flags, "tcp_flags");
10467 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10468 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10469 				tcp_flags_value, UINT8);
10470 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10471 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10472 				priority, "priority");
10473 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10474 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10475 				priority_value, UINT8);
10476 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10477 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10478 				queue, "queue");
10479 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10480 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10481 				queue_id, UINT16);
10482 
10483 cmdline_parse_inst_t cmd_5tuple_filter = {
10484 	.f = cmd_5tuple_filter_parsed,
10485 	.data = NULL,
10486 	.help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10487 		"src_ip <value> dst_port <value> src_port <value> "
10488 		"protocol <value>  mask <value> tcp_flags <value> "
10489 		"priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10490 	.tokens = {
10491 		(void *)&cmd_5tuple_filter_filter,
10492 		(void *)&cmd_5tuple_filter_port_id,
10493 		(void *)&cmd_5tuple_filter_ops,
10494 		(void *)&cmd_5tuple_filter_dst_ip,
10495 		(void *)&cmd_5tuple_filter_dst_ip_value,
10496 		(void *)&cmd_5tuple_filter_src_ip,
10497 		(void *)&cmd_5tuple_filter_src_ip_value,
10498 		(void *)&cmd_5tuple_filter_dst_port,
10499 		(void *)&cmd_5tuple_filter_dst_port_value,
10500 		(void *)&cmd_5tuple_filter_src_port,
10501 		(void *)&cmd_5tuple_filter_src_port_value,
10502 		(void *)&cmd_5tuple_filter_protocol,
10503 		(void *)&cmd_5tuple_filter_protocol_value,
10504 		(void *)&cmd_5tuple_filter_mask,
10505 		(void *)&cmd_5tuple_filter_mask_value,
10506 		(void *)&cmd_5tuple_filter_tcp_flags,
10507 		(void *)&cmd_5tuple_filter_tcp_flags_value,
10508 		(void *)&cmd_5tuple_filter_priority,
10509 		(void *)&cmd_5tuple_filter_priority_value,
10510 		(void *)&cmd_5tuple_filter_queue,
10511 		(void *)&cmd_5tuple_filter_queue_id,
10512 		NULL,
10513 	},
10514 };
10515 
10516 /* *** ADD/REMOVE A flex FILTER *** */
10517 struct cmd_flex_filter_result {
10518 	cmdline_fixed_string_t filter;
10519 	cmdline_fixed_string_t ops;
10520 	portid_t port_id;
10521 	cmdline_fixed_string_t len;
10522 	uint8_t len_value;
10523 	cmdline_fixed_string_t bytes;
10524 	cmdline_fixed_string_t bytes_value;
10525 	cmdline_fixed_string_t mask;
10526 	cmdline_fixed_string_t mask_value;
10527 	cmdline_fixed_string_t priority;
10528 	uint8_t priority_value;
10529 	cmdline_fixed_string_t queue;
10530 	uint16_t queue_id;
10531 };
10532 
10533 static int xdigit2val(unsigned char c)
10534 {
10535 	int val;
10536 	if (isdigit(c))
10537 		val = c - '0';
10538 	else if (isupper(c))
10539 		val = c - 'A' + 10;
10540 	else
10541 		val = c - 'a' + 10;
10542 	return val;
10543 }
10544 
10545 static void
10546 cmd_flex_filter_parsed(void *parsed_result,
10547 			  __attribute__((unused)) struct cmdline *cl,
10548 			  __attribute__((unused)) void *data)
10549 {
10550 	int ret = 0;
10551 	struct rte_eth_flex_filter filter;
10552 	struct cmd_flex_filter_result *res = parsed_result;
10553 	char *bytes_ptr, *mask_ptr;
10554 	uint16_t len, i, j = 0;
10555 	char c;
10556 	int val;
10557 	uint8_t byte = 0;
10558 
10559 	if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10560 		printf("the len exceed the max length 128\n");
10561 		return;
10562 	}
10563 	memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10564 	filter.len = res->len_value;
10565 	filter.priority = res->priority_value;
10566 	filter.queue = res->queue_id;
10567 	bytes_ptr = res->bytes_value;
10568 	mask_ptr = res->mask_value;
10569 
10570 	 /* translate bytes string to array. */
10571 	if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10572 		(bytes_ptr[1] == 'X')))
10573 		bytes_ptr += 2;
10574 	len = strnlen(bytes_ptr, res->len_value * 2);
10575 	if (len == 0 || (len % 8 != 0)) {
10576 		printf("please check len and bytes input\n");
10577 		return;
10578 	}
10579 	for (i = 0; i < len; i++) {
10580 		c = bytes_ptr[i];
10581 		if (isxdigit(c) == 0) {
10582 			/* invalid characters. */
10583 			printf("invalid input\n");
10584 			return;
10585 		}
10586 		val = xdigit2val(c);
10587 		if (i % 2) {
10588 			byte |= val;
10589 			filter.bytes[j] = byte;
10590 			printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10591 			j++;
10592 			byte = 0;
10593 		} else
10594 			byte |= val << 4;
10595 	}
10596 	printf("\n");
10597 	 /* translate mask string to uint8_t array. */
10598 	if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10599 		(mask_ptr[1] == 'X')))
10600 		mask_ptr += 2;
10601 	len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10602 	if (len == 0) {
10603 		printf("invalid input\n");
10604 		return;
10605 	}
10606 	j = 0;
10607 	byte = 0;
10608 	for (i = 0; i < len; i++) {
10609 		c = mask_ptr[i];
10610 		if (isxdigit(c) == 0) {
10611 			/* invalid characters. */
10612 			printf("invalid input\n");
10613 			return;
10614 		}
10615 		val = xdigit2val(c);
10616 		if (i % 2) {
10617 			byte |= val;
10618 			filter.mask[j] = byte;
10619 			printf("mask[%d]:%02x ", j, filter.mask[j]);
10620 			j++;
10621 			byte = 0;
10622 		} else
10623 			byte |= val << 4;
10624 	}
10625 	printf("\n");
10626 
10627 	if (!strcmp(res->ops, "add"))
10628 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10629 				RTE_ETH_FILTER_FLEXIBLE,
10630 				RTE_ETH_FILTER_ADD,
10631 				&filter);
10632 	else
10633 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10634 				RTE_ETH_FILTER_FLEXIBLE,
10635 				RTE_ETH_FILTER_DELETE,
10636 				&filter);
10637 
10638 	if (ret < 0)
10639 		printf("flex filter setting error: (%s)\n", strerror(-ret));
10640 }
10641 
10642 cmdline_parse_token_string_t cmd_flex_filter_filter =
10643 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10644 				filter, "flex_filter");
10645 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10646 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10647 				port_id, UINT16);
10648 cmdline_parse_token_string_t cmd_flex_filter_ops =
10649 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10650 				ops, "add#del");
10651 cmdline_parse_token_string_t cmd_flex_filter_len =
10652 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10653 				len, "len");
10654 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10655 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10656 				len_value, UINT8);
10657 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10658 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10659 				bytes, "bytes");
10660 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10661 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10662 				bytes_value, NULL);
10663 cmdline_parse_token_string_t cmd_flex_filter_mask =
10664 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10665 				mask, "mask");
10666 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10667 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10668 				mask_value, NULL);
10669 cmdline_parse_token_string_t cmd_flex_filter_priority =
10670 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10671 				priority, "priority");
10672 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10673 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10674 				priority_value, UINT8);
10675 cmdline_parse_token_string_t cmd_flex_filter_queue =
10676 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10677 				queue, "queue");
10678 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10679 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10680 				queue_id, UINT16);
10681 cmdline_parse_inst_t cmd_flex_filter = {
10682 	.f = cmd_flex_filter_parsed,
10683 	.data = NULL,
10684 	.help_str = "flex_filter <port_id> add|del len <value> bytes "
10685 		"<value> mask <value> priority <value> queue <queue_id>: "
10686 		"Add/Del a flex filter",
10687 	.tokens = {
10688 		(void *)&cmd_flex_filter_filter,
10689 		(void *)&cmd_flex_filter_port_id,
10690 		(void *)&cmd_flex_filter_ops,
10691 		(void *)&cmd_flex_filter_len,
10692 		(void *)&cmd_flex_filter_len_value,
10693 		(void *)&cmd_flex_filter_bytes,
10694 		(void *)&cmd_flex_filter_bytes_value,
10695 		(void *)&cmd_flex_filter_mask,
10696 		(void *)&cmd_flex_filter_mask_value,
10697 		(void *)&cmd_flex_filter_priority,
10698 		(void *)&cmd_flex_filter_priority_value,
10699 		(void *)&cmd_flex_filter_queue,
10700 		(void *)&cmd_flex_filter_queue_id,
10701 		NULL,
10702 	},
10703 };
10704 
10705 /* *** Filters Control *** */
10706 
10707 /* *** deal with ethertype filter *** */
10708 struct cmd_ethertype_filter_result {
10709 	cmdline_fixed_string_t filter;
10710 	portid_t port_id;
10711 	cmdline_fixed_string_t ops;
10712 	cmdline_fixed_string_t mac;
10713 	struct rte_ether_addr mac_addr;
10714 	cmdline_fixed_string_t ethertype;
10715 	uint16_t ethertype_value;
10716 	cmdline_fixed_string_t drop;
10717 	cmdline_fixed_string_t queue;
10718 	uint16_t  queue_id;
10719 };
10720 
10721 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10722 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10723 				 filter, "ethertype_filter");
10724 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10725 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10726 			      port_id, UINT16);
10727 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10728 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10729 				 ops, "add#del");
10730 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10731 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10732 				 mac, "mac_addr#mac_ignr");
10733 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10734 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10735 				     mac_addr);
10736 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10737 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10738 				 ethertype, "ethertype");
10739 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10740 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10741 			      ethertype_value, UINT16);
10742 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10743 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10744 				 drop, "drop#fwd");
10745 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10746 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10747 				 queue, "queue");
10748 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10749 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10750 			      queue_id, UINT16);
10751 
10752 static void
10753 cmd_ethertype_filter_parsed(void *parsed_result,
10754 			  __attribute__((unused)) struct cmdline *cl,
10755 			  __attribute__((unused)) void *data)
10756 {
10757 	struct cmd_ethertype_filter_result *res = parsed_result;
10758 	struct rte_eth_ethertype_filter filter;
10759 	int ret = 0;
10760 
10761 	ret = rte_eth_dev_filter_supported(res->port_id,
10762 			RTE_ETH_FILTER_ETHERTYPE);
10763 	if (ret < 0) {
10764 		printf("ethertype filter is not supported on port %u.\n",
10765 			res->port_id);
10766 		return;
10767 	}
10768 
10769 	memset(&filter, 0, sizeof(filter));
10770 	if (!strcmp(res->mac, "mac_addr")) {
10771 		filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10772 		rte_memcpy(&filter.mac_addr, &res->mac_addr,
10773 			sizeof(struct rte_ether_addr));
10774 	}
10775 	if (!strcmp(res->drop, "drop"))
10776 		filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10777 	filter.ether_type = res->ethertype_value;
10778 	filter.queue = res->queue_id;
10779 
10780 	if (!strcmp(res->ops, "add"))
10781 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10782 				RTE_ETH_FILTER_ETHERTYPE,
10783 				RTE_ETH_FILTER_ADD,
10784 				&filter);
10785 	else
10786 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10787 				RTE_ETH_FILTER_ETHERTYPE,
10788 				RTE_ETH_FILTER_DELETE,
10789 				&filter);
10790 	if (ret < 0)
10791 		printf("ethertype filter programming error: (%s)\n",
10792 			strerror(-ret));
10793 }
10794 
10795 cmdline_parse_inst_t cmd_ethertype_filter = {
10796 	.f = cmd_ethertype_filter_parsed,
10797 	.data = NULL,
10798 	.help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10799 		"<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10800 		"Add or delete an ethertype filter entry",
10801 	.tokens = {
10802 		(void *)&cmd_ethertype_filter_filter,
10803 		(void *)&cmd_ethertype_filter_port_id,
10804 		(void *)&cmd_ethertype_filter_ops,
10805 		(void *)&cmd_ethertype_filter_mac,
10806 		(void *)&cmd_ethertype_filter_mac_addr,
10807 		(void *)&cmd_ethertype_filter_ethertype,
10808 		(void *)&cmd_ethertype_filter_ethertype_value,
10809 		(void *)&cmd_ethertype_filter_drop,
10810 		(void *)&cmd_ethertype_filter_queue,
10811 		(void *)&cmd_ethertype_filter_queue_id,
10812 		NULL,
10813 	},
10814 };
10815 
10816 /* *** deal with flow director filter *** */
10817 struct cmd_flow_director_result {
10818 	cmdline_fixed_string_t flow_director_filter;
10819 	portid_t port_id;
10820 	cmdline_fixed_string_t mode;
10821 	cmdline_fixed_string_t mode_value;
10822 	cmdline_fixed_string_t ops;
10823 	cmdline_fixed_string_t flow;
10824 	cmdline_fixed_string_t flow_type;
10825 	cmdline_fixed_string_t ether;
10826 	uint16_t ether_type;
10827 	cmdline_fixed_string_t src;
10828 	cmdline_ipaddr_t ip_src;
10829 	uint16_t port_src;
10830 	cmdline_fixed_string_t dst;
10831 	cmdline_ipaddr_t ip_dst;
10832 	uint16_t port_dst;
10833 	cmdline_fixed_string_t verify_tag;
10834 	uint32_t verify_tag_value;
10835 	cmdline_fixed_string_t tos;
10836 	uint8_t tos_value;
10837 	cmdline_fixed_string_t proto;
10838 	uint8_t proto_value;
10839 	cmdline_fixed_string_t ttl;
10840 	uint8_t ttl_value;
10841 	cmdline_fixed_string_t vlan;
10842 	uint16_t vlan_value;
10843 	cmdline_fixed_string_t flexbytes;
10844 	cmdline_fixed_string_t flexbytes_value;
10845 	cmdline_fixed_string_t pf_vf;
10846 	cmdline_fixed_string_t drop;
10847 	cmdline_fixed_string_t queue;
10848 	uint16_t  queue_id;
10849 	cmdline_fixed_string_t fd_id;
10850 	uint32_t  fd_id_value;
10851 	cmdline_fixed_string_t mac;
10852 	struct rte_ether_addr mac_addr;
10853 	cmdline_fixed_string_t tunnel;
10854 	cmdline_fixed_string_t tunnel_type;
10855 	cmdline_fixed_string_t tunnel_id;
10856 	uint32_t tunnel_id_value;
10857 	cmdline_fixed_string_t packet;
10858 	char filepath[];
10859 };
10860 
10861 static inline int
10862 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10863 {
10864 	char s[256];
10865 	const char *p, *p0 = q_arg;
10866 	char *end;
10867 	unsigned long int_fld;
10868 	char *str_fld[max_num];
10869 	int i;
10870 	unsigned size;
10871 	int ret = -1;
10872 
10873 	p = strchr(p0, '(');
10874 	if (p == NULL)
10875 		return -1;
10876 	++p;
10877 	p0 = strchr(p, ')');
10878 	if (p0 == NULL)
10879 		return -1;
10880 
10881 	size = p0 - p;
10882 	if (size >= sizeof(s))
10883 		return -1;
10884 
10885 	snprintf(s, sizeof(s), "%.*s", size, p);
10886 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10887 	if (ret < 0 || ret > max_num)
10888 		return -1;
10889 	for (i = 0; i < ret; i++) {
10890 		errno = 0;
10891 		int_fld = strtoul(str_fld[i], &end, 0);
10892 		if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10893 			return -1;
10894 		flexbytes[i] = (uint8_t)int_fld;
10895 	}
10896 	return ret;
10897 }
10898 
10899 static uint16_t
10900 str2flowtype(char *string)
10901 {
10902 	uint8_t i = 0;
10903 	static const struct {
10904 		char str[32];
10905 		uint16_t type;
10906 	} flowtype_str[] = {
10907 		{"raw", RTE_ETH_FLOW_RAW},
10908 		{"ipv4", RTE_ETH_FLOW_IPV4},
10909 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10910 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10911 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10912 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10913 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10914 		{"ipv6", RTE_ETH_FLOW_IPV6},
10915 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10916 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10917 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10918 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10919 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10920 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10921 	};
10922 
10923 	for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10924 		if (!strcmp(flowtype_str[i].str, string))
10925 			return flowtype_str[i].type;
10926 	}
10927 
10928 	if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10929 		return (uint16_t)atoi(string);
10930 
10931 	return RTE_ETH_FLOW_UNKNOWN;
10932 }
10933 
10934 static enum rte_eth_fdir_tunnel_type
10935 str2fdir_tunneltype(char *string)
10936 {
10937 	uint8_t i = 0;
10938 
10939 	static const struct {
10940 		char str[32];
10941 		enum rte_eth_fdir_tunnel_type type;
10942 	} tunneltype_str[] = {
10943 		{"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10944 		{"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10945 	};
10946 
10947 	for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10948 		if (!strcmp(tunneltype_str[i].str, string))
10949 			return tunneltype_str[i].type;
10950 	}
10951 	return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10952 }
10953 
10954 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10955 do { \
10956 	if ((ip_addr).family == AF_INET) \
10957 		(ip) = (ip_addr).addr.ipv4.s_addr; \
10958 	else { \
10959 		printf("invalid parameter.\n"); \
10960 		return; \
10961 	} \
10962 } while (0)
10963 
10964 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10965 do { \
10966 	if ((ip_addr).family == AF_INET6) \
10967 		rte_memcpy(&(ip), \
10968 				 &((ip_addr).addr.ipv6), \
10969 				 sizeof(struct in6_addr)); \
10970 	else { \
10971 		printf("invalid parameter.\n"); \
10972 		return; \
10973 	} \
10974 } while (0)
10975 
10976 static void
10977 cmd_flow_director_filter_parsed(void *parsed_result,
10978 			  __attribute__((unused)) struct cmdline *cl,
10979 			  __attribute__((unused)) void *data)
10980 {
10981 	struct cmd_flow_director_result *res = parsed_result;
10982 	struct rte_eth_fdir_filter entry;
10983 	uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10984 	char *end;
10985 	unsigned long vf_id;
10986 	int ret = 0;
10987 
10988 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10989 	if (ret < 0) {
10990 		printf("flow director is not supported on port %u.\n",
10991 			res->port_id);
10992 		return;
10993 	}
10994 	memset(flexbytes, 0, sizeof(flexbytes));
10995 	memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10996 
10997 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10998 		if (strcmp(res->mode_value, "MAC-VLAN")) {
10999 			printf("Please set mode to MAC-VLAN.\n");
11000 			return;
11001 		}
11002 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11003 		if (strcmp(res->mode_value, "Tunnel")) {
11004 			printf("Please set mode to Tunnel.\n");
11005 			return;
11006 		}
11007 	} else {
11008 		if (!strcmp(res->mode_value, "raw")) {
11009 #ifdef RTE_LIBRTE_I40E_PMD
11010 			struct rte_pmd_i40e_flow_type_mapping
11011 					mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11012 			struct rte_pmd_i40e_pkt_template_conf conf;
11013 			uint16_t flow_type = str2flowtype(res->flow_type);
11014 			uint16_t i, port = res->port_id;
11015 			uint8_t add;
11016 
11017 			memset(&conf, 0, sizeof(conf));
11018 
11019 			if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11020 				printf("Invalid flow type specified.\n");
11021 				return;
11022 			}
11023 			ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11024 								 mapping);
11025 			if (ret)
11026 				return;
11027 			if (mapping[flow_type].pctype == 0ULL) {
11028 				printf("Invalid flow type specified.\n");
11029 				return;
11030 			}
11031 			for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11032 				if (mapping[flow_type].pctype & (1ULL << i)) {
11033 					conf.input.pctype = i;
11034 					break;
11035 				}
11036 			}
11037 
11038 			conf.input.packet = open_file(res->filepath,
11039 						&conf.input.length);
11040 			if (!conf.input.packet)
11041 				return;
11042 			if (!strcmp(res->drop, "drop"))
11043 				conf.action.behavior =
11044 					RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11045 			else
11046 				conf.action.behavior =
11047 					RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11048 			conf.action.report_status =
11049 					RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11050 			conf.action.rx_queue = res->queue_id;
11051 			conf.soft_id = res->fd_id_value;
11052 			add  = strcmp(res->ops, "del") ? 1 : 0;
11053 			ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11054 									&conf,
11055 									add);
11056 			if (ret < 0)
11057 				printf("flow director config error: (%s)\n",
11058 				       strerror(-ret));
11059 			close_file(conf.input.packet);
11060 #endif
11061 			return;
11062 		} else if (strcmp(res->mode_value, "IP")) {
11063 			printf("Please set mode to IP or raw.\n");
11064 			return;
11065 		}
11066 		entry.input.flow_type = str2flowtype(res->flow_type);
11067 	}
11068 
11069 	ret = parse_flexbytes(res->flexbytes_value,
11070 					flexbytes,
11071 					RTE_ETH_FDIR_MAX_FLEXLEN);
11072 	if (ret < 0) {
11073 		printf("error: Cannot parse flexbytes input.\n");
11074 		return;
11075 	}
11076 
11077 	switch (entry.input.flow_type) {
11078 	case RTE_ETH_FLOW_FRAG_IPV4:
11079 	case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11080 		entry.input.flow.ip4_flow.proto = res->proto_value;
11081 		/* fall-through */
11082 	case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11083 	case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11084 		IPV4_ADDR_TO_UINT(res->ip_dst,
11085 			entry.input.flow.ip4_flow.dst_ip);
11086 		IPV4_ADDR_TO_UINT(res->ip_src,
11087 			entry.input.flow.ip4_flow.src_ip);
11088 		entry.input.flow.ip4_flow.tos = res->tos_value;
11089 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
11090 		/* need convert to big endian. */
11091 		entry.input.flow.udp4_flow.dst_port =
11092 				rte_cpu_to_be_16(res->port_dst);
11093 		entry.input.flow.udp4_flow.src_port =
11094 				rte_cpu_to_be_16(res->port_src);
11095 		break;
11096 	case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11097 		IPV4_ADDR_TO_UINT(res->ip_dst,
11098 			entry.input.flow.sctp4_flow.ip.dst_ip);
11099 		IPV4_ADDR_TO_UINT(res->ip_src,
11100 			entry.input.flow.sctp4_flow.ip.src_ip);
11101 		entry.input.flow.ip4_flow.tos = res->tos_value;
11102 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
11103 		/* need convert to big endian. */
11104 		entry.input.flow.sctp4_flow.dst_port =
11105 				rte_cpu_to_be_16(res->port_dst);
11106 		entry.input.flow.sctp4_flow.src_port =
11107 				rte_cpu_to_be_16(res->port_src);
11108 		entry.input.flow.sctp4_flow.verify_tag =
11109 				rte_cpu_to_be_32(res->verify_tag_value);
11110 		break;
11111 	case RTE_ETH_FLOW_FRAG_IPV6:
11112 	case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11113 		entry.input.flow.ipv6_flow.proto = res->proto_value;
11114 		/* fall-through */
11115 	case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11116 	case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11117 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
11118 			entry.input.flow.ipv6_flow.dst_ip);
11119 		IPV6_ADDR_TO_ARRAY(res->ip_src,
11120 			entry.input.flow.ipv6_flow.src_ip);
11121 		entry.input.flow.ipv6_flow.tc = res->tos_value;
11122 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11123 		/* need convert to big endian. */
11124 		entry.input.flow.udp6_flow.dst_port =
11125 				rte_cpu_to_be_16(res->port_dst);
11126 		entry.input.flow.udp6_flow.src_port =
11127 				rte_cpu_to_be_16(res->port_src);
11128 		break;
11129 	case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11130 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
11131 			entry.input.flow.sctp6_flow.ip.dst_ip);
11132 		IPV6_ADDR_TO_ARRAY(res->ip_src,
11133 			entry.input.flow.sctp6_flow.ip.src_ip);
11134 		entry.input.flow.ipv6_flow.tc = res->tos_value;
11135 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11136 		/* need convert to big endian. */
11137 		entry.input.flow.sctp6_flow.dst_port =
11138 				rte_cpu_to_be_16(res->port_dst);
11139 		entry.input.flow.sctp6_flow.src_port =
11140 				rte_cpu_to_be_16(res->port_src);
11141 		entry.input.flow.sctp6_flow.verify_tag =
11142 				rte_cpu_to_be_32(res->verify_tag_value);
11143 		break;
11144 	case RTE_ETH_FLOW_L2_PAYLOAD:
11145 		entry.input.flow.l2_flow.ether_type =
11146 			rte_cpu_to_be_16(res->ether_type);
11147 		break;
11148 	default:
11149 		break;
11150 	}
11151 
11152 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11153 		rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11154 				 &res->mac_addr,
11155 				 sizeof(struct rte_ether_addr));
11156 
11157 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11158 		rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11159 				 &res->mac_addr,
11160 				 sizeof(struct rte_ether_addr));
11161 		entry.input.flow.tunnel_flow.tunnel_type =
11162 			str2fdir_tunneltype(res->tunnel_type);
11163 		entry.input.flow.tunnel_flow.tunnel_id =
11164 			rte_cpu_to_be_32(res->tunnel_id_value);
11165 	}
11166 
11167 	rte_memcpy(entry.input.flow_ext.flexbytes,
11168 		   flexbytes,
11169 		   RTE_ETH_FDIR_MAX_FLEXLEN);
11170 
11171 	entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11172 
11173 	entry.action.flex_off = 0;  /*use 0 by default */
11174 	if (!strcmp(res->drop, "drop"))
11175 		entry.action.behavior = RTE_ETH_FDIR_REJECT;
11176 	else
11177 		entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11178 
11179 	if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11180 	    fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11181 		if (!strcmp(res->pf_vf, "pf"))
11182 			entry.input.flow_ext.is_vf = 0;
11183 		else if (!strncmp(res->pf_vf, "vf", 2)) {
11184 			struct rte_eth_dev_info dev_info;
11185 
11186 			memset(&dev_info, 0, sizeof(dev_info));
11187 			rte_eth_dev_info_get(res->port_id, &dev_info);
11188 			errno = 0;
11189 			vf_id = strtoul(res->pf_vf + 2, &end, 10);
11190 			if (errno != 0 || *end != '\0' ||
11191 			    vf_id >= dev_info.max_vfs) {
11192 				printf("invalid parameter %s.\n", res->pf_vf);
11193 				return;
11194 			}
11195 			entry.input.flow_ext.is_vf = 1;
11196 			entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11197 		} else {
11198 			printf("invalid parameter %s.\n", res->pf_vf);
11199 			return;
11200 		}
11201 	}
11202 
11203 	/* set to report FD ID by default */
11204 	entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11205 	entry.action.rx_queue = res->queue_id;
11206 	entry.soft_id = res->fd_id_value;
11207 	if (!strcmp(res->ops, "add"))
11208 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11209 					     RTE_ETH_FILTER_ADD, &entry);
11210 	else if (!strcmp(res->ops, "del"))
11211 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11212 					     RTE_ETH_FILTER_DELETE, &entry);
11213 	else
11214 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11215 					     RTE_ETH_FILTER_UPDATE, &entry);
11216 	if (ret < 0)
11217 		printf("flow director programming error: (%s)\n",
11218 			strerror(-ret));
11219 }
11220 
11221 cmdline_parse_token_string_t cmd_flow_director_filter =
11222 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11223 				 flow_director_filter, "flow_director_filter");
11224 cmdline_parse_token_num_t cmd_flow_director_port_id =
11225 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11226 			      port_id, UINT16);
11227 cmdline_parse_token_string_t cmd_flow_director_ops =
11228 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11229 				 ops, "add#del#update");
11230 cmdline_parse_token_string_t cmd_flow_director_flow =
11231 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11232 				 flow, "flow");
11233 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11234 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11235 		flow_type, NULL);
11236 cmdline_parse_token_string_t cmd_flow_director_ether =
11237 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11238 				 ether, "ether");
11239 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11240 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11241 			      ether_type, UINT16);
11242 cmdline_parse_token_string_t cmd_flow_director_src =
11243 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11244 				 src, "src");
11245 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11246 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11247 				 ip_src);
11248 cmdline_parse_token_num_t cmd_flow_director_port_src =
11249 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11250 			      port_src, UINT16);
11251 cmdline_parse_token_string_t cmd_flow_director_dst =
11252 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11253 				 dst, "dst");
11254 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11255 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11256 				 ip_dst);
11257 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11258 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11259 			      port_dst, UINT16);
11260 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11261 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11262 				  verify_tag, "verify_tag");
11263 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11264 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11265 			      verify_tag_value, UINT32);
11266 cmdline_parse_token_string_t cmd_flow_director_tos =
11267 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11268 				 tos, "tos");
11269 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11270 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11271 			      tos_value, UINT8);
11272 cmdline_parse_token_string_t cmd_flow_director_proto =
11273 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11274 				 proto, "proto");
11275 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11276 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11277 			      proto_value, UINT8);
11278 cmdline_parse_token_string_t cmd_flow_director_ttl =
11279 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11280 				 ttl, "ttl");
11281 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11282 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11283 			      ttl_value, UINT8);
11284 cmdline_parse_token_string_t cmd_flow_director_vlan =
11285 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11286 				 vlan, "vlan");
11287 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11288 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11289 			      vlan_value, UINT16);
11290 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11291 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11292 				 flexbytes, "flexbytes");
11293 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11294 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11295 			      flexbytes_value, NULL);
11296 cmdline_parse_token_string_t cmd_flow_director_drop =
11297 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11298 				 drop, "drop#fwd");
11299 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11300 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11301 			      pf_vf, NULL);
11302 cmdline_parse_token_string_t cmd_flow_director_queue =
11303 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11304 				 queue, "queue");
11305 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11306 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11307 			      queue_id, UINT16);
11308 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11309 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11310 				 fd_id, "fd_id");
11311 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11312 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11313 			      fd_id_value, UINT32);
11314 
11315 cmdline_parse_token_string_t cmd_flow_director_mode =
11316 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11317 				 mode, "mode");
11318 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11319 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11320 				 mode_value, "IP");
11321 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11322 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11323 				 mode_value, "MAC-VLAN");
11324 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11325 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11326 				 mode_value, "Tunnel");
11327 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11328 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11329 				 mode_value, "raw");
11330 cmdline_parse_token_string_t cmd_flow_director_mac =
11331 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11332 				 mac, "mac");
11333 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11334 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11335 				    mac_addr);
11336 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11337 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11338 				 tunnel, "tunnel");
11339 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11340 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11341 				 tunnel_type, "NVGRE#VxLAN");
11342 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11343 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11344 				 tunnel_id, "tunnel-id");
11345 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11346 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11347 			      tunnel_id_value, UINT32);
11348 cmdline_parse_token_string_t cmd_flow_director_packet =
11349 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11350 				 packet, "packet");
11351 cmdline_parse_token_string_t cmd_flow_director_filepath =
11352 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11353 				 filepath, NULL);
11354 
11355 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11356 	.f = cmd_flow_director_filter_parsed,
11357 	.data = NULL,
11358 	.help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11359 		" ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11360 		"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11361 		"l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11362 		"proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11363 		"flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11364 		"fd_id <fd_id_value>: "
11365 		"Add or delete an ip flow director entry on NIC",
11366 	.tokens = {
11367 		(void *)&cmd_flow_director_filter,
11368 		(void *)&cmd_flow_director_port_id,
11369 		(void *)&cmd_flow_director_mode,
11370 		(void *)&cmd_flow_director_mode_ip,
11371 		(void *)&cmd_flow_director_ops,
11372 		(void *)&cmd_flow_director_flow,
11373 		(void *)&cmd_flow_director_flow_type,
11374 		(void *)&cmd_flow_director_src,
11375 		(void *)&cmd_flow_director_ip_src,
11376 		(void *)&cmd_flow_director_dst,
11377 		(void *)&cmd_flow_director_ip_dst,
11378 		(void *)&cmd_flow_director_tos,
11379 		(void *)&cmd_flow_director_tos_value,
11380 		(void *)&cmd_flow_director_proto,
11381 		(void *)&cmd_flow_director_proto_value,
11382 		(void *)&cmd_flow_director_ttl,
11383 		(void *)&cmd_flow_director_ttl_value,
11384 		(void *)&cmd_flow_director_vlan,
11385 		(void *)&cmd_flow_director_vlan_value,
11386 		(void *)&cmd_flow_director_flexbytes,
11387 		(void *)&cmd_flow_director_flexbytes_value,
11388 		(void *)&cmd_flow_director_drop,
11389 		(void *)&cmd_flow_director_pf_vf,
11390 		(void *)&cmd_flow_director_queue,
11391 		(void *)&cmd_flow_director_queue_id,
11392 		(void *)&cmd_flow_director_fd_id,
11393 		(void *)&cmd_flow_director_fd_id_value,
11394 		NULL,
11395 	},
11396 };
11397 
11398 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11399 	.f = cmd_flow_director_filter_parsed,
11400 	.data = NULL,
11401 	.help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11402 		"director entry on NIC",
11403 	.tokens = {
11404 		(void *)&cmd_flow_director_filter,
11405 		(void *)&cmd_flow_director_port_id,
11406 		(void *)&cmd_flow_director_mode,
11407 		(void *)&cmd_flow_director_mode_ip,
11408 		(void *)&cmd_flow_director_ops,
11409 		(void *)&cmd_flow_director_flow,
11410 		(void *)&cmd_flow_director_flow_type,
11411 		(void *)&cmd_flow_director_src,
11412 		(void *)&cmd_flow_director_ip_src,
11413 		(void *)&cmd_flow_director_port_src,
11414 		(void *)&cmd_flow_director_dst,
11415 		(void *)&cmd_flow_director_ip_dst,
11416 		(void *)&cmd_flow_director_port_dst,
11417 		(void *)&cmd_flow_director_tos,
11418 		(void *)&cmd_flow_director_tos_value,
11419 		(void *)&cmd_flow_director_ttl,
11420 		(void *)&cmd_flow_director_ttl_value,
11421 		(void *)&cmd_flow_director_vlan,
11422 		(void *)&cmd_flow_director_vlan_value,
11423 		(void *)&cmd_flow_director_flexbytes,
11424 		(void *)&cmd_flow_director_flexbytes_value,
11425 		(void *)&cmd_flow_director_drop,
11426 		(void *)&cmd_flow_director_pf_vf,
11427 		(void *)&cmd_flow_director_queue,
11428 		(void *)&cmd_flow_director_queue_id,
11429 		(void *)&cmd_flow_director_fd_id,
11430 		(void *)&cmd_flow_director_fd_id_value,
11431 		NULL,
11432 	},
11433 };
11434 
11435 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11436 	.f = cmd_flow_director_filter_parsed,
11437 	.data = NULL,
11438 	.help_str = "flow_director_filter ... : Add or delete a sctp flow "
11439 		"director entry on NIC",
11440 	.tokens = {
11441 		(void *)&cmd_flow_director_filter,
11442 		(void *)&cmd_flow_director_port_id,
11443 		(void *)&cmd_flow_director_mode,
11444 		(void *)&cmd_flow_director_mode_ip,
11445 		(void *)&cmd_flow_director_ops,
11446 		(void *)&cmd_flow_director_flow,
11447 		(void *)&cmd_flow_director_flow_type,
11448 		(void *)&cmd_flow_director_src,
11449 		(void *)&cmd_flow_director_ip_src,
11450 		(void *)&cmd_flow_director_port_src,
11451 		(void *)&cmd_flow_director_dst,
11452 		(void *)&cmd_flow_director_ip_dst,
11453 		(void *)&cmd_flow_director_port_dst,
11454 		(void *)&cmd_flow_director_verify_tag,
11455 		(void *)&cmd_flow_director_verify_tag_value,
11456 		(void *)&cmd_flow_director_tos,
11457 		(void *)&cmd_flow_director_tos_value,
11458 		(void *)&cmd_flow_director_ttl,
11459 		(void *)&cmd_flow_director_ttl_value,
11460 		(void *)&cmd_flow_director_vlan,
11461 		(void *)&cmd_flow_director_vlan_value,
11462 		(void *)&cmd_flow_director_flexbytes,
11463 		(void *)&cmd_flow_director_flexbytes_value,
11464 		(void *)&cmd_flow_director_drop,
11465 		(void *)&cmd_flow_director_pf_vf,
11466 		(void *)&cmd_flow_director_queue,
11467 		(void *)&cmd_flow_director_queue_id,
11468 		(void *)&cmd_flow_director_fd_id,
11469 		(void *)&cmd_flow_director_fd_id_value,
11470 		NULL,
11471 	},
11472 };
11473 
11474 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11475 	.f = cmd_flow_director_filter_parsed,
11476 	.data = NULL,
11477 	.help_str = "flow_director_filter ... : Add or delete a L2 flow "
11478 		"director entry on NIC",
11479 	.tokens = {
11480 		(void *)&cmd_flow_director_filter,
11481 		(void *)&cmd_flow_director_port_id,
11482 		(void *)&cmd_flow_director_mode,
11483 		(void *)&cmd_flow_director_mode_ip,
11484 		(void *)&cmd_flow_director_ops,
11485 		(void *)&cmd_flow_director_flow,
11486 		(void *)&cmd_flow_director_flow_type,
11487 		(void *)&cmd_flow_director_ether,
11488 		(void *)&cmd_flow_director_ether_type,
11489 		(void *)&cmd_flow_director_flexbytes,
11490 		(void *)&cmd_flow_director_flexbytes_value,
11491 		(void *)&cmd_flow_director_drop,
11492 		(void *)&cmd_flow_director_pf_vf,
11493 		(void *)&cmd_flow_director_queue,
11494 		(void *)&cmd_flow_director_queue_id,
11495 		(void *)&cmd_flow_director_fd_id,
11496 		(void *)&cmd_flow_director_fd_id_value,
11497 		NULL,
11498 	},
11499 };
11500 
11501 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11502 	.f = cmd_flow_director_filter_parsed,
11503 	.data = NULL,
11504 	.help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11505 		"director entry on NIC",
11506 	.tokens = {
11507 		(void *)&cmd_flow_director_filter,
11508 		(void *)&cmd_flow_director_port_id,
11509 		(void *)&cmd_flow_director_mode,
11510 		(void *)&cmd_flow_director_mode_mac_vlan,
11511 		(void *)&cmd_flow_director_ops,
11512 		(void *)&cmd_flow_director_mac,
11513 		(void *)&cmd_flow_director_mac_addr,
11514 		(void *)&cmd_flow_director_vlan,
11515 		(void *)&cmd_flow_director_vlan_value,
11516 		(void *)&cmd_flow_director_flexbytes,
11517 		(void *)&cmd_flow_director_flexbytes_value,
11518 		(void *)&cmd_flow_director_drop,
11519 		(void *)&cmd_flow_director_queue,
11520 		(void *)&cmd_flow_director_queue_id,
11521 		(void *)&cmd_flow_director_fd_id,
11522 		(void *)&cmd_flow_director_fd_id_value,
11523 		NULL,
11524 	},
11525 };
11526 
11527 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11528 	.f = cmd_flow_director_filter_parsed,
11529 	.data = NULL,
11530 	.help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11531 		"director entry on NIC",
11532 	.tokens = {
11533 		(void *)&cmd_flow_director_filter,
11534 		(void *)&cmd_flow_director_port_id,
11535 		(void *)&cmd_flow_director_mode,
11536 		(void *)&cmd_flow_director_mode_tunnel,
11537 		(void *)&cmd_flow_director_ops,
11538 		(void *)&cmd_flow_director_mac,
11539 		(void *)&cmd_flow_director_mac_addr,
11540 		(void *)&cmd_flow_director_vlan,
11541 		(void *)&cmd_flow_director_vlan_value,
11542 		(void *)&cmd_flow_director_tunnel,
11543 		(void *)&cmd_flow_director_tunnel_type,
11544 		(void *)&cmd_flow_director_tunnel_id,
11545 		(void *)&cmd_flow_director_tunnel_id_value,
11546 		(void *)&cmd_flow_director_flexbytes,
11547 		(void *)&cmd_flow_director_flexbytes_value,
11548 		(void *)&cmd_flow_director_drop,
11549 		(void *)&cmd_flow_director_queue,
11550 		(void *)&cmd_flow_director_queue_id,
11551 		(void *)&cmd_flow_director_fd_id,
11552 		(void *)&cmd_flow_director_fd_id_value,
11553 		NULL,
11554 	},
11555 };
11556 
11557 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11558 	.f = cmd_flow_director_filter_parsed,
11559 	.data = NULL,
11560 	.help_str = "flow_director_filter ... : Add or delete a raw flow "
11561 		"director entry on NIC",
11562 	.tokens = {
11563 		(void *)&cmd_flow_director_filter,
11564 		(void *)&cmd_flow_director_port_id,
11565 		(void *)&cmd_flow_director_mode,
11566 		(void *)&cmd_flow_director_mode_raw,
11567 		(void *)&cmd_flow_director_ops,
11568 		(void *)&cmd_flow_director_flow,
11569 		(void *)&cmd_flow_director_flow_type,
11570 		(void *)&cmd_flow_director_drop,
11571 		(void *)&cmd_flow_director_queue,
11572 		(void *)&cmd_flow_director_queue_id,
11573 		(void *)&cmd_flow_director_fd_id,
11574 		(void *)&cmd_flow_director_fd_id_value,
11575 		(void *)&cmd_flow_director_packet,
11576 		(void *)&cmd_flow_director_filepath,
11577 		NULL,
11578 	},
11579 };
11580 
11581 struct cmd_flush_flow_director_result {
11582 	cmdline_fixed_string_t flush_flow_director;
11583 	portid_t port_id;
11584 };
11585 
11586 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11587 	TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11588 				 flush_flow_director, "flush_flow_director");
11589 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11590 	TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11591 			      port_id, UINT16);
11592 
11593 static void
11594 cmd_flush_flow_director_parsed(void *parsed_result,
11595 			  __attribute__((unused)) struct cmdline *cl,
11596 			  __attribute__((unused)) void *data)
11597 {
11598 	struct cmd_flow_director_result *res = parsed_result;
11599 	int ret = 0;
11600 
11601 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11602 	if (ret < 0) {
11603 		printf("flow director is not supported on port %u.\n",
11604 			res->port_id);
11605 		return;
11606 	}
11607 
11608 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11609 			RTE_ETH_FILTER_FLUSH, NULL);
11610 	if (ret < 0)
11611 		printf("flow director table flushing error: (%s)\n",
11612 			strerror(-ret));
11613 }
11614 
11615 cmdline_parse_inst_t cmd_flush_flow_director = {
11616 	.f = cmd_flush_flow_director_parsed,
11617 	.data = NULL,
11618 	.help_str = "flush_flow_director <port_id>: "
11619 		"Flush all flow director entries of a device on NIC",
11620 	.tokens = {
11621 		(void *)&cmd_flush_flow_director_flush,
11622 		(void *)&cmd_flush_flow_director_port_id,
11623 		NULL,
11624 	},
11625 };
11626 
11627 /* *** deal with flow director mask *** */
11628 struct cmd_flow_director_mask_result {
11629 	cmdline_fixed_string_t flow_director_mask;
11630 	portid_t port_id;
11631 	cmdline_fixed_string_t mode;
11632 	cmdline_fixed_string_t mode_value;
11633 	cmdline_fixed_string_t vlan;
11634 	uint16_t vlan_mask;
11635 	cmdline_fixed_string_t src_mask;
11636 	cmdline_ipaddr_t ipv4_src;
11637 	cmdline_ipaddr_t ipv6_src;
11638 	uint16_t port_src;
11639 	cmdline_fixed_string_t dst_mask;
11640 	cmdline_ipaddr_t ipv4_dst;
11641 	cmdline_ipaddr_t ipv6_dst;
11642 	uint16_t port_dst;
11643 	cmdline_fixed_string_t mac;
11644 	uint8_t mac_addr_byte_mask;
11645 	cmdline_fixed_string_t tunnel_id;
11646 	uint32_t tunnel_id_mask;
11647 	cmdline_fixed_string_t tunnel_type;
11648 	uint8_t tunnel_type_mask;
11649 };
11650 
11651 static void
11652 cmd_flow_director_mask_parsed(void *parsed_result,
11653 			  __attribute__((unused)) struct cmdline *cl,
11654 			  __attribute__((unused)) void *data)
11655 {
11656 	struct cmd_flow_director_mask_result *res = parsed_result;
11657 	struct rte_eth_fdir_masks *mask;
11658 	struct rte_port *port;
11659 
11660 	port = &ports[res->port_id];
11661 	/** Check if the port is not started **/
11662 	if (port->port_status != RTE_PORT_STOPPED) {
11663 		printf("Please stop port %d first\n", res->port_id);
11664 		return;
11665 	}
11666 
11667 	mask = &port->dev_conf.fdir_conf.mask;
11668 
11669 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11670 		if (strcmp(res->mode_value, "MAC-VLAN")) {
11671 			printf("Please set mode to MAC-VLAN.\n");
11672 			return;
11673 		}
11674 
11675 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11676 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11677 		if (strcmp(res->mode_value, "Tunnel")) {
11678 			printf("Please set mode to Tunnel.\n");
11679 			return;
11680 		}
11681 
11682 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11683 		mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11684 		mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11685 		mask->tunnel_type_mask = res->tunnel_type_mask;
11686 	} else {
11687 		if (strcmp(res->mode_value, "IP")) {
11688 			printf("Please set mode to IP.\n");
11689 			return;
11690 		}
11691 
11692 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11693 		IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11694 		IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11695 		IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11696 		IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11697 		mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11698 		mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11699 	}
11700 
11701 	cmd_reconfig_device_queue(res->port_id, 1, 1);
11702 }
11703 
11704 cmdline_parse_token_string_t cmd_flow_director_mask =
11705 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11706 				 flow_director_mask, "flow_director_mask");
11707 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11708 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11709 			      port_id, UINT16);
11710 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11711 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11712 				 vlan, "vlan");
11713 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11714 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11715 			      vlan_mask, UINT16);
11716 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11717 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11718 				 src_mask, "src_mask");
11719 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11720 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11721 				 ipv4_src);
11722 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11723 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11724 				 ipv6_src);
11725 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11726 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11727 			      port_src, UINT16);
11728 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11729 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11730 				 dst_mask, "dst_mask");
11731 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11732 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11733 				 ipv4_dst);
11734 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11735 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11736 				 ipv6_dst);
11737 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11738 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11739 			      port_dst, UINT16);
11740 
11741 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11742 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11743 				 mode, "mode");
11744 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11745 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11746 				 mode_value, "IP");
11747 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11748 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11749 				 mode_value, "MAC-VLAN");
11750 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11751 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11752 				 mode_value, "Tunnel");
11753 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11754 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11755 				 mac, "mac");
11756 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11757 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11758 			      mac_addr_byte_mask, UINT8);
11759 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11760 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11761 				 tunnel_type, "tunnel-type");
11762 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11763 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11764 			      tunnel_type_mask, UINT8);
11765 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11766 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11767 				 tunnel_id, "tunnel-id");
11768 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11769 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11770 			      tunnel_id_mask, UINT32);
11771 
11772 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11773 	.f = cmd_flow_director_mask_parsed,
11774 	.data = NULL,
11775 	.help_str = "flow_director_mask ... : "
11776 		"Set IP mode flow director's mask on NIC",
11777 	.tokens = {
11778 		(void *)&cmd_flow_director_mask,
11779 		(void *)&cmd_flow_director_mask_port_id,
11780 		(void *)&cmd_flow_director_mask_mode,
11781 		(void *)&cmd_flow_director_mask_mode_ip,
11782 		(void *)&cmd_flow_director_mask_vlan,
11783 		(void *)&cmd_flow_director_mask_vlan_value,
11784 		(void *)&cmd_flow_director_mask_src,
11785 		(void *)&cmd_flow_director_mask_ipv4_src,
11786 		(void *)&cmd_flow_director_mask_ipv6_src,
11787 		(void *)&cmd_flow_director_mask_port_src,
11788 		(void *)&cmd_flow_director_mask_dst,
11789 		(void *)&cmd_flow_director_mask_ipv4_dst,
11790 		(void *)&cmd_flow_director_mask_ipv6_dst,
11791 		(void *)&cmd_flow_director_mask_port_dst,
11792 		NULL,
11793 	},
11794 };
11795 
11796 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11797 	.f = cmd_flow_director_mask_parsed,
11798 	.data = NULL,
11799 	.help_str = "flow_director_mask ... : Set MAC VLAN mode "
11800 		"flow director's mask on NIC",
11801 	.tokens = {
11802 		(void *)&cmd_flow_director_mask,
11803 		(void *)&cmd_flow_director_mask_port_id,
11804 		(void *)&cmd_flow_director_mask_mode,
11805 		(void *)&cmd_flow_director_mask_mode_mac_vlan,
11806 		(void *)&cmd_flow_director_mask_vlan,
11807 		(void *)&cmd_flow_director_mask_vlan_value,
11808 		NULL,
11809 	},
11810 };
11811 
11812 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11813 	.f = cmd_flow_director_mask_parsed,
11814 	.data = NULL,
11815 	.help_str = "flow_director_mask ... : Set tunnel mode "
11816 		"flow director's mask on NIC",
11817 	.tokens = {
11818 		(void *)&cmd_flow_director_mask,
11819 		(void *)&cmd_flow_director_mask_port_id,
11820 		(void *)&cmd_flow_director_mask_mode,
11821 		(void *)&cmd_flow_director_mask_mode_tunnel,
11822 		(void *)&cmd_flow_director_mask_vlan,
11823 		(void *)&cmd_flow_director_mask_vlan_value,
11824 		(void *)&cmd_flow_director_mask_mac,
11825 		(void *)&cmd_flow_director_mask_mac_value,
11826 		(void *)&cmd_flow_director_mask_tunnel_type,
11827 		(void *)&cmd_flow_director_mask_tunnel_type_value,
11828 		(void *)&cmd_flow_director_mask_tunnel_id,
11829 		(void *)&cmd_flow_director_mask_tunnel_id_value,
11830 		NULL,
11831 	},
11832 };
11833 
11834 /* *** deal with flow director mask on flexible payload *** */
11835 struct cmd_flow_director_flex_mask_result {
11836 	cmdline_fixed_string_t flow_director_flexmask;
11837 	portid_t port_id;
11838 	cmdline_fixed_string_t flow;
11839 	cmdline_fixed_string_t flow_type;
11840 	cmdline_fixed_string_t mask;
11841 };
11842 
11843 static void
11844 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11845 			  __attribute__((unused)) struct cmdline *cl,
11846 			  __attribute__((unused)) void *data)
11847 {
11848 	struct cmd_flow_director_flex_mask_result *res = parsed_result;
11849 	struct rte_eth_fdir_info fdir_info;
11850 	struct rte_eth_fdir_flex_mask flex_mask;
11851 	struct rte_port *port;
11852 	uint64_t flow_type_mask;
11853 	uint16_t i;
11854 	int ret;
11855 
11856 	port = &ports[res->port_id];
11857 	/** Check if the port is not started **/
11858 	if (port->port_status != RTE_PORT_STOPPED) {
11859 		printf("Please stop port %d first\n", res->port_id);
11860 		return;
11861 	}
11862 
11863 	memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11864 	ret = parse_flexbytes(res->mask,
11865 			flex_mask.mask,
11866 			RTE_ETH_FDIR_MAX_FLEXLEN);
11867 	if (ret < 0) {
11868 		printf("error: Cannot parse mask input.\n");
11869 		return;
11870 	}
11871 
11872 	memset(&fdir_info, 0, sizeof(fdir_info));
11873 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11874 				RTE_ETH_FILTER_INFO, &fdir_info);
11875 	if (ret < 0) {
11876 		printf("Cannot get FDir filter info\n");
11877 		return;
11878 	}
11879 
11880 	if (!strcmp(res->flow_type, "none")) {
11881 		/* means don't specify the flow type */
11882 		flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11883 		for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11884 			memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11885 			       0, sizeof(struct rte_eth_fdir_flex_mask));
11886 		port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11887 		rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11888 				 &flex_mask,
11889 				 sizeof(struct rte_eth_fdir_flex_mask));
11890 		cmd_reconfig_device_queue(res->port_id, 1, 1);
11891 		return;
11892 	}
11893 	flow_type_mask = fdir_info.flow_types_mask[0];
11894 	if (!strcmp(res->flow_type, "all")) {
11895 		if (!flow_type_mask) {
11896 			printf("No flow type supported\n");
11897 			return;
11898 		}
11899 		for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11900 			if (flow_type_mask & (1ULL << i)) {
11901 				flex_mask.flow_type = i;
11902 				fdir_set_flex_mask(res->port_id, &flex_mask);
11903 			}
11904 		}
11905 		cmd_reconfig_device_queue(res->port_id, 1, 1);
11906 		return;
11907 	}
11908 	flex_mask.flow_type = str2flowtype(res->flow_type);
11909 	if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11910 		printf("Flow type %s not supported on port %d\n",
11911 				res->flow_type, res->port_id);
11912 		return;
11913 	}
11914 	fdir_set_flex_mask(res->port_id, &flex_mask);
11915 	cmd_reconfig_device_queue(res->port_id, 1, 1);
11916 }
11917 
11918 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11919 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11920 				 flow_director_flexmask,
11921 				 "flow_director_flex_mask");
11922 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11923 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11924 			      port_id, UINT16);
11925 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11926 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11927 				 flow, "flow");
11928 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11929 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11930 		flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11931 		"ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11932 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11933 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11934 				 mask, NULL);
11935 
11936 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11937 	.f = cmd_flow_director_flex_mask_parsed,
11938 	.data = NULL,
11939 	.help_str = "flow_director_flex_mask ... : "
11940 		"Set flow director's flex mask on NIC",
11941 	.tokens = {
11942 		(void *)&cmd_flow_director_flexmask,
11943 		(void *)&cmd_flow_director_flexmask_port_id,
11944 		(void *)&cmd_flow_director_flexmask_flow,
11945 		(void *)&cmd_flow_director_flexmask_flow_type,
11946 		(void *)&cmd_flow_director_flexmask_mask,
11947 		NULL,
11948 	},
11949 };
11950 
11951 /* *** deal with flow director flexible payload configuration *** */
11952 struct cmd_flow_director_flexpayload_result {
11953 	cmdline_fixed_string_t flow_director_flexpayload;
11954 	portid_t port_id;
11955 	cmdline_fixed_string_t payload_layer;
11956 	cmdline_fixed_string_t payload_cfg;
11957 };
11958 
11959 static inline int
11960 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11961 {
11962 	char s[256];
11963 	const char *p, *p0 = q_arg;
11964 	char *end;
11965 	unsigned long int_fld;
11966 	char *str_fld[max_num];
11967 	int i;
11968 	unsigned size;
11969 	int ret = -1;
11970 
11971 	p = strchr(p0, '(');
11972 	if (p == NULL)
11973 		return -1;
11974 	++p;
11975 	p0 = strchr(p, ')');
11976 	if (p0 == NULL)
11977 		return -1;
11978 
11979 	size = p0 - p;
11980 	if (size >= sizeof(s))
11981 		return -1;
11982 
11983 	snprintf(s, sizeof(s), "%.*s", size, p);
11984 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11985 	if (ret < 0 || ret > max_num)
11986 		return -1;
11987 	for (i = 0; i < ret; i++) {
11988 		errno = 0;
11989 		int_fld = strtoul(str_fld[i], &end, 0);
11990 		if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11991 			return -1;
11992 		offsets[i] = (uint16_t)int_fld;
11993 	}
11994 	return ret;
11995 }
11996 
11997 static void
11998 cmd_flow_director_flxpld_parsed(void *parsed_result,
11999 			  __attribute__((unused)) struct cmdline *cl,
12000 			  __attribute__((unused)) void *data)
12001 {
12002 	struct cmd_flow_director_flexpayload_result *res = parsed_result;
12003 	struct rte_eth_flex_payload_cfg flex_cfg;
12004 	struct rte_port *port;
12005 	int ret = 0;
12006 
12007 	port = &ports[res->port_id];
12008 	/** Check if the port is not started **/
12009 	if (port->port_status != RTE_PORT_STOPPED) {
12010 		printf("Please stop port %d first\n", res->port_id);
12011 		return;
12012 	}
12013 
12014 	memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12015 
12016 	if (!strcmp(res->payload_layer, "raw"))
12017 		flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12018 	else if (!strcmp(res->payload_layer, "l2"))
12019 		flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12020 	else if (!strcmp(res->payload_layer, "l3"))
12021 		flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12022 	else if (!strcmp(res->payload_layer, "l4"))
12023 		flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12024 
12025 	ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12026 			    RTE_ETH_FDIR_MAX_FLEXLEN);
12027 	if (ret < 0) {
12028 		printf("error: Cannot parse flex payload input.\n");
12029 		return;
12030 	}
12031 
12032 	fdir_set_flex_payload(res->port_id, &flex_cfg);
12033 	cmd_reconfig_device_queue(res->port_id, 1, 1);
12034 }
12035 
12036 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12037 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12038 				 flow_director_flexpayload,
12039 				 "flow_director_flex_payload");
12040 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12041 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12042 			      port_id, UINT16);
12043 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12044 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12045 				 payload_layer, "raw#l2#l3#l4");
12046 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12047 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12048 				 payload_cfg, NULL);
12049 
12050 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12051 	.f = cmd_flow_director_flxpld_parsed,
12052 	.data = NULL,
12053 	.help_str = "flow_director_flexpayload ... : "
12054 		"Set flow director's flex payload on NIC",
12055 	.tokens = {
12056 		(void *)&cmd_flow_director_flexpayload,
12057 		(void *)&cmd_flow_director_flexpayload_port_id,
12058 		(void *)&cmd_flow_director_flexpayload_payload_layer,
12059 		(void *)&cmd_flow_director_flexpayload_payload_cfg,
12060 		NULL,
12061 	},
12062 };
12063 
12064 /* Generic flow interface command. */
12065 extern cmdline_parse_inst_t cmd_flow;
12066 
12067 /* *** Classification Filters Control *** */
12068 /* *** Get symmetric hash enable per port *** */
12069 struct cmd_get_sym_hash_ena_per_port_result {
12070 	cmdline_fixed_string_t get_sym_hash_ena_per_port;
12071 	portid_t port_id;
12072 };
12073 
12074 static void
12075 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12076 				 __rte_unused struct cmdline *cl,
12077 				 __rte_unused void *data)
12078 {
12079 	struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12080 	struct rte_eth_hash_filter_info info;
12081 	int ret;
12082 
12083 	if (rte_eth_dev_filter_supported(res->port_id,
12084 				RTE_ETH_FILTER_HASH) < 0) {
12085 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12086 							res->port_id);
12087 		return;
12088 	}
12089 
12090 	memset(&info, 0, sizeof(info));
12091 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12092 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12093 						RTE_ETH_FILTER_GET, &info);
12094 
12095 	if (ret < 0) {
12096 		printf("Cannot get symmetric hash enable per port "
12097 					"on port %u\n", res->port_id);
12098 		return;
12099 	}
12100 
12101 	printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12102 				"enabled" : "disabled", res->port_id);
12103 }
12104 
12105 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12106 	TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12107 		get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12108 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12109 	TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12110 		port_id, UINT16);
12111 
12112 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12113 	.f = cmd_get_sym_hash_per_port_parsed,
12114 	.data = NULL,
12115 	.help_str = "get_sym_hash_ena_per_port <port_id>",
12116 	.tokens = {
12117 		(void *)&cmd_get_sym_hash_ena_per_port_all,
12118 		(void *)&cmd_get_sym_hash_ena_per_port_port_id,
12119 		NULL,
12120 	},
12121 };
12122 
12123 /* *** Set symmetric hash enable per port *** */
12124 struct cmd_set_sym_hash_ena_per_port_result {
12125 	cmdline_fixed_string_t set_sym_hash_ena_per_port;
12126 	cmdline_fixed_string_t enable;
12127 	portid_t port_id;
12128 };
12129 
12130 static void
12131 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12132 				 __rte_unused struct cmdline *cl,
12133 				 __rte_unused void *data)
12134 {
12135 	struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12136 	struct rte_eth_hash_filter_info info;
12137 	int ret;
12138 
12139 	if (rte_eth_dev_filter_supported(res->port_id,
12140 				RTE_ETH_FILTER_HASH) < 0) {
12141 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12142 							res->port_id);
12143 		return;
12144 	}
12145 
12146 	memset(&info, 0, sizeof(info));
12147 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12148 	if (!strcmp(res->enable, "enable"))
12149 		info.info.enable = 1;
12150 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12151 					RTE_ETH_FILTER_SET, &info);
12152 	if (ret < 0) {
12153 		printf("Cannot set symmetric hash enable per port on "
12154 					"port %u\n", res->port_id);
12155 		return;
12156 	}
12157 	printf("Symmetric hash has been set to %s on port %u\n",
12158 					res->enable, res->port_id);
12159 }
12160 
12161 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12162 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12163 		set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12164 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12165 	TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12166 		port_id, UINT16);
12167 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12168 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12169 		enable, "enable#disable");
12170 
12171 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12172 	.f = cmd_set_sym_hash_per_port_parsed,
12173 	.data = NULL,
12174 	.help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12175 	.tokens = {
12176 		(void *)&cmd_set_sym_hash_ena_per_port_all,
12177 		(void *)&cmd_set_sym_hash_ena_per_port_port_id,
12178 		(void *)&cmd_set_sym_hash_ena_per_port_enable,
12179 		NULL,
12180 	},
12181 };
12182 
12183 /* Get global config of hash function */
12184 struct cmd_get_hash_global_config_result {
12185 	cmdline_fixed_string_t get_hash_global_config;
12186 	portid_t port_id;
12187 };
12188 
12189 static char *
12190 flowtype_to_str(uint16_t ftype)
12191 {
12192 	uint16_t i;
12193 	static struct {
12194 		char str[16];
12195 		uint16_t ftype;
12196 	} ftype_table[] = {
12197 		{"ipv4", RTE_ETH_FLOW_IPV4},
12198 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12199 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12200 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12201 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12202 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12203 		{"ipv6", RTE_ETH_FLOW_IPV6},
12204 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12205 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12206 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12207 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12208 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12209 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12210 		{"port", RTE_ETH_FLOW_PORT},
12211 		{"vxlan", RTE_ETH_FLOW_VXLAN},
12212 		{"geneve", RTE_ETH_FLOW_GENEVE},
12213 		{"nvgre", RTE_ETH_FLOW_NVGRE},
12214 		{"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12215 	};
12216 
12217 	for (i = 0; i < RTE_DIM(ftype_table); i++) {
12218 		if (ftype_table[i].ftype == ftype)
12219 			return ftype_table[i].str;
12220 	}
12221 
12222 	return NULL;
12223 }
12224 
12225 static void
12226 cmd_get_hash_global_config_parsed(void *parsed_result,
12227 				  __rte_unused struct cmdline *cl,
12228 				  __rte_unused void *data)
12229 {
12230 	struct cmd_get_hash_global_config_result *res = parsed_result;
12231 	struct rte_eth_hash_filter_info info;
12232 	uint32_t idx, offset;
12233 	uint16_t i;
12234 	char *str;
12235 	int ret;
12236 
12237 	if (rte_eth_dev_filter_supported(res->port_id,
12238 			RTE_ETH_FILTER_HASH) < 0) {
12239 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12240 							res->port_id);
12241 		return;
12242 	}
12243 
12244 	memset(&info, 0, sizeof(info));
12245 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12246 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12247 					RTE_ETH_FILTER_GET, &info);
12248 	if (ret < 0) {
12249 		printf("Cannot get hash global configurations by port %d\n",
12250 							res->port_id);
12251 		return;
12252 	}
12253 
12254 	switch (info.info.global_conf.hash_func) {
12255 	case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12256 		printf("Hash function is Toeplitz\n");
12257 		break;
12258 	case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12259 		printf("Hash function is Simple XOR\n");
12260 		break;
12261 	default:
12262 		printf("Unknown hash function\n");
12263 		break;
12264 	}
12265 
12266 	for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12267 		idx = i / UINT64_BIT;
12268 		offset = i % UINT64_BIT;
12269 		if (!(info.info.global_conf.valid_bit_mask[idx] &
12270 						(1ULL << offset)))
12271 			continue;
12272 		str = flowtype_to_str(i);
12273 		if (!str)
12274 			continue;
12275 		printf("Symmetric hash is %s globally for flow type %s "
12276 							"by port %d\n",
12277 			((info.info.global_conf.sym_hash_enable_mask[idx] &
12278 			(1ULL << offset)) ? "enabled" : "disabled"), str,
12279 							res->port_id);
12280 	}
12281 }
12282 
12283 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12284 	TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12285 		get_hash_global_config, "get_hash_global_config");
12286 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12287 	TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12288 		port_id, UINT16);
12289 
12290 cmdline_parse_inst_t cmd_get_hash_global_config = {
12291 	.f = cmd_get_hash_global_config_parsed,
12292 	.data = NULL,
12293 	.help_str = "get_hash_global_config <port_id>",
12294 	.tokens = {
12295 		(void *)&cmd_get_hash_global_config_all,
12296 		(void *)&cmd_get_hash_global_config_port_id,
12297 		NULL,
12298 	},
12299 };
12300 
12301 /* Set global config of hash function */
12302 struct cmd_set_hash_global_config_result {
12303 	cmdline_fixed_string_t set_hash_global_config;
12304 	portid_t port_id;
12305 	cmdline_fixed_string_t hash_func;
12306 	cmdline_fixed_string_t flow_type;
12307 	cmdline_fixed_string_t enable;
12308 };
12309 
12310 static void
12311 cmd_set_hash_global_config_parsed(void *parsed_result,
12312 				  __rte_unused struct cmdline *cl,
12313 				  __rte_unused void *data)
12314 {
12315 	struct cmd_set_hash_global_config_result *res = parsed_result;
12316 	struct rte_eth_hash_filter_info info;
12317 	uint32_t ftype, idx, offset;
12318 	int ret;
12319 
12320 	if (rte_eth_dev_filter_supported(res->port_id,
12321 				RTE_ETH_FILTER_HASH) < 0) {
12322 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12323 							res->port_id);
12324 		return;
12325 	}
12326 	memset(&info, 0, sizeof(info));
12327 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12328 	if (!strcmp(res->hash_func, "toeplitz"))
12329 		info.info.global_conf.hash_func =
12330 			RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12331 	else if (!strcmp(res->hash_func, "simple_xor"))
12332 		info.info.global_conf.hash_func =
12333 			RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12334 	else if (!strcmp(res->hash_func, "default"))
12335 		info.info.global_conf.hash_func =
12336 			RTE_ETH_HASH_FUNCTION_DEFAULT;
12337 
12338 	ftype = str2flowtype(res->flow_type);
12339 	idx = ftype / UINT64_BIT;
12340 	offset = ftype % UINT64_BIT;
12341 	info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12342 	if (!strcmp(res->enable, "enable"))
12343 		info.info.global_conf.sym_hash_enable_mask[idx] |=
12344 						(1ULL << offset);
12345 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12346 					RTE_ETH_FILTER_SET, &info);
12347 	if (ret < 0)
12348 		printf("Cannot set global hash configurations by port %d\n",
12349 							res->port_id);
12350 	else
12351 		printf("Global hash configurations have been set "
12352 			"successfully by port %d\n", res->port_id);
12353 }
12354 
12355 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12356 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12357 		set_hash_global_config, "set_hash_global_config");
12358 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12359 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12360 		port_id, UINT16);
12361 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12362 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12363 		hash_func, "toeplitz#simple_xor#default");
12364 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12365 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12366 		flow_type,
12367 		"ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12368 		"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12369 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12370 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12371 		enable, "enable#disable");
12372 
12373 cmdline_parse_inst_t cmd_set_hash_global_config = {
12374 	.f = cmd_set_hash_global_config_parsed,
12375 	.data = NULL,
12376 	.help_str = "set_hash_global_config <port_id> "
12377 		"toeplitz|simple_xor|default "
12378 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12379 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12380 		"l2_payload enable|disable",
12381 	.tokens = {
12382 		(void *)&cmd_set_hash_global_config_all,
12383 		(void *)&cmd_set_hash_global_config_port_id,
12384 		(void *)&cmd_set_hash_global_config_hash_func,
12385 		(void *)&cmd_set_hash_global_config_flow_type,
12386 		(void *)&cmd_set_hash_global_config_enable,
12387 		NULL,
12388 	},
12389 };
12390 
12391 /* Set hash input set */
12392 struct cmd_set_hash_input_set_result {
12393 	cmdline_fixed_string_t set_hash_input_set;
12394 	portid_t port_id;
12395 	cmdline_fixed_string_t flow_type;
12396 	cmdline_fixed_string_t inset_field;
12397 	cmdline_fixed_string_t select;
12398 };
12399 
12400 static enum rte_eth_input_set_field
12401 str2inset(char *string)
12402 {
12403 	uint16_t i;
12404 
12405 	static const struct {
12406 		char str[32];
12407 		enum rte_eth_input_set_field inset;
12408 	} inset_table[] = {
12409 		{"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12410 		{"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12411 		{"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12412 		{"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12413 		{"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12414 		{"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12415 		{"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12416 		{"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12417 		{"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12418 		{"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12419 		{"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12420 		{"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12421 		{"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12422 		{"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12423 		{"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12424 		{"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12425 		{"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12426 		{"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12427 		{"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12428 		{"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12429 		{"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12430 		{"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12431 		{"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12432 		{"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12433 		{"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12434 		{"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12435 		{"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12436 		{"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12437 		{"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12438 		{"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12439 		{"none", RTE_ETH_INPUT_SET_NONE},
12440 	};
12441 
12442 	for (i = 0; i < RTE_DIM(inset_table); i++) {
12443 		if (!strcmp(string, inset_table[i].str))
12444 			return inset_table[i].inset;
12445 	}
12446 
12447 	return RTE_ETH_INPUT_SET_UNKNOWN;
12448 }
12449 
12450 static void
12451 cmd_set_hash_input_set_parsed(void *parsed_result,
12452 			      __rte_unused struct cmdline *cl,
12453 			      __rte_unused void *data)
12454 {
12455 	struct cmd_set_hash_input_set_result *res = parsed_result;
12456 	struct rte_eth_hash_filter_info info;
12457 
12458 	memset(&info, 0, sizeof(info));
12459 	info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12460 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12461 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12462 	info.info.input_set_conf.inset_size = 1;
12463 	if (!strcmp(res->select, "select"))
12464 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12465 	else if (!strcmp(res->select, "add"))
12466 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12467 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12468 				RTE_ETH_FILTER_SET, &info);
12469 }
12470 
12471 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12472 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12473 		set_hash_input_set, "set_hash_input_set");
12474 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12475 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12476 		port_id, UINT16);
12477 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12478 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12479 		flow_type, NULL);
12480 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12481 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12482 		inset_field,
12483 		"ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12484 		"ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12485 		"udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12486 		"sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12487 		"fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12488 		"fld-8th#none");
12489 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12490 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12491 		select, "select#add");
12492 
12493 cmdline_parse_inst_t cmd_set_hash_input_set = {
12494 	.f = cmd_set_hash_input_set_parsed,
12495 	.data = NULL,
12496 	.help_str = "set_hash_input_set <port_id> "
12497 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12498 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12499 	"ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12500 	"ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12501 	"tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12502 	"gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12503 	"fld-7th|fld-8th|none select|add",
12504 	.tokens = {
12505 		(void *)&cmd_set_hash_input_set_cmd,
12506 		(void *)&cmd_set_hash_input_set_port_id,
12507 		(void *)&cmd_set_hash_input_set_flow_type,
12508 		(void *)&cmd_set_hash_input_set_field,
12509 		(void *)&cmd_set_hash_input_set_select,
12510 		NULL,
12511 	},
12512 };
12513 
12514 /* Set flow director input set */
12515 struct cmd_set_fdir_input_set_result {
12516 	cmdline_fixed_string_t set_fdir_input_set;
12517 	portid_t port_id;
12518 	cmdline_fixed_string_t flow_type;
12519 	cmdline_fixed_string_t inset_field;
12520 	cmdline_fixed_string_t select;
12521 };
12522 
12523 static void
12524 cmd_set_fdir_input_set_parsed(void *parsed_result,
12525 	__rte_unused struct cmdline *cl,
12526 	__rte_unused void *data)
12527 {
12528 	struct cmd_set_fdir_input_set_result *res = parsed_result;
12529 	struct rte_eth_fdir_filter_info info;
12530 
12531 	memset(&info, 0, sizeof(info));
12532 	info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12533 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12534 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12535 	info.info.input_set_conf.inset_size = 1;
12536 	if (!strcmp(res->select, "select"))
12537 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12538 	else if (!strcmp(res->select, "add"))
12539 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12540 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12541 		RTE_ETH_FILTER_SET, &info);
12542 }
12543 
12544 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12545 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12546 	set_fdir_input_set, "set_fdir_input_set");
12547 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12548 	TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12549 	port_id, UINT16);
12550 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12551 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12552 	flow_type,
12553 	"ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12554 	"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12555 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12556 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12557 	inset_field,
12558 	"ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12559 	"ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12560 	"ipv6-hop-limits#udp-src-port#udp-dst-port#"
12561 	"tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12562 	"sctp-veri-tag#none");
12563 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12564 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12565 	select, "select#add");
12566 
12567 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12568 	.f = cmd_set_fdir_input_set_parsed,
12569 	.data = NULL,
12570 	.help_str = "set_fdir_input_set <port_id> "
12571 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12572 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12573 	"ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12574 	"ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12575 	"ipv6-hop-limits|udp-src-port|udp-dst-port|"
12576 	"tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12577 	"sctp-veri-tag|none select|add",
12578 	.tokens = {
12579 		(void *)&cmd_set_fdir_input_set_cmd,
12580 		(void *)&cmd_set_fdir_input_set_port_id,
12581 		(void *)&cmd_set_fdir_input_set_flow_type,
12582 		(void *)&cmd_set_fdir_input_set_field,
12583 		(void *)&cmd_set_fdir_input_set_select,
12584 		NULL,
12585 	},
12586 };
12587 
12588 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12589 struct cmd_mcast_addr_result {
12590 	cmdline_fixed_string_t mcast_addr_cmd;
12591 	cmdline_fixed_string_t what;
12592 	uint16_t port_num;
12593 	struct rte_ether_addr mc_addr;
12594 };
12595 
12596 static void cmd_mcast_addr_parsed(void *parsed_result,
12597 		__attribute__((unused)) struct cmdline *cl,
12598 		__attribute__((unused)) void *data)
12599 {
12600 	struct cmd_mcast_addr_result *res = parsed_result;
12601 
12602 	if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12603 		printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12604 		       res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12605 		       res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12606 		       res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12607 		return;
12608 	}
12609 	if (strcmp(res->what, "add") == 0)
12610 		mcast_addr_add(res->port_num, &res->mc_addr);
12611 	else
12612 		mcast_addr_remove(res->port_num, &res->mc_addr);
12613 }
12614 
12615 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12616 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12617 				 mcast_addr_cmd, "mcast_addr");
12618 cmdline_parse_token_string_t cmd_mcast_addr_what =
12619 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12620 				 "add#remove");
12621 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12622 	TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12623 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12624 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12625 
12626 cmdline_parse_inst_t cmd_mcast_addr = {
12627 	.f = cmd_mcast_addr_parsed,
12628 	.data = (void *)0,
12629 	.help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12630 		"Add/Remove multicast MAC address on port_id",
12631 	.tokens = {
12632 		(void *)&cmd_mcast_addr_cmd,
12633 		(void *)&cmd_mcast_addr_what,
12634 		(void *)&cmd_mcast_addr_portnum,
12635 		(void *)&cmd_mcast_addr_addr,
12636 		NULL,
12637 	},
12638 };
12639 
12640 /* l2 tunnel config
12641  * only support E-tag now.
12642  */
12643 
12644 /* Ether type config */
12645 struct cmd_config_l2_tunnel_eth_type_result {
12646 	cmdline_fixed_string_t port;
12647 	cmdline_fixed_string_t config;
12648 	cmdline_fixed_string_t all;
12649 	portid_t id;
12650 	cmdline_fixed_string_t l2_tunnel;
12651 	cmdline_fixed_string_t l2_tunnel_type;
12652 	cmdline_fixed_string_t eth_type;
12653 	uint16_t eth_type_val;
12654 };
12655 
12656 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12657 	TOKEN_STRING_INITIALIZER
12658 		(struct cmd_config_l2_tunnel_eth_type_result,
12659 		 port, "port");
12660 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12661 	TOKEN_STRING_INITIALIZER
12662 		(struct cmd_config_l2_tunnel_eth_type_result,
12663 		 config, "config");
12664 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12665 	TOKEN_STRING_INITIALIZER
12666 		(struct cmd_config_l2_tunnel_eth_type_result,
12667 		 all, "all");
12668 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12669 	TOKEN_NUM_INITIALIZER
12670 		(struct cmd_config_l2_tunnel_eth_type_result,
12671 		 id, UINT16);
12672 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12673 	TOKEN_STRING_INITIALIZER
12674 		(struct cmd_config_l2_tunnel_eth_type_result,
12675 		 l2_tunnel, "l2-tunnel");
12676 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12677 	TOKEN_STRING_INITIALIZER
12678 		(struct cmd_config_l2_tunnel_eth_type_result,
12679 		 l2_tunnel_type, "E-tag");
12680 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12681 	TOKEN_STRING_INITIALIZER
12682 		(struct cmd_config_l2_tunnel_eth_type_result,
12683 		 eth_type, "ether-type");
12684 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12685 	TOKEN_NUM_INITIALIZER
12686 		(struct cmd_config_l2_tunnel_eth_type_result,
12687 		 eth_type_val, UINT16);
12688 
12689 static enum rte_eth_tunnel_type
12690 str2fdir_l2_tunnel_type(char *string)
12691 {
12692 	uint32_t i = 0;
12693 
12694 	static const struct {
12695 		char str[32];
12696 		enum rte_eth_tunnel_type type;
12697 	} l2_tunnel_type_str[] = {
12698 		{"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12699 	};
12700 
12701 	for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12702 		if (!strcmp(l2_tunnel_type_str[i].str, string))
12703 			return l2_tunnel_type_str[i].type;
12704 	}
12705 	return RTE_TUNNEL_TYPE_NONE;
12706 }
12707 
12708 /* ether type config for all ports */
12709 static void
12710 cmd_config_l2_tunnel_eth_type_all_parsed
12711 	(void *parsed_result,
12712 	 __attribute__((unused)) struct cmdline *cl,
12713 	 __attribute__((unused)) void *data)
12714 {
12715 	struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12716 	struct rte_eth_l2_tunnel_conf entry;
12717 	portid_t pid;
12718 
12719 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12720 	entry.ether_type = res->eth_type_val;
12721 
12722 	RTE_ETH_FOREACH_DEV(pid) {
12723 		rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12724 	}
12725 }
12726 
12727 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12728 	.f = cmd_config_l2_tunnel_eth_type_all_parsed,
12729 	.data = NULL,
12730 	.help_str = "port config all l2-tunnel E-tag ether-type <value>",
12731 	.tokens = {
12732 		(void *)&cmd_config_l2_tunnel_eth_type_port,
12733 		(void *)&cmd_config_l2_tunnel_eth_type_config,
12734 		(void *)&cmd_config_l2_tunnel_eth_type_all_str,
12735 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12736 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12737 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12738 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12739 		NULL,
12740 	},
12741 };
12742 
12743 /* ether type config for a specific port */
12744 static void
12745 cmd_config_l2_tunnel_eth_type_specific_parsed(
12746 	void *parsed_result,
12747 	__attribute__((unused)) struct cmdline *cl,
12748 	__attribute__((unused)) void *data)
12749 {
12750 	struct cmd_config_l2_tunnel_eth_type_result *res =
12751 		 parsed_result;
12752 	struct rte_eth_l2_tunnel_conf entry;
12753 
12754 	if (port_id_is_invalid(res->id, ENABLED_WARN))
12755 		return;
12756 
12757 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12758 	entry.ether_type = res->eth_type_val;
12759 
12760 	rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12761 }
12762 
12763 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12764 	.f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12765 	.data = NULL,
12766 	.help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12767 	.tokens = {
12768 		(void *)&cmd_config_l2_tunnel_eth_type_port,
12769 		(void *)&cmd_config_l2_tunnel_eth_type_config,
12770 		(void *)&cmd_config_l2_tunnel_eth_type_id,
12771 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12772 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12773 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12774 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12775 		NULL,
12776 	},
12777 };
12778 
12779 /* Enable/disable l2 tunnel */
12780 struct cmd_config_l2_tunnel_en_dis_result {
12781 	cmdline_fixed_string_t port;
12782 	cmdline_fixed_string_t config;
12783 	cmdline_fixed_string_t all;
12784 	portid_t id;
12785 	cmdline_fixed_string_t l2_tunnel;
12786 	cmdline_fixed_string_t l2_tunnel_type;
12787 	cmdline_fixed_string_t en_dis;
12788 };
12789 
12790 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12791 	TOKEN_STRING_INITIALIZER
12792 		(struct cmd_config_l2_tunnel_en_dis_result,
12793 		 port, "port");
12794 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12795 	TOKEN_STRING_INITIALIZER
12796 		(struct cmd_config_l2_tunnel_en_dis_result,
12797 		 config, "config");
12798 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12799 	TOKEN_STRING_INITIALIZER
12800 		(struct cmd_config_l2_tunnel_en_dis_result,
12801 		 all, "all");
12802 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12803 	TOKEN_NUM_INITIALIZER
12804 		(struct cmd_config_l2_tunnel_en_dis_result,
12805 		 id, UINT16);
12806 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12807 	TOKEN_STRING_INITIALIZER
12808 		(struct cmd_config_l2_tunnel_en_dis_result,
12809 		 l2_tunnel, "l2-tunnel");
12810 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12811 	TOKEN_STRING_INITIALIZER
12812 		(struct cmd_config_l2_tunnel_en_dis_result,
12813 		 l2_tunnel_type, "E-tag");
12814 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12815 	TOKEN_STRING_INITIALIZER
12816 		(struct cmd_config_l2_tunnel_en_dis_result,
12817 		 en_dis, "enable#disable");
12818 
12819 /* enable/disable l2 tunnel for all ports */
12820 static void
12821 cmd_config_l2_tunnel_en_dis_all_parsed(
12822 	void *parsed_result,
12823 	__attribute__((unused)) struct cmdline *cl,
12824 	__attribute__((unused)) void *data)
12825 {
12826 	struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12827 	struct rte_eth_l2_tunnel_conf entry;
12828 	portid_t pid;
12829 	uint8_t en;
12830 
12831 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12832 
12833 	if (!strcmp("enable", res->en_dis))
12834 		en = 1;
12835 	else
12836 		en = 0;
12837 
12838 	RTE_ETH_FOREACH_DEV(pid) {
12839 		rte_eth_dev_l2_tunnel_offload_set(pid,
12840 						  &entry,
12841 						  ETH_L2_TUNNEL_ENABLE_MASK,
12842 						  en);
12843 	}
12844 }
12845 
12846 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12847 	.f = cmd_config_l2_tunnel_en_dis_all_parsed,
12848 	.data = NULL,
12849 	.help_str = "port config all l2-tunnel E-tag enable|disable",
12850 	.tokens = {
12851 		(void *)&cmd_config_l2_tunnel_en_dis_port,
12852 		(void *)&cmd_config_l2_tunnel_en_dis_config,
12853 		(void *)&cmd_config_l2_tunnel_en_dis_all_str,
12854 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12855 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12856 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12857 		NULL,
12858 	},
12859 };
12860 
12861 /* enable/disable l2 tunnel for a port */
12862 static void
12863 cmd_config_l2_tunnel_en_dis_specific_parsed(
12864 	void *parsed_result,
12865 	__attribute__((unused)) struct cmdline *cl,
12866 	__attribute__((unused)) void *data)
12867 {
12868 	struct cmd_config_l2_tunnel_en_dis_result *res =
12869 		parsed_result;
12870 	struct rte_eth_l2_tunnel_conf entry;
12871 
12872 	if (port_id_is_invalid(res->id, ENABLED_WARN))
12873 		return;
12874 
12875 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12876 
12877 	if (!strcmp("enable", res->en_dis))
12878 		rte_eth_dev_l2_tunnel_offload_set(res->id,
12879 						  &entry,
12880 						  ETH_L2_TUNNEL_ENABLE_MASK,
12881 						  1);
12882 	else
12883 		rte_eth_dev_l2_tunnel_offload_set(res->id,
12884 						  &entry,
12885 						  ETH_L2_TUNNEL_ENABLE_MASK,
12886 						  0);
12887 }
12888 
12889 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12890 	.f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12891 	.data = NULL,
12892 	.help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12893 	.tokens = {
12894 		(void *)&cmd_config_l2_tunnel_en_dis_port,
12895 		(void *)&cmd_config_l2_tunnel_en_dis_config,
12896 		(void *)&cmd_config_l2_tunnel_en_dis_id,
12897 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12898 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12899 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12900 		NULL,
12901 	},
12902 };
12903 
12904 /* E-tag configuration */
12905 
12906 /* Common result structure for all E-tag configuration */
12907 struct cmd_config_e_tag_result {
12908 	cmdline_fixed_string_t e_tag;
12909 	cmdline_fixed_string_t set;
12910 	cmdline_fixed_string_t insertion;
12911 	cmdline_fixed_string_t stripping;
12912 	cmdline_fixed_string_t forwarding;
12913 	cmdline_fixed_string_t filter;
12914 	cmdline_fixed_string_t add;
12915 	cmdline_fixed_string_t del;
12916 	cmdline_fixed_string_t on;
12917 	cmdline_fixed_string_t off;
12918 	cmdline_fixed_string_t on_off;
12919 	cmdline_fixed_string_t port_tag_id;
12920 	uint32_t port_tag_id_val;
12921 	cmdline_fixed_string_t e_tag_id;
12922 	uint16_t e_tag_id_val;
12923 	cmdline_fixed_string_t dst_pool;
12924 	uint8_t dst_pool_val;
12925 	cmdline_fixed_string_t port;
12926 	portid_t port_id;
12927 	cmdline_fixed_string_t vf;
12928 	uint8_t vf_id;
12929 };
12930 
12931 /* Common CLI fields for all E-tag configuration */
12932 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12933 	TOKEN_STRING_INITIALIZER
12934 		(struct cmd_config_e_tag_result,
12935 		 e_tag, "E-tag");
12936 cmdline_parse_token_string_t cmd_config_e_tag_set =
12937 	TOKEN_STRING_INITIALIZER
12938 		(struct cmd_config_e_tag_result,
12939 		 set, "set");
12940 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12941 	TOKEN_STRING_INITIALIZER
12942 		(struct cmd_config_e_tag_result,
12943 		 insertion, "insertion");
12944 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12945 	TOKEN_STRING_INITIALIZER
12946 		(struct cmd_config_e_tag_result,
12947 		 stripping, "stripping");
12948 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12949 	TOKEN_STRING_INITIALIZER
12950 		(struct cmd_config_e_tag_result,
12951 		 forwarding, "forwarding");
12952 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12953 	TOKEN_STRING_INITIALIZER
12954 		(struct cmd_config_e_tag_result,
12955 		 filter, "filter");
12956 cmdline_parse_token_string_t cmd_config_e_tag_add =
12957 	TOKEN_STRING_INITIALIZER
12958 		(struct cmd_config_e_tag_result,
12959 		 add, "add");
12960 cmdline_parse_token_string_t cmd_config_e_tag_del =
12961 	TOKEN_STRING_INITIALIZER
12962 		(struct cmd_config_e_tag_result,
12963 		 del, "del");
12964 cmdline_parse_token_string_t cmd_config_e_tag_on =
12965 	TOKEN_STRING_INITIALIZER
12966 		(struct cmd_config_e_tag_result,
12967 		 on, "on");
12968 cmdline_parse_token_string_t cmd_config_e_tag_off =
12969 	TOKEN_STRING_INITIALIZER
12970 		(struct cmd_config_e_tag_result,
12971 		 off, "off");
12972 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12973 	TOKEN_STRING_INITIALIZER
12974 		(struct cmd_config_e_tag_result,
12975 		 on_off, "on#off");
12976 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12977 	TOKEN_STRING_INITIALIZER
12978 		(struct cmd_config_e_tag_result,
12979 		 port_tag_id, "port-tag-id");
12980 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12981 	TOKEN_NUM_INITIALIZER
12982 		(struct cmd_config_e_tag_result,
12983 		 port_tag_id_val, UINT32);
12984 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12985 	TOKEN_STRING_INITIALIZER
12986 		(struct cmd_config_e_tag_result,
12987 		 e_tag_id, "e-tag-id");
12988 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12989 	TOKEN_NUM_INITIALIZER
12990 		(struct cmd_config_e_tag_result,
12991 		 e_tag_id_val, UINT16);
12992 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12993 	TOKEN_STRING_INITIALIZER
12994 		(struct cmd_config_e_tag_result,
12995 		 dst_pool, "dst-pool");
12996 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12997 	TOKEN_NUM_INITIALIZER
12998 		(struct cmd_config_e_tag_result,
12999 		 dst_pool_val, UINT8);
13000 cmdline_parse_token_string_t cmd_config_e_tag_port =
13001 	TOKEN_STRING_INITIALIZER
13002 		(struct cmd_config_e_tag_result,
13003 		 port, "port");
13004 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13005 	TOKEN_NUM_INITIALIZER
13006 		(struct cmd_config_e_tag_result,
13007 		 port_id, UINT16);
13008 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13009 	TOKEN_STRING_INITIALIZER
13010 		(struct cmd_config_e_tag_result,
13011 		 vf, "vf");
13012 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13013 	TOKEN_NUM_INITIALIZER
13014 		(struct cmd_config_e_tag_result,
13015 		 vf_id, UINT8);
13016 
13017 /* E-tag insertion configuration */
13018 static void
13019 cmd_config_e_tag_insertion_en_parsed(
13020 	void *parsed_result,
13021 	__attribute__((unused)) struct cmdline *cl,
13022 	__attribute__((unused)) void *data)
13023 {
13024 	struct cmd_config_e_tag_result *res =
13025 		parsed_result;
13026 	struct rte_eth_l2_tunnel_conf entry;
13027 
13028 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13029 		return;
13030 
13031 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13032 	entry.tunnel_id = res->port_tag_id_val;
13033 	entry.vf_id = res->vf_id;
13034 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13035 					  &entry,
13036 					  ETH_L2_TUNNEL_INSERTION_MASK,
13037 					  1);
13038 }
13039 
13040 static void
13041 cmd_config_e_tag_insertion_dis_parsed(
13042 	void *parsed_result,
13043 	__attribute__((unused)) struct cmdline *cl,
13044 	__attribute__((unused)) void *data)
13045 {
13046 	struct cmd_config_e_tag_result *res =
13047 		parsed_result;
13048 	struct rte_eth_l2_tunnel_conf entry;
13049 
13050 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13051 		return;
13052 
13053 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13054 	entry.vf_id = res->vf_id;
13055 
13056 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13057 					  &entry,
13058 					  ETH_L2_TUNNEL_INSERTION_MASK,
13059 					  0);
13060 }
13061 
13062 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13063 	.f = cmd_config_e_tag_insertion_en_parsed,
13064 	.data = NULL,
13065 	.help_str = "E-tag ... : E-tag insertion enable",
13066 	.tokens = {
13067 		(void *)&cmd_config_e_tag_e_tag,
13068 		(void *)&cmd_config_e_tag_set,
13069 		(void *)&cmd_config_e_tag_insertion,
13070 		(void *)&cmd_config_e_tag_on,
13071 		(void *)&cmd_config_e_tag_port_tag_id,
13072 		(void *)&cmd_config_e_tag_port_tag_id_val,
13073 		(void *)&cmd_config_e_tag_port,
13074 		(void *)&cmd_config_e_tag_port_id,
13075 		(void *)&cmd_config_e_tag_vf,
13076 		(void *)&cmd_config_e_tag_vf_id,
13077 		NULL,
13078 	},
13079 };
13080 
13081 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13082 	.f = cmd_config_e_tag_insertion_dis_parsed,
13083 	.data = NULL,
13084 	.help_str = "E-tag ... : E-tag insertion disable",
13085 	.tokens = {
13086 		(void *)&cmd_config_e_tag_e_tag,
13087 		(void *)&cmd_config_e_tag_set,
13088 		(void *)&cmd_config_e_tag_insertion,
13089 		(void *)&cmd_config_e_tag_off,
13090 		(void *)&cmd_config_e_tag_port,
13091 		(void *)&cmd_config_e_tag_port_id,
13092 		(void *)&cmd_config_e_tag_vf,
13093 		(void *)&cmd_config_e_tag_vf_id,
13094 		NULL,
13095 	},
13096 };
13097 
13098 /* E-tag stripping configuration */
13099 static void
13100 cmd_config_e_tag_stripping_parsed(
13101 	void *parsed_result,
13102 	__attribute__((unused)) struct cmdline *cl,
13103 	__attribute__((unused)) void *data)
13104 {
13105 	struct cmd_config_e_tag_result *res =
13106 		parsed_result;
13107 	struct rte_eth_l2_tunnel_conf entry;
13108 
13109 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13110 		return;
13111 
13112 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13113 
13114 	if (!strcmp(res->on_off, "on"))
13115 		rte_eth_dev_l2_tunnel_offload_set
13116 			(res->port_id,
13117 			 &entry,
13118 			 ETH_L2_TUNNEL_STRIPPING_MASK,
13119 			 1);
13120 	else
13121 		rte_eth_dev_l2_tunnel_offload_set
13122 			(res->port_id,
13123 			 &entry,
13124 			 ETH_L2_TUNNEL_STRIPPING_MASK,
13125 			 0);
13126 }
13127 
13128 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13129 	.f = cmd_config_e_tag_stripping_parsed,
13130 	.data = NULL,
13131 	.help_str = "E-tag ... : E-tag stripping enable/disable",
13132 	.tokens = {
13133 		(void *)&cmd_config_e_tag_e_tag,
13134 		(void *)&cmd_config_e_tag_set,
13135 		(void *)&cmd_config_e_tag_stripping,
13136 		(void *)&cmd_config_e_tag_on_off,
13137 		(void *)&cmd_config_e_tag_port,
13138 		(void *)&cmd_config_e_tag_port_id,
13139 		NULL,
13140 	},
13141 };
13142 
13143 /* E-tag forwarding configuration */
13144 static void
13145 cmd_config_e_tag_forwarding_parsed(
13146 	void *parsed_result,
13147 	__attribute__((unused)) struct cmdline *cl,
13148 	__attribute__((unused)) void *data)
13149 {
13150 	struct cmd_config_e_tag_result *res = parsed_result;
13151 	struct rte_eth_l2_tunnel_conf entry;
13152 
13153 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13154 		return;
13155 
13156 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13157 
13158 	if (!strcmp(res->on_off, "on"))
13159 		rte_eth_dev_l2_tunnel_offload_set
13160 			(res->port_id,
13161 			 &entry,
13162 			 ETH_L2_TUNNEL_FORWARDING_MASK,
13163 			 1);
13164 	else
13165 		rte_eth_dev_l2_tunnel_offload_set
13166 			(res->port_id,
13167 			 &entry,
13168 			 ETH_L2_TUNNEL_FORWARDING_MASK,
13169 			 0);
13170 }
13171 
13172 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13173 	.f = cmd_config_e_tag_forwarding_parsed,
13174 	.data = NULL,
13175 	.help_str = "E-tag ... : E-tag forwarding enable/disable",
13176 	.tokens = {
13177 		(void *)&cmd_config_e_tag_e_tag,
13178 		(void *)&cmd_config_e_tag_set,
13179 		(void *)&cmd_config_e_tag_forwarding,
13180 		(void *)&cmd_config_e_tag_on_off,
13181 		(void *)&cmd_config_e_tag_port,
13182 		(void *)&cmd_config_e_tag_port_id,
13183 		NULL,
13184 	},
13185 };
13186 
13187 /* E-tag filter configuration */
13188 static void
13189 cmd_config_e_tag_filter_add_parsed(
13190 	void *parsed_result,
13191 	__attribute__((unused)) struct cmdline *cl,
13192 	__attribute__((unused)) void *data)
13193 {
13194 	struct cmd_config_e_tag_result *res = parsed_result;
13195 	struct rte_eth_l2_tunnel_conf entry;
13196 	int ret = 0;
13197 
13198 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13199 		return;
13200 
13201 	if (res->e_tag_id_val > 0x3fff) {
13202 		printf("e-tag-id must be equal or less than 0x3fff.\n");
13203 		return;
13204 	}
13205 
13206 	ret = rte_eth_dev_filter_supported(res->port_id,
13207 					   RTE_ETH_FILTER_L2_TUNNEL);
13208 	if (ret < 0) {
13209 		printf("E-tag filter is not supported on port %u.\n",
13210 		       res->port_id);
13211 		return;
13212 	}
13213 
13214 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13215 	entry.tunnel_id = res->e_tag_id_val;
13216 	entry.pool = res->dst_pool_val;
13217 
13218 	ret = rte_eth_dev_filter_ctrl(res->port_id,
13219 				      RTE_ETH_FILTER_L2_TUNNEL,
13220 				      RTE_ETH_FILTER_ADD,
13221 				      &entry);
13222 	if (ret < 0)
13223 		printf("E-tag filter programming error: (%s)\n",
13224 		       strerror(-ret));
13225 }
13226 
13227 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13228 	.f = cmd_config_e_tag_filter_add_parsed,
13229 	.data = NULL,
13230 	.help_str = "E-tag ... : E-tag filter add",
13231 	.tokens = {
13232 		(void *)&cmd_config_e_tag_e_tag,
13233 		(void *)&cmd_config_e_tag_set,
13234 		(void *)&cmd_config_e_tag_filter,
13235 		(void *)&cmd_config_e_tag_add,
13236 		(void *)&cmd_config_e_tag_e_tag_id,
13237 		(void *)&cmd_config_e_tag_e_tag_id_val,
13238 		(void *)&cmd_config_e_tag_dst_pool,
13239 		(void *)&cmd_config_e_tag_dst_pool_val,
13240 		(void *)&cmd_config_e_tag_port,
13241 		(void *)&cmd_config_e_tag_port_id,
13242 		NULL,
13243 	},
13244 };
13245 
13246 static void
13247 cmd_config_e_tag_filter_del_parsed(
13248 	void *parsed_result,
13249 	__attribute__((unused)) struct cmdline *cl,
13250 	__attribute__((unused)) void *data)
13251 {
13252 	struct cmd_config_e_tag_result *res = parsed_result;
13253 	struct rte_eth_l2_tunnel_conf entry;
13254 	int ret = 0;
13255 
13256 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13257 		return;
13258 
13259 	if (res->e_tag_id_val > 0x3fff) {
13260 		printf("e-tag-id must be less than 0x3fff.\n");
13261 		return;
13262 	}
13263 
13264 	ret = rte_eth_dev_filter_supported(res->port_id,
13265 					   RTE_ETH_FILTER_L2_TUNNEL);
13266 	if (ret < 0) {
13267 		printf("E-tag filter is not supported on port %u.\n",
13268 		       res->port_id);
13269 		return;
13270 	}
13271 
13272 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13273 	entry.tunnel_id = res->e_tag_id_val;
13274 
13275 	ret = rte_eth_dev_filter_ctrl(res->port_id,
13276 				      RTE_ETH_FILTER_L2_TUNNEL,
13277 				      RTE_ETH_FILTER_DELETE,
13278 				      &entry);
13279 	if (ret < 0)
13280 		printf("E-tag filter programming error: (%s)\n",
13281 		       strerror(-ret));
13282 }
13283 
13284 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13285 	.f = cmd_config_e_tag_filter_del_parsed,
13286 	.data = NULL,
13287 	.help_str = "E-tag ... : E-tag filter delete",
13288 	.tokens = {
13289 		(void *)&cmd_config_e_tag_e_tag,
13290 		(void *)&cmd_config_e_tag_set,
13291 		(void *)&cmd_config_e_tag_filter,
13292 		(void *)&cmd_config_e_tag_del,
13293 		(void *)&cmd_config_e_tag_e_tag_id,
13294 		(void *)&cmd_config_e_tag_e_tag_id_val,
13295 		(void *)&cmd_config_e_tag_port,
13296 		(void *)&cmd_config_e_tag_port_id,
13297 		NULL,
13298 	},
13299 };
13300 
13301 /* vf vlan anti spoof configuration */
13302 
13303 /* Common result structure for vf vlan anti spoof */
13304 struct cmd_vf_vlan_anti_spoof_result {
13305 	cmdline_fixed_string_t set;
13306 	cmdline_fixed_string_t vf;
13307 	cmdline_fixed_string_t vlan;
13308 	cmdline_fixed_string_t antispoof;
13309 	portid_t port_id;
13310 	uint32_t vf_id;
13311 	cmdline_fixed_string_t on_off;
13312 };
13313 
13314 /* Common CLI fields for vf vlan anti spoof enable disable */
13315 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13316 	TOKEN_STRING_INITIALIZER
13317 		(struct cmd_vf_vlan_anti_spoof_result,
13318 		 set, "set");
13319 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13320 	TOKEN_STRING_INITIALIZER
13321 		(struct cmd_vf_vlan_anti_spoof_result,
13322 		 vf, "vf");
13323 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13324 	TOKEN_STRING_INITIALIZER
13325 		(struct cmd_vf_vlan_anti_spoof_result,
13326 		 vlan, "vlan");
13327 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13328 	TOKEN_STRING_INITIALIZER
13329 		(struct cmd_vf_vlan_anti_spoof_result,
13330 		 antispoof, "antispoof");
13331 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13332 	TOKEN_NUM_INITIALIZER
13333 		(struct cmd_vf_vlan_anti_spoof_result,
13334 		 port_id, UINT16);
13335 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13336 	TOKEN_NUM_INITIALIZER
13337 		(struct cmd_vf_vlan_anti_spoof_result,
13338 		 vf_id, UINT32);
13339 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13340 	TOKEN_STRING_INITIALIZER
13341 		(struct cmd_vf_vlan_anti_spoof_result,
13342 		 on_off, "on#off");
13343 
13344 static void
13345 cmd_set_vf_vlan_anti_spoof_parsed(
13346 	void *parsed_result,
13347 	__attribute__((unused)) struct cmdline *cl,
13348 	__attribute__((unused)) void *data)
13349 {
13350 	struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13351 	int ret = -ENOTSUP;
13352 
13353 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13354 
13355 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13356 		return;
13357 
13358 #ifdef RTE_LIBRTE_IXGBE_PMD
13359 	if (ret == -ENOTSUP)
13360 		ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13361 				res->vf_id, is_on);
13362 #endif
13363 #ifdef RTE_LIBRTE_I40E_PMD
13364 	if (ret == -ENOTSUP)
13365 		ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13366 				res->vf_id, is_on);
13367 #endif
13368 #ifdef RTE_LIBRTE_BNXT_PMD
13369 	if (ret == -ENOTSUP)
13370 		ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13371 				res->vf_id, is_on);
13372 #endif
13373 
13374 	switch (ret) {
13375 	case 0:
13376 		break;
13377 	case -EINVAL:
13378 		printf("invalid vf_id %d\n", res->vf_id);
13379 		break;
13380 	case -ENODEV:
13381 		printf("invalid port_id %d\n", res->port_id);
13382 		break;
13383 	case -ENOTSUP:
13384 		printf("function not implemented\n");
13385 		break;
13386 	default:
13387 		printf("programming error: (%s)\n", strerror(-ret));
13388 	}
13389 }
13390 
13391 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13392 	.f = cmd_set_vf_vlan_anti_spoof_parsed,
13393 	.data = NULL,
13394 	.help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13395 	.tokens = {
13396 		(void *)&cmd_vf_vlan_anti_spoof_set,
13397 		(void *)&cmd_vf_vlan_anti_spoof_vf,
13398 		(void *)&cmd_vf_vlan_anti_spoof_vlan,
13399 		(void *)&cmd_vf_vlan_anti_spoof_antispoof,
13400 		(void *)&cmd_vf_vlan_anti_spoof_port_id,
13401 		(void *)&cmd_vf_vlan_anti_spoof_vf_id,
13402 		(void *)&cmd_vf_vlan_anti_spoof_on_off,
13403 		NULL,
13404 	},
13405 };
13406 
13407 /* vf mac anti spoof configuration */
13408 
13409 /* Common result structure for vf mac anti spoof */
13410 struct cmd_vf_mac_anti_spoof_result {
13411 	cmdline_fixed_string_t set;
13412 	cmdline_fixed_string_t vf;
13413 	cmdline_fixed_string_t mac;
13414 	cmdline_fixed_string_t antispoof;
13415 	portid_t port_id;
13416 	uint32_t vf_id;
13417 	cmdline_fixed_string_t on_off;
13418 };
13419 
13420 /* Common CLI fields for vf mac anti spoof enable disable */
13421 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13422 	TOKEN_STRING_INITIALIZER
13423 		(struct cmd_vf_mac_anti_spoof_result,
13424 		 set, "set");
13425 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13426 	TOKEN_STRING_INITIALIZER
13427 		(struct cmd_vf_mac_anti_spoof_result,
13428 		 vf, "vf");
13429 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13430 	TOKEN_STRING_INITIALIZER
13431 		(struct cmd_vf_mac_anti_spoof_result,
13432 		 mac, "mac");
13433 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13434 	TOKEN_STRING_INITIALIZER
13435 		(struct cmd_vf_mac_anti_spoof_result,
13436 		 antispoof, "antispoof");
13437 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13438 	TOKEN_NUM_INITIALIZER
13439 		(struct cmd_vf_mac_anti_spoof_result,
13440 		 port_id, UINT16);
13441 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13442 	TOKEN_NUM_INITIALIZER
13443 		(struct cmd_vf_mac_anti_spoof_result,
13444 		 vf_id, UINT32);
13445 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13446 	TOKEN_STRING_INITIALIZER
13447 		(struct cmd_vf_mac_anti_spoof_result,
13448 		 on_off, "on#off");
13449 
13450 static void
13451 cmd_set_vf_mac_anti_spoof_parsed(
13452 	void *parsed_result,
13453 	__attribute__((unused)) struct cmdline *cl,
13454 	__attribute__((unused)) void *data)
13455 {
13456 	struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13457 	int ret = -ENOTSUP;
13458 
13459 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13460 
13461 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13462 		return;
13463 
13464 #ifdef RTE_LIBRTE_IXGBE_PMD
13465 	if (ret == -ENOTSUP)
13466 		ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13467 			res->vf_id, is_on);
13468 #endif
13469 #ifdef RTE_LIBRTE_I40E_PMD
13470 	if (ret == -ENOTSUP)
13471 		ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13472 			res->vf_id, is_on);
13473 #endif
13474 #ifdef RTE_LIBRTE_BNXT_PMD
13475 	if (ret == -ENOTSUP)
13476 		ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13477 			res->vf_id, is_on);
13478 #endif
13479 
13480 	switch (ret) {
13481 	case 0:
13482 		break;
13483 	case -EINVAL:
13484 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13485 		break;
13486 	case -ENODEV:
13487 		printf("invalid port_id %d\n", res->port_id);
13488 		break;
13489 	case -ENOTSUP:
13490 		printf("function not implemented\n");
13491 		break;
13492 	default:
13493 		printf("programming error: (%s)\n", strerror(-ret));
13494 	}
13495 }
13496 
13497 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13498 	.f = cmd_set_vf_mac_anti_spoof_parsed,
13499 	.data = NULL,
13500 	.help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13501 	.tokens = {
13502 		(void *)&cmd_vf_mac_anti_spoof_set,
13503 		(void *)&cmd_vf_mac_anti_spoof_vf,
13504 		(void *)&cmd_vf_mac_anti_spoof_mac,
13505 		(void *)&cmd_vf_mac_anti_spoof_antispoof,
13506 		(void *)&cmd_vf_mac_anti_spoof_port_id,
13507 		(void *)&cmd_vf_mac_anti_spoof_vf_id,
13508 		(void *)&cmd_vf_mac_anti_spoof_on_off,
13509 		NULL,
13510 	},
13511 };
13512 
13513 /* vf vlan strip queue configuration */
13514 
13515 /* Common result structure for vf mac anti spoof */
13516 struct cmd_vf_vlan_stripq_result {
13517 	cmdline_fixed_string_t set;
13518 	cmdline_fixed_string_t vf;
13519 	cmdline_fixed_string_t vlan;
13520 	cmdline_fixed_string_t stripq;
13521 	portid_t port_id;
13522 	uint16_t vf_id;
13523 	cmdline_fixed_string_t on_off;
13524 };
13525 
13526 /* Common CLI fields for vf vlan strip enable disable */
13527 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13528 	TOKEN_STRING_INITIALIZER
13529 		(struct cmd_vf_vlan_stripq_result,
13530 		 set, "set");
13531 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13532 	TOKEN_STRING_INITIALIZER
13533 		(struct cmd_vf_vlan_stripq_result,
13534 		 vf, "vf");
13535 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13536 	TOKEN_STRING_INITIALIZER
13537 		(struct cmd_vf_vlan_stripq_result,
13538 		 vlan, "vlan");
13539 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13540 	TOKEN_STRING_INITIALIZER
13541 		(struct cmd_vf_vlan_stripq_result,
13542 		 stripq, "stripq");
13543 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13544 	TOKEN_NUM_INITIALIZER
13545 		(struct cmd_vf_vlan_stripq_result,
13546 		 port_id, UINT16);
13547 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13548 	TOKEN_NUM_INITIALIZER
13549 		(struct cmd_vf_vlan_stripq_result,
13550 		 vf_id, UINT16);
13551 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13552 	TOKEN_STRING_INITIALIZER
13553 		(struct cmd_vf_vlan_stripq_result,
13554 		 on_off, "on#off");
13555 
13556 static void
13557 cmd_set_vf_vlan_stripq_parsed(
13558 	void *parsed_result,
13559 	__attribute__((unused)) struct cmdline *cl,
13560 	__attribute__((unused)) void *data)
13561 {
13562 	struct cmd_vf_vlan_stripq_result *res = parsed_result;
13563 	int ret = -ENOTSUP;
13564 
13565 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13566 
13567 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13568 		return;
13569 
13570 #ifdef RTE_LIBRTE_IXGBE_PMD
13571 	if (ret == -ENOTSUP)
13572 		ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13573 			res->vf_id, is_on);
13574 #endif
13575 #ifdef RTE_LIBRTE_I40E_PMD
13576 	if (ret == -ENOTSUP)
13577 		ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13578 			res->vf_id, is_on);
13579 #endif
13580 #ifdef RTE_LIBRTE_BNXT_PMD
13581 	if (ret == -ENOTSUP)
13582 		ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13583 			res->vf_id, is_on);
13584 #endif
13585 
13586 	switch (ret) {
13587 	case 0:
13588 		break;
13589 	case -EINVAL:
13590 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13591 		break;
13592 	case -ENODEV:
13593 		printf("invalid port_id %d\n", res->port_id);
13594 		break;
13595 	case -ENOTSUP:
13596 		printf("function not implemented\n");
13597 		break;
13598 	default:
13599 		printf("programming error: (%s)\n", strerror(-ret));
13600 	}
13601 }
13602 
13603 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13604 	.f = cmd_set_vf_vlan_stripq_parsed,
13605 	.data = NULL,
13606 	.help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13607 	.tokens = {
13608 		(void *)&cmd_vf_vlan_stripq_set,
13609 		(void *)&cmd_vf_vlan_stripq_vf,
13610 		(void *)&cmd_vf_vlan_stripq_vlan,
13611 		(void *)&cmd_vf_vlan_stripq_stripq,
13612 		(void *)&cmd_vf_vlan_stripq_port_id,
13613 		(void *)&cmd_vf_vlan_stripq_vf_id,
13614 		(void *)&cmd_vf_vlan_stripq_on_off,
13615 		NULL,
13616 	},
13617 };
13618 
13619 /* vf vlan insert configuration */
13620 
13621 /* Common result structure for vf vlan insert */
13622 struct cmd_vf_vlan_insert_result {
13623 	cmdline_fixed_string_t set;
13624 	cmdline_fixed_string_t vf;
13625 	cmdline_fixed_string_t vlan;
13626 	cmdline_fixed_string_t insert;
13627 	portid_t port_id;
13628 	uint16_t vf_id;
13629 	uint16_t vlan_id;
13630 };
13631 
13632 /* Common CLI fields for vf vlan insert enable disable */
13633 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13634 	TOKEN_STRING_INITIALIZER
13635 		(struct cmd_vf_vlan_insert_result,
13636 		 set, "set");
13637 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13638 	TOKEN_STRING_INITIALIZER
13639 		(struct cmd_vf_vlan_insert_result,
13640 		 vf, "vf");
13641 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13642 	TOKEN_STRING_INITIALIZER
13643 		(struct cmd_vf_vlan_insert_result,
13644 		 vlan, "vlan");
13645 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13646 	TOKEN_STRING_INITIALIZER
13647 		(struct cmd_vf_vlan_insert_result,
13648 		 insert, "insert");
13649 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13650 	TOKEN_NUM_INITIALIZER
13651 		(struct cmd_vf_vlan_insert_result,
13652 		 port_id, UINT16);
13653 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13654 	TOKEN_NUM_INITIALIZER
13655 		(struct cmd_vf_vlan_insert_result,
13656 		 vf_id, UINT16);
13657 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13658 	TOKEN_NUM_INITIALIZER
13659 		(struct cmd_vf_vlan_insert_result,
13660 		 vlan_id, UINT16);
13661 
13662 static void
13663 cmd_set_vf_vlan_insert_parsed(
13664 	void *parsed_result,
13665 	__attribute__((unused)) struct cmdline *cl,
13666 	__attribute__((unused)) void *data)
13667 {
13668 	struct cmd_vf_vlan_insert_result *res = parsed_result;
13669 	int ret = -ENOTSUP;
13670 
13671 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13672 		return;
13673 
13674 #ifdef RTE_LIBRTE_IXGBE_PMD
13675 	if (ret == -ENOTSUP)
13676 		ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13677 			res->vlan_id);
13678 #endif
13679 #ifdef RTE_LIBRTE_I40E_PMD
13680 	if (ret == -ENOTSUP)
13681 		ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13682 			res->vlan_id);
13683 #endif
13684 #ifdef RTE_LIBRTE_BNXT_PMD
13685 	if (ret == -ENOTSUP)
13686 		ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13687 			res->vlan_id);
13688 #endif
13689 
13690 	switch (ret) {
13691 	case 0:
13692 		break;
13693 	case -EINVAL:
13694 		printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13695 		break;
13696 	case -ENODEV:
13697 		printf("invalid port_id %d\n", res->port_id);
13698 		break;
13699 	case -ENOTSUP:
13700 		printf("function not implemented\n");
13701 		break;
13702 	default:
13703 		printf("programming error: (%s)\n", strerror(-ret));
13704 	}
13705 }
13706 
13707 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13708 	.f = cmd_set_vf_vlan_insert_parsed,
13709 	.data = NULL,
13710 	.help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13711 	.tokens = {
13712 		(void *)&cmd_vf_vlan_insert_set,
13713 		(void *)&cmd_vf_vlan_insert_vf,
13714 		(void *)&cmd_vf_vlan_insert_vlan,
13715 		(void *)&cmd_vf_vlan_insert_insert,
13716 		(void *)&cmd_vf_vlan_insert_port_id,
13717 		(void *)&cmd_vf_vlan_insert_vf_id,
13718 		(void *)&cmd_vf_vlan_insert_vlan_id,
13719 		NULL,
13720 	},
13721 };
13722 
13723 /* tx loopback configuration */
13724 
13725 /* Common result structure for tx loopback */
13726 struct cmd_tx_loopback_result {
13727 	cmdline_fixed_string_t set;
13728 	cmdline_fixed_string_t tx;
13729 	cmdline_fixed_string_t loopback;
13730 	portid_t port_id;
13731 	cmdline_fixed_string_t on_off;
13732 };
13733 
13734 /* Common CLI fields for tx loopback enable disable */
13735 cmdline_parse_token_string_t cmd_tx_loopback_set =
13736 	TOKEN_STRING_INITIALIZER
13737 		(struct cmd_tx_loopback_result,
13738 		 set, "set");
13739 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13740 	TOKEN_STRING_INITIALIZER
13741 		(struct cmd_tx_loopback_result,
13742 		 tx, "tx");
13743 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13744 	TOKEN_STRING_INITIALIZER
13745 		(struct cmd_tx_loopback_result,
13746 		 loopback, "loopback");
13747 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13748 	TOKEN_NUM_INITIALIZER
13749 		(struct cmd_tx_loopback_result,
13750 		 port_id, UINT16);
13751 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13752 	TOKEN_STRING_INITIALIZER
13753 		(struct cmd_tx_loopback_result,
13754 		 on_off, "on#off");
13755 
13756 static void
13757 cmd_set_tx_loopback_parsed(
13758 	void *parsed_result,
13759 	__attribute__((unused)) struct cmdline *cl,
13760 	__attribute__((unused)) void *data)
13761 {
13762 	struct cmd_tx_loopback_result *res = parsed_result;
13763 	int ret = -ENOTSUP;
13764 
13765 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13766 
13767 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13768 		return;
13769 
13770 #ifdef RTE_LIBRTE_IXGBE_PMD
13771 	if (ret == -ENOTSUP)
13772 		ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13773 #endif
13774 #ifdef RTE_LIBRTE_I40E_PMD
13775 	if (ret == -ENOTSUP)
13776 		ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13777 #endif
13778 #ifdef RTE_LIBRTE_BNXT_PMD
13779 	if (ret == -ENOTSUP)
13780 		ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13781 #endif
13782 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13783 	if (ret == -ENOTSUP)
13784 		ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13785 #endif
13786 
13787 	switch (ret) {
13788 	case 0:
13789 		break;
13790 	case -EINVAL:
13791 		printf("invalid is_on %d\n", is_on);
13792 		break;
13793 	case -ENODEV:
13794 		printf("invalid port_id %d\n", res->port_id);
13795 		break;
13796 	case -ENOTSUP:
13797 		printf("function not implemented\n");
13798 		break;
13799 	default:
13800 		printf("programming error: (%s)\n", strerror(-ret));
13801 	}
13802 }
13803 
13804 cmdline_parse_inst_t cmd_set_tx_loopback = {
13805 	.f = cmd_set_tx_loopback_parsed,
13806 	.data = NULL,
13807 	.help_str = "set tx loopback <port_id> on|off",
13808 	.tokens = {
13809 		(void *)&cmd_tx_loopback_set,
13810 		(void *)&cmd_tx_loopback_tx,
13811 		(void *)&cmd_tx_loopback_loopback,
13812 		(void *)&cmd_tx_loopback_port_id,
13813 		(void *)&cmd_tx_loopback_on_off,
13814 		NULL,
13815 	},
13816 };
13817 
13818 /* all queues drop enable configuration */
13819 
13820 /* Common result structure for all queues drop enable */
13821 struct cmd_all_queues_drop_en_result {
13822 	cmdline_fixed_string_t set;
13823 	cmdline_fixed_string_t all;
13824 	cmdline_fixed_string_t queues;
13825 	cmdline_fixed_string_t drop;
13826 	portid_t port_id;
13827 	cmdline_fixed_string_t on_off;
13828 };
13829 
13830 /* Common CLI fields for tx loopback enable disable */
13831 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13832 	TOKEN_STRING_INITIALIZER
13833 		(struct cmd_all_queues_drop_en_result,
13834 		 set, "set");
13835 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13836 	TOKEN_STRING_INITIALIZER
13837 		(struct cmd_all_queues_drop_en_result,
13838 		 all, "all");
13839 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13840 	TOKEN_STRING_INITIALIZER
13841 		(struct cmd_all_queues_drop_en_result,
13842 		 queues, "queues");
13843 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13844 	TOKEN_STRING_INITIALIZER
13845 		(struct cmd_all_queues_drop_en_result,
13846 		 drop, "drop");
13847 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13848 	TOKEN_NUM_INITIALIZER
13849 		(struct cmd_all_queues_drop_en_result,
13850 		 port_id, UINT16);
13851 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13852 	TOKEN_STRING_INITIALIZER
13853 		(struct cmd_all_queues_drop_en_result,
13854 		 on_off, "on#off");
13855 
13856 static void
13857 cmd_set_all_queues_drop_en_parsed(
13858 	void *parsed_result,
13859 	__attribute__((unused)) struct cmdline *cl,
13860 	__attribute__((unused)) void *data)
13861 {
13862 	struct cmd_all_queues_drop_en_result *res = parsed_result;
13863 	int ret = -ENOTSUP;
13864 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13865 
13866 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13867 		return;
13868 
13869 #ifdef RTE_LIBRTE_IXGBE_PMD
13870 	if (ret == -ENOTSUP)
13871 		ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13872 #endif
13873 #ifdef RTE_LIBRTE_BNXT_PMD
13874 	if (ret == -ENOTSUP)
13875 		ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13876 #endif
13877 	switch (ret) {
13878 	case 0:
13879 		break;
13880 	case -EINVAL:
13881 		printf("invalid is_on %d\n", is_on);
13882 		break;
13883 	case -ENODEV:
13884 		printf("invalid port_id %d\n", res->port_id);
13885 		break;
13886 	case -ENOTSUP:
13887 		printf("function not implemented\n");
13888 		break;
13889 	default:
13890 		printf("programming error: (%s)\n", strerror(-ret));
13891 	}
13892 }
13893 
13894 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13895 	.f = cmd_set_all_queues_drop_en_parsed,
13896 	.data = NULL,
13897 	.help_str = "set all queues drop <port_id> on|off",
13898 	.tokens = {
13899 		(void *)&cmd_all_queues_drop_en_set,
13900 		(void *)&cmd_all_queues_drop_en_all,
13901 		(void *)&cmd_all_queues_drop_en_queues,
13902 		(void *)&cmd_all_queues_drop_en_drop,
13903 		(void *)&cmd_all_queues_drop_en_port_id,
13904 		(void *)&cmd_all_queues_drop_en_on_off,
13905 		NULL,
13906 	},
13907 };
13908 
13909 /* vf split drop enable configuration */
13910 
13911 /* Common result structure for vf split drop enable */
13912 struct cmd_vf_split_drop_en_result {
13913 	cmdline_fixed_string_t set;
13914 	cmdline_fixed_string_t vf;
13915 	cmdline_fixed_string_t split;
13916 	cmdline_fixed_string_t drop;
13917 	portid_t port_id;
13918 	uint16_t vf_id;
13919 	cmdline_fixed_string_t on_off;
13920 };
13921 
13922 /* Common CLI fields for vf split drop enable disable */
13923 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13924 	TOKEN_STRING_INITIALIZER
13925 		(struct cmd_vf_split_drop_en_result,
13926 		 set, "set");
13927 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13928 	TOKEN_STRING_INITIALIZER
13929 		(struct cmd_vf_split_drop_en_result,
13930 		 vf, "vf");
13931 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13932 	TOKEN_STRING_INITIALIZER
13933 		(struct cmd_vf_split_drop_en_result,
13934 		 split, "split");
13935 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13936 	TOKEN_STRING_INITIALIZER
13937 		(struct cmd_vf_split_drop_en_result,
13938 		 drop, "drop");
13939 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13940 	TOKEN_NUM_INITIALIZER
13941 		(struct cmd_vf_split_drop_en_result,
13942 		 port_id, UINT16);
13943 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13944 	TOKEN_NUM_INITIALIZER
13945 		(struct cmd_vf_split_drop_en_result,
13946 		 vf_id, UINT16);
13947 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13948 	TOKEN_STRING_INITIALIZER
13949 		(struct cmd_vf_split_drop_en_result,
13950 		 on_off, "on#off");
13951 
13952 static void
13953 cmd_set_vf_split_drop_en_parsed(
13954 	void *parsed_result,
13955 	__attribute__((unused)) struct cmdline *cl,
13956 	__attribute__((unused)) void *data)
13957 {
13958 	struct cmd_vf_split_drop_en_result *res = parsed_result;
13959 	int ret = -ENOTSUP;
13960 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13961 
13962 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13963 		return;
13964 
13965 #ifdef RTE_LIBRTE_IXGBE_PMD
13966 	ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13967 			is_on);
13968 #endif
13969 	switch (ret) {
13970 	case 0:
13971 		break;
13972 	case -EINVAL:
13973 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13974 		break;
13975 	case -ENODEV:
13976 		printf("invalid port_id %d\n", res->port_id);
13977 		break;
13978 	case -ENOTSUP:
13979 		printf("not supported on port %d\n", res->port_id);
13980 		break;
13981 	default:
13982 		printf("programming error: (%s)\n", strerror(-ret));
13983 	}
13984 }
13985 
13986 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13987 	.f = cmd_set_vf_split_drop_en_parsed,
13988 	.data = NULL,
13989 	.help_str = "set vf split drop <port_id> <vf_id> on|off",
13990 	.tokens = {
13991 		(void *)&cmd_vf_split_drop_en_set,
13992 		(void *)&cmd_vf_split_drop_en_vf,
13993 		(void *)&cmd_vf_split_drop_en_split,
13994 		(void *)&cmd_vf_split_drop_en_drop,
13995 		(void *)&cmd_vf_split_drop_en_port_id,
13996 		(void *)&cmd_vf_split_drop_en_vf_id,
13997 		(void *)&cmd_vf_split_drop_en_on_off,
13998 		NULL,
13999 	},
14000 };
14001 
14002 /* vf mac address configuration */
14003 
14004 /* Common result structure for vf mac address */
14005 struct cmd_set_vf_mac_addr_result {
14006 	cmdline_fixed_string_t set;
14007 	cmdline_fixed_string_t vf;
14008 	cmdline_fixed_string_t mac;
14009 	cmdline_fixed_string_t addr;
14010 	portid_t port_id;
14011 	uint16_t vf_id;
14012 	struct rte_ether_addr mac_addr;
14013 
14014 };
14015 
14016 /* Common CLI fields for vf split drop enable disable */
14017 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14018 	TOKEN_STRING_INITIALIZER
14019 		(struct cmd_set_vf_mac_addr_result,
14020 		 set, "set");
14021 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14022 	TOKEN_STRING_INITIALIZER
14023 		(struct cmd_set_vf_mac_addr_result,
14024 		 vf, "vf");
14025 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14026 	TOKEN_STRING_INITIALIZER
14027 		(struct cmd_set_vf_mac_addr_result,
14028 		 mac, "mac");
14029 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14030 	TOKEN_STRING_INITIALIZER
14031 		(struct cmd_set_vf_mac_addr_result,
14032 		 addr, "addr");
14033 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14034 	TOKEN_NUM_INITIALIZER
14035 		(struct cmd_set_vf_mac_addr_result,
14036 		 port_id, UINT16);
14037 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14038 	TOKEN_NUM_INITIALIZER
14039 		(struct cmd_set_vf_mac_addr_result,
14040 		 vf_id, UINT16);
14041 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14042 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14043 		 mac_addr);
14044 
14045 static void
14046 cmd_set_vf_mac_addr_parsed(
14047 	void *parsed_result,
14048 	__attribute__((unused)) struct cmdline *cl,
14049 	__attribute__((unused)) void *data)
14050 {
14051 	struct cmd_set_vf_mac_addr_result *res = parsed_result;
14052 	int ret = -ENOTSUP;
14053 
14054 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14055 		return;
14056 
14057 #ifdef RTE_LIBRTE_IXGBE_PMD
14058 	if (ret == -ENOTSUP)
14059 		ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14060 				&res->mac_addr);
14061 #endif
14062 #ifdef RTE_LIBRTE_I40E_PMD
14063 	if (ret == -ENOTSUP)
14064 		ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14065 				&res->mac_addr);
14066 #endif
14067 #ifdef RTE_LIBRTE_BNXT_PMD
14068 	if (ret == -ENOTSUP)
14069 		ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14070 				&res->mac_addr);
14071 #endif
14072 
14073 	switch (ret) {
14074 	case 0:
14075 		break;
14076 	case -EINVAL:
14077 		printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14078 		break;
14079 	case -ENODEV:
14080 		printf("invalid port_id %d\n", res->port_id);
14081 		break;
14082 	case -ENOTSUP:
14083 		printf("function not implemented\n");
14084 		break;
14085 	default:
14086 		printf("programming error: (%s)\n", strerror(-ret));
14087 	}
14088 }
14089 
14090 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14091 	.f = cmd_set_vf_mac_addr_parsed,
14092 	.data = NULL,
14093 	.help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14094 	.tokens = {
14095 		(void *)&cmd_set_vf_mac_addr_set,
14096 		(void *)&cmd_set_vf_mac_addr_vf,
14097 		(void *)&cmd_set_vf_mac_addr_mac,
14098 		(void *)&cmd_set_vf_mac_addr_addr,
14099 		(void *)&cmd_set_vf_mac_addr_port_id,
14100 		(void *)&cmd_set_vf_mac_addr_vf_id,
14101 		(void *)&cmd_set_vf_mac_addr_mac_addr,
14102 		NULL,
14103 	},
14104 };
14105 
14106 /* MACsec configuration */
14107 
14108 /* Common result structure for MACsec offload enable */
14109 struct cmd_macsec_offload_on_result {
14110 	cmdline_fixed_string_t set;
14111 	cmdline_fixed_string_t macsec;
14112 	cmdline_fixed_string_t offload;
14113 	portid_t port_id;
14114 	cmdline_fixed_string_t on;
14115 	cmdline_fixed_string_t encrypt;
14116 	cmdline_fixed_string_t en_on_off;
14117 	cmdline_fixed_string_t replay_protect;
14118 	cmdline_fixed_string_t rp_on_off;
14119 };
14120 
14121 /* Common CLI fields for MACsec offload disable */
14122 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14123 	TOKEN_STRING_INITIALIZER
14124 		(struct cmd_macsec_offload_on_result,
14125 		 set, "set");
14126 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14127 	TOKEN_STRING_INITIALIZER
14128 		(struct cmd_macsec_offload_on_result,
14129 		 macsec, "macsec");
14130 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14131 	TOKEN_STRING_INITIALIZER
14132 		(struct cmd_macsec_offload_on_result,
14133 		 offload, "offload");
14134 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14135 	TOKEN_NUM_INITIALIZER
14136 		(struct cmd_macsec_offload_on_result,
14137 		 port_id, UINT16);
14138 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14139 	TOKEN_STRING_INITIALIZER
14140 		(struct cmd_macsec_offload_on_result,
14141 		 on, "on");
14142 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14143 	TOKEN_STRING_INITIALIZER
14144 		(struct cmd_macsec_offload_on_result,
14145 		 encrypt, "encrypt");
14146 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14147 	TOKEN_STRING_INITIALIZER
14148 		(struct cmd_macsec_offload_on_result,
14149 		 en_on_off, "on#off");
14150 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14151 	TOKEN_STRING_INITIALIZER
14152 		(struct cmd_macsec_offload_on_result,
14153 		 replay_protect, "replay-protect");
14154 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14155 	TOKEN_STRING_INITIALIZER
14156 		(struct cmd_macsec_offload_on_result,
14157 		 rp_on_off, "on#off");
14158 
14159 static void
14160 cmd_set_macsec_offload_on_parsed(
14161 	void *parsed_result,
14162 	__attribute__((unused)) struct cmdline *cl,
14163 	__attribute__((unused)) void *data)
14164 {
14165 	struct cmd_macsec_offload_on_result *res = parsed_result;
14166 	int ret = -ENOTSUP;
14167 	portid_t port_id = res->port_id;
14168 	int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14169 	int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14170 	struct rte_eth_dev_info dev_info;
14171 
14172 	if (port_id_is_invalid(port_id, ENABLED_WARN))
14173 		return;
14174 	if (!port_is_stopped(port_id)) {
14175 		printf("Please stop port %d first\n", port_id);
14176 		return;
14177 	}
14178 
14179 	rte_eth_dev_info_get(port_id, &dev_info);
14180 	if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14181 #ifdef RTE_LIBRTE_IXGBE_PMD
14182 		ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14183 #endif
14184 	}
14185 	RTE_SET_USED(en);
14186 	RTE_SET_USED(rp);
14187 
14188 	switch (ret) {
14189 	case 0:
14190 		ports[port_id].dev_conf.txmode.offloads |=
14191 						DEV_TX_OFFLOAD_MACSEC_INSERT;
14192 		cmd_reconfig_device_queue(port_id, 1, 1);
14193 		break;
14194 	case -ENODEV:
14195 		printf("invalid port_id %d\n", port_id);
14196 		break;
14197 	case -ENOTSUP:
14198 		printf("not supported on port %d\n", port_id);
14199 		break;
14200 	default:
14201 		printf("programming error: (%s)\n", strerror(-ret));
14202 	}
14203 }
14204 
14205 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14206 	.f = cmd_set_macsec_offload_on_parsed,
14207 	.data = NULL,
14208 	.help_str = "set macsec offload <port_id> on "
14209 		"encrypt on|off replay-protect on|off",
14210 	.tokens = {
14211 		(void *)&cmd_macsec_offload_on_set,
14212 		(void *)&cmd_macsec_offload_on_macsec,
14213 		(void *)&cmd_macsec_offload_on_offload,
14214 		(void *)&cmd_macsec_offload_on_port_id,
14215 		(void *)&cmd_macsec_offload_on_on,
14216 		(void *)&cmd_macsec_offload_on_encrypt,
14217 		(void *)&cmd_macsec_offload_on_en_on_off,
14218 		(void *)&cmd_macsec_offload_on_replay_protect,
14219 		(void *)&cmd_macsec_offload_on_rp_on_off,
14220 		NULL,
14221 	},
14222 };
14223 
14224 /* Common result structure for MACsec offload disable */
14225 struct cmd_macsec_offload_off_result {
14226 	cmdline_fixed_string_t set;
14227 	cmdline_fixed_string_t macsec;
14228 	cmdline_fixed_string_t offload;
14229 	portid_t port_id;
14230 	cmdline_fixed_string_t off;
14231 };
14232 
14233 /* Common CLI fields for MACsec offload disable */
14234 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14235 	TOKEN_STRING_INITIALIZER
14236 		(struct cmd_macsec_offload_off_result,
14237 		 set, "set");
14238 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14239 	TOKEN_STRING_INITIALIZER
14240 		(struct cmd_macsec_offload_off_result,
14241 		 macsec, "macsec");
14242 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14243 	TOKEN_STRING_INITIALIZER
14244 		(struct cmd_macsec_offload_off_result,
14245 		 offload, "offload");
14246 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14247 	TOKEN_NUM_INITIALIZER
14248 		(struct cmd_macsec_offload_off_result,
14249 		 port_id, UINT16);
14250 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14251 	TOKEN_STRING_INITIALIZER
14252 		(struct cmd_macsec_offload_off_result,
14253 		 off, "off");
14254 
14255 static void
14256 cmd_set_macsec_offload_off_parsed(
14257 	void *parsed_result,
14258 	__attribute__((unused)) struct cmdline *cl,
14259 	__attribute__((unused)) void *data)
14260 {
14261 	struct cmd_macsec_offload_off_result *res = parsed_result;
14262 	int ret = -ENOTSUP;
14263 	struct rte_eth_dev_info dev_info;
14264 	portid_t port_id = res->port_id;
14265 
14266 	if (port_id_is_invalid(port_id, ENABLED_WARN))
14267 		return;
14268 	if (!port_is_stopped(port_id)) {
14269 		printf("Please stop port %d first\n", port_id);
14270 		return;
14271 	}
14272 
14273 	rte_eth_dev_info_get(port_id, &dev_info);
14274 	if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14275 #ifdef RTE_LIBRTE_IXGBE_PMD
14276 		ret = rte_pmd_ixgbe_macsec_disable(port_id);
14277 #endif
14278 	}
14279 	switch (ret) {
14280 	case 0:
14281 		ports[port_id].dev_conf.txmode.offloads &=
14282 						~DEV_TX_OFFLOAD_MACSEC_INSERT;
14283 		cmd_reconfig_device_queue(port_id, 1, 1);
14284 		break;
14285 	case -ENODEV:
14286 		printf("invalid port_id %d\n", port_id);
14287 		break;
14288 	case -ENOTSUP:
14289 		printf("not supported on port %d\n", port_id);
14290 		break;
14291 	default:
14292 		printf("programming error: (%s)\n", strerror(-ret));
14293 	}
14294 }
14295 
14296 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14297 	.f = cmd_set_macsec_offload_off_parsed,
14298 	.data = NULL,
14299 	.help_str = "set macsec offload <port_id> off",
14300 	.tokens = {
14301 		(void *)&cmd_macsec_offload_off_set,
14302 		(void *)&cmd_macsec_offload_off_macsec,
14303 		(void *)&cmd_macsec_offload_off_offload,
14304 		(void *)&cmd_macsec_offload_off_port_id,
14305 		(void *)&cmd_macsec_offload_off_off,
14306 		NULL,
14307 	},
14308 };
14309 
14310 /* Common result structure for MACsec secure connection configure */
14311 struct cmd_macsec_sc_result {
14312 	cmdline_fixed_string_t set;
14313 	cmdline_fixed_string_t macsec;
14314 	cmdline_fixed_string_t sc;
14315 	cmdline_fixed_string_t tx_rx;
14316 	portid_t port_id;
14317 	struct rte_ether_addr mac;
14318 	uint16_t pi;
14319 };
14320 
14321 /* Common CLI fields for MACsec secure connection configure */
14322 cmdline_parse_token_string_t cmd_macsec_sc_set =
14323 	TOKEN_STRING_INITIALIZER
14324 		(struct cmd_macsec_sc_result,
14325 		 set, "set");
14326 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14327 	TOKEN_STRING_INITIALIZER
14328 		(struct cmd_macsec_sc_result,
14329 		 macsec, "macsec");
14330 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14331 	TOKEN_STRING_INITIALIZER
14332 		(struct cmd_macsec_sc_result,
14333 		 sc, "sc");
14334 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14335 	TOKEN_STRING_INITIALIZER
14336 		(struct cmd_macsec_sc_result,
14337 		 tx_rx, "tx#rx");
14338 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14339 	TOKEN_NUM_INITIALIZER
14340 		(struct cmd_macsec_sc_result,
14341 		 port_id, UINT16);
14342 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14343 	TOKEN_ETHERADDR_INITIALIZER
14344 		(struct cmd_macsec_sc_result,
14345 		 mac);
14346 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14347 	TOKEN_NUM_INITIALIZER
14348 		(struct cmd_macsec_sc_result,
14349 		 pi, UINT16);
14350 
14351 static void
14352 cmd_set_macsec_sc_parsed(
14353 	void *parsed_result,
14354 	__attribute__((unused)) struct cmdline *cl,
14355 	__attribute__((unused)) void *data)
14356 {
14357 	struct cmd_macsec_sc_result *res = parsed_result;
14358 	int ret = -ENOTSUP;
14359 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14360 
14361 #ifdef RTE_LIBRTE_IXGBE_PMD
14362 	ret = is_tx ?
14363 		rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14364 				res->mac.addr_bytes) :
14365 		rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14366 				res->mac.addr_bytes, res->pi);
14367 #endif
14368 	RTE_SET_USED(is_tx);
14369 
14370 	switch (ret) {
14371 	case 0:
14372 		break;
14373 	case -ENODEV:
14374 		printf("invalid port_id %d\n", res->port_id);
14375 		break;
14376 	case -ENOTSUP:
14377 		printf("not supported on port %d\n", res->port_id);
14378 		break;
14379 	default:
14380 		printf("programming error: (%s)\n", strerror(-ret));
14381 	}
14382 }
14383 
14384 cmdline_parse_inst_t cmd_set_macsec_sc = {
14385 	.f = cmd_set_macsec_sc_parsed,
14386 	.data = NULL,
14387 	.help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14388 	.tokens = {
14389 		(void *)&cmd_macsec_sc_set,
14390 		(void *)&cmd_macsec_sc_macsec,
14391 		(void *)&cmd_macsec_sc_sc,
14392 		(void *)&cmd_macsec_sc_tx_rx,
14393 		(void *)&cmd_macsec_sc_port_id,
14394 		(void *)&cmd_macsec_sc_mac,
14395 		(void *)&cmd_macsec_sc_pi,
14396 		NULL,
14397 	},
14398 };
14399 
14400 /* Common result structure for MACsec secure connection configure */
14401 struct cmd_macsec_sa_result {
14402 	cmdline_fixed_string_t set;
14403 	cmdline_fixed_string_t macsec;
14404 	cmdline_fixed_string_t sa;
14405 	cmdline_fixed_string_t tx_rx;
14406 	portid_t port_id;
14407 	uint8_t idx;
14408 	uint8_t an;
14409 	uint32_t pn;
14410 	cmdline_fixed_string_t key;
14411 };
14412 
14413 /* Common CLI fields for MACsec secure connection configure */
14414 cmdline_parse_token_string_t cmd_macsec_sa_set =
14415 	TOKEN_STRING_INITIALIZER
14416 		(struct cmd_macsec_sa_result,
14417 		 set, "set");
14418 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14419 	TOKEN_STRING_INITIALIZER
14420 		(struct cmd_macsec_sa_result,
14421 		 macsec, "macsec");
14422 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14423 	TOKEN_STRING_INITIALIZER
14424 		(struct cmd_macsec_sa_result,
14425 		 sa, "sa");
14426 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14427 	TOKEN_STRING_INITIALIZER
14428 		(struct cmd_macsec_sa_result,
14429 		 tx_rx, "tx#rx");
14430 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14431 	TOKEN_NUM_INITIALIZER
14432 		(struct cmd_macsec_sa_result,
14433 		 port_id, UINT16);
14434 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14435 	TOKEN_NUM_INITIALIZER
14436 		(struct cmd_macsec_sa_result,
14437 		 idx, UINT8);
14438 cmdline_parse_token_num_t cmd_macsec_sa_an =
14439 	TOKEN_NUM_INITIALIZER
14440 		(struct cmd_macsec_sa_result,
14441 		 an, UINT8);
14442 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14443 	TOKEN_NUM_INITIALIZER
14444 		(struct cmd_macsec_sa_result,
14445 		 pn, UINT32);
14446 cmdline_parse_token_string_t cmd_macsec_sa_key =
14447 	TOKEN_STRING_INITIALIZER
14448 		(struct cmd_macsec_sa_result,
14449 		 key, NULL);
14450 
14451 static void
14452 cmd_set_macsec_sa_parsed(
14453 	void *parsed_result,
14454 	__attribute__((unused)) struct cmdline *cl,
14455 	__attribute__((unused)) void *data)
14456 {
14457 	struct cmd_macsec_sa_result *res = parsed_result;
14458 	int ret = -ENOTSUP;
14459 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14460 	uint8_t key[16] = { 0 };
14461 	uint8_t xdgt0;
14462 	uint8_t xdgt1;
14463 	int key_len;
14464 	int i;
14465 
14466 	key_len = strlen(res->key) / 2;
14467 	if (key_len > 16)
14468 		key_len = 16;
14469 
14470 	for (i = 0; i < key_len; i++) {
14471 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14472 		if (xdgt0 == 0xFF)
14473 			return;
14474 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14475 		if (xdgt1 == 0xFF)
14476 			return;
14477 		key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14478 	}
14479 
14480 #ifdef RTE_LIBRTE_IXGBE_PMD
14481 	ret = is_tx ?
14482 		rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14483 			res->idx, res->an, res->pn, key) :
14484 		rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14485 			res->idx, res->an, res->pn, key);
14486 #endif
14487 	RTE_SET_USED(is_tx);
14488 	RTE_SET_USED(key);
14489 
14490 	switch (ret) {
14491 	case 0:
14492 		break;
14493 	case -EINVAL:
14494 		printf("invalid idx %d or an %d\n", res->idx, res->an);
14495 		break;
14496 	case -ENODEV:
14497 		printf("invalid port_id %d\n", res->port_id);
14498 		break;
14499 	case -ENOTSUP:
14500 		printf("not supported on port %d\n", res->port_id);
14501 		break;
14502 	default:
14503 		printf("programming error: (%s)\n", strerror(-ret));
14504 	}
14505 }
14506 
14507 cmdline_parse_inst_t cmd_set_macsec_sa = {
14508 	.f = cmd_set_macsec_sa_parsed,
14509 	.data = NULL,
14510 	.help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14511 	.tokens = {
14512 		(void *)&cmd_macsec_sa_set,
14513 		(void *)&cmd_macsec_sa_macsec,
14514 		(void *)&cmd_macsec_sa_sa,
14515 		(void *)&cmd_macsec_sa_tx_rx,
14516 		(void *)&cmd_macsec_sa_port_id,
14517 		(void *)&cmd_macsec_sa_idx,
14518 		(void *)&cmd_macsec_sa_an,
14519 		(void *)&cmd_macsec_sa_pn,
14520 		(void *)&cmd_macsec_sa_key,
14521 		NULL,
14522 	},
14523 };
14524 
14525 /* VF unicast promiscuous mode configuration */
14526 
14527 /* Common result structure for VF unicast promiscuous mode */
14528 struct cmd_vf_promisc_result {
14529 	cmdline_fixed_string_t set;
14530 	cmdline_fixed_string_t vf;
14531 	cmdline_fixed_string_t promisc;
14532 	portid_t port_id;
14533 	uint32_t vf_id;
14534 	cmdline_fixed_string_t on_off;
14535 };
14536 
14537 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14538 cmdline_parse_token_string_t cmd_vf_promisc_set =
14539 	TOKEN_STRING_INITIALIZER
14540 		(struct cmd_vf_promisc_result,
14541 		 set, "set");
14542 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14543 	TOKEN_STRING_INITIALIZER
14544 		(struct cmd_vf_promisc_result,
14545 		 vf, "vf");
14546 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14547 	TOKEN_STRING_INITIALIZER
14548 		(struct cmd_vf_promisc_result,
14549 		 promisc, "promisc");
14550 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14551 	TOKEN_NUM_INITIALIZER
14552 		(struct cmd_vf_promisc_result,
14553 		 port_id, UINT16);
14554 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14555 	TOKEN_NUM_INITIALIZER
14556 		(struct cmd_vf_promisc_result,
14557 		 vf_id, UINT32);
14558 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14559 	TOKEN_STRING_INITIALIZER
14560 		(struct cmd_vf_promisc_result,
14561 		 on_off, "on#off");
14562 
14563 static void
14564 cmd_set_vf_promisc_parsed(
14565 	void *parsed_result,
14566 	__attribute__((unused)) struct cmdline *cl,
14567 	__attribute__((unused)) void *data)
14568 {
14569 	struct cmd_vf_promisc_result *res = parsed_result;
14570 	int ret = -ENOTSUP;
14571 
14572 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14573 
14574 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14575 		return;
14576 
14577 #ifdef RTE_LIBRTE_I40E_PMD
14578 	ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14579 						  res->vf_id, is_on);
14580 #endif
14581 
14582 	switch (ret) {
14583 	case 0:
14584 		break;
14585 	case -EINVAL:
14586 		printf("invalid vf_id %d\n", res->vf_id);
14587 		break;
14588 	case -ENODEV:
14589 		printf("invalid port_id %d\n", res->port_id);
14590 		break;
14591 	case -ENOTSUP:
14592 		printf("function not implemented\n");
14593 		break;
14594 	default:
14595 		printf("programming error: (%s)\n", strerror(-ret));
14596 	}
14597 }
14598 
14599 cmdline_parse_inst_t cmd_set_vf_promisc = {
14600 	.f = cmd_set_vf_promisc_parsed,
14601 	.data = NULL,
14602 	.help_str = "set vf promisc <port_id> <vf_id> on|off: "
14603 		"Set unicast promiscuous mode for a VF from the PF",
14604 	.tokens = {
14605 		(void *)&cmd_vf_promisc_set,
14606 		(void *)&cmd_vf_promisc_vf,
14607 		(void *)&cmd_vf_promisc_promisc,
14608 		(void *)&cmd_vf_promisc_port_id,
14609 		(void *)&cmd_vf_promisc_vf_id,
14610 		(void *)&cmd_vf_promisc_on_off,
14611 		NULL,
14612 	},
14613 };
14614 
14615 /* VF multicast promiscuous mode configuration */
14616 
14617 /* Common result structure for VF multicast promiscuous mode */
14618 struct cmd_vf_allmulti_result {
14619 	cmdline_fixed_string_t set;
14620 	cmdline_fixed_string_t vf;
14621 	cmdline_fixed_string_t allmulti;
14622 	portid_t port_id;
14623 	uint32_t vf_id;
14624 	cmdline_fixed_string_t on_off;
14625 };
14626 
14627 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14628 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14629 	TOKEN_STRING_INITIALIZER
14630 		(struct cmd_vf_allmulti_result,
14631 		 set, "set");
14632 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14633 	TOKEN_STRING_INITIALIZER
14634 		(struct cmd_vf_allmulti_result,
14635 		 vf, "vf");
14636 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14637 	TOKEN_STRING_INITIALIZER
14638 		(struct cmd_vf_allmulti_result,
14639 		 allmulti, "allmulti");
14640 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14641 	TOKEN_NUM_INITIALIZER
14642 		(struct cmd_vf_allmulti_result,
14643 		 port_id, UINT16);
14644 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14645 	TOKEN_NUM_INITIALIZER
14646 		(struct cmd_vf_allmulti_result,
14647 		 vf_id, UINT32);
14648 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14649 	TOKEN_STRING_INITIALIZER
14650 		(struct cmd_vf_allmulti_result,
14651 		 on_off, "on#off");
14652 
14653 static void
14654 cmd_set_vf_allmulti_parsed(
14655 	void *parsed_result,
14656 	__attribute__((unused)) struct cmdline *cl,
14657 	__attribute__((unused)) void *data)
14658 {
14659 	struct cmd_vf_allmulti_result *res = parsed_result;
14660 	int ret = -ENOTSUP;
14661 
14662 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14663 
14664 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14665 		return;
14666 
14667 #ifdef RTE_LIBRTE_I40E_PMD
14668 	ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14669 						    res->vf_id, is_on);
14670 #endif
14671 
14672 	switch (ret) {
14673 	case 0:
14674 		break;
14675 	case -EINVAL:
14676 		printf("invalid vf_id %d\n", res->vf_id);
14677 		break;
14678 	case -ENODEV:
14679 		printf("invalid port_id %d\n", res->port_id);
14680 		break;
14681 	case -ENOTSUP:
14682 		printf("function not implemented\n");
14683 		break;
14684 	default:
14685 		printf("programming error: (%s)\n", strerror(-ret));
14686 	}
14687 }
14688 
14689 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14690 	.f = cmd_set_vf_allmulti_parsed,
14691 	.data = NULL,
14692 	.help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14693 		"Set multicast promiscuous mode for a VF from the PF",
14694 	.tokens = {
14695 		(void *)&cmd_vf_allmulti_set,
14696 		(void *)&cmd_vf_allmulti_vf,
14697 		(void *)&cmd_vf_allmulti_allmulti,
14698 		(void *)&cmd_vf_allmulti_port_id,
14699 		(void *)&cmd_vf_allmulti_vf_id,
14700 		(void *)&cmd_vf_allmulti_on_off,
14701 		NULL,
14702 	},
14703 };
14704 
14705 /* vf broadcast mode configuration */
14706 
14707 /* Common result structure for vf broadcast */
14708 struct cmd_set_vf_broadcast_result {
14709 	cmdline_fixed_string_t set;
14710 	cmdline_fixed_string_t vf;
14711 	cmdline_fixed_string_t broadcast;
14712 	portid_t port_id;
14713 	uint16_t vf_id;
14714 	cmdline_fixed_string_t on_off;
14715 };
14716 
14717 /* Common CLI fields for vf broadcast enable disable */
14718 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14719 	TOKEN_STRING_INITIALIZER
14720 		(struct cmd_set_vf_broadcast_result,
14721 		 set, "set");
14722 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14723 	TOKEN_STRING_INITIALIZER
14724 		(struct cmd_set_vf_broadcast_result,
14725 		 vf, "vf");
14726 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14727 	TOKEN_STRING_INITIALIZER
14728 		(struct cmd_set_vf_broadcast_result,
14729 		 broadcast, "broadcast");
14730 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14731 	TOKEN_NUM_INITIALIZER
14732 		(struct cmd_set_vf_broadcast_result,
14733 		 port_id, UINT16);
14734 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14735 	TOKEN_NUM_INITIALIZER
14736 		(struct cmd_set_vf_broadcast_result,
14737 		 vf_id, UINT16);
14738 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14739 	TOKEN_STRING_INITIALIZER
14740 		(struct cmd_set_vf_broadcast_result,
14741 		 on_off, "on#off");
14742 
14743 static void
14744 cmd_set_vf_broadcast_parsed(
14745 	void *parsed_result,
14746 	__attribute__((unused)) struct cmdline *cl,
14747 	__attribute__((unused)) void *data)
14748 {
14749 	struct cmd_set_vf_broadcast_result *res = parsed_result;
14750 	int ret = -ENOTSUP;
14751 
14752 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14753 
14754 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14755 		return;
14756 
14757 #ifdef RTE_LIBRTE_I40E_PMD
14758 	ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14759 					    res->vf_id, is_on);
14760 #endif
14761 
14762 	switch (ret) {
14763 	case 0:
14764 		break;
14765 	case -EINVAL:
14766 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14767 		break;
14768 	case -ENODEV:
14769 		printf("invalid port_id %d\n", res->port_id);
14770 		break;
14771 	case -ENOTSUP:
14772 		printf("function not implemented\n");
14773 		break;
14774 	default:
14775 		printf("programming error: (%s)\n", strerror(-ret));
14776 	}
14777 }
14778 
14779 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14780 	.f = cmd_set_vf_broadcast_parsed,
14781 	.data = NULL,
14782 	.help_str = "set vf broadcast <port_id> <vf_id> on|off",
14783 	.tokens = {
14784 		(void *)&cmd_set_vf_broadcast_set,
14785 		(void *)&cmd_set_vf_broadcast_vf,
14786 		(void *)&cmd_set_vf_broadcast_broadcast,
14787 		(void *)&cmd_set_vf_broadcast_port_id,
14788 		(void *)&cmd_set_vf_broadcast_vf_id,
14789 		(void *)&cmd_set_vf_broadcast_on_off,
14790 		NULL,
14791 	},
14792 };
14793 
14794 /* vf vlan tag configuration */
14795 
14796 /* Common result structure for vf vlan tag */
14797 struct cmd_set_vf_vlan_tag_result {
14798 	cmdline_fixed_string_t set;
14799 	cmdline_fixed_string_t vf;
14800 	cmdline_fixed_string_t vlan;
14801 	cmdline_fixed_string_t tag;
14802 	portid_t port_id;
14803 	uint16_t vf_id;
14804 	cmdline_fixed_string_t on_off;
14805 };
14806 
14807 /* Common CLI fields for vf vlan tag enable disable */
14808 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14809 	TOKEN_STRING_INITIALIZER
14810 		(struct cmd_set_vf_vlan_tag_result,
14811 		 set, "set");
14812 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14813 	TOKEN_STRING_INITIALIZER
14814 		(struct cmd_set_vf_vlan_tag_result,
14815 		 vf, "vf");
14816 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14817 	TOKEN_STRING_INITIALIZER
14818 		(struct cmd_set_vf_vlan_tag_result,
14819 		 vlan, "vlan");
14820 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14821 	TOKEN_STRING_INITIALIZER
14822 		(struct cmd_set_vf_vlan_tag_result,
14823 		 tag, "tag");
14824 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14825 	TOKEN_NUM_INITIALIZER
14826 		(struct cmd_set_vf_vlan_tag_result,
14827 		 port_id, UINT16);
14828 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14829 	TOKEN_NUM_INITIALIZER
14830 		(struct cmd_set_vf_vlan_tag_result,
14831 		 vf_id, UINT16);
14832 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14833 	TOKEN_STRING_INITIALIZER
14834 		(struct cmd_set_vf_vlan_tag_result,
14835 		 on_off, "on#off");
14836 
14837 static void
14838 cmd_set_vf_vlan_tag_parsed(
14839 	void *parsed_result,
14840 	__attribute__((unused)) struct cmdline *cl,
14841 	__attribute__((unused)) void *data)
14842 {
14843 	struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14844 	int ret = -ENOTSUP;
14845 
14846 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14847 
14848 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14849 		return;
14850 
14851 #ifdef RTE_LIBRTE_I40E_PMD
14852 	ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14853 					   res->vf_id, is_on);
14854 #endif
14855 
14856 	switch (ret) {
14857 	case 0:
14858 		break;
14859 	case -EINVAL:
14860 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14861 		break;
14862 	case -ENODEV:
14863 		printf("invalid port_id %d\n", res->port_id);
14864 		break;
14865 	case -ENOTSUP:
14866 		printf("function not implemented\n");
14867 		break;
14868 	default:
14869 		printf("programming error: (%s)\n", strerror(-ret));
14870 	}
14871 }
14872 
14873 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14874 	.f = cmd_set_vf_vlan_tag_parsed,
14875 	.data = NULL,
14876 	.help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14877 	.tokens = {
14878 		(void *)&cmd_set_vf_vlan_tag_set,
14879 		(void *)&cmd_set_vf_vlan_tag_vf,
14880 		(void *)&cmd_set_vf_vlan_tag_vlan,
14881 		(void *)&cmd_set_vf_vlan_tag_tag,
14882 		(void *)&cmd_set_vf_vlan_tag_port_id,
14883 		(void *)&cmd_set_vf_vlan_tag_vf_id,
14884 		(void *)&cmd_set_vf_vlan_tag_on_off,
14885 		NULL,
14886 	},
14887 };
14888 
14889 /* Common definition of VF and TC TX bandwidth configuration */
14890 struct cmd_vf_tc_bw_result {
14891 	cmdline_fixed_string_t set;
14892 	cmdline_fixed_string_t vf;
14893 	cmdline_fixed_string_t tc;
14894 	cmdline_fixed_string_t tx;
14895 	cmdline_fixed_string_t min_bw;
14896 	cmdline_fixed_string_t max_bw;
14897 	cmdline_fixed_string_t strict_link_prio;
14898 	portid_t port_id;
14899 	uint16_t vf_id;
14900 	uint8_t tc_no;
14901 	uint32_t bw;
14902 	cmdline_fixed_string_t bw_list;
14903 	uint8_t tc_map;
14904 };
14905 
14906 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14907 	TOKEN_STRING_INITIALIZER
14908 		(struct cmd_vf_tc_bw_result,
14909 		 set, "set");
14910 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14911 	TOKEN_STRING_INITIALIZER
14912 		(struct cmd_vf_tc_bw_result,
14913 		 vf, "vf");
14914 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14915 	TOKEN_STRING_INITIALIZER
14916 		(struct cmd_vf_tc_bw_result,
14917 		 tc, "tc");
14918 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14919 	TOKEN_STRING_INITIALIZER
14920 		(struct cmd_vf_tc_bw_result,
14921 		 tx, "tx");
14922 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14923 	TOKEN_STRING_INITIALIZER
14924 		(struct cmd_vf_tc_bw_result,
14925 		 strict_link_prio, "strict-link-priority");
14926 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14927 	TOKEN_STRING_INITIALIZER
14928 		(struct cmd_vf_tc_bw_result,
14929 		 min_bw, "min-bandwidth");
14930 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14931 	TOKEN_STRING_INITIALIZER
14932 		(struct cmd_vf_tc_bw_result,
14933 		 max_bw, "max-bandwidth");
14934 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14935 	TOKEN_NUM_INITIALIZER
14936 		(struct cmd_vf_tc_bw_result,
14937 		 port_id, UINT16);
14938 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14939 	TOKEN_NUM_INITIALIZER
14940 		(struct cmd_vf_tc_bw_result,
14941 		 vf_id, UINT16);
14942 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14943 	TOKEN_NUM_INITIALIZER
14944 		(struct cmd_vf_tc_bw_result,
14945 		 tc_no, UINT8);
14946 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14947 	TOKEN_NUM_INITIALIZER
14948 		(struct cmd_vf_tc_bw_result,
14949 		 bw, UINT32);
14950 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14951 	TOKEN_STRING_INITIALIZER
14952 		(struct cmd_vf_tc_bw_result,
14953 		 bw_list, NULL);
14954 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14955 	TOKEN_NUM_INITIALIZER
14956 		(struct cmd_vf_tc_bw_result,
14957 		 tc_map, UINT8);
14958 
14959 /* VF max bandwidth setting */
14960 static void
14961 cmd_vf_max_bw_parsed(
14962 	void *parsed_result,
14963 	__attribute__((unused)) struct cmdline *cl,
14964 	__attribute__((unused)) void *data)
14965 {
14966 	struct cmd_vf_tc_bw_result *res = parsed_result;
14967 	int ret = -ENOTSUP;
14968 
14969 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14970 		return;
14971 
14972 #ifdef RTE_LIBRTE_I40E_PMD
14973 	ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14974 					 res->vf_id, res->bw);
14975 #endif
14976 
14977 	switch (ret) {
14978 	case 0:
14979 		break;
14980 	case -EINVAL:
14981 		printf("invalid vf_id %d or bandwidth %d\n",
14982 		       res->vf_id, res->bw);
14983 		break;
14984 	case -ENODEV:
14985 		printf("invalid port_id %d\n", res->port_id);
14986 		break;
14987 	case -ENOTSUP:
14988 		printf("function not implemented\n");
14989 		break;
14990 	default:
14991 		printf("programming error: (%s)\n", strerror(-ret));
14992 	}
14993 }
14994 
14995 cmdline_parse_inst_t cmd_vf_max_bw = {
14996 	.f = cmd_vf_max_bw_parsed,
14997 	.data = NULL,
14998 	.help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14999 	.tokens = {
15000 		(void *)&cmd_vf_tc_bw_set,
15001 		(void *)&cmd_vf_tc_bw_vf,
15002 		(void *)&cmd_vf_tc_bw_tx,
15003 		(void *)&cmd_vf_tc_bw_max_bw,
15004 		(void *)&cmd_vf_tc_bw_port_id,
15005 		(void *)&cmd_vf_tc_bw_vf_id,
15006 		(void *)&cmd_vf_tc_bw_bw,
15007 		NULL,
15008 	},
15009 };
15010 
15011 static int
15012 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15013 			   uint8_t *tc_num,
15014 			   char *str)
15015 {
15016 	uint32_t size;
15017 	const char *p, *p0 = str;
15018 	char s[256];
15019 	char *end;
15020 	char *str_fld[16];
15021 	uint16_t i;
15022 	int ret;
15023 
15024 	p = strchr(p0, '(');
15025 	if (p == NULL) {
15026 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15027 		return -1;
15028 	}
15029 	p++;
15030 	p0 = strchr(p, ')');
15031 	if (p0 == NULL) {
15032 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15033 		return -1;
15034 	}
15035 	size = p0 - p;
15036 	if (size >= sizeof(s)) {
15037 		printf("The string size exceeds the internal buffer size\n");
15038 		return -1;
15039 	}
15040 	snprintf(s, sizeof(s), "%.*s", size, p);
15041 	ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15042 	if (ret <= 0) {
15043 		printf("Failed to get the bandwidth list. ");
15044 		return -1;
15045 	}
15046 	*tc_num = ret;
15047 	for (i = 0; i < ret; i++)
15048 		bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15049 
15050 	return 0;
15051 }
15052 
15053 /* TC min bandwidth setting */
15054 static void
15055 cmd_vf_tc_min_bw_parsed(
15056 	void *parsed_result,
15057 	__attribute__((unused)) struct cmdline *cl,
15058 	__attribute__((unused)) void *data)
15059 {
15060 	struct cmd_vf_tc_bw_result *res = parsed_result;
15061 	uint8_t tc_num;
15062 	uint8_t bw[16];
15063 	int ret = -ENOTSUP;
15064 
15065 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15066 		return;
15067 
15068 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15069 	if (ret)
15070 		return;
15071 
15072 #ifdef RTE_LIBRTE_I40E_PMD
15073 	ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15074 					      tc_num, bw);
15075 #endif
15076 
15077 	switch (ret) {
15078 	case 0:
15079 		break;
15080 	case -EINVAL:
15081 		printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15082 		break;
15083 	case -ENODEV:
15084 		printf("invalid port_id %d\n", res->port_id);
15085 		break;
15086 	case -ENOTSUP:
15087 		printf("function not implemented\n");
15088 		break;
15089 	default:
15090 		printf("programming error: (%s)\n", strerror(-ret));
15091 	}
15092 }
15093 
15094 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15095 	.f = cmd_vf_tc_min_bw_parsed,
15096 	.data = NULL,
15097 	.help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15098 		    " <bw1, bw2, ...>",
15099 	.tokens = {
15100 		(void *)&cmd_vf_tc_bw_set,
15101 		(void *)&cmd_vf_tc_bw_vf,
15102 		(void *)&cmd_vf_tc_bw_tc,
15103 		(void *)&cmd_vf_tc_bw_tx,
15104 		(void *)&cmd_vf_tc_bw_min_bw,
15105 		(void *)&cmd_vf_tc_bw_port_id,
15106 		(void *)&cmd_vf_tc_bw_vf_id,
15107 		(void *)&cmd_vf_tc_bw_bw_list,
15108 		NULL,
15109 	},
15110 };
15111 
15112 static void
15113 cmd_tc_min_bw_parsed(
15114 	void *parsed_result,
15115 	__attribute__((unused)) struct cmdline *cl,
15116 	__attribute__((unused)) void *data)
15117 {
15118 	struct cmd_vf_tc_bw_result *res = parsed_result;
15119 	struct rte_port *port;
15120 	uint8_t tc_num;
15121 	uint8_t bw[16];
15122 	int ret = -ENOTSUP;
15123 
15124 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15125 		return;
15126 
15127 	port = &ports[res->port_id];
15128 	/** Check if the port is not started **/
15129 	if (port->port_status != RTE_PORT_STOPPED) {
15130 		printf("Please stop port %d first\n", res->port_id);
15131 		return;
15132 	}
15133 
15134 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15135 	if (ret)
15136 		return;
15137 
15138 #ifdef RTE_LIBRTE_IXGBE_PMD
15139 	ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15140 #endif
15141 
15142 	switch (ret) {
15143 	case 0:
15144 		break;
15145 	case -EINVAL:
15146 		printf("invalid bandwidth\n");
15147 		break;
15148 	case -ENODEV:
15149 		printf("invalid port_id %d\n", res->port_id);
15150 		break;
15151 	case -ENOTSUP:
15152 		printf("function not implemented\n");
15153 		break;
15154 	default:
15155 		printf("programming error: (%s)\n", strerror(-ret));
15156 	}
15157 }
15158 
15159 cmdline_parse_inst_t cmd_tc_min_bw = {
15160 	.f = cmd_tc_min_bw_parsed,
15161 	.data = NULL,
15162 	.help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15163 	.tokens = {
15164 		(void *)&cmd_vf_tc_bw_set,
15165 		(void *)&cmd_vf_tc_bw_tc,
15166 		(void *)&cmd_vf_tc_bw_tx,
15167 		(void *)&cmd_vf_tc_bw_min_bw,
15168 		(void *)&cmd_vf_tc_bw_port_id,
15169 		(void *)&cmd_vf_tc_bw_bw_list,
15170 		NULL,
15171 	},
15172 };
15173 
15174 /* TC max bandwidth setting */
15175 static void
15176 cmd_vf_tc_max_bw_parsed(
15177 	void *parsed_result,
15178 	__attribute__((unused)) struct cmdline *cl,
15179 	__attribute__((unused)) void *data)
15180 {
15181 	struct cmd_vf_tc_bw_result *res = parsed_result;
15182 	int ret = -ENOTSUP;
15183 
15184 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15185 		return;
15186 
15187 #ifdef RTE_LIBRTE_I40E_PMD
15188 	ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15189 					    res->tc_no, res->bw);
15190 #endif
15191 
15192 	switch (ret) {
15193 	case 0:
15194 		break;
15195 	case -EINVAL:
15196 		printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15197 		       res->vf_id, res->tc_no, res->bw);
15198 		break;
15199 	case -ENODEV:
15200 		printf("invalid port_id %d\n", res->port_id);
15201 		break;
15202 	case -ENOTSUP:
15203 		printf("function not implemented\n");
15204 		break;
15205 	default:
15206 		printf("programming error: (%s)\n", strerror(-ret));
15207 	}
15208 }
15209 
15210 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15211 	.f = cmd_vf_tc_max_bw_parsed,
15212 	.data = NULL,
15213 	.help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15214 		    " <bandwidth>",
15215 	.tokens = {
15216 		(void *)&cmd_vf_tc_bw_set,
15217 		(void *)&cmd_vf_tc_bw_vf,
15218 		(void *)&cmd_vf_tc_bw_tc,
15219 		(void *)&cmd_vf_tc_bw_tx,
15220 		(void *)&cmd_vf_tc_bw_max_bw,
15221 		(void *)&cmd_vf_tc_bw_port_id,
15222 		(void *)&cmd_vf_tc_bw_vf_id,
15223 		(void *)&cmd_vf_tc_bw_tc_no,
15224 		(void *)&cmd_vf_tc_bw_bw,
15225 		NULL,
15226 	},
15227 };
15228 
15229 
15230 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15231 
15232 /* *** Set Port default Traffic Management Hierarchy *** */
15233 struct cmd_set_port_tm_hierarchy_default_result {
15234 	cmdline_fixed_string_t set;
15235 	cmdline_fixed_string_t port;
15236 	cmdline_fixed_string_t tm;
15237 	cmdline_fixed_string_t hierarchy;
15238 	cmdline_fixed_string_t def;
15239 	portid_t port_id;
15240 };
15241 
15242 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15243 	TOKEN_STRING_INITIALIZER(
15244 		struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15245 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15246 	TOKEN_STRING_INITIALIZER(
15247 		struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15248 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15249 	TOKEN_STRING_INITIALIZER(
15250 		struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15251 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15252 	TOKEN_STRING_INITIALIZER(
15253 		struct cmd_set_port_tm_hierarchy_default_result,
15254 			hierarchy, "hierarchy");
15255 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15256 	TOKEN_STRING_INITIALIZER(
15257 		struct cmd_set_port_tm_hierarchy_default_result,
15258 			def, "default");
15259 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15260 	TOKEN_NUM_INITIALIZER(
15261 		struct cmd_set_port_tm_hierarchy_default_result,
15262 			port_id, UINT16);
15263 
15264 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15265 	__attribute__((unused)) struct cmdline *cl,
15266 	__attribute__((unused)) void *data)
15267 {
15268 	struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15269 	struct rte_port *p;
15270 	portid_t port_id = res->port_id;
15271 
15272 	if (port_id_is_invalid(port_id, ENABLED_WARN))
15273 		return;
15274 
15275 	p = &ports[port_id];
15276 
15277 	/* Forward mode: tm */
15278 	if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15279 		printf("  softnicfwd mode not enabled(error)\n");
15280 		return;
15281 	}
15282 
15283 	/* Set the default tm hierarchy */
15284 	p->softport.default_tm_hierarchy_enable = 1;
15285 }
15286 
15287 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15288 	.f = cmd_set_port_tm_hierarchy_default_parsed,
15289 	.data = NULL,
15290 	.help_str = "set port tm hierarchy default <port_id>",
15291 	.tokens = {
15292 		(void *)&cmd_set_port_tm_hierarchy_default_set,
15293 		(void *)&cmd_set_port_tm_hierarchy_default_port,
15294 		(void *)&cmd_set_port_tm_hierarchy_default_tm,
15295 		(void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15296 		(void *)&cmd_set_port_tm_hierarchy_default_default,
15297 		(void *)&cmd_set_port_tm_hierarchy_default_port_id,
15298 		NULL,
15299 	},
15300 };
15301 #endif
15302 
15303 /** Set VXLAN encapsulation details */
15304 struct cmd_set_vxlan_result {
15305 	cmdline_fixed_string_t set;
15306 	cmdline_fixed_string_t vxlan;
15307 	cmdline_fixed_string_t pos_token;
15308 	cmdline_fixed_string_t ip_version;
15309 	uint32_t vlan_present:1;
15310 	uint32_t vni;
15311 	uint16_t udp_src;
15312 	uint16_t udp_dst;
15313 	cmdline_ipaddr_t ip_src;
15314 	cmdline_ipaddr_t ip_dst;
15315 	uint16_t tci;
15316 	uint8_t tos;
15317 	uint8_t ttl;
15318 	struct rte_ether_addr eth_src;
15319 	struct rte_ether_addr eth_dst;
15320 };
15321 
15322 cmdline_parse_token_string_t cmd_set_vxlan_set =
15323 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15324 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15325 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15326 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15327 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15328 				 "vxlan-tos-ttl");
15329 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15330 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15331 				 "vxlan-with-vlan");
15332 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15333 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15334 				 "ip-version");
15335 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15336 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15337 				 "ipv4#ipv6");
15338 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15339 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15340 				 "vni");
15341 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15342 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15343 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15344 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15345 				 "udp-src");
15346 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15347 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15348 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15349 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15350 				 "udp-dst");
15351 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15352 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15353 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15354 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15355 				 "ip-tos");
15356 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15357 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15358 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15359 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15360 				 "ip-ttl");
15361 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15362 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15363 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15364 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15365 				 "ip-src");
15366 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15367 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15368 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15369 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15370 				 "ip-dst");
15371 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15372 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15373 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15374 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15375 				 "vlan-tci");
15376 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15377 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15378 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15379 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15380 				 "eth-src");
15381 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15382 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15383 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15384 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15385 				 "eth-dst");
15386 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15387 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15388 
15389 static void cmd_set_vxlan_parsed(void *parsed_result,
15390 	__attribute__((unused)) struct cmdline *cl,
15391 	__attribute__((unused)) void *data)
15392 {
15393 	struct cmd_set_vxlan_result *res = parsed_result;
15394 	union {
15395 		uint32_t vxlan_id;
15396 		uint8_t vni[4];
15397 	} id = {
15398 		.vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15399 	};
15400 
15401 	vxlan_encap_conf.select_tos_ttl = 0;
15402 	if (strcmp(res->vxlan, "vxlan") == 0)
15403 		vxlan_encap_conf.select_vlan = 0;
15404 	else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15405 		vxlan_encap_conf.select_vlan = 1;
15406 	else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15407 		vxlan_encap_conf.select_vlan = 0;
15408 		vxlan_encap_conf.select_tos_ttl = 1;
15409 	}
15410 	if (strcmp(res->ip_version, "ipv4") == 0)
15411 		vxlan_encap_conf.select_ipv4 = 1;
15412 	else if (strcmp(res->ip_version, "ipv6") == 0)
15413 		vxlan_encap_conf.select_ipv4 = 0;
15414 	else
15415 		return;
15416 	rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15417 	vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15418 	vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15419 	vxlan_encap_conf.ip_tos = res->tos;
15420 	vxlan_encap_conf.ip_ttl = res->ttl;
15421 	if (vxlan_encap_conf.select_ipv4) {
15422 		IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15423 		IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15424 	} else {
15425 		IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15426 		IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15427 	}
15428 	if (vxlan_encap_conf.select_vlan)
15429 		vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15430 	rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15431 		   RTE_ETHER_ADDR_LEN);
15432 	rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15433 		   RTE_ETHER_ADDR_LEN);
15434 }
15435 
15436 cmdline_parse_inst_t cmd_set_vxlan = {
15437 	.f = cmd_set_vxlan_parsed,
15438 	.data = NULL,
15439 	.help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15440 		" <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15441 		" eth-src <eth-src> eth-dst <eth-dst>",
15442 	.tokens = {
15443 		(void *)&cmd_set_vxlan_set,
15444 		(void *)&cmd_set_vxlan_vxlan,
15445 		(void *)&cmd_set_vxlan_ip_version,
15446 		(void *)&cmd_set_vxlan_ip_version_value,
15447 		(void *)&cmd_set_vxlan_vni,
15448 		(void *)&cmd_set_vxlan_vni_value,
15449 		(void *)&cmd_set_vxlan_udp_src,
15450 		(void *)&cmd_set_vxlan_udp_src_value,
15451 		(void *)&cmd_set_vxlan_udp_dst,
15452 		(void *)&cmd_set_vxlan_udp_dst_value,
15453 		(void *)&cmd_set_vxlan_ip_src,
15454 		(void *)&cmd_set_vxlan_ip_src_value,
15455 		(void *)&cmd_set_vxlan_ip_dst,
15456 		(void *)&cmd_set_vxlan_ip_dst_value,
15457 		(void *)&cmd_set_vxlan_eth_src,
15458 		(void *)&cmd_set_vxlan_eth_src_value,
15459 		(void *)&cmd_set_vxlan_eth_dst,
15460 		(void *)&cmd_set_vxlan_eth_dst_value,
15461 		NULL,
15462 	},
15463 };
15464 
15465 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15466 	.f = cmd_set_vxlan_parsed,
15467 	.data = NULL,
15468 	.help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15469 		" <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15470 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15471 		" eth-dst <eth-dst>",
15472 	.tokens = {
15473 		(void *)&cmd_set_vxlan_set,
15474 		(void *)&cmd_set_vxlan_vxlan_tos_ttl,
15475 		(void *)&cmd_set_vxlan_ip_version,
15476 		(void *)&cmd_set_vxlan_ip_version_value,
15477 		(void *)&cmd_set_vxlan_vni,
15478 		(void *)&cmd_set_vxlan_vni_value,
15479 		(void *)&cmd_set_vxlan_udp_src,
15480 		(void *)&cmd_set_vxlan_udp_src_value,
15481 		(void *)&cmd_set_vxlan_udp_dst,
15482 		(void *)&cmd_set_vxlan_udp_dst_value,
15483 		(void *)&cmd_set_vxlan_ip_tos,
15484 		(void *)&cmd_set_vxlan_ip_tos_value,
15485 		(void *)&cmd_set_vxlan_ip_ttl,
15486 		(void *)&cmd_set_vxlan_ip_ttl_value,
15487 		(void *)&cmd_set_vxlan_ip_src,
15488 		(void *)&cmd_set_vxlan_ip_src_value,
15489 		(void *)&cmd_set_vxlan_ip_dst,
15490 		(void *)&cmd_set_vxlan_ip_dst_value,
15491 		(void *)&cmd_set_vxlan_eth_src,
15492 		(void *)&cmd_set_vxlan_eth_src_value,
15493 		(void *)&cmd_set_vxlan_eth_dst,
15494 		(void *)&cmd_set_vxlan_eth_dst_value,
15495 		NULL,
15496 	},
15497 };
15498 
15499 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15500 	.f = cmd_set_vxlan_parsed,
15501 	.data = NULL,
15502 	.help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15503 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15504 		" <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15505 		" <eth-dst>",
15506 	.tokens = {
15507 		(void *)&cmd_set_vxlan_set,
15508 		(void *)&cmd_set_vxlan_vxlan_with_vlan,
15509 		(void *)&cmd_set_vxlan_ip_version,
15510 		(void *)&cmd_set_vxlan_ip_version_value,
15511 		(void *)&cmd_set_vxlan_vni,
15512 		(void *)&cmd_set_vxlan_vni_value,
15513 		(void *)&cmd_set_vxlan_udp_src,
15514 		(void *)&cmd_set_vxlan_udp_src_value,
15515 		(void *)&cmd_set_vxlan_udp_dst,
15516 		(void *)&cmd_set_vxlan_udp_dst_value,
15517 		(void *)&cmd_set_vxlan_ip_src,
15518 		(void *)&cmd_set_vxlan_ip_src_value,
15519 		(void *)&cmd_set_vxlan_ip_dst,
15520 		(void *)&cmd_set_vxlan_ip_dst_value,
15521 		(void *)&cmd_set_vxlan_vlan,
15522 		(void *)&cmd_set_vxlan_vlan_value,
15523 		(void *)&cmd_set_vxlan_eth_src,
15524 		(void *)&cmd_set_vxlan_eth_src_value,
15525 		(void *)&cmd_set_vxlan_eth_dst,
15526 		(void *)&cmd_set_vxlan_eth_dst_value,
15527 		NULL,
15528 	},
15529 };
15530 
15531 /** Set NVGRE encapsulation details */
15532 struct cmd_set_nvgre_result {
15533 	cmdline_fixed_string_t set;
15534 	cmdline_fixed_string_t nvgre;
15535 	cmdline_fixed_string_t pos_token;
15536 	cmdline_fixed_string_t ip_version;
15537 	uint32_t tni;
15538 	cmdline_ipaddr_t ip_src;
15539 	cmdline_ipaddr_t ip_dst;
15540 	uint16_t tci;
15541 	struct rte_ether_addr eth_src;
15542 	struct rte_ether_addr eth_dst;
15543 };
15544 
15545 cmdline_parse_token_string_t cmd_set_nvgre_set =
15546 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15547 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15548 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15549 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15550 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15551 				 "nvgre-with-vlan");
15552 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15553 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15554 				 "ip-version");
15555 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15556 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15557 				 "ipv4#ipv6");
15558 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15559 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15560 				 "tni");
15561 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15562 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15563 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15564 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15565 				 "ip-src");
15566 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15567 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15568 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15569 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15570 				 "ip-dst");
15571 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15572 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15573 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15574 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15575 				 "vlan-tci");
15576 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15577 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15578 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15579 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15580 				 "eth-src");
15581 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15582 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15583 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15584 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15585 				 "eth-dst");
15586 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15587 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15588 
15589 static void cmd_set_nvgre_parsed(void *parsed_result,
15590 	__attribute__((unused)) struct cmdline *cl,
15591 	__attribute__((unused)) void *data)
15592 {
15593 	struct cmd_set_nvgre_result *res = parsed_result;
15594 	union {
15595 		uint32_t nvgre_tni;
15596 		uint8_t tni[4];
15597 	} id = {
15598 		.nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15599 	};
15600 
15601 	if (strcmp(res->nvgre, "nvgre") == 0)
15602 		nvgre_encap_conf.select_vlan = 0;
15603 	else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15604 		nvgre_encap_conf.select_vlan = 1;
15605 	if (strcmp(res->ip_version, "ipv4") == 0)
15606 		nvgre_encap_conf.select_ipv4 = 1;
15607 	else if (strcmp(res->ip_version, "ipv6") == 0)
15608 		nvgre_encap_conf.select_ipv4 = 0;
15609 	else
15610 		return;
15611 	rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15612 	if (nvgre_encap_conf.select_ipv4) {
15613 		IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15614 		IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15615 	} else {
15616 		IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15617 		IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15618 	}
15619 	if (nvgre_encap_conf.select_vlan)
15620 		nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15621 	rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15622 		   RTE_ETHER_ADDR_LEN);
15623 	rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15624 		   RTE_ETHER_ADDR_LEN);
15625 }
15626 
15627 cmdline_parse_inst_t cmd_set_nvgre = {
15628 	.f = cmd_set_nvgre_parsed,
15629 	.data = NULL,
15630 	.help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15631 		" <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15632 		" eth-dst <eth-dst>",
15633 	.tokens = {
15634 		(void *)&cmd_set_nvgre_set,
15635 		(void *)&cmd_set_nvgre_nvgre,
15636 		(void *)&cmd_set_nvgre_ip_version,
15637 		(void *)&cmd_set_nvgre_ip_version_value,
15638 		(void *)&cmd_set_nvgre_tni,
15639 		(void *)&cmd_set_nvgre_tni_value,
15640 		(void *)&cmd_set_nvgre_ip_src,
15641 		(void *)&cmd_set_nvgre_ip_src_value,
15642 		(void *)&cmd_set_nvgre_ip_dst,
15643 		(void *)&cmd_set_nvgre_ip_dst_value,
15644 		(void *)&cmd_set_nvgre_eth_src,
15645 		(void *)&cmd_set_nvgre_eth_src_value,
15646 		(void *)&cmd_set_nvgre_eth_dst,
15647 		(void *)&cmd_set_nvgre_eth_dst_value,
15648 		NULL,
15649 	},
15650 };
15651 
15652 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15653 	.f = cmd_set_nvgre_parsed,
15654 	.data = NULL,
15655 	.help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15656 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15657 		" eth-src <eth-src> eth-dst <eth-dst>",
15658 	.tokens = {
15659 		(void *)&cmd_set_nvgre_set,
15660 		(void *)&cmd_set_nvgre_nvgre_with_vlan,
15661 		(void *)&cmd_set_nvgre_ip_version,
15662 		(void *)&cmd_set_nvgre_ip_version_value,
15663 		(void *)&cmd_set_nvgre_tni,
15664 		(void *)&cmd_set_nvgre_tni_value,
15665 		(void *)&cmd_set_nvgre_ip_src,
15666 		(void *)&cmd_set_nvgre_ip_src_value,
15667 		(void *)&cmd_set_nvgre_ip_dst,
15668 		(void *)&cmd_set_nvgre_ip_dst_value,
15669 		(void *)&cmd_set_nvgre_vlan,
15670 		(void *)&cmd_set_nvgre_vlan_value,
15671 		(void *)&cmd_set_nvgre_eth_src,
15672 		(void *)&cmd_set_nvgre_eth_src_value,
15673 		(void *)&cmd_set_nvgre_eth_dst,
15674 		(void *)&cmd_set_nvgre_eth_dst_value,
15675 		NULL,
15676 	},
15677 };
15678 
15679 /** Set L2 encapsulation details */
15680 struct cmd_set_l2_encap_result {
15681 	cmdline_fixed_string_t set;
15682 	cmdline_fixed_string_t l2_encap;
15683 	cmdline_fixed_string_t pos_token;
15684 	cmdline_fixed_string_t ip_version;
15685 	uint32_t vlan_present:1;
15686 	uint16_t tci;
15687 	struct rte_ether_addr eth_src;
15688 	struct rte_ether_addr eth_dst;
15689 };
15690 
15691 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15692 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15693 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15694 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15695 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15696 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15697 				 "l2_encap-with-vlan");
15698 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15699 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15700 				 "ip-version");
15701 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15702 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15703 				 "ipv4#ipv6");
15704 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15705 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15706 				 "vlan-tci");
15707 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15708 	TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15709 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15710 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15711 				 "eth-src");
15712 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15713 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15714 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15715 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15716 				 "eth-dst");
15717 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15718 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15719 
15720 static void cmd_set_l2_encap_parsed(void *parsed_result,
15721 	__attribute__((unused)) struct cmdline *cl,
15722 	__attribute__((unused)) void *data)
15723 {
15724 	struct cmd_set_l2_encap_result *res = parsed_result;
15725 
15726 	if (strcmp(res->l2_encap, "l2_encap") == 0)
15727 		l2_encap_conf.select_vlan = 0;
15728 	else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15729 		l2_encap_conf.select_vlan = 1;
15730 	if (strcmp(res->ip_version, "ipv4") == 0)
15731 		l2_encap_conf.select_ipv4 = 1;
15732 	else if (strcmp(res->ip_version, "ipv6") == 0)
15733 		l2_encap_conf.select_ipv4 = 0;
15734 	else
15735 		return;
15736 	if (l2_encap_conf.select_vlan)
15737 		l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15738 	rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15739 		   RTE_ETHER_ADDR_LEN);
15740 	rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15741 		   RTE_ETHER_ADDR_LEN);
15742 }
15743 
15744 cmdline_parse_inst_t cmd_set_l2_encap = {
15745 	.f = cmd_set_l2_encap_parsed,
15746 	.data = NULL,
15747 	.help_str = "set l2_encap ip-version ipv4|ipv6"
15748 		" eth-src <eth-src> eth-dst <eth-dst>",
15749 	.tokens = {
15750 		(void *)&cmd_set_l2_encap_set,
15751 		(void *)&cmd_set_l2_encap_l2_encap,
15752 		(void *)&cmd_set_l2_encap_ip_version,
15753 		(void *)&cmd_set_l2_encap_ip_version_value,
15754 		(void *)&cmd_set_l2_encap_eth_src,
15755 		(void *)&cmd_set_l2_encap_eth_src_value,
15756 		(void *)&cmd_set_l2_encap_eth_dst,
15757 		(void *)&cmd_set_l2_encap_eth_dst_value,
15758 		NULL,
15759 	},
15760 };
15761 
15762 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15763 	.f = cmd_set_l2_encap_parsed,
15764 	.data = NULL,
15765 	.help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15766 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15767 	.tokens = {
15768 		(void *)&cmd_set_l2_encap_set,
15769 		(void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15770 		(void *)&cmd_set_l2_encap_ip_version,
15771 		(void *)&cmd_set_l2_encap_ip_version_value,
15772 		(void *)&cmd_set_l2_encap_vlan,
15773 		(void *)&cmd_set_l2_encap_vlan_value,
15774 		(void *)&cmd_set_l2_encap_eth_src,
15775 		(void *)&cmd_set_l2_encap_eth_src_value,
15776 		(void *)&cmd_set_l2_encap_eth_dst,
15777 		(void *)&cmd_set_l2_encap_eth_dst_value,
15778 		NULL,
15779 	},
15780 };
15781 
15782 /** Set L2 decapsulation details */
15783 struct cmd_set_l2_decap_result {
15784 	cmdline_fixed_string_t set;
15785 	cmdline_fixed_string_t l2_decap;
15786 	cmdline_fixed_string_t pos_token;
15787 	uint32_t vlan_present:1;
15788 };
15789 
15790 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15791 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15792 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15793 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15794 				 "l2_decap");
15795 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15796 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15797 				 "l2_decap-with-vlan");
15798 
15799 static void cmd_set_l2_decap_parsed(void *parsed_result,
15800 	__attribute__((unused)) struct cmdline *cl,
15801 	__attribute__((unused)) void *data)
15802 {
15803 	struct cmd_set_l2_decap_result *res = parsed_result;
15804 
15805 	if (strcmp(res->l2_decap, "l2_decap") == 0)
15806 		l2_decap_conf.select_vlan = 0;
15807 	else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15808 		l2_decap_conf.select_vlan = 1;
15809 }
15810 
15811 cmdline_parse_inst_t cmd_set_l2_decap = {
15812 	.f = cmd_set_l2_decap_parsed,
15813 	.data = NULL,
15814 	.help_str = "set l2_decap",
15815 	.tokens = {
15816 		(void *)&cmd_set_l2_decap_set,
15817 		(void *)&cmd_set_l2_decap_l2_decap,
15818 		NULL,
15819 	},
15820 };
15821 
15822 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15823 	.f = cmd_set_l2_decap_parsed,
15824 	.data = NULL,
15825 	.help_str = "set l2_decap-with-vlan",
15826 	.tokens = {
15827 		(void *)&cmd_set_l2_decap_set,
15828 		(void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15829 		NULL,
15830 	},
15831 };
15832 
15833 /** Set MPLSoGRE encapsulation details */
15834 struct cmd_set_mplsogre_encap_result {
15835 	cmdline_fixed_string_t set;
15836 	cmdline_fixed_string_t mplsogre;
15837 	cmdline_fixed_string_t pos_token;
15838 	cmdline_fixed_string_t ip_version;
15839 	uint32_t vlan_present:1;
15840 	uint32_t label;
15841 	cmdline_ipaddr_t ip_src;
15842 	cmdline_ipaddr_t ip_dst;
15843 	uint16_t tci;
15844 	struct rte_ether_addr eth_src;
15845 	struct rte_ether_addr eth_dst;
15846 };
15847 
15848 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15849 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15850 				 "set");
15851 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15852 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15853 				 "mplsogre_encap");
15854 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15855 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15856 				 mplsogre, "mplsogre_encap-with-vlan");
15857 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15858 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15859 				 pos_token, "ip-version");
15860 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15861 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15862 				 ip_version, "ipv4#ipv6");
15863 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15864 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15865 				 pos_token, "label");
15866 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15867 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15868 			      UINT32);
15869 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15870 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15871 				 pos_token, "ip-src");
15872 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15873 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15874 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15875 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15876 				 pos_token, "ip-dst");
15877 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15878 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15879 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15880 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15881 				 pos_token, "vlan-tci");
15882 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15883 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15884 			      UINT16);
15885 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15886 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15887 				 pos_token, "eth-src");
15888 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15889 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15890 				    eth_src);
15891 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15892 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15893 				 pos_token, "eth-dst");
15894 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15895 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15896 				    eth_dst);
15897 
15898 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15899 	__attribute__((unused)) struct cmdline *cl,
15900 	__attribute__((unused)) void *data)
15901 {
15902 	struct cmd_set_mplsogre_encap_result *res = parsed_result;
15903 	union {
15904 		uint32_t mplsogre_label;
15905 		uint8_t label[4];
15906 	} id = {
15907 		.mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15908 	};
15909 
15910 	if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15911 		mplsogre_encap_conf.select_vlan = 0;
15912 	else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15913 		mplsogre_encap_conf.select_vlan = 1;
15914 	if (strcmp(res->ip_version, "ipv4") == 0)
15915 		mplsogre_encap_conf.select_ipv4 = 1;
15916 	else if (strcmp(res->ip_version, "ipv6") == 0)
15917 		mplsogre_encap_conf.select_ipv4 = 0;
15918 	else
15919 		return;
15920 	rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15921 	if (mplsogre_encap_conf.select_ipv4) {
15922 		IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15923 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15924 	} else {
15925 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15926 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15927 	}
15928 	if (mplsogre_encap_conf.select_vlan)
15929 		mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15930 	rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15931 		   RTE_ETHER_ADDR_LEN);
15932 	rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15933 		   RTE_ETHER_ADDR_LEN);
15934 }
15935 
15936 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15937 	.f = cmd_set_mplsogre_encap_parsed,
15938 	.data = NULL,
15939 	.help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15940 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15941 		" eth-dst <eth-dst>",
15942 	.tokens = {
15943 		(void *)&cmd_set_mplsogre_encap_set,
15944 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15945 		(void *)&cmd_set_mplsogre_encap_ip_version,
15946 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
15947 		(void *)&cmd_set_mplsogre_encap_label,
15948 		(void *)&cmd_set_mplsogre_encap_label_value,
15949 		(void *)&cmd_set_mplsogre_encap_ip_src,
15950 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
15951 		(void *)&cmd_set_mplsogre_encap_ip_dst,
15952 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
15953 		(void *)&cmd_set_mplsogre_encap_eth_src,
15954 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
15955 		(void *)&cmd_set_mplsogre_encap_eth_dst,
15956 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
15957 		NULL,
15958 	},
15959 };
15960 
15961 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15962 	.f = cmd_set_mplsogre_encap_parsed,
15963 	.data = NULL,
15964 	.help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15965 		" label <label> ip-src <ip-src> ip-dst <ip-dst>"
15966 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15967 	.tokens = {
15968 		(void *)&cmd_set_mplsogre_encap_set,
15969 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15970 		(void *)&cmd_set_mplsogre_encap_ip_version,
15971 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
15972 		(void *)&cmd_set_mplsogre_encap_label,
15973 		(void *)&cmd_set_mplsogre_encap_label_value,
15974 		(void *)&cmd_set_mplsogre_encap_ip_src,
15975 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
15976 		(void *)&cmd_set_mplsogre_encap_ip_dst,
15977 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
15978 		(void *)&cmd_set_mplsogre_encap_vlan,
15979 		(void *)&cmd_set_mplsogre_encap_vlan_value,
15980 		(void *)&cmd_set_mplsogre_encap_eth_src,
15981 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
15982 		(void *)&cmd_set_mplsogre_encap_eth_dst,
15983 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
15984 		NULL,
15985 	},
15986 };
15987 
15988 /** Set MPLSoGRE decapsulation details */
15989 struct cmd_set_mplsogre_decap_result {
15990 	cmdline_fixed_string_t set;
15991 	cmdline_fixed_string_t mplsogre;
15992 	cmdline_fixed_string_t pos_token;
15993 	cmdline_fixed_string_t ip_version;
15994 	uint32_t vlan_present:1;
15995 };
15996 
15997 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15998 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15999 				 "set");
16000 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16001 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16002 				 "mplsogre_decap");
16003 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16004 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16005 				 mplsogre, "mplsogre_decap-with-vlan");
16006 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16007 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16008 				 pos_token, "ip-version");
16009 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16010 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16011 				 ip_version, "ipv4#ipv6");
16012 
16013 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16014 	__attribute__((unused)) struct cmdline *cl,
16015 	__attribute__((unused)) void *data)
16016 {
16017 	struct cmd_set_mplsogre_decap_result *res = parsed_result;
16018 
16019 	if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16020 		mplsogre_decap_conf.select_vlan = 0;
16021 	else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16022 		mplsogre_decap_conf.select_vlan = 1;
16023 	if (strcmp(res->ip_version, "ipv4") == 0)
16024 		mplsogre_decap_conf.select_ipv4 = 1;
16025 	else if (strcmp(res->ip_version, "ipv6") == 0)
16026 		mplsogre_decap_conf.select_ipv4 = 0;
16027 }
16028 
16029 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16030 	.f = cmd_set_mplsogre_decap_parsed,
16031 	.data = NULL,
16032 	.help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16033 	.tokens = {
16034 		(void *)&cmd_set_mplsogre_decap_set,
16035 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16036 		(void *)&cmd_set_mplsogre_decap_ip_version,
16037 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
16038 		NULL,
16039 	},
16040 };
16041 
16042 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16043 	.f = cmd_set_mplsogre_decap_parsed,
16044 	.data = NULL,
16045 	.help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16046 	.tokens = {
16047 		(void *)&cmd_set_mplsogre_decap_set,
16048 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16049 		(void *)&cmd_set_mplsogre_decap_ip_version,
16050 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
16051 		NULL,
16052 	},
16053 };
16054 
16055 /** Set MPLSoUDP encapsulation details */
16056 struct cmd_set_mplsoudp_encap_result {
16057 	cmdline_fixed_string_t set;
16058 	cmdline_fixed_string_t mplsoudp;
16059 	cmdline_fixed_string_t pos_token;
16060 	cmdline_fixed_string_t ip_version;
16061 	uint32_t vlan_present:1;
16062 	uint32_t label;
16063 	uint16_t udp_src;
16064 	uint16_t udp_dst;
16065 	cmdline_ipaddr_t ip_src;
16066 	cmdline_ipaddr_t ip_dst;
16067 	uint16_t tci;
16068 	struct rte_ether_addr eth_src;
16069 	struct rte_ether_addr eth_dst;
16070 };
16071 
16072 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16073 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16074 				 "set");
16075 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16076 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16077 				 "mplsoudp_encap");
16078 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16079 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16080 				 mplsoudp, "mplsoudp_encap-with-vlan");
16081 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16082 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16083 				 pos_token, "ip-version");
16084 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16085 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16086 				 ip_version, "ipv4#ipv6");
16087 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16088 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16089 				 pos_token, "label");
16090 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16091 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16092 			      UINT32);
16093 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16094 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16095 				 pos_token, "udp-src");
16096 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16097 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16098 			      UINT16);
16099 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16100 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16101 				 pos_token, "udp-dst");
16102 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16103 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16104 			      UINT16);
16105 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16106 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16107 				 pos_token, "ip-src");
16108 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16109 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16110 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16111 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16112 				 pos_token, "ip-dst");
16113 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16114 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16115 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16116 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16117 				 pos_token, "vlan-tci");
16118 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16119 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16120 			      UINT16);
16121 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16122 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16123 				 pos_token, "eth-src");
16124 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16125 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16126 				    eth_src);
16127 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16128 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16129 				 pos_token, "eth-dst");
16130 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16131 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16132 				    eth_dst);
16133 
16134 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16135 	__attribute__((unused)) struct cmdline *cl,
16136 	__attribute__((unused)) void *data)
16137 {
16138 	struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16139 	union {
16140 		uint32_t mplsoudp_label;
16141 		uint8_t label[4];
16142 	} id = {
16143 		.mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16144 	};
16145 
16146 	if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16147 		mplsoudp_encap_conf.select_vlan = 0;
16148 	else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16149 		mplsoudp_encap_conf.select_vlan = 1;
16150 	if (strcmp(res->ip_version, "ipv4") == 0)
16151 		mplsoudp_encap_conf.select_ipv4 = 1;
16152 	else if (strcmp(res->ip_version, "ipv6") == 0)
16153 		mplsoudp_encap_conf.select_ipv4 = 0;
16154 	else
16155 		return;
16156 	rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16157 	mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16158 	mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16159 	if (mplsoudp_encap_conf.select_ipv4) {
16160 		IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16161 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16162 	} else {
16163 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16164 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16165 	}
16166 	if (mplsoudp_encap_conf.select_vlan)
16167 		mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16168 	rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16169 		   RTE_ETHER_ADDR_LEN);
16170 	rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16171 		   RTE_ETHER_ADDR_LEN);
16172 }
16173 
16174 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16175 	.f = cmd_set_mplsoudp_encap_parsed,
16176 	.data = NULL,
16177 	.help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16178 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16179 		" ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16180 	.tokens = {
16181 		(void *)&cmd_set_mplsoudp_encap_set,
16182 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16183 		(void *)&cmd_set_mplsoudp_encap_ip_version,
16184 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
16185 		(void *)&cmd_set_mplsoudp_encap_label,
16186 		(void *)&cmd_set_mplsoudp_encap_label_value,
16187 		(void *)&cmd_set_mplsoudp_encap_udp_src,
16188 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
16189 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
16190 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16191 		(void *)&cmd_set_mplsoudp_encap_ip_src,
16192 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
16193 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
16194 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16195 		(void *)&cmd_set_mplsoudp_encap_eth_src,
16196 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
16197 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
16198 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16199 		NULL,
16200 	},
16201 };
16202 
16203 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16204 	.f = cmd_set_mplsoudp_encap_parsed,
16205 	.data = NULL,
16206 	.help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16207 		" label <label> udp-src <udp-src> udp-dst <udp-dst>"
16208 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16209 		" eth-src <eth-src> eth-dst <eth-dst>",
16210 	.tokens = {
16211 		(void *)&cmd_set_mplsoudp_encap_set,
16212 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16213 		(void *)&cmd_set_mplsoudp_encap_ip_version,
16214 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
16215 		(void *)&cmd_set_mplsoudp_encap_label,
16216 		(void *)&cmd_set_mplsoudp_encap_label_value,
16217 		(void *)&cmd_set_mplsoudp_encap_udp_src,
16218 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
16219 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
16220 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16221 		(void *)&cmd_set_mplsoudp_encap_ip_src,
16222 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
16223 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
16224 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16225 		(void *)&cmd_set_mplsoudp_encap_vlan,
16226 		(void *)&cmd_set_mplsoudp_encap_vlan_value,
16227 		(void *)&cmd_set_mplsoudp_encap_eth_src,
16228 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
16229 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
16230 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16231 		NULL,
16232 	},
16233 };
16234 
16235 /** Set MPLSoUDP decapsulation details */
16236 struct cmd_set_mplsoudp_decap_result {
16237 	cmdline_fixed_string_t set;
16238 	cmdline_fixed_string_t mplsoudp;
16239 	cmdline_fixed_string_t pos_token;
16240 	cmdline_fixed_string_t ip_version;
16241 	uint32_t vlan_present:1;
16242 };
16243 
16244 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16245 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16246 				 "set");
16247 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16248 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16249 				 "mplsoudp_decap");
16250 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16251 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16252 				 mplsoudp, "mplsoudp_decap-with-vlan");
16253 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16254 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16255 				 pos_token, "ip-version");
16256 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16257 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16258 				 ip_version, "ipv4#ipv6");
16259 
16260 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16261 	__attribute__((unused)) struct cmdline *cl,
16262 	__attribute__((unused)) void *data)
16263 {
16264 	struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16265 
16266 	if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16267 		mplsoudp_decap_conf.select_vlan = 0;
16268 	else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16269 		mplsoudp_decap_conf.select_vlan = 1;
16270 	if (strcmp(res->ip_version, "ipv4") == 0)
16271 		mplsoudp_decap_conf.select_ipv4 = 1;
16272 	else if (strcmp(res->ip_version, "ipv6") == 0)
16273 		mplsoudp_decap_conf.select_ipv4 = 0;
16274 }
16275 
16276 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16277 	.f = cmd_set_mplsoudp_decap_parsed,
16278 	.data = NULL,
16279 	.help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16280 	.tokens = {
16281 		(void *)&cmd_set_mplsoudp_decap_set,
16282 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16283 		(void *)&cmd_set_mplsoudp_decap_ip_version,
16284 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
16285 		NULL,
16286 	},
16287 };
16288 
16289 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16290 	.f = cmd_set_mplsoudp_decap_parsed,
16291 	.data = NULL,
16292 	.help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16293 	.tokens = {
16294 		(void *)&cmd_set_mplsoudp_decap_set,
16295 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16296 		(void *)&cmd_set_mplsoudp_decap_ip_version,
16297 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
16298 		NULL,
16299 	},
16300 };
16301 
16302 /* Strict link priority scheduling mode setting */
16303 static void
16304 cmd_strict_link_prio_parsed(
16305 	void *parsed_result,
16306 	__attribute__((unused)) struct cmdline *cl,
16307 	__attribute__((unused)) void *data)
16308 {
16309 	struct cmd_vf_tc_bw_result *res = parsed_result;
16310 	int ret = -ENOTSUP;
16311 
16312 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16313 		return;
16314 
16315 #ifdef RTE_LIBRTE_I40E_PMD
16316 	ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16317 #endif
16318 
16319 	switch (ret) {
16320 	case 0:
16321 		break;
16322 	case -EINVAL:
16323 		printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16324 		break;
16325 	case -ENODEV:
16326 		printf("invalid port_id %d\n", res->port_id);
16327 		break;
16328 	case -ENOTSUP:
16329 		printf("function not implemented\n");
16330 		break;
16331 	default:
16332 		printf("programming error: (%s)\n", strerror(-ret));
16333 	}
16334 }
16335 
16336 cmdline_parse_inst_t cmd_strict_link_prio = {
16337 	.f = cmd_strict_link_prio_parsed,
16338 	.data = NULL,
16339 	.help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16340 	.tokens = {
16341 		(void *)&cmd_vf_tc_bw_set,
16342 		(void *)&cmd_vf_tc_bw_tx,
16343 		(void *)&cmd_vf_tc_bw_strict_link_prio,
16344 		(void *)&cmd_vf_tc_bw_port_id,
16345 		(void *)&cmd_vf_tc_bw_tc_map,
16346 		NULL,
16347 	},
16348 };
16349 
16350 /* Load dynamic device personalization*/
16351 struct cmd_ddp_add_result {
16352 	cmdline_fixed_string_t ddp;
16353 	cmdline_fixed_string_t add;
16354 	portid_t port_id;
16355 	char filepath[];
16356 };
16357 
16358 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16359 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16360 cmdline_parse_token_string_t cmd_ddp_add_add =
16361 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16362 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16363 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16364 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16365 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16366 
16367 static void
16368 cmd_ddp_add_parsed(
16369 	void *parsed_result,
16370 	__attribute__((unused)) struct cmdline *cl,
16371 	__attribute__((unused)) void *data)
16372 {
16373 	struct cmd_ddp_add_result *res = parsed_result;
16374 	uint8_t *buff;
16375 	uint32_t size;
16376 	char *filepath;
16377 	char *file_fld[2];
16378 	int file_num;
16379 	int ret = -ENOTSUP;
16380 
16381 	if (!all_ports_stopped()) {
16382 		printf("Please stop all ports first\n");
16383 		return;
16384 	}
16385 
16386 	filepath = strdup(res->filepath);
16387 	if (filepath == NULL) {
16388 		printf("Failed to allocate memory\n");
16389 		return;
16390 	}
16391 	file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16392 
16393 	buff = open_file(file_fld[0], &size);
16394 	if (!buff) {
16395 		free((void *)filepath);
16396 		return;
16397 	}
16398 
16399 #ifdef RTE_LIBRTE_I40E_PMD
16400 	if (ret == -ENOTSUP)
16401 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16402 					       buff, size,
16403 					       RTE_PMD_I40E_PKG_OP_WR_ADD);
16404 #endif
16405 
16406 	if (ret == -EEXIST)
16407 		printf("Profile has already existed.\n");
16408 	else if (ret < 0)
16409 		printf("Failed to load profile.\n");
16410 	else if (file_num == 2)
16411 		save_file(file_fld[1], buff, size);
16412 
16413 	close_file(buff);
16414 	free((void *)filepath);
16415 }
16416 
16417 cmdline_parse_inst_t cmd_ddp_add = {
16418 	.f = cmd_ddp_add_parsed,
16419 	.data = NULL,
16420 	.help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16421 	.tokens = {
16422 		(void *)&cmd_ddp_add_ddp,
16423 		(void *)&cmd_ddp_add_add,
16424 		(void *)&cmd_ddp_add_port_id,
16425 		(void *)&cmd_ddp_add_filepath,
16426 		NULL,
16427 	},
16428 };
16429 
16430 /* Delete dynamic device personalization*/
16431 struct cmd_ddp_del_result {
16432 	cmdline_fixed_string_t ddp;
16433 	cmdline_fixed_string_t del;
16434 	portid_t port_id;
16435 	char filepath[];
16436 };
16437 
16438 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16439 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16440 cmdline_parse_token_string_t cmd_ddp_del_del =
16441 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16442 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16443 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16444 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16445 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16446 
16447 static void
16448 cmd_ddp_del_parsed(
16449 	void *parsed_result,
16450 	__attribute__((unused)) struct cmdline *cl,
16451 	__attribute__((unused)) void *data)
16452 {
16453 	struct cmd_ddp_del_result *res = parsed_result;
16454 	uint8_t *buff;
16455 	uint32_t size;
16456 	int ret = -ENOTSUP;
16457 
16458 	if (!all_ports_stopped()) {
16459 		printf("Please stop all ports first\n");
16460 		return;
16461 	}
16462 
16463 	buff = open_file(res->filepath, &size);
16464 	if (!buff)
16465 		return;
16466 
16467 #ifdef RTE_LIBRTE_I40E_PMD
16468 	if (ret == -ENOTSUP)
16469 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16470 					       buff, size,
16471 					       RTE_PMD_I40E_PKG_OP_WR_DEL);
16472 #endif
16473 
16474 	if (ret == -EACCES)
16475 		printf("Profile does not exist.\n");
16476 	else if (ret < 0)
16477 		printf("Failed to delete profile.\n");
16478 
16479 	close_file(buff);
16480 }
16481 
16482 cmdline_parse_inst_t cmd_ddp_del = {
16483 	.f = cmd_ddp_del_parsed,
16484 	.data = NULL,
16485 	.help_str = "ddp del <port_id> <backup_profile_path>",
16486 	.tokens = {
16487 		(void *)&cmd_ddp_del_ddp,
16488 		(void *)&cmd_ddp_del_del,
16489 		(void *)&cmd_ddp_del_port_id,
16490 		(void *)&cmd_ddp_del_filepath,
16491 		NULL,
16492 	},
16493 };
16494 
16495 /* Get dynamic device personalization profile info */
16496 struct cmd_ddp_info_result {
16497 	cmdline_fixed_string_t ddp;
16498 	cmdline_fixed_string_t get;
16499 	cmdline_fixed_string_t info;
16500 	char filepath[];
16501 };
16502 
16503 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16504 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16505 cmdline_parse_token_string_t cmd_ddp_info_get =
16506 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16507 cmdline_parse_token_string_t cmd_ddp_info_info =
16508 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16509 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16510 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16511 
16512 static void
16513 cmd_ddp_info_parsed(
16514 	void *parsed_result,
16515 	__attribute__((unused)) struct cmdline *cl,
16516 	__attribute__((unused)) void *data)
16517 {
16518 	struct cmd_ddp_info_result *res = parsed_result;
16519 	uint8_t *pkg;
16520 	uint32_t pkg_size;
16521 	int ret = -ENOTSUP;
16522 #ifdef RTE_LIBRTE_I40E_PMD
16523 	uint32_t i, j, n;
16524 	uint8_t *buff;
16525 	uint32_t buff_size = 0;
16526 	struct rte_pmd_i40e_profile_info info;
16527 	uint32_t dev_num = 0;
16528 	struct rte_pmd_i40e_ddp_device_id *devs;
16529 	uint32_t proto_num = 0;
16530 	struct rte_pmd_i40e_proto_info *proto = NULL;
16531 	uint32_t pctype_num = 0;
16532 	struct rte_pmd_i40e_ptype_info *pctype;
16533 	uint32_t ptype_num = 0;
16534 	struct rte_pmd_i40e_ptype_info *ptype;
16535 	uint8_t proto_id;
16536 
16537 #endif
16538 
16539 	pkg = open_file(res->filepath, &pkg_size);
16540 	if (!pkg)
16541 		return;
16542 
16543 #ifdef RTE_LIBRTE_I40E_PMD
16544 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16545 				(uint8_t *)&info, sizeof(info),
16546 				RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16547 	if (!ret) {
16548 		printf("Global Track id:       0x%x\n", info.track_id);
16549 		printf("Global Version:        %d.%d.%d.%d\n",
16550 			info.version.major,
16551 			info.version.minor,
16552 			info.version.update,
16553 			info.version.draft);
16554 		printf("Global Package name:   %s\n\n", info.name);
16555 	}
16556 
16557 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16558 				(uint8_t *)&info, sizeof(info),
16559 				RTE_PMD_I40E_PKG_INFO_HEADER);
16560 	if (!ret) {
16561 		printf("i40e Profile Track id: 0x%x\n", info.track_id);
16562 		printf("i40e Profile Version:  %d.%d.%d.%d\n",
16563 			info.version.major,
16564 			info.version.minor,
16565 			info.version.update,
16566 			info.version.draft);
16567 		printf("i40e Profile name:     %s\n\n", info.name);
16568 	}
16569 
16570 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16571 				(uint8_t *)&buff_size, sizeof(buff_size),
16572 				RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16573 	if (!ret && buff_size) {
16574 		buff = (uint8_t *)malloc(buff_size);
16575 		if (buff) {
16576 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16577 						buff, buff_size,
16578 						RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16579 			if (!ret)
16580 				printf("Package Notes:\n%s\n\n", buff);
16581 			free(buff);
16582 		}
16583 	}
16584 
16585 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16586 				(uint8_t *)&dev_num, sizeof(dev_num),
16587 				RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16588 	if (!ret && dev_num) {
16589 		buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16590 		devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16591 		if (devs) {
16592 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16593 						(uint8_t *)devs, buff_size,
16594 						RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16595 			if (!ret) {
16596 				printf("List of supported devices:\n");
16597 				for (i = 0; i < dev_num; i++) {
16598 					printf("  %04X:%04X %04X:%04X\n",
16599 						devs[i].vendor_dev_id >> 16,
16600 						devs[i].vendor_dev_id & 0xFFFF,
16601 						devs[i].sub_vendor_dev_id >> 16,
16602 						devs[i].sub_vendor_dev_id & 0xFFFF);
16603 				}
16604 				printf("\n");
16605 			}
16606 			free(devs);
16607 		}
16608 	}
16609 
16610 	/* get information about protocols and packet types */
16611 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16612 		(uint8_t *)&proto_num, sizeof(proto_num),
16613 		RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16614 	if (ret || !proto_num)
16615 		goto no_print_return;
16616 
16617 	buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16618 	proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16619 	if (!proto)
16620 		goto no_print_return;
16621 
16622 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16623 					buff_size,
16624 					RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16625 	if (!ret) {
16626 		printf("List of used protocols:\n");
16627 		for (i = 0; i < proto_num; i++)
16628 			printf("  %2u: %s\n", proto[i].proto_id,
16629 			       proto[i].name);
16630 		printf("\n");
16631 	}
16632 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16633 		(uint8_t *)&pctype_num, sizeof(pctype_num),
16634 		RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16635 	if (ret || !pctype_num)
16636 		goto no_print_pctypes;
16637 
16638 	buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16639 	pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16640 	if (!pctype)
16641 		goto no_print_pctypes;
16642 
16643 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16644 					buff_size,
16645 					RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16646 	if (ret) {
16647 		free(pctype);
16648 		goto no_print_pctypes;
16649 	}
16650 
16651 	printf("List of defined packet classification types:\n");
16652 	for (i = 0; i < pctype_num; i++) {
16653 		printf("  %2u:", pctype[i].ptype_id);
16654 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16655 			proto_id = pctype[i].protocols[j];
16656 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16657 				for (n = 0; n < proto_num; n++) {
16658 					if (proto[n].proto_id == proto_id) {
16659 						printf(" %s", proto[n].name);
16660 						break;
16661 					}
16662 				}
16663 			}
16664 		}
16665 		printf("\n");
16666 	}
16667 	printf("\n");
16668 	free(pctype);
16669 
16670 no_print_pctypes:
16671 
16672 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16673 					sizeof(ptype_num),
16674 					RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16675 	if (ret || !ptype_num)
16676 		goto no_print_return;
16677 
16678 	buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16679 	ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16680 	if (!ptype)
16681 		goto no_print_return;
16682 
16683 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16684 					buff_size,
16685 					RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16686 	if (ret) {
16687 		free(ptype);
16688 		goto no_print_return;
16689 	}
16690 	printf("List of defined packet types:\n");
16691 	for (i = 0; i < ptype_num; i++) {
16692 		printf("  %2u:", ptype[i].ptype_id);
16693 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16694 			proto_id = ptype[i].protocols[j];
16695 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16696 				for (n = 0; n < proto_num; n++) {
16697 					if (proto[n].proto_id == proto_id) {
16698 						printf(" %s", proto[n].name);
16699 						break;
16700 					}
16701 				}
16702 			}
16703 		}
16704 		printf("\n");
16705 	}
16706 	free(ptype);
16707 	printf("\n");
16708 
16709 	ret = 0;
16710 no_print_return:
16711 	if (proto)
16712 		free(proto);
16713 #endif
16714 	if (ret == -ENOTSUP)
16715 		printf("Function not supported in PMD driver\n");
16716 	close_file(pkg);
16717 }
16718 
16719 cmdline_parse_inst_t cmd_ddp_get_info = {
16720 	.f = cmd_ddp_info_parsed,
16721 	.data = NULL,
16722 	.help_str = "ddp get info <profile_path>",
16723 	.tokens = {
16724 		(void *)&cmd_ddp_info_ddp,
16725 		(void *)&cmd_ddp_info_get,
16726 		(void *)&cmd_ddp_info_info,
16727 		(void *)&cmd_ddp_info_filepath,
16728 		NULL,
16729 	},
16730 };
16731 
16732 /* Get dynamic device personalization profile info list*/
16733 #define PROFILE_INFO_SIZE 48
16734 #define MAX_PROFILE_NUM 16
16735 
16736 struct cmd_ddp_get_list_result {
16737 	cmdline_fixed_string_t ddp;
16738 	cmdline_fixed_string_t get;
16739 	cmdline_fixed_string_t list;
16740 	portid_t port_id;
16741 };
16742 
16743 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16744 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16745 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16746 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16747 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16748 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16749 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16750 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16751 
16752 static void
16753 cmd_ddp_get_list_parsed(
16754 	__attribute__((unused)) void *parsed_result,
16755 	__attribute__((unused)) struct cmdline *cl,
16756 	__attribute__((unused)) void *data)
16757 {
16758 #ifdef RTE_LIBRTE_I40E_PMD
16759 	struct cmd_ddp_get_list_result *res = parsed_result;
16760 	struct rte_pmd_i40e_profile_list *p_list;
16761 	struct rte_pmd_i40e_profile_info *p_info;
16762 	uint32_t p_num;
16763 	uint32_t size;
16764 	uint32_t i;
16765 #endif
16766 	int ret = -ENOTSUP;
16767 
16768 #ifdef RTE_LIBRTE_I40E_PMD
16769 	size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16770 	p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16771 	if (!p_list)
16772 		printf("%s: Failed to malloc buffer\n", __func__);
16773 
16774 	if (ret == -ENOTSUP)
16775 		ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16776 						(uint8_t *)p_list, size);
16777 
16778 	if (!ret) {
16779 		p_num = p_list->p_count;
16780 		printf("Profile number is: %d\n\n", p_num);
16781 
16782 		for (i = 0; i < p_num; i++) {
16783 			p_info = &p_list->p_info[i];
16784 			printf("Profile %d:\n", i);
16785 			printf("Track id:     0x%x\n", p_info->track_id);
16786 			printf("Version:      %d.%d.%d.%d\n",
16787 			       p_info->version.major,
16788 			       p_info->version.minor,
16789 			       p_info->version.update,
16790 			       p_info->version.draft);
16791 			printf("Profile name: %s\n\n", p_info->name);
16792 		}
16793 	}
16794 
16795 	free(p_list);
16796 #endif
16797 
16798 	if (ret < 0)
16799 		printf("Failed to get ddp list\n");
16800 }
16801 
16802 cmdline_parse_inst_t cmd_ddp_get_list = {
16803 	.f = cmd_ddp_get_list_parsed,
16804 	.data = NULL,
16805 	.help_str = "ddp get list <port_id>",
16806 	.tokens = {
16807 		(void *)&cmd_ddp_get_list_ddp,
16808 		(void *)&cmd_ddp_get_list_get,
16809 		(void *)&cmd_ddp_get_list_list,
16810 		(void *)&cmd_ddp_get_list_port_id,
16811 		NULL,
16812 	},
16813 };
16814 
16815 /* Configure input set */
16816 struct cmd_cfg_input_set_result {
16817 	cmdline_fixed_string_t port;
16818 	cmdline_fixed_string_t cfg;
16819 	portid_t port_id;
16820 	cmdline_fixed_string_t pctype;
16821 	uint8_t pctype_id;
16822 	cmdline_fixed_string_t inset_type;
16823 	cmdline_fixed_string_t opt;
16824 	cmdline_fixed_string_t field;
16825 	uint8_t field_idx;
16826 };
16827 
16828 static void
16829 cmd_cfg_input_set_parsed(
16830 	__attribute__((unused)) void *parsed_result,
16831 	__attribute__((unused)) struct cmdline *cl,
16832 	__attribute__((unused)) void *data)
16833 {
16834 #ifdef RTE_LIBRTE_I40E_PMD
16835 	struct cmd_cfg_input_set_result *res = parsed_result;
16836 	enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16837 	struct rte_pmd_i40e_inset inset;
16838 #endif
16839 	int ret = -ENOTSUP;
16840 
16841 	if (!all_ports_stopped()) {
16842 		printf("Please stop all ports first\n");
16843 		return;
16844 	}
16845 
16846 #ifdef RTE_LIBRTE_I40E_PMD
16847 	if (!strcmp(res->inset_type, "hash_inset"))
16848 		inset_type = INSET_HASH;
16849 	else if (!strcmp(res->inset_type, "fdir_inset"))
16850 		inset_type = INSET_FDIR;
16851 	else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16852 		inset_type = INSET_FDIR_FLX;
16853 	ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16854 				     &inset, inset_type);
16855 	if (ret) {
16856 		printf("Failed to get input set.\n");
16857 		return;
16858 	}
16859 
16860 	if (!strcmp(res->opt, "get")) {
16861 		ret = rte_pmd_i40e_inset_field_get(inset.inset,
16862 						   res->field_idx);
16863 		if (ret)
16864 			printf("Field index %d is enabled.\n", res->field_idx);
16865 		else
16866 			printf("Field index %d is disabled.\n", res->field_idx);
16867 		return;
16868 	} else if (!strcmp(res->opt, "set"))
16869 		ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16870 						   res->field_idx);
16871 	else if (!strcmp(res->opt, "clear"))
16872 		ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16873 						     res->field_idx);
16874 	if (ret) {
16875 		printf("Failed to configure input set field.\n");
16876 		return;
16877 	}
16878 
16879 	ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16880 				     &inset, inset_type);
16881 	if (ret) {
16882 		printf("Failed to set input set.\n");
16883 		return;
16884 	}
16885 #endif
16886 
16887 	if (ret == -ENOTSUP)
16888 		printf("Function not supported\n");
16889 }
16890 
16891 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16892 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16893 				 port, "port");
16894 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16895 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16896 				 cfg, "config");
16897 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16898 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16899 			      port_id, UINT16);
16900 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16901 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16902 				 pctype, "pctype");
16903 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16904 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16905 			      pctype_id, UINT8);
16906 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16907 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16908 				 inset_type,
16909 				 "hash_inset#fdir_inset#fdir_flx_inset");
16910 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16911 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16912 				 opt, "get#set#clear");
16913 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16914 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16915 				 field, "field");
16916 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16917 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16918 			      field_idx, UINT8);
16919 
16920 cmdline_parse_inst_t cmd_cfg_input_set = {
16921 	.f = cmd_cfg_input_set_parsed,
16922 	.data = NULL,
16923 	.help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16924 		    "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16925 	.tokens = {
16926 		(void *)&cmd_cfg_input_set_port,
16927 		(void *)&cmd_cfg_input_set_cfg,
16928 		(void *)&cmd_cfg_input_set_port_id,
16929 		(void *)&cmd_cfg_input_set_pctype,
16930 		(void *)&cmd_cfg_input_set_pctype_id,
16931 		(void *)&cmd_cfg_input_set_inset_type,
16932 		(void *)&cmd_cfg_input_set_opt,
16933 		(void *)&cmd_cfg_input_set_field,
16934 		(void *)&cmd_cfg_input_set_field_idx,
16935 		NULL,
16936 	},
16937 };
16938 
16939 /* Clear input set */
16940 struct cmd_clear_input_set_result {
16941 	cmdline_fixed_string_t port;
16942 	cmdline_fixed_string_t cfg;
16943 	portid_t port_id;
16944 	cmdline_fixed_string_t pctype;
16945 	uint8_t pctype_id;
16946 	cmdline_fixed_string_t inset_type;
16947 	cmdline_fixed_string_t clear;
16948 	cmdline_fixed_string_t all;
16949 };
16950 
16951 static void
16952 cmd_clear_input_set_parsed(
16953 	__attribute__((unused)) void *parsed_result,
16954 	__attribute__((unused)) struct cmdline *cl,
16955 	__attribute__((unused)) void *data)
16956 {
16957 #ifdef RTE_LIBRTE_I40E_PMD
16958 	struct cmd_clear_input_set_result *res = parsed_result;
16959 	enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16960 	struct rte_pmd_i40e_inset inset;
16961 #endif
16962 	int ret = -ENOTSUP;
16963 
16964 	if (!all_ports_stopped()) {
16965 		printf("Please stop all ports first\n");
16966 		return;
16967 	}
16968 
16969 #ifdef RTE_LIBRTE_I40E_PMD
16970 	if (!strcmp(res->inset_type, "hash_inset"))
16971 		inset_type = INSET_HASH;
16972 	else if (!strcmp(res->inset_type, "fdir_inset"))
16973 		inset_type = INSET_FDIR;
16974 	else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16975 		inset_type = INSET_FDIR_FLX;
16976 
16977 	memset(&inset, 0, sizeof(inset));
16978 
16979 	ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16980 				     &inset, inset_type);
16981 	if (ret) {
16982 		printf("Failed to clear input set.\n");
16983 		return;
16984 	}
16985 
16986 #endif
16987 
16988 	if (ret == -ENOTSUP)
16989 		printf("Function not supported\n");
16990 }
16991 
16992 cmdline_parse_token_string_t cmd_clear_input_set_port =
16993 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16994 				 port, "port");
16995 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16996 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16997 				 cfg, "config");
16998 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16999 	TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17000 			      port_id, UINT16);
17001 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17002 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17003 				 pctype, "pctype");
17004 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17005 	TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17006 			      pctype_id, UINT8);
17007 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17008 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17009 				 inset_type,
17010 				 "hash_inset#fdir_inset#fdir_flx_inset");
17011 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17012 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17013 				 clear, "clear");
17014 cmdline_parse_token_string_t cmd_clear_input_set_all =
17015 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17016 				 all, "all");
17017 
17018 cmdline_parse_inst_t cmd_clear_input_set = {
17019 	.f = cmd_clear_input_set_parsed,
17020 	.data = NULL,
17021 	.help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17022 		    "fdir_inset|fdir_flx_inset clear all",
17023 	.tokens = {
17024 		(void *)&cmd_clear_input_set_port,
17025 		(void *)&cmd_clear_input_set_cfg,
17026 		(void *)&cmd_clear_input_set_port_id,
17027 		(void *)&cmd_clear_input_set_pctype,
17028 		(void *)&cmd_clear_input_set_pctype_id,
17029 		(void *)&cmd_clear_input_set_inset_type,
17030 		(void *)&cmd_clear_input_set_clear,
17031 		(void *)&cmd_clear_input_set_all,
17032 		NULL,
17033 	},
17034 };
17035 
17036 /* show vf stats */
17037 
17038 /* Common result structure for show vf stats */
17039 struct cmd_show_vf_stats_result {
17040 	cmdline_fixed_string_t show;
17041 	cmdline_fixed_string_t vf;
17042 	cmdline_fixed_string_t stats;
17043 	portid_t port_id;
17044 	uint16_t vf_id;
17045 };
17046 
17047 /* Common CLI fields show vf stats*/
17048 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17049 	TOKEN_STRING_INITIALIZER
17050 		(struct cmd_show_vf_stats_result,
17051 		 show, "show");
17052 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17053 	TOKEN_STRING_INITIALIZER
17054 		(struct cmd_show_vf_stats_result,
17055 		 vf, "vf");
17056 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17057 	TOKEN_STRING_INITIALIZER
17058 		(struct cmd_show_vf_stats_result,
17059 		 stats, "stats");
17060 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17061 	TOKEN_NUM_INITIALIZER
17062 		(struct cmd_show_vf_stats_result,
17063 		 port_id, UINT16);
17064 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17065 	TOKEN_NUM_INITIALIZER
17066 		(struct cmd_show_vf_stats_result,
17067 		 vf_id, UINT16);
17068 
17069 static void
17070 cmd_show_vf_stats_parsed(
17071 	void *parsed_result,
17072 	__attribute__((unused)) struct cmdline *cl,
17073 	__attribute__((unused)) void *data)
17074 {
17075 	struct cmd_show_vf_stats_result *res = parsed_result;
17076 	struct rte_eth_stats stats;
17077 	int ret = -ENOTSUP;
17078 	static const char *nic_stats_border = "########################";
17079 
17080 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17081 		return;
17082 
17083 	memset(&stats, 0, sizeof(stats));
17084 
17085 #ifdef RTE_LIBRTE_I40E_PMD
17086 	if (ret == -ENOTSUP)
17087 		ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17088 						res->vf_id,
17089 						&stats);
17090 #endif
17091 #ifdef RTE_LIBRTE_BNXT_PMD
17092 	if (ret == -ENOTSUP)
17093 		ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17094 						res->vf_id,
17095 						&stats);
17096 #endif
17097 
17098 	switch (ret) {
17099 	case 0:
17100 		break;
17101 	case -EINVAL:
17102 		printf("invalid vf_id %d\n", res->vf_id);
17103 		break;
17104 	case -ENODEV:
17105 		printf("invalid port_id %d\n", res->port_id);
17106 		break;
17107 	case -ENOTSUP:
17108 		printf("function not implemented\n");
17109 		break;
17110 	default:
17111 		printf("programming error: (%s)\n", strerror(-ret));
17112 	}
17113 
17114 	printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17115 		nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17116 
17117 	printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17118 	       "%-"PRIu64"\n",
17119 	       stats.ipackets, stats.imissed, stats.ibytes);
17120 	printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17121 	printf("  RX-nombuf:  %-10"PRIu64"\n",
17122 	       stats.rx_nombuf);
17123 	printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17124 	       "%-"PRIu64"\n",
17125 	       stats.opackets, stats.oerrors, stats.obytes);
17126 
17127 	printf("  %s############################%s\n",
17128 			       nic_stats_border, nic_stats_border);
17129 }
17130 
17131 cmdline_parse_inst_t cmd_show_vf_stats = {
17132 	.f = cmd_show_vf_stats_parsed,
17133 	.data = NULL,
17134 	.help_str = "show vf stats <port_id> <vf_id>",
17135 	.tokens = {
17136 		(void *)&cmd_show_vf_stats_show,
17137 		(void *)&cmd_show_vf_stats_vf,
17138 		(void *)&cmd_show_vf_stats_stats,
17139 		(void *)&cmd_show_vf_stats_port_id,
17140 		(void *)&cmd_show_vf_stats_vf_id,
17141 		NULL,
17142 	},
17143 };
17144 
17145 /* clear vf stats */
17146 
17147 /* Common result structure for clear vf stats */
17148 struct cmd_clear_vf_stats_result {
17149 	cmdline_fixed_string_t clear;
17150 	cmdline_fixed_string_t vf;
17151 	cmdline_fixed_string_t stats;
17152 	portid_t port_id;
17153 	uint16_t vf_id;
17154 };
17155 
17156 /* Common CLI fields clear vf stats*/
17157 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17158 	TOKEN_STRING_INITIALIZER
17159 		(struct cmd_clear_vf_stats_result,
17160 		 clear, "clear");
17161 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17162 	TOKEN_STRING_INITIALIZER
17163 		(struct cmd_clear_vf_stats_result,
17164 		 vf, "vf");
17165 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17166 	TOKEN_STRING_INITIALIZER
17167 		(struct cmd_clear_vf_stats_result,
17168 		 stats, "stats");
17169 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17170 	TOKEN_NUM_INITIALIZER
17171 		(struct cmd_clear_vf_stats_result,
17172 		 port_id, UINT16);
17173 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17174 	TOKEN_NUM_INITIALIZER
17175 		(struct cmd_clear_vf_stats_result,
17176 		 vf_id, UINT16);
17177 
17178 static void
17179 cmd_clear_vf_stats_parsed(
17180 	void *parsed_result,
17181 	__attribute__((unused)) struct cmdline *cl,
17182 	__attribute__((unused)) void *data)
17183 {
17184 	struct cmd_clear_vf_stats_result *res = parsed_result;
17185 	int ret = -ENOTSUP;
17186 
17187 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17188 		return;
17189 
17190 #ifdef RTE_LIBRTE_I40E_PMD
17191 	if (ret == -ENOTSUP)
17192 		ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17193 						  res->vf_id);
17194 #endif
17195 #ifdef RTE_LIBRTE_BNXT_PMD
17196 	if (ret == -ENOTSUP)
17197 		ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17198 						  res->vf_id);
17199 #endif
17200 
17201 	switch (ret) {
17202 	case 0:
17203 		break;
17204 	case -EINVAL:
17205 		printf("invalid vf_id %d\n", res->vf_id);
17206 		break;
17207 	case -ENODEV:
17208 		printf("invalid port_id %d\n", res->port_id);
17209 		break;
17210 	case -ENOTSUP:
17211 		printf("function not implemented\n");
17212 		break;
17213 	default:
17214 		printf("programming error: (%s)\n", strerror(-ret));
17215 	}
17216 }
17217 
17218 cmdline_parse_inst_t cmd_clear_vf_stats = {
17219 	.f = cmd_clear_vf_stats_parsed,
17220 	.data = NULL,
17221 	.help_str = "clear vf stats <port_id> <vf_id>",
17222 	.tokens = {
17223 		(void *)&cmd_clear_vf_stats_clear,
17224 		(void *)&cmd_clear_vf_stats_vf,
17225 		(void *)&cmd_clear_vf_stats_stats,
17226 		(void *)&cmd_clear_vf_stats_port_id,
17227 		(void *)&cmd_clear_vf_stats_vf_id,
17228 		NULL,
17229 	},
17230 };
17231 
17232 /* port config pctype mapping reset */
17233 
17234 /* Common result structure for port config pctype mapping reset */
17235 struct cmd_pctype_mapping_reset_result {
17236 	cmdline_fixed_string_t port;
17237 	cmdline_fixed_string_t config;
17238 	portid_t port_id;
17239 	cmdline_fixed_string_t pctype;
17240 	cmdline_fixed_string_t mapping;
17241 	cmdline_fixed_string_t reset;
17242 };
17243 
17244 /* Common CLI fields for port config pctype mapping reset*/
17245 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17246 	TOKEN_STRING_INITIALIZER
17247 		(struct cmd_pctype_mapping_reset_result,
17248 		 port, "port");
17249 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17250 	TOKEN_STRING_INITIALIZER
17251 		(struct cmd_pctype_mapping_reset_result,
17252 		 config, "config");
17253 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17254 	TOKEN_NUM_INITIALIZER
17255 		(struct cmd_pctype_mapping_reset_result,
17256 		 port_id, UINT16);
17257 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17258 	TOKEN_STRING_INITIALIZER
17259 		(struct cmd_pctype_mapping_reset_result,
17260 		 pctype, "pctype");
17261 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17262 	TOKEN_STRING_INITIALIZER
17263 		(struct cmd_pctype_mapping_reset_result,
17264 		 mapping, "mapping");
17265 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17266 	TOKEN_STRING_INITIALIZER
17267 		(struct cmd_pctype_mapping_reset_result,
17268 		 reset, "reset");
17269 
17270 static void
17271 cmd_pctype_mapping_reset_parsed(
17272 	void *parsed_result,
17273 	__attribute__((unused)) struct cmdline *cl,
17274 	__attribute__((unused)) void *data)
17275 {
17276 	struct cmd_pctype_mapping_reset_result *res = parsed_result;
17277 	int ret = -ENOTSUP;
17278 
17279 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17280 		return;
17281 
17282 #ifdef RTE_LIBRTE_I40E_PMD
17283 	ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17284 #endif
17285 
17286 	switch (ret) {
17287 	case 0:
17288 		break;
17289 	case -ENODEV:
17290 		printf("invalid port_id %d\n", res->port_id);
17291 		break;
17292 	case -ENOTSUP:
17293 		printf("function not implemented\n");
17294 		break;
17295 	default:
17296 		printf("programming error: (%s)\n", strerror(-ret));
17297 	}
17298 }
17299 
17300 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17301 	.f = cmd_pctype_mapping_reset_parsed,
17302 	.data = NULL,
17303 	.help_str = "port config <port_id> pctype mapping reset",
17304 	.tokens = {
17305 		(void *)&cmd_pctype_mapping_reset_port,
17306 		(void *)&cmd_pctype_mapping_reset_config,
17307 		(void *)&cmd_pctype_mapping_reset_port_id,
17308 		(void *)&cmd_pctype_mapping_reset_pctype,
17309 		(void *)&cmd_pctype_mapping_reset_mapping,
17310 		(void *)&cmd_pctype_mapping_reset_reset,
17311 		NULL,
17312 	},
17313 };
17314 
17315 /* show port pctype mapping */
17316 
17317 /* Common result structure for show port pctype mapping */
17318 struct cmd_pctype_mapping_get_result {
17319 	cmdline_fixed_string_t show;
17320 	cmdline_fixed_string_t port;
17321 	portid_t port_id;
17322 	cmdline_fixed_string_t pctype;
17323 	cmdline_fixed_string_t mapping;
17324 };
17325 
17326 /* Common CLI fields for pctype mapping get */
17327 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17328 	TOKEN_STRING_INITIALIZER
17329 		(struct cmd_pctype_mapping_get_result,
17330 		 show, "show");
17331 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17332 	TOKEN_STRING_INITIALIZER
17333 		(struct cmd_pctype_mapping_get_result,
17334 		 port, "port");
17335 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17336 	TOKEN_NUM_INITIALIZER
17337 		(struct cmd_pctype_mapping_get_result,
17338 		 port_id, UINT16);
17339 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17340 	TOKEN_STRING_INITIALIZER
17341 		(struct cmd_pctype_mapping_get_result,
17342 		 pctype, "pctype");
17343 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17344 	TOKEN_STRING_INITIALIZER
17345 		(struct cmd_pctype_mapping_get_result,
17346 		 mapping, "mapping");
17347 
17348 static void
17349 cmd_pctype_mapping_get_parsed(
17350 	void *parsed_result,
17351 	__attribute__((unused)) struct cmdline *cl,
17352 	__attribute__((unused)) void *data)
17353 {
17354 	struct cmd_pctype_mapping_get_result *res = parsed_result;
17355 	int ret = -ENOTSUP;
17356 #ifdef RTE_LIBRTE_I40E_PMD
17357 	struct rte_pmd_i40e_flow_type_mapping
17358 				mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17359 	int i, j, first_pctype;
17360 #endif
17361 
17362 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17363 		return;
17364 
17365 #ifdef RTE_LIBRTE_I40E_PMD
17366 	ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17367 #endif
17368 
17369 	switch (ret) {
17370 	case 0:
17371 		break;
17372 	case -ENODEV:
17373 		printf("invalid port_id %d\n", res->port_id);
17374 		return;
17375 	case -ENOTSUP:
17376 		printf("function not implemented\n");
17377 		return;
17378 	default:
17379 		printf("programming error: (%s)\n", strerror(-ret));
17380 		return;
17381 	}
17382 
17383 #ifdef RTE_LIBRTE_I40E_PMD
17384 	for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17385 		if (mapping[i].pctype != 0ULL) {
17386 			first_pctype = 1;
17387 
17388 			printf("pctype: ");
17389 			for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17390 				if (mapping[i].pctype & (1ULL << j)) {
17391 					printf(first_pctype ?
17392 					       "%02d" : ",%02d", j);
17393 					first_pctype = 0;
17394 				}
17395 			}
17396 			printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17397 		}
17398 	}
17399 #endif
17400 }
17401 
17402 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17403 	.f = cmd_pctype_mapping_get_parsed,
17404 	.data = NULL,
17405 	.help_str = "show port <port_id> pctype mapping",
17406 	.tokens = {
17407 		(void *)&cmd_pctype_mapping_get_show,
17408 		(void *)&cmd_pctype_mapping_get_port,
17409 		(void *)&cmd_pctype_mapping_get_port_id,
17410 		(void *)&cmd_pctype_mapping_get_pctype,
17411 		(void *)&cmd_pctype_mapping_get_mapping,
17412 		NULL,
17413 	},
17414 };
17415 
17416 /* port config pctype mapping update */
17417 
17418 /* Common result structure for port config pctype mapping update */
17419 struct cmd_pctype_mapping_update_result {
17420 	cmdline_fixed_string_t port;
17421 	cmdline_fixed_string_t config;
17422 	portid_t port_id;
17423 	cmdline_fixed_string_t pctype;
17424 	cmdline_fixed_string_t mapping;
17425 	cmdline_fixed_string_t update;
17426 	cmdline_fixed_string_t pctype_list;
17427 	uint16_t flow_type;
17428 };
17429 
17430 /* Common CLI fields for pctype mapping update*/
17431 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17432 	TOKEN_STRING_INITIALIZER
17433 		(struct cmd_pctype_mapping_update_result,
17434 		 port, "port");
17435 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17436 	TOKEN_STRING_INITIALIZER
17437 		(struct cmd_pctype_mapping_update_result,
17438 		 config, "config");
17439 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17440 	TOKEN_NUM_INITIALIZER
17441 		(struct cmd_pctype_mapping_update_result,
17442 		 port_id, UINT16);
17443 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17444 	TOKEN_STRING_INITIALIZER
17445 		(struct cmd_pctype_mapping_update_result,
17446 		 pctype, "pctype");
17447 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17448 	TOKEN_STRING_INITIALIZER
17449 		(struct cmd_pctype_mapping_update_result,
17450 		 mapping, "mapping");
17451 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17452 	TOKEN_STRING_INITIALIZER
17453 		(struct cmd_pctype_mapping_update_result,
17454 		 update, "update");
17455 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17456 	TOKEN_STRING_INITIALIZER
17457 		(struct cmd_pctype_mapping_update_result,
17458 		 pctype_list, NULL);
17459 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17460 	TOKEN_NUM_INITIALIZER
17461 		(struct cmd_pctype_mapping_update_result,
17462 		 flow_type, UINT16);
17463 
17464 static void
17465 cmd_pctype_mapping_update_parsed(
17466 	void *parsed_result,
17467 	__attribute__((unused)) struct cmdline *cl,
17468 	__attribute__((unused)) void *data)
17469 {
17470 	struct cmd_pctype_mapping_update_result *res = parsed_result;
17471 	int ret = -ENOTSUP;
17472 #ifdef RTE_LIBRTE_I40E_PMD
17473 	struct rte_pmd_i40e_flow_type_mapping mapping;
17474 	unsigned int i;
17475 	unsigned int nb_item;
17476 	unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17477 #endif
17478 
17479 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17480 		return;
17481 
17482 #ifdef RTE_LIBRTE_I40E_PMD
17483 	nb_item = parse_item_list(res->pctype_list, "pctypes",
17484 				  RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17485 	mapping.flow_type = res->flow_type;
17486 	for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17487 		mapping.pctype |= (1ULL << pctype_list[i]);
17488 	ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17489 						&mapping,
17490 						1,
17491 						0);
17492 #endif
17493 
17494 	switch (ret) {
17495 	case 0:
17496 		break;
17497 	case -EINVAL:
17498 		printf("invalid pctype or flow type\n");
17499 		break;
17500 	case -ENODEV:
17501 		printf("invalid port_id %d\n", res->port_id);
17502 		break;
17503 	case -ENOTSUP:
17504 		printf("function not implemented\n");
17505 		break;
17506 	default:
17507 		printf("programming error: (%s)\n", strerror(-ret));
17508 	}
17509 }
17510 
17511 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17512 	.f = cmd_pctype_mapping_update_parsed,
17513 	.data = NULL,
17514 	.help_str = "port config <port_id> pctype mapping update"
17515 	" <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17516 	.tokens = {
17517 		(void *)&cmd_pctype_mapping_update_port,
17518 		(void *)&cmd_pctype_mapping_update_config,
17519 		(void *)&cmd_pctype_mapping_update_port_id,
17520 		(void *)&cmd_pctype_mapping_update_pctype,
17521 		(void *)&cmd_pctype_mapping_update_mapping,
17522 		(void *)&cmd_pctype_mapping_update_update,
17523 		(void *)&cmd_pctype_mapping_update_pc_type,
17524 		(void *)&cmd_pctype_mapping_update_flow_type,
17525 		NULL,
17526 	},
17527 };
17528 
17529 /* ptype mapping get */
17530 
17531 /* Common result structure for ptype mapping get */
17532 struct cmd_ptype_mapping_get_result {
17533 	cmdline_fixed_string_t ptype;
17534 	cmdline_fixed_string_t mapping;
17535 	cmdline_fixed_string_t get;
17536 	portid_t port_id;
17537 	uint8_t valid_only;
17538 };
17539 
17540 /* Common CLI fields for ptype mapping get */
17541 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17542 	TOKEN_STRING_INITIALIZER
17543 		(struct cmd_ptype_mapping_get_result,
17544 		 ptype, "ptype");
17545 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17546 	TOKEN_STRING_INITIALIZER
17547 		(struct cmd_ptype_mapping_get_result,
17548 		 mapping, "mapping");
17549 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17550 	TOKEN_STRING_INITIALIZER
17551 		(struct cmd_ptype_mapping_get_result,
17552 		 get, "get");
17553 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17554 	TOKEN_NUM_INITIALIZER
17555 		(struct cmd_ptype_mapping_get_result,
17556 		 port_id, UINT16);
17557 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17558 	TOKEN_NUM_INITIALIZER
17559 		(struct cmd_ptype_mapping_get_result,
17560 		 valid_only, UINT8);
17561 
17562 static void
17563 cmd_ptype_mapping_get_parsed(
17564 	void *parsed_result,
17565 	__attribute__((unused)) struct cmdline *cl,
17566 	__attribute__((unused)) void *data)
17567 {
17568 	struct cmd_ptype_mapping_get_result *res = parsed_result;
17569 	int ret = -ENOTSUP;
17570 #ifdef RTE_LIBRTE_I40E_PMD
17571 	int max_ptype_num = 256;
17572 	struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17573 	uint16_t count;
17574 	int i;
17575 #endif
17576 
17577 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17578 		return;
17579 
17580 #ifdef RTE_LIBRTE_I40E_PMD
17581 	ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17582 					mapping,
17583 					max_ptype_num,
17584 					&count,
17585 					res->valid_only);
17586 #endif
17587 
17588 	switch (ret) {
17589 	case 0:
17590 		break;
17591 	case -ENODEV:
17592 		printf("invalid port_id %d\n", res->port_id);
17593 		break;
17594 	case -ENOTSUP:
17595 		printf("function not implemented\n");
17596 		break;
17597 	default:
17598 		printf("programming error: (%s)\n", strerror(-ret));
17599 	}
17600 
17601 #ifdef RTE_LIBRTE_I40E_PMD
17602 	if (!ret) {
17603 		for (i = 0; i < count; i++)
17604 			printf("%3d\t0x%08x\n",
17605 				mapping[i].hw_ptype, mapping[i].sw_ptype);
17606 	}
17607 #endif
17608 }
17609 
17610 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17611 	.f = cmd_ptype_mapping_get_parsed,
17612 	.data = NULL,
17613 	.help_str = "ptype mapping get <port_id> <valid_only>",
17614 	.tokens = {
17615 		(void *)&cmd_ptype_mapping_get_ptype,
17616 		(void *)&cmd_ptype_mapping_get_mapping,
17617 		(void *)&cmd_ptype_mapping_get_get,
17618 		(void *)&cmd_ptype_mapping_get_port_id,
17619 		(void *)&cmd_ptype_mapping_get_valid_only,
17620 		NULL,
17621 	},
17622 };
17623 
17624 /* ptype mapping replace */
17625 
17626 /* Common result structure for ptype mapping replace */
17627 struct cmd_ptype_mapping_replace_result {
17628 	cmdline_fixed_string_t ptype;
17629 	cmdline_fixed_string_t mapping;
17630 	cmdline_fixed_string_t replace;
17631 	portid_t port_id;
17632 	uint32_t target;
17633 	uint8_t mask;
17634 	uint32_t pkt_type;
17635 };
17636 
17637 /* Common CLI fields for ptype mapping replace */
17638 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17639 	TOKEN_STRING_INITIALIZER
17640 		(struct cmd_ptype_mapping_replace_result,
17641 		 ptype, "ptype");
17642 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17643 	TOKEN_STRING_INITIALIZER
17644 		(struct cmd_ptype_mapping_replace_result,
17645 		 mapping, "mapping");
17646 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17647 	TOKEN_STRING_INITIALIZER
17648 		(struct cmd_ptype_mapping_replace_result,
17649 		 replace, "replace");
17650 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17651 	TOKEN_NUM_INITIALIZER
17652 		(struct cmd_ptype_mapping_replace_result,
17653 		 port_id, UINT16);
17654 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17655 	TOKEN_NUM_INITIALIZER
17656 		(struct cmd_ptype_mapping_replace_result,
17657 		 target, UINT32);
17658 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17659 	TOKEN_NUM_INITIALIZER
17660 		(struct cmd_ptype_mapping_replace_result,
17661 		 mask, UINT8);
17662 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17663 	TOKEN_NUM_INITIALIZER
17664 		(struct cmd_ptype_mapping_replace_result,
17665 		 pkt_type, UINT32);
17666 
17667 static void
17668 cmd_ptype_mapping_replace_parsed(
17669 	void *parsed_result,
17670 	__attribute__((unused)) struct cmdline *cl,
17671 	__attribute__((unused)) void *data)
17672 {
17673 	struct cmd_ptype_mapping_replace_result *res = parsed_result;
17674 	int ret = -ENOTSUP;
17675 
17676 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17677 		return;
17678 
17679 #ifdef RTE_LIBRTE_I40E_PMD
17680 	ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17681 					res->target,
17682 					res->mask,
17683 					res->pkt_type);
17684 #endif
17685 
17686 	switch (ret) {
17687 	case 0:
17688 		break;
17689 	case -EINVAL:
17690 		printf("invalid ptype 0x%8x or 0x%8x\n",
17691 				res->target, res->pkt_type);
17692 		break;
17693 	case -ENODEV:
17694 		printf("invalid port_id %d\n", res->port_id);
17695 		break;
17696 	case -ENOTSUP:
17697 		printf("function not implemented\n");
17698 		break;
17699 	default:
17700 		printf("programming error: (%s)\n", strerror(-ret));
17701 	}
17702 }
17703 
17704 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17705 	.f = cmd_ptype_mapping_replace_parsed,
17706 	.data = NULL,
17707 	.help_str =
17708 		"ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17709 	.tokens = {
17710 		(void *)&cmd_ptype_mapping_replace_ptype,
17711 		(void *)&cmd_ptype_mapping_replace_mapping,
17712 		(void *)&cmd_ptype_mapping_replace_replace,
17713 		(void *)&cmd_ptype_mapping_replace_port_id,
17714 		(void *)&cmd_ptype_mapping_replace_target,
17715 		(void *)&cmd_ptype_mapping_replace_mask,
17716 		(void *)&cmd_ptype_mapping_replace_pkt_type,
17717 		NULL,
17718 	},
17719 };
17720 
17721 /* ptype mapping reset */
17722 
17723 /* Common result structure for ptype mapping reset */
17724 struct cmd_ptype_mapping_reset_result {
17725 	cmdline_fixed_string_t ptype;
17726 	cmdline_fixed_string_t mapping;
17727 	cmdline_fixed_string_t reset;
17728 	portid_t port_id;
17729 };
17730 
17731 /* Common CLI fields for ptype mapping reset*/
17732 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17733 	TOKEN_STRING_INITIALIZER
17734 		(struct cmd_ptype_mapping_reset_result,
17735 		 ptype, "ptype");
17736 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17737 	TOKEN_STRING_INITIALIZER
17738 		(struct cmd_ptype_mapping_reset_result,
17739 		 mapping, "mapping");
17740 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17741 	TOKEN_STRING_INITIALIZER
17742 		(struct cmd_ptype_mapping_reset_result,
17743 		 reset, "reset");
17744 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17745 	TOKEN_NUM_INITIALIZER
17746 		(struct cmd_ptype_mapping_reset_result,
17747 		 port_id, UINT16);
17748 
17749 static void
17750 cmd_ptype_mapping_reset_parsed(
17751 	void *parsed_result,
17752 	__attribute__((unused)) struct cmdline *cl,
17753 	__attribute__((unused)) void *data)
17754 {
17755 	struct cmd_ptype_mapping_reset_result *res = parsed_result;
17756 	int ret = -ENOTSUP;
17757 
17758 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17759 		return;
17760 
17761 #ifdef RTE_LIBRTE_I40E_PMD
17762 	ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17763 #endif
17764 
17765 	switch (ret) {
17766 	case 0:
17767 		break;
17768 	case -ENODEV:
17769 		printf("invalid port_id %d\n", res->port_id);
17770 		break;
17771 	case -ENOTSUP:
17772 		printf("function not implemented\n");
17773 		break;
17774 	default:
17775 		printf("programming error: (%s)\n", strerror(-ret));
17776 	}
17777 }
17778 
17779 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17780 	.f = cmd_ptype_mapping_reset_parsed,
17781 	.data = NULL,
17782 	.help_str = "ptype mapping reset <port_id>",
17783 	.tokens = {
17784 		(void *)&cmd_ptype_mapping_reset_ptype,
17785 		(void *)&cmd_ptype_mapping_reset_mapping,
17786 		(void *)&cmd_ptype_mapping_reset_reset,
17787 		(void *)&cmd_ptype_mapping_reset_port_id,
17788 		NULL,
17789 	},
17790 };
17791 
17792 /* ptype mapping update */
17793 
17794 /* Common result structure for ptype mapping update */
17795 struct cmd_ptype_mapping_update_result {
17796 	cmdline_fixed_string_t ptype;
17797 	cmdline_fixed_string_t mapping;
17798 	cmdline_fixed_string_t reset;
17799 	portid_t port_id;
17800 	uint8_t hw_ptype;
17801 	uint32_t sw_ptype;
17802 };
17803 
17804 /* Common CLI fields for ptype mapping update*/
17805 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17806 	TOKEN_STRING_INITIALIZER
17807 		(struct cmd_ptype_mapping_update_result,
17808 		 ptype, "ptype");
17809 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17810 	TOKEN_STRING_INITIALIZER
17811 		(struct cmd_ptype_mapping_update_result,
17812 		 mapping, "mapping");
17813 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17814 	TOKEN_STRING_INITIALIZER
17815 		(struct cmd_ptype_mapping_update_result,
17816 		 reset, "update");
17817 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17818 	TOKEN_NUM_INITIALIZER
17819 		(struct cmd_ptype_mapping_update_result,
17820 		 port_id, UINT16);
17821 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17822 	TOKEN_NUM_INITIALIZER
17823 		(struct cmd_ptype_mapping_update_result,
17824 		 hw_ptype, UINT8);
17825 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17826 	TOKEN_NUM_INITIALIZER
17827 		(struct cmd_ptype_mapping_update_result,
17828 		 sw_ptype, UINT32);
17829 
17830 static void
17831 cmd_ptype_mapping_update_parsed(
17832 	void *parsed_result,
17833 	__attribute__((unused)) struct cmdline *cl,
17834 	__attribute__((unused)) void *data)
17835 {
17836 	struct cmd_ptype_mapping_update_result *res = parsed_result;
17837 	int ret = -ENOTSUP;
17838 #ifdef RTE_LIBRTE_I40E_PMD
17839 	struct rte_pmd_i40e_ptype_mapping mapping;
17840 #endif
17841 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17842 		return;
17843 
17844 #ifdef RTE_LIBRTE_I40E_PMD
17845 	mapping.hw_ptype = res->hw_ptype;
17846 	mapping.sw_ptype = res->sw_ptype;
17847 	ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17848 						&mapping,
17849 						1,
17850 						0);
17851 #endif
17852 
17853 	switch (ret) {
17854 	case 0:
17855 		break;
17856 	case -EINVAL:
17857 		printf("invalid ptype 0x%8x\n", res->sw_ptype);
17858 		break;
17859 	case -ENODEV:
17860 		printf("invalid port_id %d\n", res->port_id);
17861 		break;
17862 	case -ENOTSUP:
17863 		printf("function not implemented\n");
17864 		break;
17865 	default:
17866 		printf("programming error: (%s)\n", strerror(-ret));
17867 	}
17868 }
17869 
17870 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17871 	.f = cmd_ptype_mapping_update_parsed,
17872 	.data = NULL,
17873 	.help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17874 	.tokens = {
17875 		(void *)&cmd_ptype_mapping_update_ptype,
17876 		(void *)&cmd_ptype_mapping_update_mapping,
17877 		(void *)&cmd_ptype_mapping_update_update,
17878 		(void *)&cmd_ptype_mapping_update_port_id,
17879 		(void *)&cmd_ptype_mapping_update_hw_ptype,
17880 		(void *)&cmd_ptype_mapping_update_sw_ptype,
17881 		NULL,
17882 	},
17883 };
17884 
17885 /* Common result structure for file commands */
17886 struct cmd_cmdfile_result {
17887 	cmdline_fixed_string_t load;
17888 	cmdline_fixed_string_t filename;
17889 };
17890 
17891 /* Common CLI fields for file commands */
17892 cmdline_parse_token_string_t cmd_load_cmdfile =
17893 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17894 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17895 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17896 
17897 static void
17898 cmd_load_from_file_parsed(
17899 	void *parsed_result,
17900 	__attribute__((unused)) struct cmdline *cl,
17901 	__attribute__((unused)) void *data)
17902 {
17903 	struct cmd_cmdfile_result *res = parsed_result;
17904 
17905 	cmdline_read_from_file(res->filename);
17906 }
17907 
17908 cmdline_parse_inst_t cmd_load_from_file = {
17909 	.f = cmd_load_from_file_parsed,
17910 	.data = NULL,
17911 	.help_str = "load <filename>",
17912 	.tokens = {
17913 		(void *)&cmd_load_cmdfile,
17914 		(void *)&cmd_load_cmdfile_filename,
17915 		NULL,
17916 	},
17917 };
17918 
17919 /* Get Rx offloads capabilities */
17920 struct cmd_rx_offload_get_capa_result {
17921 	cmdline_fixed_string_t show;
17922 	cmdline_fixed_string_t port;
17923 	portid_t port_id;
17924 	cmdline_fixed_string_t rx_offload;
17925 	cmdline_fixed_string_t capabilities;
17926 };
17927 
17928 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17929 	TOKEN_STRING_INITIALIZER
17930 		(struct cmd_rx_offload_get_capa_result,
17931 		 show, "show");
17932 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17933 	TOKEN_STRING_INITIALIZER
17934 		(struct cmd_rx_offload_get_capa_result,
17935 		 port, "port");
17936 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17937 	TOKEN_NUM_INITIALIZER
17938 		(struct cmd_rx_offload_get_capa_result,
17939 		 port_id, UINT16);
17940 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17941 	TOKEN_STRING_INITIALIZER
17942 		(struct cmd_rx_offload_get_capa_result,
17943 		 rx_offload, "rx_offload");
17944 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17945 	TOKEN_STRING_INITIALIZER
17946 		(struct cmd_rx_offload_get_capa_result,
17947 		 capabilities, "capabilities");
17948 
17949 static void
17950 print_rx_offloads(uint64_t offloads)
17951 {
17952 	uint64_t single_offload;
17953 	int begin;
17954 	int end;
17955 	int bit;
17956 
17957 	if (offloads == 0)
17958 		return;
17959 
17960 	begin = __builtin_ctzll(offloads);
17961 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17962 
17963 	single_offload = 1ULL << begin;
17964 	for (bit = begin; bit < end; bit++) {
17965 		if (offloads & single_offload)
17966 			printf(" %s",
17967 			       rte_eth_dev_rx_offload_name(single_offload));
17968 		single_offload <<= 1;
17969 	}
17970 }
17971 
17972 static void
17973 cmd_rx_offload_get_capa_parsed(
17974 	void *parsed_result,
17975 	__attribute__((unused)) struct cmdline *cl,
17976 	__attribute__((unused)) void *data)
17977 {
17978 	struct cmd_rx_offload_get_capa_result *res = parsed_result;
17979 	struct rte_eth_dev_info dev_info;
17980 	portid_t port_id = res->port_id;
17981 	uint64_t queue_offloads;
17982 	uint64_t port_offloads;
17983 
17984 	rte_eth_dev_info_get(port_id, &dev_info);
17985 	queue_offloads = dev_info.rx_queue_offload_capa;
17986 	port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17987 
17988 	printf("Rx Offloading Capabilities of port %d :\n", port_id);
17989 	printf("  Per Queue :");
17990 	print_rx_offloads(queue_offloads);
17991 
17992 	printf("\n");
17993 	printf("  Per Port  :");
17994 	print_rx_offloads(port_offloads);
17995 	printf("\n\n");
17996 }
17997 
17998 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17999 	.f = cmd_rx_offload_get_capa_parsed,
18000 	.data = NULL,
18001 	.help_str = "show port <port_id> rx_offload capabilities",
18002 	.tokens = {
18003 		(void *)&cmd_rx_offload_get_capa_show,
18004 		(void *)&cmd_rx_offload_get_capa_port,
18005 		(void *)&cmd_rx_offload_get_capa_port_id,
18006 		(void *)&cmd_rx_offload_get_capa_rx_offload,
18007 		(void *)&cmd_rx_offload_get_capa_capabilities,
18008 		NULL,
18009 	}
18010 };
18011 
18012 /* Get Rx offloads configuration */
18013 struct cmd_rx_offload_get_configuration_result {
18014 	cmdline_fixed_string_t show;
18015 	cmdline_fixed_string_t port;
18016 	portid_t port_id;
18017 	cmdline_fixed_string_t rx_offload;
18018 	cmdline_fixed_string_t configuration;
18019 };
18020 
18021 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18022 	TOKEN_STRING_INITIALIZER
18023 		(struct cmd_rx_offload_get_configuration_result,
18024 		 show, "show");
18025 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18026 	TOKEN_STRING_INITIALIZER
18027 		(struct cmd_rx_offload_get_configuration_result,
18028 		 port, "port");
18029 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18030 	TOKEN_NUM_INITIALIZER
18031 		(struct cmd_rx_offload_get_configuration_result,
18032 		 port_id, UINT16);
18033 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18034 	TOKEN_STRING_INITIALIZER
18035 		(struct cmd_rx_offload_get_configuration_result,
18036 		 rx_offload, "rx_offload");
18037 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18038 	TOKEN_STRING_INITIALIZER
18039 		(struct cmd_rx_offload_get_configuration_result,
18040 		 configuration, "configuration");
18041 
18042 static void
18043 cmd_rx_offload_get_configuration_parsed(
18044 	void *parsed_result,
18045 	__attribute__((unused)) struct cmdline *cl,
18046 	__attribute__((unused)) void *data)
18047 {
18048 	struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18049 	struct rte_eth_dev_info dev_info;
18050 	portid_t port_id = res->port_id;
18051 	struct rte_port *port = &ports[port_id];
18052 	uint64_t port_offloads;
18053 	uint64_t queue_offloads;
18054 	uint16_t nb_rx_queues;
18055 	int q;
18056 
18057 	printf("Rx Offloading Configuration of port %d :\n", port_id);
18058 
18059 	port_offloads = port->dev_conf.rxmode.offloads;
18060 	printf("  Port :");
18061 	print_rx_offloads(port_offloads);
18062 	printf("\n");
18063 
18064 	rte_eth_dev_info_get(port_id, &dev_info);
18065 	nb_rx_queues = dev_info.nb_rx_queues;
18066 	for (q = 0; q < nb_rx_queues; q++) {
18067 		queue_offloads = port->rx_conf[q].offloads;
18068 		printf("  Queue[%2d] :", q);
18069 		print_rx_offloads(queue_offloads);
18070 		printf("\n");
18071 	}
18072 	printf("\n");
18073 }
18074 
18075 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18076 	.f = cmd_rx_offload_get_configuration_parsed,
18077 	.data = NULL,
18078 	.help_str = "show port <port_id> rx_offload configuration",
18079 	.tokens = {
18080 		(void *)&cmd_rx_offload_get_configuration_show,
18081 		(void *)&cmd_rx_offload_get_configuration_port,
18082 		(void *)&cmd_rx_offload_get_configuration_port_id,
18083 		(void *)&cmd_rx_offload_get_configuration_rx_offload,
18084 		(void *)&cmd_rx_offload_get_configuration_configuration,
18085 		NULL,
18086 	}
18087 };
18088 
18089 /* Enable/Disable a per port offloading */
18090 struct cmd_config_per_port_rx_offload_result {
18091 	cmdline_fixed_string_t port;
18092 	cmdline_fixed_string_t config;
18093 	portid_t port_id;
18094 	cmdline_fixed_string_t rx_offload;
18095 	cmdline_fixed_string_t offload;
18096 	cmdline_fixed_string_t on_off;
18097 };
18098 
18099 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18100 	TOKEN_STRING_INITIALIZER
18101 		(struct cmd_config_per_port_rx_offload_result,
18102 		 port, "port");
18103 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18104 	TOKEN_STRING_INITIALIZER
18105 		(struct cmd_config_per_port_rx_offload_result,
18106 		 config, "config");
18107 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18108 	TOKEN_NUM_INITIALIZER
18109 		(struct cmd_config_per_port_rx_offload_result,
18110 		 port_id, UINT16);
18111 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18112 	TOKEN_STRING_INITIALIZER
18113 		(struct cmd_config_per_port_rx_offload_result,
18114 		 rx_offload, "rx_offload");
18115 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18116 	TOKEN_STRING_INITIALIZER
18117 		(struct cmd_config_per_port_rx_offload_result,
18118 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18119 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18120 			   "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18121 			   "crc_strip#scatter#timestamp#security#keep_crc");
18122 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18123 	TOKEN_STRING_INITIALIZER
18124 		(struct cmd_config_per_port_rx_offload_result,
18125 		 on_off, "on#off");
18126 
18127 static uint64_t
18128 search_rx_offload(const char *name)
18129 {
18130 	uint64_t single_offload;
18131 	const char *single_name;
18132 	int found = 0;
18133 	unsigned int bit;
18134 
18135 	single_offload = 1;
18136 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18137 		single_name = rte_eth_dev_rx_offload_name(single_offload);
18138 		if (!strcasecmp(single_name, name)) {
18139 			found = 1;
18140 			break;
18141 		}
18142 		single_offload <<= 1;
18143 	}
18144 
18145 	if (found)
18146 		return single_offload;
18147 
18148 	return 0;
18149 }
18150 
18151 static void
18152 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18153 				__attribute__((unused)) struct cmdline *cl,
18154 				__attribute__((unused)) void *data)
18155 {
18156 	struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18157 	portid_t port_id = res->port_id;
18158 	struct rte_eth_dev_info dev_info;
18159 	struct rte_port *port = &ports[port_id];
18160 	uint64_t single_offload;
18161 	uint16_t nb_rx_queues;
18162 	int q;
18163 
18164 	if (port->port_status != RTE_PORT_STOPPED) {
18165 		printf("Error: Can't config offload when Port %d "
18166 		       "is not stopped\n", port_id);
18167 		return;
18168 	}
18169 
18170 	single_offload = search_rx_offload(res->offload);
18171 	if (single_offload == 0) {
18172 		printf("Unknown offload name: %s\n", res->offload);
18173 		return;
18174 	}
18175 
18176 	rte_eth_dev_info_get(port_id, &dev_info);
18177 	nb_rx_queues = dev_info.nb_rx_queues;
18178 	if (!strcmp(res->on_off, "on")) {
18179 		port->dev_conf.rxmode.offloads |= single_offload;
18180 		for (q = 0; q < nb_rx_queues; q++)
18181 			port->rx_conf[q].offloads |= single_offload;
18182 	} else {
18183 		port->dev_conf.rxmode.offloads &= ~single_offload;
18184 		for (q = 0; q < nb_rx_queues; q++)
18185 			port->rx_conf[q].offloads &= ~single_offload;
18186 	}
18187 
18188 	cmd_reconfig_device_queue(port_id, 1, 1);
18189 }
18190 
18191 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18192 	.f = cmd_config_per_port_rx_offload_parsed,
18193 	.data = NULL,
18194 	.help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18195 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18196 		    "macsec_strip|header_split|vlan_filter|vlan_extend|"
18197 		    "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18198 		    "on|off",
18199 	.tokens = {
18200 		(void *)&cmd_config_per_port_rx_offload_result_port,
18201 		(void *)&cmd_config_per_port_rx_offload_result_config,
18202 		(void *)&cmd_config_per_port_rx_offload_result_port_id,
18203 		(void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18204 		(void *)&cmd_config_per_port_rx_offload_result_offload,
18205 		(void *)&cmd_config_per_port_rx_offload_result_on_off,
18206 		NULL,
18207 	}
18208 };
18209 
18210 /* Enable/Disable a per queue offloading */
18211 struct cmd_config_per_queue_rx_offload_result {
18212 	cmdline_fixed_string_t port;
18213 	portid_t port_id;
18214 	cmdline_fixed_string_t rxq;
18215 	uint16_t queue_id;
18216 	cmdline_fixed_string_t rx_offload;
18217 	cmdline_fixed_string_t offload;
18218 	cmdline_fixed_string_t on_off;
18219 };
18220 
18221 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18222 	TOKEN_STRING_INITIALIZER
18223 		(struct cmd_config_per_queue_rx_offload_result,
18224 		 port, "port");
18225 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18226 	TOKEN_NUM_INITIALIZER
18227 		(struct cmd_config_per_queue_rx_offload_result,
18228 		 port_id, UINT16);
18229 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18230 	TOKEN_STRING_INITIALIZER
18231 		(struct cmd_config_per_queue_rx_offload_result,
18232 		 rxq, "rxq");
18233 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18234 	TOKEN_NUM_INITIALIZER
18235 		(struct cmd_config_per_queue_rx_offload_result,
18236 		 queue_id, UINT16);
18237 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18238 	TOKEN_STRING_INITIALIZER
18239 		(struct cmd_config_per_queue_rx_offload_result,
18240 		 rx_offload, "rx_offload");
18241 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18242 	TOKEN_STRING_INITIALIZER
18243 		(struct cmd_config_per_queue_rx_offload_result,
18244 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18245 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18246 			   "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18247 			   "crc_strip#scatter#timestamp#security#keep_crc");
18248 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18249 	TOKEN_STRING_INITIALIZER
18250 		(struct cmd_config_per_queue_rx_offload_result,
18251 		 on_off, "on#off");
18252 
18253 static void
18254 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18255 				__attribute__((unused)) struct cmdline *cl,
18256 				__attribute__((unused)) void *data)
18257 {
18258 	struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18259 	struct rte_eth_dev_info dev_info;
18260 	portid_t port_id = res->port_id;
18261 	uint16_t queue_id = res->queue_id;
18262 	struct rte_port *port = &ports[port_id];
18263 	uint64_t single_offload;
18264 
18265 	if (port->port_status != RTE_PORT_STOPPED) {
18266 		printf("Error: Can't config offload when Port %d "
18267 		       "is not stopped\n", port_id);
18268 		return;
18269 	}
18270 
18271 	rte_eth_dev_info_get(port_id, &dev_info);
18272 	if (queue_id >= dev_info.nb_rx_queues) {
18273 		printf("Error: input queue_id should be 0 ... "
18274 		       "%d\n", dev_info.nb_rx_queues - 1);
18275 		return;
18276 	}
18277 
18278 	single_offload = search_rx_offload(res->offload);
18279 	if (single_offload == 0) {
18280 		printf("Unknown offload name: %s\n", res->offload);
18281 		return;
18282 	}
18283 
18284 	if (!strcmp(res->on_off, "on"))
18285 		port->rx_conf[queue_id].offloads |= single_offload;
18286 	else
18287 		port->rx_conf[queue_id].offloads &= ~single_offload;
18288 
18289 	cmd_reconfig_device_queue(port_id, 1, 1);
18290 }
18291 
18292 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18293 	.f = cmd_config_per_queue_rx_offload_parsed,
18294 	.data = NULL,
18295 	.help_str = "port <port_id> rxq <queue_id> rx_offload "
18296 		    "vlan_strip|ipv4_cksum|"
18297 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18298 		    "macsec_strip|header_split|vlan_filter|vlan_extend|"
18299 		    "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18300 		    "on|off",
18301 	.tokens = {
18302 		(void *)&cmd_config_per_queue_rx_offload_result_port,
18303 		(void *)&cmd_config_per_queue_rx_offload_result_port_id,
18304 		(void *)&cmd_config_per_queue_rx_offload_result_rxq,
18305 		(void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18306 		(void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18307 		(void *)&cmd_config_per_queue_rx_offload_result_offload,
18308 		(void *)&cmd_config_per_queue_rx_offload_result_on_off,
18309 		NULL,
18310 	}
18311 };
18312 
18313 /* Get Tx offloads capabilities */
18314 struct cmd_tx_offload_get_capa_result {
18315 	cmdline_fixed_string_t show;
18316 	cmdline_fixed_string_t port;
18317 	portid_t port_id;
18318 	cmdline_fixed_string_t tx_offload;
18319 	cmdline_fixed_string_t capabilities;
18320 };
18321 
18322 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18323 	TOKEN_STRING_INITIALIZER
18324 		(struct cmd_tx_offload_get_capa_result,
18325 		 show, "show");
18326 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18327 	TOKEN_STRING_INITIALIZER
18328 		(struct cmd_tx_offload_get_capa_result,
18329 		 port, "port");
18330 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18331 	TOKEN_NUM_INITIALIZER
18332 		(struct cmd_tx_offload_get_capa_result,
18333 		 port_id, UINT16);
18334 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18335 	TOKEN_STRING_INITIALIZER
18336 		(struct cmd_tx_offload_get_capa_result,
18337 		 tx_offload, "tx_offload");
18338 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18339 	TOKEN_STRING_INITIALIZER
18340 		(struct cmd_tx_offload_get_capa_result,
18341 		 capabilities, "capabilities");
18342 
18343 static void
18344 print_tx_offloads(uint64_t offloads)
18345 {
18346 	uint64_t single_offload;
18347 	int begin;
18348 	int end;
18349 	int bit;
18350 
18351 	if (offloads == 0)
18352 		return;
18353 
18354 	begin = __builtin_ctzll(offloads);
18355 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18356 
18357 	single_offload = 1ULL << begin;
18358 	for (bit = begin; bit < end; bit++) {
18359 		if (offloads & single_offload)
18360 			printf(" %s",
18361 			       rte_eth_dev_tx_offload_name(single_offload));
18362 		single_offload <<= 1;
18363 	}
18364 }
18365 
18366 static void
18367 cmd_tx_offload_get_capa_parsed(
18368 	void *parsed_result,
18369 	__attribute__((unused)) struct cmdline *cl,
18370 	__attribute__((unused)) void *data)
18371 {
18372 	struct cmd_tx_offload_get_capa_result *res = parsed_result;
18373 	struct rte_eth_dev_info dev_info;
18374 	portid_t port_id = res->port_id;
18375 	uint64_t queue_offloads;
18376 	uint64_t port_offloads;
18377 
18378 	rte_eth_dev_info_get(port_id, &dev_info);
18379 	queue_offloads = dev_info.tx_queue_offload_capa;
18380 	port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18381 
18382 	printf("Tx Offloading Capabilities of port %d :\n", port_id);
18383 	printf("  Per Queue :");
18384 	print_tx_offloads(queue_offloads);
18385 
18386 	printf("\n");
18387 	printf("  Per Port  :");
18388 	print_tx_offloads(port_offloads);
18389 	printf("\n\n");
18390 }
18391 
18392 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18393 	.f = cmd_tx_offload_get_capa_parsed,
18394 	.data = NULL,
18395 	.help_str = "show port <port_id> tx_offload capabilities",
18396 	.tokens = {
18397 		(void *)&cmd_tx_offload_get_capa_show,
18398 		(void *)&cmd_tx_offload_get_capa_port,
18399 		(void *)&cmd_tx_offload_get_capa_port_id,
18400 		(void *)&cmd_tx_offload_get_capa_tx_offload,
18401 		(void *)&cmd_tx_offload_get_capa_capabilities,
18402 		NULL,
18403 	}
18404 };
18405 
18406 /* Get Tx offloads configuration */
18407 struct cmd_tx_offload_get_configuration_result {
18408 	cmdline_fixed_string_t show;
18409 	cmdline_fixed_string_t port;
18410 	portid_t port_id;
18411 	cmdline_fixed_string_t tx_offload;
18412 	cmdline_fixed_string_t configuration;
18413 };
18414 
18415 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18416 	TOKEN_STRING_INITIALIZER
18417 		(struct cmd_tx_offload_get_configuration_result,
18418 		 show, "show");
18419 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18420 	TOKEN_STRING_INITIALIZER
18421 		(struct cmd_tx_offload_get_configuration_result,
18422 		 port, "port");
18423 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18424 	TOKEN_NUM_INITIALIZER
18425 		(struct cmd_tx_offload_get_configuration_result,
18426 		 port_id, UINT16);
18427 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18428 	TOKEN_STRING_INITIALIZER
18429 		(struct cmd_tx_offload_get_configuration_result,
18430 		 tx_offload, "tx_offload");
18431 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18432 	TOKEN_STRING_INITIALIZER
18433 		(struct cmd_tx_offload_get_configuration_result,
18434 		 configuration, "configuration");
18435 
18436 static void
18437 cmd_tx_offload_get_configuration_parsed(
18438 	void *parsed_result,
18439 	__attribute__((unused)) struct cmdline *cl,
18440 	__attribute__((unused)) void *data)
18441 {
18442 	struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18443 	struct rte_eth_dev_info dev_info;
18444 	portid_t port_id = res->port_id;
18445 	struct rte_port *port = &ports[port_id];
18446 	uint64_t port_offloads;
18447 	uint64_t queue_offloads;
18448 	uint16_t nb_tx_queues;
18449 	int q;
18450 
18451 	printf("Tx Offloading Configuration of port %d :\n", port_id);
18452 
18453 	port_offloads = port->dev_conf.txmode.offloads;
18454 	printf("  Port :");
18455 	print_tx_offloads(port_offloads);
18456 	printf("\n");
18457 
18458 	rte_eth_dev_info_get(port_id, &dev_info);
18459 	nb_tx_queues = dev_info.nb_tx_queues;
18460 	for (q = 0; q < nb_tx_queues; q++) {
18461 		queue_offloads = port->tx_conf[q].offloads;
18462 		printf("  Queue[%2d] :", q);
18463 		print_tx_offloads(queue_offloads);
18464 		printf("\n");
18465 	}
18466 	printf("\n");
18467 }
18468 
18469 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18470 	.f = cmd_tx_offload_get_configuration_parsed,
18471 	.data = NULL,
18472 	.help_str = "show port <port_id> tx_offload configuration",
18473 	.tokens = {
18474 		(void *)&cmd_tx_offload_get_configuration_show,
18475 		(void *)&cmd_tx_offload_get_configuration_port,
18476 		(void *)&cmd_tx_offload_get_configuration_port_id,
18477 		(void *)&cmd_tx_offload_get_configuration_tx_offload,
18478 		(void *)&cmd_tx_offload_get_configuration_configuration,
18479 		NULL,
18480 	}
18481 };
18482 
18483 /* Enable/Disable a per port offloading */
18484 struct cmd_config_per_port_tx_offload_result {
18485 	cmdline_fixed_string_t port;
18486 	cmdline_fixed_string_t config;
18487 	portid_t port_id;
18488 	cmdline_fixed_string_t tx_offload;
18489 	cmdline_fixed_string_t offload;
18490 	cmdline_fixed_string_t on_off;
18491 };
18492 
18493 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18494 	TOKEN_STRING_INITIALIZER
18495 		(struct cmd_config_per_port_tx_offload_result,
18496 		 port, "port");
18497 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18498 	TOKEN_STRING_INITIALIZER
18499 		(struct cmd_config_per_port_tx_offload_result,
18500 		 config, "config");
18501 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18502 	TOKEN_NUM_INITIALIZER
18503 		(struct cmd_config_per_port_tx_offload_result,
18504 		 port_id, UINT16);
18505 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18506 	TOKEN_STRING_INITIALIZER
18507 		(struct cmd_config_per_port_tx_offload_result,
18508 		 tx_offload, "tx_offload");
18509 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18510 	TOKEN_STRING_INITIALIZER
18511 		(struct cmd_config_per_port_tx_offload_result,
18512 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18513 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18514 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18515 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18516 			  "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18517 			  "match_metadata");
18518 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18519 	TOKEN_STRING_INITIALIZER
18520 		(struct cmd_config_per_port_tx_offload_result,
18521 		 on_off, "on#off");
18522 
18523 static uint64_t
18524 search_tx_offload(const char *name)
18525 {
18526 	uint64_t single_offload;
18527 	const char *single_name;
18528 	int found = 0;
18529 	unsigned int bit;
18530 
18531 	single_offload = 1;
18532 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18533 		single_name = rte_eth_dev_tx_offload_name(single_offload);
18534 		if (single_name == NULL)
18535 			break;
18536 		if (!strcasecmp(single_name, name)) {
18537 			found = 1;
18538 			break;
18539 		} else if (!strcasecmp(single_name, "UNKNOWN"))
18540 			break;
18541 		single_offload <<= 1;
18542 	}
18543 
18544 	if (found)
18545 		return single_offload;
18546 
18547 	return 0;
18548 }
18549 
18550 static void
18551 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18552 				__attribute__((unused)) struct cmdline *cl,
18553 				__attribute__((unused)) void *data)
18554 {
18555 	struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18556 	portid_t port_id = res->port_id;
18557 	struct rte_eth_dev_info dev_info;
18558 	struct rte_port *port = &ports[port_id];
18559 	uint64_t single_offload;
18560 	uint16_t nb_tx_queues;
18561 	int q;
18562 
18563 	if (port->port_status != RTE_PORT_STOPPED) {
18564 		printf("Error: Can't config offload when Port %d "
18565 		       "is not stopped\n", port_id);
18566 		return;
18567 	}
18568 
18569 	single_offload = search_tx_offload(res->offload);
18570 	if (single_offload == 0) {
18571 		printf("Unknown offload name: %s\n", res->offload);
18572 		return;
18573 	}
18574 
18575 	rte_eth_dev_info_get(port_id, &dev_info);
18576 	nb_tx_queues = dev_info.nb_tx_queues;
18577 	if (!strcmp(res->on_off, "on")) {
18578 		port->dev_conf.txmode.offloads |= single_offload;
18579 		for (q = 0; q < nb_tx_queues; q++)
18580 			port->tx_conf[q].offloads |= single_offload;
18581 	} else {
18582 		port->dev_conf.txmode.offloads &= ~single_offload;
18583 		for (q = 0; q < nb_tx_queues; q++)
18584 			port->tx_conf[q].offloads &= ~single_offload;
18585 	}
18586 
18587 	cmd_reconfig_device_queue(port_id, 1, 1);
18588 }
18589 
18590 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18591 	.f = cmd_config_per_port_tx_offload_parsed,
18592 	.data = NULL,
18593 	.help_str = "port config <port_id> tx_offload "
18594 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18595 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18596 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18597 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18598 		    "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18599 		    "match_metadata on|off",
18600 	.tokens = {
18601 		(void *)&cmd_config_per_port_tx_offload_result_port,
18602 		(void *)&cmd_config_per_port_tx_offload_result_config,
18603 		(void *)&cmd_config_per_port_tx_offload_result_port_id,
18604 		(void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18605 		(void *)&cmd_config_per_port_tx_offload_result_offload,
18606 		(void *)&cmd_config_per_port_tx_offload_result_on_off,
18607 		NULL,
18608 	}
18609 };
18610 
18611 /* Enable/Disable a per queue offloading */
18612 struct cmd_config_per_queue_tx_offload_result {
18613 	cmdline_fixed_string_t port;
18614 	portid_t port_id;
18615 	cmdline_fixed_string_t txq;
18616 	uint16_t queue_id;
18617 	cmdline_fixed_string_t tx_offload;
18618 	cmdline_fixed_string_t offload;
18619 	cmdline_fixed_string_t on_off;
18620 };
18621 
18622 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18623 	TOKEN_STRING_INITIALIZER
18624 		(struct cmd_config_per_queue_tx_offload_result,
18625 		 port, "port");
18626 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18627 	TOKEN_NUM_INITIALIZER
18628 		(struct cmd_config_per_queue_tx_offload_result,
18629 		 port_id, UINT16);
18630 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18631 	TOKEN_STRING_INITIALIZER
18632 		(struct cmd_config_per_queue_tx_offload_result,
18633 		 txq, "txq");
18634 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18635 	TOKEN_NUM_INITIALIZER
18636 		(struct cmd_config_per_queue_tx_offload_result,
18637 		 queue_id, UINT16);
18638 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18639 	TOKEN_STRING_INITIALIZER
18640 		(struct cmd_config_per_queue_tx_offload_result,
18641 		 tx_offload, "tx_offload");
18642 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18643 	TOKEN_STRING_INITIALIZER
18644 		(struct cmd_config_per_queue_tx_offload_result,
18645 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18646 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18647 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18648 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18649 			  "mt_lockfree#multi_segs#mbuf_fast_free#security");
18650 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18651 	TOKEN_STRING_INITIALIZER
18652 		(struct cmd_config_per_queue_tx_offload_result,
18653 		 on_off, "on#off");
18654 
18655 static void
18656 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18657 				__attribute__((unused)) struct cmdline *cl,
18658 				__attribute__((unused)) void *data)
18659 {
18660 	struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18661 	struct rte_eth_dev_info dev_info;
18662 	portid_t port_id = res->port_id;
18663 	uint16_t queue_id = res->queue_id;
18664 	struct rte_port *port = &ports[port_id];
18665 	uint64_t single_offload;
18666 
18667 	if (port->port_status != RTE_PORT_STOPPED) {
18668 		printf("Error: Can't config offload when Port %d "
18669 		       "is not stopped\n", port_id);
18670 		return;
18671 	}
18672 
18673 	rte_eth_dev_info_get(port_id, &dev_info);
18674 	if (queue_id >= dev_info.nb_tx_queues) {
18675 		printf("Error: input queue_id should be 0 ... "
18676 		       "%d\n", dev_info.nb_tx_queues - 1);
18677 		return;
18678 	}
18679 
18680 	single_offload = search_tx_offload(res->offload);
18681 	if (single_offload == 0) {
18682 		printf("Unknown offload name: %s\n", res->offload);
18683 		return;
18684 	}
18685 
18686 	if (!strcmp(res->on_off, "on"))
18687 		port->tx_conf[queue_id].offloads |= single_offload;
18688 	else
18689 		port->tx_conf[queue_id].offloads &= ~single_offload;
18690 
18691 	cmd_reconfig_device_queue(port_id, 1, 1);
18692 }
18693 
18694 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18695 	.f = cmd_config_per_queue_tx_offload_parsed,
18696 	.data = NULL,
18697 	.help_str = "port <port_id> txq <queue_id> tx_offload "
18698 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18699 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18700 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18701 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18702 		    "mt_lockfree|multi_segs|mbuf_fast_free|security "
18703 		    "on|off",
18704 	.tokens = {
18705 		(void *)&cmd_config_per_queue_tx_offload_result_port,
18706 		(void *)&cmd_config_per_queue_tx_offload_result_port_id,
18707 		(void *)&cmd_config_per_queue_tx_offload_result_txq,
18708 		(void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18709 		(void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18710 		(void *)&cmd_config_per_queue_tx_offload_result_offload,
18711 		(void *)&cmd_config_per_queue_tx_offload_result_on_off,
18712 		NULL,
18713 	}
18714 };
18715 
18716 /* *** configure tx_metadata for specific port *** */
18717 struct cmd_config_tx_metadata_specific_result {
18718 	cmdline_fixed_string_t port;
18719 	cmdline_fixed_string_t keyword;
18720 	uint16_t port_id;
18721 	cmdline_fixed_string_t item;
18722 	uint32_t value;
18723 };
18724 
18725 static void
18726 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18727 				__attribute__((unused)) struct cmdline *cl,
18728 				__attribute__((unused)) void *data)
18729 {
18730 	struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18731 
18732 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18733 		return;
18734 	ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18735 	/* Add/remove callback to insert valid metadata in every Tx packet. */
18736 	if (ports[res->port_id].tx_metadata)
18737 		add_tx_md_callback(res->port_id);
18738 	else
18739 		remove_tx_md_callback(res->port_id);
18740 }
18741 
18742 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18743 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18744 			port, "port");
18745 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18746 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18747 			keyword, "config");
18748 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18749 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18750 			port_id, UINT16);
18751 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18752 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18753 			item, "tx_metadata");
18754 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18755 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18756 			value, UINT32);
18757 
18758 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18759 	.f = cmd_config_tx_metadata_specific_parsed,
18760 	.data = NULL,
18761 	.help_str = "port config <port_id> tx_metadata <value>",
18762 	.tokens = {
18763 		(void *)&cmd_config_tx_metadata_specific_port,
18764 		(void *)&cmd_config_tx_metadata_specific_keyword,
18765 		(void *)&cmd_config_tx_metadata_specific_id,
18766 		(void *)&cmd_config_tx_metadata_specific_item,
18767 		(void *)&cmd_config_tx_metadata_specific_value,
18768 		NULL,
18769 	},
18770 };
18771 
18772 /* *** display tx_metadata per port configuration *** */
18773 struct cmd_show_tx_metadata_result {
18774 	cmdline_fixed_string_t cmd_show;
18775 	cmdline_fixed_string_t cmd_port;
18776 	cmdline_fixed_string_t cmd_keyword;
18777 	portid_t cmd_pid;
18778 };
18779 
18780 static void
18781 cmd_show_tx_metadata_parsed(void *parsed_result,
18782 		__attribute__((unused)) struct cmdline *cl,
18783 		__attribute__((unused)) void *data)
18784 {
18785 	struct cmd_show_tx_metadata_result *res = parsed_result;
18786 
18787 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18788 		printf("invalid port id %u\n", res->cmd_pid);
18789 		return;
18790 	}
18791 	if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18792 		printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18793 			rte_be_to_cpu_32(ports[res->cmd_pid].tx_metadata));
18794 	}
18795 }
18796 
18797 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18798 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18799 			cmd_show, "show");
18800 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18801 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18802 			cmd_port, "port");
18803 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18804 	TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18805 			cmd_pid, UINT16);
18806 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18807 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18808 			cmd_keyword, "tx_metadata");
18809 
18810 cmdline_parse_inst_t cmd_show_tx_metadata = {
18811 	.f = cmd_show_tx_metadata_parsed,
18812 	.data = NULL,
18813 	.help_str = "show port <port_id> tx_metadata",
18814 	.tokens = {
18815 		(void *)&cmd_show_tx_metadata_show,
18816 		(void *)&cmd_show_tx_metadata_port,
18817 		(void *)&cmd_show_tx_metadata_pid,
18818 		(void *)&cmd_show_tx_metadata_keyword,
18819 		NULL,
18820 	},
18821 };
18822 
18823 /* ******************************************************************************** */
18824 
18825 /* list of instructions */
18826 cmdline_parse_ctx_t main_ctx[] = {
18827 	(cmdline_parse_inst_t *)&cmd_help_brief,
18828 	(cmdline_parse_inst_t *)&cmd_help_long,
18829 	(cmdline_parse_inst_t *)&cmd_quit,
18830 	(cmdline_parse_inst_t *)&cmd_load_from_file,
18831 	(cmdline_parse_inst_t *)&cmd_showport,
18832 	(cmdline_parse_inst_t *)&cmd_showqueue,
18833 	(cmdline_parse_inst_t *)&cmd_showportall,
18834 	(cmdline_parse_inst_t *)&cmd_showdevice,
18835 	(cmdline_parse_inst_t *)&cmd_showcfg,
18836 	(cmdline_parse_inst_t *)&cmd_showfwdall,
18837 	(cmdline_parse_inst_t *)&cmd_start,
18838 	(cmdline_parse_inst_t *)&cmd_start_tx_first,
18839 	(cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18840 	(cmdline_parse_inst_t *)&cmd_set_link_up,
18841 	(cmdline_parse_inst_t *)&cmd_set_link_down,
18842 	(cmdline_parse_inst_t *)&cmd_reset,
18843 	(cmdline_parse_inst_t *)&cmd_set_numbers,
18844 	(cmdline_parse_inst_t *)&cmd_set_log,
18845 	(cmdline_parse_inst_t *)&cmd_set_txpkts,
18846 	(cmdline_parse_inst_t *)&cmd_set_txsplit,
18847 	(cmdline_parse_inst_t *)&cmd_set_fwd_list,
18848 	(cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18849 	(cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18850 	(cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18851 	(cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18852 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18853 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18854 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18855 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18856 	(cmdline_parse_inst_t *)&cmd_set_flush_rx,
18857 	(cmdline_parse_inst_t *)&cmd_set_link_check,
18858 	(cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18859 	(cmdline_parse_inst_t *)&cmd_set_bypass_event,
18860 	(cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18861 	(cmdline_parse_inst_t *)&cmd_show_bypass_config,
18862 #ifdef RTE_LIBRTE_PMD_BOND
18863 	(cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18864 	(cmdline_parse_inst_t *) &cmd_show_bonding_config,
18865 	(cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18866 	(cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18867 	(cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18868 	(cmdline_parse_inst_t *) &cmd_create_bonded_device,
18869 	(cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18870 	(cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18871 	(cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18872 	(cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18873 	(cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18874 #endif
18875 	(cmdline_parse_inst_t *)&cmd_vlan_offload,
18876 	(cmdline_parse_inst_t *)&cmd_vlan_tpid,
18877 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18878 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18879 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18880 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18881 	(cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18882 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18883 	(cmdline_parse_inst_t *)&cmd_csum_set,
18884 	(cmdline_parse_inst_t *)&cmd_csum_show,
18885 	(cmdline_parse_inst_t *)&cmd_csum_tunnel,
18886 	(cmdline_parse_inst_t *)&cmd_tso_set,
18887 	(cmdline_parse_inst_t *)&cmd_tso_show,
18888 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18889 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18890 	(cmdline_parse_inst_t *)&cmd_gro_enable,
18891 	(cmdline_parse_inst_t *)&cmd_gro_flush,
18892 	(cmdline_parse_inst_t *)&cmd_gro_show,
18893 	(cmdline_parse_inst_t *)&cmd_gso_enable,
18894 	(cmdline_parse_inst_t *)&cmd_gso_size,
18895 	(cmdline_parse_inst_t *)&cmd_gso_show,
18896 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18897 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18898 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18899 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18900 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18901 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18902 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18903 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18904 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18905 	(cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18906 	(cmdline_parse_inst_t *)&cmd_config_dcb,
18907 	(cmdline_parse_inst_t *)&cmd_read_reg,
18908 	(cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18909 	(cmdline_parse_inst_t *)&cmd_read_reg_bit,
18910 	(cmdline_parse_inst_t *)&cmd_write_reg,
18911 	(cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18912 	(cmdline_parse_inst_t *)&cmd_write_reg_bit,
18913 	(cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18914 	(cmdline_parse_inst_t *)&cmd_stop,
18915 	(cmdline_parse_inst_t *)&cmd_mac_addr,
18916 	(cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18917 	(cmdline_parse_inst_t *)&cmd_set_qmap,
18918 	(cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18919 	(cmdline_parse_inst_t *)&cmd_operate_port,
18920 	(cmdline_parse_inst_t *)&cmd_operate_specific_port,
18921 	(cmdline_parse_inst_t *)&cmd_operate_attach_port,
18922 	(cmdline_parse_inst_t *)&cmd_operate_detach_port,
18923 	(cmdline_parse_inst_t *)&cmd_operate_detach_device,
18924 	(cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18925 	(cmdline_parse_inst_t *)&cmd_config_speed_all,
18926 	(cmdline_parse_inst_t *)&cmd_config_speed_specific,
18927 	(cmdline_parse_inst_t *)&cmd_config_loopback_all,
18928 	(cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18929 	(cmdline_parse_inst_t *)&cmd_config_rx_tx,
18930 	(cmdline_parse_inst_t *)&cmd_config_mtu,
18931 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18932 	(cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18933 	(cmdline_parse_inst_t *)&cmd_config_rss,
18934 	(cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18935 	(cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18936 	(cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18937 	(cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18938 	(cmdline_parse_inst_t *)&cmd_config_rss_reta,
18939 	(cmdline_parse_inst_t *)&cmd_showport_reta,
18940 	(cmdline_parse_inst_t *)&cmd_config_burst,
18941 	(cmdline_parse_inst_t *)&cmd_config_thresh,
18942 	(cmdline_parse_inst_t *)&cmd_config_threshold,
18943 	(cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18944 	(cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18945 	(cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18946 	(cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
18947 	(cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18948 	(cmdline_parse_inst_t *)&cmd_tunnel_filter,
18949 	(cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18950 	(cmdline_parse_inst_t *)&cmd_global_config,
18951 	(cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18952 	(cmdline_parse_inst_t *)&cmd_set_mirror_link,
18953 	(cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18954 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18955 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18956 	(cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18957 	(cmdline_parse_inst_t *)&cmd_dump,
18958 	(cmdline_parse_inst_t *)&cmd_dump_one,
18959 	(cmdline_parse_inst_t *)&cmd_ethertype_filter,
18960 	(cmdline_parse_inst_t *)&cmd_syn_filter,
18961 	(cmdline_parse_inst_t *)&cmd_2tuple_filter,
18962 	(cmdline_parse_inst_t *)&cmd_5tuple_filter,
18963 	(cmdline_parse_inst_t *)&cmd_flex_filter,
18964 	(cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18965 	(cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18966 	(cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18967 	(cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18968 	(cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18969 	(cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18970 	(cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18971 	(cmdline_parse_inst_t *)&cmd_flush_flow_director,
18972 	(cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18973 	(cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18974 	(cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18975 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18976 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18977 	(cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
18978 	(cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
18979 	(cmdline_parse_inst_t *)&cmd_get_hash_global_config,
18980 	(cmdline_parse_inst_t *)&cmd_set_hash_global_config,
18981 	(cmdline_parse_inst_t *)&cmd_set_hash_input_set,
18982 	(cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18983 	(cmdline_parse_inst_t *)&cmd_flow,
18984 	(cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18985 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18986 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18987 	(cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18988 	(cmdline_parse_inst_t *)&cmd_create_port_meter,
18989 	(cmdline_parse_inst_t *)&cmd_enable_port_meter,
18990 	(cmdline_parse_inst_t *)&cmd_disable_port_meter,
18991 	(cmdline_parse_inst_t *)&cmd_del_port_meter,
18992 	(cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18993 	(cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18994 	(cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18995 	(cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18996 	(cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18997 	(cmdline_parse_inst_t *)&cmd_mcast_addr,
18998 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18999 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19000 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19001 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19002 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19003 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19004 	(cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19005 	(cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19006 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19007 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19008 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19009 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19010 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19011 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19012 	(cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19013 	(cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19014 	(cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19015 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19016 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19017 	(cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19018 	(cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19019 	(cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19020 	(cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19021 	(cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19022 	(cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19023 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19024 	(cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19025 	(cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19026 	(cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19027 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19028 	(cmdline_parse_inst_t *)&cmd_vf_max_bw,
19029 	(cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19030 	(cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19031 	(cmdline_parse_inst_t *)&cmd_strict_link_prio,
19032 	(cmdline_parse_inst_t *)&cmd_tc_min_bw,
19033 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19034 	(cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19035 #endif
19036 	(cmdline_parse_inst_t *)&cmd_set_vxlan,
19037 	(cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19038 	(cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19039 	(cmdline_parse_inst_t *)&cmd_set_nvgre,
19040 	(cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19041 	(cmdline_parse_inst_t *)&cmd_set_l2_encap,
19042 	(cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19043 	(cmdline_parse_inst_t *)&cmd_set_l2_decap,
19044 	(cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19045 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19046 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19047 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19048 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19049 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19050 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19051 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19052 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19053 	(cmdline_parse_inst_t *)&cmd_ddp_add,
19054 	(cmdline_parse_inst_t *)&cmd_ddp_del,
19055 	(cmdline_parse_inst_t *)&cmd_ddp_get_list,
19056 	(cmdline_parse_inst_t *)&cmd_ddp_get_info,
19057 	(cmdline_parse_inst_t *)&cmd_cfg_input_set,
19058 	(cmdline_parse_inst_t *)&cmd_clear_input_set,
19059 	(cmdline_parse_inst_t *)&cmd_show_vf_stats,
19060 	(cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19061 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19062 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19063 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19064 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19065 
19066 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19067 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19068 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19069 	(cmdline_parse_inst_t *)&cmd_queue_region,
19070 	(cmdline_parse_inst_t *)&cmd_region_flowtype,
19071 	(cmdline_parse_inst_t *)&cmd_user_priority_region,
19072 	(cmdline_parse_inst_t *)&cmd_flush_queue_region,
19073 	(cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19074 	(cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19075 	(cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19076 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19077 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19078 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19079 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19080 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19081 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19082 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19083 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19084 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19085 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19086 	(cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19087 	(cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19088 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19089 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19090 	(cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19091 	(cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19092 	(cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19093 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19094 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19095 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19096 	(cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19097 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19098 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19099 	(cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19100 	(cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19101 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19102 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19103 	(cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19104 	(cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19105 #ifdef RTE_LIBRTE_BPF
19106 	(cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19107 	(cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19108 #endif
19109 	(cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19110 	(cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19111 	(cmdline_parse_inst_t *)&cmd_set_raw,
19112 	NULL,
19113 };
19114 
19115 /* read cmdline commands from file */
19116 void
19117 cmdline_read_from_file(const char *filename)
19118 {
19119 	struct cmdline *cl;
19120 
19121 	cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19122 	if (cl == NULL) {
19123 		printf("Failed to create file based cmdline context: %s\n",
19124 		       filename);
19125 		return;
19126 	}
19127 
19128 	cmdline_interact(cl);
19129 	cmdline_quit(cl);
19130 
19131 	cmdline_free(cl);
19132 
19133 	printf("Read CLI commands from %s\n", filename);
19134 }
19135 
19136 /* prompt function, called from main on MASTER lcore */
19137 void
19138 prompt(void)
19139 {
19140 	/* initialize non-constant commands */
19141 	cmd_set_fwd_mode_init();
19142 	cmd_set_fwd_retry_mode_init();
19143 
19144 	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19145 	if (testpmd_cl == NULL)
19146 		return;
19147 	cmdline_interact(testpmd_cl);
19148 	cmdline_stdin_exit(testpmd_cl);
19149 }
19150 
19151 void
19152 prompt_exit(void)
19153 {
19154 	if (testpmd_cl != NULL)
19155 		cmdline_quit(testpmd_cl);
19156 }
19157 
19158 static void
19159 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19160 {
19161 	if (id == (portid_t)RTE_PORT_ALL) {
19162 		portid_t pid;
19163 
19164 		RTE_ETH_FOREACH_DEV(pid) {
19165 			/* check if need_reconfig has been set to 1 */
19166 			if (ports[pid].need_reconfig == 0)
19167 				ports[pid].need_reconfig = dev;
19168 			/* check if need_reconfig_queues has been set to 1 */
19169 			if (ports[pid].need_reconfig_queues == 0)
19170 				ports[pid].need_reconfig_queues = queue;
19171 		}
19172 	} else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19173 		/* check if need_reconfig has been set to 1 */
19174 		if (ports[id].need_reconfig == 0)
19175 			ports[id].need_reconfig = dev;
19176 		/* check if need_reconfig_queues has been set to 1 */
19177 		if (ports[id].need_reconfig_queues == 0)
19178 			ports[id].need_reconfig_queues = queue;
19179 	}
19180 }
19181