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