xref: /dpdk/app/test-pmd/cmdline.c (revision 7adf992fb9bf7162a7edc45b50d10fbb1d57824d)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5 
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16 
17 #include <sys/queue.h>
18 
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44 
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_LIBRTE_PMD_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_LIBRTE_IXGBE_PMD
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_LIBRTE_I40E_PMD
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_LIBRTE_BNXT_PMD
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73 
74 static struct cmdline *testpmd_cl;
75 
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77 
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80 	cmdline_fixed_string_t help;
81 };
82 
83 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
84                                   struct cmdline *cl,
85                                   __attribute__((unused)) void *data)
86 {
87 	cmdline_printf(
88 		cl,
89 		"\n"
90 		"Help is available for the following sections:\n\n"
91 		"    help control                    : Start and stop forwarding.\n"
92 		"    help display                    : Displaying port, stats and config "
93 		"information.\n"
94 		"    help config                     : Configuration information.\n"
95 		"    help ports                      : Configuring ports.\n"
96 		"    help registers                  : Reading and setting port registers.\n"
97 		"    help filters                    : Filters configuration help.\n"
98 		"    help traffic_management         : Traffic Management commmands.\n"
99 		"    help devices                    : Device related cmds.\n"
100 		"    help all                        : All of the above sections.\n\n"
101 	);
102 
103 }
104 
105 cmdline_parse_token_string_t cmd_help_brief_help =
106 	TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107 
108 cmdline_parse_inst_t cmd_help_brief = {
109 	.f = cmd_help_brief_parsed,
110 	.data = NULL,
111 	.help_str = "help: Show help",
112 	.tokens = {
113 		(void *)&cmd_help_brief_help,
114 		NULL,
115 	},
116 };
117 
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120 	cmdline_fixed_string_t help;
121 	cmdline_fixed_string_t section;
122 };
123 
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __attribute__((unused)) void *data)
127 {
128 	int show_all = 0;
129 	struct cmd_help_long_result *res = parsed_result;
130 
131 	if (!strcmp(res->section, "all"))
132 		show_all = 1;
133 
134 	if (show_all || !strcmp(res->section, "control")) {
135 
136 		cmdline_printf(
137 			cl,
138 			"\n"
139 			"Control forwarding:\n"
140 			"-------------------\n\n"
141 
142 			"start\n"
143 			"    Start packet forwarding with current configuration.\n\n"
144 
145 			"start tx_first\n"
146 			"    Start packet forwarding with current config"
147 			" after sending one burst of packets.\n\n"
148 
149 			"stop\n"
150 			"    Stop packet forwarding, and display accumulated"
151 			" statistics.\n\n"
152 
153 			"quit\n"
154 			"    Quit to prompt.\n\n"
155 		);
156 	}
157 
158 	if (show_all || !strcmp(res->section, "display")) {
159 
160 		cmdline_printf(
161 			cl,
162 			"\n"
163 			"Display:\n"
164 			"--------\n\n"
165 
166 			"show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
167 			"    Display information for port_id, or all.\n\n"
168 
169 			"show port X rss reta (size) (mask0,mask1,...)\n"
170 			"    Display the rss redirection table entry indicated"
171 			" by masks on port X. size is used to indicate the"
172 			" hardware supported reta size\n\n"
173 
174 			"show port (port_id) rss-hash [key]\n"
175 			"    Display the RSS hash functions and RSS hash key of port\n\n"
176 
177 			"clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
178 			"    Clear information for port_id, or all.\n\n"
179 
180 			"show (rxq|txq) info (port_id) (queue_id)\n"
181 			"    Display information for configured RX/TX queue.\n\n"
182 
183 			"show config (rxtx|cores|fwd|txpkts)\n"
184 			"    Display the given configuration.\n\n"
185 
186 			"read rxd (port_id) (queue_id) (rxd_id)\n"
187 			"    Display an RX descriptor of a port RX queue.\n\n"
188 
189 			"read txd (port_id) (queue_id) (txd_id)\n"
190 			"    Display a TX descriptor of a port TX queue.\n\n"
191 
192 			"ddp get list (port_id)\n"
193 			"    Get ddp profile info list\n\n"
194 
195 			"ddp get info (profile_path)\n"
196 			"    Get ddp profile information.\n\n"
197 
198 			"show vf stats (port_id) (vf_id)\n"
199 			"    Display a VF's statistics.\n\n"
200 
201 			"clear vf stats (port_id) (vf_id)\n"
202 			"    Reset a VF's statistics.\n\n"
203 
204 			"show port (port_id) pctype mapping\n"
205 			"    Get flow ptype to pctype mapping on a port\n\n"
206 
207 			"show port meter stats (port_id) (meter_id) (clear)\n"
208 			"    Get meter stats on a port\n\n"
209 
210 			"show fwd stats all\n"
211 			"    Display statistics for all fwd engines.\n\n"
212 
213 			"clear fwd stats all\n"
214 			"    Clear statistics for all fwd engines.\n\n"
215 
216 			"show port (port_id) rx_offload capabilities\n"
217 			"    List all per queue and per port Rx offloading"
218 			" capabilities of a port\n\n"
219 
220 			"show port (port_id) rx_offload configuration\n"
221 			"    List port level and all queue level"
222 			" Rx offloading configuration\n\n"
223 
224 			"show port (port_id) tx_offload capabilities\n"
225 			"    List all per queue and per port"
226 			" Tx offloading capabilities of a port\n\n"
227 
228 			"show port (port_id) tx_offload configuration\n"
229 			"    List port level and all queue level"
230 			" Tx offloading configuration\n\n"
231 
232 			"show port (port_id) tx_metadata\n"
233 			"    Show Tx metadata value set"
234 			" for a specific port\n\n"
235 
236 			"show port (port_id) ptypes\n"
237 			"    Show port supported ptypes"
238 			" for a specific port\n\n"
239 
240 			"show device info (<identifier>|all)"
241 			"       Show general information about devices probed.\n\n"
242 
243 			"show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
244 			"       Show status of rx|tx descriptor.\n\n"
245 
246 			"show port (port_id) macs|mcast_macs"
247 			"       Display list of mac addresses added to port.\n\n"
248 		);
249 	}
250 
251 	if (show_all || !strcmp(res->section, "config")) {
252 		cmdline_printf(
253 			cl,
254 			"\n"
255 			"Configuration:\n"
256 			"--------------\n"
257 			"Configuration changes only become active when"
258 			" forwarding is started/restarted.\n\n"
259 
260 			"set default\n"
261 			"    Reset forwarding to the default configuration.\n\n"
262 
263 			"set verbose (level)\n"
264 			"    Set the debug verbosity level X.\n\n"
265 
266 			"set log global|(type) (level)\n"
267 			"    Set the log level.\n\n"
268 
269 			"set nbport (num)\n"
270 			"    Set number of ports.\n\n"
271 
272 			"set nbcore (num)\n"
273 			"    Set number of cores.\n\n"
274 
275 			"set coremask (mask)\n"
276 			"    Set the forwarding cores hexadecimal mask.\n\n"
277 
278 			"set portmask (mask)\n"
279 			"    Set the forwarding ports hexadecimal mask.\n\n"
280 
281 			"set burst (num)\n"
282 			"    Set number of packets per burst.\n\n"
283 
284 			"set burst tx delay (microseconds) retry (num)\n"
285 			"    Set the transmit delay time and number of retries,"
286 			" effective when retry is enabled.\n\n"
287 
288 			"set txpkts (x[,y]*)\n"
289 			"    Set the length of each segment of TXONLY"
290 			" and optionally CSUM packets.\n\n"
291 
292 			"set txsplit (off|on|rand)\n"
293 			"    Set the split policy for the TX packets."
294 			" Right now only applicable for CSUM and TXONLY"
295 			" modes\n\n"
296 
297 			"set corelist (x[,y]*)\n"
298 			"    Set the list of forwarding cores.\n\n"
299 
300 			"set portlist (x[,y]*)\n"
301 			"    Set the list of forwarding ports.\n\n"
302 
303 			"set port setup on (iterator|event)\n"
304 			"    Select how attached port is retrieved for setup.\n\n"
305 
306 			"set tx loopback (port_id) (on|off)\n"
307 			"    Enable or disable tx loopback.\n\n"
308 
309 			"set all queues drop (port_id) (on|off)\n"
310 			"    Set drop enable bit for all queues.\n\n"
311 
312 			"set vf split drop (port_id) (vf_id) (on|off)\n"
313 			"    Set split drop enable bit for a VF from the PF.\n\n"
314 
315 			"set vf mac antispoof (port_id) (vf_id) (on|off).\n"
316 			"    Set MAC antispoof for a VF from the PF.\n\n"
317 
318 			"set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
319 			"    Enable MACsec offload.\n\n"
320 
321 			"set macsec offload (port_id) off\n"
322 			"    Disable MACsec offload.\n\n"
323 
324 			"set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
325 			"    Configure MACsec secure connection (SC).\n\n"
326 
327 			"set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
328 			"    Configure MACsec secure association (SA).\n\n"
329 
330 			"set vf broadcast (port_id) (vf_id) (on|off)\n"
331 			"    Set VF broadcast for a VF from the PF.\n\n"
332 
333 			"vlan set stripq (on|off) (port_id,queue_id)\n"
334 			"    Set the VLAN strip for a queue on a port.\n\n"
335 
336 			"set vf vlan stripq (port_id) (vf_id) (on|off)\n"
337 			"    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
338 
339 			"set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
340 			"    Set VLAN insert for a VF from the PF.\n\n"
341 
342 			"set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
343 			"    Set VLAN antispoof for a VF from the PF.\n\n"
344 
345 			"set vf vlan tag (port_id) (vf_id) (on|off)\n"
346 			"    Set VLAN tag for a VF from the PF.\n\n"
347 
348 			"set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
349 			"    Set a VF's max bandwidth(Mbps).\n\n"
350 
351 			"set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
352 			"    Set all TCs' min bandwidth(%%) on a VF.\n\n"
353 
354 			"set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
355 			"    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
356 
357 			"set tx strict-link-priority (port_id) (tc_bitmap)\n"
358 			"    Set some TCs' strict link priority mode on a physical port.\n\n"
359 
360 			"set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
361 			"    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
362 
363 			"vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
364 			"    Set the VLAN strip or filter or qinq strip or extend\n\n"
365 
366 			"vlan set (inner|outer) tpid (value) (port_id)\n"
367 			"    Set the VLAN TPID for Packet Filtering on"
368 			" a port\n\n"
369 
370 			"rx_vlan add (vlan_id|all) (port_id)\n"
371 			"    Add a vlan_id, or all identifiers, to the set"
372 			" of VLAN identifiers filtered by port_id.\n\n"
373 
374 			"rx_vlan rm (vlan_id|all) (port_id)\n"
375 			"    Remove a vlan_id, or all identifiers, from the set"
376 			" of VLAN identifiers filtered by port_id.\n\n"
377 
378 			"rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
379 			"    Add a vlan_id, to the set of VLAN identifiers"
380 			"filtered for VF(s) from port_id.\n\n"
381 
382 			"rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
383 			"    Remove a vlan_id, to the set of VLAN identifiers"
384 			"filtered for VF(s) from port_id.\n\n"
385 
386 			"tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
387 			"(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
388 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
389 			"   add a tunnel filter of a port.\n\n"
390 
391 			"tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
392 			"(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
393 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
394 			"   remove a tunnel filter of a port.\n\n"
395 
396 			"rx_vxlan_port add (udp_port) (port_id)\n"
397 			"    Add an UDP port for VXLAN packet filter on a port\n\n"
398 
399 			"rx_vxlan_port rm (udp_port) (port_id)\n"
400 			"    Remove an UDP port for VXLAN packet filter on a port\n\n"
401 
402 			"tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
403 			"    Set hardware insertion of VLAN IDs (single or double VLAN "
404 			"depends on the number of VLAN IDs) in packets sent on a port.\n\n"
405 
406 			"tx_vlan set pvid port_id vlan_id (on|off)\n"
407 			"    Set port based TX VLAN insertion.\n\n"
408 
409 			"tx_vlan reset (port_id)\n"
410 			"    Disable hardware insertion of a VLAN header in"
411 			" packets sent on a port.\n\n"
412 
413 			"csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
414 			"    Select hardware or software calculation of the"
415 			" checksum when transmitting a packet using the"
416 			" csum forward engine.\n"
417 			"    ip|udp|tcp|sctp always concern the inner layer.\n"
418 			"    outer-ip concerns the outer IP layer in"
419 			"    outer-udp concerns the outer UDP layer in"
420 			" case the packet is recognized as a tunnel packet by"
421 			" the forward engine (vxlan, gre and ipip are supported)\n"
422 			"    Please check the NIC datasheet for HW limits.\n\n"
423 
424 			"csum parse-tunnel (on|off) (tx_port_id)\n"
425 			"    If disabled, treat tunnel packets as non-tunneled"
426 			" packets (treat inner headers as payload). The port\n"
427 			"    argument is the port used for TX in csum forward"
428 			" engine.\n\n"
429 
430 			"csum show (port_id)\n"
431 			"    Display tx checksum offload configuration\n\n"
432 
433 			"tso set (segsize) (portid)\n"
434 			"    Enable TCP Segmentation Offload in csum forward"
435 			" engine.\n"
436 			"    Please check the NIC datasheet for HW limits.\n\n"
437 
438 			"tso show (portid)"
439 			"    Display the status of TCP Segmentation Offload.\n\n"
440 
441 			"set port (port_id) gro on|off\n"
442 			"    Enable or disable Generic Receive Offload in"
443 			" csum forwarding engine.\n\n"
444 
445 			"show port (port_id) gro\n"
446 			"    Display GRO configuration.\n\n"
447 
448 			"set gro flush (cycles)\n"
449 			"    Set the cycle to flush GROed packets from"
450 			" reassembly tables.\n\n"
451 
452 			"set port (port_id) gso (on|off)"
453 			"    Enable or disable Generic Segmentation Offload in"
454 			" csum forwarding engine.\n\n"
455 
456 			"set gso segsz (length)\n"
457 			"    Set max packet length for output GSO segments,"
458 			" including packet header and payload.\n\n"
459 
460 			"show port (port_id) gso\n"
461 			"    Show GSO configuration.\n\n"
462 
463 			"set fwd (%s)\n"
464 			"    Set packet forwarding mode.\n\n"
465 
466 			"mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
467 			"    Add a MAC address on port_id.\n\n"
468 
469 			"mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
470 			"    Remove a MAC address from port_id.\n\n"
471 
472 			"mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
473 			"    Set the default MAC address for port_id.\n\n"
474 
475 			"mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
476 			"    Add a MAC address for a VF on the port.\n\n"
477 
478 			"set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
479 			"    Set the MAC address for a VF from the PF.\n\n"
480 
481 			"set eth-peer (port_id) (peer_addr)\n"
482 			"    set the peer address for certain port.\n\n"
483 
484 			"set port (port_id) uta (mac_address|all) (on|off)\n"
485 			"    Add/Remove a or all unicast hash filter(s)"
486 			"from port X.\n\n"
487 
488 			"set promisc (port_id|all) (on|off)\n"
489 			"    Set the promiscuous mode on port_id, or all.\n\n"
490 
491 			"set allmulti (port_id|all) (on|off)\n"
492 			"    Set the allmulti mode on port_id, or all.\n\n"
493 
494 			"set vf promisc (port_id) (vf_id) (on|off)\n"
495 			"    Set unicast promiscuous mode for a VF from the PF.\n\n"
496 
497 			"set vf allmulti (port_id) (vf_id) (on|off)\n"
498 			"    Set multicast promiscuous mode for a VF from the PF.\n\n"
499 
500 			"set flow_ctrl rx (on|off) tx (on|off) (high_water)"
501 			" (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
502 			" (on|off) autoneg (on|off) (port_id)\n"
503 			"set flow_ctrl rx (on|off) (portid)\n"
504 			"set flow_ctrl tx (on|off) (portid)\n"
505 			"set flow_ctrl high_water (high_water) (portid)\n"
506 			"set flow_ctrl low_water (low_water) (portid)\n"
507 			"set flow_ctrl pause_time (pause_time) (portid)\n"
508 			"set flow_ctrl send_xon (send_xon) (portid)\n"
509 			"set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
510 			"set flow_ctrl autoneg (on|off) (port_id)\n"
511 			"    Set the link flow control parameter on a port.\n\n"
512 
513 			"set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
514 			" (low_water) (pause_time) (priority) (port_id)\n"
515 			"    Set the priority flow control parameter on a"
516 			" port.\n\n"
517 
518 			"set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
519 			"    Set statistics mapping (qmapping 0..15) for RX/TX"
520 			" queue on port.\n"
521 			"    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
522 			" on port 0 to mapping 5.\n\n"
523 
524 			"set xstats-hide-zero on|off\n"
525 			"    Set the option to hide the zero values"
526 			" for xstats display.\n"
527 
528 			"set port (port_id) vf (vf_id) rx|tx on|off\n"
529 			"    Enable/Disable a VF receive/tranmit from a port\n\n"
530 
531 			"set port (port_id) vf (vf_id) (mac_addr)"
532 			" (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
533 			"   Add/Remove unicast or multicast MAC addr filter"
534 			" for a VF.\n\n"
535 
536 			"set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
537 			"|MPE) (on|off)\n"
538 			"    AUPE:accepts untagged VLAN;"
539 			"ROPE:accept unicast hash\n\n"
540 			"    BAM:accepts broadcast packets;"
541 			"MPE:accepts all multicast packets\n\n"
542 			"    Enable/Disable a VF receive mode of a port\n\n"
543 
544 			"set port (port_id) queue (queue_id) rate (rate_num)\n"
545 			"    Set rate limit for a queue of a port\n\n"
546 
547 			"set port (port_id) vf (vf_id) rate (rate_num) "
548 			"queue_mask (queue_mask_value)\n"
549 			"    Set rate limit for queues in VF of a port\n\n"
550 
551 			"set port (port_id) mirror-rule (rule_id)"
552 			" (pool-mirror-up|pool-mirror-down|vlan-mirror)"
553 			" (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
554 			"   Set pool or vlan type mirror rule on a port.\n"
555 			"   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
556 			" dst-pool 0 on' enable mirror traffic with vlan 0,1"
557 			" to pool 0.\n\n"
558 
559 			"set port (port_id) mirror-rule (rule_id)"
560 			" (uplink-mirror|downlink-mirror) dst-pool"
561 			" (pool_id) (on|off)\n"
562 			"   Set uplink or downlink type mirror rule on a port.\n"
563 			"   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
564 			" 0 on' enable mirror income traffic to pool 0.\n\n"
565 
566 			"reset port (port_id) mirror-rule (rule_id)\n"
567 			"   Reset a mirror rule.\n\n"
568 
569 			"set flush_rx (on|off)\n"
570 			"   Flush (default) or don't flush RX streams before"
571 			" forwarding. Mainly used with PCAP drivers.\n\n"
572 
573 			"set bypass mode (normal|bypass|isolate) (port_id)\n"
574 			"   Set the bypass mode for the lowest port on bypass enabled"
575 			" NIC.\n\n"
576 
577 			"set bypass event (timeout|os_on|os_off|power_on|power_off) "
578 			"mode (normal|bypass|isolate) (port_id)\n"
579 			"   Set the event required to initiate specified bypass mode for"
580 			" the lowest port on a bypass enabled NIC where:\n"
581 			"       timeout   = enable bypass after watchdog timeout.\n"
582 			"       os_on     = enable bypass when OS/board is powered on.\n"
583 			"       os_off    = enable bypass when OS/board is powered off.\n"
584 			"       power_on  = enable bypass when power supply is turned on.\n"
585 			"       power_off = enable bypass when power supply is turned off."
586 			"\n\n"
587 
588 			"set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
589 			"   Set the bypass watchdog timeout to 'n' seconds"
590 			" where 0 = instant.\n\n"
591 
592 			"show bypass config (port_id)\n"
593 			"   Show the bypass configuration for a bypass enabled NIC"
594 			" using the lowest port on the NIC.\n\n"
595 
596 #ifdef RTE_LIBRTE_PMD_BOND
597 			"create bonded device (mode) (socket)\n"
598 			"	Create a new bonded device with specific bonding mode and socket.\n\n"
599 
600 			"add bonding slave (slave_id) (port_id)\n"
601 			"	Add a slave device to a bonded device.\n\n"
602 
603 			"remove bonding slave (slave_id) (port_id)\n"
604 			"	Remove a slave device from a bonded device.\n\n"
605 
606 			"set bonding mode (value) (port_id)\n"
607 			"	Set the bonding mode on a bonded device.\n\n"
608 
609 			"set bonding primary (slave_id) (port_id)\n"
610 			"	Set the primary slave for a bonded device.\n\n"
611 
612 			"show bonding config (port_id)\n"
613 			"	Show the bonding config for port_id.\n\n"
614 
615 			"set bonding mac_addr (port_id) (address)\n"
616 			"	Set the MAC address of a bonded device.\n\n"
617 
618 			"set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
619 			"	Set Aggregation mode for IEEE802.3AD (mode 4)"
620 
621 			"set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
622 			"	Set the transmit balance policy for bonded device running in balance mode.\n\n"
623 
624 			"set bonding mon_period (port_id) (value)\n"
625 			"	Set the bonding link status monitoring polling period in ms.\n\n"
626 
627 			"set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
628 			"	Enable/disable dedicated queues for LACP control traffic.\n\n"
629 
630 #endif
631 			"set link-up port (port_id)\n"
632 			"	Set link up for a port.\n\n"
633 
634 			"set link-down port (port_id)\n"
635 			"	Set link down for a port.\n\n"
636 
637 			"E-tag set insertion on port-tag-id (value)"
638 			" port (port_id) vf (vf_id)\n"
639 			"    Enable E-tag insertion for a VF on a port\n\n"
640 
641 			"E-tag set insertion off port (port_id) vf (vf_id)\n"
642 			"    Disable E-tag insertion for a VF on a port\n\n"
643 
644 			"E-tag set stripping (on|off) port (port_id)\n"
645 			"    Enable/disable E-tag stripping on a port\n\n"
646 
647 			"E-tag set forwarding (on|off) port (port_id)\n"
648 			"    Enable/disable E-tag based forwarding"
649 			" on a port\n\n"
650 
651 			"E-tag set filter add e-tag-id (value) dst-pool"
652 			" (pool_id) port (port_id)\n"
653 			"    Add an E-tag forwarding filter on a port\n\n"
654 
655 			"E-tag set filter del e-tag-id (value) port (port_id)\n"
656 			"    Delete an E-tag forwarding filter on a port\n\n"
657 
658 			"ddp add (port_id) (profile_path[,backup_profile_path])\n"
659 			"    Load a profile package on a port\n\n"
660 
661 			"ddp del (port_id) (backup_profile_path)\n"
662 			"    Delete a profile package from a port\n\n"
663 
664 			"ptype mapping get (port_id) (valid_only)\n"
665 			"    Get ptype mapping on a port\n\n"
666 
667 			"ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
668 			"    Replace target with the pkt_type in ptype mapping\n\n"
669 
670 			"ptype mapping reset (port_id)\n"
671 			"    Reset ptype mapping on a port\n\n"
672 
673 			"ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
674 			"    Update a ptype mapping item on a port\n\n"
675 
676 			"set port (port_id) ptype_mask (ptype_mask)\n"
677 			"    set packet types classification for a specific port\n\n"
678 
679 			"set port (port_id) queue-region region_id (value) "
680 			"queue_start_index (value) queue_num (value)\n"
681 			"    Set a queue region on a port\n\n"
682 
683 			"set port (port_id) queue-region region_id (value) "
684 			"flowtype (value)\n"
685 			"    Set a flowtype region index on a port\n\n"
686 
687 			"set port (port_id) queue-region UP (value) region_id (value)\n"
688 			"    Set the mapping of User Priority to "
689 			"queue region on a port\n\n"
690 
691 			"set port (port_id) queue-region flush (on|off)\n"
692 			"    flush all queue region related configuration\n\n"
693 
694 			"show port meter cap (port_id)\n"
695 			"    Show port meter capability information\n\n"
696 
697 			"add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
698 			"    meter profile add - srtcm rfc 2697\n\n"
699 
700 			"add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
701 			"    meter profile add - trtcm rfc 2698\n\n"
702 
703 			"add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
704 			"    meter profile add - trtcm rfc 4115\n\n"
705 
706 			"del port meter profile (port_id) (profile_id)\n"
707 			"    meter profile delete\n\n"
708 
709 			"create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
710 			"(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
711 			"(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
712 			"(dscp_tbl_entry63)]\n"
713 			"    meter create\n\n"
714 
715 			"enable port meter (port_id) (mtr_id)\n"
716 			"    meter enable\n\n"
717 
718 			"disable port meter (port_id) (mtr_id)\n"
719 			"    meter disable\n\n"
720 
721 			"del port meter (port_id) (mtr_id)\n"
722 			"    meter delete\n\n"
723 
724 			"set port meter profile (port_id) (mtr_id) (profile_id)\n"
725 			"    meter update meter profile\n\n"
726 
727 			"set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
728 			"(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
729 			"    update meter dscp table entries\n\n"
730 
731 			"set port meter policer action (port_id) (mtr_id) (action_mask)\n"
732 			"(action0) [(action1) (action2)]\n"
733 			"    meter update policer action\n\n"
734 
735 			"set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
736 			"    meter update stats\n\n"
737 
738 			"show port (port_id) queue-region\n"
739 			"    show all queue region related configuration info\n\n"
740 
741 			, list_pkt_forwarding_modes()
742 		);
743 	}
744 
745 	if (show_all || !strcmp(res->section, "ports")) {
746 
747 		cmdline_printf(
748 			cl,
749 			"\n"
750 			"Port Operations:\n"
751 			"----------------\n\n"
752 
753 			"port start (port_id|all)\n"
754 			"    Start all ports or port_id.\n\n"
755 
756 			"port stop (port_id|all)\n"
757 			"    Stop all ports or port_id.\n\n"
758 
759 			"port close (port_id|all)\n"
760 			"    Close all ports or port_id.\n\n"
761 
762 			"port reset (port_id|all)\n"
763 			"    Reset all ports or port_id.\n\n"
764 
765 			"port attach (ident)\n"
766 			"    Attach physical or virtual dev by pci address or virtual device name\n\n"
767 
768 			"port detach (port_id)\n"
769 			"    Detach physical or virtual dev by port_id\n\n"
770 
771 			"port config (port_id|all)"
772 			" speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
773 			" duplex (half|full|auto)\n"
774 			"    Set speed and duplex for all ports or port_id\n\n"
775 
776 			"port config (port_id|all) loopback (mode)\n"
777 			"    Set loopback mode for all ports or port_id\n\n"
778 
779 			"port config all (rxq|txq|rxd|txd) (value)\n"
780 			"    Set number for rxq/txq/rxd/txd.\n\n"
781 
782 			"port config all max-pkt-len (value)\n"
783 			"    Set the max packet length.\n\n"
784 
785 			"port config all max-lro-pkt-size (value)\n"
786 			"    Set the max LRO aggregated packet size.\n\n"
787 
788 			"port config all drop-en (on|off)\n"
789 			"    Enable or disable packet drop on all RX queues of all ports when no "
790 			"receive buffers available.\n\n"
791 
792 			"port config all rss (all|default|ip|tcp|udp|sctp|"
793 			"ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
794 			"    Set the RSS mode.\n\n"
795 
796 			"port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
797 			"    Set the RSS redirection table.\n\n"
798 
799 			"port config (port_id) dcb vt (on|off) (traffic_class)"
800 			" pfc (on|off)\n"
801 			"    Set the DCB mode.\n\n"
802 
803 			"port config all burst (value)\n"
804 			"    Set the number of packets per burst.\n\n"
805 
806 			"port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
807 			" (value)\n"
808 			"    Set the ring prefetch/host/writeback threshold"
809 			" for tx/rx queue.\n\n"
810 
811 			"port config all (txfreet|txrst|rxfreet) (value)\n"
812 			"    Set free threshold for rx/tx, or set"
813 			" tx rs bit threshold.\n\n"
814 			"port config mtu X value\n"
815 			"    Set the MTU of port X to a given value\n\n"
816 
817 			"port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
818 			"    Set a rx/tx queue's ring size configuration, the new"
819 			" value will take effect after command that (re-)start the port"
820 			" or command that setup the specific queue\n\n"
821 
822 			"port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
823 			"    Start/stop a rx/tx queue of port X. Only take effect"
824 			" when port X is started\n\n"
825 
826 			"port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
827 			"    Switch on/off a deferred start of port X rx/tx queue. Only"
828 			" take effect when port X is stopped.\n\n"
829 
830 			"port (port_id) (rxq|txq) (queue_id) setup\n"
831 			"    Setup a rx/tx queue of port X.\n\n"
832 
833 			"port config (port_id|all) l2-tunnel E-tag ether-type"
834 			" (value)\n"
835 			"    Set the value of E-tag ether-type.\n\n"
836 
837 			"port config (port_id|all) l2-tunnel E-tag"
838 			" (enable|disable)\n"
839 			"    Enable/disable the E-tag support.\n\n"
840 
841 			"port config (port_id) pctype mapping reset\n"
842 			"    Reset flow type to pctype mapping on a port\n\n"
843 
844 			"port config (port_id) pctype mapping update"
845 			" (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
846 			"    Update a flow type to pctype mapping item on a port\n\n"
847 
848 			"port config (port_id) pctype (pctype_id) hash_inset|"
849 			"fdir_inset|fdir_flx_inset get|set|clear field\n"
850 			" (field_idx)\n"
851 			"    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
852 
853 			"port config (port_id) pctype (pctype_id) hash_inset|"
854 			"fdir_inset|fdir_flx_inset clear all"
855 			"    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
856 
857 			"port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
858 			"    Add/remove UDP tunnel port for tunneling offload\n\n"
859 
860 			"port config <port_id> rx_offload vlan_strip|"
861 			"ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
862 			"outer_ipv4_cksum|macsec_strip|header_split|"
863 			"vlan_filter|vlan_extend|jumbo_frame|"
864 			"scatter|timestamp|security|keep_crc on|off\n"
865 			"     Enable or disable a per port Rx offloading"
866 			" on all Rx queues of a port\n\n"
867 
868 			"port (port_id) rxq (queue_id) rx_offload vlan_strip|"
869 			"ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
870 			"outer_ipv4_cksum|macsec_strip|header_split|"
871 			"vlan_filter|vlan_extend|jumbo_frame|"
872 			"scatter|timestamp|security|keep_crc on|off\n"
873 			"    Enable or disable a per queue Rx offloading"
874 			" only on a specific Rx queue\n\n"
875 
876 			"port config (port_id) tx_offload vlan_insert|"
877 			"ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
878 			"udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
879 			"gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
880 			"macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
881 			"security on|off\n"
882 			"    Enable or disable a per port Tx offloading"
883 			" on all Tx queues of a port\n\n"
884 
885 			"port (port_id) txq (queue_id) tx_offload vlan_insert|"
886 			"ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
887 			"udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
888 			"gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
889 			"|mt_lockfree|multi_segs|mbuf_fast_free|security"
890 			" on|off\n"
891 			"    Enable or disable a per queue Tx offloading"
892 			" only on a specific Tx queue\n\n"
893 
894 			"bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
895 			"    Load an eBPF program as a callback"
896 			" for particular RX/TX queue\n\n"
897 
898 			"bpf-unload rx|tx (port) (queue)\n"
899 			"    Unload previously loaded eBPF program"
900 			" for particular RX/TX queue\n\n"
901 
902 			"port config (port_id) tx_metadata (value)\n"
903 			"    Set Tx metadata value per port. Testpmd will add this value"
904 			" to any Tx packet sent from this port\n\n"
905 
906 			"port config (port_id) dynf (name) set|clear\n"
907 			"    Register a dynf and Set/clear this flag on Tx. "
908 			"Testpmd will set this value to any Tx packet "
909 			"sent from this port\n\n"
910 		);
911 	}
912 
913 	if (show_all || !strcmp(res->section, "registers")) {
914 
915 		cmdline_printf(
916 			cl,
917 			"\n"
918 			"Registers:\n"
919 			"----------\n\n"
920 
921 			"read reg (port_id) (address)\n"
922 			"    Display value of a port register.\n\n"
923 
924 			"read regfield (port_id) (address) (bit_x) (bit_y)\n"
925 			"    Display a port register bit field.\n\n"
926 
927 			"read regbit (port_id) (address) (bit_x)\n"
928 			"    Display a single port register bit.\n\n"
929 
930 			"write reg (port_id) (address) (value)\n"
931 			"    Set value of a port register.\n\n"
932 
933 			"write regfield (port_id) (address) (bit_x) (bit_y)"
934 			" (value)\n"
935 			"    Set bit field of a port register.\n\n"
936 
937 			"write regbit (port_id) (address) (bit_x) (value)\n"
938 			"    Set single bit value of a port register.\n\n"
939 		);
940 	}
941 	if (show_all || !strcmp(res->section, "filters")) {
942 
943 		cmdline_printf(
944 			cl,
945 			"\n"
946 			"filters:\n"
947 			"--------\n\n"
948 
949 			"ethertype_filter (port_id) (add|del)"
950 			" (mac_addr|mac_ignr) (mac_address) ethertype"
951 			" (ether_type) (drop|fwd) queue (queue_id)\n"
952 			"    Add/Del an ethertype filter.\n\n"
953 
954 			"2tuple_filter (port_id) (add|del)"
955 			" dst_port (dst_port_value) protocol (protocol_value)"
956 			" mask (mask_value) tcp_flags (tcp_flags_value)"
957 			" priority (prio_value) queue (queue_id)\n"
958 			"    Add/Del a 2tuple filter.\n\n"
959 
960 			"5tuple_filter (port_id) (add|del)"
961 			" dst_ip (dst_address) src_ip (src_address)"
962 			" dst_port (dst_port_value) src_port (src_port_value)"
963 			" protocol (protocol_value)"
964 			" mask (mask_value) tcp_flags (tcp_flags_value)"
965 			" priority (prio_value) queue (queue_id)\n"
966 			"    Add/Del a 5tuple filter.\n\n"
967 
968 			"syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
969 			"    Add/Del syn filter.\n\n"
970 
971 			"flex_filter (port_id) (add|del) len (len_value)"
972 			" bytes (bytes_value) mask (mask_value)"
973 			" priority (prio_value) queue (queue_id)\n"
974 			"    Add/Del a flex filter.\n\n"
975 
976 			"flow_director_filter (port_id) mode IP (add|del|update)"
977 			" flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
978 			" src (src_ip_address) dst (dst_ip_address)"
979 			" tos (tos_value) proto (proto_value) ttl (ttl_value)"
980 			" vlan (vlan_value) flexbytes (flexbytes_value)"
981 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
982 			" fd_id (fd_id_value)\n"
983 			"    Add/Del an IP type flow director filter.\n\n"
984 
985 			"flow_director_filter (port_id) mode IP (add|del|update)"
986 			" flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
987 			" src (src_ip_address) (src_port)"
988 			" dst (dst_ip_address) (dst_port)"
989 			" tos (tos_value) ttl (ttl_value)"
990 			" vlan (vlan_value) flexbytes (flexbytes_value)"
991 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
992 			" fd_id (fd_id_value)\n"
993 			"    Add/Del an UDP/TCP type flow director filter.\n\n"
994 
995 			"flow_director_filter (port_id) mode IP (add|del|update)"
996 			" flow (ipv4-sctp|ipv6-sctp)"
997 			" src (src_ip_address) (src_port)"
998 			" dst (dst_ip_address) (dst_port)"
999 			" tag (verification_tag) "
1000 			" tos (tos_value) ttl (ttl_value)"
1001 			" vlan (vlan_value)"
1002 			" flexbytes (flexbytes_value) (drop|fwd)"
1003 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1004 			"    Add/Del a SCTP type flow director filter.\n\n"
1005 
1006 			"flow_director_filter (port_id) mode IP (add|del|update)"
1007 			" flow l2_payload ether (ethertype)"
1008 			" flexbytes (flexbytes_value) (drop|fwd)"
1009 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1010 			"    Add/Del a l2 payload type flow director filter.\n\n"
1011 
1012 			"flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1013 			" mac (mac_address) vlan (vlan_value)"
1014 			" flexbytes (flexbytes_value) (drop|fwd)"
1015 			" queue (queue_id) fd_id (fd_id_value)\n"
1016 			"    Add/Del a MAC-VLAN flow director filter.\n\n"
1017 
1018 			"flow_director_filter (port_id) mode Tunnel (add|del|update)"
1019 			" mac (mac_address) vlan (vlan_value)"
1020 			" tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1021 			" flexbytes (flexbytes_value) (drop|fwd)"
1022 			" queue (queue_id) fd_id (fd_id_value)\n"
1023 			"    Add/Del a Tunnel flow director filter.\n\n"
1024 
1025 			"flow_director_filter (port_id) mode raw (add|del|update)"
1026 			" flow (flow_id) (drop|fwd) queue (queue_id)"
1027 			" fd_id (fd_id_value) packet (packet file name)\n"
1028 			"    Add/Del a raw type flow director filter.\n\n"
1029 
1030 			"flush_flow_director (port_id)\n"
1031 			"    Flush all flow director entries of a device.\n\n"
1032 
1033 			"flow_director_mask (port_id) mode IP vlan (vlan_value)"
1034 			" src_mask (ipv4_src) (ipv6_src) (src_port)"
1035 			" dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1036 			"    Set flow director IP mask.\n\n"
1037 
1038 			"flow_director_mask (port_id) mode MAC-VLAN"
1039 			" vlan (vlan_value)\n"
1040 			"    Set flow director MAC-VLAN mask.\n\n"
1041 
1042 			"flow_director_mask (port_id) mode Tunnel"
1043 			" vlan (vlan_value) mac (mac_value)"
1044 			" tunnel-type (tunnel_type_value)"
1045 			" tunnel-id (tunnel_id_value)\n"
1046 			"    Set flow director Tunnel mask.\n\n"
1047 
1048 			"flow_director_flex_mask (port_id)"
1049 			" flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1050 			"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1051 			" (mask)\n"
1052 			"    Configure mask of flex payload.\n\n"
1053 
1054 			"flow_director_flex_payload (port_id)"
1055 			" (raw|l2|l3|l4) (config)\n"
1056 			"    Configure flex payload selection.\n\n"
1057 
1058 			"get_sym_hash_ena_per_port (port_id)\n"
1059 			"    get symmetric hash enable configuration per port.\n\n"
1060 
1061 			"set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1062 			"    set symmetric hash enable configuration per port"
1063 			" to enable or disable.\n\n"
1064 
1065 			"get_hash_global_config (port_id)\n"
1066 			"    Get the global configurations of hash filters.\n\n"
1067 
1068 			"set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1069 			" (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1070 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1071 			" (enable|disable)\n"
1072 			"    Set the global configurations of hash filters.\n\n"
1073 
1074 			"set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1075 			"ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1076 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1077 			"l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1078 			"src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1079 			"ipv6-next-header|udp-src-port|udp-dst-port|"
1080 			"tcp-src-port|tcp-dst-port|sctp-src-port|"
1081 			"sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1082 			"fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1083 			"fld-8th|none) (select|add)\n"
1084 			"    Set the input set for hash.\n\n"
1085 
1086 			"set_fdir_input_set (port_id) "
1087 			"(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1088 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1089 			"l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1090 			"dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1091 			"ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1092 			"udp-dst-port|tcp-src-port|tcp-dst-port|"
1093 			"sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1094 			" (select|add)\n"
1095 			"    Set the input set for FDir.\n\n"
1096 
1097 			"flow validate {port_id}"
1098 			" [group {group_id}] [priority {level}]"
1099 			" [ingress] [egress]"
1100 			" pattern {item} [/ {item} [...]] / end"
1101 			" actions {action} [/ {action} [...]] / end\n"
1102 			"    Check whether a flow rule can be created.\n\n"
1103 
1104 			"flow create {port_id}"
1105 			" [group {group_id}] [priority {level}]"
1106 			" [ingress] [egress]"
1107 			" pattern {item} [/ {item} [...]] / end"
1108 			" actions {action} [/ {action} [...]] / end\n"
1109 			"    Create a flow rule.\n\n"
1110 
1111 			"flow destroy {port_id} rule {rule_id} [...]\n"
1112 			"    Destroy specific flow rules.\n\n"
1113 
1114 			"flow flush {port_id}\n"
1115 			"    Destroy all flow rules.\n\n"
1116 
1117 			"flow query {port_id} {rule_id} {action}\n"
1118 			"    Query an existing flow rule.\n\n"
1119 
1120 			"flow list {port_id} [group {group_id}] [...]\n"
1121 			"    List existing flow rules sorted by priority,"
1122 			" filtered by group identifiers.\n\n"
1123 
1124 			"flow isolate {port_id} {boolean}\n"
1125 			"    Restrict ingress traffic to the defined"
1126 			" flow rules\n\n"
1127 
1128 			"set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1129 			" (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1130 			" (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1131 			"       Configure the VXLAN encapsulation for flows.\n\n"
1132 
1133 			"set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1134 			" udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1135 			" ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1136 			" eth-dst (eth-dst)\n"
1137 			"       Configure the VXLAN encapsulation for flows.\n\n"
1138 
1139 			"set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1140 			" (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1141 			" ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1142 			" eth-dst (eth-dst)\n"
1143 			"       Configure the VXLAN encapsulation for flows.\n\n"
1144 
1145 			"set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1146 			" (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1147 			" (eth-dst)\n"
1148 			"       Configure the NVGRE encapsulation for flows.\n\n"
1149 
1150 			"set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1151 			" ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1152 			" eth-src (eth-src) eth-dst (eth-dst)\n"
1153 			"       Configure the NVGRE encapsulation for flows.\n\n"
1154 
1155 			"set raw_encap {flow items}\n"
1156 			"	Configure the encapsulation with raw data.\n\n"
1157 
1158 			"set raw_decap {flow items}\n"
1159 			"	Configure the decapsulation with raw data.\n\n"
1160 
1161 		);
1162 	}
1163 
1164 	if (show_all || !strcmp(res->section, "traffic_management")) {
1165 		cmdline_printf(
1166 			cl,
1167 			"\n"
1168 			"Traffic Management:\n"
1169 			"--------------\n"
1170 			"show port tm cap (port_id)\n"
1171 			"       Display the port TM capability.\n\n"
1172 
1173 			"show port tm level cap (port_id) (level_id)\n"
1174 			"       Display the port TM hierarchical level capability.\n\n"
1175 
1176 			"show port tm node cap (port_id) (node_id)\n"
1177 			"       Display the port TM node capability.\n\n"
1178 
1179 			"show port tm node type (port_id) (node_id)\n"
1180 			"       Display the port TM node type.\n\n"
1181 
1182 			"show port tm node stats (port_id) (node_id) (clear)\n"
1183 			"       Display the port TM node stats.\n\n"
1184 
1185 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1186 			"set port tm hierarchy default (port_id)\n"
1187 			"       Set default traffic Management hierarchy on a port\n\n"
1188 #endif
1189 
1190 			"add port tm node shaper profile (port_id) (shaper_profile_id)"
1191 			" (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1192 			" (packet_length_adjust)\n"
1193 			"       Add port tm node private shaper profile.\n\n"
1194 
1195 			"del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1196 			"       Delete port tm node private shaper profile.\n\n"
1197 
1198 			"add port tm node shared shaper (port_id) (shared_shaper_id)"
1199 			" (shaper_profile_id)\n"
1200 			"       Add/update port tm node shared shaper.\n\n"
1201 
1202 			"del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1203 			"       Delete port tm node shared shaper.\n\n"
1204 
1205 			"set port tm node shaper profile (port_id) (node_id)"
1206 			" (shaper_profile_id)\n"
1207 			"       Set port tm node shaper profile.\n\n"
1208 
1209 			"add port tm node wred profile (port_id) (wred_profile_id)"
1210 			" (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1211 			" (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1212 			" (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1213 			"       Add port tm node wred profile.\n\n"
1214 
1215 			"del port tm node wred profile (port_id) (wred_profile_id)\n"
1216 			"       Delete port tm node wred profile.\n\n"
1217 
1218 			"add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1219 			" (priority) (weight) (level_id) (shaper_profile_id)"
1220 			" (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1221 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1222 			"       Add port tm nonleaf node.\n\n"
1223 
1224 			"add port tm leaf node (port_id) (node_id) (parent_node_id)"
1225 			" (priority) (weight) (level_id) (shaper_profile_id)"
1226 			" (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1227 			" [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1228 			"       Add port tm leaf node.\n\n"
1229 
1230 			"del port tm node (port_id) (node_id)\n"
1231 			"       Delete port tm node.\n\n"
1232 
1233 			"set port tm node parent (port_id) (node_id) (parent_node_id)"
1234 			" (priority) (weight)\n"
1235 			"       Set port tm node parent.\n\n"
1236 
1237 			"suspend port tm node (port_id) (node_id)"
1238 			"       Suspend tm node.\n\n"
1239 
1240 			"resume port tm node (port_id) (node_id)"
1241 			"       Resume tm node.\n\n"
1242 
1243 			"port tm hierarchy commit (port_id) (clean_on_fail)\n"
1244 			"       Commit tm hierarchy.\n\n"
1245 
1246 			"set port tm mark ip_ecn (port) (green) (yellow)"
1247 			" (red)\n"
1248 			"    Enables/Disables the traffic management marking"
1249 			" for IP ECN (Explicit Congestion Notification)"
1250 			" packets on a given port\n\n"
1251 
1252 			"set port tm mark ip_dscp (port) (green) (yellow)"
1253 			" (red)\n"
1254 			"    Enables/Disables the traffic management marking"
1255 			" on the port for IP dscp packets\n\n"
1256 
1257 			"set port tm mark vlan_dei (port) (green) (yellow)"
1258 			" (red)\n"
1259 			"    Enables/Disables the traffic management marking"
1260 			" on the port for VLAN packets with DEI enabled\n\n"
1261 		);
1262 	}
1263 
1264 	if (show_all || !strcmp(res->section, "devices")) {
1265 		cmdline_printf(
1266 			cl,
1267 			"\n"
1268 			"Device Operations:\n"
1269 			"--------------\n"
1270 			"device detach (identifier)\n"
1271 			"       Detach device by identifier.\n\n"
1272 		);
1273 	}
1274 
1275 }
1276 
1277 cmdline_parse_token_string_t cmd_help_long_help =
1278 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1279 
1280 cmdline_parse_token_string_t cmd_help_long_section =
1281 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1282 			"all#control#display#config#"
1283 			"ports#registers#filters#traffic_management#devices");
1284 
1285 cmdline_parse_inst_t cmd_help_long = {
1286 	.f = cmd_help_long_parsed,
1287 	.data = NULL,
1288 	.help_str = "help all|control|display|config|ports|register|"
1289 		"filters|traffic_management|devices: "
1290 		"Show help",
1291 	.tokens = {
1292 		(void *)&cmd_help_long_help,
1293 		(void *)&cmd_help_long_section,
1294 		NULL,
1295 	},
1296 };
1297 
1298 
1299 /* *** start/stop/close all ports *** */
1300 struct cmd_operate_port_result {
1301 	cmdline_fixed_string_t keyword;
1302 	cmdline_fixed_string_t name;
1303 	cmdline_fixed_string_t value;
1304 };
1305 
1306 static void cmd_operate_port_parsed(void *parsed_result,
1307 				__attribute__((unused)) struct cmdline *cl,
1308 				__attribute__((unused)) void *data)
1309 {
1310 	struct cmd_operate_port_result *res = parsed_result;
1311 
1312 	if (!strcmp(res->name, "start"))
1313 		start_port(RTE_PORT_ALL);
1314 	else if (!strcmp(res->name, "stop"))
1315 		stop_port(RTE_PORT_ALL);
1316 	else if (!strcmp(res->name, "close"))
1317 		close_port(RTE_PORT_ALL);
1318 	else if (!strcmp(res->name, "reset"))
1319 		reset_port(RTE_PORT_ALL);
1320 	else
1321 		printf("Unknown parameter\n");
1322 }
1323 
1324 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1325 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1326 								"port");
1327 cmdline_parse_token_string_t cmd_operate_port_all_port =
1328 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1329 						"start#stop#close#reset");
1330 cmdline_parse_token_string_t cmd_operate_port_all_all =
1331 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1332 
1333 cmdline_parse_inst_t cmd_operate_port = {
1334 	.f = cmd_operate_port_parsed,
1335 	.data = NULL,
1336 	.help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1337 	.tokens = {
1338 		(void *)&cmd_operate_port_all_cmd,
1339 		(void *)&cmd_operate_port_all_port,
1340 		(void *)&cmd_operate_port_all_all,
1341 		NULL,
1342 	},
1343 };
1344 
1345 /* *** start/stop/close specific port *** */
1346 struct cmd_operate_specific_port_result {
1347 	cmdline_fixed_string_t keyword;
1348 	cmdline_fixed_string_t name;
1349 	uint8_t value;
1350 };
1351 
1352 static void cmd_operate_specific_port_parsed(void *parsed_result,
1353 			__attribute__((unused)) struct cmdline *cl,
1354 				__attribute__((unused)) void *data)
1355 {
1356 	struct cmd_operate_specific_port_result *res = parsed_result;
1357 
1358 	if (!strcmp(res->name, "start"))
1359 		start_port(res->value);
1360 	else if (!strcmp(res->name, "stop"))
1361 		stop_port(res->value);
1362 	else if (!strcmp(res->name, "close"))
1363 		close_port(res->value);
1364 	else if (!strcmp(res->name, "reset"))
1365 		reset_port(res->value);
1366 	else
1367 		printf("Unknown parameter\n");
1368 }
1369 
1370 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1371 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1372 							keyword, "port");
1373 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1374 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1375 						name, "start#stop#close#reset");
1376 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1377 	TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1378 							value, UINT8);
1379 
1380 cmdline_parse_inst_t cmd_operate_specific_port = {
1381 	.f = cmd_operate_specific_port_parsed,
1382 	.data = NULL,
1383 	.help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1384 	.tokens = {
1385 		(void *)&cmd_operate_specific_port_cmd,
1386 		(void *)&cmd_operate_specific_port_port,
1387 		(void *)&cmd_operate_specific_port_id,
1388 		NULL,
1389 	},
1390 };
1391 
1392 /* *** enable port setup (after attach) via iterator or event *** */
1393 struct cmd_set_port_setup_on_result {
1394 	cmdline_fixed_string_t set;
1395 	cmdline_fixed_string_t port;
1396 	cmdline_fixed_string_t setup;
1397 	cmdline_fixed_string_t on;
1398 	cmdline_fixed_string_t mode;
1399 };
1400 
1401 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1402 				__attribute__((unused)) struct cmdline *cl,
1403 				__attribute__((unused)) void *data)
1404 {
1405 	struct cmd_set_port_setup_on_result *res = parsed_result;
1406 
1407 	if (strcmp(res->mode, "event") == 0)
1408 		setup_on_probe_event = true;
1409 	else if (strcmp(res->mode, "iterator") == 0)
1410 		setup_on_probe_event = false;
1411 	else
1412 		printf("Unknown mode\n");
1413 }
1414 
1415 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1416 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1417 			set, "set");
1418 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1419 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1420 			port, "port");
1421 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1422 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1423 			setup, "setup");
1424 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1425 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1426 			on, "on");
1427 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1428 	TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1429 			mode, "iterator#event");
1430 
1431 cmdline_parse_inst_t cmd_set_port_setup_on = {
1432 	.f = cmd_set_port_setup_on_parsed,
1433 	.data = NULL,
1434 	.help_str = "set port setup on iterator|event",
1435 	.tokens = {
1436 		(void *)&cmd_set_port_setup_on_set,
1437 		(void *)&cmd_set_port_setup_on_port,
1438 		(void *)&cmd_set_port_setup_on_setup,
1439 		(void *)&cmd_set_port_setup_on_on,
1440 		(void *)&cmd_set_port_setup_on_mode,
1441 		NULL,
1442 	},
1443 };
1444 
1445 /* *** attach a specified port *** */
1446 struct cmd_operate_attach_port_result {
1447 	cmdline_fixed_string_t port;
1448 	cmdline_fixed_string_t keyword;
1449 	cmdline_fixed_string_t identifier;
1450 };
1451 
1452 static void cmd_operate_attach_port_parsed(void *parsed_result,
1453 				__attribute__((unused)) struct cmdline *cl,
1454 				__attribute__((unused)) void *data)
1455 {
1456 	struct cmd_operate_attach_port_result *res = parsed_result;
1457 
1458 	if (!strcmp(res->keyword, "attach"))
1459 		attach_port(res->identifier);
1460 	else
1461 		printf("Unknown parameter\n");
1462 }
1463 
1464 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1465 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1466 			port, "port");
1467 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1468 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1469 			keyword, "attach");
1470 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1471 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1472 			identifier, NULL);
1473 
1474 cmdline_parse_inst_t cmd_operate_attach_port = {
1475 	.f = cmd_operate_attach_port_parsed,
1476 	.data = NULL,
1477 	.help_str = "port attach <identifier>: "
1478 		"(identifier: pci address or virtual dev name)",
1479 	.tokens = {
1480 		(void *)&cmd_operate_attach_port_port,
1481 		(void *)&cmd_operate_attach_port_keyword,
1482 		(void *)&cmd_operate_attach_port_identifier,
1483 		NULL,
1484 	},
1485 };
1486 
1487 /* *** detach a specified port *** */
1488 struct cmd_operate_detach_port_result {
1489 	cmdline_fixed_string_t port;
1490 	cmdline_fixed_string_t keyword;
1491 	portid_t port_id;
1492 };
1493 
1494 static void cmd_operate_detach_port_parsed(void *parsed_result,
1495 				__attribute__((unused)) struct cmdline *cl,
1496 				__attribute__((unused)) void *data)
1497 {
1498 	struct cmd_operate_detach_port_result *res = parsed_result;
1499 
1500 	if (!strcmp(res->keyword, "detach"))
1501 		detach_port_device(res->port_id);
1502 	else
1503 		printf("Unknown parameter\n");
1504 }
1505 
1506 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1507 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1508 			port, "port");
1509 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1510 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1511 			keyword, "detach");
1512 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1513 	TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1514 			port_id, UINT16);
1515 
1516 cmdline_parse_inst_t cmd_operate_detach_port = {
1517 	.f = cmd_operate_detach_port_parsed,
1518 	.data = NULL,
1519 	.help_str = "port detach <port_id>",
1520 	.tokens = {
1521 		(void *)&cmd_operate_detach_port_port,
1522 		(void *)&cmd_operate_detach_port_keyword,
1523 		(void *)&cmd_operate_detach_port_port_id,
1524 		NULL,
1525 	},
1526 };
1527 
1528 /* *** detach device by identifier *** */
1529 struct cmd_operate_detach_device_result {
1530 	cmdline_fixed_string_t device;
1531 	cmdline_fixed_string_t keyword;
1532 	cmdline_fixed_string_t identifier;
1533 };
1534 
1535 static void cmd_operate_detach_device_parsed(void *parsed_result,
1536 				__attribute__((unused)) struct cmdline *cl,
1537 				__attribute__((unused)) void *data)
1538 {
1539 	struct cmd_operate_detach_device_result *res = parsed_result;
1540 
1541 	if (!strcmp(res->keyword, "detach"))
1542 		detach_device(res->identifier);
1543 	else
1544 		printf("Unknown parameter\n");
1545 }
1546 
1547 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1548 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1549 			device, "device");
1550 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1551 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1552 			keyword, "detach");
1553 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1554 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1555 			identifier, NULL);
1556 
1557 cmdline_parse_inst_t cmd_operate_detach_device = {
1558 	.f = cmd_operate_detach_device_parsed,
1559 	.data = NULL,
1560 	.help_str = "device detach <identifier>:"
1561 		"(identifier: pci address or virtual dev name)",
1562 	.tokens = {
1563 		(void *)&cmd_operate_detach_device_device,
1564 		(void *)&cmd_operate_detach_device_keyword,
1565 		(void *)&cmd_operate_detach_device_identifier,
1566 		NULL,
1567 	},
1568 };
1569 /* *** configure speed for all ports *** */
1570 struct cmd_config_speed_all {
1571 	cmdline_fixed_string_t port;
1572 	cmdline_fixed_string_t keyword;
1573 	cmdline_fixed_string_t all;
1574 	cmdline_fixed_string_t item1;
1575 	cmdline_fixed_string_t item2;
1576 	cmdline_fixed_string_t value1;
1577 	cmdline_fixed_string_t value2;
1578 };
1579 
1580 static int
1581 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1582 {
1583 
1584 	int duplex;
1585 
1586 	if (!strcmp(duplexstr, "half")) {
1587 		duplex = ETH_LINK_HALF_DUPLEX;
1588 	} else if (!strcmp(duplexstr, "full")) {
1589 		duplex = ETH_LINK_FULL_DUPLEX;
1590 	} else if (!strcmp(duplexstr, "auto")) {
1591 		duplex = ETH_LINK_FULL_DUPLEX;
1592 	} else {
1593 		printf("Unknown duplex parameter\n");
1594 		return -1;
1595 	}
1596 
1597 	if (!strcmp(speedstr, "10")) {
1598 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1599 				ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1600 	} else if (!strcmp(speedstr, "100")) {
1601 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1602 				ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1603 	} else {
1604 		if (duplex != ETH_LINK_FULL_DUPLEX) {
1605 			printf("Invalid speed/duplex parameters\n");
1606 			return -1;
1607 		}
1608 		if (!strcmp(speedstr, "1000")) {
1609 			*speed = ETH_LINK_SPEED_1G;
1610 		} else if (!strcmp(speedstr, "10000")) {
1611 			*speed = ETH_LINK_SPEED_10G;
1612 		} else if (!strcmp(speedstr, "25000")) {
1613 			*speed = ETH_LINK_SPEED_25G;
1614 		} else if (!strcmp(speedstr, "40000")) {
1615 			*speed = ETH_LINK_SPEED_40G;
1616 		} else if (!strcmp(speedstr, "50000")) {
1617 			*speed = ETH_LINK_SPEED_50G;
1618 		} else if (!strcmp(speedstr, "100000")) {
1619 			*speed = ETH_LINK_SPEED_100G;
1620 		} else if (!strcmp(speedstr, "auto")) {
1621 			*speed = ETH_LINK_SPEED_AUTONEG;
1622 		} else {
1623 			printf("Unknown speed parameter\n");
1624 			return -1;
1625 		}
1626 	}
1627 
1628 	return 0;
1629 }
1630 
1631 static void
1632 cmd_config_speed_all_parsed(void *parsed_result,
1633 			__attribute__((unused)) struct cmdline *cl,
1634 			__attribute__((unused)) void *data)
1635 {
1636 	struct cmd_config_speed_all *res = parsed_result;
1637 	uint32_t link_speed;
1638 	portid_t pid;
1639 
1640 	if (!all_ports_stopped()) {
1641 		printf("Please stop all ports first\n");
1642 		return;
1643 	}
1644 
1645 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1646 			&link_speed) < 0)
1647 		return;
1648 
1649 	RTE_ETH_FOREACH_DEV(pid) {
1650 		ports[pid].dev_conf.link_speeds = link_speed;
1651 	}
1652 
1653 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1654 }
1655 
1656 cmdline_parse_token_string_t cmd_config_speed_all_port =
1657 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1658 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1659 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1660 							"config");
1661 cmdline_parse_token_string_t cmd_config_speed_all_all =
1662 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1663 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1664 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1665 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1666 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1667 				"10#100#1000#10000#25000#40000#50000#100000#auto");
1668 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1669 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1670 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1671 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1672 						"half#full#auto");
1673 
1674 cmdline_parse_inst_t cmd_config_speed_all = {
1675 	.f = cmd_config_speed_all_parsed,
1676 	.data = NULL,
1677 	.help_str = "port config all speed "
1678 		"10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1679 							"half|full|auto",
1680 	.tokens = {
1681 		(void *)&cmd_config_speed_all_port,
1682 		(void *)&cmd_config_speed_all_keyword,
1683 		(void *)&cmd_config_speed_all_all,
1684 		(void *)&cmd_config_speed_all_item1,
1685 		(void *)&cmd_config_speed_all_value1,
1686 		(void *)&cmd_config_speed_all_item2,
1687 		(void *)&cmd_config_speed_all_value2,
1688 		NULL,
1689 	},
1690 };
1691 
1692 /* *** configure speed for specific port *** */
1693 struct cmd_config_speed_specific {
1694 	cmdline_fixed_string_t port;
1695 	cmdline_fixed_string_t keyword;
1696 	portid_t id;
1697 	cmdline_fixed_string_t item1;
1698 	cmdline_fixed_string_t item2;
1699 	cmdline_fixed_string_t value1;
1700 	cmdline_fixed_string_t value2;
1701 };
1702 
1703 static void
1704 cmd_config_speed_specific_parsed(void *parsed_result,
1705 				__attribute__((unused)) struct cmdline *cl,
1706 				__attribute__((unused)) void *data)
1707 {
1708 	struct cmd_config_speed_specific *res = parsed_result;
1709 	uint32_t link_speed;
1710 
1711 	if (!all_ports_stopped()) {
1712 		printf("Please stop all ports first\n");
1713 		return;
1714 	}
1715 
1716 	if (port_id_is_invalid(res->id, ENABLED_WARN))
1717 		return;
1718 
1719 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1720 			&link_speed) < 0)
1721 		return;
1722 
1723 	ports[res->id].dev_conf.link_speeds = link_speed;
1724 
1725 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1726 }
1727 
1728 
1729 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1730 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1731 								"port");
1732 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1733 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1734 								"config");
1735 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1736 	TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1737 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1738 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1739 								"speed");
1740 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1741 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1742 				"10#100#1000#10000#25000#40000#50000#100000#auto");
1743 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1744 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1745 								"duplex");
1746 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1747 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1748 							"half#full#auto");
1749 
1750 cmdline_parse_inst_t cmd_config_speed_specific = {
1751 	.f = cmd_config_speed_specific_parsed,
1752 	.data = NULL,
1753 	.help_str = "port config <port_id> speed "
1754 		"10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1755 							"half|full|auto",
1756 	.tokens = {
1757 		(void *)&cmd_config_speed_specific_port,
1758 		(void *)&cmd_config_speed_specific_keyword,
1759 		(void *)&cmd_config_speed_specific_id,
1760 		(void *)&cmd_config_speed_specific_item1,
1761 		(void *)&cmd_config_speed_specific_value1,
1762 		(void *)&cmd_config_speed_specific_item2,
1763 		(void *)&cmd_config_speed_specific_value2,
1764 		NULL,
1765 	},
1766 };
1767 
1768 /* *** configure loopback for all ports *** */
1769 struct cmd_config_loopback_all {
1770 	cmdline_fixed_string_t port;
1771 	cmdline_fixed_string_t keyword;
1772 	cmdline_fixed_string_t all;
1773 	cmdline_fixed_string_t item;
1774 	uint32_t mode;
1775 };
1776 
1777 static void
1778 cmd_config_loopback_all_parsed(void *parsed_result,
1779 			__attribute__((unused)) struct cmdline *cl,
1780 			__attribute__((unused)) void *data)
1781 {
1782 	struct cmd_config_loopback_all *res = parsed_result;
1783 	portid_t pid;
1784 
1785 	if (!all_ports_stopped()) {
1786 		printf("Please stop all ports first\n");
1787 		return;
1788 	}
1789 
1790 	RTE_ETH_FOREACH_DEV(pid) {
1791 		ports[pid].dev_conf.lpbk_mode = res->mode;
1792 	}
1793 
1794 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1795 }
1796 
1797 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1798 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1799 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1800 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1801 							"config");
1802 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1803 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1804 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1805 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1806 							"loopback");
1807 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1808 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1809 
1810 cmdline_parse_inst_t cmd_config_loopback_all = {
1811 	.f = cmd_config_loopback_all_parsed,
1812 	.data = NULL,
1813 	.help_str = "port config all loopback <mode>",
1814 	.tokens = {
1815 		(void *)&cmd_config_loopback_all_port,
1816 		(void *)&cmd_config_loopback_all_keyword,
1817 		(void *)&cmd_config_loopback_all_all,
1818 		(void *)&cmd_config_loopback_all_item,
1819 		(void *)&cmd_config_loopback_all_mode,
1820 		NULL,
1821 	},
1822 };
1823 
1824 /* *** configure loopback for specific port *** */
1825 struct cmd_config_loopback_specific {
1826 	cmdline_fixed_string_t port;
1827 	cmdline_fixed_string_t keyword;
1828 	uint16_t port_id;
1829 	cmdline_fixed_string_t item;
1830 	uint32_t mode;
1831 };
1832 
1833 static void
1834 cmd_config_loopback_specific_parsed(void *parsed_result,
1835 				__attribute__((unused)) struct cmdline *cl,
1836 				__attribute__((unused)) void *data)
1837 {
1838 	struct cmd_config_loopback_specific *res = parsed_result;
1839 
1840 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1841 		return;
1842 
1843 	if (!port_is_stopped(res->port_id)) {
1844 		printf("Please stop port %u first\n", res->port_id);
1845 		return;
1846 	}
1847 
1848 	ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1849 
1850 	cmd_reconfig_device_queue(res->port_id, 1, 1);
1851 }
1852 
1853 
1854 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1855 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1856 								"port");
1857 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1858 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1859 								"config");
1860 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1861 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1862 								UINT16);
1863 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1864 	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1865 								"loopback");
1866 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1867 	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1868 			      UINT32);
1869 
1870 cmdline_parse_inst_t cmd_config_loopback_specific = {
1871 	.f = cmd_config_loopback_specific_parsed,
1872 	.data = NULL,
1873 	.help_str = "port config <port_id> loopback <mode>",
1874 	.tokens = {
1875 		(void *)&cmd_config_loopback_specific_port,
1876 		(void *)&cmd_config_loopback_specific_keyword,
1877 		(void *)&cmd_config_loopback_specific_id,
1878 		(void *)&cmd_config_loopback_specific_item,
1879 		(void *)&cmd_config_loopback_specific_mode,
1880 		NULL,
1881 	},
1882 };
1883 
1884 /* *** configure txq/rxq, txd/rxd *** */
1885 struct cmd_config_rx_tx {
1886 	cmdline_fixed_string_t port;
1887 	cmdline_fixed_string_t keyword;
1888 	cmdline_fixed_string_t all;
1889 	cmdline_fixed_string_t name;
1890 	uint16_t value;
1891 };
1892 
1893 static void
1894 cmd_config_rx_tx_parsed(void *parsed_result,
1895 			__attribute__((unused)) struct cmdline *cl,
1896 			__attribute__((unused)) void *data)
1897 {
1898 	struct cmd_config_rx_tx *res = parsed_result;
1899 
1900 	if (!all_ports_stopped()) {
1901 		printf("Please stop all ports first\n");
1902 		return;
1903 	}
1904 	if (!strcmp(res->name, "rxq")) {
1905 		if (!res->value && !nb_txq) {
1906 			printf("Warning: Either rx or tx queues should be non zero\n");
1907 			return;
1908 		}
1909 		if (check_nb_rxq(res->value) != 0)
1910 			return;
1911 		nb_rxq = res->value;
1912 	}
1913 	else if (!strcmp(res->name, "txq")) {
1914 		if (!res->value && !nb_rxq) {
1915 			printf("Warning: Either rx or tx queues should be non zero\n");
1916 			return;
1917 		}
1918 		if (check_nb_txq(res->value) != 0)
1919 			return;
1920 		nb_txq = res->value;
1921 	}
1922 	else if (!strcmp(res->name, "rxd")) {
1923 		if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1924 			printf("rxd %d invalid - must be > 0 && <= %d\n",
1925 					res->value, RTE_TEST_RX_DESC_MAX);
1926 			return;
1927 		}
1928 		nb_rxd = res->value;
1929 	} else if (!strcmp(res->name, "txd")) {
1930 		if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1931 			printf("txd %d invalid - must be > 0 && <= %d\n",
1932 					res->value, RTE_TEST_TX_DESC_MAX);
1933 			return;
1934 		}
1935 		nb_txd = res->value;
1936 	} else {
1937 		printf("Unknown parameter\n");
1938 		return;
1939 	}
1940 
1941 	fwd_config_setup();
1942 
1943 	init_port_config();
1944 
1945 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1946 }
1947 
1948 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1949 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1950 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1951 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1952 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1953 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1954 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1955 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1956 						"rxq#txq#rxd#txd");
1957 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1958 	TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1959 
1960 cmdline_parse_inst_t cmd_config_rx_tx = {
1961 	.f = cmd_config_rx_tx_parsed,
1962 	.data = NULL,
1963 	.help_str = "port config all rxq|txq|rxd|txd <value>",
1964 	.tokens = {
1965 		(void *)&cmd_config_rx_tx_port,
1966 		(void *)&cmd_config_rx_tx_keyword,
1967 		(void *)&cmd_config_rx_tx_all,
1968 		(void *)&cmd_config_rx_tx_name,
1969 		(void *)&cmd_config_rx_tx_value,
1970 		NULL,
1971 	},
1972 };
1973 
1974 /* *** config max packet length *** */
1975 struct cmd_config_max_pkt_len_result {
1976 	cmdline_fixed_string_t port;
1977 	cmdline_fixed_string_t keyword;
1978 	cmdline_fixed_string_t all;
1979 	cmdline_fixed_string_t name;
1980 	uint32_t value;
1981 };
1982 
1983 static void
1984 cmd_config_max_pkt_len_parsed(void *parsed_result,
1985 				__attribute__((unused)) struct cmdline *cl,
1986 				__attribute__((unused)) void *data)
1987 {
1988 	struct cmd_config_max_pkt_len_result *res = parsed_result;
1989 	portid_t pid;
1990 
1991 	if (!all_ports_stopped()) {
1992 		printf("Please stop all ports first\n");
1993 		return;
1994 	}
1995 
1996 	RTE_ETH_FOREACH_DEV(pid) {
1997 		struct rte_port *port = &ports[pid];
1998 		uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1999 
2000 		if (!strcmp(res->name, "max-pkt-len")) {
2001 			if (res->value < RTE_ETHER_MIN_LEN) {
2002 				printf("max-pkt-len can not be less than %d\n",
2003 						RTE_ETHER_MIN_LEN);
2004 				return;
2005 			}
2006 			if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2007 				return;
2008 
2009 			port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2010 			if (res->value > RTE_ETHER_MAX_LEN)
2011 				rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2012 			else
2013 				rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2014 			port->dev_conf.rxmode.offloads = rx_offloads;
2015 		} else {
2016 			printf("Unknown parameter\n");
2017 			return;
2018 		}
2019 	}
2020 
2021 	init_port_config();
2022 
2023 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2024 }
2025 
2026 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2027 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2028 								"port");
2029 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2030 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2031 								"config");
2032 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2033 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2034 								"all");
2035 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2036 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2037 								"max-pkt-len");
2038 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2039 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2040 								UINT32);
2041 
2042 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2043 	.f = cmd_config_max_pkt_len_parsed,
2044 	.data = NULL,
2045 	.help_str = "port config all max-pkt-len <value>",
2046 	.tokens = {
2047 		(void *)&cmd_config_max_pkt_len_port,
2048 		(void *)&cmd_config_max_pkt_len_keyword,
2049 		(void *)&cmd_config_max_pkt_len_all,
2050 		(void *)&cmd_config_max_pkt_len_name,
2051 		(void *)&cmd_config_max_pkt_len_value,
2052 		NULL,
2053 	},
2054 };
2055 
2056 /* *** config max LRO aggregated packet size *** */
2057 struct cmd_config_max_lro_pkt_size_result {
2058 	cmdline_fixed_string_t port;
2059 	cmdline_fixed_string_t keyword;
2060 	cmdline_fixed_string_t all;
2061 	cmdline_fixed_string_t name;
2062 	uint32_t value;
2063 };
2064 
2065 static void
2066 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2067 				__attribute__((unused)) struct cmdline *cl,
2068 				__attribute__((unused)) void *data)
2069 {
2070 	struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2071 	portid_t pid;
2072 
2073 	if (!all_ports_stopped()) {
2074 		printf("Please stop all ports first\n");
2075 		return;
2076 	}
2077 
2078 	RTE_ETH_FOREACH_DEV(pid) {
2079 		struct rte_port *port = &ports[pid];
2080 
2081 		if (!strcmp(res->name, "max-lro-pkt-size")) {
2082 			if (res->value ==
2083 					port->dev_conf.rxmode.max_lro_pkt_size)
2084 				return;
2085 
2086 			port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2087 		} else {
2088 			printf("Unknown parameter\n");
2089 			return;
2090 		}
2091 	}
2092 
2093 	init_port_config();
2094 
2095 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2096 }
2097 
2098 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2099 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2100 				 port, "port");
2101 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2102 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2103 				 keyword, "config");
2104 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2105 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2106 				 all, "all");
2107 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2108 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2109 				 name, "max-lro-pkt-size");
2110 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2111 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2112 			      value, UINT32);
2113 
2114 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2115 	.f = cmd_config_max_lro_pkt_size_parsed,
2116 	.data = NULL,
2117 	.help_str = "port config all max-lro-pkt-size <value>",
2118 	.tokens = {
2119 		(void *)&cmd_config_max_lro_pkt_size_port,
2120 		(void *)&cmd_config_max_lro_pkt_size_keyword,
2121 		(void *)&cmd_config_max_lro_pkt_size_all,
2122 		(void *)&cmd_config_max_lro_pkt_size_name,
2123 		(void *)&cmd_config_max_lro_pkt_size_value,
2124 		NULL,
2125 	},
2126 };
2127 
2128 /* *** configure port MTU *** */
2129 struct cmd_config_mtu_result {
2130 	cmdline_fixed_string_t port;
2131 	cmdline_fixed_string_t keyword;
2132 	cmdline_fixed_string_t mtu;
2133 	portid_t port_id;
2134 	uint16_t value;
2135 };
2136 
2137 static void
2138 cmd_config_mtu_parsed(void *parsed_result,
2139 		      __attribute__((unused)) struct cmdline *cl,
2140 		      __attribute__((unused)) void *data)
2141 {
2142 	struct cmd_config_mtu_result *res = parsed_result;
2143 
2144 	if (res->value < RTE_ETHER_MIN_LEN) {
2145 		printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2146 		return;
2147 	}
2148 	port_mtu_set(res->port_id, res->value);
2149 }
2150 
2151 cmdline_parse_token_string_t cmd_config_mtu_port =
2152 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2153 				 "port");
2154 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2155 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2156 				 "config");
2157 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2158 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2159 				 "mtu");
2160 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2161 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2162 cmdline_parse_token_num_t cmd_config_mtu_value =
2163 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2164 
2165 cmdline_parse_inst_t cmd_config_mtu = {
2166 	.f = cmd_config_mtu_parsed,
2167 	.data = NULL,
2168 	.help_str = "port config mtu <port_id> <value>",
2169 	.tokens = {
2170 		(void *)&cmd_config_mtu_port,
2171 		(void *)&cmd_config_mtu_keyword,
2172 		(void *)&cmd_config_mtu_mtu,
2173 		(void *)&cmd_config_mtu_port_id,
2174 		(void *)&cmd_config_mtu_value,
2175 		NULL,
2176 	},
2177 };
2178 
2179 /* *** configure rx mode *** */
2180 struct cmd_config_rx_mode_flag {
2181 	cmdline_fixed_string_t port;
2182 	cmdline_fixed_string_t keyword;
2183 	cmdline_fixed_string_t all;
2184 	cmdline_fixed_string_t name;
2185 	cmdline_fixed_string_t value;
2186 };
2187 
2188 static void
2189 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2190 				__attribute__((unused)) struct cmdline *cl,
2191 				__attribute__((unused)) void *data)
2192 {
2193 	struct cmd_config_rx_mode_flag *res = parsed_result;
2194 
2195 	if (!all_ports_stopped()) {
2196 		printf("Please stop all ports first\n");
2197 		return;
2198 	}
2199 
2200 	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 
2214 	init_port_config();
2215 
2216 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2217 }
2218 
2219 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2220 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2221 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2222 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2223 								"config");
2224 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2225 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2226 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2227 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2228 					"drop-en");
2229 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2230 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2231 							"on#off");
2232 
2233 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2234 	.f = cmd_config_rx_mode_flag_parsed,
2235 	.data = NULL,
2236 	.help_str = "port config all drop-en on|off",
2237 	.tokens = {
2238 		(void *)&cmd_config_rx_mode_flag_port,
2239 		(void *)&cmd_config_rx_mode_flag_keyword,
2240 		(void *)&cmd_config_rx_mode_flag_all,
2241 		(void *)&cmd_config_rx_mode_flag_name,
2242 		(void *)&cmd_config_rx_mode_flag_value,
2243 		NULL,
2244 	},
2245 };
2246 
2247 /* *** configure rss *** */
2248 struct cmd_config_rss {
2249 	cmdline_fixed_string_t port;
2250 	cmdline_fixed_string_t keyword;
2251 	cmdline_fixed_string_t all;
2252 	cmdline_fixed_string_t name;
2253 	cmdline_fixed_string_t value;
2254 };
2255 
2256 static void
2257 cmd_config_rss_parsed(void *parsed_result,
2258 			__attribute__((unused)) struct cmdline *cl,
2259 			__attribute__((unused)) void *data)
2260 {
2261 	struct cmd_config_rss *res = parsed_result;
2262 	struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2263 	struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2264 	int use_default = 0;
2265 	int all_updated = 1;
2266 	int diag;
2267 	uint16_t i;
2268 	int ret;
2269 
2270 	if (!strcmp(res->value, "all"))
2271 		rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2272 				ETH_RSS_UDP | ETH_RSS_SCTP |
2273 					ETH_RSS_L2_PAYLOAD;
2274 	else if (!strcmp(res->value, "ip"))
2275 		rss_conf.rss_hf = ETH_RSS_IP;
2276 	else if (!strcmp(res->value, "udp"))
2277 		rss_conf.rss_hf = ETH_RSS_UDP;
2278 	else if (!strcmp(res->value, "tcp"))
2279 		rss_conf.rss_hf = ETH_RSS_TCP;
2280 	else if (!strcmp(res->value, "sctp"))
2281 		rss_conf.rss_hf = ETH_RSS_SCTP;
2282 	else if (!strcmp(res->value, "ether"))
2283 		rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2284 	else if (!strcmp(res->value, "port"))
2285 		rss_conf.rss_hf = ETH_RSS_PORT;
2286 	else if (!strcmp(res->value, "vxlan"))
2287 		rss_conf.rss_hf = ETH_RSS_VXLAN;
2288 	else if (!strcmp(res->value, "geneve"))
2289 		rss_conf.rss_hf = ETH_RSS_GENEVE;
2290 	else if (!strcmp(res->value, "nvgre"))
2291 		rss_conf.rss_hf = ETH_RSS_NVGRE;
2292 	else if (!strcmp(res->value, "l3-src-only"))
2293 		rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2294 	else if (!strcmp(res->value, "l3-dst-only"))
2295 		rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2296 	else if (!strcmp(res->value, "l4-src-only"))
2297 		rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2298 	else if (!strcmp(res->value, "l4-dst-only"))
2299 		rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2300 	else if (!strcmp(res->value, "none"))
2301 		rss_conf.rss_hf = 0;
2302 	else if (!strcmp(res->value, "default"))
2303 		use_default = 1;
2304 	else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2305 						atoi(res->value) < 64)
2306 		rss_conf.rss_hf = 1ULL << atoi(res->value);
2307 	else {
2308 		printf("Unknown parameter\n");
2309 		return;
2310 	}
2311 	rss_conf.rss_key = NULL;
2312 	/* Update global configuration for RSS types. */
2313 	RTE_ETH_FOREACH_DEV(i) {
2314 		struct rte_eth_rss_conf local_rss_conf;
2315 
2316 		ret = eth_dev_info_get_print_err(i, &dev_info);
2317 		if (ret != 0)
2318 			return;
2319 
2320 		if (use_default)
2321 			rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2322 
2323 		local_rss_conf = rss_conf;
2324 		local_rss_conf.rss_hf = rss_conf.rss_hf &
2325 			dev_info.flow_type_rss_offloads;
2326 		if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2327 			printf("Port %u modified RSS hash function based on hardware support,"
2328 				"requested:%#"PRIx64" configured:%#"PRIx64"\n",
2329 				i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2330 		}
2331 		diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2332 		if (diag < 0) {
2333 			all_updated = 0;
2334 			printf("Configuration of RSS hash at ethernet port %d "
2335 				"failed with error (%d): %s.\n",
2336 				i, -diag, strerror(-diag));
2337 		}
2338 	}
2339 	if (all_updated && !use_default)
2340 		rss_hf = rss_conf.rss_hf;
2341 }
2342 
2343 cmdline_parse_token_string_t cmd_config_rss_port =
2344 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2345 cmdline_parse_token_string_t cmd_config_rss_keyword =
2346 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2347 cmdline_parse_token_string_t cmd_config_rss_all =
2348 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2349 cmdline_parse_token_string_t cmd_config_rss_name =
2350 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2351 cmdline_parse_token_string_t cmd_config_rss_value =
2352 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2353 
2354 cmdline_parse_inst_t cmd_config_rss = {
2355 	.f = cmd_config_rss_parsed,
2356 	.data = NULL,
2357 	.help_str = "port config all rss "
2358 		"all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2359 	.tokens = {
2360 		(void *)&cmd_config_rss_port,
2361 		(void *)&cmd_config_rss_keyword,
2362 		(void *)&cmd_config_rss_all,
2363 		(void *)&cmd_config_rss_name,
2364 		(void *)&cmd_config_rss_value,
2365 		NULL,
2366 	},
2367 };
2368 
2369 /* *** configure rss hash key *** */
2370 struct cmd_config_rss_hash_key {
2371 	cmdline_fixed_string_t port;
2372 	cmdline_fixed_string_t config;
2373 	portid_t port_id;
2374 	cmdline_fixed_string_t rss_hash_key;
2375 	cmdline_fixed_string_t rss_type;
2376 	cmdline_fixed_string_t key;
2377 };
2378 
2379 static uint8_t
2380 hexa_digit_to_value(char hexa_digit)
2381 {
2382 	if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2383 		return (uint8_t) (hexa_digit - '0');
2384 	if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2385 		return (uint8_t) ((hexa_digit - 'a') + 10);
2386 	if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2387 		return (uint8_t) ((hexa_digit - 'A') + 10);
2388 	/* Invalid hexa digit */
2389 	return 0xFF;
2390 }
2391 
2392 static uint8_t
2393 parse_and_check_key_hexa_digit(char *key, int idx)
2394 {
2395 	uint8_t hexa_v;
2396 
2397 	hexa_v = hexa_digit_to_value(key[idx]);
2398 	if (hexa_v == 0xFF)
2399 		printf("invalid key: character %c at position %d is not a "
2400 		       "valid hexa digit\n", key[idx], idx);
2401 	return hexa_v;
2402 }
2403 
2404 static void
2405 cmd_config_rss_hash_key_parsed(void *parsed_result,
2406 			       __attribute__((unused)) struct cmdline *cl,
2407 			       __attribute__((unused)) void *data)
2408 {
2409 	struct cmd_config_rss_hash_key *res = parsed_result;
2410 	uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2411 	uint8_t xdgt0;
2412 	uint8_t xdgt1;
2413 	int i;
2414 	struct rte_eth_dev_info dev_info;
2415 	uint8_t hash_key_size;
2416 	uint32_t key_len;
2417 	int ret;
2418 
2419 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2420 	if (ret != 0)
2421 		return;
2422 
2423 	if (dev_info.hash_key_size > 0 &&
2424 			dev_info.hash_key_size <= sizeof(hash_key))
2425 		hash_key_size = dev_info.hash_key_size;
2426 	else {
2427 		printf("dev_info did not provide a valid hash key size\n");
2428 		return;
2429 	}
2430 	/* Check the length of the RSS hash key */
2431 	key_len = strlen(res->key);
2432 	if (key_len != (hash_key_size * 2)) {
2433 		printf("key length: %d invalid - key must be a string of %d"
2434 			   " hexa-decimal numbers\n",
2435 			   (int) key_len, hash_key_size * 2);
2436 		return;
2437 	}
2438 	/* Translate RSS hash key into binary representation */
2439 	for (i = 0; i < hash_key_size; i++) {
2440 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2441 		if (xdgt0 == 0xFF)
2442 			return;
2443 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2444 		if (xdgt1 == 0xFF)
2445 			return;
2446 		hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2447 	}
2448 	port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2449 			hash_key_size);
2450 }
2451 
2452 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2453 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2454 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2455 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2456 				 "config");
2457 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2458 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2459 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2460 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2461 				 rss_hash_key, "rss-hash-key");
2462 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2463 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2464 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2465 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2466 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2467 				 "ipv6-tcp-ex#ipv6-udp-ex#"
2468 				 "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only");
2469 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2470 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2471 
2472 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2473 	.f = cmd_config_rss_hash_key_parsed,
2474 	.data = NULL,
2475 	.help_str = "port config <port_id> rss-hash-key "
2476 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2477 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2478 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2479 		"l3-src-only|l3-dst-only|l4-src-only|l4-dst-only "
2480 		"<string of hex digits (variable length, NIC dependent)>",
2481 	.tokens = {
2482 		(void *)&cmd_config_rss_hash_key_port,
2483 		(void *)&cmd_config_rss_hash_key_config,
2484 		(void *)&cmd_config_rss_hash_key_port_id,
2485 		(void *)&cmd_config_rss_hash_key_rss_hash_key,
2486 		(void *)&cmd_config_rss_hash_key_rss_type,
2487 		(void *)&cmd_config_rss_hash_key_value,
2488 		NULL,
2489 	},
2490 };
2491 
2492 /* *** configure port rxq/txq ring size *** */
2493 struct cmd_config_rxtx_ring_size {
2494 	cmdline_fixed_string_t port;
2495 	cmdline_fixed_string_t config;
2496 	portid_t portid;
2497 	cmdline_fixed_string_t rxtxq;
2498 	uint16_t qid;
2499 	cmdline_fixed_string_t rsize;
2500 	uint16_t size;
2501 };
2502 
2503 static void
2504 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2505 				 __attribute__((unused)) struct cmdline *cl,
2506 				 __attribute__((unused)) void *data)
2507 {
2508 	struct cmd_config_rxtx_ring_size *res = parsed_result;
2509 	struct rte_port *port;
2510 	uint8_t isrx;
2511 
2512 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2513 		return;
2514 
2515 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2516 		printf("Invalid port id\n");
2517 		return;
2518 	}
2519 
2520 	port = &ports[res->portid];
2521 
2522 	if (!strcmp(res->rxtxq, "rxq"))
2523 		isrx = 1;
2524 	else if (!strcmp(res->rxtxq, "txq"))
2525 		isrx = 0;
2526 	else {
2527 		printf("Unknown parameter\n");
2528 		return;
2529 	}
2530 
2531 	if (isrx && rx_queue_id_is_invalid(res->qid))
2532 		return;
2533 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2534 		return;
2535 
2536 	if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2537 		printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2538 		       rx_free_thresh);
2539 		return;
2540 	}
2541 
2542 	if (isrx)
2543 		port->nb_rx_desc[res->qid] = res->size;
2544 	else
2545 		port->nb_tx_desc[res->qid] = res->size;
2546 
2547 	cmd_reconfig_device_queue(res->portid, 0, 1);
2548 }
2549 
2550 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2551 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2552 				 port, "port");
2553 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2554 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2555 				 config, "config");
2556 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2557 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2558 				 portid, UINT16);
2559 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2560 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2561 				 rxtxq, "rxq#txq");
2562 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2563 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2564 			      qid, UINT16);
2565 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2566 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2567 				 rsize, "ring_size");
2568 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2569 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2570 			      size, UINT16);
2571 
2572 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2573 	.f = cmd_config_rxtx_ring_size_parsed,
2574 	.data = NULL,
2575 	.help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2576 	.tokens = {
2577 		(void *)&cmd_config_rxtx_ring_size_port,
2578 		(void *)&cmd_config_rxtx_ring_size_config,
2579 		(void *)&cmd_config_rxtx_ring_size_portid,
2580 		(void *)&cmd_config_rxtx_ring_size_rxtxq,
2581 		(void *)&cmd_config_rxtx_ring_size_qid,
2582 		(void *)&cmd_config_rxtx_ring_size_rsize,
2583 		(void *)&cmd_config_rxtx_ring_size_size,
2584 		NULL,
2585 	},
2586 };
2587 
2588 /* *** configure port rxq/txq start/stop *** */
2589 struct cmd_config_rxtx_queue {
2590 	cmdline_fixed_string_t port;
2591 	portid_t portid;
2592 	cmdline_fixed_string_t rxtxq;
2593 	uint16_t qid;
2594 	cmdline_fixed_string_t opname;
2595 };
2596 
2597 static void
2598 cmd_config_rxtx_queue_parsed(void *parsed_result,
2599 			__attribute__((unused)) struct cmdline *cl,
2600 			__attribute__((unused)) void *data)
2601 {
2602 	struct cmd_config_rxtx_queue *res = parsed_result;
2603 	uint8_t isrx;
2604 	uint8_t isstart;
2605 	int ret = 0;
2606 
2607 	if (test_done == 0) {
2608 		printf("Please stop forwarding first\n");
2609 		return;
2610 	}
2611 
2612 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2613 		return;
2614 
2615 	if (port_is_started(res->portid) != 1) {
2616 		printf("Please start port %u first\n", res->portid);
2617 		return;
2618 	}
2619 
2620 	if (!strcmp(res->rxtxq, "rxq"))
2621 		isrx = 1;
2622 	else if (!strcmp(res->rxtxq, "txq"))
2623 		isrx = 0;
2624 	else {
2625 		printf("Unknown parameter\n");
2626 		return;
2627 	}
2628 
2629 	if (isrx && rx_queue_id_is_invalid(res->qid))
2630 		return;
2631 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2632 		return;
2633 
2634 	if (!strcmp(res->opname, "start"))
2635 		isstart = 1;
2636 	else if (!strcmp(res->opname, "stop"))
2637 		isstart = 0;
2638 	else {
2639 		printf("Unknown parameter\n");
2640 		return;
2641 	}
2642 
2643 	if (isstart && isrx)
2644 		ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2645 	else if (!isstart && isrx)
2646 		ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2647 	else if (isstart && !isrx)
2648 		ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2649 	else
2650 		ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2651 
2652 	if (ret == -ENOTSUP)
2653 		printf("Function not supported in PMD driver\n");
2654 }
2655 
2656 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2657 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2658 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2659 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2660 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2661 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2662 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2663 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2664 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2665 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2666 						"start#stop");
2667 
2668 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2669 	.f = cmd_config_rxtx_queue_parsed,
2670 	.data = NULL,
2671 	.help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2672 	.tokens = {
2673 		(void *)&cmd_config_rxtx_queue_port,
2674 		(void *)&cmd_config_rxtx_queue_portid,
2675 		(void *)&cmd_config_rxtx_queue_rxtxq,
2676 		(void *)&cmd_config_rxtx_queue_qid,
2677 		(void *)&cmd_config_rxtx_queue_opname,
2678 		NULL,
2679 	},
2680 };
2681 
2682 /* *** configure port rxq/txq deferred start on/off *** */
2683 struct cmd_config_deferred_start_rxtx_queue {
2684 	cmdline_fixed_string_t port;
2685 	portid_t port_id;
2686 	cmdline_fixed_string_t rxtxq;
2687 	uint16_t qid;
2688 	cmdline_fixed_string_t opname;
2689 	cmdline_fixed_string_t state;
2690 };
2691 
2692 static void
2693 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2694 			__attribute__((unused)) struct cmdline *cl,
2695 			__attribute__((unused)) void *data)
2696 {
2697 	struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2698 	struct rte_port *port;
2699 	uint8_t isrx;
2700 	uint8_t ison;
2701 	uint8_t needreconfig = 0;
2702 
2703 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2704 		return;
2705 
2706 	if (port_is_started(res->port_id) != 0) {
2707 		printf("Please stop port %u first\n", res->port_id);
2708 		return;
2709 	}
2710 
2711 	port = &ports[res->port_id];
2712 
2713 	isrx = !strcmp(res->rxtxq, "rxq");
2714 
2715 	if (isrx && rx_queue_id_is_invalid(res->qid))
2716 		return;
2717 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
2718 		return;
2719 
2720 	ison = !strcmp(res->state, "on");
2721 
2722 	if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2723 		port->rx_conf[res->qid].rx_deferred_start = ison;
2724 		needreconfig = 1;
2725 	} else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2726 		port->tx_conf[res->qid].tx_deferred_start = ison;
2727 		needreconfig = 1;
2728 	}
2729 
2730 	if (needreconfig)
2731 		cmd_reconfig_device_queue(res->port_id, 0, 1);
2732 }
2733 
2734 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2735 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2736 						port, "port");
2737 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2738 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2739 						port_id, UINT16);
2740 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2741 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2742 						rxtxq, "rxq#txq");
2743 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2744 	TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2745 						qid, UINT16);
2746 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2747 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2748 						opname, "deferred_start");
2749 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2750 	TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2751 						state, "on#off");
2752 
2753 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2754 	.f = cmd_config_deferred_start_rxtx_queue_parsed,
2755 	.data = NULL,
2756 	.help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2757 	.tokens = {
2758 		(void *)&cmd_config_deferred_start_rxtx_queue_port,
2759 		(void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2760 		(void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2761 		(void *)&cmd_config_deferred_start_rxtx_queue_qid,
2762 		(void *)&cmd_config_deferred_start_rxtx_queue_opname,
2763 		(void *)&cmd_config_deferred_start_rxtx_queue_state,
2764 		NULL,
2765 	},
2766 };
2767 
2768 /* *** configure port rxq/txq setup *** */
2769 struct cmd_setup_rxtx_queue {
2770 	cmdline_fixed_string_t port;
2771 	portid_t portid;
2772 	cmdline_fixed_string_t rxtxq;
2773 	uint16_t qid;
2774 	cmdline_fixed_string_t setup;
2775 };
2776 
2777 /* Common CLI fields for queue setup */
2778 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2779 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2780 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2781 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2782 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2783 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2784 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2785 	TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2786 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2787 	TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2788 
2789 static void
2790 cmd_setup_rxtx_queue_parsed(
2791 	void *parsed_result,
2792 	__attribute__((unused)) struct cmdline *cl,
2793 	__attribute__((unused)) void *data)
2794 {
2795 	struct cmd_setup_rxtx_queue *res = parsed_result;
2796 	struct rte_port *port;
2797 	struct rte_mempool *mp;
2798 	unsigned int socket_id;
2799 	uint8_t isrx = 0;
2800 	int ret;
2801 
2802 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
2803 		return;
2804 
2805 	if (res->portid == (portid_t)RTE_PORT_ALL) {
2806 		printf("Invalid port id\n");
2807 		return;
2808 	}
2809 
2810 	if (!strcmp(res->rxtxq, "rxq"))
2811 		isrx = 1;
2812 	else if (!strcmp(res->rxtxq, "txq"))
2813 		isrx = 0;
2814 	else {
2815 		printf("Unknown parameter\n");
2816 		return;
2817 	}
2818 
2819 	if (isrx && rx_queue_id_is_invalid(res->qid)) {
2820 		printf("Invalid rx queue\n");
2821 		return;
2822 	} else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2823 		printf("Invalid tx queue\n");
2824 		return;
2825 	}
2826 
2827 	port = &ports[res->portid];
2828 	if (isrx) {
2829 		socket_id = rxring_numa[res->portid];
2830 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2831 			socket_id = port->socket_id;
2832 
2833 		mp = mbuf_pool_find(socket_id);
2834 		if (mp == NULL) {
2835 			printf("Failed to setup RX queue: "
2836 				"No mempool allocation"
2837 				" on the socket %d\n",
2838 				rxring_numa[res->portid]);
2839 			return;
2840 		}
2841 		ret = rte_eth_rx_queue_setup(res->portid,
2842 					     res->qid,
2843 					     port->nb_rx_desc[res->qid],
2844 					     socket_id,
2845 					     &port->rx_conf[res->qid],
2846 					     mp);
2847 		if (ret)
2848 			printf("Failed to setup RX queue\n");
2849 	} else {
2850 		socket_id = txring_numa[res->portid];
2851 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
2852 			socket_id = port->socket_id;
2853 
2854 		ret = rte_eth_tx_queue_setup(res->portid,
2855 					     res->qid,
2856 					     port->nb_tx_desc[res->qid],
2857 					     socket_id,
2858 					     &port->tx_conf[res->qid]);
2859 		if (ret)
2860 			printf("Failed to setup TX queue\n");
2861 	}
2862 }
2863 
2864 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2865 	.f = cmd_setup_rxtx_queue_parsed,
2866 	.data = NULL,
2867 	.help_str = "port <port_id> rxq|txq <queue_idx> setup",
2868 	.tokens = {
2869 		(void *)&cmd_setup_rxtx_queue_port,
2870 		(void *)&cmd_setup_rxtx_queue_portid,
2871 		(void *)&cmd_setup_rxtx_queue_rxtxq,
2872 		(void *)&cmd_setup_rxtx_queue_qid,
2873 		(void *)&cmd_setup_rxtx_queue_setup,
2874 		NULL,
2875 	},
2876 };
2877 
2878 
2879 /* *** Configure RSS RETA *** */
2880 struct cmd_config_rss_reta {
2881 	cmdline_fixed_string_t port;
2882 	cmdline_fixed_string_t keyword;
2883 	portid_t port_id;
2884 	cmdline_fixed_string_t name;
2885 	cmdline_fixed_string_t list_name;
2886 	cmdline_fixed_string_t list_of_items;
2887 };
2888 
2889 static int
2890 parse_reta_config(const char *str,
2891 		  struct rte_eth_rss_reta_entry64 *reta_conf,
2892 		  uint16_t nb_entries)
2893 {
2894 	int i;
2895 	unsigned size;
2896 	uint16_t hash_index, idx, shift;
2897 	uint16_t nb_queue;
2898 	char s[256];
2899 	const char *p, *p0 = str;
2900 	char *end;
2901 	enum fieldnames {
2902 		FLD_HASH_INDEX = 0,
2903 		FLD_QUEUE,
2904 		_NUM_FLD
2905 	};
2906 	unsigned long int_fld[_NUM_FLD];
2907 	char *str_fld[_NUM_FLD];
2908 
2909 	while ((p = strchr(p0,'(')) != NULL) {
2910 		++p;
2911 		if((p0 = strchr(p,')')) == NULL)
2912 			return -1;
2913 
2914 		size = p0 - p;
2915 		if(size >= sizeof(s))
2916 			return -1;
2917 
2918 		snprintf(s, sizeof(s), "%.*s", size, p);
2919 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2920 			return -1;
2921 		for (i = 0; i < _NUM_FLD; i++) {
2922 			errno = 0;
2923 			int_fld[i] = strtoul(str_fld[i], &end, 0);
2924 			if (errno != 0 || end == str_fld[i] ||
2925 					int_fld[i] > 65535)
2926 				return -1;
2927 		}
2928 
2929 		hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2930 		nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2931 
2932 		if (hash_index >= nb_entries) {
2933 			printf("Invalid RETA hash index=%d\n", hash_index);
2934 			return -1;
2935 		}
2936 
2937 		idx = hash_index / RTE_RETA_GROUP_SIZE;
2938 		shift = hash_index % RTE_RETA_GROUP_SIZE;
2939 		reta_conf[idx].mask |= (1ULL << shift);
2940 		reta_conf[idx].reta[shift] = nb_queue;
2941 	}
2942 
2943 	return 0;
2944 }
2945 
2946 static void
2947 cmd_set_rss_reta_parsed(void *parsed_result,
2948 			__attribute__((unused)) struct cmdline *cl,
2949 			__attribute__((unused)) void *data)
2950 {
2951 	int ret;
2952 	struct rte_eth_dev_info dev_info;
2953 	struct rte_eth_rss_reta_entry64 reta_conf[8];
2954 	struct cmd_config_rss_reta *res = parsed_result;
2955 
2956 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2957 	if (ret != 0)
2958 		return;
2959 
2960 	if (dev_info.reta_size == 0) {
2961 		printf("Redirection table size is 0 which is "
2962 					"invalid for RSS\n");
2963 		return;
2964 	} else
2965 		printf("The reta size of port %d is %u\n",
2966 			res->port_id, dev_info.reta_size);
2967 	if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2968 		printf("Currently do not support more than %u entries of "
2969 			"redirection table\n", ETH_RSS_RETA_SIZE_512);
2970 		return;
2971 	}
2972 
2973 	memset(reta_conf, 0, sizeof(reta_conf));
2974 	if (!strcmp(res->list_name, "reta")) {
2975 		if (parse_reta_config(res->list_of_items, reta_conf,
2976 						dev_info.reta_size)) {
2977 			printf("Invalid RSS Redirection Table "
2978 					"config entered\n");
2979 			return;
2980 		}
2981 		ret = rte_eth_dev_rss_reta_update(res->port_id,
2982 				reta_conf, dev_info.reta_size);
2983 		if (ret != 0)
2984 			printf("Bad redirection table parameter, "
2985 					"return code = %d \n", ret);
2986 	}
2987 }
2988 
2989 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2990 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2991 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2992 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2993 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2994 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2995 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2996 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2997 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2998 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2999 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3000         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3001                                  NULL);
3002 cmdline_parse_inst_t cmd_config_rss_reta = {
3003 	.f = cmd_set_rss_reta_parsed,
3004 	.data = NULL,
3005 	.help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3006 	.tokens = {
3007 		(void *)&cmd_config_rss_reta_port,
3008 		(void *)&cmd_config_rss_reta_keyword,
3009 		(void *)&cmd_config_rss_reta_port_id,
3010 		(void *)&cmd_config_rss_reta_name,
3011 		(void *)&cmd_config_rss_reta_list_name,
3012 		(void *)&cmd_config_rss_reta_list_of_items,
3013 		NULL,
3014 	},
3015 };
3016 
3017 /* *** SHOW PORT RETA INFO *** */
3018 struct cmd_showport_reta {
3019 	cmdline_fixed_string_t show;
3020 	cmdline_fixed_string_t port;
3021 	portid_t port_id;
3022 	cmdline_fixed_string_t rss;
3023 	cmdline_fixed_string_t reta;
3024 	uint16_t size;
3025 	cmdline_fixed_string_t list_of_items;
3026 };
3027 
3028 static int
3029 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3030 			   uint16_t nb_entries,
3031 			   char *str)
3032 {
3033 	uint32_t size;
3034 	const char *p, *p0 = str;
3035 	char s[256];
3036 	char *end;
3037 	char *str_fld[8];
3038 	uint16_t i;
3039 	uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3040 			RTE_RETA_GROUP_SIZE;
3041 	int ret;
3042 
3043 	p = strchr(p0, '(');
3044 	if (p == NULL)
3045 		return -1;
3046 	p++;
3047 	p0 = strchr(p, ')');
3048 	if (p0 == NULL)
3049 		return -1;
3050 	size = p0 - p;
3051 	if (size >= sizeof(s)) {
3052 		printf("The string size exceeds the internal buffer size\n");
3053 		return -1;
3054 	}
3055 	snprintf(s, sizeof(s), "%.*s", size, p);
3056 	ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3057 	if (ret <= 0 || ret != num) {
3058 		printf("The bits of masks do not match the number of "
3059 					"reta entries: %u\n", num);
3060 		return -1;
3061 	}
3062 	for (i = 0; i < ret; i++)
3063 		conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3064 
3065 	return 0;
3066 }
3067 
3068 static void
3069 cmd_showport_reta_parsed(void *parsed_result,
3070 			 __attribute__((unused)) struct cmdline *cl,
3071 			 __attribute__((unused)) void *data)
3072 {
3073 	struct cmd_showport_reta *res = parsed_result;
3074 	struct rte_eth_rss_reta_entry64 reta_conf[8];
3075 	struct rte_eth_dev_info dev_info;
3076 	uint16_t max_reta_size;
3077 	int ret;
3078 
3079 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3080 	if (ret != 0)
3081 		return;
3082 
3083 	max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3084 	if (res->size == 0 || res->size > max_reta_size) {
3085 		printf("Invalid redirection table size: %u (1-%u)\n",
3086 			res->size, max_reta_size);
3087 		return;
3088 	}
3089 
3090 	memset(reta_conf, 0, sizeof(reta_conf));
3091 	if (showport_parse_reta_config(reta_conf, res->size,
3092 				res->list_of_items) < 0) {
3093 		printf("Invalid string: %s for reta masks\n",
3094 					res->list_of_items);
3095 		return;
3096 	}
3097 	port_rss_reta_info(res->port_id, reta_conf, res->size);
3098 }
3099 
3100 cmdline_parse_token_string_t cmd_showport_reta_show =
3101 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3102 cmdline_parse_token_string_t cmd_showport_reta_port =
3103 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3104 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3105 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3106 cmdline_parse_token_string_t cmd_showport_reta_rss =
3107 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3108 cmdline_parse_token_string_t cmd_showport_reta_reta =
3109 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3110 cmdline_parse_token_num_t cmd_showport_reta_size =
3111 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3112 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3113 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3114 					list_of_items, NULL);
3115 
3116 cmdline_parse_inst_t cmd_showport_reta = {
3117 	.f = cmd_showport_reta_parsed,
3118 	.data = NULL,
3119 	.help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3120 	.tokens = {
3121 		(void *)&cmd_showport_reta_show,
3122 		(void *)&cmd_showport_reta_port,
3123 		(void *)&cmd_showport_reta_port_id,
3124 		(void *)&cmd_showport_reta_rss,
3125 		(void *)&cmd_showport_reta_reta,
3126 		(void *)&cmd_showport_reta_size,
3127 		(void *)&cmd_showport_reta_list_of_items,
3128 		NULL,
3129 	},
3130 };
3131 
3132 /* *** Show RSS hash configuration *** */
3133 struct cmd_showport_rss_hash {
3134 	cmdline_fixed_string_t show;
3135 	cmdline_fixed_string_t port;
3136 	portid_t port_id;
3137 	cmdline_fixed_string_t rss_hash;
3138 	cmdline_fixed_string_t rss_type;
3139 	cmdline_fixed_string_t key; /* optional argument */
3140 };
3141 
3142 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3143 				__attribute__((unused)) struct cmdline *cl,
3144 				void *show_rss_key)
3145 {
3146 	struct cmd_showport_rss_hash *res = parsed_result;
3147 
3148 	port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3149 }
3150 
3151 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3152 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3153 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3154 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3155 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3156 	TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3157 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3158 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3159 				 "rss-hash");
3160 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3161 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3162 
3163 cmdline_parse_inst_t cmd_showport_rss_hash = {
3164 	.f = cmd_showport_rss_hash_parsed,
3165 	.data = NULL,
3166 	.help_str = "show port <port_id> rss-hash",
3167 	.tokens = {
3168 		(void *)&cmd_showport_rss_hash_show,
3169 		(void *)&cmd_showport_rss_hash_port,
3170 		(void *)&cmd_showport_rss_hash_port_id,
3171 		(void *)&cmd_showport_rss_hash_rss_hash,
3172 		NULL,
3173 	},
3174 };
3175 
3176 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3177 	.f = cmd_showport_rss_hash_parsed,
3178 	.data = (void *)1,
3179 	.help_str = "show port <port_id> rss-hash key",
3180 	.tokens = {
3181 		(void *)&cmd_showport_rss_hash_show,
3182 		(void *)&cmd_showport_rss_hash_port,
3183 		(void *)&cmd_showport_rss_hash_port_id,
3184 		(void *)&cmd_showport_rss_hash_rss_hash,
3185 		(void *)&cmd_showport_rss_hash_rss_key,
3186 		NULL,
3187 	},
3188 };
3189 
3190 /* *** Configure DCB *** */
3191 struct cmd_config_dcb {
3192 	cmdline_fixed_string_t port;
3193 	cmdline_fixed_string_t config;
3194 	portid_t port_id;
3195 	cmdline_fixed_string_t dcb;
3196 	cmdline_fixed_string_t vt;
3197 	cmdline_fixed_string_t vt_en;
3198 	uint8_t num_tcs;
3199 	cmdline_fixed_string_t pfc;
3200 	cmdline_fixed_string_t pfc_en;
3201 };
3202 
3203 static void
3204 cmd_config_dcb_parsed(void *parsed_result,
3205                         __attribute__((unused)) struct cmdline *cl,
3206                         __attribute__((unused)) void *data)
3207 {
3208 	struct cmd_config_dcb *res = parsed_result;
3209 	portid_t port_id = res->port_id;
3210 	struct rte_port *port;
3211 	uint8_t pfc_en;
3212 	int ret;
3213 
3214 	port = &ports[port_id];
3215 	/** Check if the port is not started **/
3216 	if (port->port_status != RTE_PORT_STOPPED) {
3217 		printf("Please stop port %d first\n", port_id);
3218 		return;
3219 	}
3220 
3221 	if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3222 		printf("The invalid number of traffic class,"
3223 			" only 4 or 8 allowed.\n");
3224 		return;
3225 	}
3226 
3227 	if (nb_fwd_lcores < res->num_tcs) {
3228 		printf("nb_cores shouldn't be less than number of TCs.\n");
3229 		return;
3230 	}
3231 	if (!strncmp(res->pfc_en, "on", 2))
3232 		pfc_en = 1;
3233 	else
3234 		pfc_en = 0;
3235 
3236 	/* DCB in VT mode */
3237 	if (!strncmp(res->vt_en, "on", 2))
3238 		ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3239 				(enum rte_eth_nb_tcs)res->num_tcs,
3240 				pfc_en);
3241 	else
3242 		ret = init_port_dcb_config(port_id, DCB_ENABLED,
3243 				(enum rte_eth_nb_tcs)res->num_tcs,
3244 				pfc_en);
3245 
3246 
3247 	if (ret != 0) {
3248 		printf("Cannot initialize network ports.\n");
3249 		return;
3250 	}
3251 
3252 	cmd_reconfig_device_queue(port_id, 1, 1);
3253 }
3254 
3255 cmdline_parse_token_string_t cmd_config_dcb_port =
3256         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3257 cmdline_parse_token_string_t cmd_config_dcb_config =
3258         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3259 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3260 	TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3261 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3262         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3263 cmdline_parse_token_string_t cmd_config_dcb_vt =
3264         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3265 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3266         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3267 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3268         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3269 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3270         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3271 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3272         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3273 
3274 cmdline_parse_inst_t cmd_config_dcb = {
3275 	.f = cmd_config_dcb_parsed,
3276 	.data = NULL,
3277 	.help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3278 	.tokens = {
3279 		(void *)&cmd_config_dcb_port,
3280 		(void *)&cmd_config_dcb_config,
3281 		(void *)&cmd_config_dcb_port_id,
3282 		(void *)&cmd_config_dcb_dcb,
3283 		(void *)&cmd_config_dcb_vt,
3284 		(void *)&cmd_config_dcb_vt_en,
3285 		(void *)&cmd_config_dcb_num_tcs,
3286 		(void *)&cmd_config_dcb_pfc,
3287 		(void *)&cmd_config_dcb_pfc_en,
3288                 NULL,
3289         },
3290 };
3291 
3292 /* *** configure number of packets per burst *** */
3293 struct cmd_config_burst {
3294 	cmdline_fixed_string_t port;
3295 	cmdline_fixed_string_t keyword;
3296 	cmdline_fixed_string_t all;
3297 	cmdline_fixed_string_t name;
3298 	uint16_t value;
3299 };
3300 
3301 static void
3302 cmd_config_burst_parsed(void *parsed_result,
3303 			__attribute__((unused)) struct cmdline *cl,
3304 			__attribute__((unused)) void *data)
3305 {
3306 	struct cmd_config_burst *res = parsed_result;
3307 	struct rte_eth_dev_info dev_info;
3308 	uint16_t rec_nb_pkts;
3309 	int ret;
3310 
3311 	if (!all_ports_stopped()) {
3312 		printf("Please stop all ports first\n");
3313 		return;
3314 	}
3315 
3316 	if (!strcmp(res->name, "burst")) {
3317 		if (res->value == 0) {
3318 			/* If user gives a value of zero, query the PMD for
3319 			 * its recommended Rx burst size. Testpmd uses a single
3320 			 * size for all ports, so assume all ports are the same
3321 			 * NIC model and use the values from Port 0.
3322 			 */
3323 			ret = eth_dev_info_get_print_err(0, &dev_info);
3324 			if (ret != 0)
3325 				return;
3326 
3327 			rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3328 
3329 			if (rec_nb_pkts == 0) {
3330 				printf("PMD does not recommend a burst size.\n"
3331 					"User provided value must be between"
3332 					" 1 and %d\n", MAX_PKT_BURST);
3333 				return;
3334 			} else if (rec_nb_pkts > MAX_PKT_BURST) {
3335 				printf("PMD recommended burst size of %d"
3336 					" exceeds maximum value of %d\n",
3337 					rec_nb_pkts, MAX_PKT_BURST);
3338 				return;
3339 			}
3340 			printf("Using PMD-provided burst value of %d\n",
3341 				rec_nb_pkts);
3342 			nb_pkt_per_burst = rec_nb_pkts;
3343 		} else if (res->value > MAX_PKT_BURST) {
3344 			printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3345 			return;
3346 		} else
3347 			nb_pkt_per_burst = res->value;
3348 	} else {
3349 		printf("Unknown parameter\n");
3350 		return;
3351 	}
3352 
3353 	init_port_config();
3354 
3355 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3356 }
3357 
3358 cmdline_parse_token_string_t cmd_config_burst_port =
3359 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3360 cmdline_parse_token_string_t cmd_config_burst_keyword =
3361 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3362 cmdline_parse_token_string_t cmd_config_burst_all =
3363 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3364 cmdline_parse_token_string_t cmd_config_burst_name =
3365 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3366 cmdline_parse_token_num_t cmd_config_burst_value =
3367 	TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3368 
3369 cmdline_parse_inst_t cmd_config_burst = {
3370 	.f = cmd_config_burst_parsed,
3371 	.data = NULL,
3372 	.help_str = "port config all burst <value>",
3373 	.tokens = {
3374 		(void *)&cmd_config_burst_port,
3375 		(void *)&cmd_config_burst_keyword,
3376 		(void *)&cmd_config_burst_all,
3377 		(void *)&cmd_config_burst_name,
3378 		(void *)&cmd_config_burst_value,
3379 		NULL,
3380 	},
3381 };
3382 
3383 /* *** configure rx/tx queues *** */
3384 struct cmd_config_thresh {
3385 	cmdline_fixed_string_t port;
3386 	cmdline_fixed_string_t keyword;
3387 	cmdline_fixed_string_t all;
3388 	cmdline_fixed_string_t name;
3389 	uint8_t value;
3390 };
3391 
3392 static void
3393 cmd_config_thresh_parsed(void *parsed_result,
3394 			__attribute__((unused)) struct cmdline *cl,
3395 			__attribute__((unused)) void *data)
3396 {
3397 	struct cmd_config_thresh *res = parsed_result;
3398 
3399 	if (!all_ports_stopped()) {
3400 		printf("Please stop all ports first\n");
3401 		return;
3402 	}
3403 
3404 	if (!strcmp(res->name, "txpt"))
3405 		tx_pthresh = res->value;
3406 	else if(!strcmp(res->name, "txht"))
3407 		tx_hthresh = res->value;
3408 	else if(!strcmp(res->name, "txwt"))
3409 		tx_wthresh = res->value;
3410 	else if(!strcmp(res->name, "rxpt"))
3411 		rx_pthresh = res->value;
3412 	else if(!strcmp(res->name, "rxht"))
3413 		rx_hthresh = res->value;
3414 	else if(!strcmp(res->name, "rxwt"))
3415 		rx_wthresh = res->value;
3416 	else {
3417 		printf("Unknown parameter\n");
3418 		return;
3419 	}
3420 
3421 	init_port_config();
3422 
3423 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3424 }
3425 
3426 cmdline_parse_token_string_t cmd_config_thresh_port =
3427 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3428 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3429 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3430 cmdline_parse_token_string_t cmd_config_thresh_all =
3431 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3432 cmdline_parse_token_string_t cmd_config_thresh_name =
3433 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3434 				"txpt#txht#txwt#rxpt#rxht#rxwt");
3435 cmdline_parse_token_num_t cmd_config_thresh_value =
3436 	TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3437 
3438 cmdline_parse_inst_t cmd_config_thresh = {
3439 	.f = cmd_config_thresh_parsed,
3440 	.data = NULL,
3441 	.help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3442 	.tokens = {
3443 		(void *)&cmd_config_thresh_port,
3444 		(void *)&cmd_config_thresh_keyword,
3445 		(void *)&cmd_config_thresh_all,
3446 		(void *)&cmd_config_thresh_name,
3447 		(void *)&cmd_config_thresh_value,
3448 		NULL,
3449 	},
3450 };
3451 
3452 /* *** configure free/rs threshold *** */
3453 struct cmd_config_threshold {
3454 	cmdline_fixed_string_t port;
3455 	cmdline_fixed_string_t keyword;
3456 	cmdline_fixed_string_t all;
3457 	cmdline_fixed_string_t name;
3458 	uint16_t value;
3459 };
3460 
3461 static void
3462 cmd_config_threshold_parsed(void *parsed_result,
3463 			__attribute__((unused)) struct cmdline *cl,
3464 			__attribute__((unused)) void *data)
3465 {
3466 	struct cmd_config_threshold *res = parsed_result;
3467 
3468 	if (!all_ports_stopped()) {
3469 		printf("Please stop all ports first\n");
3470 		return;
3471 	}
3472 
3473 	if (!strcmp(res->name, "txfreet"))
3474 		tx_free_thresh = res->value;
3475 	else if (!strcmp(res->name, "txrst"))
3476 		tx_rs_thresh = res->value;
3477 	else if (!strcmp(res->name, "rxfreet"))
3478 		rx_free_thresh = res->value;
3479 	else {
3480 		printf("Unknown parameter\n");
3481 		return;
3482 	}
3483 
3484 	init_port_config();
3485 
3486 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3487 }
3488 
3489 cmdline_parse_token_string_t cmd_config_threshold_port =
3490 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3491 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3492 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3493 								"config");
3494 cmdline_parse_token_string_t cmd_config_threshold_all =
3495 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3496 cmdline_parse_token_string_t cmd_config_threshold_name =
3497 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3498 						"txfreet#txrst#rxfreet");
3499 cmdline_parse_token_num_t cmd_config_threshold_value =
3500 	TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3501 
3502 cmdline_parse_inst_t cmd_config_threshold = {
3503 	.f = cmd_config_threshold_parsed,
3504 	.data = NULL,
3505 	.help_str = "port config all txfreet|txrst|rxfreet <value>",
3506 	.tokens = {
3507 		(void *)&cmd_config_threshold_port,
3508 		(void *)&cmd_config_threshold_keyword,
3509 		(void *)&cmd_config_threshold_all,
3510 		(void *)&cmd_config_threshold_name,
3511 		(void *)&cmd_config_threshold_value,
3512 		NULL,
3513 	},
3514 };
3515 
3516 /* *** stop *** */
3517 struct cmd_stop_result {
3518 	cmdline_fixed_string_t stop;
3519 };
3520 
3521 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3522 			    __attribute__((unused)) struct cmdline *cl,
3523 			    __attribute__((unused)) void *data)
3524 {
3525 	stop_packet_forwarding();
3526 }
3527 
3528 cmdline_parse_token_string_t cmd_stop_stop =
3529 	TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3530 
3531 cmdline_parse_inst_t cmd_stop = {
3532 	.f = cmd_stop_parsed,
3533 	.data = NULL,
3534 	.help_str = "stop: Stop packet forwarding",
3535 	.tokens = {
3536 		(void *)&cmd_stop_stop,
3537 		NULL,
3538 	},
3539 };
3540 
3541 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3542 
3543 unsigned int
3544 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3545 		unsigned int *parsed_items, int check_unique_values)
3546 {
3547 	unsigned int nb_item;
3548 	unsigned int value;
3549 	unsigned int i;
3550 	unsigned int j;
3551 	int value_ok;
3552 	char c;
3553 
3554 	/*
3555 	 * First parse all items in the list and store their value.
3556 	 */
3557 	value = 0;
3558 	nb_item = 0;
3559 	value_ok = 0;
3560 	for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3561 		c = str[i];
3562 		if ((c >= '0') && (c <= '9')) {
3563 			value = (unsigned int) (value * 10 + (c - '0'));
3564 			value_ok = 1;
3565 			continue;
3566 		}
3567 		if (c != ',') {
3568 			printf("character %c is not a decimal digit\n", c);
3569 			return 0;
3570 		}
3571 		if (! value_ok) {
3572 			printf("No valid value before comma\n");
3573 			return 0;
3574 		}
3575 		if (nb_item < max_items) {
3576 			parsed_items[nb_item] = value;
3577 			value_ok = 0;
3578 			value = 0;
3579 		}
3580 		nb_item++;
3581 	}
3582 	if (nb_item >= max_items) {
3583 		printf("Number of %s = %u > %u (maximum items)\n",
3584 		       item_name, nb_item + 1, max_items);
3585 		return 0;
3586 	}
3587 	parsed_items[nb_item++] = value;
3588 	if (! check_unique_values)
3589 		return nb_item;
3590 
3591 	/*
3592 	 * Then, check that all values in the list are differents.
3593 	 * No optimization here...
3594 	 */
3595 	for (i = 0; i < nb_item; i++) {
3596 		for (j = i + 1; j < nb_item; j++) {
3597 			if (parsed_items[j] == parsed_items[i]) {
3598 				printf("duplicated %s %u at index %u and %u\n",
3599 				       item_name, parsed_items[i], i, j);
3600 				return 0;
3601 			}
3602 		}
3603 	}
3604 	return nb_item;
3605 }
3606 
3607 struct cmd_set_list_result {
3608 	cmdline_fixed_string_t cmd_keyword;
3609 	cmdline_fixed_string_t list_name;
3610 	cmdline_fixed_string_t list_of_items;
3611 };
3612 
3613 static void cmd_set_list_parsed(void *parsed_result,
3614 				__attribute__((unused)) struct cmdline *cl,
3615 				__attribute__((unused)) void *data)
3616 {
3617 	struct cmd_set_list_result *res;
3618 	union {
3619 		unsigned int lcorelist[RTE_MAX_LCORE];
3620 		unsigned int portlist[RTE_MAX_ETHPORTS];
3621 	} parsed_items;
3622 	unsigned int nb_item;
3623 
3624 	if (test_done == 0) {
3625 		printf("Please stop forwarding first\n");
3626 		return;
3627 	}
3628 
3629 	res = parsed_result;
3630 	if (!strcmp(res->list_name, "corelist")) {
3631 		nb_item = parse_item_list(res->list_of_items, "core",
3632 					  RTE_MAX_LCORE,
3633 					  parsed_items.lcorelist, 1);
3634 		if (nb_item > 0) {
3635 			set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3636 			fwd_config_setup();
3637 		}
3638 		return;
3639 	}
3640 	if (!strcmp(res->list_name, "portlist")) {
3641 		nb_item = parse_item_list(res->list_of_items, "port",
3642 					  RTE_MAX_ETHPORTS,
3643 					  parsed_items.portlist, 1);
3644 		if (nb_item > 0) {
3645 			set_fwd_ports_list(parsed_items.portlist, nb_item);
3646 			fwd_config_setup();
3647 		}
3648 	}
3649 }
3650 
3651 cmdline_parse_token_string_t cmd_set_list_keyword =
3652 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3653 				 "set");
3654 cmdline_parse_token_string_t cmd_set_list_name =
3655 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3656 				 "corelist#portlist");
3657 cmdline_parse_token_string_t cmd_set_list_of_items =
3658 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3659 				 NULL);
3660 
3661 cmdline_parse_inst_t cmd_set_fwd_list = {
3662 	.f = cmd_set_list_parsed,
3663 	.data = NULL,
3664 	.help_str = "set corelist|portlist <list0[,list1]*>",
3665 	.tokens = {
3666 		(void *)&cmd_set_list_keyword,
3667 		(void *)&cmd_set_list_name,
3668 		(void *)&cmd_set_list_of_items,
3669 		NULL,
3670 	},
3671 };
3672 
3673 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3674 
3675 struct cmd_setmask_result {
3676 	cmdline_fixed_string_t set;
3677 	cmdline_fixed_string_t mask;
3678 	uint64_t hexavalue;
3679 };
3680 
3681 static void cmd_set_mask_parsed(void *parsed_result,
3682 				__attribute__((unused)) struct cmdline *cl,
3683 				__attribute__((unused)) void *data)
3684 {
3685 	struct cmd_setmask_result *res = parsed_result;
3686 
3687 	if (test_done == 0) {
3688 		printf("Please stop forwarding first\n");
3689 		return;
3690 	}
3691 	if (!strcmp(res->mask, "coremask")) {
3692 		set_fwd_lcores_mask(res->hexavalue);
3693 		fwd_config_setup();
3694 	} else if (!strcmp(res->mask, "portmask")) {
3695 		set_fwd_ports_mask(res->hexavalue);
3696 		fwd_config_setup();
3697 	}
3698 }
3699 
3700 cmdline_parse_token_string_t cmd_setmask_set =
3701 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3702 cmdline_parse_token_string_t cmd_setmask_mask =
3703 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3704 				 "coremask#portmask");
3705 cmdline_parse_token_num_t cmd_setmask_value =
3706 	TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3707 
3708 cmdline_parse_inst_t cmd_set_fwd_mask = {
3709 	.f = cmd_set_mask_parsed,
3710 	.data = NULL,
3711 	.help_str = "set coremask|portmask <hexadecimal value>",
3712 	.tokens = {
3713 		(void *)&cmd_setmask_set,
3714 		(void *)&cmd_setmask_mask,
3715 		(void *)&cmd_setmask_value,
3716 		NULL,
3717 	},
3718 };
3719 
3720 /*
3721  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3722  */
3723 struct cmd_set_result {
3724 	cmdline_fixed_string_t set;
3725 	cmdline_fixed_string_t what;
3726 	uint16_t value;
3727 };
3728 
3729 static void cmd_set_parsed(void *parsed_result,
3730 			   __attribute__((unused)) struct cmdline *cl,
3731 			   __attribute__((unused)) void *data)
3732 {
3733 	struct cmd_set_result *res = parsed_result;
3734 	if (!strcmp(res->what, "nbport")) {
3735 		set_fwd_ports_number(res->value);
3736 		fwd_config_setup();
3737 	} else if (!strcmp(res->what, "nbcore")) {
3738 		set_fwd_lcores_number(res->value);
3739 		fwd_config_setup();
3740 	} else if (!strcmp(res->what, "burst"))
3741 		set_nb_pkt_per_burst(res->value);
3742 	else if (!strcmp(res->what, "verbose"))
3743 		set_verbose_level(res->value);
3744 }
3745 
3746 cmdline_parse_token_string_t cmd_set_set =
3747 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3748 cmdline_parse_token_string_t cmd_set_what =
3749 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3750 				 "nbport#nbcore#burst#verbose");
3751 cmdline_parse_token_num_t cmd_set_value =
3752 	TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3753 
3754 cmdline_parse_inst_t cmd_set_numbers = {
3755 	.f = cmd_set_parsed,
3756 	.data = NULL,
3757 	.help_str = "set nbport|nbcore|burst|verbose <value>",
3758 	.tokens = {
3759 		(void *)&cmd_set_set,
3760 		(void *)&cmd_set_what,
3761 		(void *)&cmd_set_value,
3762 		NULL,
3763 	},
3764 };
3765 
3766 /* *** SET LOG LEVEL CONFIGURATION *** */
3767 
3768 struct cmd_set_log_result {
3769 	cmdline_fixed_string_t set;
3770 	cmdline_fixed_string_t log;
3771 	cmdline_fixed_string_t type;
3772 	uint32_t level;
3773 };
3774 
3775 static void
3776 cmd_set_log_parsed(void *parsed_result,
3777 		   __attribute__((unused)) struct cmdline *cl,
3778 		   __attribute__((unused)) void *data)
3779 {
3780 	struct cmd_set_log_result *res;
3781 	int ret;
3782 
3783 	res = parsed_result;
3784 	if (!strcmp(res->type, "global"))
3785 		rte_log_set_global_level(res->level);
3786 	else {
3787 		ret = rte_log_set_level_regexp(res->type, res->level);
3788 		if (ret < 0)
3789 			printf("Unable to set log level\n");
3790 	}
3791 }
3792 
3793 cmdline_parse_token_string_t cmd_set_log_set =
3794 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3795 cmdline_parse_token_string_t cmd_set_log_log =
3796 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3797 cmdline_parse_token_string_t cmd_set_log_type =
3798 	TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3799 cmdline_parse_token_num_t cmd_set_log_level =
3800 	TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3801 
3802 cmdline_parse_inst_t cmd_set_log = {
3803 	.f = cmd_set_log_parsed,
3804 	.data = NULL,
3805 	.help_str = "set log global|<type> <level>",
3806 	.tokens = {
3807 		(void *)&cmd_set_log_set,
3808 		(void *)&cmd_set_log_log,
3809 		(void *)&cmd_set_log_type,
3810 		(void *)&cmd_set_log_level,
3811 		NULL,
3812 	},
3813 };
3814 
3815 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3816 
3817 struct cmd_set_txpkts_result {
3818 	cmdline_fixed_string_t cmd_keyword;
3819 	cmdline_fixed_string_t txpkts;
3820 	cmdline_fixed_string_t seg_lengths;
3821 };
3822 
3823 static void
3824 cmd_set_txpkts_parsed(void *parsed_result,
3825 		      __attribute__((unused)) struct cmdline *cl,
3826 		      __attribute__((unused)) void *data)
3827 {
3828 	struct cmd_set_txpkts_result *res;
3829 	unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3830 	unsigned int nb_segs;
3831 
3832 	res = parsed_result;
3833 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3834 				  RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3835 	if (nb_segs > 0)
3836 		set_tx_pkt_segments(seg_lengths, nb_segs);
3837 }
3838 
3839 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3840 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3841 				 cmd_keyword, "set");
3842 cmdline_parse_token_string_t cmd_set_txpkts_name =
3843 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3844 				 txpkts, "txpkts");
3845 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3846 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3847 				 seg_lengths, NULL);
3848 
3849 cmdline_parse_inst_t cmd_set_txpkts = {
3850 	.f = cmd_set_txpkts_parsed,
3851 	.data = NULL,
3852 	.help_str = "set txpkts <len0[,len1]*>",
3853 	.tokens = {
3854 		(void *)&cmd_set_txpkts_keyword,
3855 		(void *)&cmd_set_txpkts_name,
3856 		(void *)&cmd_set_txpkts_lengths,
3857 		NULL,
3858 	},
3859 };
3860 
3861 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3862 
3863 struct cmd_set_txsplit_result {
3864 	cmdline_fixed_string_t cmd_keyword;
3865 	cmdline_fixed_string_t txsplit;
3866 	cmdline_fixed_string_t mode;
3867 };
3868 
3869 static void
3870 cmd_set_txsplit_parsed(void *parsed_result,
3871 		      __attribute__((unused)) struct cmdline *cl,
3872 		      __attribute__((unused)) void *data)
3873 {
3874 	struct cmd_set_txsplit_result *res;
3875 
3876 	res = parsed_result;
3877 	set_tx_pkt_split(res->mode);
3878 }
3879 
3880 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3881 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3882 				 cmd_keyword, "set");
3883 cmdline_parse_token_string_t cmd_set_txsplit_name =
3884 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3885 				 txsplit, "txsplit");
3886 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3887 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3888 				 mode, NULL);
3889 
3890 cmdline_parse_inst_t cmd_set_txsplit = {
3891 	.f = cmd_set_txsplit_parsed,
3892 	.data = NULL,
3893 	.help_str = "set txsplit on|off|rand",
3894 	.tokens = {
3895 		(void *)&cmd_set_txsplit_keyword,
3896 		(void *)&cmd_set_txsplit_name,
3897 		(void *)&cmd_set_txsplit_mode,
3898 		NULL,
3899 	},
3900 };
3901 
3902 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3903 struct cmd_rx_vlan_filter_all_result {
3904 	cmdline_fixed_string_t rx_vlan;
3905 	cmdline_fixed_string_t what;
3906 	cmdline_fixed_string_t all;
3907 	portid_t port_id;
3908 };
3909 
3910 static void
3911 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3912 			      __attribute__((unused)) struct cmdline *cl,
3913 			      __attribute__((unused)) void *data)
3914 {
3915 	struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3916 
3917 	if (!strcmp(res->what, "add"))
3918 		rx_vlan_all_filter_set(res->port_id, 1);
3919 	else
3920 		rx_vlan_all_filter_set(res->port_id, 0);
3921 }
3922 
3923 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3924 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3925 				 rx_vlan, "rx_vlan");
3926 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3927 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3928 				 what, "add#rm");
3929 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3930 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3931 				 all, "all");
3932 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3933 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3934 			      port_id, UINT16);
3935 
3936 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3937 	.f = cmd_rx_vlan_filter_all_parsed,
3938 	.data = NULL,
3939 	.help_str = "rx_vlan add|rm all <port_id>: "
3940 		"Add/Remove all identifiers to/from the set of VLAN "
3941 		"identifiers filtered by a port",
3942 	.tokens = {
3943 		(void *)&cmd_rx_vlan_filter_all_rx_vlan,
3944 		(void *)&cmd_rx_vlan_filter_all_what,
3945 		(void *)&cmd_rx_vlan_filter_all_all,
3946 		(void *)&cmd_rx_vlan_filter_all_portid,
3947 		NULL,
3948 	},
3949 };
3950 
3951 /* *** VLAN OFFLOAD SET ON A PORT *** */
3952 struct cmd_vlan_offload_result {
3953 	cmdline_fixed_string_t vlan;
3954 	cmdline_fixed_string_t set;
3955 	cmdline_fixed_string_t vlan_type;
3956 	cmdline_fixed_string_t what;
3957 	cmdline_fixed_string_t on;
3958 	cmdline_fixed_string_t port_id;
3959 };
3960 
3961 static void
3962 cmd_vlan_offload_parsed(void *parsed_result,
3963 			  __attribute__((unused)) struct cmdline *cl,
3964 			  __attribute__((unused)) void *data)
3965 {
3966 	int on;
3967 	struct cmd_vlan_offload_result *res = parsed_result;
3968 	char *str;
3969 	int i, len = 0;
3970 	portid_t port_id = 0;
3971 	unsigned int tmp;
3972 
3973 	str = res->port_id;
3974 	len = strnlen(str, STR_TOKEN_SIZE);
3975 	i = 0;
3976 	/* Get port_id first */
3977 	while(i < len){
3978 		if(str[i] == ',')
3979 			break;
3980 
3981 		i++;
3982 	}
3983 	str[i]='\0';
3984 	tmp = strtoul(str, NULL, 0);
3985 	/* If port_id greater that what portid_t can represent, return */
3986 	if(tmp >= RTE_MAX_ETHPORTS)
3987 		return;
3988 	port_id = (portid_t)tmp;
3989 
3990 	if (!strcmp(res->on, "on"))
3991 		on = 1;
3992 	else
3993 		on = 0;
3994 
3995 	if (!strcmp(res->what, "strip"))
3996 		rx_vlan_strip_set(port_id,  on);
3997 	else if(!strcmp(res->what, "stripq")){
3998 		uint16_t queue_id = 0;
3999 
4000 		/* No queue_id, return */
4001 		if(i + 1 >= len) {
4002 			printf("must specify (port,queue_id)\n");
4003 			return;
4004 		}
4005 		tmp = strtoul(str + i + 1, NULL, 0);
4006 		/* If queue_id greater that what 16-bits can represent, return */
4007 		if(tmp > 0xffff)
4008 			return;
4009 
4010 		queue_id = (uint16_t)tmp;
4011 		rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4012 	}
4013 	else if (!strcmp(res->what, "filter"))
4014 		rx_vlan_filter_set(port_id, on);
4015 	else if (!strcmp(res->what, "qinq_strip"))
4016 		rx_vlan_qinq_strip_set(port_id, on);
4017 	else
4018 		vlan_extend_set(port_id, on);
4019 
4020 	return;
4021 }
4022 
4023 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4024 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4025 				 vlan, "vlan");
4026 cmdline_parse_token_string_t cmd_vlan_offload_set =
4027 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4028 				 set, "set");
4029 cmdline_parse_token_string_t cmd_vlan_offload_what =
4030 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4031 				what, "strip#filter#qinq_strip#extend#stripq");
4032 cmdline_parse_token_string_t cmd_vlan_offload_on =
4033 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4034 			      on, "on#off");
4035 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4036 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4037 			      port_id, NULL);
4038 
4039 cmdline_parse_inst_t cmd_vlan_offload = {
4040 	.f = cmd_vlan_offload_parsed,
4041 	.data = NULL,
4042 	.help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4043 		"<port_id[,queue_id]>: "
4044 		"Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4045 	.tokens = {
4046 		(void *)&cmd_vlan_offload_vlan,
4047 		(void *)&cmd_vlan_offload_set,
4048 		(void *)&cmd_vlan_offload_what,
4049 		(void *)&cmd_vlan_offload_on,
4050 		(void *)&cmd_vlan_offload_portid,
4051 		NULL,
4052 	},
4053 };
4054 
4055 /* *** VLAN TPID SET ON A PORT *** */
4056 struct cmd_vlan_tpid_result {
4057 	cmdline_fixed_string_t vlan;
4058 	cmdline_fixed_string_t set;
4059 	cmdline_fixed_string_t vlan_type;
4060 	cmdline_fixed_string_t what;
4061 	uint16_t tp_id;
4062 	portid_t port_id;
4063 };
4064 
4065 static void
4066 cmd_vlan_tpid_parsed(void *parsed_result,
4067 			  __attribute__((unused)) struct cmdline *cl,
4068 			  __attribute__((unused)) void *data)
4069 {
4070 	struct cmd_vlan_tpid_result *res = parsed_result;
4071 	enum rte_vlan_type vlan_type;
4072 
4073 	if (!strcmp(res->vlan_type, "inner"))
4074 		vlan_type = ETH_VLAN_TYPE_INNER;
4075 	else if (!strcmp(res->vlan_type, "outer"))
4076 		vlan_type = ETH_VLAN_TYPE_OUTER;
4077 	else {
4078 		printf("Unknown vlan type\n");
4079 		return;
4080 	}
4081 	vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4082 }
4083 
4084 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4085 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4086 				 vlan, "vlan");
4087 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4088 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4089 				 set, "set");
4090 cmdline_parse_token_string_t cmd_vlan_type =
4091 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4092 				 vlan_type, "inner#outer");
4093 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4094 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4095 				 what, "tpid");
4096 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4097 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4098 			      tp_id, UINT16);
4099 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4100 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4101 			      port_id, UINT16);
4102 
4103 cmdline_parse_inst_t cmd_vlan_tpid = {
4104 	.f = cmd_vlan_tpid_parsed,
4105 	.data = NULL,
4106 	.help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4107 		"Set the VLAN Ether type",
4108 	.tokens = {
4109 		(void *)&cmd_vlan_tpid_vlan,
4110 		(void *)&cmd_vlan_tpid_set,
4111 		(void *)&cmd_vlan_type,
4112 		(void *)&cmd_vlan_tpid_what,
4113 		(void *)&cmd_vlan_tpid_tpid,
4114 		(void *)&cmd_vlan_tpid_portid,
4115 		NULL,
4116 	},
4117 };
4118 
4119 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4120 struct cmd_rx_vlan_filter_result {
4121 	cmdline_fixed_string_t rx_vlan;
4122 	cmdline_fixed_string_t what;
4123 	uint16_t vlan_id;
4124 	portid_t port_id;
4125 };
4126 
4127 static void
4128 cmd_rx_vlan_filter_parsed(void *parsed_result,
4129 			  __attribute__((unused)) struct cmdline *cl,
4130 			  __attribute__((unused)) void *data)
4131 {
4132 	struct cmd_rx_vlan_filter_result *res = parsed_result;
4133 
4134 	if (!strcmp(res->what, "add"))
4135 		rx_vft_set(res->port_id, res->vlan_id, 1);
4136 	else
4137 		rx_vft_set(res->port_id, res->vlan_id, 0);
4138 }
4139 
4140 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4141 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4142 				 rx_vlan, "rx_vlan");
4143 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4144 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4145 				 what, "add#rm");
4146 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4147 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4148 			      vlan_id, UINT16);
4149 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4150 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4151 			      port_id, UINT16);
4152 
4153 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4154 	.f = cmd_rx_vlan_filter_parsed,
4155 	.data = NULL,
4156 	.help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4157 		"Add/Remove a VLAN identifier to/from the set of VLAN "
4158 		"identifiers filtered by a port",
4159 	.tokens = {
4160 		(void *)&cmd_rx_vlan_filter_rx_vlan,
4161 		(void *)&cmd_rx_vlan_filter_what,
4162 		(void *)&cmd_rx_vlan_filter_vlanid,
4163 		(void *)&cmd_rx_vlan_filter_portid,
4164 		NULL,
4165 	},
4166 };
4167 
4168 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4169 struct cmd_tx_vlan_set_result {
4170 	cmdline_fixed_string_t tx_vlan;
4171 	cmdline_fixed_string_t set;
4172 	portid_t port_id;
4173 	uint16_t vlan_id;
4174 };
4175 
4176 static void
4177 cmd_tx_vlan_set_parsed(void *parsed_result,
4178 		       __attribute__((unused)) struct cmdline *cl,
4179 		       __attribute__((unused)) void *data)
4180 {
4181 	struct cmd_tx_vlan_set_result *res = parsed_result;
4182 
4183 	if (!port_is_stopped(res->port_id)) {
4184 		printf("Please stop port %d first\n", res->port_id);
4185 		return;
4186 	}
4187 
4188 	tx_vlan_set(res->port_id, res->vlan_id);
4189 
4190 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4191 }
4192 
4193 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4194 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4195 				 tx_vlan, "tx_vlan");
4196 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4197 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4198 				 set, "set");
4199 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4200 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4201 			      port_id, UINT16);
4202 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4203 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4204 			      vlan_id, UINT16);
4205 
4206 cmdline_parse_inst_t cmd_tx_vlan_set = {
4207 	.f = cmd_tx_vlan_set_parsed,
4208 	.data = NULL,
4209 	.help_str = "tx_vlan set <port_id> <vlan_id>: "
4210 		"Enable hardware insertion of a single VLAN header "
4211 		"with a given TAG Identifier in packets sent on a port",
4212 	.tokens = {
4213 		(void *)&cmd_tx_vlan_set_tx_vlan,
4214 		(void *)&cmd_tx_vlan_set_set,
4215 		(void *)&cmd_tx_vlan_set_portid,
4216 		(void *)&cmd_tx_vlan_set_vlanid,
4217 		NULL,
4218 	},
4219 };
4220 
4221 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4222 struct cmd_tx_vlan_set_qinq_result {
4223 	cmdline_fixed_string_t tx_vlan;
4224 	cmdline_fixed_string_t set;
4225 	portid_t port_id;
4226 	uint16_t vlan_id;
4227 	uint16_t vlan_id_outer;
4228 };
4229 
4230 static void
4231 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4232 			    __attribute__((unused)) struct cmdline *cl,
4233 			    __attribute__((unused)) void *data)
4234 {
4235 	struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4236 
4237 	if (!port_is_stopped(res->port_id)) {
4238 		printf("Please stop port %d first\n", res->port_id);
4239 		return;
4240 	}
4241 
4242 	tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4243 
4244 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4245 }
4246 
4247 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4248 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4249 		tx_vlan, "tx_vlan");
4250 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4251 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4252 		set, "set");
4253 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4254 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4255 		port_id, UINT16);
4256 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4257 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4258 		vlan_id, UINT16);
4259 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4260 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4261 		vlan_id_outer, UINT16);
4262 
4263 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4264 	.f = cmd_tx_vlan_set_qinq_parsed,
4265 	.data = NULL,
4266 	.help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4267 		"Enable hardware insertion of double VLAN header "
4268 		"with given TAG Identifiers in packets sent on a port",
4269 	.tokens = {
4270 		(void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4271 		(void *)&cmd_tx_vlan_set_qinq_set,
4272 		(void *)&cmd_tx_vlan_set_qinq_portid,
4273 		(void *)&cmd_tx_vlan_set_qinq_vlanid,
4274 		(void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4275 		NULL,
4276 	},
4277 };
4278 
4279 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4280 struct cmd_tx_vlan_set_pvid_result {
4281 	cmdline_fixed_string_t tx_vlan;
4282 	cmdline_fixed_string_t set;
4283 	cmdline_fixed_string_t pvid;
4284 	portid_t port_id;
4285 	uint16_t vlan_id;
4286 	cmdline_fixed_string_t mode;
4287 };
4288 
4289 static void
4290 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4291 			    __attribute__((unused)) struct cmdline *cl,
4292 			    __attribute__((unused)) void *data)
4293 {
4294 	struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4295 
4296 	if (strcmp(res->mode, "on") == 0)
4297 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4298 	else
4299 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4300 }
4301 
4302 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4303 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4304 				 tx_vlan, "tx_vlan");
4305 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4306 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4307 				 set, "set");
4308 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4309 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4310 				 pvid, "pvid");
4311 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4312 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4313 			     port_id, UINT16);
4314 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4315 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4316 			      vlan_id, UINT16);
4317 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4318 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4319 				 mode, "on#off");
4320 
4321 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4322 	.f = cmd_tx_vlan_set_pvid_parsed,
4323 	.data = NULL,
4324 	.help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4325 	.tokens = {
4326 		(void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4327 		(void *)&cmd_tx_vlan_set_pvid_set,
4328 		(void *)&cmd_tx_vlan_set_pvid_pvid,
4329 		(void *)&cmd_tx_vlan_set_pvid_port_id,
4330 		(void *)&cmd_tx_vlan_set_pvid_vlan_id,
4331 		(void *)&cmd_tx_vlan_set_pvid_mode,
4332 		NULL,
4333 	},
4334 };
4335 
4336 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4337 struct cmd_tx_vlan_reset_result {
4338 	cmdline_fixed_string_t tx_vlan;
4339 	cmdline_fixed_string_t reset;
4340 	portid_t port_id;
4341 };
4342 
4343 static void
4344 cmd_tx_vlan_reset_parsed(void *parsed_result,
4345 			 __attribute__((unused)) struct cmdline *cl,
4346 			 __attribute__((unused)) void *data)
4347 {
4348 	struct cmd_tx_vlan_reset_result *res = parsed_result;
4349 
4350 	if (!port_is_stopped(res->port_id)) {
4351 		printf("Please stop port %d first\n", res->port_id);
4352 		return;
4353 	}
4354 
4355 	tx_vlan_reset(res->port_id);
4356 
4357 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4358 }
4359 
4360 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4361 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4362 				 tx_vlan, "tx_vlan");
4363 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4364 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4365 				 reset, "reset");
4366 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4367 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4368 			      port_id, UINT16);
4369 
4370 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4371 	.f = cmd_tx_vlan_reset_parsed,
4372 	.data = NULL,
4373 	.help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4374 		"VLAN header in packets sent on a port",
4375 	.tokens = {
4376 		(void *)&cmd_tx_vlan_reset_tx_vlan,
4377 		(void *)&cmd_tx_vlan_reset_reset,
4378 		(void *)&cmd_tx_vlan_reset_portid,
4379 		NULL,
4380 	},
4381 };
4382 
4383 
4384 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4385 struct cmd_csum_result {
4386 	cmdline_fixed_string_t csum;
4387 	cmdline_fixed_string_t mode;
4388 	cmdline_fixed_string_t proto;
4389 	cmdline_fixed_string_t hwsw;
4390 	portid_t port_id;
4391 };
4392 
4393 static void
4394 csum_show(int port_id)
4395 {
4396 	struct rte_eth_dev_info dev_info;
4397 	uint64_t tx_offloads;
4398 	int ret;
4399 
4400 	tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4401 	printf("Parse tunnel is %s\n",
4402 		(ports[port_id].parse_tunnel) ? "on" : "off");
4403 	printf("IP checksum offload is %s\n",
4404 		(tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4405 	printf("UDP checksum offload is %s\n",
4406 		(tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4407 	printf("TCP checksum offload is %s\n",
4408 		(tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4409 	printf("SCTP checksum offload is %s\n",
4410 		(tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4411 	printf("Outer-Ip checksum offload is %s\n",
4412 		(tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4413 	printf("Outer-Udp checksum offload is %s\n",
4414 		(tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4415 
4416 	/* display warnings if configuration is not supported by the NIC */
4417 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
4418 	if (ret != 0)
4419 		return;
4420 
4421 	if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4422 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4423 		printf("Warning: hardware IP checksum enabled but not "
4424 			"supported by port %d\n", port_id);
4425 	}
4426 	if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4427 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4428 		printf("Warning: hardware UDP checksum enabled but not "
4429 			"supported by port %d\n", port_id);
4430 	}
4431 	if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4432 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4433 		printf("Warning: hardware TCP checksum enabled but not "
4434 			"supported by port %d\n", port_id);
4435 	}
4436 	if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4437 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4438 		printf("Warning: hardware SCTP checksum enabled but not "
4439 			"supported by port %d\n", port_id);
4440 	}
4441 	if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4442 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4443 		printf("Warning: hardware outer IP checksum enabled but not "
4444 			"supported by port %d\n", port_id);
4445 	}
4446 	if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4447 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4448 			== 0) {
4449 		printf("Warning: hardware outer UDP checksum enabled but not "
4450 			"supported by port %d\n", port_id);
4451 	}
4452 }
4453 
4454 static void
4455 cmd_config_queue_tx_offloads(struct rte_port *port)
4456 {
4457 	int k;
4458 
4459 	/* Apply queue tx offloads configuration */
4460 	for (k = 0; k < port->dev_info.max_rx_queues; k++)
4461 		port->tx_conf[k].offloads =
4462 			port->dev_conf.txmode.offloads;
4463 }
4464 
4465 static void
4466 cmd_csum_parsed(void *parsed_result,
4467 		       __attribute__((unused)) struct cmdline *cl,
4468 		       __attribute__((unused)) void *data)
4469 {
4470 	struct cmd_csum_result *res = parsed_result;
4471 	int hw = 0;
4472 	uint64_t csum_offloads = 0;
4473 	struct rte_eth_dev_info dev_info;
4474 	int ret;
4475 
4476 	if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4477 		printf("invalid port %d\n", res->port_id);
4478 		return;
4479 	}
4480 	if (!port_is_stopped(res->port_id)) {
4481 		printf("Please stop port %d first\n", res->port_id);
4482 		return;
4483 	}
4484 
4485 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4486 	if (ret != 0)
4487 		return;
4488 
4489 	if (!strcmp(res->mode, "set")) {
4490 
4491 		if (!strcmp(res->hwsw, "hw"))
4492 			hw = 1;
4493 
4494 		if (!strcmp(res->proto, "ip")) {
4495 			if (hw == 0 || (dev_info.tx_offload_capa &
4496 						DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4497 				csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4498 			} else {
4499 				printf("IP checksum offload is not supported "
4500 				       "by port %u\n", res->port_id);
4501 			}
4502 		} else if (!strcmp(res->proto, "udp")) {
4503 			if (hw == 0 || (dev_info.tx_offload_capa &
4504 						DEV_TX_OFFLOAD_UDP_CKSUM)) {
4505 				csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4506 			} else {
4507 				printf("UDP checksum offload is not supported "
4508 				       "by port %u\n", res->port_id);
4509 			}
4510 		} else if (!strcmp(res->proto, "tcp")) {
4511 			if (hw == 0 || (dev_info.tx_offload_capa &
4512 						DEV_TX_OFFLOAD_TCP_CKSUM)) {
4513 				csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4514 			} else {
4515 				printf("TCP checksum offload is not supported "
4516 				       "by port %u\n", res->port_id);
4517 			}
4518 		} else if (!strcmp(res->proto, "sctp")) {
4519 			if (hw == 0 || (dev_info.tx_offload_capa &
4520 						DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4521 				csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4522 			} else {
4523 				printf("SCTP checksum offload is not supported "
4524 				       "by port %u\n", res->port_id);
4525 			}
4526 		} else if (!strcmp(res->proto, "outer-ip")) {
4527 			if (hw == 0 || (dev_info.tx_offload_capa &
4528 					DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4529 				csum_offloads |=
4530 						DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4531 			} else {
4532 				printf("Outer IP checksum offload is not "
4533 				       "supported by port %u\n", res->port_id);
4534 			}
4535 		} else if (!strcmp(res->proto, "outer-udp")) {
4536 			if (hw == 0 || (dev_info.tx_offload_capa &
4537 					DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4538 				csum_offloads |=
4539 						DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4540 			} else {
4541 				printf("Outer UDP checksum offload is not "
4542 				       "supported by port %u\n", res->port_id);
4543 			}
4544 		}
4545 
4546 		if (hw) {
4547 			ports[res->port_id].dev_conf.txmode.offloads |=
4548 							csum_offloads;
4549 		} else {
4550 			ports[res->port_id].dev_conf.txmode.offloads &=
4551 							(~csum_offloads);
4552 		}
4553 		cmd_config_queue_tx_offloads(&ports[res->port_id]);
4554 	}
4555 	csum_show(res->port_id);
4556 
4557 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4558 }
4559 
4560 cmdline_parse_token_string_t cmd_csum_csum =
4561 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4562 				csum, "csum");
4563 cmdline_parse_token_string_t cmd_csum_mode =
4564 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4565 				mode, "set");
4566 cmdline_parse_token_string_t cmd_csum_proto =
4567 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4568 				proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4569 cmdline_parse_token_string_t cmd_csum_hwsw =
4570 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4571 				hwsw, "hw#sw");
4572 cmdline_parse_token_num_t cmd_csum_portid =
4573 	TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4574 				port_id, UINT16);
4575 
4576 cmdline_parse_inst_t cmd_csum_set = {
4577 	.f = cmd_csum_parsed,
4578 	.data = NULL,
4579 	.help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4580 		"Enable/Disable hardware calculation of L3/L4 checksum when "
4581 		"using csum forward engine",
4582 	.tokens = {
4583 		(void *)&cmd_csum_csum,
4584 		(void *)&cmd_csum_mode,
4585 		(void *)&cmd_csum_proto,
4586 		(void *)&cmd_csum_hwsw,
4587 		(void *)&cmd_csum_portid,
4588 		NULL,
4589 	},
4590 };
4591 
4592 cmdline_parse_token_string_t cmd_csum_mode_show =
4593 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4594 				mode, "show");
4595 
4596 cmdline_parse_inst_t cmd_csum_show = {
4597 	.f = cmd_csum_parsed,
4598 	.data = NULL,
4599 	.help_str = "csum show <port_id>: Show checksum offload configuration",
4600 	.tokens = {
4601 		(void *)&cmd_csum_csum,
4602 		(void *)&cmd_csum_mode_show,
4603 		(void *)&cmd_csum_portid,
4604 		NULL,
4605 	},
4606 };
4607 
4608 /* Enable/disable tunnel parsing */
4609 struct cmd_csum_tunnel_result {
4610 	cmdline_fixed_string_t csum;
4611 	cmdline_fixed_string_t parse;
4612 	cmdline_fixed_string_t onoff;
4613 	portid_t port_id;
4614 };
4615 
4616 static void
4617 cmd_csum_tunnel_parsed(void *parsed_result,
4618 		       __attribute__((unused)) struct cmdline *cl,
4619 		       __attribute__((unused)) void *data)
4620 {
4621 	struct cmd_csum_tunnel_result *res = parsed_result;
4622 
4623 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4624 		return;
4625 
4626 	if (!strcmp(res->onoff, "on"))
4627 		ports[res->port_id].parse_tunnel = 1;
4628 	else
4629 		ports[res->port_id].parse_tunnel = 0;
4630 
4631 	csum_show(res->port_id);
4632 }
4633 
4634 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4635 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4636 				csum, "csum");
4637 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4638 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4639 				parse, "parse-tunnel");
4640 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4641 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4642 				onoff, "on#off");
4643 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4644 	TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4645 				port_id, UINT16);
4646 
4647 cmdline_parse_inst_t cmd_csum_tunnel = {
4648 	.f = cmd_csum_tunnel_parsed,
4649 	.data = NULL,
4650 	.help_str = "csum parse-tunnel on|off <port_id>: "
4651 		"Enable/Disable parsing of tunnels for csum engine",
4652 	.tokens = {
4653 		(void *)&cmd_csum_tunnel_csum,
4654 		(void *)&cmd_csum_tunnel_parse,
4655 		(void *)&cmd_csum_tunnel_onoff,
4656 		(void *)&cmd_csum_tunnel_portid,
4657 		NULL,
4658 	},
4659 };
4660 
4661 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4662 struct cmd_tso_set_result {
4663 	cmdline_fixed_string_t tso;
4664 	cmdline_fixed_string_t mode;
4665 	uint16_t tso_segsz;
4666 	portid_t port_id;
4667 };
4668 
4669 static void
4670 cmd_tso_set_parsed(void *parsed_result,
4671 		       __attribute__((unused)) struct cmdline *cl,
4672 		       __attribute__((unused)) void *data)
4673 {
4674 	struct cmd_tso_set_result *res = parsed_result;
4675 	struct rte_eth_dev_info dev_info;
4676 	int ret;
4677 
4678 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4679 		return;
4680 	if (!port_is_stopped(res->port_id)) {
4681 		printf("Please stop port %d first\n", res->port_id);
4682 		return;
4683 	}
4684 
4685 	if (!strcmp(res->mode, "set"))
4686 		ports[res->port_id].tso_segsz = res->tso_segsz;
4687 
4688 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4689 	if (ret != 0)
4690 		return;
4691 
4692 	if ((ports[res->port_id].tso_segsz != 0) &&
4693 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4694 		printf("Error: TSO is not supported by port %d\n",
4695 		       res->port_id);
4696 		return;
4697 	}
4698 
4699 	if (ports[res->port_id].tso_segsz == 0) {
4700 		ports[res->port_id].dev_conf.txmode.offloads &=
4701 						~DEV_TX_OFFLOAD_TCP_TSO;
4702 		printf("TSO for non-tunneled packets is disabled\n");
4703 	} else {
4704 		ports[res->port_id].dev_conf.txmode.offloads |=
4705 						DEV_TX_OFFLOAD_TCP_TSO;
4706 		printf("TSO segment size for non-tunneled packets is %d\n",
4707 			ports[res->port_id].tso_segsz);
4708 	}
4709 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
4710 
4711 	/* display warnings if configuration is not supported by the NIC */
4712 	ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4713 	if (ret != 0)
4714 		return;
4715 
4716 	if ((ports[res->port_id].tso_segsz != 0) &&
4717 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4718 		printf("Warning: TSO enabled but not "
4719 			"supported by port %d\n", res->port_id);
4720 	}
4721 
4722 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4723 }
4724 
4725 cmdline_parse_token_string_t cmd_tso_set_tso =
4726 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4727 				tso, "tso");
4728 cmdline_parse_token_string_t cmd_tso_set_mode =
4729 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4730 				mode, "set");
4731 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4732 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4733 				tso_segsz, UINT16);
4734 cmdline_parse_token_num_t cmd_tso_set_portid =
4735 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4736 				port_id, UINT16);
4737 
4738 cmdline_parse_inst_t cmd_tso_set = {
4739 	.f = cmd_tso_set_parsed,
4740 	.data = NULL,
4741 	.help_str = "tso set <tso_segsz> <port_id>: "
4742 		"Set TSO segment size of non-tunneled packets for csum engine "
4743 		"(0 to disable)",
4744 	.tokens = {
4745 		(void *)&cmd_tso_set_tso,
4746 		(void *)&cmd_tso_set_mode,
4747 		(void *)&cmd_tso_set_tso_segsz,
4748 		(void *)&cmd_tso_set_portid,
4749 		NULL,
4750 	},
4751 };
4752 
4753 cmdline_parse_token_string_t cmd_tso_show_mode =
4754 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4755 				mode, "show");
4756 
4757 
4758 cmdline_parse_inst_t cmd_tso_show = {
4759 	.f = cmd_tso_set_parsed,
4760 	.data = NULL,
4761 	.help_str = "tso show <port_id>: "
4762 		"Show TSO segment size of non-tunneled packets for csum engine",
4763 	.tokens = {
4764 		(void *)&cmd_tso_set_tso,
4765 		(void *)&cmd_tso_show_mode,
4766 		(void *)&cmd_tso_set_portid,
4767 		NULL,
4768 	},
4769 };
4770 
4771 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4772 struct cmd_tunnel_tso_set_result {
4773 	cmdline_fixed_string_t tso;
4774 	cmdline_fixed_string_t mode;
4775 	uint16_t tso_segsz;
4776 	portid_t port_id;
4777 };
4778 
4779 static struct rte_eth_dev_info
4780 check_tunnel_tso_nic_support(portid_t port_id)
4781 {
4782 	struct rte_eth_dev_info dev_info;
4783 
4784 	if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4785 		return dev_info;
4786 
4787 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4788 		printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4789 		       "not enabled for port %d\n", port_id);
4790 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4791 		printf("Warning: GRE TUNNEL TSO	not supported therefore "
4792 		       "not enabled for port %d\n", port_id);
4793 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4794 		printf("Warning: IPIP TUNNEL TSO not supported therefore "
4795 		       "not enabled for port %d\n", port_id);
4796 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4797 		printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4798 		       "not enabled for port %d\n", port_id);
4799 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4800 		printf("Warning: IP TUNNEL TSO not supported therefore "
4801 		       "not enabled for port %d\n", port_id);
4802 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4803 		printf("Warning: UDP TUNNEL TSO not supported therefore "
4804 		       "not enabled for port %d\n", port_id);
4805 	return dev_info;
4806 }
4807 
4808 static void
4809 cmd_tunnel_tso_set_parsed(void *parsed_result,
4810 			  __attribute__((unused)) struct cmdline *cl,
4811 			  __attribute__((unused)) void *data)
4812 {
4813 	struct cmd_tunnel_tso_set_result *res = parsed_result;
4814 	struct rte_eth_dev_info dev_info;
4815 
4816 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4817 		return;
4818 	if (!port_is_stopped(res->port_id)) {
4819 		printf("Please stop port %d first\n", res->port_id);
4820 		return;
4821 	}
4822 
4823 	if (!strcmp(res->mode, "set"))
4824 		ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4825 
4826 	dev_info = check_tunnel_tso_nic_support(res->port_id);
4827 	if (ports[res->port_id].tunnel_tso_segsz == 0) {
4828 		ports[res->port_id].dev_conf.txmode.offloads &=
4829 			~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4830 			  DEV_TX_OFFLOAD_GRE_TNL_TSO |
4831 			  DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4832 			  DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4833 			  DEV_TX_OFFLOAD_IP_TNL_TSO |
4834 			  DEV_TX_OFFLOAD_UDP_TNL_TSO);
4835 		printf("TSO for tunneled packets is disabled\n");
4836 	} else {
4837 		uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4838 					 DEV_TX_OFFLOAD_GRE_TNL_TSO |
4839 					 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4840 					 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4841 					 DEV_TX_OFFLOAD_IP_TNL_TSO |
4842 					 DEV_TX_OFFLOAD_UDP_TNL_TSO);
4843 
4844 		ports[res->port_id].dev_conf.txmode.offloads |=
4845 			(tso_offloads & dev_info.tx_offload_capa);
4846 		printf("TSO segment size for tunneled packets is %d\n",
4847 			ports[res->port_id].tunnel_tso_segsz);
4848 
4849 		/* Below conditions are needed to make it work:
4850 		 * (1) tunnel TSO is supported by the NIC;
4851 		 * (2) "csum parse_tunnel" must be set so that tunneled pkts
4852 		 * are recognized;
4853 		 * (3) for tunneled pkts with outer L3 of IPv4,
4854 		 * "csum set outer-ip" must be set to hw, because after tso,
4855 		 * total_len of outer IP header is changed, and the checksum
4856 		 * of outer IP header calculated by sw should be wrong; that
4857 		 * is not necessary for IPv6 tunneled pkts because there's no
4858 		 * checksum in IP header anymore.
4859 		 */
4860 
4861 		if (!ports[res->port_id].parse_tunnel)
4862 			printf("Warning: csum parse_tunnel must be set "
4863 				"so that tunneled packets are recognized\n");
4864 		if (!(ports[res->port_id].dev_conf.txmode.offloads &
4865 		      DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4866 			printf("Warning: csum set outer-ip must be set to hw "
4867 				"if outer L3 is IPv4; not necessary for IPv6\n");
4868 	}
4869 
4870 	cmd_config_queue_tx_offloads(&ports[res->port_id]);
4871 	cmd_reconfig_device_queue(res->port_id, 1, 1);
4872 }
4873 
4874 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4875 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4876 				tso, "tunnel_tso");
4877 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4878 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4879 				mode, "set");
4880 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4881 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4882 				tso_segsz, UINT16);
4883 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4884 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4885 				port_id, UINT16);
4886 
4887 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4888 	.f = cmd_tunnel_tso_set_parsed,
4889 	.data = NULL,
4890 	.help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4891 		"Set TSO segment size of tunneled packets for csum engine "
4892 		"(0 to disable)",
4893 	.tokens = {
4894 		(void *)&cmd_tunnel_tso_set_tso,
4895 		(void *)&cmd_tunnel_tso_set_mode,
4896 		(void *)&cmd_tunnel_tso_set_tso_segsz,
4897 		(void *)&cmd_tunnel_tso_set_portid,
4898 		NULL,
4899 	},
4900 };
4901 
4902 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4903 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4904 				mode, "show");
4905 
4906 
4907 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4908 	.f = cmd_tunnel_tso_set_parsed,
4909 	.data = NULL,
4910 	.help_str = "tunnel_tso show <port_id> "
4911 		"Show TSO segment size of tunneled packets for csum engine",
4912 	.tokens = {
4913 		(void *)&cmd_tunnel_tso_set_tso,
4914 		(void *)&cmd_tunnel_tso_show_mode,
4915 		(void *)&cmd_tunnel_tso_set_portid,
4916 		NULL,
4917 	},
4918 };
4919 
4920 /* *** SET GRO FOR A PORT *** */
4921 struct cmd_gro_enable_result {
4922 	cmdline_fixed_string_t cmd_set;
4923 	cmdline_fixed_string_t cmd_port;
4924 	cmdline_fixed_string_t cmd_keyword;
4925 	cmdline_fixed_string_t cmd_onoff;
4926 	portid_t cmd_pid;
4927 };
4928 
4929 static void
4930 cmd_gro_enable_parsed(void *parsed_result,
4931 		__attribute__((unused)) struct cmdline *cl,
4932 		__attribute__((unused)) void *data)
4933 {
4934 	struct cmd_gro_enable_result *res;
4935 
4936 	res = parsed_result;
4937 	if (!strcmp(res->cmd_keyword, "gro"))
4938 		setup_gro(res->cmd_onoff, res->cmd_pid);
4939 }
4940 
4941 cmdline_parse_token_string_t cmd_gro_enable_set =
4942 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4943 			cmd_set, "set");
4944 cmdline_parse_token_string_t cmd_gro_enable_port =
4945 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4946 			cmd_keyword, "port");
4947 cmdline_parse_token_num_t cmd_gro_enable_pid =
4948 	TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4949 			cmd_pid, UINT16);
4950 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4951 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4952 			cmd_keyword, "gro");
4953 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4954 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4955 			cmd_onoff, "on#off");
4956 
4957 cmdline_parse_inst_t cmd_gro_enable = {
4958 	.f = cmd_gro_enable_parsed,
4959 	.data = NULL,
4960 	.help_str = "set port <port_id> gro on|off",
4961 	.tokens = {
4962 		(void *)&cmd_gro_enable_set,
4963 		(void *)&cmd_gro_enable_port,
4964 		(void *)&cmd_gro_enable_pid,
4965 		(void *)&cmd_gro_enable_keyword,
4966 		(void *)&cmd_gro_enable_onoff,
4967 		NULL,
4968 	},
4969 };
4970 
4971 /* *** DISPLAY GRO CONFIGURATION *** */
4972 struct cmd_gro_show_result {
4973 	cmdline_fixed_string_t cmd_show;
4974 	cmdline_fixed_string_t cmd_port;
4975 	cmdline_fixed_string_t cmd_keyword;
4976 	portid_t cmd_pid;
4977 };
4978 
4979 static void
4980 cmd_gro_show_parsed(void *parsed_result,
4981 		__attribute__((unused)) struct cmdline *cl,
4982 		__attribute__((unused)) void *data)
4983 {
4984 	struct cmd_gro_show_result *res;
4985 
4986 	res = parsed_result;
4987 	if (!strcmp(res->cmd_keyword, "gro"))
4988 		show_gro(res->cmd_pid);
4989 }
4990 
4991 cmdline_parse_token_string_t cmd_gro_show_show =
4992 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4993 			cmd_show, "show");
4994 cmdline_parse_token_string_t cmd_gro_show_port =
4995 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4996 			cmd_port, "port");
4997 cmdline_parse_token_num_t cmd_gro_show_pid =
4998 	TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4999 			cmd_pid, UINT16);
5000 cmdline_parse_token_string_t cmd_gro_show_keyword =
5001 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5002 			cmd_keyword, "gro");
5003 
5004 cmdline_parse_inst_t cmd_gro_show = {
5005 	.f = cmd_gro_show_parsed,
5006 	.data = NULL,
5007 	.help_str = "show port <port_id> gro",
5008 	.tokens = {
5009 		(void *)&cmd_gro_show_show,
5010 		(void *)&cmd_gro_show_port,
5011 		(void *)&cmd_gro_show_pid,
5012 		(void *)&cmd_gro_show_keyword,
5013 		NULL,
5014 	},
5015 };
5016 
5017 /* *** SET FLUSH CYCLES FOR GRO *** */
5018 struct cmd_gro_flush_result {
5019 	cmdline_fixed_string_t cmd_set;
5020 	cmdline_fixed_string_t cmd_keyword;
5021 	cmdline_fixed_string_t cmd_flush;
5022 	uint8_t cmd_cycles;
5023 };
5024 
5025 static void
5026 cmd_gro_flush_parsed(void *parsed_result,
5027 		__attribute__((unused)) struct cmdline *cl,
5028 		__attribute__((unused)) void *data)
5029 {
5030 	struct cmd_gro_flush_result *res;
5031 
5032 	res = parsed_result;
5033 	if ((!strcmp(res->cmd_keyword, "gro")) &&
5034 			(!strcmp(res->cmd_flush, "flush")))
5035 		setup_gro_flush_cycles(res->cmd_cycles);
5036 }
5037 
5038 cmdline_parse_token_string_t cmd_gro_flush_set =
5039 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5040 			cmd_set, "set");
5041 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5042 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5043 			cmd_keyword, "gro");
5044 cmdline_parse_token_string_t cmd_gro_flush_flush =
5045 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5046 			cmd_flush, "flush");
5047 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5048 	TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5049 			cmd_cycles, UINT8);
5050 
5051 cmdline_parse_inst_t cmd_gro_flush = {
5052 	.f = cmd_gro_flush_parsed,
5053 	.data = NULL,
5054 	.help_str = "set gro flush <cycles>",
5055 	.tokens = {
5056 		(void *)&cmd_gro_flush_set,
5057 		(void *)&cmd_gro_flush_keyword,
5058 		(void *)&cmd_gro_flush_flush,
5059 		(void *)&cmd_gro_flush_cycles,
5060 		NULL,
5061 	},
5062 };
5063 
5064 /* *** ENABLE/DISABLE GSO *** */
5065 struct cmd_gso_enable_result {
5066 	cmdline_fixed_string_t cmd_set;
5067 	cmdline_fixed_string_t cmd_port;
5068 	cmdline_fixed_string_t cmd_keyword;
5069 	cmdline_fixed_string_t cmd_mode;
5070 	portid_t cmd_pid;
5071 };
5072 
5073 static void
5074 cmd_gso_enable_parsed(void *parsed_result,
5075 		__attribute__((unused)) struct cmdline *cl,
5076 		__attribute__((unused)) void *data)
5077 {
5078 	struct cmd_gso_enable_result *res;
5079 
5080 	res = parsed_result;
5081 	if (!strcmp(res->cmd_keyword, "gso"))
5082 		setup_gso(res->cmd_mode, res->cmd_pid);
5083 }
5084 
5085 cmdline_parse_token_string_t cmd_gso_enable_set =
5086 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5087 			cmd_set, "set");
5088 cmdline_parse_token_string_t cmd_gso_enable_port =
5089 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5090 			cmd_port, "port");
5091 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5092 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5093 			cmd_keyword, "gso");
5094 cmdline_parse_token_string_t cmd_gso_enable_mode =
5095 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5096 			cmd_mode, "on#off");
5097 cmdline_parse_token_num_t cmd_gso_enable_pid =
5098 	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5099 			cmd_pid, UINT16);
5100 
5101 cmdline_parse_inst_t cmd_gso_enable = {
5102 	.f = cmd_gso_enable_parsed,
5103 	.data = NULL,
5104 	.help_str = "set port <port_id> gso on|off",
5105 	.tokens = {
5106 		(void *)&cmd_gso_enable_set,
5107 		(void *)&cmd_gso_enable_port,
5108 		(void *)&cmd_gso_enable_pid,
5109 		(void *)&cmd_gso_enable_keyword,
5110 		(void *)&cmd_gso_enable_mode,
5111 		NULL,
5112 	},
5113 };
5114 
5115 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5116 struct cmd_gso_size_result {
5117 	cmdline_fixed_string_t cmd_set;
5118 	cmdline_fixed_string_t cmd_keyword;
5119 	cmdline_fixed_string_t cmd_segsz;
5120 	uint16_t cmd_size;
5121 };
5122 
5123 static void
5124 cmd_gso_size_parsed(void *parsed_result,
5125 		       __attribute__((unused)) struct cmdline *cl,
5126 		       __attribute__((unused)) void *data)
5127 {
5128 	struct cmd_gso_size_result *res = parsed_result;
5129 
5130 	if (test_done == 0) {
5131 		printf("Before setting GSO segsz, please first"
5132 				" stop fowarding\n");
5133 		return;
5134 	}
5135 
5136 	if (!strcmp(res->cmd_keyword, "gso") &&
5137 			!strcmp(res->cmd_segsz, "segsz")) {
5138 		if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5139 			printf("gso_size should be larger than %zu."
5140 					" Please input a legal value\n",
5141 					RTE_GSO_SEG_SIZE_MIN);
5142 		else
5143 			gso_max_segment_size = res->cmd_size;
5144 	}
5145 }
5146 
5147 cmdline_parse_token_string_t cmd_gso_size_set =
5148 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5149 				cmd_set, "set");
5150 cmdline_parse_token_string_t cmd_gso_size_keyword =
5151 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5152 				cmd_keyword, "gso");
5153 cmdline_parse_token_string_t cmd_gso_size_segsz =
5154 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5155 				cmd_segsz, "segsz");
5156 cmdline_parse_token_num_t cmd_gso_size_size =
5157 	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5158 				cmd_size, UINT16);
5159 
5160 cmdline_parse_inst_t cmd_gso_size = {
5161 	.f = cmd_gso_size_parsed,
5162 	.data = NULL,
5163 	.help_str = "set gso segsz <length>",
5164 	.tokens = {
5165 		(void *)&cmd_gso_size_set,
5166 		(void *)&cmd_gso_size_keyword,
5167 		(void *)&cmd_gso_size_segsz,
5168 		(void *)&cmd_gso_size_size,
5169 		NULL,
5170 	},
5171 };
5172 
5173 /* *** SHOW GSO CONFIGURATION *** */
5174 struct cmd_gso_show_result {
5175 	cmdline_fixed_string_t cmd_show;
5176 	cmdline_fixed_string_t cmd_port;
5177 	cmdline_fixed_string_t cmd_keyword;
5178 	portid_t cmd_pid;
5179 };
5180 
5181 static void
5182 cmd_gso_show_parsed(void *parsed_result,
5183 		       __attribute__((unused)) struct cmdline *cl,
5184 		       __attribute__((unused)) void *data)
5185 {
5186 	struct cmd_gso_show_result *res = parsed_result;
5187 
5188 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5189 		printf("invalid port id %u\n", res->cmd_pid);
5190 		return;
5191 	}
5192 	if (!strcmp(res->cmd_keyword, "gso")) {
5193 		if (gso_ports[res->cmd_pid].enable) {
5194 			printf("Max GSO'd packet size: %uB\n"
5195 					"Supported GSO types: TCP/IPv4, "
5196 					"UDP/IPv4, VxLAN with inner "
5197 					"TCP/IPv4 packet, GRE with inner "
5198 					"TCP/IPv4 packet\n",
5199 					gso_max_segment_size);
5200 		} else
5201 			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5202 	}
5203 }
5204 
5205 cmdline_parse_token_string_t cmd_gso_show_show =
5206 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5207 		cmd_show, "show");
5208 cmdline_parse_token_string_t cmd_gso_show_port =
5209 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5210 		cmd_port, "port");
5211 cmdline_parse_token_string_t cmd_gso_show_keyword =
5212 	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5213 				cmd_keyword, "gso");
5214 cmdline_parse_token_num_t cmd_gso_show_pid =
5215 	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5216 				cmd_pid, UINT16);
5217 
5218 cmdline_parse_inst_t cmd_gso_show = {
5219 	.f = cmd_gso_show_parsed,
5220 	.data = NULL,
5221 	.help_str = "show port <port_id> gso",
5222 	.tokens = {
5223 		(void *)&cmd_gso_show_show,
5224 		(void *)&cmd_gso_show_port,
5225 		(void *)&cmd_gso_show_pid,
5226 		(void *)&cmd_gso_show_keyword,
5227 		NULL,
5228 	},
5229 };
5230 
5231 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5232 struct cmd_set_flush_rx {
5233 	cmdline_fixed_string_t set;
5234 	cmdline_fixed_string_t flush_rx;
5235 	cmdline_fixed_string_t mode;
5236 };
5237 
5238 static void
5239 cmd_set_flush_rx_parsed(void *parsed_result,
5240 		__attribute__((unused)) struct cmdline *cl,
5241 		__attribute__((unused)) void *data)
5242 {
5243 	struct cmd_set_flush_rx *res = parsed_result;
5244 	no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5245 }
5246 
5247 cmdline_parse_token_string_t cmd_setflushrx_set =
5248 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5249 			set, "set");
5250 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5251 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5252 			flush_rx, "flush_rx");
5253 cmdline_parse_token_string_t cmd_setflushrx_mode =
5254 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5255 			mode, "on#off");
5256 
5257 
5258 cmdline_parse_inst_t cmd_set_flush_rx = {
5259 	.f = cmd_set_flush_rx_parsed,
5260 	.help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5261 	.data = NULL,
5262 	.tokens = {
5263 		(void *)&cmd_setflushrx_set,
5264 		(void *)&cmd_setflushrx_flush_rx,
5265 		(void *)&cmd_setflushrx_mode,
5266 		NULL,
5267 	},
5268 };
5269 
5270 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5271 struct cmd_set_link_check {
5272 	cmdline_fixed_string_t set;
5273 	cmdline_fixed_string_t link_check;
5274 	cmdline_fixed_string_t mode;
5275 };
5276 
5277 static void
5278 cmd_set_link_check_parsed(void *parsed_result,
5279 		__attribute__((unused)) struct cmdline *cl,
5280 		__attribute__((unused)) void *data)
5281 {
5282 	struct cmd_set_link_check *res = parsed_result;
5283 	no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5284 }
5285 
5286 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5287 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5288 			set, "set");
5289 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5290 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5291 			link_check, "link_check");
5292 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5293 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5294 			mode, "on#off");
5295 
5296 
5297 cmdline_parse_inst_t cmd_set_link_check = {
5298 	.f = cmd_set_link_check_parsed,
5299 	.help_str = "set link_check on|off: Enable/Disable link status check "
5300 	            "when starting/stopping a port",
5301 	.data = NULL,
5302 	.tokens = {
5303 		(void *)&cmd_setlinkcheck_set,
5304 		(void *)&cmd_setlinkcheck_link_check,
5305 		(void *)&cmd_setlinkcheck_mode,
5306 		NULL,
5307 	},
5308 };
5309 
5310 /* *** SET NIC BYPASS MODE *** */
5311 struct cmd_set_bypass_mode_result {
5312 	cmdline_fixed_string_t set;
5313 	cmdline_fixed_string_t bypass;
5314 	cmdline_fixed_string_t mode;
5315 	cmdline_fixed_string_t value;
5316 	portid_t port_id;
5317 };
5318 
5319 static void
5320 cmd_set_bypass_mode_parsed(void *parsed_result,
5321 		__attribute__((unused)) struct cmdline *cl,
5322 		__attribute__((unused)) void *data)
5323 {
5324 	struct cmd_set_bypass_mode_result *res = parsed_result;
5325 	portid_t port_id = res->port_id;
5326 	int32_t rc = -EINVAL;
5327 
5328 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5329 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5330 
5331 	if (!strcmp(res->value, "bypass"))
5332 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5333 	else if (!strcmp(res->value, "isolate"))
5334 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5335 	else
5336 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5337 
5338 	/* Set the bypass mode for the relevant port. */
5339 	rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5340 #endif
5341 	if (rc != 0)
5342 		printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5343 }
5344 
5345 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5346 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5347 			set, "set");
5348 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5349 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5350 			bypass, "bypass");
5351 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5352 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5353 			mode, "mode");
5354 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5355 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5356 			value, "normal#bypass#isolate");
5357 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5358 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5359 				port_id, UINT16);
5360 
5361 cmdline_parse_inst_t cmd_set_bypass_mode = {
5362 	.f = cmd_set_bypass_mode_parsed,
5363 	.help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5364 	            "Set the NIC bypass mode for port_id",
5365 	.data = NULL,
5366 	.tokens = {
5367 		(void *)&cmd_setbypass_mode_set,
5368 		(void *)&cmd_setbypass_mode_bypass,
5369 		(void *)&cmd_setbypass_mode_mode,
5370 		(void *)&cmd_setbypass_mode_value,
5371 		(void *)&cmd_setbypass_mode_port,
5372 		NULL,
5373 	},
5374 };
5375 
5376 /* *** SET NIC BYPASS EVENT *** */
5377 struct cmd_set_bypass_event_result {
5378 	cmdline_fixed_string_t set;
5379 	cmdline_fixed_string_t bypass;
5380 	cmdline_fixed_string_t event;
5381 	cmdline_fixed_string_t event_value;
5382 	cmdline_fixed_string_t mode;
5383 	cmdline_fixed_string_t mode_value;
5384 	portid_t port_id;
5385 };
5386 
5387 static void
5388 cmd_set_bypass_event_parsed(void *parsed_result,
5389 		__attribute__((unused)) struct cmdline *cl,
5390 		__attribute__((unused)) void *data)
5391 {
5392 	int32_t rc = -EINVAL;
5393 	struct cmd_set_bypass_event_result *res = parsed_result;
5394 	portid_t port_id = res->port_id;
5395 
5396 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5397 	uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5398 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5399 
5400 	if (!strcmp(res->event_value, "timeout"))
5401 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5402 	else if (!strcmp(res->event_value, "os_on"))
5403 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5404 	else if (!strcmp(res->event_value, "os_off"))
5405 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5406 	else if (!strcmp(res->event_value, "power_on"))
5407 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5408 	else if (!strcmp(res->event_value, "power_off"))
5409 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5410 	else
5411 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5412 
5413 	if (!strcmp(res->mode_value, "bypass"))
5414 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5415 	else if (!strcmp(res->mode_value, "isolate"))
5416 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5417 	else
5418 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5419 
5420 	/* Set the watchdog timeout. */
5421 	if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5422 
5423 		rc = -EINVAL;
5424 		if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5425 			rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5426 							   bypass_timeout);
5427 		}
5428 		if (rc != 0) {
5429 			printf("Failed to set timeout value %u "
5430 			"for port %d, errto code: %d.\n",
5431 			bypass_timeout, port_id, rc);
5432 		}
5433 	}
5434 
5435 	/* Set the bypass event to transition to bypass mode. */
5436 	rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5437 					      bypass_mode);
5438 #endif
5439 
5440 	if (rc != 0)
5441 		printf("\t Failed to set bypass event for port = %d.\n",
5442 		       port_id);
5443 }
5444 
5445 cmdline_parse_token_string_t cmd_setbypass_event_set =
5446 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5447 			set, "set");
5448 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5449 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5450 			bypass, "bypass");
5451 cmdline_parse_token_string_t cmd_setbypass_event_event =
5452 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5453 			event, "event");
5454 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5455 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5456 			event_value, "none#timeout#os_off#os_on#power_on#power_off");
5457 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5458 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5459 			mode, "mode");
5460 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5461 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5462 			mode_value, "normal#bypass#isolate");
5463 cmdline_parse_token_num_t cmd_setbypass_event_port =
5464 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5465 				port_id, UINT16);
5466 
5467 cmdline_parse_inst_t cmd_set_bypass_event = {
5468 	.f = cmd_set_bypass_event_parsed,
5469 	.help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5470 		"power_off mode normal|bypass|isolate <port_id>: "
5471 		"Set the NIC bypass event mode for port_id",
5472 	.data = NULL,
5473 	.tokens = {
5474 		(void *)&cmd_setbypass_event_set,
5475 		(void *)&cmd_setbypass_event_bypass,
5476 		(void *)&cmd_setbypass_event_event,
5477 		(void *)&cmd_setbypass_event_event_value,
5478 		(void *)&cmd_setbypass_event_mode,
5479 		(void *)&cmd_setbypass_event_mode_value,
5480 		(void *)&cmd_setbypass_event_port,
5481 		NULL,
5482 	},
5483 };
5484 
5485 
5486 /* *** SET NIC BYPASS TIMEOUT *** */
5487 struct cmd_set_bypass_timeout_result {
5488 	cmdline_fixed_string_t set;
5489 	cmdline_fixed_string_t bypass;
5490 	cmdline_fixed_string_t timeout;
5491 	cmdline_fixed_string_t value;
5492 };
5493 
5494 static void
5495 cmd_set_bypass_timeout_parsed(void *parsed_result,
5496 		__attribute__((unused)) struct cmdline *cl,
5497 		__attribute__((unused)) void *data)
5498 {
5499 	__rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5500 
5501 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5502 	if (!strcmp(res->value, "1.5"))
5503 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5504 	else if (!strcmp(res->value, "2"))
5505 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5506 	else if (!strcmp(res->value, "3"))
5507 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5508 	else if (!strcmp(res->value, "4"))
5509 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5510 	else if (!strcmp(res->value, "8"))
5511 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5512 	else if (!strcmp(res->value, "16"))
5513 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5514 	else if (!strcmp(res->value, "32"))
5515 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5516 	else
5517 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5518 #endif
5519 }
5520 
5521 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5522 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5523 			set, "set");
5524 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5525 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5526 			bypass, "bypass");
5527 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5528 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5529 			timeout, "timeout");
5530 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5531 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5532 			value, "0#1.5#2#3#4#8#16#32");
5533 
5534 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5535 	.f = cmd_set_bypass_timeout_parsed,
5536 	.help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5537 		"Set the NIC bypass watchdog timeout in seconds",
5538 	.data = NULL,
5539 	.tokens = {
5540 		(void *)&cmd_setbypass_timeout_set,
5541 		(void *)&cmd_setbypass_timeout_bypass,
5542 		(void *)&cmd_setbypass_timeout_timeout,
5543 		(void *)&cmd_setbypass_timeout_value,
5544 		NULL,
5545 	},
5546 };
5547 
5548 /* *** SHOW NIC BYPASS MODE *** */
5549 struct cmd_show_bypass_config_result {
5550 	cmdline_fixed_string_t show;
5551 	cmdline_fixed_string_t bypass;
5552 	cmdline_fixed_string_t config;
5553 	portid_t port_id;
5554 };
5555 
5556 static void
5557 cmd_show_bypass_config_parsed(void *parsed_result,
5558 		__attribute__((unused)) struct cmdline *cl,
5559 		__attribute__((unused)) void *data)
5560 {
5561 	struct cmd_show_bypass_config_result *res = parsed_result;
5562 	portid_t port_id = res->port_id;
5563 	int rc = -EINVAL;
5564 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5565 	uint32_t event_mode;
5566 	uint32_t bypass_mode;
5567 	uint32_t timeout = bypass_timeout;
5568 	unsigned int i;
5569 
5570 	static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5571 		{"off", "1.5", "2", "3", "4", "8", "16", "32"};
5572 	static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5573 		{"UNKNOWN", "normal", "bypass", "isolate"};
5574 	static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5575 		"NONE",
5576 		"OS/board on",
5577 		"power supply on",
5578 		"OS/board off",
5579 		"power supply off",
5580 		"timeout"};
5581 
5582 	/* Display the bypass mode.*/
5583 	if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5584 		printf("\tFailed to get bypass mode for port = %d\n", port_id);
5585 		return;
5586 	}
5587 	else {
5588 		if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5589 			bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5590 
5591 		printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5592 	}
5593 
5594 	/* Display the bypass timeout.*/
5595 	if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5596 		timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5597 
5598 	printf("\tbypass timeout = %s\n", timeouts[timeout]);
5599 
5600 	/* Display the bypass events and associated modes. */
5601 	for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5602 
5603 		if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5604 			printf("\tFailed to get bypass mode for event = %s\n",
5605 				events[i]);
5606 		} else {
5607 			if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5608 				event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5609 
5610 			printf("\tbypass event: %-16s = %s\n", events[i],
5611 				modes[event_mode]);
5612 		}
5613 	}
5614 #endif
5615 	if (rc != 0)
5616 		printf("\tFailed to get bypass configuration for port = %d\n",
5617 		       port_id);
5618 }
5619 
5620 cmdline_parse_token_string_t cmd_showbypass_config_show =
5621 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5622 			show, "show");
5623 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5624 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5625 			bypass, "bypass");
5626 cmdline_parse_token_string_t cmd_showbypass_config_config =
5627 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5628 			config, "config");
5629 cmdline_parse_token_num_t cmd_showbypass_config_port =
5630 	TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5631 				port_id, UINT16);
5632 
5633 cmdline_parse_inst_t cmd_show_bypass_config = {
5634 	.f = cmd_show_bypass_config_parsed,
5635 	.help_str = "show bypass config <port_id>: "
5636 	            "Show the NIC bypass config for port_id",
5637 	.data = NULL,
5638 	.tokens = {
5639 		(void *)&cmd_showbypass_config_show,
5640 		(void *)&cmd_showbypass_config_bypass,
5641 		(void *)&cmd_showbypass_config_config,
5642 		(void *)&cmd_showbypass_config_port,
5643 		NULL,
5644 	},
5645 };
5646 
5647 #ifdef RTE_LIBRTE_PMD_BOND
5648 /* *** SET BONDING MODE *** */
5649 struct cmd_set_bonding_mode_result {
5650 	cmdline_fixed_string_t set;
5651 	cmdline_fixed_string_t bonding;
5652 	cmdline_fixed_string_t mode;
5653 	uint8_t value;
5654 	portid_t port_id;
5655 };
5656 
5657 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5658 		__attribute__((unused))  struct cmdline *cl,
5659 		__attribute__((unused)) void *data)
5660 {
5661 	struct cmd_set_bonding_mode_result *res = parsed_result;
5662 	portid_t port_id = res->port_id;
5663 
5664 	/* Set the bonding mode for the relevant port. */
5665 	if (0 != rte_eth_bond_mode_set(port_id, res->value))
5666 		printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5667 }
5668 
5669 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5670 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5671 		set, "set");
5672 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5673 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5674 		bonding, "bonding");
5675 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5676 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5677 		mode, "mode");
5678 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5679 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5680 		value, UINT8);
5681 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5682 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5683 		port_id, UINT16);
5684 
5685 cmdline_parse_inst_t cmd_set_bonding_mode = {
5686 		.f = cmd_set_bonding_mode_parsed,
5687 		.help_str = "set bonding mode <mode_value> <port_id>: "
5688 			"Set the bonding mode for port_id",
5689 		.data = NULL,
5690 		.tokens = {
5691 				(void *) &cmd_setbonding_mode_set,
5692 				(void *) &cmd_setbonding_mode_bonding,
5693 				(void *) &cmd_setbonding_mode_mode,
5694 				(void *) &cmd_setbonding_mode_value,
5695 				(void *) &cmd_setbonding_mode_port,
5696 				NULL
5697 		}
5698 };
5699 
5700 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5701 struct cmd_set_bonding_lacp_dedicated_queues_result {
5702 	cmdline_fixed_string_t set;
5703 	cmdline_fixed_string_t bonding;
5704 	cmdline_fixed_string_t lacp;
5705 	cmdline_fixed_string_t dedicated_queues;
5706 	portid_t port_id;
5707 	cmdline_fixed_string_t mode;
5708 };
5709 
5710 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5711 		__attribute__((unused))  struct cmdline *cl,
5712 		__attribute__((unused)) void *data)
5713 {
5714 	struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5715 	portid_t port_id = res->port_id;
5716 	struct rte_port *port;
5717 
5718 	port = &ports[port_id];
5719 
5720 	/** Check if the port is not started **/
5721 	if (port->port_status != RTE_PORT_STOPPED) {
5722 		printf("Please stop port %d first\n", port_id);
5723 		return;
5724 	}
5725 
5726 	if (!strcmp(res->mode, "enable")) {
5727 		if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5728 			printf("Dedicate queues for LACP control packets"
5729 					" enabled\n");
5730 		else
5731 			printf("Enabling dedicate queues for LACP control "
5732 					"packets on port %d failed\n", port_id);
5733 	} else if (!strcmp(res->mode, "disable")) {
5734 		if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5735 			printf("Dedicated queues for LACP control packets "
5736 					"disabled\n");
5737 		else
5738 			printf("Disabling dedicated queues for LACP control "
5739 					"traffic on port %d failed\n", port_id);
5740 	}
5741 }
5742 
5743 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5744 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5745 		set, "set");
5746 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5747 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5748 		bonding, "bonding");
5749 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5750 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5751 		lacp, "lacp");
5752 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5753 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5754 		dedicated_queues, "dedicated_queues");
5755 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5756 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5757 		port_id, UINT16);
5758 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5759 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5760 		mode, "enable#disable");
5761 
5762 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5763 		.f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5764 		.help_str = "set bonding lacp dedicated_queues <port_id> "
5765 			"enable|disable: "
5766 			"Enable/disable dedicated queues for LACP control traffic for port_id",
5767 		.data = NULL,
5768 		.tokens = {
5769 			(void *)&cmd_setbonding_lacp_dedicated_queues_set,
5770 			(void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5771 			(void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5772 			(void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5773 			(void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5774 			(void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5775 			NULL
5776 		}
5777 };
5778 
5779 /* *** SET BALANCE XMIT POLICY *** */
5780 struct cmd_set_bonding_balance_xmit_policy_result {
5781 	cmdline_fixed_string_t set;
5782 	cmdline_fixed_string_t bonding;
5783 	cmdline_fixed_string_t balance_xmit_policy;
5784 	portid_t port_id;
5785 	cmdline_fixed_string_t policy;
5786 };
5787 
5788 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5789 		__attribute__((unused))  struct cmdline *cl,
5790 		__attribute__((unused)) void *data)
5791 {
5792 	struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5793 	portid_t port_id = res->port_id;
5794 	uint8_t policy;
5795 
5796 	if (!strcmp(res->policy, "l2")) {
5797 		policy = BALANCE_XMIT_POLICY_LAYER2;
5798 	} else if (!strcmp(res->policy, "l23")) {
5799 		policy = BALANCE_XMIT_POLICY_LAYER23;
5800 	} else if (!strcmp(res->policy, "l34")) {
5801 		policy = BALANCE_XMIT_POLICY_LAYER34;
5802 	} else {
5803 		printf("\t Invalid xmit policy selection");
5804 		return;
5805 	}
5806 
5807 	/* Set the bonding mode for the relevant port. */
5808 	if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5809 		printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5810 				port_id);
5811 	}
5812 }
5813 
5814 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5815 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5816 		set, "set");
5817 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5818 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5819 		bonding, "bonding");
5820 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5821 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5822 		balance_xmit_policy, "balance_xmit_policy");
5823 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5824 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5825 		port_id, UINT16);
5826 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5827 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5828 		policy, "l2#l23#l34");
5829 
5830 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5831 		.f = cmd_set_bonding_balance_xmit_policy_parsed,
5832 		.help_str = "set bonding balance_xmit_policy <port_id> "
5833 			"l2|l23|l34: "
5834 			"Set the bonding balance_xmit_policy for port_id",
5835 		.data = NULL,
5836 		.tokens = {
5837 				(void *)&cmd_setbonding_balance_xmit_policy_set,
5838 				(void *)&cmd_setbonding_balance_xmit_policy_bonding,
5839 				(void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5840 				(void *)&cmd_setbonding_balance_xmit_policy_port,
5841 				(void *)&cmd_setbonding_balance_xmit_policy_policy,
5842 				NULL
5843 		}
5844 };
5845 
5846 /* *** SHOW NIC BONDING CONFIGURATION *** */
5847 struct cmd_show_bonding_config_result {
5848 	cmdline_fixed_string_t show;
5849 	cmdline_fixed_string_t bonding;
5850 	cmdline_fixed_string_t config;
5851 	portid_t port_id;
5852 };
5853 
5854 static void cmd_show_bonding_config_parsed(void *parsed_result,
5855 		__attribute__((unused))  struct cmdline *cl,
5856 		__attribute__((unused)) void *data)
5857 {
5858 	struct cmd_show_bonding_config_result *res = parsed_result;
5859 	int bonding_mode, agg_mode;
5860 	portid_t slaves[RTE_MAX_ETHPORTS];
5861 	int num_slaves, num_active_slaves;
5862 	int primary_id;
5863 	int i;
5864 	portid_t port_id = res->port_id;
5865 
5866 	/* Display the bonding mode.*/
5867 	bonding_mode = rte_eth_bond_mode_get(port_id);
5868 	if (bonding_mode < 0) {
5869 		printf("\tFailed to get bonding mode for port = %d\n", port_id);
5870 		return;
5871 	} else
5872 		printf("\tBonding mode: %d\n", bonding_mode);
5873 
5874 	if (bonding_mode == BONDING_MODE_BALANCE) {
5875 		int balance_xmit_policy;
5876 
5877 		balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5878 		if (balance_xmit_policy < 0) {
5879 			printf("\tFailed to get balance xmit policy for port = %d\n",
5880 					port_id);
5881 			return;
5882 		} else {
5883 			printf("\tBalance Xmit Policy: ");
5884 
5885 			switch (balance_xmit_policy) {
5886 			case BALANCE_XMIT_POLICY_LAYER2:
5887 				printf("BALANCE_XMIT_POLICY_LAYER2");
5888 				break;
5889 			case BALANCE_XMIT_POLICY_LAYER23:
5890 				printf("BALANCE_XMIT_POLICY_LAYER23");
5891 				break;
5892 			case BALANCE_XMIT_POLICY_LAYER34:
5893 				printf("BALANCE_XMIT_POLICY_LAYER34");
5894 				break;
5895 			}
5896 			printf("\n");
5897 		}
5898 	}
5899 
5900 	if (bonding_mode == BONDING_MODE_8023AD) {
5901 		agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5902 		printf("\tIEEE802.3AD Aggregator Mode: ");
5903 		switch (agg_mode) {
5904 		case AGG_BANDWIDTH:
5905 			printf("bandwidth");
5906 			break;
5907 		case AGG_STABLE:
5908 			printf("stable");
5909 			break;
5910 		case AGG_COUNT:
5911 			printf("count");
5912 			break;
5913 		}
5914 		printf("\n");
5915 	}
5916 
5917 	num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5918 
5919 	if (num_slaves < 0) {
5920 		printf("\tFailed to get slave list for port = %d\n", port_id);
5921 		return;
5922 	}
5923 	if (num_slaves > 0) {
5924 		printf("\tSlaves (%d): [", num_slaves);
5925 		for (i = 0; i < num_slaves - 1; i++)
5926 			printf("%d ", slaves[i]);
5927 
5928 		printf("%d]\n", slaves[num_slaves - 1]);
5929 	} else {
5930 		printf("\tSlaves: []\n");
5931 
5932 	}
5933 
5934 	num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5935 			RTE_MAX_ETHPORTS);
5936 
5937 	if (num_active_slaves < 0) {
5938 		printf("\tFailed to get active slave list for port = %d\n", port_id);
5939 		return;
5940 	}
5941 	if (num_active_slaves > 0) {
5942 		printf("\tActive Slaves (%d): [", num_active_slaves);
5943 		for (i = 0; i < num_active_slaves - 1; i++)
5944 			printf("%d ", slaves[i]);
5945 
5946 		printf("%d]\n", slaves[num_active_slaves - 1]);
5947 
5948 	} else {
5949 		printf("\tActive Slaves: []\n");
5950 
5951 	}
5952 
5953 	primary_id = rte_eth_bond_primary_get(port_id);
5954 	if (primary_id < 0) {
5955 		printf("\tFailed to get primary slave for port = %d\n", port_id);
5956 		return;
5957 	} else
5958 		printf("\tPrimary: [%d]\n", primary_id);
5959 
5960 }
5961 
5962 cmdline_parse_token_string_t cmd_showbonding_config_show =
5963 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5964 		show, "show");
5965 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5966 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5967 		bonding, "bonding");
5968 cmdline_parse_token_string_t cmd_showbonding_config_config =
5969 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5970 		config, "config");
5971 cmdline_parse_token_num_t cmd_showbonding_config_port =
5972 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5973 		port_id, UINT16);
5974 
5975 cmdline_parse_inst_t cmd_show_bonding_config = {
5976 		.f = cmd_show_bonding_config_parsed,
5977 		.help_str = "show bonding config <port_id>: "
5978 			"Show the bonding config for port_id",
5979 		.data = NULL,
5980 		.tokens = {
5981 				(void *)&cmd_showbonding_config_show,
5982 				(void *)&cmd_showbonding_config_bonding,
5983 				(void *)&cmd_showbonding_config_config,
5984 				(void *)&cmd_showbonding_config_port,
5985 				NULL
5986 		}
5987 };
5988 
5989 /* *** SET BONDING PRIMARY *** */
5990 struct cmd_set_bonding_primary_result {
5991 	cmdline_fixed_string_t set;
5992 	cmdline_fixed_string_t bonding;
5993 	cmdline_fixed_string_t primary;
5994 	portid_t slave_id;
5995 	portid_t port_id;
5996 };
5997 
5998 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5999 		__attribute__((unused))  struct cmdline *cl,
6000 		__attribute__((unused)) void *data)
6001 {
6002 	struct cmd_set_bonding_primary_result *res = parsed_result;
6003 	portid_t master_port_id = res->port_id;
6004 	portid_t slave_port_id = res->slave_id;
6005 
6006 	/* Set the primary slave for a bonded device. */
6007 	if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6008 		printf("\t Failed to set primary slave for port = %d.\n",
6009 				master_port_id);
6010 		return;
6011 	}
6012 	init_port_config();
6013 }
6014 
6015 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6016 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6017 		set, "set");
6018 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6019 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6020 		bonding, "bonding");
6021 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6022 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6023 		primary, "primary");
6024 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6025 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6026 		slave_id, UINT16);
6027 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6028 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6029 		port_id, UINT16);
6030 
6031 cmdline_parse_inst_t cmd_set_bonding_primary = {
6032 		.f = cmd_set_bonding_primary_parsed,
6033 		.help_str = "set bonding primary <slave_id> <port_id>: "
6034 			"Set the primary slave for port_id",
6035 		.data = NULL,
6036 		.tokens = {
6037 				(void *)&cmd_setbonding_primary_set,
6038 				(void *)&cmd_setbonding_primary_bonding,
6039 				(void *)&cmd_setbonding_primary_primary,
6040 				(void *)&cmd_setbonding_primary_slave,
6041 				(void *)&cmd_setbonding_primary_port,
6042 				NULL
6043 		}
6044 };
6045 
6046 /* *** ADD SLAVE *** */
6047 struct cmd_add_bonding_slave_result {
6048 	cmdline_fixed_string_t add;
6049 	cmdline_fixed_string_t bonding;
6050 	cmdline_fixed_string_t slave;
6051 	portid_t slave_id;
6052 	portid_t port_id;
6053 };
6054 
6055 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6056 		__attribute__((unused))  struct cmdline *cl,
6057 		__attribute__((unused)) void *data)
6058 {
6059 	struct cmd_add_bonding_slave_result *res = parsed_result;
6060 	portid_t master_port_id = res->port_id;
6061 	portid_t slave_port_id = res->slave_id;
6062 
6063 	/* add the slave for a bonded device. */
6064 	if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6065 		printf("\t Failed to add slave %d to master port = %d.\n",
6066 				slave_port_id, master_port_id);
6067 		return;
6068 	}
6069 	init_port_config();
6070 	set_port_slave_flag(slave_port_id);
6071 }
6072 
6073 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6074 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6075 		add, "add");
6076 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6077 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6078 		bonding, "bonding");
6079 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6080 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6081 		slave, "slave");
6082 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6083 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6084 		slave_id, UINT16);
6085 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6086 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6087 		port_id, UINT16);
6088 
6089 cmdline_parse_inst_t cmd_add_bonding_slave = {
6090 		.f = cmd_add_bonding_slave_parsed,
6091 		.help_str = "add bonding slave <slave_id> <port_id>: "
6092 			"Add a slave device to a bonded device",
6093 		.data = NULL,
6094 		.tokens = {
6095 				(void *)&cmd_addbonding_slave_add,
6096 				(void *)&cmd_addbonding_slave_bonding,
6097 				(void *)&cmd_addbonding_slave_slave,
6098 				(void *)&cmd_addbonding_slave_slaveid,
6099 				(void *)&cmd_addbonding_slave_port,
6100 				NULL
6101 		}
6102 };
6103 
6104 /* *** REMOVE SLAVE *** */
6105 struct cmd_remove_bonding_slave_result {
6106 	cmdline_fixed_string_t remove;
6107 	cmdline_fixed_string_t bonding;
6108 	cmdline_fixed_string_t slave;
6109 	portid_t slave_id;
6110 	portid_t port_id;
6111 };
6112 
6113 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6114 		__attribute__((unused))  struct cmdline *cl,
6115 		__attribute__((unused)) void *data)
6116 {
6117 	struct cmd_remove_bonding_slave_result *res = parsed_result;
6118 	portid_t master_port_id = res->port_id;
6119 	portid_t slave_port_id = res->slave_id;
6120 
6121 	/* remove the slave from a bonded device. */
6122 	if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6123 		printf("\t Failed to remove slave %d from master port = %d.\n",
6124 				slave_port_id, master_port_id);
6125 		return;
6126 	}
6127 	init_port_config();
6128 	clear_port_slave_flag(slave_port_id);
6129 }
6130 
6131 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6132 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6133 				remove, "remove");
6134 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6135 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6136 				bonding, "bonding");
6137 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6138 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6139 				slave, "slave");
6140 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6141 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6142 				slave_id, UINT16);
6143 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6144 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6145 				port_id, UINT16);
6146 
6147 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6148 		.f = cmd_remove_bonding_slave_parsed,
6149 		.help_str = "remove bonding slave <slave_id> <port_id>: "
6150 			"Remove a slave device from a bonded device",
6151 		.data = NULL,
6152 		.tokens = {
6153 				(void *)&cmd_removebonding_slave_remove,
6154 				(void *)&cmd_removebonding_slave_bonding,
6155 				(void *)&cmd_removebonding_slave_slave,
6156 				(void *)&cmd_removebonding_slave_slaveid,
6157 				(void *)&cmd_removebonding_slave_port,
6158 				NULL
6159 		}
6160 };
6161 
6162 /* *** CREATE BONDED DEVICE *** */
6163 struct cmd_create_bonded_device_result {
6164 	cmdline_fixed_string_t create;
6165 	cmdline_fixed_string_t bonded;
6166 	cmdline_fixed_string_t device;
6167 	uint8_t mode;
6168 	uint8_t socket;
6169 };
6170 
6171 static int bond_dev_num = 0;
6172 
6173 static void cmd_create_bonded_device_parsed(void *parsed_result,
6174 		__attribute__((unused))  struct cmdline *cl,
6175 		__attribute__((unused)) void *data)
6176 {
6177 	struct cmd_create_bonded_device_result *res = parsed_result;
6178 	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6179 	int port_id;
6180 	int ret;
6181 
6182 	if (test_done == 0) {
6183 		printf("Please stop forwarding first\n");
6184 		return;
6185 	}
6186 
6187 	snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6188 			bond_dev_num++);
6189 
6190 	/* Create a new bonded device. */
6191 	port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6192 	if (port_id < 0) {
6193 		printf("\t Failed to create bonded device.\n");
6194 		return;
6195 	} else {
6196 		printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6197 				port_id);
6198 
6199 		/* Update number of ports */
6200 		nb_ports = rte_eth_dev_count_avail();
6201 		reconfig(port_id, res->socket);
6202 		ret = rte_eth_promiscuous_enable(port_id);
6203 		if (ret != 0)
6204 			printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6205 				port_id, rte_strerror(-ret));
6206 
6207 		ports[port_id].need_setup = 0;
6208 		ports[port_id].port_status = RTE_PORT_STOPPED;
6209 	}
6210 
6211 }
6212 
6213 cmdline_parse_token_string_t cmd_createbonded_device_create =
6214 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6215 				create, "create");
6216 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6217 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6218 				bonded, "bonded");
6219 cmdline_parse_token_string_t cmd_createbonded_device_device =
6220 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6221 				device, "device");
6222 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6223 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6224 				mode, UINT8);
6225 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6226 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6227 				socket, UINT8);
6228 
6229 cmdline_parse_inst_t cmd_create_bonded_device = {
6230 		.f = cmd_create_bonded_device_parsed,
6231 		.help_str = "create bonded device <mode> <socket>: "
6232 			"Create a new bonded device with specific bonding mode and socket",
6233 		.data = NULL,
6234 		.tokens = {
6235 				(void *)&cmd_createbonded_device_create,
6236 				(void *)&cmd_createbonded_device_bonded,
6237 				(void *)&cmd_createbonded_device_device,
6238 				(void *)&cmd_createbonded_device_mode,
6239 				(void *)&cmd_createbonded_device_socket,
6240 				NULL
6241 		}
6242 };
6243 
6244 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6245 struct cmd_set_bond_mac_addr_result {
6246 	cmdline_fixed_string_t set;
6247 	cmdline_fixed_string_t bonding;
6248 	cmdline_fixed_string_t mac_addr;
6249 	uint16_t port_num;
6250 	struct rte_ether_addr address;
6251 };
6252 
6253 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6254 		__attribute__((unused))  struct cmdline *cl,
6255 		__attribute__((unused)) void *data)
6256 {
6257 	struct cmd_set_bond_mac_addr_result *res = parsed_result;
6258 	int ret;
6259 
6260 	if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6261 		return;
6262 
6263 	ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6264 
6265 	/* check the return value and print it if is < 0 */
6266 	if (ret < 0)
6267 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6268 }
6269 
6270 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6271 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6272 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6273 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6274 				"bonding");
6275 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6276 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6277 				"mac_addr");
6278 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6279 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6280 				port_num, UINT16);
6281 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6282 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6283 
6284 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6285 		.f = cmd_set_bond_mac_addr_parsed,
6286 		.data = (void *) 0,
6287 		.help_str = "set bonding mac_addr <port_id> <mac_addr>",
6288 		.tokens = {
6289 				(void *)&cmd_set_bond_mac_addr_set,
6290 				(void *)&cmd_set_bond_mac_addr_bonding,
6291 				(void *)&cmd_set_bond_mac_addr_mac,
6292 				(void *)&cmd_set_bond_mac_addr_portnum,
6293 				(void *)&cmd_set_bond_mac_addr_addr,
6294 				NULL
6295 		}
6296 };
6297 
6298 
6299 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6300 struct cmd_set_bond_mon_period_result {
6301 	cmdline_fixed_string_t set;
6302 	cmdline_fixed_string_t bonding;
6303 	cmdline_fixed_string_t mon_period;
6304 	uint16_t port_num;
6305 	uint32_t period_ms;
6306 };
6307 
6308 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6309 		__attribute__((unused))  struct cmdline *cl,
6310 		__attribute__((unused)) void *data)
6311 {
6312 	struct cmd_set_bond_mon_period_result *res = parsed_result;
6313 	int ret;
6314 
6315 	ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6316 
6317 	/* check the return value and print it if is < 0 */
6318 	if (ret < 0)
6319 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6320 }
6321 
6322 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6323 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6324 				set, "set");
6325 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6326 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6327 				bonding, "bonding");
6328 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6329 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6330 				mon_period,	"mon_period");
6331 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6332 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6333 				port_num, UINT16);
6334 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6335 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6336 				period_ms, UINT32);
6337 
6338 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6339 		.f = cmd_set_bond_mon_period_parsed,
6340 		.data = (void *) 0,
6341 		.help_str = "set bonding mon_period <port_id> <period_ms>",
6342 		.tokens = {
6343 				(void *)&cmd_set_bond_mon_period_set,
6344 				(void *)&cmd_set_bond_mon_period_bonding,
6345 				(void *)&cmd_set_bond_mon_period_mon_period,
6346 				(void *)&cmd_set_bond_mon_period_portnum,
6347 				(void *)&cmd_set_bond_mon_period_period_ms,
6348 				NULL
6349 		}
6350 };
6351 
6352 
6353 
6354 struct cmd_set_bonding_agg_mode_policy_result {
6355 	cmdline_fixed_string_t set;
6356 	cmdline_fixed_string_t bonding;
6357 	cmdline_fixed_string_t agg_mode;
6358 	uint16_t port_num;
6359 	cmdline_fixed_string_t policy;
6360 };
6361 
6362 
6363 static void
6364 cmd_set_bonding_agg_mode(void *parsed_result,
6365 		__attribute__((unused)) struct cmdline *cl,
6366 		__attribute__((unused)) void *data)
6367 {
6368 	struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6369 	uint8_t policy = AGG_BANDWIDTH;
6370 
6371 	if (!strcmp(res->policy, "bandwidth"))
6372 		policy = AGG_BANDWIDTH;
6373 	else if (!strcmp(res->policy, "stable"))
6374 		policy = AGG_STABLE;
6375 	else if (!strcmp(res->policy, "count"))
6376 		policy = AGG_COUNT;
6377 
6378 	rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6379 }
6380 
6381 
6382 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6383 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6384 				set, "set");
6385 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6386 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6387 				bonding, "bonding");
6388 
6389 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6390 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6391 				agg_mode, "agg_mode");
6392 
6393 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6394 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6395 				port_num, UINT16);
6396 
6397 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6398 	TOKEN_STRING_INITIALIZER(
6399 			struct cmd_set_bonding_balance_xmit_policy_result,
6400 		policy, "stable#bandwidth#count");
6401 
6402 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6403 	.f = cmd_set_bonding_agg_mode,
6404 	.data = (void *) 0,
6405 	.help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6406 	.tokens = {
6407 			(void *)&cmd_set_bonding_agg_mode_set,
6408 			(void *)&cmd_set_bonding_agg_mode_bonding,
6409 			(void *)&cmd_set_bonding_agg_mode_agg_mode,
6410 			(void *)&cmd_set_bonding_agg_mode_portnum,
6411 			(void *)&cmd_set_bonding_agg_mode_policy_string,
6412 			NULL
6413 		}
6414 };
6415 
6416 
6417 #endif /* RTE_LIBRTE_PMD_BOND */
6418 
6419 /* *** SET FORWARDING MODE *** */
6420 struct cmd_set_fwd_mode_result {
6421 	cmdline_fixed_string_t set;
6422 	cmdline_fixed_string_t fwd;
6423 	cmdline_fixed_string_t mode;
6424 };
6425 
6426 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6427 				    __attribute__((unused)) struct cmdline *cl,
6428 				    __attribute__((unused)) void *data)
6429 {
6430 	struct cmd_set_fwd_mode_result *res = parsed_result;
6431 
6432 	retry_enabled = 0;
6433 	set_pkt_forwarding_mode(res->mode);
6434 }
6435 
6436 cmdline_parse_token_string_t cmd_setfwd_set =
6437 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6438 cmdline_parse_token_string_t cmd_setfwd_fwd =
6439 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6440 cmdline_parse_token_string_t cmd_setfwd_mode =
6441 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6442 		"" /* defined at init */);
6443 
6444 cmdline_parse_inst_t cmd_set_fwd_mode = {
6445 	.f = cmd_set_fwd_mode_parsed,
6446 	.data = NULL,
6447 	.help_str = NULL, /* defined at init */
6448 	.tokens = {
6449 		(void *)&cmd_setfwd_set,
6450 		(void *)&cmd_setfwd_fwd,
6451 		(void *)&cmd_setfwd_mode,
6452 		NULL,
6453 	},
6454 };
6455 
6456 static void cmd_set_fwd_mode_init(void)
6457 {
6458 	char *modes, *c;
6459 	static char token[128];
6460 	static char help[256];
6461 	cmdline_parse_token_string_t *token_struct;
6462 
6463 	modes = list_pkt_forwarding_modes();
6464 	snprintf(help, sizeof(help), "set fwd %s: "
6465 		"Set packet forwarding mode", modes);
6466 	cmd_set_fwd_mode.help_str = help;
6467 
6468 	/* string token separator is # */
6469 	for (c = token; *modes != '\0'; modes++)
6470 		if (*modes == '|')
6471 			*c++ = '#';
6472 		else
6473 			*c++ = *modes;
6474 	token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6475 	token_struct->string_data.str = token;
6476 }
6477 
6478 /* *** SET RETRY FORWARDING MODE *** */
6479 struct cmd_set_fwd_retry_mode_result {
6480 	cmdline_fixed_string_t set;
6481 	cmdline_fixed_string_t fwd;
6482 	cmdline_fixed_string_t mode;
6483 	cmdline_fixed_string_t retry;
6484 };
6485 
6486 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6487 			    __attribute__((unused)) struct cmdline *cl,
6488 			    __attribute__((unused)) void *data)
6489 {
6490 	struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6491 
6492 	retry_enabled = 1;
6493 	set_pkt_forwarding_mode(res->mode);
6494 }
6495 
6496 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6497 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6498 			set, "set");
6499 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6500 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6501 			fwd, "fwd");
6502 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6503 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6504 			mode,
6505 		"" /* defined at init */);
6506 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6507 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6508 			retry, "retry");
6509 
6510 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6511 	.f = cmd_set_fwd_retry_mode_parsed,
6512 	.data = NULL,
6513 	.help_str = NULL, /* defined at init */
6514 	.tokens = {
6515 		(void *)&cmd_setfwd_retry_set,
6516 		(void *)&cmd_setfwd_retry_fwd,
6517 		(void *)&cmd_setfwd_retry_mode,
6518 		(void *)&cmd_setfwd_retry_retry,
6519 		NULL,
6520 	},
6521 };
6522 
6523 static void cmd_set_fwd_retry_mode_init(void)
6524 {
6525 	char *modes, *c;
6526 	static char token[128];
6527 	static char help[256];
6528 	cmdline_parse_token_string_t *token_struct;
6529 
6530 	modes = list_pkt_forwarding_retry_modes();
6531 	snprintf(help, sizeof(help), "set fwd %s retry: "
6532 		"Set packet forwarding mode with retry", modes);
6533 	cmd_set_fwd_retry_mode.help_str = help;
6534 
6535 	/* string token separator is # */
6536 	for (c = token; *modes != '\0'; modes++)
6537 		if (*modes == '|')
6538 			*c++ = '#';
6539 		else
6540 			*c++ = *modes;
6541 	token_struct = (cmdline_parse_token_string_t *)
6542 		cmd_set_fwd_retry_mode.tokens[2];
6543 	token_struct->string_data.str = token;
6544 }
6545 
6546 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6547 struct cmd_set_burst_tx_retry_result {
6548 	cmdline_fixed_string_t set;
6549 	cmdline_fixed_string_t burst;
6550 	cmdline_fixed_string_t tx;
6551 	cmdline_fixed_string_t delay;
6552 	uint32_t time;
6553 	cmdline_fixed_string_t retry;
6554 	uint32_t retry_num;
6555 };
6556 
6557 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6558 					__attribute__((unused)) struct cmdline *cl,
6559 					__attribute__((unused)) void *data)
6560 {
6561 	struct cmd_set_burst_tx_retry_result *res = parsed_result;
6562 
6563 	if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6564 		&& !strcmp(res->tx, "tx")) {
6565 		if (!strcmp(res->delay, "delay"))
6566 			burst_tx_delay_time = res->time;
6567 		if (!strcmp(res->retry, "retry"))
6568 			burst_tx_retry_num = res->retry_num;
6569 	}
6570 
6571 }
6572 
6573 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6574 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6575 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6576 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6577 				 "burst");
6578 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6579 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6580 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6581 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6582 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6583 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6584 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6585 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6586 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6587 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6588 
6589 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6590 	.f = cmd_set_burst_tx_retry_parsed,
6591 	.help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6592 	.tokens = {
6593 		(void *)&cmd_set_burst_tx_retry_set,
6594 		(void *)&cmd_set_burst_tx_retry_burst,
6595 		(void *)&cmd_set_burst_tx_retry_tx,
6596 		(void *)&cmd_set_burst_tx_retry_delay,
6597 		(void *)&cmd_set_burst_tx_retry_time,
6598 		(void *)&cmd_set_burst_tx_retry_retry,
6599 		(void *)&cmd_set_burst_tx_retry_retry_num,
6600 		NULL,
6601 	},
6602 };
6603 
6604 /* *** SET PROMISC MODE *** */
6605 struct cmd_set_promisc_mode_result {
6606 	cmdline_fixed_string_t set;
6607 	cmdline_fixed_string_t promisc;
6608 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6609 	uint16_t port_num;               /* valid if "allports" argument == 0 */
6610 	cmdline_fixed_string_t mode;
6611 };
6612 
6613 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6614 					__attribute__((unused)) struct cmdline *cl,
6615 					void *allports)
6616 {
6617 	struct cmd_set_promisc_mode_result *res = parsed_result;
6618 	int enable;
6619 	portid_t i;
6620 
6621 	if (!strcmp(res->mode, "on"))
6622 		enable = 1;
6623 	else
6624 		enable = 0;
6625 
6626 	/* all ports */
6627 	if (allports) {
6628 		RTE_ETH_FOREACH_DEV(i)
6629 			eth_set_promisc_mode(i, enable);
6630 	} else {
6631 		eth_set_promisc_mode(res->port_num, enable);
6632 	}
6633 }
6634 
6635 cmdline_parse_token_string_t cmd_setpromisc_set =
6636 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6637 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6638 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6639 				 "promisc");
6640 cmdline_parse_token_string_t cmd_setpromisc_portall =
6641 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6642 				 "all");
6643 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6644 	TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6645 			      UINT16);
6646 cmdline_parse_token_string_t cmd_setpromisc_mode =
6647 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6648 				 "on#off");
6649 
6650 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6651 	.f = cmd_set_promisc_mode_parsed,
6652 	.data = (void *)1,
6653 	.help_str = "set promisc all on|off: Set promisc mode for all ports",
6654 	.tokens = {
6655 		(void *)&cmd_setpromisc_set,
6656 		(void *)&cmd_setpromisc_promisc,
6657 		(void *)&cmd_setpromisc_portall,
6658 		(void *)&cmd_setpromisc_mode,
6659 		NULL,
6660 	},
6661 };
6662 
6663 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6664 	.f = cmd_set_promisc_mode_parsed,
6665 	.data = (void *)0,
6666 	.help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6667 	.tokens = {
6668 		(void *)&cmd_setpromisc_set,
6669 		(void *)&cmd_setpromisc_promisc,
6670 		(void *)&cmd_setpromisc_portnum,
6671 		(void *)&cmd_setpromisc_mode,
6672 		NULL,
6673 	},
6674 };
6675 
6676 /* *** SET ALLMULTI MODE *** */
6677 struct cmd_set_allmulti_mode_result {
6678 	cmdline_fixed_string_t set;
6679 	cmdline_fixed_string_t allmulti;
6680 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6681 	uint16_t port_num;               /* valid if "allports" argument == 0 */
6682 	cmdline_fixed_string_t mode;
6683 };
6684 
6685 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6686 					__attribute__((unused)) struct cmdline *cl,
6687 					void *allports)
6688 {
6689 	struct cmd_set_allmulti_mode_result *res = parsed_result;
6690 	int enable;
6691 	portid_t i;
6692 
6693 	if (!strcmp(res->mode, "on"))
6694 		enable = 1;
6695 	else
6696 		enable = 0;
6697 
6698 	/* all ports */
6699 	if (allports) {
6700 		RTE_ETH_FOREACH_DEV(i) {
6701 			eth_set_allmulticast_mode(i, enable);
6702 		}
6703 	}
6704 	else {
6705 		eth_set_allmulticast_mode(res->port_num, enable);
6706 	}
6707 }
6708 
6709 cmdline_parse_token_string_t cmd_setallmulti_set =
6710 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6711 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6712 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6713 				 "allmulti");
6714 cmdline_parse_token_string_t cmd_setallmulti_portall =
6715 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6716 				 "all");
6717 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6718 	TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6719 			      UINT16);
6720 cmdline_parse_token_string_t cmd_setallmulti_mode =
6721 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6722 				 "on#off");
6723 
6724 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6725 	.f = cmd_set_allmulti_mode_parsed,
6726 	.data = (void *)1,
6727 	.help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6728 	.tokens = {
6729 		(void *)&cmd_setallmulti_set,
6730 		(void *)&cmd_setallmulti_allmulti,
6731 		(void *)&cmd_setallmulti_portall,
6732 		(void *)&cmd_setallmulti_mode,
6733 		NULL,
6734 	},
6735 };
6736 
6737 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6738 	.f = cmd_set_allmulti_mode_parsed,
6739 	.data = (void *)0,
6740 	.help_str = "set allmulti <port_id> on|off: "
6741 		"Set allmulti mode on port_id",
6742 	.tokens = {
6743 		(void *)&cmd_setallmulti_set,
6744 		(void *)&cmd_setallmulti_allmulti,
6745 		(void *)&cmd_setallmulti_portnum,
6746 		(void *)&cmd_setallmulti_mode,
6747 		NULL,
6748 	},
6749 };
6750 
6751 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6752 struct cmd_link_flow_ctrl_set_result {
6753 	cmdline_fixed_string_t set;
6754 	cmdline_fixed_string_t flow_ctrl;
6755 	cmdline_fixed_string_t rx;
6756 	cmdline_fixed_string_t rx_lfc_mode;
6757 	cmdline_fixed_string_t tx;
6758 	cmdline_fixed_string_t tx_lfc_mode;
6759 	cmdline_fixed_string_t mac_ctrl_frame_fwd;
6760 	cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6761 	cmdline_fixed_string_t autoneg_str;
6762 	cmdline_fixed_string_t autoneg;
6763 	cmdline_fixed_string_t hw_str;
6764 	uint32_t high_water;
6765 	cmdline_fixed_string_t lw_str;
6766 	uint32_t low_water;
6767 	cmdline_fixed_string_t pt_str;
6768 	uint16_t pause_time;
6769 	cmdline_fixed_string_t xon_str;
6770 	uint16_t send_xon;
6771 	portid_t port_id;
6772 };
6773 
6774 cmdline_parse_token_string_t cmd_lfc_set_set =
6775 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6776 				set, "set");
6777 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6778 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6779 				flow_ctrl, "flow_ctrl");
6780 cmdline_parse_token_string_t cmd_lfc_set_rx =
6781 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6782 				rx, "rx");
6783 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6784 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6785 				rx_lfc_mode, "on#off");
6786 cmdline_parse_token_string_t cmd_lfc_set_tx =
6787 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6788 				tx, "tx");
6789 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6790 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6791 				tx_lfc_mode, "on#off");
6792 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6793 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6794 				hw_str, "high_water");
6795 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6796 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6797 				high_water, UINT32);
6798 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6799 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6800 				lw_str, "low_water");
6801 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6802 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6803 				low_water, UINT32);
6804 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6805 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6806 				pt_str, "pause_time");
6807 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6808 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6809 				pause_time, UINT16);
6810 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6811 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6812 				xon_str, "send_xon");
6813 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6814 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6815 				send_xon, UINT16);
6816 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6817 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6818 				mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6819 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6820 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6821 				mac_ctrl_frame_fwd_mode, "on#off");
6822 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6823 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6824 				autoneg_str, "autoneg");
6825 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6826 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6827 				autoneg, "on#off");
6828 cmdline_parse_token_num_t cmd_lfc_set_portid =
6829 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6830 				port_id, UINT16);
6831 
6832 /* forward declaration */
6833 static void
6834 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6835 			      void *data);
6836 
6837 cmdline_parse_inst_t cmd_link_flow_control_set = {
6838 	.f = cmd_link_flow_ctrl_set_parsed,
6839 	.data = NULL,
6840 	.help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6841 		"<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6842 		"autoneg on|off <port_id>: Configure the Ethernet flow control",
6843 	.tokens = {
6844 		(void *)&cmd_lfc_set_set,
6845 		(void *)&cmd_lfc_set_flow_ctrl,
6846 		(void *)&cmd_lfc_set_rx,
6847 		(void *)&cmd_lfc_set_rx_mode,
6848 		(void *)&cmd_lfc_set_tx,
6849 		(void *)&cmd_lfc_set_tx_mode,
6850 		(void *)&cmd_lfc_set_high_water,
6851 		(void *)&cmd_lfc_set_low_water,
6852 		(void *)&cmd_lfc_set_pause_time,
6853 		(void *)&cmd_lfc_set_send_xon,
6854 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6855 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6856 		(void *)&cmd_lfc_set_autoneg_str,
6857 		(void *)&cmd_lfc_set_autoneg,
6858 		(void *)&cmd_lfc_set_portid,
6859 		NULL,
6860 	},
6861 };
6862 
6863 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6864 	.f = cmd_link_flow_ctrl_set_parsed,
6865 	.data = (void *)&cmd_link_flow_control_set_rx,
6866 	.help_str = "set flow_ctrl rx on|off <port_id>: "
6867 		"Change rx flow control parameter",
6868 	.tokens = {
6869 		(void *)&cmd_lfc_set_set,
6870 		(void *)&cmd_lfc_set_flow_ctrl,
6871 		(void *)&cmd_lfc_set_rx,
6872 		(void *)&cmd_lfc_set_rx_mode,
6873 		(void *)&cmd_lfc_set_portid,
6874 		NULL,
6875 	},
6876 };
6877 
6878 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6879 	.f = cmd_link_flow_ctrl_set_parsed,
6880 	.data = (void *)&cmd_link_flow_control_set_tx,
6881 	.help_str = "set flow_ctrl tx on|off <port_id>: "
6882 		"Change tx flow control parameter",
6883 	.tokens = {
6884 		(void *)&cmd_lfc_set_set,
6885 		(void *)&cmd_lfc_set_flow_ctrl,
6886 		(void *)&cmd_lfc_set_tx,
6887 		(void *)&cmd_lfc_set_tx_mode,
6888 		(void *)&cmd_lfc_set_portid,
6889 		NULL,
6890 	},
6891 };
6892 
6893 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6894 	.f = cmd_link_flow_ctrl_set_parsed,
6895 	.data = (void *)&cmd_link_flow_control_set_hw,
6896 	.help_str = "set flow_ctrl high_water <value> <port_id>: "
6897 		"Change high water flow control parameter",
6898 	.tokens = {
6899 		(void *)&cmd_lfc_set_set,
6900 		(void *)&cmd_lfc_set_flow_ctrl,
6901 		(void *)&cmd_lfc_set_high_water_str,
6902 		(void *)&cmd_lfc_set_high_water,
6903 		(void *)&cmd_lfc_set_portid,
6904 		NULL,
6905 	},
6906 };
6907 
6908 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6909 	.f = cmd_link_flow_ctrl_set_parsed,
6910 	.data = (void *)&cmd_link_flow_control_set_lw,
6911 	.help_str = "set flow_ctrl low_water <value> <port_id>: "
6912 		"Change low water flow control parameter",
6913 	.tokens = {
6914 		(void *)&cmd_lfc_set_set,
6915 		(void *)&cmd_lfc_set_flow_ctrl,
6916 		(void *)&cmd_lfc_set_low_water_str,
6917 		(void *)&cmd_lfc_set_low_water,
6918 		(void *)&cmd_lfc_set_portid,
6919 		NULL,
6920 	},
6921 };
6922 
6923 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6924 	.f = cmd_link_flow_ctrl_set_parsed,
6925 	.data = (void *)&cmd_link_flow_control_set_pt,
6926 	.help_str = "set flow_ctrl pause_time <value> <port_id>: "
6927 		"Change pause time flow control parameter",
6928 	.tokens = {
6929 		(void *)&cmd_lfc_set_set,
6930 		(void *)&cmd_lfc_set_flow_ctrl,
6931 		(void *)&cmd_lfc_set_pause_time_str,
6932 		(void *)&cmd_lfc_set_pause_time,
6933 		(void *)&cmd_lfc_set_portid,
6934 		NULL,
6935 	},
6936 };
6937 
6938 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6939 	.f = cmd_link_flow_ctrl_set_parsed,
6940 	.data = (void *)&cmd_link_flow_control_set_xon,
6941 	.help_str = "set flow_ctrl send_xon <value> <port_id>: "
6942 		"Change send_xon flow control parameter",
6943 	.tokens = {
6944 		(void *)&cmd_lfc_set_set,
6945 		(void *)&cmd_lfc_set_flow_ctrl,
6946 		(void *)&cmd_lfc_set_send_xon_str,
6947 		(void *)&cmd_lfc_set_send_xon,
6948 		(void *)&cmd_lfc_set_portid,
6949 		NULL,
6950 	},
6951 };
6952 
6953 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6954 	.f = cmd_link_flow_ctrl_set_parsed,
6955 	.data = (void *)&cmd_link_flow_control_set_macfwd,
6956 	.help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6957 		"Change mac ctrl fwd flow control parameter",
6958 	.tokens = {
6959 		(void *)&cmd_lfc_set_set,
6960 		(void *)&cmd_lfc_set_flow_ctrl,
6961 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6962 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6963 		(void *)&cmd_lfc_set_portid,
6964 		NULL,
6965 	},
6966 };
6967 
6968 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6969 	.f = cmd_link_flow_ctrl_set_parsed,
6970 	.data = (void *)&cmd_link_flow_control_set_autoneg,
6971 	.help_str = "set flow_ctrl autoneg on|off <port_id>: "
6972 		"Change autoneg flow control parameter",
6973 	.tokens = {
6974 		(void *)&cmd_lfc_set_set,
6975 		(void *)&cmd_lfc_set_flow_ctrl,
6976 		(void *)&cmd_lfc_set_autoneg_str,
6977 		(void *)&cmd_lfc_set_autoneg,
6978 		(void *)&cmd_lfc_set_portid,
6979 		NULL,
6980 	},
6981 };
6982 
6983 static void
6984 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6985 			      __attribute__((unused)) struct cmdline *cl,
6986 			      void *data)
6987 {
6988 	struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6989 	cmdline_parse_inst_t *cmd = data;
6990 	struct rte_eth_fc_conf fc_conf;
6991 	int rx_fc_en = 0;
6992 	int tx_fc_en = 0;
6993 	int ret;
6994 
6995 	/*
6996 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6997 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6998 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6999 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7000 	 */
7001 	static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7002 			{RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7003 	};
7004 
7005 	/* Partial command line, retrieve current configuration */
7006 	if (cmd) {
7007 		ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7008 		if (ret != 0) {
7009 			printf("cannot get current flow ctrl parameters, return"
7010 			       "code = %d\n", ret);
7011 			return;
7012 		}
7013 
7014 		if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7015 		    (fc_conf.mode == RTE_FC_FULL))
7016 			rx_fc_en = 1;
7017 		if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7018 		    (fc_conf.mode == RTE_FC_FULL))
7019 			tx_fc_en = 1;
7020 	}
7021 
7022 	if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7023 		rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7024 
7025 	if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7026 		tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7027 
7028 	fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7029 
7030 	if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7031 		fc_conf.high_water = res->high_water;
7032 
7033 	if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7034 		fc_conf.low_water = res->low_water;
7035 
7036 	if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7037 		fc_conf.pause_time = res->pause_time;
7038 
7039 	if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7040 		fc_conf.send_xon = res->send_xon;
7041 
7042 	if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7043 		if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7044 			fc_conf.mac_ctrl_frame_fwd = 1;
7045 		else
7046 			fc_conf.mac_ctrl_frame_fwd = 0;
7047 	}
7048 
7049 	if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7050 		fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7051 
7052 	ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7053 	if (ret != 0)
7054 		printf("bad flow contrl parameter, return code = %d \n", ret);
7055 }
7056 
7057 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7058 struct cmd_priority_flow_ctrl_set_result {
7059 	cmdline_fixed_string_t set;
7060 	cmdline_fixed_string_t pfc_ctrl;
7061 	cmdline_fixed_string_t rx;
7062 	cmdline_fixed_string_t rx_pfc_mode;
7063 	cmdline_fixed_string_t tx;
7064 	cmdline_fixed_string_t tx_pfc_mode;
7065 	uint32_t high_water;
7066 	uint32_t low_water;
7067 	uint16_t pause_time;
7068 	uint8_t  priority;
7069 	portid_t port_id;
7070 };
7071 
7072 static void
7073 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7074 		       __attribute__((unused)) struct cmdline *cl,
7075 		       __attribute__((unused)) void *data)
7076 {
7077 	struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7078 	struct rte_eth_pfc_conf pfc_conf;
7079 	int rx_fc_enable, tx_fc_enable;
7080 	int ret;
7081 
7082 	/*
7083 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7084 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7085 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7086 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7087 	 */
7088 	static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7089 		{RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7090 	};
7091 
7092 	memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7093 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7094 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7095 	pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7096 	pfc_conf.fc.high_water = res->high_water;
7097 	pfc_conf.fc.low_water  = res->low_water;
7098 	pfc_conf.fc.pause_time = res->pause_time;
7099 	pfc_conf.priority      = res->priority;
7100 
7101 	ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7102 	if (ret != 0)
7103 		printf("bad priority flow contrl parameter, return code = %d \n", ret);
7104 }
7105 
7106 cmdline_parse_token_string_t cmd_pfc_set_set =
7107 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7108 				set, "set");
7109 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7110 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7111 				pfc_ctrl, "pfc_ctrl");
7112 cmdline_parse_token_string_t cmd_pfc_set_rx =
7113 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7114 				rx, "rx");
7115 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7116 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7117 				rx_pfc_mode, "on#off");
7118 cmdline_parse_token_string_t cmd_pfc_set_tx =
7119 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7120 				tx, "tx");
7121 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7122 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7123 				tx_pfc_mode, "on#off");
7124 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7125 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7126 				high_water, UINT32);
7127 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7128 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7129 				low_water, UINT32);
7130 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7131 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7132 				pause_time, UINT16);
7133 cmdline_parse_token_num_t cmd_pfc_set_priority =
7134 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7135 				priority, UINT8);
7136 cmdline_parse_token_num_t cmd_pfc_set_portid =
7137 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7138 				port_id, UINT16);
7139 
7140 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7141 	.f = cmd_priority_flow_ctrl_set_parsed,
7142 	.data = NULL,
7143 	.help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7144 		"<pause_time> <priority> <port_id>: "
7145 		"Configure the Ethernet priority flow control",
7146 	.tokens = {
7147 		(void *)&cmd_pfc_set_set,
7148 		(void *)&cmd_pfc_set_flow_ctrl,
7149 		(void *)&cmd_pfc_set_rx,
7150 		(void *)&cmd_pfc_set_rx_mode,
7151 		(void *)&cmd_pfc_set_tx,
7152 		(void *)&cmd_pfc_set_tx_mode,
7153 		(void *)&cmd_pfc_set_high_water,
7154 		(void *)&cmd_pfc_set_low_water,
7155 		(void *)&cmd_pfc_set_pause_time,
7156 		(void *)&cmd_pfc_set_priority,
7157 		(void *)&cmd_pfc_set_portid,
7158 		NULL,
7159 	},
7160 };
7161 
7162 /* *** RESET CONFIGURATION *** */
7163 struct cmd_reset_result {
7164 	cmdline_fixed_string_t reset;
7165 	cmdline_fixed_string_t def;
7166 };
7167 
7168 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7169 			     struct cmdline *cl,
7170 			     __attribute__((unused)) void *data)
7171 {
7172 	cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7173 	set_def_fwd_config();
7174 }
7175 
7176 cmdline_parse_token_string_t cmd_reset_set =
7177 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7178 cmdline_parse_token_string_t cmd_reset_def =
7179 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7180 				 "default");
7181 
7182 cmdline_parse_inst_t cmd_reset = {
7183 	.f = cmd_reset_parsed,
7184 	.data = NULL,
7185 	.help_str = "set default: Reset default forwarding configuration",
7186 	.tokens = {
7187 		(void *)&cmd_reset_set,
7188 		(void *)&cmd_reset_def,
7189 		NULL,
7190 	},
7191 };
7192 
7193 /* *** START FORWARDING *** */
7194 struct cmd_start_result {
7195 	cmdline_fixed_string_t start;
7196 };
7197 
7198 cmdline_parse_token_string_t cmd_start_start =
7199 	TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7200 
7201 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7202 			     __attribute__((unused)) struct cmdline *cl,
7203 			     __attribute__((unused)) void *data)
7204 {
7205 	start_packet_forwarding(0);
7206 }
7207 
7208 cmdline_parse_inst_t cmd_start = {
7209 	.f = cmd_start_parsed,
7210 	.data = NULL,
7211 	.help_str = "start: Start packet forwarding",
7212 	.tokens = {
7213 		(void *)&cmd_start_start,
7214 		NULL,
7215 	},
7216 };
7217 
7218 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7219 struct cmd_start_tx_first_result {
7220 	cmdline_fixed_string_t start;
7221 	cmdline_fixed_string_t tx_first;
7222 };
7223 
7224 static void
7225 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7226 			  __attribute__((unused)) struct cmdline *cl,
7227 			  __attribute__((unused)) void *data)
7228 {
7229 	start_packet_forwarding(1);
7230 }
7231 
7232 cmdline_parse_token_string_t cmd_start_tx_first_start =
7233 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7234 				 "start");
7235 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7236 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7237 				 tx_first, "tx_first");
7238 
7239 cmdline_parse_inst_t cmd_start_tx_first = {
7240 	.f = cmd_start_tx_first_parsed,
7241 	.data = NULL,
7242 	.help_str = "start tx_first: Start packet forwarding, "
7243 		"after sending 1 burst of packets",
7244 	.tokens = {
7245 		(void *)&cmd_start_tx_first_start,
7246 		(void *)&cmd_start_tx_first_tx_first,
7247 		NULL,
7248 	},
7249 };
7250 
7251 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7252 struct cmd_start_tx_first_n_result {
7253 	cmdline_fixed_string_t start;
7254 	cmdline_fixed_string_t tx_first;
7255 	uint32_t tx_num;
7256 };
7257 
7258 static void
7259 cmd_start_tx_first_n_parsed(void *parsed_result,
7260 			  __attribute__((unused)) struct cmdline *cl,
7261 			  __attribute__((unused)) void *data)
7262 {
7263 	struct cmd_start_tx_first_n_result *res = parsed_result;
7264 
7265 	start_packet_forwarding(res->tx_num);
7266 }
7267 
7268 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7269 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7270 			start, "start");
7271 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7272 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7273 			tx_first, "tx_first");
7274 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7275 	TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7276 			tx_num, UINT32);
7277 
7278 cmdline_parse_inst_t cmd_start_tx_first_n = {
7279 	.f = cmd_start_tx_first_n_parsed,
7280 	.data = NULL,
7281 	.help_str = "start tx_first <num>: "
7282 		"packet forwarding, after sending <num> bursts of packets",
7283 	.tokens = {
7284 		(void *)&cmd_start_tx_first_n_start,
7285 		(void *)&cmd_start_tx_first_n_tx_first,
7286 		(void *)&cmd_start_tx_first_n_tx_num,
7287 		NULL,
7288 	},
7289 };
7290 
7291 /* *** SET LINK UP *** */
7292 struct cmd_set_link_up_result {
7293 	cmdline_fixed_string_t set;
7294 	cmdline_fixed_string_t link_up;
7295 	cmdline_fixed_string_t port;
7296 	portid_t port_id;
7297 };
7298 
7299 cmdline_parse_token_string_t cmd_set_link_up_set =
7300 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7301 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7302 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7303 				"link-up");
7304 cmdline_parse_token_string_t cmd_set_link_up_port =
7305 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7306 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7307 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7308 
7309 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7310 			     __attribute__((unused)) struct cmdline *cl,
7311 			     __attribute__((unused)) void *data)
7312 {
7313 	struct cmd_set_link_up_result *res = parsed_result;
7314 	dev_set_link_up(res->port_id);
7315 }
7316 
7317 cmdline_parse_inst_t cmd_set_link_up = {
7318 	.f = cmd_set_link_up_parsed,
7319 	.data = NULL,
7320 	.help_str = "set link-up port <port id>",
7321 	.tokens = {
7322 		(void *)&cmd_set_link_up_set,
7323 		(void *)&cmd_set_link_up_link_up,
7324 		(void *)&cmd_set_link_up_port,
7325 		(void *)&cmd_set_link_up_port_id,
7326 		NULL,
7327 	},
7328 };
7329 
7330 /* *** SET LINK DOWN *** */
7331 struct cmd_set_link_down_result {
7332 	cmdline_fixed_string_t set;
7333 	cmdline_fixed_string_t link_down;
7334 	cmdline_fixed_string_t port;
7335 	portid_t port_id;
7336 };
7337 
7338 cmdline_parse_token_string_t cmd_set_link_down_set =
7339 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7340 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7341 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7342 				"link-down");
7343 cmdline_parse_token_string_t cmd_set_link_down_port =
7344 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7345 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7346 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7347 
7348 static void cmd_set_link_down_parsed(
7349 				__attribute__((unused)) void *parsed_result,
7350 				__attribute__((unused)) struct cmdline *cl,
7351 				__attribute__((unused)) void *data)
7352 {
7353 	struct cmd_set_link_down_result *res = parsed_result;
7354 	dev_set_link_down(res->port_id);
7355 }
7356 
7357 cmdline_parse_inst_t cmd_set_link_down = {
7358 	.f = cmd_set_link_down_parsed,
7359 	.data = NULL,
7360 	.help_str = "set link-down port <port id>",
7361 	.tokens = {
7362 		(void *)&cmd_set_link_down_set,
7363 		(void *)&cmd_set_link_down_link_down,
7364 		(void *)&cmd_set_link_down_port,
7365 		(void *)&cmd_set_link_down_port_id,
7366 		NULL,
7367 	},
7368 };
7369 
7370 /* *** SHOW CFG *** */
7371 struct cmd_showcfg_result {
7372 	cmdline_fixed_string_t show;
7373 	cmdline_fixed_string_t cfg;
7374 	cmdline_fixed_string_t what;
7375 };
7376 
7377 static void cmd_showcfg_parsed(void *parsed_result,
7378 			       __attribute__((unused)) struct cmdline *cl,
7379 			       __attribute__((unused)) void *data)
7380 {
7381 	struct cmd_showcfg_result *res = parsed_result;
7382 	if (!strcmp(res->what, "rxtx"))
7383 		rxtx_config_display();
7384 	else if (!strcmp(res->what, "cores"))
7385 		fwd_lcores_config_display();
7386 	else if (!strcmp(res->what, "fwd"))
7387 		pkt_fwd_config_display(&cur_fwd_config);
7388 	else if (!strcmp(res->what, "txpkts"))
7389 		show_tx_pkt_segments();
7390 }
7391 
7392 cmdline_parse_token_string_t cmd_showcfg_show =
7393 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7394 cmdline_parse_token_string_t cmd_showcfg_port =
7395 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7396 cmdline_parse_token_string_t cmd_showcfg_what =
7397 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7398 				 "rxtx#cores#fwd#txpkts");
7399 
7400 cmdline_parse_inst_t cmd_showcfg = {
7401 	.f = cmd_showcfg_parsed,
7402 	.data = NULL,
7403 	.help_str = "show config rxtx|cores|fwd|txpkts",
7404 	.tokens = {
7405 		(void *)&cmd_showcfg_show,
7406 		(void *)&cmd_showcfg_port,
7407 		(void *)&cmd_showcfg_what,
7408 		NULL,
7409 	},
7410 };
7411 
7412 /* *** SHOW ALL PORT INFO *** */
7413 struct cmd_showportall_result {
7414 	cmdline_fixed_string_t show;
7415 	cmdline_fixed_string_t port;
7416 	cmdline_fixed_string_t what;
7417 	cmdline_fixed_string_t all;
7418 };
7419 
7420 static void cmd_showportall_parsed(void *parsed_result,
7421 				__attribute__((unused)) struct cmdline *cl,
7422 				__attribute__((unused)) void *data)
7423 {
7424 	portid_t i;
7425 
7426 	struct cmd_showportall_result *res = parsed_result;
7427 	if (!strcmp(res->show, "clear")) {
7428 		if (!strcmp(res->what, "stats"))
7429 			RTE_ETH_FOREACH_DEV(i)
7430 				nic_stats_clear(i);
7431 		else if (!strcmp(res->what, "xstats"))
7432 			RTE_ETH_FOREACH_DEV(i)
7433 				nic_xstats_clear(i);
7434 	} else if (!strcmp(res->what, "info"))
7435 		RTE_ETH_FOREACH_DEV(i)
7436 			port_infos_display(i);
7437 	else if (!strcmp(res->what, "summary")) {
7438 		port_summary_header_display();
7439 		RTE_ETH_FOREACH_DEV(i)
7440 			port_summary_display(i);
7441 	}
7442 	else if (!strcmp(res->what, "stats"))
7443 		RTE_ETH_FOREACH_DEV(i)
7444 			nic_stats_display(i);
7445 	else if (!strcmp(res->what, "xstats"))
7446 		RTE_ETH_FOREACH_DEV(i)
7447 			nic_xstats_display(i);
7448 	else if (!strcmp(res->what, "fdir"))
7449 		RTE_ETH_FOREACH_DEV(i)
7450 			fdir_get_infos(i);
7451 	else if (!strcmp(res->what, "stat_qmap"))
7452 		RTE_ETH_FOREACH_DEV(i)
7453 			nic_stats_mapping_display(i);
7454 	else if (!strcmp(res->what, "dcb_tc"))
7455 		RTE_ETH_FOREACH_DEV(i)
7456 			port_dcb_info_display(i);
7457 	else if (!strcmp(res->what, "cap"))
7458 		RTE_ETH_FOREACH_DEV(i)
7459 			port_offload_cap_display(i);
7460 }
7461 
7462 cmdline_parse_token_string_t cmd_showportall_show =
7463 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7464 				 "show#clear");
7465 cmdline_parse_token_string_t cmd_showportall_port =
7466 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7467 cmdline_parse_token_string_t cmd_showportall_what =
7468 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7469 				 "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7470 cmdline_parse_token_string_t cmd_showportall_all =
7471 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7472 cmdline_parse_inst_t cmd_showportall = {
7473 	.f = cmd_showportall_parsed,
7474 	.data = NULL,
7475 	.help_str = "show|clear port "
7476 		"info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7477 	.tokens = {
7478 		(void *)&cmd_showportall_show,
7479 		(void *)&cmd_showportall_port,
7480 		(void *)&cmd_showportall_what,
7481 		(void *)&cmd_showportall_all,
7482 		NULL,
7483 	},
7484 };
7485 
7486 /* *** SHOW PORT INFO *** */
7487 struct cmd_showport_result {
7488 	cmdline_fixed_string_t show;
7489 	cmdline_fixed_string_t port;
7490 	cmdline_fixed_string_t what;
7491 	uint16_t portnum;
7492 };
7493 
7494 static void cmd_showport_parsed(void *parsed_result,
7495 				__attribute__((unused)) struct cmdline *cl,
7496 				__attribute__((unused)) void *data)
7497 {
7498 	struct cmd_showport_result *res = parsed_result;
7499 	if (!strcmp(res->show, "clear")) {
7500 		if (!strcmp(res->what, "stats"))
7501 			nic_stats_clear(res->portnum);
7502 		else if (!strcmp(res->what, "xstats"))
7503 			nic_xstats_clear(res->portnum);
7504 	} else if (!strcmp(res->what, "info"))
7505 		port_infos_display(res->portnum);
7506 	else if (!strcmp(res->what, "summary")) {
7507 		port_summary_header_display();
7508 		port_summary_display(res->portnum);
7509 	}
7510 	else if (!strcmp(res->what, "stats"))
7511 		nic_stats_display(res->portnum);
7512 	else if (!strcmp(res->what, "xstats"))
7513 		nic_xstats_display(res->portnum);
7514 	else if (!strcmp(res->what, "fdir"))
7515 		 fdir_get_infos(res->portnum);
7516 	else if (!strcmp(res->what, "stat_qmap"))
7517 		nic_stats_mapping_display(res->portnum);
7518 	else if (!strcmp(res->what, "dcb_tc"))
7519 		port_dcb_info_display(res->portnum);
7520 	else if (!strcmp(res->what, "cap"))
7521 		port_offload_cap_display(res->portnum);
7522 }
7523 
7524 cmdline_parse_token_string_t cmd_showport_show =
7525 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7526 				 "show#clear");
7527 cmdline_parse_token_string_t cmd_showport_port =
7528 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7529 cmdline_parse_token_string_t cmd_showport_what =
7530 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7531 				 "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7532 cmdline_parse_token_num_t cmd_showport_portnum =
7533 	TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7534 
7535 cmdline_parse_inst_t cmd_showport = {
7536 	.f = cmd_showport_parsed,
7537 	.data = NULL,
7538 	.help_str = "show|clear port "
7539 		"info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7540 		"<port_id>",
7541 	.tokens = {
7542 		(void *)&cmd_showport_show,
7543 		(void *)&cmd_showport_port,
7544 		(void *)&cmd_showport_what,
7545 		(void *)&cmd_showport_portnum,
7546 		NULL,
7547 	},
7548 };
7549 
7550 /* *** SHOW DEVICE INFO *** */
7551 struct cmd_showdevice_result {
7552 	cmdline_fixed_string_t show;
7553 	cmdline_fixed_string_t device;
7554 	cmdline_fixed_string_t what;
7555 	cmdline_fixed_string_t identifier;
7556 };
7557 
7558 static void cmd_showdevice_parsed(void *parsed_result,
7559 				__attribute__((unused)) struct cmdline *cl,
7560 				__attribute__((unused)) void *data)
7561 {
7562 	struct cmd_showdevice_result *res = parsed_result;
7563 	if (!strcmp(res->what, "info")) {
7564 		if (!strcmp(res->identifier, "all"))
7565 			device_infos_display(NULL);
7566 		else
7567 			device_infos_display(res->identifier);
7568 	}
7569 }
7570 
7571 cmdline_parse_token_string_t cmd_showdevice_show =
7572 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7573 				 "show");
7574 cmdline_parse_token_string_t cmd_showdevice_device =
7575 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7576 cmdline_parse_token_string_t cmd_showdevice_what =
7577 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7578 				 "info");
7579 cmdline_parse_token_string_t cmd_showdevice_identifier =
7580 	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7581 			identifier, NULL);
7582 
7583 cmdline_parse_inst_t cmd_showdevice = {
7584 	.f = cmd_showdevice_parsed,
7585 	.data = NULL,
7586 	.help_str = "show device info <identifier>|all",
7587 	.tokens = {
7588 		(void *)&cmd_showdevice_show,
7589 		(void *)&cmd_showdevice_device,
7590 		(void *)&cmd_showdevice_what,
7591 		(void *)&cmd_showdevice_identifier,
7592 		NULL,
7593 	},
7594 };
7595 /* *** SHOW QUEUE INFO *** */
7596 struct cmd_showqueue_result {
7597 	cmdline_fixed_string_t show;
7598 	cmdline_fixed_string_t type;
7599 	cmdline_fixed_string_t what;
7600 	uint16_t portnum;
7601 	uint16_t queuenum;
7602 };
7603 
7604 static void
7605 cmd_showqueue_parsed(void *parsed_result,
7606 	__attribute__((unused)) struct cmdline *cl,
7607 	__attribute__((unused)) void *data)
7608 {
7609 	struct cmd_showqueue_result *res = parsed_result;
7610 
7611 	if (!strcmp(res->type, "rxq"))
7612 		rx_queue_infos_display(res->portnum, res->queuenum);
7613 	else if (!strcmp(res->type, "txq"))
7614 		tx_queue_infos_display(res->portnum, res->queuenum);
7615 }
7616 
7617 cmdline_parse_token_string_t cmd_showqueue_show =
7618 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7619 cmdline_parse_token_string_t cmd_showqueue_type =
7620 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7621 cmdline_parse_token_string_t cmd_showqueue_what =
7622 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7623 cmdline_parse_token_num_t cmd_showqueue_portnum =
7624 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7625 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7626 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7627 
7628 cmdline_parse_inst_t cmd_showqueue = {
7629 	.f = cmd_showqueue_parsed,
7630 	.data = NULL,
7631 	.help_str = "show rxq|txq info <port_id> <queue_id>",
7632 	.tokens = {
7633 		(void *)&cmd_showqueue_show,
7634 		(void *)&cmd_showqueue_type,
7635 		(void *)&cmd_showqueue_what,
7636 		(void *)&cmd_showqueue_portnum,
7637 		(void *)&cmd_showqueue_queuenum,
7638 		NULL,
7639 	},
7640 };
7641 
7642 /* show/clear fwd engine statistics */
7643 struct fwd_result {
7644 	cmdline_fixed_string_t action;
7645 	cmdline_fixed_string_t fwd;
7646 	cmdline_fixed_string_t stats;
7647 	cmdline_fixed_string_t all;
7648 };
7649 
7650 cmdline_parse_token_string_t cmd_fwd_action =
7651 	TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7652 cmdline_parse_token_string_t cmd_fwd_fwd =
7653 	TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7654 cmdline_parse_token_string_t cmd_fwd_stats =
7655 	TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7656 cmdline_parse_token_string_t cmd_fwd_all =
7657 	TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7658 
7659 static void
7660 cmd_showfwdall_parsed(void *parsed_result,
7661 		      __rte_unused struct cmdline *cl,
7662 		      __rte_unused void *data)
7663 {
7664 	struct fwd_result *res = parsed_result;
7665 
7666 	if (!strcmp(res->action, "show"))
7667 		fwd_stats_display();
7668 	else
7669 		fwd_stats_reset();
7670 }
7671 
7672 static cmdline_parse_inst_t cmd_showfwdall = {
7673 	.f = cmd_showfwdall_parsed,
7674 	.data = NULL,
7675 	.help_str = "show|clear fwd stats all",
7676 	.tokens = {
7677 		(void *)&cmd_fwd_action,
7678 		(void *)&cmd_fwd_fwd,
7679 		(void *)&cmd_fwd_stats,
7680 		(void *)&cmd_fwd_all,
7681 		NULL,
7682 	},
7683 };
7684 
7685 /* *** READ PORT REGISTER *** */
7686 struct cmd_read_reg_result {
7687 	cmdline_fixed_string_t read;
7688 	cmdline_fixed_string_t reg;
7689 	portid_t port_id;
7690 	uint32_t reg_off;
7691 };
7692 
7693 static void
7694 cmd_read_reg_parsed(void *parsed_result,
7695 		    __attribute__((unused)) struct cmdline *cl,
7696 		    __attribute__((unused)) void *data)
7697 {
7698 	struct cmd_read_reg_result *res = parsed_result;
7699 	port_reg_display(res->port_id, res->reg_off);
7700 }
7701 
7702 cmdline_parse_token_string_t cmd_read_reg_read =
7703 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7704 cmdline_parse_token_string_t cmd_read_reg_reg =
7705 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7706 cmdline_parse_token_num_t cmd_read_reg_port_id =
7707 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7708 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7709 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7710 
7711 cmdline_parse_inst_t cmd_read_reg = {
7712 	.f = cmd_read_reg_parsed,
7713 	.data = NULL,
7714 	.help_str = "read reg <port_id> <reg_off>",
7715 	.tokens = {
7716 		(void *)&cmd_read_reg_read,
7717 		(void *)&cmd_read_reg_reg,
7718 		(void *)&cmd_read_reg_port_id,
7719 		(void *)&cmd_read_reg_reg_off,
7720 		NULL,
7721 	},
7722 };
7723 
7724 /* *** READ PORT REGISTER BIT FIELD *** */
7725 struct cmd_read_reg_bit_field_result {
7726 	cmdline_fixed_string_t read;
7727 	cmdline_fixed_string_t regfield;
7728 	portid_t port_id;
7729 	uint32_t reg_off;
7730 	uint8_t bit1_pos;
7731 	uint8_t bit2_pos;
7732 };
7733 
7734 static void
7735 cmd_read_reg_bit_field_parsed(void *parsed_result,
7736 			      __attribute__((unused)) struct cmdline *cl,
7737 			      __attribute__((unused)) void *data)
7738 {
7739 	struct cmd_read_reg_bit_field_result *res = parsed_result;
7740 	port_reg_bit_field_display(res->port_id, res->reg_off,
7741 				   res->bit1_pos, res->bit2_pos);
7742 }
7743 
7744 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7745 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7746 				 "read");
7747 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7748 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7749 				 regfield, "regfield");
7750 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7751 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7752 			      UINT16);
7753 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7754 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7755 			      UINT32);
7756 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7757 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7758 			      UINT8);
7759 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7760 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7761 			      UINT8);
7762 
7763 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7764 	.f = cmd_read_reg_bit_field_parsed,
7765 	.data = NULL,
7766 	.help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7767 	"Read register bit field between bit_x and bit_y included",
7768 	.tokens = {
7769 		(void *)&cmd_read_reg_bit_field_read,
7770 		(void *)&cmd_read_reg_bit_field_regfield,
7771 		(void *)&cmd_read_reg_bit_field_port_id,
7772 		(void *)&cmd_read_reg_bit_field_reg_off,
7773 		(void *)&cmd_read_reg_bit_field_bit1_pos,
7774 		(void *)&cmd_read_reg_bit_field_bit2_pos,
7775 		NULL,
7776 	},
7777 };
7778 
7779 /* *** READ PORT REGISTER BIT *** */
7780 struct cmd_read_reg_bit_result {
7781 	cmdline_fixed_string_t read;
7782 	cmdline_fixed_string_t regbit;
7783 	portid_t port_id;
7784 	uint32_t reg_off;
7785 	uint8_t bit_pos;
7786 };
7787 
7788 static void
7789 cmd_read_reg_bit_parsed(void *parsed_result,
7790 			__attribute__((unused)) struct cmdline *cl,
7791 			__attribute__((unused)) void *data)
7792 {
7793 	struct cmd_read_reg_bit_result *res = parsed_result;
7794 	port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7795 }
7796 
7797 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7798 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7799 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7800 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7801 				 regbit, "regbit");
7802 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7803 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7804 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7805 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7806 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7807 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7808 
7809 cmdline_parse_inst_t cmd_read_reg_bit = {
7810 	.f = cmd_read_reg_bit_parsed,
7811 	.data = NULL,
7812 	.help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7813 	.tokens = {
7814 		(void *)&cmd_read_reg_bit_read,
7815 		(void *)&cmd_read_reg_bit_regbit,
7816 		(void *)&cmd_read_reg_bit_port_id,
7817 		(void *)&cmd_read_reg_bit_reg_off,
7818 		(void *)&cmd_read_reg_bit_bit_pos,
7819 		NULL,
7820 	},
7821 };
7822 
7823 /* *** WRITE PORT REGISTER *** */
7824 struct cmd_write_reg_result {
7825 	cmdline_fixed_string_t write;
7826 	cmdline_fixed_string_t reg;
7827 	portid_t port_id;
7828 	uint32_t reg_off;
7829 	uint32_t value;
7830 };
7831 
7832 static void
7833 cmd_write_reg_parsed(void *parsed_result,
7834 		     __attribute__((unused)) struct cmdline *cl,
7835 		     __attribute__((unused)) void *data)
7836 {
7837 	struct cmd_write_reg_result *res = parsed_result;
7838 	port_reg_set(res->port_id, res->reg_off, res->value);
7839 }
7840 
7841 cmdline_parse_token_string_t cmd_write_reg_write =
7842 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7843 cmdline_parse_token_string_t cmd_write_reg_reg =
7844 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7845 cmdline_parse_token_num_t cmd_write_reg_port_id =
7846 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7847 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7848 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7849 cmdline_parse_token_num_t cmd_write_reg_value =
7850 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7851 
7852 cmdline_parse_inst_t cmd_write_reg = {
7853 	.f = cmd_write_reg_parsed,
7854 	.data = NULL,
7855 	.help_str = "write reg <port_id> <reg_off> <reg_value>",
7856 	.tokens = {
7857 		(void *)&cmd_write_reg_write,
7858 		(void *)&cmd_write_reg_reg,
7859 		(void *)&cmd_write_reg_port_id,
7860 		(void *)&cmd_write_reg_reg_off,
7861 		(void *)&cmd_write_reg_value,
7862 		NULL,
7863 	},
7864 };
7865 
7866 /* *** WRITE PORT REGISTER BIT FIELD *** */
7867 struct cmd_write_reg_bit_field_result {
7868 	cmdline_fixed_string_t write;
7869 	cmdline_fixed_string_t regfield;
7870 	portid_t port_id;
7871 	uint32_t reg_off;
7872 	uint8_t bit1_pos;
7873 	uint8_t bit2_pos;
7874 	uint32_t value;
7875 };
7876 
7877 static void
7878 cmd_write_reg_bit_field_parsed(void *parsed_result,
7879 			       __attribute__((unused)) struct cmdline *cl,
7880 			       __attribute__((unused)) void *data)
7881 {
7882 	struct cmd_write_reg_bit_field_result *res = parsed_result;
7883 	port_reg_bit_field_set(res->port_id, res->reg_off,
7884 			  res->bit1_pos, res->bit2_pos, res->value);
7885 }
7886 
7887 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7888 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7889 				 "write");
7890 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7891 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7892 				 regfield, "regfield");
7893 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7894 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7895 			      UINT16);
7896 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7897 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7898 			      UINT32);
7899 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7900 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7901 			      UINT8);
7902 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7903 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7904 			      UINT8);
7905 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7906 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7907 			      UINT32);
7908 
7909 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7910 	.f = cmd_write_reg_bit_field_parsed,
7911 	.data = NULL,
7912 	.help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7913 		"<reg_value>: "
7914 		"Set register bit field between bit_x and bit_y included",
7915 	.tokens = {
7916 		(void *)&cmd_write_reg_bit_field_write,
7917 		(void *)&cmd_write_reg_bit_field_regfield,
7918 		(void *)&cmd_write_reg_bit_field_port_id,
7919 		(void *)&cmd_write_reg_bit_field_reg_off,
7920 		(void *)&cmd_write_reg_bit_field_bit1_pos,
7921 		(void *)&cmd_write_reg_bit_field_bit2_pos,
7922 		(void *)&cmd_write_reg_bit_field_value,
7923 		NULL,
7924 	},
7925 };
7926 
7927 /* *** WRITE PORT REGISTER BIT *** */
7928 struct cmd_write_reg_bit_result {
7929 	cmdline_fixed_string_t write;
7930 	cmdline_fixed_string_t regbit;
7931 	portid_t port_id;
7932 	uint32_t reg_off;
7933 	uint8_t bit_pos;
7934 	uint8_t value;
7935 };
7936 
7937 static void
7938 cmd_write_reg_bit_parsed(void *parsed_result,
7939 			 __attribute__((unused)) struct cmdline *cl,
7940 			 __attribute__((unused)) void *data)
7941 {
7942 	struct cmd_write_reg_bit_result *res = parsed_result;
7943 	port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7944 }
7945 
7946 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7947 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7948 				 "write");
7949 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7950 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7951 				 regbit, "regbit");
7952 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7953 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7954 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7955 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7956 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7957 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7958 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7959 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7960 
7961 cmdline_parse_inst_t cmd_write_reg_bit = {
7962 	.f = cmd_write_reg_bit_parsed,
7963 	.data = NULL,
7964 	.help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7965 		"0 <= bit_x <= 31",
7966 	.tokens = {
7967 		(void *)&cmd_write_reg_bit_write,
7968 		(void *)&cmd_write_reg_bit_regbit,
7969 		(void *)&cmd_write_reg_bit_port_id,
7970 		(void *)&cmd_write_reg_bit_reg_off,
7971 		(void *)&cmd_write_reg_bit_bit_pos,
7972 		(void *)&cmd_write_reg_bit_value,
7973 		NULL,
7974 	},
7975 };
7976 
7977 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7978 struct cmd_read_rxd_txd_result {
7979 	cmdline_fixed_string_t read;
7980 	cmdline_fixed_string_t rxd_txd;
7981 	portid_t port_id;
7982 	uint16_t queue_id;
7983 	uint16_t desc_id;
7984 };
7985 
7986 static void
7987 cmd_read_rxd_txd_parsed(void *parsed_result,
7988 			__attribute__((unused)) struct cmdline *cl,
7989 			__attribute__((unused)) void *data)
7990 {
7991 	struct cmd_read_rxd_txd_result *res = parsed_result;
7992 
7993 	if (!strcmp(res->rxd_txd, "rxd"))
7994 		rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7995 	else if (!strcmp(res->rxd_txd, "txd"))
7996 		tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7997 }
7998 
7999 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8000 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8001 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8002 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8003 				 "rxd#txd");
8004 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8005 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8006 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8007 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8008 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8009 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8010 
8011 cmdline_parse_inst_t cmd_read_rxd_txd = {
8012 	.f = cmd_read_rxd_txd_parsed,
8013 	.data = NULL,
8014 	.help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8015 	.tokens = {
8016 		(void *)&cmd_read_rxd_txd_read,
8017 		(void *)&cmd_read_rxd_txd_rxd_txd,
8018 		(void *)&cmd_read_rxd_txd_port_id,
8019 		(void *)&cmd_read_rxd_txd_queue_id,
8020 		(void *)&cmd_read_rxd_txd_desc_id,
8021 		NULL,
8022 	},
8023 };
8024 
8025 /* *** QUIT *** */
8026 struct cmd_quit_result {
8027 	cmdline_fixed_string_t quit;
8028 };
8029 
8030 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
8031 			    struct cmdline *cl,
8032 			    __attribute__((unused)) void *data)
8033 {
8034 	cmdline_quit(cl);
8035 }
8036 
8037 cmdline_parse_token_string_t cmd_quit_quit =
8038 	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8039 
8040 cmdline_parse_inst_t cmd_quit = {
8041 	.f = cmd_quit_parsed,
8042 	.data = NULL,
8043 	.help_str = "quit: Exit application",
8044 	.tokens = {
8045 		(void *)&cmd_quit_quit,
8046 		NULL,
8047 	},
8048 };
8049 
8050 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8051 struct cmd_mac_addr_result {
8052 	cmdline_fixed_string_t mac_addr_cmd;
8053 	cmdline_fixed_string_t what;
8054 	uint16_t port_num;
8055 	struct rte_ether_addr address;
8056 };
8057 
8058 static void cmd_mac_addr_parsed(void *parsed_result,
8059 		__attribute__((unused)) struct cmdline *cl,
8060 		__attribute__((unused)) void *data)
8061 {
8062 	struct cmd_mac_addr_result *res = parsed_result;
8063 	int ret;
8064 
8065 	if (strcmp(res->what, "add") == 0)
8066 		ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8067 	else if (strcmp(res->what, "set") == 0)
8068 		ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8069 						       &res->address);
8070 	else
8071 		ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8072 
8073 	/* check the return value and print it if is < 0 */
8074 	if(ret < 0)
8075 		printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8076 
8077 }
8078 
8079 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8080 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8081 				"mac_addr");
8082 cmdline_parse_token_string_t cmd_mac_addr_what =
8083 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8084 				"add#remove#set");
8085 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8086 		TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8087 					UINT16);
8088 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8089 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8090 
8091 cmdline_parse_inst_t cmd_mac_addr = {
8092 	.f = cmd_mac_addr_parsed,
8093 	.data = (void *)0,
8094 	.help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8095 			"Add/Remove/Set MAC address on port_id",
8096 	.tokens = {
8097 		(void *)&cmd_mac_addr_cmd,
8098 		(void *)&cmd_mac_addr_what,
8099 		(void *)&cmd_mac_addr_portnum,
8100 		(void *)&cmd_mac_addr_addr,
8101 		NULL,
8102 	},
8103 };
8104 
8105 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8106 struct cmd_eth_peer_result {
8107 	cmdline_fixed_string_t set;
8108 	cmdline_fixed_string_t eth_peer;
8109 	portid_t port_id;
8110 	cmdline_fixed_string_t peer_addr;
8111 };
8112 
8113 static void cmd_set_eth_peer_parsed(void *parsed_result,
8114 			__attribute__((unused)) struct cmdline *cl,
8115 			__attribute__((unused)) void *data)
8116 {
8117 		struct cmd_eth_peer_result *res = parsed_result;
8118 
8119 		if (test_done == 0) {
8120 			printf("Please stop forwarding first\n");
8121 			return;
8122 		}
8123 		if (!strcmp(res->eth_peer, "eth-peer")) {
8124 			set_fwd_eth_peer(res->port_id, res->peer_addr);
8125 			fwd_config_setup();
8126 		}
8127 }
8128 cmdline_parse_token_string_t cmd_eth_peer_set =
8129 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8130 cmdline_parse_token_string_t cmd_eth_peer =
8131 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8132 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8133 	TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8134 cmdline_parse_token_string_t cmd_eth_peer_addr =
8135 	TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8136 
8137 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8138 	.f = cmd_set_eth_peer_parsed,
8139 	.data = NULL,
8140 	.help_str = "set eth-peer <port_id> <peer_mac>",
8141 	.tokens = {
8142 		(void *)&cmd_eth_peer_set,
8143 		(void *)&cmd_eth_peer,
8144 		(void *)&cmd_eth_peer_port_id,
8145 		(void *)&cmd_eth_peer_addr,
8146 		NULL,
8147 	},
8148 };
8149 
8150 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8151 struct cmd_set_qmap_result {
8152 	cmdline_fixed_string_t set;
8153 	cmdline_fixed_string_t qmap;
8154 	cmdline_fixed_string_t what;
8155 	portid_t port_id;
8156 	uint16_t queue_id;
8157 	uint8_t map_value;
8158 };
8159 
8160 static void
8161 cmd_set_qmap_parsed(void *parsed_result,
8162 		       __attribute__((unused)) struct cmdline *cl,
8163 		       __attribute__((unused)) void *data)
8164 {
8165 	struct cmd_set_qmap_result *res = parsed_result;
8166 	int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8167 
8168 	set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8169 }
8170 
8171 cmdline_parse_token_string_t cmd_setqmap_set =
8172 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8173 				 set, "set");
8174 cmdline_parse_token_string_t cmd_setqmap_qmap =
8175 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8176 				 qmap, "stat_qmap");
8177 cmdline_parse_token_string_t cmd_setqmap_what =
8178 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8179 				 what, "tx#rx");
8180 cmdline_parse_token_num_t cmd_setqmap_portid =
8181 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8182 			      port_id, UINT16);
8183 cmdline_parse_token_num_t cmd_setqmap_queueid =
8184 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8185 			      queue_id, UINT16);
8186 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8187 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8188 			      map_value, UINT8);
8189 
8190 cmdline_parse_inst_t cmd_set_qmap = {
8191 	.f = cmd_set_qmap_parsed,
8192 	.data = NULL,
8193 	.help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8194 		"Set statistics mapping value on tx|rx queue_id of port_id",
8195 	.tokens = {
8196 		(void *)&cmd_setqmap_set,
8197 		(void *)&cmd_setqmap_qmap,
8198 		(void *)&cmd_setqmap_what,
8199 		(void *)&cmd_setqmap_portid,
8200 		(void *)&cmd_setqmap_queueid,
8201 		(void *)&cmd_setqmap_mapvalue,
8202 		NULL,
8203 	},
8204 };
8205 
8206 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8207 struct cmd_set_xstats_hide_zero_result {
8208 	cmdline_fixed_string_t keyword;
8209 	cmdline_fixed_string_t name;
8210 	cmdline_fixed_string_t on_off;
8211 };
8212 
8213 static void
8214 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8215 			__attribute__((unused)) struct cmdline *cl,
8216 			__attribute__((unused)) void *data)
8217 {
8218 	struct cmd_set_xstats_hide_zero_result *res;
8219 	uint16_t on_off = 0;
8220 
8221 	res = parsed_result;
8222 	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8223 	set_xstats_hide_zero(on_off);
8224 }
8225 
8226 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8227 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8228 				 keyword, "set");
8229 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8230 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8231 				 name, "xstats-hide-zero");
8232 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8233 	TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8234 				 on_off, "on#off");
8235 
8236 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8237 	.f = cmd_set_xstats_hide_zero_parsed,
8238 	.data = NULL,
8239 	.help_str = "set xstats-hide-zero on|off",
8240 	.tokens = {
8241 		(void *)&cmd_set_xstats_hide_zero_keyword,
8242 		(void *)&cmd_set_xstats_hide_zero_name,
8243 		(void *)&cmd_set_xstats_hide_zero_on_off,
8244 		NULL,
8245 	},
8246 };
8247 
8248 /* *** CONFIGURE UNICAST HASH TABLE *** */
8249 struct cmd_set_uc_hash_table {
8250 	cmdline_fixed_string_t set;
8251 	cmdline_fixed_string_t port;
8252 	portid_t port_id;
8253 	cmdline_fixed_string_t what;
8254 	struct rte_ether_addr address;
8255 	cmdline_fixed_string_t mode;
8256 };
8257 
8258 static void
8259 cmd_set_uc_hash_parsed(void *parsed_result,
8260 		       __attribute__((unused)) struct cmdline *cl,
8261 		       __attribute__((unused)) void *data)
8262 {
8263 	int ret=0;
8264 	struct cmd_set_uc_hash_table *res = parsed_result;
8265 
8266 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8267 
8268 	if (strcmp(res->what, "uta") == 0)
8269 		ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8270 						&res->address,(uint8_t)is_on);
8271 	if (ret < 0)
8272 		printf("bad unicast hash table parameter, return code = %d \n", ret);
8273 
8274 }
8275 
8276 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8277 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8278 				 set, "set");
8279 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8280 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8281 				 port, "port");
8282 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8283 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8284 			      port_id, UINT16);
8285 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8286 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8287 				 what, "uta");
8288 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8289 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8290 				address);
8291 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8292 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8293 				 mode, "on#off");
8294 
8295 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8296 	.f = cmd_set_uc_hash_parsed,
8297 	.data = NULL,
8298 	.help_str = "set port <port_id> uta <mac_addr> on|off)",
8299 	.tokens = {
8300 		(void *)&cmd_set_uc_hash_set,
8301 		(void *)&cmd_set_uc_hash_port,
8302 		(void *)&cmd_set_uc_hash_portid,
8303 		(void *)&cmd_set_uc_hash_what,
8304 		(void *)&cmd_set_uc_hash_mac,
8305 		(void *)&cmd_set_uc_hash_mode,
8306 		NULL,
8307 	},
8308 };
8309 
8310 struct cmd_set_uc_all_hash_table {
8311 	cmdline_fixed_string_t set;
8312 	cmdline_fixed_string_t port;
8313 	portid_t port_id;
8314 	cmdline_fixed_string_t what;
8315 	cmdline_fixed_string_t value;
8316 	cmdline_fixed_string_t mode;
8317 };
8318 
8319 static void
8320 cmd_set_uc_all_hash_parsed(void *parsed_result,
8321 		       __attribute__((unused)) struct cmdline *cl,
8322 		       __attribute__((unused)) void *data)
8323 {
8324 	int ret=0;
8325 	struct cmd_set_uc_all_hash_table *res = parsed_result;
8326 
8327 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8328 
8329 	if ((strcmp(res->what, "uta") == 0) &&
8330 		(strcmp(res->value, "all") == 0))
8331 		ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8332 	if (ret < 0)
8333 		printf("bad unicast hash table parameter,"
8334 			"return code = %d \n", ret);
8335 }
8336 
8337 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8338 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8339 				 set, "set");
8340 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8341 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8342 				 port, "port");
8343 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8344 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8345 			      port_id, UINT16);
8346 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8347 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8348 				 what, "uta");
8349 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8350 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8351 				value,"all");
8352 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8353 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8354 				 mode, "on#off");
8355 
8356 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8357 	.f = cmd_set_uc_all_hash_parsed,
8358 	.data = NULL,
8359 	.help_str = "set port <port_id> uta all on|off",
8360 	.tokens = {
8361 		(void *)&cmd_set_uc_all_hash_set,
8362 		(void *)&cmd_set_uc_all_hash_port,
8363 		(void *)&cmd_set_uc_all_hash_portid,
8364 		(void *)&cmd_set_uc_all_hash_what,
8365 		(void *)&cmd_set_uc_all_hash_value,
8366 		(void *)&cmd_set_uc_all_hash_mode,
8367 		NULL,
8368 	},
8369 };
8370 
8371 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8372 struct cmd_set_vf_macvlan_filter {
8373 	cmdline_fixed_string_t set;
8374 	cmdline_fixed_string_t port;
8375 	portid_t port_id;
8376 	cmdline_fixed_string_t vf;
8377 	uint8_t vf_id;
8378 	struct rte_ether_addr address;
8379 	cmdline_fixed_string_t filter_type;
8380 	cmdline_fixed_string_t mode;
8381 };
8382 
8383 static void
8384 cmd_set_vf_macvlan_parsed(void *parsed_result,
8385 		       __attribute__((unused)) struct cmdline *cl,
8386 		       __attribute__((unused)) void *data)
8387 {
8388 	int is_on, ret = 0;
8389 	struct cmd_set_vf_macvlan_filter *res = parsed_result;
8390 	struct rte_eth_mac_filter filter;
8391 
8392 	memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8393 
8394 	rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8395 
8396 	/* set VF MAC filter */
8397 	filter.is_vf = 1;
8398 
8399 	/* set VF ID */
8400 	filter.dst_id = res->vf_id;
8401 
8402 	if (!strcmp(res->filter_type, "exact-mac"))
8403 		filter.filter_type = RTE_MAC_PERFECT_MATCH;
8404 	else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8405 		filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8406 	else if (!strcmp(res->filter_type, "hashmac"))
8407 		filter.filter_type = RTE_MAC_HASH_MATCH;
8408 	else if (!strcmp(res->filter_type, "hashmac-vlan"))
8409 		filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8410 
8411 	is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8412 
8413 	if (is_on)
8414 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8415 					RTE_ETH_FILTER_MACVLAN,
8416 					RTE_ETH_FILTER_ADD,
8417 					 &filter);
8418 	else
8419 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8420 					RTE_ETH_FILTER_MACVLAN,
8421 					RTE_ETH_FILTER_DELETE,
8422 					&filter);
8423 
8424 	if (ret < 0)
8425 		printf("bad set MAC hash parameter, return code = %d\n", ret);
8426 
8427 }
8428 
8429 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8430 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8431 				 set, "set");
8432 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8433 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8434 				 port, "port");
8435 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8436 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8437 			      port_id, UINT16);
8438 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8439 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8440 				 vf, "vf");
8441 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8442 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8443 				vf_id, UINT8);
8444 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8445 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8446 				address);
8447 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8448 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8449 				filter_type, "exact-mac#exact-mac-vlan"
8450 				"#hashmac#hashmac-vlan");
8451 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8452 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8453 				 mode, "on#off");
8454 
8455 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8456 	.f = cmd_set_vf_macvlan_parsed,
8457 	.data = NULL,
8458 	.help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8459 		"exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8460 		"Exact match rule: exact match of MAC or MAC and VLAN; "
8461 		"hash match rule: hash match of MAC and exact match of VLAN",
8462 	.tokens = {
8463 		(void *)&cmd_set_vf_macvlan_set,
8464 		(void *)&cmd_set_vf_macvlan_port,
8465 		(void *)&cmd_set_vf_macvlan_portid,
8466 		(void *)&cmd_set_vf_macvlan_vf,
8467 		(void *)&cmd_set_vf_macvlan_vf_id,
8468 		(void *)&cmd_set_vf_macvlan_mac,
8469 		(void *)&cmd_set_vf_macvlan_filter_type,
8470 		(void *)&cmd_set_vf_macvlan_mode,
8471 		NULL,
8472 	},
8473 };
8474 
8475 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8476 struct cmd_set_vf_traffic {
8477 	cmdline_fixed_string_t set;
8478 	cmdline_fixed_string_t port;
8479 	portid_t port_id;
8480 	cmdline_fixed_string_t vf;
8481 	uint8_t vf_id;
8482 	cmdline_fixed_string_t what;
8483 	cmdline_fixed_string_t mode;
8484 };
8485 
8486 static void
8487 cmd_set_vf_traffic_parsed(void *parsed_result,
8488 		       __attribute__((unused)) struct cmdline *cl,
8489 		       __attribute__((unused)) void *data)
8490 {
8491 	struct cmd_set_vf_traffic *res = parsed_result;
8492 	int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8493 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8494 
8495 	set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8496 }
8497 
8498 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8499 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8500 				 set, "set");
8501 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8502 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8503 				 port, "port");
8504 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8505 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8506 			      port_id, UINT16);
8507 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8508 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8509 				 vf, "vf");
8510 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8511 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8512 			      vf_id, UINT8);
8513 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8514 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8515 				 what, "tx#rx");
8516 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8517 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8518 				 mode, "on#off");
8519 
8520 cmdline_parse_inst_t cmd_set_vf_traffic = {
8521 	.f = cmd_set_vf_traffic_parsed,
8522 	.data = NULL,
8523 	.help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8524 	.tokens = {
8525 		(void *)&cmd_setvf_traffic_set,
8526 		(void *)&cmd_setvf_traffic_port,
8527 		(void *)&cmd_setvf_traffic_portid,
8528 		(void *)&cmd_setvf_traffic_vf,
8529 		(void *)&cmd_setvf_traffic_vfid,
8530 		(void *)&cmd_setvf_traffic_what,
8531 		(void *)&cmd_setvf_traffic_mode,
8532 		NULL,
8533 	},
8534 };
8535 
8536 /* *** CONFIGURE VF RECEIVE MODE *** */
8537 struct cmd_set_vf_rxmode {
8538 	cmdline_fixed_string_t set;
8539 	cmdline_fixed_string_t port;
8540 	portid_t port_id;
8541 	cmdline_fixed_string_t vf;
8542 	uint8_t vf_id;
8543 	cmdline_fixed_string_t what;
8544 	cmdline_fixed_string_t mode;
8545 	cmdline_fixed_string_t on;
8546 };
8547 
8548 static void
8549 cmd_set_vf_rxmode_parsed(void *parsed_result,
8550 		       __attribute__((unused)) struct cmdline *cl,
8551 		       __attribute__((unused)) void *data)
8552 {
8553 	int ret = -ENOTSUP;
8554 	uint16_t vf_rxmode = 0;
8555 	struct cmd_set_vf_rxmode *res = parsed_result;
8556 
8557 	int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8558 	if (!strcmp(res->what,"rxmode")) {
8559 		if (!strcmp(res->mode, "AUPE"))
8560 			vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8561 		else if (!strcmp(res->mode, "ROPE"))
8562 			vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8563 		else if (!strcmp(res->mode, "BAM"))
8564 			vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8565 		else if (!strncmp(res->mode, "MPE",3))
8566 			vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8567 	}
8568 
8569 	RTE_SET_USED(is_on);
8570 
8571 #ifdef RTE_LIBRTE_IXGBE_PMD
8572 	if (ret == -ENOTSUP)
8573 		ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8574 						  vf_rxmode, (uint8_t)is_on);
8575 #endif
8576 #ifdef RTE_LIBRTE_BNXT_PMD
8577 	if (ret == -ENOTSUP)
8578 		ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8579 						 vf_rxmode, (uint8_t)is_on);
8580 #endif
8581 	if (ret < 0)
8582 		printf("bad VF receive mode parameter, return code = %d \n",
8583 		ret);
8584 }
8585 
8586 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8587 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8588 				 set, "set");
8589 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8590 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8591 				 port, "port");
8592 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8593 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8594 			      port_id, UINT16);
8595 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8596 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8597 				 vf, "vf");
8598 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8599 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8600 			      vf_id, UINT8);
8601 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8602 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8603 				 what, "rxmode");
8604 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8605 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8606 				 mode, "AUPE#ROPE#BAM#MPE");
8607 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8608 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8609 				 on, "on#off");
8610 
8611 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8612 	.f = cmd_set_vf_rxmode_parsed,
8613 	.data = NULL,
8614 	.help_str = "set port <port_id> vf <vf_id> rxmode "
8615 		"AUPE|ROPE|BAM|MPE on|off",
8616 	.tokens = {
8617 		(void *)&cmd_set_vf_rxmode_set,
8618 		(void *)&cmd_set_vf_rxmode_port,
8619 		(void *)&cmd_set_vf_rxmode_portid,
8620 		(void *)&cmd_set_vf_rxmode_vf,
8621 		(void *)&cmd_set_vf_rxmode_vfid,
8622 		(void *)&cmd_set_vf_rxmode_what,
8623 		(void *)&cmd_set_vf_rxmode_mode,
8624 		(void *)&cmd_set_vf_rxmode_on,
8625 		NULL,
8626 	},
8627 };
8628 
8629 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8630 struct cmd_vf_mac_addr_result {
8631 	cmdline_fixed_string_t mac_addr_cmd;
8632 	cmdline_fixed_string_t what;
8633 	cmdline_fixed_string_t port;
8634 	uint16_t port_num;
8635 	cmdline_fixed_string_t vf;
8636 	uint8_t vf_num;
8637 	struct rte_ether_addr address;
8638 };
8639 
8640 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8641 		__attribute__((unused)) struct cmdline *cl,
8642 		__attribute__((unused)) void *data)
8643 {
8644 	struct cmd_vf_mac_addr_result *res = parsed_result;
8645 	int ret = -ENOTSUP;
8646 
8647 	if (strcmp(res->what, "add") != 0)
8648 		return;
8649 
8650 #ifdef RTE_LIBRTE_I40E_PMD
8651 	if (ret == -ENOTSUP)
8652 		ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8653 						   &res->address);
8654 #endif
8655 #ifdef RTE_LIBRTE_BNXT_PMD
8656 	if (ret == -ENOTSUP)
8657 		ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8658 						res->vf_num);
8659 #endif
8660 
8661 	if(ret < 0)
8662 		printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8663 
8664 }
8665 
8666 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8667 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8668 				mac_addr_cmd,"mac_addr");
8669 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8670 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8671 				what,"add");
8672 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8673 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8674 				port,"port");
8675 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8676 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8677 				port_num, UINT16);
8678 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8679 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8680 				vf,"vf");
8681 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8682 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8683 				vf_num, UINT8);
8684 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8685 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8686 				address);
8687 
8688 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8689 	.f = cmd_vf_mac_addr_parsed,
8690 	.data = (void *)0,
8691 	.help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8692 		"Add MAC address filtering for a VF on port_id",
8693 	.tokens = {
8694 		(void *)&cmd_vf_mac_addr_cmd,
8695 		(void *)&cmd_vf_mac_addr_what,
8696 		(void *)&cmd_vf_mac_addr_port,
8697 		(void *)&cmd_vf_mac_addr_portnum,
8698 		(void *)&cmd_vf_mac_addr_vf,
8699 		(void *)&cmd_vf_mac_addr_vfnum,
8700 		(void *)&cmd_vf_mac_addr_addr,
8701 		NULL,
8702 	},
8703 };
8704 
8705 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8706 struct cmd_vf_rx_vlan_filter {
8707 	cmdline_fixed_string_t rx_vlan;
8708 	cmdline_fixed_string_t what;
8709 	uint16_t vlan_id;
8710 	cmdline_fixed_string_t port;
8711 	portid_t port_id;
8712 	cmdline_fixed_string_t vf;
8713 	uint64_t vf_mask;
8714 };
8715 
8716 static void
8717 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8718 			  __attribute__((unused)) struct cmdline *cl,
8719 			  __attribute__((unused)) void *data)
8720 {
8721 	struct cmd_vf_rx_vlan_filter *res = parsed_result;
8722 	int ret = -ENOTSUP;
8723 
8724 	__rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8725 
8726 #ifdef RTE_LIBRTE_IXGBE_PMD
8727 	if (ret == -ENOTSUP)
8728 		ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8729 				res->vlan_id, res->vf_mask, is_add);
8730 #endif
8731 #ifdef RTE_LIBRTE_I40E_PMD
8732 	if (ret == -ENOTSUP)
8733 		ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8734 				res->vlan_id, res->vf_mask, is_add);
8735 #endif
8736 #ifdef RTE_LIBRTE_BNXT_PMD
8737 	if (ret == -ENOTSUP)
8738 		ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8739 				res->vlan_id, res->vf_mask, is_add);
8740 #endif
8741 
8742 	switch (ret) {
8743 	case 0:
8744 		break;
8745 	case -EINVAL:
8746 		printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8747 				res->vlan_id, res->vf_mask);
8748 		break;
8749 	case -ENODEV:
8750 		printf("invalid port_id %d\n", res->port_id);
8751 		break;
8752 	case -ENOTSUP:
8753 		printf("function not implemented or supported\n");
8754 		break;
8755 	default:
8756 		printf("programming error: (%s)\n", strerror(-ret));
8757 	}
8758 }
8759 
8760 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8761 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8762 				 rx_vlan, "rx_vlan");
8763 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8764 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8765 				 what, "add#rm");
8766 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8767 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8768 			      vlan_id, UINT16);
8769 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8770 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8771 				 port, "port");
8772 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8773 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8774 			      port_id, UINT16);
8775 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8776 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8777 				 vf, "vf");
8778 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8779 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8780 			      vf_mask, UINT64);
8781 
8782 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8783 	.f = cmd_vf_rx_vlan_filter_parsed,
8784 	.data = NULL,
8785 	.help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8786 		"(vf_mask = hexadecimal VF mask)",
8787 	.tokens = {
8788 		(void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8789 		(void *)&cmd_vf_rx_vlan_filter_what,
8790 		(void *)&cmd_vf_rx_vlan_filter_vlanid,
8791 		(void *)&cmd_vf_rx_vlan_filter_port,
8792 		(void *)&cmd_vf_rx_vlan_filter_portid,
8793 		(void *)&cmd_vf_rx_vlan_filter_vf,
8794 		(void *)&cmd_vf_rx_vlan_filter_vf_mask,
8795 		NULL,
8796 	},
8797 };
8798 
8799 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8800 struct cmd_queue_rate_limit_result {
8801 	cmdline_fixed_string_t set;
8802 	cmdline_fixed_string_t port;
8803 	uint16_t port_num;
8804 	cmdline_fixed_string_t queue;
8805 	uint8_t queue_num;
8806 	cmdline_fixed_string_t rate;
8807 	uint16_t rate_num;
8808 };
8809 
8810 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8811 		__attribute__((unused)) struct cmdline *cl,
8812 		__attribute__((unused)) void *data)
8813 {
8814 	struct cmd_queue_rate_limit_result *res = parsed_result;
8815 	int ret = 0;
8816 
8817 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8818 		&& (strcmp(res->queue, "queue") == 0)
8819 		&& (strcmp(res->rate, "rate") == 0))
8820 		ret = set_queue_rate_limit(res->port_num, res->queue_num,
8821 					res->rate_num);
8822 	if (ret < 0)
8823 		printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8824 
8825 }
8826 
8827 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8828 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8829 				set, "set");
8830 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8831 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8832 				port, "port");
8833 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8834 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8835 				port_num, UINT16);
8836 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8837 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8838 				queue, "queue");
8839 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8840 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8841 				queue_num, UINT8);
8842 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8843 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8844 				rate, "rate");
8845 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8846 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8847 				rate_num, UINT16);
8848 
8849 cmdline_parse_inst_t cmd_queue_rate_limit = {
8850 	.f = cmd_queue_rate_limit_parsed,
8851 	.data = (void *)0,
8852 	.help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8853 		"Set rate limit for a queue on port_id",
8854 	.tokens = {
8855 		(void *)&cmd_queue_rate_limit_set,
8856 		(void *)&cmd_queue_rate_limit_port,
8857 		(void *)&cmd_queue_rate_limit_portnum,
8858 		(void *)&cmd_queue_rate_limit_queue,
8859 		(void *)&cmd_queue_rate_limit_queuenum,
8860 		(void *)&cmd_queue_rate_limit_rate,
8861 		(void *)&cmd_queue_rate_limit_ratenum,
8862 		NULL,
8863 	},
8864 };
8865 
8866 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8867 struct cmd_vf_rate_limit_result {
8868 	cmdline_fixed_string_t set;
8869 	cmdline_fixed_string_t port;
8870 	uint16_t port_num;
8871 	cmdline_fixed_string_t vf;
8872 	uint8_t vf_num;
8873 	cmdline_fixed_string_t rate;
8874 	uint16_t rate_num;
8875 	cmdline_fixed_string_t q_msk;
8876 	uint64_t q_msk_val;
8877 };
8878 
8879 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8880 		__attribute__((unused)) struct cmdline *cl,
8881 		__attribute__((unused)) void *data)
8882 {
8883 	struct cmd_vf_rate_limit_result *res = parsed_result;
8884 	int ret = 0;
8885 
8886 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8887 		&& (strcmp(res->vf, "vf") == 0)
8888 		&& (strcmp(res->rate, "rate") == 0)
8889 		&& (strcmp(res->q_msk, "queue_mask") == 0))
8890 		ret = set_vf_rate_limit(res->port_num, res->vf_num,
8891 					res->rate_num, res->q_msk_val);
8892 	if (ret < 0)
8893 		printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8894 
8895 }
8896 
8897 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8898 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8899 				set, "set");
8900 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8901 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8902 				port, "port");
8903 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8904 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8905 				port_num, UINT16);
8906 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8907 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8908 				vf, "vf");
8909 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8910 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8911 				vf_num, UINT8);
8912 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8913 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8914 				rate, "rate");
8915 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8916 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8917 				rate_num, UINT16);
8918 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8919 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8920 				q_msk, "queue_mask");
8921 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8922 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8923 				q_msk_val, UINT64);
8924 
8925 cmdline_parse_inst_t cmd_vf_rate_limit = {
8926 	.f = cmd_vf_rate_limit_parsed,
8927 	.data = (void *)0,
8928 	.help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8929 		"queue_mask <queue_mask_value>: "
8930 		"Set rate limit for queues of VF on port_id",
8931 	.tokens = {
8932 		(void *)&cmd_vf_rate_limit_set,
8933 		(void *)&cmd_vf_rate_limit_port,
8934 		(void *)&cmd_vf_rate_limit_portnum,
8935 		(void *)&cmd_vf_rate_limit_vf,
8936 		(void *)&cmd_vf_rate_limit_vfnum,
8937 		(void *)&cmd_vf_rate_limit_rate,
8938 		(void *)&cmd_vf_rate_limit_ratenum,
8939 		(void *)&cmd_vf_rate_limit_q_msk,
8940 		(void *)&cmd_vf_rate_limit_q_msk_val,
8941 		NULL,
8942 	},
8943 };
8944 
8945 /* *** ADD TUNNEL FILTER OF A PORT *** */
8946 struct cmd_tunnel_filter_result {
8947 	cmdline_fixed_string_t cmd;
8948 	cmdline_fixed_string_t what;
8949 	portid_t port_id;
8950 	struct rte_ether_addr outer_mac;
8951 	struct rte_ether_addr inner_mac;
8952 	cmdline_ipaddr_t ip_value;
8953 	uint16_t inner_vlan;
8954 	cmdline_fixed_string_t tunnel_type;
8955 	cmdline_fixed_string_t filter_type;
8956 	uint32_t tenant_id;
8957 	uint16_t queue_num;
8958 };
8959 
8960 static void
8961 cmd_tunnel_filter_parsed(void *parsed_result,
8962 			  __attribute__((unused)) struct cmdline *cl,
8963 			  __attribute__((unused)) void *data)
8964 {
8965 	struct cmd_tunnel_filter_result *res = parsed_result;
8966 	struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8967 	int ret = 0;
8968 
8969 	memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8970 
8971 	rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8972 	rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8973 	tunnel_filter_conf.inner_vlan = res->inner_vlan;
8974 
8975 	if (res->ip_value.family == AF_INET) {
8976 		tunnel_filter_conf.ip_addr.ipv4_addr =
8977 			res->ip_value.addr.ipv4.s_addr;
8978 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8979 	} else {
8980 		memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8981 			&(res->ip_value.addr.ipv6),
8982 			sizeof(struct in6_addr));
8983 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8984 	}
8985 
8986 	if (!strcmp(res->filter_type, "imac-ivlan"))
8987 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8988 	else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8989 		tunnel_filter_conf.filter_type =
8990 			RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8991 	else if (!strcmp(res->filter_type, "imac-tenid"))
8992 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8993 	else if (!strcmp(res->filter_type, "imac"))
8994 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8995 	else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8996 		tunnel_filter_conf.filter_type =
8997 			RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8998 	else if (!strcmp(res->filter_type, "oip"))
8999 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9000 	else if (!strcmp(res->filter_type, "iip"))
9001 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9002 	else {
9003 		printf("The filter type is not supported");
9004 		return;
9005 	}
9006 
9007 	if (!strcmp(res->tunnel_type, "vxlan"))
9008 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9009 	else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9010 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9011 	else if (!strcmp(res->tunnel_type, "nvgre"))
9012 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9013 	else if (!strcmp(res->tunnel_type, "ipingre"))
9014 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9015 	else {
9016 		printf("The tunnel type %s not supported.\n", res->tunnel_type);
9017 		return;
9018 	}
9019 
9020 	tunnel_filter_conf.tenant_id = res->tenant_id;
9021 	tunnel_filter_conf.queue_id = res->queue_num;
9022 	if (!strcmp(res->what, "add"))
9023 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9024 					RTE_ETH_FILTER_TUNNEL,
9025 					RTE_ETH_FILTER_ADD,
9026 					&tunnel_filter_conf);
9027 	else
9028 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9029 					RTE_ETH_FILTER_TUNNEL,
9030 					RTE_ETH_FILTER_DELETE,
9031 					&tunnel_filter_conf);
9032 	if (ret < 0)
9033 		printf("cmd_tunnel_filter_parsed error: (%s)\n",
9034 				strerror(-ret));
9035 
9036 }
9037 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9038 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9039 	cmd, "tunnel_filter");
9040 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9041 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9042 	what, "add#rm");
9043 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9044 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9045 	port_id, UINT16);
9046 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9047 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9048 	outer_mac);
9049 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9050 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9051 	inner_mac);
9052 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9053 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9054 	inner_vlan, UINT16);
9055 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9056 	TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9057 	ip_value);
9058 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9059 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9060 	tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9061 
9062 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9063 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9064 	filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9065 		"imac#omac-imac-tenid");
9066 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9067 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9068 	tenant_id, UINT32);
9069 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9070 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9071 	queue_num, UINT16);
9072 
9073 cmdline_parse_inst_t cmd_tunnel_filter = {
9074 	.f = cmd_tunnel_filter_parsed,
9075 	.data = (void *)0,
9076 	.help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9077 		"<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9078 		"imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9079 		"<queue_id>: Add/Rm tunnel filter of a port",
9080 	.tokens = {
9081 		(void *)&cmd_tunnel_filter_cmd,
9082 		(void *)&cmd_tunnel_filter_what,
9083 		(void *)&cmd_tunnel_filter_port_id,
9084 		(void *)&cmd_tunnel_filter_outer_mac,
9085 		(void *)&cmd_tunnel_filter_inner_mac,
9086 		(void *)&cmd_tunnel_filter_ip_value,
9087 		(void *)&cmd_tunnel_filter_innner_vlan,
9088 		(void *)&cmd_tunnel_filter_tunnel_type,
9089 		(void *)&cmd_tunnel_filter_filter_type,
9090 		(void *)&cmd_tunnel_filter_tenant_id,
9091 		(void *)&cmd_tunnel_filter_queue_num,
9092 		NULL,
9093 	},
9094 };
9095 
9096 /* *** CONFIGURE TUNNEL UDP PORT *** */
9097 struct cmd_tunnel_udp_config {
9098 	cmdline_fixed_string_t cmd;
9099 	cmdline_fixed_string_t what;
9100 	uint16_t udp_port;
9101 	portid_t port_id;
9102 };
9103 
9104 static void
9105 cmd_tunnel_udp_config_parsed(void *parsed_result,
9106 			  __attribute__((unused)) struct cmdline *cl,
9107 			  __attribute__((unused)) void *data)
9108 {
9109 	struct cmd_tunnel_udp_config *res = parsed_result;
9110 	struct rte_eth_udp_tunnel tunnel_udp;
9111 	int ret;
9112 
9113 	tunnel_udp.udp_port = res->udp_port;
9114 
9115 	if (!strcmp(res->cmd, "rx_vxlan_port"))
9116 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9117 
9118 	if (!strcmp(res->what, "add"))
9119 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9120 						      &tunnel_udp);
9121 	else
9122 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9123 							 &tunnel_udp);
9124 
9125 	if (ret < 0)
9126 		printf("udp tunneling add error: (%s)\n", strerror(-ret));
9127 }
9128 
9129 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9130 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9131 				cmd, "rx_vxlan_port");
9132 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9133 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9134 				what, "add#rm");
9135 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9136 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9137 				udp_port, UINT16);
9138 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9139 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9140 				port_id, UINT16);
9141 
9142 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9143 	.f = cmd_tunnel_udp_config_parsed,
9144 	.data = (void *)0,
9145 	.help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9146 		"Add/Remove a tunneling UDP port filter",
9147 	.tokens = {
9148 		(void *)&cmd_tunnel_udp_config_cmd,
9149 		(void *)&cmd_tunnel_udp_config_what,
9150 		(void *)&cmd_tunnel_udp_config_udp_port,
9151 		(void *)&cmd_tunnel_udp_config_port_id,
9152 		NULL,
9153 	},
9154 };
9155 
9156 struct cmd_config_tunnel_udp_port {
9157 	cmdline_fixed_string_t port;
9158 	cmdline_fixed_string_t config;
9159 	portid_t port_id;
9160 	cmdline_fixed_string_t udp_tunnel_port;
9161 	cmdline_fixed_string_t action;
9162 	cmdline_fixed_string_t tunnel_type;
9163 	uint16_t udp_port;
9164 };
9165 
9166 static void
9167 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9168 			       __attribute__((unused)) struct cmdline *cl,
9169 			       __attribute__((unused)) void *data)
9170 {
9171 	struct cmd_config_tunnel_udp_port *res = parsed_result;
9172 	struct rte_eth_udp_tunnel tunnel_udp;
9173 	int ret = 0;
9174 
9175 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9176 		return;
9177 
9178 	tunnel_udp.udp_port = res->udp_port;
9179 
9180 	if (!strcmp(res->tunnel_type, "vxlan")) {
9181 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9182 	} else if (!strcmp(res->tunnel_type, "geneve")) {
9183 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9184 	} else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9185 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9186 	} else {
9187 		printf("Invalid tunnel type\n");
9188 		return;
9189 	}
9190 
9191 	if (!strcmp(res->action, "add"))
9192 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9193 						      &tunnel_udp);
9194 	else
9195 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9196 							 &tunnel_udp);
9197 
9198 	if (ret < 0)
9199 		printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9200 }
9201 
9202 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9203 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9204 				 "port");
9205 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9206 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9207 				 "config");
9208 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9209 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9210 			      UINT16);
9211 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9212 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9213 				 udp_tunnel_port,
9214 				 "udp_tunnel_port");
9215 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9216 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9217 				 "add#rm");
9218 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9219 	TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9220 				 "vxlan#geneve#vxlan-gpe");
9221 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9222 	TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9223 			      UINT16);
9224 
9225 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9226 	.f = cmd_cfg_tunnel_udp_port_parsed,
9227 	.data = NULL,
9228 	.help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9229 	.tokens = {
9230 		(void *)&cmd_config_tunnel_udp_port_port,
9231 		(void *)&cmd_config_tunnel_udp_port_config,
9232 		(void *)&cmd_config_tunnel_udp_port_port_id,
9233 		(void *)&cmd_config_tunnel_udp_port_tunnel_port,
9234 		(void *)&cmd_config_tunnel_udp_port_action,
9235 		(void *)&cmd_config_tunnel_udp_port_tunnel_type,
9236 		(void *)&cmd_config_tunnel_udp_port_value,
9237 		NULL,
9238 	},
9239 };
9240 
9241 /* *** GLOBAL CONFIG *** */
9242 struct cmd_global_config_result {
9243 	cmdline_fixed_string_t cmd;
9244 	portid_t port_id;
9245 	cmdline_fixed_string_t cfg_type;
9246 	uint8_t len;
9247 };
9248 
9249 static void
9250 cmd_global_config_parsed(void *parsed_result,
9251 			 __attribute__((unused)) struct cmdline *cl,
9252 			 __attribute__((unused)) void *data)
9253 {
9254 	struct cmd_global_config_result *res = parsed_result;
9255 	struct rte_eth_global_cfg conf;
9256 	int ret;
9257 
9258 	memset(&conf, 0, sizeof(conf));
9259 	conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9260 	conf.cfg.gre_key_len = res->len;
9261 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9262 				      RTE_ETH_FILTER_SET, &conf);
9263 	if (ret != 0)
9264 		printf("Global config error\n");
9265 }
9266 
9267 cmdline_parse_token_string_t cmd_global_config_cmd =
9268 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9269 		"global_config");
9270 cmdline_parse_token_num_t cmd_global_config_port_id =
9271 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9272 			       UINT16);
9273 cmdline_parse_token_string_t cmd_global_config_type =
9274 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9275 		cfg_type, "gre-key-len");
9276 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9277 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9278 		len, UINT8);
9279 
9280 cmdline_parse_inst_t cmd_global_config = {
9281 	.f = cmd_global_config_parsed,
9282 	.data = (void *)NULL,
9283 	.help_str = "global_config <port_id> gre-key-len <key_len>",
9284 	.tokens = {
9285 		(void *)&cmd_global_config_cmd,
9286 		(void *)&cmd_global_config_port_id,
9287 		(void *)&cmd_global_config_type,
9288 		(void *)&cmd_global_config_gre_key_len,
9289 		NULL,
9290 	},
9291 };
9292 
9293 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9294 struct cmd_set_mirror_mask_result {
9295 	cmdline_fixed_string_t set;
9296 	cmdline_fixed_string_t port;
9297 	portid_t port_id;
9298 	cmdline_fixed_string_t mirror;
9299 	uint8_t rule_id;
9300 	cmdline_fixed_string_t what;
9301 	cmdline_fixed_string_t value;
9302 	cmdline_fixed_string_t dstpool;
9303 	uint8_t dstpool_id;
9304 	cmdline_fixed_string_t on;
9305 };
9306 
9307 cmdline_parse_token_string_t cmd_mirror_mask_set =
9308 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9309 				set, "set");
9310 cmdline_parse_token_string_t cmd_mirror_mask_port =
9311 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9312 				port, "port");
9313 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9314 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9315 				port_id, UINT16);
9316 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9317 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9318 				mirror, "mirror-rule");
9319 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9320 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9321 				rule_id, UINT8);
9322 cmdline_parse_token_string_t cmd_mirror_mask_what =
9323 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9324 				what, "pool-mirror-up#pool-mirror-down"
9325 				      "#vlan-mirror");
9326 cmdline_parse_token_string_t cmd_mirror_mask_value =
9327 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9328 				value, NULL);
9329 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9330 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9331 				dstpool, "dst-pool");
9332 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9333 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9334 				dstpool_id, UINT8);
9335 cmdline_parse_token_string_t cmd_mirror_mask_on =
9336 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9337 				on, "on#off");
9338 
9339 static void
9340 cmd_set_mirror_mask_parsed(void *parsed_result,
9341 		       __attribute__((unused)) struct cmdline *cl,
9342 		       __attribute__((unused)) void *data)
9343 {
9344 	int ret,nb_item,i;
9345 	struct cmd_set_mirror_mask_result *res = parsed_result;
9346 	struct rte_eth_mirror_conf mr_conf;
9347 
9348 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9349 
9350 	unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9351 
9352 	mr_conf.dst_pool = res->dstpool_id;
9353 
9354 	if (!strcmp(res->what, "pool-mirror-up")) {
9355 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9356 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9357 	} else if (!strcmp(res->what, "pool-mirror-down")) {
9358 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9359 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9360 	} else if (!strcmp(res->what, "vlan-mirror")) {
9361 		mr_conf.rule_type = ETH_MIRROR_VLAN;
9362 		nb_item = parse_item_list(res->value, "vlan",
9363 				ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9364 		if (nb_item <= 0)
9365 			return;
9366 
9367 		for (i = 0; i < nb_item; i++) {
9368 			if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9369 				printf("Invalid vlan_id: must be < 4096\n");
9370 				return;
9371 			}
9372 
9373 			mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9374 			mr_conf.vlan.vlan_mask |= 1ULL << i;
9375 		}
9376 	}
9377 
9378 	if (!strcmp(res->on, "on"))
9379 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9380 						res->rule_id, 1);
9381 	else
9382 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9383 						res->rule_id, 0);
9384 	if (ret < 0)
9385 		printf("mirror rule add error: (%s)\n", strerror(-ret));
9386 }
9387 
9388 cmdline_parse_inst_t cmd_set_mirror_mask = {
9389 		.f = cmd_set_mirror_mask_parsed,
9390 		.data = NULL,
9391 		.help_str = "set port <port_id> mirror-rule <rule_id> "
9392 			"pool-mirror-up|pool-mirror-down|vlan-mirror "
9393 			"<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9394 		.tokens = {
9395 			(void *)&cmd_mirror_mask_set,
9396 			(void *)&cmd_mirror_mask_port,
9397 			(void *)&cmd_mirror_mask_portid,
9398 			(void *)&cmd_mirror_mask_mirror,
9399 			(void *)&cmd_mirror_mask_ruleid,
9400 			(void *)&cmd_mirror_mask_what,
9401 			(void *)&cmd_mirror_mask_value,
9402 			(void *)&cmd_mirror_mask_dstpool,
9403 			(void *)&cmd_mirror_mask_poolid,
9404 			(void *)&cmd_mirror_mask_on,
9405 			NULL,
9406 		},
9407 };
9408 
9409 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9410 struct cmd_set_mirror_link_result {
9411 	cmdline_fixed_string_t set;
9412 	cmdline_fixed_string_t port;
9413 	portid_t port_id;
9414 	cmdline_fixed_string_t mirror;
9415 	uint8_t rule_id;
9416 	cmdline_fixed_string_t what;
9417 	cmdline_fixed_string_t dstpool;
9418 	uint8_t dstpool_id;
9419 	cmdline_fixed_string_t on;
9420 };
9421 
9422 cmdline_parse_token_string_t cmd_mirror_link_set =
9423 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9424 				 set, "set");
9425 cmdline_parse_token_string_t cmd_mirror_link_port =
9426 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9427 				port, "port");
9428 cmdline_parse_token_num_t cmd_mirror_link_portid =
9429 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9430 				port_id, UINT16);
9431 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9432 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9433 				mirror, "mirror-rule");
9434 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9435 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9436 			    rule_id, UINT8);
9437 cmdline_parse_token_string_t cmd_mirror_link_what =
9438 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9439 				what, "uplink-mirror#downlink-mirror");
9440 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9441 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9442 				dstpool, "dst-pool");
9443 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9444 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9445 				dstpool_id, UINT8);
9446 cmdline_parse_token_string_t cmd_mirror_link_on =
9447 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9448 				on, "on#off");
9449 
9450 static void
9451 cmd_set_mirror_link_parsed(void *parsed_result,
9452 		       __attribute__((unused)) struct cmdline *cl,
9453 		       __attribute__((unused)) void *data)
9454 {
9455 	int ret;
9456 	struct cmd_set_mirror_link_result *res = parsed_result;
9457 	struct rte_eth_mirror_conf mr_conf;
9458 
9459 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9460 	if (!strcmp(res->what, "uplink-mirror"))
9461 		mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9462 	else
9463 		mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9464 
9465 	mr_conf.dst_pool = res->dstpool_id;
9466 
9467 	if (!strcmp(res->on, "on"))
9468 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9469 						res->rule_id, 1);
9470 	else
9471 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9472 						res->rule_id, 0);
9473 
9474 	/* check the return value and print it if is < 0 */
9475 	if (ret < 0)
9476 		printf("mirror rule add error: (%s)\n", strerror(-ret));
9477 
9478 }
9479 
9480 cmdline_parse_inst_t cmd_set_mirror_link = {
9481 		.f = cmd_set_mirror_link_parsed,
9482 		.data = NULL,
9483 		.help_str = "set port <port_id> mirror-rule <rule_id> "
9484 			"uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9485 		.tokens = {
9486 			(void *)&cmd_mirror_link_set,
9487 			(void *)&cmd_mirror_link_port,
9488 			(void *)&cmd_mirror_link_portid,
9489 			(void *)&cmd_mirror_link_mirror,
9490 			(void *)&cmd_mirror_link_ruleid,
9491 			(void *)&cmd_mirror_link_what,
9492 			(void *)&cmd_mirror_link_dstpool,
9493 			(void *)&cmd_mirror_link_poolid,
9494 			(void *)&cmd_mirror_link_on,
9495 			NULL,
9496 		},
9497 };
9498 
9499 /* *** RESET VM MIRROR RULE *** */
9500 struct cmd_rm_mirror_rule_result {
9501 	cmdline_fixed_string_t reset;
9502 	cmdline_fixed_string_t port;
9503 	portid_t port_id;
9504 	cmdline_fixed_string_t mirror;
9505 	uint8_t rule_id;
9506 };
9507 
9508 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9509 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9510 				 reset, "reset");
9511 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9512 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9513 				port, "port");
9514 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9515 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9516 				port_id, UINT16);
9517 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9518 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9519 				mirror, "mirror-rule");
9520 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9521 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9522 				rule_id, UINT8);
9523 
9524 static void
9525 cmd_reset_mirror_rule_parsed(void *parsed_result,
9526 		       __attribute__((unused)) struct cmdline *cl,
9527 		       __attribute__((unused)) void *data)
9528 {
9529 	int ret;
9530 	struct cmd_set_mirror_link_result *res = parsed_result;
9531         /* check rule_id */
9532 	ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9533 	if(ret < 0)
9534 		printf("mirror rule remove error: (%s)\n", strerror(-ret));
9535 }
9536 
9537 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9538 		.f = cmd_reset_mirror_rule_parsed,
9539 		.data = NULL,
9540 		.help_str = "reset port <port_id> mirror-rule <rule_id>",
9541 		.tokens = {
9542 			(void *)&cmd_rm_mirror_rule_reset,
9543 			(void *)&cmd_rm_mirror_rule_port,
9544 			(void *)&cmd_rm_mirror_rule_portid,
9545 			(void *)&cmd_rm_mirror_rule_mirror,
9546 			(void *)&cmd_rm_mirror_rule_ruleid,
9547 			NULL,
9548 		},
9549 };
9550 
9551 /* ******************************************************************************** */
9552 
9553 struct cmd_dump_result {
9554 	cmdline_fixed_string_t dump;
9555 };
9556 
9557 static void
9558 dump_struct_sizes(void)
9559 {
9560 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9561 	DUMP_SIZE(struct rte_mbuf);
9562 	DUMP_SIZE(struct rte_mempool);
9563 	DUMP_SIZE(struct rte_ring);
9564 #undef DUMP_SIZE
9565 }
9566 
9567 static void cmd_dump_parsed(void *parsed_result,
9568 			    __attribute__((unused)) struct cmdline *cl,
9569 			    __attribute__((unused)) void *data)
9570 {
9571 	struct cmd_dump_result *res = parsed_result;
9572 
9573 	if (!strcmp(res->dump, "dump_physmem"))
9574 		rte_dump_physmem_layout(stdout);
9575 	else if (!strcmp(res->dump, "dump_memzone"))
9576 		rte_memzone_dump(stdout);
9577 	else if (!strcmp(res->dump, "dump_struct_sizes"))
9578 		dump_struct_sizes();
9579 	else if (!strcmp(res->dump, "dump_ring"))
9580 		rte_ring_list_dump(stdout);
9581 	else if (!strcmp(res->dump, "dump_mempool"))
9582 		rte_mempool_list_dump(stdout);
9583 	else if (!strcmp(res->dump, "dump_devargs"))
9584 		rte_devargs_dump(stdout);
9585 	else if (!strcmp(res->dump, "dump_log_types"))
9586 		rte_log_dump(stdout);
9587 }
9588 
9589 cmdline_parse_token_string_t cmd_dump_dump =
9590 	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9591 		"dump_physmem#"
9592 		"dump_memzone#"
9593 		"dump_struct_sizes#"
9594 		"dump_ring#"
9595 		"dump_mempool#"
9596 		"dump_devargs#"
9597 		"dump_log_types");
9598 
9599 cmdline_parse_inst_t cmd_dump = {
9600 	.f = cmd_dump_parsed,  /* function to call */
9601 	.data = NULL,      /* 2nd arg of func */
9602 	.help_str = "Dump status",
9603 	.tokens = {        /* token list, NULL terminated */
9604 		(void *)&cmd_dump_dump,
9605 		NULL,
9606 	},
9607 };
9608 
9609 /* ******************************************************************************** */
9610 
9611 struct cmd_dump_one_result {
9612 	cmdline_fixed_string_t dump;
9613 	cmdline_fixed_string_t name;
9614 };
9615 
9616 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9617 				__attribute__((unused)) void *data)
9618 {
9619 	struct cmd_dump_one_result *res = parsed_result;
9620 
9621 	if (!strcmp(res->dump, "dump_ring")) {
9622 		struct rte_ring *r;
9623 		r = rte_ring_lookup(res->name);
9624 		if (r == NULL) {
9625 			cmdline_printf(cl, "Cannot find ring\n");
9626 			return;
9627 		}
9628 		rte_ring_dump(stdout, r);
9629 	} else if (!strcmp(res->dump, "dump_mempool")) {
9630 		struct rte_mempool *mp;
9631 		mp = rte_mempool_lookup(res->name);
9632 		if (mp == NULL) {
9633 			cmdline_printf(cl, "Cannot find mempool\n");
9634 			return;
9635 		}
9636 		rte_mempool_dump(stdout, mp);
9637 	}
9638 }
9639 
9640 cmdline_parse_token_string_t cmd_dump_one_dump =
9641 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9642 				 "dump_ring#dump_mempool");
9643 
9644 cmdline_parse_token_string_t cmd_dump_one_name =
9645 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9646 
9647 cmdline_parse_inst_t cmd_dump_one = {
9648 	.f = cmd_dump_one_parsed,  /* function to call */
9649 	.data = NULL,      /* 2nd arg of func */
9650 	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9651 	.tokens = {        /* token list, NULL terminated */
9652 		(void *)&cmd_dump_one_dump,
9653 		(void *)&cmd_dump_one_name,
9654 		NULL,
9655 	},
9656 };
9657 
9658 /* *** Add/Del syn filter *** */
9659 struct cmd_syn_filter_result {
9660 	cmdline_fixed_string_t filter;
9661 	portid_t port_id;
9662 	cmdline_fixed_string_t ops;
9663 	cmdline_fixed_string_t priority;
9664 	cmdline_fixed_string_t high;
9665 	cmdline_fixed_string_t queue;
9666 	uint16_t queue_id;
9667 };
9668 
9669 static void
9670 cmd_syn_filter_parsed(void *parsed_result,
9671 			__attribute__((unused)) struct cmdline *cl,
9672 			__attribute__((unused)) void *data)
9673 {
9674 	struct cmd_syn_filter_result *res = parsed_result;
9675 	struct rte_eth_syn_filter syn_filter;
9676 	int ret = 0;
9677 
9678 	ret = rte_eth_dev_filter_supported(res->port_id,
9679 					RTE_ETH_FILTER_SYN);
9680 	if (ret < 0) {
9681 		printf("syn filter is not supported on port %u.\n",
9682 				res->port_id);
9683 		return;
9684 	}
9685 
9686 	memset(&syn_filter, 0, sizeof(syn_filter));
9687 
9688 	if (!strcmp(res->ops, "add")) {
9689 		if (!strcmp(res->high, "high"))
9690 			syn_filter.hig_pri = 1;
9691 		else
9692 			syn_filter.hig_pri = 0;
9693 
9694 		syn_filter.queue = res->queue_id;
9695 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9696 						RTE_ETH_FILTER_SYN,
9697 						RTE_ETH_FILTER_ADD,
9698 						&syn_filter);
9699 	} else
9700 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9701 						RTE_ETH_FILTER_SYN,
9702 						RTE_ETH_FILTER_DELETE,
9703 						&syn_filter);
9704 
9705 	if (ret < 0)
9706 		printf("syn filter programming error: (%s)\n",
9707 				strerror(-ret));
9708 }
9709 
9710 cmdline_parse_token_string_t cmd_syn_filter_filter =
9711 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9712 	filter, "syn_filter");
9713 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9714 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9715 	port_id, UINT16);
9716 cmdline_parse_token_string_t cmd_syn_filter_ops =
9717 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9718 	ops, "add#del");
9719 cmdline_parse_token_string_t cmd_syn_filter_priority =
9720 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9721 				priority, "priority");
9722 cmdline_parse_token_string_t cmd_syn_filter_high =
9723 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9724 				high, "high#low");
9725 cmdline_parse_token_string_t cmd_syn_filter_queue =
9726 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9727 				queue, "queue");
9728 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9729 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9730 				queue_id, UINT16);
9731 
9732 cmdline_parse_inst_t cmd_syn_filter = {
9733 	.f = cmd_syn_filter_parsed,
9734 	.data = NULL,
9735 	.help_str = "syn_filter <port_id> add|del priority high|low queue "
9736 		"<queue_id>: Add/Delete syn filter",
9737 	.tokens = {
9738 		(void *)&cmd_syn_filter_filter,
9739 		(void *)&cmd_syn_filter_port_id,
9740 		(void *)&cmd_syn_filter_ops,
9741 		(void *)&cmd_syn_filter_priority,
9742 		(void *)&cmd_syn_filter_high,
9743 		(void *)&cmd_syn_filter_queue,
9744 		(void *)&cmd_syn_filter_queue_id,
9745 		NULL,
9746 	},
9747 };
9748 
9749 /* *** queue region set *** */
9750 struct cmd_queue_region_result {
9751 	cmdline_fixed_string_t set;
9752 	cmdline_fixed_string_t port;
9753 	portid_t port_id;
9754 	cmdline_fixed_string_t cmd;
9755 	cmdline_fixed_string_t region;
9756 	uint8_t  region_id;
9757 	cmdline_fixed_string_t queue_start_index;
9758 	uint8_t  queue_id;
9759 	cmdline_fixed_string_t queue_num;
9760 	uint8_t  queue_num_value;
9761 };
9762 
9763 static void
9764 cmd_queue_region_parsed(void *parsed_result,
9765 			__attribute__((unused)) struct cmdline *cl,
9766 			__attribute__((unused)) void *data)
9767 {
9768 	struct cmd_queue_region_result *res = parsed_result;
9769 	int ret = -ENOTSUP;
9770 #ifdef RTE_LIBRTE_I40E_PMD
9771 	struct rte_pmd_i40e_queue_region_conf region_conf;
9772 	enum rte_pmd_i40e_queue_region_op op_type;
9773 #endif
9774 
9775 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9776 		return;
9777 
9778 #ifdef RTE_LIBRTE_I40E_PMD
9779 	memset(&region_conf, 0, sizeof(region_conf));
9780 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9781 	region_conf.region_id = res->region_id;
9782 	region_conf.queue_num = res->queue_num_value;
9783 	region_conf.queue_start_index = res->queue_id;
9784 
9785 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9786 				op_type, &region_conf);
9787 #endif
9788 
9789 	switch (ret) {
9790 	case 0:
9791 		break;
9792 	case -ENOTSUP:
9793 		printf("function not implemented or supported\n");
9794 		break;
9795 	default:
9796 		printf("queue region config error: (%s)\n", strerror(-ret));
9797 	}
9798 }
9799 
9800 cmdline_parse_token_string_t cmd_queue_region_set =
9801 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9802 		set, "set");
9803 cmdline_parse_token_string_t cmd_queue_region_port =
9804 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9805 cmdline_parse_token_num_t cmd_queue_region_port_id =
9806 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9807 				port_id, UINT16);
9808 cmdline_parse_token_string_t cmd_queue_region_cmd =
9809 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9810 				 cmd, "queue-region");
9811 cmdline_parse_token_string_t cmd_queue_region_id =
9812 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9813 				region, "region_id");
9814 cmdline_parse_token_num_t cmd_queue_region_index =
9815 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9816 				region_id, UINT8);
9817 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9818 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9819 				queue_start_index, "queue_start_index");
9820 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9821 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9822 				queue_id, UINT8);
9823 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9824 	TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9825 				queue_num, "queue_num");
9826 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9827 	TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9828 				queue_num_value, UINT8);
9829 
9830 cmdline_parse_inst_t cmd_queue_region = {
9831 	.f = cmd_queue_region_parsed,
9832 	.data = NULL,
9833 	.help_str = "set port <port_id> queue-region region_id <value> "
9834 		"queue_start_index <value> queue_num <value>: Set a queue region",
9835 	.tokens = {
9836 		(void *)&cmd_queue_region_set,
9837 		(void *)&cmd_queue_region_port,
9838 		(void *)&cmd_queue_region_port_id,
9839 		(void *)&cmd_queue_region_cmd,
9840 		(void *)&cmd_queue_region_id,
9841 		(void *)&cmd_queue_region_index,
9842 		(void *)&cmd_queue_region_queue_start_index,
9843 		(void *)&cmd_queue_region_queue_id,
9844 		(void *)&cmd_queue_region_queue_num,
9845 		(void *)&cmd_queue_region_queue_num_value,
9846 		NULL,
9847 	},
9848 };
9849 
9850 /* *** queue region and flowtype set *** */
9851 struct cmd_region_flowtype_result {
9852 	cmdline_fixed_string_t set;
9853 	cmdline_fixed_string_t port;
9854 	portid_t port_id;
9855 	cmdline_fixed_string_t cmd;
9856 	cmdline_fixed_string_t region;
9857 	uint8_t  region_id;
9858 	cmdline_fixed_string_t flowtype;
9859 	uint8_t  flowtype_id;
9860 };
9861 
9862 static void
9863 cmd_region_flowtype_parsed(void *parsed_result,
9864 			__attribute__((unused)) struct cmdline *cl,
9865 			__attribute__((unused)) void *data)
9866 {
9867 	struct cmd_region_flowtype_result *res = parsed_result;
9868 	int ret = -ENOTSUP;
9869 #ifdef RTE_LIBRTE_I40E_PMD
9870 	struct rte_pmd_i40e_queue_region_conf region_conf;
9871 	enum rte_pmd_i40e_queue_region_op op_type;
9872 #endif
9873 
9874 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9875 		return;
9876 
9877 #ifdef RTE_LIBRTE_I40E_PMD
9878 	memset(&region_conf, 0, sizeof(region_conf));
9879 
9880 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9881 	region_conf.region_id = res->region_id;
9882 	region_conf.hw_flowtype = res->flowtype_id;
9883 
9884 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9885 			op_type, &region_conf);
9886 #endif
9887 
9888 	switch (ret) {
9889 	case 0:
9890 		break;
9891 	case -ENOTSUP:
9892 		printf("function not implemented or supported\n");
9893 		break;
9894 	default:
9895 		printf("region flowtype config error: (%s)\n", strerror(-ret));
9896 	}
9897 }
9898 
9899 cmdline_parse_token_string_t cmd_region_flowtype_set =
9900 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9901 				set, "set");
9902 cmdline_parse_token_string_t cmd_region_flowtype_port =
9903 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9904 				port, "port");
9905 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9906 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9907 				port_id, UINT16);
9908 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9909 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9910 				cmd, "queue-region");
9911 cmdline_parse_token_string_t cmd_region_flowtype_index =
9912 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9913 				region, "region_id");
9914 cmdline_parse_token_num_t cmd_region_flowtype_id =
9915 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9916 				region_id, UINT8);
9917 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9918 	TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9919 				flowtype, "flowtype");
9920 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9921 	TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9922 				flowtype_id, UINT8);
9923 cmdline_parse_inst_t cmd_region_flowtype = {
9924 	.f = cmd_region_flowtype_parsed,
9925 	.data = NULL,
9926 	.help_str = "set port <port_id> queue-region region_id <value> "
9927 		"flowtype <value>: Set a flowtype region index",
9928 	.tokens = {
9929 		(void *)&cmd_region_flowtype_set,
9930 		(void *)&cmd_region_flowtype_port,
9931 		(void *)&cmd_region_flowtype_port_index,
9932 		(void *)&cmd_region_flowtype_cmd,
9933 		(void *)&cmd_region_flowtype_index,
9934 		(void *)&cmd_region_flowtype_id,
9935 		(void *)&cmd_region_flowtype_flow_index,
9936 		(void *)&cmd_region_flowtype_flow_id,
9937 		NULL,
9938 	},
9939 };
9940 
9941 /* *** User Priority (UP) to queue region (region_id) set *** */
9942 struct cmd_user_priority_region_result {
9943 	cmdline_fixed_string_t set;
9944 	cmdline_fixed_string_t port;
9945 	portid_t port_id;
9946 	cmdline_fixed_string_t cmd;
9947 	cmdline_fixed_string_t user_priority;
9948 	uint8_t  user_priority_id;
9949 	cmdline_fixed_string_t region;
9950 	uint8_t  region_id;
9951 };
9952 
9953 static void
9954 cmd_user_priority_region_parsed(void *parsed_result,
9955 			__attribute__((unused)) struct cmdline *cl,
9956 			__attribute__((unused)) void *data)
9957 {
9958 	struct cmd_user_priority_region_result *res = parsed_result;
9959 	int ret = -ENOTSUP;
9960 #ifdef RTE_LIBRTE_I40E_PMD
9961 	struct rte_pmd_i40e_queue_region_conf region_conf;
9962 	enum rte_pmd_i40e_queue_region_op op_type;
9963 #endif
9964 
9965 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9966 		return;
9967 
9968 #ifdef RTE_LIBRTE_I40E_PMD
9969 	memset(&region_conf, 0, sizeof(region_conf));
9970 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9971 	region_conf.user_priority = res->user_priority_id;
9972 	region_conf.region_id = res->region_id;
9973 
9974 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9975 				op_type, &region_conf);
9976 #endif
9977 
9978 	switch (ret) {
9979 	case 0:
9980 		break;
9981 	case -ENOTSUP:
9982 		printf("function not implemented or supported\n");
9983 		break;
9984 	default:
9985 		printf("user_priority region config error: (%s)\n",
9986 				strerror(-ret));
9987 	}
9988 }
9989 
9990 cmdline_parse_token_string_t cmd_user_priority_region_set =
9991 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9992 				set, "set");
9993 cmdline_parse_token_string_t cmd_user_priority_region_port =
9994 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9995 				port, "port");
9996 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9997 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9998 				port_id, UINT16);
9999 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10000 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10001 				cmd, "queue-region");
10002 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10003 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10004 				user_priority, "UP");
10005 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10006 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10007 				user_priority_id, UINT8);
10008 cmdline_parse_token_string_t cmd_user_priority_region_region =
10009 	TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10010 				region, "region_id");
10011 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10012 	TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10013 				region_id, UINT8);
10014 
10015 cmdline_parse_inst_t cmd_user_priority_region = {
10016 	.f = cmd_user_priority_region_parsed,
10017 	.data = NULL,
10018 	.help_str = "set port <port_id> queue-region UP <value> "
10019 		"region_id <value>: Set the mapping of User Priority (UP) "
10020 		"to queue region (region_id) ",
10021 	.tokens = {
10022 		(void *)&cmd_user_priority_region_set,
10023 		(void *)&cmd_user_priority_region_port,
10024 		(void *)&cmd_user_priority_region_port_index,
10025 		(void *)&cmd_user_priority_region_cmd,
10026 		(void *)&cmd_user_priority_region_UP,
10027 		(void *)&cmd_user_priority_region_UP_id,
10028 		(void *)&cmd_user_priority_region_region,
10029 		(void *)&cmd_user_priority_region_region_id,
10030 		NULL,
10031 	},
10032 };
10033 
10034 /* *** flush all queue region related configuration *** */
10035 struct cmd_flush_queue_region_result {
10036 	cmdline_fixed_string_t set;
10037 	cmdline_fixed_string_t port;
10038 	portid_t port_id;
10039 	cmdline_fixed_string_t cmd;
10040 	cmdline_fixed_string_t flush;
10041 	cmdline_fixed_string_t what;
10042 };
10043 
10044 static void
10045 cmd_flush_queue_region_parsed(void *parsed_result,
10046 			__attribute__((unused)) struct cmdline *cl,
10047 			__attribute__((unused)) void *data)
10048 {
10049 	struct cmd_flush_queue_region_result *res = parsed_result;
10050 	int ret = -ENOTSUP;
10051 #ifdef RTE_LIBRTE_I40E_PMD
10052 	struct rte_pmd_i40e_queue_region_conf region_conf;
10053 	enum rte_pmd_i40e_queue_region_op op_type;
10054 #endif
10055 
10056 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10057 		return;
10058 
10059 #ifdef RTE_LIBRTE_I40E_PMD
10060 	memset(&region_conf, 0, sizeof(region_conf));
10061 
10062 	if (strcmp(res->what, "on") == 0)
10063 		op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10064 	else
10065 		op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10066 
10067 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10068 				op_type, &region_conf);
10069 #endif
10070 
10071 	switch (ret) {
10072 	case 0:
10073 		break;
10074 	case -ENOTSUP:
10075 		printf("function not implemented or supported\n");
10076 		break;
10077 	default:
10078 		printf("queue region config flush error: (%s)\n",
10079 				strerror(-ret));
10080 	}
10081 }
10082 
10083 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10084 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10085 				set, "set");
10086 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10087 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10088 				port, "port");
10089 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10090 	TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10091 				port_id, UINT16);
10092 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10093 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10094 				cmd, "queue-region");
10095 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10096 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10097 				flush, "flush");
10098 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10099 	TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10100 				what, "on#off");
10101 
10102 cmdline_parse_inst_t cmd_flush_queue_region = {
10103 	.f = cmd_flush_queue_region_parsed,
10104 	.data = NULL,
10105 	.help_str = "set port <port_id> queue-region flush on|off"
10106 		": flush all queue region related configuration",
10107 	.tokens = {
10108 		(void *)&cmd_flush_queue_region_set,
10109 		(void *)&cmd_flush_queue_region_port,
10110 		(void *)&cmd_flush_queue_region_port_index,
10111 		(void *)&cmd_flush_queue_region_cmd,
10112 		(void *)&cmd_flush_queue_region_flush,
10113 		(void *)&cmd_flush_queue_region_what,
10114 		NULL,
10115 	},
10116 };
10117 
10118 /* *** get all queue region related configuration info *** */
10119 struct cmd_show_queue_region_info {
10120 	cmdline_fixed_string_t show;
10121 	cmdline_fixed_string_t port;
10122 	portid_t port_id;
10123 	cmdline_fixed_string_t cmd;
10124 };
10125 
10126 static void
10127 cmd_show_queue_region_info_parsed(void *parsed_result,
10128 			__attribute__((unused)) struct cmdline *cl,
10129 			__attribute__((unused)) void *data)
10130 {
10131 	struct cmd_show_queue_region_info *res = parsed_result;
10132 	int ret = -ENOTSUP;
10133 #ifdef RTE_LIBRTE_I40E_PMD
10134 	struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10135 	enum rte_pmd_i40e_queue_region_op op_type;
10136 #endif
10137 
10138 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10139 		return;
10140 
10141 #ifdef RTE_LIBRTE_I40E_PMD
10142 	memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10143 
10144 	op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10145 
10146 	ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10147 					op_type, &rte_pmd_regions);
10148 
10149 	port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10150 #endif
10151 
10152 	switch (ret) {
10153 	case 0:
10154 		break;
10155 	case -ENOTSUP:
10156 		printf("function not implemented or supported\n");
10157 		break;
10158 	default:
10159 		printf("queue region config info show error: (%s)\n",
10160 				strerror(-ret));
10161 	}
10162 }
10163 
10164 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10165 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10166 				show, "show");
10167 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10168 	TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10169 				port, "port");
10170 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10171 	TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10172 				port_id, UINT16);
10173 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10174 	TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10175 				cmd, "queue-region");
10176 
10177 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10178 	.f = cmd_show_queue_region_info_parsed,
10179 	.data = NULL,
10180 	.help_str = "show port <port_id> queue-region"
10181 		": show all queue region related configuration info",
10182 	.tokens = {
10183 		(void *)&cmd_show_queue_region_info_get,
10184 		(void *)&cmd_show_queue_region_info_port,
10185 		(void *)&cmd_show_queue_region_info_port_index,
10186 		(void *)&cmd_show_queue_region_info_cmd,
10187 		NULL,
10188 	},
10189 };
10190 
10191 /* *** ADD/REMOVE A 2tuple FILTER *** */
10192 struct cmd_2tuple_filter_result {
10193 	cmdline_fixed_string_t filter;
10194 	portid_t port_id;
10195 	cmdline_fixed_string_t ops;
10196 	cmdline_fixed_string_t dst_port;
10197 	uint16_t dst_port_value;
10198 	cmdline_fixed_string_t protocol;
10199 	uint8_t protocol_value;
10200 	cmdline_fixed_string_t mask;
10201 	uint8_t  mask_value;
10202 	cmdline_fixed_string_t tcp_flags;
10203 	uint8_t tcp_flags_value;
10204 	cmdline_fixed_string_t priority;
10205 	uint8_t  priority_value;
10206 	cmdline_fixed_string_t queue;
10207 	uint16_t  queue_id;
10208 };
10209 
10210 static void
10211 cmd_2tuple_filter_parsed(void *parsed_result,
10212 			__attribute__((unused)) struct cmdline *cl,
10213 			__attribute__((unused)) void *data)
10214 {
10215 	struct rte_eth_ntuple_filter filter;
10216 	struct cmd_2tuple_filter_result *res = parsed_result;
10217 	int ret = 0;
10218 
10219 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10220 	if (ret < 0) {
10221 		printf("ntuple filter is not supported on port %u.\n",
10222 			res->port_id);
10223 		return;
10224 	}
10225 
10226 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10227 
10228 	filter.flags = RTE_2TUPLE_FLAGS;
10229 	filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10230 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10231 	filter.proto = res->protocol_value;
10232 	filter.priority = res->priority_value;
10233 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10234 		printf("nonzero tcp_flags is only meaningful"
10235 			" when protocol is TCP.\n");
10236 		return;
10237 	}
10238 	if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10239 		printf("invalid TCP flags.\n");
10240 		return;
10241 	}
10242 
10243 	if (res->tcp_flags_value != 0) {
10244 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10245 		filter.tcp_flags = res->tcp_flags_value;
10246 	}
10247 
10248 	/* need convert to big endian. */
10249 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10250 	filter.queue = res->queue_id;
10251 
10252 	if (!strcmp(res->ops, "add"))
10253 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10254 				RTE_ETH_FILTER_NTUPLE,
10255 				RTE_ETH_FILTER_ADD,
10256 				&filter);
10257 	else
10258 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10259 				RTE_ETH_FILTER_NTUPLE,
10260 				RTE_ETH_FILTER_DELETE,
10261 				&filter);
10262 	if (ret < 0)
10263 		printf("2tuple filter programming error: (%s)\n",
10264 			strerror(-ret));
10265 
10266 }
10267 
10268 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10269 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10270 				 filter, "2tuple_filter");
10271 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10272 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10273 				port_id, UINT16);
10274 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10275 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10276 				 ops, "add#del");
10277 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10278 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10279 				dst_port, "dst_port");
10280 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10281 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10282 				dst_port_value, UINT16);
10283 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10284 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10285 				protocol, "protocol");
10286 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10287 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10288 				protocol_value, UINT8);
10289 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10290 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10291 				mask, "mask");
10292 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10293 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10294 				mask_value, INT8);
10295 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10296 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10297 				tcp_flags, "tcp_flags");
10298 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10299 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10300 				tcp_flags_value, UINT8);
10301 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10302 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10303 				priority, "priority");
10304 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10305 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10306 				priority_value, UINT8);
10307 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10308 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10309 				queue, "queue");
10310 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10311 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10312 				queue_id, UINT16);
10313 
10314 cmdline_parse_inst_t cmd_2tuple_filter = {
10315 	.f = cmd_2tuple_filter_parsed,
10316 	.data = NULL,
10317 	.help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10318 		"<value> mask <value> tcp_flags <value> priority <value> queue "
10319 		"<queue_id>: Add a 2tuple filter",
10320 	.tokens = {
10321 		(void *)&cmd_2tuple_filter_filter,
10322 		(void *)&cmd_2tuple_filter_port_id,
10323 		(void *)&cmd_2tuple_filter_ops,
10324 		(void *)&cmd_2tuple_filter_dst_port,
10325 		(void *)&cmd_2tuple_filter_dst_port_value,
10326 		(void *)&cmd_2tuple_filter_protocol,
10327 		(void *)&cmd_2tuple_filter_protocol_value,
10328 		(void *)&cmd_2tuple_filter_mask,
10329 		(void *)&cmd_2tuple_filter_mask_value,
10330 		(void *)&cmd_2tuple_filter_tcp_flags,
10331 		(void *)&cmd_2tuple_filter_tcp_flags_value,
10332 		(void *)&cmd_2tuple_filter_priority,
10333 		(void *)&cmd_2tuple_filter_priority_value,
10334 		(void *)&cmd_2tuple_filter_queue,
10335 		(void *)&cmd_2tuple_filter_queue_id,
10336 		NULL,
10337 	},
10338 };
10339 
10340 /* *** ADD/REMOVE A 5tuple FILTER *** */
10341 struct cmd_5tuple_filter_result {
10342 	cmdline_fixed_string_t filter;
10343 	portid_t port_id;
10344 	cmdline_fixed_string_t ops;
10345 	cmdline_fixed_string_t dst_ip;
10346 	cmdline_ipaddr_t dst_ip_value;
10347 	cmdline_fixed_string_t src_ip;
10348 	cmdline_ipaddr_t src_ip_value;
10349 	cmdline_fixed_string_t dst_port;
10350 	uint16_t dst_port_value;
10351 	cmdline_fixed_string_t src_port;
10352 	uint16_t src_port_value;
10353 	cmdline_fixed_string_t protocol;
10354 	uint8_t protocol_value;
10355 	cmdline_fixed_string_t mask;
10356 	uint8_t  mask_value;
10357 	cmdline_fixed_string_t tcp_flags;
10358 	uint8_t tcp_flags_value;
10359 	cmdline_fixed_string_t priority;
10360 	uint8_t  priority_value;
10361 	cmdline_fixed_string_t queue;
10362 	uint16_t  queue_id;
10363 };
10364 
10365 static void
10366 cmd_5tuple_filter_parsed(void *parsed_result,
10367 			__attribute__((unused)) struct cmdline *cl,
10368 			__attribute__((unused)) void *data)
10369 {
10370 	struct rte_eth_ntuple_filter filter;
10371 	struct cmd_5tuple_filter_result *res = parsed_result;
10372 	int ret = 0;
10373 
10374 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10375 	if (ret < 0) {
10376 		printf("ntuple filter is not supported on port %u.\n",
10377 			res->port_id);
10378 		return;
10379 	}
10380 
10381 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10382 
10383 	filter.flags = RTE_5TUPLE_FLAGS;
10384 	filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10385 	filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10386 	filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10387 	filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10388 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10389 	filter.proto = res->protocol_value;
10390 	filter.priority = res->priority_value;
10391 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10392 		printf("nonzero tcp_flags is only meaningful"
10393 			" when protocol is TCP.\n");
10394 		return;
10395 	}
10396 	if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10397 		printf("invalid TCP flags.\n");
10398 		return;
10399 	}
10400 
10401 	if (res->tcp_flags_value != 0) {
10402 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10403 		filter.tcp_flags = res->tcp_flags_value;
10404 	}
10405 
10406 	if (res->dst_ip_value.family == AF_INET)
10407 		/* no need to convert, already big endian. */
10408 		filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10409 	else {
10410 		if (filter.dst_ip_mask == 0) {
10411 			printf("can not support ipv6 involved compare.\n");
10412 			return;
10413 		}
10414 		filter.dst_ip = 0;
10415 	}
10416 
10417 	if (res->src_ip_value.family == AF_INET)
10418 		/* no need to convert, already big endian. */
10419 		filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10420 	else {
10421 		if (filter.src_ip_mask == 0) {
10422 			printf("can not support ipv6 involved compare.\n");
10423 			return;
10424 		}
10425 		filter.src_ip = 0;
10426 	}
10427 	/* need convert to big endian. */
10428 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10429 	filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10430 	filter.queue = res->queue_id;
10431 
10432 	if (!strcmp(res->ops, "add"))
10433 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10434 				RTE_ETH_FILTER_NTUPLE,
10435 				RTE_ETH_FILTER_ADD,
10436 				&filter);
10437 	else
10438 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10439 				RTE_ETH_FILTER_NTUPLE,
10440 				RTE_ETH_FILTER_DELETE,
10441 				&filter);
10442 	if (ret < 0)
10443 		printf("5tuple filter programming error: (%s)\n",
10444 			strerror(-ret));
10445 }
10446 
10447 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10448 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10449 				 filter, "5tuple_filter");
10450 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10451 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10452 				port_id, UINT16);
10453 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10454 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10455 				 ops, "add#del");
10456 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10457 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10458 				dst_ip, "dst_ip");
10459 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10460 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10461 				dst_ip_value);
10462 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10463 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10464 				src_ip, "src_ip");
10465 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10466 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10467 				src_ip_value);
10468 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10469 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10470 				dst_port, "dst_port");
10471 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10472 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10473 				dst_port_value, UINT16);
10474 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10475 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10476 				src_port, "src_port");
10477 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10478 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10479 				src_port_value, UINT16);
10480 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10481 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10482 				protocol, "protocol");
10483 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10484 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10485 				protocol_value, UINT8);
10486 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10487 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10488 				mask, "mask");
10489 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10490 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10491 				mask_value, INT8);
10492 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10493 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10494 				tcp_flags, "tcp_flags");
10495 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10496 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10497 				tcp_flags_value, UINT8);
10498 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10499 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10500 				priority, "priority");
10501 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10502 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10503 				priority_value, UINT8);
10504 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10505 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10506 				queue, "queue");
10507 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10508 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10509 				queue_id, UINT16);
10510 
10511 cmdline_parse_inst_t cmd_5tuple_filter = {
10512 	.f = cmd_5tuple_filter_parsed,
10513 	.data = NULL,
10514 	.help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10515 		"src_ip <value> dst_port <value> src_port <value> "
10516 		"protocol <value>  mask <value> tcp_flags <value> "
10517 		"priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10518 	.tokens = {
10519 		(void *)&cmd_5tuple_filter_filter,
10520 		(void *)&cmd_5tuple_filter_port_id,
10521 		(void *)&cmd_5tuple_filter_ops,
10522 		(void *)&cmd_5tuple_filter_dst_ip,
10523 		(void *)&cmd_5tuple_filter_dst_ip_value,
10524 		(void *)&cmd_5tuple_filter_src_ip,
10525 		(void *)&cmd_5tuple_filter_src_ip_value,
10526 		(void *)&cmd_5tuple_filter_dst_port,
10527 		(void *)&cmd_5tuple_filter_dst_port_value,
10528 		(void *)&cmd_5tuple_filter_src_port,
10529 		(void *)&cmd_5tuple_filter_src_port_value,
10530 		(void *)&cmd_5tuple_filter_protocol,
10531 		(void *)&cmd_5tuple_filter_protocol_value,
10532 		(void *)&cmd_5tuple_filter_mask,
10533 		(void *)&cmd_5tuple_filter_mask_value,
10534 		(void *)&cmd_5tuple_filter_tcp_flags,
10535 		(void *)&cmd_5tuple_filter_tcp_flags_value,
10536 		(void *)&cmd_5tuple_filter_priority,
10537 		(void *)&cmd_5tuple_filter_priority_value,
10538 		(void *)&cmd_5tuple_filter_queue,
10539 		(void *)&cmd_5tuple_filter_queue_id,
10540 		NULL,
10541 	},
10542 };
10543 
10544 /* *** ADD/REMOVE A flex FILTER *** */
10545 struct cmd_flex_filter_result {
10546 	cmdline_fixed_string_t filter;
10547 	cmdline_fixed_string_t ops;
10548 	portid_t port_id;
10549 	cmdline_fixed_string_t len;
10550 	uint8_t len_value;
10551 	cmdline_fixed_string_t bytes;
10552 	cmdline_fixed_string_t bytes_value;
10553 	cmdline_fixed_string_t mask;
10554 	cmdline_fixed_string_t mask_value;
10555 	cmdline_fixed_string_t priority;
10556 	uint8_t priority_value;
10557 	cmdline_fixed_string_t queue;
10558 	uint16_t queue_id;
10559 };
10560 
10561 static int xdigit2val(unsigned char c)
10562 {
10563 	int val;
10564 	if (isdigit(c))
10565 		val = c - '0';
10566 	else if (isupper(c))
10567 		val = c - 'A' + 10;
10568 	else
10569 		val = c - 'a' + 10;
10570 	return val;
10571 }
10572 
10573 static void
10574 cmd_flex_filter_parsed(void *parsed_result,
10575 			  __attribute__((unused)) struct cmdline *cl,
10576 			  __attribute__((unused)) void *data)
10577 {
10578 	int ret = 0;
10579 	struct rte_eth_flex_filter filter;
10580 	struct cmd_flex_filter_result *res = parsed_result;
10581 	char *bytes_ptr, *mask_ptr;
10582 	uint16_t len, i, j = 0;
10583 	char c;
10584 	int val;
10585 	uint8_t byte = 0;
10586 
10587 	if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10588 		printf("the len exceed the max length 128\n");
10589 		return;
10590 	}
10591 	memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10592 	filter.len = res->len_value;
10593 	filter.priority = res->priority_value;
10594 	filter.queue = res->queue_id;
10595 	bytes_ptr = res->bytes_value;
10596 	mask_ptr = res->mask_value;
10597 
10598 	 /* translate bytes string to array. */
10599 	if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10600 		(bytes_ptr[1] == 'X')))
10601 		bytes_ptr += 2;
10602 	len = strnlen(bytes_ptr, res->len_value * 2);
10603 	if (len == 0 || (len % 8 != 0)) {
10604 		printf("please check len and bytes input\n");
10605 		return;
10606 	}
10607 	for (i = 0; i < len; i++) {
10608 		c = bytes_ptr[i];
10609 		if (isxdigit(c) == 0) {
10610 			/* invalid characters. */
10611 			printf("invalid input\n");
10612 			return;
10613 		}
10614 		val = xdigit2val(c);
10615 		if (i % 2) {
10616 			byte |= val;
10617 			filter.bytes[j] = byte;
10618 			printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10619 			j++;
10620 			byte = 0;
10621 		} else
10622 			byte |= val << 4;
10623 	}
10624 	printf("\n");
10625 	 /* translate mask string to uint8_t array. */
10626 	if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10627 		(mask_ptr[1] == 'X')))
10628 		mask_ptr += 2;
10629 	len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10630 	if (len == 0) {
10631 		printf("invalid input\n");
10632 		return;
10633 	}
10634 	j = 0;
10635 	byte = 0;
10636 	for (i = 0; i < len; i++) {
10637 		c = mask_ptr[i];
10638 		if (isxdigit(c) == 0) {
10639 			/* invalid characters. */
10640 			printf("invalid input\n");
10641 			return;
10642 		}
10643 		val = xdigit2val(c);
10644 		if (i % 2) {
10645 			byte |= val;
10646 			filter.mask[j] = byte;
10647 			printf("mask[%d]:%02x ", j, filter.mask[j]);
10648 			j++;
10649 			byte = 0;
10650 		} else
10651 			byte |= val << 4;
10652 	}
10653 	printf("\n");
10654 
10655 	if (!strcmp(res->ops, "add"))
10656 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10657 				RTE_ETH_FILTER_FLEXIBLE,
10658 				RTE_ETH_FILTER_ADD,
10659 				&filter);
10660 	else
10661 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10662 				RTE_ETH_FILTER_FLEXIBLE,
10663 				RTE_ETH_FILTER_DELETE,
10664 				&filter);
10665 
10666 	if (ret < 0)
10667 		printf("flex filter setting error: (%s)\n", strerror(-ret));
10668 }
10669 
10670 cmdline_parse_token_string_t cmd_flex_filter_filter =
10671 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10672 				filter, "flex_filter");
10673 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10674 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10675 				port_id, UINT16);
10676 cmdline_parse_token_string_t cmd_flex_filter_ops =
10677 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10678 				ops, "add#del");
10679 cmdline_parse_token_string_t cmd_flex_filter_len =
10680 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10681 				len, "len");
10682 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10683 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10684 				len_value, UINT8);
10685 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10686 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10687 				bytes, "bytes");
10688 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10689 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10690 				bytes_value, NULL);
10691 cmdline_parse_token_string_t cmd_flex_filter_mask =
10692 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10693 				mask, "mask");
10694 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10695 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10696 				mask_value, NULL);
10697 cmdline_parse_token_string_t cmd_flex_filter_priority =
10698 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10699 				priority, "priority");
10700 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10701 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10702 				priority_value, UINT8);
10703 cmdline_parse_token_string_t cmd_flex_filter_queue =
10704 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10705 				queue, "queue");
10706 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10707 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10708 				queue_id, UINT16);
10709 cmdline_parse_inst_t cmd_flex_filter = {
10710 	.f = cmd_flex_filter_parsed,
10711 	.data = NULL,
10712 	.help_str = "flex_filter <port_id> add|del len <value> bytes "
10713 		"<value> mask <value> priority <value> queue <queue_id>: "
10714 		"Add/Del a flex filter",
10715 	.tokens = {
10716 		(void *)&cmd_flex_filter_filter,
10717 		(void *)&cmd_flex_filter_port_id,
10718 		(void *)&cmd_flex_filter_ops,
10719 		(void *)&cmd_flex_filter_len,
10720 		(void *)&cmd_flex_filter_len_value,
10721 		(void *)&cmd_flex_filter_bytes,
10722 		(void *)&cmd_flex_filter_bytes_value,
10723 		(void *)&cmd_flex_filter_mask,
10724 		(void *)&cmd_flex_filter_mask_value,
10725 		(void *)&cmd_flex_filter_priority,
10726 		(void *)&cmd_flex_filter_priority_value,
10727 		(void *)&cmd_flex_filter_queue,
10728 		(void *)&cmd_flex_filter_queue_id,
10729 		NULL,
10730 	},
10731 };
10732 
10733 /* *** Filters Control *** */
10734 
10735 /* *** deal with ethertype filter *** */
10736 struct cmd_ethertype_filter_result {
10737 	cmdline_fixed_string_t filter;
10738 	portid_t port_id;
10739 	cmdline_fixed_string_t ops;
10740 	cmdline_fixed_string_t mac;
10741 	struct rte_ether_addr mac_addr;
10742 	cmdline_fixed_string_t ethertype;
10743 	uint16_t ethertype_value;
10744 	cmdline_fixed_string_t drop;
10745 	cmdline_fixed_string_t queue;
10746 	uint16_t  queue_id;
10747 };
10748 
10749 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10750 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10751 				 filter, "ethertype_filter");
10752 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10753 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10754 			      port_id, UINT16);
10755 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10756 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10757 				 ops, "add#del");
10758 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10759 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10760 				 mac, "mac_addr#mac_ignr");
10761 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10762 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10763 				     mac_addr);
10764 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10765 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10766 				 ethertype, "ethertype");
10767 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10768 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10769 			      ethertype_value, UINT16);
10770 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10771 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10772 				 drop, "drop#fwd");
10773 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10774 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10775 				 queue, "queue");
10776 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10777 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10778 			      queue_id, UINT16);
10779 
10780 static void
10781 cmd_ethertype_filter_parsed(void *parsed_result,
10782 			  __attribute__((unused)) struct cmdline *cl,
10783 			  __attribute__((unused)) void *data)
10784 {
10785 	struct cmd_ethertype_filter_result *res = parsed_result;
10786 	struct rte_eth_ethertype_filter filter;
10787 	int ret = 0;
10788 
10789 	ret = rte_eth_dev_filter_supported(res->port_id,
10790 			RTE_ETH_FILTER_ETHERTYPE);
10791 	if (ret < 0) {
10792 		printf("ethertype filter is not supported on port %u.\n",
10793 			res->port_id);
10794 		return;
10795 	}
10796 
10797 	memset(&filter, 0, sizeof(filter));
10798 	if (!strcmp(res->mac, "mac_addr")) {
10799 		filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10800 		rte_memcpy(&filter.mac_addr, &res->mac_addr,
10801 			sizeof(struct rte_ether_addr));
10802 	}
10803 	if (!strcmp(res->drop, "drop"))
10804 		filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10805 	filter.ether_type = res->ethertype_value;
10806 	filter.queue = res->queue_id;
10807 
10808 	if (!strcmp(res->ops, "add"))
10809 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10810 				RTE_ETH_FILTER_ETHERTYPE,
10811 				RTE_ETH_FILTER_ADD,
10812 				&filter);
10813 	else
10814 		ret = rte_eth_dev_filter_ctrl(res->port_id,
10815 				RTE_ETH_FILTER_ETHERTYPE,
10816 				RTE_ETH_FILTER_DELETE,
10817 				&filter);
10818 	if (ret < 0)
10819 		printf("ethertype filter programming error: (%s)\n",
10820 			strerror(-ret));
10821 }
10822 
10823 cmdline_parse_inst_t cmd_ethertype_filter = {
10824 	.f = cmd_ethertype_filter_parsed,
10825 	.data = NULL,
10826 	.help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10827 		"<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10828 		"Add or delete an ethertype filter entry",
10829 	.tokens = {
10830 		(void *)&cmd_ethertype_filter_filter,
10831 		(void *)&cmd_ethertype_filter_port_id,
10832 		(void *)&cmd_ethertype_filter_ops,
10833 		(void *)&cmd_ethertype_filter_mac,
10834 		(void *)&cmd_ethertype_filter_mac_addr,
10835 		(void *)&cmd_ethertype_filter_ethertype,
10836 		(void *)&cmd_ethertype_filter_ethertype_value,
10837 		(void *)&cmd_ethertype_filter_drop,
10838 		(void *)&cmd_ethertype_filter_queue,
10839 		(void *)&cmd_ethertype_filter_queue_id,
10840 		NULL,
10841 	},
10842 };
10843 
10844 /* *** deal with flow director filter *** */
10845 struct cmd_flow_director_result {
10846 	cmdline_fixed_string_t flow_director_filter;
10847 	portid_t port_id;
10848 	cmdline_fixed_string_t mode;
10849 	cmdline_fixed_string_t mode_value;
10850 	cmdline_fixed_string_t ops;
10851 	cmdline_fixed_string_t flow;
10852 	cmdline_fixed_string_t flow_type;
10853 	cmdline_fixed_string_t ether;
10854 	uint16_t ether_type;
10855 	cmdline_fixed_string_t src;
10856 	cmdline_ipaddr_t ip_src;
10857 	uint16_t port_src;
10858 	cmdline_fixed_string_t dst;
10859 	cmdline_ipaddr_t ip_dst;
10860 	uint16_t port_dst;
10861 	cmdline_fixed_string_t verify_tag;
10862 	uint32_t verify_tag_value;
10863 	cmdline_fixed_string_t tos;
10864 	uint8_t tos_value;
10865 	cmdline_fixed_string_t proto;
10866 	uint8_t proto_value;
10867 	cmdline_fixed_string_t ttl;
10868 	uint8_t ttl_value;
10869 	cmdline_fixed_string_t vlan;
10870 	uint16_t vlan_value;
10871 	cmdline_fixed_string_t flexbytes;
10872 	cmdline_fixed_string_t flexbytes_value;
10873 	cmdline_fixed_string_t pf_vf;
10874 	cmdline_fixed_string_t drop;
10875 	cmdline_fixed_string_t queue;
10876 	uint16_t  queue_id;
10877 	cmdline_fixed_string_t fd_id;
10878 	uint32_t  fd_id_value;
10879 	cmdline_fixed_string_t mac;
10880 	struct rte_ether_addr mac_addr;
10881 	cmdline_fixed_string_t tunnel;
10882 	cmdline_fixed_string_t tunnel_type;
10883 	cmdline_fixed_string_t tunnel_id;
10884 	uint32_t tunnel_id_value;
10885 	cmdline_fixed_string_t packet;
10886 	char filepath[];
10887 };
10888 
10889 static inline int
10890 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10891 {
10892 	char s[256];
10893 	const char *p, *p0 = q_arg;
10894 	char *end;
10895 	unsigned long int_fld;
10896 	char *str_fld[max_num];
10897 	int i;
10898 	unsigned size;
10899 	int ret = -1;
10900 
10901 	p = strchr(p0, '(');
10902 	if (p == NULL)
10903 		return -1;
10904 	++p;
10905 	p0 = strchr(p, ')');
10906 	if (p0 == NULL)
10907 		return -1;
10908 
10909 	size = p0 - p;
10910 	if (size >= sizeof(s))
10911 		return -1;
10912 
10913 	snprintf(s, sizeof(s), "%.*s", size, p);
10914 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10915 	if (ret < 0 || ret > max_num)
10916 		return -1;
10917 	for (i = 0; i < ret; i++) {
10918 		errno = 0;
10919 		int_fld = strtoul(str_fld[i], &end, 0);
10920 		if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10921 			return -1;
10922 		flexbytes[i] = (uint8_t)int_fld;
10923 	}
10924 	return ret;
10925 }
10926 
10927 static uint16_t
10928 str2flowtype(char *string)
10929 {
10930 	uint8_t i = 0;
10931 	static const struct {
10932 		char str[32];
10933 		uint16_t type;
10934 	} flowtype_str[] = {
10935 		{"raw", RTE_ETH_FLOW_RAW},
10936 		{"ipv4", RTE_ETH_FLOW_IPV4},
10937 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10938 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10939 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10940 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10941 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10942 		{"ipv6", RTE_ETH_FLOW_IPV6},
10943 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10944 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10945 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10946 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10947 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10948 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10949 	};
10950 
10951 	for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10952 		if (!strcmp(flowtype_str[i].str, string))
10953 			return flowtype_str[i].type;
10954 	}
10955 
10956 	if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10957 		return (uint16_t)atoi(string);
10958 
10959 	return RTE_ETH_FLOW_UNKNOWN;
10960 }
10961 
10962 static enum rte_eth_fdir_tunnel_type
10963 str2fdir_tunneltype(char *string)
10964 {
10965 	uint8_t i = 0;
10966 
10967 	static const struct {
10968 		char str[32];
10969 		enum rte_eth_fdir_tunnel_type type;
10970 	} tunneltype_str[] = {
10971 		{"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10972 		{"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10973 	};
10974 
10975 	for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10976 		if (!strcmp(tunneltype_str[i].str, string))
10977 			return tunneltype_str[i].type;
10978 	}
10979 	return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10980 }
10981 
10982 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10983 do { \
10984 	if ((ip_addr).family == AF_INET) \
10985 		(ip) = (ip_addr).addr.ipv4.s_addr; \
10986 	else { \
10987 		printf("invalid parameter.\n"); \
10988 		return; \
10989 	} \
10990 } while (0)
10991 
10992 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10993 do { \
10994 	if ((ip_addr).family == AF_INET6) \
10995 		rte_memcpy(&(ip), \
10996 				 &((ip_addr).addr.ipv6), \
10997 				 sizeof(struct in6_addr)); \
10998 	else { \
10999 		printf("invalid parameter.\n"); \
11000 		return; \
11001 	} \
11002 } while (0)
11003 
11004 static void
11005 cmd_flow_director_filter_parsed(void *parsed_result,
11006 			  __attribute__((unused)) struct cmdline *cl,
11007 			  __attribute__((unused)) void *data)
11008 {
11009 	struct cmd_flow_director_result *res = parsed_result;
11010 	struct rte_eth_fdir_filter entry;
11011 	uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11012 	char *end;
11013 	unsigned long vf_id;
11014 	int ret = 0;
11015 
11016 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11017 	if (ret < 0) {
11018 		printf("flow director is not supported on port %u.\n",
11019 			res->port_id);
11020 		return;
11021 	}
11022 	memset(flexbytes, 0, sizeof(flexbytes));
11023 	memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11024 
11025 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11026 		if (strcmp(res->mode_value, "MAC-VLAN")) {
11027 			printf("Please set mode to MAC-VLAN.\n");
11028 			return;
11029 		}
11030 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11031 		if (strcmp(res->mode_value, "Tunnel")) {
11032 			printf("Please set mode to Tunnel.\n");
11033 			return;
11034 		}
11035 	} else {
11036 		if (!strcmp(res->mode_value, "raw")) {
11037 #ifdef RTE_LIBRTE_I40E_PMD
11038 			struct rte_pmd_i40e_flow_type_mapping
11039 					mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11040 			struct rte_pmd_i40e_pkt_template_conf conf;
11041 			uint16_t flow_type = str2flowtype(res->flow_type);
11042 			uint16_t i, port = res->port_id;
11043 			uint8_t add;
11044 
11045 			memset(&conf, 0, sizeof(conf));
11046 
11047 			if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11048 				printf("Invalid flow type specified.\n");
11049 				return;
11050 			}
11051 			ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11052 								 mapping);
11053 			if (ret)
11054 				return;
11055 			if (mapping[flow_type].pctype == 0ULL) {
11056 				printf("Invalid flow type specified.\n");
11057 				return;
11058 			}
11059 			for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11060 				if (mapping[flow_type].pctype & (1ULL << i)) {
11061 					conf.input.pctype = i;
11062 					break;
11063 				}
11064 			}
11065 
11066 			conf.input.packet = open_file(res->filepath,
11067 						&conf.input.length);
11068 			if (!conf.input.packet)
11069 				return;
11070 			if (!strcmp(res->drop, "drop"))
11071 				conf.action.behavior =
11072 					RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11073 			else
11074 				conf.action.behavior =
11075 					RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11076 			conf.action.report_status =
11077 					RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11078 			conf.action.rx_queue = res->queue_id;
11079 			conf.soft_id = res->fd_id_value;
11080 			add  = strcmp(res->ops, "del") ? 1 : 0;
11081 			ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11082 									&conf,
11083 									add);
11084 			if (ret < 0)
11085 				printf("flow director config error: (%s)\n",
11086 				       strerror(-ret));
11087 			close_file(conf.input.packet);
11088 #endif
11089 			return;
11090 		} else if (strcmp(res->mode_value, "IP")) {
11091 			printf("Please set mode to IP or raw.\n");
11092 			return;
11093 		}
11094 		entry.input.flow_type = str2flowtype(res->flow_type);
11095 	}
11096 
11097 	ret = parse_flexbytes(res->flexbytes_value,
11098 					flexbytes,
11099 					RTE_ETH_FDIR_MAX_FLEXLEN);
11100 	if (ret < 0) {
11101 		printf("error: Cannot parse flexbytes input.\n");
11102 		return;
11103 	}
11104 
11105 	switch (entry.input.flow_type) {
11106 	case RTE_ETH_FLOW_FRAG_IPV4:
11107 	case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11108 		entry.input.flow.ip4_flow.proto = res->proto_value;
11109 		/* fall-through */
11110 	case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11111 	case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11112 		IPV4_ADDR_TO_UINT(res->ip_dst,
11113 			entry.input.flow.ip4_flow.dst_ip);
11114 		IPV4_ADDR_TO_UINT(res->ip_src,
11115 			entry.input.flow.ip4_flow.src_ip);
11116 		entry.input.flow.ip4_flow.tos = res->tos_value;
11117 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
11118 		/* need convert to big endian. */
11119 		entry.input.flow.udp4_flow.dst_port =
11120 				rte_cpu_to_be_16(res->port_dst);
11121 		entry.input.flow.udp4_flow.src_port =
11122 				rte_cpu_to_be_16(res->port_src);
11123 		break;
11124 	case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11125 		IPV4_ADDR_TO_UINT(res->ip_dst,
11126 			entry.input.flow.sctp4_flow.ip.dst_ip);
11127 		IPV4_ADDR_TO_UINT(res->ip_src,
11128 			entry.input.flow.sctp4_flow.ip.src_ip);
11129 		entry.input.flow.ip4_flow.tos = res->tos_value;
11130 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
11131 		/* need convert to big endian. */
11132 		entry.input.flow.sctp4_flow.dst_port =
11133 				rte_cpu_to_be_16(res->port_dst);
11134 		entry.input.flow.sctp4_flow.src_port =
11135 				rte_cpu_to_be_16(res->port_src);
11136 		entry.input.flow.sctp4_flow.verify_tag =
11137 				rte_cpu_to_be_32(res->verify_tag_value);
11138 		break;
11139 	case RTE_ETH_FLOW_FRAG_IPV6:
11140 	case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11141 		entry.input.flow.ipv6_flow.proto = res->proto_value;
11142 		/* fall-through */
11143 	case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11144 	case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11145 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
11146 			entry.input.flow.ipv6_flow.dst_ip);
11147 		IPV6_ADDR_TO_ARRAY(res->ip_src,
11148 			entry.input.flow.ipv6_flow.src_ip);
11149 		entry.input.flow.ipv6_flow.tc = res->tos_value;
11150 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11151 		/* need convert to big endian. */
11152 		entry.input.flow.udp6_flow.dst_port =
11153 				rte_cpu_to_be_16(res->port_dst);
11154 		entry.input.flow.udp6_flow.src_port =
11155 				rte_cpu_to_be_16(res->port_src);
11156 		break;
11157 	case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11158 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
11159 			entry.input.flow.sctp6_flow.ip.dst_ip);
11160 		IPV6_ADDR_TO_ARRAY(res->ip_src,
11161 			entry.input.flow.sctp6_flow.ip.src_ip);
11162 		entry.input.flow.ipv6_flow.tc = res->tos_value;
11163 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11164 		/* need convert to big endian. */
11165 		entry.input.flow.sctp6_flow.dst_port =
11166 				rte_cpu_to_be_16(res->port_dst);
11167 		entry.input.flow.sctp6_flow.src_port =
11168 				rte_cpu_to_be_16(res->port_src);
11169 		entry.input.flow.sctp6_flow.verify_tag =
11170 				rte_cpu_to_be_32(res->verify_tag_value);
11171 		break;
11172 	case RTE_ETH_FLOW_L2_PAYLOAD:
11173 		entry.input.flow.l2_flow.ether_type =
11174 			rte_cpu_to_be_16(res->ether_type);
11175 		break;
11176 	default:
11177 		break;
11178 	}
11179 
11180 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11181 		rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11182 				 &res->mac_addr,
11183 				 sizeof(struct rte_ether_addr));
11184 
11185 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11186 		rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11187 				 &res->mac_addr,
11188 				 sizeof(struct rte_ether_addr));
11189 		entry.input.flow.tunnel_flow.tunnel_type =
11190 			str2fdir_tunneltype(res->tunnel_type);
11191 		entry.input.flow.tunnel_flow.tunnel_id =
11192 			rte_cpu_to_be_32(res->tunnel_id_value);
11193 	}
11194 
11195 	rte_memcpy(entry.input.flow_ext.flexbytes,
11196 		   flexbytes,
11197 		   RTE_ETH_FDIR_MAX_FLEXLEN);
11198 
11199 	entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11200 
11201 	entry.action.flex_off = 0;  /*use 0 by default */
11202 	if (!strcmp(res->drop, "drop"))
11203 		entry.action.behavior = RTE_ETH_FDIR_REJECT;
11204 	else
11205 		entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11206 
11207 	if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11208 	    fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11209 		if (!strcmp(res->pf_vf, "pf"))
11210 			entry.input.flow_ext.is_vf = 0;
11211 		else if (!strncmp(res->pf_vf, "vf", 2)) {
11212 			struct rte_eth_dev_info dev_info;
11213 
11214 			ret = eth_dev_info_get_print_err(res->port_id,
11215 						&dev_info);
11216 			if (ret != 0)
11217 				return;
11218 
11219 			errno = 0;
11220 			vf_id = strtoul(res->pf_vf + 2, &end, 10);
11221 			if (errno != 0 || *end != '\0' ||
11222 			    vf_id >= dev_info.max_vfs) {
11223 				printf("invalid parameter %s.\n", res->pf_vf);
11224 				return;
11225 			}
11226 			entry.input.flow_ext.is_vf = 1;
11227 			entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11228 		} else {
11229 			printf("invalid parameter %s.\n", res->pf_vf);
11230 			return;
11231 		}
11232 	}
11233 
11234 	/* set to report FD ID by default */
11235 	entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11236 	entry.action.rx_queue = res->queue_id;
11237 	entry.soft_id = res->fd_id_value;
11238 	if (!strcmp(res->ops, "add"))
11239 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11240 					     RTE_ETH_FILTER_ADD, &entry);
11241 	else if (!strcmp(res->ops, "del"))
11242 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11243 					     RTE_ETH_FILTER_DELETE, &entry);
11244 	else
11245 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11246 					     RTE_ETH_FILTER_UPDATE, &entry);
11247 	if (ret < 0)
11248 		printf("flow director programming error: (%s)\n",
11249 			strerror(-ret));
11250 }
11251 
11252 cmdline_parse_token_string_t cmd_flow_director_filter =
11253 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11254 				 flow_director_filter, "flow_director_filter");
11255 cmdline_parse_token_num_t cmd_flow_director_port_id =
11256 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11257 			      port_id, UINT16);
11258 cmdline_parse_token_string_t cmd_flow_director_ops =
11259 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11260 				 ops, "add#del#update");
11261 cmdline_parse_token_string_t cmd_flow_director_flow =
11262 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11263 				 flow, "flow");
11264 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11265 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11266 		flow_type, NULL);
11267 cmdline_parse_token_string_t cmd_flow_director_ether =
11268 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11269 				 ether, "ether");
11270 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11271 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11272 			      ether_type, UINT16);
11273 cmdline_parse_token_string_t cmd_flow_director_src =
11274 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11275 				 src, "src");
11276 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11277 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11278 				 ip_src);
11279 cmdline_parse_token_num_t cmd_flow_director_port_src =
11280 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11281 			      port_src, UINT16);
11282 cmdline_parse_token_string_t cmd_flow_director_dst =
11283 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11284 				 dst, "dst");
11285 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11286 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11287 				 ip_dst);
11288 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11289 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11290 			      port_dst, UINT16);
11291 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11292 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11293 				  verify_tag, "verify_tag");
11294 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11295 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11296 			      verify_tag_value, UINT32);
11297 cmdline_parse_token_string_t cmd_flow_director_tos =
11298 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11299 				 tos, "tos");
11300 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11301 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11302 			      tos_value, UINT8);
11303 cmdline_parse_token_string_t cmd_flow_director_proto =
11304 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11305 				 proto, "proto");
11306 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11307 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11308 			      proto_value, UINT8);
11309 cmdline_parse_token_string_t cmd_flow_director_ttl =
11310 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11311 				 ttl, "ttl");
11312 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11313 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11314 			      ttl_value, UINT8);
11315 cmdline_parse_token_string_t cmd_flow_director_vlan =
11316 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11317 				 vlan, "vlan");
11318 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11319 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11320 			      vlan_value, UINT16);
11321 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11322 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11323 				 flexbytes, "flexbytes");
11324 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11325 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11326 			      flexbytes_value, NULL);
11327 cmdline_parse_token_string_t cmd_flow_director_drop =
11328 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11329 				 drop, "drop#fwd");
11330 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11331 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11332 			      pf_vf, NULL);
11333 cmdline_parse_token_string_t cmd_flow_director_queue =
11334 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11335 				 queue, "queue");
11336 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11337 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11338 			      queue_id, UINT16);
11339 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11340 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11341 				 fd_id, "fd_id");
11342 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11343 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11344 			      fd_id_value, UINT32);
11345 
11346 cmdline_parse_token_string_t cmd_flow_director_mode =
11347 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11348 				 mode, "mode");
11349 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11350 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11351 				 mode_value, "IP");
11352 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11353 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11354 				 mode_value, "MAC-VLAN");
11355 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11356 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11357 				 mode_value, "Tunnel");
11358 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11359 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11360 				 mode_value, "raw");
11361 cmdline_parse_token_string_t cmd_flow_director_mac =
11362 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11363 				 mac, "mac");
11364 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11365 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11366 				    mac_addr);
11367 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11368 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11369 				 tunnel, "tunnel");
11370 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11371 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11372 				 tunnel_type, "NVGRE#VxLAN");
11373 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11374 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11375 				 tunnel_id, "tunnel-id");
11376 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11377 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11378 			      tunnel_id_value, UINT32);
11379 cmdline_parse_token_string_t cmd_flow_director_packet =
11380 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11381 				 packet, "packet");
11382 cmdline_parse_token_string_t cmd_flow_director_filepath =
11383 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11384 				 filepath, NULL);
11385 
11386 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11387 	.f = cmd_flow_director_filter_parsed,
11388 	.data = NULL,
11389 	.help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11390 		" ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11391 		"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11392 		"l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11393 		"proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11394 		"flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11395 		"fd_id <fd_id_value>: "
11396 		"Add or delete an ip flow director entry on NIC",
11397 	.tokens = {
11398 		(void *)&cmd_flow_director_filter,
11399 		(void *)&cmd_flow_director_port_id,
11400 		(void *)&cmd_flow_director_mode,
11401 		(void *)&cmd_flow_director_mode_ip,
11402 		(void *)&cmd_flow_director_ops,
11403 		(void *)&cmd_flow_director_flow,
11404 		(void *)&cmd_flow_director_flow_type,
11405 		(void *)&cmd_flow_director_src,
11406 		(void *)&cmd_flow_director_ip_src,
11407 		(void *)&cmd_flow_director_dst,
11408 		(void *)&cmd_flow_director_ip_dst,
11409 		(void *)&cmd_flow_director_tos,
11410 		(void *)&cmd_flow_director_tos_value,
11411 		(void *)&cmd_flow_director_proto,
11412 		(void *)&cmd_flow_director_proto_value,
11413 		(void *)&cmd_flow_director_ttl,
11414 		(void *)&cmd_flow_director_ttl_value,
11415 		(void *)&cmd_flow_director_vlan,
11416 		(void *)&cmd_flow_director_vlan_value,
11417 		(void *)&cmd_flow_director_flexbytes,
11418 		(void *)&cmd_flow_director_flexbytes_value,
11419 		(void *)&cmd_flow_director_drop,
11420 		(void *)&cmd_flow_director_pf_vf,
11421 		(void *)&cmd_flow_director_queue,
11422 		(void *)&cmd_flow_director_queue_id,
11423 		(void *)&cmd_flow_director_fd_id,
11424 		(void *)&cmd_flow_director_fd_id_value,
11425 		NULL,
11426 	},
11427 };
11428 
11429 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11430 	.f = cmd_flow_director_filter_parsed,
11431 	.data = NULL,
11432 	.help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11433 		"director entry on NIC",
11434 	.tokens = {
11435 		(void *)&cmd_flow_director_filter,
11436 		(void *)&cmd_flow_director_port_id,
11437 		(void *)&cmd_flow_director_mode,
11438 		(void *)&cmd_flow_director_mode_ip,
11439 		(void *)&cmd_flow_director_ops,
11440 		(void *)&cmd_flow_director_flow,
11441 		(void *)&cmd_flow_director_flow_type,
11442 		(void *)&cmd_flow_director_src,
11443 		(void *)&cmd_flow_director_ip_src,
11444 		(void *)&cmd_flow_director_port_src,
11445 		(void *)&cmd_flow_director_dst,
11446 		(void *)&cmd_flow_director_ip_dst,
11447 		(void *)&cmd_flow_director_port_dst,
11448 		(void *)&cmd_flow_director_tos,
11449 		(void *)&cmd_flow_director_tos_value,
11450 		(void *)&cmd_flow_director_ttl,
11451 		(void *)&cmd_flow_director_ttl_value,
11452 		(void *)&cmd_flow_director_vlan,
11453 		(void *)&cmd_flow_director_vlan_value,
11454 		(void *)&cmd_flow_director_flexbytes,
11455 		(void *)&cmd_flow_director_flexbytes_value,
11456 		(void *)&cmd_flow_director_drop,
11457 		(void *)&cmd_flow_director_pf_vf,
11458 		(void *)&cmd_flow_director_queue,
11459 		(void *)&cmd_flow_director_queue_id,
11460 		(void *)&cmd_flow_director_fd_id,
11461 		(void *)&cmd_flow_director_fd_id_value,
11462 		NULL,
11463 	},
11464 };
11465 
11466 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11467 	.f = cmd_flow_director_filter_parsed,
11468 	.data = NULL,
11469 	.help_str = "flow_director_filter ... : Add or delete a sctp flow "
11470 		"director entry on NIC",
11471 	.tokens = {
11472 		(void *)&cmd_flow_director_filter,
11473 		(void *)&cmd_flow_director_port_id,
11474 		(void *)&cmd_flow_director_mode,
11475 		(void *)&cmd_flow_director_mode_ip,
11476 		(void *)&cmd_flow_director_ops,
11477 		(void *)&cmd_flow_director_flow,
11478 		(void *)&cmd_flow_director_flow_type,
11479 		(void *)&cmd_flow_director_src,
11480 		(void *)&cmd_flow_director_ip_src,
11481 		(void *)&cmd_flow_director_port_src,
11482 		(void *)&cmd_flow_director_dst,
11483 		(void *)&cmd_flow_director_ip_dst,
11484 		(void *)&cmd_flow_director_port_dst,
11485 		(void *)&cmd_flow_director_verify_tag,
11486 		(void *)&cmd_flow_director_verify_tag_value,
11487 		(void *)&cmd_flow_director_tos,
11488 		(void *)&cmd_flow_director_tos_value,
11489 		(void *)&cmd_flow_director_ttl,
11490 		(void *)&cmd_flow_director_ttl_value,
11491 		(void *)&cmd_flow_director_vlan,
11492 		(void *)&cmd_flow_director_vlan_value,
11493 		(void *)&cmd_flow_director_flexbytes,
11494 		(void *)&cmd_flow_director_flexbytes_value,
11495 		(void *)&cmd_flow_director_drop,
11496 		(void *)&cmd_flow_director_pf_vf,
11497 		(void *)&cmd_flow_director_queue,
11498 		(void *)&cmd_flow_director_queue_id,
11499 		(void *)&cmd_flow_director_fd_id,
11500 		(void *)&cmd_flow_director_fd_id_value,
11501 		NULL,
11502 	},
11503 };
11504 
11505 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11506 	.f = cmd_flow_director_filter_parsed,
11507 	.data = NULL,
11508 	.help_str = "flow_director_filter ... : Add or delete a L2 flow "
11509 		"director entry on NIC",
11510 	.tokens = {
11511 		(void *)&cmd_flow_director_filter,
11512 		(void *)&cmd_flow_director_port_id,
11513 		(void *)&cmd_flow_director_mode,
11514 		(void *)&cmd_flow_director_mode_ip,
11515 		(void *)&cmd_flow_director_ops,
11516 		(void *)&cmd_flow_director_flow,
11517 		(void *)&cmd_flow_director_flow_type,
11518 		(void *)&cmd_flow_director_ether,
11519 		(void *)&cmd_flow_director_ether_type,
11520 		(void *)&cmd_flow_director_flexbytes,
11521 		(void *)&cmd_flow_director_flexbytes_value,
11522 		(void *)&cmd_flow_director_drop,
11523 		(void *)&cmd_flow_director_pf_vf,
11524 		(void *)&cmd_flow_director_queue,
11525 		(void *)&cmd_flow_director_queue_id,
11526 		(void *)&cmd_flow_director_fd_id,
11527 		(void *)&cmd_flow_director_fd_id_value,
11528 		NULL,
11529 	},
11530 };
11531 
11532 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11533 	.f = cmd_flow_director_filter_parsed,
11534 	.data = NULL,
11535 	.help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11536 		"director entry on NIC",
11537 	.tokens = {
11538 		(void *)&cmd_flow_director_filter,
11539 		(void *)&cmd_flow_director_port_id,
11540 		(void *)&cmd_flow_director_mode,
11541 		(void *)&cmd_flow_director_mode_mac_vlan,
11542 		(void *)&cmd_flow_director_ops,
11543 		(void *)&cmd_flow_director_mac,
11544 		(void *)&cmd_flow_director_mac_addr,
11545 		(void *)&cmd_flow_director_vlan,
11546 		(void *)&cmd_flow_director_vlan_value,
11547 		(void *)&cmd_flow_director_flexbytes,
11548 		(void *)&cmd_flow_director_flexbytes_value,
11549 		(void *)&cmd_flow_director_drop,
11550 		(void *)&cmd_flow_director_queue,
11551 		(void *)&cmd_flow_director_queue_id,
11552 		(void *)&cmd_flow_director_fd_id,
11553 		(void *)&cmd_flow_director_fd_id_value,
11554 		NULL,
11555 	},
11556 };
11557 
11558 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11559 	.f = cmd_flow_director_filter_parsed,
11560 	.data = NULL,
11561 	.help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11562 		"director entry on NIC",
11563 	.tokens = {
11564 		(void *)&cmd_flow_director_filter,
11565 		(void *)&cmd_flow_director_port_id,
11566 		(void *)&cmd_flow_director_mode,
11567 		(void *)&cmd_flow_director_mode_tunnel,
11568 		(void *)&cmd_flow_director_ops,
11569 		(void *)&cmd_flow_director_mac,
11570 		(void *)&cmd_flow_director_mac_addr,
11571 		(void *)&cmd_flow_director_vlan,
11572 		(void *)&cmd_flow_director_vlan_value,
11573 		(void *)&cmd_flow_director_tunnel,
11574 		(void *)&cmd_flow_director_tunnel_type,
11575 		(void *)&cmd_flow_director_tunnel_id,
11576 		(void *)&cmd_flow_director_tunnel_id_value,
11577 		(void *)&cmd_flow_director_flexbytes,
11578 		(void *)&cmd_flow_director_flexbytes_value,
11579 		(void *)&cmd_flow_director_drop,
11580 		(void *)&cmd_flow_director_queue,
11581 		(void *)&cmd_flow_director_queue_id,
11582 		(void *)&cmd_flow_director_fd_id,
11583 		(void *)&cmd_flow_director_fd_id_value,
11584 		NULL,
11585 	},
11586 };
11587 
11588 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11589 	.f = cmd_flow_director_filter_parsed,
11590 	.data = NULL,
11591 	.help_str = "flow_director_filter ... : Add or delete a raw flow "
11592 		"director entry on NIC",
11593 	.tokens = {
11594 		(void *)&cmd_flow_director_filter,
11595 		(void *)&cmd_flow_director_port_id,
11596 		(void *)&cmd_flow_director_mode,
11597 		(void *)&cmd_flow_director_mode_raw,
11598 		(void *)&cmd_flow_director_ops,
11599 		(void *)&cmd_flow_director_flow,
11600 		(void *)&cmd_flow_director_flow_type,
11601 		(void *)&cmd_flow_director_drop,
11602 		(void *)&cmd_flow_director_queue,
11603 		(void *)&cmd_flow_director_queue_id,
11604 		(void *)&cmd_flow_director_fd_id,
11605 		(void *)&cmd_flow_director_fd_id_value,
11606 		(void *)&cmd_flow_director_packet,
11607 		(void *)&cmd_flow_director_filepath,
11608 		NULL,
11609 	},
11610 };
11611 
11612 struct cmd_flush_flow_director_result {
11613 	cmdline_fixed_string_t flush_flow_director;
11614 	portid_t port_id;
11615 };
11616 
11617 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11618 	TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11619 				 flush_flow_director, "flush_flow_director");
11620 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11621 	TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11622 			      port_id, UINT16);
11623 
11624 static void
11625 cmd_flush_flow_director_parsed(void *parsed_result,
11626 			  __attribute__((unused)) struct cmdline *cl,
11627 			  __attribute__((unused)) void *data)
11628 {
11629 	struct cmd_flow_director_result *res = parsed_result;
11630 	int ret = 0;
11631 
11632 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11633 	if (ret < 0) {
11634 		printf("flow director is not supported on port %u.\n",
11635 			res->port_id);
11636 		return;
11637 	}
11638 
11639 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11640 			RTE_ETH_FILTER_FLUSH, NULL);
11641 	if (ret < 0)
11642 		printf("flow director table flushing error: (%s)\n",
11643 			strerror(-ret));
11644 }
11645 
11646 cmdline_parse_inst_t cmd_flush_flow_director = {
11647 	.f = cmd_flush_flow_director_parsed,
11648 	.data = NULL,
11649 	.help_str = "flush_flow_director <port_id>: "
11650 		"Flush all flow director entries of a device on NIC",
11651 	.tokens = {
11652 		(void *)&cmd_flush_flow_director_flush,
11653 		(void *)&cmd_flush_flow_director_port_id,
11654 		NULL,
11655 	},
11656 };
11657 
11658 /* *** deal with flow director mask *** */
11659 struct cmd_flow_director_mask_result {
11660 	cmdline_fixed_string_t flow_director_mask;
11661 	portid_t port_id;
11662 	cmdline_fixed_string_t mode;
11663 	cmdline_fixed_string_t mode_value;
11664 	cmdline_fixed_string_t vlan;
11665 	uint16_t vlan_mask;
11666 	cmdline_fixed_string_t src_mask;
11667 	cmdline_ipaddr_t ipv4_src;
11668 	cmdline_ipaddr_t ipv6_src;
11669 	uint16_t port_src;
11670 	cmdline_fixed_string_t dst_mask;
11671 	cmdline_ipaddr_t ipv4_dst;
11672 	cmdline_ipaddr_t ipv6_dst;
11673 	uint16_t port_dst;
11674 	cmdline_fixed_string_t mac;
11675 	uint8_t mac_addr_byte_mask;
11676 	cmdline_fixed_string_t tunnel_id;
11677 	uint32_t tunnel_id_mask;
11678 	cmdline_fixed_string_t tunnel_type;
11679 	uint8_t tunnel_type_mask;
11680 };
11681 
11682 static void
11683 cmd_flow_director_mask_parsed(void *parsed_result,
11684 			  __attribute__((unused)) struct cmdline *cl,
11685 			  __attribute__((unused)) void *data)
11686 {
11687 	struct cmd_flow_director_mask_result *res = parsed_result;
11688 	struct rte_eth_fdir_masks *mask;
11689 	struct rte_port *port;
11690 
11691 	port = &ports[res->port_id];
11692 	/** Check if the port is not started **/
11693 	if (port->port_status != RTE_PORT_STOPPED) {
11694 		printf("Please stop port %d first\n", res->port_id);
11695 		return;
11696 	}
11697 
11698 	mask = &port->dev_conf.fdir_conf.mask;
11699 
11700 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11701 		if (strcmp(res->mode_value, "MAC-VLAN")) {
11702 			printf("Please set mode to MAC-VLAN.\n");
11703 			return;
11704 		}
11705 
11706 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11707 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11708 		if (strcmp(res->mode_value, "Tunnel")) {
11709 			printf("Please set mode to Tunnel.\n");
11710 			return;
11711 		}
11712 
11713 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11714 		mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11715 		mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11716 		mask->tunnel_type_mask = res->tunnel_type_mask;
11717 	} else {
11718 		if (strcmp(res->mode_value, "IP")) {
11719 			printf("Please set mode to IP.\n");
11720 			return;
11721 		}
11722 
11723 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11724 		IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11725 		IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11726 		IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11727 		IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11728 		mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11729 		mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11730 	}
11731 
11732 	cmd_reconfig_device_queue(res->port_id, 1, 1);
11733 }
11734 
11735 cmdline_parse_token_string_t cmd_flow_director_mask =
11736 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11737 				 flow_director_mask, "flow_director_mask");
11738 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11739 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11740 			      port_id, UINT16);
11741 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11742 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11743 				 vlan, "vlan");
11744 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11745 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11746 			      vlan_mask, UINT16);
11747 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11748 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11749 				 src_mask, "src_mask");
11750 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11751 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11752 				 ipv4_src);
11753 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11754 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11755 				 ipv6_src);
11756 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11757 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11758 			      port_src, UINT16);
11759 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11760 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11761 				 dst_mask, "dst_mask");
11762 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11763 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11764 				 ipv4_dst);
11765 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11766 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11767 				 ipv6_dst);
11768 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11769 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11770 			      port_dst, UINT16);
11771 
11772 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11773 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11774 				 mode, "mode");
11775 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11776 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11777 				 mode_value, "IP");
11778 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11779 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11780 				 mode_value, "MAC-VLAN");
11781 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11782 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11783 				 mode_value, "Tunnel");
11784 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11785 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11786 				 mac, "mac");
11787 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11788 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11789 			      mac_addr_byte_mask, UINT8);
11790 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11791 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11792 				 tunnel_type, "tunnel-type");
11793 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11794 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11795 			      tunnel_type_mask, UINT8);
11796 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11797 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11798 				 tunnel_id, "tunnel-id");
11799 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11800 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11801 			      tunnel_id_mask, UINT32);
11802 
11803 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11804 	.f = cmd_flow_director_mask_parsed,
11805 	.data = NULL,
11806 	.help_str = "flow_director_mask ... : "
11807 		"Set IP mode flow director's mask on NIC",
11808 	.tokens = {
11809 		(void *)&cmd_flow_director_mask,
11810 		(void *)&cmd_flow_director_mask_port_id,
11811 		(void *)&cmd_flow_director_mask_mode,
11812 		(void *)&cmd_flow_director_mask_mode_ip,
11813 		(void *)&cmd_flow_director_mask_vlan,
11814 		(void *)&cmd_flow_director_mask_vlan_value,
11815 		(void *)&cmd_flow_director_mask_src,
11816 		(void *)&cmd_flow_director_mask_ipv4_src,
11817 		(void *)&cmd_flow_director_mask_ipv6_src,
11818 		(void *)&cmd_flow_director_mask_port_src,
11819 		(void *)&cmd_flow_director_mask_dst,
11820 		(void *)&cmd_flow_director_mask_ipv4_dst,
11821 		(void *)&cmd_flow_director_mask_ipv6_dst,
11822 		(void *)&cmd_flow_director_mask_port_dst,
11823 		NULL,
11824 	},
11825 };
11826 
11827 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11828 	.f = cmd_flow_director_mask_parsed,
11829 	.data = NULL,
11830 	.help_str = "flow_director_mask ... : Set MAC VLAN mode "
11831 		"flow director's mask on NIC",
11832 	.tokens = {
11833 		(void *)&cmd_flow_director_mask,
11834 		(void *)&cmd_flow_director_mask_port_id,
11835 		(void *)&cmd_flow_director_mask_mode,
11836 		(void *)&cmd_flow_director_mask_mode_mac_vlan,
11837 		(void *)&cmd_flow_director_mask_vlan,
11838 		(void *)&cmd_flow_director_mask_vlan_value,
11839 		NULL,
11840 	},
11841 };
11842 
11843 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11844 	.f = cmd_flow_director_mask_parsed,
11845 	.data = NULL,
11846 	.help_str = "flow_director_mask ... : Set tunnel mode "
11847 		"flow director's mask on NIC",
11848 	.tokens = {
11849 		(void *)&cmd_flow_director_mask,
11850 		(void *)&cmd_flow_director_mask_port_id,
11851 		(void *)&cmd_flow_director_mask_mode,
11852 		(void *)&cmd_flow_director_mask_mode_tunnel,
11853 		(void *)&cmd_flow_director_mask_vlan,
11854 		(void *)&cmd_flow_director_mask_vlan_value,
11855 		(void *)&cmd_flow_director_mask_mac,
11856 		(void *)&cmd_flow_director_mask_mac_value,
11857 		(void *)&cmd_flow_director_mask_tunnel_type,
11858 		(void *)&cmd_flow_director_mask_tunnel_type_value,
11859 		(void *)&cmd_flow_director_mask_tunnel_id,
11860 		(void *)&cmd_flow_director_mask_tunnel_id_value,
11861 		NULL,
11862 	},
11863 };
11864 
11865 /* *** deal with flow director mask on flexible payload *** */
11866 struct cmd_flow_director_flex_mask_result {
11867 	cmdline_fixed_string_t flow_director_flexmask;
11868 	portid_t port_id;
11869 	cmdline_fixed_string_t flow;
11870 	cmdline_fixed_string_t flow_type;
11871 	cmdline_fixed_string_t mask;
11872 };
11873 
11874 static void
11875 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11876 			  __attribute__((unused)) struct cmdline *cl,
11877 			  __attribute__((unused)) void *data)
11878 {
11879 	struct cmd_flow_director_flex_mask_result *res = parsed_result;
11880 	struct rte_eth_fdir_info fdir_info;
11881 	struct rte_eth_fdir_flex_mask flex_mask;
11882 	struct rte_port *port;
11883 	uint64_t flow_type_mask;
11884 	uint16_t i;
11885 	int ret;
11886 
11887 	port = &ports[res->port_id];
11888 	/** Check if the port is not started **/
11889 	if (port->port_status != RTE_PORT_STOPPED) {
11890 		printf("Please stop port %d first\n", res->port_id);
11891 		return;
11892 	}
11893 
11894 	memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11895 	ret = parse_flexbytes(res->mask,
11896 			flex_mask.mask,
11897 			RTE_ETH_FDIR_MAX_FLEXLEN);
11898 	if (ret < 0) {
11899 		printf("error: Cannot parse mask input.\n");
11900 		return;
11901 	}
11902 
11903 	memset(&fdir_info, 0, sizeof(fdir_info));
11904 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11905 				RTE_ETH_FILTER_INFO, &fdir_info);
11906 	if (ret < 0) {
11907 		printf("Cannot get FDir filter info\n");
11908 		return;
11909 	}
11910 
11911 	if (!strcmp(res->flow_type, "none")) {
11912 		/* means don't specify the flow type */
11913 		flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11914 		for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11915 			memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11916 			       0, sizeof(struct rte_eth_fdir_flex_mask));
11917 		port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11918 		rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11919 				 &flex_mask,
11920 				 sizeof(struct rte_eth_fdir_flex_mask));
11921 		cmd_reconfig_device_queue(res->port_id, 1, 1);
11922 		return;
11923 	}
11924 	flow_type_mask = fdir_info.flow_types_mask[0];
11925 	if (!strcmp(res->flow_type, "all")) {
11926 		if (!flow_type_mask) {
11927 			printf("No flow type supported\n");
11928 			return;
11929 		}
11930 		for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11931 			if (flow_type_mask & (1ULL << i)) {
11932 				flex_mask.flow_type = i;
11933 				fdir_set_flex_mask(res->port_id, &flex_mask);
11934 			}
11935 		}
11936 		cmd_reconfig_device_queue(res->port_id, 1, 1);
11937 		return;
11938 	}
11939 	flex_mask.flow_type = str2flowtype(res->flow_type);
11940 	if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11941 		printf("Flow type %s not supported on port %d\n",
11942 				res->flow_type, res->port_id);
11943 		return;
11944 	}
11945 	fdir_set_flex_mask(res->port_id, &flex_mask);
11946 	cmd_reconfig_device_queue(res->port_id, 1, 1);
11947 }
11948 
11949 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11950 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11951 				 flow_director_flexmask,
11952 				 "flow_director_flex_mask");
11953 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11954 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11955 			      port_id, UINT16);
11956 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11957 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11958 				 flow, "flow");
11959 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11960 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11961 		flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11962 		"ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11963 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11964 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11965 				 mask, NULL);
11966 
11967 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11968 	.f = cmd_flow_director_flex_mask_parsed,
11969 	.data = NULL,
11970 	.help_str = "flow_director_flex_mask ... : "
11971 		"Set flow director's flex mask on NIC",
11972 	.tokens = {
11973 		(void *)&cmd_flow_director_flexmask,
11974 		(void *)&cmd_flow_director_flexmask_port_id,
11975 		(void *)&cmd_flow_director_flexmask_flow,
11976 		(void *)&cmd_flow_director_flexmask_flow_type,
11977 		(void *)&cmd_flow_director_flexmask_mask,
11978 		NULL,
11979 	},
11980 };
11981 
11982 /* *** deal with flow director flexible payload configuration *** */
11983 struct cmd_flow_director_flexpayload_result {
11984 	cmdline_fixed_string_t flow_director_flexpayload;
11985 	portid_t port_id;
11986 	cmdline_fixed_string_t payload_layer;
11987 	cmdline_fixed_string_t payload_cfg;
11988 };
11989 
11990 static inline int
11991 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11992 {
11993 	char s[256];
11994 	const char *p, *p0 = q_arg;
11995 	char *end;
11996 	unsigned long int_fld;
11997 	char *str_fld[max_num];
11998 	int i;
11999 	unsigned size;
12000 	int ret = -1;
12001 
12002 	p = strchr(p0, '(');
12003 	if (p == NULL)
12004 		return -1;
12005 	++p;
12006 	p0 = strchr(p, ')');
12007 	if (p0 == NULL)
12008 		return -1;
12009 
12010 	size = p0 - p;
12011 	if (size >= sizeof(s))
12012 		return -1;
12013 
12014 	snprintf(s, sizeof(s), "%.*s", size, p);
12015 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12016 	if (ret < 0 || ret > max_num)
12017 		return -1;
12018 	for (i = 0; i < ret; i++) {
12019 		errno = 0;
12020 		int_fld = strtoul(str_fld[i], &end, 0);
12021 		if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12022 			return -1;
12023 		offsets[i] = (uint16_t)int_fld;
12024 	}
12025 	return ret;
12026 }
12027 
12028 static void
12029 cmd_flow_director_flxpld_parsed(void *parsed_result,
12030 			  __attribute__((unused)) struct cmdline *cl,
12031 			  __attribute__((unused)) void *data)
12032 {
12033 	struct cmd_flow_director_flexpayload_result *res = parsed_result;
12034 	struct rte_eth_flex_payload_cfg flex_cfg;
12035 	struct rte_port *port;
12036 	int ret = 0;
12037 
12038 	port = &ports[res->port_id];
12039 	/** Check if the port is not started **/
12040 	if (port->port_status != RTE_PORT_STOPPED) {
12041 		printf("Please stop port %d first\n", res->port_id);
12042 		return;
12043 	}
12044 
12045 	memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12046 
12047 	if (!strcmp(res->payload_layer, "raw"))
12048 		flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12049 	else if (!strcmp(res->payload_layer, "l2"))
12050 		flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12051 	else if (!strcmp(res->payload_layer, "l3"))
12052 		flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12053 	else if (!strcmp(res->payload_layer, "l4"))
12054 		flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12055 
12056 	ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12057 			    RTE_ETH_FDIR_MAX_FLEXLEN);
12058 	if (ret < 0) {
12059 		printf("error: Cannot parse flex payload input.\n");
12060 		return;
12061 	}
12062 
12063 	fdir_set_flex_payload(res->port_id, &flex_cfg);
12064 	cmd_reconfig_device_queue(res->port_id, 1, 1);
12065 }
12066 
12067 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12068 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12069 				 flow_director_flexpayload,
12070 				 "flow_director_flex_payload");
12071 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12072 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12073 			      port_id, UINT16);
12074 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12075 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12076 				 payload_layer, "raw#l2#l3#l4");
12077 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12078 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12079 				 payload_cfg, NULL);
12080 
12081 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12082 	.f = cmd_flow_director_flxpld_parsed,
12083 	.data = NULL,
12084 	.help_str = "flow_director_flexpayload ... : "
12085 		"Set flow director's flex payload on NIC",
12086 	.tokens = {
12087 		(void *)&cmd_flow_director_flexpayload,
12088 		(void *)&cmd_flow_director_flexpayload_port_id,
12089 		(void *)&cmd_flow_director_flexpayload_payload_layer,
12090 		(void *)&cmd_flow_director_flexpayload_payload_cfg,
12091 		NULL,
12092 	},
12093 };
12094 
12095 /* Generic flow interface command. */
12096 extern cmdline_parse_inst_t cmd_flow;
12097 
12098 /* *** Classification Filters Control *** */
12099 /* *** Get symmetric hash enable per port *** */
12100 struct cmd_get_sym_hash_ena_per_port_result {
12101 	cmdline_fixed_string_t get_sym_hash_ena_per_port;
12102 	portid_t port_id;
12103 };
12104 
12105 static void
12106 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12107 				 __rte_unused struct cmdline *cl,
12108 				 __rte_unused void *data)
12109 {
12110 	struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12111 	struct rte_eth_hash_filter_info info;
12112 	int ret;
12113 
12114 	if (rte_eth_dev_filter_supported(res->port_id,
12115 				RTE_ETH_FILTER_HASH) < 0) {
12116 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12117 							res->port_id);
12118 		return;
12119 	}
12120 
12121 	memset(&info, 0, sizeof(info));
12122 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12123 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12124 						RTE_ETH_FILTER_GET, &info);
12125 
12126 	if (ret < 0) {
12127 		printf("Cannot get symmetric hash enable per port "
12128 					"on port %u\n", res->port_id);
12129 		return;
12130 	}
12131 
12132 	printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12133 				"enabled" : "disabled", res->port_id);
12134 }
12135 
12136 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12137 	TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12138 		get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12139 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12140 	TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12141 		port_id, UINT16);
12142 
12143 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12144 	.f = cmd_get_sym_hash_per_port_parsed,
12145 	.data = NULL,
12146 	.help_str = "get_sym_hash_ena_per_port <port_id>",
12147 	.tokens = {
12148 		(void *)&cmd_get_sym_hash_ena_per_port_all,
12149 		(void *)&cmd_get_sym_hash_ena_per_port_port_id,
12150 		NULL,
12151 	},
12152 };
12153 
12154 /* *** Set symmetric hash enable per port *** */
12155 struct cmd_set_sym_hash_ena_per_port_result {
12156 	cmdline_fixed_string_t set_sym_hash_ena_per_port;
12157 	cmdline_fixed_string_t enable;
12158 	portid_t port_id;
12159 };
12160 
12161 static void
12162 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12163 				 __rte_unused struct cmdline *cl,
12164 				 __rte_unused void *data)
12165 {
12166 	struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12167 	struct rte_eth_hash_filter_info info;
12168 	int ret;
12169 
12170 	if (rte_eth_dev_filter_supported(res->port_id,
12171 				RTE_ETH_FILTER_HASH) < 0) {
12172 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12173 							res->port_id);
12174 		return;
12175 	}
12176 
12177 	memset(&info, 0, sizeof(info));
12178 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12179 	if (!strcmp(res->enable, "enable"))
12180 		info.info.enable = 1;
12181 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12182 					RTE_ETH_FILTER_SET, &info);
12183 	if (ret < 0) {
12184 		printf("Cannot set symmetric hash enable per port on "
12185 					"port %u\n", res->port_id);
12186 		return;
12187 	}
12188 	printf("Symmetric hash has been set to %s on port %u\n",
12189 					res->enable, res->port_id);
12190 }
12191 
12192 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12193 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12194 		set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12195 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12196 	TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12197 		port_id, UINT16);
12198 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12199 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12200 		enable, "enable#disable");
12201 
12202 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12203 	.f = cmd_set_sym_hash_per_port_parsed,
12204 	.data = NULL,
12205 	.help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12206 	.tokens = {
12207 		(void *)&cmd_set_sym_hash_ena_per_port_all,
12208 		(void *)&cmd_set_sym_hash_ena_per_port_port_id,
12209 		(void *)&cmd_set_sym_hash_ena_per_port_enable,
12210 		NULL,
12211 	},
12212 };
12213 
12214 /* Get global config of hash function */
12215 struct cmd_get_hash_global_config_result {
12216 	cmdline_fixed_string_t get_hash_global_config;
12217 	portid_t port_id;
12218 };
12219 
12220 static char *
12221 flowtype_to_str(uint16_t ftype)
12222 {
12223 	uint16_t i;
12224 	static struct {
12225 		char str[16];
12226 		uint16_t ftype;
12227 	} ftype_table[] = {
12228 		{"ipv4", RTE_ETH_FLOW_IPV4},
12229 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12230 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12231 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12232 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12233 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12234 		{"ipv6", RTE_ETH_FLOW_IPV6},
12235 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12236 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12237 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12238 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12239 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12240 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12241 		{"port", RTE_ETH_FLOW_PORT},
12242 		{"vxlan", RTE_ETH_FLOW_VXLAN},
12243 		{"geneve", RTE_ETH_FLOW_GENEVE},
12244 		{"nvgre", RTE_ETH_FLOW_NVGRE},
12245 		{"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12246 	};
12247 
12248 	for (i = 0; i < RTE_DIM(ftype_table); i++) {
12249 		if (ftype_table[i].ftype == ftype)
12250 			return ftype_table[i].str;
12251 	}
12252 
12253 	return NULL;
12254 }
12255 
12256 static void
12257 cmd_get_hash_global_config_parsed(void *parsed_result,
12258 				  __rte_unused struct cmdline *cl,
12259 				  __rte_unused void *data)
12260 {
12261 	struct cmd_get_hash_global_config_result *res = parsed_result;
12262 	struct rte_eth_hash_filter_info info;
12263 	uint32_t idx, offset;
12264 	uint16_t i;
12265 	char *str;
12266 	int ret;
12267 
12268 	if (rte_eth_dev_filter_supported(res->port_id,
12269 			RTE_ETH_FILTER_HASH) < 0) {
12270 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12271 							res->port_id);
12272 		return;
12273 	}
12274 
12275 	memset(&info, 0, sizeof(info));
12276 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12277 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12278 					RTE_ETH_FILTER_GET, &info);
12279 	if (ret < 0) {
12280 		printf("Cannot get hash global configurations by port %d\n",
12281 							res->port_id);
12282 		return;
12283 	}
12284 
12285 	switch (info.info.global_conf.hash_func) {
12286 	case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12287 		printf("Hash function is Toeplitz\n");
12288 		break;
12289 	case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12290 		printf("Hash function is Simple XOR\n");
12291 		break;
12292 	case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12293 		printf("Hash function is Symmetric Toeplitz\n");
12294 		break;
12295 	default:
12296 		printf("Unknown hash function\n");
12297 		break;
12298 	}
12299 
12300 	for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12301 		idx = i / UINT64_BIT;
12302 		offset = i % UINT64_BIT;
12303 		if (!(info.info.global_conf.valid_bit_mask[idx] &
12304 						(1ULL << offset)))
12305 			continue;
12306 		str = flowtype_to_str(i);
12307 		if (!str)
12308 			continue;
12309 		printf("Symmetric hash is %s globally for flow type %s "
12310 							"by port %d\n",
12311 			((info.info.global_conf.sym_hash_enable_mask[idx] &
12312 			(1ULL << offset)) ? "enabled" : "disabled"), str,
12313 							res->port_id);
12314 	}
12315 }
12316 
12317 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12318 	TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12319 		get_hash_global_config, "get_hash_global_config");
12320 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12321 	TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12322 		port_id, UINT16);
12323 
12324 cmdline_parse_inst_t cmd_get_hash_global_config = {
12325 	.f = cmd_get_hash_global_config_parsed,
12326 	.data = NULL,
12327 	.help_str = "get_hash_global_config <port_id>",
12328 	.tokens = {
12329 		(void *)&cmd_get_hash_global_config_all,
12330 		(void *)&cmd_get_hash_global_config_port_id,
12331 		NULL,
12332 	},
12333 };
12334 
12335 /* Set global config of hash function */
12336 struct cmd_set_hash_global_config_result {
12337 	cmdline_fixed_string_t set_hash_global_config;
12338 	portid_t port_id;
12339 	cmdline_fixed_string_t hash_func;
12340 	cmdline_fixed_string_t flow_type;
12341 	cmdline_fixed_string_t enable;
12342 };
12343 
12344 static void
12345 cmd_set_hash_global_config_parsed(void *parsed_result,
12346 				  __rte_unused struct cmdline *cl,
12347 				  __rte_unused void *data)
12348 {
12349 	struct cmd_set_hash_global_config_result *res = parsed_result;
12350 	struct rte_eth_hash_filter_info info;
12351 	uint32_t ftype, idx, offset;
12352 	int ret;
12353 
12354 	if (rte_eth_dev_filter_supported(res->port_id,
12355 				RTE_ETH_FILTER_HASH) < 0) {
12356 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12357 							res->port_id);
12358 		return;
12359 	}
12360 	memset(&info, 0, sizeof(info));
12361 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12362 	if (!strcmp(res->hash_func, "toeplitz"))
12363 		info.info.global_conf.hash_func =
12364 			RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12365 	else if (!strcmp(res->hash_func, "simple_xor"))
12366 		info.info.global_conf.hash_func =
12367 			RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12368 	else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12369 		info.info.global_conf.hash_func =
12370 			RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12371 	else if (!strcmp(res->hash_func, "default"))
12372 		info.info.global_conf.hash_func =
12373 			RTE_ETH_HASH_FUNCTION_DEFAULT;
12374 
12375 	ftype = str2flowtype(res->flow_type);
12376 	idx = ftype / UINT64_BIT;
12377 	offset = ftype % UINT64_BIT;
12378 	info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12379 	if (!strcmp(res->enable, "enable"))
12380 		info.info.global_conf.sym_hash_enable_mask[idx] |=
12381 						(1ULL << offset);
12382 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12383 					RTE_ETH_FILTER_SET, &info);
12384 	if (ret < 0)
12385 		printf("Cannot set global hash configurations by port %d\n",
12386 							res->port_id);
12387 	else
12388 		printf("Global hash configurations have been set "
12389 			"successfully by port %d\n", res->port_id);
12390 }
12391 
12392 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12393 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12394 		set_hash_global_config, "set_hash_global_config");
12395 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12396 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12397 		port_id, UINT16);
12398 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12399 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12400 		hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12401 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12402 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12403 		flow_type,
12404 		"ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12405 		"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12406 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12407 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12408 		enable, "enable#disable");
12409 
12410 cmdline_parse_inst_t cmd_set_hash_global_config = {
12411 	.f = cmd_set_hash_global_config_parsed,
12412 	.data = NULL,
12413 	.help_str = "set_hash_global_config <port_id> "
12414 		"toeplitz|simple_xor|symmetric_toeplitz|default "
12415 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12416 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12417 		"l2_payload enable|disable",
12418 	.tokens = {
12419 		(void *)&cmd_set_hash_global_config_all,
12420 		(void *)&cmd_set_hash_global_config_port_id,
12421 		(void *)&cmd_set_hash_global_config_hash_func,
12422 		(void *)&cmd_set_hash_global_config_flow_type,
12423 		(void *)&cmd_set_hash_global_config_enable,
12424 		NULL,
12425 	},
12426 };
12427 
12428 /* Set hash input set */
12429 struct cmd_set_hash_input_set_result {
12430 	cmdline_fixed_string_t set_hash_input_set;
12431 	portid_t port_id;
12432 	cmdline_fixed_string_t flow_type;
12433 	cmdline_fixed_string_t inset_field;
12434 	cmdline_fixed_string_t select;
12435 };
12436 
12437 static enum rte_eth_input_set_field
12438 str2inset(char *string)
12439 {
12440 	uint16_t i;
12441 
12442 	static const struct {
12443 		char str[32];
12444 		enum rte_eth_input_set_field inset;
12445 	} inset_table[] = {
12446 		{"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12447 		{"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12448 		{"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12449 		{"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12450 		{"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12451 		{"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12452 		{"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12453 		{"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12454 		{"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12455 		{"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12456 		{"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12457 		{"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12458 		{"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12459 		{"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12460 		{"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12461 		{"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12462 		{"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12463 		{"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12464 		{"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12465 		{"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12466 		{"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12467 		{"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12468 		{"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12469 		{"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12470 		{"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12471 		{"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12472 		{"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12473 		{"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12474 		{"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12475 		{"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12476 		{"none", RTE_ETH_INPUT_SET_NONE},
12477 	};
12478 
12479 	for (i = 0; i < RTE_DIM(inset_table); i++) {
12480 		if (!strcmp(string, inset_table[i].str))
12481 			return inset_table[i].inset;
12482 	}
12483 
12484 	return RTE_ETH_INPUT_SET_UNKNOWN;
12485 }
12486 
12487 static void
12488 cmd_set_hash_input_set_parsed(void *parsed_result,
12489 			      __rte_unused struct cmdline *cl,
12490 			      __rte_unused void *data)
12491 {
12492 	struct cmd_set_hash_input_set_result *res = parsed_result;
12493 	struct rte_eth_hash_filter_info info;
12494 
12495 	memset(&info, 0, sizeof(info));
12496 	info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12497 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12498 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12499 	info.info.input_set_conf.inset_size = 1;
12500 	if (!strcmp(res->select, "select"))
12501 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12502 	else if (!strcmp(res->select, "add"))
12503 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12504 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12505 				RTE_ETH_FILTER_SET, &info);
12506 }
12507 
12508 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12509 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12510 		set_hash_input_set, "set_hash_input_set");
12511 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12512 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12513 		port_id, UINT16);
12514 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12515 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12516 		flow_type, NULL);
12517 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12518 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12519 		inset_field,
12520 		"ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12521 		"ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12522 		"udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12523 		"sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12524 		"fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12525 		"fld-8th#none");
12526 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12527 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12528 		select, "select#add");
12529 
12530 cmdline_parse_inst_t cmd_set_hash_input_set = {
12531 	.f = cmd_set_hash_input_set_parsed,
12532 	.data = NULL,
12533 	.help_str = "set_hash_input_set <port_id> "
12534 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12535 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12536 	"ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12537 	"ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12538 	"tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12539 	"gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12540 	"fld-7th|fld-8th|none select|add",
12541 	.tokens = {
12542 		(void *)&cmd_set_hash_input_set_cmd,
12543 		(void *)&cmd_set_hash_input_set_port_id,
12544 		(void *)&cmd_set_hash_input_set_flow_type,
12545 		(void *)&cmd_set_hash_input_set_field,
12546 		(void *)&cmd_set_hash_input_set_select,
12547 		NULL,
12548 	},
12549 };
12550 
12551 /* Set flow director input set */
12552 struct cmd_set_fdir_input_set_result {
12553 	cmdline_fixed_string_t set_fdir_input_set;
12554 	portid_t port_id;
12555 	cmdline_fixed_string_t flow_type;
12556 	cmdline_fixed_string_t inset_field;
12557 	cmdline_fixed_string_t select;
12558 };
12559 
12560 static void
12561 cmd_set_fdir_input_set_parsed(void *parsed_result,
12562 	__rte_unused struct cmdline *cl,
12563 	__rte_unused void *data)
12564 {
12565 	struct cmd_set_fdir_input_set_result *res = parsed_result;
12566 	struct rte_eth_fdir_filter_info info;
12567 
12568 	memset(&info, 0, sizeof(info));
12569 	info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12570 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12571 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12572 	info.info.input_set_conf.inset_size = 1;
12573 	if (!strcmp(res->select, "select"))
12574 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12575 	else if (!strcmp(res->select, "add"))
12576 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12577 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12578 		RTE_ETH_FILTER_SET, &info);
12579 }
12580 
12581 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12582 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12583 	set_fdir_input_set, "set_fdir_input_set");
12584 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12585 	TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12586 	port_id, UINT16);
12587 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12588 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12589 	flow_type,
12590 	"ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12591 	"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12592 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12593 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12594 	inset_field,
12595 	"ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12596 	"ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12597 	"ipv6-hop-limits#udp-src-port#udp-dst-port#"
12598 	"tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12599 	"sctp-veri-tag#none");
12600 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12601 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12602 	select, "select#add");
12603 
12604 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12605 	.f = cmd_set_fdir_input_set_parsed,
12606 	.data = NULL,
12607 	.help_str = "set_fdir_input_set <port_id> "
12608 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12609 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12610 	"ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12611 	"ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12612 	"ipv6-hop-limits|udp-src-port|udp-dst-port|"
12613 	"tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12614 	"sctp-veri-tag|none select|add",
12615 	.tokens = {
12616 		(void *)&cmd_set_fdir_input_set_cmd,
12617 		(void *)&cmd_set_fdir_input_set_port_id,
12618 		(void *)&cmd_set_fdir_input_set_flow_type,
12619 		(void *)&cmd_set_fdir_input_set_field,
12620 		(void *)&cmd_set_fdir_input_set_select,
12621 		NULL,
12622 	},
12623 };
12624 
12625 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12626 struct cmd_mcast_addr_result {
12627 	cmdline_fixed_string_t mcast_addr_cmd;
12628 	cmdline_fixed_string_t what;
12629 	uint16_t port_num;
12630 	struct rte_ether_addr mc_addr;
12631 };
12632 
12633 static void cmd_mcast_addr_parsed(void *parsed_result,
12634 		__attribute__((unused)) struct cmdline *cl,
12635 		__attribute__((unused)) void *data)
12636 {
12637 	struct cmd_mcast_addr_result *res = parsed_result;
12638 
12639 	if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12640 		printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12641 		       res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12642 		       res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12643 		       res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12644 		return;
12645 	}
12646 	if (strcmp(res->what, "add") == 0)
12647 		mcast_addr_add(res->port_num, &res->mc_addr);
12648 	else
12649 		mcast_addr_remove(res->port_num, &res->mc_addr);
12650 }
12651 
12652 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12653 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12654 				 mcast_addr_cmd, "mcast_addr");
12655 cmdline_parse_token_string_t cmd_mcast_addr_what =
12656 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12657 				 "add#remove");
12658 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12659 	TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12660 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12661 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12662 
12663 cmdline_parse_inst_t cmd_mcast_addr = {
12664 	.f = cmd_mcast_addr_parsed,
12665 	.data = (void *)0,
12666 	.help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12667 		"Add/Remove multicast MAC address on port_id",
12668 	.tokens = {
12669 		(void *)&cmd_mcast_addr_cmd,
12670 		(void *)&cmd_mcast_addr_what,
12671 		(void *)&cmd_mcast_addr_portnum,
12672 		(void *)&cmd_mcast_addr_addr,
12673 		NULL,
12674 	},
12675 };
12676 
12677 /* l2 tunnel config
12678  * only support E-tag now.
12679  */
12680 
12681 /* Ether type config */
12682 struct cmd_config_l2_tunnel_eth_type_result {
12683 	cmdline_fixed_string_t port;
12684 	cmdline_fixed_string_t config;
12685 	cmdline_fixed_string_t all;
12686 	portid_t id;
12687 	cmdline_fixed_string_t l2_tunnel;
12688 	cmdline_fixed_string_t l2_tunnel_type;
12689 	cmdline_fixed_string_t eth_type;
12690 	uint16_t eth_type_val;
12691 };
12692 
12693 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12694 	TOKEN_STRING_INITIALIZER
12695 		(struct cmd_config_l2_tunnel_eth_type_result,
12696 		 port, "port");
12697 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12698 	TOKEN_STRING_INITIALIZER
12699 		(struct cmd_config_l2_tunnel_eth_type_result,
12700 		 config, "config");
12701 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12702 	TOKEN_STRING_INITIALIZER
12703 		(struct cmd_config_l2_tunnel_eth_type_result,
12704 		 all, "all");
12705 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12706 	TOKEN_NUM_INITIALIZER
12707 		(struct cmd_config_l2_tunnel_eth_type_result,
12708 		 id, UINT16);
12709 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12710 	TOKEN_STRING_INITIALIZER
12711 		(struct cmd_config_l2_tunnel_eth_type_result,
12712 		 l2_tunnel, "l2-tunnel");
12713 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12714 	TOKEN_STRING_INITIALIZER
12715 		(struct cmd_config_l2_tunnel_eth_type_result,
12716 		 l2_tunnel_type, "E-tag");
12717 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12718 	TOKEN_STRING_INITIALIZER
12719 		(struct cmd_config_l2_tunnel_eth_type_result,
12720 		 eth_type, "ether-type");
12721 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12722 	TOKEN_NUM_INITIALIZER
12723 		(struct cmd_config_l2_tunnel_eth_type_result,
12724 		 eth_type_val, UINT16);
12725 
12726 static enum rte_eth_tunnel_type
12727 str2fdir_l2_tunnel_type(char *string)
12728 {
12729 	uint32_t i = 0;
12730 
12731 	static const struct {
12732 		char str[32];
12733 		enum rte_eth_tunnel_type type;
12734 	} l2_tunnel_type_str[] = {
12735 		{"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12736 	};
12737 
12738 	for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12739 		if (!strcmp(l2_tunnel_type_str[i].str, string))
12740 			return l2_tunnel_type_str[i].type;
12741 	}
12742 	return RTE_TUNNEL_TYPE_NONE;
12743 }
12744 
12745 /* ether type config for all ports */
12746 static void
12747 cmd_config_l2_tunnel_eth_type_all_parsed
12748 	(void *parsed_result,
12749 	 __attribute__((unused)) struct cmdline *cl,
12750 	 __attribute__((unused)) void *data)
12751 {
12752 	struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12753 	struct rte_eth_l2_tunnel_conf entry;
12754 	portid_t pid;
12755 
12756 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12757 	entry.ether_type = res->eth_type_val;
12758 
12759 	RTE_ETH_FOREACH_DEV(pid) {
12760 		rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12761 	}
12762 }
12763 
12764 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12765 	.f = cmd_config_l2_tunnel_eth_type_all_parsed,
12766 	.data = NULL,
12767 	.help_str = "port config all l2-tunnel E-tag ether-type <value>",
12768 	.tokens = {
12769 		(void *)&cmd_config_l2_tunnel_eth_type_port,
12770 		(void *)&cmd_config_l2_tunnel_eth_type_config,
12771 		(void *)&cmd_config_l2_tunnel_eth_type_all_str,
12772 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12773 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12774 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12775 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12776 		NULL,
12777 	},
12778 };
12779 
12780 /* ether type config for a specific port */
12781 static void
12782 cmd_config_l2_tunnel_eth_type_specific_parsed(
12783 	void *parsed_result,
12784 	__attribute__((unused)) struct cmdline *cl,
12785 	__attribute__((unused)) void *data)
12786 {
12787 	struct cmd_config_l2_tunnel_eth_type_result *res =
12788 		 parsed_result;
12789 	struct rte_eth_l2_tunnel_conf entry;
12790 
12791 	if (port_id_is_invalid(res->id, ENABLED_WARN))
12792 		return;
12793 
12794 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12795 	entry.ether_type = res->eth_type_val;
12796 
12797 	rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12798 }
12799 
12800 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12801 	.f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12802 	.data = NULL,
12803 	.help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12804 	.tokens = {
12805 		(void *)&cmd_config_l2_tunnel_eth_type_port,
12806 		(void *)&cmd_config_l2_tunnel_eth_type_config,
12807 		(void *)&cmd_config_l2_tunnel_eth_type_id,
12808 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12809 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12810 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12811 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12812 		NULL,
12813 	},
12814 };
12815 
12816 /* Enable/disable l2 tunnel */
12817 struct cmd_config_l2_tunnel_en_dis_result {
12818 	cmdline_fixed_string_t port;
12819 	cmdline_fixed_string_t config;
12820 	cmdline_fixed_string_t all;
12821 	portid_t id;
12822 	cmdline_fixed_string_t l2_tunnel;
12823 	cmdline_fixed_string_t l2_tunnel_type;
12824 	cmdline_fixed_string_t en_dis;
12825 };
12826 
12827 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12828 	TOKEN_STRING_INITIALIZER
12829 		(struct cmd_config_l2_tunnel_en_dis_result,
12830 		 port, "port");
12831 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12832 	TOKEN_STRING_INITIALIZER
12833 		(struct cmd_config_l2_tunnel_en_dis_result,
12834 		 config, "config");
12835 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12836 	TOKEN_STRING_INITIALIZER
12837 		(struct cmd_config_l2_tunnel_en_dis_result,
12838 		 all, "all");
12839 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12840 	TOKEN_NUM_INITIALIZER
12841 		(struct cmd_config_l2_tunnel_en_dis_result,
12842 		 id, UINT16);
12843 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12844 	TOKEN_STRING_INITIALIZER
12845 		(struct cmd_config_l2_tunnel_en_dis_result,
12846 		 l2_tunnel, "l2-tunnel");
12847 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12848 	TOKEN_STRING_INITIALIZER
12849 		(struct cmd_config_l2_tunnel_en_dis_result,
12850 		 l2_tunnel_type, "E-tag");
12851 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12852 	TOKEN_STRING_INITIALIZER
12853 		(struct cmd_config_l2_tunnel_en_dis_result,
12854 		 en_dis, "enable#disable");
12855 
12856 /* enable/disable l2 tunnel for all ports */
12857 static void
12858 cmd_config_l2_tunnel_en_dis_all_parsed(
12859 	void *parsed_result,
12860 	__attribute__((unused)) struct cmdline *cl,
12861 	__attribute__((unused)) void *data)
12862 {
12863 	struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12864 	struct rte_eth_l2_tunnel_conf entry;
12865 	portid_t pid;
12866 	uint8_t en;
12867 
12868 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12869 
12870 	if (!strcmp("enable", res->en_dis))
12871 		en = 1;
12872 	else
12873 		en = 0;
12874 
12875 	RTE_ETH_FOREACH_DEV(pid) {
12876 		rte_eth_dev_l2_tunnel_offload_set(pid,
12877 						  &entry,
12878 						  ETH_L2_TUNNEL_ENABLE_MASK,
12879 						  en);
12880 	}
12881 }
12882 
12883 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12884 	.f = cmd_config_l2_tunnel_en_dis_all_parsed,
12885 	.data = NULL,
12886 	.help_str = "port config all l2-tunnel E-tag enable|disable",
12887 	.tokens = {
12888 		(void *)&cmd_config_l2_tunnel_en_dis_port,
12889 		(void *)&cmd_config_l2_tunnel_en_dis_config,
12890 		(void *)&cmd_config_l2_tunnel_en_dis_all_str,
12891 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12892 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12893 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12894 		NULL,
12895 	},
12896 };
12897 
12898 /* enable/disable l2 tunnel for a port */
12899 static void
12900 cmd_config_l2_tunnel_en_dis_specific_parsed(
12901 	void *parsed_result,
12902 	__attribute__((unused)) struct cmdline *cl,
12903 	__attribute__((unused)) void *data)
12904 {
12905 	struct cmd_config_l2_tunnel_en_dis_result *res =
12906 		parsed_result;
12907 	struct rte_eth_l2_tunnel_conf entry;
12908 
12909 	if (port_id_is_invalid(res->id, ENABLED_WARN))
12910 		return;
12911 
12912 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12913 
12914 	if (!strcmp("enable", res->en_dis))
12915 		rte_eth_dev_l2_tunnel_offload_set(res->id,
12916 						  &entry,
12917 						  ETH_L2_TUNNEL_ENABLE_MASK,
12918 						  1);
12919 	else
12920 		rte_eth_dev_l2_tunnel_offload_set(res->id,
12921 						  &entry,
12922 						  ETH_L2_TUNNEL_ENABLE_MASK,
12923 						  0);
12924 }
12925 
12926 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12927 	.f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12928 	.data = NULL,
12929 	.help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12930 	.tokens = {
12931 		(void *)&cmd_config_l2_tunnel_en_dis_port,
12932 		(void *)&cmd_config_l2_tunnel_en_dis_config,
12933 		(void *)&cmd_config_l2_tunnel_en_dis_id,
12934 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12935 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12936 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12937 		NULL,
12938 	},
12939 };
12940 
12941 /* E-tag configuration */
12942 
12943 /* Common result structure for all E-tag configuration */
12944 struct cmd_config_e_tag_result {
12945 	cmdline_fixed_string_t e_tag;
12946 	cmdline_fixed_string_t set;
12947 	cmdline_fixed_string_t insertion;
12948 	cmdline_fixed_string_t stripping;
12949 	cmdline_fixed_string_t forwarding;
12950 	cmdline_fixed_string_t filter;
12951 	cmdline_fixed_string_t add;
12952 	cmdline_fixed_string_t del;
12953 	cmdline_fixed_string_t on;
12954 	cmdline_fixed_string_t off;
12955 	cmdline_fixed_string_t on_off;
12956 	cmdline_fixed_string_t port_tag_id;
12957 	uint32_t port_tag_id_val;
12958 	cmdline_fixed_string_t e_tag_id;
12959 	uint16_t e_tag_id_val;
12960 	cmdline_fixed_string_t dst_pool;
12961 	uint8_t dst_pool_val;
12962 	cmdline_fixed_string_t port;
12963 	portid_t port_id;
12964 	cmdline_fixed_string_t vf;
12965 	uint8_t vf_id;
12966 };
12967 
12968 /* Common CLI fields for all E-tag configuration */
12969 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12970 	TOKEN_STRING_INITIALIZER
12971 		(struct cmd_config_e_tag_result,
12972 		 e_tag, "E-tag");
12973 cmdline_parse_token_string_t cmd_config_e_tag_set =
12974 	TOKEN_STRING_INITIALIZER
12975 		(struct cmd_config_e_tag_result,
12976 		 set, "set");
12977 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12978 	TOKEN_STRING_INITIALIZER
12979 		(struct cmd_config_e_tag_result,
12980 		 insertion, "insertion");
12981 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12982 	TOKEN_STRING_INITIALIZER
12983 		(struct cmd_config_e_tag_result,
12984 		 stripping, "stripping");
12985 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12986 	TOKEN_STRING_INITIALIZER
12987 		(struct cmd_config_e_tag_result,
12988 		 forwarding, "forwarding");
12989 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12990 	TOKEN_STRING_INITIALIZER
12991 		(struct cmd_config_e_tag_result,
12992 		 filter, "filter");
12993 cmdline_parse_token_string_t cmd_config_e_tag_add =
12994 	TOKEN_STRING_INITIALIZER
12995 		(struct cmd_config_e_tag_result,
12996 		 add, "add");
12997 cmdline_parse_token_string_t cmd_config_e_tag_del =
12998 	TOKEN_STRING_INITIALIZER
12999 		(struct cmd_config_e_tag_result,
13000 		 del, "del");
13001 cmdline_parse_token_string_t cmd_config_e_tag_on =
13002 	TOKEN_STRING_INITIALIZER
13003 		(struct cmd_config_e_tag_result,
13004 		 on, "on");
13005 cmdline_parse_token_string_t cmd_config_e_tag_off =
13006 	TOKEN_STRING_INITIALIZER
13007 		(struct cmd_config_e_tag_result,
13008 		 off, "off");
13009 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13010 	TOKEN_STRING_INITIALIZER
13011 		(struct cmd_config_e_tag_result,
13012 		 on_off, "on#off");
13013 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13014 	TOKEN_STRING_INITIALIZER
13015 		(struct cmd_config_e_tag_result,
13016 		 port_tag_id, "port-tag-id");
13017 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13018 	TOKEN_NUM_INITIALIZER
13019 		(struct cmd_config_e_tag_result,
13020 		 port_tag_id_val, UINT32);
13021 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13022 	TOKEN_STRING_INITIALIZER
13023 		(struct cmd_config_e_tag_result,
13024 		 e_tag_id, "e-tag-id");
13025 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13026 	TOKEN_NUM_INITIALIZER
13027 		(struct cmd_config_e_tag_result,
13028 		 e_tag_id_val, UINT16);
13029 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13030 	TOKEN_STRING_INITIALIZER
13031 		(struct cmd_config_e_tag_result,
13032 		 dst_pool, "dst-pool");
13033 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13034 	TOKEN_NUM_INITIALIZER
13035 		(struct cmd_config_e_tag_result,
13036 		 dst_pool_val, UINT8);
13037 cmdline_parse_token_string_t cmd_config_e_tag_port =
13038 	TOKEN_STRING_INITIALIZER
13039 		(struct cmd_config_e_tag_result,
13040 		 port, "port");
13041 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13042 	TOKEN_NUM_INITIALIZER
13043 		(struct cmd_config_e_tag_result,
13044 		 port_id, UINT16);
13045 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13046 	TOKEN_STRING_INITIALIZER
13047 		(struct cmd_config_e_tag_result,
13048 		 vf, "vf");
13049 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13050 	TOKEN_NUM_INITIALIZER
13051 		(struct cmd_config_e_tag_result,
13052 		 vf_id, UINT8);
13053 
13054 /* E-tag insertion configuration */
13055 static void
13056 cmd_config_e_tag_insertion_en_parsed(
13057 	void *parsed_result,
13058 	__attribute__((unused)) struct cmdline *cl,
13059 	__attribute__((unused)) void *data)
13060 {
13061 	struct cmd_config_e_tag_result *res =
13062 		parsed_result;
13063 	struct rte_eth_l2_tunnel_conf entry;
13064 
13065 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13066 		return;
13067 
13068 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13069 	entry.tunnel_id = res->port_tag_id_val;
13070 	entry.vf_id = res->vf_id;
13071 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13072 					  &entry,
13073 					  ETH_L2_TUNNEL_INSERTION_MASK,
13074 					  1);
13075 }
13076 
13077 static void
13078 cmd_config_e_tag_insertion_dis_parsed(
13079 	void *parsed_result,
13080 	__attribute__((unused)) struct cmdline *cl,
13081 	__attribute__((unused)) void *data)
13082 {
13083 	struct cmd_config_e_tag_result *res =
13084 		parsed_result;
13085 	struct rte_eth_l2_tunnel_conf entry;
13086 
13087 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13088 		return;
13089 
13090 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13091 	entry.vf_id = res->vf_id;
13092 
13093 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13094 					  &entry,
13095 					  ETH_L2_TUNNEL_INSERTION_MASK,
13096 					  0);
13097 }
13098 
13099 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13100 	.f = cmd_config_e_tag_insertion_en_parsed,
13101 	.data = NULL,
13102 	.help_str = "E-tag ... : E-tag insertion enable",
13103 	.tokens = {
13104 		(void *)&cmd_config_e_tag_e_tag,
13105 		(void *)&cmd_config_e_tag_set,
13106 		(void *)&cmd_config_e_tag_insertion,
13107 		(void *)&cmd_config_e_tag_on,
13108 		(void *)&cmd_config_e_tag_port_tag_id,
13109 		(void *)&cmd_config_e_tag_port_tag_id_val,
13110 		(void *)&cmd_config_e_tag_port,
13111 		(void *)&cmd_config_e_tag_port_id,
13112 		(void *)&cmd_config_e_tag_vf,
13113 		(void *)&cmd_config_e_tag_vf_id,
13114 		NULL,
13115 	},
13116 };
13117 
13118 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13119 	.f = cmd_config_e_tag_insertion_dis_parsed,
13120 	.data = NULL,
13121 	.help_str = "E-tag ... : E-tag insertion disable",
13122 	.tokens = {
13123 		(void *)&cmd_config_e_tag_e_tag,
13124 		(void *)&cmd_config_e_tag_set,
13125 		(void *)&cmd_config_e_tag_insertion,
13126 		(void *)&cmd_config_e_tag_off,
13127 		(void *)&cmd_config_e_tag_port,
13128 		(void *)&cmd_config_e_tag_port_id,
13129 		(void *)&cmd_config_e_tag_vf,
13130 		(void *)&cmd_config_e_tag_vf_id,
13131 		NULL,
13132 	},
13133 };
13134 
13135 /* E-tag stripping configuration */
13136 static void
13137 cmd_config_e_tag_stripping_parsed(
13138 	void *parsed_result,
13139 	__attribute__((unused)) struct cmdline *cl,
13140 	__attribute__((unused)) void *data)
13141 {
13142 	struct cmd_config_e_tag_result *res =
13143 		parsed_result;
13144 	struct rte_eth_l2_tunnel_conf entry;
13145 
13146 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13147 		return;
13148 
13149 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13150 
13151 	if (!strcmp(res->on_off, "on"))
13152 		rte_eth_dev_l2_tunnel_offload_set
13153 			(res->port_id,
13154 			 &entry,
13155 			 ETH_L2_TUNNEL_STRIPPING_MASK,
13156 			 1);
13157 	else
13158 		rte_eth_dev_l2_tunnel_offload_set
13159 			(res->port_id,
13160 			 &entry,
13161 			 ETH_L2_TUNNEL_STRIPPING_MASK,
13162 			 0);
13163 }
13164 
13165 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13166 	.f = cmd_config_e_tag_stripping_parsed,
13167 	.data = NULL,
13168 	.help_str = "E-tag ... : E-tag stripping enable/disable",
13169 	.tokens = {
13170 		(void *)&cmd_config_e_tag_e_tag,
13171 		(void *)&cmd_config_e_tag_set,
13172 		(void *)&cmd_config_e_tag_stripping,
13173 		(void *)&cmd_config_e_tag_on_off,
13174 		(void *)&cmd_config_e_tag_port,
13175 		(void *)&cmd_config_e_tag_port_id,
13176 		NULL,
13177 	},
13178 };
13179 
13180 /* E-tag forwarding configuration */
13181 static void
13182 cmd_config_e_tag_forwarding_parsed(
13183 	void *parsed_result,
13184 	__attribute__((unused)) struct cmdline *cl,
13185 	__attribute__((unused)) void *data)
13186 {
13187 	struct cmd_config_e_tag_result *res = parsed_result;
13188 	struct rte_eth_l2_tunnel_conf entry;
13189 
13190 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13191 		return;
13192 
13193 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13194 
13195 	if (!strcmp(res->on_off, "on"))
13196 		rte_eth_dev_l2_tunnel_offload_set
13197 			(res->port_id,
13198 			 &entry,
13199 			 ETH_L2_TUNNEL_FORWARDING_MASK,
13200 			 1);
13201 	else
13202 		rte_eth_dev_l2_tunnel_offload_set
13203 			(res->port_id,
13204 			 &entry,
13205 			 ETH_L2_TUNNEL_FORWARDING_MASK,
13206 			 0);
13207 }
13208 
13209 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13210 	.f = cmd_config_e_tag_forwarding_parsed,
13211 	.data = NULL,
13212 	.help_str = "E-tag ... : E-tag forwarding enable/disable",
13213 	.tokens = {
13214 		(void *)&cmd_config_e_tag_e_tag,
13215 		(void *)&cmd_config_e_tag_set,
13216 		(void *)&cmd_config_e_tag_forwarding,
13217 		(void *)&cmd_config_e_tag_on_off,
13218 		(void *)&cmd_config_e_tag_port,
13219 		(void *)&cmd_config_e_tag_port_id,
13220 		NULL,
13221 	},
13222 };
13223 
13224 /* E-tag filter configuration */
13225 static void
13226 cmd_config_e_tag_filter_add_parsed(
13227 	void *parsed_result,
13228 	__attribute__((unused)) struct cmdline *cl,
13229 	__attribute__((unused)) void *data)
13230 {
13231 	struct cmd_config_e_tag_result *res = parsed_result;
13232 	struct rte_eth_l2_tunnel_conf entry;
13233 	int ret = 0;
13234 
13235 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13236 		return;
13237 
13238 	if (res->e_tag_id_val > 0x3fff) {
13239 		printf("e-tag-id must be equal or less than 0x3fff.\n");
13240 		return;
13241 	}
13242 
13243 	ret = rte_eth_dev_filter_supported(res->port_id,
13244 					   RTE_ETH_FILTER_L2_TUNNEL);
13245 	if (ret < 0) {
13246 		printf("E-tag filter is not supported on port %u.\n",
13247 		       res->port_id);
13248 		return;
13249 	}
13250 
13251 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13252 	entry.tunnel_id = res->e_tag_id_val;
13253 	entry.pool = res->dst_pool_val;
13254 
13255 	ret = rte_eth_dev_filter_ctrl(res->port_id,
13256 				      RTE_ETH_FILTER_L2_TUNNEL,
13257 				      RTE_ETH_FILTER_ADD,
13258 				      &entry);
13259 	if (ret < 0)
13260 		printf("E-tag filter programming error: (%s)\n",
13261 		       strerror(-ret));
13262 }
13263 
13264 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13265 	.f = cmd_config_e_tag_filter_add_parsed,
13266 	.data = NULL,
13267 	.help_str = "E-tag ... : E-tag filter add",
13268 	.tokens = {
13269 		(void *)&cmd_config_e_tag_e_tag,
13270 		(void *)&cmd_config_e_tag_set,
13271 		(void *)&cmd_config_e_tag_filter,
13272 		(void *)&cmd_config_e_tag_add,
13273 		(void *)&cmd_config_e_tag_e_tag_id,
13274 		(void *)&cmd_config_e_tag_e_tag_id_val,
13275 		(void *)&cmd_config_e_tag_dst_pool,
13276 		(void *)&cmd_config_e_tag_dst_pool_val,
13277 		(void *)&cmd_config_e_tag_port,
13278 		(void *)&cmd_config_e_tag_port_id,
13279 		NULL,
13280 	},
13281 };
13282 
13283 static void
13284 cmd_config_e_tag_filter_del_parsed(
13285 	void *parsed_result,
13286 	__attribute__((unused)) struct cmdline *cl,
13287 	__attribute__((unused)) void *data)
13288 {
13289 	struct cmd_config_e_tag_result *res = parsed_result;
13290 	struct rte_eth_l2_tunnel_conf entry;
13291 	int ret = 0;
13292 
13293 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13294 		return;
13295 
13296 	if (res->e_tag_id_val > 0x3fff) {
13297 		printf("e-tag-id must be less than 0x3fff.\n");
13298 		return;
13299 	}
13300 
13301 	ret = rte_eth_dev_filter_supported(res->port_id,
13302 					   RTE_ETH_FILTER_L2_TUNNEL);
13303 	if (ret < 0) {
13304 		printf("E-tag filter is not supported on port %u.\n",
13305 		       res->port_id);
13306 		return;
13307 	}
13308 
13309 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13310 	entry.tunnel_id = res->e_tag_id_val;
13311 
13312 	ret = rte_eth_dev_filter_ctrl(res->port_id,
13313 				      RTE_ETH_FILTER_L2_TUNNEL,
13314 				      RTE_ETH_FILTER_DELETE,
13315 				      &entry);
13316 	if (ret < 0)
13317 		printf("E-tag filter programming error: (%s)\n",
13318 		       strerror(-ret));
13319 }
13320 
13321 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13322 	.f = cmd_config_e_tag_filter_del_parsed,
13323 	.data = NULL,
13324 	.help_str = "E-tag ... : E-tag filter delete",
13325 	.tokens = {
13326 		(void *)&cmd_config_e_tag_e_tag,
13327 		(void *)&cmd_config_e_tag_set,
13328 		(void *)&cmd_config_e_tag_filter,
13329 		(void *)&cmd_config_e_tag_del,
13330 		(void *)&cmd_config_e_tag_e_tag_id,
13331 		(void *)&cmd_config_e_tag_e_tag_id_val,
13332 		(void *)&cmd_config_e_tag_port,
13333 		(void *)&cmd_config_e_tag_port_id,
13334 		NULL,
13335 	},
13336 };
13337 
13338 /* vf vlan anti spoof configuration */
13339 
13340 /* Common result structure for vf vlan anti spoof */
13341 struct cmd_vf_vlan_anti_spoof_result {
13342 	cmdline_fixed_string_t set;
13343 	cmdline_fixed_string_t vf;
13344 	cmdline_fixed_string_t vlan;
13345 	cmdline_fixed_string_t antispoof;
13346 	portid_t port_id;
13347 	uint32_t vf_id;
13348 	cmdline_fixed_string_t on_off;
13349 };
13350 
13351 /* Common CLI fields for vf vlan anti spoof enable disable */
13352 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13353 	TOKEN_STRING_INITIALIZER
13354 		(struct cmd_vf_vlan_anti_spoof_result,
13355 		 set, "set");
13356 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13357 	TOKEN_STRING_INITIALIZER
13358 		(struct cmd_vf_vlan_anti_spoof_result,
13359 		 vf, "vf");
13360 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13361 	TOKEN_STRING_INITIALIZER
13362 		(struct cmd_vf_vlan_anti_spoof_result,
13363 		 vlan, "vlan");
13364 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13365 	TOKEN_STRING_INITIALIZER
13366 		(struct cmd_vf_vlan_anti_spoof_result,
13367 		 antispoof, "antispoof");
13368 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13369 	TOKEN_NUM_INITIALIZER
13370 		(struct cmd_vf_vlan_anti_spoof_result,
13371 		 port_id, UINT16);
13372 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13373 	TOKEN_NUM_INITIALIZER
13374 		(struct cmd_vf_vlan_anti_spoof_result,
13375 		 vf_id, UINT32);
13376 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13377 	TOKEN_STRING_INITIALIZER
13378 		(struct cmd_vf_vlan_anti_spoof_result,
13379 		 on_off, "on#off");
13380 
13381 static void
13382 cmd_set_vf_vlan_anti_spoof_parsed(
13383 	void *parsed_result,
13384 	__attribute__((unused)) struct cmdline *cl,
13385 	__attribute__((unused)) void *data)
13386 {
13387 	struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13388 	int ret = -ENOTSUP;
13389 
13390 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13391 
13392 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13393 		return;
13394 
13395 #ifdef RTE_LIBRTE_IXGBE_PMD
13396 	if (ret == -ENOTSUP)
13397 		ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13398 				res->vf_id, is_on);
13399 #endif
13400 #ifdef RTE_LIBRTE_I40E_PMD
13401 	if (ret == -ENOTSUP)
13402 		ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13403 				res->vf_id, is_on);
13404 #endif
13405 #ifdef RTE_LIBRTE_BNXT_PMD
13406 	if (ret == -ENOTSUP)
13407 		ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13408 				res->vf_id, is_on);
13409 #endif
13410 
13411 	switch (ret) {
13412 	case 0:
13413 		break;
13414 	case -EINVAL:
13415 		printf("invalid vf_id %d\n", res->vf_id);
13416 		break;
13417 	case -ENODEV:
13418 		printf("invalid port_id %d\n", res->port_id);
13419 		break;
13420 	case -ENOTSUP:
13421 		printf("function not implemented\n");
13422 		break;
13423 	default:
13424 		printf("programming error: (%s)\n", strerror(-ret));
13425 	}
13426 }
13427 
13428 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13429 	.f = cmd_set_vf_vlan_anti_spoof_parsed,
13430 	.data = NULL,
13431 	.help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13432 	.tokens = {
13433 		(void *)&cmd_vf_vlan_anti_spoof_set,
13434 		(void *)&cmd_vf_vlan_anti_spoof_vf,
13435 		(void *)&cmd_vf_vlan_anti_spoof_vlan,
13436 		(void *)&cmd_vf_vlan_anti_spoof_antispoof,
13437 		(void *)&cmd_vf_vlan_anti_spoof_port_id,
13438 		(void *)&cmd_vf_vlan_anti_spoof_vf_id,
13439 		(void *)&cmd_vf_vlan_anti_spoof_on_off,
13440 		NULL,
13441 	},
13442 };
13443 
13444 /* vf mac anti spoof configuration */
13445 
13446 /* Common result structure for vf mac anti spoof */
13447 struct cmd_vf_mac_anti_spoof_result {
13448 	cmdline_fixed_string_t set;
13449 	cmdline_fixed_string_t vf;
13450 	cmdline_fixed_string_t mac;
13451 	cmdline_fixed_string_t antispoof;
13452 	portid_t port_id;
13453 	uint32_t vf_id;
13454 	cmdline_fixed_string_t on_off;
13455 };
13456 
13457 /* Common CLI fields for vf mac anti spoof enable disable */
13458 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13459 	TOKEN_STRING_INITIALIZER
13460 		(struct cmd_vf_mac_anti_spoof_result,
13461 		 set, "set");
13462 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13463 	TOKEN_STRING_INITIALIZER
13464 		(struct cmd_vf_mac_anti_spoof_result,
13465 		 vf, "vf");
13466 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13467 	TOKEN_STRING_INITIALIZER
13468 		(struct cmd_vf_mac_anti_spoof_result,
13469 		 mac, "mac");
13470 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13471 	TOKEN_STRING_INITIALIZER
13472 		(struct cmd_vf_mac_anti_spoof_result,
13473 		 antispoof, "antispoof");
13474 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13475 	TOKEN_NUM_INITIALIZER
13476 		(struct cmd_vf_mac_anti_spoof_result,
13477 		 port_id, UINT16);
13478 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13479 	TOKEN_NUM_INITIALIZER
13480 		(struct cmd_vf_mac_anti_spoof_result,
13481 		 vf_id, UINT32);
13482 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13483 	TOKEN_STRING_INITIALIZER
13484 		(struct cmd_vf_mac_anti_spoof_result,
13485 		 on_off, "on#off");
13486 
13487 static void
13488 cmd_set_vf_mac_anti_spoof_parsed(
13489 	void *parsed_result,
13490 	__attribute__((unused)) struct cmdline *cl,
13491 	__attribute__((unused)) void *data)
13492 {
13493 	struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13494 	int ret = -ENOTSUP;
13495 
13496 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13497 
13498 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13499 		return;
13500 
13501 #ifdef RTE_LIBRTE_IXGBE_PMD
13502 	if (ret == -ENOTSUP)
13503 		ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13504 			res->vf_id, is_on);
13505 #endif
13506 #ifdef RTE_LIBRTE_I40E_PMD
13507 	if (ret == -ENOTSUP)
13508 		ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13509 			res->vf_id, is_on);
13510 #endif
13511 #ifdef RTE_LIBRTE_BNXT_PMD
13512 	if (ret == -ENOTSUP)
13513 		ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13514 			res->vf_id, is_on);
13515 #endif
13516 
13517 	switch (ret) {
13518 	case 0:
13519 		break;
13520 	case -EINVAL:
13521 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13522 		break;
13523 	case -ENODEV:
13524 		printf("invalid port_id %d\n", res->port_id);
13525 		break;
13526 	case -ENOTSUP:
13527 		printf("function not implemented\n");
13528 		break;
13529 	default:
13530 		printf("programming error: (%s)\n", strerror(-ret));
13531 	}
13532 }
13533 
13534 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13535 	.f = cmd_set_vf_mac_anti_spoof_parsed,
13536 	.data = NULL,
13537 	.help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13538 	.tokens = {
13539 		(void *)&cmd_vf_mac_anti_spoof_set,
13540 		(void *)&cmd_vf_mac_anti_spoof_vf,
13541 		(void *)&cmd_vf_mac_anti_spoof_mac,
13542 		(void *)&cmd_vf_mac_anti_spoof_antispoof,
13543 		(void *)&cmd_vf_mac_anti_spoof_port_id,
13544 		(void *)&cmd_vf_mac_anti_spoof_vf_id,
13545 		(void *)&cmd_vf_mac_anti_spoof_on_off,
13546 		NULL,
13547 	},
13548 };
13549 
13550 /* vf vlan strip queue configuration */
13551 
13552 /* Common result structure for vf mac anti spoof */
13553 struct cmd_vf_vlan_stripq_result {
13554 	cmdline_fixed_string_t set;
13555 	cmdline_fixed_string_t vf;
13556 	cmdline_fixed_string_t vlan;
13557 	cmdline_fixed_string_t stripq;
13558 	portid_t port_id;
13559 	uint16_t vf_id;
13560 	cmdline_fixed_string_t on_off;
13561 };
13562 
13563 /* Common CLI fields for vf vlan strip enable disable */
13564 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13565 	TOKEN_STRING_INITIALIZER
13566 		(struct cmd_vf_vlan_stripq_result,
13567 		 set, "set");
13568 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13569 	TOKEN_STRING_INITIALIZER
13570 		(struct cmd_vf_vlan_stripq_result,
13571 		 vf, "vf");
13572 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13573 	TOKEN_STRING_INITIALIZER
13574 		(struct cmd_vf_vlan_stripq_result,
13575 		 vlan, "vlan");
13576 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13577 	TOKEN_STRING_INITIALIZER
13578 		(struct cmd_vf_vlan_stripq_result,
13579 		 stripq, "stripq");
13580 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13581 	TOKEN_NUM_INITIALIZER
13582 		(struct cmd_vf_vlan_stripq_result,
13583 		 port_id, UINT16);
13584 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13585 	TOKEN_NUM_INITIALIZER
13586 		(struct cmd_vf_vlan_stripq_result,
13587 		 vf_id, UINT16);
13588 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13589 	TOKEN_STRING_INITIALIZER
13590 		(struct cmd_vf_vlan_stripq_result,
13591 		 on_off, "on#off");
13592 
13593 static void
13594 cmd_set_vf_vlan_stripq_parsed(
13595 	void *parsed_result,
13596 	__attribute__((unused)) struct cmdline *cl,
13597 	__attribute__((unused)) void *data)
13598 {
13599 	struct cmd_vf_vlan_stripq_result *res = parsed_result;
13600 	int ret = -ENOTSUP;
13601 
13602 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13603 
13604 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13605 		return;
13606 
13607 #ifdef RTE_LIBRTE_IXGBE_PMD
13608 	if (ret == -ENOTSUP)
13609 		ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13610 			res->vf_id, is_on);
13611 #endif
13612 #ifdef RTE_LIBRTE_I40E_PMD
13613 	if (ret == -ENOTSUP)
13614 		ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13615 			res->vf_id, is_on);
13616 #endif
13617 #ifdef RTE_LIBRTE_BNXT_PMD
13618 	if (ret == -ENOTSUP)
13619 		ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13620 			res->vf_id, is_on);
13621 #endif
13622 
13623 	switch (ret) {
13624 	case 0:
13625 		break;
13626 	case -EINVAL:
13627 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13628 		break;
13629 	case -ENODEV:
13630 		printf("invalid port_id %d\n", res->port_id);
13631 		break;
13632 	case -ENOTSUP:
13633 		printf("function not implemented\n");
13634 		break;
13635 	default:
13636 		printf("programming error: (%s)\n", strerror(-ret));
13637 	}
13638 }
13639 
13640 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13641 	.f = cmd_set_vf_vlan_stripq_parsed,
13642 	.data = NULL,
13643 	.help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13644 	.tokens = {
13645 		(void *)&cmd_vf_vlan_stripq_set,
13646 		(void *)&cmd_vf_vlan_stripq_vf,
13647 		(void *)&cmd_vf_vlan_stripq_vlan,
13648 		(void *)&cmd_vf_vlan_stripq_stripq,
13649 		(void *)&cmd_vf_vlan_stripq_port_id,
13650 		(void *)&cmd_vf_vlan_stripq_vf_id,
13651 		(void *)&cmd_vf_vlan_stripq_on_off,
13652 		NULL,
13653 	},
13654 };
13655 
13656 /* vf vlan insert configuration */
13657 
13658 /* Common result structure for vf vlan insert */
13659 struct cmd_vf_vlan_insert_result {
13660 	cmdline_fixed_string_t set;
13661 	cmdline_fixed_string_t vf;
13662 	cmdline_fixed_string_t vlan;
13663 	cmdline_fixed_string_t insert;
13664 	portid_t port_id;
13665 	uint16_t vf_id;
13666 	uint16_t vlan_id;
13667 };
13668 
13669 /* Common CLI fields for vf vlan insert enable disable */
13670 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13671 	TOKEN_STRING_INITIALIZER
13672 		(struct cmd_vf_vlan_insert_result,
13673 		 set, "set");
13674 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13675 	TOKEN_STRING_INITIALIZER
13676 		(struct cmd_vf_vlan_insert_result,
13677 		 vf, "vf");
13678 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13679 	TOKEN_STRING_INITIALIZER
13680 		(struct cmd_vf_vlan_insert_result,
13681 		 vlan, "vlan");
13682 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13683 	TOKEN_STRING_INITIALIZER
13684 		(struct cmd_vf_vlan_insert_result,
13685 		 insert, "insert");
13686 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13687 	TOKEN_NUM_INITIALIZER
13688 		(struct cmd_vf_vlan_insert_result,
13689 		 port_id, UINT16);
13690 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13691 	TOKEN_NUM_INITIALIZER
13692 		(struct cmd_vf_vlan_insert_result,
13693 		 vf_id, UINT16);
13694 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13695 	TOKEN_NUM_INITIALIZER
13696 		(struct cmd_vf_vlan_insert_result,
13697 		 vlan_id, UINT16);
13698 
13699 static void
13700 cmd_set_vf_vlan_insert_parsed(
13701 	void *parsed_result,
13702 	__attribute__((unused)) struct cmdline *cl,
13703 	__attribute__((unused)) void *data)
13704 {
13705 	struct cmd_vf_vlan_insert_result *res = parsed_result;
13706 	int ret = -ENOTSUP;
13707 
13708 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13709 		return;
13710 
13711 #ifdef RTE_LIBRTE_IXGBE_PMD
13712 	if (ret == -ENOTSUP)
13713 		ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13714 			res->vlan_id);
13715 #endif
13716 #ifdef RTE_LIBRTE_I40E_PMD
13717 	if (ret == -ENOTSUP)
13718 		ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13719 			res->vlan_id);
13720 #endif
13721 #ifdef RTE_LIBRTE_BNXT_PMD
13722 	if (ret == -ENOTSUP)
13723 		ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13724 			res->vlan_id);
13725 #endif
13726 
13727 	switch (ret) {
13728 	case 0:
13729 		break;
13730 	case -EINVAL:
13731 		printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13732 		break;
13733 	case -ENODEV:
13734 		printf("invalid port_id %d\n", res->port_id);
13735 		break;
13736 	case -ENOTSUP:
13737 		printf("function not implemented\n");
13738 		break;
13739 	default:
13740 		printf("programming error: (%s)\n", strerror(-ret));
13741 	}
13742 }
13743 
13744 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13745 	.f = cmd_set_vf_vlan_insert_parsed,
13746 	.data = NULL,
13747 	.help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13748 	.tokens = {
13749 		(void *)&cmd_vf_vlan_insert_set,
13750 		(void *)&cmd_vf_vlan_insert_vf,
13751 		(void *)&cmd_vf_vlan_insert_vlan,
13752 		(void *)&cmd_vf_vlan_insert_insert,
13753 		(void *)&cmd_vf_vlan_insert_port_id,
13754 		(void *)&cmd_vf_vlan_insert_vf_id,
13755 		(void *)&cmd_vf_vlan_insert_vlan_id,
13756 		NULL,
13757 	},
13758 };
13759 
13760 /* tx loopback configuration */
13761 
13762 /* Common result structure for tx loopback */
13763 struct cmd_tx_loopback_result {
13764 	cmdline_fixed_string_t set;
13765 	cmdline_fixed_string_t tx;
13766 	cmdline_fixed_string_t loopback;
13767 	portid_t port_id;
13768 	cmdline_fixed_string_t on_off;
13769 };
13770 
13771 /* Common CLI fields for tx loopback enable disable */
13772 cmdline_parse_token_string_t cmd_tx_loopback_set =
13773 	TOKEN_STRING_INITIALIZER
13774 		(struct cmd_tx_loopback_result,
13775 		 set, "set");
13776 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13777 	TOKEN_STRING_INITIALIZER
13778 		(struct cmd_tx_loopback_result,
13779 		 tx, "tx");
13780 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13781 	TOKEN_STRING_INITIALIZER
13782 		(struct cmd_tx_loopback_result,
13783 		 loopback, "loopback");
13784 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13785 	TOKEN_NUM_INITIALIZER
13786 		(struct cmd_tx_loopback_result,
13787 		 port_id, UINT16);
13788 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13789 	TOKEN_STRING_INITIALIZER
13790 		(struct cmd_tx_loopback_result,
13791 		 on_off, "on#off");
13792 
13793 static void
13794 cmd_set_tx_loopback_parsed(
13795 	void *parsed_result,
13796 	__attribute__((unused)) struct cmdline *cl,
13797 	__attribute__((unused)) void *data)
13798 {
13799 	struct cmd_tx_loopback_result *res = parsed_result;
13800 	int ret = -ENOTSUP;
13801 
13802 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13803 
13804 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13805 		return;
13806 
13807 #ifdef RTE_LIBRTE_IXGBE_PMD
13808 	if (ret == -ENOTSUP)
13809 		ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13810 #endif
13811 #ifdef RTE_LIBRTE_I40E_PMD
13812 	if (ret == -ENOTSUP)
13813 		ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13814 #endif
13815 #ifdef RTE_LIBRTE_BNXT_PMD
13816 	if (ret == -ENOTSUP)
13817 		ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13818 #endif
13819 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13820 	if (ret == -ENOTSUP)
13821 		ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13822 #endif
13823 
13824 	switch (ret) {
13825 	case 0:
13826 		break;
13827 	case -EINVAL:
13828 		printf("invalid is_on %d\n", is_on);
13829 		break;
13830 	case -ENODEV:
13831 		printf("invalid port_id %d\n", res->port_id);
13832 		break;
13833 	case -ENOTSUP:
13834 		printf("function not implemented\n");
13835 		break;
13836 	default:
13837 		printf("programming error: (%s)\n", strerror(-ret));
13838 	}
13839 }
13840 
13841 cmdline_parse_inst_t cmd_set_tx_loopback = {
13842 	.f = cmd_set_tx_loopback_parsed,
13843 	.data = NULL,
13844 	.help_str = "set tx loopback <port_id> on|off",
13845 	.tokens = {
13846 		(void *)&cmd_tx_loopback_set,
13847 		(void *)&cmd_tx_loopback_tx,
13848 		(void *)&cmd_tx_loopback_loopback,
13849 		(void *)&cmd_tx_loopback_port_id,
13850 		(void *)&cmd_tx_loopback_on_off,
13851 		NULL,
13852 	},
13853 };
13854 
13855 /* all queues drop enable configuration */
13856 
13857 /* Common result structure for all queues drop enable */
13858 struct cmd_all_queues_drop_en_result {
13859 	cmdline_fixed_string_t set;
13860 	cmdline_fixed_string_t all;
13861 	cmdline_fixed_string_t queues;
13862 	cmdline_fixed_string_t drop;
13863 	portid_t port_id;
13864 	cmdline_fixed_string_t on_off;
13865 };
13866 
13867 /* Common CLI fields for tx loopback enable disable */
13868 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13869 	TOKEN_STRING_INITIALIZER
13870 		(struct cmd_all_queues_drop_en_result,
13871 		 set, "set");
13872 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13873 	TOKEN_STRING_INITIALIZER
13874 		(struct cmd_all_queues_drop_en_result,
13875 		 all, "all");
13876 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13877 	TOKEN_STRING_INITIALIZER
13878 		(struct cmd_all_queues_drop_en_result,
13879 		 queues, "queues");
13880 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13881 	TOKEN_STRING_INITIALIZER
13882 		(struct cmd_all_queues_drop_en_result,
13883 		 drop, "drop");
13884 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13885 	TOKEN_NUM_INITIALIZER
13886 		(struct cmd_all_queues_drop_en_result,
13887 		 port_id, UINT16);
13888 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13889 	TOKEN_STRING_INITIALIZER
13890 		(struct cmd_all_queues_drop_en_result,
13891 		 on_off, "on#off");
13892 
13893 static void
13894 cmd_set_all_queues_drop_en_parsed(
13895 	void *parsed_result,
13896 	__attribute__((unused)) struct cmdline *cl,
13897 	__attribute__((unused)) void *data)
13898 {
13899 	struct cmd_all_queues_drop_en_result *res = parsed_result;
13900 	int ret = -ENOTSUP;
13901 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13902 
13903 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13904 		return;
13905 
13906 #ifdef RTE_LIBRTE_IXGBE_PMD
13907 	if (ret == -ENOTSUP)
13908 		ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13909 #endif
13910 #ifdef RTE_LIBRTE_BNXT_PMD
13911 	if (ret == -ENOTSUP)
13912 		ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13913 #endif
13914 	switch (ret) {
13915 	case 0:
13916 		break;
13917 	case -EINVAL:
13918 		printf("invalid is_on %d\n", is_on);
13919 		break;
13920 	case -ENODEV:
13921 		printf("invalid port_id %d\n", res->port_id);
13922 		break;
13923 	case -ENOTSUP:
13924 		printf("function not implemented\n");
13925 		break;
13926 	default:
13927 		printf("programming error: (%s)\n", strerror(-ret));
13928 	}
13929 }
13930 
13931 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13932 	.f = cmd_set_all_queues_drop_en_parsed,
13933 	.data = NULL,
13934 	.help_str = "set all queues drop <port_id> on|off",
13935 	.tokens = {
13936 		(void *)&cmd_all_queues_drop_en_set,
13937 		(void *)&cmd_all_queues_drop_en_all,
13938 		(void *)&cmd_all_queues_drop_en_queues,
13939 		(void *)&cmd_all_queues_drop_en_drop,
13940 		(void *)&cmd_all_queues_drop_en_port_id,
13941 		(void *)&cmd_all_queues_drop_en_on_off,
13942 		NULL,
13943 	},
13944 };
13945 
13946 /* vf split drop enable configuration */
13947 
13948 /* Common result structure for vf split drop enable */
13949 struct cmd_vf_split_drop_en_result {
13950 	cmdline_fixed_string_t set;
13951 	cmdline_fixed_string_t vf;
13952 	cmdline_fixed_string_t split;
13953 	cmdline_fixed_string_t drop;
13954 	portid_t port_id;
13955 	uint16_t vf_id;
13956 	cmdline_fixed_string_t on_off;
13957 };
13958 
13959 /* Common CLI fields for vf split drop enable disable */
13960 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13961 	TOKEN_STRING_INITIALIZER
13962 		(struct cmd_vf_split_drop_en_result,
13963 		 set, "set");
13964 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13965 	TOKEN_STRING_INITIALIZER
13966 		(struct cmd_vf_split_drop_en_result,
13967 		 vf, "vf");
13968 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13969 	TOKEN_STRING_INITIALIZER
13970 		(struct cmd_vf_split_drop_en_result,
13971 		 split, "split");
13972 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13973 	TOKEN_STRING_INITIALIZER
13974 		(struct cmd_vf_split_drop_en_result,
13975 		 drop, "drop");
13976 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13977 	TOKEN_NUM_INITIALIZER
13978 		(struct cmd_vf_split_drop_en_result,
13979 		 port_id, UINT16);
13980 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13981 	TOKEN_NUM_INITIALIZER
13982 		(struct cmd_vf_split_drop_en_result,
13983 		 vf_id, UINT16);
13984 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13985 	TOKEN_STRING_INITIALIZER
13986 		(struct cmd_vf_split_drop_en_result,
13987 		 on_off, "on#off");
13988 
13989 static void
13990 cmd_set_vf_split_drop_en_parsed(
13991 	void *parsed_result,
13992 	__attribute__((unused)) struct cmdline *cl,
13993 	__attribute__((unused)) void *data)
13994 {
13995 	struct cmd_vf_split_drop_en_result *res = parsed_result;
13996 	int ret = -ENOTSUP;
13997 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13998 
13999 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14000 		return;
14001 
14002 #ifdef RTE_LIBRTE_IXGBE_PMD
14003 	ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14004 			is_on);
14005 #endif
14006 	switch (ret) {
14007 	case 0:
14008 		break;
14009 	case -EINVAL:
14010 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14011 		break;
14012 	case -ENODEV:
14013 		printf("invalid port_id %d\n", res->port_id);
14014 		break;
14015 	case -ENOTSUP:
14016 		printf("not supported on port %d\n", res->port_id);
14017 		break;
14018 	default:
14019 		printf("programming error: (%s)\n", strerror(-ret));
14020 	}
14021 }
14022 
14023 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14024 	.f = cmd_set_vf_split_drop_en_parsed,
14025 	.data = NULL,
14026 	.help_str = "set vf split drop <port_id> <vf_id> on|off",
14027 	.tokens = {
14028 		(void *)&cmd_vf_split_drop_en_set,
14029 		(void *)&cmd_vf_split_drop_en_vf,
14030 		(void *)&cmd_vf_split_drop_en_split,
14031 		(void *)&cmd_vf_split_drop_en_drop,
14032 		(void *)&cmd_vf_split_drop_en_port_id,
14033 		(void *)&cmd_vf_split_drop_en_vf_id,
14034 		(void *)&cmd_vf_split_drop_en_on_off,
14035 		NULL,
14036 	},
14037 };
14038 
14039 /* vf mac address configuration */
14040 
14041 /* Common result structure for vf mac address */
14042 struct cmd_set_vf_mac_addr_result {
14043 	cmdline_fixed_string_t set;
14044 	cmdline_fixed_string_t vf;
14045 	cmdline_fixed_string_t mac;
14046 	cmdline_fixed_string_t addr;
14047 	portid_t port_id;
14048 	uint16_t vf_id;
14049 	struct rte_ether_addr mac_addr;
14050 
14051 };
14052 
14053 /* Common CLI fields for vf split drop enable disable */
14054 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14055 	TOKEN_STRING_INITIALIZER
14056 		(struct cmd_set_vf_mac_addr_result,
14057 		 set, "set");
14058 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14059 	TOKEN_STRING_INITIALIZER
14060 		(struct cmd_set_vf_mac_addr_result,
14061 		 vf, "vf");
14062 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14063 	TOKEN_STRING_INITIALIZER
14064 		(struct cmd_set_vf_mac_addr_result,
14065 		 mac, "mac");
14066 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14067 	TOKEN_STRING_INITIALIZER
14068 		(struct cmd_set_vf_mac_addr_result,
14069 		 addr, "addr");
14070 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14071 	TOKEN_NUM_INITIALIZER
14072 		(struct cmd_set_vf_mac_addr_result,
14073 		 port_id, UINT16);
14074 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14075 	TOKEN_NUM_INITIALIZER
14076 		(struct cmd_set_vf_mac_addr_result,
14077 		 vf_id, UINT16);
14078 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14079 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14080 		 mac_addr);
14081 
14082 static void
14083 cmd_set_vf_mac_addr_parsed(
14084 	void *parsed_result,
14085 	__attribute__((unused)) struct cmdline *cl,
14086 	__attribute__((unused)) void *data)
14087 {
14088 	struct cmd_set_vf_mac_addr_result *res = parsed_result;
14089 	int ret = -ENOTSUP;
14090 
14091 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14092 		return;
14093 
14094 #ifdef RTE_LIBRTE_IXGBE_PMD
14095 	if (ret == -ENOTSUP)
14096 		ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14097 				&res->mac_addr);
14098 #endif
14099 #ifdef RTE_LIBRTE_I40E_PMD
14100 	if (ret == -ENOTSUP)
14101 		ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14102 				&res->mac_addr);
14103 #endif
14104 #ifdef RTE_LIBRTE_BNXT_PMD
14105 	if (ret == -ENOTSUP)
14106 		ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14107 				&res->mac_addr);
14108 #endif
14109 
14110 	switch (ret) {
14111 	case 0:
14112 		break;
14113 	case -EINVAL:
14114 		printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14115 		break;
14116 	case -ENODEV:
14117 		printf("invalid port_id %d\n", res->port_id);
14118 		break;
14119 	case -ENOTSUP:
14120 		printf("function not implemented\n");
14121 		break;
14122 	default:
14123 		printf("programming error: (%s)\n", strerror(-ret));
14124 	}
14125 }
14126 
14127 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14128 	.f = cmd_set_vf_mac_addr_parsed,
14129 	.data = NULL,
14130 	.help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14131 	.tokens = {
14132 		(void *)&cmd_set_vf_mac_addr_set,
14133 		(void *)&cmd_set_vf_mac_addr_vf,
14134 		(void *)&cmd_set_vf_mac_addr_mac,
14135 		(void *)&cmd_set_vf_mac_addr_addr,
14136 		(void *)&cmd_set_vf_mac_addr_port_id,
14137 		(void *)&cmd_set_vf_mac_addr_vf_id,
14138 		(void *)&cmd_set_vf_mac_addr_mac_addr,
14139 		NULL,
14140 	},
14141 };
14142 
14143 /* MACsec configuration */
14144 
14145 /* Common result structure for MACsec offload enable */
14146 struct cmd_macsec_offload_on_result {
14147 	cmdline_fixed_string_t set;
14148 	cmdline_fixed_string_t macsec;
14149 	cmdline_fixed_string_t offload;
14150 	portid_t port_id;
14151 	cmdline_fixed_string_t on;
14152 	cmdline_fixed_string_t encrypt;
14153 	cmdline_fixed_string_t en_on_off;
14154 	cmdline_fixed_string_t replay_protect;
14155 	cmdline_fixed_string_t rp_on_off;
14156 };
14157 
14158 /* Common CLI fields for MACsec offload disable */
14159 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14160 	TOKEN_STRING_INITIALIZER
14161 		(struct cmd_macsec_offload_on_result,
14162 		 set, "set");
14163 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14164 	TOKEN_STRING_INITIALIZER
14165 		(struct cmd_macsec_offload_on_result,
14166 		 macsec, "macsec");
14167 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14168 	TOKEN_STRING_INITIALIZER
14169 		(struct cmd_macsec_offload_on_result,
14170 		 offload, "offload");
14171 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14172 	TOKEN_NUM_INITIALIZER
14173 		(struct cmd_macsec_offload_on_result,
14174 		 port_id, UINT16);
14175 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14176 	TOKEN_STRING_INITIALIZER
14177 		(struct cmd_macsec_offload_on_result,
14178 		 on, "on");
14179 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14180 	TOKEN_STRING_INITIALIZER
14181 		(struct cmd_macsec_offload_on_result,
14182 		 encrypt, "encrypt");
14183 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14184 	TOKEN_STRING_INITIALIZER
14185 		(struct cmd_macsec_offload_on_result,
14186 		 en_on_off, "on#off");
14187 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14188 	TOKEN_STRING_INITIALIZER
14189 		(struct cmd_macsec_offload_on_result,
14190 		 replay_protect, "replay-protect");
14191 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14192 	TOKEN_STRING_INITIALIZER
14193 		(struct cmd_macsec_offload_on_result,
14194 		 rp_on_off, "on#off");
14195 
14196 static void
14197 cmd_set_macsec_offload_on_parsed(
14198 	void *parsed_result,
14199 	__attribute__((unused)) struct cmdline *cl,
14200 	__attribute__((unused)) void *data)
14201 {
14202 	struct cmd_macsec_offload_on_result *res = parsed_result;
14203 	int ret = -ENOTSUP;
14204 	portid_t port_id = res->port_id;
14205 	int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14206 	int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14207 	struct rte_eth_dev_info dev_info;
14208 
14209 	if (port_id_is_invalid(port_id, ENABLED_WARN))
14210 		return;
14211 	if (!port_is_stopped(port_id)) {
14212 		printf("Please stop port %d first\n", port_id);
14213 		return;
14214 	}
14215 
14216 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
14217 	if (ret != 0)
14218 		return;
14219 
14220 	if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14221 #ifdef RTE_LIBRTE_IXGBE_PMD
14222 		ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14223 #endif
14224 	}
14225 	RTE_SET_USED(en);
14226 	RTE_SET_USED(rp);
14227 
14228 	switch (ret) {
14229 	case 0:
14230 		ports[port_id].dev_conf.txmode.offloads |=
14231 						DEV_TX_OFFLOAD_MACSEC_INSERT;
14232 		cmd_reconfig_device_queue(port_id, 1, 1);
14233 		break;
14234 	case -ENODEV:
14235 		printf("invalid port_id %d\n", port_id);
14236 		break;
14237 	case -ENOTSUP:
14238 		printf("not supported on port %d\n", port_id);
14239 		break;
14240 	default:
14241 		printf("programming error: (%s)\n", strerror(-ret));
14242 	}
14243 }
14244 
14245 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14246 	.f = cmd_set_macsec_offload_on_parsed,
14247 	.data = NULL,
14248 	.help_str = "set macsec offload <port_id> on "
14249 		"encrypt on|off replay-protect on|off",
14250 	.tokens = {
14251 		(void *)&cmd_macsec_offload_on_set,
14252 		(void *)&cmd_macsec_offload_on_macsec,
14253 		(void *)&cmd_macsec_offload_on_offload,
14254 		(void *)&cmd_macsec_offload_on_port_id,
14255 		(void *)&cmd_macsec_offload_on_on,
14256 		(void *)&cmd_macsec_offload_on_encrypt,
14257 		(void *)&cmd_macsec_offload_on_en_on_off,
14258 		(void *)&cmd_macsec_offload_on_replay_protect,
14259 		(void *)&cmd_macsec_offload_on_rp_on_off,
14260 		NULL,
14261 	},
14262 };
14263 
14264 /* Common result structure for MACsec offload disable */
14265 struct cmd_macsec_offload_off_result {
14266 	cmdline_fixed_string_t set;
14267 	cmdline_fixed_string_t macsec;
14268 	cmdline_fixed_string_t offload;
14269 	portid_t port_id;
14270 	cmdline_fixed_string_t off;
14271 };
14272 
14273 /* Common CLI fields for MACsec offload disable */
14274 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14275 	TOKEN_STRING_INITIALIZER
14276 		(struct cmd_macsec_offload_off_result,
14277 		 set, "set");
14278 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14279 	TOKEN_STRING_INITIALIZER
14280 		(struct cmd_macsec_offload_off_result,
14281 		 macsec, "macsec");
14282 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14283 	TOKEN_STRING_INITIALIZER
14284 		(struct cmd_macsec_offload_off_result,
14285 		 offload, "offload");
14286 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14287 	TOKEN_NUM_INITIALIZER
14288 		(struct cmd_macsec_offload_off_result,
14289 		 port_id, UINT16);
14290 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14291 	TOKEN_STRING_INITIALIZER
14292 		(struct cmd_macsec_offload_off_result,
14293 		 off, "off");
14294 
14295 static void
14296 cmd_set_macsec_offload_off_parsed(
14297 	void *parsed_result,
14298 	__attribute__((unused)) struct cmdline *cl,
14299 	__attribute__((unused)) void *data)
14300 {
14301 	struct cmd_macsec_offload_off_result *res = parsed_result;
14302 	int ret = -ENOTSUP;
14303 	struct rte_eth_dev_info dev_info;
14304 	portid_t port_id = res->port_id;
14305 
14306 	if (port_id_is_invalid(port_id, ENABLED_WARN))
14307 		return;
14308 	if (!port_is_stopped(port_id)) {
14309 		printf("Please stop port %d first\n", port_id);
14310 		return;
14311 	}
14312 
14313 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
14314 	if (ret != 0)
14315 		return;
14316 
14317 	if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14318 #ifdef RTE_LIBRTE_IXGBE_PMD
14319 		ret = rte_pmd_ixgbe_macsec_disable(port_id);
14320 #endif
14321 	}
14322 	switch (ret) {
14323 	case 0:
14324 		ports[port_id].dev_conf.txmode.offloads &=
14325 						~DEV_TX_OFFLOAD_MACSEC_INSERT;
14326 		cmd_reconfig_device_queue(port_id, 1, 1);
14327 		break;
14328 	case -ENODEV:
14329 		printf("invalid port_id %d\n", port_id);
14330 		break;
14331 	case -ENOTSUP:
14332 		printf("not supported on port %d\n", port_id);
14333 		break;
14334 	default:
14335 		printf("programming error: (%s)\n", strerror(-ret));
14336 	}
14337 }
14338 
14339 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14340 	.f = cmd_set_macsec_offload_off_parsed,
14341 	.data = NULL,
14342 	.help_str = "set macsec offload <port_id> off",
14343 	.tokens = {
14344 		(void *)&cmd_macsec_offload_off_set,
14345 		(void *)&cmd_macsec_offload_off_macsec,
14346 		(void *)&cmd_macsec_offload_off_offload,
14347 		(void *)&cmd_macsec_offload_off_port_id,
14348 		(void *)&cmd_macsec_offload_off_off,
14349 		NULL,
14350 	},
14351 };
14352 
14353 /* Common result structure for MACsec secure connection configure */
14354 struct cmd_macsec_sc_result {
14355 	cmdline_fixed_string_t set;
14356 	cmdline_fixed_string_t macsec;
14357 	cmdline_fixed_string_t sc;
14358 	cmdline_fixed_string_t tx_rx;
14359 	portid_t port_id;
14360 	struct rte_ether_addr mac;
14361 	uint16_t pi;
14362 };
14363 
14364 /* Common CLI fields for MACsec secure connection configure */
14365 cmdline_parse_token_string_t cmd_macsec_sc_set =
14366 	TOKEN_STRING_INITIALIZER
14367 		(struct cmd_macsec_sc_result,
14368 		 set, "set");
14369 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14370 	TOKEN_STRING_INITIALIZER
14371 		(struct cmd_macsec_sc_result,
14372 		 macsec, "macsec");
14373 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14374 	TOKEN_STRING_INITIALIZER
14375 		(struct cmd_macsec_sc_result,
14376 		 sc, "sc");
14377 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14378 	TOKEN_STRING_INITIALIZER
14379 		(struct cmd_macsec_sc_result,
14380 		 tx_rx, "tx#rx");
14381 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14382 	TOKEN_NUM_INITIALIZER
14383 		(struct cmd_macsec_sc_result,
14384 		 port_id, UINT16);
14385 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14386 	TOKEN_ETHERADDR_INITIALIZER
14387 		(struct cmd_macsec_sc_result,
14388 		 mac);
14389 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14390 	TOKEN_NUM_INITIALIZER
14391 		(struct cmd_macsec_sc_result,
14392 		 pi, UINT16);
14393 
14394 static void
14395 cmd_set_macsec_sc_parsed(
14396 	void *parsed_result,
14397 	__attribute__((unused)) struct cmdline *cl,
14398 	__attribute__((unused)) void *data)
14399 {
14400 	struct cmd_macsec_sc_result *res = parsed_result;
14401 	int ret = -ENOTSUP;
14402 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14403 
14404 #ifdef RTE_LIBRTE_IXGBE_PMD
14405 	ret = is_tx ?
14406 		rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14407 				res->mac.addr_bytes) :
14408 		rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14409 				res->mac.addr_bytes, res->pi);
14410 #endif
14411 	RTE_SET_USED(is_tx);
14412 
14413 	switch (ret) {
14414 	case 0:
14415 		break;
14416 	case -ENODEV:
14417 		printf("invalid port_id %d\n", res->port_id);
14418 		break;
14419 	case -ENOTSUP:
14420 		printf("not supported on port %d\n", res->port_id);
14421 		break;
14422 	default:
14423 		printf("programming error: (%s)\n", strerror(-ret));
14424 	}
14425 }
14426 
14427 cmdline_parse_inst_t cmd_set_macsec_sc = {
14428 	.f = cmd_set_macsec_sc_parsed,
14429 	.data = NULL,
14430 	.help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14431 	.tokens = {
14432 		(void *)&cmd_macsec_sc_set,
14433 		(void *)&cmd_macsec_sc_macsec,
14434 		(void *)&cmd_macsec_sc_sc,
14435 		(void *)&cmd_macsec_sc_tx_rx,
14436 		(void *)&cmd_macsec_sc_port_id,
14437 		(void *)&cmd_macsec_sc_mac,
14438 		(void *)&cmd_macsec_sc_pi,
14439 		NULL,
14440 	},
14441 };
14442 
14443 /* Common result structure for MACsec secure connection configure */
14444 struct cmd_macsec_sa_result {
14445 	cmdline_fixed_string_t set;
14446 	cmdline_fixed_string_t macsec;
14447 	cmdline_fixed_string_t sa;
14448 	cmdline_fixed_string_t tx_rx;
14449 	portid_t port_id;
14450 	uint8_t idx;
14451 	uint8_t an;
14452 	uint32_t pn;
14453 	cmdline_fixed_string_t key;
14454 };
14455 
14456 /* Common CLI fields for MACsec secure connection configure */
14457 cmdline_parse_token_string_t cmd_macsec_sa_set =
14458 	TOKEN_STRING_INITIALIZER
14459 		(struct cmd_macsec_sa_result,
14460 		 set, "set");
14461 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14462 	TOKEN_STRING_INITIALIZER
14463 		(struct cmd_macsec_sa_result,
14464 		 macsec, "macsec");
14465 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14466 	TOKEN_STRING_INITIALIZER
14467 		(struct cmd_macsec_sa_result,
14468 		 sa, "sa");
14469 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14470 	TOKEN_STRING_INITIALIZER
14471 		(struct cmd_macsec_sa_result,
14472 		 tx_rx, "tx#rx");
14473 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14474 	TOKEN_NUM_INITIALIZER
14475 		(struct cmd_macsec_sa_result,
14476 		 port_id, UINT16);
14477 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14478 	TOKEN_NUM_INITIALIZER
14479 		(struct cmd_macsec_sa_result,
14480 		 idx, UINT8);
14481 cmdline_parse_token_num_t cmd_macsec_sa_an =
14482 	TOKEN_NUM_INITIALIZER
14483 		(struct cmd_macsec_sa_result,
14484 		 an, UINT8);
14485 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14486 	TOKEN_NUM_INITIALIZER
14487 		(struct cmd_macsec_sa_result,
14488 		 pn, UINT32);
14489 cmdline_parse_token_string_t cmd_macsec_sa_key =
14490 	TOKEN_STRING_INITIALIZER
14491 		(struct cmd_macsec_sa_result,
14492 		 key, NULL);
14493 
14494 static void
14495 cmd_set_macsec_sa_parsed(
14496 	void *parsed_result,
14497 	__attribute__((unused)) struct cmdline *cl,
14498 	__attribute__((unused)) void *data)
14499 {
14500 	struct cmd_macsec_sa_result *res = parsed_result;
14501 	int ret = -ENOTSUP;
14502 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14503 	uint8_t key[16] = { 0 };
14504 	uint8_t xdgt0;
14505 	uint8_t xdgt1;
14506 	int key_len;
14507 	int i;
14508 
14509 	key_len = strlen(res->key) / 2;
14510 	if (key_len > 16)
14511 		key_len = 16;
14512 
14513 	for (i = 0; i < key_len; i++) {
14514 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14515 		if (xdgt0 == 0xFF)
14516 			return;
14517 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14518 		if (xdgt1 == 0xFF)
14519 			return;
14520 		key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14521 	}
14522 
14523 #ifdef RTE_LIBRTE_IXGBE_PMD
14524 	ret = is_tx ?
14525 		rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14526 			res->idx, res->an, res->pn, key) :
14527 		rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14528 			res->idx, res->an, res->pn, key);
14529 #endif
14530 	RTE_SET_USED(is_tx);
14531 	RTE_SET_USED(key);
14532 
14533 	switch (ret) {
14534 	case 0:
14535 		break;
14536 	case -EINVAL:
14537 		printf("invalid idx %d or an %d\n", res->idx, res->an);
14538 		break;
14539 	case -ENODEV:
14540 		printf("invalid port_id %d\n", res->port_id);
14541 		break;
14542 	case -ENOTSUP:
14543 		printf("not supported on port %d\n", res->port_id);
14544 		break;
14545 	default:
14546 		printf("programming error: (%s)\n", strerror(-ret));
14547 	}
14548 }
14549 
14550 cmdline_parse_inst_t cmd_set_macsec_sa = {
14551 	.f = cmd_set_macsec_sa_parsed,
14552 	.data = NULL,
14553 	.help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14554 	.tokens = {
14555 		(void *)&cmd_macsec_sa_set,
14556 		(void *)&cmd_macsec_sa_macsec,
14557 		(void *)&cmd_macsec_sa_sa,
14558 		(void *)&cmd_macsec_sa_tx_rx,
14559 		(void *)&cmd_macsec_sa_port_id,
14560 		(void *)&cmd_macsec_sa_idx,
14561 		(void *)&cmd_macsec_sa_an,
14562 		(void *)&cmd_macsec_sa_pn,
14563 		(void *)&cmd_macsec_sa_key,
14564 		NULL,
14565 	},
14566 };
14567 
14568 /* VF unicast promiscuous mode configuration */
14569 
14570 /* Common result structure for VF unicast promiscuous mode */
14571 struct cmd_vf_promisc_result {
14572 	cmdline_fixed_string_t set;
14573 	cmdline_fixed_string_t vf;
14574 	cmdline_fixed_string_t promisc;
14575 	portid_t port_id;
14576 	uint32_t vf_id;
14577 	cmdline_fixed_string_t on_off;
14578 };
14579 
14580 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14581 cmdline_parse_token_string_t cmd_vf_promisc_set =
14582 	TOKEN_STRING_INITIALIZER
14583 		(struct cmd_vf_promisc_result,
14584 		 set, "set");
14585 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14586 	TOKEN_STRING_INITIALIZER
14587 		(struct cmd_vf_promisc_result,
14588 		 vf, "vf");
14589 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14590 	TOKEN_STRING_INITIALIZER
14591 		(struct cmd_vf_promisc_result,
14592 		 promisc, "promisc");
14593 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14594 	TOKEN_NUM_INITIALIZER
14595 		(struct cmd_vf_promisc_result,
14596 		 port_id, UINT16);
14597 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14598 	TOKEN_NUM_INITIALIZER
14599 		(struct cmd_vf_promisc_result,
14600 		 vf_id, UINT32);
14601 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14602 	TOKEN_STRING_INITIALIZER
14603 		(struct cmd_vf_promisc_result,
14604 		 on_off, "on#off");
14605 
14606 static void
14607 cmd_set_vf_promisc_parsed(
14608 	void *parsed_result,
14609 	__attribute__((unused)) struct cmdline *cl,
14610 	__attribute__((unused)) void *data)
14611 {
14612 	struct cmd_vf_promisc_result *res = parsed_result;
14613 	int ret = -ENOTSUP;
14614 
14615 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14616 
14617 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14618 		return;
14619 
14620 #ifdef RTE_LIBRTE_I40E_PMD
14621 	ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14622 						  res->vf_id, is_on);
14623 #endif
14624 
14625 	switch (ret) {
14626 	case 0:
14627 		break;
14628 	case -EINVAL:
14629 		printf("invalid vf_id %d\n", res->vf_id);
14630 		break;
14631 	case -ENODEV:
14632 		printf("invalid port_id %d\n", res->port_id);
14633 		break;
14634 	case -ENOTSUP:
14635 		printf("function not implemented\n");
14636 		break;
14637 	default:
14638 		printf("programming error: (%s)\n", strerror(-ret));
14639 	}
14640 }
14641 
14642 cmdline_parse_inst_t cmd_set_vf_promisc = {
14643 	.f = cmd_set_vf_promisc_parsed,
14644 	.data = NULL,
14645 	.help_str = "set vf promisc <port_id> <vf_id> on|off: "
14646 		"Set unicast promiscuous mode for a VF from the PF",
14647 	.tokens = {
14648 		(void *)&cmd_vf_promisc_set,
14649 		(void *)&cmd_vf_promisc_vf,
14650 		(void *)&cmd_vf_promisc_promisc,
14651 		(void *)&cmd_vf_promisc_port_id,
14652 		(void *)&cmd_vf_promisc_vf_id,
14653 		(void *)&cmd_vf_promisc_on_off,
14654 		NULL,
14655 	},
14656 };
14657 
14658 /* VF multicast promiscuous mode configuration */
14659 
14660 /* Common result structure for VF multicast promiscuous mode */
14661 struct cmd_vf_allmulti_result {
14662 	cmdline_fixed_string_t set;
14663 	cmdline_fixed_string_t vf;
14664 	cmdline_fixed_string_t allmulti;
14665 	portid_t port_id;
14666 	uint32_t vf_id;
14667 	cmdline_fixed_string_t on_off;
14668 };
14669 
14670 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14671 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14672 	TOKEN_STRING_INITIALIZER
14673 		(struct cmd_vf_allmulti_result,
14674 		 set, "set");
14675 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14676 	TOKEN_STRING_INITIALIZER
14677 		(struct cmd_vf_allmulti_result,
14678 		 vf, "vf");
14679 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14680 	TOKEN_STRING_INITIALIZER
14681 		(struct cmd_vf_allmulti_result,
14682 		 allmulti, "allmulti");
14683 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14684 	TOKEN_NUM_INITIALIZER
14685 		(struct cmd_vf_allmulti_result,
14686 		 port_id, UINT16);
14687 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14688 	TOKEN_NUM_INITIALIZER
14689 		(struct cmd_vf_allmulti_result,
14690 		 vf_id, UINT32);
14691 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14692 	TOKEN_STRING_INITIALIZER
14693 		(struct cmd_vf_allmulti_result,
14694 		 on_off, "on#off");
14695 
14696 static void
14697 cmd_set_vf_allmulti_parsed(
14698 	void *parsed_result,
14699 	__attribute__((unused)) struct cmdline *cl,
14700 	__attribute__((unused)) void *data)
14701 {
14702 	struct cmd_vf_allmulti_result *res = parsed_result;
14703 	int ret = -ENOTSUP;
14704 
14705 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14706 
14707 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14708 		return;
14709 
14710 #ifdef RTE_LIBRTE_I40E_PMD
14711 	ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14712 						    res->vf_id, is_on);
14713 #endif
14714 
14715 	switch (ret) {
14716 	case 0:
14717 		break;
14718 	case -EINVAL:
14719 		printf("invalid vf_id %d\n", res->vf_id);
14720 		break;
14721 	case -ENODEV:
14722 		printf("invalid port_id %d\n", res->port_id);
14723 		break;
14724 	case -ENOTSUP:
14725 		printf("function not implemented\n");
14726 		break;
14727 	default:
14728 		printf("programming error: (%s)\n", strerror(-ret));
14729 	}
14730 }
14731 
14732 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14733 	.f = cmd_set_vf_allmulti_parsed,
14734 	.data = NULL,
14735 	.help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14736 		"Set multicast promiscuous mode for a VF from the PF",
14737 	.tokens = {
14738 		(void *)&cmd_vf_allmulti_set,
14739 		(void *)&cmd_vf_allmulti_vf,
14740 		(void *)&cmd_vf_allmulti_allmulti,
14741 		(void *)&cmd_vf_allmulti_port_id,
14742 		(void *)&cmd_vf_allmulti_vf_id,
14743 		(void *)&cmd_vf_allmulti_on_off,
14744 		NULL,
14745 	},
14746 };
14747 
14748 /* vf broadcast mode configuration */
14749 
14750 /* Common result structure for vf broadcast */
14751 struct cmd_set_vf_broadcast_result {
14752 	cmdline_fixed_string_t set;
14753 	cmdline_fixed_string_t vf;
14754 	cmdline_fixed_string_t broadcast;
14755 	portid_t port_id;
14756 	uint16_t vf_id;
14757 	cmdline_fixed_string_t on_off;
14758 };
14759 
14760 /* Common CLI fields for vf broadcast enable disable */
14761 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14762 	TOKEN_STRING_INITIALIZER
14763 		(struct cmd_set_vf_broadcast_result,
14764 		 set, "set");
14765 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14766 	TOKEN_STRING_INITIALIZER
14767 		(struct cmd_set_vf_broadcast_result,
14768 		 vf, "vf");
14769 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14770 	TOKEN_STRING_INITIALIZER
14771 		(struct cmd_set_vf_broadcast_result,
14772 		 broadcast, "broadcast");
14773 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14774 	TOKEN_NUM_INITIALIZER
14775 		(struct cmd_set_vf_broadcast_result,
14776 		 port_id, UINT16);
14777 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14778 	TOKEN_NUM_INITIALIZER
14779 		(struct cmd_set_vf_broadcast_result,
14780 		 vf_id, UINT16);
14781 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14782 	TOKEN_STRING_INITIALIZER
14783 		(struct cmd_set_vf_broadcast_result,
14784 		 on_off, "on#off");
14785 
14786 static void
14787 cmd_set_vf_broadcast_parsed(
14788 	void *parsed_result,
14789 	__attribute__((unused)) struct cmdline *cl,
14790 	__attribute__((unused)) void *data)
14791 {
14792 	struct cmd_set_vf_broadcast_result *res = parsed_result;
14793 	int ret = -ENOTSUP;
14794 
14795 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14796 
14797 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14798 		return;
14799 
14800 #ifdef RTE_LIBRTE_I40E_PMD
14801 	ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14802 					    res->vf_id, is_on);
14803 #endif
14804 
14805 	switch (ret) {
14806 	case 0:
14807 		break;
14808 	case -EINVAL:
14809 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14810 		break;
14811 	case -ENODEV:
14812 		printf("invalid port_id %d\n", res->port_id);
14813 		break;
14814 	case -ENOTSUP:
14815 		printf("function not implemented\n");
14816 		break;
14817 	default:
14818 		printf("programming error: (%s)\n", strerror(-ret));
14819 	}
14820 }
14821 
14822 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14823 	.f = cmd_set_vf_broadcast_parsed,
14824 	.data = NULL,
14825 	.help_str = "set vf broadcast <port_id> <vf_id> on|off",
14826 	.tokens = {
14827 		(void *)&cmd_set_vf_broadcast_set,
14828 		(void *)&cmd_set_vf_broadcast_vf,
14829 		(void *)&cmd_set_vf_broadcast_broadcast,
14830 		(void *)&cmd_set_vf_broadcast_port_id,
14831 		(void *)&cmd_set_vf_broadcast_vf_id,
14832 		(void *)&cmd_set_vf_broadcast_on_off,
14833 		NULL,
14834 	},
14835 };
14836 
14837 /* vf vlan tag configuration */
14838 
14839 /* Common result structure for vf vlan tag */
14840 struct cmd_set_vf_vlan_tag_result {
14841 	cmdline_fixed_string_t set;
14842 	cmdline_fixed_string_t vf;
14843 	cmdline_fixed_string_t vlan;
14844 	cmdline_fixed_string_t tag;
14845 	portid_t port_id;
14846 	uint16_t vf_id;
14847 	cmdline_fixed_string_t on_off;
14848 };
14849 
14850 /* Common CLI fields for vf vlan tag enable disable */
14851 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14852 	TOKEN_STRING_INITIALIZER
14853 		(struct cmd_set_vf_vlan_tag_result,
14854 		 set, "set");
14855 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14856 	TOKEN_STRING_INITIALIZER
14857 		(struct cmd_set_vf_vlan_tag_result,
14858 		 vf, "vf");
14859 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14860 	TOKEN_STRING_INITIALIZER
14861 		(struct cmd_set_vf_vlan_tag_result,
14862 		 vlan, "vlan");
14863 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14864 	TOKEN_STRING_INITIALIZER
14865 		(struct cmd_set_vf_vlan_tag_result,
14866 		 tag, "tag");
14867 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14868 	TOKEN_NUM_INITIALIZER
14869 		(struct cmd_set_vf_vlan_tag_result,
14870 		 port_id, UINT16);
14871 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14872 	TOKEN_NUM_INITIALIZER
14873 		(struct cmd_set_vf_vlan_tag_result,
14874 		 vf_id, UINT16);
14875 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14876 	TOKEN_STRING_INITIALIZER
14877 		(struct cmd_set_vf_vlan_tag_result,
14878 		 on_off, "on#off");
14879 
14880 static void
14881 cmd_set_vf_vlan_tag_parsed(
14882 	void *parsed_result,
14883 	__attribute__((unused)) struct cmdline *cl,
14884 	__attribute__((unused)) void *data)
14885 {
14886 	struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14887 	int ret = -ENOTSUP;
14888 
14889 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14890 
14891 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14892 		return;
14893 
14894 #ifdef RTE_LIBRTE_I40E_PMD
14895 	ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14896 					   res->vf_id, is_on);
14897 #endif
14898 
14899 	switch (ret) {
14900 	case 0:
14901 		break;
14902 	case -EINVAL:
14903 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14904 		break;
14905 	case -ENODEV:
14906 		printf("invalid port_id %d\n", res->port_id);
14907 		break;
14908 	case -ENOTSUP:
14909 		printf("function not implemented\n");
14910 		break;
14911 	default:
14912 		printf("programming error: (%s)\n", strerror(-ret));
14913 	}
14914 }
14915 
14916 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14917 	.f = cmd_set_vf_vlan_tag_parsed,
14918 	.data = NULL,
14919 	.help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14920 	.tokens = {
14921 		(void *)&cmd_set_vf_vlan_tag_set,
14922 		(void *)&cmd_set_vf_vlan_tag_vf,
14923 		(void *)&cmd_set_vf_vlan_tag_vlan,
14924 		(void *)&cmd_set_vf_vlan_tag_tag,
14925 		(void *)&cmd_set_vf_vlan_tag_port_id,
14926 		(void *)&cmd_set_vf_vlan_tag_vf_id,
14927 		(void *)&cmd_set_vf_vlan_tag_on_off,
14928 		NULL,
14929 	},
14930 };
14931 
14932 /* Common definition of VF and TC TX bandwidth configuration */
14933 struct cmd_vf_tc_bw_result {
14934 	cmdline_fixed_string_t set;
14935 	cmdline_fixed_string_t vf;
14936 	cmdline_fixed_string_t tc;
14937 	cmdline_fixed_string_t tx;
14938 	cmdline_fixed_string_t min_bw;
14939 	cmdline_fixed_string_t max_bw;
14940 	cmdline_fixed_string_t strict_link_prio;
14941 	portid_t port_id;
14942 	uint16_t vf_id;
14943 	uint8_t tc_no;
14944 	uint32_t bw;
14945 	cmdline_fixed_string_t bw_list;
14946 	uint8_t tc_map;
14947 };
14948 
14949 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14950 	TOKEN_STRING_INITIALIZER
14951 		(struct cmd_vf_tc_bw_result,
14952 		 set, "set");
14953 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14954 	TOKEN_STRING_INITIALIZER
14955 		(struct cmd_vf_tc_bw_result,
14956 		 vf, "vf");
14957 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14958 	TOKEN_STRING_INITIALIZER
14959 		(struct cmd_vf_tc_bw_result,
14960 		 tc, "tc");
14961 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14962 	TOKEN_STRING_INITIALIZER
14963 		(struct cmd_vf_tc_bw_result,
14964 		 tx, "tx");
14965 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14966 	TOKEN_STRING_INITIALIZER
14967 		(struct cmd_vf_tc_bw_result,
14968 		 strict_link_prio, "strict-link-priority");
14969 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14970 	TOKEN_STRING_INITIALIZER
14971 		(struct cmd_vf_tc_bw_result,
14972 		 min_bw, "min-bandwidth");
14973 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14974 	TOKEN_STRING_INITIALIZER
14975 		(struct cmd_vf_tc_bw_result,
14976 		 max_bw, "max-bandwidth");
14977 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14978 	TOKEN_NUM_INITIALIZER
14979 		(struct cmd_vf_tc_bw_result,
14980 		 port_id, UINT16);
14981 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14982 	TOKEN_NUM_INITIALIZER
14983 		(struct cmd_vf_tc_bw_result,
14984 		 vf_id, UINT16);
14985 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14986 	TOKEN_NUM_INITIALIZER
14987 		(struct cmd_vf_tc_bw_result,
14988 		 tc_no, UINT8);
14989 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14990 	TOKEN_NUM_INITIALIZER
14991 		(struct cmd_vf_tc_bw_result,
14992 		 bw, UINT32);
14993 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14994 	TOKEN_STRING_INITIALIZER
14995 		(struct cmd_vf_tc_bw_result,
14996 		 bw_list, NULL);
14997 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14998 	TOKEN_NUM_INITIALIZER
14999 		(struct cmd_vf_tc_bw_result,
15000 		 tc_map, UINT8);
15001 
15002 /* VF max bandwidth setting */
15003 static void
15004 cmd_vf_max_bw_parsed(
15005 	void *parsed_result,
15006 	__attribute__((unused)) struct cmdline *cl,
15007 	__attribute__((unused)) void *data)
15008 {
15009 	struct cmd_vf_tc_bw_result *res = parsed_result;
15010 	int ret = -ENOTSUP;
15011 
15012 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15013 		return;
15014 
15015 #ifdef RTE_LIBRTE_I40E_PMD
15016 	ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15017 					 res->vf_id, res->bw);
15018 #endif
15019 
15020 	switch (ret) {
15021 	case 0:
15022 		break;
15023 	case -EINVAL:
15024 		printf("invalid vf_id %d or bandwidth %d\n",
15025 		       res->vf_id, res->bw);
15026 		break;
15027 	case -ENODEV:
15028 		printf("invalid port_id %d\n", res->port_id);
15029 		break;
15030 	case -ENOTSUP:
15031 		printf("function not implemented\n");
15032 		break;
15033 	default:
15034 		printf("programming error: (%s)\n", strerror(-ret));
15035 	}
15036 }
15037 
15038 cmdline_parse_inst_t cmd_vf_max_bw = {
15039 	.f = cmd_vf_max_bw_parsed,
15040 	.data = NULL,
15041 	.help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15042 	.tokens = {
15043 		(void *)&cmd_vf_tc_bw_set,
15044 		(void *)&cmd_vf_tc_bw_vf,
15045 		(void *)&cmd_vf_tc_bw_tx,
15046 		(void *)&cmd_vf_tc_bw_max_bw,
15047 		(void *)&cmd_vf_tc_bw_port_id,
15048 		(void *)&cmd_vf_tc_bw_vf_id,
15049 		(void *)&cmd_vf_tc_bw_bw,
15050 		NULL,
15051 	},
15052 };
15053 
15054 static int
15055 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15056 			   uint8_t *tc_num,
15057 			   char *str)
15058 {
15059 	uint32_t size;
15060 	const char *p, *p0 = str;
15061 	char s[256];
15062 	char *end;
15063 	char *str_fld[16];
15064 	uint16_t i;
15065 	int ret;
15066 
15067 	p = strchr(p0, '(');
15068 	if (p == NULL) {
15069 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15070 		return -1;
15071 	}
15072 	p++;
15073 	p0 = strchr(p, ')');
15074 	if (p0 == NULL) {
15075 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15076 		return -1;
15077 	}
15078 	size = p0 - p;
15079 	if (size >= sizeof(s)) {
15080 		printf("The string size exceeds the internal buffer size\n");
15081 		return -1;
15082 	}
15083 	snprintf(s, sizeof(s), "%.*s", size, p);
15084 	ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15085 	if (ret <= 0) {
15086 		printf("Failed to get the bandwidth list. ");
15087 		return -1;
15088 	}
15089 	*tc_num = ret;
15090 	for (i = 0; i < ret; i++)
15091 		bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15092 
15093 	return 0;
15094 }
15095 
15096 /* TC min bandwidth setting */
15097 static void
15098 cmd_vf_tc_min_bw_parsed(
15099 	void *parsed_result,
15100 	__attribute__((unused)) struct cmdline *cl,
15101 	__attribute__((unused)) void *data)
15102 {
15103 	struct cmd_vf_tc_bw_result *res = parsed_result;
15104 	uint8_t tc_num;
15105 	uint8_t bw[16];
15106 	int ret = -ENOTSUP;
15107 
15108 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15109 		return;
15110 
15111 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15112 	if (ret)
15113 		return;
15114 
15115 #ifdef RTE_LIBRTE_I40E_PMD
15116 	ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15117 					      tc_num, bw);
15118 #endif
15119 
15120 	switch (ret) {
15121 	case 0:
15122 		break;
15123 	case -EINVAL:
15124 		printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15125 		break;
15126 	case -ENODEV:
15127 		printf("invalid port_id %d\n", res->port_id);
15128 		break;
15129 	case -ENOTSUP:
15130 		printf("function not implemented\n");
15131 		break;
15132 	default:
15133 		printf("programming error: (%s)\n", strerror(-ret));
15134 	}
15135 }
15136 
15137 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15138 	.f = cmd_vf_tc_min_bw_parsed,
15139 	.data = NULL,
15140 	.help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15141 		    " <bw1, bw2, ...>",
15142 	.tokens = {
15143 		(void *)&cmd_vf_tc_bw_set,
15144 		(void *)&cmd_vf_tc_bw_vf,
15145 		(void *)&cmd_vf_tc_bw_tc,
15146 		(void *)&cmd_vf_tc_bw_tx,
15147 		(void *)&cmd_vf_tc_bw_min_bw,
15148 		(void *)&cmd_vf_tc_bw_port_id,
15149 		(void *)&cmd_vf_tc_bw_vf_id,
15150 		(void *)&cmd_vf_tc_bw_bw_list,
15151 		NULL,
15152 	},
15153 };
15154 
15155 static void
15156 cmd_tc_min_bw_parsed(
15157 	void *parsed_result,
15158 	__attribute__((unused)) struct cmdline *cl,
15159 	__attribute__((unused)) void *data)
15160 {
15161 	struct cmd_vf_tc_bw_result *res = parsed_result;
15162 	struct rte_port *port;
15163 	uint8_t tc_num;
15164 	uint8_t bw[16];
15165 	int ret = -ENOTSUP;
15166 
15167 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15168 		return;
15169 
15170 	port = &ports[res->port_id];
15171 	/** Check if the port is not started **/
15172 	if (port->port_status != RTE_PORT_STOPPED) {
15173 		printf("Please stop port %d first\n", res->port_id);
15174 		return;
15175 	}
15176 
15177 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15178 	if (ret)
15179 		return;
15180 
15181 #ifdef RTE_LIBRTE_IXGBE_PMD
15182 	ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15183 #endif
15184 
15185 	switch (ret) {
15186 	case 0:
15187 		break;
15188 	case -EINVAL:
15189 		printf("invalid bandwidth\n");
15190 		break;
15191 	case -ENODEV:
15192 		printf("invalid port_id %d\n", res->port_id);
15193 		break;
15194 	case -ENOTSUP:
15195 		printf("function not implemented\n");
15196 		break;
15197 	default:
15198 		printf("programming error: (%s)\n", strerror(-ret));
15199 	}
15200 }
15201 
15202 cmdline_parse_inst_t cmd_tc_min_bw = {
15203 	.f = cmd_tc_min_bw_parsed,
15204 	.data = NULL,
15205 	.help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15206 	.tokens = {
15207 		(void *)&cmd_vf_tc_bw_set,
15208 		(void *)&cmd_vf_tc_bw_tc,
15209 		(void *)&cmd_vf_tc_bw_tx,
15210 		(void *)&cmd_vf_tc_bw_min_bw,
15211 		(void *)&cmd_vf_tc_bw_port_id,
15212 		(void *)&cmd_vf_tc_bw_bw_list,
15213 		NULL,
15214 	},
15215 };
15216 
15217 /* TC max bandwidth setting */
15218 static void
15219 cmd_vf_tc_max_bw_parsed(
15220 	void *parsed_result,
15221 	__attribute__((unused)) struct cmdline *cl,
15222 	__attribute__((unused)) void *data)
15223 {
15224 	struct cmd_vf_tc_bw_result *res = parsed_result;
15225 	int ret = -ENOTSUP;
15226 
15227 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15228 		return;
15229 
15230 #ifdef RTE_LIBRTE_I40E_PMD
15231 	ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15232 					    res->tc_no, res->bw);
15233 #endif
15234 
15235 	switch (ret) {
15236 	case 0:
15237 		break;
15238 	case -EINVAL:
15239 		printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15240 		       res->vf_id, res->tc_no, res->bw);
15241 		break;
15242 	case -ENODEV:
15243 		printf("invalid port_id %d\n", res->port_id);
15244 		break;
15245 	case -ENOTSUP:
15246 		printf("function not implemented\n");
15247 		break;
15248 	default:
15249 		printf("programming error: (%s)\n", strerror(-ret));
15250 	}
15251 }
15252 
15253 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15254 	.f = cmd_vf_tc_max_bw_parsed,
15255 	.data = NULL,
15256 	.help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15257 		    " <bandwidth>",
15258 	.tokens = {
15259 		(void *)&cmd_vf_tc_bw_set,
15260 		(void *)&cmd_vf_tc_bw_vf,
15261 		(void *)&cmd_vf_tc_bw_tc,
15262 		(void *)&cmd_vf_tc_bw_tx,
15263 		(void *)&cmd_vf_tc_bw_max_bw,
15264 		(void *)&cmd_vf_tc_bw_port_id,
15265 		(void *)&cmd_vf_tc_bw_vf_id,
15266 		(void *)&cmd_vf_tc_bw_tc_no,
15267 		(void *)&cmd_vf_tc_bw_bw,
15268 		NULL,
15269 	},
15270 };
15271 
15272 
15273 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15274 
15275 /* *** Set Port default Traffic Management Hierarchy *** */
15276 struct cmd_set_port_tm_hierarchy_default_result {
15277 	cmdline_fixed_string_t set;
15278 	cmdline_fixed_string_t port;
15279 	cmdline_fixed_string_t tm;
15280 	cmdline_fixed_string_t hierarchy;
15281 	cmdline_fixed_string_t def;
15282 	portid_t port_id;
15283 };
15284 
15285 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15286 	TOKEN_STRING_INITIALIZER(
15287 		struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15288 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15289 	TOKEN_STRING_INITIALIZER(
15290 		struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15291 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15292 	TOKEN_STRING_INITIALIZER(
15293 		struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15294 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15295 	TOKEN_STRING_INITIALIZER(
15296 		struct cmd_set_port_tm_hierarchy_default_result,
15297 			hierarchy, "hierarchy");
15298 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15299 	TOKEN_STRING_INITIALIZER(
15300 		struct cmd_set_port_tm_hierarchy_default_result,
15301 			def, "default");
15302 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15303 	TOKEN_NUM_INITIALIZER(
15304 		struct cmd_set_port_tm_hierarchy_default_result,
15305 			port_id, UINT16);
15306 
15307 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15308 	__attribute__((unused)) struct cmdline *cl,
15309 	__attribute__((unused)) void *data)
15310 {
15311 	struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15312 	struct rte_port *p;
15313 	portid_t port_id = res->port_id;
15314 
15315 	if (port_id_is_invalid(port_id, ENABLED_WARN))
15316 		return;
15317 
15318 	p = &ports[port_id];
15319 
15320 	/* Forward mode: tm */
15321 	if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15322 		printf("  softnicfwd mode not enabled(error)\n");
15323 		return;
15324 	}
15325 
15326 	/* Set the default tm hierarchy */
15327 	p->softport.default_tm_hierarchy_enable = 1;
15328 }
15329 
15330 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15331 	.f = cmd_set_port_tm_hierarchy_default_parsed,
15332 	.data = NULL,
15333 	.help_str = "set port tm hierarchy default <port_id>",
15334 	.tokens = {
15335 		(void *)&cmd_set_port_tm_hierarchy_default_set,
15336 		(void *)&cmd_set_port_tm_hierarchy_default_port,
15337 		(void *)&cmd_set_port_tm_hierarchy_default_tm,
15338 		(void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15339 		(void *)&cmd_set_port_tm_hierarchy_default_default,
15340 		(void *)&cmd_set_port_tm_hierarchy_default_port_id,
15341 		NULL,
15342 	},
15343 };
15344 #endif
15345 
15346 /** Set VXLAN encapsulation details */
15347 struct cmd_set_vxlan_result {
15348 	cmdline_fixed_string_t set;
15349 	cmdline_fixed_string_t vxlan;
15350 	cmdline_fixed_string_t pos_token;
15351 	cmdline_fixed_string_t ip_version;
15352 	uint32_t vlan_present:1;
15353 	uint32_t vni;
15354 	uint16_t udp_src;
15355 	uint16_t udp_dst;
15356 	cmdline_ipaddr_t ip_src;
15357 	cmdline_ipaddr_t ip_dst;
15358 	uint16_t tci;
15359 	uint8_t tos;
15360 	uint8_t ttl;
15361 	struct rte_ether_addr eth_src;
15362 	struct rte_ether_addr eth_dst;
15363 };
15364 
15365 cmdline_parse_token_string_t cmd_set_vxlan_set =
15366 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15367 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15368 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15369 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15370 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15371 				 "vxlan-tos-ttl");
15372 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15373 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15374 				 "vxlan-with-vlan");
15375 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15376 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15377 				 "ip-version");
15378 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15379 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15380 				 "ipv4#ipv6");
15381 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15382 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15383 				 "vni");
15384 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15385 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15386 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15387 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15388 				 "udp-src");
15389 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15390 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15391 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15392 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15393 				 "udp-dst");
15394 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15395 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15396 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15397 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15398 				 "ip-tos");
15399 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15400 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15401 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15402 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15403 				 "ip-ttl");
15404 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15405 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15406 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15407 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15408 				 "ip-src");
15409 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15410 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15411 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15412 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15413 				 "ip-dst");
15414 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15415 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15416 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15417 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15418 				 "vlan-tci");
15419 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15420 	TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15421 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15422 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15423 				 "eth-src");
15424 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15425 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15426 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15427 	TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15428 				 "eth-dst");
15429 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15430 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15431 
15432 static void cmd_set_vxlan_parsed(void *parsed_result,
15433 	__attribute__((unused)) struct cmdline *cl,
15434 	__attribute__((unused)) void *data)
15435 {
15436 	struct cmd_set_vxlan_result *res = parsed_result;
15437 	union {
15438 		uint32_t vxlan_id;
15439 		uint8_t vni[4];
15440 	} id = {
15441 		.vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15442 	};
15443 
15444 	vxlan_encap_conf.select_tos_ttl = 0;
15445 	if (strcmp(res->vxlan, "vxlan") == 0)
15446 		vxlan_encap_conf.select_vlan = 0;
15447 	else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15448 		vxlan_encap_conf.select_vlan = 1;
15449 	else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15450 		vxlan_encap_conf.select_vlan = 0;
15451 		vxlan_encap_conf.select_tos_ttl = 1;
15452 	}
15453 	if (strcmp(res->ip_version, "ipv4") == 0)
15454 		vxlan_encap_conf.select_ipv4 = 1;
15455 	else if (strcmp(res->ip_version, "ipv6") == 0)
15456 		vxlan_encap_conf.select_ipv4 = 0;
15457 	else
15458 		return;
15459 	rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15460 	vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15461 	vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15462 	vxlan_encap_conf.ip_tos = res->tos;
15463 	vxlan_encap_conf.ip_ttl = res->ttl;
15464 	if (vxlan_encap_conf.select_ipv4) {
15465 		IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15466 		IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15467 	} else {
15468 		IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15469 		IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15470 	}
15471 	if (vxlan_encap_conf.select_vlan)
15472 		vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15473 	rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15474 		   RTE_ETHER_ADDR_LEN);
15475 	rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15476 		   RTE_ETHER_ADDR_LEN);
15477 }
15478 
15479 cmdline_parse_inst_t cmd_set_vxlan = {
15480 	.f = cmd_set_vxlan_parsed,
15481 	.data = NULL,
15482 	.help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15483 		" <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15484 		" eth-src <eth-src> eth-dst <eth-dst>",
15485 	.tokens = {
15486 		(void *)&cmd_set_vxlan_set,
15487 		(void *)&cmd_set_vxlan_vxlan,
15488 		(void *)&cmd_set_vxlan_ip_version,
15489 		(void *)&cmd_set_vxlan_ip_version_value,
15490 		(void *)&cmd_set_vxlan_vni,
15491 		(void *)&cmd_set_vxlan_vni_value,
15492 		(void *)&cmd_set_vxlan_udp_src,
15493 		(void *)&cmd_set_vxlan_udp_src_value,
15494 		(void *)&cmd_set_vxlan_udp_dst,
15495 		(void *)&cmd_set_vxlan_udp_dst_value,
15496 		(void *)&cmd_set_vxlan_ip_src,
15497 		(void *)&cmd_set_vxlan_ip_src_value,
15498 		(void *)&cmd_set_vxlan_ip_dst,
15499 		(void *)&cmd_set_vxlan_ip_dst_value,
15500 		(void *)&cmd_set_vxlan_eth_src,
15501 		(void *)&cmd_set_vxlan_eth_src_value,
15502 		(void *)&cmd_set_vxlan_eth_dst,
15503 		(void *)&cmd_set_vxlan_eth_dst_value,
15504 		NULL,
15505 	},
15506 };
15507 
15508 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15509 	.f = cmd_set_vxlan_parsed,
15510 	.data = NULL,
15511 	.help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15512 		" <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15513 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15514 		" eth-dst <eth-dst>",
15515 	.tokens = {
15516 		(void *)&cmd_set_vxlan_set,
15517 		(void *)&cmd_set_vxlan_vxlan_tos_ttl,
15518 		(void *)&cmd_set_vxlan_ip_version,
15519 		(void *)&cmd_set_vxlan_ip_version_value,
15520 		(void *)&cmd_set_vxlan_vni,
15521 		(void *)&cmd_set_vxlan_vni_value,
15522 		(void *)&cmd_set_vxlan_udp_src,
15523 		(void *)&cmd_set_vxlan_udp_src_value,
15524 		(void *)&cmd_set_vxlan_udp_dst,
15525 		(void *)&cmd_set_vxlan_udp_dst_value,
15526 		(void *)&cmd_set_vxlan_ip_tos,
15527 		(void *)&cmd_set_vxlan_ip_tos_value,
15528 		(void *)&cmd_set_vxlan_ip_ttl,
15529 		(void *)&cmd_set_vxlan_ip_ttl_value,
15530 		(void *)&cmd_set_vxlan_ip_src,
15531 		(void *)&cmd_set_vxlan_ip_src_value,
15532 		(void *)&cmd_set_vxlan_ip_dst,
15533 		(void *)&cmd_set_vxlan_ip_dst_value,
15534 		(void *)&cmd_set_vxlan_eth_src,
15535 		(void *)&cmd_set_vxlan_eth_src_value,
15536 		(void *)&cmd_set_vxlan_eth_dst,
15537 		(void *)&cmd_set_vxlan_eth_dst_value,
15538 		NULL,
15539 	},
15540 };
15541 
15542 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15543 	.f = cmd_set_vxlan_parsed,
15544 	.data = NULL,
15545 	.help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15546 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15547 		" <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15548 		" <eth-dst>",
15549 	.tokens = {
15550 		(void *)&cmd_set_vxlan_set,
15551 		(void *)&cmd_set_vxlan_vxlan_with_vlan,
15552 		(void *)&cmd_set_vxlan_ip_version,
15553 		(void *)&cmd_set_vxlan_ip_version_value,
15554 		(void *)&cmd_set_vxlan_vni,
15555 		(void *)&cmd_set_vxlan_vni_value,
15556 		(void *)&cmd_set_vxlan_udp_src,
15557 		(void *)&cmd_set_vxlan_udp_src_value,
15558 		(void *)&cmd_set_vxlan_udp_dst,
15559 		(void *)&cmd_set_vxlan_udp_dst_value,
15560 		(void *)&cmd_set_vxlan_ip_src,
15561 		(void *)&cmd_set_vxlan_ip_src_value,
15562 		(void *)&cmd_set_vxlan_ip_dst,
15563 		(void *)&cmd_set_vxlan_ip_dst_value,
15564 		(void *)&cmd_set_vxlan_vlan,
15565 		(void *)&cmd_set_vxlan_vlan_value,
15566 		(void *)&cmd_set_vxlan_eth_src,
15567 		(void *)&cmd_set_vxlan_eth_src_value,
15568 		(void *)&cmd_set_vxlan_eth_dst,
15569 		(void *)&cmd_set_vxlan_eth_dst_value,
15570 		NULL,
15571 	},
15572 };
15573 
15574 /** Set NVGRE encapsulation details */
15575 struct cmd_set_nvgre_result {
15576 	cmdline_fixed_string_t set;
15577 	cmdline_fixed_string_t nvgre;
15578 	cmdline_fixed_string_t pos_token;
15579 	cmdline_fixed_string_t ip_version;
15580 	uint32_t tni;
15581 	cmdline_ipaddr_t ip_src;
15582 	cmdline_ipaddr_t ip_dst;
15583 	uint16_t tci;
15584 	struct rte_ether_addr eth_src;
15585 	struct rte_ether_addr eth_dst;
15586 };
15587 
15588 cmdline_parse_token_string_t cmd_set_nvgre_set =
15589 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15590 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15591 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15592 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15593 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15594 				 "nvgre-with-vlan");
15595 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15596 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15597 				 "ip-version");
15598 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15599 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15600 				 "ipv4#ipv6");
15601 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15602 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15603 				 "tni");
15604 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15605 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15606 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15607 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15608 				 "ip-src");
15609 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15610 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15611 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15612 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15613 				 "ip-dst");
15614 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15615 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15616 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15617 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15618 				 "vlan-tci");
15619 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15620 	TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15621 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15622 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15623 				 "eth-src");
15624 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15625 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15626 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15627 	TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15628 				 "eth-dst");
15629 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15630 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15631 
15632 static void cmd_set_nvgre_parsed(void *parsed_result,
15633 	__attribute__((unused)) struct cmdline *cl,
15634 	__attribute__((unused)) void *data)
15635 {
15636 	struct cmd_set_nvgre_result *res = parsed_result;
15637 	union {
15638 		uint32_t nvgre_tni;
15639 		uint8_t tni[4];
15640 	} id = {
15641 		.nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15642 	};
15643 
15644 	if (strcmp(res->nvgre, "nvgre") == 0)
15645 		nvgre_encap_conf.select_vlan = 0;
15646 	else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15647 		nvgre_encap_conf.select_vlan = 1;
15648 	if (strcmp(res->ip_version, "ipv4") == 0)
15649 		nvgre_encap_conf.select_ipv4 = 1;
15650 	else if (strcmp(res->ip_version, "ipv6") == 0)
15651 		nvgre_encap_conf.select_ipv4 = 0;
15652 	else
15653 		return;
15654 	rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15655 	if (nvgre_encap_conf.select_ipv4) {
15656 		IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15657 		IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15658 	} else {
15659 		IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15660 		IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15661 	}
15662 	if (nvgre_encap_conf.select_vlan)
15663 		nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15664 	rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15665 		   RTE_ETHER_ADDR_LEN);
15666 	rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15667 		   RTE_ETHER_ADDR_LEN);
15668 }
15669 
15670 cmdline_parse_inst_t cmd_set_nvgre = {
15671 	.f = cmd_set_nvgre_parsed,
15672 	.data = NULL,
15673 	.help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15674 		" <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15675 		" eth-dst <eth-dst>",
15676 	.tokens = {
15677 		(void *)&cmd_set_nvgre_set,
15678 		(void *)&cmd_set_nvgre_nvgre,
15679 		(void *)&cmd_set_nvgre_ip_version,
15680 		(void *)&cmd_set_nvgre_ip_version_value,
15681 		(void *)&cmd_set_nvgre_tni,
15682 		(void *)&cmd_set_nvgre_tni_value,
15683 		(void *)&cmd_set_nvgre_ip_src,
15684 		(void *)&cmd_set_nvgre_ip_src_value,
15685 		(void *)&cmd_set_nvgre_ip_dst,
15686 		(void *)&cmd_set_nvgre_ip_dst_value,
15687 		(void *)&cmd_set_nvgre_eth_src,
15688 		(void *)&cmd_set_nvgre_eth_src_value,
15689 		(void *)&cmd_set_nvgre_eth_dst,
15690 		(void *)&cmd_set_nvgre_eth_dst_value,
15691 		NULL,
15692 	},
15693 };
15694 
15695 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15696 	.f = cmd_set_nvgre_parsed,
15697 	.data = NULL,
15698 	.help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15699 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15700 		" eth-src <eth-src> eth-dst <eth-dst>",
15701 	.tokens = {
15702 		(void *)&cmd_set_nvgre_set,
15703 		(void *)&cmd_set_nvgre_nvgre_with_vlan,
15704 		(void *)&cmd_set_nvgre_ip_version,
15705 		(void *)&cmd_set_nvgre_ip_version_value,
15706 		(void *)&cmd_set_nvgre_tni,
15707 		(void *)&cmd_set_nvgre_tni_value,
15708 		(void *)&cmd_set_nvgre_ip_src,
15709 		(void *)&cmd_set_nvgre_ip_src_value,
15710 		(void *)&cmd_set_nvgre_ip_dst,
15711 		(void *)&cmd_set_nvgre_ip_dst_value,
15712 		(void *)&cmd_set_nvgre_vlan,
15713 		(void *)&cmd_set_nvgre_vlan_value,
15714 		(void *)&cmd_set_nvgre_eth_src,
15715 		(void *)&cmd_set_nvgre_eth_src_value,
15716 		(void *)&cmd_set_nvgre_eth_dst,
15717 		(void *)&cmd_set_nvgre_eth_dst_value,
15718 		NULL,
15719 	},
15720 };
15721 
15722 /** Set L2 encapsulation details */
15723 struct cmd_set_l2_encap_result {
15724 	cmdline_fixed_string_t set;
15725 	cmdline_fixed_string_t l2_encap;
15726 	cmdline_fixed_string_t pos_token;
15727 	cmdline_fixed_string_t ip_version;
15728 	uint32_t vlan_present:1;
15729 	uint16_t tci;
15730 	struct rte_ether_addr eth_src;
15731 	struct rte_ether_addr eth_dst;
15732 };
15733 
15734 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15735 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15736 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15737 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15738 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15739 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15740 				 "l2_encap-with-vlan");
15741 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15742 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15743 				 "ip-version");
15744 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15745 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15746 				 "ipv4#ipv6");
15747 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15748 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15749 				 "vlan-tci");
15750 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15751 	TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15752 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15753 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15754 				 "eth-src");
15755 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15756 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15757 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15758 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15759 				 "eth-dst");
15760 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15761 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15762 
15763 static void cmd_set_l2_encap_parsed(void *parsed_result,
15764 	__attribute__((unused)) struct cmdline *cl,
15765 	__attribute__((unused)) void *data)
15766 {
15767 	struct cmd_set_l2_encap_result *res = parsed_result;
15768 
15769 	if (strcmp(res->l2_encap, "l2_encap") == 0)
15770 		l2_encap_conf.select_vlan = 0;
15771 	else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15772 		l2_encap_conf.select_vlan = 1;
15773 	if (strcmp(res->ip_version, "ipv4") == 0)
15774 		l2_encap_conf.select_ipv4 = 1;
15775 	else if (strcmp(res->ip_version, "ipv6") == 0)
15776 		l2_encap_conf.select_ipv4 = 0;
15777 	else
15778 		return;
15779 	if (l2_encap_conf.select_vlan)
15780 		l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15781 	rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15782 		   RTE_ETHER_ADDR_LEN);
15783 	rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15784 		   RTE_ETHER_ADDR_LEN);
15785 }
15786 
15787 cmdline_parse_inst_t cmd_set_l2_encap = {
15788 	.f = cmd_set_l2_encap_parsed,
15789 	.data = NULL,
15790 	.help_str = "set l2_encap ip-version ipv4|ipv6"
15791 		" eth-src <eth-src> eth-dst <eth-dst>",
15792 	.tokens = {
15793 		(void *)&cmd_set_l2_encap_set,
15794 		(void *)&cmd_set_l2_encap_l2_encap,
15795 		(void *)&cmd_set_l2_encap_ip_version,
15796 		(void *)&cmd_set_l2_encap_ip_version_value,
15797 		(void *)&cmd_set_l2_encap_eth_src,
15798 		(void *)&cmd_set_l2_encap_eth_src_value,
15799 		(void *)&cmd_set_l2_encap_eth_dst,
15800 		(void *)&cmd_set_l2_encap_eth_dst_value,
15801 		NULL,
15802 	},
15803 };
15804 
15805 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15806 	.f = cmd_set_l2_encap_parsed,
15807 	.data = NULL,
15808 	.help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15809 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15810 	.tokens = {
15811 		(void *)&cmd_set_l2_encap_set,
15812 		(void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15813 		(void *)&cmd_set_l2_encap_ip_version,
15814 		(void *)&cmd_set_l2_encap_ip_version_value,
15815 		(void *)&cmd_set_l2_encap_vlan,
15816 		(void *)&cmd_set_l2_encap_vlan_value,
15817 		(void *)&cmd_set_l2_encap_eth_src,
15818 		(void *)&cmd_set_l2_encap_eth_src_value,
15819 		(void *)&cmd_set_l2_encap_eth_dst,
15820 		(void *)&cmd_set_l2_encap_eth_dst_value,
15821 		NULL,
15822 	},
15823 };
15824 
15825 /** Set L2 decapsulation details */
15826 struct cmd_set_l2_decap_result {
15827 	cmdline_fixed_string_t set;
15828 	cmdline_fixed_string_t l2_decap;
15829 	cmdline_fixed_string_t pos_token;
15830 	uint32_t vlan_present:1;
15831 };
15832 
15833 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15834 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15835 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15836 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15837 				 "l2_decap");
15838 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15839 	TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15840 				 "l2_decap-with-vlan");
15841 
15842 static void cmd_set_l2_decap_parsed(void *parsed_result,
15843 	__attribute__((unused)) struct cmdline *cl,
15844 	__attribute__((unused)) void *data)
15845 {
15846 	struct cmd_set_l2_decap_result *res = parsed_result;
15847 
15848 	if (strcmp(res->l2_decap, "l2_decap") == 0)
15849 		l2_decap_conf.select_vlan = 0;
15850 	else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15851 		l2_decap_conf.select_vlan = 1;
15852 }
15853 
15854 cmdline_parse_inst_t cmd_set_l2_decap = {
15855 	.f = cmd_set_l2_decap_parsed,
15856 	.data = NULL,
15857 	.help_str = "set l2_decap",
15858 	.tokens = {
15859 		(void *)&cmd_set_l2_decap_set,
15860 		(void *)&cmd_set_l2_decap_l2_decap,
15861 		NULL,
15862 	},
15863 };
15864 
15865 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15866 	.f = cmd_set_l2_decap_parsed,
15867 	.data = NULL,
15868 	.help_str = "set l2_decap-with-vlan",
15869 	.tokens = {
15870 		(void *)&cmd_set_l2_decap_set,
15871 		(void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15872 		NULL,
15873 	},
15874 };
15875 
15876 /** Set MPLSoGRE encapsulation details */
15877 struct cmd_set_mplsogre_encap_result {
15878 	cmdline_fixed_string_t set;
15879 	cmdline_fixed_string_t mplsogre;
15880 	cmdline_fixed_string_t pos_token;
15881 	cmdline_fixed_string_t ip_version;
15882 	uint32_t vlan_present:1;
15883 	uint32_t label;
15884 	cmdline_ipaddr_t ip_src;
15885 	cmdline_ipaddr_t ip_dst;
15886 	uint16_t tci;
15887 	struct rte_ether_addr eth_src;
15888 	struct rte_ether_addr eth_dst;
15889 };
15890 
15891 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15892 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15893 				 "set");
15894 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15895 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15896 				 "mplsogre_encap");
15897 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15898 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15899 				 mplsogre, "mplsogre_encap-with-vlan");
15900 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15901 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15902 				 pos_token, "ip-version");
15903 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15904 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15905 				 ip_version, "ipv4#ipv6");
15906 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15907 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15908 				 pos_token, "label");
15909 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15910 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15911 			      UINT32);
15912 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15913 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15914 				 pos_token, "ip-src");
15915 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15916 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15917 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15918 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15919 				 pos_token, "ip-dst");
15920 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15921 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15922 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15923 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15924 				 pos_token, "vlan-tci");
15925 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15926 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15927 			      UINT16);
15928 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15929 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15930 				 pos_token, "eth-src");
15931 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15932 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15933 				    eth_src);
15934 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15935 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15936 				 pos_token, "eth-dst");
15937 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15938 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15939 				    eth_dst);
15940 
15941 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15942 	__attribute__((unused)) struct cmdline *cl,
15943 	__attribute__((unused)) void *data)
15944 {
15945 	struct cmd_set_mplsogre_encap_result *res = parsed_result;
15946 	union {
15947 		uint32_t mplsogre_label;
15948 		uint8_t label[4];
15949 	} id = {
15950 		.mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15951 	};
15952 
15953 	if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15954 		mplsogre_encap_conf.select_vlan = 0;
15955 	else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15956 		mplsogre_encap_conf.select_vlan = 1;
15957 	if (strcmp(res->ip_version, "ipv4") == 0)
15958 		mplsogre_encap_conf.select_ipv4 = 1;
15959 	else if (strcmp(res->ip_version, "ipv6") == 0)
15960 		mplsogre_encap_conf.select_ipv4 = 0;
15961 	else
15962 		return;
15963 	rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15964 	if (mplsogre_encap_conf.select_ipv4) {
15965 		IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15966 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15967 	} else {
15968 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15969 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15970 	}
15971 	if (mplsogre_encap_conf.select_vlan)
15972 		mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15973 	rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15974 		   RTE_ETHER_ADDR_LEN);
15975 	rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15976 		   RTE_ETHER_ADDR_LEN);
15977 }
15978 
15979 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15980 	.f = cmd_set_mplsogre_encap_parsed,
15981 	.data = NULL,
15982 	.help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15983 		" ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15984 		" eth-dst <eth-dst>",
15985 	.tokens = {
15986 		(void *)&cmd_set_mplsogre_encap_set,
15987 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15988 		(void *)&cmd_set_mplsogre_encap_ip_version,
15989 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
15990 		(void *)&cmd_set_mplsogre_encap_label,
15991 		(void *)&cmd_set_mplsogre_encap_label_value,
15992 		(void *)&cmd_set_mplsogre_encap_ip_src,
15993 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
15994 		(void *)&cmd_set_mplsogre_encap_ip_dst,
15995 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
15996 		(void *)&cmd_set_mplsogre_encap_eth_src,
15997 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
15998 		(void *)&cmd_set_mplsogre_encap_eth_dst,
15999 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
16000 		NULL,
16001 	},
16002 };
16003 
16004 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16005 	.f = cmd_set_mplsogre_encap_parsed,
16006 	.data = NULL,
16007 	.help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16008 		" label <label> ip-src <ip-src> ip-dst <ip-dst>"
16009 		" vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16010 	.tokens = {
16011 		(void *)&cmd_set_mplsogre_encap_set,
16012 		(void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16013 		(void *)&cmd_set_mplsogre_encap_ip_version,
16014 		(void *)&cmd_set_mplsogre_encap_ip_version_value,
16015 		(void *)&cmd_set_mplsogre_encap_label,
16016 		(void *)&cmd_set_mplsogre_encap_label_value,
16017 		(void *)&cmd_set_mplsogre_encap_ip_src,
16018 		(void *)&cmd_set_mplsogre_encap_ip_src_value,
16019 		(void *)&cmd_set_mplsogre_encap_ip_dst,
16020 		(void *)&cmd_set_mplsogre_encap_ip_dst_value,
16021 		(void *)&cmd_set_mplsogre_encap_vlan,
16022 		(void *)&cmd_set_mplsogre_encap_vlan_value,
16023 		(void *)&cmd_set_mplsogre_encap_eth_src,
16024 		(void *)&cmd_set_mplsogre_encap_eth_src_value,
16025 		(void *)&cmd_set_mplsogre_encap_eth_dst,
16026 		(void *)&cmd_set_mplsogre_encap_eth_dst_value,
16027 		NULL,
16028 	},
16029 };
16030 
16031 /** Set MPLSoGRE decapsulation details */
16032 struct cmd_set_mplsogre_decap_result {
16033 	cmdline_fixed_string_t set;
16034 	cmdline_fixed_string_t mplsogre;
16035 	cmdline_fixed_string_t pos_token;
16036 	cmdline_fixed_string_t ip_version;
16037 	uint32_t vlan_present:1;
16038 };
16039 
16040 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16041 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16042 				 "set");
16043 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16044 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16045 				 "mplsogre_decap");
16046 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16047 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16048 				 mplsogre, "mplsogre_decap-with-vlan");
16049 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16050 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16051 				 pos_token, "ip-version");
16052 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16053 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16054 				 ip_version, "ipv4#ipv6");
16055 
16056 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16057 	__attribute__((unused)) struct cmdline *cl,
16058 	__attribute__((unused)) void *data)
16059 {
16060 	struct cmd_set_mplsogre_decap_result *res = parsed_result;
16061 
16062 	if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16063 		mplsogre_decap_conf.select_vlan = 0;
16064 	else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16065 		mplsogre_decap_conf.select_vlan = 1;
16066 	if (strcmp(res->ip_version, "ipv4") == 0)
16067 		mplsogre_decap_conf.select_ipv4 = 1;
16068 	else if (strcmp(res->ip_version, "ipv6") == 0)
16069 		mplsogre_decap_conf.select_ipv4 = 0;
16070 }
16071 
16072 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16073 	.f = cmd_set_mplsogre_decap_parsed,
16074 	.data = NULL,
16075 	.help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16076 	.tokens = {
16077 		(void *)&cmd_set_mplsogre_decap_set,
16078 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16079 		(void *)&cmd_set_mplsogre_decap_ip_version,
16080 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
16081 		NULL,
16082 	},
16083 };
16084 
16085 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16086 	.f = cmd_set_mplsogre_decap_parsed,
16087 	.data = NULL,
16088 	.help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16089 	.tokens = {
16090 		(void *)&cmd_set_mplsogre_decap_set,
16091 		(void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16092 		(void *)&cmd_set_mplsogre_decap_ip_version,
16093 		(void *)&cmd_set_mplsogre_decap_ip_version_value,
16094 		NULL,
16095 	},
16096 };
16097 
16098 /** Set MPLSoUDP encapsulation details */
16099 struct cmd_set_mplsoudp_encap_result {
16100 	cmdline_fixed_string_t set;
16101 	cmdline_fixed_string_t mplsoudp;
16102 	cmdline_fixed_string_t pos_token;
16103 	cmdline_fixed_string_t ip_version;
16104 	uint32_t vlan_present:1;
16105 	uint32_t label;
16106 	uint16_t udp_src;
16107 	uint16_t udp_dst;
16108 	cmdline_ipaddr_t ip_src;
16109 	cmdline_ipaddr_t ip_dst;
16110 	uint16_t tci;
16111 	struct rte_ether_addr eth_src;
16112 	struct rte_ether_addr eth_dst;
16113 };
16114 
16115 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16116 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16117 				 "set");
16118 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16119 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16120 				 "mplsoudp_encap");
16121 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16122 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16123 				 mplsoudp, "mplsoudp_encap-with-vlan");
16124 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16125 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16126 				 pos_token, "ip-version");
16127 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16128 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16129 				 ip_version, "ipv4#ipv6");
16130 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16131 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16132 				 pos_token, "label");
16133 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16134 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16135 			      UINT32);
16136 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16137 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16138 				 pos_token, "udp-src");
16139 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16140 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16141 			      UINT16);
16142 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16143 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16144 				 pos_token, "udp-dst");
16145 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16146 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16147 			      UINT16);
16148 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16149 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16150 				 pos_token, "ip-src");
16151 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16152 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16153 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16154 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16155 				 pos_token, "ip-dst");
16156 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16157 	TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16158 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16159 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16160 				 pos_token, "vlan-tci");
16161 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16162 	TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16163 			      UINT16);
16164 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16165 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16166 				 pos_token, "eth-src");
16167 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16168 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16169 				    eth_src);
16170 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16171 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16172 				 pos_token, "eth-dst");
16173 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16174 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16175 				    eth_dst);
16176 
16177 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16178 	__attribute__((unused)) struct cmdline *cl,
16179 	__attribute__((unused)) void *data)
16180 {
16181 	struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16182 	union {
16183 		uint32_t mplsoudp_label;
16184 		uint8_t label[4];
16185 	} id = {
16186 		.mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16187 	};
16188 
16189 	if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16190 		mplsoudp_encap_conf.select_vlan = 0;
16191 	else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16192 		mplsoudp_encap_conf.select_vlan = 1;
16193 	if (strcmp(res->ip_version, "ipv4") == 0)
16194 		mplsoudp_encap_conf.select_ipv4 = 1;
16195 	else if (strcmp(res->ip_version, "ipv6") == 0)
16196 		mplsoudp_encap_conf.select_ipv4 = 0;
16197 	else
16198 		return;
16199 	rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16200 	mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16201 	mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16202 	if (mplsoudp_encap_conf.select_ipv4) {
16203 		IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16204 		IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16205 	} else {
16206 		IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16207 		IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16208 	}
16209 	if (mplsoudp_encap_conf.select_vlan)
16210 		mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16211 	rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16212 		   RTE_ETHER_ADDR_LEN);
16213 	rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16214 		   RTE_ETHER_ADDR_LEN);
16215 }
16216 
16217 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16218 	.f = cmd_set_mplsoudp_encap_parsed,
16219 	.data = NULL,
16220 	.help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16221 		" udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16222 		" ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16223 	.tokens = {
16224 		(void *)&cmd_set_mplsoudp_encap_set,
16225 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16226 		(void *)&cmd_set_mplsoudp_encap_ip_version,
16227 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
16228 		(void *)&cmd_set_mplsoudp_encap_label,
16229 		(void *)&cmd_set_mplsoudp_encap_label_value,
16230 		(void *)&cmd_set_mplsoudp_encap_udp_src,
16231 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
16232 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
16233 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16234 		(void *)&cmd_set_mplsoudp_encap_ip_src,
16235 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
16236 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
16237 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16238 		(void *)&cmd_set_mplsoudp_encap_eth_src,
16239 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
16240 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
16241 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16242 		NULL,
16243 	},
16244 };
16245 
16246 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16247 	.f = cmd_set_mplsoudp_encap_parsed,
16248 	.data = NULL,
16249 	.help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16250 		" label <label> udp-src <udp-src> udp-dst <udp-dst>"
16251 		" ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16252 		" eth-src <eth-src> eth-dst <eth-dst>",
16253 	.tokens = {
16254 		(void *)&cmd_set_mplsoudp_encap_set,
16255 		(void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16256 		(void *)&cmd_set_mplsoudp_encap_ip_version,
16257 		(void *)&cmd_set_mplsoudp_encap_ip_version_value,
16258 		(void *)&cmd_set_mplsoudp_encap_label,
16259 		(void *)&cmd_set_mplsoudp_encap_label_value,
16260 		(void *)&cmd_set_mplsoudp_encap_udp_src,
16261 		(void *)&cmd_set_mplsoudp_encap_udp_src_value,
16262 		(void *)&cmd_set_mplsoudp_encap_udp_dst,
16263 		(void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16264 		(void *)&cmd_set_mplsoudp_encap_ip_src,
16265 		(void *)&cmd_set_mplsoudp_encap_ip_src_value,
16266 		(void *)&cmd_set_mplsoudp_encap_ip_dst,
16267 		(void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16268 		(void *)&cmd_set_mplsoudp_encap_vlan,
16269 		(void *)&cmd_set_mplsoudp_encap_vlan_value,
16270 		(void *)&cmd_set_mplsoudp_encap_eth_src,
16271 		(void *)&cmd_set_mplsoudp_encap_eth_src_value,
16272 		(void *)&cmd_set_mplsoudp_encap_eth_dst,
16273 		(void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16274 		NULL,
16275 	},
16276 };
16277 
16278 /** Set MPLSoUDP decapsulation details */
16279 struct cmd_set_mplsoudp_decap_result {
16280 	cmdline_fixed_string_t set;
16281 	cmdline_fixed_string_t mplsoudp;
16282 	cmdline_fixed_string_t pos_token;
16283 	cmdline_fixed_string_t ip_version;
16284 	uint32_t vlan_present:1;
16285 };
16286 
16287 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16288 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16289 				 "set");
16290 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16291 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16292 				 "mplsoudp_decap");
16293 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16294 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16295 				 mplsoudp, "mplsoudp_decap-with-vlan");
16296 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16297 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16298 				 pos_token, "ip-version");
16299 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16300 	TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16301 				 ip_version, "ipv4#ipv6");
16302 
16303 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16304 	__attribute__((unused)) struct cmdline *cl,
16305 	__attribute__((unused)) void *data)
16306 {
16307 	struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16308 
16309 	if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16310 		mplsoudp_decap_conf.select_vlan = 0;
16311 	else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16312 		mplsoudp_decap_conf.select_vlan = 1;
16313 	if (strcmp(res->ip_version, "ipv4") == 0)
16314 		mplsoudp_decap_conf.select_ipv4 = 1;
16315 	else if (strcmp(res->ip_version, "ipv6") == 0)
16316 		mplsoudp_decap_conf.select_ipv4 = 0;
16317 }
16318 
16319 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16320 	.f = cmd_set_mplsoudp_decap_parsed,
16321 	.data = NULL,
16322 	.help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16323 	.tokens = {
16324 		(void *)&cmd_set_mplsoudp_decap_set,
16325 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16326 		(void *)&cmd_set_mplsoudp_decap_ip_version,
16327 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
16328 		NULL,
16329 	},
16330 };
16331 
16332 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16333 	.f = cmd_set_mplsoudp_decap_parsed,
16334 	.data = NULL,
16335 	.help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16336 	.tokens = {
16337 		(void *)&cmd_set_mplsoudp_decap_set,
16338 		(void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16339 		(void *)&cmd_set_mplsoudp_decap_ip_version,
16340 		(void *)&cmd_set_mplsoudp_decap_ip_version_value,
16341 		NULL,
16342 	},
16343 };
16344 
16345 /* Strict link priority scheduling mode setting */
16346 static void
16347 cmd_strict_link_prio_parsed(
16348 	void *parsed_result,
16349 	__attribute__((unused)) struct cmdline *cl,
16350 	__attribute__((unused)) void *data)
16351 {
16352 	struct cmd_vf_tc_bw_result *res = parsed_result;
16353 	int ret = -ENOTSUP;
16354 
16355 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16356 		return;
16357 
16358 #ifdef RTE_LIBRTE_I40E_PMD
16359 	ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16360 #endif
16361 
16362 	switch (ret) {
16363 	case 0:
16364 		break;
16365 	case -EINVAL:
16366 		printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16367 		break;
16368 	case -ENODEV:
16369 		printf("invalid port_id %d\n", res->port_id);
16370 		break;
16371 	case -ENOTSUP:
16372 		printf("function not implemented\n");
16373 		break;
16374 	default:
16375 		printf("programming error: (%s)\n", strerror(-ret));
16376 	}
16377 }
16378 
16379 cmdline_parse_inst_t cmd_strict_link_prio = {
16380 	.f = cmd_strict_link_prio_parsed,
16381 	.data = NULL,
16382 	.help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16383 	.tokens = {
16384 		(void *)&cmd_vf_tc_bw_set,
16385 		(void *)&cmd_vf_tc_bw_tx,
16386 		(void *)&cmd_vf_tc_bw_strict_link_prio,
16387 		(void *)&cmd_vf_tc_bw_port_id,
16388 		(void *)&cmd_vf_tc_bw_tc_map,
16389 		NULL,
16390 	},
16391 };
16392 
16393 /* Load dynamic device personalization*/
16394 struct cmd_ddp_add_result {
16395 	cmdline_fixed_string_t ddp;
16396 	cmdline_fixed_string_t add;
16397 	portid_t port_id;
16398 	char filepath[];
16399 };
16400 
16401 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16402 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16403 cmdline_parse_token_string_t cmd_ddp_add_add =
16404 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16405 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16406 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16407 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16408 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16409 
16410 static void
16411 cmd_ddp_add_parsed(
16412 	void *parsed_result,
16413 	__attribute__((unused)) struct cmdline *cl,
16414 	__attribute__((unused)) void *data)
16415 {
16416 	struct cmd_ddp_add_result *res = parsed_result;
16417 	uint8_t *buff;
16418 	uint32_t size;
16419 	char *filepath;
16420 	char *file_fld[2];
16421 	int file_num;
16422 	int ret = -ENOTSUP;
16423 
16424 	if (!all_ports_stopped()) {
16425 		printf("Please stop all ports first\n");
16426 		return;
16427 	}
16428 
16429 	filepath = strdup(res->filepath);
16430 	if (filepath == NULL) {
16431 		printf("Failed to allocate memory\n");
16432 		return;
16433 	}
16434 	file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16435 
16436 	buff = open_file(file_fld[0], &size);
16437 	if (!buff) {
16438 		free((void *)filepath);
16439 		return;
16440 	}
16441 
16442 #ifdef RTE_LIBRTE_I40E_PMD
16443 	if (ret == -ENOTSUP)
16444 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16445 					       buff, size,
16446 					       RTE_PMD_I40E_PKG_OP_WR_ADD);
16447 #endif
16448 
16449 	if (ret == -EEXIST)
16450 		printf("Profile has already existed.\n");
16451 	else if (ret < 0)
16452 		printf("Failed to load profile.\n");
16453 	else if (file_num == 2)
16454 		save_file(file_fld[1], buff, size);
16455 
16456 	close_file(buff);
16457 	free((void *)filepath);
16458 }
16459 
16460 cmdline_parse_inst_t cmd_ddp_add = {
16461 	.f = cmd_ddp_add_parsed,
16462 	.data = NULL,
16463 	.help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16464 	.tokens = {
16465 		(void *)&cmd_ddp_add_ddp,
16466 		(void *)&cmd_ddp_add_add,
16467 		(void *)&cmd_ddp_add_port_id,
16468 		(void *)&cmd_ddp_add_filepath,
16469 		NULL,
16470 	},
16471 };
16472 
16473 /* Delete dynamic device personalization*/
16474 struct cmd_ddp_del_result {
16475 	cmdline_fixed_string_t ddp;
16476 	cmdline_fixed_string_t del;
16477 	portid_t port_id;
16478 	char filepath[];
16479 };
16480 
16481 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16482 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16483 cmdline_parse_token_string_t cmd_ddp_del_del =
16484 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16485 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16486 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16487 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16488 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16489 
16490 static void
16491 cmd_ddp_del_parsed(
16492 	void *parsed_result,
16493 	__attribute__((unused)) struct cmdline *cl,
16494 	__attribute__((unused)) void *data)
16495 {
16496 	struct cmd_ddp_del_result *res = parsed_result;
16497 	uint8_t *buff;
16498 	uint32_t size;
16499 	int ret = -ENOTSUP;
16500 
16501 	if (!all_ports_stopped()) {
16502 		printf("Please stop all ports first\n");
16503 		return;
16504 	}
16505 
16506 	buff = open_file(res->filepath, &size);
16507 	if (!buff)
16508 		return;
16509 
16510 #ifdef RTE_LIBRTE_I40E_PMD
16511 	if (ret == -ENOTSUP)
16512 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16513 					       buff, size,
16514 					       RTE_PMD_I40E_PKG_OP_WR_DEL);
16515 #endif
16516 
16517 	if (ret == -EACCES)
16518 		printf("Profile does not exist.\n");
16519 	else if (ret < 0)
16520 		printf("Failed to delete profile.\n");
16521 
16522 	close_file(buff);
16523 }
16524 
16525 cmdline_parse_inst_t cmd_ddp_del = {
16526 	.f = cmd_ddp_del_parsed,
16527 	.data = NULL,
16528 	.help_str = "ddp del <port_id> <backup_profile_path>",
16529 	.tokens = {
16530 		(void *)&cmd_ddp_del_ddp,
16531 		(void *)&cmd_ddp_del_del,
16532 		(void *)&cmd_ddp_del_port_id,
16533 		(void *)&cmd_ddp_del_filepath,
16534 		NULL,
16535 	},
16536 };
16537 
16538 /* Get dynamic device personalization profile info */
16539 struct cmd_ddp_info_result {
16540 	cmdline_fixed_string_t ddp;
16541 	cmdline_fixed_string_t get;
16542 	cmdline_fixed_string_t info;
16543 	char filepath[];
16544 };
16545 
16546 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16547 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16548 cmdline_parse_token_string_t cmd_ddp_info_get =
16549 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16550 cmdline_parse_token_string_t cmd_ddp_info_info =
16551 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16552 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16553 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16554 
16555 static void
16556 cmd_ddp_info_parsed(
16557 	void *parsed_result,
16558 	__attribute__((unused)) struct cmdline *cl,
16559 	__attribute__((unused)) void *data)
16560 {
16561 	struct cmd_ddp_info_result *res = parsed_result;
16562 	uint8_t *pkg;
16563 	uint32_t pkg_size;
16564 	int ret = -ENOTSUP;
16565 #ifdef RTE_LIBRTE_I40E_PMD
16566 	uint32_t i, j, n;
16567 	uint8_t *buff;
16568 	uint32_t buff_size = 0;
16569 	struct rte_pmd_i40e_profile_info info;
16570 	uint32_t dev_num = 0;
16571 	struct rte_pmd_i40e_ddp_device_id *devs;
16572 	uint32_t proto_num = 0;
16573 	struct rte_pmd_i40e_proto_info *proto = NULL;
16574 	uint32_t pctype_num = 0;
16575 	struct rte_pmd_i40e_ptype_info *pctype;
16576 	uint32_t ptype_num = 0;
16577 	struct rte_pmd_i40e_ptype_info *ptype;
16578 	uint8_t proto_id;
16579 
16580 #endif
16581 
16582 	pkg = open_file(res->filepath, &pkg_size);
16583 	if (!pkg)
16584 		return;
16585 
16586 #ifdef RTE_LIBRTE_I40E_PMD
16587 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16588 				(uint8_t *)&info, sizeof(info),
16589 				RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16590 	if (!ret) {
16591 		printf("Global Track id:       0x%x\n", info.track_id);
16592 		printf("Global Version:        %d.%d.%d.%d\n",
16593 			info.version.major,
16594 			info.version.minor,
16595 			info.version.update,
16596 			info.version.draft);
16597 		printf("Global Package name:   %s\n\n", info.name);
16598 	}
16599 
16600 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16601 				(uint8_t *)&info, sizeof(info),
16602 				RTE_PMD_I40E_PKG_INFO_HEADER);
16603 	if (!ret) {
16604 		printf("i40e Profile Track id: 0x%x\n", info.track_id);
16605 		printf("i40e Profile Version:  %d.%d.%d.%d\n",
16606 			info.version.major,
16607 			info.version.minor,
16608 			info.version.update,
16609 			info.version.draft);
16610 		printf("i40e Profile name:     %s\n\n", info.name);
16611 	}
16612 
16613 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16614 				(uint8_t *)&buff_size, sizeof(buff_size),
16615 				RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16616 	if (!ret && buff_size) {
16617 		buff = (uint8_t *)malloc(buff_size);
16618 		if (buff) {
16619 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16620 						buff, buff_size,
16621 						RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16622 			if (!ret)
16623 				printf("Package Notes:\n%s\n\n", buff);
16624 			free(buff);
16625 		}
16626 	}
16627 
16628 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16629 				(uint8_t *)&dev_num, sizeof(dev_num),
16630 				RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16631 	if (!ret && dev_num) {
16632 		buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16633 		devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16634 		if (devs) {
16635 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16636 						(uint8_t *)devs, buff_size,
16637 						RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16638 			if (!ret) {
16639 				printf("List of supported devices:\n");
16640 				for (i = 0; i < dev_num; i++) {
16641 					printf("  %04X:%04X %04X:%04X\n",
16642 						devs[i].vendor_dev_id >> 16,
16643 						devs[i].vendor_dev_id & 0xFFFF,
16644 						devs[i].sub_vendor_dev_id >> 16,
16645 						devs[i].sub_vendor_dev_id & 0xFFFF);
16646 				}
16647 				printf("\n");
16648 			}
16649 			free(devs);
16650 		}
16651 	}
16652 
16653 	/* get information about protocols and packet types */
16654 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16655 		(uint8_t *)&proto_num, sizeof(proto_num),
16656 		RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16657 	if (ret || !proto_num)
16658 		goto no_print_return;
16659 
16660 	buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16661 	proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16662 	if (!proto)
16663 		goto no_print_return;
16664 
16665 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16666 					buff_size,
16667 					RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16668 	if (!ret) {
16669 		printf("List of used protocols:\n");
16670 		for (i = 0; i < proto_num; i++)
16671 			printf("  %2u: %s\n", proto[i].proto_id,
16672 			       proto[i].name);
16673 		printf("\n");
16674 	}
16675 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16676 		(uint8_t *)&pctype_num, sizeof(pctype_num),
16677 		RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16678 	if (ret || !pctype_num)
16679 		goto no_print_pctypes;
16680 
16681 	buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16682 	pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16683 	if (!pctype)
16684 		goto no_print_pctypes;
16685 
16686 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16687 					buff_size,
16688 					RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16689 	if (ret) {
16690 		free(pctype);
16691 		goto no_print_pctypes;
16692 	}
16693 
16694 	printf("List of defined packet classification types:\n");
16695 	for (i = 0; i < pctype_num; i++) {
16696 		printf("  %2u:", pctype[i].ptype_id);
16697 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16698 			proto_id = pctype[i].protocols[j];
16699 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16700 				for (n = 0; n < proto_num; n++) {
16701 					if (proto[n].proto_id == proto_id) {
16702 						printf(" %s", proto[n].name);
16703 						break;
16704 					}
16705 				}
16706 			}
16707 		}
16708 		printf("\n");
16709 	}
16710 	printf("\n");
16711 	free(pctype);
16712 
16713 no_print_pctypes:
16714 
16715 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16716 					sizeof(ptype_num),
16717 					RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16718 	if (ret || !ptype_num)
16719 		goto no_print_return;
16720 
16721 	buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16722 	ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16723 	if (!ptype)
16724 		goto no_print_return;
16725 
16726 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16727 					buff_size,
16728 					RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16729 	if (ret) {
16730 		free(ptype);
16731 		goto no_print_return;
16732 	}
16733 	printf("List of defined packet types:\n");
16734 	for (i = 0; i < ptype_num; i++) {
16735 		printf("  %2u:", ptype[i].ptype_id);
16736 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16737 			proto_id = ptype[i].protocols[j];
16738 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16739 				for (n = 0; n < proto_num; n++) {
16740 					if (proto[n].proto_id == proto_id) {
16741 						printf(" %s", proto[n].name);
16742 						break;
16743 					}
16744 				}
16745 			}
16746 		}
16747 		printf("\n");
16748 	}
16749 	free(ptype);
16750 	printf("\n");
16751 
16752 	ret = 0;
16753 no_print_return:
16754 	if (proto)
16755 		free(proto);
16756 #endif
16757 	if (ret == -ENOTSUP)
16758 		printf("Function not supported in PMD driver\n");
16759 	close_file(pkg);
16760 }
16761 
16762 cmdline_parse_inst_t cmd_ddp_get_info = {
16763 	.f = cmd_ddp_info_parsed,
16764 	.data = NULL,
16765 	.help_str = "ddp get info <profile_path>",
16766 	.tokens = {
16767 		(void *)&cmd_ddp_info_ddp,
16768 		(void *)&cmd_ddp_info_get,
16769 		(void *)&cmd_ddp_info_info,
16770 		(void *)&cmd_ddp_info_filepath,
16771 		NULL,
16772 	},
16773 };
16774 
16775 /* Get dynamic device personalization profile info list*/
16776 #define PROFILE_INFO_SIZE 48
16777 #define MAX_PROFILE_NUM 16
16778 
16779 struct cmd_ddp_get_list_result {
16780 	cmdline_fixed_string_t ddp;
16781 	cmdline_fixed_string_t get;
16782 	cmdline_fixed_string_t list;
16783 	portid_t port_id;
16784 };
16785 
16786 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16787 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16788 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16789 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16790 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16791 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16792 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16793 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16794 
16795 static void
16796 cmd_ddp_get_list_parsed(
16797 	__attribute__((unused)) void *parsed_result,
16798 	__attribute__((unused)) struct cmdline *cl,
16799 	__attribute__((unused)) void *data)
16800 {
16801 #ifdef RTE_LIBRTE_I40E_PMD
16802 	struct cmd_ddp_get_list_result *res = parsed_result;
16803 	struct rte_pmd_i40e_profile_list *p_list;
16804 	struct rte_pmd_i40e_profile_info *p_info;
16805 	uint32_t p_num;
16806 	uint32_t size;
16807 	uint32_t i;
16808 #endif
16809 	int ret = -ENOTSUP;
16810 
16811 #ifdef RTE_LIBRTE_I40E_PMD
16812 	size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16813 	p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16814 	if (!p_list)
16815 		printf("%s: Failed to malloc buffer\n", __func__);
16816 
16817 	if (ret == -ENOTSUP)
16818 		ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16819 						(uint8_t *)p_list, size);
16820 
16821 	if (!ret) {
16822 		p_num = p_list->p_count;
16823 		printf("Profile number is: %d\n\n", p_num);
16824 
16825 		for (i = 0; i < p_num; i++) {
16826 			p_info = &p_list->p_info[i];
16827 			printf("Profile %d:\n", i);
16828 			printf("Track id:     0x%x\n", p_info->track_id);
16829 			printf("Version:      %d.%d.%d.%d\n",
16830 			       p_info->version.major,
16831 			       p_info->version.minor,
16832 			       p_info->version.update,
16833 			       p_info->version.draft);
16834 			printf("Profile name: %s\n\n", p_info->name);
16835 		}
16836 	}
16837 
16838 	free(p_list);
16839 #endif
16840 
16841 	if (ret < 0)
16842 		printf("Failed to get ddp list\n");
16843 }
16844 
16845 cmdline_parse_inst_t cmd_ddp_get_list = {
16846 	.f = cmd_ddp_get_list_parsed,
16847 	.data = NULL,
16848 	.help_str = "ddp get list <port_id>",
16849 	.tokens = {
16850 		(void *)&cmd_ddp_get_list_ddp,
16851 		(void *)&cmd_ddp_get_list_get,
16852 		(void *)&cmd_ddp_get_list_list,
16853 		(void *)&cmd_ddp_get_list_port_id,
16854 		NULL,
16855 	},
16856 };
16857 
16858 /* Configure input set */
16859 struct cmd_cfg_input_set_result {
16860 	cmdline_fixed_string_t port;
16861 	cmdline_fixed_string_t cfg;
16862 	portid_t port_id;
16863 	cmdline_fixed_string_t pctype;
16864 	uint8_t pctype_id;
16865 	cmdline_fixed_string_t inset_type;
16866 	cmdline_fixed_string_t opt;
16867 	cmdline_fixed_string_t field;
16868 	uint8_t field_idx;
16869 };
16870 
16871 static void
16872 cmd_cfg_input_set_parsed(
16873 	__attribute__((unused)) void *parsed_result,
16874 	__attribute__((unused)) struct cmdline *cl,
16875 	__attribute__((unused)) void *data)
16876 {
16877 #ifdef RTE_LIBRTE_I40E_PMD
16878 	struct cmd_cfg_input_set_result *res = parsed_result;
16879 	enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16880 	struct rte_pmd_i40e_inset inset;
16881 #endif
16882 	int ret = -ENOTSUP;
16883 
16884 	if (!all_ports_stopped()) {
16885 		printf("Please stop all ports first\n");
16886 		return;
16887 	}
16888 
16889 #ifdef RTE_LIBRTE_I40E_PMD
16890 	if (!strcmp(res->inset_type, "hash_inset"))
16891 		inset_type = INSET_HASH;
16892 	else if (!strcmp(res->inset_type, "fdir_inset"))
16893 		inset_type = INSET_FDIR;
16894 	else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16895 		inset_type = INSET_FDIR_FLX;
16896 	ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16897 				     &inset, inset_type);
16898 	if (ret) {
16899 		printf("Failed to get input set.\n");
16900 		return;
16901 	}
16902 
16903 	if (!strcmp(res->opt, "get")) {
16904 		ret = rte_pmd_i40e_inset_field_get(inset.inset,
16905 						   res->field_idx);
16906 		if (ret)
16907 			printf("Field index %d is enabled.\n", res->field_idx);
16908 		else
16909 			printf("Field index %d is disabled.\n", res->field_idx);
16910 		return;
16911 	} else if (!strcmp(res->opt, "set"))
16912 		ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16913 						   res->field_idx);
16914 	else if (!strcmp(res->opt, "clear"))
16915 		ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16916 						     res->field_idx);
16917 	if (ret) {
16918 		printf("Failed to configure input set field.\n");
16919 		return;
16920 	}
16921 
16922 	ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16923 				     &inset, inset_type);
16924 	if (ret) {
16925 		printf("Failed to set input set.\n");
16926 		return;
16927 	}
16928 #endif
16929 
16930 	if (ret == -ENOTSUP)
16931 		printf("Function not supported\n");
16932 }
16933 
16934 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16935 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16936 				 port, "port");
16937 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16938 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16939 				 cfg, "config");
16940 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16941 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16942 			      port_id, UINT16);
16943 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16944 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16945 				 pctype, "pctype");
16946 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16947 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16948 			      pctype_id, UINT8);
16949 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16950 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16951 				 inset_type,
16952 				 "hash_inset#fdir_inset#fdir_flx_inset");
16953 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16954 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16955 				 opt, "get#set#clear");
16956 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16957 	TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16958 				 field, "field");
16959 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16960 	TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16961 			      field_idx, UINT8);
16962 
16963 cmdline_parse_inst_t cmd_cfg_input_set = {
16964 	.f = cmd_cfg_input_set_parsed,
16965 	.data = NULL,
16966 	.help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16967 		    "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16968 	.tokens = {
16969 		(void *)&cmd_cfg_input_set_port,
16970 		(void *)&cmd_cfg_input_set_cfg,
16971 		(void *)&cmd_cfg_input_set_port_id,
16972 		(void *)&cmd_cfg_input_set_pctype,
16973 		(void *)&cmd_cfg_input_set_pctype_id,
16974 		(void *)&cmd_cfg_input_set_inset_type,
16975 		(void *)&cmd_cfg_input_set_opt,
16976 		(void *)&cmd_cfg_input_set_field,
16977 		(void *)&cmd_cfg_input_set_field_idx,
16978 		NULL,
16979 	},
16980 };
16981 
16982 /* Clear input set */
16983 struct cmd_clear_input_set_result {
16984 	cmdline_fixed_string_t port;
16985 	cmdline_fixed_string_t cfg;
16986 	portid_t port_id;
16987 	cmdline_fixed_string_t pctype;
16988 	uint8_t pctype_id;
16989 	cmdline_fixed_string_t inset_type;
16990 	cmdline_fixed_string_t clear;
16991 	cmdline_fixed_string_t all;
16992 };
16993 
16994 static void
16995 cmd_clear_input_set_parsed(
16996 	__attribute__((unused)) void *parsed_result,
16997 	__attribute__((unused)) struct cmdline *cl,
16998 	__attribute__((unused)) void *data)
16999 {
17000 #ifdef RTE_LIBRTE_I40E_PMD
17001 	struct cmd_clear_input_set_result *res = parsed_result;
17002 	enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17003 	struct rte_pmd_i40e_inset inset;
17004 #endif
17005 	int ret = -ENOTSUP;
17006 
17007 	if (!all_ports_stopped()) {
17008 		printf("Please stop all ports first\n");
17009 		return;
17010 	}
17011 
17012 #ifdef RTE_LIBRTE_I40E_PMD
17013 	if (!strcmp(res->inset_type, "hash_inset"))
17014 		inset_type = INSET_HASH;
17015 	else if (!strcmp(res->inset_type, "fdir_inset"))
17016 		inset_type = INSET_FDIR;
17017 	else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17018 		inset_type = INSET_FDIR_FLX;
17019 
17020 	memset(&inset, 0, sizeof(inset));
17021 
17022 	ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17023 				     &inset, inset_type);
17024 	if (ret) {
17025 		printf("Failed to clear input set.\n");
17026 		return;
17027 	}
17028 
17029 #endif
17030 
17031 	if (ret == -ENOTSUP)
17032 		printf("Function not supported\n");
17033 }
17034 
17035 cmdline_parse_token_string_t cmd_clear_input_set_port =
17036 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17037 				 port, "port");
17038 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17039 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17040 				 cfg, "config");
17041 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17042 	TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17043 			      port_id, UINT16);
17044 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17045 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17046 				 pctype, "pctype");
17047 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17048 	TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17049 			      pctype_id, UINT8);
17050 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17051 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17052 				 inset_type,
17053 				 "hash_inset#fdir_inset#fdir_flx_inset");
17054 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17055 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17056 				 clear, "clear");
17057 cmdline_parse_token_string_t cmd_clear_input_set_all =
17058 	TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17059 				 all, "all");
17060 
17061 cmdline_parse_inst_t cmd_clear_input_set = {
17062 	.f = cmd_clear_input_set_parsed,
17063 	.data = NULL,
17064 	.help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17065 		    "fdir_inset|fdir_flx_inset clear all",
17066 	.tokens = {
17067 		(void *)&cmd_clear_input_set_port,
17068 		(void *)&cmd_clear_input_set_cfg,
17069 		(void *)&cmd_clear_input_set_port_id,
17070 		(void *)&cmd_clear_input_set_pctype,
17071 		(void *)&cmd_clear_input_set_pctype_id,
17072 		(void *)&cmd_clear_input_set_inset_type,
17073 		(void *)&cmd_clear_input_set_clear,
17074 		(void *)&cmd_clear_input_set_all,
17075 		NULL,
17076 	},
17077 };
17078 
17079 /* show vf stats */
17080 
17081 /* Common result structure for show vf stats */
17082 struct cmd_show_vf_stats_result {
17083 	cmdline_fixed_string_t show;
17084 	cmdline_fixed_string_t vf;
17085 	cmdline_fixed_string_t stats;
17086 	portid_t port_id;
17087 	uint16_t vf_id;
17088 };
17089 
17090 /* Common CLI fields show vf stats*/
17091 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17092 	TOKEN_STRING_INITIALIZER
17093 		(struct cmd_show_vf_stats_result,
17094 		 show, "show");
17095 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17096 	TOKEN_STRING_INITIALIZER
17097 		(struct cmd_show_vf_stats_result,
17098 		 vf, "vf");
17099 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17100 	TOKEN_STRING_INITIALIZER
17101 		(struct cmd_show_vf_stats_result,
17102 		 stats, "stats");
17103 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17104 	TOKEN_NUM_INITIALIZER
17105 		(struct cmd_show_vf_stats_result,
17106 		 port_id, UINT16);
17107 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17108 	TOKEN_NUM_INITIALIZER
17109 		(struct cmd_show_vf_stats_result,
17110 		 vf_id, UINT16);
17111 
17112 static void
17113 cmd_show_vf_stats_parsed(
17114 	void *parsed_result,
17115 	__attribute__((unused)) struct cmdline *cl,
17116 	__attribute__((unused)) void *data)
17117 {
17118 	struct cmd_show_vf_stats_result *res = parsed_result;
17119 	struct rte_eth_stats stats;
17120 	int ret = -ENOTSUP;
17121 	static const char *nic_stats_border = "########################";
17122 
17123 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17124 		return;
17125 
17126 	memset(&stats, 0, sizeof(stats));
17127 
17128 #ifdef RTE_LIBRTE_I40E_PMD
17129 	if (ret == -ENOTSUP)
17130 		ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17131 						res->vf_id,
17132 						&stats);
17133 #endif
17134 #ifdef RTE_LIBRTE_BNXT_PMD
17135 	if (ret == -ENOTSUP)
17136 		ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17137 						res->vf_id,
17138 						&stats);
17139 #endif
17140 
17141 	switch (ret) {
17142 	case 0:
17143 		break;
17144 	case -EINVAL:
17145 		printf("invalid vf_id %d\n", res->vf_id);
17146 		break;
17147 	case -ENODEV:
17148 		printf("invalid port_id %d\n", res->port_id);
17149 		break;
17150 	case -ENOTSUP:
17151 		printf("function not implemented\n");
17152 		break;
17153 	default:
17154 		printf("programming error: (%s)\n", strerror(-ret));
17155 	}
17156 
17157 	printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17158 		nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17159 
17160 	printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17161 	       "%-"PRIu64"\n",
17162 	       stats.ipackets, stats.imissed, stats.ibytes);
17163 	printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17164 	printf("  RX-nombuf:  %-10"PRIu64"\n",
17165 	       stats.rx_nombuf);
17166 	printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17167 	       "%-"PRIu64"\n",
17168 	       stats.opackets, stats.oerrors, stats.obytes);
17169 
17170 	printf("  %s############################%s\n",
17171 			       nic_stats_border, nic_stats_border);
17172 }
17173 
17174 cmdline_parse_inst_t cmd_show_vf_stats = {
17175 	.f = cmd_show_vf_stats_parsed,
17176 	.data = NULL,
17177 	.help_str = "show vf stats <port_id> <vf_id>",
17178 	.tokens = {
17179 		(void *)&cmd_show_vf_stats_show,
17180 		(void *)&cmd_show_vf_stats_vf,
17181 		(void *)&cmd_show_vf_stats_stats,
17182 		(void *)&cmd_show_vf_stats_port_id,
17183 		(void *)&cmd_show_vf_stats_vf_id,
17184 		NULL,
17185 	},
17186 };
17187 
17188 /* clear vf stats */
17189 
17190 /* Common result structure for clear vf stats */
17191 struct cmd_clear_vf_stats_result {
17192 	cmdline_fixed_string_t clear;
17193 	cmdline_fixed_string_t vf;
17194 	cmdline_fixed_string_t stats;
17195 	portid_t port_id;
17196 	uint16_t vf_id;
17197 };
17198 
17199 /* Common CLI fields clear vf stats*/
17200 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17201 	TOKEN_STRING_INITIALIZER
17202 		(struct cmd_clear_vf_stats_result,
17203 		 clear, "clear");
17204 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17205 	TOKEN_STRING_INITIALIZER
17206 		(struct cmd_clear_vf_stats_result,
17207 		 vf, "vf");
17208 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17209 	TOKEN_STRING_INITIALIZER
17210 		(struct cmd_clear_vf_stats_result,
17211 		 stats, "stats");
17212 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17213 	TOKEN_NUM_INITIALIZER
17214 		(struct cmd_clear_vf_stats_result,
17215 		 port_id, UINT16);
17216 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17217 	TOKEN_NUM_INITIALIZER
17218 		(struct cmd_clear_vf_stats_result,
17219 		 vf_id, UINT16);
17220 
17221 static void
17222 cmd_clear_vf_stats_parsed(
17223 	void *parsed_result,
17224 	__attribute__((unused)) struct cmdline *cl,
17225 	__attribute__((unused)) void *data)
17226 {
17227 	struct cmd_clear_vf_stats_result *res = parsed_result;
17228 	int ret = -ENOTSUP;
17229 
17230 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17231 		return;
17232 
17233 #ifdef RTE_LIBRTE_I40E_PMD
17234 	if (ret == -ENOTSUP)
17235 		ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17236 						  res->vf_id);
17237 #endif
17238 #ifdef RTE_LIBRTE_BNXT_PMD
17239 	if (ret == -ENOTSUP)
17240 		ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17241 						  res->vf_id);
17242 #endif
17243 
17244 	switch (ret) {
17245 	case 0:
17246 		break;
17247 	case -EINVAL:
17248 		printf("invalid vf_id %d\n", res->vf_id);
17249 		break;
17250 	case -ENODEV:
17251 		printf("invalid port_id %d\n", res->port_id);
17252 		break;
17253 	case -ENOTSUP:
17254 		printf("function not implemented\n");
17255 		break;
17256 	default:
17257 		printf("programming error: (%s)\n", strerror(-ret));
17258 	}
17259 }
17260 
17261 cmdline_parse_inst_t cmd_clear_vf_stats = {
17262 	.f = cmd_clear_vf_stats_parsed,
17263 	.data = NULL,
17264 	.help_str = "clear vf stats <port_id> <vf_id>",
17265 	.tokens = {
17266 		(void *)&cmd_clear_vf_stats_clear,
17267 		(void *)&cmd_clear_vf_stats_vf,
17268 		(void *)&cmd_clear_vf_stats_stats,
17269 		(void *)&cmd_clear_vf_stats_port_id,
17270 		(void *)&cmd_clear_vf_stats_vf_id,
17271 		NULL,
17272 	},
17273 };
17274 
17275 /* port config pctype mapping reset */
17276 
17277 /* Common result structure for port config pctype mapping reset */
17278 struct cmd_pctype_mapping_reset_result {
17279 	cmdline_fixed_string_t port;
17280 	cmdline_fixed_string_t config;
17281 	portid_t port_id;
17282 	cmdline_fixed_string_t pctype;
17283 	cmdline_fixed_string_t mapping;
17284 	cmdline_fixed_string_t reset;
17285 };
17286 
17287 /* Common CLI fields for port config pctype mapping reset*/
17288 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17289 	TOKEN_STRING_INITIALIZER
17290 		(struct cmd_pctype_mapping_reset_result,
17291 		 port, "port");
17292 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17293 	TOKEN_STRING_INITIALIZER
17294 		(struct cmd_pctype_mapping_reset_result,
17295 		 config, "config");
17296 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17297 	TOKEN_NUM_INITIALIZER
17298 		(struct cmd_pctype_mapping_reset_result,
17299 		 port_id, UINT16);
17300 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17301 	TOKEN_STRING_INITIALIZER
17302 		(struct cmd_pctype_mapping_reset_result,
17303 		 pctype, "pctype");
17304 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17305 	TOKEN_STRING_INITIALIZER
17306 		(struct cmd_pctype_mapping_reset_result,
17307 		 mapping, "mapping");
17308 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17309 	TOKEN_STRING_INITIALIZER
17310 		(struct cmd_pctype_mapping_reset_result,
17311 		 reset, "reset");
17312 
17313 static void
17314 cmd_pctype_mapping_reset_parsed(
17315 	void *parsed_result,
17316 	__attribute__((unused)) struct cmdline *cl,
17317 	__attribute__((unused)) void *data)
17318 {
17319 	struct cmd_pctype_mapping_reset_result *res = parsed_result;
17320 	int ret = -ENOTSUP;
17321 
17322 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17323 		return;
17324 
17325 #ifdef RTE_LIBRTE_I40E_PMD
17326 	ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17327 #endif
17328 
17329 	switch (ret) {
17330 	case 0:
17331 		break;
17332 	case -ENODEV:
17333 		printf("invalid port_id %d\n", res->port_id);
17334 		break;
17335 	case -ENOTSUP:
17336 		printf("function not implemented\n");
17337 		break;
17338 	default:
17339 		printf("programming error: (%s)\n", strerror(-ret));
17340 	}
17341 }
17342 
17343 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17344 	.f = cmd_pctype_mapping_reset_parsed,
17345 	.data = NULL,
17346 	.help_str = "port config <port_id> pctype mapping reset",
17347 	.tokens = {
17348 		(void *)&cmd_pctype_mapping_reset_port,
17349 		(void *)&cmd_pctype_mapping_reset_config,
17350 		(void *)&cmd_pctype_mapping_reset_port_id,
17351 		(void *)&cmd_pctype_mapping_reset_pctype,
17352 		(void *)&cmd_pctype_mapping_reset_mapping,
17353 		(void *)&cmd_pctype_mapping_reset_reset,
17354 		NULL,
17355 	},
17356 };
17357 
17358 /* show port pctype mapping */
17359 
17360 /* Common result structure for show port pctype mapping */
17361 struct cmd_pctype_mapping_get_result {
17362 	cmdline_fixed_string_t show;
17363 	cmdline_fixed_string_t port;
17364 	portid_t port_id;
17365 	cmdline_fixed_string_t pctype;
17366 	cmdline_fixed_string_t mapping;
17367 };
17368 
17369 /* Common CLI fields for pctype mapping get */
17370 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17371 	TOKEN_STRING_INITIALIZER
17372 		(struct cmd_pctype_mapping_get_result,
17373 		 show, "show");
17374 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17375 	TOKEN_STRING_INITIALIZER
17376 		(struct cmd_pctype_mapping_get_result,
17377 		 port, "port");
17378 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17379 	TOKEN_NUM_INITIALIZER
17380 		(struct cmd_pctype_mapping_get_result,
17381 		 port_id, UINT16);
17382 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17383 	TOKEN_STRING_INITIALIZER
17384 		(struct cmd_pctype_mapping_get_result,
17385 		 pctype, "pctype");
17386 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17387 	TOKEN_STRING_INITIALIZER
17388 		(struct cmd_pctype_mapping_get_result,
17389 		 mapping, "mapping");
17390 
17391 static void
17392 cmd_pctype_mapping_get_parsed(
17393 	void *parsed_result,
17394 	__attribute__((unused)) struct cmdline *cl,
17395 	__attribute__((unused)) void *data)
17396 {
17397 	struct cmd_pctype_mapping_get_result *res = parsed_result;
17398 	int ret = -ENOTSUP;
17399 #ifdef RTE_LIBRTE_I40E_PMD
17400 	struct rte_pmd_i40e_flow_type_mapping
17401 				mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17402 	int i, j, first_pctype;
17403 #endif
17404 
17405 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17406 		return;
17407 
17408 #ifdef RTE_LIBRTE_I40E_PMD
17409 	ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17410 #endif
17411 
17412 	switch (ret) {
17413 	case 0:
17414 		break;
17415 	case -ENODEV:
17416 		printf("invalid port_id %d\n", res->port_id);
17417 		return;
17418 	case -ENOTSUP:
17419 		printf("function not implemented\n");
17420 		return;
17421 	default:
17422 		printf("programming error: (%s)\n", strerror(-ret));
17423 		return;
17424 	}
17425 
17426 #ifdef RTE_LIBRTE_I40E_PMD
17427 	for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17428 		if (mapping[i].pctype != 0ULL) {
17429 			first_pctype = 1;
17430 
17431 			printf("pctype: ");
17432 			for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17433 				if (mapping[i].pctype & (1ULL << j)) {
17434 					printf(first_pctype ?
17435 					       "%02d" : ",%02d", j);
17436 					first_pctype = 0;
17437 				}
17438 			}
17439 			printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17440 		}
17441 	}
17442 #endif
17443 }
17444 
17445 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17446 	.f = cmd_pctype_mapping_get_parsed,
17447 	.data = NULL,
17448 	.help_str = "show port <port_id> pctype mapping",
17449 	.tokens = {
17450 		(void *)&cmd_pctype_mapping_get_show,
17451 		(void *)&cmd_pctype_mapping_get_port,
17452 		(void *)&cmd_pctype_mapping_get_port_id,
17453 		(void *)&cmd_pctype_mapping_get_pctype,
17454 		(void *)&cmd_pctype_mapping_get_mapping,
17455 		NULL,
17456 	},
17457 };
17458 
17459 /* port config pctype mapping update */
17460 
17461 /* Common result structure for port config pctype mapping update */
17462 struct cmd_pctype_mapping_update_result {
17463 	cmdline_fixed_string_t port;
17464 	cmdline_fixed_string_t config;
17465 	portid_t port_id;
17466 	cmdline_fixed_string_t pctype;
17467 	cmdline_fixed_string_t mapping;
17468 	cmdline_fixed_string_t update;
17469 	cmdline_fixed_string_t pctype_list;
17470 	uint16_t flow_type;
17471 };
17472 
17473 /* Common CLI fields for pctype mapping update*/
17474 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17475 	TOKEN_STRING_INITIALIZER
17476 		(struct cmd_pctype_mapping_update_result,
17477 		 port, "port");
17478 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17479 	TOKEN_STRING_INITIALIZER
17480 		(struct cmd_pctype_mapping_update_result,
17481 		 config, "config");
17482 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17483 	TOKEN_NUM_INITIALIZER
17484 		(struct cmd_pctype_mapping_update_result,
17485 		 port_id, UINT16);
17486 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17487 	TOKEN_STRING_INITIALIZER
17488 		(struct cmd_pctype_mapping_update_result,
17489 		 pctype, "pctype");
17490 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17491 	TOKEN_STRING_INITIALIZER
17492 		(struct cmd_pctype_mapping_update_result,
17493 		 mapping, "mapping");
17494 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17495 	TOKEN_STRING_INITIALIZER
17496 		(struct cmd_pctype_mapping_update_result,
17497 		 update, "update");
17498 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17499 	TOKEN_STRING_INITIALIZER
17500 		(struct cmd_pctype_mapping_update_result,
17501 		 pctype_list, NULL);
17502 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17503 	TOKEN_NUM_INITIALIZER
17504 		(struct cmd_pctype_mapping_update_result,
17505 		 flow_type, UINT16);
17506 
17507 static void
17508 cmd_pctype_mapping_update_parsed(
17509 	void *parsed_result,
17510 	__attribute__((unused)) struct cmdline *cl,
17511 	__attribute__((unused)) void *data)
17512 {
17513 	struct cmd_pctype_mapping_update_result *res = parsed_result;
17514 	int ret = -ENOTSUP;
17515 #ifdef RTE_LIBRTE_I40E_PMD
17516 	struct rte_pmd_i40e_flow_type_mapping mapping;
17517 	unsigned int i;
17518 	unsigned int nb_item;
17519 	unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17520 #endif
17521 
17522 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17523 		return;
17524 
17525 #ifdef RTE_LIBRTE_I40E_PMD
17526 	nb_item = parse_item_list(res->pctype_list, "pctypes",
17527 				  RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17528 	mapping.flow_type = res->flow_type;
17529 	for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17530 		mapping.pctype |= (1ULL << pctype_list[i]);
17531 	ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17532 						&mapping,
17533 						1,
17534 						0);
17535 #endif
17536 
17537 	switch (ret) {
17538 	case 0:
17539 		break;
17540 	case -EINVAL:
17541 		printf("invalid pctype or flow type\n");
17542 		break;
17543 	case -ENODEV:
17544 		printf("invalid port_id %d\n", res->port_id);
17545 		break;
17546 	case -ENOTSUP:
17547 		printf("function not implemented\n");
17548 		break;
17549 	default:
17550 		printf("programming error: (%s)\n", strerror(-ret));
17551 	}
17552 }
17553 
17554 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17555 	.f = cmd_pctype_mapping_update_parsed,
17556 	.data = NULL,
17557 	.help_str = "port config <port_id> pctype mapping update"
17558 	" <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17559 	.tokens = {
17560 		(void *)&cmd_pctype_mapping_update_port,
17561 		(void *)&cmd_pctype_mapping_update_config,
17562 		(void *)&cmd_pctype_mapping_update_port_id,
17563 		(void *)&cmd_pctype_mapping_update_pctype,
17564 		(void *)&cmd_pctype_mapping_update_mapping,
17565 		(void *)&cmd_pctype_mapping_update_update,
17566 		(void *)&cmd_pctype_mapping_update_pc_type,
17567 		(void *)&cmd_pctype_mapping_update_flow_type,
17568 		NULL,
17569 	},
17570 };
17571 
17572 /* ptype mapping get */
17573 
17574 /* Common result structure for ptype mapping get */
17575 struct cmd_ptype_mapping_get_result {
17576 	cmdline_fixed_string_t ptype;
17577 	cmdline_fixed_string_t mapping;
17578 	cmdline_fixed_string_t get;
17579 	portid_t port_id;
17580 	uint8_t valid_only;
17581 };
17582 
17583 /* Common CLI fields for ptype mapping get */
17584 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17585 	TOKEN_STRING_INITIALIZER
17586 		(struct cmd_ptype_mapping_get_result,
17587 		 ptype, "ptype");
17588 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17589 	TOKEN_STRING_INITIALIZER
17590 		(struct cmd_ptype_mapping_get_result,
17591 		 mapping, "mapping");
17592 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17593 	TOKEN_STRING_INITIALIZER
17594 		(struct cmd_ptype_mapping_get_result,
17595 		 get, "get");
17596 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17597 	TOKEN_NUM_INITIALIZER
17598 		(struct cmd_ptype_mapping_get_result,
17599 		 port_id, UINT16);
17600 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17601 	TOKEN_NUM_INITIALIZER
17602 		(struct cmd_ptype_mapping_get_result,
17603 		 valid_only, UINT8);
17604 
17605 static void
17606 cmd_ptype_mapping_get_parsed(
17607 	void *parsed_result,
17608 	__attribute__((unused)) struct cmdline *cl,
17609 	__attribute__((unused)) void *data)
17610 {
17611 	struct cmd_ptype_mapping_get_result *res = parsed_result;
17612 	int ret = -ENOTSUP;
17613 #ifdef RTE_LIBRTE_I40E_PMD
17614 	int max_ptype_num = 256;
17615 	struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17616 	uint16_t count;
17617 	int i;
17618 #endif
17619 
17620 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17621 		return;
17622 
17623 #ifdef RTE_LIBRTE_I40E_PMD
17624 	ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17625 					mapping,
17626 					max_ptype_num,
17627 					&count,
17628 					res->valid_only);
17629 #endif
17630 
17631 	switch (ret) {
17632 	case 0:
17633 		break;
17634 	case -ENODEV:
17635 		printf("invalid port_id %d\n", res->port_id);
17636 		break;
17637 	case -ENOTSUP:
17638 		printf("function not implemented\n");
17639 		break;
17640 	default:
17641 		printf("programming error: (%s)\n", strerror(-ret));
17642 	}
17643 
17644 #ifdef RTE_LIBRTE_I40E_PMD
17645 	if (!ret) {
17646 		for (i = 0; i < count; i++)
17647 			printf("%3d\t0x%08x\n",
17648 				mapping[i].hw_ptype, mapping[i].sw_ptype);
17649 	}
17650 #endif
17651 }
17652 
17653 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17654 	.f = cmd_ptype_mapping_get_parsed,
17655 	.data = NULL,
17656 	.help_str = "ptype mapping get <port_id> <valid_only>",
17657 	.tokens = {
17658 		(void *)&cmd_ptype_mapping_get_ptype,
17659 		(void *)&cmd_ptype_mapping_get_mapping,
17660 		(void *)&cmd_ptype_mapping_get_get,
17661 		(void *)&cmd_ptype_mapping_get_port_id,
17662 		(void *)&cmd_ptype_mapping_get_valid_only,
17663 		NULL,
17664 	},
17665 };
17666 
17667 /* ptype mapping replace */
17668 
17669 /* Common result structure for ptype mapping replace */
17670 struct cmd_ptype_mapping_replace_result {
17671 	cmdline_fixed_string_t ptype;
17672 	cmdline_fixed_string_t mapping;
17673 	cmdline_fixed_string_t replace;
17674 	portid_t port_id;
17675 	uint32_t target;
17676 	uint8_t mask;
17677 	uint32_t pkt_type;
17678 };
17679 
17680 /* Common CLI fields for ptype mapping replace */
17681 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17682 	TOKEN_STRING_INITIALIZER
17683 		(struct cmd_ptype_mapping_replace_result,
17684 		 ptype, "ptype");
17685 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17686 	TOKEN_STRING_INITIALIZER
17687 		(struct cmd_ptype_mapping_replace_result,
17688 		 mapping, "mapping");
17689 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17690 	TOKEN_STRING_INITIALIZER
17691 		(struct cmd_ptype_mapping_replace_result,
17692 		 replace, "replace");
17693 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17694 	TOKEN_NUM_INITIALIZER
17695 		(struct cmd_ptype_mapping_replace_result,
17696 		 port_id, UINT16);
17697 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17698 	TOKEN_NUM_INITIALIZER
17699 		(struct cmd_ptype_mapping_replace_result,
17700 		 target, UINT32);
17701 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17702 	TOKEN_NUM_INITIALIZER
17703 		(struct cmd_ptype_mapping_replace_result,
17704 		 mask, UINT8);
17705 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17706 	TOKEN_NUM_INITIALIZER
17707 		(struct cmd_ptype_mapping_replace_result,
17708 		 pkt_type, UINT32);
17709 
17710 static void
17711 cmd_ptype_mapping_replace_parsed(
17712 	void *parsed_result,
17713 	__attribute__((unused)) struct cmdline *cl,
17714 	__attribute__((unused)) void *data)
17715 {
17716 	struct cmd_ptype_mapping_replace_result *res = parsed_result;
17717 	int ret = -ENOTSUP;
17718 
17719 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17720 		return;
17721 
17722 #ifdef RTE_LIBRTE_I40E_PMD
17723 	ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17724 					res->target,
17725 					res->mask,
17726 					res->pkt_type);
17727 #endif
17728 
17729 	switch (ret) {
17730 	case 0:
17731 		break;
17732 	case -EINVAL:
17733 		printf("invalid ptype 0x%8x or 0x%8x\n",
17734 				res->target, res->pkt_type);
17735 		break;
17736 	case -ENODEV:
17737 		printf("invalid port_id %d\n", res->port_id);
17738 		break;
17739 	case -ENOTSUP:
17740 		printf("function not implemented\n");
17741 		break;
17742 	default:
17743 		printf("programming error: (%s)\n", strerror(-ret));
17744 	}
17745 }
17746 
17747 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17748 	.f = cmd_ptype_mapping_replace_parsed,
17749 	.data = NULL,
17750 	.help_str =
17751 		"ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17752 	.tokens = {
17753 		(void *)&cmd_ptype_mapping_replace_ptype,
17754 		(void *)&cmd_ptype_mapping_replace_mapping,
17755 		(void *)&cmd_ptype_mapping_replace_replace,
17756 		(void *)&cmd_ptype_mapping_replace_port_id,
17757 		(void *)&cmd_ptype_mapping_replace_target,
17758 		(void *)&cmd_ptype_mapping_replace_mask,
17759 		(void *)&cmd_ptype_mapping_replace_pkt_type,
17760 		NULL,
17761 	},
17762 };
17763 
17764 /* ptype mapping reset */
17765 
17766 /* Common result structure for ptype mapping reset */
17767 struct cmd_ptype_mapping_reset_result {
17768 	cmdline_fixed_string_t ptype;
17769 	cmdline_fixed_string_t mapping;
17770 	cmdline_fixed_string_t reset;
17771 	portid_t port_id;
17772 };
17773 
17774 /* Common CLI fields for ptype mapping reset*/
17775 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17776 	TOKEN_STRING_INITIALIZER
17777 		(struct cmd_ptype_mapping_reset_result,
17778 		 ptype, "ptype");
17779 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17780 	TOKEN_STRING_INITIALIZER
17781 		(struct cmd_ptype_mapping_reset_result,
17782 		 mapping, "mapping");
17783 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17784 	TOKEN_STRING_INITIALIZER
17785 		(struct cmd_ptype_mapping_reset_result,
17786 		 reset, "reset");
17787 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17788 	TOKEN_NUM_INITIALIZER
17789 		(struct cmd_ptype_mapping_reset_result,
17790 		 port_id, UINT16);
17791 
17792 static void
17793 cmd_ptype_mapping_reset_parsed(
17794 	void *parsed_result,
17795 	__attribute__((unused)) struct cmdline *cl,
17796 	__attribute__((unused)) void *data)
17797 {
17798 	struct cmd_ptype_mapping_reset_result *res = parsed_result;
17799 	int ret = -ENOTSUP;
17800 
17801 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17802 		return;
17803 
17804 #ifdef RTE_LIBRTE_I40E_PMD
17805 	ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17806 #endif
17807 
17808 	switch (ret) {
17809 	case 0:
17810 		break;
17811 	case -ENODEV:
17812 		printf("invalid port_id %d\n", res->port_id);
17813 		break;
17814 	case -ENOTSUP:
17815 		printf("function not implemented\n");
17816 		break;
17817 	default:
17818 		printf("programming error: (%s)\n", strerror(-ret));
17819 	}
17820 }
17821 
17822 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17823 	.f = cmd_ptype_mapping_reset_parsed,
17824 	.data = NULL,
17825 	.help_str = "ptype mapping reset <port_id>",
17826 	.tokens = {
17827 		(void *)&cmd_ptype_mapping_reset_ptype,
17828 		(void *)&cmd_ptype_mapping_reset_mapping,
17829 		(void *)&cmd_ptype_mapping_reset_reset,
17830 		(void *)&cmd_ptype_mapping_reset_port_id,
17831 		NULL,
17832 	},
17833 };
17834 
17835 /* ptype mapping update */
17836 
17837 /* Common result structure for ptype mapping update */
17838 struct cmd_ptype_mapping_update_result {
17839 	cmdline_fixed_string_t ptype;
17840 	cmdline_fixed_string_t mapping;
17841 	cmdline_fixed_string_t reset;
17842 	portid_t port_id;
17843 	uint8_t hw_ptype;
17844 	uint32_t sw_ptype;
17845 };
17846 
17847 /* Common CLI fields for ptype mapping update*/
17848 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17849 	TOKEN_STRING_INITIALIZER
17850 		(struct cmd_ptype_mapping_update_result,
17851 		 ptype, "ptype");
17852 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17853 	TOKEN_STRING_INITIALIZER
17854 		(struct cmd_ptype_mapping_update_result,
17855 		 mapping, "mapping");
17856 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17857 	TOKEN_STRING_INITIALIZER
17858 		(struct cmd_ptype_mapping_update_result,
17859 		 reset, "update");
17860 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17861 	TOKEN_NUM_INITIALIZER
17862 		(struct cmd_ptype_mapping_update_result,
17863 		 port_id, UINT16);
17864 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17865 	TOKEN_NUM_INITIALIZER
17866 		(struct cmd_ptype_mapping_update_result,
17867 		 hw_ptype, UINT8);
17868 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17869 	TOKEN_NUM_INITIALIZER
17870 		(struct cmd_ptype_mapping_update_result,
17871 		 sw_ptype, UINT32);
17872 
17873 static void
17874 cmd_ptype_mapping_update_parsed(
17875 	void *parsed_result,
17876 	__attribute__((unused)) struct cmdline *cl,
17877 	__attribute__((unused)) void *data)
17878 {
17879 	struct cmd_ptype_mapping_update_result *res = parsed_result;
17880 	int ret = -ENOTSUP;
17881 #ifdef RTE_LIBRTE_I40E_PMD
17882 	struct rte_pmd_i40e_ptype_mapping mapping;
17883 #endif
17884 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17885 		return;
17886 
17887 #ifdef RTE_LIBRTE_I40E_PMD
17888 	mapping.hw_ptype = res->hw_ptype;
17889 	mapping.sw_ptype = res->sw_ptype;
17890 	ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17891 						&mapping,
17892 						1,
17893 						0);
17894 #endif
17895 
17896 	switch (ret) {
17897 	case 0:
17898 		break;
17899 	case -EINVAL:
17900 		printf("invalid ptype 0x%8x\n", res->sw_ptype);
17901 		break;
17902 	case -ENODEV:
17903 		printf("invalid port_id %d\n", res->port_id);
17904 		break;
17905 	case -ENOTSUP:
17906 		printf("function not implemented\n");
17907 		break;
17908 	default:
17909 		printf("programming error: (%s)\n", strerror(-ret));
17910 	}
17911 }
17912 
17913 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17914 	.f = cmd_ptype_mapping_update_parsed,
17915 	.data = NULL,
17916 	.help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17917 	.tokens = {
17918 		(void *)&cmd_ptype_mapping_update_ptype,
17919 		(void *)&cmd_ptype_mapping_update_mapping,
17920 		(void *)&cmd_ptype_mapping_update_update,
17921 		(void *)&cmd_ptype_mapping_update_port_id,
17922 		(void *)&cmd_ptype_mapping_update_hw_ptype,
17923 		(void *)&cmd_ptype_mapping_update_sw_ptype,
17924 		NULL,
17925 	},
17926 };
17927 
17928 /* Common result structure for file commands */
17929 struct cmd_cmdfile_result {
17930 	cmdline_fixed_string_t load;
17931 	cmdline_fixed_string_t filename;
17932 };
17933 
17934 /* Common CLI fields for file commands */
17935 cmdline_parse_token_string_t cmd_load_cmdfile =
17936 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17937 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17938 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17939 
17940 static void
17941 cmd_load_from_file_parsed(
17942 	void *parsed_result,
17943 	__attribute__((unused)) struct cmdline *cl,
17944 	__attribute__((unused)) void *data)
17945 {
17946 	struct cmd_cmdfile_result *res = parsed_result;
17947 
17948 	cmdline_read_from_file(res->filename);
17949 }
17950 
17951 cmdline_parse_inst_t cmd_load_from_file = {
17952 	.f = cmd_load_from_file_parsed,
17953 	.data = NULL,
17954 	.help_str = "load <filename>",
17955 	.tokens = {
17956 		(void *)&cmd_load_cmdfile,
17957 		(void *)&cmd_load_cmdfile_filename,
17958 		NULL,
17959 	},
17960 };
17961 
17962 /* Get Rx offloads capabilities */
17963 struct cmd_rx_offload_get_capa_result {
17964 	cmdline_fixed_string_t show;
17965 	cmdline_fixed_string_t port;
17966 	portid_t port_id;
17967 	cmdline_fixed_string_t rx_offload;
17968 	cmdline_fixed_string_t capabilities;
17969 };
17970 
17971 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17972 	TOKEN_STRING_INITIALIZER
17973 		(struct cmd_rx_offload_get_capa_result,
17974 		 show, "show");
17975 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17976 	TOKEN_STRING_INITIALIZER
17977 		(struct cmd_rx_offload_get_capa_result,
17978 		 port, "port");
17979 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17980 	TOKEN_NUM_INITIALIZER
17981 		(struct cmd_rx_offload_get_capa_result,
17982 		 port_id, UINT16);
17983 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17984 	TOKEN_STRING_INITIALIZER
17985 		(struct cmd_rx_offload_get_capa_result,
17986 		 rx_offload, "rx_offload");
17987 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17988 	TOKEN_STRING_INITIALIZER
17989 		(struct cmd_rx_offload_get_capa_result,
17990 		 capabilities, "capabilities");
17991 
17992 static void
17993 print_rx_offloads(uint64_t offloads)
17994 {
17995 	uint64_t single_offload;
17996 	int begin;
17997 	int end;
17998 	int bit;
17999 
18000 	if (offloads == 0)
18001 		return;
18002 
18003 	begin = __builtin_ctzll(offloads);
18004 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18005 
18006 	single_offload = 1ULL << begin;
18007 	for (bit = begin; bit < end; bit++) {
18008 		if (offloads & single_offload)
18009 			printf(" %s",
18010 			       rte_eth_dev_rx_offload_name(single_offload));
18011 		single_offload <<= 1;
18012 	}
18013 }
18014 
18015 static void
18016 cmd_rx_offload_get_capa_parsed(
18017 	void *parsed_result,
18018 	__attribute__((unused)) struct cmdline *cl,
18019 	__attribute__((unused)) void *data)
18020 {
18021 	struct cmd_rx_offload_get_capa_result *res = parsed_result;
18022 	struct rte_eth_dev_info dev_info;
18023 	portid_t port_id = res->port_id;
18024 	uint64_t queue_offloads;
18025 	uint64_t port_offloads;
18026 	int ret;
18027 
18028 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18029 	if (ret != 0)
18030 		return;
18031 
18032 	queue_offloads = dev_info.rx_queue_offload_capa;
18033 	port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18034 
18035 	printf("Rx Offloading Capabilities of port %d :\n", port_id);
18036 	printf("  Per Queue :");
18037 	print_rx_offloads(queue_offloads);
18038 
18039 	printf("\n");
18040 	printf("  Per Port  :");
18041 	print_rx_offloads(port_offloads);
18042 	printf("\n\n");
18043 }
18044 
18045 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18046 	.f = cmd_rx_offload_get_capa_parsed,
18047 	.data = NULL,
18048 	.help_str = "show port <port_id> rx_offload capabilities",
18049 	.tokens = {
18050 		(void *)&cmd_rx_offload_get_capa_show,
18051 		(void *)&cmd_rx_offload_get_capa_port,
18052 		(void *)&cmd_rx_offload_get_capa_port_id,
18053 		(void *)&cmd_rx_offload_get_capa_rx_offload,
18054 		(void *)&cmd_rx_offload_get_capa_capabilities,
18055 		NULL,
18056 	}
18057 };
18058 
18059 /* Get Rx offloads configuration */
18060 struct cmd_rx_offload_get_configuration_result {
18061 	cmdline_fixed_string_t show;
18062 	cmdline_fixed_string_t port;
18063 	portid_t port_id;
18064 	cmdline_fixed_string_t rx_offload;
18065 	cmdline_fixed_string_t configuration;
18066 };
18067 
18068 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18069 	TOKEN_STRING_INITIALIZER
18070 		(struct cmd_rx_offload_get_configuration_result,
18071 		 show, "show");
18072 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18073 	TOKEN_STRING_INITIALIZER
18074 		(struct cmd_rx_offload_get_configuration_result,
18075 		 port, "port");
18076 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18077 	TOKEN_NUM_INITIALIZER
18078 		(struct cmd_rx_offload_get_configuration_result,
18079 		 port_id, UINT16);
18080 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18081 	TOKEN_STRING_INITIALIZER
18082 		(struct cmd_rx_offload_get_configuration_result,
18083 		 rx_offload, "rx_offload");
18084 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18085 	TOKEN_STRING_INITIALIZER
18086 		(struct cmd_rx_offload_get_configuration_result,
18087 		 configuration, "configuration");
18088 
18089 static void
18090 cmd_rx_offload_get_configuration_parsed(
18091 	void *parsed_result,
18092 	__attribute__((unused)) struct cmdline *cl,
18093 	__attribute__((unused)) void *data)
18094 {
18095 	struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18096 	struct rte_eth_dev_info dev_info;
18097 	portid_t port_id = res->port_id;
18098 	struct rte_port *port = &ports[port_id];
18099 	uint64_t port_offloads;
18100 	uint64_t queue_offloads;
18101 	uint16_t nb_rx_queues;
18102 	int q;
18103 	int ret;
18104 
18105 	printf("Rx Offloading Configuration of port %d :\n", port_id);
18106 
18107 	port_offloads = port->dev_conf.rxmode.offloads;
18108 	printf("  Port :");
18109 	print_rx_offloads(port_offloads);
18110 	printf("\n");
18111 
18112 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18113 	if (ret != 0)
18114 		return;
18115 
18116 	nb_rx_queues = dev_info.nb_rx_queues;
18117 	for (q = 0; q < nb_rx_queues; q++) {
18118 		queue_offloads = port->rx_conf[q].offloads;
18119 		printf("  Queue[%2d] :", q);
18120 		print_rx_offloads(queue_offloads);
18121 		printf("\n");
18122 	}
18123 	printf("\n");
18124 }
18125 
18126 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18127 	.f = cmd_rx_offload_get_configuration_parsed,
18128 	.data = NULL,
18129 	.help_str = "show port <port_id> rx_offload configuration",
18130 	.tokens = {
18131 		(void *)&cmd_rx_offload_get_configuration_show,
18132 		(void *)&cmd_rx_offload_get_configuration_port,
18133 		(void *)&cmd_rx_offload_get_configuration_port_id,
18134 		(void *)&cmd_rx_offload_get_configuration_rx_offload,
18135 		(void *)&cmd_rx_offload_get_configuration_configuration,
18136 		NULL,
18137 	}
18138 };
18139 
18140 /* Enable/Disable a per port offloading */
18141 struct cmd_config_per_port_rx_offload_result {
18142 	cmdline_fixed_string_t port;
18143 	cmdline_fixed_string_t config;
18144 	portid_t port_id;
18145 	cmdline_fixed_string_t rx_offload;
18146 	cmdline_fixed_string_t offload;
18147 	cmdline_fixed_string_t on_off;
18148 };
18149 
18150 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18151 	TOKEN_STRING_INITIALIZER
18152 		(struct cmd_config_per_port_rx_offload_result,
18153 		 port, "port");
18154 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18155 	TOKEN_STRING_INITIALIZER
18156 		(struct cmd_config_per_port_rx_offload_result,
18157 		 config, "config");
18158 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18159 	TOKEN_NUM_INITIALIZER
18160 		(struct cmd_config_per_port_rx_offload_result,
18161 		 port_id, UINT16);
18162 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18163 	TOKEN_STRING_INITIALIZER
18164 		(struct cmd_config_per_port_rx_offload_result,
18165 		 rx_offload, "rx_offload");
18166 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18167 	TOKEN_STRING_INITIALIZER
18168 		(struct cmd_config_per_port_rx_offload_result,
18169 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18170 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18171 			   "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18172 			   "scatter#timestamp#security#keep_crc#rss_hash");
18173 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18174 	TOKEN_STRING_INITIALIZER
18175 		(struct cmd_config_per_port_rx_offload_result,
18176 		 on_off, "on#off");
18177 
18178 static uint64_t
18179 search_rx_offload(const char *name)
18180 {
18181 	uint64_t single_offload;
18182 	const char *single_name;
18183 	int found = 0;
18184 	unsigned int bit;
18185 
18186 	single_offload = 1;
18187 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18188 		single_name = rte_eth_dev_rx_offload_name(single_offload);
18189 		if (!strcasecmp(single_name, name)) {
18190 			found = 1;
18191 			break;
18192 		}
18193 		single_offload <<= 1;
18194 	}
18195 
18196 	if (found)
18197 		return single_offload;
18198 
18199 	return 0;
18200 }
18201 
18202 static void
18203 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18204 				__attribute__((unused)) struct cmdline *cl,
18205 				__attribute__((unused)) void *data)
18206 {
18207 	struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18208 	portid_t port_id = res->port_id;
18209 	struct rte_eth_dev_info dev_info;
18210 	struct rte_port *port = &ports[port_id];
18211 	uint64_t single_offload;
18212 	uint16_t nb_rx_queues;
18213 	int q;
18214 	int ret;
18215 
18216 	if (port->port_status != RTE_PORT_STOPPED) {
18217 		printf("Error: Can't config offload when Port %d "
18218 		       "is not stopped\n", port_id);
18219 		return;
18220 	}
18221 
18222 	single_offload = search_rx_offload(res->offload);
18223 	if (single_offload == 0) {
18224 		printf("Unknown offload name: %s\n", res->offload);
18225 		return;
18226 	}
18227 
18228 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18229 	if (ret != 0)
18230 		return;
18231 
18232 	nb_rx_queues = dev_info.nb_rx_queues;
18233 	if (!strcmp(res->on_off, "on")) {
18234 		port->dev_conf.rxmode.offloads |= single_offload;
18235 		for (q = 0; q < nb_rx_queues; q++)
18236 			port->rx_conf[q].offloads |= single_offload;
18237 	} else {
18238 		port->dev_conf.rxmode.offloads &= ~single_offload;
18239 		for (q = 0; q < nb_rx_queues; q++)
18240 			port->rx_conf[q].offloads &= ~single_offload;
18241 	}
18242 
18243 	cmd_reconfig_device_queue(port_id, 1, 1);
18244 }
18245 
18246 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18247 	.f = cmd_config_per_port_rx_offload_parsed,
18248 	.data = NULL,
18249 	.help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18250 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18251 		    "macsec_strip|header_split|vlan_filter|vlan_extend|"
18252 		    "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18253 		    "on|off",
18254 	.tokens = {
18255 		(void *)&cmd_config_per_port_rx_offload_result_port,
18256 		(void *)&cmd_config_per_port_rx_offload_result_config,
18257 		(void *)&cmd_config_per_port_rx_offload_result_port_id,
18258 		(void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18259 		(void *)&cmd_config_per_port_rx_offload_result_offload,
18260 		(void *)&cmd_config_per_port_rx_offload_result_on_off,
18261 		NULL,
18262 	}
18263 };
18264 
18265 /* Enable/Disable a per queue offloading */
18266 struct cmd_config_per_queue_rx_offload_result {
18267 	cmdline_fixed_string_t port;
18268 	portid_t port_id;
18269 	cmdline_fixed_string_t rxq;
18270 	uint16_t queue_id;
18271 	cmdline_fixed_string_t rx_offload;
18272 	cmdline_fixed_string_t offload;
18273 	cmdline_fixed_string_t on_off;
18274 };
18275 
18276 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18277 	TOKEN_STRING_INITIALIZER
18278 		(struct cmd_config_per_queue_rx_offload_result,
18279 		 port, "port");
18280 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18281 	TOKEN_NUM_INITIALIZER
18282 		(struct cmd_config_per_queue_rx_offload_result,
18283 		 port_id, UINT16);
18284 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18285 	TOKEN_STRING_INITIALIZER
18286 		(struct cmd_config_per_queue_rx_offload_result,
18287 		 rxq, "rxq");
18288 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18289 	TOKEN_NUM_INITIALIZER
18290 		(struct cmd_config_per_queue_rx_offload_result,
18291 		 queue_id, UINT16);
18292 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18293 	TOKEN_STRING_INITIALIZER
18294 		(struct cmd_config_per_queue_rx_offload_result,
18295 		 rx_offload, "rx_offload");
18296 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18297 	TOKEN_STRING_INITIALIZER
18298 		(struct cmd_config_per_queue_rx_offload_result,
18299 		 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18300 			   "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18301 			   "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18302 			   "scatter#timestamp#security#keep_crc");
18303 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18304 	TOKEN_STRING_INITIALIZER
18305 		(struct cmd_config_per_queue_rx_offload_result,
18306 		 on_off, "on#off");
18307 
18308 static void
18309 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18310 				__attribute__((unused)) struct cmdline *cl,
18311 				__attribute__((unused)) void *data)
18312 {
18313 	struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18314 	struct rte_eth_dev_info dev_info;
18315 	portid_t port_id = res->port_id;
18316 	uint16_t queue_id = res->queue_id;
18317 	struct rte_port *port = &ports[port_id];
18318 	uint64_t single_offload;
18319 	int ret;
18320 
18321 	if (port->port_status != RTE_PORT_STOPPED) {
18322 		printf("Error: Can't config offload when Port %d "
18323 		       "is not stopped\n", port_id);
18324 		return;
18325 	}
18326 
18327 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18328 	if (ret != 0)
18329 		return;
18330 
18331 	if (queue_id >= dev_info.nb_rx_queues) {
18332 		printf("Error: input queue_id should be 0 ... "
18333 		       "%d\n", dev_info.nb_rx_queues - 1);
18334 		return;
18335 	}
18336 
18337 	single_offload = search_rx_offload(res->offload);
18338 	if (single_offload == 0) {
18339 		printf("Unknown offload name: %s\n", res->offload);
18340 		return;
18341 	}
18342 
18343 	if (!strcmp(res->on_off, "on"))
18344 		port->rx_conf[queue_id].offloads |= single_offload;
18345 	else
18346 		port->rx_conf[queue_id].offloads &= ~single_offload;
18347 
18348 	cmd_reconfig_device_queue(port_id, 1, 1);
18349 }
18350 
18351 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18352 	.f = cmd_config_per_queue_rx_offload_parsed,
18353 	.data = NULL,
18354 	.help_str = "port <port_id> rxq <queue_id> rx_offload "
18355 		    "vlan_strip|ipv4_cksum|"
18356 		    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18357 		    "macsec_strip|header_split|vlan_filter|vlan_extend|"
18358 		    "jumbo_frame|scatter|timestamp|security|keep_crc "
18359 		    "on|off",
18360 	.tokens = {
18361 		(void *)&cmd_config_per_queue_rx_offload_result_port,
18362 		(void *)&cmd_config_per_queue_rx_offload_result_port_id,
18363 		(void *)&cmd_config_per_queue_rx_offload_result_rxq,
18364 		(void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18365 		(void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18366 		(void *)&cmd_config_per_queue_rx_offload_result_offload,
18367 		(void *)&cmd_config_per_queue_rx_offload_result_on_off,
18368 		NULL,
18369 	}
18370 };
18371 
18372 /* Get Tx offloads capabilities */
18373 struct cmd_tx_offload_get_capa_result {
18374 	cmdline_fixed_string_t show;
18375 	cmdline_fixed_string_t port;
18376 	portid_t port_id;
18377 	cmdline_fixed_string_t tx_offload;
18378 	cmdline_fixed_string_t capabilities;
18379 };
18380 
18381 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18382 	TOKEN_STRING_INITIALIZER
18383 		(struct cmd_tx_offload_get_capa_result,
18384 		 show, "show");
18385 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18386 	TOKEN_STRING_INITIALIZER
18387 		(struct cmd_tx_offload_get_capa_result,
18388 		 port, "port");
18389 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18390 	TOKEN_NUM_INITIALIZER
18391 		(struct cmd_tx_offload_get_capa_result,
18392 		 port_id, UINT16);
18393 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18394 	TOKEN_STRING_INITIALIZER
18395 		(struct cmd_tx_offload_get_capa_result,
18396 		 tx_offload, "tx_offload");
18397 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18398 	TOKEN_STRING_INITIALIZER
18399 		(struct cmd_tx_offload_get_capa_result,
18400 		 capabilities, "capabilities");
18401 
18402 static void
18403 print_tx_offloads(uint64_t offloads)
18404 {
18405 	uint64_t single_offload;
18406 	int begin;
18407 	int end;
18408 	int bit;
18409 
18410 	if (offloads == 0)
18411 		return;
18412 
18413 	begin = __builtin_ctzll(offloads);
18414 	end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18415 
18416 	single_offload = 1ULL << begin;
18417 	for (bit = begin; bit < end; bit++) {
18418 		if (offloads & single_offload)
18419 			printf(" %s",
18420 			       rte_eth_dev_tx_offload_name(single_offload));
18421 		single_offload <<= 1;
18422 	}
18423 }
18424 
18425 static void
18426 cmd_tx_offload_get_capa_parsed(
18427 	void *parsed_result,
18428 	__attribute__((unused)) struct cmdline *cl,
18429 	__attribute__((unused)) void *data)
18430 {
18431 	struct cmd_tx_offload_get_capa_result *res = parsed_result;
18432 	struct rte_eth_dev_info dev_info;
18433 	portid_t port_id = res->port_id;
18434 	uint64_t queue_offloads;
18435 	uint64_t port_offloads;
18436 	int ret;
18437 
18438 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18439 	if (ret != 0)
18440 		return;
18441 
18442 	queue_offloads = dev_info.tx_queue_offload_capa;
18443 	port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18444 
18445 	printf("Tx Offloading Capabilities of port %d :\n", port_id);
18446 	printf("  Per Queue :");
18447 	print_tx_offloads(queue_offloads);
18448 
18449 	printf("\n");
18450 	printf("  Per Port  :");
18451 	print_tx_offloads(port_offloads);
18452 	printf("\n\n");
18453 }
18454 
18455 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18456 	.f = cmd_tx_offload_get_capa_parsed,
18457 	.data = NULL,
18458 	.help_str = "show port <port_id> tx_offload capabilities",
18459 	.tokens = {
18460 		(void *)&cmd_tx_offload_get_capa_show,
18461 		(void *)&cmd_tx_offload_get_capa_port,
18462 		(void *)&cmd_tx_offload_get_capa_port_id,
18463 		(void *)&cmd_tx_offload_get_capa_tx_offload,
18464 		(void *)&cmd_tx_offload_get_capa_capabilities,
18465 		NULL,
18466 	}
18467 };
18468 
18469 /* Get Tx offloads configuration */
18470 struct cmd_tx_offload_get_configuration_result {
18471 	cmdline_fixed_string_t show;
18472 	cmdline_fixed_string_t port;
18473 	portid_t port_id;
18474 	cmdline_fixed_string_t tx_offload;
18475 	cmdline_fixed_string_t configuration;
18476 };
18477 
18478 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18479 	TOKEN_STRING_INITIALIZER
18480 		(struct cmd_tx_offload_get_configuration_result,
18481 		 show, "show");
18482 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18483 	TOKEN_STRING_INITIALIZER
18484 		(struct cmd_tx_offload_get_configuration_result,
18485 		 port, "port");
18486 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18487 	TOKEN_NUM_INITIALIZER
18488 		(struct cmd_tx_offload_get_configuration_result,
18489 		 port_id, UINT16);
18490 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18491 	TOKEN_STRING_INITIALIZER
18492 		(struct cmd_tx_offload_get_configuration_result,
18493 		 tx_offload, "tx_offload");
18494 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18495 	TOKEN_STRING_INITIALIZER
18496 		(struct cmd_tx_offload_get_configuration_result,
18497 		 configuration, "configuration");
18498 
18499 static void
18500 cmd_tx_offload_get_configuration_parsed(
18501 	void *parsed_result,
18502 	__attribute__((unused)) struct cmdline *cl,
18503 	__attribute__((unused)) void *data)
18504 {
18505 	struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18506 	struct rte_eth_dev_info dev_info;
18507 	portid_t port_id = res->port_id;
18508 	struct rte_port *port = &ports[port_id];
18509 	uint64_t port_offloads;
18510 	uint64_t queue_offloads;
18511 	uint16_t nb_tx_queues;
18512 	int q;
18513 	int ret;
18514 
18515 	printf("Tx Offloading Configuration of port %d :\n", port_id);
18516 
18517 	port_offloads = port->dev_conf.txmode.offloads;
18518 	printf("  Port :");
18519 	print_tx_offloads(port_offloads);
18520 	printf("\n");
18521 
18522 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18523 	if (ret != 0)
18524 		return;
18525 
18526 	nb_tx_queues = dev_info.nb_tx_queues;
18527 	for (q = 0; q < nb_tx_queues; q++) {
18528 		queue_offloads = port->tx_conf[q].offloads;
18529 		printf("  Queue[%2d] :", q);
18530 		print_tx_offloads(queue_offloads);
18531 		printf("\n");
18532 	}
18533 	printf("\n");
18534 }
18535 
18536 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18537 	.f = cmd_tx_offload_get_configuration_parsed,
18538 	.data = NULL,
18539 	.help_str = "show port <port_id> tx_offload configuration",
18540 	.tokens = {
18541 		(void *)&cmd_tx_offload_get_configuration_show,
18542 		(void *)&cmd_tx_offload_get_configuration_port,
18543 		(void *)&cmd_tx_offload_get_configuration_port_id,
18544 		(void *)&cmd_tx_offload_get_configuration_tx_offload,
18545 		(void *)&cmd_tx_offload_get_configuration_configuration,
18546 		NULL,
18547 	}
18548 };
18549 
18550 /* Enable/Disable a per port offloading */
18551 struct cmd_config_per_port_tx_offload_result {
18552 	cmdline_fixed_string_t port;
18553 	cmdline_fixed_string_t config;
18554 	portid_t port_id;
18555 	cmdline_fixed_string_t tx_offload;
18556 	cmdline_fixed_string_t offload;
18557 	cmdline_fixed_string_t on_off;
18558 };
18559 
18560 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18561 	TOKEN_STRING_INITIALIZER
18562 		(struct cmd_config_per_port_tx_offload_result,
18563 		 port, "port");
18564 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18565 	TOKEN_STRING_INITIALIZER
18566 		(struct cmd_config_per_port_tx_offload_result,
18567 		 config, "config");
18568 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18569 	TOKEN_NUM_INITIALIZER
18570 		(struct cmd_config_per_port_tx_offload_result,
18571 		 port_id, UINT16);
18572 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18573 	TOKEN_STRING_INITIALIZER
18574 		(struct cmd_config_per_port_tx_offload_result,
18575 		 tx_offload, "tx_offload");
18576 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18577 	TOKEN_STRING_INITIALIZER
18578 		(struct cmd_config_per_port_tx_offload_result,
18579 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18580 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18581 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18582 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18583 			  "mt_lockfree#multi_segs#mbuf_fast_free#security");
18584 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18585 	TOKEN_STRING_INITIALIZER
18586 		(struct cmd_config_per_port_tx_offload_result,
18587 		 on_off, "on#off");
18588 
18589 static uint64_t
18590 search_tx_offload(const char *name)
18591 {
18592 	uint64_t single_offload;
18593 	const char *single_name;
18594 	int found = 0;
18595 	unsigned int bit;
18596 
18597 	single_offload = 1;
18598 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18599 		single_name = rte_eth_dev_tx_offload_name(single_offload);
18600 		if (single_name == NULL)
18601 			break;
18602 		if (!strcasecmp(single_name, name)) {
18603 			found = 1;
18604 			break;
18605 		} else if (!strcasecmp(single_name, "UNKNOWN"))
18606 			break;
18607 		single_offload <<= 1;
18608 	}
18609 
18610 	if (found)
18611 		return single_offload;
18612 
18613 	return 0;
18614 }
18615 
18616 static void
18617 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18618 				__attribute__((unused)) struct cmdline *cl,
18619 				__attribute__((unused)) void *data)
18620 {
18621 	struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18622 	portid_t port_id = res->port_id;
18623 	struct rte_eth_dev_info dev_info;
18624 	struct rte_port *port = &ports[port_id];
18625 	uint64_t single_offload;
18626 	uint16_t nb_tx_queues;
18627 	int q;
18628 	int ret;
18629 
18630 	if (port->port_status != RTE_PORT_STOPPED) {
18631 		printf("Error: Can't config offload when Port %d "
18632 		       "is not stopped\n", port_id);
18633 		return;
18634 	}
18635 
18636 	single_offload = search_tx_offload(res->offload);
18637 	if (single_offload == 0) {
18638 		printf("Unknown offload name: %s\n", res->offload);
18639 		return;
18640 	}
18641 
18642 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18643 	if (ret != 0)
18644 		return;
18645 
18646 	nb_tx_queues = dev_info.nb_tx_queues;
18647 	if (!strcmp(res->on_off, "on")) {
18648 		port->dev_conf.txmode.offloads |= single_offload;
18649 		for (q = 0; q < nb_tx_queues; q++)
18650 			port->tx_conf[q].offloads |= single_offload;
18651 	} else {
18652 		port->dev_conf.txmode.offloads &= ~single_offload;
18653 		for (q = 0; q < nb_tx_queues; q++)
18654 			port->tx_conf[q].offloads &= ~single_offload;
18655 	}
18656 
18657 	cmd_reconfig_device_queue(port_id, 1, 1);
18658 }
18659 
18660 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18661 	.f = cmd_config_per_port_tx_offload_parsed,
18662 	.data = NULL,
18663 	.help_str = "port config <port_id> tx_offload "
18664 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18665 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18666 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18667 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18668 		    "mt_lockfree|multi_segs|mbuf_fast_free|security on|off",
18669 	.tokens = {
18670 		(void *)&cmd_config_per_port_tx_offload_result_port,
18671 		(void *)&cmd_config_per_port_tx_offload_result_config,
18672 		(void *)&cmd_config_per_port_tx_offload_result_port_id,
18673 		(void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18674 		(void *)&cmd_config_per_port_tx_offload_result_offload,
18675 		(void *)&cmd_config_per_port_tx_offload_result_on_off,
18676 		NULL,
18677 	}
18678 };
18679 
18680 /* Enable/Disable a per queue offloading */
18681 struct cmd_config_per_queue_tx_offload_result {
18682 	cmdline_fixed_string_t port;
18683 	portid_t port_id;
18684 	cmdline_fixed_string_t txq;
18685 	uint16_t queue_id;
18686 	cmdline_fixed_string_t tx_offload;
18687 	cmdline_fixed_string_t offload;
18688 	cmdline_fixed_string_t on_off;
18689 };
18690 
18691 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18692 	TOKEN_STRING_INITIALIZER
18693 		(struct cmd_config_per_queue_tx_offload_result,
18694 		 port, "port");
18695 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18696 	TOKEN_NUM_INITIALIZER
18697 		(struct cmd_config_per_queue_tx_offload_result,
18698 		 port_id, UINT16);
18699 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18700 	TOKEN_STRING_INITIALIZER
18701 		(struct cmd_config_per_queue_tx_offload_result,
18702 		 txq, "txq");
18703 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18704 	TOKEN_NUM_INITIALIZER
18705 		(struct cmd_config_per_queue_tx_offload_result,
18706 		 queue_id, UINT16);
18707 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18708 	TOKEN_STRING_INITIALIZER
18709 		(struct cmd_config_per_queue_tx_offload_result,
18710 		 tx_offload, "tx_offload");
18711 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18712 	TOKEN_STRING_INITIALIZER
18713 		(struct cmd_config_per_queue_tx_offload_result,
18714 		 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18715 			  "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18716 			  "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18717 			  "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18718 			  "mt_lockfree#multi_segs#mbuf_fast_free#security");
18719 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18720 	TOKEN_STRING_INITIALIZER
18721 		(struct cmd_config_per_queue_tx_offload_result,
18722 		 on_off, "on#off");
18723 
18724 static void
18725 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18726 				__attribute__((unused)) struct cmdline *cl,
18727 				__attribute__((unused)) void *data)
18728 {
18729 	struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18730 	struct rte_eth_dev_info dev_info;
18731 	portid_t port_id = res->port_id;
18732 	uint16_t queue_id = res->queue_id;
18733 	struct rte_port *port = &ports[port_id];
18734 	uint64_t single_offload;
18735 	int ret;
18736 
18737 	if (port->port_status != RTE_PORT_STOPPED) {
18738 		printf("Error: Can't config offload when Port %d "
18739 		       "is not stopped\n", port_id);
18740 		return;
18741 	}
18742 
18743 	ret = eth_dev_info_get_print_err(port_id, &dev_info);
18744 	if (ret != 0)
18745 		return;
18746 
18747 	if (queue_id >= dev_info.nb_tx_queues) {
18748 		printf("Error: input queue_id should be 0 ... "
18749 		       "%d\n", dev_info.nb_tx_queues - 1);
18750 		return;
18751 	}
18752 
18753 	single_offload = search_tx_offload(res->offload);
18754 	if (single_offload == 0) {
18755 		printf("Unknown offload name: %s\n", res->offload);
18756 		return;
18757 	}
18758 
18759 	if (!strcmp(res->on_off, "on"))
18760 		port->tx_conf[queue_id].offloads |= single_offload;
18761 	else
18762 		port->tx_conf[queue_id].offloads &= ~single_offload;
18763 
18764 	cmd_reconfig_device_queue(port_id, 1, 1);
18765 }
18766 
18767 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18768 	.f = cmd_config_per_queue_tx_offload_parsed,
18769 	.data = NULL,
18770 	.help_str = "port <port_id> txq <queue_id> tx_offload "
18771 		    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18772 		    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18773 		    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18774 		    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18775 		    "mt_lockfree|multi_segs|mbuf_fast_free|security "
18776 		    "on|off",
18777 	.tokens = {
18778 		(void *)&cmd_config_per_queue_tx_offload_result_port,
18779 		(void *)&cmd_config_per_queue_tx_offload_result_port_id,
18780 		(void *)&cmd_config_per_queue_tx_offload_result_txq,
18781 		(void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18782 		(void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18783 		(void *)&cmd_config_per_queue_tx_offload_result_offload,
18784 		(void *)&cmd_config_per_queue_tx_offload_result_on_off,
18785 		NULL,
18786 	}
18787 };
18788 
18789 /* *** configure tx_metadata for specific port *** */
18790 struct cmd_config_tx_metadata_specific_result {
18791 	cmdline_fixed_string_t port;
18792 	cmdline_fixed_string_t keyword;
18793 	uint16_t port_id;
18794 	cmdline_fixed_string_t item;
18795 	uint32_t value;
18796 };
18797 
18798 static void
18799 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18800 				__attribute__((unused)) struct cmdline *cl,
18801 				__attribute__((unused)) void *data)
18802 {
18803 	struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18804 
18805 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18806 		return;
18807 	ports[res->port_id].tx_metadata = res->value;
18808 	/* Add/remove callback to insert valid metadata in every Tx packet. */
18809 	if (ports[res->port_id].tx_metadata)
18810 		add_tx_md_callback(res->port_id);
18811 	else
18812 		remove_tx_md_callback(res->port_id);
18813 	rte_flow_dynf_metadata_register();
18814 }
18815 
18816 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18817 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18818 			port, "port");
18819 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18820 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18821 			keyword, "config");
18822 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18823 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18824 			port_id, UINT16);
18825 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18826 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18827 			item, "tx_metadata");
18828 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18829 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18830 			value, UINT32);
18831 
18832 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18833 	.f = cmd_config_tx_metadata_specific_parsed,
18834 	.data = NULL,
18835 	.help_str = "port config <port_id> tx_metadata <value>",
18836 	.tokens = {
18837 		(void *)&cmd_config_tx_metadata_specific_port,
18838 		(void *)&cmd_config_tx_metadata_specific_keyword,
18839 		(void *)&cmd_config_tx_metadata_specific_id,
18840 		(void *)&cmd_config_tx_metadata_specific_item,
18841 		(void *)&cmd_config_tx_metadata_specific_value,
18842 		NULL,
18843 	},
18844 };
18845 
18846 /* *** set dynf *** */
18847 struct cmd_config_tx_dynf_specific_result {
18848 	cmdline_fixed_string_t port;
18849 	cmdline_fixed_string_t keyword;
18850 	uint16_t port_id;
18851 	cmdline_fixed_string_t item;
18852 	cmdline_fixed_string_t name;
18853 	cmdline_fixed_string_t value;
18854 };
18855 
18856 static void
18857 cmd_config_dynf_specific_parsed(void *parsed_result,
18858 				__attribute__((unused)) struct cmdline *cl,
18859 				__attribute__((unused)) void *data)
18860 {
18861 	struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18862 	struct rte_mbuf_dynflag desc_flag;
18863 	int flag;
18864 	uint64_t old_port_flags;
18865 
18866 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18867 		return;
18868 	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18869 	if (flag <= 0) {
18870 		if (strlcpy(desc_flag.name, res->name,
18871 			    RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18872 			printf("Flag name too long\n");
18873 			return;
18874 		}
18875 		desc_flag.flags = 0;
18876 		flag = rte_mbuf_dynflag_register(&desc_flag);
18877 		if (flag < 0) {
18878 			printf("Can't register flag\n");
18879 			return;
18880 		}
18881 		strcpy(dynf_names[flag], desc_flag.name);
18882 	}
18883 	old_port_flags = ports[res->port_id].mbuf_dynf;
18884 	if (!strcmp(res->value, "set")) {
18885 		ports[res->port_id].mbuf_dynf |= 1UL << flag;
18886 		if (old_port_flags == 0)
18887 			add_tx_dynf_callback(res->port_id);
18888 	} else {
18889 		ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18890 		if (ports[res->port_id].mbuf_dynf == 0)
18891 			remove_tx_dynf_callback(res->port_id);
18892 	}
18893 }
18894 
18895 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18896 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18897 			keyword, "port");
18898 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
18899 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18900 			keyword, "config");
18901 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
18902 	TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18903 			port_id, UINT16);
18904 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
18905 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18906 			item, "dynf");
18907 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
18908 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18909 			name, NULL);
18910 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
18911 	TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18912 			value, "set#clear");
18913 
18914 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
18915 	.f = cmd_config_dynf_specific_parsed,
18916 	.data = NULL,
18917 	.help_str = "port config <port id> dynf <name> set|clear",
18918 	.tokens = {
18919 		(void *)&cmd_config_tx_dynf_specific_port,
18920 		(void *)&cmd_config_tx_dynf_specific_keyword,
18921 		(void *)&cmd_config_tx_dynf_specific_port_id,
18922 		(void *)&cmd_config_tx_dynf_specific_item,
18923 		(void *)&cmd_config_tx_dynf_specific_name,
18924 		(void *)&cmd_config_tx_dynf_specific_value,
18925 		NULL,
18926 	},
18927 };
18928 
18929 /* *** display tx_metadata per port configuration *** */
18930 struct cmd_show_tx_metadata_result {
18931 	cmdline_fixed_string_t cmd_show;
18932 	cmdline_fixed_string_t cmd_port;
18933 	cmdline_fixed_string_t cmd_keyword;
18934 	portid_t cmd_pid;
18935 };
18936 
18937 static void
18938 cmd_show_tx_metadata_parsed(void *parsed_result,
18939 		__attribute__((unused)) struct cmdline *cl,
18940 		__attribute__((unused)) void *data)
18941 {
18942 	struct cmd_show_tx_metadata_result *res = parsed_result;
18943 
18944 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18945 		printf("invalid port id %u\n", res->cmd_pid);
18946 		return;
18947 	}
18948 	if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18949 		printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18950 		       ports[res->cmd_pid].tx_metadata);
18951 	}
18952 }
18953 
18954 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18955 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18956 			cmd_show, "show");
18957 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18958 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18959 			cmd_port, "port");
18960 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18961 	TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18962 			cmd_pid, UINT16);
18963 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18964 	TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18965 			cmd_keyword, "tx_metadata");
18966 
18967 cmdline_parse_inst_t cmd_show_tx_metadata = {
18968 	.f = cmd_show_tx_metadata_parsed,
18969 	.data = NULL,
18970 	.help_str = "show port <port_id> tx_metadata",
18971 	.tokens = {
18972 		(void *)&cmd_show_tx_metadata_show,
18973 		(void *)&cmd_show_tx_metadata_port,
18974 		(void *)&cmd_show_tx_metadata_pid,
18975 		(void *)&cmd_show_tx_metadata_keyword,
18976 		NULL,
18977 	},
18978 };
18979 
18980 /* show port supported ptypes */
18981 
18982 /* Common result structure for show port ptypes */
18983 struct cmd_show_port_supported_ptypes_result {
18984 	cmdline_fixed_string_t show;
18985 	cmdline_fixed_string_t port;
18986 	portid_t port_id;
18987 	cmdline_fixed_string_t ptypes;
18988 };
18989 
18990 /* Common CLI fields for show port ptypes */
18991 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
18992 	TOKEN_STRING_INITIALIZER
18993 		(struct cmd_show_port_supported_ptypes_result,
18994 		 show, "show");
18995 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
18996 	TOKEN_STRING_INITIALIZER
18997 		(struct cmd_show_port_supported_ptypes_result,
18998 		 port, "port");
18999 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19000 	TOKEN_NUM_INITIALIZER
19001 		(struct cmd_show_port_supported_ptypes_result,
19002 		 port_id, UINT16);
19003 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19004 	TOKEN_STRING_INITIALIZER
19005 		(struct cmd_show_port_supported_ptypes_result,
19006 		 ptypes, "ptypes");
19007 
19008 static void
19009 cmd_show_port_supported_ptypes_parsed(
19010 	void *parsed_result,
19011 	__attribute__((unused)) struct cmdline *cl,
19012 	__attribute__((unused)) void *data)
19013 {
19014 #define RSVD_PTYPE_MASK       0xf0000000
19015 #define MAX_PTYPES_PER_LAYER  16
19016 #define LTYPE_NAMESIZE        32
19017 #define PTYPE_NAMESIZE        256
19018 	struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19019 	char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19020 	uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19021 	uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19022 	uint16_t port_id = res->port_id;
19023 	int ret, i;
19024 
19025 	ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19026 	if (ret < 0)
19027 		return;
19028 
19029 	while (ptype_mask != RSVD_PTYPE_MASK) {
19030 
19031 		switch (ptype_mask) {
19032 		case RTE_PTYPE_L2_MASK:
19033 			strlcpy(ltype, "L2", sizeof(ltype));
19034 			break;
19035 		case RTE_PTYPE_L3_MASK:
19036 			strlcpy(ltype, "L3", sizeof(ltype));
19037 			break;
19038 		case RTE_PTYPE_L4_MASK:
19039 			strlcpy(ltype, "L4", sizeof(ltype));
19040 			break;
19041 		case RTE_PTYPE_TUNNEL_MASK:
19042 			strlcpy(ltype, "Tunnel", sizeof(ltype));
19043 			break;
19044 		case RTE_PTYPE_INNER_L2_MASK:
19045 			strlcpy(ltype, "Inner L2", sizeof(ltype));
19046 			break;
19047 		case RTE_PTYPE_INNER_L3_MASK:
19048 			strlcpy(ltype, "Inner L3", sizeof(ltype));
19049 			break;
19050 		case RTE_PTYPE_INNER_L4_MASK:
19051 			strlcpy(ltype, "Inner L4", sizeof(ltype));
19052 			break;
19053 		default:
19054 			return;
19055 		}
19056 
19057 		ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19058 						       ptype_mask, ptypes,
19059 						       MAX_PTYPES_PER_LAYER);
19060 
19061 		if (ret > 0)
19062 			printf("Supported %s ptypes:\n", ltype);
19063 		else
19064 			printf("%s ptypes unsupported\n", ltype);
19065 
19066 		for (i = 0; i < ret; ++i) {
19067 			rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19068 			printf("%s\n", buf);
19069 		}
19070 
19071 		ptype_mask <<= 4;
19072 	}
19073 }
19074 
19075 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19076 	.f = cmd_show_port_supported_ptypes_parsed,
19077 	.data = NULL,
19078 	.help_str = "show port <port_id> ptypes",
19079 	.tokens = {
19080 		(void *)&cmd_show_port_supported_ptypes_show,
19081 		(void *)&cmd_show_port_supported_ptypes_port,
19082 		(void *)&cmd_show_port_supported_ptypes_port_id,
19083 		(void *)&cmd_show_port_supported_ptypes_ptypes,
19084 		NULL,
19085 	},
19086 };
19087 
19088 /* *** display rx/tx descriptor status *** */
19089 struct cmd_show_rx_tx_desc_status_result {
19090 	cmdline_fixed_string_t cmd_show;
19091 	cmdline_fixed_string_t cmd_port;
19092 	cmdline_fixed_string_t cmd_keyword;
19093 	cmdline_fixed_string_t cmd_desc;
19094 	cmdline_fixed_string_t cmd_status;
19095 	portid_t cmd_pid;
19096 	portid_t cmd_qid;
19097 	portid_t cmd_did;
19098 };
19099 
19100 static void
19101 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19102 		__attribute__((unused)) struct cmdline *cl,
19103 		__attribute__((unused)) void *data)
19104 {
19105 	struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19106 	int rc;
19107 
19108 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19109 		printf("invalid port id %u\n", res->cmd_pid);
19110 		return;
19111 	}
19112 
19113 	if (!strcmp(res->cmd_keyword, "rxq")) {
19114 		rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19115 					     res->cmd_did);
19116 		if (rc < 0) {
19117 			printf("Invalid queueid = %d\n", res->cmd_qid);
19118 			return;
19119 		}
19120 		if (rc == RTE_ETH_RX_DESC_AVAIL)
19121 			printf("Desc status = AVAILABLE\n");
19122 		else if (rc == RTE_ETH_RX_DESC_DONE)
19123 			printf("Desc status = DONE\n");
19124 		else
19125 			printf("Desc status = UNAVAILABLE\n");
19126 	} else if (!strcmp(res->cmd_keyword, "txq")) {
19127 		rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19128 					     res->cmd_did);
19129 		if (rc < 0) {
19130 			printf("Invalid queueid = %d\n", res->cmd_qid);
19131 			return;
19132 		}
19133 		if (rc == RTE_ETH_TX_DESC_FULL)
19134 			printf("Desc status = FULL\n");
19135 		else if (rc == RTE_ETH_TX_DESC_DONE)
19136 			printf("Desc status = DONE\n");
19137 		else
19138 			printf("Desc status = UNAVAILABLE\n");
19139 	}
19140 }
19141 
19142 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19143 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19144 			cmd_show, "show");
19145 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19146 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19147 			cmd_port, "port");
19148 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19149 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19150 			cmd_pid, UINT16);
19151 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19152 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19153 			cmd_keyword, "rxq#txq");
19154 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19155 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19156 			cmd_qid, UINT16);
19157 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19158 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19159 			cmd_desc, "desc");
19160 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19161 	TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19162 			cmd_did, UINT16);
19163 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19164 	TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19165 			cmd_status, "status");
19166 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19167 	.f = cmd_show_rx_tx_desc_status_parsed,
19168 	.data = NULL,
19169 	.help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19170 		"status",
19171 	.tokens = {
19172 		(void *)&cmd_show_rx_tx_desc_status_show,
19173 		(void *)&cmd_show_rx_tx_desc_status_port,
19174 		(void *)&cmd_show_rx_tx_desc_status_pid,
19175 		(void *)&cmd_show_rx_tx_desc_status_keyword,
19176 		(void *)&cmd_show_rx_tx_desc_status_qid,
19177 		(void *)&cmd_show_rx_tx_desc_status_desc,
19178 		(void *)&cmd_show_rx_tx_desc_status_did,
19179 		(void *)&cmd_show_rx_tx_desc_status_status,
19180 		NULL,
19181 	},
19182 };
19183 
19184 /* Common result structure for set port ptypes */
19185 struct cmd_set_port_ptypes_result {
19186 	cmdline_fixed_string_t set;
19187 	cmdline_fixed_string_t port;
19188 	portid_t port_id;
19189 	cmdline_fixed_string_t ptype_mask;
19190 	uint32_t mask;
19191 };
19192 
19193 /* Common CLI fields for set port ptypes */
19194 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19195 	TOKEN_STRING_INITIALIZER
19196 		(struct cmd_set_port_ptypes_result,
19197 		 set, "set");
19198 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19199 	TOKEN_STRING_INITIALIZER
19200 		(struct cmd_set_port_ptypes_result,
19201 		 port, "port");
19202 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19203 	TOKEN_NUM_INITIALIZER
19204 		(struct cmd_set_port_ptypes_result,
19205 		 port_id, UINT16);
19206 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19207 	TOKEN_STRING_INITIALIZER
19208 		(struct cmd_set_port_ptypes_result,
19209 		 ptype_mask, "ptype_mask");
19210 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19211 	TOKEN_NUM_INITIALIZER
19212 		(struct cmd_set_port_ptypes_result,
19213 		 mask, UINT32);
19214 
19215 static void
19216 cmd_set_port_ptypes_parsed(
19217 	void *parsed_result,
19218 	__attribute__((unused)) struct cmdline *cl,
19219 	__attribute__((unused)) void *data)
19220 {
19221 	struct cmd_set_port_ptypes_result *res = parsed_result;
19222 #define PTYPE_NAMESIZE        256
19223 	char ptype_name[PTYPE_NAMESIZE];
19224 	uint16_t port_id = res->port_id;
19225 	uint32_t ptype_mask = res->mask;
19226 	int ret, i;
19227 
19228 	ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19229 					       NULL, 0);
19230 	if (ret <= 0) {
19231 		printf("Port %d doesn't support any ptypes.\n", port_id);
19232 		return;
19233 	}
19234 
19235 	uint32_t ptypes[ret];
19236 
19237 	ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19238 	if (ret < 0) {
19239 		printf("Unable to set requested ptypes for Port %d\n", port_id);
19240 		return;
19241 	}
19242 
19243 	printf("Successfully set following ptypes for Port %d\n", port_id);
19244 	for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19245 		rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19246 		printf("%s\n", ptype_name);
19247 	}
19248 
19249 	clear_ptypes = false;
19250 }
19251 
19252 cmdline_parse_inst_t cmd_set_port_ptypes = {
19253 	.f = cmd_set_port_ptypes_parsed,
19254 	.data = NULL,
19255 	.help_str = "set port <port_id> ptype_mask <mask>",
19256 	.tokens = {
19257 		(void *)&cmd_set_port_ptypes_set,
19258 		(void *)&cmd_set_port_ptypes_port,
19259 		(void *)&cmd_set_port_ptypes_port_id,
19260 		(void *)&cmd_set_port_ptypes_mask_str,
19261 		(void *)&cmd_set_port_ptypes_mask_u32,
19262 		NULL,
19263 	},
19264 };
19265 
19266 /* *** display mac addresses added to a port *** */
19267 struct cmd_showport_macs_result {
19268 	cmdline_fixed_string_t cmd_show;
19269 	cmdline_fixed_string_t cmd_port;
19270 	cmdline_fixed_string_t cmd_keyword;
19271 	portid_t cmd_pid;
19272 };
19273 
19274 static void
19275 cmd_showport_macs_parsed(void *parsed_result,
19276 		__attribute__((unused)) struct cmdline *cl,
19277 		__attribute__((unused)) void *data)
19278 {
19279 	struct cmd_showport_macs_result *res = parsed_result;
19280 
19281 	if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19282 		return;
19283 
19284 	if (!strcmp(res->cmd_keyword, "macs"))
19285 		show_macs(res->cmd_pid);
19286 	else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19287 		show_mcast_macs(res->cmd_pid);
19288 }
19289 
19290 cmdline_parse_token_string_t cmd_showport_macs_show =
19291 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19292 			cmd_show, "show");
19293 cmdline_parse_token_string_t cmd_showport_macs_port =
19294 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19295 			cmd_port, "port");
19296 cmdline_parse_token_num_t cmd_showport_macs_pid =
19297 	TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19298 			cmd_pid, UINT16);
19299 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19300 	TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19301 			cmd_keyword, "macs#mcast_macs");
19302 
19303 cmdline_parse_inst_t cmd_showport_macs = {
19304 	.f = cmd_showport_macs_parsed,
19305 	.data = NULL,
19306 	.help_str = "show port <port_id> macs|mcast_macs",
19307 	.tokens = {
19308 		(void *)&cmd_showport_macs_show,
19309 		(void *)&cmd_showport_macs_port,
19310 		(void *)&cmd_showport_macs_pid,
19311 		(void *)&cmd_showport_macs_keyword,
19312 		NULL,
19313 	},
19314 };
19315 
19316 /* ******************************************************************************** */
19317 
19318 /* list of instructions */
19319 cmdline_parse_ctx_t main_ctx[] = {
19320 	(cmdline_parse_inst_t *)&cmd_help_brief,
19321 	(cmdline_parse_inst_t *)&cmd_help_long,
19322 	(cmdline_parse_inst_t *)&cmd_quit,
19323 	(cmdline_parse_inst_t *)&cmd_load_from_file,
19324 	(cmdline_parse_inst_t *)&cmd_showport,
19325 	(cmdline_parse_inst_t *)&cmd_showqueue,
19326 	(cmdline_parse_inst_t *)&cmd_showportall,
19327 	(cmdline_parse_inst_t *)&cmd_showdevice,
19328 	(cmdline_parse_inst_t *)&cmd_showcfg,
19329 	(cmdline_parse_inst_t *)&cmd_showfwdall,
19330 	(cmdline_parse_inst_t *)&cmd_start,
19331 	(cmdline_parse_inst_t *)&cmd_start_tx_first,
19332 	(cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19333 	(cmdline_parse_inst_t *)&cmd_set_link_up,
19334 	(cmdline_parse_inst_t *)&cmd_set_link_down,
19335 	(cmdline_parse_inst_t *)&cmd_reset,
19336 	(cmdline_parse_inst_t *)&cmd_set_numbers,
19337 	(cmdline_parse_inst_t *)&cmd_set_log,
19338 	(cmdline_parse_inst_t *)&cmd_set_txpkts,
19339 	(cmdline_parse_inst_t *)&cmd_set_txsplit,
19340 	(cmdline_parse_inst_t *)&cmd_set_fwd_list,
19341 	(cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19342 	(cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19343 	(cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19344 	(cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19345 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19346 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19347 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19348 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19349 	(cmdline_parse_inst_t *)&cmd_set_flush_rx,
19350 	(cmdline_parse_inst_t *)&cmd_set_link_check,
19351 	(cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19352 	(cmdline_parse_inst_t *)&cmd_set_bypass_event,
19353 	(cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19354 	(cmdline_parse_inst_t *)&cmd_show_bypass_config,
19355 #ifdef RTE_LIBRTE_PMD_BOND
19356 	(cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19357 	(cmdline_parse_inst_t *) &cmd_show_bonding_config,
19358 	(cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19359 	(cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19360 	(cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19361 	(cmdline_parse_inst_t *) &cmd_create_bonded_device,
19362 	(cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19363 	(cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19364 	(cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19365 	(cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19366 	(cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19367 #endif
19368 	(cmdline_parse_inst_t *)&cmd_vlan_offload,
19369 	(cmdline_parse_inst_t *)&cmd_vlan_tpid,
19370 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19371 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19372 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19373 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19374 	(cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19375 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19376 	(cmdline_parse_inst_t *)&cmd_csum_set,
19377 	(cmdline_parse_inst_t *)&cmd_csum_show,
19378 	(cmdline_parse_inst_t *)&cmd_csum_tunnel,
19379 	(cmdline_parse_inst_t *)&cmd_tso_set,
19380 	(cmdline_parse_inst_t *)&cmd_tso_show,
19381 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19382 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19383 	(cmdline_parse_inst_t *)&cmd_gro_enable,
19384 	(cmdline_parse_inst_t *)&cmd_gro_flush,
19385 	(cmdline_parse_inst_t *)&cmd_gro_show,
19386 	(cmdline_parse_inst_t *)&cmd_gso_enable,
19387 	(cmdline_parse_inst_t *)&cmd_gso_size,
19388 	(cmdline_parse_inst_t *)&cmd_gso_show,
19389 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19390 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19391 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19392 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19393 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19394 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19395 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19396 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19397 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19398 	(cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19399 	(cmdline_parse_inst_t *)&cmd_config_dcb,
19400 	(cmdline_parse_inst_t *)&cmd_read_reg,
19401 	(cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19402 	(cmdline_parse_inst_t *)&cmd_read_reg_bit,
19403 	(cmdline_parse_inst_t *)&cmd_write_reg,
19404 	(cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19405 	(cmdline_parse_inst_t *)&cmd_write_reg_bit,
19406 	(cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19407 	(cmdline_parse_inst_t *)&cmd_stop,
19408 	(cmdline_parse_inst_t *)&cmd_mac_addr,
19409 	(cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19410 	(cmdline_parse_inst_t *)&cmd_set_qmap,
19411 	(cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19412 	(cmdline_parse_inst_t *)&cmd_operate_port,
19413 	(cmdline_parse_inst_t *)&cmd_operate_specific_port,
19414 	(cmdline_parse_inst_t *)&cmd_operate_attach_port,
19415 	(cmdline_parse_inst_t *)&cmd_operate_detach_port,
19416 	(cmdline_parse_inst_t *)&cmd_operate_detach_device,
19417 	(cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19418 	(cmdline_parse_inst_t *)&cmd_config_speed_all,
19419 	(cmdline_parse_inst_t *)&cmd_config_speed_specific,
19420 	(cmdline_parse_inst_t *)&cmd_config_loopback_all,
19421 	(cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19422 	(cmdline_parse_inst_t *)&cmd_config_rx_tx,
19423 	(cmdline_parse_inst_t *)&cmd_config_mtu,
19424 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19425 	(cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19426 	(cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19427 	(cmdline_parse_inst_t *)&cmd_config_rss,
19428 	(cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19429 	(cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19430 	(cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19431 	(cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19432 	(cmdline_parse_inst_t *)&cmd_config_rss_reta,
19433 	(cmdline_parse_inst_t *)&cmd_showport_reta,
19434 	(cmdline_parse_inst_t *)&cmd_showport_macs,
19435 	(cmdline_parse_inst_t *)&cmd_config_burst,
19436 	(cmdline_parse_inst_t *)&cmd_config_thresh,
19437 	(cmdline_parse_inst_t *)&cmd_config_threshold,
19438 	(cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19439 	(cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19440 	(cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19441 	(cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19442 	(cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19443 	(cmdline_parse_inst_t *)&cmd_tunnel_filter,
19444 	(cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19445 	(cmdline_parse_inst_t *)&cmd_global_config,
19446 	(cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19447 	(cmdline_parse_inst_t *)&cmd_set_mirror_link,
19448 	(cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19449 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19450 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19451 	(cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19452 	(cmdline_parse_inst_t *)&cmd_dump,
19453 	(cmdline_parse_inst_t *)&cmd_dump_one,
19454 	(cmdline_parse_inst_t *)&cmd_ethertype_filter,
19455 	(cmdline_parse_inst_t *)&cmd_syn_filter,
19456 	(cmdline_parse_inst_t *)&cmd_2tuple_filter,
19457 	(cmdline_parse_inst_t *)&cmd_5tuple_filter,
19458 	(cmdline_parse_inst_t *)&cmd_flex_filter,
19459 	(cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19460 	(cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19461 	(cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19462 	(cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19463 	(cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19464 	(cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19465 	(cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19466 	(cmdline_parse_inst_t *)&cmd_flush_flow_director,
19467 	(cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19468 	(cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19469 	(cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19470 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19471 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19472 	(cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19473 	(cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19474 	(cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19475 	(cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19476 	(cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19477 	(cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19478 	(cmdline_parse_inst_t *)&cmd_flow,
19479 	(cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19480 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19481 	(cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19482 	(cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19483 	(cmdline_parse_inst_t *)&cmd_create_port_meter,
19484 	(cmdline_parse_inst_t *)&cmd_enable_port_meter,
19485 	(cmdline_parse_inst_t *)&cmd_disable_port_meter,
19486 	(cmdline_parse_inst_t *)&cmd_del_port_meter,
19487 	(cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19488 	(cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19489 	(cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19490 	(cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19491 	(cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19492 	(cmdline_parse_inst_t *)&cmd_mcast_addr,
19493 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19494 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19495 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19496 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19497 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19498 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19499 	(cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19500 	(cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19501 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19502 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19503 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19504 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19505 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19506 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19507 	(cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19508 	(cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19509 	(cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19510 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19511 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19512 	(cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19513 	(cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19514 	(cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19515 	(cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19516 	(cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19517 	(cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19518 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19519 	(cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19520 	(cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19521 	(cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19522 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19523 	(cmdline_parse_inst_t *)&cmd_vf_max_bw,
19524 	(cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19525 	(cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19526 	(cmdline_parse_inst_t *)&cmd_strict_link_prio,
19527 	(cmdline_parse_inst_t *)&cmd_tc_min_bw,
19528 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19529 	(cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19530 #endif
19531 	(cmdline_parse_inst_t *)&cmd_set_vxlan,
19532 	(cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19533 	(cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19534 	(cmdline_parse_inst_t *)&cmd_set_nvgre,
19535 	(cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19536 	(cmdline_parse_inst_t *)&cmd_set_l2_encap,
19537 	(cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19538 	(cmdline_parse_inst_t *)&cmd_set_l2_decap,
19539 	(cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19540 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19541 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19542 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19543 	(cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19544 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19545 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19546 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19547 	(cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19548 	(cmdline_parse_inst_t *)&cmd_ddp_add,
19549 	(cmdline_parse_inst_t *)&cmd_ddp_del,
19550 	(cmdline_parse_inst_t *)&cmd_ddp_get_list,
19551 	(cmdline_parse_inst_t *)&cmd_ddp_get_info,
19552 	(cmdline_parse_inst_t *)&cmd_cfg_input_set,
19553 	(cmdline_parse_inst_t *)&cmd_clear_input_set,
19554 	(cmdline_parse_inst_t *)&cmd_show_vf_stats,
19555 	(cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19556 	(cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19557 	(cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19558 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19559 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19560 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19561 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19562 
19563 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19564 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19565 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19566 	(cmdline_parse_inst_t *)&cmd_queue_region,
19567 	(cmdline_parse_inst_t *)&cmd_region_flowtype,
19568 	(cmdline_parse_inst_t *)&cmd_user_priority_region,
19569 	(cmdline_parse_inst_t *)&cmd_flush_queue_region,
19570 	(cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19571 	(cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19572 	(cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19573 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19574 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19575 	(cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19576 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19577 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19578 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19579 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19580 	(cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19581 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19582 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19583 	(cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19584 	(cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19585 	(cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19586 	(cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19587 	(cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19588 	(cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19589 	(cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19590 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19591 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19592 	(cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19593 	(cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19594 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19595 	(cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19596 	(cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19597 	(cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19598 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19599 	(cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19600 	(cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19601 	(cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19602 #ifdef RTE_LIBRTE_BPF
19603 	(cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19604 	(cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19605 #endif
19606 	(cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19607 	(cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19608 	(cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19609 	(cmdline_parse_inst_t *)&cmd_set_raw,
19610 	(cmdline_parse_inst_t *)&cmd_show_set_raw,
19611 	(cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19612 	(cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19613 	NULL,
19614 };
19615 
19616 /* read cmdline commands from file */
19617 void
19618 cmdline_read_from_file(const char *filename)
19619 {
19620 	struct cmdline *cl;
19621 
19622 	cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19623 	if (cl == NULL) {
19624 		printf("Failed to create file based cmdline context: %s\n",
19625 		       filename);
19626 		return;
19627 	}
19628 
19629 	cmdline_interact(cl);
19630 	cmdline_quit(cl);
19631 
19632 	cmdline_free(cl);
19633 
19634 	printf("Read CLI commands from %s\n", filename);
19635 }
19636 
19637 /* prompt function, called from main on MASTER lcore */
19638 void
19639 prompt(void)
19640 {
19641 	/* initialize non-constant commands */
19642 	cmd_set_fwd_mode_init();
19643 	cmd_set_fwd_retry_mode_init();
19644 
19645 	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19646 	if (testpmd_cl == NULL)
19647 		return;
19648 	cmdline_interact(testpmd_cl);
19649 	cmdline_stdin_exit(testpmd_cl);
19650 }
19651 
19652 void
19653 prompt_exit(void)
19654 {
19655 	if (testpmd_cl != NULL)
19656 		cmdline_quit(testpmd_cl);
19657 }
19658 
19659 static void
19660 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19661 {
19662 	if (id == (portid_t)RTE_PORT_ALL) {
19663 		portid_t pid;
19664 
19665 		RTE_ETH_FOREACH_DEV(pid) {
19666 			/* check if need_reconfig has been set to 1 */
19667 			if (ports[pid].need_reconfig == 0)
19668 				ports[pid].need_reconfig = dev;
19669 			/* check if need_reconfig_queues has been set to 1 */
19670 			if (ports[pid].need_reconfig_queues == 0)
19671 				ports[pid].need_reconfig_queues = queue;
19672 		}
19673 	} else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19674 		/* check if need_reconfig has been set to 1 */
19675 		if (ports[id].need_reconfig == 0)
19676 			ports[id].need_reconfig = dev;
19677 		/* check if need_reconfig_queues has been set to 1 */
19678 		if (ports[id].need_reconfig_queues == 0)
19679 			ports[id].need_reconfig_queues = queue;
19680 	}
19681 }
19682