xref: /dpdk/app/test-pmd/cmdline.c (revision a103a97e7191179ad6a451ce85182df2ecb10c26)
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 <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51 
52 #include <sys/queue.h>
53 
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.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 			"show port (port_id) pctype mapping\n"
235 			"    Get flow ptype to pctype mapping on a port\n\n"
236 
237 		);
238 	}
239 
240 	if (show_all || !strcmp(res->section, "config")) {
241 		cmdline_printf(
242 			cl,
243 			"\n"
244 			"Configuration:\n"
245 			"--------------\n"
246 			"Configuration changes only become active when"
247 			" forwarding is started/restarted.\n\n"
248 
249 			"set default\n"
250 			"    Reset forwarding to the default configuration.\n\n"
251 
252 			"set verbose (level)\n"
253 			"    Set the debug verbosity level X.\n\n"
254 
255 			"set nbport (num)\n"
256 			"    Set number of ports.\n\n"
257 
258 			"set nbcore (num)\n"
259 			"    Set number of cores.\n\n"
260 
261 			"set coremask (mask)\n"
262 			"    Set the forwarding cores hexadecimal mask.\n\n"
263 
264 			"set portmask (mask)\n"
265 			"    Set the forwarding ports hexadecimal mask.\n\n"
266 
267 			"set burst (num)\n"
268 			"    Set number of packets per burst.\n\n"
269 
270 			"set burst tx delay (microseconds) retry (num)\n"
271 			"    Set the transmit delay time and number of retries,"
272 			" effective when retry is enabled.\n\n"
273 
274 			"set txpkts (x[,y]*)\n"
275 			"    Set the length of each segment of TXONLY"
276 			" and optionally CSUM packets.\n\n"
277 
278 			"set txsplit (off|on|rand)\n"
279 			"    Set the split policy for the TX packets."
280 			" Right now only applicable for CSUM and TXONLY"
281 			" modes\n\n"
282 
283 			"set corelist (x[,y]*)\n"
284 			"    Set the list of forwarding cores.\n\n"
285 
286 			"set portlist (x[,y]*)\n"
287 			"    Set the list of forwarding ports.\n\n"
288 
289 			"set tx loopback (port_id) (on|off)\n"
290 			"    Enable or disable tx loopback.\n\n"
291 
292 			"set all queues drop (port_id) (on|off)\n"
293 			"    Set drop enable bit for all queues.\n\n"
294 
295 			"set vf split drop (port_id) (vf_id) (on|off)\n"
296 			"    Set split drop enable bit for a VF from the PF.\n\n"
297 
298 			"set vf mac antispoof (port_id) (vf_id) (on|off).\n"
299 			"    Set MAC antispoof for a VF from the PF.\n\n"
300 
301 			"set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
302 			"    Enable MACsec offload.\n\n"
303 
304 			"set macsec offload (port_id) off\n"
305 			"    Disable MACsec offload.\n\n"
306 
307 			"set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
308 			"    Configure MACsec secure connection (SC).\n\n"
309 
310 			"set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
311 			"    Configure MACsec secure association (SA).\n\n"
312 
313 			"set vf broadcast (port_id) (vf_id) (on|off)\n"
314 			"    Set VF broadcast for a VF from the PF.\n\n"
315 
316 			"vlan set strip (on|off) (port_id)\n"
317 			"    Set the VLAN strip on a port.\n\n"
318 
319 			"vlan set stripq (on|off) (port_id,queue_id)\n"
320 			"    Set the VLAN strip for a queue on a port.\n\n"
321 
322 			"set vf vlan stripq (port_id) (vf_id) (on|off)\n"
323 			"    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
324 
325 			"set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
326 			"    Set VLAN insert for a VF from the PF.\n\n"
327 
328 			"set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
329 			"    Set VLAN antispoof for a VF from the PF.\n\n"
330 
331 			"set vf vlan tag (port_id) (vf_id) (on|off)\n"
332 			"    Set VLAN tag for a VF from the PF.\n\n"
333 
334 			"set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
335 			"    Set a VF's max bandwidth(Mbps).\n\n"
336 
337 			"set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
338 			"    Set all TCs' min bandwidth(%%) on a VF.\n\n"
339 
340 			"set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
341 			"    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
342 
343 			"set tx strict-link-priority (port_id) (tc_bitmap)\n"
344 			"    Set some TCs' strict link priority mode on a physical port.\n\n"
345 
346 			"set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
347 			"    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
348 
349 			"vlan set filter (on|off) (port_id)\n"
350 			"    Set the VLAN filter on a port.\n\n"
351 
352 			"vlan set qinq (on|off) (port_id)\n"
353 			"    Set the VLAN QinQ (extended queue in queue)"
354 			" on a port.\n\n"
355 
356 			"vlan set (inner|outer) tpid (value) (port_id)\n"
357 			"    Set the VLAN TPID for Packet Filtering on"
358 			" a port\n\n"
359 
360 			"rx_vlan add (vlan_id|all) (port_id)\n"
361 			"    Add a vlan_id, or all identifiers, to the set"
362 			" of VLAN identifiers filtered by port_id.\n\n"
363 
364 			"rx_vlan rm (vlan_id|all) (port_id)\n"
365 			"    Remove a vlan_id, or all identifiers, from the set"
366 			" of VLAN identifiers filtered by port_id.\n\n"
367 
368 			"rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
369 			"    Add a vlan_id, to the set of VLAN identifiers"
370 			"filtered for VF(s) from port_id.\n\n"
371 
372 			"rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
373 			"    Remove a vlan_id, to the set of VLAN identifiers"
374 			"filtered for VF(s) from port_id.\n\n"
375 
376 			"tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
377 			"(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
378 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
379 			"   add a tunnel filter of a port.\n\n"
380 
381 			"tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
382 			"(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
383 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
384 			"   remove a tunnel filter of a port.\n\n"
385 
386 			"rx_vxlan_port add (udp_port) (port_id)\n"
387 			"    Add an UDP port for VXLAN packet filter on a port\n\n"
388 
389 			"rx_vxlan_port rm (udp_port) (port_id)\n"
390 			"    Remove an UDP port for VXLAN packet filter on a port\n\n"
391 
392 			"tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
393 			"    Set hardware insertion of VLAN IDs (single or double VLAN "
394 			"depends on the number of VLAN IDs) in packets sent on a port.\n\n"
395 
396 			"tx_vlan set pvid port_id vlan_id (on|off)\n"
397 			"    Set port based TX VLAN insertion.\n\n"
398 
399 			"tx_vlan reset (port_id)\n"
400 			"    Disable hardware insertion of a VLAN header in"
401 			" packets sent on a port.\n\n"
402 
403 			"csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
404 			"    Select hardware or software calculation of the"
405 			" checksum when transmitting a packet using the"
406 			" csum forward engine.\n"
407 			"    ip|udp|tcp|sctp always concern the inner layer.\n"
408 			"    outer-ip concerns the outer IP layer in"
409 			" case the packet is recognized as a tunnel packet by"
410 			" the forward engine (vxlan, gre and ipip are supported)\n"
411 			"    Please check the NIC datasheet for HW limits.\n\n"
412 
413 			"csum parse-tunnel (on|off) (tx_port_id)\n"
414 			"    If disabled, treat tunnel packets as non-tunneled"
415 			" packets (treat inner headers as payload). The port\n"
416 			"    argument is the port used for TX in csum forward"
417 			" engine.\n\n"
418 
419 			"csum show (port_id)\n"
420 			"    Display tx checksum offload configuration\n\n"
421 
422 			"tso set (segsize) (portid)\n"
423 			"    Enable TCP Segmentation Offload in csum forward"
424 			" engine.\n"
425 			"    Please check the NIC datasheet for HW limits.\n\n"
426 
427 			"tso show (portid)"
428 			"    Display the status of TCP Segmentation Offload.\n\n"
429 
430 			"gro (on|off) (port_id)"
431 			"    Enable or disable Generic Receive Offload in"
432 			" csum forwarding engine.\n\n"
433 
434 			"gro set (max_flow_num) (max_item_num_per_flow) (port_id)\n"
435 			"    Set max flow number and max packet number per-flow"
436 			" for GRO.\n\n"
437 
438 			"set fwd (%s)\n"
439 			"    Set packet forwarding mode.\n\n"
440 
441 			"mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
442 			"    Add a MAC address on port_id.\n\n"
443 
444 			"mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
445 			"    Remove a MAC address from port_id.\n\n"
446 
447 			"mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
448 			"    Set the default MAC address for port_id.\n\n"
449 
450 			"mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
451 			"    Add a MAC address for a VF on the port.\n\n"
452 
453 			"set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
454 			"    Set the MAC address for a VF from the PF.\n\n"
455 
456 			"set port (port_id) uta (mac_address|all) (on|off)\n"
457 			"    Add/Remove a or all unicast hash filter(s)"
458 			"from port X.\n\n"
459 
460 			"set promisc (port_id|all) (on|off)\n"
461 			"    Set the promiscuous mode on port_id, or all.\n\n"
462 
463 			"set allmulti (port_id|all) (on|off)\n"
464 			"    Set the allmulti mode on port_id, or all.\n\n"
465 
466 			"set vf promisc (port_id) (vf_id) (on|off)\n"
467 			"    Set unicast promiscuous mode for a VF from the PF.\n\n"
468 
469 			"set vf allmulti (port_id) (vf_id) (on|off)\n"
470 			"    Set multicast promiscuous mode for a VF from the PF.\n\n"
471 
472 			"set flow_ctrl rx (on|off) tx (on|off) (high_water)"
473 			" (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
474 			" (on|off) autoneg (on|off) (port_id)\n"
475 			"set flow_ctrl rx (on|off) (portid)\n"
476 			"set flow_ctrl tx (on|off) (portid)\n"
477 			"set flow_ctrl high_water (high_water) (portid)\n"
478 			"set flow_ctrl low_water (low_water) (portid)\n"
479 			"set flow_ctrl pause_time (pause_time) (portid)\n"
480 			"set flow_ctrl send_xon (send_xon) (portid)\n"
481 			"set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
482 			"set flow_ctrl autoneg (on|off) (port_id)\n"
483 			"    Set the link flow control parameter on a port.\n\n"
484 
485 			"set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
486 			" (low_water) (pause_time) (priority) (port_id)\n"
487 			"    Set the priority flow control parameter on a"
488 			" port.\n\n"
489 
490 			"set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
491 			"    Set statistics mapping (qmapping 0..15) for RX/TX"
492 			" queue on port.\n"
493 			"    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
494 			" on port 0 to mapping 5.\n\n"
495 
496 			"set port (port_id) vf (vf_id) rx|tx on|off\n"
497 			"    Enable/Disable a VF receive/tranmit from a port\n\n"
498 
499 			"set port (port_id) vf (vf_id) (mac_addr)"
500 			" (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
501 			"   Add/Remove unicast or multicast MAC addr filter"
502 			" for a VF.\n\n"
503 
504 			"set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
505 			"|MPE) (on|off)\n"
506 			"    AUPE:accepts untagged VLAN;"
507 			"ROPE:accept unicast hash\n\n"
508 			"    BAM:accepts broadcast packets;"
509 			"MPE:accepts all multicast packets\n\n"
510 			"    Enable/Disable a VF receive mode of a port\n\n"
511 
512 			"set port (port_id) queue (queue_id) rate (rate_num)\n"
513 			"    Set rate limit for a queue of a port\n\n"
514 
515 			"set port (port_id) vf (vf_id) rate (rate_num) "
516 			"queue_mask (queue_mask_value)\n"
517 			"    Set rate limit for queues in VF of a port\n\n"
518 
519 			"set port (port_id) mirror-rule (rule_id)"
520 			" (pool-mirror-up|pool-mirror-down|vlan-mirror)"
521 			" (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
522 			"   Set pool or vlan type mirror rule on a port.\n"
523 			"   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
524 			" dst-pool 0 on' enable mirror traffic with vlan 0,1"
525 			" to pool 0.\n\n"
526 
527 			"set port (port_id) mirror-rule (rule_id)"
528 			" (uplink-mirror|downlink-mirror) dst-pool"
529 			" (pool_id) (on|off)\n"
530 			"   Set uplink or downlink type mirror rule on a port.\n"
531 			"   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
532 			" 0 on' enable mirror income traffic to pool 0.\n\n"
533 
534 			"reset port (port_id) mirror-rule (rule_id)\n"
535 			"   Reset a mirror rule.\n\n"
536 
537 			"set flush_rx (on|off)\n"
538 			"   Flush (default) or don't flush RX streams before"
539 			" forwarding. Mainly used with PCAP drivers.\n\n"
540 
541 			"set bypass mode (normal|bypass|isolate) (port_id)\n"
542 			"   Set the bypass mode for the lowest port on bypass enabled"
543 			" NIC.\n\n"
544 
545 			"set bypass event (timeout|os_on|os_off|power_on|power_off) "
546 			"mode (normal|bypass|isolate) (port_id)\n"
547 			"   Set the event required to initiate specified bypass mode for"
548 			" the lowest port on a bypass enabled NIC where:\n"
549 			"       timeout   = enable bypass after watchdog timeout.\n"
550 			"       os_on     = enable bypass when OS/board is powered on.\n"
551 			"       os_off    = enable bypass when OS/board is powered off.\n"
552 			"       power_on  = enable bypass when power supply is turned on.\n"
553 			"       power_off = enable bypass when power supply is turned off."
554 			"\n\n"
555 
556 			"set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
557 			"   Set the bypass watchdog timeout to 'n' seconds"
558 			" where 0 = instant.\n\n"
559 
560 			"show bypass config (port_id)\n"
561 			"   Show the bypass configuration for a bypass enabled NIC"
562 			" using the lowest port on the NIC.\n\n"
563 
564 #ifdef RTE_LIBRTE_PMD_BOND
565 			"create bonded device (mode) (socket)\n"
566 			"	Create a new bonded device with specific bonding mode and socket.\n\n"
567 
568 			"add bonding slave (slave_id) (port_id)\n"
569 			"	Add a slave device to a bonded device.\n\n"
570 
571 			"remove bonding slave (slave_id) (port_id)\n"
572 			"	Remove a slave device from a bonded device.\n\n"
573 
574 			"set bonding mode (value) (port_id)\n"
575 			"	Set the bonding mode on a bonded device.\n\n"
576 
577 			"set bonding primary (slave_id) (port_id)\n"
578 			"	Set the primary slave for a bonded device.\n\n"
579 
580 			"show bonding config (port_id)\n"
581 			"	Show the bonding config for port_id.\n\n"
582 
583 			"set bonding mac_addr (port_id) (address)\n"
584 			"	Set the MAC address of a bonded device.\n\n"
585 
586 			"set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
587 			"	Set Aggregation mode for IEEE802.3AD (mode 4)"
588 
589 			"set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
590 			"	Set the transmit balance policy for bonded device running in balance mode.\n\n"
591 
592 			"set bonding mon_period (port_id) (value)\n"
593 			"	Set the bonding link status monitoring polling period in ms.\n\n"
594 
595 			"set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
596 			"	Enable/disable dedicated queues for LACP control traffic.\n\n"
597 
598 #endif
599 			"set link-up port (port_id)\n"
600 			"	Set link up for a port.\n\n"
601 
602 			"set link-down port (port_id)\n"
603 			"	Set link down for a port.\n\n"
604 
605 			"E-tag set insertion on port-tag-id (value)"
606 			" port (port_id) vf (vf_id)\n"
607 			"    Enable E-tag insertion for a VF on a port\n\n"
608 
609 			"E-tag set insertion off port (port_id) vf (vf_id)\n"
610 			"    Disable E-tag insertion for a VF on a port\n\n"
611 
612 			"E-tag set stripping (on|off) port (port_id)\n"
613 			"    Enable/disable E-tag stripping on a port\n\n"
614 
615 			"E-tag set forwarding (on|off) port (port_id)\n"
616 			"    Enable/disable E-tag based forwarding"
617 			" on a port\n\n"
618 
619 			"E-tag set filter add e-tag-id (value) dst-pool"
620 			" (pool_id) port (port_id)\n"
621 			"    Add an E-tag forwarding filter on a port\n\n"
622 
623 			"E-tag set filter del e-tag-id (value) port (port_id)\n"
624 			"    Delete an E-tag forwarding filter on a port\n\n"
625 
626 			"ddp add (port_id) (profile_path[,output_path])\n"
627 			"    Load a profile package on a port\n\n"
628 
629 			"ddp del (port_id) (profile_path)\n"
630 			"    Delete a profile package from a port\n\n"
631 
632 			"ptype mapping get (port_id) (valid_only)\n"
633 			"    Get ptype mapping on a port\n\n"
634 
635 			"ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
636 			"    Replace target with the pkt_type in ptype mapping\n\n"
637 
638 			"ptype mapping reset (port_id)\n"
639 			"    Reset ptype mapping on a port\n\n"
640 
641 			"ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
642 			"    Update a ptype mapping item on a port\n\n"
643 
644 			, list_pkt_forwarding_modes()
645 		);
646 	}
647 
648 	if (show_all || !strcmp(res->section, "ports")) {
649 
650 		cmdline_printf(
651 			cl,
652 			"\n"
653 			"Port Operations:\n"
654 			"----------------\n\n"
655 
656 			"port start (port_id|all)\n"
657 			"    Start all ports or port_id.\n\n"
658 
659 			"port stop (port_id|all)\n"
660 			"    Stop all ports or port_id.\n\n"
661 
662 			"port close (port_id|all)\n"
663 			"    Close all ports or port_id.\n\n"
664 
665 			"port attach (ident)\n"
666 			"    Attach physical or virtual dev by pci address or virtual device name\n\n"
667 
668 			"port detach (port_id)\n"
669 			"    Detach physical or virtual dev by port_id\n\n"
670 
671 			"port config (port_id|all)"
672 			" speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
673 			" duplex (half|full|auto)\n"
674 			"    Set speed and duplex for all ports or port_id\n\n"
675 
676 			"port config all (rxq|txq|rxd|txd) (value)\n"
677 			"    Set number for rxq/txq/rxd/txd.\n\n"
678 
679 			"port config all max-pkt-len (value)\n"
680 			"    Set the max packet length.\n\n"
681 
682 			"port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|"
683 			"hw-vlan-strip|hw-vlan-extend|drop-en)"
684 			" (on|off)\n"
685 			"    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
686 			" for ports.\n\n"
687 
688 			"port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
689 			"geneve|nvgre|none|<flowtype_id>)\n"
690 			"    Set the RSS mode.\n\n"
691 
692 			"port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
693 			"    Set the RSS redirection table.\n\n"
694 
695 			"port config (port_id) dcb vt (on|off) (traffic_class)"
696 			" pfc (on|off)\n"
697 			"    Set the DCB mode.\n\n"
698 
699 			"port config all burst (value)\n"
700 			"    Set the number of packets per burst.\n\n"
701 
702 			"port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
703 			" (value)\n"
704 			"    Set the ring prefetch/host/writeback threshold"
705 			" for tx/rx queue.\n\n"
706 
707 			"port config all (txfreet|txrst|rxfreet) (value)\n"
708 			"    Set free threshold for rx/tx, or set"
709 			" tx rs bit threshold.\n\n"
710 			"port config mtu X value\n"
711 			"    Set the MTU of port X to a given value\n\n"
712 
713 			"port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
714 			"    Start/stop a rx/tx queue of port X. Only take effect"
715 			" when port X is started\n\n"
716 
717 			"port config (port_id|all) l2-tunnel E-tag ether-type"
718 			" (value)\n"
719 			"    Set the value of E-tag ether-type.\n\n"
720 
721 			"port config (port_id|all) l2-tunnel E-tag"
722 			" (enable|disable)\n"
723 			"    Enable/disable the E-tag support.\n\n"
724 
725 			"port config (port_id) pctype mapping reset\n"
726 			"    Reset flow type to pctype mapping on a port\n\n"
727 
728 			"port config (port_id) pctype mapping update"
729 			" (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
730 			"    Update a flow type to pctype mapping item on a port\n\n"
731 		);
732 	}
733 
734 	if (show_all || !strcmp(res->section, "registers")) {
735 
736 		cmdline_printf(
737 			cl,
738 			"\n"
739 			"Registers:\n"
740 			"----------\n\n"
741 
742 			"read reg (port_id) (address)\n"
743 			"    Display value of a port register.\n\n"
744 
745 			"read regfield (port_id) (address) (bit_x) (bit_y)\n"
746 			"    Display a port register bit field.\n\n"
747 
748 			"read regbit (port_id) (address) (bit_x)\n"
749 			"    Display a single port register bit.\n\n"
750 
751 			"write reg (port_id) (address) (value)\n"
752 			"    Set value of a port register.\n\n"
753 
754 			"write regfield (port_id) (address) (bit_x) (bit_y)"
755 			" (value)\n"
756 			"    Set bit field of a port register.\n\n"
757 
758 			"write regbit (port_id) (address) (bit_x) (value)\n"
759 			"    Set single bit value of a port register.\n\n"
760 		);
761 	}
762 	if (show_all || !strcmp(res->section, "filters")) {
763 
764 		cmdline_printf(
765 			cl,
766 			"\n"
767 			"filters:\n"
768 			"--------\n\n"
769 
770 			"ethertype_filter (port_id) (add|del)"
771 			" (mac_addr|mac_ignr) (mac_address) ethertype"
772 			" (ether_type) (drop|fwd) queue (queue_id)\n"
773 			"    Add/Del an ethertype filter.\n\n"
774 
775 			"2tuple_filter (port_id) (add|del)"
776 			" dst_port (dst_port_value) protocol (protocol_value)"
777 			" mask (mask_value) tcp_flags (tcp_flags_value)"
778 			" priority (prio_value) queue (queue_id)\n"
779 			"    Add/Del a 2tuple filter.\n\n"
780 
781 			"5tuple_filter (port_id) (add|del)"
782 			" dst_ip (dst_address) src_ip (src_address)"
783 			" dst_port (dst_port_value) src_port (src_port_value)"
784 			" protocol (protocol_value)"
785 			" mask (mask_value) tcp_flags (tcp_flags_value)"
786 			" priority (prio_value) queue (queue_id)\n"
787 			"    Add/Del a 5tuple filter.\n\n"
788 
789 			"syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
790 			"    Add/Del syn filter.\n\n"
791 
792 			"flex_filter (port_id) (add|del) len (len_value)"
793 			" bytes (bytes_value) mask (mask_value)"
794 			" priority (prio_value) queue (queue_id)\n"
795 			"    Add/Del a flex filter.\n\n"
796 
797 			"flow_director_filter (port_id) mode IP (add|del|update)"
798 			" flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
799 			" src (src_ip_address) dst (dst_ip_address)"
800 			" tos (tos_value) proto (proto_value) ttl (ttl_value)"
801 			" vlan (vlan_value) flexbytes (flexbytes_value)"
802 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
803 			" fd_id (fd_id_value)\n"
804 			"    Add/Del an IP type flow director filter.\n\n"
805 
806 			"flow_director_filter (port_id) mode IP (add|del|update)"
807 			" flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
808 			" src (src_ip_address) (src_port)"
809 			" dst (dst_ip_address) (dst_port)"
810 			" tos (tos_value) ttl (ttl_value)"
811 			" vlan (vlan_value) flexbytes (flexbytes_value)"
812 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
813 			" fd_id (fd_id_value)\n"
814 			"    Add/Del an UDP/TCP type flow director filter.\n\n"
815 
816 			"flow_director_filter (port_id) mode IP (add|del|update)"
817 			" flow (ipv4-sctp|ipv6-sctp)"
818 			" src (src_ip_address) (src_port)"
819 			" dst (dst_ip_address) (dst_port)"
820 			" tag (verification_tag) "
821 			" tos (tos_value) ttl (ttl_value)"
822 			" vlan (vlan_value)"
823 			" flexbytes (flexbytes_value) (drop|fwd)"
824 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
825 			"    Add/Del a SCTP type flow director filter.\n\n"
826 
827 			"flow_director_filter (port_id) mode IP (add|del|update)"
828 			" flow l2_payload ether (ethertype)"
829 			" flexbytes (flexbytes_value) (drop|fwd)"
830 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
831 			"    Add/Del a l2 payload type flow director filter.\n\n"
832 
833 			"flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
834 			" mac (mac_address) vlan (vlan_value)"
835 			" flexbytes (flexbytes_value) (drop|fwd)"
836 			" queue (queue_id) fd_id (fd_id_value)\n"
837 			"    Add/Del a MAC-VLAN flow director filter.\n\n"
838 
839 			"flow_director_filter (port_id) mode Tunnel (add|del|update)"
840 			" mac (mac_address) vlan (vlan_value)"
841 			" tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
842 			" flexbytes (flexbytes_value) (drop|fwd)"
843 			" queue (queue_id) fd_id (fd_id_value)\n"
844 			"    Add/Del a Tunnel flow director filter.\n\n"
845 
846 			"flush_flow_director (port_id)\n"
847 			"    Flush all flow director entries of a device.\n\n"
848 
849 			"flow_director_mask (port_id) mode IP vlan (vlan_value)"
850 			" src_mask (ipv4_src) (ipv6_src) (src_port)"
851 			" dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
852 			"    Set flow director IP mask.\n\n"
853 
854 			"flow_director_mask (port_id) mode MAC-VLAN"
855 			" vlan (vlan_value)\n"
856 			"    Set flow director MAC-VLAN mask.\n\n"
857 
858 			"flow_director_mask (port_id) mode Tunnel"
859 			" vlan (vlan_value) mac (mac_value)"
860 			" tunnel-type (tunnel_type_value)"
861 			" tunnel-id (tunnel_id_value)\n"
862 			"    Set flow director Tunnel mask.\n\n"
863 
864 			"flow_director_flex_mask (port_id)"
865 			" flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
866 			"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
867 			" (mask)\n"
868 			"    Configure mask of flex payload.\n\n"
869 
870 			"flow_director_flex_payload (port_id)"
871 			" (raw|l2|l3|l4) (config)\n"
872 			"    Configure flex payload selection.\n\n"
873 
874 			"get_sym_hash_ena_per_port (port_id)\n"
875 			"    get symmetric hash enable configuration per port.\n\n"
876 
877 			"set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
878 			"    set symmetric hash enable configuration per port"
879 			" to enable or disable.\n\n"
880 
881 			"get_hash_global_config (port_id)\n"
882 			"    Get the global configurations of hash filters.\n\n"
883 
884 			"set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
885 			" (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
886 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
887 			" (enable|disable)\n"
888 			"    Set the global configurations of hash filters.\n\n"
889 
890 			"set_hash_input_set (port_id) (ipv4|ipv4-frag|"
891 			"ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
892 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
893 			"l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
894 			"src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
895 			"ipv6-next-header|udp-src-port|udp-dst-port|"
896 			"tcp-src-port|tcp-dst-port|sctp-src-port|"
897 			"sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
898 			"fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
899 			"fld-8th|none) (select|add)\n"
900 			"    Set the input set for hash.\n\n"
901 
902 			"set_fdir_input_set (port_id) "
903 			"(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
904 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
905 			"l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
906 			"dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
907 			"ipv6-next-header|ipv6-hop-limits|udp-src-port|"
908 			"udp-dst-port|tcp-src-port|tcp-dst-port|"
909 			"sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
910 			" (select|add)\n"
911 			"    Set the input set for FDir.\n\n"
912 
913 			"flow validate {port_id}"
914 			" [group {group_id}] [priority {level}]"
915 			" [ingress] [egress]"
916 			" pattern {item} [/ {item} [...]] / end"
917 			" actions {action} [/ {action} [...]] / end\n"
918 			"    Check whether a flow rule can be created.\n\n"
919 
920 			"flow create {port_id}"
921 			" [group {group_id}] [priority {level}]"
922 			" [ingress] [egress]"
923 			" pattern {item} [/ {item} [...]] / end"
924 			" actions {action} [/ {action} [...]] / end\n"
925 			"    Create a flow rule.\n\n"
926 
927 			"flow destroy {port_id} rule {rule_id} [...]\n"
928 			"    Destroy specific flow rules.\n\n"
929 
930 			"flow flush {port_id}\n"
931 			"    Destroy all flow rules.\n\n"
932 
933 			"flow query {port_id} {rule_id} {action}\n"
934 			"    Query an existing flow rule.\n\n"
935 
936 			"flow list {port_id} [group {group_id}] [...]\n"
937 			"    List existing flow rules sorted by priority,"
938 			" filtered by group identifiers.\n\n"
939 
940 			"flow isolate {port_id} {boolean}\n"
941 			"    Restrict ingress traffic to the defined"
942 			" flow rules\n\n"
943 		);
944 	}
945 }
946 
947 cmdline_parse_token_string_t cmd_help_long_help =
948 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
949 
950 cmdline_parse_token_string_t cmd_help_long_section =
951 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
952 			"all#control#display#config#"
953 			"ports#registers#filters");
954 
955 cmdline_parse_inst_t cmd_help_long = {
956 	.f = cmd_help_long_parsed,
957 	.data = NULL,
958 	.help_str = "help all|control|display|config|ports|register|filters: "
959 		"Show help",
960 	.tokens = {
961 		(void *)&cmd_help_long_help,
962 		(void *)&cmd_help_long_section,
963 		NULL,
964 	},
965 };
966 
967 
968 /* *** start/stop/close all ports *** */
969 struct cmd_operate_port_result {
970 	cmdline_fixed_string_t keyword;
971 	cmdline_fixed_string_t name;
972 	cmdline_fixed_string_t value;
973 };
974 
975 static void cmd_operate_port_parsed(void *parsed_result,
976 				__attribute__((unused)) struct cmdline *cl,
977 				__attribute__((unused)) void *data)
978 {
979 	struct cmd_operate_port_result *res = parsed_result;
980 
981 	if (!strcmp(res->name, "start"))
982 		start_port(RTE_PORT_ALL);
983 	else if (!strcmp(res->name, "stop"))
984 		stop_port(RTE_PORT_ALL);
985 	else if (!strcmp(res->name, "close"))
986 		close_port(RTE_PORT_ALL);
987 	else if (!strcmp(res->name, "reset"))
988 		reset_port(RTE_PORT_ALL);
989 	else
990 		printf("Unknown parameter\n");
991 }
992 
993 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
994 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
995 								"port");
996 cmdline_parse_token_string_t cmd_operate_port_all_port =
997 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
998 						"start#stop#close#reset");
999 cmdline_parse_token_string_t cmd_operate_port_all_all =
1000 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1001 
1002 cmdline_parse_inst_t cmd_operate_port = {
1003 	.f = cmd_operate_port_parsed,
1004 	.data = NULL,
1005 	.help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1006 	.tokens = {
1007 		(void *)&cmd_operate_port_all_cmd,
1008 		(void *)&cmd_operate_port_all_port,
1009 		(void *)&cmd_operate_port_all_all,
1010 		NULL,
1011 	},
1012 };
1013 
1014 /* *** start/stop/close specific port *** */
1015 struct cmd_operate_specific_port_result {
1016 	cmdline_fixed_string_t keyword;
1017 	cmdline_fixed_string_t name;
1018 	uint8_t value;
1019 };
1020 
1021 static void cmd_operate_specific_port_parsed(void *parsed_result,
1022 			__attribute__((unused)) struct cmdline *cl,
1023 				__attribute__((unused)) void *data)
1024 {
1025 	struct cmd_operate_specific_port_result *res = parsed_result;
1026 
1027 	if (!strcmp(res->name, "start"))
1028 		start_port(res->value);
1029 	else if (!strcmp(res->name, "stop"))
1030 		stop_port(res->value);
1031 	else if (!strcmp(res->name, "close"))
1032 		close_port(res->value);
1033 	else if (!strcmp(res->name, "reset"))
1034 		reset_port(res->value);
1035 	else
1036 		printf("Unknown parameter\n");
1037 }
1038 
1039 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1040 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1041 							keyword, "port");
1042 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1043 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1044 						name, "start#stop#close#reset");
1045 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1046 	TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1047 							value, UINT8);
1048 
1049 cmdline_parse_inst_t cmd_operate_specific_port = {
1050 	.f = cmd_operate_specific_port_parsed,
1051 	.data = NULL,
1052 	.help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1053 	.tokens = {
1054 		(void *)&cmd_operate_specific_port_cmd,
1055 		(void *)&cmd_operate_specific_port_port,
1056 		(void *)&cmd_operate_specific_port_id,
1057 		NULL,
1058 	},
1059 };
1060 
1061 /* *** attach a specified port *** */
1062 struct cmd_operate_attach_port_result {
1063 	cmdline_fixed_string_t port;
1064 	cmdline_fixed_string_t keyword;
1065 	cmdline_fixed_string_t identifier;
1066 };
1067 
1068 static void cmd_operate_attach_port_parsed(void *parsed_result,
1069 				__attribute__((unused)) struct cmdline *cl,
1070 				__attribute__((unused)) void *data)
1071 {
1072 	struct cmd_operate_attach_port_result *res = parsed_result;
1073 
1074 	if (!strcmp(res->keyword, "attach"))
1075 		attach_port(res->identifier);
1076 	else
1077 		printf("Unknown parameter\n");
1078 }
1079 
1080 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1081 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1082 			port, "port");
1083 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1084 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1085 			keyword, "attach");
1086 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1087 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1088 			identifier, NULL);
1089 
1090 cmdline_parse_inst_t cmd_operate_attach_port = {
1091 	.f = cmd_operate_attach_port_parsed,
1092 	.data = NULL,
1093 	.help_str = "port attach <identifier>: "
1094 		"(identifier: pci address or virtual dev name)",
1095 	.tokens = {
1096 		(void *)&cmd_operate_attach_port_port,
1097 		(void *)&cmd_operate_attach_port_keyword,
1098 		(void *)&cmd_operate_attach_port_identifier,
1099 		NULL,
1100 	},
1101 };
1102 
1103 /* *** detach a specified port *** */
1104 struct cmd_operate_detach_port_result {
1105 	cmdline_fixed_string_t port;
1106 	cmdline_fixed_string_t keyword;
1107 	uint8_t port_id;
1108 };
1109 
1110 static void cmd_operate_detach_port_parsed(void *parsed_result,
1111 				__attribute__((unused)) struct cmdline *cl,
1112 				__attribute__((unused)) void *data)
1113 {
1114 	struct cmd_operate_detach_port_result *res = parsed_result;
1115 
1116 	if (!strcmp(res->keyword, "detach"))
1117 		detach_port(res->port_id);
1118 	else
1119 		printf("Unknown parameter\n");
1120 }
1121 
1122 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1123 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1124 			port, "port");
1125 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1126 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1127 			keyword, "detach");
1128 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1129 	TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1130 			port_id, UINT8);
1131 
1132 cmdline_parse_inst_t cmd_operate_detach_port = {
1133 	.f = cmd_operate_detach_port_parsed,
1134 	.data = NULL,
1135 	.help_str = "port detach <port_id>",
1136 	.tokens = {
1137 		(void *)&cmd_operate_detach_port_port,
1138 		(void *)&cmd_operate_detach_port_keyword,
1139 		(void *)&cmd_operate_detach_port_port_id,
1140 		NULL,
1141 	},
1142 };
1143 
1144 /* *** configure speed for all ports *** */
1145 struct cmd_config_speed_all {
1146 	cmdline_fixed_string_t port;
1147 	cmdline_fixed_string_t keyword;
1148 	cmdline_fixed_string_t all;
1149 	cmdline_fixed_string_t item1;
1150 	cmdline_fixed_string_t item2;
1151 	cmdline_fixed_string_t value1;
1152 	cmdline_fixed_string_t value2;
1153 };
1154 
1155 static int
1156 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1157 {
1158 
1159 	int duplex;
1160 
1161 	if (!strcmp(duplexstr, "half")) {
1162 		duplex = ETH_LINK_HALF_DUPLEX;
1163 	} else if (!strcmp(duplexstr, "full")) {
1164 		duplex = ETH_LINK_FULL_DUPLEX;
1165 	} else if (!strcmp(duplexstr, "auto")) {
1166 		duplex = ETH_LINK_FULL_DUPLEX;
1167 	} else {
1168 		printf("Unknown duplex parameter\n");
1169 		return -1;
1170 	}
1171 
1172 	if (!strcmp(speedstr, "10")) {
1173 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1174 				ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1175 	} else if (!strcmp(speedstr, "100")) {
1176 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1177 				ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1178 	} else {
1179 		if (duplex != ETH_LINK_FULL_DUPLEX) {
1180 			printf("Invalid speed/duplex parameters\n");
1181 			return -1;
1182 		}
1183 		if (!strcmp(speedstr, "1000")) {
1184 			*speed = ETH_LINK_SPEED_1G;
1185 		} else if (!strcmp(speedstr, "10000")) {
1186 			*speed = ETH_LINK_SPEED_10G;
1187 		} else if (!strcmp(speedstr, "25000")) {
1188 			*speed = ETH_LINK_SPEED_25G;
1189 		} else if (!strcmp(speedstr, "40000")) {
1190 			*speed = ETH_LINK_SPEED_40G;
1191 		} else if (!strcmp(speedstr, "50000")) {
1192 			*speed = ETH_LINK_SPEED_50G;
1193 		} else if (!strcmp(speedstr, "100000")) {
1194 			*speed = ETH_LINK_SPEED_100G;
1195 		} else if (!strcmp(speedstr, "auto")) {
1196 			*speed = ETH_LINK_SPEED_AUTONEG;
1197 		} else {
1198 			printf("Unknown speed parameter\n");
1199 			return -1;
1200 		}
1201 	}
1202 
1203 	return 0;
1204 }
1205 
1206 static void
1207 cmd_config_speed_all_parsed(void *parsed_result,
1208 			__attribute__((unused)) struct cmdline *cl,
1209 			__attribute__((unused)) void *data)
1210 {
1211 	struct cmd_config_speed_all *res = parsed_result;
1212 	uint32_t link_speed;
1213 	portid_t pid;
1214 
1215 	if (!all_ports_stopped()) {
1216 		printf("Please stop all ports first\n");
1217 		return;
1218 	}
1219 
1220 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1221 			&link_speed) < 0)
1222 		return;
1223 
1224 	RTE_ETH_FOREACH_DEV(pid) {
1225 		ports[pid].dev_conf.link_speeds = link_speed;
1226 	}
1227 
1228 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1229 }
1230 
1231 cmdline_parse_token_string_t cmd_config_speed_all_port =
1232 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1233 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1234 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1235 							"config");
1236 cmdline_parse_token_string_t cmd_config_speed_all_all =
1237 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1238 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1239 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1240 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1241 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1242 				"10#100#1000#10000#25000#40000#50000#100000#auto");
1243 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1244 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1245 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1246 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1247 						"half#full#auto");
1248 
1249 cmdline_parse_inst_t cmd_config_speed_all = {
1250 	.f = cmd_config_speed_all_parsed,
1251 	.data = NULL,
1252 	.help_str = "port config all speed "
1253 		"10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1254 							"half|full|auto",
1255 	.tokens = {
1256 		(void *)&cmd_config_speed_all_port,
1257 		(void *)&cmd_config_speed_all_keyword,
1258 		(void *)&cmd_config_speed_all_all,
1259 		(void *)&cmd_config_speed_all_item1,
1260 		(void *)&cmd_config_speed_all_value1,
1261 		(void *)&cmd_config_speed_all_item2,
1262 		(void *)&cmd_config_speed_all_value2,
1263 		NULL,
1264 	},
1265 };
1266 
1267 /* *** configure speed for specific port *** */
1268 struct cmd_config_speed_specific {
1269 	cmdline_fixed_string_t port;
1270 	cmdline_fixed_string_t keyword;
1271 	uint8_t id;
1272 	cmdline_fixed_string_t item1;
1273 	cmdline_fixed_string_t item2;
1274 	cmdline_fixed_string_t value1;
1275 	cmdline_fixed_string_t value2;
1276 };
1277 
1278 static void
1279 cmd_config_speed_specific_parsed(void *parsed_result,
1280 				__attribute__((unused)) struct cmdline *cl,
1281 				__attribute__((unused)) void *data)
1282 {
1283 	struct cmd_config_speed_specific *res = parsed_result;
1284 	uint32_t link_speed;
1285 
1286 	if (!all_ports_stopped()) {
1287 		printf("Please stop all ports first\n");
1288 		return;
1289 	}
1290 
1291 	if (port_id_is_invalid(res->id, ENABLED_WARN))
1292 		return;
1293 
1294 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1295 			&link_speed) < 0)
1296 		return;
1297 
1298 	ports[res->id].dev_conf.link_speeds = link_speed;
1299 
1300 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1301 }
1302 
1303 
1304 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1305 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1306 								"port");
1307 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1308 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1309 								"config");
1310 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1311 	TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1312 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1313 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1314 								"speed");
1315 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1316 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1317 				"10#100#1000#10000#25000#40000#50000#100000#auto");
1318 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1319 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1320 								"duplex");
1321 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1322 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1323 							"half#full#auto");
1324 
1325 cmdline_parse_inst_t cmd_config_speed_specific = {
1326 	.f = cmd_config_speed_specific_parsed,
1327 	.data = NULL,
1328 	.help_str = "port config <port_id> speed "
1329 		"10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1330 							"half|full|auto",
1331 	.tokens = {
1332 		(void *)&cmd_config_speed_specific_port,
1333 		(void *)&cmd_config_speed_specific_keyword,
1334 		(void *)&cmd_config_speed_specific_id,
1335 		(void *)&cmd_config_speed_specific_item1,
1336 		(void *)&cmd_config_speed_specific_value1,
1337 		(void *)&cmd_config_speed_specific_item2,
1338 		(void *)&cmd_config_speed_specific_value2,
1339 		NULL,
1340 	},
1341 };
1342 
1343 /* *** configure txq/rxq, txd/rxd *** */
1344 struct cmd_config_rx_tx {
1345 	cmdline_fixed_string_t port;
1346 	cmdline_fixed_string_t keyword;
1347 	cmdline_fixed_string_t all;
1348 	cmdline_fixed_string_t name;
1349 	uint16_t value;
1350 };
1351 
1352 static void
1353 cmd_config_rx_tx_parsed(void *parsed_result,
1354 			__attribute__((unused)) struct cmdline *cl,
1355 			__attribute__((unused)) void *data)
1356 {
1357 	struct cmd_config_rx_tx *res = parsed_result;
1358 
1359 	if (!all_ports_stopped()) {
1360 		printf("Please stop all ports first\n");
1361 		return;
1362 	}
1363 	if (!strcmp(res->name, "rxq")) {
1364 		if (!res->value && !nb_txq) {
1365 			printf("Warning: Either rx or tx queues should be non zero\n");
1366 			return;
1367 		}
1368 		nb_rxq = res->value;
1369 	}
1370 	else if (!strcmp(res->name, "txq")) {
1371 		if (!res->value && !nb_rxq) {
1372 			printf("Warning: Either rx or tx queues should be non zero\n");
1373 			return;
1374 		}
1375 		nb_txq = res->value;
1376 	}
1377 	else if (!strcmp(res->name, "rxd")) {
1378 		if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1379 			printf("rxd %d invalid - must be > 0 && <= %d\n",
1380 					res->value, RTE_TEST_RX_DESC_MAX);
1381 			return;
1382 		}
1383 		nb_rxd = res->value;
1384 	} else if (!strcmp(res->name, "txd")) {
1385 		if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1386 			printf("txd %d invalid - must be > 0 && <= %d\n",
1387 					res->value, RTE_TEST_TX_DESC_MAX);
1388 			return;
1389 		}
1390 		nb_txd = res->value;
1391 	} else {
1392 		printf("Unknown parameter\n");
1393 		return;
1394 	}
1395 
1396 	fwd_config_setup();
1397 
1398 	init_port_config();
1399 
1400 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1401 }
1402 
1403 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1404 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1405 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1406 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1407 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1408 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1409 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1410 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1411 						"rxq#txq#rxd#txd");
1412 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1413 	TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1414 
1415 cmdline_parse_inst_t cmd_config_rx_tx = {
1416 	.f = cmd_config_rx_tx_parsed,
1417 	.data = NULL,
1418 	.help_str = "port config all rxq|txq|rxd|txd <value>",
1419 	.tokens = {
1420 		(void *)&cmd_config_rx_tx_port,
1421 		(void *)&cmd_config_rx_tx_keyword,
1422 		(void *)&cmd_config_rx_tx_all,
1423 		(void *)&cmd_config_rx_tx_name,
1424 		(void *)&cmd_config_rx_tx_value,
1425 		NULL,
1426 	},
1427 };
1428 
1429 /* *** config max packet length *** */
1430 struct cmd_config_max_pkt_len_result {
1431 	cmdline_fixed_string_t port;
1432 	cmdline_fixed_string_t keyword;
1433 	cmdline_fixed_string_t all;
1434 	cmdline_fixed_string_t name;
1435 	uint32_t value;
1436 };
1437 
1438 static void
1439 cmd_config_max_pkt_len_parsed(void *parsed_result,
1440 				__attribute__((unused)) struct cmdline *cl,
1441 				__attribute__((unused)) void *data)
1442 {
1443 	struct cmd_config_max_pkt_len_result *res = parsed_result;
1444 
1445 	if (!all_ports_stopped()) {
1446 		printf("Please stop all ports first\n");
1447 		return;
1448 	}
1449 
1450 	if (!strcmp(res->name, "max-pkt-len")) {
1451 		if (res->value < ETHER_MIN_LEN) {
1452 			printf("max-pkt-len can not be less than %d\n",
1453 							ETHER_MIN_LEN);
1454 			return;
1455 		}
1456 		if (res->value == rx_mode.max_rx_pkt_len)
1457 			return;
1458 
1459 		rx_mode.max_rx_pkt_len = res->value;
1460 		if (res->value > ETHER_MAX_LEN)
1461 			rx_mode.jumbo_frame = 1;
1462 		else
1463 			rx_mode.jumbo_frame = 0;
1464 	} else {
1465 		printf("Unknown parameter\n");
1466 		return;
1467 	}
1468 
1469 	init_port_config();
1470 
1471 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1472 }
1473 
1474 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1475 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1476 								"port");
1477 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1478 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1479 								"config");
1480 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1481 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1482 								"all");
1483 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1484 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1485 								"max-pkt-len");
1486 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1487 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1488 								UINT32);
1489 
1490 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1491 	.f = cmd_config_max_pkt_len_parsed,
1492 	.data = NULL,
1493 	.help_str = "port config all max-pkt-len <value>",
1494 	.tokens = {
1495 		(void *)&cmd_config_max_pkt_len_port,
1496 		(void *)&cmd_config_max_pkt_len_keyword,
1497 		(void *)&cmd_config_max_pkt_len_all,
1498 		(void *)&cmd_config_max_pkt_len_name,
1499 		(void *)&cmd_config_max_pkt_len_value,
1500 		NULL,
1501 	},
1502 };
1503 
1504 /* *** configure port MTU *** */
1505 struct cmd_config_mtu_result {
1506 	cmdline_fixed_string_t port;
1507 	cmdline_fixed_string_t keyword;
1508 	cmdline_fixed_string_t mtu;
1509 	uint8_t port_id;
1510 	uint16_t value;
1511 };
1512 
1513 static void
1514 cmd_config_mtu_parsed(void *parsed_result,
1515 		      __attribute__((unused)) struct cmdline *cl,
1516 		      __attribute__((unused)) void *data)
1517 {
1518 	struct cmd_config_mtu_result *res = parsed_result;
1519 
1520 	if (res->value < ETHER_MIN_LEN) {
1521 		printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1522 		return;
1523 	}
1524 	port_mtu_set(res->port_id, res->value);
1525 }
1526 
1527 cmdline_parse_token_string_t cmd_config_mtu_port =
1528 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1529 				 "port");
1530 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1531 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1532 				 "config");
1533 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1534 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1535 				 "mtu");
1536 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1537 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1538 cmdline_parse_token_num_t cmd_config_mtu_value =
1539 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1540 
1541 cmdline_parse_inst_t cmd_config_mtu = {
1542 	.f = cmd_config_mtu_parsed,
1543 	.data = NULL,
1544 	.help_str = "port config mtu <port_id> <value>",
1545 	.tokens = {
1546 		(void *)&cmd_config_mtu_port,
1547 		(void *)&cmd_config_mtu_keyword,
1548 		(void *)&cmd_config_mtu_mtu,
1549 		(void *)&cmd_config_mtu_port_id,
1550 		(void *)&cmd_config_mtu_value,
1551 		NULL,
1552 	},
1553 };
1554 
1555 /* *** configure rx mode *** */
1556 struct cmd_config_rx_mode_flag {
1557 	cmdline_fixed_string_t port;
1558 	cmdline_fixed_string_t keyword;
1559 	cmdline_fixed_string_t all;
1560 	cmdline_fixed_string_t name;
1561 	cmdline_fixed_string_t value;
1562 };
1563 
1564 static void
1565 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1566 				__attribute__((unused)) struct cmdline *cl,
1567 				__attribute__((unused)) void *data)
1568 {
1569 	struct cmd_config_rx_mode_flag *res = parsed_result;
1570 
1571 	if (!all_ports_stopped()) {
1572 		printf("Please stop all ports first\n");
1573 		return;
1574 	}
1575 
1576 	if (!strcmp(res->name, "crc-strip")) {
1577 		if (!strcmp(res->value, "on"))
1578 			rx_mode.hw_strip_crc = 1;
1579 		else if (!strcmp(res->value, "off"))
1580 			rx_mode.hw_strip_crc = 0;
1581 		else {
1582 			printf("Unknown parameter\n");
1583 			return;
1584 		}
1585 	} else if (!strcmp(res->name, "scatter")) {
1586 		if (!strcmp(res->value, "on"))
1587 			rx_mode.enable_scatter = 1;
1588 		else if (!strcmp(res->value, "off"))
1589 			rx_mode.enable_scatter = 0;
1590 		else {
1591 			printf("Unknown parameter\n");
1592 			return;
1593 		}
1594 	} else if (!strcmp(res->name, "rx-cksum")) {
1595 		if (!strcmp(res->value, "on"))
1596 			rx_mode.hw_ip_checksum = 1;
1597 		else if (!strcmp(res->value, "off"))
1598 			rx_mode.hw_ip_checksum = 0;
1599 		else {
1600 			printf("Unknown parameter\n");
1601 			return;
1602 		}
1603 	} else if (!strcmp(res->name, "hw-vlan")) {
1604 		if (!strcmp(res->value, "on")) {
1605 			rx_mode.hw_vlan_filter = 1;
1606 			rx_mode.hw_vlan_strip  = 1;
1607 		}
1608 		else if (!strcmp(res->value, "off")) {
1609 			rx_mode.hw_vlan_filter = 0;
1610 			rx_mode.hw_vlan_strip  = 0;
1611 		}
1612 		else {
1613 			printf("Unknown parameter\n");
1614 			return;
1615 		}
1616 	} else if (!strcmp(res->name, "hw-vlan-filter")) {
1617 		if (!strcmp(res->value, "on"))
1618 			rx_mode.hw_vlan_filter = 1;
1619 		else if (!strcmp(res->value, "off"))
1620 			rx_mode.hw_vlan_filter = 0;
1621 		else {
1622 			printf("Unknown parameter\n");
1623 			return;
1624 		}
1625 	} else if (!strcmp(res->name, "hw-vlan-strip")) {
1626 		if (!strcmp(res->value, "on"))
1627 			rx_mode.hw_vlan_strip  = 1;
1628 		else if (!strcmp(res->value, "off"))
1629 			rx_mode.hw_vlan_strip  = 0;
1630 		else {
1631 			printf("Unknown parameter\n");
1632 			return;
1633 		}
1634 	} else if (!strcmp(res->name, "hw-vlan-extend")) {
1635 		if (!strcmp(res->value, "on"))
1636 			rx_mode.hw_vlan_extend = 1;
1637 		else if (!strcmp(res->value, "off"))
1638 			rx_mode.hw_vlan_extend = 0;
1639 		else {
1640 			printf("Unknown parameter\n");
1641 			return;
1642 		}
1643 	} else if (!strcmp(res->name, "drop-en")) {
1644 		if (!strcmp(res->value, "on"))
1645 			rx_drop_en = 1;
1646 		else if (!strcmp(res->value, "off"))
1647 			rx_drop_en = 0;
1648 		else {
1649 			printf("Unknown parameter\n");
1650 			return;
1651 		}
1652 	} else {
1653 		printf("Unknown parameter\n");
1654 		return;
1655 	}
1656 
1657 	init_port_config();
1658 
1659 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1660 }
1661 
1662 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1663 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1664 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1665 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1666 								"config");
1667 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1668 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1669 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1670 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1671 					"crc-strip#scatter#rx-cksum#hw-vlan#"
1672 					"hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1673 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1674 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1675 							"on#off");
1676 
1677 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1678 	.f = cmd_config_rx_mode_flag_parsed,
1679 	.data = NULL,
1680 	.help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|"
1681 		"hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1682 	.tokens = {
1683 		(void *)&cmd_config_rx_mode_flag_port,
1684 		(void *)&cmd_config_rx_mode_flag_keyword,
1685 		(void *)&cmd_config_rx_mode_flag_all,
1686 		(void *)&cmd_config_rx_mode_flag_name,
1687 		(void *)&cmd_config_rx_mode_flag_value,
1688 		NULL,
1689 	},
1690 };
1691 
1692 /* *** configure rss *** */
1693 struct cmd_config_rss {
1694 	cmdline_fixed_string_t port;
1695 	cmdline_fixed_string_t keyword;
1696 	cmdline_fixed_string_t all;
1697 	cmdline_fixed_string_t name;
1698 	cmdline_fixed_string_t value;
1699 };
1700 
1701 static void
1702 cmd_config_rss_parsed(void *parsed_result,
1703 			__attribute__((unused)) struct cmdline *cl,
1704 			__attribute__((unused)) void *data)
1705 {
1706 	struct cmd_config_rss *res = parsed_result;
1707 	struct rte_eth_rss_conf rss_conf;
1708 	int diag;
1709 	uint8_t i;
1710 
1711 	if (!strcmp(res->value, "all"))
1712 		rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1713 				ETH_RSS_UDP | ETH_RSS_SCTP |
1714 					ETH_RSS_L2_PAYLOAD;
1715 	else if (!strcmp(res->value, "ip"))
1716 		rss_conf.rss_hf = ETH_RSS_IP;
1717 	else if (!strcmp(res->value, "udp"))
1718 		rss_conf.rss_hf = ETH_RSS_UDP;
1719 	else if (!strcmp(res->value, "tcp"))
1720 		rss_conf.rss_hf = ETH_RSS_TCP;
1721 	else if (!strcmp(res->value, "sctp"))
1722 		rss_conf.rss_hf = ETH_RSS_SCTP;
1723 	else if (!strcmp(res->value, "ether"))
1724 		rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1725 	else if (!strcmp(res->value, "port"))
1726 		rss_conf.rss_hf = ETH_RSS_PORT;
1727 	else if (!strcmp(res->value, "vxlan"))
1728 		rss_conf.rss_hf = ETH_RSS_VXLAN;
1729 	else if (!strcmp(res->value, "geneve"))
1730 		rss_conf.rss_hf = ETH_RSS_GENEVE;
1731 	else if (!strcmp(res->value, "nvgre"))
1732 		rss_conf.rss_hf = ETH_RSS_NVGRE;
1733 	else if (!strcmp(res->value, "none"))
1734 		rss_conf.rss_hf = 0;
1735 	else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1736 						atoi(res->value) < 64)
1737 		rss_conf.rss_hf = 1ULL << atoi(res->value);
1738 	else {
1739 		printf("Unknown parameter\n");
1740 		return;
1741 	}
1742 	rss_conf.rss_key = NULL;
1743 	for (i = 0; i < rte_eth_dev_count(); i++) {
1744 		diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1745 		if (diag < 0)
1746 			printf("Configuration of RSS hash at ethernet port %d "
1747 				"failed with error (%d): %s.\n",
1748 				i, -diag, strerror(-diag));
1749 	}
1750 }
1751 
1752 cmdline_parse_token_string_t cmd_config_rss_port =
1753 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1754 cmdline_parse_token_string_t cmd_config_rss_keyword =
1755 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1756 cmdline_parse_token_string_t cmd_config_rss_all =
1757 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1758 cmdline_parse_token_string_t cmd_config_rss_name =
1759 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1760 cmdline_parse_token_string_t cmd_config_rss_value =
1761 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1762 
1763 cmdline_parse_inst_t cmd_config_rss = {
1764 	.f = cmd_config_rss_parsed,
1765 	.data = NULL,
1766 	.help_str = "port config all rss "
1767 		"all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1768 	.tokens = {
1769 		(void *)&cmd_config_rss_port,
1770 		(void *)&cmd_config_rss_keyword,
1771 		(void *)&cmd_config_rss_all,
1772 		(void *)&cmd_config_rss_name,
1773 		(void *)&cmd_config_rss_value,
1774 		NULL,
1775 	},
1776 };
1777 
1778 /* *** configure rss hash key *** */
1779 struct cmd_config_rss_hash_key {
1780 	cmdline_fixed_string_t port;
1781 	cmdline_fixed_string_t config;
1782 	uint8_t port_id;
1783 	cmdline_fixed_string_t rss_hash_key;
1784 	cmdline_fixed_string_t rss_type;
1785 	cmdline_fixed_string_t key;
1786 };
1787 
1788 static uint8_t
1789 hexa_digit_to_value(char hexa_digit)
1790 {
1791 	if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1792 		return (uint8_t) (hexa_digit - '0');
1793 	if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1794 		return (uint8_t) ((hexa_digit - 'a') + 10);
1795 	if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1796 		return (uint8_t) ((hexa_digit - 'A') + 10);
1797 	/* Invalid hexa digit */
1798 	return 0xFF;
1799 }
1800 
1801 static uint8_t
1802 parse_and_check_key_hexa_digit(char *key, int idx)
1803 {
1804 	uint8_t hexa_v;
1805 
1806 	hexa_v = hexa_digit_to_value(key[idx]);
1807 	if (hexa_v == 0xFF)
1808 		printf("invalid key: character %c at position %d is not a "
1809 		       "valid hexa digit\n", key[idx], idx);
1810 	return hexa_v;
1811 }
1812 
1813 static void
1814 cmd_config_rss_hash_key_parsed(void *parsed_result,
1815 			       __attribute__((unused)) struct cmdline *cl,
1816 			       __attribute__((unused)) void *data)
1817 {
1818 	struct cmd_config_rss_hash_key *res = parsed_result;
1819 	uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1820 	uint8_t xdgt0;
1821 	uint8_t xdgt1;
1822 	int i;
1823 	struct rte_eth_dev_info dev_info;
1824 	uint8_t hash_key_size;
1825 	uint32_t key_len;
1826 
1827 	memset(&dev_info, 0, sizeof(dev_info));
1828 	rte_eth_dev_info_get(res->port_id, &dev_info);
1829 	if (dev_info.hash_key_size > 0 &&
1830 			dev_info.hash_key_size <= sizeof(hash_key))
1831 		hash_key_size = dev_info.hash_key_size;
1832 	else {
1833 		printf("dev_info did not provide a valid hash key size\n");
1834 		return;
1835 	}
1836 	/* Check the length of the RSS hash key */
1837 	key_len = strlen(res->key);
1838 	if (key_len != (hash_key_size * 2)) {
1839 		printf("key length: %d invalid - key must be a string of %d"
1840 			   " hexa-decimal numbers\n",
1841 			   (int) key_len, hash_key_size * 2);
1842 		return;
1843 	}
1844 	/* Translate RSS hash key into binary representation */
1845 	for (i = 0; i < hash_key_size; i++) {
1846 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1847 		if (xdgt0 == 0xFF)
1848 			return;
1849 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1850 		if (xdgt1 == 0xFF)
1851 			return;
1852 		hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1853 	}
1854 	port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1855 			hash_key_size);
1856 }
1857 
1858 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1859 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1860 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1861 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1862 				 "config");
1863 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1864 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1865 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1866 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1867 				 rss_hash_key, "rss-hash-key");
1868 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1869 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1870 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1871 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1872 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1873 				 "ipv6-tcp-ex#ipv6-udp-ex");
1874 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1875 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1876 
1877 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1878 	.f = cmd_config_rss_hash_key_parsed,
1879 	.data = NULL,
1880 	.help_str = "port config <port_id> rss-hash-key "
1881 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1882 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1883 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
1884 		"<string of hex digits (variable length, NIC dependent)>",
1885 	.tokens = {
1886 		(void *)&cmd_config_rss_hash_key_port,
1887 		(void *)&cmd_config_rss_hash_key_config,
1888 		(void *)&cmd_config_rss_hash_key_port_id,
1889 		(void *)&cmd_config_rss_hash_key_rss_hash_key,
1890 		(void *)&cmd_config_rss_hash_key_rss_type,
1891 		(void *)&cmd_config_rss_hash_key_value,
1892 		NULL,
1893 	},
1894 };
1895 
1896 /* *** configure port rxq/txq start/stop *** */
1897 struct cmd_config_rxtx_queue {
1898 	cmdline_fixed_string_t port;
1899 	uint8_t portid;
1900 	cmdline_fixed_string_t rxtxq;
1901 	uint16_t qid;
1902 	cmdline_fixed_string_t opname;
1903 };
1904 
1905 static void
1906 cmd_config_rxtx_queue_parsed(void *parsed_result,
1907 			__attribute__((unused)) struct cmdline *cl,
1908 			__attribute__((unused)) void *data)
1909 {
1910 	struct cmd_config_rxtx_queue *res = parsed_result;
1911 	uint8_t isrx;
1912 	uint8_t isstart;
1913 	int ret = 0;
1914 
1915 	if (test_done == 0) {
1916 		printf("Please stop forwarding first\n");
1917 		return;
1918 	}
1919 
1920 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
1921 		return;
1922 
1923 	if (port_is_started(res->portid) != 1) {
1924 		printf("Please start port %u first\n", res->portid);
1925 		return;
1926 	}
1927 
1928 	if (!strcmp(res->rxtxq, "rxq"))
1929 		isrx = 1;
1930 	else if (!strcmp(res->rxtxq, "txq"))
1931 		isrx = 0;
1932 	else {
1933 		printf("Unknown parameter\n");
1934 		return;
1935 	}
1936 
1937 	if (isrx && rx_queue_id_is_invalid(res->qid))
1938 		return;
1939 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
1940 		return;
1941 
1942 	if (!strcmp(res->opname, "start"))
1943 		isstart = 1;
1944 	else if (!strcmp(res->opname, "stop"))
1945 		isstart = 0;
1946 	else {
1947 		printf("Unknown parameter\n");
1948 		return;
1949 	}
1950 
1951 	if (isstart && isrx)
1952 		ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1953 	else if (!isstart && isrx)
1954 		ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1955 	else if (isstart && !isrx)
1956 		ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1957 	else
1958 		ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1959 
1960 	if (ret == -ENOTSUP)
1961 		printf("Function not supported in PMD driver\n");
1962 }
1963 
1964 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1965 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1966 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1967 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1968 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1969 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1970 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1971 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
1972 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
1973 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
1974 						"start#stop");
1975 
1976 cmdline_parse_inst_t cmd_config_rxtx_queue = {
1977 	.f = cmd_config_rxtx_queue_parsed,
1978 	.data = NULL,
1979 	.help_str = "port <port_id> rxq|txq <queue_id> start|stop",
1980 	.tokens = {
1981 		(void *)&cmd_config_speed_all_port,
1982 		(void *)&cmd_config_rxtx_queue_portid,
1983 		(void *)&cmd_config_rxtx_queue_rxtxq,
1984 		(void *)&cmd_config_rxtx_queue_qid,
1985 		(void *)&cmd_config_rxtx_queue_opname,
1986 		NULL,
1987 	},
1988 };
1989 
1990 /* *** Configure RSS RETA *** */
1991 struct cmd_config_rss_reta {
1992 	cmdline_fixed_string_t port;
1993 	cmdline_fixed_string_t keyword;
1994 	uint8_t port_id;
1995 	cmdline_fixed_string_t name;
1996 	cmdline_fixed_string_t list_name;
1997 	cmdline_fixed_string_t list_of_items;
1998 };
1999 
2000 static int
2001 parse_reta_config(const char *str,
2002 		  struct rte_eth_rss_reta_entry64 *reta_conf,
2003 		  uint16_t nb_entries)
2004 {
2005 	int i;
2006 	unsigned size;
2007 	uint16_t hash_index, idx, shift;
2008 	uint16_t nb_queue;
2009 	char s[256];
2010 	const char *p, *p0 = str;
2011 	char *end;
2012 	enum fieldnames {
2013 		FLD_HASH_INDEX = 0,
2014 		FLD_QUEUE,
2015 		_NUM_FLD
2016 	};
2017 	unsigned long int_fld[_NUM_FLD];
2018 	char *str_fld[_NUM_FLD];
2019 
2020 	while ((p = strchr(p0,'(')) != NULL) {
2021 		++p;
2022 		if((p0 = strchr(p,')')) == NULL)
2023 			return -1;
2024 
2025 		size = p0 - p;
2026 		if(size >= sizeof(s))
2027 			return -1;
2028 
2029 		snprintf(s, sizeof(s), "%.*s", size, p);
2030 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2031 			return -1;
2032 		for (i = 0; i < _NUM_FLD; i++) {
2033 			errno = 0;
2034 			int_fld[i] = strtoul(str_fld[i], &end, 0);
2035 			if (errno != 0 || end == str_fld[i] ||
2036 					int_fld[i] > 65535)
2037 				return -1;
2038 		}
2039 
2040 		hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2041 		nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2042 
2043 		if (hash_index >= nb_entries) {
2044 			printf("Invalid RETA hash index=%d\n", hash_index);
2045 			return -1;
2046 		}
2047 
2048 		idx = hash_index / RTE_RETA_GROUP_SIZE;
2049 		shift = hash_index % RTE_RETA_GROUP_SIZE;
2050 		reta_conf[idx].mask |= (1ULL << shift);
2051 		reta_conf[idx].reta[shift] = nb_queue;
2052 	}
2053 
2054 	return 0;
2055 }
2056 
2057 static void
2058 cmd_set_rss_reta_parsed(void *parsed_result,
2059 			__attribute__((unused)) struct cmdline *cl,
2060 			__attribute__((unused)) void *data)
2061 {
2062 	int ret;
2063 	struct rte_eth_dev_info dev_info;
2064 	struct rte_eth_rss_reta_entry64 reta_conf[8];
2065 	struct cmd_config_rss_reta *res = parsed_result;
2066 
2067 	memset(&dev_info, 0, sizeof(dev_info));
2068 	rte_eth_dev_info_get(res->port_id, &dev_info);
2069 	if (dev_info.reta_size == 0) {
2070 		printf("Redirection table size is 0 which is "
2071 					"invalid for RSS\n");
2072 		return;
2073 	} else
2074 		printf("The reta size of port %d is %u\n",
2075 			res->port_id, dev_info.reta_size);
2076 	if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2077 		printf("Currently do not support more than %u entries of "
2078 			"redirection table\n", ETH_RSS_RETA_SIZE_512);
2079 		return;
2080 	}
2081 
2082 	memset(reta_conf, 0, sizeof(reta_conf));
2083 	if (!strcmp(res->list_name, "reta")) {
2084 		if (parse_reta_config(res->list_of_items, reta_conf,
2085 						dev_info.reta_size)) {
2086 			printf("Invalid RSS Redirection Table "
2087 					"config entered\n");
2088 			return;
2089 		}
2090 		ret = rte_eth_dev_rss_reta_update(res->port_id,
2091 				reta_conf, dev_info.reta_size);
2092 		if (ret != 0)
2093 			printf("Bad redirection table parameter, "
2094 					"return code = %d \n", ret);
2095 	}
2096 }
2097 
2098 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2099 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2100 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2101 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2102 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2103 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
2104 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2105 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2106 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2107 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2108 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2109         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2110                                  NULL);
2111 cmdline_parse_inst_t cmd_config_rss_reta = {
2112 	.f = cmd_set_rss_reta_parsed,
2113 	.data = NULL,
2114 	.help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2115 	.tokens = {
2116 		(void *)&cmd_config_rss_reta_port,
2117 		(void *)&cmd_config_rss_reta_keyword,
2118 		(void *)&cmd_config_rss_reta_port_id,
2119 		(void *)&cmd_config_rss_reta_name,
2120 		(void *)&cmd_config_rss_reta_list_name,
2121 		(void *)&cmd_config_rss_reta_list_of_items,
2122 		NULL,
2123 	},
2124 };
2125 
2126 /* *** SHOW PORT RETA INFO *** */
2127 struct cmd_showport_reta {
2128 	cmdline_fixed_string_t show;
2129 	cmdline_fixed_string_t port;
2130 	uint8_t port_id;
2131 	cmdline_fixed_string_t rss;
2132 	cmdline_fixed_string_t reta;
2133 	uint16_t size;
2134 	cmdline_fixed_string_t list_of_items;
2135 };
2136 
2137 static int
2138 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2139 			   uint16_t nb_entries,
2140 			   char *str)
2141 {
2142 	uint32_t size;
2143 	const char *p, *p0 = str;
2144 	char s[256];
2145 	char *end;
2146 	char *str_fld[8];
2147 	uint16_t i;
2148 	uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2149 			RTE_RETA_GROUP_SIZE;
2150 	int ret;
2151 
2152 	p = strchr(p0, '(');
2153 	if (p == NULL)
2154 		return -1;
2155 	p++;
2156 	p0 = strchr(p, ')');
2157 	if (p0 == NULL)
2158 		return -1;
2159 	size = p0 - p;
2160 	if (size >= sizeof(s)) {
2161 		printf("The string size exceeds the internal buffer size\n");
2162 		return -1;
2163 	}
2164 	snprintf(s, sizeof(s), "%.*s", size, p);
2165 	ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2166 	if (ret <= 0 || ret != num) {
2167 		printf("The bits of masks do not match the number of "
2168 					"reta entries: %u\n", num);
2169 		return -1;
2170 	}
2171 	for (i = 0; i < ret; i++)
2172 		conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2173 
2174 	return 0;
2175 }
2176 
2177 static void
2178 cmd_showport_reta_parsed(void *parsed_result,
2179 			 __attribute__((unused)) struct cmdline *cl,
2180 			 __attribute__((unused)) void *data)
2181 {
2182 	struct cmd_showport_reta *res = parsed_result;
2183 	struct rte_eth_rss_reta_entry64 reta_conf[8];
2184 	struct rte_eth_dev_info dev_info;
2185 
2186 	memset(&dev_info, 0, sizeof(dev_info));
2187 	rte_eth_dev_info_get(res->port_id, &dev_info);
2188 	if (dev_info.reta_size == 0 || res->size != dev_info.reta_size ||
2189 				res->size > ETH_RSS_RETA_SIZE_512) {
2190 		printf("Invalid redirection table size: %u\n", res->size);
2191 		return;
2192 	}
2193 
2194 	memset(reta_conf, 0, sizeof(reta_conf));
2195 	if (showport_parse_reta_config(reta_conf, res->size,
2196 				res->list_of_items) < 0) {
2197 		printf("Invalid string: %s for reta masks\n",
2198 					res->list_of_items);
2199 		return;
2200 	}
2201 	port_rss_reta_info(res->port_id, reta_conf, res->size);
2202 }
2203 
2204 cmdline_parse_token_string_t cmd_showport_reta_show =
2205 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2206 cmdline_parse_token_string_t cmd_showport_reta_port =
2207 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2208 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2209 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
2210 cmdline_parse_token_string_t cmd_showport_reta_rss =
2211 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2212 cmdline_parse_token_string_t cmd_showport_reta_reta =
2213 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2214 cmdline_parse_token_num_t cmd_showport_reta_size =
2215 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2216 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2217 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2218 					list_of_items, NULL);
2219 
2220 cmdline_parse_inst_t cmd_showport_reta = {
2221 	.f = cmd_showport_reta_parsed,
2222 	.data = NULL,
2223 	.help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2224 	.tokens = {
2225 		(void *)&cmd_showport_reta_show,
2226 		(void *)&cmd_showport_reta_port,
2227 		(void *)&cmd_showport_reta_port_id,
2228 		(void *)&cmd_showport_reta_rss,
2229 		(void *)&cmd_showport_reta_reta,
2230 		(void *)&cmd_showport_reta_size,
2231 		(void *)&cmd_showport_reta_list_of_items,
2232 		NULL,
2233 	},
2234 };
2235 
2236 /* *** Show RSS hash configuration *** */
2237 struct cmd_showport_rss_hash {
2238 	cmdline_fixed_string_t show;
2239 	cmdline_fixed_string_t port;
2240 	uint8_t port_id;
2241 	cmdline_fixed_string_t rss_hash;
2242 	cmdline_fixed_string_t rss_type;
2243 	cmdline_fixed_string_t key; /* optional argument */
2244 };
2245 
2246 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2247 				__attribute__((unused)) struct cmdline *cl,
2248 				void *show_rss_key)
2249 {
2250 	struct cmd_showport_rss_hash *res = parsed_result;
2251 
2252 	port_rss_hash_conf_show(res->port_id, res->rss_type,
2253 				show_rss_key != NULL);
2254 }
2255 
2256 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2257 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2258 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2259 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2260 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2261 	TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
2262 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2263 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2264 				 "rss-hash");
2265 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2266 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2267 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2268 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2269 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2270 				 "ipv6-tcp-ex#ipv6-udp-ex");
2271 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2272 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2273 
2274 cmdline_parse_inst_t cmd_showport_rss_hash = {
2275 	.f = cmd_showport_rss_hash_parsed,
2276 	.data = NULL,
2277 	.help_str = "show port <port_id> rss-hash "
2278 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2279 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2280 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2281 	.tokens = {
2282 		(void *)&cmd_showport_rss_hash_show,
2283 		(void *)&cmd_showport_rss_hash_port,
2284 		(void *)&cmd_showport_rss_hash_port_id,
2285 		(void *)&cmd_showport_rss_hash_rss_hash,
2286 		(void *)&cmd_showport_rss_hash_rss_hash_info,
2287 		NULL,
2288 	},
2289 };
2290 
2291 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2292 	.f = cmd_showport_rss_hash_parsed,
2293 	.data = (void *)1,
2294 	.help_str = "show port <port_id> rss-hash "
2295 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2296 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2297 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2298 	.tokens = {
2299 		(void *)&cmd_showport_rss_hash_show,
2300 		(void *)&cmd_showport_rss_hash_port,
2301 		(void *)&cmd_showport_rss_hash_port_id,
2302 		(void *)&cmd_showport_rss_hash_rss_hash,
2303 		(void *)&cmd_showport_rss_hash_rss_hash_info,
2304 		(void *)&cmd_showport_rss_hash_rss_key,
2305 		NULL,
2306 	},
2307 };
2308 
2309 /* *** Configure DCB *** */
2310 struct cmd_config_dcb {
2311 	cmdline_fixed_string_t port;
2312 	cmdline_fixed_string_t config;
2313 	uint8_t port_id;
2314 	cmdline_fixed_string_t dcb;
2315 	cmdline_fixed_string_t vt;
2316 	cmdline_fixed_string_t vt_en;
2317 	uint8_t num_tcs;
2318 	cmdline_fixed_string_t pfc;
2319 	cmdline_fixed_string_t pfc_en;
2320 };
2321 
2322 static void
2323 cmd_config_dcb_parsed(void *parsed_result,
2324                         __attribute__((unused)) struct cmdline *cl,
2325                         __attribute__((unused)) void *data)
2326 {
2327 	struct cmd_config_dcb *res = parsed_result;
2328 	portid_t port_id = res->port_id;
2329 	struct rte_port *port;
2330 	uint8_t pfc_en;
2331 	int ret;
2332 
2333 	port = &ports[port_id];
2334 	/** Check if the port is not started **/
2335 	if (port->port_status != RTE_PORT_STOPPED) {
2336 		printf("Please stop port %d first\n", port_id);
2337 		return;
2338 	}
2339 
2340 	if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2341 		printf("The invalid number of traffic class,"
2342 			" only 4 or 8 allowed.\n");
2343 		return;
2344 	}
2345 
2346 	if (nb_fwd_lcores < res->num_tcs) {
2347 		printf("nb_cores shouldn't be less than number of TCs.\n");
2348 		return;
2349 	}
2350 	if (!strncmp(res->pfc_en, "on", 2))
2351 		pfc_en = 1;
2352 	else
2353 		pfc_en = 0;
2354 
2355 	/* DCB in VT mode */
2356 	if (!strncmp(res->vt_en, "on", 2))
2357 		ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2358 				(enum rte_eth_nb_tcs)res->num_tcs,
2359 				pfc_en);
2360 	else
2361 		ret = init_port_dcb_config(port_id, DCB_ENABLED,
2362 				(enum rte_eth_nb_tcs)res->num_tcs,
2363 				pfc_en);
2364 
2365 
2366 	if (ret != 0) {
2367 		printf("Cannot initialize network ports.\n");
2368 		return;
2369 	}
2370 
2371 	cmd_reconfig_device_queue(port_id, 1, 1);
2372 }
2373 
2374 cmdline_parse_token_string_t cmd_config_dcb_port =
2375         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2376 cmdline_parse_token_string_t cmd_config_dcb_config =
2377         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2378 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2379         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2380 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2381         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2382 cmdline_parse_token_string_t cmd_config_dcb_vt =
2383         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2384 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2385         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2386 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2387         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2388 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2389         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2390 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2391         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2392 
2393 cmdline_parse_inst_t cmd_config_dcb = {
2394 	.f = cmd_config_dcb_parsed,
2395 	.data = NULL,
2396 	.help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2397 	.tokens = {
2398 		(void *)&cmd_config_dcb_port,
2399 		(void *)&cmd_config_dcb_config,
2400 		(void *)&cmd_config_dcb_port_id,
2401 		(void *)&cmd_config_dcb_dcb,
2402 		(void *)&cmd_config_dcb_vt,
2403 		(void *)&cmd_config_dcb_vt_en,
2404 		(void *)&cmd_config_dcb_num_tcs,
2405 		(void *)&cmd_config_dcb_pfc,
2406 		(void *)&cmd_config_dcb_pfc_en,
2407                 NULL,
2408         },
2409 };
2410 
2411 /* *** configure number of packets per burst *** */
2412 struct cmd_config_burst {
2413 	cmdline_fixed_string_t port;
2414 	cmdline_fixed_string_t keyword;
2415 	cmdline_fixed_string_t all;
2416 	cmdline_fixed_string_t name;
2417 	uint16_t value;
2418 };
2419 
2420 static void
2421 cmd_config_burst_parsed(void *parsed_result,
2422 			__attribute__((unused)) struct cmdline *cl,
2423 			__attribute__((unused)) void *data)
2424 {
2425 	struct cmd_config_burst *res = parsed_result;
2426 
2427 	if (!all_ports_stopped()) {
2428 		printf("Please stop all ports first\n");
2429 		return;
2430 	}
2431 
2432 	if (!strcmp(res->name, "burst")) {
2433 		if (res->value < 1 || res->value > MAX_PKT_BURST) {
2434 			printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2435 			return;
2436 		}
2437 		nb_pkt_per_burst = res->value;
2438 	} else {
2439 		printf("Unknown parameter\n");
2440 		return;
2441 	}
2442 
2443 	init_port_config();
2444 
2445 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2446 }
2447 
2448 cmdline_parse_token_string_t cmd_config_burst_port =
2449 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2450 cmdline_parse_token_string_t cmd_config_burst_keyword =
2451 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2452 cmdline_parse_token_string_t cmd_config_burst_all =
2453 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2454 cmdline_parse_token_string_t cmd_config_burst_name =
2455 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2456 cmdline_parse_token_num_t cmd_config_burst_value =
2457 	TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2458 
2459 cmdline_parse_inst_t cmd_config_burst = {
2460 	.f = cmd_config_burst_parsed,
2461 	.data = NULL,
2462 	.help_str = "port config all burst <value>",
2463 	.tokens = {
2464 		(void *)&cmd_config_burst_port,
2465 		(void *)&cmd_config_burst_keyword,
2466 		(void *)&cmd_config_burst_all,
2467 		(void *)&cmd_config_burst_name,
2468 		(void *)&cmd_config_burst_value,
2469 		NULL,
2470 	},
2471 };
2472 
2473 /* *** configure rx/tx queues *** */
2474 struct cmd_config_thresh {
2475 	cmdline_fixed_string_t port;
2476 	cmdline_fixed_string_t keyword;
2477 	cmdline_fixed_string_t all;
2478 	cmdline_fixed_string_t name;
2479 	uint8_t value;
2480 };
2481 
2482 static void
2483 cmd_config_thresh_parsed(void *parsed_result,
2484 			__attribute__((unused)) struct cmdline *cl,
2485 			__attribute__((unused)) void *data)
2486 {
2487 	struct cmd_config_thresh *res = parsed_result;
2488 
2489 	if (!all_ports_stopped()) {
2490 		printf("Please stop all ports first\n");
2491 		return;
2492 	}
2493 
2494 	if (!strcmp(res->name, "txpt"))
2495 		tx_pthresh = res->value;
2496 	else if(!strcmp(res->name, "txht"))
2497 		tx_hthresh = res->value;
2498 	else if(!strcmp(res->name, "txwt"))
2499 		tx_wthresh = res->value;
2500 	else if(!strcmp(res->name, "rxpt"))
2501 		rx_pthresh = res->value;
2502 	else if(!strcmp(res->name, "rxht"))
2503 		rx_hthresh = res->value;
2504 	else if(!strcmp(res->name, "rxwt"))
2505 		rx_wthresh = res->value;
2506 	else {
2507 		printf("Unknown parameter\n");
2508 		return;
2509 	}
2510 
2511 	init_port_config();
2512 
2513 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2514 }
2515 
2516 cmdline_parse_token_string_t cmd_config_thresh_port =
2517 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2518 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2519 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2520 cmdline_parse_token_string_t cmd_config_thresh_all =
2521 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2522 cmdline_parse_token_string_t cmd_config_thresh_name =
2523 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2524 				"txpt#txht#txwt#rxpt#rxht#rxwt");
2525 cmdline_parse_token_num_t cmd_config_thresh_value =
2526 	TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2527 
2528 cmdline_parse_inst_t cmd_config_thresh = {
2529 	.f = cmd_config_thresh_parsed,
2530 	.data = NULL,
2531 	.help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2532 	.tokens = {
2533 		(void *)&cmd_config_thresh_port,
2534 		(void *)&cmd_config_thresh_keyword,
2535 		(void *)&cmd_config_thresh_all,
2536 		(void *)&cmd_config_thresh_name,
2537 		(void *)&cmd_config_thresh_value,
2538 		NULL,
2539 	},
2540 };
2541 
2542 /* *** configure free/rs threshold *** */
2543 struct cmd_config_threshold {
2544 	cmdline_fixed_string_t port;
2545 	cmdline_fixed_string_t keyword;
2546 	cmdline_fixed_string_t all;
2547 	cmdline_fixed_string_t name;
2548 	uint16_t value;
2549 };
2550 
2551 static void
2552 cmd_config_threshold_parsed(void *parsed_result,
2553 			__attribute__((unused)) struct cmdline *cl,
2554 			__attribute__((unused)) void *data)
2555 {
2556 	struct cmd_config_threshold *res = parsed_result;
2557 
2558 	if (!all_ports_stopped()) {
2559 		printf("Please stop all ports first\n");
2560 		return;
2561 	}
2562 
2563 	if (!strcmp(res->name, "txfreet"))
2564 		tx_free_thresh = res->value;
2565 	else if (!strcmp(res->name, "txrst"))
2566 		tx_rs_thresh = res->value;
2567 	else if (!strcmp(res->name, "rxfreet"))
2568 		rx_free_thresh = res->value;
2569 	else {
2570 		printf("Unknown parameter\n");
2571 		return;
2572 	}
2573 
2574 	init_port_config();
2575 
2576 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2577 }
2578 
2579 cmdline_parse_token_string_t cmd_config_threshold_port =
2580 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2581 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2582 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2583 								"config");
2584 cmdline_parse_token_string_t cmd_config_threshold_all =
2585 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2586 cmdline_parse_token_string_t cmd_config_threshold_name =
2587 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2588 						"txfreet#txrst#rxfreet");
2589 cmdline_parse_token_num_t cmd_config_threshold_value =
2590 	TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2591 
2592 cmdline_parse_inst_t cmd_config_threshold = {
2593 	.f = cmd_config_threshold_parsed,
2594 	.data = NULL,
2595 	.help_str = "port config all txfreet|txrst|rxfreet <value>",
2596 	.tokens = {
2597 		(void *)&cmd_config_threshold_port,
2598 		(void *)&cmd_config_threshold_keyword,
2599 		(void *)&cmd_config_threshold_all,
2600 		(void *)&cmd_config_threshold_name,
2601 		(void *)&cmd_config_threshold_value,
2602 		NULL,
2603 	},
2604 };
2605 
2606 /* *** stop *** */
2607 struct cmd_stop_result {
2608 	cmdline_fixed_string_t stop;
2609 };
2610 
2611 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2612 			    __attribute__((unused)) struct cmdline *cl,
2613 			    __attribute__((unused)) void *data)
2614 {
2615 	stop_packet_forwarding();
2616 }
2617 
2618 cmdline_parse_token_string_t cmd_stop_stop =
2619 	TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2620 
2621 cmdline_parse_inst_t cmd_stop = {
2622 	.f = cmd_stop_parsed,
2623 	.data = NULL,
2624 	.help_str = "stop: Stop packet forwarding",
2625 	.tokens = {
2626 		(void *)&cmd_stop_stop,
2627 		NULL,
2628 	},
2629 };
2630 
2631 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2632 
2633 unsigned int
2634 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2635 		unsigned int *parsed_items, int check_unique_values)
2636 {
2637 	unsigned int nb_item;
2638 	unsigned int value;
2639 	unsigned int i;
2640 	unsigned int j;
2641 	int value_ok;
2642 	char c;
2643 
2644 	/*
2645 	 * First parse all items in the list and store their value.
2646 	 */
2647 	value = 0;
2648 	nb_item = 0;
2649 	value_ok = 0;
2650 	for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2651 		c = str[i];
2652 		if ((c >= '0') && (c <= '9')) {
2653 			value = (unsigned int) (value * 10 + (c - '0'));
2654 			value_ok = 1;
2655 			continue;
2656 		}
2657 		if (c != ',') {
2658 			printf("character %c is not a decimal digit\n", c);
2659 			return 0;
2660 		}
2661 		if (! value_ok) {
2662 			printf("No valid value before comma\n");
2663 			return 0;
2664 		}
2665 		if (nb_item < max_items) {
2666 			parsed_items[nb_item] = value;
2667 			value_ok = 0;
2668 			value = 0;
2669 		}
2670 		nb_item++;
2671 	}
2672 	if (nb_item >= max_items) {
2673 		printf("Number of %s = %u > %u (maximum items)\n",
2674 		       item_name, nb_item + 1, max_items);
2675 		return 0;
2676 	}
2677 	parsed_items[nb_item++] = value;
2678 	if (! check_unique_values)
2679 		return nb_item;
2680 
2681 	/*
2682 	 * Then, check that all values in the list are differents.
2683 	 * No optimization here...
2684 	 */
2685 	for (i = 0; i < nb_item; i++) {
2686 		for (j = i + 1; j < nb_item; j++) {
2687 			if (parsed_items[j] == parsed_items[i]) {
2688 				printf("duplicated %s %u at index %u and %u\n",
2689 				       item_name, parsed_items[i], i, j);
2690 				return 0;
2691 			}
2692 		}
2693 	}
2694 	return nb_item;
2695 }
2696 
2697 struct cmd_set_list_result {
2698 	cmdline_fixed_string_t cmd_keyword;
2699 	cmdline_fixed_string_t list_name;
2700 	cmdline_fixed_string_t list_of_items;
2701 };
2702 
2703 static void cmd_set_list_parsed(void *parsed_result,
2704 				__attribute__((unused)) struct cmdline *cl,
2705 				__attribute__((unused)) void *data)
2706 {
2707 	struct cmd_set_list_result *res;
2708 	union {
2709 		unsigned int lcorelist[RTE_MAX_LCORE];
2710 		unsigned int portlist[RTE_MAX_ETHPORTS];
2711 	} parsed_items;
2712 	unsigned int nb_item;
2713 
2714 	if (test_done == 0) {
2715 		printf("Please stop forwarding first\n");
2716 		return;
2717 	}
2718 
2719 	res = parsed_result;
2720 	if (!strcmp(res->list_name, "corelist")) {
2721 		nb_item = parse_item_list(res->list_of_items, "core",
2722 					  RTE_MAX_LCORE,
2723 					  parsed_items.lcorelist, 1);
2724 		if (nb_item > 0) {
2725 			set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2726 			fwd_config_setup();
2727 		}
2728 		return;
2729 	}
2730 	if (!strcmp(res->list_name, "portlist")) {
2731 		nb_item = parse_item_list(res->list_of_items, "port",
2732 					  RTE_MAX_ETHPORTS,
2733 					  parsed_items.portlist, 1);
2734 		if (nb_item > 0) {
2735 			set_fwd_ports_list(parsed_items.portlist, nb_item);
2736 			fwd_config_setup();
2737 		}
2738 	}
2739 }
2740 
2741 cmdline_parse_token_string_t cmd_set_list_keyword =
2742 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2743 				 "set");
2744 cmdline_parse_token_string_t cmd_set_list_name =
2745 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2746 				 "corelist#portlist");
2747 cmdline_parse_token_string_t cmd_set_list_of_items =
2748 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2749 				 NULL);
2750 
2751 cmdline_parse_inst_t cmd_set_fwd_list = {
2752 	.f = cmd_set_list_parsed,
2753 	.data = NULL,
2754 	.help_str = "set corelist|portlist <list0[,list1]*>",
2755 	.tokens = {
2756 		(void *)&cmd_set_list_keyword,
2757 		(void *)&cmd_set_list_name,
2758 		(void *)&cmd_set_list_of_items,
2759 		NULL,
2760 	},
2761 };
2762 
2763 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2764 
2765 struct cmd_setmask_result {
2766 	cmdline_fixed_string_t set;
2767 	cmdline_fixed_string_t mask;
2768 	uint64_t hexavalue;
2769 };
2770 
2771 static void cmd_set_mask_parsed(void *parsed_result,
2772 				__attribute__((unused)) struct cmdline *cl,
2773 				__attribute__((unused)) void *data)
2774 {
2775 	struct cmd_setmask_result *res = parsed_result;
2776 
2777 	if (test_done == 0) {
2778 		printf("Please stop forwarding first\n");
2779 		return;
2780 	}
2781 	if (!strcmp(res->mask, "coremask")) {
2782 		set_fwd_lcores_mask(res->hexavalue);
2783 		fwd_config_setup();
2784 	} else if (!strcmp(res->mask, "portmask")) {
2785 		set_fwd_ports_mask(res->hexavalue);
2786 		fwd_config_setup();
2787 	}
2788 }
2789 
2790 cmdline_parse_token_string_t cmd_setmask_set =
2791 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2792 cmdline_parse_token_string_t cmd_setmask_mask =
2793 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2794 				 "coremask#portmask");
2795 cmdline_parse_token_num_t cmd_setmask_value =
2796 	TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2797 
2798 cmdline_parse_inst_t cmd_set_fwd_mask = {
2799 	.f = cmd_set_mask_parsed,
2800 	.data = NULL,
2801 	.help_str = "set coremask|portmask <hexadecimal value>",
2802 	.tokens = {
2803 		(void *)&cmd_setmask_set,
2804 		(void *)&cmd_setmask_mask,
2805 		(void *)&cmd_setmask_value,
2806 		NULL,
2807 	},
2808 };
2809 
2810 /*
2811  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2812  */
2813 struct cmd_set_result {
2814 	cmdline_fixed_string_t set;
2815 	cmdline_fixed_string_t what;
2816 	uint16_t value;
2817 };
2818 
2819 static void cmd_set_parsed(void *parsed_result,
2820 			   __attribute__((unused)) struct cmdline *cl,
2821 			   __attribute__((unused)) void *data)
2822 {
2823 	struct cmd_set_result *res = parsed_result;
2824 	if (!strcmp(res->what, "nbport")) {
2825 		set_fwd_ports_number(res->value);
2826 		fwd_config_setup();
2827 	} else if (!strcmp(res->what, "nbcore")) {
2828 		set_fwd_lcores_number(res->value);
2829 		fwd_config_setup();
2830 	} else if (!strcmp(res->what, "burst"))
2831 		set_nb_pkt_per_burst(res->value);
2832 	else if (!strcmp(res->what, "verbose"))
2833 		set_verbose_level(res->value);
2834 }
2835 
2836 cmdline_parse_token_string_t cmd_set_set =
2837 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2838 cmdline_parse_token_string_t cmd_set_what =
2839 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2840 				 "nbport#nbcore#burst#verbose");
2841 cmdline_parse_token_num_t cmd_set_value =
2842 	TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2843 
2844 cmdline_parse_inst_t cmd_set_numbers = {
2845 	.f = cmd_set_parsed,
2846 	.data = NULL,
2847 	.help_str = "set nbport|nbcore|burst|verbose <value>",
2848 	.tokens = {
2849 		(void *)&cmd_set_set,
2850 		(void *)&cmd_set_what,
2851 		(void *)&cmd_set_value,
2852 		NULL,
2853 	},
2854 };
2855 
2856 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2857 
2858 struct cmd_set_txpkts_result {
2859 	cmdline_fixed_string_t cmd_keyword;
2860 	cmdline_fixed_string_t txpkts;
2861 	cmdline_fixed_string_t seg_lengths;
2862 };
2863 
2864 static void
2865 cmd_set_txpkts_parsed(void *parsed_result,
2866 		      __attribute__((unused)) struct cmdline *cl,
2867 		      __attribute__((unused)) void *data)
2868 {
2869 	struct cmd_set_txpkts_result *res;
2870 	unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2871 	unsigned int nb_segs;
2872 
2873 	res = parsed_result;
2874 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2875 				  RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2876 	if (nb_segs > 0)
2877 		set_tx_pkt_segments(seg_lengths, nb_segs);
2878 }
2879 
2880 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2881 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2882 				 cmd_keyword, "set");
2883 cmdline_parse_token_string_t cmd_set_txpkts_name =
2884 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2885 				 txpkts, "txpkts");
2886 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2887 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2888 				 seg_lengths, NULL);
2889 
2890 cmdline_parse_inst_t cmd_set_txpkts = {
2891 	.f = cmd_set_txpkts_parsed,
2892 	.data = NULL,
2893 	.help_str = "set txpkts <len0[,len1]*>",
2894 	.tokens = {
2895 		(void *)&cmd_set_txpkts_keyword,
2896 		(void *)&cmd_set_txpkts_name,
2897 		(void *)&cmd_set_txpkts_lengths,
2898 		NULL,
2899 	},
2900 };
2901 
2902 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2903 
2904 struct cmd_set_txsplit_result {
2905 	cmdline_fixed_string_t cmd_keyword;
2906 	cmdline_fixed_string_t txsplit;
2907 	cmdline_fixed_string_t mode;
2908 };
2909 
2910 static void
2911 cmd_set_txsplit_parsed(void *parsed_result,
2912 		      __attribute__((unused)) struct cmdline *cl,
2913 		      __attribute__((unused)) void *data)
2914 {
2915 	struct cmd_set_txsplit_result *res;
2916 
2917 	res = parsed_result;
2918 	set_tx_pkt_split(res->mode);
2919 }
2920 
2921 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2922 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2923 				 cmd_keyword, "set");
2924 cmdline_parse_token_string_t cmd_set_txsplit_name =
2925 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2926 				 txsplit, "txsplit");
2927 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2928 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2929 				 mode, NULL);
2930 
2931 cmdline_parse_inst_t cmd_set_txsplit = {
2932 	.f = cmd_set_txsplit_parsed,
2933 	.data = NULL,
2934 	.help_str = "set txsplit on|off|rand",
2935 	.tokens = {
2936 		(void *)&cmd_set_txsplit_keyword,
2937 		(void *)&cmd_set_txsplit_name,
2938 		(void *)&cmd_set_txsplit_mode,
2939 		NULL,
2940 	},
2941 };
2942 
2943 /* *** CONFIG TX QUEUE FLAGS *** */
2944 
2945 struct cmd_config_txqflags_result {
2946 	cmdline_fixed_string_t port;
2947 	cmdline_fixed_string_t config;
2948 	cmdline_fixed_string_t all;
2949 	cmdline_fixed_string_t what;
2950 	int32_t hexvalue;
2951 };
2952 
2953 static void cmd_config_txqflags_parsed(void *parsed_result,
2954 				__attribute__((unused)) struct cmdline *cl,
2955 				__attribute__((unused)) void *data)
2956 {
2957 	struct cmd_config_txqflags_result *res = parsed_result;
2958 
2959 	if (!all_ports_stopped()) {
2960 		printf("Please stop all ports first\n");
2961 		return;
2962 	}
2963 
2964 	if (strcmp(res->what, "txqflags")) {
2965 		printf("Unknown parameter\n");
2966 		return;
2967 	}
2968 
2969 	if (res->hexvalue >= 0) {
2970 		txq_flags = res->hexvalue;
2971 	} else {
2972 		printf("txqflags must be >= 0\n");
2973 		return;
2974 	}
2975 
2976 	init_port_config();
2977 
2978 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2979 }
2980 
2981 cmdline_parse_token_string_t cmd_config_txqflags_port =
2982 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
2983 				 "port");
2984 cmdline_parse_token_string_t cmd_config_txqflags_config =
2985 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
2986 				 "config");
2987 cmdline_parse_token_string_t cmd_config_txqflags_all =
2988 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
2989 				 "all");
2990 cmdline_parse_token_string_t cmd_config_txqflags_what =
2991 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
2992 				 "txqflags");
2993 cmdline_parse_token_num_t cmd_config_txqflags_value =
2994 	TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
2995 				hexvalue, INT32);
2996 
2997 cmdline_parse_inst_t cmd_config_txqflags = {
2998 	.f = cmd_config_txqflags_parsed,
2999 	.data = NULL,
3000 	.help_str = "port config all txqflags <value>",
3001 	.tokens = {
3002 		(void *)&cmd_config_txqflags_port,
3003 		(void *)&cmd_config_txqflags_config,
3004 		(void *)&cmd_config_txqflags_all,
3005 		(void *)&cmd_config_txqflags_what,
3006 		(void *)&cmd_config_txqflags_value,
3007 		NULL,
3008 	},
3009 };
3010 
3011 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3012 struct cmd_rx_vlan_filter_all_result {
3013 	cmdline_fixed_string_t rx_vlan;
3014 	cmdline_fixed_string_t what;
3015 	cmdline_fixed_string_t all;
3016 	uint8_t port_id;
3017 };
3018 
3019 static void
3020 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3021 			      __attribute__((unused)) struct cmdline *cl,
3022 			      __attribute__((unused)) void *data)
3023 {
3024 	struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3025 
3026 	if (!strcmp(res->what, "add"))
3027 		rx_vlan_all_filter_set(res->port_id, 1);
3028 	else
3029 		rx_vlan_all_filter_set(res->port_id, 0);
3030 }
3031 
3032 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3033 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3034 				 rx_vlan, "rx_vlan");
3035 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3036 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3037 				 what, "add#rm");
3038 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3039 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3040 				 all, "all");
3041 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3042 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3043 			      port_id, UINT8);
3044 
3045 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3046 	.f = cmd_rx_vlan_filter_all_parsed,
3047 	.data = NULL,
3048 	.help_str = "rx_vlan add|rm all <port_id>: "
3049 		"Add/Remove all identifiers to/from the set of VLAN "
3050 		"identifiers filtered by a port",
3051 	.tokens = {
3052 		(void *)&cmd_rx_vlan_filter_all_rx_vlan,
3053 		(void *)&cmd_rx_vlan_filter_all_what,
3054 		(void *)&cmd_rx_vlan_filter_all_all,
3055 		(void *)&cmd_rx_vlan_filter_all_portid,
3056 		NULL,
3057 	},
3058 };
3059 
3060 /* *** VLAN OFFLOAD SET ON A PORT *** */
3061 struct cmd_vlan_offload_result {
3062 	cmdline_fixed_string_t vlan;
3063 	cmdline_fixed_string_t set;
3064 	cmdline_fixed_string_t vlan_type;
3065 	cmdline_fixed_string_t what;
3066 	cmdline_fixed_string_t on;
3067 	cmdline_fixed_string_t port_id;
3068 };
3069 
3070 static void
3071 cmd_vlan_offload_parsed(void *parsed_result,
3072 			  __attribute__((unused)) struct cmdline *cl,
3073 			  __attribute__((unused)) void *data)
3074 {
3075 	int on;
3076 	struct cmd_vlan_offload_result *res = parsed_result;
3077 	char *str;
3078 	int i, len = 0;
3079 	portid_t port_id = 0;
3080 	unsigned int tmp;
3081 
3082 	str = res->port_id;
3083 	len = strnlen(str, STR_TOKEN_SIZE);
3084 	i = 0;
3085 	/* Get port_id first */
3086 	while(i < len){
3087 		if(str[i] == ',')
3088 			break;
3089 
3090 		i++;
3091 	}
3092 	str[i]='\0';
3093 	tmp = strtoul(str, NULL, 0);
3094 	/* If port_id greater that what portid_t can represent, return */
3095 	if(tmp >= RTE_MAX_ETHPORTS)
3096 		return;
3097 	port_id = (portid_t)tmp;
3098 
3099 	if (!strcmp(res->on, "on"))
3100 		on = 1;
3101 	else
3102 		on = 0;
3103 
3104 	if (!strcmp(res->what, "strip"))
3105 		rx_vlan_strip_set(port_id,  on);
3106 	else if(!strcmp(res->what, "stripq")){
3107 		uint16_t queue_id = 0;
3108 
3109 		/* No queue_id, return */
3110 		if(i + 1 >= len) {
3111 			printf("must specify (port,queue_id)\n");
3112 			return;
3113 		}
3114 		tmp = strtoul(str + i + 1, NULL, 0);
3115 		/* If queue_id greater that what 16-bits can represent, return */
3116 		if(tmp > 0xffff)
3117 			return;
3118 
3119 		queue_id = (uint16_t)tmp;
3120 		rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3121 	}
3122 	else if (!strcmp(res->what, "filter"))
3123 		rx_vlan_filter_set(port_id, on);
3124 	else
3125 		vlan_extend_set(port_id, on);
3126 
3127 	return;
3128 }
3129 
3130 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3131 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3132 				 vlan, "vlan");
3133 cmdline_parse_token_string_t cmd_vlan_offload_set =
3134 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3135 				 set, "set");
3136 cmdline_parse_token_string_t cmd_vlan_offload_what =
3137 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3138 				 what, "strip#filter#qinq#stripq");
3139 cmdline_parse_token_string_t cmd_vlan_offload_on =
3140 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3141 			      on, "on#off");
3142 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3143 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3144 			      port_id, NULL);
3145 
3146 cmdline_parse_inst_t cmd_vlan_offload = {
3147 	.f = cmd_vlan_offload_parsed,
3148 	.data = NULL,
3149 	.help_str = "vlan set strip|filter|qinq|stripq on|off "
3150 		"<port_id[,queue_id]>: "
3151 		"Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3152 	.tokens = {
3153 		(void *)&cmd_vlan_offload_vlan,
3154 		(void *)&cmd_vlan_offload_set,
3155 		(void *)&cmd_vlan_offload_what,
3156 		(void *)&cmd_vlan_offload_on,
3157 		(void *)&cmd_vlan_offload_portid,
3158 		NULL,
3159 	},
3160 };
3161 
3162 /* *** VLAN TPID SET ON A PORT *** */
3163 struct cmd_vlan_tpid_result {
3164 	cmdline_fixed_string_t vlan;
3165 	cmdline_fixed_string_t set;
3166 	cmdline_fixed_string_t vlan_type;
3167 	cmdline_fixed_string_t what;
3168 	uint16_t tp_id;
3169 	uint8_t port_id;
3170 };
3171 
3172 static void
3173 cmd_vlan_tpid_parsed(void *parsed_result,
3174 			  __attribute__((unused)) struct cmdline *cl,
3175 			  __attribute__((unused)) void *data)
3176 {
3177 	struct cmd_vlan_tpid_result *res = parsed_result;
3178 	enum rte_vlan_type vlan_type;
3179 
3180 	if (!strcmp(res->vlan_type, "inner"))
3181 		vlan_type = ETH_VLAN_TYPE_INNER;
3182 	else if (!strcmp(res->vlan_type, "outer"))
3183 		vlan_type = ETH_VLAN_TYPE_OUTER;
3184 	else {
3185 		printf("Unknown vlan type\n");
3186 		return;
3187 	}
3188 	vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3189 }
3190 
3191 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3192 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3193 				 vlan, "vlan");
3194 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3195 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3196 				 set, "set");
3197 cmdline_parse_token_string_t cmd_vlan_type =
3198 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3199 				 vlan_type, "inner#outer");
3200 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3201 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3202 				 what, "tpid");
3203 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3204 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3205 			      tp_id, UINT16);
3206 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3207 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3208 			      port_id, UINT8);
3209 
3210 cmdline_parse_inst_t cmd_vlan_tpid = {
3211 	.f = cmd_vlan_tpid_parsed,
3212 	.data = NULL,
3213 	.help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3214 		"Set the VLAN Ether type",
3215 	.tokens = {
3216 		(void *)&cmd_vlan_tpid_vlan,
3217 		(void *)&cmd_vlan_tpid_set,
3218 		(void *)&cmd_vlan_type,
3219 		(void *)&cmd_vlan_tpid_what,
3220 		(void *)&cmd_vlan_tpid_tpid,
3221 		(void *)&cmd_vlan_tpid_portid,
3222 		NULL,
3223 	},
3224 };
3225 
3226 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3227 struct cmd_rx_vlan_filter_result {
3228 	cmdline_fixed_string_t rx_vlan;
3229 	cmdline_fixed_string_t what;
3230 	uint16_t vlan_id;
3231 	uint8_t port_id;
3232 };
3233 
3234 static void
3235 cmd_rx_vlan_filter_parsed(void *parsed_result,
3236 			  __attribute__((unused)) struct cmdline *cl,
3237 			  __attribute__((unused)) void *data)
3238 {
3239 	struct cmd_rx_vlan_filter_result *res = parsed_result;
3240 
3241 	if (!strcmp(res->what, "add"))
3242 		rx_vft_set(res->port_id, res->vlan_id, 1);
3243 	else
3244 		rx_vft_set(res->port_id, res->vlan_id, 0);
3245 }
3246 
3247 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3248 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3249 				 rx_vlan, "rx_vlan");
3250 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3251 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3252 				 what, "add#rm");
3253 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3254 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3255 			      vlan_id, UINT16);
3256 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3257 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3258 			      port_id, UINT8);
3259 
3260 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3261 	.f = cmd_rx_vlan_filter_parsed,
3262 	.data = NULL,
3263 	.help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3264 		"Add/Remove a VLAN identifier to/from the set of VLAN "
3265 		"identifiers filtered by a port",
3266 	.tokens = {
3267 		(void *)&cmd_rx_vlan_filter_rx_vlan,
3268 		(void *)&cmd_rx_vlan_filter_what,
3269 		(void *)&cmd_rx_vlan_filter_vlanid,
3270 		(void *)&cmd_rx_vlan_filter_portid,
3271 		NULL,
3272 	},
3273 };
3274 
3275 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3276 struct cmd_tx_vlan_set_result {
3277 	cmdline_fixed_string_t tx_vlan;
3278 	cmdline_fixed_string_t set;
3279 	uint8_t port_id;
3280 	uint16_t vlan_id;
3281 };
3282 
3283 static void
3284 cmd_tx_vlan_set_parsed(void *parsed_result,
3285 		       __attribute__((unused)) struct cmdline *cl,
3286 		       __attribute__((unused)) void *data)
3287 {
3288 	struct cmd_tx_vlan_set_result *res = parsed_result;
3289 
3290 	tx_vlan_set(res->port_id, res->vlan_id);
3291 }
3292 
3293 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3294 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3295 				 tx_vlan, "tx_vlan");
3296 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3297 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3298 				 set, "set");
3299 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3300 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3301 			      port_id, UINT8);
3302 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3303 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3304 			      vlan_id, UINT16);
3305 
3306 cmdline_parse_inst_t cmd_tx_vlan_set = {
3307 	.f = cmd_tx_vlan_set_parsed,
3308 	.data = NULL,
3309 	.help_str = "tx_vlan set <port_id> <vlan_id>: "
3310 		"Enable hardware insertion of a single VLAN header "
3311 		"with a given TAG Identifier in packets sent on a port",
3312 	.tokens = {
3313 		(void *)&cmd_tx_vlan_set_tx_vlan,
3314 		(void *)&cmd_tx_vlan_set_set,
3315 		(void *)&cmd_tx_vlan_set_portid,
3316 		(void *)&cmd_tx_vlan_set_vlanid,
3317 		NULL,
3318 	},
3319 };
3320 
3321 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3322 struct cmd_tx_vlan_set_qinq_result {
3323 	cmdline_fixed_string_t tx_vlan;
3324 	cmdline_fixed_string_t set;
3325 	uint8_t port_id;
3326 	uint16_t vlan_id;
3327 	uint16_t vlan_id_outer;
3328 };
3329 
3330 static void
3331 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3332 			    __attribute__((unused)) struct cmdline *cl,
3333 			    __attribute__((unused)) void *data)
3334 {
3335 	struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3336 
3337 	tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3338 }
3339 
3340 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3341 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3342 		tx_vlan, "tx_vlan");
3343 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3344 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3345 		set, "set");
3346 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3347 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3348 		port_id, UINT8);
3349 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3350 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3351 		vlan_id, UINT16);
3352 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3353 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3354 		vlan_id_outer, UINT16);
3355 
3356 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3357 	.f = cmd_tx_vlan_set_qinq_parsed,
3358 	.data = NULL,
3359 	.help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3360 		"Enable hardware insertion of double VLAN header "
3361 		"with given TAG Identifiers in packets sent on a port",
3362 	.tokens = {
3363 		(void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3364 		(void *)&cmd_tx_vlan_set_qinq_set,
3365 		(void *)&cmd_tx_vlan_set_qinq_portid,
3366 		(void *)&cmd_tx_vlan_set_qinq_vlanid,
3367 		(void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3368 		NULL,
3369 	},
3370 };
3371 
3372 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3373 struct cmd_tx_vlan_set_pvid_result {
3374 	cmdline_fixed_string_t tx_vlan;
3375 	cmdline_fixed_string_t set;
3376 	cmdline_fixed_string_t pvid;
3377 	uint8_t port_id;
3378 	uint16_t vlan_id;
3379 	cmdline_fixed_string_t mode;
3380 };
3381 
3382 static void
3383 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3384 			    __attribute__((unused)) struct cmdline *cl,
3385 			    __attribute__((unused)) void *data)
3386 {
3387 	struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3388 
3389 	if (strcmp(res->mode, "on") == 0)
3390 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3391 	else
3392 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3393 }
3394 
3395 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3396 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3397 				 tx_vlan, "tx_vlan");
3398 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3399 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3400 				 set, "set");
3401 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3402 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3403 				 pvid, "pvid");
3404 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3405 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3406 			     port_id, UINT8);
3407 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3408 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3409 			      vlan_id, UINT16);
3410 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3411 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3412 				 mode, "on#off");
3413 
3414 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3415 	.f = cmd_tx_vlan_set_pvid_parsed,
3416 	.data = NULL,
3417 	.help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3418 	.tokens = {
3419 		(void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3420 		(void *)&cmd_tx_vlan_set_pvid_set,
3421 		(void *)&cmd_tx_vlan_set_pvid_pvid,
3422 		(void *)&cmd_tx_vlan_set_pvid_port_id,
3423 		(void *)&cmd_tx_vlan_set_pvid_vlan_id,
3424 		(void *)&cmd_tx_vlan_set_pvid_mode,
3425 		NULL,
3426 	},
3427 };
3428 
3429 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3430 struct cmd_tx_vlan_reset_result {
3431 	cmdline_fixed_string_t tx_vlan;
3432 	cmdline_fixed_string_t reset;
3433 	uint8_t port_id;
3434 };
3435 
3436 static void
3437 cmd_tx_vlan_reset_parsed(void *parsed_result,
3438 			 __attribute__((unused)) struct cmdline *cl,
3439 			 __attribute__((unused)) void *data)
3440 {
3441 	struct cmd_tx_vlan_reset_result *res = parsed_result;
3442 
3443 	tx_vlan_reset(res->port_id);
3444 }
3445 
3446 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3447 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3448 				 tx_vlan, "tx_vlan");
3449 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3450 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3451 				 reset, "reset");
3452 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3453 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3454 			      port_id, UINT8);
3455 
3456 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3457 	.f = cmd_tx_vlan_reset_parsed,
3458 	.data = NULL,
3459 	.help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3460 		"VLAN header in packets sent on a port",
3461 	.tokens = {
3462 		(void *)&cmd_tx_vlan_reset_tx_vlan,
3463 		(void *)&cmd_tx_vlan_reset_reset,
3464 		(void *)&cmd_tx_vlan_reset_portid,
3465 		NULL,
3466 	},
3467 };
3468 
3469 
3470 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3471 struct cmd_csum_result {
3472 	cmdline_fixed_string_t csum;
3473 	cmdline_fixed_string_t mode;
3474 	cmdline_fixed_string_t proto;
3475 	cmdline_fixed_string_t hwsw;
3476 	uint8_t port_id;
3477 };
3478 
3479 static void
3480 csum_show(int port_id)
3481 {
3482 	struct rte_eth_dev_info dev_info;
3483 	uint16_t ol_flags;
3484 
3485 	ol_flags = ports[port_id].tx_ol_flags;
3486 	printf("Parse tunnel is %s\n",
3487 		(ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3488 	printf("IP checksum offload is %s\n",
3489 		(ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3490 	printf("UDP checksum offload is %s\n",
3491 		(ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3492 	printf("TCP checksum offload is %s\n",
3493 		(ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3494 	printf("SCTP checksum offload is %s\n",
3495 		(ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3496 	printf("Outer-Ip checksum offload is %s\n",
3497 		(ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3498 
3499 	/* display warnings if configuration is not supported by the NIC */
3500 	rte_eth_dev_info_get(port_id, &dev_info);
3501 	if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3502 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3503 		printf("Warning: hardware IP checksum enabled but not "
3504 			"supported by port %d\n", port_id);
3505 	}
3506 	if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3507 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3508 		printf("Warning: hardware UDP checksum enabled but not "
3509 			"supported by port %d\n", port_id);
3510 	}
3511 	if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3512 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3513 		printf("Warning: hardware TCP checksum enabled but not "
3514 			"supported by port %d\n", port_id);
3515 	}
3516 	if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3517 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3518 		printf("Warning: hardware SCTP checksum enabled but not "
3519 			"supported by port %d\n", port_id);
3520 	}
3521 	if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3522 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3523 		printf("Warning: hardware outer IP checksum enabled but not "
3524 			"supported by port %d\n", port_id);
3525 	}
3526 }
3527 
3528 static void
3529 cmd_csum_parsed(void *parsed_result,
3530 		       __attribute__((unused)) struct cmdline *cl,
3531 		       __attribute__((unused)) void *data)
3532 {
3533 	struct cmd_csum_result *res = parsed_result;
3534 	int hw = 0;
3535 	uint16_t mask = 0;
3536 
3537 	if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3538 		printf("invalid port %d\n", res->port_id);
3539 		return;
3540 	}
3541 
3542 	if (!strcmp(res->mode, "set")) {
3543 
3544 		if (!strcmp(res->hwsw, "hw"))
3545 			hw = 1;
3546 
3547 		if (!strcmp(res->proto, "ip")) {
3548 			mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3549 		} else if (!strcmp(res->proto, "udp")) {
3550 			mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3551 		} else if (!strcmp(res->proto, "tcp")) {
3552 			mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3553 		} else if (!strcmp(res->proto, "sctp")) {
3554 			mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3555 		} else if (!strcmp(res->proto, "outer-ip")) {
3556 			mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3557 		}
3558 
3559 		if (hw)
3560 			ports[res->port_id].tx_ol_flags |= mask;
3561 		else
3562 			ports[res->port_id].tx_ol_flags &= (~mask);
3563 	}
3564 	csum_show(res->port_id);
3565 }
3566 
3567 cmdline_parse_token_string_t cmd_csum_csum =
3568 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3569 				csum, "csum");
3570 cmdline_parse_token_string_t cmd_csum_mode =
3571 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3572 				mode, "set");
3573 cmdline_parse_token_string_t cmd_csum_proto =
3574 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3575 				proto, "ip#tcp#udp#sctp#outer-ip");
3576 cmdline_parse_token_string_t cmd_csum_hwsw =
3577 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3578 				hwsw, "hw#sw");
3579 cmdline_parse_token_num_t cmd_csum_portid =
3580 	TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3581 				port_id, UINT8);
3582 
3583 cmdline_parse_inst_t cmd_csum_set = {
3584 	.f = cmd_csum_parsed,
3585 	.data = NULL,
3586 	.help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3587 		"Enable/Disable hardware calculation of L3/L4 checksum when "
3588 		"using csum forward engine",
3589 	.tokens = {
3590 		(void *)&cmd_csum_csum,
3591 		(void *)&cmd_csum_mode,
3592 		(void *)&cmd_csum_proto,
3593 		(void *)&cmd_csum_hwsw,
3594 		(void *)&cmd_csum_portid,
3595 		NULL,
3596 	},
3597 };
3598 
3599 cmdline_parse_token_string_t cmd_csum_mode_show =
3600 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3601 				mode, "show");
3602 
3603 cmdline_parse_inst_t cmd_csum_show = {
3604 	.f = cmd_csum_parsed,
3605 	.data = NULL,
3606 	.help_str = "csum show <port_id>: Show checksum offload configuration",
3607 	.tokens = {
3608 		(void *)&cmd_csum_csum,
3609 		(void *)&cmd_csum_mode_show,
3610 		(void *)&cmd_csum_portid,
3611 		NULL,
3612 	},
3613 };
3614 
3615 /* Enable/disable tunnel parsing */
3616 struct cmd_csum_tunnel_result {
3617 	cmdline_fixed_string_t csum;
3618 	cmdline_fixed_string_t parse;
3619 	cmdline_fixed_string_t onoff;
3620 	uint8_t port_id;
3621 };
3622 
3623 static void
3624 cmd_csum_tunnel_parsed(void *parsed_result,
3625 		       __attribute__((unused)) struct cmdline *cl,
3626 		       __attribute__((unused)) void *data)
3627 {
3628 	struct cmd_csum_tunnel_result *res = parsed_result;
3629 
3630 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3631 		return;
3632 
3633 	if (!strcmp(res->onoff, "on"))
3634 		ports[res->port_id].tx_ol_flags |=
3635 			TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3636 	else
3637 		ports[res->port_id].tx_ol_flags &=
3638 			(~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3639 
3640 	csum_show(res->port_id);
3641 }
3642 
3643 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3644 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3645 				csum, "csum");
3646 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3647 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3648 				parse, "parse_tunnel");
3649 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3650 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3651 				onoff, "on#off");
3652 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3653 	TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3654 				port_id, UINT8);
3655 
3656 cmdline_parse_inst_t cmd_csum_tunnel = {
3657 	.f = cmd_csum_tunnel_parsed,
3658 	.data = NULL,
3659 	.help_str = "csum parse_tunnel on|off <port_id>: "
3660 		"Enable/Disable parsing of tunnels for csum engine",
3661 	.tokens = {
3662 		(void *)&cmd_csum_tunnel_csum,
3663 		(void *)&cmd_csum_tunnel_parse,
3664 		(void *)&cmd_csum_tunnel_onoff,
3665 		(void *)&cmd_csum_tunnel_portid,
3666 		NULL,
3667 	},
3668 };
3669 
3670 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3671 struct cmd_tso_set_result {
3672 	cmdline_fixed_string_t tso;
3673 	cmdline_fixed_string_t mode;
3674 	uint16_t tso_segsz;
3675 	uint8_t port_id;
3676 };
3677 
3678 static void
3679 cmd_tso_set_parsed(void *parsed_result,
3680 		       __attribute__((unused)) struct cmdline *cl,
3681 		       __attribute__((unused)) void *data)
3682 {
3683 	struct cmd_tso_set_result *res = parsed_result;
3684 	struct rte_eth_dev_info dev_info;
3685 
3686 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3687 		return;
3688 
3689 	if (!strcmp(res->mode, "set"))
3690 		ports[res->port_id].tso_segsz = res->tso_segsz;
3691 
3692 	if (ports[res->port_id].tso_segsz == 0)
3693 		printf("TSO for non-tunneled packets is disabled\n");
3694 	else
3695 		printf("TSO segment size for non-tunneled packets is %d\n",
3696 			ports[res->port_id].tso_segsz);
3697 
3698 	/* display warnings if configuration is not supported by the NIC */
3699 	rte_eth_dev_info_get(res->port_id, &dev_info);
3700 	if ((ports[res->port_id].tso_segsz != 0) &&
3701 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3702 		printf("Warning: TSO enabled but not "
3703 			"supported by port %d\n", res->port_id);
3704 	}
3705 }
3706 
3707 cmdline_parse_token_string_t cmd_tso_set_tso =
3708 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3709 				tso, "tso");
3710 cmdline_parse_token_string_t cmd_tso_set_mode =
3711 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3712 				mode, "set");
3713 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3714 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3715 				tso_segsz, UINT16);
3716 cmdline_parse_token_num_t cmd_tso_set_portid =
3717 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3718 				port_id, UINT8);
3719 
3720 cmdline_parse_inst_t cmd_tso_set = {
3721 	.f = cmd_tso_set_parsed,
3722 	.data = NULL,
3723 	.help_str = "tso set <tso_segsz> <port_id>: "
3724 		"Set TSO segment size of non-tunneled packets for csum engine "
3725 		"(0 to disable)",
3726 	.tokens = {
3727 		(void *)&cmd_tso_set_tso,
3728 		(void *)&cmd_tso_set_mode,
3729 		(void *)&cmd_tso_set_tso_segsz,
3730 		(void *)&cmd_tso_set_portid,
3731 		NULL,
3732 	},
3733 };
3734 
3735 cmdline_parse_token_string_t cmd_tso_show_mode =
3736 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3737 				mode, "show");
3738 
3739 
3740 cmdline_parse_inst_t cmd_tso_show = {
3741 	.f = cmd_tso_set_parsed,
3742 	.data = NULL,
3743 	.help_str = "tso show <port_id>: "
3744 		"Show TSO segment size of non-tunneled packets for csum engine",
3745 	.tokens = {
3746 		(void *)&cmd_tso_set_tso,
3747 		(void *)&cmd_tso_show_mode,
3748 		(void *)&cmd_tso_set_portid,
3749 		NULL,
3750 	},
3751 };
3752 
3753 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3754 struct cmd_tunnel_tso_set_result {
3755 	cmdline_fixed_string_t tso;
3756 	cmdline_fixed_string_t mode;
3757 	uint16_t tso_segsz;
3758 	uint8_t port_id;
3759 };
3760 
3761 static void
3762 check_tunnel_tso_nic_support(uint8_t port_id)
3763 {
3764 	struct rte_eth_dev_info dev_info;
3765 
3766 	rte_eth_dev_info_get(port_id, &dev_info);
3767 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3768 		printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3769 		       "supported by port %d\n", port_id);
3770 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3771 		printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3772 			"supported by port %d\n", port_id);
3773 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3774 		printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3775 		       "supported by port %d\n", port_id);
3776 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3777 		printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3778 		       "supported by port %d\n", port_id);
3779 }
3780 
3781 static void
3782 cmd_tunnel_tso_set_parsed(void *parsed_result,
3783 			  __attribute__((unused)) struct cmdline *cl,
3784 			  __attribute__((unused)) void *data)
3785 {
3786 	struct cmd_tunnel_tso_set_result *res = parsed_result;
3787 
3788 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3789 		return;
3790 
3791 	if (!strcmp(res->mode, "set"))
3792 		ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3793 
3794 	if (ports[res->port_id].tunnel_tso_segsz == 0)
3795 		printf("TSO for tunneled packets is disabled\n");
3796 	else {
3797 		printf("TSO segment size for tunneled packets is %d\n",
3798 			ports[res->port_id].tunnel_tso_segsz);
3799 
3800 		/* Below conditions are needed to make it work:
3801 		 * (1) tunnel TSO is supported by the NIC;
3802 		 * (2) "csum parse_tunnel" must be set so that tunneled pkts
3803 		 * are recognized;
3804 		 * (3) for tunneled pkts with outer L3 of IPv4,
3805 		 * "csum set outer-ip" must be set to hw, because after tso,
3806 		 * total_len of outer IP header is changed, and the checksum
3807 		 * of outer IP header calculated by sw should be wrong; that
3808 		 * is not necessary for IPv6 tunneled pkts because there's no
3809 		 * checksum in IP header anymore.
3810 		 */
3811 		check_tunnel_tso_nic_support(res->port_id);
3812 
3813 		if (!(ports[res->port_id].tx_ol_flags &
3814 		      TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3815 			printf("Warning: csum parse_tunnel must be set "
3816 				"so that tunneled packets are recognized\n");
3817 		if (!(ports[res->port_id].tx_ol_flags &
3818 		      TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3819 			printf("Warning: csum set outer-ip must be set to hw "
3820 				"if outer L3 is IPv4; not necessary for IPv6\n");
3821 	}
3822 }
3823 
3824 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3825 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3826 				tso, "tunnel_tso");
3827 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3828 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3829 				mode, "set");
3830 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3831 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3832 				tso_segsz, UINT16);
3833 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3834 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3835 				port_id, UINT8);
3836 
3837 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3838 	.f = cmd_tunnel_tso_set_parsed,
3839 	.data = NULL,
3840 	.help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3841 		"Set TSO segment size of tunneled packets for csum engine "
3842 		"(0 to disable)",
3843 	.tokens = {
3844 		(void *)&cmd_tunnel_tso_set_tso,
3845 		(void *)&cmd_tunnel_tso_set_mode,
3846 		(void *)&cmd_tunnel_tso_set_tso_segsz,
3847 		(void *)&cmd_tunnel_tso_set_portid,
3848 		NULL,
3849 	},
3850 };
3851 
3852 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3853 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3854 				mode, "show");
3855 
3856 
3857 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3858 	.f = cmd_tunnel_tso_set_parsed,
3859 	.data = NULL,
3860 	.help_str = "tunnel_tso show <port_id> "
3861 		"Show TSO segment size of tunneled packets for csum engine",
3862 	.tokens = {
3863 		(void *)&cmd_tunnel_tso_set_tso,
3864 		(void *)&cmd_tunnel_tso_show_mode,
3865 		(void *)&cmd_tunnel_tso_set_portid,
3866 		NULL,
3867 	},
3868 };
3869 
3870 /* *** SET GRO FOR A PORT *** */
3871 struct cmd_gro_result {
3872 	cmdline_fixed_string_t cmd_keyword;
3873 	cmdline_fixed_string_t mode;
3874 	uint8_t port_id;
3875 };
3876 
3877 static void
3878 cmd_enable_gro_parsed(void *parsed_result,
3879 		__attribute__((unused)) struct cmdline *cl,
3880 		__attribute__((unused)) void *data)
3881 {
3882 	struct cmd_gro_result *res;
3883 
3884 	res = parsed_result;
3885 	setup_gro(res->mode, res->port_id);
3886 }
3887 
3888 cmdline_parse_token_string_t cmd_gro_keyword =
3889 	TOKEN_STRING_INITIALIZER(struct cmd_gro_result,
3890 			cmd_keyword, "gro");
3891 cmdline_parse_token_string_t cmd_gro_mode =
3892 	TOKEN_STRING_INITIALIZER(struct cmd_gro_result,
3893 			mode, "on#off");
3894 cmdline_parse_token_num_t cmd_gro_pid =
3895 	TOKEN_NUM_INITIALIZER(struct cmd_gro_result,
3896 			port_id, UINT8);
3897 
3898 cmdline_parse_inst_t cmd_enable_gro = {
3899 	.f = cmd_enable_gro_parsed,
3900 	.data = NULL,
3901 	.help_str = "gro (on|off) (port_id)",
3902 	.tokens = {
3903 		(void *)&cmd_gro_keyword,
3904 		(void *)&cmd_gro_mode,
3905 		(void *)&cmd_gro_pid,
3906 		NULL,
3907 	},
3908 };
3909 
3910 /* *** SET MAX FLOW NUMBER AND ITEM NUM PER FLOW FOR GRO *** */
3911 struct cmd_gro_set_result {
3912 	cmdline_fixed_string_t gro;
3913 	cmdline_fixed_string_t mode;
3914 	uint16_t flow_num;
3915 	uint16_t item_num_per_flow;
3916 	uint8_t port_id;
3917 };
3918 
3919 static void
3920 cmd_gro_set_parsed(void *parsed_result,
3921 		       __attribute__((unused)) struct cmdline *cl,
3922 		       __attribute__((unused)) void *data)
3923 {
3924 	struct cmd_gro_set_result *res = parsed_result;
3925 
3926 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3927 		return;
3928 	if (test_done == 0) {
3929 		printf("Before set GRO flow_num and item_num_per_flow,"
3930 				" please stop forwarding first\n");
3931 		return;
3932 	}
3933 
3934 	if (!strcmp(res->mode, "set")) {
3935 		if (res->flow_num == 0)
3936 			printf("Invalid flow number. Revert to default value:"
3937 					" %u.\n", GRO_DEFAULT_FLOW_NUM);
3938 		else
3939 			gro_ports[res->port_id].param.max_flow_num =
3940 				res->flow_num;
3941 
3942 		if (res->item_num_per_flow == 0)
3943 			printf("Invalid item number per-flow. Revert"
3944 					" to default value:%u.\n",
3945 					GRO_DEFAULT_ITEM_NUM_PER_FLOW);
3946 		else
3947 			gro_ports[res->port_id].param.max_item_per_flow =
3948 				res->item_num_per_flow;
3949 	}
3950 }
3951 
3952 cmdline_parse_token_string_t cmd_gro_set_gro =
3953 	TOKEN_STRING_INITIALIZER(struct cmd_gro_set_result,
3954 				gro, "gro");
3955 cmdline_parse_token_string_t cmd_gro_set_mode =
3956 	TOKEN_STRING_INITIALIZER(struct cmd_gro_set_result,
3957 				mode, "set");
3958 cmdline_parse_token_num_t cmd_gro_set_flow_num =
3959 	TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result,
3960 				flow_num, UINT16);
3961 cmdline_parse_token_num_t cmd_gro_set_item_num_per_flow =
3962 	TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result,
3963 				item_num_per_flow, UINT16);
3964 cmdline_parse_token_num_t cmd_gro_set_portid =
3965 	TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result,
3966 				port_id, UINT8);
3967 
3968 cmdline_parse_inst_t cmd_gro_set = {
3969 	.f = cmd_gro_set_parsed,
3970 	.data = NULL,
3971 	.help_str = "gro set <max_flow_num> <max_item_num_per_flow> "
3972 		"<port_id>: set max flow number and max packet number per-flow "
3973 		"for GRO",
3974 	.tokens = {
3975 		(void *)&cmd_gro_set_gro,
3976 		(void *)&cmd_gro_set_mode,
3977 		(void *)&cmd_gro_set_flow_num,
3978 		(void *)&cmd_gro_set_item_num_per_flow,
3979 		(void *)&cmd_gro_set_portid,
3980 		NULL,
3981 	},
3982 };
3983 
3984 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
3985 struct cmd_set_flush_rx {
3986 	cmdline_fixed_string_t set;
3987 	cmdline_fixed_string_t flush_rx;
3988 	cmdline_fixed_string_t mode;
3989 };
3990 
3991 static void
3992 cmd_set_flush_rx_parsed(void *parsed_result,
3993 		__attribute__((unused)) struct cmdline *cl,
3994 		__attribute__((unused)) void *data)
3995 {
3996 	struct cmd_set_flush_rx *res = parsed_result;
3997 	no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3998 }
3999 
4000 cmdline_parse_token_string_t cmd_setflushrx_set =
4001 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4002 			set, "set");
4003 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4004 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4005 			flush_rx, "flush_rx");
4006 cmdline_parse_token_string_t cmd_setflushrx_mode =
4007 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4008 			mode, "on#off");
4009 
4010 
4011 cmdline_parse_inst_t cmd_set_flush_rx = {
4012 	.f = cmd_set_flush_rx_parsed,
4013 	.help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4014 	.data = NULL,
4015 	.tokens = {
4016 		(void *)&cmd_setflushrx_set,
4017 		(void *)&cmd_setflushrx_flush_rx,
4018 		(void *)&cmd_setflushrx_mode,
4019 		NULL,
4020 	},
4021 };
4022 
4023 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4024 struct cmd_set_link_check {
4025 	cmdline_fixed_string_t set;
4026 	cmdline_fixed_string_t link_check;
4027 	cmdline_fixed_string_t mode;
4028 };
4029 
4030 static void
4031 cmd_set_link_check_parsed(void *parsed_result,
4032 		__attribute__((unused)) struct cmdline *cl,
4033 		__attribute__((unused)) void *data)
4034 {
4035 	struct cmd_set_link_check *res = parsed_result;
4036 	no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4037 }
4038 
4039 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4040 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4041 			set, "set");
4042 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4043 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4044 			link_check, "link_check");
4045 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4046 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4047 			mode, "on#off");
4048 
4049 
4050 cmdline_parse_inst_t cmd_set_link_check = {
4051 	.f = cmd_set_link_check_parsed,
4052 	.help_str = "set link_check on|off: Enable/Disable link status check "
4053 	            "when starting/stopping a port",
4054 	.data = NULL,
4055 	.tokens = {
4056 		(void *)&cmd_setlinkcheck_set,
4057 		(void *)&cmd_setlinkcheck_link_check,
4058 		(void *)&cmd_setlinkcheck_mode,
4059 		NULL,
4060 	},
4061 };
4062 
4063 /* *** SET NIC BYPASS MODE *** */
4064 struct cmd_set_bypass_mode_result {
4065 	cmdline_fixed_string_t set;
4066 	cmdline_fixed_string_t bypass;
4067 	cmdline_fixed_string_t mode;
4068 	cmdline_fixed_string_t value;
4069 	uint8_t port_id;
4070 };
4071 
4072 static void
4073 cmd_set_bypass_mode_parsed(void *parsed_result,
4074 		__attribute__((unused)) struct cmdline *cl,
4075 		__attribute__((unused)) void *data)
4076 {
4077 	struct cmd_set_bypass_mode_result *res = parsed_result;
4078 	portid_t port_id = res->port_id;
4079 	int32_t rc = -EINVAL;
4080 
4081 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4082 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4083 
4084 	if (!strcmp(res->value, "bypass"))
4085 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4086 	else if (!strcmp(res->value, "isolate"))
4087 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4088 	else
4089 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4090 
4091 	/* Set the bypass mode for the relevant port. */
4092 	rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4093 #endif
4094 	if (rc != 0)
4095 		printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4096 }
4097 
4098 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4099 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4100 			set, "set");
4101 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4102 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4103 			bypass, "bypass");
4104 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4105 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4106 			mode, "mode");
4107 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4108 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4109 			value, "normal#bypass#isolate");
4110 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4111 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4112 				port_id, UINT8);
4113 
4114 cmdline_parse_inst_t cmd_set_bypass_mode = {
4115 	.f = cmd_set_bypass_mode_parsed,
4116 	.help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4117 	            "Set the NIC bypass mode for port_id",
4118 	.data = NULL,
4119 	.tokens = {
4120 		(void *)&cmd_setbypass_mode_set,
4121 		(void *)&cmd_setbypass_mode_bypass,
4122 		(void *)&cmd_setbypass_mode_mode,
4123 		(void *)&cmd_setbypass_mode_value,
4124 		(void *)&cmd_setbypass_mode_port,
4125 		NULL,
4126 	},
4127 };
4128 
4129 /* *** SET NIC BYPASS EVENT *** */
4130 struct cmd_set_bypass_event_result {
4131 	cmdline_fixed_string_t set;
4132 	cmdline_fixed_string_t bypass;
4133 	cmdline_fixed_string_t event;
4134 	cmdline_fixed_string_t event_value;
4135 	cmdline_fixed_string_t mode;
4136 	cmdline_fixed_string_t mode_value;
4137 	uint8_t port_id;
4138 };
4139 
4140 static void
4141 cmd_set_bypass_event_parsed(void *parsed_result,
4142 		__attribute__((unused)) struct cmdline *cl,
4143 		__attribute__((unused)) void *data)
4144 {
4145 	int32_t rc = -EINVAL;
4146 	struct cmd_set_bypass_event_result *res = parsed_result;
4147 	portid_t port_id = res->port_id;
4148 
4149 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4150 	uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4151 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4152 
4153 	if (!strcmp(res->event_value, "timeout"))
4154 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4155 	else if (!strcmp(res->event_value, "os_on"))
4156 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4157 	else if (!strcmp(res->event_value, "os_off"))
4158 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4159 	else if (!strcmp(res->event_value, "power_on"))
4160 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4161 	else if (!strcmp(res->event_value, "power_off"))
4162 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4163 	else
4164 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4165 
4166 	if (!strcmp(res->mode_value, "bypass"))
4167 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4168 	else if (!strcmp(res->mode_value, "isolate"))
4169 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4170 	else
4171 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4172 
4173 	/* Set the watchdog timeout. */
4174 	if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4175 
4176 		rc = -EINVAL;
4177 		if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4178 			rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4179 							   bypass_timeout);
4180 		}
4181 		if (rc != 0) {
4182 			printf("Failed to set timeout value %u "
4183 			"for port %d, errto code: %d.\n",
4184 			bypass_timeout, port_id, rc);
4185 		}
4186 	}
4187 
4188 	/* Set the bypass event to transition to bypass mode. */
4189 	rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4190 					      bypass_mode);
4191 #endif
4192 
4193 	if (rc != 0)
4194 		printf("\t Failed to set bypass event for port = %d.\n",
4195 		       port_id);
4196 }
4197 
4198 cmdline_parse_token_string_t cmd_setbypass_event_set =
4199 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4200 			set, "set");
4201 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4202 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4203 			bypass, "bypass");
4204 cmdline_parse_token_string_t cmd_setbypass_event_event =
4205 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4206 			event, "event");
4207 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4208 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4209 			event_value, "none#timeout#os_off#os_on#power_on#power_off");
4210 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4211 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4212 			mode, "mode");
4213 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4214 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4215 			mode_value, "normal#bypass#isolate");
4216 cmdline_parse_token_num_t cmd_setbypass_event_port =
4217 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4218 				port_id, UINT8);
4219 
4220 cmdline_parse_inst_t cmd_set_bypass_event = {
4221 	.f = cmd_set_bypass_event_parsed,
4222 	.help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4223 		"power_off mode normal|bypass|isolate <port_id>: "
4224 		"Set the NIC bypass event mode for port_id",
4225 	.data = NULL,
4226 	.tokens = {
4227 		(void *)&cmd_setbypass_event_set,
4228 		(void *)&cmd_setbypass_event_bypass,
4229 		(void *)&cmd_setbypass_event_event,
4230 		(void *)&cmd_setbypass_event_event_value,
4231 		(void *)&cmd_setbypass_event_mode,
4232 		(void *)&cmd_setbypass_event_mode_value,
4233 		(void *)&cmd_setbypass_event_port,
4234 		NULL,
4235 	},
4236 };
4237 
4238 
4239 /* *** SET NIC BYPASS TIMEOUT *** */
4240 struct cmd_set_bypass_timeout_result {
4241 	cmdline_fixed_string_t set;
4242 	cmdline_fixed_string_t bypass;
4243 	cmdline_fixed_string_t timeout;
4244 	cmdline_fixed_string_t value;
4245 };
4246 
4247 static void
4248 cmd_set_bypass_timeout_parsed(void *parsed_result,
4249 		__attribute__((unused)) struct cmdline *cl,
4250 		__attribute__((unused)) void *data)
4251 {
4252 	__rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4253 
4254 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4255 	if (!strcmp(res->value, "1.5"))
4256 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4257 	else if (!strcmp(res->value, "2"))
4258 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4259 	else if (!strcmp(res->value, "3"))
4260 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4261 	else if (!strcmp(res->value, "4"))
4262 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4263 	else if (!strcmp(res->value, "8"))
4264 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4265 	else if (!strcmp(res->value, "16"))
4266 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4267 	else if (!strcmp(res->value, "32"))
4268 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4269 	else
4270 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4271 #endif
4272 }
4273 
4274 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4275 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4276 			set, "set");
4277 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4278 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4279 			bypass, "bypass");
4280 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4281 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4282 			timeout, "timeout");
4283 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4284 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4285 			value, "0#1.5#2#3#4#8#16#32");
4286 
4287 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4288 	.f = cmd_set_bypass_timeout_parsed,
4289 	.help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4290 		"Set the NIC bypass watchdog timeout in seconds",
4291 	.data = NULL,
4292 	.tokens = {
4293 		(void *)&cmd_setbypass_timeout_set,
4294 		(void *)&cmd_setbypass_timeout_bypass,
4295 		(void *)&cmd_setbypass_timeout_timeout,
4296 		(void *)&cmd_setbypass_timeout_value,
4297 		NULL,
4298 	},
4299 };
4300 
4301 /* *** SHOW NIC BYPASS MODE *** */
4302 struct cmd_show_bypass_config_result {
4303 	cmdline_fixed_string_t show;
4304 	cmdline_fixed_string_t bypass;
4305 	cmdline_fixed_string_t config;
4306 	uint8_t port_id;
4307 };
4308 
4309 static void
4310 cmd_show_bypass_config_parsed(void *parsed_result,
4311 		__attribute__((unused)) struct cmdline *cl,
4312 		__attribute__((unused)) void *data)
4313 {
4314 	struct cmd_show_bypass_config_result *res = parsed_result;
4315 	portid_t port_id = res->port_id;
4316 	int rc = -EINVAL;
4317 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4318 	uint32_t event_mode;
4319 	uint32_t bypass_mode;
4320 	uint32_t timeout = bypass_timeout;
4321 	int i;
4322 
4323 	static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4324 		{"off", "1.5", "2", "3", "4", "8", "16", "32"};
4325 	static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4326 		{"UNKNOWN", "normal", "bypass", "isolate"};
4327 	static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4328 		"NONE",
4329 		"OS/board on",
4330 		"power supply on",
4331 		"OS/board off",
4332 		"power supply off",
4333 		"timeout"};
4334 	int num_events = (sizeof events) / (sizeof events[0]);
4335 
4336 	/* Display the bypass mode.*/
4337 	if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4338 		printf("\tFailed to get bypass mode for port = %d\n", port_id);
4339 		return;
4340 	}
4341 	else {
4342 		if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4343 			bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4344 
4345 		printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4346 	}
4347 
4348 	/* Display the bypass timeout.*/
4349 	if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4350 		timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4351 
4352 	printf("\tbypass timeout = %s\n", timeouts[timeout]);
4353 
4354 	/* Display the bypass events and associated modes. */
4355 	for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4356 
4357 		if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4358 			printf("\tFailed to get bypass mode for event = %s\n",
4359 				events[i]);
4360 		} else {
4361 			if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4362 				event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4363 
4364 			printf("\tbypass event: %-16s = %s\n", events[i],
4365 				modes[event_mode]);
4366 		}
4367 	}
4368 #endif
4369 	if (rc != 0)
4370 		printf("\tFailed to get bypass configuration for port = %d\n",
4371 		       port_id);
4372 }
4373 
4374 cmdline_parse_token_string_t cmd_showbypass_config_show =
4375 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4376 			show, "show");
4377 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4378 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4379 			bypass, "bypass");
4380 cmdline_parse_token_string_t cmd_showbypass_config_config =
4381 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4382 			config, "config");
4383 cmdline_parse_token_num_t cmd_showbypass_config_port =
4384 	TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4385 				port_id, UINT8);
4386 
4387 cmdline_parse_inst_t cmd_show_bypass_config = {
4388 	.f = cmd_show_bypass_config_parsed,
4389 	.help_str = "show bypass config <port_id>: "
4390 	            "Show the NIC bypass config for port_id",
4391 	.data = NULL,
4392 	.tokens = {
4393 		(void *)&cmd_showbypass_config_show,
4394 		(void *)&cmd_showbypass_config_bypass,
4395 		(void *)&cmd_showbypass_config_config,
4396 		(void *)&cmd_showbypass_config_port,
4397 		NULL,
4398 	},
4399 };
4400 
4401 #ifdef RTE_LIBRTE_PMD_BOND
4402 /* *** SET BONDING MODE *** */
4403 struct cmd_set_bonding_mode_result {
4404 	cmdline_fixed_string_t set;
4405 	cmdline_fixed_string_t bonding;
4406 	cmdline_fixed_string_t mode;
4407 	uint8_t value;
4408 	uint8_t port_id;
4409 };
4410 
4411 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4412 		__attribute__((unused))  struct cmdline *cl,
4413 		__attribute__((unused)) void *data)
4414 {
4415 	struct cmd_set_bonding_mode_result *res = parsed_result;
4416 	portid_t port_id = res->port_id;
4417 
4418 	/* Set the bonding mode for the relevant port. */
4419 	if (0 != rte_eth_bond_mode_set(port_id, res->value))
4420 		printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4421 }
4422 
4423 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4424 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4425 		set, "set");
4426 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4427 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4428 		bonding, "bonding");
4429 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4430 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4431 		mode, "mode");
4432 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4433 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4434 		value, UINT8);
4435 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4436 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4437 		port_id, UINT8);
4438 
4439 cmdline_parse_inst_t cmd_set_bonding_mode = {
4440 		.f = cmd_set_bonding_mode_parsed,
4441 		.help_str = "set bonding mode <mode_value> <port_id>: "
4442 			"Set the bonding mode for port_id",
4443 		.data = NULL,
4444 		.tokens = {
4445 				(void *) &cmd_setbonding_mode_set,
4446 				(void *) &cmd_setbonding_mode_bonding,
4447 				(void *) &cmd_setbonding_mode_mode,
4448 				(void *) &cmd_setbonding_mode_value,
4449 				(void *) &cmd_setbonding_mode_port,
4450 				NULL
4451 		}
4452 };
4453 
4454 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4455 struct cmd_set_bonding_lacp_dedicated_queues_result {
4456 	cmdline_fixed_string_t set;
4457 	cmdline_fixed_string_t bonding;
4458 	cmdline_fixed_string_t lacp;
4459 	cmdline_fixed_string_t dedicated_queues;
4460 	uint8_t port_id;
4461 	cmdline_fixed_string_t mode;
4462 };
4463 
4464 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4465 		__attribute__((unused))  struct cmdline *cl,
4466 		__attribute__((unused)) void *data)
4467 {
4468 	struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4469 	portid_t port_id = res->port_id;
4470 	struct rte_port *port;
4471 
4472 	port = &ports[port_id];
4473 
4474 	/** Check if the port is not started **/
4475 	if (port->port_status != RTE_PORT_STOPPED) {
4476 		printf("Please stop port %d first\n", port_id);
4477 		return;
4478 	}
4479 
4480 	if (!strcmp(res->mode, "enable")) {
4481 		if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4482 			printf("Dedicate queues for LACP control packets"
4483 					" enabled\n");
4484 		else
4485 			printf("Enabling dedicate queues for LACP control "
4486 					"packets on port %d failed\n", port_id);
4487 	} else if (!strcmp(res->mode, "disable")) {
4488 		if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4489 			printf("Dedicated queues for LACP control packets "
4490 					"disabled\n");
4491 		else
4492 			printf("Disabling dedicated queues for LACP control "
4493 					"traffic on port %d failed\n", port_id);
4494 	}
4495 }
4496 
4497 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4498 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4499 		set, "set");
4500 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4501 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4502 		bonding, "bonding");
4503 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4504 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4505 		lacp, "lacp");
4506 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4507 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4508 		dedicated_queues, "dedicated_queues");
4509 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4510 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4511 		port_id, UINT8);
4512 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4513 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4514 		mode, "enable#disable");
4515 
4516 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4517 		.f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4518 		.help_str = "set bonding lacp dedicated_queues <port_id> "
4519 			"enable|disable: "
4520 			"Enable/disable dedicated queues for LACP control traffic for port_id",
4521 		.data = NULL,
4522 		.tokens = {
4523 			(void *)&cmd_setbonding_lacp_dedicated_queues_set,
4524 			(void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4525 			(void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4526 			(void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4527 			(void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4528 			(void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4529 			NULL
4530 		}
4531 };
4532 
4533 /* *** SET BALANCE XMIT POLICY *** */
4534 struct cmd_set_bonding_balance_xmit_policy_result {
4535 	cmdline_fixed_string_t set;
4536 	cmdline_fixed_string_t bonding;
4537 	cmdline_fixed_string_t balance_xmit_policy;
4538 	uint8_t port_id;
4539 	cmdline_fixed_string_t policy;
4540 };
4541 
4542 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4543 		__attribute__((unused))  struct cmdline *cl,
4544 		__attribute__((unused)) void *data)
4545 {
4546 	struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4547 	portid_t port_id = res->port_id;
4548 	uint8_t policy;
4549 
4550 	if (!strcmp(res->policy, "l2")) {
4551 		policy = BALANCE_XMIT_POLICY_LAYER2;
4552 	} else if (!strcmp(res->policy, "l23")) {
4553 		policy = BALANCE_XMIT_POLICY_LAYER23;
4554 	} else if (!strcmp(res->policy, "l34")) {
4555 		policy = BALANCE_XMIT_POLICY_LAYER34;
4556 	} else {
4557 		printf("\t Invalid xmit policy selection");
4558 		return;
4559 	}
4560 
4561 	/* Set the bonding mode for the relevant port. */
4562 	if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4563 		printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4564 				port_id);
4565 	}
4566 }
4567 
4568 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4569 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4570 		set, "set");
4571 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4572 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4573 		bonding, "bonding");
4574 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4575 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4576 		balance_xmit_policy, "balance_xmit_policy");
4577 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4578 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4579 		port_id, UINT8);
4580 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4581 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4582 		policy, "l2#l23#l34");
4583 
4584 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4585 		.f = cmd_set_bonding_balance_xmit_policy_parsed,
4586 		.help_str = "set bonding balance_xmit_policy <port_id> "
4587 			"l2|l23|l34: "
4588 			"Set the bonding balance_xmit_policy for port_id",
4589 		.data = NULL,
4590 		.tokens = {
4591 				(void *)&cmd_setbonding_balance_xmit_policy_set,
4592 				(void *)&cmd_setbonding_balance_xmit_policy_bonding,
4593 				(void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4594 				(void *)&cmd_setbonding_balance_xmit_policy_port,
4595 				(void *)&cmd_setbonding_balance_xmit_policy_policy,
4596 				NULL
4597 		}
4598 };
4599 
4600 /* *** SHOW NIC BONDING CONFIGURATION *** */
4601 struct cmd_show_bonding_config_result {
4602 	cmdline_fixed_string_t show;
4603 	cmdline_fixed_string_t bonding;
4604 	cmdline_fixed_string_t config;
4605 	portid_t port_id;
4606 };
4607 
4608 static void cmd_show_bonding_config_parsed(void *parsed_result,
4609 		__attribute__((unused))  struct cmdline *cl,
4610 		__attribute__((unused)) void *data)
4611 {
4612 	struct cmd_show_bonding_config_result *res = parsed_result;
4613 	int bonding_mode, agg_mode;
4614 	portid_t slaves[RTE_MAX_ETHPORTS];
4615 	int num_slaves, num_active_slaves;
4616 	int primary_id;
4617 	int i;
4618 	portid_t port_id = res->port_id;
4619 
4620 	/* Display the bonding mode.*/
4621 	bonding_mode = rte_eth_bond_mode_get(port_id);
4622 	if (bonding_mode < 0) {
4623 		printf("\tFailed to get bonding mode for port = %d\n", port_id);
4624 		return;
4625 	} else
4626 		printf("\tBonding mode: %d\n", bonding_mode);
4627 
4628 	if (bonding_mode == BONDING_MODE_BALANCE) {
4629 		int balance_xmit_policy;
4630 
4631 		balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4632 		if (balance_xmit_policy < 0) {
4633 			printf("\tFailed to get balance xmit policy for port = %d\n",
4634 					port_id);
4635 			return;
4636 		} else {
4637 			printf("\tBalance Xmit Policy: ");
4638 
4639 			switch (balance_xmit_policy) {
4640 			case BALANCE_XMIT_POLICY_LAYER2:
4641 				printf("BALANCE_XMIT_POLICY_LAYER2");
4642 				break;
4643 			case BALANCE_XMIT_POLICY_LAYER23:
4644 				printf("BALANCE_XMIT_POLICY_LAYER23");
4645 				break;
4646 			case BALANCE_XMIT_POLICY_LAYER34:
4647 				printf("BALANCE_XMIT_POLICY_LAYER34");
4648 				break;
4649 			}
4650 			printf("\n");
4651 		}
4652 	}
4653 
4654 	if (bonding_mode == BONDING_MODE_8023AD) {
4655 		agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4656 		printf("\tIEEE802.3AD Aggregator Mode: ");
4657 		switch (agg_mode) {
4658 		case AGG_BANDWIDTH:
4659 			printf("bandwidth");
4660 			break;
4661 		case AGG_STABLE:
4662 			printf("stable");
4663 			break;
4664 		case AGG_COUNT:
4665 			printf("count");
4666 			break;
4667 		}
4668 		printf("\n");
4669 	}
4670 
4671 	num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4672 
4673 	if (num_slaves < 0) {
4674 		printf("\tFailed to get slave list for port = %d\n", port_id);
4675 		return;
4676 	}
4677 	if (num_slaves > 0) {
4678 		printf("\tSlaves (%d): [", num_slaves);
4679 		for (i = 0; i < num_slaves - 1; i++)
4680 			printf("%d ", slaves[i]);
4681 
4682 		printf("%d]\n", slaves[num_slaves - 1]);
4683 	} else {
4684 		printf("\tSlaves: []\n");
4685 
4686 	}
4687 
4688 	num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4689 			RTE_MAX_ETHPORTS);
4690 
4691 	if (num_active_slaves < 0) {
4692 		printf("\tFailed to get active slave list for port = %d\n", port_id);
4693 		return;
4694 	}
4695 	if (num_active_slaves > 0) {
4696 		printf("\tActive Slaves (%d): [", num_active_slaves);
4697 		for (i = 0; i < num_active_slaves - 1; i++)
4698 			printf("%d ", slaves[i]);
4699 
4700 		printf("%d]\n", slaves[num_active_slaves - 1]);
4701 
4702 	} else {
4703 		printf("\tActive Slaves: []\n");
4704 
4705 	}
4706 
4707 	primary_id = rte_eth_bond_primary_get(port_id);
4708 	if (primary_id < 0) {
4709 		printf("\tFailed to get primary slave for port = %d\n", port_id);
4710 		return;
4711 	} else
4712 		printf("\tPrimary: [%d]\n", primary_id);
4713 
4714 }
4715 
4716 cmdline_parse_token_string_t cmd_showbonding_config_show =
4717 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4718 		show, "show");
4719 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4720 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4721 		bonding, "bonding");
4722 cmdline_parse_token_string_t cmd_showbonding_config_config =
4723 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4724 		config, "config");
4725 cmdline_parse_token_num_t cmd_showbonding_config_port =
4726 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4727 		port_id, UINT8);
4728 
4729 cmdline_parse_inst_t cmd_show_bonding_config = {
4730 		.f = cmd_show_bonding_config_parsed,
4731 		.help_str = "show bonding config <port_id>: "
4732 			"Show the bonding config for port_id",
4733 		.data = NULL,
4734 		.tokens = {
4735 				(void *)&cmd_showbonding_config_show,
4736 				(void *)&cmd_showbonding_config_bonding,
4737 				(void *)&cmd_showbonding_config_config,
4738 				(void *)&cmd_showbonding_config_port,
4739 				NULL
4740 		}
4741 };
4742 
4743 /* *** SET BONDING PRIMARY *** */
4744 struct cmd_set_bonding_primary_result {
4745 	cmdline_fixed_string_t set;
4746 	cmdline_fixed_string_t bonding;
4747 	cmdline_fixed_string_t primary;
4748 	uint8_t slave_id;
4749 	uint8_t port_id;
4750 };
4751 
4752 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4753 		__attribute__((unused))  struct cmdline *cl,
4754 		__attribute__((unused)) void *data)
4755 {
4756 	struct cmd_set_bonding_primary_result *res = parsed_result;
4757 	portid_t master_port_id = res->port_id;
4758 	portid_t slave_port_id = res->slave_id;
4759 
4760 	/* Set the primary slave for a bonded device. */
4761 	if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4762 		printf("\t Failed to set primary slave for port = %d.\n",
4763 				master_port_id);
4764 		return;
4765 	}
4766 	init_port_config();
4767 }
4768 
4769 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4770 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4771 		set, "set");
4772 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4773 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4774 		bonding, "bonding");
4775 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4776 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4777 		primary, "primary");
4778 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4779 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4780 		slave_id, UINT8);
4781 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4782 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4783 		port_id, UINT8);
4784 
4785 cmdline_parse_inst_t cmd_set_bonding_primary = {
4786 		.f = cmd_set_bonding_primary_parsed,
4787 		.help_str = "set bonding primary <slave_id> <port_id>: "
4788 			"Set the primary slave for port_id",
4789 		.data = NULL,
4790 		.tokens = {
4791 				(void *)&cmd_setbonding_primary_set,
4792 				(void *)&cmd_setbonding_primary_bonding,
4793 				(void *)&cmd_setbonding_primary_primary,
4794 				(void *)&cmd_setbonding_primary_slave,
4795 				(void *)&cmd_setbonding_primary_port,
4796 				NULL
4797 		}
4798 };
4799 
4800 /* *** ADD SLAVE *** */
4801 struct cmd_add_bonding_slave_result {
4802 	cmdline_fixed_string_t add;
4803 	cmdline_fixed_string_t bonding;
4804 	cmdline_fixed_string_t slave;
4805 	uint8_t slave_id;
4806 	uint8_t port_id;
4807 };
4808 
4809 static void cmd_add_bonding_slave_parsed(void *parsed_result,
4810 		__attribute__((unused))  struct cmdline *cl,
4811 		__attribute__((unused)) void *data)
4812 {
4813 	struct cmd_add_bonding_slave_result *res = parsed_result;
4814 	portid_t master_port_id = res->port_id;
4815 	portid_t slave_port_id = res->slave_id;
4816 
4817 	/* add the slave for a bonded device. */
4818 	if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
4819 		printf("\t Failed to add slave %d to master port = %d.\n",
4820 				slave_port_id, master_port_id);
4821 		return;
4822 	}
4823 	init_port_config();
4824 	set_port_slave_flag(slave_port_id);
4825 }
4826 
4827 cmdline_parse_token_string_t cmd_addbonding_slave_add =
4828 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4829 		add, "add");
4830 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
4831 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4832 		bonding, "bonding");
4833 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
4834 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4835 		slave, "slave");
4836 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
4837 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4838 		slave_id, UINT8);
4839 cmdline_parse_token_num_t cmd_addbonding_slave_port =
4840 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4841 		port_id, UINT8);
4842 
4843 cmdline_parse_inst_t cmd_add_bonding_slave = {
4844 		.f = cmd_add_bonding_slave_parsed,
4845 		.help_str = "add bonding slave <slave_id> <port_id>: "
4846 			"Add a slave device to a bonded device",
4847 		.data = NULL,
4848 		.tokens = {
4849 				(void *)&cmd_addbonding_slave_add,
4850 				(void *)&cmd_addbonding_slave_bonding,
4851 				(void *)&cmd_addbonding_slave_slave,
4852 				(void *)&cmd_addbonding_slave_slaveid,
4853 				(void *)&cmd_addbonding_slave_port,
4854 				NULL
4855 		}
4856 };
4857 
4858 /* *** REMOVE SLAVE *** */
4859 struct cmd_remove_bonding_slave_result {
4860 	cmdline_fixed_string_t remove;
4861 	cmdline_fixed_string_t bonding;
4862 	cmdline_fixed_string_t slave;
4863 	uint8_t slave_id;
4864 	uint8_t port_id;
4865 };
4866 
4867 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
4868 		__attribute__((unused))  struct cmdline *cl,
4869 		__attribute__((unused)) void *data)
4870 {
4871 	struct cmd_remove_bonding_slave_result *res = parsed_result;
4872 	portid_t master_port_id = res->port_id;
4873 	portid_t slave_port_id = res->slave_id;
4874 
4875 	/* remove the slave from a bonded device. */
4876 	if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
4877 		printf("\t Failed to remove slave %d from master port = %d.\n",
4878 				slave_port_id, master_port_id);
4879 		return;
4880 	}
4881 	init_port_config();
4882 	clear_port_slave_flag(slave_port_id);
4883 }
4884 
4885 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
4886 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4887 				remove, "remove");
4888 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
4889 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4890 				bonding, "bonding");
4891 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
4892 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4893 				slave, "slave");
4894 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
4895 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4896 				slave_id, UINT8);
4897 cmdline_parse_token_num_t cmd_removebonding_slave_port =
4898 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4899 				port_id, UINT8);
4900 
4901 cmdline_parse_inst_t cmd_remove_bonding_slave = {
4902 		.f = cmd_remove_bonding_slave_parsed,
4903 		.help_str = "remove bonding slave <slave_id> <port_id>: "
4904 			"Remove a slave device from a bonded device",
4905 		.data = NULL,
4906 		.tokens = {
4907 				(void *)&cmd_removebonding_slave_remove,
4908 				(void *)&cmd_removebonding_slave_bonding,
4909 				(void *)&cmd_removebonding_slave_slave,
4910 				(void *)&cmd_removebonding_slave_slaveid,
4911 				(void *)&cmd_removebonding_slave_port,
4912 				NULL
4913 		}
4914 };
4915 
4916 /* *** CREATE BONDED DEVICE *** */
4917 struct cmd_create_bonded_device_result {
4918 	cmdline_fixed_string_t create;
4919 	cmdline_fixed_string_t bonded;
4920 	cmdline_fixed_string_t device;
4921 	uint8_t mode;
4922 	uint8_t socket;
4923 };
4924 
4925 static int bond_dev_num = 0;
4926 
4927 static void cmd_create_bonded_device_parsed(void *parsed_result,
4928 		__attribute__((unused))  struct cmdline *cl,
4929 		__attribute__((unused)) void *data)
4930 {
4931 	struct cmd_create_bonded_device_result *res = parsed_result;
4932 	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
4933 	int port_id;
4934 
4935 	if (test_done == 0) {
4936 		printf("Please stop forwarding first\n");
4937 		return;
4938 	}
4939 
4940 	snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
4941 			bond_dev_num++);
4942 
4943 	/* Create a new bonded device. */
4944 	port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
4945 	if (port_id < 0) {
4946 		printf("\t Failed to create bonded device.\n");
4947 		return;
4948 	} else {
4949 		printf("Created new bonded device %s on (port %d).\n", ethdev_name,
4950 				port_id);
4951 
4952 		/* Update number of ports */
4953 		nb_ports = rte_eth_dev_count();
4954 		reconfig(port_id, res->socket);
4955 		rte_eth_promiscuous_enable(port_id);
4956 	}
4957 
4958 }
4959 
4960 cmdline_parse_token_string_t cmd_createbonded_device_create =
4961 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4962 				create, "create");
4963 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
4964 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4965 				bonded, "bonded");
4966 cmdline_parse_token_string_t cmd_createbonded_device_device =
4967 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4968 				device, "device");
4969 cmdline_parse_token_num_t cmd_createbonded_device_mode =
4970 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4971 				mode, UINT8);
4972 cmdline_parse_token_num_t cmd_createbonded_device_socket =
4973 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4974 				socket, UINT8);
4975 
4976 cmdline_parse_inst_t cmd_create_bonded_device = {
4977 		.f = cmd_create_bonded_device_parsed,
4978 		.help_str = "create bonded device <mode> <socket>: "
4979 			"Create a new bonded device with specific bonding mode and socket",
4980 		.data = NULL,
4981 		.tokens = {
4982 				(void *)&cmd_createbonded_device_create,
4983 				(void *)&cmd_createbonded_device_bonded,
4984 				(void *)&cmd_createbonded_device_device,
4985 				(void *)&cmd_createbonded_device_mode,
4986 				(void *)&cmd_createbonded_device_socket,
4987 				NULL
4988 		}
4989 };
4990 
4991 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
4992 struct cmd_set_bond_mac_addr_result {
4993 	cmdline_fixed_string_t set;
4994 	cmdline_fixed_string_t bonding;
4995 	cmdline_fixed_string_t mac_addr;
4996 	uint8_t port_num;
4997 	struct ether_addr address;
4998 };
4999 
5000 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5001 		__attribute__((unused))  struct cmdline *cl,
5002 		__attribute__((unused)) void *data)
5003 {
5004 	struct cmd_set_bond_mac_addr_result *res = parsed_result;
5005 	int ret;
5006 
5007 	if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5008 		return;
5009 
5010 	ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5011 
5012 	/* check the return value and print it if is < 0 */
5013 	if (ret < 0)
5014 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5015 }
5016 
5017 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5018 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5019 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5020 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5021 				"bonding");
5022 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5023 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5024 				"mac_addr");
5025 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5026 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
5027 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5028 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5029 
5030 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5031 		.f = cmd_set_bond_mac_addr_parsed,
5032 		.data = (void *) 0,
5033 		.help_str = "set bonding mac_addr <port_id> <mac_addr>",
5034 		.tokens = {
5035 				(void *)&cmd_set_bond_mac_addr_set,
5036 				(void *)&cmd_set_bond_mac_addr_bonding,
5037 				(void *)&cmd_set_bond_mac_addr_mac,
5038 				(void *)&cmd_set_bond_mac_addr_portnum,
5039 				(void *)&cmd_set_bond_mac_addr_addr,
5040 				NULL
5041 		}
5042 };
5043 
5044 
5045 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5046 struct cmd_set_bond_mon_period_result {
5047 	cmdline_fixed_string_t set;
5048 	cmdline_fixed_string_t bonding;
5049 	cmdline_fixed_string_t mon_period;
5050 	uint8_t port_num;
5051 	uint32_t period_ms;
5052 };
5053 
5054 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5055 		__attribute__((unused))  struct cmdline *cl,
5056 		__attribute__((unused)) void *data)
5057 {
5058 	struct cmd_set_bond_mon_period_result *res = parsed_result;
5059 	int ret;
5060 
5061 	if (res->port_num >= nb_ports) {
5062 		printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5063 		return;
5064 	}
5065 
5066 	ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5067 
5068 	/* check the return value and print it if is < 0 */
5069 	if (ret < 0)
5070 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5071 }
5072 
5073 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5074 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5075 				set, "set");
5076 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5077 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5078 				bonding, "bonding");
5079 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5080 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5081 				mon_period,	"mon_period");
5082 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5083 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5084 				port_num, UINT8);
5085 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5086 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5087 				period_ms, UINT32);
5088 
5089 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5090 		.f = cmd_set_bond_mon_period_parsed,
5091 		.data = (void *) 0,
5092 		.help_str = "set bonding mon_period <port_id> <period_ms>",
5093 		.tokens = {
5094 				(void *)&cmd_set_bond_mon_period_set,
5095 				(void *)&cmd_set_bond_mon_period_bonding,
5096 				(void *)&cmd_set_bond_mon_period_mon_period,
5097 				(void *)&cmd_set_bond_mon_period_portnum,
5098 				(void *)&cmd_set_bond_mon_period_period_ms,
5099 				NULL
5100 		}
5101 };
5102 
5103 
5104 
5105 struct cmd_set_bonding_agg_mode_policy_result {
5106 	cmdline_fixed_string_t set;
5107 	cmdline_fixed_string_t bonding;
5108 	cmdline_fixed_string_t agg_mode;
5109 	uint8_t port_num;
5110 	cmdline_fixed_string_t policy;
5111 };
5112 
5113 
5114 static void
5115 cmd_set_bonding_agg_mode(void *parsed_result,
5116 		__attribute__((unused)) struct cmdline *cl,
5117 		__attribute__((unused)) void *data)
5118 {
5119 	struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5120 	uint8_t policy = AGG_BANDWIDTH;
5121 
5122 	if (res->port_num >= nb_ports) {
5123 		printf("Port id %d must be less than %d\n",
5124 				res->port_num, nb_ports);
5125 		return;
5126 	}
5127 
5128 	if (!strcmp(res->policy, "bandwidth"))
5129 		policy = AGG_BANDWIDTH;
5130 	else if (!strcmp(res->policy, "stable"))
5131 		policy = AGG_STABLE;
5132 	else if (!strcmp(res->policy, "count"))
5133 		policy = AGG_COUNT;
5134 
5135 	rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5136 }
5137 
5138 
5139 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5140 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5141 				set, "set");
5142 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5143 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5144 				bonding, "bonding");
5145 
5146 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5147 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5148 				agg_mode, "agg_mode");
5149 
5150 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5151 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5152 				port_num, UINT8);
5153 
5154 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5155 	TOKEN_STRING_INITIALIZER(
5156 			struct cmd_set_bonding_balance_xmit_policy_result,
5157 		policy, "stable#bandwidth#count");
5158 
5159 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5160 	.f = cmd_set_bonding_agg_mode,
5161 	.data = (void *) 0,
5162 	.help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5163 	.tokens = {
5164 			(void *)&cmd_set_bonding_agg_mode_set,
5165 			(void *)&cmd_set_bonding_agg_mode_bonding,
5166 			(void *)&cmd_set_bonding_agg_mode_agg_mode,
5167 			(void *)&cmd_set_bonding_agg_mode_portnum,
5168 			(void *)&cmd_set_bonding_agg_mode_policy_string,
5169 			NULL
5170 		}
5171 };
5172 
5173 
5174 #endif /* RTE_LIBRTE_PMD_BOND */
5175 
5176 /* *** SET FORWARDING MODE *** */
5177 struct cmd_set_fwd_mode_result {
5178 	cmdline_fixed_string_t set;
5179 	cmdline_fixed_string_t fwd;
5180 	cmdline_fixed_string_t mode;
5181 };
5182 
5183 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5184 				    __attribute__((unused)) struct cmdline *cl,
5185 				    __attribute__((unused)) void *data)
5186 {
5187 	struct cmd_set_fwd_mode_result *res = parsed_result;
5188 
5189 	retry_enabled = 0;
5190 	set_pkt_forwarding_mode(res->mode);
5191 }
5192 
5193 cmdline_parse_token_string_t cmd_setfwd_set =
5194 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5195 cmdline_parse_token_string_t cmd_setfwd_fwd =
5196 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5197 cmdline_parse_token_string_t cmd_setfwd_mode =
5198 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5199 		"" /* defined at init */);
5200 
5201 cmdline_parse_inst_t cmd_set_fwd_mode = {
5202 	.f = cmd_set_fwd_mode_parsed,
5203 	.data = NULL,
5204 	.help_str = NULL, /* defined at init */
5205 	.tokens = {
5206 		(void *)&cmd_setfwd_set,
5207 		(void *)&cmd_setfwd_fwd,
5208 		(void *)&cmd_setfwd_mode,
5209 		NULL,
5210 	},
5211 };
5212 
5213 static void cmd_set_fwd_mode_init(void)
5214 {
5215 	char *modes, *c;
5216 	static char token[128];
5217 	static char help[256];
5218 	cmdline_parse_token_string_t *token_struct;
5219 
5220 	modes = list_pkt_forwarding_modes();
5221 	snprintf(help, sizeof(help), "set fwd %s: "
5222 		"Set packet forwarding mode", modes);
5223 	cmd_set_fwd_mode.help_str = help;
5224 
5225 	/* string token separator is # */
5226 	for (c = token; *modes != '\0'; modes++)
5227 		if (*modes == '|')
5228 			*c++ = '#';
5229 		else
5230 			*c++ = *modes;
5231 	token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5232 	token_struct->string_data.str = token;
5233 }
5234 
5235 /* *** SET RETRY FORWARDING MODE *** */
5236 struct cmd_set_fwd_retry_mode_result {
5237 	cmdline_fixed_string_t set;
5238 	cmdline_fixed_string_t fwd;
5239 	cmdline_fixed_string_t mode;
5240 	cmdline_fixed_string_t retry;
5241 };
5242 
5243 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5244 			    __attribute__((unused)) struct cmdline *cl,
5245 			    __attribute__((unused)) void *data)
5246 {
5247 	struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5248 
5249 	retry_enabled = 1;
5250 	set_pkt_forwarding_mode(res->mode);
5251 }
5252 
5253 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5254 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5255 			set, "set");
5256 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5257 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5258 			fwd, "fwd");
5259 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5260 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5261 			mode,
5262 		"" /* defined at init */);
5263 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5264 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5265 			retry, "retry");
5266 
5267 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5268 	.f = cmd_set_fwd_retry_mode_parsed,
5269 	.data = NULL,
5270 	.help_str = NULL, /* defined at init */
5271 	.tokens = {
5272 		(void *)&cmd_setfwd_retry_set,
5273 		(void *)&cmd_setfwd_retry_fwd,
5274 		(void *)&cmd_setfwd_retry_mode,
5275 		(void *)&cmd_setfwd_retry_retry,
5276 		NULL,
5277 	},
5278 };
5279 
5280 static void cmd_set_fwd_retry_mode_init(void)
5281 {
5282 	char *modes, *c;
5283 	static char token[128];
5284 	static char help[256];
5285 	cmdline_parse_token_string_t *token_struct;
5286 
5287 	modes = list_pkt_forwarding_retry_modes();
5288 	snprintf(help, sizeof(help), "set fwd %s retry: "
5289 		"Set packet forwarding mode with retry", modes);
5290 	cmd_set_fwd_retry_mode.help_str = help;
5291 
5292 	/* string token separator is # */
5293 	for (c = token; *modes != '\0'; modes++)
5294 		if (*modes == '|')
5295 			*c++ = '#';
5296 		else
5297 			*c++ = *modes;
5298 	token_struct = (cmdline_parse_token_string_t *)
5299 		cmd_set_fwd_retry_mode.tokens[2];
5300 	token_struct->string_data.str = token;
5301 }
5302 
5303 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5304 struct cmd_set_burst_tx_retry_result {
5305 	cmdline_fixed_string_t set;
5306 	cmdline_fixed_string_t burst;
5307 	cmdline_fixed_string_t tx;
5308 	cmdline_fixed_string_t delay;
5309 	uint32_t time;
5310 	cmdline_fixed_string_t retry;
5311 	uint32_t retry_num;
5312 };
5313 
5314 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5315 					__attribute__((unused)) struct cmdline *cl,
5316 					__attribute__((unused)) void *data)
5317 {
5318 	struct cmd_set_burst_tx_retry_result *res = parsed_result;
5319 
5320 	if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5321 		&& !strcmp(res->tx, "tx")) {
5322 		if (!strcmp(res->delay, "delay"))
5323 			burst_tx_delay_time = res->time;
5324 		if (!strcmp(res->retry, "retry"))
5325 			burst_tx_retry_num = res->retry_num;
5326 	}
5327 
5328 }
5329 
5330 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5331 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5332 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5333 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5334 				 "burst");
5335 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5336 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5337 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5338 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5339 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5340 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5341 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5342 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5343 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5344 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5345 
5346 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5347 	.f = cmd_set_burst_tx_retry_parsed,
5348 	.help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5349 	.tokens = {
5350 		(void *)&cmd_set_burst_tx_retry_set,
5351 		(void *)&cmd_set_burst_tx_retry_burst,
5352 		(void *)&cmd_set_burst_tx_retry_tx,
5353 		(void *)&cmd_set_burst_tx_retry_delay,
5354 		(void *)&cmd_set_burst_tx_retry_time,
5355 		(void *)&cmd_set_burst_tx_retry_retry,
5356 		(void *)&cmd_set_burst_tx_retry_retry_num,
5357 		NULL,
5358 	},
5359 };
5360 
5361 /* *** SET PROMISC MODE *** */
5362 struct cmd_set_promisc_mode_result {
5363 	cmdline_fixed_string_t set;
5364 	cmdline_fixed_string_t promisc;
5365 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5366 	uint8_t port_num;                /* valid if "allports" argument == 0 */
5367 	cmdline_fixed_string_t mode;
5368 };
5369 
5370 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5371 					__attribute__((unused)) struct cmdline *cl,
5372 					void *allports)
5373 {
5374 	struct cmd_set_promisc_mode_result *res = parsed_result;
5375 	int enable;
5376 	portid_t i;
5377 
5378 	if (!strcmp(res->mode, "on"))
5379 		enable = 1;
5380 	else
5381 		enable = 0;
5382 
5383 	/* all ports */
5384 	if (allports) {
5385 		RTE_ETH_FOREACH_DEV(i) {
5386 			if (enable)
5387 				rte_eth_promiscuous_enable(i);
5388 			else
5389 				rte_eth_promiscuous_disable(i);
5390 		}
5391 	}
5392 	else {
5393 		if (enable)
5394 			rte_eth_promiscuous_enable(res->port_num);
5395 		else
5396 			rte_eth_promiscuous_disable(res->port_num);
5397 	}
5398 }
5399 
5400 cmdline_parse_token_string_t cmd_setpromisc_set =
5401 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5402 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5403 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5404 				 "promisc");
5405 cmdline_parse_token_string_t cmd_setpromisc_portall =
5406 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5407 				 "all");
5408 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5409 	TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5410 			      UINT8);
5411 cmdline_parse_token_string_t cmd_setpromisc_mode =
5412 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5413 				 "on#off");
5414 
5415 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5416 	.f = cmd_set_promisc_mode_parsed,
5417 	.data = (void *)1,
5418 	.help_str = "set promisc all on|off: Set promisc mode for all ports",
5419 	.tokens = {
5420 		(void *)&cmd_setpromisc_set,
5421 		(void *)&cmd_setpromisc_promisc,
5422 		(void *)&cmd_setpromisc_portall,
5423 		(void *)&cmd_setpromisc_mode,
5424 		NULL,
5425 	},
5426 };
5427 
5428 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5429 	.f = cmd_set_promisc_mode_parsed,
5430 	.data = (void *)0,
5431 	.help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5432 	.tokens = {
5433 		(void *)&cmd_setpromisc_set,
5434 		(void *)&cmd_setpromisc_promisc,
5435 		(void *)&cmd_setpromisc_portnum,
5436 		(void *)&cmd_setpromisc_mode,
5437 		NULL,
5438 	},
5439 };
5440 
5441 /* *** SET ALLMULTI MODE *** */
5442 struct cmd_set_allmulti_mode_result {
5443 	cmdline_fixed_string_t set;
5444 	cmdline_fixed_string_t allmulti;
5445 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5446 	uint8_t port_num;                /* valid if "allports" argument == 0 */
5447 	cmdline_fixed_string_t mode;
5448 };
5449 
5450 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5451 					__attribute__((unused)) struct cmdline *cl,
5452 					void *allports)
5453 {
5454 	struct cmd_set_allmulti_mode_result *res = parsed_result;
5455 	int enable;
5456 	portid_t i;
5457 
5458 	if (!strcmp(res->mode, "on"))
5459 		enable = 1;
5460 	else
5461 		enable = 0;
5462 
5463 	/* all ports */
5464 	if (allports) {
5465 		RTE_ETH_FOREACH_DEV(i) {
5466 			if (enable)
5467 				rte_eth_allmulticast_enable(i);
5468 			else
5469 				rte_eth_allmulticast_disable(i);
5470 		}
5471 	}
5472 	else {
5473 		if (enable)
5474 			rte_eth_allmulticast_enable(res->port_num);
5475 		else
5476 			rte_eth_allmulticast_disable(res->port_num);
5477 	}
5478 }
5479 
5480 cmdline_parse_token_string_t cmd_setallmulti_set =
5481 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5482 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5483 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5484 				 "allmulti");
5485 cmdline_parse_token_string_t cmd_setallmulti_portall =
5486 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5487 				 "all");
5488 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5489 	TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5490 			      UINT8);
5491 cmdline_parse_token_string_t cmd_setallmulti_mode =
5492 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5493 				 "on#off");
5494 
5495 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5496 	.f = cmd_set_allmulti_mode_parsed,
5497 	.data = (void *)1,
5498 	.help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5499 	.tokens = {
5500 		(void *)&cmd_setallmulti_set,
5501 		(void *)&cmd_setallmulti_allmulti,
5502 		(void *)&cmd_setallmulti_portall,
5503 		(void *)&cmd_setallmulti_mode,
5504 		NULL,
5505 	},
5506 };
5507 
5508 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5509 	.f = cmd_set_allmulti_mode_parsed,
5510 	.data = (void *)0,
5511 	.help_str = "set allmulti <port_id> on|off: "
5512 		"Set allmulti mode on port_id",
5513 	.tokens = {
5514 		(void *)&cmd_setallmulti_set,
5515 		(void *)&cmd_setallmulti_allmulti,
5516 		(void *)&cmd_setallmulti_portnum,
5517 		(void *)&cmd_setallmulti_mode,
5518 		NULL,
5519 	},
5520 };
5521 
5522 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5523 struct cmd_link_flow_ctrl_set_result {
5524 	cmdline_fixed_string_t set;
5525 	cmdline_fixed_string_t flow_ctrl;
5526 	cmdline_fixed_string_t rx;
5527 	cmdline_fixed_string_t rx_lfc_mode;
5528 	cmdline_fixed_string_t tx;
5529 	cmdline_fixed_string_t tx_lfc_mode;
5530 	cmdline_fixed_string_t mac_ctrl_frame_fwd;
5531 	cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5532 	cmdline_fixed_string_t autoneg_str;
5533 	cmdline_fixed_string_t autoneg;
5534 	cmdline_fixed_string_t hw_str;
5535 	uint32_t high_water;
5536 	cmdline_fixed_string_t lw_str;
5537 	uint32_t low_water;
5538 	cmdline_fixed_string_t pt_str;
5539 	uint16_t pause_time;
5540 	cmdline_fixed_string_t xon_str;
5541 	uint16_t send_xon;
5542 	uint8_t  port_id;
5543 };
5544 
5545 cmdline_parse_token_string_t cmd_lfc_set_set =
5546 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5547 				set, "set");
5548 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5549 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5550 				flow_ctrl, "flow_ctrl");
5551 cmdline_parse_token_string_t cmd_lfc_set_rx =
5552 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5553 				rx, "rx");
5554 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5555 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5556 				rx_lfc_mode, "on#off");
5557 cmdline_parse_token_string_t cmd_lfc_set_tx =
5558 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5559 				tx, "tx");
5560 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5561 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5562 				tx_lfc_mode, "on#off");
5563 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5564 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5565 				hw_str, "high_water");
5566 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5567 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5568 				high_water, UINT32);
5569 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5570 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5571 				lw_str, "low_water");
5572 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5573 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5574 				low_water, UINT32);
5575 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5576 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5577 				pt_str, "pause_time");
5578 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5579 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5580 				pause_time, UINT16);
5581 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5582 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5583 				xon_str, "send_xon");
5584 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5585 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5586 				send_xon, UINT16);
5587 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5588 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5589 				mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5590 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5591 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5592 				mac_ctrl_frame_fwd_mode, "on#off");
5593 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5594 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5595 				autoneg_str, "autoneg");
5596 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5597 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5598 				autoneg, "on#off");
5599 cmdline_parse_token_num_t cmd_lfc_set_portid =
5600 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5601 				port_id, UINT8);
5602 
5603 /* forward declaration */
5604 static void
5605 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5606 			      void *data);
5607 
5608 cmdline_parse_inst_t cmd_link_flow_control_set = {
5609 	.f = cmd_link_flow_ctrl_set_parsed,
5610 	.data = NULL,
5611 	.help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5612 		"<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5613 		"autoneg on|off <port_id>: Configure the Ethernet flow control",
5614 	.tokens = {
5615 		(void *)&cmd_lfc_set_set,
5616 		(void *)&cmd_lfc_set_flow_ctrl,
5617 		(void *)&cmd_lfc_set_rx,
5618 		(void *)&cmd_lfc_set_rx_mode,
5619 		(void *)&cmd_lfc_set_tx,
5620 		(void *)&cmd_lfc_set_tx_mode,
5621 		(void *)&cmd_lfc_set_high_water,
5622 		(void *)&cmd_lfc_set_low_water,
5623 		(void *)&cmd_lfc_set_pause_time,
5624 		(void *)&cmd_lfc_set_send_xon,
5625 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5626 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5627 		(void *)&cmd_lfc_set_autoneg_str,
5628 		(void *)&cmd_lfc_set_autoneg,
5629 		(void *)&cmd_lfc_set_portid,
5630 		NULL,
5631 	},
5632 };
5633 
5634 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5635 	.f = cmd_link_flow_ctrl_set_parsed,
5636 	.data = (void *)&cmd_link_flow_control_set_rx,
5637 	.help_str = "set flow_ctrl rx on|off <port_id>: "
5638 		"Change rx flow control parameter",
5639 	.tokens = {
5640 		(void *)&cmd_lfc_set_set,
5641 		(void *)&cmd_lfc_set_flow_ctrl,
5642 		(void *)&cmd_lfc_set_rx,
5643 		(void *)&cmd_lfc_set_rx_mode,
5644 		(void *)&cmd_lfc_set_portid,
5645 		NULL,
5646 	},
5647 };
5648 
5649 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5650 	.f = cmd_link_flow_ctrl_set_parsed,
5651 	.data = (void *)&cmd_link_flow_control_set_tx,
5652 	.help_str = "set flow_ctrl tx on|off <port_id>: "
5653 		"Change tx flow control parameter",
5654 	.tokens = {
5655 		(void *)&cmd_lfc_set_set,
5656 		(void *)&cmd_lfc_set_flow_ctrl,
5657 		(void *)&cmd_lfc_set_tx,
5658 		(void *)&cmd_lfc_set_tx_mode,
5659 		(void *)&cmd_lfc_set_portid,
5660 		NULL,
5661 	},
5662 };
5663 
5664 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5665 	.f = cmd_link_flow_ctrl_set_parsed,
5666 	.data = (void *)&cmd_link_flow_control_set_hw,
5667 	.help_str = "set flow_ctrl high_water <value> <port_id>: "
5668 		"Change high water flow control parameter",
5669 	.tokens = {
5670 		(void *)&cmd_lfc_set_set,
5671 		(void *)&cmd_lfc_set_flow_ctrl,
5672 		(void *)&cmd_lfc_set_high_water_str,
5673 		(void *)&cmd_lfc_set_high_water,
5674 		(void *)&cmd_lfc_set_portid,
5675 		NULL,
5676 	},
5677 };
5678 
5679 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5680 	.f = cmd_link_flow_ctrl_set_parsed,
5681 	.data = (void *)&cmd_link_flow_control_set_lw,
5682 	.help_str = "set flow_ctrl low_water <value> <port_id>: "
5683 		"Change low water flow control parameter",
5684 	.tokens = {
5685 		(void *)&cmd_lfc_set_set,
5686 		(void *)&cmd_lfc_set_flow_ctrl,
5687 		(void *)&cmd_lfc_set_low_water_str,
5688 		(void *)&cmd_lfc_set_low_water,
5689 		(void *)&cmd_lfc_set_portid,
5690 		NULL,
5691 	},
5692 };
5693 
5694 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5695 	.f = cmd_link_flow_ctrl_set_parsed,
5696 	.data = (void *)&cmd_link_flow_control_set_pt,
5697 	.help_str = "set flow_ctrl pause_time <value> <port_id>: "
5698 		"Change pause time flow control parameter",
5699 	.tokens = {
5700 		(void *)&cmd_lfc_set_set,
5701 		(void *)&cmd_lfc_set_flow_ctrl,
5702 		(void *)&cmd_lfc_set_pause_time_str,
5703 		(void *)&cmd_lfc_set_pause_time,
5704 		(void *)&cmd_lfc_set_portid,
5705 		NULL,
5706 	},
5707 };
5708 
5709 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5710 	.f = cmd_link_flow_ctrl_set_parsed,
5711 	.data = (void *)&cmd_link_flow_control_set_xon,
5712 	.help_str = "set flow_ctrl send_xon <value> <port_id>: "
5713 		"Change send_xon flow control parameter",
5714 	.tokens = {
5715 		(void *)&cmd_lfc_set_set,
5716 		(void *)&cmd_lfc_set_flow_ctrl,
5717 		(void *)&cmd_lfc_set_send_xon_str,
5718 		(void *)&cmd_lfc_set_send_xon,
5719 		(void *)&cmd_lfc_set_portid,
5720 		NULL,
5721 	},
5722 };
5723 
5724 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5725 	.f = cmd_link_flow_ctrl_set_parsed,
5726 	.data = (void *)&cmd_link_flow_control_set_macfwd,
5727 	.help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
5728 		"Change mac ctrl fwd flow control parameter",
5729 	.tokens = {
5730 		(void *)&cmd_lfc_set_set,
5731 		(void *)&cmd_lfc_set_flow_ctrl,
5732 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5733 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5734 		(void *)&cmd_lfc_set_portid,
5735 		NULL,
5736 	},
5737 };
5738 
5739 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5740 	.f = cmd_link_flow_ctrl_set_parsed,
5741 	.data = (void *)&cmd_link_flow_control_set_autoneg,
5742 	.help_str = "set flow_ctrl autoneg on|off <port_id>: "
5743 		"Change autoneg flow control parameter",
5744 	.tokens = {
5745 		(void *)&cmd_lfc_set_set,
5746 		(void *)&cmd_lfc_set_flow_ctrl,
5747 		(void *)&cmd_lfc_set_autoneg_str,
5748 		(void *)&cmd_lfc_set_autoneg,
5749 		(void *)&cmd_lfc_set_portid,
5750 		NULL,
5751 	},
5752 };
5753 
5754 static void
5755 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
5756 			      __attribute__((unused)) struct cmdline *cl,
5757 			      void *data)
5758 {
5759 	struct cmd_link_flow_ctrl_set_result *res = parsed_result;
5760 	cmdline_parse_inst_t *cmd = data;
5761 	struct rte_eth_fc_conf fc_conf;
5762 	int rx_fc_en = 0;
5763 	int tx_fc_en = 0;
5764 	int ret;
5765 
5766 	/*
5767 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5768 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5769 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5770 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5771 	 */
5772 	static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5773 			{RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
5774 	};
5775 
5776 	/* Partial command line, retrieve current configuration */
5777 	if (cmd) {
5778 		ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5779 		if (ret != 0) {
5780 			printf("cannot get current flow ctrl parameters, return"
5781 			       "code = %d\n", ret);
5782 			return;
5783 		}
5784 
5785 		if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
5786 		    (fc_conf.mode == RTE_FC_FULL))
5787 			rx_fc_en = 1;
5788 		if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
5789 		    (fc_conf.mode == RTE_FC_FULL))
5790 			tx_fc_en = 1;
5791 	}
5792 
5793 	if (!cmd || cmd == &cmd_link_flow_control_set_rx)
5794 		rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
5795 
5796 	if (!cmd || cmd == &cmd_link_flow_control_set_tx)
5797 		tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
5798 
5799 	fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
5800 
5801 	if (!cmd || cmd == &cmd_link_flow_control_set_hw)
5802 		fc_conf.high_water = res->high_water;
5803 
5804 	if (!cmd || cmd == &cmd_link_flow_control_set_lw)
5805 		fc_conf.low_water = res->low_water;
5806 
5807 	if (!cmd || cmd == &cmd_link_flow_control_set_pt)
5808 		fc_conf.pause_time = res->pause_time;
5809 
5810 	if (!cmd || cmd == &cmd_link_flow_control_set_xon)
5811 		fc_conf.send_xon = res->send_xon;
5812 
5813 	if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
5814 		if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
5815 			fc_conf.mac_ctrl_frame_fwd = 1;
5816 		else
5817 			fc_conf.mac_ctrl_frame_fwd = 0;
5818 	}
5819 
5820 	if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
5821 		fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
5822 
5823 	ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
5824 	if (ret != 0)
5825 		printf("bad flow contrl parameter, return code = %d \n", ret);
5826 }
5827 
5828 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
5829 struct cmd_priority_flow_ctrl_set_result {
5830 	cmdline_fixed_string_t set;
5831 	cmdline_fixed_string_t pfc_ctrl;
5832 	cmdline_fixed_string_t rx;
5833 	cmdline_fixed_string_t rx_pfc_mode;
5834 	cmdline_fixed_string_t tx;
5835 	cmdline_fixed_string_t tx_pfc_mode;
5836 	uint32_t high_water;
5837 	uint32_t low_water;
5838 	uint16_t pause_time;
5839 	uint8_t  priority;
5840 	uint8_t  port_id;
5841 };
5842 
5843 static void
5844 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
5845 		       __attribute__((unused)) struct cmdline *cl,
5846 		       __attribute__((unused)) void *data)
5847 {
5848 	struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
5849 	struct rte_eth_pfc_conf pfc_conf;
5850 	int rx_fc_enable, tx_fc_enable;
5851 	int ret;
5852 
5853 	/*
5854 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5855 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5856 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5857 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5858 	 */
5859 	static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
5860 			{RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
5861 	};
5862 
5863 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
5864 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
5865 	pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
5866 	pfc_conf.fc.high_water = res->high_water;
5867 	pfc_conf.fc.low_water  = res->low_water;
5868 	pfc_conf.fc.pause_time = res->pause_time;
5869 	pfc_conf.priority      = res->priority;
5870 
5871 	ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
5872 	if (ret != 0)
5873 		printf("bad priority flow contrl parameter, return code = %d \n", ret);
5874 }
5875 
5876 cmdline_parse_token_string_t cmd_pfc_set_set =
5877 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5878 				set, "set");
5879 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
5880 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5881 				pfc_ctrl, "pfc_ctrl");
5882 cmdline_parse_token_string_t cmd_pfc_set_rx =
5883 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5884 				rx, "rx");
5885 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
5886 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5887 				rx_pfc_mode, "on#off");
5888 cmdline_parse_token_string_t cmd_pfc_set_tx =
5889 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5890 				tx, "tx");
5891 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
5892 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5893 				tx_pfc_mode, "on#off");
5894 cmdline_parse_token_num_t cmd_pfc_set_high_water =
5895 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5896 				high_water, UINT32);
5897 cmdline_parse_token_num_t cmd_pfc_set_low_water =
5898 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5899 				low_water, UINT32);
5900 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
5901 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5902 				pause_time, UINT16);
5903 cmdline_parse_token_num_t cmd_pfc_set_priority =
5904 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5905 				priority, UINT8);
5906 cmdline_parse_token_num_t cmd_pfc_set_portid =
5907 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5908 				port_id, UINT8);
5909 
5910 cmdline_parse_inst_t cmd_priority_flow_control_set = {
5911 	.f = cmd_priority_flow_ctrl_set_parsed,
5912 	.data = NULL,
5913 	.help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
5914 		"<pause_time> <priority> <port_id>: "
5915 		"Configure the Ethernet priority flow control",
5916 	.tokens = {
5917 		(void *)&cmd_pfc_set_set,
5918 		(void *)&cmd_pfc_set_flow_ctrl,
5919 		(void *)&cmd_pfc_set_rx,
5920 		(void *)&cmd_pfc_set_rx_mode,
5921 		(void *)&cmd_pfc_set_tx,
5922 		(void *)&cmd_pfc_set_tx_mode,
5923 		(void *)&cmd_pfc_set_high_water,
5924 		(void *)&cmd_pfc_set_low_water,
5925 		(void *)&cmd_pfc_set_pause_time,
5926 		(void *)&cmd_pfc_set_priority,
5927 		(void *)&cmd_pfc_set_portid,
5928 		NULL,
5929 	},
5930 };
5931 
5932 /* *** RESET CONFIGURATION *** */
5933 struct cmd_reset_result {
5934 	cmdline_fixed_string_t reset;
5935 	cmdline_fixed_string_t def;
5936 };
5937 
5938 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
5939 			     struct cmdline *cl,
5940 			     __attribute__((unused)) void *data)
5941 {
5942 	cmdline_printf(cl, "Reset to default forwarding configuration...\n");
5943 	set_def_fwd_config();
5944 }
5945 
5946 cmdline_parse_token_string_t cmd_reset_set =
5947 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
5948 cmdline_parse_token_string_t cmd_reset_def =
5949 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
5950 				 "default");
5951 
5952 cmdline_parse_inst_t cmd_reset = {
5953 	.f = cmd_reset_parsed,
5954 	.data = NULL,
5955 	.help_str = "set default: Reset default forwarding configuration",
5956 	.tokens = {
5957 		(void *)&cmd_reset_set,
5958 		(void *)&cmd_reset_def,
5959 		NULL,
5960 	},
5961 };
5962 
5963 /* *** START FORWARDING *** */
5964 struct cmd_start_result {
5965 	cmdline_fixed_string_t start;
5966 };
5967 
5968 cmdline_parse_token_string_t cmd_start_start =
5969 	TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
5970 
5971 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
5972 			     __attribute__((unused)) struct cmdline *cl,
5973 			     __attribute__((unused)) void *data)
5974 {
5975 	start_packet_forwarding(0);
5976 }
5977 
5978 cmdline_parse_inst_t cmd_start = {
5979 	.f = cmd_start_parsed,
5980 	.data = NULL,
5981 	.help_str = "start: Start packet forwarding",
5982 	.tokens = {
5983 		(void *)&cmd_start_start,
5984 		NULL,
5985 	},
5986 };
5987 
5988 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
5989 struct cmd_start_tx_first_result {
5990 	cmdline_fixed_string_t start;
5991 	cmdline_fixed_string_t tx_first;
5992 };
5993 
5994 static void
5995 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
5996 			  __attribute__((unused)) struct cmdline *cl,
5997 			  __attribute__((unused)) void *data)
5998 {
5999 	start_packet_forwarding(1);
6000 }
6001 
6002 cmdline_parse_token_string_t cmd_start_tx_first_start =
6003 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6004 				 "start");
6005 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6006 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6007 				 tx_first, "tx_first");
6008 
6009 cmdline_parse_inst_t cmd_start_tx_first = {
6010 	.f = cmd_start_tx_first_parsed,
6011 	.data = NULL,
6012 	.help_str = "start tx_first: Start packet forwarding, "
6013 		"after sending 1 burst of packets",
6014 	.tokens = {
6015 		(void *)&cmd_start_tx_first_start,
6016 		(void *)&cmd_start_tx_first_tx_first,
6017 		NULL,
6018 	},
6019 };
6020 
6021 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6022 struct cmd_start_tx_first_n_result {
6023 	cmdline_fixed_string_t start;
6024 	cmdline_fixed_string_t tx_first;
6025 	uint32_t tx_num;
6026 };
6027 
6028 static void
6029 cmd_start_tx_first_n_parsed(void *parsed_result,
6030 			  __attribute__((unused)) struct cmdline *cl,
6031 			  __attribute__((unused)) void *data)
6032 {
6033 	struct cmd_start_tx_first_n_result *res = parsed_result;
6034 
6035 	start_packet_forwarding(res->tx_num);
6036 }
6037 
6038 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6039 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6040 			start, "start");
6041 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6042 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6043 			tx_first, "tx_first");
6044 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6045 	TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6046 			tx_num, UINT32);
6047 
6048 cmdline_parse_inst_t cmd_start_tx_first_n = {
6049 	.f = cmd_start_tx_first_n_parsed,
6050 	.data = NULL,
6051 	.help_str = "start tx_first <num>: "
6052 		"packet forwarding, after sending <num> bursts of packets",
6053 	.tokens = {
6054 		(void *)&cmd_start_tx_first_n_start,
6055 		(void *)&cmd_start_tx_first_n_tx_first,
6056 		(void *)&cmd_start_tx_first_n_tx_num,
6057 		NULL,
6058 	},
6059 };
6060 
6061 /* *** SET LINK UP *** */
6062 struct cmd_set_link_up_result {
6063 	cmdline_fixed_string_t set;
6064 	cmdline_fixed_string_t link_up;
6065 	cmdline_fixed_string_t port;
6066 	uint8_t port_id;
6067 };
6068 
6069 cmdline_parse_token_string_t cmd_set_link_up_set =
6070 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6071 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6072 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6073 				"link-up");
6074 cmdline_parse_token_string_t cmd_set_link_up_port =
6075 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6076 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6077 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
6078 
6079 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6080 			     __attribute__((unused)) struct cmdline *cl,
6081 			     __attribute__((unused)) void *data)
6082 {
6083 	struct cmd_set_link_up_result *res = parsed_result;
6084 	dev_set_link_up(res->port_id);
6085 }
6086 
6087 cmdline_parse_inst_t cmd_set_link_up = {
6088 	.f = cmd_set_link_up_parsed,
6089 	.data = NULL,
6090 	.help_str = "set link-up port <port id>",
6091 	.tokens = {
6092 		(void *)&cmd_set_link_up_set,
6093 		(void *)&cmd_set_link_up_link_up,
6094 		(void *)&cmd_set_link_up_port,
6095 		(void *)&cmd_set_link_up_port_id,
6096 		NULL,
6097 	},
6098 };
6099 
6100 /* *** SET LINK DOWN *** */
6101 struct cmd_set_link_down_result {
6102 	cmdline_fixed_string_t set;
6103 	cmdline_fixed_string_t link_down;
6104 	cmdline_fixed_string_t port;
6105 	uint8_t port_id;
6106 };
6107 
6108 cmdline_parse_token_string_t cmd_set_link_down_set =
6109 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6110 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6111 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6112 				"link-down");
6113 cmdline_parse_token_string_t cmd_set_link_down_port =
6114 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6115 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6116 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
6117 
6118 static void cmd_set_link_down_parsed(
6119 				__attribute__((unused)) void *parsed_result,
6120 				__attribute__((unused)) struct cmdline *cl,
6121 				__attribute__((unused)) void *data)
6122 {
6123 	struct cmd_set_link_down_result *res = parsed_result;
6124 	dev_set_link_down(res->port_id);
6125 }
6126 
6127 cmdline_parse_inst_t cmd_set_link_down = {
6128 	.f = cmd_set_link_down_parsed,
6129 	.data = NULL,
6130 	.help_str = "set link-down port <port id>",
6131 	.tokens = {
6132 		(void *)&cmd_set_link_down_set,
6133 		(void *)&cmd_set_link_down_link_down,
6134 		(void *)&cmd_set_link_down_port,
6135 		(void *)&cmd_set_link_down_port_id,
6136 		NULL,
6137 	},
6138 };
6139 
6140 /* *** SHOW CFG *** */
6141 struct cmd_showcfg_result {
6142 	cmdline_fixed_string_t show;
6143 	cmdline_fixed_string_t cfg;
6144 	cmdline_fixed_string_t what;
6145 };
6146 
6147 static void cmd_showcfg_parsed(void *parsed_result,
6148 			       __attribute__((unused)) struct cmdline *cl,
6149 			       __attribute__((unused)) void *data)
6150 {
6151 	struct cmd_showcfg_result *res = parsed_result;
6152 	if (!strcmp(res->what, "rxtx"))
6153 		rxtx_config_display();
6154 	else if (!strcmp(res->what, "cores"))
6155 		fwd_lcores_config_display();
6156 	else if (!strcmp(res->what, "fwd"))
6157 		pkt_fwd_config_display(&cur_fwd_config);
6158 	else if (!strcmp(res->what, "txpkts"))
6159 		show_tx_pkt_segments();
6160 }
6161 
6162 cmdline_parse_token_string_t cmd_showcfg_show =
6163 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6164 cmdline_parse_token_string_t cmd_showcfg_port =
6165 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6166 cmdline_parse_token_string_t cmd_showcfg_what =
6167 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6168 				 "rxtx#cores#fwd#txpkts");
6169 
6170 cmdline_parse_inst_t cmd_showcfg = {
6171 	.f = cmd_showcfg_parsed,
6172 	.data = NULL,
6173 	.help_str = "show config rxtx|cores|fwd|txpkts",
6174 	.tokens = {
6175 		(void *)&cmd_showcfg_show,
6176 		(void *)&cmd_showcfg_port,
6177 		(void *)&cmd_showcfg_what,
6178 		NULL,
6179 	},
6180 };
6181 
6182 /* *** SHOW ALL PORT INFO *** */
6183 struct cmd_showportall_result {
6184 	cmdline_fixed_string_t show;
6185 	cmdline_fixed_string_t port;
6186 	cmdline_fixed_string_t what;
6187 	cmdline_fixed_string_t all;
6188 };
6189 
6190 static void cmd_showportall_parsed(void *parsed_result,
6191 				__attribute__((unused)) struct cmdline *cl,
6192 				__attribute__((unused)) void *data)
6193 {
6194 	portid_t i;
6195 
6196 	struct cmd_showportall_result *res = parsed_result;
6197 	if (!strcmp(res->show, "clear")) {
6198 		if (!strcmp(res->what, "stats"))
6199 			RTE_ETH_FOREACH_DEV(i)
6200 				nic_stats_clear(i);
6201 		else if (!strcmp(res->what, "xstats"))
6202 			RTE_ETH_FOREACH_DEV(i)
6203 				nic_xstats_clear(i);
6204 	} else if (!strcmp(res->what, "info"))
6205 		RTE_ETH_FOREACH_DEV(i)
6206 			port_infos_display(i);
6207 	else if (!strcmp(res->what, "stats"))
6208 		RTE_ETH_FOREACH_DEV(i)
6209 			nic_stats_display(i);
6210 	else if (!strcmp(res->what, "xstats"))
6211 		RTE_ETH_FOREACH_DEV(i)
6212 			nic_xstats_display(i);
6213 	else if (!strcmp(res->what, "fdir"))
6214 		RTE_ETH_FOREACH_DEV(i)
6215 			fdir_get_infos(i);
6216 	else if (!strcmp(res->what, "stat_qmap"))
6217 		RTE_ETH_FOREACH_DEV(i)
6218 			nic_stats_mapping_display(i);
6219 	else if (!strcmp(res->what, "dcb_tc"))
6220 		RTE_ETH_FOREACH_DEV(i)
6221 			port_dcb_info_display(i);
6222 	else if (!strcmp(res->what, "cap"))
6223 		RTE_ETH_FOREACH_DEV(i)
6224 			port_offload_cap_display(i);
6225 }
6226 
6227 cmdline_parse_token_string_t cmd_showportall_show =
6228 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6229 				 "show#clear");
6230 cmdline_parse_token_string_t cmd_showportall_port =
6231 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6232 cmdline_parse_token_string_t cmd_showportall_what =
6233 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6234 				 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6235 cmdline_parse_token_string_t cmd_showportall_all =
6236 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6237 cmdline_parse_inst_t cmd_showportall = {
6238 	.f = cmd_showportall_parsed,
6239 	.data = NULL,
6240 	.help_str = "show|clear port "
6241 		"info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6242 	.tokens = {
6243 		(void *)&cmd_showportall_show,
6244 		(void *)&cmd_showportall_port,
6245 		(void *)&cmd_showportall_what,
6246 		(void *)&cmd_showportall_all,
6247 		NULL,
6248 	},
6249 };
6250 
6251 /* *** SHOW PORT INFO *** */
6252 struct cmd_showport_result {
6253 	cmdline_fixed_string_t show;
6254 	cmdline_fixed_string_t port;
6255 	cmdline_fixed_string_t what;
6256 	uint8_t portnum;
6257 };
6258 
6259 static void cmd_showport_parsed(void *parsed_result,
6260 				__attribute__((unused)) struct cmdline *cl,
6261 				__attribute__((unused)) void *data)
6262 {
6263 	struct cmd_showport_result *res = parsed_result;
6264 	if (!strcmp(res->show, "clear")) {
6265 		if (!strcmp(res->what, "stats"))
6266 			nic_stats_clear(res->portnum);
6267 		else if (!strcmp(res->what, "xstats"))
6268 			nic_xstats_clear(res->portnum);
6269 	} else if (!strcmp(res->what, "info"))
6270 		port_infos_display(res->portnum);
6271 	else if (!strcmp(res->what, "stats"))
6272 		nic_stats_display(res->portnum);
6273 	else if (!strcmp(res->what, "xstats"))
6274 		nic_xstats_display(res->portnum);
6275 	else if (!strcmp(res->what, "fdir"))
6276 		 fdir_get_infos(res->portnum);
6277 	else if (!strcmp(res->what, "stat_qmap"))
6278 		nic_stats_mapping_display(res->portnum);
6279 	else if (!strcmp(res->what, "dcb_tc"))
6280 		port_dcb_info_display(res->portnum);
6281 	else if (!strcmp(res->what, "cap"))
6282 		port_offload_cap_display(res->portnum);
6283 }
6284 
6285 cmdline_parse_token_string_t cmd_showport_show =
6286 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6287 				 "show#clear");
6288 cmdline_parse_token_string_t cmd_showport_port =
6289 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6290 cmdline_parse_token_string_t cmd_showport_what =
6291 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6292 				 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6293 cmdline_parse_token_num_t cmd_showport_portnum =
6294 	TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
6295 
6296 cmdline_parse_inst_t cmd_showport = {
6297 	.f = cmd_showport_parsed,
6298 	.data = NULL,
6299 	.help_str = "show|clear port "
6300 		"info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6301 		"<port_id>",
6302 	.tokens = {
6303 		(void *)&cmd_showport_show,
6304 		(void *)&cmd_showport_port,
6305 		(void *)&cmd_showport_what,
6306 		(void *)&cmd_showport_portnum,
6307 		NULL,
6308 	},
6309 };
6310 
6311 /* *** SHOW QUEUE INFO *** */
6312 struct cmd_showqueue_result {
6313 	cmdline_fixed_string_t show;
6314 	cmdline_fixed_string_t type;
6315 	cmdline_fixed_string_t what;
6316 	uint8_t portnum;
6317 	uint16_t queuenum;
6318 };
6319 
6320 static void
6321 cmd_showqueue_parsed(void *parsed_result,
6322 	__attribute__((unused)) struct cmdline *cl,
6323 	__attribute__((unused)) void *data)
6324 {
6325 	struct cmd_showqueue_result *res = parsed_result;
6326 
6327 	if (!strcmp(res->type, "rxq"))
6328 		rx_queue_infos_display(res->portnum, res->queuenum);
6329 	else if (!strcmp(res->type, "txq"))
6330 		tx_queue_infos_display(res->portnum, res->queuenum);
6331 }
6332 
6333 cmdline_parse_token_string_t cmd_showqueue_show =
6334 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6335 cmdline_parse_token_string_t cmd_showqueue_type =
6336 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6337 cmdline_parse_token_string_t cmd_showqueue_what =
6338 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6339 cmdline_parse_token_num_t cmd_showqueue_portnum =
6340 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
6341 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6342 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6343 
6344 cmdline_parse_inst_t cmd_showqueue = {
6345 	.f = cmd_showqueue_parsed,
6346 	.data = NULL,
6347 	.help_str = "show rxq|txq info <port_id> <queue_id>",
6348 	.tokens = {
6349 		(void *)&cmd_showqueue_show,
6350 		(void *)&cmd_showqueue_type,
6351 		(void *)&cmd_showqueue_what,
6352 		(void *)&cmd_showqueue_portnum,
6353 		(void *)&cmd_showqueue_queuenum,
6354 		NULL,
6355 	},
6356 };
6357 
6358 /* *** READ PORT REGISTER *** */
6359 struct cmd_read_reg_result {
6360 	cmdline_fixed_string_t read;
6361 	cmdline_fixed_string_t reg;
6362 	uint8_t port_id;
6363 	uint32_t reg_off;
6364 };
6365 
6366 static void
6367 cmd_read_reg_parsed(void *parsed_result,
6368 		    __attribute__((unused)) struct cmdline *cl,
6369 		    __attribute__((unused)) void *data)
6370 {
6371 	struct cmd_read_reg_result *res = parsed_result;
6372 	port_reg_display(res->port_id, res->reg_off);
6373 }
6374 
6375 cmdline_parse_token_string_t cmd_read_reg_read =
6376 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6377 cmdline_parse_token_string_t cmd_read_reg_reg =
6378 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6379 cmdline_parse_token_num_t cmd_read_reg_port_id =
6380 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
6381 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6382 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6383 
6384 cmdline_parse_inst_t cmd_read_reg = {
6385 	.f = cmd_read_reg_parsed,
6386 	.data = NULL,
6387 	.help_str = "read reg <port_id> <reg_off>",
6388 	.tokens = {
6389 		(void *)&cmd_read_reg_read,
6390 		(void *)&cmd_read_reg_reg,
6391 		(void *)&cmd_read_reg_port_id,
6392 		(void *)&cmd_read_reg_reg_off,
6393 		NULL,
6394 	},
6395 };
6396 
6397 /* *** READ PORT REGISTER BIT FIELD *** */
6398 struct cmd_read_reg_bit_field_result {
6399 	cmdline_fixed_string_t read;
6400 	cmdline_fixed_string_t regfield;
6401 	uint8_t port_id;
6402 	uint32_t reg_off;
6403 	uint8_t bit1_pos;
6404 	uint8_t bit2_pos;
6405 };
6406 
6407 static void
6408 cmd_read_reg_bit_field_parsed(void *parsed_result,
6409 			      __attribute__((unused)) struct cmdline *cl,
6410 			      __attribute__((unused)) void *data)
6411 {
6412 	struct cmd_read_reg_bit_field_result *res = parsed_result;
6413 	port_reg_bit_field_display(res->port_id, res->reg_off,
6414 				   res->bit1_pos, res->bit2_pos);
6415 }
6416 
6417 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6418 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6419 				 "read");
6420 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6421 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6422 				 regfield, "regfield");
6423 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6424 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6425 			      UINT8);
6426 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6427 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6428 			      UINT32);
6429 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6430 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6431 			      UINT8);
6432 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6433 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6434 			      UINT8);
6435 
6436 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6437 	.f = cmd_read_reg_bit_field_parsed,
6438 	.data = NULL,
6439 	.help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6440 	"Read register bit field between bit_x and bit_y included",
6441 	.tokens = {
6442 		(void *)&cmd_read_reg_bit_field_read,
6443 		(void *)&cmd_read_reg_bit_field_regfield,
6444 		(void *)&cmd_read_reg_bit_field_port_id,
6445 		(void *)&cmd_read_reg_bit_field_reg_off,
6446 		(void *)&cmd_read_reg_bit_field_bit1_pos,
6447 		(void *)&cmd_read_reg_bit_field_bit2_pos,
6448 		NULL,
6449 	},
6450 };
6451 
6452 /* *** READ PORT REGISTER BIT *** */
6453 struct cmd_read_reg_bit_result {
6454 	cmdline_fixed_string_t read;
6455 	cmdline_fixed_string_t regbit;
6456 	uint8_t port_id;
6457 	uint32_t reg_off;
6458 	uint8_t bit_pos;
6459 };
6460 
6461 static void
6462 cmd_read_reg_bit_parsed(void *parsed_result,
6463 			__attribute__((unused)) struct cmdline *cl,
6464 			__attribute__((unused)) void *data)
6465 {
6466 	struct cmd_read_reg_bit_result *res = parsed_result;
6467 	port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6468 }
6469 
6470 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6471 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6472 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6473 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6474 				 regbit, "regbit");
6475 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6476 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
6477 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6478 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6479 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6480 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6481 
6482 cmdline_parse_inst_t cmd_read_reg_bit = {
6483 	.f = cmd_read_reg_bit_parsed,
6484 	.data = NULL,
6485 	.help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6486 	.tokens = {
6487 		(void *)&cmd_read_reg_bit_read,
6488 		(void *)&cmd_read_reg_bit_regbit,
6489 		(void *)&cmd_read_reg_bit_port_id,
6490 		(void *)&cmd_read_reg_bit_reg_off,
6491 		(void *)&cmd_read_reg_bit_bit_pos,
6492 		NULL,
6493 	},
6494 };
6495 
6496 /* *** WRITE PORT REGISTER *** */
6497 struct cmd_write_reg_result {
6498 	cmdline_fixed_string_t write;
6499 	cmdline_fixed_string_t reg;
6500 	uint8_t port_id;
6501 	uint32_t reg_off;
6502 	uint32_t value;
6503 };
6504 
6505 static void
6506 cmd_write_reg_parsed(void *parsed_result,
6507 		     __attribute__((unused)) struct cmdline *cl,
6508 		     __attribute__((unused)) void *data)
6509 {
6510 	struct cmd_write_reg_result *res = parsed_result;
6511 	port_reg_set(res->port_id, res->reg_off, res->value);
6512 }
6513 
6514 cmdline_parse_token_string_t cmd_write_reg_write =
6515 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6516 cmdline_parse_token_string_t cmd_write_reg_reg =
6517 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6518 cmdline_parse_token_num_t cmd_write_reg_port_id =
6519 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
6520 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6521 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6522 cmdline_parse_token_num_t cmd_write_reg_value =
6523 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6524 
6525 cmdline_parse_inst_t cmd_write_reg = {
6526 	.f = cmd_write_reg_parsed,
6527 	.data = NULL,
6528 	.help_str = "write reg <port_id> <reg_off> <reg_value>",
6529 	.tokens = {
6530 		(void *)&cmd_write_reg_write,
6531 		(void *)&cmd_write_reg_reg,
6532 		(void *)&cmd_write_reg_port_id,
6533 		(void *)&cmd_write_reg_reg_off,
6534 		(void *)&cmd_write_reg_value,
6535 		NULL,
6536 	},
6537 };
6538 
6539 /* *** WRITE PORT REGISTER BIT FIELD *** */
6540 struct cmd_write_reg_bit_field_result {
6541 	cmdline_fixed_string_t write;
6542 	cmdline_fixed_string_t regfield;
6543 	uint8_t port_id;
6544 	uint32_t reg_off;
6545 	uint8_t bit1_pos;
6546 	uint8_t bit2_pos;
6547 	uint32_t value;
6548 };
6549 
6550 static void
6551 cmd_write_reg_bit_field_parsed(void *parsed_result,
6552 			       __attribute__((unused)) struct cmdline *cl,
6553 			       __attribute__((unused)) void *data)
6554 {
6555 	struct cmd_write_reg_bit_field_result *res = parsed_result;
6556 	port_reg_bit_field_set(res->port_id, res->reg_off,
6557 			  res->bit1_pos, res->bit2_pos, res->value);
6558 }
6559 
6560 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6561 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6562 				 "write");
6563 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6564 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6565 				 regfield, "regfield");
6566 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6567 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6568 			      UINT8);
6569 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6570 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6571 			      UINT32);
6572 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6573 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6574 			      UINT8);
6575 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6576 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6577 			      UINT8);
6578 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6579 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6580 			      UINT32);
6581 
6582 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6583 	.f = cmd_write_reg_bit_field_parsed,
6584 	.data = NULL,
6585 	.help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6586 		"<reg_value>: "
6587 		"Set register bit field between bit_x and bit_y included",
6588 	.tokens = {
6589 		(void *)&cmd_write_reg_bit_field_write,
6590 		(void *)&cmd_write_reg_bit_field_regfield,
6591 		(void *)&cmd_write_reg_bit_field_port_id,
6592 		(void *)&cmd_write_reg_bit_field_reg_off,
6593 		(void *)&cmd_write_reg_bit_field_bit1_pos,
6594 		(void *)&cmd_write_reg_bit_field_bit2_pos,
6595 		(void *)&cmd_write_reg_bit_field_value,
6596 		NULL,
6597 	},
6598 };
6599 
6600 /* *** WRITE PORT REGISTER BIT *** */
6601 struct cmd_write_reg_bit_result {
6602 	cmdline_fixed_string_t write;
6603 	cmdline_fixed_string_t regbit;
6604 	uint8_t port_id;
6605 	uint32_t reg_off;
6606 	uint8_t bit_pos;
6607 	uint8_t value;
6608 };
6609 
6610 static void
6611 cmd_write_reg_bit_parsed(void *parsed_result,
6612 			 __attribute__((unused)) struct cmdline *cl,
6613 			 __attribute__((unused)) void *data)
6614 {
6615 	struct cmd_write_reg_bit_result *res = parsed_result;
6616 	port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6617 }
6618 
6619 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6620 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6621 				 "write");
6622 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6623 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6624 				 regbit, "regbit");
6625 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6626 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
6627 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6628 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6629 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6630 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6631 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6632 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6633 
6634 cmdline_parse_inst_t cmd_write_reg_bit = {
6635 	.f = cmd_write_reg_bit_parsed,
6636 	.data = NULL,
6637 	.help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6638 		"0 <= bit_x <= 31",
6639 	.tokens = {
6640 		(void *)&cmd_write_reg_bit_write,
6641 		(void *)&cmd_write_reg_bit_regbit,
6642 		(void *)&cmd_write_reg_bit_port_id,
6643 		(void *)&cmd_write_reg_bit_reg_off,
6644 		(void *)&cmd_write_reg_bit_bit_pos,
6645 		(void *)&cmd_write_reg_bit_value,
6646 		NULL,
6647 	},
6648 };
6649 
6650 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6651 struct cmd_read_rxd_txd_result {
6652 	cmdline_fixed_string_t read;
6653 	cmdline_fixed_string_t rxd_txd;
6654 	uint8_t port_id;
6655 	uint16_t queue_id;
6656 	uint16_t desc_id;
6657 };
6658 
6659 static void
6660 cmd_read_rxd_txd_parsed(void *parsed_result,
6661 			__attribute__((unused)) struct cmdline *cl,
6662 			__attribute__((unused)) void *data)
6663 {
6664 	struct cmd_read_rxd_txd_result *res = parsed_result;
6665 
6666 	if (!strcmp(res->rxd_txd, "rxd"))
6667 		rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6668 	else if (!strcmp(res->rxd_txd, "txd"))
6669 		tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6670 }
6671 
6672 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6673 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6674 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6675 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6676 				 "rxd#txd");
6677 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6678 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
6679 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6680 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6681 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6682 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6683 
6684 cmdline_parse_inst_t cmd_read_rxd_txd = {
6685 	.f = cmd_read_rxd_txd_parsed,
6686 	.data = NULL,
6687 	.help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6688 	.tokens = {
6689 		(void *)&cmd_read_rxd_txd_read,
6690 		(void *)&cmd_read_rxd_txd_rxd_txd,
6691 		(void *)&cmd_read_rxd_txd_port_id,
6692 		(void *)&cmd_read_rxd_txd_queue_id,
6693 		(void *)&cmd_read_rxd_txd_desc_id,
6694 		NULL,
6695 	},
6696 };
6697 
6698 /* *** QUIT *** */
6699 struct cmd_quit_result {
6700 	cmdline_fixed_string_t quit;
6701 };
6702 
6703 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6704 			    struct cmdline *cl,
6705 			    __attribute__((unused)) void *data)
6706 {
6707 	pmd_test_exit();
6708 	cmdline_quit(cl);
6709 }
6710 
6711 cmdline_parse_token_string_t cmd_quit_quit =
6712 	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6713 
6714 cmdline_parse_inst_t cmd_quit = {
6715 	.f = cmd_quit_parsed,
6716 	.data = NULL,
6717 	.help_str = "quit: Exit application",
6718 	.tokens = {
6719 		(void *)&cmd_quit_quit,
6720 		NULL,
6721 	},
6722 };
6723 
6724 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
6725 struct cmd_mac_addr_result {
6726 	cmdline_fixed_string_t mac_addr_cmd;
6727 	cmdline_fixed_string_t what;
6728 	uint8_t port_num;
6729 	struct ether_addr address;
6730 };
6731 
6732 static void cmd_mac_addr_parsed(void *parsed_result,
6733 		__attribute__((unused)) struct cmdline *cl,
6734 		__attribute__((unused)) void *data)
6735 {
6736 	struct cmd_mac_addr_result *res = parsed_result;
6737 	int ret;
6738 
6739 	if (strcmp(res->what, "add") == 0)
6740 		ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
6741 	else if (strcmp(res->what, "set") == 0)
6742 		ret = rte_eth_dev_default_mac_addr_set(res->port_num,
6743 						       &res->address);
6744 	else
6745 		ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
6746 
6747 	/* check the return value and print it if is < 0 */
6748 	if(ret < 0)
6749 		printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
6750 
6751 }
6752 
6753 cmdline_parse_token_string_t cmd_mac_addr_cmd =
6754 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
6755 				"mac_addr");
6756 cmdline_parse_token_string_t cmd_mac_addr_what =
6757 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
6758 				"add#remove#set");
6759 cmdline_parse_token_num_t cmd_mac_addr_portnum =
6760 		TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
6761 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
6762 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
6763 
6764 cmdline_parse_inst_t cmd_mac_addr = {
6765 	.f = cmd_mac_addr_parsed,
6766 	.data = (void *)0,
6767 	.help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
6768 			"Add/Remove/Set MAC address on port_id",
6769 	.tokens = {
6770 		(void *)&cmd_mac_addr_cmd,
6771 		(void *)&cmd_mac_addr_what,
6772 		(void *)&cmd_mac_addr_portnum,
6773 		(void *)&cmd_mac_addr_addr,
6774 		NULL,
6775 	},
6776 };
6777 
6778 
6779 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
6780 struct cmd_set_qmap_result {
6781 	cmdline_fixed_string_t set;
6782 	cmdline_fixed_string_t qmap;
6783 	cmdline_fixed_string_t what;
6784 	uint8_t port_id;
6785 	uint16_t queue_id;
6786 	uint8_t map_value;
6787 };
6788 
6789 static void
6790 cmd_set_qmap_parsed(void *parsed_result,
6791 		       __attribute__((unused)) struct cmdline *cl,
6792 		       __attribute__((unused)) void *data)
6793 {
6794 	struct cmd_set_qmap_result *res = parsed_result;
6795 	int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
6796 
6797 	set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
6798 }
6799 
6800 cmdline_parse_token_string_t cmd_setqmap_set =
6801 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6802 				 set, "set");
6803 cmdline_parse_token_string_t cmd_setqmap_qmap =
6804 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6805 				 qmap, "stat_qmap");
6806 cmdline_parse_token_string_t cmd_setqmap_what =
6807 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
6808 				 what, "tx#rx");
6809 cmdline_parse_token_num_t cmd_setqmap_portid =
6810 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6811 			      port_id, UINT8);
6812 cmdline_parse_token_num_t cmd_setqmap_queueid =
6813 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6814 			      queue_id, UINT16);
6815 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
6816 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
6817 			      map_value, UINT8);
6818 
6819 cmdline_parse_inst_t cmd_set_qmap = {
6820 	.f = cmd_set_qmap_parsed,
6821 	.data = NULL,
6822 	.help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
6823 		"Set statistics mapping value on tx|rx queue_id of port_id",
6824 	.tokens = {
6825 		(void *)&cmd_setqmap_set,
6826 		(void *)&cmd_setqmap_qmap,
6827 		(void *)&cmd_setqmap_what,
6828 		(void *)&cmd_setqmap_portid,
6829 		(void *)&cmd_setqmap_queueid,
6830 		(void *)&cmd_setqmap_mapvalue,
6831 		NULL,
6832 	},
6833 };
6834 
6835 /* *** CONFIGURE UNICAST HASH TABLE *** */
6836 struct cmd_set_uc_hash_table {
6837 	cmdline_fixed_string_t set;
6838 	cmdline_fixed_string_t port;
6839 	uint8_t port_id;
6840 	cmdline_fixed_string_t what;
6841 	struct ether_addr address;
6842 	cmdline_fixed_string_t mode;
6843 };
6844 
6845 static void
6846 cmd_set_uc_hash_parsed(void *parsed_result,
6847 		       __attribute__((unused)) struct cmdline *cl,
6848 		       __attribute__((unused)) void *data)
6849 {
6850 	int ret=0;
6851 	struct cmd_set_uc_hash_table *res = parsed_result;
6852 
6853 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6854 
6855 	if (strcmp(res->what, "uta") == 0)
6856 		ret = rte_eth_dev_uc_hash_table_set(res->port_id,
6857 						&res->address,(uint8_t)is_on);
6858 	if (ret < 0)
6859 		printf("bad unicast hash table parameter, return code = %d \n", ret);
6860 
6861 }
6862 
6863 cmdline_parse_token_string_t cmd_set_uc_hash_set =
6864 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6865 				 set, "set");
6866 cmdline_parse_token_string_t cmd_set_uc_hash_port =
6867 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6868 				 port, "port");
6869 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
6870 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
6871 			      port_id, UINT8);
6872 cmdline_parse_token_string_t cmd_set_uc_hash_what =
6873 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6874 				 what, "uta");
6875 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
6876 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
6877 				address);
6878 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
6879 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6880 				 mode, "on#off");
6881 
6882 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
6883 	.f = cmd_set_uc_hash_parsed,
6884 	.data = NULL,
6885 	.help_str = "set port <port_id> uta <mac_addr> on|off)",
6886 	.tokens = {
6887 		(void *)&cmd_set_uc_hash_set,
6888 		(void *)&cmd_set_uc_hash_port,
6889 		(void *)&cmd_set_uc_hash_portid,
6890 		(void *)&cmd_set_uc_hash_what,
6891 		(void *)&cmd_set_uc_hash_mac,
6892 		(void *)&cmd_set_uc_hash_mode,
6893 		NULL,
6894 	},
6895 };
6896 
6897 struct cmd_set_uc_all_hash_table {
6898 	cmdline_fixed_string_t set;
6899 	cmdline_fixed_string_t port;
6900 	uint8_t port_id;
6901 	cmdline_fixed_string_t what;
6902 	cmdline_fixed_string_t value;
6903 	cmdline_fixed_string_t mode;
6904 };
6905 
6906 static void
6907 cmd_set_uc_all_hash_parsed(void *parsed_result,
6908 		       __attribute__((unused)) struct cmdline *cl,
6909 		       __attribute__((unused)) void *data)
6910 {
6911 	int ret=0;
6912 	struct cmd_set_uc_all_hash_table *res = parsed_result;
6913 
6914 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6915 
6916 	if ((strcmp(res->what, "uta") == 0) &&
6917 		(strcmp(res->value, "all") == 0))
6918 		ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
6919 	if (ret < 0)
6920 		printf("bad unicast hash table parameter,"
6921 			"return code = %d \n", ret);
6922 }
6923 
6924 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
6925 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6926 				 set, "set");
6927 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
6928 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6929 				 port, "port");
6930 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
6931 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
6932 			      port_id, UINT8);
6933 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
6934 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6935 				 what, "uta");
6936 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
6937 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6938 				value,"all");
6939 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
6940 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6941 				 mode, "on#off");
6942 
6943 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
6944 	.f = cmd_set_uc_all_hash_parsed,
6945 	.data = NULL,
6946 	.help_str = "set port <port_id> uta all on|off",
6947 	.tokens = {
6948 		(void *)&cmd_set_uc_all_hash_set,
6949 		(void *)&cmd_set_uc_all_hash_port,
6950 		(void *)&cmd_set_uc_all_hash_portid,
6951 		(void *)&cmd_set_uc_all_hash_what,
6952 		(void *)&cmd_set_uc_all_hash_value,
6953 		(void *)&cmd_set_uc_all_hash_mode,
6954 		NULL,
6955 	},
6956 };
6957 
6958 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
6959 struct cmd_set_vf_macvlan_filter {
6960 	cmdline_fixed_string_t set;
6961 	cmdline_fixed_string_t port;
6962 	uint8_t port_id;
6963 	cmdline_fixed_string_t vf;
6964 	uint8_t vf_id;
6965 	struct ether_addr address;
6966 	cmdline_fixed_string_t filter_type;
6967 	cmdline_fixed_string_t mode;
6968 };
6969 
6970 static void
6971 cmd_set_vf_macvlan_parsed(void *parsed_result,
6972 		       __attribute__((unused)) struct cmdline *cl,
6973 		       __attribute__((unused)) void *data)
6974 {
6975 	int is_on, ret = 0;
6976 	struct cmd_set_vf_macvlan_filter *res = parsed_result;
6977 	struct rte_eth_mac_filter filter;
6978 
6979 	memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
6980 
6981 	rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
6982 
6983 	/* set VF MAC filter */
6984 	filter.is_vf = 1;
6985 
6986 	/* set VF ID */
6987 	filter.dst_id = res->vf_id;
6988 
6989 	if (!strcmp(res->filter_type, "exact-mac"))
6990 		filter.filter_type = RTE_MAC_PERFECT_MATCH;
6991 	else if (!strcmp(res->filter_type, "exact-mac-vlan"))
6992 		filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
6993 	else if (!strcmp(res->filter_type, "hashmac"))
6994 		filter.filter_type = RTE_MAC_HASH_MATCH;
6995 	else if (!strcmp(res->filter_type, "hashmac-vlan"))
6996 		filter.filter_type = RTE_MACVLAN_HASH_MATCH;
6997 
6998 	is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6999 
7000 	if (is_on)
7001 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7002 					RTE_ETH_FILTER_MACVLAN,
7003 					RTE_ETH_FILTER_ADD,
7004 					 &filter);
7005 	else
7006 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7007 					RTE_ETH_FILTER_MACVLAN,
7008 					RTE_ETH_FILTER_DELETE,
7009 					&filter);
7010 
7011 	if (ret < 0)
7012 		printf("bad set MAC hash parameter, return code = %d\n", ret);
7013 
7014 }
7015 
7016 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7017 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7018 				 set, "set");
7019 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7020 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7021 				 port, "port");
7022 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7023 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7024 			      port_id, UINT8);
7025 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7026 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7027 				 vf, "vf");
7028 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7029 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7030 				vf_id, UINT8);
7031 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7032 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7033 				address);
7034 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7035 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7036 				filter_type, "exact-mac#exact-mac-vlan"
7037 				"#hashmac#hashmac-vlan");
7038 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7039 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7040 				 mode, "on#off");
7041 
7042 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7043 	.f = cmd_set_vf_macvlan_parsed,
7044 	.data = NULL,
7045 	.help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7046 		"exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7047 		"Exact match rule: exact match of MAC or MAC and VLAN; "
7048 		"hash match rule: hash match of MAC and exact match of VLAN",
7049 	.tokens = {
7050 		(void *)&cmd_set_vf_macvlan_set,
7051 		(void *)&cmd_set_vf_macvlan_port,
7052 		(void *)&cmd_set_vf_macvlan_portid,
7053 		(void *)&cmd_set_vf_macvlan_vf,
7054 		(void *)&cmd_set_vf_macvlan_vf_id,
7055 		(void *)&cmd_set_vf_macvlan_mac,
7056 		(void *)&cmd_set_vf_macvlan_filter_type,
7057 		(void *)&cmd_set_vf_macvlan_mode,
7058 		NULL,
7059 	},
7060 };
7061 
7062 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7063 struct cmd_set_vf_traffic {
7064 	cmdline_fixed_string_t set;
7065 	cmdline_fixed_string_t port;
7066 	uint8_t port_id;
7067 	cmdline_fixed_string_t vf;
7068 	uint8_t vf_id;
7069 	cmdline_fixed_string_t what;
7070 	cmdline_fixed_string_t mode;
7071 };
7072 
7073 static void
7074 cmd_set_vf_traffic_parsed(void *parsed_result,
7075 		       __attribute__((unused)) struct cmdline *cl,
7076 		       __attribute__((unused)) void *data)
7077 {
7078 	struct cmd_set_vf_traffic *res = parsed_result;
7079 	int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7080 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7081 
7082 	set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7083 }
7084 
7085 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7086 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7087 				 set, "set");
7088 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7089 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7090 				 port, "port");
7091 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7092 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7093 			      port_id, UINT8);
7094 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7095 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7096 				 vf, "vf");
7097 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7098 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7099 			      vf_id, UINT8);
7100 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7101 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7102 				 what, "tx#rx");
7103 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7104 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7105 				 mode, "on#off");
7106 
7107 cmdline_parse_inst_t cmd_set_vf_traffic = {
7108 	.f = cmd_set_vf_traffic_parsed,
7109 	.data = NULL,
7110 	.help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7111 	.tokens = {
7112 		(void *)&cmd_setvf_traffic_set,
7113 		(void *)&cmd_setvf_traffic_port,
7114 		(void *)&cmd_setvf_traffic_portid,
7115 		(void *)&cmd_setvf_traffic_vf,
7116 		(void *)&cmd_setvf_traffic_vfid,
7117 		(void *)&cmd_setvf_traffic_what,
7118 		(void *)&cmd_setvf_traffic_mode,
7119 		NULL,
7120 	},
7121 };
7122 
7123 /* *** CONFIGURE VF RECEIVE MODE *** */
7124 struct cmd_set_vf_rxmode {
7125 	cmdline_fixed_string_t set;
7126 	cmdline_fixed_string_t port;
7127 	uint8_t port_id;
7128 	cmdline_fixed_string_t vf;
7129 	uint8_t vf_id;
7130 	cmdline_fixed_string_t what;
7131 	cmdline_fixed_string_t mode;
7132 	cmdline_fixed_string_t on;
7133 };
7134 
7135 static void
7136 cmd_set_vf_rxmode_parsed(void *parsed_result,
7137 		       __attribute__((unused)) struct cmdline *cl,
7138 		       __attribute__((unused)) void *data)
7139 {
7140 	int ret = -ENOTSUP;
7141 	uint16_t rx_mode = 0;
7142 	struct cmd_set_vf_rxmode *res = parsed_result;
7143 
7144 	int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7145 	if (!strcmp(res->what,"rxmode")) {
7146 		if (!strcmp(res->mode, "AUPE"))
7147 			rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7148 		else if (!strcmp(res->mode, "ROPE"))
7149 			rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7150 		else if (!strcmp(res->mode, "BAM"))
7151 			rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7152 		else if (!strncmp(res->mode, "MPE",3))
7153 			rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7154 	}
7155 
7156 #ifdef RTE_LIBRTE_IXGBE_PMD
7157 	if (ret == -ENOTSUP)
7158 		ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7159 						  rx_mode, (uint8_t)is_on);
7160 #endif
7161 #ifdef RTE_LIBRTE_BNXT_PMD
7162 	if (ret == -ENOTSUP)
7163 		ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7164 						 rx_mode, (uint8_t)is_on);
7165 #endif
7166 	if (ret < 0)
7167 		printf("bad VF receive mode parameter, return code = %d \n",
7168 		ret);
7169 }
7170 
7171 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7172 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7173 				 set, "set");
7174 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7175 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7176 				 port, "port");
7177 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7178 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7179 			      port_id, UINT8);
7180 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7181 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7182 				 vf, "vf");
7183 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7184 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7185 			      vf_id, UINT8);
7186 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7187 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7188 				 what, "rxmode");
7189 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7190 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7191 				 mode, "AUPE#ROPE#BAM#MPE");
7192 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7193 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7194 				 on, "on#off");
7195 
7196 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7197 	.f = cmd_set_vf_rxmode_parsed,
7198 	.data = NULL,
7199 	.help_str = "set port <port_id> vf <vf_id> rxmode "
7200 		"AUPE|ROPE|BAM|MPE on|off",
7201 	.tokens = {
7202 		(void *)&cmd_set_vf_rxmode_set,
7203 		(void *)&cmd_set_vf_rxmode_port,
7204 		(void *)&cmd_set_vf_rxmode_portid,
7205 		(void *)&cmd_set_vf_rxmode_vf,
7206 		(void *)&cmd_set_vf_rxmode_vfid,
7207 		(void *)&cmd_set_vf_rxmode_what,
7208 		(void *)&cmd_set_vf_rxmode_mode,
7209 		(void *)&cmd_set_vf_rxmode_on,
7210 		NULL,
7211 	},
7212 };
7213 
7214 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7215 struct cmd_vf_mac_addr_result {
7216 	cmdline_fixed_string_t mac_addr_cmd;
7217 	cmdline_fixed_string_t what;
7218 	cmdline_fixed_string_t port;
7219 	uint8_t port_num;
7220 	cmdline_fixed_string_t vf;
7221 	uint8_t vf_num;
7222 	struct ether_addr address;
7223 };
7224 
7225 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7226 		__attribute__((unused)) struct cmdline *cl,
7227 		__attribute__((unused)) void *data)
7228 {
7229 	struct cmd_vf_mac_addr_result *res = parsed_result;
7230 	int ret = -ENOTSUP;
7231 
7232 	if (strcmp(res->what, "add") != 0)
7233 		return;
7234 
7235 #ifdef RTE_LIBRTE_I40E_PMD
7236 	if (ret == -ENOTSUP)
7237 		ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7238 						   &res->address);
7239 #endif
7240 #ifdef RTE_LIBRTE_BNXT_PMD
7241 	if (ret == -ENOTSUP)
7242 		ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7243 						res->vf_num);
7244 #endif
7245 
7246 	if(ret < 0)
7247 		printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7248 
7249 }
7250 
7251 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7252 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7253 				mac_addr_cmd,"mac_addr");
7254 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7255 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7256 				what,"add");
7257 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7258 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7259 				port,"port");
7260 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7261 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7262 				port_num, UINT8);
7263 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7264 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7265 				vf,"vf");
7266 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7267 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7268 				vf_num, UINT8);
7269 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7270 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7271 				address);
7272 
7273 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7274 	.f = cmd_vf_mac_addr_parsed,
7275 	.data = (void *)0,
7276 	.help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7277 		"Add MAC address filtering for a VF on port_id",
7278 	.tokens = {
7279 		(void *)&cmd_vf_mac_addr_cmd,
7280 		(void *)&cmd_vf_mac_addr_what,
7281 		(void *)&cmd_vf_mac_addr_port,
7282 		(void *)&cmd_vf_mac_addr_portnum,
7283 		(void *)&cmd_vf_mac_addr_vf,
7284 		(void *)&cmd_vf_mac_addr_vfnum,
7285 		(void *)&cmd_vf_mac_addr_addr,
7286 		NULL,
7287 	},
7288 };
7289 
7290 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7291 struct cmd_vf_rx_vlan_filter {
7292 	cmdline_fixed_string_t rx_vlan;
7293 	cmdline_fixed_string_t what;
7294 	uint16_t vlan_id;
7295 	cmdline_fixed_string_t port;
7296 	uint8_t port_id;
7297 	cmdline_fixed_string_t vf;
7298 	uint64_t vf_mask;
7299 };
7300 
7301 static void
7302 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7303 			  __attribute__((unused)) struct cmdline *cl,
7304 			  __attribute__((unused)) void *data)
7305 {
7306 	struct cmd_vf_rx_vlan_filter *res = parsed_result;
7307 	int ret = -ENOTSUP;
7308 
7309 	__rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7310 
7311 #ifdef RTE_LIBRTE_IXGBE_PMD
7312 	if (ret == -ENOTSUP)
7313 		ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7314 				res->vlan_id, res->vf_mask, is_add);
7315 #endif
7316 #ifdef RTE_LIBRTE_I40E_PMD
7317 	if (ret == -ENOTSUP)
7318 		ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7319 				res->vlan_id, res->vf_mask, is_add);
7320 #endif
7321 #ifdef RTE_LIBRTE_BNXT_PMD
7322 	if (ret == -ENOTSUP)
7323 		ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7324 				res->vlan_id, res->vf_mask, is_add);
7325 #endif
7326 
7327 	switch (ret) {
7328 	case 0:
7329 		break;
7330 	case -EINVAL:
7331 		printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7332 				res->vlan_id, res->vf_mask);
7333 		break;
7334 	case -ENODEV:
7335 		printf("invalid port_id %d\n", res->port_id);
7336 		break;
7337 	case -ENOTSUP:
7338 		printf("function not implemented or supported\n");
7339 		break;
7340 	default:
7341 		printf("programming error: (%s)\n", strerror(-ret));
7342 	}
7343 }
7344 
7345 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7346 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7347 				 rx_vlan, "rx_vlan");
7348 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7349 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7350 				 what, "add#rm");
7351 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7352 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7353 			      vlan_id, UINT16);
7354 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7355 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7356 				 port, "port");
7357 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7358 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7359 			      port_id, UINT8);
7360 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7361 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7362 				 vf, "vf");
7363 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7364 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7365 			      vf_mask, UINT64);
7366 
7367 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7368 	.f = cmd_vf_rx_vlan_filter_parsed,
7369 	.data = NULL,
7370 	.help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7371 		"(vf_mask = hexadecimal VF mask)",
7372 	.tokens = {
7373 		(void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7374 		(void *)&cmd_vf_rx_vlan_filter_what,
7375 		(void *)&cmd_vf_rx_vlan_filter_vlanid,
7376 		(void *)&cmd_vf_rx_vlan_filter_port,
7377 		(void *)&cmd_vf_rx_vlan_filter_portid,
7378 		(void *)&cmd_vf_rx_vlan_filter_vf,
7379 		(void *)&cmd_vf_rx_vlan_filter_vf_mask,
7380 		NULL,
7381 	},
7382 };
7383 
7384 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7385 struct cmd_queue_rate_limit_result {
7386 	cmdline_fixed_string_t set;
7387 	cmdline_fixed_string_t port;
7388 	uint8_t port_num;
7389 	cmdline_fixed_string_t queue;
7390 	uint8_t queue_num;
7391 	cmdline_fixed_string_t rate;
7392 	uint16_t rate_num;
7393 };
7394 
7395 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7396 		__attribute__((unused)) struct cmdline *cl,
7397 		__attribute__((unused)) void *data)
7398 {
7399 	struct cmd_queue_rate_limit_result *res = parsed_result;
7400 	int ret = 0;
7401 
7402 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7403 		&& (strcmp(res->queue, "queue") == 0)
7404 		&& (strcmp(res->rate, "rate") == 0))
7405 		ret = set_queue_rate_limit(res->port_num, res->queue_num,
7406 					res->rate_num);
7407 	if (ret < 0)
7408 		printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7409 
7410 }
7411 
7412 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7413 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7414 				set, "set");
7415 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7416 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7417 				port, "port");
7418 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7419 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7420 				port_num, UINT8);
7421 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7422 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7423 				queue, "queue");
7424 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7425 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7426 				queue_num, UINT8);
7427 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7428 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7429 				rate, "rate");
7430 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7431 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7432 				rate_num, UINT16);
7433 
7434 cmdline_parse_inst_t cmd_queue_rate_limit = {
7435 	.f = cmd_queue_rate_limit_parsed,
7436 	.data = (void *)0,
7437 	.help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7438 		"Set rate limit for a queue on port_id",
7439 	.tokens = {
7440 		(void *)&cmd_queue_rate_limit_set,
7441 		(void *)&cmd_queue_rate_limit_port,
7442 		(void *)&cmd_queue_rate_limit_portnum,
7443 		(void *)&cmd_queue_rate_limit_queue,
7444 		(void *)&cmd_queue_rate_limit_queuenum,
7445 		(void *)&cmd_queue_rate_limit_rate,
7446 		(void *)&cmd_queue_rate_limit_ratenum,
7447 		NULL,
7448 	},
7449 };
7450 
7451 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7452 struct cmd_vf_rate_limit_result {
7453 	cmdline_fixed_string_t set;
7454 	cmdline_fixed_string_t port;
7455 	uint8_t port_num;
7456 	cmdline_fixed_string_t vf;
7457 	uint8_t vf_num;
7458 	cmdline_fixed_string_t rate;
7459 	uint16_t rate_num;
7460 	cmdline_fixed_string_t q_msk;
7461 	uint64_t q_msk_val;
7462 };
7463 
7464 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7465 		__attribute__((unused)) struct cmdline *cl,
7466 		__attribute__((unused)) void *data)
7467 {
7468 	struct cmd_vf_rate_limit_result *res = parsed_result;
7469 	int ret = 0;
7470 
7471 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7472 		&& (strcmp(res->vf, "vf") == 0)
7473 		&& (strcmp(res->rate, "rate") == 0)
7474 		&& (strcmp(res->q_msk, "queue_mask") == 0))
7475 		ret = set_vf_rate_limit(res->port_num, res->vf_num,
7476 					res->rate_num, res->q_msk_val);
7477 	if (ret < 0)
7478 		printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7479 
7480 }
7481 
7482 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7483 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7484 				set, "set");
7485 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7486 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7487 				port, "port");
7488 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7489 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7490 				port_num, UINT8);
7491 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7492 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7493 				vf, "vf");
7494 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7495 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7496 				vf_num, UINT8);
7497 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7498 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7499 				rate, "rate");
7500 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7501 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7502 				rate_num, UINT16);
7503 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7504 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7505 				q_msk, "queue_mask");
7506 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7507 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7508 				q_msk_val, UINT64);
7509 
7510 cmdline_parse_inst_t cmd_vf_rate_limit = {
7511 	.f = cmd_vf_rate_limit_parsed,
7512 	.data = (void *)0,
7513 	.help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7514 		"queue_mask <queue_mask_value>: "
7515 		"Set rate limit for queues of VF on port_id",
7516 	.tokens = {
7517 		(void *)&cmd_vf_rate_limit_set,
7518 		(void *)&cmd_vf_rate_limit_port,
7519 		(void *)&cmd_vf_rate_limit_portnum,
7520 		(void *)&cmd_vf_rate_limit_vf,
7521 		(void *)&cmd_vf_rate_limit_vfnum,
7522 		(void *)&cmd_vf_rate_limit_rate,
7523 		(void *)&cmd_vf_rate_limit_ratenum,
7524 		(void *)&cmd_vf_rate_limit_q_msk,
7525 		(void *)&cmd_vf_rate_limit_q_msk_val,
7526 		NULL,
7527 	},
7528 };
7529 
7530 /* *** ADD TUNNEL FILTER OF A PORT *** */
7531 struct cmd_tunnel_filter_result {
7532 	cmdline_fixed_string_t cmd;
7533 	cmdline_fixed_string_t what;
7534 	uint8_t port_id;
7535 	struct ether_addr outer_mac;
7536 	struct ether_addr inner_mac;
7537 	cmdline_ipaddr_t ip_value;
7538 	uint16_t inner_vlan;
7539 	cmdline_fixed_string_t tunnel_type;
7540 	cmdline_fixed_string_t filter_type;
7541 	uint32_t tenant_id;
7542 	uint16_t queue_num;
7543 };
7544 
7545 static void
7546 cmd_tunnel_filter_parsed(void *parsed_result,
7547 			  __attribute__((unused)) struct cmdline *cl,
7548 			  __attribute__((unused)) void *data)
7549 {
7550 	struct cmd_tunnel_filter_result *res = parsed_result;
7551 	struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7552 	int ret = 0;
7553 
7554 	memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7555 
7556 	ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7557 	ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7558 	tunnel_filter_conf.inner_vlan = res->inner_vlan;
7559 
7560 	if (res->ip_value.family == AF_INET) {
7561 		tunnel_filter_conf.ip_addr.ipv4_addr =
7562 			res->ip_value.addr.ipv4.s_addr;
7563 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7564 	} else {
7565 		memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7566 			&(res->ip_value.addr.ipv6),
7567 			sizeof(struct in6_addr));
7568 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7569 	}
7570 
7571 	if (!strcmp(res->filter_type, "imac-ivlan"))
7572 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7573 	else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7574 		tunnel_filter_conf.filter_type =
7575 			RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7576 	else if (!strcmp(res->filter_type, "imac-tenid"))
7577 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7578 	else if (!strcmp(res->filter_type, "imac"))
7579 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7580 	else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7581 		tunnel_filter_conf.filter_type =
7582 			RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7583 	else if (!strcmp(res->filter_type, "oip"))
7584 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7585 	else if (!strcmp(res->filter_type, "iip"))
7586 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7587 	else {
7588 		printf("The filter type is not supported");
7589 		return;
7590 	}
7591 
7592 	if (!strcmp(res->tunnel_type, "vxlan"))
7593 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7594 	else if (!strcmp(res->tunnel_type, "nvgre"))
7595 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7596 	else if (!strcmp(res->tunnel_type, "ipingre"))
7597 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7598 	else {
7599 		printf("The tunnel type %s not supported.\n", res->tunnel_type);
7600 		return;
7601 	}
7602 
7603 	tunnel_filter_conf.tenant_id = res->tenant_id;
7604 	tunnel_filter_conf.queue_id = res->queue_num;
7605 	if (!strcmp(res->what, "add"))
7606 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7607 					RTE_ETH_FILTER_TUNNEL,
7608 					RTE_ETH_FILTER_ADD,
7609 					&tunnel_filter_conf);
7610 	else
7611 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7612 					RTE_ETH_FILTER_TUNNEL,
7613 					RTE_ETH_FILTER_DELETE,
7614 					&tunnel_filter_conf);
7615 	if (ret < 0)
7616 		printf("cmd_tunnel_filter_parsed error: (%s)\n",
7617 				strerror(-ret));
7618 
7619 }
7620 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7621 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7622 	cmd, "tunnel_filter");
7623 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7624 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7625 	what, "add#rm");
7626 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7627 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7628 	port_id, UINT8);
7629 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7630 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7631 	outer_mac);
7632 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7633 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7634 	inner_mac);
7635 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7636 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7637 	inner_vlan, UINT16);
7638 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7639 	TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7640 	ip_value);
7641 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7642 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7643 	tunnel_type, "vxlan#nvgre#ipingre");
7644 
7645 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7646 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7647 	filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7648 		"imac#omac-imac-tenid");
7649 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7650 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7651 	tenant_id, UINT32);
7652 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7653 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7654 	queue_num, UINT16);
7655 
7656 cmdline_parse_inst_t cmd_tunnel_filter = {
7657 	.f = cmd_tunnel_filter_parsed,
7658 	.data = (void *)0,
7659 	.help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7660 		"<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7661 		"imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7662 		"<queue_id>: Add/Rm tunnel filter of a port",
7663 	.tokens = {
7664 		(void *)&cmd_tunnel_filter_cmd,
7665 		(void *)&cmd_tunnel_filter_what,
7666 		(void *)&cmd_tunnel_filter_port_id,
7667 		(void *)&cmd_tunnel_filter_outer_mac,
7668 		(void *)&cmd_tunnel_filter_inner_mac,
7669 		(void *)&cmd_tunnel_filter_ip_value,
7670 		(void *)&cmd_tunnel_filter_innner_vlan,
7671 		(void *)&cmd_tunnel_filter_tunnel_type,
7672 		(void *)&cmd_tunnel_filter_filter_type,
7673 		(void *)&cmd_tunnel_filter_tenant_id,
7674 		(void *)&cmd_tunnel_filter_queue_num,
7675 		NULL,
7676 	},
7677 };
7678 
7679 /* *** CONFIGURE TUNNEL UDP PORT *** */
7680 struct cmd_tunnel_udp_config {
7681 	cmdline_fixed_string_t cmd;
7682 	cmdline_fixed_string_t what;
7683 	uint16_t udp_port;
7684 	uint8_t port_id;
7685 };
7686 
7687 static void
7688 cmd_tunnel_udp_config_parsed(void *parsed_result,
7689 			  __attribute__((unused)) struct cmdline *cl,
7690 			  __attribute__((unused)) void *data)
7691 {
7692 	struct cmd_tunnel_udp_config *res = parsed_result;
7693 	struct rte_eth_udp_tunnel tunnel_udp;
7694 	int ret;
7695 
7696 	tunnel_udp.udp_port = res->udp_port;
7697 
7698 	if (!strcmp(res->cmd, "rx_vxlan_port"))
7699 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7700 
7701 	if (!strcmp(res->what, "add"))
7702 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7703 						      &tunnel_udp);
7704 	else
7705 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7706 							 &tunnel_udp);
7707 
7708 	if (ret < 0)
7709 		printf("udp tunneling add error: (%s)\n", strerror(-ret));
7710 }
7711 
7712 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7713 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7714 				cmd, "rx_vxlan_port");
7715 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7716 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7717 				what, "add#rm");
7718 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7719 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7720 				udp_port, UINT16);
7721 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7722 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7723 				port_id, UINT8);
7724 
7725 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7726 	.f = cmd_tunnel_udp_config_parsed,
7727 	.data = (void *)0,
7728 	.help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
7729 		"Add/Remove a tunneling UDP port filter",
7730 	.tokens = {
7731 		(void *)&cmd_tunnel_udp_config_cmd,
7732 		(void *)&cmd_tunnel_udp_config_what,
7733 		(void *)&cmd_tunnel_udp_config_udp_port,
7734 		(void *)&cmd_tunnel_udp_config_port_id,
7735 		NULL,
7736 	},
7737 };
7738 
7739 /* *** GLOBAL CONFIG *** */
7740 struct cmd_global_config_result {
7741 	cmdline_fixed_string_t cmd;
7742 	uint8_t port_id;
7743 	cmdline_fixed_string_t cfg_type;
7744 	uint8_t len;
7745 };
7746 
7747 static void
7748 cmd_global_config_parsed(void *parsed_result,
7749 			 __attribute__((unused)) struct cmdline *cl,
7750 			 __attribute__((unused)) void *data)
7751 {
7752 	struct cmd_global_config_result *res = parsed_result;
7753 	struct rte_eth_global_cfg conf;
7754 	int ret;
7755 
7756 	memset(&conf, 0, sizeof(conf));
7757 	conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
7758 	conf.cfg.gre_key_len = res->len;
7759 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
7760 				      RTE_ETH_FILTER_SET, &conf);
7761 	if (ret != 0)
7762 		printf("Global config error\n");
7763 }
7764 
7765 cmdline_parse_token_string_t cmd_global_config_cmd =
7766 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
7767 		"global_config");
7768 cmdline_parse_token_num_t cmd_global_config_port_id =
7769 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
7770 cmdline_parse_token_string_t cmd_global_config_type =
7771 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
7772 		cfg_type, "gre-key-len");
7773 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
7774 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
7775 		len, UINT8);
7776 
7777 cmdline_parse_inst_t cmd_global_config = {
7778 	.f = cmd_global_config_parsed,
7779 	.data = (void *)NULL,
7780 	.help_str = "global_config <port_id> gre-key-len <key_len>",
7781 	.tokens = {
7782 		(void *)&cmd_global_config_cmd,
7783 		(void *)&cmd_global_config_port_id,
7784 		(void *)&cmd_global_config_type,
7785 		(void *)&cmd_global_config_gre_key_len,
7786 		NULL,
7787 	},
7788 };
7789 
7790 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
7791 struct cmd_set_mirror_mask_result {
7792 	cmdline_fixed_string_t set;
7793 	cmdline_fixed_string_t port;
7794 	uint8_t port_id;
7795 	cmdline_fixed_string_t mirror;
7796 	uint8_t rule_id;
7797 	cmdline_fixed_string_t what;
7798 	cmdline_fixed_string_t value;
7799 	cmdline_fixed_string_t dstpool;
7800 	uint8_t dstpool_id;
7801 	cmdline_fixed_string_t on;
7802 };
7803 
7804 cmdline_parse_token_string_t cmd_mirror_mask_set =
7805 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7806 				set, "set");
7807 cmdline_parse_token_string_t cmd_mirror_mask_port =
7808 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7809 				port, "port");
7810 cmdline_parse_token_num_t cmd_mirror_mask_portid =
7811 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7812 				port_id, UINT8);
7813 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
7814 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7815 				mirror, "mirror-rule");
7816 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
7817 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7818 				rule_id, UINT8);
7819 cmdline_parse_token_string_t cmd_mirror_mask_what =
7820 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7821 				what, "pool-mirror-up#pool-mirror-down"
7822 				      "#vlan-mirror");
7823 cmdline_parse_token_string_t cmd_mirror_mask_value =
7824 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7825 				value, NULL);
7826 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
7827 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7828 				dstpool, "dst-pool");
7829 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
7830 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
7831 				dstpool_id, UINT8);
7832 cmdline_parse_token_string_t cmd_mirror_mask_on =
7833 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
7834 				on, "on#off");
7835 
7836 static void
7837 cmd_set_mirror_mask_parsed(void *parsed_result,
7838 		       __attribute__((unused)) struct cmdline *cl,
7839 		       __attribute__((unused)) void *data)
7840 {
7841 	int ret,nb_item,i;
7842 	struct cmd_set_mirror_mask_result *res = parsed_result;
7843 	struct rte_eth_mirror_conf mr_conf;
7844 
7845 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7846 
7847 	unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
7848 
7849 	mr_conf.dst_pool = res->dstpool_id;
7850 
7851 	if (!strcmp(res->what, "pool-mirror-up")) {
7852 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7853 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
7854 	} else if (!strcmp(res->what, "pool-mirror-down")) {
7855 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
7856 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
7857 	} else if (!strcmp(res->what, "vlan-mirror")) {
7858 		mr_conf.rule_type = ETH_MIRROR_VLAN;
7859 		nb_item = parse_item_list(res->value, "vlan",
7860 				ETH_MIRROR_MAX_VLANS, vlan_list, 1);
7861 		if (nb_item <= 0)
7862 			return;
7863 
7864 		for (i = 0; i < nb_item; i++) {
7865 			if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
7866 				printf("Invalid vlan_id: must be < 4096\n");
7867 				return;
7868 			}
7869 
7870 			mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
7871 			mr_conf.vlan.vlan_mask |= 1ULL << i;
7872 		}
7873 	}
7874 
7875 	if (!strcmp(res->on, "on"))
7876 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7877 						res->rule_id, 1);
7878 	else
7879 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7880 						res->rule_id, 0);
7881 	if (ret < 0)
7882 		printf("mirror rule add error: (%s)\n", strerror(-ret));
7883 }
7884 
7885 cmdline_parse_inst_t cmd_set_mirror_mask = {
7886 		.f = cmd_set_mirror_mask_parsed,
7887 		.data = NULL,
7888 		.help_str = "set port <port_id> mirror-rule <rule_id> "
7889 			"pool-mirror-up|pool-mirror-down|vlan-mirror "
7890 			"<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
7891 		.tokens = {
7892 			(void *)&cmd_mirror_mask_set,
7893 			(void *)&cmd_mirror_mask_port,
7894 			(void *)&cmd_mirror_mask_portid,
7895 			(void *)&cmd_mirror_mask_mirror,
7896 			(void *)&cmd_mirror_mask_ruleid,
7897 			(void *)&cmd_mirror_mask_what,
7898 			(void *)&cmd_mirror_mask_value,
7899 			(void *)&cmd_mirror_mask_dstpool,
7900 			(void *)&cmd_mirror_mask_poolid,
7901 			(void *)&cmd_mirror_mask_on,
7902 			NULL,
7903 		},
7904 };
7905 
7906 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
7907 struct cmd_set_mirror_link_result {
7908 	cmdline_fixed_string_t set;
7909 	cmdline_fixed_string_t port;
7910 	uint8_t port_id;
7911 	cmdline_fixed_string_t mirror;
7912 	uint8_t rule_id;
7913 	cmdline_fixed_string_t what;
7914 	cmdline_fixed_string_t dstpool;
7915 	uint8_t dstpool_id;
7916 	cmdline_fixed_string_t on;
7917 };
7918 
7919 cmdline_parse_token_string_t cmd_mirror_link_set =
7920 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7921 				 set, "set");
7922 cmdline_parse_token_string_t cmd_mirror_link_port =
7923 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7924 				port, "port");
7925 cmdline_parse_token_num_t cmd_mirror_link_portid =
7926 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7927 				port_id, UINT8);
7928 cmdline_parse_token_string_t cmd_mirror_link_mirror =
7929 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7930 				mirror, "mirror-rule");
7931 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7932 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7933 			    rule_id, UINT8);
7934 cmdline_parse_token_string_t cmd_mirror_link_what =
7935 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7936 				what, "uplink-mirror#downlink-mirror");
7937 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7938 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7939 				dstpool, "dst-pool");
7940 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7941 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7942 				dstpool_id, UINT8);
7943 cmdline_parse_token_string_t cmd_mirror_link_on =
7944 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7945 				on, "on#off");
7946 
7947 static void
7948 cmd_set_mirror_link_parsed(void *parsed_result,
7949 		       __attribute__((unused)) struct cmdline *cl,
7950 		       __attribute__((unused)) void *data)
7951 {
7952 	int ret;
7953 	struct cmd_set_mirror_link_result *res = parsed_result;
7954 	struct rte_eth_mirror_conf mr_conf;
7955 
7956 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7957 	if (!strcmp(res->what, "uplink-mirror"))
7958 		mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
7959 	else
7960 		mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
7961 
7962 	mr_conf.dst_pool = res->dstpool_id;
7963 
7964 	if (!strcmp(res->on, "on"))
7965 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7966 						res->rule_id, 1);
7967 	else
7968 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7969 						res->rule_id, 0);
7970 
7971 	/* check the return value and print it if is < 0 */
7972 	if (ret < 0)
7973 		printf("mirror rule add error: (%s)\n", strerror(-ret));
7974 
7975 }
7976 
7977 cmdline_parse_inst_t cmd_set_mirror_link = {
7978 		.f = cmd_set_mirror_link_parsed,
7979 		.data = NULL,
7980 		.help_str = "set port <port_id> mirror-rule <rule_id> "
7981 			"uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
7982 		.tokens = {
7983 			(void *)&cmd_mirror_link_set,
7984 			(void *)&cmd_mirror_link_port,
7985 			(void *)&cmd_mirror_link_portid,
7986 			(void *)&cmd_mirror_link_mirror,
7987 			(void *)&cmd_mirror_link_ruleid,
7988 			(void *)&cmd_mirror_link_what,
7989 			(void *)&cmd_mirror_link_dstpool,
7990 			(void *)&cmd_mirror_link_poolid,
7991 			(void *)&cmd_mirror_link_on,
7992 			NULL,
7993 		},
7994 };
7995 
7996 /* *** RESET VM MIRROR RULE *** */
7997 struct cmd_rm_mirror_rule_result {
7998 	cmdline_fixed_string_t reset;
7999 	cmdline_fixed_string_t port;
8000 	uint8_t port_id;
8001 	cmdline_fixed_string_t mirror;
8002 	uint8_t rule_id;
8003 };
8004 
8005 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8006 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8007 				 reset, "reset");
8008 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8009 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8010 				port, "port");
8011 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8012 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8013 				port_id, UINT8);
8014 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8015 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8016 				mirror, "mirror-rule");
8017 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8018 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8019 				rule_id, UINT8);
8020 
8021 static void
8022 cmd_reset_mirror_rule_parsed(void *parsed_result,
8023 		       __attribute__((unused)) struct cmdline *cl,
8024 		       __attribute__((unused)) void *data)
8025 {
8026 	int ret;
8027 	struct cmd_set_mirror_link_result *res = parsed_result;
8028         /* check rule_id */
8029 	ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8030 	if(ret < 0)
8031 		printf("mirror rule remove error: (%s)\n", strerror(-ret));
8032 }
8033 
8034 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8035 		.f = cmd_reset_mirror_rule_parsed,
8036 		.data = NULL,
8037 		.help_str = "reset port <port_id> mirror-rule <rule_id>",
8038 		.tokens = {
8039 			(void *)&cmd_rm_mirror_rule_reset,
8040 			(void *)&cmd_rm_mirror_rule_port,
8041 			(void *)&cmd_rm_mirror_rule_portid,
8042 			(void *)&cmd_rm_mirror_rule_mirror,
8043 			(void *)&cmd_rm_mirror_rule_ruleid,
8044 			NULL,
8045 		},
8046 };
8047 
8048 /* ******************************************************************************** */
8049 
8050 struct cmd_dump_result {
8051 	cmdline_fixed_string_t dump;
8052 };
8053 
8054 static void
8055 dump_struct_sizes(void)
8056 {
8057 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8058 	DUMP_SIZE(struct rte_mbuf);
8059 	DUMP_SIZE(struct rte_mempool);
8060 	DUMP_SIZE(struct rte_ring);
8061 #undef DUMP_SIZE
8062 }
8063 
8064 static void cmd_dump_parsed(void *parsed_result,
8065 			    __attribute__((unused)) struct cmdline *cl,
8066 			    __attribute__((unused)) void *data)
8067 {
8068 	struct cmd_dump_result *res = parsed_result;
8069 
8070 	if (!strcmp(res->dump, "dump_physmem"))
8071 		rte_dump_physmem_layout(stdout);
8072 	else if (!strcmp(res->dump, "dump_memzone"))
8073 		rte_memzone_dump(stdout);
8074 	else if (!strcmp(res->dump, "dump_struct_sizes"))
8075 		dump_struct_sizes();
8076 	else if (!strcmp(res->dump, "dump_ring"))
8077 		rte_ring_list_dump(stdout);
8078 	else if (!strcmp(res->dump, "dump_mempool"))
8079 		rte_mempool_list_dump(stdout);
8080 	else if (!strcmp(res->dump, "dump_devargs"))
8081 		rte_eal_devargs_dump(stdout);
8082 	else if (!strcmp(res->dump, "dump_log_types"))
8083 		rte_log_dump(stdout);
8084 }
8085 
8086 cmdline_parse_token_string_t cmd_dump_dump =
8087 	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8088 		"dump_physmem#"
8089 		"dump_memzone#"
8090 		"dump_struct_sizes#"
8091 		"dump_ring#"
8092 		"dump_mempool#"
8093 		"dump_devargs#"
8094 		"dump_log_types");
8095 
8096 cmdline_parse_inst_t cmd_dump = {
8097 	.f = cmd_dump_parsed,  /* function to call */
8098 	.data = NULL,      /* 2nd arg of func */
8099 	.help_str = "Dump status",
8100 	.tokens = {        /* token list, NULL terminated */
8101 		(void *)&cmd_dump_dump,
8102 		NULL,
8103 	},
8104 };
8105 
8106 /* ******************************************************************************** */
8107 
8108 struct cmd_dump_one_result {
8109 	cmdline_fixed_string_t dump;
8110 	cmdline_fixed_string_t name;
8111 };
8112 
8113 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8114 				__attribute__((unused)) void *data)
8115 {
8116 	struct cmd_dump_one_result *res = parsed_result;
8117 
8118 	if (!strcmp(res->dump, "dump_ring")) {
8119 		struct rte_ring *r;
8120 		r = rte_ring_lookup(res->name);
8121 		if (r == NULL) {
8122 			cmdline_printf(cl, "Cannot find ring\n");
8123 			return;
8124 		}
8125 		rte_ring_dump(stdout, r);
8126 	} else if (!strcmp(res->dump, "dump_mempool")) {
8127 		struct rte_mempool *mp;
8128 		mp = rte_mempool_lookup(res->name);
8129 		if (mp == NULL) {
8130 			cmdline_printf(cl, "Cannot find mempool\n");
8131 			return;
8132 		}
8133 		rte_mempool_dump(stdout, mp);
8134 	}
8135 }
8136 
8137 cmdline_parse_token_string_t cmd_dump_one_dump =
8138 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8139 				 "dump_ring#dump_mempool");
8140 
8141 cmdline_parse_token_string_t cmd_dump_one_name =
8142 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8143 
8144 cmdline_parse_inst_t cmd_dump_one = {
8145 	.f = cmd_dump_one_parsed,  /* function to call */
8146 	.data = NULL,      /* 2nd arg of func */
8147 	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8148 	.tokens = {        /* token list, NULL terminated */
8149 		(void *)&cmd_dump_one_dump,
8150 		(void *)&cmd_dump_one_name,
8151 		NULL,
8152 	},
8153 };
8154 
8155 /* *** Add/Del syn filter *** */
8156 struct cmd_syn_filter_result {
8157 	cmdline_fixed_string_t filter;
8158 	uint8_t port_id;
8159 	cmdline_fixed_string_t ops;
8160 	cmdline_fixed_string_t priority;
8161 	cmdline_fixed_string_t high;
8162 	cmdline_fixed_string_t queue;
8163 	uint16_t queue_id;
8164 };
8165 
8166 static void
8167 cmd_syn_filter_parsed(void *parsed_result,
8168 			__attribute__((unused)) struct cmdline *cl,
8169 			__attribute__((unused)) void *data)
8170 {
8171 	struct cmd_syn_filter_result *res = parsed_result;
8172 	struct rte_eth_syn_filter syn_filter;
8173 	int ret = 0;
8174 
8175 	ret = rte_eth_dev_filter_supported(res->port_id,
8176 					RTE_ETH_FILTER_SYN);
8177 	if (ret < 0) {
8178 		printf("syn filter is not supported on port %u.\n",
8179 				res->port_id);
8180 		return;
8181 	}
8182 
8183 	memset(&syn_filter, 0, sizeof(syn_filter));
8184 
8185 	if (!strcmp(res->ops, "add")) {
8186 		if (!strcmp(res->high, "high"))
8187 			syn_filter.hig_pri = 1;
8188 		else
8189 			syn_filter.hig_pri = 0;
8190 
8191 		syn_filter.queue = res->queue_id;
8192 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8193 						RTE_ETH_FILTER_SYN,
8194 						RTE_ETH_FILTER_ADD,
8195 						&syn_filter);
8196 	} else
8197 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8198 						RTE_ETH_FILTER_SYN,
8199 						RTE_ETH_FILTER_DELETE,
8200 						&syn_filter);
8201 
8202 	if (ret < 0)
8203 		printf("syn filter programming error: (%s)\n",
8204 				strerror(-ret));
8205 }
8206 
8207 cmdline_parse_token_string_t cmd_syn_filter_filter =
8208 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8209 	filter, "syn_filter");
8210 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8211 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8212 	port_id, UINT8);
8213 cmdline_parse_token_string_t cmd_syn_filter_ops =
8214 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8215 	ops, "add#del");
8216 cmdline_parse_token_string_t cmd_syn_filter_priority =
8217 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8218 				priority, "priority");
8219 cmdline_parse_token_string_t cmd_syn_filter_high =
8220 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8221 				high, "high#low");
8222 cmdline_parse_token_string_t cmd_syn_filter_queue =
8223 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8224 				queue, "queue");
8225 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8226 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8227 				queue_id, UINT16);
8228 
8229 cmdline_parse_inst_t cmd_syn_filter = {
8230 	.f = cmd_syn_filter_parsed,
8231 	.data = NULL,
8232 	.help_str = "syn_filter <port_id> add|del priority high|low queue "
8233 		"<queue_id>: Add/Delete syn filter",
8234 	.tokens = {
8235 		(void *)&cmd_syn_filter_filter,
8236 		(void *)&cmd_syn_filter_port_id,
8237 		(void *)&cmd_syn_filter_ops,
8238 		(void *)&cmd_syn_filter_priority,
8239 		(void *)&cmd_syn_filter_high,
8240 		(void *)&cmd_syn_filter_queue,
8241 		(void *)&cmd_syn_filter_queue_id,
8242 		NULL,
8243 	},
8244 };
8245 
8246 /* *** ADD/REMOVE A 2tuple FILTER *** */
8247 struct cmd_2tuple_filter_result {
8248 	cmdline_fixed_string_t filter;
8249 	uint8_t  port_id;
8250 	cmdline_fixed_string_t ops;
8251 	cmdline_fixed_string_t dst_port;
8252 	uint16_t dst_port_value;
8253 	cmdline_fixed_string_t protocol;
8254 	uint8_t protocol_value;
8255 	cmdline_fixed_string_t mask;
8256 	uint8_t  mask_value;
8257 	cmdline_fixed_string_t tcp_flags;
8258 	uint8_t tcp_flags_value;
8259 	cmdline_fixed_string_t priority;
8260 	uint8_t  priority_value;
8261 	cmdline_fixed_string_t queue;
8262 	uint16_t  queue_id;
8263 };
8264 
8265 static void
8266 cmd_2tuple_filter_parsed(void *parsed_result,
8267 			__attribute__((unused)) struct cmdline *cl,
8268 			__attribute__((unused)) void *data)
8269 {
8270 	struct rte_eth_ntuple_filter filter;
8271 	struct cmd_2tuple_filter_result *res = parsed_result;
8272 	int ret = 0;
8273 
8274 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8275 	if (ret < 0) {
8276 		printf("ntuple filter is not supported on port %u.\n",
8277 			res->port_id);
8278 		return;
8279 	}
8280 
8281 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8282 
8283 	filter.flags = RTE_2TUPLE_FLAGS;
8284 	filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8285 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8286 	filter.proto = res->protocol_value;
8287 	filter.priority = res->priority_value;
8288 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8289 		printf("nonzero tcp_flags is only meaningful"
8290 			" when protocol is TCP.\n");
8291 		return;
8292 	}
8293 	if (res->tcp_flags_value > TCP_FLAG_ALL) {
8294 		printf("invalid TCP flags.\n");
8295 		return;
8296 	}
8297 
8298 	if (res->tcp_flags_value != 0) {
8299 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8300 		filter.tcp_flags = res->tcp_flags_value;
8301 	}
8302 
8303 	/* need convert to big endian. */
8304 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8305 	filter.queue = res->queue_id;
8306 
8307 	if (!strcmp(res->ops, "add"))
8308 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8309 				RTE_ETH_FILTER_NTUPLE,
8310 				RTE_ETH_FILTER_ADD,
8311 				&filter);
8312 	else
8313 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8314 				RTE_ETH_FILTER_NTUPLE,
8315 				RTE_ETH_FILTER_DELETE,
8316 				&filter);
8317 	if (ret < 0)
8318 		printf("2tuple filter programming error: (%s)\n",
8319 			strerror(-ret));
8320 
8321 }
8322 
8323 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
8324 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8325 				 filter, "2tuple_filter");
8326 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
8327 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8328 				port_id, UINT8);
8329 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
8330 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8331 				 ops, "add#del");
8332 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
8333 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8334 				dst_port, "dst_port");
8335 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
8336 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8337 				dst_port_value, UINT16);
8338 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
8339 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8340 				protocol, "protocol");
8341 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
8342 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8343 				protocol_value, UINT8);
8344 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
8345 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8346 				mask, "mask");
8347 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
8348 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8349 				mask_value, INT8);
8350 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
8351 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8352 				tcp_flags, "tcp_flags");
8353 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
8354 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8355 				tcp_flags_value, UINT8);
8356 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
8357 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8358 				priority, "priority");
8359 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
8360 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8361 				priority_value, UINT8);
8362 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
8363 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8364 				queue, "queue");
8365 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
8366 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8367 				queue_id, UINT16);
8368 
8369 cmdline_parse_inst_t cmd_2tuple_filter = {
8370 	.f = cmd_2tuple_filter_parsed,
8371 	.data = NULL,
8372 	.help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
8373 		"<value> mask <value> tcp_flags <value> priority <value> queue "
8374 		"<queue_id>: Add a 2tuple filter",
8375 	.tokens = {
8376 		(void *)&cmd_2tuple_filter_filter,
8377 		(void *)&cmd_2tuple_filter_port_id,
8378 		(void *)&cmd_2tuple_filter_ops,
8379 		(void *)&cmd_2tuple_filter_dst_port,
8380 		(void *)&cmd_2tuple_filter_dst_port_value,
8381 		(void *)&cmd_2tuple_filter_protocol,
8382 		(void *)&cmd_2tuple_filter_protocol_value,
8383 		(void *)&cmd_2tuple_filter_mask,
8384 		(void *)&cmd_2tuple_filter_mask_value,
8385 		(void *)&cmd_2tuple_filter_tcp_flags,
8386 		(void *)&cmd_2tuple_filter_tcp_flags_value,
8387 		(void *)&cmd_2tuple_filter_priority,
8388 		(void *)&cmd_2tuple_filter_priority_value,
8389 		(void *)&cmd_2tuple_filter_queue,
8390 		(void *)&cmd_2tuple_filter_queue_id,
8391 		NULL,
8392 	},
8393 };
8394 
8395 /* *** ADD/REMOVE A 5tuple FILTER *** */
8396 struct cmd_5tuple_filter_result {
8397 	cmdline_fixed_string_t filter;
8398 	uint8_t  port_id;
8399 	cmdline_fixed_string_t ops;
8400 	cmdline_fixed_string_t dst_ip;
8401 	cmdline_ipaddr_t dst_ip_value;
8402 	cmdline_fixed_string_t src_ip;
8403 	cmdline_ipaddr_t src_ip_value;
8404 	cmdline_fixed_string_t dst_port;
8405 	uint16_t dst_port_value;
8406 	cmdline_fixed_string_t src_port;
8407 	uint16_t src_port_value;
8408 	cmdline_fixed_string_t protocol;
8409 	uint8_t protocol_value;
8410 	cmdline_fixed_string_t mask;
8411 	uint8_t  mask_value;
8412 	cmdline_fixed_string_t tcp_flags;
8413 	uint8_t tcp_flags_value;
8414 	cmdline_fixed_string_t priority;
8415 	uint8_t  priority_value;
8416 	cmdline_fixed_string_t queue;
8417 	uint16_t  queue_id;
8418 };
8419 
8420 static void
8421 cmd_5tuple_filter_parsed(void *parsed_result,
8422 			__attribute__((unused)) struct cmdline *cl,
8423 			__attribute__((unused)) void *data)
8424 {
8425 	struct rte_eth_ntuple_filter filter;
8426 	struct cmd_5tuple_filter_result *res = parsed_result;
8427 	int ret = 0;
8428 
8429 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8430 	if (ret < 0) {
8431 		printf("ntuple filter is not supported on port %u.\n",
8432 			res->port_id);
8433 		return;
8434 	}
8435 
8436 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8437 
8438 	filter.flags = RTE_5TUPLE_FLAGS;
8439 	filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
8440 	filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
8441 	filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
8442 	filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8443 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8444 	filter.proto = res->protocol_value;
8445 	filter.priority = res->priority_value;
8446 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8447 		printf("nonzero tcp_flags is only meaningful"
8448 			" when protocol is TCP.\n");
8449 		return;
8450 	}
8451 	if (res->tcp_flags_value > TCP_FLAG_ALL) {
8452 		printf("invalid TCP flags.\n");
8453 		return;
8454 	}
8455 
8456 	if (res->tcp_flags_value != 0) {
8457 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8458 		filter.tcp_flags = res->tcp_flags_value;
8459 	}
8460 
8461 	if (res->dst_ip_value.family == AF_INET)
8462 		/* no need to convert, already big endian. */
8463 		filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
8464 	else {
8465 		if (filter.dst_ip_mask == 0) {
8466 			printf("can not support ipv6 involved compare.\n");
8467 			return;
8468 		}
8469 		filter.dst_ip = 0;
8470 	}
8471 
8472 	if (res->src_ip_value.family == AF_INET)
8473 		/* no need to convert, already big endian. */
8474 		filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
8475 	else {
8476 		if (filter.src_ip_mask == 0) {
8477 			printf("can not support ipv6 involved compare.\n");
8478 			return;
8479 		}
8480 		filter.src_ip = 0;
8481 	}
8482 	/* need convert to big endian. */
8483 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8484 	filter.src_port = rte_cpu_to_be_16(res->src_port_value);
8485 	filter.queue = res->queue_id;
8486 
8487 	if (!strcmp(res->ops, "add"))
8488 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8489 				RTE_ETH_FILTER_NTUPLE,
8490 				RTE_ETH_FILTER_ADD,
8491 				&filter);
8492 	else
8493 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8494 				RTE_ETH_FILTER_NTUPLE,
8495 				RTE_ETH_FILTER_DELETE,
8496 				&filter);
8497 	if (ret < 0)
8498 		printf("5tuple filter programming error: (%s)\n",
8499 			strerror(-ret));
8500 }
8501 
8502 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
8503 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8504 				 filter, "5tuple_filter");
8505 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
8506 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8507 				port_id, UINT8);
8508 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
8509 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8510 				 ops, "add#del");
8511 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
8512 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8513 				dst_ip, "dst_ip");
8514 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
8515 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8516 				dst_ip_value);
8517 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
8518 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8519 				src_ip, "src_ip");
8520 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
8521 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8522 				src_ip_value);
8523 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
8524 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8525 				dst_port, "dst_port");
8526 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
8527 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8528 				dst_port_value, UINT16);
8529 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
8530 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8531 				src_port, "src_port");
8532 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
8533 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8534 				src_port_value, UINT16);
8535 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
8536 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8537 				protocol, "protocol");
8538 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
8539 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8540 				protocol_value, UINT8);
8541 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
8542 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8543 				mask, "mask");
8544 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
8545 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8546 				mask_value, INT8);
8547 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
8548 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8549 				tcp_flags, "tcp_flags");
8550 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
8551 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8552 				tcp_flags_value, UINT8);
8553 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
8554 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8555 				priority, "priority");
8556 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
8557 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8558 				priority_value, UINT8);
8559 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
8560 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8561 				queue, "queue");
8562 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
8563 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8564 				queue_id, UINT16);
8565 
8566 cmdline_parse_inst_t cmd_5tuple_filter = {
8567 	.f = cmd_5tuple_filter_parsed,
8568 	.data = NULL,
8569 	.help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
8570 		"src_ip <value> dst_port <value> src_port <value> "
8571 		"protocol <value>  mask <value> tcp_flags <value> "
8572 		"priority <value> queue <queue_id>: Add/Del a 5tuple filter",
8573 	.tokens = {
8574 		(void *)&cmd_5tuple_filter_filter,
8575 		(void *)&cmd_5tuple_filter_port_id,
8576 		(void *)&cmd_5tuple_filter_ops,
8577 		(void *)&cmd_5tuple_filter_dst_ip,
8578 		(void *)&cmd_5tuple_filter_dst_ip_value,
8579 		(void *)&cmd_5tuple_filter_src_ip,
8580 		(void *)&cmd_5tuple_filter_src_ip_value,
8581 		(void *)&cmd_5tuple_filter_dst_port,
8582 		(void *)&cmd_5tuple_filter_dst_port_value,
8583 		(void *)&cmd_5tuple_filter_src_port,
8584 		(void *)&cmd_5tuple_filter_src_port_value,
8585 		(void *)&cmd_5tuple_filter_protocol,
8586 		(void *)&cmd_5tuple_filter_protocol_value,
8587 		(void *)&cmd_5tuple_filter_mask,
8588 		(void *)&cmd_5tuple_filter_mask_value,
8589 		(void *)&cmd_5tuple_filter_tcp_flags,
8590 		(void *)&cmd_5tuple_filter_tcp_flags_value,
8591 		(void *)&cmd_5tuple_filter_priority,
8592 		(void *)&cmd_5tuple_filter_priority_value,
8593 		(void *)&cmd_5tuple_filter_queue,
8594 		(void *)&cmd_5tuple_filter_queue_id,
8595 		NULL,
8596 	},
8597 };
8598 
8599 /* *** ADD/REMOVE A flex FILTER *** */
8600 struct cmd_flex_filter_result {
8601 	cmdline_fixed_string_t filter;
8602 	cmdline_fixed_string_t ops;
8603 	uint8_t port_id;
8604 	cmdline_fixed_string_t len;
8605 	uint8_t len_value;
8606 	cmdline_fixed_string_t bytes;
8607 	cmdline_fixed_string_t bytes_value;
8608 	cmdline_fixed_string_t mask;
8609 	cmdline_fixed_string_t mask_value;
8610 	cmdline_fixed_string_t priority;
8611 	uint8_t priority_value;
8612 	cmdline_fixed_string_t queue;
8613 	uint16_t queue_id;
8614 };
8615 
8616 static int xdigit2val(unsigned char c)
8617 {
8618 	int val;
8619 	if (isdigit(c))
8620 		val = c - '0';
8621 	else if (isupper(c))
8622 		val = c - 'A' + 10;
8623 	else
8624 		val = c - 'a' + 10;
8625 	return val;
8626 }
8627 
8628 static void
8629 cmd_flex_filter_parsed(void *parsed_result,
8630 			  __attribute__((unused)) struct cmdline *cl,
8631 			  __attribute__((unused)) void *data)
8632 {
8633 	int ret = 0;
8634 	struct rte_eth_flex_filter filter;
8635 	struct cmd_flex_filter_result *res = parsed_result;
8636 	char *bytes_ptr, *mask_ptr;
8637 	uint16_t len, i, j = 0;
8638 	char c;
8639 	int val;
8640 	uint8_t byte = 0;
8641 
8642 	if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
8643 		printf("the len exceed the max length 128\n");
8644 		return;
8645 	}
8646 	memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
8647 	filter.len = res->len_value;
8648 	filter.priority = res->priority_value;
8649 	filter.queue = res->queue_id;
8650 	bytes_ptr = res->bytes_value;
8651 	mask_ptr = res->mask_value;
8652 
8653 	 /* translate bytes string to array. */
8654 	if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
8655 		(bytes_ptr[1] == 'X')))
8656 		bytes_ptr += 2;
8657 	len = strnlen(bytes_ptr, res->len_value * 2);
8658 	if (len == 0 || (len % 8 != 0)) {
8659 		printf("please check len and bytes input\n");
8660 		return;
8661 	}
8662 	for (i = 0; i < len; i++) {
8663 		c = bytes_ptr[i];
8664 		if (isxdigit(c) == 0) {
8665 			/* invalid characters. */
8666 			printf("invalid input\n");
8667 			return;
8668 		}
8669 		val = xdigit2val(c);
8670 		if (i % 2) {
8671 			byte |= val;
8672 			filter.bytes[j] = byte;
8673 			printf("bytes[%d]:%02x ", j, filter.bytes[j]);
8674 			j++;
8675 			byte = 0;
8676 		} else
8677 			byte |= val << 4;
8678 	}
8679 	printf("\n");
8680 	 /* translate mask string to uint8_t array. */
8681 	if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
8682 		(mask_ptr[1] == 'X')))
8683 		mask_ptr += 2;
8684 	len = strnlen(mask_ptr, (res->len_value + 3) / 4);
8685 	if (len == 0) {
8686 		printf("invalid input\n");
8687 		return;
8688 	}
8689 	j = 0;
8690 	byte = 0;
8691 	for (i = 0; i < len; i++) {
8692 		c = mask_ptr[i];
8693 		if (isxdigit(c) == 0) {
8694 			/* invalid characters. */
8695 			printf("invalid input\n");
8696 			return;
8697 		}
8698 		val = xdigit2val(c);
8699 		if (i % 2) {
8700 			byte |= val;
8701 			filter.mask[j] = byte;
8702 			printf("mask[%d]:%02x ", j, filter.mask[j]);
8703 			j++;
8704 			byte = 0;
8705 		} else
8706 			byte |= val << 4;
8707 	}
8708 	printf("\n");
8709 
8710 	if (!strcmp(res->ops, "add"))
8711 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8712 				RTE_ETH_FILTER_FLEXIBLE,
8713 				RTE_ETH_FILTER_ADD,
8714 				&filter);
8715 	else
8716 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8717 				RTE_ETH_FILTER_FLEXIBLE,
8718 				RTE_ETH_FILTER_DELETE,
8719 				&filter);
8720 
8721 	if (ret < 0)
8722 		printf("flex filter setting error: (%s)\n", strerror(-ret));
8723 }
8724 
8725 cmdline_parse_token_string_t cmd_flex_filter_filter =
8726 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8727 				filter, "flex_filter");
8728 cmdline_parse_token_num_t cmd_flex_filter_port_id =
8729 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8730 				port_id, UINT8);
8731 cmdline_parse_token_string_t cmd_flex_filter_ops =
8732 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8733 				ops, "add#del");
8734 cmdline_parse_token_string_t cmd_flex_filter_len =
8735 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8736 				len, "len");
8737 cmdline_parse_token_num_t cmd_flex_filter_len_value =
8738 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8739 				len_value, UINT8);
8740 cmdline_parse_token_string_t cmd_flex_filter_bytes =
8741 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8742 				bytes, "bytes");
8743 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
8744 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8745 				bytes_value, NULL);
8746 cmdline_parse_token_string_t cmd_flex_filter_mask =
8747 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8748 				mask, "mask");
8749 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
8750 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8751 				mask_value, NULL);
8752 cmdline_parse_token_string_t cmd_flex_filter_priority =
8753 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8754 				priority, "priority");
8755 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
8756 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8757 				priority_value, UINT8);
8758 cmdline_parse_token_string_t cmd_flex_filter_queue =
8759 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8760 				queue, "queue");
8761 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
8762 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8763 				queue_id, UINT16);
8764 cmdline_parse_inst_t cmd_flex_filter = {
8765 	.f = cmd_flex_filter_parsed,
8766 	.data = NULL,
8767 	.help_str = "flex_filter <port_id> add|del len <value> bytes "
8768 		"<value> mask <value> priority <value> queue <queue_id>: "
8769 		"Add/Del a flex filter",
8770 	.tokens = {
8771 		(void *)&cmd_flex_filter_filter,
8772 		(void *)&cmd_flex_filter_port_id,
8773 		(void *)&cmd_flex_filter_ops,
8774 		(void *)&cmd_flex_filter_len,
8775 		(void *)&cmd_flex_filter_len_value,
8776 		(void *)&cmd_flex_filter_bytes,
8777 		(void *)&cmd_flex_filter_bytes_value,
8778 		(void *)&cmd_flex_filter_mask,
8779 		(void *)&cmd_flex_filter_mask_value,
8780 		(void *)&cmd_flex_filter_priority,
8781 		(void *)&cmd_flex_filter_priority_value,
8782 		(void *)&cmd_flex_filter_queue,
8783 		(void *)&cmd_flex_filter_queue_id,
8784 		NULL,
8785 	},
8786 };
8787 
8788 /* *** Filters Control *** */
8789 
8790 /* *** deal with ethertype filter *** */
8791 struct cmd_ethertype_filter_result {
8792 	cmdline_fixed_string_t filter;
8793 	uint8_t port_id;
8794 	cmdline_fixed_string_t ops;
8795 	cmdline_fixed_string_t mac;
8796 	struct ether_addr mac_addr;
8797 	cmdline_fixed_string_t ethertype;
8798 	uint16_t ethertype_value;
8799 	cmdline_fixed_string_t drop;
8800 	cmdline_fixed_string_t queue;
8801 	uint16_t  queue_id;
8802 };
8803 
8804 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
8805 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8806 				 filter, "ethertype_filter");
8807 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
8808 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8809 			      port_id, UINT8);
8810 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
8811 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8812 				 ops, "add#del");
8813 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
8814 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8815 				 mac, "mac_addr#mac_ignr");
8816 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
8817 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
8818 				     mac_addr);
8819 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
8820 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8821 				 ethertype, "ethertype");
8822 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
8823 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8824 			      ethertype_value, UINT16);
8825 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
8826 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8827 				 drop, "drop#fwd");
8828 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
8829 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
8830 				 queue, "queue");
8831 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
8832 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
8833 			      queue_id, UINT16);
8834 
8835 static void
8836 cmd_ethertype_filter_parsed(void *parsed_result,
8837 			  __attribute__((unused)) struct cmdline *cl,
8838 			  __attribute__((unused)) void *data)
8839 {
8840 	struct cmd_ethertype_filter_result *res = parsed_result;
8841 	struct rte_eth_ethertype_filter filter;
8842 	int ret = 0;
8843 
8844 	ret = rte_eth_dev_filter_supported(res->port_id,
8845 			RTE_ETH_FILTER_ETHERTYPE);
8846 	if (ret < 0) {
8847 		printf("ethertype filter is not supported on port %u.\n",
8848 			res->port_id);
8849 		return;
8850 	}
8851 
8852 	memset(&filter, 0, sizeof(filter));
8853 	if (!strcmp(res->mac, "mac_addr")) {
8854 		filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
8855 		rte_memcpy(&filter.mac_addr, &res->mac_addr,
8856 			sizeof(struct ether_addr));
8857 	}
8858 	if (!strcmp(res->drop, "drop"))
8859 		filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
8860 	filter.ether_type = res->ethertype_value;
8861 	filter.queue = res->queue_id;
8862 
8863 	if (!strcmp(res->ops, "add"))
8864 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8865 				RTE_ETH_FILTER_ETHERTYPE,
8866 				RTE_ETH_FILTER_ADD,
8867 				&filter);
8868 	else
8869 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8870 				RTE_ETH_FILTER_ETHERTYPE,
8871 				RTE_ETH_FILTER_DELETE,
8872 				&filter);
8873 	if (ret < 0)
8874 		printf("ethertype filter programming error: (%s)\n",
8875 			strerror(-ret));
8876 }
8877 
8878 cmdline_parse_inst_t cmd_ethertype_filter = {
8879 	.f = cmd_ethertype_filter_parsed,
8880 	.data = NULL,
8881 	.help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
8882 		"<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
8883 		"Add or delete an ethertype filter entry",
8884 	.tokens = {
8885 		(void *)&cmd_ethertype_filter_filter,
8886 		(void *)&cmd_ethertype_filter_port_id,
8887 		(void *)&cmd_ethertype_filter_ops,
8888 		(void *)&cmd_ethertype_filter_mac,
8889 		(void *)&cmd_ethertype_filter_mac_addr,
8890 		(void *)&cmd_ethertype_filter_ethertype,
8891 		(void *)&cmd_ethertype_filter_ethertype_value,
8892 		(void *)&cmd_ethertype_filter_drop,
8893 		(void *)&cmd_ethertype_filter_queue,
8894 		(void *)&cmd_ethertype_filter_queue_id,
8895 		NULL,
8896 	},
8897 };
8898 
8899 /* *** deal with flow director filter *** */
8900 struct cmd_flow_director_result {
8901 	cmdline_fixed_string_t flow_director_filter;
8902 	uint8_t port_id;
8903 	cmdline_fixed_string_t mode;
8904 	cmdline_fixed_string_t mode_value;
8905 	cmdline_fixed_string_t ops;
8906 	cmdline_fixed_string_t flow;
8907 	cmdline_fixed_string_t flow_type;
8908 	cmdline_fixed_string_t ether;
8909 	uint16_t ether_type;
8910 	cmdline_fixed_string_t src;
8911 	cmdline_ipaddr_t ip_src;
8912 	uint16_t port_src;
8913 	cmdline_fixed_string_t dst;
8914 	cmdline_ipaddr_t ip_dst;
8915 	uint16_t port_dst;
8916 	cmdline_fixed_string_t verify_tag;
8917 	uint32_t verify_tag_value;
8918 	cmdline_ipaddr_t tos;
8919 	uint8_t tos_value;
8920 	cmdline_ipaddr_t proto;
8921 	uint8_t proto_value;
8922 	cmdline_ipaddr_t ttl;
8923 	uint8_t ttl_value;
8924 	cmdline_fixed_string_t vlan;
8925 	uint16_t vlan_value;
8926 	cmdline_fixed_string_t flexbytes;
8927 	cmdline_fixed_string_t flexbytes_value;
8928 	cmdline_fixed_string_t pf_vf;
8929 	cmdline_fixed_string_t drop;
8930 	cmdline_fixed_string_t queue;
8931 	uint16_t  queue_id;
8932 	cmdline_fixed_string_t fd_id;
8933 	uint32_t  fd_id_value;
8934 	cmdline_fixed_string_t mac;
8935 	struct ether_addr mac_addr;
8936 	cmdline_fixed_string_t tunnel;
8937 	cmdline_fixed_string_t tunnel_type;
8938 	cmdline_fixed_string_t tunnel_id;
8939 	uint32_t tunnel_id_value;
8940 };
8941 
8942 static inline int
8943 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
8944 {
8945 	char s[256];
8946 	const char *p, *p0 = q_arg;
8947 	char *end;
8948 	unsigned long int_fld;
8949 	char *str_fld[max_num];
8950 	int i;
8951 	unsigned size;
8952 	int ret = -1;
8953 
8954 	p = strchr(p0, '(');
8955 	if (p == NULL)
8956 		return -1;
8957 	++p;
8958 	p0 = strchr(p, ')');
8959 	if (p0 == NULL)
8960 		return -1;
8961 
8962 	size = p0 - p;
8963 	if (size >= sizeof(s))
8964 		return -1;
8965 
8966 	snprintf(s, sizeof(s), "%.*s", size, p);
8967 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8968 	if (ret < 0 || ret > max_num)
8969 		return -1;
8970 	for (i = 0; i < ret; i++) {
8971 		errno = 0;
8972 		int_fld = strtoul(str_fld[i], &end, 0);
8973 		if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
8974 			return -1;
8975 		flexbytes[i] = (uint8_t)int_fld;
8976 	}
8977 	return ret;
8978 }
8979 
8980 static uint16_t
8981 str2flowtype(char *string)
8982 {
8983 	uint8_t i = 0;
8984 	static const struct {
8985 		char str[32];
8986 		uint16_t type;
8987 	} flowtype_str[] = {
8988 		{"raw", RTE_ETH_FLOW_RAW},
8989 		{"ipv4", RTE_ETH_FLOW_IPV4},
8990 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
8991 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
8992 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
8993 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
8994 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
8995 		{"ipv6", RTE_ETH_FLOW_IPV6},
8996 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
8997 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
8998 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
8999 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9000 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9001 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9002 	};
9003 
9004 	for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9005 		if (!strcmp(flowtype_str[i].str, string))
9006 			return flowtype_str[i].type;
9007 	}
9008 
9009 	if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9010 		return (uint16_t)atoi(string);
9011 
9012 	return RTE_ETH_FLOW_UNKNOWN;
9013 }
9014 
9015 static enum rte_eth_fdir_tunnel_type
9016 str2fdir_tunneltype(char *string)
9017 {
9018 	uint8_t i = 0;
9019 
9020 	static const struct {
9021 		char str[32];
9022 		enum rte_eth_fdir_tunnel_type type;
9023 	} tunneltype_str[] = {
9024 		{"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9025 		{"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9026 	};
9027 
9028 	for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9029 		if (!strcmp(tunneltype_str[i].str, string))
9030 			return tunneltype_str[i].type;
9031 	}
9032 	return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9033 }
9034 
9035 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9036 do { \
9037 	if ((ip_addr).family == AF_INET) \
9038 		(ip) = (ip_addr).addr.ipv4.s_addr; \
9039 	else { \
9040 		printf("invalid parameter.\n"); \
9041 		return; \
9042 	} \
9043 } while (0)
9044 
9045 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9046 do { \
9047 	if ((ip_addr).family == AF_INET6) \
9048 		rte_memcpy(&(ip), \
9049 				 &((ip_addr).addr.ipv6), \
9050 				 sizeof(struct in6_addr)); \
9051 	else { \
9052 		printf("invalid parameter.\n"); \
9053 		return; \
9054 	} \
9055 } while (0)
9056 
9057 static void
9058 cmd_flow_director_filter_parsed(void *parsed_result,
9059 			  __attribute__((unused)) struct cmdline *cl,
9060 			  __attribute__((unused)) void *data)
9061 {
9062 	struct cmd_flow_director_result *res = parsed_result;
9063 	struct rte_eth_fdir_filter entry;
9064 	uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9065 	char *end;
9066 	unsigned long vf_id;
9067 	int ret = 0;
9068 
9069 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9070 	if (ret < 0) {
9071 		printf("flow director is not supported on port %u.\n",
9072 			res->port_id);
9073 		return;
9074 	}
9075 	memset(flexbytes, 0, sizeof(flexbytes));
9076 	memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9077 
9078 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9079 		if (strcmp(res->mode_value, "MAC-VLAN")) {
9080 			printf("Please set mode to MAC-VLAN.\n");
9081 			return;
9082 		}
9083 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9084 		if (strcmp(res->mode_value, "Tunnel")) {
9085 			printf("Please set mode to Tunnel.\n");
9086 			return;
9087 		}
9088 	} else {
9089 		if (strcmp(res->mode_value, "IP")) {
9090 			printf("Please set mode to IP.\n");
9091 			return;
9092 		}
9093 		entry.input.flow_type = str2flowtype(res->flow_type);
9094 	}
9095 
9096 	ret = parse_flexbytes(res->flexbytes_value,
9097 					flexbytes,
9098 					RTE_ETH_FDIR_MAX_FLEXLEN);
9099 	if (ret < 0) {
9100 		printf("error: Cannot parse flexbytes input.\n");
9101 		return;
9102 	}
9103 
9104 	switch (entry.input.flow_type) {
9105 	case RTE_ETH_FLOW_FRAG_IPV4:
9106 	case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9107 		entry.input.flow.ip4_flow.proto = res->proto_value;
9108 		/* fall-through */
9109 	case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9110 	case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9111 		IPV4_ADDR_TO_UINT(res->ip_dst,
9112 			entry.input.flow.ip4_flow.dst_ip);
9113 		IPV4_ADDR_TO_UINT(res->ip_src,
9114 			entry.input.flow.ip4_flow.src_ip);
9115 		entry.input.flow.ip4_flow.tos = res->tos_value;
9116 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
9117 		/* need convert to big endian. */
9118 		entry.input.flow.udp4_flow.dst_port =
9119 				rte_cpu_to_be_16(res->port_dst);
9120 		entry.input.flow.udp4_flow.src_port =
9121 				rte_cpu_to_be_16(res->port_src);
9122 		break;
9123 	case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9124 		IPV4_ADDR_TO_UINT(res->ip_dst,
9125 			entry.input.flow.sctp4_flow.ip.dst_ip);
9126 		IPV4_ADDR_TO_UINT(res->ip_src,
9127 			entry.input.flow.sctp4_flow.ip.src_ip);
9128 		entry.input.flow.ip4_flow.tos = res->tos_value;
9129 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
9130 		/* need convert to big endian. */
9131 		entry.input.flow.sctp4_flow.dst_port =
9132 				rte_cpu_to_be_16(res->port_dst);
9133 		entry.input.flow.sctp4_flow.src_port =
9134 				rte_cpu_to_be_16(res->port_src);
9135 		entry.input.flow.sctp4_flow.verify_tag =
9136 				rte_cpu_to_be_32(res->verify_tag_value);
9137 		break;
9138 	case RTE_ETH_FLOW_FRAG_IPV6:
9139 	case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9140 		entry.input.flow.ipv6_flow.proto = res->proto_value;
9141 		/* fall-through */
9142 	case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9143 	case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9144 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
9145 			entry.input.flow.ipv6_flow.dst_ip);
9146 		IPV6_ADDR_TO_ARRAY(res->ip_src,
9147 			entry.input.flow.ipv6_flow.src_ip);
9148 		entry.input.flow.ipv6_flow.tc = res->tos_value;
9149 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9150 		/* need convert to big endian. */
9151 		entry.input.flow.udp6_flow.dst_port =
9152 				rte_cpu_to_be_16(res->port_dst);
9153 		entry.input.flow.udp6_flow.src_port =
9154 				rte_cpu_to_be_16(res->port_src);
9155 		break;
9156 	case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9157 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
9158 			entry.input.flow.sctp6_flow.ip.dst_ip);
9159 		IPV6_ADDR_TO_ARRAY(res->ip_src,
9160 			entry.input.flow.sctp6_flow.ip.src_ip);
9161 		entry.input.flow.ipv6_flow.tc = res->tos_value;
9162 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9163 		/* need convert to big endian. */
9164 		entry.input.flow.sctp6_flow.dst_port =
9165 				rte_cpu_to_be_16(res->port_dst);
9166 		entry.input.flow.sctp6_flow.src_port =
9167 				rte_cpu_to_be_16(res->port_src);
9168 		entry.input.flow.sctp6_flow.verify_tag =
9169 				rte_cpu_to_be_32(res->verify_tag_value);
9170 		break;
9171 	case RTE_ETH_FLOW_L2_PAYLOAD:
9172 		entry.input.flow.l2_flow.ether_type =
9173 			rte_cpu_to_be_16(res->ether_type);
9174 		break;
9175 	default:
9176 		break;
9177 	}
9178 
9179 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9180 		rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9181 				 &res->mac_addr,
9182 				 sizeof(struct ether_addr));
9183 
9184 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9185 		rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9186 				 &res->mac_addr,
9187 				 sizeof(struct ether_addr));
9188 		entry.input.flow.tunnel_flow.tunnel_type =
9189 			str2fdir_tunneltype(res->tunnel_type);
9190 		entry.input.flow.tunnel_flow.tunnel_id =
9191 			rte_cpu_to_be_32(res->tunnel_id_value);
9192 	}
9193 
9194 	rte_memcpy(entry.input.flow_ext.flexbytes,
9195 		   flexbytes,
9196 		   RTE_ETH_FDIR_MAX_FLEXLEN);
9197 
9198 	entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9199 
9200 	entry.action.flex_off = 0;  /*use 0 by default */
9201 	if (!strcmp(res->drop, "drop"))
9202 		entry.action.behavior = RTE_ETH_FDIR_REJECT;
9203 	else
9204 		entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9205 
9206 	if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9207 	    fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9208 		if (!strcmp(res->pf_vf, "pf"))
9209 			entry.input.flow_ext.is_vf = 0;
9210 		else if (!strncmp(res->pf_vf, "vf", 2)) {
9211 			struct rte_eth_dev_info dev_info;
9212 
9213 			memset(&dev_info, 0, sizeof(dev_info));
9214 			rte_eth_dev_info_get(res->port_id, &dev_info);
9215 			errno = 0;
9216 			vf_id = strtoul(res->pf_vf + 2, &end, 10);
9217 			if (errno != 0 || *end != '\0' ||
9218 			    vf_id >= dev_info.max_vfs) {
9219 				printf("invalid parameter %s.\n", res->pf_vf);
9220 				return;
9221 			}
9222 			entry.input.flow_ext.is_vf = 1;
9223 			entry.input.flow_ext.dst_id = (uint16_t)vf_id;
9224 		} else {
9225 			printf("invalid parameter %s.\n", res->pf_vf);
9226 			return;
9227 		}
9228 	}
9229 
9230 	/* set to report FD ID by default */
9231 	entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
9232 	entry.action.rx_queue = res->queue_id;
9233 	entry.soft_id = res->fd_id_value;
9234 	if (!strcmp(res->ops, "add"))
9235 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9236 					     RTE_ETH_FILTER_ADD, &entry);
9237 	else if (!strcmp(res->ops, "del"))
9238 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9239 					     RTE_ETH_FILTER_DELETE, &entry);
9240 	else
9241 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9242 					     RTE_ETH_FILTER_UPDATE, &entry);
9243 	if (ret < 0)
9244 		printf("flow director programming error: (%s)\n",
9245 			strerror(-ret));
9246 }
9247 
9248 cmdline_parse_token_string_t cmd_flow_director_filter =
9249 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9250 				 flow_director_filter, "flow_director_filter");
9251 cmdline_parse_token_num_t cmd_flow_director_port_id =
9252 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9253 			      port_id, UINT8);
9254 cmdline_parse_token_string_t cmd_flow_director_ops =
9255 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9256 				 ops, "add#del#update");
9257 cmdline_parse_token_string_t cmd_flow_director_flow =
9258 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9259 				 flow, "flow");
9260 cmdline_parse_token_string_t cmd_flow_director_flow_type =
9261 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9262 		flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9263 		"ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
9264 cmdline_parse_token_string_t cmd_flow_director_ether =
9265 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9266 				 ether, "ether");
9267 cmdline_parse_token_num_t cmd_flow_director_ether_type =
9268 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9269 			      ether_type, UINT16);
9270 cmdline_parse_token_string_t cmd_flow_director_src =
9271 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9272 				 src, "src");
9273 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
9274 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9275 				 ip_src);
9276 cmdline_parse_token_num_t cmd_flow_director_port_src =
9277 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9278 			      port_src, UINT16);
9279 cmdline_parse_token_string_t cmd_flow_director_dst =
9280 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9281 				 dst, "dst");
9282 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
9283 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9284 				 ip_dst);
9285 cmdline_parse_token_num_t cmd_flow_director_port_dst =
9286 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9287 			      port_dst, UINT16);
9288 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
9289 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9290 				  verify_tag, "verify_tag");
9291 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
9292 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9293 			      verify_tag_value, UINT32);
9294 cmdline_parse_token_string_t cmd_flow_director_tos =
9295 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9296 				 tos, "tos");
9297 cmdline_parse_token_num_t cmd_flow_director_tos_value =
9298 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9299 			      tos_value, UINT8);
9300 cmdline_parse_token_string_t cmd_flow_director_proto =
9301 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9302 				 proto, "proto");
9303 cmdline_parse_token_num_t cmd_flow_director_proto_value =
9304 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9305 			      proto_value, UINT8);
9306 cmdline_parse_token_string_t cmd_flow_director_ttl =
9307 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9308 				 ttl, "ttl");
9309 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
9310 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9311 			      ttl_value, UINT8);
9312 cmdline_parse_token_string_t cmd_flow_director_vlan =
9313 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9314 				 vlan, "vlan");
9315 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
9316 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9317 			      vlan_value, UINT16);
9318 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
9319 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9320 				 flexbytes, "flexbytes");
9321 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
9322 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9323 			      flexbytes_value, NULL);
9324 cmdline_parse_token_string_t cmd_flow_director_drop =
9325 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9326 				 drop, "drop#fwd");
9327 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
9328 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9329 			      pf_vf, NULL);
9330 cmdline_parse_token_string_t cmd_flow_director_queue =
9331 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9332 				 queue, "queue");
9333 cmdline_parse_token_num_t cmd_flow_director_queue_id =
9334 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9335 			      queue_id, UINT16);
9336 cmdline_parse_token_string_t cmd_flow_director_fd_id =
9337 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9338 				 fd_id, "fd_id");
9339 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
9340 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9341 			      fd_id_value, UINT32);
9342 
9343 cmdline_parse_token_string_t cmd_flow_director_mode =
9344 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9345 				 mode, "mode");
9346 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
9347 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9348 				 mode_value, "IP");
9349 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
9350 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9351 				 mode_value, "MAC-VLAN");
9352 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
9353 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9354 				 mode_value, "Tunnel");
9355 cmdline_parse_token_string_t cmd_flow_director_mac =
9356 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9357 				 mac, "mac");
9358 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
9359 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
9360 				    mac_addr);
9361 cmdline_parse_token_string_t cmd_flow_director_tunnel =
9362 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9363 				 tunnel, "tunnel");
9364 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
9365 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9366 				 tunnel_type, "NVGRE#VxLAN");
9367 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
9368 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9369 				 tunnel_id, "tunnel-id");
9370 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
9371 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9372 			      tunnel_id_value, UINT32);
9373 
9374 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
9375 	.f = cmd_flow_director_filter_parsed,
9376 	.data = NULL,
9377 	.help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
9378 		" ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
9379 		"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
9380 		"l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
9381 		"proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
9382 		"flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
9383 		"fd_id <fd_id_value>: "
9384 		"Add or delete an ip flow director entry on NIC",
9385 	.tokens = {
9386 		(void *)&cmd_flow_director_filter,
9387 		(void *)&cmd_flow_director_port_id,
9388 		(void *)&cmd_flow_director_mode,
9389 		(void *)&cmd_flow_director_mode_ip,
9390 		(void *)&cmd_flow_director_ops,
9391 		(void *)&cmd_flow_director_flow,
9392 		(void *)&cmd_flow_director_flow_type,
9393 		(void *)&cmd_flow_director_src,
9394 		(void *)&cmd_flow_director_ip_src,
9395 		(void *)&cmd_flow_director_dst,
9396 		(void *)&cmd_flow_director_ip_dst,
9397 		(void *)&cmd_flow_director_tos,
9398 		(void *)&cmd_flow_director_tos_value,
9399 		(void *)&cmd_flow_director_proto,
9400 		(void *)&cmd_flow_director_proto_value,
9401 		(void *)&cmd_flow_director_ttl,
9402 		(void *)&cmd_flow_director_ttl_value,
9403 		(void *)&cmd_flow_director_vlan,
9404 		(void *)&cmd_flow_director_vlan_value,
9405 		(void *)&cmd_flow_director_flexbytes,
9406 		(void *)&cmd_flow_director_flexbytes_value,
9407 		(void *)&cmd_flow_director_drop,
9408 		(void *)&cmd_flow_director_pf_vf,
9409 		(void *)&cmd_flow_director_queue,
9410 		(void *)&cmd_flow_director_queue_id,
9411 		(void *)&cmd_flow_director_fd_id,
9412 		(void *)&cmd_flow_director_fd_id_value,
9413 		NULL,
9414 	},
9415 };
9416 
9417 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
9418 	.f = cmd_flow_director_filter_parsed,
9419 	.data = NULL,
9420 	.help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
9421 		"director entry on NIC",
9422 	.tokens = {
9423 		(void *)&cmd_flow_director_filter,
9424 		(void *)&cmd_flow_director_port_id,
9425 		(void *)&cmd_flow_director_mode,
9426 		(void *)&cmd_flow_director_mode_ip,
9427 		(void *)&cmd_flow_director_ops,
9428 		(void *)&cmd_flow_director_flow,
9429 		(void *)&cmd_flow_director_flow_type,
9430 		(void *)&cmd_flow_director_src,
9431 		(void *)&cmd_flow_director_ip_src,
9432 		(void *)&cmd_flow_director_port_src,
9433 		(void *)&cmd_flow_director_dst,
9434 		(void *)&cmd_flow_director_ip_dst,
9435 		(void *)&cmd_flow_director_port_dst,
9436 		(void *)&cmd_flow_director_tos,
9437 		(void *)&cmd_flow_director_tos_value,
9438 		(void *)&cmd_flow_director_ttl,
9439 		(void *)&cmd_flow_director_ttl_value,
9440 		(void *)&cmd_flow_director_vlan,
9441 		(void *)&cmd_flow_director_vlan_value,
9442 		(void *)&cmd_flow_director_flexbytes,
9443 		(void *)&cmd_flow_director_flexbytes_value,
9444 		(void *)&cmd_flow_director_drop,
9445 		(void *)&cmd_flow_director_pf_vf,
9446 		(void *)&cmd_flow_director_queue,
9447 		(void *)&cmd_flow_director_queue_id,
9448 		(void *)&cmd_flow_director_fd_id,
9449 		(void *)&cmd_flow_director_fd_id_value,
9450 		NULL,
9451 	},
9452 };
9453 
9454 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
9455 	.f = cmd_flow_director_filter_parsed,
9456 	.data = NULL,
9457 	.help_str = "flow_director_filter ... : Add or delete a sctp flow "
9458 		"director entry on NIC",
9459 	.tokens = {
9460 		(void *)&cmd_flow_director_filter,
9461 		(void *)&cmd_flow_director_port_id,
9462 		(void *)&cmd_flow_director_mode,
9463 		(void *)&cmd_flow_director_mode_ip,
9464 		(void *)&cmd_flow_director_ops,
9465 		(void *)&cmd_flow_director_flow,
9466 		(void *)&cmd_flow_director_flow_type,
9467 		(void *)&cmd_flow_director_src,
9468 		(void *)&cmd_flow_director_ip_src,
9469 		(void *)&cmd_flow_director_port_dst,
9470 		(void *)&cmd_flow_director_dst,
9471 		(void *)&cmd_flow_director_ip_dst,
9472 		(void *)&cmd_flow_director_port_dst,
9473 		(void *)&cmd_flow_director_verify_tag,
9474 		(void *)&cmd_flow_director_verify_tag_value,
9475 		(void *)&cmd_flow_director_tos,
9476 		(void *)&cmd_flow_director_tos_value,
9477 		(void *)&cmd_flow_director_ttl,
9478 		(void *)&cmd_flow_director_ttl_value,
9479 		(void *)&cmd_flow_director_vlan,
9480 		(void *)&cmd_flow_director_vlan_value,
9481 		(void *)&cmd_flow_director_flexbytes,
9482 		(void *)&cmd_flow_director_flexbytes_value,
9483 		(void *)&cmd_flow_director_drop,
9484 		(void *)&cmd_flow_director_pf_vf,
9485 		(void *)&cmd_flow_director_queue,
9486 		(void *)&cmd_flow_director_queue_id,
9487 		(void *)&cmd_flow_director_fd_id,
9488 		(void *)&cmd_flow_director_fd_id_value,
9489 		NULL,
9490 	},
9491 };
9492 
9493 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
9494 	.f = cmd_flow_director_filter_parsed,
9495 	.data = NULL,
9496 	.help_str = "flow_director_filter ... : Add or delete a L2 flow "
9497 		"director entry on NIC",
9498 	.tokens = {
9499 		(void *)&cmd_flow_director_filter,
9500 		(void *)&cmd_flow_director_port_id,
9501 		(void *)&cmd_flow_director_mode,
9502 		(void *)&cmd_flow_director_mode_ip,
9503 		(void *)&cmd_flow_director_ops,
9504 		(void *)&cmd_flow_director_flow,
9505 		(void *)&cmd_flow_director_flow_type,
9506 		(void *)&cmd_flow_director_ether,
9507 		(void *)&cmd_flow_director_ether_type,
9508 		(void *)&cmd_flow_director_flexbytes,
9509 		(void *)&cmd_flow_director_flexbytes_value,
9510 		(void *)&cmd_flow_director_drop,
9511 		(void *)&cmd_flow_director_pf_vf,
9512 		(void *)&cmd_flow_director_queue,
9513 		(void *)&cmd_flow_director_queue_id,
9514 		(void *)&cmd_flow_director_fd_id,
9515 		(void *)&cmd_flow_director_fd_id_value,
9516 		NULL,
9517 	},
9518 };
9519 
9520 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
9521 	.f = cmd_flow_director_filter_parsed,
9522 	.data = NULL,
9523 	.help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
9524 		"director entry on NIC",
9525 	.tokens = {
9526 		(void *)&cmd_flow_director_filter,
9527 		(void *)&cmd_flow_director_port_id,
9528 		(void *)&cmd_flow_director_mode,
9529 		(void *)&cmd_flow_director_mode_mac_vlan,
9530 		(void *)&cmd_flow_director_ops,
9531 		(void *)&cmd_flow_director_mac,
9532 		(void *)&cmd_flow_director_mac_addr,
9533 		(void *)&cmd_flow_director_vlan,
9534 		(void *)&cmd_flow_director_vlan_value,
9535 		(void *)&cmd_flow_director_flexbytes,
9536 		(void *)&cmd_flow_director_flexbytes_value,
9537 		(void *)&cmd_flow_director_drop,
9538 		(void *)&cmd_flow_director_queue,
9539 		(void *)&cmd_flow_director_queue_id,
9540 		(void *)&cmd_flow_director_fd_id,
9541 		(void *)&cmd_flow_director_fd_id_value,
9542 		NULL,
9543 	},
9544 };
9545 
9546 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
9547 	.f = cmd_flow_director_filter_parsed,
9548 	.data = NULL,
9549 	.help_str = "flow_director_filter ... : Add or delete a tunnel flow "
9550 		"director entry on NIC",
9551 	.tokens = {
9552 		(void *)&cmd_flow_director_filter,
9553 		(void *)&cmd_flow_director_port_id,
9554 		(void *)&cmd_flow_director_mode,
9555 		(void *)&cmd_flow_director_mode_tunnel,
9556 		(void *)&cmd_flow_director_ops,
9557 		(void *)&cmd_flow_director_mac,
9558 		(void *)&cmd_flow_director_mac_addr,
9559 		(void *)&cmd_flow_director_vlan,
9560 		(void *)&cmd_flow_director_vlan_value,
9561 		(void *)&cmd_flow_director_tunnel,
9562 		(void *)&cmd_flow_director_tunnel_type,
9563 		(void *)&cmd_flow_director_tunnel_id,
9564 		(void *)&cmd_flow_director_tunnel_id_value,
9565 		(void *)&cmd_flow_director_flexbytes,
9566 		(void *)&cmd_flow_director_flexbytes_value,
9567 		(void *)&cmd_flow_director_drop,
9568 		(void *)&cmd_flow_director_queue,
9569 		(void *)&cmd_flow_director_queue_id,
9570 		(void *)&cmd_flow_director_fd_id,
9571 		(void *)&cmd_flow_director_fd_id_value,
9572 		NULL,
9573 	},
9574 };
9575 
9576 struct cmd_flush_flow_director_result {
9577 	cmdline_fixed_string_t flush_flow_director;
9578 	uint8_t port_id;
9579 };
9580 
9581 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
9582 	TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
9583 				 flush_flow_director, "flush_flow_director");
9584 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
9585 	TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
9586 			      port_id, UINT8);
9587 
9588 static void
9589 cmd_flush_flow_director_parsed(void *parsed_result,
9590 			  __attribute__((unused)) struct cmdline *cl,
9591 			  __attribute__((unused)) void *data)
9592 {
9593 	struct cmd_flow_director_result *res = parsed_result;
9594 	int ret = 0;
9595 
9596 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9597 	if (ret < 0) {
9598 		printf("flow director is not supported on port %u.\n",
9599 			res->port_id);
9600 		return;
9601 	}
9602 
9603 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9604 			RTE_ETH_FILTER_FLUSH, NULL);
9605 	if (ret < 0)
9606 		printf("flow director table flushing error: (%s)\n",
9607 			strerror(-ret));
9608 }
9609 
9610 cmdline_parse_inst_t cmd_flush_flow_director = {
9611 	.f = cmd_flush_flow_director_parsed,
9612 	.data = NULL,
9613 	.help_str = "flush_flow_director <port_id>: "
9614 		"Flush all flow director entries of a device on NIC",
9615 	.tokens = {
9616 		(void *)&cmd_flush_flow_director_flush,
9617 		(void *)&cmd_flush_flow_director_port_id,
9618 		NULL,
9619 	},
9620 };
9621 
9622 /* *** deal with flow director mask *** */
9623 struct cmd_flow_director_mask_result {
9624 	cmdline_fixed_string_t flow_director_mask;
9625 	uint8_t port_id;
9626 	cmdline_fixed_string_t mode;
9627 	cmdline_fixed_string_t mode_value;
9628 	cmdline_fixed_string_t vlan;
9629 	uint16_t vlan_mask;
9630 	cmdline_fixed_string_t src_mask;
9631 	cmdline_ipaddr_t ipv4_src;
9632 	cmdline_ipaddr_t ipv6_src;
9633 	uint16_t port_src;
9634 	cmdline_fixed_string_t dst_mask;
9635 	cmdline_ipaddr_t ipv4_dst;
9636 	cmdline_ipaddr_t ipv6_dst;
9637 	uint16_t port_dst;
9638 	cmdline_fixed_string_t mac;
9639 	uint8_t mac_addr_byte_mask;
9640 	cmdline_fixed_string_t tunnel_id;
9641 	uint32_t tunnel_id_mask;
9642 	cmdline_fixed_string_t tunnel_type;
9643 	uint8_t tunnel_type_mask;
9644 };
9645 
9646 static void
9647 cmd_flow_director_mask_parsed(void *parsed_result,
9648 			  __attribute__((unused)) struct cmdline *cl,
9649 			  __attribute__((unused)) void *data)
9650 {
9651 	struct cmd_flow_director_mask_result *res = parsed_result;
9652 	struct rte_eth_fdir_masks *mask;
9653 	struct rte_port *port;
9654 
9655 	if (res->port_id > nb_ports) {
9656 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9657 		return;
9658 	}
9659 
9660 	port = &ports[res->port_id];
9661 	/** Check if the port is not started **/
9662 	if (port->port_status != RTE_PORT_STOPPED) {
9663 		printf("Please stop port %d first\n", res->port_id);
9664 		return;
9665 	}
9666 
9667 	mask = &port->dev_conf.fdir_conf.mask;
9668 
9669 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9670 		if (strcmp(res->mode_value, "MAC-VLAN")) {
9671 			printf("Please set mode to MAC-VLAN.\n");
9672 			return;
9673 		}
9674 
9675 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9676 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9677 		if (strcmp(res->mode_value, "Tunnel")) {
9678 			printf("Please set mode to Tunnel.\n");
9679 			return;
9680 		}
9681 
9682 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9683 		mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9684 		mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
9685 		mask->tunnel_type_mask = res->tunnel_type_mask;
9686 	} else {
9687 		if (strcmp(res->mode_value, "IP")) {
9688 			printf("Please set mode to IP.\n");
9689 			return;
9690 		}
9691 
9692 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9693 		IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
9694 		IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
9695 		IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
9696 		IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
9697 		mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
9698 		mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
9699 	}
9700 
9701 	cmd_reconfig_device_queue(res->port_id, 1, 1);
9702 }
9703 
9704 cmdline_parse_token_string_t cmd_flow_director_mask =
9705 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9706 				 flow_director_mask, "flow_director_mask");
9707 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
9708 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9709 			      port_id, UINT8);
9710 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
9711 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9712 				 vlan, "vlan");
9713 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
9714 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9715 			      vlan_mask, UINT16);
9716 cmdline_parse_token_string_t cmd_flow_director_mask_src =
9717 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9718 				 src_mask, "src_mask");
9719 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
9720 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9721 				 ipv4_src);
9722 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
9723 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9724 				 ipv6_src);
9725 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
9726 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9727 			      port_src, UINT16);
9728 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
9729 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9730 				 dst_mask, "dst_mask");
9731 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
9732 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9733 				 ipv4_dst);
9734 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
9735 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9736 				 ipv6_dst);
9737 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
9738 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9739 			      port_dst, UINT16);
9740 
9741 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
9742 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9743 				 mode, "mode");
9744 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
9745 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9746 				 mode_value, "IP");
9747 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
9748 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9749 				 mode_value, "MAC-VLAN");
9750 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
9751 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9752 				 mode_value, "Tunnel");
9753 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
9754 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9755 				 mac, "mac");
9756 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
9757 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9758 			      mac_addr_byte_mask, UINT8);
9759 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
9760 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9761 				 tunnel_type, "tunnel-type");
9762 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
9763 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9764 			      tunnel_type_mask, UINT8);
9765 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
9766 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9767 				 tunnel_id, "tunnel-id");
9768 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
9769 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9770 			      tunnel_id_mask, UINT32);
9771 
9772 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
9773 	.f = cmd_flow_director_mask_parsed,
9774 	.data = NULL,
9775 	.help_str = "flow_director_mask ... : "
9776 		"Set IP mode flow director's mask on NIC",
9777 	.tokens = {
9778 		(void *)&cmd_flow_director_mask,
9779 		(void *)&cmd_flow_director_mask_port_id,
9780 		(void *)&cmd_flow_director_mask_mode,
9781 		(void *)&cmd_flow_director_mask_mode_ip,
9782 		(void *)&cmd_flow_director_mask_vlan,
9783 		(void *)&cmd_flow_director_mask_vlan_value,
9784 		(void *)&cmd_flow_director_mask_src,
9785 		(void *)&cmd_flow_director_mask_ipv4_src,
9786 		(void *)&cmd_flow_director_mask_ipv6_src,
9787 		(void *)&cmd_flow_director_mask_port_src,
9788 		(void *)&cmd_flow_director_mask_dst,
9789 		(void *)&cmd_flow_director_mask_ipv4_dst,
9790 		(void *)&cmd_flow_director_mask_ipv6_dst,
9791 		(void *)&cmd_flow_director_mask_port_dst,
9792 		NULL,
9793 	},
9794 };
9795 
9796 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
9797 	.f = cmd_flow_director_mask_parsed,
9798 	.data = NULL,
9799 	.help_str = "flow_director_mask ... : Set MAC VLAN mode "
9800 		"flow director's mask on NIC",
9801 	.tokens = {
9802 		(void *)&cmd_flow_director_mask,
9803 		(void *)&cmd_flow_director_mask_port_id,
9804 		(void *)&cmd_flow_director_mask_mode,
9805 		(void *)&cmd_flow_director_mask_mode_mac_vlan,
9806 		(void *)&cmd_flow_director_mask_vlan,
9807 		(void *)&cmd_flow_director_mask_vlan_value,
9808 		NULL,
9809 	},
9810 };
9811 
9812 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
9813 	.f = cmd_flow_director_mask_parsed,
9814 	.data = NULL,
9815 	.help_str = "flow_director_mask ... : Set tunnel mode "
9816 		"flow director's mask on NIC",
9817 	.tokens = {
9818 		(void *)&cmd_flow_director_mask,
9819 		(void *)&cmd_flow_director_mask_port_id,
9820 		(void *)&cmd_flow_director_mask_mode,
9821 		(void *)&cmd_flow_director_mask_mode_tunnel,
9822 		(void *)&cmd_flow_director_mask_vlan,
9823 		(void *)&cmd_flow_director_mask_vlan_value,
9824 		(void *)&cmd_flow_director_mask_mac,
9825 		(void *)&cmd_flow_director_mask_mac_value,
9826 		(void *)&cmd_flow_director_mask_tunnel_type,
9827 		(void *)&cmd_flow_director_mask_tunnel_type_value,
9828 		(void *)&cmd_flow_director_mask_tunnel_id,
9829 		(void *)&cmd_flow_director_mask_tunnel_id_value,
9830 		NULL,
9831 	},
9832 };
9833 
9834 /* *** deal with flow director mask on flexible payload *** */
9835 struct cmd_flow_director_flex_mask_result {
9836 	cmdline_fixed_string_t flow_director_flexmask;
9837 	uint8_t port_id;
9838 	cmdline_fixed_string_t flow;
9839 	cmdline_fixed_string_t flow_type;
9840 	cmdline_fixed_string_t mask;
9841 };
9842 
9843 static void
9844 cmd_flow_director_flex_mask_parsed(void *parsed_result,
9845 			  __attribute__((unused)) struct cmdline *cl,
9846 			  __attribute__((unused)) void *data)
9847 {
9848 	struct cmd_flow_director_flex_mask_result *res = parsed_result;
9849 	struct rte_eth_fdir_info fdir_info;
9850 	struct rte_eth_fdir_flex_mask flex_mask;
9851 	struct rte_port *port;
9852 	uint32_t flow_type_mask;
9853 	uint16_t i;
9854 	int ret;
9855 
9856 	if (res->port_id > nb_ports) {
9857 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9858 		return;
9859 	}
9860 
9861 	port = &ports[res->port_id];
9862 	/** Check if the port is not started **/
9863 	if (port->port_status != RTE_PORT_STOPPED) {
9864 		printf("Please stop port %d first\n", res->port_id);
9865 		return;
9866 	}
9867 
9868 	memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
9869 	ret = parse_flexbytes(res->mask,
9870 			flex_mask.mask,
9871 			RTE_ETH_FDIR_MAX_FLEXLEN);
9872 	if (ret < 0) {
9873 		printf("error: Cannot parse mask input.\n");
9874 		return;
9875 	}
9876 
9877 	memset(&fdir_info, 0, sizeof(fdir_info));
9878 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9879 				RTE_ETH_FILTER_INFO, &fdir_info);
9880 	if (ret < 0) {
9881 		printf("Cannot get FDir filter info\n");
9882 		return;
9883 	}
9884 
9885 	if (!strcmp(res->flow_type, "none")) {
9886 		/* means don't specify the flow type */
9887 		flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
9888 		for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
9889 			memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
9890 			       0, sizeof(struct rte_eth_fdir_flex_mask));
9891 		port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
9892 		rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
9893 				 &flex_mask,
9894 				 sizeof(struct rte_eth_fdir_flex_mask));
9895 		cmd_reconfig_device_queue(res->port_id, 1, 1);
9896 		return;
9897 	}
9898 	flow_type_mask = fdir_info.flow_types_mask[0];
9899 	if (!strcmp(res->flow_type, "all")) {
9900 		if (!flow_type_mask) {
9901 			printf("No flow type supported\n");
9902 			return;
9903 		}
9904 		for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
9905 			if (flow_type_mask & (1 << i)) {
9906 				flex_mask.flow_type = i;
9907 				fdir_set_flex_mask(res->port_id, &flex_mask);
9908 			}
9909 		}
9910 		cmd_reconfig_device_queue(res->port_id, 1, 1);
9911 		return;
9912 	}
9913 	flex_mask.flow_type = str2flowtype(res->flow_type);
9914 	if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
9915 		printf("Flow type %s not supported on port %d\n",
9916 				res->flow_type, res->port_id);
9917 		return;
9918 	}
9919 	fdir_set_flex_mask(res->port_id, &flex_mask);
9920 	cmd_reconfig_device_queue(res->port_id, 1, 1);
9921 }
9922 
9923 cmdline_parse_token_string_t cmd_flow_director_flexmask =
9924 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9925 				 flow_director_flexmask,
9926 				 "flow_director_flex_mask");
9927 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
9928 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9929 			      port_id, UINT8);
9930 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
9931 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9932 				 flow, "flow");
9933 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
9934 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9935 		flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9936 		"ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
9937 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
9938 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9939 				 mask, NULL);
9940 
9941 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
9942 	.f = cmd_flow_director_flex_mask_parsed,
9943 	.data = NULL,
9944 	.help_str = "flow_director_flex_mask ... : "
9945 		"Set flow director's flex mask on NIC",
9946 	.tokens = {
9947 		(void *)&cmd_flow_director_flexmask,
9948 		(void *)&cmd_flow_director_flexmask_port_id,
9949 		(void *)&cmd_flow_director_flexmask_flow,
9950 		(void *)&cmd_flow_director_flexmask_flow_type,
9951 		(void *)&cmd_flow_director_flexmask_mask,
9952 		NULL,
9953 	},
9954 };
9955 
9956 /* *** deal with flow director flexible payload configuration *** */
9957 struct cmd_flow_director_flexpayload_result {
9958 	cmdline_fixed_string_t flow_director_flexpayload;
9959 	uint8_t port_id;
9960 	cmdline_fixed_string_t payload_layer;
9961 	cmdline_fixed_string_t payload_cfg;
9962 };
9963 
9964 static inline int
9965 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
9966 {
9967 	char s[256];
9968 	const char *p, *p0 = q_arg;
9969 	char *end;
9970 	unsigned long int_fld;
9971 	char *str_fld[max_num];
9972 	int i;
9973 	unsigned size;
9974 	int ret = -1;
9975 
9976 	p = strchr(p0, '(');
9977 	if (p == NULL)
9978 		return -1;
9979 	++p;
9980 	p0 = strchr(p, ')');
9981 	if (p0 == NULL)
9982 		return -1;
9983 
9984 	size = p0 - p;
9985 	if (size >= sizeof(s))
9986 		return -1;
9987 
9988 	snprintf(s, sizeof(s), "%.*s", size, p);
9989 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9990 	if (ret < 0 || ret > max_num)
9991 		return -1;
9992 	for (i = 0; i < ret; i++) {
9993 		errno = 0;
9994 		int_fld = strtoul(str_fld[i], &end, 0);
9995 		if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
9996 			return -1;
9997 		offsets[i] = (uint16_t)int_fld;
9998 	}
9999 	return ret;
10000 }
10001 
10002 static void
10003 cmd_flow_director_flxpld_parsed(void *parsed_result,
10004 			  __attribute__((unused)) struct cmdline *cl,
10005 			  __attribute__((unused)) void *data)
10006 {
10007 	struct cmd_flow_director_flexpayload_result *res = parsed_result;
10008 	struct rte_eth_flex_payload_cfg flex_cfg;
10009 	struct rte_port *port;
10010 	int ret = 0;
10011 
10012 	if (res->port_id > nb_ports) {
10013 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10014 		return;
10015 	}
10016 
10017 	port = &ports[res->port_id];
10018 	/** Check if the port is not started **/
10019 	if (port->port_status != RTE_PORT_STOPPED) {
10020 		printf("Please stop port %d first\n", res->port_id);
10021 		return;
10022 	}
10023 
10024 	memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10025 
10026 	if (!strcmp(res->payload_layer, "raw"))
10027 		flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10028 	else if (!strcmp(res->payload_layer, "l2"))
10029 		flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10030 	else if (!strcmp(res->payload_layer, "l3"))
10031 		flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10032 	else if (!strcmp(res->payload_layer, "l4"))
10033 		flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10034 
10035 	ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10036 			    RTE_ETH_FDIR_MAX_FLEXLEN);
10037 	if (ret < 0) {
10038 		printf("error: Cannot parse flex payload input.\n");
10039 		return;
10040 	}
10041 
10042 	fdir_set_flex_payload(res->port_id, &flex_cfg);
10043 	cmd_reconfig_device_queue(res->port_id, 1, 1);
10044 }
10045 
10046 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10047 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10048 				 flow_director_flexpayload,
10049 				 "flow_director_flex_payload");
10050 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10051 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10052 			      port_id, UINT8);
10053 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10054 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10055 				 payload_layer, "raw#l2#l3#l4");
10056 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10057 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10058 				 payload_cfg, NULL);
10059 
10060 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10061 	.f = cmd_flow_director_flxpld_parsed,
10062 	.data = NULL,
10063 	.help_str = "flow_director_flexpayload ... : "
10064 		"Set flow director's flex payload on NIC",
10065 	.tokens = {
10066 		(void *)&cmd_flow_director_flexpayload,
10067 		(void *)&cmd_flow_director_flexpayload_port_id,
10068 		(void *)&cmd_flow_director_flexpayload_payload_layer,
10069 		(void *)&cmd_flow_director_flexpayload_payload_cfg,
10070 		NULL,
10071 	},
10072 };
10073 
10074 /* Generic flow interface command. */
10075 extern cmdline_parse_inst_t cmd_flow;
10076 
10077 /* *** Classification Filters Control *** */
10078 /* *** Get symmetric hash enable per port *** */
10079 struct cmd_get_sym_hash_ena_per_port_result {
10080 	cmdline_fixed_string_t get_sym_hash_ena_per_port;
10081 	uint8_t port_id;
10082 };
10083 
10084 static void
10085 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10086 				 __rte_unused struct cmdline *cl,
10087 				 __rte_unused void *data)
10088 {
10089 	struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10090 	struct rte_eth_hash_filter_info info;
10091 	int ret;
10092 
10093 	if (rte_eth_dev_filter_supported(res->port_id,
10094 				RTE_ETH_FILTER_HASH) < 0) {
10095 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10096 							res->port_id);
10097 		return;
10098 	}
10099 
10100 	memset(&info, 0, sizeof(info));
10101 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10102 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10103 						RTE_ETH_FILTER_GET, &info);
10104 
10105 	if (ret < 0) {
10106 		printf("Cannot get symmetric hash enable per port "
10107 					"on port %u\n", res->port_id);
10108 		return;
10109 	}
10110 
10111 	printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10112 				"enabled" : "disabled", res->port_id);
10113 }
10114 
10115 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10116 	TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10117 		get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10118 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10119 	TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10120 		port_id, UINT8);
10121 
10122 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10123 	.f = cmd_get_sym_hash_per_port_parsed,
10124 	.data = NULL,
10125 	.help_str = "get_sym_hash_ena_per_port <port_id>",
10126 	.tokens = {
10127 		(void *)&cmd_get_sym_hash_ena_per_port_all,
10128 		(void *)&cmd_get_sym_hash_ena_per_port_port_id,
10129 		NULL,
10130 	},
10131 };
10132 
10133 /* *** Set symmetric hash enable per port *** */
10134 struct cmd_set_sym_hash_ena_per_port_result {
10135 	cmdline_fixed_string_t set_sym_hash_ena_per_port;
10136 	cmdline_fixed_string_t enable;
10137 	uint8_t port_id;
10138 };
10139 
10140 static void
10141 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10142 				 __rte_unused struct cmdline *cl,
10143 				 __rte_unused void *data)
10144 {
10145 	struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10146 	struct rte_eth_hash_filter_info info;
10147 	int ret;
10148 
10149 	if (rte_eth_dev_filter_supported(res->port_id,
10150 				RTE_ETH_FILTER_HASH) < 0) {
10151 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10152 							res->port_id);
10153 		return;
10154 	}
10155 
10156 	memset(&info, 0, sizeof(info));
10157 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10158 	if (!strcmp(res->enable, "enable"))
10159 		info.info.enable = 1;
10160 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10161 					RTE_ETH_FILTER_SET, &info);
10162 	if (ret < 0) {
10163 		printf("Cannot set symmetric hash enable per port on "
10164 					"port %u\n", res->port_id);
10165 		return;
10166 	}
10167 	printf("Symmetric hash has been set to %s on port %u\n",
10168 					res->enable, res->port_id);
10169 }
10170 
10171 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10172 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10173 		set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10174 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10175 	TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10176 		port_id, UINT8);
10177 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10178 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10179 		enable, "enable#disable");
10180 
10181 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10182 	.f = cmd_set_sym_hash_per_port_parsed,
10183 	.data = NULL,
10184 	.help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10185 	.tokens = {
10186 		(void *)&cmd_set_sym_hash_ena_per_port_all,
10187 		(void *)&cmd_set_sym_hash_ena_per_port_port_id,
10188 		(void *)&cmd_set_sym_hash_ena_per_port_enable,
10189 		NULL,
10190 	},
10191 };
10192 
10193 /* Get global config of hash function */
10194 struct cmd_get_hash_global_config_result {
10195 	cmdline_fixed_string_t get_hash_global_config;
10196 	uint8_t port_id;
10197 };
10198 
10199 static char *
10200 flowtype_to_str(uint16_t ftype)
10201 {
10202 	uint16_t i;
10203 	static struct {
10204 		char str[16];
10205 		uint16_t ftype;
10206 	} ftype_table[] = {
10207 		{"ipv4", RTE_ETH_FLOW_IPV4},
10208 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10209 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10210 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10211 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10212 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10213 		{"ipv6", RTE_ETH_FLOW_IPV6},
10214 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10215 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10216 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10217 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10218 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10219 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10220 		{"port", RTE_ETH_FLOW_PORT},
10221 		{"vxlan", RTE_ETH_FLOW_VXLAN},
10222 		{"geneve", RTE_ETH_FLOW_GENEVE},
10223 		{"nvgre", RTE_ETH_FLOW_NVGRE},
10224 	};
10225 
10226 	for (i = 0; i < RTE_DIM(ftype_table); i++) {
10227 		if (ftype_table[i].ftype == ftype)
10228 			return ftype_table[i].str;
10229 	}
10230 
10231 	return NULL;
10232 }
10233 
10234 static void
10235 cmd_get_hash_global_config_parsed(void *parsed_result,
10236 				  __rte_unused struct cmdline *cl,
10237 				  __rte_unused void *data)
10238 {
10239 	struct cmd_get_hash_global_config_result *res = parsed_result;
10240 	struct rte_eth_hash_filter_info info;
10241 	uint32_t idx, offset;
10242 	uint16_t i;
10243 	char *str;
10244 	int ret;
10245 
10246 	if (rte_eth_dev_filter_supported(res->port_id,
10247 			RTE_ETH_FILTER_HASH) < 0) {
10248 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10249 							res->port_id);
10250 		return;
10251 	}
10252 
10253 	memset(&info, 0, sizeof(info));
10254 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10255 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10256 					RTE_ETH_FILTER_GET, &info);
10257 	if (ret < 0) {
10258 		printf("Cannot get hash global configurations by port %d\n",
10259 							res->port_id);
10260 		return;
10261 	}
10262 
10263 	switch (info.info.global_conf.hash_func) {
10264 	case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
10265 		printf("Hash function is Toeplitz\n");
10266 		break;
10267 	case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
10268 		printf("Hash function is Simple XOR\n");
10269 		break;
10270 	default:
10271 		printf("Unknown hash function\n");
10272 		break;
10273 	}
10274 
10275 	for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
10276 		idx = i / UINT32_BIT;
10277 		offset = i % UINT32_BIT;
10278 		if (!(info.info.global_conf.valid_bit_mask[idx] &
10279 						(1UL << offset)))
10280 			continue;
10281 		str = flowtype_to_str(i);
10282 		if (!str)
10283 			continue;
10284 		printf("Symmetric hash is %s globally for flow type %s "
10285 							"by port %d\n",
10286 			((info.info.global_conf.sym_hash_enable_mask[idx] &
10287 			(1UL << offset)) ? "enabled" : "disabled"), str,
10288 							res->port_id);
10289 	}
10290 }
10291 
10292 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
10293 	TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
10294 		get_hash_global_config, "get_hash_global_config");
10295 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
10296 	TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
10297 		port_id, UINT8);
10298 
10299 cmdline_parse_inst_t cmd_get_hash_global_config = {
10300 	.f = cmd_get_hash_global_config_parsed,
10301 	.data = NULL,
10302 	.help_str = "get_hash_global_config <port_id>",
10303 	.tokens = {
10304 		(void *)&cmd_get_hash_global_config_all,
10305 		(void *)&cmd_get_hash_global_config_port_id,
10306 		NULL,
10307 	},
10308 };
10309 
10310 /* Set global config of hash function */
10311 struct cmd_set_hash_global_config_result {
10312 	cmdline_fixed_string_t set_hash_global_config;
10313 	uint8_t port_id;
10314 	cmdline_fixed_string_t hash_func;
10315 	cmdline_fixed_string_t flow_type;
10316 	cmdline_fixed_string_t enable;
10317 };
10318 
10319 static void
10320 cmd_set_hash_global_config_parsed(void *parsed_result,
10321 				  __rte_unused struct cmdline *cl,
10322 				  __rte_unused void *data)
10323 {
10324 	struct cmd_set_hash_global_config_result *res = parsed_result;
10325 	struct rte_eth_hash_filter_info info;
10326 	uint32_t ftype, idx, offset;
10327 	int ret;
10328 
10329 	if (rte_eth_dev_filter_supported(res->port_id,
10330 				RTE_ETH_FILTER_HASH) < 0) {
10331 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10332 							res->port_id);
10333 		return;
10334 	}
10335 	memset(&info, 0, sizeof(info));
10336 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10337 	if (!strcmp(res->hash_func, "toeplitz"))
10338 		info.info.global_conf.hash_func =
10339 			RTE_ETH_HASH_FUNCTION_TOEPLITZ;
10340 	else if (!strcmp(res->hash_func, "simple_xor"))
10341 		info.info.global_conf.hash_func =
10342 			RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
10343 	else if (!strcmp(res->hash_func, "default"))
10344 		info.info.global_conf.hash_func =
10345 			RTE_ETH_HASH_FUNCTION_DEFAULT;
10346 
10347 	ftype = str2flowtype(res->flow_type);
10348 	idx = ftype / (CHAR_BIT * sizeof(uint32_t));
10349 	offset = ftype % (CHAR_BIT * sizeof(uint32_t));
10350 	info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
10351 	if (!strcmp(res->enable, "enable"))
10352 		info.info.global_conf.sym_hash_enable_mask[idx] |=
10353 						(1UL << offset);
10354 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10355 					RTE_ETH_FILTER_SET, &info);
10356 	if (ret < 0)
10357 		printf("Cannot set global hash configurations by port %d\n",
10358 							res->port_id);
10359 	else
10360 		printf("Global hash configurations have been set "
10361 			"succcessfully by port %d\n", res->port_id);
10362 }
10363 
10364 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
10365 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10366 		set_hash_global_config, "set_hash_global_config");
10367 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
10368 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
10369 		port_id, UINT8);
10370 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
10371 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10372 		hash_func, "toeplitz#simple_xor#default");
10373 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
10374 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10375 		flow_type,
10376 		"ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
10377 		"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10378 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
10379 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10380 		enable, "enable#disable");
10381 
10382 cmdline_parse_inst_t cmd_set_hash_global_config = {
10383 	.f = cmd_set_hash_global_config_parsed,
10384 	.data = NULL,
10385 	.help_str = "set_hash_global_config <port_id> "
10386 		"toeplitz|simple_xor|default "
10387 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10388 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
10389 		"l2_payload enable|disable",
10390 	.tokens = {
10391 		(void *)&cmd_set_hash_global_config_all,
10392 		(void *)&cmd_set_hash_global_config_port_id,
10393 		(void *)&cmd_set_hash_global_config_hash_func,
10394 		(void *)&cmd_set_hash_global_config_flow_type,
10395 		(void *)&cmd_set_hash_global_config_enable,
10396 		NULL,
10397 	},
10398 };
10399 
10400 /* Set hash input set */
10401 struct cmd_set_hash_input_set_result {
10402 	cmdline_fixed_string_t set_hash_input_set;
10403 	uint8_t port_id;
10404 	cmdline_fixed_string_t flow_type;
10405 	cmdline_fixed_string_t inset_field;
10406 	cmdline_fixed_string_t select;
10407 };
10408 
10409 static enum rte_eth_input_set_field
10410 str2inset(char *string)
10411 {
10412 	uint16_t i;
10413 
10414 	static const struct {
10415 		char str[32];
10416 		enum rte_eth_input_set_field inset;
10417 	} inset_table[] = {
10418 		{"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
10419 		{"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
10420 		{"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
10421 		{"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
10422 		{"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
10423 		{"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
10424 		{"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
10425 		{"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
10426 		{"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
10427 		{"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
10428 		{"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
10429 		{"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
10430 		{"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
10431 		{"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
10432 		{"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
10433 		{"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
10434 		{"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
10435 		{"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
10436 		{"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
10437 		{"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
10438 		{"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
10439 		{"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
10440 		{"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
10441 		{"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
10442 		{"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
10443 		{"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
10444 		{"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
10445 		{"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
10446 		{"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
10447 		{"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
10448 		{"none", RTE_ETH_INPUT_SET_NONE},
10449 	};
10450 
10451 	for (i = 0; i < RTE_DIM(inset_table); i++) {
10452 		if (!strcmp(string, inset_table[i].str))
10453 			return inset_table[i].inset;
10454 	}
10455 
10456 	return RTE_ETH_INPUT_SET_UNKNOWN;
10457 }
10458 
10459 static void
10460 cmd_set_hash_input_set_parsed(void *parsed_result,
10461 			      __rte_unused struct cmdline *cl,
10462 			      __rte_unused void *data)
10463 {
10464 	struct cmd_set_hash_input_set_result *res = parsed_result;
10465 	struct rte_eth_hash_filter_info info;
10466 
10467 	memset(&info, 0, sizeof(info));
10468 	info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
10469 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10470 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10471 	info.info.input_set_conf.inset_size = 1;
10472 	if (!strcmp(res->select, "select"))
10473 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10474 	else if (!strcmp(res->select, "add"))
10475 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10476 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10477 				RTE_ETH_FILTER_SET, &info);
10478 }
10479 
10480 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
10481 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10482 		set_hash_input_set, "set_hash_input_set");
10483 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
10484 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
10485 		port_id, UINT8);
10486 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
10487 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10488 		flow_type, NULL);
10489 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
10490 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10491 		inset_field,
10492 		"ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10493 		"ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
10494 		"udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
10495 		"sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
10496 		"fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
10497 		"fld-8th#none");
10498 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
10499 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10500 		select, "select#add");
10501 
10502 cmdline_parse_inst_t cmd_set_hash_input_set = {
10503 	.f = cmd_set_hash_input_set_parsed,
10504 	.data = NULL,
10505 	.help_str = "set_hash_input_set <port_id> "
10506 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10507 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
10508 	"ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
10509 	"ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
10510 	"tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
10511 	"gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
10512 	"fld-7th|fld-8th|none select|add",
10513 	.tokens = {
10514 		(void *)&cmd_set_hash_input_set_cmd,
10515 		(void *)&cmd_set_hash_input_set_port_id,
10516 		(void *)&cmd_set_hash_input_set_flow_type,
10517 		(void *)&cmd_set_hash_input_set_field,
10518 		(void *)&cmd_set_hash_input_set_select,
10519 		NULL,
10520 	},
10521 };
10522 
10523 /* Set flow director input set */
10524 struct cmd_set_fdir_input_set_result {
10525 	cmdline_fixed_string_t set_fdir_input_set;
10526 	uint8_t port_id;
10527 	cmdline_fixed_string_t flow_type;
10528 	cmdline_fixed_string_t inset_field;
10529 	cmdline_fixed_string_t select;
10530 };
10531 
10532 static void
10533 cmd_set_fdir_input_set_parsed(void *parsed_result,
10534 	__rte_unused struct cmdline *cl,
10535 	__rte_unused void *data)
10536 {
10537 	struct cmd_set_fdir_input_set_result *res = parsed_result;
10538 	struct rte_eth_fdir_filter_info info;
10539 
10540 	memset(&info, 0, sizeof(info));
10541 	info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
10542 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10543 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10544 	info.info.input_set_conf.inset_size = 1;
10545 	if (!strcmp(res->select, "select"))
10546 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10547 	else if (!strcmp(res->select, "add"))
10548 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10549 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10550 		RTE_ETH_FILTER_SET, &info);
10551 }
10552 
10553 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
10554 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10555 	set_fdir_input_set, "set_fdir_input_set");
10556 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
10557 	TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
10558 	port_id, UINT8);
10559 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
10560 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10561 	flow_type,
10562 	"ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10563 	"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10564 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
10565 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10566 	inset_field,
10567 	"ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10568 	"ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
10569 	"ipv6-hop-limits#udp-src-port#udp-dst-port#"
10570 	"tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
10571 	"sctp-veri-tag#none");
10572 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
10573 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10574 	select, "select#add");
10575 
10576 cmdline_parse_inst_t cmd_set_fdir_input_set = {
10577 	.f = cmd_set_fdir_input_set_parsed,
10578 	.data = NULL,
10579 	.help_str = "set_fdir_input_set <port_id> "
10580 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10581 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10582 	"ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
10583 	"ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
10584 	"ipv6-hop-limits|udp-src-port|udp-dst-port|"
10585 	"tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
10586 	"sctp-veri-tag|none select|add",
10587 	.tokens = {
10588 		(void *)&cmd_set_fdir_input_set_cmd,
10589 		(void *)&cmd_set_fdir_input_set_port_id,
10590 		(void *)&cmd_set_fdir_input_set_flow_type,
10591 		(void *)&cmd_set_fdir_input_set_field,
10592 		(void *)&cmd_set_fdir_input_set_select,
10593 		NULL,
10594 	},
10595 };
10596 
10597 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10598 struct cmd_mcast_addr_result {
10599 	cmdline_fixed_string_t mcast_addr_cmd;
10600 	cmdline_fixed_string_t what;
10601 	uint8_t port_num;
10602 	struct ether_addr mc_addr;
10603 };
10604 
10605 static void cmd_mcast_addr_parsed(void *parsed_result,
10606 		__attribute__((unused)) struct cmdline *cl,
10607 		__attribute__((unused)) void *data)
10608 {
10609 	struct cmd_mcast_addr_result *res = parsed_result;
10610 
10611 	if (!is_multicast_ether_addr(&res->mc_addr)) {
10612 		printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10613 		       res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10614 		       res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10615 		       res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10616 		return;
10617 	}
10618 	if (strcmp(res->what, "add") == 0)
10619 		mcast_addr_add(res->port_num, &res->mc_addr);
10620 	else
10621 		mcast_addr_remove(res->port_num, &res->mc_addr);
10622 }
10623 
10624 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10625 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10626 				 mcast_addr_cmd, "mcast_addr");
10627 cmdline_parse_token_string_t cmd_mcast_addr_what =
10628 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10629 				 "add#remove");
10630 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10631 	TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
10632 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10633 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10634 
10635 cmdline_parse_inst_t cmd_mcast_addr = {
10636 	.f = cmd_mcast_addr_parsed,
10637 	.data = (void *)0,
10638 	.help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10639 		"Add/Remove multicast MAC address on port_id",
10640 	.tokens = {
10641 		(void *)&cmd_mcast_addr_cmd,
10642 		(void *)&cmd_mcast_addr_what,
10643 		(void *)&cmd_mcast_addr_portnum,
10644 		(void *)&cmd_mcast_addr_addr,
10645 		NULL,
10646 	},
10647 };
10648 
10649 /* l2 tunnel config
10650  * only support E-tag now.
10651  */
10652 
10653 /* Ether type config */
10654 struct cmd_config_l2_tunnel_eth_type_result {
10655 	cmdline_fixed_string_t port;
10656 	cmdline_fixed_string_t config;
10657 	cmdline_fixed_string_t all;
10658 	uint8_t id;
10659 	cmdline_fixed_string_t l2_tunnel;
10660 	cmdline_fixed_string_t l2_tunnel_type;
10661 	cmdline_fixed_string_t eth_type;
10662 	uint16_t eth_type_val;
10663 };
10664 
10665 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10666 	TOKEN_STRING_INITIALIZER
10667 		(struct cmd_config_l2_tunnel_eth_type_result,
10668 		 port, "port");
10669 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10670 	TOKEN_STRING_INITIALIZER
10671 		(struct cmd_config_l2_tunnel_eth_type_result,
10672 		 config, "config");
10673 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10674 	TOKEN_STRING_INITIALIZER
10675 		(struct cmd_config_l2_tunnel_eth_type_result,
10676 		 all, "all");
10677 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10678 	TOKEN_NUM_INITIALIZER
10679 		(struct cmd_config_l2_tunnel_eth_type_result,
10680 		 id, UINT8);
10681 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10682 	TOKEN_STRING_INITIALIZER
10683 		(struct cmd_config_l2_tunnel_eth_type_result,
10684 		 l2_tunnel, "l2-tunnel");
10685 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10686 	TOKEN_STRING_INITIALIZER
10687 		(struct cmd_config_l2_tunnel_eth_type_result,
10688 		 l2_tunnel_type, "E-tag");
10689 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10690 	TOKEN_STRING_INITIALIZER
10691 		(struct cmd_config_l2_tunnel_eth_type_result,
10692 		 eth_type, "ether-type");
10693 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10694 	TOKEN_NUM_INITIALIZER
10695 		(struct cmd_config_l2_tunnel_eth_type_result,
10696 		 eth_type_val, UINT16);
10697 
10698 static enum rte_eth_tunnel_type
10699 str2fdir_l2_tunnel_type(char *string)
10700 {
10701 	uint32_t i = 0;
10702 
10703 	static const struct {
10704 		char str[32];
10705 		enum rte_eth_tunnel_type type;
10706 	} l2_tunnel_type_str[] = {
10707 		{"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10708 	};
10709 
10710 	for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10711 		if (!strcmp(l2_tunnel_type_str[i].str, string))
10712 			return l2_tunnel_type_str[i].type;
10713 	}
10714 	return RTE_TUNNEL_TYPE_NONE;
10715 }
10716 
10717 /* ether type config for all ports */
10718 static void
10719 cmd_config_l2_tunnel_eth_type_all_parsed
10720 	(void *parsed_result,
10721 	 __attribute__((unused)) struct cmdline *cl,
10722 	 __attribute__((unused)) void *data)
10723 {
10724 	struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10725 	struct rte_eth_l2_tunnel_conf entry;
10726 	portid_t pid;
10727 
10728 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10729 	entry.ether_type = res->eth_type_val;
10730 
10731 	RTE_ETH_FOREACH_DEV(pid) {
10732 		rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10733 	}
10734 }
10735 
10736 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10737 	.f = cmd_config_l2_tunnel_eth_type_all_parsed,
10738 	.data = NULL,
10739 	.help_str = "port config all l2-tunnel E-tag ether-type <value>",
10740 	.tokens = {
10741 		(void *)&cmd_config_l2_tunnel_eth_type_port,
10742 		(void *)&cmd_config_l2_tunnel_eth_type_config,
10743 		(void *)&cmd_config_l2_tunnel_eth_type_all_str,
10744 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10745 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10746 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10747 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10748 		NULL,
10749 	},
10750 };
10751 
10752 /* ether type config for a specific port */
10753 static void
10754 cmd_config_l2_tunnel_eth_type_specific_parsed(
10755 	void *parsed_result,
10756 	__attribute__((unused)) struct cmdline *cl,
10757 	__attribute__((unused)) void *data)
10758 {
10759 	struct cmd_config_l2_tunnel_eth_type_result *res =
10760 		 parsed_result;
10761 	struct rte_eth_l2_tunnel_conf entry;
10762 
10763 	if (port_id_is_invalid(res->id, ENABLED_WARN))
10764 		return;
10765 
10766 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10767 	entry.ether_type = res->eth_type_val;
10768 
10769 	rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10770 }
10771 
10772 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10773 	.f = cmd_config_l2_tunnel_eth_type_specific_parsed,
10774 	.data = NULL,
10775 	.help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
10776 	.tokens = {
10777 		(void *)&cmd_config_l2_tunnel_eth_type_port,
10778 		(void *)&cmd_config_l2_tunnel_eth_type_config,
10779 		(void *)&cmd_config_l2_tunnel_eth_type_id,
10780 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10781 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10782 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10783 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10784 		NULL,
10785 	},
10786 };
10787 
10788 /* Enable/disable l2 tunnel */
10789 struct cmd_config_l2_tunnel_en_dis_result {
10790 	cmdline_fixed_string_t port;
10791 	cmdline_fixed_string_t config;
10792 	cmdline_fixed_string_t all;
10793 	uint8_t id;
10794 	cmdline_fixed_string_t l2_tunnel;
10795 	cmdline_fixed_string_t l2_tunnel_type;
10796 	cmdline_fixed_string_t en_dis;
10797 };
10798 
10799 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
10800 	TOKEN_STRING_INITIALIZER
10801 		(struct cmd_config_l2_tunnel_en_dis_result,
10802 		 port, "port");
10803 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
10804 	TOKEN_STRING_INITIALIZER
10805 		(struct cmd_config_l2_tunnel_en_dis_result,
10806 		 config, "config");
10807 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
10808 	TOKEN_STRING_INITIALIZER
10809 		(struct cmd_config_l2_tunnel_en_dis_result,
10810 		 all, "all");
10811 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
10812 	TOKEN_NUM_INITIALIZER
10813 		(struct cmd_config_l2_tunnel_en_dis_result,
10814 		 id, UINT8);
10815 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
10816 	TOKEN_STRING_INITIALIZER
10817 		(struct cmd_config_l2_tunnel_en_dis_result,
10818 		 l2_tunnel, "l2-tunnel");
10819 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
10820 	TOKEN_STRING_INITIALIZER
10821 		(struct cmd_config_l2_tunnel_en_dis_result,
10822 		 l2_tunnel_type, "E-tag");
10823 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
10824 	TOKEN_STRING_INITIALIZER
10825 		(struct cmd_config_l2_tunnel_en_dis_result,
10826 		 en_dis, "enable#disable");
10827 
10828 /* enable/disable l2 tunnel for all ports */
10829 static void
10830 cmd_config_l2_tunnel_en_dis_all_parsed(
10831 	void *parsed_result,
10832 	__attribute__((unused)) struct cmdline *cl,
10833 	__attribute__((unused)) void *data)
10834 {
10835 	struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
10836 	struct rte_eth_l2_tunnel_conf entry;
10837 	portid_t pid;
10838 	uint8_t en;
10839 
10840 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10841 
10842 	if (!strcmp("enable", res->en_dis))
10843 		en = 1;
10844 	else
10845 		en = 0;
10846 
10847 	RTE_ETH_FOREACH_DEV(pid) {
10848 		rte_eth_dev_l2_tunnel_offload_set(pid,
10849 						  &entry,
10850 						  ETH_L2_TUNNEL_ENABLE_MASK,
10851 						  en);
10852 	}
10853 }
10854 
10855 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
10856 	.f = cmd_config_l2_tunnel_en_dis_all_parsed,
10857 	.data = NULL,
10858 	.help_str = "port config all l2-tunnel E-tag enable|disable",
10859 	.tokens = {
10860 		(void *)&cmd_config_l2_tunnel_en_dis_port,
10861 		(void *)&cmd_config_l2_tunnel_en_dis_config,
10862 		(void *)&cmd_config_l2_tunnel_en_dis_all_str,
10863 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10864 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10865 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10866 		NULL,
10867 	},
10868 };
10869 
10870 /* enable/disable l2 tunnel for a port */
10871 static void
10872 cmd_config_l2_tunnel_en_dis_specific_parsed(
10873 	void *parsed_result,
10874 	__attribute__((unused)) struct cmdline *cl,
10875 	__attribute__((unused)) void *data)
10876 {
10877 	struct cmd_config_l2_tunnel_en_dis_result *res =
10878 		parsed_result;
10879 	struct rte_eth_l2_tunnel_conf entry;
10880 
10881 	if (port_id_is_invalid(res->id, ENABLED_WARN))
10882 		return;
10883 
10884 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10885 
10886 	if (!strcmp("enable", res->en_dis))
10887 		rte_eth_dev_l2_tunnel_offload_set(res->id,
10888 						  &entry,
10889 						  ETH_L2_TUNNEL_ENABLE_MASK,
10890 						  1);
10891 	else
10892 		rte_eth_dev_l2_tunnel_offload_set(res->id,
10893 						  &entry,
10894 						  ETH_L2_TUNNEL_ENABLE_MASK,
10895 						  0);
10896 }
10897 
10898 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
10899 	.f = cmd_config_l2_tunnel_en_dis_specific_parsed,
10900 	.data = NULL,
10901 	.help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
10902 	.tokens = {
10903 		(void *)&cmd_config_l2_tunnel_en_dis_port,
10904 		(void *)&cmd_config_l2_tunnel_en_dis_config,
10905 		(void *)&cmd_config_l2_tunnel_en_dis_id,
10906 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10907 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10908 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10909 		NULL,
10910 	},
10911 };
10912 
10913 /* E-tag configuration */
10914 
10915 /* Common result structure for all E-tag configuration */
10916 struct cmd_config_e_tag_result {
10917 	cmdline_fixed_string_t e_tag;
10918 	cmdline_fixed_string_t set;
10919 	cmdline_fixed_string_t insertion;
10920 	cmdline_fixed_string_t stripping;
10921 	cmdline_fixed_string_t forwarding;
10922 	cmdline_fixed_string_t filter;
10923 	cmdline_fixed_string_t add;
10924 	cmdline_fixed_string_t del;
10925 	cmdline_fixed_string_t on;
10926 	cmdline_fixed_string_t off;
10927 	cmdline_fixed_string_t on_off;
10928 	cmdline_fixed_string_t port_tag_id;
10929 	uint32_t port_tag_id_val;
10930 	cmdline_fixed_string_t e_tag_id;
10931 	uint16_t e_tag_id_val;
10932 	cmdline_fixed_string_t dst_pool;
10933 	uint8_t dst_pool_val;
10934 	cmdline_fixed_string_t port;
10935 	uint8_t port_id;
10936 	cmdline_fixed_string_t vf;
10937 	uint8_t vf_id;
10938 };
10939 
10940 /* Common CLI fields for all E-tag configuration */
10941 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
10942 	TOKEN_STRING_INITIALIZER
10943 		(struct cmd_config_e_tag_result,
10944 		 e_tag, "E-tag");
10945 cmdline_parse_token_string_t cmd_config_e_tag_set =
10946 	TOKEN_STRING_INITIALIZER
10947 		(struct cmd_config_e_tag_result,
10948 		 set, "set");
10949 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
10950 	TOKEN_STRING_INITIALIZER
10951 		(struct cmd_config_e_tag_result,
10952 		 insertion, "insertion");
10953 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
10954 	TOKEN_STRING_INITIALIZER
10955 		(struct cmd_config_e_tag_result,
10956 		 stripping, "stripping");
10957 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
10958 	TOKEN_STRING_INITIALIZER
10959 		(struct cmd_config_e_tag_result,
10960 		 forwarding, "forwarding");
10961 cmdline_parse_token_string_t cmd_config_e_tag_filter =
10962 	TOKEN_STRING_INITIALIZER
10963 		(struct cmd_config_e_tag_result,
10964 		 filter, "filter");
10965 cmdline_parse_token_string_t cmd_config_e_tag_add =
10966 	TOKEN_STRING_INITIALIZER
10967 		(struct cmd_config_e_tag_result,
10968 		 add, "add");
10969 cmdline_parse_token_string_t cmd_config_e_tag_del =
10970 	TOKEN_STRING_INITIALIZER
10971 		(struct cmd_config_e_tag_result,
10972 		 del, "del");
10973 cmdline_parse_token_string_t cmd_config_e_tag_on =
10974 	TOKEN_STRING_INITIALIZER
10975 		(struct cmd_config_e_tag_result,
10976 		 on, "on");
10977 cmdline_parse_token_string_t cmd_config_e_tag_off =
10978 	TOKEN_STRING_INITIALIZER
10979 		(struct cmd_config_e_tag_result,
10980 		 off, "off");
10981 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
10982 	TOKEN_STRING_INITIALIZER
10983 		(struct cmd_config_e_tag_result,
10984 		 on_off, "on#off");
10985 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
10986 	TOKEN_STRING_INITIALIZER
10987 		(struct cmd_config_e_tag_result,
10988 		 port_tag_id, "port-tag-id");
10989 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
10990 	TOKEN_NUM_INITIALIZER
10991 		(struct cmd_config_e_tag_result,
10992 		 port_tag_id_val, UINT32);
10993 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
10994 	TOKEN_STRING_INITIALIZER
10995 		(struct cmd_config_e_tag_result,
10996 		 e_tag_id, "e-tag-id");
10997 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
10998 	TOKEN_NUM_INITIALIZER
10999 		(struct cmd_config_e_tag_result,
11000 		 e_tag_id_val, UINT16);
11001 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11002 	TOKEN_STRING_INITIALIZER
11003 		(struct cmd_config_e_tag_result,
11004 		 dst_pool, "dst-pool");
11005 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11006 	TOKEN_NUM_INITIALIZER
11007 		(struct cmd_config_e_tag_result,
11008 		 dst_pool_val, UINT8);
11009 cmdline_parse_token_string_t cmd_config_e_tag_port =
11010 	TOKEN_STRING_INITIALIZER
11011 		(struct cmd_config_e_tag_result,
11012 		 port, "port");
11013 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11014 	TOKEN_NUM_INITIALIZER
11015 		(struct cmd_config_e_tag_result,
11016 		 port_id, UINT8);
11017 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11018 	TOKEN_STRING_INITIALIZER
11019 		(struct cmd_config_e_tag_result,
11020 		 vf, "vf");
11021 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11022 	TOKEN_NUM_INITIALIZER
11023 		(struct cmd_config_e_tag_result,
11024 		 vf_id, UINT8);
11025 
11026 /* E-tag insertion configuration */
11027 static void
11028 cmd_config_e_tag_insertion_en_parsed(
11029 	void *parsed_result,
11030 	__attribute__((unused)) struct cmdline *cl,
11031 	__attribute__((unused)) void *data)
11032 {
11033 	struct cmd_config_e_tag_result *res =
11034 		parsed_result;
11035 	struct rte_eth_l2_tunnel_conf entry;
11036 
11037 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11038 		return;
11039 
11040 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11041 	entry.tunnel_id = res->port_tag_id_val;
11042 	entry.vf_id = res->vf_id;
11043 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11044 					  &entry,
11045 					  ETH_L2_TUNNEL_INSERTION_MASK,
11046 					  1);
11047 }
11048 
11049 static void
11050 cmd_config_e_tag_insertion_dis_parsed(
11051 	void *parsed_result,
11052 	__attribute__((unused)) struct cmdline *cl,
11053 	__attribute__((unused)) void *data)
11054 {
11055 	struct cmd_config_e_tag_result *res =
11056 		parsed_result;
11057 	struct rte_eth_l2_tunnel_conf entry;
11058 
11059 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11060 		return;
11061 
11062 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11063 	entry.vf_id = res->vf_id;
11064 
11065 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11066 					  &entry,
11067 					  ETH_L2_TUNNEL_INSERTION_MASK,
11068 					  0);
11069 }
11070 
11071 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11072 	.f = cmd_config_e_tag_insertion_en_parsed,
11073 	.data = NULL,
11074 	.help_str = "E-tag ... : E-tag insertion enable",
11075 	.tokens = {
11076 		(void *)&cmd_config_e_tag_e_tag,
11077 		(void *)&cmd_config_e_tag_set,
11078 		(void *)&cmd_config_e_tag_insertion,
11079 		(void *)&cmd_config_e_tag_on,
11080 		(void *)&cmd_config_e_tag_port_tag_id,
11081 		(void *)&cmd_config_e_tag_port_tag_id_val,
11082 		(void *)&cmd_config_e_tag_port,
11083 		(void *)&cmd_config_e_tag_port_id,
11084 		(void *)&cmd_config_e_tag_vf,
11085 		(void *)&cmd_config_e_tag_vf_id,
11086 		NULL,
11087 	},
11088 };
11089 
11090 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11091 	.f = cmd_config_e_tag_insertion_dis_parsed,
11092 	.data = NULL,
11093 	.help_str = "E-tag ... : E-tag insertion disable",
11094 	.tokens = {
11095 		(void *)&cmd_config_e_tag_e_tag,
11096 		(void *)&cmd_config_e_tag_set,
11097 		(void *)&cmd_config_e_tag_insertion,
11098 		(void *)&cmd_config_e_tag_off,
11099 		(void *)&cmd_config_e_tag_port,
11100 		(void *)&cmd_config_e_tag_port_id,
11101 		(void *)&cmd_config_e_tag_vf,
11102 		(void *)&cmd_config_e_tag_vf_id,
11103 		NULL,
11104 	},
11105 };
11106 
11107 /* E-tag stripping configuration */
11108 static void
11109 cmd_config_e_tag_stripping_parsed(
11110 	void *parsed_result,
11111 	__attribute__((unused)) struct cmdline *cl,
11112 	__attribute__((unused)) void *data)
11113 {
11114 	struct cmd_config_e_tag_result *res =
11115 		parsed_result;
11116 	struct rte_eth_l2_tunnel_conf entry;
11117 
11118 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11119 		return;
11120 
11121 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11122 
11123 	if (!strcmp(res->on_off, "on"))
11124 		rte_eth_dev_l2_tunnel_offload_set
11125 			(res->port_id,
11126 			 &entry,
11127 			 ETH_L2_TUNNEL_STRIPPING_MASK,
11128 			 1);
11129 	else
11130 		rte_eth_dev_l2_tunnel_offload_set
11131 			(res->port_id,
11132 			 &entry,
11133 			 ETH_L2_TUNNEL_STRIPPING_MASK,
11134 			 0);
11135 }
11136 
11137 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11138 	.f = cmd_config_e_tag_stripping_parsed,
11139 	.data = NULL,
11140 	.help_str = "E-tag ... : E-tag stripping enable/disable",
11141 	.tokens = {
11142 		(void *)&cmd_config_e_tag_e_tag,
11143 		(void *)&cmd_config_e_tag_set,
11144 		(void *)&cmd_config_e_tag_stripping,
11145 		(void *)&cmd_config_e_tag_on_off,
11146 		(void *)&cmd_config_e_tag_port,
11147 		(void *)&cmd_config_e_tag_port_id,
11148 		NULL,
11149 	},
11150 };
11151 
11152 /* E-tag forwarding configuration */
11153 static void
11154 cmd_config_e_tag_forwarding_parsed(
11155 	void *parsed_result,
11156 	__attribute__((unused)) struct cmdline *cl,
11157 	__attribute__((unused)) void *data)
11158 {
11159 	struct cmd_config_e_tag_result *res = parsed_result;
11160 	struct rte_eth_l2_tunnel_conf entry;
11161 
11162 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11163 		return;
11164 
11165 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11166 
11167 	if (!strcmp(res->on_off, "on"))
11168 		rte_eth_dev_l2_tunnel_offload_set
11169 			(res->port_id,
11170 			 &entry,
11171 			 ETH_L2_TUNNEL_FORWARDING_MASK,
11172 			 1);
11173 	else
11174 		rte_eth_dev_l2_tunnel_offload_set
11175 			(res->port_id,
11176 			 &entry,
11177 			 ETH_L2_TUNNEL_FORWARDING_MASK,
11178 			 0);
11179 }
11180 
11181 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11182 	.f = cmd_config_e_tag_forwarding_parsed,
11183 	.data = NULL,
11184 	.help_str = "E-tag ... : E-tag forwarding enable/disable",
11185 	.tokens = {
11186 		(void *)&cmd_config_e_tag_e_tag,
11187 		(void *)&cmd_config_e_tag_set,
11188 		(void *)&cmd_config_e_tag_forwarding,
11189 		(void *)&cmd_config_e_tag_on_off,
11190 		(void *)&cmd_config_e_tag_port,
11191 		(void *)&cmd_config_e_tag_port_id,
11192 		NULL,
11193 	},
11194 };
11195 
11196 /* E-tag filter configuration */
11197 static void
11198 cmd_config_e_tag_filter_add_parsed(
11199 	void *parsed_result,
11200 	__attribute__((unused)) struct cmdline *cl,
11201 	__attribute__((unused)) void *data)
11202 {
11203 	struct cmd_config_e_tag_result *res = parsed_result;
11204 	struct rte_eth_l2_tunnel_conf entry;
11205 	int ret = 0;
11206 
11207 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11208 		return;
11209 
11210 	if (res->e_tag_id_val > 0x3fff) {
11211 		printf("e-tag-id must be equal or less than 0x3fff.\n");
11212 		return;
11213 	}
11214 
11215 	ret = rte_eth_dev_filter_supported(res->port_id,
11216 					   RTE_ETH_FILTER_L2_TUNNEL);
11217 	if (ret < 0) {
11218 		printf("E-tag filter is not supported on port %u.\n",
11219 		       res->port_id);
11220 		return;
11221 	}
11222 
11223 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11224 	entry.tunnel_id = res->e_tag_id_val;
11225 	entry.pool = res->dst_pool_val;
11226 
11227 	ret = rte_eth_dev_filter_ctrl(res->port_id,
11228 				      RTE_ETH_FILTER_L2_TUNNEL,
11229 				      RTE_ETH_FILTER_ADD,
11230 				      &entry);
11231 	if (ret < 0)
11232 		printf("E-tag filter programming error: (%s)\n",
11233 		       strerror(-ret));
11234 }
11235 
11236 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
11237 	.f = cmd_config_e_tag_filter_add_parsed,
11238 	.data = NULL,
11239 	.help_str = "E-tag ... : E-tag filter add",
11240 	.tokens = {
11241 		(void *)&cmd_config_e_tag_e_tag,
11242 		(void *)&cmd_config_e_tag_set,
11243 		(void *)&cmd_config_e_tag_filter,
11244 		(void *)&cmd_config_e_tag_add,
11245 		(void *)&cmd_config_e_tag_e_tag_id,
11246 		(void *)&cmd_config_e_tag_e_tag_id_val,
11247 		(void *)&cmd_config_e_tag_dst_pool,
11248 		(void *)&cmd_config_e_tag_dst_pool_val,
11249 		(void *)&cmd_config_e_tag_port,
11250 		(void *)&cmd_config_e_tag_port_id,
11251 		NULL,
11252 	},
11253 };
11254 
11255 static void
11256 cmd_config_e_tag_filter_del_parsed(
11257 	void *parsed_result,
11258 	__attribute__((unused)) struct cmdline *cl,
11259 	__attribute__((unused)) void *data)
11260 {
11261 	struct cmd_config_e_tag_result *res = parsed_result;
11262 	struct rte_eth_l2_tunnel_conf entry;
11263 	int ret = 0;
11264 
11265 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11266 		return;
11267 
11268 	if (res->e_tag_id_val > 0x3fff) {
11269 		printf("e-tag-id must be less than 0x3fff.\n");
11270 		return;
11271 	}
11272 
11273 	ret = rte_eth_dev_filter_supported(res->port_id,
11274 					   RTE_ETH_FILTER_L2_TUNNEL);
11275 	if (ret < 0) {
11276 		printf("E-tag filter is not supported on port %u.\n",
11277 		       res->port_id);
11278 		return;
11279 	}
11280 
11281 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11282 	entry.tunnel_id = res->e_tag_id_val;
11283 
11284 	ret = rte_eth_dev_filter_ctrl(res->port_id,
11285 				      RTE_ETH_FILTER_L2_TUNNEL,
11286 				      RTE_ETH_FILTER_DELETE,
11287 				      &entry);
11288 	if (ret < 0)
11289 		printf("E-tag filter programming error: (%s)\n",
11290 		       strerror(-ret));
11291 }
11292 
11293 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
11294 	.f = cmd_config_e_tag_filter_del_parsed,
11295 	.data = NULL,
11296 	.help_str = "E-tag ... : E-tag filter delete",
11297 	.tokens = {
11298 		(void *)&cmd_config_e_tag_e_tag,
11299 		(void *)&cmd_config_e_tag_set,
11300 		(void *)&cmd_config_e_tag_filter,
11301 		(void *)&cmd_config_e_tag_del,
11302 		(void *)&cmd_config_e_tag_e_tag_id,
11303 		(void *)&cmd_config_e_tag_e_tag_id_val,
11304 		(void *)&cmd_config_e_tag_port,
11305 		(void *)&cmd_config_e_tag_port_id,
11306 		NULL,
11307 	},
11308 };
11309 
11310 /* vf vlan anti spoof configuration */
11311 
11312 /* Common result structure for vf vlan anti spoof */
11313 struct cmd_vf_vlan_anti_spoof_result {
11314 	cmdline_fixed_string_t set;
11315 	cmdline_fixed_string_t vf;
11316 	cmdline_fixed_string_t vlan;
11317 	cmdline_fixed_string_t antispoof;
11318 	uint8_t port_id;
11319 	uint32_t vf_id;
11320 	cmdline_fixed_string_t on_off;
11321 };
11322 
11323 /* Common CLI fields for vf vlan anti spoof enable disable */
11324 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11325 	TOKEN_STRING_INITIALIZER
11326 		(struct cmd_vf_vlan_anti_spoof_result,
11327 		 set, "set");
11328 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11329 	TOKEN_STRING_INITIALIZER
11330 		(struct cmd_vf_vlan_anti_spoof_result,
11331 		 vf, "vf");
11332 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11333 	TOKEN_STRING_INITIALIZER
11334 		(struct cmd_vf_vlan_anti_spoof_result,
11335 		 vlan, "vlan");
11336 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11337 	TOKEN_STRING_INITIALIZER
11338 		(struct cmd_vf_vlan_anti_spoof_result,
11339 		 antispoof, "antispoof");
11340 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11341 	TOKEN_NUM_INITIALIZER
11342 		(struct cmd_vf_vlan_anti_spoof_result,
11343 		 port_id, UINT8);
11344 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11345 	TOKEN_NUM_INITIALIZER
11346 		(struct cmd_vf_vlan_anti_spoof_result,
11347 		 vf_id, UINT32);
11348 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11349 	TOKEN_STRING_INITIALIZER
11350 		(struct cmd_vf_vlan_anti_spoof_result,
11351 		 on_off, "on#off");
11352 
11353 static void
11354 cmd_set_vf_vlan_anti_spoof_parsed(
11355 	void *parsed_result,
11356 	__attribute__((unused)) struct cmdline *cl,
11357 	__attribute__((unused)) void *data)
11358 {
11359 	struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11360 	int ret = -ENOTSUP;
11361 
11362 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11363 
11364 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11365 		return;
11366 
11367 #ifdef RTE_LIBRTE_IXGBE_PMD
11368 	if (ret == -ENOTSUP)
11369 		ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11370 				res->vf_id, is_on);
11371 #endif
11372 #ifdef RTE_LIBRTE_I40E_PMD
11373 	if (ret == -ENOTSUP)
11374 		ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11375 				res->vf_id, is_on);
11376 #endif
11377 #ifdef RTE_LIBRTE_BNXT_PMD
11378 	if (ret == -ENOTSUP)
11379 		ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11380 				res->vf_id, is_on);
11381 #endif
11382 
11383 	switch (ret) {
11384 	case 0:
11385 		break;
11386 	case -EINVAL:
11387 		printf("invalid vf_id %d\n", res->vf_id);
11388 		break;
11389 	case -ENODEV:
11390 		printf("invalid port_id %d\n", res->port_id);
11391 		break;
11392 	case -ENOTSUP:
11393 		printf("function not implemented\n");
11394 		break;
11395 	default:
11396 		printf("programming error: (%s)\n", strerror(-ret));
11397 	}
11398 }
11399 
11400 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11401 	.f = cmd_set_vf_vlan_anti_spoof_parsed,
11402 	.data = NULL,
11403 	.help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11404 	.tokens = {
11405 		(void *)&cmd_vf_vlan_anti_spoof_set,
11406 		(void *)&cmd_vf_vlan_anti_spoof_vf,
11407 		(void *)&cmd_vf_vlan_anti_spoof_vlan,
11408 		(void *)&cmd_vf_vlan_anti_spoof_antispoof,
11409 		(void *)&cmd_vf_vlan_anti_spoof_port_id,
11410 		(void *)&cmd_vf_vlan_anti_spoof_vf_id,
11411 		(void *)&cmd_vf_vlan_anti_spoof_on_off,
11412 		NULL,
11413 	},
11414 };
11415 
11416 /* vf mac anti spoof configuration */
11417 
11418 /* Common result structure for vf mac anti spoof */
11419 struct cmd_vf_mac_anti_spoof_result {
11420 	cmdline_fixed_string_t set;
11421 	cmdline_fixed_string_t vf;
11422 	cmdline_fixed_string_t mac;
11423 	cmdline_fixed_string_t antispoof;
11424 	uint8_t port_id;
11425 	uint32_t vf_id;
11426 	cmdline_fixed_string_t on_off;
11427 };
11428 
11429 /* Common CLI fields for vf mac anti spoof enable disable */
11430 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11431 	TOKEN_STRING_INITIALIZER
11432 		(struct cmd_vf_mac_anti_spoof_result,
11433 		 set, "set");
11434 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11435 	TOKEN_STRING_INITIALIZER
11436 		(struct cmd_vf_mac_anti_spoof_result,
11437 		 vf, "vf");
11438 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11439 	TOKEN_STRING_INITIALIZER
11440 		(struct cmd_vf_mac_anti_spoof_result,
11441 		 mac, "mac");
11442 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11443 	TOKEN_STRING_INITIALIZER
11444 		(struct cmd_vf_mac_anti_spoof_result,
11445 		 antispoof, "antispoof");
11446 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11447 	TOKEN_NUM_INITIALIZER
11448 		(struct cmd_vf_mac_anti_spoof_result,
11449 		 port_id, UINT8);
11450 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11451 	TOKEN_NUM_INITIALIZER
11452 		(struct cmd_vf_mac_anti_spoof_result,
11453 		 vf_id, UINT32);
11454 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11455 	TOKEN_STRING_INITIALIZER
11456 		(struct cmd_vf_mac_anti_spoof_result,
11457 		 on_off, "on#off");
11458 
11459 static void
11460 cmd_set_vf_mac_anti_spoof_parsed(
11461 	void *parsed_result,
11462 	__attribute__((unused)) struct cmdline *cl,
11463 	__attribute__((unused)) void *data)
11464 {
11465 	struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11466 	int ret = -ENOTSUP;
11467 
11468 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11469 
11470 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11471 		return;
11472 
11473 #ifdef RTE_LIBRTE_IXGBE_PMD
11474 	if (ret == -ENOTSUP)
11475 		ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11476 			res->vf_id, is_on);
11477 #endif
11478 #ifdef RTE_LIBRTE_I40E_PMD
11479 	if (ret == -ENOTSUP)
11480 		ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11481 			res->vf_id, is_on);
11482 #endif
11483 #ifdef RTE_LIBRTE_BNXT_PMD
11484 	if (ret == -ENOTSUP)
11485 		ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11486 			res->vf_id, is_on);
11487 #endif
11488 
11489 	switch (ret) {
11490 	case 0:
11491 		break;
11492 	case -EINVAL:
11493 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11494 		break;
11495 	case -ENODEV:
11496 		printf("invalid port_id %d\n", res->port_id);
11497 		break;
11498 	case -ENOTSUP:
11499 		printf("function not implemented\n");
11500 		break;
11501 	default:
11502 		printf("programming error: (%s)\n", strerror(-ret));
11503 	}
11504 }
11505 
11506 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11507 	.f = cmd_set_vf_mac_anti_spoof_parsed,
11508 	.data = NULL,
11509 	.help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11510 	.tokens = {
11511 		(void *)&cmd_vf_mac_anti_spoof_set,
11512 		(void *)&cmd_vf_mac_anti_spoof_vf,
11513 		(void *)&cmd_vf_mac_anti_spoof_mac,
11514 		(void *)&cmd_vf_mac_anti_spoof_antispoof,
11515 		(void *)&cmd_vf_mac_anti_spoof_port_id,
11516 		(void *)&cmd_vf_mac_anti_spoof_vf_id,
11517 		(void *)&cmd_vf_mac_anti_spoof_on_off,
11518 		NULL,
11519 	},
11520 };
11521 
11522 /* vf vlan strip queue configuration */
11523 
11524 /* Common result structure for vf mac anti spoof */
11525 struct cmd_vf_vlan_stripq_result {
11526 	cmdline_fixed_string_t set;
11527 	cmdline_fixed_string_t vf;
11528 	cmdline_fixed_string_t vlan;
11529 	cmdline_fixed_string_t stripq;
11530 	portid_t port_id;
11531 	uint16_t vf_id;
11532 	cmdline_fixed_string_t on_off;
11533 };
11534 
11535 /* Common CLI fields for vf vlan strip enable disable */
11536 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11537 	TOKEN_STRING_INITIALIZER
11538 		(struct cmd_vf_vlan_stripq_result,
11539 		 set, "set");
11540 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11541 	TOKEN_STRING_INITIALIZER
11542 		(struct cmd_vf_vlan_stripq_result,
11543 		 vf, "vf");
11544 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11545 	TOKEN_STRING_INITIALIZER
11546 		(struct cmd_vf_vlan_stripq_result,
11547 		 vlan, "vlan");
11548 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11549 	TOKEN_STRING_INITIALIZER
11550 		(struct cmd_vf_vlan_stripq_result,
11551 		 stripq, "stripq");
11552 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11553 	TOKEN_NUM_INITIALIZER
11554 		(struct cmd_vf_vlan_stripq_result,
11555 		 port_id, UINT8);
11556 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11557 	TOKEN_NUM_INITIALIZER
11558 		(struct cmd_vf_vlan_stripq_result,
11559 		 vf_id, UINT16);
11560 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11561 	TOKEN_STRING_INITIALIZER
11562 		(struct cmd_vf_vlan_stripq_result,
11563 		 on_off, "on#off");
11564 
11565 static void
11566 cmd_set_vf_vlan_stripq_parsed(
11567 	void *parsed_result,
11568 	__attribute__((unused)) struct cmdline *cl,
11569 	__attribute__((unused)) void *data)
11570 {
11571 	struct cmd_vf_vlan_stripq_result *res = parsed_result;
11572 	int ret = -ENOTSUP;
11573 
11574 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11575 
11576 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11577 		return;
11578 
11579 #ifdef RTE_LIBRTE_IXGBE_PMD
11580 	if (ret == -ENOTSUP)
11581 		ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11582 			res->vf_id, is_on);
11583 #endif
11584 #ifdef RTE_LIBRTE_I40E_PMD
11585 	if (ret == -ENOTSUP)
11586 		ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11587 			res->vf_id, is_on);
11588 #endif
11589 #ifdef RTE_LIBRTE_BNXT_PMD
11590 	if (ret == -ENOTSUP)
11591 		ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11592 			res->vf_id, is_on);
11593 #endif
11594 
11595 	switch (ret) {
11596 	case 0:
11597 		break;
11598 	case -EINVAL:
11599 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11600 		break;
11601 	case -ENODEV:
11602 		printf("invalid port_id %d\n", res->port_id);
11603 		break;
11604 	case -ENOTSUP:
11605 		printf("function not implemented\n");
11606 		break;
11607 	default:
11608 		printf("programming error: (%s)\n", strerror(-ret));
11609 	}
11610 }
11611 
11612 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11613 	.f = cmd_set_vf_vlan_stripq_parsed,
11614 	.data = NULL,
11615 	.help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11616 	.tokens = {
11617 		(void *)&cmd_vf_vlan_stripq_set,
11618 		(void *)&cmd_vf_vlan_stripq_vf,
11619 		(void *)&cmd_vf_vlan_stripq_vlan,
11620 		(void *)&cmd_vf_vlan_stripq_stripq,
11621 		(void *)&cmd_vf_vlan_stripq_port_id,
11622 		(void *)&cmd_vf_vlan_stripq_vf_id,
11623 		(void *)&cmd_vf_vlan_stripq_on_off,
11624 		NULL,
11625 	},
11626 };
11627 
11628 /* vf vlan insert configuration */
11629 
11630 /* Common result structure for vf vlan insert */
11631 struct cmd_vf_vlan_insert_result {
11632 	cmdline_fixed_string_t set;
11633 	cmdline_fixed_string_t vf;
11634 	cmdline_fixed_string_t vlan;
11635 	cmdline_fixed_string_t insert;
11636 	uint8_t port_id;
11637 	uint16_t vf_id;
11638 	uint16_t vlan_id;
11639 };
11640 
11641 /* Common CLI fields for vf vlan insert enable disable */
11642 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11643 	TOKEN_STRING_INITIALIZER
11644 		(struct cmd_vf_vlan_insert_result,
11645 		 set, "set");
11646 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11647 	TOKEN_STRING_INITIALIZER
11648 		(struct cmd_vf_vlan_insert_result,
11649 		 vf, "vf");
11650 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11651 	TOKEN_STRING_INITIALIZER
11652 		(struct cmd_vf_vlan_insert_result,
11653 		 vlan, "vlan");
11654 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11655 	TOKEN_STRING_INITIALIZER
11656 		(struct cmd_vf_vlan_insert_result,
11657 		 insert, "insert");
11658 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11659 	TOKEN_NUM_INITIALIZER
11660 		(struct cmd_vf_vlan_insert_result,
11661 		 port_id, UINT8);
11662 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11663 	TOKEN_NUM_INITIALIZER
11664 		(struct cmd_vf_vlan_insert_result,
11665 		 vf_id, UINT16);
11666 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11667 	TOKEN_NUM_INITIALIZER
11668 		(struct cmd_vf_vlan_insert_result,
11669 		 vlan_id, UINT16);
11670 
11671 static void
11672 cmd_set_vf_vlan_insert_parsed(
11673 	void *parsed_result,
11674 	__attribute__((unused)) struct cmdline *cl,
11675 	__attribute__((unused)) void *data)
11676 {
11677 	struct cmd_vf_vlan_insert_result *res = parsed_result;
11678 	int ret = -ENOTSUP;
11679 
11680 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11681 		return;
11682 
11683 #ifdef RTE_LIBRTE_IXGBE_PMD
11684 	if (ret == -ENOTSUP)
11685 		ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11686 			res->vlan_id);
11687 #endif
11688 #ifdef RTE_LIBRTE_I40E_PMD
11689 	if (ret == -ENOTSUP)
11690 		ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11691 			res->vlan_id);
11692 #endif
11693 #ifdef RTE_LIBRTE_BNXT_PMD
11694 	if (ret == -ENOTSUP)
11695 		ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11696 			res->vlan_id);
11697 #endif
11698 
11699 	switch (ret) {
11700 	case 0:
11701 		break;
11702 	case -EINVAL:
11703 		printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11704 		break;
11705 	case -ENODEV:
11706 		printf("invalid port_id %d\n", res->port_id);
11707 		break;
11708 	case -ENOTSUP:
11709 		printf("function not implemented\n");
11710 		break;
11711 	default:
11712 		printf("programming error: (%s)\n", strerror(-ret));
11713 	}
11714 }
11715 
11716 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11717 	.f = cmd_set_vf_vlan_insert_parsed,
11718 	.data = NULL,
11719 	.help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11720 	.tokens = {
11721 		(void *)&cmd_vf_vlan_insert_set,
11722 		(void *)&cmd_vf_vlan_insert_vf,
11723 		(void *)&cmd_vf_vlan_insert_vlan,
11724 		(void *)&cmd_vf_vlan_insert_insert,
11725 		(void *)&cmd_vf_vlan_insert_port_id,
11726 		(void *)&cmd_vf_vlan_insert_vf_id,
11727 		(void *)&cmd_vf_vlan_insert_vlan_id,
11728 		NULL,
11729 	},
11730 };
11731 
11732 /* tx loopback configuration */
11733 
11734 /* Common result structure for tx loopback */
11735 struct cmd_tx_loopback_result {
11736 	cmdline_fixed_string_t set;
11737 	cmdline_fixed_string_t tx;
11738 	cmdline_fixed_string_t loopback;
11739 	uint8_t port_id;
11740 	cmdline_fixed_string_t on_off;
11741 };
11742 
11743 /* Common CLI fields for tx loopback enable disable */
11744 cmdline_parse_token_string_t cmd_tx_loopback_set =
11745 	TOKEN_STRING_INITIALIZER
11746 		(struct cmd_tx_loopback_result,
11747 		 set, "set");
11748 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11749 	TOKEN_STRING_INITIALIZER
11750 		(struct cmd_tx_loopback_result,
11751 		 tx, "tx");
11752 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11753 	TOKEN_STRING_INITIALIZER
11754 		(struct cmd_tx_loopback_result,
11755 		 loopback, "loopback");
11756 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11757 	TOKEN_NUM_INITIALIZER
11758 		(struct cmd_tx_loopback_result,
11759 		 port_id, UINT8);
11760 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11761 	TOKEN_STRING_INITIALIZER
11762 		(struct cmd_tx_loopback_result,
11763 		 on_off, "on#off");
11764 
11765 static void
11766 cmd_set_tx_loopback_parsed(
11767 	void *parsed_result,
11768 	__attribute__((unused)) struct cmdline *cl,
11769 	__attribute__((unused)) void *data)
11770 {
11771 	struct cmd_tx_loopback_result *res = parsed_result;
11772 	int ret = -ENOTSUP;
11773 
11774 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11775 
11776 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11777 		return;
11778 
11779 #ifdef RTE_LIBRTE_IXGBE_PMD
11780 	if (ret == -ENOTSUP)
11781 		ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11782 #endif
11783 #ifdef RTE_LIBRTE_I40E_PMD
11784 	if (ret == -ENOTSUP)
11785 		ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11786 #endif
11787 #ifdef RTE_LIBRTE_BNXT_PMD
11788 	if (ret == -ENOTSUP)
11789 		ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11790 #endif
11791 
11792 	switch (ret) {
11793 	case 0:
11794 		break;
11795 	case -EINVAL:
11796 		printf("invalid is_on %d\n", is_on);
11797 		break;
11798 	case -ENODEV:
11799 		printf("invalid port_id %d\n", res->port_id);
11800 		break;
11801 	case -ENOTSUP:
11802 		printf("function not implemented\n");
11803 		break;
11804 	default:
11805 		printf("programming error: (%s)\n", strerror(-ret));
11806 	}
11807 }
11808 
11809 cmdline_parse_inst_t cmd_set_tx_loopback = {
11810 	.f = cmd_set_tx_loopback_parsed,
11811 	.data = NULL,
11812 	.help_str = "set tx loopback <port_id> on|off",
11813 	.tokens = {
11814 		(void *)&cmd_tx_loopback_set,
11815 		(void *)&cmd_tx_loopback_tx,
11816 		(void *)&cmd_tx_loopback_loopback,
11817 		(void *)&cmd_tx_loopback_port_id,
11818 		(void *)&cmd_tx_loopback_on_off,
11819 		NULL,
11820 	},
11821 };
11822 
11823 /* all queues drop enable configuration */
11824 
11825 /* Common result structure for all queues drop enable */
11826 struct cmd_all_queues_drop_en_result {
11827 	cmdline_fixed_string_t set;
11828 	cmdline_fixed_string_t all;
11829 	cmdline_fixed_string_t queues;
11830 	cmdline_fixed_string_t drop;
11831 	uint8_t port_id;
11832 	cmdline_fixed_string_t on_off;
11833 };
11834 
11835 /* Common CLI fields for tx loopback enable disable */
11836 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11837 	TOKEN_STRING_INITIALIZER
11838 		(struct cmd_all_queues_drop_en_result,
11839 		 set, "set");
11840 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11841 	TOKEN_STRING_INITIALIZER
11842 		(struct cmd_all_queues_drop_en_result,
11843 		 all, "all");
11844 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11845 	TOKEN_STRING_INITIALIZER
11846 		(struct cmd_all_queues_drop_en_result,
11847 		 queues, "queues");
11848 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11849 	TOKEN_STRING_INITIALIZER
11850 		(struct cmd_all_queues_drop_en_result,
11851 		 drop, "drop");
11852 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11853 	TOKEN_NUM_INITIALIZER
11854 		(struct cmd_all_queues_drop_en_result,
11855 		 port_id, UINT8);
11856 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11857 	TOKEN_STRING_INITIALIZER
11858 		(struct cmd_all_queues_drop_en_result,
11859 		 on_off, "on#off");
11860 
11861 static void
11862 cmd_set_all_queues_drop_en_parsed(
11863 	void *parsed_result,
11864 	__attribute__((unused)) struct cmdline *cl,
11865 	__attribute__((unused)) void *data)
11866 {
11867 	struct cmd_all_queues_drop_en_result *res = parsed_result;
11868 	int ret = -ENOTSUP;
11869 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11870 
11871 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11872 		return;
11873 
11874 #ifdef RTE_LIBRTE_IXGBE_PMD
11875 	if (ret == -ENOTSUP)
11876 		ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11877 #endif
11878 #ifdef RTE_LIBRTE_BNXT_PMD
11879 	if (ret == -ENOTSUP)
11880 		ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11881 #endif
11882 	switch (ret) {
11883 	case 0:
11884 		break;
11885 	case -EINVAL:
11886 		printf("invalid is_on %d\n", is_on);
11887 		break;
11888 	case -ENODEV:
11889 		printf("invalid port_id %d\n", res->port_id);
11890 		break;
11891 	case -ENOTSUP:
11892 		printf("function not implemented\n");
11893 		break;
11894 	default:
11895 		printf("programming error: (%s)\n", strerror(-ret));
11896 	}
11897 }
11898 
11899 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11900 	.f = cmd_set_all_queues_drop_en_parsed,
11901 	.data = NULL,
11902 	.help_str = "set all queues drop <port_id> on|off",
11903 	.tokens = {
11904 		(void *)&cmd_all_queues_drop_en_set,
11905 		(void *)&cmd_all_queues_drop_en_all,
11906 		(void *)&cmd_all_queues_drop_en_queues,
11907 		(void *)&cmd_all_queues_drop_en_drop,
11908 		(void *)&cmd_all_queues_drop_en_port_id,
11909 		(void *)&cmd_all_queues_drop_en_on_off,
11910 		NULL,
11911 	},
11912 };
11913 
11914 /* vf split drop enable configuration */
11915 
11916 /* Common result structure for vf split drop enable */
11917 struct cmd_vf_split_drop_en_result {
11918 	cmdline_fixed_string_t set;
11919 	cmdline_fixed_string_t vf;
11920 	cmdline_fixed_string_t split;
11921 	cmdline_fixed_string_t drop;
11922 	uint8_t port_id;
11923 	uint16_t vf_id;
11924 	cmdline_fixed_string_t on_off;
11925 };
11926 
11927 /* Common CLI fields for vf split drop enable disable */
11928 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11929 	TOKEN_STRING_INITIALIZER
11930 		(struct cmd_vf_split_drop_en_result,
11931 		 set, "set");
11932 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11933 	TOKEN_STRING_INITIALIZER
11934 		(struct cmd_vf_split_drop_en_result,
11935 		 vf, "vf");
11936 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11937 	TOKEN_STRING_INITIALIZER
11938 		(struct cmd_vf_split_drop_en_result,
11939 		 split, "split");
11940 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11941 	TOKEN_STRING_INITIALIZER
11942 		(struct cmd_vf_split_drop_en_result,
11943 		 drop, "drop");
11944 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11945 	TOKEN_NUM_INITIALIZER
11946 		(struct cmd_vf_split_drop_en_result,
11947 		 port_id, UINT8);
11948 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11949 	TOKEN_NUM_INITIALIZER
11950 		(struct cmd_vf_split_drop_en_result,
11951 		 vf_id, UINT16);
11952 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11953 	TOKEN_STRING_INITIALIZER
11954 		(struct cmd_vf_split_drop_en_result,
11955 		 on_off, "on#off");
11956 
11957 static void
11958 cmd_set_vf_split_drop_en_parsed(
11959 	void *parsed_result,
11960 	__attribute__((unused)) struct cmdline *cl,
11961 	__attribute__((unused)) void *data)
11962 {
11963 	struct cmd_vf_split_drop_en_result *res = parsed_result;
11964 	int ret = -ENOTSUP;
11965 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11966 
11967 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11968 		return;
11969 
11970 #ifdef RTE_LIBRTE_IXGBE_PMD
11971 	ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11972 			is_on);
11973 #endif
11974 	switch (ret) {
11975 	case 0:
11976 		break;
11977 	case -EINVAL:
11978 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11979 		break;
11980 	case -ENODEV:
11981 		printf("invalid port_id %d\n", res->port_id);
11982 		break;
11983 	case -ENOTSUP:
11984 		printf("not supported on port %d\n", res->port_id);
11985 		break;
11986 	default:
11987 		printf("programming error: (%s)\n", strerror(-ret));
11988 	}
11989 }
11990 
11991 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11992 	.f = cmd_set_vf_split_drop_en_parsed,
11993 	.data = NULL,
11994 	.help_str = "set vf split drop <port_id> <vf_id> on|off",
11995 	.tokens = {
11996 		(void *)&cmd_vf_split_drop_en_set,
11997 		(void *)&cmd_vf_split_drop_en_vf,
11998 		(void *)&cmd_vf_split_drop_en_split,
11999 		(void *)&cmd_vf_split_drop_en_drop,
12000 		(void *)&cmd_vf_split_drop_en_port_id,
12001 		(void *)&cmd_vf_split_drop_en_vf_id,
12002 		(void *)&cmd_vf_split_drop_en_on_off,
12003 		NULL,
12004 	},
12005 };
12006 
12007 /* vf mac address configuration */
12008 
12009 /* Common result structure for vf mac address */
12010 struct cmd_set_vf_mac_addr_result {
12011 	cmdline_fixed_string_t set;
12012 	cmdline_fixed_string_t vf;
12013 	cmdline_fixed_string_t mac;
12014 	cmdline_fixed_string_t addr;
12015 	uint8_t port_id;
12016 	uint16_t vf_id;
12017 	struct ether_addr mac_addr;
12018 
12019 };
12020 
12021 /* Common CLI fields for vf split drop enable disable */
12022 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12023 	TOKEN_STRING_INITIALIZER
12024 		(struct cmd_set_vf_mac_addr_result,
12025 		 set, "set");
12026 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12027 	TOKEN_STRING_INITIALIZER
12028 		(struct cmd_set_vf_mac_addr_result,
12029 		 vf, "vf");
12030 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12031 	TOKEN_STRING_INITIALIZER
12032 		(struct cmd_set_vf_mac_addr_result,
12033 		 mac, "mac");
12034 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12035 	TOKEN_STRING_INITIALIZER
12036 		(struct cmd_set_vf_mac_addr_result,
12037 		 addr, "addr");
12038 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12039 	TOKEN_NUM_INITIALIZER
12040 		(struct cmd_set_vf_mac_addr_result,
12041 		 port_id, UINT8);
12042 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12043 	TOKEN_NUM_INITIALIZER
12044 		(struct cmd_set_vf_mac_addr_result,
12045 		 vf_id, UINT16);
12046 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12047 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12048 		 mac_addr);
12049 
12050 static void
12051 cmd_set_vf_mac_addr_parsed(
12052 	void *parsed_result,
12053 	__attribute__((unused)) struct cmdline *cl,
12054 	__attribute__((unused)) void *data)
12055 {
12056 	struct cmd_set_vf_mac_addr_result *res = parsed_result;
12057 	int ret = -ENOTSUP;
12058 
12059 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12060 		return;
12061 
12062 #ifdef RTE_LIBRTE_IXGBE_PMD
12063 	if (ret == -ENOTSUP)
12064 		ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12065 				&res->mac_addr);
12066 #endif
12067 #ifdef RTE_LIBRTE_I40E_PMD
12068 	if (ret == -ENOTSUP)
12069 		ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12070 				&res->mac_addr);
12071 #endif
12072 #ifdef RTE_LIBRTE_BNXT_PMD
12073 	if (ret == -ENOTSUP)
12074 		ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12075 				&res->mac_addr);
12076 #endif
12077 
12078 	switch (ret) {
12079 	case 0:
12080 		break;
12081 	case -EINVAL:
12082 		printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12083 		break;
12084 	case -ENODEV:
12085 		printf("invalid port_id %d\n", res->port_id);
12086 		break;
12087 	case -ENOTSUP:
12088 		printf("function not implemented\n");
12089 		break;
12090 	default:
12091 		printf("programming error: (%s)\n", strerror(-ret));
12092 	}
12093 }
12094 
12095 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12096 	.f = cmd_set_vf_mac_addr_parsed,
12097 	.data = NULL,
12098 	.help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12099 	.tokens = {
12100 		(void *)&cmd_set_vf_mac_addr_set,
12101 		(void *)&cmd_set_vf_mac_addr_vf,
12102 		(void *)&cmd_set_vf_mac_addr_mac,
12103 		(void *)&cmd_set_vf_mac_addr_addr,
12104 		(void *)&cmd_set_vf_mac_addr_port_id,
12105 		(void *)&cmd_set_vf_mac_addr_vf_id,
12106 		(void *)&cmd_set_vf_mac_addr_mac_addr,
12107 		NULL,
12108 	},
12109 };
12110 
12111 /* MACsec configuration */
12112 
12113 /* Common result structure for MACsec offload enable */
12114 struct cmd_macsec_offload_on_result {
12115 	cmdline_fixed_string_t set;
12116 	cmdline_fixed_string_t macsec;
12117 	cmdline_fixed_string_t offload;
12118 	uint8_t port_id;
12119 	cmdline_fixed_string_t on;
12120 	cmdline_fixed_string_t encrypt;
12121 	cmdline_fixed_string_t en_on_off;
12122 	cmdline_fixed_string_t replay_protect;
12123 	cmdline_fixed_string_t rp_on_off;
12124 };
12125 
12126 /* Common CLI fields for MACsec offload disable */
12127 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12128 	TOKEN_STRING_INITIALIZER
12129 		(struct cmd_macsec_offload_on_result,
12130 		 set, "set");
12131 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12132 	TOKEN_STRING_INITIALIZER
12133 		(struct cmd_macsec_offload_on_result,
12134 		 macsec, "macsec");
12135 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12136 	TOKEN_STRING_INITIALIZER
12137 		(struct cmd_macsec_offload_on_result,
12138 		 offload, "offload");
12139 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12140 	TOKEN_NUM_INITIALIZER
12141 		(struct cmd_macsec_offload_on_result,
12142 		 port_id, UINT8);
12143 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12144 	TOKEN_STRING_INITIALIZER
12145 		(struct cmd_macsec_offload_on_result,
12146 		 on, "on");
12147 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12148 	TOKEN_STRING_INITIALIZER
12149 		(struct cmd_macsec_offload_on_result,
12150 		 encrypt, "encrypt");
12151 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12152 	TOKEN_STRING_INITIALIZER
12153 		(struct cmd_macsec_offload_on_result,
12154 		 en_on_off, "on#off");
12155 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12156 	TOKEN_STRING_INITIALIZER
12157 		(struct cmd_macsec_offload_on_result,
12158 		 replay_protect, "replay-protect");
12159 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12160 	TOKEN_STRING_INITIALIZER
12161 		(struct cmd_macsec_offload_on_result,
12162 		 rp_on_off, "on#off");
12163 
12164 static void
12165 cmd_set_macsec_offload_on_parsed(
12166 	void *parsed_result,
12167 	__attribute__((unused)) struct cmdline *cl,
12168 	__attribute__((unused)) void *data)
12169 {
12170 	struct cmd_macsec_offload_on_result *res = parsed_result;
12171 	int ret = -ENOTSUP;
12172 	portid_t port_id = res->port_id;
12173 	int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12174 	int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12175 
12176 	if (port_id_is_invalid(port_id, ENABLED_WARN))
12177 		return;
12178 
12179 	ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12180 #ifdef RTE_LIBRTE_IXGBE_PMD
12181 	ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12182 #endif
12183 	RTE_SET_USED(en);
12184 	RTE_SET_USED(rp);
12185 
12186 	switch (ret) {
12187 	case 0:
12188 		break;
12189 	case -ENODEV:
12190 		printf("invalid port_id %d\n", port_id);
12191 		break;
12192 	case -ENOTSUP:
12193 		printf("not supported on port %d\n", port_id);
12194 		break;
12195 	default:
12196 		printf("programming error: (%s)\n", strerror(-ret));
12197 	}
12198 }
12199 
12200 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12201 	.f = cmd_set_macsec_offload_on_parsed,
12202 	.data = NULL,
12203 	.help_str = "set macsec offload <port_id> on "
12204 		"encrypt on|off replay-protect on|off",
12205 	.tokens = {
12206 		(void *)&cmd_macsec_offload_on_set,
12207 		(void *)&cmd_macsec_offload_on_macsec,
12208 		(void *)&cmd_macsec_offload_on_offload,
12209 		(void *)&cmd_macsec_offload_on_port_id,
12210 		(void *)&cmd_macsec_offload_on_on,
12211 		(void *)&cmd_macsec_offload_on_encrypt,
12212 		(void *)&cmd_macsec_offload_on_en_on_off,
12213 		(void *)&cmd_macsec_offload_on_replay_protect,
12214 		(void *)&cmd_macsec_offload_on_rp_on_off,
12215 		NULL,
12216 	},
12217 };
12218 
12219 /* Common result structure for MACsec offload disable */
12220 struct cmd_macsec_offload_off_result {
12221 	cmdline_fixed_string_t set;
12222 	cmdline_fixed_string_t macsec;
12223 	cmdline_fixed_string_t offload;
12224 	uint8_t port_id;
12225 	cmdline_fixed_string_t off;
12226 };
12227 
12228 /* Common CLI fields for MACsec offload disable */
12229 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12230 	TOKEN_STRING_INITIALIZER
12231 		(struct cmd_macsec_offload_off_result,
12232 		 set, "set");
12233 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12234 	TOKEN_STRING_INITIALIZER
12235 		(struct cmd_macsec_offload_off_result,
12236 		 macsec, "macsec");
12237 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12238 	TOKEN_STRING_INITIALIZER
12239 		(struct cmd_macsec_offload_off_result,
12240 		 offload, "offload");
12241 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12242 	TOKEN_NUM_INITIALIZER
12243 		(struct cmd_macsec_offload_off_result,
12244 		 port_id, UINT8);
12245 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12246 	TOKEN_STRING_INITIALIZER
12247 		(struct cmd_macsec_offload_off_result,
12248 		 off, "off");
12249 
12250 static void
12251 cmd_set_macsec_offload_off_parsed(
12252 	void *parsed_result,
12253 	__attribute__((unused)) struct cmdline *cl,
12254 	__attribute__((unused)) void *data)
12255 {
12256 	struct cmd_macsec_offload_off_result *res = parsed_result;
12257 	int ret = -ENOTSUP;
12258 	portid_t port_id = res->port_id;
12259 
12260 	if (port_id_is_invalid(port_id, ENABLED_WARN))
12261 		return;
12262 
12263 	ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
12264 #ifdef RTE_LIBRTE_IXGBE_PMD
12265 	ret = rte_pmd_ixgbe_macsec_disable(port_id);
12266 #endif
12267 
12268 	switch (ret) {
12269 	case 0:
12270 		break;
12271 	case -ENODEV:
12272 		printf("invalid port_id %d\n", port_id);
12273 		break;
12274 	case -ENOTSUP:
12275 		printf("not supported on port %d\n", port_id);
12276 		break;
12277 	default:
12278 		printf("programming error: (%s)\n", strerror(-ret));
12279 	}
12280 }
12281 
12282 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12283 	.f = cmd_set_macsec_offload_off_parsed,
12284 	.data = NULL,
12285 	.help_str = "set macsec offload <port_id> off",
12286 	.tokens = {
12287 		(void *)&cmd_macsec_offload_off_set,
12288 		(void *)&cmd_macsec_offload_off_macsec,
12289 		(void *)&cmd_macsec_offload_off_offload,
12290 		(void *)&cmd_macsec_offload_off_port_id,
12291 		(void *)&cmd_macsec_offload_off_off,
12292 		NULL,
12293 	},
12294 };
12295 
12296 /* Common result structure for MACsec secure connection configure */
12297 struct cmd_macsec_sc_result {
12298 	cmdline_fixed_string_t set;
12299 	cmdline_fixed_string_t macsec;
12300 	cmdline_fixed_string_t sc;
12301 	cmdline_fixed_string_t tx_rx;
12302 	uint8_t port_id;
12303 	struct ether_addr mac;
12304 	uint16_t pi;
12305 };
12306 
12307 /* Common CLI fields for MACsec secure connection configure */
12308 cmdline_parse_token_string_t cmd_macsec_sc_set =
12309 	TOKEN_STRING_INITIALIZER
12310 		(struct cmd_macsec_sc_result,
12311 		 set, "set");
12312 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12313 	TOKEN_STRING_INITIALIZER
12314 		(struct cmd_macsec_sc_result,
12315 		 macsec, "macsec");
12316 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12317 	TOKEN_STRING_INITIALIZER
12318 		(struct cmd_macsec_sc_result,
12319 		 sc, "sc");
12320 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12321 	TOKEN_STRING_INITIALIZER
12322 		(struct cmd_macsec_sc_result,
12323 		 tx_rx, "tx#rx");
12324 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12325 	TOKEN_NUM_INITIALIZER
12326 		(struct cmd_macsec_sc_result,
12327 		 port_id, UINT8);
12328 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12329 	TOKEN_ETHERADDR_INITIALIZER
12330 		(struct cmd_macsec_sc_result,
12331 		 mac);
12332 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12333 	TOKEN_NUM_INITIALIZER
12334 		(struct cmd_macsec_sc_result,
12335 		 pi, UINT16);
12336 
12337 static void
12338 cmd_set_macsec_sc_parsed(
12339 	void *parsed_result,
12340 	__attribute__((unused)) struct cmdline *cl,
12341 	__attribute__((unused)) void *data)
12342 {
12343 	struct cmd_macsec_sc_result *res = parsed_result;
12344 	int ret = -ENOTSUP;
12345 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12346 
12347 #ifdef RTE_LIBRTE_IXGBE_PMD
12348 	ret = is_tx ?
12349 		rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12350 				res->mac.addr_bytes) :
12351 		rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12352 				res->mac.addr_bytes, res->pi);
12353 #endif
12354 	RTE_SET_USED(is_tx);
12355 
12356 	switch (ret) {
12357 	case 0:
12358 		break;
12359 	case -ENODEV:
12360 		printf("invalid port_id %d\n", res->port_id);
12361 		break;
12362 	case -ENOTSUP:
12363 		printf("not supported on port %d\n", res->port_id);
12364 		break;
12365 	default:
12366 		printf("programming error: (%s)\n", strerror(-ret));
12367 	}
12368 }
12369 
12370 cmdline_parse_inst_t cmd_set_macsec_sc = {
12371 	.f = cmd_set_macsec_sc_parsed,
12372 	.data = NULL,
12373 	.help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12374 	.tokens = {
12375 		(void *)&cmd_macsec_sc_set,
12376 		(void *)&cmd_macsec_sc_macsec,
12377 		(void *)&cmd_macsec_sc_sc,
12378 		(void *)&cmd_macsec_sc_tx_rx,
12379 		(void *)&cmd_macsec_sc_port_id,
12380 		(void *)&cmd_macsec_sc_mac,
12381 		(void *)&cmd_macsec_sc_pi,
12382 		NULL,
12383 	},
12384 };
12385 
12386 /* Common result structure for MACsec secure connection configure */
12387 struct cmd_macsec_sa_result {
12388 	cmdline_fixed_string_t set;
12389 	cmdline_fixed_string_t macsec;
12390 	cmdline_fixed_string_t sa;
12391 	cmdline_fixed_string_t tx_rx;
12392 	uint8_t port_id;
12393 	uint8_t idx;
12394 	uint8_t an;
12395 	uint32_t pn;
12396 	cmdline_fixed_string_t key;
12397 };
12398 
12399 /* Common CLI fields for MACsec secure connection configure */
12400 cmdline_parse_token_string_t cmd_macsec_sa_set =
12401 	TOKEN_STRING_INITIALIZER
12402 		(struct cmd_macsec_sa_result,
12403 		 set, "set");
12404 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12405 	TOKEN_STRING_INITIALIZER
12406 		(struct cmd_macsec_sa_result,
12407 		 macsec, "macsec");
12408 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12409 	TOKEN_STRING_INITIALIZER
12410 		(struct cmd_macsec_sa_result,
12411 		 sa, "sa");
12412 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12413 	TOKEN_STRING_INITIALIZER
12414 		(struct cmd_macsec_sa_result,
12415 		 tx_rx, "tx#rx");
12416 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12417 	TOKEN_NUM_INITIALIZER
12418 		(struct cmd_macsec_sa_result,
12419 		 port_id, UINT8);
12420 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12421 	TOKEN_NUM_INITIALIZER
12422 		(struct cmd_macsec_sa_result,
12423 		 idx, UINT8);
12424 cmdline_parse_token_num_t cmd_macsec_sa_an =
12425 	TOKEN_NUM_INITIALIZER
12426 		(struct cmd_macsec_sa_result,
12427 		 an, UINT8);
12428 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12429 	TOKEN_NUM_INITIALIZER
12430 		(struct cmd_macsec_sa_result,
12431 		 pn, UINT32);
12432 cmdline_parse_token_string_t cmd_macsec_sa_key =
12433 	TOKEN_STRING_INITIALIZER
12434 		(struct cmd_macsec_sa_result,
12435 		 key, NULL);
12436 
12437 static void
12438 cmd_set_macsec_sa_parsed(
12439 	void *parsed_result,
12440 	__attribute__((unused)) struct cmdline *cl,
12441 	__attribute__((unused)) void *data)
12442 {
12443 	struct cmd_macsec_sa_result *res = parsed_result;
12444 	int ret = -ENOTSUP;
12445 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12446 	uint8_t key[16] = { 0 };
12447 	uint8_t xdgt0;
12448 	uint8_t xdgt1;
12449 	int key_len;
12450 	int i;
12451 
12452 	key_len = strlen(res->key) / 2;
12453 	if (key_len > 16)
12454 		key_len = 16;
12455 
12456 	for (i = 0; i < key_len; i++) {
12457 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12458 		if (xdgt0 == 0xFF)
12459 			return;
12460 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12461 		if (xdgt1 == 0xFF)
12462 			return;
12463 		key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12464 	}
12465 
12466 #ifdef RTE_LIBRTE_IXGBE_PMD
12467 	ret = is_tx ?
12468 		rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12469 			res->idx, res->an, res->pn, key) :
12470 		rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12471 			res->idx, res->an, res->pn, key);
12472 #endif
12473 	RTE_SET_USED(is_tx);
12474 	RTE_SET_USED(key);
12475 
12476 	switch (ret) {
12477 	case 0:
12478 		break;
12479 	case -EINVAL:
12480 		printf("invalid idx %d or an %d\n", res->idx, res->an);
12481 		break;
12482 	case -ENODEV:
12483 		printf("invalid port_id %d\n", res->port_id);
12484 		break;
12485 	case -ENOTSUP:
12486 		printf("not supported on port %d\n", res->port_id);
12487 		break;
12488 	default:
12489 		printf("programming error: (%s)\n", strerror(-ret));
12490 	}
12491 }
12492 
12493 cmdline_parse_inst_t cmd_set_macsec_sa = {
12494 	.f = cmd_set_macsec_sa_parsed,
12495 	.data = NULL,
12496 	.help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12497 	.tokens = {
12498 		(void *)&cmd_macsec_sa_set,
12499 		(void *)&cmd_macsec_sa_macsec,
12500 		(void *)&cmd_macsec_sa_sa,
12501 		(void *)&cmd_macsec_sa_tx_rx,
12502 		(void *)&cmd_macsec_sa_port_id,
12503 		(void *)&cmd_macsec_sa_idx,
12504 		(void *)&cmd_macsec_sa_an,
12505 		(void *)&cmd_macsec_sa_pn,
12506 		(void *)&cmd_macsec_sa_key,
12507 		NULL,
12508 	},
12509 };
12510 
12511 /* VF unicast promiscuous mode configuration */
12512 
12513 /* Common result structure for VF unicast promiscuous mode */
12514 struct cmd_vf_promisc_result {
12515 	cmdline_fixed_string_t set;
12516 	cmdline_fixed_string_t vf;
12517 	cmdline_fixed_string_t promisc;
12518 	uint8_t port_id;
12519 	uint32_t vf_id;
12520 	cmdline_fixed_string_t on_off;
12521 };
12522 
12523 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12524 cmdline_parse_token_string_t cmd_vf_promisc_set =
12525 	TOKEN_STRING_INITIALIZER
12526 		(struct cmd_vf_promisc_result,
12527 		 set, "set");
12528 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12529 	TOKEN_STRING_INITIALIZER
12530 		(struct cmd_vf_promisc_result,
12531 		 vf, "vf");
12532 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12533 	TOKEN_STRING_INITIALIZER
12534 		(struct cmd_vf_promisc_result,
12535 		 promisc, "promisc");
12536 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12537 	TOKEN_NUM_INITIALIZER
12538 		(struct cmd_vf_promisc_result,
12539 		 port_id, UINT8);
12540 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12541 	TOKEN_NUM_INITIALIZER
12542 		(struct cmd_vf_promisc_result,
12543 		 vf_id, UINT32);
12544 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12545 	TOKEN_STRING_INITIALIZER
12546 		(struct cmd_vf_promisc_result,
12547 		 on_off, "on#off");
12548 
12549 static void
12550 cmd_set_vf_promisc_parsed(
12551 	void *parsed_result,
12552 	__attribute__((unused)) struct cmdline *cl,
12553 	__attribute__((unused)) void *data)
12554 {
12555 	struct cmd_vf_promisc_result *res = parsed_result;
12556 	int ret = -ENOTSUP;
12557 
12558 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12559 
12560 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12561 		return;
12562 
12563 #ifdef RTE_LIBRTE_I40E_PMD
12564 	ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12565 						  res->vf_id, is_on);
12566 #endif
12567 
12568 	switch (ret) {
12569 	case 0:
12570 		break;
12571 	case -EINVAL:
12572 		printf("invalid vf_id %d\n", res->vf_id);
12573 		break;
12574 	case -ENODEV:
12575 		printf("invalid port_id %d\n", res->port_id);
12576 		break;
12577 	case -ENOTSUP:
12578 		printf("function not implemented\n");
12579 		break;
12580 	default:
12581 		printf("programming error: (%s)\n", strerror(-ret));
12582 	}
12583 }
12584 
12585 cmdline_parse_inst_t cmd_set_vf_promisc = {
12586 	.f = cmd_set_vf_promisc_parsed,
12587 	.data = NULL,
12588 	.help_str = "set vf promisc <port_id> <vf_id> on|off: "
12589 		"Set unicast promiscuous mode for a VF from the PF",
12590 	.tokens = {
12591 		(void *)&cmd_vf_promisc_set,
12592 		(void *)&cmd_vf_promisc_vf,
12593 		(void *)&cmd_vf_promisc_promisc,
12594 		(void *)&cmd_vf_promisc_port_id,
12595 		(void *)&cmd_vf_promisc_vf_id,
12596 		(void *)&cmd_vf_promisc_on_off,
12597 		NULL,
12598 	},
12599 };
12600 
12601 /* VF multicast promiscuous mode configuration */
12602 
12603 /* Common result structure for VF multicast promiscuous mode */
12604 struct cmd_vf_allmulti_result {
12605 	cmdline_fixed_string_t set;
12606 	cmdline_fixed_string_t vf;
12607 	cmdline_fixed_string_t allmulti;
12608 	uint8_t port_id;
12609 	uint32_t vf_id;
12610 	cmdline_fixed_string_t on_off;
12611 };
12612 
12613 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12614 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12615 	TOKEN_STRING_INITIALIZER
12616 		(struct cmd_vf_allmulti_result,
12617 		 set, "set");
12618 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12619 	TOKEN_STRING_INITIALIZER
12620 		(struct cmd_vf_allmulti_result,
12621 		 vf, "vf");
12622 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12623 	TOKEN_STRING_INITIALIZER
12624 		(struct cmd_vf_allmulti_result,
12625 		 allmulti, "allmulti");
12626 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12627 	TOKEN_NUM_INITIALIZER
12628 		(struct cmd_vf_allmulti_result,
12629 		 port_id, UINT8);
12630 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12631 	TOKEN_NUM_INITIALIZER
12632 		(struct cmd_vf_allmulti_result,
12633 		 vf_id, UINT32);
12634 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12635 	TOKEN_STRING_INITIALIZER
12636 		(struct cmd_vf_allmulti_result,
12637 		 on_off, "on#off");
12638 
12639 static void
12640 cmd_set_vf_allmulti_parsed(
12641 	void *parsed_result,
12642 	__attribute__((unused)) struct cmdline *cl,
12643 	__attribute__((unused)) void *data)
12644 {
12645 	struct cmd_vf_allmulti_result *res = parsed_result;
12646 	int ret = -ENOTSUP;
12647 
12648 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12649 
12650 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12651 		return;
12652 
12653 #ifdef RTE_LIBRTE_I40E_PMD
12654 	ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12655 						    res->vf_id, is_on);
12656 #endif
12657 
12658 	switch (ret) {
12659 	case 0:
12660 		break;
12661 	case -EINVAL:
12662 		printf("invalid vf_id %d\n", res->vf_id);
12663 		break;
12664 	case -ENODEV:
12665 		printf("invalid port_id %d\n", res->port_id);
12666 		break;
12667 	case -ENOTSUP:
12668 		printf("function not implemented\n");
12669 		break;
12670 	default:
12671 		printf("programming error: (%s)\n", strerror(-ret));
12672 	}
12673 }
12674 
12675 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12676 	.f = cmd_set_vf_allmulti_parsed,
12677 	.data = NULL,
12678 	.help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12679 		"Set multicast promiscuous mode for a VF from the PF",
12680 	.tokens = {
12681 		(void *)&cmd_vf_allmulti_set,
12682 		(void *)&cmd_vf_allmulti_vf,
12683 		(void *)&cmd_vf_allmulti_allmulti,
12684 		(void *)&cmd_vf_allmulti_port_id,
12685 		(void *)&cmd_vf_allmulti_vf_id,
12686 		(void *)&cmd_vf_allmulti_on_off,
12687 		NULL,
12688 	},
12689 };
12690 
12691 /* vf broadcast mode configuration */
12692 
12693 /* Common result structure for vf broadcast */
12694 struct cmd_set_vf_broadcast_result {
12695 	cmdline_fixed_string_t set;
12696 	cmdline_fixed_string_t vf;
12697 	cmdline_fixed_string_t broadcast;
12698 	uint8_t port_id;
12699 	uint16_t vf_id;
12700 	cmdline_fixed_string_t on_off;
12701 };
12702 
12703 /* Common CLI fields for vf broadcast enable disable */
12704 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12705 	TOKEN_STRING_INITIALIZER
12706 		(struct cmd_set_vf_broadcast_result,
12707 		 set, "set");
12708 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12709 	TOKEN_STRING_INITIALIZER
12710 		(struct cmd_set_vf_broadcast_result,
12711 		 vf, "vf");
12712 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12713 	TOKEN_STRING_INITIALIZER
12714 		(struct cmd_set_vf_broadcast_result,
12715 		 broadcast, "broadcast");
12716 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12717 	TOKEN_NUM_INITIALIZER
12718 		(struct cmd_set_vf_broadcast_result,
12719 		 port_id, UINT8);
12720 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12721 	TOKEN_NUM_INITIALIZER
12722 		(struct cmd_set_vf_broadcast_result,
12723 		 vf_id, UINT16);
12724 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12725 	TOKEN_STRING_INITIALIZER
12726 		(struct cmd_set_vf_broadcast_result,
12727 		 on_off, "on#off");
12728 
12729 static void
12730 cmd_set_vf_broadcast_parsed(
12731 	void *parsed_result,
12732 	__attribute__((unused)) struct cmdline *cl,
12733 	__attribute__((unused)) void *data)
12734 {
12735 	struct cmd_set_vf_broadcast_result *res = parsed_result;
12736 	int ret = -ENOTSUP;
12737 
12738 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12739 
12740 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12741 		return;
12742 
12743 #ifdef RTE_LIBRTE_I40E_PMD
12744 	ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12745 					    res->vf_id, is_on);
12746 #endif
12747 
12748 	switch (ret) {
12749 	case 0:
12750 		break;
12751 	case -EINVAL:
12752 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12753 		break;
12754 	case -ENODEV:
12755 		printf("invalid port_id %d\n", res->port_id);
12756 		break;
12757 	case -ENOTSUP:
12758 		printf("function not implemented\n");
12759 		break;
12760 	default:
12761 		printf("programming error: (%s)\n", strerror(-ret));
12762 	}
12763 }
12764 
12765 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12766 	.f = cmd_set_vf_broadcast_parsed,
12767 	.data = NULL,
12768 	.help_str = "set vf broadcast <port_id> <vf_id> on|off",
12769 	.tokens = {
12770 		(void *)&cmd_set_vf_broadcast_set,
12771 		(void *)&cmd_set_vf_broadcast_vf,
12772 		(void *)&cmd_set_vf_broadcast_broadcast,
12773 		(void *)&cmd_set_vf_broadcast_port_id,
12774 		(void *)&cmd_set_vf_broadcast_vf_id,
12775 		(void *)&cmd_set_vf_broadcast_on_off,
12776 		NULL,
12777 	},
12778 };
12779 
12780 /* vf vlan tag configuration */
12781 
12782 /* Common result structure for vf vlan tag */
12783 struct cmd_set_vf_vlan_tag_result {
12784 	cmdline_fixed_string_t set;
12785 	cmdline_fixed_string_t vf;
12786 	cmdline_fixed_string_t vlan;
12787 	cmdline_fixed_string_t tag;
12788 	uint8_t port_id;
12789 	uint16_t vf_id;
12790 	cmdline_fixed_string_t on_off;
12791 };
12792 
12793 /* Common CLI fields for vf vlan tag enable disable */
12794 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12795 	TOKEN_STRING_INITIALIZER
12796 		(struct cmd_set_vf_vlan_tag_result,
12797 		 set, "set");
12798 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12799 	TOKEN_STRING_INITIALIZER
12800 		(struct cmd_set_vf_vlan_tag_result,
12801 		 vf, "vf");
12802 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12803 	TOKEN_STRING_INITIALIZER
12804 		(struct cmd_set_vf_vlan_tag_result,
12805 		 vlan, "vlan");
12806 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12807 	TOKEN_STRING_INITIALIZER
12808 		(struct cmd_set_vf_vlan_tag_result,
12809 		 tag, "tag");
12810 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12811 	TOKEN_NUM_INITIALIZER
12812 		(struct cmd_set_vf_vlan_tag_result,
12813 		 port_id, UINT8);
12814 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12815 	TOKEN_NUM_INITIALIZER
12816 		(struct cmd_set_vf_vlan_tag_result,
12817 		 vf_id, UINT16);
12818 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12819 	TOKEN_STRING_INITIALIZER
12820 		(struct cmd_set_vf_vlan_tag_result,
12821 		 on_off, "on#off");
12822 
12823 static void
12824 cmd_set_vf_vlan_tag_parsed(
12825 	void *parsed_result,
12826 	__attribute__((unused)) struct cmdline *cl,
12827 	__attribute__((unused)) void *data)
12828 {
12829 	struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12830 	int ret = -ENOTSUP;
12831 
12832 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12833 
12834 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12835 		return;
12836 
12837 #ifdef RTE_LIBRTE_I40E_PMD
12838 	ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12839 					   res->vf_id, is_on);
12840 #endif
12841 
12842 	switch (ret) {
12843 	case 0:
12844 		break;
12845 	case -EINVAL:
12846 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12847 		break;
12848 	case -ENODEV:
12849 		printf("invalid port_id %d\n", res->port_id);
12850 		break;
12851 	case -ENOTSUP:
12852 		printf("function not implemented\n");
12853 		break;
12854 	default:
12855 		printf("programming error: (%s)\n", strerror(-ret));
12856 	}
12857 }
12858 
12859 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12860 	.f = cmd_set_vf_vlan_tag_parsed,
12861 	.data = NULL,
12862 	.help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12863 	.tokens = {
12864 		(void *)&cmd_set_vf_vlan_tag_set,
12865 		(void *)&cmd_set_vf_vlan_tag_vf,
12866 		(void *)&cmd_set_vf_vlan_tag_vlan,
12867 		(void *)&cmd_set_vf_vlan_tag_tag,
12868 		(void *)&cmd_set_vf_vlan_tag_port_id,
12869 		(void *)&cmd_set_vf_vlan_tag_vf_id,
12870 		(void *)&cmd_set_vf_vlan_tag_on_off,
12871 		NULL,
12872 	},
12873 };
12874 
12875 /* Common definition of VF and TC TX bandwidth configuration */
12876 struct cmd_vf_tc_bw_result {
12877 	cmdline_fixed_string_t set;
12878 	cmdline_fixed_string_t vf;
12879 	cmdline_fixed_string_t tc;
12880 	cmdline_fixed_string_t tx;
12881 	cmdline_fixed_string_t min_bw;
12882 	cmdline_fixed_string_t max_bw;
12883 	cmdline_fixed_string_t strict_link_prio;
12884 	uint8_t port_id;
12885 	uint16_t vf_id;
12886 	uint8_t tc_no;
12887 	uint32_t bw;
12888 	cmdline_fixed_string_t bw_list;
12889 	uint8_t tc_map;
12890 };
12891 
12892 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12893 	TOKEN_STRING_INITIALIZER
12894 		(struct cmd_vf_tc_bw_result,
12895 		 set, "set");
12896 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12897 	TOKEN_STRING_INITIALIZER
12898 		(struct cmd_vf_tc_bw_result,
12899 		 vf, "vf");
12900 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12901 	TOKEN_STRING_INITIALIZER
12902 		(struct cmd_vf_tc_bw_result,
12903 		 tc, "tc");
12904 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12905 	TOKEN_STRING_INITIALIZER
12906 		(struct cmd_vf_tc_bw_result,
12907 		 tx, "tx");
12908 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12909 	TOKEN_STRING_INITIALIZER
12910 		(struct cmd_vf_tc_bw_result,
12911 		 strict_link_prio, "strict-link-priority");
12912 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12913 	TOKEN_STRING_INITIALIZER
12914 		(struct cmd_vf_tc_bw_result,
12915 		 min_bw, "min-bandwidth");
12916 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12917 	TOKEN_STRING_INITIALIZER
12918 		(struct cmd_vf_tc_bw_result,
12919 		 max_bw, "max-bandwidth");
12920 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12921 	TOKEN_NUM_INITIALIZER
12922 		(struct cmd_vf_tc_bw_result,
12923 		 port_id, UINT8);
12924 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12925 	TOKEN_NUM_INITIALIZER
12926 		(struct cmd_vf_tc_bw_result,
12927 		 vf_id, UINT16);
12928 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12929 	TOKEN_NUM_INITIALIZER
12930 		(struct cmd_vf_tc_bw_result,
12931 		 tc_no, UINT8);
12932 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12933 	TOKEN_NUM_INITIALIZER
12934 		(struct cmd_vf_tc_bw_result,
12935 		 bw, UINT32);
12936 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12937 	TOKEN_STRING_INITIALIZER
12938 		(struct cmd_vf_tc_bw_result,
12939 		 bw_list, NULL);
12940 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12941 	TOKEN_NUM_INITIALIZER
12942 		(struct cmd_vf_tc_bw_result,
12943 		 tc_map, UINT8);
12944 
12945 /* VF max bandwidth setting */
12946 static void
12947 cmd_vf_max_bw_parsed(
12948 	void *parsed_result,
12949 	__attribute__((unused)) struct cmdline *cl,
12950 	__attribute__((unused)) void *data)
12951 {
12952 	struct cmd_vf_tc_bw_result *res = parsed_result;
12953 	int ret = -ENOTSUP;
12954 
12955 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12956 		return;
12957 
12958 #ifdef RTE_LIBRTE_I40E_PMD
12959 	ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12960 					 res->vf_id, res->bw);
12961 #endif
12962 
12963 	switch (ret) {
12964 	case 0:
12965 		break;
12966 	case -EINVAL:
12967 		printf("invalid vf_id %d or bandwidth %d\n",
12968 		       res->vf_id, res->bw);
12969 		break;
12970 	case -ENODEV:
12971 		printf("invalid port_id %d\n", res->port_id);
12972 		break;
12973 	case -ENOTSUP:
12974 		printf("function not implemented\n");
12975 		break;
12976 	default:
12977 		printf("programming error: (%s)\n", strerror(-ret));
12978 	}
12979 }
12980 
12981 cmdline_parse_inst_t cmd_vf_max_bw = {
12982 	.f = cmd_vf_max_bw_parsed,
12983 	.data = NULL,
12984 	.help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12985 	.tokens = {
12986 		(void *)&cmd_vf_tc_bw_set,
12987 		(void *)&cmd_vf_tc_bw_vf,
12988 		(void *)&cmd_vf_tc_bw_tx,
12989 		(void *)&cmd_vf_tc_bw_max_bw,
12990 		(void *)&cmd_vf_tc_bw_port_id,
12991 		(void *)&cmd_vf_tc_bw_vf_id,
12992 		(void *)&cmd_vf_tc_bw_bw,
12993 		NULL,
12994 	},
12995 };
12996 
12997 static int
12998 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12999 			   uint8_t *tc_num,
13000 			   char *str)
13001 {
13002 	uint32_t size;
13003 	const char *p, *p0 = str;
13004 	char s[256];
13005 	char *end;
13006 	char *str_fld[16];
13007 	uint16_t i;
13008 	int ret;
13009 
13010 	p = strchr(p0, '(');
13011 	if (p == NULL) {
13012 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13013 		return -1;
13014 	}
13015 	p++;
13016 	p0 = strchr(p, ')');
13017 	if (p0 == NULL) {
13018 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13019 		return -1;
13020 	}
13021 	size = p0 - p;
13022 	if (size >= sizeof(s)) {
13023 		printf("The string size exceeds the internal buffer size\n");
13024 		return -1;
13025 	}
13026 	snprintf(s, sizeof(s), "%.*s", size, p);
13027 	ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13028 	if (ret <= 0) {
13029 		printf("Failed to get the bandwidth list. ");
13030 		return -1;
13031 	}
13032 	*tc_num = ret;
13033 	for (i = 0; i < ret; i++)
13034 		bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13035 
13036 	return 0;
13037 }
13038 
13039 /* TC min bandwidth setting */
13040 static void
13041 cmd_vf_tc_min_bw_parsed(
13042 	void *parsed_result,
13043 	__attribute__((unused)) struct cmdline *cl,
13044 	__attribute__((unused)) void *data)
13045 {
13046 	struct cmd_vf_tc_bw_result *res = parsed_result;
13047 	uint8_t tc_num;
13048 	uint8_t bw[16];
13049 	int ret = -ENOTSUP;
13050 
13051 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13052 		return;
13053 
13054 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13055 	if (ret)
13056 		return;
13057 
13058 #ifdef RTE_LIBRTE_I40E_PMD
13059 	ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13060 					      tc_num, bw);
13061 #endif
13062 
13063 	switch (ret) {
13064 	case 0:
13065 		break;
13066 	case -EINVAL:
13067 		printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13068 		break;
13069 	case -ENODEV:
13070 		printf("invalid port_id %d\n", res->port_id);
13071 		break;
13072 	case -ENOTSUP:
13073 		printf("function not implemented\n");
13074 		break;
13075 	default:
13076 		printf("programming error: (%s)\n", strerror(-ret));
13077 	}
13078 }
13079 
13080 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13081 	.f = cmd_vf_tc_min_bw_parsed,
13082 	.data = NULL,
13083 	.help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13084 		    " <bw1, bw2, ...>",
13085 	.tokens = {
13086 		(void *)&cmd_vf_tc_bw_set,
13087 		(void *)&cmd_vf_tc_bw_vf,
13088 		(void *)&cmd_vf_tc_bw_tc,
13089 		(void *)&cmd_vf_tc_bw_tx,
13090 		(void *)&cmd_vf_tc_bw_min_bw,
13091 		(void *)&cmd_vf_tc_bw_port_id,
13092 		(void *)&cmd_vf_tc_bw_vf_id,
13093 		(void *)&cmd_vf_tc_bw_bw_list,
13094 		NULL,
13095 	},
13096 };
13097 
13098 static void
13099 cmd_tc_min_bw_parsed(
13100 	void *parsed_result,
13101 	__attribute__((unused)) struct cmdline *cl,
13102 	__attribute__((unused)) void *data)
13103 {
13104 	struct cmd_vf_tc_bw_result *res = parsed_result;
13105 	struct rte_port *port;
13106 	uint8_t tc_num;
13107 	uint8_t bw[16];
13108 	int ret = -ENOTSUP;
13109 
13110 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13111 		return;
13112 
13113 	port = &ports[res->port_id];
13114 	/** Check if the port is not started **/
13115 	if (port->port_status != RTE_PORT_STOPPED) {
13116 		printf("Please stop port %d first\n", res->port_id);
13117 		return;
13118 	}
13119 
13120 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13121 	if (ret)
13122 		return;
13123 
13124 #ifdef RTE_LIBRTE_IXGBE_PMD
13125 	ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13126 #endif
13127 
13128 	switch (ret) {
13129 	case 0:
13130 		break;
13131 	case -EINVAL:
13132 		printf("invalid bandwidth\n");
13133 		break;
13134 	case -ENODEV:
13135 		printf("invalid port_id %d\n", res->port_id);
13136 		break;
13137 	case -ENOTSUP:
13138 		printf("function not implemented\n");
13139 		break;
13140 	default:
13141 		printf("programming error: (%s)\n", strerror(-ret));
13142 	}
13143 }
13144 
13145 cmdline_parse_inst_t cmd_tc_min_bw = {
13146 	.f = cmd_tc_min_bw_parsed,
13147 	.data = NULL,
13148 	.help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13149 	.tokens = {
13150 		(void *)&cmd_vf_tc_bw_set,
13151 		(void *)&cmd_vf_tc_bw_tc,
13152 		(void *)&cmd_vf_tc_bw_tx,
13153 		(void *)&cmd_vf_tc_bw_min_bw,
13154 		(void *)&cmd_vf_tc_bw_port_id,
13155 		(void *)&cmd_vf_tc_bw_bw_list,
13156 		NULL,
13157 	},
13158 };
13159 
13160 /* TC max bandwidth setting */
13161 static void
13162 cmd_vf_tc_max_bw_parsed(
13163 	void *parsed_result,
13164 	__attribute__((unused)) struct cmdline *cl,
13165 	__attribute__((unused)) void *data)
13166 {
13167 	struct cmd_vf_tc_bw_result *res = parsed_result;
13168 	int ret = -ENOTSUP;
13169 
13170 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13171 		return;
13172 
13173 #ifdef RTE_LIBRTE_I40E_PMD
13174 	ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13175 					    res->tc_no, res->bw);
13176 #endif
13177 
13178 	switch (ret) {
13179 	case 0:
13180 		break;
13181 	case -EINVAL:
13182 		printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13183 		       res->vf_id, res->tc_no, res->bw);
13184 		break;
13185 	case -ENODEV:
13186 		printf("invalid port_id %d\n", res->port_id);
13187 		break;
13188 	case -ENOTSUP:
13189 		printf("function not implemented\n");
13190 		break;
13191 	default:
13192 		printf("programming error: (%s)\n", strerror(-ret));
13193 	}
13194 }
13195 
13196 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13197 	.f = cmd_vf_tc_max_bw_parsed,
13198 	.data = NULL,
13199 	.help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13200 		    " <bandwidth>",
13201 	.tokens = {
13202 		(void *)&cmd_vf_tc_bw_set,
13203 		(void *)&cmd_vf_tc_bw_vf,
13204 		(void *)&cmd_vf_tc_bw_tc,
13205 		(void *)&cmd_vf_tc_bw_tx,
13206 		(void *)&cmd_vf_tc_bw_max_bw,
13207 		(void *)&cmd_vf_tc_bw_port_id,
13208 		(void *)&cmd_vf_tc_bw_vf_id,
13209 		(void *)&cmd_vf_tc_bw_tc_no,
13210 		(void *)&cmd_vf_tc_bw_bw,
13211 		NULL,
13212 	},
13213 };
13214 
13215 /* Strict link priority scheduling mode setting */
13216 static void
13217 cmd_strict_link_prio_parsed(
13218 	void *parsed_result,
13219 	__attribute__((unused)) struct cmdline *cl,
13220 	__attribute__((unused)) void *data)
13221 {
13222 	struct cmd_vf_tc_bw_result *res = parsed_result;
13223 	int ret = -ENOTSUP;
13224 
13225 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13226 		return;
13227 
13228 #ifdef RTE_LIBRTE_I40E_PMD
13229 	ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13230 #endif
13231 
13232 	switch (ret) {
13233 	case 0:
13234 		break;
13235 	case -EINVAL:
13236 		printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13237 		break;
13238 	case -ENODEV:
13239 		printf("invalid port_id %d\n", res->port_id);
13240 		break;
13241 	case -ENOTSUP:
13242 		printf("function not implemented\n");
13243 		break;
13244 	default:
13245 		printf("programming error: (%s)\n", strerror(-ret));
13246 	}
13247 }
13248 
13249 cmdline_parse_inst_t cmd_strict_link_prio = {
13250 	.f = cmd_strict_link_prio_parsed,
13251 	.data = NULL,
13252 	.help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13253 	.tokens = {
13254 		(void *)&cmd_vf_tc_bw_set,
13255 		(void *)&cmd_vf_tc_bw_tx,
13256 		(void *)&cmd_vf_tc_bw_strict_link_prio,
13257 		(void *)&cmd_vf_tc_bw_port_id,
13258 		(void *)&cmd_vf_tc_bw_tc_map,
13259 		NULL,
13260 	},
13261 };
13262 
13263 /* Load dynamic device personalization*/
13264 struct cmd_ddp_add_result {
13265 	cmdline_fixed_string_t ddp;
13266 	cmdline_fixed_string_t add;
13267 	uint8_t port_id;
13268 	char filepath[];
13269 };
13270 
13271 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13272 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13273 cmdline_parse_token_string_t cmd_ddp_add_add =
13274 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13275 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13276 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8);
13277 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13278 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13279 
13280 static void
13281 cmd_ddp_add_parsed(
13282 	void *parsed_result,
13283 	__attribute__((unused)) struct cmdline *cl,
13284 	__attribute__((unused)) void *data)
13285 {
13286 	struct cmd_ddp_add_result *res = parsed_result;
13287 	uint8_t *buff;
13288 	uint32_t size;
13289 	char *filepath;
13290 	char *file_fld[2];
13291 	int file_num;
13292 	int ret = -ENOTSUP;
13293 
13294 	if (res->port_id > nb_ports) {
13295 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13296 		return;
13297 	}
13298 
13299 	if (!all_ports_stopped()) {
13300 		printf("Please stop all ports first\n");
13301 		return;
13302 	}
13303 
13304 	filepath = strdup(res->filepath);
13305 	if (filepath == NULL) {
13306 		printf("Failed to allocate memory\n");
13307 		return;
13308 	}
13309 	file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13310 
13311 	buff = open_ddp_package_file(file_fld[0], &size);
13312 	if (!buff) {
13313 		free((void *)filepath);
13314 		return;
13315 	}
13316 
13317 #ifdef RTE_LIBRTE_I40E_PMD
13318 	if (ret == -ENOTSUP)
13319 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13320 					       buff, size,
13321 					       RTE_PMD_I40E_PKG_OP_WR_ADD);
13322 #endif
13323 
13324 	if (ret == -EEXIST)
13325 		printf("Profile has already existed.\n");
13326 	else if (ret < 0)
13327 		printf("Failed to load profile.\n");
13328 	else if (file_num == 2)
13329 		save_ddp_package_file(file_fld[1], buff, size);
13330 
13331 	close_ddp_package_file(buff);
13332 	free((void *)filepath);
13333 }
13334 
13335 cmdline_parse_inst_t cmd_ddp_add = {
13336 	.f = cmd_ddp_add_parsed,
13337 	.data = NULL,
13338 	.help_str = "ddp add <port_id> <profile_path[,output_path]>",
13339 	.tokens = {
13340 		(void *)&cmd_ddp_add_ddp,
13341 		(void *)&cmd_ddp_add_add,
13342 		(void *)&cmd_ddp_add_port_id,
13343 		(void *)&cmd_ddp_add_filepath,
13344 		NULL,
13345 	},
13346 };
13347 
13348 /* Delete dynamic device personalization*/
13349 struct cmd_ddp_del_result {
13350 	cmdline_fixed_string_t ddp;
13351 	cmdline_fixed_string_t del;
13352 	uint8_t port_id;
13353 	char filepath[];
13354 };
13355 
13356 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13357 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13358 cmdline_parse_token_string_t cmd_ddp_del_del =
13359 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13360 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13361 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT8);
13362 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13363 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13364 
13365 static void
13366 cmd_ddp_del_parsed(
13367 	void *parsed_result,
13368 	__attribute__((unused)) struct cmdline *cl,
13369 	__attribute__((unused)) void *data)
13370 {
13371 	struct cmd_ddp_del_result *res = parsed_result;
13372 	uint8_t *buff;
13373 	uint32_t size;
13374 	int ret = -ENOTSUP;
13375 
13376 	if (res->port_id > nb_ports) {
13377 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13378 		return;
13379 	}
13380 
13381 	if (!all_ports_stopped()) {
13382 		printf("Please stop all ports first\n");
13383 		return;
13384 	}
13385 
13386 	buff = open_ddp_package_file(res->filepath, &size);
13387 	if (!buff)
13388 		return;
13389 
13390 #ifdef RTE_LIBRTE_I40E_PMD
13391 	if (ret == -ENOTSUP)
13392 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13393 					       buff, size,
13394 					       RTE_PMD_I40E_PKG_OP_WR_DEL);
13395 #endif
13396 
13397 	if (ret == -EACCES)
13398 		printf("Profile does not exist.\n");
13399 	else if (ret < 0)
13400 		printf("Failed to delete profile.\n");
13401 
13402 	close_ddp_package_file(buff);
13403 }
13404 
13405 cmdline_parse_inst_t cmd_ddp_del = {
13406 	.f = cmd_ddp_del_parsed,
13407 	.data = NULL,
13408 	.help_str = "ddp del <port_id> <profile_path>",
13409 	.tokens = {
13410 		(void *)&cmd_ddp_del_ddp,
13411 		(void *)&cmd_ddp_del_del,
13412 		(void *)&cmd_ddp_del_port_id,
13413 		(void *)&cmd_ddp_del_filepath,
13414 		NULL,
13415 	},
13416 };
13417 
13418 /* Get dynamic device personalization profile info */
13419 struct cmd_ddp_info_result {
13420 	cmdline_fixed_string_t ddp;
13421 	cmdline_fixed_string_t get;
13422 	cmdline_fixed_string_t info;
13423 	char filepath[];
13424 };
13425 
13426 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13427 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13428 cmdline_parse_token_string_t cmd_ddp_info_get =
13429 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13430 cmdline_parse_token_string_t cmd_ddp_info_info =
13431 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13432 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13433 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13434 
13435 static void
13436 cmd_ddp_info_parsed(
13437 	void *parsed_result,
13438 	__attribute__((unused)) struct cmdline *cl,
13439 	__attribute__((unused)) void *data)
13440 {
13441 	struct cmd_ddp_info_result *res = parsed_result;
13442 	uint8_t *pkg;
13443 	uint32_t pkg_size;
13444 	int ret = -ENOTSUP;
13445 #ifdef RTE_LIBRTE_I40E_PMD
13446 	uint32_t i, j, n;
13447 	uint8_t *buff;
13448 	uint32_t buff_size = 0;
13449 	struct rte_pmd_i40e_profile_info info;
13450 	uint32_t dev_num = 0;
13451 	struct rte_pmd_i40e_ddp_device_id *devs;
13452 	uint32_t proto_num = 0;
13453 	struct rte_pmd_i40e_proto_info *proto;
13454 	uint32_t pctype_num = 0;
13455 	struct rte_pmd_i40e_ptype_info *pctype;
13456 	uint32_t ptype_num = 0;
13457 	struct rte_pmd_i40e_ptype_info *ptype;
13458 	uint8_t proto_id;
13459 
13460 #endif
13461 
13462 	pkg = open_ddp_package_file(res->filepath, &pkg_size);
13463 	if (!pkg)
13464 		return;
13465 
13466 #ifdef RTE_LIBRTE_I40E_PMD
13467 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13468 				(uint8_t *)&info, sizeof(info),
13469 				RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13470 	if (!ret) {
13471 		printf("Global Track id:       0x%x\n", info.track_id);
13472 		printf("Global Version:        %d.%d.%d.%d\n",
13473 			info.version.major,
13474 			info.version.minor,
13475 			info.version.update,
13476 			info.version.draft);
13477 		printf("Global Package name:   %s\n\n", info.name);
13478 	}
13479 
13480 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13481 				(uint8_t *)&info, sizeof(info),
13482 				RTE_PMD_I40E_PKG_INFO_HEADER);
13483 	if (!ret) {
13484 		printf("i40e Profile Track id: 0x%x\n", info.track_id);
13485 		printf("i40e Profile Version:  %d.%d.%d.%d\n",
13486 			info.version.major,
13487 			info.version.minor,
13488 			info.version.update,
13489 			info.version.draft);
13490 		printf("i40e Profile name:     %s\n\n", info.name);
13491 	}
13492 
13493 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13494 				(uint8_t *)&buff_size, sizeof(buff_size),
13495 				RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13496 	if (!ret && buff_size) {
13497 		buff = (uint8_t *)malloc(buff_size);
13498 		if (buff) {
13499 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13500 						buff, buff_size,
13501 						RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13502 			if (!ret)
13503 				printf("Package Notes:\n%s\n\n", buff);
13504 			free(buff);
13505 		}
13506 	}
13507 
13508 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13509 				(uint8_t *)&dev_num, sizeof(dev_num),
13510 				RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13511 	if (!ret && dev_num) {
13512 		buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
13513 		devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
13514 		if (devs) {
13515 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13516 						(uint8_t *)devs, buff_size,
13517 						RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13518 			if (!ret) {
13519 				printf("List of supported devices:\n");
13520 				for (i = 0; i < dev_num; i++) {
13521 					printf("  %04X:%04X %04X:%04X\n",
13522 						devs[i].vendor_dev_id >> 16,
13523 						devs[i].vendor_dev_id & 0xFFFF,
13524 						devs[i].sub_vendor_dev_id >> 16,
13525 						devs[i].sub_vendor_dev_id & 0xFFFF);
13526 				}
13527 				printf("\n");
13528 			}
13529 			free(devs);
13530 		}
13531 	}
13532 
13533 	/* get information about protocols and packet types */
13534 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13535 		(uint8_t *)&proto_num, sizeof(proto_num),
13536 		RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
13537 	if (ret || !proto_num)
13538 		goto no_print_return;
13539 
13540 	buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
13541 	proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
13542 	if (!proto)
13543 		goto no_print_return;
13544 
13545 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
13546 					buff_size,
13547 					RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
13548 	if (!ret) {
13549 		printf("List of used protocols:\n");
13550 		for (i = 0; i < proto_num; i++)
13551 			printf("  %2u: %s\n", proto[i].proto_id,
13552 			       proto[i].name);
13553 		printf("\n");
13554 	}
13555 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13556 		(uint8_t *)&pctype_num, sizeof(pctype_num),
13557 		RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
13558 	if (ret || !pctype_num)
13559 		goto no_print_pctypes;
13560 
13561 	buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13562 	pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13563 	if (!pctype)
13564 		goto no_print_pctypes;
13565 
13566 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
13567 					buff_size,
13568 					RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
13569 	if (ret) {
13570 		free(pctype);
13571 		goto no_print_pctypes;
13572 	}
13573 
13574 	printf("List of defined packet classification types:\n");
13575 	for (i = 0; i < pctype_num; i++) {
13576 		printf("  %2u:", pctype[i].ptype_id);
13577 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13578 			proto_id = pctype[i].protocols[j];
13579 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13580 				for (n = 0; n < proto_num; n++) {
13581 					if (proto[n].proto_id == proto_id) {
13582 						printf(" %s", proto[n].name);
13583 						break;
13584 					}
13585 				}
13586 			}
13587 		}
13588 		printf("\n");
13589 	}
13590 	printf("\n");
13591 	free(pctype);
13592 
13593 no_print_pctypes:
13594 
13595 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
13596 					sizeof(ptype_num),
13597 					RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
13598 	if (ret || !ptype_num)
13599 		goto no_print_return;
13600 
13601 	buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13602 	ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13603 	if (!ptype)
13604 		goto no_print_return;
13605 
13606 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
13607 					buff_size,
13608 					RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
13609 	if (ret) {
13610 		free(ptype);
13611 		goto no_print_return;
13612 	}
13613 	printf("List of defined packet types:\n");
13614 	for (i = 0; i < ptype_num; i++) {
13615 		printf("  %2u:", ptype[i].ptype_id);
13616 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13617 			proto_id = ptype[i].protocols[j];
13618 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13619 				for (n = 0; n < proto_num; n++) {
13620 					if (proto[n].proto_id == proto_id) {
13621 						printf(" %s", proto[n].name);
13622 						break;
13623 					}
13624 				}
13625 			}
13626 		}
13627 		printf("\n");
13628 	}
13629 	free(ptype);
13630 	printf("\n");
13631 
13632 	free(proto);
13633 	ret = 0;
13634 #endif
13635 no_print_return:
13636 	if (ret == -ENOTSUP)
13637 		printf("Function not supported in PMD driver\n");
13638 	close_ddp_package_file(pkg);
13639 }
13640 
13641 cmdline_parse_inst_t cmd_ddp_get_info = {
13642 	.f = cmd_ddp_info_parsed,
13643 	.data = NULL,
13644 	.help_str = "ddp get info <profile_path>",
13645 	.tokens = {
13646 		(void *)&cmd_ddp_info_ddp,
13647 		(void *)&cmd_ddp_info_get,
13648 		(void *)&cmd_ddp_info_info,
13649 		(void *)&cmd_ddp_info_filepath,
13650 		NULL,
13651 	},
13652 };
13653 
13654 /* Get dynamic device personalization profile info list*/
13655 #define PROFILE_INFO_SIZE 48
13656 #define MAX_PROFILE_NUM 16
13657 
13658 struct cmd_ddp_get_list_result {
13659 	cmdline_fixed_string_t ddp;
13660 	cmdline_fixed_string_t get;
13661 	cmdline_fixed_string_t list;
13662 	uint8_t port_id;
13663 };
13664 
13665 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
13666 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
13667 cmdline_parse_token_string_t cmd_ddp_get_list_get =
13668 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
13669 cmdline_parse_token_string_t cmd_ddp_get_list_list =
13670 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
13671 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
13672 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8);
13673 
13674 static void
13675 cmd_ddp_get_list_parsed(
13676 	void *parsed_result,
13677 	__attribute__((unused)) struct cmdline *cl,
13678 	__attribute__((unused)) void *data)
13679 {
13680 	struct cmd_ddp_get_list_result *res = parsed_result;
13681 #ifdef RTE_LIBRTE_I40E_PMD
13682 	struct rte_pmd_i40e_profile_list *p_list;
13683 	struct rte_pmd_i40e_profile_info *p_info;
13684 	uint32_t p_num;
13685 	uint32_t size;
13686 	uint32_t i;
13687 #endif
13688 	int ret = -ENOTSUP;
13689 
13690 	if (res->port_id > nb_ports) {
13691 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13692 		return;
13693 	}
13694 
13695 #ifdef RTE_LIBRTE_I40E_PMD
13696 	size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
13697 	p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
13698 	if (!p_list)
13699 		printf("%s: Failed to malloc buffer\n", __func__);
13700 
13701 	if (ret == -ENOTSUP)
13702 		ret = rte_pmd_i40e_get_ddp_list(res->port_id,
13703 						(uint8_t *)p_list, size);
13704 
13705 	if (!ret) {
13706 		p_num = p_list->p_count;
13707 		printf("Profile number is: %d\n\n", p_num);
13708 
13709 		for (i = 0; i < p_num; i++) {
13710 			p_info = &p_list->p_info[i];
13711 			printf("Profile %d:\n", i);
13712 			printf("Track id:     0x%x\n", p_info->track_id);
13713 			printf("Version:      %d.%d.%d.%d\n",
13714 			       p_info->version.major,
13715 			       p_info->version.minor,
13716 			       p_info->version.update,
13717 			       p_info->version.draft);
13718 			printf("Profile name: %s\n\n", p_info->name);
13719 		}
13720 	}
13721 
13722 	free(p_list);
13723 #endif
13724 
13725 	if (ret < 0)
13726 		printf("Failed to get ddp list\n");
13727 }
13728 
13729 cmdline_parse_inst_t cmd_ddp_get_list = {
13730 	.f = cmd_ddp_get_list_parsed,
13731 	.data = NULL,
13732 	.help_str = "ddp get list <port_id>",
13733 	.tokens = {
13734 		(void *)&cmd_ddp_get_list_ddp,
13735 		(void *)&cmd_ddp_get_list_get,
13736 		(void *)&cmd_ddp_get_list_list,
13737 		(void *)&cmd_ddp_get_list_port_id,
13738 		NULL,
13739 	},
13740 };
13741 
13742 /* show vf stats */
13743 
13744 /* Common result structure for show vf stats */
13745 struct cmd_show_vf_stats_result {
13746 	cmdline_fixed_string_t show;
13747 	cmdline_fixed_string_t vf;
13748 	cmdline_fixed_string_t stats;
13749 	uint8_t port_id;
13750 	uint16_t vf_id;
13751 };
13752 
13753 /* Common CLI fields show vf stats*/
13754 cmdline_parse_token_string_t cmd_show_vf_stats_show =
13755 	TOKEN_STRING_INITIALIZER
13756 		(struct cmd_show_vf_stats_result,
13757 		 show, "show");
13758 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
13759 	TOKEN_STRING_INITIALIZER
13760 		(struct cmd_show_vf_stats_result,
13761 		 vf, "vf");
13762 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
13763 	TOKEN_STRING_INITIALIZER
13764 		(struct cmd_show_vf_stats_result,
13765 		 stats, "stats");
13766 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
13767 	TOKEN_NUM_INITIALIZER
13768 		(struct cmd_show_vf_stats_result,
13769 		 port_id, UINT8);
13770 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
13771 	TOKEN_NUM_INITIALIZER
13772 		(struct cmd_show_vf_stats_result,
13773 		 vf_id, UINT16);
13774 
13775 static void
13776 cmd_show_vf_stats_parsed(
13777 	void *parsed_result,
13778 	__attribute__((unused)) struct cmdline *cl,
13779 	__attribute__((unused)) void *data)
13780 {
13781 	struct cmd_show_vf_stats_result *res = parsed_result;
13782 	struct rte_eth_stats stats;
13783 	int ret = -ENOTSUP;
13784 	static const char *nic_stats_border = "########################";
13785 
13786 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13787 		return;
13788 
13789 	memset(&stats, 0, sizeof(stats));
13790 
13791 #ifdef RTE_LIBRTE_I40E_PMD
13792 	if (ret == -ENOTSUP)
13793 		ret = rte_pmd_i40e_get_vf_stats(res->port_id,
13794 						res->vf_id,
13795 						&stats);
13796 #endif
13797 #ifdef RTE_LIBRTE_BNXT_PMD
13798 	if (ret == -ENOTSUP)
13799 		ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
13800 						res->vf_id,
13801 						&stats);
13802 #endif
13803 
13804 	switch (ret) {
13805 	case 0:
13806 		break;
13807 	case -EINVAL:
13808 		printf("invalid vf_id %d\n", res->vf_id);
13809 		break;
13810 	case -ENODEV:
13811 		printf("invalid port_id %d\n", res->port_id);
13812 		break;
13813 	case -ENOTSUP:
13814 		printf("function not implemented\n");
13815 		break;
13816 	default:
13817 		printf("programming error: (%s)\n", strerror(-ret));
13818 	}
13819 
13820 	printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
13821 		nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
13822 
13823 	printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
13824 	       "%-"PRIu64"\n",
13825 	       stats.ipackets, stats.imissed, stats.ibytes);
13826 	printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
13827 	printf("  RX-nombuf:  %-10"PRIu64"\n",
13828 	       stats.rx_nombuf);
13829 	printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
13830 	       "%-"PRIu64"\n",
13831 	       stats.opackets, stats.oerrors, stats.obytes);
13832 
13833 	printf("  %s############################%s\n",
13834 			       nic_stats_border, nic_stats_border);
13835 }
13836 
13837 cmdline_parse_inst_t cmd_show_vf_stats = {
13838 	.f = cmd_show_vf_stats_parsed,
13839 	.data = NULL,
13840 	.help_str = "show vf stats <port_id> <vf_id>",
13841 	.tokens = {
13842 		(void *)&cmd_show_vf_stats_show,
13843 		(void *)&cmd_show_vf_stats_vf,
13844 		(void *)&cmd_show_vf_stats_stats,
13845 		(void *)&cmd_show_vf_stats_port_id,
13846 		(void *)&cmd_show_vf_stats_vf_id,
13847 		NULL,
13848 	},
13849 };
13850 
13851 /* clear vf stats */
13852 
13853 /* Common result structure for clear vf stats */
13854 struct cmd_clear_vf_stats_result {
13855 	cmdline_fixed_string_t clear;
13856 	cmdline_fixed_string_t vf;
13857 	cmdline_fixed_string_t stats;
13858 	uint8_t port_id;
13859 	uint16_t vf_id;
13860 };
13861 
13862 /* Common CLI fields clear vf stats*/
13863 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
13864 	TOKEN_STRING_INITIALIZER
13865 		(struct cmd_clear_vf_stats_result,
13866 		 clear, "clear");
13867 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
13868 	TOKEN_STRING_INITIALIZER
13869 		(struct cmd_clear_vf_stats_result,
13870 		 vf, "vf");
13871 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
13872 	TOKEN_STRING_INITIALIZER
13873 		(struct cmd_clear_vf_stats_result,
13874 		 stats, "stats");
13875 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
13876 	TOKEN_NUM_INITIALIZER
13877 		(struct cmd_clear_vf_stats_result,
13878 		 port_id, UINT8);
13879 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
13880 	TOKEN_NUM_INITIALIZER
13881 		(struct cmd_clear_vf_stats_result,
13882 		 vf_id, UINT16);
13883 
13884 static void
13885 cmd_clear_vf_stats_parsed(
13886 	void *parsed_result,
13887 	__attribute__((unused)) struct cmdline *cl,
13888 	__attribute__((unused)) void *data)
13889 {
13890 	struct cmd_clear_vf_stats_result *res = parsed_result;
13891 	int ret = -ENOTSUP;
13892 
13893 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13894 		return;
13895 
13896 #ifdef RTE_LIBRTE_I40E_PMD
13897 	if (ret == -ENOTSUP)
13898 		ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
13899 						  res->vf_id);
13900 #endif
13901 #ifdef RTE_LIBRTE_BNXT_PMD
13902 	if (ret == -ENOTSUP)
13903 		ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
13904 						  res->vf_id);
13905 #endif
13906 
13907 	switch (ret) {
13908 	case 0:
13909 		break;
13910 	case -EINVAL:
13911 		printf("invalid vf_id %d\n", res->vf_id);
13912 		break;
13913 	case -ENODEV:
13914 		printf("invalid port_id %d\n", res->port_id);
13915 		break;
13916 	case -ENOTSUP:
13917 		printf("function not implemented\n");
13918 		break;
13919 	default:
13920 		printf("programming error: (%s)\n", strerror(-ret));
13921 	}
13922 }
13923 
13924 cmdline_parse_inst_t cmd_clear_vf_stats = {
13925 	.f = cmd_clear_vf_stats_parsed,
13926 	.data = NULL,
13927 	.help_str = "clear vf stats <port_id> <vf_id>",
13928 	.tokens = {
13929 		(void *)&cmd_clear_vf_stats_clear,
13930 		(void *)&cmd_clear_vf_stats_vf,
13931 		(void *)&cmd_clear_vf_stats_stats,
13932 		(void *)&cmd_clear_vf_stats_port_id,
13933 		(void *)&cmd_clear_vf_stats_vf_id,
13934 		NULL,
13935 	},
13936 };
13937 
13938 /* port config pctype mapping reset */
13939 
13940 /* Common result structure for port config pctype mapping reset */
13941 struct cmd_pctype_mapping_reset_result {
13942 	cmdline_fixed_string_t port;
13943 	cmdline_fixed_string_t config;
13944 	uint8_t port_id;
13945 	cmdline_fixed_string_t pctype;
13946 	cmdline_fixed_string_t mapping;
13947 	cmdline_fixed_string_t reset;
13948 };
13949 
13950 /* Common CLI fields for port config pctype mapping reset*/
13951 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
13952 	TOKEN_STRING_INITIALIZER
13953 		(struct cmd_pctype_mapping_reset_result,
13954 		 port, "port");
13955 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
13956 	TOKEN_STRING_INITIALIZER
13957 		(struct cmd_pctype_mapping_reset_result,
13958 		 config, "config");
13959 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
13960 	TOKEN_NUM_INITIALIZER
13961 		(struct cmd_pctype_mapping_reset_result,
13962 		 port_id, UINT8);
13963 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
13964 	TOKEN_STRING_INITIALIZER
13965 		(struct cmd_pctype_mapping_reset_result,
13966 		 pctype, "pctype");
13967 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
13968 	TOKEN_STRING_INITIALIZER
13969 		(struct cmd_pctype_mapping_reset_result,
13970 		 mapping, "mapping");
13971 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
13972 	TOKEN_STRING_INITIALIZER
13973 		(struct cmd_pctype_mapping_reset_result,
13974 		 reset, "reset");
13975 
13976 static void
13977 cmd_pctype_mapping_reset_parsed(
13978 	void *parsed_result,
13979 	__attribute__((unused)) struct cmdline *cl,
13980 	__attribute__((unused)) void *data)
13981 {
13982 	struct cmd_pctype_mapping_reset_result *res = parsed_result;
13983 	int ret = -ENOTSUP;
13984 
13985 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13986 		return;
13987 
13988 #ifdef RTE_LIBRTE_I40E_PMD
13989 	ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
13990 #endif
13991 
13992 	switch (ret) {
13993 	case 0:
13994 		break;
13995 	case -ENODEV:
13996 		printf("invalid port_id %d\n", res->port_id);
13997 		break;
13998 	case -ENOTSUP:
13999 		printf("function not implemented\n");
14000 		break;
14001 	default:
14002 		printf("programming error: (%s)\n", strerror(-ret));
14003 	}
14004 }
14005 
14006 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14007 	.f = cmd_pctype_mapping_reset_parsed,
14008 	.data = NULL,
14009 	.help_str = "port config <port_id> pctype mapping reset",
14010 	.tokens = {
14011 		(void *)&cmd_pctype_mapping_reset_port,
14012 		(void *)&cmd_pctype_mapping_reset_config,
14013 		(void *)&cmd_pctype_mapping_reset_port_id,
14014 		(void *)&cmd_pctype_mapping_reset_pctype,
14015 		(void *)&cmd_pctype_mapping_reset_mapping,
14016 		(void *)&cmd_pctype_mapping_reset_reset,
14017 		NULL,
14018 	},
14019 };
14020 
14021 /* show port pctype mapping */
14022 
14023 /* Common result structure for show port pctype mapping */
14024 struct cmd_pctype_mapping_get_result {
14025 	cmdline_fixed_string_t show;
14026 	cmdline_fixed_string_t port;
14027 	uint8_t port_id;
14028 	cmdline_fixed_string_t pctype;
14029 	cmdline_fixed_string_t mapping;
14030 };
14031 
14032 /* Common CLI fields for pctype mapping get */
14033 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14034 	TOKEN_STRING_INITIALIZER
14035 		(struct cmd_pctype_mapping_get_result,
14036 		 show, "show");
14037 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14038 	TOKEN_STRING_INITIALIZER
14039 		(struct cmd_pctype_mapping_get_result,
14040 		 port, "port");
14041 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14042 	TOKEN_NUM_INITIALIZER
14043 		(struct cmd_pctype_mapping_get_result,
14044 		 port_id, UINT8);
14045 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14046 	TOKEN_STRING_INITIALIZER
14047 		(struct cmd_pctype_mapping_get_result,
14048 		 pctype, "pctype");
14049 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14050 	TOKEN_STRING_INITIALIZER
14051 		(struct cmd_pctype_mapping_get_result,
14052 		 mapping, "mapping");
14053 
14054 static void
14055 cmd_pctype_mapping_get_parsed(
14056 	void *parsed_result,
14057 	__attribute__((unused)) struct cmdline *cl,
14058 	__attribute__((unused)) void *data)
14059 {
14060 	struct cmd_pctype_mapping_get_result *res = parsed_result;
14061 	int ret = -ENOTSUP;
14062 #ifdef RTE_LIBRTE_I40E_PMD
14063 	struct rte_pmd_i40e_flow_type_mapping
14064 				mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14065 	int i, j, first_pctype;
14066 #endif
14067 
14068 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14069 		return;
14070 
14071 #ifdef RTE_LIBRTE_I40E_PMD
14072 	ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14073 #endif
14074 
14075 	switch (ret) {
14076 	case 0:
14077 		break;
14078 	case -ENODEV:
14079 		printf("invalid port_id %d\n", res->port_id);
14080 		return;
14081 	case -ENOTSUP:
14082 		printf("function not implemented\n");
14083 		return;
14084 	default:
14085 		printf("programming error: (%s)\n", strerror(-ret));
14086 		return;
14087 	}
14088 
14089 #ifdef RTE_LIBRTE_I40E_PMD
14090 	for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14091 		if (mapping[i].pctype != 0ULL) {
14092 			first_pctype = 1;
14093 
14094 			printf("pctype: ");
14095 			for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14096 				if (mapping[i].pctype & (1ULL << j)) {
14097 					printf(first_pctype ?
14098 					       "%02d" : ",%02d", j);
14099 					first_pctype = 0;
14100 				}
14101 			}
14102 			printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14103 		}
14104 	}
14105 #endif
14106 }
14107 
14108 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14109 	.f = cmd_pctype_mapping_get_parsed,
14110 	.data = NULL,
14111 	.help_str = "show port <port_id> pctype mapping",
14112 	.tokens = {
14113 		(void *)&cmd_pctype_mapping_get_show,
14114 		(void *)&cmd_pctype_mapping_get_port,
14115 		(void *)&cmd_pctype_mapping_get_port_id,
14116 		(void *)&cmd_pctype_mapping_get_pctype,
14117 		(void *)&cmd_pctype_mapping_get_mapping,
14118 		NULL,
14119 	},
14120 };
14121 
14122 /* port config pctype mapping update */
14123 
14124 /* Common result structure for port config pctype mapping update */
14125 struct cmd_pctype_mapping_update_result {
14126 	cmdline_fixed_string_t port;
14127 	cmdline_fixed_string_t config;
14128 	uint8_t port_id;
14129 	cmdline_fixed_string_t pctype;
14130 	cmdline_fixed_string_t mapping;
14131 	cmdline_fixed_string_t update;
14132 	cmdline_fixed_string_t pctype_list;
14133 	uint16_t flow_type;
14134 };
14135 
14136 /* Common CLI fields for pctype mapping update*/
14137 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14138 	TOKEN_STRING_INITIALIZER
14139 		(struct cmd_pctype_mapping_update_result,
14140 		 port, "port");
14141 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14142 	TOKEN_STRING_INITIALIZER
14143 		(struct cmd_pctype_mapping_update_result,
14144 		 config, "config");
14145 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14146 	TOKEN_NUM_INITIALIZER
14147 		(struct cmd_pctype_mapping_update_result,
14148 		 port_id, UINT8);
14149 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14150 	TOKEN_STRING_INITIALIZER
14151 		(struct cmd_pctype_mapping_update_result,
14152 		 pctype, "pctype");
14153 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14154 	TOKEN_STRING_INITIALIZER
14155 		(struct cmd_pctype_mapping_update_result,
14156 		 mapping, "mapping");
14157 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14158 	TOKEN_STRING_INITIALIZER
14159 		(struct cmd_pctype_mapping_update_result,
14160 		 update, "update");
14161 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14162 	TOKEN_STRING_INITIALIZER
14163 		(struct cmd_pctype_mapping_update_result,
14164 		 pctype_list, NULL);
14165 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14166 	TOKEN_NUM_INITIALIZER
14167 		(struct cmd_pctype_mapping_update_result,
14168 		 flow_type, UINT16);
14169 
14170 static void
14171 cmd_pctype_mapping_update_parsed(
14172 	void *parsed_result,
14173 	__attribute__((unused)) struct cmdline *cl,
14174 	__attribute__((unused)) void *data)
14175 {
14176 	struct cmd_pctype_mapping_update_result *res = parsed_result;
14177 	int ret = -ENOTSUP;
14178 #ifdef RTE_LIBRTE_I40E_PMD
14179 	struct rte_pmd_i40e_flow_type_mapping mapping;
14180 	unsigned int i;
14181 #endif
14182 	unsigned int nb_item;
14183 	unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14184 
14185 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14186 		return;
14187 
14188 	nb_item = parse_item_list(res->pctype_list, "pctypes",
14189 				  RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14190 
14191 #ifdef RTE_LIBRTE_I40E_PMD
14192 	mapping.flow_type = res->flow_type;
14193 	for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14194 		mapping.pctype |= (1ULL << pctype_list[i]);
14195 	ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14196 						&mapping,
14197 						1,
14198 						0);
14199 #endif
14200 
14201 	switch (ret) {
14202 	case 0:
14203 		break;
14204 	case -EINVAL:
14205 		printf("invalid pctype or flow type\n");
14206 		break;
14207 	case -ENODEV:
14208 		printf("invalid port_id %d\n", res->port_id);
14209 		break;
14210 	case -ENOTSUP:
14211 		printf("function not implemented\n");
14212 		break;
14213 	default:
14214 		printf("programming error: (%s)\n", strerror(-ret));
14215 	}
14216 }
14217 
14218 cmdline_parse_inst_t cmd_pctype_mapping_update = {
14219 	.f = cmd_pctype_mapping_update_parsed,
14220 	.data = NULL,
14221 	.help_str = "port config <port_id> pctype mapping update"
14222 	" <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
14223 	.tokens = {
14224 		(void *)&cmd_pctype_mapping_update_port,
14225 		(void *)&cmd_pctype_mapping_update_config,
14226 		(void *)&cmd_pctype_mapping_update_port_id,
14227 		(void *)&cmd_pctype_mapping_update_pctype,
14228 		(void *)&cmd_pctype_mapping_update_mapping,
14229 		(void *)&cmd_pctype_mapping_update_update,
14230 		(void *)&cmd_pctype_mapping_update_pc_type,
14231 		(void *)&cmd_pctype_mapping_update_flow_type,
14232 		NULL,
14233 	},
14234 };
14235 
14236 /* ptype mapping get */
14237 
14238 /* Common result structure for ptype mapping get */
14239 struct cmd_ptype_mapping_get_result {
14240 	cmdline_fixed_string_t ptype;
14241 	cmdline_fixed_string_t mapping;
14242 	cmdline_fixed_string_t get;
14243 	uint8_t port_id;
14244 	uint8_t valid_only;
14245 };
14246 
14247 /* Common CLI fields for ptype mapping get */
14248 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
14249 	TOKEN_STRING_INITIALIZER
14250 		(struct cmd_ptype_mapping_get_result,
14251 		 ptype, "ptype");
14252 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
14253 	TOKEN_STRING_INITIALIZER
14254 		(struct cmd_ptype_mapping_get_result,
14255 		 mapping, "mapping");
14256 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
14257 	TOKEN_STRING_INITIALIZER
14258 		(struct cmd_ptype_mapping_get_result,
14259 		 get, "get");
14260 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
14261 	TOKEN_NUM_INITIALIZER
14262 		(struct cmd_ptype_mapping_get_result,
14263 		 port_id, UINT8);
14264 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
14265 	TOKEN_NUM_INITIALIZER
14266 		(struct cmd_ptype_mapping_get_result,
14267 		 valid_only, UINT8);
14268 
14269 static void
14270 cmd_ptype_mapping_get_parsed(
14271 	void *parsed_result,
14272 	__attribute__((unused)) struct cmdline *cl,
14273 	__attribute__((unused)) void *data)
14274 {
14275 	struct cmd_ptype_mapping_get_result *res = parsed_result;
14276 	int ret = -ENOTSUP;
14277 #ifdef RTE_LIBRTE_I40E_PMD
14278 	int max_ptype_num = 256;
14279 	struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
14280 	uint16_t count;
14281 	int i;
14282 #endif
14283 
14284 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14285 		return;
14286 
14287 #ifdef RTE_LIBRTE_I40E_PMD
14288 	ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
14289 					mapping,
14290 					max_ptype_num,
14291 					&count,
14292 					res->valid_only);
14293 #endif
14294 
14295 	switch (ret) {
14296 	case 0:
14297 		break;
14298 	case -ENODEV:
14299 		printf("invalid port_id %d\n", res->port_id);
14300 		break;
14301 	case -ENOTSUP:
14302 		printf("function not implemented\n");
14303 		break;
14304 	default:
14305 		printf("programming error: (%s)\n", strerror(-ret));
14306 	}
14307 
14308 #ifdef RTE_LIBRTE_I40E_PMD
14309 	if (!ret) {
14310 		for (i = 0; i < count; i++)
14311 			printf("%3d\t0x%08x\n",
14312 				mapping[i].hw_ptype, mapping[i].sw_ptype);
14313 	}
14314 #endif
14315 }
14316 
14317 cmdline_parse_inst_t cmd_ptype_mapping_get = {
14318 	.f = cmd_ptype_mapping_get_parsed,
14319 	.data = NULL,
14320 	.help_str = "ptype mapping get <port_id> <valid_only>",
14321 	.tokens = {
14322 		(void *)&cmd_ptype_mapping_get_ptype,
14323 		(void *)&cmd_ptype_mapping_get_mapping,
14324 		(void *)&cmd_ptype_mapping_get_get,
14325 		(void *)&cmd_ptype_mapping_get_port_id,
14326 		(void *)&cmd_ptype_mapping_get_valid_only,
14327 		NULL,
14328 	},
14329 };
14330 
14331 /* ptype mapping replace */
14332 
14333 /* Common result structure for ptype mapping replace */
14334 struct cmd_ptype_mapping_replace_result {
14335 	cmdline_fixed_string_t ptype;
14336 	cmdline_fixed_string_t mapping;
14337 	cmdline_fixed_string_t replace;
14338 	uint8_t port_id;
14339 	uint32_t target;
14340 	uint8_t mask;
14341 	uint32_t pkt_type;
14342 };
14343 
14344 /* Common CLI fields for ptype mapping replace */
14345 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
14346 	TOKEN_STRING_INITIALIZER
14347 		(struct cmd_ptype_mapping_replace_result,
14348 		 ptype, "ptype");
14349 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
14350 	TOKEN_STRING_INITIALIZER
14351 		(struct cmd_ptype_mapping_replace_result,
14352 		 mapping, "mapping");
14353 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
14354 	TOKEN_STRING_INITIALIZER
14355 		(struct cmd_ptype_mapping_replace_result,
14356 		 replace, "replace");
14357 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
14358 	TOKEN_NUM_INITIALIZER
14359 		(struct cmd_ptype_mapping_replace_result,
14360 		 port_id, UINT8);
14361 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
14362 	TOKEN_NUM_INITIALIZER
14363 		(struct cmd_ptype_mapping_replace_result,
14364 		 target, UINT32);
14365 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
14366 	TOKEN_NUM_INITIALIZER
14367 		(struct cmd_ptype_mapping_replace_result,
14368 		 mask, UINT8);
14369 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
14370 	TOKEN_NUM_INITIALIZER
14371 		(struct cmd_ptype_mapping_replace_result,
14372 		 pkt_type, UINT32);
14373 
14374 static void
14375 cmd_ptype_mapping_replace_parsed(
14376 	void *parsed_result,
14377 	__attribute__((unused)) struct cmdline *cl,
14378 	__attribute__((unused)) void *data)
14379 {
14380 	struct cmd_ptype_mapping_replace_result *res = parsed_result;
14381 	int ret = -ENOTSUP;
14382 
14383 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14384 		return;
14385 
14386 #ifdef RTE_LIBRTE_I40E_PMD
14387 	ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
14388 					res->target,
14389 					res->mask,
14390 					res->pkt_type);
14391 #endif
14392 
14393 	switch (ret) {
14394 	case 0:
14395 		break;
14396 	case -EINVAL:
14397 		printf("invalid ptype 0x%8x or 0x%8x\n",
14398 				res->target, res->pkt_type);
14399 		break;
14400 	case -ENODEV:
14401 		printf("invalid port_id %d\n", res->port_id);
14402 		break;
14403 	case -ENOTSUP:
14404 		printf("function not implemented\n");
14405 		break;
14406 	default:
14407 		printf("programming error: (%s)\n", strerror(-ret));
14408 	}
14409 }
14410 
14411 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
14412 	.f = cmd_ptype_mapping_replace_parsed,
14413 	.data = NULL,
14414 	.help_str =
14415 		"ptype mapping replace <port_id> <target> <mask> <pkt_type>",
14416 	.tokens = {
14417 		(void *)&cmd_ptype_mapping_replace_ptype,
14418 		(void *)&cmd_ptype_mapping_replace_mapping,
14419 		(void *)&cmd_ptype_mapping_replace_replace,
14420 		(void *)&cmd_ptype_mapping_replace_port_id,
14421 		(void *)&cmd_ptype_mapping_replace_target,
14422 		(void *)&cmd_ptype_mapping_replace_mask,
14423 		(void *)&cmd_ptype_mapping_replace_pkt_type,
14424 		NULL,
14425 	},
14426 };
14427 
14428 /* ptype mapping reset */
14429 
14430 /* Common result structure for ptype mapping reset */
14431 struct cmd_ptype_mapping_reset_result {
14432 	cmdline_fixed_string_t ptype;
14433 	cmdline_fixed_string_t mapping;
14434 	cmdline_fixed_string_t reset;
14435 	uint8_t port_id;
14436 };
14437 
14438 /* Common CLI fields for ptype mapping reset*/
14439 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
14440 	TOKEN_STRING_INITIALIZER
14441 		(struct cmd_ptype_mapping_reset_result,
14442 		 ptype, "ptype");
14443 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
14444 	TOKEN_STRING_INITIALIZER
14445 		(struct cmd_ptype_mapping_reset_result,
14446 		 mapping, "mapping");
14447 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
14448 	TOKEN_STRING_INITIALIZER
14449 		(struct cmd_ptype_mapping_reset_result,
14450 		 reset, "reset");
14451 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
14452 	TOKEN_NUM_INITIALIZER
14453 		(struct cmd_ptype_mapping_reset_result,
14454 		 port_id, UINT8);
14455 
14456 static void
14457 cmd_ptype_mapping_reset_parsed(
14458 	void *parsed_result,
14459 	__attribute__((unused)) struct cmdline *cl,
14460 	__attribute__((unused)) void *data)
14461 {
14462 	struct cmd_ptype_mapping_reset_result *res = parsed_result;
14463 	int ret = -ENOTSUP;
14464 
14465 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14466 		return;
14467 
14468 #ifdef RTE_LIBRTE_I40E_PMD
14469 	ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
14470 #endif
14471 
14472 	switch (ret) {
14473 	case 0:
14474 		break;
14475 	case -ENODEV:
14476 		printf("invalid port_id %d\n", res->port_id);
14477 		break;
14478 	case -ENOTSUP:
14479 		printf("function not implemented\n");
14480 		break;
14481 	default:
14482 		printf("programming error: (%s)\n", strerror(-ret));
14483 	}
14484 }
14485 
14486 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
14487 	.f = cmd_ptype_mapping_reset_parsed,
14488 	.data = NULL,
14489 	.help_str = "ptype mapping reset <port_id>",
14490 	.tokens = {
14491 		(void *)&cmd_ptype_mapping_reset_ptype,
14492 		(void *)&cmd_ptype_mapping_reset_mapping,
14493 		(void *)&cmd_ptype_mapping_reset_reset,
14494 		(void *)&cmd_ptype_mapping_reset_port_id,
14495 		NULL,
14496 	},
14497 };
14498 
14499 /* ptype mapping update */
14500 
14501 /* Common result structure for ptype mapping update */
14502 struct cmd_ptype_mapping_update_result {
14503 	cmdline_fixed_string_t ptype;
14504 	cmdline_fixed_string_t mapping;
14505 	cmdline_fixed_string_t reset;
14506 	uint8_t port_id;
14507 	uint8_t hw_ptype;
14508 	uint32_t sw_ptype;
14509 };
14510 
14511 /* Common CLI fields for ptype mapping update*/
14512 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
14513 	TOKEN_STRING_INITIALIZER
14514 		(struct cmd_ptype_mapping_update_result,
14515 		 ptype, "ptype");
14516 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
14517 	TOKEN_STRING_INITIALIZER
14518 		(struct cmd_ptype_mapping_update_result,
14519 		 mapping, "mapping");
14520 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
14521 	TOKEN_STRING_INITIALIZER
14522 		(struct cmd_ptype_mapping_update_result,
14523 		 reset, "update");
14524 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
14525 	TOKEN_NUM_INITIALIZER
14526 		(struct cmd_ptype_mapping_update_result,
14527 		 port_id, UINT8);
14528 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
14529 	TOKEN_NUM_INITIALIZER
14530 		(struct cmd_ptype_mapping_update_result,
14531 		 hw_ptype, UINT8);
14532 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
14533 	TOKEN_NUM_INITIALIZER
14534 		(struct cmd_ptype_mapping_update_result,
14535 		 sw_ptype, UINT32);
14536 
14537 static void
14538 cmd_ptype_mapping_update_parsed(
14539 	void *parsed_result,
14540 	__attribute__((unused)) struct cmdline *cl,
14541 	__attribute__((unused)) void *data)
14542 {
14543 	struct cmd_ptype_mapping_update_result *res = parsed_result;
14544 	int ret = -ENOTSUP;
14545 #ifdef RTE_LIBRTE_I40E_PMD
14546 	struct rte_pmd_i40e_ptype_mapping mapping;
14547 #endif
14548 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14549 		return;
14550 
14551 #ifdef RTE_LIBRTE_I40E_PMD
14552 	mapping.hw_ptype = res->hw_ptype;
14553 	mapping.sw_ptype = res->sw_ptype;
14554 	ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
14555 						&mapping,
14556 						1,
14557 						0);
14558 #endif
14559 
14560 	switch (ret) {
14561 	case 0:
14562 		break;
14563 	case -EINVAL:
14564 		printf("invalid ptype 0x%8x\n", res->sw_ptype);
14565 		break;
14566 	case -ENODEV:
14567 		printf("invalid port_id %d\n", res->port_id);
14568 		break;
14569 	case -ENOTSUP:
14570 		printf("function not implemented\n");
14571 		break;
14572 	default:
14573 		printf("programming error: (%s)\n", strerror(-ret));
14574 	}
14575 }
14576 
14577 cmdline_parse_inst_t cmd_ptype_mapping_update = {
14578 	.f = cmd_ptype_mapping_update_parsed,
14579 	.data = NULL,
14580 	.help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
14581 	.tokens = {
14582 		(void *)&cmd_ptype_mapping_update_ptype,
14583 		(void *)&cmd_ptype_mapping_update_mapping,
14584 		(void *)&cmd_ptype_mapping_update_update,
14585 		(void *)&cmd_ptype_mapping_update_port_id,
14586 		(void *)&cmd_ptype_mapping_update_hw_ptype,
14587 		(void *)&cmd_ptype_mapping_update_sw_ptype,
14588 		NULL,
14589 	},
14590 };
14591 
14592 /* Common result structure for file commands */
14593 struct cmd_cmdfile_result {
14594 	cmdline_fixed_string_t load;
14595 	cmdline_fixed_string_t filename;
14596 };
14597 
14598 /* Common CLI fields for file commands */
14599 cmdline_parse_token_string_t cmd_load_cmdfile =
14600 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
14601 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
14602 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
14603 
14604 static void
14605 cmd_load_from_file_parsed(
14606 	void *parsed_result,
14607 	__attribute__((unused)) struct cmdline *cl,
14608 	__attribute__((unused)) void *data)
14609 {
14610 	struct cmd_cmdfile_result *res = parsed_result;
14611 
14612 	cmdline_read_from_file(res->filename);
14613 }
14614 
14615 cmdline_parse_inst_t cmd_load_from_file = {
14616 	.f = cmd_load_from_file_parsed,
14617 	.data = NULL,
14618 	.help_str = "load <filename>",
14619 	.tokens = {
14620 		(void *)&cmd_load_cmdfile,
14621 		(void *)&cmd_load_cmdfile_filename,
14622 		NULL,
14623 	},
14624 };
14625 
14626 /* ******************************************************************************** */
14627 
14628 /* list of instructions */
14629 cmdline_parse_ctx_t main_ctx[] = {
14630 	(cmdline_parse_inst_t *)&cmd_help_brief,
14631 	(cmdline_parse_inst_t *)&cmd_help_long,
14632 	(cmdline_parse_inst_t *)&cmd_quit,
14633 	(cmdline_parse_inst_t *)&cmd_load_from_file,
14634 	(cmdline_parse_inst_t *)&cmd_showport,
14635 	(cmdline_parse_inst_t *)&cmd_showqueue,
14636 	(cmdline_parse_inst_t *)&cmd_showportall,
14637 	(cmdline_parse_inst_t *)&cmd_showcfg,
14638 	(cmdline_parse_inst_t *)&cmd_start,
14639 	(cmdline_parse_inst_t *)&cmd_start_tx_first,
14640 	(cmdline_parse_inst_t *)&cmd_start_tx_first_n,
14641 	(cmdline_parse_inst_t *)&cmd_set_link_up,
14642 	(cmdline_parse_inst_t *)&cmd_set_link_down,
14643 	(cmdline_parse_inst_t *)&cmd_reset,
14644 	(cmdline_parse_inst_t *)&cmd_set_numbers,
14645 	(cmdline_parse_inst_t *)&cmd_set_txpkts,
14646 	(cmdline_parse_inst_t *)&cmd_set_txsplit,
14647 	(cmdline_parse_inst_t *)&cmd_set_fwd_list,
14648 	(cmdline_parse_inst_t *)&cmd_set_fwd_mask,
14649 	(cmdline_parse_inst_t *)&cmd_set_fwd_mode,
14650 	(cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
14651 	(cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
14652 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
14653 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
14654 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
14655 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
14656 	(cmdline_parse_inst_t *)&cmd_set_flush_rx,
14657 	(cmdline_parse_inst_t *)&cmd_set_link_check,
14658 	(cmdline_parse_inst_t *)&cmd_set_bypass_mode,
14659 	(cmdline_parse_inst_t *)&cmd_set_bypass_event,
14660 	(cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
14661 	(cmdline_parse_inst_t *)&cmd_show_bypass_config,
14662 #ifdef RTE_LIBRTE_PMD_BOND
14663 	(cmdline_parse_inst_t *) &cmd_set_bonding_mode,
14664 	(cmdline_parse_inst_t *) &cmd_show_bonding_config,
14665 	(cmdline_parse_inst_t *) &cmd_set_bonding_primary,
14666 	(cmdline_parse_inst_t *) &cmd_add_bonding_slave,
14667 	(cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
14668 	(cmdline_parse_inst_t *) &cmd_create_bonded_device,
14669 	(cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
14670 	(cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
14671 	(cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
14672 	(cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
14673 	(cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
14674 #endif
14675 	(cmdline_parse_inst_t *)&cmd_vlan_offload,
14676 	(cmdline_parse_inst_t *)&cmd_vlan_tpid,
14677 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
14678 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
14679 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set,
14680 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
14681 	(cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
14682 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
14683 	(cmdline_parse_inst_t *)&cmd_csum_set,
14684 	(cmdline_parse_inst_t *)&cmd_csum_show,
14685 	(cmdline_parse_inst_t *)&cmd_csum_tunnel,
14686 	(cmdline_parse_inst_t *)&cmd_tso_set,
14687 	(cmdline_parse_inst_t *)&cmd_tso_show,
14688 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
14689 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
14690 	(cmdline_parse_inst_t *)&cmd_enable_gro,
14691 	(cmdline_parse_inst_t *)&cmd_gro_set,
14692 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
14693 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
14694 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
14695 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
14696 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
14697 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
14698 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
14699 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
14700 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
14701 	(cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
14702 	(cmdline_parse_inst_t *)&cmd_config_dcb,
14703 	(cmdline_parse_inst_t *)&cmd_read_reg,
14704 	(cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
14705 	(cmdline_parse_inst_t *)&cmd_read_reg_bit,
14706 	(cmdline_parse_inst_t *)&cmd_write_reg,
14707 	(cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
14708 	(cmdline_parse_inst_t *)&cmd_write_reg_bit,
14709 	(cmdline_parse_inst_t *)&cmd_read_rxd_txd,
14710 	(cmdline_parse_inst_t *)&cmd_stop,
14711 	(cmdline_parse_inst_t *)&cmd_mac_addr,
14712 	(cmdline_parse_inst_t *)&cmd_set_qmap,
14713 	(cmdline_parse_inst_t *)&cmd_operate_port,
14714 	(cmdline_parse_inst_t *)&cmd_operate_specific_port,
14715 	(cmdline_parse_inst_t *)&cmd_operate_attach_port,
14716 	(cmdline_parse_inst_t *)&cmd_operate_detach_port,
14717 	(cmdline_parse_inst_t *)&cmd_config_speed_all,
14718 	(cmdline_parse_inst_t *)&cmd_config_speed_specific,
14719 	(cmdline_parse_inst_t *)&cmd_config_rx_tx,
14720 	(cmdline_parse_inst_t *)&cmd_config_mtu,
14721 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
14722 	(cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
14723 	(cmdline_parse_inst_t *)&cmd_config_rss,
14724 	(cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
14725 	(cmdline_parse_inst_t *)&cmd_config_txqflags,
14726 	(cmdline_parse_inst_t *)&cmd_config_rss_reta,
14727 	(cmdline_parse_inst_t *)&cmd_showport_reta,
14728 	(cmdline_parse_inst_t *)&cmd_config_burst,
14729 	(cmdline_parse_inst_t *)&cmd_config_thresh,
14730 	(cmdline_parse_inst_t *)&cmd_config_threshold,
14731 	(cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
14732 	(cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
14733 	(cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
14734 	(cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
14735 	(cmdline_parse_inst_t *)&cmd_queue_rate_limit,
14736 	(cmdline_parse_inst_t *)&cmd_tunnel_filter,
14737 	(cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
14738 	(cmdline_parse_inst_t *)&cmd_global_config,
14739 	(cmdline_parse_inst_t *)&cmd_set_mirror_mask,
14740 	(cmdline_parse_inst_t *)&cmd_set_mirror_link,
14741 	(cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
14742 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash,
14743 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
14744 	(cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
14745 	(cmdline_parse_inst_t *)&cmd_dump,
14746 	(cmdline_parse_inst_t *)&cmd_dump_one,
14747 	(cmdline_parse_inst_t *)&cmd_ethertype_filter,
14748 	(cmdline_parse_inst_t *)&cmd_syn_filter,
14749 	(cmdline_parse_inst_t *)&cmd_2tuple_filter,
14750 	(cmdline_parse_inst_t *)&cmd_5tuple_filter,
14751 	(cmdline_parse_inst_t *)&cmd_flex_filter,
14752 	(cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
14753 	(cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
14754 	(cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
14755 	(cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
14756 	(cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
14757 	(cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
14758 	(cmdline_parse_inst_t *)&cmd_flush_flow_director,
14759 	(cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
14760 	(cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
14761 	(cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
14762 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
14763 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
14764 	(cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
14765 	(cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
14766 	(cmdline_parse_inst_t *)&cmd_get_hash_global_config,
14767 	(cmdline_parse_inst_t *)&cmd_set_hash_global_config,
14768 	(cmdline_parse_inst_t *)&cmd_set_hash_input_set,
14769 	(cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
14770 	(cmdline_parse_inst_t *)&cmd_flow,
14771 	(cmdline_parse_inst_t *)&cmd_mcast_addr,
14772 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
14773 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
14774 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
14775 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
14776 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
14777 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
14778 	(cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
14779 	(cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
14780 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
14781 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
14782 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
14783 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
14784 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
14785 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
14786 	(cmdline_parse_inst_t *)&cmd_set_tx_loopback,
14787 	(cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
14788 	(cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
14789 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
14790 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
14791 	(cmdline_parse_inst_t *)&cmd_set_macsec_sc,
14792 	(cmdline_parse_inst_t *)&cmd_set_macsec_sa,
14793 	(cmdline_parse_inst_t *)&cmd_set_vf_traffic,
14794 	(cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
14795 	(cmdline_parse_inst_t *)&cmd_vf_rate_limit,
14796 	(cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
14797 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
14798 	(cmdline_parse_inst_t *)&cmd_set_vf_promisc,
14799 	(cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
14800 	(cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
14801 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
14802 	(cmdline_parse_inst_t *)&cmd_vf_max_bw,
14803 	(cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
14804 	(cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
14805 	(cmdline_parse_inst_t *)&cmd_strict_link_prio,
14806 	(cmdline_parse_inst_t *)&cmd_tc_min_bw,
14807 	(cmdline_parse_inst_t *)&cmd_ddp_add,
14808 	(cmdline_parse_inst_t *)&cmd_ddp_del,
14809 	(cmdline_parse_inst_t *)&cmd_ddp_get_list,
14810 	(cmdline_parse_inst_t *)&cmd_ddp_get_info,
14811 	(cmdline_parse_inst_t *)&cmd_show_vf_stats,
14812 	(cmdline_parse_inst_t *)&cmd_clear_vf_stats,
14813 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
14814 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
14815 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
14816 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
14817 
14818 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
14819 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
14820 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
14821 	NULL,
14822 };
14823 
14824 /* read cmdline commands from file */
14825 void
14826 cmdline_read_from_file(const char *filename)
14827 {
14828 	struct cmdline *cl;
14829 
14830 	cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
14831 	if (cl == NULL) {
14832 		printf("Failed to create file based cmdline context: %s\n",
14833 		       filename);
14834 		return;
14835 	}
14836 
14837 	cmdline_interact(cl);
14838 	cmdline_quit(cl);
14839 
14840 	cmdline_free(cl);
14841 
14842 	printf("Read CLI commands from %s\n", filename);
14843 }
14844 
14845 /* prompt function, called from main on MASTER lcore */
14846 void
14847 prompt(void)
14848 {
14849 	/* initialize non-constant commands */
14850 	cmd_set_fwd_mode_init();
14851 	cmd_set_fwd_retry_mode_init();
14852 
14853 	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
14854 	if (testpmd_cl == NULL)
14855 		return;
14856 	cmdline_interact(testpmd_cl);
14857 	cmdline_stdin_exit(testpmd_cl);
14858 }
14859 
14860 void
14861 prompt_exit(void)
14862 {
14863 	if (testpmd_cl != NULL)
14864 		cmdline_quit(testpmd_cl);
14865 }
14866 
14867 static void
14868 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
14869 {
14870 	if (id == (portid_t)RTE_PORT_ALL) {
14871 		portid_t pid;
14872 
14873 		RTE_ETH_FOREACH_DEV(pid) {
14874 			/* check if need_reconfig has been set to 1 */
14875 			if (ports[pid].need_reconfig == 0)
14876 				ports[pid].need_reconfig = dev;
14877 			/* check if need_reconfig_queues has been set to 1 */
14878 			if (ports[pid].need_reconfig_queues == 0)
14879 				ports[pid].need_reconfig_queues = queue;
14880 		}
14881 	} else if (!port_id_is_invalid(id, DISABLED_WARN)) {
14882 		/* check if need_reconfig has been set to 1 */
14883 		if (ports[id].need_reconfig == 0)
14884 			ports[id].need_reconfig = dev;
14885 		/* check if need_reconfig_queues has been set to 1 */
14886 		if (ports[id].need_reconfig_queues == 0)
14887 			ports[id].need_reconfig_queues = queue;
14888 	}
14889 }
14890