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