xref: /dpdk/app/test-pmd/cmdline.c (revision 81ef862b51dc416217ca4ac1d0bf894a0baec9cc)
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <stdarg.h>
40 #include <string.h>
41 #include <termios.h>
42 #include <unistd.h>
43 #include <inttypes.h>
44 #ifndef __linux__
45 #ifndef __FreeBSD__
46 #include <net/socket.h>
47 #else
48 #include <sys/socket.h>
49 #endif
50 #endif
51 #include <netinet/in.h>
52 
53 #include <sys/queue.h>
54 
55 #include <rte_common.h>
56 #include <rte_byteorder.h>
57 #include <rte_log.h>
58 #include <rte_debug.h>
59 #include <rte_cycles.h>
60 #include <rte_memory.h>
61 #include <rte_memzone.h>
62 #include <rte_malloc.h>
63 #include <rte_launch.h>
64 #include <rte_eal.h>
65 #include <rte_per_lcore.h>
66 #include <rte_lcore.h>
67 #include <rte_atomic.h>
68 #include <rte_branch_prediction.h>
69 #include <rte_ring.h>
70 #include <rte_mempool.h>
71 #include <rte_interrupts.h>
72 #include <rte_pci.h>
73 #include <rte_ether.h>
74 #include <rte_ethdev.h>
75 #include <rte_string_fns.h>
76 #include <rte_devargs.h>
77 #include <rte_eth_ctrl.h>
78 #include <rte_flow.h>
79 
80 #include <cmdline_rdline.h>
81 #include <cmdline_parse.h>
82 #include <cmdline_parse_num.h>
83 #include <cmdline_parse_string.h>
84 #include <cmdline_parse_ipaddr.h>
85 #include <cmdline_parse_etheraddr.h>
86 #include <cmdline_socket.h>
87 #include <cmdline.h>
88 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #endif
91 #ifdef RTE_LIBRTE_IXGBE_PMD
92 #include <rte_pmd_ixgbe.h>
93 #endif
94 #ifdef RTE_LIBRTE_I40E_PMD
95 #include <rte_pmd_i40e.h>
96 #endif
97 #include "testpmd.h"
98 
99 static struct cmdline *testpmd_cl;
100 
101 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
102 
103 /* *** Help command with introduction. *** */
104 struct cmd_help_brief_result {
105 	cmdline_fixed_string_t help;
106 };
107 
108 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
109                                   struct cmdline *cl,
110                                   __attribute__((unused)) void *data)
111 {
112 	cmdline_printf(
113 		cl,
114 		"\n"
115 		"Help is available for the following sections:\n\n"
116 		"    help control    : Start and stop forwarding.\n"
117 		"    help display    : Displaying port, stats and config "
118 		"information.\n"
119 		"    help config     : Configuration information.\n"
120 		"    help ports      : Configuring ports.\n"
121 		"    help registers  : Reading and setting port registers.\n"
122 		"    help filters    : Filters configuration help.\n"
123 		"    help all        : All of the above sections.\n\n"
124 	);
125 
126 }
127 
128 cmdline_parse_token_string_t cmd_help_brief_help =
129 	TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
130 
131 cmdline_parse_inst_t cmd_help_brief = {
132 	.f = cmd_help_brief_parsed,
133 	.data = NULL,
134 	.help_str = "help: Show help",
135 	.tokens = {
136 		(void *)&cmd_help_brief_help,
137 		NULL,
138 	},
139 };
140 
141 /* *** Help command with help sections. *** */
142 struct cmd_help_long_result {
143 	cmdline_fixed_string_t help;
144 	cmdline_fixed_string_t section;
145 };
146 
147 static void cmd_help_long_parsed(void *parsed_result,
148                                  struct cmdline *cl,
149                                  __attribute__((unused)) void *data)
150 {
151 	int show_all = 0;
152 	struct cmd_help_long_result *res = parsed_result;
153 
154 	if (!strcmp(res->section, "all"))
155 		show_all = 1;
156 
157 	if (show_all || !strcmp(res->section, "control")) {
158 
159 		cmdline_printf(
160 			cl,
161 			"\n"
162 			"Control forwarding:\n"
163 			"-------------------\n\n"
164 
165 			"start\n"
166 			"    Start packet forwarding with current configuration.\n\n"
167 
168 			"start tx_first\n"
169 			"    Start packet forwarding with current config"
170 			" after sending one burst of packets.\n\n"
171 
172 			"stop\n"
173 			"    Stop packet forwarding, and display accumulated"
174 			" statistics.\n\n"
175 
176 			"quit\n"
177 			"    Quit to prompt.\n\n"
178 		);
179 	}
180 
181 	if (show_all || !strcmp(res->section, "display")) {
182 
183 		cmdline_printf(
184 			cl,
185 			"\n"
186 			"Display:\n"
187 			"--------\n\n"
188 
189 			"show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
190 			"    Display information for port_id, or all.\n\n"
191 
192 			"show port X rss reta (size) (mask0,mask1,...)\n"
193 			"    Display the rss redirection table entry indicated"
194 			" by masks on port X. size is used to indicate the"
195 			" hardware supported reta size\n\n"
196 
197 			"show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
198 			"ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
199 			"ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
200 			"    Display the RSS hash functions and RSS hash key"
201 			" of port X\n\n"
202 
203 			"clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
204 			"    Clear information for port_id, or all.\n\n"
205 
206 			"show (rxq|txq) info (port_id) (queue_id)\n"
207 			"    Display information for configured RX/TX queue.\n\n"
208 
209 			"show config (rxtx|cores|fwd|txpkts)\n"
210 			"    Display the given configuration.\n\n"
211 
212 			"read rxd (port_id) (queue_id) (rxd_id)\n"
213 			"    Display an RX descriptor of a port RX queue.\n\n"
214 
215 			"read txd (port_id) (queue_id) (txd_id)\n"
216 			"    Display a TX descriptor of a port TX queue.\n\n"
217 
218 			"ddp get list (port_id)\n"
219 			"    Get ddp profile info list\n\n"
220 
221 			"show vf stats (port_id) (vf_id)\n"
222 			"    Display a VF's statistics.\n\n"
223 
224 			"clear vf stats (port_id) (vf_id)\n"
225 			"    Reset a VF's statistics.\n\n"
226 		);
227 	}
228 
229 	if (show_all || !strcmp(res->section, "config")) {
230 		cmdline_printf(
231 			cl,
232 			"\n"
233 			"Configuration:\n"
234 			"--------------\n"
235 			"Configuration changes only become active when"
236 			" forwarding is started/restarted.\n\n"
237 
238 			"set default\n"
239 			"    Reset forwarding to the default configuration.\n\n"
240 
241 			"set verbose (level)\n"
242 			"    Set the debug verbosity level X.\n\n"
243 
244 			"set nbport (num)\n"
245 			"    Set number of ports.\n\n"
246 
247 			"set nbcore (num)\n"
248 			"    Set number of cores.\n\n"
249 
250 			"set coremask (mask)\n"
251 			"    Set the forwarding cores hexadecimal mask.\n\n"
252 
253 			"set portmask (mask)\n"
254 			"    Set the forwarding ports hexadecimal mask.\n\n"
255 
256 			"set burst (num)\n"
257 			"    Set number of packets per burst.\n\n"
258 
259 			"set burst tx delay (microseconds) retry (num)\n"
260 			"    Set the transmit delay time and number of retries,"
261 			" effective when retry is enabled.\n\n"
262 
263 			"set txpkts (x[,y]*)\n"
264 			"    Set the length of each segment of TXONLY"
265 			" and optionally CSUM packets.\n\n"
266 
267 			"set txsplit (off|on|rand)\n"
268 			"    Set the split policy for the TX packets."
269 			" Right now only applicable for CSUM and TXONLY"
270 			" modes\n\n"
271 
272 			"set corelist (x[,y]*)\n"
273 			"    Set the list of forwarding cores.\n\n"
274 
275 			"set portlist (x[,y]*)\n"
276 			"    Set the list of forwarding ports.\n\n"
277 
278 			"set tx loopback (port_id) (on|off)\n"
279 			"    Enable or disable tx loopback.\n\n"
280 
281 #ifdef RTE_LIBRTE_IXGBE_PMD
282 			"set all queues drop (port_id) (on|off)\n"
283 			"    Set drop enable bit for all queues.\n\n"
284 
285 			"set vf split drop (port_id) (vf_id) (on|off)\n"
286 			"    Set split drop enable bit for a VF from the PF.\n\n"
287 #endif
288 
289 			"set vf mac antispoof (port_id) (vf_id) (on|off).\n"
290 			"    Set MAC antispoof for a VF from the PF.\n\n"
291 
292 #ifdef RTE_LIBRTE_IXGBE_PMD
293 			"set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
294 			"    Enable MACsec offload.\n\n"
295 
296 			"set macsec offload (port_id) off\n"
297 			"    Disable MACsec offload.\n\n"
298 
299 			"set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
300 			"    Configure MACsec secure connection (SC).\n\n"
301 
302 			"set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
303 			"    Configure MACsec secure association (SA).\n\n"
304 #endif
305 
306 			"set vf broadcast (port_id) (vf_id) (on|off)\n"
307 			"    Set VF broadcast for a VF from the PF.\n\n"
308 
309 			"vlan set strip (on|off) (port_id)\n"
310 			"    Set the VLAN strip on a port.\n\n"
311 
312 			"vlan set stripq (on|off) (port_id,queue_id)\n"
313 			"    Set the VLAN strip for a queue on a port.\n\n"
314 
315 			"set vf vlan stripq (port_id) (vf_id) (on|off)\n"
316 			"    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
317 
318 			"set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
319 			"    Set VLAN insert for a VF from the PF.\n\n"
320 
321 			"set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
322 			"    Set VLAN antispoof for a VF from the PF.\n\n"
323 
324 			"set vf vlan tag (port_id) (vf_id) (on|off)\n"
325 			"    Set VLAN tag for a VF from the PF.\n\n"
326 
327 			"set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
328 			"    Set a VF's max bandwidth(Mbps).\n\n"
329 
330 			"set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
331 			"    Set all TCs' min bandwidth(%%) on a VF.\n\n"
332 
333 			"set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
334 			"    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
335 
336 			"set tx strict-link-priority (port_id) (tc_bitmap)\n"
337 			"    Set some TCs' strict link priority mode on a physical port.\n\n"
338 
339 			"set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
340 			"    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
341 
342 			"vlan set filter (on|off) (port_id)\n"
343 			"    Set the VLAN filter on a port.\n\n"
344 
345 			"vlan set qinq (on|off) (port_id)\n"
346 			"    Set the VLAN QinQ (extended queue in queue)"
347 			" on a port.\n\n"
348 
349 			"vlan set (inner|outer) tpid (value) (port_id)\n"
350 			"    Set the VLAN TPID for Packet Filtering on"
351 			" a port\n\n"
352 
353 			"rx_vlan add (vlan_id|all) (port_id)\n"
354 			"    Add a vlan_id, or all identifiers, to the set"
355 			" of VLAN identifiers filtered by port_id.\n\n"
356 
357 			"rx_vlan rm (vlan_id|all) (port_id)\n"
358 			"    Remove a vlan_id, or all identifiers, from the set"
359 			" of VLAN identifiers filtered by port_id.\n\n"
360 
361 			"rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
362 			"    Add a vlan_id, to the set of VLAN identifiers"
363 			"filtered for VF(s) from port_id.\n\n"
364 
365 			"rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
366 			"    Remove a vlan_id, to the set of VLAN identifiers"
367 			"filtered for VF(s) from port_id.\n\n"
368 
369 			"tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
370 			"(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
371 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
372 			"   add a tunnel filter of a port.\n\n"
373 
374 			"tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
375 			"(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
376 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
377 			"   remove a tunnel filter of a port.\n\n"
378 
379 			"rx_vxlan_port add (udp_port) (port_id)\n"
380 			"    Add an UDP port for VXLAN packet filter on a port\n\n"
381 
382 			"rx_vxlan_port rm (udp_port) (port_id)\n"
383 			"    Remove an UDP port for VXLAN packet filter on a port\n\n"
384 
385 			"tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
386 			"    Set hardware insertion of VLAN IDs (single or double VLAN "
387 			"depends on the number of VLAN IDs) in packets sent on a port.\n\n"
388 
389 			"tx_vlan set pvid port_id vlan_id (on|off)\n"
390 			"    Set port based TX VLAN insertion.\n\n"
391 
392 			"tx_vlan reset (port_id)\n"
393 			"    Disable hardware insertion of a VLAN header in"
394 			" packets sent on a port.\n\n"
395 
396 			"csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
397 			"    Select hardware or software calculation of the"
398 			" checksum when transmitting a packet using the"
399 			" csum forward engine.\n"
400 			"    ip|udp|tcp|sctp always concern the inner layer.\n"
401 			"    outer-ip concerns the outer IP layer in"
402 			" case the packet is recognized as a tunnel packet by"
403 			" the forward engine (vxlan, gre and ipip are supported)\n"
404 			"    Please check the NIC datasheet for HW limits.\n\n"
405 
406 			"csum parse-tunnel (on|off) (tx_port_id)\n"
407 			"    If disabled, treat tunnel packets as non-tunneled"
408 			" packets (treat inner headers as payload). The port\n"
409 			"    argument is the port used for TX in csum forward"
410 			" engine.\n\n"
411 
412 			"csum show (port_id)\n"
413 			"    Display tx checksum offload configuration\n\n"
414 
415 			"tso set (segsize) (portid)\n"
416 			"    Enable TCP Segmentation Offload in csum forward"
417 			" engine.\n"
418 			"    Please check the NIC datasheet for HW limits.\n\n"
419 
420 			"tso show (portid)"
421 			"    Display the status of TCP Segmentation Offload.\n\n"
422 
423 			"set fwd (%s)\n"
424 			"    Set packet forwarding mode.\n\n"
425 
426 			"mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
427 			"    Add a MAC address on port_id.\n\n"
428 
429 			"mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
430 			"    Remove a MAC address from port_id.\n\n"
431 
432 			"mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
433 			"    Set the default MAC address for port_id.\n\n"
434 
435 			"mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
436 			"    Add a MAC address for a VF on the port.\n\n"
437 
438 			"set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
439 			"    Set the MAC address for a VF from the PF.\n\n"
440 
441 			"set port (port_id) uta (mac_address|all) (on|off)\n"
442 			"    Add/Remove a or all unicast hash filter(s)"
443 			"from port X.\n\n"
444 
445 			"set promisc (port_id|all) (on|off)\n"
446 			"    Set the promiscuous mode on port_id, or all.\n\n"
447 
448 			"set allmulti (port_id|all) (on|off)\n"
449 			"    Set the allmulti mode on port_id, or all.\n\n"
450 
451 			"set vf promisc (port_id) (vf_id) (on|off)\n"
452 			"    Set unicast promiscuous mode for a VF from the PF.\n\n"
453 
454 			"set vf allmulti (port_id) (vf_id) (on|off)\n"
455 			"    Set multicast promiscuous mode for a VF from the PF.\n\n"
456 
457 			"set flow_ctrl rx (on|off) tx (on|off) (high_water)"
458 			" (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
459 			" (on|off) autoneg (on|off) (port_id)\n"
460 			"set flow_ctrl rx (on|off) (portid)\n"
461 			"set flow_ctrl tx (on|off) (portid)\n"
462 			"set flow_ctrl high_water (high_water) (portid)\n"
463 			"set flow_ctrl low_water (low_water) (portid)\n"
464 			"set flow_ctrl pause_time (pause_time) (portid)\n"
465 			"set flow_ctrl send_xon (send_xon) (portid)\n"
466 			"set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
467 			"set flow_ctrl autoneg (on|off) (port_id)\n"
468 			"    Set the link flow control parameter on a port.\n\n"
469 
470 			"set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
471 			" (low_water) (pause_time) (priority) (port_id)\n"
472 			"    Set the priority flow control parameter on a"
473 			" port.\n\n"
474 
475 			"set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
476 			"    Set statistics mapping (qmapping 0..15) for RX/TX"
477 			" queue on port.\n"
478 			"    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
479 			" on port 0 to mapping 5.\n\n"
480 
481 			"set port (port_id) vf (vf_id) rx|tx on|off\n"
482 			"    Enable/Disable a VF receive/tranmit from a port\n\n"
483 
484 			"set port (port_id) vf (vf_id) (mac_addr)"
485 			" (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
486 			"   Add/Remove unicast or multicast MAC addr filter"
487 			" for a VF.\n\n"
488 
489 			"set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
490 			"|MPE) (on|off)\n"
491 			"    AUPE:accepts untagged VLAN;"
492 			"ROPE:accept unicast hash\n\n"
493 			"    BAM:accepts broadcast packets;"
494 			"MPE:accepts all multicast packets\n\n"
495 			"    Enable/Disable a VF receive mode of a port\n\n"
496 
497 			"set port (port_id) queue (queue_id) rate (rate_num)\n"
498 			"    Set rate limit for a queue of a port\n\n"
499 
500 			"set port (port_id) vf (vf_id) rate (rate_num) "
501 			"queue_mask (queue_mask_value)\n"
502 			"    Set rate limit for queues in VF of a port\n\n"
503 
504 			"set port (port_id) mirror-rule (rule_id)"
505 			" (pool-mirror-up|pool-mirror-down|vlan-mirror)"
506 			" (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
507 			"   Set pool or vlan type mirror rule on a port.\n"
508 			"   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
509 			" dst-pool 0 on' enable mirror traffic with vlan 0,1"
510 			" to pool 0.\n\n"
511 
512 			"set port (port_id) mirror-rule (rule_id)"
513 			" (uplink-mirror|downlink-mirror) dst-pool"
514 			" (pool_id) (on|off)\n"
515 			"   Set uplink or downlink type mirror rule on a port.\n"
516 			"   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
517 			" 0 on' enable mirror income traffic to pool 0.\n\n"
518 
519 			"reset port (port_id) mirror-rule (rule_id)\n"
520 			"   Reset a mirror rule.\n\n"
521 
522 			"set flush_rx (on|off)\n"
523 			"   Flush (default) or don't flush RX streams before"
524 			" forwarding. Mainly used with PCAP drivers.\n\n"
525 
526 			#ifdef RTE_NIC_BYPASS
527 			"set bypass mode (normal|bypass|isolate) (port_id)\n"
528 			"   Set the bypass mode for the lowest port on bypass enabled"
529 			" NIC.\n\n"
530 
531 			"set bypass event (timeout|os_on|os_off|power_on|power_off) "
532 			"mode (normal|bypass|isolate) (port_id)\n"
533 			"   Set the event required to initiate specified bypass mode for"
534 			" the lowest port on a bypass enabled NIC where:\n"
535 			"       timeout   = enable bypass after watchdog timeout.\n"
536 			"       os_on     = enable bypass when OS/board is powered on.\n"
537 			"       os_off    = enable bypass when OS/board is powered off.\n"
538 			"       power_on  = enable bypass when power supply is turned on.\n"
539 			"       power_off = enable bypass when power supply is turned off."
540 			"\n\n"
541 
542 			"set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
543 			"   Set the bypass watchdog timeout to 'n' seconds"
544 			" where 0 = instant.\n\n"
545 
546 			"show bypass config (port_id)\n"
547 			"   Show the bypass configuration for a bypass enabled NIC"
548 			" using the lowest port on the NIC.\n\n"
549 #endif
550 #ifdef RTE_LIBRTE_PMD_BOND
551 			"create bonded device (mode) (socket)\n"
552 			"	Create a new bonded device with specific bonding mode and socket.\n\n"
553 
554 			"add bonding slave (slave_id) (port_id)\n"
555 			"	Add a slave device to a bonded device.\n\n"
556 
557 			"remove bonding slave (slave_id) (port_id)\n"
558 			"	Remove a slave device from a bonded device.\n\n"
559 
560 			"set bonding mode (value) (port_id)\n"
561 			"	Set the bonding mode on a bonded device.\n\n"
562 
563 			"set bonding primary (slave_id) (port_id)\n"
564 			"	Set the primary slave for a bonded device.\n\n"
565 
566 			"show bonding config (port_id)\n"
567 			"	Show the bonding config for port_id.\n\n"
568 
569 			"set bonding mac_addr (port_id) (address)\n"
570 			"	Set the MAC address of a bonded device.\n\n"
571 
572 			"set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
573 			"	Set the transmit balance policy for bonded device running in balance mode.\n\n"
574 
575 			"set bonding mon_period (port_id) (value)\n"
576 			"	Set the bonding link status monitoring polling period in ms.\n\n"
577 #endif
578 			"set link-up port (port_id)\n"
579 			"	Set link up for a port.\n\n"
580 
581 			"set link-down port (port_id)\n"
582 			"	Set link down for a port.\n\n"
583 
584 			"E-tag set insertion on port-tag-id (value)"
585 			" port (port_id) vf (vf_id)\n"
586 			"    Enable E-tag insertion for a VF on a port\n\n"
587 
588 			"E-tag set insertion off port (port_id) vf (vf_id)\n"
589 			"    Disable E-tag insertion for a VF on a port\n\n"
590 
591 			"E-tag set stripping (on|off) port (port_id)\n"
592 			"    Enable/disable E-tag stripping on a port\n\n"
593 
594 			"E-tag set forwarding (on|off) port (port_id)\n"
595 			"    Enable/disable E-tag based forwarding"
596 			" on a port\n\n"
597 
598 			"E-tag set filter add e-tag-id (value) dst-pool"
599 			" (pool_id) port (port_id)\n"
600 			"    Add an E-tag forwarding filter on a port\n\n"
601 
602 			"E-tag set filter del e-tag-id (value) port (port_id)\n"
603 			"    Delete an E-tag forwarding filter on a port\n\n"
604 
605 			"ddp add (port_id) (profile_path)\n"
606 			"    Load a profile package on a port\n\n"
607 
608 			"ptype mapping get (port_id) (valid_only)\n"
609 			"    Get ptype mapping on a port\n\n"
610 
611 			"ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
612 			"    Replace target with the pkt_type in ptype mapping\n\n"
613 
614 			"ptype mapping reset (port_id)\n"
615 			"    Reset ptype mapping on a port\n\n"
616 
617 			"ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
618 			"    Update a ptype mapping item on a port\n\n"
619 
620 			, list_pkt_forwarding_modes()
621 		);
622 	}
623 
624 	if (show_all || !strcmp(res->section, "ports")) {
625 
626 		cmdline_printf(
627 			cl,
628 			"\n"
629 			"Port Operations:\n"
630 			"----------------\n\n"
631 
632 			"port start (port_id|all)\n"
633 			"    Start all ports or port_id.\n\n"
634 
635 			"port stop (port_id|all)\n"
636 			"    Stop all ports or port_id.\n\n"
637 
638 			"port close (port_id|all)\n"
639 			"    Close all ports or port_id.\n\n"
640 
641 			"port attach (ident)\n"
642 			"    Attach physical or virtual dev by pci address or virtual device name\n\n"
643 
644 			"port detach (port_id)\n"
645 			"    Detach physical or virtual dev by port_id\n\n"
646 
647 			"port config (port_id|all)"
648 			" speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
649 			" duplex (half|full|auto)\n"
650 			"    Set speed and duplex for all ports or port_id\n\n"
651 
652 			"port config all (rxq|txq|rxd|txd) (value)\n"
653 			"    Set number for rxq/txq/rxd/txd.\n\n"
654 
655 			"port config all max-pkt-len (value)\n"
656 			"    Set the max packet length.\n\n"
657 
658 			"port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|"
659 			"hw-vlan-strip|hw-vlan-extend|drop-en)"
660 			" (on|off)\n"
661 			"    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
662 			" for ports.\n\n"
663 
664 			"port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none)\n"
665 			"    Set the RSS mode.\n\n"
666 
667 			"port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
668 			"    Set the RSS redirection table.\n\n"
669 
670 			"port config (port_id) dcb vt (on|off) (traffic_class)"
671 			" pfc (on|off)\n"
672 			"    Set the DCB mode.\n\n"
673 
674 			"port config all burst (value)\n"
675 			"    Set the number of packets per burst.\n\n"
676 
677 			"port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
678 			" (value)\n"
679 			"    Set the ring prefetch/host/writeback threshold"
680 			" for tx/rx queue.\n\n"
681 
682 			"port config all (txfreet|txrst|rxfreet) (value)\n"
683 			"    Set free threshold for rx/tx, or set"
684 			" tx rs bit threshold.\n\n"
685 			"port config mtu X value\n"
686 			"    Set the MTU of port X to a given value\n\n"
687 
688 			"port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
689 			"    Start/stop a rx/tx queue of port X. Only take effect"
690 			" when port X is started\n\n"
691 
692 			"port config (port_id|all) l2-tunnel E-tag ether-type"
693 			" (value)\n"
694 			"    Set the value of E-tag ether-type.\n\n"
695 
696 			"port config (port_id|all) l2-tunnel E-tag"
697 			" (enable|disable)\n"
698 			"    Enable/disable the E-tag support.\n\n"
699 		);
700 	}
701 
702 	if (show_all || !strcmp(res->section, "registers")) {
703 
704 		cmdline_printf(
705 			cl,
706 			"\n"
707 			"Registers:\n"
708 			"----------\n\n"
709 
710 			"read reg (port_id) (address)\n"
711 			"    Display value of a port register.\n\n"
712 
713 			"read regfield (port_id) (address) (bit_x) (bit_y)\n"
714 			"    Display a port register bit field.\n\n"
715 
716 			"read regbit (port_id) (address) (bit_x)\n"
717 			"    Display a single port register bit.\n\n"
718 
719 			"write reg (port_id) (address) (value)\n"
720 			"    Set value of a port register.\n\n"
721 
722 			"write regfield (port_id) (address) (bit_x) (bit_y)"
723 			" (value)\n"
724 			"    Set bit field of a port register.\n\n"
725 
726 			"write regbit (port_id) (address) (bit_x) (value)\n"
727 			"    Set single bit value of a port register.\n\n"
728 		);
729 	}
730 	if (show_all || !strcmp(res->section, "filters")) {
731 
732 		cmdline_printf(
733 			cl,
734 			"\n"
735 			"filters:\n"
736 			"--------\n\n"
737 
738 			"ethertype_filter (port_id) (add|del)"
739 			" (mac_addr|mac_ignr) (mac_address) ethertype"
740 			" (ether_type) (drop|fwd) queue (queue_id)\n"
741 			"    Add/Del an ethertype filter.\n\n"
742 
743 			"2tuple_filter (port_id) (add|del)"
744 			" dst_port (dst_port_value) protocol (protocol_value)"
745 			" mask (mask_value) tcp_flags (tcp_flags_value)"
746 			" priority (prio_value) queue (queue_id)\n"
747 			"    Add/Del a 2tuple filter.\n\n"
748 
749 			"5tuple_filter (port_id) (add|del)"
750 			" dst_ip (dst_address) src_ip (src_address)"
751 			" dst_port (dst_port_value) src_port (src_port_value)"
752 			" protocol (protocol_value)"
753 			" mask (mask_value) tcp_flags (tcp_flags_value)"
754 			" priority (prio_value) queue (queue_id)\n"
755 			"    Add/Del a 5tuple filter.\n\n"
756 
757 			"syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
758 			"    Add/Del syn filter.\n\n"
759 
760 			"flex_filter (port_id) (add|del) len (len_value)"
761 			" bytes (bytes_value) mask (mask_value)"
762 			" priority (prio_value) queue (queue_id)\n"
763 			"    Add/Del a flex filter.\n\n"
764 
765 			"flow_director_filter (port_id) mode IP (add|del|update)"
766 			" flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
767 			" src (src_ip_address) dst (dst_ip_address)"
768 			" tos (tos_value) proto (proto_value) ttl (ttl_value)"
769 			" vlan (vlan_value) flexbytes (flexbytes_value)"
770 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
771 			" fd_id (fd_id_value)\n"
772 			"    Add/Del an IP type flow director filter.\n\n"
773 
774 			"flow_director_filter (port_id) mode IP (add|del|update)"
775 			" flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
776 			" src (src_ip_address) (src_port)"
777 			" dst (dst_ip_address) (dst_port)"
778 			" tos (tos_value) ttl (ttl_value)"
779 			" vlan (vlan_value) flexbytes (flexbytes_value)"
780 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
781 			" fd_id (fd_id_value)\n"
782 			"    Add/Del an UDP/TCP type flow director filter.\n\n"
783 
784 			"flow_director_filter (port_id) mode IP (add|del|update)"
785 			" flow (ipv4-sctp|ipv6-sctp)"
786 			" src (src_ip_address) (src_port)"
787 			" dst (dst_ip_address) (dst_port)"
788 			" tag (verification_tag) "
789 			" tos (tos_value) ttl (ttl_value)"
790 			" vlan (vlan_value)"
791 			" flexbytes (flexbytes_value) (drop|fwd)"
792 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
793 			"    Add/Del a SCTP type flow director filter.\n\n"
794 
795 			"flow_director_filter (port_id) mode IP (add|del|update)"
796 			" flow l2_payload ether (ethertype)"
797 			" flexbytes (flexbytes_value) (drop|fwd)"
798 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
799 			"    Add/Del a l2 payload type flow director filter.\n\n"
800 
801 			"flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
802 			" mac (mac_address) vlan (vlan_value)"
803 			" flexbytes (flexbytes_value) (drop|fwd)"
804 			" queue (queue_id) fd_id (fd_id_value)\n"
805 			"    Add/Del a MAC-VLAN flow director filter.\n\n"
806 
807 			"flow_director_filter (port_id) mode Tunnel (add|del|update)"
808 			" mac (mac_address) vlan (vlan_value)"
809 			" tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
810 			" flexbytes (flexbytes_value) (drop|fwd)"
811 			" queue (queue_id) fd_id (fd_id_value)\n"
812 			"    Add/Del a Tunnel flow director filter.\n\n"
813 
814 			"flush_flow_director (port_id)\n"
815 			"    Flush all flow director entries of a device.\n\n"
816 
817 			"flow_director_mask (port_id) mode IP vlan (vlan_value)"
818 			" src_mask (ipv4_src) (ipv6_src) (src_port)"
819 			" dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
820 			"    Set flow director IP mask.\n\n"
821 
822 			"flow_director_mask (port_id) mode MAC-VLAN"
823 			" vlan (vlan_value)\n"
824 			"    Set flow director MAC-VLAN mask.\n\n"
825 
826 			"flow_director_mask (port_id) mode Tunnel"
827 			" vlan (vlan_value) mac (mac_value)"
828 			" tunnel-type (tunnel_type_value)"
829 			" tunnel-id (tunnel_id_value)\n"
830 			"    Set flow director Tunnel mask.\n\n"
831 
832 			"flow_director_flex_mask (port_id)"
833 			" flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
834 			"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
835 			" (mask)\n"
836 			"    Configure mask of flex payload.\n\n"
837 
838 			"flow_director_flex_payload (port_id)"
839 			" (raw|l2|l3|l4) (config)\n"
840 			"    Configure flex payload selection.\n\n"
841 
842 			"get_sym_hash_ena_per_port (port_id)\n"
843 			"    get symmetric hash enable configuration per port.\n\n"
844 
845 			"set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
846 			"    set symmetric hash enable configuration per port"
847 			" to enable or disable.\n\n"
848 
849 			"get_hash_global_config (port_id)\n"
850 			"    Get the global configurations of hash filters.\n\n"
851 
852 			"set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
853 			" (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
854 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
855 			" (enable|disable)\n"
856 			"    Set the global configurations of hash filters.\n\n"
857 
858 			"set_hash_input_set (port_id) (ipv4|ipv4-frag|"
859 			"ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
860 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
861 			"l2_payload) (ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|"
862 			"dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
863 			"ipv6-next-header|udp-src-port|udp-dst-port|"
864 			"tcp-src-port|tcp-dst-port|sctp-src-port|"
865 			"sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
866 			"fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
867 			"fld-8th|none) (select|add)\n"
868 			"    Set the input set for hash.\n\n"
869 
870 			"set_fdir_input_set (port_id) "
871 			"(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
872 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
873 			"l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
874 			"dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
875 			"ipv6-next-header|ipv6-hop-limits|udp-src-port|"
876 			"udp-dst-port|tcp-src-port|tcp-dst-port|"
877 			"sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
878 			" (select|add)\n"
879 			"    Set the input set for FDir.\n\n"
880 
881 			"flow validate {port_id}"
882 			" [group {group_id}] [priority {level}]"
883 			" [ingress] [egress]"
884 			" pattern {item} [/ {item} [...]] / end"
885 			" actions {action} [/ {action} [...]] / end\n"
886 			"    Check whether a flow rule can be created.\n\n"
887 
888 			"flow create {port_id}"
889 			" [group {group_id}] [priority {level}]"
890 			" [ingress] [egress]"
891 			" pattern {item} [/ {item} [...]] / end"
892 			" actions {action} [/ {action} [...]] / end\n"
893 			"    Create a flow rule.\n\n"
894 
895 			"flow destroy {port_id} rule {rule_id} [...]\n"
896 			"    Destroy specific flow rules.\n\n"
897 
898 			"flow flush {port_id}\n"
899 			"    Destroy all flow rules.\n\n"
900 
901 			"flow query {port_id} {rule_id} {action}\n"
902 			"    Query an existing flow rule.\n\n"
903 
904 			"flow list {port_id} [group {group_id}] [...]\n"
905 			"    List existing flow rules sorted by priority,"
906 			" filtered by group identifiers.\n\n"
907 		);
908 	}
909 }
910 
911 cmdline_parse_token_string_t cmd_help_long_help =
912 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
913 
914 cmdline_parse_token_string_t cmd_help_long_section =
915 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
916 			"all#control#display#config#"
917 			"ports#registers#filters");
918 
919 cmdline_parse_inst_t cmd_help_long = {
920 	.f = cmd_help_long_parsed,
921 	.data = NULL,
922 	.help_str = "help all|control|display|config|ports|register|filters: "
923 		"Show help",
924 	.tokens = {
925 		(void *)&cmd_help_long_help,
926 		(void *)&cmd_help_long_section,
927 		NULL,
928 	},
929 };
930 
931 
932 /* *** start/stop/close all ports *** */
933 struct cmd_operate_port_result {
934 	cmdline_fixed_string_t keyword;
935 	cmdline_fixed_string_t name;
936 	cmdline_fixed_string_t value;
937 };
938 
939 static void cmd_operate_port_parsed(void *parsed_result,
940 				__attribute__((unused)) struct cmdline *cl,
941 				__attribute__((unused)) void *data)
942 {
943 	struct cmd_operate_port_result *res = parsed_result;
944 
945 	if (!strcmp(res->name, "start"))
946 		start_port(RTE_PORT_ALL);
947 	else if (!strcmp(res->name, "stop"))
948 		stop_port(RTE_PORT_ALL);
949 	else if (!strcmp(res->name, "close"))
950 		close_port(RTE_PORT_ALL);
951 	else
952 		printf("Unknown parameter\n");
953 }
954 
955 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
956 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
957 								"port");
958 cmdline_parse_token_string_t cmd_operate_port_all_port =
959 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
960 						"start#stop#close");
961 cmdline_parse_token_string_t cmd_operate_port_all_all =
962 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
963 
964 cmdline_parse_inst_t cmd_operate_port = {
965 	.f = cmd_operate_port_parsed,
966 	.data = NULL,
967 	.help_str = "port start|stop|close all: Start/Stop/Close all ports",
968 	.tokens = {
969 		(void *)&cmd_operate_port_all_cmd,
970 		(void *)&cmd_operate_port_all_port,
971 		(void *)&cmd_operate_port_all_all,
972 		NULL,
973 	},
974 };
975 
976 /* *** start/stop/close specific port *** */
977 struct cmd_operate_specific_port_result {
978 	cmdline_fixed_string_t keyword;
979 	cmdline_fixed_string_t name;
980 	uint8_t value;
981 };
982 
983 static void cmd_operate_specific_port_parsed(void *parsed_result,
984 			__attribute__((unused)) struct cmdline *cl,
985 				__attribute__((unused)) void *data)
986 {
987 	struct cmd_operate_specific_port_result *res = parsed_result;
988 
989 	if (!strcmp(res->name, "start"))
990 		start_port(res->value);
991 	else if (!strcmp(res->name, "stop"))
992 		stop_port(res->value);
993 	else if (!strcmp(res->name, "close"))
994 		close_port(res->value);
995 	else
996 		printf("Unknown parameter\n");
997 }
998 
999 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1000 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1001 							keyword, "port");
1002 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1003 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1004 						name, "start#stop#close");
1005 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1006 	TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1007 							value, UINT8);
1008 
1009 cmdline_parse_inst_t cmd_operate_specific_port = {
1010 	.f = cmd_operate_specific_port_parsed,
1011 	.data = NULL,
1012 	.help_str = "port start|stop|close <port_id>: Start/Stop/Close port_id",
1013 	.tokens = {
1014 		(void *)&cmd_operate_specific_port_cmd,
1015 		(void *)&cmd_operate_specific_port_port,
1016 		(void *)&cmd_operate_specific_port_id,
1017 		NULL,
1018 	},
1019 };
1020 
1021 /* *** attach a specified port *** */
1022 struct cmd_operate_attach_port_result {
1023 	cmdline_fixed_string_t port;
1024 	cmdline_fixed_string_t keyword;
1025 	cmdline_fixed_string_t identifier;
1026 };
1027 
1028 static void cmd_operate_attach_port_parsed(void *parsed_result,
1029 				__attribute__((unused)) struct cmdline *cl,
1030 				__attribute__((unused)) void *data)
1031 {
1032 	struct cmd_operate_attach_port_result *res = parsed_result;
1033 
1034 	if (!strcmp(res->keyword, "attach"))
1035 		attach_port(res->identifier);
1036 	else
1037 		printf("Unknown parameter\n");
1038 }
1039 
1040 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1041 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1042 			port, "port");
1043 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1044 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1045 			keyword, "attach");
1046 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1047 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1048 			identifier, NULL);
1049 
1050 cmdline_parse_inst_t cmd_operate_attach_port = {
1051 	.f = cmd_operate_attach_port_parsed,
1052 	.data = NULL,
1053 	.help_str = "port attach <identifier>: "
1054 		"(identifier: pci address or virtual dev name)",
1055 	.tokens = {
1056 		(void *)&cmd_operate_attach_port_port,
1057 		(void *)&cmd_operate_attach_port_keyword,
1058 		(void *)&cmd_operate_attach_port_identifier,
1059 		NULL,
1060 	},
1061 };
1062 
1063 /* *** detach a specified port *** */
1064 struct cmd_operate_detach_port_result {
1065 	cmdline_fixed_string_t port;
1066 	cmdline_fixed_string_t keyword;
1067 	uint8_t port_id;
1068 };
1069 
1070 static void cmd_operate_detach_port_parsed(void *parsed_result,
1071 				__attribute__((unused)) struct cmdline *cl,
1072 				__attribute__((unused)) void *data)
1073 {
1074 	struct cmd_operate_detach_port_result *res = parsed_result;
1075 
1076 	if (!strcmp(res->keyword, "detach"))
1077 		detach_port(res->port_id);
1078 	else
1079 		printf("Unknown parameter\n");
1080 }
1081 
1082 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1083 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1084 			port, "port");
1085 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1086 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1087 			keyword, "detach");
1088 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1089 	TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1090 			port_id, UINT8);
1091 
1092 cmdline_parse_inst_t cmd_operate_detach_port = {
1093 	.f = cmd_operate_detach_port_parsed,
1094 	.data = NULL,
1095 	.help_str = "port detach <port_id>",
1096 	.tokens = {
1097 		(void *)&cmd_operate_detach_port_port,
1098 		(void *)&cmd_operate_detach_port_keyword,
1099 		(void *)&cmd_operate_detach_port_port_id,
1100 		NULL,
1101 	},
1102 };
1103 
1104 /* *** configure speed for all ports *** */
1105 struct cmd_config_speed_all {
1106 	cmdline_fixed_string_t port;
1107 	cmdline_fixed_string_t keyword;
1108 	cmdline_fixed_string_t all;
1109 	cmdline_fixed_string_t item1;
1110 	cmdline_fixed_string_t item2;
1111 	cmdline_fixed_string_t value1;
1112 	cmdline_fixed_string_t value2;
1113 };
1114 
1115 static int
1116 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1117 {
1118 
1119 	int duplex;
1120 
1121 	if (!strcmp(duplexstr, "half")) {
1122 		duplex = ETH_LINK_HALF_DUPLEX;
1123 	} else if (!strcmp(duplexstr, "full")) {
1124 		duplex = ETH_LINK_FULL_DUPLEX;
1125 	} else if (!strcmp(duplexstr, "auto")) {
1126 		duplex = ETH_LINK_FULL_DUPLEX;
1127 	} else {
1128 		printf("Unknown duplex parameter\n");
1129 		return -1;
1130 	}
1131 
1132 	if (!strcmp(speedstr, "10")) {
1133 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1134 				ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1135 	} else if (!strcmp(speedstr, "100")) {
1136 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1137 				ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1138 	} else {
1139 		if (duplex != ETH_LINK_FULL_DUPLEX) {
1140 			printf("Invalid speed/duplex parameters\n");
1141 			return -1;
1142 		}
1143 		if (!strcmp(speedstr, "1000")) {
1144 			*speed = ETH_LINK_SPEED_1G;
1145 		} else if (!strcmp(speedstr, "10000")) {
1146 			*speed = ETH_LINK_SPEED_10G;
1147 		} else if (!strcmp(speedstr, "25000")) {
1148 			*speed = ETH_LINK_SPEED_25G;
1149 		} else if (!strcmp(speedstr, "40000")) {
1150 			*speed = ETH_LINK_SPEED_40G;
1151 		} else if (!strcmp(speedstr, "50000")) {
1152 			*speed = ETH_LINK_SPEED_50G;
1153 		} else if (!strcmp(speedstr, "100000")) {
1154 			*speed = ETH_LINK_SPEED_100G;
1155 		} else if (!strcmp(speedstr, "auto")) {
1156 			*speed = ETH_LINK_SPEED_AUTONEG;
1157 		} else {
1158 			printf("Unknown speed parameter\n");
1159 			return -1;
1160 		}
1161 	}
1162 
1163 	return 0;
1164 }
1165 
1166 static void
1167 cmd_config_speed_all_parsed(void *parsed_result,
1168 			__attribute__((unused)) struct cmdline *cl,
1169 			__attribute__((unused)) void *data)
1170 {
1171 	struct cmd_config_speed_all *res = parsed_result;
1172 	uint32_t link_speed;
1173 	portid_t pid;
1174 
1175 	if (!all_ports_stopped()) {
1176 		printf("Please stop all ports first\n");
1177 		return;
1178 	}
1179 
1180 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1181 			&link_speed) < 0)
1182 		return;
1183 
1184 	RTE_ETH_FOREACH_DEV(pid) {
1185 		ports[pid].dev_conf.link_speeds = link_speed;
1186 	}
1187 
1188 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1189 }
1190 
1191 cmdline_parse_token_string_t cmd_config_speed_all_port =
1192 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1193 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1194 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1195 							"config");
1196 cmdline_parse_token_string_t cmd_config_speed_all_all =
1197 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1198 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1199 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1200 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1201 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1202 				"10#100#1000#10000#25000#40000#50000#100000#auto");
1203 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1204 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1205 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1206 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1207 						"half#full#auto");
1208 
1209 cmdline_parse_inst_t cmd_config_speed_all = {
1210 	.f = cmd_config_speed_all_parsed,
1211 	.data = NULL,
1212 	.help_str = "port config all speed "
1213 		"10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1214 							"half|full|auto",
1215 	.tokens = {
1216 		(void *)&cmd_config_speed_all_port,
1217 		(void *)&cmd_config_speed_all_keyword,
1218 		(void *)&cmd_config_speed_all_all,
1219 		(void *)&cmd_config_speed_all_item1,
1220 		(void *)&cmd_config_speed_all_value1,
1221 		(void *)&cmd_config_speed_all_item2,
1222 		(void *)&cmd_config_speed_all_value2,
1223 		NULL,
1224 	},
1225 };
1226 
1227 /* *** configure speed for specific port *** */
1228 struct cmd_config_speed_specific {
1229 	cmdline_fixed_string_t port;
1230 	cmdline_fixed_string_t keyword;
1231 	uint8_t id;
1232 	cmdline_fixed_string_t item1;
1233 	cmdline_fixed_string_t item2;
1234 	cmdline_fixed_string_t value1;
1235 	cmdline_fixed_string_t value2;
1236 };
1237 
1238 static void
1239 cmd_config_speed_specific_parsed(void *parsed_result,
1240 				__attribute__((unused)) struct cmdline *cl,
1241 				__attribute__((unused)) void *data)
1242 {
1243 	struct cmd_config_speed_specific *res = parsed_result;
1244 	uint32_t link_speed;
1245 
1246 	if (!all_ports_stopped()) {
1247 		printf("Please stop all ports first\n");
1248 		return;
1249 	}
1250 
1251 	if (port_id_is_invalid(res->id, ENABLED_WARN))
1252 		return;
1253 
1254 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1255 			&link_speed) < 0)
1256 		return;
1257 
1258 	ports[res->id].dev_conf.link_speeds = link_speed;
1259 
1260 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1261 }
1262 
1263 
1264 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1265 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1266 								"port");
1267 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1268 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1269 								"config");
1270 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1271 	TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1272 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1273 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1274 								"speed");
1275 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1276 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1277 				"10#100#1000#10000#25000#40000#50000#100000#auto");
1278 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1279 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1280 								"duplex");
1281 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1282 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1283 							"half#full#auto");
1284 
1285 cmdline_parse_inst_t cmd_config_speed_specific = {
1286 	.f = cmd_config_speed_specific_parsed,
1287 	.data = NULL,
1288 	.help_str = "port config <port_id> speed "
1289 		"10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1290 							"half|full|auto",
1291 	.tokens = {
1292 		(void *)&cmd_config_speed_specific_port,
1293 		(void *)&cmd_config_speed_specific_keyword,
1294 		(void *)&cmd_config_speed_specific_id,
1295 		(void *)&cmd_config_speed_specific_item1,
1296 		(void *)&cmd_config_speed_specific_value1,
1297 		(void *)&cmd_config_speed_specific_item2,
1298 		(void *)&cmd_config_speed_specific_value2,
1299 		NULL,
1300 	},
1301 };
1302 
1303 /* *** configure txq/rxq, txd/rxd *** */
1304 struct cmd_config_rx_tx {
1305 	cmdline_fixed_string_t port;
1306 	cmdline_fixed_string_t keyword;
1307 	cmdline_fixed_string_t all;
1308 	cmdline_fixed_string_t name;
1309 	uint16_t value;
1310 };
1311 
1312 static void
1313 cmd_config_rx_tx_parsed(void *parsed_result,
1314 			__attribute__((unused)) struct cmdline *cl,
1315 			__attribute__((unused)) void *data)
1316 {
1317 	struct cmd_config_rx_tx *res = parsed_result;
1318 
1319 	if (!all_ports_stopped()) {
1320 		printf("Please stop all ports first\n");
1321 		return;
1322 	}
1323 	if (!strcmp(res->name, "rxq")) {
1324 		if (!res->value && !nb_txq) {
1325 			printf("Warning: Either rx or tx queues should be non zero\n");
1326 			return;
1327 		}
1328 		nb_rxq = res->value;
1329 	}
1330 	else if (!strcmp(res->name, "txq")) {
1331 		if (!res->value && !nb_rxq) {
1332 			printf("Warning: Either rx or tx queues should be non zero\n");
1333 			return;
1334 		}
1335 		nb_txq = res->value;
1336 	}
1337 	else if (!strcmp(res->name, "rxd")) {
1338 		if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1339 			printf("rxd %d invalid - must be > 0 && <= %d\n",
1340 					res->value, RTE_TEST_RX_DESC_MAX);
1341 			return;
1342 		}
1343 		nb_rxd = res->value;
1344 	} else if (!strcmp(res->name, "txd")) {
1345 		if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1346 			printf("txd %d invalid - must be > 0 && <= %d\n",
1347 					res->value, RTE_TEST_TX_DESC_MAX);
1348 			return;
1349 		}
1350 		nb_txd = res->value;
1351 	} else {
1352 		printf("Unknown parameter\n");
1353 		return;
1354 	}
1355 
1356 	fwd_config_setup();
1357 
1358 	init_port_config();
1359 
1360 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1361 }
1362 
1363 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1364 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1365 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1366 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1367 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1368 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1369 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1370 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1371 						"rxq#txq#rxd#txd");
1372 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1373 	TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1374 
1375 cmdline_parse_inst_t cmd_config_rx_tx = {
1376 	.f = cmd_config_rx_tx_parsed,
1377 	.data = NULL,
1378 	.help_str = "port config all rxq|txq|rxd|txd <value>",
1379 	.tokens = {
1380 		(void *)&cmd_config_rx_tx_port,
1381 		(void *)&cmd_config_rx_tx_keyword,
1382 		(void *)&cmd_config_rx_tx_all,
1383 		(void *)&cmd_config_rx_tx_name,
1384 		(void *)&cmd_config_rx_tx_value,
1385 		NULL,
1386 	},
1387 };
1388 
1389 /* *** config max packet length *** */
1390 struct cmd_config_max_pkt_len_result {
1391 	cmdline_fixed_string_t port;
1392 	cmdline_fixed_string_t keyword;
1393 	cmdline_fixed_string_t all;
1394 	cmdline_fixed_string_t name;
1395 	uint32_t value;
1396 };
1397 
1398 static void
1399 cmd_config_max_pkt_len_parsed(void *parsed_result,
1400 				__attribute__((unused)) struct cmdline *cl,
1401 				__attribute__((unused)) void *data)
1402 {
1403 	struct cmd_config_max_pkt_len_result *res = parsed_result;
1404 
1405 	if (!all_ports_stopped()) {
1406 		printf("Please stop all ports first\n");
1407 		return;
1408 	}
1409 
1410 	if (!strcmp(res->name, "max-pkt-len")) {
1411 		if (res->value < ETHER_MIN_LEN) {
1412 			printf("max-pkt-len can not be less than %d\n",
1413 							ETHER_MIN_LEN);
1414 			return;
1415 		}
1416 		if (res->value == rx_mode.max_rx_pkt_len)
1417 			return;
1418 
1419 		rx_mode.max_rx_pkt_len = res->value;
1420 		if (res->value > ETHER_MAX_LEN)
1421 			rx_mode.jumbo_frame = 1;
1422 		else
1423 			rx_mode.jumbo_frame = 0;
1424 	} else {
1425 		printf("Unknown parameter\n");
1426 		return;
1427 	}
1428 
1429 	init_port_config();
1430 
1431 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1432 }
1433 
1434 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1435 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1436 								"port");
1437 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1438 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1439 								"config");
1440 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1441 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1442 								"all");
1443 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1444 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1445 								"max-pkt-len");
1446 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1447 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1448 								UINT32);
1449 
1450 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1451 	.f = cmd_config_max_pkt_len_parsed,
1452 	.data = NULL,
1453 	.help_str = "port config all max-pkt-len <value>",
1454 	.tokens = {
1455 		(void *)&cmd_config_max_pkt_len_port,
1456 		(void *)&cmd_config_max_pkt_len_keyword,
1457 		(void *)&cmd_config_max_pkt_len_all,
1458 		(void *)&cmd_config_max_pkt_len_name,
1459 		(void *)&cmd_config_max_pkt_len_value,
1460 		NULL,
1461 	},
1462 };
1463 
1464 /* *** configure port MTU *** */
1465 struct cmd_config_mtu_result {
1466 	cmdline_fixed_string_t port;
1467 	cmdline_fixed_string_t keyword;
1468 	cmdline_fixed_string_t mtu;
1469 	uint8_t port_id;
1470 	uint16_t value;
1471 };
1472 
1473 static void
1474 cmd_config_mtu_parsed(void *parsed_result,
1475 		      __attribute__((unused)) struct cmdline *cl,
1476 		      __attribute__((unused)) void *data)
1477 {
1478 	struct cmd_config_mtu_result *res = parsed_result;
1479 
1480 	if (res->value < ETHER_MIN_LEN) {
1481 		printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1482 		return;
1483 	}
1484 	port_mtu_set(res->port_id, res->value);
1485 }
1486 
1487 cmdline_parse_token_string_t cmd_config_mtu_port =
1488 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1489 				 "port");
1490 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1491 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1492 				 "config");
1493 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1494 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1495 				 "mtu");
1496 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1497 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1498 cmdline_parse_token_num_t cmd_config_mtu_value =
1499 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1500 
1501 cmdline_parse_inst_t cmd_config_mtu = {
1502 	.f = cmd_config_mtu_parsed,
1503 	.data = NULL,
1504 	.help_str = "port config mtu <port_id> <value>",
1505 	.tokens = {
1506 		(void *)&cmd_config_mtu_port,
1507 		(void *)&cmd_config_mtu_keyword,
1508 		(void *)&cmd_config_mtu_mtu,
1509 		(void *)&cmd_config_mtu_port_id,
1510 		(void *)&cmd_config_mtu_value,
1511 		NULL,
1512 	},
1513 };
1514 
1515 /* *** configure rx mode *** */
1516 struct cmd_config_rx_mode_flag {
1517 	cmdline_fixed_string_t port;
1518 	cmdline_fixed_string_t keyword;
1519 	cmdline_fixed_string_t all;
1520 	cmdline_fixed_string_t name;
1521 	cmdline_fixed_string_t value;
1522 };
1523 
1524 static void
1525 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1526 				__attribute__((unused)) struct cmdline *cl,
1527 				__attribute__((unused)) void *data)
1528 {
1529 	struct cmd_config_rx_mode_flag *res = parsed_result;
1530 
1531 	if (!all_ports_stopped()) {
1532 		printf("Please stop all ports first\n");
1533 		return;
1534 	}
1535 
1536 	if (!strcmp(res->name, "crc-strip")) {
1537 		if (!strcmp(res->value, "on"))
1538 			rx_mode.hw_strip_crc = 1;
1539 		else if (!strcmp(res->value, "off"))
1540 			rx_mode.hw_strip_crc = 0;
1541 		else {
1542 			printf("Unknown parameter\n");
1543 			return;
1544 		}
1545 	} else if (!strcmp(res->name, "scatter")) {
1546 		if (!strcmp(res->value, "on"))
1547 			rx_mode.enable_scatter = 1;
1548 		else if (!strcmp(res->value, "off"))
1549 			rx_mode.enable_scatter = 0;
1550 		else {
1551 			printf("Unknown parameter\n");
1552 			return;
1553 		}
1554 	} else if (!strcmp(res->name, "rx-cksum")) {
1555 		if (!strcmp(res->value, "on"))
1556 			rx_mode.hw_ip_checksum = 1;
1557 		else if (!strcmp(res->value, "off"))
1558 			rx_mode.hw_ip_checksum = 0;
1559 		else {
1560 			printf("Unknown parameter\n");
1561 			return;
1562 		}
1563 	} else if (!strcmp(res->name, "hw-vlan")) {
1564 		if (!strcmp(res->value, "on")) {
1565 			rx_mode.hw_vlan_filter = 1;
1566 			rx_mode.hw_vlan_strip  = 1;
1567 		}
1568 		else if (!strcmp(res->value, "off")) {
1569 			rx_mode.hw_vlan_filter = 0;
1570 			rx_mode.hw_vlan_strip  = 0;
1571 		}
1572 		else {
1573 			printf("Unknown parameter\n");
1574 			return;
1575 		}
1576 	} else if (!strcmp(res->name, "hw-vlan-filter")) {
1577 		if (!strcmp(res->value, "on"))
1578 			rx_mode.hw_vlan_filter = 1;
1579 		else if (!strcmp(res->value, "off"))
1580 			rx_mode.hw_vlan_filter = 0;
1581 		else {
1582 			printf("Unknown parameter\n");
1583 			return;
1584 		}
1585 	} else if (!strcmp(res->name, "hw-vlan-strip")) {
1586 		if (!strcmp(res->value, "on"))
1587 			rx_mode.hw_vlan_strip  = 1;
1588 		else if (!strcmp(res->value, "off"))
1589 			rx_mode.hw_vlan_strip  = 0;
1590 		else {
1591 			printf("Unknown parameter\n");
1592 			return;
1593 		}
1594 	} else if (!strcmp(res->name, "hw-vlan-extend")) {
1595 		if (!strcmp(res->value, "on"))
1596 			rx_mode.hw_vlan_extend = 1;
1597 		else if (!strcmp(res->value, "off"))
1598 			rx_mode.hw_vlan_extend = 0;
1599 		else {
1600 			printf("Unknown parameter\n");
1601 			return;
1602 		}
1603 	} else if (!strcmp(res->name, "drop-en")) {
1604 		if (!strcmp(res->value, "on"))
1605 			rx_drop_en = 1;
1606 		else if (!strcmp(res->value, "off"))
1607 			rx_drop_en = 0;
1608 		else {
1609 			printf("Unknown parameter\n");
1610 			return;
1611 		}
1612 	} else {
1613 		printf("Unknown parameter\n");
1614 		return;
1615 	}
1616 
1617 	init_port_config();
1618 
1619 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1620 }
1621 
1622 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1623 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1624 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1625 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1626 								"config");
1627 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1628 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1629 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1630 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1631 					"crc-strip#scatter#rx-cksum#hw-vlan#"
1632 					"hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1633 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1634 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1635 							"on#off");
1636 
1637 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1638 	.f = cmd_config_rx_mode_flag_parsed,
1639 	.data = NULL,
1640 	.help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|"
1641 		"hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1642 	.tokens = {
1643 		(void *)&cmd_config_rx_mode_flag_port,
1644 		(void *)&cmd_config_rx_mode_flag_keyword,
1645 		(void *)&cmd_config_rx_mode_flag_all,
1646 		(void *)&cmd_config_rx_mode_flag_name,
1647 		(void *)&cmd_config_rx_mode_flag_value,
1648 		NULL,
1649 	},
1650 };
1651 
1652 /* *** configure rss *** */
1653 struct cmd_config_rss {
1654 	cmdline_fixed_string_t port;
1655 	cmdline_fixed_string_t keyword;
1656 	cmdline_fixed_string_t all;
1657 	cmdline_fixed_string_t name;
1658 	cmdline_fixed_string_t value;
1659 };
1660 
1661 static void
1662 cmd_config_rss_parsed(void *parsed_result,
1663 			__attribute__((unused)) struct cmdline *cl,
1664 			__attribute__((unused)) void *data)
1665 {
1666 	struct cmd_config_rss *res = parsed_result;
1667 	struct rte_eth_rss_conf rss_conf;
1668 	int diag;
1669 	uint8_t i;
1670 
1671 	if (!strcmp(res->value, "all"))
1672 		rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1673 				ETH_RSS_UDP | ETH_RSS_SCTP |
1674 					ETH_RSS_L2_PAYLOAD;
1675 	else if (!strcmp(res->value, "ip"))
1676 		rss_conf.rss_hf = ETH_RSS_IP;
1677 	else if (!strcmp(res->value, "udp"))
1678 		rss_conf.rss_hf = ETH_RSS_UDP;
1679 	else if (!strcmp(res->value, "tcp"))
1680 		rss_conf.rss_hf = ETH_RSS_TCP;
1681 	else if (!strcmp(res->value, "sctp"))
1682 		rss_conf.rss_hf = ETH_RSS_SCTP;
1683 	else if (!strcmp(res->value, "ether"))
1684 		rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1685 	else if (!strcmp(res->value, "port"))
1686 		rss_conf.rss_hf = ETH_RSS_PORT;
1687 	else if (!strcmp(res->value, "vxlan"))
1688 		rss_conf.rss_hf = ETH_RSS_VXLAN;
1689 	else if (!strcmp(res->value, "geneve"))
1690 		rss_conf.rss_hf = ETH_RSS_GENEVE;
1691 	else if (!strcmp(res->value, "nvgre"))
1692 		rss_conf.rss_hf = ETH_RSS_NVGRE;
1693 	else if (!strcmp(res->value, "none"))
1694 		rss_conf.rss_hf = 0;
1695 	else {
1696 		printf("Unknown parameter\n");
1697 		return;
1698 	}
1699 	rss_conf.rss_key = NULL;
1700 	for (i = 0; i < rte_eth_dev_count(); i++) {
1701 		diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1702 		if (diag < 0)
1703 			printf("Configuration of RSS hash at ethernet port %d "
1704 				"failed with error (%d): %s.\n",
1705 				i, -diag, strerror(-diag));
1706 	}
1707 }
1708 
1709 cmdline_parse_token_string_t cmd_config_rss_port =
1710 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1711 cmdline_parse_token_string_t cmd_config_rss_keyword =
1712 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1713 cmdline_parse_token_string_t cmd_config_rss_all =
1714 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1715 cmdline_parse_token_string_t cmd_config_rss_name =
1716 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1717 cmdline_parse_token_string_t cmd_config_rss_value =
1718 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value,
1719 		"all#ip#tcp#udp#sctp#ether#port#vxlan#geneve#nvgre#none");
1720 
1721 cmdline_parse_inst_t cmd_config_rss = {
1722 	.f = cmd_config_rss_parsed,
1723 	.data = NULL,
1724 	.help_str = "port config all rss "
1725 		"all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none",
1726 	.tokens = {
1727 		(void *)&cmd_config_rss_port,
1728 		(void *)&cmd_config_rss_keyword,
1729 		(void *)&cmd_config_rss_all,
1730 		(void *)&cmd_config_rss_name,
1731 		(void *)&cmd_config_rss_value,
1732 		NULL,
1733 	},
1734 };
1735 
1736 /* *** configure rss hash key *** */
1737 struct cmd_config_rss_hash_key {
1738 	cmdline_fixed_string_t port;
1739 	cmdline_fixed_string_t config;
1740 	uint8_t port_id;
1741 	cmdline_fixed_string_t rss_hash_key;
1742 	cmdline_fixed_string_t rss_type;
1743 	cmdline_fixed_string_t key;
1744 };
1745 
1746 static uint8_t
1747 hexa_digit_to_value(char hexa_digit)
1748 {
1749 	if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1750 		return (uint8_t) (hexa_digit - '0');
1751 	if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1752 		return (uint8_t) ((hexa_digit - 'a') + 10);
1753 	if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1754 		return (uint8_t) ((hexa_digit - 'A') + 10);
1755 	/* Invalid hexa digit */
1756 	return 0xFF;
1757 }
1758 
1759 static uint8_t
1760 parse_and_check_key_hexa_digit(char *key, int idx)
1761 {
1762 	uint8_t hexa_v;
1763 
1764 	hexa_v = hexa_digit_to_value(key[idx]);
1765 	if (hexa_v == 0xFF)
1766 		printf("invalid key: character %c at position %d is not a "
1767 		       "valid hexa digit\n", key[idx], idx);
1768 	return hexa_v;
1769 }
1770 
1771 static void
1772 cmd_config_rss_hash_key_parsed(void *parsed_result,
1773 			       __attribute__((unused)) struct cmdline *cl,
1774 			       __attribute__((unused)) void *data)
1775 {
1776 	struct cmd_config_rss_hash_key *res = parsed_result;
1777 	uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1778 	uint8_t xdgt0;
1779 	uint8_t xdgt1;
1780 	int i;
1781 	struct rte_eth_dev_info dev_info;
1782 	uint8_t hash_key_size;
1783 	uint32_t key_len;
1784 
1785 	memset(&dev_info, 0, sizeof(dev_info));
1786 	rte_eth_dev_info_get(res->port_id, &dev_info);
1787 	if (dev_info.hash_key_size > 0 &&
1788 			dev_info.hash_key_size <= sizeof(hash_key))
1789 		hash_key_size = dev_info.hash_key_size;
1790 	else {
1791 		printf("dev_info did not provide a valid hash key size\n");
1792 		return;
1793 	}
1794 	/* Check the length of the RSS hash key */
1795 	key_len = strlen(res->key);
1796 	if (key_len != (hash_key_size * 2)) {
1797 		printf("key length: %d invalid - key must be a string of %d"
1798 			   " hexa-decimal numbers\n",
1799 			   (int) key_len, hash_key_size * 2);
1800 		return;
1801 	}
1802 	/* Translate RSS hash key into binary representation */
1803 	for (i = 0; i < hash_key_size; i++) {
1804 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1805 		if (xdgt0 == 0xFF)
1806 			return;
1807 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1808 		if (xdgt1 == 0xFF)
1809 			return;
1810 		hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1811 	}
1812 	port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1813 			hash_key_size);
1814 }
1815 
1816 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1817 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1818 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1819 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1820 				 "config");
1821 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1822 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1823 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1824 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1825 				 rss_hash_key, "rss-hash-key");
1826 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1827 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1828 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1829 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1830 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1831 				 "ipv6-tcp-ex#ipv6-udp-ex");
1832 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1833 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1834 
1835 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1836 	.f = cmd_config_rss_hash_key_parsed,
1837 	.data = NULL,
1838 	.help_str = "port config <port_id> rss-hash-key "
1839 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1840 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1841 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
1842 		"<string of hex digits (variable length, NIC dependent)>",
1843 	.tokens = {
1844 		(void *)&cmd_config_rss_hash_key_port,
1845 		(void *)&cmd_config_rss_hash_key_config,
1846 		(void *)&cmd_config_rss_hash_key_port_id,
1847 		(void *)&cmd_config_rss_hash_key_rss_hash_key,
1848 		(void *)&cmd_config_rss_hash_key_rss_type,
1849 		(void *)&cmd_config_rss_hash_key_value,
1850 		NULL,
1851 	},
1852 };
1853 
1854 /* *** configure port rxq/txq start/stop *** */
1855 struct cmd_config_rxtx_queue {
1856 	cmdline_fixed_string_t port;
1857 	uint8_t portid;
1858 	cmdline_fixed_string_t rxtxq;
1859 	uint16_t qid;
1860 	cmdline_fixed_string_t opname;
1861 };
1862 
1863 static void
1864 cmd_config_rxtx_queue_parsed(void *parsed_result,
1865 			__attribute__((unused)) struct cmdline *cl,
1866 			__attribute__((unused)) void *data)
1867 {
1868 	struct cmd_config_rxtx_queue *res = parsed_result;
1869 	uint8_t isrx;
1870 	uint8_t isstart;
1871 	int ret = 0;
1872 
1873 	if (test_done == 0) {
1874 		printf("Please stop forwarding first\n");
1875 		return;
1876 	}
1877 
1878 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
1879 		return;
1880 
1881 	if (port_is_started(res->portid) != 1) {
1882 		printf("Please start port %u first\n", res->portid);
1883 		return;
1884 	}
1885 
1886 	if (!strcmp(res->rxtxq, "rxq"))
1887 		isrx = 1;
1888 	else if (!strcmp(res->rxtxq, "txq"))
1889 		isrx = 0;
1890 	else {
1891 		printf("Unknown parameter\n");
1892 		return;
1893 	}
1894 
1895 	if (isrx && rx_queue_id_is_invalid(res->qid))
1896 		return;
1897 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
1898 		return;
1899 
1900 	if (!strcmp(res->opname, "start"))
1901 		isstart = 1;
1902 	else if (!strcmp(res->opname, "stop"))
1903 		isstart = 0;
1904 	else {
1905 		printf("Unknown parameter\n");
1906 		return;
1907 	}
1908 
1909 	if (isstart && isrx)
1910 		ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1911 	else if (!isstart && isrx)
1912 		ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1913 	else if (isstart && !isrx)
1914 		ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1915 	else
1916 		ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1917 
1918 	if (ret == -ENOTSUP)
1919 		printf("Function not supported in PMD driver\n");
1920 }
1921 
1922 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1923 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1924 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1925 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1926 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1927 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1928 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1929 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
1930 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
1931 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
1932 						"start#stop");
1933 
1934 cmdline_parse_inst_t cmd_config_rxtx_queue = {
1935 	.f = cmd_config_rxtx_queue_parsed,
1936 	.data = NULL,
1937 	.help_str = "port <port_id> rxq|txq <queue_id> start|stop",
1938 	.tokens = {
1939 		(void *)&cmd_config_speed_all_port,
1940 		(void *)&cmd_config_rxtx_queue_portid,
1941 		(void *)&cmd_config_rxtx_queue_rxtxq,
1942 		(void *)&cmd_config_rxtx_queue_qid,
1943 		(void *)&cmd_config_rxtx_queue_opname,
1944 		NULL,
1945 	},
1946 };
1947 
1948 /* *** Configure RSS RETA *** */
1949 struct cmd_config_rss_reta {
1950 	cmdline_fixed_string_t port;
1951 	cmdline_fixed_string_t keyword;
1952 	uint8_t port_id;
1953 	cmdline_fixed_string_t name;
1954 	cmdline_fixed_string_t list_name;
1955 	cmdline_fixed_string_t list_of_items;
1956 };
1957 
1958 static int
1959 parse_reta_config(const char *str,
1960 		  struct rte_eth_rss_reta_entry64 *reta_conf,
1961 		  uint16_t nb_entries)
1962 {
1963 	int i;
1964 	unsigned size;
1965 	uint16_t hash_index, idx, shift;
1966 	uint16_t nb_queue;
1967 	char s[256];
1968 	const char *p, *p0 = str;
1969 	char *end;
1970 	enum fieldnames {
1971 		FLD_HASH_INDEX = 0,
1972 		FLD_QUEUE,
1973 		_NUM_FLD
1974 	};
1975 	unsigned long int_fld[_NUM_FLD];
1976 	char *str_fld[_NUM_FLD];
1977 
1978 	while ((p = strchr(p0,'(')) != NULL) {
1979 		++p;
1980 		if((p0 = strchr(p,')')) == NULL)
1981 			return -1;
1982 
1983 		size = p0 - p;
1984 		if(size >= sizeof(s))
1985 			return -1;
1986 
1987 		snprintf(s, sizeof(s), "%.*s", size, p);
1988 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
1989 			return -1;
1990 		for (i = 0; i < _NUM_FLD; i++) {
1991 			errno = 0;
1992 			int_fld[i] = strtoul(str_fld[i], &end, 0);
1993 			if (errno != 0 || end == str_fld[i] ||
1994 					int_fld[i] > 65535)
1995 				return -1;
1996 		}
1997 
1998 		hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
1999 		nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2000 
2001 		if (hash_index >= nb_entries) {
2002 			printf("Invalid RETA hash index=%d\n", hash_index);
2003 			return -1;
2004 		}
2005 
2006 		idx = hash_index / RTE_RETA_GROUP_SIZE;
2007 		shift = hash_index % RTE_RETA_GROUP_SIZE;
2008 		reta_conf[idx].mask |= (1ULL << shift);
2009 		reta_conf[idx].reta[shift] = nb_queue;
2010 	}
2011 
2012 	return 0;
2013 }
2014 
2015 static void
2016 cmd_set_rss_reta_parsed(void *parsed_result,
2017 			__attribute__((unused)) struct cmdline *cl,
2018 			__attribute__((unused)) void *data)
2019 {
2020 	int ret;
2021 	struct rte_eth_dev_info dev_info;
2022 	struct rte_eth_rss_reta_entry64 reta_conf[8];
2023 	struct cmd_config_rss_reta *res = parsed_result;
2024 
2025 	memset(&dev_info, 0, sizeof(dev_info));
2026 	rte_eth_dev_info_get(res->port_id, &dev_info);
2027 	if (dev_info.reta_size == 0) {
2028 		printf("Redirection table size is 0 which is "
2029 					"invalid for RSS\n");
2030 		return;
2031 	} else
2032 		printf("The reta size of port %d is %u\n",
2033 			res->port_id, dev_info.reta_size);
2034 	if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2035 		printf("Currently do not support more than %u entries of "
2036 			"redirection table\n", ETH_RSS_RETA_SIZE_512);
2037 		return;
2038 	}
2039 
2040 	memset(reta_conf, 0, sizeof(reta_conf));
2041 	if (!strcmp(res->list_name, "reta")) {
2042 		if (parse_reta_config(res->list_of_items, reta_conf,
2043 						dev_info.reta_size)) {
2044 			printf("Invalid RSS Redirection Table "
2045 					"config entered\n");
2046 			return;
2047 		}
2048 		ret = rte_eth_dev_rss_reta_update(res->port_id,
2049 				reta_conf, dev_info.reta_size);
2050 		if (ret != 0)
2051 			printf("Bad redirection table parameter, "
2052 					"return code = %d \n", ret);
2053 	}
2054 }
2055 
2056 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2057 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2058 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2059 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2060 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2061 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
2062 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2063 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2064 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2065 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2066 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2067         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2068                                  NULL);
2069 cmdline_parse_inst_t cmd_config_rss_reta = {
2070 	.f = cmd_set_rss_reta_parsed,
2071 	.data = NULL,
2072 	.help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2073 	.tokens = {
2074 		(void *)&cmd_config_rss_reta_port,
2075 		(void *)&cmd_config_rss_reta_keyword,
2076 		(void *)&cmd_config_rss_reta_port_id,
2077 		(void *)&cmd_config_rss_reta_name,
2078 		(void *)&cmd_config_rss_reta_list_name,
2079 		(void *)&cmd_config_rss_reta_list_of_items,
2080 		NULL,
2081 	},
2082 };
2083 
2084 /* *** SHOW PORT RETA INFO *** */
2085 struct cmd_showport_reta {
2086 	cmdline_fixed_string_t show;
2087 	cmdline_fixed_string_t port;
2088 	uint8_t port_id;
2089 	cmdline_fixed_string_t rss;
2090 	cmdline_fixed_string_t reta;
2091 	uint16_t size;
2092 	cmdline_fixed_string_t list_of_items;
2093 };
2094 
2095 static int
2096 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2097 			   uint16_t nb_entries,
2098 			   char *str)
2099 {
2100 	uint32_t size;
2101 	const char *p, *p0 = str;
2102 	char s[256];
2103 	char *end;
2104 	char *str_fld[8];
2105 	uint16_t i;
2106 	uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2107 			RTE_RETA_GROUP_SIZE;
2108 	int ret;
2109 
2110 	p = strchr(p0, '(');
2111 	if (p == NULL)
2112 		return -1;
2113 	p++;
2114 	p0 = strchr(p, ')');
2115 	if (p0 == NULL)
2116 		return -1;
2117 	size = p0 - p;
2118 	if (size >= sizeof(s)) {
2119 		printf("The string size exceeds the internal buffer size\n");
2120 		return -1;
2121 	}
2122 	snprintf(s, sizeof(s), "%.*s", size, p);
2123 	ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2124 	if (ret <= 0 || ret != num) {
2125 		printf("The bits of masks do not match the number of "
2126 					"reta entries: %u\n", num);
2127 		return -1;
2128 	}
2129 	for (i = 0; i < ret; i++)
2130 		conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2131 
2132 	return 0;
2133 }
2134 
2135 static void
2136 cmd_showport_reta_parsed(void *parsed_result,
2137 			 __attribute__((unused)) struct cmdline *cl,
2138 			 __attribute__((unused)) void *data)
2139 {
2140 	struct cmd_showport_reta *res = parsed_result;
2141 	struct rte_eth_rss_reta_entry64 reta_conf[8];
2142 	struct rte_eth_dev_info dev_info;
2143 
2144 	memset(&dev_info, 0, sizeof(dev_info));
2145 	rte_eth_dev_info_get(res->port_id, &dev_info);
2146 	if (dev_info.reta_size == 0 || res->size != dev_info.reta_size ||
2147 				res->size > ETH_RSS_RETA_SIZE_512) {
2148 		printf("Invalid redirection table size: %u\n", res->size);
2149 		return;
2150 	}
2151 
2152 	memset(reta_conf, 0, sizeof(reta_conf));
2153 	if (showport_parse_reta_config(reta_conf, res->size,
2154 				res->list_of_items) < 0) {
2155 		printf("Invalid string: %s for reta masks\n",
2156 					res->list_of_items);
2157 		return;
2158 	}
2159 	port_rss_reta_info(res->port_id, reta_conf, res->size);
2160 }
2161 
2162 cmdline_parse_token_string_t cmd_showport_reta_show =
2163 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2164 cmdline_parse_token_string_t cmd_showport_reta_port =
2165 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2166 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2167 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
2168 cmdline_parse_token_string_t cmd_showport_reta_rss =
2169 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2170 cmdline_parse_token_string_t cmd_showport_reta_reta =
2171 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2172 cmdline_parse_token_num_t cmd_showport_reta_size =
2173 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2174 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2175 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2176 					list_of_items, NULL);
2177 
2178 cmdline_parse_inst_t cmd_showport_reta = {
2179 	.f = cmd_showport_reta_parsed,
2180 	.data = NULL,
2181 	.help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2182 	.tokens = {
2183 		(void *)&cmd_showport_reta_show,
2184 		(void *)&cmd_showport_reta_port,
2185 		(void *)&cmd_showport_reta_port_id,
2186 		(void *)&cmd_showport_reta_rss,
2187 		(void *)&cmd_showport_reta_reta,
2188 		(void *)&cmd_showport_reta_size,
2189 		(void *)&cmd_showport_reta_list_of_items,
2190 		NULL,
2191 	},
2192 };
2193 
2194 /* *** Show RSS hash configuration *** */
2195 struct cmd_showport_rss_hash {
2196 	cmdline_fixed_string_t show;
2197 	cmdline_fixed_string_t port;
2198 	uint8_t port_id;
2199 	cmdline_fixed_string_t rss_hash;
2200 	cmdline_fixed_string_t rss_type;
2201 	cmdline_fixed_string_t key; /* optional argument */
2202 };
2203 
2204 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2205 				__attribute__((unused)) struct cmdline *cl,
2206 				void *show_rss_key)
2207 {
2208 	struct cmd_showport_rss_hash *res = parsed_result;
2209 
2210 	port_rss_hash_conf_show(res->port_id, res->rss_type,
2211 				show_rss_key != NULL);
2212 }
2213 
2214 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2215 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2216 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2217 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2218 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2219 	TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
2220 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2221 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2222 				 "rss-hash");
2223 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2224 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2225 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2226 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2227 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2228 				 "ipv6-tcp-ex#ipv6-udp-ex");
2229 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2230 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2231 
2232 cmdline_parse_inst_t cmd_showport_rss_hash = {
2233 	.f = cmd_showport_rss_hash_parsed,
2234 	.data = NULL,
2235 	.help_str = "show port <port_id> rss-hash "
2236 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2237 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2238 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2239 	.tokens = {
2240 		(void *)&cmd_showport_rss_hash_show,
2241 		(void *)&cmd_showport_rss_hash_port,
2242 		(void *)&cmd_showport_rss_hash_port_id,
2243 		(void *)&cmd_showport_rss_hash_rss_hash,
2244 		(void *)&cmd_showport_rss_hash_rss_hash_info,
2245 		NULL,
2246 	},
2247 };
2248 
2249 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2250 	.f = cmd_showport_rss_hash_parsed,
2251 	.data = (void *)1,
2252 	.help_str = "show port <port_id> rss-hash "
2253 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2254 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2255 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2256 	.tokens = {
2257 		(void *)&cmd_showport_rss_hash_show,
2258 		(void *)&cmd_showport_rss_hash_port,
2259 		(void *)&cmd_showport_rss_hash_port_id,
2260 		(void *)&cmd_showport_rss_hash_rss_hash,
2261 		(void *)&cmd_showport_rss_hash_rss_hash_info,
2262 		(void *)&cmd_showport_rss_hash_rss_key,
2263 		NULL,
2264 	},
2265 };
2266 
2267 /* *** Configure DCB *** */
2268 struct cmd_config_dcb {
2269 	cmdline_fixed_string_t port;
2270 	cmdline_fixed_string_t config;
2271 	uint8_t port_id;
2272 	cmdline_fixed_string_t dcb;
2273 	cmdline_fixed_string_t vt;
2274 	cmdline_fixed_string_t vt_en;
2275 	uint8_t num_tcs;
2276 	cmdline_fixed_string_t pfc;
2277 	cmdline_fixed_string_t pfc_en;
2278 };
2279 
2280 static void
2281 cmd_config_dcb_parsed(void *parsed_result,
2282                         __attribute__((unused)) struct cmdline *cl,
2283                         __attribute__((unused)) void *data)
2284 {
2285 	struct cmd_config_dcb *res = parsed_result;
2286 	portid_t port_id = res->port_id;
2287 	struct rte_port *port;
2288 	uint8_t pfc_en;
2289 	int ret;
2290 
2291 	port = &ports[port_id];
2292 	/** Check if the port is not started **/
2293 	if (port->port_status != RTE_PORT_STOPPED) {
2294 		printf("Please stop port %d first\n", port_id);
2295 		return;
2296 	}
2297 
2298 	if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2299 		printf("The invalid number of traffic class,"
2300 			" only 4 or 8 allowed.\n");
2301 		return;
2302 	}
2303 
2304 	if (nb_fwd_lcores < res->num_tcs) {
2305 		printf("nb_cores shouldn't be less than number of TCs.\n");
2306 		return;
2307 	}
2308 	if (!strncmp(res->pfc_en, "on", 2))
2309 		pfc_en = 1;
2310 	else
2311 		pfc_en = 0;
2312 
2313 	/* DCB in VT mode */
2314 	if (!strncmp(res->vt_en, "on", 2))
2315 		ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2316 				(enum rte_eth_nb_tcs)res->num_tcs,
2317 				pfc_en);
2318 	else
2319 		ret = init_port_dcb_config(port_id, DCB_ENABLED,
2320 				(enum rte_eth_nb_tcs)res->num_tcs,
2321 				pfc_en);
2322 
2323 
2324 	if (ret != 0) {
2325 		printf("Cannot initialize network ports.\n");
2326 		return;
2327 	}
2328 
2329 	cmd_reconfig_device_queue(port_id, 1, 1);
2330 }
2331 
2332 cmdline_parse_token_string_t cmd_config_dcb_port =
2333         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2334 cmdline_parse_token_string_t cmd_config_dcb_config =
2335         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2336 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2337         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2338 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2339         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2340 cmdline_parse_token_string_t cmd_config_dcb_vt =
2341         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2342 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2343         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2344 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2345         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2346 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2347         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2348 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2349         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2350 
2351 cmdline_parse_inst_t cmd_config_dcb = {
2352 	.f = cmd_config_dcb_parsed,
2353 	.data = NULL,
2354 	.help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2355 	.tokens = {
2356 		(void *)&cmd_config_dcb_port,
2357 		(void *)&cmd_config_dcb_config,
2358 		(void *)&cmd_config_dcb_port_id,
2359 		(void *)&cmd_config_dcb_dcb,
2360 		(void *)&cmd_config_dcb_vt,
2361 		(void *)&cmd_config_dcb_vt_en,
2362 		(void *)&cmd_config_dcb_num_tcs,
2363 		(void *)&cmd_config_dcb_pfc,
2364 		(void *)&cmd_config_dcb_pfc_en,
2365                 NULL,
2366         },
2367 };
2368 
2369 /* *** configure number of packets per burst *** */
2370 struct cmd_config_burst {
2371 	cmdline_fixed_string_t port;
2372 	cmdline_fixed_string_t keyword;
2373 	cmdline_fixed_string_t all;
2374 	cmdline_fixed_string_t name;
2375 	uint16_t value;
2376 };
2377 
2378 static void
2379 cmd_config_burst_parsed(void *parsed_result,
2380 			__attribute__((unused)) struct cmdline *cl,
2381 			__attribute__((unused)) void *data)
2382 {
2383 	struct cmd_config_burst *res = parsed_result;
2384 
2385 	if (!all_ports_stopped()) {
2386 		printf("Please stop all ports first\n");
2387 		return;
2388 	}
2389 
2390 	if (!strcmp(res->name, "burst")) {
2391 		if (res->value < 1 || res->value > MAX_PKT_BURST) {
2392 			printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2393 			return;
2394 		}
2395 		nb_pkt_per_burst = res->value;
2396 	} else {
2397 		printf("Unknown parameter\n");
2398 		return;
2399 	}
2400 
2401 	init_port_config();
2402 
2403 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2404 }
2405 
2406 cmdline_parse_token_string_t cmd_config_burst_port =
2407 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2408 cmdline_parse_token_string_t cmd_config_burst_keyword =
2409 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2410 cmdline_parse_token_string_t cmd_config_burst_all =
2411 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2412 cmdline_parse_token_string_t cmd_config_burst_name =
2413 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2414 cmdline_parse_token_num_t cmd_config_burst_value =
2415 	TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2416 
2417 cmdline_parse_inst_t cmd_config_burst = {
2418 	.f = cmd_config_burst_parsed,
2419 	.data = NULL,
2420 	.help_str = "port config all burst <value>",
2421 	.tokens = {
2422 		(void *)&cmd_config_burst_port,
2423 		(void *)&cmd_config_burst_keyword,
2424 		(void *)&cmd_config_burst_all,
2425 		(void *)&cmd_config_burst_name,
2426 		(void *)&cmd_config_burst_value,
2427 		NULL,
2428 	},
2429 };
2430 
2431 /* *** configure rx/tx queues *** */
2432 struct cmd_config_thresh {
2433 	cmdline_fixed_string_t port;
2434 	cmdline_fixed_string_t keyword;
2435 	cmdline_fixed_string_t all;
2436 	cmdline_fixed_string_t name;
2437 	uint8_t value;
2438 };
2439 
2440 static void
2441 cmd_config_thresh_parsed(void *parsed_result,
2442 			__attribute__((unused)) struct cmdline *cl,
2443 			__attribute__((unused)) void *data)
2444 {
2445 	struct cmd_config_thresh *res = parsed_result;
2446 
2447 	if (!all_ports_stopped()) {
2448 		printf("Please stop all ports first\n");
2449 		return;
2450 	}
2451 
2452 	if (!strcmp(res->name, "txpt"))
2453 		tx_pthresh = res->value;
2454 	else if(!strcmp(res->name, "txht"))
2455 		tx_hthresh = res->value;
2456 	else if(!strcmp(res->name, "txwt"))
2457 		tx_wthresh = res->value;
2458 	else if(!strcmp(res->name, "rxpt"))
2459 		rx_pthresh = res->value;
2460 	else if(!strcmp(res->name, "rxht"))
2461 		rx_hthresh = res->value;
2462 	else if(!strcmp(res->name, "rxwt"))
2463 		rx_wthresh = res->value;
2464 	else {
2465 		printf("Unknown parameter\n");
2466 		return;
2467 	}
2468 
2469 	init_port_config();
2470 
2471 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2472 }
2473 
2474 cmdline_parse_token_string_t cmd_config_thresh_port =
2475 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2476 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2477 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2478 cmdline_parse_token_string_t cmd_config_thresh_all =
2479 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2480 cmdline_parse_token_string_t cmd_config_thresh_name =
2481 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2482 				"txpt#txht#txwt#rxpt#rxht#rxwt");
2483 cmdline_parse_token_num_t cmd_config_thresh_value =
2484 	TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2485 
2486 cmdline_parse_inst_t cmd_config_thresh = {
2487 	.f = cmd_config_thresh_parsed,
2488 	.data = NULL,
2489 	.help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2490 	.tokens = {
2491 		(void *)&cmd_config_thresh_port,
2492 		(void *)&cmd_config_thresh_keyword,
2493 		(void *)&cmd_config_thresh_all,
2494 		(void *)&cmd_config_thresh_name,
2495 		(void *)&cmd_config_thresh_value,
2496 		NULL,
2497 	},
2498 };
2499 
2500 /* *** configure free/rs threshold *** */
2501 struct cmd_config_threshold {
2502 	cmdline_fixed_string_t port;
2503 	cmdline_fixed_string_t keyword;
2504 	cmdline_fixed_string_t all;
2505 	cmdline_fixed_string_t name;
2506 	uint16_t value;
2507 };
2508 
2509 static void
2510 cmd_config_threshold_parsed(void *parsed_result,
2511 			__attribute__((unused)) struct cmdline *cl,
2512 			__attribute__((unused)) void *data)
2513 {
2514 	struct cmd_config_threshold *res = parsed_result;
2515 
2516 	if (!all_ports_stopped()) {
2517 		printf("Please stop all ports first\n");
2518 		return;
2519 	}
2520 
2521 	if (!strcmp(res->name, "txfreet"))
2522 		tx_free_thresh = res->value;
2523 	else if (!strcmp(res->name, "txrst"))
2524 		tx_rs_thresh = res->value;
2525 	else if (!strcmp(res->name, "rxfreet"))
2526 		rx_free_thresh = res->value;
2527 	else {
2528 		printf("Unknown parameter\n");
2529 		return;
2530 	}
2531 
2532 	init_port_config();
2533 
2534 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2535 }
2536 
2537 cmdline_parse_token_string_t cmd_config_threshold_port =
2538 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2539 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2540 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2541 								"config");
2542 cmdline_parse_token_string_t cmd_config_threshold_all =
2543 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2544 cmdline_parse_token_string_t cmd_config_threshold_name =
2545 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2546 						"txfreet#txrst#rxfreet");
2547 cmdline_parse_token_num_t cmd_config_threshold_value =
2548 	TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2549 
2550 cmdline_parse_inst_t cmd_config_threshold = {
2551 	.f = cmd_config_threshold_parsed,
2552 	.data = NULL,
2553 	.help_str = "port config all txfreet|txrst|rxfreet <value>",
2554 	.tokens = {
2555 		(void *)&cmd_config_threshold_port,
2556 		(void *)&cmd_config_threshold_keyword,
2557 		(void *)&cmd_config_threshold_all,
2558 		(void *)&cmd_config_threshold_name,
2559 		(void *)&cmd_config_threshold_value,
2560 		NULL,
2561 	},
2562 };
2563 
2564 /* *** stop *** */
2565 struct cmd_stop_result {
2566 	cmdline_fixed_string_t stop;
2567 };
2568 
2569 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2570 			    __attribute__((unused)) struct cmdline *cl,
2571 			    __attribute__((unused)) void *data)
2572 {
2573 	stop_packet_forwarding();
2574 }
2575 
2576 cmdline_parse_token_string_t cmd_stop_stop =
2577 	TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2578 
2579 cmdline_parse_inst_t cmd_stop = {
2580 	.f = cmd_stop_parsed,
2581 	.data = NULL,
2582 	.help_str = "stop: Stop packet forwarding",
2583 	.tokens = {
2584 		(void *)&cmd_stop_stop,
2585 		NULL,
2586 	},
2587 };
2588 
2589 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2590 
2591 unsigned int
2592 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2593 		unsigned int *parsed_items, int check_unique_values)
2594 {
2595 	unsigned int nb_item;
2596 	unsigned int value;
2597 	unsigned int i;
2598 	unsigned int j;
2599 	int value_ok;
2600 	char c;
2601 
2602 	/*
2603 	 * First parse all items in the list and store their value.
2604 	 */
2605 	value = 0;
2606 	nb_item = 0;
2607 	value_ok = 0;
2608 	for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2609 		c = str[i];
2610 		if ((c >= '0') && (c <= '9')) {
2611 			value = (unsigned int) (value * 10 + (c - '0'));
2612 			value_ok = 1;
2613 			continue;
2614 		}
2615 		if (c != ',') {
2616 			printf("character %c is not a decimal digit\n", c);
2617 			return 0;
2618 		}
2619 		if (! value_ok) {
2620 			printf("No valid value before comma\n");
2621 			return 0;
2622 		}
2623 		if (nb_item < max_items) {
2624 			parsed_items[nb_item] = value;
2625 			value_ok = 0;
2626 			value = 0;
2627 		}
2628 		nb_item++;
2629 	}
2630 	if (nb_item >= max_items) {
2631 		printf("Number of %s = %u > %u (maximum items)\n",
2632 		       item_name, nb_item + 1, max_items);
2633 		return 0;
2634 	}
2635 	parsed_items[nb_item++] = value;
2636 	if (! check_unique_values)
2637 		return nb_item;
2638 
2639 	/*
2640 	 * Then, check that all values in the list are differents.
2641 	 * No optimization here...
2642 	 */
2643 	for (i = 0; i < nb_item; i++) {
2644 		for (j = i + 1; j < nb_item; j++) {
2645 			if (parsed_items[j] == parsed_items[i]) {
2646 				printf("duplicated %s %u at index %u and %u\n",
2647 				       item_name, parsed_items[i], i, j);
2648 				return 0;
2649 			}
2650 		}
2651 	}
2652 	return nb_item;
2653 }
2654 
2655 struct cmd_set_list_result {
2656 	cmdline_fixed_string_t cmd_keyword;
2657 	cmdline_fixed_string_t list_name;
2658 	cmdline_fixed_string_t list_of_items;
2659 };
2660 
2661 static void cmd_set_list_parsed(void *parsed_result,
2662 				__attribute__((unused)) struct cmdline *cl,
2663 				__attribute__((unused)) void *data)
2664 {
2665 	struct cmd_set_list_result *res;
2666 	union {
2667 		unsigned int lcorelist[RTE_MAX_LCORE];
2668 		unsigned int portlist[RTE_MAX_ETHPORTS];
2669 	} parsed_items;
2670 	unsigned int nb_item;
2671 
2672 	if (test_done == 0) {
2673 		printf("Please stop forwarding first\n");
2674 		return;
2675 	}
2676 
2677 	res = parsed_result;
2678 	if (!strcmp(res->list_name, "corelist")) {
2679 		nb_item = parse_item_list(res->list_of_items, "core",
2680 					  RTE_MAX_LCORE,
2681 					  parsed_items.lcorelist, 1);
2682 		if (nb_item > 0) {
2683 			set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2684 			fwd_config_setup();
2685 		}
2686 		return;
2687 	}
2688 	if (!strcmp(res->list_name, "portlist")) {
2689 		nb_item = parse_item_list(res->list_of_items, "port",
2690 					  RTE_MAX_ETHPORTS,
2691 					  parsed_items.portlist, 1);
2692 		if (nb_item > 0) {
2693 			set_fwd_ports_list(parsed_items.portlist, nb_item);
2694 			fwd_config_setup();
2695 		}
2696 	}
2697 }
2698 
2699 cmdline_parse_token_string_t cmd_set_list_keyword =
2700 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2701 				 "set");
2702 cmdline_parse_token_string_t cmd_set_list_name =
2703 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2704 				 "corelist#portlist");
2705 cmdline_parse_token_string_t cmd_set_list_of_items =
2706 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2707 				 NULL);
2708 
2709 cmdline_parse_inst_t cmd_set_fwd_list = {
2710 	.f = cmd_set_list_parsed,
2711 	.data = NULL,
2712 	.help_str = "set corelist|portlist <list0[,list1]*>",
2713 	.tokens = {
2714 		(void *)&cmd_set_list_keyword,
2715 		(void *)&cmd_set_list_name,
2716 		(void *)&cmd_set_list_of_items,
2717 		NULL,
2718 	},
2719 };
2720 
2721 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2722 
2723 struct cmd_setmask_result {
2724 	cmdline_fixed_string_t set;
2725 	cmdline_fixed_string_t mask;
2726 	uint64_t hexavalue;
2727 };
2728 
2729 static void cmd_set_mask_parsed(void *parsed_result,
2730 				__attribute__((unused)) struct cmdline *cl,
2731 				__attribute__((unused)) void *data)
2732 {
2733 	struct cmd_setmask_result *res = parsed_result;
2734 
2735 	if (test_done == 0) {
2736 		printf("Please stop forwarding first\n");
2737 		return;
2738 	}
2739 	if (!strcmp(res->mask, "coremask")) {
2740 		set_fwd_lcores_mask(res->hexavalue);
2741 		fwd_config_setup();
2742 	} else if (!strcmp(res->mask, "portmask")) {
2743 		set_fwd_ports_mask(res->hexavalue);
2744 		fwd_config_setup();
2745 	}
2746 }
2747 
2748 cmdline_parse_token_string_t cmd_setmask_set =
2749 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2750 cmdline_parse_token_string_t cmd_setmask_mask =
2751 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2752 				 "coremask#portmask");
2753 cmdline_parse_token_num_t cmd_setmask_value =
2754 	TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2755 
2756 cmdline_parse_inst_t cmd_set_fwd_mask = {
2757 	.f = cmd_set_mask_parsed,
2758 	.data = NULL,
2759 	.help_str = "set coremask|portmask <hexadecimal value>",
2760 	.tokens = {
2761 		(void *)&cmd_setmask_set,
2762 		(void *)&cmd_setmask_mask,
2763 		(void *)&cmd_setmask_value,
2764 		NULL,
2765 	},
2766 };
2767 
2768 /*
2769  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2770  */
2771 struct cmd_set_result {
2772 	cmdline_fixed_string_t set;
2773 	cmdline_fixed_string_t what;
2774 	uint16_t value;
2775 };
2776 
2777 static void cmd_set_parsed(void *parsed_result,
2778 			   __attribute__((unused)) struct cmdline *cl,
2779 			   __attribute__((unused)) void *data)
2780 {
2781 	struct cmd_set_result *res = parsed_result;
2782 	if (!strcmp(res->what, "nbport")) {
2783 		set_fwd_ports_number(res->value);
2784 		fwd_config_setup();
2785 	} else if (!strcmp(res->what, "nbcore")) {
2786 		set_fwd_lcores_number(res->value);
2787 		fwd_config_setup();
2788 	} else if (!strcmp(res->what, "burst"))
2789 		set_nb_pkt_per_burst(res->value);
2790 	else if (!strcmp(res->what, "verbose"))
2791 		set_verbose_level(res->value);
2792 }
2793 
2794 cmdline_parse_token_string_t cmd_set_set =
2795 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2796 cmdline_parse_token_string_t cmd_set_what =
2797 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2798 				 "nbport#nbcore#burst#verbose");
2799 cmdline_parse_token_num_t cmd_set_value =
2800 	TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2801 
2802 cmdline_parse_inst_t cmd_set_numbers = {
2803 	.f = cmd_set_parsed,
2804 	.data = NULL,
2805 	.help_str = "set nbport|nbcore|burst|verbose <value>",
2806 	.tokens = {
2807 		(void *)&cmd_set_set,
2808 		(void *)&cmd_set_what,
2809 		(void *)&cmd_set_value,
2810 		NULL,
2811 	},
2812 };
2813 
2814 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2815 
2816 struct cmd_set_txpkts_result {
2817 	cmdline_fixed_string_t cmd_keyword;
2818 	cmdline_fixed_string_t txpkts;
2819 	cmdline_fixed_string_t seg_lengths;
2820 };
2821 
2822 static void
2823 cmd_set_txpkts_parsed(void *parsed_result,
2824 		      __attribute__((unused)) struct cmdline *cl,
2825 		      __attribute__((unused)) void *data)
2826 {
2827 	struct cmd_set_txpkts_result *res;
2828 	unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2829 	unsigned int nb_segs;
2830 
2831 	res = parsed_result;
2832 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2833 				  RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2834 	if (nb_segs > 0)
2835 		set_tx_pkt_segments(seg_lengths, nb_segs);
2836 }
2837 
2838 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2839 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2840 				 cmd_keyword, "set");
2841 cmdline_parse_token_string_t cmd_set_txpkts_name =
2842 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2843 				 txpkts, "txpkts");
2844 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2845 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2846 				 seg_lengths, NULL);
2847 
2848 cmdline_parse_inst_t cmd_set_txpkts = {
2849 	.f = cmd_set_txpkts_parsed,
2850 	.data = NULL,
2851 	.help_str = "set txpkts <len0[,len1]*>",
2852 	.tokens = {
2853 		(void *)&cmd_set_txpkts_keyword,
2854 		(void *)&cmd_set_txpkts_name,
2855 		(void *)&cmd_set_txpkts_lengths,
2856 		NULL,
2857 	},
2858 };
2859 
2860 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2861 
2862 struct cmd_set_txsplit_result {
2863 	cmdline_fixed_string_t cmd_keyword;
2864 	cmdline_fixed_string_t txsplit;
2865 	cmdline_fixed_string_t mode;
2866 };
2867 
2868 static void
2869 cmd_set_txsplit_parsed(void *parsed_result,
2870 		      __attribute__((unused)) struct cmdline *cl,
2871 		      __attribute__((unused)) void *data)
2872 {
2873 	struct cmd_set_txsplit_result *res;
2874 
2875 	res = parsed_result;
2876 	set_tx_pkt_split(res->mode);
2877 }
2878 
2879 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2880 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2881 				 cmd_keyword, "set");
2882 cmdline_parse_token_string_t cmd_set_txsplit_name =
2883 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2884 				 txsplit, "txsplit");
2885 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2886 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2887 				 mode, NULL);
2888 
2889 cmdline_parse_inst_t cmd_set_txsplit = {
2890 	.f = cmd_set_txsplit_parsed,
2891 	.data = NULL,
2892 	.help_str = "set txsplit on|off|rand",
2893 	.tokens = {
2894 		(void *)&cmd_set_txsplit_keyword,
2895 		(void *)&cmd_set_txsplit_name,
2896 		(void *)&cmd_set_txsplit_mode,
2897 		NULL,
2898 	},
2899 };
2900 
2901 /* *** CONFIG TX QUEUE FLAGS *** */
2902 
2903 struct cmd_config_txqflags_result {
2904 	cmdline_fixed_string_t port;
2905 	cmdline_fixed_string_t config;
2906 	cmdline_fixed_string_t all;
2907 	cmdline_fixed_string_t what;
2908 	int32_t hexvalue;
2909 };
2910 
2911 static void cmd_config_txqflags_parsed(void *parsed_result,
2912 				__attribute__((unused)) struct cmdline *cl,
2913 				__attribute__((unused)) void *data)
2914 {
2915 	struct cmd_config_txqflags_result *res = parsed_result;
2916 
2917 	if (!all_ports_stopped()) {
2918 		printf("Please stop all ports first\n");
2919 		return;
2920 	}
2921 
2922 	if (strcmp(res->what, "txqflags")) {
2923 		printf("Unknown parameter\n");
2924 		return;
2925 	}
2926 
2927 	if (res->hexvalue >= 0) {
2928 		txq_flags = res->hexvalue;
2929 	} else {
2930 		printf("txqflags must be >= 0\n");
2931 		return;
2932 	}
2933 
2934 	init_port_config();
2935 
2936 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2937 }
2938 
2939 cmdline_parse_token_string_t cmd_config_txqflags_port =
2940 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
2941 				 "port");
2942 cmdline_parse_token_string_t cmd_config_txqflags_config =
2943 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
2944 				 "config");
2945 cmdline_parse_token_string_t cmd_config_txqflags_all =
2946 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
2947 				 "all");
2948 cmdline_parse_token_string_t cmd_config_txqflags_what =
2949 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
2950 				 "txqflags");
2951 cmdline_parse_token_num_t cmd_config_txqflags_value =
2952 	TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
2953 				hexvalue, INT32);
2954 
2955 cmdline_parse_inst_t cmd_config_txqflags = {
2956 	.f = cmd_config_txqflags_parsed,
2957 	.data = NULL,
2958 	.help_str = "port config all txqflags <value>",
2959 	.tokens = {
2960 		(void *)&cmd_config_txqflags_port,
2961 		(void *)&cmd_config_txqflags_config,
2962 		(void *)&cmd_config_txqflags_all,
2963 		(void *)&cmd_config_txqflags_what,
2964 		(void *)&cmd_config_txqflags_value,
2965 		NULL,
2966 	},
2967 };
2968 
2969 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
2970 struct cmd_rx_vlan_filter_all_result {
2971 	cmdline_fixed_string_t rx_vlan;
2972 	cmdline_fixed_string_t what;
2973 	cmdline_fixed_string_t all;
2974 	uint8_t port_id;
2975 };
2976 
2977 static void
2978 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
2979 			      __attribute__((unused)) struct cmdline *cl,
2980 			      __attribute__((unused)) void *data)
2981 {
2982 	struct cmd_rx_vlan_filter_all_result *res = parsed_result;
2983 
2984 	if (!strcmp(res->what, "add"))
2985 		rx_vlan_all_filter_set(res->port_id, 1);
2986 	else
2987 		rx_vlan_all_filter_set(res->port_id, 0);
2988 }
2989 
2990 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
2991 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2992 				 rx_vlan, "rx_vlan");
2993 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
2994 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2995 				 what, "add#rm");
2996 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
2997 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2998 				 all, "all");
2999 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3000 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3001 			      port_id, UINT8);
3002 
3003 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3004 	.f = cmd_rx_vlan_filter_all_parsed,
3005 	.data = NULL,
3006 	.help_str = "rx_vlan add|rm all <port_id>: "
3007 		"Add/Remove all identifiers to/from the set of VLAN "
3008 		"identifiers filtered by a port",
3009 	.tokens = {
3010 		(void *)&cmd_rx_vlan_filter_all_rx_vlan,
3011 		(void *)&cmd_rx_vlan_filter_all_what,
3012 		(void *)&cmd_rx_vlan_filter_all_all,
3013 		(void *)&cmd_rx_vlan_filter_all_portid,
3014 		NULL,
3015 	},
3016 };
3017 
3018 /* *** VLAN OFFLOAD SET ON A PORT *** */
3019 struct cmd_vlan_offload_result {
3020 	cmdline_fixed_string_t vlan;
3021 	cmdline_fixed_string_t set;
3022 	cmdline_fixed_string_t vlan_type;
3023 	cmdline_fixed_string_t what;
3024 	cmdline_fixed_string_t on;
3025 	cmdline_fixed_string_t port_id;
3026 };
3027 
3028 static void
3029 cmd_vlan_offload_parsed(void *parsed_result,
3030 			  __attribute__((unused)) struct cmdline *cl,
3031 			  __attribute__((unused)) void *data)
3032 {
3033 	int on;
3034 	struct cmd_vlan_offload_result *res = parsed_result;
3035 	char *str;
3036 	int i, len = 0;
3037 	portid_t port_id = 0;
3038 	unsigned int tmp;
3039 
3040 	str = res->port_id;
3041 	len = strnlen(str, STR_TOKEN_SIZE);
3042 	i = 0;
3043 	/* Get port_id first */
3044 	while(i < len){
3045 		if(str[i] == ',')
3046 			break;
3047 
3048 		i++;
3049 	}
3050 	str[i]='\0';
3051 	tmp = strtoul(str, NULL, 0);
3052 	/* If port_id greater that what portid_t can represent, return */
3053 	if(tmp >= RTE_MAX_ETHPORTS)
3054 		return;
3055 	port_id = (portid_t)tmp;
3056 
3057 	if (!strcmp(res->on, "on"))
3058 		on = 1;
3059 	else
3060 		on = 0;
3061 
3062 	if (!strcmp(res->what, "strip"))
3063 		rx_vlan_strip_set(port_id,  on);
3064 	else if(!strcmp(res->what, "stripq")){
3065 		uint16_t queue_id = 0;
3066 
3067 		/* No queue_id, return */
3068 		if(i + 1 >= len) {
3069 			printf("must specify (port,queue_id)\n");
3070 			return;
3071 		}
3072 		tmp = strtoul(str + i + 1, NULL, 0);
3073 		/* If queue_id greater that what 16-bits can represent, return */
3074 		if(tmp > 0xffff)
3075 			return;
3076 
3077 		queue_id = (uint16_t)tmp;
3078 		rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3079 	}
3080 	else if (!strcmp(res->what, "filter"))
3081 		rx_vlan_filter_set(port_id, on);
3082 	else
3083 		vlan_extend_set(port_id, on);
3084 
3085 	return;
3086 }
3087 
3088 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3089 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3090 				 vlan, "vlan");
3091 cmdline_parse_token_string_t cmd_vlan_offload_set =
3092 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3093 				 set, "set");
3094 cmdline_parse_token_string_t cmd_vlan_offload_what =
3095 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3096 				 what, "strip#filter#qinq#stripq");
3097 cmdline_parse_token_string_t cmd_vlan_offload_on =
3098 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3099 			      on, "on#off");
3100 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3101 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3102 			      port_id, NULL);
3103 
3104 cmdline_parse_inst_t cmd_vlan_offload = {
3105 	.f = cmd_vlan_offload_parsed,
3106 	.data = NULL,
3107 	.help_str = "vlan set strip|filter|qinq|stripq on|off "
3108 		"<port_id[,queue_id]>: "
3109 		"Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3110 	.tokens = {
3111 		(void *)&cmd_vlan_offload_vlan,
3112 		(void *)&cmd_vlan_offload_set,
3113 		(void *)&cmd_vlan_offload_what,
3114 		(void *)&cmd_vlan_offload_on,
3115 		(void *)&cmd_vlan_offload_portid,
3116 		NULL,
3117 	},
3118 };
3119 
3120 /* *** VLAN TPID SET ON A PORT *** */
3121 struct cmd_vlan_tpid_result {
3122 	cmdline_fixed_string_t vlan;
3123 	cmdline_fixed_string_t set;
3124 	cmdline_fixed_string_t vlan_type;
3125 	cmdline_fixed_string_t what;
3126 	uint16_t tp_id;
3127 	uint8_t port_id;
3128 };
3129 
3130 static void
3131 cmd_vlan_tpid_parsed(void *parsed_result,
3132 			  __attribute__((unused)) struct cmdline *cl,
3133 			  __attribute__((unused)) void *data)
3134 {
3135 	struct cmd_vlan_tpid_result *res = parsed_result;
3136 	enum rte_vlan_type vlan_type;
3137 
3138 	if (!strcmp(res->vlan_type, "inner"))
3139 		vlan_type = ETH_VLAN_TYPE_INNER;
3140 	else if (!strcmp(res->vlan_type, "outer"))
3141 		vlan_type = ETH_VLAN_TYPE_OUTER;
3142 	else {
3143 		printf("Unknown vlan type\n");
3144 		return;
3145 	}
3146 	vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3147 }
3148 
3149 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3150 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3151 				 vlan, "vlan");
3152 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3153 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3154 				 set, "set");
3155 cmdline_parse_token_string_t cmd_vlan_type =
3156 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3157 				 vlan_type, "inner#outer");
3158 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3159 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3160 				 what, "tpid");
3161 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3162 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3163 			      tp_id, UINT16);
3164 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3165 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3166 			      port_id, UINT8);
3167 
3168 cmdline_parse_inst_t cmd_vlan_tpid = {
3169 	.f = cmd_vlan_tpid_parsed,
3170 	.data = NULL,
3171 	.help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3172 		"Set the VLAN Ether type",
3173 	.tokens = {
3174 		(void *)&cmd_vlan_tpid_vlan,
3175 		(void *)&cmd_vlan_tpid_set,
3176 		(void *)&cmd_vlan_type,
3177 		(void *)&cmd_vlan_tpid_what,
3178 		(void *)&cmd_vlan_tpid_tpid,
3179 		(void *)&cmd_vlan_tpid_portid,
3180 		NULL,
3181 	},
3182 };
3183 
3184 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3185 struct cmd_rx_vlan_filter_result {
3186 	cmdline_fixed_string_t rx_vlan;
3187 	cmdline_fixed_string_t what;
3188 	uint16_t vlan_id;
3189 	uint8_t port_id;
3190 };
3191 
3192 static void
3193 cmd_rx_vlan_filter_parsed(void *parsed_result,
3194 			  __attribute__((unused)) struct cmdline *cl,
3195 			  __attribute__((unused)) void *data)
3196 {
3197 	struct cmd_rx_vlan_filter_result *res = parsed_result;
3198 
3199 	if (!strcmp(res->what, "add"))
3200 		rx_vft_set(res->port_id, res->vlan_id, 1);
3201 	else
3202 		rx_vft_set(res->port_id, res->vlan_id, 0);
3203 }
3204 
3205 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3206 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3207 				 rx_vlan, "rx_vlan");
3208 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3209 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3210 				 what, "add#rm");
3211 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3212 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3213 			      vlan_id, UINT16);
3214 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3215 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3216 			      port_id, UINT8);
3217 
3218 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3219 	.f = cmd_rx_vlan_filter_parsed,
3220 	.data = NULL,
3221 	.help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3222 		"Add/Remove a VLAN identifier to/from the set of VLAN "
3223 		"identifiers filtered by a port",
3224 	.tokens = {
3225 		(void *)&cmd_rx_vlan_filter_rx_vlan,
3226 		(void *)&cmd_rx_vlan_filter_what,
3227 		(void *)&cmd_rx_vlan_filter_vlanid,
3228 		(void *)&cmd_rx_vlan_filter_portid,
3229 		NULL,
3230 	},
3231 };
3232 
3233 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3234 struct cmd_tx_vlan_set_result {
3235 	cmdline_fixed_string_t tx_vlan;
3236 	cmdline_fixed_string_t set;
3237 	uint8_t port_id;
3238 	uint16_t vlan_id;
3239 };
3240 
3241 static void
3242 cmd_tx_vlan_set_parsed(void *parsed_result,
3243 		       __attribute__((unused)) struct cmdline *cl,
3244 		       __attribute__((unused)) void *data)
3245 {
3246 	struct cmd_tx_vlan_set_result *res = parsed_result;
3247 
3248 	tx_vlan_set(res->port_id, res->vlan_id);
3249 }
3250 
3251 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3252 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3253 				 tx_vlan, "tx_vlan");
3254 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3255 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3256 				 set, "set");
3257 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3258 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3259 			      port_id, UINT8);
3260 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3261 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3262 			      vlan_id, UINT16);
3263 
3264 cmdline_parse_inst_t cmd_tx_vlan_set = {
3265 	.f = cmd_tx_vlan_set_parsed,
3266 	.data = NULL,
3267 	.help_str = "tx_vlan set <port_id> <vlan_id>: "
3268 		"Enable hardware insertion of a single VLAN header "
3269 		"with a given TAG Identifier in packets sent on a port",
3270 	.tokens = {
3271 		(void *)&cmd_tx_vlan_set_tx_vlan,
3272 		(void *)&cmd_tx_vlan_set_set,
3273 		(void *)&cmd_tx_vlan_set_portid,
3274 		(void *)&cmd_tx_vlan_set_vlanid,
3275 		NULL,
3276 	},
3277 };
3278 
3279 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3280 struct cmd_tx_vlan_set_qinq_result {
3281 	cmdline_fixed_string_t tx_vlan;
3282 	cmdline_fixed_string_t set;
3283 	uint8_t port_id;
3284 	uint16_t vlan_id;
3285 	uint16_t vlan_id_outer;
3286 };
3287 
3288 static void
3289 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3290 			    __attribute__((unused)) struct cmdline *cl,
3291 			    __attribute__((unused)) void *data)
3292 {
3293 	struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3294 
3295 	tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3296 }
3297 
3298 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3299 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3300 		tx_vlan, "tx_vlan");
3301 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3302 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3303 		set, "set");
3304 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3305 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3306 		port_id, UINT8);
3307 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3308 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3309 		vlan_id, UINT16);
3310 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3311 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3312 		vlan_id_outer, UINT16);
3313 
3314 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3315 	.f = cmd_tx_vlan_set_qinq_parsed,
3316 	.data = NULL,
3317 	.help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3318 		"Enable hardware insertion of double VLAN header "
3319 		"with given TAG Identifiers in packets sent on a port",
3320 	.tokens = {
3321 		(void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3322 		(void *)&cmd_tx_vlan_set_qinq_set,
3323 		(void *)&cmd_tx_vlan_set_qinq_portid,
3324 		(void *)&cmd_tx_vlan_set_qinq_vlanid,
3325 		(void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3326 		NULL,
3327 	},
3328 };
3329 
3330 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3331 struct cmd_tx_vlan_set_pvid_result {
3332 	cmdline_fixed_string_t tx_vlan;
3333 	cmdline_fixed_string_t set;
3334 	cmdline_fixed_string_t pvid;
3335 	uint8_t port_id;
3336 	uint16_t vlan_id;
3337 	cmdline_fixed_string_t mode;
3338 };
3339 
3340 static void
3341 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3342 			    __attribute__((unused)) struct cmdline *cl,
3343 			    __attribute__((unused)) void *data)
3344 {
3345 	struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3346 
3347 	if (strcmp(res->mode, "on") == 0)
3348 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3349 	else
3350 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3351 }
3352 
3353 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3354 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3355 				 tx_vlan, "tx_vlan");
3356 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3357 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3358 				 set, "set");
3359 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3360 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3361 				 pvid, "pvid");
3362 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3363 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3364 			     port_id, UINT8);
3365 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3366 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3367 			      vlan_id, UINT16);
3368 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3369 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3370 				 mode, "on#off");
3371 
3372 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3373 	.f = cmd_tx_vlan_set_pvid_parsed,
3374 	.data = NULL,
3375 	.help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3376 	.tokens = {
3377 		(void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3378 		(void *)&cmd_tx_vlan_set_pvid_set,
3379 		(void *)&cmd_tx_vlan_set_pvid_pvid,
3380 		(void *)&cmd_tx_vlan_set_pvid_port_id,
3381 		(void *)&cmd_tx_vlan_set_pvid_vlan_id,
3382 		(void *)&cmd_tx_vlan_set_pvid_mode,
3383 		NULL,
3384 	},
3385 };
3386 
3387 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3388 struct cmd_tx_vlan_reset_result {
3389 	cmdline_fixed_string_t tx_vlan;
3390 	cmdline_fixed_string_t reset;
3391 	uint8_t port_id;
3392 };
3393 
3394 static void
3395 cmd_tx_vlan_reset_parsed(void *parsed_result,
3396 			 __attribute__((unused)) struct cmdline *cl,
3397 			 __attribute__((unused)) void *data)
3398 {
3399 	struct cmd_tx_vlan_reset_result *res = parsed_result;
3400 
3401 	tx_vlan_reset(res->port_id);
3402 }
3403 
3404 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3405 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3406 				 tx_vlan, "tx_vlan");
3407 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3408 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3409 				 reset, "reset");
3410 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3411 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3412 			      port_id, UINT8);
3413 
3414 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3415 	.f = cmd_tx_vlan_reset_parsed,
3416 	.data = NULL,
3417 	.help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3418 		"VLAN header in packets sent on a port",
3419 	.tokens = {
3420 		(void *)&cmd_tx_vlan_reset_tx_vlan,
3421 		(void *)&cmd_tx_vlan_reset_reset,
3422 		(void *)&cmd_tx_vlan_reset_portid,
3423 		NULL,
3424 	},
3425 };
3426 
3427 
3428 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3429 struct cmd_csum_result {
3430 	cmdline_fixed_string_t csum;
3431 	cmdline_fixed_string_t mode;
3432 	cmdline_fixed_string_t proto;
3433 	cmdline_fixed_string_t hwsw;
3434 	uint8_t port_id;
3435 };
3436 
3437 static void
3438 csum_show(int port_id)
3439 {
3440 	struct rte_eth_dev_info dev_info;
3441 	uint16_t ol_flags;
3442 
3443 	ol_flags = ports[port_id].tx_ol_flags;
3444 	printf("Parse tunnel is %s\n",
3445 		(ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3446 	printf("IP checksum offload is %s\n",
3447 		(ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3448 	printf("UDP checksum offload is %s\n",
3449 		(ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3450 	printf("TCP checksum offload is %s\n",
3451 		(ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3452 	printf("SCTP checksum offload is %s\n",
3453 		(ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3454 	printf("Outer-Ip checksum offload is %s\n",
3455 		(ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3456 
3457 	/* display warnings if configuration is not supported by the NIC */
3458 	rte_eth_dev_info_get(port_id, &dev_info);
3459 	if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3460 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3461 		printf("Warning: hardware IP checksum enabled but not "
3462 			"supported by port %d\n", port_id);
3463 	}
3464 	if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3465 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3466 		printf("Warning: hardware UDP checksum enabled but not "
3467 			"supported by port %d\n", port_id);
3468 	}
3469 	if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3470 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3471 		printf("Warning: hardware TCP checksum enabled but not "
3472 			"supported by port %d\n", port_id);
3473 	}
3474 	if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3475 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3476 		printf("Warning: hardware SCTP checksum enabled but not "
3477 			"supported by port %d\n", port_id);
3478 	}
3479 	if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3480 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3481 		printf("Warning: hardware outer IP checksum enabled but not "
3482 			"supported by port %d\n", port_id);
3483 	}
3484 }
3485 
3486 static void
3487 cmd_csum_parsed(void *parsed_result,
3488 		       __attribute__((unused)) struct cmdline *cl,
3489 		       __attribute__((unused)) void *data)
3490 {
3491 	struct cmd_csum_result *res = parsed_result;
3492 	int hw = 0;
3493 	uint16_t mask = 0;
3494 
3495 	if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3496 		printf("invalid port %d\n", res->port_id);
3497 		return;
3498 	}
3499 
3500 	if (!strcmp(res->mode, "set")) {
3501 
3502 		if (!strcmp(res->hwsw, "hw"))
3503 			hw = 1;
3504 
3505 		if (!strcmp(res->proto, "ip")) {
3506 			mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3507 		} else if (!strcmp(res->proto, "udp")) {
3508 			mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3509 		} else if (!strcmp(res->proto, "tcp")) {
3510 			mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3511 		} else if (!strcmp(res->proto, "sctp")) {
3512 			mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3513 		} else if (!strcmp(res->proto, "outer-ip")) {
3514 			mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3515 		}
3516 
3517 		if (hw)
3518 			ports[res->port_id].tx_ol_flags |= mask;
3519 		else
3520 			ports[res->port_id].tx_ol_flags &= (~mask);
3521 	}
3522 	csum_show(res->port_id);
3523 }
3524 
3525 cmdline_parse_token_string_t cmd_csum_csum =
3526 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3527 				csum, "csum");
3528 cmdline_parse_token_string_t cmd_csum_mode =
3529 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3530 				mode, "set");
3531 cmdline_parse_token_string_t cmd_csum_proto =
3532 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3533 				proto, "ip#tcp#udp#sctp#outer-ip");
3534 cmdline_parse_token_string_t cmd_csum_hwsw =
3535 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3536 				hwsw, "hw#sw");
3537 cmdline_parse_token_num_t cmd_csum_portid =
3538 	TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3539 				port_id, UINT8);
3540 
3541 cmdline_parse_inst_t cmd_csum_set = {
3542 	.f = cmd_csum_parsed,
3543 	.data = NULL,
3544 	.help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3545 		"Enable/Disable hardware calculation of L3/L4 checksum when "
3546 		"using csum forward engine",
3547 	.tokens = {
3548 		(void *)&cmd_csum_csum,
3549 		(void *)&cmd_csum_mode,
3550 		(void *)&cmd_csum_proto,
3551 		(void *)&cmd_csum_hwsw,
3552 		(void *)&cmd_csum_portid,
3553 		NULL,
3554 	},
3555 };
3556 
3557 cmdline_parse_token_string_t cmd_csum_mode_show =
3558 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3559 				mode, "show");
3560 
3561 cmdline_parse_inst_t cmd_csum_show = {
3562 	.f = cmd_csum_parsed,
3563 	.data = NULL,
3564 	.help_str = "csum show <port_id>: Show checksum offload configuration",
3565 	.tokens = {
3566 		(void *)&cmd_csum_csum,
3567 		(void *)&cmd_csum_mode_show,
3568 		(void *)&cmd_csum_portid,
3569 		NULL,
3570 	},
3571 };
3572 
3573 /* Enable/disable tunnel parsing */
3574 struct cmd_csum_tunnel_result {
3575 	cmdline_fixed_string_t csum;
3576 	cmdline_fixed_string_t parse;
3577 	cmdline_fixed_string_t onoff;
3578 	uint8_t port_id;
3579 };
3580 
3581 static void
3582 cmd_csum_tunnel_parsed(void *parsed_result,
3583 		       __attribute__((unused)) struct cmdline *cl,
3584 		       __attribute__((unused)) void *data)
3585 {
3586 	struct cmd_csum_tunnel_result *res = parsed_result;
3587 
3588 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3589 		return;
3590 
3591 	if (!strcmp(res->onoff, "on"))
3592 		ports[res->port_id].tx_ol_flags |=
3593 			TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3594 	else
3595 		ports[res->port_id].tx_ol_flags &=
3596 			(~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3597 
3598 	csum_show(res->port_id);
3599 }
3600 
3601 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3602 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3603 				csum, "csum");
3604 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3605 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3606 				parse, "parse_tunnel");
3607 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3608 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3609 				onoff, "on#off");
3610 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3611 	TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3612 				port_id, UINT8);
3613 
3614 cmdline_parse_inst_t cmd_csum_tunnel = {
3615 	.f = cmd_csum_tunnel_parsed,
3616 	.data = NULL,
3617 	.help_str = "csum parse_tunnel on|off <port_id>: "
3618 		"Enable/Disable parsing of tunnels for csum engine",
3619 	.tokens = {
3620 		(void *)&cmd_csum_tunnel_csum,
3621 		(void *)&cmd_csum_tunnel_parse,
3622 		(void *)&cmd_csum_tunnel_onoff,
3623 		(void *)&cmd_csum_tunnel_portid,
3624 		NULL,
3625 	},
3626 };
3627 
3628 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3629 struct cmd_tso_set_result {
3630 	cmdline_fixed_string_t tso;
3631 	cmdline_fixed_string_t mode;
3632 	uint16_t tso_segsz;
3633 	uint8_t port_id;
3634 };
3635 
3636 static void
3637 cmd_tso_set_parsed(void *parsed_result,
3638 		       __attribute__((unused)) struct cmdline *cl,
3639 		       __attribute__((unused)) void *data)
3640 {
3641 	struct cmd_tso_set_result *res = parsed_result;
3642 	struct rte_eth_dev_info dev_info;
3643 
3644 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3645 		return;
3646 
3647 	if (!strcmp(res->mode, "set"))
3648 		ports[res->port_id].tso_segsz = res->tso_segsz;
3649 
3650 	if (ports[res->port_id].tso_segsz == 0)
3651 		printf("TSO for non-tunneled packets is disabled\n");
3652 	else
3653 		printf("TSO segment size for non-tunneled packets is %d\n",
3654 			ports[res->port_id].tso_segsz);
3655 
3656 	/* display warnings if configuration is not supported by the NIC */
3657 	rte_eth_dev_info_get(res->port_id, &dev_info);
3658 	if ((ports[res->port_id].tso_segsz != 0) &&
3659 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3660 		printf("Warning: TSO enabled but not "
3661 			"supported by port %d\n", res->port_id);
3662 	}
3663 }
3664 
3665 cmdline_parse_token_string_t cmd_tso_set_tso =
3666 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3667 				tso, "tso");
3668 cmdline_parse_token_string_t cmd_tso_set_mode =
3669 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3670 				mode, "set");
3671 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3672 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3673 				tso_segsz, UINT16);
3674 cmdline_parse_token_num_t cmd_tso_set_portid =
3675 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3676 				port_id, UINT8);
3677 
3678 cmdline_parse_inst_t cmd_tso_set = {
3679 	.f = cmd_tso_set_parsed,
3680 	.data = NULL,
3681 	.help_str = "tso set <tso_segsz> <port_id>: "
3682 		"Set TSO segment size of non-tunneled packets for csum engine "
3683 		"(0 to disable)",
3684 	.tokens = {
3685 		(void *)&cmd_tso_set_tso,
3686 		(void *)&cmd_tso_set_mode,
3687 		(void *)&cmd_tso_set_tso_segsz,
3688 		(void *)&cmd_tso_set_portid,
3689 		NULL,
3690 	},
3691 };
3692 
3693 cmdline_parse_token_string_t cmd_tso_show_mode =
3694 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3695 				mode, "show");
3696 
3697 
3698 cmdline_parse_inst_t cmd_tso_show = {
3699 	.f = cmd_tso_set_parsed,
3700 	.data = NULL,
3701 	.help_str = "tso show <port_id>: "
3702 		"Show TSO segment size of non-tunneled packets for csum engine",
3703 	.tokens = {
3704 		(void *)&cmd_tso_set_tso,
3705 		(void *)&cmd_tso_show_mode,
3706 		(void *)&cmd_tso_set_portid,
3707 		NULL,
3708 	},
3709 };
3710 
3711 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3712 struct cmd_tunnel_tso_set_result {
3713 	cmdline_fixed_string_t tso;
3714 	cmdline_fixed_string_t mode;
3715 	uint16_t tso_segsz;
3716 	uint8_t port_id;
3717 };
3718 
3719 static void
3720 check_tunnel_tso_nic_support(uint8_t port_id)
3721 {
3722 	struct rte_eth_dev_info dev_info;
3723 
3724 	rte_eth_dev_info_get(port_id, &dev_info);
3725 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3726 		printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3727 		       "supported by port %d\n", port_id);
3728 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3729 		printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3730 			"supported by port %d\n", port_id);
3731 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3732 		printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3733 		       "supported by port %d\n", port_id);
3734 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3735 		printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3736 		       "supported by port %d\n", port_id);
3737 }
3738 
3739 static void
3740 cmd_tunnel_tso_set_parsed(void *parsed_result,
3741 			  __attribute__((unused)) struct cmdline *cl,
3742 			  __attribute__((unused)) void *data)
3743 {
3744 	struct cmd_tunnel_tso_set_result *res = parsed_result;
3745 
3746 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3747 		return;
3748 
3749 	if (!strcmp(res->mode, "set"))
3750 		ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3751 
3752 	if (ports[res->port_id].tunnel_tso_segsz == 0)
3753 		printf("TSO for tunneled packets is disabled\n");
3754 	else {
3755 		printf("TSO segment size for tunneled packets is %d\n",
3756 			ports[res->port_id].tunnel_tso_segsz);
3757 
3758 		/* Below conditions are needed to make it work:
3759 		 * (1) tunnel TSO is supported by the NIC;
3760 		 * (2) "csum parse_tunnel" must be set so that tunneled pkts
3761 		 * are recognized;
3762 		 * (3) for tunneled pkts with outer L3 of IPv4,
3763 		 * "csum set outer-ip" must be set to hw, because after tso,
3764 		 * total_len of outer IP header is changed, and the checksum
3765 		 * of outer IP header calculated by sw should be wrong; that
3766 		 * is not necessary for IPv6 tunneled pkts because there's no
3767 		 * checksum in IP header anymore.
3768 		 */
3769 		check_tunnel_tso_nic_support(res->port_id);
3770 
3771 		if (!(ports[res->port_id].tx_ol_flags &
3772 		      TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3773 			printf("Warning: csum parse_tunnel must be set "
3774 				"so that tunneled packets are recognized\n");
3775 		if (!(ports[res->port_id].tx_ol_flags &
3776 		      TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3777 			printf("Warning: csum set outer-ip must be set to hw "
3778 				"if outer L3 is IPv4; not necessary for IPv6\n");
3779 	}
3780 }
3781 
3782 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3783 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3784 				tso, "tunnel_tso");
3785 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3786 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3787 				mode, "set");
3788 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3789 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3790 				tso_segsz, UINT16);
3791 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3792 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3793 				port_id, UINT8);
3794 
3795 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3796 	.f = cmd_tunnel_tso_set_parsed,
3797 	.data = NULL,
3798 	.help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3799 		"Set TSO segment size of tunneled packets for csum engine "
3800 		"(0 to disable)",
3801 	.tokens = {
3802 		(void *)&cmd_tunnel_tso_set_tso,
3803 		(void *)&cmd_tunnel_tso_set_mode,
3804 		(void *)&cmd_tunnel_tso_set_tso_segsz,
3805 		(void *)&cmd_tunnel_tso_set_portid,
3806 		NULL,
3807 	},
3808 };
3809 
3810 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3811 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3812 				mode, "show");
3813 
3814 
3815 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3816 	.f = cmd_tunnel_tso_set_parsed,
3817 	.data = NULL,
3818 	.help_str = "tunnel_tso show <port_id> "
3819 		"Show TSO segment size of tunneled packets for csum engine",
3820 	.tokens = {
3821 		(void *)&cmd_tunnel_tso_set_tso,
3822 		(void *)&cmd_tunnel_tso_show_mode,
3823 		(void *)&cmd_tunnel_tso_set_portid,
3824 		NULL,
3825 	},
3826 };
3827 
3828 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
3829 struct cmd_set_flush_rx {
3830 	cmdline_fixed_string_t set;
3831 	cmdline_fixed_string_t flush_rx;
3832 	cmdline_fixed_string_t mode;
3833 };
3834 
3835 static void
3836 cmd_set_flush_rx_parsed(void *parsed_result,
3837 		__attribute__((unused)) struct cmdline *cl,
3838 		__attribute__((unused)) void *data)
3839 {
3840 	struct cmd_set_flush_rx *res = parsed_result;
3841 	no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3842 }
3843 
3844 cmdline_parse_token_string_t cmd_setflushrx_set =
3845 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3846 			set, "set");
3847 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
3848 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3849 			flush_rx, "flush_rx");
3850 cmdline_parse_token_string_t cmd_setflushrx_mode =
3851 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3852 			mode, "on#off");
3853 
3854 
3855 cmdline_parse_inst_t cmd_set_flush_rx = {
3856 	.f = cmd_set_flush_rx_parsed,
3857 	.help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
3858 	.data = NULL,
3859 	.tokens = {
3860 		(void *)&cmd_setflushrx_set,
3861 		(void *)&cmd_setflushrx_flush_rx,
3862 		(void *)&cmd_setflushrx_mode,
3863 		NULL,
3864 	},
3865 };
3866 
3867 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
3868 struct cmd_set_link_check {
3869 	cmdline_fixed_string_t set;
3870 	cmdline_fixed_string_t link_check;
3871 	cmdline_fixed_string_t mode;
3872 };
3873 
3874 static void
3875 cmd_set_link_check_parsed(void *parsed_result,
3876 		__attribute__((unused)) struct cmdline *cl,
3877 		__attribute__((unused)) void *data)
3878 {
3879 	struct cmd_set_link_check *res = parsed_result;
3880 	no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3881 }
3882 
3883 cmdline_parse_token_string_t cmd_setlinkcheck_set =
3884 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3885 			set, "set");
3886 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
3887 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3888 			link_check, "link_check");
3889 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
3890 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3891 			mode, "on#off");
3892 
3893 
3894 cmdline_parse_inst_t cmd_set_link_check = {
3895 	.f = cmd_set_link_check_parsed,
3896 	.help_str = "set link_check on|off: Enable/Disable link status check "
3897 	            "when starting/stopping a port",
3898 	.data = NULL,
3899 	.tokens = {
3900 		(void *)&cmd_setlinkcheck_set,
3901 		(void *)&cmd_setlinkcheck_link_check,
3902 		(void *)&cmd_setlinkcheck_mode,
3903 		NULL,
3904 	},
3905 };
3906 
3907 #ifdef RTE_NIC_BYPASS
3908 /* *** SET NIC BYPASS MODE *** */
3909 struct cmd_set_bypass_mode_result {
3910 	cmdline_fixed_string_t set;
3911 	cmdline_fixed_string_t bypass;
3912 	cmdline_fixed_string_t mode;
3913 	cmdline_fixed_string_t value;
3914 	uint8_t port_id;
3915 };
3916 
3917 static void
3918 cmd_set_bypass_mode_parsed(void *parsed_result,
3919 		__attribute__((unused)) struct cmdline *cl,
3920 		__attribute__((unused)) void *data)
3921 {
3922 	struct cmd_set_bypass_mode_result *res = parsed_result;
3923 	portid_t port_id = res->port_id;
3924 	uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3925 
3926 	if (!strcmp(res->value, "bypass"))
3927 		bypass_mode = RTE_BYPASS_MODE_BYPASS;
3928 	else if (!strcmp(res->value, "isolate"))
3929 		bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3930 	else
3931 		bypass_mode = RTE_BYPASS_MODE_NORMAL;
3932 
3933 	/* Set the bypass mode for the relevant port. */
3934 	if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) {
3935 		printf("\t Failed to set bypass mode for port = %d.\n", port_id);
3936 	}
3937 }
3938 
3939 cmdline_parse_token_string_t cmd_setbypass_mode_set =
3940 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3941 			set, "set");
3942 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
3943 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3944 			bypass, "bypass");
3945 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
3946 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3947 			mode, "mode");
3948 cmdline_parse_token_string_t cmd_setbypass_mode_value =
3949 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3950 			value, "normal#bypass#isolate");
3951 cmdline_parse_token_num_t cmd_setbypass_mode_port =
3952 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
3953 				port_id, UINT8);
3954 
3955 cmdline_parse_inst_t cmd_set_bypass_mode = {
3956 	.f = cmd_set_bypass_mode_parsed,
3957 	.help_str = "set bypass mode normal|bypass|isolate <port_id>: "
3958 	            "Set the NIC bypass mode for port_id",
3959 	.data = NULL,
3960 	.tokens = {
3961 		(void *)&cmd_setbypass_mode_set,
3962 		(void *)&cmd_setbypass_mode_bypass,
3963 		(void *)&cmd_setbypass_mode_mode,
3964 		(void *)&cmd_setbypass_mode_value,
3965 		(void *)&cmd_setbypass_mode_port,
3966 		NULL,
3967 	},
3968 };
3969 
3970 /* *** SET NIC BYPASS EVENT *** */
3971 struct cmd_set_bypass_event_result {
3972 	cmdline_fixed_string_t set;
3973 	cmdline_fixed_string_t bypass;
3974 	cmdline_fixed_string_t event;
3975 	cmdline_fixed_string_t event_value;
3976 	cmdline_fixed_string_t mode;
3977 	cmdline_fixed_string_t mode_value;
3978 	uint8_t port_id;
3979 };
3980 
3981 static void
3982 cmd_set_bypass_event_parsed(void *parsed_result,
3983 		__attribute__((unused)) struct cmdline *cl,
3984 		__attribute__((unused)) void *data)
3985 {
3986 	int32_t rc;
3987 	struct cmd_set_bypass_event_result *res = parsed_result;
3988 	portid_t port_id = res->port_id;
3989 	uint32_t bypass_event = RTE_BYPASS_EVENT_NONE;
3990 	uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3991 
3992 	if (!strcmp(res->event_value, "timeout"))
3993 		bypass_event = RTE_BYPASS_EVENT_TIMEOUT;
3994 	else if (!strcmp(res->event_value, "os_on"))
3995 		bypass_event = RTE_BYPASS_EVENT_OS_ON;
3996 	else if (!strcmp(res->event_value, "os_off"))
3997 		bypass_event = RTE_BYPASS_EVENT_OS_OFF;
3998 	else if (!strcmp(res->event_value, "power_on"))
3999 		bypass_event = RTE_BYPASS_EVENT_POWER_ON;
4000 	else if (!strcmp(res->event_value, "power_off"))
4001 		bypass_event = RTE_BYPASS_EVENT_POWER_OFF;
4002 	else
4003 		bypass_event = RTE_BYPASS_EVENT_NONE;
4004 
4005 	if (!strcmp(res->mode_value, "bypass"))
4006 		bypass_mode = RTE_BYPASS_MODE_BYPASS;
4007 	else if (!strcmp(res->mode_value, "isolate"))
4008 		bypass_mode = RTE_BYPASS_MODE_ISOLATE;
4009 	else
4010 		bypass_mode = RTE_BYPASS_MODE_NORMAL;
4011 
4012 	/* Set the watchdog timeout. */
4013 	if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) {
4014 
4015 		rc = -EINVAL;
4016 		if (!RTE_BYPASS_TMT_VALID(bypass_timeout) ||
4017 				(rc = rte_eth_dev_wd_timeout_store(port_id,
4018 				bypass_timeout)) != 0) {
4019 			printf("Failed to set timeout value %u "
4020 				"for port %d, errto code: %d.\n",
4021 				bypass_timeout, port_id, rc);
4022 		}
4023 	}
4024 
4025 	/* Set the bypass event to transition to bypass mode. */
4026 	if (0 != rte_eth_dev_bypass_event_store(port_id,
4027 			bypass_event, bypass_mode)) {
4028 		printf("\t Failed to set bypass event for port = %d.\n", port_id);
4029 	}
4030 
4031 }
4032 
4033 cmdline_parse_token_string_t cmd_setbypass_event_set =
4034 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4035 			set, "set");
4036 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4037 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4038 			bypass, "bypass");
4039 cmdline_parse_token_string_t cmd_setbypass_event_event =
4040 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4041 			event, "event");
4042 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4043 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4044 			event_value, "none#timeout#os_off#os_on#power_on#power_off");
4045 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4046 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4047 			mode, "mode");
4048 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4049 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4050 			mode_value, "normal#bypass#isolate");
4051 cmdline_parse_token_num_t cmd_setbypass_event_port =
4052 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4053 				port_id, UINT8);
4054 
4055 cmdline_parse_inst_t cmd_set_bypass_event = {
4056 	.f = cmd_set_bypass_event_parsed,
4057 	.help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4058 		"power_off mode normal|bypass|isolate <port_id>: "
4059 		"Set the NIC bypass event mode for port_id",
4060 	.data = NULL,
4061 	.tokens = {
4062 		(void *)&cmd_setbypass_event_set,
4063 		(void *)&cmd_setbypass_event_bypass,
4064 		(void *)&cmd_setbypass_event_event,
4065 		(void *)&cmd_setbypass_event_event_value,
4066 		(void *)&cmd_setbypass_event_mode,
4067 		(void *)&cmd_setbypass_event_mode_value,
4068 		(void *)&cmd_setbypass_event_port,
4069 		NULL,
4070 	},
4071 };
4072 
4073 
4074 /* *** SET NIC BYPASS TIMEOUT *** */
4075 struct cmd_set_bypass_timeout_result {
4076 	cmdline_fixed_string_t set;
4077 	cmdline_fixed_string_t bypass;
4078 	cmdline_fixed_string_t timeout;
4079 	cmdline_fixed_string_t value;
4080 };
4081 
4082 static void
4083 cmd_set_bypass_timeout_parsed(void *parsed_result,
4084 		__attribute__((unused)) struct cmdline *cl,
4085 		__attribute__((unused)) void *data)
4086 {
4087 	struct cmd_set_bypass_timeout_result *res = parsed_result;
4088 
4089 	if (!strcmp(res->value, "1.5"))
4090 		bypass_timeout = RTE_BYPASS_TMT_1_5_SEC;
4091 	else if (!strcmp(res->value, "2"))
4092 		bypass_timeout = RTE_BYPASS_TMT_2_SEC;
4093 	else if (!strcmp(res->value, "3"))
4094 		bypass_timeout = RTE_BYPASS_TMT_3_SEC;
4095 	else if (!strcmp(res->value, "4"))
4096 		bypass_timeout = RTE_BYPASS_TMT_4_SEC;
4097 	else if (!strcmp(res->value, "8"))
4098 		bypass_timeout = RTE_BYPASS_TMT_8_SEC;
4099 	else if (!strcmp(res->value, "16"))
4100 		bypass_timeout = RTE_BYPASS_TMT_16_SEC;
4101 	else if (!strcmp(res->value, "32"))
4102 		bypass_timeout = RTE_BYPASS_TMT_32_SEC;
4103 	else
4104 		bypass_timeout = RTE_BYPASS_TMT_OFF;
4105 }
4106 
4107 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4108 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4109 			set, "set");
4110 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4111 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4112 			bypass, "bypass");
4113 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4114 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4115 			timeout, "timeout");
4116 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4117 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4118 			value, "0#1.5#2#3#4#8#16#32");
4119 
4120 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4121 	.f = cmd_set_bypass_timeout_parsed,
4122 	.help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4123 		"Set the NIC bypass watchdog timeout in seconds",
4124 	.data = NULL,
4125 	.tokens = {
4126 		(void *)&cmd_setbypass_timeout_set,
4127 		(void *)&cmd_setbypass_timeout_bypass,
4128 		(void *)&cmd_setbypass_timeout_timeout,
4129 		(void *)&cmd_setbypass_timeout_value,
4130 		NULL,
4131 	},
4132 };
4133 
4134 /* *** SHOW NIC BYPASS MODE *** */
4135 struct cmd_show_bypass_config_result {
4136 	cmdline_fixed_string_t show;
4137 	cmdline_fixed_string_t bypass;
4138 	cmdline_fixed_string_t config;
4139 	uint8_t port_id;
4140 };
4141 
4142 static void
4143 cmd_show_bypass_config_parsed(void *parsed_result,
4144 		__attribute__((unused)) struct cmdline *cl,
4145 		__attribute__((unused)) void *data)
4146 {
4147 	struct cmd_show_bypass_config_result *res = parsed_result;
4148 	uint32_t event_mode;
4149 	uint32_t bypass_mode;
4150 	portid_t port_id = res->port_id;
4151 	uint32_t timeout = bypass_timeout;
4152 	int i;
4153 
4154 	static const char * const timeouts[RTE_BYPASS_TMT_NUM] =
4155 		{"off", "1.5", "2", "3", "4", "8", "16", "32"};
4156 	static const char * const modes[RTE_BYPASS_MODE_NUM] =
4157 		{"UNKNOWN", "normal", "bypass", "isolate"};
4158 	static const char * const events[RTE_BYPASS_EVENT_NUM] = {
4159 		"NONE",
4160 		"OS/board on",
4161 		"power supply on",
4162 		"OS/board off",
4163 		"power supply off",
4164 		"timeout"};
4165 	int num_events = (sizeof events) / (sizeof events[0]);
4166 
4167 	/* Display the bypass mode.*/
4168 	if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) {
4169 		printf("\tFailed to get bypass mode for port = %d\n", port_id);
4170 		return;
4171 	}
4172 	else {
4173 		if (!RTE_BYPASS_MODE_VALID(bypass_mode))
4174 			bypass_mode = RTE_BYPASS_MODE_NONE;
4175 
4176 		printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4177 	}
4178 
4179 	/* Display the bypass timeout.*/
4180 	if (!RTE_BYPASS_TMT_VALID(timeout))
4181 		timeout = RTE_BYPASS_TMT_OFF;
4182 
4183 	printf("\tbypass timeout = %s\n", timeouts[timeout]);
4184 
4185 	/* Display the bypass events and associated modes. */
4186 	for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) {
4187 
4188 		if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) {
4189 			printf("\tFailed to get bypass mode for event = %s\n",
4190 				events[i]);
4191 		} else {
4192 			if (!RTE_BYPASS_MODE_VALID(event_mode))
4193 				event_mode = RTE_BYPASS_MODE_NONE;
4194 
4195 			printf("\tbypass event: %-16s = %s\n", events[i],
4196 				modes[event_mode]);
4197 		}
4198 	}
4199 }
4200 
4201 cmdline_parse_token_string_t cmd_showbypass_config_show =
4202 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4203 			show, "show");
4204 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4205 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4206 			bypass, "bypass");
4207 cmdline_parse_token_string_t cmd_showbypass_config_config =
4208 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4209 			config, "config");
4210 cmdline_parse_token_num_t cmd_showbypass_config_port =
4211 	TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4212 				port_id, UINT8);
4213 
4214 cmdline_parse_inst_t cmd_show_bypass_config = {
4215 	.f = cmd_show_bypass_config_parsed,
4216 	.help_str = "show bypass config <port_id>: "
4217 	            "Show the NIC bypass config for port_id",
4218 	.data = NULL,
4219 	.tokens = {
4220 		(void *)&cmd_showbypass_config_show,
4221 		(void *)&cmd_showbypass_config_bypass,
4222 		(void *)&cmd_showbypass_config_config,
4223 		(void *)&cmd_showbypass_config_port,
4224 		NULL,
4225 	},
4226 };
4227 #endif
4228 
4229 #ifdef RTE_LIBRTE_PMD_BOND
4230 /* *** SET BONDING MODE *** */
4231 struct cmd_set_bonding_mode_result {
4232 	cmdline_fixed_string_t set;
4233 	cmdline_fixed_string_t bonding;
4234 	cmdline_fixed_string_t mode;
4235 	uint8_t value;
4236 	uint8_t port_id;
4237 };
4238 
4239 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4240 		__attribute__((unused))  struct cmdline *cl,
4241 		__attribute__((unused)) void *data)
4242 {
4243 	struct cmd_set_bonding_mode_result *res = parsed_result;
4244 	portid_t port_id = res->port_id;
4245 
4246 	/* Set the bonding mode for the relevant port. */
4247 	if (0 != rte_eth_bond_mode_set(port_id, res->value))
4248 		printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4249 }
4250 
4251 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4252 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4253 		set, "set");
4254 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4255 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4256 		bonding, "bonding");
4257 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4258 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4259 		mode, "mode");
4260 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4261 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4262 		value, UINT8);
4263 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4264 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4265 		port_id, UINT8);
4266 
4267 cmdline_parse_inst_t cmd_set_bonding_mode = {
4268 		.f = cmd_set_bonding_mode_parsed,
4269 		.help_str = "set bonding mode <mode_value> <port_id>: "
4270 			"Set the bonding mode for port_id",
4271 		.data = NULL,
4272 		.tokens = {
4273 				(void *) &cmd_setbonding_mode_set,
4274 				(void *) &cmd_setbonding_mode_bonding,
4275 				(void *) &cmd_setbonding_mode_mode,
4276 				(void *) &cmd_setbonding_mode_value,
4277 				(void *) &cmd_setbonding_mode_port,
4278 				NULL
4279 		}
4280 };
4281 
4282 /* *** SET BALANCE XMIT POLICY *** */
4283 struct cmd_set_bonding_balance_xmit_policy_result {
4284 	cmdline_fixed_string_t set;
4285 	cmdline_fixed_string_t bonding;
4286 	cmdline_fixed_string_t balance_xmit_policy;
4287 	uint8_t port_id;
4288 	cmdline_fixed_string_t policy;
4289 };
4290 
4291 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4292 		__attribute__((unused))  struct cmdline *cl,
4293 		__attribute__((unused)) void *data)
4294 {
4295 	struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4296 	portid_t port_id = res->port_id;
4297 	uint8_t policy;
4298 
4299 	if (!strcmp(res->policy, "l2")) {
4300 		policy = BALANCE_XMIT_POLICY_LAYER2;
4301 	} else if (!strcmp(res->policy, "l23")) {
4302 		policy = BALANCE_XMIT_POLICY_LAYER23;
4303 	} else if (!strcmp(res->policy, "l34")) {
4304 		policy = BALANCE_XMIT_POLICY_LAYER34;
4305 	} else {
4306 		printf("\t Invalid xmit policy selection");
4307 		return;
4308 	}
4309 
4310 	/* Set the bonding mode for the relevant port. */
4311 	if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4312 		printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4313 				port_id);
4314 	}
4315 }
4316 
4317 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4318 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4319 		set, "set");
4320 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4321 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4322 		bonding, "bonding");
4323 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4324 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4325 		balance_xmit_policy, "balance_xmit_policy");
4326 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4327 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4328 		port_id, UINT8);
4329 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4330 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4331 		policy, "l2#l23#l34");
4332 
4333 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4334 		.f = cmd_set_bonding_balance_xmit_policy_parsed,
4335 		.help_str = "set bonding balance_xmit_policy <port_id> "
4336 			"l2|l23|l34: "
4337 			"Set the bonding balance_xmit_policy for port_id",
4338 		.data = NULL,
4339 		.tokens = {
4340 				(void *)&cmd_setbonding_balance_xmit_policy_set,
4341 				(void *)&cmd_setbonding_balance_xmit_policy_bonding,
4342 				(void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4343 				(void *)&cmd_setbonding_balance_xmit_policy_port,
4344 				(void *)&cmd_setbonding_balance_xmit_policy_policy,
4345 				NULL
4346 		}
4347 };
4348 
4349 /* *** SHOW NIC BONDING CONFIGURATION *** */
4350 struct cmd_show_bonding_config_result {
4351 	cmdline_fixed_string_t show;
4352 	cmdline_fixed_string_t bonding;
4353 	cmdline_fixed_string_t config;
4354 	uint8_t port_id;
4355 };
4356 
4357 static void cmd_show_bonding_config_parsed(void *parsed_result,
4358 		__attribute__((unused))  struct cmdline *cl,
4359 		__attribute__((unused)) void *data)
4360 {
4361 	struct cmd_show_bonding_config_result *res = parsed_result;
4362 	int bonding_mode;
4363 	uint8_t slaves[RTE_MAX_ETHPORTS];
4364 	int num_slaves, num_active_slaves;
4365 	int primary_id;
4366 	int i;
4367 	portid_t port_id = res->port_id;
4368 
4369 	/* Display the bonding mode.*/
4370 	bonding_mode = rte_eth_bond_mode_get(port_id);
4371 	if (bonding_mode < 0) {
4372 		printf("\tFailed to get bonding mode for port = %d\n", port_id);
4373 		return;
4374 	} else
4375 		printf("\tBonding mode: %d\n", bonding_mode);
4376 
4377 	if (bonding_mode == BONDING_MODE_BALANCE) {
4378 		int balance_xmit_policy;
4379 
4380 		balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4381 		if (balance_xmit_policy < 0) {
4382 			printf("\tFailed to get balance xmit policy for port = %d\n",
4383 					port_id);
4384 			return;
4385 		} else {
4386 			printf("\tBalance Xmit Policy: ");
4387 
4388 			switch (balance_xmit_policy) {
4389 			case BALANCE_XMIT_POLICY_LAYER2:
4390 				printf("BALANCE_XMIT_POLICY_LAYER2");
4391 				break;
4392 			case BALANCE_XMIT_POLICY_LAYER23:
4393 				printf("BALANCE_XMIT_POLICY_LAYER23");
4394 				break;
4395 			case BALANCE_XMIT_POLICY_LAYER34:
4396 				printf("BALANCE_XMIT_POLICY_LAYER34");
4397 				break;
4398 			}
4399 			printf("\n");
4400 		}
4401 	}
4402 
4403 	num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4404 
4405 	if (num_slaves < 0) {
4406 		printf("\tFailed to get slave list for port = %d\n", port_id);
4407 		return;
4408 	}
4409 	if (num_slaves > 0) {
4410 		printf("\tSlaves (%d): [", num_slaves);
4411 		for (i = 0; i < num_slaves - 1; i++)
4412 			printf("%d ", slaves[i]);
4413 
4414 		printf("%d]\n", slaves[num_slaves - 1]);
4415 	} else {
4416 		printf("\tSlaves: []\n");
4417 
4418 	}
4419 
4420 	num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4421 			RTE_MAX_ETHPORTS);
4422 
4423 	if (num_active_slaves < 0) {
4424 		printf("\tFailed to get active slave list for port = %d\n", port_id);
4425 		return;
4426 	}
4427 	if (num_active_slaves > 0) {
4428 		printf("\tActive Slaves (%d): [", num_active_slaves);
4429 		for (i = 0; i < num_active_slaves - 1; i++)
4430 			printf("%d ", slaves[i]);
4431 
4432 		printf("%d]\n", slaves[num_active_slaves - 1]);
4433 
4434 	} else {
4435 		printf("\tActive Slaves: []\n");
4436 
4437 	}
4438 
4439 	primary_id = rte_eth_bond_primary_get(port_id);
4440 	if (primary_id < 0) {
4441 		printf("\tFailed to get primary slave for port = %d\n", port_id);
4442 		return;
4443 	} else
4444 		printf("\tPrimary: [%d]\n", primary_id);
4445 
4446 }
4447 
4448 cmdline_parse_token_string_t cmd_showbonding_config_show =
4449 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4450 		show, "show");
4451 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4452 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4453 		bonding, "bonding");
4454 cmdline_parse_token_string_t cmd_showbonding_config_config =
4455 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4456 		config, "config");
4457 cmdline_parse_token_num_t cmd_showbonding_config_port =
4458 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4459 		port_id, UINT8);
4460 
4461 cmdline_parse_inst_t cmd_show_bonding_config = {
4462 		.f = cmd_show_bonding_config_parsed,
4463 		.help_str = "show bonding config <port_id>: "
4464 			"Show the bonding config for port_id",
4465 		.data = NULL,
4466 		.tokens = {
4467 				(void *)&cmd_showbonding_config_show,
4468 				(void *)&cmd_showbonding_config_bonding,
4469 				(void *)&cmd_showbonding_config_config,
4470 				(void *)&cmd_showbonding_config_port,
4471 				NULL
4472 		}
4473 };
4474 
4475 /* *** SET BONDING PRIMARY *** */
4476 struct cmd_set_bonding_primary_result {
4477 	cmdline_fixed_string_t set;
4478 	cmdline_fixed_string_t bonding;
4479 	cmdline_fixed_string_t primary;
4480 	uint8_t slave_id;
4481 	uint8_t port_id;
4482 };
4483 
4484 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4485 		__attribute__((unused))  struct cmdline *cl,
4486 		__attribute__((unused)) void *data)
4487 {
4488 	struct cmd_set_bonding_primary_result *res = parsed_result;
4489 	portid_t master_port_id = res->port_id;
4490 	portid_t slave_port_id = res->slave_id;
4491 
4492 	/* Set the primary slave for a bonded device. */
4493 	if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4494 		printf("\t Failed to set primary slave for port = %d.\n",
4495 				master_port_id);
4496 		return;
4497 	}
4498 	init_port_config();
4499 }
4500 
4501 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4502 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4503 		set, "set");
4504 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4505 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4506 		bonding, "bonding");
4507 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4508 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4509 		primary, "primary");
4510 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4511 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4512 		slave_id, UINT8);
4513 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4514 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4515 		port_id, UINT8);
4516 
4517 cmdline_parse_inst_t cmd_set_bonding_primary = {
4518 		.f = cmd_set_bonding_primary_parsed,
4519 		.help_str = "set bonding primary <slave_id> <port_id>: "
4520 			"Set the primary slave for port_id",
4521 		.data = NULL,
4522 		.tokens = {
4523 				(void *)&cmd_setbonding_primary_set,
4524 				(void *)&cmd_setbonding_primary_bonding,
4525 				(void *)&cmd_setbonding_primary_primary,
4526 				(void *)&cmd_setbonding_primary_slave,
4527 				(void *)&cmd_setbonding_primary_port,
4528 				NULL
4529 		}
4530 };
4531 
4532 /* *** ADD SLAVE *** */
4533 struct cmd_add_bonding_slave_result {
4534 	cmdline_fixed_string_t add;
4535 	cmdline_fixed_string_t bonding;
4536 	cmdline_fixed_string_t slave;
4537 	uint8_t slave_id;
4538 	uint8_t port_id;
4539 };
4540 
4541 static void cmd_add_bonding_slave_parsed(void *parsed_result,
4542 		__attribute__((unused))  struct cmdline *cl,
4543 		__attribute__((unused)) void *data)
4544 {
4545 	struct cmd_add_bonding_slave_result *res = parsed_result;
4546 	portid_t master_port_id = res->port_id;
4547 	portid_t slave_port_id = res->slave_id;
4548 
4549 	/* Set the primary slave for a bonded device. */
4550 	if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
4551 		printf("\t Failed to add slave %d to master port = %d.\n",
4552 				slave_port_id, master_port_id);
4553 		return;
4554 	}
4555 	init_port_config();
4556 	set_port_slave_flag(slave_port_id);
4557 }
4558 
4559 cmdline_parse_token_string_t cmd_addbonding_slave_add =
4560 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4561 		add, "add");
4562 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
4563 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4564 		bonding, "bonding");
4565 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
4566 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4567 		slave, "slave");
4568 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
4569 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4570 		slave_id, UINT8);
4571 cmdline_parse_token_num_t cmd_addbonding_slave_port =
4572 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4573 		port_id, UINT8);
4574 
4575 cmdline_parse_inst_t cmd_add_bonding_slave = {
4576 		.f = cmd_add_bonding_slave_parsed,
4577 		.help_str = "add bonding slave <slave_id> <port_id>: "
4578 			"Add a slave device to a bonded device",
4579 		.data = NULL,
4580 		.tokens = {
4581 				(void *)&cmd_addbonding_slave_add,
4582 				(void *)&cmd_addbonding_slave_bonding,
4583 				(void *)&cmd_addbonding_slave_slave,
4584 				(void *)&cmd_addbonding_slave_slaveid,
4585 				(void *)&cmd_addbonding_slave_port,
4586 				NULL
4587 		}
4588 };
4589 
4590 /* *** REMOVE SLAVE *** */
4591 struct cmd_remove_bonding_slave_result {
4592 	cmdline_fixed_string_t remove;
4593 	cmdline_fixed_string_t bonding;
4594 	cmdline_fixed_string_t slave;
4595 	uint8_t slave_id;
4596 	uint8_t port_id;
4597 };
4598 
4599 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
4600 		__attribute__((unused))  struct cmdline *cl,
4601 		__attribute__((unused)) void *data)
4602 {
4603 	struct cmd_remove_bonding_slave_result *res = parsed_result;
4604 	portid_t master_port_id = res->port_id;
4605 	portid_t slave_port_id = res->slave_id;
4606 
4607 	/* Set the primary slave for a bonded device. */
4608 	if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
4609 		printf("\t Failed to remove slave %d from master port = %d.\n",
4610 				slave_port_id, master_port_id);
4611 		return;
4612 	}
4613 	init_port_config();
4614 	clear_port_slave_flag(slave_port_id);
4615 }
4616 
4617 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
4618 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4619 				remove, "remove");
4620 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
4621 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4622 				bonding, "bonding");
4623 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
4624 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4625 				slave, "slave");
4626 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
4627 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4628 				slave_id, UINT8);
4629 cmdline_parse_token_num_t cmd_removebonding_slave_port =
4630 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4631 				port_id, UINT8);
4632 
4633 cmdline_parse_inst_t cmd_remove_bonding_slave = {
4634 		.f = cmd_remove_bonding_slave_parsed,
4635 		.help_str = "remove bonding slave <slave_id> <port_id>: "
4636 			"Remove a slave device from a bonded device",
4637 		.data = NULL,
4638 		.tokens = {
4639 				(void *)&cmd_removebonding_slave_remove,
4640 				(void *)&cmd_removebonding_slave_bonding,
4641 				(void *)&cmd_removebonding_slave_slave,
4642 				(void *)&cmd_removebonding_slave_slaveid,
4643 				(void *)&cmd_removebonding_slave_port,
4644 				NULL
4645 		}
4646 };
4647 
4648 /* *** CREATE BONDED DEVICE *** */
4649 struct cmd_create_bonded_device_result {
4650 	cmdline_fixed_string_t create;
4651 	cmdline_fixed_string_t bonded;
4652 	cmdline_fixed_string_t device;
4653 	uint8_t mode;
4654 	uint8_t socket;
4655 };
4656 
4657 static int bond_dev_num = 0;
4658 
4659 static void cmd_create_bonded_device_parsed(void *parsed_result,
4660 		__attribute__((unused))  struct cmdline *cl,
4661 		__attribute__((unused)) void *data)
4662 {
4663 	struct cmd_create_bonded_device_result *res = parsed_result;
4664 	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
4665 	int port_id;
4666 
4667 	if (test_done == 0) {
4668 		printf("Please stop forwarding first\n");
4669 		return;
4670 	}
4671 
4672 	snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bond_testpmd_%d",
4673 			bond_dev_num++);
4674 
4675 	/* Create a new bonded device. */
4676 	port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
4677 	if (port_id < 0) {
4678 		printf("\t Failed to create bonded device.\n");
4679 		return;
4680 	} else {
4681 		printf("Created new bonded device %s on (port %d).\n", ethdev_name,
4682 				port_id);
4683 
4684 		/* Update number of ports */
4685 		nb_ports = rte_eth_dev_count();
4686 		reconfig(port_id, res->socket);
4687 		rte_eth_promiscuous_enable(port_id);
4688 	}
4689 
4690 }
4691 
4692 cmdline_parse_token_string_t cmd_createbonded_device_create =
4693 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4694 				create, "create");
4695 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
4696 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4697 				bonded, "bonded");
4698 cmdline_parse_token_string_t cmd_createbonded_device_device =
4699 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4700 				device, "device");
4701 cmdline_parse_token_num_t cmd_createbonded_device_mode =
4702 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4703 				mode, UINT8);
4704 cmdline_parse_token_num_t cmd_createbonded_device_socket =
4705 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4706 				socket, UINT8);
4707 
4708 cmdline_parse_inst_t cmd_create_bonded_device = {
4709 		.f = cmd_create_bonded_device_parsed,
4710 		.help_str = "create bonded device <mode> <socket>: "
4711 			"Create a new bonded device with specific bonding mode and socket",
4712 		.data = NULL,
4713 		.tokens = {
4714 				(void *)&cmd_createbonded_device_create,
4715 				(void *)&cmd_createbonded_device_bonded,
4716 				(void *)&cmd_createbonded_device_device,
4717 				(void *)&cmd_createbonded_device_mode,
4718 				(void *)&cmd_createbonded_device_socket,
4719 				NULL
4720 		}
4721 };
4722 
4723 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
4724 struct cmd_set_bond_mac_addr_result {
4725 	cmdline_fixed_string_t set;
4726 	cmdline_fixed_string_t bonding;
4727 	cmdline_fixed_string_t mac_addr;
4728 	uint8_t port_num;
4729 	struct ether_addr address;
4730 };
4731 
4732 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
4733 		__attribute__((unused))  struct cmdline *cl,
4734 		__attribute__((unused)) void *data)
4735 {
4736 	struct cmd_set_bond_mac_addr_result *res = parsed_result;
4737 	int ret;
4738 
4739 	if (port_id_is_invalid(res->port_num, ENABLED_WARN))
4740 		return;
4741 
4742 	ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
4743 
4744 	/* check the return value and print it if is < 0 */
4745 	if (ret < 0)
4746 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4747 }
4748 
4749 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
4750 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
4751 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
4752 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
4753 				"bonding");
4754 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
4755 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
4756 				"mac_addr");
4757 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
4758 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
4759 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
4760 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
4761 
4762 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
4763 		.f = cmd_set_bond_mac_addr_parsed,
4764 		.data = (void *) 0,
4765 		.help_str = "set bonding mac_addr <port_id> <mac_addr>",
4766 		.tokens = {
4767 				(void *)&cmd_set_bond_mac_addr_set,
4768 				(void *)&cmd_set_bond_mac_addr_bonding,
4769 				(void *)&cmd_set_bond_mac_addr_mac,
4770 				(void *)&cmd_set_bond_mac_addr_portnum,
4771 				(void *)&cmd_set_bond_mac_addr_addr,
4772 				NULL
4773 		}
4774 };
4775 
4776 
4777 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
4778 struct cmd_set_bond_mon_period_result {
4779 	cmdline_fixed_string_t set;
4780 	cmdline_fixed_string_t bonding;
4781 	cmdline_fixed_string_t mon_period;
4782 	uint8_t port_num;
4783 	uint32_t period_ms;
4784 };
4785 
4786 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
4787 		__attribute__((unused))  struct cmdline *cl,
4788 		__attribute__((unused)) void *data)
4789 {
4790 	struct cmd_set_bond_mon_period_result *res = parsed_result;
4791 	int ret;
4792 
4793 	if (res->port_num >= nb_ports) {
4794 		printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
4795 		return;
4796 	}
4797 
4798 	ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
4799 
4800 	/* check the return value and print it if is < 0 */
4801 	if (ret < 0)
4802 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4803 }
4804 
4805 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
4806 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4807 				set, "set");
4808 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
4809 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4810 				bonding, "bonding");
4811 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
4812 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4813 				mon_period,	"mon_period");
4814 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
4815 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4816 				port_num, UINT8);
4817 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
4818 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4819 				period_ms, UINT32);
4820 
4821 cmdline_parse_inst_t cmd_set_bond_mon_period = {
4822 		.f = cmd_set_bond_mon_period_parsed,
4823 		.data = (void *) 0,
4824 		.help_str = "set bonding mon_period <port_id> <period_ms>",
4825 		.tokens = {
4826 				(void *)&cmd_set_bond_mon_period_set,
4827 				(void *)&cmd_set_bond_mon_period_bonding,
4828 				(void *)&cmd_set_bond_mon_period_mon_period,
4829 				(void *)&cmd_set_bond_mon_period_portnum,
4830 				(void *)&cmd_set_bond_mon_period_period_ms,
4831 				NULL
4832 		}
4833 };
4834 
4835 #endif /* RTE_LIBRTE_PMD_BOND */
4836 
4837 /* *** SET FORWARDING MODE *** */
4838 struct cmd_set_fwd_mode_result {
4839 	cmdline_fixed_string_t set;
4840 	cmdline_fixed_string_t fwd;
4841 	cmdline_fixed_string_t mode;
4842 };
4843 
4844 static void cmd_set_fwd_mode_parsed(void *parsed_result,
4845 				    __attribute__((unused)) struct cmdline *cl,
4846 				    __attribute__((unused)) void *data)
4847 {
4848 	struct cmd_set_fwd_mode_result *res = parsed_result;
4849 
4850 	retry_enabled = 0;
4851 	set_pkt_forwarding_mode(res->mode);
4852 }
4853 
4854 cmdline_parse_token_string_t cmd_setfwd_set =
4855 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
4856 cmdline_parse_token_string_t cmd_setfwd_fwd =
4857 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
4858 cmdline_parse_token_string_t cmd_setfwd_mode =
4859 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
4860 		"" /* defined at init */);
4861 
4862 cmdline_parse_inst_t cmd_set_fwd_mode = {
4863 	.f = cmd_set_fwd_mode_parsed,
4864 	.data = NULL,
4865 	.help_str = NULL, /* defined at init */
4866 	.tokens = {
4867 		(void *)&cmd_setfwd_set,
4868 		(void *)&cmd_setfwd_fwd,
4869 		(void *)&cmd_setfwd_mode,
4870 		NULL,
4871 	},
4872 };
4873 
4874 static void cmd_set_fwd_mode_init(void)
4875 {
4876 	char *modes, *c;
4877 	static char token[128];
4878 	static char help[256];
4879 	cmdline_parse_token_string_t *token_struct;
4880 
4881 	modes = list_pkt_forwarding_modes();
4882 	snprintf(help, sizeof(help), "set fwd %s: "
4883 		"Set packet forwarding mode", modes);
4884 	cmd_set_fwd_mode.help_str = help;
4885 
4886 	/* string token separator is # */
4887 	for (c = token; *modes != '\0'; modes++)
4888 		if (*modes == '|')
4889 			*c++ = '#';
4890 		else
4891 			*c++ = *modes;
4892 	token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
4893 	token_struct->string_data.str = token;
4894 }
4895 
4896 /* *** SET RETRY FORWARDING MODE *** */
4897 struct cmd_set_fwd_retry_mode_result {
4898 	cmdline_fixed_string_t set;
4899 	cmdline_fixed_string_t fwd;
4900 	cmdline_fixed_string_t mode;
4901 	cmdline_fixed_string_t retry;
4902 };
4903 
4904 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
4905 			    __attribute__((unused)) struct cmdline *cl,
4906 			    __attribute__((unused)) void *data)
4907 {
4908 	struct cmd_set_fwd_retry_mode_result *res = parsed_result;
4909 
4910 	retry_enabled = 1;
4911 	set_pkt_forwarding_mode(res->mode);
4912 }
4913 
4914 cmdline_parse_token_string_t cmd_setfwd_retry_set =
4915 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4916 			set, "set");
4917 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
4918 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4919 			fwd, "fwd");
4920 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
4921 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4922 			mode,
4923 		"" /* defined at init */);
4924 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
4925 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
4926 			retry, "retry");
4927 
4928 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
4929 	.f = cmd_set_fwd_retry_mode_parsed,
4930 	.data = NULL,
4931 	.help_str = NULL, /* defined at init */
4932 	.tokens = {
4933 		(void *)&cmd_setfwd_retry_set,
4934 		(void *)&cmd_setfwd_retry_fwd,
4935 		(void *)&cmd_setfwd_retry_mode,
4936 		(void *)&cmd_setfwd_retry_retry,
4937 		NULL,
4938 	},
4939 };
4940 
4941 static void cmd_set_fwd_retry_mode_init(void)
4942 {
4943 	char *modes, *c;
4944 	static char token[128];
4945 	static char help[256];
4946 	cmdline_parse_token_string_t *token_struct;
4947 
4948 	modes = list_pkt_forwarding_retry_modes();
4949 	snprintf(help, sizeof(help), "set fwd %s retry: "
4950 		"Set packet forwarding mode with retry", modes);
4951 	cmd_set_fwd_retry_mode.help_str = help;
4952 
4953 	/* string token separator is # */
4954 	for (c = token; *modes != '\0'; modes++)
4955 		if (*modes == '|')
4956 			*c++ = '#';
4957 		else
4958 			*c++ = *modes;
4959 	token_struct = (cmdline_parse_token_string_t *)
4960 		cmd_set_fwd_retry_mode.tokens[2];
4961 	token_struct->string_data.str = token;
4962 }
4963 
4964 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
4965 struct cmd_set_burst_tx_retry_result {
4966 	cmdline_fixed_string_t set;
4967 	cmdline_fixed_string_t burst;
4968 	cmdline_fixed_string_t tx;
4969 	cmdline_fixed_string_t delay;
4970 	uint32_t time;
4971 	cmdline_fixed_string_t retry;
4972 	uint32_t retry_num;
4973 };
4974 
4975 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
4976 					__attribute__((unused)) struct cmdline *cl,
4977 					__attribute__((unused)) void *data)
4978 {
4979 	struct cmd_set_burst_tx_retry_result *res = parsed_result;
4980 
4981 	if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
4982 		&& !strcmp(res->tx, "tx")) {
4983 		if (!strcmp(res->delay, "delay"))
4984 			burst_tx_delay_time = res->time;
4985 		if (!strcmp(res->retry, "retry"))
4986 			burst_tx_retry_num = res->retry_num;
4987 	}
4988 
4989 }
4990 
4991 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
4992 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
4993 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
4994 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
4995 				 "burst");
4996 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
4997 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
4998 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
4999 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5000 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5001 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5002 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5003 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5004 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5005 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5006 
5007 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5008 	.f = cmd_set_burst_tx_retry_parsed,
5009 	.help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5010 	.tokens = {
5011 		(void *)&cmd_set_burst_tx_retry_set,
5012 		(void *)&cmd_set_burst_tx_retry_burst,
5013 		(void *)&cmd_set_burst_tx_retry_tx,
5014 		(void *)&cmd_set_burst_tx_retry_delay,
5015 		(void *)&cmd_set_burst_tx_retry_time,
5016 		(void *)&cmd_set_burst_tx_retry_retry,
5017 		(void *)&cmd_set_burst_tx_retry_retry_num,
5018 		NULL,
5019 	},
5020 };
5021 
5022 /* *** SET PROMISC MODE *** */
5023 struct cmd_set_promisc_mode_result {
5024 	cmdline_fixed_string_t set;
5025 	cmdline_fixed_string_t promisc;
5026 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5027 	uint8_t port_num;                /* valid if "allports" argument == 0 */
5028 	cmdline_fixed_string_t mode;
5029 };
5030 
5031 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5032 					__attribute__((unused)) struct cmdline *cl,
5033 					void *allports)
5034 {
5035 	struct cmd_set_promisc_mode_result *res = parsed_result;
5036 	int enable;
5037 	portid_t i;
5038 
5039 	if (!strcmp(res->mode, "on"))
5040 		enable = 1;
5041 	else
5042 		enable = 0;
5043 
5044 	/* all ports */
5045 	if (allports) {
5046 		RTE_ETH_FOREACH_DEV(i) {
5047 			if (enable)
5048 				rte_eth_promiscuous_enable(i);
5049 			else
5050 				rte_eth_promiscuous_disable(i);
5051 		}
5052 	}
5053 	else {
5054 		if (enable)
5055 			rte_eth_promiscuous_enable(res->port_num);
5056 		else
5057 			rte_eth_promiscuous_disable(res->port_num);
5058 	}
5059 }
5060 
5061 cmdline_parse_token_string_t cmd_setpromisc_set =
5062 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5063 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5064 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5065 				 "promisc");
5066 cmdline_parse_token_string_t cmd_setpromisc_portall =
5067 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5068 				 "all");
5069 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5070 	TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5071 			      UINT8);
5072 cmdline_parse_token_string_t cmd_setpromisc_mode =
5073 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5074 				 "on#off");
5075 
5076 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5077 	.f = cmd_set_promisc_mode_parsed,
5078 	.data = (void *)1,
5079 	.help_str = "set promisc all on|off: Set promisc mode for all ports",
5080 	.tokens = {
5081 		(void *)&cmd_setpromisc_set,
5082 		(void *)&cmd_setpromisc_promisc,
5083 		(void *)&cmd_setpromisc_portall,
5084 		(void *)&cmd_setpromisc_mode,
5085 		NULL,
5086 	},
5087 };
5088 
5089 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5090 	.f = cmd_set_promisc_mode_parsed,
5091 	.data = (void *)0,
5092 	.help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5093 	.tokens = {
5094 		(void *)&cmd_setpromisc_set,
5095 		(void *)&cmd_setpromisc_promisc,
5096 		(void *)&cmd_setpromisc_portnum,
5097 		(void *)&cmd_setpromisc_mode,
5098 		NULL,
5099 	},
5100 };
5101 
5102 /* *** SET ALLMULTI MODE *** */
5103 struct cmd_set_allmulti_mode_result {
5104 	cmdline_fixed_string_t set;
5105 	cmdline_fixed_string_t allmulti;
5106 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5107 	uint8_t port_num;                /* valid if "allports" argument == 0 */
5108 	cmdline_fixed_string_t mode;
5109 };
5110 
5111 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5112 					__attribute__((unused)) struct cmdline *cl,
5113 					void *allports)
5114 {
5115 	struct cmd_set_allmulti_mode_result *res = parsed_result;
5116 	int enable;
5117 	portid_t i;
5118 
5119 	if (!strcmp(res->mode, "on"))
5120 		enable = 1;
5121 	else
5122 		enable = 0;
5123 
5124 	/* all ports */
5125 	if (allports) {
5126 		RTE_ETH_FOREACH_DEV(i) {
5127 			if (enable)
5128 				rte_eth_allmulticast_enable(i);
5129 			else
5130 				rte_eth_allmulticast_disable(i);
5131 		}
5132 	}
5133 	else {
5134 		if (enable)
5135 			rte_eth_allmulticast_enable(res->port_num);
5136 		else
5137 			rte_eth_allmulticast_disable(res->port_num);
5138 	}
5139 }
5140 
5141 cmdline_parse_token_string_t cmd_setallmulti_set =
5142 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5143 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5144 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5145 				 "allmulti");
5146 cmdline_parse_token_string_t cmd_setallmulti_portall =
5147 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5148 				 "all");
5149 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5150 	TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5151 			      UINT8);
5152 cmdline_parse_token_string_t cmd_setallmulti_mode =
5153 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5154 				 "on#off");
5155 
5156 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5157 	.f = cmd_set_allmulti_mode_parsed,
5158 	.data = (void *)1,
5159 	.help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5160 	.tokens = {
5161 		(void *)&cmd_setallmulti_set,
5162 		(void *)&cmd_setallmulti_allmulti,
5163 		(void *)&cmd_setallmulti_portall,
5164 		(void *)&cmd_setallmulti_mode,
5165 		NULL,
5166 	},
5167 };
5168 
5169 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5170 	.f = cmd_set_allmulti_mode_parsed,
5171 	.data = (void *)0,
5172 	.help_str = "set allmulti <port_id> on|off: "
5173 		"Set allmulti mode on port_id",
5174 	.tokens = {
5175 		(void *)&cmd_setallmulti_set,
5176 		(void *)&cmd_setallmulti_allmulti,
5177 		(void *)&cmd_setallmulti_portnum,
5178 		(void *)&cmd_setallmulti_mode,
5179 		NULL,
5180 	},
5181 };
5182 
5183 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5184 struct cmd_link_flow_ctrl_set_result {
5185 	cmdline_fixed_string_t set;
5186 	cmdline_fixed_string_t flow_ctrl;
5187 	cmdline_fixed_string_t rx;
5188 	cmdline_fixed_string_t rx_lfc_mode;
5189 	cmdline_fixed_string_t tx;
5190 	cmdline_fixed_string_t tx_lfc_mode;
5191 	cmdline_fixed_string_t mac_ctrl_frame_fwd;
5192 	cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5193 	cmdline_fixed_string_t autoneg_str;
5194 	cmdline_fixed_string_t autoneg;
5195 	cmdline_fixed_string_t hw_str;
5196 	uint32_t high_water;
5197 	cmdline_fixed_string_t lw_str;
5198 	uint32_t low_water;
5199 	cmdline_fixed_string_t pt_str;
5200 	uint16_t pause_time;
5201 	cmdline_fixed_string_t xon_str;
5202 	uint16_t send_xon;
5203 	uint8_t  port_id;
5204 };
5205 
5206 cmdline_parse_token_string_t cmd_lfc_set_set =
5207 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5208 				set, "set");
5209 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5210 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5211 				flow_ctrl, "flow_ctrl");
5212 cmdline_parse_token_string_t cmd_lfc_set_rx =
5213 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5214 				rx, "rx");
5215 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5216 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5217 				rx_lfc_mode, "on#off");
5218 cmdline_parse_token_string_t cmd_lfc_set_tx =
5219 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5220 				tx, "tx");
5221 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5222 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5223 				tx_lfc_mode, "on#off");
5224 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5225 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5226 				hw_str, "high_water");
5227 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5228 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5229 				high_water, UINT32);
5230 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5231 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5232 				lw_str, "low_water");
5233 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5234 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5235 				low_water, UINT32);
5236 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5237 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5238 				pt_str, "pause_time");
5239 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5240 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5241 				pause_time, UINT16);
5242 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5243 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5244 				xon_str, "send_xon");
5245 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5246 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5247 				send_xon, UINT16);
5248 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5249 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5250 				mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5251 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5252 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5253 				mac_ctrl_frame_fwd_mode, "on#off");
5254 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5255 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5256 				autoneg_str, "autoneg");
5257 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5258 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5259 				autoneg, "on#off");
5260 cmdline_parse_token_num_t cmd_lfc_set_portid =
5261 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5262 				port_id, UINT8);
5263 
5264 /* forward declaration */
5265 static void
5266 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5267 			      void *data);
5268 
5269 cmdline_parse_inst_t cmd_link_flow_control_set = {
5270 	.f = cmd_link_flow_ctrl_set_parsed,
5271 	.data = NULL,
5272 	.help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5273 		"<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5274 		"autoneg on|off <port_id>: Configure the Ethernet flow control",
5275 	.tokens = {
5276 		(void *)&cmd_lfc_set_set,
5277 		(void *)&cmd_lfc_set_flow_ctrl,
5278 		(void *)&cmd_lfc_set_rx,
5279 		(void *)&cmd_lfc_set_rx_mode,
5280 		(void *)&cmd_lfc_set_tx,
5281 		(void *)&cmd_lfc_set_tx_mode,
5282 		(void *)&cmd_lfc_set_high_water,
5283 		(void *)&cmd_lfc_set_low_water,
5284 		(void *)&cmd_lfc_set_pause_time,
5285 		(void *)&cmd_lfc_set_send_xon,
5286 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5287 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5288 		(void *)&cmd_lfc_set_autoneg_str,
5289 		(void *)&cmd_lfc_set_autoneg,
5290 		(void *)&cmd_lfc_set_portid,
5291 		NULL,
5292 	},
5293 };
5294 
5295 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5296 	.f = cmd_link_flow_ctrl_set_parsed,
5297 	.data = (void *)&cmd_link_flow_control_set_rx,
5298 	.help_str = "set flow_ctrl rx on|off <port_id>: "
5299 		"Change rx flow control parameter",
5300 	.tokens = {
5301 		(void *)&cmd_lfc_set_set,
5302 		(void *)&cmd_lfc_set_flow_ctrl,
5303 		(void *)&cmd_lfc_set_rx,
5304 		(void *)&cmd_lfc_set_rx_mode,
5305 		(void *)&cmd_lfc_set_portid,
5306 		NULL,
5307 	},
5308 };
5309 
5310 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5311 	.f = cmd_link_flow_ctrl_set_parsed,
5312 	.data = (void *)&cmd_link_flow_control_set_tx,
5313 	.help_str = "set flow_ctrl tx on|off <port_id>: "
5314 		"Change tx flow control parameter",
5315 	.tokens = {
5316 		(void *)&cmd_lfc_set_set,
5317 		(void *)&cmd_lfc_set_flow_ctrl,
5318 		(void *)&cmd_lfc_set_tx,
5319 		(void *)&cmd_lfc_set_tx_mode,
5320 		(void *)&cmd_lfc_set_portid,
5321 		NULL,
5322 	},
5323 };
5324 
5325 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5326 	.f = cmd_link_flow_ctrl_set_parsed,
5327 	.data = (void *)&cmd_link_flow_control_set_hw,
5328 	.help_str = "set flow_ctrl high_water <value> <port_id>: "
5329 		"Change high water flow control parameter",
5330 	.tokens = {
5331 		(void *)&cmd_lfc_set_set,
5332 		(void *)&cmd_lfc_set_flow_ctrl,
5333 		(void *)&cmd_lfc_set_high_water_str,
5334 		(void *)&cmd_lfc_set_high_water,
5335 		(void *)&cmd_lfc_set_portid,
5336 		NULL,
5337 	},
5338 };
5339 
5340 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5341 	.f = cmd_link_flow_ctrl_set_parsed,
5342 	.data = (void *)&cmd_link_flow_control_set_lw,
5343 	.help_str = "set flow_ctrl low_water <value> <port_id>: "
5344 		"Change low water flow control parameter",
5345 	.tokens = {
5346 		(void *)&cmd_lfc_set_set,
5347 		(void *)&cmd_lfc_set_flow_ctrl,
5348 		(void *)&cmd_lfc_set_low_water_str,
5349 		(void *)&cmd_lfc_set_low_water,
5350 		(void *)&cmd_lfc_set_portid,
5351 		NULL,
5352 	},
5353 };
5354 
5355 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5356 	.f = cmd_link_flow_ctrl_set_parsed,
5357 	.data = (void *)&cmd_link_flow_control_set_pt,
5358 	.help_str = "set flow_ctrl pause_time <value> <port_id>: "
5359 		"Change pause time flow control parameter",
5360 	.tokens = {
5361 		(void *)&cmd_lfc_set_set,
5362 		(void *)&cmd_lfc_set_flow_ctrl,
5363 		(void *)&cmd_lfc_set_pause_time_str,
5364 		(void *)&cmd_lfc_set_pause_time,
5365 		(void *)&cmd_lfc_set_portid,
5366 		NULL,
5367 	},
5368 };
5369 
5370 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5371 	.f = cmd_link_flow_ctrl_set_parsed,
5372 	.data = (void *)&cmd_link_flow_control_set_xon,
5373 	.help_str = "set flow_ctrl send_xon <value> <port_id>: "
5374 		"Change send_xon flow control parameter",
5375 	.tokens = {
5376 		(void *)&cmd_lfc_set_set,
5377 		(void *)&cmd_lfc_set_flow_ctrl,
5378 		(void *)&cmd_lfc_set_send_xon_str,
5379 		(void *)&cmd_lfc_set_send_xon,
5380 		(void *)&cmd_lfc_set_portid,
5381 		NULL,
5382 	},
5383 };
5384 
5385 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5386 	.f = cmd_link_flow_ctrl_set_parsed,
5387 	.data = (void *)&cmd_link_flow_control_set_macfwd,
5388 	.help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
5389 		"Change mac ctrl fwd flow control parameter",
5390 	.tokens = {
5391 		(void *)&cmd_lfc_set_set,
5392 		(void *)&cmd_lfc_set_flow_ctrl,
5393 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5394 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5395 		(void *)&cmd_lfc_set_portid,
5396 		NULL,
5397 	},
5398 };
5399 
5400 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5401 	.f = cmd_link_flow_ctrl_set_parsed,
5402 	.data = (void *)&cmd_link_flow_control_set_autoneg,
5403 	.help_str = "set flow_ctrl autoneg on|off <port_id>: "
5404 		"Change autoneg flow control parameter",
5405 	.tokens = {
5406 		(void *)&cmd_lfc_set_set,
5407 		(void *)&cmd_lfc_set_flow_ctrl,
5408 		(void *)&cmd_lfc_set_autoneg_str,
5409 		(void *)&cmd_lfc_set_autoneg,
5410 		(void *)&cmd_lfc_set_portid,
5411 		NULL,
5412 	},
5413 };
5414 
5415 static void
5416 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
5417 			      __attribute__((unused)) struct cmdline *cl,
5418 			      void *data)
5419 {
5420 	struct cmd_link_flow_ctrl_set_result *res = parsed_result;
5421 	cmdline_parse_inst_t *cmd = data;
5422 	struct rte_eth_fc_conf fc_conf;
5423 	int rx_fc_en = 0;
5424 	int tx_fc_en = 0;
5425 	int ret;
5426 
5427 	/*
5428 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5429 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5430 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5431 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5432 	 */
5433 	static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5434 			{RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
5435 	};
5436 
5437 	/* Partial command line, retrieve current configuration */
5438 	if (cmd) {
5439 		ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5440 		if (ret != 0) {
5441 			printf("cannot get current flow ctrl parameters, return"
5442 			       "code = %d\n", ret);
5443 			return;
5444 		}
5445 
5446 		if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
5447 		    (fc_conf.mode == RTE_FC_FULL))
5448 			rx_fc_en = 1;
5449 		if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
5450 		    (fc_conf.mode == RTE_FC_FULL))
5451 			tx_fc_en = 1;
5452 	}
5453 
5454 	if (!cmd || cmd == &cmd_link_flow_control_set_rx)
5455 		rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
5456 
5457 	if (!cmd || cmd == &cmd_link_flow_control_set_tx)
5458 		tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
5459 
5460 	fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
5461 
5462 	if (!cmd || cmd == &cmd_link_flow_control_set_hw)
5463 		fc_conf.high_water = res->high_water;
5464 
5465 	if (!cmd || cmd == &cmd_link_flow_control_set_lw)
5466 		fc_conf.low_water = res->low_water;
5467 
5468 	if (!cmd || cmd == &cmd_link_flow_control_set_pt)
5469 		fc_conf.pause_time = res->pause_time;
5470 
5471 	if (!cmd || cmd == &cmd_link_flow_control_set_xon)
5472 		fc_conf.send_xon = res->send_xon;
5473 
5474 	if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
5475 		if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
5476 			fc_conf.mac_ctrl_frame_fwd = 1;
5477 		else
5478 			fc_conf.mac_ctrl_frame_fwd = 0;
5479 	}
5480 
5481 	if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
5482 		fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
5483 
5484 	ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
5485 	if (ret != 0)
5486 		printf("bad flow contrl parameter, return code = %d \n", ret);
5487 }
5488 
5489 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
5490 struct cmd_priority_flow_ctrl_set_result {
5491 	cmdline_fixed_string_t set;
5492 	cmdline_fixed_string_t pfc_ctrl;
5493 	cmdline_fixed_string_t rx;
5494 	cmdline_fixed_string_t rx_pfc_mode;
5495 	cmdline_fixed_string_t tx;
5496 	cmdline_fixed_string_t tx_pfc_mode;
5497 	uint32_t high_water;
5498 	uint32_t low_water;
5499 	uint16_t pause_time;
5500 	uint8_t  priority;
5501 	uint8_t  port_id;
5502 };
5503 
5504 static void
5505 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
5506 		       __attribute__((unused)) struct cmdline *cl,
5507 		       __attribute__((unused)) void *data)
5508 {
5509 	struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
5510 	struct rte_eth_pfc_conf pfc_conf;
5511 	int rx_fc_enable, tx_fc_enable;
5512 	int ret;
5513 
5514 	/*
5515 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5516 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5517 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5518 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5519 	 */
5520 	static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
5521 			{RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
5522 	};
5523 
5524 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
5525 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
5526 	pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
5527 	pfc_conf.fc.high_water = res->high_water;
5528 	pfc_conf.fc.low_water  = res->low_water;
5529 	pfc_conf.fc.pause_time = res->pause_time;
5530 	pfc_conf.priority      = res->priority;
5531 
5532 	ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
5533 	if (ret != 0)
5534 		printf("bad priority flow contrl parameter, return code = %d \n", ret);
5535 }
5536 
5537 cmdline_parse_token_string_t cmd_pfc_set_set =
5538 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5539 				set, "set");
5540 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
5541 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5542 				pfc_ctrl, "pfc_ctrl");
5543 cmdline_parse_token_string_t cmd_pfc_set_rx =
5544 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5545 				rx, "rx");
5546 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
5547 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5548 				rx_pfc_mode, "on#off");
5549 cmdline_parse_token_string_t cmd_pfc_set_tx =
5550 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5551 				tx, "tx");
5552 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
5553 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5554 				tx_pfc_mode, "on#off");
5555 cmdline_parse_token_num_t cmd_pfc_set_high_water =
5556 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5557 				high_water, UINT32);
5558 cmdline_parse_token_num_t cmd_pfc_set_low_water =
5559 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5560 				low_water, UINT32);
5561 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
5562 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5563 				pause_time, UINT16);
5564 cmdline_parse_token_num_t cmd_pfc_set_priority =
5565 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5566 				priority, UINT8);
5567 cmdline_parse_token_num_t cmd_pfc_set_portid =
5568 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5569 				port_id, UINT8);
5570 
5571 cmdline_parse_inst_t cmd_priority_flow_control_set = {
5572 	.f = cmd_priority_flow_ctrl_set_parsed,
5573 	.data = NULL,
5574 	.help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
5575 		"<pause_time> <priority> <port_id>: "
5576 		"Configure the Ethernet priority flow control",
5577 	.tokens = {
5578 		(void *)&cmd_pfc_set_set,
5579 		(void *)&cmd_pfc_set_flow_ctrl,
5580 		(void *)&cmd_pfc_set_rx,
5581 		(void *)&cmd_pfc_set_rx_mode,
5582 		(void *)&cmd_pfc_set_tx,
5583 		(void *)&cmd_pfc_set_tx_mode,
5584 		(void *)&cmd_pfc_set_high_water,
5585 		(void *)&cmd_pfc_set_low_water,
5586 		(void *)&cmd_pfc_set_pause_time,
5587 		(void *)&cmd_pfc_set_priority,
5588 		(void *)&cmd_pfc_set_portid,
5589 		NULL,
5590 	},
5591 };
5592 
5593 /* *** RESET CONFIGURATION *** */
5594 struct cmd_reset_result {
5595 	cmdline_fixed_string_t reset;
5596 	cmdline_fixed_string_t def;
5597 };
5598 
5599 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
5600 			     struct cmdline *cl,
5601 			     __attribute__((unused)) void *data)
5602 {
5603 	cmdline_printf(cl, "Reset to default forwarding configuration...\n");
5604 	set_def_fwd_config();
5605 }
5606 
5607 cmdline_parse_token_string_t cmd_reset_set =
5608 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
5609 cmdline_parse_token_string_t cmd_reset_def =
5610 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
5611 				 "default");
5612 
5613 cmdline_parse_inst_t cmd_reset = {
5614 	.f = cmd_reset_parsed,
5615 	.data = NULL,
5616 	.help_str = "set default: Reset default forwarding configuration",
5617 	.tokens = {
5618 		(void *)&cmd_reset_set,
5619 		(void *)&cmd_reset_def,
5620 		NULL,
5621 	},
5622 };
5623 
5624 /* *** START FORWARDING *** */
5625 struct cmd_start_result {
5626 	cmdline_fixed_string_t start;
5627 };
5628 
5629 cmdline_parse_token_string_t cmd_start_start =
5630 	TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
5631 
5632 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
5633 			     __attribute__((unused)) struct cmdline *cl,
5634 			     __attribute__((unused)) void *data)
5635 {
5636 	start_packet_forwarding(0);
5637 }
5638 
5639 cmdline_parse_inst_t cmd_start = {
5640 	.f = cmd_start_parsed,
5641 	.data = NULL,
5642 	.help_str = "start: Start packet forwarding",
5643 	.tokens = {
5644 		(void *)&cmd_start_start,
5645 		NULL,
5646 	},
5647 };
5648 
5649 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
5650 struct cmd_start_tx_first_result {
5651 	cmdline_fixed_string_t start;
5652 	cmdline_fixed_string_t tx_first;
5653 };
5654 
5655 static void
5656 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
5657 			  __attribute__((unused)) struct cmdline *cl,
5658 			  __attribute__((unused)) void *data)
5659 {
5660 	start_packet_forwarding(1);
5661 }
5662 
5663 cmdline_parse_token_string_t cmd_start_tx_first_start =
5664 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
5665 				 "start");
5666 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
5667 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
5668 				 tx_first, "tx_first");
5669 
5670 cmdline_parse_inst_t cmd_start_tx_first = {
5671 	.f = cmd_start_tx_first_parsed,
5672 	.data = NULL,
5673 	.help_str = "start tx_first: Start packet forwarding, "
5674 		"after sending 1 burst of packets",
5675 	.tokens = {
5676 		(void *)&cmd_start_tx_first_start,
5677 		(void *)&cmd_start_tx_first_tx_first,
5678 		NULL,
5679 	},
5680 };
5681 
5682 /* *** START FORWARDING WITH N TX BURST FIRST *** */
5683 struct cmd_start_tx_first_n_result {
5684 	cmdline_fixed_string_t start;
5685 	cmdline_fixed_string_t tx_first;
5686 	uint32_t tx_num;
5687 };
5688 
5689 static void
5690 cmd_start_tx_first_n_parsed(void *parsed_result,
5691 			  __attribute__((unused)) struct cmdline *cl,
5692 			  __attribute__((unused)) void *data)
5693 {
5694 	struct cmd_start_tx_first_n_result *res = parsed_result;
5695 
5696 	start_packet_forwarding(res->tx_num);
5697 }
5698 
5699 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
5700 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
5701 			start, "start");
5702 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
5703 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
5704 			tx_first, "tx_first");
5705 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
5706 	TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
5707 			tx_num, UINT32);
5708 
5709 cmdline_parse_inst_t cmd_start_tx_first_n = {
5710 	.f = cmd_start_tx_first_n_parsed,
5711 	.data = NULL,
5712 	.help_str = "start tx_first <num>: "
5713 		"packet forwarding, after sending <num> bursts of packets",
5714 	.tokens = {
5715 		(void *)&cmd_start_tx_first_n_start,
5716 		(void *)&cmd_start_tx_first_n_tx_first,
5717 		(void *)&cmd_start_tx_first_n_tx_num,
5718 		NULL,
5719 	},
5720 };
5721 
5722 /* *** SET LINK UP *** */
5723 struct cmd_set_link_up_result {
5724 	cmdline_fixed_string_t set;
5725 	cmdline_fixed_string_t link_up;
5726 	cmdline_fixed_string_t port;
5727 	uint8_t port_id;
5728 };
5729 
5730 cmdline_parse_token_string_t cmd_set_link_up_set =
5731 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
5732 cmdline_parse_token_string_t cmd_set_link_up_link_up =
5733 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
5734 				"link-up");
5735 cmdline_parse_token_string_t cmd_set_link_up_port =
5736 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
5737 cmdline_parse_token_num_t cmd_set_link_up_port_id =
5738 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
5739 
5740 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
5741 			     __attribute__((unused)) struct cmdline *cl,
5742 			     __attribute__((unused)) void *data)
5743 {
5744 	struct cmd_set_link_up_result *res = parsed_result;
5745 	dev_set_link_up(res->port_id);
5746 }
5747 
5748 cmdline_parse_inst_t cmd_set_link_up = {
5749 	.f = cmd_set_link_up_parsed,
5750 	.data = NULL,
5751 	.help_str = "set link-up port <port id>",
5752 	.tokens = {
5753 		(void *)&cmd_set_link_up_set,
5754 		(void *)&cmd_set_link_up_link_up,
5755 		(void *)&cmd_set_link_up_port,
5756 		(void *)&cmd_set_link_up_port_id,
5757 		NULL,
5758 	},
5759 };
5760 
5761 /* *** SET LINK DOWN *** */
5762 struct cmd_set_link_down_result {
5763 	cmdline_fixed_string_t set;
5764 	cmdline_fixed_string_t link_down;
5765 	cmdline_fixed_string_t port;
5766 	uint8_t port_id;
5767 };
5768 
5769 cmdline_parse_token_string_t cmd_set_link_down_set =
5770 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
5771 cmdline_parse_token_string_t cmd_set_link_down_link_down =
5772 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
5773 				"link-down");
5774 cmdline_parse_token_string_t cmd_set_link_down_port =
5775 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
5776 cmdline_parse_token_num_t cmd_set_link_down_port_id =
5777 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
5778 
5779 static void cmd_set_link_down_parsed(
5780 				__attribute__((unused)) void *parsed_result,
5781 				__attribute__((unused)) struct cmdline *cl,
5782 				__attribute__((unused)) void *data)
5783 {
5784 	struct cmd_set_link_down_result *res = parsed_result;
5785 	dev_set_link_down(res->port_id);
5786 }
5787 
5788 cmdline_parse_inst_t cmd_set_link_down = {
5789 	.f = cmd_set_link_down_parsed,
5790 	.data = NULL,
5791 	.help_str = "set link-down port <port id>",
5792 	.tokens = {
5793 		(void *)&cmd_set_link_down_set,
5794 		(void *)&cmd_set_link_down_link_down,
5795 		(void *)&cmd_set_link_down_port,
5796 		(void *)&cmd_set_link_down_port_id,
5797 		NULL,
5798 	},
5799 };
5800 
5801 /* *** SHOW CFG *** */
5802 struct cmd_showcfg_result {
5803 	cmdline_fixed_string_t show;
5804 	cmdline_fixed_string_t cfg;
5805 	cmdline_fixed_string_t what;
5806 };
5807 
5808 static void cmd_showcfg_parsed(void *parsed_result,
5809 			       __attribute__((unused)) struct cmdline *cl,
5810 			       __attribute__((unused)) void *data)
5811 {
5812 	struct cmd_showcfg_result *res = parsed_result;
5813 	if (!strcmp(res->what, "rxtx"))
5814 		rxtx_config_display();
5815 	else if (!strcmp(res->what, "cores"))
5816 		fwd_lcores_config_display();
5817 	else if (!strcmp(res->what, "fwd"))
5818 		pkt_fwd_config_display(&cur_fwd_config);
5819 	else if (!strcmp(res->what, "txpkts"))
5820 		show_tx_pkt_segments();
5821 }
5822 
5823 cmdline_parse_token_string_t cmd_showcfg_show =
5824 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
5825 cmdline_parse_token_string_t cmd_showcfg_port =
5826 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
5827 cmdline_parse_token_string_t cmd_showcfg_what =
5828 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
5829 				 "rxtx#cores#fwd#txpkts");
5830 
5831 cmdline_parse_inst_t cmd_showcfg = {
5832 	.f = cmd_showcfg_parsed,
5833 	.data = NULL,
5834 	.help_str = "show config rxtx|cores|fwd|txpkts",
5835 	.tokens = {
5836 		(void *)&cmd_showcfg_show,
5837 		(void *)&cmd_showcfg_port,
5838 		(void *)&cmd_showcfg_what,
5839 		NULL,
5840 	},
5841 };
5842 
5843 /* *** SHOW ALL PORT INFO *** */
5844 struct cmd_showportall_result {
5845 	cmdline_fixed_string_t show;
5846 	cmdline_fixed_string_t port;
5847 	cmdline_fixed_string_t what;
5848 	cmdline_fixed_string_t all;
5849 };
5850 
5851 static void cmd_showportall_parsed(void *parsed_result,
5852 				__attribute__((unused)) struct cmdline *cl,
5853 				__attribute__((unused)) void *data)
5854 {
5855 	portid_t i;
5856 
5857 	struct cmd_showportall_result *res = parsed_result;
5858 	if (!strcmp(res->show, "clear")) {
5859 		if (!strcmp(res->what, "stats"))
5860 			RTE_ETH_FOREACH_DEV(i)
5861 				nic_stats_clear(i);
5862 		else if (!strcmp(res->what, "xstats"))
5863 			RTE_ETH_FOREACH_DEV(i)
5864 				nic_xstats_clear(i);
5865 	} else if (!strcmp(res->what, "info"))
5866 		RTE_ETH_FOREACH_DEV(i)
5867 			port_infos_display(i);
5868 	else if (!strcmp(res->what, "stats"))
5869 		RTE_ETH_FOREACH_DEV(i)
5870 			nic_stats_display(i);
5871 	else if (!strcmp(res->what, "xstats"))
5872 		RTE_ETH_FOREACH_DEV(i)
5873 			nic_xstats_display(i);
5874 	else if (!strcmp(res->what, "fdir"))
5875 		RTE_ETH_FOREACH_DEV(i)
5876 			fdir_get_infos(i);
5877 	else if (!strcmp(res->what, "stat_qmap"))
5878 		RTE_ETH_FOREACH_DEV(i)
5879 			nic_stats_mapping_display(i);
5880 	else if (!strcmp(res->what, "dcb_tc"))
5881 		RTE_ETH_FOREACH_DEV(i)
5882 			port_dcb_info_display(i);
5883 	else if (!strcmp(res->what, "cap"))
5884 		RTE_ETH_FOREACH_DEV(i)
5885 			port_offload_cap_display(i);
5886 }
5887 
5888 cmdline_parse_token_string_t cmd_showportall_show =
5889 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
5890 				 "show#clear");
5891 cmdline_parse_token_string_t cmd_showportall_port =
5892 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
5893 cmdline_parse_token_string_t cmd_showportall_what =
5894 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
5895 				 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
5896 cmdline_parse_token_string_t cmd_showportall_all =
5897 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
5898 cmdline_parse_inst_t cmd_showportall = {
5899 	.f = cmd_showportall_parsed,
5900 	.data = NULL,
5901 	.help_str = "show|clear port "
5902 		"info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
5903 	.tokens = {
5904 		(void *)&cmd_showportall_show,
5905 		(void *)&cmd_showportall_port,
5906 		(void *)&cmd_showportall_what,
5907 		(void *)&cmd_showportall_all,
5908 		NULL,
5909 	},
5910 };
5911 
5912 /* *** SHOW PORT INFO *** */
5913 struct cmd_showport_result {
5914 	cmdline_fixed_string_t show;
5915 	cmdline_fixed_string_t port;
5916 	cmdline_fixed_string_t what;
5917 	uint8_t portnum;
5918 };
5919 
5920 static void cmd_showport_parsed(void *parsed_result,
5921 				__attribute__((unused)) struct cmdline *cl,
5922 				__attribute__((unused)) void *data)
5923 {
5924 	struct cmd_showport_result *res = parsed_result;
5925 	if (!strcmp(res->show, "clear")) {
5926 		if (!strcmp(res->what, "stats"))
5927 			nic_stats_clear(res->portnum);
5928 		else if (!strcmp(res->what, "xstats"))
5929 			nic_xstats_clear(res->portnum);
5930 	} else if (!strcmp(res->what, "info"))
5931 		port_infos_display(res->portnum);
5932 	else if (!strcmp(res->what, "stats"))
5933 		nic_stats_display(res->portnum);
5934 	else if (!strcmp(res->what, "xstats"))
5935 		nic_xstats_display(res->portnum);
5936 	else if (!strcmp(res->what, "fdir"))
5937 		 fdir_get_infos(res->portnum);
5938 	else if (!strcmp(res->what, "stat_qmap"))
5939 		nic_stats_mapping_display(res->portnum);
5940 	else if (!strcmp(res->what, "dcb_tc"))
5941 		port_dcb_info_display(res->portnum);
5942 	else if (!strcmp(res->what, "cap"))
5943 		port_offload_cap_display(res->portnum);
5944 }
5945 
5946 cmdline_parse_token_string_t cmd_showport_show =
5947 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
5948 				 "show#clear");
5949 cmdline_parse_token_string_t cmd_showport_port =
5950 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
5951 cmdline_parse_token_string_t cmd_showport_what =
5952 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
5953 				 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
5954 cmdline_parse_token_num_t cmd_showport_portnum =
5955 	TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
5956 
5957 cmdline_parse_inst_t cmd_showport = {
5958 	.f = cmd_showport_parsed,
5959 	.data = NULL,
5960 	.help_str = "show|clear port "
5961 		"info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
5962 		"<port_id>",
5963 	.tokens = {
5964 		(void *)&cmd_showport_show,
5965 		(void *)&cmd_showport_port,
5966 		(void *)&cmd_showport_what,
5967 		(void *)&cmd_showport_portnum,
5968 		NULL,
5969 	},
5970 };
5971 
5972 /* *** SHOW QUEUE INFO *** */
5973 struct cmd_showqueue_result {
5974 	cmdline_fixed_string_t show;
5975 	cmdline_fixed_string_t type;
5976 	cmdline_fixed_string_t what;
5977 	uint8_t portnum;
5978 	uint16_t queuenum;
5979 };
5980 
5981 static void
5982 cmd_showqueue_parsed(void *parsed_result,
5983 	__attribute__((unused)) struct cmdline *cl,
5984 	__attribute__((unused)) void *data)
5985 {
5986 	struct cmd_showqueue_result *res = parsed_result;
5987 
5988 	if (!strcmp(res->type, "rxq"))
5989 		rx_queue_infos_display(res->portnum, res->queuenum);
5990 	else if (!strcmp(res->type, "txq"))
5991 		tx_queue_infos_display(res->portnum, res->queuenum);
5992 }
5993 
5994 cmdline_parse_token_string_t cmd_showqueue_show =
5995 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
5996 cmdline_parse_token_string_t cmd_showqueue_type =
5997 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
5998 cmdline_parse_token_string_t cmd_showqueue_what =
5999 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6000 cmdline_parse_token_num_t cmd_showqueue_portnum =
6001 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
6002 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6003 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6004 
6005 cmdline_parse_inst_t cmd_showqueue = {
6006 	.f = cmd_showqueue_parsed,
6007 	.data = NULL,
6008 	.help_str = "show rxq|txq info <port_id> <queue_id>",
6009 	.tokens = {
6010 		(void *)&cmd_showqueue_show,
6011 		(void *)&cmd_showqueue_type,
6012 		(void *)&cmd_showqueue_what,
6013 		(void *)&cmd_showqueue_portnum,
6014 		(void *)&cmd_showqueue_queuenum,
6015 		NULL,
6016 	},
6017 };
6018 
6019 /* *** READ PORT REGISTER *** */
6020 struct cmd_read_reg_result {
6021 	cmdline_fixed_string_t read;
6022 	cmdline_fixed_string_t reg;
6023 	uint8_t port_id;
6024 	uint32_t reg_off;
6025 };
6026 
6027 static void
6028 cmd_read_reg_parsed(void *parsed_result,
6029 		    __attribute__((unused)) struct cmdline *cl,
6030 		    __attribute__((unused)) void *data)
6031 {
6032 	struct cmd_read_reg_result *res = parsed_result;
6033 	port_reg_display(res->port_id, res->reg_off);
6034 }
6035 
6036 cmdline_parse_token_string_t cmd_read_reg_read =
6037 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6038 cmdline_parse_token_string_t cmd_read_reg_reg =
6039 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6040 cmdline_parse_token_num_t cmd_read_reg_port_id =
6041 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
6042 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6043 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6044 
6045 cmdline_parse_inst_t cmd_read_reg = {
6046 	.f = cmd_read_reg_parsed,
6047 	.data = NULL,
6048 	.help_str = "read reg <port_id> <reg_off>",
6049 	.tokens = {
6050 		(void *)&cmd_read_reg_read,
6051 		(void *)&cmd_read_reg_reg,
6052 		(void *)&cmd_read_reg_port_id,
6053 		(void *)&cmd_read_reg_reg_off,
6054 		NULL,
6055 	},
6056 };
6057 
6058 /* *** READ PORT REGISTER BIT FIELD *** */
6059 struct cmd_read_reg_bit_field_result {
6060 	cmdline_fixed_string_t read;
6061 	cmdline_fixed_string_t regfield;
6062 	uint8_t port_id;
6063 	uint32_t reg_off;
6064 	uint8_t bit1_pos;
6065 	uint8_t bit2_pos;
6066 };
6067 
6068 static void
6069 cmd_read_reg_bit_field_parsed(void *parsed_result,
6070 			      __attribute__((unused)) struct cmdline *cl,
6071 			      __attribute__((unused)) void *data)
6072 {
6073 	struct cmd_read_reg_bit_field_result *res = parsed_result;
6074 	port_reg_bit_field_display(res->port_id, res->reg_off,
6075 				   res->bit1_pos, res->bit2_pos);
6076 }
6077 
6078 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6079 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6080 				 "read");
6081 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6082 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6083 				 regfield, "regfield");
6084 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6085 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6086 			      UINT8);
6087 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6088 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6089 			      UINT32);
6090 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6091 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6092 			      UINT8);
6093 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6094 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6095 			      UINT8);
6096 
6097 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6098 	.f = cmd_read_reg_bit_field_parsed,
6099 	.data = NULL,
6100 	.help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6101 	"Read register bit field between bit_x and bit_y included",
6102 	.tokens = {
6103 		(void *)&cmd_read_reg_bit_field_read,
6104 		(void *)&cmd_read_reg_bit_field_regfield,
6105 		(void *)&cmd_read_reg_bit_field_port_id,
6106 		(void *)&cmd_read_reg_bit_field_reg_off,
6107 		(void *)&cmd_read_reg_bit_field_bit1_pos,
6108 		(void *)&cmd_read_reg_bit_field_bit2_pos,
6109 		NULL,
6110 	},
6111 };
6112 
6113 /* *** READ PORT REGISTER BIT *** */
6114 struct cmd_read_reg_bit_result {
6115 	cmdline_fixed_string_t read;
6116 	cmdline_fixed_string_t regbit;
6117 	uint8_t port_id;
6118 	uint32_t reg_off;
6119 	uint8_t bit_pos;
6120 };
6121 
6122 static void
6123 cmd_read_reg_bit_parsed(void *parsed_result,
6124 			__attribute__((unused)) struct cmdline *cl,
6125 			__attribute__((unused)) void *data)
6126 {
6127 	struct cmd_read_reg_bit_result *res = parsed_result;
6128 	port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6129 }
6130 
6131 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6132 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6133 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6134 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6135 				 regbit, "regbit");
6136 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6137 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
6138 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6139 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6140 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6141 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6142 
6143 cmdline_parse_inst_t cmd_read_reg_bit = {
6144 	.f = cmd_read_reg_bit_parsed,
6145 	.data = NULL,
6146 	.help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6147 	.tokens = {
6148 		(void *)&cmd_read_reg_bit_read,
6149 		(void *)&cmd_read_reg_bit_regbit,
6150 		(void *)&cmd_read_reg_bit_port_id,
6151 		(void *)&cmd_read_reg_bit_reg_off,
6152 		(void *)&cmd_read_reg_bit_bit_pos,
6153 		NULL,
6154 	},
6155 };
6156 
6157 /* *** WRITE PORT REGISTER *** */
6158 struct cmd_write_reg_result {
6159 	cmdline_fixed_string_t write;
6160 	cmdline_fixed_string_t reg;
6161 	uint8_t port_id;
6162 	uint32_t reg_off;
6163 	uint32_t value;
6164 };
6165 
6166 static void
6167 cmd_write_reg_parsed(void *parsed_result,
6168 		     __attribute__((unused)) struct cmdline *cl,
6169 		     __attribute__((unused)) void *data)
6170 {
6171 	struct cmd_write_reg_result *res = parsed_result;
6172 	port_reg_set(res->port_id, res->reg_off, res->value);
6173 }
6174 
6175 cmdline_parse_token_string_t cmd_write_reg_write =
6176 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6177 cmdline_parse_token_string_t cmd_write_reg_reg =
6178 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6179 cmdline_parse_token_num_t cmd_write_reg_port_id =
6180 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
6181 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6182 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6183 cmdline_parse_token_num_t cmd_write_reg_value =
6184 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6185 
6186 cmdline_parse_inst_t cmd_write_reg = {
6187 	.f = cmd_write_reg_parsed,
6188 	.data = NULL,
6189 	.help_str = "write reg <port_id> <reg_off> <reg_value>",
6190 	.tokens = {
6191 		(void *)&cmd_write_reg_write,
6192 		(void *)&cmd_write_reg_reg,
6193 		(void *)&cmd_write_reg_port_id,
6194 		(void *)&cmd_write_reg_reg_off,
6195 		(void *)&cmd_write_reg_value,
6196 		NULL,
6197 	},
6198 };
6199 
6200 /* *** WRITE PORT REGISTER BIT FIELD *** */
6201 struct cmd_write_reg_bit_field_result {
6202 	cmdline_fixed_string_t write;
6203 	cmdline_fixed_string_t regfield;
6204 	uint8_t port_id;
6205 	uint32_t reg_off;
6206 	uint8_t bit1_pos;
6207 	uint8_t bit2_pos;
6208 	uint32_t value;
6209 };
6210 
6211 static void
6212 cmd_write_reg_bit_field_parsed(void *parsed_result,
6213 			       __attribute__((unused)) struct cmdline *cl,
6214 			       __attribute__((unused)) void *data)
6215 {
6216 	struct cmd_write_reg_bit_field_result *res = parsed_result;
6217 	port_reg_bit_field_set(res->port_id, res->reg_off,
6218 			  res->bit1_pos, res->bit2_pos, res->value);
6219 }
6220 
6221 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6222 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6223 				 "write");
6224 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6225 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6226 				 regfield, "regfield");
6227 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6228 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6229 			      UINT8);
6230 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6231 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6232 			      UINT32);
6233 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6234 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6235 			      UINT8);
6236 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6237 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6238 			      UINT8);
6239 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6240 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6241 			      UINT32);
6242 
6243 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6244 	.f = cmd_write_reg_bit_field_parsed,
6245 	.data = NULL,
6246 	.help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6247 		"<reg_value>: "
6248 		"Set register bit field between bit_x and bit_y included",
6249 	.tokens = {
6250 		(void *)&cmd_write_reg_bit_field_write,
6251 		(void *)&cmd_write_reg_bit_field_regfield,
6252 		(void *)&cmd_write_reg_bit_field_port_id,
6253 		(void *)&cmd_write_reg_bit_field_reg_off,
6254 		(void *)&cmd_write_reg_bit_field_bit1_pos,
6255 		(void *)&cmd_write_reg_bit_field_bit2_pos,
6256 		(void *)&cmd_write_reg_bit_field_value,
6257 		NULL,
6258 	},
6259 };
6260 
6261 /* *** WRITE PORT REGISTER BIT *** */
6262 struct cmd_write_reg_bit_result {
6263 	cmdline_fixed_string_t write;
6264 	cmdline_fixed_string_t regbit;
6265 	uint8_t port_id;
6266 	uint32_t reg_off;
6267 	uint8_t bit_pos;
6268 	uint8_t value;
6269 };
6270 
6271 static void
6272 cmd_write_reg_bit_parsed(void *parsed_result,
6273 			 __attribute__((unused)) struct cmdline *cl,
6274 			 __attribute__((unused)) void *data)
6275 {
6276 	struct cmd_write_reg_bit_result *res = parsed_result;
6277 	port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6278 }
6279 
6280 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6281 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6282 				 "write");
6283 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6284 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6285 				 regbit, "regbit");
6286 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6287 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
6288 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6289 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6290 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6291 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6292 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6293 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6294 
6295 cmdline_parse_inst_t cmd_write_reg_bit = {
6296 	.f = cmd_write_reg_bit_parsed,
6297 	.data = NULL,
6298 	.help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6299 		"0 <= bit_x <= 31",
6300 	.tokens = {
6301 		(void *)&cmd_write_reg_bit_write,
6302 		(void *)&cmd_write_reg_bit_regbit,
6303 		(void *)&cmd_write_reg_bit_port_id,
6304 		(void *)&cmd_write_reg_bit_reg_off,
6305 		(void *)&cmd_write_reg_bit_bit_pos,
6306 		(void *)&cmd_write_reg_bit_value,
6307 		NULL,
6308 	},
6309 };
6310 
6311 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6312 struct cmd_read_rxd_txd_result {
6313 	cmdline_fixed_string_t read;
6314 	cmdline_fixed_string_t rxd_txd;
6315 	uint8_t port_id;
6316 	uint16_t queue_id;
6317 	uint16_t desc_id;
6318 };
6319 
6320 static void
6321 cmd_read_rxd_txd_parsed(void *parsed_result,
6322 			__attribute__((unused)) struct cmdline *cl,
6323 			__attribute__((unused)) void *data)
6324 {
6325 	struct cmd_read_rxd_txd_result *res = parsed_result;
6326 
6327 	if (!strcmp(res->rxd_txd, "rxd"))
6328 		rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6329 	else if (!strcmp(res->rxd_txd, "txd"))
6330 		tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6331 }
6332 
6333 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6334 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6335 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6336 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6337 				 "rxd#txd");
6338 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6339 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
6340 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6341 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6342 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6343 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6344 
6345 cmdline_parse_inst_t cmd_read_rxd_txd = {
6346 	.f = cmd_read_rxd_txd_parsed,
6347 	.data = NULL,
6348 	.help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6349 	.tokens = {
6350 		(void *)&cmd_read_rxd_txd_read,
6351 		(void *)&cmd_read_rxd_txd_rxd_txd,
6352 		(void *)&cmd_read_rxd_txd_port_id,
6353 		(void *)&cmd_read_rxd_txd_queue_id,
6354 		(void *)&cmd_read_rxd_txd_desc_id,
6355 		NULL,
6356 	},
6357 };
6358 
6359 /* *** QUIT *** */
6360 struct cmd_quit_result {
6361 	cmdline_fixed_string_t quit;
6362 };
6363 
6364 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6365 			    struct cmdline *cl,
6366 			    __attribute__((unused)) void *data)
6367 {
6368 	pmd_test_exit();
6369 	cmdline_quit(cl);
6370 }
6371 
6372 cmdline_parse_token_string_t cmd_quit_quit =
6373 	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6374 
6375 cmdline_parse_inst_t cmd_quit = {
6376 	.f = cmd_quit_parsed,
6377 	.data = NULL,
6378 	.help_str = "quit: Exit application",
6379 	.tokens = {
6380 		(void *)&cmd_quit_quit,
6381 		NULL,
6382 	},
6383 };
6384 
6385 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
6386 struct cmd_mac_addr_result {
6387 	cmdline_fixed_string_t mac_addr_cmd;
6388 	cmdline_fixed_string_t what;
6389 	uint8_t port_num;
6390 	struct ether_addr address;
6391 };
6392 
6393 static void cmd_mac_addr_parsed(void *parsed_result,
6394 		__attribute__((unused)) struct cmdline *cl,
6395 		__attribute__((unused)) void *data)
6396 {
6397 	struct cmd_mac_addr_result *res = parsed_result;
6398 	int ret;
6399 
6400 	if (strcmp(res->what, "add") == 0)
6401 		ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
6402 	else if (strcmp(res->what, "set") == 0)
6403 		ret = rte_eth_dev_default_mac_addr_set(res->port_num,
6404 						       &res->address);
6405 	else
6406 		ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
6407 
6408 	/* check the return value and print it if is < 0 */
6409 	if(ret < 0)
6410 		printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
6411 
6412 }
6413 
6414 cmdline_parse_token_string_t cmd_mac_addr_cmd =
6415 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
6416 				"mac_addr");
6417 cmdline_parse_token_string_t cmd_mac_addr_what =
6418 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
6419 				"add#remove#set");
6420 cmdline_parse_token_num_t cmd_mac_addr_portnum =
6421 		TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
6422 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
6423 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
6424 
6425 cmdline_parse_inst_t cmd_mac_addr = {
6426 	.f = cmd_mac_addr_parsed,
6427 	.data = (void *)0,
6428 	.help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
6429 			"Add/Remove/Set MAC address on port_id",
6430 	.tokens = {
6431 		(void *)&cmd_mac_addr_cmd,
6432 		(void *)&cmd_mac_addr_what,
6433 		(void *)&cmd_mac_addr_portnum,
6434 		(void *)&cmd_mac_addr_addr,
6435 		NULL,
6436 	},
6437 };
6438 
6439 
6440 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
6441 struct cmd_set_qmap_result {
6442 	cmdline_fixed_string_t set;
6443 	cmdline_fixed_string_t qmap;
6444 	cmdline_fixed_string_t what;
6445 	uint8_t port_id;
6446 	uint16_t queue_id;
6447 	uint8_t map_value;
6448 };
6449 
6450 static void
6451 cmd_set_qmap_parsed(void *parsed_result,
6452 		       __attribute__((unused)) struct cmdline *cl,
6453 		       __attribute__((unused)) void *data)
6454 {
6455 	struct cmd_set_qmap_result *res = parsed_result;
6456 	int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
6457 
6458 	set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
6459 }
6460 
6461 cmdline_parse_token_string_t cmd_setqmap_set =
6462 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6463 				 set, "set");
6464 cmdline_parse_token_string_t cmd_setqmap_qmap =
6465 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6466 				 qmap, "stat_qmap");
6467 cmdline_parse_token_string_t cmd_setqmap_what =
6468 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6469 				 what, "tx#rx");
6470 cmdline_parse_token_num_t cmd_setqmap_portid =
6471 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6472 			      port_id, UINT8);
6473 cmdline_parse_token_num_t cmd_setqmap_queueid =
6474 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6475 			      queue_id, UINT16);
6476 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
6477 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6478 			      map_value, UINT8);
6479 
6480 cmdline_parse_inst_t cmd_set_qmap = {
6481 	.f = cmd_set_qmap_parsed,
6482 	.data = NULL,
6483 	.help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
6484 		"Set statistics mapping value on tx|rx queue_id of port_id",
6485 	.tokens = {
6486 		(void *)&cmd_setqmap_set,
6487 		(void *)&cmd_setqmap_qmap,
6488 		(void *)&cmd_setqmap_what,
6489 		(void *)&cmd_setqmap_portid,
6490 		(void *)&cmd_setqmap_queueid,
6491 		(void *)&cmd_setqmap_mapvalue,
6492 		NULL,
6493 	},
6494 };
6495 
6496 /* *** CONFIGURE UNICAST HASH TABLE *** */
6497 struct cmd_set_uc_hash_table {
6498 	cmdline_fixed_string_t set;
6499 	cmdline_fixed_string_t port;
6500 	uint8_t port_id;
6501 	cmdline_fixed_string_t what;
6502 	struct ether_addr address;
6503 	cmdline_fixed_string_t mode;
6504 };
6505 
6506 static void
6507 cmd_set_uc_hash_parsed(void *parsed_result,
6508 		       __attribute__((unused)) struct cmdline *cl,
6509 		       __attribute__((unused)) void *data)
6510 {
6511 	int ret=0;
6512 	struct cmd_set_uc_hash_table *res = parsed_result;
6513 
6514 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6515 
6516 	if (strcmp(res->what, "uta") == 0)
6517 		ret = rte_eth_dev_uc_hash_table_set(res->port_id,
6518 						&res->address,(uint8_t)is_on);
6519 	if (ret < 0)
6520 		printf("bad unicast hash table parameter, return code = %d \n", ret);
6521 
6522 }
6523 
6524 cmdline_parse_token_string_t cmd_set_uc_hash_set =
6525 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6526 				 set, "set");
6527 cmdline_parse_token_string_t cmd_set_uc_hash_port =
6528 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6529 				 port, "port");
6530 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
6531 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
6532 			      port_id, UINT8);
6533 cmdline_parse_token_string_t cmd_set_uc_hash_what =
6534 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6535 				 what, "uta");
6536 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
6537 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
6538 				address);
6539 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
6540 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6541 				 mode, "on#off");
6542 
6543 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
6544 	.f = cmd_set_uc_hash_parsed,
6545 	.data = NULL,
6546 	.help_str = "set port <port_id> uta <mac_addr> on|off)",
6547 	.tokens = {
6548 		(void *)&cmd_set_uc_hash_set,
6549 		(void *)&cmd_set_uc_hash_port,
6550 		(void *)&cmd_set_uc_hash_portid,
6551 		(void *)&cmd_set_uc_hash_what,
6552 		(void *)&cmd_set_uc_hash_mac,
6553 		(void *)&cmd_set_uc_hash_mode,
6554 		NULL,
6555 	},
6556 };
6557 
6558 struct cmd_set_uc_all_hash_table {
6559 	cmdline_fixed_string_t set;
6560 	cmdline_fixed_string_t port;
6561 	uint8_t port_id;
6562 	cmdline_fixed_string_t what;
6563 	cmdline_fixed_string_t value;
6564 	cmdline_fixed_string_t mode;
6565 };
6566 
6567 static void
6568 cmd_set_uc_all_hash_parsed(void *parsed_result,
6569 		       __attribute__((unused)) struct cmdline *cl,
6570 		       __attribute__((unused)) void *data)
6571 {
6572 	int ret=0;
6573 	struct cmd_set_uc_all_hash_table *res = parsed_result;
6574 
6575 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6576 
6577 	if ((strcmp(res->what, "uta") == 0) &&
6578 		(strcmp(res->value, "all") == 0))
6579 		ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
6580 	if (ret < 0)
6581 		printf("bad unicast hash table parameter,"
6582 			"return code = %d \n", ret);
6583 }
6584 
6585 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
6586 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6587 				 set, "set");
6588 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
6589 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6590 				 port, "port");
6591 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
6592 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
6593 			      port_id, UINT8);
6594 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
6595 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6596 				 what, "uta");
6597 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
6598 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6599 				value,"all");
6600 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
6601 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6602 				 mode, "on#off");
6603 
6604 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
6605 	.f = cmd_set_uc_all_hash_parsed,
6606 	.data = NULL,
6607 	.help_str = "set port <port_id> uta all on|off",
6608 	.tokens = {
6609 		(void *)&cmd_set_uc_all_hash_set,
6610 		(void *)&cmd_set_uc_all_hash_port,
6611 		(void *)&cmd_set_uc_all_hash_portid,
6612 		(void *)&cmd_set_uc_all_hash_what,
6613 		(void *)&cmd_set_uc_all_hash_value,
6614 		(void *)&cmd_set_uc_all_hash_mode,
6615 		NULL,
6616 	},
6617 };
6618 
6619 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
6620 struct cmd_set_vf_macvlan_filter {
6621 	cmdline_fixed_string_t set;
6622 	cmdline_fixed_string_t port;
6623 	uint8_t port_id;
6624 	cmdline_fixed_string_t vf;
6625 	uint8_t vf_id;
6626 	struct ether_addr address;
6627 	cmdline_fixed_string_t filter_type;
6628 	cmdline_fixed_string_t mode;
6629 };
6630 
6631 static void
6632 cmd_set_vf_macvlan_parsed(void *parsed_result,
6633 		       __attribute__((unused)) struct cmdline *cl,
6634 		       __attribute__((unused)) void *data)
6635 {
6636 	int is_on, ret = 0;
6637 	struct cmd_set_vf_macvlan_filter *res = parsed_result;
6638 	struct rte_eth_mac_filter filter;
6639 
6640 	memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
6641 
6642 	(void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
6643 
6644 	/* set VF MAC filter */
6645 	filter.is_vf = 1;
6646 
6647 	/* set VF ID */
6648 	filter.dst_id = res->vf_id;
6649 
6650 	if (!strcmp(res->filter_type, "exact-mac"))
6651 		filter.filter_type = RTE_MAC_PERFECT_MATCH;
6652 	else if (!strcmp(res->filter_type, "exact-mac-vlan"))
6653 		filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
6654 	else if (!strcmp(res->filter_type, "hashmac"))
6655 		filter.filter_type = RTE_MAC_HASH_MATCH;
6656 	else if (!strcmp(res->filter_type, "hashmac-vlan"))
6657 		filter.filter_type = RTE_MACVLAN_HASH_MATCH;
6658 
6659 	is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6660 
6661 	if (is_on)
6662 		ret = rte_eth_dev_filter_ctrl(res->port_id,
6663 					RTE_ETH_FILTER_MACVLAN,
6664 					RTE_ETH_FILTER_ADD,
6665 					 &filter);
6666 	else
6667 		ret = rte_eth_dev_filter_ctrl(res->port_id,
6668 					RTE_ETH_FILTER_MACVLAN,
6669 					RTE_ETH_FILTER_DELETE,
6670 					&filter);
6671 
6672 	if (ret < 0)
6673 		printf("bad set MAC hash parameter, return code = %d\n", ret);
6674 
6675 }
6676 
6677 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
6678 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6679 				 set, "set");
6680 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
6681 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6682 				 port, "port");
6683 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
6684 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6685 			      port_id, UINT8);
6686 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
6687 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6688 				 vf, "vf");
6689 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
6690 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6691 				vf_id, UINT8);
6692 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
6693 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6694 				address);
6695 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
6696 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6697 				filter_type, "exact-mac#exact-mac-vlan"
6698 				"#hashmac#hashmac-vlan");
6699 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
6700 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6701 				 mode, "on#off");
6702 
6703 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
6704 	.f = cmd_set_vf_macvlan_parsed,
6705 	.data = NULL,
6706 	.help_str = "set port <port_id> vf <vf_id> <mac_addr> "
6707 		"exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
6708 		"Exact match rule: exact match of MAC or MAC and VLAN; "
6709 		"hash match rule: hash match of MAC and exact match of VLAN",
6710 	.tokens = {
6711 		(void *)&cmd_set_vf_macvlan_set,
6712 		(void *)&cmd_set_vf_macvlan_port,
6713 		(void *)&cmd_set_vf_macvlan_portid,
6714 		(void *)&cmd_set_vf_macvlan_vf,
6715 		(void *)&cmd_set_vf_macvlan_vf_id,
6716 		(void *)&cmd_set_vf_macvlan_mac,
6717 		(void *)&cmd_set_vf_macvlan_filter_type,
6718 		(void *)&cmd_set_vf_macvlan_mode,
6719 		NULL,
6720 	},
6721 };
6722 
6723 #ifdef RTE_LIBRTE_IXGBE_PMD
6724 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
6725 struct cmd_set_vf_traffic {
6726 	cmdline_fixed_string_t set;
6727 	cmdline_fixed_string_t port;
6728 	uint8_t port_id;
6729 	cmdline_fixed_string_t vf;
6730 	uint8_t vf_id;
6731 	cmdline_fixed_string_t what;
6732 	cmdline_fixed_string_t mode;
6733 };
6734 
6735 static void
6736 cmd_set_vf_traffic_parsed(void *parsed_result,
6737 		       __attribute__((unused)) struct cmdline *cl,
6738 		       __attribute__((unused)) void *data)
6739 {
6740 	struct cmd_set_vf_traffic *res = parsed_result;
6741 	int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
6742 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6743 
6744 	set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
6745 }
6746 
6747 cmdline_parse_token_string_t cmd_setvf_traffic_set =
6748 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6749 				 set, "set");
6750 cmdline_parse_token_string_t cmd_setvf_traffic_port =
6751 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6752 				 port, "port");
6753 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
6754 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6755 			      port_id, UINT8);
6756 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
6757 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6758 				 vf, "vf");
6759 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
6760 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6761 			      vf_id, UINT8);
6762 cmdline_parse_token_string_t cmd_setvf_traffic_what =
6763 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6764 				 what, "tx#rx");
6765 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
6766 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6767 				 mode, "on#off");
6768 
6769 cmdline_parse_inst_t cmd_set_vf_traffic = {
6770 	.f = cmd_set_vf_traffic_parsed,
6771 	.data = NULL,
6772 	.help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
6773 	.tokens = {
6774 		(void *)&cmd_setvf_traffic_set,
6775 		(void *)&cmd_setvf_traffic_port,
6776 		(void *)&cmd_setvf_traffic_portid,
6777 		(void *)&cmd_setvf_traffic_vf,
6778 		(void *)&cmd_setvf_traffic_vfid,
6779 		(void *)&cmd_setvf_traffic_what,
6780 		(void *)&cmd_setvf_traffic_mode,
6781 		NULL,
6782 	},
6783 };
6784 
6785 /* *** CONFIGURE VF RECEIVE MODE *** */
6786 struct cmd_set_vf_rxmode {
6787 	cmdline_fixed_string_t set;
6788 	cmdline_fixed_string_t port;
6789 	uint8_t port_id;
6790 	cmdline_fixed_string_t vf;
6791 	uint8_t vf_id;
6792 	cmdline_fixed_string_t what;
6793 	cmdline_fixed_string_t mode;
6794 	cmdline_fixed_string_t on;
6795 };
6796 
6797 static void
6798 cmd_set_vf_rxmode_parsed(void *parsed_result,
6799 		       __attribute__((unused)) struct cmdline *cl,
6800 		       __attribute__((unused)) void *data)
6801 {
6802 	int ret;
6803 	uint16_t rx_mode = 0;
6804 	struct cmd_set_vf_rxmode *res = parsed_result;
6805 
6806 	int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
6807 	if (!strcmp(res->what,"rxmode")) {
6808 		if (!strcmp(res->mode, "AUPE"))
6809 			rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
6810 		else if (!strcmp(res->mode, "ROPE"))
6811 			rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
6812 		else if (!strcmp(res->mode, "BAM"))
6813 			rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
6814 		else if (!strncmp(res->mode, "MPE",3))
6815 			rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
6816 	}
6817 
6818 	ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id, rx_mode, (uint8_t)is_on);
6819 	if (ret < 0)
6820 		printf("bad VF receive mode parameter, return code = %d \n",
6821 		ret);
6822 }
6823 
6824 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
6825 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6826 				 set, "set");
6827 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
6828 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6829 				 port, "port");
6830 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
6831 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6832 			      port_id, UINT8);
6833 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
6834 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6835 				 vf, "vf");
6836 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
6837 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6838 			      vf_id, UINT8);
6839 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
6840 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6841 				 what, "rxmode");
6842 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
6843 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6844 				 mode, "AUPE#ROPE#BAM#MPE");
6845 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
6846 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6847 				 on, "on#off");
6848 
6849 cmdline_parse_inst_t cmd_set_vf_rxmode = {
6850 	.f = cmd_set_vf_rxmode_parsed,
6851 	.data = NULL,
6852 	.help_str = "set port <port_id> vf <vf_id> rxmode "
6853 		"AUPE|ROPE|BAM|MPE on|off",
6854 	.tokens = {
6855 		(void *)&cmd_set_vf_rxmode_set,
6856 		(void *)&cmd_set_vf_rxmode_port,
6857 		(void *)&cmd_set_vf_rxmode_portid,
6858 		(void *)&cmd_set_vf_rxmode_vf,
6859 		(void *)&cmd_set_vf_rxmode_vfid,
6860 		(void *)&cmd_set_vf_rxmode_what,
6861 		(void *)&cmd_set_vf_rxmode_mode,
6862 		(void *)&cmd_set_vf_rxmode_on,
6863 		NULL,
6864 	},
6865 };
6866 #endif
6867 
6868 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
6869 struct cmd_vf_mac_addr_result {
6870 	cmdline_fixed_string_t mac_addr_cmd;
6871 	cmdline_fixed_string_t what;
6872 	cmdline_fixed_string_t port;
6873 	uint8_t port_num;
6874 	cmdline_fixed_string_t vf;
6875 	uint8_t vf_num;
6876 	struct ether_addr address;
6877 };
6878 
6879 static void cmd_vf_mac_addr_parsed(void *parsed_result,
6880 		__attribute__((unused)) struct cmdline *cl,
6881 		__attribute__((unused)) void *data)
6882 {
6883 	struct cmd_vf_mac_addr_result *res = parsed_result;
6884 	int ret = 0;
6885 
6886 	if (strcmp(res->what, "add") == 0)
6887 		ret = rte_eth_dev_mac_addr_add(res->port_num,
6888 					&res->address, res->vf_num);
6889 	if(ret < 0)
6890 		printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
6891 
6892 }
6893 
6894 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
6895 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6896 				mac_addr_cmd,"mac_addr");
6897 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
6898 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6899 				what,"add");
6900 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
6901 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6902 				port,"port");
6903 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
6904 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6905 				port_num, UINT8);
6906 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
6907 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6908 				vf,"vf");
6909 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
6910 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6911 				vf_num, UINT8);
6912 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
6913 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
6914 				address);
6915 
6916 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
6917 	.f = cmd_vf_mac_addr_parsed,
6918 	.data = (void *)0,
6919 	.help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
6920 		"Add MAC address filtering for a VF on port_id",
6921 	.tokens = {
6922 		(void *)&cmd_vf_mac_addr_cmd,
6923 		(void *)&cmd_vf_mac_addr_what,
6924 		(void *)&cmd_vf_mac_addr_port,
6925 		(void *)&cmd_vf_mac_addr_portnum,
6926 		(void *)&cmd_vf_mac_addr_vf,
6927 		(void *)&cmd_vf_mac_addr_vfnum,
6928 		(void *)&cmd_vf_mac_addr_addr,
6929 		NULL,
6930 	},
6931 };
6932 
6933 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
6934 struct cmd_vf_rx_vlan_filter {
6935 	cmdline_fixed_string_t rx_vlan;
6936 	cmdline_fixed_string_t what;
6937 	uint16_t vlan_id;
6938 	cmdline_fixed_string_t port;
6939 	uint8_t port_id;
6940 	cmdline_fixed_string_t vf;
6941 	uint64_t vf_mask;
6942 };
6943 
6944 static void
6945 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
6946 			  __attribute__((unused)) struct cmdline *cl,
6947 			  __attribute__((unused)) void *data)
6948 {
6949 	struct cmd_vf_rx_vlan_filter *res = parsed_result;
6950 	int ret = -ENOTSUP;
6951 
6952 	__rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
6953 
6954 #ifdef RTE_LIBRTE_IXGBE_PMD
6955 	if (ret == -ENOTSUP)
6956 		ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
6957 				res->vlan_id, res->vf_mask, is_add);
6958 #endif
6959 #ifdef RTE_LIBRTE_I40E_PMD
6960 	if (ret == -ENOTSUP)
6961 		ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
6962 				res->vlan_id, res->vf_mask, is_add);
6963 #endif
6964 
6965 	switch (ret) {
6966 	case 0:
6967 		break;
6968 	case -EINVAL:
6969 		printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
6970 				res->vlan_id, res->vf_mask);
6971 		break;
6972 	case -ENODEV:
6973 		printf("invalid port_id %d\n", res->port_id);
6974 		break;
6975 	case -ENOTSUP:
6976 		printf("function not implemented or supported\n");
6977 		break;
6978 	default:
6979 		printf("programming error: (%s)\n", strerror(-ret));
6980 	}
6981 }
6982 
6983 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
6984 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6985 				 rx_vlan, "rx_vlan");
6986 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
6987 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6988 				 what, "add#rm");
6989 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
6990 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6991 			      vlan_id, UINT16);
6992 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
6993 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6994 				 port, "port");
6995 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
6996 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6997 			      port_id, UINT8);
6998 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
6999 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7000 				 vf, "vf");
7001 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7002 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7003 			      vf_mask, UINT64);
7004 
7005 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7006 	.f = cmd_vf_rx_vlan_filter_parsed,
7007 	.data = NULL,
7008 	.help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7009 		"(vf_mask = hexadecimal VF mask)",
7010 	.tokens = {
7011 		(void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7012 		(void *)&cmd_vf_rx_vlan_filter_what,
7013 		(void *)&cmd_vf_rx_vlan_filter_vlanid,
7014 		(void *)&cmd_vf_rx_vlan_filter_port,
7015 		(void *)&cmd_vf_rx_vlan_filter_portid,
7016 		(void *)&cmd_vf_rx_vlan_filter_vf,
7017 		(void *)&cmd_vf_rx_vlan_filter_vf_mask,
7018 		NULL,
7019 	},
7020 };
7021 
7022 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7023 struct cmd_queue_rate_limit_result {
7024 	cmdline_fixed_string_t set;
7025 	cmdline_fixed_string_t port;
7026 	uint8_t port_num;
7027 	cmdline_fixed_string_t queue;
7028 	uint8_t queue_num;
7029 	cmdline_fixed_string_t rate;
7030 	uint16_t rate_num;
7031 };
7032 
7033 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7034 		__attribute__((unused)) struct cmdline *cl,
7035 		__attribute__((unused)) void *data)
7036 {
7037 	struct cmd_queue_rate_limit_result *res = parsed_result;
7038 	int ret = 0;
7039 
7040 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7041 		&& (strcmp(res->queue, "queue") == 0)
7042 		&& (strcmp(res->rate, "rate") == 0))
7043 		ret = set_queue_rate_limit(res->port_num, res->queue_num,
7044 					res->rate_num);
7045 	if (ret < 0)
7046 		printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7047 
7048 }
7049 
7050 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7051 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7052 				set, "set");
7053 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7054 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7055 				port, "port");
7056 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7057 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7058 				port_num, UINT8);
7059 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7060 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7061 				queue, "queue");
7062 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7063 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7064 				queue_num, UINT8);
7065 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7066 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7067 				rate, "rate");
7068 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7069 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7070 				rate_num, UINT16);
7071 
7072 cmdline_parse_inst_t cmd_queue_rate_limit = {
7073 	.f = cmd_queue_rate_limit_parsed,
7074 	.data = (void *)0,
7075 	.help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7076 		"Set rate limit for a queue on port_id",
7077 	.tokens = {
7078 		(void *)&cmd_queue_rate_limit_set,
7079 		(void *)&cmd_queue_rate_limit_port,
7080 		(void *)&cmd_queue_rate_limit_portnum,
7081 		(void *)&cmd_queue_rate_limit_queue,
7082 		(void *)&cmd_queue_rate_limit_queuenum,
7083 		(void *)&cmd_queue_rate_limit_rate,
7084 		(void *)&cmd_queue_rate_limit_ratenum,
7085 		NULL,
7086 	},
7087 };
7088 
7089 #ifdef RTE_LIBRTE_IXGBE_PMD
7090 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7091 struct cmd_vf_rate_limit_result {
7092 	cmdline_fixed_string_t set;
7093 	cmdline_fixed_string_t port;
7094 	uint8_t port_num;
7095 	cmdline_fixed_string_t vf;
7096 	uint8_t vf_num;
7097 	cmdline_fixed_string_t rate;
7098 	uint16_t rate_num;
7099 	cmdline_fixed_string_t q_msk;
7100 	uint64_t q_msk_val;
7101 };
7102 
7103 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7104 		__attribute__((unused)) struct cmdline *cl,
7105 		__attribute__((unused)) void *data)
7106 {
7107 	struct cmd_vf_rate_limit_result *res = parsed_result;
7108 	int ret = 0;
7109 
7110 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7111 		&& (strcmp(res->vf, "vf") == 0)
7112 		&& (strcmp(res->rate, "rate") == 0)
7113 		&& (strcmp(res->q_msk, "queue_mask") == 0))
7114 		ret = set_vf_rate_limit(res->port_num, res->vf_num,
7115 					res->rate_num, res->q_msk_val);
7116 	if (ret < 0)
7117 		printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7118 
7119 }
7120 
7121 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7122 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7123 				set, "set");
7124 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7125 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7126 				port, "port");
7127 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7128 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7129 				port_num, UINT8);
7130 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7131 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7132 				vf, "vf");
7133 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7134 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7135 				vf_num, UINT8);
7136 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7137 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7138 				rate, "rate");
7139 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7140 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7141 				rate_num, UINT16);
7142 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7143 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7144 				q_msk, "queue_mask");
7145 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7146 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7147 				q_msk_val, UINT64);
7148 
7149 cmdline_parse_inst_t cmd_vf_rate_limit = {
7150 	.f = cmd_vf_rate_limit_parsed,
7151 	.data = (void *)0,
7152 	.help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7153 		"queue_mask <queue_mask_value>: "
7154 		"Set rate limit for queues of VF on port_id",
7155 	.tokens = {
7156 		(void *)&cmd_vf_rate_limit_set,
7157 		(void *)&cmd_vf_rate_limit_port,
7158 		(void *)&cmd_vf_rate_limit_portnum,
7159 		(void *)&cmd_vf_rate_limit_vf,
7160 		(void *)&cmd_vf_rate_limit_vfnum,
7161 		(void *)&cmd_vf_rate_limit_rate,
7162 		(void *)&cmd_vf_rate_limit_ratenum,
7163 		(void *)&cmd_vf_rate_limit_q_msk,
7164 		(void *)&cmd_vf_rate_limit_q_msk_val,
7165 		NULL,
7166 	},
7167 };
7168 #endif
7169 
7170 /* *** ADD TUNNEL FILTER OF A PORT *** */
7171 struct cmd_tunnel_filter_result {
7172 	cmdline_fixed_string_t cmd;
7173 	cmdline_fixed_string_t what;
7174 	uint8_t port_id;
7175 	struct ether_addr outer_mac;
7176 	struct ether_addr inner_mac;
7177 	cmdline_ipaddr_t ip_value;
7178 	uint16_t inner_vlan;
7179 	cmdline_fixed_string_t tunnel_type;
7180 	cmdline_fixed_string_t filter_type;
7181 	uint32_t tenant_id;
7182 	uint16_t queue_num;
7183 };
7184 
7185 static void
7186 cmd_tunnel_filter_parsed(void *parsed_result,
7187 			  __attribute__((unused)) struct cmdline *cl,
7188 			  __attribute__((unused)) void *data)
7189 {
7190 	struct cmd_tunnel_filter_result *res = parsed_result;
7191 	struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7192 	int ret = 0;
7193 
7194 	memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7195 
7196 	ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7197 	ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7198 	tunnel_filter_conf.inner_vlan = res->inner_vlan;
7199 
7200 	if (res->ip_value.family == AF_INET) {
7201 		tunnel_filter_conf.ip_addr.ipv4_addr =
7202 			res->ip_value.addr.ipv4.s_addr;
7203 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7204 	} else {
7205 		memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7206 			&(res->ip_value.addr.ipv6),
7207 			sizeof(struct in6_addr));
7208 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7209 	}
7210 
7211 	if (!strcmp(res->filter_type, "imac-ivlan"))
7212 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7213 	else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7214 		tunnel_filter_conf.filter_type =
7215 			RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7216 	else if (!strcmp(res->filter_type, "imac-tenid"))
7217 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7218 	else if (!strcmp(res->filter_type, "imac"))
7219 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7220 	else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7221 		tunnel_filter_conf.filter_type =
7222 			RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7223 	else if (!strcmp(res->filter_type, "oip"))
7224 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7225 	else if (!strcmp(res->filter_type, "iip"))
7226 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7227 	else {
7228 		printf("The filter type is not supported");
7229 		return;
7230 	}
7231 
7232 	if (!strcmp(res->tunnel_type, "vxlan"))
7233 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7234 	else if (!strcmp(res->tunnel_type, "nvgre"))
7235 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7236 	else if (!strcmp(res->tunnel_type, "ipingre"))
7237 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7238 	else {
7239 		printf("The tunnel type %s not supported.\n", res->tunnel_type);
7240 		return;
7241 	}
7242 
7243 	tunnel_filter_conf.tenant_id = res->tenant_id;
7244 	tunnel_filter_conf.queue_id = res->queue_num;
7245 	if (!strcmp(res->what, "add"))
7246 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7247 					RTE_ETH_FILTER_TUNNEL,
7248 					RTE_ETH_FILTER_ADD,
7249 					&tunnel_filter_conf);
7250 	else
7251 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7252 					RTE_ETH_FILTER_TUNNEL,
7253 					RTE_ETH_FILTER_DELETE,
7254 					&tunnel_filter_conf);
7255 	if (ret < 0)
7256 		printf("cmd_tunnel_filter_parsed error: (%s)\n",
7257 				strerror(-ret));
7258 
7259 }
7260 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7261 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7262 	cmd, "tunnel_filter");
7263 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7264 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7265 	what, "add#rm");
7266 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7267 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7268 	port_id, UINT8);
7269 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7270 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7271 	outer_mac);
7272 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7273 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7274 	inner_mac);
7275 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7276 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7277 	inner_vlan, UINT16);
7278 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7279 	TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7280 	ip_value);
7281 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7282 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7283 	tunnel_type, "vxlan#nvgre#ipingre");
7284 
7285 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7286 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7287 	filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7288 		"imac#omac-imac-tenid");
7289 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7290 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7291 	tenant_id, UINT32);
7292 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7293 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7294 	queue_num, UINT16);
7295 
7296 cmdline_parse_inst_t cmd_tunnel_filter = {
7297 	.f = cmd_tunnel_filter_parsed,
7298 	.data = (void *)0,
7299 	.help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7300 		"<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7301 		"imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7302 		"<queue_id>: Add/Rm tunnel filter of a port",
7303 	.tokens = {
7304 		(void *)&cmd_tunnel_filter_cmd,
7305 		(void *)&cmd_tunnel_filter_what,
7306 		(void *)&cmd_tunnel_filter_port_id,
7307 		(void *)&cmd_tunnel_filter_outer_mac,
7308 		(void *)&cmd_tunnel_filter_inner_mac,
7309 		(void *)&cmd_tunnel_filter_ip_value,
7310 		(void *)&cmd_tunnel_filter_innner_vlan,
7311 		(void *)&cmd_tunnel_filter_tunnel_type,
7312 		(void *)&cmd_tunnel_filter_filter_type,
7313 		(void *)&cmd_tunnel_filter_tenant_id,
7314 		(void *)&cmd_tunnel_filter_queue_num,
7315 		NULL,
7316 	},
7317 };
7318 
7319 /* *** CONFIGURE TUNNEL UDP PORT *** */
7320 struct cmd_tunnel_udp_config {
7321 	cmdline_fixed_string_t cmd;
7322 	cmdline_fixed_string_t what;
7323 	uint16_t udp_port;
7324 	uint8_t port_id;
7325 };
7326 
7327 static void
7328 cmd_tunnel_udp_config_parsed(void *parsed_result,
7329 			  __attribute__((unused)) struct cmdline *cl,
7330 			  __attribute__((unused)) void *data)
7331 {
7332 	struct cmd_tunnel_udp_config *res = parsed_result;
7333 	struct rte_eth_udp_tunnel tunnel_udp;
7334 	int ret;
7335 
7336 	tunnel_udp.udp_port = res->udp_port;
7337 
7338 	if (!strcmp(res->cmd, "rx_vxlan_port"))
7339 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7340 
7341 	if (!strcmp(res->what, "add"))
7342 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7343 						      &tunnel_udp);
7344 	else
7345 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7346 							 &tunnel_udp);
7347 
7348 	if (ret < 0)
7349 		printf("udp tunneling add error: (%s)\n", strerror(-ret));
7350 }
7351 
7352 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7353 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7354 				cmd, "rx_vxlan_port");
7355 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7356 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7357 				what, "add#rm");
7358 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7359 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7360 				udp_port, UINT16);
7361 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7362 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7363 				port_id, UINT8);
7364 
7365 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7366 	.f = cmd_tunnel_udp_config_parsed,
7367 	.data = (void *)0,
7368 	.help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
7369 		"Add/Remove a tunneling UDP port filter",
7370 	.tokens = {
7371 		(void *)&cmd_tunnel_udp_config_cmd,
7372 		(void *)&cmd_tunnel_udp_config_what,
7373 		(void *)&cmd_tunnel_udp_config_udp_port,
7374 		(void *)&cmd_tunnel_udp_config_port_id,
7375 		NULL,
7376 	},
7377 };
7378 
7379 /* *** GLOBAL CONFIG *** */
7380 struct cmd_global_config_result {
7381 	cmdline_fixed_string_t cmd;
7382 	uint8_t port_id;
7383 	cmdline_fixed_string_t cfg_type;
7384 	uint8_t len;
7385 };
7386 
7387 static void
7388 cmd_global_config_parsed(void *parsed_result,
7389 			 __attribute__((unused)) struct cmdline *cl,
7390 			 __attribute__((unused)) void *data)
7391 {
7392 	struct cmd_global_config_result *res = parsed_result;
7393 	struct rte_eth_global_cfg conf;
7394 	int ret;
7395 
7396 	memset(&conf, 0, sizeof(conf));
7397 	conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
7398 	conf.cfg.gre_key_len = res->len;
7399 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
7400 				      RTE_ETH_FILTER_SET, &conf);
7401 	if (ret != 0)
7402 		printf("Global config error\n");
7403 }
7404 
7405 cmdline_parse_token_string_t cmd_global_config_cmd =
7406 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
7407 		"global_config");
7408 cmdline_parse_token_num_t cmd_global_config_port_id =
7409 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
7410 cmdline_parse_token_string_t cmd_global_config_type =
7411 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
7412 		cfg_type, "gre-key-len");
7413 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
7414 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
7415 		len, UINT8);
7416 
7417 cmdline_parse_inst_t cmd_global_config = {
7418 	.f = cmd_global_config_parsed,
7419 	.data = (void *)NULL,
7420 	.help_str = "global_config <port_id> gre-key-len <key_len>",
7421 	.tokens = {
7422 		(void *)&cmd_global_config_cmd,
7423 		(void *)&cmd_global_config_port_id,
7424 		(void *)&cmd_global_config_type,
7425 		(void *)&cmd_global_config_gre_key_len,
7426 		NULL,
7427 	},
7428 };
7429 
7430 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
7431 struct cmd_set_mirror_mask_result {
7432 	cmdline_fixed_string_t set;
7433 	cmdline_fixed_string_t port;
7434 	uint8_t port_id;
7435 	cmdline_fixed_string_t mirror;
7436 	uint8_t rule_id;
7437 	cmdline_fixed_string_t what;
7438 	cmdline_fixed_string_t value;
7439 	cmdline_fixed_string_t dstpool;
7440 	uint8_t dstpool_id;
7441 	cmdline_fixed_string_t on;
7442 };
7443 
7444 cmdline_parse_token_string_t cmd_mirror_mask_set =
7445 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7446 				set, "set");
7447 cmdline_parse_token_string_t cmd_mirror_mask_port =
7448 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7449 				port, "port");
7450 cmdline_parse_token_num_t cmd_mirror_mask_portid =
7451 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7452 				port_id, UINT8);
7453 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
7454 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7455 				mirror, "mirror-rule");
7456 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
7457 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7458 				rule_id, UINT8);
7459 cmdline_parse_token_string_t cmd_mirror_mask_what =
7460 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7461 				what, "pool-mirror-up#pool-mirror-down"
7462 				      "#vlan-mirror");
7463 cmdline_parse_token_string_t cmd_mirror_mask_value =
7464 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7465 				value, NULL);
7466 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
7467 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7468 				dstpool, "dst-pool");
7469 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
7470 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7471 				dstpool_id, UINT8);
7472 cmdline_parse_token_string_t cmd_mirror_mask_on =
7473 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7474 				on, "on#off");
7475 
7476 static void
7477 cmd_set_mirror_mask_parsed(void *parsed_result,
7478 		       __attribute__((unused)) struct cmdline *cl,
7479 		       __attribute__((unused)) void *data)
7480 {
7481 	int ret,nb_item,i;
7482 	struct cmd_set_mirror_mask_result *res = parsed_result;
7483 	struct rte_eth_mirror_conf mr_conf;
7484 
7485 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7486 
7487 	unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
7488 
7489 	mr_conf.dst_pool = res->dstpool_id;
7490 
7491 	if (!strcmp(res->what, "pool-mirror-up")) {
7492 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7493 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
7494 	} else if (!strcmp(res->what, "pool-mirror-down")) {
7495 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7496 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
7497 	} else if (!strcmp(res->what, "vlan-mirror")) {
7498 		mr_conf.rule_type = ETH_MIRROR_VLAN;
7499 		nb_item = parse_item_list(res->value, "vlan",
7500 				ETH_MIRROR_MAX_VLANS, vlan_list, 1);
7501 		if (nb_item <= 0)
7502 			return;
7503 
7504 		for (i = 0; i < nb_item; i++) {
7505 			if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
7506 				printf("Invalid vlan_id: must be < 4096\n");
7507 				return;
7508 			}
7509 
7510 			mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
7511 			mr_conf.vlan.vlan_mask |= 1ULL << i;
7512 		}
7513 	}
7514 
7515 	if (!strcmp(res->on, "on"))
7516 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7517 						res->rule_id, 1);
7518 	else
7519 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7520 						res->rule_id, 0);
7521 	if (ret < 0)
7522 		printf("mirror rule add error: (%s)\n", strerror(-ret));
7523 }
7524 
7525 cmdline_parse_inst_t cmd_set_mirror_mask = {
7526 		.f = cmd_set_mirror_mask_parsed,
7527 		.data = NULL,
7528 		.help_str = "set port <port_id> mirror-rule <rule_id> "
7529 			"pool-mirror-up|pool-mirror-down|vlan-mirror "
7530 			"<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
7531 		.tokens = {
7532 			(void *)&cmd_mirror_mask_set,
7533 			(void *)&cmd_mirror_mask_port,
7534 			(void *)&cmd_mirror_mask_portid,
7535 			(void *)&cmd_mirror_mask_mirror,
7536 			(void *)&cmd_mirror_mask_ruleid,
7537 			(void *)&cmd_mirror_mask_what,
7538 			(void *)&cmd_mirror_mask_value,
7539 			(void *)&cmd_mirror_mask_dstpool,
7540 			(void *)&cmd_mirror_mask_poolid,
7541 			(void *)&cmd_mirror_mask_on,
7542 			NULL,
7543 		},
7544 };
7545 
7546 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
7547 struct cmd_set_mirror_link_result {
7548 	cmdline_fixed_string_t set;
7549 	cmdline_fixed_string_t port;
7550 	uint8_t port_id;
7551 	cmdline_fixed_string_t mirror;
7552 	uint8_t rule_id;
7553 	cmdline_fixed_string_t what;
7554 	cmdline_fixed_string_t dstpool;
7555 	uint8_t dstpool_id;
7556 	cmdline_fixed_string_t on;
7557 };
7558 
7559 cmdline_parse_token_string_t cmd_mirror_link_set =
7560 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7561 				 set, "set");
7562 cmdline_parse_token_string_t cmd_mirror_link_port =
7563 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7564 				port, "port");
7565 cmdline_parse_token_num_t cmd_mirror_link_portid =
7566 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7567 				port_id, UINT8);
7568 cmdline_parse_token_string_t cmd_mirror_link_mirror =
7569 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7570 				mirror, "mirror-rule");
7571 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7572 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7573 			    rule_id, UINT8);
7574 cmdline_parse_token_string_t cmd_mirror_link_what =
7575 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7576 				what, "uplink-mirror#downlink-mirror");
7577 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7578 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7579 				dstpool, "dst-pool");
7580 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7581 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7582 				dstpool_id, UINT8);
7583 cmdline_parse_token_string_t cmd_mirror_link_on =
7584 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7585 				on, "on#off");
7586 
7587 static void
7588 cmd_set_mirror_link_parsed(void *parsed_result,
7589 		       __attribute__((unused)) struct cmdline *cl,
7590 		       __attribute__((unused)) void *data)
7591 {
7592 	int ret;
7593 	struct cmd_set_mirror_link_result *res = parsed_result;
7594 	struct rte_eth_mirror_conf mr_conf;
7595 
7596 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7597 	if (!strcmp(res->what, "uplink-mirror"))
7598 		mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
7599 	else
7600 		mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
7601 
7602 	mr_conf.dst_pool = res->dstpool_id;
7603 
7604 	if (!strcmp(res->on, "on"))
7605 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7606 						res->rule_id, 1);
7607 	else
7608 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7609 						res->rule_id, 0);
7610 
7611 	/* check the return value and print it if is < 0 */
7612 	if (ret < 0)
7613 		printf("mirror rule add error: (%s)\n", strerror(-ret));
7614 
7615 }
7616 
7617 cmdline_parse_inst_t cmd_set_mirror_link = {
7618 		.f = cmd_set_mirror_link_parsed,
7619 		.data = NULL,
7620 		.help_str = "set port <port_id> mirror-rule <rule_id> "
7621 			"uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
7622 		.tokens = {
7623 			(void *)&cmd_mirror_link_set,
7624 			(void *)&cmd_mirror_link_port,
7625 			(void *)&cmd_mirror_link_portid,
7626 			(void *)&cmd_mirror_link_mirror,
7627 			(void *)&cmd_mirror_link_ruleid,
7628 			(void *)&cmd_mirror_link_what,
7629 			(void *)&cmd_mirror_link_dstpool,
7630 			(void *)&cmd_mirror_link_poolid,
7631 			(void *)&cmd_mirror_link_on,
7632 			NULL,
7633 		},
7634 };
7635 
7636 /* *** RESET VM MIRROR RULE *** */
7637 struct cmd_rm_mirror_rule_result {
7638 	cmdline_fixed_string_t reset;
7639 	cmdline_fixed_string_t port;
7640 	uint8_t port_id;
7641 	cmdline_fixed_string_t mirror;
7642 	uint8_t rule_id;
7643 };
7644 
7645 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
7646 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7647 				 reset, "reset");
7648 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
7649 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7650 				port, "port");
7651 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
7652 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7653 				port_id, UINT8);
7654 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
7655 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7656 				mirror, "mirror-rule");
7657 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
7658 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7659 				rule_id, UINT8);
7660 
7661 static void
7662 cmd_reset_mirror_rule_parsed(void *parsed_result,
7663 		       __attribute__((unused)) struct cmdline *cl,
7664 		       __attribute__((unused)) void *data)
7665 {
7666 	int ret;
7667 	struct cmd_set_mirror_link_result *res = parsed_result;
7668         /* check rule_id */
7669 	ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
7670 	if(ret < 0)
7671 		printf("mirror rule remove error: (%s)\n", strerror(-ret));
7672 }
7673 
7674 cmdline_parse_inst_t cmd_reset_mirror_rule = {
7675 		.f = cmd_reset_mirror_rule_parsed,
7676 		.data = NULL,
7677 		.help_str = "reset port <port_id> mirror-rule <rule_id>",
7678 		.tokens = {
7679 			(void *)&cmd_rm_mirror_rule_reset,
7680 			(void *)&cmd_rm_mirror_rule_port,
7681 			(void *)&cmd_rm_mirror_rule_portid,
7682 			(void *)&cmd_rm_mirror_rule_mirror,
7683 			(void *)&cmd_rm_mirror_rule_ruleid,
7684 			NULL,
7685 		},
7686 };
7687 
7688 /* ******************************************************************************** */
7689 
7690 struct cmd_dump_result {
7691 	cmdline_fixed_string_t dump;
7692 };
7693 
7694 static void
7695 dump_struct_sizes(void)
7696 {
7697 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
7698 	DUMP_SIZE(struct rte_mbuf);
7699 	DUMP_SIZE(struct rte_mempool);
7700 	DUMP_SIZE(struct rte_ring);
7701 #undef DUMP_SIZE
7702 }
7703 
7704 static void cmd_dump_parsed(void *parsed_result,
7705 			    __attribute__((unused)) struct cmdline *cl,
7706 			    __attribute__((unused)) void *data)
7707 {
7708 	struct cmd_dump_result *res = parsed_result;
7709 
7710 	if (!strcmp(res->dump, "dump_physmem"))
7711 		rte_dump_physmem_layout(stdout);
7712 	else if (!strcmp(res->dump, "dump_memzone"))
7713 		rte_memzone_dump(stdout);
7714 	else if (!strcmp(res->dump, "dump_struct_sizes"))
7715 		dump_struct_sizes();
7716 	else if (!strcmp(res->dump, "dump_ring"))
7717 		rte_ring_list_dump(stdout);
7718 	else if (!strcmp(res->dump, "dump_mempool"))
7719 		rte_mempool_list_dump(stdout);
7720 	else if (!strcmp(res->dump, "dump_devargs"))
7721 		rte_eal_devargs_dump(stdout);
7722 	else if (!strcmp(res->dump, "dump_log_types"))
7723 		rte_log_dump(stdout);
7724 }
7725 
7726 cmdline_parse_token_string_t cmd_dump_dump =
7727 	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
7728 		"dump_physmem#"
7729 		"dump_memzone#"
7730 		"dump_struct_sizes#"
7731 		"dump_ring#"
7732 		"dump_mempool#"
7733 		"dump_devargs#"
7734 		"dump_log_types");
7735 
7736 cmdline_parse_inst_t cmd_dump = {
7737 	.f = cmd_dump_parsed,  /* function to call */
7738 	.data = NULL,      /* 2nd arg of func */
7739 	.help_str = "Dump status",
7740 	.tokens = {        /* token list, NULL terminated */
7741 		(void *)&cmd_dump_dump,
7742 		NULL,
7743 	},
7744 };
7745 
7746 /* ******************************************************************************** */
7747 
7748 struct cmd_dump_one_result {
7749 	cmdline_fixed_string_t dump;
7750 	cmdline_fixed_string_t name;
7751 };
7752 
7753 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
7754 				__attribute__((unused)) void *data)
7755 {
7756 	struct cmd_dump_one_result *res = parsed_result;
7757 
7758 	if (!strcmp(res->dump, "dump_ring")) {
7759 		struct rte_ring *r;
7760 		r = rte_ring_lookup(res->name);
7761 		if (r == NULL) {
7762 			cmdline_printf(cl, "Cannot find ring\n");
7763 			return;
7764 		}
7765 		rte_ring_dump(stdout, r);
7766 	} else if (!strcmp(res->dump, "dump_mempool")) {
7767 		struct rte_mempool *mp;
7768 		mp = rte_mempool_lookup(res->name);
7769 		if (mp == NULL) {
7770 			cmdline_printf(cl, "Cannot find mempool\n");
7771 			return;
7772 		}
7773 		rte_mempool_dump(stdout, mp);
7774 	}
7775 }
7776 
7777 cmdline_parse_token_string_t cmd_dump_one_dump =
7778 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
7779 				 "dump_ring#dump_mempool");
7780 
7781 cmdline_parse_token_string_t cmd_dump_one_name =
7782 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
7783 
7784 cmdline_parse_inst_t cmd_dump_one = {
7785 	.f = cmd_dump_one_parsed,  /* function to call */
7786 	.data = NULL,      /* 2nd arg of func */
7787 	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
7788 	.tokens = {        /* token list, NULL terminated */
7789 		(void *)&cmd_dump_one_dump,
7790 		(void *)&cmd_dump_one_name,
7791 		NULL,
7792 	},
7793 };
7794 
7795 /* *** Add/Del syn filter *** */
7796 struct cmd_syn_filter_result {
7797 	cmdline_fixed_string_t filter;
7798 	uint8_t port_id;
7799 	cmdline_fixed_string_t ops;
7800 	cmdline_fixed_string_t priority;
7801 	cmdline_fixed_string_t high;
7802 	cmdline_fixed_string_t queue;
7803 	uint16_t queue_id;
7804 };
7805 
7806 static void
7807 cmd_syn_filter_parsed(void *parsed_result,
7808 			__attribute__((unused)) struct cmdline *cl,
7809 			__attribute__((unused)) void *data)
7810 {
7811 	struct cmd_syn_filter_result *res = parsed_result;
7812 	struct rte_eth_syn_filter syn_filter;
7813 	int ret = 0;
7814 
7815 	ret = rte_eth_dev_filter_supported(res->port_id,
7816 					RTE_ETH_FILTER_SYN);
7817 	if (ret < 0) {
7818 		printf("syn filter is not supported on port %u.\n",
7819 				res->port_id);
7820 		return;
7821 	}
7822 
7823 	memset(&syn_filter, 0, sizeof(syn_filter));
7824 
7825 	if (!strcmp(res->ops, "add")) {
7826 		if (!strcmp(res->high, "high"))
7827 			syn_filter.hig_pri = 1;
7828 		else
7829 			syn_filter.hig_pri = 0;
7830 
7831 		syn_filter.queue = res->queue_id;
7832 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7833 						RTE_ETH_FILTER_SYN,
7834 						RTE_ETH_FILTER_ADD,
7835 						&syn_filter);
7836 	} else
7837 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7838 						RTE_ETH_FILTER_SYN,
7839 						RTE_ETH_FILTER_DELETE,
7840 						&syn_filter);
7841 
7842 	if (ret < 0)
7843 		printf("syn filter programming error: (%s)\n",
7844 				strerror(-ret));
7845 }
7846 
7847 cmdline_parse_token_string_t cmd_syn_filter_filter =
7848 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7849 	filter, "syn_filter");
7850 cmdline_parse_token_num_t cmd_syn_filter_port_id =
7851 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7852 	port_id, UINT8);
7853 cmdline_parse_token_string_t cmd_syn_filter_ops =
7854 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7855 	ops, "add#del");
7856 cmdline_parse_token_string_t cmd_syn_filter_priority =
7857 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7858 				priority, "priority");
7859 cmdline_parse_token_string_t cmd_syn_filter_high =
7860 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7861 				high, "high#low");
7862 cmdline_parse_token_string_t cmd_syn_filter_queue =
7863 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7864 				queue, "queue");
7865 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
7866 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7867 				queue_id, UINT16);
7868 
7869 cmdline_parse_inst_t cmd_syn_filter = {
7870 	.f = cmd_syn_filter_parsed,
7871 	.data = NULL,
7872 	.help_str = "syn_filter <port_id> add|del priority high|low queue "
7873 		"<queue_id>: Add/Delete syn filter",
7874 	.tokens = {
7875 		(void *)&cmd_syn_filter_filter,
7876 		(void *)&cmd_syn_filter_port_id,
7877 		(void *)&cmd_syn_filter_ops,
7878 		(void *)&cmd_syn_filter_priority,
7879 		(void *)&cmd_syn_filter_high,
7880 		(void *)&cmd_syn_filter_queue,
7881 		(void *)&cmd_syn_filter_queue_id,
7882 		NULL,
7883 	},
7884 };
7885 
7886 /* *** ADD/REMOVE A 2tuple FILTER *** */
7887 struct cmd_2tuple_filter_result {
7888 	cmdline_fixed_string_t filter;
7889 	uint8_t  port_id;
7890 	cmdline_fixed_string_t ops;
7891 	cmdline_fixed_string_t dst_port;
7892 	uint16_t dst_port_value;
7893 	cmdline_fixed_string_t protocol;
7894 	uint8_t protocol_value;
7895 	cmdline_fixed_string_t mask;
7896 	uint8_t  mask_value;
7897 	cmdline_fixed_string_t tcp_flags;
7898 	uint8_t tcp_flags_value;
7899 	cmdline_fixed_string_t priority;
7900 	uint8_t  priority_value;
7901 	cmdline_fixed_string_t queue;
7902 	uint16_t  queue_id;
7903 };
7904 
7905 static void
7906 cmd_2tuple_filter_parsed(void *parsed_result,
7907 			__attribute__((unused)) struct cmdline *cl,
7908 			__attribute__((unused)) void *data)
7909 {
7910 	struct rte_eth_ntuple_filter filter;
7911 	struct cmd_2tuple_filter_result *res = parsed_result;
7912 	int ret = 0;
7913 
7914 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7915 	if (ret < 0) {
7916 		printf("ntuple filter is not supported on port %u.\n",
7917 			res->port_id);
7918 		return;
7919 	}
7920 
7921 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7922 
7923 	filter.flags = RTE_2TUPLE_FLAGS;
7924 	filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7925 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7926 	filter.proto = res->protocol_value;
7927 	filter.priority = res->priority_value;
7928 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7929 		printf("nonzero tcp_flags is only meaningful"
7930 			" when protocol is TCP.\n");
7931 		return;
7932 	}
7933 	if (res->tcp_flags_value > TCP_FLAG_ALL) {
7934 		printf("invalid TCP flags.\n");
7935 		return;
7936 	}
7937 
7938 	if (res->tcp_flags_value != 0) {
7939 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7940 		filter.tcp_flags = res->tcp_flags_value;
7941 	}
7942 
7943 	/* need convert to big endian. */
7944 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7945 	filter.queue = res->queue_id;
7946 
7947 	if (!strcmp(res->ops, "add"))
7948 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7949 				RTE_ETH_FILTER_NTUPLE,
7950 				RTE_ETH_FILTER_ADD,
7951 				&filter);
7952 	else
7953 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7954 				RTE_ETH_FILTER_NTUPLE,
7955 				RTE_ETH_FILTER_DELETE,
7956 				&filter);
7957 	if (ret < 0)
7958 		printf("2tuple filter programming error: (%s)\n",
7959 			strerror(-ret));
7960 
7961 }
7962 
7963 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
7964 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7965 				 filter, "2tuple_filter");
7966 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
7967 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7968 				port_id, UINT8);
7969 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
7970 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7971 				 ops, "add#del");
7972 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
7973 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7974 				dst_port, "dst_port");
7975 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
7976 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7977 				dst_port_value, UINT16);
7978 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
7979 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7980 				protocol, "protocol");
7981 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
7982 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7983 				protocol_value, UINT8);
7984 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
7985 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7986 				mask, "mask");
7987 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
7988 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7989 				mask_value, INT8);
7990 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
7991 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7992 				tcp_flags, "tcp_flags");
7993 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
7994 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7995 				tcp_flags_value, UINT8);
7996 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
7997 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7998 				priority, "priority");
7999 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
8000 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8001 				priority_value, UINT8);
8002 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
8003 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8004 				queue, "queue");
8005 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
8006 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8007 				queue_id, UINT16);
8008 
8009 cmdline_parse_inst_t cmd_2tuple_filter = {
8010 	.f = cmd_2tuple_filter_parsed,
8011 	.data = NULL,
8012 	.help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
8013 		"<value> mask <value> tcp_flags <value> priority <value> queue "
8014 		"<queue_id>: Add a 2tuple filter",
8015 	.tokens = {
8016 		(void *)&cmd_2tuple_filter_filter,
8017 		(void *)&cmd_2tuple_filter_port_id,
8018 		(void *)&cmd_2tuple_filter_ops,
8019 		(void *)&cmd_2tuple_filter_dst_port,
8020 		(void *)&cmd_2tuple_filter_dst_port_value,
8021 		(void *)&cmd_2tuple_filter_protocol,
8022 		(void *)&cmd_2tuple_filter_protocol_value,
8023 		(void *)&cmd_2tuple_filter_mask,
8024 		(void *)&cmd_2tuple_filter_mask_value,
8025 		(void *)&cmd_2tuple_filter_tcp_flags,
8026 		(void *)&cmd_2tuple_filter_tcp_flags_value,
8027 		(void *)&cmd_2tuple_filter_priority,
8028 		(void *)&cmd_2tuple_filter_priority_value,
8029 		(void *)&cmd_2tuple_filter_queue,
8030 		(void *)&cmd_2tuple_filter_queue_id,
8031 		NULL,
8032 	},
8033 };
8034 
8035 /* *** ADD/REMOVE A 5tuple FILTER *** */
8036 struct cmd_5tuple_filter_result {
8037 	cmdline_fixed_string_t filter;
8038 	uint8_t  port_id;
8039 	cmdline_fixed_string_t ops;
8040 	cmdline_fixed_string_t dst_ip;
8041 	cmdline_ipaddr_t dst_ip_value;
8042 	cmdline_fixed_string_t src_ip;
8043 	cmdline_ipaddr_t src_ip_value;
8044 	cmdline_fixed_string_t dst_port;
8045 	uint16_t dst_port_value;
8046 	cmdline_fixed_string_t src_port;
8047 	uint16_t src_port_value;
8048 	cmdline_fixed_string_t protocol;
8049 	uint8_t protocol_value;
8050 	cmdline_fixed_string_t mask;
8051 	uint8_t  mask_value;
8052 	cmdline_fixed_string_t tcp_flags;
8053 	uint8_t tcp_flags_value;
8054 	cmdline_fixed_string_t priority;
8055 	uint8_t  priority_value;
8056 	cmdline_fixed_string_t queue;
8057 	uint16_t  queue_id;
8058 };
8059 
8060 static void
8061 cmd_5tuple_filter_parsed(void *parsed_result,
8062 			__attribute__((unused)) struct cmdline *cl,
8063 			__attribute__((unused)) void *data)
8064 {
8065 	struct rte_eth_ntuple_filter filter;
8066 	struct cmd_5tuple_filter_result *res = parsed_result;
8067 	int ret = 0;
8068 
8069 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8070 	if (ret < 0) {
8071 		printf("ntuple filter is not supported on port %u.\n",
8072 			res->port_id);
8073 		return;
8074 	}
8075 
8076 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8077 
8078 	filter.flags = RTE_5TUPLE_FLAGS;
8079 	filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
8080 	filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
8081 	filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
8082 	filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8083 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8084 	filter.proto = res->protocol_value;
8085 	filter.priority = res->priority_value;
8086 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8087 		printf("nonzero tcp_flags is only meaningful"
8088 			" when protocol is TCP.\n");
8089 		return;
8090 	}
8091 	if (res->tcp_flags_value > TCP_FLAG_ALL) {
8092 		printf("invalid TCP flags.\n");
8093 		return;
8094 	}
8095 
8096 	if (res->tcp_flags_value != 0) {
8097 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8098 		filter.tcp_flags = res->tcp_flags_value;
8099 	}
8100 
8101 	if (res->dst_ip_value.family == AF_INET)
8102 		/* no need to convert, already big endian. */
8103 		filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
8104 	else {
8105 		if (filter.dst_ip_mask == 0) {
8106 			printf("can not support ipv6 involved compare.\n");
8107 			return;
8108 		}
8109 		filter.dst_ip = 0;
8110 	}
8111 
8112 	if (res->src_ip_value.family == AF_INET)
8113 		/* no need to convert, already big endian. */
8114 		filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
8115 	else {
8116 		if (filter.src_ip_mask == 0) {
8117 			printf("can not support ipv6 involved compare.\n");
8118 			return;
8119 		}
8120 		filter.src_ip = 0;
8121 	}
8122 	/* need convert to big endian. */
8123 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8124 	filter.src_port = rte_cpu_to_be_16(res->src_port_value);
8125 	filter.queue = res->queue_id;
8126 
8127 	if (!strcmp(res->ops, "add"))
8128 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8129 				RTE_ETH_FILTER_NTUPLE,
8130 				RTE_ETH_FILTER_ADD,
8131 				&filter);
8132 	else
8133 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8134 				RTE_ETH_FILTER_NTUPLE,
8135 				RTE_ETH_FILTER_DELETE,
8136 				&filter);
8137 	if (ret < 0)
8138 		printf("5tuple filter programming error: (%s)\n",
8139 			strerror(-ret));
8140 }
8141 
8142 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
8143 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8144 				 filter, "5tuple_filter");
8145 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
8146 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8147 				port_id, UINT8);
8148 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
8149 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8150 				 ops, "add#del");
8151 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
8152 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8153 				dst_ip, "dst_ip");
8154 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
8155 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8156 				dst_ip_value);
8157 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
8158 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8159 				src_ip, "src_ip");
8160 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
8161 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8162 				src_ip_value);
8163 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
8164 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8165 				dst_port, "dst_port");
8166 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
8167 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8168 				dst_port_value, UINT16);
8169 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
8170 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8171 				src_port, "src_port");
8172 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
8173 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8174 				src_port_value, UINT16);
8175 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
8176 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8177 				protocol, "protocol");
8178 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
8179 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8180 				protocol_value, UINT8);
8181 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
8182 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8183 				mask, "mask");
8184 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
8185 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8186 				mask_value, INT8);
8187 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
8188 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8189 				tcp_flags, "tcp_flags");
8190 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
8191 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8192 				tcp_flags_value, UINT8);
8193 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
8194 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8195 				priority, "priority");
8196 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
8197 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8198 				priority_value, UINT8);
8199 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
8200 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8201 				queue, "queue");
8202 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
8203 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8204 				queue_id, UINT16);
8205 
8206 cmdline_parse_inst_t cmd_5tuple_filter = {
8207 	.f = cmd_5tuple_filter_parsed,
8208 	.data = NULL,
8209 	.help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
8210 		"src_ip <value> dst_port <value> src_port <value> "
8211 		"protocol <value>  mask <value> tcp_flags <value> "
8212 		"priority <value> queue <queue_id>: Add/Del a 5tuple filter",
8213 	.tokens = {
8214 		(void *)&cmd_5tuple_filter_filter,
8215 		(void *)&cmd_5tuple_filter_port_id,
8216 		(void *)&cmd_5tuple_filter_ops,
8217 		(void *)&cmd_5tuple_filter_dst_ip,
8218 		(void *)&cmd_5tuple_filter_dst_ip_value,
8219 		(void *)&cmd_5tuple_filter_src_ip,
8220 		(void *)&cmd_5tuple_filter_src_ip_value,
8221 		(void *)&cmd_5tuple_filter_dst_port,
8222 		(void *)&cmd_5tuple_filter_dst_port_value,
8223 		(void *)&cmd_5tuple_filter_src_port,
8224 		(void *)&cmd_5tuple_filter_src_port_value,
8225 		(void *)&cmd_5tuple_filter_protocol,
8226 		(void *)&cmd_5tuple_filter_protocol_value,
8227 		(void *)&cmd_5tuple_filter_mask,
8228 		(void *)&cmd_5tuple_filter_mask_value,
8229 		(void *)&cmd_5tuple_filter_tcp_flags,
8230 		(void *)&cmd_5tuple_filter_tcp_flags_value,
8231 		(void *)&cmd_5tuple_filter_priority,
8232 		(void *)&cmd_5tuple_filter_priority_value,
8233 		(void *)&cmd_5tuple_filter_queue,
8234 		(void *)&cmd_5tuple_filter_queue_id,
8235 		NULL,
8236 	},
8237 };
8238 
8239 /* *** ADD/REMOVE A flex FILTER *** */
8240 struct cmd_flex_filter_result {
8241 	cmdline_fixed_string_t filter;
8242 	cmdline_fixed_string_t ops;
8243 	uint8_t port_id;
8244 	cmdline_fixed_string_t len;
8245 	uint8_t len_value;
8246 	cmdline_fixed_string_t bytes;
8247 	cmdline_fixed_string_t bytes_value;
8248 	cmdline_fixed_string_t mask;
8249 	cmdline_fixed_string_t mask_value;
8250 	cmdline_fixed_string_t priority;
8251 	uint8_t priority_value;
8252 	cmdline_fixed_string_t queue;
8253 	uint16_t queue_id;
8254 };
8255 
8256 static int xdigit2val(unsigned char c)
8257 {
8258 	int val;
8259 	if (isdigit(c))
8260 		val = c - '0';
8261 	else if (isupper(c))
8262 		val = c - 'A' + 10;
8263 	else
8264 		val = c - 'a' + 10;
8265 	return val;
8266 }
8267 
8268 static void
8269 cmd_flex_filter_parsed(void *parsed_result,
8270 			  __attribute__((unused)) struct cmdline *cl,
8271 			  __attribute__((unused)) void *data)
8272 {
8273 	int ret = 0;
8274 	struct rte_eth_flex_filter filter;
8275 	struct cmd_flex_filter_result *res = parsed_result;
8276 	char *bytes_ptr, *mask_ptr;
8277 	uint16_t len, i, j = 0;
8278 	char c;
8279 	int val;
8280 	uint8_t byte = 0;
8281 
8282 	if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
8283 		printf("the len exceed the max length 128\n");
8284 		return;
8285 	}
8286 	memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
8287 	filter.len = res->len_value;
8288 	filter.priority = res->priority_value;
8289 	filter.queue = res->queue_id;
8290 	bytes_ptr = res->bytes_value;
8291 	mask_ptr = res->mask_value;
8292 
8293 	 /* translate bytes string to array. */
8294 	if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
8295 		(bytes_ptr[1] == 'X')))
8296 		bytes_ptr += 2;
8297 	len = strnlen(bytes_ptr, res->len_value * 2);
8298 	if (len == 0 || (len % 8 != 0)) {
8299 		printf("please check len and bytes input\n");
8300 		return;
8301 	}
8302 	for (i = 0; i < len; i++) {
8303 		c = bytes_ptr[i];
8304 		if (isxdigit(c) == 0) {
8305 			/* invalid characters. */
8306 			printf("invalid input\n");
8307 			return;
8308 		}
8309 		val = xdigit2val(c);
8310 		if (i % 2) {
8311 			byte |= val;
8312 			filter.bytes[j] = byte;
8313 			printf("bytes[%d]:%02x ", j, filter.bytes[j]);
8314 			j++;
8315 			byte = 0;
8316 		} else
8317 			byte |= val << 4;
8318 	}
8319 	printf("\n");
8320 	 /* translate mask string to uint8_t array. */
8321 	if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
8322 		(mask_ptr[1] == 'X')))
8323 		mask_ptr += 2;
8324 	len = strnlen(mask_ptr, (res->len_value + 3) / 4);
8325 	if (len == 0) {
8326 		printf("invalid input\n");
8327 		return;
8328 	}
8329 	j = 0;
8330 	byte = 0;
8331 	for (i = 0; i < len; i++) {
8332 		c = mask_ptr[i];
8333 		if (isxdigit(c) == 0) {
8334 			/* invalid characters. */
8335 			printf("invalid input\n");
8336 			return;
8337 		}
8338 		val = xdigit2val(c);
8339 		if (i % 2) {
8340 			byte |= val;
8341 			filter.mask[j] = byte;
8342 			printf("mask[%d]:%02x ", j, filter.mask[j]);
8343 			j++;
8344 			byte = 0;
8345 		} else
8346 			byte |= val << 4;
8347 	}
8348 	printf("\n");
8349 
8350 	if (!strcmp(res->ops, "add"))
8351 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8352 				RTE_ETH_FILTER_FLEXIBLE,
8353 				RTE_ETH_FILTER_ADD,
8354 				&filter);
8355 	else
8356 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8357 				RTE_ETH_FILTER_FLEXIBLE,
8358 				RTE_ETH_FILTER_DELETE,
8359 				&filter);
8360 
8361 	if (ret < 0)
8362 		printf("flex filter setting error: (%s)\n", strerror(-ret));
8363 }
8364 
8365 cmdline_parse_token_string_t cmd_flex_filter_filter =
8366 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8367 				filter, "flex_filter");
8368 cmdline_parse_token_num_t cmd_flex_filter_port_id =
8369 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8370 				port_id, UINT8);
8371 cmdline_parse_token_string_t cmd_flex_filter_ops =
8372 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8373 				ops, "add#del");
8374 cmdline_parse_token_string_t cmd_flex_filter_len =
8375 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8376 				len, "len");
8377 cmdline_parse_token_num_t cmd_flex_filter_len_value =
8378 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8379 				len_value, UINT8);
8380 cmdline_parse_token_string_t cmd_flex_filter_bytes =
8381 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8382 				bytes, "bytes");
8383 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
8384 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8385 				bytes_value, NULL);
8386 cmdline_parse_token_string_t cmd_flex_filter_mask =
8387 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8388 				mask, "mask");
8389 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
8390 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8391 				mask_value, NULL);
8392 cmdline_parse_token_string_t cmd_flex_filter_priority =
8393 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8394 				priority, "priority");
8395 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
8396 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8397 				priority_value, UINT8);
8398 cmdline_parse_token_string_t cmd_flex_filter_queue =
8399 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8400 				queue, "queue");
8401 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
8402 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8403 				queue_id, UINT16);
8404 cmdline_parse_inst_t cmd_flex_filter = {
8405 	.f = cmd_flex_filter_parsed,
8406 	.data = NULL,
8407 	.help_str = "flex_filter <port_id> add|del len <value> bytes "
8408 		"<value> mask <value> priority <value> queue <queue_id>: "
8409 		"Add/Del a flex filter",
8410 	.tokens = {
8411 		(void *)&cmd_flex_filter_filter,
8412 		(void *)&cmd_flex_filter_port_id,
8413 		(void *)&cmd_flex_filter_ops,
8414 		(void *)&cmd_flex_filter_len,
8415 		(void *)&cmd_flex_filter_len_value,
8416 		(void *)&cmd_flex_filter_bytes,
8417 		(void *)&cmd_flex_filter_bytes_value,
8418 		(void *)&cmd_flex_filter_mask,
8419 		(void *)&cmd_flex_filter_mask_value,
8420 		(void *)&cmd_flex_filter_priority,
8421 		(void *)&cmd_flex_filter_priority_value,
8422 		(void *)&cmd_flex_filter_queue,
8423 		(void *)&cmd_flex_filter_queue_id,
8424 		NULL,
8425 	},
8426 };
8427 
8428 /* *** Filters Control *** */
8429 
8430 /* *** deal with ethertype filter *** */
8431 struct cmd_ethertype_filter_result {
8432 	cmdline_fixed_string_t filter;
8433 	uint8_t port_id;
8434 	cmdline_fixed_string_t ops;
8435 	cmdline_fixed_string_t mac;
8436 	struct ether_addr mac_addr;
8437 	cmdline_fixed_string_t ethertype;
8438 	uint16_t ethertype_value;
8439 	cmdline_fixed_string_t drop;
8440 	cmdline_fixed_string_t queue;
8441 	uint16_t  queue_id;
8442 };
8443 
8444 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
8445 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8446 				 filter, "ethertype_filter");
8447 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
8448 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8449 			      port_id, UINT8);
8450 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
8451 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8452 				 ops, "add#del");
8453 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
8454 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8455 				 mac, "mac_addr#mac_ignr");
8456 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
8457 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
8458 				     mac_addr);
8459 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
8460 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8461 				 ethertype, "ethertype");
8462 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
8463 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8464 			      ethertype_value, UINT16);
8465 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
8466 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8467 				 drop, "drop#fwd");
8468 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
8469 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8470 				 queue, "queue");
8471 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
8472 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8473 			      queue_id, UINT16);
8474 
8475 static void
8476 cmd_ethertype_filter_parsed(void *parsed_result,
8477 			  __attribute__((unused)) struct cmdline *cl,
8478 			  __attribute__((unused)) void *data)
8479 {
8480 	struct cmd_ethertype_filter_result *res = parsed_result;
8481 	struct rte_eth_ethertype_filter filter;
8482 	int ret = 0;
8483 
8484 	ret = rte_eth_dev_filter_supported(res->port_id,
8485 			RTE_ETH_FILTER_ETHERTYPE);
8486 	if (ret < 0) {
8487 		printf("ethertype filter is not supported on port %u.\n",
8488 			res->port_id);
8489 		return;
8490 	}
8491 
8492 	memset(&filter, 0, sizeof(filter));
8493 	if (!strcmp(res->mac, "mac_addr")) {
8494 		filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
8495 		(void)rte_memcpy(&filter.mac_addr, &res->mac_addr,
8496 			sizeof(struct ether_addr));
8497 	}
8498 	if (!strcmp(res->drop, "drop"))
8499 		filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
8500 	filter.ether_type = res->ethertype_value;
8501 	filter.queue = res->queue_id;
8502 
8503 	if (!strcmp(res->ops, "add"))
8504 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8505 				RTE_ETH_FILTER_ETHERTYPE,
8506 				RTE_ETH_FILTER_ADD,
8507 				&filter);
8508 	else
8509 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8510 				RTE_ETH_FILTER_ETHERTYPE,
8511 				RTE_ETH_FILTER_DELETE,
8512 				&filter);
8513 	if (ret < 0)
8514 		printf("ethertype filter programming error: (%s)\n",
8515 			strerror(-ret));
8516 }
8517 
8518 cmdline_parse_inst_t cmd_ethertype_filter = {
8519 	.f = cmd_ethertype_filter_parsed,
8520 	.data = NULL,
8521 	.help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
8522 		"<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
8523 		"Add or delete an ethertype filter entry",
8524 	.tokens = {
8525 		(void *)&cmd_ethertype_filter_filter,
8526 		(void *)&cmd_ethertype_filter_port_id,
8527 		(void *)&cmd_ethertype_filter_ops,
8528 		(void *)&cmd_ethertype_filter_mac,
8529 		(void *)&cmd_ethertype_filter_mac_addr,
8530 		(void *)&cmd_ethertype_filter_ethertype,
8531 		(void *)&cmd_ethertype_filter_ethertype_value,
8532 		(void *)&cmd_ethertype_filter_drop,
8533 		(void *)&cmd_ethertype_filter_queue,
8534 		(void *)&cmd_ethertype_filter_queue_id,
8535 		NULL,
8536 	},
8537 };
8538 
8539 /* *** deal with flow director filter *** */
8540 struct cmd_flow_director_result {
8541 	cmdline_fixed_string_t flow_director_filter;
8542 	uint8_t port_id;
8543 	cmdline_fixed_string_t mode;
8544 	cmdline_fixed_string_t mode_value;
8545 	cmdline_fixed_string_t ops;
8546 	cmdline_fixed_string_t flow;
8547 	cmdline_fixed_string_t flow_type;
8548 	cmdline_fixed_string_t ether;
8549 	uint16_t ether_type;
8550 	cmdline_fixed_string_t src;
8551 	cmdline_ipaddr_t ip_src;
8552 	uint16_t port_src;
8553 	cmdline_fixed_string_t dst;
8554 	cmdline_ipaddr_t ip_dst;
8555 	uint16_t port_dst;
8556 	cmdline_fixed_string_t verify_tag;
8557 	uint32_t verify_tag_value;
8558 	cmdline_ipaddr_t tos;
8559 	uint8_t tos_value;
8560 	cmdline_ipaddr_t proto;
8561 	uint8_t proto_value;
8562 	cmdline_ipaddr_t ttl;
8563 	uint8_t ttl_value;
8564 	cmdline_fixed_string_t vlan;
8565 	uint16_t vlan_value;
8566 	cmdline_fixed_string_t flexbytes;
8567 	cmdline_fixed_string_t flexbytes_value;
8568 	cmdline_fixed_string_t pf_vf;
8569 	cmdline_fixed_string_t drop;
8570 	cmdline_fixed_string_t queue;
8571 	uint16_t  queue_id;
8572 	cmdline_fixed_string_t fd_id;
8573 	uint32_t  fd_id_value;
8574 	cmdline_fixed_string_t mac;
8575 	struct ether_addr mac_addr;
8576 	cmdline_fixed_string_t tunnel;
8577 	cmdline_fixed_string_t tunnel_type;
8578 	cmdline_fixed_string_t tunnel_id;
8579 	uint32_t tunnel_id_value;
8580 };
8581 
8582 static inline int
8583 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
8584 {
8585 	char s[256];
8586 	const char *p, *p0 = q_arg;
8587 	char *end;
8588 	unsigned long int_fld;
8589 	char *str_fld[max_num];
8590 	int i;
8591 	unsigned size;
8592 	int ret = -1;
8593 
8594 	p = strchr(p0, '(');
8595 	if (p == NULL)
8596 		return -1;
8597 	++p;
8598 	p0 = strchr(p, ')');
8599 	if (p0 == NULL)
8600 		return -1;
8601 
8602 	size = p0 - p;
8603 	if (size >= sizeof(s))
8604 		return -1;
8605 
8606 	snprintf(s, sizeof(s), "%.*s", size, p);
8607 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8608 	if (ret < 0 || ret > max_num)
8609 		return -1;
8610 	for (i = 0; i < ret; i++) {
8611 		errno = 0;
8612 		int_fld = strtoul(str_fld[i], &end, 0);
8613 		if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
8614 			return -1;
8615 		flexbytes[i] = (uint8_t)int_fld;
8616 	}
8617 	return ret;
8618 }
8619 
8620 static uint16_t
8621 str2flowtype(char *string)
8622 {
8623 	uint8_t i = 0;
8624 	static const struct {
8625 		char str[32];
8626 		uint16_t type;
8627 	} flowtype_str[] = {
8628 		{"raw", RTE_ETH_FLOW_RAW},
8629 		{"ipv4", RTE_ETH_FLOW_IPV4},
8630 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
8631 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
8632 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
8633 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
8634 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
8635 		{"ipv6", RTE_ETH_FLOW_IPV6},
8636 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
8637 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
8638 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
8639 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
8640 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
8641 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
8642 	};
8643 
8644 	for (i = 0; i < RTE_DIM(flowtype_str); i++) {
8645 		if (!strcmp(flowtype_str[i].str, string))
8646 			return flowtype_str[i].type;
8647 	}
8648 	return RTE_ETH_FLOW_UNKNOWN;
8649 }
8650 
8651 static enum rte_eth_fdir_tunnel_type
8652 str2fdir_tunneltype(char *string)
8653 {
8654 	uint8_t i = 0;
8655 
8656 	static const struct {
8657 		char str[32];
8658 		enum rte_eth_fdir_tunnel_type type;
8659 	} tunneltype_str[] = {
8660 		{"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
8661 		{"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
8662 	};
8663 
8664 	for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
8665 		if (!strcmp(tunneltype_str[i].str, string))
8666 			return tunneltype_str[i].type;
8667 	}
8668 	return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
8669 }
8670 
8671 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
8672 do { \
8673 	if ((ip_addr).family == AF_INET) \
8674 		(ip) = (ip_addr).addr.ipv4.s_addr; \
8675 	else { \
8676 		printf("invalid parameter.\n"); \
8677 		return; \
8678 	} \
8679 } while (0)
8680 
8681 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
8682 do { \
8683 	if ((ip_addr).family == AF_INET6) \
8684 		(void)rte_memcpy(&(ip), \
8685 				 &((ip_addr).addr.ipv6), \
8686 				 sizeof(struct in6_addr)); \
8687 	else { \
8688 		printf("invalid parameter.\n"); \
8689 		return; \
8690 	} \
8691 } while (0)
8692 
8693 static void
8694 cmd_flow_director_filter_parsed(void *parsed_result,
8695 			  __attribute__((unused)) struct cmdline *cl,
8696 			  __attribute__((unused)) void *data)
8697 {
8698 	struct cmd_flow_director_result *res = parsed_result;
8699 	struct rte_eth_fdir_filter entry;
8700 	uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
8701 	char *end;
8702 	unsigned long vf_id;
8703 	int ret = 0;
8704 
8705 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8706 	if (ret < 0) {
8707 		printf("flow director is not supported on port %u.\n",
8708 			res->port_id);
8709 		return;
8710 	}
8711 	memset(flexbytes, 0, sizeof(flexbytes));
8712 	memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
8713 
8714 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
8715 		if (strcmp(res->mode_value, "MAC-VLAN")) {
8716 			printf("Please set mode to MAC-VLAN.\n");
8717 			return;
8718 		}
8719 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8720 		if (strcmp(res->mode_value, "Tunnel")) {
8721 			printf("Please set mode to Tunnel.\n");
8722 			return;
8723 		}
8724 	} else {
8725 		if (strcmp(res->mode_value, "IP")) {
8726 			printf("Please set mode to IP.\n");
8727 			return;
8728 		}
8729 		entry.input.flow_type = str2flowtype(res->flow_type);
8730 	}
8731 
8732 	ret = parse_flexbytes(res->flexbytes_value,
8733 					flexbytes,
8734 					RTE_ETH_FDIR_MAX_FLEXLEN);
8735 	if (ret < 0) {
8736 		printf("error: Cannot parse flexbytes input.\n");
8737 		return;
8738 	}
8739 
8740 	switch (entry.input.flow_type) {
8741 	case RTE_ETH_FLOW_FRAG_IPV4:
8742 	case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
8743 		entry.input.flow.ip4_flow.proto = res->proto_value;
8744 	case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
8745 	case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
8746 		IPV4_ADDR_TO_UINT(res->ip_dst,
8747 			entry.input.flow.ip4_flow.dst_ip);
8748 		IPV4_ADDR_TO_UINT(res->ip_src,
8749 			entry.input.flow.ip4_flow.src_ip);
8750 		entry.input.flow.ip4_flow.tos = res->tos_value;
8751 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
8752 		/* need convert to big endian. */
8753 		entry.input.flow.udp4_flow.dst_port =
8754 				rte_cpu_to_be_16(res->port_dst);
8755 		entry.input.flow.udp4_flow.src_port =
8756 				rte_cpu_to_be_16(res->port_src);
8757 		break;
8758 	case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
8759 		IPV4_ADDR_TO_UINT(res->ip_dst,
8760 			entry.input.flow.sctp4_flow.ip.dst_ip);
8761 		IPV4_ADDR_TO_UINT(res->ip_src,
8762 			entry.input.flow.sctp4_flow.ip.src_ip);
8763 		entry.input.flow.ip4_flow.tos = res->tos_value;
8764 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
8765 		/* need convert to big endian. */
8766 		entry.input.flow.sctp4_flow.dst_port =
8767 				rte_cpu_to_be_16(res->port_dst);
8768 		entry.input.flow.sctp4_flow.src_port =
8769 				rte_cpu_to_be_16(res->port_src);
8770 		entry.input.flow.sctp4_flow.verify_tag =
8771 				rte_cpu_to_be_32(res->verify_tag_value);
8772 		break;
8773 	case RTE_ETH_FLOW_FRAG_IPV6:
8774 	case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
8775 		entry.input.flow.ipv6_flow.proto = res->proto_value;
8776 	case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
8777 	case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
8778 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
8779 			entry.input.flow.ipv6_flow.dst_ip);
8780 		IPV6_ADDR_TO_ARRAY(res->ip_src,
8781 			entry.input.flow.ipv6_flow.src_ip);
8782 		entry.input.flow.ipv6_flow.tc = res->tos_value;
8783 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
8784 		/* need convert to big endian. */
8785 		entry.input.flow.udp6_flow.dst_port =
8786 				rte_cpu_to_be_16(res->port_dst);
8787 		entry.input.flow.udp6_flow.src_port =
8788 				rte_cpu_to_be_16(res->port_src);
8789 		break;
8790 	case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
8791 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
8792 			entry.input.flow.sctp6_flow.ip.dst_ip);
8793 		IPV6_ADDR_TO_ARRAY(res->ip_src,
8794 			entry.input.flow.sctp6_flow.ip.src_ip);
8795 		entry.input.flow.ipv6_flow.tc = res->tos_value;
8796 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
8797 		/* need convert to big endian. */
8798 		entry.input.flow.sctp6_flow.dst_port =
8799 				rte_cpu_to_be_16(res->port_dst);
8800 		entry.input.flow.sctp6_flow.src_port =
8801 				rte_cpu_to_be_16(res->port_src);
8802 		entry.input.flow.sctp6_flow.verify_tag =
8803 				rte_cpu_to_be_32(res->verify_tag_value);
8804 		break;
8805 	case RTE_ETH_FLOW_L2_PAYLOAD:
8806 		entry.input.flow.l2_flow.ether_type =
8807 			rte_cpu_to_be_16(res->ether_type);
8808 		break;
8809 	default:
8810 		break;
8811 	}
8812 
8813 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
8814 		(void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
8815 				 &res->mac_addr,
8816 				 sizeof(struct ether_addr));
8817 
8818 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8819 		(void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
8820 				 &res->mac_addr,
8821 				 sizeof(struct ether_addr));
8822 		entry.input.flow.tunnel_flow.tunnel_type =
8823 			str2fdir_tunneltype(res->tunnel_type);
8824 		entry.input.flow.tunnel_flow.tunnel_id =
8825 			rte_cpu_to_be_32(res->tunnel_id_value);
8826 	}
8827 
8828 	(void)rte_memcpy(entry.input.flow_ext.flexbytes,
8829 		   flexbytes,
8830 		   RTE_ETH_FDIR_MAX_FLEXLEN);
8831 
8832 	entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
8833 
8834 	entry.action.flex_off = 0;  /*use 0 by default */
8835 	if (!strcmp(res->drop, "drop"))
8836 		entry.action.behavior = RTE_ETH_FDIR_REJECT;
8837 	else
8838 		entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
8839 
8840 	if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
8841 	    fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8842 		if (!strcmp(res->pf_vf, "pf"))
8843 			entry.input.flow_ext.is_vf = 0;
8844 		else if (!strncmp(res->pf_vf, "vf", 2)) {
8845 			struct rte_eth_dev_info dev_info;
8846 
8847 			memset(&dev_info, 0, sizeof(dev_info));
8848 			rte_eth_dev_info_get(res->port_id, &dev_info);
8849 			errno = 0;
8850 			vf_id = strtoul(res->pf_vf + 2, &end, 10);
8851 			if (errno != 0 || *end != '\0' ||
8852 			    vf_id >= dev_info.max_vfs) {
8853 				printf("invalid parameter %s.\n", res->pf_vf);
8854 				return;
8855 			}
8856 			entry.input.flow_ext.is_vf = 1;
8857 			entry.input.flow_ext.dst_id = (uint16_t)vf_id;
8858 		} else {
8859 			printf("invalid parameter %s.\n", res->pf_vf);
8860 			return;
8861 		}
8862 	}
8863 
8864 	/* set to report FD ID by default */
8865 	entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
8866 	entry.action.rx_queue = res->queue_id;
8867 	entry.soft_id = res->fd_id_value;
8868 	if (!strcmp(res->ops, "add"))
8869 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8870 					     RTE_ETH_FILTER_ADD, &entry);
8871 	else if (!strcmp(res->ops, "del"))
8872 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8873 					     RTE_ETH_FILTER_DELETE, &entry);
8874 	else
8875 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8876 					     RTE_ETH_FILTER_UPDATE, &entry);
8877 	if (ret < 0)
8878 		printf("flow director programming error: (%s)\n",
8879 			strerror(-ret));
8880 }
8881 
8882 cmdline_parse_token_string_t cmd_flow_director_filter =
8883 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8884 				 flow_director_filter, "flow_director_filter");
8885 cmdline_parse_token_num_t cmd_flow_director_port_id =
8886 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8887 			      port_id, UINT8);
8888 cmdline_parse_token_string_t cmd_flow_director_ops =
8889 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8890 				 ops, "add#del#update");
8891 cmdline_parse_token_string_t cmd_flow_director_flow =
8892 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8893 				 flow, "flow");
8894 cmdline_parse_token_string_t cmd_flow_director_flow_type =
8895 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8896 		flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
8897 		"ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
8898 cmdline_parse_token_string_t cmd_flow_director_ether =
8899 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8900 				 ether, "ether");
8901 cmdline_parse_token_num_t cmd_flow_director_ether_type =
8902 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8903 			      ether_type, UINT16);
8904 cmdline_parse_token_string_t cmd_flow_director_src =
8905 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8906 				 src, "src");
8907 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
8908 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8909 				 ip_src);
8910 cmdline_parse_token_num_t cmd_flow_director_port_src =
8911 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8912 			      port_src, UINT16);
8913 cmdline_parse_token_string_t cmd_flow_director_dst =
8914 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8915 				 dst, "dst");
8916 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
8917 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8918 				 ip_dst);
8919 cmdline_parse_token_num_t cmd_flow_director_port_dst =
8920 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8921 			      port_dst, UINT16);
8922 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
8923 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8924 				  verify_tag, "verify_tag");
8925 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
8926 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8927 			      verify_tag_value, UINT32);
8928 cmdline_parse_token_string_t cmd_flow_director_tos =
8929 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8930 				 tos, "tos");
8931 cmdline_parse_token_num_t cmd_flow_director_tos_value =
8932 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8933 			      tos_value, UINT8);
8934 cmdline_parse_token_string_t cmd_flow_director_proto =
8935 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8936 				 proto, "proto");
8937 cmdline_parse_token_num_t cmd_flow_director_proto_value =
8938 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8939 			      proto_value, UINT8);
8940 cmdline_parse_token_string_t cmd_flow_director_ttl =
8941 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8942 				 ttl, "ttl");
8943 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
8944 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8945 			      ttl_value, UINT8);
8946 cmdline_parse_token_string_t cmd_flow_director_vlan =
8947 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8948 				 vlan, "vlan");
8949 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
8950 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8951 			      vlan_value, UINT16);
8952 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
8953 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8954 				 flexbytes, "flexbytes");
8955 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
8956 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8957 			      flexbytes_value, NULL);
8958 cmdline_parse_token_string_t cmd_flow_director_drop =
8959 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8960 				 drop, "drop#fwd");
8961 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
8962 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8963 			      pf_vf, NULL);
8964 cmdline_parse_token_string_t cmd_flow_director_queue =
8965 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8966 				 queue, "queue");
8967 cmdline_parse_token_num_t cmd_flow_director_queue_id =
8968 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8969 			      queue_id, UINT16);
8970 cmdline_parse_token_string_t cmd_flow_director_fd_id =
8971 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8972 				 fd_id, "fd_id");
8973 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
8974 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8975 			      fd_id_value, UINT32);
8976 
8977 cmdline_parse_token_string_t cmd_flow_director_mode =
8978 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8979 				 mode, "mode");
8980 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
8981 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8982 				 mode_value, "IP");
8983 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
8984 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8985 				 mode_value, "MAC-VLAN");
8986 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
8987 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8988 				 mode_value, "Tunnel");
8989 cmdline_parse_token_string_t cmd_flow_director_mac =
8990 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8991 				 mac, "mac");
8992 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
8993 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
8994 				    mac_addr);
8995 cmdline_parse_token_string_t cmd_flow_director_tunnel =
8996 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8997 				 tunnel, "tunnel");
8998 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
8999 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9000 				 tunnel_type, "NVGRE#VxLAN");
9001 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
9002 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9003 				 tunnel_id, "tunnel-id");
9004 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
9005 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9006 			      tunnel_id_value, UINT32);
9007 
9008 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
9009 	.f = cmd_flow_director_filter_parsed,
9010 	.data = NULL,
9011 	.help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
9012 		" ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
9013 		"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
9014 		"l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
9015 		"proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
9016 		"flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
9017 		"fd_id <fd_id_value>: "
9018 		"Add or delete an ip flow director entry on NIC",
9019 	.tokens = {
9020 		(void *)&cmd_flow_director_filter,
9021 		(void *)&cmd_flow_director_port_id,
9022 		(void *)&cmd_flow_director_mode,
9023 		(void *)&cmd_flow_director_mode_ip,
9024 		(void *)&cmd_flow_director_ops,
9025 		(void *)&cmd_flow_director_flow,
9026 		(void *)&cmd_flow_director_flow_type,
9027 		(void *)&cmd_flow_director_src,
9028 		(void *)&cmd_flow_director_ip_src,
9029 		(void *)&cmd_flow_director_dst,
9030 		(void *)&cmd_flow_director_ip_dst,
9031 		(void *)&cmd_flow_director_tos,
9032 		(void *)&cmd_flow_director_tos_value,
9033 		(void *)&cmd_flow_director_proto,
9034 		(void *)&cmd_flow_director_proto_value,
9035 		(void *)&cmd_flow_director_ttl,
9036 		(void *)&cmd_flow_director_ttl_value,
9037 		(void *)&cmd_flow_director_vlan,
9038 		(void *)&cmd_flow_director_vlan_value,
9039 		(void *)&cmd_flow_director_flexbytes,
9040 		(void *)&cmd_flow_director_flexbytes_value,
9041 		(void *)&cmd_flow_director_drop,
9042 		(void *)&cmd_flow_director_pf_vf,
9043 		(void *)&cmd_flow_director_queue,
9044 		(void *)&cmd_flow_director_queue_id,
9045 		(void *)&cmd_flow_director_fd_id,
9046 		(void *)&cmd_flow_director_fd_id_value,
9047 		NULL,
9048 	},
9049 };
9050 
9051 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
9052 	.f = cmd_flow_director_filter_parsed,
9053 	.data = NULL,
9054 	.help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
9055 		"director entry on NIC",
9056 	.tokens = {
9057 		(void *)&cmd_flow_director_filter,
9058 		(void *)&cmd_flow_director_port_id,
9059 		(void *)&cmd_flow_director_mode,
9060 		(void *)&cmd_flow_director_mode_ip,
9061 		(void *)&cmd_flow_director_ops,
9062 		(void *)&cmd_flow_director_flow,
9063 		(void *)&cmd_flow_director_flow_type,
9064 		(void *)&cmd_flow_director_src,
9065 		(void *)&cmd_flow_director_ip_src,
9066 		(void *)&cmd_flow_director_port_src,
9067 		(void *)&cmd_flow_director_dst,
9068 		(void *)&cmd_flow_director_ip_dst,
9069 		(void *)&cmd_flow_director_port_dst,
9070 		(void *)&cmd_flow_director_tos,
9071 		(void *)&cmd_flow_director_tos_value,
9072 		(void *)&cmd_flow_director_ttl,
9073 		(void *)&cmd_flow_director_ttl_value,
9074 		(void *)&cmd_flow_director_vlan,
9075 		(void *)&cmd_flow_director_vlan_value,
9076 		(void *)&cmd_flow_director_flexbytes,
9077 		(void *)&cmd_flow_director_flexbytes_value,
9078 		(void *)&cmd_flow_director_drop,
9079 		(void *)&cmd_flow_director_pf_vf,
9080 		(void *)&cmd_flow_director_queue,
9081 		(void *)&cmd_flow_director_queue_id,
9082 		(void *)&cmd_flow_director_fd_id,
9083 		(void *)&cmd_flow_director_fd_id_value,
9084 		NULL,
9085 	},
9086 };
9087 
9088 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
9089 	.f = cmd_flow_director_filter_parsed,
9090 	.data = NULL,
9091 	.help_str = "flow_director_filter ... : Add or delete a sctp flow "
9092 		"director entry on NIC",
9093 	.tokens = {
9094 		(void *)&cmd_flow_director_filter,
9095 		(void *)&cmd_flow_director_port_id,
9096 		(void *)&cmd_flow_director_mode,
9097 		(void *)&cmd_flow_director_mode_ip,
9098 		(void *)&cmd_flow_director_ops,
9099 		(void *)&cmd_flow_director_flow,
9100 		(void *)&cmd_flow_director_flow_type,
9101 		(void *)&cmd_flow_director_src,
9102 		(void *)&cmd_flow_director_ip_src,
9103 		(void *)&cmd_flow_director_port_dst,
9104 		(void *)&cmd_flow_director_dst,
9105 		(void *)&cmd_flow_director_ip_dst,
9106 		(void *)&cmd_flow_director_port_dst,
9107 		(void *)&cmd_flow_director_verify_tag,
9108 		(void *)&cmd_flow_director_verify_tag_value,
9109 		(void *)&cmd_flow_director_tos,
9110 		(void *)&cmd_flow_director_tos_value,
9111 		(void *)&cmd_flow_director_ttl,
9112 		(void *)&cmd_flow_director_ttl_value,
9113 		(void *)&cmd_flow_director_vlan,
9114 		(void *)&cmd_flow_director_vlan_value,
9115 		(void *)&cmd_flow_director_flexbytes,
9116 		(void *)&cmd_flow_director_flexbytes_value,
9117 		(void *)&cmd_flow_director_drop,
9118 		(void *)&cmd_flow_director_pf_vf,
9119 		(void *)&cmd_flow_director_queue,
9120 		(void *)&cmd_flow_director_queue_id,
9121 		(void *)&cmd_flow_director_fd_id,
9122 		(void *)&cmd_flow_director_fd_id_value,
9123 		NULL,
9124 	},
9125 };
9126 
9127 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
9128 	.f = cmd_flow_director_filter_parsed,
9129 	.data = NULL,
9130 	.help_str = "flow_director_filter ... : Add or delete a L2 flow "
9131 		"director entry on NIC",
9132 	.tokens = {
9133 		(void *)&cmd_flow_director_filter,
9134 		(void *)&cmd_flow_director_port_id,
9135 		(void *)&cmd_flow_director_mode,
9136 		(void *)&cmd_flow_director_mode_ip,
9137 		(void *)&cmd_flow_director_ops,
9138 		(void *)&cmd_flow_director_flow,
9139 		(void *)&cmd_flow_director_flow_type,
9140 		(void *)&cmd_flow_director_ether,
9141 		(void *)&cmd_flow_director_ether_type,
9142 		(void *)&cmd_flow_director_flexbytes,
9143 		(void *)&cmd_flow_director_flexbytes_value,
9144 		(void *)&cmd_flow_director_drop,
9145 		(void *)&cmd_flow_director_pf_vf,
9146 		(void *)&cmd_flow_director_queue,
9147 		(void *)&cmd_flow_director_queue_id,
9148 		(void *)&cmd_flow_director_fd_id,
9149 		(void *)&cmd_flow_director_fd_id_value,
9150 		NULL,
9151 	},
9152 };
9153 
9154 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
9155 	.f = cmd_flow_director_filter_parsed,
9156 	.data = NULL,
9157 	.help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
9158 		"director entry on NIC",
9159 	.tokens = {
9160 		(void *)&cmd_flow_director_filter,
9161 		(void *)&cmd_flow_director_port_id,
9162 		(void *)&cmd_flow_director_mode,
9163 		(void *)&cmd_flow_director_mode_mac_vlan,
9164 		(void *)&cmd_flow_director_ops,
9165 		(void *)&cmd_flow_director_mac,
9166 		(void *)&cmd_flow_director_mac_addr,
9167 		(void *)&cmd_flow_director_vlan,
9168 		(void *)&cmd_flow_director_vlan_value,
9169 		(void *)&cmd_flow_director_flexbytes,
9170 		(void *)&cmd_flow_director_flexbytes_value,
9171 		(void *)&cmd_flow_director_drop,
9172 		(void *)&cmd_flow_director_queue,
9173 		(void *)&cmd_flow_director_queue_id,
9174 		(void *)&cmd_flow_director_fd_id,
9175 		(void *)&cmd_flow_director_fd_id_value,
9176 		NULL,
9177 	},
9178 };
9179 
9180 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
9181 	.f = cmd_flow_director_filter_parsed,
9182 	.data = NULL,
9183 	.help_str = "flow_director_filter ... : Add or delete a tunnel flow "
9184 		"director entry on NIC",
9185 	.tokens = {
9186 		(void *)&cmd_flow_director_filter,
9187 		(void *)&cmd_flow_director_port_id,
9188 		(void *)&cmd_flow_director_mode,
9189 		(void *)&cmd_flow_director_mode_tunnel,
9190 		(void *)&cmd_flow_director_ops,
9191 		(void *)&cmd_flow_director_mac,
9192 		(void *)&cmd_flow_director_mac_addr,
9193 		(void *)&cmd_flow_director_vlan,
9194 		(void *)&cmd_flow_director_vlan_value,
9195 		(void *)&cmd_flow_director_tunnel,
9196 		(void *)&cmd_flow_director_tunnel_type,
9197 		(void *)&cmd_flow_director_tunnel_id,
9198 		(void *)&cmd_flow_director_tunnel_id_value,
9199 		(void *)&cmd_flow_director_flexbytes,
9200 		(void *)&cmd_flow_director_flexbytes_value,
9201 		(void *)&cmd_flow_director_drop,
9202 		(void *)&cmd_flow_director_queue,
9203 		(void *)&cmd_flow_director_queue_id,
9204 		(void *)&cmd_flow_director_fd_id,
9205 		(void *)&cmd_flow_director_fd_id_value,
9206 		NULL,
9207 	},
9208 };
9209 
9210 struct cmd_flush_flow_director_result {
9211 	cmdline_fixed_string_t flush_flow_director;
9212 	uint8_t port_id;
9213 };
9214 
9215 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
9216 	TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
9217 				 flush_flow_director, "flush_flow_director");
9218 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
9219 	TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
9220 			      port_id, UINT8);
9221 
9222 static void
9223 cmd_flush_flow_director_parsed(void *parsed_result,
9224 			  __attribute__((unused)) struct cmdline *cl,
9225 			  __attribute__((unused)) void *data)
9226 {
9227 	struct cmd_flow_director_result *res = parsed_result;
9228 	int ret = 0;
9229 
9230 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9231 	if (ret < 0) {
9232 		printf("flow director is not supported on port %u.\n",
9233 			res->port_id);
9234 		return;
9235 	}
9236 
9237 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9238 			RTE_ETH_FILTER_FLUSH, NULL);
9239 	if (ret < 0)
9240 		printf("flow director table flushing error: (%s)\n",
9241 			strerror(-ret));
9242 }
9243 
9244 cmdline_parse_inst_t cmd_flush_flow_director = {
9245 	.f = cmd_flush_flow_director_parsed,
9246 	.data = NULL,
9247 	.help_str = "flush_flow_director <port_id>: "
9248 		"Flush all flow director entries of a device on NIC",
9249 	.tokens = {
9250 		(void *)&cmd_flush_flow_director_flush,
9251 		(void *)&cmd_flush_flow_director_port_id,
9252 		NULL,
9253 	},
9254 };
9255 
9256 /* *** deal with flow director mask *** */
9257 struct cmd_flow_director_mask_result {
9258 	cmdline_fixed_string_t flow_director_mask;
9259 	uint8_t port_id;
9260 	cmdline_fixed_string_t mode;
9261 	cmdline_fixed_string_t mode_value;
9262 	cmdline_fixed_string_t vlan;
9263 	uint16_t vlan_mask;
9264 	cmdline_fixed_string_t src_mask;
9265 	cmdline_ipaddr_t ipv4_src;
9266 	cmdline_ipaddr_t ipv6_src;
9267 	uint16_t port_src;
9268 	cmdline_fixed_string_t dst_mask;
9269 	cmdline_ipaddr_t ipv4_dst;
9270 	cmdline_ipaddr_t ipv6_dst;
9271 	uint16_t port_dst;
9272 	cmdline_fixed_string_t mac;
9273 	uint8_t mac_addr_byte_mask;
9274 	cmdline_fixed_string_t tunnel_id;
9275 	uint32_t tunnel_id_mask;
9276 	cmdline_fixed_string_t tunnel_type;
9277 	uint8_t tunnel_type_mask;
9278 };
9279 
9280 static void
9281 cmd_flow_director_mask_parsed(void *parsed_result,
9282 			  __attribute__((unused)) struct cmdline *cl,
9283 			  __attribute__((unused)) void *data)
9284 {
9285 	struct cmd_flow_director_mask_result *res = parsed_result;
9286 	struct rte_eth_fdir_masks *mask;
9287 	struct rte_port *port;
9288 
9289 	if (res->port_id > nb_ports) {
9290 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9291 		return;
9292 	}
9293 
9294 	port = &ports[res->port_id];
9295 	/** Check if the port is not started **/
9296 	if (port->port_status != RTE_PORT_STOPPED) {
9297 		printf("Please stop port %d first\n", res->port_id);
9298 		return;
9299 	}
9300 
9301 	mask = &port->dev_conf.fdir_conf.mask;
9302 
9303 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9304 		if (strcmp(res->mode_value, "MAC-VLAN")) {
9305 			printf("Please set mode to MAC-VLAN.\n");
9306 			return;
9307 		}
9308 
9309 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9310 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9311 		if (strcmp(res->mode_value, "Tunnel")) {
9312 			printf("Please set mode to Tunnel.\n");
9313 			return;
9314 		}
9315 
9316 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9317 		mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9318 		mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
9319 		mask->tunnel_type_mask = res->tunnel_type_mask;
9320 	} else {
9321 		if (strcmp(res->mode_value, "IP")) {
9322 			printf("Please set mode to IP.\n");
9323 			return;
9324 		}
9325 
9326 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9327 		IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
9328 		IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
9329 		IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
9330 		IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
9331 		mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
9332 		mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
9333 	}
9334 
9335 	cmd_reconfig_device_queue(res->port_id, 1, 1);
9336 }
9337 
9338 cmdline_parse_token_string_t cmd_flow_director_mask =
9339 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9340 				 flow_director_mask, "flow_director_mask");
9341 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
9342 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9343 			      port_id, UINT8);
9344 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
9345 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9346 				 vlan, "vlan");
9347 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
9348 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9349 			      vlan_mask, UINT16);
9350 cmdline_parse_token_string_t cmd_flow_director_mask_src =
9351 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9352 				 src_mask, "src_mask");
9353 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
9354 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9355 				 ipv4_src);
9356 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
9357 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9358 				 ipv6_src);
9359 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
9360 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9361 			      port_src, UINT16);
9362 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
9363 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9364 				 dst_mask, "dst_mask");
9365 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
9366 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9367 				 ipv4_dst);
9368 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
9369 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9370 				 ipv6_dst);
9371 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
9372 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9373 			      port_dst, UINT16);
9374 
9375 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
9376 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9377 				 mode, "mode");
9378 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
9379 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9380 				 mode_value, "IP");
9381 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
9382 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9383 				 mode_value, "MAC-VLAN");
9384 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
9385 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9386 				 mode_value, "Tunnel");
9387 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
9388 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9389 				 mac, "mac");
9390 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
9391 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9392 			      mac_addr_byte_mask, UINT8);
9393 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
9394 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9395 				 tunnel_type, "tunnel-type");
9396 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
9397 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9398 			      tunnel_type_mask, UINT8);
9399 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
9400 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9401 				 tunnel_id, "tunnel-id");
9402 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
9403 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9404 			      tunnel_id_mask, UINT32);
9405 
9406 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
9407 	.f = cmd_flow_director_mask_parsed,
9408 	.data = NULL,
9409 	.help_str = "flow_director_mask ... : "
9410 		"Set IP mode flow director's mask on NIC",
9411 	.tokens = {
9412 		(void *)&cmd_flow_director_mask,
9413 		(void *)&cmd_flow_director_mask_port_id,
9414 		(void *)&cmd_flow_director_mask_mode,
9415 		(void *)&cmd_flow_director_mask_mode_ip,
9416 		(void *)&cmd_flow_director_mask_vlan,
9417 		(void *)&cmd_flow_director_mask_vlan_value,
9418 		(void *)&cmd_flow_director_mask_src,
9419 		(void *)&cmd_flow_director_mask_ipv4_src,
9420 		(void *)&cmd_flow_director_mask_ipv6_src,
9421 		(void *)&cmd_flow_director_mask_port_src,
9422 		(void *)&cmd_flow_director_mask_dst,
9423 		(void *)&cmd_flow_director_mask_ipv4_dst,
9424 		(void *)&cmd_flow_director_mask_ipv6_dst,
9425 		(void *)&cmd_flow_director_mask_port_dst,
9426 		NULL,
9427 	},
9428 };
9429 
9430 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
9431 	.f = cmd_flow_director_mask_parsed,
9432 	.data = NULL,
9433 	.help_str = "flow_director_mask ... : Set MAC VLAN mode "
9434 		"flow director's mask on NIC",
9435 	.tokens = {
9436 		(void *)&cmd_flow_director_mask,
9437 		(void *)&cmd_flow_director_mask_port_id,
9438 		(void *)&cmd_flow_director_mask_mode,
9439 		(void *)&cmd_flow_director_mask_mode_mac_vlan,
9440 		(void *)&cmd_flow_director_mask_vlan,
9441 		(void *)&cmd_flow_director_mask_vlan_value,
9442 		NULL,
9443 	},
9444 };
9445 
9446 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
9447 	.f = cmd_flow_director_mask_parsed,
9448 	.data = NULL,
9449 	.help_str = "flow_director_mask ... : Set tunnel mode "
9450 		"flow director's mask on NIC",
9451 	.tokens = {
9452 		(void *)&cmd_flow_director_mask,
9453 		(void *)&cmd_flow_director_mask_port_id,
9454 		(void *)&cmd_flow_director_mask_mode,
9455 		(void *)&cmd_flow_director_mask_mode_tunnel,
9456 		(void *)&cmd_flow_director_mask_vlan,
9457 		(void *)&cmd_flow_director_mask_vlan_value,
9458 		(void *)&cmd_flow_director_mask_mac,
9459 		(void *)&cmd_flow_director_mask_mac_value,
9460 		(void *)&cmd_flow_director_mask_tunnel_type,
9461 		(void *)&cmd_flow_director_mask_tunnel_type_value,
9462 		(void *)&cmd_flow_director_mask_tunnel_id,
9463 		(void *)&cmd_flow_director_mask_tunnel_id_value,
9464 		NULL,
9465 	},
9466 };
9467 
9468 /* *** deal with flow director mask on flexible payload *** */
9469 struct cmd_flow_director_flex_mask_result {
9470 	cmdline_fixed_string_t flow_director_flexmask;
9471 	uint8_t port_id;
9472 	cmdline_fixed_string_t flow;
9473 	cmdline_fixed_string_t flow_type;
9474 	cmdline_fixed_string_t mask;
9475 };
9476 
9477 static void
9478 cmd_flow_director_flex_mask_parsed(void *parsed_result,
9479 			  __attribute__((unused)) struct cmdline *cl,
9480 			  __attribute__((unused)) void *data)
9481 {
9482 	struct cmd_flow_director_flex_mask_result *res = parsed_result;
9483 	struct rte_eth_fdir_info fdir_info;
9484 	struct rte_eth_fdir_flex_mask flex_mask;
9485 	struct rte_port *port;
9486 	uint32_t flow_type_mask;
9487 	uint16_t i;
9488 	int ret;
9489 
9490 	if (res->port_id > nb_ports) {
9491 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9492 		return;
9493 	}
9494 
9495 	port = &ports[res->port_id];
9496 	/** Check if the port is not started **/
9497 	if (port->port_status != RTE_PORT_STOPPED) {
9498 		printf("Please stop port %d first\n", res->port_id);
9499 		return;
9500 	}
9501 
9502 	memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
9503 	ret = parse_flexbytes(res->mask,
9504 			flex_mask.mask,
9505 			RTE_ETH_FDIR_MAX_FLEXLEN);
9506 	if (ret < 0) {
9507 		printf("error: Cannot parse mask input.\n");
9508 		return;
9509 	}
9510 
9511 	memset(&fdir_info, 0, sizeof(fdir_info));
9512 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9513 				RTE_ETH_FILTER_INFO, &fdir_info);
9514 	if (ret < 0) {
9515 		printf("Cannot get FDir filter info\n");
9516 		return;
9517 	}
9518 
9519 	if (!strcmp(res->flow_type, "none")) {
9520 		/* means don't specify the flow type */
9521 		flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
9522 		for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
9523 			memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
9524 			       0, sizeof(struct rte_eth_fdir_flex_mask));
9525 		port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
9526 		(void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
9527 				 &flex_mask,
9528 				 sizeof(struct rte_eth_fdir_flex_mask));
9529 		cmd_reconfig_device_queue(res->port_id, 1, 1);
9530 		return;
9531 	}
9532 	flow_type_mask = fdir_info.flow_types_mask[0];
9533 	if (!strcmp(res->flow_type, "all")) {
9534 		if (!flow_type_mask) {
9535 			printf("No flow type supported\n");
9536 			return;
9537 		}
9538 		for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
9539 			if (flow_type_mask & (1 << i)) {
9540 				flex_mask.flow_type = i;
9541 				fdir_set_flex_mask(res->port_id, &flex_mask);
9542 			}
9543 		}
9544 		cmd_reconfig_device_queue(res->port_id, 1, 1);
9545 		return;
9546 	}
9547 	flex_mask.flow_type = str2flowtype(res->flow_type);
9548 	if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
9549 		printf("Flow type %s not supported on port %d\n",
9550 				res->flow_type, res->port_id);
9551 		return;
9552 	}
9553 	fdir_set_flex_mask(res->port_id, &flex_mask);
9554 	cmd_reconfig_device_queue(res->port_id, 1, 1);
9555 }
9556 
9557 cmdline_parse_token_string_t cmd_flow_director_flexmask =
9558 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9559 				 flow_director_flexmask,
9560 				 "flow_director_flex_mask");
9561 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
9562 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9563 			      port_id, UINT8);
9564 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
9565 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9566 				 flow, "flow");
9567 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
9568 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9569 		flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9570 		"ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
9571 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
9572 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9573 				 mask, NULL);
9574 
9575 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
9576 	.f = cmd_flow_director_flex_mask_parsed,
9577 	.data = NULL,
9578 	.help_str = "flow_director_flex_mask ... : "
9579 		"Set flow director's flex mask on NIC",
9580 	.tokens = {
9581 		(void *)&cmd_flow_director_flexmask,
9582 		(void *)&cmd_flow_director_flexmask_port_id,
9583 		(void *)&cmd_flow_director_flexmask_flow,
9584 		(void *)&cmd_flow_director_flexmask_flow_type,
9585 		(void *)&cmd_flow_director_flexmask_mask,
9586 		NULL,
9587 	},
9588 };
9589 
9590 /* *** deal with flow director flexible payload configuration *** */
9591 struct cmd_flow_director_flexpayload_result {
9592 	cmdline_fixed_string_t flow_director_flexpayload;
9593 	uint8_t port_id;
9594 	cmdline_fixed_string_t payload_layer;
9595 	cmdline_fixed_string_t payload_cfg;
9596 };
9597 
9598 static inline int
9599 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
9600 {
9601 	char s[256];
9602 	const char *p, *p0 = q_arg;
9603 	char *end;
9604 	unsigned long int_fld;
9605 	char *str_fld[max_num];
9606 	int i;
9607 	unsigned size;
9608 	int ret = -1;
9609 
9610 	p = strchr(p0, '(');
9611 	if (p == NULL)
9612 		return -1;
9613 	++p;
9614 	p0 = strchr(p, ')');
9615 	if (p0 == NULL)
9616 		return -1;
9617 
9618 	size = p0 - p;
9619 	if (size >= sizeof(s))
9620 		return -1;
9621 
9622 	snprintf(s, sizeof(s), "%.*s", size, p);
9623 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9624 	if (ret < 0 || ret > max_num)
9625 		return -1;
9626 	for (i = 0; i < ret; i++) {
9627 		errno = 0;
9628 		int_fld = strtoul(str_fld[i], &end, 0);
9629 		if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
9630 			return -1;
9631 		offsets[i] = (uint16_t)int_fld;
9632 	}
9633 	return ret;
9634 }
9635 
9636 static void
9637 cmd_flow_director_flxpld_parsed(void *parsed_result,
9638 			  __attribute__((unused)) struct cmdline *cl,
9639 			  __attribute__((unused)) void *data)
9640 {
9641 	struct cmd_flow_director_flexpayload_result *res = parsed_result;
9642 	struct rte_eth_flex_payload_cfg flex_cfg;
9643 	struct rte_port *port;
9644 	int ret = 0;
9645 
9646 	if (res->port_id > nb_ports) {
9647 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9648 		return;
9649 	}
9650 
9651 	port = &ports[res->port_id];
9652 	/** Check if the port is not started **/
9653 	if (port->port_status != RTE_PORT_STOPPED) {
9654 		printf("Please stop port %d first\n", res->port_id);
9655 		return;
9656 	}
9657 
9658 	memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
9659 
9660 	if (!strcmp(res->payload_layer, "raw"))
9661 		flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
9662 	else if (!strcmp(res->payload_layer, "l2"))
9663 		flex_cfg.type = RTE_ETH_L2_PAYLOAD;
9664 	else if (!strcmp(res->payload_layer, "l3"))
9665 		flex_cfg.type = RTE_ETH_L3_PAYLOAD;
9666 	else if (!strcmp(res->payload_layer, "l4"))
9667 		flex_cfg.type = RTE_ETH_L4_PAYLOAD;
9668 
9669 	ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
9670 			    RTE_ETH_FDIR_MAX_FLEXLEN);
9671 	if (ret < 0) {
9672 		printf("error: Cannot parse flex payload input.\n");
9673 		return;
9674 	}
9675 
9676 	fdir_set_flex_payload(res->port_id, &flex_cfg);
9677 	cmd_reconfig_device_queue(res->port_id, 1, 1);
9678 }
9679 
9680 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
9681 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9682 				 flow_director_flexpayload,
9683 				 "flow_director_flex_payload");
9684 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
9685 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9686 			      port_id, UINT8);
9687 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
9688 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9689 				 payload_layer, "raw#l2#l3#l4");
9690 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
9691 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9692 				 payload_cfg, NULL);
9693 
9694 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
9695 	.f = cmd_flow_director_flxpld_parsed,
9696 	.data = NULL,
9697 	.help_str = "flow_director_flexpayload ... : "
9698 		"Set flow director's flex payload on NIC",
9699 	.tokens = {
9700 		(void *)&cmd_flow_director_flexpayload,
9701 		(void *)&cmd_flow_director_flexpayload_port_id,
9702 		(void *)&cmd_flow_director_flexpayload_payload_layer,
9703 		(void *)&cmd_flow_director_flexpayload_payload_cfg,
9704 		NULL,
9705 	},
9706 };
9707 
9708 /* Generic flow interface command. */
9709 extern cmdline_parse_inst_t cmd_flow;
9710 
9711 /* *** Classification Filters Control *** */
9712 /* *** Get symmetric hash enable per port *** */
9713 struct cmd_get_sym_hash_ena_per_port_result {
9714 	cmdline_fixed_string_t get_sym_hash_ena_per_port;
9715 	uint8_t port_id;
9716 };
9717 
9718 static void
9719 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
9720 				 __rte_unused struct cmdline *cl,
9721 				 __rte_unused void *data)
9722 {
9723 	struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
9724 	struct rte_eth_hash_filter_info info;
9725 	int ret;
9726 
9727 	if (rte_eth_dev_filter_supported(res->port_id,
9728 				RTE_ETH_FILTER_HASH) < 0) {
9729 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9730 							res->port_id);
9731 		return;
9732 	}
9733 
9734 	memset(&info, 0, sizeof(info));
9735 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9736 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9737 						RTE_ETH_FILTER_GET, &info);
9738 
9739 	if (ret < 0) {
9740 		printf("Cannot get symmetric hash enable per port "
9741 					"on port %u\n", res->port_id);
9742 		return;
9743 	}
9744 
9745 	printf("Symmetric hash is %s on port %u\n", info.info.enable ?
9746 				"enabled" : "disabled", res->port_id);
9747 }
9748 
9749 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
9750 	TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9751 		get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
9752 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
9753 	TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9754 		port_id, UINT8);
9755 
9756 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
9757 	.f = cmd_get_sym_hash_per_port_parsed,
9758 	.data = NULL,
9759 	.help_str = "get_sym_hash_ena_per_port <port_id>",
9760 	.tokens = {
9761 		(void *)&cmd_get_sym_hash_ena_per_port_all,
9762 		(void *)&cmd_get_sym_hash_ena_per_port_port_id,
9763 		NULL,
9764 	},
9765 };
9766 
9767 /* *** Set symmetric hash enable per port *** */
9768 struct cmd_set_sym_hash_ena_per_port_result {
9769 	cmdline_fixed_string_t set_sym_hash_ena_per_port;
9770 	cmdline_fixed_string_t enable;
9771 	uint8_t port_id;
9772 };
9773 
9774 static void
9775 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
9776 				 __rte_unused struct cmdline *cl,
9777 				 __rte_unused void *data)
9778 {
9779 	struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
9780 	struct rte_eth_hash_filter_info info;
9781 	int ret;
9782 
9783 	if (rte_eth_dev_filter_supported(res->port_id,
9784 				RTE_ETH_FILTER_HASH) < 0) {
9785 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9786 							res->port_id);
9787 		return;
9788 	}
9789 
9790 	memset(&info, 0, sizeof(info));
9791 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9792 	if (!strcmp(res->enable, "enable"))
9793 		info.info.enable = 1;
9794 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9795 					RTE_ETH_FILTER_SET, &info);
9796 	if (ret < 0) {
9797 		printf("Cannot set symmetric hash enable per port on "
9798 					"port %u\n", res->port_id);
9799 		return;
9800 	}
9801 	printf("Symmetric hash has been set to %s on port %u\n",
9802 					res->enable, res->port_id);
9803 }
9804 
9805 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
9806 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9807 		set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
9808 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
9809 	TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9810 		port_id, UINT8);
9811 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
9812 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9813 		enable, "enable#disable");
9814 
9815 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
9816 	.f = cmd_set_sym_hash_per_port_parsed,
9817 	.data = NULL,
9818 	.help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
9819 	.tokens = {
9820 		(void *)&cmd_set_sym_hash_ena_per_port_all,
9821 		(void *)&cmd_set_sym_hash_ena_per_port_port_id,
9822 		(void *)&cmd_set_sym_hash_ena_per_port_enable,
9823 		NULL,
9824 	},
9825 };
9826 
9827 /* Get global config of hash function */
9828 struct cmd_get_hash_global_config_result {
9829 	cmdline_fixed_string_t get_hash_global_config;
9830 	uint8_t port_id;
9831 };
9832 
9833 static char *
9834 flowtype_to_str(uint16_t ftype)
9835 {
9836 	uint16_t i;
9837 	static struct {
9838 		char str[16];
9839 		uint16_t ftype;
9840 	} ftype_table[] = {
9841 		{"ipv4", RTE_ETH_FLOW_IPV4},
9842 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9843 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9844 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9845 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9846 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9847 		{"ipv6", RTE_ETH_FLOW_IPV6},
9848 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9849 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9850 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9851 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9852 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9853 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9854 		{"port", RTE_ETH_FLOW_PORT},
9855 		{"vxlan", RTE_ETH_FLOW_VXLAN},
9856 		{"geneve", RTE_ETH_FLOW_GENEVE},
9857 		{"nvgre", RTE_ETH_FLOW_NVGRE},
9858 	};
9859 
9860 	for (i = 0; i < RTE_DIM(ftype_table); i++) {
9861 		if (ftype_table[i].ftype == ftype)
9862 			return ftype_table[i].str;
9863 	}
9864 
9865 	return NULL;
9866 }
9867 
9868 static void
9869 cmd_get_hash_global_config_parsed(void *parsed_result,
9870 				  __rte_unused struct cmdline *cl,
9871 				  __rte_unused void *data)
9872 {
9873 	struct cmd_get_hash_global_config_result *res = parsed_result;
9874 	struct rte_eth_hash_filter_info info;
9875 	uint32_t idx, offset;
9876 	uint16_t i;
9877 	char *str;
9878 	int ret;
9879 
9880 	if (rte_eth_dev_filter_supported(res->port_id,
9881 			RTE_ETH_FILTER_HASH) < 0) {
9882 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9883 							res->port_id);
9884 		return;
9885 	}
9886 
9887 	memset(&info, 0, sizeof(info));
9888 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9889 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9890 					RTE_ETH_FILTER_GET, &info);
9891 	if (ret < 0) {
9892 		printf("Cannot get hash global configurations by port %d\n",
9893 							res->port_id);
9894 		return;
9895 	}
9896 
9897 	switch (info.info.global_conf.hash_func) {
9898 	case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
9899 		printf("Hash function is Toeplitz\n");
9900 		break;
9901 	case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
9902 		printf("Hash function is Simple XOR\n");
9903 		break;
9904 	default:
9905 		printf("Unknown hash function\n");
9906 		break;
9907 	}
9908 
9909 	for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
9910 		idx = i / UINT32_BIT;
9911 		offset = i % UINT32_BIT;
9912 		if (!(info.info.global_conf.valid_bit_mask[idx] &
9913 						(1UL << offset)))
9914 			continue;
9915 		str = flowtype_to_str(i);
9916 		if (!str)
9917 			continue;
9918 		printf("Symmetric hash is %s globally for flow type %s "
9919 							"by port %d\n",
9920 			((info.info.global_conf.sym_hash_enable_mask[idx] &
9921 			(1UL << offset)) ? "enabled" : "disabled"), str,
9922 							res->port_id);
9923 	}
9924 }
9925 
9926 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
9927 	TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
9928 		get_hash_global_config, "get_hash_global_config");
9929 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
9930 	TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
9931 		port_id, UINT8);
9932 
9933 cmdline_parse_inst_t cmd_get_hash_global_config = {
9934 	.f = cmd_get_hash_global_config_parsed,
9935 	.data = NULL,
9936 	.help_str = "get_hash_global_config <port_id>",
9937 	.tokens = {
9938 		(void *)&cmd_get_hash_global_config_all,
9939 		(void *)&cmd_get_hash_global_config_port_id,
9940 		NULL,
9941 	},
9942 };
9943 
9944 /* Set global config of hash function */
9945 struct cmd_set_hash_global_config_result {
9946 	cmdline_fixed_string_t set_hash_global_config;
9947 	uint8_t port_id;
9948 	cmdline_fixed_string_t hash_func;
9949 	cmdline_fixed_string_t flow_type;
9950 	cmdline_fixed_string_t enable;
9951 };
9952 
9953 static void
9954 cmd_set_hash_global_config_parsed(void *parsed_result,
9955 				  __rte_unused struct cmdline *cl,
9956 				  __rte_unused void *data)
9957 {
9958 	struct cmd_set_hash_global_config_result *res = parsed_result;
9959 	struct rte_eth_hash_filter_info info;
9960 	uint32_t ftype, idx, offset;
9961 	int ret;
9962 
9963 	if (rte_eth_dev_filter_supported(res->port_id,
9964 				RTE_ETH_FILTER_HASH) < 0) {
9965 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9966 							res->port_id);
9967 		return;
9968 	}
9969 	memset(&info, 0, sizeof(info));
9970 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9971 	if (!strcmp(res->hash_func, "toeplitz"))
9972 		info.info.global_conf.hash_func =
9973 			RTE_ETH_HASH_FUNCTION_TOEPLITZ;
9974 	else if (!strcmp(res->hash_func, "simple_xor"))
9975 		info.info.global_conf.hash_func =
9976 			RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
9977 	else if (!strcmp(res->hash_func, "default"))
9978 		info.info.global_conf.hash_func =
9979 			RTE_ETH_HASH_FUNCTION_DEFAULT;
9980 
9981 	ftype = str2flowtype(res->flow_type);
9982 	idx = ftype / (CHAR_BIT * sizeof(uint32_t));
9983 	offset = ftype % (CHAR_BIT * sizeof(uint32_t));
9984 	info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
9985 	if (!strcmp(res->enable, "enable"))
9986 		info.info.global_conf.sym_hash_enable_mask[idx] |=
9987 						(1UL << offset);
9988 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9989 					RTE_ETH_FILTER_SET, &info);
9990 	if (ret < 0)
9991 		printf("Cannot set global hash configurations by port %d\n",
9992 							res->port_id);
9993 	else
9994 		printf("Global hash configurations have been set "
9995 			"succcessfully by port %d\n", res->port_id);
9996 }
9997 
9998 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
9999 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10000 		set_hash_global_config, "set_hash_global_config");
10001 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
10002 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
10003 		port_id, UINT8);
10004 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
10005 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10006 		hash_func, "toeplitz#simple_xor#default");
10007 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
10008 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10009 		flow_type,
10010 		"ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
10011 		"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10012 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
10013 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10014 		enable, "enable#disable");
10015 
10016 cmdline_parse_inst_t cmd_set_hash_global_config = {
10017 	.f = cmd_set_hash_global_config_parsed,
10018 	.data = NULL,
10019 	.help_str = "set_hash_global_config <port_id> "
10020 		"toeplitz|simple_xor|default "
10021 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10022 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
10023 		"l2_payload enable|disable",
10024 	.tokens = {
10025 		(void *)&cmd_set_hash_global_config_all,
10026 		(void *)&cmd_set_hash_global_config_port_id,
10027 		(void *)&cmd_set_hash_global_config_hash_func,
10028 		(void *)&cmd_set_hash_global_config_flow_type,
10029 		(void *)&cmd_set_hash_global_config_enable,
10030 		NULL,
10031 	},
10032 };
10033 
10034 /* Set hash input set */
10035 struct cmd_set_hash_input_set_result {
10036 	cmdline_fixed_string_t set_hash_input_set;
10037 	uint8_t port_id;
10038 	cmdline_fixed_string_t flow_type;
10039 	cmdline_fixed_string_t inset_field;
10040 	cmdline_fixed_string_t select;
10041 };
10042 
10043 static enum rte_eth_input_set_field
10044 str2inset(char *string)
10045 {
10046 	uint16_t i;
10047 
10048 	static const struct {
10049 		char str[32];
10050 		enum rte_eth_input_set_field inset;
10051 	} inset_table[] = {
10052 		{"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
10053 		{"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
10054 		{"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
10055 		{"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
10056 		{"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
10057 		{"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
10058 		{"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
10059 		{"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
10060 		{"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
10061 		{"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
10062 		{"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
10063 		{"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
10064 		{"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
10065 		{"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
10066 		{"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
10067 		{"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
10068 		{"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
10069 		{"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
10070 		{"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
10071 		{"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
10072 		{"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
10073 		{"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
10074 		{"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
10075 		{"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
10076 		{"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
10077 		{"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
10078 		{"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
10079 		{"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
10080 		{"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
10081 		{"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
10082 		{"none", RTE_ETH_INPUT_SET_NONE},
10083 	};
10084 
10085 	for (i = 0; i < RTE_DIM(inset_table); i++) {
10086 		if (!strcmp(string, inset_table[i].str))
10087 			return inset_table[i].inset;
10088 	}
10089 
10090 	return RTE_ETH_INPUT_SET_UNKNOWN;
10091 }
10092 
10093 static void
10094 cmd_set_hash_input_set_parsed(void *parsed_result,
10095 			      __rte_unused struct cmdline *cl,
10096 			      __rte_unused void *data)
10097 {
10098 	struct cmd_set_hash_input_set_result *res = parsed_result;
10099 	struct rte_eth_hash_filter_info info;
10100 
10101 	memset(&info, 0, sizeof(info));
10102 	info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
10103 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10104 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10105 	info.info.input_set_conf.inset_size = 1;
10106 	if (!strcmp(res->select, "select"))
10107 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10108 	else if (!strcmp(res->select, "add"))
10109 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10110 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10111 				RTE_ETH_FILTER_SET, &info);
10112 }
10113 
10114 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
10115 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10116 		set_hash_input_set, "set_hash_input_set");
10117 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
10118 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
10119 		port_id, UINT8);
10120 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
10121 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10122 		flow_type,
10123 		"ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10124 		"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10125 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
10126 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10127 		inset_field,
10128 		"ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10129 		"ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
10130 		"udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
10131 		"sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
10132 		"fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
10133 		"fld-8th#none");
10134 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
10135 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10136 		select, "select#add");
10137 
10138 cmdline_parse_inst_t cmd_set_hash_input_set = {
10139 	.f = cmd_set_hash_input_set_parsed,
10140 	.data = NULL,
10141 	.help_str = "set_hash_input_set <port_id> "
10142 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10143 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10144 	"ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
10145 	"ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
10146 	"tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
10147 	"gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
10148 	"fld-7th|fld-8th|none select|add",
10149 	.tokens = {
10150 		(void *)&cmd_set_hash_input_set_cmd,
10151 		(void *)&cmd_set_hash_input_set_port_id,
10152 		(void *)&cmd_set_hash_input_set_flow_type,
10153 		(void *)&cmd_set_hash_input_set_field,
10154 		(void *)&cmd_set_hash_input_set_select,
10155 		NULL,
10156 	},
10157 };
10158 
10159 /* Set flow director input set */
10160 struct cmd_set_fdir_input_set_result {
10161 	cmdline_fixed_string_t set_fdir_input_set;
10162 	uint8_t port_id;
10163 	cmdline_fixed_string_t flow_type;
10164 	cmdline_fixed_string_t inset_field;
10165 	cmdline_fixed_string_t select;
10166 };
10167 
10168 static void
10169 cmd_set_fdir_input_set_parsed(void *parsed_result,
10170 	__rte_unused struct cmdline *cl,
10171 	__rte_unused void *data)
10172 {
10173 	struct cmd_set_fdir_input_set_result *res = parsed_result;
10174 	struct rte_eth_fdir_filter_info info;
10175 
10176 	memset(&info, 0, sizeof(info));
10177 	info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
10178 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10179 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10180 	info.info.input_set_conf.inset_size = 1;
10181 	if (!strcmp(res->select, "select"))
10182 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10183 	else if (!strcmp(res->select, "add"))
10184 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10185 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10186 		RTE_ETH_FILTER_SET, &info);
10187 }
10188 
10189 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
10190 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10191 	set_fdir_input_set, "set_fdir_input_set");
10192 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
10193 	TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
10194 	port_id, UINT8);
10195 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
10196 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10197 	flow_type,
10198 	"ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10199 	"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10200 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
10201 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10202 	inset_field,
10203 	"ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10204 	"ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
10205 	"ipv6-hop-limits#udp-src-port#udp-dst-port#"
10206 	"tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
10207 	"sctp-veri-tag#none");
10208 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
10209 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10210 	select, "select#add");
10211 
10212 cmdline_parse_inst_t cmd_set_fdir_input_set = {
10213 	.f = cmd_set_fdir_input_set_parsed,
10214 	.data = NULL,
10215 	.help_str = "set_fdir_input_set <port_id> "
10216 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10217 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10218 	"ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
10219 	"ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
10220 	"ipv6-hop-limits|udp-src-port|udp-dst-port|"
10221 	"tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
10222 	"sctp-veri-tag|none select|add",
10223 	.tokens = {
10224 		(void *)&cmd_set_fdir_input_set_cmd,
10225 		(void *)&cmd_set_fdir_input_set_port_id,
10226 		(void *)&cmd_set_fdir_input_set_flow_type,
10227 		(void *)&cmd_set_fdir_input_set_field,
10228 		(void *)&cmd_set_fdir_input_set_select,
10229 		NULL,
10230 	},
10231 };
10232 
10233 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10234 struct cmd_mcast_addr_result {
10235 	cmdline_fixed_string_t mcast_addr_cmd;
10236 	cmdline_fixed_string_t what;
10237 	uint8_t port_num;
10238 	struct ether_addr mc_addr;
10239 };
10240 
10241 static void cmd_mcast_addr_parsed(void *parsed_result,
10242 		__attribute__((unused)) struct cmdline *cl,
10243 		__attribute__((unused)) void *data)
10244 {
10245 	struct cmd_mcast_addr_result *res = parsed_result;
10246 
10247 	if (!is_multicast_ether_addr(&res->mc_addr)) {
10248 		printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10249 		       res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10250 		       res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10251 		       res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10252 		return;
10253 	}
10254 	if (strcmp(res->what, "add") == 0)
10255 		mcast_addr_add(res->port_num, &res->mc_addr);
10256 	else
10257 		mcast_addr_remove(res->port_num, &res->mc_addr);
10258 }
10259 
10260 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10261 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10262 				 mcast_addr_cmd, "mcast_addr");
10263 cmdline_parse_token_string_t cmd_mcast_addr_what =
10264 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10265 				 "add#remove");
10266 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10267 	TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
10268 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10269 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10270 
10271 cmdline_parse_inst_t cmd_mcast_addr = {
10272 	.f = cmd_mcast_addr_parsed,
10273 	.data = (void *)0,
10274 	.help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10275 		"Add/Remove multicast MAC address on port_id",
10276 	.tokens = {
10277 		(void *)&cmd_mcast_addr_cmd,
10278 		(void *)&cmd_mcast_addr_what,
10279 		(void *)&cmd_mcast_addr_portnum,
10280 		(void *)&cmd_mcast_addr_addr,
10281 		NULL,
10282 	},
10283 };
10284 
10285 /* l2 tunnel config
10286  * only support E-tag now.
10287  */
10288 
10289 /* Ether type config */
10290 struct cmd_config_l2_tunnel_eth_type_result {
10291 	cmdline_fixed_string_t port;
10292 	cmdline_fixed_string_t config;
10293 	cmdline_fixed_string_t all;
10294 	uint8_t id;
10295 	cmdline_fixed_string_t l2_tunnel;
10296 	cmdline_fixed_string_t l2_tunnel_type;
10297 	cmdline_fixed_string_t eth_type;
10298 	uint16_t eth_type_val;
10299 };
10300 
10301 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10302 	TOKEN_STRING_INITIALIZER
10303 		(struct cmd_config_l2_tunnel_eth_type_result,
10304 		 port, "port");
10305 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10306 	TOKEN_STRING_INITIALIZER
10307 		(struct cmd_config_l2_tunnel_eth_type_result,
10308 		 config, "config");
10309 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10310 	TOKEN_STRING_INITIALIZER
10311 		(struct cmd_config_l2_tunnel_eth_type_result,
10312 		 all, "all");
10313 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10314 	TOKEN_NUM_INITIALIZER
10315 		(struct cmd_config_l2_tunnel_eth_type_result,
10316 		 id, UINT8);
10317 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10318 	TOKEN_STRING_INITIALIZER
10319 		(struct cmd_config_l2_tunnel_eth_type_result,
10320 		 l2_tunnel, "l2-tunnel");
10321 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10322 	TOKEN_STRING_INITIALIZER
10323 		(struct cmd_config_l2_tunnel_eth_type_result,
10324 		 l2_tunnel_type, "E-tag");
10325 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10326 	TOKEN_STRING_INITIALIZER
10327 		(struct cmd_config_l2_tunnel_eth_type_result,
10328 		 eth_type, "ether-type");
10329 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10330 	TOKEN_NUM_INITIALIZER
10331 		(struct cmd_config_l2_tunnel_eth_type_result,
10332 		 eth_type_val, UINT16);
10333 
10334 static enum rte_eth_tunnel_type
10335 str2fdir_l2_tunnel_type(char *string)
10336 {
10337 	uint32_t i = 0;
10338 
10339 	static const struct {
10340 		char str[32];
10341 		enum rte_eth_tunnel_type type;
10342 	} l2_tunnel_type_str[] = {
10343 		{"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10344 	};
10345 
10346 	for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10347 		if (!strcmp(l2_tunnel_type_str[i].str, string))
10348 			return l2_tunnel_type_str[i].type;
10349 	}
10350 	return RTE_TUNNEL_TYPE_NONE;
10351 }
10352 
10353 /* ether type config for all ports */
10354 static void
10355 cmd_config_l2_tunnel_eth_type_all_parsed
10356 	(void *parsed_result,
10357 	 __attribute__((unused)) struct cmdline *cl,
10358 	 __attribute__((unused)) void *data)
10359 {
10360 	struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10361 	struct rte_eth_l2_tunnel_conf entry;
10362 	portid_t pid;
10363 
10364 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10365 	entry.ether_type = res->eth_type_val;
10366 
10367 	RTE_ETH_FOREACH_DEV(pid) {
10368 		rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10369 	}
10370 }
10371 
10372 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10373 	.f = cmd_config_l2_tunnel_eth_type_all_parsed,
10374 	.data = NULL,
10375 	.help_str = "port config all l2-tunnel E-tag ether-type <value>",
10376 	.tokens = {
10377 		(void *)&cmd_config_l2_tunnel_eth_type_port,
10378 		(void *)&cmd_config_l2_tunnel_eth_type_config,
10379 		(void *)&cmd_config_l2_tunnel_eth_type_all_str,
10380 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10381 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10382 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10383 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10384 		NULL,
10385 	},
10386 };
10387 
10388 /* ether type config for a specific port */
10389 static void
10390 cmd_config_l2_tunnel_eth_type_specific_parsed(
10391 	void *parsed_result,
10392 	__attribute__((unused)) struct cmdline *cl,
10393 	__attribute__((unused)) void *data)
10394 {
10395 	struct cmd_config_l2_tunnel_eth_type_result *res =
10396 		 parsed_result;
10397 	struct rte_eth_l2_tunnel_conf entry;
10398 
10399 	if (port_id_is_invalid(res->id, ENABLED_WARN))
10400 		return;
10401 
10402 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10403 	entry.ether_type = res->eth_type_val;
10404 
10405 	rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10406 }
10407 
10408 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10409 	.f = cmd_config_l2_tunnel_eth_type_specific_parsed,
10410 	.data = NULL,
10411 	.help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
10412 	.tokens = {
10413 		(void *)&cmd_config_l2_tunnel_eth_type_port,
10414 		(void *)&cmd_config_l2_tunnel_eth_type_config,
10415 		(void *)&cmd_config_l2_tunnel_eth_type_id,
10416 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10417 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10418 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10419 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10420 		NULL,
10421 	},
10422 };
10423 
10424 /* Enable/disable l2 tunnel */
10425 struct cmd_config_l2_tunnel_en_dis_result {
10426 	cmdline_fixed_string_t port;
10427 	cmdline_fixed_string_t config;
10428 	cmdline_fixed_string_t all;
10429 	uint8_t id;
10430 	cmdline_fixed_string_t l2_tunnel;
10431 	cmdline_fixed_string_t l2_tunnel_type;
10432 	cmdline_fixed_string_t en_dis;
10433 };
10434 
10435 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
10436 	TOKEN_STRING_INITIALIZER
10437 		(struct cmd_config_l2_tunnel_en_dis_result,
10438 		 port, "port");
10439 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
10440 	TOKEN_STRING_INITIALIZER
10441 		(struct cmd_config_l2_tunnel_en_dis_result,
10442 		 config, "config");
10443 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
10444 	TOKEN_STRING_INITIALIZER
10445 		(struct cmd_config_l2_tunnel_en_dis_result,
10446 		 all, "all");
10447 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
10448 	TOKEN_NUM_INITIALIZER
10449 		(struct cmd_config_l2_tunnel_en_dis_result,
10450 		 id, UINT8);
10451 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
10452 	TOKEN_STRING_INITIALIZER
10453 		(struct cmd_config_l2_tunnel_en_dis_result,
10454 		 l2_tunnel, "l2-tunnel");
10455 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
10456 	TOKEN_STRING_INITIALIZER
10457 		(struct cmd_config_l2_tunnel_en_dis_result,
10458 		 l2_tunnel_type, "E-tag");
10459 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
10460 	TOKEN_STRING_INITIALIZER
10461 		(struct cmd_config_l2_tunnel_en_dis_result,
10462 		 en_dis, "enable#disable");
10463 
10464 /* enable/disable l2 tunnel for all ports */
10465 static void
10466 cmd_config_l2_tunnel_en_dis_all_parsed(
10467 	void *parsed_result,
10468 	__attribute__((unused)) struct cmdline *cl,
10469 	__attribute__((unused)) void *data)
10470 {
10471 	struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
10472 	struct rte_eth_l2_tunnel_conf entry;
10473 	portid_t pid;
10474 	uint8_t en;
10475 
10476 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10477 
10478 	if (!strcmp("enable", res->en_dis))
10479 		en = 1;
10480 	else
10481 		en = 0;
10482 
10483 	RTE_ETH_FOREACH_DEV(pid) {
10484 		rte_eth_dev_l2_tunnel_offload_set(pid,
10485 						  &entry,
10486 						  ETH_L2_TUNNEL_ENABLE_MASK,
10487 						  en);
10488 	}
10489 }
10490 
10491 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
10492 	.f = cmd_config_l2_tunnel_en_dis_all_parsed,
10493 	.data = NULL,
10494 	.help_str = "port config all l2-tunnel E-tag enable|disable",
10495 	.tokens = {
10496 		(void *)&cmd_config_l2_tunnel_en_dis_port,
10497 		(void *)&cmd_config_l2_tunnel_en_dis_config,
10498 		(void *)&cmd_config_l2_tunnel_en_dis_all_str,
10499 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10500 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10501 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10502 		NULL,
10503 	},
10504 };
10505 
10506 /* enable/disable l2 tunnel for a port */
10507 static void
10508 cmd_config_l2_tunnel_en_dis_specific_parsed(
10509 	void *parsed_result,
10510 	__attribute__((unused)) struct cmdline *cl,
10511 	__attribute__((unused)) void *data)
10512 {
10513 	struct cmd_config_l2_tunnel_en_dis_result *res =
10514 		parsed_result;
10515 	struct rte_eth_l2_tunnel_conf entry;
10516 
10517 	if (port_id_is_invalid(res->id, ENABLED_WARN))
10518 		return;
10519 
10520 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10521 
10522 	if (!strcmp("enable", res->en_dis))
10523 		rte_eth_dev_l2_tunnel_offload_set(res->id,
10524 						  &entry,
10525 						  ETH_L2_TUNNEL_ENABLE_MASK,
10526 						  1);
10527 	else
10528 		rte_eth_dev_l2_tunnel_offload_set(res->id,
10529 						  &entry,
10530 						  ETH_L2_TUNNEL_ENABLE_MASK,
10531 						  0);
10532 }
10533 
10534 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
10535 	.f = cmd_config_l2_tunnel_en_dis_specific_parsed,
10536 	.data = NULL,
10537 	.help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
10538 	.tokens = {
10539 		(void *)&cmd_config_l2_tunnel_en_dis_port,
10540 		(void *)&cmd_config_l2_tunnel_en_dis_config,
10541 		(void *)&cmd_config_l2_tunnel_en_dis_id,
10542 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10543 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10544 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10545 		NULL,
10546 	},
10547 };
10548 
10549 /* E-tag configuration */
10550 
10551 /* Common result structure for all E-tag configuration */
10552 struct cmd_config_e_tag_result {
10553 	cmdline_fixed_string_t e_tag;
10554 	cmdline_fixed_string_t set;
10555 	cmdline_fixed_string_t insertion;
10556 	cmdline_fixed_string_t stripping;
10557 	cmdline_fixed_string_t forwarding;
10558 	cmdline_fixed_string_t filter;
10559 	cmdline_fixed_string_t add;
10560 	cmdline_fixed_string_t del;
10561 	cmdline_fixed_string_t on;
10562 	cmdline_fixed_string_t off;
10563 	cmdline_fixed_string_t on_off;
10564 	cmdline_fixed_string_t port_tag_id;
10565 	uint32_t port_tag_id_val;
10566 	cmdline_fixed_string_t e_tag_id;
10567 	uint16_t e_tag_id_val;
10568 	cmdline_fixed_string_t dst_pool;
10569 	uint8_t dst_pool_val;
10570 	cmdline_fixed_string_t port;
10571 	uint8_t port_id;
10572 	cmdline_fixed_string_t vf;
10573 	uint8_t vf_id;
10574 };
10575 
10576 /* Common CLI fields for all E-tag configuration */
10577 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
10578 	TOKEN_STRING_INITIALIZER
10579 		(struct cmd_config_e_tag_result,
10580 		 e_tag, "E-tag");
10581 cmdline_parse_token_string_t cmd_config_e_tag_set =
10582 	TOKEN_STRING_INITIALIZER
10583 		(struct cmd_config_e_tag_result,
10584 		 set, "set");
10585 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
10586 	TOKEN_STRING_INITIALIZER
10587 		(struct cmd_config_e_tag_result,
10588 		 insertion, "insertion");
10589 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
10590 	TOKEN_STRING_INITIALIZER
10591 		(struct cmd_config_e_tag_result,
10592 		 stripping, "stripping");
10593 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
10594 	TOKEN_STRING_INITIALIZER
10595 		(struct cmd_config_e_tag_result,
10596 		 forwarding, "forwarding");
10597 cmdline_parse_token_string_t cmd_config_e_tag_filter =
10598 	TOKEN_STRING_INITIALIZER
10599 		(struct cmd_config_e_tag_result,
10600 		 filter, "filter");
10601 cmdline_parse_token_string_t cmd_config_e_tag_add =
10602 	TOKEN_STRING_INITIALIZER
10603 		(struct cmd_config_e_tag_result,
10604 		 add, "add");
10605 cmdline_parse_token_string_t cmd_config_e_tag_del =
10606 	TOKEN_STRING_INITIALIZER
10607 		(struct cmd_config_e_tag_result,
10608 		 del, "del");
10609 cmdline_parse_token_string_t cmd_config_e_tag_on =
10610 	TOKEN_STRING_INITIALIZER
10611 		(struct cmd_config_e_tag_result,
10612 		 on, "on");
10613 cmdline_parse_token_string_t cmd_config_e_tag_off =
10614 	TOKEN_STRING_INITIALIZER
10615 		(struct cmd_config_e_tag_result,
10616 		 off, "off");
10617 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
10618 	TOKEN_STRING_INITIALIZER
10619 		(struct cmd_config_e_tag_result,
10620 		 on_off, "on#off");
10621 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
10622 	TOKEN_STRING_INITIALIZER
10623 		(struct cmd_config_e_tag_result,
10624 		 port_tag_id, "port-tag-id");
10625 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
10626 	TOKEN_NUM_INITIALIZER
10627 		(struct cmd_config_e_tag_result,
10628 		 port_tag_id_val, UINT32);
10629 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
10630 	TOKEN_STRING_INITIALIZER
10631 		(struct cmd_config_e_tag_result,
10632 		 e_tag_id, "e-tag-id");
10633 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
10634 	TOKEN_NUM_INITIALIZER
10635 		(struct cmd_config_e_tag_result,
10636 		 e_tag_id_val, UINT16);
10637 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
10638 	TOKEN_STRING_INITIALIZER
10639 		(struct cmd_config_e_tag_result,
10640 		 dst_pool, "dst-pool");
10641 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
10642 	TOKEN_NUM_INITIALIZER
10643 		(struct cmd_config_e_tag_result,
10644 		 dst_pool_val, UINT8);
10645 cmdline_parse_token_string_t cmd_config_e_tag_port =
10646 	TOKEN_STRING_INITIALIZER
10647 		(struct cmd_config_e_tag_result,
10648 		 port, "port");
10649 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
10650 	TOKEN_NUM_INITIALIZER
10651 		(struct cmd_config_e_tag_result,
10652 		 port_id, UINT8);
10653 cmdline_parse_token_string_t cmd_config_e_tag_vf =
10654 	TOKEN_STRING_INITIALIZER
10655 		(struct cmd_config_e_tag_result,
10656 		 vf, "vf");
10657 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
10658 	TOKEN_NUM_INITIALIZER
10659 		(struct cmd_config_e_tag_result,
10660 		 vf_id, UINT8);
10661 
10662 /* E-tag insertion configuration */
10663 static void
10664 cmd_config_e_tag_insertion_en_parsed(
10665 	void *parsed_result,
10666 	__attribute__((unused)) struct cmdline *cl,
10667 	__attribute__((unused)) void *data)
10668 {
10669 	struct cmd_config_e_tag_result *res =
10670 		parsed_result;
10671 	struct rte_eth_l2_tunnel_conf entry;
10672 
10673 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10674 		return;
10675 
10676 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10677 	entry.tunnel_id = res->port_tag_id_val;
10678 	entry.vf_id = res->vf_id;
10679 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10680 					  &entry,
10681 					  ETH_L2_TUNNEL_INSERTION_MASK,
10682 					  1);
10683 }
10684 
10685 static void
10686 cmd_config_e_tag_insertion_dis_parsed(
10687 	void *parsed_result,
10688 	__attribute__((unused)) struct cmdline *cl,
10689 	__attribute__((unused)) void *data)
10690 {
10691 	struct cmd_config_e_tag_result *res =
10692 		parsed_result;
10693 	struct rte_eth_l2_tunnel_conf entry;
10694 
10695 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10696 		return;
10697 
10698 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10699 	entry.vf_id = res->vf_id;
10700 
10701 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10702 					  &entry,
10703 					  ETH_L2_TUNNEL_INSERTION_MASK,
10704 					  0);
10705 }
10706 
10707 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
10708 	.f = cmd_config_e_tag_insertion_en_parsed,
10709 	.data = NULL,
10710 	.help_str = "E-tag ... : E-tag insertion enable",
10711 	.tokens = {
10712 		(void *)&cmd_config_e_tag_e_tag,
10713 		(void *)&cmd_config_e_tag_set,
10714 		(void *)&cmd_config_e_tag_insertion,
10715 		(void *)&cmd_config_e_tag_on,
10716 		(void *)&cmd_config_e_tag_port_tag_id,
10717 		(void *)&cmd_config_e_tag_port_tag_id_val,
10718 		(void *)&cmd_config_e_tag_port,
10719 		(void *)&cmd_config_e_tag_port_id,
10720 		(void *)&cmd_config_e_tag_vf,
10721 		(void *)&cmd_config_e_tag_vf_id,
10722 		NULL,
10723 	},
10724 };
10725 
10726 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
10727 	.f = cmd_config_e_tag_insertion_dis_parsed,
10728 	.data = NULL,
10729 	.help_str = "E-tag ... : E-tag insertion disable",
10730 	.tokens = {
10731 		(void *)&cmd_config_e_tag_e_tag,
10732 		(void *)&cmd_config_e_tag_set,
10733 		(void *)&cmd_config_e_tag_insertion,
10734 		(void *)&cmd_config_e_tag_off,
10735 		(void *)&cmd_config_e_tag_port,
10736 		(void *)&cmd_config_e_tag_port_id,
10737 		(void *)&cmd_config_e_tag_vf,
10738 		(void *)&cmd_config_e_tag_vf_id,
10739 		NULL,
10740 	},
10741 };
10742 
10743 /* E-tag stripping configuration */
10744 static void
10745 cmd_config_e_tag_stripping_parsed(
10746 	void *parsed_result,
10747 	__attribute__((unused)) struct cmdline *cl,
10748 	__attribute__((unused)) void *data)
10749 {
10750 	struct cmd_config_e_tag_result *res =
10751 		parsed_result;
10752 	struct rte_eth_l2_tunnel_conf entry;
10753 
10754 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10755 		return;
10756 
10757 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10758 
10759 	if (!strcmp(res->on_off, "on"))
10760 		rte_eth_dev_l2_tunnel_offload_set
10761 			(res->port_id,
10762 			 &entry,
10763 			 ETH_L2_TUNNEL_STRIPPING_MASK,
10764 			 1);
10765 	else
10766 		rte_eth_dev_l2_tunnel_offload_set
10767 			(res->port_id,
10768 			 &entry,
10769 			 ETH_L2_TUNNEL_STRIPPING_MASK,
10770 			 0);
10771 }
10772 
10773 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
10774 	.f = cmd_config_e_tag_stripping_parsed,
10775 	.data = NULL,
10776 	.help_str = "E-tag ... : E-tag stripping enable/disable",
10777 	.tokens = {
10778 		(void *)&cmd_config_e_tag_e_tag,
10779 		(void *)&cmd_config_e_tag_set,
10780 		(void *)&cmd_config_e_tag_stripping,
10781 		(void *)&cmd_config_e_tag_on_off,
10782 		(void *)&cmd_config_e_tag_port,
10783 		(void *)&cmd_config_e_tag_port_id,
10784 		NULL,
10785 	},
10786 };
10787 
10788 /* E-tag forwarding configuration */
10789 static void
10790 cmd_config_e_tag_forwarding_parsed(
10791 	void *parsed_result,
10792 	__attribute__((unused)) struct cmdline *cl,
10793 	__attribute__((unused)) void *data)
10794 {
10795 	struct cmd_config_e_tag_result *res = parsed_result;
10796 	struct rte_eth_l2_tunnel_conf entry;
10797 
10798 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10799 		return;
10800 
10801 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10802 
10803 	if (!strcmp(res->on_off, "on"))
10804 		rte_eth_dev_l2_tunnel_offload_set
10805 			(res->port_id,
10806 			 &entry,
10807 			 ETH_L2_TUNNEL_FORWARDING_MASK,
10808 			 1);
10809 	else
10810 		rte_eth_dev_l2_tunnel_offload_set
10811 			(res->port_id,
10812 			 &entry,
10813 			 ETH_L2_TUNNEL_FORWARDING_MASK,
10814 			 0);
10815 }
10816 
10817 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
10818 	.f = cmd_config_e_tag_forwarding_parsed,
10819 	.data = NULL,
10820 	.help_str = "E-tag ... : E-tag forwarding enable/disable",
10821 	.tokens = {
10822 		(void *)&cmd_config_e_tag_e_tag,
10823 		(void *)&cmd_config_e_tag_set,
10824 		(void *)&cmd_config_e_tag_forwarding,
10825 		(void *)&cmd_config_e_tag_on_off,
10826 		(void *)&cmd_config_e_tag_port,
10827 		(void *)&cmd_config_e_tag_port_id,
10828 		NULL,
10829 	},
10830 };
10831 
10832 /* E-tag filter configuration */
10833 static void
10834 cmd_config_e_tag_filter_add_parsed(
10835 	void *parsed_result,
10836 	__attribute__((unused)) struct cmdline *cl,
10837 	__attribute__((unused)) void *data)
10838 {
10839 	struct cmd_config_e_tag_result *res = parsed_result;
10840 	struct rte_eth_l2_tunnel_conf entry;
10841 	int ret = 0;
10842 
10843 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10844 		return;
10845 
10846 	if (res->e_tag_id_val > 0x3fff) {
10847 		printf("e-tag-id must be equal or less than 0x3fff.\n");
10848 		return;
10849 	}
10850 
10851 	ret = rte_eth_dev_filter_supported(res->port_id,
10852 					   RTE_ETH_FILTER_L2_TUNNEL);
10853 	if (ret < 0) {
10854 		printf("E-tag filter is not supported on port %u.\n",
10855 		       res->port_id);
10856 		return;
10857 	}
10858 
10859 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10860 	entry.tunnel_id = res->e_tag_id_val;
10861 	entry.pool = res->dst_pool_val;
10862 
10863 	ret = rte_eth_dev_filter_ctrl(res->port_id,
10864 				      RTE_ETH_FILTER_L2_TUNNEL,
10865 				      RTE_ETH_FILTER_ADD,
10866 				      &entry);
10867 	if (ret < 0)
10868 		printf("E-tag filter programming error: (%s)\n",
10869 		       strerror(-ret));
10870 }
10871 
10872 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
10873 	.f = cmd_config_e_tag_filter_add_parsed,
10874 	.data = NULL,
10875 	.help_str = "E-tag ... : E-tag filter add",
10876 	.tokens = {
10877 		(void *)&cmd_config_e_tag_e_tag,
10878 		(void *)&cmd_config_e_tag_set,
10879 		(void *)&cmd_config_e_tag_filter,
10880 		(void *)&cmd_config_e_tag_add,
10881 		(void *)&cmd_config_e_tag_e_tag_id,
10882 		(void *)&cmd_config_e_tag_e_tag_id_val,
10883 		(void *)&cmd_config_e_tag_dst_pool,
10884 		(void *)&cmd_config_e_tag_dst_pool_val,
10885 		(void *)&cmd_config_e_tag_port,
10886 		(void *)&cmd_config_e_tag_port_id,
10887 		NULL,
10888 	},
10889 };
10890 
10891 static void
10892 cmd_config_e_tag_filter_del_parsed(
10893 	void *parsed_result,
10894 	__attribute__((unused)) struct cmdline *cl,
10895 	__attribute__((unused)) void *data)
10896 {
10897 	struct cmd_config_e_tag_result *res = parsed_result;
10898 	struct rte_eth_l2_tunnel_conf entry;
10899 	int ret = 0;
10900 
10901 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10902 		return;
10903 
10904 	if (res->e_tag_id_val > 0x3fff) {
10905 		printf("e-tag-id must be less than 0x3fff.\n");
10906 		return;
10907 	}
10908 
10909 	ret = rte_eth_dev_filter_supported(res->port_id,
10910 					   RTE_ETH_FILTER_L2_TUNNEL);
10911 	if (ret < 0) {
10912 		printf("E-tag filter is not supported on port %u.\n",
10913 		       res->port_id);
10914 		return;
10915 	}
10916 
10917 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10918 	entry.tunnel_id = res->e_tag_id_val;
10919 
10920 	ret = rte_eth_dev_filter_ctrl(res->port_id,
10921 				      RTE_ETH_FILTER_L2_TUNNEL,
10922 				      RTE_ETH_FILTER_DELETE,
10923 				      &entry);
10924 	if (ret < 0)
10925 		printf("E-tag filter programming error: (%s)\n",
10926 		       strerror(-ret));
10927 }
10928 
10929 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
10930 	.f = cmd_config_e_tag_filter_del_parsed,
10931 	.data = NULL,
10932 	.help_str = "E-tag ... : E-tag filter delete",
10933 	.tokens = {
10934 		(void *)&cmd_config_e_tag_e_tag,
10935 		(void *)&cmd_config_e_tag_set,
10936 		(void *)&cmd_config_e_tag_filter,
10937 		(void *)&cmd_config_e_tag_del,
10938 		(void *)&cmd_config_e_tag_e_tag_id,
10939 		(void *)&cmd_config_e_tag_e_tag_id_val,
10940 		(void *)&cmd_config_e_tag_port,
10941 		(void *)&cmd_config_e_tag_port_id,
10942 		NULL,
10943 	},
10944 };
10945 
10946 /* vf vlan anti spoof configuration */
10947 
10948 /* Common result structure for vf vlan anti spoof */
10949 struct cmd_vf_vlan_anti_spoof_result {
10950 	cmdline_fixed_string_t set;
10951 	cmdline_fixed_string_t vf;
10952 	cmdline_fixed_string_t vlan;
10953 	cmdline_fixed_string_t antispoof;
10954 	uint8_t port_id;
10955 	uint32_t vf_id;
10956 	cmdline_fixed_string_t on_off;
10957 };
10958 
10959 /* Common CLI fields for vf vlan anti spoof enable disable */
10960 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10961 	TOKEN_STRING_INITIALIZER
10962 		(struct cmd_vf_vlan_anti_spoof_result,
10963 		 set, "set");
10964 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10965 	TOKEN_STRING_INITIALIZER
10966 		(struct cmd_vf_vlan_anti_spoof_result,
10967 		 vf, "vf");
10968 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10969 	TOKEN_STRING_INITIALIZER
10970 		(struct cmd_vf_vlan_anti_spoof_result,
10971 		 vlan, "vlan");
10972 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10973 	TOKEN_STRING_INITIALIZER
10974 		(struct cmd_vf_vlan_anti_spoof_result,
10975 		 antispoof, "antispoof");
10976 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10977 	TOKEN_NUM_INITIALIZER
10978 		(struct cmd_vf_vlan_anti_spoof_result,
10979 		 port_id, UINT8);
10980 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10981 	TOKEN_NUM_INITIALIZER
10982 		(struct cmd_vf_vlan_anti_spoof_result,
10983 		 vf_id, UINT32);
10984 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10985 	TOKEN_STRING_INITIALIZER
10986 		(struct cmd_vf_vlan_anti_spoof_result,
10987 		 on_off, "on#off");
10988 
10989 static void
10990 cmd_set_vf_vlan_anti_spoof_parsed(
10991 	void *parsed_result,
10992 	__attribute__((unused)) struct cmdline *cl,
10993 	__attribute__((unused)) void *data)
10994 {
10995 	struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10996 	int ret = -ENOTSUP;
10997 
10998 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10999 
11000 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11001 		return;
11002 
11003 #ifdef RTE_LIBRTE_IXGBE_PMD
11004 	if (ret == -ENOTSUP)
11005 		ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11006 				res->vf_id, is_on);
11007 #endif
11008 #ifdef RTE_LIBRTE_I40E_PMD
11009 	if (ret == -ENOTSUP)
11010 		ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11011 				res->vf_id, is_on);
11012 #endif
11013 
11014 	switch (ret) {
11015 	case 0:
11016 		break;
11017 	case -EINVAL:
11018 		printf("invalid vf_id %d\n", res->vf_id);
11019 		break;
11020 	case -ENODEV:
11021 		printf("invalid port_id %d\n", res->port_id);
11022 		break;
11023 	case -ENOTSUP:
11024 		printf("function not implemented\n");
11025 		break;
11026 	default:
11027 		printf("programming error: (%s)\n", strerror(-ret));
11028 	}
11029 }
11030 
11031 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11032 	.f = cmd_set_vf_vlan_anti_spoof_parsed,
11033 	.data = NULL,
11034 	.help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11035 	.tokens = {
11036 		(void *)&cmd_vf_vlan_anti_spoof_set,
11037 		(void *)&cmd_vf_vlan_anti_spoof_vf,
11038 		(void *)&cmd_vf_vlan_anti_spoof_vlan,
11039 		(void *)&cmd_vf_vlan_anti_spoof_antispoof,
11040 		(void *)&cmd_vf_vlan_anti_spoof_port_id,
11041 		(void *)&cmd_vf_vlan_anti_spoof_vf_id,
11042 		(void *)&cmd_vf_vlan_anti_spoof_on_off,
11043 		NULL,
11044 	},
11045 };
11046 
11047 /* vf mac anti spoof configuration */
11048 
11049 /* Common result structure for vf mac anti spoof */
11050 struct cmd_vf_mac_anti_spoof_result {
11051 	cmdline_fixed_string_t set;
11052 	cmdline_fixed_string_t vf;
11053 	cmdline_fixed_string_t mac;
11054 	cmdline_fixed_string_t antispoof;
11055 	uint8_t port_id;
11056 	uint32_t vf_id;
11057 	cmdline_fixed_string_t on_off;
11058 };
11059 
11060 /* Common CLI fields for vf mac anti spoof enable disable */
11061 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11062 	TOKEN_STRING_INITIALIZER
11063 		(struct cmd_vf_mac_anti_spoof_result,
11064 		 set, "set");
11065 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11066 	TOKEN_STRING_INITIALIZER
11067 		(struct cmd_vf_mac_anti_spoof_result,
11068 		 vf, "vf");
11069 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11070 	TOKEN_STRING_INITIALIZER
11071 		(struct cmd_vf_mac_anti_spoof_result,
11072 		 mac, "mac");
11073 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11074 	TOKEN_STRING_INITIALIZER
11075 		(struct cmd_vf_mac_anti_spoof_result,
11076 		 antispoof, "antispoof");
11077 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11078 	TOKEN_NUM_INITIALIZER
11079 		(struct cmd_vf_mac_anti_spoof_result,
11080 		 port_id, UINT8);
11081 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11082 	TOKEN_NUM_INITIALIZER
11083 		(struct cmd_vf_mac_anti_spoof_result,
11084 		 vf_id, UINT32);
11085 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11086 	TOKEN_STRING_INITIALIZER
11087 		(struct cmd_vf_mac_anti_spoof_result,
11088 		 on_off, "on#off");
11089 
11090 static void
11091 cmd_set_vf_mac_anti_spoof_parsed(
11092 	void *parsed_result,
11093 	__attribute__((unused)) struct cmdline *cl,
11094 	__attribute__((unused)) void *data)
11095 {
11096 	struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11097 	int ret = -ENOTSUP;
11098 
11099 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11100 
11101 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11102 		return;
11103 
11104 #ifdef RTE_LIBRTE_IXGBE_PMD
11105 	if (ret == -ENOTSUP)
11106 		ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11107 			res->vf_id, is_on);
11108 #endif
11109 #ifdef RTE_LIBRTE_I40E_PMD
11110 	if (ret == -ENOTSUP)
11111 		ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11112 			res->vf_id, is_on);
11113 #endif
11114 
11115 	switch (ret) {
11116 	case 0:
11117 		break;
11118 	case -EINVAL:
11119 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11120 		break;
11121 	case -ENODEV:
11122 		printf("invalid port_id %d\n", res->port_id);
11123 		break;
11124 	case -ENOTSUP:
11125 		printf("function not implemented\n");
11126 		break;
11127 	default:
11128 		printf("programming error: (%s)\n", strerror(-ret));
11129 	}
11130 }
11131 
11132 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11133 	.f = cmd_set_vf_mac_anti_spoof_parsed,
11134 	.data = NULL,
11135 	.help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11136 	.tokens = {
11137 		(void *)&cmd_vf_mac_anti_spoof_set,
11138 		(void *)&cmd_vf_mac_anti_spoof_vf,
11139 		(void *)&cmd_vf_mac_anti_spoof_mac,
11140 		(void *)&cmd_vf_mac_anti_spoof_antispoof,
11141 		(void *)&cmd_vf_mac_anti_spoof_port_id,
11142 		(void *)&cmd_vf_mac_anti_spoof_vf_id,
11143 		(void *)&cmd_vf_mac_anti_spoof_on_off,
11144 		NULL,
11145 	},
11146 };
11147 
11148 /* vf vlan strip queue configuration */
11149 
11150 /* Common result structure for vf mac anti spoof */
11151 struct cmd_vf_vlan_stripq_result {
11152 	cmdline_fixed_string_t set;
11153 	cmdline_fixed_string_t vf;
11154 	cmdline_fixed_string_t vlan;
11155 	cmdline_fixed_string_t stripq;
11156 	uint8_t port_id;
11157 	uint16_t vf_id;
11158 	cmdline_fixed_string_t on_off;
11159 };
11160 
11161 /* Common CLI fields for vf vlan strip enable disable */
11162 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11163 	TOKEN_STRING_INITIALIZER
11164 		(struct cmd_vf_vlan_stripq_result,
11165 		 set, "set");
11166 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11167 	TOKEN_STRING_INITIALIZER
11168 		(struct cmd_vf_vlan_stripq_result,
11169 		 vf, "vf");
11170 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11171 	TOKEN_STRING_INITIALIZER
11172 		(struct cmd_vf_vlan_stripq_result,
11173 		 vlan, "vlan");
11174 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11175 	TOKEN_STRING_INITIALIZER
11176 		(struct cmd_vf_vlan_stripq_result,
11177 		 stripq, "stripq");
11178 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11179 	TOKEN_NUM_INITIALIZER
11180 		(struct cmd_vf_vlan_stripq_result,
11181 		 port_id, UINT8);
11182 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11183 	TOKEN_NUM_INITIALIZER
11184 		(struct cmd_vf_vlan_stripq_result,
11185 		 vf_id, UINT16);
11186 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11187 	TOKEN_STRING_INITIALIZER
11188 		(struct cmd_vf_vlan_stripq_result,
11189 		 on_off, "on#off");
11190 
11191 static void
11192 cmd_set_vf_vlan_stripq_parsed(
11193 	void *parsed_result,
11194 	__attribute__((unused)) struct cmdline *cl,
11195 	__attribute__((unused)) void *data)
11196 {
11197 	struct cmd_vf_vlan_stripq_result *res = parsed_result;
11198 	int ret = -ENOTSUP;
11199 
11200 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11201 
11202 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11203 		return;
11204 
11205 #ifdef RTE_LIBRTE_IXGBE_PMD
11206 	if (ret == -ENOTSUP)
11207 		ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11208 			res->vf_id, is_on);
11209 #endif
11210 #ifdef RTE_LIBRTE_I40E_PMD
11211 	if (ret == -ENOTSUP)
11212 		ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11213 			res->vf_id, is_on);
11214 #endif
11215 
11216 	switch (ret) {
11217 	case 0:
11218 		break;
11219 	case -EINVAL:
11220 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11221 		break;
11222 	case -ENODEV:
11223 		printf("invalid port_id %d\n", res->port_id);
11224 		break;
11225 	case -ENOTSUP:
11226 		printf("function not implemented\n");
11227 		break;
11228 	default:
11229 		printf("programming error: (%s)\n", strerror(-ret));
11230 	}
11231 }
11232 
11233 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11234 	.f = cmd_set_vf_vlan_stripq_parsed,
11235 	.data = NULL,
11236 	.help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11237 	.tokens = {
11238 		(void *)&cmd_vf_vlan_stripq_set,
11239 		(void *)&cmd_vf_vlan_stripq_vf,
11240 		(void *)&cmd_vf_vlan_stripq_vlan,
11241 		(void *)&cmd_vf_vlan_stripq_stripq,
11242 		(void *)&cmd_vf_vlan_stripq_port_id,
11243 		(void *)&cmd_vf_vlan_stripq_vf_id,
11244 		(void *)&cmd_vf_vlan_stripq_on_off,
11245 		NULL,
11246 	},
11247 };
11248 
11249 /* vf vlan insert configuration */
11250 
11251 /* Common result structure for vf vlan insert */
11252 struct cmd_vf_vlan_insert_result {
11253 	cmdline_fixed_string_t set;
11254 	cmdline_fixed_string_t vf;
11255 	cmdline_fixed_string_t vlan;
11256 	cmdline_fixed_string_t insert;
11257 	uint8_t port_id;
11258 	uint16_t vf_id;
11259 	uint16_t vlan_id;
11260 };
11261 
11262 /* Common CLI fields for vf vlan insert enable disable */
11263 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11264 	TOKEN_STRING_INITIALIZER
11265 		(struct cmd_vf_vlan_insert_result,
11266 		 set, "set");
11267 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11268 	TOKEN_STRING_INITIALIZER
11269 		(struct cmd_vf_vlan_insert_result,
11270 		 vf, "vf");
11271 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11272 	TOKEN_STRING_INITIALIZER
11273 		(struct cmd_vf_vlan_insert_result,
11274 		 vlan, "vlan");
11275 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11276 	TOKEN_STRING_INITIALIZER
11277 		(struct cmd_vf_vlan_insert_result,
11278 		 insert, "insert");
11279 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11280 	TOKEN_NUM_INITIALIZER
11281 		(struct cmd_vf_vlan_insert_result,
11282 		 port_id, UINT8);
11283 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11284 	TOKEN_NUM_INITIALIZER
11285 		(struct cmd_vf_vlan_insert_result,
11286 		 vf_id, UINT16);
11287 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11288 	TOKEN_NUM_INITIALIZER
11289 		(struct cmd_vf_vlan_insert_result,
11290 		 vlan_id, UINT16);
11291 
11292 static void
11293 cmd_set_vf_vlan_insert_parsed(
11294 	void *parsed_result,
11295 	__attribute__((unused)) struct cmdline *cl,
11296 	__attribute__((unused)) void *data)
11297 {
11298 	struct cmd_vf_vlan_insert_result *res = parsed_result;
11299 	int ret = -ENOTSUP;
11300 
11301 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11302 		return;
11303 
11304 #ifdef RTE_LIBRTE_IXGBE_PMD
11305 	if (ret == -ENOTSUP)
11306 		ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11307 			res->vlan_id);
11308 #endif
11309 #ifdef RTE_LIBRTE_I40E_PMD
11310 	if (ret == -ENOTSUP)
11311 		ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11312 			res->vlan_id);
11313 #endif
11314 
11315 	switch (ret) {
11316 	case 0:
11317 		break;
11318 	case -EINVAL:
11319 		printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11320 		break;
11321 	case -ENODEV:
11322 		printf("invalid port_id %d\n", res->port_id);
11323 		break;
11324 	case -ENOTSUP:
11325 		printf("function not implemented\n");
11326 		break;
11327 	default:
11328 		printf("programming error: (%s)\n", strerror(-ret));
11329 	}
11330 }
11331 
11332 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11333 	.f = cmd_set_vf_vlan_insert_parsed,
11334 	.data = NULL,
11335 	.help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11336 	.tokens = {
11337 		(void *)&cmd_vf_vlan_insert_set,
11338 		(void *)&cmd_vf_vlan_insert_vf,
11339 		(void *)&cmd_vf_vlan_insert_vlan,
11340 		(void *)&cmd_vf_vlan_insert_insert,
11341 		(void *)&cmd_vf_vlan_insert_port_id,
11342 		(void *)&cmd_vf_vlan_insert_vf_id,
11343 		(void *)&cmd_vf_vlan_insert_vlan_id,
11344 		NULL,
11345 	},
11346 };
11347 
11348 /* tx loopback configuration */
11349 
11350 /* Common result structure for tx loopback */
11351 struct cmd_tx_loopback_result {
11352 	cmdline_fixed_string_t set;
11353 	cmdline_fixed_string_t tx;
11354 	cmdline_fixed_string_t loopback;
11355 	uint8_t port_id;
11356 	cmdline_fixed_string_t on_off;
11357 };
11358 
11359 /* Common CLI fields for tx loopback enable disable */
11360 cmdline_parse_token_string_t cmd_tx_loopback_set =
11361 	TOKEN_STRING_INITIALIZER
11362 		(struct cmd_tx_loopback_result,
11363 		 set, "set");
11364 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11365 	TOKEN_STRING_INITIALIZER
11366 		(struct cmd_tx_loopback_result,
11367 		 tx, "tx");
11368 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11369 	TOKEN_STRING_INITIALIZER
11370 		(struct cmd_tx_loopback_result,
11371 		 loopback, "loopback");
11372 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11373 	TOKEN_NUM_INITIALIZER
11374 		(struct cmd_tx_loopback_result,
11375 		 port_id, UINT8);
11376 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11377 	TOKEN_STRING_INITIALIZER
11378 		(struct cmd_tx_loopback_result,
11379 		 on_off, "on#off");
11380 
11381 static void
11382 cmd_set_tx_loopback_parsed(
11383 	void *parsed_result,
11384 	__attribute__((unused)) struct cmdline *cl,
11385 	__attribute__((unused)) void *data)
11386 {
11387 	struct cmd_tx_loopback_result *res = parsed_result;
11388 	int ret = -ENOTSUP;
11389 
11390 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11391 
11392 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11393 		return;
11394 
11395 #ifdef RTE_LIBRTE_IXGBE_PMD
11396 	if (ret == -ENOTSUP)
11397 		ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11398 #endif
11399 #ifdef RTE_LIBRTE_I40E_PMD
11400 	if (ret == -ENOTSUP)
11401 		ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11402 #endif
11403 
11404 	switch (ret) {
11405 	case 0:
11406 		break;
11407 	case -EINVAL:
11408 		printf("invalid is_on %d\n", is_on);
11409 		break;
11410 	case -ENODEV:
11411 		printf("invalid port_id %d\n", res->port_id);
11412 		break;
11413 	case -ENOTSUP:
11414 		printf("function not implemented\n");
11415 		break;
11416 	default:
11417 		printf("programming error: (%s)\n", strerror(-ret));
11418 	}
11419 }
11420 
11421 cmdline_parse_inst_t cmd_set_tx_loopback = {
11422 	.f = cmd_set_tx_loopback_parsed,
11423 	.data = NULL,
11424 	.help_str = "set tx loopback <port_id> on|off",
11425 	.tokens = {
11426 		(void *)&cmd_tx_loopback_set,
11427 		(void *)&cmd_tx_loopback_tx,
11428 		(void *)&cmd_tx_loopback_loopback,
11429 		(void *)&cmd_tx_loopback_port_id,
11430 		(void *)&cmd_tx_loopback_on_off,
11431 		NULL,
11432 	},
11433 };
11434 
11435 #ifdef RTE_LIBRTE_IXGBE_PMD
11436 /* all queues drop enable configuration */
11437 
11438 /* Common result structure for all queues drop enable */
11439 struct cmd_all_queues_drop_en_result {
11440 	cmdline_fixed_string_t set;
11441 	cmdline_fixed_string_t all;
11442 	cmdline_fixed_string_t queues;
11443 	cmdline_fixed_string_t drop;
11444 	uint8_t port_id;
11445 	cmdline_fixed_string_t on_off;
11446 };
11447 
11448 /* Common CLI fields for tx loopback enable disable */
11449 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11450 	TOKEN_STRING_INITIALIZER
11451 		(struct cmd_all_queues_drop_en_result,
11452 		 set, "set");
11453 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11454 	TOKEN_STRING_INITIALIZER
11455 		(struct cmd_all_queues_drop_en_result,
11456 		 all, "all");
11457 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11458 	TOKEN_STRING_INITIALIZER
11459 		(struct cmd_all_queues_drop_en_result,
11460 		 queues, "queues");
11461 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11462 	TOKEN_STRING_INITIALIZER
11463 		(struct cmd_all_queues_drop_en_result,
11464 		 drop, "drop");
11465 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11466 	TOKEN_NUM_INITIALIZER
11467 		(struct cmd_all_queues_drop_en_result,
11468 		 port_id, UINT8);
11469 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11470 	TOKEN_STRING_INITIALIZER
11471 		(struct cmd_all_queues_drop_en_result,
11472 		 on_off, "on#off");
11473 
11474 static void
11475 cmd_set_all_queues_drop_en_parsed(
11476 	void *parsed_result,
11477 	__attribute__((unused)) struct cmdline *cl,
11478 	__attribute__((unused)) void *data)
11479 {
11480 	struct cmd_all_queues_drop_en_result *res = parsed_result;
11481 	int ret = 0;
11482 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11483 
11484 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11485 		return;
11486 
11487 	ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11488 	switch (ret) {
11489 	case 0:
11490 		break;
11491 	case -EINVAL:
11492 		printf("invalid is_on %d\n", is_on);
11493 		break;
11494 	case -ENODEV:
11495 		printf("invalid port_id %d\n", res->port_id);
11496 		break;
11497 	case -ENOTSUP:
11498 		printf("function not implemented\n");
11499 		break;
11500 	default:
11501 		printf("programming error: (%s)\n", strerror(-ret));
11502 	}
11503 }
11504 
11505 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11506 	.f = cmd_set_all_queues_drop_en_parsed,
11507 	.data = NULL,
11508 	.help_str = "set all queues drop <port_id> on|off",
11509 	.tokens = {
11510 		(void *)&cmd_all_queues_drop_en_set,
11511 		(void *)&cmd_all_queues_drop_en_all,
11512 		(void *)&cmd_all_queues_drop_en_queues,
11513 		(void *)&cmd_all_queues_drop_en_drop,
11514 		(void *)&cmd_all_queues_drop_en_port_id,
11515 		(void *)&cmd_all_queues_drop_en_on_off,
11516 		NULL,
11517 	},
11518 };
11519 
11520 /* vf split drop enable configuration */
11521 
11522 /* Common result structure for vf split drop enable */
11523 struct cmd_vf_split_drop_en_result {
11524 	cmdline_fixed_string_t set;
11525 	cmdline_fixed_string_t vf;
11526 	cmdline_fixed_string_t split;
11527 	cmdline_fixed_string_t drop;
11528 	uint8_t port_id;
11529 	uint16_t vf_id;
11530 	cmdline_fixed_string_t on_off;
11531 };
11532 
11533 /* Common CLI fields for vf split drop enable disable */
11534 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11535 	TOKEN_STRING_INITIALIZER
11536 		(struct cmd_vf_split_drop_en_result,
11537 		 set, "set");
11538 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11539 	TOKEN_STRING_INITIALIZER
11540 		(struct cmd_vf_split_drop_en_result,
11541 		 vf, "vf");
11542 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11543 	TOKEN_STRING_INITIALIZER
11544 		(struct cmd_vf_split_drop_en_result,
11545 		 split, "split");
11546 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11547 	TOKEN_STRING_INITIALIZER
11548 		(struct cmd_vf_split_drop_en_result,
11549 		 drop, "drop");
11550 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11551 	TOKEN_NUM_INITIALIZER
11552 		(struct cmd_vf_split_drop_en_result,
11553 		 port_id, UINT8);
11554 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11555 	TOKEN_NUM_INITIALIZER
11556 		(struct cmd_vf_split_drop_en_result,
11557 		 vf_id, UINT16);
11558 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11559 	TOKEN_STRING_INITIALIZER
11560 		(struct cmd_vf_split_drop_en_result,
11561 		 on_off, "on#off");
11562 
11563 static void
11564 cmd_set_vf_split_drop_en_parsed(
11565 	void *parsed_result,
11566 	__attribute__((unused)) struct cmdline *cl,
11567 	__attribute__((unused)) void *data)
11568 {
11569 	struct cmd_vf_split_drop_en_result *res = parsed_result;
11570 	int ret;
11571 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11572 
11573 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11574 		return;
11575 
11576 	ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11577 			is_on);
11578 	switch (ret) {
11579 	case 0:
11580 		break;
11581 	case -EINVAL:
11582 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11583 		break;
11584 	case -ENODEV:
11585 		printf("invalid port_id %d\n", res->port_id);
11586 		break;
11587 	default:
11588 		printf("programming error: (%s)\n", strerror(-ret));
11589 	}
11590 }
11591 
11592 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11593 	.f = cmd_set_vf_split_drop_en_parsed,
11594 	.data = NULL,
11595 	.help_str = "set vf split drop <port_id> <vf_id> on|off",
11596 	.tokens = {
11597 		(void *)&cmd_vf_split_drop_en_set,
11598 		(void *)&cmd_vf_split_drop_en_vf,
11599 		(void *)&cmd_vf_split_drop_en_split,
11600 		(void *)&cmd_vf_split_drop_en_drop,
11601 		(void *)&cmd_vf_split_drop_en_port_id,
11602 		(void *)&cmd_vf_split_drop_en_vf_id,
11603 		(void *)&cmd_vf_split_drop_en_on_off,
11604 		NULL,
11605 	},
11606 };
11607 #endif
11608 
11609 /* vf mac address configuration */
11610 
11611 /* Common result structure for vf mac address */
11612 struct cmd_set_vf_mac_addr_result {
11613 	cmdline_fixed_string_t set;
11614 	cmdline_fixed_string_t vf;
11615 	cmdline_fixed_string_t mac;
11616 	cmdline_fixed_string_t addr;
11617 	uint8_t port_id;
11618 	uint16_t vf_id;
11619 	struct ether_addr mac_addr;
11620 
11621 };
11622 
11623 /* Common CLI fields for vf split drop enable disable */
11624 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11625 	TOKEN_STRING_INITIALIZER
11626 		(struct cmd_set_vf_mac_addr_result,
11627 		 set, "set");
11628 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11629 	TOKEN_STRING_INITIALIZER
11630 		(struct cmd_set_vf_mac_addr_result,
11631 		 vf, "vf");
11632 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11633 	TOKEN_STRING_INITIALIZER
11634 		(struct cmd_set_vf_mac_addr_result,
11635 		 mac, "mac");
11636 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11637 	TOKEN_STRING_INITIALIZER
11638 		(struct cmd_set_vf_mac_addr_result,
11639 		 addr, "addr");
11640 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11641 	TOKEN_NUM_INITIALIZER
11642 		(struct cmd_set_vf_mac_addr_result,
11643 		 port_id, UINT8);
11644 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11645 	TOKEN_NUM_INITIALIZER
11646 		(struct cmd_set_vf_mac_addr_result,
11647 		 vf_id, UINT16);
11648 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11649 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11650 		 mac_addr);
11651 
11652 static void
11653 cmd_set_vf_mac_addr_parsed(
11654 	void *parsed_result,
11655 	__attribute__((unused)) struct cmdline *cl,
11656 	__attribute__((unused)) void *data)
11657 {
11658 	struct cmd_set_vf_mac_addr_result *res = parsed_result;
11659 	int ret = -ENOTSUP;
11660 
11661 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11662 		return;
11663 
11664 #ifdef RTE_LIBRTE_IXGBE_PMD
11665 	if (ret == -ENOTSUP)
11666 		ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11667 				&res->mac_addr);
11668 #endif
11669 #ifdef RTE_LIBRTE_I40E_PMD
11670 	if (ret == -ENOTSUP)
11671 		ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11672 				&res->mac_addr);
11673 #endif
11674 
11675 	switch (ret) {
11676 	case 0:
11677 		break;
11678 	case -EINVAL:
11679 		printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11680 		break;
11681 	case -ENODEV:
11682 		printf("invalid port_id %d\n", res->port_id);
11683 		break;
11684 	case -ENOTSUP:
11685 		printf("function not implemented\n");
11686 		break;
11687 	default:
11688 		printf("programming error: (%s)\n", strerror(-ret));
11689 	}
11690 }
11691 
11692 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11693 	.f = cmd_set_vf_mac_addr_parsed,
11694 	.data = NULL,
11695 	.help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11696 	.tokens = {
11697 		(void *)&cmd_set_vf_mac_addr_set,
11698 		(void *)&cmd_set_vf_mac_addr_vf,
11699 		(void *)&cmd_set_vf_mac_addr_mac,
11700 		(void *)&cmd_set_vf_mac_addr_addr,
11701 		(void *)&cmd_set_vf_mac_addr_port_id,
11702 		(void *)&cmd_set_vf_mac_addr_vf_id,
11703 		(void *)&cmd_set_vf_mac_addr_mac_addr,
11704 		NULL,
11705 	},
11706 };
11707 
11708 #ifdef RTE_LIBRTE_IXGBE_PMD
11709 /* MACsec configuration */
11710 
11711 /* Common result structure for MACsec offload enable */
11712 struct cmd_macsec_offload_on_result {
11713 	cmdline_fixed_string_t set;
11714 	cmdline_fixed_string_t macsec;
11715 	cmdline_fixed_string_t offload;
11716 	uint8_t port_id;
11717 	cmdline_fixed_string_t on;
11718 	cmdline_fixed_string_t encrypt;
11719 	cmdline_fixed_string_t en_on_off;
11720 	cmdline_fixed_string_t replay_protect;
11721 	cmdline_fixed_string_t rp_on_off;
11722 };
11723 
11724 /* Common CLI fields for MACsec offload disable */
11725 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11726 	TOKEN_STRING_INITIALIZER
11727 		(struct cmd_macsec_offload_on_result,
11728 		 set, "set");
11729 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11730 	TOKEN_STRING_INITIALIZER
11731 		(struct cmd_macsec_offload_on_result,
11732 		 macsec, "macsec");
11733 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11734 	TOKEN_STRING_INITIALIZER
11735 		(struct cmd_macsec_offload_on_result,
11736 		 offload, "offload");
11737 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11738 	TOKEN_NUM_INITIALIZER
11739 		(struct cmd_macsec_offload_on_result,
11740 		 port_id, UINT8);
11741 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11742 	TOKEN_STRING_INITIALIZER
11743 		(struct cmd_macsec_offload_on_result,
11744 		 on, "on");
11745 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11746 	TOKEN_STRING_INITIALIZER
11747 		(struct cmd_macsec_offload_on_result,
11748 		 encrypt, "encrypt");
11749 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11750 	TOKEN_STRING_INITIALIZER
11751 		(struct cmd_macsec_offload_on_result,
11752 		 en_on_off, "on#off");
11753 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11754 	TOKEN_STRING_INITIALIZER
11755 		(struct cmd_macsec_offload_on_result,
11756 		 replay_protect, "replay-protect");
11757 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11758 	TOKEN_STRING_INITIALIZER
11759 		(struct cmd_macsec_offload_on_result,
11760 		 rp_on_off, "on#off");
11761 
11762 static void
11763 cmd_set_macsec_offload_on_parsed(
11764 	void *parsed_result,
11765 	__attribute__((unused)) struct cmdline *cl,
11766 	__attribute__((unused)) void *data)
11767 {
11768 	struct cmd_macsec_offload_on_result *res = parsed_result;
11769 	int ret;
11770 	portid_t port_id = res->port_id;
11771 	int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11772 	int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11773 
11774 	if (port_id_is_invalid(port_id, ENABLED_WARN))
11775 		return;
11776 
11777 	ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
11778 	ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11779 
11780 	switch (ret) {
11781 	case 0:
11782 		break;
11783 	case -ENODEV:
11784 		printf("invalid port_id %d\n", port_id);
11785 		break;
11786 	default:
11787 		printf("programming error: (%s)\n", strerror(-ret));
11788 	}
11789 }
11790 
11791 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11792 	.f = cmd_set_macsec_offload_on_parsed,
11793 	.data = NULL,
11794 	.help_str = "set macsec offload <port_id> on "
11795 		"encrypt on|off replay-protect on|off",
11796 	.tokens = {
11797 		(void *)&cmd_macsec_offload_on_set,
11798 		(void *)&cmd_macsec_offload_on_macsec,
11799 		(void *)&cmd_macsec_offload_on_offload,
11800 		(void *)&cmd_macsec_offload_on_port_id,
11801 		(void *)&cmd_macsec_offload_on_on,
11802 		(void *)&cmd_macsec_offload_on_encrypt,
11803 		(void *)&cmd_macsec_offload_on_en_on_off,
11804 		(void *)&cmd_macsec_offload_on_replay_protect,
11805 		(void *)&cmd_macsec_offload_on_rp_on_off,
11806 		NULL,
11807 	},
11808 };
11809 
11810 /* Common result structure for MACsec offload disable */
11811 struct cmd_macsec_offload_off_result {
11812 	cmdline_fixed_string_t set;
11813 	cmdline_fixed_string_t macsec;
11814 	cmdline_fixed_string_t offload;
11815 	uint8_t port_id;
11816 	cmdline_fixed_string_t off;
11817 };
11818 
11819 /* Common CLI fields for MACsec offload disable */
11820 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11821 	TOKEN_STRING_INITIALIZER
11822 		(struct cmd_macsec_offload_off_result,
11823 		 set, "set");
11824 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11825 	TOKEN_STRING_INITIALIZER
11826 		(struct cmd_macsec_offload_off_result,
11827 		 macsec, "macsec");
11828 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11829 	TOKEN_STRING_INITIALIZER
11830 		(struct cmd_macsec_offload_off_result,
11831 		 offload, "offload");
11832 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11833 	TOKEN_NUM_INITIALIZER
11834 		(struct cmd_macsec_offload_off_result,
11835 		 port_id, UINT8);
11836 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11837 	TOKEN_STRING_INITIALIZER
11838 		(struct cmd_macsec_offload_off_result,
11839 		 off, "off");
11840 
11841 static void
11842 cmd_set_macsec_offload_off_parsed(
11843 	void *parsed_result,
11844 	__attribute__((unused)) struct cmdline *cl,
11845 	__attribute__((unused)) void *data)
11846 {
11847 	struct cmd_macsec_offload_off_result *res = parsed_result;
11848 	int ret;
11849 	portid_t port_id = res->port_id;
11850 
11851 	if (port_id_is_invalid(port_id, ENABLED_WARN))
11852 		return;
11853 
11854 	ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
11855 	ret = rte_pmd_ixgbe_macsec_disable(port_id);
11856 
11857 	switch (ret) {
11858 	case 0:
11859 		break;
11860 	case -ENODEV:
11861 		printf("invalid port_id %d\n", port_id);
11862 		break;
11863 	default:
11864 		printf("programming error: (%s)\n", strerror(-ret));
11865 	}
11866 }
11867 
11868 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11869 	.f = cmd_set_macsec_offload_off_parsed,
11870 	.data = NULL,
11871 	.help_str = "set macsec offload <port_id> off",
11872 	.tokens = {
11873 		(void *)&cmd_macsec_offload_off_set,
11874 		(void *)&cmd_macsec_offload_off_macsec,
11875 		(void *)&cmd_macsec_offload_off_offload,
11876 		(void *)&cmd_macsec_offload_off_port_id,
11877 		(void *)&cmd_macsec_offload_off_off,
11878 		NULL,
11879 	},
11880 };
11881 
11882 /* Common result structure for MACsec secure connection configure */
11883 struct cmd_macsec_sc_result {
11884 	cmdline_fixed_string_t set;
11885 	cmdline_fixed_string_t macsec;
11886 	cmdline_fixed_string_t sc;
11887 	cmdline_fixed_string_t tx_rx;
11888 	uint8_t port_id;
11889 	struct ether_addr mac;
11890 	uint16_t pi;
11891 };
11892 
11893 /* Common CLI fields for MACsec secure connection configure */
11894 cmdline_parse_token_string_t cmd_macsec_sc_set =
11895 	TOKEN_STRING_INITIALIZER
11896 		(struct cmd_macsec_sc_result,
11897 		 set, "set");
11898 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11899 	TOKEN_STRING_INITIALIZER
11900 		(struct cmd_macsec_sc_result,
11901 		 macsec, "macsec");
11902 cmdline_parse_token_string_t cmd_macsec_sc_sc =
11903 	TOKEN_STRING_INITIALIZER
11904 		(struct cmd_macsec_sc_result,
11905 		 sc, "sc");
11906 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11907 	TOKEN_STRING_INITIALIZER
11908 		(struct cmd_macsec_sc_result,
11909 		 tx_rx, "tx#rx");
11910 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11911 	TOKEN_NUM_INITIALIZER
11912 		(struct cmd_macsec_sc_result,
11913 		 port_id, UINT8);
11914 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11915 	TOKEN_ETHERADDR_INITIALIZER
11916 		(struct cmd_macsec_sc_result,
11917 		 mac);
11918 cmdline_parse_token_num_t cmd_macsec_sc_pi =
11919 	TOKEN_NUM_INITIALIZER
11920 		(struct cmd_macsec_sc_result,
11921 		 pi, UINT16);
11922 
11923 static void
11924 cmd_set_macsec_sc_parsed(
11925 	void *parsed_result,
11926 	__attribute__((unused)) struct cmdline *cl,
11927 	__attribute__((unused)) void *data)
11928 {
11929 	struct cmd_macsec_sc_result *res = parsed_result;
11930 	int ret;
11931 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11932 
11933 	ret = is_tx ?
11934 		rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
11935 				res->mac.addr_bytes) :
11936 		rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
11937 				res->mac.addr_bytes, res->pi);
11938 	switch (ret) {
11939 	case 0:
11940 		break;
11941 	case -ENODEV:
11942 		printf("invalid port_id %d\n", res->port_id);
11943 		break;
11944 	default:
11945 		printf("programming error: (%s)\n", strerror(-ret));
11946 	}
11947 }
11948 
11949 cmdline_parse_inst_t cmd_set_macsec_sc = {
11950 	.f = cmd_set_macsec_sc_parsed,
11951 	.data = NULL,
11952 	.help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
11953 	.tokens = {
11954 		(void *)&cmd_macsec_sc_set,
11955 		(void *)&cmd_macsec_sc_macsec,
11956 		(void *)&cmd_macsec_sc_sc,
11957 		(void *)&cmd_macsec_sc_tx_rx,
11958 		(void *)&cmd_macsec_sc_port_id,
11959 		(void *)&cmd_macsec_sc_mac,
11960 		(void *)&cmd_macsec_sc_pi,
11961 		NULL,
11962 	},
11963 };
11964 
11965 /* Common result structure for MACsec secure connection configure */
11966 struct cmd_macsec_sa_result {
11967 	cmdline_fixed_string_t set;
11968 	cmdline_fixed_string_t macsec;
11969 	cmdline_fixed_string_t sa;
11970 	cmdline_fixed_string_t tx_rx;
11971 	uint8_t port_id;
11972 	uint8_t idx;
11973 	uint8_t an;
11974 	uint32_t pn;
11975 	cmdline_fixed_string_t key;
11976 };
11977 
11978 /* Common CLI fields for MACsec secure connection configure */
11979 cmdline_parse_token_string_t cmd_macsec_sa_set =
11980 	TOKEN_STRING_INITIALIZER
11981 		(struct cmd_macsec_sa_result,
11982 		 set, "set");
11983 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
11984 	TOKEN_STRING_INITIALIZER
11985 		(struct cmd_macsec_sa_result,
11986 		 macsec, "macsec");
11987 cmdline_parse_token_string_t cmd_macsec_sa_sa =
11988 	TOKEN_STRING_INITIALIZER
11989 		(struct cmd_macsec_sa_result,
11990 		 sa, "sa");
11991 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
11992 	TOKEN_STRING_INITIALIZER
11993 		(struct cmd_macsec_sa_result,
11994 		 tx_rx, "tx#rx");
11995 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
11996 	TOKEN_NUM_INITIALIZER
11997 		(struct cmd_macsec_sa_result,
11998 		 port_id, UINT8);
11999 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12000 	TOKEN_NUM_INITIALIZER
12001 		(struct cmd_macsec_sa_result,
12002 		 idx, UINT8);
12003 cmdline_parse_token_num_t cmd_macsec_sa_an =
12004 	TOKEN_NUM_INITIALIZER
12005 		(struct cmd_macsec_sa_result,
12006 		 an, UINT8);
12007 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12008 	TOKEN_NUM_INITIALIZER
12009 		(struct cmd_macsec_sa_result,
12010 		 pn, UINT32);
12011 cmdline_parse_token_string_t cmd_macsec_sa_key =
12012 	TOKEN_STRING_INITIALIZER
12013 		(struct cmd_macsec_sa_result,
12014 		 key, NULL);
12015 
12016 static void
12017 cmd_set_macsec_sa_parsed(
12018 	void *parsed_result,
12019 	__attribute__((unused)) struct cmdline *cl,
12020 	__attribute__((unused)) void *data)
12021 {
12022 	struct cmd_macsec_sa_result *res = parsed_result;
12023 	int ret;
12024 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12025 	uint8_t key[16] = { 0 };
12026 	uint8_t xdgt0;
12027 	uint8_t xdgt1;
12028 	int key_len;
12029 	int i;
12030 
12031 	key_len = strlen(res->key) / 2;
12032 	if (key_len > 16)
12033 		key_len = 16;
12034 
12035 	for (i = 0; i < key_len; i++) {
12036 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12037 		if (xdgt0 == 0xFF)
12038 			return;
12039 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12040 		if (xdgt1 == 0xFF)
12041 			return;
12042 		key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12043 	}
12044 
12045 	ret = is_tx ?
12046 		rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12047 			res->idx, res->an, res->pn, key) :
12048 		rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12049 			res->idx, res->an, res->pn, key);
12050 	switch (ret) {
12051 	case 0:
12052 		break;
12053 	case -EINVAL:
12054 		printf("invalid idx %d or an %d\n", res->idx, res->an);
12055 		break;
12056 	case -ENODEV:
12057 		printf("invalid port_id %d\n", res->port_id);
12058 		break;
12059 	default:
12060 		printf("programming error: (%s)\n", strerror(-ret));
12061 	}
12062 }
12063 
12064 cmdline_parse_inst_t cmd_set_macsec_sa = {
12065 	.f = cmd_set_macsec_sa_parsed,
12066 	.data = NULL,
12067 	.help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12068 	.tokens = {
12069 		(void *)&cmd_macsec_sa_set,
12070 		(void *)&cmd_macsec_sa_macsec,
12071 		(void *)&cmd_macsec_sa_sa,
12072 		(void *)&cmd_macsec_sa_tx_rx,
12073 		(void *)&cmd_macsec_sa_port_id,
12074 		(void *)&cmd_macsec_sa_idx,
12075 		(void *)&cmd_macsec_sa_an,
12076 		(void *)&cmd_macsec_sa_pn,
12077 		(void *)&cmd_macsec_sa_key,
12078 		NULL,
12079 	},
12080 };
12081 #endif
12082 
12083 /* VF unicast promiscuous mode configuration */
12084 
12085 /* Common result structure for VF unicast promiscuous mode */
12086 struct cmd_vf_promisc_result {
12087 	cmdline_fixed_string_t set;
12088 	cmdline_fixed_string_t vf;
12089 	cmdline_fixed_string_t promisc;
12090 	uint8_t port_id;
12091 	uint32_t vf_id;
12092 	cmdline_fixed_string_t on_off;
12093 };
12094 
12095 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12096 cmdline_parse_token_string_t cmd_vf_promisc_set =
12097 	TOKEN_STRING_INITIALIZER
12098 		(struct cmd_vf_promisc_result,
12099 		 set, "set");
12100 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12101 	TOKEN_STRING_INITIALIZER
12102 		(struct cmd_vf_promisc_result,
12103 		 vf, "vf");
12104 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12105 	TOKEN_STRING_INITIALIZER
12106 		(struct cmd_vf_promisc_result,
12107 		 promisc, "promisc");
12108 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12109 	TOKEN_NUM_INITIALIZER
12110 		(struct cmd_vf_promisc_result,
12111 		 port_id, UINT8);
12112 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12113 	TOKEN_NUM_INITIALIZER
12114 		(struct cmd_vf_promisc_result,
12115 		 vf_id, UINT32);
12116 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12117 	TOKEN_STRING_INITIALIZER
12118 		(struct cmd_vf_promisc_result,
12119 		 on_off, "on#off");
12120 
12121 static void
12122 cmd_set_vf_promisc_parsed(
12123 	void *parsed_result,
12124 	__attribute__((unused)) struct cmdline *cl,
12125 	__attribute__((unused)) void *data)
12126 {
12127 	struct cmd_vf_promisc_result *res = parsed_result;
12128 	int ret = -ENOTSUP;
12129 
12130 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12131 
12132 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12133 		return;
12134 
12135 #ifdef RTE_LIBRTE_I40E_PMD
12136 	ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12137 						  res->vf_id, is_on);
12138 #endif
12139 
12140 	switch (ret) {
12141 	case 0:
12142 		break;
12143 	case -EINVAL:
12144 		printf("invalid vf_id %d\n", res->vf_id);
12145 		break;
12146 	case -ENODEV:
12147 		printf("invalid port_id %d\n", res->port_id);
12148 		break;
12149 	case -ENOTSUP:
12150 		printf("function not implemented\n");
12151 		break;
12152 	default:
12153 		printf("programming error: (%s)\n", strerror(-ret));
12154 	}
12155 }
12156 
12157 cmdline_parse_inst_t cmd_set_vf_promisc = {
12158 	.f = cmd_set_vf_promisc_parsed,
12159 	.data = NULL,
12160 	.help_str = "set vf promisc <port_id> <vf_id> on|off: "
12161 		"Set unicast promiscuous mode for a VF from the PF",
12162 	.tokens = {
12163 		(void *)&cmd_vf_promisc_set,
12164 		(void *)&cmd_vf_promisc_vf,
12165 		(void *)&cmd_vf_promisc_promisc,
12166 		(void *)&cmd_vf_promisc_port_id,
12167 		(void *)&cmd_vf_promisc_vf_id,
12168 		(void *)&cmd_vf_promisc_on_off,
12169 		NULL,
12170 	},
12171 };
12172 
12173 /* VF multicast promiscuous mode configuration */
12174 
12175 /* Common result structure for VF multicast promiscuous mode */
12176 struct cmd_vf_allmulti_result {
12177 	cmdline_fixed_string_t set;
12178 	cmdline_fixed_string_t vf;
12179 	cmdline_fixed_string_t allmulti;
12180 	uint8_t port_id;
12181 	uint32_t vf_id;
12182 	cmdline_fixed_string_t on_off;
12183 };
12184 
12185 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12186 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12187 	TOKEN_STRING_INITIALIZER
12188 		(struct cmd_vf_allmulti_result,
12189 		 set, "set");
12190 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12191 	TOKEN_STRING_INITIALIZER
12192 		(struct cmd_vf_allmulti_result,
12193 		 vf, "vf");
12194 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12195 	TOKEN_STRING_INITIALIZER
12196 		(struct cmd_vf_allmulti_result,
12197 		 allmulti, "allmulti");
12198 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12199 	TOKEN_NUM_INITIALIZER
12200 		(struct cmd_vf_allmulti_result,
12201 		 port_id, UINT8);
12202 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12203 	TOKEN_NUM_INITIALIZER
12204 		(struct cmd_vf_allmulti_result,
12205 		 vf_id, UINT32);
12206 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12207 	TOKEN_STRING_INITIALIZER
12208 		(struct cmd_vf_allmulti_result,
12209 		 on_off, "on#off");
12210 
12211 static void
12212 cmd_set_vf_allmulti_parsed(
12213 	void *parsed_result,
12214 	__attribute__((unused)) struct cmdline *cl,
12215 	__attribute__((unused)) void *data)
12216 {
12217 	struct cmd_vf_allmulti_result *res = parsed_result;
12218 	int ret = -ENOTSUP;
12219 
12220 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12221 
12222 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12223 		return;
12224 
12225 #ifdef RTE_LIBRTE_I40E_PMD
12226 	ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12227 						    res->vf_id, is_on);
12228 #endif
12229 
12230 	switch (ret) {
12231 	case 0:
12232 		break;
12233 	case -EINVAL:
12234 		printf("invalid vf_id %d\n", res->vf_id);
12235 		break;
12236 	case -ENODEV:
12237 		printf("invalid port_id %d\n", res->port_id);
12238 		break;
12239 	case -ENOTSUP:
12240 		printf("function not implemented\n");
12241 		break;
12242 	default:
12243 		printf("programming error: (%s)\n", strerror(-ret));
12244 	}
12245 }
12246 
12247 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12248 	.f = cmd_set_vf_allmulti_parsed,
12249 	.data = NULL,
12250 	.help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12251 		"Set multicast promiscuous mode for a VF from the PF",
12252 	.tokens = {
12253 		(void *)&cmd_vf_allmulti_set,
12254 		(void *)&cmd_vf_allmulti_vf,
12255 		(void *)&cmd_vf_allmulti_allmulti,
12256 		(void *)&cmd_vf_allmulti_port_id,
12257 		(void *)&cmd_vf_allmulti_vf_id,
12258 		(void *)&cmd_vf_allmulti_on_off,
12259 		NULL,
12260 	},
12261 };
12262 
12263 /* vf broadcast mode configuration */
12264 
12265 /* Common result structure for vf broadcast */
12266 struct cmd_set_vf_broadcast_result {
12267 	cmdline_fixed_string_t set;
12268 	cmdline_fixed_string_t vf;
12269 	cmdline_fixed_string_t broadcast;
12270 	uint8_t port_id;
12271 	uint16_t vf_id;
12272 	cmdline_fixed_string_t on_off;
12273 };
12274 
12275 /* Common CLI fields for vf broadcast enable disable */
12276 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12277 	TOKEN_STRING_INITIALIZER
12278 		(struct cmd_set_vf_broadcast_result,
12279 		 set, "set");
12280 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12281 	TOKEN_STRING_INITIALIZER
12282 		(struct cmd_set_vf_broadcast_result,
12283 		 vf, "vf");
12284 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12285 	TOKEN_STRING_INITIALIZER
12286 		(struct cmd_set_vf_broadcast_result,
12287 		 broadcast, "broadcast");
12288 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12289 	TOKEN_NUM_INITIALIZER
12290 		(struct cmd_set_vf_broadcast_result,
12291 		 port_id, UINT8);
12292 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12293 	TOKEN_NUM_INITIALIZER
12294 		(struct cmd_set_vf_broadcast_result,
12295 		 vf_id, UINT16);
12296 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12297 	TOKEN_STRING_INITIALIZER
12298 		(struct cmd_set_vf_broadcast_result,
12299 		 on_off, "on#off");
12300 
12301 static void
12302 cmd_set_vf_broadcast_parsed(
12303 	void *parsed_result,
12304 	__attribute__((unused)) struct cmdline *cl,
12305 	__attribute__((unused)) void *data)
12306 {
12307 	struct cmd_set_vf_broadcast_result *res = parsed_result;
12308 	int ret = -ENOTSUP;
12309 
12310 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12311 
12312 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12313 		return;
12314 
12315 #ifdef RTE_LIBRTE_I40E_PMD
12316 	ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12317 					    res->vf_id, is_on);
12318 #endif
12319 
12320 	switch (ret) {
12321 	case 0:
12322 		break;
12323 	case -EINVAL:
12324 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12325 		break;
12326 	case -ENODEV:
12327 		printf("invalid port_id %d\n", res->port_id);
12328 		break;
12329 	case -ENOTSUP:
12330 		printf("function not implemented\n");
12331 		break;
12332 	default:
12333 		printf("programming error: (%s)\n", strerror(-ret));
12334 	}
12335 }
12336 
12337 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12338 	.f = cmd_set_vf_broadcast_parsed,
12339 	.data = NULL,
12340 	.help_str = "set vf broadcast <port_id> <vf_id> on|off",
12341 	.tokens = {
12342 		(void *)&cmd_set_vf_broadcast_set,
12343 		(void *)&cmd_set_vf_broadcast_vf,
12344 		(void *)&cmd_set_vf_broadcast_broadcast,
12345 		(void *)&cmd_set_vf_broadcast_port_id,
12346 		(void *)&cmd_set_vf_broadcast_vf_id,
12347 		(void *)&cmd_set_vf_broadcast_on_off,
12348 		NULL,
12349 	},
12350 };
12351 
12352 /* vf vlan tag configuration */
12353 
12354 /* Common result structure for vf vlan tag */
12355 struct cmd_set_vf_vlan_tag_result {
12356 	cmdline_fixed_string_t set;
12357 	cmdline_fixed_string_t vf;
12358 	cmdline_fixed_string_t vlan;
12359 	cmdline_fixed_string_t tag;
12360 	uint8_t port_id;
12361 	uint16_t vf_id;
12362 	cmdline_fixed_string_t on_off;
12363 };
12364 
12365 /* Common CLI fields for vf vlan tag enable disable */
12366 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12367 	TOKEN_STRING_INITIALIZER
12368 		(struct cmd_set_vf_vlan_tag_result,
12369 		 set, "set");
12370 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12371 	TOKEN_STRING_INITIALIZER
12372 		(struct cmd_set_vf_vlan_tag_result,
12373 		 vf, "vf");
12374 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12375 	TOKEN_STRING_INITIALIZER
12376 		(struct cmd_set_vf_vlan_tag_result,
12377 		 vlan, "vlan");
12378 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12379 	TOKEN_STRING_INITIALIZER
12380 		(struct cmd_set_vf_vlan_tag_result,
12381 		 tag, "tag");
12382 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12383 	TOKEN_NUM_INITIALIZER
12384 		(struct cmd_set_vf_vlan_tag_result,
12385 		 port_id, UINT8);
12386 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12387 	TOKEN_NUM_INITIALIZER
12388 		(struct cmd_set_vf_vlan_tag_result,
12389 		 vf_id, UINT16);
12390 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12391 	TOKEN_STRING_INITIALIZER
12392 		(struct cmd_set_vf_vlan_tag_result,
12393 		 on_off, "on#off");
12394 
12395 static void
12396 cmd_set_vf_vlan_tag_parsed(
12397 	void *parsed_result,
12398 	__attribute__((unused)) struct cmdline *cl,
12399 	__attribute__((unused)) void *data)
12400 {
12401 	struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12402 	int ret = -ENOTSUP;
12403 
12404 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12405 
12406 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12407 		return;
12408 
12409 #ifdef RTE_LIBRTE_I40E_PMD
12410 	ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12411 					   res->vf_id, is_on);
12412 #endif
12413 
12414 	switch (ret) {
12415 	case 0:
12416 		break;
12417 	case -EINVAL:
12418 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12419 		break;
12420 	case -ENODEV:
12421 		printf("invalid port_id %d\n", res->port_id);
12422 		break;
12423 	case -ENOTSUP:
12424 		printf("function not implemented\n");
12425 		break;
12426 	default:
12427 		printf("programming error: (%s)\n", strerror(-ret));
12428 	}
12429 }
12430 
12431 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12432 	.f = cmd_set_vf_vlan_tag_parsed,
12433 	.data = NULL,
12434 	.help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12435 	.tokens = {
12436 		(void *)&cmd_set_vf_vlan_tag_set,
12437 		(void *)&cmd_set_vf_vlan_tag_vf,
12438 		(void *)&cmd_set_vf_vlan_tag_vlan,
12439 		(void *)&cmd_set_vf_vlan_tag_tag,
12440 		(void *)&cmd_set_vf_vlan_tag_port_id,
12441 		(void *)&cmd_set_vf_vlan_tag_vf_id,
12442 		(void *)&cmd_set_vf_vlan_tag_on_off,
12443 		NULL,
12444 	},
12445 };
12446 
12447 /* Common definition of VF and TC TX bandwidth configuration */
12448 struct cmd_vf_tc_bw_result {
12449 	cmdline_fixed_string_t set;
12450 	cmdline_fixed_string_t vf;
12451 	cmdline_fixed_string_t tc;
12452 	cmdline_fixed_string_t tx;
12453 	cmdline_fixed_string_t min_bw;
12454 	cmdline_fixed_string_t max_bw;
12455 	cmdline_fixed_string_t strict_link_prio;
12456 	uint8_t port_id;
12457 	uint16_t vf_id;
12458 	uint8_t tc_no;
12459 	uint32_t bw;
12460 	cmdline_fixed_string_t bw_list;
12461 	uint8_t tc_map;
12462 };
12463 
12464 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12465 	TOKEN_STRING_INITIALIZER
12466 		(struct cmd_vf_tc_bw_result,
12467 		 set, "set");
12468 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12469 	TOKEN_STRING_INITIALIZER
12470 		(struct cmd_vf_tc_bw_result,
12471 		 vf, "vf");
12472 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12473 	TOKEN_STRING_INITIALIZER
12474 		(struct cmd_vf_tc_bw_result,
12475 		 tc, "tc");
12476 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12477 	TOKEN_STRING_INITIALIZER
12478 		(struct cmd_vf_tc_bw_result,
12479 		 tx, "tx");
12480 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12481 	TOKEN_STRING_INITIALIZER
12482 		(struct cmd_vf_tc_bw_result,
12483 		 strict_link_prio, "strict-link-priority");
12484 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12485 	TOKEN_STRING_INITIALIZER
12486 		(struct cmd_vf_tc_bw_result,
12487 		 min_bw, "min-bandwidth");
12488 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12489 	TOKEN_STRING_INITIALIZER
12490 		(struct cmd_vf_tc_bw_result,
12491 		 max_bw, "max-bandwidth");
12492 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12493 	TOKEN_NUM_INITIALIZER
12494 		(struct cmd_vf_tc_bw_result,
12495 		 port_id, UINT8);
12496 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12497 	TOKEN_NUM_INITIALIZER
12498 		(struct cmd_vf_tc_bw_result,
12499 		 vf_id, UINT16);
12500 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12501 	TOKEN_NUM_INITIALIZER
12502 		(struct cmd_vf_tc_bw_result,
12503 		 tc_no, UINT8);
12504 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12505 	TOKEN_NUM_INITIALIZER
12506 		(struct cmd_vf_tc_bw_result,
12507 		 bw, UINT32);
12508 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12509 	TOKEN_STRING_INITIALIZER
12510 		(struct cmd_vf_tc_bw_result,
12511 		 bw_list, NULL);
12512 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12513 	TOKEN_NUM_INITIALIZER
12514 		(struct cmd_vf_tc_bw_result,
12515 		 tc_map, UINT8);
12516 
12517 /* VF max bandwidth setting */
12518 static void
12519 cmd_vf_max_bw_parsed(
12520 	void *parsed_result,
12521 	__attribute__((unused)) struct cmdline *cl,
12522 	__attribute__((unused)) void *data)
12523 {
12524 	struct cmd_vf_tc_bw_result *res = parsed_result;
12525 	int ret = -ENOTSUP;
12526 
12527 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12528 		return;
12529 
12530 #ifdef RTE_LIBRTE_I40E_PMD
12531 	ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12532 					 res->vf_id, res->bw);
12533 #endif
12534 
12535 	switch (ret) {
12536 	case 0:
12537 		break;
12538 	case -EINVAL:
12539 		printf("invalid vf_id %d or bandwidth %d\n",
12540 		       res->vf_id, res->bw);
12541 		break;
12542 	case -ENODEV:
12543 		printf("invalid port_id %d\n", res->port_id);
12544 		break;
12545 	case -ENOTSUP:
12546 		printf("function not implemented\n");
12547 		break;
12548 	default:
12549 		printf("programming error: (%s)\n", strerror(-ret));
12550 	}
12551 }
12552 
12553 cmdline_parse_inst_t cmd_vf_max_bw = {
12554 	.f = cmd_vf_max_bw_parsed,
12555 	.data = NULL,
12556 	.help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12557 	.tokens = {
12558 		(void *)&cmd_vf_tc_bw_set,
12559 		(void *)&cmd_vf_tc_bw_vf,
12560 		(void *)&cmd_vf_tc_bw_tx,
12561 		(void *)&cmd_vf_tc_bw_max_bw,
12562 		(void *)&cmd_vf_tc_bw_port_id,
12563 		(void *)&cmd_vf_tc_bw_vf_id,
12564 		(void *)&cmd_vf_tc_bw_bw,
12565 		NULL,
12566 	},
12567 };
12568 
12569 static int
12570 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12571 			   uint8_t *tc_num,
12572 			   char *str)
12573 {
12574 	uint32_t size;
12575 	const char *p, *p0 = str;
12576 	char s[256];
12577 	char *end;
12578 	char *str_fld[16];
12579 	uint16_t i;
12580 	int ret;
12581 
12582 	p = strchr(p0, '(');
12583 	if (p == NULL) {
12584 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12585 		return -1;
12586 	}
12587 	p++;
12588 	p0 = strchr(p, ')');
12589 	if (p0 == NULL) {
12590 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12591 		return -1;
12592 	}
12593 	size = p0 - p;
12594 	if (size >= sizeof(s)) {
12595 		printf("The string size exceeds the internal buffer size\n");
12596 		return -1;
12597 	}
12598 	snprintf(s, sizeof(s), "%.*s", size, p);
12599 	ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12600 	if (ret <= 0) {
12601 		printf("Failed to get the bandwidth list. ");
12602 		return -1;
12603 	}
12604 	*tc_num = ret;
12605 	for (i = 0; i < ret; i++)
12606 		bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12607 
12608 	return 0;
12609 }
12610 
12611 /* TC min bandwidth setting */
12612 static void
12613 cmd_vf_tc_min_bw_parsed(
12614 	void *parsed_result,
12615 	__attribute__((unused)) struct cmdline *cl,
12616 	__attribute__((unused)) void *data)
12617 {
12618 	struct cmd_vf_tc_bw_result *res = parsed_result;
12619 	uint8_t tc_num;
12620 	uint8_t bw[16];
12621 	int ret = -ENOTSUP;
12622 
12623 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12624 		return;
12625 
12626 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12627 	if (ret)
12628 		return;
12629 
12630 #ifdef RTE_LIBRTE_I40E_PMD
12631 	ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12632 					      tc_num, bw);
12633 #endif
12634 
12635 	switch (ret) {
12636 	case 0:
12637 		break;
12638 	case -EINVAL:
12639 		printf("invalid vf_id %d or bandwidth\n", res->vf_id);
12640 		break;
12641 	case -ENODEV:
12642 		printf("invalid port_id %d\n", res->port_id);
12643 		break;
12644 	case -ENOTSUP:
12645 		printf("function not implemented\n");
12646 		break;
12647 	default:
12648 		printf("programming error: (%s)\n", strerror(-ret));
12649 	}
12650 }
12651 
12652 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12653 	.f = cmd_vf_tc_min_bw_parsed,
12654 	.data = NULL,
12655 	.help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12656 		    " <bw1, bw2, ...>",
12657 	.tokens = {
12658 		(void *)&cmd_vf_tc_bw_set,
12659 		(void *)&cmd_vf_tc_bw_vf,
12660 		(void *)&cmd_vf_tc_bw_tc,
12661 		(void *)&cmd_vf_tc_bw_tx,
12662 		(void *)&cmd_vf_tc_bw_min_bw,
12663 		(void *)&cmd_vf_tc_bw_port_id,
12664 		(void *)&cmd_vf_tc_bw_vf_id,
12665 		(void *)&cmd_vf_tc_bw_bw_list,
12666 		NULL,
12667 	},
12668 };
12669 
12670 static void
12671 cmd_tc_min_bw_parsed(
12672 	void *parsed_result,
12673 	__attribute__((unused)) struct cmdline *cl,
12674 	__attribute__((unused)) void *data)
12675 {
12676 	struct cmd_vf_tc_bw_result *res = parsed_result;
12677 	struct rte_port *port;
12678 	uint8_t tc_num;
12679 	uint8_t bw[16];
12680 	int ret = -ENOTSUP;
12681 
12682 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12683 		return;
12684 
12685 	port = &ports[res->port_id];
12686 	/** Check if the port is not started **/
12687 	if (port->port_status != RTE_PORT_STOPPED) {
12688 		printf("Please stop port %d first\n", res->port_id);
12689 		return;
12690 	}
12691 
12692 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12693 	if (ret)
12694 		return;
12695 
12696 #ifdef RTE_LIBRTE_IXGBE_PMD
12697 	ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12698 #endif
12699 
12700 	switch (ret) {
12701 	case 0:
12702 		break;
12703 	case -EINVAL:
12704 		printf("invalid bandwidth\n");
12705 		break;
12706 	case -ENODEV:
12707 		printf("invalid port_id %d\n", res->port_id);
12708 		break;
12709 	case -ENOTSUP:
12710 		printf("function not implemented\n");
12711 		break;
12712 	default:
12713 		printf("programming error: (%s)\n", strerror(-ret));
12714 	}
12715 }
12716 
12717 cmdline_parse_inst_t cmd_tc_min_bw = {
12718 	.f = cmd_tc_min_bw_parsed,
12719 	.data = NULL,
12720 	.help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12721 	.tokens = {
12722 		(void *)&cmd_vf_tc_bw_set,
12723 		(void *)&cmd_vf_tc_bw_tc,
12724 		(void *)&cmd_vf_tc_bw_tx,
12725 		(void *)&cmd_vf_tc_bw_min_bw,
12726 		(void *)&cmd_vf_tc_bw_port_id,
12727 		(void *)&cmd_vf_tc_bw_bw_list,
12728 		NULL,
12729 	},
12730 };
12731 
12732 /* TC max bandwidth setting */
12733 static void
12734 cmd_vf_tc_max_bw_parsed(
12735 	void *parsed_result,
12736 	__attribute__((unused)) struct cmdline *cl,
12737 	__attribute__((unused)) void *data)
12738 {
12739 	struct cmd_vf_tc_bw_result *res = parsed_result;
12740 	int ret = -ENOTSUP;
12741 
12742 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12743 		return;
12744 
12745 #ifdef RTE_LIBRTE_I40E_PMD
12746 	ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12747 					    res->tc_no, res->bw);
12748 #endif
12749 
12750 	switch (ret) {
12751 	case 0:
12752 		break;
12753 	case -EINVAL:
12754 		printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
12755 		       res->vf_id, res->tc_no, res->bw);
12756 		break;
12757 	case -ENODEV:
12758 		printf("invalid port_id %d\n", res->port_id);
12759 		break;
12760 	case -ENOTSUP:
12761 		printf("function not implemented\n");
12762 		break;
12763 	default:
12764 		printf("programming error: (%s)\n", strerror(-ret));
12765 	}
12766 }
12767 
12768 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12769 	.f = cmd_vf_tc_max_bw_parsed,
12770 	.data = NULL,
12771 	.help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12772 		    " <bandwidth>",
12773 	.tokens = {
12774 		(void *)&cmd_vf_tc_bw_set,
12775 		(void *)&cmd_vf_tc_bw_vf,
12776 		(void *)&cmd_vf_tc_bw_tc,
12777 		(void *)&cmd_vf_tc_bw_tx,
12778 		(void *)&cmd_vf_tc_bw_max_bw,
12779 		(void *)&cmd_vf_tc_bw_port_id,
12780 		(void *)&cmd_vf_tc_bw_vf_id,
12781 		(void *)&cmd_vf_tc_bw_tc_no,
12782 		(void *)&cmd_vf_tc_bw_bw,
12783 		NULL,
12784 	},
12785 };
12786 
12787 /* Strict link priority scheduling mode setting */
12788 static void
12789 cmd_strict_link_prio_parsed(
12790 	void *parsed_result,
12791 	__attribute__((unused)) struct cmdline *cl,
12792 	__attribute__((unused)) void *data)
12793 {
12794 	struct cmd_vf_tc_bw_result *res = parsed_result;
12795 	int ret = -ENOTSUP;
12796 
12797 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12798 		return;
12799 
12800 #ifdef RTE_LIBRTE_I40E_PMD
12801 	ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
12802 #endif
12803 
12804 	switch (ret) {
12805 	case 0:
12806 		break;
12807 	case -EINVAL:
12808 		printf("invalid tc_bitmap 0x%x\n", res->tc_map);
12809 		break;
12810 	case -ENODEV:
12811 		printf("invalid port_id %d\n", res->port_id);
12812 		break;
12813 	case -ENOTSUP:
12814 		printf("function not implemented\n");
12815 		break;
12816 	default:
12817 		printf("programming error: (%s)\n", strerror(-ret));
12818 	}
12819 }
12820 
12821 cmdline_parse_inst_t cmd_strict_link_prio = {
12822 	.f = cmd_strict_link_prio_parsed,
12823 	.data = NULL,
12824 	.help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
12825 	.tokens = {
12826 		(void *)&cmd_vf_tc_bw_set,
12827 		(void *)&cmd_vf_tc_bw_tx,
12828 		(void *)&cmd_vf_tc_bw_strict_link_prio,
12829 		(void *)&cmd_vf_tc_bw_port_id,
12830 		(void *)&cmd_vf_tc_bw_tc_map,
12831 		NULL,
12832 	},
12833 };
12834 
12835 /* Load dynamic device personalization*/
12836 struct cmd_ddp_add_result {
12837 	cmdline_fixed_string_t ddp;
12838 	cmdline_fixed_string_t add;
12839 	uint8_t port_id;
12840 	char filepath[];
12841 };
12842 
12843 cmdline_parse_token_string_t cmd_ddp_add_ddp =
12844 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
12845 cmdline_parse_token_string_t cmd_ddp_add_add =
12846 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
12847 cmdline_parse_token_num_t cmd_ddp_add_port_id =
12848 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8);
12849 cmdline_parse_token_string_t cmd_ddp_add_filepath =
12850 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
12851 
12852 static void
12853 cmd_ddp_add_parsed(
12854 	void *parsed_result,
12855 	__attribute__((unused)) struct cmdline *cl,
12856 	__attribute__((unused)) void *data)
12857 {
12858 	struct cmd_ddp_add_result *res = parsed_result;
12859 	uint8_t *buff;
12860 	uint32_t size;
12861 	int ret = -ENOTSUP;
12862 
12863 	if (res->port_id > nb_ports) {
12864 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
12865 		return;
12866 	}
12867 
12868 	if (!all_ports_stopped()) {
12869 		printf("Please stop all ports first\n");
12870 		return;
12871 	}
12872 
12873 	buff = open_ddp_package_file(res->filepath, &size);
12874 	if (!buff)
12875 		return;
12876 
12877 #ifdef RTE_LIBRTE_I40E_PMD
12878 	if (ret == -ENOTSUP)
12879 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
12880 					       buff, size,
12881 					       RTE_PMD_I40E_PKG_OP_WR_ADD);
12882 #endif
12883 
12884 	if (ret < 0)
12885 		printf("Failed to load profile.\n");
12886 	else if (ret > 0)
12887 		printf("Profile has already existed.\n");
12888 
12889 	close_ddp_package_file(buff);
12890 }
12891 
12892 cmdline_parse_inst_t cmd_ddp_add = {
12893 	.f = cmd_ddp_add_parsed,
12894 	.data = NULL,
12895 	.help_str = "ddp add <port_id> <profile_path>",
12896 	.tokens = {
12897 		(void *)&cmd_ddp_add_ddp,
12898 		(void *)&cmd_ddp_add_add,
12899 		(void *)&cmd_ddp_add_port_id,
12900 		(void *)&cmd_ddp_add_filepath,
12901 		NULL,
12902 	},
12903 };
12904 
12905 /* Get dynamic device personalization profile info list*/
12906 #define PROFILE_INFO_SIZE 48
12907 #define MAX_PROFILE_NUM 16
12908 
12909 struct cmd_ddp_get_list_result {
12910 	cmdline_fixed_string_t ddp;
12911 	cmdline_fixed_string_t get;
12912 	cmdline_fixed_string_t list;
12913 	uint8_t port_id;
12914 };
12915 
12916 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
12917 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
12918 cmdline_parse_token_string_t cmd_ddp_get_list_get =
12919 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
12920 cmdline_parse_token_string_t cmd_ddp_get_list_list =
12921 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
12922 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
12923 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8);
12924 
12925 static void
12926 cmd_ddp_get_list_parsed(
12927 	void *parsed_result,
12928 	__attribute__((unused)) struct cmdline *cl,
12929 	__attribute__((unused)) void *data)
12930 {
12931 	struct cmd_ddp_get_list_result *res = parsed_result;
12932 #ifdef RTE_LIBRTE_I40E_PMD
12933 	struct rte_pmd_i40e_profile_list *p_list;
12934 	struct rte_pmd_i40e_profile_info *p_info;
12935 	uint32_t p_num;
12936 	uint32_t size;
12937 	uint32_t i;
12938 #endif
12939 	int ret = -ENOTSUP;
12940 
12941 	if (res->port_id > nb_ports) {
12942 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
12943 		return;
12944 	}
12945 
12946 #ifdef RTE_LIBRTE_I40E_PMD
12947 	size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
12948 	p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
12949 	if (!p_list)
12950 		printf("%s: Failed to malloc buffer\n", __func__);
12951 
12952 	if (ret == -ENOTSUP)
12953 		ret = rte_pmd_i40e_get_ddp_list(res->port_id,
12954 						(uint8_t *)p_list, size);
12955 
12956 	if (!ret) {
12957 		p_num = p_list->p_count;
12958 		printf("Profile number is: %d\n\n", p_num);
12959 
12960 		for (i = 0; i < p_num; i++) {
12961 			p_info = &p_list->p_info[i];
12962 			printf("Profile %d:\n", i);
12963 			printf("Track id:     0x%x\n", p_info->track_id);
12964 			printf("Version:      %d.%d.%d.%d\n",
12965 			       p_info->version.major,
12966 			       p_info->version.minor,
12967 			       p_info->version.update,
12968 			       p_info->version.draft);
12969 			printf("Profile name: %s\n\n", p_info->name);
12970 		}
12971 	}
12972 
12973 	free(p_list);
12974 #endif
12975 
12976 	if (ret < 0)
12977 		printf("Failed to get ddp list\n");
12978 }
12979 
12980 cmdline_parse_inst_t cmd_ddp_get_list = {
12981 	.f = cmd_ddp_get_list_parsed,
12982 	.data = NULL,
12983 	.help_str = "ddp get list <port_id>",
12984 	.tokens = {
12985 		(void *)&cmd_ddp_get_list_ddp,
12986 		(void *)&cmd_ddp_get_list_get,
12987 		(void *)&cmd_ddp_get_list_list,
12988 		(void *)&cmd_ddp_get_list_port_id,
12989 		NULL,
12990 	},
12991 };
12992 
12993 /* show vf stats */
12994 
12995 /* Common result structure for show vf stats */
12996 struct cmd_show_vf_stats_result {
12997 	cmdline_fixed_string_t show;
12998 	cmdline_fixed_string_t vf;
12999 	cmdline_fixed_string_t stats;
13000 	uint8_t port_id;
13001 	uint16_t vf_id;
13002 };
13003 
13004 /* Common CLI fields show vf stats*/
13005 cmdline_parse_token_string_t cmd_show_vf_stats_show =
13006 	TOKEN_STRING_INITIALIZER
13007 		(struct cmd_show_vf_stats_result,
13008 		 show, "show");
13009 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
13010 	TOKEN_STRING_INITIALIZER
13011 		(struct cmd_show_vf_stats_result,
13012 		 vf, "vf");
13013 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
13014 	TOKEN_STRING_INITIALIZER
13015 		(struct cmd_show_vf_stats_result,
13016 		 stats, "stats");
13017 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
13018 	TOKEN_NUM_INITIALIZER
13019 		(struct cmd_show_vf_stats_result,
13020 		 port_id, UINT8);
13021 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
13022 	TOKEN_NUM_INITIALIZER
13023 		(struct cmd_show_vf_stats_result,
13024 		 vf_id, UINT16);
13025 
13026 static void
13027 cmd_show_vf_stats_parsed(
13028 	void *parsed_result,
13029 	__attribute__((unused)) struct cmdline *cl,
13030 	__attribute__((unused)) void *data)
13031 {
13032 	struct cmd_show_vf_stats_result *res = parsed_result;
13033 	struct rte_eth_stats stats;
13034 	int ret = -ENOTSUP;
13035 	static const char *nic_stats_border = "########################";
13036 
13037 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13038 		return;
13039 
13040 	memset(&stats, 0, sizeof(stats));
13041 
13042 #ifdef RTE_LIBRTE_I40E_PMD
13043 	ret = rte_pmd_i40e_get_vf_stats(res->port_id,
13044 					res->vf_id,
13045 					&stats);
13046 #endif
13047 
13048 	switch (ret) {
13049 	case 0:
13050 		break;
13051 	case -EINVAL:
13052 		printf("invalid vf_id %d\n", res->vf_id);
13053 		break;
13054 	case -ENODEV:
13055 		printf("invalid port_id %d\n", res->port_id);
13056 		break;
13057 	case -ENOTSUP:
13058 		printf("function not implemented\n");
13059 		break;
13060 	default:
13061 		printf("programming error: (%s)\n", strerror(-ret));
13062 	}
13063 
13064 	printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
13065 		nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
13066 
13067 	printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
13068 	       "%-"PRIu64"\n",
13069 	       stats.ipackets, stats.imissed, stats.ibytes);
13070 	printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
13071 	printf("  RX-nombuf:  %-10"PRIu64"\n",
13072 	       stats.rx_nombuf);
13073 	printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
13074 	       "%-"PRIu64"\n",
13075 	       stats.opackets, stats.oerrors, stats.obytes);
13076 
13077 	printf("  %s############################%s\n",
13078 			       nic_stats_border, nic_stats_border);
13079 }
13080 
13081 cmdline_parse_inst_t cmd_show_vf_stats = {
13082 	.f = cmd_show_vf_stats_parsed,
13083 	.data = NULL,
13084 	.help_str = "show vf stats <port_id> <vf_id>",
13085 	.tokens = {
13086 		(void *)&cmd_show_vf_stats_show,
13087 		(void *)&cmd_show_vf_stats_vf,
13088 		(void *)&cmd_show_vf_stats_stats,
13089 		(void *)&cmd_show_vf_stats_port_id,
13090 		(void *)&cmd_show_vf_stats_vf_id,
13091 		NULL,
13092 	},
13093 };
13094 
13095 /* clear vf stats */
13096 
13097 /* Common result structure for clear vf stats */
13098 struct cmd_clear_vf_stats_result {
13099 	cmdline_fixed_string_t clear;
13100 	cmdline_fixed_string_t vf;
13101 	cmdline_fixed_string_t stats;
13102 	uint8_t port_id;
13103 	uint16_t vf_id;
13104 };
13105 
13106 /* Common CLI fields clear vf stats*/
13107 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
13108 	TOKEN_STRING_INITIALIZER
13109 		(struct cmd_clear_vf_stats_result,
13110 		 clear, "clear");
13111 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
13112 	TOKEN_STRING_INITIALIZER
13113 		(struct cmd_clear_vf_stats_result,
13114 		 vf, "vf");
13115 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
13116 	TOKEN_STRING_INITIALIZER
13117 		(struct cmd_clear_vf_stats_result,
13118 		 stats, "stats");
13119 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
13120 	TOKEN_NUM_INITIALIZER
13121 		(struct cmd_clear_vf_stats_result,
13122 		 port_id, UINT8);
13123 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
13124 	TOKEN_NUM_INITIALIZER
13125 		(struct cmd_clear_vf_stats_result,
13126 		 vf_id, UINT16);
13127 
13128 static void
13129 cmd_clear_vf_stats_parsed(
13130 	void *parsed_result,
13131 	__attribute__((unused)) struct cmdline *cl,
13132 	__attribute__((unused)) void *data)
13133 {
13134 	struct cmd_clear_vf_stats_result *res = parsed_result;
13135 	int ret = -ENOTSUP;
13136 
13137 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13138 		return;
13139 
13140 #ifdef RTE_LIBRTE_I40E_PMD
13141 	ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
13142 					  res->vf_id);
13143 #endif
13144 
13145 	switch (ret) {
13146 	case 0:
13147 		break;
13148 	case -EINVAL:
13149 		printf("invalid vf_id %d\n", res->vf_id);
13150 		break;
13151 	case -ENODEV:
13152 		printf("invalid port_id %d\n", res->port_id);
13153 		break;
13154 	case -ENOTSUP:
13155 		printf("function not implemented\n");
13156 		break;
13157 	default:
13158 		printf("programming error: (%s)\n", strerror(-ret));
13159 	}
13160 }
13161 
13162 cmdline_parse_inst_t cmd_clear_vf_stats = {
13163 	.f = cmd_clear_vf_stats_parsed,
13164 	.data = NULL,
13165 	.help_str = "clear vf stats <port_id> <vf_id>",
13166 	.tokens = {
13167 		(void *)&cmd_clear_vf_stats_clear,
13168 		(void *)&cmd_clear_vf_stats_vf,
13169 		(void *)&cmd_clear_vf_stats_stats,
13170 		(void *)&cmd_clear_vf_stats_port_id,
13171 		(void *)&cmd_clear_vf_stats_vf_id,
13172 		NULL,
13173 	},
13174 };
13175 
13176 /* ptype mapping get */
13177 
13178 /* Common result structure for ptype mapping get */
13179 struct cmd_ptype_mapping_get_result {
13180 	cmdline_fixed_string_t ptype;
13181 	cmdline_fixed_string_t mapping;
13182 	cmdline_fixed_string_t get;
13183 	uint8_t port_id;
13184 	uint8_t valid_only;
13185 };
13186 
13187 /* Common CLI fields for ptype mapping get */
13188 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
13189 	TOKEN_STRING_INITIALIZER
13190 		(struct cmd_ptype_mapping_get_result,
13191 		 ptype, "ptype");
13192 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
13193 	TOKEN_STRING_INITIALIZER
13194 		(struct cmd_ptype_mapping_get_result,
13195 		 mapping, "mapping");
13196 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
13197 	TOKEN_STRING_INITIALIZER
13198 		(struct cmd_ptype_mapping_get_result,
13199 		 get, "get");
13200 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
13201 	TOKEN_NUM_INITIALIZER
13202 		(struct cmd_ptype_mapping_get_result,
13203 		 port_id, UINT8);
13204 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
13205 	TOKEN_NUM_INITIALIZER
13206 		(struct cmd_ptype_mapping_get_result,
13207 		 valid_only, UINT8);
13208 
13209 static void
13210 cmd_ptype_mapping_get_parsed(
13211 	void *parsed_result,
13212 	__attribute__((unused)) struct cmdline *cl,
13213 	__attribute__((unused)) void *data)
13214 {
13215 	struct cmd_ptype_mapping_get_result *res = parsed_result;
13216 	int ret = -ENOTSUP;
13217 #ifdef RTE_LIBRTE_I40E_PMD
13218 	int max_ptype_num = 256;
13219 	struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
13220 	uint16_t count;
13221 	int i;
13222 #endif
13223 
13224 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13225 		return;
13226 
13227 #ifdef RTE_LIBRTE_I40E_PMD
13228 	ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
13229 					mapping,
13230 					max_ptype_num,
13231 					&count,
13232 					res->valid_only);
13233 #endif
13234 
13235 	switch (ret) {
13236 	case 0:
13237 		break;
13238 	case -ENODEV:
13239 		printf("invalid port_id %d\n", res->port_id);
13240 		break;
13241 	case -ENOTSUP:
13242 		printf("function not implemented\n");
13243 		break;
13244 	default:
13245 		printf("programming error: (%s)\n", strerror(-ret));
13246 	}
13247 
13248 #ifdef RTE_LIBRTE_I40E_PMD
13249 	if (!ret) {
13250 		for (i = 0; i < count; i++)
13251 			printf("%3d\t0x%08x\n",
13252 				mapping[i].hw_ptype, mapping[i].sw_ptype);
13253 	}
13254 #endif
13255 }
13256 
13257 cmdline_parse_inst_t cmd_ptype_mapping_get = {
13258 	.f = cmd_ptype_mapping_get_parsed,
13259 	.data = NULL,
13260 	.help_str = "ptype mapping get <port_id> <valid_only>",
13261 	.tokens = {
13262 		(void *)&cmd_ptype_mapping_get_ptype,
13263 		(void *)&cmd_ptype_mapping_get_mapping,
13264 		(void *)&cmd_ptype_mapping_get_get,
13265 		(void *)&cmd_ptype_mapping_get_port_id,
13266 		(void *)&cmd_ptype_mapping_get_valid_only,
13267 		NULL,
13268 	},
13269 };
13270 
13271 /* ptype mapping replace */
13272 
13273 /* Common result structure for ptype mapping replace */
13274 struct cmd_ptype_mapping_replace_result {
13275 	cmdline_fixed_string_t ptype;
13276 	cmdline_fixed_string_t mapping;
13277 	cmdline_fixed_string_t replace;
13278 	uint8_t port_id;
13279 	uint32_t target;
13280 	uint8_t mask;
13281 	uint32_t pkt_type;
13282 };
13283 
13284 /* Common CLI fields for ptype mapping replace */
13285 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
13286 	TOKEN_STRING_INITIALIZER
13287 		(struct cmd_ptype_mapping_replace_result,
13288 		 ptype, "ptype");
13289 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
13290 	TOKEN_STRING_INITIALIZER
13291 		(struct cmd_ptype_mapping_replace_result,
13292 		 mapping, "mapping");
13293 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
13294 	TOKEN_STRING_INITIALIZER
13295 		(struct cmd_ptype_mapping_replace_result,
13296 		 replace, "replace");
13297 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
13298 	TOKEN_NUM_INITIALIZER
13299 		(struct cmd_ptype_mapping_replace_result,
13300 		 port_id, UINT8);
13301 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
13302 	TOKEN_NUM_INITIALIZER
13303 		(struct cmd_ptype_mapping_replace_result,
13304 		 target, UINT32);
13305 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
13306 	TOKEN_NUM_INITIALIZER
13307 		(struct cmd_ptype_mapping_replace_result,
13308 		 mask, UINT8);
13309 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
13310 	TOKEN_NUM_INITIALIZER
13311 		(struct cmd_ptype_mapping_replace_result,
13312 		 pkt_type, UINT32);
13313 
13314 static void
13315 cmd_ptype_mapping_replace_parsed(
13316 	void *parsed_result,
13317 	__attribute__((unused)) struct cmdline *cl,
13318 	__attribute__((unused)) void *data)
13319 {
13320 	struct cmd_ptype_mapping_replace_result *res = parsed_result;
13321 	int ret = -ENOTSUP;
13322 
13323 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13324 		return;
13325 
13326 #ifdef RTE_LIBRTE_I40E_PMD
13327 	ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
13328 					res->target,
13329 					res->mask,
13330 					res->pkt_type);
13331 #endif
13332 
13333 	switch (ret) {
13334 	case 0:
13335 		break;
13336 	case -EINVAL:
13337 		printf("invalid ptype 0x%8x or 0x%8x\n",
13338 				res->target, res->pkt_type);
13339 		break;
13340 	case -ENODEV:
13341 		printf("invalid port_id %d\n", res->port_id);
13342 		break;
13343 	case -ENOTSUP:
13344 		printf("function not implemented\n");
13345 		break;
13346 	default:
13347 		printf("programming error: (%s)\n", strerror(-ret));
13348 	}
13349 }
13350 
13351 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
13352 	.f = cmd_ptype_mapping_replace_parsed,
13353 	.data = NULL,
13354 	.help_str =
13355 		"ptype mapping replace <port_id> <target> <mask> <pkt_type>",
13356 	.tokens = {
13357 		(void *)&cmd_ptype_mapping_replace_ptype,
13358 		(void *)&cmd_ptype_mapping_replace_mapping,
13359 		(void *)&cmd_ptype_mapping_replace_replace,
13360 		(void *)&cmd_ptype_mapping_replace_port_id,
13361 		(void *)&cmd_ptype_mapping_replace_target,
13362 		(void *)&cmd_ptype_mapping_replace_mask,
13363 		(void *)&cmd_ptype_mapping_replace_pkt_type,
13364 		NULL,
13365 	},
13366 };
13367 
13368 /* ptype mapping reset */
13369 
13370 /* Common result structure for ptype mapping reset */
13371 struct cmd_ptype_mapping_reset_result {
13372 	cmdline_fixed_string_t ptype;
13373 	cmdline_fixed_string_t mapping;
13374 	cmdline_fixed_string_t reset;
13375 	uint8_t port_id;
13376 };
13377 
13378 /* Common CLI fields for ptype mapping reset*/
13379 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
13380 	TOKEN_STRING_INITIALIZER
13381 		(struct cmd_ptype_mapping_reset_result,
13382 		 ptype, "ptype");
13383 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
13384 	TOKEN_STRING_INITIALIZER
13385 		(struct cmd_ptype_mapping_reset_result,
13386 		 mapping, "mapping");
13387 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
13388 	TOKEN_STRING_INITIALIZER
13389 		(struct cmd_ptype_mapping_reset_result,
13390 		 reset, "reset");
13391 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
13392 	TOKEN_NUM_INITIALIZER
13393 		(struct cmd_ptype_mapping_reset_result,
13394 		 port_id, UINT8);
13395 
13396 static void
13397 cmd_ptype_mapping_reset_parsed(
13398 	void *parsed_result,
13399 	__attribute__((unused)) struct cmdline *cl,
13400 	__attribute__((unused)) void *data)
13401 {
13402 	struct cmd_ptype_mapping_reset_result *res = parsed_result;
13403 	int ret = -ENOTSUP;
13404 
13405 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13406 		return;
13407 
13408 #ifdef RTE_LIBRTE_I40E_PMD
13409 	ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
13410 #endif
13411 
13412 	switch (ret) {
13413 	case 0:
13414 		break;
13415 	case -ENODEV:
13416 		printf("invalid port_id %d\n", res->port_id);
13417 		break;
13418 	case -ENOTSUP:
13419 		printf("function not implemented\n");
13420 		break;
13421 	default:
13422 		printf("programming error: (%s)\n", strerror(-ret));
13423 	}
13424 }
13425 
13426 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
13427 	.f = cmd_ptype_mapping_reset_parsed,
13428 	.data = NULL,
13429 	.help_str = "ptype mapping reset <port_id>",
13430 	.tokens = {
13431 		(void *)&cmd_ptype_mapping_reset_ptype,
13432 		(void *)&cmd_ptype_mapping_reset_mapping,
13433 		(void *)&cmd_ptype_mapping_reset_reset,
13434 		(void *)&cmd_ptype_mapping_reset_port_id,
13435 		NULL,
13436 	},
13437 };
13438 
13439 /* ptype mapping update */
13440 
13441 /* Common result structure for ptype mapping update */
13442 struct cmd_ptype_mapping_update_result {
13443 	cmdline_fixed_string_t ptype;
13444 	cmdline_fixed_string_t mapping;
13445 	cmdline_fixed_string_t reset;
13446 	uint8_t port_id;
13447 	uint8_t hw_ptype;
13448 	uint32_t sw_ptype;
13449 };
13450 
13451 /* Common CLI fields for ptype mapping update*/
13452 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
13453 	TOKEN_STRING_INITIALIZER
13454 		(struct cmd_ptype_mapping_update_result,
13455 		 ptype, "ptype");
13456 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
13457 	TOKEN_STRING_INITIALIZER
13458 		(struct cmd_ptype_mapping_update_result,
13459 		 mapping, "mapping");
13460 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
13461 	TOKEN_STRING_INITIALIZER
13462 		(struct cmd_ptype_mapping_update_result,
13463 		 reset, "update");
13464 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
13465 	TOKEN_NUM_INITIALIZER
13466 		(struct cmd_ptype_mapping_update_result,
13467 		 port_id, UINT8);
13468 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
13469 	TOKEN_NUM_INITIALIZER
13470 		(struct cmd_ptype_mapping_update_result,
13471 		 hw_ptype, UINT8);
13472 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
13473 	TOKEN_NUM_INITIALIZER
13474 		(struct cmd_ptype_mapping_update_result,
13475 		 sw_ptype, UINT32);
13476 
13477 static void
13478 cmd_ptype_mapping_update_parsed(
13479 	void *parsed_result,
13480 	__attribute__((unused)) struct cmdline *cl,
13481 	__attribute__((unused)) void *data)
13482 {
13483 	struct cmd_ptype_mapping_update_result *res = parsed_result;
13484 	int ret = -ENOTSUP;
13485 #ifdef RTE_LIBRTE_I40E_PMD
13486 	struct rte_pmd_i40e_ptype_mapping mapping;
13487 #endif
13488 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13489 		return;
13490 
13491 #ifdef RTE_LIBRTE_I40E_PMD
13492 	mapping.hw_ptype = res->hw_ptype;
13493 	mapping.sw_ptype = res->sw_ptype;
13494 	ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
13495 						&mapping,
13496 						1,
13497 						0);
13498 #endif
13499 
13500 	switch (ret) {
13501 	case 0:
13502 		break;
13503 	case -EINVAL:
13504 		printf("invalid ptype 0x%8x\n", res->sw_ptype);
13505 		break;
13506 	case -ENODEV:
13507 		printf("invalid port_id %d\n", res->port_id);
13508 		break;
13509 	case -ENOTSUP:
13510 		printf("function not implemented\n");
13511 		break;
13512 	default:
13513 		printf("programming error: (%s)\n", strerror(-ret));
13514 	}
13515 }
13516 
13517 cmdline_parse_inst_t cmd_ptype_mapping_update = {
13518 	.f = cmd_ptype_mapping_update_parsed,
13519 	.data = NULL,
13520 	.help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
13521 	.tokens = {
13522 		(void *)&cmd_ptype_mapping_update_ptype,
13523 		(void *)&cmd_ptype_mapping_update_mapping,
13524 		(void *)&cmd_ptype_mapping_update_update,
13525 		(void *)&cmd_ptype_mapping_update_port_id,
13526 		(void *)&cmd_ptype_mapping_update_hw_ptype,
13527 		(void *)&cmd_ptype_mapping_update_sw_ptype,
13528 		NULL,
13529 	},
13530 };
13531 
13532 /* ******************************************************************************** */
13533 
13534 /* list of instructions */
13535 cmdline_parse_ctx_t main_ctx[] = {
13536 	(cmdline_parse_inst_t *)&cmd_help_brief,
13537 	(cmdline_parse_inst_t *)&cmd_help_long,
13538 	(cmdline_parse_inst_t *)&cmd_quit,
13539 	(cmdline_parse_inst_t *)&cmd_showport,
13540 	(cmdline_parse_inst_t *)&cmd_showqueue,
13541 	(cmdline_parse_inst_t *)&cmd_showportall,
13542 	(cmdline_parse_inst_t *)&cmd_showcfg,
13543 	(cmdline_parse_inst_t *)&cmd_start,
13544 	(cmdline_parse_inst_t *)&cmd_start_tx_first,
13545 	(cmdline_parse_inst_t *)&cmd_start_tx_first_n,
13546 	(cmdline_parse_inst_t *)&cmd_set_link_up,
13547 	(cmdline_parse_inst_t *)&cmd_set_link_down,
13548 	(cmdline_parse_inst_t *)&cmd_reset,
13549 	(cmdline_parse_inst_t *)&cmd_set_numbers,
13550 	(cmdline_parse_inst_t *)&cmd_set_txpkts,
13551 	(cmdline_parse_inst_t *)&cmd_set_txsplit,
13552 	(cmdline_parse_inst_t *)&cmd_set_fwd_list,
13553 	(cmdline_parse_inst_t *)&cmd_set_fwd_mask,
13554 	(cmdline_parse_inst_t *)&cmd_set_fwd_mode,
13555 	(cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
13556 	(cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
13557 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
13558 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
13559 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
13560 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
13561 	(cmdline_parse_inst_t *)&cmd_set_flush_rx,
13562 	(cmdline_parse_inst_t *)&cmd_set_link_check,
13563 #ifdef RTE_NIC_BYPASS
13564 	(cmdline_parse_inst_t *)&cmd_set_bypass_mode,
13565 	(cmdline_parse_inst_t *)&cmd_set_bypass_event,
13566 	(cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
13567 	(cmdline_parse_inst_t *)&cmd_show_bypass_config,
13568 #endif
13569 #ifdef RTE_LIBRTE_PMD_BOND
13570 	(cmdline_parse_inst_t *) &cmd_set_bonding_mode,
13571 	(cmdline_parse_inst_t *) &cmd_show_bonding_config,
13572 	(cmdline_parse_inst_t *) &cmd_set_bonding_primary,
13573 	(cmdline_parse_inst_t *) &cmd_add_bonding_slave,
13574 	(cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
13575 	(cmdline_parse_inst_t *) &cmd_create_bonded_device,
13576 	(cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
13577 	(cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
13578 	(cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
13579 #endif
13580 	(cmdline_parse_inst_t *)&cmd_vlan_offload,
13581 	(cmdline_parse_inst_t *)&cmd_vlan_tpid,
13582 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
13583 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
13584 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set,
13585 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
13586 	(cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
13587 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
13588 	(cmdline_parse_inst_t *)&cmd_csum_set,
13589 	(cmdline_parse_inst_t *)&cmd_csum_show,
13590 	(cmdline_parse_inst_t *)&cmd_csum_tunnel,
13591 	(cmdline_parse_inst_t *)&cmd_tso_set,
13592 	(cmdline_parse_inst_t *)&cmd_tso_show,
13593 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
13594 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
13595 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
13596 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
13597 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
13598 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
13599 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
13600 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
13601 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
13602 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
13603 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
13604 	(cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
13605 	(cmdline_parse_inst_t *)&cmd_config_dcb,
13606 	(cmdline_parse_inst_t *)&cmd_read_reg,
13607 	(cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
13608 	(cmdline_parse_inst_t *)&cmd_read_reg_bit,
13609 	(cmdline_parse_inst_t *)&cmd_write_reg,
13610 	(cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
13611 	(cmdline_parse_inst_t *)&cmd_write_reg_bit,
13612 	(cmdline_parse_inst_t *)&cmd_read_rxd_txd,
13613 	(cmdline_parse_inst_t *)&cmd_stop,
13614 	(cmdline_parse_inst_t *)&cmd_mac_addr,
13615 	(cmdline_parse_inst_t *)&cmd_set_qmap,
13616 	(cmdline_parse_inst_t *)&cmd_operate_port,
13617 	(cmdline_parse_inst_t *)&cmd_operate_specific_port,
13618 	(cmdline_parse_inst_t *)&cmd_operate_attach_port,
13619 	(cmdline_parse_inst_t *)&cmd_operate_detach_port,
13620 	(cmdline_parse_inst_t *)&cmd_config_speed_all,
13621 	(cmdline_parse_inst_t *)&cmd_config_speed_specific,
13622 	(cmdline_parse_inst_t *)&cmd_config_rx_tx,
13623 	(cmdline_parse_inst_t *)&cmd_config_mtu,
13624 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
13625 	(cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
13626 	(cmdline_parse_inst_t *)&cmd_config_rss,
13627 	(cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
13628 	(cmdline_parse_inst_t *)&cmd_config_txqflags,
13629 	(cmdline_parse_inst_t *)&cmd_config_rss_reta,
13630 	(cmdline_parse_inst_t *)&cmd_showport_reta,
13631 	(cmdline_parse_inst_t *)&cmd_config_burst,
13632 	(cmdline_parse_inst_t *)&cmd_config_thresh,
13633 	(cmdline_parse_inst_t *)&cmd_config_threshold,
13634 	(cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
13635 	(cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
13636 	(cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
13637 	(cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
13638 	(cmdline_parse_inst_t *)&cmd_queue_rate_limit,
13639 	(cmdline_parse_inst_t *)&cmd_tunnel_filter,
13640 	(cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
13641 	(cmdline_parse_inst_t *)&cmd_global_config,
13642 	(cmdline_parse_inst_t *)&cmd_set_mirror_mask,
13643 	(cmdline_parse_inst_t *)&cmd_set_mirror_link,
13644 	(cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
13645 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash,
13646 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
13647 	(cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
13648 	(cmdline_parse_inst_t *)&cmd_dump,
13649 	(cmdline_parse_inst_t *)&cmd_dump_one,
13650 	(cmdline_parse_inst_t *)&cmd_ethertype_filter,
13651 	(cmdline_parse_inst_t *)&cmd_syn_filter,
13652 	(cmdline_parse_inst_t *)&cmd_2tuple_filter,
13653 	(cmdline_parse_inst_t *)&cmd_5tuple_filter,
13654 	(cmdline_parse_inst_t *)&cmd_flex_filter,
13655 	(cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
13656 	(cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
13657 	(cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
13658 	(cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
13659 	(cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
13660 	(cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
13661 	(cmdline_parse_inst_t *)&cmd_flush_flow_director,
13662 	(cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
13663 	(cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
13664 	(cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
13665 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
13666 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
13667 	(cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
13668 	(cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
13669 	(cmdline_parse_inst_t *)&cmd_get_hash_global_config,
13670 	(cmdline_parse_inst_t *)&cmd_set_hash_global_config,
13671 	(cmdline_parse_inst_t *)&cmd_set_hash_input_set,
13672 	(cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
13673 	(cmdline_parse_inst_t *)&cmd_flow,
13674 	(cmdline_parse_inst_t *)&cmd_mcast_addr,
13675 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
13676 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
13677 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
13678 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
13679 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
13680 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
13681 	(cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
13682 	(cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
13683 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
13684 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
13685 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
13686 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
13687 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
13688 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
13689 	(cmdline_parse_inst_t *)&cmd_set_tx_loopback,
13690 #ifdef RTE_LIBRTE_IXGBE_PMD
13691 	(cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
13692 	(cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
13693 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
13694 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
13695 	(cmdline_parse_inst_t *)&cmd_set_macsec_sc,
13696 	(cmdline_parse_inst_t *)&cmd_set_macsec_sa,
13697 	(cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
13698 	(cmdline_parse_inst_t *)&cmd_set_vf_traffic,
13699 	(cmdline_parse_inst_t *)&cmd_vf_rate_limit,
13700 #endif
13701 	(cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
13702 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
13703 	(cmdline_parse_inst_t *)&cmd_set_vf_promisc,
13704 	(cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
13705 	(cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
13706 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
13707 	(cmdline_parse_inst_t *)&cmd_vf_max_bw,
13708 	(cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
13709 	(cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
13710 	(cmdline_parse_inst_t *)&cmd_strict_link_prio,
13711 	(cmdline_parse_inst_t *)&cmd_tc_min_bw,
13712 	(cmdline_parse_inst_t *)&cmd_ddp_add,
13713 	(cmdline_parse_inst_t *)&cmd_ddp_get_list,
13714 	(cmdline_parse_inst_t *)&cmd_show_vf_stats,
13715 	(cmdline_parse_inst_t *)&cmd_clear_vf_stats,
13716 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
13717 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
13718 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
13719 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
13720 	NULL,
13721 };
13722 
13723 /* read cmdline commands from file */
13724 void
13725 cmdline_read_from_file(const char *filename)
13726 {
13727 	struct cmdline *cl;
13728 
13729 	cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
13730 	if (cl == NULL) {
13731 		printf("Failed to create file based cmdline context: %s\n",
13732 		       filename);
13733 		return;
13734 	}
13735 
13736 	cmdline_interact(cl);
13737 	cmdline_quit(cl);
13738 
13739 	cmdline_free(cl);
13740 
13741 	printf("Read CLI commands from %s\n", filename);
13742 }
13743 
13744 /* prompt function, called from main on MASTER lcore */
13745 void
13746 prompt(void)
13747 {
13748 	/* initialize non-constant commands */
13749 	cmd_set_fwd_mode_init();
13750 	cmd_set_fwd_retry_mode_init();
13751 
13752 	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
13753 	if (testpmd_cl == NULL)
13754 		return;
13755 	cmdline_interact(testpmd_cl);
13756 	cmdline_stdin_exit(testpmd_cl);
13757 }
13758 
13759 void
13760 prompt_exit(void)
13761 {
13762 	if (testpmd_cl != NULL)
13763 		cmdline_quit(testpmd_cl);
13764 }
13765 
13766 static void
13767 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
13768 {
13769 	if (id == (portid_t)RTE_PORT_ALL) {
13770 		portid_t pid;
13771 
13772 		RTE_ETH_FOREACH_DEV(pid) {
13773 			/* check if need_reconfig has been set to 1 */
13774 			if (ports[pid].need_reconfig == 0)
13775 				ports[pid].need_reconfig = dev;
13776 			/* check if need_reconfig_queues has been set to 1 */
13777 			if (ports[pid].need_reconfig_queues == 0)
13778 				ports[pid].need_reconfig_queues = queue;
13779 		}
13780 	} else if (!port_id_is_invalid(id, DISABLED_WARN)) {
13781 		/* check if need_reconfig has been set to 1 */
13782 		if (ports[id].need_reconfig == 0)
13783 			ports[id].need_reconfig = dev;
13784 		/* check if need_reconfig_queues has been set to 1 */
13785 		if (ports[id].need_reconfig_queues == 0)
13786 			ports[id].need_reconfig_queues = queue;
13787 	}
13788 }
13789