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