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