xref: /dpdk/app/test-pmd/cmdline.c (revision 912267a33eede1427e865fc591e3ee2645cd596c)
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 			"set port (port_id) gro on|off\n"
431 			"    Enable or disable Generic Receive Offload in"
432 			" csum forwarding engine.\n\n"
433 
434 			"show port (port_id) gro\n"
435 			"    Display GRO configuration.\n\n"
436 
437 			"set gro flush (cycles)\n"
438 			"    Set the cycle to flush GROed packets from"
439 			" reassembly tables.\n\n"
440 
441 			"set port (port_id) gso (on|off)"
442 			"    Enable or disable Generic Segmentation Offload in"
443 			" csum forwarding engine.\n\n"
444 
445 			"set gso segsz (length)\n"
446 			"    Set max packet length for output GSO segments,"
447 			" including packet header and payload.\n\n"
448 
449 			"show port (port_id) gso\n"
450 			"    Show GSO configuration.\n\n"
451 
452 			"set fwd (%s)\n"
453 			"    Set packet forwarding mode.\n\n"
454 
455 			"mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
456 			"    Add a MAC address on port_id.\n\n"
457 
458 			"mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
459 			"    Remove a MAC address from port_id.\n\n"
460 
461 			"mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
462 			"    Set the default MAC address for port_id.\n\n"
463 
464 			"mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
465 			"    Add a MAC address for a VF on the port.\n\n"
466 
467 			"set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
468 			"    Set the MAC address for a VF from the PF.\n\n"
469 
470 			"set port (port_id) uta (mac_address|all) (on|off)\n"
471 			"    Add/Remove a or all unicast hash filter(s)"
472 			"from port X.\n\n"
473 
474 			"set promisc (port_id|all) (on|off)\n"
475 			"    Set the promiscuous mode on port_id, or all.\n\n"
476 
477 			"set allmulti (port_id|all) (on|off)\n"
478 			"    Set the allmulti mode on port_id, or all.\n\n"
479 
480 			"set vf promisc (port_id) (vf_id) (on|off)\n"
481 			"    Set unicast promiscuous mode for a VF from the PF.\n\n"
482 
483 			"set vf allmulti (port_id) (vf_id) (on|off)\n"
484 			"    Set multicast promiscuous mode for a VF from the PF.\n\n"
485 
486 			"set flow_ctrl rx (on|off) tx (on|off) (high_water)"
487 			" (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
488 			" (on|off) autoneg (on|off) (port_id)\n"
489 			"set flow_ctrl rx (on|off) (portid)\n"
490 			"set flow_ctrl tx (on|off) (portid)\n"
491 			"set flow_ctrl high_water (high_water) (portid)\n"
492 			"set flow_ctrl low_water (low_water) (portid)\n"
493 			"set flow_ctrl pause_time (pause_time) (portid)\n"
494 			"set flow_ctrl send_xon (send_xon) (portid)\n"
495 			"set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
496 			"set flow_ctrl autoneg (on|off) (port_id)\n"
497 			"    Set the link flow control parameter on a port.\n\n"
498 
499 			"set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
500 			" (low_water) (pause_time) (priority) (port_id)\n"
501 			"    Set the priority flow control parameter on a"
502 			" port.\n\n"
503 
504 			"set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
505 			"    Set statistics mapping (qmapping 0..15) for RX/TX"
506 			" queue on port.\n"
507 			"    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
508 			" on port 0 to mapping 5.\n\n"
509 
510 			"set port (port_id) vf (vf_id) rx|tx on|off\n"
511 			"    Enable/Disable a VF receive/tranmit from a port\n\n"
512 
513 			"set port (port_id) vf (vf_id) (mac_addr)"
514 			" (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
515 			"   Add/Remove unicast or multicast MAC addr filter"
516 			" for a VF.\n\n"
517 
518 			"set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
519 			"|MPE) (on|off)\n"
520 			"    AUPE:accepts untagged VLAN;"
521 			"ROPE:accept unicast hash\n\n"
522 			"    BAM:accepts broadcast packets;"
523 			"MPE:accepts all multicast packets\n\n"
524 			"    Enable/Disable a VF receive mode of a port\n\n"
525 
526 			"set port (port_id) queue (queue_id) rate (rate_num)\n"
527 			"    Set rate limit for a queue of a port\n\n"
528 
529 			"set port (port_id) vf (vf_id) rate (rate_num) "
530 			"queue_mask (queue_mask_value)\n"
531 			"    Set rate limit for queues in VF of a port\n\n"
532 
533 			"set port (port_id) mirror-rule (rule_id)"
534 			" (pool-mirror-up|pool-mirror-down|vlan-mirror)"
535 			" (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
536 			"   Set pool or vlan type mirror rule on a port.\n"
537 			"   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
538 			" dst-pool 0 on' enable mirror traffic with vlan 0,1"
539 			" to pool 0.\n\n"
540 
541 			"set port (port_id) mirror-rule (rule_id)"
542 			" (uplink-mirror|downlink-mirror) dst-pool"
543 			" (pool_id) (on|off)\n"
544 			"   Set uplink or downlink type mirror rule on a port.\n"
545 			"   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
546 			" 0 on' enable mirror income traffic to pool 0.\n\n"
547 
548 			"reset port (port_id) mirror-rule (rule_id)\n"
549 			"   Reset a mirror rule.\n\n"
550 
551 			"set flush_rx (on|off)\n"
552 			"   Flush (default) or don't flush RX streams before"
553 			" forwarding. Mainly used with PCAP drivers.\n\n"
554 
555 			"set bypass mode (normal|bypass|isolate) (port_id)\n"
556 			"   Set the bypass mode for the lowest port on bypass enabled"
557 			" NIC.\n\n"
558 
559 			"set bypass event (timeout|os_on|os_off|power_on|power_off) "
560 			"mode (normal|bypass|isolate) (port_id)\n"
561 			"   Set the event required to initiate specified bypass mode for"
562 			" the lowest port on a bypass enabled NIC where:\n"
563 			"       timeout   = enable bypass after watchdog timeout.\n"
564 			"       os_on     = enable bypass when OS/board is powered on.\n"
565 			"       os_off    = enable bypass when OS/board is powered off.\n"
566 			"       power_on  = enable bypass when power supply is turned on.\n"
567 			"       power_off = enable bypass when power supply is turned off."
568 			"\n\n"
569 
570 			"set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
571 			"   Set the bypass watchdog timeout to 'n' seconds"
572 			" where 0 = instant.\n\n"
573 
574 			"show bypass config (port_id)\n"
575 			"   Show the bypass configuration for a bypass enabled NIC"
576 			" using the lowest port on the NIC.\n\n"
577 
578 #ifdef RTE_LIBRTE_PMD_BOND
579 			"create bonded device (mode) (socket)\n"
580 			"	Create a new bonded device with specific bonding mode and socket.\n\n"
581 
582 			"add bonding slave (slave_id) (port_id)\n"
583 			"	Add a slave device to a bonded device.\n\n"
584 
585 			"remove bonding slave (slave_id) (port_id)\n"
586 			"	Remove a slave device from a bonded device.\n\n"
587 
588 			"set bonding mode (value) (port_id)\n"
589 			"	Set the bonding mode on a bonded device.\n\n"
590 
591 			"set bonding primary (slave_id) (port_id)\n"
592 			"	Set the primary slave for a bonded device.\n\n"
593 
594 			"show bonding config (port_id)\n"
595 			"	Show the bonding config for port_id.\n\n"
596 
597 			"set bonding mac_addr (port_id) (address)\n"
598 			"	Set the MAC address of a bonded device.\n\n"
599 
600 			"set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
601 			"	Set Aggregation mode for IEEE802.3AD (mode 4)"
602 
603 			"set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
604 			"	Set the transmit balance policy for bonded device running in balance mode.\n\n"
605 
606 			"set bonding mon_period (port_id) (value)\n"
607 			"	Set the bonding link status monitoring polling period in ms.\n\n"
608 
609 			"set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
610 			"	Enable/disable dedicated queues for LACP control traffic.\n\n"
611 
612 #endif
613 			"set link-up port (port_id)\n"
614 			"	Set link up for a port.\n\n"
615 
616 			"set link-down port (port_id)\n"
617 			"	Set link down for a port.\n\n"
618 
619 			"E-tag set insertion on port-tag-id (value)"
620 			" port (port_id) vf (vf_id)\n"
621 			"    Enable E-tag insertion for a VF on a port\n\n"
622 
623 			"E-tag set insertion off port (port_id) vf (vf_id)\n"
624 			"    Disable E-tag insertion for a VF on a port\n\n"
625 
626 			"E-tag set stripping (on|off) port (port_id)\n"
627 			"    Enable/disable E-tag stripping on a port\n\n"
628 
629 			"E-tag set forwarding (on|off) port (port_id)\n"
630 			"    Enable/disable E-tag based forwarding"
631 			" on a port\n\n"
632 
633 			"E-tag set filter add e-tag-id (value) dst-pool"
634 			" (pool_id) port (port_id)\n"
635 			"    Add an E-tag forwarding filter on a port\n\n"
636 
637 			"E-tag set filter del e-tag-id (value) port (port_id)\n"
638 			"    Delete an E-tag forwarding filter on a port\n\n"
639 
640 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
641 			"set port tm hierarchy default (port_id)\n"
642 			"	Set default traffic Management hierarchy on a port\n\n"
643 
644 #endif
645 			"ddp add (port_id) (profile_path[,output_path])\n"
646 			"    Load a profile package on a port\n\n"
647 
648 			"ddp del (port_id) (profile_path)\n"
649 			"    Delete a profile package from a port\n\n"
650 
651 			"ptype mapping get (port_id) (valid_only)\n"
652 			"    Get ptype mapping on a port\n\n"
653 
654 			"ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
655 			"    Replace target with the pkt_type in ptype mapping\n\n"
656 
657 			"ptype mapping reset (port_id)\n"
658 			"    Reset ptype mapping on a port\n\n"
659 
660 			"ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
661 			"    Update a ptype mapping item on a port\n\n"
662 
663 			, list_pkt_forwarding_modes()
664 		);
665 	}
666 
667 	if (show_all || !strcmp(res->section, "ports")) {
668 
669 		cmdline_printf(
670 			cl,
671 			"\n"
672 			"Port Operations:\n"
673 			"----------------\n\n"
674 
675 			"port start (port_id|all)\n"
676 			"    Start all ports or port_id.\n\n"
677 
678 			"port stop (port_id|all)\n"
679 			"    Stop all ports or port_id.\n\n"
680 
681 			"port close (port_id|all)\n"
682 			"    Close all ports or port_id.\n\n"
683 
684 			"port attach (ident)\n"
685 			"    Attach physical or virtual dev by pci address or virtual device name\n\n"
686 
687 			"port detach (port_id)\n"
688 			"    Detach physical or virtual dev by port_id\n\n"
689 
690 			"port config (port_id|all)"
691 			" speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
692 			" duplex (half|full|auto)\n"
693 			"    Set speed and duplex for all ports or port_id\n\n"
694 
695 			"port config all (rxq|txq|rxd|txd) (value)\n"
696 			"    Set number for rxq/txq/rxd/txd.\n\n"
697 
698 			"port config all max-pkt-len (value)\n"
699 			"    Set the max packet length.\n\n"
700 
701 			"port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
702 			"hw-vlan-strip|hw-vlan-extend|drop-en)"
703 			" (on|off)\n"
704 			"    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
705 			" for ports.\n\n"
706 
707 			"port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
708 			"geneve|nvgre|none|<flowtype_id>)\n"
709 			"    Set the RSS mode.\n\n"
710 
711 			"port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
712 			"    Set the RSS redirection table.\n\n"
713 
714 			"port config (port_id) dcb vt (on|off) (traffic_class)"
715 			" pfc (on|off)\n"
716 			"    Set the DCB mode.\n\n"
717 
718 			"port config all burst (value)\n"
719 			"    Set the number of packets per burst.\n\n"
720 
721 			"port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
722 			" (value)\n"
723 			"    Set the ring prefetch/host/writeback threshold"
724 			" for tx/rx queue.\n\n"
725 
726 			"port config all (txfreet|txrst|rxfreet) (value)\n"
727 			"    Set free threshold for rx/tx, or set"
728 			" tx rs bit threshold.\n\n"
729 			"port config mtu X value\n"
730 			"    Set the MTU of port X to a given value\n\n"
731 
732 			"port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
733 			"    Start/stop a rx/tx queue of port X. Only take effect"
734 			" when port X is started\n\n"
735 
736 			"port config (port_id|all) l2-tunnel E-tag ether-type"
737 			" (value)\n"
738 			"    Set the value of E-tag ether-type.\n\n"
739 
740 			"port config (port_id|all) l2-tunnel E-tag"
741 			" (enable|disable)\n"
742 			"    Enable/disable the E-tag support.\n\n"
743 
744 			"port config (port_id) pctype mapping reset\n"
745 			"    Reset flow type to pctype mapping on a port\n\n"
746 
747 			"port config (port_id) pctype mapping update"
748 			" (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
749 			"    Update a flow type to pctype mapping item on a port\n\n"
750 		);
751 	}
752 
753 	if (show_all || !strcmp(res->section, "registers")) {
754 
755 		cmdline_printf(
756 			cl,
757 			"\n"
758 			"Registers:\n"
759 			"----------\n\n"
760 
761 			"read reg (port_id) (address)\n"
762 			"    Display value of a port register.\n\n"
763 
764 			"read regfield (port_id) (address) (bit_x) (bit_y)\n"
765 			"    Display a port register bit field.\n\n"
766 
767 			"read regbit (port_id) (address) (bit_x)\n"
768 			"    Display a single port register bit.\n\n"
769 
770 			"write reg (port_id) (address) (value)\n"
771 			"    Set value of a port register.\n\n"
772 
773 			"write regfield (port_id) (address) (bit_x) (bit_y)"
774 			" (value)\n"
775 			"    Set bit field of a port register.\n\n"
776 
777 			"write regbit (port_id) (address) (bit_x) (value)\n"
778 			"    Set single bit value of a port register.\n\n"
779 		);
780 	}
781 	if (show_all || !strcmp(res->section, "filters")) {
782 
783 		cmdline_printf(
784 			cl,
785 			"\n"
786 			"filters:\n"
787 			"--------\n\n"
788 
789 			"ethertype_filter (port_id) (add|del)"
790 			" (mac_addr|mac_ignr) (mac_address) ethertype"
791 			" (ether_type) (drop|fwd) queue (queue_id)\n"
792 			"    Add/Del an ethertype filter.\n\n"
793 
794 			"2tuple_filter (port_id) (add|del)"
795 			" dst_port (dst_port_value) protocol (protocol_value)"
796 			" mask (mask_value) tcp_flags (tcp_flags_value)"
797 			" priority (prio_value) queue (queue_id)\n"
798 			"    Add/Del a 2tuple filter.\n\n"
799 
800 			"5tuple_filter (port_id) (add|del)"
801 			" dst_ip (dst_address) src_ip (src_address)"
802 			" dst_port (dst_port_value) src_port (src_port_value)"
803 			" protocol (protocol_value)"
804 			" mask (mask_value) tcp_flags (tcp_flags_value)"
805 			" priority (prio_value) queue (queue_id)\n"
806 			"    Add/Del a 5tuple filter.\n\n"
807 
808 			"syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
809 			"    Add/Del syn filter.\n\n"
810 
811 			"flex_filter (port_id) (add|del) len (len_value)"
812 			" bytes (bytes_value) mask (mask_value)"
813 			" priority (prio_value) queue (queue_id)\n"
814 			"    Add/Del a flex filter.\n\n"
815 
816 			"flow_director_filter (port_id) mode IP (add|del|update)"
817 			" flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
818 			" src (src_ip_address) dst (dst_ip_address)"
819 			" tos (tos_value) proto (proto_value) ttl (ttl_value)"
820 			" vlan (vlan_value) flexbytes (flexbytes_value)"
821 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
822 			" fd_id (fd_id_value)\n"
823 			"    Add/Del an IP type flow director filter.\n\n"
824 
825 			"flow_director_filter (port_id) mode IP (add|del|update)"
826 			" flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
827 			" src (src_ip_address) (src_port)"
828 			" dst (dst_ip_address) (dst_port)"
829 			" tos (tos_value) ttl (ttl_value)"
830 			" vlan (vlan_value) flexbytes (flexbytes_value)"
831 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
832 			" fd_id (fd_id_value)\n"
833 			"    Add/Del an UDP/TCP type flow director filter.\n\n"
834 
835 			"flow_director_filter (port_id) mode IP (add|del|update)"
836 			" flow (ipv4-sctp|ipv6-sctp)"
837 			" src (src_ip_address) (src_port)"
838 			" dst (dst_ip_address) (dst_port)"
839 			" tag (verification_tag) "
840 			" tos (tos_value) ttl (ttl_value)"
841 			" vlan (vlan_value)"
842 			" flexbytes (flexbytes_value) (drop|fwd)"
843 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
844 			"    Add/Del a SCTP type flow director filter.\n\n"
845 
846 			"flow_director_filter (port_id) mode IP (add|del|update)"
847 			" flow l2_payload ether (ethertype)"
848 			" flexbytes (flexbytes_value) (drop|fwd)"
849 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
850 			"    Add/Del a l2 payload type flow director filter.\n\n"
851 
852 			"flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
853 			" mac (mac_address) vlan (vlan_value)"
854 			" flexbytes (flexbytes_value) (drop|fwd)"
855 			" queue (queue_id) fd_id (fd_id_value)\n"
856 			"    Add/Del a MAC-VLAN flow director filter.\n\n"
857 
858 			"flow_director_filter (port_id) mode Tunnel (add|del|update)"
859 			" mac (mac_address) vlan (vlan_value)"
860 			" tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
861 			" flexbytes (flexbytes_value) (drop|fwd)"
862 			" queue (queue_id) fd_id (fd_id_value)\n"
863 			"    Add/Del a Tunnel flow director filter.\n\n"
864 
865 			"flush_flow_director (port_id)\n"
866 			"    Flush all flow director entries of a device.\n\n"
867 
868 			"flow_director_mask (port_id) mode IP vlan (vlan_value)"
869 			" src_mask (ipv4_src) (ipv6_src) (src_port)"
870 			" dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
871 			"    Set flow director IP mask.\n\n"
872 
873 			"flow_director_mask (port_id) mode MAC-VLAN"
874 			" vlan (vlan_value)\n"
875 			"    Set flow director MAC-VLAN mask.\n\n"
876 
877 			"flow_director_mask (port_id) mode Tunnel"
878 			" vlan (vlan_value) mac (mac_value)"
879 			" tunnel-type (tunnel_type_value)"
880 			" tunnel-id (tunnel_id_value)\n"
881 			"    Set flow director Tunnel mask.\n\n"
882 
883 			"flow_director_flex_mask (port_id)"
884 			" flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
885 			"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
886 			" (mask)\n"
887 			"    Configure mask of flex payload.\n\n"
888 
889 			"flow_director_flex_payload (port_id)"
890 			" (raw|l2|l3|l4) (config)\n"
891 			"    Configure flex payload selection.\n\n"
892 
893 			"get_sym_hash_ena_per_port (port_id)\n"
894 			"    get symmetric hash enable configuration per port.\n\n"
895 
896 			"set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
897 			"    set symmetric hash enable configuration per port"
898 			" to enable or disable.\n\n"
899 
900 			"get_hash_global_config (port_id)\n"
901 			"    Get the global configurations of hash filters.\n\n"
902 
903 			"set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
904 			" (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
905 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
906 			" (enable|disable)\n"
907 			"    Set the global configurations of hash filters.\n\n"
908 
909 			"set_hash_input_set (port_id) (ipv4|ipv4-frag|"
910 			"ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
911 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
912 			"l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
913 			"src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
914 			"ipv6-next-header|udp-src-port|udp-dst-port|"
915 			"tcp-src-port|tcp-dst-port|sctp-src-port|"
916 			"sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
917 			"fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
918 			"fld-8th|none) (select|add)\n"
919 			"    Set the input set for hash.\n\n"
920 
921 			"set_fdir_input_set (port_id) "
922 			"(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
923 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
924 			"l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
925 			"dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
926 			"ipv6-next-header|ipv6-hop-limits|udp-src-port|"
927 			"udp-dst-port|tcp-src-port|tcp-dst-port|"
928 			"sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
929 			" (select|add)\n"
930 			"    Set the input set for FDir.\n\n"
931 
932 			"flow validate {port_id}"
933 			" [group {group_id}] [priority {level}]"
934 			" [ingress] [egress]"
935 			" pattern {item} [/ {item} [...]] / end"
936 			" actions {action} [/ {action} [...]] / end\n"
937 			"    Check whether a flow rule can be created.\n\n"
938 
939 			"flow create {port_id}"
940 			" [group {group_id}] [priority {level}]"
941 			" [ingress] [egress]"
942 			" pattern {item} [/ {item} [...]] / end"
943 			" actions {action} [/ {action} [...]] / end\n"
944 			"    Create a flow rule.\n\n"
945 
946 			"flow destroy {port_id} rule {rule_id} [...]\n"
947 			"    Destroy specific flow rules.\n\n"
948 
949 			"flow flush {port_id}\n"
950 			"    Destroy all flow rules.\n\n"
951 
952 			"flow query {port_id} {rule_id} {action}\n"
953 			"    Query an existing flow rule.\n\n"
954 
955 			"flow list {port_id} [group {group_id}] [...]\n"
956 			"    List existing flow rules sorted by priority,"
957 			" filtered by group identifiers.\n\n"
958 
959 			"flow isolate {port_id} {boolean}\n"
960 			"    Restrict ingress traffic to the defined"
961 			" flow rules\n\n"
962 		);
963 	}
964 }
965 
966 cmdline_parse_token_string_t cmd_help_long_help =
967 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
968 
969 cmdline_parse_token_string_t cmd_help_long_section =
970 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
971 			"all#control#display#config#"
972 			"ports#registers#filters");
973 
974 cmdline_parse_inst_t cmd_help_long = {
975 	.f = cmd_help_long_parsed,
976 	.data = NULL,
977 	.help_str = "help all|control|display|config|ports|register|filters: "
978 		"Show help",
979 	.tokens = {
980 		(void *)&cmd_help_long_help,
981 		(void *)&cmd_help_long_section,
982 		NULL,
983 	},
984 };
985 
986 
987 /* *** start/stop/close all ports *** */
988 struct cmd_operate_port_result {
989 	cmdline_fixed_string_t keyword;
990 	cmdline_fixed_string_t name;
991 	cmdline_fixed_string_t value;
992 };
993 
994 static void cmd_operate_port_parsed(void *parsed_result,
995 				__attribute__((unused)) struct cmdline *cl,
996 				__attribute__((unused)) void *data)
997 {
998 	struct cmd_operate_port_result *res = parsed_result;
999 
1000 	if (!strcmp(res->name, "start"))
1001 		start_port(RTE_PORT_ALL);
1002 	else if (!strcmp(res->name, "stop"))
1003 		stop_port(RTE_PORT_ALL);
1004 	else if (!strcmp(res->name, "close"))
1005 		close_port(RTE_PORT_ALL);
1006 	else if (!strcmp(res->name, "reset"))
1007 		reset_port(RTE_PORT_ALL);
1008 	else
1009 		printf("Unknown parameter\n");
1010 }
1011 
1012 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1013 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1014 								"port");
1015 cmdline_parse_token_string_t cmd_operate_port_all_port =
1016 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1017 						"start#stop#close#reset");
1018 cmdline_parse_token_string_t cmd_operate_port_all_all =
1019 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1020 
1021 cmdline_parse_inst_t cmd_operate_port = {
1022 	.f = cmd_operate_port_parsed,
1023 	.data = NULL,
1024 	.help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1025 	.tokens = {
1026 		(void *)&cmd_operate_port_all_cmd,
1027 		(void *)&cmd_operate_port_all_port,
1028 		(void *)&cmd_operate_port_all_all,
1029 		NULL,
1030 	},
1031 };
1032 
1033 /* *** start/stop/close specific port *** */
1034 struct cmd_operate_specific_port_result {
1035 	cmdline_fixed_string_t keyword;
1036 	cmdline_fixed_string_t name;
1037 	uint8_t value;
1038 };
1039 
1040 static void cmd_operate_specific_port_parsed(void *parsed_result,
1041 			__attribute__((unused)) struct cmdline *cl,
1042 				__attribute__((unused)) void *data)
1043 {
1044 	struct cmd_operate_specific_port_result *res = parsed_result;
1045 
1046 	if (!strcmp(res->name, "start"))
1047 		start_port(res->value);
1048 	else if (!strcmp(res->name, "stop"))
1049 		stop_port(res->value);
1050 	else if (!strcmp(res->name, "close"))
1051 		close_port(res->value);
1052 	else if (!strcmp(res->name, "reset"))
1053 		reset_port(res->value);
1054 	else
1055 		printf("Unknown parameter\n");
1056 }
1057 
1058 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1059 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1060 							keyword, "port");
1061 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1062 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1063 						name, "start#stop#close#reset");
1064 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1065 	TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1066 							value, UINT8);
1067 
1068 cmdline_parse_inst_t cmd_operate_specific_port = {
1069 	.f = cmd_operate_specific_port_parsed,
1070 	.data = NULL,
1071 	.help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1072 	.tokens = {
1073 		(void *)&cmd_operate_specific_port_cmd,
1074 		(void *)&cmd_operate_specific_port_port,
1075 		(void *)&cmd_operate_specific_port_id,
1076 		NULL,
1077 	},
1078 };
1079 
1080 /* *** attach a specified port *** */
1081 struct cmd_operate_attach_port_result {
1082 	cmdline_fixed_string_t port;
1083 	cmdline_fixed_string_t keyword;
1084 	cmdline_fixed_string_t identifier;
1085 };
1086 
1087 static void cmd_operate_attach_port_parsed(void *parsed_result,
1088 				__attribute__((unused)) struct cmdline *cl,
1089 				__attribute__((unused)) void *data)
1090 {
1091 	struct cmd_operate_attach_port_result *res = parsed_result;
1092 
1093 	if (!strcmp(res->keyword, "attach"))
1094 		attach_port(res->identifier);
1095 	else
1096 		printf("Unknown parameter\n");
1097 }
1098 
1099 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1100 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1101 			port, "port");
1102 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1103 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1104 			keyword, "attach");
1105 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1106 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1107 			identifier, NULL);
1108 
1109 cmdline_parse_inst_t cmd_operate_attach_port = {
1110 	.f = cmd_operate_attach_port_parsed,
1111 	.data = NULL,
1112 	.help_str = "port attach <identifier>: "
1113 		"(identifier: pci address or virtual dev name)",
1114 	.tokens = {
1115 		(void *)&cmd_operate_attach_port_port,
1116 		(void *)&cmd_operate_attach_port_keyword,
1117 		(void *)&cmd_operate_attach_port_identifier,
1118 		NULL,
1119 	},
1120 };
1121 
1122 /* *** detach a specified port *** */
1123 struct cmd_operate_detach_port_result {
1124 	cmdline_fixed_string_t port;
1125 	cmdline_fixed_string_t keyword;
1126 	uint8_t port_id;
1127 };
1128 
1129 static void cmd_operate_detach_port_parsed(void *parsed_result,
1130 				__attribute__((unused)) struct cmdline *cl,
1131 				__attribute__((unused)) void *data)
1132 {
1133 	struct cmd_operate_detach_port_result *res = parsed_result;
1134 
1135 	if (!strcmp(res->keyword, "detach"))
1136 		detach_port(res->port_id);
1137 	else
1138 		printf("Unknown parameter\n");
1139 }
1140 
1141 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1142 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1143 			port, "port");
1144 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1145 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1146 			keyword, "detach");
1147 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1148 	TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1149 			port_id, UINT8);
1150 
1151 cmdline_parse_inst_t cmd_operate_detach_port = {
1152 	.f = cmd_operate_detach_port_parsed,
1153 	.data = NULL,
1154 	.help_str = "port detach <port_id>",
1155 	.tokens = {
1156 		(void *)&cmd_operate_detach_port_port,
1157 		(void *)&cmd_operate_detach_port_keyword,
1158 		(void *)&cmd_operate_detach_port_port_id,
1159 		NULL,
1160 	},
1161 };
1162 
1163 /* *** configure speed for all ports *** */
1164 struct cmd_config_speed_all {
1165 	cmdline_fixed_string_t port;
1166 	cmdline_fixed_string_t keyword;
1167 	cmdline_fixed_string_t all;
1168 	cmdline_fixed_string_t item1;
1169 	cmdline_fixed_string_t item2;
1170 	cmdline_fixed_string_t value1;
1171 	cmdline_fixed_string_t value2;
1172 };
1173 
1174 static int
1175 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1176 {
1177 
1178 	int duplex;
1179 
1180 	if (!strcmp(duplexstr, "half")) {
1181 		duplex = ETH_LINK_HALF_DUPLEX;
1182 	} else if (!strcmp(duplexstr, "full")) {
1183 		duplex = ETH_LINK_FULL_DUPLEX;
1184 	} else if (!strcmp(duplexstr, "auto")) {
1185 		duplex = ETH_LINK_FULL_DUPLEX;
1186 	} else {
1187 		printf("Unknown duplex parameter\n");
1188 		return -1;
1189 	}
1190 
1191 	if (!strcmp(speedstr, "10")) {
1192 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1193 				ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1194 	} else if (!strcmp(speedstr, "100")) {
1195 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1196 				ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1197 	} else {
1198 		if (duplex != ETH_LINK_FULL_DUPLEX) {
1199 			printf("Invalid speed/duplex parameters\n");
1200 			return -1;
1201 		}
1202 		if (!strcmp(speedstr, "1000")) {
1203 			*speed = ETH_LINK_SPEED_1G;
1204 		} else if (!strcmp(speedstr, "10000")) {
1205 			*speed = ETH_LINK_SPEED_10G;
1206 		} else if (!strcmp(speedstr, "25000")) {
1207 			*speed = ETH_LINK_SPEED_25G;
1208 		} else if (!strcmp(speedstr, "40000")) {
1209 			*speed = ETH_LINK_SPEED_40G;
1210 		} else if (!strcmp(speedstr, "50000")) {
1211 			*speed = ETH_LINK_SPEED_50G;
1212 		} else if (!strcmp(speedstr, "100000")) {
1213 			*speed = ETH_LINK_SPEED_100G;
1214 		} else if (!strcmp(speedstr, "auto")) {
1215 			*speed = ETH_LINK_SPEED_AUTONEG;
1216 		} else {
1217 			printf("Unknown speed parameter\n");
1218 			return -1;
1219 		}
1220 	}
1221 
1222 	return 0;
1223 }
1224 
1225 static void
1226 cmd_config_speed_all_parsed(void *parsed_result,
1227 			__attribute__((unused)) struct cmdline *cl,
1228 			__attribute__((unused)) void *data)
1229 {
1230 	struct cmd_config_speed_all *res = parsed_result;
1231 	uint32_t link_speed;
1232 	portid_t pid;
1233 
1234 	if (!all_ports_stopped()) {
1235 		printf("Please stop all ports first\n");
1236 		return;
1237 	}
1238 
1239 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1240 			&link_speed) < 0)
1241 		return;
1242 
1243 	RTE_ETH_FOREACH_DEV(pid) {
1244 		ports[pid].dev_conf.link_speeds = link_speed;
1245 	}
1246 
1247 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1248 }
1249 
1250 cmdline_parse_token_string_t cmd_config_speed_all_port =
1251 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1252 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1253 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1254 							"config");
1255 cmdline_parse_token_string_t cmd_config_speed_all_all =
1256 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1257 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1258 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1259 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1260 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1261 				"10#100#1000#10000#25000#40000#50000#100000#auto");
1262 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1263 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1264 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1265 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1266 						"half#full#auto");
1267 
1268 cmdline_parse_inst_t cmd_config_speed_all = {
1269 	.f = cmd_config_speed_all_parsed,
1270 	.data = NULL,
1271 	.help_str = "port config all speed "
1272 		"10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1273 							"half|full|auto",
1274 	.tokens = {
1275 		(void *)&cmd_config_speed_all_port,
1276 		(void *)&cmd_config_speed_all_keyword,
1277 		(void *)&cmd_config_speed_all_all,
1278 		(void *)&cmd_config_speed_all_item1,
1279 		(void *)&cmd_config_speed_all_value1,
1280 		(void *)&cmd_config_speed_all_item2,
1281 		(void *)&cmd_config_speed_all_value2,
1282 		NULL,
1283 	},
1284 };
1285 
1286 /* *** configure speed for specific port *** */
1287 struct cmd_config_speed_specific {
1288 	cmdline_fixed_string_t port;
1289 	cmdline_fixed_string_t keyword;
1290 	uint8_t id;
1291 	cmdline_fixed_string_t item1;
1292 	cmdline_fixed_string_t item2;
1293 	cmdline_fixed_string_t value1;
1294 	cmdline_fixed_string_t value2;
1295 };
1296 
1297 static void
1298 cmd_config_speed_specific_parsed(void *parsed_result,
1299 				__attribute__((unused)) struct cmdline *cl,
1300 				__attribute__((unused)) void *data)
1301 {
1302 	struct cmd_config_speed_specific *res = parsed_result;
1303 	uint32_t link_speed;
1304 
1305 	if (!all_ports_stopped()) {
1306 		printf("Please stop all ports first\n");
1307 		return;
1308 	}
1309 
1310 	if (port_id_is_invalid(res->id, ENABLED_WARN))
1311 		return;
1312 
1313 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1314 			&link_speed) < 0)
1315 		return;
1316 
1317 	ports[res->id].dev_conf.link_speeds = link_speed;
1318 
1319 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1320 }
1321 
1322 
1323 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1324 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1325 								"port");
1326 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1327 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1328 								"config");
1329 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1330 	TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1331 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1332 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1333 								"speed");
1334 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1335 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1336 				"10#100#1000#10000#25000#40000#50000#100000#auto");
1337 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1338 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1339 								"duplex");
1340 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1341 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1342 							"half#full#auto");
1343 
1344 cmdline_parse_inst_t cmd_config_speed_specific = {
1345 	.f = cmd_config_speed_specific_parsed,
1346 	.data = NULL,
1347 	.help_str = "port config <port_id> speed "
1348 		"10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1349 							"half|full|auto",
1350 	.tokens = {
1351 		(void *)&cmd_config_speed_specific_port,
1352 		(void *)&cmd_config_speed_specific_keyword,
1353 		(void *)&cmd_config_speed_specific_id,
1354 		(void *)&cmd_config_speed_specific_item1,
1355 		(void *)&cmd_config_speed_specific_value1,
1356 		(void *)&cmd_config_speed_specific_item2,
1357 		(void *)&cmd_config_speed_specific_value2,
1358 		NULL,
1359 	},
1360 };
1361 
1362 /* *** configure txq/rxq, txd/rxd *** */
1363 struct cmd_config_rx_tx {
1364 	cmdline_fixed_string_t port;
1365 	cmdline_fixed_string_t keyword;
1366 	cmdline_fixed_string_t all;
1367 	cmdline_fixed_string_t name;
1368 	uint16_t value;
1369 };
1370 
1371 static void
1372 cmd_config_rx_tx_parsed(void *parsed_result,
1373 			__attribute__((unused)) struct cmdline *cl,
1374 			__attribute__((unused)) void *data)
1375 {
1376 	struct cmd_config_rx_tx *res = parsed_result;
1377 
1378 	if (!all_ports_stopped()) {
1379 		printf("Please stop all ports first\n");
1380 		return;
1381 	}
1382 	if (!strcmp(res->name, "rxq")) {
1383 		if (!res->value && !nb_txq) {
1384 			printf("Warning: Either rx or tx queues should be non zero\n");
1385 			return;
1386 		}
1387 		nb_rxq = res->value;
1388 	}
1389 	else if (!strcmp(res->name, "txq")) {
1390 		if (!res->value && !nb_rxq) {
1391 			printf("Warning: Either rx or tx queues should be non zero\n");
1392 			return;
1393 		}
1394 		nb_txq = res->value;
1395 	}
1396 	else if (!strcmp(res->name, "rxd")) {
1397 		if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1398 			printf("rxd %d invalid - must be > 0 && <= %d\n",
1399 					res->value, RTE_TEST_RX_DESC_MAX);
1400 			return;
1401 		}
1402 		nb_rxd = res->value;
1403 	} else if (!strcmp(res->name, "txd")) {
1404 		if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1405 			printf("txd %d invalid - must be > 0 && <= %d\n",
1406 					res->value, RTE_TEST_TX_DESC_MAX);
1407 			return;
1408 		}
1409 		nb_txd = res->value;
1410 	} else {
1411 		printf("Unknown parameter\n");
1412 		return;
1413 	}
1414 
1415 	fwd_config_setup();
1416 
1417 	init_port_config();
1418 
1419 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1420 }
1421 
1422 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1423 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1424 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1425 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1426 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1427 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1428 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1429 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1430 						"rxq#txq#rxd#txd");
1431 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1432 	TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1433 
1434 cmdline_parse_inst_t cmd_config_rx_tx = {
1435 	.f = cmd_config_rx_tx_parsed,
1436 	.data = NULL,
1437 	.help_str = "port config all rxq|txq|rxd|txd <value>",
1438 	.tokens = {
1439 		(void *)&cmd_config_rx_tx_port,
1440 		(void *)&cmd_config_rx_tx_keyword,
1441 		(void *)&cmd_config_rx_tx_all,
1442 		(void *)&cmd_config_rx_tx_name,
1443 		(void *)&cmd_config_rx_tx_value,
1444 		NULL,
1445 	},
1446 };
1447 
1448 /* *** config max packet length *** */
1449 struct cmd_config_max_pkt_len_result {
1450 	cmdline_fixed_string_t port;
1451 	cmdline_fixed_string_t keyword;
1452 	cmdline_fixed_string_t all;
1453 	cmdline_fixed_string_t name;
1454 	uint32_t value;
1455 };
1456 
1457 static void
1458 cmd_config_max_pkt_len_parsed(void *parsed_result,
1459 				__attribute__((unused)) struct cmdline *cl,
1460 				__attribute__((unused)) void *data)
1461 {
1462 	struct cmd_config_max_pkt_len_result *res = parsed_result;
1463 
1464 	if (!all_ports_stopped()) {
1465 		printf("Please stop all ports first\n");
1466 		return;
1467 	}
1468 
1469 	if (!strcmp(res->name, "max-pkt-len")) {
1470 		if (res->value < ETHER_MIN_LEN) {
1471 			printf("max-pkt-len can not be less than %d\n",
1472 							ETHER_MIN_LEN);
1473 			return;
1474 		}
1475 		if (res->value == rx_mode.max_rx_pkt_len)
1476 			return;
1477 
1478 		rx_mode.max_rx_pkt_len = res->value;
1479 		if (res->value > ETHER_MAX_LEN)
1480 			rx_mode.jumbo_frame = 1;
1481 		else
1482 			rx_mode.jumbo_frame = 0;
1483 	} else {
1484 		printf("Unknown parameter\n");
1485 		return;
1486 	}
1487 
1488 	init_port_config();
1489 
1490 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1491 }
1492 
1493 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1494 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1495 								"port");
1496 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1497 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1498 								"config");
1499 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1500 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1501 								"all");
1502 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1503 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1504 								"max-pkt-len");
1505 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1506 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1507 								UINT32);
1508 
1509 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1510 	.f = cmd_config_max_pkt_len_parsed,
1511 	.data = NULL,
1512 	.help_str = "port config all max-pkt-len <value>",
1513 	.tokens = {
1514 		(void *)&cmd_config_max_pkt_len_port,
1515 		(void *)&cmd_config_max_pkt_len_keyword,
1516 		(void *)&cmd_config_max_pkt_len_all,
1517 		(void *)&cmd_config_max_pkt_len_name,
1518 		(void *)&cmd_config_max_pkt_len_value,
1519 		NULL,
1520 	},
1521 };
1522 
1523 /* *** configure port MTU *** */
1524 struct cmd_config_mtu_result {
1525 	cmdline_fixed_string_t port;
1526 	cmdline_fixed_string_t keyword;
1527 	cmdline_fixed_string_t mtu;
1528 	uint8_t port_id;
1529 	uint16_t value;
1530 };
1531 
1532 static void
1533 cmd_config_mtu_parsed(void *parsed_result,
1534 		      __attribute__((unused)) struct cmdline *cl,
1535 		      __attribute__((unused)) void *data)
1536 {
1537 	struct cmd_config_mtu_result *res = parsed_result;
1538 
1539 	if (res->value < ETHER_MIN_LEN) {
1540 		printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1541 		return;
1542 	}
1543 	port_mtu_set(res->port_id, res->value);
1544 }
1545 
1546 cmdline_parse_token_string_t cmd_config_mtu_port =
1547 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1548 				 "port");
1549 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1550 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1551 				 "config");
1552 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1553 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1554 				 "mtu");
1555 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1556 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1557 cmdline_parse_token_num_t cmd_config_mtu_value =
1558 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1559 
1560 cmdline_parse_inst_t cmd_config_mtu = {
1561 	.f = cmd_config_mtu_parsed,
1562 	.data = NULL,
1563 	.help_str = "port config mtu <port_id> <value>",
1564 	.tokens = {
1565 		(void *)&cmd_config_mtu_port,
1566 		(void *)&cmd_config_mtu_keyword,
1567 		(void *)&cmd_config_mtu_mtu,
1568 		(void *)&cmd_config_mtu_port_id,
1569 		(void *)&cmd_config_mtu_value,
1570 		NULL,
1571 	},
1572 };
1573 
1574 /* *** configure rx mode *** */
1575 struct cmd_config_rx_mode_flag {
1576 	cmdline_fixed_string_t port;
1577 	cmdline_fixed_string_t keyword;
1578 	cmdline_fixed_string_t all;
1579 	cmdline_fixed_string_t name;
1580 	cmdline_fixed_string_t value;
1581 };
1582 
1583 static void
1584 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1585 				__attribute__((unused)) struct cmdline *cl,
1586 				__attribute__((unused)) void *data)
1587 {
1588 	struct cmd_config_rx_mode_flag *res = parsed_result;
1589 
1590 	if (!all_ports_stopped()) {
1591 		printf("Please stop all ports first\n");
1592 		return;
1593 	}
1594 
1595 	if (!strcmp(res->name, "crc-strip")) {
1596 		if (!strcmp(res->value, "on"))
1597 			rx_mode.hw_strip_crc = 1;
1598 		else if (!strcmp(res->value, "off"))
1599 			rx_mode.hw_strip_crc = 0;
1600 		else {
1601 			printf("Unknown parameter\n");
1602 			return;
1603 		}
1604 	} else if (!strcmp(res->name, "scatter")) {
1605 		if (!strcmp(res->value, "on"))
1606 			rx_mode.enable_scatter = 1;
1607 		else if (!strcmp(res->value, "off"))
1608 			rx_mode.enable_scatter = 0;
1609 		else {
1610 			printf("Unknown parameter\n");
1611 			return;
1612 		}
1613 	} else if (!strcmp(res->name, "rx-cksum")) {
1614 		if (!strcmp(res->value, "on"))
1615 			rx_mode.hw_ip_checksum = 1;
1616 		else if (!strcmp(res->value, "off"))
1617 			rx_mode.hw_ip_checksum = 0;
1618 		else {
1619 			printf("Unknown parameter\n");
1620 			return;
1621 		}
1622 	} else if (!strcmp(res->name, "rx-timestamp")) {
1623 		if (!strcmp(res->value, "on"))
1624 			rx_mode.hw_timestamp = 1;
1625 		else if (!strcmp(res->value, "off"))
1626 			rx_mode.hw_timestamp = 0;
1627 		else {
1628 			printf("Unknown parameter\n");
1629 			return;
1630 		}
1631 	} else if (!strcmp(res->name, "hw-vlan")) {
1632 		if (!strcmp(res->value, "on")) {
1633 			rx_mode.hw_vlan_filter = 1;
1634 			rx_mode.hw_vlan_strip  = 1;
1635 		}
1636 		else if (!strcmp(res->value, "off")) {
1637 			rx_mode.hw_vlan_filter = 0;
1638 			rx_mode.hw_vlan_strip  = 0;
1639 		}
1640 		else {
1641 			printf("Unknown parameter\n");
1642 			return;
1643 		}
1644 	} else if (!strcmp(res->name, "hw-vlan-filter")) {
1645 		if (!strcmp(res->value, "on"))
1646 			rx_mode.hw_vlan_filter = 1;
1647 		else if (!strcmp(res->value, "off"))
1648 			rx_mode.hw_vlan_filter = 0;
1649 		else {
1650 			printf("Unknown parameter\n");
1651 			return;
1652 		}
1653 	} else if (!strcmp(res->name, "hw-vlan-strip")) {
1654 		if (!strcmp(res->value, "on"))
1655 			rx_mode.hw_vlan_strip  = 1;
1656 		else if (!strcmp(res->value, "off"))
1657 			rx_mode.hw_vlan_strip  = 0;
1658 		else {
1659 			printf("Unknown parameter\n");
1660 			return;
1661 		}
1662 	} else if (!strcmp(res->name, "hw-vlan-extend")) {
1663 		if (!strcmp(res->value, "on"))
1664 			rx_mode.hw_vlan_extend = 1;
1665 		else if (!strcmp(res->value, "off"))
1666 			rx_mode.hw_vlan_extend = 0;
1667 		else {
1668 			printf("Unknown parameter\n");
1669 			return;
1670 		}
1671 	} else if (!strcmp(res->name, "drop-en")) {
1672 		if (!strcmp(res->value, "on"))
1673 			rx_drop_en = 1;
1674 		else if (!strcmp(res->value, "off"))
1675 			rx_drop_en = 0;
1676 		else {
1677 			printf("Unknown parameter\n");
1678 			return;
1679 		}
1680 	} else {
1681 		printf("Unknown parameter\n");
1682 		return;
1683 	}
1684 
1685 	init_port_config();
1686 
1687 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1688 }
1689 
1690 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1691 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1692 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1693 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1694 								"config");
1695 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1696 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1697 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1698 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1699 					"crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1700 					"hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1701 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1702 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1703 							"on#off");
1704 
1705 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1706 	.f = cmd_config_rx_mode_flag_parsed,
1707 	.data = NULL,
1708 	.help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1709 		"hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1710 	.tokens = {
1711 		(void *)&cmd_config_rx_mode_flag_port,
1712 		(void *)&cmd_config_rx_mode_flag_keyword,
1713 		(void *)&cmd_config_rx_mode_flag_all,
1714 		(void *)&cmd_config_rx_mode_flag_name,
1715 		(void *)&cmd_config_rx_mode_flag_value,
1716 		NULL,
1717 	},
1718 };
1719 
1720 /* *** configure rss *** */
1721 struct cmd_config_rss {
1722 	cmdline_fixed_string_t port;
1723 	cmdline_fixed_string_t keyword;
1724 	cmdline_fixed_string_t all;
1725 	cmdline_fixed_string_t name;
1726 	cmdline_fixed_string_t value;
1727 };
1728 
1729 static void
1730 cmd_config_rss_parsed(void *parsed_result,
1731 			__attribute__((unused)) struct cmdline *cl,
1732 			__attribute__((unused)) void *data)
1733 {
1734 	struct cmd_config_rss *res = parsed_result;
1735 	struct rte_eth_rss_conf rss_conf;
1736 	int diag;
1737 	uint8_t i;
1738 
1739 	if (!strcmp(res->value, "all"))
1740 		rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1741 				ETH_RSS_UDP | ETH_RSS_SCTP |
1742 					ETH_RSS_L2_PAYLOAD;
1743 	else if (!strcmp(res->value, "ip"))
1744 		rss_conf.rss_hf = ETH_RSS_IP;
1745 	else if (!strcmp(res->value, "udp"))
1746 		rss_conf.rss_hf = ETH_RSS_UDP;
1747 	else if (!strcmp(res->value, "tcp"))
1748 		rss_conf.rss_hf = ETH_RSS_TCP;
1749 	else if (!strcmp(res->value, "sctp"))
1750 		rss_conf.rss_hf = ETH_RSS_SCTP;
1751 	else if (!strcmp(res->value, "ether"))
1752 		rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1753 	else if (!strcmp(res->value, "port"))
1754 		rss_conf.rss_hf = ETH_RSS_PORT;
1755 	else if (!strcmp(res->value, "vxlan"))
1756 		rss_conf.rss_hf = ETH_RSS_VXLAN;
1757 	else if (!strcmp(res->value, "geneve"))
1758 		rss_conf.rss_hf = ETH_RSS_GENEVE;
1759 	else if (!strcmp(res->value, "nvgre"))
1760 		rss_conf.rss_hf = ETH_RSS_NVGRE;
1761 	else if (!strcmp(res->value, "none"))
1762 		rss_conf.rss_hf = 0;
1763 	else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1764 						atoi(res->value) < 64)
1765 		rss_conf.rss_hf = 1ULL << atoi(res->value);
1766 	else {
1767 		printf("Unknown parameter\n");
1768 		return;
1769 	}
1770 	rss_conf.rss_key = NULL;
1771 	for (i = 0; i < rte_eth_dev_count(); i++) {
1772 		diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1773 		if (diag < 0)
1774 			printf("Configuration of RSS hash at ethernet port %d "
1775 				"failed with error (%d): %s.\n",
1776 				i, -diag, strerror(-diag));
1777 	}
1778 }
1779 
1780 cmdline_parse_token_string_t cmd_config_rss_port =
1781 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1782 cmdline_parse_token_string_t cmd_config_rss_keyword =
1783 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1784 cmdline_parse_token_string_t cmd_config_rss_all =
1785 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1786 cmdline_parse_token_string_t cmd_config_rss_name =
1787 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1788 cmdline_parse_token_string_t cmd_config_rss_value =
1789 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1790 
1791 cmdline_parse_inst_t cmd_config_rss = {
1792 	.f = cmd_config_rss_parsed,
1793 	.data = NULL,
1794 	.help_str = "port config all rss "
1795 		"all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1796 	.tokens = {
1797 		(void *)&cmd_config_rss_port,
1798 		(void *)&cmd_config_rss_keyword,
1799 		(void *)&cmd_config_rss_all,
1800 		(void *)&cmd_config_rss_name,
1801 		(void *)&cmd_config_rss_value,
1802 		NULL,
1803 	},
1804 };
1805 
1806 /* *** configure rss hash key *** */
1807 struct cmd_config_rss_hash_key {
1808 	cmdline_fixed_string_t port;
1809 	cmdline_fixed_string_t config;
1810 	uint8_t port_id;
1811 	cmdline_fixed_string_t rss_hash_key;
1812 	cmdline_fixed_string_t rss_type;
1813 	cmdline_fixed_string_t key;
1814 };
1815 
1816 static uint8_t
1817 hexa_digit_to_value(char hexa_digit)
1818 {
1819 	if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1820 		return (uint8_t) (hexa_digit - '0');
1821 	if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1822 		return (uint8_t) ((hexa_digit - 'a') + 10);
1823 	if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1824 		return (uint8_t) ((hexa_digit - 'A') + 10);
1825 	/* Invalid hexa digit */
1826 	return 0xFF;
1827 }
1828 
1829 static uint8_t
1830 parse_and_check_key_hexa_digit(char *key, int idx)
1831 {
1832 	uint8_t hexa_v;
1833 
1834 	hexa_v = hexa_digit_to_value(key[idx]);
1835 	if (hexa_v == 0xFF)
1836 		printf("invalid key: character %c at position %d is not a "
1837 		       "valid hexa digit\n", key[idx], idx);
1838 	return hexa_v;
1839 }
1840 
1841 static void
1842 cmd_config_rss_hash_key_parsed(void *parsed_result,
1843 			       __attribute__((unused)) struct cmdline *cl,
1844 			       __attribute__((unused)) void *data)
1845 {
1846 	struct cmd_config_rss_hash_key *res = parsed_result;
1847 	uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1848 	uint8_t xdgt0;
1849 	uint8_t xdgt1;
1850 	int i;
1851 	struct rte_eth_dev_info dev_info;
1852 	uint8_t hash_key_size;
1853 	uint32_t key_len;
1854 
1855 	memset(&dev_info, 0, sizeof(dev_info));
1856 	rte_eth_dev_info_get(res->port_id, &dev_info);
1857 	if (dev_info.hash_key_size > 0 &&
1858 			dev_info.hash_key_size <= sizeof(hash_key))
1859 		hash_key_size = dev_info.hash_key_size;
1860 	else {
1861 		printf("dev_info did not provide a valid hash key size\n");
1862 		return;
1863 	}
1864 	/* Check the length of the RSS hash key */
1865 	key_len = strlen(res->key);
1866 	if (key_len != (hash_key_size * 2)) {
1867 		printf("key length: %d invalid - key must be a string of %d"
1868 			   " hexa-decimal numbers\n",
1869 			   (int) key_len, hash_key_size * 2);
1870 		return;
1871 	}
1872 	/* Translate RSS hash key into binary representation */
1873 	for (i = 0; i < hash_key_size; i++) {
1874 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1875 		if (xdgt0 == 0xFF)
1876 			return;
1877 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1878 		if (xdgt1 == 0xFF)
1879 			return;
1880 		hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1881 	}
1882 	port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1883 			hash_key_size);
1884 }
1885 
1886 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1887 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1888 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1889 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1890 				 "config");
1891 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1892 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1893 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1894 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1895 				 rss_hash_key, "rss-hash-key");
1896 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1897 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1898 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1899 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1900 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1901 				 "ipv6-tcp-ex#ipv6-udp-ex");
1902 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1903 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1904 
1905 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1906 	.f = cmd_config_rss_hash_key_parsed,
1907 	.data = NULL,
1908 	.help_str = "port config <port_id> rss-hash-key "
1909 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1910 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1911 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
1912 		"<string of hex digits (variable length, NIC dependent)>",
1913 	.tokens = {
1914 		(void *)&cmd_config_rss_hash_key_port,
1915 		(void *)&cmd_config_rss_hash_key_config,
1916 		(void *)&cmd_config_rss_hash_key_port_id,
1917 		(void *)&cmd_config_rss_hash_key_rss_hash_key,
1918 		(void *)&cmd_config_rss_hash_key_rss_type,
1919 		(void *)&cmd_config_rss_hash_key_value,
1920 		NULL,
1921 	},
1922 };
1923 
1924 /* *** configure port rxq/txq start/stop *** */
1925 struct cmd_config_rxtx_queue {
1926 	cmdline_fixed_string_t port;
1927 	uint8_t portid;
1928 	cmdline_fixed_string_t rxtxq;
1929 	uint16_t qid;
1930 	cmdline_fixed_string_t opname;
1931 };
1932 
1933 static void
1934 cmd_config_rxtx_queue_parsed(void *parsed_result,
1935 			__attribute__((unused)) struct cmdline *cl,
1936 			__attribute__((unused)) void *data)
1937 {
1938 	struct cmd_config_rxtx_queue *res = parsed_result;
1939 	uint8_t isrx;
1940 	uint8_t isstart;
1941 	int ret = 0;
1942 
1943 	if (test_done == 0) {
1944 		printf("Please stop forwarding first\n");
1945 		return;
1946 	}
1947 
1948 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
1949 		return;
1950 
1951 	if (port_is_started(res->portid) != 1) {
1952 		printf("Please start port %u first\n", res->portid);
1953 		return;
1954 	}
1955 
1956 	if (!strcmp(res->rxtxq, "rxq"))
1957 		isrx = 1;
1958 	else if (!strcmp(res->rxtxq, "txq"))
1959 		isrx = 0;
1960 	else {
1961 		printf("Unknown parameter\n");
1962 		return;
1963 	}
1964 
1965 	if (isrx && rx_queue_id_is_invalid(res->qid))
1966 		return;
1967 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
1968 		return;
1969 
1970 	if (!strcmp(res->opname, "start"))
1971 		isstart = 1;
1972 	else if (!strcmp(res->opname, "stop"))
1973 		isstart = 0;
1974 	else {
1975 		printf("Unknown parameter\n");
1976 		return;
1977 	}
1978 
1979 	if (isstart && isrx)
1980 		ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1981 	else if (!isstart && isrx)
1982 		ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1983 	else if (isstart && !isrx)
1984 		ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1985 	else
1986 		ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1987 
1988 	if (ret == -ENOTSUP)
1989 		printf("Function not supported in PMD driver\n");
1990 }
1991 
1992 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1993 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1994 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1995 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1996 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1997 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1998 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1999 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2000 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2001 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2002 						"start#stop");
2003 
2004 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2005 	.f = cmd_config_rxtx_queue_parsed,
2006 	.data = NULL,
2007 	.help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2008 	.tokens = {
2009 		(void *)&cmd_config_speed_all_port,
2010 		(void *)&cmd_config_rxtx_queue_portid,
2011 		(void *)&cmd_config_rxtx_queue_rxtxq,
2012 		(void *)&cmd_config_rxtx_queue_qid,
2013 		(void *)&cmd_config_rxtx_queue_opname,
2014 		NULL,
2015 	},
2016 };
2017 
2018 /* *** Configure RSS RETA *** */
2019 struct cmd_config_rss_reta {
2020 	cmdline_fixed_string_t port;
2021 	cmdline_fixed_string_t keyword;
2022 	uint8_t port_id;
2023 	cmdline_fixed_string_t name;
2024 	cmdline_fixed_string_t list_name;
2025 	cmdline_fixed_string_t list_of_items;
2026 };
2027 
2028 static int
2029 parse_reta_config(const char *str,
2030 		  struct rte_eth_rss_reta_entry64 *reta_conf,
2031 		  uint16_t nb_entries)
2032 {
2033 	int i;
2034 	unsigned size;
2035 	uint16_t hash_index, idx, shift;
2036 	uint16_t nb_queue;
2037 	char s[256];
2038 	const char *p, *p0 = str;
2039 	char *end;
2040 	enum fieldnames {
2041 		FLD_HASH_INDEX = 0,
2042 		FLD_QUEUE,
2043 		_NUM_FLD
2044 	};
2045 	unsigned long int_fld[_NUM_FLD];
2046 	char *str_fld[_NUM_FLD];
2047 
2048 	while ((p = strchr(p0,'(')) != NULL) {
2049 		++p;
2050 		if((p0 = strchr(p,')')) == NULL)
2051 			return -1;
2052 
2053 		size = p0 - p;
2054 		if(size >= sizeof(s))
2055 			return -1;
2056 
2057 		snprintf(s, sizeof(s), "%.*s", size, p);
2058 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2059 			return -1;
2060 		for (i = 0; i < _NUM_FLD; i++) {
2061 			errno = 0;
2062 			int_fld[i] = strtoul(str_fld[i], &end, 0);
2063 			if (errno != 0 || end == str_fld[i] ||
2064 					int_fld[i] > 65535)
2065 				return -1;
2066 		}
2067 
2068 		hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2069 		nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2070 
2071 		if (hash_index >= nb_entries) {
2072 			printf("Invalid RETA hash index=%d\n", hash_index);
2073 			return -1;
2074 		}
2075 
2076 		idx = hash_index / RTE_RETA_GROUP_SIZE;
2077 		shift = hash_index % RTE_RETA_GROUP_SIZE;
2078 		reta_conf[idx].mask |= (1ULL << shift);
2079 		reta_conf[idx].reta[shift] = nb_queue;
2080 	}
2081 
2082 	return 0;
2083 }
2084 
2085 static void
2086 cmd_set_rss_reta_parsed(void *parsed_result,
2087 			__attribute__((unused)) struct cmdline *cl,
2088 			__attribute__((unused)) void *data)
2089 {
2090 	int ret;
2091 	struct rte_eth_dev_info dev_info;
2092 	struct rte_eth_rss_reta_entry64 reta_conf[8];
2093 	struct cmd_config_rss_reta *res = parsed_result;
2094 
2095 	memset(&dev_info, 0, sizeof(dev_info));
2096 	rte_eth_dev_info_get(res->port_id, &dev_info);
2097 	if (dev_info.reta_size == 0) {
2098 		printf("Redirection table size is 0 which is "
2099 					"invalid for RSS\n");
2100 		return;
2101 	} else
2102 		printf("The reta size of port %d is %u\n",
2103 			res->port_id, dev_info.reta_size);
2104 	if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2105 		printf("Currently do not support more than %u entries of "
2106 			"redirection table\n", ETH_RSS_RETA_SIZE_512);
2107 		return;
2108 	}
2109 
2110 	memset(reta_conf, 0, sizeof(reta_conf));
2111 	if (!strcmp(res->list_name, "reta")) {
2112 		if (parse_reta_config(res->list_of_items, reta_conf,
2113 						dev_info.reta_size)) {
2114 			printf("Invalid RSS Redirection Table "
2115 					"config entered\n");
2116 			return;
2117 		}
2118 		ret = rte_eth_dev_rss_reta_update(res->port_id,
2119 				reta_conf, dev_info.reta_size);
2120 		if (ret != 0)
2121 			printf("Bad redirection table parameter, "
2122 					"return code = %d \n", ret);
2123 	}
2124 }
2125 
2126 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2127 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2128 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2129 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2130 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2131 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
2132 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2133 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2134 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2135 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2136 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2137         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2138                                  NULL);
2139 cmdline_parse_inst_t cmd_config_rss_reta = {
2140 	.f = cmd_set_rss_reta_parsed,
2141 	.data = NULL,
2142 	.help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2143 	.tokens = {
2144 		(void *)&cmd_config_rss_reta_port,
2145 		(void *)&cmd_config_rss_reta_keyword,
2146 		(void *)&cmd_config_rss_reta_port_id,
2147 		(void *)&cmd_config_rss_reta_name,
2148 		(void *)&cmd_config_rss_reta_list_name,
2149 		(void *)&cmd_config_rss_reta_list_of_items,
2150 		NULL,
2151 	},
2152 };
2153 
2154 /* *** SHOW PORT RETA INFO *** */
2155 struct cmd_showport_reta {
2156 	cmdline_fixed_string_t show;
2157 	cmdline_fixed_string_t port;
2158 	uint8_t port_id;
2159 	cmdline_fixed_string_t rss;
2160 	cmdline_fixed_string_t reta;
2161 	uint16_t size;
2162 	cmdline_fixed_string_t list_of_items;
2163 };
2164 
2165 static int
2166 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2167 			   uint16_t nb_entries,
2168 			   char *str)
2169 {
2170 	uint32_t size;
2171 	const char *p, *p0 = str;
2172 	char s[256];
2173 	char *end;
2174 	char *str_fld[8];
2175 	uint16_t i;
2176 	uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2177 			RTE_RETA_GROUP_SIZE;
2178 	int ret;
2179 
2180 	p = strchr(p0, '(');
2181 	if (p == NULL)
2182 		return -1;
2183 	p++;
2184 	p0 = strchr(p, ')');
2185 	if (p0 == NULL)
2186 		return -1;
2187 	size = p0 - p;
2188 	if (size >= sizeof(s)) {
2189 		printf("The string size exceeds the internal buffer size\n");
2190 		return -1;
2191 	}
2192 	snprintf(s, sizeof(s), "%.*s", size, p);
2193 	ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2194 	if (ret <= 0 || ret != num) {
2195 		printf("The bits of masks do not match the number of "
2196 					"reta entries: %u\n", num);
2197 		return -1;
2198 	}
2199 	for (i = 0; i < ret; i++)
2200 		conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2201 
2202 	return 0;
2203 }
2204 
2205 static void
2206 cmd_showport_reta_parsed(void *parsed_result,
2207 			 __attribute__((unused)) struct cmdline *cl,
2208 			 __attribute__((unused)) void *data)
2209 {
2210 	struct cmd_showport_reta *res = parsed_result;
2211 	struct rte_eth_rss_reta_entry64 reta_conf[8];
2212 	struct rte_eth_dev_info dev_info;
2213 	uint16_t max_reta_size;
2214 
2215 	memset(&dev_info, 0, sizeof(dev_info));
2216 	rte_eth_dev_info_get(res->port_id, &dev_info);
2217 	max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2218 	if (res->size == 0 || res->size > max_reta_size) {
2219 		printf("Invalid redirection table size: %u (1-%u)\n",
2220 			res->size, max_reta_size);
2221 		return;
2222 	}
2223 
2224 	memset(reta_conf, 0, sizeof(reta_conf));
2225 	if (showport_parse_reta_config(reta_conf, res->size,
2226 				res->list_of_items) < 0) {
2227 		printf("Invalid string: %s for reta masks\n",
2228 					res->list_of_items);
2229 		return;
2230 	}
2231 	port_rss_reta_info(res->port_id, reta_conf, res->size);
2232 }
2233 
2234 cmdline_parse_token_string_t cmd_showport_reta_show =
2235 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2236 cmdline_parse_token_string_t cmd_showport_reta_port =
2237 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2238 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2239 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
2240 cmdline_parse_token_string_t cmd_showport_reta_rss =
2241 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2242 cmdline_parse_token_string_t cmd_showport_reta_reta =
2243 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2244 cmdline_parse_token_num_t cmd_showport_reta_size =
2245 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2246 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2247 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2248 					list_of_items, NULL);
2249 
2250 cmdline_parse_inst_t cmd_showport_reta = {
2251 	.f = cmd_showport_reta_parsed,
2252 	.data = NULL,
2253 	.help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2254 	.tokens = {
2255 		(void *)&cmd_showport_reta_show,
2256 		(void *)&cmd_showport_reta_port,
2257 		(void *)&cmd_showport_reta_port_id,
2258 		(void *)&cmd_showport_reta_rss,
2259 		(void *)&cmd_showport_reta_reta,
2260 		(void *)&cmd_showport_reta_size,
2261 		(void *)&cmd_showport_reta_list_of_items,
2262 		NULL,
2263 	},
2264 };
2265 
2266 /* *** Show RSS hash configuration *** */
2267 struct cmd_showport_rss_hash {
2268 	cmdline_fixed_string_t show;
2269 	cmdline_fixed_string_t port;
2270 	uint8_t port_id;
2271 	cmdline_fixed_string_t rss_hash;
2272 	cmdline_fixed_string_t rss_type;
2273 	cmdline_fixed_string_t key; /* optional argument */
2274 };
2275 
2276 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2277 				__attribute__((unused)) struct cmdline *cl,
2278 				void *show_rss_key)
2279 {
2280 	struct cmd_showport_rss_hash *res = parsed_result;
2281 
2282 	port_rss_hash_conf_show(res->port_id, res->rss_type,
2283 				show_rss_key != NULL);
2284 }
2285 
2286 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2287 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2288 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2289 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2290 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2291 	TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
2292 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2293 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2294 				 "rss-hash");
2295 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2296 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2297 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2298 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2299 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2300 				 "ipv6-tcp-ex#ipv6-udp-ex");
2301 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2302 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2303 
2304 cmdline_parse_inst_t cmd_showport_rss_hash = {
2305 	.f = cmd_showport_rss_hash_parsed,
2306 	.data = NULL,
2307 	.help_str = "show port <port_id> rss-hash "
2308 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2309 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2310 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2311 	.tokens = {
2312 		(void *)&cmd_showport_rss_hash_show,
2313 		(void *)&cmd_showport_rss_hash_port,
2314 		(void *)&cmd_showport_rss_hash_port_id,
2315 		(void *)&cmd_showport_rss_hash_rss_hash,
2316 		(void *)&cmd_showport_rss_hash_rss_hash_info,
2317 		NULL,
2318 	},
2319 };
2320 
2321 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2322 	.f = cmd_showport_rss_hash_parsed,
2323 	.data = (void *)1,
2324 	.help_str = "show port <port_id> rss-hash "
2325 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2326 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2327 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2328 	.tokens = {
2329 		(void *)&cmd_showport_rss_hash_show,
2330 		(void *)&cmd_showport_rss_hash_port,
2331 		(void *)&cmd_showport_rss_hash_port_id,
2332 		(void *)&cmd_showport_rss_hash_rss_hash,
2333 		(void *)&cmd_showport_rss_hash_rss_hash_info,
2334 		(void *)&cmd_showport_rss_hash_rss_key,
2335 		NULL,
2336 	},
2337 };
2338 
2339 /* *** Configure DCB *** */
2340 struct cmd_config_dcb {
2341 	cmdline_fixed_string_t port;
2342 	cmdline_fixed_string_t config;
2343 	uint8_t port_id;
2344 	cmdline_fixed_string_t dcb;
2345 	cmdline_fixed_string_t vt;
2346 	cmdline_fixed_string_t vt_en;
2347 	uint8_t num_tcs;
2348 	cmdline_fixed_string_t pfc;
2349 	cmdline_fixed_string_t pfc_en;
2350 };
2351 
2352 static void
2353 cmd_config_dcb_parsed(void *parsed_result,
2354                         __attribute__((unused)) struct cmdline *cl,
2355                         __attribute__((unused)) void *data)
2356 {
2357 	struct cmd_config_dcb *res = parsed_result;
2358 	portid_t port_id = res->port_id;
2359 	struct rte_port *port;
2360 	uint8_t pfc_en;
2361 	int ret;
2362 
2363 	port = &ports[port_id];
2364 	/** Check if the port is not started **/
2365 	if (port->port_status != RTE_PORT_STOPPED) {
2366 		printf("Please stop port %d first\n", port_id);
2367 		return;
2368 	}
2369 
2370 	if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2371 		printf("The invalid number of traffic class,"
2372 			" only 4 or 8 allowed.\n");
2373 		return;
2374 	}
2375 
2376 	if (nb_fwd_lcores < res->num_tcs) {
2377 		printf("nb_cores shouldn't be less than number of TCs.\n");
2378 		return;
2379 	}
2380 	if (!strncmp(res->pfc_en, "on", 2))
2381 		pfc_en = 1;
2382 	else
2383 		pfc_en = 0;
2384 
2385 	/* DCB in VT mode */
2386 	if (!strncmp(res->vt_en, "on", 2))
2387 		ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2388 				(enum rte_eth_nb_tcs)res->num_tcs,
2389 				pfc_en);
2390 	else
2391 		ret = init_port_dcb_config(port_id, DCB_ENABLED,
2392 				(enum rte_eth_nb_tcs)res->num_tcs,
2393 				pfc_en);
2394 
2395 
2396 	if (ret != 0) {
2397 		printf("Cannot initialize network ports.\n");
2398 		return;
2399 	}
2400 
2401 	cmd_reconfig_device_queue(port_id, 1, 1);
2402 }
2403 
2404 cmdline_parse_token_string_t cmd_config_dcb_port =
2405         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2406 cmdline_parse_token_string_t cmd_config_dcb_config =
2407         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2408 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2409         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2410 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2411         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2412 cmdline_parse_token_string_t cmd_config_dcb_vt =
2413         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2414 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2415         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2416 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2417         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2418 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2419         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2420 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2421         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2422 
2423 cmdline_parse_inst_t cmd_config_dcb = {
2424 	.f = cmd_config_dcb_parsed,
2425 	.data = NULL,
2426 	.help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2427 	.tokens = {
2428 		(void *)&cmd_config_dcb_port,
2429 		(void *)&cmd_config_dcb_config,
2430 		(void *)&cmd_config_dcb_port_id,
2431 		(void *)&cmd_config_dcb_dcb,
2432 		(void *)&cmd_config_dcb_vt,
2433 		(void *)&cmd_config_dcb_vt_en,
2434 		(void *)&cmd_config_dcb_num_tcs,
2435 		(void *)&cmd_config_dcb_pfc,
2436 		(void *)&cmd_config_dcb_pfc_en,
2437                 NULL,
2438         },
2439 };
2440 
2441 /* *** configure number of packets per burst *** */
2442 struct cmd_config_burst {
2443 	cmdline_fixed_string_t port;
2444 	cmdline_fixed_string_t keyword;
2445 	cmdline_fixed_string_t all;
2446 	cmdline_fixed_string_t name;
2447 	uint16_t value;
2448 };
2449 
2450 static void
2451 cmd_config_burst_parsed(void *parsed_result,
2452 			__attribute__((unused)) struct cmdline *cl,
2453 			__attribute__((unused)) void *data)
2454 {
2455 	struct cmd_config_burst *res = parsed_result;
2456 
2457 	if (!all_ports_stopped()) {
2458 		printf("Please stop all ports first\n");
2459 		return;
2460 	}
2461 
2462 	if (!strcmp(res->name, "burst")) {
2463 		if (res->value < 1 || res->value > MAX_PKT_BURST) {
2464 			printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2465 			return;
2466 		}
2467 		nb_pkt_per_burst = res->value;
2468 	} else {
2469 		printf("Unknown parameter\n");
2470 		return;
2471 	}
2472 
2473 	init_port_config();
2474 
2475 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2476 }
2477 
2478 cmdline_parse_token_string_t cmd_config_burst_port =
2479 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2480 cmdline_parse_token_string_t cmd_config_burst_keyword =
2481 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2482 cmdline_parse_token_string_t cmd_config_burst_all =
2483 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2484 cmdline_parse_token_string_t cmd_config_burst_name =
2485 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2486 cmdline_parse_token_num_t cmd_config_burst_value =
2487 	TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2488 
2489 cmdline_parse_inst_t cmd_config_burst = {
2490 	.f = cmd_config_burst_parsed,
2491 	.data = NULL,
2492 	.help_str = "port config all burst <value>",
2493 	.tokens = {
2494 		(void *)&cmd_config_burst_port,
2495 		(void *)&cmd_config_burst_keyword,
2496 		(void *)&cmd_config_burst_all,
2497 		(void *)&cmd_config_burst_name,
2498 		(void *)&cmd_config_burst_value,
2499 		NULL,
2500 	},
2501 };
2502 
2503 /* *** configure rx/tx queues *** */
2504 struct cmd_config_thresh {
2505 	cmdline_fixed_string_t port;
2506 	cmdline_fixed_string_t keyword;
2507 	cmdline_fixed_string_t all;
2508 	cmdline_fixed_string_t name;
2509 	uint8_t value;
2510 };
2511 
2512 static void
2513 cmd_config_thresh_parsed(void *parsed_result,
2514 			__attribute__((unused)) struct cmdline *cl,
2515 			__attribute__((unused)) void *data)
2516 {
2517 	struct cmd_config_thresh *res = parsed_result;
2518 
2519 	if (!all_ports_stopped()) {
2520 		printf("Please stop all ports first\n");
2521 		return;
2522 	}
2523 
2524 	if (!strcmp(res->name, "txpt"))
2525 		tx_pthresh = res->value;
2526 	else if(!strcmp(res->name, "txht"))
2527 		tx_hthresh = res->value;
2528 	else if(!strcmp(res->name, "txwt"))
2529 		tx_wthresh = res->value;
2530 	else if(!strcmp(res->name, "rxpt"))
2531 		rx_pthresh = res->value;
2532 	else if(!strcmp(res->name, "rxht"))
2533 		rx_hthresh = res->value;
2534 	else if(!strcmp(res->name, "rxwt"))
2535 		rx_wthresh = res->value;
2536 	else {
2537 		printf("Unknown parameter\n");
2538 		return;
2539 	}
2540 
2541 	init_port_config();
2542 
2543 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2544 }
2545 
2546 cmdline_parse_token_string_t cmd_config_thresh_port =
2547 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2548 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2549 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2550 cmdline_parse_token_string_t cmd_config_thresh_all =
2551 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2552 cmdline_parse_token_string_t cmd_config_thresh_name =
2553 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2554 				"txpt#txht#txwt#rxpt#rxht#rxwt");
2555 cmdline_parse_token_num_t cmd_config_thresh_value =
2556 	TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2557 
2558 cmdline_parse_inst_t cmd_config_thresh = {
2559 	.f = cmd_config_thresh_parsed,
2560 	.data = NULL,
2561 	.help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2562 	.tokens = {
2563 		(void *)&cmd_config_thresh_port,
2564 		(void *)&cmd_config_thresh_keyword,
2565 		(void *)&cmd_config_thresh_all,
2566 		(void *)&cmd_config_thresh_name,
2567 		(void *)&cmd_config_thresh_value,
2568 		NULL,
2569 	},
2570 };
2571 
2572 /* *** configure free/rs threshold *** */
2573 struct cmd_config_threshold {
2574 	cmdline_fixed_string_t port;
2575 	cmdline_fixed_string_t keyword;
2576 	cmdline_fixed_string_t all;
2577 	cmdline_fixed_string_t name;
2578 	uint16_t value;
2579 };
2580 
2581 static void
2582 cmd_config_threshold_parsed(void *parsed_result,
2583 			__attribute__((unused)) struct cmdline *cl,
2584 			__attribute__((unused)) void *data)
2585 {
2586 	struct cmd_config_threshold *res = parsed_result;
2587 
2588 	if (!all_ports_stopped()) {
2589 		printf("Please stop all ports first\n");
2590 		return;
2591 	}
2592 
2593 	if (!strcmp(res->name, "txfreet"))
2594 		tx_free_thresh = res->value;
2595 	else if (!strcmp(res->name, "txrst"))
2596 		tx_rs_thresh = res->value;
2597 	else if (!strcmp(res->name, "rxfreet"))
2598 		rx_free_thresh = res->value;
2599 	else {
2600 		printf("Unknown parameter\n");
2601 		return;
2602 	}
2603 
2604 	init_port_config();
2605 
2606 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2607 }
2608 
2609 cmdline_parse_token_string_t cmd_config_threshold_port =
2610 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2611 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2612 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2613 								"config");
2614 cmdline_parse_token_string_t cmd_config_threshold_all =
2615 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2616 cmdline_parse_token_string_t cmd_config_threshold_name =
2617 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2618 						"txfreet#txrst#rxfreet");
2619 cmdline_parse_token_num_t cmd_config_threshold_value =
2620 	TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2621 
2622 cmdline_parse_inst_t cmd_config_threshold = {
2623 	.f = cmd_config_threshold_parsed,
2624 	.data = NULL,
2625 	.help_str = "port config all txfreet|txrst|rxfreet <value>",
2626 	.tokens = {
2627 		(void *)&cmd_config_threshold_port,
2628 		(void *)&cmd_config_threshold_keyword,
2629 		(void *)&cmd_config_threshold_all,
2630 		(void *)&cmd_config_threshold_name,
2631 		(void *)&cmd_config_threshold_value,
2632 		NULL,
2633 	},
2634 };
2635 
2636 /* *** stop *** */
2637 struct cmd_stop_result {
2638 	cmdline_fixed_string_t stop;
2639 };
2640 
2641 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2642 			    __attribute__((unused)) struct cmdline *cl,
2643 			    __attribute__((unused)) void *data)
2644 {
2645 	stop_packet_forwarding();
2646 }
2647 
2648 cmdline_parse_token_string_t cmd_stop_stop =
2649 	TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2650 
2651 cmdline_parse_inst_t cmd_stop = {
2652 	.f = cmd_stop_parsed,
2653 	.data = NULL,
2654 	.help_str = "stop: Stop packet forwarding",
2655 	.tokens = {
2656 		(void *)&cmd_stop_stop,
2657 		NULL,
2658 	},
2659 };
2660 
2661 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2662 
2663 unsigned int
2664 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2665 		unsigned int *parsed_items, int check_unique_values)
2666 {
2667 	unsigned int nb_item;
2668 	unsigned int value;
2669 	unsigned int i;
2670 	unsigned int j;
2671 	int value_ok;
2672 	char c;
2673 
2674 	/*
2675 	 * First parse all items in the list and store their value.
2676 	 */
2677 	value = 0;
2678 	nb_item = 0;
2679 	value_ok = 0;
2680 	for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2681 		c = str[i];
2682 		if ((c >= '0') && (c <= '9')) {
2683 			value = (unsigned int) (value * 10 + (c - '0'));
2684 			value_ok = 1;
2685 			continue;
2686 		}
2687 		if (c != ',') {
2688 			printf("character %c is not a decimal digit\n", c);
2689 			return 0;
2690 		}
2691 		if (! value_ok) {
2692 			printf("No valid value before comma\n");
2693 			return 0;
2694 		}
2695 		if (nb_item < max_items) {
2696 			parsed_items[nb_item] = value;
2697 			value_ok = 0;
2698 			value = 0;
2699 		}
2700 		nb_item++;
2701 	}
2702 	if (nb_item >= max_items) {
2703 		printf("Number of %s = %u > %u (maximum items)\n",
2704 		       item_name, nb_item + 1, max_items);
2705 		return 0;
2706 	}
2707 	parsed_items[nb_item++] = value;
2708 	if (! check_unique_values)
2709 		return nb_item;
2710 
2711 	/*
2712 	 * Then, check that all values in the list are differents.
2713 	 * No optimization here...
2714 	 */
2715 	for (i = 0; i < nb_item; i++) {
2716 		for (j = i + 1; j < nb_item; j++) {
2717 			if (parsed_items[j] == parsed_items[i]) {
2718 				printf("duplicated %s %u at index %u and %u\n",
2719 				       item_name, parsed_items[i], i, j);
2720 				return 0;
2721 			}
2722 		}
2723 	}
2724 	return nb_item;
2725 }
2726 
2727 struct cmd_set_list_result {
2728 	cmdline_fixed_string_t cmd_keyword;
2729 	cmdline_fixed_string_t list_name;
2730 	cmdline_fixed_string_t list_of_items;
2731 };
2732 
2733 static void cmd_set_list_parsed(void *parsed_result,
2734 				__attribute__((unused)) struct cmdline *cl,
2735 				__attribute__((unused)) void *data)
2736 {
2737 	struct cmd_set_list_result *res;
2738 	union {
2739 		unsigned int lcorelist[RTE_MAX_LCORE];
2740 		unsigned int portlist[RTE_MAX_ETHPORTS];
2741 	} parsed_items;
2742 	unsigned int nb_item;
2743 
2744 	if (test_done == 0) {
2745 		printf("Please stop forwarding first\n");
2746 		return;
2747 	}
2748 
2749 	res = parsed_result;
2750 	if (!strcmp(res->list_name, "corelist")) {
2751 		nb_item = parse_item_list(res->list_of_items, "core",
2752 					  RTE_MAX_LCORE,
2753 					  parsed_items.lcorelist, 1);
2754 		if (nb_item > 0) {
2755 			set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2756 			fwd_config_setup();
2757 		}
2758 		return;
2759 	}
2760 	if (!strcmp(res->list_name, "portlist")) {
2761 		nb_item = parse_item_list(res->list_of_items, "port",
2762 					  RTE_MAX_ETHPORTS,
2763 					  parsed_items.portlist, 1);
2764 		if (nb_item > 0) {
2765 			set_fwd_ports_list(parsed_items.portlist, nb_item);
2766 			fwd_config_setup();
2767 		}
2768 	}
2769 }
2770 
2771 cmdline_parse_token_string_t cmd_set_list_keyword =
2772 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2773 				 "set");
2774 cmdline_parse_token_string_t cmd_set_list_name =
2775 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2776 				 "corelist#portlist");
2777 cmdline_parse_token_string_t cmd_set_list_of_items =
2778 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2779 				 NULL);
2780 
2781 cmdline_parse_inst_t cmd_set_fwd_list = {
2782 	.f = cmd_set_list_parsed,
2783 	.data = NULL,
2784 	.help_str = "set corelist|portlist <list0[,list1]*>",
2785 	.tokens = {
2786 		(void *)&cmd_set_list_keyword,
2787 		(void *)&cmd_set_list_name,
2788 		(void *)&cmd_set_list_of_items,
2789 		NULL,
2790 	},
2791 };
2792 
2793 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2794 
2795 struct cmd_setmask_result {
2796 	cmdline_fixed_string_t set;
2797 	cmdline_fixed_string_t mask;
2798 	uint64_t hexavalue;
2799 };
2800 
2801 static void cmd_set_mask_parsed(void *parsed_result,
2802 				__attribute__((unused)) struct cmdline *cl,
2803 				__attribute__((unused)) void *data)
2804 {
2805 	struct cmd_setmask_result *res = parsed_result;
2806 
2807 	if (test_done == 0) {
2808 		printf("Please stop forwarding first\n");
2809 		return;
2810 	}
2811 	if (!strcmp(res->mask, "coremask")) {
2812 		set_fwd_lcores_mask(res->hexavalue);
2813 		fwd_config_setup();
2814 	} else if (!strcmp(res->mask, "portmask")) {
2815 		set_fwd_ports_mask(res->hexavalue);
2816 		fwd_config_setup();
2817 	}
2818 }
2819 
2820 cmdline_parse_token_string_t cmd_setmask_set =
2821 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2822 cmdline_parse_token_string_t cmd_setmask_mask =
2823 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2824 				 "coremask#portmask");
2825 cmdline_parse_token_num_t cmd_setmask_value =
2826 	TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2827 
2828 cmdline_parse_inst_t cmd_set_fwd_mask = {
2829 	.f = cmd_set_mask_parsed,
2830 	.data = NULL,
2831 	.help_str = "set coremask|portmask <hexadecimal value>",
2832 	.tokens = {
2833 		(void *)&cmd_setmask_set,
2834 		(void *)&cmd_setmask_mask,
2835 		(void *)&cmd_setmask_value,
2836 		NULL,
2837 	},
2838 };
2839 
2840 /*
2841  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2842  */
2843 struct cmd_set_result {
2844 	cmdline_fixed_string_t set;
2845 	cmdline_fixed_string_t what;
2846 	uint16_t value;
2847 };
2848 
2849 static void cmd_set_parsed(void *parsed_result,
2850 			   __attribute__((unused)) struct cmdline *cl,
2851 			   __attribute__((unused)) void *data)
2852 {
2853 	struct cmd_set_result *res = parsed_result;
2854 	if (!strcmp(res->what, "nbport")) {
2855 		set_fwd_ports_number(res->value);
2856 		fwd_config_setup();
2857 	} else if (!strcmp(res->what, "nbcore")) {
2858 		set_fwd_lcores_number(res->value);
2859 		fwd_config_setup();
2860 	} else if (!strcmp(res->what, "burst"))
2861 		set_nb_pkt_per_burst(res->value);
2862 	else if (!strcmp(res->what, "verbose"))
2863 		set_verbose_level(res->value);
2864 }
2865 
2866 cmdline_parse_token_string_t cmd_set_set =
2867 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2868 cmdline_parse_token_string_t cmd_set_what =
2869 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2870 				 "nbport#nbcore#burst#verbose");
2871 cmdline_parse_token_num_t cmd_set_value =
2872 	TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2873 
2874 cmdline_parse_inst_t cmd_set_numbers = {
2875 	.f = cmd_set_parsed,
2876 	.data = NULL,
2877 	.help_str = "set nbport|nbcore|burst|verbose <value>",
2878 	.tokens = {
2879 		(void *)&cmd_set_set,
2880 		(void *)&cmd_set_what,
2881 		(void *)&cmd_set_value,
2882 		NULL,
2883 	},
2884 };
2885 
2886 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2887 
2888 struct cmd_set_txpkts_result {
2889 	cmdline_fixed_string_t cmd_keyword;
2890 	cmdline_fixed_string_t txpkts;
2891 	cmdline_fixed_string_t seg_lengths;
2892 };
2893 
2894 static void
2895 cmd_set_txpkts_parsed(void *parsed_result,
2896 		      __attribute__((unused)) struct cmdline *cl,
2897 		      __attribute__((unused)) void *data)
2898 {
2899 	struct cmd_set_txpkts_result *res;
2900 	unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2901 	unsigned int nb_segs;
2902 
2903 	res = parsed_result;
2904 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2905 				  RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2906 	if (nb_segs > 0)
2907 		set_tx_pkt_segments(seg_lengths, nb_segs);
2908 }
2909 
2910 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2911 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2912 				 cmd_keyword, "set");
2913 cmdline_parse_token_string_t cmd_set_txpkts_name =
2914 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2915 				 txpkts, "txpkts");
2916 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2917 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2918 				 seg_lengths, NULL);
2919 
2920 cmdline_parse_inst_t cmd_set_txpkts = {
2921 	.f = cmd_set_txpkts_parsed,
2922 	.data = NULL,
2923 	.help_str = "set txpkts <len0[,len1]*>",
2924 	.tokens = {
2925 		(void *)&cmd_set_txpkts_keyword,
2926 		(void *)&cmd_set_txpkts_name,
2927 		(void *)&cmd_set_txpkts_lengths,
2928 		NULL,
2929 	},
2930 };
2931 
2932 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2933 
2934 struct cmd_set_txsplit_result {
2935 	cmdline_fixed_string_t cmd_keyword;
2936 	cmdline_fixed_string_t txsplit;
2937 	cmdline_fixed_string_t mode;
2938 };
2939 
2940 static void
2941 cmd_set_txsplit_parsed(void *parsed_result,
2942 		      __attribute__((unused)) struct cmdline *cl,
2943 		      __attribute__((unused)) void *data)
2944 {
2945 	struct cmd_set_txsplit_result *res;
2946 
2947 	res = parsed_result;
2948 	set_tx_pkt_split(res->mode);
2949 }
2950 
2951 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2952 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2953 				 cmd_keyword, "set");
2954 cmdline_parse_token_string_t cmd_set_txsplit_name =
2955 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2956 				 txsplit, "txsplit");
2957 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2958 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2959 				 mode, NULL);
2960 
2961 cmdline_parse_inst_t cmd_set_txsplit = {
2962 	.f = cmd_set_txsplit_parsed,
2963 	.data = NULL,
2964 	.help_str = "set txsplit on|off|rand",
2965 	.tokens = {
2966 		(void *)&cmd_set_txsplit_keyword,
2967 		(void *)&cmd_set_txsplit_name,
2968 		(void *)&cmd_set_txsplit_mode,
2969 		NULL,
2970 	},
2971 };
2972 
2973 /* *** CONFIG TX QUEUE FLAGS *** */
2974 
2975 struct cmd_config_txqflags_result {
2976 	cmdline_fixed_string_t port;
2977 	cmdline_fixed_string_t config;
2978 	cmdline_fixed_string_t all;
2979 	cmdline_fixed_string_t what;
2980 	int32_t hexvalue;
2981 };
2982 
2983 static void cmd_config_txqflags_parsed(void *parsed_result,
2984 				__attribute__((unused)) struct cmdline *cl,
2985 				__attribute__((unused)) void *data)
2986 {
2987 	struct cmd_config_txqflags_result *res = parsed_result;
2988 
2989 	if (!all_ports_stopped()) {
2990 		printf("Please stop all ports first\n");
2991 		return;
2992 	}
2993 
2994 	if (strcmp(res->what, "txqflags")) {
2995 		printf("Unknown parameter\n");
2996 		return;
2997 	}
2998 
2999 	if (res->hexvalue >= 0) {
3000 		txq_flags = res->hexvalue;
3001 	} else {
3002 		printf("txqflags must be >= 0\n");
3003 		return;
3004 	}
3005 
3006 	init_port_config();
3007 
3008 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3009 }
3010 
3011 cmdline_parse_token_string_t cmd_config_txqflags_port =
3012 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
3013 				 "port");
3014 cmdline_parse_token_string_t cmd_config_txqflags_config =
3015 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3016 				 "config");
3017 cmdline_parse_token_string_t cmd_config_txqflags_all =
3018 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3019 				 "all");
3020 cmdline_parse_token_string_t cmd_config_txqflags_what =
3021 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3022 				 "txqflags");
3023 cmdline_parse_token_num_t cmd_config_txqflags_value =
3024 	TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3025 				hexvalue, INT32);
3026 
3027 cmdline_parse_inst_t cmd_config_txqflags = {
3028 	.f = cmd_config_txqflags_parsed,
3029 	.data = NULL,
3030 	.help_str = "port config all txqflags <value>",
3031 	.tokens = {
3032 		(void *)&cmd_config_txqflags_port,
3033 		(void *)&cmd_config_txqflags_config,
3034 		(void *)&cmd_config_txqflags_all,
3035 		(void *)&cmd_config_txqflags_what,
3036 		(void *)&cmd_config_txqflags_value,
3037 		NULL,
3038 	},
3039 };
3040 
3041 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3042 struct cmd_rx_vlan_filter_all_result {
3043 	cmdline_fixed_string_t rx_vlan;
3044 	cmdline_fixed_string_t what;
3045 	cmdline_fixed_string_t all;
3046 	uint8_t port_id;
3047 };
3048 
3049 static void
3050 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3051 			      __attribute__((unused)) struct cmdline *cl,
3052 			      __attribute__((unused)) void *data)
3053 {
3054 	struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3055 
3056 	if (!strcmp(res->what, "add"))
3057 		rx_vlan_all_filter_set(res->port_id, 1);
3058 	else
3059 		rx_vlan_all_filter_set(res->port_id, 0);
3060 }
3061 
3062 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3063 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3064 				 rx_vlan, "rx_vlan");
3065 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3066 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3067 				 what, "add#rm");
3068 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3069 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3070 				 all, "all");
3071 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3072 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3073 			      port_id, UINT8);
3074 
3075 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3076 	.f = cmd_rx_vlan_filter_all_parsed,
3077 	.data = NULL,
3078 	.help_str = "rx_vlan add|rm all <port_id>: "
3079 		"Add/Remove all identifiers to/from the set of VLAN "
3080 		"identifiers filtered by a port",
3081 	.tokens = {
3082 		(void *)&cmd_rx_vlan_filter_all_rx_vlan,
3083 		(void *)&cmd_rx_vlan_filter_all_what,
3084 		(void *)&cmd_rx_vlan_filter_all_all,
3085 		(void *)&cmd_rx_vlan_filter_all_portid,
3086 		NULL,
3087 	},
3088 };
3089 
3090 /* *** VLAN OFFLOAD SET ON A PORT *** */
3091 struct cmd_vlan_offload_result {
3092 	cmdline_fixed_string_t vlan;
3093 	cmdline_fixed_string_t set;
3094 	cmdline_fixed_string_t vlan_type;
3095 	cmdline_fixed_string_t what;
3096 	cmdline_fixed_string_t on;
3097 	cmdline_fixed_string_t port_id;
3098 };
3099 
3100 static void
3101 cmd_vlan_offload_parsed(void *parsed_result,
3102 			  __attribute__((unused)) struct cmdline *cl,
3103 			  __attribute__((unused)) void *data)
3104 {
3105 	int on;
3106 	struct cmd_vlan_offload_result *res = parsed_result;
3107 	char *str;
3108 	int i, len = 0;
3109 	portid_t port_id = 0;
3110 	unsigned int tmp;
3111 
3112 	str = res->port_id;
3113 	len = strnlen(str, STR_TOKEN_SIZE);
3114 	i = 0;
3115 	/* Get port_id first */
3116 	while(i < len){
3117 		if(str[i] == ',')
3118 			break;
3119 
3120 		i++;
3121 	}
3122 	str[i]='\0';
3123 	tmp = strtoul(str, NULL, 0);
3124 	/* If port_id greater that what portid_t can represent, return */
3125 	if(tmp >= RTE_MAX_ETHPORTS)
3126 		return;
3127 	port_id = (portid_t)tmp;
3128 
3129 	if (!strcmp(res->on, "on"))
3130 		on = 1;
3131 	else
3132 		on = 0;
3133 
3134 	if (!strcmp(res->what, "strip"))
3135 		rx_vlan_strip_set(port_id,  on);
3136 	else if(!strcmp(res->what, "stripq")){
3137 		uint16_t queue_id = 0;
3138 
3139 		/* No queue_id, return */
3140 		if(i + 1 >= len) {
3141 			printf("must specify (port,queue_id)\n");
3142 			return;
3143 		}
3144 		tmp = strtoul(str + i + 1, NULL, 0);
3145 		/* If queue_id greater that what 16-bits can represent, return */
3146 		if(tmp > 0xffff)
3147 			return;
3148 
3149 		queue_id = (uint16_t)tmp;
3150 		rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3151 	}
3152 	else if (!strcmp(res->what, "filter"))
3153 		rx_vlan_filter_set(port_id, on);
3154 	else
3155 		vlan_extend_set(port_id, on);
3156 
3157 	return;
3158 }
3159 
3160 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3161 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3162 				 vlan, "vlan");
3163 cmdline_parse_token_string_t cmd_vlan_offload_set =
3164 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3165 				 set, "set");
3166 cmdline_parse_token_string_t cmd_vlan_offload_what =
3167 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3168 				 what, "strip#filter#qinq#stripq");
3169 cmdline_parse_token_string_t cmd_vlan_offload_on =
3170 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3171 			      on, "on#off");
3172 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3173 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3174 			      port_id, NULL);
3175 
3176 cmdline_parse_inst_t cmd_vlan_offload = {
3177 	.f = cmd_vlan_offload_parsed,
3178 	.data = NULL,
3179 	.help_str = "vlan set strip|filter|qinq|stripq on|off "
3180 		"<port_id[,queue_id]>: "
3181 		"Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3182 	.tokens = {
3183 		(void *)&cmd_vlan_offload_vlan,
3184 		(void *)&cmd_vlan_offload_set,
3185 		(void *)&cmd_vlan_offload_what,
3186 		(void *)&cmd_vlan_offload_on,
3187 		(void *)&cmd_vlan_offload_portid,
3188 		NULL,
3189 	},
3190 };
3191 
3192 /* *** VLAN TPID SET ON A PORT *** */
3193 struct cmd_vlan_tpid_result {
3194 	cmdline_fixed_string_t vlan;
3195 	cmdline_fixed_string_t set;
3196 	cmdline_fixed_string_t vlan_type;
3197 	cmdline_fixed_string_t what;
3198 	uint16_t tp_id;
3199 	uint8_t port_id;
3200 };
3201 
3202 static void
3203 cmd_vlan_tpid_parsed(void *parsed_result,
3204 			  __attribute__((unused)) struct cmdline *cl,
3205 			  __attribute__((unused)) void *data)
3206 {
3207 	struct cmd_vlan_tpid_result *res = parsed_result;
3208 	enum rte_vlan_type vlan_type;
3209 
3210 	if (!strcmp(res->vlan_type, "inner"))
3211 		vlan_type = ETH_VLAN_TYPE_INNER;
3212 	else if (!strcmp(res->vlan_type, "outer"))
3213 		vlan_type = ETH_VLAN_TYPE_OUTER;
3214 	else {
3215 		printf("Unknown vlan type\n");
3216 		return;
3217 	}
3218 	vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3219 }
3220 
3221 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3222 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3223 				 vlan, "vlan");
3224 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3225 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3226 				 set, "set");
3227 cmdline_parse_token_string_t cmd_vlan_type =
3228 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3229 				 vlan_type, "inner#outer");
3230 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3231 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3232 				 what, "tpid");
3233 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3234 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3235 			      tp_id, UINT16);
3236 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3237 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3238 			      port_id, UINT8);
3239 
3240 cmdline_parse_inst_t cmd_vlan_tpid = {
3241 	.f = cmd_vlan_tpid_parsed,
3242 	.data = NULL,
3243 	.help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3244 		"Set the VLAN Ether type",
3245 	.tokens = {
3246 		(void *)&cmd_vlan_tpid_vlan,
3247 		(void *)&cmd_vlan_tpid_set,
3248 		(void *)&cmd_vlan_type,
3249 		(void *)&cmd_vlan_tpid_what,
3250 		(void *)&cmd_vlan_tpid_tpid,
3251 		(void *)&cmd_vlan_tpid_portid,
3252 		NULL,
3253 	},
3254 };
3255 
3256 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3257 struct cmd_rx_vlan_filter_result {
3258 	cmdline_fixed_string_t rx_vlan;
3259 	cmdline_fixed_string_t what;
3260 	uint16_t vlan_id;
3261 	uint8_t port_id;
3262 };
3263 
3264 static void
3265 cmd_rx_vlan_filter_parsed(void *parsed_result,
3266 			  __attribute__((unused)) struct cmdline *cl,
3267 			  __attribute__((unused)) void *data)
3268 {
3269 	struct cmd_rx_vlan_filter_result *res = parsed_result;
3270 
3271 	if (!strcmp(res->what, "add"))
3272 		rx_vft_set(res->port_id, res->vlan_id, 1);
3273 	else
3274 		rx_vft_set(res->port_id, res->vlan_id, 0);
3275 }
3276 
3277 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3278 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3279 				 rx_vlan, "rx_vlan");
3280 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3281 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3282 				 what, "add#rm");
3283 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3284 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3285 			      vlan_id, UINT16);
3286 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3287 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3288 			      port_id, UINT8);
3289 
3290 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3291 	.f = cmd_rx_vlan_filter_parsed,
3292 	.data = NULL,
3293 	.help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3294 		"Add/Remove a VLAN identifier to/from the set of VLAN "
3295 		"identifiers filtered by a port",
3296 	.tokens = {
3297 		(void *)&cmd_rx_vlan_filter_rx_vlan,
3298 		(void *)&cmd_rx_vlan_filter_what,
3299 		(void *)&cmd_rx_vlan_filter_vlanid,
3300 		(void *)&cmd_rx_vlan_filter_portid,
3301 		NULL,
3302 	},
3303 };
3304 
3305 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3306 struct cmd_tx_vlan_set_result {
3307 	cmdline_fixed_string_t tx_vlan;
3308 	cmdline_fixed_string_t set;
3309 	uint8_t port_id;
3310 	uint16_t vlan_id;
3311 };
3312 
3313 static void
3314 cmd_tx_vlan_set_parsed(void *parsed_result,
3315 		       __attribute__((unused)) struct cmdline *cl,
3316 		       __attribute__((unused)) void *data)
3317 {
3318 	struct cmd_tx_vlan_set_result *res = parsed_result;
3319 
3320 	tx_vlan_set(res->port_id, res->vlan_id);
3321 }
3322 
3323 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3324 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3325 				 tx_vlan, "tx_vlan");
3326 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3327 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3328 				 set, "set");
3329 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3330 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3331 			      port_id, UINT8);
3332 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3333 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3334 			      vlan_id, UINT16);
3335 
3336 cmdline_parse_inst_t cmd_tx_vlan_set = {
3337 	.f = cmd_tx_vlan_set_parsed,
3338 	.data = NULL,
3339 	.help_str = "tx_vlan set <port_id> <vlan_id>: "
3340 		"Enable hardware insertion of a single VLAN header "
3341 		"with a given TAG Identifier in packets sent on a port",
3342 	.tokens = {
3343 		(void *)&cmd_tx_vlan_set_tx_vlan,
3344 		(void *)&cmd_tx_vlan_set_set,
3345 		(void *)&cmd_tx_vlan_set_portid,
3346 		(void *)&cmd_tx_vlan_set_vlanid,
3347 		NULL,
3348 	},
3349 };
3350 
3351 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3352 struct cmd_tx_vlan_set_qinq_result {
3353 	cmdline_fixed_string_t tx_vlan;
3354 	cmdline_fixed_string_t set;
3355 	uint8_t port_id;
3356 	uint16_t vlan_id;
3357 	uint16_t vlan_id_outer;
3358 };
3359 
3360 static void
3361 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3362 			    __attribute__((unused)) struct cmdline *cl,
3363 			    __attribute__((unused)) void *data)
3364 {
3365 	struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3366 
3367 	tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3368 }
3369 
3370 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3371 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3372 		tx_vlan, "tx_vlan");
3373 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3374 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3375 		set, "set");
3376 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3377 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3378 		port_id, UINT8);
3379 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3380 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3381 		vlan_id, UINT16);
3382 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3383 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3384 		vlan_id_outer, UINT16);
3385 
3386 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3387 	.f = cmd_tx_vlan_set_qinq_parsed,
3388 	.data = NULL,
3389 	.help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3390 		"Enable hardware insertion of double VLAN header "
3391 		"with given TAG Identifiers in packets sent on a port",
3392 	.tokens = {
3393 		(void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3394 		(void *)&cmd_tx_vlan_set_qinq_set,
3395 		(void *)&cmd_tx_vlan_set_qinq_portid,
3396 		(void *)&cmd_tx_vlan_set_qinq_vlanid,
3397 		(void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3398 		NULL,
3399 	},
3400 };
3401 
3402 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3403 struct cmd_tx_vlan_set_pvid_result {
3404 	cmdline_fixed_string_t tx_vlan;
3405 	cmdline_fixed_string_t set;
3406 	cmdline_fixed_string_t pvid;
3407 	uint8_t port_id;
3408 	uint16_t vlan_id;
3409 	cmdline_fixed_string_t mode;
3410 };
3411 
3412 static void
3413 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3414 			    __attribute__((unused)) struct cmdline *cl,
3415 			    __attribute__((unused)) void *data)
3416 {
3417 	struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3418 
3419 	if (strcmp(res->mode, "on") == 0)
3420 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3421 	else
3422 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3423 }
3424 
3425 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3426 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3427 				 tx_vlan, "tx_vlan");
3428 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3429 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3430 				 set, "set");
3431 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3432 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3433 				 pvid, "pvid");
3434 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3435 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3436 			     port_id, UINT8);
3437 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3438 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3439 			      vlan_id, UINT16);
3440 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3441 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3442 				 mode, "on#off");
3443 
3444 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3445 	.f = cmd_tx_vlan_set_pvid_parsed,
3446 	.data = NULL,
3447 	.help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3448 	.tokens = {
3449 		(void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3450 		(void *)&cmd_tx_vlan_set_pvid_set,
3451 		(void *)&cmd_tx_vlan_set_pvid_pvid,
3452 		(void *)&cmd_tx_vlan_set_pvid_port_id,
3453 		(void *)&cmd_tx_vlan_set_pvid_vlan_id,
3454 		(void *)&cmd_tx_vlan_set_pvid_mode,
3455 		NULL,
3456 	},
3457 };
3458 
3459 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3460 struct cmd_tx_vlan_reset_result {
3461 	cmdline_fixed_string_t tx_vlan;
3462 	cmdline_fixed_string_t reset;
3463 	uint8_t port_id;
3464 };
3465 
3466 static void
3467 cmd_tx_vlan_reset_parsed(void *parsed_result,
3468 			 __attribute__((unused)) struct cmdline *cl,
3469 			 __attribute__((unused)) void *data)
3470 {
3471 	struct cmd_tx_vlan_reset_result *res = parsed_result;
3472 
3473 	tx_vlan_reset(res->port_id);
3474 }
3475 
3476 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3477 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3478 				 tx_vlan, "tx_vlan");
3479 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3480 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3481 				 reset, "reset");
3482 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3483 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3484 			      port_id, UINT8);
3485 
3486 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3487 	.f = cmd_tx_vlan_reset_parsed,
3488 	.data = NULL,
3489 	.help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3490 		"VLAN header in packets sent on a port",
3491 	.tokens = {
3492 		(void *)&cmd_tx_vlan_reset_tx_vlan,
3493 		(void *)&cmd_tx_vlan_reset_reset,
3494 		(void *)&cmd_tx_vlan_reset_portid,
3495 		NULL,
3496 	},
3497 };
3498 
3499 
3500 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3501 struct cmd_csum_result {
3502 	cmdline_fixed_string_t csum;
3503 	cmdline_fixed_string_t mode;
3504 	cmdline_fixed_string_t proto;
3505 	cmdline_fixed_string_t hwsw;
3506 	uint8_t port_id;
3507 };
3508 
3509 static void
3510 csum_show(int port_id)
3511 {
3512 	struct rte_eth_dev_info dev_info;
3513 	uint16_t ol_flags;
3514 
3515 	ol_flags = ports[port_id].tx_ol_flags;
3516 	printf("Parse tunnel is %s\n",
3517 		(ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3518 	printf("IP checksum offload is %s\n",
3519 		(ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3520 	printf("UDP checksum offload is %s\n",
3521 		(ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3522 	printf("TCP checksum offload is %s\n",
3523 		(ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3524 	printf("SCTP checksum offload is %s\n",
3525 		(ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3526 	printf("Outer-Ip checksum offload is %s\n",
3527 		(ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3528 
3529 	/* display warnings if configuration is not supported by the NIC */
3530 	rte_eth_dev_info_get(port_id, &dev_info);
3531 	if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3532 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3533 		printf("Warning: hardware IP checksum enabled but not "
3534 			"supported by port %d\n", port_id);
3535 	}
3536 	if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3537 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3538 		printf("Warning: hardware UDP checksum enabled but not "
3539 			"supported by port %d\n", port_id);
3540 	}
3541 	if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3542 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3543 		printf("Warning: hardware TCP checksum enabled but not "
3544 			"supported by port %d\n", port_id);
3545 	}
3546 	if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3547 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3548 		printf("Warning: hardware SCTP checksum enabled but not "
3549 			"supported by port %d\n", port_id);
3550 	}
3551 	if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3552 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3553 		printf("Warning: hardware outer IP checksum enabled but not "
3554 			"supported by port %d\n", port_id);
3555 	}
3556 }
3557 
3558 static void
3559 cmd_csum_parsed(void *parsed_result,
3560 		       __attribute__((unused)) struct cmdline *cl,
3561 		       __attribute__((unused)) void *data)
3562 {
3563 	struct cmd_csum_result *res = parsed_result;
3564 	int hw = 0;
3565 	uint16_t mask = 0;
3566 
3567 	if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3568 		printf("invalid port %d\n", res->port_id);
3569 		return;
3570 	}
3571 
3572 	if (!strcmp(res->mode, "set")) {
3573 
3574 		if (!strcmp(res->hwsw, "hw"))
3575 			hw = 1;
3576 
3577 		if (!strcmp(res->proto, "ip")) {
3578 			mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3579 		} else if (!strcmp(res->proto, "udp")) {
3580 			mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3581 		} else if (!strcmp(res->proto, "tcp")) {
3582 			mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3583 		} else if (!strcmp(res->proto, "sctp")) {
3584 			mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3585 		} else if (!strcmp(res->proto, "outer-ip")) {
3586 			mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3587 		}
3588 
3589 		if (hw)
3590 			ports[res->port_id].tx_ol_flags |= mask;
3591 		else
3592 			ports[res->port_id].tx_ol_flags &= (~mask);
3593 	}
3594 	csum_show(res->port_id);
3595 }
3596 
3597 cmdline_parse_token_string_t cmd_csum_csum =
3598 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3599 				csum, "csum");
3600 cmdline_parse_token_string_t cmd_csum_mode =
3601 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3602 				mode, "set");
3603 cmdline_parse_token_string_t cmd_csum_proto =
3604 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3605 				proto, "ip#tcp#udp#sctp#outer-ip");
3606 cmdline_parse_token_string_t cmd_csum_hwsw =
3607 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3608 				hwsw, "hw#sw");
3609 cmdline_parse_token_num_t cmd_csum_portid =
3610 	TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3611 				port_id, UINT8);
3612 
3613 cmdline_parse_inst_t cmd_csum_set = {
3614 	.f = cmd_csum_parsed,
3615 	.data = NULL,
3616 	.help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3617 		"Enable/Disable hardware calculation of L3/L4 checksum when "
3618 		"using csum forward engine",
3619 	.tokens = {
3620 		(void *)&cmd_csum_csum,
3621 		(void *)&cmd_csum_mode,
3622 		(void *)&cmd_csum_proto,
3623 		(void *)&cmd_csum_hwsw,
3624 		(void *)&cmd_csum_portid,
3625 		NULL,
3626 	},
3627 };
3628 
3629 cmdline_parse_token_string_t cmd_csum_mode_show =
3630 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3631 				mode, "show");
3632 
3633 cmdline_parse_inst_t cmd_csum_show = {
3634 	.f = cmd_csum_parsed,
3635 	.data = NULL,
3636 	.help_str = "csum show <port_id>: Show checksum offload configuration",
3637 	.tokens = {
3638 		(void *)&cmd_csum_csum,
3639 		(void *)&cmd_csum_mode_show,
3640 		(void *)&cmd_csum_portid,
3641 		NULL,
3642 	},
3643 };
3644 
3645 /* Enable/disable tunnel parsing */
3646 struct cmd_csum_tunnel_result {
3647 	cmdline_fixed_string_t csum;
3648 	cmdline_fixed_string_t parse;
3649 	cmdline_fixed_string_t onoff;
3650 	uint8_t port_id;
3651 };
3652 
3653 static void
3654 cmd_csum_tunnel_parsed(void *parsed_result,
3655 		       __attribute__((unused)) struct cmdline *cl,
3656 		       __attribute__((unused)) void *data)
3657 {
3658 	struct cmd_csum_tunnel_result *res = parsed_result;
3659 
3660 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3661 		return;
3662 
3663 	if (!strcmp(res->onoff, "on"))
3664 		ports[res->port_id].tx_ol_flags |=
3665 			TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3666 	else
3667 		ports[res->port_id].tx_ol_flags &=
3668 			(~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3669 
3670 	csum_show(res->port_id);
3671 }
3672 
3673 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3674 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3675 				csum, "csum");
3676 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3677 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3678 				parse, "parse_tunnel");
3679 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3680 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3681 				onoff, "on#off");
3682 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3683 	TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3684 				port_id, UINT8);
3685 
3686 cmdline_parse_inst_t cmd_csum_tunnel = {
3687 	.f = cmd_csum_tunnel_parsed,
3688 	.data = NULL,
3689 	.help_str = "csum parse_tunnel on|off <port_id>: "
3690 		"Enable/Disable parsing of tunnels for csum engine",
3691 	.tokens = {
3692 		(void *)&cmd_csum_tunnel_csum,
3693 		(void *)&cmd_csum_tunnel_parse,
3694 		(void *)&cmd_csum_tunnel_onoff,
3695 		(void *)&cmd_csum_tunnel_portid,
3696 		NULL,
3697 	},
3698 };
3699 
3700 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3701 struct cmd_tso_set_result {
3702 	cmdline_fixed_string_t tso;
3703 	cmdline_fixed_string_t mode;
3704 	uint16_t tso_segsz;
3705 	uint8_t port_id;
3706 };
3707 
3708 static void
3709 cmd_tso_set_parsed(void *parsed_result,
3710 		       __attribute__((unused)) struct cmdline *cl,
3711 		       __attribute__((unused)) void *data)
3712 {
3713 	struct cmd_tso_set_result *res = parsed_result;
3714 	struct rte_eth_dev_info dev_info;
3715 
3716 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3717 		return;
3718 
3719 	if (!strcmp(res->mode, "set"))
3720 		ports[res->port_id].tso_segsz = res->tso_segsz;
3721 
3722 	if (ports[res->port_id].tso_segsz == 0)
3723 		printf("TSO for non-tunneled packets is disabled\n");
3724 	else
3725 		printf("TSO segment size for non-tunneled packets is %d\n",
3726 			ports[res->port_id].tso_segsz);
3727 
3728 	/* display warnings if configuration is not supported by the NIC */
3729 	rte_eth_dev_info_get(res->port_id, &dev_info);
3730 	if ((ports[res->port_id].tso_segsz != 0) &&
3731 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3732 		printf("Warning: TSO enabled but not "
3733 			"supported by port %d\n", res->port_id);
3734 	}
3735 }
3736 
3737 cmdline_parse_token_string_t cmd_tso_set_tso =
3738 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3739 				tso, "tso");
3740 cmdline_parse_token_string_t cmd_tso_set_mode =
3741 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3742 				mode, "set");
3743 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3744 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3745 				tso_segsz, UINT16);
3746 cmdline_parse_token_num_t cmd_tso_set_portid =
3747 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3748 				port_id, UINT8);
3749 
3750 cmdline_parse_inst_t cmd_tso_set = {
3751 	.f = cmd_tso_set_parsed,
3752 	.data = NULL,
3753 	.help_str = "tso set <tso_segsz> <port_id>: "
3754 		"Set TSO segment size of non-tunneled packets for csum engine "
3755 		"(0 to disable)",
3756 	.tokens = {
3757 		(void *)&cmd_tso_set_tso,
3758 		(void *)&cmd_tso_set_mode,
3759 		(void *)&cmd_tso_set_tso_segsz,
3760 		(void *)&cmd_tso_set_portid,
3761 		NULL,
3762 	},
3763 };
3764 
3765 cmdline_parse_token_string_t cmd_tso_show_mode =
3766 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3767 				mode, "show");
3768 
3769 
3770 cmdline_parse_inst_t cmd_tso_show = {
3771 	.f = cmd_tso_set_parsed,
3772 	.data = NULL,
3773 	.help_str = "tso show <port_id>: "
3774 		"Show TSO segment size of non-tunneled packets for csum engine",
3775 	.tokens = {
3776 		(void *)&cmd_tso_set_tso,
3777 		(void *)&cmd_tso_show_mode,
3778 		(void *)&cmd_tso_set_portid,
3779 		NULL,
3780 	},
3781 };
3782 
3783 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3784 struct cmd_tunnel_tso_set_result {
3785 	cmdline_fixed_string_t tso;
3786 	cmdline_fixed_string_t mode;
3787 	uint16_t tso_segsz;
3788 	uint8_t port_id;
3789 };
3790 
3791 static void
3792 check_tunnel_tso_nic_support(uint8_t port_id)
3793 {
3794 	struct rte_eth_dev_info dev_info;
3795 
3796 	rte_eth_dev_info_get(port_id, &dev_info);
3797 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3798 		printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3799 		       "supported by port %d\n", port_id);
3800 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3801 		printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3802 			"supported by port %d\n", port_id);
3803 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3804 		printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3805 		       "supported by port %d\n", port_id);
3806 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3807 		printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3808 		       "supported by port %d\n", port_id);
3809 }
3810 
3811 static void
3812 cmd_tunnel_tso_set_parsed(void *parsed_result,
3813 			  __attribute__((unused)) struct cmdline *cl,
3814 			  __attribute__((unused)) void *data)
3815 {
3816 	struct cmd_tunnel_tso_set_result *res = parsed_result;
3817 
3818 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3819 		return;
3820 
3821 	if (!strcmp(res->mode, "set"))
3822 		ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3823 
3824 	if (ports[res->port_id].tunnel_tso_segsz == 0)
3825 		printf("TSO for tunneled packets is disabled\n");
3826 	else {
3827 		printf("TSO segment size for tunneled packets is %d\n",
3828 			ports[res->port_id].tunnel_tso_segsz);
3829 
3830 		/* Below conditions are needed to make it work:
3831 		 * (1) tunnel TSO is supported by the NIC;
3832 		 * (2) "csum parse_tunnel" must be set so that tunneled pkts
3833 		 * are recognized;
3834 		 * (3) for tunneled pkts with outer L3 of IPv4,
3835 		 * "csum set outer-ip" must be set to hw, because after tso,
3836 		 * total_len of outer IP header is changed, and the checksum
3837 		 * of outer IP header calculated by sw should be wrong; that
3838 		 * is not necessary for IPv6 tunneled pkts because there's no
3839 		 * checksum in IP header anymore.
3840 		 */
3841 		check_tunnel_tso_nic_support(res->port_id);
3842 
3843 		if (!(ports[res->port_id].tx_ol_flags &
3844 		      TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3845 			printf("Warning: csum parse_tunnel must be set "
3846 				"so that tunneled packets are recognized\n");
3847 		if (!(ports[res->port_id].tx_ol_flags &
3848 		      TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3849 			printf("Warning: csum set outer-ip must be set to hw "
3850 				"if outer L3 is IPv4; not necessary for IPv6\n");
3851 	}
3852 }
3853 
3854 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3855 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3856 				tso, "tunnel_tso");
3857 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3858 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3859 				mode, "set");
3860 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3861 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3862 				tso_segsz, UINT16);
3863 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3864 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3865 				port_id, UINT8);
3866 
3867 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3868 	.f = cmd_tunnel_tso_set_parsed,
3869 	.data = NULL,
3870 	.help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3871 		"Set TSO segment size of tunneled packets for csum engine "
3872 		"(0 to disable)",
3873 	.tokens = {
3874 		(void *)&cmd_tunnel_tso_set_tso,
3875 		(void *)&cmd_tunnel_tso_set_mode,
3876 		(void *)&cmd_tunnel_tso_set_tso_segsz,
3877 		(void *)&cmd_tunnel_tso_set_portid,
3878 		NULL,
3879 	},
3880 };
3881 
3882 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3883 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3884 				mode, "show");
3885 
3886 
3887 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3888 	.f = cmd_tunnel_tso_set_parsed,
3889 	.data = NULL,
3890 	.help_str = "tunnel_tso show <port_id> "
3891 		"Show TSO segment size of tunneled packets for csum engine",
3892 	.tokens = {
3893 		(void *)&cmd_tunnel_tso_set_tso,
3894 		(void *)&cmd_tunnel_tso_show_mode,
3895 		(void *)&cmd_tunnel_tso_set_portid,
3896 		NULL,
3897 	},
3898 };
3899 
3900 /* *** SET GRO FOR A PORT *** */
3901 struct cmd_gro_enable_result {
3902 	cmdline_fixed_string_t cmd_set;
3903 	cmdline_fixed_string_t cmd_port;
3904 	cmdline_fixed_string_t cmd_keyword;
3905 	cmdline_fixed_string_t cmd_onoff;
3906 	portid_t cmd_pid;
3907 };
3908 
3909 static void
3910 cmd_gro_enable_parsed(void *parsed_result,
3911 		__attribute__((unused)) struct cmdline *cl,
3912 		__attribute__((unused)) void *data)
3913 {
3914 	struct cmd_gro_enable_result *res;
3915 
3916 	res = parsed_result;
3917 	if (!strcmp(res->cmd_keyword, "gro"))
3918 		setup_gro(res->cmd_onoff, res->cmd_pid);
3919 }
3920 
3921 cmdline_parse_token_string_t cmd_gro_enable_set =
3922 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3923 			cmd_set, "set");
3924 cmdline_parse_token_string_t cmd_gro_enable_port =
3925 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3926 			cmd_keyword, "port");
3927 cmdline_parse_token_num_t cmd_gro_enable_pid =
3928 	TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
3929 			cmd_pid, UINT16);
3930 cmdline_parse_token_string_t cmd_gro_enable_keyword =
3931 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3932 			cmd_keyword, "gro");
3933 cmdline_parse_token_string_t cmd_gro_enable_onoff =
3934 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3935 			cmd_onoff, "on#off");
3936 
3937 cmdline_parse_inst_t cmd_gro_enable = {
3938 	.f = cmd_gro_enable_parsed,
3939 	.data = NULL,
3940 	.help_str = "set port <port_id> gro on|off",
3941 	.tokens = {
3942 		(void *)&cmd_gro_enable_set,
3943 		(void *)&cmd_gro_enable_port,
3944 		(void *)&cmd_gro_enable_pid,
3945 		(void *)&cmd_gro_enable_keyword,
3946 		(void *)&cmd_gro_enable_onoff,
3947 		NULL,
3948 	},
3949 };
3950 
3951 /* *** DISPLAY GRO CONFIGURATION *** */
3952 struct cmd_gro_show_result {
3953 	cmdline_fixed_string_t cmd_show;
3954 	cmdline_fixed_string_t cmd_port;
3955 	cmdline_fixed_string_t cmd_keyword;
3956 	portid_t cmd_pid;
3957 };
3958 
3959 static void
3960 cmd_gro_show_parsed(void *parsed_result,
3961 		__attribute__((unused)) struct cmdline *cl,
3962 		__attribute__((unused)) void *data)
3963 {
3964 	struct cmd_gro_show_result *res;
3965 
3966 	res = parsed_result;
3967 	if (!strcmp(res->cmd_keyword, "gro"))
3968 		show_gro(res->cmd_pid);
3969 }
3970 
3971 cmdline_parse_token_string_t cmd_gro_show_show =
3972 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3973 			cmd_show, "show");
3974 cmdline_parse_token_string_t cmd_gro_show_port =
3975 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3976 			cmd_port, "port");
3977 cmdline_parse_token_num_t cmd_gro_show_pid =
3978 	TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
3979 			cmd_pid, UINT16);
3980 cmdline_parse_token_string_t cmd_gro_show_keyword =
3981 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3982 			cmd_keyword, "gro");
3983 
3984 cmdline_parse_inst_t cmd_gro_show = {
3985 	.f = cmd_gro_show_parsed,
3986 	.data = NULL,
3987 	.help_str = "show port <port_id> gro",
3988 	.tokens = {
3989 		(void *)&cmd_gro_show_show,
3990 		(void *)&cmd_gro_show_port,
3991 		(void *)&cmd_gro_show_pid,
3992 		(void *)&cmd_gro_show_keyword,
3993 		NULL,
3994 	},
3995 };
3996 
3997 /* *** SET FLUSH CYCLES FOR GRO *** */
3998 struct cmd_gro_flush_result {
3999 	cmdline_fixed_string_t cmd_set;
4000 	cmdline_fixed_string_t cmd_keyword;
4001 	cmdline_fixed_string_t cmd_flush;
4002 	uint8_t cmd_cycles;
4003 };
4004 
4005 static void
4006 cmd_gro_flush_parsed(void *parsed_result,
4007 		__attribute__((unused)) struct cmdline *cl,
4008 		__attribute__((unused)) void *data)
4009 {
4010 	struct cmd_gro_flush_result *res;
4011 
4012 	res = parsed_result;
4013 	if ((!strcmp(res->cmd_keyword, "gro")) &&
4014 			(!strcmp(res->cmd_flush, "flush")))
4015 		setup_gro_flush_cycles(res->cmd_cycles);
4016 }
4017 
4018 cmdline_parse_token_string_t cmd_gro_flush_set =
4019 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4020 			cmd_set, "set");
4021 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4022 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4023 			cmd_keyword, "gro");
4024 cmdline_parse_token_string_t cmd_gro_flush_flush =
4025 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4026 			cmd_flush, "flush");
4027 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4028 	TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4029 			cmd_cycles, UINT8);
4030 
4031 cmdline_parse_inst_t cmd_gro_flush = {
4032 	.f = cmd_gro_flush_parsed,
4033 	.data = NULL,
4034 	.help_str = "set gro flush <cycles>",
4035 	.tokens = {
4036 		(void *)&cmd_gro_flush_set,
4037 		(void *)&cmd_gro_flush_keyword,
4038 		(void *)&cmd_gro_flush_flush,
4039 		(void *)&cmd_gro_flush_cycles,
4040 		NULL,
4041 	},
4042 };
4043 
4044 /* *** ENABLE/DISABLE GSO *** */
4045 struct cmd_gso_enable_result {
4046 	cmdline_fixed_string_t cmd_set;
4047 	cmdline_fixed_string_t cmd_port;
4048 	cmdline_fixed_string_t cmd_keyword;
4049 	cmdline_fixed_string_t cmd_mode;
4050 	portid_t cmd_pid;
4051 };
4052 
4053 static void
4054 cmd_gso_enable_parsed(void *parsed_result,
4055 		__attribute__((unused)) struct cmdline *cl,
4056 		__attribute__((unused)) void *data)
4057 {
4058 	struct cmd_gso_enable_result *res;
4059 
4060 	res = parsed_result;
4061 	if (!strcmp(res->cmd_keyword, "gso"))
4062 		setup_gso(res->cmd_mode, res->cmd_pid);
4063 }
4064 
4065 cmdline_parse_token_string_t cmd_gso_enable_set =
4066 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4067 			cmd_set, "set");
4068 cmdline_parse_token_string_t cmd_gso_enable_port =
4069 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4070 			cmd_port, "port");
4071 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4072 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4073 			cmd_keyword, "gso");
4074 cmdline_parse_token_string_t cmd_gso_enable_mode =
4075 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4076 			cmd_mode, "on#off");
4077 cmdline_parse_token_num_t cmd_gso_enable_pid =
4078 	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4079 			cmd_pid, UINT16);
4080 
4081 cmdline_parse_inst_t cmd_gso_enable = {
4082 	.f = cmd_gso_enable_parsed,
4083 	.data = NULL,
4084 	.help_str = "set port <port_id> gso on|off",
4085 	.tokens = {
4086 		(void *)&cmd_gso_enable_set,
4087 		(void *)&cmd_gso_enable_port,
4088 		(void *)&cmd_gso_enable_pid,
4089 		(void *)&cmd_gso_enable_keyword,
4090 		(void *)&cmd_gso_enable_mode,
4091 		NULL,
4092 	},
4093 };
4094 
4095 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4096 struct cmd_gso_size_result {
4097 	cmdline_fixed_string_t cmd_set;
4098 	cmdline_fixed_string_t cmd_keyword;
4099 	cmdline_fixed_string_t cmd_segsz;
4100 	uint16_t cmd_size;
4101 };
4102 
4103 static void
4104 cmd_gso_size_parsed(void *parsed_result,
4105 		       __attribute__((unused)) struct cmdline *cl,
4106 		       __attribute__((unused)) void *data)
4107 {
4108 	struct cmd_gso_size_result *res = parsed_result;
4109 
4110 	if (test_done == 0) {
4111 		printf("Before setting GSO segsz, please first"
4112 				" stop fowarding\n");
4113 		return;
4114 	}
4115 
4116 	if (!strcmp(res->cmd_keyword, "gso") &&
4117 			!strcmp(res->cmd_segsz, "segsz")) {
4118 		if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4119 			printf("gso_size should be larger than %zu."
4120 					" Please input a legal value\n",
4121 					RTE_GSO_SEG_SIZE_MIN);
4122 		else
4123 			gso_max_segment_size = res->cmd_size;
4124 	}
4125 }
4126 
4127 cmdline_parse_token_string_t cmd_gso_size_set =
4128 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4129 				cmd_set, "set");
4130 cmdline_parse_token_string_t cmd_gso_size_keyword =
4131 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4132 				cmd_keyword, "gso");
4133 cmdline_parse_token_string_t cmd_gso_size_segsz =
4134 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4135 				cmd_segsz, "segsz");
4136 cmdline_parse_token_num_t cmd_gso_size_size =
4137 	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4138 				cmd_size, UINT16);
4139 
4140 cmdline_parse_inst_t cmd_gso_size = {
4141 	.f = cmd_gso_size_parsed,
4142 	.data = NULL,
4143 	.help_str = "set gso segsz <length>",
4144 	.tokens = {
4145 		(void *)&cmd_gso_size_set,
4146 		(void *)&cmd_gso_size_keyword,
4147 		(void *)&cmd_gso_size_segsz,
4148 		(void *)&cmd_gso_size_size,
4149 		NULL,
4150 	},
4151 };
4152 
4153 /* *** SHOW GSO CONFIGURATION *** */
4154 struct cmd_gso_show_result {
4155 	cmdline_fixed_string_t cmd_show;
4156 	cmdline_fixed_string_t cmd_port;
4157 	cmdline_fixed_string_t cmd_keyword;
4158 	portid_t cmd_pid;
4159 };
4160 
4161 static void
4162 cmd_gso_show_parsed(void *parsed_result,
4163 		       __attribute__((unused)) struct cmdline *cl,
4164 		       __attribute__((unused)) void *data)
4165 {
4166 	struct cmd_gso_show_result *res = parsed_result;
4167 
4168 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4169 		printf("invalid port id %u\n", res->cmd_pid);
4170 		return;
4171 	}
4172 	if (!strcmp(res->cmd_keyword, "gso")) {
4173 		if (gso_ports[res->cmd_pid].enable) {
4174 			printf("Max GSO'd packet size: %uB\n"
4175 					"Supported GSO types: TCP/IPv4, "
4176 					"VxLAN with inner TCP/IPv4 packet, "
4177 					"GRE with inner TCP/IPv4  packet\n",
4178 					gso_max_segment_size);
4179 		} else
4180 			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4181 	}
4182 }
4183 
4184 cmdline_parse_token_string_t cmd_gso_show_show =
4185 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4186 		cmd_show, "show");
4187 cmdline_parse_token_string_t cmd_gso_show_port =
4188 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4189 		cmd_port, "port");
4190 cmdline_parse_token_string_t cmd_gso_show_keyword =
4191 	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4192 				cmd_keyword, "gso");
4193 cmdline_parse_token_num_t cmd_gso_show_pid =
4194 	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4195 				cmd_pid, UINT16);
4196 
4197 cmdline_parse_inst_t cmd_gso_show = {
4198 	.f = cmd_gso_show_parsed,
4199 	.data = NULL,
4200 	.help_str = "show port <port_id> gso",
4201 	.tokens = {
4202 		(void *)&cmd_gso_show_show,
4203 		(void *)&cmd_gso_show_port,
4204 		(void *)&cmd_gso_show_pid,
4205 		(void *)&cmd_gso_show_keyword,
4206 		NULL,
4207 	},
4208 };
4209 
4210 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4211 struct cmd_set_flush_rx {
4212 	cmdline_fixed_string_t set;
4213 	cmdline_fixed_string_t flush_rx;
4214 	cmdline_fixed_string_t mode;
4215 };
4216 
4217 static void
4218 cmd_set_flush_rx_parsed(void *parsed_result,
4219 		__attribute__((unused)) struct cmdline *cl,
4220 		__attribute__((unused)) void *data)
4221 {
4222 	struct cmd_set_flush_rx *res = parsed_result;
4223 	no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4224 }
4225 
4226 cmdline_parse_token_string_t cmd_setflushrx_set =
4227 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4228 			set, "set");
4229 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4230 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4231 			flush_rx, "flush_rx");
4232 cmdline_parse_token_string_t cmd_setflushrx_mode =
4233 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4234 			mode, "on#off");
4235 
4236 
4237 cmdline_parse_inst_t cmd_set_flush_rx = {
4238 	.f = cmd_set_flush_rx_parsed,
4239 	.help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4240 	.data = NULL,
4241 	.tokens = {
4242 		(void *)&cmd_setflushrx_set,
4243 		(void *)&cmd_setflushrx_flush_rx,
4244 		(void *)&cmd_setflushrx_mode,
4245 		NULL,
4246 	},
4247 };
4248 
4249 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4250 struct cmd_set_link_check {
4251 	cmdline_fixed_string_t set;
4252 	cmdline_fixed_string_t link_check;
4253 	cmdline_fixed_string_t mode;
4254 };
4255 
4256 static void
4257 cmd_set_link_check_parsed(void *parsed_result,
4258 		__attribute__((unused)) struct cmdline *cl,
4259 		__attribute__((unused)) void *data)
4260 {
4261 	struct cmd_set_link_check *res = parsed_result;
4262 	no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4263 }
4264 
4265 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4266 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4267 			set, "set");
4268 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4269 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4270 			link_check, "link_check");
4271 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4272 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4273 			mode, "on#off");
4274 
4275 
4276 cmdline_parse_inst_t cmd_set_link_check = {
4277 	.f = cmd_set_link_check_parsed,
4278 	.help_str = "set link_check on|off: Enable/Disable link status check "
4279 	            "when starting/stopping a port",
4280 	.data = NULL,
4281 	.tokens = {
4282 		(void *)&cmd_setlinkcheck_set,
4283 		(void *)&cmd_setlinkcheck_link_check,
4284 		(void *)&cmd_setlinkcheck_mode,
4285 		NULL,
4286 	},
4287 };
4288 
4289 /* *** SET NIC BYPASS MODE *** */
4290 struct cmd_set_bypass_mode_result {
4291 	cmdline_fixed_string_t set;
4292 	cmdline_fixed_string_t bypass;
4293 	cmdline_fixed_string_t mode;
4294 	cmdline_fixed_string_t value;
4295 	uint8_t port_id;
4296 };
4297 
4298 static void
4299 cmd_set_bypass_mode_parsed(void *parsed_result,
4300 		__attribute__((unused)) struct cmdline *cl,
4301 		__attribute__((unused)) void *data)
4302 {
4303 	struct cmd_set_bypass_mode_result *res = parsed_result;
4304 	portid_t port_id = res->port_id;
4305 	int32_t rc = -EINVAL;
4306 
4307 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4308 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4309 
4310 	if (!strcmp(res->value, "bypass"))
4311 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4312 	else if (!strcmp(res->value, "isolate"))
4313 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4314 	else
4315 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4316 
4317 	/* Set the bypass mode for the relevant port. */
4318 	rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4319 #endif
4320 	if (rc != 0)
4321 		printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4322 }
4323 
4324 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4325 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4326 			set, "set");
4327 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4328 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4329 			bypass, "bypass");
4330 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4331 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4332 			mode, "mode");
4333 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4334 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4335 			value, "normal#bypass#isolate");
4336 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4337 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4338 				port_id, UINT8);
4339 
4340 cmdline_parse_inst_t cmd_set_bypass_mode = {
4341 	.f = cmd_set_bypass_mode_parsed,
4342 	.help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4343 	            "Set the NIC bypass mode for port_id",
4344 	.data = NULL,
4345 	.tokens = {
4346 		(void *)&cmd_setbypass_mode_set,
4347 		(void *)&cmd_setbypass_mode_bypass,
4348 		(void *)&cmd_setbypass_mode_mode,
4349 		(void *)&cmd_setbypass_mode_value,
4350 		(void *)&cmd_setbypass_mode_port,
4351 		NULL,
4352 	},
4353 };
4354 
4355 /* *** SET NIC BYPASS EVENT *** */
4356 struct cmd_set_bypass_event_result {
4357 	cmdline_fixed_string_t set;
4358 	cmdline_fixed_string_t bypass;
4359 	cmdline_fixed_string_t event;
4360 	cmdline_fixed_string_t event_value;
4361 	cmdline_fixed_string_t mode;
4362 	cmdline_fixed_string_t mode_value;
4363 	uint8_t port_id;
4364 };
4365 
4366 static void
4367 cmd_set_bypass_event_parsed(void *parsed_result,
4368 		__attribute__((unused)) struct cmdline *cl,
4369 		__attribute__((unused)) void *data)
4370 {
4371 	int32_t rc = -EINVAL;
4372 	struct cmd_set_bypass_event_result *res = parsed_result;
4373 	portid_t port_id = res->port_id;
4374 
4375 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4376 	uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4377 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4378 
4379 	if (!strcmp(res->event_value, "timeout"))
4380 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4381 	else if (!strcmp(res->event_value, "os_on"))
4382 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4383 	else if (!strcmp(res->event_value, "os_off"))
4384 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4385 	else if (!strcmp(res->event_value, "power_on"))
4386 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4387 	else if (!strcmp(res->event_value, "power_off"))
4388 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4389 	else
4390 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4391 
4392 	if (!strcmp(res->mode_value, "bypass"))
4393 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4394 	else if (!strcmp(res->mode_value, "isolate"))
4395 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4396 	else
4397 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4398 
4399 	/* Set the watchdog timeout. */
4400 	if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4401 
4402 		rc = -EINVAL;
4403 		if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4404 			rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4405 							   bypass_timeout);
4406 		}
4407 		if (rc != 0) {
4408 			printf("Failed to set timeout value %u "
4409 			"for port %d, errto code: %d.\n",
4410 			bypass_timeout, port_id, rc);
4411 		}
4412 	}
4413 
4414 	/* Set the bypass event to transition to bypass mode. */
4415 	rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4416 					      bypass_mode);
4417 #endif
4418 
4419 	if (rc != 0)
4420 		printf("\t Failed to set bypass event for port = %d.\n",
4421 		       port_id);
4422 }
4423 
4424 cmdline_parse_token_string_t cmd_setbypass_event_set =
4425 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4426 			set, "set");
4427 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4428 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4429 			bypass, "bypass");
4430 cmdline_parse_token_string_t cmd_setbypass_event_event =
4431 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4432 			event, "event");
4433 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4434 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4435 			event_value, "none#timeout#os_off#os_on#power_on#power_off");
4436 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4437 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4438 			mode, "mode");
4439 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4440 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4441 			mode_value, "normal#bypass#isolate");
4442 cmdline_parse_token_num_t cmd_setbypass_event_port =
4443 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4444 				port_id, UINT8);
4445 
4446 cmdline_parse_inst_t cmd_set_bypass_event = {
4447 	.f = cmd_set_bypass_event_parsed,
4448 	.help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4449 		"power_off mode normal|bypass|isolate <port_id>: "
4450 		"Set the NIC bypass event mode for port_id",
4451 	.data = NULL,
4452 	.tokens = {
4453 		(void *)&cmd_setbypass_event_set,
4454 		(void *)&cmd_setbypass_event_bypass,
4455 		(void *)&cmd_setbypass_event_event,
4456 		(void *)&cmd_setbypass_event_event_value,
4457 		(void *)&cmd_setbypass_event_mode,
4458 		(void *)&cmd_setbypass_event_mode_value,
4459 		(void *)&cmd_setbypass_event_port,
4460 		NULL,
4461 	},
4462 };
4463 
4464 
4465 /* *** SET NIC BYPASS TIMEOUT *** */
4466 struct cmd_set_bypass_timeout_result {
4467 	cmdline_fixed_string_t set;
4468 	cmdline_fixed_string_t bypass;
4469 	cmdline_fixed_string_t timeout;
4470 	cmdline_fixed_string_t value;
4471 };
4472 
4473 static void
4474 cmd_set_bypass_timeout_parsed(void *parsed_result,
4475 		__attribute__((unused)) struct cmdline *cl,
4476 		__attribute__((unused)) void *data)
4477 {
4478 	__rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4479 
4480 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4481 	if (!strcmp(res->value, "1.5"))
4482 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4483 	else if (!strcmp(res->value, "2"))
4484 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4485 	else if (!strcmp(res->value, "3"))
4486 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4487 	else if (!strcmp(res->value, "4"))
4488 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4489 	else if (!strcmp(res->value, "8"))
4490 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4491 	else if (!strcmp(res->value, "16"))
4492 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4493 	else if (!strcmp(res->value, "32"))
4494 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4495 	else
4496 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4497 #endif
4498 }
4499 
4500 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4501 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4502 			set, "set");
4503 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4504 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4505 			bypass, "bypass");
4506 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4507 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4508 			timeout, "timeout");
4509 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4510 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4511 			value, "0#1.5#2#3#4#8#16#32");
4512 
4513 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4514 	.f = cmd_set_bypass_timeout_parsed,
4515 	.help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4516 		"Set the NIC bypass watchdog timeout in seconds",
4517 	.data = NULL,
4518 	.tokens = {
4519 		(void *)&cmd_setbypass_timeout_set,
4520 		(void *)&cmd_setbypass_timeout_bypass,
4521 		(void *)&cmd_setbypass_timeout_timeout,
4522 		(void *)&cmd_setbypass_timeout_value,
4523 		NULL,
4524 	},
4525 };
4526 
4527 /* *** SHOW NIC BYPASS MODE *** */
4528 struct cmd_show_bypass_config_result {
4529 	cmdline_fixed_string_t show;
4530 	cmdline_fixed_string_t bypass;
4531 	cmdline_fixed_string_t config;
4532 	uint8_t port_id;
4533 };
4534 
4535 static void
4536 cmd_show_bypass_config_parsed(void *parsed_result,
4537 		__attribute__((unused)) struct cmdline *cl,
4538 		__attribute__((unused)) void *data)
4539 {
4540 	struct cmd_show_bypass_config_result *res = parsed_result;
4541 	portid_t port_id = res->port_id;
4542 	int rc = -EINVAL;
4543 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4544 	uint32_t event_mode;
4545 	uint32_t bypass_mode;
4546 	uint32_t timeout = bypass_timeout;
4547 	int i;
4548 
4549 	static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4550 		{"off", "1.5", "2", "3", "4", "8", "16", "32"};
4551 	static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4552 		{"UNKNOWN", "normal", "bypass", "isolate"};
4553 	static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4554 		"NONE",
4555 		"OS/board on",
4556 		"power supply on",
4557 		"OS/board off",
4558 		"power supply off",
4559 		"timeout"};
4560 	int num_events = (sizeof events) / (sizeof events[0]);
4561 
4562 	/* Display the bypass mode.*/
4563 	if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4564 		printf("\tFailed to get bypass mode for port = %d\n", port_id);
4565 		return;
4566 	}
4567 	else {
4568 		if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4569 			bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4570 
4571 		printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4572 	}
4573 
4574 	/* Display the bypass timeout.*/
4575 	if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4576 		timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4577 
4578 	printf("\tbypass timeout = %s\n", timeouts[timeout]);
4579 
4580 	/* Display the bypass events and associated modes. */
4581 	for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4582 
4583 		if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4584 			printf("\tFailed to get bypass mode for event = %s\n",
4585 				events[i]);
4586 		} else {
4587 			if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4588 				event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4589 
4590 			printf("\tbypass event: %-16s = %s\n", events[i],
4591 				modes[event_mode]);
4592 		}
4593 	}
4594 #endif
4595 	if (rc != 0)
4596 		printf("\tFailed to get bypass configuration for port = %d\n",
4597 		       port_id);
4598 }
4599 
4600 cmdline_parse_token_string_t cmd_showbypass_config_show =
4601 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4602 			show, "show");
4603 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4604 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4605 			bypass, "bypass");
4606 cmdline_parse_token_string_t cmd_showbypass_config_config =
4607 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4608 			config, "config");
4609 cmdline_parse_token_num_t cmd_showbypass_config_port =
4610 	TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4611 				port_id, UINT8);
4612 
4613 cmdline_parse_inst_t cmd_show_bypass_config = {
4614 	.f = cmd_show_bypass_config_parsed,
4615 	.help_str = "show bypass config <port_id>: "
4616 	            "Show the NIC bypass config for port_id",
4617 	.data = NULL,
4618 	.tokens = {
4619 		(void *)&cmd_showbypass_config_show,
4620 		(void *)&cmd_showbypass_config_bypass,
4621 		(void *)&cmd_showbypass_config_config,
4622 		(void *)&cmd_showbypass_config_port,
4623 		NULL,
4624 	},
4625 };
4626 
4627 #ifdef RTE_LIBRTE_PMD_BOND
4628 /* *** SET BONDING MODE *** */
4629 struct cmd_set_bonding_mode_result {
4630 	cmdline_fixed_string_t set;
4631 	cmdline_fixed_string_t bonding;
4632 	cmdline_fixed_string_t mode;
4633 	uint8_t value;
4634 	uint8_t port_id;
4635 };
4636 
4637 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4638 		__attribute__((unused))  struct cmdline *cl,
4639 		__attribute__((unused)) void *data)
4640 {
4641 	struct cmd_set_bonding_mode_result *res = parsed_result;
4642 	portid_t port_id = res->port_id;
4643 
4644 	/* Set the bonding mode for the relevant port. */
4645 	if (0 != rte_eth_bond_mode_set(port_id, res->value))
4646 		printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4647 }
4648 
4649 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4650 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4651 		set, "set");
4652 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4653 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4654 		bonding, "bonding");
4655 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4656 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4657 		mode, "mode");
4658 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4659 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4660 		value, UINT8);
4661 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4662 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4663 		port_id, UINT8);
4664 
4665 cmdline_parse_inst_t cmd_set_bonding_mode = {
4666 		.f = cmd_set_bonding_mode_parsed,
4667 		.help_str = "set bonding mode <mode_value> <port_id>: "
4668 			"Set the bonding mode for port_id",
4669 		.data = NULL,
4670 		.tokens = {
4671 				(void *) &cmd_setbonding_mode_set,
4672 				(void *) &cmd_setbonding_mode_bonding,
4673 				(void *) &cmd_setbonding_mode_mode,
4674 				(void *) &cmd_setbonding_mode_value,
4675 				(void *) &cmd_setbonding_mode_port,
4676 				NULL
4677 		}
4678 };
4679 
4680 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4681 struct cmd_set_bonding_lacp_dedicated_queues_result {
4682 	cmdline_fixed_string_t set;
4683 	cmdline_fixed_string_t bonding;
4684 	cmdline_fixed_string_t lacp;
4685 	cmdline_fixed_string_t dedicated_queues;
4686 	uint8_t port_id;
4687 	cmdline_fixed_string_t mode;
4688 };
4689 
4690 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4691 		__attribute__((unused))  struct cmdline *cl,
4692 		__attribute__((unused)) void *data)
4693 {
4694 	struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4695 	portid_t port_id = res->port_id;
4696 	struct rte_port *port;
4697 
4698 	port = &ports[port_id];
4699 
4700 	/** Check if the port is not started **/
4701 	if (port->port_status != RTE_PORT_STOPPED) {
4702 		printf("Please stop port %d first\n", port_id);
4703 		return;
4704 	}
4705 
4706 	if (!strcmp(res->mode, "enable")) {
4707 		if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4708 			printf("Dedicate queues for LACP control packets"
4709 					" enabled\n");
4710 		else
4711 			printf("Enabling dedicate queues for LACP control "
4712 					"packets on port %d failed\n", port_id);
4713 	} else if (!strcmp(res->mode, "disable")) {
4714 		if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4715 			printf("Dedicated queues for LACP control packets "
4716 					"disabled\n");
4717 		else
4718 			printf("Disabling dedicated queues for LACP control "
4719 					"traffic on port %d failed\n", port_id);
4720 	}
4721 }
4722 
4723 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4724 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4725 		set, "set");
4726 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4727 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4728 		bonding, "bonding");
4729 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4730 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4731 		lacp, "lacp");
4732 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4733 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4734 		dedicated_queues, "dedicated_queues");
4735 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4736 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4737 		port_id, UINT8);
4738 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4739 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4740 		mode, "enable#disable");
4741 
4742 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4743 		.f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4744 		.help_str = "set bonding lacp dedicated_queues <port_id> "
4745 			"enable|disable: "
4746 			"Enable/disable dedicated queues for LACP control traffic for port_id",
4747 		.data = NULL,
4748 		.tokens = {
4749 			(void *)&cmd_setbonding_lacp_dedicated_queues_set,
4750 			(void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4751 			(void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4752 			(void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4753 			(void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4754 			(void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4755 			NULL
4756 		}
4757 };
4758 
4759 /* *** SET BALANCE XMIT POLICY *** */
4760 struct cmd_set_bonding_balance_xmit_policy_result {
4761 	cmdline_fixed_string_t set;
4762 	cmdline_fixed_string_t bonding;
4763 	cmdline_fixed_string_t balance_xmit_policy;
4764 	uint8_t port_id;
4765 	cmdline_fixed_string_t policy;
4766 };
4767 
4768 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4769 		__attribute__((unused))  struct cmdline *cl,
4770 		__attribute__((unused)) void *data)
4771 {
4772 	struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4773 	portid_t port_id = res->port_id;
4774 	uint8_t policy;
4775 
4776 	if (!strcmp(res->policy, "l2")) {
4777 		policy = BALANCE_XMIT_POLICY_LAYER2;
4778 	} else if (!strcmp(res->policy, "l23")) {
4779 		policy = BALANCE_XMIT_POLICY_LAYER23;
4780 	} else if (!strcmp(res->policy, "l34")) {
4781 		policy = BALANCE_XMIT_POLICY_LAYER34;
4782 	} else {
4783 		printf("\t Invalid xmit policy selection");
4784 		return;
4785 	}
4786 
4787 	/* Set the bonding mode for the relevant port. */
4788 	if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4789 		printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4790 				port_id);
4791 	}
4792 }
4793 
4794 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4795 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4796 		set, "set");
4797 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4798 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4799 		bonding, "bonding");
4800 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4801 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4802 		balance_xmit_policy, "balance_xmit_policy");
4803 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4804 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4805 		port_id, UINT8);
4806 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4807 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4808 		policy, "l2#l23#l34");
4809 
4810 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4811 		.f = cmd_set_bonding_balance_xmit_policy_parsed,
4812 		.help_str = "set bonding balance_xmit_policy <port_id> "
4813 			"l2|l23|l34: "
4814 			"Set the bonding balance_xmit_policy for port_id",
4815 		.data = NULL,
4816 		.tokens = {
4817 				(void *)&cmd_setbonding_balance_xmit_policy_set,
4818 				(void *)&cmd_setbonding_balance_xmit_policy_bonding,
4819 				(void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4820 				(void *)&cmd_setbonding_balance_xmit_policy_port,
4821 				(void *)&cmd_setbonding_balance_xmit_policy_policy,
4822 				NULL
4823 		}
4824 };
4825 
4826 /* *** SHOW NIC BONDING CONFIGURATION *** */
4827 struct cmd_show_bonding_config_result {
4828 	cmdline_fixed_string_t show;
4829 	cmdline_fixed_string_t bonding;
4830 	cmdline_fixed_string_t config;
4831 	portid_t port_id;
4832 };
4833 
4834 static void cmd_show_bonding_config_parsed(void *parsed_result,
4835 		__attribute__((unused))  struct cmdline *cl,
4836 		__attribute__((unused)) void *data)
4837 {
4838 	struct cmd_show_bonding_config_result *res = parsed_result;
4839 	int bonding_mode, agg_mode;
4840 	portid_t slaves[RTE_MAX_ETHPORTS];
4841 	int num_slaves, num_active_slaves;
4842 	int primary_id;
4843 	int i;
4844 	portid_t port_id = res->port_id;
4845 
4846 	/* Display the bonding mode.*/
4847 	bonding_mode = rte_eth_bond_mode_get(port_id);
4848 	if (bonding_mode < 0) {
4849 		printf("\tFailed to get bonding mode for port = %d\n", port_id);
4850 		return;
4851 	} else
4852 		printf("\tBonding mode: %d\n", bonding_mode);
4853 
4854 	if (bonding_mode == BONDING_MODE_BALANCE) {
4855 		int balance_xmit_policy;
4856 
4857 		balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4858 		if (balance_xmit_policy < 0) {
4859 			printf("\tFailed to get balance xmit policy for port = %d\n",
4860 					port_id);
4861 			return;
4862 		} else {
4863 			printf("\tBalance Xmit Policy: ");
4864 
4865 			switch (balance_xmit_policy) {
4866 			case BALANCE_XMIT_POLICY_LAYER2:
4867 				printf("BALANCE_XMIT_POLICY_LAYER2");
4868 				break;
4869 			case BALANCE_XMIT_POLICY_LAYER23:
4870 				printf("BALANCE_XMIT_POLICY_LAYER23");
4871 				break;
4872 			case BALANCE_XMIT_POLICY_LAYER34:
4873 				printf("BALANCE_XMIT_POLICY_LAYER34");
4874 				break;
4875 			}
4876 			printf("\n");
4877 		}
4878 	}
4879 
4880 	if (bonding_mode == BONDING_MODE_8023AD) {
4881 		agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4882 		printf("\tIEEE802.3AD Aggregator Mode: ");
4883 		switch (agg_mode) {
4884 		case AGG_BANDWIDTH:
4885 			printf("bandwidth");
4886 			break;
4887 		case AGG_STABLE:
4888 			printf("stable");
4889 			break;
4890 		case AGG_COUNT:
4891 			printf("count");
4892 			break;
4893 		}
4894 		printf("\n");
4895 	}
4896 
4897 	num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4898 
4899 	if (num_slaves < 0) {
4900 		printf("\tFailed to get slave list for port = %d\n", port_id);
4901 		return;
4902 	}
4903 	if (num_slaves > 0) {
4904 		printf("\tSlaves (%d): [", num_slaves);
4905 		for (i = 0; i < num_slaves - 1; i++)
4906 			printf("%d ", slaves[i]);
4907 
4908 		printf("%d]\n", slaves[num_slaves - 1]);
4909 	} else {
4910 		printf("\tSlaves: []\n");
4911 
4912 	}
4913 
4914 	num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4915 			RTE_MAX_ETHPORTS);
4916 
4917 	if (num_active_slaves < 0) {
4918 		printf("\tFailed to get active slave list for port = %d\n", port_id);
4919 		return;
4920 	}
4921 	if (num_active_slaves > 0) {
4922 		printf("\tActive Slaves (%d): [", num_active_slaves);
4923 		for (i = 0; i < num_active_slaves - 1; i++)
4924 			printf("%d ", slaves[i]);
4925 
4926 		printf("%d]\n", slaves[num_active_slaves - 1]);
4927 
4928 	} else {
4929 		printf("\tActive Slaves: []\n");
4930 
4931 	}
4932 
4933 	primary_id = rte_eth_bond_primary_get(port_id);
4934 	if (primary_id < 0) {
4935 		printf("\tFailed to get primary slave for port = %d\n", port_id);
4936 		return;
4937 	} else
4938 		printf("\tPrimary: [%d]\n", primary_id);
4939 
4940 }
4941 
4942 cmdline_parse_token_string_t cmd_showbonding_config_show =
4943 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4944 		show, "show");
4945 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4946 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4947 		bonding, "bonding");
4948 cmdline_parse_token_string_t cmd_showbonding_config_config =
4949 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4950 		config, "config");
4951 cmdline_parse_token_num_t cmd_showbonding_config_port =
4952 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4953 		port_id, UINT8);
4954 
4955 cmdline_parse_inst_t cmd_show_bonding_config = {
4956 		.f = cmd_show_bonding_config_parsed,
4957 		.help_str = "show bonding config <port_id>: "
4958 			"Show the bonding config for port_id",
4959 		.data = NULL,
4960 		.tokens = {
4961 				(void *)&cmd_showbonding_config_show,
4962 				(void *)&cmd_showbonding_config_bonding,
4963 				(void *)&cmd_showbonding_config_config,
4964 				(void *)&cmd_showbonding_config_port,
4965 				NULL
4966 		}
4967 };
4968 
4969 /* *** SET BONDING PRIMARY *** */
4970 struct cmd_set_bonding_primary_result {
4971 	cmdline_fixed_string_t set;
4972 	cmdline_fixed_string_t bonding;
4973 	cmdline_fixed_string_t primary;
4974 	uint8_t slave_id;
4975 	uint8_t port_id;
4976 };
4977 
4978 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4979 		__attribute__((unused))  struct cmdline *cl,
4980 		__attribute__((unused)) void *data)
4981 {
4982 	struct cmd_set_bonding_primary_result *res = parsed_result;
4983 	portid_t master_port_id = res->port_id;
4984 	portid_t slave_port_id = res->slave_id;
4985 
4986 	/* Set the primary slave for a bonded device. */
4987 	if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4988 		printf("\t Failed to set primary slave for port = %d.\n",
4989 				master_port_id);
4990 		return;
4991 	}
4992 	init_port_config();
4993 }
4994 
4995 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4996 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4997 		set, "set");
4998 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4999 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5000 		bonding, "bonding");
5001 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5002 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5003 		primary, "primary");
5004 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5005 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5006 		slave_id, UINT8);
5007 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5008 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5009 		port_id, UINT8);
5010 
5011 cmdline_parse_inst_t cmd_set_bonding_primary = {
5012 		.f = cmd_set_bonding_primary_parsed,
5013 		.help_str = "set bonding primary <slave_id> <port_id>: "
5014 			"Set the primary slave for port_id",
5015 		.data = NULL,
5016 		.tokens = {
5017 				(void *)&cmd_setbonding_primary_set,
5018 				(void *)&cmd_setbonding_primary_bonding,
5019 				(void *)&cmd_setbonding_primary_primary,
5020 				(void *)&cmd_setbonding_primary_slave,
5021 				(void *)&cmd_setbonding_primary_port,
5022 				NULL
5023 		}
5024 };
5025 
5026 /* *** ADD SLAVE *** */
5027 struct cmd_add_bonding_slave_result {
5028 	cmdline_fixed_string_t add;
5029 	cmdline_fixed_string_t bonding;
5030 	cmdline_fixed_string_t slave;
5031 	uint8_t slave_id;
5032 	uint8_t port_id;
5033 };
5034 
5035 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5036 		__attribute__((unused))  struct cmdline *cl,
5037 		__attribute__((unused)) void *data)
5038 {
5039 	struct cmd_add_bonding_slave_result *res = parsed_result;
5040 	portid_t master_port_id = res->port_id;
5041 	portid_t slave_port_id = res->slave_id;
5042 
5043 	/* add the slave for a bonded device. */
5044 	if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5045 		printf("\t Failed to add slave %d to master port = %d.\n",
5046 				slave_port_id, master_port_id);
5047 		return;
5048 	}
5049 	init_port_config();
5050 	set_port_slave_flag(slave_port_id);
5051 }
5052 
5053 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5054 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5055 		add, "add");
5056 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5057 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5058 		bonding, "bonding");
5059 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5060 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5061 		slave, "slave");
5062 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5063 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5064 		slave_id, UINT8);
5065 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5066 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5067 		port_id, UINT8);
5068 
5069 cmdline_parse_inst_t cmd_add_bonding_slave = {
5070 		.f = cmd_add_bonding_slave_parsed,
5071 		.help_str = "add bonding slave <slave_id> <port_id>: "
5072 			"Add a slave device to a bonded device",
5073 		.data = NULL,
5074 		.tokens = {
5075 				(void *)&cmd_addbonding_slave_add,
5076 				(void *)&cmd_addbonding_slave_bonding,
5077 				(void *)&cmd_addbonding_slave_slave,
5078 				(void *)&cmd_addbonding_slave_slaveid,
5079 				(void *)&cmd_addbonding_slave_port,
5080 				NULL
5081 		}
5082 };
5083 
5084 /* *** REMOVE SLAVE *** */
5085 struct cmd_remove_bonding_slave_result {
5086 	cmdline_fixed_string_t remove;
5087 	cmdline_fixed_string_t bonding;
5088 	cmdline_fixed_string_t slave;
5089 	uint8_t slave_id;
5090 	uint8_t port_id;
5091 };
5092 
5093 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5094 		__attribute__((unused))  struct cmdline *cl,
5095 		__attribute__((unused)) void *data)
5096 {
5097 	struct cmd_remove_bonding_slave_result *res = parsed_result;
5098 	portid_t master_port_id = res->port_id;
5099 	portid_t slave_port_id = res->slave_id;
5100 
5101 	/* remove the slave from a bonded device. */
5102 	if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5103 		printf("\t Failed to remove slave %d from master port = %d.\n",
5104 				slave_port_id, master_port_id);
5105 		return;
5106 	}
5107 	init_port_config();
5108 	clear_port_slave_flag(slave_port_id);
5109 }
5110 
5111 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5112 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5113 				remove, "remove");
5114 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5115 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5116 				bonding, "bonding");
5117 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5118 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5119 				slave, "slave");
5120 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5121 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5122 				slave_id, UINT8);
5123 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5124 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5125 				port_id, UINT8);
5126 
5127 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5128 		.f = cmd_remove_bonding_slave_parsed,
5129 		.help_str = "remove bonding slave <slave_id> <port_id>: "
5130 			"Remove a slave device from a bonded device",
5131 		.data = NULL,
5132 		.tokens = {
5133 				(void *)&cmd_removebonding_slave_remove,
5134 				(void *)&cmd_removebonding_slave_bonding,
5135 				(void *)&cmd_removebonding_slave_slave,
5136 				(void *)&cmd_removebonding_slave_slaveid,
5137 				(void *)&cmd_removebonding_slave_port,
5138 				NULL
5139 		}
5140 };
5141 
5142 /* *** CREATE BONDED DEVICE *** */
5143 struct cmd_create_bonded_device_result {
5144 	cmdline_fixed_string_t create;
5145 	cmdline_fixed_string_t bonded;
5146 	cmdline_fixed_string_t device;
5147 	uint8_t mode;
5148 	uint8_t socket;
5149 };
5150 
5151 static int bond_dev_num = 0;
5152 
5153 static void cmd_create_bonded_device_parsed(void *parsed_result,
5154 		__attribute__((unused))  struct cmdline *cl,
5155 		__attribute__((unused)) void *data)
5156 {
5157 	struct cmd_create_bonded_device_result *res = parsed_result;
5158 	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5159 	int port_id;
5160 
5161 	if (test_done == 0) {
5162 		printf("Please stop forwarding first\n");
5163 		return;
5164 	}
5165 
5166 	snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5167 			bond_dev_num++);
5168 
5169 	/* Create a new bonded device. */
5170 	port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5171 	if (port_id < 0) {
5172 		printf("\t Failed to create bonded device.\n");
5173 		return;
5174 	} else {
5175 		printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5176 				port_id);
5177 
5178 		/* Update number of ports */
5179 		nb_ports = rte_eth_dev_count();
5180 		reconfig(port_id, res->socket);
5181 		rte_eth_promiscuous_enable(port_id);
5182 	}
5183 
5184 }
5185 
5186 cmdline_parse_token_string_t cmd_createbonded_device_create =
5187 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5188 				create, "create");
5189 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5190 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5191 				bonded, "bonded");
5192 cmdline_parse_token_string_t cmd_createbonded_device_device =
5193 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5194 				device, "device");
5195 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5196 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5197 				mode, UINT8);
5198 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5199 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5200 				socket, UINT8);
5201 
5202 cmdline_parse_inst_t cmd_create_bonded_device = {
5203 		.f = cmd_create_bonded_device_parsed,
5204 		.help_str = "create bonded device <mode> <socket>: "
5205 			"Create a new bonded device with specific bonding mode and socket",
5206 		.data = NULL,
5207 		.tokens = {
5208 				(void *)&cmd_createbonded_device_create,
5209 				(void *)&cmd_createbonded_device_bonded,
5210 				(void *)&cmd_createbonded_device_device,
5211 				(void *)&cmd_createbonded_device_mode,
5212 				(void *)&cmd_createbonded_device_socket,
5213 				NULL
5214 		}
5215 };
5216 
5217 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5218 struct cmd_set_bond_mac_addr_result {
5219 	cmdline_fixed_string_t set;
5220 	cmdline_fixed_string_t bonding;
5221 	cmdline_fixed_string_t mac_addr;
5222 	uint8_t port_num;
5223 	struct ether_addr address;
5224 };
5225 
5226 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5227 		__attribute__((unused))  struct cmdline *cl,
5228 		__attribute__((unused)) void *data)
5229 {
5230 	struct cmd_set_bond_mac_addr_result *res = parsed_result;
5231 	int ret;
5232 
5233 	if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5234 		return;
5235 
5236 	ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5237 
5238 	/* check the return value and print it if is < 0 */
5239 	if (ret < 0)
5240 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5241 }
5242 
5243 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5244 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5245 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5246 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5247 				"bonding");
5248 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5249 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5250 				"mac_addr");
5251 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5252 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
5253 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5254 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5255 
5256 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5257 		.f = cmd_set_bond_mac_addr_parsed,
5258 		.data = (void *) 0,
5259 		.help_str = "set bonding mac_addr <port_id> <mac_addr>",
5260 		.tokens = {
5261 				(void *)&cmd_set_bond_mac_addr_set,
5262 				(void *)&cmd_set_bond_mac_addr_bonding,
5263 				(void *)&cmd_set_bond_mac_addr_mac,
5264 				(void *)&cmd_set_bond_mac_addr_portnum,
5265 				(void *)&cmd_set_bond_mac_addr_addr,
5266 				NULL
5267 		}
5268 };
5269 
5270 
5271 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5272 struct cmd_set_bond_mon_period_result {
5273 	cmdline_fixed_string_t set;
5274 	cmdline_fixed_string_t bonding;
5275 	cmdline_fixed_string_t mon_period;
5276 	uint8_t port_num;
5277 	uint32_t period_ms;
5278 };
5279 
5280 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5281 		__attribute__((unused))  struct cmdline *cl,
5282 		__attribute__((unused)) void *data)
5283 {
5284 	struct cmd_set_bond_mon_period_result *res = parsed_result;
5285 	int ret;
5286 
5287 	if (res->port_num >= nb_ports) {
5288 		printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5289 		return;
5290 	}
5291 
5292 	ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5293 
5294 	/* check the return value and print it if is < 0 */
5295 	if (ret < 0)
5296 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5297 }
5298 
5299 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5300 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5301 				set, "set");
5302 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5303 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5304 				bonding, "bonding");
5305 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5306 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5307 				mon_period,	"mon_period");
5308 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5309 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5310 				port_num, UINT8);
5311 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5312 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5313 				period_ms, UINT32);
5314 
5315 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5316 		.f = cmd_set_bond_mon_period_parsed,
5317 		.data = (void *) 0,
5318 		.help_str = "set bonding mon_period <port_id> <period_ms>",
5319 		.tokens = {
5320 				(void *)&cmd_set_bond_mon_period_set,
5321 				(void *)&cmd_set_bond_mon_period_bonding,
5322 				(void *)&cmd_set_bond_mon_period_mon_period,
5323 				(void *)&cmd_set_bond_mon_period_portnum,
5324 				(void *)&cmd_set_bond_mon_period_period_ms,
5325 				NULL
5326 		}
5327 };
5328 
5329 
5330 
5331 struct cmd_set_bonding_agg_mode_policy_result {
5332 	cmdline_fixed_string_t set;
5333 	cmdline_fixed_string_t bonding;
5334 	cmdline_fixed_string_t agg_mode;
5335 	uint8_t port_num;
5336 	cmdline_fixed_string_t policy;
5337 };
5338 
5339 
5340 static void
5341 cmd_set_bonding_agg_mode(void *parsed_result,
5342 		__attribute__((unused)) struct cmdline *cl,
5343 		__attribute__((unused)) void *data)
5344 {
5345 	struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5346 	uint8_t policy = AGG_BANDWIDTH;
5347 
5348 	if (res->port_num >= nb_ports) {
5349 		printf("Port id %d must be less than %d\n",
5350 				res->port_num, nb_ports);
5351 		return;
5352 	}
5353 
5354 	if (!strcmp(res->policy, "bandwidth"))
5355 		policy = AGG_BANDWIDTH;
5356 	else if (!strcmp(res->policy, "stable"))
5357 		policy = AGG_STABLE;
5358 	else if (!strcmp(res->policy, "count"))
5359 		policy = AGG_COUNT;
5360 
5361 	rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5362 }
5363 
5364 
5365 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5366 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5367 				set, "set");
5368 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5369 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5370 				bonding, "bonding");
5371 
5372 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5373 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5374 				agg_mode, "agg_mode");
5375 
5376 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5377 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5378 				port_num, UINT8);
5379 
5380 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5381 	TOKEN_STRING_INITIALIZER(
5382 			struct cmd_set_bonding_balance_xmit_policy_result,
5383 		policy, "stable#bandwidth#count");
5384 
5385 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5386 	.f = cmd_set_bonding_agg_mode,
5387 	.data = (void *) 0,
5388 	.help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5389 	.tokens = {
5390 			(void *)&cmd_set_bonding_agg_mode_set,
5391 			(void *)&cmd_set_bonding_agg_mode_bonding,
5392 			(void *)&cmd_set_bonding_agg_mode_agg_mode,
5393 			(void *)&cmd_set_bonding_agg_mode_portnum,
5394 			(void *)&cmd_set_bonding_agg_mode_policy_string,
5395 			NULL
5396 		}
5397 };
5398 
5399 
5400 #endif /* RTE_LIBRTE_PMD_BOND */
5401 
5402 /* *** SET FORWARDING MODE *** */
5403 struct cmd_set_fwd_mode_result {
5404 	cmdline_fixed_string_t set;
5405 	cmdline_fixed_string_t fwd;
5406 	cmdline_fixed_string_t mode;
5407 };
5408 
5409 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5410 				    __attribute__((unused)) struct cmdline *cl,
5411 				    __attribute__((unused)) void *data)
5412 {
5413 	struct cmd_set_fwd_mode_result *res = parsed_result;
5414 
5415 	retry_enabled = 0;
5416 	set_pkt_forwarding_mode(res->mode);
5417 }
5418 
5419 cmdline_parse_token_string_t cmd_setfwd_set =
5420 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5421 cmdline_parse_token_string_t cmd_setfwd_fwd =
5422 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5423 cmdline_parse_token_string_t cmd_setfwd_mode =
5424 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5425 		"" /* defined at init */);
5426 
5427 cmdline_parse_inst_t cmd_set_fwd_mode = {
5428 	.f = cmd_set_fwd_mode_parsed,
5429 	.data = NULL,
5430 	.help_str = NULL, /* defined at init */
5431 	.tokens = {
5432 		(void *)&cmd_setfwd_set,
5433 		(void *)&cmd_setfwd_fwd,
5434 		(void *)&cmd_setfwd_mode,
5435 		NULL,
5436 	},
5437 };
5438 
5439 static void cmd_set_fwd_mode_init(void)
5440 {
5441 	char *modes, *c;
5442 	static char token[128];
5443 	static char help[256];
5444 	cmdline_parse_token_string_t *token_struct;
5445 
5446 	modes = list_pkt_forwarding_modes();
5447 	snprintf(help, sizeof(help), "set fwd %s: "
5448 		"Set packet forwarding mode", modes);
5449 	cmd_set_fwd_mode.help_str = help;
5450 
5451 	/* string token separator is # */
5452 	for (c = token; *modes != '\0'; modes++)
5453 		if (*modes == '|')
5454 			*c++ = '#';
5455 		else
5456 			*c++ = *modes;
5457 	token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5458 	token_struct->string_data.str = token;
5459 }
5460 
5461 /* *** SET RETRY FORWARDING MODE *** */
5462 struct cmd_set_fwd_retry_mode_result {
5463 	cmdline_fixed_string_t set;
5464 	cmdline_fixed_string_t fwd;
5465 	cmdline_fixed_string_t mode;
5466 	cmdline_fixed_string_t retry;
5467 };
5468 
5469 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5470 			    __attribute__((unused)) struct cmdline *cl,
5471 			    __attribute__((unused)) void *data)
5472 {
5473 	struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5474 
5475 	retry_enabled = 1;
5476 	set_pkt_forwarding_mode(res->mode);
5477 }
5478 
5479 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5480 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5481 			set, "set");
5482 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5483 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5484 			fwd, "fwd");
5485 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5486 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5487 			mode,
5488 		"" /* defined at init */);
5489 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5490 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5491 			retry, "retry");
5492 
5493 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5494 	.f = cmd_set_fwd_retry_mode_parsed,
5495 	.data = NULL,
5496 	.help_str = NULL, /* defined at init */
5497 	.tokens = {
5498 		(void *)&cmd_setfwd_retry_set,
5499 		(void *)&cmd_setfwd_retry_fwd,
5500 		(void *)&cmd_setfwd_retry_mode,
5501 		(void *)&cmd_setfwd_retry_retry,
5502 		NULL,
5503 	},
5504 };
5505 
5506 static void cmd_set_fwd_retry_mode_init(void)
5507 {
5508 	char *modes, *c;
5509 	static char token[128];
5510 	static char help[256];
5511 	cmdline_parse_token_string_t *token_struct;
5512 
5513 	modes = list_pkt_forwarding_retry_modes();
5514 	snprintf(help, sizeof(help), "set fwd %s retry: "
5515 		"Set packet forwarding mode with retry", modes);
5516 	cmd_set_fwd_retry_mode.help_str = help;
5517 
5518 	/* string token separator is # */
5519 	for (c = token; *modes != '\0'; modes++)
5520 		if (*modes == '|')
5521 			*c++ = '#';
5522 		else
5523 			*c++ = *modes;
5524 	token_struct = (cmdline_parse_token_string_t *)
5525 		cmd_set_fwd_retry_mode.tokens[2];
5526 	token_struct->string_data.str = token;
5527 }
5528 
5529 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5530 struct cmd_set_burst_tx_retry_result {
5531 	cmdline_fixed_string_t set;
5532 	cmdline_fixed_string_t burst;
5533 	cmdline_fixed_string_t tx;
5534 	cmdline_fixed_string_t delay;
5535 	uint32_t time;
5536 	cmdline_fixed_string_t retry;
5537 	uint32_t retry_num;
5538 };
5539 
5540 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5541 					__attribute__((unused)) struct cmdline *cl,
5542 					__attribute__((unused)) void *data)
5543 {
5544 	struct cmd_set_burst_tx_retry_result *res = parsed_result;
5545 
5546 	if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5547 		&& !strcmp(res->tx, "tx")) {
5548 		if (!strcmp(res->delay, "delay"))
5549 			burst_tx_delay_time = res->time;
5550 		if (!strcmp(res->retry, "retry"))
5551 			burst_tx_retry_num = res->retry_num;
5552 	}
5553 
5554 }
5555 
5556 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5557 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5558 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5559 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5560 				 "burst");
5561 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5562 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5563 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5564 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5565 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5566 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5567 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5568 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5569 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5570 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5571 
5572 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5573 	.f = cmd_set_burst_tx_retry_parsed,
5574 	.help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5575 	.tokens = {
5576 		(void *)&cmd_set_burst_tx_retry_set,
5577 		(void *)&cmd_set_burst_tx_retry_burst,
5578 		(void *)&cmd_set_burst_tx_retry_tx,
5579 		(void *)&cmd_set_burst_tx_retry_delay,
5580 		(void *)&cmd_set_burst_tx_retry_time,
5581 		(void *)&cmd_set_burst_tx_retry_retry,
5582 		(void *)&cmd_set_burst_tx_retry_retry_num,
5583 		NULL,
5584 	},
5585 };
5586 
5587 /* *** SET PROMISC MODE *** */
5588 struct cmd_set_promisc_mode_result {
5589 	cmdline_fixed_string_t set;
5590 	cmdline_fixed_string_t promisc;
5591 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5592 	uint8_t port_num;                /* valid if "allports" argument == 0 */
5593 	cmdline_fixed_string_t mode;
5594 };
5595 
5596 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5597 					__attribute__((unused)) struct cmdline *cl,
5598 					void *allports)
5599 {
5600 	struct cmd_set_promisc_mode_result *res = parsed_result;
5601 	int enable;
5602 	portid_t i;
5603 
5604 	if (!strcmp(res->mode, "on"))
5605 		enable = 1;
5606 	else
5607 		enable = 0;
5608 
5609 	/* all ports */
5610 	if (allports) {
5611 		RTE_ETH_FOREACH_DEV(i) {
5612 			if (enable)
5613 				rte_eth_promiscuous_enable(i);
5614 			else
5615 				rte_eth_promiscuous_disable(i);
5616 		}
5617 	}
5618 	else {
5619 		if (enable)
5620 			rte_eth_promiscuous_enable(res->port_num);
5621 		else
5622 			rte_eth_promiscuous_disable(res->port_num);
5623 	}
5624 }
5625 
5626 cmdline_parse_token_string_t cmd_setpromisc_set =
5627 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5628 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5629 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5630 				 "promisc");
5631 cmdline_parse_token_string_t cmd_setpromisc_portall =
5632 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5633 				 "all");
5634 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5635 	TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5636 			      UINT8);
5637 cmdline_parse_token_string_t cmd_setpromisc_mode =
5638 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5639 				 "on#off");
5640 
5641 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5642 	.f = cmd_set_promisc_mode_parsed,
5643 	.data = (void *)1,
5644 	.help_str = "set promisc all on|off: Set promisc mode for all ports",
5645 	.tokens = {
5646 		(void *)&cmd_setpromisc_set,
5647 		(void *)&cmd_setpromisc_promisc,
5648 		(void *)&cmd_setpromisc_portall,
5649 		(void *)&cmd_setpromisc_mode,
5650 		NULL,
5651 	},
5652 };
5653 
5654 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5655 	.f = cmd_set_promisc_mode_parsed,
5656 	.data = (void *)0,
5657 	.help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5658 	.tokens = {
5659 		(void *)&cmd_setpromisc_set,
5660 		(void *)&cmd_setpromisc_promisc,
5661 		(void *)&cmd_setpromisc_portnum,
5662 		(void *)&cmd_setpromisc_mode,
5663 		NULL,
5664 	},
5665 };
5666 
5667 /* *** SET ALLMULTI MODE *** */
5668 struct cmd_set_allmulti_mode_result {
5669 	cmdline_fixed_string_t set;
5670 	cmdline_fixed_string_t allmulti;
5671 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5672 	uint8_t port_num;                /* valid if "allports" argument == 0 */
5673 	cmdline_fixed_string_t mode;
5674 };
5675 
5676 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5677 					__attribute__((unused)) struct cmdline *cl,
5678 					void *allports)
5679 {
5680 	struct cmd_set_allmulti_mode_result *res = parsed_result;
5681 	int enable;
5682 	portid_t i;
5683 
5684 	if (!strcmp(res->mode, "on"))
5685 		enable = 1;
5686 	else
5687 		enable = 0;
5688 
5689 	/* all ports */
5690 	if (allports) {
5691 		RTE_ETH_FOREACH_DEV(i) {
5692 			if (enable)
5693 				rte_eth_allmulticast_enable(i);
5694 			else
5695 				rte_eth_allmulticast_disable(i);
5696 		}
5697 	}
5698 	else {
5699 		if (enable)
5700 			rte_eth_allmulticast_enable(res->port_num);
5701 		else
5702 			rte_eth_allmulticast_disable(res->port_num);
5703 	}
5704 }
5705 
5706 cmdline_parse_token_string_t cmd_setallmulti_set =
5707 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5708 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5709 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5710 				 "allmulti");
5711 cmdline_parse_token_string_t cmd_setallmulti_portall =
5712 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5713 				 "all");
5714 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5715 	TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5716 			      UINT8);
5717 cmdline_parse_token_string_t cmd_setallmulti_mode =
5718 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5719 				 "on#off");
5720 
5721 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5722 	.f = cmd_set_allmulti_mode_parsed,
5723 	.data = (void *)1,
5724 	.help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5725 	.tokens = {
5726 		(void *)&cmd_setallmulti_set,
5727 		(void *)&cmd_setallmulti_allmulti,
5728 		(void *)&cmd_setallmulti_portall,
5729 		(void *)&cmd_setallmulti_mode,
5730 		NULL,
5731 	},
5732 };
5733 
5734 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5735 	.f = cmd_set_allmulti_mode_parsed,
5736 	.data = (void *)0,
5737 	.help_str = "set allmulti <port_id> on|off: "
5738 		"Set allmulti mode on port_id",
5739 	.tokens = {
5740 		(void *)&cmd_setallmulti_set,
5741 		(void *)&cmd_setallmulti_allmulti,
5742 		(void *)&cmd_setallmulti_portnum,
5743 		(void *)&cmd_setallmulti_mode,
5744 		NULL,
5745 	},
5746 };
5747 
5748 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5749 struct cmd_link_flow_ctrl_set_result {
5750 	cmdline_fixed_string_t set;
5751 	cmdline_fixed_string_t flow_ctrl;
5752 	cmdline_fixed_string_t rx;
5753 	cmdline_fixed_string_t rx_lfc_mode;
5754 	cmdline_fixed_string_t tx;
5755 	cmdline_fixed_string_t tx_lfc_mode;
5756 	cmdline_fixed_string_t mac_ctrl_frame_fwd;
5757 	cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5758 	cmdline_fixed_string_t autoneg_str;
5759 	cmdline_fixed_string_t autoneg;
5760 	cmdline_fixed_string_t hw_str;
5761 	uint32_t high_water;
5762 	cmdline_fixed_string_t lw_str;
5763 	uint32_t low_water;
5764 	cmdline_fixed_string_t pt_str;
5765 	uint16_t pause_time;
5766 	cmdline_fixed_string_t xon_str;
5767 	uint16_t send_xon;
5768 	uint8_t  port_id;
5769 };
5770 
5771 cmdline_parse_token_string_t cmd_lfc_set_set =
5772 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5773 				set, "set");
5774 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5775 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5776 				flow_ctrl, "flow_ctrl");
5777 cmdline_parse_token_string_t cmd_lfc_set_rx =
5778 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5779 				rx, "rx");
5780 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5781 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5782 				rx_lfc_mode, "on#off");
5783 cmdline_parse_token_string_t cmd_lfc_set_tx =
5784 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5785 				tx, "tx");
5786 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5787 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5788 				tx_lfc_mode, "on#off");
5789 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5790 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5791 				hw_str, "high_water");
5792 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5793 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5794 				high_water, UINT32);
5795 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5796 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5797 				lw_str, "low_water");
5798 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5799 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5800 				low_water, UINT32);
5801 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5802 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5803 				pt_str, "pause_time");
5804 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5805 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5806 				pause_time, UINT16);
5807 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5808 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5809 				xon_str, "send_xon");
5810 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5811 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5812 				send_xon, UINT16);
5813 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5814 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5815 				mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5816 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5817 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5818 				mac_ctrl_frame_fwd_mode, "on#off");
5819 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5820 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5821 				autoneg_str, "autoneg");
5822 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5823 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5824 				autoneg, "on#off");
5825 cmdline_parse_token_num_t cmd_lfc_set_portid =
5826 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5827 				port_id, UINT8);
5828 
5829 /* forward declaration */
5830 static void
5831 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5832 			      void *data);
5833 
5834 cmdline_parse_inst_t cmd_link_flow_control_set = {
5835 	.f = cmd_link_flow_ctrl_set_parsed,
5836 	.data = NULL,
5837 	.help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5838 		"<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5839 		"autoneg on|off <port_id>: Configure the Ethernet flow control",
5840 	.tokens = {
5841 		(void *)&cmd_lfc_set_set,
5842 		(void *)&cmd_lfc_set_flow_ctrl,
5843 		(void *)&cmd_lfc_set_rx,
5844 		(void *)&cmd_lfc_set_rx_mode,
5845 		(void *)&cmd_lfc_set_tx,
5846 		(void *)&cmd_lfc_set_tx_mode,
5847 		(void *)&cmd_lfc_set_high_water,
5848 		(void *)&cmd_lfc_set_low_water,
5849 		(void *)&cmd_lfc_set_pause_time,
5850 		(void *)&cmd_lfc_set_send_xon,
5851 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5852 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5853 		(void *)&cmd_lfc_set_autoneg_str,
5854 		(void *)&cmd_lfc_set_autoneg,
5855 		(void *)&cmd_lfc_set_portid,
5856 		NULL,
5857 	},
5858 };
5859 
5860 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5861 	.f = cmd_link_flow_ctrl_set_parsed,
5862 	.data = (void *)&cmd_link_flow_control_set_rx,
5863 	.help_str = "set flow_ctrl rx on|off <port_id>: "
5864 		"Change rx flow control parameter",
5865 	.tokens = {
5866 		(void *)&cmd_lfc_set_set,
5867 		(void *)&cmd_lfc_set_flow_ctrl,
5868 		(void *)&cmd_lfc_set_rx,
5869 		(void *)&cmd_lfc_set_rx_mode,
5870 		(void *)&cmd_lfc_set_portid,
5871 		NULL,
5872 	},
5873 };
5874 
5875 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5876 	.f = cmd_link_flow_ctrl_set_parsed,
5877 	.data = (void *)&cmd_link_flow_control_set_tx,
5878 	.help_str = "set flow_ctrl tx on|off <port_id>: "
5879 		"Change tx flow control parameter",
5880 	.tokens = {
5881 		(void *)&cmd_lfc_set_set,
5882 		(void *)&cmd_lfc_set_flow_ctrl,
5883 		(void *)&cmd_lfc_set_tx,
5884 		(void *)&cmd_lfc_set_tx_mode,
5885 		(void *)&cmd_lfc_set_portid,
5886 		NULL,
5887 	},
5888 };
5889 
5890 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5891 	.f = cmd_link_flow_ctrl_set_parsed,
5892 	.data = (void *)&cmd_link_flow_control_set_hw,
5893 	.help_str = "set flow_ctrl high_water <value> <port_id>: "
5894 		"Change high water flow control parameter",
5895 	.tokens = {
5896 		(void *)&cmd_lfc_set_set,
5897 		(void *)&cmd_lfc_set_flow_ctrl,
5898 		(void *)&cmd_lfc_set_high_water_str,
5899 		(void *)&cmd_lfc_set_high_water,
5900 		(void *)&cmd_lfc_set_portid,
5901 		NULL,
5902 	},
5903 };
5904 
5905 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5906 	.f = cmd_link_flow_ctrl_set_parsed,
5907 	.data = (void *)&cmd_link_flow_control_set_lw,
5908 	.help_str = "set flow_ctrl low_water <value> <port_id>: "
5909 		"Change low water flow control parameter",
5910 	.tokens = {
5911 		(void *)&cmd_lfc_set_set,
5912 		(void *)&cmd_lfc_set_flow_ctrl,
5913 		(void *)&cmd_lfc_set_low_water_str,
5914 		(void *)&cmd_lfc_set_low_water,
5915 		(void *)&cmd_lfc_set_portid,
5916 		NULL,
5917 	},
5918 };
5919 
5920 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5921 	.f = cmd_link_flow_ctrl_set_parsed,
5922 	.data = (void *)&cmd_link_flow_control_set_pt,
5923 	.help_str = "set flow_ctrl pause_time <value> <port_id>: "
5924 		"Change pause time flow control parameter",
5925 	.tokens = {
5926 		(void *)&cmd_lfc_set_set,
5927 		(void *)&cmd_lfc_set_flow_ctrl,
5928 		(void *)&cmd_lfc_set_pause_time_str,
5929 		(void *)&cmd_lfc_set_pause_time,
5930 		(void *)&cmd_lfc_set_portid,
5931 		NULL,
5932 	},
5933 };
5934 
5935 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5936 	.f = cmd_link_flow_ctrl_set_parsed,
5937 	.data = (void *)&cmd_link_flow_control_set_xon,
5938 	.help_str = "set flow_ctrl send_xon <value> <port_id>: "
5939 		"Change send_xon flow control parameter",
5940 	.tokens = {
5941 		(void *)&cmd_lfc_set_set,
5942 		(void *)&cmd_lfc_set_flow_ctrl,
5943 		(void *)&cmd_lfc_set_send_xon_str,
5944 		(void *)&cmd_lfc_set_send_xon,
5945 		(void *)&cmd_lfc_set_portid,
5946 		NULL,
5947 	},
5948 };
5949 
5950 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5951 	.f = cmd_link_flow_ctrl_set_parsed,
5952 	.data = (void *)&cmd_link_flow_control_set_macfwd,
5953 	.help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
5954 		"Change mac ctrl fwd flow control parameter",
5955 	.tokens = {
5956 		(void *)&cmd_lfc_set_set,
5957 		(void *)&cmd_lfc_set_flow_ctrl,
5958 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5959 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5960 		(void *)&cmd_lfc_set_portid,
5961 		NULL,
5962 	},
5963 };
5964 
5965 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5966 	.f = cmd_link_flow_ctrl_set_parsed,
5967 	.data = (void *)&cmd_link_flow_control_set_autoneg,
5968 	.help_str = "set flow_ctrl autoneg on|off <port_id>: "
5969 		"Change autoneg flow control parameter",
5970 	.tokens = {
5971 		(void *)&cmd_lfc_set_set,
5972 		(void *)&cmd_lfc_set_flow_ctrl,
5973 		(void *)&cmd_lfc_set_autoneg_str,
5974 		(void *)&cmd_lfc_set_autoneg,
5975 		(void *)&cmd_lfc_set_portid,
5976 		NULL,
5977 	},
5978 };
5979 
5980 static void
5981 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
5982 			      __attribute__((unused)) struct cmdline *cl,
5983 			      void *data)
5984 {
5985 	struct cmd_link_flow_ctrl_set_result *res = parsed_result;
5986 	cmdline_parse_inst_t *cmd = data;
5987 	struct rte_eth_fc_conf fc_conf;
5988 	int rx_fc_en = 0;
5989 	int tx_fc_en = 0;
5990 	int ret;
5991 
5992 	/*
5993 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5994 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5995 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5996 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5997 	 */
5998 	static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5999 			{RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6000 	};
6001 
6002 	/* Partial command line, retrieve current configuration */
6003 	if (cmd) {
6004 		ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6005 		if (ret != 0) {
6006 			printf("cannot get current flow ctrl parameters, return"
6007 			       "code = %d\n", ret);
6008 			return;
6009 		}
6010 
6011 		if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6012 		    (fc_conf.mode == RTE_FC_FULL))
6013 			rx_fc_en = 1;
6014 		if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6015 		    (fc_conf.mode == RTE_FC_FULL))
6016 			tx_fc_en = 1;
6017 	}
6018 
6019 	if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6020 		rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6021 
6022 	if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6023 		tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6024 
6025 	fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6026 
6027 	if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6028 		fc_conf.high_water = res->high_water;
6029 
6030 	if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6031 		fc_conf.low_water = res->low_water;
6032 
6033 	if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6034 		fc_conf.pause_time = res->pause_time;
6035 
6036 	if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6037 		fc_conf.send_xon = res->send_xon;
6038 
6039 	if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6040 		if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6041 			fc_conf.mac_ctrl_frame_fwd = 1;
6042 		else
6043 			fc_conf.mac_ctrl_frame_fwd = 0;
6044 	}
6045 
6046 	if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6047 		fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6048 
6049 	ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6050 	if (ret != 0)
6051 		printf("bad flow contrl parameter, return code = %d \n", ret);
6052 }
6053 
6054 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6055 struct cmd_priority_flow_ctrl_set_result {
6056 	cmdline_fixed_string_t set;
6057 	cmdline_fixed_string_t pfc_ctrl;
6058 	cmdline_fixed_string_t rx;
6059 	cmdline_fixed_string_t rx_pfc_mode;
6060 	cmdline_fixed_string_t tx;
6061 	cmdline_fixed_string_t tx_pfc_mode;
6062 	uint32_t high_water;
6063 	uint32_t low_water;
6064 	uint16_t pause_time;
6065 	uint8_t  priority;
6066 	uint8_t  port_id;
6067 };
6068 
6069 static void
6070 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6071 		       __attribute__((unused)) struct cmdline *cl,
6072 		       __attribute__((unused)) void *data)
6073 {
6074 	struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6075 	struct rte_eth_pfc_conf pfc_conf;
6076 	int rx_fc_enable, tx_fc_enable;
6077 	int ret;
6078 
6079 	/*
6080 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6081 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6082 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6083 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6084 	 */
6085 	static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6086 			{RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6087 	};
6088 
6089 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6090 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6091 	pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6092 	pfc_conf.fc.high_water = res->high_water;
6093 	pfc_conf.fc.low_water  = res->low_water;
6094 	pfc_conf.fc.pause_time = res->pause_time;
6095 	pfc_conf.priority      = res->priority;
6096 
6097 	ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6098 	if (ret != 0)
6099 		printf("bad priority flow contrl parameter, return code = %d \n", ret);
6100 }
6101 
6102 cmdline_parse_token_string_t cmd_pfc_set_set =
6103 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6104 				set, "set");
6105 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6106 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6107 				pfc_ctrl, "pfc_ctrl");
6108 cmdline_parse_token_string_t cmd_pfc_set_rx =
6109 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6110 				rx, "rx");
6111 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6112 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6113 				rx_pfc_mode, "on#off");
6114 cmdline_parse_token_string_t cmd_pfc_set_tx =
6115 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6116 				tx, "tx");
6117 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6118 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6119 				tx_pfc_mode, "on#off");
6120 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6121 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6122 				high_water, UINT32);
6123 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6124 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6125 				low_water, UINT32);
6126 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6127 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6128 				pause_time, UINT16);
6129 cmdline_parse_token_num_t cmd_pfc_set_priority =
6130 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6131 				priority, UINT8);
6132 cmdline_parse_token_num_t cmd_pfc_set_portid =
6133 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6134 				port_id, UINT8);
6135 
6136 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6137 	.f = cmd_priority_flow_ctrl_set_parsed,
6138 	.data = NULL,
6139 	.help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6140 		"<pause_time> <priority> <port_id>: "
6141 		"Configure the Ethernet priority flow control",
6142 	.tokens = {
6143 		(void *)&cmd_pfc_set_set,
6144 		(void *)&cmd_pfc_set_flow_ctrl,
6145 		(void *)&cmd_pfc_set_rx,
6146 		(void *)&cmd_pfc_set_rx_mode,
6147 		(void *)&cmd_pfc_set_tx,
6148 		(void *)&cmd_pfc_set_tx_mode,
6149 		(void *)&cmd_pfc_set_high_water,
6150 		(void *)&cmd_pfc_set_low_water,
6151 		(void *)&cmd_pfc_set_pause_time,
6152 		(void *)&cmd_pfc_set_priority,
6153 		(void *)&cmd_pfc_set_portid,
6154 		NULL,
6155 	},
6156 };
6157 
6158 /* *** RESET CONFIGURATION *** */
6159 struct cmd_reset_result {
6160 	cmdline_fixed_string_t reset;
6161 	cmdline_fixed_string_t def;
6162 };
6163 
6164 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6165 			     struct cmdline *cl,
6166 			     __attribute__((unused)) void *data)
6167 {
6168 	cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6169 	set_def_fwd_config();
6170 }
6171 
6172 cmdline_parse_token_string_t cmd_reset_set =
6173 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6174 cmdline_parse_token_string_t cmd_reset_def =
6175 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6176 				 "default");
6177 
6178 cmdline_parse_inst_t cmd_reset = {
6179 	.f = cmd_reset_parsed,
6180 	.data = NULL,
6181 	.help_str = "set default: Reset default forwarding configuration",
6182 	.tokens = {
6183 		(void *)&cmd_reset_set,
6184 		(void *)&cmd_reset_def,
6185 		NULL,
6186 	},
6187 };
6188 
6189 /* *** START FORWARDING *** */
6190 struct cmd_start_result {
6191 	cmdline_fixed_string_t start;
6192 };
6193 
6194 cmdline_parse_token_string_t cmd_start_start =
6195 	TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6196 
6197 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6198 			     __attribute__((unused)) struct cmdline *cl,
6199 			     __attribute__((unused)) void *data)
6200 {
6201 	start_packet_forwarding(0);
6202 }
6203 
6204 cmdline_parse_inst_t cmd_start = {
6205 	.f = cmd_start_parsed,
6206 	.data = NULL,
6207 	.help_str = "start: Start packet forwarding",
6208 	.tokens = {
6209 		(void *)&cmd_start_start,
6210 		NULL,
6211 	},
6212 };
6213 
6214 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6215 struct cmd_start_tx_first_result {
6216 	cmdline_fixed_string_t start;
6217 	cmdline_fixed_string_t tx_first;
6218 };
6219 
6220 static void
6221 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6222 			  __attribute__((unused)) struct cmdline *cl,
6223 			  __attribute__((unused)) void *data)
6224 {
6225 	start_packet_forwarding(1);
6226 }
6227 
6228 cmdline_parse_token_string_t cmd_start_tx_first_start =
6229 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6230 				 "start");
6231 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6232 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6233 				 tx_first, "tx_first");
6234 
6235 cmdline_parse_inst_t cmd_start_tx_first = {
6236 	.f = cmd_start_tx_first_parsed,
6237 	.data = NULL,
6238 	.help_str = "start tx_first: Start packet forwarding, "
6239 		"after sending 1 burst of packets",
6240 	.tokens = {
6241 		(void *)&cmd_start_tx_first_start,
6242 		(void *)&cmd_start_tx_first_tx_first,
6243 		NULL,
6244 	},
6245 };
6246 
6247 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6248 struct cmd_start_tx_first_n_result {
6249 	cmdline_fixed_string_t start;
6250 	cmdline_fixed_string_t tx_first;
6251 	uint32_t tx_num;
6252 };
6253 
6254 static void
6255 cmd_start_tx_first_n_parsed(void *parsed_result,
6256 			  __attribute__((unused)) struct cmdline *cl,
6257 			  __attribute__((unused)) void *data)
6258 {
6259 	struct cmd_start_tx_first_n_result *res = parsed_result;
6260 
6261 	start_packet_forwarding(res->tx_num);
6262 }
6263 
6264 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6265 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6266 			start, "start");
6267 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6268 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6269 			tx_first, "tx_first");
6270 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6271 	TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6272 			tx_num, UINT32);
6273 
6274 cmdline_parse_inst_t cmd_start_tx_first_n = {
6275 	.f = cmd_start_tx_first_n_parsed,
6276 	.data = NULL,
6277 	.help_str = "start tx_first <num>: "
6278 		"packet forwarding, after sending <num> bursts of packets",
6279 	.tokens = {
6280 		(void *)&cmd_start_tx_first_n_start,
6281 		(void *)&cmd_start_tx_first_n_tx_first,
6282 		(void *)&cmd_start_tx_first_n_tx_num,
6283 		NULL,
6284 	},
6285 };
6286 
6287 /* *** SET LINK UP *** */
6288 struct cmd_set_link_up_result {
6289 	cmdline_fixed_string_t set;
6290 	cmdline_fixed_string_t link_up;
6291 	cmdline_fixed_string_t port;
6292 	uint8_t port_id;
6293 };
6294 
6295 cmdline_parse_token_string_t cmd_set_link_up_set =
6296 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6297 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6298 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6299 				"link-up");
6300 cmdline_parse_token_string_t cmd_set_link_up_port =
6301 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6302 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6303 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
6304 
6305 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6306 			     __attribute__((unused)) struct cmdline *cl,
6307 			     __attribute__((unused)) void *data)
6308 {
6309 	struct cmd_set_link_up_result *res = parsed_result;
6310 	dev_set_link_up(res->port_id);
6311 }
6312 
6313 cmdline_parse_inst_t cmd_set_link_up = {
6314 	.f = cmd_set_link_up_parsed,
6315 	.data = NULL,
6316 	.help_str = "set link-up port <port id>",
6317 	.tokens = {
6318 		(void *)&cmd_set_link_up_set,
6319 		(void *)&cmd_set_link_up_link_up,
6320 		(void *)&cmd_set_link_up_port,
6321 		(void *)&cmd_set_link_up_port_id,
6322 		NULL,
6323 	},
6324 };
6325 
6326 /* *** SET LINK DOWN *** */
6327 struct cmd_set_link_down_result {
6328 	cmdline_fixed_string_t set;
6329 	cmdline_fixed_string_t link_down;
6330 	cmdline_fixed_string_t port;
6331 	uint8_t port_id;
6332 };
6333 
6334 cmdline_parse_token_string_t cmd_set_link_down_set =
6335 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6336 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6337 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6338 				"link-down");
6339 cmdline_parse_token_string_t cmd_set_link_down_port =
6340 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6341 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6342 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
6343 
6344 static void cmd_set_link_down_parsed(
6345 				__attribute__((unused)) void *parsed_result,
6346 				__attribute__((unused)) struct cmdline *cl,
6347 				__attribute__((unused)) void *data)
6348 {
6349 	struct cmd_set_link_down_result *res = parsed_result;
6350 	dev_set_link_down(res->port_id);
6351 }
6352 
6353 cmdline_parse_inst_t cmd_set_link_down = {
6354 	.f = cmd_set_link_down_parsed,
6355 	.data = NULL,
6356 	.help_str = "set link-down port <port id>",
6357 	.tokens = {
6358 		(void *)&cmd_set_link_down_set,
6359 		(void *)&cmd_set_link_down_link_down,
6360 		(void *)&cmd_set_link_down_port,
6361 		(void *)&cmd_set_link_down_port_id,
6362 		NULL,
6363 	},
6364 };
6365 
6366 /* *** SHOW CFG *** */
6367 struct cmd_showcfg_result {
6368 	cmdline_fixed_string_t show;
6369 	cmdline_fixed_string_t cfg;
6370 	cmdline_fixed_string_t what;
6371 };
6372 
6373 static void cmd_showcfg_parsed(void *parsed_result,
6374 			       __attribute__((unused)) struct cmdline *cl,
6375 			       __attribute__((unused)) void *data)
6376 {
6377 	struct cmd_showcfg_result *res = parsed_result;
6378 	if (!strcmp(res->what, "rxtx"))
6379 		rxtx_config_display();
6380 	else if (!strcmp(res->what, "cores"))
6381 		fwd_lcores_config_display();
6382 	else if (!strcmp(res->what, "fwd"))
6383 		pkt_fwd_config_display(&cur_fwd_config);
6384 	else if (!strcmp(res->what, "txpkts"))
6385 		show_tx_pkt_segments();
6386 }
6387 
6388 cmdline_parse_token_string_t cmd_showcfg_show =
6389 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6390 cmdline_parse_token_string_t cmd_showcfg_port =
6391 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6392 cmdline_parse_token_string_t cmd_showcfg_what =
6393 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6394 				 "rxtx#cores#fwd#txpkts");
6395 
6396 cmdline_parse_inst_t cmd_showcfg = {
6397 	.f = cmd_showcfg_parsed,
6398 	.data = NULL,
6399 	.help_str = "show config rxtx|cores|fwd|txpkts",
6400 	.tokens = {
6401 		(void *)&cmd_showcfg_show,
6402 		(void *)&cmd_showcfg_port,
6403 		(void *)&cmd_showcfg_what,
6404 		NULL,
6405 	},
6406 };
6407 
6408 /* *** SHOW ALL PORT INFO *** */
6409 struct cmd_showportall_result {
6410 	cmdline_fixed_string_t show;
6411 	cmdline_fixed_string_t port;
6412 	cmdline_fixed_string_t what;
6413 	cmdline_fixed_string_t all;
6414 };
6415 
6416 static void cmd_showportall_parsed(void *parsed_result,
6417 				__attribute__((unused)) struct cmdline *cl,
6418 				__attribute__((unused)) void *data)
6419 {
6420 	portid_t i;
6421 
6422 	struct cmd_showportall_result *res = parsed_result;
6423 	if (!strcmp(res->show, "clear")) {
6424 		if (!strcmp(res->what, "stats"))
6425 			RTE_ETH_FOREACH_DEV(i)
6426 				nic_stats_clear(i);
6427 		else if (!strcmp(res->what, "xstats"))
6428 			RTE_ETH_FOREACH_DEV(i)
6429 				nic_xstats_clear(i);
6430 	} else if (!strcmp(res->what, "info"))
6431 		RTE_ETH_FOREACH_DEV(i)
6432 			port_infos_display(i);
6433 	else if (!strcmp(res->what, "stats"))
6434 		RTE_ETH_FOREACH_DEV(i)
6435 			nic_stats_display(i);
6436 	else if (!strcmp(res->what, "xstats"))
6437 		RTE_ETH_FOREACH_DEV(i)
6438 			nic_xstats_display(i);
6439 	else if (!strcmp(res->what, "fdir"))
6440 		RTE_ETH_FOREACH_DEV(i)
6441 			fdir_get_infos(i);
6442 	else if (!strcmp(res->what, "stat_qmap"))
6443 		RTE_ETH_FOREACH_DEV(i)
6444 			nic_stats_mapping_display(i);
6445 	else if (!strcmp(res->what, "dcb_tc"))
6446 		RTE_ETH_FOREACH_DEV(i)
6447 			port_dcb_info_display(i);
6448 	else if (!strcmp(res->what, "cap"))
6449 		RTE_ETH_FOREACH_DEV(i)
6450 			port_offload_cap_display(i);
6451 }
6452 
6453 cmdline_parse_token_string_t cmd_showportall_show =
6454 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6455 				 "show#clear");
6456 cmdline_parse_token_string_t cmd_showportall_port =
6457 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6458 cmdline_parse_token_string_t cmd_showportall_what =
6459 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6460 				 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6461 cmdline_parse_token_string_t cmd_showportall_all =
6462 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6463 cmdline_parse_inst_t cmd_showportall = {
6464 	.f = cmd_showportall_parsed,
6465 	.data = NULL,
6466 	.help_str = "show|clear port "
6467 		"info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6468 	.tokens = {
6469 		(void *)&cmd_showportall_show,
6470 		(void *)&cmd_showportall_port,
6471 		(void *)&cmd_showportall_what,
6472 		(void *)&cmd_showportall_all,
6473 		NULL,
6474 	},
6475 };
6476 
6477 /* *** SHOW PORT INFO *** */
6478 struct cmd_showport_result {
6479 	cmdline_fixed_string_t show;
6480 	cmdline_fixed_string_t port;
6481 	cmdline_fixed_string_t what;
6482 	uint8_t portnum;
6483 };
6484 
6485 static void cmd_showport_parsed(void *parsed_result,
6486 				__attribute__((unused)) struct cmdline *cl,
6487 				__attribute__((unused)) void *data)
6488 {
6489 	struct cmd_showport_result *res = parsed_result;
6490 	if (!strcmp(res->show, "clear")) {
6491 		if (!strcmp(res->what, "stats"))
6492 			nic_stats_clear(res->portnum);
6493 		else if (!strcmp(res->what, "xstats"))
6494 			nic_xstats_clear(res->portnum);
6495 	} else if (!strcmp(res->what, "info"))
6496 		port_infos_display(res->portnum);
6497 	else if (!strcmp(res->what, "stats"))
6498 		nic_stats_display(res->portnum);
6499 	else if (!strcmp(res->what, "xstats"))
6500 		nic_xstats_display(res->portnum);
6501 	else if (!strcmp(res->what, "fdir"))
6502 		 fdir_get_infos(res->portnum);
6503 	else if (!strcmp(res->what, "stat_qmap"))
6504 		nic_stats_mapping_display(res->portnum);
6505 	else if (!strcmp(res->what, "dcb_tc"))
6506 		port_dcb_info_display(res->portnum);
6507 	else if (!strcmp(res->what, "cap"))
6508 		port_offload_cap_display(res->portnum);
6509 }
6510 
6511 cmdline_parse_token_string_t cmd_showport_show =
6512 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6513 				 "show#clear");
6514 cmdline_parse_token_string_t cmd_showport_port =
6515 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6516 cmdline_parse_token_string_t cmd_showport_what =
6517 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6518 				 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6519 cmdline_parse_token_num_t cmd_showport_portnum =
6520 	TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
6521 
6522 cmdline_parse_inst_t cmd_showport = {
6523 	.f = cmd_showport_parsed,
6524 	.data = NULL,
6525 	.help_str = "show|clear port "
6526 		"info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6527 		"<port_id>",
6528 	.tokens = {
6529 		(void *)&cmd_showport_show,
6530 		(void *)&cmd_showport_port,
6531 		(void *)&cmd_showport_what,
6532 		(void *)&cmd_showport_portnum,
6533 		NULL,
6534 	},
6535 };
6536 
6537 /* *** SHOW QUEUE INFO *** */
6538 struct cmd_showqueue_result {
6539 	cmdline_fixed_string_t show;
6540 	cmdline_fixed_string_t type;
6541 	cmdline_fixed_string_t what;
6542 	uint8_t portnum;
6543 	uint16_t queuenum;
6544 };
6545 
6546 static void
6547 cmd_showqueue_parsed(void *parsed_result,
6548 	__attribute__((unused)) struct cmdline *cl,
6549 	__attribute__((unused)) void *data)
6550 {
6551 	struct cmd_showqueue_result *res = parsed_result;
6552 
6553 	if (!strcmp(res->type, "rxq"))
6554 		rx_queue_infos_display(res->portnum, res->queuenum);
6555 	else if (!strcmp(res->type, "txq"))
6556 		tx_queue_infos_display(res->portnum, res->queuenum);
6557 }
6558 
6559 cmdline_parse_token_string_t cmd_showqueue_show =
6560 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6561 cmdline_parse_token_string_t cmd_showqueue_type =
6562 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6563 cmdline_parse_token_string_t cmd_showqueue_what =
6564 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6565 cmdline_parse_token_num_t cmd_showqueue_portnum =
6566 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
6567 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6568 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6569 
6570 cmdline_parse_inst_t cmd_showqueue = {
6571 	.f = cmd_showqueue_parsed,
6572 	.data = NULL,
6573 	.help_str = "show rxq|txq info <port_id> <queue_id>",
6574 	.tokens = {
6575 		(void *)&cmd_showqueue_show,
6576 		(void *)&cmd_showqueue_type,
6577 		(void *)&cmd_showqueue_what,
6578 		(void *)&cmd_showqueue_portnum,
6579 		(void *)&cmd_showqueue_queuenum,
6580 		NULL,
6581 	},
6582 };
6583 
6584 /* *** READ PORT REGISTER *** */
6585 struct cmd_read_reg_result {
6586 	cmdline_fixed_string_t read;
6587 	cmdline_fixed_string_t reg;
6588 	uint8_t port_id;
6589 	uint32_t reg_off;
6590 };
6591 
6592 static void
6593 cmd_read_reg_parsed(void *parsed_result,
6594 		    __attribute__((unused)) struct cmdline *cl,
6595 		    __attribute__((unused)) void *data)
6596 {
6597 	struct cmd_read_reg_result *res = parsed_result;
6598 	port_reg_display(res->port_id, res->reg_off);
6599 }
6600 
6601 cmdline_parse_token_string_t cmd_read_reg_read =
6602 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6603 cmdline_parse_token_string_t cmd_read_reg_reg =
6604 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6605 cmdline_parse_token_num_t cmd_read_reg_port_id =
6606 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
6607 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6608 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6609 
6610 cmdline_parse_inst_t cmd_read_reg = {
6611 	.f = cmd_read_reg_parsed,
6612 	.data = NULL,
6613 	.help_str = "read reg <port_id> <reg_off>",
6614 	.tokens = {
6615 		(void *)&cmd_read_reg_read,
6616 		(void *)&cmd_read_reg_reg,
6617 		(void *)&cmd_read_reg_port_id,
6618 		(void *)&cmd_read_reg_reg_off,
6619 		NULL,
6620 	},
6621 };
6622 
6623 /* *** READ PORT REGISTER BIT FIELD *** */
6624 struct cmd_read_reg_bit_field_result {
6625 	cmdline_fixed_string_t read;
6626 	cmdline_fixed_string_t regfield;
6627 	uint8_t port_id;
6628 	uint32_t reg_off;
6629 	uint8_t bit1_pos;
6630 	uint8_t bit2_pos;
6631 };
6632 
6633 static void
6634 cmd_read_reg_bit_field_parsed(void *parsed_result,
6635 			      __attribute__((unused)) struct cmdline *cl,
6636 			      __attribute__((unused)) void *data)
6637 {
6638 	struct cmd_read_reg_bit_field_result *res = parsed_result;
6639 	port_reg_bit_field_display(res->port_id, res->reg_off,
6640 				   res->bit1_pos, res->bit2_pos);
6641 }
6642 
6643 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6644 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6645 				 "read");
6646 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6647 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6648 				 regfield, "regfield");
6649 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6650 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6651 			      UINT8);
6652 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6653 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6654 			      UINT32);
6655 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6656 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6657 			      UINT8);
6658 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6659 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6660 			      UINT8);
6661 
6662 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6663 	.f = cmd_read_reg_bit_field_parsed,
6664 	.data = NULL,
6665 	.help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6666 	"Read register bit field between bit_x and bit_y included",
6667 	.tokens = {
6668 		(void *)&cmd_read_reg_bit_field_read,
6669 		(void *)&cmd_read_reg_bit_field_regfield,
6670 		(void *)&cmd_read_reg_bit_field_port_id,
6671 		(void *)&cmd_read_reg_bit_field_reg_off,
6672 		(void *)&cmd_read_reg_bit_field_bit1_pos,
6673 		(void *)&cmd_read_reg_bit_field_bit2_pos,
6674 		NULL,
6675 	},
6676 };
6677 
6678 /* *** READ PORT REGISTER BIT *** */
6679 struct cmd_read_reg_bit_result {
6680 	cmdline_fixed_string_t read;
6681 	cmdline_fixed_string_t regbit;
6682 	uint8_t port_id;
6683 	uint32_t reg_off;
6684 	uint8_t bit_pos;
6685 };
6686 
6687 static void
6688 cmd_read_reg_bit_parsed(void *parsed_result,
6689 			__attribute__((unused)) struct cmdline *cl,
6690 			__attribute__((unused)) void *data)
6691 {
6692 	struct cmd_read_reg_bit_result *res = parsed_result;
6693 	port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6694 }
6695 
6696 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6697 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6698 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6699 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6700 				 regbit, "regbit");
6701 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6702 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
6703 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6704 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6705 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6706 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6707 
6708 cmdline_parse_inst_t cmd_read_reg_bit = {
6709 	.f = cmd_read_reg_bit_parsed,
6710 	.data = NULL,
6711 	.help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6712 	.tokens = {
6713 		(void *)&cmd_read_reg_bit_read,
6714 		(void *)&cmd_read_reg_bit_regbit,
6715 		(void *)&cmd_read_reg_bit_port_id,
6716 		(void *)&cmd_read_reg_bit_reg_off,
6717 		(void *)&cmd_read_reg_bit_bit_pos,
6718 		NULL,
6719 	},
6720 };
6721 
6722 /* *** WRITE PORT REGISTER *** */
6723 struct cmd_write_reg_result {
6724 	cmdline_fixed_string_t write;
6725 	cmdline_fixed_string_t reg;
6726 	uint8_t port_id;
6727 	uint32_t reg_off;
6728 	uint32_t value;
6729 };
6730 
6731 static void
6732 cmd_write_reg_parsed(void *parsed_result,
6733 		     __attribute__((unused)) struct cmdline *cl,
6734 		     __attribute__((unused)) void *data)
6735 {
6736 	struct cmd_write_reg_result *res = parsed_result;
6737 	port_reg_set(res->port_id, res->reg_off, res->value);
6738 }
6739 
6740 cmdline_parse_token_string_t cmd_write_reg_write =
6741 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6742 cmdline_parse_token_string_t cmd_write_reg_reg =
6743 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6744 cmdline_parse_token_num_t cmd_write_reg_port_id =
6745 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
6746 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6747 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6748 cmdline_parse_token_num_t cmd_write_reg_value =
6749 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6750 
6751 cmdline_parse_inst_t cmd_write_reg = {
6752 	.f = cmd_write_reg_parsed,
6753 	.data = NULL,
6754 	.help_str = "write reg <port_id> <reg_off> <reg_value>",
6755 	.tokens = {
6756 		(void *)&cmd_write_reg_write,
6757 		(void *)&cmd_write_reg_reg,
6758 		(void *)&cmd_write_reg_port_id,
6759 		(void *)&cmd_write_reg_reg_off,
6760 		(void *)&cmd_write_reg_value,
6761 		NULL,
6762 	},
6763 };
6764 
6765 /* *** WRITE PORT REGISTER BIT FIELD *** */
6766 struct cmd_write_reg_bit_field_result {
6767 	cmdline_fixed_string_t write;
6768 	cmdline_fixed_string_t regfield;
6769 	uint8_t port_id;
6770 	uint32_t reg_off;
6771 	uint8_t bit1_pos;
6772 	uint8_t bit2_pos;
6773 	uint32_t value;
6774 };
6775 
6776 static void
6777 cmd_write_reg_bit_field_parsed(void *parsed_result,
6778 			       __attribute__((unused)) struct cmdline *cl,
6779 			       __attribute__((unused)) void *data)
6780 {
6781 	struct cmd_write_reg_bit_field_result *res = parsed_result;
6782 	port_reg_bit_field_set(res->port_id, res->reg_off,
6783 			  res->bit1_pos, res->bit2_pos, res->value);
6784 }
6785 
6786 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6787 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6788 				 "write");
6789 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6790 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6791 				 regfield, "regfield");
6792 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6793 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6794 			      UINT8);
6795 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6796 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6797 			      UINT32);
6798 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6799 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6800 			      UINT8);
6801 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6802 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6803 			      UINT8);
6804 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6805 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6806 			      UINT32);
6807 
6808 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6809 	.f = cmd_write_reg_bit_field_parsed,
6810 	.data = NULL,
6811 	.help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6812 		"<reg_value>: "
6813 		"Set register bit field between bit_x and bit_y included",
6814 	.tokens = {
6815 		(void *)&cmd_write_reg_bit_field_write,
6816 		(void *)&cmd_write_reg_bit_field_regfield,
6817 		(void *)&cmd_write_reg_bit_field_port_id,
6818 		(void *)&cmd_write_reg_bit_field_reg_off,
6819 		(void *)&cmd_write_reg_bit_field_bit1_pos,
6820 		(void *)&cmd_write_reg_bit_field_bit2_pos,
6821 		(void *)&cmd_write_reg_bit_field_value,
6822 		NULL,
6823 	},
6824 };
6825 
6826 /* *** WRITE PORT REGISTER BIT *** */
6827 struct cmd_write_reg_bit_result {
6828 	cmdline_fixed_string_t write;
6829 	cmdline_fixed_string_t regbit;
6830 	uint8_t port_id;
6831 	uint32_t reg_off;
6832 	uint8_t bit_pos;
6833 	uint8_t value;
6834 };
6835 
6836 static void
6837 cmd_write_reg_bit_parsed(void *parsed_result,
6838 			 __attribute__((unused)) struct cmdline *cl,
6839 			 __attribute__((unused)) void *data)
6840 {
6841 	struct cmd_write_reg_bit_result *res = parsed_result;
6842 	port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6843 }
6844 
6845 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6846 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6847 				 "write");
6848 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6849 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6850 				 regbit, "regbit");
6851 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6852 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
6853 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6854 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6855 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6856 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6857 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6858 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6859 
6860 cmdline_parse_inst_t cmd_write_reg_bit = {
6861 	.f = cmd_write_reg_bit_parsed,
6862 	.data = NULL,
6863 	.help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6864 		"0 <= bit_x <= 31",
6865 	.tokens = {
6866 		(void *)&cmd_write_reg_bit_write,
6867 		(void *)&cmd_write_reg_bit_regbit,
6868 		(void *)&cmd_write_reg_bit_port_id,
6869 		(void *)&cmd_write_reg_bit_reg_off,
6870 		(void *)&cmd_write_reg_bit_bit_pos,
6871 		(void *)&cmd_write_reg_bit_value,
6872 		NULL,
6873 	},
6874 };
6875 
6876 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6877 struct cmd_read_rxd_txd_result {
6878 	cmdline_fixed_string_t read;
6879 	cmdline_fixed_string_t rxd_txd;
6880 	uint8_t port_id;
6881 	uint16_t queue_id;
6882 	uint16_t desc_id;
6883 };
6884 
6885 static void
6886 cmd_read_rxd_txd_parsed(void *parsed_result,
6887 			__attribute__((unused)) struct cmdline *cl,
6888 			__attribute__((unused)) void *data)
6889 {
6890 	struct cmd_read_rxd_txd_result *res = parsed_result;
6891 
6892 	if (!strcmp(res->rxd_txd, "rxd"))
6893 		rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6894 	else if (!strcmp(res->rxd_txd, "txd"))
6895 		tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6896 }
6897 
6898 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6899 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6900 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6901 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6902 				 "rxd#txd");
6903 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6904 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
6905 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6906 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6907 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6908 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6909 
6910 cmdline_parse_inst_t cmd_read_rxd_txd = {
6911 	.f = cmd_read_rxd_txd_parsed,
6912 	.data = NULL,
6913 	.help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6914 	.tokens = {
6915 		(void *)&cmd_read_rxd_txd_read,
6916 		(void *)&cmd_read_rxd_txd_rxd_txd,
6917 		(void *)&cmd_read_rxd_txd_port_id,
6918 		(void *)&cmd_read_rxd_txd_queue_id,
6919 		(void *)&cmd_read_rxd_txd_desc_id,
6920 		NULL,
6921 	},
6922 };
6923 
6924 /* *** QUIT *** */
6925 struct cmd_quit_result {
6926 	cmdline_fixed_string_t quit;
6927 };
6928 
6929 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6930 			    struct cmdline *cl,
6931 			    __attribute__((unused)) void *data)
6932 {
6933 	pmd_test_exit();
6934 	cmdline_quit(cl);
6935 }
6936 
6937 cmdline_parse_token_string_t cmd_quit_quit =
6938 	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6939 
6940 cmdline_parse_inst_t cmd_quit = {
6941 	.f = cmd_quit_parsed,
6942 	.data = NULL,
6943 	.help_str = "quit: Exit application",
6944 	.tokens = {
6945 		(void *)&cmd_quit_quit,
6946 		NULL,
6947 	},
6948 };
6949 
6950 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
6951 struct cmd_mac_addr_result {
6952 	cmdline_fixed_string_t mac_addr_cmd;
6953 	cmdline_fixed_string_t what;
6954 	uint8_t port_num;
6955 	struct ether_addr address;
6956 };
6957 
6958 static void cmd_mac_addr_parsed(void *parsed_result,
6959 		__attribute__((unused)) struct cmdline *cl,
6960 		__attribute__((unused)) void *data)
6961 {
6962 	struct cmd_mac_addr_result *res = parsed_result;
6963 	int ret;
6964 
6965 	if (strcmp(res->what, "add") == 0)
6966 		ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
6967 	else if (strcmp(res->what, "set") == 0)
6968 		ret = rte_eth_dev_default_mac_addr_set(res->port_num,
6969 						       &res->address);
6970 	else
6971 		ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
6972 
6973 	/* check the return value and print it if is < 0 */
6974 	if(ret < 0)
6975 		printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
6976 
6977 }
6978 
6979 cmdline_parse_token_string_t cmd_mac_addr_cmd =
6980 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
6981 				"mac_addr");
6982 cmdline_parse_token_string_t cmd_mac_addr_what =
6983 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
6984 				"add#remove#set");
6985 cmdline_parse_token_num_t cmd_mac_addr_portnum =
6986 		TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
6987 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
6988 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
6989 
6990 cmdline_parse_inst_t cmd_mac_addr = {
6991 	.f = cmd_mac_addr_parsed,
6992 	.data = (void *)0,
6993 	.help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
6994 			"Add/Remove/Set MAC address on port_id",
6995 	.tokens = {
6996 		(void *)&cmd_mac_addr_cmd,
6997 		(void *)&cmd_mac_addr_what,
6998 		(void *)&cmd_mac_addr_portnum,
6999 		(void *)&cmd_mac_addr_addr,
7000 		NULL,
7001 	},
7002 };
7003 
7004 
7005 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7006 struct cmd_set_qmap_result {
7007 	cmdline_fixed_string_t set;
7008 	cmdline_fixed_string_t qmap;
7009 	cmdline_fixed_string_t what;
7010 	uint8_t port_id;
7011 	uint16_t queue_id;
7012 	uint8_t map_value;
7013 };
7014 
7015 static void
7016 cmd_set_qmap_parsed(void *parsed_result,
7017 		       __attribute__((unused)) struct cmdline *cl,
7018 		       __attribute__((unused)) void *data)
7019 {
7020 	struct cmd_set_qmap_result *res = parsed_result;
7021 	int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7022 
7023 	set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7024 }
7025 
7026 cmdline_parse_token_string_t cmd_setqmap_set =
7027 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7028 				 set, "set");
7029 cmdline_parse_token_string_t cmd_setqmap_qmap =
7030 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7031 				 qmap, "stat_qmap");
7032 cmdline_parse_token_string_t cmd_setqmap_what =
7033 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7034 				 what, "tx#rx");
7035 cmdline_parse_token_num_t cmd_setqmap_portid =
7036 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7037 			      port_id, UINT8);
7038 cmdline_parse_token_num_t cmd_setqmap_queueid =
7039 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7040 			      queue_id, UINT16);
7041 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7042 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7043 			      map_value, UINT8);
7044 
7045 cmdline_parse_inst_t cmd_set_qmap = {
7046 	.f = cmd_set_qmap_parsed,
7047 	.data = NULL,
7048 	.help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7049 		"Set statistics mapping value on tx|rx queue_id of port_id",
7050 	.tokens = {
7051 		(void *)&cmd_setqmap_set,
7052 		(void *)&cmd_setqmap_qmap,
7053 		(void *)&cmd_setqmap_what,
7054 		(void *)&cmd_setqmap_portid,
7055 		(void *)&cmd_setqmap_queueid,
7056 		(void *)&cmd_setqmap_mapvalue,
7057 		NULL,
7058 	},
7059 };
7060 
7061 /* *** CONFIGURE UNICAST HASH TABLE *** */
7062 struct cmd_set_uc_hash_table {
7063 	cmdline_fixed_string_t set;
7064 	cmdline_fixed_string_t port;
7065 	uint8_t port_id;
7066 	cmdline_fixed_string_t what;
7067 	struct ether_addr address;
7068 	cmdline_fixed_string_t mode;
7069 };
7070 
7071 static void
7072 cmd_set_uc_hash_parsed(void *parsed_result,
7073 		       __attribute__((unused)) struct cmdline *cl,
7074 		       __attribute__((unused)) void *data)
7075 {
7076 	int ret=0;
7077 	struct cmd_set_uc_hash_table *res = parsed_result;
7078 
7079 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7080 
7081 	if (strcmp(res->what, "uta") == 0)
7082 		ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7083 						&res->address,(uint8_t)is_on);
7084 	if (ret < 0)
7085 		printf("bad unicast hash table parameter, return code = %d \n", ret);
7086 
7087 }
7088 
7089 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7090 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7091 				 set, "set");
7092 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7093 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7094 				 port, "port");
7095 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7096 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7097 			      port_id, UINT8);
7098 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7099 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7100 				 what, "uta");
7101 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7102 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7103 				address);
7104 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7105 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7106 				 mode, "on#off");
7107 
7108 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7109 	.f = cmd_set_uc_hash_parsed,
7110 	.data = NULL,
7111 	.help_str = "set port <port_id> uta <mac_addr> on|off)",
7112 	.tokens = {
7113 		(void *)&cmd_set_uc_hash_set,
7114 		(void *)&cmd_set_uc_hash_port,
7115 		(void *)&cmd_set_uc_hash_portid,
7116 		(void *)&cmd_set_uc_hash_what,
7117 		(void *)&cmd_set_uc_hash_mac,
7118 		(void *)&cmd_set_uc_hash_mode,
7119 		NULL,
7120 	},
7121 };
7122 
7123 struct cmd_set_uc_all_hash_table {
7124 	cmdline_fixed_string_t set;
7125 	cmdline_fixed_string_t port;
7126 	uint8_t port_id;
7127 	cmdline_fixed_string_t what;
7128 	cmdline_fixed_string_t value;
7129 	cmdline_fixed_string_t mode;
7130 };
7131 
7132 static void
7133 cmd_set_uc_all_hash_parsed(void *parsed_result,
7134 		       __attribute__((unused)) struct cmdline *cl,
7135 		       __attribute__((unused)) void *data)
7136 {
7137 	int ret=0;
7138 	struct cmd_set_uc_all_hash_table *res = parsed_result;
7139 
7140 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7141 
7142 	if ((strcmp(res->what, "uta") == 0) &&
7143 		(strcmp(res->value, "all") == 0))
7144 		ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7145 	if (ret < 0)
7146 		printf("bad unicast hash table parameter,"
7147 			"return code = %d \n", ret);
7148 }
7149 
7150 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7151 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7152 				 set, "set");
7153 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7154 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7155 				 port, "port");
7156 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7157 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7158 			      port_id, UINT8);
7159 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7160 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7161 				 what, "uta");
7162 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7163 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7164 				value,"all");
7165 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7166 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7167 				 mode, "on#off");
7168 
7169 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7170 	.f = cmd_set_uc_all_hash_parsed,
7171 	.data = NULL,
7172 	.help_str = "set port <port_id> uta all on|off",
7173 	.tokens = {
7174 		(void *)&cmd_set_uc_all_hash_set,
7175 		(void *)&cmd_set_uc_all_hash_port,
7176 		(void *)&cmd_set_uc_all_hash_portid,
7177 		(void *)&cmd_set_uc_all_hash_what,
7178 		(void *)&cmd_set_uc_all_hash_value,
7179 		(void *)&cmd_set_uc_all_hash_mode,
7180 		NULL,
7181 	},
7182 };
7183 
7184 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7185 struct cmd_set_vf_macvlan_filter {
7186 	cmdline_fixed_string_t set;
7187 	cmdline_fixed_string_t port;
7188 	uint8_t port_id;
7189 	cmdline_fixed_string_t vf;
7190 	uint8_t vf_id;
7191 	struct ether_addr address;
7192 	cmdline_fixed_string_t filter_type;
7193 	cmdline_fixed_string_t mode;
7194 };
7195 
7196 static void
7197 cmd_set_vf_macvlan_parsed(void *parsed_result,
7198 		       __attribute__((unused)) struct cmdline *cl,
7199 		       __attribute__((unused)) void *data)
7200 {
7201 	int is_on, ret = 0;
7202 	struct cmd_set_vf_macvlan_filter *res = parsed_result;
7203 	struct rte_eth_mac_filter filter;
7204 
7205 	memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7206 
7207 	rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7208 
7209 	/* set VF MAC filter */
7210 	filter.is_vf = 1;
7211 
7212 	/* set VF ID */
7213 	filter.dst_id = res->vf_id;
7214 
7215 	if (!strcmp(res->filter_type, "exact-mac"))
7216 		filter.filter_type = RTE_MAC_PERFECT_MATCH;
7217 	else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7218 		filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7219 	else if (!strcmp(res->filter_type, "hashmac"))
7220 		filter.filter_type = RTE_MAC_HASH_MATCH;
7221 	else if (!strcmp(res->filter_type, "hashmac-vlan"))
7222 		filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7223 
7224 	is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7225 
7226 	if (is_on)
7227 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7228 					RTE_ETH_FILTER_MACVLAN,
7229 					RTE_ETH_FILTER_ADD,
7230 					 &filter);
7231 	else
7232 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7233 					RTE_ETH_FILTER_MACVLAN,
7234 					RTE_ETH_FILTER_DELETE,
7235 					&filter);
7236 
7237 	if (ret < 0)
7238 		printf("bad set MAC hash parameter, return code = %d\n", ret);
7239 
7240 }
7241 
7242 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7243 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7244 				 set, "set");
7245 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7246 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7247 				 port, "port");
7248 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7249 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7250 			      port_id, UINT8);
7251 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7252 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7253 				 vf, "vf");
7254 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7255 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7256 				vf_id, UINT8);
7257 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7258 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7259 				address);
7260 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7261 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7262 				filter_type, "exact-mac#exact-mac-vlan"
7263 				"#hashmac#hashmac-vlan");
7264 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7265 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7266 				 mode, "on#off");
7267 
7268 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7269 	.f = cmd_set_vf_macvlan_parsed,
7270 	.data = NULL,
7271 	.help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7272 		"exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7273 		"Exact match rule: exact match of MAC or MAC and VLAN; "
7274 		"hash match rule: hash match of MAC and exact match of VLAN",
7275 	.tokens = {
7276 		(void *)&cmd_set_vf_macvlan_set,
7277 		(void *)&cmd_set_vf_macvlan_port,
7278 		(void *)&cmd_set_vf_macvlan_portid,
7279 		(void *)&cmd_set_vf_macvlan_vf,
7280 		(void *)&cmd_set_vf_macvlan_vf_id,
7281 		(void *)&cmd_set_vf_macvlan_mac,
7282 		(void *)&cmd_set_vf_macvlan_filter_type,
7283 		(void *)&cmd_set_vf_macvlan_mode,
7284 		NULL,
7285 	},
7286 };
7287 
7288 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7289 struct cmd_set_vf_traffic {
7290 	cmdline_fixed_string_t set;
7291 	cmdline_fixed_string_t port;
7292 	uint8_t port_id;
7293 	cmdline_fixed_string_t vf;
7294 	uint8_t vf_id;
7295 	cmdline_fixed_string_t what;
7296 	cmdline_fixed_string_t mode;
7297 };
7298 
7299 static void
7300 cmd_set_vf_traffic_parsed(void *parsed_result,
7301 		       __attribute__((unused)) struct cmdline *cl,
7302 		       __attribute__((unused)) void *data)
7303 {
7304 	struct cmd_set_vf_traffic *res = parsed_result;
7305 	int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7306 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7307 
7308 	set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7309 }
7310 
7311 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7312 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7313 				 set, "set");
7314 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7315 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7316 				 port, "port");
7317 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7318 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7319 			      port_id, UINT8);
7320 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7321 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7322 				 vf, "vf");
7323 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7324 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7325 			      vf_id, UINT8);
7326 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7327 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7328 				 what, "tx#rx");
7329 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7330 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7331 				 mode, "on#off");
7332 
7333 cmdline_parse_inst_t cmd_set_vf_traffic = {
7334 	.f = cmd_set_vf_traffic_parsed,
7335 	.data = NULL,
7336 	.help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7337 	.tokens = {
7338 		(void *)&cmd_setvf_traffic_set,
7339 		(void *)&cmd_setvf_traffic_port,
7340 		(void *)&cmd_setvf_traffic_portid,
7341 		(void *)&cmd_setvf_traffic_vf,
7342 		(void *)&cmd_setvf_traffic_vfid,
7343 		(void *)&cmd_setvf_traffic_what,
7344 		(void *)&cmd_setvf_traffic_mode,
7345 		NULL,
7346 	},
7347 };
7348 
7349 /* *** CONFIGURE VF RECEIVE MODE *** */
7350 struct cmd_set_vf_rxmode {
7351 	cmdline_fixed_string_t set;
7352 	cmdline_fixed_string_t port;
7353 	uint8_t port_id;
7354 	cmdline_fixed_string_t vf;
7355 	uint8_t vf_id;
7356 	cmdline_fixed_string_t what;
7357 	cmdline_fixed_string_t mode;
7358 	cmdline_fixed_string_t on;
7359 };
7360 
7361 static void
7362 cmd_set_vf_rxmode_parsed(void *parsed_result,
7363 		       __attribute__((unused)) struct cmdline *cl,
7364 		       __attribute__((unused)) void *data)
7365 {
7366 	int ret = -ENOTSUP;
7367 	uint16_t rx_mode = 0;
7368 	struct cmd_set_vf_rxmode *res = parsed_result;
7369 
7370 	int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7371 	if (!strcmp(res->what,"rxmode")) {
7372 		if (!strcmp(res->mode, "AUPE"))
7373 			rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7374 		else if (!strcmp(res->mode, "ROPE"))
7375 			rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7376 		else if (!strcmp(res->mode, "BAM"))
7377 			rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7378 		else if (!strncmp(res->mode, "MPE",3))
7379 			rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7380 	}
7381 
7382 #ifdef RTE_LIBRTE_IXGBE_PMD
7383 	if (ret == -ENOTSUP)
7384 		ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7385 						  rx_mode, (uint8_t)is_on);
7386 #endif
7387 #ifdef RTE_LIBRTE_BNXT_PMD
7388 	if (ret == -ENOTSUP)
7389 		ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7390 						 rx_mode, (uint8_t)is_on);
7391 #endif
7392 	if (ret < 0)
7393 		printf("bad VF receive mode parameter, return code = %d \n",
7394 		ret);
7395 }
7396 
7397 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7398 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7399 				 set, "set");
7400 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7401 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7402 				 port, "port");
7403 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7404 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7405 			      port_id, UINT8);
7406 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7407 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7408 				 vf, "vf");
7409 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7410 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7411 			      vf_id, UINT8);
7412 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7413 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7414 				 what, "rxmode");
7415 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7416 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7417 				 mode, "AUPE#ROPE#BAM#MPE");
7418 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7419 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7420 				 on, "on#off");
7421 
7422 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7423 	.f = cmd_set_vf_rxmode_parsed,
7424 	.data = NULL,
7425 	.help_str = "set port <port_id> vf <vf_id> rxmode "
7426 		"AUPE|ROPE|BAM|MPE on|off",
7427 	.tokens = {
7428 		(void *)&cmd_set_vf_rxmode_set,
7429 		(void *)&cmd_set_vf_rxmode_port,
7430 		(void *)&cmd_set_vf_rxmode_portid,
7431 		(void *)&cmd_set_vf_rxmode_vf,
7432 		(void *)&cmd_set_vf_rxmode_vfid,
7433 		(void *)&cmd_set_vf_rxmode_what,
7434 		(void *)&cmd_set_vf_rxmode_mode,
7435 		(void *)&cmd_set_vf_rxmode_on,
7436 		NULL,
7437 	},
7438 };
7439 
7440 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7441 struct cmd_vf_mac_addr_result {
7442 	cmdline_fixed_string_t mac_addr_cmd;
7443 	cmdline_fixed_string_t what;
7444 	cmdline_fixed_string_t port;
7445 	uint8_t port_num;
7446 	cmdline_fixed_string_t vf;
7447 	uint8_t vf_num;
7448 	struct ether_addr address;
7449 };
7450 
7451 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7452 		__attribute__((unused)) struct cmdline *cl,
7453 		__attribute__((unused)) void *data)
7454 {
7455 	struct cmd_vf_mac_addr_result *res = parsed_result;
7456 	int ret = -ENOTSUP;
7457 
7458 	if (strcmp(res->what, "add") != 0)
7459 		return;
7460 
7461 #ifdef RTE_LIBRTE_I40E_PMD
7462 	if (ret == -ENOTSUP)
7463 		ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7464 						   &res->address);
7465 #endif
7466 #ifdef RTE_LIBRTE_BNXT_PMD
7467 	if (ret == -ENOTSUP)
7468 		ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7469 						res->vf_num);
7470 #endif
7471 
7472 	if(ret < 0)
7473 		printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7474 
7475 }
7476 
7477 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7478 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7479 				mac_addr_cmd,"mac_addr");
7480 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7481 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7482 				what,"add");
7483 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7484 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7485 				port,"port");
7486 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7487 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7488 				port_num, UINT8);
7489 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7490 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7491 				vf,"vf");
7492 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7493 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7494 				vf_num, UINT8);
7495 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7496 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7497 				address);
7498 
7499 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7500 	.f = cmd_vf_mac_addr_parsed,
7501 	.data = (void *)0,
7502 	.help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7503 		"Add MAC address filtering for a VF on port_id",
7504 	.tokens = {
7505 		(void *)&cmd_vf_mac_addr_cmd,
7506 		(void *)&cmd_vf_mac_addr_what,
7507 		(void *)&cmd_vf_mac_addr_port,
7508 		(void *)&cmd_vf_mac_addr_portnum,
7509 		(void *)&cmd_vf_mac_addr_vf,
7510 		(void *)&cmd_vf_mac_addr_vfnum,
7511 		(void *)&cmd_vf_mac_addr_addr,
7512 		NULL,
7513 	},
7514 };
7515 
7516 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7517 struct cmd_vf_rx_vlan_filter {
7518 	cmdline_fixed_string_t rx_vlan;
7519 	cmdline_fixed_string_t what;
7520 	uint16_t vlan_id;
7521 	cmdline_fixed_string_t port;
7522 	uint8_t port_id;
7523 	cmdline_fixed_string_t vf;
7524 	uint64_t vf_mask;
7525 };
7526 
7527 static void
7528 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7529 			  __attribute__((unused)) struct cmdline *cl,
7530 			  __attribute__((unused)) void *data)
7531 {
7532 	struct cmd_vf_rx_vlan_filter *res = parsed_result;
7533 	int ret = -ENOTSUP;
7534 
7535 	__rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7536 
7537 #ifdef RTE_LIBRTE_IXGBE_PMD
7538 	if (ret == -ENOTSUP)
7539 		ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7540 				res->vlan_id, res->vf_mask, is_add);
7541 #endif
7542 #ifdef RTE_LIBRTE_I40E_PMD
7543 	if (ret == -ENOTSUP)
7544 		ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7545 				res->vlan_id, res->vf_mask, is_add);
7546 #endif
7547 #ifdef RTE_LIBRTE_BNXT_PMD
7548 	if (ret == -ENOTSUP)
7549 		ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7550 				res->vlan_id, res->vf_mask, is_add);
7551 #endif
7552 
7553 	switch (ret) {
7554 	case 0:
7555 		break;
7556 	case -EINVAL:
7557 		printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7558 				res->vlan_id, res->vf_mask);
7559 		break;
7560 	case -ENODEV:
7561 		printf("invalid port_id %d\n", res->port_id);
7562 		break;
7563 	case -ENOTSUP:
7564 		printf("function not implemented or supported\n");
7565 		break;
7566 	default:
7567 		printf("programming error: (%s)\n", strerror(-ret));
7568 	}
7569 }
7570 
7571 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7572 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7573 				 rx_vlan, "rx_vlan");
7574 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7575 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7576 				 what, "add#rm");
7577 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7578 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7579 			      vlan_id, UINT16);
7580 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7581 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7582 				 port, "port");
7583 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7584 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7585 			      port_id, UINT8);
7586 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7587 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7588 				 vf, "vf");
7589 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7590 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7591 			      vf_mask, UINT64);
7592 
7593 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7594 	.f = cmd_vf_rx_vlan_filter_parsed,
7595 	.data = NULL,
7596 	.help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7597 		"(vf_mask = hexadecimal VF mask)",
7598 	.tokens = {
7599 		(void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7600 		(void *)&cmd_vf_rx_vlan_filter_what,
7601 		(void *)&cmd_vf_rx_vlan_filter_vlanid,
7602 		(void *)&cmd_vf_rx_vlan_filter_port,
7603 		(void *)&cmd_vf_rx_vlan_filter_portid,
7604 		(void *)&cmd_vf_rx_vlan_filter_vf,
7605 		(void *)&cmd_vf_rx_vlan_filter_vf_mask,
7606 		NULL,
7607 	},
7608 };
7609 
7610 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7611 struct cmd_queue_rate_limit_result {
7612 	cmdline_fixed_string_t set;
7613 	cmdline_fixed_string_t port;
7614 	uint8_t port_num;
7615 	cmdline_fixed_string_t queue;
7616 	uint8_t queue_num;
7617 	cmdline_fixed_string_t rate;
7618 	uint16_t rate_num;
7619 };
7620 
7621 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7622 		__attribute__((unused)) struct cmdline *cl,
7623 		__attribute__((unused)) void *data)
7624 {
7625 	struct cmd_queue_rate_limit_result *res = parsed_result;
7626 	int ret = 0;
7627 
7628 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7629 		&& (strcmp(res->queue, "queue") == 0)
7630 		&& (strcmp(res->rate, "rate") == 0))
7631 		ret = set_queue_rate_limit(res->port_num, res->queue_num,
7632 					res->rate_num);
7633 	if (ret < 0)
7634 		printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7635 
7636 }
7637 
7638 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7639 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7640 				set, "set");
7641 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7642 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7643 				port, "port");
7644 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7645 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7646 				port_num, UINT8);
7647 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7648 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7649 				queue, "queue");
7650 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7651 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7652 				queue_num, UINT8);
7653 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7654 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7655 				rate, "rate");
7656 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7657 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7658 				rate_num, UINT16);
7659 
7660 cmdline_parse_inst_t cmd_queue_rate_limit = {
7661 	.f = cmd_queue_rate_limit_parsed,
7662 	.data = (void *)0,
7663 	.help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7664 		"Set rate limit for a queue on port_id",
7665 	.tokens = {
7666 		(void *)&cmd_queue_rate_limit_set,
7667 		(void *)&cmd_queue_rate_limit_port,
7668 		(void *)&cmd_queue_rate_limit_portnum,
7669 		(void *)&cmd_queue_rate_limit_queue,
7670 		(void *)&cmd_queue_rate_limit_queuenum,
7671 		(void *)&cmd_queue_rate_limit_rate,
7672 		(void *)&cmd_queue_rate_limit_ratenum,
7673 		NULL,
7674 	},
7675 };
7676 
7677 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7678 struct cmd_vf_rate_limit_result {
7679 	cmdline_fixed_string_t set;
7680 	cmdline_fixed_string_t port;
7681 	uint8_t port_num;
7682 	cmdline_fixed_string_t vf;
7683 	uint8_t vf_num;
7684 	cmdline_fixed_string_t rate;
7685 	uint16_t rate_num;
7686 	cmdline_fixed_string_t q_msk;
7687 	uint64_t q_msk_val;
7688 };
7689 
7690 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7691 		__attribute__((unused)) struct cmdline *cl,
7692 		__attribute__((unused)) void *data)
7693 {
7694 	struct cmd_vf_rate_limit_result *res = parsed_result;
7695 	int ret = 0;
7696 
7697 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7698 		&& (strcmp(res->vf, "vf") == 0)
7699 		&& (strcmp(res->rate, "rate") == 0)
7700 		&& (strcmp(res->q_msk, "queue_mask") == 0))
7701 		ret = set_vf_rate_limit(res->port_num, res->vf_num,
7702 					res->rate_num, res->q_msk_val);
7703 	if (ret < 0)
7704 		printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7705 
7706 }
7707 
7708 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7709 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7710 				set, "set");
7711 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7712 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7713 				port, "port");
7714 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7715 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7716 				port_num, UINT8);
7717 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7718 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7719 				vf, "vf");
7720 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7721 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7722 				vf_num, UINT8);
7723 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7724 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7725 				rate, "rate");
7726 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7727 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7728 				rate_num, UINT16);
7729 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7730 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7731 				q_msk, "queue_mask");
7732 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7733 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7734 				q_msk_val, UINT64);
7735 
7736 cmdline_parse_inst_t cmd_vf_rate_limit = {
7737 	.f = cmd_vf_rate_limit_parsed,
7738 	.data = (void *)0,
7739 	.help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7740 		"queue_mask <queue_mask_value>: "
7741 		"Set rate limit for queues of VF on port_id",
7742 	.tokens = {
7743 		(void *)&cmd_vf_rate_limit_set,
7744 		(void *)&cmd_vf_rate_limit_port,
7745 		(void *)&cmd_vf_rate_limit_portnum,
7746 		(void *)&cmd_vf_rate_limit_vf,
7747 		(void *)&cmd_vf_rate_limit_vfnum,
7748 		(void *)&cmd_vf_rate_limit_rate,
7749 		(void *)&cmd_vf_rate_limit_ratenum,
7750 		(void *)&cmd_vf_rate_limit_q_msk,
7751 		(void *)&cmd_vf_rate_limit_q_msk_val,
7752 		NULL,
7753 	},
7754 };
7755 
7756 /* *** ADD TUNNEL FILTER OF A PORT *** */
7757 struct cmd_tunnel_filter_result {
7758 	cmdline_fixed_string_t cmd;
7759 	cmdline_fixed_string_t what;
7760 	uint8_t port_id;
7761 	struct ether_addr outer_mac;
7762 	struct ether_addr inner_mac;
7763 	cmdline_ipaddr_t ip_value;
7764 	uint16_t inner_vlan;
7765 	cmdline_fixed_string_t tunnel_type;
7766 	cmdline_fixed_string_t filter_type;
7767 	uint32_t tenant_id;
7768 	uint16_t queue_num;
7769 };
7770 
7771 static void
7772 cmd_tunnel_filter_parsed(void *parsed_result,
7773 			  __attribute__((unused)) struct cmdline *cl,
7774 			  __attribute__((unused)) void *data)
7775 {
7776 	struct cmd_tunnel_filter_result *res = parsed_result;
7777 	struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7778 	int ret = 0;
7779 
7780 	memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7781 
7782 	ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7783 	ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7784 	tunnel_filter_conf.inner_vlan = res->inner_vlan;
7785 
7786 	if (res->ip_value.family == AF_INET) {
7787 		tunnel_filter_conf.ip_addr.ipv4_addr =
7788 			res->ip_value.addr.ipv4.s_addr;
7789 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7790 	} else {
7791 		memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7792 			&(res->ip_value.addr.ipv6),
7793 			sizeof(struct in6_addr));
7794 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7795 	}
7796 
7797 	if (!strcmp(res->filter_type, "imac-ivlan"))
7798 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7799 	else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7800 		tunnel_filter_conf.filter_type =
7801 			RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7802 	else if (!strcmp(res->filter_type, "imac-tenid"))
7803 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7804 	else if (!strcmp(res->filter_type, "imac"))
7805 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7806 	else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7807 		tunnel_filter_conf.filter_type =
7808 			RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7809 	else if (!strcmp(res->filter_type, "oip"))
7810 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7811 	else if (!strcmp(res->filter_type, "iip"))
7812 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7813 	else {
7814 		printf("The filter type is not supported");
7815 		return;
7816 	}
7817 
7818 	if (!strcmp(res->tunnel_type, "vxlan"))
7819 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7820 	else if (!strcmp(res->tunnel_type, "nvgre"))
7821 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7822 	else if (!strcmp(res->tunnel_type, "ipingre"))
7823 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7824 	else {
7825 		printf("The tunnel type %s not supported.\n", res->tunnel_type);
7826 		return;
7827 	}
7828 
7829 	tunnel_filter_conf.tenant_id = res->tenant_id;
7830 	tunnel_filter_conf.queue_id = res->queue_num;
7831 	if (!strcmp(res->what, "add"))
7832 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7833 					RTE_ETH_FILTER_TUNNEL,
7834 					RTE_ETH_FILTER_ADD,
7835 					&tunnel_filter_conf);
7836 	else
7837 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7838 					RTE_ETH_FILTER_TUNNEL,
7839 					RTE_ETH_FILTER_DELETE,
7840 					&tunnel_filter_conf);
7841 	if (ret < 0)
7842 		printf("cmd_tunnel_filter_parsed error: (%s)\n",
7843 				strerror(-ret));
7844 
7845 }
7846 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7847 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7848 	cmd, "tunnel_filter");
7849 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7850 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7851 	what, "add#rm");
7852 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7853 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7854 	port_id, UINT8);
7855 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7856 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7857 	outer_mac);
7858 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7859 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7860 	inner_mac);
7861 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7862 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7863 	inner_vlan, UINT16);
7864 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7865 	TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7866 	ip_value);
7867 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7868 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7869 	tunnel_type, "vxlan#nvgre#ipingre");
7870 
7871 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7872 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7873 	filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7874 		"imac#omac-imac-tenid");
7875 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7876 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7877 	tenant_id, UINT32);
7878 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7879 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7880 	queue_num, UINT16);
7881 
7882 cmdline_parse_inst_t cmd_tunnel_filter = {
7883 	.f = cmd_tunnel_filter_parsed,
7884 	.data = (void *)0,
7885 	.help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7886 		"<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7887 		"imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7888 		"<queue_id>: Add/Rm tunnel filter of a port",
7889 	.tokens = {
7890 		(void *)&cmd_tunnel_filter_cmd,
7891 		(void *)&cmd_tunnel_filter_what,
7892 		(void *)&cmd_tunnel_filter_port_id,
7893 		(void *)&cmd_tunnel_filter_outer_mac,
7894 		(void *)&cmd_tunnel_filter_inner_mac,
7895 		(void *)&cmd_tunnel_filter_ip_value,
7896 		(void *)&cmd_tunnel_filter_innner_vlan,
7897 		(void *)&cmd_tunnel_filter_tunnel_type,
7898 		(void *)&cmd_tunnel_filter_filter_type,
7899 		(void *)&cmd_tunnel_filter_tenant_id,
7900 		(void *)&cmd_tunnel_filter_queue_num,
7901 		NULL,
7902 	},
7903 };
7904 
7905 /* *** CONFIGURE TUNNEL UDP PORT *** */
7906 struct cmd_tunnel_udp_config {
7907 	cmdline_fixed_string_t cmd;
7908 	cmdline_fixed_string_t what;
7909 	uint16_t udp_port;
7910 	uint8_t port_id;
7911 };
7912 
7913 static void
7914 cmd_tunnel_udp_config_parsed(void *parsed_result,
7915 			  __attribute__((unused)) struct cmdline *cl,
7916 			  __attribute__((unused)) void *data)
7917 {
7918 	struct cmd_tunnel_udp_config *res = parsed_result;
7919 	struct rte_eth_udp_tunnel tunnel_udp;
7920 	int ret;
7921 
7922 	tunnel_udp.udp_port = res->udp_port;
7923 
7924 	if (!strcmp(res->cmd, "rx_vxlan_port"))
7925 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7926 
7927 	if (!strcmp(res->what, "add"))
7928 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7929 						      &tunnel_udp);
7930 	else
7931 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7932 							 &tunnel_udp);
7933 
7934 	if (ret < 0)
7935 		printf("udp tunneling add error: (%s)\n", strerror(-ret));
7936 }
7937 
7938 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7939 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7940 				cmd, "rx_vxlan_port");
7941 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7942 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7943 				what, "add#rm");
7944 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7945 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7946 				udp_port, UINT16);
7947 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7948 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7949 				port_id, UINT8);
7950 
7951 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7952 	.f = cmd_tunnel_udp_config_parsed,
7953 	.data = (void *)0,
7954 	.help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
7955 		"Add/Remove a tunneling UDP port filter",
7956 	.tokens = {
7957 		(void *)&cmd_tunnel_udp_config_cmd,
7958 		(void *)&cmd_tunnel_udp_config_what,
7959 		(void *)&cmd_tunnel_udp_config_udp_port,
7960 		(void *)&cmd_tunnel_udp_config_port_id,
7961 		NULL,
7962 	},
7963 };
7964 
7965 /* *** GLOBAL CONFIG *** */
7966 struct cmd_global_config_result {
7967 	cmdline_fixed_string_t cmd;
7968 	uint8_t port_id;
7969 	cmdline_fixed_string_t cfg_type;
7970 	uint8_t len;
7971 };
7972 
7973 static void
7974 cmd_global_config_parsed(void *parsed_result,
7975 			 __attribute__((unused)) struct cmdline *cl,
7976 			 __attribute__((unused)) void *data)
7977 {
7978 	struct cmd_global_config_result *res = parsed_result;
7979 	struct rte_eth_global_cfg conf;
7980 	int ret;
7981 
7982 	memset(&conf, 0, sizeof(conf));
7983 	conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
7984 	conf.cfg.gre_key_len = res->len;
7985 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
7986 				      RTE_ETH_FILTER_SET, &conf);
7987 	if (ret != 0)
7988 		printf("Global config error\n");
7989 }
7990 
7991 cmdline_parse_token_string_t cmd_global_config_cmd =
7992 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
7993 		"global_config");
7994 cmdline_parse_token_num_t cmd_global_config_port_id =
7995 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
7996 cmdline_parse_token_string_t cmd_global_config_type =
7997 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
7998 		cfg_type, "gre-key-len");
7999 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8000 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8001 		len, UINT8);
8002 
8003 cmdline_parse_inst_t cmd_global_config = {
8004 	.f = cmd_global_config_parsed,
8005 	.data = (void *)NULL,
8006 	.help_str = "global_config <port_id> gre-key-len <key_len>",
8007 	.tokens = {
8008 		(void *)&cmd_global_config_cmd,
8009 		(void *)&cmd_global_config_port_id,
8010 		(void *)&cmd_global_config_type,
8011 		(void *)&cmd_global_config_gre_key_len,
8012 		NULL,
8013 	},
8014 };
8015 
8016 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8017 struct cmd_set_mirror_mask_result {
8018 	cmdline_fixed_string_t set;
8019 	cmdline_fixed_string_t port;
8020 	uint8_t port_id;
8021 	cmdline_fixed_string_t mirror;
8022 	uint8_t rule_id;
8023 	cmdline_fixed_string_t what;
8024 	cmdline_fixed_string_t value;
8025 	cmdline_fixed_string_t dstpool;
8026 	uint8_t dstpool_id;
8027 	cmdline_fixed_string_t on;
8028 };
8029 
8030 cmdline_parse_token_string_t cmd_mirror_mask_set =
8031 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8032 				set, "set");
8033 cmdline_parse_token_string_t cmd_mirror_mask_port =
8034 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8035 				port, "port");
8036 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8037 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8038 				port_id, UINT8);
8039 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8040 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8041 				mirror, "mirror-rule");
8042 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8043 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8044 				rule_id, UINT8);
8045 cmdline_parse_token_string_t cmd_mirror_mask_what =
8046 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8047 				what, "pool-mirror-up#pool-mirror-down"
8048 				      "#vlan-mirror");
8049 cmdline_parse_token_string_t cmd_mirror_mask_value =
8050 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8051 				value, NULL);
8052 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8053 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8054 				dstpool, "dst-pool");
8055 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8056 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8057 				dstpool_id, UINT8);
8058 cmdline_parse_token_string_t cmd_mirror_mask_on =
8059 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8060 				on, "on#off");
8061 
8062 static void
8063 cmd_set_mirror_mask_parsed(void *parsed_result,
8064 		       __attribute__((unused)) struct cmdline *cl,
8065 		       __attribute__((unused)) void *data)
8066 {
8067 	int ret,nb_item,i;
8068 	struct cmd_set_mirror_mask_result *res = parsed_result;
8069 	struct rte_eth_mirror_conf mr_conf;
8070 
8071 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8072 
8073 	unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8074 
8075 	mr_conf.dst_pool = res->dstpool_id;
8076 
8077 	if (!strcmp(res->what, "pool-mirror-up")) {
8078 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8079 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8080 	} else if (!strcmp(res->what, "pool-mirror-down")) {
8081 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8082 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8083 	} else if (!strcmp(res->what, "vlan-mirror")) {
8084 		mr_conf.rule_type = ETH_MIRROR_VLAN;
8085 		nb_item = parse_item_list(res->value, "vlan",
8086 				ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8087 		if (nb_item <= 0)
8088 			return;
8089 
8090 		for (i = 0; i < nb_item; i++) {
8091 			if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8092 				printf("Invalid vlan_id: must be < 4096\n");
8093 				return;
8094 			}
8095 
8096 			mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8097 			mr_conf.vlan.vlan_mask |= 1ULL << i;
8098 		}
8099 	}
8100 
8101 	if (!strcmp(res->on, "on"))
8102 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8103 						res->rule_id, 1);
8104 	else
8105 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8106 						res->rule_id, 0);
8107 	if (ret < 0)
8108 		printf("mirror rule add error: (%s)\n", strerror(-ret));
8109 }
8110 
8111 cmdline_parse_inst_t cmd_set_mirror_mask = {
8112 		.f = cmd_set_mirror_mask_parsed,
8113 		.data = NULL,
8114 		.help_str = "set port <port_id> mirror-rule <rule_id> "
8115 			"pool-mirror-up|pool-mirror-down|vlan-mirror "
8116 			"<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8117 		.tokens = {
8118 			(void *)&cmd_mirror_mask_set,
8119 			(void *)&cmd_mirror_mask_port,
8120 			(void *)&cmd_mirror_mask_portid,
8121 			(void *)&cmd_mirror_mask_mirror,
8122 			(void *)&cmd_mirror_mask_ruleid,
8123 			(void *)&cmd_mirror_mask_what,
8124 			(void *)&cmd_mirror_mask_value,
8125 			(void *)&cmd_mirror_mask_dstpool,
8126 			(void *)&cmd_mirror_mask_poolid,
8127 			(void *)&cmd_mirror_mask_on,
8128 			NULL,
8129 		},
8130 };
8131 
8132 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8133 struct cmd_set_mirror_link_result {
8134 	cmdline_fixed_string_t set;
8135 	cmdline_fixed_string_t port;
8136 	uint8_t port_id;
8137 	cmdline_fixed_string_t mirror;
8138 	uint8_t rule_id;
8139 	cmdline_fixed_string_t what;
8140 	cmdline_fixed_string_t dstpool;
8141 	uint8_t dstpool_id;
8142 	cmdline_fixed_string_t on;
8143 };
8144 
8145 cmdline_parse_token_string_t cmd_mirror_link_set =
8146 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8147 				 set, "set");
8148 cmdline_parse_token_string_t cmd_mirror_link_port =
8149 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8150 				port, "port");
8151 cmdline_parse_token_num_t cmd_mirror_link_portid =
8152 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8153 				port_id, UINT8);
8154 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8155 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8156 				mirror, "mirror-rule");
8157 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8158 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8159 			    rule_id, UINT8);
8160 cmdline_parse_token_string_t cmd_mirror_link_what =
8161 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8162 				what, "uplink-mirror#downlink-mirror");
8163 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8164 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8165 				dstpool, "dst-pool");
8166 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8167 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8168 				dstpool_id, UINT8);
8169 cmdline_parse_token_string_t cmd_mirror_link_on =
8170 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8171 				on, "on#off");
8172 
8173 static void
8174 cmd_set_mirror_link_parsed(void *parsed_result,
8175 		       __attribute__((unused)) struct cmdline *cl,
8176 		       __attribute__((unused)) void *data)
8177 {
8178 	int ret;
8179 	struct cmd_set_mirror_link_result *res = parsed_result;
8180 	struct rte_eth_mirror_conf mr_conf;
8181 
8182 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8183 	if (!strcmp(res->what, "uplink-mirror"))
8184 		mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8185 	else
8186 		mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8187 
8188 	mr_conf.dst_pool = res->dstpool_id;
8189 
8190 	if (!strcmp(res->on, "on"))
8191 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8192 						res->rule_id, 1);
8193 	else
8194 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8195 						res->rule_id, 0);
8196 
8197 	/* check the return value and print it if is < 0 */
8198 	if (ret < 0)
8199 		printf("mirror rule add error: (%s)\n", strerror(-ret));
8200 
8201 }
8202 
8203 cmdline_parse_inst_t cmd_set_mirror_link = {
8204 		.f = cmd_set_mirror_link_parsed,
8205 		.data = NULL,
8206 		.help_str = "set port <port_id> mirror-rule <rule_id> "
8207 			"uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8208 		.tokens = {
8209 			(void *)&cmd_mirror_link_set,
8210 			(void *)&cmd_mirror_link_port,
8211 			(void *)&cmd_mirror_link_portid,
8212 			(void *)&cmd_mirror_link_mirror,
8213 			(void *)&cmd_mirror_link_ruleid,
8214 			(void *)&cmd_mirror_link_what,
8215 			(void *)&cmd_mirror_link_dstpool,
8216 			(void *)&cmd_mirror_link_poolid,
8217 			(void *)&cmd_mirror_link_on,
8218 			NULL,
8219 		},
8220 };
8221 
8222 /* *** RESET VM MIRROR RULE *** */
8223 struct cmd_rm_mirror_rule_result {
8224 	cmdline_fixed_string_t reset;
8225 	cmdline_fixed_string_t port;
8226 	uint8_t port_id;
8227 	cmdline_fixed_string_t mirror;
8228 	uint8_t rule_id;
8229 };
8230 
8231 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8232 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8233 				 reset, "reset");
8234 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8235 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8236 				port, "port");
8237 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8238 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8239 				port_id, UINT8);
8240 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8241 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8242 				mirror, "mirror-rule");
8243 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8244 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8245 				rule_id, UINT8);
8246 
8247 static void
8248 cmd_reset_mirror_rule_parsed(void *parsed_result,
8249 		       __attribute__((unused)) struct cmdline *cl,
8250 		       __attribute__((unused)) void *data)
8251 {
8252 	int ret;
8253 	struct cmd_set_mirror_link_result *res = parsed_result;
8254         /* check rule_id */
8255 	ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8256 	if(ret < 0)
8257 		printf("mirror rule remove error: (%s)\n", strerror(-ret));
8258 }
8259 
8260 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8261 		.f = cmd_reset_mirror_rule_parsed,
8262 		.data = NULL,
8263 		.help_str = "reset port <port_id> mirror-rule <rule_id>",
8264 		.tokens = {
8265 			(void *)&cmd_rm_mirror_rule_reset,
8266 			(void *)&cmd_rm_mirror_rule_port,
8267 			(void *)&cmd_rm_mirror_rule_portid,
8268 			(void *)&cmd_rm_mirror_rule_mirror,
8269 			(void *)&cmd_rm_mirror_rule_ruleid,
8270 			NULL,
8271 		},
8272 };
8273 
8274 /* ******************************************************************************** */
8275 
8276 struct cmd_dump_result {
8277 	cmdline_fixed_string_t dump;
8278 };
8279 
8280 static void
8281 dump_struct_sizes(void)
8282 {
8283 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8284 	DUMP_SIZE(struct rte_mbuf);
8285 	DUMP_SIZE(struct rte_mempool);
8286 	DUMP_SIZE(struct rte_ring);
8287 #undef DUMP_SIZE
8288 }
8289 
8290 static void cmd_dump_parsed(void *parsed_result,
8291 			    __attribute__((unused)) struct cmdline *cl,
8292 			    __attribute__((unused)) void *data)
8293 {
8294 	struct cmd_dump_result *res = parsed_result;
8295 
8296 	if (!strcmp(res->dump, "dump_physmem"))
8297 		rte_dump_physmem_layout(stdout);
8298 	else if (!strcmp(res->dump, "dump_memzone"))
8299 		rte_memzone_dump(stdout);
8300 	else if (!strcmp(res->dump, "dump_struct_sizes"))
8301 		dump_struct_sizes();
8302 	else if (!strcmp(res->dump, "dump_ring"))
8303 		rte_ring_list_dump(stdout);
8304 	else if (!strcmp(res->dump, "dump_mempool"))
8305 		rte_mempool_list_dump(stdout);
8306 	else if (!strcmp(res->dump, "dump_devargs"))
8307 		rte_eal_devargs_dump(stdout);
8308 	else if (!strcmp(res->dump, "dump_log_types"))
8309 		rte_log_dump(stdout);
8310 }
8311 
8312 cmdline_parse_token_string_t cmd_dump_dump =
8313 	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8314 		"dump_physmem#"
8315 		"dump_memzone#"
8316 		"dump_struct_sizes#"
8317 		"dump_ring#"
8318 		"dump_mempool#"
8319 		"dump_devargs#"
8320 		"dump_log_types");
8321 
8322 cmdline_parse_inst_t cmd_dump = {
8323 	.f = cmd_dump_parsed,  /* function to call */
8324 	.data = NULL,      /* 2nd arg of func */
8325 	.help_str = "Dump status",
8326 	.tokens = {        /* token list, NULL terminated */
8327 		(void *)&cmd_dump_dump,
8328 		NULL,
8329 	},
8330 };
8331 
8332 /* ******************************************************************************** */
8333 
8334 struct cmd_dump_one_result {
8335 	cmdline_fixed_string_t dump;
8336 	cmdline_fixed_string_t name;
8337 };
8338 
8339 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8340 				__attribute__((unused)) void *data)
8341 {
8342 	struct cmd_dump_one_result *res = parsed_result;
8343 
8344 	if (!strcmp(res->dump, "dump_ring")) {
8345 		struct rte_ring *r;
8346 		r = rte_ring_lookup(res->name);
8347 		if (r == NULL) {
8348 			cmdline_printf(cl, "Cannot find ring\n");
8349 			return;
8350 		}
8351 		rte_ring_dump(stdout, r);
8352 	} else if (!strcmp(res->dump, "dump_mempool")) {
8353 		struct rte_mempool *mp;
8354 		mp = rte_mempool_lookup(res->name);
8355 		if (mp == NULL) {
8356 			cmdline_printf(cl, "Cannot find mempool\n");
8357 			return;
8358 		}
8359 		rte_mempool_dump(stdout, mp);
8360 	}
8361 }
8362 
8363 cmdline_parse_token_string_t cmd_dump_one_dump =
8364 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8365 				 "dump_ring#dump_mempool");
8366 
8367 cmdline_parse_token_string_t cmd_dump_one_name =
8368 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8369 
8370 cmdline_parse_inst_t cmd_dump_one = {
8371 	.f = cmd_dump_one_parsed,  /* function to call */
8372 	.data = NULL,      /* 2nd arg of func */
8373 	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8374 	.tokens = {        /* token list, NULL terminated */
8375 		(void *)&cmd_dump_one_dump,
8376 		(void *)&cmd_dump_one_name,
8377 		NULL,
8378 	},
8379 };
8380 
8381 /* *** Add/Del syn filter *** */
8382 struct cmd_syn_filter_result {
8383 	cmdline_fixed_string_t filter;
8384 	uint8_t port_id;
8385 	cmdline_fixed_string_t ops;
8386 	cmdline_fixed_string_t priority;
8387 	cmdline_fixed_string_t high;
8388 	cmdline_fixed_string_t queue;
8389 	uint16_t queue_id;
8390 };
8391 
8392 static void
8393 cmd_syn_filter_parsed(void *parsed_result,
8394 			__attribute__((unused)) struct cmdline *cl,
8395 			__attribute__((unused)) void *data)
8396 {
8397 	struct cmd_syn_filter_result *res = parsed_result;
8398 	struct rte_eth_syn_filter syn_filter;
8399 	int ret = 0;
8400 
8401 	ret = rte_eth_dev_filter_supported(res->port_id,
8402 					RTE_ETH_FILTER_SYN);
8403 	if (ret < 0) {
8404 		printf("syn filter is not supported on port %u.\n",
8405 				res->port_id);
8406 		return;
8407 	}
8408 
8409 	memset(&syn_filter, 0, sizeof(syn_filter));
8410 
8411 	if (!strcmp(res->ops, "add")) {
8412 		if (!strcmp(res->high, "high"))
8413 			syn_filter.hig_pri = 1;
8414 		else
8415 			syn_filter.hig_pri = 0;
8416 
8417 		syn_filter.queue = res->queue_id;
8418 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8419 						RTE_ETH_FILTER_SYN,
8420 						RTE_ETH_FILTER_ADD,
8421 						&syn_filter);
8422 	} else
8423 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8424 						RTE_ETH_FILTER_SYN,
8425 						RTE_ETH_FILTER_DELETE,
8426 						&syn_filter);
8427 
8428 	if (ret < 0)
8429 		printf("syn filter programming error: (%s)\n",
8430 				strerror(-ret));
8431 }
8432 
8433 cmdline_parse_token_string_t cmd_syn_filter_filter =
8434 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8435 	filter, "syn_filter");
8436 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8437 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8438 	port_id, UINT8);
8439 cmdline_parse_token_string_t cmd_syn_filter_ops =
8440 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8441 	ops, "add#del");
8442 cmdline_parse_token_string_t cmd_syn_filter_priority =
8443 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8444 				priority, "priority");
8445 cmdline_parse_token_string_t cmd_syn_filter_high =
8446 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8447 				high, "high#low");
8448 cmdline_parse_token_string_t cmd_syn_filter_queue =
8449 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8450 				queue, "queue");
8451 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8452 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8453 				queue_id, UINT16);
8454 
8455 cmdline_parse_inst_t cmd_syn_filter = {
8456 	.f = cmd_syn_filter_parsed,
8457 	.data = NULL,
8458 	.help_str = "syn_filter <port_id> add|del priority high|low queue "
8459 		"<queue_id>: Add/Delete syn filter",
8460 	.tokens = {
8461 		(void *)&cmd_syn_filter_filter,
8462 		(void *)&cmd_syn_filter_port_id,
8463 		(void *)&cmd_syn_filter_ops,
8464 		(void *)&cmd_syn_filter_priority,
8465 		(void *)&cmd_syn_filter_high,
8466 		(void *)&cmd_syn_filter_queue,
8467 		(void *)&cmd_syn_filter_queue_id,
8468 		NULL,
8469 	},
8470 };
8471 
8472 /* *** ADD/REMOVE A 2tuple FILTER *** */
8473 struct cmd_2tuple_filter_result {
8474 	cmdline_fixed_string_t filter;
8475 	uint8_t  port_id;
8476 	cmdline_fixed_string_t ops;
8477 	cmdline_fixed_string_t dst_port;
8478 	uint16_t dst_port_value;
8479 	cmdline_fixed_string_t protocol;
8480 	uint8_t protocol_value;
8481 	cmdline_fixed_string_t mask;
8482 	uint8_t  mask_value;
8483 	cmdline_fixed_string_t tcp_flags;
8484 	uint8_t tcp_flags_value;
8485 	cmdline_fixed_string_t priority;
8486 	uint8_t  priority_value;
8487 	cmdline_fixed_string_t queue;
8488 	uint16_t  queue_id;
8489 };
8490 
8491 static void
8492 cmd_2tuple_filter_parsed(void *parsed_result,
8493 			__attribute__((unused)) struct cmdline *cl,
8494 			__attribute__((unused)) void *data)
8495 {
8496 	struct rte_eth_ntuple_filter filter;
8497 	struct cmd_2tuple_filter_result *res = parsed_result;
8498 	int ret = 0;
8499 
8500 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8501 	if (ret < 0) {
8502 		printf("ntuple filter is not supported on port %u.\n",
8503 			res->port_id);
8504 		return;
8505 	}
8506 
8507 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8508 
8509 	filter.flags = RTE_2TUPLE_FLAGS;
8510 	filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8511 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8512 	filter.proto = res->protocol_value;
8513 	filter.priority = res->priority_value;
8514 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8515 		printf("nonzero tcp_flags is only meaningful"
8516 			" when protocol is TCP.\n");
8517 		return;
8518 	}
8519 	if (res->tcp_flags_value > TCP_FLAG_ALL) {
8520 		printf("invalid TCP flags.\n");
8521 		return;
8522 	}
8523 
8524 	if (res->tcp_flags_value != 0) {
8525 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8526 		filter.tcp_flags = res->tcp_flags_value;
8527 	}
8528 
8529 	/* need convert to big endian. */
8530 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8531 	filter.queue = res->queue_id;
8532 
8533 	if (!strcmp(res->ops, "add"))
8534 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8535 				RTE_ETH_FILTER_NTUPLE,
8536 				RTE_ETH_FILTER_ADD,
8537 				&filter);
8538 	else
8539 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8540 				RTE_ETH_FILTER_NTUPLE,
8541 				RTE_ETH_FILTER_DELETE,
8542 				&filter);
8543 	if (ret < 0)
8544 		printf("2tuple filter programming error: (%s)\n",
8545 			strerror(-ret));
8546 
8547 }
8548 
8549 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
8550 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8551 				 filter, "2tuple_filter");
8552 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
8553 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8554 				port_id, UINT8);
8555 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
8556 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8557 				 ops, "add#del");
8558 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
8559 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8560 				dst_port, "dst_port");
8561 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
8562 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8563 				dst_port_value, UINT16);
8564 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
8565 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8566 				protocol, "protocol");
8567 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
8568 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8569 				protocol_value, UINT8);
8570 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
8571 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8572 				mask, "mask");
8573 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
8574 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8575 				mask_value, INT8);
8576 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
8577 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8578 				tcp_flags, "tcp_flags");
8579 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
8580 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8581 				tcp_flags_value, UINT8);
8582 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
8583 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8584 				priority, "priority");
8585 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
8586 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8587 				priority_value, UINT8);
8588 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
8589 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8590 				queue, "queue");
8591 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
8592 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8593 				queue_id, UINT16);
8594 
8595 cmdline_parse_inst_t cmd_2tuple_filter = {
8596 	.f = cmd_2tuple_filter_parsed,
8597 	.data = NULL,
8598 	.help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
8599 		"<value> mask <value> tcp_flags <value> priority <value> queue "
8600 		"<queue_id>: Add a 2tuple filter",
8601 	.tokens = {
8602 		(void *)&cmd_2tuple_filter_filter,
8603 		(void *)&cmd_2tuple_filter_port_id,
8604 		(void *)&cmd_2tuple_filter_ops,
8605 		(void *)&cmd_2tuple_filter_dst_port,
8606 		(void *)&cmd_2tuple_filter_dst_port_value,
8607 		(void *)&cmd_2tuple_filter_protocol,
8608 		(void *)&cmd_2tuple_filter_protocol_value,
8609 		(void *)&cmd_2tuple_filter_mask,
8610 		(void *)&cmd_2tuple_filter_mask_value,
8611 		(void *)&cmd_2tuple_filter_tcp_flags,
8612 		(void *)&cmd_2tuple_filter_tcp_flags_value,
8613 		(void *)&cmd_2tuple_filter_priority,
8614 		(void *)&cmd_2tuple_filter_priority_value,
8615 		(void *)&cmd_2tuple_filter_queue,
8616 		(void *)&cmd_2tuple_filter_queue_id,
8617 		NULL,
8618 	},
8619 };
8620 
8621 /* *** ADD/REMOVE A 5tuple FILTER *** */
8622 struct cmd_5tuple_filter_result {
8623 	cmdline_fixed_string_t filter;
8624 	uint8_t  port_id;
8625 	cmdline_fixed_string_t ops;
8626 	cmdline_fixed_string_t dst_ip;
8627 	cmdline_ipaddr_t dst_ip_value;
8628 	cmdline_fixed_string_t src_ip;
8629 	cmdline_ipaddr_t src_ip_value;
8630 	cmdline_fixed_string_t dst_port;
8631 	uint16_t dst_port_value;
8632 	cmdline_fixed_string_t src_port;
8633 	uint16_t src_port_value;
8634 	cmdline_fixed_string_t protocol;
8635 	uint8_t protocol_value;
8636 	cmdline_fixed_string_t mask;
8637 	uint8_t  mask_value;
8638 	cmdline_fixed_string_t tcp_flags;
8639 	uint8_t tcp_flags_value;
8640 	cmdline_fixed_string_t priority;
8641 	uint8_t  priority_value;
8642 	cmdline_fixed_string_t queue;
8643 	uint16_t  queue_id;
8644 };
8645 
8646 static void
8647 cmd_5tuple_filter_parsed(void *parsed_result,
8648 			__attribute__((unused)) struct cmdline *cl,
8649 			__attribute__((unused)) void *data)
8650 {
8651 	struct rte_eth_ntuple_filter filter;
8652 	struct cmd_5tuple_filter_result *res = parsed_result;
8653 	int ret = 0;
8654 
8655 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8656 	if (ret < 0) {
8657 		printf("ntuple filter is not supported on port %u.\n",
8658 			res->port_id);
8659 		return;
8660 	}
8661 
8662 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8663 
8664 	filter.flags = RTE_5TUPLE_FLAGS;
8665 	filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
8666 	filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
8667 	filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
8668 	filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8669 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8670 	filter.proto = res->protocol_value;
8671 	filter.priority = res->priority_value;
8672 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8673 		printf("nonzero tcp_flags is only meaningful"
8674 			" when protocol is TCP.\n");
8675 		return;
8676 	}
8677 	if (res->tcp_flags_value > TCP_FLAG_ALL) {
8678 		printf("invalid TCP flags.\n");
8679 		return;
8680 	}
8681 
8682 	if (res->tcp_flags_value != 0) {
8683 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8684 		filter.tcp_flags = res->tcp_flags_value;
8685 	}
8686 
8687 	if (res->dst_ip_value.family == AF_INET)
8688 		/* no need to convert, already big endian. */
8689 		filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
8690 	else {
8691 		if (filter.dst_ip_mask == 0) {
8692 			printf("can not support ipv6 involved compare.\n");
8693 			return;
8694 		}
8695 		filter.dst_ip = 0;
8696 	}
8697 
8698 	if (res->src_ip_value.family == AF_INET)
8699 		/* no need to convert, already big endian. */
8700 		filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
8701 	else {
8702 		if (filter.src_ip_mask == 0) {
8703 			printf("can not support ipv6 involved compare.\n");
8704 			return;
8705 		}
8706 		filter.src_ip = 0;
8707 	}
8708 	/* need convert to big endian. */
8709 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8710 	filter.src_port = rte_cpu_to_be_16(res->src_port_value);
8711 	filter.queue = res->queue_id;
8712 
8713 	if (!strcmp(res->ops, "add"))
8714 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8715 				RTE_ETH_FILTER_NTUPLE,
8716 				RTE_ETH_FILTER_ADD,
8717 				&filter);
8718 	else
8719 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8720 				RTE_ETH_FILTER_NTUPLE,
8721 				RTE_ETH_FILTER_DELETE,
8722 				&filter);
8723 	if (ret < 0)
8724 		printf("5tuple filter programming error: (%s)\n",
8725 			strerror(-ret));
8726 }
8727 
8728 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
8729 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8730 				 filter, "5tuple_filter");
8731 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
8732 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8733 				port_id, UINT8);
8734 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
8735 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8736 				 ops, "add#del");
8737 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
8738 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8739 				dst_ip, "dst_ip");
8740 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
8741 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8742 				dst_ip_value);
8743 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
8744 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8745 				src_ip, "src_ip");
8746 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
8747 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8748 				src_ip_value);
8749 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
8750 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8751 				dst_port, "dst_port");
8752 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
8753 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8754 				dst_port_value, UINT16);
8755 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
8756 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8757 				src_port, "src_port");
8758 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
8759 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8760 				src_port_value, UINT16);
8761 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
8762 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8763 				protocol, "protocol");
8764 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
8765 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8766 				protocol_value, UINT8);
8767 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
8768 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8769 				mask, "mask");
8770 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
8771 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8772 				mask_value, INT8);
8773 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
8774 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8775 				tcp_flags, "tcp_flags");
8776 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
8777 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8778 				tcp_flags_value, UINT8);
8779 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
8780 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8781 				priority, "priority");
8782 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
8783 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8784 				priority_value, UINT8);
8785 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
8786 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8787 				queue, "queue");
8788 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
8789 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8790 				queue_id, UINT16);
8791 
8792 cmdline_parse_inst_t cmd_5tuple_filter = {
8793 	.f = cmd_5tuple_filter_parsed,
8794 	.data = NULL,
8795 	.help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
8796 		"src_ip <value> dst_port <value> src_port <value> "
8797 		"protocol <value>  mask <value> tcp_flags <value> "
8798 		"priority <value> queue <queue_id>: Add/Del a 5tuple filter",
8799 	.tokens = {
8800 		(void *)&cmd_5tuple_filter_filter,
8801 		(void *)&cmd_5tuple_filter_port_id,
8802 		(void *)&cmd_5tuple_filter_ops,
8803 		(void *)&cmd_5tuple_filter_dst_ip,
8804 		(void *)&cmd_5tuple_filter_dst_ip_value,
8805 		(void *)&cmd_5tuple_filter_src_ip,
8806 		(void *)&cmd_5tuple_filter_src_ip_value,
8807 		(void *)&cmd_5tuple_filter_dst_port,
8808 		(void *)&cmd_5tuple_filter_dst_port_value,
8809 		(void *)&cmd_5tuple_filter_src_port,
8810 		(void *)&cmd_5tuple_filter_src_port_value,
8811 		(void *)&cmd_5tuple_filter_protocol,
8812 		(void *)&cmd_5tuple_filter_protocol_value,
8813 		(void *)&cmd_5tuple_filter_mask,
8814 		(void *)&cmd_5tuple_filter_mask_value,
8815 		(void *)&cmd_5tuple_filter_tcp_flags,
8816 		(void *)&cmd_5tuple_filter_tcp_flags_value,
8817 		(void *)&cmd_5tuple_filter_priority,
8818 		(void *)&cmd_5tuple_filter_priority_value,
8819 		(void *)&cmd_5tuple_filter_queue,
8820 		(void *)&cmd_5tuple_filter_queue_id,
8821 		NULL,
8822 	},
8823 };
8824 
8825 /* *** ADD/REMOVE A flex FILTER *** */
8826 struct cmd_flex_filter_result {
8827 	cmdline_fixed_string_t filter;
8828 	cmdline_fixed_string_t ops;
8829 	uint8_t port_id;
8830 	cmdline_fixed_string_t len;
8831 	uint8_t len_value;
8832 	cmdline_fixed_string_t bytes;
8833 	cmdline_fixed_string_t bytes_value;
8834 	cmdline_fixed_string_t mask;
8835 	cmdline_fixed_string_t mask_value;
8836 	cmdline_fixed_string_t priority;
8837 	uint8_t priority_value;
8838 	cmdline_fixed_string_t queue;
8839 	uint16_t queue_id;
8840 };
8841 
8842 static int xdigit2val(unsigned char c)
8843 {
8844 	int val;
8845 	if (isdigit(c))
8846 		val = c - '0';
8847 	else if (isupper(c))
8848 		val = c - 'A' + 10;
8849 	else
8850 		val = c - 'a' + 10;
8851 	return val;
8852 }
8853 
8854 static void
8855 cmd_flex_filter_parsed(void *parsed_result,
8856 			  __attribute__((unused)) struct cmdline *cl,
8857 			  __attribute__((unused)) void *data)
8858 {
8859 	int ret = 0;
8860 	struct rte_eth_flex_filter filter;
8861 	struct cmd_flex_filter_result *res = parsed_result;
8862 	char *bytes_ptr, *mask_ptr;
8863 	uint16_t len, i, j = 0;
8864 	char c;
8865 	int val;
8866 	uint8_t byte = 0;
8867 
8868 	if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
8869 		printf("the len exceed the max length 128\n");
8870 		return;
8871 	}
8872 	memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
8873 	filter.len = res->len_value;
8874 	filter.priority = res->priority_value;
8875 	filter.queue = res->queue_id;
8876 	bytes_ptr = res->bytes_value;
8877 	mask_ptr = res->mask_value;
8878 
8879 	 /* translate bytes string to array. */
8880 	if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
8881 		(bytes_ptr[1] == 'X')))
8882 		bytes_ptr += 2;
8883 	len = strnlen(bytes_ptr, res->len_value * 2);
8884 	if (len == 0 || (len % 8 != 0)) {
8885 		printf("please check len and bytes input\n");
8886 		return;
8887 	}
8888 	for (i = 0; i < len; i++) {
8889 		c = bytes_ptr[i];
8890 		if (isxdigit(c) == 0) {
8891 			/* invalid characters. */
8892 			printf("invalid input\n");
8893 			return;
8894 		}
8895 		val = xdigit2val(c);
8896 		if (i % 2) {
8897 			byte |= val;
8898 			filter.bytes[j] = byte;
8899 			printf("bytes[%d]:%02x ", j, filter.bytes[j]);
8900 			j++;
8901 			byte = 0;
8902 		} else
8903 			byte |= val << 4;
8904 	}
8905 	printf("\n");
8906 	 /* translate mask string to uint8_t array. */
8907 	if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
8908 		(mask_ptr[1] == 'X')))
8909 		mask_ptr += 2;
8910 	len = strnlen(mask_ptr, (res->len_value + 3) / 4);
8911 	if (len == 0) {
8912 		printf("invalid input\n");
8913 		return;
8914 	}
8915 	j = 0;
8916 	byte = 0;
8917 	for (i = 0; i < len; i++) {
8918 		c = mask_ptr[i];
8919 		if (isxdigit(c) == 0) {
8920 			/* invalid characters. */
8921 			printf("invalid input\n");
8922 			return;
8923 		}
8924 		val = xdigit2val(c);
8925 		if (i % 2) {
8926 			byte |= val;
8927 			filter.mask[j] = byte;
8928 			printf("mask[%d]:%02x ", j, filter.mask[j]);
8929 			j++;
8930 			byte = 0;
8931 		} else
8932 			byte |= val << 4;
8933 	}
8934 	printf("\n");
8935 
8936 	if (!strcmp(res->ops, "add"))
8937 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8938 				RTE_ETH_FILTER_FLEXIBLE,
8939 				RTE_ETH_FILTER_ADD,
8940 				&filter);
8941 	else
8942 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8943 				RTE_ETH_FILTER_FLEXIBLE,
8944 				RTE_ETH_FILTER_DELETE,
8945 				&filter);
8946 
8947 	if (ret < 0)
8948 		printf("flex filter setting error: (%s)\n", strerror(-ret));
8949 }
8950 
8951 cmdline_parse_token_string_t cmd_flex_filter_filter =
8952 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8953 				filter, "flex_filter");
8954 cmdline_parse_token_num_t cmd_flex_filter_port_id =
8955 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8956 				port_id, UINT8);
8957 cmdline_parse_token_string_t cmd_flex_filter_ops =
8958 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8959 				ops, "add#del");
8960 cmdline_parse_token_string_t cmd_flex_filter_len =
8961 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8962 				len, "len");
8963 cmdline_parse_token_num_t cmd_flex_filter_len_value =
8964 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8965 				len_value, UINT8);
8966 cmdline_parse_token_string_t cmd_flex_filter_bytes =
8967 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8968 				bytes, "bytes");
8969 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
8970 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8971 				bytes_value, NULL);
8972 cmdline_parse_token_string_t cmd_flex_filter_mask =
8973 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8974 				mask, "mask");
8975 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
8976 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8977 				mask_value, NULL);
8978 cmdline_parse_token_string_t cmd_flex_filter_priority =
8979 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8980 				priority, "priority");
8981 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
8982 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8983 				priority_value, UINT8);
8984 cmdline_parse_token_string_t cmd_flex_filter_queue =
8985 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8986 				queue, "queue");
8987 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
8988 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8989 				queue_id, UINT16);
8990 cmdline_parse_inst_t cmd_flex_filter = {
8991 	.f = cmd_flex_filter_parsed,
8992 	.data = NULL,
8993 	.help_str = "flex_filter <port_id> add|del len <value> bytes "
8994 		"<value> mask <value> priority <value> queue <queue_id>: "
8995 		"Add/Del a flex filter",
8996 	.tokens = {
8997 		(void *)&cmd_flex_filter_filter,
8998 		(void *)&cmd_flex_filter_port_id,
8999 		(void *)&cmd_flex_filter_ops,
9000 		(void *)&cmd_flex_filter_len,
9001 		(void *)&cmd_flex_filter_len_value,
9002 		(void *)&cmd_flex_filter_bytes,
9003 		(void *)&cmd_flex_filter_bytes_value,
9004 		(void *)&cmd_flex_filter_mask,
9005 		(void *)&cmd_flex_filter_mask_value,
9006 		(void *)&cmd_flex_filter_priority,
9007 		(void *)&cmd_flex_filter_priority_value,
9008 		(void *)&cmd_flex_filter_queue,
9009 		(void *)&cmd_flex_filter_queue_id,
9010 		NULL,
9011 	},
9012 };
9013 
9014 /* *** Filters Control *** */
9015 
9016 /* *** deal with ethertype filter *** */
9017 struct cmd_ethertype_filter_result {
9018 	cmdline_fixed_string_t filter;
9019 	uint8_t port_id;
9020 	cmdline_fixed_string_t ops;
9021 	cmdline_fixed_string_t mac;
9022 	struct ether_addr mac_addr;
9023 	cmdline_fixed_string_t ethertype;
9024 	uint16_t ethertype_value;
9025 	cmdline_fixed_string_t drop;
9026 	cmdline_fixed_string_t queue;
9027 	uint16_t  queue_id;
9028 };
9029 
9030 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9031 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9032 				 filter, "ethertype_filter");
9033 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9034 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9035 			      port_id, UINT8);
9036 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9037 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9038 				 ops, "add#del");
9039 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9040 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9041 				 mac, "mac_addr#mac_ignr");
9042 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9043 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9044 				     mac_addr);
9045 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9046 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9047 				 ethertype, "ethertype");
9048 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9049 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9050 			      ethertype_value, UINT16);
9051 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9052 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9053 				 drop, "drop#fwd");
9054 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9055 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9056 				 queue, "queue");
9057 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9058 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9059 			      queue_id, UINT16);
9060 
9061 static void
9062 cmd_ethertype_filter_parsed(void *parsed_result,
9063 			  __attribute__((unused)) struct cmdline *cl,
9064 			  __attribute__((unused)) void *data)
9065 {
9066 	struct cmd_ethertype_filter_result *res = parsed_result;
9067 	struct rte_eth_ethertype_filter filter;
9068 	int ret = 0;
9069 
9070 	ret = rte_eth_dev_filter_supported(res->port_id,
9071 			RTE_ETH_FILTER_ETHERTYPE);
9072 	if (ret < 0) {
9073 		printf("ethertype filter is not supported on port %u.\n",
9074 			res->port_id);
9075 		return;
9076 	}
9077 
9078 	memset(&filter, 0, sizeof(filter));
9079 	if (!strcmp(res->mac, "mac_addr")) {
9080 		filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9081 		rte_memcpy(&filter.mac_addr, &res->mac_addr,
9082 			sizeof(struct ether_addr));
9083 	}
9084 	if (!strcmp(res->drop, "drop"))
9085 		filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9086 	filter.ether_type = res->ethertype_value;
9087 	filter.queue = res->queue_id;
9088 
9089 	if (!strcmp(res->ops, "add"))
9090 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9091 				RTE_ETH_FILTER_ETHERTYPE,
9092 				RTE_ETH_FILTER_ADD,
9093 				&filter);
9094 	else
9095 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9096 				RTE_ETH_FILTER_ETHERTYPE,
9097 				RTE_ETH_FILTER_DELETE,
9098 				&filter);
9099 	if (ret < 0)
9100 		printf("ethertype filter programming error: (%s)\n",
9101 			strerror(-ret));
9102 }
9103 
9104 cmdline_parse_inst_t cmd_ethertype_filter = {
9105 	.f = cmd_ethertype_filter_parsed,
9106 	.data = NULL,
9107 	.help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9108 		"<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9109 		"Add or delete an ethertype filter entry",
9110 	.tokens = {
9111 		(void *)&cmd_ethertype_filter_filter,
9112 		(void *)&cmd_ethertype_filter_port_id,
9113 		(void *)&cmd_ethertype_filter_ops,
9114 		(void *)&cmd_ethertype_filter_mac,
9115 		(void *)&cmd_ethertype_filter_mac_addr,
9116 		(void *)&cmd_ethertype_filter_ethertype,
9117 		(void *)&cmd_ethertype_filter_ethertype_value,
9118 		(void *)&cmd_ethertype_filter_drop,
9119 		(void *)&cmd_ethertype_filter_queue,
9120 		(void *)&cmd_ethertype_filter_queue_id,
9121 		NULL,
9122 	},
9123 };
9124 
9125 /* *** deal with flow director filter *** */
9126 struct cmd_flow_director_result {
9127 	cmdline_fixed_string_t flow_director_filter;
9128 	uint8_t port_id;
9129 	cmdline_fixed_string_t mode;
9130 	cmdline_fixed_string_t mode_value;
9131 	cmdline_fixed_string_t ops;
9132 	cmdline_fixed_string_t flow;
9133 	cmdline_fixed_string_t flow_type;
9134 	cmdline_fixed_string_t ether;
9135 	uint16_t ether_type;
9136 	cmdline_fixed_string_t src;
9137 	cmdline_ipaddr_t ip_src;
9138 	uint16_t port_src;
9139 	cmdline_fixed_string_t dst;
9140 	cmdline_ipaddr_t ip_dst;
9141 	uint16_t port_dst;
9142 	cmdline_fixed_string_t verify_tag;
9143 	uint32_t verify_tag_value;
9144 	cmdline_ipaddr_t tos;
9145 	uint8_t tos_value;
9146 	cmdline_ipaddr_t proto;
9147 	uint8_t proto_value;
9148 	cmdline_ipaddr_t ttl;
9149 	uint8_t ttl_value;
9150 	cmdline_fixed_string_t vlan;
9151 	uint16_t vlan_value;
9152 	cmdline_fixed_string_t flexbytes;
9153 	cmdline_fixed_string_t flexbytes_value;
9154 	cmdline_fixed_string_t pf_vf;
9155 	cmdline_fixed_string_t drop;
9156 	cmdline_fixed_string_t queue;
9157 	uint16_t  queue_id;
9158 	cmdline_fixed_string_t fd_id;
9159 	uint32_t  fd_id_value;
9160 	cmdline_fixed_string_t mac;
9161 	struct ether_addr mac_addr;
9162 	cmdline_fixed_string_t tunnel;
9163 	cmdline_fixed_string_t tunnel_type;
9164 	cmdline_fixed_string_t tunnel_id;
9165 	uint32_t tunnel_id_value;
9166 };
9167 
9168 static inline int
9169 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9170 {
9171 	char s[256];
9172 	const char *p, *p0 = q_arg;
9173 	char *end;
9174 	unsigned long int_fld;
9175 	char *str_fld[max_num];
9176 	int i;
9177 	unsigned size;
9178 	int ret = -1;
9179 
9180 	p = strchr(p0, '(');
9181 	if (p == NULL)
9182 		return -1;
9183 	++p;
9184 	p0 = strchr(p, ')');
9185 	if (p0 == NULL)
9186 		return -1;
9187 
9188 	size = p0 - p;
9189 	if (size >= sizeof(s))
9190 		return -1;
9191 
9192 	snprintf(s, sizeof(s), "%.*s", size, p);
9193 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9194 	if (ret < 0 || ret > max_num)
9195 		return -1;
9196 	for (i = 0; i < ret; i++) {
9197 		errno = 0;
9198 		int_fld = strtoul(str_fld[i], &end, 0);
9199 		if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9200 			return -1;
9201 		flexbytes[i] = (uint8_t)int_fld;
9202 	}
9203 	return ret;
9204 }
9205 
9206 static uint16_t
9207 str2flowtype(char *string)
9208 {
9209 	uint8_t i = 0;
9210 	static const struct {
9211 		char str[32];
9212 		uint16_t type;
9213 	} flowtype_str[] = {
9214 		{"raw", RTE_ETH_FLOW_RAW},
9215 		{"ipv4", RTE_ETH_FLOW_IPV4},
9216 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9217 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9218 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9219 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9220 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9221 		{"ipv6", RTE_ETH_FLOW_IPV6},
9222 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9223 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9224 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9225 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9226 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9227 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9228 	};
9229 
9230 	for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9231 		if (!strcmp(flowtype_str[i].str, string))
9232 			return flowtype_str[i].type;
9233 	}
9234 
9235 	if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9236 		return (uint16_t)atoi(string);
9237 
9238 	return RTE_ETH_FLOW_UNKNOWN;
9239 }
9240 
9241 static enum rte_eth_fdir_tunnel_type
9242 str2fdir_tunneltype(char *string)
9243 {
9244 	uint8_t i = 0;
9245 
9246 	static const struct {
9247 		char str[32];
9248 		enum rte_eth_fdir_tunnel_type type;
9249 	} tunneltype_str[] = {
9250 		{"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9251 		{"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9252 	};
9253 
9254 	for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9255 		if (!strcmp(tunneltype_str[i].str, string))
9256 			return tunneltype_str[i].type;
9257 	}
9258 	return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9259 }
9260 
9261 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9262 do { \
9263 	if ((ip_addr).family == AF_INET) \
9264 		(ip) = (ip_addr).addr.ipv4.s_addr; \
9265 	else { \
9266 		printf("invalid parameter.\n"); \
9267 		return; \
9268 	} \
9269 } while (0)
9270 
9271 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9272 do { \
9273 	if ((ip_addr).family == AF_INET6) \
9274 		rte_memcpy(&(ip), \
9275 				 &((ip_addr).addr.ipv6), \
9276 				 sizeof(struct in6_addr)); \
9277 	else { \
9278 		printf("invalid parameter.\n"); \
9279 		return; \
9280 	} \
9281 } while (0)
9282 
9283 static void
9284 cmd_flow_director_filter_parsed(void *parsed_result,
9285 			  __attribute__((unused)) struct cmdline *cl,
9286 			  __attribute__((unused)) void *data)
9287 {
9288 	struct cmd_flow_director_result *res = parsed_result;
9289 	struct rte_eth_fdir_filter entry;
9290 	uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9291 	char *end;
9292 	unsigned long vf_id;
9293 	int ret = 0;
9294 
9295 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9296 	if (ret < 0) {
9297 		printf("flow director is not supported on port %u.\n",
9298 			res->port_id);
9299 		return;
9300 	}
9301 	memset(flexbytes, 0, sizeof(flexbytes));
9302 	memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9303 
9304 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9305 		if (strcmp(res->mode_value, "MAC-VLAN")) {
9306 			printf("Please set mode to MAC-VLAN.\n");
9307 			return;
9308 		}
9309 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9310 		if (strcmp(res->mode_value, "Tunnel")) {
9311 			printf("Please set mode to Tunnel.\n");
9312 			return;
9313 		}
9314 	} else {
9315 		if (strcmp(res->mode_value, "IP")) {
9316 			printf("Please set mode to IP.\n");
9317 			return;
9318 		}
9319 		entry.input.flow_type = str2flowtype(res->flow_type);
9320 	}
9321 
9322 	ret = parse_flexbytes(res->flexbytes_value,
9323 					flexbytes,
9324 					RTE_ETH_FDIR_MAX_FLEXLEN);
9325 	if (ret < 0) {
9326 		printf("error: Cannot parse flexbytes input.\n");
9327 		return;
9328 	}
9329 
9330 	switch (entry.input.flow_type) {
9331 	case RTE_ETH_FLOW_FRAG_IPV4:
9332 	case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9333 		entry.input.flow.ip4_flow.proto = res->proto_value;
9334 		/* fall-through */
9335 	case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9336 	case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9337 		IPV4_ADDR_TO_UINT(res->ip_dst,
9338 			entry.input.flow.ip4_flow.dst_ip);
9339 		IPV4_ADDR_TO_UINT(res->ip_src,
9340 			entry.input.flow.ip4_flow.src_ip);
9341 		entry.input.flow.ip4_flow.tos = res->tos_value;
9342 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
9343 		/* need convert to big endian. */
9344 		entry.input.flow.udp4_flow.dst_port =
9345 				rte_cpu_to_be_16(res->port_dst);
9346 		entry.input.flow.udp4_flow.src_port =
9347 				rte_cpu_to_be_16(res->port_src);
9348 		break;
9349 	case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9350 		IPV4_ADDR_TO_UINT(res->ip_dst,
9351 			entry.input.flow.sctp4_flow.ip.dst_ip);
9352 		IPV4_ADDR_TO_UINT(res->ip_src,
9353 			entry.input.flow.sctp4_flow.ip.src_ip);
9354 		entry.input.flow.ip4_flow.tos = res->tos_value;
9355 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
9356 		/* need convert to big endian. */
9357 		entry.input.flow.sctp4_flow.dst_port =
9358 				rte_cpu_to_be_16(res->port_dst);
9359 		entry.input.flow.sctp4_flow.src_port =
9360 				rte_cpu_to_be_16(res->port_src);
9361 		entry.input.flow.sctp4_flow.verify_tag =
9362 				rte_cpu_to_be_32(res->verify_tag_value);
9363 		break;
9364 	case RTE_ETH_FLOW_FRAG_IPV6:
9365 	case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9366 		entry.input.flow.ipv6_flow.proto = res->proto_value;
9367 		/* fall-through */
9368 	case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9369 	case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9370 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
9371 			entry.input.flow.ipv6_flow.dst_ip);
9372 		IPV6_ADDR_TO_ARRAY(res->ip_src,
9373 			entry.input.flow.ipv6_flow.src_ip);
9374 		entry.input.flow.ipv6_flow.tc = res->tos_value;
9375 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9376 		/* need convert to big endian. */
9377 		entry.input.flow.udp6_flow.dst_port =
9378 				rte_cpu_to_be_16(res->port_dst);
9379 		entry.input.flow.udp6_flow.src_port =
9380 				rte_cpu_to_be_16(res->port_src);
9381 		break;
9382 	case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9383 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
9384 			entry.input.flow.sctp6_flow.ip.dst_ip);
9385 		IPV6_ADDR_TO_ARRAY(res->ip_src,
9386 			entry.input.flow.sctp6_flow.ip.src_ip);
9387 		entry.input.flow.ipv6_flow.tc = res->tos_value;
9388 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9389 		/* need convert to big endian. */
9390 		entry.input.flow.sctp6_flow.dst_port =
9391 				rte_cpu_to_be_16(res->port_dst);
9392 		entry.input.flow.sctp6_flow.src_port =
9393 				rte_cpu_to_be_16(res->port_src);
9394 		entry.input.flow.sctp6_flow.verify_tag =
9395 				rte_cpu_to_be_32(res->verify_tag_value);
9396 		break;
9397 	case RTE_ETH_FLOW_L2_PAYLOAD:
9398 		entry.input.flow.l2_flow.ether_type =
9399 			rte_cpu_to_be_16(res->ether_type);
9400 		break;
9401 	default:
9402 		break;
9403 	}
9404 
9405 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9406 		rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9407 				 &res->mac_addr,
9408 				 sizeof(struct ether_addr));
9409 
9410 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9411 		rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9412 				 &res->mac_addr,
9413 				 sizeof(struct ether_addr));
9414 		entry.input.flow.tunnel_flow.tunnel_type =
9415 			str2fdir_tunneltype(res->tunnel_type);
9416 		entry.input.flow.tunnel_flow.tunnel_id =
9417 			rte_cpu_to_be_32(res->tunnel_id_value);
9418 	}
9419 
9420 	rte_memcpy(entry.input.flow_ext.flexbytes,
9421 		   flexbytes,
9422 		   RTE_ETH_FDIR_MAX_FLEXLEN);
9423 
9424 	entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9425 
9426 	entry.action.flex_off = 0;  /*use 0 by default */
9427 	if (!strcmp(res->drop, "drop"))
9428 		entry.action.behavior = RTE_ETH_FDIR_REJECT;
9429 	else
9430 		entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9431 
9432 	if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9433 	    fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9434 		if (!strcmp(res->pf_vf, "pf"))
9435 			entry.input.flow_ext.is_vf = 0;
9436 		else if (!strncmp(res->pf_vf, "vf", 2)) {
9437 			struct rte_eth_dev_info dev_info;
9438 
9439 			memset(&dev_info, 0, sizeof(dev_info));
9440 			rte_eth_dev_info_get(res->port_id, &dev_info);
9441 			errno = 0;
9442 			vf_id = strtoul(res->pf_vf + 2, &end, 10);
9443 			if (errno != 0 || *end != '\0' ||
9444 			    vf_id >= dev_info.max_vfs) {
9445 				printf("invalid parameter %s.\n", res->pf_vf);
9446 				return;
9447 			}
9448 			entry.input.flow_ext.is_vf = 1;
9449 			entry.input.flow_ext.dst_id = (uint16_t)vf_id;
9450 		} else {
9451 			printf("invalid parameter %s.\n", res->pf_vf);
9452 			return;
9453 		}
9454 	}
9455 
9456 	/* set to report FD ID by default */
9457 	entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
9458 	entry.action.rx_queue = res->queue_id;
9459 	entry.soft_id = res->fd_id_value;
9460 	if (!strcmp(res->ops, "add"))
9461 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9462 					     RTE_ETH_FILTER_ADD, &entry);
9463 	else if (!strcmp(res->ops, "del"))
9464 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9465 					     RTE_ETH_FILTER_DELETE, &entry);
9466 	else
9467 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9468 					     RTE_ETH_FILTER_UPDATE, &entry);
9469 	if (ret < 0)
9470 		printf("flow director programming error: (%s)\n",
9471 			strerror(-ret));
9472 }
9473 
9474 cmdline_parse_token_string_t cmd_flow_director_filter =
9475 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9476 				 flow_director_filter, "flow_director_filter");
9477 cmdline_parse_token_num_t cmd_flow_director_port_id =
9478 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9479 			      port_id, UINT8);
9480 cmdline_parse_token_string_t cmd_flow_director_ops =
9481 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9482 				 ops, "add#del#update");
9483 cmdline_parse_token_string_t cmd_flow_director_flow =
9484 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9485 				 flow, "flow");
9486 cmdline_parse_token_string_t cmd_flow_director_flow_type =
9487 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9488 		flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9489 		"ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
9490 cmdline_parse_token_string_t cmd_flow_director_ether =
9491 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9492 				 ether, "ether");
9493 cmdline_parse_token_num_t cmd_flow_director_ether_type =
9494 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9495 			      ether_type, UINT16);
9496 cmdline_parse_token_string_t cmd_flow_director_src =
9497 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9498 				 src, "src");
9499 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
9500 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9501 				 ip_src);
9502 cmdline_parse_token_num_t cmd_flow_director_port_src =
9503 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9504 			      port_src, UINT16);
9505 cmdline_parse_token_string_t cmd_flow_director_dst =
9506 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9507 				 dst, "dst");
9508 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
9509 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9510 				 ip_dst);
9511 cmdline_parse_token_num_t cmd_flow_director_port_dst =
9512 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9513 			      port_dst, UINT16);
9514 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
9515 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9516 				  verify_tag, "verify_tag");
9517 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
9518 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9519 			      verify_tag_value, UINT32);
9520 cmdline_parse_token_string_t cmd_flow_director_tos =
9521 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9522 				 tos, "tos");
9523 cmdline_parse_token_num_t cmd_flow_director_tos_value =
9524 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9525 			      tos_value, UINT8);
9526 cmdline_parse_token_string_t cmd_flow_director_proto =
9527 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9528 				 proto, "proto");
9529 cmdline_parse_token_num_t cmd_flow_director_proto_value =
9530 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9531 			      proto_value, UINT8);
9532 cmdline_parse_token_string_t cmd_flow_director_ttl =
9533 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9534 				 ttl, "ttl");
9535 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
9536 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9537 			      ttl_value, UINT8);
9538 cmdline_parse_token_string_t cmd_flow_director_vlan =
9539 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9540 				 vlan, "vlan");
9541 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
9542 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9543 			      vlan_value, UINT16);
9544 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
9545 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9546 				 flexbytes, "flexbytes");
9547 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
9548 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9549 			      flexbytes_value, NULL);
9550 cmdline_parse_token_string_t cmd_flow_director_drop =
9551 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9552 				 drop, "drop#fwd");
9553 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
9554 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9555 			      pf_vf, NULL);
9556 cmdline_parse_token_string_t cmd_flow_director_queue =
9557 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9558 				 queue, "queue");
9559 cmdline_parse_token_num_t cmd_flow_director_queue_id =
9560 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9561 			      queue_id, UINT16);
9562 cmdline_parse_token_string_t cmd_flow_director_fd_id =
9563 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9564 				 fd_id, "fd_id");
9565 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
9566 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9567 			      fd_id_value, UINT32);
9568 
9569 cmdline_parse_token_string_t cmd_flow_director_mode =
9570 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9571 				 mode, "mode");
9572 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
9573 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9574 				 mode_value, "IP");
9575 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
9576 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9577 				 mode_value, "MAC-VLAN");
9578 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
9579 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9580 				 mode_value, "Tunnel");
9581 cmdline_parse_token_string_t cmd_flow_director_mac =
9582 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9583 				 mac, "mac");
9584 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
9585 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
9586 				    mac_addr);
9587 cmdline_parse_token_string_t cmd_flow_director_tunnel =
9588 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9589 				 tunnel, "tunnel");
9590 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
9591 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9592 				 tunnel_type, "NVGRE#VxLAN");
9593 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
9594 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9595 				 tunnel_id, "tunnel-id");
9596 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
9597 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9598 			      tunnel_id_value, UINT32);
9599 
9600 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
9601 	.f = cmd_flow_director_filter_parsed,
9602 	.data = NULL,
9603 	.help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
9604 		" ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
9605 		"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
9606 		"l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
9607 		"proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
9608 		"flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
9609 		"fd_id <fd_id_value>: "
9610 		"Add or delete an ip flow director entry on NIC",
9611 	.tokens = {
9612 		(void *)&cmd_flow_director_filter,
9613 		(void *)&cmd_flow_director_port_id,
9614 		(void *)&cmd_flow_director_mode,
9615 		(void *)&cmd_flow_director_mode_ip,
9616 		(void *)&cmd_flow_director_ops,
9617 		(void *)&cmd_flow_director_flow,
9618 		(void *)&cmd_flow_director_flow_type,
9619 		(void *)&cmd_flow_director_src,
9620 		(void *)&cmd_flow_director_ip_src,
9621 		(void *)&cmd_flow_director_dst,
9622 		(void *)&cmd_flow_director_ip_dst,
9623 		(void *)&cmd_flow_director_tos,
9624 		(void *)&cmd_flow_director_tos_value,
9625 		(void *)&cmd_flow_director_proto,
9626 		(void *)&cmd_flow_director_proto_value,
9627 		(void *)&cmd_flow_director_ttl,
9628 		(void *)&cmd_flow_director_ttl_value,
9629 		(void *)&cmd_flow_director_vlan,
9630 		(void *)&cmd_flow_director_vlan_value,
9631 		(void *)&cmd_flow_director_flexbytes,
9632 		(void *)&cmd_flow_director_flexbytes_value,
9633 		(void *)&cmd_flow_director_drop,
9634 		(void *)&cmd_flow_director_pf_vf,
9635 		(void *)&cmd_flow_director_queue,
9636 		(void *)&cmd_flow_director_queue_id,
9637 		(void *)&cmd_flow_director_fd_id,
9638 		(void *)&cmd_flow_director_fd_id_value,
9639 		NULL,
9640 	},
9641 };
9642 
9643 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
9644 	.f = cmd_flow_director_filter_parsed,
9645 	.data = NULL,
9646 	.help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
9647 		"director entry on NIC",
9648 	.tokens = {
9649 		(void *)&cmd_flow_director_filter,
9650 		(void *)&cmd_flow_director_port_id,
9651 		(void *)&cmd_flow_director_mode,
9652 		(void *)&cmd_flow_director_mode_ip,
9653 		(void *)&cmd_flow_director_ops,
9654 		(void *)&cmd_flow_director_flow,
9655 		(void *)&cmd_flow_director_flow_type,
9656 		(void *)&cmd_flow_director_src,
9657 		(void *)&cmd_flow_director_ip_src,
9658 		(void *)&cmd_flow_director_port_src,
9659 		(void *)&cmd_flow_director_dst,
9660 		(void *)&cmd_flow_director_ip_dst,
9661 		(void *)&cmd_flow_director_port_dst,
9662 		(void *)&cmd_flow_director_tos,
9663 		(void *)&cmd_flow_director_tos_value,
9664 		(void *)&cmd_flow_director_ttl,
9665 		(void *)&cmd_flow_director_ttl_value,
9666 		(void *)&cmd_flow_director_vlan,
9667 		(void *)&cmd_flow_director_vlan_value,
9668 		(void *)&cmd_flow_director_flexbytes,
9669 		(void *)&cmd_flow_director_flexbytes_value,
9670 		(void *)&cmd_flow_director_drop,
9671 		(void *)&cmd_flow_director_pf_vf,
9672 		(void *)&cmd_flow_director_queue,
9673 		(void *)&cmd_flow_director_queue_id,
9674 		(void *)&cmd_flow_director_fd_id,
9675 		(void *)&cmd_flow_director_fd_id_value,
9676 		NULL,
9677 	},
9678 };
9679 
9680 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
9681 	.f = cmd_flow_director_filter_parsed,
9682 	.data = NULL,
9683 	.help_str = "flow_director_filter ... : Add or delete a sctp flow "
9684 		"director entry on NIC",
9685 	.tokens = {
9686 		(void *)&cmd_flow_director_filter,
9687 		(void *)&cmd_flow_director_port_id,
9688 		(void *)&cmd_flow_director_mode,
9689 		(void *)&cmd_flow_director_mode_ip,
9690 		(void *)&cmd_flow_director_ops,
9691 		(void *)&cmd_flow_director_flow,
9692 		(void *)&cmd_flow_director_flow_type,
9693 		(void *)&cmd_flow_director_src,
9694 		(void *)&cmd_flow_director_ip_src,
9695 		(void *)&cmd_flow_director_port_dst,
9696 		(void *)&cmd_flow_director_dst,
9697 		(void *)&cmd_flow_director_ip_dst,
9698 		(void *)&cmd_flow_director_port_dst,
9699 		(void *)&cmd_flow_director_verify_tag,
9700 		(void *)&cmd_flow_director_verify_tag_value,
9701 		(void *)&cmd_flow_director_tos,
9702 		(void *)&cmd_flow_director_tos_value,
9703 		(void *)&cmd_flow_director_ttl,
9704 		(void *)&cmd_flow_director_ttl_value,
9705 		(void *)&cmd_flow_director_vlan,
9706 		(void *)&cmd_flow_director_vlan_value,
9707 		(void *)&cmd_flow_director_flexbytes,
9708 		(void *)&cmd_flow_director_flexbytes_value,
9709 		(void *)&cmd_flow_director_drop,
9710 		(void *)&cmd_flow_director_pf_vf,
9711 		(void *)&cmd_flow_director_queue,
9712 		(void *)&cmd_flow_director_queue_id,
9713 		(void *)&cmd_flow_director_fd_id,
9714 		(void *)&cmd_flow_director_fd_id_value,
9715 		NULL,
9716 	},
9717 };
9718 
9719 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
9720 	.f = cmd_flow_director_filter_parsed,
9721 	.data = NULL,
9722 	.help_str = "flow_director_filter ... : Add or delete a L2 flow "
9723 		"director entry on NIC",
9724 	.tokens = {
9725 		(void *)&cmd_flow_director_filter,
9726 		(void *)&cmd_flow_director_port_id,
9727 		(void *)&cmd_flow_director_mode,
9728 		(void *)&cmd_flow_director_mode_ip,
9729 		(void *)&cmd_flow_director_ops,
9730 		(void *)&cmd_flow_director_flow,
9731 		(void *)&cmd_flow_director_flow_type,
9732 		(void *)&cmd_flow_director_ether,
9733 		(void *)&cmd_flow_director_ether_type,
9734 		(void *)&cmd_flow_director_flexbytes,
9735 		(void *)&cmd_flow_director_flexbytes_value,
9736 		(void *)&cmd_flow_director_drop,
9737 		(void *)&cmd_flow_director_pf_vf,
9738 		(void *)&cmd_flow_director_queue,
9739 		(void *)&cmd_flow_director_queue_id,
9740 		(void *)&cmd_flow_director_fd_id,
9741 		(void *)&cmd_flow_director_fd_id_value,
9742 		NULL,
9743 	},
9744 };
9745 
9746 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
9747 	.f = cmd_flow_director_filter_parsed,
9748 	.data = NULL,
9749 	.help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
9750 		"director entry on NIC",
9751 	.tokens = {
9752 		(void *)&cmd_flow_director_filter,
9753 		(void *)&cmd_flow_director_port_id,
9754 		(void *)&cmd_flow_director_mode,
9755 		(void *)&cmd_flow_director_mode_mac_vlan,
9756 		(void *)&cmd_flow_director_ops,
9757 		(void *)&cmd_flow_director_mac,
9758 		(void *)&cmd_flow_director_mac_addr,
9759 		(void *)&cmd_flow_director_vlan,
9760 		(void *)&cmd_flow_director_vlan_value,
9761 		(void *)&cmd_flow_director_flexbytes,
9762 		(void *)&cmd_flow_director_flexbytes_value,
9763 		(void *)&cmd_flow_director_drop,
9764 		(void *)&cmd_flow_director_queue,
9765 		(void *)&cmd_flow_director_queue_id,
9766 		(void *)&cmd_flow_director_fd_id,
9767 		(void *)&cmd_flow_director_fd_id_value,
9768 		NULL,
9769 	},
9770 };
9771 
9772 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
9773 	.f = cmd_flow_director_filter_parsed,
9774 	.data = NULL,
9775 	.help_str = "flow_director_filter ... : Add or delete a tunnel flow "
9776 		"director entry on NIC",
9777 	.tokens = {
9778 		(void *)&cmd_flow_director_filter,
9779 		(void *)&cmd_flow_director_port_id,
9780 		(void *)&cmd_flow_director_mode,
9781 		(void *)&cmd_flow_director_mode_tunnel,
9782 		(void *)&cmd_flow_director_ops,
9783 		(void *)&cmd_flow_director_mac,
9784 		(void *)&cmd_flow_director_mac_addr,
9785 		(void *)&cmd_flow_director_vlan,
9786 		(void *)&cmd_flow_director_vlan_value,
9787 		(void *)&cmd_flow_director_tunnel,
9788 		(void *)&cmd_flow_director_tunnel_type,
9789 		(void *)&cmd_flow_director_tunnel_id,
9790 		(void *)&cmd_flow_director_tunnel_id_value,
9791 		(void *)&cmd_flow_director_flexbytes,
9792 		(void *)&cmd_flow_director_flexbytes_value,
9793 		(void *)&cmd_flow_director_drop,
9794 		(void *)&cmd_flow_director_queue,
9795 		(void *)&cmd_flow_director_queue_id,
9796 		(void *)&cmd_flow_director_fd_id,
9797 		(void *)&cmd_flow_director_fd_id_value,
9798 		NULL,
9799 	},
9800 };
9801 
9802 struct cmd_flush_flow_director_result {
9803 	cmdline_fixed_string_t flush_flow_director;
9804 	uint8_t port_id;
9805 };
9806 
9807 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
9808 	TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
9809 				 flush_flow_director, "flush_flow_director");
9810 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
9811 	TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
9812 			      port_id, UINT8);
9813 
9814 static void
9815 cmd_flush_flow_director_parsed(void *parsed_result,
9816 			  __attribute__((unused)) struct cmdline *cl,
9817 			  __attribute__((unused)) void *data)
9818 {
9819 	struct cmd_flow_director_result *res = parsed_result;
9820 	int ret = 0;
9821 
9822 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9823 	if (ret < 0) {
9824 		printf("flow director is not supported on port %u.\n",
9825 			res->port_id);
9826 		return;
9827 	}
9828 
9829 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9830 			RTE_ETH_FILTER_FLUSH, NULL);
9831 	if (ret < 0)
9832 		printf("flow director table flushing error: (%s)\n",
9833 			strerror(-ret));
9834 }
9835 
9836 cmdline_parse_inst_t cmd_flush_flow_director = {
9837 	.f = cmd_flush_flow_director_parsed,
9838 	.data = NULL,
9839 	.help_str = "flush_flow_director <port_id>: "
9840 		"Flush all flow director entries of a device on NIC",
9841 	.tokens = {
9842 		(void *)&cmd_flush_flow_director_flush,
9843 		(void *)&cmd_flush_flow_director_port_id,
9844 		NULL,
9845 	},
9846 };
9847 
9848 /* *** deal with flow director mask *** */
9849 struct cmd_flow_director_mask_result {
9850 	cmdline_fixed_string_t flow_director_mask;
9851 	uint8_t port_id;
9852 	cmdline_fixed_string_t mode;
9853 	cmdline_fixed_string_t mode_value;
9854 	cmdline_fixed_string_t vlan;
9855 	uint16_t vlan_mask;
9856 	cmdline_fixed_string_t src_mask;
9857 	cmdline_ipaddr_t ipv4_src;
9858 	cmdline_ipaddr_t ipv6_src;
9859 	uint16_t port_src;
9860 	cmdline_fixed_string_t dst_mask;
9861 	cmdline_ipaddr_t ipv4_dst;
9862 	cmdline_ipaddr_t ipv6_dst;
9863 	uint16_t port_dst;
9864 	cmdline_fixed_string_t mac;
9865 	uint8_t mac_addr_byte_mask;
9866 	cmdline_fixed_string_t tunnel_id;
9867 	uint32_t tunnel_id_mask;
9868 	cmdline_fixed_string_t tunnel_type;
9869 	uint8_t tunnel_type_mask;
9870 };
9871 
9872 static void
9873 cmd_flow_director_mask_parsed(void *parsed_result,
9874 			  __attribute__((unused)) struct cmdline *cl,
9875 			  __attribute__((unused)) void *data)
9876 {
9877 	struct cmd_flow_director_mask_result *res = parsed_result;
9878 	struct rte_eth_fdir_masks *mask;
9879 	struct rte_port *port;
9880 
9881 	if (res->port_id > nb_ports) {
9882 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9883 		return;
9884 	}
9885 
9886 	port = &ports[res->port_id];
9887 	/** Check if the port is not started **/
9888 	if (port->port_status != RTE_PORT_STOPPED) {
9889 		printf("Please stop port %d first\n", res->port_id);
9890 		return;
9891 	}
9892 
9893 	mask = &port->dev_conf.fdir_conf.mask;
9894 
9895 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9896 		if (strcmp(res->mode_value, "MAC-VLAN")) {
9897 			printf("Please set mode to MAC-VLAN.\n");
9898 			return;
9899 		}
9900 
9901 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9902 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9903 		if (strcmp(res->mode_value, "Tunnel")) {
9904 			printf("Please set mode to Tunnel.\n");
9905 			return;
9906 		}
9907 
9908 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9909 		mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9910 		mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
9911 		mask->tunnel_type_mask = res->tunnel_type_mask;
9912 	} else {
9913 		if (strcmp(res->mode_value, "IP")) {
9914 			printf("Please set mode to IP.\n");
9915 			return;
9916 		}
9917 
9918 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9919 		IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
9920 		IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
9921 		IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
9922 		IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
9923 		mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
9924 		mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
9925 	}
9926 
9927 	cmd_reconfig_device_queue(res->port_id, 1, 1);
9928 }
9929 
9930 cmdline_parse_token_string_t cmd_flow_director_mask =
9931 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9932 				 flow_director_mask, "flow_director_mask");
9933 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
9934 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9935 			      port_id, UINT8);
9936 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
9937 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9938 				 vlan, "vlan");
9939 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
9940 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9941 			      vlan_mask, UINT16);
9942 cmdline_parse_token_string_t cmd_flow_director_mask_src =
9943 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9944 				 src_mask, "src_mask");
9945 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
9946 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9947 				 ipv4_src);
9948 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
9949 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9950 				 ipv6_src);
9951 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
9952 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9953 			      port_src, UINT16);
9954 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
9955 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9956 				 dst_mask, "dst_mask");
9957 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
9958 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9959 				 ipv4_dst);
9960 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
9961 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9962 				 ipv6_dst);
9963 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
9964 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9965 			      port_dst, UINT16);
9966 
9967 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
9968 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9969 				 mode, "mode");
9970 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
9971 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9972 				 mode_value, "IP");
9973 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
9974 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9975 				 mode_value, "MAC-VLAN");
9976 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
9977 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9978 				 mode_value, "Tunnel");
9979 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
9980 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9981 				 mac, "mac");
9982 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
9983 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9984 			      mac_addr_byte_mask, UINT8);
9985 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
9986 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9987 				 tunnel_type, "tunnel-type");
9988 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
9989 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9990 			      tunnel_type_mask, UINT8);
9991 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
9992 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9993 				 tunnel_id, "tunnel-id");
9994 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
9995 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9996 			      tunnel_id_mask, UINT32);
9997 
9998 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
9999 	.f = cmd_flow_director_mask_parsed,
10000 	.data = NULL,
10001 	.help_str = "flow_director_mask ... : "
10002 		"Set IP mode flow director's mask on NIC",
10003 	.tokens = {
10004 		(void *)&cmd_flow_director_mask,
10005 		(void *)&cmd_flow_director_mask_port_id,
10006 		(void *)&cmd_flow_director_mask_mode,
10007 		(void *)&cmd_flow_director_mask_mode_ip,
10008 		(void *)&cmd_flow_director_mask_vlan,
10009 		(void *)&cmd_flow_director_mask_vlan_value,
10010 		(void *)&cmd_flow_director_mask_src,
10011 		(void *)&cmd_flow_director_mask_ipv4_src,
10012 		(void *)&cmd_flow_director_mask_ipv6_src,
10013 		(void *)&cmd_flow_director_mask_port_src,
10014 		(void *)&cmd_flow_director_mask_dst,
10015 		(void *)&cmd_flow_director_mask_ipv4_dst,
10016 		(void *)&cmd_flow_director_mask_ipv6_dst,
10017 		(void *)&cmd_flow_director_mask_port_dst,
10018 		NULL,
10019 	},
10020 };
10021 
10022 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10023 	.f = cmd_flow_director_mask_parsed,
10024 	.data = NULL,
10025 	.help_str = "flow_director_mask ... : Set MAC VLAN mode "
10026 		"flow director's mask on NIC",
10027 	.tokens = {
10028 		(void *)&cmd_flow_director_mask,
10029 		(void *)&cmd_flow_director_mask_port_id,
10030 		(void *)&cmd_flow_director_mask_mode,
10031 		(void *)&cmd_flow_director_mask_mode_mac_vlan,
10032 		(void *)&cmd_flow_director_mask_vlan,
10033 		(void *)&cmd_flow_director_mask_vlan_value,
10034 		NULL,
10035 	},
10036 };
10037 
10038 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10039 	.f = cmd_flow_director_mask_parsed,
10040 	.data = NULL,
10041 	.help_str = "flow_director_mask ... : Set tunnel mode "
10042 		"flow director's mask on NIC",
10043 	.tokens = {
10044 		(void *)&cmd_flow_director_mask,
10045 		(void *)&cmd_flow_director_mask_port_id,
10046 		(void *)&cmd_flow_director_mask_mode,
10047 		(void *)&cmd_flow_director_mask_mode_tunnel,
10048 		(void *)&cmd_flow_director_mask_vlan,
10049 		(void *)&cmd_flow_director_mask_vlan_value,
10050 		(void *)&cmd_flow_director_mask_mac,
10051 		(void *)&cmd_flow_director_mask_mac_value,
10052 		(void *)&cmd_flow_director_mask_tunnel_type,
10053 		(void *)&cmd_flow_director_mask_tunnel_type_value,
10054 		(void *)&cmd_flow_director_mask_tunnel_id,
10055 		(void *)&cmd_flow_director_mask_tunnel_id_value,
10056 		NULL,
10057 	},
10058 };
10059 
10060 /* *** deal with flow director mask on flexible payload *** */
10061 struct cmd_flow_director_flex_mask_result {
10062 	cmdline_fixed_string_t flow_director_flexmask;
10063 	uint8_t port_id;
10064 	cmdline_fixed_string_t flow;
10065 	cmdline_fixed_string_t flow_type;
10066 	cmdline_fixed_string_t mask;
10067 };
10068 
10069 static void
10070 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10071 			  __attribute__((unused)) struct cmdline *cl,
10072 			  __attribute__((unused)) void *data)
10073 {
10074 	struct cmd_flow_director_flex_mask_result *res = parsed_result;
10075 	struct rte_eth_fdir_info fdir_info;
10076 	struct rte_eth_fdir_flex_mask flex_mask;
10077 	struct rte_port *port;
10078 	uint32_t flow_type_mask;
10079 	uint16_t i;
10080 	int ret;
10081 
10082 	if (res->port_id > nb_ports) {
10083 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10084 		return;
10085 	}
10086 
10087 	port = &ports[res->port_id];
10088 	/** Check if the port is not started **/
10089 	if (port->port_status != RTE_PORT_STOPPED) {
10090 		printf("Please stop port %d first\n", res->port_id);
10091 		return;
10092 	}
10093 
10094 	memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10095 	ret = parse_flexbytes(res->mask,
10096 			flex_mask.mask,
10097 			RTE_ETH_FDIR_MAX_FLEXLEN);
10098 	if (ret < 0) {
10099 		printf("error: Cannot parse mask input.\n");
10100 		return;
10101 	}
10102 
10103 	memset(&fdir_info, 0, sizeof(fdir_info));
10104 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10105 				RTE_ETH_FILTER_INFO, &fdir_info);
10106 	if (ret < 0) {
10107 		printf("Cannot get FDir filter info\n");
10108 		return;
10109 	}
10110 
10111 	if (!strcmp(res->flow_type, "none")) {
10112 		/* means don't specify the flow type */
10113 		flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10114 		for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10115 			memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10116 			       0, sizeof(struct rte_eth_fdir_flex_mask));
10117 		port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10118 		rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10119 				 &flex_mask,
10120 				 sizeof(struct rte_eth_fdir_flex_mask));
10121 		cmd_reconfig_device_queue(res->port_id, 1, 1);
10122 		return;
10123 	}
10124 	flow_type_mask = fdir_info.flow_types_mask[0];
10125 	if (!strcmp(res->flow_type, "all")) {
10126 		if (!flow_type_mask) {
10127 			printf("No flow type supported\n");
10128 			return;
10129 		}
10130 		for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10131 			if (flow_type_mask & (1 << i)) {
10132 				flex_mask.flow_type = i;
10133 				fdir_set_flex_mask(res->port_id, &flex_mask);
10134 			}
10135 		}
10136 		cmd_reconfig_device_queue(res->port_id, 1, 1);
10137 		return;
10138 	}
10139 	flex_mask.flow_type = str2flowtype(res->flow_type);
10140 	if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10141 		printf("Flow type %s not supported on port %d\n",
10142 				res->flow_type, res->port_id);
10143 		return;
10144 	}
10145 	fdir_set_flex_mask(res->port_id, &flex_mask);
10146 	cmd_reconfig_device_queue(res->port_id, 1, 1);
10147 }
10148 
10149 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10150 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10151 				 flow_director_flexmask,
10152 				 "flow_director_flex_mask");
10153 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10154 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10155 			      port_id, UINT8);
10156 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10157 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10158 				 flow, "flow");
10159 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10160 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10161 		flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10162 		"ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10163 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10164 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10165 				 mask, NULL);
10166 
10167 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10168 	.f = cmd_flow_director_flex_mask_parsed,
10169 	.data = NULL,
10170 	.help_str = "flow_director_flex_mask ... : "
10171 		"Set flow director's flex mask on NIC",
10172 	.tokens = {
10173 		(void *)&cmd_flow_director_flexmask,
10174 		(void *)&cmd_flow_director_flexmask_port_id,
10175 		(void *)&cmd_flow_director_flexmask_flow,
10176 		(void *)&cmd_flow_director_flexmask_flow_type,
10177 		(void *)&cmd_flow_director_flexmask_mask,
10178 		NULL,
10179 	},
10180 };
10181 
10182 /* *** deal with flow director flexible payload configuration *** */
10183 struct cmd_flow_director_flexpayload_result {
10184 	cmdline_fixed_string_t flow_director_flexpayload;
10185 	uint8_t port_id;
10186 	cmdline_fixed_string_t payload_layer;
10187 	cmdline_fixed_string_t payload_cfg;
10188 };
10189 
10190 static inline int
10191 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10192 {
10193 	char s[256];
10194 	const char *p, *p0 = q_arg;
10195 	char *end;
10196 	unsigned long int_fld;
10197 	char *str_fld[max_num];
10198 	int i;
10199 	unsigned size;
10200 	int ret = -1;
10201 
10202 	p = strchr(p0, '(');
10203 	if (p == NULL)
10204 		return -1;
10205 	++p;
10206 	p0 = strchr(p, ')');
10207 	if (p0 == NULL)
10208 		return -1;
10209 
10210 	size = p0 - p;
10211 	if (size >= sizeof(s))
10212 		return -1;
10213 
10214 	snprintf(s, sizeof(s), "%.*s", size, p);
10215 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10216 	if (ret < 0 || ret > max_num)
10217 		return -1;
10218 	for (i = 0; i < ret; i++) {
10219 		errno = 0;
10220 		int_fld = strtoul(str_fld[i], &end, 0);
10221 		if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10222 			return -1;
10223 		offsets[i] = (uint16_t)int_fld;
10224 	}
10225 	return ret;
10226 }
10227 
10228 static void
10229 cmd_flow_director_flxpld_parsed(void *parsed_result,
10230 			  __attribute__((unused)) struct cmdline *cl,
10231 			  __attribute__((unused)) void *data)
10232 {
10233 	struct cmd_flow_director_flexpayload_result *res = parsed_result;
10234 	struct rte_eth_flex_payload_cfg flex_cfg;
10235 	struct rte_port *port;
10236 	int ret = 0;
10237 
10238 	if (res->port_id > nb_ports) {
10239 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10240 		return;
10241 	}
10242 
10243 	port = &ports[res->port_id];
10244 	/** Check if the port is not started **/
10245 	if (port->port_status != RTE_PORT_STOPPED) {
10246 		printf("Please stop port %d first\n", res->port_id);
10247 		return;
10248 	}
10249 
10250 	memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10251 
10252 	if (!strcmp(res->payload_layer, "raw"))
10253 		flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10254 	else if (!strcmp(res->payload_layer, "l2"))
10255 		flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10256 	else if (!strcmp(res->payload_layer, "l3"))
10257 		flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10258 	else if (!strcmp(res->payload_layer, "l4"))
10259 		flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10260 
10261 	ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10262 			    RTE_ETH_FDIR_MAX_FLEXLEN);
10263 	if (ret < 0) {
10264 		printf("error: Cannot parse flex payload input.\n");
10265 		return;
10266 	}
10267 
10268 	fdir_set_flex_payload(res->port_id, &flex_cfg);
10269 	cmd_reconfig_device_queue(res->port_id, 1, 1);
10270 }
10271 
10272 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10273 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10274 				 flow_director_flexpayload,
10275 				 "flow_director_flex_payload");
10276 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10277 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10278 			      port_id, UINT8);
10279 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10280 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10281 				 payload_layer, "raw#l2#l3#l4");
10282 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10283 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10284 				 payload_cfg, NULL);
10285 
10286 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10287 	.f = cmd_flow_director_flxpld_parsed,
10288 	.data = NULL,
10289 	.help_str = "flow_director_flexpayload ... : "
10290 		"Set flow director's flex payload on NIC",
10291 	.tokens = {
10292 		(void *)&cmd_flow_director_flexpayload,
10293 		(void *)&cmd_flow_director_flexpayload_port_id,
10294 		(void *)&cmd_flow_director_flexpayload_payload_layer,
10295 		(void *)&cmd_flow_director_flexpayload_payload_cfg,
10296 		NULL,
10297 	},
10298 };
10299 
10300 /* Generic flow interface command. */
10301 extern cmdline_parse_inst_t cmd_flow;
10302 
10303 /* *** Classification Filters Control *** */
10304 /* *** Get symmetric hash enable per port *** */
10305 struct cmd_get_sym_hash_ena_per_port_result {
10306 	cmdline_fixed_string_t get_sym_hash_ena_per_port;
10307 	uint8_t port_id;
10308 };
10309 
10310 static void
10311 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10312 				 __rte_unused struct cmdline *cl,
10313 				 __rte_unused void *data)
10314 {
10315 	struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10316 	struct rte_eth_hash_filter_info info;
10317 	int ret;
10318 
10319 	if (rte_eth_dev_filter_supported(res->port_id,
10320 				RTE_ETH_FILTER_HASH) < 0) {
10321 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10322 							res->port_id);
10323 		return;
10324 	}
10325 
10326 	memset(&info, 0, sizeof(info));
10327 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10328 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10329 						RTE_ETH_FILTER_GET, &info);
10330 
10331 	if (ret < 0) {
10332 		printf("Cannot get symmetric hash enable per port "
10333 					"on port %u\n", res->port_id);
10334 		return;
10335 	}
10336 
10337 	printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10338 				"enabled" : "disabled", res->port_id);
10339 }
10340 
10341 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10342 	TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10343 		get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10344 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10345 	TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10346 		port_id, UINT8);
10347 
10348 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10349 	.f = cmd_get_sym_hash_per_port_parsed,
10350 	.data = NULL,
10351 	.help_str = "get_sym_hash_ena_per_port <port_id>",
10352 	.tokens = {
10353 		(void *)&cmd_get_sym_hash_ena_per_port_all,
10354 		(void *)&cmd_get_sym_hash_ena_per_port_port_id,
10355 		NULL,
10356 	},
10357 };
10358 
10359 /* *** Set symmetric hash enable per port *** */
10360 struct cmd_set_sym_hash_ena_per_port_result {
10361 	cmdline_fixed_string_t set_sym_hash_ena_per_port;
10362 	cmdline_fixed_string_t enable;
10363 	uint8_t port_id;
10364 };
10365 
10366 static void
10367 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10368 				 __rte_unused struct cmdline *cl,
10369 				 __rte_unused void *data)
10370 {
10371 	struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10372 	struct rte_eth_hash_filter_info info;
10373 	int ret;
10374 
10375 	if (rte_eth_dev_filter_supported(res->port_id,
10376 				RTE_ETH_FILTER_HASH) < 0) {
10377 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10378 							res->port_id);
10379 		return;
10380 	}
10381 
10382 	memset(&info, 0, sizeof(info));
10383 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10384 	if (!strcmp(res->enable, "enable"))
10385 		info.info.enable = 1;
10386 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10387 					RTE_ETH_FILTER_SET, &info);
10388 	if (ret < 0) {
10389 		printf("Cannot set symmetric hash enable per port on "
10390 					"port %u\n", res->port_id);
10391 		return;
10392 	}
10393 	printf("Symmetric hash has been set to %s on port %u\n",
10394 					res->enable, res->port_id);
10395 }
10396 
10397 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10398 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10399 		set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10400 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10401 	TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10402 		port_id, UINT8);
10403 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10404 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10405 		enable, "enable#disable");
10406 
10407 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10408 	.f = cmd_set_sym_hash_per_port_parsed,
10409 	.data = NULL,
10410 	.help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10411 	.tokens = {
10412 		(void *)&cmd_set_sym_hash_ena_per_port_all,
10413 		(void *)&cmd_set_sym_hash_ena_per_port_port_id,
10414 		(void *)&cmd_set_sym_hash_ena_per_port_enable,
10415 		NULL,
10416 	},
10417 };
10418 
10419 /* Get global config of hash function */
10420 struct cmd_get_hash_global_config_result {
10421 	cmdline_fixed_string_t get_hash_global_config;
10422 	uint8_t port_id;
10423 };
10424 
10425 static char *
10426 flowtype_to_str(uint16_t ftype)
10427 {
10428 	uint16_t i;
10429 	static struct {
10430 		char str[16];
10431 		uint16_t ftype;
10432 	} ftype_table[] = {
10433 		{"ipv4", RTE_ETH_FLOW_IPV4},
10434 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10435 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10436 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10437 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10438 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10439 		{"ipv6", RTE_ETH_FLOW_IPV6},
10440 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10441 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10442 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10443 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10444 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10445 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10446 		{"port", RTE_ETH_FLOW_PORT},
10447 		{"vxlan", RTE_ETH_FLOW_VXLAN},
10448 		{"geneve", RTE_ETH_FLOW_GENEVE},
10449 		{"nvgre", RTE_ETH_FLOW_NVGRE},
10450 	};
10451 
10452 	for (i = 0; i < RTE_DIM(ftype_table); i++) {
10453 		if (ftype_table[i].ftype == ftype)
10454 			return ftype_table[i].str;
10455 	}
10456 
10457 	return NULL;
10458 }
10459 
10460 static void
10461 cmd_get_hash_global_config_parsed(void *parsed_result,
10462 				  __rte_unused struct cmdline *cl,
10463 				  __rte_unused void *data)
10464 {
10465 	struct cmd_get_hash_global_config_result *res = parsed_result;
10466 	struct rte_eth_hash_filter_info info;
10467 	uint32_t idx, offset;
10468 	uint16_t i;
10469 	char *str;
10470 	int ret;
10471 
10472 	if (rte_eth_dev_filter_supported(res->port_id,
10473 			RTE_ETH_FILTER_HASH) < 0) {
10474 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10475 							res->port_id);
10476 		return;
10477 	}
10478 
10479 	memset(&info, 0, sizeof(info));
10480 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10481 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10482 					RTE_ETH_FILTER_GET, &info);
10483 	if (ret < 0) {
10484 		printf("Cannot get hash global configurations by port %d\n",
10485 							res->port_id);
10486 		return;
10487 	}
10488 
10489 	switch (info.info.global_conf.hash_func) {
10490 	case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
10491 		printf("Hash function is Toeplitz\n");
10492 		break;
10493 	case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
10494 		printf("Hash function is Simple XOR\n");
10495 		break;
10496 	default:
10497 		printf("Unknown hash function\n");
10498 		break;
10499 	}
10500 
10501 	for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
10502 		idx = i / UINT32_BIT;
10503 		offset = i % UINT32_BIT;
10504 		if (!(info.info.global_conf.valid_bit_mask[idx] &
10505 						(1UL << offset)))
10506 			continue;
10507 		str = flowtype_to_str(i);
10508 		if (!str)
10509 			continue;
10510 		printf("Symmetric hash is %s globally for flow type %s "
10511 							"by port %d\n",
10512 			((info.info.global_conf.sym_hash_enable_mask[idx] &
10513 			(1UL << offset)) ? "enabled" : "disabled"), str,
10514 							res->port_id);
10515 	}
10516 }
10517 
10518 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
10519 	TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
10520 		get_hash_global_config, "get_hash_global_config");
10521 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
10522 	TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
10523 		port_id, UINT8);
10524 
10525 cmdline_parse_inst_t cmd_get_hash_global_config = {
10526 	.f = cmd_get_hash_global_config_parsed,
10527 	.data = NULL,
10528 	.help_str = "get_hash_global_config <port_id>",
10529 	.tokens = {
10530 		(void *)&cmd_get_hash_global_config_all,
10531 		(void *)&cmd_get_hash_global_config_port_id,
10532 		NULL,
10533 	},
10534 };
10535 
10536 /* Set global config of hash function */
10537 struct cmd_set_hash_global_config_result {
10538 	cmdline_fixed_string_t set_hash_global_config;
10539 	uint8_t port_id;
10540 	cmdline_fixed_string_t hash_func;
10541 	cmdline_fixed_string_t flow_type;
10542 	cmdline_fixed_string_t enable;
10543 };
10544 
10545 static void
10546 cmd_set_hash_global_config_parsed(void *parsed_result,
10547 				  __rte_unused struct cmdline *cl,
10548 				  __rte_unused void *data)
10549 {
10550 	struct cmd_set_hash_global_config_result *res = parsed_result;
10551 	struct rte_eth_hash_filter_info info;
10552 	uint32_t ftype, idx, offset;
10553 	int ret;
10554 
10555 	if (rte_eth_dev_filter_supported(res->port_id,
10556 				RTE_ETH_FILTER_HASH) < 0) {
10557 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10558 							res->port_id);
10559 		return;
10560 	}
10561 	memset(&info, 0, sizeof(info));
10562 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10563 	if (!strcmp(res->hash_func, "toeplitz"))
10564 		info.info.global_conf.hash_func =
10565 			RTE_ETH_HASH_FUNCTION_TOEPLITZ;
10566 	else if (!strcmp(res->hash_func, "simple_xor"))
10567 		info.info.global_conf.hash_func =
10568 			RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
10569 	else if (!strcmp(res->hash_func, "default"))
10570 		info.info.global_conf.hash_func =
10571 			RTE_ETH_HASH_FUNCTION_DEFAULT;
10572 
10573 	ftype = str2flowtype(res->flow_type);
10574 	idx = ftype / (CHAR_BIT * sizeof(uint32_t));
10575 	offset = ftype % (CHAR_BIT * sizeof(uint32_t));
10576 	info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
10577 	if (!strcmp(res->enable, "enable"))
10578 		info.info.global_conf.sym_hash_enable_mask[idx] |=
10579 						(1UL << offset);
10580 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10581 					RTE_ETH_FILTER_SET, &info);
10582 	if (ret < 0)
10583 		printf("Cannot set global hash configurations by port %d\n",
10584 							res->port_id);
10585 	else
10586 		printf("Global hash configurations have been set "
10587 			"succcessfully by port %d\n", res->port_id);
10588 }
10589 
10590 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
10591 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10592 		set_hash_global_config, "set_hash_global_config");
10593 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
10594 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
10595 		port_id, UINT8);
10596 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
10597 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10598 		hash_func, "toeplitz#simple_xor#default");
10599 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
10600 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10601 		flow_type,
10602 		"ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
10603 		"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10604 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
10605 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10606 		enable, "enable#disable");
10607 
10608 cmdline_parse_inst_t cmd_set_hash_global_config = {
10609 	.f = cmd_set_hash_global_config_parsed,
10610 	.data = NULL,
10611 	.help_str = "set_hash_global_config <port_id> "
10612 		"toeplitz|simple_xor|default "
10613 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10614 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
10615 		"l2_payload enable|disable",
10616 	.tokens = {
10617 		(void *)&cmd_set_hash_global_config_all,
10618 		(void *)&cmd_set_hash_global_config_port_id,
10619 		(void *)&cmd_set_hash_global_config_hash_func,
10620 		(void *)&cmd_set_hash_global_config_flow_type,
10621 		(void *)&cmd_set_hash_global_config_enable,
10622 		NULL,
10623 	},
10624 };
10625 
10626 /* Set hash input set */
10627 struct cmd_set_hash_input_set_result {
10628 	cmdline_fixed_string_t set_hash_input_set;
10629 	uint8_t port_id;
10630 	cmdline_fixed_string_t flow_type;
10631 	cmdline_fixed_string_t inset_field;
10632 	cmdline_fixed_string_t select;
10633 };
10634 
10635 static enum rte_eth_input_set_field
10636 str2inset(char *string)
10637 {
10638 	uint16_t i;
10639 
10640 	static const struct {
10641 		char str[32];
10642 		enum rte_eth_input_set_field inset;
10643 	} inset_table[] = {
10644 		{"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
10645 		{"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
10646 		{"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
10647 		{"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
10648 		{"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
10649 		{"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
10650 		{"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
10651 		{"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
10652 		{"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
10653 		{"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
10654 		{"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
10655 		{"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
10656 		{"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
10657 		{"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
10658 		{"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
10659 		{"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
10660 		{"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
10661 		{"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
10662 		{"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
10663 		{"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
10664 		{"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
10665 		{"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
10666 		{"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
10667 		{"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
10668 		{"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
10669 		{"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
10670 		{"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
10671 		{"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
10672 		{"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
10673 		{"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
10674 		{"none", RTE_ETH_INPUT_SET_NONE},
10675 	};
10676 
10677 	for (i = 0; i < RTE_DIM(inset_table); i++) {
10678 		if (!strcmp(string, inset_table[i].str))
10679 			return inset_table[i].inset;
10680 	}
10681 
10682 	return RTE_ETH_INPUT_SET_UNKNOWN;
10683 }
10684 
10685 static void
10686 cmd_set_hash_input_set_parsed(void *parsed_result,
10687 			      __rte_unused struct cmdline *cl,
10688 			      __rte_unused void *data)
10689 {
10690 	struct cmd_set_hash_input_set_result *res = parsed_result;
10691 	struct rte_eth_hash_filter_info info;
10692 
10693 	memset(&info, 0, sizeof(info));
10694 	info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
10695 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10696 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10697 	info.info.input_set_conf.inset_size = 1;
10698 	if (!strcmp(res->select, "select"))
10699 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10700 	else if (!strcmp(res->select, "add"))
10701 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10702 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10703 				RTE_ETH_FILTER_SET, &info);
10704 }
10705 
10706 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
10707 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10708 		set_hash_input_set, "set_hash_input_set");
10709 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
10710 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
10711 		port_id, UINT8);
10712 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
10713 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10714 		flow_type, NULL);
10715 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
10716 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10717 		inset_field,
10718 		"ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10719 		"ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
10720 		"udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
10721 		"sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
10722 		"fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
10723 		"fld-8th#none");
10724 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
10725 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10726 		select, "select#add");
10727 
10728 cmdline_parse_inst_t cmd_set_hash_input_set = {
10729 	.f = cmd_set_hash_input_set_parsed,
10730 	.data = NULL,
10731 	.help_str = "set_hash_input_set <port_id> "
10732 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10733 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
10734 	"ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
10735 	"ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
10736 	"tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
10737 	"gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
10738 	"fld-7th|fld-8th|none select|add",
10739 	.tokens = {
10740 		(void *)&cmd_set_hash_input_set_cmd,
10741 		(void *)&cmd_set_hash_input_set_port_id,
10742 		(void *)&cmd_set_hash_input_set_flow_type,
10743 		(void *)&cmd_set_hash_input_set_field,
10744 		(void *)&cmd_set_hash_input_set_select,
10745 		NULL,
10746 	},
10747 };
10748 
10749 /* Set flow director input set */
10750 struct cmd_set_fdir_input_set_result {
10751 	cmdline_fixed_string_t set_fdir_input_set;
10752 	uint8_t port_id;
10753 	cmdline_fixed_string_t flow_type;
10754 	cmdline_fixed_string_t inset_field;
10755 	cmdline_fixed_string_t select;
10756 };
10757 
10758 static void
10759 cmd_set_fdir_input_set_parsed(void *parsed_result,
10760 	__rte_unused struct cmdline *cl,
10761 	__rte_unused void *data)
10762 {
10763 	struct cmd_set_fdir_input_set_result *res = parsed_result;
10764 	struct rte_eth_fdir_filter_info info;
10765 
10766 	memset(&info, 0, sizeof(info));
10767 	info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
10768 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10769 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10770 	info.info.input_set_conf.inset_size = 1;
10771 	if (!strcmp(res->select, "select"))
10772 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10773 	else if (!strcmp(res->select, "add"))
10774 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10775 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10776 		RTE_ETH_FILTER_SET, &info);
10777 }
10778 
10779 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
10780 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10781 	set_fdir_input_set, "set_fdir_input_set");
10782 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
10783 	TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
10784 	port_id, UINT8);
10785 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
10786 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10787 	flow_type,
10788 	"ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10789 	"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10790 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
10791 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10792 	inset_field,
10793 	"ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10794 	"ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
10795 	"ipv6-hop-limits#udp-src-port#udp-dst-port#"
10796 	"tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
10797 	"sctp-veri-tag#none");
10798 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
10799 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10800 	select, "select#add");
10801 
10802 cmdline_parse_inst_t cmd_set_fdir_input_set = {
10803 	.f = cmd_set_fdir_input_set_parsed,
10804 	.data = NULL,
10805 	.help_str = "set_fdir_input_set <port_id> "
10806 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10807 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10808 	"ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
10809 	"ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
10810 	"ipv6-hop-limits|udp-src-port|udp-dst-port|"
10811 	"tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
10812 	"sctp-veri-tag|none select|add",
10813 	.tokens = {
10814 		(void *)&cmd_set_fdir_input_set_cmd,
10815 		(void *)&cmd_set_fdir_input_set_port_id,
10816 		(void *)&cmd_set_fdir_input_set_flow_type,
10817 		(void *)&cmd_set_fdir_input_set_field,
10818 		(void *)&cmd_set_fdir_input_set_select,
10819 		NULL,
10820 	},
10821 };
10822 
10823 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10824 struct cmd_mcast_addr_result {
10825 	cmdline_fixed_string_t mcast_addr_cmd;
10826 	cmdline_fixed_string_t what;
10827 	uint8_t port_num;
10828 	struct ether_addr mc_addr;
10829 };
10830 
10831 static void cmd_mcast_addr_parsed(void *parsed_result,
10832 		__attribute__((unused)) struct cmdline *cl,
10833 		__attribute__((unused)) void *data)
10834 {
10835 	struct cmd_mcast_addr_result *res = parsed_result;
10836 
10837 	if (!is_multicast_ether_addr(&res->mc_addr)) {
10838 		printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10839 		       res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10840 		       res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10841 		       res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10842 		return;
10843 	}
10844 	if (strcmp(res->what, "add") == 0)
10845 		mcast_addr_add(res->port_num, &res->mc_addr);
10846 	else
10847 		mcast_addr_remove(res->port_num, &res->mc_addr);
10848 }
10849 
10850 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10851 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10852 				 mcast_addr_cmd, "mcast_addr");
10853 cmdline_parse_token_string_t cmd_mcast_addr_what =
10854 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10855 				 "add#remove");
10856 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10857 	TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
10858 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10859 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10860 
10861 cmdline_parse_inst_t cmd_mcast_addr = {
10862 	.f = cmd_mcast_addr_parsed,
10863 	.data = (void *)0,
10864 	.help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10865 		"Add/Remove multicast MAC address on port_id",
10866 	.tokens = {
10867 		(void *)&cmd_mcast_addr_cmd,
10868 		(void *)&cmd_mcast_addr_what,
10869 		(void *)&cmd_mcast_addr_portnum,
10870 		(void *)&cmd_mcast_addr_addr,
10871 		NULL,
10872 	},
10873 };
10874 
10875 /* l2 tunnel config
10876  * only support E-tag now.
10877  */
10878 
10879 /* Ether type config */
10880 struct cmd_config_l2_tunnel_eth_type_result {
10881 	cmdline_fixed_string_t port;
10882 	cmdline_fixed_string_t config;
10883 	cmdline_fixed_string_t all;
10884 	uint8_t id;
10885 	cmdline_fixed_string_t l2_tunnel;
10886 	cmdline_fixed_string_t l2_tunnel_type;
10887 	cmdline_fixed_string_t eth_type;
10888 	uint16_t eth_type_val;
10889 };
10890 
10891 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10892 	TOKEN_STRING_INITIALIZER
10893 		(struct cmd_config_l2_tunnel_eth_type_result,
10894 		 port, "port");
10895 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10896 	TOKEN_STRING_INITIALIZER
10897 		(struct cmd_config_l2_tunnel_eth_type_result,
10898 		 config, "config");
10899 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10900 	TOKEN_STRING_INITIALIZER
10901 		(struct cmd_config_l2_tunnel_eth_type_result,
10902 		 all, "all");
10903 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10904 	TOKEN_NUM_INITIALIZER
10905 		(struct cmd_config_l2_tunnel_eth_type_result,
10906 		 id, UINT8);
10907 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10908 	TOKEN_STRING_INITIALIZER
10909 		(struct cmd_config_l2_tunnel_eth_type_result,
10910 		 l2_tunnel, "l2-tunnel");
10911 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10912 	TOKEN_STRING_INITIALIZER
10913 		(struct cmd_config_l2_tunnel_eth_type_result,
10914 		 l2_tunnel_type, "E-tag");
10915 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10916 	TOKEN_STRING_INITIALIZER
10917 		(struct cmd_config_l2_tunnel_eth_type_result,
10918 		 eth_type, "ether-type");
10919 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10920 	TOKEN_NUM_INITIALIZER
10921 		(struct cmd_config_l2_tunnel_eth_type_result,
10922 		 eth_type_val, UINT16);
10923 
10924 static enum rte_eth_tunnel_type
10925 str2fdir_l2_tunnel_type(char *string)
10926 {
10927 	uint32_t i = 0;
10928 
10929 	static const struct {
10930 		char str[32];
10931 		enum rte_eth_tunnel_type type;
10932 	} l2_tunnel_type_str[] = {
10933 		{"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10934 	};
10935 
10936 	for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10937 		if (!strcmp(l2_tunnel_type_str[i].str, string))
10938 			return l2_tunnel_type_str[i].type;
10939 	}
10940 	return RTE_TUNNEL_TYPE_NONE;
10941 }
10942 
10943 /* ether type config for all ports */
10944 static void
10945 cmd_config_l2_tunnel_eth_type_all_parsed
10946 	(void *parsed_result,
10947 	 __attribute__((unused)) struct cmdline *cl,
10948 	 __attribute__((unused)) void *data)
10949 {
10950 	struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10951 	struct rte_eth_l2_tunnel_conf entry;
10952 	portid_t pid;
10953 
10954 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10955 	entry.ether_type = res->eth_type_val;
10956 
10957 	RTE_ETH_FOREACH_DEV(pid) {
10958 		rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10959 	}
10960 }
10961 
10962 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10963 	.f = cmd_config_l2_tunnel_eth_type_all_parsed,
10964 	.data = NULL,
10965 	.help_str = "port config all l2-tunnel E-tag ether-type <value>",
10966 	.tokens = {
10967 		(void *)&cmd_config_l2_tunnel_eth_type_port,
10968 		(void *)&cmd_config_l2_tunnel_eth_type_config,
10969 		(void *)&cmd_config_l2_tunnel_eth_type_all_str,
10970 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10971 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10972 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10973 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10974 		NULL,
10975 	},
10976 };
10977 
10978 /* ether type config for a specific port */
10979 static void
10980 cmd_config_l2_tunnel_eth_type_specific_parsed(
10981 	void *parsed_result,
10982 	__attribute__((unused)) struct cmdline *cl,
10983 	__attribute__((unused)) void *data)
10984 {
10985 	struct cmd_config_l2_tunnel_eth_type_result *res =
10986 		 parsed_result;
10987 	struct rte_eth_l2_tunnel_conf entry;
10988 
10989 	if (port_id_is_invalid(res->id, ENABLED_WARN))
10990 		return;
10991 
10992 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10993 	entry.ether_type = res->eth_type_val;
10994 
10995 	rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10996 }
10997 
10998 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10999 	.f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11000 	.data = NULL,
11001 	.help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11002 	.tokens = {
11003 		(void *)&cmd_config_l2_tunnel_eth_type_port,
11004 		(void *)&cmd_config_l2_tunnel_eth_type_config,
11005 		(void *)&cmd_config_l2_tunnel_eth_type_id,
11006 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11007 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11008 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11009 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11010 		NULL,
11011 	},
11012 };
11013 
11014 /* Enable/disable l2 tunnel */
11015 struct cmd_config_l2_tunnel_en_dis_result {
11016 	cmdline_fixed_string_t port;
11017 	cmdline_fixed_string_t config;
11018 	cmdline_fixed_string_t all;
11019 	uint8_t id;
11020 	cmdline_fixed_string_t l2_tunnel;
11021 	cmdline_fixed_string_t l2_tunnel_type;
11022 	cmdline_fixed_string_t en_dis;
11023 };
11024 
11025 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11026 	TOKEN_STRING_INITIALIZER
11027 		(struct cmd_config_l2_tunnel_en_dis_result,
11028 		 port, "port");
11029 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11030 	TOKEN_STRING_INITIALIZER
11031 		(struct cmd_config_l2_tunnel_en_dis_result,
11032 		 config, "config");
11033 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11034 	TOKEN_STRING_INITIALIZER
11035 		(struct cmd_config_l2_tunnel_en_dis_result,
11036 		 all, "all");
11037 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11038 	TOKEN_NUM_INITIALIZER
11039 		(struct cmd_config_l2_tunnel_en_dis_result,
11040 		 id, UINT8);
11041 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11042 	TOKEN_STRING_INITIALIZER
11043 		(struct cmd_config_l2_tunnel_en_dis_result,
11044 		 l2_tunnel, "l2-tunnel");
11045 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11046 	TOKEN_STRING_INITIALIZER
11047 		(struct cmd_config_l2_tunnel_en_dis_result,
11048 		 l2_tunnel_type, "E-tag");
11049 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11050 	TOKEN_STRING_INITIALIZER
11051 		(struct cmd_config_l2_tunnel_en_dis_result,
11052 		 en_dis, "enable#disable");
11053 
11054 /* enable/disable l2 tunnel for all ports */
11055 static void
11056 cmd_config_l2_tunnel_en_dis_all_parsed(
11057 	void *parsed_result,
11058 	__attribute__((unused)) struct cmdline *cl,
11059 	__attribute__((unused)) void *data)
11060 {
11061 	struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11062 	struct rte_eth_l2_tunnel_conf entry;
11063 	portid_t pid;
11064 	uint8_t en;
11065 
11066 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11067 
11068 	if (!strcmp("enable", res->en_dis))
11069 		en = 1;
11070 	else
11071 		en = 0;
11072 
11073 	RTE_ETH_FOREACH_DEV(pid) {
11074 		rte_eth_dev_l2_tunnel_offload_set(pid,
11075 						  &entry,
11076 						  ETH_L2_TUNNEL_ENABLE_MASK,
11077 						  en);
11078 	}
11079 }
11080 
11081 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11082 	.f = cmd_config_l2_tunnel_en_dis_all_parsed,
11083 	.data = NULL,
11084 	.help_str = "port config all l2-tunnel E-tag enable|disable",
11085 	.tokens = {
11086 		(void *)&cmd_config_l2_tunnel_en_dis_port,
11087 		(void *)&cmd_config_l2_tunnel_en_dis_config,
11088 		(void *)&cmd_config_l2_tunnel_en_dis_all_str,
11089 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11090 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11091 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11092 		NULL,
11093 	},
11094 };
11095 
11096 /* enable/disable l2 tunnel for a port */
11097 static void
11098 cmd_config_l2_tunnel_en_dis_specific_parsed(
11099 	void *parsed_result,
11100 	__attribute__((unused)) struct cmdline *cl,
11101 	__attribute__((unused)) void *data)
11102 {
11103 	struct cmd_config_l2_tunnel_en_dis_result *res =
11104 		parsed_result;
11105 	struct rte_eth_l2_tunnel_conf entry;
11106 
11107 	if (port_id_is_invalid(res->id, ENABLED_WARN))
11108 		return;
11109 
11110 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11111 
11112 	if (!strcmp("enable", res->en_dis))
11113 		rte_eth_dev_l2_tunnel_offload_set(res->id,
11114 						  &entry,
11115 						  ETH_L2_TUNNEL_ENABLE_MASK,
11116 						  1);
11117 	else
11118 		rte_eth_dev_l2_tunnel_offload_set(res->id,
11119 						  &entry,
11120 						  ETH_L2_TUNNEL_ENABLE_MASK,
11121 						  0);
11122 }
11123 
11124 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11125 	.f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11126 	.data = NULL,
11127 	.help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11128 	.tokens = {
11129 		(void *)&cmd_config_l2_tunnel_en_dis_port,
11130 		(void *)&cmd_config_l2_tunnel_en_dis_config,
11131 		(void *)&cmd_config_l2_tunnel_en_dis_id,
11132 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11133 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11134 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11135 		NULL,
11136 	},
11137 };
11138 
11139 /* E-tag configuration */
11140 
11141 /* Common result structure for all E-tag configuration */
11142 struct cmd_config_e_tag_result {
11143 	cmdline_fixed_string_t e_tag;
11144 	cmdline_fixed_string_t set;
11145 	cmdline_fixed_string_t insertion;
11146 	cmdline_fixed_string_t stripping;
11147 	cmdline_fixed_string_t forwarding;
11148 	cmdline_fixed_string_t filter;
11149 	cmdline_fixed_string_t add;
11150 	cmdline_fixed_string_t del;
11151 	cmdline_fixed_string_t on;
11152 	cmdline_fixed_string_t off;
11153 	cmdline_fixed_string_t on_off;
11154 	cmdline_fixed_string_t port_tag_id;
11155 	uint32_t port_tag_id_val;
11156 	cmdline_fixed_string_t e_tag_id;
11157 	uint16_t e_tag_id_val;
11158 	cmdline_fixed_string_t dst_pool;
11159 	uint8_t dst_pool_val;
11160 	cmdline_fixed_string_t port;
11161 	uint8_t port_id;
11162 	cmdline_fixed_string_t vf;
11163 	uint8_t vf_id;
11164 };
11165 
11166 /* Common CLI fields for all E-tag configuration */
11167 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11168 	TOKEN_STRING_INITIALIZER
11169 		(struct cmd_config_e_tag_result,
11170 		 e_tag, "E-tag");
11171 cmdline_parse_token_string_t cmd_config_e_tag_set =
11172 	TOKEN_STRING_INITIALIZER
11173 		(struct cmd_config_e_tag_result,
11174 		 set, "set");
11175 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11176 	TOKEN_STRING_INITIALIZER
11177 		(struct cmd_config_e_tag_result,
11178 		 insertion, "insertion");
11179 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11180 	TOKEN_STRING_INITIALIZER
11181 		(struct cmd_config_e_tag_result,
11182 		 stripping, "stripping");
11183 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11184 	TOKEN_STRING_INITIALIZER
11185 		(struct cmd_config_e_tag_result,
11186 		 forwarding, "forwarding");
11187 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11188 	TOKEN_STRING_INITIALIZER
11189 		(struct cmd_config_e_tag_result,
11190 		 filter, "filter");
11191 cmdline_parse_token_string_t cmd_config_e_tag_add =
11192 	TOKEN_STRING_INITIALIZER
11193 		(struct cmd_config_e_tag_result,
11194 		 add, "add");
11195 cmdline_parse_token_string_t cmd_config_e_tag_del =
11196 	TOKEN_STRING_INITIALIZER
11197 		(struct cmd_config_e_tag_result,
11198 		 del, "del");
11199 cmdline_parse_token_string_t cmd_config_e_tag_on =
11200 	TOKEN_STRING_INITIALIZER
11201 		(struct cmd_config_e_tag_result,
11202 		 on, "on");
11203 cmdline_parse_token_string_t cmd_config_e_tag_off =
11204 	TOKEN_STRING_INITIALIZER
11205 		(struct cmd_config_e_tag_result,
11206 		 off, "off");
11207 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11208 	TOKEN_STRING_INITIALIZER
11209 		(struct cmd_config_e_tag_result,
11210 		 on_off, "on#off");
11211 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11212 	TOKEN_STRING_INITIALIZER
11213 		(struct cmd_config_e_tag_result,
11214 		 port_tag_id, "port-tag-id");
11215 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11216 	TOKEN_NUM_INITIALIZER
11217 		(struct cmd_config_e_tag_result,
11218 		 port_tag_id_val, UINT32);
11219 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11220 	TOKEN_STRING_INITIALIZER
11221 		(struct cmd_config_e_tag_result,
11222 		 e_tag_id, "e-tag-id");
11223 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11224 	TOKEN_NUM_INITIALIZER
11225 		(struct cmd_config_e_tag_result,
11226 		 e_tag_id_val, UINT16);
11227 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11228 	TOKEN_STRING_INITIALIZER
11229 		(struct cmd_config_e_tag_result,
11230 		 dst_pool, "dst-pool");
11231 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11232 	TOKEN_NUM_INITIALIZER
11233 		(struct cmd_config_e_tag_result,
11234 		 dst_pool_val, UINT8);
11235 cmdline_parse_token_string_t cmd_config_e_tag_port =
11236 	TOKEN_STRING_INITIALIZER
11237 		(struct cmd_config_e_tag_result,
11238 		 port, "port");
11239 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11240 	TOKEN_NUM_INITIALIZER
11241 		(struct cmd_config_e_tag_result,
11242 		 port_id, UINT8);
11243 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11244 	TOKEN_STRING_INITIALIZER
11245 		(struct cmd_config_e_tag_result,
11246 		 vf, "vf");
11247 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11248 	TOKEN_NUM_INITIALIZER
11249 		(struct cmd_config_e_tag_result,
11250 		 vf_id, UINT8);
11251 
11252 /* E-tag insertion configuration */
11253 static void
11254 cmd_config_e_tag_insertion_en_parsed(
11255 	void *parsed_result,
11256 	__attribute__((unused)) struct cmdline *cl,
11257 	__attribute__((unused)) void *data)
11258 {
11259 	struct cmd_config_e_tag_result *res =
11260 		parsed_result;
11261 	struct rte_eth_l2_tunnel_conf entry;
11262 
11263 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11264 		return;
11265 
11266 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11267 	entry.tunnel_id = res->port_tag_id_val;
11268 	entry.vf_id = res->vf_id;
11269 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11270 					  &entry,
11271 					  ETH_L2_TUNNEL_INSERTION_MASK,
11272 					  1);
11273 }
11274 
11275 static void
11276 cmd_config_e_tag_insertion_dis_parsed(
11277 	void *parsed_result,
11278 	__attribute__((unused)) struct cmdline *cl,
11279 	__attribute__((unused)) void *data)
11280 {
11281 	struct cmd_config_e_tag_result *res =
11282 		parsed_result;
11283 	struct rte_eth_l2_tunnel_conf entry;
11284 
11285 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11286 		return;
11287 
11288 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11289 	entry.vf_id = res->vf_id;
11290 
11291 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11292 					  &entry,
11293 					  ETH_L2_TUNNEL_INSERTION_MASK,
11294 					  0);
11295 }
11296 
11297 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11298 	.f = cmd_config_e_tag_insertion_en_parsed,
11299 	.data = NULL,
11300 	.help_str = "E-tag ... : E-tag insertion enable",
11301 	.tokens = {
11302 		(void *)&cmd_config_e_tag_e_tag,
11303 		(void *)&cmd_config_e_tag_set,
11304 		(void *)&cmd_config_e_tag_insertion,
11305 		(void *)&cmd_config_e_tag_on,
11306 		(void *)&cmd_config_e_tag_port_tag_id,
11307 		(void *)&cmd_config_e_tag_port_tag_id_val,
11308 		(void *)&cmd_config_e_tag_port,
11309 		(void *)&cmd_config_e_tag_port_id,
11310 		(void *)&cmd_config_e_tag_vf,
11311 		(void *)&cmd_config_e_tag_vf_id,
11312 		NULL,
11313 	},
11314 };
11315 
11316 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11317 	.f = cmd_config_e_tag_insertion_dis_parsed,
11318 	.data = NULL,
11319 	.help_str = "E-tag ... : E-tag insertion disable",
11320 	.tokens = {
11321 		(void *)&cmd_config_e_tag_e_tag,
11322 		(void *)&cmd_config_e_tag_set,
11323 		(void *)&cmd_config_e_tag_insertion,
11324 		(void *)&cmd_config_e_tag_off,
11325 		(void *)&cmd_config_e_tag_port,
11326 		(void *)&cmd_config_e_tag_port_id,
11327 		(void *)&cmd_config_e_tag_vf,
11328 		(void *)&cmd_config_e_tag_vf_id,
11329 		NULL,
11330 	},
11331 };
11332 
11333 /* E-tag stripping configuration */
11334 static void
11335 cmd_config_e_tag_stripping_parsed(
11336 	void *parsed_result,
11337 	__attribute__((unused)) struct cmdline *cl,
11338 	__attribute__((unused)) void *data)
11339 {
11340 	struct cmd_config_e_tag_result *res =
11341 		parsed_result;
11342 	struct rte_eth_l2_tunnel_conf entry;
11343 
11344 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11345 		return;
11346 
11347 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11348 
11349 	if (!strcmp(res->on_off, "on"))
11350 		rte_eth_dev_l2_tunnel_offload_set
11351 			(res->port_id,
11352 			 &entry,
11353 			 ETH_L2_TUNNEL_STRIPPING_MASK,
11354 			 1);
11355 	else
11356 		rte_eth_dev_l2_tunnel_offload_set
11357 			(res->port_id,
11358 			 &entry,
11359 			 ETH_L2_TUNNEL_STRIPPING_MASK,
11360 			 0);
11361 }
11362 
11363 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11364 	.f = cmd_config_e_tag_stripping_parsed,
11365 	.data = NULL,
11366 	.help_str = "E-tag ... : E-tag stripping enable/disable",
11367 	.tokens = {
11368 		(void *)&cmd_config_e_tag_e_tag,
11369 		(void *)&cmd_config_e_tag_set,
11370 		(void *)&cmd_config_e_tag_stripping,
11371 		(void *)&cmd_config_e_tag_on_off,
11372 		(void *)&cmd_config_e_tag_port,
11373 		(void *)&cmd_config_e_tag_port_id,
11374 		NULL,
11375 	},
11376 };
11377 
11378 /* E-tag forwarding configuration */
11379 static void
11380 cmd_config_e_tag_forwarding_parsed(
11381 	void *parsed_result,
11382 	__attribute__((unused)) struct cmdline *cl,
11383 	__attribute__((unused)) void *data)
11384 {
11385 	struct cmd_config_e_tag_result *res = parsed_result;
11386 	struct rte_eth_l2_tunnel_conf entry;
11387 
11388 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11389 		return;
11390 
11391 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11392 
11393 	if (!strcmp(res->on_off, "on"))
11394 		rte_eth_dev_l2_tunnel_offload_set
11395 			(res->port_id,
11396 			 &entry,
11397 			 ETH_L2_TUNNEL_FORWARDING_MASK,
11398 			 1);
11399 	else
11400 		rte_eth_dev_l2_tunnel_offload_set
11401 			(res->port_id,
11402 			 &entry,
11403 			 ETH_L2_TUNNEL_FORWARDING_MASK,
11404 			 0);
11405 }
11406 
11407 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11408 	.f = cmd_config_e_tag_forwarding_parsed,
11409 	.data = NULL,
11410 	.help_str = "E-tag ... : E-tag forwarding enable/disable",
11411 	.tokens = {
11412 		(void *)&cmd_config_e_tag_e_tag,
11413 		(void *)&cmd_config_e_tag_set,
11414 		(void *)&cmd_config_e_tag_forwarding,
11415 		(void *)&cmd_config_e_tag_on_off,
11416 		(void *)&cmd_config_e_tag_port,
11417 		(void *)&cmd_config_e_tag_port_id,
11418 		NULL,
11419 	},
11420 };
11421 
11422 /* E-tag filter configuration */
11423 static void
11424 cmd_config_e_tag_filter_add_parsed(
11425 	void *parsed_result,
11426 	__attribute__((unused)) struct cmdline *cl,
11427 	__attribute__((unused)) void *data)
11428 {
11429 	struct cmd_config_e_tag_result *res = parsed_result;
11430 	struct rte_eth_l2_tunnel_conf entry;
11431 	int ret = 0;
11432 
11433 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11434 		return;
11435 
11436 	if (res->e_tag_id_val > 0x3fff) {
11437 		printf("e-tag-id must be equal or less than 0x3fff.\n");
11438 		return;
11439 	}
11440 
11441 	ret = rte_eth_dev_filter_supported(res->port_id,
11442 					   RTE_ETH_FILTER_L2_TUNNEL);
11443 	if (ret < 0) {
11444 		printf("E-tag filter is not supported on port %u.\n",
11445 		       res->port_id);
11446 		return;
11447 	}
11448 
11449 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11450 	entry.tunnel_id = res->e_tag_id_val;
11451 	entry.pool = res->dst_pool_val;
11452 
11453 	ret = rte_eth_dev_filter_ctrl(res->port_id,
11454 				      RTE_ETH_FILTER_L2_TUNNEL,
11455 				      RTE_ETH_FILTER_ADD,
11456 				      &entry);
11457 	if (ret < 0)
11458 		printf("E-tag filter programming error: (%s)\n",
11459 		       strerror(-ret));
11460 }
11461 
11462 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
11463 	.f = cmd_config_e_tag_filter_add_parsed,
11464 	.data = NULL,
11465 	.help_str = "E-tag ... : E-tag filter add",
11466 	.tokens = {
11467 		(void *)&cmd_config_e_tag_e_tag,
11468 		(void *)&cmd_config_e_tag_set,
11469 		(void *)&cmd_config_e_tag_filter,
11470 		(void *)&cmd_config_e_tag_add,
11471 		(void *)&cmd_config_e_tag_e_tag_id,
11472 		(void *)&cmd_config_e_tag_e_tag_id_val,
11473 		(void *)&cmd_config_e_tag_dst_pool,
11474 		(void *)&cmd_config_e_tag_dst_pool_val,
11475 		(void *)&cmd_config_e_tag_port,
11476 		(void *)&cmd_config_e_tag_port_id,
11477 		NULL,
11478 	},
11479 };
11480 
11481 static void
11482 cmd_config_e_tag_filter_del_parsed(
11483 	void *parsed_result,
11484 	__attribute__((unused)) struct cmdline *cl,
11485 	__attribute__((unused)) void *data)
11486 {
11487 	struct cmd_config_e_tag_result *res = parsed_result;
11488 	struct rte_eth_l2_tunnel_conf entry;
11489 	int ret = 0;
11490 
11491 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11492 		return;
11493 
11494 	if (res->e_tag_id_val > 0x3fff) {
11495 		printf("e-tag-id must be less than 0x3fff.\n");
11496 		return;
11497 	}
11498 
11499 	ret = rte_eth_dev_filter_supported(res->port_id,
11500 					   RTE_ETH_FILTER_L2_TUNNEL);
11501 	if (ret < 0) {
11502 		printf("E-tag filter is not supported on port %u.\n",
11503 		       res->port_id);
11504 		return;
11505 	}
11506 
11507 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11508 	entry.tunnel_id = res->e_tag_id_val;
11509 
11510 	ret = rte_eth_dev_filter_ctrl(res->port_id,
11511 				      RTE_ETH_FILTER_L2_TUNNEL,
11512 				      RTE_ETH_FILTER_DELETE,
11513 				      &entry);
11514 	if (ret < 0)
11515 		printf("E-tag filter programming error: (%s)\n",
11516 		       strerror(-ret));
11517 }
11518 
11519 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
11520 	.f = cmd_config_e_tag_filter_del_parsed,
11521 	.data = NULL,
11522 	.help_str = "E-tag ... : E-tag filter delete",
11523 	.tokens = {
11524 		(void *)&cmd_config_e_tag_e_tag,
11525 		(void *)&cmd_config_e_tag_set,
11526 		(void *)&cmd_config_e_tag_filter,
11527 		(void *)&cmd_config_e_tag_del,
11528 		(void *)&cmd_config_e_tag_e_tag_id,
11529 		(void *)&cmd_config_e_tag_e_tag_id_val,
11530 		(void *)&cmd_config_e_tag_port,
11531 		(void *)&cmd_config_e_tag_port_id,
11532 		NULL,
11533 	},
11534 };
11535 
11536 /* vf vlan anti spoof configuration */
11537 
11538 /* Common result structure for vf vlan anti spoof */
11539 struct cmd_vf_vlan_anti_spoof_result {
11540 	cmdline_fixed_string_t set;
11541 	cmdline_fixed_string_t vf;
11542 	cmdline_fixed_string_t vlan;
11543 	cmdline_fixed_string_t antispoof;
11544 	uint8_t port_id;
11545 	uint32_t vf_id;
11546 	cmdline_fixed_string_t on_off;
11547 };
11548 
11549 /* Common CLI fields for vf vlan anti spoof enable disable */
11550 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11551 	TOKEN_STRING_INITIALIZER
11552 		(struct cmd_vf_vlan_anti_spoof_result,
11553 		 set, "set");
11554 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11555 	TOKEN_STRING_INITIALIZER
11556 		(struct cmd_vf_vlan_anti_spoof_result,
11557 		 vf, "vf");
11558 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11559 	TOKEN_STRING_INITIALIZER
11560 		(struct cmd_vf_vlan_anti_spoof_result,
11561 		 vlan, "vlan");
11562 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11563 	TOKEN_STRING_INITIALIZER
11564 		(struct cmd_vf_vlan_anti_spoof_result,
11565 		 antispoof, "antispoof");
11566 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11567 	TOKEN_NUM_INITIALIZER
11568 		(struct cmd_vf_vlan_anti_spoof_result,
11569 		 port_id, UINT8);
11570 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11571 	TOKEN_NUM_INITIALIZER
11572 		(struct cmd_vf_vlan_anti_spoof_result,
11573 		 vf_id, UINT32);
11574 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11575 	TOKEN_STRING_INITIALIZER
11576 		(struct cmd_vf_vlan_anti_spoof_result,
11577 		 on_off, "on#off");
11578 
11579 static void
11580 cmd_set_vf_vlan_anti_spoof_parsed(
11581 	void *parsed_result,
11582 	__attribute__((unused)) struct cmdline *cl,
11583 	__attribute__((unused)) void *data)
11584 {
11585 	struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11586 	int ret = -ENOTSUP;
11587 
11588 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11589 
11590 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11591 		return;
11592 
11593 #ifdef RTE_LIBRTE_IXGBE_PMD
11594 	if (ret == -ENOTSUP)
11595 		ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11596 				res->vf_id, is_on);
11597 #endif
11598 #ifdef RTE_LIBRTE_I40E_PMD
11599 	if (ret == -ENOTSUP)
11600 		ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11601 				res->vf_id, is_on);
11602 #endif
11603 #ifdef RTE_LIBRTE_BNXT_PMD
11604 	if (ret == -ENOTSUP)
11605 		ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11606 				res->vf_id, is_on);
11607 #endif
11608 
11609 	switch (ret) {
11610 	case 0:
11611 		break;
11612 	case -EINVAL:
11613 		printf("invalid vf_id %d\n", res->vf_id);
11614 		break;
11615 	case -ENODEV:
11616 		printf("invalid port_id %d\n", res->port_id);
11617 		break;
11618 	case -ENOTSUP:
11619 		printf("function not implemented\n");
11620 		break;
11621 	default:
11622 		printf("programming error: (%s)\n", strerror(-ret));
11623 	}
11624 }
11625 
11626 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11627 	.f = cmd_set_vf_vlan_anti_spoof_parsed,
11628 	.data = NULL,
11629 	.help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11630 	.tokens = {
11631 		(void *)&cmd_vf_vlan_anti_spoof_set,
11632 		(void *)&cmd_vf_vlan_anti_spoof_vf,
11633 		(void *)&cmd_vf_vlan_anti_spoof_vlan,
11634 		(void *)&cmd_vf_vlan_anti_spoof_antispoof,
11635 		(void *)&cmd_vf_vlan_anti_spoof_port_id,
11636 		(void *)&cmd_vf_vlan_anti_spoof_vf_id,
11637 		(void *)&cmd_vf_vlan_anti_spoof_on_off,
11638 		NULL,
11639 	},
11640 };
11641 
11642 /* vf mac anti spoof configuration */
11643 
11644 /* Common result structure for vf mac anti spoof */
11645 struct cmd_vf_mac_anti_spoof_result {
11646 	cmdline_fixed_string_t set;
11647 	cmdline_fixed_string_t vf;
11648 	cmdline_fixed_string_t mac;
11649 	cmdline_fixed_string_t antispoof;
11650 	uint8_t port_id;
11651 	uint32_t vf_id;
11652 	cmdline_fixed_string_t on_off;
11653 };
11654 
11655 /* Common CLI fields for vf mac anti spoof enable disable */
11656 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11657 	TOKEN_STRING_INITIALIZER
11658 		(struct cmd_vf_mac_anti_spoof_result,
11659 		 set, "set");
11660 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11661 	TOKEN_STRING_INITIALIZER
11662 		(struct cmd_vf_mac_anti_spoof_result,
11663 		 vf, "vf");
11664 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11665 	TOKEN_STRING_INITIALIZER
11666 		(struct cmd_vf_mac_anti_spoof_result,
11667 		 mac, "mac");
11668 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11669 	TOKEN_STRING_INITIALIZER
11670 		(struct cmd_vf_mac_anti_spoof_result,
11671 		 antispoof, "antispoof");
11672 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11673 	TOKEN_NUM_INITIALIZER
11674 		(struct cmd_vf_mac_anti_spoof_result,
11675 		 port_id, UINT8);
11676 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11677 	TOKEN_NUM_INITIALIZER
11678 		(struct cmd_vf_mac_anti_spoof_result,
11679 		 vf_id, UINT32);
11680 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11681 	TOKEN_STRING_INITIALIZER
11682 		(struct cmd_vf_mac_anti_spoof_result,
11683 		 on_off, "on#off");
11684 
11685 static void
11686 cmd_set_vf_mac_anti_spoof_parsed(
11687 	void *parsed_result,
11688 	__attribute__((unused)) struct cmdline *cl,
11689 	__attribute__((unused)) void *data)
11690 {
11691 	struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11692 	int ret = -ENOTSUP;
11693 
11694 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11695 
11696 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11697 		return;
11698 
11699 #ifdef RTE_LIBRTE_IXGBE_PMD
11700 	if (ret == -ENOTSUP)
11701 		ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11702 			res->vf_id, is_on);
11703 #endif
11704 #ifdef RTE_LIBRTE_I40E_PMD
11705 	if (ret == -ENOTSUP)
11706 		ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11707 			res->vf_id, is_on);
11708 #endif
11709 #ifdef RTE_LIBRTE_BNXT_PMD
11710 	if (ret == -ENOTSUP)
11711 		ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11712 			res->vf_id, is_on);
11713 #endif
11714 
11715 	switch (ret) {
11716 	case 0:
11717 		break;
11718 	case -EINVAL:
11719 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11720 		break;
11721 	case -ENODEV:
11722 		printf("invalid port_id %d\n", res->port_id);
11723 		break;
11724 	case -ENOTSUP:
11725 		printf("function not implemented\n");
11726 		break;
11727 	default:
11728 		printf("programming error: (%s)\n", strerror(-ret));
11729 	}
11730 }
11731 
11732 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11733 	.f = cmd_set_vf_mac_anti_spoof_parsed,
11734 	.data = NULL,
11735 	.help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11736 	.tokens = {
11737 		(void *)&cmd_vf_mac_anti_spoof_set,
11738 		(void *)&cmd_vf_mac_anti_spoof_vf,
11739 		(void *)&cmd_vf_mac_anti_spoof_mac,
11740 		(void *)&cmd_vf_mac_anti_spoof_antispoof,
11741 		(void *)&cmd_vf_mac_anti_spoof_port_id,
11742 		(void *)&cmd_vf_mac_anti_spoof_vf_id,
11743 		(void *)&cmd_vf_mac_anti_spoof_on_off,
11744 		NULL,
11745 	},
11746 };
11747 
11748 /* vf vlan strip queue configuration */
11749 
11750 /* Common result structure for vf mac anti spoof */
11751 struct cmd_vf_vlan_stripq_result {
11752 	cmdline_fixed_string_t set;
11753 	cmdline_fixed_string_t vf;
11754 	cmdline_fixed_string_t vlan;
11755 	cmdline_fixed_string_t stripq;
11756 	portid_t port_id;
11757 	uint16_t vf_id;
11758 	cmdline_fixed_string_t on_off;
11759 };
11760 
11761 /* Common CLI fields for vf vlan strip enable disable */
11762 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11763 	TOKEN_STRING_INITIALIZER
11764 		(struct cmd_vf_vlan_stripq_result,
11765 		 set, "set");
11766 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11767 	TOKEN_STRING_INITIALIZER
11768 		(struct cmd_vf_vlan_stripq_result,
11769 		 vf, "vf");
11770 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11771 	TOKEN_STRING_INITIALIZER
11772 		(struct cmd_vf_vlan_stripq_result,
11773 		 vlan, "vlan");
11774 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11775 	TOKEN_STRING_INITIALIZER
11776 		(struct cmd_vf_vlan_stripq_result,
11777 		 stripq, "stripq");
11778 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11779 	TOKEN_NUM_INITIALIZER
11780 		(struct cmd_vf_vlan_stripq_result,
11781 		 port_id, UINT8);
11782 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11783 	TOKEN_NUM_INITIALIZER
11784 		(struct cmd_vf_vlan_stripq_result,
11785 		 vf_id, UINT16);
11786 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11787 	TOKEN_STRING_INITIALIZER
11788 		(struct cmd_vf_vlan_stripq_result,
11789 		 on_off, "on#off");
11790 
11791 static void
11792 cmd_set_vf_vlan_stripq_parsed(
11793 	void *parsed_result,
11794 	__attribute__((unused)) struct cmdline *cl,
11795 	__attribute__((unused)) void *data)
11796 {
11797 	struct cmd_vf_vlan_stripq_result *res = parsed_result;
11798 	int ret = -ENOTSUP;
11799 
11800 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11801 
11802 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11803 		return;
11804 
11805 #ifdef RTE_LIBRTE_IXGBE_PMD
11806 	if (ret == -ENOTSUP)
11807 		ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11808 			res->vf_id, is_on);
11809 #endif
11810 #ifdef RTE_LIBRTE_I40E_PMD
11811 	if (ret == -ENOTSUP)
11812 		ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11813 			res->vf_id, is_on);
11814 #endif
11815 #ifdef RTE_LIBRTE_BNXT_PMD
11816 	if (ret == -ENOTSUP)
11817 		ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11818 			res->vf_id, is_on);
11819 #endif
11820 
11821 	switch (ret) {
11822 	case 0:
11823 		break;
11824 	case -EINVAL:
11825 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11826 		break;
11827 	case -ENODEV:
11828 		printf("invalid port_id %d\n", res->port_id);
11829 		break;
11830 	case -ENOTSUP:
11831 		printf("function not implemented\n");
11832 		break;
11833 	default:
11834 		printf("programming error: (%s)\n", strerror(-ret));
11835 	}
11836 }
11837 
11838 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11839 	.f = cmd_set_vf_vlan_stripq_parsed,
11840 	.data = NULL,
11841 	.help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11842 	.tokens = {
11843 		(void *)&cmd_vf_vlan_stripq_set,
11844 		(void *)&cmd_vf_vlan_stripq_vf,
11845 		(void *)&cmd_vf_vlan_stripq_vlan,
11846 		(void *)&cmd_vf_vlan_stripq_stripq,
11847 		(void *)&cmd_vf_vlan_stripq_port_id,
11848 		(void *)&cmd_vf_vlan_stripq_vf_id,
11849 		(void *)&cmd_vf_vlan_stripq_on_off,
11850 		NULL,
11851 	},
11852 };
11853 
11854 /* vf vlan insert configuration */
11855 
11856 /* Common result structure for vf vlan insert */
11857 struct cmd_vf_vlan_insert_result {
11858 	cmdline_fixed_string_t set;
11859 	cmdline_fixed_string_t vf;
11860 	cmdline_fixed_string_t vlan;
11861 	cmdline_fixed_string_t insert;
11862 	uint8_t port_id;
11863 	uint16_t vf_id;
11864 	uint16_t vlan_id;
11865 };
11866 
11867 /* Common CLI fields for vf vlan insert enable disable */
11868 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11869 	TOKEN_STRING_INITIALIZER
11870 		(struct cmd_vf_vlan_insert_result,
11871 		 set, "set");
11872 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11873 	TOKEN_STRING_INITIALIZER
11874 		(struct cmd_vf_vlan_insert_result,
11875 		 vf, "vf");
11876 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11877 	TOKEN_STRING_INITIALIZER
11878 		(struct cmd_vf_vlan_insert_result,
11879 		 vlan, "vlan");
11880 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11881 	TOKEN_STRING_INITIALIZER
11882 		(struct cmd_vf_vlan_insert_result,
11883 		 insert, "insert");
11884 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11885 	TOKEN_NUM_INITIALIZER
11886 		(struct cmd_vf_vlan_insert_result,
11887 		 port_id, UINT8);
11888 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11889 	TOKEN_NUM_INITIALIZER
11890 		(struct cmd_vf_vlan_insert_result,
11891 		 vf_id, UINT16);
11892 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11893 	TOKEN_NUM_INITIALIZER
11894 		(struct cmd_vf_vlan_insert_result,
11895 		 vlan_id, UINT16);
11896 
11897 static void
11898 cmd_set_vf_vlan_insert_parsed(
11899 	void *parsed_result,
11900 	__attribute__((unused)) struct cmdline *cl,
11901 	__attribute__((unused)) void *data)
11902 {
11903 	struct cmd_vf_vlan_insert_result *res = parsed_result;
11904 	int ret = -ENOTSUP;
11905 
11906 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11907 		return;
11908 
11909 #ifdef RTE_LIBRTE_IXGBE_PMD
11910 	if (ret == -ENOTSUP)
11911 		ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11912 			res->vlan_id);
11913 #endif
11914 #ifdef RTE_LIBRTE_I40E_PMD
11915 	if (ret == -ENOTSUP)
11916 		ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11917 			res->vlan_id);
11918 #endif
11919 #ifdef RTE_LIBRTE_BNXT_PMD
11920 	if (ret == -ENOTSUP)
11921 		ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11922 			res->vlan_id);
11923 #endif
11924 
11925 	switch (ret) {
11926 	case 0:
11927 		break;
11928 	case -EINVAL:
11929 		printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11930 		break;
11931 	case -ENODEV:
11932 		printf("invalid port_id %d\n", res->port_id);
11933 		break;
11934 	case -ENOTSUP:
11935 		printf("function not implemented\n");
11936 		break;
11937 	default:
11938 		printf("programming error: (%s)\n", strerror(-ret));
11939 	}
11940 }
11941 
11942 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11943 	.f = cmd_set_vf_vlan_insert_parsed,
11944 	.data = NULL,
11945 	.help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11946 	.tokens = {
11947 		(void *)&cmd_vf_vlan_insert_set,
11948 		(void *)&cmd_vf_vlan_insert_vf,
11949 		(void *)&cmd_vf_vlan_insert_vlan,
11950 		(void *)&cmd_vf_vlan_insert_insert,
11951 		(void *)&cmd_vf_vlan_insert_port_id,
11952 		(void *)&cmd_vf_vlan_insert_vf_id,
11953 		(void *)&cmd_vf_vlan_insert_vlan_id,
11954 		NULL,
11955 	},
11956 };
11957 
11958 /* tx loopback configuration */
11959 
11960 /* Common result structure for tx loopback */
11961 struct cmd_tx_loopback_result {
11962 	cmdline_fixed_string_t set;
11963 	cmdline_fixed_string_t tx;
11964 	cmdline_fixed_string_t loopback;
11965 	uint8_t port_id;
11966 	cmdline_fixed_string_t on_off;
11967 };
11968 
11969 /* Common CLI fields for tx loopback enable disable */
11970 cmdline_parse_token_string_t cmd_tx_loopback_set =
11971 	TOKEN_STRING_INITIALIZER
11972 		(struct cmd_tx_loopback_result,
11973 		 set, "set");
11974 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11975 	TOKEN_STRING_INITIALIZER
11976 		(struct cmd_tx_loopback_result,
11977 		 tx, "tx");
11978 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11979 	TOKEN_STRING_INITIALIZER
11980 		(struct cmd_tx_loopback_result,
11981 		 loopback, "loopback");
11982 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11983 	TOKEN_NUM_INITIALIZER
11984 		(struct cmd_tx_loopback_result,
11985 		 port_id, UINT8);
11986 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11987 	TOKEN_STRING_INITIALIZER
11988 		(struct cmd_tx_loopback_result,
11989 		 on_off, "on#off");
11990 
11991 static void
11992 cmd_set_tx_loopback_parsed(
11993 	void *parsed_result,
11994 	__attribute__((unused)) struct cmdline *cl,
11995 	__attribute__((unused)) void *data)
11996 {
11997 	struct cmd_tx_loopback_result *res = parsed_result;
11998 	int ret = -ENOTSUP;
11999 
12000 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12001 
12002 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12003 		return;
12004 
12005 #ifdef RTE_LIBRTE_IXGBE_PMD
12006 	if (ret == -ENOTSUP)
12007 		ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12008 #endif
12009 #ifdef RTE_LIBRTE_I40E_PMD
12010 	if (ret == -ENOTSUP)
12011 		ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12012 #endif
12013 #ifdef RTE_LIBRTE_BNXT_PMD
12014 	if (ret == -ENOTSUP)
12015 		ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12016 #endif
12017 
12018 	switch (ret) {
12019 	case 0:
12020 		break;
12021 	case -EINVAL:
12022 		printf("invalid is_on %d\n", is_on);
12023 		break;
12024 	case -ENODEV:
12025 		printf("invalid port_id %d\n", res->port_id);
12026 		break;
12027 	case -ENOTSUP:
12028 		printf("function not implemented\n");
12029 		break;
12030 	default:
12031 		printf("programming error: (%s)\n", strerror(-ret));
12032 	}
12033 }
12034 
12035 cmdline_parse_inst_t cmd_set_tx_loopback = {
12036 	.f = cmd_set_tx_loopback_parsed,
12037 	.data = NULL,
12038 	.help_str = "set tx loopback <port_id> on|off",
12039 	.tokens = {
12040 		(void *)&cmd_tx_loopback_set,
12041 		(void *)&cmd_tx_loopback_tx,
12042 		(void *)&cmd_tx_loopback_loopback,
12043 		(void *)&cmd_tx_loopback_port_id,
12044 		(void *)&cmd_tx_loopback_on_off,
12045 		NULL,
12046 	},
12047 };
12048 
12049 /* all queues drop enable configuration */
12050 
12051 /* Common result structure for all queues drop enable */
12052 struct cmd_all_queues_drop_en_result {
12053 	cmdline_fixed_string_t set;
12054 	cmdline_fixed_string_t all;
12055 	cmdline_fixed_string_t queues;
12056 	cmdline_fixed_string_t drop;
12057 	uint8_t port_id;
12058 	cmdline_fixed_string_t on_off;
12059 };
12060 
12061 /* Common CLI fields for tx loopback enable disable */
12062 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12063 	TOKEN_STRING_INITIALIZER
12064 		(struct cmd_all_queues_drop_en_result,
12065 		 set, "set");
12066 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12067 	TOKEN_STRING_INITIALIZER
12068 		(struct cmd_all_queues_drop_en_result,
12069 		 all, "all");
12070 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12071 	TOKEN_STRING_INITIALIZER
12072 		(struct cmd_all_queues_drop_en_result,
12073 		 queues, "queues");
12074 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12075 	TOKEN_STRING_INITIALIZER
12076 		(struct cmd_all_queues_drop_en_result,
12077 		 drop, "drop");
12078 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12079 	TOKEN_NUM_INITIALIZER
12080 		(struct cmd_all_queues_drop_en_result,
12081 		 port_id, UINT8);
12082 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12083 	TOKEN_STRING_INITIALIZER
12084 		(struct cmd_all_queues_drop_en_result,
12085 		 on_off, "on#off");
12086 
12087 static void
12088 cmd_set_all_queues_drop_en_parsed(
12089 	void *parsed_result,
12090 	__attribute__((unused)) struct cmdline *cl,
12091 	__attribute__((unused)) void *data)
12092 {
12093 	struct cmd_all_queues_drop_en_result *res = parsed_result;
12094 	int ret = -ENOTSUP;
12095 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12096 
12097 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12098 		return;
12099 
12100 #ifdef RTE_LIBRTE_IXGBE_PMD
12101 	if (ret == -ENOTSUP)
12102 		ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12103 #endif
12104 #ifdef RTE_LIBRTE_BNXT_PMD
12105 	if (ret == -ENOTSUP)
12106 		ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12107 #endif
12108 	switch (ret) {
12109 	case 0:
12110 		break;
12111 	case -EINVAL:
12112 		printf("invalid is_on %d\n", is_on);
12113 		break;
12114 	case -ENODEV:
12115 		printf("invalid port_id %d\n", res->port_id);
12116 		break;
12117 	case -ENOTSUP:
12118 		printf("function not implemented\n");
12119 		break;
12120 	default:
12121 		printf("programming error: (%s)\n", strerror(-ret));
12122 	}
12123 }
12124 
12125 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12126 	.f = cmd_set_all_queues_drop_en_parsed,
12127 	.data = NULL,
12128 	.help_str = "set all queues drop <port_id> on|off",
12129 	.tokens = {
12130 		(void *)&cmd_all_queues_drop_en_set,
12131 		(void *)&cmd_all_queues_drop_en_all,
12132 		(void *)&cmd_all_queues_drop_en_queues,
12133 		(void *)&cmd_all_queues_drop_en_drop,
12134 		(void *)&cmd_all_queues_drop_en_port_id,
12135 		(void *)&cmd_all_queues_drop_en_on_off,
12136 		NULL,
12137 	},
12138 };
12139 
12140 /* vf split drop enable configuration */
12141 
12142 /* Common result structure for vf split drop enable */
12143 struct cmd_vf_split_drop_en_result {
12144 	cmdline_fixed_string_t set;
12145 	cmdline_fixed_string_t vf;
12146 	cmdline_fixed_string_t split;
12147 	cmdline_fixed_string_t drop;
12148 	uint8_t port_id;
12149 	uint16_t vf_id;
12150 	cmdline_fixed_string_t on_off;
12151 };
12152 
12153 /* Common CLI fields for vf split drop enable disable */
12154 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12155 	TOKEN_STRING_INITIALIZER
12156 		(struct cmd_vf_split_drop_en_result,
12157 		 set, "set");
12158 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12159 	TOKEN_STRING_INITIALIZER
12160 		(struct cmd_vf_split_drop_en_result,
12161 		 vf, "vf");
12162 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12163 	TOKEN_STRING_INITIALIZER
12164 		(struct cmd_vf_split_drop_en_result,
12165 		 split, "split");
12166 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12167 	TOKEN_STRING_INITIALIZER
12168 		(struct cmd_vf_split_drop_en_result,
12169 		 drop, "drop");
12170 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12171 	TOKEN_NUM_INITIALIZER
12172 		(struct cmd_vf_split_drop_en_result,
12173 		 port_id, UINT8);
12174 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12175 	TOKEN_NUM_INITIALIZER
12176 		(struct cmd_vf_split_drop_en_result,
12177 		 vf_id, UINT16);
12178 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12179 	TOKEN_STRING_INITIALIZER
12180 		(struct cmd_vf_split_drop_en_result,
12181 		 on_off, "on#off");
12182 
12183 static void
12184 cmd_set_vf_split_drop_en_parsed(
12185 	void *parsed_result,
12186 	__attribute__((unused)) struct cmdline *cl,
12187 	__attribute__((unused)) void *data)
12188 {
12189 	struct cmd_vf_split_drop_en_result *res = parsed_result;
12190 	int ret = -ENOTSUP;
12191 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12192 
12193 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12194 		return;
12195 
12196 #ifdef RTE_LIBRTE_IXGBE_PMD
12197 	ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12198 			is_on);
12199 #endif
12200 	switch (ret) {
12201 	case 0:
12202 		break;
12203 	case -EINVAL:
12204 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12205 		break;
12206 	case -ENODEV:
12207 		printf("invalid port_id %d\n", res->port_id);
12208 		break;
12209 	case -ENOTSUP:
12210 		printf("not supported on port %d\n", res->port_id);
12211 		break;
12212 	default:
12213 		printf("programming error: (%s)\n", strerror(-ret));
12214 	}
12215 }
12216 
12217 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12218 	.f = cmd_set_vf_split_drop_en_parsed,
12219 	.data = NULL,
12220 	.help_str = "set vf split drop <port_id> <vf_id> on|off",
12221 	.tokens = {
12222 		(void *)&cmd_vf_split_drop_en_set,
12223 		(void *)&cmd_vf_split_drop_en_vf,
12224 		(void *)&cmd_vf_split_drop_en_split,
12225 		(void *)&cmd_vf_split_drop_en_drop,
12226 		(void *)&cmd_vf_split_drop_en_port_id,
12227 		(void *)&cmd_vf_split_drop_en_vf_id,
12228 		(void *)&cmd_vf_split_drop_en_on_off,
12229 		NULL,
12230 	},
12231 };
12232 
12233 /* vf mac address configuration */
12234 
12235 /* Common result structure for vf mac address */
12236 struct cmd_set_vf_mac_addr_result {
12237 	cmdline_fixed_string_t set;
12238 	cmdline_fixed_string_t vf;
12239 	cmdline_fixed_string_t mac;
12240 	cmdline_fixed_string_t addr;
12241 	uint8_t port_id;
12242 	uint16_t vf_id;
12243 	struct ether_addr mac_addr;
12244 
12245 };
12246 
12247 /* Common CLI fields for vf split drop enable disable */
12248 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12249 	TOKEN_STRING_INITIALIZER
12250 		(struct cmd_set_vf_mac_addr_result,
12251 		 set, "set");
12252 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12253 	TOKEN_STRING_INITIALIZER
12254 		(struct cmd_set_vf_mac_addr_result,
12255 		 vf, "vf");
12256 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12257 	TOKEN_STRING_INITIALIZER
12258 		(struct cmd_set_vf_mac_addr_result,
12259 		 mac, "mac");
12260 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12261 	TOKEN_STRING_INITIALIZER
12262 		(struct cmd_set_vf_mac_addr_result,
12263 		 addr, "addr");
12264 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12265 	TOKEN_NUM_INITIALIZER
12266 		(struct cmd_set_vf_mac_addr_result,
12267 		 port_id, UINT8);
12268 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12269 	TOKEN_NUM_INITIALIZER
12270 		(struct cmd_set_vf_mac_addr_result,
12271 		 vf_id, UINT16);
12272 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12273 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12274 		 mac_addr);
12275 
12276 static void
12277 cmd_set_vf_mac_addr_parsed(
12278 	void *parsed_result,
12279 	__attribute__((unused)) struct cmdline *cl,
12280 	__attribute__((unused)) void *data)
12281 {
12282 	struct cmd_set_vf_mac_addr_result *res = parsed_result;
12283 	int ret = -ENOTSUP;
12284 
12285 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12286 		return;
12287 
12288 #ifdef RTE_LIBRTE_IXGBE_PMD
12289 	if (ret == -ENOTSUP)
12290 		ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12291 				&res->mac_addr);
12292 #endif
12293 #ifdef RTE_LIBRTE_I40E_PMD
12294 	if (ret == -ENOTSUP)
12295 		ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12296 				&res->mac_addr);
12297 #endif
12298 #ifdef RTE_LIBRTE_BNXT_PMD
12299 	if (ret == -ENOTSUP)
12300 		ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12301 				&res->mac_addr);
12302 #endif
12303 
12304 	switch (ret) {
12305 	case 0:
12306 		break;
12307 	case -EINVAL:
12308 		printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12309 		break;
12310 	case -ENODEV:
12311 		printf("invalid port_id %d\n", res->port_id);
12312 		break;
12313 	case -ENOTSUP:
12314 		printf("function not implemented\n");
12315 		break;
12316 	default:
12317 		printf("programming error: (%s)\n", strerror(-ret));
12318 	}
12319 }
12320 
12321 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12322 	.f = cmd_set_vf_mac_addr_parsed,
12323 	.data = NULL,
12324 	.help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12325 	.tokens = {
12326 		(void *)&cmd_set_vf_mac_addr_set,
12327 		(void *)&cmd_set_vf_mac_addr_vf,
12328 		(void *)&cmd_set_vf_mac_addr_mac,
12329 		(void *)&cmd_set_vf_mac_addr_addr,
12330 		(void *)&cmd_set_vf_mac_addr_port_id,
12331 		(void *)&cmd_set_vf_mac_addr_vf_id,
12332 		(void *)&cmd_set_vf_mac_addr_mac_addr,
12333 		NULL,
12334 	},
12335 };
12336 
12337 /* MACsec configuration */
12338 
12339 /* Common result structure for MACsec offload enable */
12340 struct cmd_macsec_offload_on_result {
12341 	cmdline_fixed_string_t set;
12342 	cmdline_fixed_string_t macsec;
12343 	cmdline_fixed_string_t offload;
12344 	uint8_t port_id;
12345 	cmdline_fixed_string_t on;
12346 	cmdline_fixed_string_t encrypt;
12347 	cmdline_fixed_string_t en_on_off;
12348 	cmdline_fixed_string_t replay_protect;
12349 	cmdline_fixed_string_t rp_on_off;
12350 };
12351 
12352 /* Common CLI fields for MACsec offload disable */
12353 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12354 	TOKEN_STRING_INITIALIZER
12355 		(struct cmd_macsec_offload_on_result,
12356 		 set, "set");
12357 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12358 	TOKEN_STRING_INITIALIZER
12359 		(struct cmd_macsec_offload_on_result,
12360 		 macsec, "macsec");
12361 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12362 	TOKEN_STRING_INITIALIZER
12363 		(struct cmd_macsec_offload_on_result,
12364 		 offload, "offload");
12365 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12366 	TOKEN_NUM_INITIALIZER
12367 		(struct cmd_macsec_offload_on_result,
12368 		 port_id, UINT8);
12369 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12370 	TOKEN_STRING_INITIALIZER
12371 		(struct cmd_macsec_offload_on_result,
12372 		 on, "on");
12373 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12374 	TOKEN_STRING_INITIALIZER
12375 		(struct cmd_macsec_offload_on_result,
12376 		 encrypt, "encrypt");
12377 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12378 	TOKEN_STRING_INITIALIZER
12379 		(struct cmd_macsec_offload_on_result,
12380 		 en_on_off, "on#off");
12381 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12382 	TOKEN_STRING_INITIALIZER
12383 		(struct cmd_macsec_offload_on_result,
12384 		 replay_protect, "replay-protect");
12385 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12386 	TOKEN_STRING_INITIALIZER
12387 		(struct cmd_macsec_offload_on_result,
12388 		 rp_on_off, "on#off");
12389 
12390 static void
12391 cmd_set_macsec_offload_on_parsed(
12392 	void *parsed_result,
12393 	__attribute__((unused)) struct cmdline *cl,
12394 	__attribute__((unused)) void *data)
12395 {
12396 	struct cmd_macsec_offload_on_result *res = parsed_result;
12397 	int ret = -ENOTSUP;
12398 	portid_t port_id = res->port_id;
12399 	int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12400 	int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12401 
12402 	if (port_id_is_invalid(port_id, ENABLED_WARN))
12403 		return;
12404 
12405 	ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12406 #ifdef RTE_LIBRTE_IXGBE_PMD
12407 	ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12408 #endif
12409 	RTE_SET_USED(en);
12410 	RTE_SET_USED(rp);
12411 
12412 	switch (ret) {
12413 	case 0:
12414 		break;
12415 	case -ENODEV:
12416 		printf("invalid port_id %d\n", port_id);
12417 		break;
12418 	case -ENOTSUP:
12419 		printf("not supported on port %d\n", port_id);
12420 		break;
12421 	default:
12422 		printf("programming error: (%s)\n", strerror(-ret));
12423 	}
12424 }
12425 
12426 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12427 	.f = cmd_set_macsec_offload_on_parsed,
12428 	.data = NULL,
12429 	.help_str = "set macsec offload <port_id> on "
12430 		"encrypt on|off replay-protect on|off",
12431 	.tokens = {
12432 		(void *)&cmd_macsec_offload_on_set,
12433 		(void *)&cmd_macsec_offload_on_macsec,
12434 		(void *)&cmd_macsec_offload_on_offload,
12435 		(void *)&cmd_macsec_offload_on_port_id,
12436 		(void *)&cmd_macsec_offload_on_on,
12437 		(void *)&cmd_macsec_offload_on_encrypt,
12438 		(void *)&cmd_macsec_offload_on_en_on_off,
12439 		(void *)&cmd_macsec_offload_on_replay_protect,
12440 		(void *)&cmd_macsec_offload_on_rp_on_off,
12441 		NULL,
12442 	},
12443 };
12444 
12445 /* Common result structure for MACsec offload disable */
12446 struct cmd_macsec_offload_off_result {
12447 	cmdline_fixed_string_t set;
12448 	cmdline_fixed_string_t macsec;
12449 	cmdline_fixed_string_t offload;
12450 	uint8_t port_id;
12451 	cmdline_fixed_string_t off;
12452 };
12453 
12454 /* Common CLI fields for MACsec offload disable */
12455 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12456 	TOKEN_STRING_INITIALIZER
12457 		(struct cmd_macsec_offload_off_result,
12458 		 set, "set");
12459 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12460 	TOKEN_STRING_INITIALIZER
12461 		(struct cmd_macsec_offload_off_result,
12462 		 macsec, "macsec");
12463 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12464 	TOKEN_STRING_INITIALIZER
12465 		(struct cmd_macsec_offload_off_result,
12466 		 offload, "offload");
12467 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12468 	TOKEN_NUM_INITIALIZER
12469 		(struct cmd_macsec_offload_off_result,
12470 		 port_id, UINT8);
12471 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12472 	TOKEN_STRING_INITIALIZER
12473 		(struct cmd_macsec_offload_off_result,
12474 		 off, "off");
12475 
12476 static void
12477 cmd_set_macsec_offload_off_parsed(
12478 	void *parsed_result,
12479 	__attribute__((unused)) struct cmdline *cl,
12480 	__attribute__((unused)) void *data)
12481 {
12482 	struct cmd_macsec_offload_off_result *res = parsed_result;
12483 	int ret = -ENOTSUP;
12484 	portid_t port_id = res->port_id;
12485 
12486 	if (port_id_is_invalid(port_id, ENABLED_WARN))
12487 		return;
12488 
12489 	ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
12490 #ifdef RTE_LIBRTE_IXGBE_PMD
12491 	ret = rte_pmd_ixgbe_macsec_disable(port_id);
12492 #endif
12493 
12494 	switch (ret) {
12495 	case 0:
12496 		break;
12497 	case -ENODEV:
12498 		printf("invalid port_id %d\n", port_id);
12499 		break;
12500 	case -ENOTSUP:
12501 		printf("not supported on port %d\n", port_id);
12502 		break;
12503 	default:
12504 		printf("programming error: (%s)\n", strerror(-ret));
12505 	}
12506 }
12507 
12508 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12509 	.f = cmd_set_macsec_offload_off_parsed,
12510 	.data = NULL,
12511 	.help_str = "set macsec offload <port_id> off",
12512 	.tokens = {
12513 		(void *)&cmd_macsec_offload_off_set,
12514 		(void *)&cmd_macsec_offload_off_macsec,
12515 		(void *)&cmd_macsec_offload_off_offload,
12516 		(void *)&cmd_macsec_offload_off_port_id,
12517 		(void *)&cmd_macsec_offload_off_off,
12518 		NULL,
12519 	},
12520 };
12521 
12522 /* Common result structure for MACsec secure connection configure */
12523 struct cmd_macsec_sc_result {
12524 	cmdline_fixed_string_t set;
12525 	cmdline_fixed_string_t macsec;
12526 	cmdline_fixed_string_t sc;
12527 	cmdline_fixed_string_t tx_rx;
12528 	uint8_t port_id;
12529 	struct ether_addr mac;
12530 	uint16_t pi;
12531 };
12532 
12533 /* Common CLI fields for MACsec secure connection configure */
12534 cmdline_parse_token_string_t cmd_macsec_sc_set =
12535 	TOKEN_STRING_INITIALIZER
12536 		(struct cmd_macsec_sc_result,
12537 		 set, "set");
12538 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12539 	TOKEN_STRING_INITIALIZER
12540 		(struct cmd_macsec_sc_result,
12541 		 macsec, "macsec");
12542 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12543 	TOKEN_STRING_INITIALIZER
12544 		(struct cmd_macsec_sc_result,
12545 		 sc, "sc");
12546 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12547 	TOKEN_STRING_INITIALIZER
12548 		(struct cmd_macsec_sc_result,
12549 		 tx_rx, "tx#rx");
12550 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12551 	TOKEN_NUM_INITIALIZER
12552 		(struct cmd_macsec_sc_result,
12553 		 port_id, UINT8);
12554 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12555 	TOKEN_ETHERADDR_INITIALIZER
12556 		(struct cmd_macsec_sc_result,
12557 		 mac);
12558 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12559 	TOKEN_NUM_INITIALIZER
12560 		(struct cmd_macsec_sc_result,
12561 		 pi, UINT16);
12562 
12563 static void
12564 cmd_set_macsec_sc_parsed(
12565 	void *parsed_result,
12566 	__attribute__((unused)) struct cmdline *cl,
12567 	__attribute__((unused)) void *data)
12568 {
12569 	struct cmd_macsec_sc_result *res = parsed_result;
12570 	int ret = -ENOTSUP;
12571 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12572 
12573 #ifdef RTE_LIBRTE_IXGBE_PMD
12574 	ret = is_tx ?
12575 		rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12576 				res->mac.addr_bytes) :
12577 		rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12578 				res->mac.addr_bytes, res->pi);
12579 #endif
12580 	RTE_SET_USED(is_tx);
12581 
12582 	switch (ret) {
12583 	case 0:
12584 		break;
12585 	case -ENODEV:
12586 		printf("invalid port_id %d\n", res->port_id);
12587 		break;
12588 	case -ENOTSUP:
12589 		printf("not supported on port %d\n", res->port_id);
12590 		break;
12591 	default:
12592 		printf("programming error: (%s)\n", strerror(-ret));
12593 	}
12594 }
12595 
12596 cmdline_parse_inst_t cmd_set_macsec_sc = {
12597 	.f = cmd_set_macsec_sc_parsed,
12598 	.data = NULL,
12599 	.help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12600 	.tokens = {
12601 		(void *)&cmd_macsec_sc_set,
12602 		(void *)&cmd_macsec_sc_macsec,
12603 		(void *)&cmd_macsec_sc_sc,
12604 		(void *)&cmd_macsec_sc_tx_rx,
12605 		(void *)&cmd_macsec_sc_port_id,
12606 		(void *)&cmd_macsec_sc_mac,
12607 		(void *)&cmd_macsec_sc_pi,
12608 		NULL,
12609 	},
12610 };
12611 
12612 /* Common result structure for MACsec secure connection configure */
12613 struct cmd_macsec_sa_result {
12614 	cmdline_fixed_string_t set;
12615 	cmdline_fixed_string_t macsec;
12616 	cmdline_fixed_string_t sa;
12617 	cmdline_fixed_string_t tx_rx;
12618 	uint8_t port_id;
12619 	uint8_t idx;
12620 	uint8_t an;
12621 	uint32_t pn;
12622 	cmdline_fixed_string_t key;
12623 };
12624 
12625 /* Common CLI fields for MACsec secure connection configure */
12626 cmdline_parse_token_string_t cmd_macsec_sa_set =
12627 	TOKEN_STRING_INITIALIZER
12628 		(struct cmd_macsec_sa_result,
12629 		 set, "set");
12630 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12631 	TOKEN_STRING_INITIALIZER
12632 		(struct cmd_macsec_sa_result,
12633 		 macsec, "macsec");
12634 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12635 	TOKEN_STRING_INITIALIZER
12636 		(struct cmd_macsec_sa_result,
12637 		 sa, "sa");
12638 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12639 	TOKEN_STRING_INITIALIZER
12640 		(struct cmd_macsec_sa_result,
12641 		 tx_rx, "tx#rx");
12642 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12643 	TOKEN_NUM_INITIALIZER
12644 		(struct cmd_macsec_sa_result,
12645 		 port_id, UINT8);
12646 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12647 	TOKEN_NUM_INITIALIZER
12648 		(struct cmd_macsec_sa_result,
12649 		 idx, UINT8);
12650 cmdline_parse_token_num_t cmd_macsec_sa_an =
12651 	TOKEN_NUM_INITIALIZER
12652 		(struct cmd_macsec_sa_result,
12653 		 an, UINT8);
12654 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12655 	TOKEN_NUM_INITIALIZER
12656 		(struct cmd_macsec_sa_result,
12657 		 pn, UINT32);
12658 cmdline_parse_token_string_t cmd_macsec_sa_key =
12659 	TOKEN_STRING_INITIALIZER
12660 		(struct cmd_macsec_sa_result,
12661 		 key, NULL);
12662 
12663 static void
12664 cmd_set_macsec_sa_parsed(
12665 	void *parsed_result,
12666 	__attribute__((unused)) struct cmdline *cl,
12667 	__attribute__((unused)) void *data)
12668 {
12669 	struct cmd_macsec_sa_result *res = parsed_result;
12670 	int ret = -ENOTSUP;
12671 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12672 	uint8_t key[16] = { 0 };
12673 	uint8_t xdgt0;
12674 	uint8_t xdgt1;
12675 	int key_len;
12676 	int i;
12677 
12678 	key_len = strlen(res->key) / 2;
12679 	if (key_len > 16)
12680 		key_len = 16;
12681 
12682 	for (i = 0; i < key_len; i++) {
12683 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12684 		if (xdgt0 == 0xFF)
12685 			return;
12686 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12687 		if (xdgt1 == 0xFF)
12688 			return;
12689 		key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12690 	}
12691 
12692 #ifdef RTE_LIBRTE_IXGBE_PMD
12693 	ret = is_tx ?
12694 		rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12695 			res->idx, res->an, res->pn, key) :
12696 		rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12697 			res->idx, res->an, res->pn, key);
12698 #endif
12699 	RTE_SET_USED(is_tx);
12700 	RTE_SET_USED(key);
12701 
12702 	switch (ret) {
12703 	case 0:
12704 		break;
12705 	case -EINVAL:
12706 		printf("invalid idx %d or an %d\n", res->idx, res->an);
12707 		break;
12708 	case -ENODEV:
12709 		printf("invalid port_id %d\n", res->port_id);
12710 		break;
12711 	case -ENOTSUP:
12712 		printf("not supported on port %d\n", res->port_id);
12713 		break;
12714 	default:
12715 		printf("programming error: (%s)\n", strerror(-ret));
12716 	}
12717 }
12718 
12719 cmdline_parse_inst_t cmd_set_macsec_sa = {
12720 	.f = cmd_set_macsec_sa_parsed,
12721 	.data = NULL,
12722 	.help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12723 	.tokens = {
12724 		(void *)&cmd_macsec_sa_set,
12725 		(void *)&cmd_macsec_sa_macsec,
12726 		(void *)&cmd_macsec_sa_sa,
12727 		(void *)&cmd_macsec_sa_tx_rx,
12728 		(void *)&cmd_macsec_sa_port_id,
12729 		(void *)&cmd_macsec_sa_idx,
12730 		(void *)&cmd_macsec_sa_an,
12731 		(void *)&cmd_macsec_sa_pn,
12732 		(void *)&cmd_macsec_sa_key,
12733 		NULL,
12734 	},
12735 };
12736 
12737 /* VF unicast promiscuous mode configuration */
12738 
12739 /* Common result structure for VF unicast promiscuous mode */
12740 struct cmd_vf_promisc_result {
12741 	cmdline_fixed_string_t set;
12742 	cmdline_fixed_string_t vf;
12743 	cmdline_fixed_string_t promisc;
12744 	uint8_t port_id;
12745 	uint32_t vf_id;
12746 	cmdline_fixed_string_t on_off;
12747 };
12748 
12749 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12750 cmdline_parse_token_string_t cmd_vf_promisc_set =
12751 	TOKEN_STRING_INITIALIZER
12752 		(struct cmd_vf_promisc_result,
12753 		 set, "set");
12754 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12755 	TOKEN_STRING_INITIALIZER
12756 		(struct cmd_vf_promisc_result,
12757 		 vf, "vf");
12758 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12759 	TOKEN_STRING_INITIALIZER
12760 		(struct cmd_vf_promisc_result,
12761 		 promisc, "promisc");
12762 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12763 	TOKEN_NUM_INITIALIZER
12764 		(struct cmd_vf_promisc_result,
12765 		 port_id, UINT8);
12766 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12767 	TOKEN_NUM_INITIALIZER
12768 		(struct cmd_vf_promisc_result,
12769 		 vf_id, UINT32);
12770 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12771 	TOKEN_STRING_INITIALIZER
12772 		(struct cmd_vf_promisc_result,
12773 		 on_off, "on#off");
12774 
12775 static void
12776 cmd_set_vf_promisc_parsed(
12777 	void *parsed_result,
12778 	__attribute__((unused)) struct cmdline *cl,
12779 	__attribute__((unused)) void *data)
12780 {
12781 	struct cmd_vf_promisc_result *res = parsed_result;
12782 	int ret = -ENOTSUP;
12783 
12784 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12785 
12786 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12787 		return;
12788 
12789 #ifdef RTE_LIBRTE_I40E_PMD
12790 	ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12791 						  res->vf_id, is_on);
12792 #endif
12793 
12794 	switch (ret) {
12795 	case 0:
12796 		break;
12797 	case -EINVAL:
12798 		printf("invalid vf_id %d\n", res->vf_id);
12799 		break;
12800 	case -ENODEV:
12801 		printf("invalid port_id %d\n", res->port_id);
12802 		break;
12803 	case -ENOTSUP:
12804 		printf("function not implemented\n");
12805 		break;
12806 	default:
12807 		printf("programming error: (%s)\n", strerror(-ret));
12808 	}
12809 }
12810 
12811 cmdline_parse_inst_t cmd_set_vf_promisc = {
12812 	.f = cmd_set_vf_promisc_parsed,
12813 	.data = NULL,
12814 	.help_str = "set vf promisc <port_id> <vf_id> on|off: "
12815 		"Set unicast promiscuous mode for a VF from the PF",
12816 	.tokens = {
12817 		(void *)&cmd_vf_promisc_set,
12818 		(void *)&cmd_vf_promisc_vf,
12819 		(void *)&cmd_vf_promisc_promisc,
12820 		(void *)&cmd_vf_promisc_port_id,
12821 		(void *)&cmd_vf_promisc_vf_id,
12822 		(void *)&cmd_vf_promisc_on_off,
12823 		NULL,
12824 	},
12825 };
12826 
12827 /* VF multicast promiscuous mode configuration */
12828 
12829 /* Common result structure for VF multicast promiscuous mode */
12830 struct cmd_vf_allmulti_result {
12831 	cmdline_fixed_string_t set;
12832 	cmdline_fixed_string_t vf;
12833 	cmdline_fixed_string_t allmulti;
12834 	uint8_t port_id;
12835 	uint32_t vf_id;
12836 	cmdline_fixed_string_t on_off;
12837 };
12838 
12839 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12840 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12841 	TOKEN_STRING_INITIALIZER
12842 		(struct cmd_vf_allmulti_result,
12843 		 set, "set");
12844 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12845 	TOKEN_STRING_INITIALIZER
12846 		(struct cmd_vf_allmulti_result,
12847 		 vf, "vf");
12848 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12849 	TOKEN_STRING_INITIALIZER
12850 		(struct cmd_vf_allmulti_result,
12851 		 allmulti, "allmulti");
12852 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12853 	TOKEN_NUM_INITIALIZER
12854 		(struct cmd_vf_allmulti_result,
12855 		 port_id, UINT8);
12856 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12857 	TOKEN_NUM_INITIALIZER
12858 		(struct cmd_vf_allmulti_result,
12859 		 vf_id, UINT32);
12860 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12861 	TOKEN_STRING_INITIALIZER
12862 		(struct cmd_vf_allmulti_result,
12863 		 on_off, "on#off");
12864 
12865 static void
12866 cmd_set_vf_allmulti_parsed(
12867 	void *parsed_result,
12868 	__attribute__((unused)) struct cmdline *cl,
12869 	__attribute__((unused)) void *data)
12870 {
12871 	struct cmd_vf_allmulti_result *res = parsed_result;
12872 	int ret = -ENOTSUP;
12873 
12874 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12875 
12876 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12877 		return;
12878 
12879 #ifdef RTE_LIBRTE_I40E_PMD
12880 	ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12881 						    res->vf_id, is_on);
12882 #endif
12883 
12884 	switch (ret) {
12885 	case 0:
12886 		break;
12887 	case -EINVAL:
12888 		printf("invalid vf_id %d\n", res->vf_id);
12889 		break;
12890 	case -ENODEV:
12891 		printf("invalid port_id %d\n", res->port_id);
12892 		break;
12893 	case -ENOTSUP:
12894 		printf("function not implemented\n");
12895 		break;
12896 	default:
12897 		printf("programming error: (%s)\n", strerror(-ret));
12898 	}
12899 }
12900 
12901 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12902 	.f = cmd_set_vf_allmulti_parsed,
12903 	.data = NULL,
12904 	.help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12905 		"Set multicast promiscuous mode for a VF from the PF",
12906 	.tokens = {
12907 		(void *)&cmd_vf_allmulti_set,
12908 		(void *)&cmd_vf_allmulti_vf,
12909 		(void *)&cmd_vf_allmulti_allmulti,
12910 		(void *)&cmd_vf_allmulti_port_id,
12911 		(void *)&cmd_vf_allmulti_vf_id,
12912 		(void *)&cmd_vf_allmulti_on_off,
12913 		NULL,
12914 	},
12915 };
12916 
12917 /* vf broadcast mode configuration */
12918 
12919 /* Common result structure for vf broadcast */
12920 struct cmd_set_vf_broadcast_result {
12921 	cmdline_fixed_string_t set;
12922 	cmdline_fixed_string_t vf;
12923 	cmdline_fixed_string_t broadcast;
12924 	uint8_t port_id;
12925 	uint16_t vf_id;
12926 	cmdline_fixed_string_t on_off;
12927 };
12928 
12929 /* Common CLI fields for vf broadcast enable disable */
12930 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12931 	TOKEN_STRING_INITIALIZER
12932 		(struct cmd_set_vf_broadcast_result,
12933 		 set, "set");
12934 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12935 	TOKEN_STRING_INITIALIZER
12936 		(struct cmd_set_vf_broadcast_result,
12937 		 vf, "vf");
12938 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12939 	TOKEN_STRING_INITIALIZER
12940 		(struct cmd_set_vf_broadcast_result,
12941 		 broadcast, "broadcast");
12942 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12943 	TOKEN_NUM_INITIALIZER
12944 		(struct cmd_set_vf_broadcast_result,
12945 		 port_id, UINT8);
12946 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12947 	TOKEN_NUM_INITIALIZER
12948 		(struct cmd_set_vf_broadcast_result,
12949 		 vf_id, UINT16);
12950 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12951 	TOKEN_STRING_INITIALIZER
12952 		(struct cmd_set_vf_broadcast_result,
12953 		 on_off, "on#off");
12954 
12955 static void
12956 cmd_set_vf_broadcast_parsed(
12957 	void *parsed_result,
12958 	__attribute__((unused)) struct cmdline *cl,
12959 	__attribute__((unused)) void *data)
12960 {
12961 	struct cmd_set_vf_broadcast_result *res = parsed_result;
12962 	int ret = -ENOTSUP;
12963 
12964 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12965 
12966 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12967 		return;
12968 
12969 #ifdef RTE_LIBRTE_I40E_PMD
12970 	ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12971 					    res->vf_id, is_on);
12972 #endif
12973 
12974 	switch (ret) {
12975 	case 0:
12976 		break;
12977 	case -EINVAL:
12978 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12979 		break;
12980 	case -ENODEV:
12981 		printf("invalid port_id %d\n", res->port_id);
12982 		break;
12983 	case -ENOTSUP:
12984 		printf("function not implemented\n");
12985 		break;
12986 	default:
12987 		printf("programming error: (%s)\n", strerror(-ret));
12988 	}
12989 }
12990 
12991 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12992 	.f = cmd_set_vf_broadcast_parsed,
12993 	.data = NULL,
12994 	.help_str = "set vf broadcast <port_id> <vf_id> on|off",
12995 	.tokens = {
12996 		(void *)&cmd_set_vf_broadcast_set,
12997 		(void *)&cmd_set_vf_broadcast_vf,
12998 		(void *)&cmd_set_vf_broadcast_broadcast,
12999 		(void *)&cmd_set_vf_broadcast_port_id,
13000 		(void *)&cmd_set_vf_broadcast_vf_id,
13001 		(void *)&cmd_set_vf_broadcast_on_off,
13002 		NULL,
13003 	},
13004 };
13005 
13006 /* vf vlan tag configuration */
13007 
13008 /* Common result structure for vf vlan tag */
13009 struct cmd_set_vf_vlan_tag_result {
13010 	cmdline_fixed_string_t set;
13011 	cmdline_fixed_string_t vf;
13012 	cmdline_fixed_string_t vlan;
13013 	cmdline_fixed_string_t tag;
13014 	uint8_t port_id;
13015 	uint16_t vf_id;
13016 	cmdline_fixed_string_t on_off;
13017 };
13018 
13019 /* Common CLI fields for vf vlan tag enable disable */
13020 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13021 	TOKEN_STRING_INITIALIZER
13022 		(struct cmd_set_vf_vlan_tag_result,
13023 		 set, "set");
13024 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13025 	TOKEN_STRING_INITIALIZER
13026 		(struct cmd_set_vf_vlan_tag_result,
13027 		 vf, "vf");
13028 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13029 	TOKEN_STRING_INITIALIZER
13030 		(struct cmd_set_vf_vlan_tag_result,
13031 		 vlan, "vlan");
13032 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13033 	TOKEN_STRING_INITIALIZER
13034 		(struct cmd_set_vf_vlan_tag_result,
13035 		 tag, "tag");
13036 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13037 	TOKEN_NUM_INITIALIZER
13038 		(struct cmd_set_vf_vlan_tag_result,
13039 		 port_id, UINT8);
13040 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13041 	TOKEN_NUM_INITIALIZER
13042 		(struct cmd_set_vf_vlan_tag_result,
13043 		 vf_id, UINT16);
13044 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13045 	TOKEN_STRING_INITIALIZER
13046 		(struct cmd_set_vf_vlan_tag_result,
13047 		 on_off, "on#off");
13048 
13049 static void
13050 cmd_set_vf_vlan_tag_parsed(
13051 	void *parsed_result,
13052 	__attribute__((unused)) struct cmdline *cl,
13053 	__attribute__((unused)) void *data)
13054 {
13055 	struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13056 	int ret = -ENOTSUP;
13057 
13058 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13059 
13060 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13061 		return;
13062 
13063 #ifdef RTE_LIBRTE_I40E_PMD
13064 	ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13065 					   res->vf_id, is_on);
13066 #endif
13067 
13068 	switch (ret) {
13069 	case 0:
13070 		break;
13071 	case -EINVAL:
13072 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13073 		break;
13074 	case -ENODEV:
13075 		printf("invalid port_id %d\n", res->port_id);
13076 		break;
13077 	case -ENOTSUP:
13078 		printf("function not implemented\n");
13079 		break;
13080 	default:
13081 		printf("programming error: (%s)\n", strerror(-ret));
13082 	}
13083 }
13084 
13085 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13086 	.f = cmd_set_vf_vlan_tag_parsed,
13087 	.data = NULL,
13088 	.help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13089 	.tokens = {
13090 		(void *)&cmd_set_vf_vlan_tag_set,
13091 		(void *)&cmd_set_vf_vlan_tag_vf,
13092 		(void *)&cmd_set_vf_vlan_tag_vlan,
13093 		(void *)&cmd_set_vf_vlan_tag_tag,
13094 		(void *)&cmd_set_vf_vlan_tag_port_id,
13095 		(void *)&cmd_set_vf_vlan_tag_vf_id,
13096 		(void *)&cmd_set_vf_vlan_tag_on_off,
13097 		NULL,
13098 	},
13099 };
13100 
13101 /* Common definition of VF and TC TX bandwidth configuration */
13102 struct cmd_vf_tc_bw_result {
13103 	cmdline_fixed_string_t set;
13104 	cmdline_fixed_string_t vf;
13105 	cmdline_fixed_string_t tc;
13106 	cmdline_fixed_string_t tx;
13107 	cmdline_fixed_string_t min_bw;
13108 	cmdline_fixed_string_t max_bw;
13109 	cmdline_fixed_string_t strict_link_prio;
13110 	uint8_t port_id;
13111 	uint16_t vf_id;
13112 	uint8_t tc_no;
13113 	uint32_t bw;
13114 	cmdline_fixed_string_t bw_list;
13115 	uint8_t tc_map;
13116 };
13117 
13118 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13119 	TOKEN_STRING_INITIALIZER
13120 		(struct cmd_vf_tc_bw_result,
13121 		 set, "set");
13122 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13123 	TOKEN_STRING_INITIALIZER
13124 		(struct cmd_vf_tc_bw_result,
13125 		 vf, "vf");
13126 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13127 	TOKEN_STRING_INITIALIZER
13128 		(struct cmd_vf_tc_bw_result,
13129 		 tc, "tc");
13130 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13131 	TOKEN_STRING_INITIALIZER
13132 		(struct cmd_vf_tc_bw_result,
13133 		 tx, "tx");
13134 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13135 	TOKEN_STRING_INITIALIZER
13136 		(struct cmd_vf_tc_bw_result,
13137 		 strict_link_prio, "strict-link-priority");
13138 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13139 	TOKEN_STRING_INITIALIZER
13140 		(struct cmd_vf_tc_bw_result,
13141 		 min_bw, "min-bandwidth");
13142 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13143 	TOKEN_STRING_INITIALIZER
13144 		(struct cmd_vf_tc_bw_result,
13145 		 max_bw, "max-bandwidth");
13146 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13147 	TOKEN_NUM_INITIALIZER
13148 		(struct cmd_vf_tc_bw_result,
13149 		 port_id, UINT8);
13150 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13151 	TOKEN_NUM_INITIALIZER
13152 		(struct cmd_vf_tc_bw_result,
13153 		 vf_id, UINT16);
13154 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13155 	TOKEN_NUM_INITIALIZER
13156 		(struct cmd_vf_tc_bw_result,
13157 		 tc_no, UINT8);
13158 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13159 	TOKEN_NUM_INITIALIZER
13160 		(struct cmd_vf_tc_bw_result,
13161 		 bw, UINT32);
13162 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13163 	TOKEN_STRING_INITIALIZER
13164 		(struct cmd_vf_tc_bw_result,
13165 		 bw_list, NULL);
13166 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13167 	TOKEN_NUM_INITIALIZER
13168 		(struct cmd_vf_tc_bw_result,
13169 		 tc_map, UINT8);
13170 
13171 /* VF max bandwidth setting */
13172 static void
13173 cmd_vf_max_bw_parsed(
13174 	void *parsed_result,
13175 	__attribute__((unused)) struct cmdline *cl,
13176 	__attribute__((unused)) void *data)
13177 {
13178 	struct cmd_vf_tc_bw_result *res = parsed_result;
13179 	int ret = -ENOTSUP;
13180 
13181 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13182 		return;
13183 
13184 #ifdef RTE_LIBRTE_I40E_PMD
13185 	ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13186 					 res->vf_id, res->bw);
13187 #endif
13188 
13189 	switch (ret) {
13190 	case 0:
13191 		break;
13192 	case -EINVAL:
13193 		printf("invalid vf_id %d or bandwidth %d\n",
13194 		       res->vf_id, res->bw);
13195 		break;
13196 	case -ENODEV:
13197 		printf("invalid port_id %d\n", res->port_id);
13198 		break;
13199 	case -ENOTSUP:
13200 		printf("function not implemented\n");
13201 		break;
13202 	default:
13203 		printf("programming error: (%s)\n", strerror(-ret));
13204 	}
13205 }
13206 
13207 cmdline_parse_inst_t cmd_vf_max_bw = {
13208 	.f = cmd_vf_max_bw_parsed,
13209 	.data = NULL,
13210 	.help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13211 	.tokens = {
13212 		(void *)&cmd_vf_tc_bw_set,
13213 		(void *)&cmd_vf_tc_bw_vf,
13214 		(void *)&cmd_vf_tc_bw_tx,
13215 		(void *)&cmd_vf_tc_bw_max_bw,
13216 		(void *)&cmd_vf_tc_bw_port_id,
13217 		(void *)&cmd_vf_tc_bw_vf_id,
13218 		(void *)&cmd_vf_tc_bw_bw,
13219 		NULL,
13220 	},
13221 };
13222 
13223 static int
13224 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13225 			   uint8_t *tc_num,
13226 			   char *str)
13227 {
13228 	uint32_t size;
13229 	const char *p, *p0 = str;
13230 	char s[256];
13231 	char *end;
13232 	char *str_fld[16];
13233 	uint16_t i;
13234 	int ret;
13235 
13236 	p = strchr(p0, '(');
13237 	if (p == NULL) {
13238 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13239 		return -1;
13240 	}
13241 	p++;
13242 	p0 = strchr(p, ')');
13243 	if (p0 == NULL) {
13244 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13245 		return -1;
13246 	}
13247 	size = p0 - p;
13248 	if (size >= sizeof(s)) {
13249 		printf("The string size exceeds the internal buffer size\n");
13250 		return -1;
13251 	}
13252 	snprintf(s, sizeof(s), "%.*s", size, p);
13253 	ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13254 	if (ret <= 0) {
13255 		printf("Failed to get the bandwidth list. ");
13256 		return -1;
13257 	}
13258 	*tc_num = ret;
13259 	for (i = 0; i < ret; i++)
13260 		bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13261 
13262 	return 0;
13263 }
13264 
13265 /* TC min bandwidth setting */
13266 static void
13267 cmd_vf_tc_min_bw_parsed(
13268 	void *parsed_result,
13269 	__attribute__((unused)) struct cmdline *cl,
13270 	__attribute__((unused)) void *data)
13271 {
13272 	struct cmd_vf_tc_bw_result *res = parsed_result;
13273 	uint8_t tc_num;
13274 	uint8_t bw[16];
13275 	int ret = -ENOTSUP;
13276 
13277 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13278 		return;
13279 
13280 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13281 	if (ret)
13282 		return;
13283 
13284 #ifdef RTE_LIBRTE_I40E_PMD
13285 	ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13286 					      tc_num, bw);
13287 #endif
13288 
13289 	switch (ret) {
13290 	case 0:
13291 		break;
13292 	case -EINVAL:
13293 		printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13294 		break;
13295 	case -ENODEV:
13296 		printf("invalid port_id %d\n", res->port_id);
13297 		break;
13298 	case -ENOTSUP:
13299 		printf("function not implemented\n");
13300 		break;
13301 	default:
13302 		printf("programming error: (%s)\n", strerror(-ret));
13303 	}
13304 }
13305 
13306 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13307 	.f = cmd_vf_tc_min_bw_parsed,
13308 	.data = NULL,
13309 	.help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13310 		    " <bw1, bw2, ...>",
13311 	.tokens = {
13312 		(void *)&cmd_vf_tc_bw_set,
13313 		(void *)&cmd_vf_tc_bw_vf,
13314 		(void *)&cmd_vf_tc_bw_tc,
13315 		(void *)&cmd_vf_tc_bw_tx,
13316 		(void *)&cmd_vf_tc_bw_min_bw,
13317 		(void *)&cmd_vf_tc_bw_port_id,
13318 		(void *)&cmd_vf_tc_bw_vf_id,
13319 		(void *)&cmd_vf_tc_bw_bw_list,
13320 		NULL,
13321 	},
13322 };
13323 
13324 static void
13325 cmd_tc_min_bw_parsed(
13326 	void *parsed_result,
13327 	__attribute__((unused)) struct cmdline *cl,
13328 	__attribute__((unused)) void *data)
13329 {
13330 	struct cmd_vf_tc_bw_result *res = parsed_result;
13331 	struct rte_port *port;
13332 	uint8_t tc_num;
13333 	uint8_t bw[16];
13334 	int ret = -ENOTSUP;
13335 
13336 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13337 		return;
13338 
13339 	port = &ports[res->port_id];
13340 	/** Check if the port is not started **/
13341 	if (port->port_status != RTE_PORT_STOPPED) {
13342 		printf("Please stop port %d first\n", res->port_id);
13343 		return;
13344 	}
13345 
13346 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13347 	if (ret)
13348 		return;
13349 
13350 #ifdef RTE_LIBRTE_IXGBE_PMD
13351 	ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13352 #endif
13353 
13354 	switch (ret) {
13355 	case 0:
13356 		break;
13357 	case -EINVAL:
13358 		printf("invalid bandwidth\n");
13359 		break;
13360 	case -ENODEV:
13361 		printf("invalid port_id %d\n", res->port_id);
13362 		break;
13363 	case -ENOTSUP:
13364 		printf("function not implemented\n");
13365 		break;
13366 	default:
13367 		printf("programming error: (%s)\n", strerror(-ret));
13368 	}
13369 }
13370 
13371 cmdline_parse_inst_t cmd_tc_min_bw = {
13372 	.f = cmd_tc_min_bw_parsed,
13373 	.data = NULL,
13374 	.help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13375 	.tokens = {
13376 		(void *)&cmd_vf_tc_bw_set,
13377 		(void *)&cmd_vf_tc_bw_tc,
13378 		(void *)&cmd_vf_tc_bw_tx,
13379 		(void *)&cmd_vf_tc_bw_min_bw,
13380 		(void *)&cmd_vf_tc_bw_port_id,
13381 		(void *)&cmd_vf_tc_bw_bw_list,
13382 		NULL,
13383 	},
13384 };
13385 
13386 /* TC max bandwidth setting */
13387 static void
13388 cmd_vf_tc_max_bw_parsed(
13389 	void *parsed_result,
13390 	__attribute__((unused)) struct cmdline *cl,
13391 	__attribute__((unused)) void *data)
13392 {
13393 	struct cmd_vf_tc_bw_result *res = parsed_result;
13394 	int ret = -ENOTSUP;
13395 
13396 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13397 		return;
13398 
13399 #ifdef RTE_LIBRTE_I40E_PMD
13400 	ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13401 					    res->tc_no, res->bw);
13402 #endif
13403 
13404 	switch (ret) {
13405 	case 0:
13406 		break;
13407 	case -EINVAL:
13408 		printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13409 		       res->vf_id, res->tc_no, res->bw);
13410 		break;
13411 	case -ENODEV:
13412 		printf("invalid port_id %d\n", res->port_id);
13413 		break;
13414 	case -ENOTSUP:
13415 		printf("function not implemented\n");
13416 		break;
13417 	default:
13418 		printf("programming error: (%s)\n", strerror(-ret));
13419 	}
13420 }
13421 
13422 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13423 	.f = cmd_vf_tc_max_bw_parsed,
13424 	.data = NULL,
13425 	.help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13426 		    " <bandwidth>",
13427 	.tokens = {
13428 		(void *)&cmd_vf_tc_bw_set,
13429 		(void *)&cmd_vf_tc_bw_vf,
13430 		(void *)&cmd_vf_tc_bw_tc,
13431 		(void *)&cmd_vf_tc_bw_tx,
13432 		(void *)&cmd_vf_tc_bw_max_bw,
13433 		(void *)&cmd_vf_tc_bw_port_id,
13434 		(void *)&cmd_vf_tc_bw_vf_id,
13435 		(void *)&cmd_vf_tc_bw_tc_no,
13436 		(void *)&cmd_vf_tc_bw_bw,
13437 		NULL,
13438 	},
13439 };
13440 
13441 
13442 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
13443 
13444 /* *** Set Port default Traffic Management Hierarchy *** */
13445 struct cmd_set_port_tm_hierarchy_default_result {
13446 	cmdline_fixed_string_t set;
13447 	cmdline_fixed_string_t port;
13448 	cmdline_fixed_string_t tm;
13449 	cmdline_fixed_string_t hierarchy;
13450 	cmdline_fixed_string_t def;
13451 	uint16_t port_id;
13452 };
13453 
13454 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
13455 	TOKEN_STRING_INITIALIZER(
13456 		struct cmd_set_port_tm_hierarchy_default_result, set, "set");
13457 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
13458 	TOKEN_STRING_INITIALIZER(
13459 		struct cmd_set_port_tm_hierarchy_default_result, port, "port");
13460 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
13461 	TOKEN_STRING_INITIALIZER(
13462 		struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
13463 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
13464 	TOKEN_STRING_INITIALIZER(
13465 		struct cmd_set_port_tm_hierarchy_default_result,
13466 			hierarchy, "hierarchy");
13467 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
13468 	TOKEN_STRING_INITIALIZER(
13469 		struct cmd_set_port_tm_hierarchy_default_result,
13470 			def, "default");
13471 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
13472 	TOKEN_NUM_INITIALIZER(
13473 		struct cmd_set_port_tm_hierarchy_default_result,
13474 			port_id, UINT8);
13475 
13476 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
13477 	__attribute__((unused)) struct cmdline *cl,
13478 	__attribute__((unused)) void *data)
13479 {
13480 	struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
13481 	struct rte_port *p;
13482 	uint16_t port_id = res->port_id;
13483 
13484 	if (port_id_is_invalid(port_id, ENABLED_WARN))
13485 		return;
13486 
13487 	p = &ports[port_id];
13488 
13489 	/* Port tm flag */
13490 	if (p->softport.tm_flag == 0) {
13491 		printf("  tm not enabled on port %u (error)\n", port_id);
13492 		return;
13493 	}
13494 
13495 	/* Forward mode: tm */
13496 	if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
13497 		printf("  tm mode not enabled(error)\n");
13498 		return;
13499 	}
13500 
13501 	/* Set the default tm hierarchy */
13502 	p->softport.tm.default_hierarchy_enable = 1;
13503 }
13504 
13505 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
13506 	.f = cmd_set_port_tm_hierarchy_default_parsed,
13507 	.data = NULL,
13508 	.help_str = "set port tm hierarchy default <port_id>",
13509 	.tokens = {
13510 		(void *)&cmd_set_port_tm_hierarchy_default_set,
13511 		(void *)&cmd_set_port_tm_hierarchy_default_port,
13512 		(void *)&cmd_set_port_tm_hierarchy_default_tm,
13513 		(void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
13514 		(void *)&cmd_set_port_tm_hierarchy_default_default,
13515 		(void *)&cmd_set_port_tm_hierarchy_default_port_id,
13516 		NULL,
13517 	},
13518 };
13519 #endif
13520 
13521 /* Strict link priority scheduling mode setting */
13522 static void
13523 cmd_strict_link_prio_parsed(
13524 	void *parsed_result,
13525 	__attribute__((unused)) struct cmdline *cl,
13526 	__attribute__((unused)) void *data)
13527 {
13528 	struct cmd_vf_tc_bw_result *res = parsed_result;
13529 	int ret = -ENOTSUP;
13530 
13531 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13532 		return;
13533 
13534 #ifdef RTE_LIBRTE_I40E_PMD
13535 	ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13536 #endif
13537 
13538 	switch (ret) {
13539 	case 0:
13540 		break;
13541 	case -EINVAL:
13542 		printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13543 		break;
13544 	case -ENODEV:
13545 		printf("invalid port_id %d\n", res->port_id);
13546 		break;
13547 	case -ENOTSUP:
13548 		printf("function not implemented\n");
13549 		break;
13550 	default:
13551 		printf("programming error: (%s)\n", strerror(-ret));
13552 	}
13553 }
13554 
13555 cmdline_parse_inst_t cmd_strict_link_prio = {
13556 	.f = cmd_strict_link_prio_parsed,
13557 	.data = NULL,
13558 	.help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13559 	.tokens = {
13560 		(void *)&cmd_vf_tc_bw_set,
13561 		(void *)&cmd_vf_tc_bw_tx,
13562 		(void *)&cmd_vf_tc_bw_strict_link_prio,
13563 		(void *)&cmd_vf_tc_bw_port_id,
13564 		(void *)&cmd_vf_tc_bw_tc_map,
13565 		NULL,
13566 	},
13567 };
13568 
13569 /* Load dynamic device personalization*/
13570 struct cmd_ddp_add_result {
13571 	cmdline_fixed_string_t ddp;
13572 	cmdline_fixed_string_t add;
13573 	uint8_t port_id;
13574 	char filepath[];
13575 };
13576 
13577 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13578 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13579 cmdline_parse_token_string_t cmd_ddp_add_add =
13580 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13581 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13582 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8);
13583 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13584 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13585 
13586 static void
13587 cmd_ddp_add_parsed(
13588 	void *parsed_result,
13589 	__attribute__((unused)) struct cmdline *cl,
13590 	__attribute__((unused)) void *data)
13591 {
13592 	struct cmd_ddp_add_result *res = parsed_result;
13593 	uint8_t *buff;
13594 	uint32_t size;
13595 	char *filepath;
13596 	char *file_fld[2];
13597 	int file_num;
13598 	int ret = -ENOTSUP;
13599 
13600 	if (res->port_id > nb_ports) {
13601 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13602 		return;
13603 	}
13604 
13605 	if (!all_ports_stopped()) {
13606 		printf("Please stop all ports first\n");
13607 		return;
13608 	}
13609 
13610 	filepath = strdup(res->filepath);
13611 	if (filepath == NULL) {
13612 		printf("Failed to allocate memory\n");
13613 		return;
13614 	}
13615 	file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13616 
13617 	buff = open_ddp_package_file(file_fld[0], &size);
13618 	if (!buff) {
13619 		free((void *)filepath);
13620 		return;
13621 	}
13622 
13623 #ifdef RTE_LIBRTE_I40E_PMD
13624 	if (ret == -ENOTSUP)
13625 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13626 					       buff, size,
13627 					       RTE_PMD_I40E_PKG_OP_WR_ADD);
13628 #endif
13629 
13630 	if (ret == -EEXIST)
13631 		printf("Profile has already existed.\n");
13632 	else if (ret < 0)
13633 		printf("Failed to load profile.\n");
13634 	else if (file_num == 2)
13635 		save_ddp_package_file(file_fld[1], buff, size);
13636 
13637 	close_ddp_package_file(buff);
13638 	free((void *)filepath);
13639 }
13640 
13641 cmdline_parse_inst_t cmd_ddp_add = {
13642 	.f = cmd_ddp_add_parsed,
13643 	.data = NULL,
13644 	.help_str = "ddp add <port_id> <profile_path[,output_path]>",
13645 	.tokens = {
13646 		(void *)&cmd_ddp_add_ddp,
13647 		(void *)&cmd_ddp_add_add,
13648 		(void *)&cmd_ddp_add_port_id,
13649 		(void *)&cmd_ddp_add_filepath,
13650 		NULL,
13651 	},
13652 };
13653 
13654 /* Delete dynamic device personalization*/
13655 struct cmd_ddp_del_result {
13656 	cmdline_fixed_string_t ddp;
13657 	cmdline_fixed_string_t del;
13658 	uint8_t port_id;
13659 	char filepath[];
13660 };
13661 
13662 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13663 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13664 cmdline_parse_token_string_t cmd_ddp_del_del =
13665 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13666 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13667 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT8);
13668 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13669 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13670 
13671 static void
13672 cmd_ddp_del_parsed(
13673 	void *parsed_result,
13674 	__attribute__((unused)) struct cmdline *cl,
13675 	__attribute__((unused)) void *data)
13676 {
13677 	struct cmd_ddp_del_result *res = parsed_result;
13678 	uint8_t *buff;
13679 	uint32_t size;
13680 	int ret = -ENOTSUP;
13681 
13682 	if (res->port_id > nb_ports) {
13683 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13684 		return;
13685 	}
13686 
13687 	if (!all_ports_stopped()) {
13688 		printf("Please stop all ports first\n");
13689 		return;
13690 	}
13691 
13692 	buff = open_ddp_package_file(res->filepath, &size);
13693 	if (!buff)
13694 		return;
13695 
13696 #ifdef RTE_LIBRTE_I40E_PMD
13697 	if (ret == -ENOTSUP)
13698 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13699 					       buff, size,
13700 					       RTE_PMD_I40E_PKG_OP_WR_DEL);
13701 #endif
13702 
13703 	if (ret == -EACCES)
13704 		printf("Profile does not exist.\n");
13705 	else if (ret < 0)
13706 		printf("Failed to delete profile.\n");
13707 
13708 	close_ddp_package_file(buff);
13709 }
13710 
13711 cmdline_parse_inst_t cmd_ddp_del = {
13712 	.f = cmd_ddp_del_parsed,
13713 	.data = NULL,
13714 	.help_str = "ddp del <port_id> <profile_path>",
13715 	.tokens = {
13716 		(void *)&cmd_ddp_del_ddp,
13717 		(void *)&cmd_ddp_del_del,
13718 		(void *)&cmd_ddp_del_port_id,
13719 		(void *)&cmd_ddp_del_filepath,
13720 		NULL,
13721 	},
13722 };
13723 
13724 /* Get dynamic device personalization profile info */
13725 struct cmd_ddp_info_result {
13726 	cmdline_fixed_string_t ddp;
13727 	cmdline_fixed_string_t get;
13728 	cmdline_fixed_string_t info;
13729 	char filepath[];
13730 };
13731 
13732 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13733 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13734 cmdline_parse_token_string_t cmd_ddp_info_get =
13735 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13736 cmdline_parse_token_string_t cmd_ddp_info_info =
13737 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13738 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13739 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13740 
13741 static void
13742 cmd_ddp_info_parsed(
13743 	void *parsed_result,
13744 	__attribute__((unused)) struct cmdline *cl,
13745 	__attribute__((unused)) void *data)
13746 {
13747 	struct cmd_ddp_info_result *res = parsed_result;
13748 	uint8_t *pkg;
13749 	uint32_t pkg_size;
13750 	int ret = -ENOTSUP;
13751 #ifdef RTE_LIBRTE_I40E_PMD
13752 	uint32_t i, j, n;
13753 	uint8_t *buff;
13754 	uint32_t buff_size = 0;
13755 	struct rte_pmd_i40e_profile_info info;
13756 	uint32_t dev_num = 0;
13757 	struct rte_pmd_i40e_ddp_device_id *devs;
13758 	uint32_t proto_num = 0;
13759 	struct rte_pmd_i40e_proto_info *proto;
13760 	uint32_t pctype_num = 0;
13761 	struct rte_pmd_i40e_ptype_info *pctype;
13762 	uint32_t ptype_num = 0;
13763 	struct rte_pmd_i40e_ptype_info *ptype;
13764 	uint8_t proto_id;
13765 
13766 #endif
13767 
13768 	pkg = open_ddp_package_file(res->filepath, &pkg_size);
13769 	if (!pkg)
13770 		return;
13771 
13772 #ifdef RTE_LIBRTE_I40E_PMD
13773 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13774 				(uint8_t *)&info, sizeof(info),
13775 				RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13776 	if (!ret) {
13777 		printf("Global Track id:       0x%x\n", info.track_id);
13778 		printf("Global Version:        %d.%d.%d.%d\n",
13779 			info.version.major,
13780 			info.version.minor,
13781 			info.version.update,
13782 			info.version.draft);
13783 		printf("Global Package name:   %s\n\n", info.name);
13784 	}
13785 
13786 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13787 				(uint8_t *)&info, sizeof(info),
13788 				RTE_PMD_I40E_PKG_INFO_HEADER);
13789 	if (!ret) {
13790 		printf("i40e Profile Track id: 0x%x\n", info.track_id);
13791 		printf("i40e Profile Version:  %d.%d.%d.%d\n",
13792 			info.version.major,
13793 			info.version.minor,
13794 			info.version.update,
13795 			info.version.draft);
13796 		printf("i40e Profile name:     %s\n\n", info.name);
13797 	}
13798 
13799 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13800 				(uint8_t *)&buff_size, sizeof(buff_size),
13801 				RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13802 	if (!ret && buff_size) {
13803 		buff = (uint8_t *)malloc(buff_size);
13804 		if (buff) {
13805 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13806 						buff, buff_size,
13807 						RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13808 			if (!ret)
13809 				printf("Package Notes:\n%s\n\n", buff);
13810 			free(buff);
13811 		}
13812 	}
13813 
13814 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13815 				(uint8_t *)&dev_num, sizeof(dev_num),
13816 				RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13817 	if (!ret && dev_num) {
13818 		buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
13819 		devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
13820 		if (devs) {
13821 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13822 						(uint8_t *)devs, buff_size,
13823 						RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13824 			if (!ret) {
13825 				printf("List of supported devices:\n");
13826 				for (i = 0; i < dev_num; i++) {
13827 					printf("  %04X:%04X %04X:%04X\n",
13828 						devs[i].vendor_dev_id >> 16,
13829 						devs[i].vendor_dev_id & 0xFFFF,
13830 						devs[i].sub_vendor_dev_id >> 16,
13831 						devs[i].sub_vendor_dev_id & 0xFFFF);
13832 				}
13833 				printf("\n");
13834 			}
13835 			free(devs);
13836 		}
13837 	}
13838 
13839 	/* get information about protocols and packet types */
13840 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13841 		(uint8_t *)&proto_num, sizeof(proto_num),
13842 		RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
13843 	if (ret || !proto_num)
13844 		goto no_print_return;
13845 
13846 	buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
13847 	proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
13848 	if (!proto)
13849 		goto no_print_return;
13850 
13851 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
13852 					buff_size,
13853 					RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
13854 	if (!ret) {
13855 		printf("List of used protocols:\n");
13856 		for (i = 0; i < proto_num; i++)
13857 			printf("  %2u: %s\n", proto[i].proto_id,
13858 			       proto[i].name);
13859 		printf("\n");
13860 	}
13861 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13862 		(uint8_t *)&pctype_num, sizeof(pctype_num),
13863 		RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
13864 	if (ret || !pctype_num)
13865 		goto no_print_pctypes;
13866 
13867 	buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13868 	pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13869 	if (!pctype)
13870 		goto no_print_pctypes;
13871 
13872 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
13873 					buff_size,
13874 					RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
13875 	if (ret) {
13876 		free(pctype);
13877 		goto no_print_pctypes;
13878 	}
13879 
13880 	printf("List of defined packet classification types:\n");
13881 	for (i = 0; i < pctype_num; i++) {
13882 		printf("  %2u:", pctype[i].ptype_id);
13883 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13884 			proto_id = pctype[i].protocols[j];
13885 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13886 				for (n = 0; n < proto_num; n++) {
13887 					if (proto[n].proto_id == proto_id) {
13888 						printf(" %s", proto[n].name);
13889 						break;
13890 					}
13891 				}
13892 			}
13893 		}
13894 		printf("\n");
13895 	}
13896 	printf("\n");
13897 	free(pctype);
13898 
13899 no_print_pctypes:
13900 
13901 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
13902 					sizeof(ptype_num),
13903 					RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
13904 	if (ret || !ptype_num)
13905 		goto no_print_return;
13906 
13907 	buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13908 	ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13909 	if (!ptype)
13910 		goto no_print_return;
13911 
13912 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
13913 					buff_size,
13914 					RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
13915 	if (ret) {
13916 		free(ptype);
13917 		goto no_print_return;
13918 	}
13919 	printf("List of defined packet types:\n");
13920 	for (i = 0; i < ptype_num; i++) {
13921 		printf("  %2u:", ptype[i].ptype_id);
13922 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13923 			proto_id = ptype[i].protocols[j];
13924 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13925 				for (n = 0; n < proto_num; n++) {
13926 					if (proto[n].proto_id == proto_id) {
13927 						printf(" %s", proto[n].name);
13928 						break;
13929 					}
13930 				}
13931 			}
13932 		}
13933 		printf("\n");
13934 	}
13935 	free(ptype);
13936 	printf("\n");
13937 
13938 	free(proto);
13939 	ret = 0;
13940 no_print_return:
13941 #endif
13942 	if (ret == -ENOTSUP)
13943 		printf("Function not supported in PMD driver\n");
13944 	close_ddp_package_file(pkg);
13945 }
13946 
13947 cmdline_parse_inst_t cmd_ddp_get_info = {
13948 	.f = cmd_ddp_info_parsed,
13949 	.data = NULL,
13950 	.help_str = "ddp get info <profile_path>",
13951 	.tokens = {
13952 		(void *)&cmd_ddp_info_ddp,
13953 		(void *)&cmd_ddp_info_get,
13954 		(void *)&cmd_ddp_info_info,
13955 		(void *)&cmd_ddp_info_filepath,
13956 		NULL,
13957 	},
13958 };
13959 
13960 /* Get dynamic device personalization profile info list*/
13961 #define PROFILE_INFO_SIZE 48
13962 #define MAX_PROFILE_NUM 16
13963 
13964 struct cmd_ddp_get_list_result {
13965 	cmdline_fixed_string_t ddp;
13966 	cmdline_fixed_string_t get;
13967 	cmdline_fixed_string_t list;
13968 	uint8_t port_id;
13969 };
13970 
13971 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
13972 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
13973 cmdline_parse_token_string_t cmd_ddp_get_list_get =
13974 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
13975 cmdline_parse_token_string_t cmd_ddp_get_list_list =
13976 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
13977 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
13978 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8);
13979 
13980 static void
13981 cmd_ddp_get_list_parsed(
13982 	void *parsed_result,
13983 	__attribute__((unused)) struct cmdline *cl,
13984 	__attribute__((unused)) void *data)
13985 {
13986 	struct cmd_ddp_get_list_result *res = parsed_result;
13987 #ifdef RTE_LIBRTE_I40E_PMD
13988 	struct rte_pmd_i40e_profile_list *p_list;
13989 	struct rte_pmd_i40e_profile_info *p_info;
13990 	uint32_t p_num;
13991 	uint32_t size;
13992 	uint32_t i;
13993 #endif
13994 	int ret = -ENOTSUP;
13995 
13996 	if (res->port_id > nb_ports) {
13997 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13998 		return;
13999 	}
14000 
14001 #ifdef RTE_LIBRTE_I40E_PMD
14002 	size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14003 	p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14004 	if (!p_list)
14005 		printf("%s: Failed to malloc buffer\n", __func__);
14006 
14007 	if (ret == -ENOTSUP)
14008 		ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14009 						(uint8_t *)p_list, size);
14010 
14011 	if (!ret) {
14012 		p_num = p_list->p_count;
14013 		printf("Profile number is: %d\n\n", p_num);
14014 
14015 		for (i = 0; i < p_num; i++) {
14016 			p_info = &p_list->p_info[i];
14017 			printf("Profile %d:\n", i);
14018 			printf("Track id:     0x%x\n", p_info->track_id);
14019 			printf("Version:      %d.%d.%d.%d\n",
14020 			       p_info->version.major,
14021 			       p_info->version.minor,
14022 			       p_info->version.update,
14023 			       p_info->version.draft);
14024 			printf("Profile name: %s\n\n", p_info->name);
14025 		}
14026 	}
14027 
14028 	free(p_list);
14029 #endif
14030 
14031 	if (ret < 0)
14032 		printf("Failed to get ddp list\n");
14033 }
14034 
14035 cmdline_parse_inst_t cmd_ddp_get_list = {
14036 	.f = cmd_ddp_get_list_parsed,
14037 	.data = NULL,
14038 	.help_str = "ddp get list <port_id>",
14039 	.tokens = {
14040 		(void *)&cmd_ddp_get_list_ddp,
14041 		(void *)&cmd_ddp_get_list_get,
14042 		(void *)&cmd_ddp_get_list_list,
14043 		(void *)&cmd_ddp_get_list_port_id,
14044 		NULL,
14045 	},
14046 };
14047 
14048 /* show vf stats */
14049 
14050 /* Common result structure for show vf stats */
14051 struct cmd_show_vf_stats_result {
14052 	cmdline_fixed_string_t show;
14053 	cmdline_fixed_string_t vf;
14054 	cmdline_fixed_string_t stats;
14055 	uint8_t port_id;
14056 	uint16_t vf_id;
14057 };
14058 
14059 /* Common CLI fields show vf stats*/
14060 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14061 	TOKEN_STRING_INITIALIZER
14062 		(struct cmd_show_vf_stats_result,
14063 		 show, "show");
14064 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14065 	TOKEN_STRING_INITIALIZER
14066 		(struct cmd_show_vf_stats_result,
14067 		 vf, "vf");
14068 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14069 	TOKEN_STRING_INITIALIZER
14070 		(struct cmd_show_vf_stats_result,
14071 		 stats, "stats");
14072 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14073 	TOKEN_NUM_INITIALIZER
14074 		(struct cmd_show_vf_stats_result,
14075 		 port_id, UINT8);
14076 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14077 	TOKEN_NUM_INITIALIZER
14078 		(struct cmd_show_vf_stats_result,
14079 		 vf_id, UINT16);
14080 
14081 static void
14082 cmd_show_vf_stats_parsed(
14083 	void *parsed_result,
14084 	__attribute__((unused)) struct cmdline *cl,
14085 	__attribute__((unused)) void *data)
14086 {
14087 	struct cmd_show_vf_stats_result *res = parsed_result;
14088 	struct rte_eth_stats stats;
14089 	int ret = -ENOTSUP;
14090 	static const char *nic_stats_border = "########################";
14091 
14092 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14093 		return;
14094 
14095 	memset(&stats, 0, sizeof(stats));
14096 
14097 #ifdef RTE_LIBRTE_I40E_PMD
14098 	if (ret == -ENOTSUP)
14099 		ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14100 						res->vf_id,
14101 						&stats);
14102 #endif
14103 #ifdef RTE_LIBRTE_BNXT_PMD
14104 	if (ret == -ENOTSUP)
14105 		ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14106 						res->vf_id,
14107 						&stats);
14108 #endif
14109 
14110 	switch (ret) {
14111 	case 0:
14112 		break;
14113 	case -EINVAL:
14114 		printf("invalid vf_id %d\n", res->vf_id);
14115 		break;
14116 	case -ENODEV:
14117 		printf("invalid port_id %d\n", res->port_id);
14118 		break;
14119 	case -ENOTSUP:
14120 		printf("function not implemented\n");
14121 		break;
14122 	default:
14123 		printf("programming error: (%s)\n", strerror(-ret));
14124 	}
14125 
14126 	printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14127 		nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14128 
14129 	printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14130 	       "%-"PRIu64"\n",
14131 	       stats.ipackets, stats.imissed, stats.ibytes);
14132 	printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14133 	printf("  RX-nombuf:  %-10"PRIu64"\n",
14134 	       stats.rx_nombuf);
14135 	printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14136 	       "%-"PRIu64"\n",
14137 	       stats.opackets, stats.oerrors, stats.obytes);
14138 
14139 	printf("  %s############################%s\n",
14140 			       nic_stats_border, nic_stats_border);
14141 }
14142 
14143 cmdline_parse_inst_t cmd_show_vf_stats = {
14144 	.f = cmd_show_vf_stats_parsed,
14145 	.data = NULL,
14146 	.help_str = "show vf stats <port_id> <vf_id>",
14147 	.tokens = {
14148 		(void *)&cmd_show_vf_stats_show,
14149 		(void *)&cmd_show_vf_stats_vf,
14150 		(void *)&cmd_show_vf_stats_stats,
14151 		(void *)&cmd_show_vf_stats_port_id,
14152 		(void *)&cmd_show_vf_stats_vf_id,
14153 		NULL,
14154 	},
14155 };
14156 
14157 /* clear vf stats */
14158 
14159 /* Common result structure for clear vf stats */
14160 struct cmd_clear_vf_stats_result {
14161 	cmdline_fixed_string_t clear;
14162 	cmdline_fixed_string_t vf;
14163 	cmdline_fixed_string_t stats;
14164 	uint8_t port_id;
14165 	uint16_t vf_id;
14166 };
14167 
14168 /* Common CLI fields clear vf stats*/
14169 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14170 	TOKEN_STRING_INITIALIZER
14171 		(struct cmd_clear_vf_stats_result,
14172 		 clear, "clear");
14173 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14174 	TOKEN_STRING_INITIALIZER
14175 		(struct cmd_clear_vf_stats_result,
14176 		 vf, "vf");
14177 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14178 	TOKEN_STRING_INITIALIZER
14179 		(struct cmd_clear_vf_stats_result,
14180 		 stats, "stats");
14181 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14182 	TOKEN_NUM_INITIALIZER
14183 		(struct cmd_clear_vf_stats_result,
14184 		 port_id, UINT8);
14185 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14186 	TOKEN_NUM_INITIALIZER
14187 		(struct cmd_clear_vf_stats_result,
14188 		 vf_id, UINT16);
14189 
14190 static void
14191 cmd_clear_vf_stats_parsed(
14192 	void *parsed_result,
14193 	__attribute__((unused)) struct cmdline *cl,
14194 	__attribute__((unused)) void *data)
14195 {
14196 	struct cmd_clear_vf_stats_result *res = parsed_result;
14197 	int ret = -ENOTSUP;
14198 
14199 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14200 		return;
14201 
14202 #ifdef RTE_LIBRTE_I40E_PMD
14203 	if (ret == -ENOTSUP)
14204 		ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14205 						  res->vf_id);
14206 #endif
14207 #ifdef RTE_LIBRTE_BNXT_PMD
14208 	if (ret == -ENOTSUP)
14209 		ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14210 						  res->vf_id);
14211 #endif
14212 
14213 	switch (ret) {
14214 	case 0:
14215 		break;
14216 	case -EINVAL:
14217 		printf("invalid vf_id %d\n", res->vf_id);
14218 		break;
14219 	case -ENODEV:
14220 		printf("invalid port_id %d\n", res->port_id);
14221 		break;
14222 	case -ENOTSUP:
14223 		printf("function not implemented\n");
14224 		break;
14225 	default:
14226 		printf("programming error: (%s)\n", strerror(-ret));
14227 	}
14228 }
14229 
14230 cmdline_parse_inst_t cmd_clear_vf_stats = {
14231 	.f = cmd_clear_vf_stats_parsed,
14232 	.data = NULL,
14233 	.help_str = "clear vf stats <port_id> <vf_id>",
14234 	.tokens = {
14235 		(void *)&cmd_clear_vf_stats_clear,
14236 		(void *)&cmd_clear_vf_stats_vf,
14237 		(void *)&cmd_clear_vf_stats_stats,
14238 		(void *)&cmd_clear_vf_stats_port_id,
14239 		(void *)&cmd_clear_vf_stats_vf_id,
14240 		NULL,
14241 	},
14242 };
14243 
14244 /* port config pctype mapping reset */
14245 
14246 /* Common result structure for port config pctype mapping reset */
14247 struct cmd_pctype_mapping_reset_result {
14248 	cmdline_fixed_string_t port;
14249 	cmdline_fixed_string_t config;
14250 	uint8_t port_id;
14251 	cmdline_fixed_string_t pctype;
14252 	cmdline_fixed_string_t mapping;
14253 	cmdline_fixed_string_t reset;
14254 };
14255 
14256 /* Common CLI fields for port config pctype mapping reset*/
14257 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14258 	TOKEN_STRING_INITIALIZER
14259 		(struct cmd_pctype_mapping_reset_result,
14260 		 port, "port");
14261 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14262 	TOKEN_STRING_INITIALIZER
14263 		(struct cmd_pctype_mapping_reset_result,
14264 		 config, "config");
14265 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14266 	TOKEN_NUM_INITIALIZER
14267 		(struct cmd_pctype_mapping_reset_result,
14268 		 port_id, UINT8);
14269 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14270 	TOKEN_STRING_INITIALIZER
14271 		(struct cmd_pctype_mapping_reset_result,
14272 		 pctype, "pctype");
14273 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14274 	TOKEN_STRING_INITIALIZER
14275 		(struct cmd_pctype_mapping_reset_result,
14276 		 mapping, "mapping");
14277 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14278 	TOKEN_STRING_INITIALIZER
14279 		(struct cmd_pctype_mapping_reset_result,
14280 		 reset, "reset");
14281 
14282 static void
14283 cmd_pctype_mapping_reset_parsed(
14284 	void *parsed_result,
14285 	__attribute__((unused)) struct cmdline *cl,
14286 	__attribute__((unused)) void *data)
14287 {
14288 	struct cmd_pctype_mapping_reset_result *res = parsed_result;
14289 	int ret = -ENOTSUP;
14290 
14291 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14292 		return;
14293 
14294 #ifdef RTE_LIBRTE_I40E_PMD
14295 	ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14296 #endif
14297 
14298 	switch (ret) {
14299 	case 0:
14300 		break;
14301 	case -ENODEV:
14302 		printf("invalid port_id %d\n", res->port_id);
14303 		break;
14304 	case -ENOTSUP:
14305 		printf("function not implemented\n");
14306 		break;
14307 	default:
14308 		printf("programming error: (%s)\n", strerror(-ret));
14309 	}
14310 }
14311 
14312 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14313 	.f = cmd_pctype_mapping_reset_parsed,
14314 	.data = NULL,
14315 	.help_str = "port config <port_id> pctype mapping reset",
14316 	.tokens = {
14317 		(void *)&cmd_pctype_mapping_reset_port,
14318 		(void *)&cmd_pctype_mapping_reset_config,
14319 		(void *)&cmd_pctype_mapping_reset_port_id,
14320 		(void *)&cmd_pctype_mapping_reset_pctype,
14321 		(void *)&cmd_pctype_mapping_reset_mapping,
14322 		(void *)&cmd_pctype_mapping_reset_reset,
14323 		NULL,
14324 	},
14325 };
14326 
14327 /* show port pctype mapping */
14328 
14329 /* Common result structure for show port pctype mapping */
14330 struct cmd_pctype_mapping_get_result {
14331 	cmdline_fixed_string_t show;
14332 	cmdline_fixed_string_t port;
14333 	uint8_t port_id;
14334 	cmdline_fixed_string_t pctype;
14335 	cmdline_fixed_string_t mapping;
14336 };
14337 
14338 /* Common CLI fields for pctype mapping get */
14339 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14340 	TOKEN_STRING_INITIALIZER
14341 		(struct cmd_pctype_mapping_get_result,
14342 		 show, "show");
14343 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14344 	TOKEN_STRING_INITIALIZER
14345 		(struct cmd_pctype_mapping_get_result,
14346 		 port, "port");
14347 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14348 	TOKEN_NUM_INITIALIZER
14349 		(struct cmd_pctype_mapping_get_result,
14350 		 port_id, UINT8);
14351 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14352 	TOKEN_STRING_INITIALIZER
14353 		(struct cmd_pctype_mapping_get_result,
14354 		 pctype, "pctype");
14355 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14356 	TOKEN_STRING_INITIALIZER
14357 		(struct cmd_pctype_mapping_get_result,
14358 		 mapping, "mapping");
14359 
14360 static void
14361 cmd_pctype_mapping_get_parsed(
14362 	void *parsed_result,
14363 	__attribute__((unused)) struct cmdline *cl,
14364 	__attribute__((unused)) void *data)
14365 {
14366 	struct cmd_pctype_mapping_get_result *res = parsed_result;
14367 	int ret = -ENOTSUP;
14368 #ifdef RTE_LIBRTE_I40E_PMD
14369 	struct rte_pmd_i40e_flow_type_mapping
14370 				mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14371 	int i, j, first_pctype;
14372 #endif
14373 
14374 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14375 		return;
14376 
14377 #ifdef RTE_LIBRTE_I40E_PMD
14378 	ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14379 #endif
14380 
14381 	switch (ret) {
14382 	case 0:
14383 		break;
14384 	case -ENODEV:
14385 		printf("invalid port_id %d\n", res->port_id);
14386 		return;
14387 	case -ENOTSUP:
14388 		printf("function not implemented\n");
14389 		return;
14390 	default:
14391 		printf("programming error: (%s)\n", strerror(-ret));
14392 		return;
14393 	}
14394 
14395 #ifdef RTE_LIBRTE_I40E_PMD
14396 	for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14397 		if (mapping[i].pctype != 0ULL) {
14398 			first_pctype = 1;
14399 
14400 			printf("pctype: ");
14401 			for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14402 				if (mapping[i].pctype & (1ULL << j)) {
14403 					printf(first_pctype ?
14404 					       "%02d" : ",%02d", j);
14405 					first_pctype = 0;
14406 				}
14407 			}
14408 			printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14409 		}
14410 	}
14411 #endif
14412 }
14413 
14414 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14415 	.f = cmd_pctype_mapping_get_parsed,
14416 	.data = NULL,
14417 	.help_str = "show port <port_id> pctype mapping",
14418 	.tokens = {
14419 		(void *)&cmd_pctype_mapping_get_show,
14420 		(void *)&cmd_pctype_mapping_get_port,
14421 		(void *)&cmd_pctype_mapping_get_port_id,
14422 		(void *)&cmd_pctype_mapping_get_pctype,
14423 		(void *)&cmd_pctype_mapping_get_mapping,
14424 		NULL,
14425 	},
14426 };
14427 
14428 /* port config pctype mapping update */
14429 
14430 /* Common result structure for port config pctype mapping update */
14431 struct cmd_pctype_mapping_update_result {
14432 	cmdline_fixed_string_t port;
14433 	cmdline_fixed_string_t config;
14434 	uint8_t port_id;
14435 	cmdline_fixed_string_t pctype;
14436 	cmdline_fixed_string_t mapping;
14437 	cmdline_fixed_string_t update;
14438 	cmdline_fixed_string_t pctype_list;
14439 	uint16_t flow_type;
14440 };
14441 
14442 /* Common CLI fields for pctype mapping update*/
14443 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14444 	TOKEN_STRING_INITIALIZER
14445 		(struct cmd_pctype_mapping_update_result,
14446 		 port, "port");
14447 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14448 	TOKEN_STRING_INITIALIZER
14449 		(struct cmd_pctype_mapping_update_result,
14450 		 config, "config");
14451 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14452 	TOKEN_NUM_INITIALIZER
14453 		(struct cmd_pctype_mapping_update_result,
14454 		 port_id, UINT8);
14455 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14456 	TOKEN_STRING_INITIALIZER
14457 		(struct cmd_pctype_mapping_update_result,
14458 		 pctype, "pctype");
14459 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14460 	TOKEN_STRING_INITIALIZER
14461 		(struct cmd_pctype_mapping_update_result,
14462 		 mapping, "mapping");
14463 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14464 	TOKEN_STRING_INITIALIZER
14465 		(struct cmd_pctype_mapping_update_result,
14466 		 update, "update");
14467 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14468 	TOKEN_STRING_INITIALIZER
14469 		(struct cmd_pctype_mapping_update_result,
14470 		 pctype_list, NULL);
14471 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14472 	TOKEN_NUM_INITIALIZER
14473 		(struct cmd_pctype_mapping_update_result,
14474 		 flow_type, UINT16);
14475 
14476 static void
14477 cmd_pctype_mapping_update_parsed(
14478 	void *parsed_result,
14479 	__attribute__((unused)) struct cmdline *cl,
14480 	__attribute__((unused)) void *data)
14481 {
14482 	struct cmd_pctype_mapping_update_result *res = parsed_result;
14483 	int ret = -ENOTSUP;
14484 #ifdef RTE_LIBRTE_I40E_PMD
14485 	struct rte_pmd_i40e_flow_type_mapping mapping;
14486 	unsigned int i;
14487 	unsigned int nb_item;
14488 	unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14489 #endif
14490 
14491 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14492 		return;
14493 
14494 #ifdef RTE_LIBRTE_I40E_PMD
14495 	nb_item = parse_item_list(res->pctype_list, "pctypes",
14496 				  RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14497 	mapping.flow_type = res->flow_type;
14498 	for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14499 		mapping.pctype |= (1ULL << pctype_list[i]);
14500 	ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14501 						&mapping,
14502 						1,
14503 						0);
14504 #endif
14505 
14506 	switch (ret) {
14507 	case 0:
14508 		break;
14509 	case -EINVAL:
14510 		printf("invalid pctype or flow type\n");
14511 		break;
14512 	case -ENODEV:
14513 		printf("invalid port_id %d\n", res->port_id);
14514 		break;
14515 	case -ENOTSUP:
14516 		printf("function not implemented\n");
14517 		break;
14518 	default:
14519 		printf("programming error: (%s)\n", strerror(-ret));
14520 	}
14521 }
14522 
14523 cmdline_parse_inst_t cmd_pctype_mapping_update = {
14524 	.f = cmd_pctype_mapping_update_parsed,
14525 	.data = NULL,
14526 	.help_str = "port config <port_id> pctype mapping update"
14527 	" <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
14528 	.tokens = {
14529 		(void *)&cmd_pctype_mapping_update_port,
14530 		(void *)&cmd_pctype_mapping_update_config,
14531 		(void *)&cmd_pctype_mapping_update_port_id,
14532 		(void *)&cmd_pctype_mapping_update_pctype,
14533 		(void *)&cmd_pctype_mapping_update_mapping,
14534 		(void *)&cmd_pctype_mapping_update_update,
14535 		(void *)&cmd_pctype_mapping_update_pc_type,
14536 		(void *)&cmd_pctype_mapping_update_flow_type,
14537 		NULL,
14538 	},
14539 };
14540 
14541 /* ptype mapping get */
14542 
14543 /* Common result structure for ptype mapping get */
14544 struct cmd_ptype_mapping_get_result {
14545 	cmdline_fixed_string_t ptype;
14546 	cmdline_fixed_string_t mapping;
14547 	cmdline_fixed_string_t get;
14548 	uint8_t port_id;
14549 	uint8_t valid_only;
14550 };
14551 
14552 /* Common CLI fields for ptype mapping get */
14553 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
14554 	TOKEN_STRING_INITIALIZER
14555 		(struct cmd_ptype_mapping_get_result,
14556 		 ptype, "ptype");
14557 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
14558 	TOKEN_STRING_INITIALIZER
14559 		(struct cmd_ptype_mapping_get_result,
14560 		 mapping, "mapping");
14561 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
14562 	TOKEN_STRING_INITIALIZER
14563 		(struct cmd_ptype_mapping_get_result,
14564 		 get, "get");
14565 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
14566 	TOKEN_NUM_INITIALIZER
14567 		(struct cmd_ptype_mapping_get_result,
14568 		 port_id, UINT8);
14569 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
14570 	TOKEN_NUM_INITIALIZER
14571 		(struct cmd_ptype_mapping_get_result,
14572 		 valid_only, UINT8);
14573 
14574 static void
14575 cmd_ptype_mapping_get_parsed(
14576 	void *parsed_result,
14577 	__attribute__((unused)) struct cmdline *cl,
14578 	__attribute__((unused)) void *data)
14579 {
14580 	struct cmd_ptype_mapping_get_result *res = parsed_result;
14581 	int ret = -ENOTSUP;
14582 #ifdef RTE_LIBRTE_I40E_PMD
14583 	int max_ptype_num = 256;
14584 	struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
14585 	uint16_t count;
14586 	int i;
14587 #endif
14588 
14589 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14590 		return;
14591 
14592 #ifdef RTE_LIBRTE_I40E_PMD
14593 	ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
14594 					mapping,
14595 					max_ptype_num,
14596 					&count,
14597 					res->valid_only);
14598 #endif
14599 
14600 	switch (ret) {
14601 	case 0:
14602 		break;
14603 	case -ENODEV:
14604 		printf("invalid port_id %d\n", res->port_id);
14605 		break;
14606 	case -ENOTSUP:
14607 		printf("function not implemented\n");
14608 		break;
14609 	default:
14610 		printf("programming error: (%s)\n", strerror(-ret));
14611 	}
14612 
14613 #ifdef RTE_LIBRTE_I40E_PMD
14614 	if (!ret) {
14615 		for (i = 0; i < count; i++)
14616 			printf("%3d\t0x%08x\n",
14617 				mapping[i].hw_ptype, mapping[i].sw_ptype);
14618 	}
14619 #endif
14620 }
14621 
14622 cmdline_parse_inst_t cmd_ptype_mapping_get = {
14623 	.f = cmd_ptype_mapping_get_parsed,
14624 	.data = NULL,
14625 	.help_str = "ptype mapping get <port_id> <valid_only>",
14626 	.tokens = {
14627 		(void *)&cmd_ptype_mapping_get_ptype,
14628 		(void *)&cmd_ptype_mapping_get_mapping,
14629 		(void *)&cmd_ptype_mapping_get_get,
14630 		(void *)&cmd_ptype_mapping_get_port_id,
14631 		(void *)&cmd_ptype_mapping_get_valid_only,
14632 		NULL,
14633 	},
14634 };
14635 
14636 /* ptype mapping replace */
14637 
14638 /* Common result structure for ptype mapping replace */
14639 struct cmd_ptype_mapping_replace_result {
14640 	cmdline_fixed_string_t ptype;
14641 	cmdline_fixed_string_t mapping;
14642 	cmdline_fixed_string_t replace;
14643 	uint8_t port_id;
14644 	uint32_t target;
14645 	uint8_t mask;
14646 	uint32_t pkt_type;
14647 };
14648 
14649 /* Common CLI fields for ptype mapping replace */
14650 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
14651 	TOKEN_STRING_INITIALIZER
14652 		(struct cmd_ptype_mapping_replace_result,
14653 		 ptype, "ptype");
14654 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
14655 	TOKEN_STRING_INITIALIZER
14656 		(struct cmd_ptype_mapping_replace_result,
14657 		 mapping, "mapping");
14658 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
14659 	TOKEN_STRING_INITIALIZER
14660 		(struct cmd_ptype_mapping_replace_result,
14661 		 replace, "replace");
14662 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
14663 	TOKEN_NUM_INITIALIZER
14664 		(struct cmd_ptype_mapping_replace_result,
14665 		 port_id, UINT8);
14666 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
14667 	TOKEN_NUM_INITIALIZER
14668 		(struct cmd_ptype_mapping_replace_result,
14669 		 target, UINT32);
14670 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
14671 	TOKEN_NUM_INITIALIZER
14672 		(struct cmd_ptype_mapping_replace_result,
14673 		 mask, UINT8);
14674 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
14675 	TOKEN_NUM_INITIALIZER
14676 		(struct cmd_ptype_mapping_replace_result,
14677 		 pkt_type, UINT32);
14678 
14679 static void
14680 cmd_ptype_mapping_replace_parsed(
14681 	void *parsed_result,
14682 	__attribute__((unused)) struct cmdline *cl,
14683 	__attribute__((unused)) void *data)
14684 {
14685 	struct cmd_ptype_mapping_replace_result *res = parsed_result;
14686 	int ret = -ENOTSUP;
14687 
14688 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14689 		return;
14690 
14691 #ifdef RTE_LIBRTE_I40E_PMD
14692 	ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
14693 					res->target,
14694 					res->mask,
14695 					res->pkt_type);
14696 #endif
14697 
14698 	switch (ret) {
14699 	case 0:
14700 		break;
14701 	case -EINVAL:
14702 		printf("invalid ptype 0x%8x or 0x%8x\n",
14703 				res->target, res->pkt_type);
14704 		break;
14705 	case -ENODEV:
14706 		printf("invalid port_id %d\n", res->port_id);
14707 		break;
14708 	case -ENOTSUP:
14709 		printf("function not implemented\n");
14710 		break;
14711 	default:
14712 		printf("programming error: (%s)\n", strerror(-ret));
14713 	}
14714 }
14715 
14716 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
14717 	.f = cmd_ptype_mapping_replace_parsed,
14718 	.data = NULL,
14719 	.help_str =
14720 		"ptype mapping replace <port_id> <target> <mask> <pkt_type>",
14721 	.tokens = {
14722 		(void *)&cmd_ptype_mapping_replace_ptype,
14723 		(void *)&cmd_ptype_mapping_replace_mapping,
14724 		(void *)&cmd_ptype_mapping_replace_replace,
14725 		(void *)&cmd_ptype_mapping_replace_port_id,
14726 		(void *)&cmd_ptype_mapping_replace_target,
14727 		(void *)&cmd_ptype_mapping_replace_mask,
14728 		(void *)&cmd_ptype_mapping_replace_pkt_type,
14729 		NULL,
14730 	},
14731 };
14732 
14733 /* ptype mapping reset */
14734 
14735 /* Common result structure for ptype mapping reset */
14736 struct cmd_ptype_mapping_reset_result {
14737 	cmdline_fixed_string_t ptype;
14738 	cmdline_fixed_string_t mapping;
14739 	cmdline_fixed_string_t reset;
14740 	uint8_t port_id;
14741 };
14742 
14743 /* Common CLI fields for ptype mapping reset*/
14744 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
14745 	TOKEN_STRING_INITIALIZER
14746 		(struct cmd_ptype_mapping_reset_result,
14747 		 ptype, "ptype");
14748 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
14749 	TOKEN_STRING_INITIALIZER
14750 		(struct cmd_ptype_mapping_reset_result,
14751 		 mapping, "mapping");
14752 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
14753 	TOKEN_STRING_INITIALIZER
14754 		(struct cmd_ptype_mapping_reset_result,
14755 		 reset, "reset");
14756 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
14757 	TOKEN_NUM_INITIALIZER
14758 		(struct cmd_ptype_mapping_reset_result,
14759 		 port_id, UINT8);
14760 
14761 static void
14762 cmd_ptype_mapping_reset_parsed(
14763 	void *parsed_result,
14764 	__attribute__((unused)) struct cmdline *cl,
14765 	__attribute__((unused)) void *data)
14766 {
14767 	struct cmd_ptype_mapping_reset_result *res = parsed_result;
14768 	int ret = -ENOTSUP;
14769 
14770 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14771 		return;
14772 
14773 #ifdef RTE_LIBRTE_I40E_PMD
14774 	ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
14775 #endif
14776 
14777 	switch (ret) {
14778 	case 0:
14779 		break;
14780 	case -ENODEV:
14781 		printf("invalid port_id %d\n", res->port_id);
14782 		break;
14783 	case -ENOTSUP:
14784 		printf("function not implemented\n");
14785 		break;
14786 	default:
14787 		printf("programming error: (%s)\n", strerror(-ret));
14788 	}
14789 }
14790 
14791 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
14792 	.f = cmd_ptype_mapping_reset_parsed,
14793 	.data = NULL,
14794 	.help_str = "ptype mapping reset <port_id>",
14795 	.tokens = {
14796 		(void *)&cmd_ptype_mapping_reset_ptype,
14797 		(void *)&cmd_ptype_mapping_reset_mapping,
14798 		(void *)&cmd_ptype_mapping_reset_reset,
14799 		(void *)&cmd_ptype_mapping_reset_port_id,
14800 		NULL,
14801 	},
14802 };
14803 
14804 /* ptype mapping update */
14805 
14806 /* Common result structure for ptype mapping update */
14807 struct cmd_ptype_mapping_update_result {
14808 	cmdline_fixed_string_t ptype;
14809 	cmdline_fixed_string_t mapping;
14810 	cmdline_fixed_string_t reset;
14811 	uint8_t port_id;
14812 	uint8_t hw_ptype;
14813 	uint32_t sw_ptype;
14814 };
14815 
14816 /* Common CLI fields for ptype mapping update*/
14817 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
14818 	TOKEN_STRING_INITIALIZER
14819 		(struct cmd_ptype_mapping_update_result,
14820 		 ptype, "ptype");
14821 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
14822 	TOKEN_STRING_INITIALIZER
14823 		(struct cmd_ptype_mapping_update_result,
14824 		 mapping, "mapping");
14825 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
14826 	TOKEN_STRING_INITIALIZER
14827 		(struct cmd_ptype_mapping_update_result,
14828 		 reset, "update");
14829 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
14830 	TOKEN_NUM_INITIALIZER
14831 		(struct cmd_ptype_mapping_update_result,
14832 		 port_id, UINT8);
14833 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
14834 	TOKEN_NUM_INITIALIZER
14835 		(struct cmd_ptype_mapping_update_result,
14836 		 hw_ptype, UINT8);
14837 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
14838 	TOKEN_NUM_INITIALIZER
14839 		(struct cmd_ptype_mapping_update_result,
14840 		 sw_ptype, UINT32);
14841 
14842 static void
14843 cmd_ptype_mapping_update_parsed(
14844 	void *parsed_result,
14845 	__attribute__((unused)) struct cmdline *cl,
14846 	__attribute__((unused)) void *data)
14847 {
14848 	struct cmd_ptype_mapping_update_result *res = parsed_result;
14849 	int ret = -ENOTSUP;
14850 #ifdef RTE_LIBRTE_I40E_PMD
14851 	struct rte_pmd_i40e_ptype_mapping mapping;
14852 #endif
14853 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14854 		return;
14855 
14856 #ifdef RTE_LIBRTE_I40E_PMD
14857 	mapping.hw_ptype = res->hw_ptype;
14858 	mapping.sw_ptype = res->sw_ptype;
14859 	ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
14860 						&mapping,
14861 						1,
14862 						0);
14863 #endif
14864 
14865 	switch (ret) {
14866 	case 0:
14867 		break;
14868 	case -EINVAL:
14869 		printf("invalid ptype 0x%8x\n", res->sw_ptype);
14870 		break;
14871 	case -ENODEV:
14872 		printf("invalid port_id %d\n", res->port_id);
14873 		break;
14874 	case -ENOTSUP:
14875 		printf("function not implemented\n");
14876 		break;
14877 	default:
14878 		printf("programming error: (%s)\n", strerror(-ret));
14879 	}
14880 }
14881 
14882 cmdline_parse_inst_t cmd_ptype_mapping_update = {
14883 	.f = cmd_ptype_mapping_update_parsed,
14884 	.data = NULL,
14885 	.help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
14886 	.tokens = {
14887 		(void *)&cmd_ptype_mapping_update_ptype,
14888 		(void *)&cmd_ptype_mapping_update_mapping,
14889 		(void *)&cmd_ptype_mapping_update_update,
14890 		(void *)&cmd_ptype_mapping_update_port_id,
14891 		(void *)&cmd_ptype_mapping_update_hw_ptype,
14892 		(void *)&cmd_ptype_mapping_update_sw_ptype,
14893 		NULL,
14894 	},
14895 };
14896 
14897 /* Common result structure for file commands */
14898 struct cmd_cmdfile_result {
14899 	cmdline_fixed_string_t load;
14900 	cmdline_fixed_string_t filename;
14901 };
14902 
14903 /* Common CLI fields for file commands */
14904 cmdline_parse_token_string_t cmd_load_cmdfile =
14905 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
14906 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
14907 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
14908 
14909 static void
14910 cmd_load_from_file_parsed(
14911 	void *parsed_result,
14912 	__attribute__((unused)) struct cmdline *cl,
14913 	__attribute__((unused)) void *data)
14914 {
14915 	struct cmd_cmdfile_result *res = parsed_result;
14916 
14917 	cmdline_read_from_file(res->filename);
14918 }
14919 
14920 cmdline_parse_inst_t cmd_load_from_file = {
14921 	.f = cmd_load_from_file_parsed,
14922 	.data = NULL,
14923 	.help_str = "load <filename>",
14924 	.tokens = {
14925 		(void *)&cmd_load_cmdfile,
14926 		(void *)&cmd_load_cmdfile_filename,
14927 		NULL,
14928 	},
14929 };
14930 
14931 /* ******************************************************************************** */
14932 
14933 /* list of instructions */
14934 cmdline_parse_ctx_t main_ctx[] = {
14935 	(cmdline_parse_inst_t *)&cmd_help_brief,
14936 	(cmdline_parse_inst_t *)&cmd_help_long,
14937 	(cmdline_parse_inst_t *)&cmd_quit,
14938 	(cmdline_parse_inst_t *)&cmd_load_from_file,
14939 	(cmdline_parse_inst_t *)&cmd_showport,
14940 	(cmdline_parse_inst_t *)&cmd_showqueue,
14941 	(cmdline_parse_inst_t *)&cmd_showportall,
14942 	(cmdline_parse_inst_t *)&cmd_showcfg,
14943 	(cmdline_parse_inst_t *)&cmd_start,
14944 	(cmdline_parse_inst_t *)&cmd_start_tx_first,
14945 	(cmdline_parse_inst_t *)&cmd_start_tx_first_n,
14946 	(cmdline_parse_inst_t *)&cmd_set_link_up,
14947 	(cmdline_parse_inst_t *)&cmd_set_link_down,
14948 	(cmdline_parse_inst_t *)&cmd_reset,
14949 	(cmdline_parse_inst_t *)&cmd_set_numbers,
14950 	(cmdline_parse_inst_t *)&cmd_set_txpkts,
14951 	(cmdline_parse_inst_t *)&cmd_set_txsplit,
14952 	(cmdline_parse_inst_t *)&cmd_set_fwd_list,
14953 	(cmdline_parse_inst_t *)&cmd_set_fwd_mask,
14954 	(cmdline_parse_inst_t *)&cmd_set_fwd_mode,
14955 	(cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
14956 	(cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
14957 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
14958 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
14959 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
14960 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
14961 	(cmdline_parse_inst_t *)&cmd_set_flush_rx,
14962 	(cmdline_parse_inst_t *)&cmd_set_link_check,
14963 	(cmdline_parse_inst_t *)&cmd_set_bypass_mode,
14964 	(cmdline_parse_inst_t *)&cmd_set_bypass_event,
14965 	(cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
14966 	(cmdline_parse_inst_t *)&cmd_show_bypass_config,
14967 #ifdef RTE_LIBRTE_PMD_BOND
14968 	(cmdline_parse_inst_t *) &cmd_set_bonding_mode,
14969 	(cmdline_parse_inst_t *) &cmd_show_bonding_config,
14970 	(cmdline_parse_inst_t *) &cmd_set_bonding_primary,
14971 	(cmdline_parse_inst_t *) &cmd_add_bonding_slave,
14972 	(cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
14973 	(cmdline_parse_inst_t *) &cmd_create_bonded_device,
14974 	(cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
14975 	(cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
14976 	(cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
14977 	(cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
14978 	(cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
14979 #endif
14980 	(cmdline_parse_inst_t *)&cmd_vlan_offload,
14981 	(cmdline_parse_inst_t *)&cmd_vlan_tpid,
14982 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
14983 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
14984 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set,
14985 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
14986 	(cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
14987 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
14988 	(cmdline_parse_inst_t *)&cmd_csum_set,
14989 	(cmdline_parse_inst_t *)&cmd_csum_show,
14990 	(cmdline_parse_inst_t *)&cmd_csum_tunnel,
14991 	(cmdline_parse_inst_t *)&cmd_tso_set,
14992 	(cmdline_parse_inst_t *)&cmd_tso_show,
14993 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
14994 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
14995 	(cmdline_parse_inst_t *)&cmd_gro_enable,
14996 	(cmdline_parse_inst_t *)&cmd_gro_flush,
14997 	(cmdline_parse_inst_t *)&cmd_gro_show,
14998 	(cmdline_parse_inst_t *)&cmd_gso_enable,
14999 	(cmdline_parse_inst_t *)&cmd_gso_size,
15000 	(cmdline_parse_inst_t *)&cmd_gso_show,
15001 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15002 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15003 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15004 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15005 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15006 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15007 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15008 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15009 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15010 	(cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15011 	(cmdline_parse_inst_t *)&cmd_config_dcb,
15012 	(cmdline_parse_inst_t *)&cmd_read_reg,
15013 	(cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15014 	(cmdline_parse_inst_t *)&cmd_read_reg_bit,
15015 	(cmdline_parse_inst_t *)&cmd_write_reg,
15016 	(cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15017 	(cmdline_parse_inst_t *)&cmd_write_reg_bit,
15018 	(cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15019 	(cmdline_parse_inst_t *)&cmd_stop,
15020 	(cmdline_parse_inst_t *)&cmd_mac_addr,
15021 	(cmdline_parse_inst_t *)&cmd_set_qmap,
15022 	(cmdline_parse_inst_t *)&cmd_operate_port,
15023 	(cmdline_parse_inst_t *)&cmd_operate_specific_port,
15024 	(cmdline_parse_inst_t *)&cmd_operate_attach_port,
15025 	(cmdline_parse_inst_t *)&cmd_operate_detach_port,
15026 	(cmdline_parse_inst_t *)&cmd_config_speed_all,
15027 	(cmdline_parse_inst_t *)&cmd_config_speed_specific,
15028 	(cmdline_parse_inst_t *)&cmd_config_rx_tx,
15029 	(cmdline_parse_inst_t *)&cmd_config_mtu,
15030 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15031 	(cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15032 	(cmdline_parse_inst_t *)&cmd_config_rss,
15033 	(cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15034 	(cmdline_parse_inst_t *)&cmd_config_txqflags,
15035 	(cmdline_parse_inst_t *)&cmd_config_rss_reta,
15036 	(cmdline_parse_inst_t *)&cmd_showport_reta,
15037 	(cmdline_parse_inst_t *)&cmd_config_burst,
15038 	(cmdline_parse_inst_t *)&cmd_config_thresh,
15039 	(cmdline_parse_inst_t *)&cmd_config_threshold,
15040 	(cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15041 	(cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15042 	(cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15043 	(cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15044 	(cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15045 	(cmdline_parse_inst_t *)&cmd_tunnel_filter,
15046 	(cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15047 	(cmdline_parse_inst_t *)&cmd_global_config,
15048 	(cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15049 	(cmdline_parse_inst_t *)&cmd_set_mirror_link,
15050 	(cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15051 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15052 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15053 	(cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15054 	(cmdline_parse_inst_t *)&cmd_dump,
15055 	(cmdline_parse_inst_t *)&cmd_dump_one,
15056 	(cmdline_parse_inst_t *)&cmd_ethertype_filter,
15057 	(cmdline_parse_inst_t *)&cmd_syn_filter,
15058 	(cmdline_parse_inst_t *)&cmd_2tuple_filter,
15059 	(cmdline_parse_inst_t *)&cmd_5tuple_filter,
15060 	(cmdline_parse_inst_t *)&cmd_flex_filter,
15061 	(cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15062 	(cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15063 	(cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15064 	(cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15065 	(cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15066 	(cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15067 	(cmdline_parse_inst_t *)&cmd_flush_flow_director,
15068 	(cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15069 	(cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15070 	(cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15071 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15072 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15073 	(cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15074 	(cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15075 	(cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15076 	(cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15077 	(cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15078 	(cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15079 	(cmdline_parse_inst_t *)&cmd_flow,
15080 	(cmdline_parse_inst_t *)&cmd_mcast_addr,
15081 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15082 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15083 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15084 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15085 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15086 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15087 	(cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15088 	(cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15089 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15090 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15091 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15092 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15093 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15094 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15095 	(cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15096 	(cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15097 	(cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15098 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15099 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15100 	(cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15101 	(cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15102 	(cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15103 	(cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15104 	(cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15105 	(cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15106 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15107 	(cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15108 	(cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15109 	(cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15110 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15111 	(cmdline_parse_inst_t *)&cmd_vf_max_bw,
15112 	(cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15113 	(cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15114 	(cmdline_parse_inst_t *)&cmd_strict_link_prio,
15115 	(cmdline_parse_inst_t *)&cmd_tc_min_bw,
15116 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15117 	(cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15118 #endif
15119 	(cmdline_parse_inst_t *)&cmd_ddp_add,
15120 	(cmdline_parse_inst_t *)&cmd_ddp_del,
15121 	(cmdline_parse_inst_t *)&cmd_ddp_get_list,
15122 	(cmdline_parse_inst_t *)&cmd_ddp_get_info,
15123 	(cmdline_parse_inst_t *)&cmd_show_vf_stats,
15124 	(cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15125 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15126 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15127 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15128 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15129 
15130 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15131 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15132 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15133 	NULL,
15134 };
15135 
15136 /* read cmdline commands from file */
15137 void
15138 cmdline_read_from_file(const char *filename)
15139 {
15140 	struct cmdline *cl;
15141 
15142 	cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15143 	if (cl == NULL) {
15144 		printf("Failed to create file based cmdline context: %s\n",
15145 		       filename);
15146 		return;
15147 	}
15148 
15149 	cmdline_interact(cl);
15150 	cmdline_quit(cl);
15151 
15152 	cmdline_free(cl);
15153 
15154 	printf("Read CLI commands from %s\n", filename);
15155 }
15156 
15157 /* prompt function, called from main on MASTER lcore */
15158 void
15159 prompt(void)
15160 {
15161 	/* initialize non-constant commands */
15162 	cmd_set_fwd_mode_init();
15163 	cmd_set_fwd_retry_mode_init();
15164 
15165 	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15166 	if (testpmd_cl == NULL)
15167 		return;
15168 	cmdline_interact(testpmd_cl);
15169 	cmdline_stdin_exit(testpmd_cl);
15170 }
15171 
15172 void
15173 prompt_exit(void)
15174 {
15175 	if (testpmd_cl != NULL)
15176 		cmdline_quit(testpmd_cl);
15177 }
15178 
15179 static void
15180 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15181 {
15182 	if (id == (portid_t)RTE_PORT_ALL) {
15183 		portid_t pid;
15184 
15185 		RTE_ETH_FOREACH_DEV(pid) {
15186 			/* check if need_reconfig has been set to 1 */
15187 			if (ports[pid].need_reconfig == 0)
15188 				ports[pid].need_reconfig = dev;
15189 			/* check if need_reconfig_queues has been set to 1 */
15190 			if (ports[pid].need_reconfig_queues == 0)
15191 				ports[pid].need_reconfig_queues = queue;
15192 		}
15193 	} else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15194 		/* check if need_reconfig has been set to 1 */
15195 		if (ports[id].need_reconfig == 0)
15196 			ports[id].need_reconfig = dev;
15197 		/* check if need_reconfig_queues has been set to 1 */
15198 		if (ports[id].need_reconfig_queues == 0)
15199 			ports[id].need_reconfig_queues = queue;
15200 	}
15201 }
15202