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